Merge remote-tracking branch 'upstream/master' into develop

This commit is contained in:
EvilFactory
2024-12-11 10:44:53 -03:00
257 changed files with 4793 additions and 1653 deletions
@@ -921,20 +921,16 @@ namespace Barotrauma
{
isRemote = character.IsRemotelyControlled;
}
if (isRemote)
//if the character is remotely controlled,
//let the server decide when to deselect the ladder and stop climbing
if (!isRemote)
{
if (Math.Abs(targetMovement.X) > 0.05f ||
(TargetMovement.Y < 0.0f && ConvertUnits.ToSimUnits(trigger.Height) + handPos.Y < HeadPosition) ||
(TargetMovement.Y > 0.0f && handPos.Y > 0.1f))
if ((character.IsKeyDown(InputType.Left) || character.IsKeyDown(InputType.Right)) &&
(!character.IsKeyDown(InputType.Up) && !character.IsKeyDown(InputType.Down)))
{
isClimbing = false;
}
}
else if ((character.IsKeyDown(InputType.Left) || character.IsKeyDown(InputType.Right)) &&
(!character.IsKeyDown(InputType.Up) && !character.IsKeyDown(InputType.Down)))
{
isClimbing = false;
}
if (!isClimbing)
{
@@ -147,20 +147,7 @@ namespace Barotrauma
if (!character.CanMove)
{
levitatingCollider = false;
Collider.FarseerBody.FixedRotation = false;
if (GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient)
{
Collider.Enabled = false;
Collider.LinearVelocity = mainLimb.LinearVelocity;
Collider.SetTransformIgnoreContacts(mainLimb.SimPosition, mainLimb.Rotation);
//reset pull joints to prevent the character from "hanging" mid-air if pull joints had been active when the character was still moving
//(except when dragging, then we need the pull joints)
if (!Draggable || character.SelectedBy == null)
{
ResetPullJoints();
}
}
UpdateRagdollControlsMovement();
if (character.IsDead && deathAnimTimer < deathAnimDuration)
{
deathAnimTimer += deltaTime;
@@ -186,11 +173,11 @@ namespace Barotrauma
if (InWater)
{
Collider.SetTransform(new Vector2(Collider.SimPosition.X, MainLimb.SimPosition.Y), 0.0f);
Collider.SetTransformIgnoreContacts(new Vector2(Collider.SimPosition.X, MainLimb.SimPosition.Y), 0.0f);
}
else
{
Collider.SetTransform(new Vector2(
Collider.SetTransformIgnoreContacts(new Vector2(
Collider.SimPosition.X,
Math.Max(lowestLimb.SimPosition.Y + (Collider.Radius + Collider.Height / 2), Collider.SimPosition.Y)),
0.0f);
@@ -995,7 +982,7 @@ namespace Barotrauma
if (RagdollParams.IsSpritesheetOrientationHorizontal)
{
//horizontally aligned limbs need to be flipped 180 degrees
l.body.SetTransform(l.SimPosition, l.body.Rotation + MathHelper.Pi * Dir);
l.body.SetTransformIgnoreContacts(l.SimPosition, l.body.Rotation + MathHelper.Pi * Dir);
}
//no need to do anything when flipping vertically oriented limbs
//the sprite gets flipped horizontally, which does the job
@@ -296,25 +296,7 @@ namespace Barotrauma
fallingProneAnimTimer += deltaTime;
UpdateFallingProne(1.0f);
}
levitatingCollider = false;
Collider.FarseerBody.FixedRotation = false;
if (GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient)
{
if (Collider.Enabled)
{
//deactivating the collider -> make the main limb inherit the collider's velocity because it'll control the movement now
MainLimb.body.LinearVelocity = Collider.LinearVelocity;
Collider.Enabled = false;
}
Collider.LinearVelocity = MainLimb.LinearVelocity;
Collider.SetTransformIgnoreContacts(MainLimb.SimPosition, MainLimb.Rotation);
//reset pull joints to prevent the character from "hanging" mid-air if pull joints had been active when the character was still moving
//(except when dragging, then we need the pull joints)
if (!Draggable || character.SelectedBy == null)
{
ResetPullJoints();
}
}
UpdateRagdollControlsMovement();
return;
}
fallingProneAnimTimer = 0.0f;
@@ -324,7 +306,7 @@ namespace Barotrauma
{
var lowestLimb = FindLowestLimb();
Collider.SetTransform(new Vector2(
Collider.SetTransformIgnoreContacts(new Vector2(
Collider.SimPosition.X,
Math.Max(lowestLimb.SimPosition.Y + (Collider.Radius + Collider.Height / 2), Collider.SimPosition.Y)),
Collider.Rotation);
@@ -356,7 +338,7 @@ namespace Barotrauma
float angleDiff = MathUtils.GetShortestAngle(Collider.Rotation, 0.0f);
if (Math.Abs(angleDiff) > 0.001f)
{
Collider.SetTransform(Collider.SimPosition, Collider.Rotation + angleDiff);
Collider.SetTransformIgnoreContacts(Collider.SimPosition, Collider.Rotation + angleDiff);
}
}
@@ -581,9 +563,7 @@ namespace Barotrauma
footMid += (Math.Max(Math.Abs(walkPosX) * limpAmount, 0.0f) * Math.Min(Math.Abs(TargetMovement.X), 0.3f)) * Dir;
}
movement = overrideTargetMovement == Vector2.Zero ?
MathUtils.SmoothStep(movement, TargetMovement, movementLerp) :
overrideTargetMovement;
movement = overrideTargetMovement ?? MathUtils.SmoothStep(movement, TargetMovement, movementLerp);
if (Math.Abs(movement.X) < 0.005f)
{
@@ -112,7 +112,7 @@ namespace Barotrauma
//a movement vector that overrides targetmovement if trying to steer
//a Character to the position sent by server in multiplayer mode
protected Vector2 overrideTargetMovement;
protected Vector2? overrideTargetMovement;
protected float floorY, standOnFloorY;
protected Fixture floorFixture;
@@ -142,6 +142,12 @@ namespace Barotrauma
private Category prevCollisionCategory = Category.None;
/// <summary>
/// When the character is alive/conscious, the collider drives the character's movement and is used to sync the character's position in MP.
/// When unconscious, the ragdoll controls the movement and the collider just sticks to the main limb.
/// </summary>
public bool ColliderControlsMovement => character.CanMove;
public bool IsStuck => Limbs.Any(l => l.IsStuck);
public PhysicsBody Collider
@@ -189,7 +195,7 @@ namespace Barotrauma
Vector2 pos = collider[colliderIndex].SimPosition;
pos.Y -= collider[colliderIndex].Height * 0.5f;
pos.Y += collider[value].Height * 0.5f;
collider[value].SetTransform(pos, collider[colliderIndex].Rotation);
collider[value].SetTransformIgnoreContacts(pos, collider[colliderIndex].Rotation);
collider[value].LinearVelocity = collider[colliderIndex].LinearVelocity;
collider[value].AngularVelocity = collider[colliderIndex].AngularVelocity;
@@ -286,7 +292,7 @@ namespace Barotrauma
foreach (Limb limb in Limbs)
{
if (limb.IsSevered || !limb.body.PhysEnabled) { continue; }
limb.body.SetTransform(Collider.SimPosition, Collider.Rotation);
limb.body.SetTransformIgnoreContacts(Collider.SimPosition, Collider.Rotation);
//reset pull joints (they may be somewhere far away if the character has moved from the position where animations were last updated)
limb.PullJointEnabled = false;
limb.PullJointWorldAnchorB = limb.SimPosition;
@@ -301,11 +307,11 @@ namespace Barotrauma
{
get
{
return (overrideTargetMovement == Vector2.Zero) ? targetMovement : overrideTargetMovement;
return overrideTargetMovement ?? targetMovement;
}
set
{
if (!MathUtils.IsValid(value)) return;
if (!MathUtils.IsValid(value)) { return; }
targetMovement.X = MathHelper.Clamp(value.X, -MAX_SPEED, MAX_SPEED);
targetMovement.Y = MathHelper.Clamp(value.Y, -MAX_SPEED, MAX_SPEED);
}
@@ -1307,6 +1313,11 @@ namespace Barotrauma
}
}
float MaxVel = NetConfig.MaxPhysicsBodyVelocity;
Collider.LinearVelocity = new Vector2(
NetConfig.Quantize(Collider.LinearVelocity.X, -MaxVel, MaxVel, 12),
NetConfig.Quantize(Collider.LinearVelocity.Y, -MaxVel, MaxVel, 12));
if (forceStanding)
{
inWater = false;
@@ -1451,7 +1462,7 @@ namespace Barotrauma
else
{
// Falling -> ragdoll briefly if we are not moving at all, because we are probably stuck.
if (Collider.LinearVelocity == Vector2.Zero)
if (Collider.LinearVelocity == Vector2.Zero && !character.IsRemotePlayer)
{
character.IsRagdolled = true;
if (character.IsBot)
@@ -1466,6 +1477,30 @@ namespace Barotrauma
forceNotStanding = false;
}
/// <summary>
/// Update the logic that needs to run when the ragdoll is what controls the character's movement instead of the collider <see cref="ColliderControlsMovement"/>
/// (making the collider stick to the ragdoll's main limb).
/// </summary>
protected void UpdateRagdollControlsMovement()
{
levitatingCollider = false;
Collider.FarseerBody.FixedRotation = false;
if (Collider.Enabled)
{
//deactivating the collider -> make the main limb inherit the collider's velocity because it'll control the movement now
MainLimb.body.LinearVelocity = Collider.LinearVelocity;
Collider.Enabled = false;
}
Collider.LinearVelocity = MainLimb.LinearVelocity;
Collider.SetTransformIgnoreContacts(MainLimb.SimPosition, MainLimb.Rotation);
//reset pull joints to prevent the character from "hanging" mid-air if pull joints had been active when the character was still moving
//(except when dragging, then we need the pull joints)
if (!Draggable || character.SelectedBy == null)
{
ResetPullJoints();
}
}
private void CheckBodyInRest(float deltaTime)
{
if (SimplePhysicsEnabled) { return; }
@@ -2102,7 +2137,7 @@ namespace Barotrauma
partial void UpdateNetPlayerPositionProjSpecific(float deltaTime, float lowestSubPos);
private void UpdateNetPlayerPosition(float deltaTime)
{
if (GameMain.NetworkMember == null) return;
if (GameMain.NetworkMember == null) { return; }
float lowestSubPos = float.MaxValue;
if (Submarine.Loaded.Any())