Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4212fbb
Physics based air throws
VMSolidus Apr 29, 2024
bddb87b
Update base_structureclosets.yml
VMSolidus Apr 29, 2024
162c284
Updates for review
VMSolidus Apr 29, 2024
3374757
Hello, this is an asymptote. Divide by zero must be an exit condition.
VMSolidus Apr 29, 2024
3dc71fb
Adding the clamp back in
VMSolidus Apr 29, 2024
b3c503c
I found another small optimization
VMSolidus May 1, 2024
68e0510
Another one
VMSolidus May 1, 2024
9e7aa5d
New Cvar
VMSolidus May 4, 2024
3d03262
Update comments for documentation
VMSolidus May 4, 2024
67fdaff
Apply suggestions from code review
VMSolidus May 6, 2024
6cc4704
MORE
VMSolidus May 16, 2024
54ca8ce
Update AtmosphereSystem.HighPressureDelta.cs
VMSolidus May 16, 2024
7500efd
guh, last push
VMSolidus May 16, 2024
3440636
Merge branch 'Simple-Station:master' into Atmos-optimization-test
VMSolidus May 16, 2024
7470ba7
Fix for objects getting stuck on walls, new CVar for more expensive a…
VMSolidus May 16, 2024
b328725
Update animals.yml
VMSolidus May 16, 2024
f7e2f70
Fix tiny mobs boiling themselves to death
VMSolidus May 16, 2024
53d221f
Merge branch 'master' into Atmos-optimization-test
VMSolidus May 29, 2024
eba2d1d
Merge branch 'master' into Atmos-optimization-test
VMSolidus May 29, 2024
7c1ba29
Merge branch 'master' into Atmos-optimization-test
VMSolidus Jun 11, 2024
9d81e24
Initial Beta for Rip Tile Rework
VMSolidus Jun 12, 2024
70a9345
Tentative fixes for wall quantum tunneling
VMSolidus Jun 12, 2024
4d1cf7d
More fixes
VMSolidus Jun 12, 2024
c9286a5
Update CCVars.cs
VMSolidus Jun 12, 2024
9c00871
Update CCVars.cs
VMSolidus Jun 12, 2024
adf3745
Apply suggestions from code review
VMSolidus Jun 16, 2024
351c4ec
Add System for making Humanoids get thrown harder
VMSolidus Jun 25, 2024
9b544bf
Update CCVars.cs
VMSolidus Jun 25, 2024
c9eadac
1984 move by pressure, reroute to ThrowingSystem because its more adv…
VMSolidus Jun 25, 2024
bc25b78
This is significantly smoother
VMSolidus Jun 25, 2024
c5946ee
Update AtmosphereSystem.HighPressureDelta.cs
VMSolidus Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public sealed partial class AtmosphereSystem
public float SpaceWindPressureForceDivisorPush { get; private set; }
public float SpaceWindMaxVelocity { get; private set; }
public float SpaceWindMaxPushForce { get; private set; }
public float SpaceWindMinimumMassThreshold { get; private set; }
public bool MonstermosEqualization { get; private set; }
public bool MonstermosDepressurization { get; private set; }
public bool MonstermosRipTiles { get; private set; }
Expand Down Expand Up @@ -41,6 +42,7 @@ private void InitializeCVars()
Subs.CVar(_cfg, CCVars.SpaceWindPressureForceDivisorPush, value => SpaceWindPressureForceDivisorPush = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMaxVelocity, value => SpaceWindMaxVelocity = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMaxPushForce, value => SpaceWindMaxPushForce = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMinimumMassThreshold, value => SpaceWindMinimumMassThreshold = value, true);
Subs.CVar(_cfg, CCVars.MonstermosEqualization, value => MonstermosEqualization = value, true);
Subs.CVar(_cfg, CCVars.MonstermosDepressurization, value => MonstermosDepressurization = value, true);
Subs.CVar(_cfg, CCVars.MonstermosRipTiles, value => MonstermosRipTiles = value, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using Content.Server.Atmos.Components;
using Content.Shared.Atmos;
using Content.Shared.Audio;
using Content.Shared.Mobs.Components;
using Content.Shared.Physics;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Utility;

namespace Content.Server.Atmos.EntitySystems
Expand Down Expand Up @@ -51,8 +48,7 @@ private void UpdateHighPressure(float frameTime)
comp.Accumulator = 0f;
toRemove.Add(ent);

if (HasComp<MobStateComponent>(uid) &&
TryComp<PhysicsComponent>(uid, out var body))
if (TryComp<PhysicsComponent>(uid, out var body))
{
_physics.SetBodyStatus(body, BodyStatus.OnGround);
}
Expand All @@ -72,7 +68,7 @@ private void UpdateHighPressure(float frameTime)
}
}

private void AddMobMovedByPressure(EntityUid uid, MovedByPressureComponent component, PhysicsComponent body)
private void AddMovedByPressure(EntityUid uid, MovedByPressureComponent component, PhysicsComponent body)
{
if (!TryComp<FixturesComponent>(uid, out var fixtures))
return;
Expand Down Expand Up @@ -162,7 +158,7 @@ private void HighPressureMovements(Entity<GridAtmosphereComponent> gridAtmospher
(entity, pressureMovements),
gridAtmosphere.Comp.UpdateCounter,
tile.PressureDifference,
tile.PressureDirection, 0,
tile.PressureDirection,
tile.PressureSpecificTarget != null ? _mapSystem.ToCenterCoordinates(tile.GridIndex, tile.PressureSpecificTarget.GridIndices) : EntityCoordinates.Invalid,
gridWorldRotation,
xforms.GetComponent(entity),
Expand All @@ -183,12 +179,13 @@ private void ConsiderPressureDifference(GridAtmosphereComponent gridAtmosphere,
tile.PressureDirection = differenceDirection;
}

//The EE version of this function drops pressureResistanceProbDelta, since it's not needed. If you are for whatever reason calling this function
//And it isn't working, you've probably still got the pressureResistanceProbDelta line included.
public void ExperiencePressureDifference(
Entity<MovedByPressureComponent> ent,
int cycle,
float pressureDifference,
AtmosDirection direction,
float pressureResistanceProbDelta,
EntityCoordinates throwTarget,
Angle gridWorldRotation,
TransformComponent? xform = null,
Expand All @@ -201,50 +198,40 @@ public void ExperiencePressureDifference(
if (!Resolve(uid, ref xform))
return;

// TODO ATMOS stuns?

var maxForce = MathF.Sqrt(pressureDifference) * 2.25f;
var moveProb = 100f;

if (component.PressureResistance > 0)
moveProb = MathF.Abs((pressureDifference / component.PressureResistance * MovedByPressureComponent.ProbabilityBasePercent) -
MovedByPressureComponent.ProbabilityOffset);

// Can we yeet the thing (due to probability, strength, etc.)
if (moveProb > MovedByPressureComponent.ProbabilityOffset && _robustRandom.Prob(MathF.Min(moveProb / 100f, 1f))
&& !float.IsPositiveInfinity(component.MoveResist)
&& (physics.BodyType != BodyType.Static
&& (maxForce >= (component.MoveResist * MovedByPressureComponent.MoveForcePushRatio)))
|| (physics.BodyType == BodyType.Static && (maxForce >= (component.MoveResist * MovedByPressureComponent.MoveForceForcePushRatio))))
// EXPLANATION:
// pressureDifference = Force of Air Flow on a given tile
// physics.Mass = Mass of the object potentially being thrown
// physics.InvMass = 1 divided by said Mass. More CPU efficient way to do division.
//
// Objects can only be thrown if the force of air flow is greater than the SQUARE of their mass or {SpaceWindMinimumMassThreshold}, whichever is heavier
// This means that the heavier an object is, the exponentially more force is required to move it
// The force of a throw is equal to the force of air pressure, divided by an object's mass. So not only are heavier objects
// less likely to be thrown, they are also harder to throw,
// while lighter objects are yeeted easily, and from great distance.
//
// For a human sized entity with a standard weight of 80kg and a spacing between a hard vacuum and a room pressurized at 101kpa,
// The human shall only be moved if he is either very close to the hole, or is standing in a region of high airflow
if (physics.BodyType != BodyType.Static
&& !float.IsPositiveInfinity(component.MoveResist))
{
if (HasComp<MobStateComponent>(uid))
{
AddMobMovedByPressure(uid, component, physics);
}
var moveForce = pressureDifference * physics.InvMass;

if (maxForce > MovedByPressureComponent.ThrowForce)
if (moveForce > MathF.MaxMagnitude(physics.Mass, SpaceWindMinimumMassThreshold))
{
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);

AddMovedByPressure(uid, component, physics);
// Grid-rotation adjusted direction
var dirVec = (direction.ToAngle() + gridWorldRotation).ToWorldVec();
var maxSafeForceForObject = SpaceWindMaxVelocity * physics.Mass;

// TODO: Technically these directions won't be correct but uhh I'm just here for optimisations buddy not to fix my old bugs.
// TODO: Consider replacing throw target with proper trigonometry angles.
if (throwTarget != EntityCoordinates.Invalid)
{
var pos = ((throwTarget.ToMap(EntityManager).Position - xform.WorldPosition).Normalized() + dirVec).Normalized();
_physics.ApplyLinearImpulse(uid, pos * moveForce, body: physics);
_physics.ApplyLinearImpulse(uid, pos * Math.Clamp(moveForce, 0, maxSafeForceForObject), body: physics);
}
else
{
moveForce = MathF.Min(moveForce, SpaceWindMaxPushForce);
_physics.ApplyLinearImpulse(uid, dirVec * moveForce, body: physics);
_physics.ApplyLinearImpulse(uid, dirVec * Math.Clamp(moveForce, 0, maxSafeForceForObject), body: physics);
}

component.LastHighPressureMovementAirCycle = cycle;
Expand Down
11 changes: 11 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,17 @@ public static readonly CVarDef<bool>
public static readonly CVarDef<float> SpaceWindMaxPushForce =
CVarDef.Create("atmos.space_wind_max_push_force", 20f, CVar.SERVERONLY);

/// <summary>
/// If an object's mass is below this number, then this number is used in place of mass to determine whether air pressure can throw an object.
/// This has nothing to do with throwing force, only acting as a way of reducing the odds of tiny 5 gram objects from being yeeted by people's breath
/// </summary>
/// <remarks>
/// If you are reading this because you want to change it, consider looking into why almost every item in the game weighs only 5 grams
/// And maybe do your part to fix that? :)
/// </remarks>
public static readonly CVarDef<float> SpaceWindMinimumMassThreshold =
CVarDef.Create("atmos.space_wind_minimum_mass_threshold", 10f, CVar.SERVERONLY);

/// <summary>
/// Whether monstermos tile equalization is enabled.
/// </summary>
Expand Down