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