]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Atmos scaling cvar changes (#22501)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Fri, 15 Dec 2023 22:02:21 +0000 (17:02 -0500)
committerGitHub <noreply@github.com>
Fri, 15 Dec 2023 22:02:21 +0000 (14:02 -0800)
16 files changed:
Content.Server/Atmos/EntitySystems/AtmosphereSystem.Gases.cs
Content.Server/Atmos/EntitySystems/AtmosphereSystem.GridAtmosphere.cs
Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs
Content.Server/Atmos/EntitySystems/HeatExchangerSystem.cs
Content.Server/Atmos/IGasReactionEffect.cs
Content.Server/Atmos/Piping/Unary/EntitySystems/GasCondenserSystem.cs
Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs
Content.Server/Atmos/Reactions/FrezonCoolantReaction.cs
Content.Server/Atmos/Reactions/FrezonProductionReaction.cs
Content.Server/Atmos/Reactions/GasReactionPrototype.cs
Content.Server/Atmos/Reactions/MiasmicSubsumationReaction.cs
Content.Server/Atmos/Reactions/PlasmaFireReaction.cs
Content.Server/Atmos/Reactions/TritiumFireReaction.cs
Content.Server/Atmos/Reactions/WaterVaporReaction.cs
Content.Server/Power/Generation/Teg/TegSystem.cs
Content.Server/Temperature/Systems/TemperatureSystem.cs

index 6a631858113bdcb8f87b8f0d4e3d9baecba0d998..4c3437e431e6e836a465305e25a214fe009dc1f8 100644 (file)
@@ -43,11 +43,22 @@ namespace Content.Server.Atmos.EntitySystems
         /// <summary>
         ///     Calculates the heat capacity for a gas mixture.
         /// </summary>
-        public float GetHeatCapacity(GasMixture mixture)
+        /// <param name="mixture">The mixture whose heat capacity should be calculated</param>
+        /// <param name="applyScaling"> Whether the internal heat capacity scaling should be applied. This should not be
+        /// used outside of atmospheric related heat transfer.</param>
+        /// <returns></returns>
+        public float GetHeatCapacity(GasMixture mixture, bool applyScaling)
         {
-            return GetHeatCapacityCalculation(mixture.Moles, mixture.Immutable);
+            var scale = GetHeatCapacityCalculation(mixture.Moles, mixture.Immutable);
+
+            // By default GetHeatCapacityCalculation() has the heat-scale divisor pre-applied.
+            // So if we want the un-scaled heat capacity, we have to multiply by the scale.
+            return applyScaling ? scale : scale * HeatScale;
         }
 
+        private float GetHeatCapacity(GasMixture mixture)
+            =>  GetHeatCapacityCalculation(mixture.Moles, mixture.Immutable);
+
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         private float GetHeatCapacityCalculation(float[] moles, bool space)
         {
@@ -320,7 +331,9 @@ namespace Content.Server.Atmos.EntitySystems
 
                     var req = prototype.MinimumRequirements[i];
 
-                    if (!(mixture.GetMoles(i) < req)) continue;
+                    if (!(mixture.GetMoles(i) < req))
+                        continue;
+
                     doReaction = false;
                     break;
                 }
@@ -328,7 +341,7 @@ namespace Content.Server.Atmos.EntitySystems
                 if (!doReaction)
                     continue;
 
-                reaction = prototype.React(mixture, holder, this);
+                reaction = prototype.React(mixture, holder, this, HeatScale);
                 if(reaction.HasFlag(ReactionResult.StopReactions))
                     break;
             }
index 036b64cad944b1e296f944c5fc2d9ebe97dce454..3eb38296f6a0aba3e8dd3e4ac343e560a355675c 100644 (file)
@@ -3,6 +3,7 @@ using Content.Server.Atmos.Components;
 using Content.Server.Atmos.Reactions;
 using Content.Shared.Atmos;
 using Content.Shared.Atmos.Components;
