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:
@@ -64,5 +64,11 @@ namespace Content.Server.Atmos.Piping.Unary.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float EnergyLeakPercentage;
|
public float EnergyLeakPercentage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If true, heat is exclusively exchanged with the local atmosphere instead of the inlet pipe air
|
||||||
|
/// </summary>
|
||||||
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public bool Atmospheric = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,17 +55,17 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, ref AtmosDeviceUpdateEvent args)
|
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, ref AtmosDeviceUpdateEvent args)
|
||||||
{
|
{
|
||||||
if (!(_power.IsPowered(uid) && TryComp<ApcPowerReceiverComponent>(uid, out var receiver))
|
if (!(_power.IsPowered(uid) && TryComp<ApcPowerReceiverComponent>(uid, out var receiver)))
|
||||||
|| !TryComp<NodeContainerComponent>(uid, out var nodeContainer)
|
return;
|
||||||
|| !_nodeContainer.TryGetNode(nodeContainer, thermoMachine.InletName, out PipeNode? inlet))
|
|
||||||
{
|
GetHeatExchangeGasMixture(uid, thermoMachine, out var heatExchangeGasMixture);
|
||||||
|
if (heatExchangeGasMixture == null)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
float sign = Math.Sign(thermoMachine.Cp); // 1 if heater, -1 if freezer
|
float sign = Math.Sign(thermoMachine.Cp); // 1 if heater, -1 if freezer
|
||||||
float targetTemp = thermoMachine.TargetTemperature;
|
float targetTemp = thermoMachine.TargetTemperature;
|
||||||
float highTemp = targetTemp + sign * thermoMachine.TemperatureTolerance;
|
float highTemp = targetTemp + sign * thermoMachine.TemperatureTolerance;
|
||||||
float temp = inlet.Air.Temperature;
|
float temp = heatExchangeGasMixture.Temperature;
|
||||||
|
|
||||||
if (sign * temp >= sign * highTemp) // upper bound
|
if (sign * temp >= sign * highTemp) // upper bound
|
||||||
thermoMachine.HysteresisState = false; // turn off
|
thermoMachine.HysteresisState = false; // turn off
|
||||||
@@ -74,8 +74,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
if (thermoMachine.HysteresisState)
|
if (thermoMachine.HysteresisState)
|
||||||
targetTemp = highTemp; // when on, target upper hysteresis bound
|
targetTemp = highTemp; // when on, target upper hysteresis bound
|
||||||
|
else // Hysteresis is the same as "Should this be on?"
|
||||||
if (!thermoMachine.HysteresisState) // Hysteresis is the same as "Should this be on?"
|
|
||||||
{
|
{
|
||||||
// Turn dynamic load back on when power has been adjusted to not cause lights to
|
// Turn dynamic load back on when power has been adjusted to not cause lights to
|
||||||
// blink every time this heater comes on.
|
// 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;
|
float dQ = thermoMachine.HeatCapacity * thermoMachine.Cp * args.dt;
|
||||||
|
|
||||||
// Clamps the heat transferred to not overshoot
|
// 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 dT = targetTemp - temp;
|
||||||
float dQLim = dT * Cin;
|
float dQLim = dT * Cin;
|
||||||
float scale = 1f;
|
float scale = 1f;
|
||||||
@@ -96,17 +95,45 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
scale = dQLim / dQ; // reduce power consumption
|
scale = dQLim / dQ; // reduce power consumption
|
||||||
thermoMachine.HysteresisState = false; // turn off
|
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)
|
float dQActual = dQ * scale;
|
||||||
_atmosphereSystem.AddHeat(containingMixture, dQLeak);
|
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
|
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)
|
private bool IsHeater(GasThermoMachineComponent comp)
|
||||||
{
|
{
|
||||||
return comp.Cp >= 0;
|
return comp.Cp >= 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user