fix issue where repair behavior targets enemy HQ in balancing target

This commit is contained in:
2026-06-19 21:36:04 +02:00
parent 9573b9789a
commit 4818997164
3 changed files with 58 additions and 2 deletions

View File

@@ -22,6 +22,7 @@
#include "EntityAdmin.h"
#include "FactionComponent.h"
#include "HealthComponent.h"
#include "HqProxyComponent.h"
#include "ModuleOwnerComponent.h"
#include "MovementIntentComponent.h"
#include "MovementIntentSystem.h"
@@ -862,6 +863,48 @@ TEST_CASE("RepairSystem: does not crash when a tool's owner is not a repair ship
REQUIRE_FALSE(f.admin.get<RepairToolComponent>(moduleEntity).currentTarget.has_value());
}
TEST_CASE("RepairSystem: repair tool does not repair an HQ", "[behavior]")
{
Fixture f;
const ShipLayoutConfig repairLayout = makeSingleModuleLayout("repair_tool");
const entt::entity repairShip = f.ships.spawn("repair_ship", 1, QVector2D(0.0f, 0.0f),
false, repairLayout);
// A damaged, same-faction HQ in repair range — spawned as a station and tagged
// as an HQ (as the balancing arena does). The HQ is not a repair target.
const std::vector<QPoint> cells = {QPoint(2, 0), QPoint(3, 0), QPoint(2, 1), QPoint(3, 1)};
const entt::entity hq = f.admin.spawnStation(QPoint(2, 0), QSize(2, 2), cells,
100.0f, 200.0f, false);
f.admin.addComponent<HqProxyComponent>(hq);
f.decide();
f.runRepairHeal();
REQUIRE(f.admin.get<HealthComponent>(hq).hp == Approx(100.0f));
const entt::entity rc = firstRepairChild(f.admin, repairShip);
REQUIRE_FALSE(f.admin.get<RepairToolComponent>(rc).currentTarget.has_value());
}
TEST_CASE("RepairSystem: repair tool still repairs a damaged defence station", "[behavior]")
{
Fixture f;
const ShipLayoutConfig repairLayout = makeSingleModuleLayout("repair_tool");
const entt::entity repairShip = f.ships.spawn("repair_ship", 1, QVector2D(0.0f, 0.0f),
false, repairLayout);
// A damaged, same-faction defence station (no HQ tag) in repair range.
const std::vector<QPoint> cells = {QPoint(2, 0), QPoint(3, 0), QPoint(2, 1), QPoint(3, 1)};
const entt::entity station = f.admin.spawnStation(QPoint(2, 0), QSize(2, 2), cells,
100.0f, 200.0f, false);
f.decide();
f.runRepairHeal();
REQUIRE(f.admin.get<HealthComponent>(station).hp > 100.0f);
const entt::entity rc = firstRepairChild(f.admin, repairShip);
REQUIRE(*f.admin.get<RepairToolComponent>(rc).currentTarget == station);
}
// ---------------------------------------------------------------------------
// SalvageScrapBehavior / DeliverScrapBehavior
// ---------------------------------------------------------------------------