Skip to content

Commit

Permalink
Keep pipe changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyyapril committed Nov 14, 2024
1 parent e3a2610 commit ad90905
Showing 1 changed file with 15 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.Trinary.Components;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos.Piping;
Expand All @@ -13,7 +11,6 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
[UsedImplicitly]
public sealed class PressureControlledValveSystem : EntitySystem
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
Expand All @@ -40,39 +37,26 @@ private void OnUpdate(EntityUid uid, PressureControlledValveComponent comp, ref
return;
}

// If output is higher than input, flip input/output to enable bidirectional flow.
if (outletNode.Air.Pressure > inletNode.Air.Pressure)
{
PipeNode temp = outletNode;
outletNode = inletNode;
inletNode = temp;
}

float control = (controlNode.Air.Pressure - outletNode.Air.Pressure) - comp.Threshold;
float transferRate;
if (control < 0)
{
comp.Enabled = false;
transferRate = 0;
}
else
// If the pressure in either inlet or outlet exceeds the side pressure, act as an open pipe.
if (!comp.Enabled && (controlNode.Air.Pressure < inletNode.Air.Pressure
|| controlNode.Air.Pressure < outletNode.Air.Pressure))
{
inletNode.AddAlwaysReachable(outletNode);
outletNode.AddAlwaysReachable(inletNode);
comp.Enabled = true;
transferRate = Math.Min(control * comp.Gain, comp.MaxTransferRate * _atmosphereSystem.PumpSpeedup());
UpdateAppearance(uid, comp);
_ambientSoundSystem.SetAmbience(uid, true);
return;
}
UpdateAppearance(uid, comp);

// We multiply the transfer rate in L/s by the seconds passed since the last process to get the liters.
var transferVolume = transferRate * args.dt;
if (transferVolume <= 0)
{
_ambientSoundSystem.SetAmbience(uid, false);
if (!comp.Enabled)
return;
}

_ambientSoundSystem.SetAmbience(uid, true);
var removed = inletNode.Air.RemoveVolume(transferVolume);
_atmosphereSystem.Merge(outletNode.Air, removed);
inletNode.RemoveAlwaysReachable(outletNode);
outletNode.RemoveAlwaysReachable(inletNode);
comp.Enabled = false;
UpdateAppearance(uid, comp);
_ambientSoundSystem.SetAmbience(uid, false);
}

private void OnFilterLeaveAtmosphere(EntityUid uid, PressureControlledValveComponent comp, ref AtmosDeviceDisabledEvent args)
Expand All @@ -90,4 +74,4 @@ private void UpdateAppearance(EntityUid uid, PressureControlledValveComponent? c
_appearance.SetData(uid, FilterVisuals.Enabled, comp.Enabled, appearance);
}
}
}
}

0 comments on commit ad90905

Please sign in to comment.