-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathNitriumProductionReaction.cs
More file actions
61 lines (46 loc) · 2.41 KB
/
Copy pathNitriumProductionReaction.cs
File metadata and controls
61 lines (46 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Reactions;
using JetBrains.Annotations;
namespace Content.Server._Starlight.Atmos.Reactions;
/// <summary>
/// Funky Atmos - /tg/ gases - Starlight Overhaul
/// Produces Nitrium by mixing Tritium, Nitrogen and Pluoxium at temperatures above 500K.
/// </summary>
[UsedImplicitly]
public sealed partial class NitriumProductionReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem, float heatScale)
{
if (mixture.Temperature > 20f && mixture.GetMoles(Gas.HyperNoblium) >= 5f)
return ReactionResult.NoReaction;
var initTritium = mixture.GetMoles(Gas.Tritium);
var initNitrogen = mixture.GetMoles(Gas.Nitrogen);
var initPluox = mixture.GetMoles(Gas.Pluoxium);
var initBZ = mixture.GetMoles(Gas.BZ);
var pressure = mixture.Pressure;
var volume = mixture.Volume;
var temperature = mixture.Temperature;
var catalyze = 1f + (initBZ / 100f) ;
/// Check what ingredient is smallest relative to its un-catalyzed demand. Use it as a limiter.
var limit = Math.Min(initTritium / 2f, Math.Min(initNitrogen * catalyze / 3f, initPluox));
/// Produces faster with higher temperature, lower pressure, and higher concetrations of BZ. BZ also magnifies the nitrogen consumption so watch out.
var tempRate = temperature / 500f ;
var pressureRate = (10f / pressure) * 2f ;
var rate = Math.Min(0.5F * tempRate * pressureRate * catalyze, limit);
var tritiumRemoved = 2f * rate;
var nitrogenRemoved = 3f * rate * catalyze;
var pluoxRemoved = 1f * rate;
var nitriumProduced = 3f * rate;
mixture.AdjustMoles(Gas.Tritium, -tritiumRemoved);
mixture.AdjustMoles(Gas.Nitrogen, -nitrogenRemoved);
mixture.AdjustMoles(Gas.Pluoxium, -pluoxRemoved);
mixture.AdjustMoles(Gas.Nitrium, nitriumProduced);
var energyReleased = rate * Atmospherics.NitriumProductionEnergy / heatScale;
var heatCap = atmosphereSystem.GetHeatCapacity(mixture, true);
if (heatCap > Atmospherics.MinimumHeatCapacity)
mixture.Temperature = Math.Max((mixture.Temperature * heatCap + energyReleased) / heatCap, Atmospherics.TCMB);
return ReactionResult.Reacting;
}
}