+using Robust.Shared.Map;
 using Robust.Shared.Map.Components;
 using Robust.Shared.Utility;
 
@@ -558,4 +559,12 @@ public sealed partial class AtmosphereSystem
             InvalidateVisuals(uid, position, overlay);
         }
     }
+
+    public TileRef GetTileRef(TileAtmosphere tile)
+    {
+        if (!TryComp(tile.GridIndex, out MapGridComponent? grid))
+            return default;
+        _map.TryGetTileRef(tile.GridIndex, grid, tile.GridIndices, out var tileRef);
+        return tileRef;
+    }
 }
index 19855a71e56439fea29207fb64a4ff2aa91aa19c..07efdb4f679c741230b1decb0f828adefd90e560 100644 (file)
@@ -1,13 +1,12 @@
 using Content.Server.Administration.Logs;
 using Content.Server.Atmos.Components;
 using Content.Server.Body.Systems;
-using Content.Server.Maps;
+using Content.Server.Fluids.EntitySystems;
 using Content.Server.NodeContainer.EntitySystems;
 using Content.Shared.Atmos.EntitySystems;
 using Content.Shared.Maps;
 using JetBrains.Annotations;
 using Robust.Server.GameObjects;
-using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
 using Robust.Shared.Map;
@@ -33,6 +32,8 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
     [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly TransformSystem _transformSystem = default!;
     [Dependency] private readonly TileSystem _tile = default!;
+    [Dependency] private readonly MapSystem _map = default!;
+    [Dependency] public readonly PuddleSystem Puddle = default!;
 
     private const float ExposedUpdateDelay = 1f;
     private float _exposedTimer = 0f;
@@ -80,7 +81,7 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
             return;
 
         var query = EntityQueryEnumerator<AtmosExposedComponent, TransformComponent>();
-        while (query.MoveNext(out var uid, out var exposed, out var transform))
+        while (query.MoveNext(out var uid, out _, out var transform))
         {
             var air = GetContainingMixture(uid, transform:transform);
 
index e8a7b089c679a90353ab2decb7355fdc2ba629ba..2541d98a7efbae97adf605431791bcb97a2fdafa 100644 (file)
@@ -83,7 +83,7 @@ public sealed class HeatExchangerSystem : EntitySystem
         else
             xfer = outlet.Air.Remove(-n);
 
-        float CXfer = _atmosphereSystem.GetHeatCapacity(xfer);
+        float CXfer = _atmosphereSystem.GetHeatCapacity(xfer, true);
         if (CXfer < Atmospherics.MinimumHeatCapacity)
             return;
 
@@ -94,7 +94,7 @@ public sealed class HeatExchangerSystem : EntitySystem
         float CEnv = 0f;
         if (environment != null)
         {
-            CEnv = _atmosphereSystem.GetHeatCapacity(environment);
+            CEnv = _atmosphereSystem.GetHeatCapacity(environment, true);
             hasEnv = CEnv >= Atmospherics.MinimumHeatCapacity && environment.TotalMoles > 0f;
             if (hasEnv)
                 radTemp = environment.Temperature;
index acaef2a0719cba81d0a1f239951634bdc6feb24e..bd229694bb177841294030272dc8204aa779be2b 100644 (file)
@@ -6,6 +6,14 @@ namespace Content.Server.Atmos
     [ImplicitDataDefinitionForInheritors]
     public partial interface IGasReactionEffect
     {
-        ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem);
+        /// <summary>
+        /// Process this reaction effect.
+        /// </summary>
+        /// <param name="mixture">The gas mixture to react</param>
+        /// <param name="holder">The container of this gas mixture</param>
+        /// <param name="atmosphereSystem">The atmosphere system</param>
+        /// <param name="heatScale">Scaling factor that should be applied to all heat input or outputs.</param>
+        ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem,
+            float heatScale);
     }
 }
