Gas Tanks no longer use NodeContainer, Gas Canisters no longer use passive gates.

This commit is contained in:
Vera Aguilera Puerto
2021-06-23 12:02:28 +02:00
parent 263c9ef974
commit 34e457b854
7 changed files with 93 additions and 149 deletions

View File

@@ -48,35 +48,7 @@ namespace Content.Server.Atmos.Components
[ViewVariables] private BoundUserInterface? _userInterface;
[ViewVariables]
public GasMixture Air
{
// TODO ATMOS Kill it with fire.
get
{
if (!Owner.TryGetComponent(out NodeContainerComponent nodeContainer))
throw new InvalidOperationException("Can't get tank air without a node container!");
if (!nodeContainer.TryGetNode(TankName, out PipeNode? node))
throw new InvalidOperationException($"Node container doesn't have a pipenode called {TankName}!");
return node.Air;
}
set
{
// This will throw if the node container is not found.
var nodeContainer = Owner.GetComponent<NodeContainerComponent>();
if (!nodeContainer.TryGetNode(TankName, out PipeNode? node))
throw new InvalidOperationException($"Node container doesn't have a pipenode called {TankName}!");
node.Air = value;
}
}
[DataField("air")] [ViewVariables]
public GasMixture InitialMixture { get; set; } = new();
[DataField("air")] [ViewVariables] public GasMixture Air { get; set; } = new();
/// <summary>
/// Distributed pressure.
@@ -119,12 +91,6 @@ namespace Content.Server.Atmos.Components
[DataField("tankFragmentScale")]
public float TankFragmentScale { get; set; } = 10 * Atmospherics.OneAtmosphere;
/// <summary>
/// NodeContainer node.
/// </summary>
[DataField("tank")]
public string TankName { get; set; } = "tank";
protected override void Initialize()
{
base.Initialize();

View File

@@ -0,0 +1,32 @@
using Content.Server.Atmos.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Atmos.EntitySystems
{
[UsedImplicitly]
public class GasTankSystem : EntitySystem
{
private const float TimerDelay = 0.5f;
private float _timer = 0f;
public override void Update(float frameTime)
{
base.Update(frameTime);
_timer += frameTime;
if (_timer < TimerDelay) return;
_timer -= TimerDelay;
var atmosphereSystem = Get<AtmosphereSystem>();
foreach (var gasTank in EntityManager.ComponentManager.EntityQuery<GasTankComponent>())
{
atmosphereSystem.React(gasTank.Air, gasTank);
gasTank.CheckStatus();
gasTank.UpdateUserInterface();
}
}
}
}

View File

@@ -3,7 +3,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Atmos.Piping.Binary.Components
namespace Content.Server.Atmos.Piping.Unary.Components
{
[RegisterComponent]
public class GasCanisterComponent : Component
@@ -14,10 +14,6 @@ namespace Content.Server.Atmos.Piping.Binary.Components
[DataField("port")]
public string PortName { get; set; } = "port";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("tank")]
public string TankName { get; set; } = "tank";
/// <summary>
/// Container name for the gas tank holder.
/// </summary>
@@ -45,8 +41,22 @@ namespace Content.Server.Atmos.Piping.Binary.Components
/// <summary>
/// Maximum release pressure possible for the release valve.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[ViewVariables(VVAccess.ReadWrite)]
[DataField("maxReleasePressure")]
public float MaxReleasePressure { get; set; } = Atmospherics.OneAtmosphere * 10;
/// <summary>
/// Valve release pressure.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("releasePressure")]
public float ReleasePressure { get; set; } = Atmospherics.OneAtmosphere;
/// <summary>
/// Whether the release valve is open on the canister.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("releaseValve")]
public bool ReleaseValve { get; set; } = false;
}
}

View File

