diff --git a/code/modules/plumbing/plumbers/pill_press.dm b/code/modules/plumbing/plumbers/pill_press.dm index 873177819cbe..931bf1d2fdfc 100644 --- a/code/modules/plumbing/plumbers/pill_press.dm +++ b/code/modules/plumbing/plumbers/pill_press.dm @@ -1,7 +1,5 @@ ///the minimum size of a pill or patch #define MIN_VOLUME 5 -///the maximum size a pill or patch can be -#define MAX_VOLUME 50 ///max amount of pills allowed on our tile before we start storing them instead #define MAX_FLOOR_PRODUCTS 10 @@ -12,16 +10,16 @@ icon_state = "pill_press" ///category for plumbing RCD category="Storage" - /// current operating product (pills or patches) - var/product = "pill" /// selected size of the product var/current_volume = 10 + /// maximum printable volume of the product + var/max_volume = 50 /// prefix for the product name var/product_name = "factory" /// All packaging types wrapped up in 1 big list var/static/list/packaging_types = null ///The type of packaging to use - var/packaging_type + var/obj/item/reagent_containers/packaging_type ///Category of packaging var/packaging_category /// list of products stored in the machine, so we dont have 610 pills on one tile @@ -53,34 +51,28 @@ packaging_types += list(category_item) - packaging_type = REF(GLOB.chem_master_containers[CAT_PILLS][1]) - decode_category() + packaging_type = GLOB.chem_master_containers[CAT_PILLS][1] //monkestation edit: reaplces GLOB.reagent_containers with GLOB.chem_master_containers + max_volume = initial(packaging_type.volume) + current_volume = clamp(current_volume, MIN_VOLUME, max_volume) AddComponent(/datum/component/plumbing/simple_demand, bolt, layer) +/obj/machinery/plumbing/pill_press/Destroy(force) + QDEL_LAZYLIST(stored_products) + return ..() + /obj/machinery/plumbing/pill_press/examine(mob/user) . = ..() . += span_notice("The [name] currently has [stored_products.len] stored. There needs to be less than [MAX_FLOOR_PRODUCTS] on the floor to continue dispensing.") -/// decode product category from it's type path and returns the decoded typepath -/obj/machinery/plumbing/pill_press/proc/decode_category() - var/obj/item/reagent_containers/container = locate(packaging_type) - if(ispath(container, /obj/item/reagent_containers/pill/patch)) - packaging_category = CAT_PATCHES - else if(ispath(container, /obj/item/reagent_containers/pill)) - packaging_category = CAT_PILLS - else - packaging_category = CAT_TUBES - return container - /obj/machinery/plumbing/pill_press/process(seconds_per_tick) if(!is_operational) return //shift & check to account for floating point inaccuracies if(reagents.total_volume >= current_volume) - var/obj/item/reagent_containers/container = locate(packaging_type) - container = new container(src) + var/obj/item/reagent_containers/container = new packaging_type(src) + var/suffix switch(packaging_category) if(CAT_PILLS) @@ -122,7 +114,6 @@ var/list/data = list() data["min_volume"] = MIN_VOLUME - data["max_volume"] = MAX_VOLUME data["packaging_types"] = packaging_types return data @@ -131,8 +122,9 @@ var/list/data = list() data["current_volume"] = current_volume + data["max_volume"] = max_volume data["product_name"] = product_name - data["packaging_type"] = packaging_type + data["packaging_type"] = REF(packaging_type) data["packaging_category"] = packaging_category return data @@ -142,21 +134,57 @@ if(.) return - . = TRUE switch(action) if("change_current_volume") - current_volume = round(clamp(text2num(params["volume"]), MIN_VOLUME, MAX_VOLUME)) + var/value = params["volume"] + if(isnull(value)) + return FALSE + + value = text2num(value) + if(isnull(value)) + return FALSE + + current_volume = clamp(value, MIN_VOLUME, max_volume) + return TRUE + if("change_product_name") var/formatted_name = html_encode(params["name"]) if (length(formatted_name) > MAX_NAME_LEN) product_name = copytext(formatted_name, 1, MAX_NAME_LEN + 1) else product_name = formatted_name + return TRUE + if("change_product") - packaging_type = params["ref"] - var/obj/item/reagent_containers/container = decode_category() - current_volume = clamp(current_volume, MIN_VOLUME, initial(container.volume)) + var/container = params["ref"] + if(!container) + return FALSE + + //is a valid option + var/container_found = FALSE + for(var/list/category as anything in packaging_types) + if(container_found) + break + for(var/list/package_item as anything in category["products"]) + if(container == package_item["ref"]) + container_found = TRUE + break + if(!container_found) + return FALSE + + //decode container & its category + packaging_type = locate(container) + if(ispath(packaging_type, /obj/item/reagent_containers/pill/patch)) + packaging_category = CAT_PATCHES + else if(ispath(packaging_type, /obj/item/reagent_containers/pill)) + packaging_category = CAT_PILLS + else + packaging_category = "Bottles" + + //get new volumes + max_volume = initial(packaging_type.volume) + current_volume = clamp(current_volume, MIN_VOLUME, max_volume) + return TRUE #undef MIN_VOLUME -#undef MAX_VOLUME #undef MAX_FLOOR_PRODUCTS diff --git a/code/modules/reagents/chemistry/machinery/chem_master.dm b/code/modules/reagents/chemistry/machinery/chem_master.dm index 202b29287d9d..0a3b8abd8180 100644 --- a/code/modules/reagents/chemistry/machinery/chem_master.dm +++ b/code/modules/reagents/chemistry/machinery/chem_master.dm @@ -355,7 +355,24 @@ GLOBAL_LIST_INIT(chem_master_containers, list( return TRUE if(action == "selectContainer") - selected_container = params["ref"] + var/obj/item/reagent_containers/target = locate(params["ref"]) + + //is this even a valid type path + if(!ispath(target)) + return FALSE + + //are we printing a valid container + var/container_found = FALSE + for(var/category in printable_containers) + for(var/obj/item/reagent_containers/container as anything in printable_containers[category]) + if(target == container) + container_found = TRUE + break + if(!container_found) + return FALSE + + //set the container + selected_container = target return TRUE if(action == "create")