Adds fire/air alarms (#5018)

Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Co-authored-by: E F R <602406+Efruit@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Flipp Syder
2022-01-01 20:56:24 -08:00
committed by GitHub
parent 903f796b0f
commit b1584793bf
71 changed files with 4340 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
using System;
using Content.Server.Atmos.Piping.Unary.Components;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

View File

@@ -2,10 +2,10 @@ using System;
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.NodeContainer;
using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Atmos.Visuals;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;

View File

@@ -1,5 +1,6 @@
using System;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -14,6 +15,9 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[ViewVariables(VVAccess.ReadWrite)]
public bool Enabled { get; set; } = true;
[ViewVariables]
public bool IsDirty { get; set; } = false;
[ViewVariables(VVAccess.ReadWrite)]
public bool Welded { get; set; } = false;
@@ -33,19 +37,30 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[ViewVariables(VVAccess.ReadWrite)]
public float InternalPressureBound { get; set; } = 0f;
}
public enum VentPumpDirection : sbyte
{
Siphoning = 0,
Releasing = 1,
}
public GasVentPumpData ToAirAlarmData()
{
if (!IsDirty) return new GasVentPumpData { Dirty = IsDirty };
[Flags]
public enum VentPressureBound : sbyte
{
NoBound = 0,
InternalBound = 1,
ExternalBound = 2,
return new GasVentPumpData
{
Enabled = Enabled,
Dirty = IsDirty,
PumpDirection = PumpDirection,
PressureChecks = PressureChecks,
ExternalPressureBound = ExternalPressureBound,
InternalPressureBound = InternalPressureBound
};
}
public void FromAirAlarmData(GasVentPumpData data)
{
Enabled = data.Enabled;
IsDirty = data.Dirty;
PumpDirection = (VentPumpDirection) data.PumpDirection!;
PressureChecks = (VentPressureBound) data.PressureChecks!;
ExternalPressureBound = (float) data.ExternalPressureBound!;
InternalPressureBound = (float) data.InternalPressureBound!;
}
}
}

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -14,6 +16,9 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[ViewVariables(VVAccess.ReadWrite)]
public bool Enabled { get; set; } = true;
[ViewVariables]
public bool IsDirty { get; set; } = false;
[ViewVariables(VVAccess.ReadWrite)]
public bool Welded { get; set; } = false;
@@ -22,13 +27,7 @@ namespace Content.Server.Atmos.Piping.Unary.Components
public string OutletName { get; set; } = "pipe";
[ViewVariables]
public readonly HashSet<Gas> FilterGases = new()
{
Gas.CarbonDioxide,
Gas.Plasma,
Gas.Tritium,
Gas.WaterVapor
};
public readonly HashSet<Gas> FilterGases = GasVentScrubberData.DefaultFilterGases;
[ViewVariables(VVAccess.ReadWrite)]
public ScrubberPumpDirection PumpDirection { get; set; } = ScrubberPumpDirection.Scrubbing;
@@ -38,11 +37,36 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[ViewVariables(VVAccess.ReadWrite)]
public bool WideNet { get; set; } = false;
}
public enum ScrubberPumpDirection : sbyte
{
Siphoning = 0,
Scrubbing = 1,
public GasVentScrubberData ToAirAlarmData()
{
if (!IsDirty) return new GasVentScrubberData { Dirty = IsDirty };
return new GasVentScrubberData
{
Enabled = Enabled,
Dirty = IsDirty,
FilterGases = FilterGases,
PumpDirection = PumpDirection,
VolumeRate = VolumeRate,
WideNet = WideNet
};
}
public void FromAirAlarmData(GasVentScrubberData data)
{
Enabled = data.Enabled;
IsDirty = data.Dirty;
PumpDirection = (ScrubberPumpDirection) data.PumpDirection!;
VolumeRate = (float) data.VolumeRate!;
WideNet = data.WideNet;
if (!data.FilterGases!.SequenceEqual(FilterGases))
{
FilterGases.Clear();
foreach (var gas in data.FilterGases!)
FilterGases.Add(gas);
}
}
}
}

View File

