From 34e457b85479b56d71201574c7c24473b50468cf Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Wed, 23 Jun 2021 12:02:28 +0200 Subject: [PATCH] Gas Tanks no longer use NodeContainer, Gas Canisters no longer use passive gates. --- .../Atmos/Components/GasTankComponent.cs | 36 +--------- .../Atmos/EntitySystems/GasTankSystem.cs | 32 +++++++++ .../Components/GasCanisterComponent.cs | 22 ++++-- .../EntitySystems/GasCanisterSystem.cs | 72 +++++++++++-------- .../Unary/EntitySystems/GasTankSystem.cs | 58 --------------- .../Piping/Atmospherics/gas_canisters.yml | 13 ---- .../Entities/Objects/Tools/gas_tanks.yml | 9 --- 7 files changed, 93 insertions(+), 149 deletions(-) create mode 100644 Content.Server/Atmos/EntitySystems/GasTankSystem.cs rename Content.Server/Atmos/Piping/{Binary => Unary}/Components/GasCanisterComponent.cs (74%) rename Content.Server/Atmos/Piping/{Binary => Unary}/EntitySystems/GasCanisterSystem.cs (80%) delete mode 100644 Content.Server/Atmos/Piping/Unary/EntitySystems/GasTankSystem.cs diff --git a/Content.Server/Atmos/Components/GasTankComponent.cs b/Content.Server/Atmos/Components/GasTankComponent.cs index c57d7518eb..add95c5905 100644 --- a/Content.Server/Atmos/Components/GasTankComponent.cs +++ b/Content.Server/Atmos/Components/GasTankComponent.cs @@ -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(); - - 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(); /// /// Distributed pressure. @@ -119,12 +91,6 @@ namespace Content.Server.Atmos.Components [DataField("tankFragmentScale")] public float TankFragmentScale { get; set; } = 10 * Atmospherics.OneAtmosphere; - /// - /// NodeContainer node. - /// - [DataField("tank")] - public string TankName { get; set; } = "tank"; - protected override void Initialize() { base.Initialize(); diff --git a/Content.Server/Atmos/EntitySystems/GasTankSystem.cs b/Content.Server/Atmos/EntitySystems/GasTankSystem.cs new file mode 100644 index 0000000000..2d3da529e9 --- /dev/null +++ b/Content.Server/Atmos/EntitySystems/GasTankSystem.cs @@ -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(); + + foreach (var gasTank in EntityManager.ComponentManager.EntityQuery()) + { + atmosphereSystem.React(gasTank.Air, gasTank); + gasTank.CheckStatus(); + gasTank.UpdateUserInterface(); + } + } + } +} diff --git a/Content.Server/Atmos/Piping/Binary/Components/GasCanisterComponent.cs b/Content.Server/Atmos/Piping/Unary/Components/GasCanisterComponent.cs similarity index 74% rename from Content.Server/Atmos/Piping/Binary/Components/GasCanisterComponent.cs rename to Content.Server/Atmos/Piping/Unary/Components/GasCanisterComponent.cs index 450dfd321a..d8999b09b2 100644 --- a/Content.Server/Atmos/Piping/Binary/Components/GasCanisterComponent.cs +++ b/Content.Server/Atmos/Piping/Unary/Components/GasCanisterComponent.cs @@ -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"; - /// /// Container name for the gas tank holder. /// @@ -45,8 +41,22 @@ namespace Content.Server.Atmos.Piping.Binary.Components /// /// Maximum release pressure possible for the release valve. /// - [ViewVariables(VVAccess.ReadOnly)] + [ViewVariables(VVAccess.ReadWrite)] [DataField("maxReleasePressure")] public float MaxReleasePressure { get; set; } = Atmospherics.OneAtmosphere * 10; + + /// + /// Valve release pressure. + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("releasePressure")] + public float ReleasePressure { get; set; } = Atmospherics.OneAtmosphere; + + /// + /// Whether the release valve is open on the canister. + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("releaseValve")] + public bool ReleaseValve { get; set; } = false; } } diff --git a/Content.Server/Atmos/Piping/Binary/EntitySystems/GasCanisterSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs similarity index 80% rename from Content.Server/Atmos/Piping/Binary/EntitySystems/GasCanisterSystem.cs rename to Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs index d084826a2c..2cfabfeb1f 100644 --- a/Content.Server/Atmos/Piping/Binary/EntitySystems/GasCanisterSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs @@ -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(EntityManager.GetEntity(uid)); + } + + // Ensure container. + if (!containerManager.TryGetContainer(canister.ContainerName, out _)) + { + containerManager.MakeContainer(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(); 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(); + + if (container.ContainedEntities.Count > 0) + { + var gasTank = container.ContainedEntities[0].GetComponent(); + 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; diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasTankSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasTankSystem.cs deleted file mode 100644 index 6cea9c7f89..0000000000 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasTankSystem.cs +++ /dev/null @@ -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(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(); - - foreach (var gasTank in EntityManager.ComponentManager.EntityQuery(true)) - { - atmosphereSystem.React(gasTank.Air, gasTank); - gasTank.CheckStatus(); - gasTank.UpdateUserInterface(); - } - } - } -} diff --git a/Resources/Prototypes/Entities/Constructible/Piping/Atmospherics/gas_canisters.yml b/Resources/Prototypes/Entities/Constructible/Piping/Atmospherics/gas_canisters.yml index f16535ecc9..c4dcba4396 100644 --- a/Resources/Prototypes/Entities/Constructible/Piping/Atmospherics/gas_canisters.yml +++ b/Resources/Prototypes/Entities/Constructible/Piping/Atmospherics/gas_canisters.yml @@ -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 diff --git a/Resources/Prototypes/Entities/Objects/Tools/gas_tanks.yml b/Resources/Prototypes/Entities/Objects/Tools/gas_tanks.yml index 1d1c2f9de8..4c93eab341 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/gas_tanks.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/gas_tanks.yml @@ -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: