From 5120812adfaf882c9d24741b9bf23a0c7699a5c8 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 13 Mar 2016 19:24:30 +0200 Subject: [PATCH] - fixed AICharacters being updated even if they're disabled - enemies can spot targets from further away if they've previously spotted the target - physics bodies are immediately moved to the correct position if they're really far (instead of lerping) --- Subsurface/Content/Characters/Endworm/endworm.xml | 2 +- Subsurface/Content/Items/Diving/divinggear.xml | 6 +++--- Subsurface/Source/Characters/AI/AITarget.cs | 2 +- .../Source/Characters/AI/EnemyAIController.cs | 15 ++++++++++----- Subsurface/Source/Characters/AICharacter.cs | 2 ++ Subsurface/Source/DebugConsole.cs | 9 +++------ .../Source/Items/Components/Machines/Radar.cs | 1 - Subsurface/Source/Map/Hull.cs | 4 ++-- Subsurface/Source/Physics/PhysicsBody.cs | 2 +- 9 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Subsurface/Content/Characters/Endworm/endworm.xml b/Subsurface/Content/Characters/Endworm/endworm.xml index eb183714c..78b17f1a8 100644 --- a/Subsurface/Content/Characters/Endworm/endworm.xml +++ b/Subsurface/Content/Characters/Endworm/endworm.xml @@ -73,6 +73,6 @@ - + diff --git a/Subsurface/Content/Items/Diving/divinggear.xml b/Subsurface/Content/Items/Diving/divinggear.xml index 04bf10b3d..2a27490e8 100644 --- a/Subsurface/Content/Items/Diving/divinggear.xml +++ b/Subsurface/Content/Items/Diving/divinggear.xml @@ -36,7 +36,7 @@ - + @@ -66,7 +66,7 @@ - + @@ -118,7 +118,7 @@ - + diff --git a/Subsurface/Source/Characters/AI/AITarget.cs b/Subsurface/Source/Characters/AI/AITarget.cs index e6bcd2574..1f5f47f69 100644 --- a/Subsurface/Source/Characters/AI/AITarget.cs +++ b/Subsurface/Source/Characters/AI/AITarget.cs @@ -11,7 +11,7 @@ namespace Barotrauma public static List List = new List(); - public Entity Entity; + public readonly Entity Entity; private float soundRange; private float sightRange; diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 45c7b5a04..09a1c98db 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -438,7 +438,7 @@ namespace Barotrauma valueModifier = attackHumans; } - else if (target.Entity!=null && attackRooms!=0.0f) + else if (target.Entity!=null && attackRooms != 0.0f) { //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; @@ -450,12 +450,17 @@ namespace Barotrauma character.WorldPosition, target.WorldPosition); + //if the target has been within range earlier, the character will notice it more easily + //(i.e. remember where the target was) + if (targetMemories.ContainsKey(target)) dist *= 0.5f; + + //ignore target if it's too far to see or hear + if (dist > target.SightRange * sight && dist > target.SoundRange * hearing) continue; + AITargetMemory targetMemory = FindTargetMemory(target); - valueModifier = valueModifier * targetMemory.Priority / dist; - //dist -= targetMemory.Priority; - if (Math.Abs(valueModifier) > Math.Abs(targetValue) && (dist < target.SightRange * sight || dist < target.SoundRange * hearing)) + if (Math.Abs(valueModifier) > Math.Abs(targetValue)) { Vector2 rayStart = character.AnimController.Limbs[0].SimPosition; Vector2 rayEnd = target.SimPosition; @@ -517,7 +522,7 @@ namespace Barotrauma foreach(KeyValuePair memory in targetMemories) { memory.Value.Priority += 0.5f; - if (memory.Value.Priority == 0.0f || !AITarget.List.Contains(memory.Key)) toBeRemoved.Add(memory.Key); + if (Math.Abs(memory.Value.Priority) < 1.0f || !AITarget.List.Contains(memory.Key)) toBeRemoved.Add(memory.Key); } foreach (AITarget target in toBeRemoved) diff --git a/Subsurface/Source/Characters/AICharacter.cs b/Subsurface/Source/Characters/AICharacter.cs index f188c9b89..c26ee7684 100644 --- a/Subsurface/Source/Characters/AICharacter.cs +++ b/Subsurface/Source/Characters/AICharacter.cs @@ -33,6 +33,8 @@ namespace Barotrauma public override void Update(Camera cam, float deltaTime) { + if (!Enabled) return; + base.Update(cam, deltaTime); float dist = Vector2.Distance(cam.WorldViewCenter, WorldPosition); diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 8dbdbb72a..34286e9ac 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -417,11 +417,8 @@ namespace Barotrauma new GUIMessageBox(commands[1], commands[2]); break; case "debugdraw": - //Hull.DebugDraw = !Hull.DebugDraw; - //Ragdoll.DebugDraw = !Ragdoll.DebugDraw; GameMain.DebugDraw = !GameMain.DebugDraw; break; - case "drawaitargets": case "showaitargets": AITarget.ShowAITargets = !AITarget.ShowAITargets; @@ -429,11 +426,11 @@ namespace Barotrauma case "sendrandomdata": int messageCount = 1; - if (commands.Length>1) int.TryParse(commands[1], out messageCount); + if (commands.Length > 1) int.TryParse(commands[1], out messageCount); - for (int i = 0; i < messageCount; i++ ) + for (int i = 0; i < messageCount; i++) { - if (GameMain.Server!=null) + if (GameMain.Server != null) { GameMain.Server.SendRandomData(); } diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index b08beee6a..31dd944ca 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -200,7 +200,6 @@ namespace Barotrauma.Items.Components if (limb.SimPosition == Vector2.Zero || pointDist > radius) continue; - if (pointDist > radius) continue; if (pointDist > prevPingRadius && pointDist < pingRadius) { for (int i = 0; i<=limb.Mass/100.0f; i++) diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 5c7f15cdd..daa794261 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -352,8 +352,8 @@ namespace Barotrauma FireSource.UpdateAll(fireSources, deltaTime); - aiTarget.SightRange = Submarine == null ? 0.0f : Submarine.Velocity.Length() * 500.0f; - aiTarget.SoundRange -= deltaTime*1000.0f; + aiTarget.SightRange = Submarine == null ? 0.0f : Math.Max(Submarine.Velocity.Length() * 500.0f, 500.0f); + aiTarget.SoundRange -= deltaTime * 1000.0f; float strongestFlow = 0.0f; foreach (Gap gap in ConnectedGaps) diff --git a/Subsurface/Source/Physics/PhysicsBody.cs b/Subsurface/Source/Physics/PhysicsBody.cs index 39cec79c4..dab2bfeff 100644 --- a/Subsurface/Source/Physics/PhysicsBody.cs +++ b/Subsurface/Source/Physics/PhysicsBody.cs @@ -307,7 +307,7 @@ namespace Barotrauma return; } - if (lerp) + if (lerp && Vector2.Distance(targetPosition, body.Position)<10.0f) { offsetFromTargetPos = targetPosition - (body.Position - offsetFromTargetPos); prevPosition = targetPosition;