derive threat cost dynamically

This commit is contained in:
2026-06-13 21:50:00 +02:00
parent 3716c2b734
commit 10c5ad678f
28 changed files with 498 additions and 79 deletions

View File

@@ -22,6 +22,7 @@
#include "ShipsConfig.h"
#include "Simulation.h"
#include "Tick.h"
#include "ThreatCostCalculator.h"
#include "WaveSystem.h"
static GameConfig loadConfig()
@@ -201,25 +202,16 @@ TEST_CASE("WaveSystem: enemy ships spawn after the initial gap elapses", "[wave]
REQUIRE(foundEnemyShip);
}
TEST_CASE("WaveSystem: only eligible ships (cost > 0) appear in waves", "[wave]")
TEST_CASE("WaveSystem: all ships have positive dynamic threat cost", "[wave]")
{
Simulation sim(loadConfig(), 42);
const GameConfig cfg = loadConfig();
// Run long enough for several waves.
const int limit = static_cast<int>(secondsToTicks(120.0));
for (int i = 0; i < limit; ++i)
for (const ShipDef& def : cfg.ships.ships)
{
sim.tick();
const double cost = calculateShipThreatCost(cfg.threatCosts, cfg,
def.id, def.defaultModules);
CHECK(cost > 0.0);
}
sim.admin().forEach<ShipIdentityComponent, FactionComponent>(
[&](entt::entity /*e*/, const ShipIdentityComponent& si, const FactionComponent& f)
{
if (!f.isEnemy) { return; }
// salvage_ship and repair_ship have cost_formula = "0" and must not spawn.
REQUIRE(si.schematicId != "salvage_ship");
REQUIRE(si.schematicId != "repair_ship");
});
}
// ---------------------------------------------------------------------------