Skip to content

Commit

Permalink
Update PressureControlledValveSystem.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Nov 1, 2024
1 parent 9294ab2 commit f1b0547
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,24 @@ private void OnUpdate(EntityUid uid, PressureControlledValveComponent comp, ref
return;
}

// If inlet pressure is greater than reference pressure, transfer air from inlet to outlet.
if (controlNode.Air.Pressure > inletNode.Air.Pressure)
return;

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

inletNode.AddAlwaysReachable(outletNode);
outletNode.AddAlwaysReachable(inletNode);

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

private void OnFilterLeaveAtmosphere(EntityUid uid, PressureControlledValveComponent comp, ref AtmosDeviceDisabledEvent args)
Expand Down

0 comments on commit f1b0547

Please sign in to comment.