fix tests

This commit is contained in:
2026-05-25 21:00:15 +02:00
parent 25ff3c56c5
commit 9e36c13635
3 changed files with 28 additions and 8 deletions

View File

@@ -2,8 +2,10 @@
#include "EntityAdmin.h"
#include "FactionComponent.h"
#include "StationBodyComponent.h"
#include "HealthComponent.h"
#include "PositionComponent.h"
#include "SensorRangeComponent.h"
#include "ShipIdentityComponent.h"
#include "ThreatResponseBehaviorComponent.h"
#include "WeaponComponent.h"
@@ -31,10 +33,11 @@ void CombatSystem::tick(Tick currentTick,
resolveWeapon(e, weapon, pos, faction, currentTick, admin, outFireEvents);
});
// Station weapons.
admin.forEach<WeaponComponent, PositionComponent, FactionComponent>(
// Station weapons (entities with StationBodyComponent; ships are excluded because
// they lack that component and are already handled by the ship loop above).
admin.forEach<WeaponComponent, PositionComponent, FactionComponent, StationBodyComponent>(
[&](entt::entity e, WeaponComponent& weapon, PositionComponent& pos,
FactionComponent& faction)
FactionComponent& faction, const StationBodyComponent& /*sb*/)
{
resolveWeapon(e, weapon, pos, faction, currentTick, admin, outFireEvents);
});
@@ -77,10 +80,14 @@ void CombatSystem::resolveWeapon(
}
}
// Acquire a new target if needed (nearest opposing-faction ship).
// Acquire a new target if needed.
// Ships use their sensor range; stations fall back to weapon range.
if (!weapon.currentTarget)
{
float bestDistanceSquared = weapon.range * weapon.range;
const float acquisitionRange = admin.hasAll<SensorRangeComponent>(shipEntity)
? admin.get<SensorRangeComponent>(shipEntity).value
: weapon.range;
float bestDistanceSquared = acquisitionRange * acquisitionRange;
admin.forEach<ShipIdentityComponent, PositionComponent, FactionComponent>(
[&](entt::entity candidate, const ShipIdentityComponent& /*si*/,
const PositionComponent& candidatePos,