(439481a07) Set the random factor for initiative each time the objective changes and once per 5 secs when the idle is active. Change the formula. Fix the waiting after character has been unselected.

This commit is contained in:
Joonas Rikkonen
2019-05-16 05:30:06 +03:00
parent ca3b5ae04b
commit 348f21598e
9 changed files with 143 additions and 311 deletions
@@ -40,13 +40,39 @@ namespace Barotrauma
public override bool IsLoop { get => true; set => throw new System.Exception("Trying to set the value for IsLoop from: " + System.Environment.StackTrace); }
private float randomTimer;
private float randomUpdateInterval = 5;
public float Random { get; private set; }
public void SetRandom()
{
Random = Rand.Range(0.5f, 1.5f);
randomTimer = randomUpdateInterval;
}
public override float GetPriority()
{
float max = Math.Min(AIObjectiveManager.OrderPriority - 1, 100);
Priority = MathHelper.Lerp(1, max, MathUtils.InverseLerp(100, 0, character.GetSkillLevel("initiative")));
float max = Math.Min(Math.Min(AIObjectiveManager.RunPriority, AIObjectiveManager.OrderPriority) - 1, 100);
float initiative = character.GetSkillLevel("initiative");
Priority = MathHelper.Lerp(1, max, MathUtils.InverseLerp(100, 0, initiative * Random));
return Priority;
}
public override void Update(float deltaTime)
{
if (objectiveManager.CurrentObjective == this)
{
if (randomTimer > 0)
{
randomTimer -= deltaTime;
}
else
{
SetRandom();
}
}
}
public override bool IsCompleted() => false;
public override bool CanBeCompleted => true;
@@ -69,17 +95,10 @@ namespace Barotrauma
character.SelectedConstruction = null;
}
bool currentHullForbidden = IsForbidden(character.CurrentHull);
if (!currentHullForbidden && !character.AnimController.InWater && !character.IsClimbing)
{
SteeringManager.Reset();
return;
}
bool currentTargetIsInvalid = currentTarget == null || IsForbidden(currentTarget) ||
(PathSteering.CurrentPath != null && PathSteering.CurrentPath.Nodes.Any(n => HumanAIController.UnsafeHulls.Contains(n.CurrentHull)));
if (currentTargetIsInvalid || (currentTarget == null && currentHullForbidden))
if (currentTargetIsInvalid || currentTarget == null && IsForbidden(character.CurrentHull))
{
newTargetTimer = 0;
standStillTimer = 0;
@@ -281,7 +300,7 @@ namespace Barotrauma
}
}
private bool IsForbidden(Hull hull)
public static bool IsForbidden(Hull hull)
{
if (hull == null) { return true; }
string hullName = hull.RoomName?.ToLowerInvariant();
@@ -109,6 +109,7 @@ namespace Barotrauma
if (previousObjective != CurrentObjective)
{
CurrentObjective?.OnSelected();
GetObjective<AIObjectiveIdle>().SetRandom();
}
return CurrentObjective;
}
@@ -170,7 +171,16 @@ namespace Barotrauma
else
{
WaitTimer -= deltaTime;
character.AIController?.SteeringManager?.Reset();
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();
}
}
}
}
}