Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atmos gaming #203

Merged
merged 3 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Content.Server/Atmos/EntitySystems/AtmosphereSystem.Hotspot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void ProcessHotspot(GridAtmosphereComponent gridAtmosphere, TileAtmosphe
ExcitedGroupResetCooldowns(tile.ExcitedGroup);

if ((tile.Hotspot.Temperature < Atmospherics.FireMinimumTemperatureToExist) || (tile.Hotspot.Volume <= 1f)
|| tile.Air == null || tile.Air.GetMoles(Gas.Oxygen) < 0.5f || (tile.Air.GetMoles(Gas.Plasma) < 0.5f && tile.Air.GetMoles(Gas.Tritium) < 0.5f))
|| tile.Air == null || tile.Air.GetMoles(Gas.Oxygen) < 0.5f || (tile.Air.GetMoles(Gas.Plasma) < 0.5f && tile.Air.GetMoles(Gas.Tritium) < 0.5f && tile.Air.GetMoles(Gas.Hydrogen) < 0.5f && tile.Air.GetMoles(Gas.HyperNoblium) > 5f))
{
tile.Hotspot = new Hotspot();
InvalidateVisuals(tile.GridIndex, tile.GridIndices);
Expand Down Expand Up @@ -108,12 +108,14 @@ private void HotspotExpose(GridAtmosphereComponent gridAtmosphere, TileAtmospher

var plasma = tile.Air.GetMoles(Gas.Plasma);
var tritium = tile.Air.GetMoles(Gas.Tritium);
var hydrogen = tile.Air.GetMoles(Gas.Hydrogen);
var hypernoblium = tile.Air.GetMoles(Gas.HyperNoblium);

if (tile.Hotspot.Valid)
{
if (soh)
{
if (plasma > 0.5f || tritium > 0.5f)
if (plasma > 0.5f && hypernoblium < 5f || tritium > 0.5f && hypernoblium < 5f || hydrogen > 0.5f && hypernoblium < 5f)
{
if (tile.Hotspot.Temperature < exposedTemperature)
tile.Hotspot.Temperature = exposedTemperature;
Expand All @@ -125,10 +127,10 @@ private void HotspotExpose(GridAtmosphereComponent gridAtmosphere, TileAtmospher
return;
}

if ((exposedTemperature > Atmospherics.PlasmaMinimumBurnTemperature) && (plasma > 0.5f || tritium > 0.5f))
if ((exposedTemperature > Atmospherics.PlasmaMinimumBurnTemperature) && (plasma > 0.5f && hypernoblium < 5f || tritium > 0.5f && hypernoblium < 5f || hydrogen > 0.5f && hypernoblium < 5f))
{
if (sparkSourceUid.HasValue)
_adminLog.Add(LogType.Flammable, LogImpact.High, $"Heat/spark of {ToPrettyString(sparkSourceUid.Value)} caused atmos ignition of gas: {tile.Air.Temperature.ToString():temperature}K - {oxygen}mol Oxygen, {plasma}mol Plasma, {tritium}mol Tritium");
_adminLog.Add(LogType.Flammable, LogImpact.High, $"Heat/spark of {ToPrettyString(sparkSourceUid.Value)} caused atmos ignition of gas: {tile.Air.Temperature.ToString():temperature}K - {oxygen}mol Oxygen, {plasma}mol Plasma, {tritium}mol Tritium, {hydrogen}mol Hydrogen");

tile.Hotspot = new Hotspot
{
Expand Down
13 changes: 12 additions & 1 deletion Content.Server/Atmos/Portable/PortableScrubberComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ public sealed class PortableScrubberComponent : Component
Gas.WaterVapor,
Gas.Miasma,
Gas.NitrousOxide,
Gas.Frezon
Gas.Frezon,
Gas.BZ,
Gas.Pluoxium,
Gas.Hydrogen,
Gas.Nitrium,
Gas.Healium,
Gas.HyperNoblium,
Gas.ProtoNitrate,
Gas.Zauker,
Gas.Halon,
Gas.Helium,
Gas.AntiNoblium
};

[ViewVariables(VVAccess.ReadWrite)]
Expand Down
50 changes: 50 additions & 0 deletions Content.Server/Atmos/Reactions/BZProductionReaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Atmos;
using JetBrains.Annotations;

namespace Content.Server.Atmos.Reactions;

[UsedImplicitly]
public sealed class BZProductionReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var initialNitrousOxide = mixture.GetMoles(Gas.NitrousOxide);
var initialPlasma = mixture.GetMoles(Gas.Plasma);

var environmentEfficiency = mixture.Volume / mixture.Pressure;
var ratioEfficiency = Math.Min(initialNitrousOxide / initialPlasma, 1);

var BZFormed = Math.Min(0.01f * ratioEfficiency * environmentEfficiency, Math.Min(initialNitrousOxide * 0.4f, initialPlasma * 0.8f));

if (initialNitrousOxide - BZFormed * 0.4f < 0 || initialPlasma - (0.8f - BZFormed) < 0 || BZFormed <= 0)
return ReactionResult.NoReaction;

var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);

var amountDecomposed = 0.0f;
var nitrousOxideDecomposedFactor = Math.Max(4.0f * (initialPlasma / (initialNitrousOxide + initialPlasma) - 0.75f), 0);
if (nitrousOxideDecomposedFactor > 0)
{
amountDecomposed = 0.4f * BZFormed * nitrousOxideDecomposedFactor;
mixture.AdjustMoles(Gas.Oxygen, amountDecomposed);
mixture.AdjustMoles(Gas.Nitrogen, 0.5f * amountDecomposed);
}

mixture.AdjustMoles(Gas.BZ, Math.Max(0f, BZFormed * (1.0f - nitrousOxideDecomposedFactor)));
mixture.AdjustMoles(Gas.NitrousOxide, -0.4f * BZFormed);
mixture.AdjustMoles(Gas.Plasma, -0.8f * BZFormed * (1.0f - nitrousOxideDecomposedFactor));

var energyReleased = BZFormed * (Atmospherics.BZFormationEnergy + nitrousOxideDecomposedFactor * (Atmospherics.NitrousOxideDecompositionEnergy - Atmospherics.BZFormationEnergy));

var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
mixture.Temperature = Math.Max((mixture.Temperature * oldHeatCapacity + energyReleased) / newHeatCapacity, Atmospherics.TCMB);

return ReactionResult.Reacting;
}
}
4 changes: 4 additions & 0 deletions Content.Server/Atmos/Reactions/FrezonCoolantReaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public sealed class FrezonCoolantReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
var temperature = mixture.Temperature;

Expand Down
4 changes: 4 additions & 0 deletions Content.Server/Atmos/Reactions/FrezonProductionReaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public sealed class FrezonProductionReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var initialN2 = mixture.GetMoles(Gas.Nitrogen);
var initialOxy = mixture.GetMoles(Gas.Oxygen);
var initialTrit = mixture.GetMoles(Gas.Tritium);
Expand Down
38 changes: 38 additions & 0 deletions Content.Server/Atmos/Reactions/HalonOxygenAbsorptionReaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Atmos;
using JetBrains.Annotations;

namespace Content.Server.Atmos.Reactions;

[UsedImplicitly]
public sealed class HalonOxygenAbsorptionReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var initialHalon = mixture.GetMoles(Gas.Halon);
var initialOxygen = mixture.GetMoles(Gas.Oxygen);

var temperature = mixture.Temperature;

var heatEfficiency = Math.Min(temperature / (Atmospherics.FireMinimumTemperatureToExist * 10f), Math.Min(initialHalon, initialOxygen*20f));
if (heatEfficiency <= 0f || initialHalon - heatEfficiency < 0f || initialOxygen - heatEfficiency * 20f < 0f)
return ReactionResult.NoReaction;

var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);

mixture.AdjustMoles(Gas.Halon, -heatEfficiency);
mixture.AdjustMoles(Gas.Oxygen, -heatEfficiency*20f);
mixture.AdjustMoles(Gas.CarbonDioxide, heatEfficiency*5f);

var energyUsed = heatEfficiency * Atmospherics.HalonCombustionEnergy;
var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
mixture.Temperature = Math.Max((mixture.Temperature * oldHeatCapacity + energyUsed) / newHeatCapacity, Atmospherics.TCMB);

return ReactionResult.Reacting;
}
}
39 changes: 39 additions & 0 deletions Content.Server/Atmos/Reactions/HealiumProductionReaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Atmos;
using JetBrains.Annotations;

