-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 054321d. Co-authored-by: Kevin Zheng <[email protected]> --------- Co-authored-by: Kevin Zheng <[email protected]> Co-authored-by: Kara <[email protected]>
- Loading branch information
1 parent
a10c109
commit 6afde59
Showing
10 changed files
with
286 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 0 additions & 130 deletions
130
Content.Server/Atmos/EntitySystems/GenericGasReactionSystem.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Content.Server/Atmos/Reactions/N2ODecompositionReaction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.