From 499f02a77e37802c27dbcaa2ed94b5ad76475631 Mon Sep 17 00:00:00 2001 From: SnoopCooper Date: Tue, 7 Jun 2022 06:52:52 +0200 Subject: [PATCH] Reworks the BZ reaction slightly (#66583) Makes BZ reaction rates between pipes and turfs consistent. Removes O2 production from the BZ reaction. Also fixes rate multiplication by splitting pipenets using valves or similar. Makes BZ rates consistent and makes pipebased BZ setups actually produce gas in significant amounts. Makes multiplying reaction rates for BZ by splitting pipenets impossible. Simplifies the reaction by removing a largely unused, mostly unknown way of making o2. BZ production rates between pipes and turfs are now consistent. O2 production removed. Multiplying production rates by splitting pipenets no longer possible. --- code/__DEFINES/reactions.dm | 4 +- .../gasmixtures/reaction_factors.dm | 12 +++--- .../atmospherics/gasmixtures/reactions.dm | 42 +++++++++++-------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/code/__DEFINES/reactions.dm b/code/__DEFINES/reactions.dm index 91889daaa45..8d367cea185 100644 --- a/code/__DEFINES/reactions.dm +++ b/code/__DEFINES/reactions.dm @@ -138,8 +138,8 @@ // BZ: /// The maximum temperature BZ can form at. Deliberately set lower than the minimum burn temperature for most combustible gases in an attempt to prevent long fuse singlecaps. #define BZ_FORMATION_MAX_TEMPERATURE (FIRE_MINIMUM_TEMPERATURE_TO_EXIST - 60) // Yes, someone used this as a bomb timer. I hate players. -/// The amount of energy ~2.5 moles of BZ forming from N2O and plasma releases. -#define BZ_FORMATION_ENERGY FIRE_CARBON_ENERGY_RELEASED +/// The amount of energy 1 mole of BZ forming from N2O and plasma releases. +#define BZ_FORMATION_ENERGY 80000 // Pluoxium: /// The minimum temperature pluoxium can form from carbon dioxide, oxygen, and tritium at. diff --git a/code/modules/atmospherics/gasmixtures/reaction_factors.dm b/code/modules/atmospherics/gasmixtures/reaction_factors.dm index 844a8585ca8..eb65ea64637 100644 --- a/code/modules/atmospherics/gasmixtures/reaction_factors.dm +++ b/code/modules/atmospherics/gasmixtures/reaction_factors.dm @@ -75,12 +75,12 @@ /datum/gas_reaction/bzformation/init_factors() factor = list( - /datum/gas/plasma = "Plasma is consumed at 2 reaction rate. If there is more plasma than nitrous oxide reaction rate is slowed down.", - /datum/gas/nitrous_oxide = "Nitrous oxide is consumed at 1 reaction rate. If there is less nitrous oxide than plasma the reaction rate is slowed down.", - /datum/gas/bz = "BZ is formed at 2.5 reaction rate. A small malus up to half a mole per tick is applied if the reaction rate is constricted by nitrous oxide.", - /datum/gas/oxygen = "Oxygen is produced from the BZ malus. This only happens when the reaction rate is being constricted by the amount of nitrous oxide present. I.E. amount of nitrous oxide is less than the reaction rate.", // Less than the reaction rate AND half the plasma, but suppose that's not necessary to mention. - "Pressure" = "The lower the pressure the faster the reaction rate goes.", - "Energy" = "[FIRE_CARBON_ENERGY_RELEASED] joules of energy is released per reaction rate", + /datum/gas/plasma = "Each mole of BZ made consumes 0.8 moles of plasma. If there is more plasma than nitrous oxide reaction rate is slowed down.", + /datum/gas/nitrous_oxide = "Each mole of bz made consumes 0.4 moles of Nitrous oxide. If there is less nitrous oxide than plasma the reaction rate is slowed down. At three times the amount of plasma to Nitrous oxide it will start breaking down into Nitrogen and Oxygen, the lower the ratio the more Nitrous oxide decomposes.", + /datum/gas/bz = "The lower the pressure and larger the volume the more bz gets made. Less nitrous oxide than plasma will slow down the reaction.", + /datum/gas/nitrogen = "Each mole Nitrous oxide decomposed makes 1 mol Nitrogen. Lower ratio of Nitrous oxide to Plasma means a higher ratio of decomposition to BZ production.", + /datum/gas/oxygen = "Each mole Nitrous oxide decomposed makes 0.5 moles Oxygen. Lower ratio of Nitrous oxide to Plasma means a higher ratio of decomposition to BZ production.", + "Energy" = "[BZ_FORMATION_ENERGY] joules of energy is released per mol of BZ made. Nitrous oxide decomposition releases [N2O_DECOMPOSITION_ENERGY] per mol decomposed", ) /datum/gas_reaction/pluox_formation/init_factors() diff --git a/code/modules/atmospherics/gasmixtures/reactions.dm b/code/modules/atmospherics/gasmixtures/reactions.dm index 1ff8be48872..4041d710320 100644 --- a/code/modules/atmospherics/gasmixtures/reactions.dm +++ b/code/modules/atmospherics/gasmixtures/reactions.dm @@ -549,31 +549,37 @@ /datum/gas_reaction/bzformation/react(datum/gas_mixture/air) var/list/cached_gases = air.gases var/pressure = air.return_pressure() - // This slows down in relation to pressure, very quickly. Please don't expect it to be anything more then a snail + var/volume = air.return_volume() + var/environment_effciency = volume/pressure //More volume and less pressure gives better rates + var/ratio_efficency = min(cached_gases[/datum/gas/nitrous_oxide][MOLES]/cached_gases[/datum/gas/plasma][MOLES], 1) //Less n2o than plasma give lower rates + var/bz_formed = min(0.01 * ratio_efficency * environment_effciency, cached_gases[/datum/gas/nitrous_oxide][MOLES] * INVERSE(0.4), cached_gases[/datum/gas/plasma][MOLES] * INVERSE(0.8)) - // Bigger is better for these two values. - var/pressure_efficiency = (0.1 * ONE_ATMOSPHERE) / pressure // More pressure = more bad - var/ratio_efficiency = min(cached_gases[/datum/gas/nitrous_oxide][MOLES] / cached_gases[/datum/gas/plasma][MOLES], 1) // Malus to production if more plasma than n2o. - - var/reaction_efficency = min(pressure_efficiency * ratio_efficiency, cached_gases[/datum/gas/nitrous_oxide][MOLES], cached_gases[/datum/gas/plasma][MOLES] * INVERSE(2)) - - if ((cached_gases[/datum/gas/nitrous_oxide][MOLES] - reaction_efficency < 0 )|| (cached_gases[/datum/gas/plasma][MOLES] - (2 * reaction_efficency) < 0) || reaction_efficency <= 0) //Shouldn't produce gas from nothing. + if (cached_gases[/datum/gas/nitrous_oxide][MOLES] - bz_formed * 0.4 < 0 || cached_gases[/datum/gas/plasma][MOLES] - (0.8 * bz_formed) < 0 || bz_formed <= 0) return NO_REACTION var/old_heat_capacity = air.heat_capacity() - ASSERT_GAS(/datum/gas/bz, air) - if (reaction_efficency == cached_gases[/datum/gas/nitrous_oxide][MOLES]) + + /** + *If n2o-plasma ratio is less than 1:3 start decomposing n2o. + *Rate of decomposition vs BZ production increases as n2o concentration gets lower + *Plasma acts as a catalyst on decomposition, so it doesn't get consumed in the process. + *N2O decomposes with its normal decomposition energy + */ + var/nitrous_oxide_decomposed_factor = max(4*(cached_gases[/datum/gas/plasma][MOLES]/(cached_gases[/datum/gas/plasma]+cached_gases[/datum/gas/plasma][MOLES]) - 0.75), 0) + if (nitrous_oxide_decomposed_factor>0) + ASSERT_GAS(/datum/gas/nitrogen, air) ASSERT_GAS(/datum/gas/oxygen, air) - cached_gases[/datum/gas/bz][MOLES] += (reaction_efficency * 2.5) - min(pressure, 0.5) - cached_gases[/datum/gas/oxygen][MOLES] += min(pressure, 0.5) - else - cached_gases[/datum/gas/bz][MOLES] += reaction_efficency * 2.5 + var/amount_decomposed = 0.4 * bz_formed * nitrous_oxide_decomposed_factor + cached_gases[/datum/gas/nitrogen] += amount_decomposed + cached_gases[/datum/gas/oxygen] += 0.5 * amount_decomposed - cached_gases[/datum/gas/nitrous_oxide][MOLES] -= reaction_efficency - cached_gases[/datum/gas/plasma][MOLES] -= 2 * reaction_efficency + ASSERT_GAS(/datum/gas/bz, air) + cached_gases[/datum/gas/bz][MOLES] += bz_formed * (1-nitrous_oxide_decomposed_factor) + cached_gases[/datum/gas/nitrous_oxide][MOLES] -= 0.4 * bz_formed + cached_gases[/datum/gas/plasma][MOLES] -= 0.8 * bz_formed * (1-nitrous_oxide_decomposed_factor) - SET_REACTION_RESULTS(reaction_efficency) - var/energy_released = 2 * reaction_efficency * FIRE_CARBON_ENERGY_RELEASED + SET_REACTION_RESULTS(bz_formed) + var/energy_released = bz_formed * (BZ_FORMATION_ENERGY + nitrous_oxide_decomposed_factor * (N2O_DECOMPOSITION_ENERGY - BZ_FORMATION_ENERGY)) var/new_heat_capacity = air.heat_capacity() if(new_heat_capacity > MINIMUM_HEAT_CAPACITY) air.temperature = max(((air.temperature * old_heat_capacity + energy_released) / new_heat_capacity), TCMB)