namespace Content.Server.Atmos.Reactions;

[UsedImplicitly]
public sealed class HealiumProductionReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var initialBZ = mixture.GetMoles(Gas.BZ);
var initialFrezon = mixture.GetMoles(Gas.Frezon);

var temperature = mixture.Temperature;
var heatEfficiency = Math.Min(temperature*0.3f, Math.Min(initialFrezon*2.75f, initialBZ*0.25f));

if (heatEfficiency <= 0 || initialFrezon - heatEfficiency * 2.75f < 0 || initialBZ - heatEfficiency * 0.25f < 0)
return ReactionResult.NoReaction;

var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);

mixture.AdjustMoles(Gas.Frezon, -heatEfficiency*2.75f);
mixture.AdjustMoles(Gas.BZ, -heatEfficiency*0.25f);
mixture.AdjustMoles(Gas.Healium, heatEfficiency*3);

var energyReleased = heatEfficiency * Atmospherics.HealiumFormationEnergy;

var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
mixture.Temperature = Math.Max((mixture.Temperature * oldHeatCapacity + energyReleased) / newHeatCapacity, Atmospherics.TCMB);

return ReactionResult.Reacting;
}
}
58 changes: 58 additions & 0 deletions Content.Server/Atmos/Reactions/HydrogenFireReaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Atmos;
using JetBrains.Annotations;

