From edebe9036ce3012968d3aaaeff7ce979f69845ad Mon Sep 17 00:00:00 2001 From: py01 <60152240+collinlunn@users.noreply.github.com> Date: Tue, 22 Sep 2020 04:05:06 -0600 Subject: [PATCH] PressureSiphonComponent (#2118) Co-authored-by: py01 --- Content.Client/IgnoredComponents.cs | 4 +- .../Piping/Scrubbers/DebugSiphonComponent.cs | 21 ------- .../Atmos/Piping/Scrubbers/PressureSiphon.cs | 57 +++++++++++++++++++ .../Constructible/Ground/scrubbers.yml | 2 +- 4 files changed, 59 insertions(+), 25 deletions(-) delete mode 100644 Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/DebugSiphonComponent.cs create mode 100644 Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/PressureSiphon.cs diff --git a/Content.Client/IgnoredComponents.cs b/Content.Client/IgnoredComponents.cs index 4c284fb026..fe100bfa17 100644 --- a/Content.Client/IgnoredComponents.cs +++ b/Content.Client/IgnoredComponents.cs @@ -155,12 +155,10 @@ "AMEPart", "AMEFuelContainer", "AMEShield", - "DebugPump", "PressurePump", "PressureVent", "VolumePump", - "DebugVent", - "DebugSiphon", + "PressureSiphon", "SignalReceiver", "SignalSwitch", "SignalTransmitter", diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/DebugSiphonComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/DebugSiphonComponent.cs deleted file mode 100644 index ddfdb1b512..0000000000 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/DebugSiphonComponent.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Content.Server.Atmos; -using Robust.Shared.GameObjects; - -namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers -{ - /// - /// Placeholder example of scrubber functionality. - /// - [RegisterComponent] - [ComponentReference(typeof(BaseSiphonComponent))] - public class DebugSiphonComponent : BaseSiphonComponent - { - public override string Name => "DebugSiphon"; - - protected override void ScrubGas(GasMixture inletGas, GasMixture outletGas) - { - outletGas.Merge(inletGas); - inletGas.Clear(); - } - } -} diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/PressureSiphon.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/PressureSiphon.cs new file mode 100644 index 0000000000..a48537d6f5 --- /dev/null +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/PressureSiphon.cs @@ -0,0 +1,57 @@ +using System; +using Content.Server.Atmos; +using Content.Shared.Atmos; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; + +namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers +{ + [RegisterComponent] + [ComponentReference(typeof(BaseSiphonComponent))] + public class PressureSiphonComponent : BaseSiphonComponent + { + public override string Name => "PressureSiphon"; + + /// + /// The pressure this siphon will try to bring its inlet too. + /// + [ViewVariables(VVAccess.ReadWrite)] + public float SiphonPressureTarget + { + get => _siphonPressureTarget; + set => _siphonPressureTarget = Math.Max(value, 0); + } + private float _siphonPressureTarget; + + /// + /// Every update, this siphon will only decrease the inlet pressure by this fraction of the amount needed to reach the . + /// + [ViewVariables(VVAccess.ReadWrite)] + public float TransferRatio + { + get => _transferRatio; + set => _transferRatio = Math.Clamp(value, 0, 1); + } + private float _transferRatio; + + public override void ExposeData(ObjectSerializer serializer) + { + base.ExposeData(serializer); + serializer.DataField(ref _siphonPressureTarget, "startingSiphonPressureTarget", Atmospherics.OneAtmosphere * 2); + serializer.DataField(ref _transferRatio, "transferRatio", 0.5f); + } + + protected override void ScrubGas(GasMixture inletGas, GasMixture outletGas) + { + var goalDiff = SiphonPressureTarget - inletGas.Pressure; + var realGoalPressureDiff = goalDiff * TransferRatio; + + var moleRatioToTransfer = 1 - (inletGas.Pressure + realGoalPressureDiff) / inletGas.Pressure; + moleRatioToTransfer = Math.Clamp(moleRatioToTransfer, 0, 1); + + var transferedGas = inletGas.RemoveRatio(moleRatioToTransfer); + outletGas.Merge(transferedGas); + } + } +} diff --git a/Resources/Prototypes/Entities/Constructible/Ground/scrubbers.yml b/Resources/Prototypes/Entities/Constructible/Ground/scrubbers.yml index fcb270dd43..5982e61853 100644 --- a/Resources/Prototypes/Entities/Constructible/Ground/scrubbers.yml +++ b/Resources/Prototypes/Entities/Constructible/Ground/scrubbers.yml @@ -35,5 +35,5 @@ - !type:PipeNode nodeGroID: Pipe pipeDirection: South - - type: DebugSiphon + - type: PressureSiphon scrubberOutletDirection: South