FrezonProductionReaction.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Content.Server.Atmos.EntitySystems;
  2. using Content.Shared.Atmos;
  3. using Content.Shared.Atmos.Reactions;
  4. using JetBrains.Annotations;
  5. namespace Content.Server.Atmos.Reactions;
  6. /// <summary>
  7. /// Produces frezon from oxygen and tritium, with nitrogen as a catalyst that also acts as a stopper if too much is present.
  8. /// Has a max temperature, but paradoxically gets more efficient the hotter it is.
  9. /// </summary>
  10. [UsedImplicitly]
  11. public sealed partial class FrezonProductionReaction : IGasReactionEffect
  12. {
  13. public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
  14. {
  15. var initialN2 = mixture.GetMoles(Gas.Nitrogen);
  16. var initialOxy = mixture.GetMoles(Gas.Oxygen);
  17. var initialTrit = mixture.GetMoles(Gas.Tritium);
  18. var efficiency = mixture.Temperature / Atmospherics.FrezonProductionMaxEfficiencyTemperature;
  19. var loss = 1 - efficiency;
  20. // How much the catalyst (N2) will allow us to produce
  21. // Less N2 is required the more efficient it is.
  22. var catalystLimit = initialN2 * (Atmospherics.FrezonProductionNitrogenRatio / efficiency);
  23. var oxyLimit = Math.Min(initialOxy, catalystLimit) / Atmospherics.FrezonProductionTritRatio;
  24. // Amount of tritium & oxygen that are reacting
  25. var tritBurned = Math.Min(oxyLimit, initialTrit);
  26. var oxyBurned = tritBurned * Atmospherics.FrezonProductionTritRatio;
  27. var oxyConversion = oxyBurned / Atmospherics.FrezonProductionConversionRate;
  28. var tritConversion = tritBurned / Atmospherics.FrezonProductionConversionRate;
  29. var total = oxyConversion + tritConversion;
  30. mixture.AdjustMoles(Gas.Oxygen, -oxyConversion);
  31. mixture.AdjustMoles(Gas.Tritium, -tritConversion);
  32. mixture.AdjustMoles(Gas.Frezon, total * efficiency);
  33. mixture.AdjustMoles(Gas.Nitrogen, total * loss);
  34. return ReactionResult.Reacting;
  35. }
  36. }