Fixes the median temperature calculation for the crystallizer. (#63656)

(A - B) / 2 is not how you calculate the median for two numbers. For most recipes it wasn't even within the valid temperature range.

The quality of your crystallizer products can now increase.
This commit is contained in:
TemporalOroboros
2022-01-03 16:56:32 -08:00
committed by GitHub
parent 2a955d65e2
commit f23d3d5ee9
2 changed files with 17 additions and 40 deletions
@@ -1,8 +1,5 @@
///Global list of recipes for atmospheric machines to use
GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
///Defines for the recipes var
#define ENDOTHERMIC_REACTION "endothermic"
#define EXOTHERMIC_REACTION "exothermic"
/*
* Global proc to build the gas recipe global list
@@ -25,9 +22,10 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
var/min_temp = TCMB
///Maximum temperature for the recipe
var/max_temp = INFINITY
///Type of reaction (either endothermic or exothermic)
var/reaction_type = ""
///Amount of energy released/consumed by the reaction (always positive)
/**
* Amount of thermal energy released/consumed by the reaction.
* Positive numbers make the reaction release energy (exothermic) while negative numbers make the reaction consume energy (endothermic).
*/
var/energy_release = 0
var/dangerous = FALSE
///Gas required for the recipe to work
@@ -43,8 +41,7 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Hypernoblium Crystal"
min_temp = 3
max_temp = 250
reaction_type = ENDOTHERMIC_REACTION
energy_release = 250000
energy_release = -250000
requirements = list(/datum/gas/oxygen = 2000, /datum/gas/hypernoblium = 175)
products = list(/obj/item/hypernoblium_crystal = 1)
@@ -53,8 +50,7 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Metallic hydrogen"
min_temp = 50000
max_temp = 150000
reaction_type = ENDOTHERMIC_REACTION
energy_release = 2500000
energy_release = -2500000
requirements = list(/datum/gas/hydrogen = 300, /datum/gas/bz = 50)
products = list(/obj/item/stack/sheet/mineral/metal_hydrogen = 1)
@@ -63,8 +59,7 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Healium crystal"
min_temp = 200
max_temp = 400
reaction_type = ENDOTHERMIC_REACTION
energy_release = 2000000
energy_release = -2000000
requirements = list(/datum/gas/healium = 100, /datum/gas/oxygen = 120, /datum/gas/plasma = 50)
products = list(/obj/item/grenade/gas_crystal/healium_crystal = 1)
@@ -73,7 +68,6 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Proto nitrate crystal"
min_temp = 200
max_temp = 400
reaction_type = EXOTHERMIC_REACTION
energy_release = 1500000
requirements = list(/datum/gas/proto_nitrate = 100, /datum/gas/nitrogen = 80, /datum/gas/oxygen = 80)
products = list(/obj/item/grenade/gas_crystal/proto_nitrate_crystal = 1)
@@ -83,8 +77,7 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Hot ice"
min_temp = 15
max_temp = 35
reaction_type = ENDOTHERMIC_REACTION
energy_release = 3000000
energy_release = -3000000
requirements = list(/datum/gas/freon = 60, /datum/gas/plasma = 160, /datum/gas/oxygen = 80)
products = list(/obj/item/stack/sheet/hot_ice = 1)
@@ -93,7 +86,6 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Ammonia crystal"
min_temp = 200
max_temp = 240
reaction_type = EXOTHERMIC_REACTION
energy_release = 950000
requirements = list(/datum/gas/hydrogen = 50, /datum/gas/nitrogen = 40)
products = list(/obj/item/stack/ammonia_crystals = 2)
@@ -103,7 +95,6 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Supermatter crystal shard"
min_temp = TCMB
max_temp = 5
reaction_type = EXOTHERMIC_REACTION
energy_release = 150000000
dangerous = TRUE
requirements = list(/datum/gas/hypernoblium = 250, /datum/gas/antinoblium = 250, /datum/gas/bz = 200, /datum/gas/plasma = 5000, /datum/gas/oxygen = 4500)
@@ -114,7 +105,6 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Nitrous oxide crystal"
min_temp = 50
max_temp = 350
reaction_type = EXOTHERMIC_REACTION
energy_release = 3500000
requirements = list(/datum/gas/nitrous_oxide = 150, /datum/gas/bz = 30)
products = list(/obj/item/grenade/gas_crystal/nitrous_oxide_crystal = 1)
@@ -124,7 +114,6 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Diamond"
min_temp = 10000
max_temp = 30000
reaction_type = ENDOTHERMIC_REACTION
energy_release = 9500000
requirements = list(/datum/gas/carbon_dioxide = 1500)
products = list(/obj/item/stack/sheet/mineral/diamond = 1)
@@ -134,7 +123,6 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Plasma sheet"
min_temp = 10
max_temp = 20
reaction_type = EXOTHERMIC_REACTION
energy_release = 3500000
requirements = list(/datum/gas/plasma = 450)
products = list(/obj/item/stack/sheet/mineral/plasma = 1)
@@ -144,8 +132,7 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Crystal Cell"
min_temp = 50
max_temp = 90
reaction_type = ENDOTHERMIC_REACTION
energy_release = 800000
energy_release = -800000
requirements = list(/datum/gas/plasma = 800, /datum/gas/helium = 100, /datum/gas/bz = 50)
products = list(/obj/item/stock_parts/cell/crystal_cell = 1)
@@ -154,7 +141,6 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Zaukerite sheet"
min_temp = 5
max_temp = 20
reaction_type = EXOTHERMIC_REACTION
energy_release = 2900000
requirements = list(/datum/gas/antinoblium = 5, /datum/gas/zauker = 20, /datum/gas/bz = 7.5)
products = list(/obj/item/stack/sheet/mineral/zaukerite = 2)
@@ -162,31 +148,27 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
/datum/gas_recipe/crystallizer/fuel_pellet
id = "fuel_basic"
name = "standard fuel pellet"
reaction_type = ENDOTHERMIC_REACTION
energy_release = 6000000
energy_release = -6000000
requirements = list(/datum/gas/oxygen = 50, /datum/gas/plasma = 100)
products = list(/obj/item/fuel_pellet = 1)
/datum/gas_recipe/crystallizer/fuel_pellet_advanced
id = "fuel_advanced"
name = "advanced fuel pellet"
reaction_type = ENDOTHERMIC_REACTION
energy_release = 6000000
energy_release = -6000000
requirements = list(/datum/gas/tritium = 100, /datum/gas/hydrogen = 100)
products = list(/obj/item/fuel_pellet/advanced = 1)
/datum/gas_recipe/crystallizer/fuel_pellet_exotic
id = "fuel_exotic"
name = "exotic fuel pellet"
reaction_type = ENDOTHERMIC_REACTION
energy_release = 6000000
energy_release = -6000000
requirements = list(/datum/gas/hypernoblium = 100, /datum/gas/nitrium = 100)
products = list(/obj/item/fuel_pellet/exotic = 1)
/datum/gas_recipe/crystallizer/crystal_foam
id = "crystal_foam"
name = "Crystal foam grenade"
reaction_type = EXOTHERMIC_REACTION
energy_release = 140000
requirements = list(/datum/gas/carbon_dioxide = 150, /datum/gas/nitrous_oxide = 100, /datum/gas/water_vapor = 25)
products = list(/obj/item/grenade/gas_crystal/crystal_foam = 1)
@@ -196,7 +178,6 @@ GLOBAL_LIST_INIT(gas_recipe_meta, gas_recipes_list())
name = "Nitrium crystal"
min_temp = 10
max_temp = 25
reaction_type = ENDOTHERMIC_REACTION
energy_release = 45000
energy_release = -45000
requirements = list(/datum/gas/nitrium = 150, /datum/gas/oxygen = 70, /datum/gas/bz = 50)
products = list(/obj/item/nitrium_crystal = 1)
@@ -138,16 +138,12 @@
(internal.temperature >= selected_recipe.max_temp && internal.temperature <= (selected_recipe.max_temp * MAX_DEVIATION_RATE)))
quality_loss = min(quality_loss + 1.5, 100)
var/median_temperature = (selected_recipe.max_temp - selected_recipe.min_temp) * 0.5
var/median_temperature = (selected_recipe.max_temp + selected_recipe.min_temp) / 2
if(internal.temperature >= (median_temperature * MIN_DEVIATION_RATE) && internal.temperature <= (median_temperature * MAX_DEVIATION_RATE))
quality_loss = max(quality_loss - 5.5, -100)
if(selected_recipe.reaction_type == "endothermic")
internal.temperature = max(internal.temperature - (selected_recipe.energy_release / internal.heat_capacity()), TCMB)
update_parents()
else if(selected_recipe.reaction_type == "exothermic")
internal.temperature = max(internal.temperature + (selected_recipe.energy_release / internal.heat_capacity()), TCMB)
update_parents()
internal.temperature = max(internal.temperature + (selected_recipe.energy_release / internal.heat_capacity()), TCMB)
update_parents()
///Conduction between the internal gasmix and the moderating (cooling/heating) gasmix.
/obj/machinery/atmospherics/components/binary/crystallizer/proc/heat_conduction()
@@ -291,7 +287,7 @@
var/amount_consumed = selected_recipe.requirements[gas_type]
requirements += "-[amount_consumed] moles of [initial(gas_required.name)]"
requirements += "In a temperature range between [selected_recipe.min_temp] K and [selected_recipe.max_temp] K"
requirements += "The crystallization reaction will be [selected_recipe.reaction_type]"
requirements += "The crystallization reaction will be [selected_recipe.energy_release ? (selected_recipe.energy_release > 0 ? "exothermic" : "endothermic") : "thermally neutral"]"
data["requirements"] = requirements.Join("\n")
var/temperature