82 lines
2.9 KiB
C++
82 lines
2.9 KiB
C++
#include "BehaviorTargeting.h"
|
|
|
|
#include "EntityAdmin.h"
|
|
#include "FactionComponent.h"
|
|
#include "HealthComponent.h"
|
|
#include "HqProxyComponent.h"
|
|
#include "ModuleOwnerComponent.h"
|
|
#include "PositionComponent.h"
|
|
#include "SalvageCargoComponent.h"
|
|
#include "ShipIdentityComponent.h"
|
|
#include "StationBodyComponent.h"
|
|
|
|
std::vector<RepairableInfo> buildRepairables(EntityAdmin& admin)
|
|
{
|
|
std::vector<RepairableInfo> repairables;
|
|
|
|
admin.forEach<ShipIdentityComponent, PositionComponent, FactionComponent, HealthComponent>(
|
|
[&repairables](entt::entity e, const ShipIdentityComponent& /*si*/,
|
|
const PositionComponent& pos, const FactionComponent& f,
|
|
const HealthComponent& h)
|
|
{
|
|
repairables.push_back({e, pos.value, f.isEnemy, true, h.hp, h.maxHp});
|
|
});
|
|
|
|
admin.forEach<StationBodyComponent, PositionComponent, FactionComponent, HealthComponent>(
|
|
[&repairables](entt::entity e, const StationBodyComponent& /*sb*/,
|
|
const PositionComponent& pos, const FactionComponent& f,
|
|
const HealthComponent& h)
|
|
{
|
|
repairables.push_back({e, pos.value, f.isEnemy, false, h.hp, h.maxHp});
|
|
});
|
|
|
|
return repairables;
|
|
}
|
|
|
|
std::vector<CombatantInfo> buildCombatants(EntityAdmin& admin)
|
|
{
|
|
std::vector<CombatantInfo> combatants;
|
|
|
|
admin.forEach<PositionComponent, FactionComponent, ShipIdentityComponent>(
|
|
[&combatants](entt::entity e, const PositionComponent& pos,
|
|
const FactionComponent& f, const ShipIdentityComponent& /*si*/)
|
|
{
|
|
combatants.push_back({e, pos.value, f.isEnemy, false});
|
|
});
|
|
|
|
admin.forEach<PositionComponent, FactionComponent, StationBodyComponent>(
|
|
[&combatants](entt::entity e, const PositionComponent& pos,
|
|
const FactionComponent& f, const StationBodyComponent& /*sb*/)
|
|
{
|
|
combatants.push_back({e, pos.value, f.isEnemy, true});
|
|
});
|
|
|
|
admin.forEach<PositionComponent, FactionComponent, HqProxyComponent>(
|
|
[&combatants](entt::entity e, const PositionComponent& pos,
|
|
const FactionComponent& f, const HqProxyComponent& /*hq*/)
|
|
{
|
|
combatants.push_back({e, pos.value, f.isEnemy, true});
|
|
});
|
|
|
|
return combatants;
|
|
}
|
|
|
|
std::unordered_map<entt::entity, CargoState> buildCargoByShip(EntityAdmin& admin)
|
|
{
|
|
std::unordered_map<entt::entity, CargoState> cargoByShip;
|
|
admin.forEach<SalvageCargoComponent, ModuleOwnerComponent>(
|
|
[&cargoByShip](entt::entity /*ce*/, const SalvageCargoComponent& c,
|
|
const ModuleOwnerComponent& o)
|
|
{
|
|
CargoState& agg = cargoByShip[o.owner];
|
|
agg.current += c.current;
|
|
agg.capacity += c.capacity;
|
|
});
|
|
return cargoByShip;
|
|
}
|
|
|
|
bool isCargoFull(const CargoState& cargo)
|
|
{
|
|
return cargo.capacity > 0 && cargo.current >= cargo.capacity;
|
|
}
|