Fixed IsInWater acting strangely

This commit is contained in:
Alex Noir
2017-12-20 18:54:00 +03:00
parent 20e583d816
commit 1fe71b5fe6
2 changed files with 39 additions and 35 deletions
@@ -175,11 +175,11 @@
<StatusEffect type="OnUse" target="Character" Health="-5.0" disabledeltatime="true"> <StatusEffect type="OnUse" target="Character" Health="-5.0" disabledeltatime="true">
<RequiredItem name="Medical Syringe" type="Container"/> <RequiredItem name="Medical Syringe" type="Container"/>
</StatusEffect> </StatusEffect>
<!-- InWater is horribly broken right now. https://github.com/Regalis11/Barotrauma/issues/187 <!-- InWater is horribly broken right now. https://github.com/Regalis11/Barotrauma/issues/187 -->
<StatusEffect type="InWater" target="This" Condition="0.0" setvalue="true"> <StatusEffect type="InWater" target="This" Condition="0.0" setvalue="true">
<Sound file="Content/Items/Reactor/explosion.ogg"/> <Sound file="Content/Items/Reactor/explosion.ogg"/>
<Explosion range="250.0" structuredamage="10" damage="20" stun="5" force="5.0"/> <Explosion range="250.0" structuredamage="10" damage="20" stun="5" force="5.0"/>
</StatusEffect> --> </StatusEffect>
</Throwable> </Throwable>
</Item> </Item>
@@ -515,7 +515,7 @@
</StatusEffect> </StatusEffect>
<!-- Here's a problem: if a chemical with delay is injected into more than one person, only the last person will get that delayed effect. <!-- Here's a problem: if a chemical with delay is injected into more than one person, only the last person will get that delayed effect.
Everyone else gets off scott free! Woo!!!..... --> Everyone else gets off scott free! Woo!!!..... -->
<StatusEffect type="OnUse" target="Character" Oxygen="-15.0" Health="-1.0" duration="60.0" delay="20.0"> <StatusEffect type="OnUse" target="Character" Oxygen="-20.0" Health="-1.0" duration="60.0" delay="20.0">
<RequiredItem name="Medical Syringe" type="Container"/> <RequiredItem name="Medical Syringe" type="Container"/>
</StatusEffect> </StatusEffect>
</Throwable> </Throwable>
@@ -777,11 +777,13 @@ namespace Barotrauma
private bool IsInWater() private bool IsInWater()
{ {
if (parentInventory != null && parentInventory.Owner != null)
FindHull();
if (CurrentHull == null) return true; if (CurrentHull == null) return true;
float surfaceY = CurrentHull.Surface; float surfaceY = CurrentHull.Surface;
return Position.Y < surfaceY; return CurrentHull.WaterVolume > 0.0f && Position.Y < surfaceY;
} }
@@ -826,43 +828,45 @@ namespace Barotrauma
} }
} }
inWater = IsInWater(); if (body != null && body.Enabled)
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)
{ {
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) FindHull();
{
body.SetTransform(body.SimPosition + prevSub.SimPosition, body.Rotation); if (Submarine == null && prevSub != null)
} {
else if (Submarine != null && prevSub == null) body.SetTransform(body.SimPosition + prevSub.SimPosition, body.Rotation);
{ }
body.SetTransform(body.SimPosition - Submarine.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));
}
} }
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition); UpdateNetPosition();
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(); inWater = IsInWater();
if (!inWater || ParentInventory != null) return; if (inWater) ApplyStatusEffects(ActionType.InWater, deltaTime);
if (body == null || !body.Enabled || !inWater || ParentInventory != null) return;
ApplyWaterForces(); ApplyWaterForces();
CurrentHull?.ApplyFlowForces(deltaTime, this); CurrentHull?.ApplyFlowForces(deltaTime, this);