Skip to content

Commit 4892b79

Browse files
authoredApr 18, 2022
Add an atmos throw velocity cap, adjustible console variables, and fix throw directions for station rotation (#7631)
1 parent 86a474f commit 4892b79

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed
 

‎Content.Server/Atmos/EntitySystems/AtmosphereSystem.CVars.cs

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public sealed partial class AtmosphereSystem
99
[Dependency] private readonly IConfigurationManager _cfg = default!;
1010

1111
public bool SpaceWind { get; private set; }
12+
public float SpaceWindPressureForceDivisorThrow { get; private set; }
13+
public float SpaceWindPressureForceDivisorPush { get; private set; }
14+
public float SpaceWindMaxVelocity { get; private set; }
15+
public float SpaceWindMaxPushForce { get; private set; }
1216
public bool MonstermosEqualization { get; private set; }
1317
public bool MonstermosDepressurization { get; private set; }
1418
public bool MonstermosRipTiles { get; private set; }
@@ -23,6 +27,10 @@ public sealed partial class AtmosphereSystem
2327
private void InitializeCVars()
2428
{
2529
_cfg.OnValueChanged(CCVars.SpaceWind, value => SpaceWind = value, true);
30+
_cfg.OnValueChanged(CCVars.SpaceWindPressureForceDivisorThrow, value => SpaceWindPressureForceDivisorThrow = value, true);
31+
_cfg.OnValueChanged(CCVars.SpaceWindPressureForceDivisorPush, value => SpaceWindPressureForceDivisorPush = value, true);
32+
_cfg.OnValueChanged(CCVars.SpaceWindMaxVelocity, value => SpaceWindMaxVelocity = value, true);
33+
_cfg.OnValueChanged(CCVars.SpaceWindMaxPushForce, value => SpaceWindMaxPushForce = value, true);
2634
_cfg.OnValueChanged(CCVars.MonstermosEqualization, value => MonstermosEqualization = value, true);
2735
_cfg.OnValueChanged(CCVars.MonstermosDepressurization, value => MonstermosDepressurization = value, true);
2836
_cfg.OnValueChanged(CCVars.MonstermosRipTiles, value => MonstermosRipTiles = value, true);

‎Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ private void HighPressureMovements(GridAtmosphereComponent gridAtmosphere, TileA
104104
}
105105
}
106106

107+
// Used by ExperiencePressureDifference to correct push/throw directions from tile-relative to physics world.
108+
var gridWorldRotation = xforms.GetComponent(gridAtmosphere.Owner).WorldRotation;
109+
107110
foreach (var entity in _lookup.GetEntitiesIntersecting(tile.GridIndex, tile.GridIndices))
108111
{
109112
// Ideally containers would have their own EntityQuery internally or something given recursively it may need to slam GetComp<T> anyway.
@@ -125,6 +128,7 @@ private void HighPressureMovements(GridAtmosphereComponent gridAtmosphere, TileA
125128
tile.PressureDifference,
126129
tile.PressureDirection, 0,
127130
tile.PressureSpecificTarget?.GridIndices.ToEntityCoordinates(tile.GridIndex, _mapManager) ?? EntityCoordinates.Invalid,
131+
gridWorldRotation,
128132
xforms.GetComponent(entity),
129133
body);
130134
}
@@ -140,6 +144,7 @@ private void HighPressureMovements(GridAtmosphereComponent gridAtmosphere, TileA
140144
_spaceWindSoundCooldown = 0;
141145
}
142146

147+
// Called from AtmosphereSystem.LINDA.cs with SpaceWind CVar check handled there.
143148
private void ConsiderPressureDifference(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, TileAtmosphere other, float difference)
144149
{
145150
gridAtmosphere.HighPressureDelta.Add(tile);
@@ -157,6 +162,7 @@ public void ExperiencePressureDifference(
157162
AtmosDirection direction,
158163
float pressureResistanceProbDelta,
159164
EntityCoordinates throwTarget,
165+
Angle gridWorldRotation,
160166
TransformComponent? xform = null,
161167
PhysicsComponent? physics = null)
162168
{
@@ -188,18 +194,28 @@ public void ExperiencePressureDifference(
188194

189195
if (maxForce > MovedByPressureComponent.ThrowForce)
190196
{
197+
var moveForce = maxForce;
198+
moveForce /= (throwTarget != EntityCoordinates.Invalid) ? SpaceWindPressureForceDivisorThrow : SpaceWindPressureForceDivisorPush;
199+
moveForce *= MathHelper.Clamp(moveProb, 0, 100);
200+
201+
// Apply a sanity clamp to prevent being thrown through objects.
202+
var maxSafeForceForObject = SpaceWindMaxVelocity * physics.Mass;
203+
moveForce = MathF.Min(moveForce, maxSafeForceForObject);
204+
205+
// Grid-rotation adjusted direction
206+
var dirVec = (direction.ToAngle() + gridWorldRotation).ToWorldVec();
207+
191208
// TODO: Technically these directions won't be correct but uhh I'm just here for optimisations buddy not to fix my old bugs.
192209
if (throwTarget != EntityCoordinates.Invalid)
193210
{
194-
var moveForce = maxForce * MathHelper.Clamp(moveProb, 0, 100) / 15f;
195-
var pos = ((throwTarget.Position - xform.Coordinates.Position).Normalized + direction.ToDirection().ToVec()).Normalized;
211+
var pos = ((throwTarget.ToMap(EntityManager).Position - xform.WorldPosition).Normalized + dirVec).Normalized;
196212
physics.ApplyLinearImpulse(pos * moveForce);
197213
}
198214

199215
else
200216
{
201-
var moveForce = MathF.Min(maxForce * MathHelper.Clamp(moveProb, 0, 100) / 2500f, 20f);
202-
physics.ApplyLinearImpulse(direction.ToDirection().ToVec() * moveForce);
217+
moveForce = MathF.Min(moveForce, SpaceWindMaxPushForce);
218+
physics.ApplyLinearImpulse(dirVec * moveForce);
203219
}
204220

205221
component.LastHighPressureMovementAirCycle = cycle;

‎Content.Shared/CCVar/CCVars.cs

+26
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,32 @@ public static readonly CVarDef<bool>
544544
public static readonly CVarDef<bool> SpaceWind =
545545
CVarDef.Create("atmos.space_wind", true, CVar.SERVERONLY);
546546

547+
/// <summary>
548+
/// Divisor from maxForce (pressureDifference * 2.25f) to force applied on objects.
549+
/// </summary>
550+
public static readonly CVarDef<float> SpaceWindPressureForceDivisorThrow =
551+
CVarDef.Create("atmos.space_wind_pressure_force_divisor_throw", 15f, CVar.SERVERONLY);
552+
553+
/// <summary>
554+
/// Divisor from maxForce (pressureDifference * 2.25f) to force applied on objects.
555+
/// </summary>
556+
public static readonly CVarDef<float> SpaceWindPressureForceDivisorPush =
557+
CVarDef.Create("atmos.space_wind_pressure_force_divisor_push", 2500f, CVar.SERVERONLY);
558+
559+
/// <summary>
560+
/// The maximum velocity (not force) that may be applied to an object by atmospheric pressure differences.
561+
/// Useful to prevent clipping through objects.
562+
/// </summary>
563+
public static readonly CVarDef<float> SpaceWindMaxVelocity =
564+
CVarDef.Create("atmos.space_wind_max_velocity", 30f, CVar.SERVERONLY);
565+
566+
/// <summary>
567+
/// The maximum force that may be applied to an object by pushing (i.e. not throwing) atmospheric pressure differences.
568+
/// A "throwing" atmospheric pressure difference ignores this limit, but not the max. velocity limit.
569+
/// </summary>
570+
public static readonly CVarDef<float> SpaceWindMaxPushForce =
571+
CVarDef.Create("atmos.space_wind_max_push_force", 20f, CVar.SERVERONLY);
572+
547573
/// <summary>
548574
/// Whether monstermos tile equalization is enabled.
549575
/// </summary>

0 commit comments

Comments
 (0)
Please sign in to comment.