Unstable 1.1.14.0

This commit is contained in:
Markus Isberg
2023-10-02 16:43:54 +03:00
parent 94f5a93a0c
commit cf8f0de659
606 changed files with 21906 additions and 11456 deletions
@@ -56,6 +56,16 @@ namespace Barotrauma.Items.Components
}
}
enum StickTargetType
{
Structure,
Limb,
Item,
Submarine,
LevelWall,
Unknown
}
public const float WaterDragCoefficient = 0.1f;
private readonly Queue<Impact> impactQueue = new Queue<Impact>();
@@ -353,7 +363,7 @@ namespace Barotrauma.Items.Components
if (Item.Removed) { return; }
launchPos = simPosition;
//set the rotation of the projectile again because dropping the projectile resets the rotation
Item.SetTransform(simPosition, rotation + (Item.body.Dir * LaunchRotationRadians));
Item.SetTransform(simPosition, rotation + (Item.body.Dir * LaunchRotationRadians), findNewHull: false);
if (DeactivationTime > 0)
{
deactivationTimer = DeactivationTime;
@@ -442,27 +452,49 @@ namespace Barotrauma.Items.Components
{
hits.Clear();
Vector2 prevVelocity = item.body.LinearVelocity;
if (item.AiTarget != null)
{
item.AiTarget.SightRange = item.AiTarget.MaxSightRange;
item.AiTarget.SoundRange = item.AiTarget.MaxSoundRange;
}
//do not create a network event about dropping the projectile at this point,
//otherwise clients would fail to launch the correct projectile when firing the weapon
var prevInventory = item.ParentInventory;
if (prevInventory != null && GameMain.NetworkMember is { IsServer: true })
{
//update the state of the inventory after a delay,
//in case a client failed to launch the projectile for some reason
CoroutineManager.Invoke(() =>
{
if (item.Removed) { return; }
prevInventory.CreateNetworkEvent();
}, delay: CorrectionDelay / 2);
}
item.Drop(null, createNetworkEvent: false);
Item.WaterDragCoefficient = WaterDragCoefficient;
launchPos = item.SimPosition;
item.body.Enabled = true;
item.body.Enabled = true;
if (item.body.BodyType == BodyType.Kinematic)
{
item.body.LinearVelocity = impulse;
}
else
else if (impulse.LengthSquared() > 0.001f)
{
impulse *= item.body.Mass;
item.body.ApplyLinearImpulse(impulse, maxVelocity: NetConfig.MaxPhysicsBodyVelocity * 0.95f);
}
else
{
//if no impulse is defined, maintain the projectile's original velocity (if any)
//can be used to make throwable items behave as projectiles
item.body.LinearVelocity = prevVelocity;
}
item.body.FarseerBody.OnCollision += OnProjectileCollision;
item.body.FarseerBody.IsBullet = true;
@@ -483,7 +515,7 @@ namespace Barotrauma.Items.Components
float rotation = item.body.Rotation;
Vector2 simPositon = item.SimPosition;
Vector2 rayStartWorld = item.WorldPosition;
item.Drop(null);
item.Drop(null, createNetworkEvent: false);
Item.WaterDragCoefficient = WaterDragCoefficient;
item.body.Enabled = true;
@@ -666,6 +698,7 @@ namespace Barotrauma.Items.Components
if (fixture.Body.UserData is VoronoiCell) { return -1; }
if (fixture.Body.UserData is Entity entity && entity.Submarine != submarine) { return -1; }
if (fixture.Body.UserData is Limb limb && limb.character?.Submarine != submarine) { return -1; }
if (fixture.Body == Level.Loaded?.TopBarrier || fixture.Body == Level.Loaded?.BottomBarrier) { return -1; }
}
// Ignore holdables that can't push -> shouldn't block
@@ -891,8 +924,17 @@ namespace Barotrauma.Items.Components
return false;
}
Vector2 dir = item.body.LinearVelocity.LengthSquared() < 0.001f ?
contact.Manifold.LocalNormal : Vector2.Normalize(item.body.LinearVelocity);
Vector2 normalizedVel;
Vector2 dir;
if (item.body.LinearVelocity.LengthSquared() < 0.001f)
{
normalizedVel = Vector2.Zero;
dir = contact.Manifold.LocalNormal;
}
else
{
normalizedVel = dir = Vector2.Normalize(item.body.LinearVelocity);
}
//do a raycast in the sub's coordinate space to see if it hit a structure
var wallBody = Submarine.PickBody(
@@ -901,7 +943,7 @@ namespace Barotrauma.Items.Components
collisionCategory: Physics.CollisionWall);
if (wallBody?.FixtureList?.First() != null && (wallBody.UserData is Structure || wallBody.UserData is Item) &&
//ignore the hit if it's behind the position the item was launched from, and the projectile is travelling in the opposite direction
Vector2.Dot(item.body.SimPosition - launchPos, dir) > 0)
Vector2.Dot((item.body.SimPosition + normalizedVel) - launchPos, dir) > 0)
{
target = wallBody.FixtureList.First();
if (hits.Contains(target.Body))
@@ -1136,7 +1178,13 @@ namespace Barotrauma.Items.Components
removePending = true;
item.HiddenInGame = true;
item.body.FarseerBody.Enabled = false;
Entity.Spawner?.AddItemToRemoveQueue(item);
//delete with a brief delay so we don't delete the item
//before a client has managed to launch it (can happen with hitscan projectile)
CoroutineManager.Invoke(() =>
{
if (item.Removed) { return; }
Entity.Spawner?.AddItemToRemoveQueue(item);
}, delay: 0.5f);
}
return true;
@@ -1181,6 +1229,11 @@ namespace Barotrauma.Items.Components
IgnoredBodies?.Clear();
}
public bool IsAttachedTo(PhysicsBody body)
{
return stickJoint != null && (stickJoint.BodyA == body?.FarseerBody || stickJoint.BodyB == body?.FarseerBody);
}
private void StickToTarget(Body targetBody, Vector2 axis)
{
if (stickJoint != null) { return; }