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 @@ -58,6 +58,30 @@ public sealed partial class GasVentPumpComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField("underPressureLockoutLeaking")]
public float UnderPressureLockoutLeaking = 0.0001f;
/// <summary>
/// Is the vent pressure lockout currently manually disabled?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("forceLockoutDisabled")]
PotentiallyTom marked this conversation as resolved.
Show resolved Hide resolved
public bool IsPressureLockoutManuallyDisabled = false;
/// <summary>
/// The time when the manual pressure lockout override occured.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("manualLockoutDisabledAt")]
public TimeSpan ManualLockoutDisabledAt;
PotentiallyTom marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// How long the lockout should remain manually disabled after being interacted with (in seconds).
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("manualLockoutDisabledDuration")]
public float ManualLockoutDisabledDuration = 30.0f; // Enough time to fill a 5x5 room
/// <summary>
/// How long the doAfter should take when attempting to manually disable the pressure lockout.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("manualLockoutDisableDoAfter")]
public float ManualLockoutDisableDoAfter = 2.0f;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("externalPressureBound")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
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.Tools.Systems;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;

namespace Content.Server.Atmos.Piping.Unary.EntitySystems
{
Expand All @@ -34,7 +39,9 @@ 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!;
public override void Initialize()
{
base.Initialize();
Expand All @@ -50,6 +57,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,10 +89,15 @@ private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, ref
return;
}

if (vent.IsPressureLockoutManuallyDisabled && (_timing.CurTime - vent.ManualLockoutDisabledAt).TotalSeconds > vent.ManualLockoutDisabledDuration)
PotentiallyTom marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -114,7 +128,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 @@ -272,7 +286,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 @@ -289,7 +303,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 @@ -324,5 +338,24 @@ private void OnWeldChanged(EntityUid uid, GasVentPumpComponent component, ref We
{
UpdateState(uid, component);
}
private void OnInteractUsing(EntityUid uid, GasVentPumpComponent component, InteractUsingEvent args)
{
if (args.Handled
|| !_toolSystem.HasQuality(args.Used, "Screwing")
|| component.UnderPressureLockout == false
)
{
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.ManualLockoutDisabledAt = _timing.CurTime;
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