mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-20 15:08:46 +03:00
* Check for divide by near zero (#22876) * Clamp after AdjustMoles() (#22907) Clamping is needed because x - x can be negative with floating point numbers. If we don't clamp here, the caller always has to call GetMoles(), clamp, then SetMoles(), which makes this function not very useful. * Add maximum atmos temperature limit (#22882) * Add Tmax * Increase Tmax * Revert "Add YAML gas reactions (#22803)" (#22939) This reverts commit 054321d2c2c17eb55a1640150131c61c29a3eb2b. Co-authored-by: Kevin Zheng <kevinz5000@gmail.com> --------- Co-authored-by: Kevin Zheng <kevinz5000@gmail.com> Co-authored-by: Kara <lunarautomaton6@gmail.com>
59 lines
2.3 KiB
C#
59 lines
2.3 KiB
C#
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Shared.Atmos;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Content.Server.Atmos.Reactions;
|
|
|
|
/// <summary>
|
|
/// Takes in nitrogen and frezon and cools down the surrounding area.
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
public sealed partial class FrezonCoolantReaction : IGasReactionEffect
|
|
{
|
|
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
|
|
{
|
|
var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
|
|
var temperature = mixture.Temperature;
|
|
|
|
var energyModifier = 1f;
|
|
var scale = (temperature - Atmospherics.FrezonCoolLowerTemperature) /
|
|
(Atmospherics.FrezonCoolMidTemperature - Atmospherics.FrezonCoolLowerTemperature);
|
|
|
|
if (scale > 1f)
|
|
{
|
|
// Scale energy but not frezon usage if we're in a very, very hot place
|
|
energyModifier = Math.Min(scale, Atmospherics.FrezonCoolMaximumEnergyModifier);
|
|
scale = 1f;
|
|
}
|
|
|
|
if (scale <= 0)
|
|
return ReactionResult.NoReaction;
|
|
|
|
var initialNit = mixture.GetMoles(Gas.Nitrogen);
|
|
var initialFrezon = mixture.GetMoles(Gas.Frezon);
|
|
|
|
var burnRate = initialFrezon * scale / Atmospherics.FrezonCoolRateModifier;
|
|
|
|
var energyReleased = 0f;
|
|
if (burnRate > Atmospherics.MinimumHeatCapacity)
|
|
{
|
|
var nitAmt = Math.Min(burnRate * Atmospherics.FrezonNitrogenCoolRatio, initialNit);
|
|
var frezonAmt = Math.Min(burnRate, initialFrezon);
|
|
mixture.AdjustMoles(Gas.Nitrogen, -nitAmt);
|
|
mixture.AdjustMoles(Gas.Frezon, -frezonAmt);
|
|
mixture.AdjustMoles(Gas.NitrousOxide, nitAmt + frezonAmt);
|
|
energyReleased = burnRate * Atmospherics.FrezonCoolEnergyReleased * energyModifier;
|
|
}
|
|
|
|
energyReleased /= heatScale; // adjust energy to make sure speedup doesn't cause mega temperature rise
|
|
if (energyReleased >= 0f)
|
|
return ReactionResult.NoReaction;
|
|
|
|
var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
|
|
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
|
|
mixture.Temperature = (temperature * oldHeatCapacity + energyReleased) / newHeatCapacity;
|
|
|
|
return ReactionResult.Reacting;
|
|
}
|
|
}
|