Option to make AI characters flee when their health is below a specific threshold

This commit is contained in:
Joonas Rikkonen
2017-06-12 18:50:15 +03:00
parent 0ba11e1fb6
commit c7d22ecb47
3 changed files with 10 additions and 3 deletions
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<Character name ="crawler" humanoid="false"> <Character name ="crawler" humanoid="false" health="100">
<sound file="Content/Characters/Crawler/attack1.ogg" state="Attack" range="500"/> <sound file="Content/Characters/Crawler/attack1.ogg" state="Attack" range="500"/>
<sound file="Content/Characters/Crawler/attack2.ogg" state="Attack" range="500"/> <sound file="Content/Characters/Crawler/attack2.ogg" state="Attack" range="500"/>
@@ -78,6 +78,7 @@
<ai attackhumans="500" attackrooms="50.0" attackweaker="50" attackstronger="-30" <ai attackhumans="500" attackrooms="50.0" attackweaker="50" attackstronger="-30"
sight="0.5" hearing="1.0" sight="0.5" hearing="1.0"
fleehealththreshold="10"
attackcooldown="3.0"/> attackcooldown="3.0"/>
</Character> </Character>
@@ -95,6 +95,7 @@
attackprioritystronger="-30" attackprioritystronger="-30"
attackcooldown="1.0" attackcooldown="1.0"
sight="0.5" sight="0.5"
hearing="1.0"/> hearing="1.0"
fleehealththreshold="20"/>
</Character> </Character>
@@ -49,6 +49,9 @@ namespace Barotrauma
//the limb selected for the current attack //the limb selected for the current attack
private Limb attackingLimb; private Limb attackingLimb;
//flee when the health is below this value
private float fleeHealthThreshold;
private AITarget selectedAiTarget; private AITarget selectedAiTarget;
private AITargetMemory selectedTargetMemory; private AITargetMemory selectedTargetMemory;
private float targetValue; private float targetValue;
@@ -89,6 +92,8 @@ namespace Barotrauma
attackWhenProvoked = ToolBox.GetAttributeBool(aiElement, "attackwhenprovoked", false); attackWhenProvoked = ToolBox.GetAttributeBool(aiElement, "attackwhenprovoked", false);
fleeHealthThreshold = ToolBox.GetAttributeFloat(aiElement, "fleehealththreshold", 0.0f);
outsideSteering = new SteeringManager(this); outsideSteering = new SteeringManager(this);
insideSteering = new IndoorsSteeringManager(this, false); insideSteering = new IndoorsSteeringManager(this, false);
@@ -146,7 +151,7 @@ namespace Barotrauma
} }
else else
{ {
state = (targetValue > 0.0f) ? AiState.Attack : AiState.Escape; state = (targetValue < 0.0f || Character.Health < fleeHealthThreshold) ? AiState.Escape : AiState.Attack;
} }
//if (coolDownTimer >= 0.0f) return; //if (coolDownTimer >= 0.0f) return;
} }