]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow thermomachines to exchange with air instead of inlet (#25247)
authorMenshin <Menshin@users.noreply.github.com>
Thu, 15 Feb 2024 01:00:21 +0000 (02:00 +0100)
committerGitHub <noreply@github.com>
Thu, 15 Feb 2024 01:00:21 +0000 (17:00 -0800)
Add purely atmospheric heat exchange to the gas thermomachine component (in preparation for space heaters).

Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs
Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs

index 93d973d12310966f2468b1895b7e4bbcaef43608..5da4ec9fdf2330e235de0edd27b7ad1cce740280 100644 (file)
@@ -64,5 +64,11 @@ namespace Content.Server.Atmos.Piping.Unary.Components
         /// </summary>
         [DataField, ViewVariables(VVAccess.ReadWrite)]
         public float EnergyLeakPercentage;
+
+        /// <summary>
+        /// If true, heat is exclusively exchanged with the local atmosphere instead of the inlet pipe air
+        /// </summary>
+        [DataField, ViewVariables(VVAccess.ReadWrite)]
+        public bool Atmospheric = false;
     }
 }
index 645b2ecc459dcf6f3c8057ead6dc651a50591811..2900082623221315e2d6d80399df3e1842262242 100644 (file)
@@ -55,17 +55,17 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
 
         private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, ref AtmosDeviceUpdateEvent args)
         {
-            if (!(_power.IsPowered(uid) && TryComp<ApcPowerReceiverComponent>(uid, out var receiver))
-                || !TryComp<NodeContainerComponent>(uid, out var nodeContainer)
-                || !_nodeContainer.TryGetNode(nodeContainer, thermoMachine.InletName, out PipeNode? inlet))
-            {
+            if (!(_power.IsPowered(uid) && TryComp<ApcPowerReceiverComponent>(uid, out var receiver)))
+                return;
+
+            GetHeatExchangeGasMixture(uid, thermoMachine, out var heatExchangeGasMixture);
+            if (heatExchangeGasMixture == null)
                 return;
-            }
 
             float sign = Math.Sign(thermoMachine.Cp); // 1 if heater, -1 if freezer
             float targetTemp = thermoMachine.TargetTemperature;
             float highTemp = targetTemp + sign * thermoMachine.TemperatureTolerance;
-            float temp = inlet.Air.Temperature;
+            float temp = heatExchangeGasMixture.Temperature;
 
             if (sign * temp >= sign * highTemp) // upper bound
                 thermoMachine.HysteresisState = false; // turn off
@@ -74,8 +74,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
 
             if (thermoMachine.HysteresisState)
                 targetTemp = highTemp; // when on, target upper hysteresis bound
-
-            if (!thermoMachine.HysteresisState) // Hysteresis is the same as "Should this be on?"
+            else // Hysteresis is the same as "Should this be on?"
             {
                 // Turn dynamic load back on when power has been adjusted to not cause lights to
                 // blink every time this heater comes on.
@@ -87,7 +86,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, true);
+            float Cin = _atmosphereSystem.GetHeatCapacity(heatExchangeGasMixture, true);
             float dT = targetTemp - temp;
             float dQLim = dT * Cin;
             float scale = 1f;
@@ -96,17 +95,45 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
                 scale = dQLim / dQ; // reduce power consumption
                 thermoMachine.HysteresisState = false; // turn off
             }
+
             float dQActual = dQ * scale;
-            float dQLeak = dQActual * thermoMachine.EnergyLeakPercentage;
-            float dQPipe = dQActual - dQLeak;
-            _atmosphereSystem.AddHeat(inlet.Air, dQPipe);
+            if (thermoMachine.Atmospheric)
+            {
+                _atmosphereSystem.AddHeat(heatExchangeGasMixture, dQActual);
+            }
+            else
+            {
+                float dQLeak = dQActual * thermoMachine.EnergyLeakPercentage;
+                float dQPipe = dQActual - dQLeak;
+                _atmosphereSystem.AddHeat(heatExchangeGasMixture, dQPipe);
 
-            if (_atmosphereSystem.GetContainingMixture(uid) is { } containingMixture)
-                _atmosphereSystem.AddHeat(containingMixture, dQLeak);
+                if (dQLeak != 0f && _atmosphereSystem.GetContainingMixture(uid) is { } containingMixture)
+                    _atmosphereSystem.AddHeat(containingMixture, dQLeak);
+            }
 
             receiver.Load = thermoMachine.HeatCapacity;// * scale; // we're not ready for dynamic load yet, see note above
         }
 
+        /// <summary>
+        /// Returns the gas mixture with which the thermomachine will exchange heat (the local atmosphere if atmospheric or the inlet pipe
+        /// air if not). Returns null if no gas mixture is found.
+        /// </summary>
+        private void GetHeatExchangeGasMixture(EntityUid uid, GasThermoMachineComponent thermoMachine, out GasMixture? heatExchangeGasMixture)
+        {
+            heatExchangeGasMixture = null;
+            if (thermoMachine.Atmospheric)
+            {
+                heatExchangeGasMixture = _atmosphereSystem.GetContainingMixture(uid);
+            }
+            else
+            {
+                if (!TryComp<NodeContainerComponent>(uid, out var nodeContainer)
+                    || !_nodeContainer.TryGetNode(nodeContainer, thermoMachine.InletName, out PipeNode? inlet))
+                    return;
+                heatExchangeGasMixture = inlet.Air;
+            }
+        }
+
         private bool IsHeater(GasThermoMachineComponent comp)
         {
             return comp.Cp >= 0;