rename behavior components
This commit is contained in:
@@ -69,8 +69,8 @@ struct ShipIdentity
|
||||
// ---------------------------------------------------------------------------
|
||||
// Ship optional components (hardware + behavior, in Ship.h)
|
||||
// ---------------------------------------------------------------------------
|
||||
// Weapon, SalvageCargo, RepairTool, ThreatResponse, ScrapCollector,
|
||||
// RepairBehavior, HomeReturn, RallyBehavior remain defined in Ship.h.
|
||||
// Weapon, SalvageCargo, RepairTool, ThreatResponseBehavior, SalvageBehavior,
|
||||
// RepairBehavior, HomeReturnBehavior, RallyBehavior remain defined in Ship.h.
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Station components
|
||||
|
||||
@@ -16,29 +16,29 @@
|
||||
#include "Ship.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// tickHomeReturn (priority 4)
|
||||
// tickHomeReturnBehavior (priority 4)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void AiSystem::tickHomeReturn(EntityAdmin& admin)
|
||||
void AiSystem::tickHomeReturnBehavior(EntityAdmin& admin)
|
||||
{
|
||||
admin.forEach<HomeReturn, Health, MovementIntent>(
|
||||
[](entt::entity /*e*/, const HomeReturn& hr, const Health& h, MovementIntent& intent)
|
||||
admin.forEach<HomeReturnBehavior, Health, MovementIntent>(
|
||||
[](entt::entity /*e*/, const HomeReturnBehavior& homeReturnBehavior, const Health& h, MovementIntent& intent)
|
||||
{
|
||||
if (h.hp / h.maxHp < hr.retreatHpFraction)
|
||||
if (h.hp / h.maxHp < homeReturnBehavior.retreatHpFraction)
|
||||
{
|
||||
if (4 > intent.priority)
|
||||
{
|
||||
intent = MovementIntent{4, hr.homePos};
|
||||
intent = MovementIntent{4, homeReturnBehavior.homePos};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// tickThreatResponse (priority 3)
|
||||
// tickThreatResponseBehavior (priority 3)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void AiSystem::tickThreatResponse(EntityAdmin& admin, const BuildingSystem& buildings)
|
||||
void AiSystem::tickThreatResponseBehavior(EntityAdmin& admin, const BuildingSystem& buildings)
|
||||
{
|
||||
// Snapshot all combatant entities for target acquisition.
|
||||
struct CombatantInfo
|
||||
@@ -68,17 +68,17 @@ void AiSystem::tickThreatResponse(EntityAdmin& admin, const BuildingSystem& buil
|
||||
combatants.push_back({e, pos.value, f.isEnemy, true});
|
||||
});
|
||||
|
||||
admin.forEach<ThreatResponse, Position, Faction, SensorRange, MovementIntent>(
|
||||
[&](entt::entity e, ThreatResponse& threat, Position& pos, Faction& faction,
|
||||
admin.forEach<ThreatResponseBehavior, Position, Faction, SensorRange, MovementIntent>(
|
||||
[&](entt::entity e, ThreatResponseBehavior& threatResponseBehavior, Position& pos, Faction& faction,
|
||||
SensorRange& sensor, MovementIntent& intent)
|
||||
{
|
||||
const float range = sensor.value;
|
||||
|
||||
// Validate current target.
|
||||
bool targetValid = false;
|
||||
if (threat.currentTarget)
|
||||
if (threatResponseBehavior.currentTarget)
|
||||
{
|
||||
const entt::entity t = *threat.currentTarget;
|
||||
const entt::entity t = *threatResponseBehavior.currentTarget;
|
||||
if (admin.isValid(t) && admin.hasAll<Position>(t))
|
||||
{
|
||||
const float dist = (admin.get<Position>(t).value - pos.value).length();
|
||||
@@ -91,7 +91,7 @@ void AiSystem::tickThreatResponse(EntityAdmin& admin, const BuildingSystem& buil
|
||||
|
||||
if (!targetValid)
|
||||
{
|
||||
threat.currentTarget = std::nullopt;
|
||||
threatResponseBehavior.currentTarget = std::nullopt;
|
||||
float bestDist = range;
|
||||
|
||||
for (const CombatantInfo& c : combatants)
|
||||
@@ -113,14 +113,14 @@ void AiSystem::tickThreatResponse(EntityAdmin& admin, const BuildingSystem& buil
|
||||
if (dist < bestDist)
|
||||
{
|
||||
bestDist = dist;
|
||||
threat.currentTarget = c.entity;
|
||||
threatResponseBehavior.currentTarget = c.entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (threat.currentTarget)
|
||||
if (threatResponseBehavior.currentTarget)
|
||||
{
|
||||
const entt::entity t = *threat.currentTarget;
|
||||
const entt::entity t = *threatResponseBehavior.currentTarget;
|
||||
QVector2D dest = pos.value;
|
||||
if (admin.isValid(t) && admin.hasAll<Position>(t))
|
||||
{
|
||||
@@ -298,11 +298,11 @@ void AiSystem::tickRepairBehavior(EntityAdmin& admin, BuildingSystem& buildings)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// tickScrapCollector (priority 1)
|
||||
// tickSalvageBehavior (priority 1)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void AiSystem::tickScrapCollector(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
BuildingSystem& buildings)
|
||||
void AiSystem::tickSalvageBehavior(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
BuildingSystem& buildings)
|
||||
{
|
||||
// Snapshot enemy ships for threat detection.
|
||||
struct EnemyShipPos
|
||||
@@ -322,24 +322,24 @@ void AiSystem::tickScrapCollector(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
|
||||
const std::vector<ScrapInfo> allScrap = scraps.allScrapInfo();
|
||||
|
||||
admin.forEach<ScrapCollector, SalvageCargo, Position, SensorRange, MovementIntent>(
|
||||
[&](entt::entity /*e*/, ScrapCollector& sc, SalvageCargo& cargo,
|
||||
admin.forEach<SalvageBehavior, SalvageCargo, Position, SensorRange, MovementIntent>(
|
||||
[&](entt::entity /*e*/, SalvageBehavior& salvageBehavior, SalvageCargo& cargo,
|
||||
Position& pos, SensorRange& sensor, MovementIntent& intent)
|
||||
{
|
||||
const float collectRange = cargo.collectionRange;
|
||||
|
||||
// Assign nearest SalvageBay if needed.
|
||||
if (sc.deliveryBay == kInvalidBuildingId)
|
||||
if (salvageBehavior.deliveryBay == kInvalidBuildingId)
|
||||
{
|
||||
const Building* bay = buildings.findNearestBuilding(pos.value,
|
||||
BuildingType::SalvageBay);
|
||||
if (bay)
|
||||
{
|
||||
sc.deliveryBay = bay->id;
|
||||
salvageBehavior.deliveryBay = bay->id;
|
||||
}
|
||||
}
|
||||
|
||||
const BuildingId bayId = sc.deliveryBay;
|
||||
const BuildingId bayId = salvageBehavior.deliveryBay;
|
||||
|
||||
QVector2D bayPos = pos.value;
|
||||
if (bayId != kInvalidBuildingId)
|
||||
@@ -398,18 +398,18 @@ void AiSystem::tickScrapCollector(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
if (scraps.consume(si.entity))
|
||||
{
|
||||
++cargo.current;
|
||||
sc.scrapTarget = std::nullopt;
|
||||
salvageBehavior.scrapTarget = std::nullopt;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Move toward scrap target or find a new one.
|
||||
if (sc.scrapTarget)
|
||||
if (salvageBehavior.scrapTarget)
|
||||
{
|
||||
if (1 > intent.priority)
|
||||
{
|
||||
intent = MovementIntent{1, *sc.scrapTarget};
|
||||
intent = MovementIntent{1, *salvageBehavior.scrapTarget};
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -427,7 +427,7 @@ void AiSystem::tickScrapCollector(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
}
|
||||
if (bestPos)
|
||||
{
|
||||
sc.scrapTarget = bestPos;
|
||||
salvageBehavior.scrapTarget = bestPos;
|
||||
if (1 > intent.priority)
|
||||
{
|
||||
intent = MovementIntent{1, *bestPos};
|
||||
|
||||
@@ -7,8 +7,8 @@ class ScrapSystem;
|
||||
class AiSystem
|
||||
{
|
||||
public:
|
||||
void tickHomeReturn(EntityAdmin& admin);
|
||||
void tickThreatResponse(EntityAdmin& admin, const BuildingSystem& buildings);
|
||||
void tickHomeReturnBehavior(EntityAdmin& admin);
|
||||
void tickThreatResponseBehavior(EntityAdmin& admin, const BuildingSystem& buildings);
|
||||
void tickRepairBehavior(EntityAdmin& admin, BuildingSystem& buildings);
|
||||
void tickScrapCollector(EntityAdmin& admin, ScrapSystem& scraps, BuildingSystem& buildings);
|
||||
void tickSalvageBehavior(EntityAdmin& admin, ScrapSystem& scraps, BuildingSystem& buildings);
|
||||
};
|
||||
|
||||
@@ -16,10 +16,10 @@ void CombatSystem::tick(Tick currentTick,
|
||||
std::vector<FireEvent>& outFireEvents)
|
||||
{
|
||||
// Ship weapons.
|
||||
admin.forEach<Weapon, ThreatResponse, Position, Faction>(
|
||||
[&](entt::entity e, Weapon& weapon, ThreatResponse& threat, Position& pos, Faction& faction)
|
||||
admin.forEach<Weapon, ThreatResponseBehavior, Position, Faction>(
|
||||
[&](entt::entity e, Weapon& weapon, ThreatResponseBehavior& threatResponseBehavior, Position& pos, Faction& faction)
|
||||
{
|
||||
weapon.currentTarget = threat.currentTarget;
|
||||
weapon.currentTarget = threatResponseBehavior.currentTarget;
|
||||
resolveWeapon(e, weapon, pos, faction, currentTick, admin, outFireEvents);
|
||||
});
|
||||
|
||||
|
||||
@@ -41,12 +41,12 @@ struct RepairTool
|
||||
// Behavior components — AI state consumed by step-6 behavior systems
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct ThreatResponse
|
||||
struct ThreatResponseBehavior
|
||||
{
|
||||
std::optional<entt::entity> currentTarget;
|
||||
};
|
||||
|
||||
struct ScrapCollector
|
||||
struct SalvageBehavior
|
||||
{
|
||||
std::optional<QVector2D> scrapTarget;
|
||||
BuildingId deliveryBay; // kInvalidBuildingId until assigned at a salvage bay
|
||||
@@ -57,7 +57,7 @@ struct RepairBehavior
|
||||
std::optional<entt::entity> currentTarget;
|
||||
};
|
||||
|
||||
struct HomeReturn
|
||||
struct HomeReturnBehavior
|
||||
{
|
||||
float retreatHpFraction;
|
||||
QVector2D homePos;
|
||||
|
||||
@@ -75,7 +75,7 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level, QVecto
|
||||
w.currentTarget = std::nullopt;
|
||||
m_admin.addComponent<Weapon>(entity, w);
|
||||
|
||||
m_admin.addComponent<ThreatResponse>(entity, ThreatResponse{});
|
||||
m_admin.addComponent<ThreatResponseBehavior>(entity, ThreatResponseBehavior{});
|
||||
|
||||
if (!isEnemy)
|
||||
{
|
||||
@@ -91,10 +91,10 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level, QVecto
|
||||
cargo.collectionRange = static_cast<float>(def->salvage->collectionRange);
|
||||
m_admin.addComponent<SalvageCargo>(entity, cargo);
|
||||
|
||||
ScrapCollector sc;
|
||||
sc.scrapTarget = std::nullopt;
|
||||
sc.deliveryBay = kInvalidBuildingId;
|
||||
m_admin.addComponent<ScrapCollector>(entity, sc);
|
||||
SalvageBehavior salvageBehavior;
|
||||
salvageBehavior.scrapTarget = std::nullopt;
|
||||
salvageBehavior.deliveryBay = kInvalidBuildingId;
|
||||
m_admin.addComponent<SalvageBehavior>(entity, salvageBehavior);
|
||||
}
|
||||
|
||||
if (def->repair)
|
||||
|
||||
@@ -162,10 +162,10 @@ void Simulation::tick()
|
||||
}
|
||||
|
||||
m_shipSystem->clearMovementIntents();
|
||||
m_aiSystem->tickHomeReturn(m_admin); // priority 4
|
||||
m_aiSystem->tickThreatResponse(m_admin, *m_buildingSystem); // priority 3
|
||||
m_aiSystem->tickRepairBehavior(m_admin, *m_buildingSystem); // priority 2
|
||||
m_aiSystem->tickScrapCollector(m_admin, *m_scrapSystem, *m_buildingSystem); // priority 1
|
||||
m_aiSystem->tickHomeReturnBehavior(m_admin); // priority 4
|
||||
m_aiSystem->tickThreatResponseBehavior(m_admin, *m_buildingSystem); // priority 3
|
||||
m_aiSystem->tickRepairBehavior(m_admin, *m_buildingSystem); // priority 2
|
||||
m_aiSystem->tickSalvageBehavior(m_admin, *m_scrapSystem, *m_buildingSystem); // priority 1
|
||||
|
||||
// Step 8: combat resolution
|
||||
m_combatSystem->tick(m_currentTick, m_admin,
|
||||
|
||||
Reference in New Issue
Block a user