From: Mervill Date: Tue, 2 Jul 2024 20:18:56 +0000 (-0700) Subject: Clean up gas miners (#29657) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=4ec15c84fa220c6ff60477f0a53c6598eac2685d;p=space-station-14.git Clean up gas miners (#29657) 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 --- diff --git a/Content.Server/Atmos/Piping/Other/Components/GasMinerComponent.cs b/Content.Server/Atmos/Piping/Other/Components/GasMinerComponent.cs index 18a0b9b078..1775ec5dad 100644 --- a/Content.Server/Atmos/Piping/Other/Components/GasMinerComponent.cs +++ b/Content.Server/Atmos/Piping/Other/Components/GasMinerComponent.cs @@ -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; + /// + /// If the number of moles in the external environment exceeds this number, no gas will be mined. + /// [ViewVariables(VVAccess.ReadWrite)] [DataField("maxExternalAmount")] public float MaxExternalAmount { get; set; } = float.PositiveInfinity; + /// + /// If the pressure (in kPA) of the external environment exceeds this number, no gas will be mined. + /// [ViewVariables(VVAccess.ReadWrite)] [DataField("maxExternalPressure")] public float MaxExternalPressure { get; set; } = Atmospherics.GasMinerDefaultMaxExternalPressure; diff --git a/Content.Server/Atmos/Piping/Other/EntitySystems/GasMinerSystem.cs b/Content.Server/Atmos/Piping/Other/EntitySystems/GasMinerSystem.cs index 1aa5973c96..dd46fb6b4c 100644 --- a/Content.Server/Atmos/Piping/Other/EntitySystems/GasMinerSystem.cs +++ b/Content.Server/Atmos/Piping/Other/EntitySystems/GasMinerSystem.cs @@ -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 ent, float toSpawnTarget, out GasMixture? environment) + private bool GetValidEnvironment(Entity 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 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; } } diff --git a/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/miners.yml b/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/miners.yml index 6d10b1521e..64dd38accb 100644 --- a/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/miners.yml +++ b/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/miners.yml @@ -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 @@ -104,8 +100,6 @@ name: plasma gas miner parent: GasMinerBase id: GasMinerPlasma - placement: - mode: SnapgridCenter components: - type: GasMiner spawnGas: Plasma @@ -114,8 +108,6 @@ name: tritium gas miner parent: GasMinerBase id: GasMinerTritium - placement: - mode: SnapgridCenter components: - type: GasMiner spawnGas: Tritium @@ -124,8 +116,6 @@ name: water vapor gas miner parent: GasMinerBase id: GasMinerWaterVapor - placement: - mode: SnapgridCenter components: - type: GasMiner spawnGas: WaterVapor @@ -134,8 +124,6 @@ name: ammonia gas miner parent: GasMinerBase id: GasMinerAmmonia - placement: - mode: SnapgridCenter components: - type: GasMiner spawnGas: Ammonia @@ -144,8 +132,6 @@ name: nitrous oxide gas miner parent: GasMinerBase id: GasMinerNitrousOxide - placement: - mode: SnapgridCenter components: - type: GasMiner spawnGas: NitrousOxide