Make miners respect AtmosDeviceUpdateEvent.dt (#29522)

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
This commit is contained in:
Guillaume E
2024-06-28 20:49:39 +02:00
committed by GitHub
parent 9e4b8077f3
commit c38859b77a
3 changed files with 12 additions and 5 deletions

View 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;

View 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;

View File

@@ -30,7 +30,7 @@
- type: AtmosDevice
- type: GasMiner
maxExternalPressure: 300
spawnAmount: 200
spawnAmount: 400
- type: entity
name: O2 gas miner