diff --git a/Subsurface/Content/Items/Electricity/signalitems.xml b/Subsurface/Content/Items/Electricity/signalitems.xml index abf9de80d..c9f705ebc 100644 --- a/Subsurface/Content/Items/Electricity/signalitems.xml +++ b/Subsurface/Content/Items/Electricity/signalitems.xml @@ -124,7 +124,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -159,7 +159,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -193,7 +193,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -230,7 +230,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -269,7 +269,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -302,7 +302,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -336,7 +336,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -367,7 +367,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -398,7 +398,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -431,7 +431,7 @@ - @@ -463,7 +463,7 @@ - @@ -493,7 +493,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> @@ -526,7 +526,7 @@ + aimpos="65,-10" handle1="0,0" attachable="true" aimable="true"> diff --git a/Subsurface/Source/Characters/AI/HumanAIController.cs b/Subsurface/Source/Characters/AI/HumanAIController.cs index 0a912eb10..34ecde408 100644 --- a/Subsurface/Source/Characters/AI/HumanAIController.cs +++ b/Subsurface/Source/Characters/AI/HumanAIController.cs @@ -72,6 +72,8 @@ namespace Barotrauma steeringManager.Update(moveSpeed); Character.AnimController.IgnorePlatforms = (-Character.AnimController.TargetMovement.Y > Math.Abs(Character.AnimController.TargetMovement.X*0.5f)); + (Character.AnimController as HumanoidAnimController).Crouching = false; + if (!Character.AnimController.InWater) { @@ -125,6 +127,8 @@ namespace Barotrauma public override void OnAttacked(IDamageable attacker, float amount) { + if (amount <= 0.0f) return; + var enemy = attacker as Character; if (enemy == null || enemy == Character) return; diff --git a/Subsurface/Source/Characters/Animation/AnimController.cs b/Subsurface/Source/Characters/Animation/AnimController.cs index e86eba7a6..cc3d82144 100644 --- a/Subsurface/Source/Characters/Animation/AnimController.cs +++ b/Subsurface/Source/Characters/Animation/AnimController.cs @@ -6,7 +6,7 @@ namespace Barotrauma { class AnimController : Ragdoll { - public enum Animation { None, Climbing, UsingConstruction, Struggle }; + public enum Animation { None, Climbing, UsingConstruction, Struggle, CPR }; public Animation Anim; public Direction TargetDir; diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index f05b937cd..bfc4c5287 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -9,6 +9,8 @@ namespace Barotrauma { class HumanoidAnimController : AnimController { + public bool Crouching; + private bool aiming; private float walkAnimSpeed; @@ -17,6 +19,30 @@ namespace Barotrauma private float thighTorque; + protected override float HeadPosition + { + get + { + return Crouching ? base.HeadPosition : base.HeadPosition; + } + } + + protected override float TorsoPosition + { + get + { + return Crouching ? base.TorsoPosition - base.HeadPosition * 0.3f : base.TorsoPosition; + } + } + + protected override float TorsoAngle + { + get + { + return Crouching ? base.TorsoAngle+0.5f : base.TorsoAngle; + } + } + public HumanoidAnimController(Character character, XElement element) : base(character, element) { @@ -182,6 +208,16 @@ namespace Barotrauma break; case Animation.UsingConstruction: UpdateStanding(); + break; + case Animation.CPR: + if (character.SelectedCharacter == null) + { + Anim = Animation.None; + return; + } + + DragCharacter(character.SelectedCharacter); + break; default: if (inWater) @@ -268,6 +304,8 @@ namespace Barotrauma Vector2 stepSize = new Vector2( this.stepSize.X * walkPosX * runningModifier, this.stepSize.Y * walkPosY * runningModifier * runningModifier); + + if (Crouching) stepSize *= 0.5f; float footMid = waist.SimPosition.X;// (leftFoot.SimPosition.X + rightFoot.SimPosition.X) / 2.0f; @@ -300,43 +338,46 @@ namespace Barotrauma if (!onGround || (LowestLimb.SimPosition.Y - floorY > 0.5f && stairs == null)) return; + float? ceilingY = null; + if (Submarine.PickBody(head.SimPosition, head.SimPosition + Vector2.UnitY, null, Physics.CollisionWall)!=null) + { + ceilingY = Submarine.LastPickedPosition.Y; + + if (ceilingY - floorY < HeadPosition) Crouching = true; + } + getUpSpeed = getUpSpeed * Math.Max(head.SimPosition.Y - colliderPos.Y, 0.5f); + torso.pullJoint.Enabled = true; + head.pullJoint.Enabled = true; + waist.pullJoint.Enabled = true; + if (stairs != null) { if (LowestLimb.SimPosition.Y < stairs.SimPosition.Y) IgnorePlatforms = true; - torso.pullJoint.Enabled = true; torso.pullJoint.WorldAnchorB = new Vector2( MathHelper.SmoothStep(torso.SimPosition.X, footMid + movement.X * 0.35f, getUpSpeed * 0.8f), MathHelper.SmoothStep(torso.SimPosition.Y, colliderPos.Y + TorsoPosition - Math.Abs(walkPosX * 0.05f), getUpSpeed * 2.0f)); - head.pullJoint.Enabled = true; head.pullJoint.WorldAnchorB = new Vector2( - MathHelper.SmoothStep(head.SimPosition.X, footMid + movement.X * 0.4f, getUpSpeed * 0.8f), + MathHelper.SmoothStep(head.SimPosition.X, footMid + movement.X * (Crouching ? 1.0f : 0.4f), getUpSpeed * 0.8f), MathHelper.SmoothStep(head.SimPosition.Y, colliderPos.Y + HeadPosition - Math.Abs(walkPosX * 0.05f), getUpSpeed * 2.0f)); - waist.pullJoint.Enabled = true; waist.pullJoint.WorldAnchorB = waist.SimPosition;// +movement * 0.3f; } else { - torso.pullJoint.Enabled = true; torso.pullJoint.WorldAnchorB = MathUtils.SmoothStep(torso.SimPosition, new Vector2(footMid + movement.X * 0.3f, colliderPos.Y + TorsoPosition), getUpSpeed); - - head.pullJoint.Enabled = true; head.pullJoint.WorldAnchorB = MathUtils.SmoothStep(head.SimPosition, - new Vector2(footMid + movement.X * 0.3f, colliderPos.Y + HeadPosition), getUpSpeed*1.2f); + new Vector2(footMid + movement.X * (Crouching && Math.Sign(movement.X)==Math.Sign(Dir) ? 1.0f : 0.3f), colliderPos.Y + HeadPosition), getUpSpeed*1.2f); - waist.pullJoint.Enabled = true; waist.pullJoint.WorldAnchorB = waist.SimPosition + movement * 0.1f; - //MathUtils.SmoothStep(waist.SimPosition, - //new Vector2(footMid + movement.X * 0.4f, colliderPos.Y + HeadPosition), getUpSpeed); } @@ -416,12 +457,20 @@ namespace Barotrauma { float movementFactor = (movement.X / 4.0f) * movement.X * Math.Sign(movement.X); + + + //MoveLimb(leftFoot, footPos, 2.5f); + + for (int i = -1; i < 2; i+=2 ) + { Vector2 footPos = new Vector2( - colliderPos.X, + Crouching ? waist.SimPosition.X + Math.Sign(stepSize.X*i)*Dir*0.3f : waist.SimPosition.X, colliderPos.Y - 0.2f); - MoveLimb(leftFoot, footPos, 2.5f); - MoveLimb(rightFoot, footPos, 2.5f); + var foot = i == -1 ? rightFoot : leftFoot; + + MoveLimb(foot, footPos, Math.Abs(foot.SimPosition.X - footPos.X)*50.0f); + } leftFoot.body.SmoothRotate(Dir * MathHelper.PiOver2, 5.0f); rightFoot.body.SmoothRotate(Dir * MathHelper.PiOver2, 5.0f); @@ -850,7 +899,6 @@ namespace Barotrauma targetLimb.pullJoint.Enabled = true; targetLimb.pullJoint.WorldAnchorB = pullLimb.SimPosition; - } @@ -1039,30 +1087,49 @@ namespace Barotrauma foreach (Limb limb in Limbs) { + bool mirror = false; + bool flipAngle = false; + bool wrapAngle = false; + switch (limb.type) { case LimbType.LeftHand: case LimbType.LeftArm: case LimbType.RightHand: case LimbType.RightArm: - if (!limb.pullJoint.Enabled) - { - difference = limb.body.SimPosition - torso.SimPosition; - difference = Vector2.Transform(difference, torsoTransform); - difference.Y = -difference.Y; - - TrySetLimbPosition(limb, limb.SimPosition, torso.SimPosition + Vector2.Transform(difference, -torsoTransform)); - } - limb.body.SetTransform(limb.body.SimPosition, -limb.body.Rotation); + mirror = true; + flipAngle = true; + break; + case LimbType.LeftThigh: + case LimbType.LeftLeg: + case LimbType.LeftFoot: + case LimbType.RightThigh: + case LimbType.RightLeg: + case LimbType.RightFoot: + mirror = true; + flipAngle = true; + wrapAngle = true; break; default: - if (!inWater) limb.body.SetTransform(limb.body.SimPosition, - MathUtils.WrapAnglePi(limb.body.Rotation * (limb.DoesFlip ? -1.0f : 1.0f))); + flipAngle = limb.DoesFlip; break; } + + if (!limb.pullJoint.Enabled && mirror) + { + difference = limb.body.SimPosition - torso.SimPosition; + difference = Vector2.Transform(difference, torsoTransform); + difference.Y = -difference.Y; + + TrySetLimbPosition(limb, limb.SimPosition, torso.SimPosition + Vector2.Transform(difference, -torsoTransform)); + } + + float angle = flipAngle ? -limb.body.Rotation : limb.body.Rotation; + if (wrapAngle) angle = MathUtils.WrapAnglePi(angle); + + limb.body.SetTransform(limb.body.SimPosition, angle); } - } - + } } diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index f058eecd9..ca0916238 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -117,22 +117,22 @@ namespace Barotrauma } } - public float HeadPosition + protected virtual float HeadPosition { get { return headPosition; } } - public float HeadAngle + protected virtual float HeadAngle { get { return headAngle; } } - - public float TorsoPosition + + protected virtual float TorsoPosition { get { return torsoPosition; } } - public float TorsoAngle + protected virtual float TorsoAngle { get { return torsoAngle; } } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 1a4695485..91fc5539a 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -235,6 +235,11 @@ namespace Barotrauma } } + public bool IsUnconscious + { + get { return (needsAir && oxygen < 0.0f) || health < 0.0f; } + } + public bool NeedsAir { get { return needsAir; } @@ -246,8 +251,8 @@ namespace Barotrauma set { if (!MathUtils.IsValid(value)) return; - oxygen = MathHelper.Clamp(value, 0.0f, 100.0f); - if (oxygen == 0.0f) Kill(AnimController.InWater ? CauseOfDeath.Drowning : CauseOfDeath.Suffocation); + oxygen = MathHelper.Clamp(value, -100.0f, 100.0f); + if (oxygen == -100.0f) Kill(AnimController.InWater ? CauseOfDeath.Drowning : CauseOfDeath.Suffocation); } } @@ -269,7 +274,7 @@ namespace Barotrauma set { if (!MathUtils.IsValid(value)) return; - health = MathHelper.Clamp(value, 0.0f, maxHealth); + health = MathHelper.Clamp(value, -100.0f, maxHealth); } } @@ -656,9 +661,13 @@ namespace Barotrauma Vector2 targetMovement = GetTargetMovement(); AnimController.TargetMovement = targetMovement; - AnimController.IgnorePlatforms = AnimController.TargetMovement.Y < 0.0f; + if (AnimController is HumanoidAnimController) + { + ((HumanoidAnimController) AnimController).Crouching = IsKeyDown(InputType.Crouch); + } + if (AnimController.onGround && !AnimController.InWater && AnimController.Anim != AnimController.Animation.UsingConstruction) @@ -988,7 +997,7 @@ namespace Barotrauma networkUpdateSent = false; } - + if (needsAir) { bool protectedFromPressure = PressureProtection > 0.0f; @@ -1016,7 +1025,7 @@ namespace Barotrauma PressureTimer = 0.0f; } } - + if (controlled == this) { Lights.LightManager.ViewTarget = this; @@ -1024,6 +1033,12 @@ namespace Barotrauma ControlLocalPlayer(deltaTime, cam); } + if (IsUnconscious) + { + UpdateUnconscious(deltaTime); + return; + } + if (controlled==this || !(this is AICharacter)) Control(deltaTime, cam); UpdateSightRange(); @@ -1052,12 +1067,19 @@ namespace Barotrauma Health -= bleeding * deltaTime; Bleeding -= BleedingDecreaseSpeed * deltaTime; - if (health <= 0.0f) Kill(CauseOfDeath.Bloodloss, false); + if (health <= 0.0f) Kill(CauseOfDeath.Bloodloss); if (!IsDead) LockHands = false; } + private void UpdateUnconscious(float deltaTime) + { + Stun = Math.Max(5.0f, Stun); + if (oxygen < 0.0f) Oxygen -= deltaTime; + + if (health < 0.0f) Health -= Math.Max(bleeding, 1.0f) * deltaTime; + } private void UpdateSightRange() { diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index 036d711a6..3bd0927ea 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -10,7 +10,7 @@ namespace Barotrauma.Items.Components { class RepairTool : ItemComponent { - private List fixableEntities; + private readonly List fixableEntities; private float range; @@ -80,13 +80,6 @@ namespace Barotrauma.Items.Components { this.item = item; - //range = ToolBox.GetAttributeFloat(element, "range", 100.0f); - //range = ConvertUnits.ToSimUnits(range); - - //structureFixAmount = ToolBox.GetAttributeFloat(element, "structurefixamount", 1.0f); - //limbFixAmount = ToolBox.GetAttributeFloat(element, "limbfixamount", -0.5f); - - fixableEntities = new List(); foreach (XElement subElement in element.Elements()) { @@ -194,23 +187,13 @@ namespace Barotrauma.Items.Components } else if ((targetItem = (targetBody.UserData as Item)) != null) { - //targetItem.Condition -= structureFixAmount; targetItem.IsHighlighted = true; foreach (StatusEffect effect in statusEffects) { - //if (Array.IndexOf(effect.TargetNames, targetItem.Name) == -1) continue; effect.Apply(ActionType.OnUse, deltaTime, item, targetItem.AllPropertyObjects); - //targetItem.ApplyStatusEffect(effect, ActionType.OnUse, deltaTime); } - //ApplyStatusEffects(ActionType.OnUse, 1.0f, null, targ); } - //if (Character.SecondaryKeyDown.State) - //{ - // IPropertyObject propertyObject = targetBody.UserData as IPropertyObject; - // if (propertyObject!=null) ApplyStatusEffects(ActionType.OnUse, 1.0f, item.SimPosition, propertyObject); - // //isActive = true; - //} return true; } diff --git a/Subsurface/Source/Items/Components/Signal/LightComponent.cs b/Subsurface/Source/Items/Components/Signal/LightComponent.cs index 534419757..ae135333e 100644 --- a/Subsurface/Source/Items/Components/Signal/LightComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/LightComponent.cs @@ -150,9 +150,9 @@ namespace Barotrauma.Items.Components public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, bool editing = false) { - if (light.LightSprite != null) + if (light.LightSprite != null && (item.body==null || item.body.Enabled)) { - light.LightSprite.Draw(spriteBatch, new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), lightColor * lightBrightness); + light.LightSprite.Draw(spriteBatch, new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), lightColor * lightBrightness, 0.0f, 1.0f, Microsoft.Xna.Framework.Graphics.SpriteEffects.None, item.Sprite.Depth-0.0001f); } } diff --git a/Subsurface/Source/PlayerInput.cs b/Subsurface/Source/PlayerInput.cs index 179828393..8ce5e59c0 100644 --- a/Subsurface/Source/PlayerInput.cs +++ b/Subsurface/Source/PlayerInput.cs @@ -10,7 +10,7 @@ namespace Barotrauma Use, Aim, Up, Down, Left, Right, - Run, + Run, Crouch, Chat, CrewOrders } diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index 549d59f61..83b32f28e 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -93,14 +93,15 @@ namespace Barotrauma foreach (Submarine sub in Submarine.SavedSubmarines) { - GUITextBlock textBlock = new GUITextBlock( + new GUITextBlock( new Rectangle(0, 0, 0, 25), - sub.Name, - GUI.Style, - Alignment.Left, Alignment.Left, mapList); - textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); - textBlock.ToolTip = sub.Description; - textBlock.UserData = sub; + sub.Name, GUI.Style, + Alignment.Left, Alignment.Left, mapList) + { + Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f), + ToolTip = sub.Description, + UserData = sub + }; } if (Submarine.SavedSubmarines.Count > 0) mapList.Select(Submarine.SavedSubmarines[0]); diff --git a/Subsurface/config.xml b/Subsurface/config.xml index 02812052c..fa7192526 100644 --- a/Subsurface/config.xml +++ b/Subsurface/config.xml @@ -2,5 +2,5 @@ - + \ No newline at end of file