fix issue where ships cancel their attacks and advance if on low health in balancing target
This commit is contained in:
@@ -16,7 +16,7 @@ namespace BehaviorScores
|
||||
constexpr float kAttack = 0.60f; // healthy and target in sensor range
|
||||
constexpr float kRetreat = 0.90f;
|
||||
|
||||
// Health fraction at/below which a ship is considered "low HP" — used by the
|
||||
// Attack evaluator (do not attack when low) and the Retreat evaluator.
|
||||
// Health fraction below which a ship is considered "low HP" — used by the
|
||||
// Retreat evaluator to trigger retreat (which outscores attack).
|
||||
constexpr float kLowHpFraction = 0.3f;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "BehaviorTargeting.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "ModuleOwnerComponent.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "SensorRangeComponent.h"
|
||||
@@ -55,10 +54,9 @@ void AttackEvaluator::evaluate(EntityAdmin& admin)
|
||||
|
||||
// Pass C: per-ship target selection.
|
||||
admin.forEach<AttackBehavior, PositionComponent, FactionComponent,
|
||||
SensorRangeComponent, HealthComponent>(
|
||||
SensorRangeComponent>(
|
||||
[&](entt::entity e, AttackBehavior& attack, const PositionComponent& pos,
|
||||
const FactionComponent& faction, const SensorRangeComponent& sensor,
|
||||
const HealthComponent& health)
|
||||
const FactionComponent& faction, const SensorRangeComponent& sensor)
|
||||
{
|
||||
const float sensorRange_tiles = sensor.value_tiles;
|
||||
|
||||
@@ -135,13 +133,14 @@ void AttackEvaluator::evaluate(EntityAdmin& admin)
|
||||
}
|
||||
}
|
||||
|
||||
if (!keptCurrent) { attack.currentTarget = bestTarget; }
|
||||
if (!keptCurrent)
|
||||
{
|
||||
attack.currentTarget = bestTarget;
|
||||
}
|
||||
|
||||
const bool healthy =
|
||||
(health.maxHp > 0.0f)
|
||||
&& (health.hp / health.maxHp >= BehaviorScores::kLowHpFraction);
|
||||
attack.score = (healthy && attack.currentTarget)
|
||||
attack.score = attack.currentTarget
|
||||
? BehaviorScores::kAttack
|
||||
: BehaviorScores::kInactive;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user