diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs index f3afac468..12c490f57 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs @@ -115,7 +115,8 @@ namespace Barotrauma unreachable.Add(goToObjective.Target as Hull); } goToObjective = null; - SteeringManager.SteeringWander(); + HumanAIController.ObjectiveManager.GetObjective().Wander(deltaTime); + //SteeringManager.SteeringWander(); } } else if (currentHull != null) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs index 7f20924c1..d0c519da9 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs @@ -99,7 +99,8 @@ namespace Barotrauma FindTargetItem(); if (targetItem == null || moveToTarget == null) { - SteeringManager.SteeringWander(); + HumanAIController.ObjectiveManager.GetObjective().Wander(deltaTime); + //SteeringManager.SteeringWander(); return; } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveIdle.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveIdle.cs index a4138c65c..51b085582 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveIdle.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveIdle.cs @@ -98,51 +98,13 @@ namespace Barotrauma PathSteering.Reset(); return; } - if (standStillTimer < -walkDuration) { standStillTimer = Rand.Range(standStillMin, standStillMax); } - - //steer away from edges of the hull - if (character.AnimController.CurrentHull != null && !character.IsClimbing) - { - float leftDist = character.Position.X - character.AnimController.CurrentHull.Rect.X; - float rightDist = character.AnimController.CurrentHull.Rect.Right - character.Position.X; - - if (leftDist < WallAvoidDistance && rightDist < WallAvoidDistance) - { - if (Math.Abs(rightDist - leftDist) > WallAvoidDistance / 2) - { - PathSteering.SteeringManual(deltaTime, Vector2.UnitX * Math.Sign(rightDist - leftDist)); - } - else - { - PathSteering.Reset(); - return; - } - } - else if (leftDist < WallAvoidDistance) - { - PathSteering.SteeringManual(deltaTime, Vector2.UnitX * (WallAvoidDistance-leftDist) / WallAvoidDistance); - PathSteering.WanderAngle = 0.0f; - return; - } - else if (rightDist < WallAvoidDistance) - { - PathSteering.SteeringManual(deltaTime, -Vector2.UnitX * (WallAvoidDistance-rightDist) / WallAvoidDistance); - PathSteering.WanderAngle = MathHelper.Pi; - return; - } - } - - character.AIController.SteeringManager.SteeringWander(); - if (!character.IsClimbing && !character.AnimController.InWater) - { - //reset vertical steering to prevent dropping down from platforms etc - character.AIController.SteeringManager.ResetY(); - } - return; + + Wander(deltaTime); + return; } if (currentTarget != null) @@ -151,6 +113,43 @@ namespace Barotrauma } } + public void Wander(float deltaTime) + { + //steer away from edges of the hull + if (character.AnimController.CurrentHull != null && !character.IsClimbing) + { + float leftDist = character.Position.X - character.AnimController.CurrentHull.Rect.X; + float rightDist = character.AnimController.CurrentHull.Rect.Right - character.Position.X; + if (leftDist < WallAvoidDistance && rightDist < WallAvoidDistance) + { + if (Math.Abs(rightDist - leftDist) > WallAvoidDistance / 2) + { + PathSteering.SteeringManual(deltaTime, Vector2.UnitX * Math.Sign(rightDist - leftDist)); + } + else + { + PathSteering.Reset(); + } + } + else if (leftDist < WallAvoidDistance) + { + PathSteering.SteeringManual(deltaTime, Vector2.UnitX * (WallAvoidDistance - leftDist) / WallAvoidDistance); + PathSteering.WanderAngle = 0.0f; + } + else if (rightDist < WallAvoidDistance) + { + PathSteering.SteeringManual(deltaTime, -Vector2.UnitX * (WallAvoidDistance - rightDist) / WallAvoidDistance); + PathSteering.WanderAngle = MathHelper.Pi; + } + } + SteeringManager.SteeringWander(); + if (!character.IsClimbing && !character.AnimController.InWater) + { + //reset vertical steering to prevent dropping down from platforms etc + character.AIController.SteeringManager.ResetY(); + } + } + private readonly List targetHulls = new List(20); private readonly List hullWeights = new List(20);