move ecs related code to own folder
This commit is contained in:
@@ -8,14 +8,18 @@
|
||||
#include "BuildingType.h"
|
||||
#include "CombatSystem.h"
|
||||
#include "ConfigLoader.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "FireEvent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "HqProxyComponent.h"
|
||||
#include "ScrapSystem.h"
|
||||
#include "Ship.h"
|
||||
#include "ShipSystem.h"
|
||||
#include "Simulation.h"
|
||||
#include "StationBodyComponent.h"
|
||||
#include "Tick.h"
|
||||
#include "ThreatResponseBehaviorComponent.h"
|
||||
#include "WeaponComponent.h"
|
||||
|
||||
static GameConfig loadConfig()
|
||||
{
|
||||
@@ -63,14 +67,14 @@ struct CombatFixture
|
||||
|
||||
void wireEnemyTarget(entt::entity enemy, entt::entity playerTarget)
|
||||
{
|
||||
if (admin.hasAll<Weapon>(enemy))
|
||||
if (admin.hasAll<WeaponComponent>(enemy))
|
||||
{
|
||||
admin.get<Weapon>(enemy).currentTarget = playerTarget;
|
||||
admin.get<Weapon>(enemy).cooldownTicks = 0.0f;
|
||||
admin.get<WeaponComponent>(enemy).currentTarget = playerTarget;
|
||||
admin.get<WeaponComponent>(enemy).cooldownTicks = 0.0f;
|
||||
}
|
||||
if (admin.hasAll<ThreatResponseBehavior>(enemy))
|
||||
if (admin.hasAll<ThreatResponseBehaviorComponent>(enemy))
|
||||
{
|
||||
admin.get<ThreatResponseBehavior>(enemy).currentTarget = playerTarget;
|
||||
admin.get<ThreatResponseBehaviorComponent>(enemy).currentTarget = playerTarget;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -89,13 +93,13 @@ TEST_CASE("CombatSystem: ship fires when cooldown=0 and target in range", "[comb
|
||||
const entt::entity player = f.ships.spawn(combatDef->id, 1, QVector2D(4.0f, 5.0f), false);
|
||||
f.wireEnemyTarget(enemy, player);
|
||||
|
||||
const float hpBefore = f.admin.get<Health>(player).hp;
|
||||
const float hpBefore = f.admin.get<HealthComponent>(player).hp;
|
||||
|
||||
std::vector<FireEvent> events;
|
||||
f.combat.tick(0, f.admin, f.buildings, events);
|
||||
f.combat.applyPendingDamage(5, f.admin);
|
||||
|
||||
REQUIRE(f.admin.get<Health>(player).hp < hpBefore);
|
||||
REQUIRE(f.admin.get<HealthComponent>(player).hp < hpBefore);
|
||||
REQUIRE(events.size() >= 1);
|
||||
}
|
||||
|
||||
@@ -109,7 +113,7 @@ TEST_CASE("CombatSystem: cooldown prevents firing before it expires", "[combat]"
|
||||
const entt::entity player = f.ships.spawn(combatDef->id, 1, QVector2D(4.0f, 5.0f), false);
|
||||
|
||||
f.wireEnemyTarget(enemy, player);
|
||||
f.admin.get<Weapon>(enemy).cooldownTicks = 3.0f; // override to 3
|
||||
f.admin.get<WeaponComponent>(enemy).cooldownTicks = 3.0f; // override to 3
|
||||
|
||||
std::vector<FireEvent> events;
|
||||
f.combat.tick(0, f.admin, f.buildings, events);
|
||||
@@ -146,8 +150,8 @@ TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat]
|
||||
// Find the player station entity via ECS.
|
||||
entt::entity stationEntity = entt::null;
|
||||
QVector2D stationCenter;
|
||||
sim.admin().forEach<StationBody, Faction>(
|
||||
[&](entt::entity e, const StationBody& sb, const Faction& f)
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent>(
|
||||
[&](entt::entity e, const StationBodyComponent& sb, const FactionComponent& f)
|
||||
{
|
||||
if (!f.isEnemy && stationEntity == entt::null)
|
||||
{
|
||||
@@ -184,8 +188,8 @@ TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]
|
||||
|
||||
entt::entity stationEntity = entt::null;
|
||||
QVector2D stationCenter;
|
||||
sim.admin().forEach<StationBody, Faction>(
|
||||
[&](entt::entity e, const StationBody& sb, const Faction& f)
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent>(
|
||||
[&](entt::entity e, const StationBodyComponent& sb, const FactionComponent& f)
|
||||
{
|
||||
if (f.isEnemy && stationEntity == entt::null)
|
||||
{
|
||||
@@ -222,8 +226,8 @@ TEST_CASE("CombatSystem: player ship fires at enemy station in range", "[combat]
|
||||
|
||||
entt::entity stationEntity = entt::null;
|
||||
QVector2D stationCenter;
|
||||
sim.admin().forEach<StationBody, Faction>(
|
||||
[&](entt::entity e, const StationBody& sb, const Faction& f)
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent>(
|
||||
[&](entt::entity e, const StationBodyComponent& sb, const FactionComponent& f)
|
||||
{
|
||||
if (f.isEnemy && stationEntity == entt::null)
|
||||
{
|
||||
@@ -271,7 +275,7 @@ TEST_CASE("CombatSystem: damage not applied before impact tick", "[combat]")
|
||||
const entt::entity player = f.ships.spawn(combatDef->id, 1, QVector2D(4.0f, 5.0f), false);
|
||||
f.wireEnemyTarget(enemy, player);
|
||||
|
||||
const float hpBefore = f.admin.get<Health>(player).hp;
|
||||
const float hpBefore = f.admin.get<HealthComponent>(player).hp;
|
||||
|
||||
std::vector<FireEvent> events;
|
||||
f.combat.tick(0, f.admin, f.buildings, events);
|
||||
@@ -279,7 +283,7 @@ TEST_CASE("CombatSystem: damage not applied before impact tick", "[combat]")
|
||||
for (Tick t = 1; t < 5; ++t)
|
||||
{
|
||||
f.combat.applyPendingDamage(t, f.admin);
|
||||
REQUIRE(f.admin.get<Health>(player).hp == Approx(hpBefore));
|
||||
REQUIRE(f.admin.get<HealthComponent>(player).hp == Approx(hpBefore));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,13 +297,13 @@ TEST_CASE("CombatSystem: damage applied exactly at impact tick", "[combat]")
|
||||
const entt::entity player = f.ships.spawn(combatDef->id, 1, QVector2D(4.0f, 5.0f), false);
|
||||
f.wireEnemyTarget(enemy, player);
|
||||
|
||||
const float hpBefore = f.admin.get<Health>(player).hp;
|
||||
const float hpBefore = f.admin.get<HealthComponent>(player).hp;
|
||||
|
||||
std::vector<FireEvent> events;
|
||||
f.combat.tick(0, f.admin, f.buildings, events);
|
||||
f.combat.applyPendingDamage(5, f.admin);
|
||||
|
||||
REQUIRE(f.admin.get<Health>(player).hp < hpBefore);
|
||||
REQUIRE(f.admin.get<HealthComponent>(player).hp < hpBefore);
|
||||
}
|
||||
|
||||
TEST_CASE("CombatSystem: damage silently dropped if target already dead", "[combat]")
|
||||
@@ -333,7 +337,7 @@ TEST_CASE("CombatSystem: damage still applied if shooter already dead", "[combat
|
||||
const entt::entity player = f.ships.spawn(combatDef->id, 1, QVector2D(4.0f, 5.0f), false);
|
||||
f.wireEnemyTarget(enemy, player);
|
||||
|
||||
const float hpBefore = f.admin.get<Health>(player).hp;
|
||||
const float hpBefore = f.admin.get<HealthComponent>(player).hp;
|
||||
|
||||
std::vector<FireEvent> events;
|
||||
f.combat.tick(0, f.admin, f.buildings, events);
|
||||
@@ -342,7 +346,7 @@ TEST_CASE("CombatSystem: damage still applied if shooter already dead", "[combat
|
||||
|
||||
f.combat.applyPendingDamage(5, f.admin);
|
||||
|
||||
REQUIRE(f.admin.get<Health>(player).hp < hpBefore);
|
||||
REQUIRE(f.admin.get<HealthComponent>(player).hp < hpBefore);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -359,7 +363,7 @@ TEST_CASE("CombatSystem: dead ship is removed after tick step 9", "[combat]")
|
||||
const entt::entity ship = sim.ships().spawn(combatDef->id, 1,
|
||||
QVector2D(10.0f, 10.0f));
|
||||
|
||||
sim.admin().get<Health>(ship).hp = -1.0f;
|
||||
sim.admin().get<HealthComponent>(ship).hp = -1.0f;
|
||||
|
||||
sim.tick();
|
||||
|
||||
@@ -383,7 +387,7 @@ TEST_CASE("CombatSystem: scrap is spawned on ship death", "[combat]")
|
||||
|
||||
const entt::entity ship = sim.ships().spawn(droppingDef->id, 1,
|
||||
QVector2D(10.0f, 10.0f));
|
||||
sim.admin().get<Health>(ship).hp = -1.0f;
|
||||
sim.admin().get<HealthComponent>(ship).hp = -1.0f;
|
||||
|
||||
sim.tick();
|
||||
|
||||
@@ -395,8 +399,8 @@ TEST_CASE("CombatSystem: HQ death sets game over", "[combat]")
|
||||
Simulation sim(loadConfig(), 42);
|
||||
|
||||
// Damage the HQ proxy entity (has HqProxy + Health).
|
||||
sim.admin().forEach<HqProxy, Health>(
|
||||
[](entt::entity /*e*/, const HqProxy& /*hq*/, Health& h)
|
||||
sim.admin().forEach<HqProxyComponent, HealthComponent>(
|
||||
[](entt::entity /*e*/, const HqProxyComponent& /*hq*/, HealthComponent& h)
|
||||
{
|
||||
h.hp = -1.0f;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user