From 243747057a55e5bbda6c2d4e0acff57a3bcd9b4f Mon Sep 17 00:00:00 2001 From: Ghilker <42839747+Ghilker@users.noreply.github.com> Date: Sun, 8 May 2022 19:19:49 +0200 Subject: [PATCH] Freon reaction rebalance and improvements (#66562) This is the first of hopefully many prs to fix and improve our current reactions to be sane and also easier to understand and explain to players. Current freon reaction is a mess of numbers and incoherent amounts, with consumptions made up and without a logical sense. This PR fixes that by using proper equations and amounts for ratios and formation. Minimum amounts for gases changed from random 40/20/20, to MINIMUM_MOLE_COUNT * 6/1/3 (encourages players to keep the ratio later) --- code/__DEFINES/reactions.dm | 2 -- .../gasmixtures/reaction_factors.dm | 12 +++---- .../atmospherics/gasmixtures/reactions.dm | 31 ++++++++++++------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/code/__DEFINES/reactions.dm b/code/__DEFINES/reactions.dm index dcb6e93a065..91889daaa45 100644 --- a/code/__DEFINES/reactions.dm +++ b/code/__DEFINES/reactions.dm @@ -169,8 +169,6 @@ // Freon: /// The minimum temperature freon can form from plasma, CO2, and BZ at. #define FREON_FORMATION_MIN_TEMPERATURE FIRE_MINIMUM_TEMPERATURE_TO_EXIST + 100 -/// A scaling divisor for the rate of freon formation relative to mix temperature. -#define FREON_FORMATION_TEMP_DIVISOR (FIRE_MINIMUM_TEMPERATURE_TO_EXIST * 10) /// The amount of energy 2.5 moles of freon forming from plasma, CO2, and BZ consumes. #define FREON_FORMATION_ENERGY 100 diff --git a/code/modules/atmospherics/gasmixtures/reaction_factors.dm b/code/modules/atmospherics/gasmixtures/reaction_factors.dm index cad8b68ab96..844a8585ca8 100644 --- a/code/modules/atmospherics/gasmixtures/reaction_factors.dm +++ b/code/modules/atmospherics/gasmixtures/reaction_factors.dm @@ -116,12 +116,12 @@ /datum/gas_reaction/freonformation/init_factors() factor = list( - /datum/gas/plasma = "40 moles of plasma needs to be present for the reaction to occur. Plasma is consumed at 1.5 reaction rate.", - /datum/gas/carbon_dioxide = "20 moles of carbon dioxide needs to be present for the reaction to occur. Carbon dioxide is consumed at 0.75 reaction rate.", - /datum/gas/bz = "20 moles of BZ needs to be present for the reaction to occur. BZ is consumed at 0.25 reaction rate.", - /datum/gas/freon = "Freon is produced at 2.5 reaction rate", - "Energy" = "[FREON_FORMATION_ENERGY] joules of energy is absorbed per reaction rate", - "Temperature" = "Minimum temperature of [FIRE_MINIMUM_TEMPERATURE_TO_EXIST + 100] Kelvin to occur", + /datum/gas/plasma = "At least 0.06 moles of plasma needs to be present. Plasma is consumed at 0.6 moles per tile/pipenet", + /datum/gas/carbon_dioxide = "At least 0.03 moles of CO2 needs to be present. CO2 is consumed at 0.3 moles per tile/pipenet", + /datum/gas/bz = "At least 0.01 moles of BZ needs to be present. BZ is consumed at 0.1 moles per tile/pipenet", + /datum/gas/freon = "Freon is produced at 1 mole per tile/pipenet", + "Energy" = "Between 100 and 800 joules of energy is absorbed per mole of freon produced", + "Temperature" = "Minimum temperature of [FIRE_MINIMUM_TEMPERATURE_TO_EXIST + 100] Kelvin to occur, with production peak at 800 K. However at temperatures above 5500 K higher rates are possible maxing out at three times the low temperature rate at over 8500 K.", ) /datum/gas_reaction/nobliumformation/init_factors() diff --git a/code/modules/atmospherics/gasmixtures/reactions.dm b/code/modules/atmospherics/gasmixtures/reactions.dm index eb690f56119..ea21f3a2fb9 100644 --- a/code/modules/atmospherics/gasmixtures/reactions.dm +++ b/code/modules/atmospherics/gasmixtures/reactions.dm @@ -733,31 +733,38 @@ /datum/gas_reaction/freonformation/init_reqs() //minimum requirements for freon formation requirements = list( - /datum/gas/plasma = 40, - /datum/gas/carbon_dioxide = 20, - /datum/gas/bz = 20, + /datum/gas/plasma = MINIMUM_MOLE_COUNT * 6, + /datum/gas/carbon_dioxide = MINIMUM_MOLE_COUNT * 3, + /datum/gas/bz = MINIMUM_MOLE_COUNT, "MIN_TEMP" = FREON_FORMATION_MIN_TEMPERATURE, ) /datum/gas_reaction/freonformation/react(datum/gas_mixture/air) var/list/cached_gases = air.gases var/temperature = air.temperature - var/heat_efficency = min(temperature / FREON_FORMATION_TEMP_DIVISOR, cached_gases[/datum/gas/plasma][MOLES] * INVERSE(1.5), cached_gases[/datum/gas/carbon_dioxide][MOLES] * INVERSE(0.75), cached_gases[/datum/gas/bz][MOLES] * INVERSE(0.25)) - if (heat_efficency <= 0 || (cached_gases[/datum/gas/plasma][MOLES] - heat_efficency * 1.5 < 0 ) || (cached_gases[/datum/gas/carbon_dioxide][MOLES] - heat_efficency * 0.75 < 0) || (cached_gases[/datum/gas/bz][MOLES] - heat_efficency * 0.25 < 0)) //Shouldn't produce gas from nothing. + var/minimal_mole_factor = min(cached_gases[/datum/gas/plasma][MOLES] * INVERSE(0.6), cached_gases[/datum/gas/bz][MOLES] * INVERSE(0.1), cached_gases[/datum/gas/carbon_dioxide][MOLES] * INVERSE(0.3)) + + var/equation_first_part = NUM_E ** (-((temperature - 800) / 200) ** 2) + var/equation_second_part = 3 / (1 + NUM_E ** (-0.001 * (temperature - 6000))) + var/heat_factor = equation_first_part + equation_second_part + + var/freon_formed = min(heat_factor * minimal_mole_factor * 0.05, cached_gases[/datum/gas/plasma][MOLES] * INVERSE(0.6), cached_gases[/datum/gas/carbon_dioxide][MOLES] * INVERSE(0.3), cached_gases[/datum/gas/bz][MOLES] * INVERSE(0.1)) + if (freon_formed <= 0 || (cached_gases[/datum/gas/plasma][MOLES] - freon_formed * 0.6 < 0 ) || (cached_gases[/datum/gas/carbon_dioxide][MOLES] - freon_formed * 0.3 < 0) || (cached_gases[/datum/gas/bz][MOLES] - freon_formed * 0.1 < 0)) //Shouldn't produce gas from nothing. return NO_REACTION var/old_heat_capacity = air.heat_capacity() ASSERT_GAS(/datum/gas/freon, air) - cached_gases[/datum/gas/plasma][MOLES] -= heat_efficency * 1.5 // 6 - cached_gases[/datum/gas/carbon_dioxide][MOLES] -= heat_efficency * 0.75 // 3 - cached_gases[/datum/gas/bz][MOLES] -= heat_efficency * 0.25 // 1 - cached_gases[/datum/gas/freon][MOLES] += heat_efficency * 2.5 // 10 + cached_gases[/datum/gas/plasma][MOLES] -= freon_formed * 0.6 + cached_gases[/datum/gas/carbon_dioxide][MOLES] -= freon_formed * 0.3 + cached_gases[/datum/gas/bz][MOLES] -= freon_formed * 0.1 + cached_gases[/datum/gas/freon][MOLES] += freon_formed - SET_REACTION_RESULTS(heat_efficency * 2.5) - var/energy_used = heat_efficency * FREON_FORMATION_ENERGY + SET_REACTION_RESULTS(freon_formed) + + var/energy_consumed = (7000 / (1 + NUM_E ** (-0.0015 * (temperature - 6000))) + 1000) * freon_formed * 0.1 var/new_heat_capacity = air.heat_capacity() if(new_heat_capacity > MINIMUM_HEAT_CAPACITY) - air.temperature = max(((temperature * old_heat_capacity - energy_used)/new_heat_capacity), TCMB) + air.temperature = max(((temperature * old_heat_capacity - energy_consumed)/new_heat_capacity), TCMB) return REACTING