2021-12-10 12:23:18 -06:00
|
|
|
using Content.Server.Administration.Logs;
|
2021-07-19 12:07:37 +02:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2023-08-12 22:41:55 +02:00
|
|
|
using Content.Server.Atmos.Monitor.Systems;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.Atmos.Piping.Binary.Components;
|
|
|
|
|
using Content.Server.Atmos.Piping.Components;
|
2023-08-12 22:41:55 +02:00
|
|
|
using Content.Server.DeviceNetwork;
|
|
|
|
|
using Content.Server.DeviceNetwork.Components;
|
|
|
|
|
using Content.Server.DeviceNetwork.Systems;
|
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;
|
2024-09-14 17:58:10 -08:00
|
|
|
using Content.Server.Power.Components;
|
2021-11-04 19:41:56 -05:00
|
|
|
using Content.Shared.Atmos.Piping.Binary.Components;
|
2023-09-30 05:35:23 +02:00
|
|
|
using Content.Shared.Atmos.Visuals;
|
2022-03-12 16:20:31 -06:00
|
|
|
using Content.Shared.Audio;
|
2021-12-10 12:23:18 -06:00
|
|
|
using Content.Shared.Database;
|
2024-02-11 14:19:45 +11:00
|
|
|
using Content.Shared.DeviceNetwork;
|
2021-10-19 21:46:31 +00:00
|
|
|
using Content.Shared.Examine;
|
2021-11-04 19:41:56 -05:00
|
|
|
using Content.Shared.Interaction;
|
2021-11-11 16:10:21 -06:00
|
|
|
using Content.Shared.Popups;
|
2024-09-14 21:00:06 -07:00
|
|
|
using Content.Shared.Power;
|
2021-06-19 13:25:05 +02:00
|
|
|
using JetBrains.Annotations;
|
2021-11-04 19:41:56 -05:00
|
|
|
using Robust.Server.GameObjects;
|
2023-10-29 04:21:02 +11:00
|
|
|
using Robust.Shared.Player;
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos.Piping.Binary.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class GasVolumePumpSystem : EntitySystem
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2022-07-04 16:51:34 +02:00
|
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
2022-03-12 16:20:31 -06:00
|
|
|
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
|
|
|
|
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2023-06-28 14:28:38 +03:00
|
|
|
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
2023-08-12 22:41:55 +02:00
|
|
|
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
|
2023-10-15 22:56:09 -07:00
|
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
2023-08-12 22:41:55 +02:00
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2022-06-23 14:18:11 +02:00
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, ComponentInit>(OnInit);
|
2021-06-19 13:25:05 +02:00
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceUpdateEvent>(OnVolumePumpUpdated);
|
2022-06-23 14:18:11 +02:00
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceDisabledEvent>(OnVolumePumpLeaveAtmosphere);
|
2021-10-19 21:46:31 +00:00
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, ExaminedEvent>(OnExamined);
|
2023-08-12 22:41:55 +02:00
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, ActivateInWorldEvent>(OnPumpActivate);
|
2024-09-14 17:58:10 -08:00
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, PowerChangedEvent>(OnPowerChanged);
|
2021-11-04 19:41:56 -05:00
|
|
|
// Bound UI subscriptions
|
|
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpChangeTransferRateMessage>(OnTransferRateChangeMessage);
|
|
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpToggleStatusMessage>(OnToggleStatusMessage);
|
2023-08-12 22:41:55 +02:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<GasVolumePumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
2021-10-19 21:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-23 14:18:11 +02:00
|
|
|
private void OnInit(EntityUid uid, GasVolumePumpComponent pump, ComponentInit args)
|
|
|
|
|
{
|
|
|
|
|
UpdateAppearance(uid, pump);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 21:46:31 +00:00
|
|
|
private void OnExamined(EntityUid uid, GasVolumePumpComponent pump, ExaminedEvent args)
|
|
|
|
|
{
|
2023-10-15 22:56:09 -07:00
|
|
|
if (!EntityManager.GetComponent<TransformComponent>(uid).Anchored || !args.IsInDetailsRange) // Not anchored? Out of range? No status.
|
2021-10-19 21:46:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (Loc.TryGetString("gas-volume-pump-system-examined", out var str,
|
|
|
|
|
("statusColor", "lightblue"), // TODO: change with volume?
|
|
|
|
|
("rate", pump.TransferRate)
|
|
|
|
|
))
|
|
|
|
|
args.PushMarkup(str);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-14 17:58:10 -08:00
|
|
|
private void OnPowerChanged(EntityUid uid, GasVolumePumpComponent component, ref PowerChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
UpdateAppearance(uid, component);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-21 18:48:18 -07:00
|
|
|
private void OnVolumePumpUpdated(EntityUid uid, GasVolumePumpComponent pump, ref AtmosDeviceUpdateEvent args)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2024-03-30 17:17:53 +13:00
|
|
|
if (!pump.Enabled ||
|
2024-09-14 17:58:10 -08:00
|
|
|
(TryComp<ApcPowerReceiverComponent>(uid, out var power) && !power.Powered) ||
|
2024-03-30 17:17:53 +13:00
|
|
|
!_nodeContainer.TryGetNodes(uid, pump.InletName, pump.OutletName, out PipeNode? inlet, out PipeNode? outlet))
|
2022-03-01 03:39:30 +13:00
|
|
|
{
|
2022-07-04 16:51:34 +02:00
|
|
|
_ambientSoundSystem.SetAmbience(uid, false);
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
2022-03-01 03:39:30 +13:00
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
var inputStartingPressure = inlet.Air.Pressure;
|
|
|
|
|
var outputStartingPressure = outlet.Air.Pressure;
|
|
|
|
|
|
2023-09-30 05:35:23 +02:00
|
|
|
var previouslyBlocked = pump.Blocked;
|
|
|
|
|
pump.Blocked = false;
|
|
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
// Pump mechanism won't do anything if the pressure is too high/too low unless you overclock it.
|
|
|
|
|
if ((inputStartingPressure < pump.LowerThreshold) || (outputStartingPressure > pump.HigherThreshold) && !pump.Overclocked)
|
2023-09-30 05:35:23 +02:00
|
|
|
{
|
|
|
|
|
pump.Blocked = true;
|
|
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
// Overclocked pumps can only force gas a certain amount.
|
|
|
|
|
if ((outputStartingPressure - inputStartingPressure > pump.OverclockThreshold) && pump.Overclocked)
|
2023-09-30 05:35:23 +02:00
|
|
|
{
|
|
|
|
|
pump.Blocked = true;
|
|
|
|
|
}
|
2023-10-15 22:56:09 -07:00
|
|
|
|
2023-09-30 05:35:23 +02:00
|
|
|
if (previouslyBlocked != pump.Blocked)
|
|
|
|
|
UpdateAppearance(uid, pump);
|
|
|
|
|
if (pump.Blocked)
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// We multiply the transfer rate in L/s by the seconds passed since the last process to get the liters.
|
2023-12-11 15:59:47 -08:00
|
|
|
var removed = inlet.Air.RemoveVolume(pump.TransferRate * _atmosphereSystem.PumpSpeedup() * args.dt);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
// Some of the gas from the mixture leaks when overclocked.
|
|
|
|
|
if (pump.Overclocked)
|
|
|
|
|
{
|
2023-11-28 18:03:44 -05:00
|
|
|
var tile = _atmosphereSystem.GetTileMixture(uid, excite: true);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
if (tile != null)
|
|
|
|
|
{
|
|
|
|
|
var leaked = removed.RemoveRatio(pump.LeakRatio);
|
2021-07-26 12:58:17 +02:00
|
|
|
_atmosphereSystem.Merge(tile, leaked);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-12 22:41:55 +02:00
|
|
|
pump.LastMolesTransferred = removed.TotalMoles;
|
|
|
|
|
|
2022-02-05 23:57:26 +13:00
|
|
|
_atmosphereSystem.Merge(outlet.Air, removed);
|
2022-07-04 16:51:34 +02:00
|
|
|
_ambientSoundSystem.SetAmbience(uid, removed.TotalMoles > 0f);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
2021-11-04 19:41:56 -05:00
|
|
|
|
2023-12-21 18:48:18 -07:00
|
|
|
private void OnVolumePumpLeaveAtmosphere(EntityUid uid, GasVolumePumpComponent pump, ref AtmosDeviceDisabledEvent args)
|
2022-06-23 14:18:11 +02:00
|
|
|
{
|
|
|
|
|
pump.Enabled = false;
|
|
|
|
|
UpdateAppearance(uid, pump);
|
|
|
|
|
|
|
|
|
|
DirtyUI(uid, pump);
|
2024-04-26 18:16:24 +10:00
|
|
|
_userInterfaceSystem.CloseUi(uid, GasVolumePumpUiKey.Key);
|
2022-06-23 14:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-12 22:41:55 +02:00
|
|
|
private void OnPumpActivate(EntityUid uid, GasVolumePumpComponent pump, ActivateInWorldEvent args)
|
2021-11-04 19:41:56 -05:00
|
|
|
{
|
2024-05-31 16:26:19 -04:00
|
|
|
if (args.Handled || !args.Complex)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
|
2021-11-04 19:41:56 -05:00
|
|
|
return;
|
|
|
|
|
|
2023-10-15 22:56:09 -07:00
|
|
|
if (Transform(uid).Anchored)
|
2021-11-11 16:10:21 -06:00
|
|
|
{
|
2024-04-26 18:16:24 +10:00
|
|
|
_userInterfaceSystem.OpenUi(uid, GasVolumePumpUiKey.Key, actor.PlayerSession);
|
2022-06-23 14:18:11 +02:00
|
|
|
DirtyUI(uid, pump);
|
2021-11-11 16:10:21 -06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-10-15 22:56:09 -07:00
|
|
|
_popup.PopupCursor(Loc.GetString("comp-gas-pump-ui-needs-anchor"), args.User);
|
2021-11-11 16:10:21 -06:00
|
|
|
}
|
2021-11-04 19:41:56 -05:00
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnToggleStatusMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpToggleStatusMessage args)
|
|
|
|
|
{
|
|
|
|
|
pump.Enabled = args.Enabled;
|
2022-05-28 23:41:17 -07:00
|
|
|
_adminLogger.Add(LogType.AtmosPowerChanged, LogImpact.Medium,
|
2024-04-26 18:16:24 +10:00
|
|
|
$"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(uid):device} to {args.Enabled}");
|
2021-11-04 19:41:56 -05:00
|
|
|
DirtyUI(uid, pump);
|
2022-06-23 14:18:11 +02:00
|
|
|
UpdateAppearance(uid, pump);
|
2021-11-04 19:41:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTransferRateChangeMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpChangeTransferRateMessage args)
|
|
|
|
|
{
|
2022-03-01 03:39:30 +13:00
|
|
|
pump.TransferRate = Math.Clamp(args.TransferRate, 0f, pump.MaxTransferRate);
|
2022-05-28 23:41:17 -07:00
|
|
|
_adminLogger.Add(LogType.AtmosVolumeChanged, LogImpact.Medium,
|
2024-04-26 18:16:24 +10:00
|
|
|
$"{ToPrettyString(args.Actor):player} set the transfer rate on {ToPrettyString(uid):device} to {args.TransferRate}");
|
2021-11-04 19:41:56 -05:00
|
|
|
DirtyUI(uid, pump);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DirtyUI(EntityUid uid, GasVolumePumpComponent? pump)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref pump))
|
|
|
|
|
return;
|
|
|
|
|
|
2024-04-26 18:16:24 +10:00
|
|
|
_userInterfaceSystem.SetUiState(uid, GasVolumePumpUiKey.Key,
|
2023-10-15 22:56:09 -07:00
|
|
|
new GasVolumePumpBoundUserInterfaceState(Name(uid), pump.TransferRate, pump.Enabled));
|
2021-11-04 19:41:56 -05:00
|
|
|
}
|
2022-06-23 14:18:11 +02:00
|
|
|
|
|
|
|
|
private void UpdateAppearance(EntityUid uid, GasVolumePumpComponent? pump = null, AppearanceComponent? appearance = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref pump, ref appearance, false))
|
|
|
|
|
return;
|
|
|
|
|
|
2024-09-14 17:58:10 -08:00
|
|
|
bool pumpOn = pump.Enabled && (TryComp<ApcPowerReceiverComponent>(uid, out var power) && power.Powered);
|
|
|
|
|
if (!pumpOn)
|
2023-09-30 05:35:23 +02:00
|
|
|
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.Off, appearance);
|
|
|
|
|
else if (pump.Blocked)
|
|
|
|
|
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.Blocked, appearance);
|
|
|
|
|
else
|
|
|
|
|
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.On, appearance);
|
2022-06-23 14:18:11 +02:00
|
|
|
}
|
2023-08-12 22:41:55 +02:00
|
|
|
|
|
|
|
|
private void OnPacketRecv(EntityUid uid, GasVolumePumpComponent component, DeviceNetworkPacketEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp(uid, out DeviceNetworkComponent? netConn)
|
|
|
|
|
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var payload = new NetworkPayload();
|
|
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
|
{
|
|
|
|
|
case AtmosDeviceNetworkSystem.SyncData:
|
|
|
|
|
payload.Add(DeviceNetworkConstants.Command, AtmosDeviceNetworkSystem.SyncData);
|
|
|
|
|
payload.Add(AtmosDeviceNetworkSystem.SyncData, new GasVolumePumpData(component.LastMolesTransferred));
|
|
|
|
|
|
|
|
|
|
_deviceNetwork.QueuePacket(uid, args.SenderAddress, payload, device: netConn);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|