From 1fe71b5fe6e87f9d945616186ee4a9af65a1b8dd Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Wed, 20 Dec 2017 18:54:00 +0300 Subject: [PATCH] Fixed IsInWater acting strangely --- .../Content/Items/Medical/medical.xml | 6 +- .../BarotraumaShared/Source/Items/Item.cs | 68 ++++++++++--------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Content/Items/Medical/medical.xml b/Barotrauma/BarotraumaShared/Content/Items/Medical/medical.xml index eb12d3e2d..123d0f521 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Medical/medical.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Medical/medical.xml @@ -175,11 +175,11 @@ - - --> + @@ -515,7 +515,7 @@ - + diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 8af99c2af..e6e6ef53d 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -777,11 +777,13 @@ namespace Barotrauma private bool IsInWater() { + if (parentInventory != null && parentInventory.Owner != null) + FindHull(); if (CurrentHull == null) return true; float surfaceY = CurrentHull.Surface; - return Position.Y < surfaceY; + return CurrentHull.WaterVolume > 0.0f && Position.Y < surfaceY; } @@ -826,44 +828,46 @@ namespace Barotrauma } } - inWater = IsInWater(); - if (inWater) ApplyStatusEffects(ActionType.InWater, deltaTime); - - if (body == null || !body.Enabled) return; - - System.Diagnostics.Debug.Assert(body.FarseerBody.FixtureList != null); - - if (Math.Abs(body.LinearVelocity.X) > 0.01f || Math.Abs(body.LinearVelocity.Y) > 0.01f) + if (body != null && body.Enabled) { - Submarine prevSub = Submarine; + System.Diagnostics.Debug.Assert(body.FarseerBody.FixtureList != null); - FindHull(); + if (Math.Abs(body.LinearVelocity.X) > 0.01f || Math.Abs(body.LinearVelocity.Y) > 0.01f) + { + Submarine prevSub = Submarine; - if (Submarine == null && prevSub != null) - { - body.SetTransform(body.SimPosition + prevSub.SimPosition, body.Rotation); - } - else if (Submarine != null && prevSub == null) - { - body.SetTransform(body.SimPosition - Submarine.SimPosition, body.Rotation); - } - - Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition); - rect.X = (int)(displayPos.X - rect.Width / 2.0f); - rect.Y = (int)(displayPos.Y + rect.Height / 2.0f); + FindHull(); - if (Math.Abs(body.LinearVelocity.X) > MaxVel || Math.Abs(body.LinearVelocity.Y) > MaxVel) - { - body.LinearVelocity = new Vector2( - MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), - MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel)); + if (Submarine == null && prevSub != null) + { + body.SetTransform(body.SimPosition + prevSub.SimPosition, body.Rotation); + } + else if (Submarine != null && prevSub == null) + { + body.SetTransform(body.SimPosition - Submarine.SimPosition, body.Rotation); + } + + Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition); + rect.X = (int)(displayPos.X - rect.Width / 2.0f); + rect.Y = (int)(displayPos.Y + rect.Height / 2.0f); + + if (Math.Abs(body.LinearVelocity.X) > MaxVel || Math.Abs(body.LinearVelocity.Y) > MaxVel) + { + body.LinearVelocity = new Vector2( + MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), + MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel)); + } } + + UpdateNetPosition(); } - UpdateNetPosition(); - - if (!inWater || ParentInventory != null) return; - + inWater = IsInWater(); + + if (inWater) ApplyStatusEffects(ActionType.InWater, deltaTime); + + if (body == null || !body.Enabled || !inWater || ParentInventory != null) return; + ApplyWaterForces(); CurrentHull?.ApplyFlowForces(deltaTime, this); }