@@ -1,10 +1,19 @@
using System;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Monitor.Components;
using Content.Server.Atmos.Monitor.Systems;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.Unary.Components;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Monitor.Components;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Atmos.Visuals;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
@@ -16,6 +25,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
public class GasVentPumpSystem : EntitySystem
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!;
public override void Initialize()
{
@@ -23,6 +33,9 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceUpdateEvent>(OnGasVentPumpUpdated);
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceDisabledEvent>(OnGasVentPumpLeaveAtmosphere);
SubscribeLocalEvent<GasVentPumpComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
SubscribeLocalEvent<GasVentPumpComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<GasVentPumpComponent, PacketSentEvent>(OnPacketRecv);
}
private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, AtmosDeviceUpdateEvent args)
@@ -99,5 +112,56 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
appearance.SetData(VentPumpVisuals.State, VentPumpState.Off);
}
}
private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosMonitorAlarmEvent args)
{
if (args.HighestNetworkType == AtmosMonitorAlarmType.Danger)
{
component.Enabled = false;
}
else if (args.HighestNetworkType == AtmosMonitorAlarmType.Normal)
{
component.Enabled = true;
}
}
private void OnPowerChanged(EntityUid uid, GasVentPumpComponent component, PowerChangedEvent args)
{
component.Enabled = args.Powered;
}
private void OnPacketRecv(EntityUid uid, GasVentPumpComponent component, PacketSentEvent args)
{
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent netConn)
|| !EntityManager.TryGetComponent(uid, out AtmosAlarmableComponent alarmable)
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
return;
var payload = new NetworkPayload();
switch (cmd)
{
case AirAlarmSystem.AirAlarmSyncCmd:
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSyncData);
payload.Add(AirAlarmSystem.AirAlarmSyncData, component.ToAirAlarmData());
_deviceNetSystem.QueuePacket(uid, args.SenderAddress, AirAlarmSystem.Freq, payload);
return;
case AirAlarmSystem.AirAlarmSetData:
if (!args.Data.TryGetValue(AirAlarmSystem.AirAlarmSetData, out GasVentPumpData? setData))
break;
component.FromAirAlarmData(setData);
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
_deviceNetSystem.QueuePacket(uid, string.Empty, AirAlarmSystem.Freq, payload, true);
return;
}
}
}
}

View File

@@ -1,11 +1,19 @@
using System;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Monitor.Components;
using Content.Server.Atmos.Monitor.Systems;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.Unary.Components;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Visuals;
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Piping.Unary.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -17,6 +25,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
public class GasVentScrubberSystem : EntitySystem
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!;
public override void Initialize()
{
@@ -24,6 +33,10 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceUpdateEvent>(OnVentScrubberUpdated);
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceDisabledEvent>(OnVentScrubberLeaveAtmosphere);
SubscribeLocalEvent<GasVentScrubberComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
SubscribeLocalEvent<GasVentScrubberComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<GasVentScrubberComponent, PacketSentEvent>(OnPacketRecv);
}
private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrubber, AtmosDeviceUpdateEvent args)
@@ -102,5 +115,53 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
outlet.AssumeAir(removed);
}
}
private void OnAtmosAlarm(EntityUid uid, GasVentScrubberComponent component, AtmosMonitorAlarmEvent args)
{
if (args.HighestNetworkType == AtmosMonitorAlarmType.Danger)
{
component.Enabled = false;
}
else if (args.HighestNetworkType == AtmosMonitorAlarmType.Normal)
{
component.Enabled = true;
}
}
private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, PowerChangedEvent args) =>
component.Enabled = args.Powered;
private void OnPacketRecv(EntityUid uid, GasVentScrubberComponent component, PacketSentEvent args)
{
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent netConn)
|| !EntityManager.TryGetComponent(uid, out AtmosAlarmableComponent alarmable)
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
return;
var payload = new NetworkPayload();
switch (cmd)
{
case AirAlarmSystem.AirAlarmSyncCmd:
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSyncData);
payload.Add(AirAlarmSystem.AirAlarmSyncData, component.ToAirAlarmData());
_deviceNetSystem.QueuePacket(uid, args.SenderAddress, AirAlarmSystem.Freq, payload);
return;
case AirAlarmSystem.AirAlarmSetData:
if (!args.Data.TryGetValue(AirAlarmSystem.AirAlarmSetData, out GasVentScrubberData? setData))
break;
component.FromAirAlarmData(setData);
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
_deviceNetSystem.QueuePacket(uid, string.Empty, AirAlarmSystem.Freq, payload, true);
return;
}
}
}
}