#include "RepairExecutor.h" #include "BehaviorKind.h" #include "EntityAdmin.h" #include "ModuleOwnerComponent.h" #include "MovementIntentComponent.h" #include "OrbitMath.h" #include "PositionComponent.h" #include "RepairBehavior.h" #include "RepairToolComponent.h" #include "SelectedBehaviorComponent.h" #include "tracing.h" void RepairExecutor::execute(EntityAdmin& admin) { TRACE(); // Ships: move toward the repair target. admin.forEach( [&](entt::entity /*e*/, const RepairBehavior& repair, const SelectedBehaviorComponent& selected, const PositionComponent& pos, MovementIntentComponent& intent) { if (selected.winner != BehaviorKind::Repair) { return; } if (!repair.currentTarget) { return; } const entt::entity t = *repair.currentTarget; QVector2D dest = pos.value; if (admin.isValid(t) && admin.hasAll(t)) { const QVector2D targetPos = admin.get(t).value; dest = OrbitMath::computeOrbitDestination(pos.value, targetPos, repair.orbitRadius_tiles); } intent = MovementIntentComponent{true, dest}; }); // Repair tools: prefer the behavior target if it is within tool range. admin.forEach( [&](entt::entity /*re*/, RepairToolComponent& tool, const ModuleOwnerComponent& owner) { if (!admin.hasAll(owner.owner)) { return; } const SelectedBehaviorComponent& selected = admin.get(owner.owner); if (selected.winner != BehaviorKind::Repair) { return; } const RepairBehavior& repair = admin.get(owner.owner); if (!repair.currentTarget) { return; } const entt::entity t = *repair.currentTarget; if (!admin.isValid(t) || !admin.hasAll(t)) { return; } const QVector2D ownerPos = admin.get(owner.owner).value; const float dist = (admin.get(t).value - ownerPos).length(); if (dist <= tool.range_tiles) { tool.currentTarget = t; } }); }