Adds tritium fire reaction and water vapor, fix gas reactions (#1623)

hehe Tritfire go BRRRR
This commit is contained in:
Víctor Aguilera Puerto
2020-08-08 19:16:24 +02:00
committed by GitHub
parent cc9f16e738
commit b5a976b173
8 changed files with 144 additions and 14 deletions

View File

@@ -35,6 +35,13 @@ namespace Content.Server.Atmos
[ViewVariables]
public float LastShare { get; private set; } = 0;
[ViewVariables]
public readonly Dictionary<GasReaction, float> ReactionResults = new Dictionary<GasReaction, float>()
{
// We initialize the dictionary here.
{ GasReaction.Fire, 0f }
};
[ViewVariables]
public float HeatCapacity
{
@@ -107,8 +114,6 @@ namespace Content.Server.Atmos
}
}
public float ReactionResultFire { get; set; }
[ViewVariables]
public float ThermalEnergy => Temperature * HeatCapacity;
@@ -452,19 +457,25 @@ namespace Content.Server.Atmos
temperature < prototype.MinimumTemperatureRequirement)
continue;
var doReaction = true;
for (var i = 0; i < prototype.MinimumRequirements.Length; i++)
{
if(i > Atmospherics.TotalNumberOfGases)
throw new IndexOutOfRangeException("Reaction Gas Minimum Requirements Array Prototype exceeds total number of gases!");
var req = prototype.MinimumRequirements[i];
if (GetMoles(i) < req)
continue;
reaction = prototype.React(this, holder);
if(reaction.HasFlag(ReactionResult.StopReactions))
break;
if (!(GetMoles(i) < req)) continue;
doReaction = false;
break;
}
if (!doReaction)
continue;
reaction = prototype.React(this, holder);
if(reaction.HasFlag(ReactionResult.StopReactions))
break;
}
return reaction;

View File

@@ -16,6 +16,11 @@ namespace Content.Server.Atmos.Reactions
StopReactions = 2,
}
public enum GasReaction : byte
{
Fire = 0,
}
[Prototype("gasReaction")]
public class GasReactionPrototype : IPrototype, IIndexedPrototype
{

View File

@@ -3,6 +3,7 @@ using CannyFastMath;
using Content.Server.Interfaces;
using Content.Shared.Atmos;
using JetBrains.Annotations;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
namespace Content.Server.Atmos.Reactions
@@ -53,7 +54,7 @@ namespace Content.Server.Atmos.Reactions
energyReleased += Atmospherics.FirePhoronEnergyReleased * (phoronBurnRate);
mixture.ReactionResultFire += (phoronBurnRate) * (1 + oxygenBurnRate);
mixture.ReactionResults[GasReaction.Fire] += (phoronBurnRate) * (1 + oxygenBurnRate);
}
}
@@ -69,15 +70,15 @@ namespace Content.Server.Atmos.Reactions
temperature = mixture.Temperature;
if (temperature > Atmospherics.FireMinimumTemperatureToExist)
{
location.HotspotExpose(temperature, Atmospherics.CellVolume);
location.HotspotExpose(temperature, mixture.Volume);
// TODO ATMOS Expose temperature all items on cell
location.TemperatureExpose(mixture, temperature, Atmospherics.CellVolume);
location.TemperatureExpose(mixture, temperature, mixture.Volume);
}
}
return mixture.ReactionResultFire != 0 ? ReactionResult.Reacting : ReactionResult.NoReaction;
return mixture.ReactionResults[GasReaction.Fire] != 0 ? ReactionResult.Reacting : ReactionResult.NoReaction;
}
public void ExposeData(ObjectSerializer serializer)

View File

@@ -0,0 +1,78 @@
#nullable enable
using Content.Server.Interfaces;
using Content.Shared.Atmos;
using JetBrains.Annotations;
using Robust.Shared.Serialization;
namespace Content.Server.Atmos.Reactions
{
[UsedImplicitly]
public class TritiumFireReaction : IGasReactionEffect
{
public void ExposeData(ObjectSerializer serializer)
{
}
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder)
{
var energyReleased = 0f;
var oldHeatCapacity = mixture.HeatCapacity;
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;
}
if (energyReleased > 0)
{
var newHeatCapacity = mixture.HeatCapacity;
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
mixture.Temperature = ((temperature * oldHeatCapacity + energyReleased) / newHeatCapacity);
}
if (location != null)
{
temperature = mixture.Temperature;
if (temperature > Atmospherics.FireMinimumTemperatureToExist)
{
location.HotspotExpose(temperature, mixture.Volume);
// TODO ATMOS Expose temperature all items on cell
location.TemperatureExpose(mixture, temperature, mixture.Volume);
}
}
return mixture.ReactionResults[GasReaction.Fire] != 0 ? ReactionResult.Reacting : ReactionResult.NoReaction;
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Content.Server.Atmos.Reactions;
using Content.Server.GameObjects.Components.Atmos;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
@@ -686,7 +687,7 @@ namespace Content.Server.Atmos
if (Hotspot.Bypassing)
{
Hotspot.Volume = Air.ReactionResultFire * Atmospherics.FireGrowthRate;
Hotspot.Volume = Air.ReactionResults[GasReaction.Fire] * Atmospherics.FireGrowthRate;
Hotspot.Temperature = Air.Temperature;
}
else
@@ -697,7 +698,7 @@ namespace Content.Server.Atmos
affected.Temperature = Hotspot.Temperature;
affected.React(this);
Hotspot.Temperature = affected.Temperature;
Hotspot.Volume = affected.ReactionResultFire * Atmospherics.FireGrowthRate;
Hotspot.Volume = affected.ReactionResults[GasReaction.Fire] * Atmospherics.FireGrowthRate;
AssumeAir(affected);
}
}