* Make ReactionResults an array We're making the dictionaries fixed-size anyway. Alternatively could use a frozendictionary but not sure on the perf difference. Worst case whoever adds another reactionresult makes a minor adjustment * apply conventions --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
72 lines
3.0 KiB
C#
72 lines
3.0 KiB
C#
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Shared.Atmos;
|
|
using Content.Shared.Atmos.Reactions;
|
|
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[(byte)GasReaction.Fire] = 0f;
|
|
var burnedFuel = 0f;
|
|
var initialTrit = mixture.GetMoles(Gas.Tritium);
|
|
|
|
if (mixture.GetMoles(Gas.Oxygen) < initialTrit ||
|
|
Atmospherics.MinimumTritiumOxyburnEnergy > (temperature * oldHeatCapacity * heatScale))
|
|
{
|
|
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[(byte)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, temperature, mixture.Volume);
|
|
}
|
|
}
|
|
|
|
return mixture.ReactionResults[(byte)GasReaction.Fire] != 0 ? ReactionResult.Reacting : ReactionResult.NoReaction;
|
|
}
|
|
}
|
|
}
|