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

Smart gas vents, open/close with approximate derivative of external pressure #35489

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ public sealed partial class GasVentPumpComponent : Component
[DataField]
public bool UnderPressureLockout { get; set; } = false;

[DataField]
public float VelocityPressureLockoutValue { get; set; } = 1.0f;

[DataField]
public bool VelocityPressureLockoutEnabled { get; set; } = true;

public float VelocityPressureModifier => VelocityPressureLockoutEnabled && !PressureLockoutOverride ? VelocityPressureLockoutValue : 1.0f;

[DataField]
public float VelocityPressureValueMin { get; set; } = 0.0001f;

[DataField]
public float PreviousPressure { get; set; } = 0.0f;

[DataField]
public float VelocityPressureAcceleration { get; set; } = 2.0f;

/// <summary>
/// In releasing mode, do not pump when environment pressure is below this limit.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, ref
var timeDelta = args.dt;
var pressureDelta = timeDelta * vent.TargetPressureChange;

var lockout = (environment.Pressure < vent.UnderPressureLockoutThreshold) && !vent.IsPressureLockoutManuallyDisabled;
var lockout = !vent.IsPressureLockoutManuallyDisabled && (vent.VelocityPressureLockoutEnabled
? vent.VelocityPressureLockoutValue <= vent.VelocityPressureValueMin
: environment.Pressure < vent.UnderPressureLockoutThreshold);
if (vent.UnderPressureLockout != lockout) // update visuals only if this changes
{
vent.UnderPressureLockout = lockout;
Expand Down Expand Up @@ -130,10 +132,10 @@ private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, ref

// how many moles to transfer to change external pressure by pressureDelta
// (ignoring temperature differences because I am lazy)
var transferMoles = pressureDelta * environment.Volume / (pipe.Air.Temperature * Atmospherics.R);
var transferMoles = pressureDelta * environment.Volume / (pipe.Air.Temperature * Atmospherics.R) * vent.VelocityPressureModifier;

// Only run if the device is under lockout and not being overriden
if (vent.UnderPressureLockout & !vent.PressureLockoutOverride & !vent.IsPressureLockoutManuallyDisabled)
if (!vent.VelocityPressureLockoutEnabled && 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 All @@ -150,11 +152,25 @@ private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, ref
if (internalDelta <= 0)
return;

var maxTransfer = internalDelta * pipe.Air.Volume / (pipe.Air.Temperature * Atmospherics.R);
var maxTransfer = internalDelta * pipe.Air.Volume / (pipe.Air.Temperature * Atmospherics.R) * vent.VelocityPressureModifier;
transferMoles = MathF.Min(transferMoles, maxTransfer);
}

var curPressure = environment.Pressure;
_atmosphereSystem.Merge(environment, pipe.Air.Remove(transferMoles));
if (vent.VelocityPressureLockoutEnabled)
{
var deltaP = curPressure - vent.PreviousPressure;
// Bias towards opening the valve, increase acceleration if pressure is increasing
// Will add an acceleration and deceleration parameter later
var delta = deltaP * (vent.VelocityPressureAcceleration / pressureDelta) * (deltaP < 0 ? 1.0f : 10.0f);

vent.VelocityPressureLockoutValue =
Math.Clamp(vent.VelocityPressureLockoutValue + delta,
vent.VelocityPressureValueMin, 1.0f);

vent.PreviousPressure = curPressure;
}
}
else if (vent.PumpDirection == VentPumpDirection.Siphoning && environment.Pressure > 0)
{
Expand Down Expand Up @@ -349,6 +365,10 @@ private void OnExamine(EntityUid uid, GasVentPumpComponent component, ExaminedEv
{
args.PushMarkup(Loc.GetString("gas-vent-pump-uvlo"));
}
if(pumpComponent.VelocityPressureLockoutEnabled)
{
args.PushMarkup(Loc.GetString("gas-vent-pump-close-value", ("percent", (int)(pumpComponent.VelocityPressureLockoutValue*100))));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/atmos/gas-vent-pump.ftl
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gas-vent-pump-uvlo = It is in [color=red]under-pressure lock out[/color].
gas-vent-pump-close-value = It is [color=yellow]{$percent}%[/color] opened.