]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make miners respect AtmosDeviceUpdateEvent.dt (#29522)
authorGuillaume E <262623+quatre@users.noreply.github.com>
Fri, 28 Jun 2024 18:49:39 +0000 (20:49 +0200)
committerGitHub <noreply@github.com>
Fri, 28 Jun 2024 18:49:39 +0000 (10:49 -0800)
Miners' prototype have been changed to reflect this (I read
somewhere that we have about 1 atmos tick/0.5s, my tests show more
like 1/0.53 but that looks close enough).

This also means that miner's spawnAmount is now expressed in mol/s.

See: #18781

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 e6d8ec790d8632c2f2d45dfe1f97202ffb711661..18a0b9b07828630144d3d7e549907d20857d7105 100644 (file)
@@ -25,6 +25,9 @@ namespace Content.Server.Atmos.Piping.Other.Components
         [DataField("spawnTemperature")]
         public float SpawnTemperature { get; set; } = Atmospherics.T20C;
 
+        /// <summary>
+        ///     Number of moles created per second when the miner is working.
+        /// </summary>
         [ViewVariables(VVAccess.ReadWrite)]
         [DataField("spawnAmount")]
         public float SpawnAmount { get; set; } = Atmospherics.MolesCellStandard * 20f;
index aa206dbc6867c009e0e43232d1b8666b09dd6398..2505c8189f88aa3a12d0c4819b6ad353b22a8fae 100644 (file)
@@ -24,18 +24,22 @@ namespace Content.Server.Atmos.Piping.Other.EntitySystems
         private void OnMinerUpdated(Entity<GasMinerComponent> ent, ref AtmosDeviceUpdateEvent args)
         {
             var miner = ent.Comp;
-            if (!CheckMinerOperation(ent, out var environment) || !miner.Enabled || !miner.SpawnGas.HasValue || miner.SpawnAmount <= 0f)
+
+            // 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.
+            var toSpawn = miner.SpawnAmount * args.dt;
+            if (!CheckMinerOperation(ent, toSpawn, out var environment) || !miner.Enabled || !miner.SpawnGas.HasValue || toSpawn <= 0f)
                 return;
 
             // Time to mine some gas.
 
             var merger = new GasMixture(1) { Temperature = miner.SpawnTemperature };
-            merger.SetMoles(miner.SpawnGas.Value, miner.SpawnAmount);
+            merger.SetMoles(miner.SpawnGas.Value, toSpawn);
 
             _atmosphereSystem.Merge(environment, merger);
         }
 
-        private bool CheckMinerOperation(Entity<GasMinerComponent> ent, [NotNullWhen(true)] out GasMixture? environment)
+        private bool CheckMinerOperation(Entity<GasMinerComponent> ent, float toSpawn, [NotNullWhen(true)] out GasMixture? environment)
         {
             var (uid, miner) = ent;
             var transform = Transform(uid);
@@ -59,7 +63,7 @@ namespace Content.Server.Atmos.Piping.Other.EntitySystems
 
             // External pressure above threshold.
             if (!float.IsInfinity(miner.MaxExternalPressure) &&
-                environment.Pressure > miner.MaxExternalPressure - miner.SpawnAmount * miner.SpawnTemperature * Atmospherics.R / environment.Volume)
+                environment.Pressure > miner.MaxExternalPressure - toSpawn * miner.SpawnTemperature * Atmospherics.R / environment.Volume)
             {
                 miner.Broken = true;
                 return false;
index 2231fc4ddc161328937d5dffc532a643c0a959c7..6d10b1521e7c618c96f382f5f60f981235806ac5 100644 (file)
@@ -30,7 +30,7 @@
     - type: AtmosDevice
     - type: GasMiner
       maxExternalPressure: 300
-      spawnAmount: 200
+      spawnAmount: 400
 
 - type: entity
   name: O2 gas miner