From e271873a43af0c1790ecf313fea7319819a85f02 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 20 Apr 2016 17:28:20 +0300 Subject: [PATCH] Autopilot uses submarine position as a "reference position" (instead of the position of the nav terminal), radar display bugfix, ragdolls aren't teleported outside the sub if they're in a tiny gap between hulls (e.g. passing through a broken wall between rooms) --- Subsurface/Barotrauma.csproj | 11 +++ .../Source/Characters/Animation/Ragdoll.cs | 9 ++ .../Source/Items/Components/Machines/Radar.cs | 5 +- .../Items/Components/Machines/Steering.cs | 87 +++++++++---------- 4 files changed, 64 insertions(+), 48 deletions(-) diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 48e46d9d5..eb8c8c695 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -117,6 +117,7 @@ + @@ -136,6 +137,7 @@ + @@ -461,6 +463,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -1180,6 +1185,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 658f3ec99..f7fddcf91 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -560,6 +560,15 @@ namespace Barotrauma { if (newHull == null && currentHull.Submarine != null) { + //if there's a hull right above and below the position, don't teleport outside the sub + //(the character is most likely inside some small gap between hulls) + if (Hull.FindHull(findPos + Vector2.UnitY * Submarine.GridSize.Y * 2.0f, currentHull) != null && + Hull.FindHull(findPos - Vector2.UnitY * Submarine.GridSize.Y * 2.0f, currentHull) != null) return; + + if (Hull.FindHull(findPos + Vector2.UnitX * Submarine.GridSize.X * 2.0f, currentHull) != null && + Hull.FindHull(findPos - Vector2.UnitX * Submarine.GridSize.X * 2.0f, currentHull) != null) return; + + Vector2 ragdollSpeed = refLimb.LinearVelocity == Vector2.Zero ? Vector2.Zero : Vector2.Normalize(refLimb.LinearVelocity); SetPosition(refLimb.SimPosition + ragdollSpeed + ConvertUnits.ToSimUnits(currentHull.Submarine.Position)); character.CursorPosition += currentHull.Submarine.Position; diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index 368963422..44ebb88a3 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -147,7 +147,7 @@ namespace Barotrauma.Items.Components } else { - float simScale = ConvertUnits.ToSimUnits(displayScale); + float simScale = displayScale * Physics.DisplayToSimRation; Vector2 offset = ConvertUnits.ToSimUnits(Submarine.Loaded.WorldPosition - item.WorldPosition); @@ -158,8 +158,7 @@ namespace Barotrauma.Items.Components Vector2 end = (Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] + offset) * simScale; end.Y = -end.Y; - GUI.DrawLine(spriteBatch, center + start, center + end, Color.Green); - + GUI.DrawLine(spriteBatch, center + start, center + end, Color.Green); } } diff --git a/Subsurface/Source/Items/Components/Machines/Steering.cs b/Subsurface/Source/Items/Components/Machines/Steering.cs index 59fadf364..c625eeb59 100644 --- a/Subsurface/Source/Items/Components/Machines/Steering.cs +++ b/Subsurface/Source/Items/Components/Machines/Steering.cs @@ -208,52 +208,49 @@ namespace Barotrauma.Items.Components private void UpdateAutoPilot(float deltaTime) { - if (posToMaintain==null) - { - - autopilotRayCastTimer -= deltaTime; - - steeringPath.CheckProgress(ConvertUnits.ToSimUnits(item.WorldPosition), 10.0f); - - if (autopilotRayCastTimer<=0.0f && steeringPath.NextNode != null) - { - Vector2 diff = Vector2.Normalize(ConvertUnits.ToSimUnits(steeringPath.NextNode.Position - Submarine.Loaded.WorldPosition)); - - bool nextVisible = true; - for (int x = -1; x < 2; x += 2) - { - for (int y = -1; y < 2; y += 2) - { - Vector2 cornerPos = - new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f; - - cornerPos = ConvertUnits.ToSimUnits(cornerPos * 1.2f + Submarine.Loaded.WorldPosition); - - float dist = Vector2.Distance(cornerPos, steeringPath.NextNode.SimPosition); - - if (Submarine.PickBody(cornerPos, cornerPos + diff*dist, null, Physics.CollisionLevel) == null) continue; - - nextVisible = false; - x = 2; - y = 2; - } - } - - if (nextVisible) steeringPath.SkipToNextNode(); - - autopilotRayCastTimer = AutopilotRayCastInterval; - } - - if (steeringPath.CurrentNode != null) - { - SteerTowardsPosition(steeringPath.CurrentNode.WorldPosition); - } - } - else + if (posToMaintain != null) { SteerTowardsPosition((Vector2)posToMaintain); + return; } + autopilotRayCastTimer -= deltaTime; + + steeringPath.CheckProgress(ConvertUnits.ToSimUnits(item.Submarine.WorldPosition), 10.0f); + + if (autopilotRayCastTimer <= 0.0f && steeringPath.NextNode != null) + { + Vector2 diff = Vector2.Normalize(ConvertUnits.ToSimUnits(steeringPath.NextNode.Position - Submarine.Loaded.WorldPosition)); + + bool nextVisible = true; + for (int x = -1; x < 2; x += 2) + { + for (int y = -1; y < 2; y += 2) + { + Vector2 cornerPos = + new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f; + + cornerPos = ConvertUnits.ToSimUnits(cornerPos * 1.2f + Submarine.Loaded.WorldPosition); + + float dist = Vector2.Distance(cornerPos, steeringPath.NextNode.SimPosition); + + if (Submarine.PickBody(cornerPos, cornerPos + diff*dist, null, Physics.CollisionLevel) == null) continue; + + nextVisible = false; + x = 2; + y = 2; + } + } + + if (nextVisible) steeringPath.SkipToNextNode(); + + autopilotRayCastTimer = AutopilotRayCastInterval; + } + + if (steeringPath.CurrentNode != null) + { + SteerTowardsPosition(steeringPath.CurrentNode.WorldPosition); + } } private void SteerTowardsPosition(Vector2 worldPosition) @@ -261,7 +258,7 @@ namespace Barotrauma.Items.Components float prediction = 10.0f; Vector2 futurePosition = ConvertUnits.ToDisplayUnits(item.Submarine.Velocity) * prediction; - Vector2 targetSpeed = ((worldPosition - item.WorldPosition) - futurePosition); + Vector2 targetSpeed = ((worldPosition - item.Submarine.WorldPosition) - futurePosition); if (targetSpeed.Length()>500.0f) { @@ -282,13 +279,13 @@ namespace Barotrauma.Items.Components if (tickBox.Selected) { - if (Submarine.Loaded == null) + if (item.Submarine == null) { posToMaintain = null; } else { - posToMaintain = item.WorldPosition; + posToMaintain = item.Submarine.WorldPosition; } } else