From 73b25d7ef28207617fd8a881f2f863f2aaa133c4 Mon Sep 17 00:00:00 2001 From: oranges Date: Sat, 25 Nov 2017 00:45:44 +1300 Subject: [PATCH] Refactor on_reagent_change to pass through the change type (#32805) this is purely so the smoke circuit can reset the notification only when reagents are actually added to it --- code/__DEFINES/reagents.dm | 7 ++++++- code/datums/datumvars.dm | 2 +- code/game/mecha/equipment/tools/medical_tools.dm | 2 +- code/game/mecha/equipment/tools/work_tools.dm | 3 --- code/game/objects/items/devices/scanners.dm | 2 +- code/modules/food_and_drinks/drinks/drinks.dm | 8 ++++---- .../food_and_drinks/drinks/drinks/drinkingglass.dm | 6 +++--- code/modules/food_and_drinks/food/condiment.dm | 10 +++++----- code/modules/food_and_drinks/food/customizables.dm | 2 +- code/modules/hydroponics/biogenerator.dm | 2 +- code/modules/integrated_electronics/passive/power.dm | 2 +- .../integrated_electronics/subtypes/reagents.dm | 12 ++++++------ code/modules/mob/living/simple_animal/bot/secbot.dm | 2 +- code/modules/reagents/chemistry/holder.dm | 9 ++++----- .../reagents/reagent_containers/blood_pack.dm | 2 +- code/modules/reagents/reagent_containers/bottle.dm | 2 +- code/modules/reagents/reagent_containers/glass.dm | 2 +- code/modules/reagents/reagent_containers/syringes.dm | 2 +- 18 files changed, 39 insertions(+), 38 deletions(-) diff --git a/code/__DEFINES/reagents.dm b/code/__DEFINES/reagents.dm index 9e17719e760..c85365db907 100644 --- a/code/__DEFINES/reagents.dm +++ b/code/__DEFINES/reagents.dm @@ -11,4 +11,9 @@ #define INGEST 2 //ingestion #define VAPOR 3 //foam, spray, blob attack #define PATCH 4 //patches -#define INJECT 5 //injection \ No newline at end of file +#define INJECT 5 //injection + +//defines passed through to the on_reagent_change proc +#define DEL_REAGENT 1 //reagent deleted (fully cleared) +#define ADD_REAGENT 2 // reagent added +#define REM_REAGENT 3 // reagent removed (may still exist) diff --git a/code/datums/datumvars.dm b/code/datums/datumvars.dm index 894f34345d5..c609e63f0f7 100644 --- a/code/datums/datumvars.dm +++ b/code/datums/datumvars.dm @@ -31,7 +31,7 @@ .["Show VV To Player"] = "?_src_=vars;[HrefToken(TRUE)];expose=[REF(src)]" -/datum/proc/on_reagent_change() +/datum/proc/on_reagent_change(changetype) return diff --git a/code/game/mecha/equipment/tools/medical_tools.dm b/code/game/mecha/equipment/tools/medical_tools.dm index 4d3ad9355b4..97a8d090893 100644 --- a/code/game/mecha/equipment/tools/medical_tools.dm +++ b/code/game/mecha/equipment/tools/medical_tools.dm @@ -502,7 +502,7 @@ return 1 return -/obj/item/mecha_parts/mecha_equipment/medical/syringe_gun/on_reagent_change() +/obj/item/mecha_parts/mecha_equipment/medical/syringe_gun/on_reagent_change(changetype) ..() update_equip_info() return diff --git a/code/game/mecha/equipment/tools/work_tools.dm b/code/game/mecha/equipment/tools/work_tools.dm index 35330996151..d4566426337 100644 --- a/code/game/mecha/equipment/tools/work_tools.dm +++ b/code/game/mecha/equipment/tools/work_tools.dm @@ -179,9 +179,6 @@ /obj/item/mecha_parts/mecha_equipment/extinguisher/get_equip_info() return "[..()] \[[src.reagents.total_volume]\]" -/obj/item/mecha_parts/mecha_equipment/extinguisher/on_reagent_change() - return - /obj/item/mecha_parts/mecha_equipment/extinguisher/can_attach(obj/mecha/working/M as obj) if(..()) if(istype(M)) diff --git a/code/game/objects/items/devices/scanners.dm b/code/game/objects/items/devices/scanners.dm index 82ee67f5700..bd9524f188e 100644 --- a/code/game/objects/items/devices/scanners.dm +++ b/code/game/objects/items/devices/scanners.dm @@ -407,7 +407,7 @@ MASS SPECTROMETER ..() create_reagents(5) -/obj/item/device/mass_spectrometer/on_reagent_change() +/obj/item/device/mass_spectrometer/on_reagent_change(changetype) if(reagents.total_volume) icon_state = initial(icon_state) + "_s" else diff --git a/code/modules/food_and_drinks/drinks/drinks.dm b/code/modules/food_and_drinks/drinks/drinks.dm index 478b599055e..eb6f0f0627d 100644 --- a/code/modules/food_and_drinks/drinks/drinks.dm +++ b/code/modules/food_and_drinks/drinks/drinks.dm @@ -15,7 +15,7 @@ resistance_flags = NONE var/isGlass = TRUE //Whether the 'bottle' is made of glass or not so that milk cartons dont shatter when someone gets hit by it -/obj/item/reagent_containers/food/drinks/on_reagent_change() +/obj/item/reagent_containers/food/drinks/on_reagent_change(changetype) if (gulp_size < 5) gulp_size = 5 else @@ -207,7 +207,7 @@ item_state = "coffee" spillable = TRUE -/obj/item/reagent_containers/food/drinks/mug/on_reagent_change() +/obj/item/reagent_containers/food/drinks/mug/on_reagent_change(changetype) if(reagents.total_volume) icon_state = "tea" else @@ -259,7 +259,7 @@ spillable = TRUE isGlass = FALSE -/obj/item/reagent_containers/food/drinks/sillycup/on_reagent_change() +/obj/item/reagent_containers/food/drinks/sillycup/on_reagent_change(changetype) if(reagents.total_volume) icon_state = "water_cup" else @@ -287,7 +287,7 @@ transfer_fingerprints_to(B) qdel(src) -/obj/item/reagent_containers/food/drinks/sillycup/smallcarton/on_reagent_change() +/obj/item/reagent_containers/food/drinks/sillycup/smallcarton/on_reagent_change(changetype) if (reagents.reagent_list.len) switch(reagents.get_master_reagent_id()) if("orangejuice") diff --git a/code/modules/food_and_drinks/drinks/drinks/drinkingglass.dm b/code/modules/food_and_drinks/drinks/drinks/drinkingglass.dm index ae5bc177f34..263d592303c 100644 --- a/code/modules/food_and_drinks/drinks/drinks/drinkingglass.dm +++ b/code/modules/food_and_drinks/drinks/drinks/drinkingglass.dm @@ -12,7 +12,7 @@ resistance_flags = ACID_PROOF unique_rename = 1 -/obj/item/reagent_containers/food/drinks/drinkingglass/on_reagent_change() +/obj/item/reagent_containers/food/drinks/drinkingglass/on_reagent_change(changetype) cut_overlays() if(reagents.reagent_list.len) var/datum/reagent/R = reagents.get_master_reagent() @@ -46,7 +46,7 @@ volume = 15 materials = list(MAT_GLASS=100) -/obj/item/reagent_containers/food/drinks/drinkingglass/shotglass/on_reagent_change() +/obj/item/reagent_containers/food/drinks/drinkingglass/shotglass/on_reagent_change(changetype) cut_overlays() if (gulp_size < 15) @@ -76,7 +76,7 @@ /obj/item/reagent_containers/food/drinks/drinkingglass/filled/Initialize() . = ..() - on_reagent_change() + on_reagent_change(ADD_REAGENT) /obj/item/reagent_containers/food/drinks/drinkingglass/filled/soda name = "Soda Water" diff --git a/code/modules/food_and_drinks/food/condiment.dm b/code/modules/food_and_drinks/food/condiment.dm index c115ef51af6..3e6e2e84505 100644 --- a/code/modules/food_and_drinks/food/condiment.dm +++ b/code/modules/food_and_drinks/food/condiment.dm @@ -13,7 +13,7 @@ container_type = OPENCONTAINER_1 possible_transfer_amounts = list(1, 5, 10, 15, 20, 25, 30, 50) volume = 50 - //Possible_states has the reagent id as key and a list of, in order, the icon_state, the name and the desc as values. Used in the on_reagent_change() to change names, descs and sprites. + //Possible_states has the reagent id as key and a list of, in order, the icon_state, the name and the desc as values. Used in the on_reagent_change(changetype) to change names, descs and sprites. var/list/possible_states = list( "ketchup" = list("ketchup", "ketchup bottle", "You feel more American already."), "capsaicin" = list("hotsauce", "hotsauce bottle", "You can almost TASTE the stomach ulcers now!"), @@ -80,7 +80,7 @@ var/trans = src.reagents.trans_to(target, amount_per_transfer_from_this) to_chat(user, "You transfer [trans] units of the condiment to [target].") -/obj/item/reagent_containers/food/condiment/on_reagent_change() +/obj/item/reagent_containers/food/condiment/on_reagent_change(changetype) if(!possible_states.len) return if(reagents.reagent_list.len > 0) @@ -126,7 +126,7 @@ list_reagents = list("sodiumchloride" = 20) possible_states = list() -/obj/item/reagent_containers/food/condiment/saltshaker/on_reagent_change() +/obj/item/reagent_containers/food/condiment/saltshaker/on_reagent_change(changetype) if(reagents.reagent_list.len == 0) icon_state = "emptyshaker" else @@ -164,7 +164,7 @@ list_reagents = list("blackpepper" = 20) possible_states = list() -/obj/item/reagent_containers/food/condiment/peppermill/on_reagent_change() +/obj/item/reagent_containers/food/condiment/peppermill/on_reagent_change(changetype) if(reagents.reagent_list.len == 0) icon_state = "emptyshaker" else @@ -255,7 +255,7 @@ src.reagents.trans_to(target, amount_per_transfer_from_this) qdel(src) -/obj/item/reagent_containers/food/condiment/pack/on_reagent_change() +/obj/item/reagent_containers/food/condiment/pack/on_reagent_change(changetype) if(reagents.reagent_list.len > 0) var/main_reagent = reagents.get_master_reagent_id() if(main_reagent in possible_states) diff --git a/code/modules/food_and_drinks/food/customizables.dm b/code/modules/food_and_drinks/food/customizables.dm index 28ab6e65373..fc49cee9ab8 100644 --- a/code/modules/food_and_drinks/food/customizables.dm +++ b/code/modules/food_and_drinks/food/customizables.dm @@ -313,7 +313,7 @@ . = ..() return -/obj/item/reagent_containers/glass/bowl/on_reagent_change() +/obj/item/reagent_containers/glass/bowl/on_reagent_change(changetype) ..() update_icon() diff --git a/code/modules/hydroponics/biogenerator.dm b/code/modules/hydroponics/biogenerator.dm index 16d84d80026..6c9ef5f9467 100644 --- a/code/modules/hydroponics/biogenerator.dm +++ b/code/modules/hydroponics/biogenerator.dm @@ -53,7 +53,7 @@ productivity = P max_items = max_storage -/obj/machinery/biogenerator/on_reagent_change() //When the reagents change, change the icon as well. +/obj/machinery/biogenerator/on_reagent_change(changetype) //When the reagents change, change the icon as well. update_icon() /obj/machinery/biogenerator/update_icon() diff --git a/code/modules/integrated_electronics/passive/power.dm b/code/modules/integrated_electronics/passive/power.dm index 4b67f08a030..5cd9ee34fc3 100644 --- a/code/modules/integrated_electronics/passive/power.dm +++ b/code/modules/integrated_electronics/passive/power.dm @@ -108,7 +108,7 @@ push_data() ..() -/obj/item/integrated_circuit/passive/power/chemical_cell/on_reagent_change() +/obj/item/integrated_circuit/passive/power/chemical_cell/on_reagent_change(changetype) set_pin_data(IC_OUTPUT, 1, reagents.total_volume) push_data() diff --git a/code/modules/integrated_electronics/subtypes/reagents.dm b/code/modules/integrated_electronics/subtypes/reagents.dm index 9db83cfedcc..8a348f1cdaf 100644 --- a/code/modules/integrated_electronics/subtypes/reagents.dm +++ b/code/modules/integrated_electronics/subtypes/reagents.dm @@ -26,9 +26,10 @@ var/smoke_radius = 5 var/notified = FALSE -/obj/item/integrated_circuit/reagent/smoke/on_reagent_change() - //reset warning - notified = FALSE +/obj/item/integrated_circuit/reagent/smoke/on_reagent_change(changetype) + //reset warning only if we have reagents now + if(changetype == ADD_REAGENT) + notified = FALSE set_pin_data(IC_OUTPUT, 1, reagents.total_volume) push_data() @@ -46,7 +47,6 @@ if(S) S.set_up(reagents, smoke_radius, location, notified) if(!notified) - //we have now notified notified = TRUE S.start() @@ -81,7 +81,7 @@ ..() -/obj/item/integrated_circuit/reagent/injector/on_reagent_change() +/obj/item/integrated_circuit/reagent/injector/on_reagent_change(changetype) set_pin_data(IC_OUTPUT, 1, reagents.total_volume) push_data() @@ -259,7 +259,7 @@ push_data() ..() -/obj/item/integrated_circuit/reagent/storage/on_reagent_change() +/obj/item/integrated_circuit/reagent/storage/on_reagent_change(changetype) set_pin_data(IC_OUTPUT, 1, reagents.total_volume) push_data() diff --git a/code/modules/mob/living/simple_animal/bot/secbot.dm b/code/modules/mob/living/simple_animal/bot/secbot.dm index acef65f5456..82eae37f820 100644 --- a/code/modules/mob/living/simple_animal/bot/secbot.dm +++ b/code/modules/mob/living/simple_animal/bot/secbot.dm @@ -54,7 +54,7 @@ new /obj/item/stock_parts/cell/potato(Tsec) var/obj/item/reagent_containers/food/drinks/drinkingglass/shotglass/S = new(Tsec) S.reagents.add_reagent("whiskey", 15) - S.on_reagent_change() + S.on_reagent_change(ADD_REAGENT) ..() /mob/living/simple_animal/bot/secbot/pingsky diff --git a/code/modules/reagents/chemistry/holder.dm b/code/modules/reagents/chemistry/holder.dm index b962bf17c4e..2d3200c5068 100644 --- a/code/modules/reagents/chemistry/holder.dm +++ b/code/modules/reagents/chemistry/holder.dm @@ -1,5 +1,4 @@ - /////////////////////////////////////////////////////////////////////////////////// /datum/reagents @@ -429,7 +428,7 @@ reagent_list -= R update_total() if(my_atom) - my_atom.on_reagent_change() + my_atom.on_reagent_change(DEL_REAGENT) check_ignoreslow(my_atom) check_gofast(my_atom) check_goreallyfast(my_atom) @@ -527,7 +526,7 @@ R.volume += amount update_total() if(my_atom) - my_atom.on_reagent_change() + my_atom.on_reagent_change(ADD_REAGENT) R.on_merge(data, amount) if(!no_react) handle_reactions() @@ -546,7 +545,7 @@ update_total() if(my_atom) - my_atom.on_reagent_change() + my_atom.on_reagent_change(ADD_REAGENT) if(!no_react) handle_reactions() if(isliving(my_atom)) @@ -588,7 +587,7 @@ if(!safety)//So it does not handle reactions when it need not to handle_reactions() if(my_atom) - my_atom.on_reagent_change() + my_atom.on_reagent_change(REM_REAGENT) return TRUE return FALSE diff --git a/code/modules/reagents/reagent_containers/blood_pack.dm b/code/modules/reagents/reagent_containers/blood_pack.dm index 8856f773768..bc92521b934 100644 --- a/code/modules/reagents/reagent_containers/blood_pack.dm +++ b/code/modules/reagents/reagent_containers/blood_pack.dm @@ -13,7 +13,7 @@ reagents.add_reagent("blood", 200, list("donor"=null,"viruses"=null,"blood_DNA"=null,"blood_type"=blood_type,"resistances"=null,"trace_chem"=null)) update_icon() -/obj/item/reagent_containers/blood/on_reagent_change() +/obj/item/reagent_containers/blood/on_reagent_change(changetype) if(reagents) var/datum/reagent/blood/B = reagents.has_reagent("blood") if(B && B.data && B.data["blood_type"]) diff --git a/code/modules/reagents/reagent_containers/bottle.dm b/code/modules/reagents/reagent_containers/bottle.dm index 2425dca5ff6..749031b367e 100644 --- a/code/modules/reagents/reagent_containers/bottle.dm +++ b/code/modules/reagents/reagent_containers/bottle.dm @@ -15,7 +15,7 @@ icon_state = "bottle" update_icon() -/obj/item/reagent_containers/glass/bottle/on_reagent_change() +/obj/item/reagent_containers/glass/bottle/on_reagent_change(changetype) update_icon() /obj/item/reagent_containers/glass/bottle/update_icon() diff --git a/code/modules/reagents/reagent_containers/glass.dm b/code/modules/reagents/reagent_containers/glass.dm index 9544147bb0e..7a8fd395838 100755 --- a/code/modules/reagents/reagent_containers/glass.dm +++ b/code/modules/reagents/reagent_containers/glass.dm @@ -120,7 +120,7 @@ . = ..() update_icon() -/obj/item/reagent_containers/glass/beaker/on_reagent_change() +/obj/item/reagent_containers/glass/beaker/on_reagent_change(changetype) update_icon() /obj/item/reagent_containers/glass/beaker/update_icon() diff --git a/code/modules/reagents/reagent_containers/syringes.dm b/code/modules/reagents/reagent_containers/syringes.dm index 672af4425dd..24d3bd31491 100644 --- a/code/modules/reagents/reagent_containers/syringes.dm +++ b/code/modules/reagents/reagent_containers/syringes.dm @@ -21,7 +21,7 @@ mode = SYRINGE_INJECT update_icon() -/obj/item/reagent_containers/syringe/on_reagent_change() +/obj/item/reagent_containers/syringe/on_reagent_change(changetype) update_icon() /obj/item/reagent_containers/syringe/pickup(mob/user)