fix repair tool targeting
This commit is contained in:
@@ -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<RepairableInfo> repairables = buildRepairables(admin);
|
||||
|
||||
admin.forEach<RepairBehavior, PositionComponent, SensorRangeComponent>(
|
||||
admin.forEach<RepairBehavior, PositionComponent, SensorRangeComponent, FactionComponent>(
|
||||
[&](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<HealthComponent>(t))
|
||||
if (admin.isValid(t) && admin.hasAll<HealthComponent, FactionComponent>(t))
|
||||
{
|
||||
const HealthComponent& th = admin.get<HealthComponent>(t);
|
||||
if (th.hp > 0.0f && th.hp < th.maxHp) { targetValid = true; }
|
||||
const HealthComponent& th = admin.get<HealthComponent>(t);
|
||||
const FactionComponent& tf = admin.get<FactionComponent>(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)
|
||||
|
||||
Reference in New Issue
Block a user