2021-06-23 11:35:30 +02:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.Atmos.Piping.Components;
|
|
|
|
|
using Content.Server.Atmos.Piping.Unary.Components;
|
|
|
|
|
using Content.Server.NodeContainer;
|
2021-07-04 18:11:52 +02:00
|
|
|
using Content.Server.NodeContainer.Nodes;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Shared.Atmos.Piping;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-26 12:58:17 +02:00
|
|
|
using Robust.Shared.IoC;
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class GasThermoMachineSystem : EntitySystem
|
|
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
|
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<GasThermoMachineComponent, AtmosDeviceUpdateEvent>(OnThermoMachineUpdated);
|
|
|
|
|
SubscribeLocalEvent<GasThermoMachineComponent, AtmosDeviceDisabledEvent>(OnThermoMachineLeaveAtmosphere);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, AtmosDeviceUpdateEvent args)
|
|
|
|
|
{
|
2021-12-08 13:00:43 +01:00
|
|
|
var appearance = EntityManager.GetComponentOrNull<AppearanceComponent>(thermoMachine.Owner);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2021-07-30 14:00:14 +02:00
|
|
|
if (!thermoMachine.Enabled
|
2021-09-28 13:35:29 +02:00
|
|
|
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|
2021-07-30 14:00:14 +02:00
|
|
|
|| !nodeContainer.TryGetNode(thermoMachine.InletName, out PipeNode? inlet))
|
|
|
|
|
{
|
|
|
|
|
appearance?.SetData(ThermoMachineVisuals.Enabled, false);
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
2021-07-30 14:00:14 +02:00
|
|
|
}
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2021-07-26 12:58:17 +02:00
|
|
|
var airHeatCapacity = _atmosphereSystem.GetHeatCapacity(inlet.Air);
|
2021-06-19 13:25:05 +02:00
|
|
|
var combinedHeatCapacity = airHeatCapacity + thermoMachine.HeatCapacity;
|
|
|
|
|
var oldTemperature = inlet.Air.Temperature;
|
|
|
|
|
|
|
|
|
|
if (combinedHeatCapacity > 0)
|
|
|
|
|
{
|
|
|
|
|
appearance?.SetData(ThermoMachineVisuals.Enabled, true);
|
|
|
|
|
var combinedEnergy = thermoMachine.HeatCapacity * thermoMachine.TargetTemperature + airHeatCapacity * inlet.Air.Temperature;
|
|
|
|
|
inlet.Air.Temperature = combinedEnergy / combinedHeatCapacity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO ATMOS: Active power usage.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnThermoMachineLeaveAtmosphere(EntityUid uid, GasThermoMachineComponent component, AtmosDeviceDisabledEvent args)
|
|
|
|
|
{
|
2021-09-28 13:35:29 +02:00
|
|
|
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
|
|
|
|
appearance.SetData(ThermoMachineVisuals.Enabled, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|