advance towards enemy buildings

This commit is contained in:
2026-06-15 20:52:43 +02:00
parent e8dd73bcb0
commit 6b7c3df64a
2 changed files with 141 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
#include <random>
#include <QPoint>
#include <QSize>
#include <QVector2D>
#include "AdvanceBehavior.h"
@@ -383,6 +384,58 @@ TEST_CASE("BehaviorSystem: enemy ship with no target advances leftward",
REQUIRE(intent(f.admin, enemy).target.x() < 0.0f);
}
TEST_CASE("BehaviorSystem: advancing ship targets center between enemy defence stations",
"[behavior]")
{
Fixture f;
// Two enemy defence stations far from the ship (out of sensor/attack range),
// 1x1 footprint so each center is anchor + (0.5, 0.5).
const std::vector<QPoint> body{QPoint(0, 0)};
f.admin.spawnStation(QPoint(1000, 10), QSize(1, 1), body, 100.0f, 100.0f, /*isEnemy=*/true);
f.admin.spawnStation(QPoint(1000, 30), QSize(1, 1), body, 100.0f, 100.0f, /*isEnemy=*/true);
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f),
/*isEnemy=*/false);
// Player ships rally until departure; drop Rally so Advance is the fallback.
f.ships.triggerRallyDeparture();
f.decide();
// Centers (1000.5, 10.5) and (1000.5, 30.5) -> midpoint (1000.5, 20.5).
REQUIRE(winnerOf(f.admin, player) == BehaviorKind::Advance);
REQUIRE(intent(f.admin, player).active);
REQUIRE(intent(f.admin, player).target.x() == Approx(1000.5f));
REQUIRE(intent(f.admin, player).target.y() == Approx(20.5f));
}
TEST_CASE("BehaviorSystem: advancing ship falls back to enemy HQ, then off-world",
"[behavior]")
{
Fixture f;
// Player HQ proxy (isEnemy=false) but no player defence stations.
const QVector2D hqPos(5.0f, 7.0f);
const entt::entity hq = f.admin.spawnHqProxy(hqPos, 100.0f, 100.0f);
const entt::entity enemy = f.ships.spawn("interceptor", 1, QVector2D(1000.0f, 0.0f),
/*isEnemy=*/true);
f.decide();
REQUIRE(winnerOf(f.admin, enemy) == BehaviorKind::Advance);
REQUIRE(intent(f.admin, enemy).active);
REQUIRE(intent(f.admin, enemy).target.x() == Approx(hqPos.x()));
REQUIRE(intent(f.admin, enemy).target.y() == Approx(hqPos.y()));
// With the HQ gone too, the ship falls back to advancing off-world (leftward).
f.admin.get<HealthComponent>(hq).hp = 0.0f;
f.decide();
REQUIRE(winnerOf(f.admin, enemy) == BehaviorKind::Advance);
REQUIRE(intent(f.admin, enemy).target.x() < 0.0f);
}
// ---------------------------------------------------------------------------
// RepairBehavior
// ---------------------------------------------------------------------------