From 68870b67f5877879ba0b5c6c0ab6fb259a7bb027 Mon Sep 17 00:00:00 2001 From: Regalis Date: Thu, 26 May 2016 18:04:25 +0300 Subject: [PATCH] - fractal guardians have higher impact tolerance to stop them from killing themselves by slamming at the walls - enemies use pathfinding when inside the sub and handle platforms/stairs better --- .../Fractalguardian/fractalguardian.xml | 8 +-- .../Fractalguardian2/fractalguardian2.xml | 6 +-- .../Source/Characters/AI/EnemyAIController.cs | 24 +++++++-- .../Animation/FishAnimController.cs | 50 ++++++++++++------- 4 files changed, 59 insertions(+), 29 deletions(-) diff --git a/Subsurface/Content/Characters/Fractalguardian/fractalguardian.xml b/Subsurface/Content/Characters/Fractalguardian/fractalguardian.xml index 310dcd6eb..32aa58d7c 100644 --- a/Subsurface/Content/Characters/Fractalguardian/fractalguardian.xml +++ b/Subsurface/Content/Characters/Fractalguardian/fractalguardian.xml @@ -7,22 +7,22 @@ - + - + - + - + diff --git a/Subsurface/Content/Characters/Fractalguardian2/fractalguardian2.xml b/Subsurface/Content/Characters/Fractalguardian2/fractalguardian2.xml index a7aae8f8d..147a5bd7b 100644 --- a/Subsurface/Content/Characters/Fractalguardian2/fractalguardian2.xml +++ b/Subsurface/Content/Characters/Fractalguardian2/fractalguardian2.xml @@ -7,7 +7,7 @@ - + @@ -16,7 +16,7 @@ - + @@ -25,7 +25,7 @@ - + diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 72a6796f6..3e32edbc0 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -25,6 +25,8 @@ namespace Barotrauma //negative values = escapes targets of this type private float attackRooms, attackHumans, attackWeaker, attackStronger; + private SteeringManager outsideSteering, insideSteering; + private float updateTargetsTimer; private float raycastTimer; @@ -88,7 +90,10 @@ namespace Barotrauma attackWhenProvoked = ToolBox.GetAttributeBool(aiElement, "attackwhenprovoked", false); - steeringManager = new SteeringManager(this); + outsideSteering = new SteeringManager(this); + insideSteering = new IndoorsSteeringManager(this, false); + + steeringManager = outsideSteering; state = AiState.None; } @@ -133,7 +138,9 @@ namespace Barotrauma state = (targetValue > 0.0f) ? AiState.Attack : AiState.Escape; } //if (coolDownTimer >= 0.0f) return; - } + } + + steeringManager = Character.Submarine == null ? outsideSteering : insideSteering; switch (state) { @@ -210,7 +217,7 @@ namespace Barotrauma raycastTimer = RaycastInterval; } - steeringManager.SteeringAvoid(deltaTime, 1.0f); + //steeringManager.SteeringAvoid(deltaTime, 1.0f); steeringManager.SteeringSeek(attackSimPosition); //check if any of the limbs is close enough to attack the target @@ -252,6 +259,12 @@ namespace Barotrauma private void GetTargetEntity() { targetEntity = null; + + if (Character.AnimController.CurrentHull != null) + { + wallAttackPos = Vector2.Zero; + return; + } //check if there's a wall between the target and the Character Vector2 rayStart = Character.SimPosition; @@ -274,7 +287,7 @@ namespace Barotrauma if (wall == null) { wallAttackPos = Submarine.LastPickedPosition; - if (selectedAiTarget.Entity.Submarine!=null) wallAttackPos -= ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position); + if (selectedAiTarget.Entity.Submarine!=null && Character.Submarine == null) wallAttackPos -= ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position); } else @@ -370,7 +383,6 @@ namespace Barotrauma break; } - if (dist < limb.attack.Range) { attackTimer += deltaTime; @@ -413,6 +425,8 @@ namespace Barotrauma } distanceAccumulator = 0.0f; + wallAttackPos = Vector2.Zero; + selectedAiTarget = null; selectedTargetMemory = null; targetValue = 0.0f; diff --git a/Subsurface/Source/Characters/Animation/FishAnimController.cs b/Subsurface/Source/Characters/Animation/FishAnimController.cs index 4848c309b..66ab02c90 100644 --- a/Subsurface/Source/Characters/Animation/FishAnimController.cs +++ b/Subsurface/Source/Characters/Animation/FishAnimController.cs @@ -73,7 +73,7 @@ namespace Barotrauma } else { - if (inWater) + if (inWater || RefLimb.inWater) { UpdateSineAnim(deltaTime); } @@ -83,7 +83,7 @@ namespace Barotrauma } } - if (mirror) + if (mirror || !inWater) { if (!character.IsNetworkPlayer) { @@ -278,28 +278,44 @@ namespace Barotrauma //out whether the ragdoll is standing on ground float closestFraction = 1; //Structure closestStructure = null; + GameMain.World.RayCast((fixture, point, normal, fraction) => { - //other limbs and bodies with no collision detection are ignored - if (fixture == null || - fixture.CollisionCategories == Physics.CollisionCharacter || - fixture.CollisionCategories == Physics.CollisionNone || - fixture.CollisionCategories == Physics.CollisionItem) return -1; - - Structure structure = fixture.Body.UserData as Structure; - if (structure != null) + switch (fixture.CollisionCategories) { - if (structure.StairDirection != Direction.None && (stairs == null)) return -1; - if (structure.IsPlatform && (IgnorePlatforms || stairs != null)) return -1; + case Physics.CollisionStairs: + if (inWater && TargetMovement.Y < 0.5f) return -1; + Structure structure = fixture.Body.UserData as Structure; + if (stairs == null && structure != null) + { + if (LowestLimb.SimPosition.Y < structure.SimPosition.Y) + { + return -1; + } + else + { + stairs = structure; + } + } + break; + case Physics.CollisionPlatform: + Structure platform = fixture.Body.UserData as Structure; + if (IgnorePlatforms || LowestLimb.Position.Y < platform.Rect.Y) return -1; + break; + case Physics.CollisionWall: + break; + default: + return -1; } onGround = true; + if (fraction < closestFraction) + { + closestFraction = fraction; + } onFloorTimer = 0.05f; - - if (fraction < closestFraction) closestFraction = fraction; - return 1; - } - , rayStart, rayEnd); + return closestFraction; + } , rayStart, rayEnd); //the ragdoll "stays on ground" for 50 millisecs after separation if (onFloorTimer <= 0.0f)