diff --git a/src/test/CombatSystemTest.cpp b/src/test/CombatSystemTest.cpp index 2c5917e..a1a82b6 100644 --- a/src/test/CombatSystemTest.cpp +++ b/src/test/CombatSystemTest.cpp @@ -194,8 +194,7 @@ TEST_CASE("CombatSystem: no fire when target is out of range", "[combat]") TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); // Find the player defence station. EntityId stationId = kInvalidEntityId; @@ -223,7 +222,7 @@ TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat] } // Find a combat ship blueprint for the enemy. - const ShipDef* combatDef = findCombatShip(cfg); + const ShipDef* combatDef = findCombatShip(sim.config()); REQUIRE(combatDef != nullptr); const EntityId enemyId = sim.ships().spawn( @@ -246,8 +245,7 @@ TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat] TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); // Find the enemy defence station. EntityId stationId = kInvalidEntityId; @@ -265,7 +263,7 @@ TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat] } REQUIRE(stationId != kInvalidEntityId); - const ShipDef* combatDef = findCombatShip(cfg); + const ShipDef* combatDef = findCombatShip(sim.config()); REQUIRE(combatDef != nullptr); // Spawn a player ship right next to the enemy station. @@ -291,10 +289,9 @@ TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat] TEST_CASE("CombatSystem: dead ship is removed after tick step 9", "[combat]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); - const ShipDef* combatDef = findCombatShip(cfg); + const ShipDef* combatDef = findCombatShip(sim.config()); REQUIRE(combatDef != nullptr); const EntityId shipId = sim.ships().spawn(combatDef->id, 1, @@ -310,12 +307,11 @@ TEST_CASE("CombatSystem: dead ship is removed after tick step 9", "[combat]") TEST_CASE("CombatSystem: scrap is spawned on ship death", "[combat]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); // Find a ship def that drops scrap. const ShipDef* droppingDef = nullptr; - for (const ShipDef& def : cfg.ships.ships) + for (const ShipDef& def : sim.config().ships.ships) { if (def.loot.scrapDrop > 0) { @@ -337,8 +333,7 @@ TEST_CASE("CombatSystem: scrap is spawned on ship death", "[combat]") TEST_CASE("CombatSystem: HQ death sets game over", "[combat]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); sim.buildings().forEachBuilding([](Building& b) { diff --git a/src/test/ShipyardTest.cpp b/src/test/ShipyardTest.cpp index a24f9d5..d4e691a 100644 --- a/src/test/ShipyardTest.cpp +++ b/src/test/ShipyardTest.cpp @@ -73,12 +73,11 @@ static void fillMaterials(Simulation& sim, EntityId yardId, const ShipDef& def) TEST_CASE("Shipyard: spawns a player ship after production cycle completes", "[shipyard]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); - const ShipDef* def = findAvailableBlueprint(cfg); + const ShipDef* def = findAvailableBlueprint(sim.config()); REQUIRE(def != nullptr); - const BuildingDef* yardDef = findShipyardDef(cfg); + const BuildingDef* yardDef = findShipyardDef(sim.config()); REQUIRE(yardDef != nullptr); const int shipsBefore = static_cast(sim.ships().allShips().size()); @@ -119,10 +118,9 @@ TEST_CASE("Shipyard: spawns a player ship after production cycle completes", TEST_CASE("Shipyard: does not spawn without a blueprint set", "[shipyard]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); - const BuildingDef* yardDef = findShipyardDef(cfg); + const BuildingDef* yardDef = findShipyardDef(sim.config()); REQUIRE(yardDef != nullptr); const int shipsBefore = static_cast(sim.ships().allShips().size()); @@ -136,12 +134,11 @@ TEST_CASE("Shipyard: does not spawn without a blueprint set", "[shipyard]") TEST_CASE("Shipyard: does not spawn with insufficient materials", "[shipyard]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); - const ShipDef* def = findAvailableBlueprint(cfg); + const ShipDef* def = findAvailableBlueprint(sim.config()); REQUIRE(def != nullptr); - const BuildingDef* yardDef = findShipyardDef(cfg); + const BuildingDef* yardDef = findShipyardDef(sim.config()); REQUIRE(yardDef != nullptr); const int shipsBefore = static_cast(sim.ships().allShips().size()); @@ -161,12 +158,11 @@ TEST_CASE("Shipyard: does not spawn with insufficient materials", "[shipyard]") TEST_CASE("Shipyard: spawns a second ship after materials replenished", "[shipyard]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); - const ShipDef* def = findAvailableBlueprint(cfg); + const ShipDef* def = findAvailableBlueprint(sim.config()); REQUIRE(def != nullptr); - const BuildingDef* yardDef = findShipyardDef(cfg); + const BuildingDef* yardDef = findShipyardDef(sim.config()); REQUIRE(yardDef != nullptr); const EntityId yardId = placeShipyard(sim, *yardDef); diff --git a/src/test/SimulationTest.cpp b/src/test/SimulationTest.cpp index dd7fc2c..c3644c0 100644 --- a/src/test/SimulationTest.cpp +++ b/src/test/SimulationTest.cpp @@ -17,16 +17,14 @@ static GameConfig loadConfig() TEST_CASE("Simulation::currentTick starts at 0", "[simulation]") { - const GameConfig config = loadConfig(); - const Simulation sim(config); + const Simulation sim(loadConfig()); REQUIRE(sim.currentTick() == 0); } TEST_CASE("Simulation::tick increments currentTick by 1", "[simulation]") { - const GameConfig config = loadConfig(); - Simulation sim(config); + Simulation sim(loadConfig()); sim.tick(); @@ -35,8 +33,7 @@ TEST_CASE("Simulation::tick increments currentTick by 1", "[simulation]") TEST_CASE("Simulation::tick 10 times yields currentTick == 10", "[simulation]") { - const GameConfig config = loadConfig(); - Simulation sim(config); + Simulation sim(loadConfig()); for (int i = 0; i < 10; ++i) { @@ -48,16 +45,14 @@ TEST_CASE("Simulation::tick 10 times yields currentTick == 10", "[simulation]") TEST_CASE("Simulation::drainFireEvents returns empty initially", "[simulation]") { - const GameConfig config = loadConfig(); - Simulation sim(config); + Simulation sim(loadConfig()); REQUIRE(sim.drainFireEvents().empty()); } TEST_CASE("Simulation::drainFireEvents clears queue on drain", "[simulation]") { - const GameConfig config = loadConfig(); - Simulation sim(config); + Simulation sim(loadConfig()); // First drain: empty. sim.drainFireEvents(); @@ -68,8 +63,7 @@ TEST_CASE("Simulation::drainFireEvents clears queue on drain", "[simulation]") TEST_CASE("Simulation::drainBlueprintDropEvents returns empty initially", "[simulation]") { - const GameConfig config = loadConfig(); - Simulation sim(config); + Simulation sim(loadConfig()); REQUIRE(sim.drainBlueprintDropEvents().empty()); } diff --git a/src/test/WaveSystemTest.cpp b/src/test/WaveSystemTest.cpp index ad4ca76..ae3f046 100644 --- a/src/test/WaveSystemTest.cpp +++ b/src/test/WaveSystemTest.cpp @@ -98,8 +98,7 @@ TEST_CASE("WaveSystem: generation starts at 0 and increments on push", "[wave]") TEST_CASE("WaveSystem: Simulation pre-places HQ + 2 player + 2 enemy stations", "[wave]") { - const GameConfig cfg = loadConfig(); - const Simulation sim(cfg, 42); + const Simulation sim(loadConfig(), 42); int hqCount = 0; int playerCount = 0; @@ -118,11 +117,10 @@ TEST_CASE("WaveSystem: Simulation pre-places HQ + 2 player + 2 enemy stations", TEST_CASE("WaveSystem: HQ has correct initial HP from config", "[wave]") { - const GameConfig cfg = loadConfig(); - const Simulation sim(cfg, 42); + const Simulation sim(loadConfig(), 42); const float expectedHp = - static_cast(cfg.stations.hq.hpFormula.evaluate(0.0)); + static_cast(sim.config().stations.hq.hpFormula.evaluate(0.0)); bool found = false; float actualHp = 0.0f; for (const Building& b : sim.buildings().allBuildings()) @@ -141,8 +139,7 @@ TEST_CASE("WaveSystem: HQ has correct initial HP from config", "[wave]") TEST_CASE("WaveSystem: HQ anchor is at asteroid right edge", "[wave]") { - const GameConfig cfg = loadConfig(); - const Simulation sim(cfg, 42); + const Simulation sim(loadConfig(), 42); for (const Building& b : sim.buildings().allBuildings()) { @@ -159,8 +156,7 @@ TEST_CASE("WaveSystem: HQ anchor is at asteroid right edge", "[wave]") TEST_CASE("WaveSystem: player stations have weapon set", "[wave]") { - const GameConfig cfg = loadConfig(); - const Simulation sim(cfg, 42); + const Simulation sim(loadConfig(), 42); int armedPlayerStations = 0; for (const Building& b : sim.buildings().allBuildings()) @@ -178,8 +174,7 @@ TEST_CASE("WaveSystem: player stations have weapon set", "[wave]") TEST_CASE("WaveSystem: enemy stations have weapon set", "[wave]") { - const GameConfig cfg = loadConfig(); - const Simulation sim(cfg, 42); + const Simulation sim(loadConfig(), 42); int armedEnemyStations = 0; for (const Building& b : sim.buildings().allBuildings()) @@ -201,8 +196,7 @@ TEST_CASE("WaveSystem: enemy stations have weapon set", "[wave]") TEST_CASE("WaveSystem: enemy ships spawn after the initial gap elapses", "[wave]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); // The maximum gap is gapMaxSeconds = 45s → 1350 ticks. // Run 1500 ticks to guarantee at least one wave has triggered. @@ -226,8 +220,7 @@ TEST_CASE("WaveSystem: enemy ships spawn after the initial gap elapses", "[wave] TEST_CASE("WaveSystem: only eligible ships (cost > 0) appear in waves", "[wave]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); // Run long enough for several waves. const int limit = static_cast(secondsToTicks(120.0)); @@ -251,8 +244,7 @@ TEST_CASE("WaveSystem: only eligible ships (cost > 0) appear in waves", "[wave]" TEST_CASE("WaveSystem: destroying both enemy stations triggers a push", "[wave]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); // Damage both enemy stations to 0. sim.buildings().forEachBuilding([](Building& b) @@ -276,8 +268,7 @@ TEST_CASE("WaveSystem: destroying both enemy stations triggers a push", "[wave]" TEST_CASE("WaveSystem: push emits exactly one BlueprintDropEvent", "[wave]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); sim.buildings().forEachBuilding([](Building& b) { @@ -295,8 +286,7 @@ TEST_CASE("WaveSystem: push emits exactly one BlueprintDropEvent", "[wave]") TEST_CASE("WaveSystem: push blueprint drop awards a known ship id", "[wave]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); sim.buildings().forEachBuilding([](Building& b) { @@ -311,7 +301,7 @@ TEST_CASE("WaveSystem: push blueprint drop awards a known ship id", "[wave]") REQUIRE(events.size() == 1); bool validId = false; - for (const ShipDef& def : cfg.ships.ships) + for (const ShipDef& def : sim.config().ships.ships) { if (def.id == events[0].blueprintId) { @@ -325,8 +315,7 @@ TEST_CASE("WaveSystem: push blueprint drop awards a known ship id", "[wave]") TEST_CASE("WaveSystem: push places new enemy stations further right", "[wave]") { - const GameConfig cfg = loadConfig(); - Simulation sim(cfg, 42); + Simulation sim(loadConfig(), 42); // Record the X position of the initial enemy stations. int initialX = std::numeric_limits::min();