HumanAIController calculates the "dangerousness" of an enemy based on the largest amount of damage received from it (assuming it's larger than the attack values of the enemy's limbs). Meaning that an enemy that inflicted lots of damage to the character using items is considered dangerous even if it has no attacks assigned to it's limbs.

This commit is contained in:
Joonas Rikkonen
2017-10-19 00:01:34 +03:00
parent 87e9936c60
commit 1f92e31166
5 changed files with 22 additions and 11 deletions

View File

@@ -461,7 +461,7 @@ namespace Barotrauma
if (attacker == null || attacker.AiTarget == null) return;
AITargetMemory targetMemory = FindTargetMemory(attacker.AiTarget);
targetMemory.Priority += amount;
targetMemory.Priority += amount / Math.Max(Character.Health, 1.0f);
}
private void UpdateLimbAttack(float deltaTime, Limb limb, Vector2 attackPosition)

View File

@@ -145,6 +145,11 @@ namespace Barotrauma
if (enemy == null || enemy == Character) return;
objectiveManager.AddObjective(new AIObjectiveCombat(Character, enemy));
//the objective in the manager is not necessarily the same as the one we just instantiated,
//because the objective isn't added if there's already an identical objective in the manager
var combatObjective = objectiveManager.GetObjective<AIObjectiveCombat>();
combatObjective.MaxEnemyDamage = Math.Max(amount, combatObjective.MaxEnemyDamage);
}
public void SetOrder(Order order, string option)

View File

@@ -9,6 +9,10 @@ namespace Barotrauma
{
const float CoolDown = 10.0f;
//the largest amount of damage the enemy has inflicted on this character
//(may be higher than enemyStrength if the enemy is e.g. a human using items)
public float MaxEnemyDamage;
private Character enemy;
private AIObjectiveFindSafety escapeObjective;
@@ -17,7 +21,7 @@ namespace Barotrauma
private readonly float enemyStrength;
public AIObjectiveCombat (Character character, Character enemy)
public AIObjectiveCombat(Character character, Character enemy)
: base(character, "")
{
this.enemy = enemy;
@@ -88,13 +92,6 @@ namespace Barotrauma
}
escapeObjective.TryComplete(deltaTime);
//if (Vector2.Distance(character.SimPosition, enemy.SimPosition) < 3.0f)
//{
// character.AIController.SteeringManager.SteeringManual(deltaTime,
// new Vector2(Math.Sign(character.SimPosition.X - enemy.SimPosition.X), 0.0f));
// coolDownTimer = CoolDown;
//}
}
public override bool IsCompleted()
@@ -107,7 +104,7 @@ namespace Barotrauma
//clamp the strength to the health of this character
//(it doesn't make a difference whether the enemy does 200 or 600 damage, it's one hit kill anyway)
float enemyDanger = Math.Min(enemyStrength, character.Health) + enemy.Health / 10.0f;
float enemyDanger = Math.Min(Math.Max(enemyStrength, MaxEnemyDamage), character.Health) + enemy.Health / 10.0f;
EnemyAIController enemyAI = enemy.AIController as EnemyAIController;
if (enemyAI != null)

View File

@@ -36,6 +36,15 @@ namespace Barotrauma
objectives.Add(objective);
}
public T GetObjective<T>() where T : AIObjective
{
foreach (AIObjective objective in objectives)
{
if (objective is T) return (T)objective;
}
return null;
}
public float GetCurrentPriority(Character character)
{
if (currentObjective != null) return OrderPriority;

View File

@@ -61,7 +61,7 @@ namespace Barotrauma
{
AttackResult result = base.AddDamage(attacker, worldPosition, attack, deltaTime, playSound);
aiController.OnAttacked(attacker, (result.Damage + result.Bleeding) / Math.Max(Health, 1.0f));
aiController.OnAttacked(attacker, result.Damage + result.Bleeding);
return result;
}