(e7b2add9d) Merge branch 'human-ai' of https://github.com/Regalis11/Barotrauma-development into human-ai

This commit is contained in:
Joonas Rikkonen
2019-05-16 05:30:39 +03:00
parent 54a0164f89
commit 7614642d93
34 changed files with 369 additions and 316 deletions
@@ -19,7 +19,7 @@ namespace Barotrauma
private Character character;
/// <summary>
/// When set above zero, the character will stand still doing nothing until the timer runs out. Only affects idling.
/// When set above zero, the character will stand still doing nothing until the timer runs out. Does not affect orders.
/// </summary>
public float WaitTimer;
@@ -31,7 +31,7 @@ namespace Barotrauma
public AIObjectiveManager(Character character)
{
this.character = character;
CreateAutomaticObjectives();
CreateAutonomousObjectives();
}
public void AddObjective(AIObjective objective)
@@ -49,7 +49,7 @@ namespace Barotrauma
public Dictionary<AIObjective, CoroutineHandle> DelayedObjectives { get; private set; } = new Dictionary<AIObjective, CoroutineHandle>();
public void CreateAutomaticObjectives()
public void CreateAutonomousObjectives()
{
Objectives.Clear();
AddObjective(new AIObjectiveFindSafety(character, this));
@@ -109,6 +109,7 @@ namespace Barotrauma
if (previousObjective != CurrentObjective)
{
CurrentObjective?.OnSelected();
GetObjective<AIObjectiveIdle>().SetRandom();
}
return CurrentObjective;
}
@@ -157,8 +158,31 @@ namespace Barotrauma
public void DoCurrentObjective(float deltaTime)
{
if (WaitTimer > 0.0f) { WaitTimer -= deltaTime; }
CurrentObjective?.TryComplete(deltaTime);
if (WaitTimer <= 0)
{
CurrentObjective?.TryComplete(deltaTime);
}
else
{
if (CurrentOrder != null)
{
CurrentOrder.TryComplete(deltaTime);
}
else
{
WaitTimer -= deltaTime;
if (character.AIController is HumanAIController humanAI && humanAI.SteeringManager != null)
{
if (!character.AnimController.InWater &&
!character.IsClimbing &&
!humanAI.UnsafeHulls.Contains(character.CurrentHull) &&
!AIObjectiveIdle.IsForbidden(character.CurrentHull))
{
humanAI.SteeringManager.Reset();
}
}
}
}
}
public void SetOrder(AIObjective objective)
@@ -172,7 +196,7 @@ namespace Barotrauma
if (CurrentOrder == null)
{
// Recreate objectives, because some of them may be removed, if impossible to complete (e.g. due to path finding)
CreateAutomaticObjectives();
CreateAutonomousObjectives();
}
}