From 72c5c2234edfea995baec3f6feb2e285247ee023 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Sun, 12 Jul 2020 05:15:55 -0700 Subject: [PATCH 1/2] ok --- code/__DEFINES/chemistry/reactions.dm | 4 ++++ code/__HELPERS/cmp.dm | 8 ++++++++ code/modules/reagents/chemistry/holder.dm | 11 ++--------- code/modules/reagents/chemistry/recipes.dm | 3 +++ .../reagents/chemistry/recipes/pyrotechnics.dm | 1 + tgstation.dme | 1 + 6 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 code/__DEFINES/chemistry/reactions.dm diff --git a/code/__DEFINES/chemistry/reactions.dm b/code/__DEFINES/chemistry/reactions.dm new file mode 100644 index 0000000000..0deadcbfe0 --- /dev/null +++ b/code/__DEFINES/chemistry/reactions.dm @@ -0,0 +1,4 @@ +// Reaction priorities, higher makes it checked first. Otherwise, it goes based on reaction temperature requirements. + +#define CHEMICAL_REACTION_PRIORITY_DEFAULT 100 +#define CHEMICAL_REACTION_PRIORITY_SMOKE 1000 diff --git a/code/__HELPERS/cmp.dm b/code/__HELPERS/cmp.dm index dce4d554b7..e0af4dbec0 100644 --- a/code/__HELPERS/cmp.dm +++ b/code/__HELPERS/cmp.dm @@ -125,3 +125,11 @@ GLOBAL_VAR_INIT(cmp_field, "name") if(A.ui_category == B.ui_category) return sorttext(A.name, B.name) return sorttext(A.ui_category, B.ui_category) + +/proc/cmp_chemical_reactions_default(datum/chemical_reaction/A, datum/chemical_reaction/B) + if(A.priority != B.priority) + return A.priority - B.priority + else if(A.is_cold_recipe) + return B.required_temp - A.required_temp //return coldest + else + return A.required_temp - B.required_temp //return hottest diff --git a/code/modules/reagents/chemistry/holder.dm b/code/modules/reagents/chemistry/holder.dm index 4cf50cd072..c2662a8342 100644 --- a/code/modules/reagents/chemistry/holder.dm +++ b/code/modules/reagents/chemistry/holder.dm @@ -463,17 +463,10 @@ if(total_matching_reagents == total_required_reagents && total_matching_catalysts == total_required_catalysts && matching_container && matching_other && meets_temp_requirement && can_special_react) possible_reactions += C + sortTim(possible_reactions, /proc/cmp_chemical_reactions_default, FALSE) + if(possible_reactions.len) var/datum/chemical_reaction/selected_reaction = possible_reactions[1] - //select the reaction with the most extreme temperature requirements - for(var/V in possible_reactions) - var/datum/chemical_reaction/competitor = V - if(selected_reaction.is_cold_recipe) - if(competitor.required_temp <= selected_reaction.required_temp) - selected_reaction = competitor - else - if(competitor.required_temp >= selected_reaction.required_temp) //will return with the hotter reacting first. - selected_reaction = competitor var/list/cached_required_reagents = selected_reaction.required_reagents//update reagents list var/list/cached_results = selected_reaction.results//resultant chemical list var/special_react_result = selected_reaction.check_special_react(src) diff --git a/code/modules/reagents/chemistry/recipes.dm b/code/modules/reagents/chemistry/recipes.dm index 98d66a2b1b..7df061c8aa 100644 --- a/code/modules/reagents/chemistry/recipes.dm +++ b/code/modules/reagents/chemistry/recipes.dm @@ -5,6 +5,9 @@ var/list/required_reagents = new/list() var/list/required_catalysts = new/list() + /// Higher is higher priority, determines which order reactions are checked. + var/priority = CHEMICAL_REACTION_PRIORITY_DEFAULT + // Both of these variables are mostly going to be used with slime cores - but if you want to, you can use them for other things var/required_container = null // the exact container path required for the reaction to happen var/required_other = 0 // an integer required for the reaction to happen diff --git a/code/modules/reagents/chemistry/recipes/pyrotechnics.dm b/code/modules/reagents/chemistry/recipes/pyrotechnics.dm index 1d06aaacde..efa92ef7d6 100644 --- a/code/modules/reagents/chemistry/recipes/pyrotechnics.dm +++ b/code/modules/reagents/chemistry/recipes/pyrotechnics.dm @@ -280,6 +280,7 @@ /datum/chemical_reaction/smoke_powder name = "smoke_powder" id = /datum/reagent/smoke_powder + priority = CHEMICAL_REACTION_PRIORITY_SMOKE results = list(/datum/reagent/smoke_powder = 3) required_reagents = list(/datum/reagent/potassium = 1, /datum/reagent/consumable/sugar = 1, /datum/reagent/phosphorus = 1) diff --git a/tgstation.dme b/tgstation.dme index 430e8d8db6..b745cb8d0b 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -123,6 +123,7 @@ #include "code\__DEFINES\_flags\item_flags.dm" #include "code\__DEFINES\_flags\obj_flags.dm" #include "code\__DEFINES\admin\keybindings.dm" +#include "code\__DEFINES\chemistry\reactions.dm" #include "code\__DEFINES\combat\attack_types.dm" #include "code\__DEFINES\combat\block.dm" #include "code\__DEFINES\combat\block_parry.dm" From 047a36c973e7ec1d8c40c846829aed3f52c7b4a8 Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Sun, 12 Jul 2020 05:37:07 -0700 Subject: [PATCH 2/2] fix --- code/__HELPERS/cmp.dm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/__HELPERS/cmp.dm b/code/__HELPERS/cmp.dm index e0af4dbec0..0825e51ae4 100644 --- a/code/__HELPERS/cmp.dm +++ b/code/__HELPERS/cmp.dm @@ -128,8 +128,8 @@ GLOBAL_VAR_INIT(cmp_field, "name") /proc/cmp_chemical_reactions_default(datum/chemical_reaction/A, datum/chemical_reaction/B) if(A.priority != B.priority) - return A.priority - B.priority + return B.priority - A.priority else if(A.is_cold_recipe) - return B.required_temp - A.required_temp //return coldest + return A.required_temp - B.required_temp //return coldest else - return A.required_temp - B.required_temp //return hottest + return B.required_temp - A.required_temp //return hottest