index 1b790b5cf0013e692ddc0494d4602f3a9661fe50..8df1bb53658a26361141b900d5ddcf006d7e7746 100644 (file)
@@ -64,7 +64,7 @@ public sealed class GasCondenserSystem : EntitySystem
 
     public float NumberOfMolesToConvert(ApcPowerReceiverComponent comp, GasMixture mix, float dt)
     {
-        var hc = _atmosphereSystem.GetHeatCapacity(mix);
+        var hc = _atmosphereSystem.GetHeatCapacity(mix, true);
         var alpha = 0.8f; // tuned to give us 1-ish u/second of reagent conversion
         // ignores the energy needed to cool down the solution to the condensation point, but that probably adds too much difficulty and so let's not simulate that
         var energy = comp.Load * dt;
index 7f5f58fe4b78d43b2c4c283caf46090087d59adf..4140eb2a93f29d27e633adf0145a60d1400d1bc6 100644 (file)
@@ -80,7 +80,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
             float dQ = thermoMachine.HeatCapacity * thermoMachine.Cp * args.dt;
 
             // Clamps the heat transferred to not overshoot
-            float Cin = _atmosphereSystem.GetHeatCapacity(inlet.Air);
+            float Cin = _atmosphereSystem.GetHeatCapacity(inlet.Air, true);
             float dT = targetTemp - temp;
             float dQLim = dT * Cin;
             float scale = 1f;
index ddbd8a772b78083d19f4c5d42fb32cd5d40863e7..051ee8202db2fceb52eb03b0d81c2ff1f98c5efa 100644 (file)
@@ -10,9 +10,9 @@ namespace Content.Server.Atmos.Reactions;
 [UsedImplicitly]
 public sealed partial class FrezonCoolantReaction : IGasReactionEffect
 {
-    public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
+    public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
     {
-        var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
+        var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
         var temperature = mixture.Temperature;
 
         var energyModifier = 1f;
@@ -45,11 +45,11 @@ public sealed partial class FrezonCoolantReaction : IGasReactionEffect
             energyReleased = burnRate * Atmospherics.FrezonCoolEnergyReleased * energyModifier;
         }
 
-        energyReleased /= atmosphereSystem.HeatScale; // adjust energy to make sure speedup doesn't cause mega temperature rise
+        energyReleased /= heatScale; // adjust energy to make sure speedup doesn't cause mega temperature rise
         if (energyReleased >= 0f)
             return ReactionResult.NoReaction;
 
-        var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
+        var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
         if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
             mixture.Temperature = (temperature * oldHeatCapacity + energyReleased) / newHeatCapacity;
 
index 084d939e4e0ad9ceacb40cc8450dd3cb0c9a6be2..4ffd9c2f5b3e9a690ada0482d39950e13f812878 100644 (file)
@@ -11,7 +11,7 @@ namespace Content.Server.Atmos.Reactions;
 [UsedImplicitly]
 public sealed partial class FrezonProductionReaction : IGasReactionEffect
 {
-    public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
+    public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
     {
         var initialN2 = mixture.GetMoles(Gas.Nitrogen);
         var initialOxy = mixture.GetMoles(Gas.Oxygen);
@@ -28,7 +28,6 @@ public sealed partial class FrezonProductionReaction : IGasReactionEffect
         // Amount of tritium & oxygen that are reacting
         var tritBurned = Math.Min(oxyLimit, initialTrit);
         var oxyBurned = tritBurned * Atmospherics.FrezonProductionTritRatio;
-        var burnRatio = tritBurned / initialTrit;
 
         var oxyConversion = oxyBurned / Atmospherics.FrezonProductionConversionRate;
         var tritConversion = tritBurned / Atmospherics.FrezonProductionConversionRate;
index 30f9b72f8df6085c09162009ba1f45ca00ada92a..0ee29de3bf196fb7178d0496d8c2fdec310f94ef 100644 (file)
@@ -60,13 +60,20 @@ namespace Content.Server.Atmos.Reactions
         /// </summary>
         [DataField("effects")] private List<IGasReactionEffect> _effects = new();
 
-        public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
+        /// <summary>
+        /// Process all reaction effects.
+        /// </summary>
+        /// <param name="mixture">The gas mixture to react</param>
+        /// <param name="holder">The container of this gas mixture</param>
+        /// <param name="atmosphereSystem">The atmosphere system</param>
+        /// <param name="heatScale">Scaling factor that should be applied to all heat input or outputs.</param>
+        public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
         {
             var result = ReactionResult.NoReaction;
 
             foreach (var effect in _effects)
             {
-                result |= effect.React(mixture, holder, atmosphereSystem);
+                result |= effect.React(mixture, holder, atmosphereSystem, heatScale);
             }
 
             return result;
index b7dd5b7eb89ec6541db51473232ae8e3765840b1..f9e8cbdf776af5e13be09868cac6853b59ca05b1 100644 (file)
@@ -10,7 +10,7 @@ namespace Content.Server.Atmos.Reactions;
 [UsedImplicitly]
 public sealed partial class MiasmicSubsumationReaction : IGasReactionEffect
 {
-    public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
+    public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
     {
         var initialMiasma = mixture.GetMoles(Gas.Miasma);
         var initialFrezon = mixture.GetMoles(Gas.Frezon);
index 22a8772e6826bdb45e61dc06eec1ddc74c87f9b4..9adda3089ccbf1651147b9558fa52bc037265320 100644 (file)
@@ -8,10 +8,10 @@ namespace Content.Server.Atmos.Reactions
     [DataDefinition]
     public sealed partial class PlasmaFireReaction : IGasReactionEffect
     {
-        public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
+        public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
         {
             var energyReleased = 0f;
-            var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
+            var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
             var temperature = mixture.Temperature;
             var location = holder as TileAtmosphere;
             mixture.ReactionResults[GasReaction.Fire] = 0;
@@ -22,8 +22,10 @@ namespace Content.Server.Atmos.Reactions
             if (temperature > Atmospherics.PlasmaUpperTemperature)
                 temperatureScale = 1f;
             else
+            {
                 temperatureScale = (temperature - Atmospherics.PlasmaMinimumBurnTemperature) /
                                    (Atmospherics.PlasmaUpperTemperature - Atmospherics.PlasmaMinimumBurnTemperature);
+            }
 
             if (temperatureScale > 0)
             {
@@ -56,14 +58,14 @@ namespace Content.Server.Atmos.Reactions
                     mixture.AdjustMoles(Gas.CarbonDioxide, plasmaBurnRate * (1.0f - supersaturation));
 
                     energyReleased += Atmospherics.FirePlasmaEnergyReleased * plasmaBurnRate;
-                    energyReleased /= atmosphereSystem.HeatScale; // adjust energy to make sure speedup doesn't cause mega temperature rise
+                    energyReleased /= heatScale; // adjust energy to make sure speedup doesn't cause mega temperature rise
                     mixture.ReactionResults[GasReaction.Fire] += plasmaBurnRate * (1 + oxygenBurnRate);
                 }
             }
 
             if (energyReleased > 0)
             {
-                var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
+                var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
                 if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
                     mixture.Temperature = (temperature * oldHeatCapacity + energyReleased) / newHeatCapacity;
             }
index d1459993bf80d288fb0b3ed0811b0a796aa22cdb..c52b431fd43acf09997eeac276fc20553d240fea 100644 (file)
@@ -8,10 +8,10 @@ namespace Content.Server.Atmos.Reactions
     [DataDefinition]
     public sealed partial class TritiumFireReaction : IGasReactionEffect
     {
-        public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
+        public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
         {
             var energyReleased = 0f;
-            var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
+            var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
             var temperature = mixture.Temperature;
             var location = holder as TileAtmosphere;
             mixture.ReactionResults[GasReaction.Fire] = 0f;
@@ -47,10 +47,10 @@ namespace Content.Server.Atmos.Reactions
                 mixture.ReactionResults[GasReaction.Fire] += burnedFuel;
             }
 
-            energyReleased /= atmosphereSystem.HeatScale; // adjust energy to make sure speedup doesn't cause mega temperature rise
+            energyReleased /= heatScale; // adjust energy to make sure speedup doesn't cause mega temperature rise
             if (energyReleased > 0)
             {
-                var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
+                var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
                 if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
                     mixture.Temperature = ((temperature * oldHeatCapacity + energyReleased) / newHeatCapacity);
             }
index 75eb0291dfac2431a5246c83c91043ce7d512210..8db8fdbd66d135b51e9a1304703f57e0c9370209 100644 (file)
@@ -17,7 +17,7 @@ namespace Content.Server.Atmos.Reactions
 
         [DataField("molesPerUnit")] public float MolesPerUnit { get; private set; } = 1;
 
-        public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
+        public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
         {
             // If any of the prototypes is invalid, we do nothing.
             if (string.IsNullOrEmpty(Reagent))
@@ -34,9 +34,8 @@ namespace Content.Server.Atmos.Reactions
             // Remove the moles from the mixture...
             mixture.AdjustMoles(GasId, -MolesPerUnit);
 
-            var tileRef = tile.GridIndices.GetTileRef(tile.GridIndex);
-            EntitySystem.Get<PuddleSystem>()
-                .TrySpillAt(tileRef, new Solution(Reagent, FixedPoint2.New(MolesPerUnit)), out _, sound: false);
+            var tileRef = atmosphereSystem.GetTileRef(tile);
+            atmosphereSystem.Puddle.TrySpillAt(tileRef, new Solution(Reagent, FixedPoint2.New(MolesPerUnit)), out _, sound: false);
 
             return ReactionResult.Reacting;
         }
index 2be41f7c923d633024f6fa8fb91399c98fe8bad5..1fb844ac5b1c0d255d011f1de9ddc5d83e578615 100644 (file)
@@ -120,8 +120,8 @@ public sealed class TegSystem : EntitySystem
         var (airA, δpA) = GetCirculatorAirTransfer(inletA.Air, outletA.Air);
         var (airB, δpB) = GetCirculatorAirTransfer(inletB.Air, outletB.Air);
 
-        var cA = _atmosphere.GetHeatCapacity(airA);
-        var cB = _atmosphere.GetHeatCapacity(airB);
+        var cA = _atmosphere.GetHeatCapacity(airA, true);
+        var cB = _atmosphere.GetHeatCapacity(airB, true);
 
         // Shift ramp position based on demand and generation from previous tick.
         var curRamp = component.RampPosition;
index 5de609d24bacd4692fc8909856077f94381bc256..2ab9ce74c661a2b076345877502444df228622dd 100644 (file)
@@ -149,13 +149,11 @@ public sealed class TemperatureSystem : EntitySystem
         if (transform.MapUid == null)
             return;
 
-        var position = _transform.GetGridTilePositionOrDefault((uid, transform));
         var temperatureDelta = args.GasMixture.Temperature - temperature.CurrentTemperature;
-        var tileHeatCapacity =
-            _atmosphere.GetTileHeatCapacity(transform.GridUid, transform.MapUid.Value, position);
+        var airHeatCapacity = _atmosphere.GetHeatCapacity(args.GasMixture, false);
         var heatCapacity = GetHeatCapacity(uid, temperature);
-        var heat = temperatureDelta * (tileHeatCapacity * heatCapacity /
-                                       (tileHeatCapacity + heatCapacity));
+        var heat = temperatureDelta * (airHeatCapacity * heatCapacity /
+                                       (airHeatCapacity + heatCapacity));
         ChangeHeat(uid, heat * temperature.AtmosTemperatureTransferEfficiency, temperature: temperature);
     }