This reverts commit 054321d2c2.
Co-authored-by: Kevin Zheng <kevinz5000@gmail.com>
This commit is contained in:
33
Content.Server/Atmos/Reactions/AmmoniaOxygenReaction.cs
Normal file
33
Content.Server/Atmos/Reactions/AmmoniaOxygenReaction.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.Atmos.Reactions;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed partial class AmmoniaOxygenReaction : IGasReactionEffect
|
||||
{
|
||||
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
|
||||
{
|
||||
var nAmmonia = mixture.GetMoles(Gas.Ammonia);
|
||||
var nOxygen = mixture.GetMoles(Gas.Oxygen);
|
||||
var nTotal = mixture.TotalMoles;
|
||||
|
||||
// Concentration-dependent reaction rate
|
||||
var fAmmonia = nAmmonia/nTotal;
|
||||
var fOxygen = nOxygen/nTotal;
|
||||
var rate = MathF.Pow(fAmmonia, 2) * MathF.Pow(fOxygen, 2);
|
||||
|
||||
var deltaMoles = nAmmonia / Atmospherics.AmmoniaOxygenReactionRate * 2 * rate;
|
||||
|
||||
if (deltaMoles <= 0 || nAmmonia - deltaMoles < 0)
|
||||
return ReactionResult.NoReaction;
|
||||
|
||||
mixture.AdjustMoles(Gas.Ammonia, -deltaMoles);
|
||||
mixture.AdjustMoles(Gas.Oxygen, -deltaMoles);
|
||||
mixture.AdjustMoles(Gas.NitrousOxide, deltaMoles / 2);
|
||||
mixture.AdjustMoles(Gas.WaterVapor, deltaMoles * 1.5f);
|
||||
|
||||
return ReactionResult.Reacting;
|
||||
}
|
||||
}
|
||||
58
Content.Server/Atmos/Reactions/FrezonCoolantReaction.cs
Normal file
58
Content.Server/Atmos/Reactions/FrezonCoolantReaction.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,7 @@ namespace Content.Server.Atmos.Reactions
|
||||
public string ID { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum gas amount requirements. Reactions that meet these minimum mole requirements
|
||||
/// have their reaction effects run. Generic gas reactions do not have minimum requirements.
|
||||
/// Minimum gas amount requirements.
|
||||
/// </summary>
|
||||
[DataField("minimumRequirements")]
|
||||
public float[] MinimumRequirements { get; private set; } = new float[Atmospherics.TotalNumberOfGases];
|
||||
@@ -43,13 +42,6 @@ namespace Content.Server.Atmos.Reactions
|
||||
[DataField("minimumTemperature")]
|
||||
public float MinimumTemperatureRequirement { get; private set; } = Atmospherics.TCMB;
|
||||
|
||||
/// <summary>
|
||||
/// If this is a generic gas reaction, multiply the initial rate by this. The default is reasonable for
|
||||
/// synthesis reactions. Consider raising this for fires.
|
||||
/// </summary>
|
||||
[DataField("rateMultiplier")]
|
||||
public float RateMultiplier = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum energy requirement.
|
||||
/// </summary>
|
||||
@@ -68,31 +60,6 @@ namespace Content.Server.Atmos.Reactions
|
||||
/// </summary>
|
||||
[DataField("effects")] private List<IGasReactionEffect> _effects = new();
|
||||
|
||||
/// <summary>
|
||||
/// Energy released by the reaction.
|
||||
/// </summary>
|
||||
[DataField("enthalpy")]
|
||||
public float Enthalpy;
|
||||
|
||||
/// <summary>
|
||||
/// Integer gas IDs and integer ratios required in the reaction. If this is defined, the
|
||||
/// generic gas reaction will run.
|
||||
/// </summary>
|
||||
[DataField("reactants")]
|
||||
public Dictionary<Gas, int> Reactants = new();
|
||||
|
||||
/// <summary>
|
||||
/// Integer gas IDs and integer ratios of reaction products.
|
||||
/// </summary>
|
||||
[DataField("products")]
|
||||
public Dictionary<Gas, int> Products = new();
|
||||
|
||||
/// <summary>
|
||||
/// Integer gas IDs and how much they modify the activation energy (J/mol).
|
||||
/// </summary>
|
||||
[DataField("catalysts")]
|
||||
public Dictionary<Gas, int> Catalysts = new();
|
||||
|
||||
/// <summary>
|
||||
/// Process all reaction effects.
|
||||
/// </summary>
|
||||
|
||||
28
Content.Server/Atmos/Reactions/N2ODecompositionReaction.cs
Normal file
28
Content.Server/Atmos/Reactions/N2ODecompositionReaction.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.Atmos.Reactions;
|
||||
|
||||
/// <summary>
|
||||
/// Decomposes Nitrous Oxide into Nitrogen and Oxygen.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public sealed partial class N2ODecompositionReaction : IGasReactionEffect
|
||||
{
|
||||
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
|
||||
{
|
||||
var cacheN2O = mixture.GetMoles(Gas.NitrousOxide);
|
||||
|
||||
var burnedFuel = cacheN2O / Atmospherics.N2ODecompositionRate;
|
||||
|
||||
if (burnedFuel <= 0 || cacheN2O - burnedFuel < 0)
|
||||
return ReactionResult.NoReaction;
|
||||
|
||||
mixture.AdjustMoles(Gas.NitrousOxide, -burnedFuel);
|
||||
mixture.AdjustMoles(Gas.Nitrogen, burnedFuel);
|
||||
mixture.AdjustMoles(Gas.Oxygen, burnedFuel / 2);
|
||||
|
||||
return ReactionResult.Reacting;
|
||||
}
|
||||
}
|
||||
70
Content.Server/Atmos/Reactions/TritiumFireReaction.cs
Normal file
70
Content.Server/Atmos/Reactions/TritiumFireReaction.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.Atmos.Reactions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed partial class TritiumFireReaction : IGasReactionEffect
|
||||
{
|
||||
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
|
||||
{
|
||||
var energyReleased = 0f;
|
||||
var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
|
||||
var temperature = mixture.Temperature;
|
||||
var location = holder as TileAtmosphere;
|
||||
mixture.ReactionResults[GasReaction.Fire] = 0f;
|
||||
var burnedFuel = 0f;
|
||||
var initialTrit = mixture.GetMoles(Gas.Tritium);
|
||||
|
||||
if (mixture.GetMoles(Gas.Oxygen) < initialTrit ||
|
||||
Atmospherics.MinimumTritiumOxyburnEnergy > (temperature * oldHeatCapacity))
|
||||
{
|
||||
burnedFuel = mixture.GetMoles(Gas.Oxygen) / Atmospherics.TritiumBurnOxyFactor;
|
||||
if (burnedFuel > initialTrit)
|
||||
burnedFuel = initialTrit;
|
||||
|
||||
mixture.AdjustMoles(Gas.Tritium, -burnedFuel);
|
||||
}
|
||||
else
|
||||
{
|
||||
burnedFuel = initialTrit;
|
||||
mixture.SetMoles(Gas.Tritium, mixture.GetMoles(Gas.Tritium ) * (1 - 1 / Atmospherics.TritiumBurnTritFactor));
|
||||
mixture.AdjustMoles(Gas.Oxygen, -mixture.GetMoles(Gas.Tritium));
|
||||
energyReleased += (Atmospherics.FireHydrogenEnergyReleased * burnedFuel * (Atmospherics.TritiumBurnTritFactor - 1));
|
||||
}
|
||||
|
||||
if (burnedFuel > 0)
|
||||
{
|
||||
energyReleased += (Atmospherics.FireHydrogenEnergyReleased * burnedFuel);
|
||||
|
||||
// TODO ATMOS Radiation pulse here!
|
||||
|
||||
// Conservation of mass is important.
|
||||
mixture.AdjustMoles(Gas.WaterVapor, burnedFuel);
|
||||
|
||||
mixture.ReactionResults[GasReaction.Fire] += burnedFuel;
|
||||
}
|
||||
|
||||
energyReleased /= heatScale; // adjust energy to make sure speedup doesn't cause mega temperature rise
|
||||
if (energyReleased > 0)
|
||||
{
|
||||
var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture, true);
|
||||
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
|
||||
mixture.Temperature = ((temperature * oldHeatCapacity + energyReleased) / newHeatCapacity);
|
||||
}
|
||||
|
||||
if (location != null)
|
||||
{
|
||||
temperature = mixture.Temperature;
|
||||
if (temperature > Atmospherics.FireMinimumTemperatureToExist)
|
||||
{
|
||||
atmosphereSystem.HotspotExpose(location.GridIndex, location.GridIndices, temperature, mixture.Volume);
|
||||
}
|
||||
}
|
||||
|
||||
return mixture.ReactionResults[GasReaction.Fire] != 0 ? ReactionResult.Reacting : ReactionResult.NoReaction;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user