fix bug where player ships did not fire on enemy defense stations
This commit is contained in:
@@ -245,7 +245,7 @@ void ShipSystem::tickThreatResponse(const BuildingSystem& buildings)
|
||||
|
||||
if (!s.isEnemy)
|
||||
{
|
||||
// Player combat ship: target nearest enemy ship.
|
||||
// Player combat ship: target nearest enemy ship or enemy building.
|
||||
if (!isTargetValid(s.threatResponse->currentTarget.value_or(kInvalidEntityId),
|
||||
range, s, buildings))
|
||||
{
|
||||
@@ -264,14 +264,39 @@ void ShipSystem::tickThreatResponse(const BuildingSystem& buildings)
|
||||
s.threatResponse->currentTarget = candidate.id;
|
||||
}
|
||||
}
|
||||
|
||||
for (const Building& b : allBuildings)
|
||||
{
|
||||
if (b.type != BuildingType::EnemyDefenceStation)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float dist = (buildingCenter(b) - s.position).length();
|
||||
if (dist < bestDist)
|
||||
{
|
||||
bestDist = dist;
|
||||
s.threatResponse->currentTarget = b.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s.threatResponse->currentTarget)
|
||||
{
|
||||
const Ship* target = findShip(*s.threatResponse->currentTarget);
|
||||
if (target && 3 > s.intent.priority)
|
||||
QVector2D dest;
|
||||
const Ship* tShip = findShip(*s.threatResponse->currentTarget);
|
||||
if (tShip)
|
||||
{
|
||||
s.intent = MovementIntent{3, target->position};
|
||||
dest = tShip->position;
|
||||
}
|
||||
else
|
||||
{
|
||||
const Building* tBld = buildings.findBuilding(
|
||||
*s.threatResponse->currentTarget);
|
||||
dest = tBld ? buildingCenter(*tBld) : s.position;
|
||||
}
|
||||
if (3 > s.intent.priority)
|
||||
{
|
||||
s.intent = MovementIntent{3, dest};
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user