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:
committed by
GitHub
parent
61bf951ec4
commit
a242af506e
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user