define ship roles via added modules and allow multiple weapons

This commit is contained in:
2026-06-01 22:57:53 +02:00
parent f363f7a67c
commit 9d0a60a93b
31 changed files with 873 additions and 407 deletions

View File

@@ -2,8 +2,8 @@
#include "EntityAdmin.h"
#include "FactionComponent.h"
#include "StationBodyComponent.h"
#include "HealthComponent.h"
#include "ModuleOwnerComponent.h"
#include "PositionComponent.h"
#include "SensorRangeComponent.h"
#include "ShipIdentityComponent.h"
@@ -22,24 +22,18 @@ void CombatSystem::tick(Tick currentTick,
BuildingSystem& /*buildings*/,
std::vector<FireEvent>& outFireEvents)
{
// Ship weapons.
admin.forEach<WeaponComponent, ThreatResponseBehaviorComponent,
PositionComponent, FactionComponent>(
[&](entt::entity e, WeaponComponent& weapon,
ThreatResponseBehaviorComponent& threatResponseBehavior,
PositionComponent& pos, FactionComponent& faction)
// All weapons (ships and stations) are child entities linked via ModuleOwnerComponent.
admin.forEach<WeaponComponent, ModuleOwnerComponent>(
[&](entt::entity /*e*/, WeaponComponent& weapon, const ModuleOwnerComponent& owner)
{
weapon.currentTarget = threatResponseBehavior.currentTarget;
resolveWeapon(e, weapon, pos, faction, currentTick, admin, outFireEvents);
});
// 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, const StationBodyComponent& /*sb*/)
{
resolveWeapon(e, weapon, pos, faction, currentTick, admin, outFireEvents);
if (admin.hasAll<ThreatResponseBehaviorComponent>(owner.owner))
{
weapon.currentTarget =
admin.get<ThreatResponseBehaviorComponent>(owner.owner).currentTarget;
}
const PositionComponent& pos = admin.get<PositionComponent>(owner.owner);
const FactionComponent& faction = admin.get<FactionComponent>(owner.owner);
resolveWeapon(owner.owner, weapon, pos, faction, currentTick, admin, outFireEvents);
});
}