Add an atmos throw velocity cap, adjustible console variables, and fix throw directions for station rotation (#7631)

This commit is contained in:
20kdc
2022-04-18 15:42:32 +01:00
committed by GitHub
parent 86a474f321
commit 4892b7960f
3 changed files with 54 additions and 4 deletions

View File

@@ -104,6 +104,9 @@ namespace Content.Server.Atmos.EntitySystems
}
}
// Used by ExperiencePressureDifference to correct push/throw directions from tile-relative to physics world.
var gridWorldRotation = xforms.GetComponent(gridAtmosphere.Owner).WorldRotation;
foreach (var entity in _lookup.GetEntitiesIntersecting(tile.GridIndex, tile.GridIndices))
{
// Ideally containers would have their own EntityQuery internally or something given recursively it may need to slam GetComp<T> anyway.
@@ -125,6 +128,7 @@ namespace Content.Server.Atmos.EntitySystems
tile.PressureDifference,
tile.PressureDirection, 0,
tile.PressureSpecificTarget?.GridIndices.ToEntityCoordinates(tile.GridIndex, _mapManager) ?? EntityCoordinates.Invalid,
gridWorldRotation,
xforms.GetComponent(entity),
body);
}
@@ -140,6 +144,7 @@ namespace Content.Server.Atmos.EntitySystems
_spaceWindSoundCooldown = 0;
}
// Called from AtmosphereSystem.LINDA.cs with SpaceWind CVar check handled there.
private void ConsiderPressureDifference(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, TileAtmosphere other, float difference)
{
gridAtmosphere.HighPressureDelta.Add(tile);
@@ -157,6 +162,7 @@ namespace Content.Server.Atmos.EntitySystems
AtmosDirection direction,
float pressureResistanceProbDelta,
EntityCoordinates throwTarget,
Angle gridWorldRotation,
TransformComponent? xform = null,
PhysicsComponent? physics = null)
{
@@ -188,18 +194,28 @@ namespace Content.Server.Atmos.EntitySystems
if (maxForce > MovedByPressureComponent.ThrowForce)
{
var moveForce = maxForce;
moveForce /= (throwTarget != EntityCoordinates.Invalid) ? SpaceWindPressureForceDivisorThrow : SpaceWindPressureForceDivisorPush;
moveForce *= MathHelper.Clamp(moveProb, 0, 100);
// Apply a sanity clamp to prevent being thrown through objects.
var maxSafeForceForObject = SpaceWindMaxVelocity * physics.Mass;
moveForce = MathF.Min(moveForce, maxSafeForceForObject);
// Grid-rotation adjusted direction
var dirVec = (direction.ToAngle() + gridWorldRotation).ToWorldVec();
// TODO: Technically these directions won't be correct but uhh I'm just here for optimisations buddy not to fix my old bugs.
if (throwTarget != EntityCoordinates.Invalid)
{
var moveForce = maxForce * MathHelper.Clamp(moveProb, 0, 100) / 15f;
var pos = ((throwTarget.Position - xform.Coordinates.Position).Normalized + direction.ToDirection().ToVec()).Normalized;
var pos = ((throwTarget.ToMap(EntityManager).Position - xform.WorldPosition).Normalized + dirVec).Normalized;
physics.ApplyLinearImpulse(pos * moveForce);
}
else
{
var moveForce = MathF.Min(maxForce * MathHelper.Clamp(moveProb, 0, 100) / 2500f, 20f);
physics.ApplyLinearImpulse(direction.ToDirection().ToVec() * moveForce);
moveForce = MathF.Min(moveForce, SpaceWindMaxPushForce);
physics.ApplyLinearImpulse(dirVec * moveForce);
}
component.LastHighPressureMovementAirCycle = cycle;