From 5bd7184d9ceb7fc9e830a8654d4bf2e5976665a3 Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Mon, 30 Oct 2017 21:34:28 +0200 Subject: [PATCH] Deterministic output slots for smartfridges (#32225) * a spooky commit * It is too late, the skeleton is already inside you * mexican river dolphins for halloween 2018 * Compiler warnings for halloween 2018 --- code/game/machinery/_machinery.dm | 11 ++++ .../kitchen_machinery/smartfridge.dm | 1 + .../chemistry/machinery/chem_master.dm | 57 +++++++++++++------ 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index 60260d2a4f..286bcee1f8 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -506,3 +506,14 @@ Class Procs: . = ..() if (AM == occupant) occupant = null + +/obj/machinery/proc/adjust_item_drop_location(atom/movable/AM) // Adjust item drop location to a 3x3 grid inside the tile, returns slot id from 0 to 8 + var/md5 = md5(AM.name) // Oh, and it's deterministic too. A specific item will always drop from the same slot. +#if DM_VERSION > 511 +#warn Refactor the loop in /obj/machinery/proc/adjust_item_drop_location() to make use of 512's list-like access to characters in a string +#endif + for (var/i in 1 to 32) + . += hex2num(copytext(md5,i,i+1)) + . = . % 9 + AM.pixel_x = -8 + ((.%3)*8) + AM.pixel_y = -8 + (round( . / 3)*8) \ No newline at end of file diff --git a/code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm b/code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm index efd877b9dc..46e2f3ea5f 100644 --- a/code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm +++ b/code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm @@ -194,6 +194,7 @@ break if(O.name == params["name"]) O.forceMove(drop_location()) + adjust_item_drop_location(O) desired-- return TRUE return FALSE diff --git a/code/modules/reagents/chemistry/machinery/chem_master.dm b/code/modules/reagents/chemistry/machinery/chem_master.dm index f1da846ebc..7c764e26cb 100644 --- a/code/modules/reagents/chemistry/machinery/chem_master.dm +++ b/code/modules/reagents/chemistry/machinery/chem_master.dm @@ -62,11 +62,13 @@ /obj/machinery/chem_master/attackby(obj/item/I, mob/user, params) if(default_deconstruction_screwdriver(user, "mixer0_nopower", "mixer0", I)) if(beaker) - beaker.loc = src.loc + beaker.forceMove(drop_location()) + adjust_item_drop_location(beaker) beaker = null reagents.clear_reagents() if(bottle) - bottle.loc = src.loc + bottle.forceMove(drop_location()) + adjust_item_drop_location(bottle) bottle = null return @@ -153,7 +155,8 @@ switch(action) if("eject") if(beaker) - beaker.loc = src.loc + beaker.forceMove(drop_location()) + adjust_item_drop_location(beaker) beaker = null reagents.clear_reagents() icon_state = "mixer0" @@ -161,7 +164,8 @@ if("ejectp") if(bottle) - bottle.loc = src.loc + bottle.forceMove(drop_location()) + adjust_item_drop_location(bottle) bottle = null . = TRUE @@ -214,16 +218,15 @@ if(bottle && bottle.contents.len < bottle.storage_slots) P = new/obj/item/reagent_containers/pill(bottle) else - P = new/obj/item/reagent_containers/pill(src.loc) + P = new/obj/item/reagent_containers/pill(drop_location()) P.name = trim("[name] pill") - P.pixel_x = rand(-7, 7) //random position - P.pixel_y = rand(-7, 7) + adjust_item_drop_location(P) reagents.trans_to(P,vol_each) else var/name = stripped_input(usr, "Name:", "Name your pack!", reagents.get_master_reagent_name(), MAX_NAME_LEN) if(!name || !reagents.total_volume || !src || QDELETED(src) || !usr.canUseTopic(src, be_close=TRUE)) return - var/obj/item/reagent_containers/food/condiment/pack/P = new/obj/item/reagent_containers/food/condiment/pack(src.loc) + var/obj/item/reagent_containers/food/condiment/pack/P = new/obj/item/reagent_containers/food/condiment/pack(drop_location()) P.originalname = name P.name = trim("[name] pack") @@ -248,10 +251,9 @@ var/obj/item/reagent_containers/pill/P for(var/i = 0; i < amount; i++) - P = new/obj/item/reagent_containers/pill/patch(src.loc) + P = new/obj/item/reagent_containers/pill/patch(drop_location()) P.name = trim("[name] patch") - P.pixel_x = rand(-7, 7) //random position - P.pixel_y = rand(-7, 7) + adjust_item_drop_location(P) reagents.trans_to(P,vol_each) . = TRUE @@ -264,7 +266,7 @@ var/name = stripped_input(usr, "Name:","Name your bottle!", (reagents.total_volume ? reagents.get_master_reagent_name() : " "), MAX_NAME_LEN) if(!name || !reagents.total_volume || !src || QDELETED(src) || !usr.canUseTopic(src, be_close=TRUE)) return - var/obj/item/reagent_containers/food/condiment/P = new(src.loc) + var/obj/item/reagent_containers/food/condiment/P = new(drop_location()) P.originalname = name P.name = trim("[name] bottle") reagents.trans_to(P, P.volume) @@ -280,15 +282,15 @@ var/obj/item/reagent_containers/glass/bottle/P for(var/i = 0; i < amount_full; i++) - P = new/obj/item/reagent_containers/glass/bottle(src.loc) - P.pixel_x = rand(-7, 7) //random position - P.pixel_y = rand(-7, 7) + P = new/obj/item/reagent_containers/glass/bottle(drop_location()) P.name = trim("[name] bottle") + adjust_item_drop_location(P) reagents.trans_to(P, 30) if(vol_part) - P = new/obj/item/reagent_containers/glass/bottle(src.loc) + P = new/obj/item/reagent_containers/glass/bottle(drop_location()) P.name = trim("[name] bottle") + adjust_item_drop_location(P) reagents.trans_to(P, vol_part) . = TRUE @@ -328,6 +330,29 @@ return 0 +/obj/machinery/chem_master/adjust_item_drop_location(atom/movable/AM) // Special version for chemmasters and condimasters + if (AM == beaker) + AM.pixel_x = -8 + AM.pixel_y = 8 + return null + else if (AM == bottle) + if (length(bottle.contents)) + AM.pixel_x = -13 + else + AM.pixel_x = -7 + AM.pixel_y = -8 + return null + else + var/md5 = md5(AM.name) +#if DM_VERSION > 511 +#warn Refactor the loop in /obj/machinery/chem_master/adjust_item_drop_location() to make use of 512's list-like access to characters in a string +#endif + for (var/i in 1 to 32) + . += hex2num(copytext(md5,i,i+1)) + . = . % 9 + AM.pixel_x = ((.%3)*6) + AM.pixel_y = -8 + (round( . / 3)*8) + /obj/machinery/chem_master/condimaster name = "CondiMaster 3000" desc = "Used to create condiments and other cooking supplies."