From b95eaaaded4aa450e03f8ba6dfbd42a5065d9f74 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Wed, 17 Jun 2026 21:52:47 +0200 Subject: [PATCH] fix repair tool targeting --- src/lib/ecs/system/ai/RepairEvaluator.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lib/ecs/system/ai/RepairEvaluator.cpp b/src/lib/ecs/system/ai/RepairEvaluator.cpp index 5079be4..d7ab149 100644 --- a/src/lib/ecs/system/ai/RepairEvaluator.cpp +++ b/src/lib/ecs/system/ai/RepairEvaluator.cpp @@ -5,6 +5,7 @@ #include "BehaviorScores.h" #include "BehaviorTargeting.h" #include "EntityAdmin.h" +#include "FactionComponent.h" #include "HealthComponent.h" #include "PositionComponent.h" #include "RepairBehavior.h" @@ -16,23 +17,28 @@ void RepairEvaluator::evaluate(EntityAdmin& admin) TRACE(); const std::vector repairables = buildRepairables(admin); - admin.forEach( + admin.forEach( [&](entt::entity e, RepairBehavior& repair, const PositionComponent& pos, - const SensorRangeComponent& sensor) + const SensorRangeComponent& sensor, const FactionComponent& faction) { - // Validate current target: alive and still damaged. + // Validate current target: same faction, alive and still damaged. bool targetValid = false; if (repair.currentTarget) { const entt::entity t = *repair.currentTarget; - if (admin.isValid(t) && admin.hasAll(t)) + if (admin.isValid(t) && admin.hasAll(t)) { - const HealthComponent& th = admin.get(t); - if (th.hp > 0.0f && th.hp < th.maxHp) { targetValid = true; } + const HealthComponent& th = admin.get(t); + const FactionComponent& tf = admin.get(t); + if (tf.isEnemy == faction.isEnemy && th.hp > 0.0f && th.hp < th.maxHp) + { + targetValid = true; + } } } - // Acquire nearest damaged friendly within sensor range. + // Acquire nearest damaged friendly within sensor range. Friendly is + // relative to this ship's faction, not the absolute isEnemy flag. if (!targetValid) { repair.currentTarget = std::nullopt; @@ -40,7 +46,7 @@ void RepairEvaluator::evaluate(EntityAdmin& admin) for (const RepairableInfo& r : repairables) { if (r.entity == e) { continue; } - if (r.isEnemy) { continue; } + if (r.isEnemy != faction.isEnemy) { continue; } if (r.hp <= 0.0f || r.hp >= r.maxHp) { continue; } const float dist = (r.position - pos.value).length(); if (dist < bestDist)