2021-06-23 11:35:30 +02:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Content.Server.Atmos.Monitor.Components;
|
|
|
|
|
using Content.Server.Atmos.Monitor.Systems;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.Atmos.Piping.Components;
|
|
|
|
|
using Content.Server.Atmos.Piping.Unary.Components;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Content.Server.DeviceNetwork;
|
|
|
|
|
using Content.Server.DeviceNetwork.Components;
|
|
|
|
|
using Content.Server.DeviceNetwork.Systems;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.NodeContainer;
|
2023-06-28 14:28:38 +03:00
|
|
|
using Content.Server.NodeContainer.EntitySystems;
|
2021-07-04 18:11:52 +02:00
|
|
|
using Content.Server.NodeContainer.Nodes;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Content.Server.Power.Components;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Shared.Atmos;
|
|
|
|
|
using Content.Shared.Atmos.Piping.Unary.Visuals;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Content.Shared.Atmos.Monitor;
|
|
|
|
|
using Content.Shared.Atmos.Piping.Unary.Components;
|
2022-03-12 16:20:31 -06:00
|
|
|
using Content.Shared.Audio;
|
2024-02-11 14:19:45 +11:00
|
|
|
using Content.Shared.DeviceNetwork;
|
2024-08-25 22:18:42 +10:00
|
|
|
using Content.Shared.Power;
|
2023-09-05 00:07:01 +10:00
|
|
|
using Content.Shared.Tools.Systems;
|
2021-06-19 13:25:05 +02:00
|
|
|
using JetBrains.Annotations;
|
2022-07-04 16:51:34 +02:00
|
|
|
using Robust.Server.GameObjects;
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class GasVentScrubberSystem : EntitySystem
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
2022-01-01 20:56:24 -08:00
|
|
|
[Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!;
|
2023-09-05 00:07:01 +10:00
|
|
|
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
2022-03-12 16:20:31 -06:00
|
|
|
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
2022-07-04 16:51:34 +02:00
|
|
|
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2023-09-05 00:07:01 +10:00
|
|
|
[Dependency] private readonly WeldableSystem _weldable = default!;
|
2021-07-26 12:58:17 +02:00
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceUpdateEvent>(OnVentScrubberUpdated);
|
2022-04-08 19:52:44 -07:00
|
|
|
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceEnabledEvent>(OnVentScrubberEnterAtmosphere);
|
2021-06-19 13:25:05 +02:00
|
|
|
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceDisabledEvent>(OnVentScrubberLeaveAtmosphere);
|
2022-08-23 10:42:03 -07:00
|
|
|
SubscribeLocalEvent<GasVentScrubberComponent, AtmosAlarmEvent>(OnAtmosAlarm);
|
2022-01-01 20:56:24 -08:00
|
|
|
SubscribeLocalEvent<GasVentScrubberComponent, PowerChangedEvent>(OnPowerChanged);
|
2022-04-09 00:27:10 +12:00
|
|
|
SubscribeLocalEvent<GasVentScrubberComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
2023-09-04 06:23:38 +02:00
|
|
|
SubscribeLocalEvent<GasVentScrubberComponent, WeldableChangedEvent>(OnWeldChanged);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-21 18:48:18 -07:00
|
|
|
private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrubber, ref AtmosDeviceUpdateEvent args)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2023-09-05 00:07:01 +10:00
|
|
|
if (_weldable.IsWelded(uid))
|
2022-03-01 03:39:30 +13:00
|
|
|
return;
|
|
|
|
|
|
2023-08-12 23:42:12 -07:00
|
|
|
var timeDelta = args.dt;
|
2022-03-01 03:39:30 +13:00
|
|
|
|
2024-03-30 17:17:53 +13:00
|
|
|
if (!scrubber.Enabled || !_nodeContainer.TryGetNode(uid, scrubber.OutletName, out PipeNode? outlet))
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-03-30 17:17:53 +13:00
|
|
|
if (args.Grid is not {} grid)
|
2022-07-04 16:51:34 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-03-30 17:17:53 +13:00
|
|
|
var position = _transformSystem.GetGridTilePositionOrDefault(uid);
|
|
|
|
|
var environment = _atmosphereSystem.GetTileMixture(grid, args.Map, position, true);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2022-04-08 19:52:44 -07:00
|
|
|
Scrub(timeDelta, scrubber, environment, outlet);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2022-07-04 16:51:34 +02:00
|
|
|
if (!scrubber.WideNet)
|
|
|
|
|
return;
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
// Scrub adjacent tiles too.
|
2024-03-30 17:17:53 +13:00
|
|
|
var enumerator = _atmosphereSystem.GetAdjacentTileMixtures(grid, position, false, true);
|
2024-03-28 15:22:19 +13:00
|
|
|
while (enumerator.MoveNext(out var adjacent))
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2022-04-08 19:52:44 -07:00
|
|
|
Scrub(timeDelta, scrubber, adjacent, outlet);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 19:52:44 -07:00
|
|
|
private void OnVentScrubberLeaveAtmosphere(EntityUid uid, GasVentScrubberComponent component,
|
|
|
|
|
AtmosDeviceDisabledEvent args) => UpdateState(uid, component);
|
|
|
|
|
|
|
|
|
|
private void OnVentScrubberEnterAtmosphere(EntityUid uid, GasVentScrubberComponent component,
|
|
|
|
|
AtmosDeviceEnabledEvent args) => UpdateState(uid, component);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2022-04-08 19:52:44 -07:00
|
|
|
private void Scrub(float timeDelta, GasVentScrubberComponent scrubber, GasMixture? tile, PipeNode outlet)
|
2022-07-15 08:46:30 -04:00
|
|
|
{
|
2023-12-11 15:59:47 -08:00
|
|
|
Scrub(timeDelta, scrubber.TransferRate*_atmosphereSystem.PumpSpeedup(), scrubber.PumpDirection, scrubber.FilterGases, tile, outlet.Air);
|
2022-07-15 08:46:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if we were able to scrub, false if we were not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Scrub(float timeDelta, float transferRate, ScrubberPumpDirection mode, HashSet<Gas> filterGases, GasMixture? tile, GasMixture destination)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
|
|
|
|
// Cannot scrub if tile is null or air-blocked.
|
2021-07-30 14:00:14 +02:00
|
|
|
if (tile == null
|
2022-07-15 08:46:30 -04:00
|
|
|
|| destination.Pressure >= 50 * Atmospherics.OneAtmosphere) // Cannot scrub if pressure too high.
|
2021-07-30 14:00:14 +02:00
|
|
|
{
|
2022-07-15 08:46:30 -04:00
|
|
|
return false;
|
2021-07-30 14:00:14 +02:00
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2022-03-01 03:39:30 +13:00
|
|
|
// Take a gas sample.
|
2022-07-15 08:46:30 -04:00
|
|
|
var ratio = MathF.Min(1f, timeDelta * transferRate / tile.Volume);
|
2022-03-01 03:39:30 +13:00
|
|
|
var removed = tile.RemoveRatio(ratio);
|
|
|
|
|
|
|
|
|
|
// Nothing left to remove from the tile.
|
|
|
|
|
if (MathHelper.CloseToPercent(removed.TotalMoles, 0f))
|
2022-07-15 08:46:30 -04:00
|
|
|
return false;
|
2022-03-01 03:39:30 +13:00
|
|
|
|
2022-07-15 08:46:30 -04:00
|
|
|
if (mode == ScrubberPumpDirection.Scrubbing)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2022-07-15 08:46:30 -04:00
|
|
|
_atmosphereSystem.ScrubInto(removed, destination, filterGases);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
// Remix the gases.
|
2022-03-01 03:39:30 +13:00
|
|
|
_atmosphereSystem.Merge(tile, removed);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
2022-07-15 08:46:30 -04:00
|
|
|
else if (mode == ScrubberPumpDirection.Siphoning)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2022-07-15 08:46:30 -04:00
|
|
|
_atmosphereSystem.Merge(destination, removed);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
2022-07-15 08:46:30 -04:00
|
|
|
return true;
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:42:03 -07:00
|
|
|
private void OnAtmosAlarm(EntityUid uid, GasVentScrubberComponent component, AtmosAlarmEvent args)
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
2022-08-29 07:37:26 -07:00
|
|
|
if (args.AlarmType == AtmosAlarmType.Danger)
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
|
|
|
|
component.Enabled = false;
|
|
|
|
|
}
|
2022-08-29 07:37:26 -07:00
|
|
|
else if (args.AlarmType == AtmosAlarmType.Normal)
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
|
|
|
|
component.Enabled = true;
|
|
|
|
|
}
|
2022-04-08 19:52:44 -07:00
|
|
|
|
|
|
|
|
UpdateState(uid, component);
|
2022-01-01 20:56:24 -08:00
|
|
|
}
|
|
|
|
|
|
2022-10-15 15:08:15 +11:00
|
|
|
private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, ref PowerChangedEvent args)
|
2022-04-08 19:52:44 -07:00
|
|
|
{
|
2022-01-01 20:56:24 -08:00
|
|
|
component.Enabled = args.Powered;
|
2022-04-08 19:52:44 -07:00
|
|
|
UpdateState(uid, component);
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-04-09 00:27:10 +12:00
|
|
|
private void OnPacketRecv(EntityUid uid, GasVentScrubberComponent component, DeviceNetworkPacketEvent args)
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
2022-06-04 19:17:48 +12:00
|
|
|
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn)
|
2022-01-01 20:56:24 -08:00
|
|
|
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var payload = new NetworkPayload();
|
|
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
|
{
|
2022-08-22 01:14:39 -07:00
|
|
|
case AtmosDeviceNetworkSystem.SyncData:
|
|
|
|
|
payload.Add(DeviceNetworkConstants.Command, AtmosDeviceNetworkSystem.SyncData);
|
|
|
|
|
payload.Add(AtmosDeviceNetworkSystem.SyncData, component.ToAirAlarmData());
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-04-09 00:27:10 +12:00
|
|
|
_deviceNetSystem.QueuePacket(uid, args.SenderAddress, payload, device: netConn);
|
2022-01-01 20:56:24 -08:00
|
|
|
|
|
|
|
|
return;
|
2022-08-22 05:49:51 -07:00
|
|
|
case DeviceNetworkConstants.CmdSetState:
|
|
|
|
|
if (!args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out GasVentScrubberData? setData))
|
2022-01-01 20:56:24 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
component.FromAirAlarmData(setData);
|
2022-04-08 19:52:44 -07:00
|
|
|
UpdateState(uid, component);
|
2022-01-01 20:56:24 -08:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-08 19:52:44 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates a scrubber's appearance and ambience state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateState(EntityUid uid, GasVentScrubberComponent scrubber,
|
|
|
|
|
AppearanceComponent? appearance = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref appearance, false))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_ambientSoundSystem.SetAmbience(uid, true);
|
2023-09-05 00:07:01 +10:00
|
|
|
if (_weldable.IsWelded(uid))
|
2023-09-04 06:23:38 +02:00
|
|
|
{
|
|
|
|
|
_ambientSoundSystem.SetAmbience(uid, false);
|
|
|
|
|
_appearance.SetData(uid, ScrubberVisuals.State, ScrubberState.Welded, appearance);
|
|
|
|
|
}
|
|
|
|
|
else if (!scrubber.Enabled)
|
2022-04-08 19:52:44 -07:00
|
|
|
{
|
|
|
|
|
_ambientSoundSystem.SetAmbience(uid, false);
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, ScrubberVisuals.State, ScrubberState.Off, appearance);
|
2022-04-08 19:52:44 -07:00
|
|
|
}
|
|
|
|
|
else if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing)
|
|
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, ScrubberVisuals.State, scrubber.WideNet ? ScrubberState.WideScrub : ScrubberState.Scrub, appearance);
|
2022-04-08 19:52:44 -07:00
|
|
|
}
|
|
|
|
|
else if (scrubber.PumpDirection == ScrubberPumpDirection.Siphoning)
|
|
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, ScrubberVisuals.State, ScrubberState.Siphon, appearance);
|
2022-04-08 19:52:44 -07:00
|
|
|
}
|
2023-09-04 06:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-05 00:07:01 +10:00
|
|
|
private void OnWeldChanged(EntityUid uid, GasVentScrubberComponent component, ref WeldableChangedEvent args)
|
2023-09-04 06:23:38 +02:00
|
|
|
{
|
|
|
|
|
UpdateState(uid, component);
|
2022-04-08 19:52:44 -07:00
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|