Adds the thermo-electric generator (#18840)

* Basic TEG start.

Connects via node group.

* Basic TEG test map

* Sensor monitoring basics, TEG circulator flow

* Basic power generation (it doesn't work)

* More sensor monitoring work

* Battery (SMES) monitoring system.

* Sensor monitoring fixes

Make it work properly when mapped.

* Test map improvements

* Revise TEG power output mechanism.

Now uses a fixed supplier with a custom ramping system.

* TEG test map fixes

* Make air alarms and pumps open UI on activate.

* Clean up thermo machines power switch.

Removed separate Enabled bool from the component that always matched the power receiver's state.

This enables adding a PowerSwitch component to give us alt click/verb menu.

* TEG but now fancy

* Make sensor monitoring console obviously WiP to mappers.

* Vending machine sound, because of course.

* Terrible, terrible graph background color

* Examine improvements for the TEG.

* Account for electrical power when equalizing gas mixtures.

* Get rid of the TegCirculatorArrow logic.

Use TimedDespawn instead. The "no show in right-click menuu" goes into a new general-purpose component.

Thanks Julian.

* Put big notice of "not ready, here's why" on the sensor monitoring console.

* TryGetComponent -> TryComp

* Lol there's a HideContextMenu tag

* Test fixes

* Guidebook for TEG

Fixed rotation on GuideEntityEmbed not working correctly.

Added Margin property to GuideEntityEmbed

* Make TEG power bar default to invisible.

So it doesn't appear in the guidebook and spawn menu.
This commit is contained in:
Pieter-Jan Briers
2023-08-12 22:41:55 +02:00
committed by GitHub
parent 61bf951ec4
commit a242af506e
74 changed files with 5546 additions and 22 deletions

View File

@@ -166,7 +166,7 @@ public sealed class AirAlarmSystem : EntitySystem
SubscribeLocalEvent<AirAlarmComponent, DeviceListUpdateEvent>(OnDeviceListUpdate);
SubscribeLocalEvent<AirAlarmComponent, BoundUIClosedEvent>(OnClose);
SubscribeLocalEvent<AirAlarmComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<AirAlarmComponent, InteractHandEvent>(OnInteract);
SubscribeLocalEvent<AirAlarmComponent, ActivateInWorldEvent>(OnActivate);
}
private void OnDeviceListUpdate(EntityUid uid, AirAlarmComponent component, DeviceListUpdateEvent args)
@@ -225,7 +225,7 @@ public sealed class AirAlarmSystem : EntitySystem
_activeUserInterfaces.Remove(uid);
}
private void OnInteract(EntityUid uid, AirAlarmComponent component, InteractHandEvent args)
private void OnActivate(EntityUid uid, AirAlarmComponent component, ActivateInWorldEvent args)
{
if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target))
return;

View File

@@ -40,5 +40,8 @@ namespace Content.Server.Atmos.Piping.Binary.Components
[DataField("overclockThreshold")]
public float OverclockThreshold { get; set; } = 1000;
[DataField("lastMolesTransferred")]
public float LastMolesTransferred;
}
}

View File

@@ -36,7 +36,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceUpdateEvent>(OnPumpUpdated);
SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceDisabledEvent>(OnPumpLeaveAtmosphere);
SubscribeLocalEvent<GasPressurePumpComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<GasPressurePumpComponent, InteractHandEvent>(OnPumpInteractHand);
SubscribeLocalEvent<GasPressurePumpComponent, ActivateInWorldEvent>(OnPumpActivate);
// Bound UI subscriptions
SubscribeLocalEvent<GasPressurePumpComponent, GasPressurePumpChangeOutputPressureMessage>(OnOutputPressureChangeMessage);
SubscribeLocalEvent<GasPressurePumpComponent, GasPressurePumpToggleStatusMessage>(OnToggleStatusMessage);
@@ -99,7 +99,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
_userInterfaceSystem.TryCloseAll(uid, GasPressurePumpUiKey.Key);
}
private void OnPumpInteractHand(EntityUid uid, GasPressurePumpComponent pump, InteractHandEvent args)
private void OnPumpActivate(EntityUid uid, GasPressurePumpComponent pump, ActivateInWorldEvent args)
{
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
return;

View File

@@ -1,12 +1,17 @@
using Content.Server.Administration.Logs;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Monitor.Systems;
using Content.Server.Atmos.Piping.Binary.Components;
using Content.Server.Atmos.Piping.Components;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos.Piping;
using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Audio;
using Content.Shared.Database;
using Content.Shared.Examine;
@@ -29,6 +34,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
public override void Initialize()
{
@@ -38,10 +45,12 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceUpdateEvent>(OnVolumePumpUpdated);
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceDisabledEvent>(OnVolumePumpLeaveAtmosphere);
SubscribeLocalEvent<GasVolumePumpComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<GasVolumePumpComponent, InteractHandEvent>(OnPumpInteractHand);
SubscribeLocalEvent<GasVolumePumpComponent, ActivateInWorldEvent>(OnPumpActivate);
// Bound UI subscriptions
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpChangeTransferRateMessage>(OnTransferRateChangeMessage);
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpToggleStatusMessage>(OnToggleStatusMessage);
SubscribeLocalEvent<GasVolumePumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
}
private void OnInit(EntityUid uid, GasVolumePumpComponent pump, ComponentInit args)
@@ -101,6 +110,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
}
}
pump.LastMolesTransferred = removed.TotalMoles;
_atmosphereSystem.Merge(outlet.Air, removed);
_ambientSoundSystem.SetAmbience(uid, removed.TotalMoles > 0f);
}
@@ -114,7 +125,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
_userInterfaceSystem.TryCloseAll(uid, GasVolumePumpUiKey.Key);
}
private void OnPumpInteractHand(EntityUid uid, GasVolumePumpComponent pump, InteractHandEvent args)
private void OnPumpActivate(EntityUid uid, GasVolumePumpComponent pump, ActivateInWorldEvent args)
{
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
return;
@@ -165,5 +176,24 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
_appearance.SetData(uid, PumpVisuals.Enabled, pump.Enabled, appearance);
}
private void OnPacketRecv(EntityUid uid, GasVolumePumpComponent component, DeviceNetworkPacketEvent args)
{
if (!TryComp(uid, out DeviceNetworkComponent? netConn)
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
return;
var payload = new NetworkPayload();
switch (cmd)
{
case AtmosDeviceNetworkSystem.SyncData:
payload.Add(DeviceNetworkConstants.Command, AtmosDeviceNetworkSystem.SyncData);
payload.Add(AtmosDeviceNetworkSystem.SyncData, new GasVolumePumpData(component.LastMolesTransferred));
_deviceNetwork.QueuePacket(uid, args.SenderAddress, payload, device: netConn);
return;
}
}
}
}

