2021-06-19 13:25:05 +02:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using Content.Server.Atmos.Components;
|
2021-07-19 12:07:37 +02:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.Atmos.Piping.Components;
|
|
|
|
|
using Content.Server.Atmos.Piping.Other.Components;
|
|
|
|
|
using Content.Shared.Atmos;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-26 12:58:17 +02:00
|
|
|
using Robust.Shared.IoC;
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos.Piping.Other.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class GasMinerSystem : EntitySystem
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
|
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<GasMinerComponent, AtmosDeviceUpdateEvent>(OnMinerUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMinerUpdated(EntityUid uid, GasMinerComponent miner, AtmosDeviceUpdateEvent args)
|
|
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
if (!CheckMinerOperation(miner, out var environment) || !miner.Enabled || !miner.SpawnGas.HasValue || miner.SpawnAmount <= 0f)
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Time to mine some gas.
|
|
|
|
|
|
|
|
|
|
var merger = new GasMixture(1) { Temperature = miner.SpawnTemperature };
|
2021-06-21 10:51:06 +02:00
|
|
|
merger.SetMoles(miner.SpawnGas.Value, miner.SpawnAmount);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2021-07-26 12:58:17 +02:00
|
|
|
_atmosphereSystem.Merge(environment, merger);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-26 12:58:17 +02:00
|
|
|
private bool CheckMinerOperation(GasMinerComponent miner, [NotNullWhen(true)] out GasMixture? environment)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2021-12-08 13:00:43 +01:00
|
|
|
environment = _atmosphereSystem.GetTileMixture(EntityManager.GetComponent<TransformComponent>(miner.Owner).Coordinates, true);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
// Space.
|
2021-12-08 13:00:43 +01:00
|
|
|
if (_atmosphereSystem.IsTileSpace(EntityManager.GetComponent<TransformComponent>(miner.Owner).Coordinates))
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
|
|
|
|
miner.Broken = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 12:07:37 +02:00
|
|
|
// Air-blocked location.
|
|
|
|
|
if (environment == null)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
|
|
|
|
miner.Broken = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// External pressure above threshold.
|
|
|
|
|
if (!float.IsInfinity(miner.MaxExternalPressure) &&
|
2021-07-19 12:07:37 +02:00
|
|
|
environment.Pressure > miner.MaxExternalPressure - miner.SpawnAmount * miner.SpawnTemperature * Atmospherics.R / environment.Volume)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
|
|
|
|
miner.Broken = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// External gas amount above threshold.
|
2021-07-19 12:07:37 +02:00
|
|
|
if (!float.IsInfinity(miner.MaxExternalAmount) && environment.TotalMoles > miner.MaxExternalAmount)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
|
|
|
|
miner.Broken = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
miner.Broken = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|