Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes it possible to disable the vent pressure lockout temporarily with a screwdriver #31050

Merged
merged 11 commits into from
Sep 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Content.Server.Atmos.Piping.Unary.Components
{
// The world if people documented their shit.
[AutoGenerateComponentPause]
[RegisterComponent]
public sealed partial class GasVentPumpComponent : Component
{
Expand All @@ -15,31 +16,25 @@ public sealed partial class GasVentPumpComponent : Component
[ViewVariables]
public bool IsDirty { get; set; } = false;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("inlet")]
[DataField]
public string Inlet { get; set; } = "pipe";

[ViewVariables(VVAccess.ReadWrite)]
[DataField("outlet")]
[DataField]
public string Outlet { get; set; } = "pipe";

[ViewVariables(VVAccess.ReadWrite)]
[DataField("pumpDirection")]
[DataField]
public VentPumpDirection PumpDirection { get; set; } = VentPumpDirection.Releasing;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("pressureChecks")]
[DataField]
public VentPressureBound PressureChecks { get; set; } = VentPressureBound.ExternalBound;

[ViewVariables(VVAccess.ReadOnly)]
[DataField("underPressureLockout")]
[DataField]
public bool UnderPressureLockout { get; set; } = false;

/// <summary>
/// In releasing mode, do not pump when environment pressure is below this limit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("underPressureLockoutThreshold")]
[DataField]
public float UnderPressureLockoutThreshold = 80; // this must be tuned in conjunction with atmos.mmos_spacing_speed

/// <summary>
Expand All @@ -55,12 +50,30 @@ public sealed partial class GasVentPumpComponent : Component
/// repressurizing of the development map take about 30 minutes using an oxygen tank (high pressure)
/// </remarks>

[ViewVariables(VVAccess.ReadWrite)]
[DataField("underPressureLockoutLeaking")]
[DataField]
public float UnderPressureLockoutLeaking = 0.0001f;
/// <summary>
/// Is the vent pressure lockout currently manually disabled?
/// </summary>
[DataField]
public bool IsPressureLockoutManuallyDisabled = false;
/// <summary>
/// The time when the manual pressure lockout will be reenabled.
/// </summary>
[DataField]
[AutoPausedField]
public TimeSpan ManualLockoutReenabledAt;
/// <summary>
/// How long the lockout should remain manually disabled after being interacted with.
/// </summary>
[DataField]
public TimeSpan ManualLockoutDisabledDuration = TimeSpan.FromSeconds(30); // Enough time to fill a 5x5 room
/// <summary>
/// How long the doAfter should take when attempting to manually disable the pressure lockout.
/// </summary>
public float ManualLockoutDisableDoAfter = 2.0f;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("externalPressureBound")]
[DataField]
public float ExternalPressureBound
{
get => _externalPressureBound;
Expand All @@ -72,8 +85,7 @@ public float ExternalPressureBound

private float _externalPressureBound = Atmospherics.OneAtmosphere;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("internalPressureBound")]
[DataField]
public float InternalPressureBound
{
get => _internalPressureBound;
Expand All @@ -88,8 +100,7 @@ public float InternalPressureBound
/// <summary>
/// Max pressure of the target gas (NOT relative to source).
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("maxPressure")]
[DataField]
public float MaxPressure = Atmospherics.MaxOutputPressure;

/// <summary>
Expand All @@ -100,8 +111,7 @@ public float InternalPressureBound
/// is too high, and the vent is connected to a large pipe-net, then someone can nearly instantly flood a
/// room with gas.
/// </remarks>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("targetPressureChange")]
[DataField]
public float TargetPressureChange = Atmospherics.OneAtmosphere;

/// <summary>
Expand All @@ -111,29 +121,26 @@ public float InternalPressureBound
/// Vents cannot suck a pipe completely empty, instead pressurizing a section to a max of
/// pipe pressure * PumpPower (in kPa). So a 51 kPa pipe is required for 101 kPA sections at PumpPower 2.0
/// </remarks>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("PumpPower")]
[DataField]
public float PumpPower = 2.0f;

#region Machine Linking
/// <summary>
/// Whether or not machine linking is enabled for this component.
/// </summary>
[DataField("canLink")]
[DataField]
public bool CanLink = false;

