2021-12-10 12:23:18 -06:00
|
|
|
using Content.Server.Administration.Logs;
|
2022-02-05 23:57:26 +13:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.Atmos.Piping.Binary.Components;
|
|
|
|
|
using Content.Server.Atmos.Piping.Components;
|
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-06-19 13:25:05 +02:00
|
|
|
using Content.Shared.Atmos;
|
|
|
|
|
using Content.Shared.Atmos.Piping;
|
2021-11-04 19:41:56 -05:00
|
|
|
using Content.Shared.Atmos.Piping.Binary.Components;
|
2022-03-12 16:20:31 -06:00
|
|
|
using Content.Shared.Audio;
|
2021-12-10 12:23:18 -06:00
|
|
|
using Content.Shared.Database;
|
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;
|
|
|
|
|
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 GasPressurePumpSystem : EntitySystem
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2022-03-12 16:20:31 -06:00
|
|
|
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
2022-05-28 23:41:17 -07:00
|
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
2022-02-05 23:57:26 +13:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
2022-03-12 16:20:31 -06:00
|
|
|
[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-10-15 22:56:09 -07:00
|
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
2021-11-04 19:41:56 -05:00
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2022-06-23 14:18:11 +02:00
|
|
|
SubscribeLocalEvent<GasPressurePumpComponent, ComponentInit>(OnInit);
|
2021-06-19 13:25:05 +02:00
|
|
|
SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceUpdateEvent>(OnPumpUpdated);
|
|
|
|
|
SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceDisabledEvent>(OnPumpLeaveAtmosphere);
|
2021-10-19 21:46:31 +00:00
|
|
|
SubscribeLocalEvent<GasPressurePumpComponent, ExaminedEvent>(OnExamined);
|
2023-08-12 22:41:55 +02:00
|
|
|
SubscribeLocalEvent<GasPressurePumpComponent, ActivateInWorldEvent>(OnPumpActivate);
|
2024-09-14 17:58:10 -08:00
|
|
|
SubscribeLocalEvent<GasPressurePumpComponent, PowerChangedEvent>(OnPowerChanged);
|
2021-11-04 19:41:56 -05:00
|
|
|
// Bound UI subscriptions
|
|
|
|
|
SubscribeLocalEvent<GasPressurePumpComponent, GasPressurePumpChangeOutputPressureMessage>(OnOutputPressureChangeMessage);
|
|
|
|
|
SubscribeLocalEvent<GasPressurePumpComponent, GasPressurePumpToggleStatusMessage>(OnToggleStatusMessage);
|
2021-10-19 21:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-23 14:18:11 +02:00
|
|
|
private void OnInit(EntityUid uid, GasPressurePumpComponent pump, ComponentInit args)
|
|
|
|
|
{
|
|
|
|
|
UpdateAppearance(uid, pump);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 21:46:31 +00:00
|
|
|
private void OnExamined(EntityUid uid, GasPressurePumpComponent 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-pressure-pump-system-examined", out var str,
|
2023-10-15 22:56:09 -07:00
|
|
|
("statusColor", "lightblue"), // TODO: change with pressure?
|
|
|
|
|
("pressure", pump.TargetPressure)
|
|
|
|
|
))
|
|
|
|
|
{
|
2021-10-19 21:46:31 +00:00
|
|
|
args.PushMarkup(str);
|
2023-10-15 22:56:09 -07:00
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-14 17:58:10 -08:00
|
|
|
private void OnPowerChanged(EntityUid uid, GasPressurePumpComponent component, ref PowerChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
UpdateAppearance(uid, component);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-21 18:48:18 -07:00
|
|
|
private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceUpdateEvent args)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2021-07-30 14:00:14 +02: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))
|
2021-07-30 14:00:14 +02:00
|
|
|
{
|
2023-10-15 22:56:09 -07:00
|
|
|
_ambientSoundSystem.SetAmbience(uid, false);
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
2021-07-30 14:00:14 +02:00
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
var outputStartingPressure = outlet.Air.Pressure;
|
|
|
|
|
|
2022-05-03 13:24:30 -07:00
|
|
|
if (outputStartingPressure >= pump.TargetPressure)
|
2021-07-30 14:00:14 +02:00
|
|
|
{
|
2023-10-15 22:56:09 -07:00
|
|
|
_ambientSoundSystem.SetAmbience(uid, false);
|
2021-06-19 13:25:05 +02:00
|
|
|
return; // No need to pump gas if target has been reached.
|
2021-07-30 14:00:14 +02:00
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0)
|
|
|
|
|
{
|
|
|
|
|
// We calculate the necessary moles to transfer using our good ol' friend PV=nRT.
|
|
|
|
|
var pressureDelta = pump.TargetPressure - outputStartingPressure;
|
2022-05-21 11:37:44 +03:00
|
|
|
var transferMoles = (pressureDelta * outlet.Air.Volume) / (inlet.Air.Temperature * Atmospherics.R);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
var removed = inlet.Air.Remove(transferMoles);
|
2022-02-05 23:57:26 +13:00
|
|
|
_atmosphereSystem.Merge(outlet.Air, removed);
|
2023-10-15 22:56:09 -07:00
|
|
|
_ambientSoundSystem.SetAmbience(uid, removed.TotalMoles > 0f);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-21 18:48:18 -07:00
|
|
|
private void OnPumpLeaveAtmosphere(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceDisabledEvent args)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
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, GasPressurePumpUiKey.Key);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-12 22:41:55 +02:00
|
|
|
private void OnPumpActivate(EntityUid uid, GasPressurePumpComponent 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, GasPressurePumpUiKey.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, GasPressurePumpComponent pump, GasPressurePumpToggleStatusMessage 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 OnOutputPressureChangeMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpChangeOutputPressureMessage args)
|
|
|
|
|
{
|
|
|
|
|
pump.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure);
|
2022-05-28 23:41:17 -07:00
|
|
|
_adminLogger.Add(LogType.AtmosPressureChanged, LogImpact.Medium,
|
2024-04-26 18:16:24 +10:00
|
|
|
$"{ToPrettyString(args.Actor):player} set the pressure on {ToPrettyString(uid):device} to {args.Pressure}kPa");
|
2021-11-04 19:41:56 -05:00
|
|
|
DirtyUI(uid, pump);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DirtyUI(EntityUid uid, GasPressurePumpComponent? pump)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref pump))
|
|
|
|
|
return;
|
|
|
|
|
|
2024-04-26 18:16:24 +10:00
|
|
|
_userInterfaceSystem.SetUiState(uid, GasPressurePumpUiKey.Key,
|
2023-10-15 22:56:09 -07:00
|
|
|
new GasPressurePumpBoundUserInterfaceState(EntityManager.GetComponent<MetaDataComponent>(uid).EntityName, pump.TargetPressure, pump.Enabled));
|
2021-11-04 19:41:56 -05:00
|
|
|
}
|
2022-06-23 14:18:11 +02:00
|
|
|
|
|
|
|
|
private void UpdateAppearance(EntityUid uid, GasPressurePumpComponent? 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);
|
|
|
|
|
_appearance.SetData(uid, PumpVisuals.Enabled, pumpOn, appearance);
|
2022-06-23 14:18:11 +02:00
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|