From 56547a2556e6ac516c03a85b05efa25ce466e61f Mon Sep 17 00:00:00 2001
From: Timothy Teakettle <59849408+timothyteakettle@users.noreply.github.com>
Date: Wed, 23 Feb 2022 11:38:04 +0000
Subject: [PATCH] generalizes recipe searching, adds chemistry functionality
---
code/_globalvars/lists/objects.dm | 3 +-
code/game/objects/items/devices/PDA/PDA.dm | 30 ++++++-------------
code/game/objects/items/devices/PDA/cart.dm | 3 +-
code/modules/reagents/chemistry/holder.dm | 32 +++++++++++++++++++--
4 files changed, 42 insertions(+), 26 deletions(-)
diff --git a/code/_globalvars/lists/objects.dm b/code/_globalvars/lists/objects.dm
index d29bdfae23..921b512d32 100644
--- a/code/_globalvars/lists/objects.dm
+++ b/code/_globalvars/lists/objects.dm
@@ -16,7 +16,8 @@ GLOBAL_LIST_EMPTY(singularities) //list of all singularities on the stati
GLOBAL_LIST_EMPTY(grounding_rods) //list of all grounding rods on the station
GLOBAL_LIST(chemical_reactions_list) //list of all /datum/chemical_reaction datums. Used during chemical reactions
-GLOBAL_LIST(drink_reactions_list) //list of all /datum/chemical_reaction datums where the output is of type /datum/reagent/consumable
+GLOBAL_LIST(drink_reactions_list) //list of all /datum/chemical_reaction datums where the output is of type /datum/reagent/consumable for bartender PDA
+GLOBAL_LIST(normalized_chemical_reactions_list) //list of all /datum/chemical_reaction datums with actual sane indexing for chemistry PDA
GLOBAL_LIST(chemical_reagents_list) //list of all /datum/reagent datums indexed by reagent id. Used by chemistry stuff
GLOBAL_LIST_EMPTY(tech_list) //list of all /datum/tech datums indexed by id.
GLOBAL_LIST_EMPTY(surgeries_list) //list of all surgeries by name, associated with their path.
diff --git a/code/game/objects/items/devices/PDA/PDA.dm b/code/game/objects/items/devices/PDA/PDA.dm
index c339b0024c..1a130998b6 100644
--- a/code/game/objects/items/devices/PDA/PDA.dm
+++ b/code/game/objects/items/devices/PDA/PDA.dm
@@ -371,6 +371,8 @@ GLOBAL_LIST_EMPTY(PDAs)
dat += "
[PDAIMG(dronephone)]Drone Phone"
if (cartridge.access & CART_BARTENDER)
dat += "[PDAIMG(bucket)]Drink Recipe Browser"
+ if (cartridge.access & CART_CHEMISTRY)
+ dat += "[PDAIMG(bucket)]Chemistry Recipe Browser"
dat += "[PDAIMG(atmos)]Atmospheric Scan"
dat += "[PDAIMG(flashlight)][fon ? "Disable" : "Enable"] Flashlight"
if (pai)
@@ -710,28 +712,12 @@ GLOBAL_LIST_EMPTY(PDAs)
//DRINK RECIPE BROWSER=============================
if("Drink Recipe Browser")
if(cartridge && cartridge.access & CART_BARTENDER)
- var/option = input(U, "Enter keyword to return a recipe.")
- if(option)
- option = lowertext(option)
- var/list/reagents_required
- var/found_reagent_name
- var/required_temp
- for(var/reagent_name in GLOB.drink_reactions_list)
- if(findtext(lowertext(reagent_name), option))
- found_reagent_name = reagent_name
- reagents_required = GLOB.drink_reactions_list[reagent_name].required_reagents
- required_temp = GLOB.drink_reactions_list[reagent_name].required_temp
- break
- if(length(reagents_required))
- to_chat(U, "Recipe found: [found_reagent_name][required_temp ? "
Required Temperature: [required_temp]K" : ""]
Required Reagents:")
- var/reagents_required_string = ""
- for(var/r in reagents_required)
- var/datum/reagent/reagent = r
- reagents_required_string += "
[initial(reagent.name)]: [reagents_required[r]]"
- to_chat(U, reagents_required_string)
- return
- else
- to_chat(U, "Reagent with term: [option] could not be located!")
+ recipe_search(U, GLOB.drink_reactions_list)
+
+//CHEMISTRY RECIPE BROWSER
+ if("Chemistry Recipe Browser")
+ if(cartridge && cartridge.access & CART_CHEMISTRY)
+ recipe_search(U, GLOB.normalized_chemical_reactions_list)
//LINK FUNCTIONS===================================
diff --git a/code/game/objects/items/devices/PDA/cart.dm b/code/game/objects/items/devices/PDA/cart.dm
index 9d02207375..ca72e3371b 100644
--- a/code/game/objects/items/devices/PDA/cart.dm
+++ b/code/game/objects/items/devices/PDA/cart.dm
@@ -14,6 +14,7 @@
#define CART_HYDROPONICS (1<<13)
#define CART_DRONEPHONE (1<<14)
#define CART_BARTENDER (1<<15)
+#define CART_CHEMISTRY (1<<16)
/obj/item/cartridge
@@ -78,7 +79,7 @@
/obj/item/cartridge/chemistry
name = "\improper ChemWhiz cartridge"
icon_state = "cart-chem"
- access = CART_REAGENT_SCANNER
+ access = CART_REAGENT_SCANNER | CART_CHEMISTRY
bot_access_flags = MED_BOT
/obj/item/cartridge/security
diff --git a/code/modules/reagents/chemistry/holder.dm b/code/modules/reagents/chemistry/holder.dm
index 89ff24d2f3..e1602fab4a 100644
--- a/code/modules/reagents/chemistry/holder.dm
+++ b/code/modules/reagents/chemistry/holder.dm
@@ -27,7 +27,8 @@
//Randomized need to go last since they need to check against conflicts with normal recipes
var/paths = subtypesof(/datum/chemical_reaction) - typesof(/datum/chemical_reaction/randomized) + subtypesof(/datum/chemical_reaction/randomized)
GLOB.chemical_reactions_list = list()
- GLOB.drink_reactions_list = list()
+ GLOB.normalized_chemical_reactions_list = list() // chemistry pda
+ GLOB.drink_reactions_list = list() // bartender pda
for(var/path in paths)
@@ -35,9 +36,11 @@
var/list/reaction_ids = list()
// store drinks separately for bartender cartridge
if(D.id)
+ var/datum/reagent/r = D.id
if(ispath(D.id, /datum/reagent/consumable))
- var/datum/reagent/consumable/r = D.id
GLOB.drink_reactions_list[initial(r.name)] = D
+ if(ispath(D.id, /datum/reagent))
+ GLOB.normalized_chemical_reactions_list[initial(r.name)] = D
if(D.required_reagents && D.required_reagents.len)
for(var/reaction in D.required_reagents)
@@ -50,6 +53,31 @@
GLOB.chemical_reactions_list[id] += D
break // Don't bother adding ourselves to other reagent ids, it is redundant
+/proc/recipe_search(mob/M, list/reaction_list)
+ var/option = input(M, "Enter keyword to return a recipe.")
+ if(option)
+ option = lowertext(option)
+ var/list/reagents_required
+ var/found_reagent_name
+ var/required_temp
+ for(var/reagent_name in reaction_list)
+ if(findtext(lowertext(reagent_name), option))
+ var/datum/chemical_reaction/reaction = reaction_list[reagent_name]
+ found_reagent_name = reagent_name
+ reagents_required = reaction.required_reagents
+ required_temp = reaction.required_temp
+ break
+ if(length(reagents_required))
+ to_chat(M, "Recipe found: [found_reagent_name][required_temp ? "
Required Temperature: [required_temp]K" : ""]
Required Reagents:")
+ var/reagents_required_string = ""
+ for(var/r in reagents_required)
+ var/datum/reagent/reagent = r
+ reagents_required_string += "
[initial(reagent.name)]: [reagents_required[r]]"
+ to_chat(M, reagents_required_string)
+ return
+ else
+ to_chat(M, "Reagent with term: [option] could not be located!")
+
///////////////////////////////////////////////////////////////////////////////////
/datum/reagents