namespace Content.Server.Atmos.Reactions
{
[UsedImplicitly]
[DataDefinition]
public sealed class HydrogenFireReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var energyReleased = 0f;
var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
var temperature = mixture.Temperature;
var location = holder as TileAtmosphere;
mixture.ReactionResults[GasReaction.Fire] = 0;

var initialOxygen = mixture.GetMoles(Gas.Oxygen);
var initialHydrogen = mixture.GetMoles(Gas.Hydrogen);

var burnedFuel = Math.Min(initialHydrogen / Atmospherics.FireH2BurnRateDelta, Math.Min(initialOxygen / (Atmospherics.FireH2BurnRateDelta * Atmospherics.H2OxygenFullBurn), Math.Min(initialHydrogen, initialOxygen * 0.5f)));

if (burnedFuel > 0)
{
energyReleased += Atmospherics.FireH2EnergyReleased * burnedFuel;

mixture.AdjustMoles(Gas.WaterVapor, burnedFuel);
mixture.AdjustMoles(Gas.Hydrogen, -burnedFuel);
mixture.AdjustMoles(Gas.Oxygen, -burnedFuel * 0.5f);

mixture.ReactionResults[GasReaction.Fire] += burnedFuel;
}

if (energyReleased > 0)
{
var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
mixture.Temperature = (temperature * oldHeatCapacity + energyReleased) / newHeatCapacity;
}

if (location != null)
{
temperature = mixture.Temperature;
if (temperature > Atmospherics.FireMinimumTemperatureToExist)
{
atmosphereSystem.HotspotExpose(location.GridIndex, location.GridIndices, temperature, mixture.Volume);
}
}

return mixture.ReactionResults[GasReaction.Fire] != 0 ? ReactionResult.Reacting : ReactionResult.NoReaction;
}
}
}
40 changes: 40 additions & 0 deletions Content.Server/Atmos/Reactions/HyperNobliumProductionReaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Atmos;
using JetBrains.Annotations;

namespace Content.Server.Atmos.Reactions;

[UsedImplicitly]
public sealed class HyperNobliumProductionReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var initialNitrogen = mixture.GetMoles(Gas.Nitrogen);
var initialTritium = mixture.GetMoles(Gas.Tritium);
var initialBZ = mixture.GetMoles(Gas.BZ);

var nobFormed = Math.Min((initialNitrogen+initialTritium)*0.01f,Math.Min(initialTritium*5f, initialNitrogen*10f));
if (nobFormed <= 0 || (initialTritium - 5f) * nobFormed < 0 || (initialNitrogen - 10f) * nobFormed < 0)
return ReactionResult.NoReaction;

var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);

var reductionFactor = Math.Clamp(initialTritium/(initialTritium+initialBZ), 0.001f, 1f);

mixture.AdjustMoles(Gas.Tritium, -5f * nobFormed * reductionFactor);
mixture.AdjustMoles(Gas.Nitrogen, -10f * nobFormed);
mixture.AdjustMoles(Gas.HyperNoblium, nobFormed);

var energyReleased = nobFormed * (Atmospherics.NobliumFormationEnergy/Math.Max(initialBZ, 1));

var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
mixture.Temperature = Math.Max((mixture.Temperature * oldHeatCapacity + energyReleased) / newHeatCapacity, Atmospherics.TCMB);

return ReactionResult.Reacting;
}
}
4 changes: 4 additions & 0 deletions Content.Server/Atmos/Reactions/MiasmicSubsumationReaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public sealed class MiasmicSubsumationReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var initialMiasma = mixture.GetMoles(Gas.Miasma);
var initialFrezon = mixture.GetMoles(Gas.Frezon);

Expand Down
38 changes: 38 additions & 0 deletions Content.Server/Atmos/Reactions/NitriumDecompositionReaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Atmos;
using JetBrains.Annotations;

namespace Content.Server.Atmos.Reactions;

[UsedImplicitly]
public sealed class NitriumDecompositionReaction : IGasReactionEffect
{
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, AtmosphereSystem atmosphereSystem)
{
var initialHyperNoblium = mixture.GetMoles(Gas.HyperNoblium);
if (initialHyperNoblium >= 5.0f && mixture.Temperature > 20f)
return ReactionResult.NoReaction;

var initialNitrium = mixture.GetMoles(Gas.Nitrium);

var temperature = mixture.Temperature;
var heatEfficiency = Math.Min(temperature / Atmospherics.NitriumDecompositionTempDivisor, initialNitrium);

if (heatEfficiency <= 0 || initialNitrium - heatEfficiency < 0)
return ReactionResult.NoReaction;

var oldHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);

mixture.AdjustMoles(Gas.Nitrium, -heatEfficiency);
mixture.AdjustMoles(Gas.Hydrogen, heatEfficiency);
mixture.AdjustMoles(Gas.Nitrogen, heatEfficiency);

var energyReleased = heatEfficiency * Atmospherics.NitriumDecompositionEnergy;

var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
if (newHeatCapacity > Atmospherics.MinimumHeatCapacity)
mixture.Temperature = Math.Max((mixture.Temperature * oldHeatCapacity + energyReleased) / newHeatCapacity, Atmospherics.TCMB);

return ReactionResult.Reacting;
}
}
Loading