Allow thermomachines to exchange with air instead of inlet (#25247)
Add purely atmospheric heat exchange to the gas thermomachine component (in preparation for space heaters).
This commit is contained in:
@@ -55,17 +55,17 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
|
||||
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, ref AtmosDeviceUpdateEvent args)
|
||||
{
|
||||
if (!(_power.IsPowered(uid) && TryComp<ApcPowerReceiverComponent>(uid, out var receiver))
|
||||
|| !TryComp<NodeContainerComponent>(uid, out var nodeContainer)
|
||||
|| !_nodeContainer.TryGetNode(nodeContainer, thermoMachine.InletName, out PipeNode? inlet))
|
||||
{
|
||||
if (!(_power.IsPowered(uid) && TryComp<ApcPowerReceiverComponent>(uid, out var receiver)))
|
||||
return;
|
||||
|
||||
GetHeatExchangeGasMixture(uid, thermoMachine, out var heatExchangeGasMixture);
|
||||
if (heatExchangeGasMixture == null)
|
||||
return;
|
||||
}
|
||||
|
||||
float sign = Math.Sign(thermoMachine.Cp); // 1 if heater, -1 if freezer
|
||||
float targetTemp = thermoMachine.TargetTemperature;
|
||||
float highTemp = targetTemp + sign * thermoMachine.TemperatureTolerance;
|
||||
float temp = inlet.Air.Temperature;
|
||||
float temp = heatExchangeGasMixture.Temperature;
|
||||
|
||||
if (sign * temp >= sign * highTemp) // upper bound
|
||||
thermoMachine.HysteresisState = false; // turn off
|
||||
@@ -74,8 +74,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
|
||||
if (thermoMachine.HysteresisState)
|
||||
targetTemp = highTemp; // when on, target upper hysteresis bound
|
||||
|
||||
if (!thermoMachine.HysteresisState) // Hysteresis is the same as "Should this be on?"
|
||||
else // Hysteresis is the same as "Should this be on?"
|
||||
{
|
||||
// Turn dynamic load back on when power has been adjusted to not cause lights to
|
||||
// blink every time this heater comes on.
|
||||
@@ -87,7 +86,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
float dQ = thermoMachine.HeatCapacity * thermoMachine.Cp * args.dt;
|
||||
|
||||
// Clamps the heat transferred to not overshoot
|
||||
float Cin = _atmosphereSystem.GetHeatCapacity(inlet.Air, true);
|
||||
float Cin = _atmosphereSystem.GetHeatCapacity(heatExchangeGasMixture, true);
|
||||
float dT = targetTemp - temp;
|
||||
float dQLim = dT * Cin;
|
||||
float scale = 1f;
|
||||
@@ -96,17 +95,45 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
scale = dQLim / dQ; // reduce power consumption
|
||||
thermoMachine.HysteresisState = false; // turn off
|
||||
}
|
||||
float dQActual = dQ * scale;
|
||||
float dQLeak = dQActual * thermoMachine.EnergyLeakPercentage;
|
||||
float dQPipe = dQActual - dQLeak;
|
||||
_atmosphereSystem.AddHeat(inlet.Air, dQPipe);
|
||||
|
||||
if (_atmosphereSystem.GetContainingMixture(uid) is { } containingMixture)
|
||||
_atmosphereSystem.AddHeat(containingMixture, dQLeak);
|
||||
float dQActual = dQ * scale;
|
||||
if (thermoMachine.Atmospheric)
|
||||
{
|
||||
_atmosphereSystem.AddHeat(heatExchangeGasMixture, dQActual);
|
||||
}
|
||||
else
|
||||
{
|
||||
float dQLeak = dQActual * thermoMachine.EnergyLeakPercentage;
|
||||
float dQPipe = dQActual - dQLeak;
|
||||
_atmosphereSystem.AddHeat(heatExchangeGasMixture, dQPipe);
|
||||
|
||||
if (dQLeak != 0f && _atmosphereSystem.GetContainingMixture(uid) is { } containingMixture)
|
||||
_atmosphereSystem.AddHeat(containingMixture, dQLeak);
|
||||
}
|
||||
|
||||
receiver.Load = thermoMachine.HeatCapacity;// * scale; // we're not ready for dynamic load yet, see note above
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the gas mixture with which the thermomachine will exchange heat (the local atmosphere if atmospheric or the inlet pipe
|
||||
/// air if not). Returns null if no gas mixture is found.
|
||||
/// </summary>
|
||||
private void GetHeatExchangeGasMixture(EntityUid uid, GasThermoMachineComponent thermoMachine, out GasMixture? heatExchangeGasMixture)
|
||||
{
|
||||
heatExchangeGasMixture = null;
|
||||
if (thermoMachine.Atmospheric)
|
||||
{
|
||||
heatExchangeGasMixture = _atmosphereSystem.GetContainingMixture(uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!TryComp<NodeContainerComponent>(uid, out var nodeContainer)
|
||||
|| !_nodeContainer.TryGetNode(nodeContainer, thermoMachine.InletName, out PipeNode? inlet))
|
||||
return;
|
||||
heatExchangeGasMixture = inlet.Air;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsHeater(GasThermoMachineComponent comp)
|
||||
{
|
||||
return comp.Cp >= 0;
|
||||
|
||||
Reference in New Issue
Block a user