[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;
{
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.
_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(
var toSpawnReal = Math.Clamp(allowableMoles, 0f, toSpawnTarget);
if (toSpawnReal < Atmospherics.GasMinMoles) {
- miner.Broken = true;
return 0f;
}
- miner.Broken = false;
return toSpawnReal;
}
}