From 3981b4efa3b93e50f245850cef01caae85981a40 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Fri, 30 Jun 2017 17:28:52 +0300 Subject: [PATCH] - Enemies wander randomly if they can't find a path to a selected attack target. - Enemies don't select hulls as targets if they're already inside. - FishAnimController updates the walking animation even if the character is not moving (otherwise the character would just fall down if TargetMovement is zero). - Eating anim tweaking. --- .../Tigerthresher/tigerthresher.xml | 2 +- .../Source/Characters/AI/EnemyAIController.cs | 25 ++++++++++++------- .../Animation/FishAnimController.cs | 9 ------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Barotrauma/Content/Characters/Tigerthresher/tigerthresher.xml b/Barotrauma/Content/Characters/Tigerthresher/tigerthresher.xml index 6c3d35f6e..47ef44ec6 100644 --- a/Barotrauma/Content/Characters/Tigerthresher/tigerthresher.xml +++ b/Barotrauma/Content/Characters/Tigerthresher/tigerthresher.xml @@ -25,7 +25,7 @@ - + diff --git a/Barotrauma/Source/Characters/AI/EnemyAIController.cs b/Barotrauma/Source/Characters/AI/EnemyAIController.cs index e546032f7..baea625ad 100644 --- a/Barotrauma/Source/Characters/AI/EnemyAIController.cs +++ b/Barotrauma/Source/Characters/AI/EnemyAIController.cs @@ -362,9 +362,18 @@ namespace Barotrauma if (steeringManager is IndoorsSteeringManager) { var indoorsSteering = (IndoorsSteeringManager)steeringManager; - if (indoorsSteering.CurrentPath != null && (indoorsSteering.CurrentPath.Finished || indoorsSteering.CurrentPath.Unreachable)) + if (indoorsSteering.CurrentPath != null) { - steeringManager.SteeringManual(deltaTime, attackSimPosition - attackLimb.SimPosition); + if (indoorsSteering.CurrentPath.Unreachable) + { + //wander around randomly and decrease the priority faster if no path is found + if (selectedTargetMemory != null) selectedTargetMemory.Priority -= deltaTime * 10.0f; + steeringManager.SteeringWander(); + } + else if (indoorsSteering.CurrentPath.Finished) + { + steeringManager.SteeringManual(deltaTime, attackSimPosition - attackLimb.SimPosition); + } } } @@ -525,6 +534,8 @@ namespace Barotrauma //pull the target character to the position of the mouth //(+ make the force fluctuate to waggle the character a bit) targetCharacter.AnimController.MainLimb.MoveToPos(mouthPos, (float)(Math.Sin(eatTimer) + 10.0f)); + targetCharacter.AnimController.MainLimb.body.SmoothRotate(mouthLimb.Rotation); + targetCharacter.AnimController.Collider.MoveToPos(mouthPos, (float)(Math.Sin(eatTimer) + 10.0f)); //pull the character's mouth to the target character (again with a fluctuating force) float pullStrength = (float)(Math.Sin(eatTimer) * Math.Max(Math.Sin(eatTimer * 0.5f), 0.0f)); @@ -632,8 +643,8 @@ namespace Barotrauma IDamageable targetDamageable = target.Entity as IDamageable; if (targetDamageable != null && targetDamageable.Health <= 0.0f) continue; - //skip the target if it's the room the Character is inside of - if (character.AnimController.CurrentHull != null && character.AnimController.CurrentHull == target.Entity as Hull) continue; + //skip the target if it's a room and the character is already inside a sub + if (character.AnimController.CurrentHull != null && target.Entity is Hull) continue; valueModifier = attackRooms; } @@ -701,7 +712,6 @@ namespace Barotrauma //have a corresponding AItarget or whose priority is 0.0f private void UpdateTargetMemories() { - List toBeRemoved = new List(); foreach(KeyValuePair memory in targetMemories) { @@ -724,7 +734,7 @@ namespace Barotrauma Vector2 pos = Character.WorldPosition; pos.Y = -pos.Y; - if (selectedAiTarget!=null) + if (selectedAiTarget!=null && selectedAiTarget.Entity != null) { GUI.DrawLine(spriteBatch, pos, new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red); @@ -734,10 +744,7 @@ namespace Barotrauma } GUI.Font.DrawString(spriteBatch, targetValue.ToString(), pos - Vector2.UnitY*20.0f, Color.Red); - } - if (selectedAiTarget != null) - { GUI.DrawLine(spriteBatch, new Vector2(Character.DrawPosition.X, -Character.DrawPosition.Y), new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red); diff --git a/Barotrauma/Source/Characters/Animation/FishAnimController.cs b/Barotrauma/Source/Characters/Animation/FishAnimController.cs index 1d352de69..7fa3c6752 100644 --- a/Barotrauma/Source/Characters/Animation/FishAnimController.cs +++ b/Barotrauma/Source/Characters/Animation/FishAnimController.cs @@ -213,14 +213,6 @@ namespace Barotrauma Vector2 pullPos = Limbs[i].pullJoint == null ? Limbs[i].SimPosition : Limbs[i].pullJoint.WorldAnchorA; Limbs[i].body.ApplyForce(movement * Limbs[i].SteerForce * Limbs[i].Mass, pullPos); - - /*if (Limbs[i] == MainLimb) continue; - - float dist = (MainLimb.SimPosition - Limbs[i].SimPosition).Length(); - - Vector2 limbPos = MainLimb.SimPosition - Vector2.Normalize(movement) * dist; - - Limbs[i].body.ApplyForce(((limbPos - Limbs[i].SimPosition) * 3.0f - Limbs[i].LinearVelocity * 3.0f) * Limbs[i].Mass);*/ } Collider.LinearVelocity = Vector2.Lerp(Collider.LinearVelocity, movement, 0.5f); @@ -231,7 +223,6 @@ namespace Barotrauma void UpdateWalkAnim(float deltaTime) { movement = MathUtils.SmoothStep(movement, TargetMovement * walkSpeed, 0.2f); - if (movement == Vector2.Zero) return; float mainLimbHeight, mainLimbAngle; if (MainLimb.type == LimbType.Torso)