* First pass * Fix access and rename banananium to bananium * Fix captialization of CookTimeInfoLabel * Fix InteractUsing calls * Remove unused [Dependency] * Replace obsolete references to Anchored with BodyType * Assign default value to shoving someone in disposals * Fix naming * Replace Initialize TryGetComponents with EnsureComponent * Rework AnchorableComponent * Fix singularity component * Replace obsolete usages of Angle.South * Fix efcore warning * Fix container tests * Fix DebugPressurePump invalid PressurePump yaml * Fix getting pathfinding region of grid 0 * Fix atmos plaque missing layer and add info message when it happens * Fix AiSteeringSystem steering in an invalid grid in entity test * Make content able to choose which log level leads to test failures * Revert container test fix for Acruid * Fix sprite, pipe and saving errors Make EntityTest print all errors instead of stopping on the first * Reorder singularity visualizer * Disable pvs for container occlusion adn simple predict reconcile, they use entities other than map ones Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
#nullable enable
|
|
using System.Linq;
|
|
using Content.Server.Atmos;
|
|
using Content.Server.GameObjects.Components.NodeContainer;
|
|
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
|
using Content.Shared.GameObjects.Components.Atmos;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
|
|
{
|
|
/// <summary>
|
|
/// Transfer gas from one <see cref="PipeNode"/> to another.
|
|
/// </summary>
|
|
public abstract class BasePumpComponent : Component, IActivate
|
|
{
|
|
/// <summary>
|
|
/// If the pump is currently pumping.
|
|
/// </summary>
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public bool PumpEnabled
|
|
{
|
|
get => _pumpEnabled;
|
|
set
|
|
{
|
|
_pumpEnabled = value;
|
|
UpdateAppearance();
|
|
}
|
|
}
|
|
|
|
[DataField("pumpEnabled")]
|
|
private bool _pumpEnabled;
|
|
|
|
/// <summary>
|
|
/// Needs to be same <see cref="PipeDirection"/> as that of a <see cref="PipeNode"/> on this entity.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
[DataField("initialInletDirection", required: true)]
|
|
private PipeDirection _initialInletDirection = PipeDirection.None;
|
|
|
|
/// <summary>
|
|
/// Needs to be same <see cref="PipeDirection"/> as that of a <see cref="PipeNode"/> on this entity.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
[DataField("initialOutletDirection", required: true)]
|
|
private PipeDirection _initialOutletDirection = PipeDirection.None;
|
|
|
|
[ViewVariables]
|
|
private PipeNode? _inletPipe;
|
|
|
|
[ViewVariables]
|
|
private PipeNode? _outletPipe;
|
|
|
|
private AppearanceComponent? _appearance;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
Owner.EnsureComponentWarn<PipeNetDeviceComponent>();
|
|
SetPipes();
|
|
Owner.TryGetComponent(out _appearance);
|
|
UpdateAppearance();
|
|
}
|
|
|
|
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
|
{
|
|
base.HandleMessage(message, component);
|
|
switch (message)
|
|
{
|
|
case PipeNetUpdateMessage:
|
|
Update();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (!PumpEnabled)
|
|
return;
|
|
|
|
if (_inletPipe == null || _outletPipe == null)
|
|
return;
|
|
|
|
PumpGas(_inletPipe.Air, _outletPipe.Air);
|
|
}
|
|
|
|
protected abstract void PumpGas(GasMixture inletGas, GasMixture outletGas);
|
|
|
|
private void UpdateAppearance()
|
|
{
|
|
if (_inletPipe == null || _outletPipe == null) return;
|
|
_appearance?.SetData(PumpVisuals.VisualState, new PumpVisualState(_initialInletDirection, _initialOutletDirection, PumpEnabled));
|
|
}
|
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
|
{
|
|
PumpEnabled = !PumpEnabled;
|
|
}
|
|
|
|
private void SetPipes()
|
|
{
|
|
_inletPipe = null;
|
|
_outletPipe = null;
|
|
|
|
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
|
|
{
|
|
Logger.Warning($"{nameof(BasePumpComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}.");
|
|
return;
|
|
}
|
|
var pipeNodes = container.Nodes.OfType<PipeNode>();
|
|
_inletPipe = pipeNodes.Where(pipe => pipe.PipeDirection == _initialInletDirection).FirstOrDefault();
|
|
_outletPipe = pipeNodes.Where(pipe => pipe.PipeDirection == _initialOutletDirection).FirstOrDefault();
|
|
if (_inletPipe == null || _outletPipe == null)
|
|
{
|
|
Logger.Warning($"{nameof(BasePumpComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|