switch to ECS architecture
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include "BuildingSystem.h"
|
||||
#include "BuildingType.h"
|
||||
#include "ConfigLoader.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "GameConfig.h"
|
||||
#include "ItemType.h"
|
||||
#include "Rotation.h"
|
||||
@@ -51,6 +53,14 @@ static EntityId placeShipyard(Simulation& sim, const BuildingDef& yardDef)
|
||||
100.0f, 100.0f);
|
||||
}
|
||||
|
||||
static int countShips(Simulation& sim)
|
||||
{
|
||||
int n = 0;
|
||||
sim.admin().forEach<ShipIdentity>(
|
||||
[&n](entt::entity /*e*/, const ShipIdentity& /*si*/) { ++n; });
|
||||
return n;
|
||||
}
|
||||
|
||||
static void fillMaterials(Simulation& sim, EntityId yardId, const ShipDef& def)
|
||||
{
|
||||
sim.buildings().forEachBuilding([&](Building& b)
|
||||
@@ -80,7 +90,7 @@ TEST_CASE("Shipyard: spawns a player ship after production cycle completes",
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||
REQUIRE(yardDef != nullptr);
|
||||
|
||||
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
||||
const int shipsBefore = countShips(sim);
|
||||
|
||||
const EntityId yardId = placeShipyard(sim, *yardDef);
|
||||
REQUIRE(yardId != kInvalidEntityId);
|
||||
@@ -90,7 +100,7 @@ TEST_CASE("Shipyard: spawns a player ship after production cycle completes",
|
||||
|
||||
// First tick: materials consumed, production cycle starts — no ship yet.
|
||||
sim.tick();
|
||||
REQUIRE(static_cast<int>(sim.ships().allShips().size()) == shipsBefore);
|
||||
REQUIRE(countShips(sim) == shipsBefore);
|
||||
|
||||
// Tick until the cycle completes.
|
||||
const Tick cycleTicks = secondsToTicks(def->schematic.productionTimeSeconds);
|
||||
@@ -98,21 +108,21 @@ TEST_CASE("Shipyard: spawns a player ship after production cycle completes",
|
||||
{
|
||||
sim.tick();
|
||||
}
|
||||
REQUIRE(static_cast<int>(sim.ships().allShips().size()) == shipsBefore);
|
||||
REQUIRE(countShips(sim) == shipsBefore);
|
||||
|
||||
// Final tick: cycle completes, ship spawns.
|
||||
sim.tick();
|
||||
REQUIRE(static_cast<int>(sim.ships().allShips().size()) == shipsBefore + 1);
|
||||
REQUIRE(countShips(sim) == shipsBefore + 1);
|
||||
|
||||
bool foundPlayerShip = false;
|
||||
for (const Ship& ship : sim.ships().allShips())
|
||||
{
|
||||
if (!ship.isEnemy && ship.schematicId == def->id)
|
||||
sim.admin().forEach<ShipIdentity, Faction>(
|
||||
[&](entt::entity /*e*/, const ShipIdentity& si, const Faction& f)
|
||||
{
|
||||
foundPlayerShip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!f.isEnemy && si.schematicId == def->id)
|
||||
{
|
||||
foundPlayerShip = true;
|
||||
}
|
||||
});
|
||||
REQUIRE(foundPlayerShip);
|
||||
}
|
||||
|
||||
@@ -123,13 +133,13 @@ TEST_CASE("Shipyard: does not spawn without a schematic set", "[shipyard]")
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||
REQUIRE(yardDef != nullptr);
|
||||
|
||||
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
||||
const int shipsBefore = countShips(sim);
|
||||
|
||||
placeShipyard(sim, *yardDef);
|
||||
|
||||
sim.tick();
|
||||
|
||||
REQUIRE(static_cast<int>(sim.ships().allShips().size()) == shipsBefore);
|
||||
REQUIRE(countShips(sim) == shipsBefore);
|
||||
}
|
||||
|
||||
TEST_CASE("Shipyard: does not spawn with insufficient materials", "[shipyard]")
|
||||
@@ -141,7 +151,7 @@ TEST_CASE("Shipyard: does not spawn with insufficient materials", "[shipyard]")
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||
REQUIRE(yardDef != nullptr);
|
||||
|
||||
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
||||
const int shipsBefore = countShips(sim);
|
||||
|
||||
const EntityId yardId = placeShipyard(sim, *yardDef);
|
||||
sim.buildings().setRecipe(yardId, def->id);
|
||||
@@ -153,7 +163,7 @@ TEST_CASE("Shipyard: does not spawn with insufficient materials", "[shipyard]")
|
||||
sim.tick();
|
||||
}
|
||||
|
||||
REQUIRE(static_cast<int>(sim.ships().allShips().size()) == shipsBefore);
|
||||
REQUIRE(countShips(sim) == shipsBefore);
|
||||
}
|
||||
|
||||
TEST_CASE("Shipyard: spawns a second ship after materials replenished", "[shipyard]")
|
||||
@@ -176,7 +186,7 @@ TEST_CASE("Shipyard: spawns a second ship after materials replenished", "[shipya
|
||||
{
|
||||
sim.tick();
|
||||
}
|
||||
const int after1 = static_cast<int>(sim.ships().allShips().size());
|
||||
const int after1 = countShips(sim);
|
||||
|
||||
// Second cycle: capture count immediately after the next spawn tick.
|
||||
fillMaterials(sim, yardId, *def);
|
||||
@@ -184,7 +194,7 @@ TEST_CASE("Shipyard: spawns a second ship after materials replenished", "[shipya
|
||||
{
|
||||
sim.tick();
|
||||
}
|
||||
const int after2 = static_cast<int>(sim.ships().allShips().size());
|
||||
const int after2 = countShips(sim);
|
||||
|
||||
// After each cycle one ship was added; ships from prior cycles may have died
|
||||
// from enemy fire, so we only assert the most-recent spawn is still present.
|
||||
|
||||
Reference in New Issue
Block a user