Files
OldThink/Content.Server/Atmos/Reactions/FrezonProductionReaction.cs

41 lines
1.6 KiB
C#
Raw Normal View History

using Content.Server.Atmos.EntitySystems;
using Content.Shared.Atmos;
using JetBrains.Annotations;
namespace Content.Server.Atmos.Reactions;
/// <summary>
/// Produces frezon from oxygen and tritium, with nitrogen as a catalyst that also acts as a stopper if too much is present.
/// Has a max temperature, but paradoxically gets more efficient the hotter it is.
/// </summary>
[UsedImplicitly]
public sealed class FrezonProductionReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialN2 = mixture.GetMoles(Gas.Nitrogen);
var initialOxy = mixture.GetMoles(Gas.Oxygen);
var initialTrit = mixture.GetMoles(Gas.Tritium);
var efficiency = mixture.Temperature / Atmospherics.FrezonProductionMaxEfficiencyTemperature;
var loss = 1 - efficiency;
// Less N2 is required the more efficient it is.
var minimumN2 = (initialOxy + initialTrit) / (Atmospherics.FrezonProductionNitrogenRatio * efficiency);
if (initialN2 < minimumN2)
return ReactionResult.NoReaction;
var oxyConversion = initialOxy / Atmospherics.FrezonProductionConversionRate;
var tritConversion = initialTrit / Atmospherics.FrezonProductionConversionRate;
var total = oxyConversion + tritConversion;
mixture.AdjustMoles(Gas.Oxygen, -oxyConversion);
mixture.AdjustMoles(Gas.Tritium, -tritConversion);
mixture.AdjustMoles(Gas.Frezon, total * efficiency);
mixture.AdjustMoles(Gas.Nitrogen, total * loss);
return ReactionResult.Reacting;
}
}