PressureSiphonComponent (#2118)

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2020-09-22 04:05:06 -06:00
committed by GitHub
parent 759aefee7b
commit edebe9036c
4 changed files with 59 additions and 25 deletions

View File

@@ -155,12 +155,10 @@
"AMEPart",
"AMEFuelContainer",
"AMEShield",
"DebugPump",
"PressurePump",
"PressureVent",
"VolumePump",
"DebugVent",
"DebugSiphon",
"PressureSiphon",
"SignalReceiver",
"SignalSwitch",
"SignalTransmitter",

View File

@@ -1,21 +0,0 @@
using Content.Server.Atmos;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers
{
/// <summary>
/// Placeholder example of scrubber functionality.
/// </summary>
[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();
}
}
}

View File

@@ -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";
/// <summary>
/// The pressure this siphon will try to bring its inlet too.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float SiphonPressureTarget
{
get => _siphonPressureTarget;
set => _siphonPressureTarget = Math.Max(value, 0);
}
private float _siphonPressureTarget;
/// <summary>
/// Every update, this siphon will only decrease the inlet pressure by this fraction of the amount needed to reach the <see cref="SiphonPressureTarget"/>.
/// </summary>
[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);
}
}
}

View File

@@ -35,5 +35,5 @@
- !type:PipeNode
nodeGroID: Pipe
pipeDirection: South
- type: DebugSiphon
- type: PressureSiphon
scrubberOutletDirection: South