Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into unstable

This commit is contained in:
EvilFactory
2022-09-29 12:13:55 -03:00
602 changed files with 19759 additions and 16312 deletions
@@ -101,7 +101,7 @@ namespace Barotrauma
{
if (InWater || !CanWalk)
{
return TargetMovement.LengthSquared() > MathUtils.Pow2(SwimSlowParams.MovementSpeed);
return TargetMovement.LengthSquared() > MathUtils.Pow2(SwimSlowParams.MovementSpeed + 0.0001f);
}
else
{
@@ -134,9 +134,12 @@ namespace Barotrauma
}
}
public enum Animation { None, Climbing, UsingConstruction, Struggle, CPR };
public enum Animation { None, Climbing, UsingItem, Struggle, CPR, UsingItemWhileClimbing };
public Animation Anim;
public bool IsUsingItem => Anim == Animation.UsingItem || Anim == Animation.UsingItemWhileClimbing;
public bool IsClimbing => Anim == Animation.Climbing || Anim == Animation.UsingItemWhileClimbing;
public Vector2 AimSourceWorldPos
{
get
@@ -280,7 +283,7 @@ namespace Barotrauma
public void UpdateUseItem(bool allowMovement, Vector2 handWorldPos)
{
useItemTimer = 0.5f;
Anim = Animation.UsingConstruction;
StartUsingItem();
if (!allowMovement)
{
@@ -359,8 +362,13 @@ namespace Barotrauma
Vector2 itemPos = aim ? aimPos : holdPos;
var controller = character.SelectedConstruction?.GetComponent<Controller>();
var controller = character.SelectedItem?.GetComponent<Controller>();
bool usingController = controller != null && !controller.AllowAiming;
if (!usingController)
{
controller = character.SelectedSecondaryItem?.GetComponent<Controller>();
usingController = controller != null && !controller.AllowAiming;
}
bool isClimbing = character.IsClimbing && Math.Abs(character.AnimController.TargetMovement.Y) > 0.01f;
float itemAngle;
Holdable holdable = item.GetComponent<Holdable>();
@@ -722,5 +730,45 @@ namespace Barotrauma
CalculateArmLengths();
}
}
private void StartAnimation(Animation animation)
{
if (animation == Animation.UsingItem)
{
Anim = IsClimbing ? Animation.UsingItemWhileClimbing : Animation.UsingItem;
}
else if (animation == Animation.Climbing)
{
Anim = IsUsingItem ? Animation.UsingItemWhileClimbing : Animation.Climbing;
}
else
{
Anim = animation;
}
}
private void StopAnimation(Animation animation)
{
if (animation == Animation.UsingItem)
{
Anim = IsClimbing ? Animation.Climbing : Animation.None;
}
else if (animation == Animation.Climbing)
{
Anim = IsUsingItem ? Animation.UsingItem : Animation.None;
}
else
{
Anim = Animation.None;
}
}
public void StartUsingItem() => StartAnimation(Animation.UsingItem);
public void StartClimbing() => StartAnimation(Animation.Climbing);
public void StopUsingItem() => StopAnimation(Animation.UsingItem);
public void StopClimbing() => StopAnimation(Animation.Climbing);
}
}
@@ -237,13 +237,14 @@ namespace Barotrauma
public override void UpdateAnim(float deltaTime)
{
if (Frozen) return;
if (Frozen) { return; }
if (MainLimb == null) { return; }
levitatingCollider = !IsHanging;
ColliderIndex = Crouching && !swimming ? 1 : 0;
if (character.SelectedConstruction?.GetComponent<Controller>()?.ControlCharacterPose ?? false ||
character.SelectedConstruction?.GetComponent<Ladder>() != null ||
if ((character.SelectedItem?.GetComponent<Controller>()?.ControlCharacterPose ?? false) ||
(character.SelectedSecondaryItem?.GetComponent<Controller>()?.ControlCharacterPose ?? false) ||
character.SelectedSecondaryItem?.GetComponent<Ladder>() != null ||
(ForceSelectAnimationType != AnimationType.Crouch && ForceSelectAnimationType != AnimationType.NotDefined))
{
Crouching = false;
@@ -330,35 +331,41 @@ namespace Barotrauma
Collider.SetTransform(Collider.SimPosition, Collider.Rotation + angleDiff);
}
}
if (character.LockHands)
{
var leftHand = GetLimb(LimbType.LeftHand);
var rightHand = GetLimb(LimbType.RightHand);
var waist = GetLimb(LimbType.Waist) ?? GetLimb(LimbType.Torso);
rightHand.Disabled = true;
leftHand.Disabled = true;
Vector2 midPos = waist.SimPosition;
Matrix torsoTransform = Matrix.CreateRotationZ(waist.Rotation);
midPos += Vector2.Transform(new Vector2(-0.3f * Dir, -0.2f), torsoTransform);
if (rightHand.PullJointEnabled) midPos = (midPos + rightHand.PullJointWorldAnchorB) / 2.0f;
HandIK(rightHand, midPos, CurrentAnimationParams.ArmIKStrength, CurrentAnimationParams.HandIKStrength);
HandIK(leftHand, midPos, CurrentAnimationParams.ArmIKStrength, CurrentAnimationParams.HandIKStrength);
}
else if (character.AnimController.AnimationTestPose)
if (character.AnimController.AnimationTestPose)
{
ApplyTestPose();
}
else
else if (character.SelectedBy == null)
{
if (Anim != Animation.UsingConstruction)
if (character.LockHands)
{
ResetPullJoints();
var leftHand = GetLimb(LimbType.LeftHand);
var rightHand = GetLimb(LimbType.RightHand);
var waist = GetLimb(LimbType.Waist) ?? GetLimb(LimbType.Torso);
rightHand.Disabled = true;
leftHand.Disabled = true;
Vector2 midPos = waist.SimPosition;
Matrix torsoTransform = Matrix.CreateRotationZ(waist.Rotation);
midPos += Vector2.Transform(new Vector2(-0.3f * Dir, -0.2f), torsoTransform);
if (rightHand.PullJointEnabled) midPos = (midPos + rightHand.PullJointWorldAnchorB) / 2.0f;
HandIK(rightHand, midPos, CurrentAnimationParams.ArmIKStrength, CurrentAnimationParams.HandIKStrength);
HandIK(leftHand, midPos, CurrentAnimationParams.ArmIKStrength, CurrentAnimationParams.HandIKStrength);
}
if (Anim != Animation.UsingItem)
{
if (Anim != Animation.UsingItemWhileClimbing)
{
ResetPullJoints();
}
else
{
ResetPullJoints(l => l.IsLowerBody);
}
}
}
@@ -377,49 +384,53 @@ namespace Barotrauma
switch (Anim)
{
case Animation.Climbing:
case Animation.UsingItemWhileClimbing:
levitatingCollider = false;
UpdateClimbing();
UpdateUseItemTimer();
break;
case Animation.CPR:
UpdateCPR(deltaTime);
break;
case Animation.UsingConstruction:
case Animation.UsingItem:
default:
if (Anim == Animation.UsingConstruction)
{
useItemTimer -= deltaTime;
if (useItemTimer <= 0.0f) Anim = Animation.None;
}
UpdateUseItemTimer();
swimmingStateLockTimer -= deltaTime;
if (forceStanding || character.AnimController.AnimationTestPose)
{
swimming = false;
}
else
else if (swimming != inWater && swimmingStateLockTimer <= 0.0f)
{
//0.5 second delay for switching between swimming and walking
//prevents rapid switches between swimming/walking if the water level is fluctuating around the minimum swimming depth
if (swimming != inWater && swimmingStateLockTimer <= 0.0f)
{
swimming = inWater;
swimmingStateLockTimer = 0.5f;
}
swimming = inWater;
swimmingStateLockTimer = 0.5f;
}
if (swimming)
{
UpdateSwimming();
}
else
else if (character.SelectedItem == null || !(character.SelectedSecondaryItem?.GetComponent<Controller>() is { } controller) ||
!controller.ControlCharacterPose || !controller.UserInCorrectPosition)
{
UpdateStanding();
}
break;
}
void UpdateUseItemTimer()
{
if (IsUsingItem)
{
useItemTimer -= deltaTime;
if (useItemTimer <= 0.0f)
{
StopUsingItem();
}
}
}
if (Timing.TotalTime > LockFlippingUntil && TargetDir != dir && !IsStuck)
{
Flip();
@@ -841,7 +852,9 @@ namespace Barotrauma
float targetSpeed = TargetMovement.Length();
if (targetSpeed > 0.1f && !character.IsRemotelyControlled && !Aiming)
{
if (Anim != Animation.UsingConstruction && !(character.SelectedConstruction?.GetComponent<Controller>()?.ControlCharacterPose ?? false))
if (!IsUsingItem &&
!(character.SelectedItem?.GetComponent<Controller>()?.ControlCharacterPose ?? false) &&
!(character.SelectedSecondaryItem?.GetComponent<Controller>()?.ControlCharacterPose ?? false))
{
if (rotation > 20 && rotation < 170)
{
@@ -1041,12 +1054,17 @@ namespace Barotrauma
void UpdateClimbing()
{
var ladder = character.SelectedConstruction?.GetComponent<Ladder>();
if (ladder == null || character.IsIncapacitated)
var ladder = character.SelectedSecondaryItem?.GetComponent<Ladder>();
if (character.IsIncapacitated)
{
Anim = Animation.None;
return;
}
else if (ladder == null)
{
StopClimbing();
return;
}
onGround = false;
IgnorePlatforms = true;
@@ -1209,15 +1227,21 @@ namespace Barotrauma
{
RotateHead(head);
}
else if (Anim == Animation.UsingItemWhileClimbing && character.SelectedItem is { } selectedItem)
{
Vector2 diff = (selectedItem.WorldPosition - head.WorldPosition) * Dir;
float targetRotation = MathHelper.WrapAngle(MathUtils.VectorToAngle(diff) - MathHelper.PiOver4 * Dir);
head.body.SmoothRotate(targetRotation, force: WalkParams.HeadTorque);
}
else
{
float movementMultiplier = targetMovement.Y < 0 ? 0 : 1;
head.body.SmoothRotate(MathHelper.PiOver4 * movementMultiplier * Dir, WalkParams.HeadTorque);
head.body.SmoothRotate(MathHelper.PiOver4 * movementMultiplier * Dir, force: WalkParams.HeadTorque);
}
if (!ladder.Item.Prefab.Triggers.Any())
if (ladder.Item.Prefab.Triggers.None())
{
character.SelectedConstruction = null;
character.SelectedSecondaryItem = null;
return;
}
@@ -1247,8 +1271,7 @@ namespace Barotrauma
if (!isClimbing)
{
Anim = Animation.None;
character.SelectedConstruction = null;
character.StopClimbing();
IgnorePlatforms = false;
}
@@ -1474,17 +1497,17 @@ namespace Barotrauma
public override void DragCharacter(Character target, float deltaTime)
{
if (target == null) return;
if (target == null) { return; }
Limb torso = GetLimb(LimbType.Torso);
Limb leftHand = GetLimb(LimbType.LeftHand);
Limb rightHand = GetLimb(LimbType.RightHand);
Limb targetLeftHand = target.AnimController.GetLimb(LimbType.LeftHand);
Limb targetLeftHand = target.AnimController.GetLimb(LimbType.LeftForearm);
if (targetLeftHand == null) targetLeftHand = target.AnimController.GetLimb(LimbType.Torso);
if (targetLeftHand == null) targetLeftHand = target.AnimController.MainLimb;
Limb targetRightHand = target.AnimController.GetLimb(LimbType.RightHand);
Limb targetRightHand = target.AnimController.GetLimb(LimbType.RightForearm);
if (targetRightHand == null) targetRightHand = target.AnimController.GetLimb(LimbType.Torso);
if (targetRightHand == null) targetRightHand = target.AnimController.MainLimb;
@@ -1493,7 +1516,7 @@ namespace Barotrauma
target.AnimController.ResetPullJoints();
}
if (Anim == Animation.Climbing)
if (IsClimbing)
{
//cannot drag up ladders if the character is conscious
if (target.AllowInput && (GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient))
@@ -1613,7 +1636,7 @@ namespace Barotrauma
}
//only pull with one hand when swimming
if (i > 0 && inWater) continue;
if (i > 0 && inWater) { continue; }
Vector2 diff = ConvertUnits.ToSimUnits(targetLimb.WorldPosition - pullLimb.WorldPosition);
@@ -1665,14 +1688,15 @@ namespace Barotrauma
targetForce = 5000.0f;
}
if (!target.AllowInput)
{
targetLimb.PullJointEnabled = true;
targetLimb.PullJointMaxForce = targetForce;
targetLimb.PullJointWorldAnchorB = targetAnchor;
}
targetLimb.PullJointEnabled = true;
targetLimb.PullJointMaxForce = targetForce;
targetLimb.PullJointWorldAnchorB = targetAnchor;
targetLimb.Disabled = true;
target.AnimController.movement = -diff;
if (diff.LengthSquared() > 0.1f)
{
target.AnimController.movement = -diff;
}
}
float dist = ConvertUnits.ToSimUnits(Vector2.Distance(target.WorldPosition, WorldPosition));
@@ -1698,8 +1722,17 @@ namespace Barotrauma
}
else if (target is AICharacter && target != Character.Controlled)
{
target.AnimController.TargetDir = WorldPosition.X > target.WorldPosition.X ? Direction.Right : Direction.Left;
target.AnimController.TargetMovement = (character.SimPosition + Vector2.UnitX * Dir) - target.SimPosition;
if (target.AnimController.Dir > 0 == WorldPosition.X > target.WorldPosition.X)
{
target.AnimController.LockFlippingUntil = (float)Timing.TotalTime + 0.5f;
}
else
{
target.AnimController.TargetDir = WorldPosition.X > target.WorldPosition.X ? Direction.Right : Direction.Left;
}
//make the target stand 0.5 meters away from this character, on the side they're currently at
Vector2 movement = (character.SimPosition + Vector2.UnitX * 0.5f * Math.Sign(target.SimPosition.X - character.SimPosition.X)) - target.SimPosition;
target.AnimController.TargetMovement = movement.LengthSquared() > 0.01f ? movement : Vector2.Zero;
}
}
}
@@ -930,12 +930,13 @@ namespace Barotrauma
{
limb.MoveToPos(pos, amount, pullFromCenter);
}
public void ResetPullJoints()
public void ResetPullJoints(Func<Limb, bool> condition = null)
{
for (int i = 0; i < Limbs.Length; i++)
{
if (Limbs[i] == null) { continue; }
if (condition != null && !condition(Limbs[i])) { continue; }
Limbs[i].PullJointEnabled = false;
}
}
@@ -1241,7 +1242,7 @@ namespace Barotrauma
{
//find the room which the limb is in
//the room where the ragdoll is in is used as the "guess", meaning that it's checked first
Hull limbHull = currentHull == null ? null : Hull.FindHull(limb.WorldPosition, currentHull);
Hull newHull = currentHull == null ? null : Hull.FindHull(limb.WorldPosition, currentHull);
bool prevInWater = limb.InWater;
limb.InWater = false;
@@ -1250,38 +1251,37 @@ namespace Barotrauma
{
limb.InWater = false;
}
else if (limbHull == null)
else if (newHull == null)
{
//limb isn't in any room -> it's in the water
limb.InWater = true;
if (limb.type == LimbType.Head) headInWater = true;
if (limb.type == LimbType.Head) { headInWater = true; }
}
else if (limbHull.WaterVolume > 0.0f && Submarine.RectContains(limbHull.Rect, limb.Position))
else if (newHull.WaterVolume > 0.0f && Submarine.RectContains(newHull.Rect, limb.Position))
{
if (limb.Position.Y < limbHull.Surface)
if (limb.Position.Y < newHull.Surface)
{
limb.InWater = true;
surfaceY = limbHull.Surface;
surfaceY = newHull.Surface;
if (limb.type == LimbType.Head)
{
headInWater = true;
}
}
//the limb has gone through the surface of the water
if (Math.Abs(limb.LinearVelocity.Y) > 5.0f && limb.InWater != prevInWater)
if (Math.Abs(limb.LinearVelocity.Y) > 5.0f && limb.InWater != prevInWater && newHull == limb.Hull)
{
Splash(limb, limbHull);
Splash(limb, newHull);
//if the Character dropped into water, create a wave
if (limb.LinearVelocity.Y < 0.0f)
{
Vector2 impulse = limb.LinearVelocity * limb.Mass;
int n = (int)((limb.Position.X - limbHull.Rect.X) / Hull.WaveWidth);
limbHull.WaveVel[n] += MathHelper.Clamp(impulse.Y, -5.0f, 5.0f);
int n = (int)((limb.Position.X - newHull.Rect.X) / Hull.WaveWidth);
newHull.WaveVel[n] += MathHelper.Clamp(impulse.Y, -5.0f, 5.0f);
}
}
}
limb.Hull = newHull;
limb.Update(deltaTime);
}
@@ -1499,12 +1499,12 @@ namespace Barotrauma
}
if (flowForce.LengthSquared() > 0.001f)
{
Collider.ApplyForce(flowForce);
{
Collider.ApplyForce(flowForce * (Collider.Mass / Mass));
foreach (Limb limb in limbs)
{
if (!limb.InWater) { continue; }
limb.body.ApplyForce(flowForce);
limb.body.ApplyForce(flowForce * (limb.Mass / Mass * limbs.Length));
}
}
}