[DataField("pressurizePort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
public string PressurizePort = "Pressurize";

[DataField("depressurizePort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
public string DepressurizePort = "Depressurize";

[ViewVariables(VVAccess.ReadWrite)]
[DataField("pressurizePressure")]
[DataField]
public float PressurizePressure = Atmospherics.OneAtmosphere;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("depressurizePressure")]
[DataField]
public float DepressurizePressure = 0;

// When true, ignore under-pressure lockout. Used to re-fill rooms in air alarm "Fill" mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Piping.Unary;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Atmos.Visuals;
using Content.Shared.Audio;
using Content.Shared.DeviceNetwork;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Power;
using Content.Shared.Tools.Systems;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Timing;

namespace Content.Server.Atmos.Piping.Unary.EntitySystems
{
Expand All @@ -35,7 +36,10 @@ public sealed class GasVentPumpSystem : EntitySystem
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly WeldableSystem _weldable = default!;

[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
// [Dependency] private readonly TransformSystem _transformSystem = default!;
PotentiallyTom marked this conversation as resolved.
Show resolved Hide resolved
public override void Initialize()
{
base.Initialize();
Expand All @@ -51,6 +55,8 @@ public override void Initialize()
SubscribeLocalEvent<GasVentPumpComponent, SignalReceivedEvent>(OnSignalReceived);
SubscribeLocalEvent<GasVentPumpComponent, GasAnalyzerScanEvent>(OnAnalyzed);
SubscribeLocalEvent<GasVentPumpComponent, WeldableChangedEvent>(OnWeldChanged);
SubscribeLocalEvent<GasVentPumpComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<GasVentPumpComponent, VentScrewedDoAfterEvent>(OnVentScrewed);
}

private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, ref AtmosDeviceUpdateEvent args)
Expand Down Expand Up @@ -80,11 +86,16 @@ private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, ref
{
return;
}
// If the lockout has expired, disable it.
if (vent.IsPressureLockoutManuallyDisabled && _timing.CurTime >= vent.ManualLockoutReenabledAt)
{
vent.IsPressureLockoutManuallyDisabled = false;
}

var timeDelta = args.dt;
var pressureDelta = timeDelta * vent.TargetPressureChange;

var lockout = (environment.Pressure < vent.UnderPressureLockoutThreshold);
var lockout = (environment.Pressure < vent.UnderPressureLockoutThreshold) && !vent.IsPressureLockoutManuallyDisabled;
if (vent.UnderPressureLockout != lockout) // update visuals only if this changes
{
vent.UnderPressureLockout = lockout;
Expand Down Expand Up @@ -115,7 +126,7 @@ private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, ref
var transferMoles = pressureDelta * environment.Volume / (pipe.Air.Temperature * Atmospherics.R);

// Only run if the device is under lockout and not being overriden
if (vent.UnderPressureLockout & !vent.PressureLockoutOverride)
if (vent.UnderPressureLockout & !vent.PressureLockoutOverride & !vent.IsPressureLockoutManuallyDisabled)
{
// Leak only a small amount of gas as a proportion of supply pipe pressure.
var pipeDelta = pipe.Air.Pressure - environment.Pressure;
Expand Down Expand Up @@ -273,7 +284,7 @@ private void UpdateState(EntityUid uid, GasVentPumpComponent vent, AppearanceCom
}
else if (vent.PumpDirection == VentPumpDirection.Releasing)
{
if (vent.UnderPressureLockout & !vent.PressureLockoutOverride)
if (vent.UnderPressureLockout & !vent.PressureLockoutOverride & !vent.IsPressureLockoutManuallyDisabled)
_appearance.SetData(uid, VentPumpVisuals.State, VentPumpState.Lockout, appearance);
else
_appearance.SetData(uid, VentPumpVisuals.State, VentPumpState.Out, appearance);
Expand All @@ -290,7 +301,7 @@ private void OnExamine(EntityUid uid, GasVentPumpComponent component, ExaminedEv
return;
if (args.IsInDetailsRange)
{
if (pumpComponent.PumpDirection == VentPumpDirection.Releasing & pumpComponent.UnderPressureLockout & !pumpComponent.PressureLockoutOverride)
if (pumpComponent.PumpDirection == VentPumpDirection.Releasing & pumpComponent.UnderPressureLockout & !pumpComponent.PressureLockoutOverride & !pumpComponent.IsPressureLockoutManuallyDisabled)
{
args.PushMarkup(Loc.GetString("gas-vent-pump-uvlo"));
}
Expand Down Expand Up @@ -325,5 +336,25 @@ private void OnWeldChanged(EntityUid uid, GasVentPumpComponent component, ref We
{
UpdateState(uid, component);
}
private void OnInteractUsing(EntityUid uid, GasVentPumpComponent component, InteractUsingEvent args)
{
if (args.Handled
|| component.UnderPressureLockout == false
|| !_toolSystem.HasQuality(args.Used, "Screwing")
|| (!CompOrNull<TransformComponent>(uid)?.Anchored ?? false) // If component doesn't exist continue, else check for anchor, stops it from eating the deconstruction screwdrivering
PotentiallyTom marked this conversation as resolved.
Show resolved Hide resolved
)
{
return;
}

args.Handled = true;

_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, component.ManualLockoutDisableDoAfter, new VentScrewedDoAfterEvent(), uid, uid, args.Used));
}
private void OnVentScrewed(EntityUid uid, GasVentPumpComponent component, VentScrewedDoAfterEvent args)
{
component.ManualLockoutReenabledAt = _timing.CurTime + component.ManualLockoutDisabledDuration;
component.IsPressureLockoutManuallyDisabled = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;

namespace Content.Shared.Atmos.Piping.Unary;

[Serializable, NetSerializable]
public sealed partial class VentScrewedDoAfterEvent : SimpleDoAfterEvent
{
}
Loading