From c08029dea8b7b0b124bfb5099c230a745290c621 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 24 Apr 2016 20:31:26 +0300 Subject: [PATCH] Handheld sonars only consume batteries when they're on, endworms aren't "flipped" when they turn around, every limb is checked in SubmarineBody.DisplaceCharacters (instead of just reflimb) --- .../Content/Characters/Endworm/endworm.xml | 18 +++++------ .../Content/Characters/Moloch/moloch.xml | 2 +- .../Content/Characters/Watcher/watcher.xml | 2 +- Subsurface/Content/Items/Tools/tools.xml | 2 +- .../Animation/FishAnimController.cs | 11 ++++--- .../Source/Characters/Animation/Ragdoll.cs | 17 +++++++++-- Subsurface/Source/Map/SubmarineBody.cs | 30 +++++++++++-------- Subsurface/Source/Physics/PhysicsBody.cs | 2 +- 8 files changed, 52 insertions(+), 32 deletions(-) diff --git a/Subsurface/Content/Characters/Endworm/endworm.xml b/Subsurface/Content/Characters/Endworm/endworm.xml index 78b17f1a8..bfcaecdb7 100644 --- a/Subsurface/Content/Characters/Endworm/endworm.xml +++ b/Subsurface/Content/Characters/Endworm/endworm.xml @@ -5,40 +5,40 @@ - + - + - + - + - + - + - + - + - + diff --git a/Subsurface/Content/Characters/Moloch/moloch.xml b/Subsurface/Content/Characters/Moloch/moloch.xml index 765e02224..c4b6ba180 100644 --- a/Subsurface/Content/Characters/Moloch/moloch.xml +++ b/Subsurface/Content/Characters/Moloch/moloch.xml @@ -6,7 +6,7 @@ - + diff --git a/Subsurface/Content/Characters/Watcher/watcher.xml b/Subsurface/Content/Characters/Watcher/watcher.xml index 9101f725a..14b2c3abd 100644 --- a/Subsurface/Content/Characters/Watcher/watcher.xml +++ b/Subsurface/Content/Characters/Watcher/watcher.xml @@ -1,7 +1,7 @@  - + diff --git a/Subsurface/Content/Items/Tools/tools.xml b/Subsurface/Content/Items/Tools/tools.xml index 903c590b1..4f05e60dc 100644 --- a/Subsurface/Content/Items/Tools/tools.xml +++ b/Subsurface/Content/Items/Tools/tools.xml @@ -199,6 +199,7 @@ holdangle="30" handle1="-10,0"/> + @@ -208,7 +209,6 @@ - diff --git a/Subsurface/Source/Characters/Animation/FishAnimController.cs b/Subsurface/Source/Characters/Animation/FishAnimController.cs index 99e100c4c..8e9731489 100644 --- a/Subsurface/Source/Characters/Animation/FishAnimController.cs +++ b/Subsurface/Source/Characters/Animation/FishAnimController.cs @@ -17,7 +17,7 @@ namespace Barotrauma private bool rotateTowardsMovement; - private bool flip; + private bool mirror, flip; private float flipTimer; @@ -29,7 +29,8 @@ namespace Barotrauma waveAmplitude = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "waveamplitude", 0.0f)); waveLength = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "wavelength", 0.0f)); - flip = ToolBox.GetAttributeBool(element, "flip", false); + flip = ToolBox.GetAttributeBool(element, "flip", true); + mirror = ToolBox.GetAttributeBool(element, "mirror", false); float footRot = ToolBox.GetAttributeFloat(element,"footrotation", float.NaN); if (float.IsNaN(footRot)) @@ -82,7 +83,7 @@ namespace Barotrauma } } - if (flip) + if (mirror) { if (!character.IsNetworkPlayer) { @@ -117,6 +118,8 @@ namespace Barotrauma } //if (stunTimer > gameTime.TotalGameTime.TotalMilliseconds) return; + if (!flip) return; + flipTimer += deltaTime; if (TargetDir != dir) @@ -124,7 +127,7 @@ namespace Barotrauma if (flipTimer>1.0f || character.IsNetworkPlayer) { Flip(); - if (flip) Mirror(); + if (mirror) Mirror(); flipTimer = 0.0f; } } diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index fcf7c7eb4..c9ef82302 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -112,8 +112,8 @@ namespace Barotrauma set { if (!MathUtils.IsValid(value)) return; - targetMovement.X = MathHelper.Clamp(value.X, -3.0f, 3.0f); - targetMovement.Y = MathHelper.Clamp(value.Y, -3.0f, 3.0f); + targetMovement.X = MathHelper.Clamp(value.X, -5.0f, 5.0f); + targetMovement.Y = MathHelper.Clamp(value.Y, -5.0f, 5.0f); } } @@ -152,6 +152,8 @@ namespace Barotrauma get { return headInWater; } } + public readonly bool CanEnterSubmarine; + public Hull CurrentHull { get { return currentHull; } @@ -213,6 +215,8 @@ namespace Barotrauma torsoPosition = ToolBox.GetAttributeFloat(element, "torsoposition", 50.0f); torsoPosition = ConvertUnits.ToSimUnits(torsoPosition); torsoAngle = MathHelper.ToRadians(ToolBox.GetAttributeFloat(element, "torsoangle", 0.0f)); + + CanEnterSubmarine = ToolBox.GetAttributeBool(element, "canentersubmarine", true); foreach (XElement subElement in element.Elements()) { @@ -272,6 +276,8 @@ namespace Barotrauma if (refLimb == null) refLimb = GetLimb(LimbType.Head); if (refLimb == null) DebugConsole.ThrowError("Character ''" + character + "'' doesn't have a head or torso!"); + UpdateCollisionCategories(); + foreach (var joint in limbJoints) { @@ -550,6 +556,11 @@ namespace Barotrauma public void FindHull(Vector2? worldPosition = null, bool setSubmarine = true) { + if (!CanEnterSubmarine) + { + return; + } + Vector2 findPos = worldPosition==null ? refLimb.WorldPosition : (Vector2)worldPosition; Hull newHull = Hull.FindHull(findPos, currentHull); @@ -747,7 +758,7 @@ namespace Barotrauma } } - if (lerp) + if (lerp) { limb.body.TargetPosition = movePos; limb.body.MoveToTargetPosition(Vector2.Distance(limb.SimPosition, movePos) < 10.0f); diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index 8e9e39e1b..8c19cbbcf 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -296,20 +296,26 @@ namespace Barotrauma foreach (Character c in Character.CharacterList) { if (c.AnimController.CurrentHull != null) continue; - - //if the character isn't inside the bounding box, continue - if (!Submarine.RectContains(worldBorders, c.WorldPosition)) continue; - //cast a line from the position of the character to the same direction as the translation of the sub - //and see where it intersects with the bounding box - Vector2? intersection = MathUtils.GetLineRectangleIntersection(c.WorldPosition, - c.WorldPosition + translateDir*100000.0f, worldBorders); - - //should never be null when casting a line out from inside the bounding box - Debug.Assert(intersection != null); + foreach (Limb limb in c.AnimController.Limbs) + { + //if the character isn't inside the bounding box, continue + if (!Submarine.RectContains(worldBorders, limb.WorldPosition)) continue; - c.AnimController.SetPosition(ConvertUnits.ToSimUnits((Vector2)intersection) + translateDir); - //''+ translatedir'' in order to move the character slightly away from the wall + //cast a line from the position of the character to the same direction as the translation of the sub + //and see where it intersects with the bounding box + Vector2? intersection = MathUtils.GetLineRectangleIntersection(limb.WorldPosition, + limb.WorldPosition + translateDir*100000.0f, worldBorders); + + //should never be null when casting a line out from inside the bounding box + Debug.Assert(intersection != null); + + //''+ translatedir'' in order to move the character slightly away from the wall + c.AnimController.SetPosition(c.WorldPosition + ConvertUnits.ToSimUnits((Vector2)intersection - limb.WorldPosition) + translateDir); + + return; + } + } } diff --git a/Subsurface/Source/Physics/PhysicsBody.cs b/Subsurface/Source/Physics/PhysicsBody.cs index dab2bfeff..65b03900c 100644 --- a/Subsurface/Source/Physics/PhysicsBody.cs +++ b/Subsurface/Source/Physics/PhysicsBody.cs @@ -313,7 +313,7 @@ namespace Barotrauma prevPosition = targetPosition; } - body.SetTransform(targetPosition, targetRotation); + body.SetTransform(targetPosition, targetRotation == 0.0f ? body.Rotation : targetRotation); body.LinearVelocity = targetVelocity; body.AngularVelocity = targetAngularVelocity; targetPosition = Vector2.Zero;