Skip to content

Commit

Permalink
Fix freon Cooling behaviour (unitystation#10558)
Browse files Browse the repository at this point in the history
* Fix freon cooling

* tweaked requiring to tritium

* This is more generous

* just a trace

---------

Co-authored-by: Bod9001 <[email protected]>
  • Loading branch information
AutumnNova and Bod9001 authored Oct 8, 2024
1 parent f40993f commit 6471534
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ public static class AtmosDefines
public const float FREON_BURN_RATE_DELTA = 4f;
public const float FIRE_FREON_ENERGY_RELEASED = -300000f; //amount of heat absorbed per mole of burnt freon in the tile

public const float FREON_MAXIMUM_BURN_TEMPERATURE = 150f;
public const float FREON_LOWER_TEMPERATURE = 60f; //minimum temperature allowed for the burn to go, we would have negative pressure otherwise
public const float FREON_MAXIMUM_BURN_TEMPERATURE = 323.15f;
public const float FREON_LOWER_TEMPERATURE = 223.15f; //minimum temperature allowed for the burn to go, we would have negative pressure otherwise

public const float FREON_TRITIUM_MAXIMUM_BURN_TEMPERATURE = 323.15f;
public const float FREON_TRITIUM_LOWER_TEMPERATURE = 60f; //minimum temperature allowed for the burn to go, we would have negative pressure otherwise


public const float FREON_OXYGEN_FULLBURN = 10f;

public const float N2O_DECOMPOSITION_MIN_ENERGY = 1400f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Systems.Atmospherics
public class FreonFireReaction : Reaction
{
private static System.Random rnd = new System.Random();

public bool Satisfies(GasMix gasMix)
{
throw new System.NotImplementedException();
Expand All @@ -15,20 +16,42 @@ public bool Satisfies(GasMix gasMix)
public void React(GasMix gasMix, MetaDataNode node)
{
var energyReleased = 0f;
var OldTemperature = gasMix.Temperature;

var temperatureScale = 1f;

if (gasMix.Temperature < AtmosDefines.FREON_LOWER_TEMPERATURE)
if (gasMix.Temperature is < AtmosDefines.FREON_TRITIUM_LOWER_TEMPERATURE
or > AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE)
{
temperatureScale = 0;
}

var TotalMoles = gasMix.Moles;
var TritiumMoles = gasMix.GetMoles(Gas.Tritium);

var HotIceCompatible = false;

if ((TritiumMoles / TotalMoles) > 0.0001f) //0.01%
{
HotIceCompatible = true;
temperatureScale = (AtmosDefines.FREON_TRITIUM_MAXIMUM_BURN_TEMPERATURE - gasMix.Temperature) /
(AtmosDefines.FREON_TRITIUM_MAXIMUM_BURN_TEMPERATURE - AtmosDefines.FREON_TRITIUM_LOWER_TEMPERATURE);
}
else
{
temperatureScale = (AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE - gasMix.Temperature) / (AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE - AtmosDefines.FREON_LOWER_TEMPERATURE);
HotIceCompatible = false;
temperatureScale = (AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE - gasMix.Temperature)
/ (AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE - AtmosDefines.FREON_LOWER_TEMPERATURE);

if (gasMix.Temperature is < AtmosDefines.FREON_LOWER_TEMPERATURE
or > AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE)
{
temperatureScale = 0;
}
}

if (temperatureScale >= 0)

var oldHeatCap = gasMix.WholeHeatCapacity;
if (temperatureScale > 0)
{
var oxygenBurnRate = AtmosDefines.OXYGEN_BURN_RATE_BASE - temperatureScale;

Expand All @@ -41,19 +64,21 @@ public void React(GasMix gasMix, MetaDataNode node)
}
else
{
freonBurnRate = (temperatureScale * (gasMix.GetMoles(Gas.Oxygen) / AtmosDefines.FREON_OXYGEN_FULLBURN) / AtmosDefines.FREON_BURN_RATE_DELTA);
freonBurnRate = (temperatureScale *
(gasMix.GetMoles(Gas.Oxygen) / AtmosDefines.FREON_OXYGEN_FULLBURN) /
AtmosDefines.FREON_BURN_RATE_DELTA);
}

if (freonBurnRate > 0.0001f)
{
freonBurnRate = Mathf.Min(freonBurnRate, gasMix.GetMoles(Gas.Freon), gasMix.GetMoles(Gas.Oxygen));
freonBurnRate = Mathf.Min(freonBurnRate, gasMix.GetMoles(Gas.Freon),
gasMix.GetMoles(Gas.Oxygen));

gasMix.RemoveGas(Gas.Freon, freonBurnRate);
gasMix.RemoveGas(Gas.Oxygen, freonBurnRate * oxygenBurnRate);
gasMix.RemoveGas(Gas.Plasma, freonBurnRate);
gasMix.AddGasWithTemperature(Gas.CarbonDioxide, freonBurnRate, gasMix.Temperature);

if (gasMix.Temperature < 160 && gasMix.Temperature > 120 && rnd.Next(0, 2) == 0)
if (gasMix.Temperature < 160 && gasMix.Temperature > 120 && rnd.Next(0, 2) == 0 && HotIceCompatible)
{
SpawnSafeThread.SpawnPrefab(node.WorldPosition, AtmosManager.Instance.HotIce);
}
Expand All @@ -62,11 +87,14 @@ public void React(GasMix gasMix, MetaDataNode node)
}
}

if (Mathf.Abs(energyReleased) < 0)
if (energyReleased < 0)
{
gasMix.Temperature = OldTemperature;
gasMix.InternalEnergy =+ energyReleased;
var newHeatCap = gasMix.WholeHeatCapacity;
if (newHeatCap > 0.0003f)
{
gasMix.SetTemperature((gasMix.Temperature * oldHeatCap + energyReleased) / newHeatCap);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public struct GasReactions
private static GasReactions NitrylForm;
private static GasReactions BZForm;
private static GasReactions FreonForm;
private static GasReactions FreonCold;
private static GasReactions WaterVapour;
private static GasReactions StimulumForm;
private static GasReactions StimBallReaction;
Expand Down Expand Up @@ -141,14 +140,6 @@ public static void SetUpReactions()
minimumMolesToReact = 0.01f
}
},
{
Gas.Plasma,
new GasReactionData()
{
minimumMolesToReact = 0.01f
}
},

},

minimumTileTemperature: 0,
Expand Down Expand Up @@ -476,35 +467,6 @@ public static void SetUpReactions()

#endregion

#region FreonCold

FreonCold = new GasReactions(

reaction: new freonfreeze(),

gasReactionData: new Dictionary<GasSO, GasReactionData>()
{
{
Gas.Freon,
new GasReactionData()
{
minimumMolesToReact = 1
}
},
},

minimumTileTemperature: TemperatureUtils.ZERO_CELSIUS_IN_KELVIN + -45,
maximumTileTemperature: TemperatureUtils.ZERO_CELSIUS_IN_KELVIN + 40f,
minimumTilePressure: 0,
maximumTilePressure: 10000000000,

minimumTileMoles: 5,
maximumTileMoles: 10000000000,
addToBaseReactions: true
);

#endregion

#region WaterVapour

WaterVapour = new GasReactions(
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 6471534

Please sign in to comment.