@@ -3,6 +3,7 @@ using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Piping.Binary.Components;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.Unary.Components;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.Hands.Components;
using Content.Server.NodeContainer;
@@ -18,7 +19,7 @@ using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
namespace Content.Server.Atmos.Piping.Binary.EntitySystems
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
{
[UsedImplicitly]
public class GasCanisterSystem : EntitySystem
@@ -42,6 +43,18 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
if(canister.Owner.GetUIOrNull(GasCanisterUiKey.Key) is {} ui)
ui.OnReceiveMessage += msg => OnCanisterUIMessage(uid, canister, msg);
// Ensure container manager.
if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
{
containerManager = ComponentManager.AddComponent<ContainerManagerComponent>(EntityManager.GetEntity(uid));
}
// Ensure container.
if (!containerManager.TryGetContainer(canister.ContainerName, out _))
{
containerManager.MakeContainer<ContainerSlot>(canister.ContainerName);
}
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return;
@@ -59,10 +72,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
{
if (!ComponentManager.TryGetComponent(uid, out IMetaDataComponent? metadata)
|| !ComponentManager.TryGetComponent(uid, out GasCanisterComponent? canister)
|| !ComponentManager.TryGetComponent(uid, out GasPassiveGateComponent? passiveGate)
|| !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode)
|| !nodeContainer.TryGetNode(canister.TankName, out PipeNode? tankNode)
|| !ComponentManager.TryGetComponent(uid, out ServerUserInterfaceComponent? userInterfaceComponent)
|| !userInterfaceComponent.TryGetBoundUserInterface(GasCanisterUiKey.Key, out var ui))
return;
@@ -73,13 +84,14 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
if (ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) && containerManager.TryGetContainer(canister.ContainerName, out var tankContainer) && tankContainer.ContainedEntities.Count > 0)
{
var tank = tankContainer.ContainedEntities[0];
var tankComponent = tank.GetComponent<GasTankComponent>();
tankLabel = tank.Name;
tankPressure = tankNode.Air.Pressure;
tankPressure = tankComponent.Air.Pressure;
}
ui.SetState(new GasCanisterBoundUserInterfaceState(metadata.EntityName, portNode.Air.Pressure,
portNode.NodeGroup.Nodes.Count > 1, tankLabel, tankPressure,
passiveGate.TargetPressure, passiveGate.Enabled,
canister.ReleasePressure, canister.ReleaseValve,
canister.MinReleasePressure, canister.MaxReleasePressure));
}
@@ -91,8 +103,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
return;
if (!ComponentManager.TryGetComponent(uid, out GasPassiveGateComponent? passiveGate)
|| !ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)
if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)
|| !containerManager.TryGetContainer(canister.ContainerName, out var container))
return;
@@ -108,12 +119,12 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
case GasCanisterChangeReleasePressureMessage changeReleasePressure:
var pressure = Math.Clamp(changeReleasePressure.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure);
passiveGate.TargetPressure = pressure;
canister.ReleasePressure = pressure;
DirtyUI(uid);
break;
case GasCanisterChangeReleaseValveMessage changeReleaseValve:
passiveGate.Enabled = changeReleaseValve.Valve;
canister.ReleaseValve = changeReleaseValve.Valve;
DirtyUI(uid);
break;
}
@@ -122,12 +133,34 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args)
{
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|| !ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
return;
if (!nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode))
return;
// Release valve is open, release gas.
if (canister.ReleaseValve)
{
if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)
|| !containerManager.TryGetContainer(canister.ContainerName, out var container))
return;
var atmosphereSystem = Get<AtmosphereSystem>();
if (container.ContainedEntities.Count > 0)
{
var gasTank = container.ContainedEntities[0].GetComponent<GasTankComponent>();
atmosphereSystem.ReleaseGasTo(portNode.Air, gasTank.Air, canister.ReleasePressure);
}
else
{
var tileAtmosphere = canister.Owner.Transform.Coordinates.GetTileAtmosphere();
atmosphereSystem.ReleaseGasTo(portNode.Air, tileAtmosphere?.Air, canister.ReleasePressure);
tileAtmosphere?.Invalidate();
}
}
DirtyUI(uid);
// Nothing to do here.
@@ -183,8 +216,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
return;
// Check the used item is valid...
if (!args.Used.TryGetComponent(out GasTankComponent? _)
|| !args.Used.TryGetComponent(out NodeContainerComponent? _))
if (!args.Used.TryGetComponent(out GasTankComponent? _))
return;
// Check the user has hands.
@@ -207,14 +239,6 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
DirtyUI(uid);
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(component.TankName, out PipeNode? tankNode))
return;
tankNode.EnvironmentalAir = false;
tankNode.ConnectToContainedEntities = true;
tankNode.NodeGroup.RemakeGroup();
if (!ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
return;
@@ -228,14 +252,6 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
DirtyUI(uid);
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(component.TankName, out PipeNode? tankNode))
return;
tankNode.NodeGroup.RemakeGroup();
tankNode.ConnectToContainedEntities = false;
tankNode.EnvironmentalAir = true;
if (!ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
return;

View File

@@ -1,58 +0,0 @@
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.NodeContainer;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
{
[UsedImplicitly]
public class GasTankSystem : EntitySystem
{
private const float TimerDelay = 0.5f;
private float _timer = 0f;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasTankComponent, ComponentStartup>(OnTankStartup);
}
private void OnTankStartup(EntityUid uid, GasTankComponent tank, ComponentStartup args)
{
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return;
if (!nodeContainer.TryGetNode(tank.TankName, out PipeNode? tankNode))
return;
// Create a pipenet if we don't have one already.
tankNode.TryAssignGroupIfNeeded();
tankNode.AssumeAir(tank.InitialMixture);
tankNode.Volume = tank.InitialMixture.Volume;
tankNode.Air.Volume = tank.InitialMixture.Volume;
tankNode.Air.Temperature = tank.InitialMixture.Temperature;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
_timer += frameTime;
if (_timer < TimerDelay) return;
_timer -= TimerDelay;
var atmosphereSystem = Get<AtmosphereSystem>();
foreach (var gasTank in EntityManager.ComponentManager.EntityQuery<GasTankComponent>(true))
{
atmosphereSystem.React(gasTank.Air, gasTank);
gasTank.CheckStatus();
gasTank.UpdateUserInterface();
}
}
}
}

View File

@@ -71,21 +71,8 @@
needAnchored: false
rotationsEnabled: false
volume: 1000
tank:
!type:PipeNode
nodeGroupID: Pipe
pipeDirection: None
needAnchored: false
connectToContainedEntities: false
environmentalAir: true
rotationsEnabled: false
volume: 1
- type: GasPortable
- type: GasCanister
- type: GasPassiveGate
enabled: false
inlet: port
outlet: tank
- type: entity
parent: GasCanister

View File

@@ -13,15 +13,6 @@
- type: Clothing
sprite: Objects/Tanks/generic.rsi
QuickEquip: false
- type: NodeContainer
nodes:
tank:
!type:PipeNode
nodeGroupID: Pipe
pipeDirection: None
connectionsEnabled: false
needAnchored: false
rotationsEnabled: false
- type: GasTank
- type: ItemActions
actions: