]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix barotrauma calculations
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Sun, 17 Mar 2024 21:37:28 +0000 (22:37 +0100)
committerPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Sun, 17 Mar 2024 21:37:28 +0000 (22:37 +0100)
The math for our pressure damage (barotrauma) system is directly taken from TG. The constants are the same and the math is almost the same. However there are two errors.

1. Pressure damage started being applied within the WARNING bounds, rather than the HAZARD bounds. This means you started taking low pressure damage at 50 kPa instead of the intended 20 kPa, and also the HUD icon didn't show "danger" like it should even if you were already taking damage.

2. The calculations for high pressure damage were wrong. These are supposed to be linearly scaled, but the function was wrong so the scaling didn't actually work properly (especially when considering the fixed bounds above). This appears to be the case because the function was taken from an incorrect comment in the original source, rather than the real math.

Both of these issues are now fixed to match the TG behavior. Note that this somewhat nerfs pressure damage in non-extreme circumstances. e.g. a room at 40 kPa now gives NO pressure damage, whereas previously it would do full space damage.

The description of the pressure alerts is wrong for "low" severity, but I can't be arsed to fix that right now. Alerts don't have a way to change the description depending on severity...

Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs
Content.Shared/Atmos/Atmospherics.cs

index 023ac287634bcfa8f55c646f77dee85a469c43e3..2b1d6b526b23479f7393c71b6fd54fbfd10551ca 100644 (file)
@@ -224,69 +224,64 @@ namespace Content.Server.Atmos.EntitySystems
                     pressure = MathF.Max(mixture.Pressure, 1f);
                 }
 
-                switch (pressure)
+                pressure = pressure switch
                 {
-                    // Low pressure.
-                    case <= Atmospherics.WarningLowPressure:
-                        pressure = GetFeltLowPressure(uid, barotrauma, pressure);
+                    // Adjust pressure based on equipment. Works differently depending on if it's "high" or "low".
+                    <= Atmospherics.WarningLowPressure => GetFeltLowPressure(uid, barotrauma, pressure),
+                    >= Atmospherics.WarningHighPressure => GetFeltHighPressure(uid, barotrauma, pressure),
+                    _ => pressure
+                };
 
-                        if (pressure > Atmospherics.WarningLowPressure)
-                            goto default;
-
-                        // Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
-                        _damageableSystem.TryChangeDamage(uid, barotrauma.Damage * Atmospherics.LowPressureDamage, true, false);
-
-                        if (!barotrauma.TakingDamage)
-                        {
-                            barotrauma.TakingDamage = true;
-                            _adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} started taking low pressure damage");
-                        }
-
-                        if (pressure <= Atmospherics.HazardLowPressure)
-                        {
-                            _alertsSystem.ShowAlert(uid, AlertType.LowPressure, 2);
-                            break;
-                        }
-
-                        _alertsSystem.ShowAlert(uid, AlertType.LowPressure, 1);
-                        break;
+                if (pressure <= Atmospherics.HazardLowPressure)
+                {
+                    // Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
+                    _damageableSystem.TryChangeDamage(uid, barotrauma.Damage * Atmospherics.LowPressureDamage, true, false);
 
-                    // High pressure.
-                    case >= Atmospherics.WarningHighPressure:
-                        pressure = GetFeltHighPressure(uid, barotrauma, pressure);
+                    if (!barotrauma.TakingDamage)
+                    {
+                        barotrauma.TakingDamage = true;
+                        _adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} started taking low pressure damage");
+                    }
 
-                        if (pressure < Atmospherics.WarningHighPressure)
-                            goto default;
+                    _alertsSystem.ShowAlert(uid, AlertType.LowPressure, 2);
+                }
+                else if (pressure >= Atmospherics.HazardHighPressure)
+                {
+                    var damageScale = MathF.Min(((pressure / Atmospherics.HazardHighPressure) - 1) * Atmospherics.PressureDamageCoefficient, Atmospherics.MaxHighPressureDamage);
 
-                        var damageScale = MathF.Min((pressure / Atmospherics.HazardHighPressure) * Atmospherics.PressureDamageCoefficient, Atmospherics.MaxHighPressureDamage);
+                    // Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
+                    _damageableSystem.TryChangeDamage(uid, barotrauma.Damage * damageScale, true, false);
 
-                        // Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
-                        _damageableSystem.TryChangeDamage(uid, barotrauma.Damage * damageScale, true, false);
+                    if (!barotrauma.TakingDamage)
+                    {
+                        barotrauma.TakingDamage = true;
+                        _adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} started taking high pressure damage");
+                    }
 
-                        if (!barotrauma.TakingDamage)
-                        {
-                            barotrauma.TakingDamage = true;
-                            _adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} started taking high pressure damage");
-                        }
+                    _alertsSystem.ShowAlert(uid, AlertType.HighPressure, 2);
+                }
+                else
+                {
+                    // Within safe pressure limits
+                    if (barotrauma.TakingDamage)
+                    {
+                        barotrauma.TakingDamage = false;
+                        _adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} stopped taking pressure damage");
+                    }
 
-                        if (pressure >= Atmospherics.HazardHighPressure)
-                        {
-                            _alertsSystem.ShowAlert(uid, AlertType.HighPressure, 2);
+                    // Set correct alert.
+                    switch (pressure)
+                    {
+                        case <= Atmospherics.WarningLowPressure:
+                            _alertsSystem.ShowAlert(uid, AlertType.LowPressure, 1);
                             break;
-                        }
-
-                        _alertsSystem.ShowAlert(uid, AlertType.HighPressure, 1);
-                        break;
-
-                    // Normal pressure.
-                    default:
-                        if (barotrauma.TakingDamage)
-                        {
-                            barotrauma.TakingDamage = false;
-                            _adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} stopped taking pressure damage");
-                        }
-                        _alertsSystem.ClearAlertCategory(uid, AlertCategory.Pressure);
-                        break;
+                        case >= Atmospherics.WarningHighPressure:
+                            _alertsSystem.ShowAlert(uid, AlertType.HighPressure, 1);
+                            break;
+                        default:
+                            _alertsSystem.ClearAlertCategory(uid, AlertCategory.Pressure);
+                            break;
+                    }
                 }
             }
         }
index 7460e08e46ff07633c93b66e4d79c22a4bcdcab7..c56edd205b72fb75aee6ac1d7575151af15b7b35 100644 (file)
@@ -276,7 +276,7 @@ namespace Content.Shared.Atmos
         public const float HazardLowPressure = 20f;
 
         /// <summary>
-        ///    The amount of pressure damage someone takes is equal to (pressure / HAZARD_HIGH_PRESSURE)*PRESSURE_DAMAGE_COEFFICIENT,
+        ///    The amount of pressure damage someone takes is equal to ((pressure / HAZARD_HIGH_PRESSURE) - 1)*PRESSURE_DAMAGE_COEFFICIENT,
         ///     with the maximum of MaxHighPressureDamage.
         /// </summary>
         public const float PressureDamageCoefficient = 4;