GasGeneratorComponent (#3029)

* GasGeneratorComponent

* gas generator sprite

* component comment

* replace the other typeof with nameof

* Update Resources/Textures/Constructible/Atmos/gasgenerator.rsi/meta.json

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Constructible/Ground/gasgenerator.yml

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Content.Server/GameObjects/Components/Atmos/Piping/GasGeneratorComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Atmos/Piping/GasGeneratorComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* specifies physics component

* comments

Co-authored-by: py01 <pyronetics01@gmail.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
This commit is contained in:
py01
2021-01-24 02:42:33 -06:00
committed by GitHub
parent e53ae365a3
commit 72b5ae9468
10 changed files with 175 additions and 10 deletions

View File

@@ -239,7 +239,8 @@ namespace Content.Client
"Recyclable", "Recyclable",
"SecretStash", "SecretStash",
"Toilet", "Toilet",
"ClusterFlash" "ClusterFlash",
"GasGenerator"
}; };
} }
} }

View File

@@ -83,13 +83,13 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
{ {
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container)) if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{ {
Logger.Error($"{typeof(GasCanisterPortComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(GasCanisterPortComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}.");
return; return;
} }
_gasPort = container.Nodes.OfType<PipeNode>().FirstOrDefault(); _gasPort = container.Nodes.OfType<PipeNode>().FirstOrDefault();
if (_gasPort == null) if (_gasPort == null)
{ {
Logger.Error($"{typeof(GasCanisterPortComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(GasCanisterPortComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return; return;
} }
} }

View File

@@ -171,7 +171,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Filters
if (_inletPipe == null || _filterOutletPipe == null || _outletPipe == null) if (_inletPipe == null || _filterOutletPipe == null || _outletPipe == null)
{ {
Logger.Error($"{typeof(GasFilterComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(GasFilterComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return; return;
} }
} }

View File

@@ -0,0 +1,105 @@
#nullable enable
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Shared.Atmos;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System.Linq;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Generates gas in the attached pipe.
/// </summary>
[RegisterComponent]
public class GasGeneratorComponent : Component
{
public override string Name => "GasGenerator";
/// <summary>
/// If the generator is producing gas.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public bool GeneratorEnabled { get; set; }
/// <summary>
/// What gas is being generated.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public Gas GeneratedGas { get; set; }
/// <summary>
/// Molar rate of gas generation.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float GasGenerationRate { get; set; }
/// <summary>
/// The pipe pressure above which the generator stops producing gas.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float GeneratorPressureCap { get; set; }
/// <summary>
/// The pipe to which generated gas is added.
/// </summary>
[ViewVariables]
private PipeNode? Pipe { get; set; }
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(this, x => x.GeneratorEnabled, "generatorEnabled", true);
serializer.DataField(this, x => x.GeneratedGas, "generatedGas", Gas.Oxygen);
serializer.DataField(this, x => x.GasGenerationRate, "gasGenerationRate", 10);
serializer.DataField(this, x => x.GeneratorPressureCap, "generatorPressureCap", 10);
}
public override void Initialize()
{
base.Initialize();
Owner.EnsureComponentWarn<PipeNetDeviceComponent>();
SetPipes();
}
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PipeNetUpdateMessage:
Update();
break;
}
}
private void Update()
{
if (!GeneratorEnabled)
return;
if (Pipe == null || Pipe.Air.Pressure > GeneratorPressureCap)
return;
Pipe.Air.AdjustMoles(GeneratedGas, GasGenerationRate);
}
private void SetPipes()
{
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{
Logger.Error($"{nameof(GasGeneratorComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}.");
return;
}
Pipe = container.Nodes.OfType<PipeNode>().FirstOrDefault();
if (Pipe == null)
{
Logger.Error($"{nameof(GasGeneratorComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return;
}
}
}
}

View File

@@ -107,7 +107,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container)) if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{ {
Logger.Error($"{typeof(BasePumpComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(BasePumpComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}.");
return; return;
} }
var pipeNodes = container.Nodes.OfType<PipeNode>(); var pipeNodes = container.Nodes.OfType<PipeNode>();
@@ -115,7 +115,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
_outletPipe = pipeNodes.Where(pipe => pipe.PipeDirection == _initialOutletDirection).FirstOrDefault(); _outletPipe = pipeNodes.Where(pipe => pipe.PipeDirection == _initialOutletDirection).FirstOrDefault();
if (_inletPipe == null || _outletPipe == null) if (_inletPipe == null || _outletPipe == null)
{ {
Logger.Error($"{typeof(BasePumpComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(BasePumpComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return; return;
} }
} }

View File

@@ -80,13 +80,13 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers
{ {
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container)) if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{ {
Logger.Error($"{typeof(BaseSiphonComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(BaseSiphonComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}.");
return; return;
} }
_scrubberOutlet = container.Nodes.OfType<PipeNode>().FirstOrDefault(); _scrubberOutlet = container.Nodes.OfType<PipeNode>().FirstOrDefault();
if (_scrubberOutlet == null) if (_scrubberOutlet == null)
{ {
Logger.Error($"{typeof(BaseSiphonComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(BaseSiphonComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return; return;
} }
} }

View File

@@ -80,13 +80,13 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents
{ {
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container)) if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{ {
Logger.Error($"{typeof(BaseVentComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(BaseVentComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} did not have a {nameof(NodeContainerComponent)}.");
return; return;
} }
_ventInlet = container.Nodes.OfType<PipeNode>().FirstOrDefault(); _ventInlet = container.Nodes.OfType<PipeNode>().FirstOrDefault();
if (_ventInlet == null) if (_ventInlet == null)
{ {
Logger.Error($"{typeof(BaseVentComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}."); Logger.Error($"{nameof(BaseVentComponent)} on {Owner?.Prototype?.ID}, Uid {Owner?.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return; return;
} }
} }

View File

@@ -0,0 +1,45 @@
- type: entity
abstract: true
id: GasGeneratorBase
placement:
mode: SnapgridCenter
components:
- type: Clickable
- type: InteractionOutline
- type: Physics
anchored: true
shapes:
- !type:PhysShapeAabb
bounds: "-0.5,-0.5,0.5,0.5"
layer:
- Impassable
- MobImpassable
- VaultImpassable
- Opaque
mask:
- Impassable
- MobImpassable
- VaultImpassable
- type: SnapGrid
offset: Center
- type: GasGenerator
- type: entity
parent: GasGeneratorBase
id: GasGenerator
name: gas generator
description: Fabricates gas.
components:
- type: Sprite
netsync: false
sprite: Constructible/Atmos/gasgenerator.rsi
layers:
- sprite: Constructible/Atmos/pipe.rsi
state: pipeFourway
- state: gasGenerator
- type: NodeContainer
nodes:
- !type:PipeNode
nodeGroupID: Pipe
pipeDirection: Fourway

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,14 @@
{
"version":1,
"size":{
"x":32,
"y":32
},
"license":"CC-BY-SA-3.0",
"copyright":"Taken from https://github.com/tgstation/tgstation at commit 57cd1d59ca019dd0e7811ac451f295f818e573da",
"states":[
{
"name":"gasGenerator"
}
]
}