add live ship stats panel
This commit is contained in:
@@ -3,6 +3,16 @@
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
#include "DynamicBodyComponent.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "ModuleOwnerComponent.h"
|
||||
#include "RepairToolComponent.h"
|
||||
#include "SalvageCargoComponent.h"
|
||||
#include "SensorRangeComponent.h"
|
||||
#include "Tick.h"
|
||||
#include "WeaponComponent.h"
|
||||
|
||||
ShipStats calculateShipStats(const GameConfig& config,
|
||||
const std::string& shipId,
|
||||
int level,
|
||||
@@ -216,3 +226,68 @@ ShipStats calculateShipStats(const GameConfig& config,
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ShipStats buildShipStatsFromEntity(const EntityAdmin& admin, entt::entity shipEntity)
|
||||
{
|
||||
ShipStats result{};
|
||||
|
||||
const HealthComponent& health = admin.get<HealthComponent>(shipEntity);
|
||||
const DynamicBodyComponent& body = admin.get<DynamicBodyComponent>(shipEntity);
|
||||
const SensorRangeComponent& sensor = admin.get<SensorRangeComponent>(shipEntity);
|
||||
|
||||
result.hp = health.maxHp;
|
||||
result.maxSpeed_tps = body.maxSpeed_tpt * kTickRateHz;
|
||||
result.sensorRange_tiles = sensor.value_tiles;
|
||||
result.mainAcceleration_tpss = body.mainAcceleration_tptt * kTickRateHz * kTickRateHz;
|
||||
result.maneuveringAcceleration_tpss = body.maneuveringAcceleration_tptt * kTickRateHz * kTickRateHz;
|
||||
result.angularAcceleration_radpss = body.maxAngularAcceleration_rptt * kTickRateHz * kTickRateHz;
|
||||
result.maxRotationSpeed_radps = body.maxRotationSpeed_rpt * kTickRateHz;
|
||||
|
||||
float weaponDps = 0.0f;
|
||||
float weaponMaxRange = 0.0f;
|
||||
bool hasWeapons = false;
|
||||
|
||||
float salvageRate = 0.0f;
|
||||
float salvageMaxRange = 0.0f;
|
||||
bool hasSalvage = false;
|
||||
|
||||
float repairRate = 0.0f;
|
||||
float repairMaxRange = 0.0f;
|
||||
bool hasRepair = false;
|
||||
|
||||
admin.forEach<ModuleOwnerComponent, WeaponComponent>(
|
||||
[&](entt::entity /*child*/, const ModuleOwnerComponent& owner, const WeaponComponent& w)
|
||||
{
|
||||
if (owner.owner != shipEntity) { return; }
|
||||
hasWeapons = true;
|
||||
weaponDps += w.damage * w.fireRateHz;
|
||||
if (w.range_tiles > weaponMaxRange) { weaponMaxRange = w.range_tiles; }
|
||||
});
|
||||
|
||||
admin.forEach<ModuleOwnerComponent, SalvageCargoComponent>(
|
||||
[&](entt::entity /*child*/, const ModuleOwnerComponent& owner, const SalvageCargoComponent& s)
|
||||
{
|
||||
if (owner.owner != shipEntity) { return; }
|
||||
hasSalvage = true;
|
||||
const float rate = (s.collectionIntervalTicks > 0)
|
||||
? static_cast<float>(kTickRateHz) / static_cast<float>(s.collectionIntervalTicks)
|
||||
: 0.0f;
|
||||
salvageRate += rate;
|
||||
if (s.collectionRange_tiles > salvageMaxRange) { salvageMaxRange = s.collectionRange_tiles; }
|
||||
});
|
||||
|
||||
admin.forEach<ModuleOwnerComponent, RepairToolComponent>(
|
||||
[&](entt::entity /*child*/, const ModuleOwnerComponent& owner, const RepairToolComponent& r)
|
||||
{
|
||||
if (owner.owner != shipEntity) { return; }
|
||||
hasRepair = true;
|
||||
repairRate += r.ratePerTick * kTickRateHz;
|
||||
if (r.range_tiles > repairMaxRange) { repairMaxRange = r.range_tiles; }
|
||||
});
|
||||
|
||||
if (hasWeapons) { result.weapons = ShipStats::WeaponStats{weaponDps, weaponMaxRange}; }
|
||||
if (hasSalvage) { result.salvage = ShipStats::SalvageStats{salvageRate, salvageMaxRange}; }
|
||||
if (hasRepair) { result.repair = ShipStats::RepairStats{repairRate, repairMaxRange}; }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user