Volume and pressure pump (#1955)

* PressurePump and VolumePump

* VolumePump fix

* PressurePump fix

* volume pump simplification

* Fixes GridAtmosphereComponent not updating pumps

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2020-08-30 18:13:23 -06:00
committed by GitHub
parent 68ec6e6be5
commit 9d5278ab0d
6 changed files with 136 additions and 28 deletions

View File

@@ -163,6 +163,8 @@
"AMEFuelContainer", "AMEFuelContainer",
"AMEShield", "AMEShield",
"DebugPump", "DebugPump",
"PressurePump",
"VolumePump",
"DebugVent", "DebugVent",
"DebugSiphon", "DebugSiphon",
"SignalReceiver", "SignalReceiver",

View File

@@ -755,7 +755,7 @@ namespace Content.Server.GameObjects.Components.Atmos
_currentRunPipeNetDevice = new Queue<PipeNetDeviceComponent>(_pipeNetDevices); _currentRunPipeNetDevice = new Queue<PipeNetDeviceComponent>(_pipeNetDevices);
var number = 0; var number = 0;
while (_currentRunPipeNet.Count > 0) while (_currentRunPipeNetDevice.Count > 0)
{ {
var device = _currentRunPipeNetDevice.Dequeue(); var device = _currentRunPipeNetDevice.Dequeue();
device.Update(); device.Update();

View File

@@ -1,21 +0,0 @@
using Content.Server.Atmos;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Placeholder example of pump functionality.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(BasePumpComponent))]
public class DebugPumpComponent : BasePumpComponent
{
public override string Name => "DebugPump";
protected override void PumpGas(GasMixture inletGas, GasMixture outletGas)
{
outletGas.Merge(inletGas);
inletGas.Clear();
}
}
}

View File

@@ -0,0 +1,65 @@
using Content.Server.Atmos;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System;
namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
{
[RegisterComponent]
[ComponentReference(typeof(BasePumpComponent))]
public class PressurePumpComponent : BasePumpComponent
{
public override string Name => "PressurePump";
/// <summary>
/// The pressure this pump will try to bring its oulet too.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public int PressurePumpTarget
{
get => _pressurePumpTarget;
set => _pressurePumpTarget = Math.Clamp(value, 0, MaxPressurePumpTarget);
}
private int _pressurePumpTarget;
/// <summary>
/// Max value <see cref="PressurePumpTarget"/> can be set to.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public int MaxPressurePumpTarget
{
get => _maxPressurePumpTarget;
set => Math.Max(value, 0);
}
private int _maxPressurePumpTarget;
/// <summary>
/// Every upate, this pump will only increase the outlet pressure by this fraction of the amount needed to reach the <see cref="PressurePumpTarget"/>.
/// </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 _pressurePumpTarget, "startingPressurePumpTarget", 0);
serializer.DataField(ref _maxPressurePumpTarget, "maxPressurePumpTarget", 100);
serializer.DataField(ref _transferRatio, "transferRatio", 0.5f);
}
protected override void PumpGas(GasMixture inletGas, GasMixture outletGas)
{
var goalDiff = PressurePumpTarget - outletGas.Pressure;
var realGoalPressureDiff = goalDiff * TransferRatio;
var realTargetPressure = outletGas.Pressure + realGoalPressureDiff;
var realCappedTargetPressure = Math.Max(realTargetPressure, outletGas.Pressure); //no lowering the outlet's pressure
inletGas.PumpGasTo(outletGas, realCappedTargetPressure);
}
}
}

View File

@@ -0,0 +1,46 @@
using Content.Server.Atmos;
using Content.Shared.Atmos;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System;
using System.Diagnostics;
namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
{
[RegisterComponent]
[ComponentReference(typeof(BasePumpComponent))]
public class VolumePumpComponent : BasePumpComponent
{
[ViewVariables(VVAccess.ReadWrite)]
public int VolumePumpRate
{
get => _volumePumpRate;
set => _volumePumpRate = Math.Clamp(value, 0, MaxVolumePumpRate);
}
private int _volumePumpRate;
[ViewVariables(VVAccess.ReadWrite)]
public int MaxVolumePumpRate
{
get => _maxVolumePumpRate;
set => Math.Max(value, 0);
}
private int _maxVolumePumpRate;
public override string Name => "VolumePump";
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _volumePumpRate, "startingVolumePumpRate", 0);
serializer.DataField(ref _maxVolumePumpRate, "maxVolumePumpRate", 100);
}
protected override void PumpGas(GasMixture inletGas, GasMixture outletGas)
{
var volumeRatio = Math.Clamp(VolumePumpRate / inletGas.Volume, 0, 1);
outletGas.Merge(inletGas.RemoveRatio(volumeRatio));
}
}
}

View File

@@ -17,9 +17,9 @@
thresholdvalue: 100 thresholdvalue: 100
- type: entity - type: entity
abstract: true
parent: PumpBase parent: PumpBase
id: NorthFromSouthPipePump id: NorthwardLongitudinalPump
name: North from south pipe pump
components: components:
- type: Sprite - type: Sprite
state: mvcable_3 state: mvcable_3
@@ -27,10 +27,26 @@
nodes: nodes:
- !type:PipeNode - !type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: North pipeDirection: South
- !type:PipeNode - !type:PipeNode
nodeGroupID: Pipe nodeGroupID: Pipe
pipeDirection: South pipeDirection: North
- type: DebugPump
outletDirection: North - type: entity
parent: NorthwardLongitudinalPump
id: NorthwardLongitudinalVolumePump
name: Northward Longitudinal Volume Pump
components:
- type: VolumePump
inletDirection: South inletDirection: South
outletDirection: North
- type: entity
parent: NorthwardLongitudinalPump
id: NorthwardLongitudinalPressurePump
name: Northward Longitudinal Pressure Pump
components:
- type: PressurePump
inletDirection: South
outletDirection: North