2021-01-28 20:20:13 -06:00
#nullable enable
using System ;
2020-09-13 14:23:52 +02:00
using Content.Server.Atmos ;
2021-02-04 09:47:04 +00:00
using Content.Shared.Interfaces.GameObjects.Components ;
2020-08-30 18:13:23 -06:00
using Robust.Shared.GameObjects ;
2021-03-05 01:08:38 +01:00
using Robust.Shared.Prototypes ;
2020-08-30 18:13:23 -06:00
using Robust.Shared.Serialization ;
2021-03-05 01:08:38 +01:00
using Robust.Shared.Serialization.Manager.Attributes ;
2020-08-30 18:13:23 -06:00
using Robust.Shared.ViewVariables ;
namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
{
[RegisterComponent]
[ComponentReference(typeof(BasePumpComponent))]
2021-02-04 09:47:04 +00:00
[ComponentReference(typeof(IActivate))]
2020-08-30 18:13:23 -06:00
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 ) ;
}
2021-03-05 01:08:38 +01:00
[DataField("startingPressurePumpTarget")]
2020-08-30 18:13:23 -06:00
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 ) ;
}
2021-03-05 01:08:38 +01:00
[DataField("maxPressurePumpTarget")]
private int _maxPressurePumpTarget = 100 ;
2020-08-30 18:13:23 -06:00
/// <summary>
2020-09-16 05:47:47 -06:00
/// Every update, this pump will only increase the outlet pressure by this fraction of the amount needed to reach the <see cref="PressurePumpTarget"/>.
2020-08-30 18:13:23 -06:00
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float TransferRatio
{
get = > _transferRatio ;
set = > _transferRatio = Math . Clamp ( value , 0 , 1 ) ;
}
2021-03-05 01:08:38 +01:00
[DataField("transferRatio")]
private float _transferRatio = 0.5f ;
2020-08-30 18:13:23 -06:00
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 ) ;
}
}
}