Build 0.21.1.0

This commit is contained in:
Markus Isberg
2023-01-13 18:10:35 +02:00
parent 2f7205fb4b
commit 697ec52120
155 changed files with 2423 additions and 1237 deletions
@@ -24,7 +24,7 @@ namespace Barotrauma
public bool IsAiming => wasAiming;
public bool IsAimingMelee => wasAimingMelee;
protected bool Aiming => aiming || aimingMelee || LockFlippingUntil > Timing.TotalTime && character.IsKeyDown(InputType.Aim);
protected bool Aiming => aiming || aimingMelee || FlipLockTime > Timing.TotalTime && character.IsKeyDown(InputType.Aim);
public float ArmLength => upperArmLength + forearmLength;
@@ -278,7 +278,11 @@ namespace Barotrauma
// We need some margin, because if a hatch has closed, it's possible that the height from floor is slightly negative.
public bool IsAboveFloor => GetHeightFromFloor() > -0.1f;
public float LockFlippingUntil;
public float FlipLockTime { get; private set; }
public void LockFlipping(float time = 0.2f)
{
FlipLockTime = (float)Timing.TotalTime + time;
}
public void UpdateUseItem(bool allowMovement, Vector2 handWorldPos)
{
@@ -994,7 +994,7 @@ namespace Barotrauma
foreach (Limb l in Limbs)
{
if (l.IsSevered) { continue; }
if (!l.DoesFlip) { continue; }
if (!l.DoesFlip) { continue; }
if (RagdollParams.IsSpritesheetOrientationHorizontal)
{
//horizontally aligned limbs need to be flipped 180 degrees
@@ -1014,7 +1014,7 @@ namespace Barotrauma
if (l.IsSevered) { continue; }
float rotation = l.body.Rotation;
if (l.DoesFlip)
if (l.DoesMirror)
{
if (RagdollParams.IsSpritesheetOrientationHorizontal)
{
@@ -150,8 +150,10 @@ namespace Barotrauma
private readonly float movementLerp;
private float cprAnimTimer;
private float cprPump;
private float cprAnimTimer,cprPump;
private float fallingProneAnimTimer;
const float FallingProneAnimDuration = 1.0f;
private bool swimming;
//time until the character can switch from walking to swimming or vice versa
@@ -268,7 +270,8 @@ namespace Barotrauma
if (deathAnimTimer < deathAnimDuration)
{
deathAnimTimer += deltaTime;
UpdateDying(deltaTime);
//the force/torque used to move the limbs goes from 1 to 0 during the death anim duration
UpdateFallingProne(1.0f - deathAnimTimer / deathAnimDuration);
}
}
else
@@ -278,6 +281,11 @@ namespace Barotrauma
if (!character.CanMove)
{
if (fallingProneAnimTimer < FallingProneAnimDuration)
{
fallingProneAnimTimer += deltaTime;
UpdateFallingProne(1.0f);
}
levitatingCollider = false;
Collider.FarseerBody.FixedRotation = false;
if (GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient)
@@ -291,18 +299,20 @@ namespace Barotrauma
}
return;
}
fallingProneAnimTimer = 0.0f;
//re-enable collider
if (!Collider.Enabled)
{
var lowestLimb = FindLowestLimb();
Collider.SetTransform(new Vector2(
Collider.SimPosition.X,
Math.Max(lowestLimb.SimPosition.Y + (Collider.radius + Collider.height / 2), Collider.SimPosition.Y)),
Collider.Rotation);
Collider.FarseerBody.ResetDynamics();
Collider.FarseerBody.LinearVelocity = MainLimb.LinearVelocity;
Collider.Enabled = true;
}
@@ -431,7 +441,7 @@ namespace Barotrauma
}
}
if (Timing.TotalTime > LockFlippingUntil && TargetDir != dir && !IsStuck)
if (Timing.TotalTime > FlipLockTime && TargetDir != dir && !IsStuck)
{
Flip();
}
@@ -1292,10 +1302,9 @@ namespace Barotrauma
}
}
void UpdateDying(float deltaTime)
void UpdateFallingProne(float strength)
{
//the force/torque used to move the limbs goes from 1 to 0 during the death anim duration
float strength = 1.0f - deathAnimTimer / deathAnimDuration;
if (strength <= 0.0f) { return; }
Limb head = GetLimb(LimbType.Head);
Limb torso = GetLimb(LimbType.Torso);
@@ -1319,6 +1328,19 @@ namespace Barotrauma
}
if (torso == null) { return; }
//make the torso tip over
//otherwise it tends to just drop straight down, pinning the characters legs in a weird pose
if (!InWater)
{
//prefer tipping over in the same direction the torso is rotating
//or moving
//or lastly, in the direction it's facing if it's not moving/rotating
float fallDirection = Math.Sign(torso.body.AngularVelocity - torso.body.LinearVelocity.X - Dir * 0.01f);
float torque = MathF.Cos(torso.Rotation) * fallDirection * 5.0f * strength;
torso.body.ApplyTorque(torque * torso.body.Mass);
}
//attempt to make legs stay in a straight line with the torso to prevent the character from doing a split
for (int i = 0; i < 2; i++)
{
@@ -1503,12 +1525,12 @@ namespace Barotrauma
Limb rightHand = GetLimb(LimbType.RightHand);
Limb targetLeftHand = target.AnimController.GetLimb(LimbType.LeftForearm);
if (targetLeftHand == null) targetLeftHand = target.AnimController.GetLimb(LimbType.Torso);
if (targetLeftHand == null) targetLeftHand = target.AnimController.MainLimb;
if (targetLeftHand == null) { targetLeftHand = target.AnimController.GetLimb(LimbType.Torso); }
if (targetLeftHand == null) { targetLeftHand = target.AnimController.MainLimb; }
Limb targetRightHand = target.AnimController.GetLimb(LimbType.RightForearm);
if (targetRightHand == null) targetRightHand = target.AnimController.GetLimb(LimbType.Torso);
if (targetRightHand == null) targetRightHand = target.AnimController.MainLimb;
if (targetRightHand == null) { targetRightHand = target.AnimController.GetLimb(LimbType.Torso); }
if (targetRightHand == null) { targetRightHand = target.AnimController.MainLimb; }
if (!target.AllowInput)
{
@@ -1644,18 +1666,24 @@ namespace Barotrauma
pullLimb.PullJointEnabled = true;
if (targetLimb.type == LimbType.Torso || targetLimb == target.AnimController.MainLimb)
{
Vector2 pullLimbAnchor = targetLimb.SimPosition;
pullLimb.PullJointMaxForce = 5000.0f;
if (!character.HasAbilityFlag(AbilityFlags.MoveNormallyWhileDragging))
{
targetMovement *= MathHelper.Clamp(Mass / target.Mass, 0.5f, 1.0f);
}
Vector2 shoulderPos = rightShoulder.WorldAnchorA;
Vector2 dragDir = inWater ? Vector2.Normalize(targetLimb.SimPosition - shoulderPos) : Vector2.UnitY;
if (!MathUtils.IsValid(dragDir)) { dragDir = Vector2.UnitY; }
targetAnchor = shoulderPos - dragDir * ConvertUnits.ToSimUnits(upperArmLength + forearmLength);
Vector2 shoulderPos = rightShoulder.WorldAnchorA;
float targetDist = Vector2.Distance(targetLimb.SimPosition, shoulderPos);
Vector2 dragDir = (targetLimb.SimPosition - shoulderPos) / targetDist;
if (!MathUtils.IsValid(dragDir)) { dragDir = -Vector2.UnitY; }
if (!InWater)
{
//lerp the arm downwards when not swimming
dragDir = Vector2.Lerp(dragDir, -Vector2.UnitY, 0.5f);
}
Vector2 pullLimbAnchor = shoulderPos + dragDir * Math.Min(targetDist, (upperArmLength + forearmLength) * 2);
targetAnchor = shoulderPos + dragDir * (upperArmLength + forearmLength);
targetForce = 200.0f;
if (target.Submarine != character.Submarine)
{
@@ -1723,7 +1751,7 @@ namespace Barotrauma
{
if (target.AnimController.Dir > 0 == WorldPosition.X > target.WorldPosition.X)
{
target.AnimController.LockFlippingUntil = (float)Timing.TotalTime + 0.5f;
target.AnimController.LockFlipping(0.5f);
}
else
{
@@ -1822,16 +1850,22 @@ namespace Barotrauma
public override void Flip()
{
if (Character == null || Character.Removed)
{
LogAccessedRemovedCharacterError();
return;
}
base.Flip();
WalkPos = -WalkPos;
Limb torso = GetLimb(LimbType.Torso);
Vector2 difference;
if (torso == null) { return; }
Matrix torsoTransform = Matrix.CreateRotationZ(torso.Rotation);
Vector2 difference;
foreach (Item heldItem in character.HeldItems)
{
if (heldItem?.body != null && !heldItem.Removed && heldItem.GetComponent<Holdable>() != null)
@@ -57,17 +57,7 @@ namespace Barotrauma
{
if (limbs == null)
{
if (!accessRemovedCharacterErrorShown)
{
string errorMsg = "Attempted to access a potentially removed ragdoll. Character: " + character.Name + ", id: " + character.ID + ", removed: " + character.Removed + ", ragdoll removed: " + !list.Contains(this);
errorMsg += '\n' + Environment.StackTrace.CleanupStackTrace();
DebugConsole.ThrowError(errorMsg);
GameAnalyticsManager.AddErrorEventOnce(
"Ragdoll.Limbs:AccessRemoved",
GameAnalyticsManager.ErrorSeverity.Error,
"Attempted to access a potentially removed ragdoll. Character: " + character.SpeciesName + ", id: " + character.ID + ", removed: " + character.Removed + ", ragdoll removed: " + !list.Contains(this) + "\n" + Environment.StackTrace.CleanupStackTrace());
accessRemovedCharacterErrorShown = true;
}
LogAccessedRemovedCharacterError();
return Array.Empty<Limb>();
}
return limbs;
@@ -158,6 +148,20 @@ namespace Barotrauma
}
}
public bool TryGetCollider(int index, out PhysicsBody collider)
{
collider = null;
try
{
collider = this.collider?[index];
return true;
}
catch
{
return false;
}
}
public int ColliderIndex
{
get
@@ -873,7 +877,7 @@ namespace Barotrauma
foreach (Limb limb in Limbs)
{
if (limb == null || limb.IsSevered || !limb.DoesFlip) { continue; }
if (limb == null || limb.IsSevered || !limb.DoesMirror) { continue; }
limb.Dir = Dir;
limb.MouthPos = new Vector2(-limb.MouthPos.X, limb.MouthPos.Y);
limb.MirrorPullJoint();
@@ -1428,6 +1432,21 @@ namespace Barotrauma
return true;
}
protected void LogAccessedRemovedCharacterError()
{
if (!accessRemovedCharacterErrorShown)
{
string errorMsg = "Attempted to access a potentially removed ragdoll. Character: " + character.Name + ", id: " + character.ID + ", removed: " + character.Removed + ", ragdoll removed: " + !list.Contains(this);
errorMsg += '\n' + Environment.StackTrace.CleanupStackTrace();
DebugConsole.ThrowError(errorMsg);
GameAnalyticsManager.AddErrorEventOnce(
"Ragdoll:AccessRemoved",
GameAnalyticsManager.ErrorSeverity.Error,
"Attempted to access a potentially removed ragdoll. Character: " + character.SpeciesName + ", id: " + character.ID + ", removed: " + character.Removed + ", ragdoll removed: " + !list.Contains(this) + "\n" + Environment.StackTrace.CleanupStackTrace());
accessRemovedCharacterErrorShown = true;
}
}
partial void UpdateProjSpecific(float deltaTime, Camera cam);
partial void Splash(Limb limb, Hull limbHull);