From 07bd88a2ff0185abb529128b3f377a08cdaa15df Mon Sep 17 00:00:00 2001 From: Migratingcocofruit <69551563+Migratingcocofruit@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:20:40 +0300 Subject: [PATCH] Fixes N2O not decomposing above 100000 Kelvin (#26817) * Replaces the N2O decomposition function with one that is slightly above 0 at 1400 Kelvin and approaches 1 as temp increases. * adds a min check to the calculation of the amount to decompose --- code/__DEFINES/atmospherics_defines.dm | 7 +++++- .../atmospherics/gasmixtures/gas_mixture.dm | 22 +++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/code/__DEFINES/atmospherics_defines.dm b/code/__DEFINES/atmospherics_defines.dm index eff495a0665..2df5b9f0a2f 100644 --- a/code/__DEFINES/atmospherics_defines.dm +++ b/code/__DEFINES/atmospherics_defines.dm @@ -151,7 +151,12 @@ // Reactions #define N2O_DECOMPOSITION_MIN_ENERGY 1400 #define N2O_DECOMPOSITION_ENERGY_RELEASED 200000 - +/// The coefficient a for a function of the form: 1 - (a / (x + c)^2) which gives a decomposition rate of 0.5 at 50000 Kelvin +/// And a decomposition close to 0 at 1400 Kelvin +#define N2O_DECOMPOSITION_COEFFICIENT_A 1.376651173e10 +/// The coefficient c for a function of the form: 1 - (a / (x + c)^2) which gives a decomposition rate of 0.5 at 50000 Kelvin +/// And a decomposition rate close to 0 at 1400 Kelvin +#define N2O_DECOMPOSITION_COEFFICIENT_C 115930.77913 // From milla/src/model.rs, line 126 #define ATMOS_MODE_SPACE 0 //! Tile is exposed to space and loses air every second #define ATMOS_MODE_SEALED 1 //! Tile has no special behaviour diff --git a/code/modules/atmospherics/gasmixtures/gas_mixture.dm b/code/modules/atmospherics/gasmixtures/gas_mixture.dm index 86cd73ec61b..aa1abcaf979 100644 --- a/code/modules/atmospherics/gasmixtures/gas_mixture.dm +++ b/code/modules/atmospherics/gasmixtures/gas_mixture.dm @@ -574,21 +574,19 @@ What are the archived variables for? var/energy_released = 0 var/old_heat_capacity = heat_capacity() var/burned_fuel = 0 + burned_fuel = min((1 - (N2O_DECOMPOSITION_COEFFICIENT_A / ((private_temperature + N2O_DECOMPOSITION_COEFFICIENT_C) ** 2))) * private_sleeping_agent, private_sleeping_agent) + private_sleeping_agent -= burned_fuel - burned_fuel = max(0, 0.00002 * (private_temperature - (0.00001 * (private_temperature ** 2)))) * private_sleeping_agent - if(private_sleeping_agent - burned_fuel > 0) - private_sleeping_agent -= burned_fuel + if(burned_fuel) + energy_released += (N2O_DECOMPOSITION_ENERGY_RELEASED * burned_fuel) - if(burned_fuel) - energy_released += (N2O_DECOMPOSITION_ENERGY_RELEASED * burned_fuel) + private_oxygen += burned_fuel * 0.5 + private_nitrogen += burned_fuel - private_oxygen += burned_fuel * 0.5 - private_nitrogen += burned_fuel - - var/new_heat_capacity = heat_capacity() - if(new_heat_capacity > MINIMUM_HEAT_CAPACITY) - private_temperature = (private_temperature * old_heat_capacity + energy_released) / new_heat_capacity - reacting = TRUE + var/new_heat_capacity = heat_capacity() + if(new_heat_capacity > MINIMUM_HEAT_CAPACITY) + private_temperature = (private_temperature * old_heat_capacity + energy_released) / new_heat_capacity + reacting = TRUE fuel_burnt = 0 //Handle plasma burning