]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Clean up gas miners (#29657)
authorMervill <mervills.email@gmail.com>
Tue, 2 Jul 2024 20:18:56 +0000 (13:18 -0700)
committerGitHub <noreply@github.com>
Tue, 2 Jul 2024 20:18:56 +0000 (12:18 -0800)
Separate the environment check from CapSpawnAmount into GetValidEnvironment to make the code a little cleaner, and also makes these two checks independent.

CapSpawnAmount and GetValidEnvironment now both have zero side-effects

Broken renamed Idle to reflect its use. Broken in my mind implies that there's some method for fixing.

---------

Co-authored-by: Partmedia <kevinz5000@gmail.com>
Content.Server/Atmos/Piping/Other/Components/GasMinerComponent.cs
Content.Server/Atmos/Piping/Other/EntitySystems/GasMinerSystem.cs
Resources/Prototypes/Entities/Structures/Piping/Atmospherics/miners.yml

index 18a0b9b07828630144d3d7e549907d20857d7105..1775ec5dad8f14cab022c007caf24ef4da6e0c35 100644 (file)
@@ -5,14 +5,22 @@ namespace Content.Server.Atmos.Piping.Other.Components
     [RegisterComponent]
     public sealed partial class GasMinerComponent : Component
     {
+        [ViewVariables(VVAccess.ReadWrite)]
         public bool Enabled { get; set; } = true;
 
-        public bool Broken { get; set; } = false;
+        [ViewVariables(VVAccess.ReadOnly)]
+        public bool Idle { get; set; } = false;
 
+        /// <summary>
+        ///      If the number of moles in the external environment exceeds this number, no gas will be mined.
+        /// </summary>
         [ViewVariables(VVAccess.ReadWrite)]
         [DataField("maxExternalAmount")]
         public float MaxExternalAmount { get; set; } = float.PositiveInfinity;
 
+        /// <summary>
+        ///      If the pressure (in kPA) of the external environment exceeds this number, no gas will be mined.
+        /// </summary>
         [ViewVariables(VVAccess.ReadWrite)]
         [DataField("maxExternalPressure")]
         public float MaxExternalPressure { get; set; } = Atmospherics.GasMinerDefaultMaxExternalPressure;
index 1aa5973c968d49335dd5b3e6f89196455445c7a4..dd46fb6b4c1048571c6ca9713a2bc52b5e65035e 100644 (file)
@@ -25,10 +25,17 @@ namespace Content.Server.Atmos.Piping.Other.EntitySystems
         {
             var miner = ent.Comp;
 
+            if (!GetValidEnvironment(ent, out var environment))
+            {
+                miner.Idle = true;
+                return;
+            }
+
             // SpawnAmount is declared in mol/s so to get the amount of gas we hope to mine, we have to multiply this by
             // how long we have been waiting to spawn it and further cap the number according to the miner's state.
-            var toSpawn = CapSpawnAmount(ent, miner.SpawnAmount * args.dt, out var environment);
-            if (toSpawn <= 0f || environment == null || !miner.Enabled || !miner.SpawnGas.HasValue)
+            var toSpawn = CapSpawnAmount(ent, miner.SpawnAmount * args.dt, environment);
+            miner.Idle = toSpawn == 0;
+            if (miner.Idle || !miner.Enabled || !miner.SpawnGas.HasValue)
                 return;
 
             // Time to mine some gas.
@@ -39,27 +46,26 @@ namespace Content.Server.Atmos.Piping.Other.EntitySystems
             _atmosphereSystem.Merge(environment, merger);
         }
 
-        private float CapSpawnAmount(Entity<GasMinerComponent> ent, float toSpawnTarget, out GasMixture? environment)
+        private bool GetValidEnvironment(Entity<GasMinerComponent> ent, [NotNullWhen(true)] out GasMixture? environment)
         {
             var (uid, miner) = ent;
             var transform = Transform(uid);
-            environment = _atmosphereSystem.GetContainingMixture((uid, transform), true, true);
-
             var position = _transformSystem.GetGridOrMapTilePosition(uid, transform);
 
-            // Space.
+            // Treat space as an invalid environment
             if (_atmosphereSystem.IsTileSpace(transform.GridUid, transform.MapUid, position))
             {
-                miner.Broken = true;
-                return 0f;
+                environment = null;
+                return false;
             }
 
-            // Air-blocked location.
-            if (environment == null)
-            {
-                miner.Broken = true;
-                return 0f;
-            }
+            environment = _atmosphereSystem.GetContainingMixture((uid, transform), true, true);
+            return environment != null;
+        }
+
+        private float CapSpawnAmount(Entity<GasMinerComponent> ent, float toSpawnTarget, GasMixture environment)
+        {
+            var (uid, miner) = ent;
 
             // How many moles could we theoretically spawn. Cap by pressure and amount.
             var allowableMoles = Math.Min(
@@ -69,11 +75,9 @@ namespace Content.Server.Atmos.Piping.Other.EntitySystems
             var toSpawnReal = Math.Clamp(allowableMoles, 0f, toSpawnTarget);
 
             if (toSpawnReal < Atmospherics.GasMinMoles) {
-                miner.Broken = true;
                 return 0f;
             }
 
-            miner.Broken = false;
             return toSpawnReal;
         }
     }
index 6d10b1521e7c618c96f382f5f60f981235806ac5..64dd38accb49c1792e4e08776b9a740a6dac8b97 100644 (file)
@@ -66,8 +66,6 @@
   parent: GasMinerBase
   id: GasMinerNitrogen
   suffix: Shuttle, 300kPa
-  placement:
-    mode: SnapgridCenter
   components:
     - type: GasMiner
       spawnGas: Nitrogen
@@ -94,8 +92,6 @@
   name: CO2 gas miner
   parent: GasMinerBase
   id: GasMinerCarbonDioxide
-  placement:
-    mode: SnapgridCenter
   components:
     - type: GasMiner
       spawnGas: CarbonDioxide
   name: plasma gas miner
   parent: GasMinerBase
   id: GasMinerPlasma
-  placement:
-    mode: SnapgridCenter
   components:
     - type: GasMiner
       spawnGas: Plasma
   name: tritium gas miner
   parent: GasMinerBase
   id: GasMinerTritium
-  placement:
-    mode: SnapgridCenter
   components:
     - type: GasMiner
       spawnGas: Tritium
   name: water vapor gas miner
   parent: GasMinerBase
   id: GasMinerWaterVapor
-  placement:
-    mode: SnapgridCenter
   components:
     - type: GasMiner
       spawnGas: WaterVapor
   name: ammonia gas miner
   parent: GasMinerBase
   id: GasMinerAmmonia
-  placement:
-    mode: SnapgridCenter
   components:
     - type: GasMiner
       spawnGas: Ammonia
   name: nitrous oxide gas miner
   parent: GasMinerBase
   id: GasMinerNitrousOxide
-  placement:
-    mode: SnapgridCenter
   components:
     - type: GasMiner
       spawnGas: NitrousOxide