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] [ViewVariables]
public float LastShare { get; private set; } = 0; 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] [ViewVariables]
public float HeatCapacity public float HeatCapacity
{ {
@@ -107,8 +114,6 @@ namespace Content.Server.Atmos
} }
} }
public float ReactionResultFire { get; set; }
[ViewVariables] [ViewVariables]
public float ThermalEnergy => Temperature * HeatCapacity; public float ThermalEnergy => Temperature * HeatCapacity;
@@ -452,20 +457,26 @@ namespace Content.Server.Atmos
temperature < prototype.MinimumTemperatureRequirement) temperature < prototype.MinimumTemperatureRequirement)
continue; continue;
var doReaction = true;
for (var i = 0; i < prototype.MinimumRequirements.Length; i++) for (var i = 0; i < prototype.MinimumRequirements.Length; i++)
{ {
if(i > Atmospherics.TotalNumberOfGases) if(i > Atmospherics.TotalNumberOfGases)
throw new IndexOutOfRangeException("Reaction Gas Minimum Requirements Array Prototype exceeds total number of gases!"); throw new IndexOutOfRangeException("Reaction Gas Minimum Requirements Array Prototype exceeds total number of gases!");
var req = prototype.MinimumRequirements[i]; var req = prototype.MinimumRequirements[i];
if (GetMoles(i) < req)
if (!(GetMoles(i) < req)) continue;
doReaction = false;
break;
}
if (!doReaction)
continue; continue;
reaction = prototype.React(this, holder); reaction = prototype.React(this, holder);
if(reaction.HasFlag(ReactionResult.StopReactions)) if(reaction.HasFlag(ReactionResult.StopReactions))
break; break;
} }
}
return reaction; return reaction;
} }

View File

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

View File

@@ -3,6 +3,7 @@ using CannyFastMath;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Log;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Server.Atmos.Reactions namespace Content.Server.Atmos.Reactions
@@ -53,7 +54,7 @@ namespace Content.Server.Atmos.Reactions
energyReleased += Atmospherics.FirePhoronEnergyReleased * (phoronBurnRate); 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; temperature = mixture.Temperature;
if (temperature > Atmospherics.FireMinimumTemperatureToExist) if (temperature > Atmospherics.FireMinimumTemperatureToExist)
{ {
location.HotspotExpose(temperature, Atmospherics.CellVolume); location.HotspotExpose(temperature, mixture.Volume);
// TODO ATMOS Expose temperature all items on cell // 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) 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Content.Server.Atmos.Reactions;
using Content.Server.GameObjects.Components.Atmos; using Content.Server.GameObjects.Components.Atmos;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces; using Content.Server.Interfaces;
@@ -686,7 +687,7 @@ namespace Content.Server.Atmos
if (Hotspot.Bypassing) if (Hotspot.Bypassing)
{ {
Hotspot.Volume = Air.ReactionResultFire * Atmospherics.FireGrowthRate; Hotspot.Volume = Air.ReactionResults[GasReaction.Fire] * Atmospherics.FireGrowthRate;
Hotspot.Temperature = Air.Temperature; Hotspot.Temperature = Air.Temperature;
} }
else else
@@ -697,7 +698,7 @@ namespace Content.Server.Atmos
affected.Temperature = Hotspot.Temperature; affected.Temperature = Hotspot.Temperature;
affected.React(this); affected.React(this);
Hotspot.Temperature = affected.Temperature; Hotspot.Temperature = affected.Temperature;
Hotspot.Volume = affected.ReactionResultFire * Atmospherics.FireGrowthRate; Hotspot.Volume = affected.ReactionResults[GasReaction.Fire] * Atmospherics.FireGrowthRate;
AssumeAir(affected); AssumeAir(affected);
} }
} }

View File

@@ -143,8 +143,12 @@ namespace Content.Shared.Atmos
/// <summary> /// <summary>
/// Total number of gases. Increase this if you want to add more! /// Total number of gases. Increase this if you want to add more!
/// </summary> /// </summary>
public const int TotalNumberOfGases = 5; public const int TotalNumberOfGases = 6;
/// <summary>
/// Amount of heat released per mole of burnt hydrogen or tritium (hydrogen isotope)
/// </summary>
public const float FireHydrogenEnergyReleased = 560000f;
public const float FireMinimumTemperatureToExist = T0C + 100f; public const float FireMinimumTemperatureToExist = T0C + 100f;
public const float FireMinimumTemperatureToSpread = T0C + 150f; public const float FireMinimumTemperatureToSpread = T0C + 150f;
public const float FireSpreadRadiosityScale = 0.85f; public const float FireSpreadRadiosityScale = 0.85f;
@@ -159,6 +163,14 @@ namespace Content.Shared.Atmos
public const float PhoronOxygenFullburn = 10f; public const float PhoronOxygenFullburn = 10f;
public const float PhoronBurnRateDelta = 9f; public const float PhoronBurnRateDelta = 9f;
/// <summary>
/// This is calculated to help prevent singlecap bombs (Overpowered tritium/oxygen single tank bombs)
/// </summary>
public const float MinimumTritiumOxyburnEnergy = 2000000f;
public const float TritiumBurnOxyFactor = 100f;
public const float TritiumBurnTritFactor = 10f;
/// <summary> /// <summary>
/// Determines at what pressure the ultra-high pressure red icon is displayed. /// Determines at what pressure the ultra-high pressure red icon is displayed.
/// </summary> /// </summary>
@@ -208,5 +220,6 @@ namespace Content.Shared.Atmos
CarbonDioxide = 2, CarbonDioxide = 2,
Phoron = 3, Phoron = 3,
Tritium = 4, Tritium = 4,
WaterVapor = 5,
} }
} }

View File

@@ -31,3 +31,11 @@
gasOverlaySprite: /Textures/Effects/atmospherics.rsi gasOverlaySprite: /Textures/Effects/atmospherics.rsi
gasOverlayState: tritium gasOverlayState: tritium
color: 13FF4B color: 13FF4B
- type: gas
id: 5
name: Water Vapor
specificHeat: 40
gasOverlaySprite: /Textures/Effects/atmospherics.rsi
gasOverlayState: water_vapor
color: bffffd

View File

@@ -9,3 +9,16 @@
- 0.01 # phoron - 0.01 # phoron
effects: effects:
- !type:PhoronFireReaction {} - !type:PhoronFireReaction {}
- type: gasReaction
id: TritiumFire
priority: -1
minimumTemperature: 373.149 # Same as Atmospherics.FireMinimumTemperatureToExist
minimumRequirements: # In this case, same as minimum mole count.
- 0.01 # oxygen
- 0 # nitrogen
- 0 # carbon dioxide
- 0 # phoron
- 0.01 # tritium
effects:
- !type:TritiumFireReaction {}