fix bug where player ships did not fire on enemy defense stations
This commit is contained in:
@@ -283,6 +283,47 @@ TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]
|
||||
REQUIRE(stationFired);
|
||||
}
|
||||
|
||||
TEST_CASE("CombatSystem: player ship fires at enemy station in range", "[combat]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
|
||||
EntityId stationId = kInvalidEntityId;
|
||||
QVector2D stationCenter;
|
||||
for (const Building& b : sim.buildings().allBuildings())
|
||||
{
|
||||
if (b.type == BuildingType::EnemyDefenceStation)
|
||||
{
|
||||
stationId = b.id;
|
||||
stationCenter = QVector2D(
|
||||
b.anchor.x() + b.footprint.width() / 2.0f,
|
||||
b.anchor.y() + b.footprint.height() / 2.0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
REQUIRE(stationId != kInvalidEntityId);
|
||||
|
||||
const ShipDef* combatDef = findCombatShip(sim.config());
|
||||
REQUIRE(combatDef != nullptr);
|
||||
|
||||
const EntityId playerId = sim.ships().spawn(
|
||||
combatDef->id, 1,
|
||||
QVector2D(stationCenter.x() - 1.0f, stationCenter.y()),
|
||||
/*isEnemy=*/false);
|
||||
|
||||
sim.tick();
|
||||
|
||||
const std::vector<FireEvent> events = sim.drainFireEvents();
|
||||
bool playerFiredAtStation = false;
|
||||
for (const FireEvent& e : events)
|
||||
{
|
||||
if (e.shooter == playerId && e.target == stationId)
|
||||
{
|
||||
playerFiredAtStation = true;
|
||||
}
|
||||
}
|
||||
REQUIRE(playerFiredAtStation);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Deaths & loot (tick step 9)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user