(b522c4551) Don't assign the attackinglimb if we shouldn't be attacking. Fixes Hammerhead not falling back after hitting the sub.

This commit is contained in:
Joonas Rikkonen
2019-04-01 22:50:39 +03:00
parent e9a3577316
commit 5d6cbb5898
10 changed files with 126 additions and 109 deletions
@@ -44,29 +44,25 @@ namespace Barotrauma
return;
}
if (character.MemState[0].SelectedCharacter == null || character.MemState[0].SelectedCharacter.Removed)
if (character.MemState[0].Interact == null || character.MemState[0].Interact.Removed)
{
character.DeselectCharacter();
}
else if (character.MemState[0].SelectedCharacter != null)
{
character.SelectCharacter(character.MemState[0].SelectedCharacter);
}
if (character.MemState[0].SelectedItem == null || character.MemState[0].SelectedItem.Removed)
{
character.SelectedConstruction = null;
}
else
else if (character.MemState[0].Interact is Character)
{
if (character.SelectedConstruction != character.MemState[0].SelectedItem)
character.SelectCharacter((Character)character.MemState[0].Interact);
}
else if (character.MemState[0].Interact is Item newSelectedConstruction)
{
if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction)
{
foreach (var ic in character.MemState[0].SelectedItem.Components)
foreach (var ic in newSelectedConstruction.Components)
{
if (ic.CanBeSelected) ic.Select(character);
}
}
character.SelectedConstruction = character.MemState[0].SelectedItem;
character.SelectedConstruction = newSelectedConstruction;
}
if (character.MemState[0].Animation == AnimController.Animation.CPR)
@@ -92,13 +88,13 @@ namespace Barotrauma
Collider.AngularVelocity = newAngularVelocity;
float distSqrd = Vector2.DistanceSquared(newPosition, Collider.SimPosition);
float errorTolerance = character.AllowInput ? 0.01f : 0.2f;
float errorTolerance = character.AllowInput ? 0.01f : 0.1f;
if (distSqrd > errorTolerance)
{
if (distSqrd > 10.0f || !character.AllowInput)
{
Collider.TargetRotation = newRotation;
SetPosition(newPosition, lerp: distSqrd < 5.0f);
SetPosition(newPosition, lerp: distSqrd < 1.0f);
}
else
{
@@ -112,15 +108,8 @@ namespace Barotrauma
// -> we need to correct it manually
if (!character.AllowInput)
{
float mainLimbDistSqrd = Vector2.DistanceSquared(MainLimb.PullJointWorldAnchorA, Collider.SimPosition);
float mainLimbErrorTolerance = 0.1f;
//if the main limb is roughly at the correct position and the collider isn't moving (much at least),
//don't attempt to correct the position.
if (mainLimbDistSqrd > mainLimbErrorTolerance || Collider.LinearVelocity.LengthSquared() > 0.05f)
{
MainLimb.PullJointWorldAnchorB = Collider.SimPosition;
MainLimb.PullJointEnabled = true;
}
MainLimb.PullJointWorldAnchorB = Collider.SimPosition;
MainLimb.PullJointEnabled = true;
}
}
character.MemLocalState.Clear();
@@ -173,30 +162,25 @@ namespace Barotrauma
CharacterStateInfo localPos = character.MemLocalState[localPosIndex];
//the entity we're interacting with doesn't match the server's
if (localPos.SelectedCharacter != serverPos.SelectedCharacter)
if (localPos.Interact != serverPos.Interact)
{
if (serverPos.SelectedCharacter == null || serverPos.SelectedCharacter.Removed)
if (serverPos.Interact == null || serverPos.Interact.Removed)
{
character.DeselectCharacter();
}
else if (serverPos.SelectedCharacter != null)
{
character.SelectCharacter(serverPos.SelectedCharacter);
}
}
if (localPos.SelectedItem != serverPos.SelectedItem)
{
if (serverPos.SelectedItem == null || serverPos.SelectedItem.Removed)
{
character.SelectedConstruction = null;
}
else if (serverPos.SelectedItem != null)
else if (serverPos.Interact is Character)
{
if (character.SelectedConstruction != serverPos.SelectedItem)
character.SelectCharacter((Character)serverPos.Interact);
}
else
{
var newSelectedConstruction = (Item)serverPos.Interact;
if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction)
{
serverPos.SelectedItem.TryInteract(character, true, true);
newSelectedConstruction.TryInteract(character, true, true);
}
character.SelectedConstruction = serverPos.SelectedItem;
character.SelectedConstruction = newSelectedConstruction;
}
}
@@ -30,13 +30,12 @@ namespace Barotrauma
else
{
var posInfo = new CharacterStateInfo(
SimPosition,
AnimController.Collider.Rotation,
LastNetworkUpdateID,
AnimController.TargetDir,
SelectedCharacter,
SelectedConstruction,
AnimController.Anim);
SimPosition,
AnimController.Collider.Rotation,
LastNetworkUpdateID,
AnimController.TargetDir,
SelectedCharacter == null ? (Entity)SelectedConstruction : (Entity)SelectedCharacter,
AnimController.Anim);
memLocalState.Add(posInfo);
@@ -215,7 +214,6 @@ namespace Barotrauma
Vector2 linearVelocity = new Vector2(
msg.ReadRangedSingle(-MaxVel, MaxVel, 12),
msg.ReadRangedSingle(-MaxVel, MaxVel, 12));
linearVelocity = NetConfig.Quantize(linearVelocity, -MaxVel, MaxVel, 12);
bool fixedRotation = msg.ReadBoolean();
float? rotation = null;
@@ -225,7 +223,6 @@ namespace Barotrauma
rotation = msg.ReadFloat();
float MaxAngularVel = NetConfig.MaxPhysicsBodyAngularVelocity;
angularVelocity = msg.ReadRangedSingle(-MaxAngularVel, MaxAngularVel, 8);
angularVelocity = NetConfig.Quantize(angularVelocity.Value, -MaxAngularVel, MaxAngularVel, 8);
}
bool readStatus = msg.ReadBoolean();
@@ -239,11 +236,7 @@ namespace Barotrauma
int index = 0;
if (GameMain.Client.Character == this && AllowInput)
{
var posInfo = new CharacterStateInfo(
pos, rotation,
networkUpdateID,
facingRight ? Direction.Right : Direction.Left,
selectedCharacter, selectedItem, animation);
var posInfo = new CharacterStateInfo(pos, rotation, networkUpdateID, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation);
while (index < memState.Count && NetIdUtils.IdMoreRecent(posInfo.ID, memState[index].ID))
index++;
@@ -251,11 +244,7 @@ namespace Barotrauma
}
else
{
var posInfo = new CharacterStateInfo(
pos, rotation,
linearVelocity, angularVelocity,
sendingTime, facingRight ? Direction.Right : Direction.Left,
selectedCharacter, selectedItem, animation);
var posInfo = new CharacterStateInfo(pos, rotation, linearVelocity, angularVelocity, sendingTime, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation);
while (index < memState.Count && posInfo.Timestamp > memState[index].Timestamp)
index++;
@@ -656,13 +656,6 @@ namespace Barotrauma
msg.Timer -= deltaTime;
msg.Pos += msg.Velocity * deltaTime;
}
foreach (GUIMessage msg in messages)
{
if (!msg.WorldSpace) continue;
msg.Timer -= deltaTime;
msg.Pos += msg.Velocity * deltaTime;
}
}
messages.RemoveAll(m => m.Timer <= 0.0f);
@@ -171,12 +171,9 @@ namespace Barotrauma
newVelocity = new Vector2(
msg.ReadRangedSingle(-MaxVel, MaxVel, 12),
msg.ReadRangedSingle(-MaxVel, MaxVel, 12));
newVelocity = NetConfig.Quantize(newVelocity, -MaxVel, MaxVel, 12);
if (!fixedRotation)
{
newAngularVelocity = msg.ReadRangedSingle(-MaxAngularVel, MaxAngularVel, 8);
newAngularVelocity = NetConfig.Quantize(newAngularVelocity.Value, -MaxAngularVel, MaxAngularVel, 8);
}
}
msg.ReadPadBits();