From 6471534c8a7ba18114056b4e65a6db27ffc369cb Mon Sep 17 00:00:00 2001 From: Autumn <55225562+AutumnNova@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:05:50 +1100 Subject: [PATCH] Fix freon Cooling behaviour (#10558) * Fix freon cooling * tweaked requiring to tritium * This is more generous * just a trace --------- Co-authored-by: Bod9001 --- .../Meta/Atmospherics/AtmosDefines.cs | 9 +++- .../Data/Reactions/FreonFireReaction.cs | 52 ++++++++++++++----- .../Atmospherics/Data/Reactions/Reaction.cs | 38 -------------- .../Data/Reactions/freonfreeze.cs | 18 ------- .../Data/Reactions/freonfreeze.cs.meta | 2 - 5 files changed, 47 insertions(+), 72 deletions(-) delete mode 100644 UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/freonfreeze.cs delete mode 100644 UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/freonfreeze.cs.meta diff --git a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/AtmosDefines.cs b/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/AtmosDefines.cs index 192cac8b0d7..f930ebf55ed 100644 --- a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/AtmosDefines.cs +++ b/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/AtmosDefines.cs @@ -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; diff --git a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/FreonFireReaction.cs b/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/FreonFireReaction.cs index 431efc71709..2cc067c86f1 100644 --- a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/FreonFireReaction.cs +++ b/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/FreonFireReaction.cs @@ -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(); @@ -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; @@ -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); } @@ -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); + } } } } -} +} \ No newline at end of file diff --git a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/Reaction.cs b/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/Reaction.cs index b9b9ef792db..2b395ebc2a0 100644 --- a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/Reaction.cs +++ b/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/Reaction.cs @@ -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; @@ -141,14 +140,6 @@ public static void SetUpReactions() minimumMolesToReact = 0.01f } }, - { - Gas.Plasma, - new GasReactionData() - { - minimumMolesToReact = 0.01f - } - }, - }, minimumTileTemperature: 0, @@ -476,35 +467,6 @@ public static void SetUpReactions() #endregion - #region FreonCold - - FreonCold = new GasReactions( - - reaction: new freonfreeze(), - - gasReactionData: new Dictionary() - { - { - 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( diff --git a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/freonfreeze.cs b/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/freonfreeze.cs deleted file mode 100644 index 6b266ca11a2..00000000000 --- a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/freonfreeze.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using Systems.Atmospherics; -using UnityEngine; -using Reaction = Chemistry.Reaction; - -public class freonfreeze : Systems.Atmospherics.Reaction -{ - public bool Satisfies(GasMix gasMix) - { - throw new System.NotImplementedException(); - } - - public void React(GasMix gasMix, MetaDataNode node) - { - gasMix.SetTemperature(TemperatureUtils.ZERO_CELSIUS_IN_KELVIN - 50f); - } -} \ No newline at end of file diff --git a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/freonfreeze.cs.meta b/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/freonfreeze.cs.meta deleted file mode 100644 index bea6e1b06e3..00000000000 --- a/UnityProject/Assets/Scripts/Tilemaps/Behaviours/Meta/Atmospherics/Data/Reactions/freonfreeze.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 23e6e3ebc3d015a4abbdbb233d7988ad \ No newline at end of file