View File

@@ -11,10 +11,6 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[DataField("inlet")]
public string InletName = "pipe";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("enabled")]
public bool Enabled = false;
/// <summary>
/// Current maximum temperature, calculated from <see cref="BaseHeatCapacity"/> and the quality of matter
/// bins. The heat capacity effectively determines the rate at which the thermo machine can add or remove
@@ -93,5 +89,11 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[DataField("machinePartTemperature", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartTemperature = "Capacitor";
/// <summary>
/// Last amount of energy added/removed from the attached pipe network
/// </summary>
[DataField("lastEnergyDelta")]
[ViewVariables(VVAccess.ReadWrite)]
public float LastEnergyDelta;
}
}

View File

@@ -1,10 +1,15 @@
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Monitor.Systems;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.Unary.Components;
using Content.Server.Construction;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Components;
using JetBrains.Annotations;
@@ -22,6 +27,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly PowerReceiverSystem _power = default!;
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
public override void Initialize()
{
@@ -35,12 +42,15 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
// UI events
SubscribeLocalEvent<GasThermoMachineComponent, GasThermomachineToggleMessage>(OnToggleMessage);
SubscribeLocalEvent<GasThermoMachineComponent, GasThermomachineChangeTemperatureMessage>(OnChangeTemperature);
// Device network
SubscribeLocalEvent<GasThermoMachineComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
}
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, AtmosDeviceUpdateEvent args)
{
if (!(thermoMachine.Enabled && _power.IsPowered(uid))
if (!(_power.IsPowered(uid))
|| !TryComp(uid, out NodeContainerComponent? nodeContainer)
|| !_nodeContainer.TryGetNode(nodeContainer, thermoMachine.InletName, out PipeNode? inlet))
{
@@ -50,10 +60,14 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
var airHeatCapacity = _atmosphereSystem.GetHeatCapacity(inlet.Air);
var combinedHeatCapacity = airHeatCapacity + thermoMachine.HeatCapacity;
var startEnergy = inlet.Air.Temperature * airHeatCapacity;
if (!MathHelper.CloseTo(combinedHeatCapacity, 0, 0.001f))
{
var combinedEnergy = thermoMachine.HeatCapacity * thermoMachine.TargetTemperature + airHeatCapacity * inlet.Air.Temperature;
inlet.Air.Temperature = combinedEnergy / combinedHeatCapacity;
thermoMachine.LastEnergyDelta = inlet.Air.Temperature * airHeatCapacity - startEnergy;
}
}
@@ -98,7 +112,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnToggleMessage(EntityUid uid, GasThermoMachineComponent thermoMachine, GasThermomachineToggleMessage args)
{
SetEnabled(uid, thermoMachine, _power.TogglePower(uid));
_power.TogglePower(uid);
DirtyUI(uid, thermoMachine);
}
@@ -115,13 +129,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (!Resolve(uid, ref thermoMachine, ref ui, false))
return;
_userInterfaceSystem.TrySetUiState(uid, ThermomachineUiKey.Key,
new GasThermomachineBoundUserInterfaceState(thermoMachine.MinTemperature, thermoMachine.MaxTemperature, thermoMachine.TargetTemperature, thermoMachine.Enabled, thermoMachine.Mode), null, ui);
}
ApcPowerReceiverComponent? powerReceiver = null;
if (!Resolve(uid, ref powerReceiver))
return;
private void SetEnabled(EntityUid uid, GasThermoMachineComponent thermoMachine, bool enabled)
{
thermoMachine.Enabled = enabled;
_userInterfaceSystem.TrySetUiState(uid, ThermomachineUiKey.Key,
new GasThermomachineBoundUserInterfaceState(thermoMachine.MinTemperature, thermoMachine.MaxTemperature, thermoMachine.TargetTemperature, !powerReceiver.PowerDisabled, thermoMachine.Mode), null, ui);
}
private void OnExamined(EntityUid uid, GasThermoMachineComponent thermoMachine, ExaminedEvent args)
@@ -137,5 +150,25 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
args.PushMarkup(str);
}
private void OnPacketRecv(EntityUid uid, GasThermoMachineComponent component, DeviceNetworkPacketEvent args)
{
if (!TryComp(uid, out DeviceNetworkComponent? netConn)
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
return;
var payload = new NetworkPayload();
switch (cmd)
{
case AtmosDeviceNetworkSystem.SyncData:
payload.Add(DeviceNetworkConstants.Command, AtmosDeviceNetworkSystem.SyncData);
payload.Add(AtmosDeviceNetworkSystem.SyncData, new GasThermoMachineData(component.LastEnergyDelta));
_deviceNetwork.QueuePacket(uid, args.SenderAddress, payload, device: netConn);
return;
}
}
}
}