make stations not attack other stations

This commit is contained in:
2026-04-21 21:42:54 +02:00
parent 6321e13a00
commit 2523cd6a1b
2 changed files with 4 additions and 29 deletions

View File

@@ -121,8 +121,7 @@ void CombatSystem::resolveStationWeapon(Building& station, Tick currentTick,
// Acquire a new target if needed. // Acquire a new target if needed.
if (!w.currentTarget) if (!w.currentTarget)
{ {
w.currentTarget = acquireStationTarget(station, stationIsEnemy, w.currentTarget = acquireStationTarget(station, stationIsEnemy, ships);
ships, buildings);
} }
if (!w.currentTarget) if (!w.currentTarget)
@@ -174,8 +173,7 @@ void CombatSystem::resolveStationWeapon(Building& station, Tick currentTick,
std::optional<EntityId> CombatSystem::acquireStationTarget( std::optional<EntityId> CombatSystem::acquireStationTarget(
const Building& station, bool stationIsEnemy, const Building& station, bool stationIsEnemy,
const ShipSystem& ships, const ShipSystem& ships) const
const BuildingSystem& buildings) const
{ {
const QVector2D stationCenter( const QVector2D stationCenter(
station.anchor.x() + station.footprint.width() / 2.0f, station.anchor.x() + station.footprint.width() / 2.0f,
@@ -202,27 +200,6 @@ std::optional<EntityId> CombatSystem::acquireStationTarget(
} }
} }
// Enemy stations also target player buildings (HQ, PlayerDefenceStation).
if (stationIsEnemy)
{
for (const Building& b : buildings.allBuildings())
{
if (b.type != BuildingType::Hq &&
b.type != BuildingType::PlayerDefenceStation)
{
continue;
}
const QVector2D bCenter(b.anchor.x() + b.footprint.width() / 2.0f,
b.anchor.y() + b.footprint.height() / 2.0f);
const float dist = (bCenter - stationCenter).length();
if (dist < bestDist)
{
bestDist = dist;
best = b.id;
}
}
}
return best; return best;
} }

View File

@@ -45,12 +45,10 @@ private:
std::vector<FireEvent>& out); std::vector<FireEvent>& out);
// Find the nearest valid target for a defence station within its range. // Find the nearest valid target for a defence station within its range.
// Enemy stations target player ships + HQ + PlayerDefenceStation. // Both enemy and player stations target ships of the opposing faction only.
// Player stations target enemy ships only.
std::optional<EntityId> acquireStationTarget( std::optional<EntityId> acquireStationTarget(
const Building& station, bool stationIsEnemy, const Building& station, bool stationIsEnemy,
const ShipSystem& ships, const ShipSystem& ships) const;
const BuildingSystem& buildings) const;
// Return the world position of the entity, or nullopt if it no longer exists. // Return the world position of the entity, or nullopt if it no longer exists.
std::optional<QVector2D> targetPosition(EntityId id, std::optional<QVector2D> targetPosition(EntityId id,