From ea351bc9ac54fc05e25f33ed669a9000fa121f11 Mon Sep 17 00:00:00 2001 From: ShizCalev Date: Fri, 24 Jul 2020 22:30:03 -0400 Subject: [PATCH] Merge pull request #52433 from Jared-Fogle/metabolization-tests Add unit tests for metabolizing of all reagents and fix the ones that failed --- code/modules/mob/living/carbon/carbon.dm | 2 +- .../chemistry/reagents/alcohol_reagents.dm | 14 +++++++------- .../chemistry/reagents/drink_reagents.dm | 2 +- .../chemistry/reagents/drug_reagents.dm | 8 ++++---- .../chemistry/reagents/medicine_reagents.dm | 2 +- code/modules/unit_tests/_unit_tests.dm | 1 + code/modules/unit_tests/metabolizing.dm | 19 +++++++++++++++++++ 7 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 code/modules/unit_tests/metabolizing.dm diff --git a/code/modules/mob/living/carbon/carbon.dm b/code/modules/mob/living/carbon/carbon.dm index 6b7c183c7af..e94dc3c19d1 100644 --- a/code/modules/mob/living/carbon/carbon.dm +++ b/code/modules/mob/living/carbon/carbon.dm @@ -506,7 +506,7 @@ if(T) T.add_vomit_floor(src, VOMIT_TOXIC, purge)//toxic barf looks different || call purge when doing detoxicfication to pump more chems out of the stomach. T = get_step(T, dir) - if (is_blocked_turf(T)) + if (T != null && is_blocked_turf(T)) break return TRUE diff --git a/code/modules/reagents/chemistry/reagents/alcohol_reagents.dm b/code/modules/reagents/chemistry/reagents/alcohol_reagents.dm index e77a51fcd98..3731010234f 100644 --- a/code/modules/reagents/chemistry/reagents/alcohol_reagents.dm +++ b/code/modules/reagents/chemistry/reagents/alcohol_reagents.dm @@ -103,7 +103,7 @@ All effects don't start immediately, but rather get worse over time; the rate is taste_description = "dish water" glass_name = "glass of light beer" glass_desc = "A freezing pint of watery light beer." - + /datum/reagent/consumable/ethanol/beer/maltliquor name = "Malt Liquor" description = "An alcoholic beverage brewed since ancient times on Old Earth. This variety is stronger than usual, super cheap, and super terrible." @@ -683,14 +683,14 @@ All effects don't start immediately, but rather get worse over time; the rate is /datum/reagent/consumable/ethanol/beepsky_smash/on_mob_metabolize(mob/living/carbon/M) if(HAS_TRAIT(M, TRAIT_ALCOHOL_TOLERANCE)) metabolization_rate = 0.8 - if(!HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) + if(M.mind != null && !HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) B = new() M.gain_trauma(B, TRAUMA_RESILIENCE_ABSOLUTE) ..() /datum/reagent/consumable/ethanol/beepsky_smash/on_mob_life(mob/living/carbon/M) M.Jitter(2) - if(HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) + if(M.mind != null && HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) M.adjustStaminaLoss(-10, 0) if(prob(20)) new /datum/hallucination/items_other(M) @@ -705,7 +705,7 @@ All effects don't start immediately, but rather get worse over time; the rate is return ..() /datum/reagent/consumable/ethanol/beepsky_smash/overdose_start(mob/living/carbon/M) - if(!HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) + if(M.mind != null && !HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) M.gain_trauma(/datum/brain_trauma/mild/phobia/security, TRAUMA_RESILIENCE_BASIC) /datum/reagent/consumable/ethanol/irish_cream @@ -1521,7 +1521,7 @@ All effects don't start immediately, but rather get worse over time; the rate is /datum/reagent/consumable/ethanol/quadruple_sec/on_mob_life(mob/living/carbon/M) //Securidrink in line with the Screwdriver for engineers or Nothing for mimes - if(HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) + if(M.mind != null && HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) M.heal_bodypart_damage(1, 1) M.adjustBruteLoss(-2,0) . = 1 @@ -1540,7 +1540,7 @@ All effects don't start immediately, but rather get worse over time; the rate is /datum/reagent/consumable/ethanol/quintuple_sec/on_mob_life(mob/living/carbon/M) //Securidrink in line with the Screwdriver for engineers or Nothing for mimes but STRONG.. - if(HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) + if(M.mind != null && HAS_TRAIT(M.mind, TRAIT_LAW_ENFORCEMENT_METABOLISM)) M.heal_bodypart_damage(2,2,2) M.adjustBruteLoss(-5,0) M.adjustOxyLoss(-5,0) @@ -2154,7 +2154,7 @@ All effects don't start immediately, but rather get worse over time; the rate is glass_desc = "boozy Catholicism in a glass." /datum/reagent/consumable/ethanol/trappist/on_mob_life(mob/living/carbon/M) - if(M.mind.holy_role) + if(M.mind?.holy_role) M.adjustFireLoss(-2.5, 0) M.jitteriness = max(0, M.jitteriness-1) M.stuttering = max(0, M.stuttering-1) diff --git a/code/modules/reagents/chemistry/reagents/drink_reagents.dm b/code/modules/reagents/chemistry/reagents/drink_reagents.dm index 19aa060636a..9d0cf3a01e9 100644 --- a/code/modules/reagents/chemistry/reagents/drink_reagents.dm +++ b/code/modules/reagents/chemistry/reagents/drink_reagents.dm @@ -525,7 +525,7 @@ /datum/reagent/consumable/pwr_game/on_mob_life(mob/living/carbon/M) M.adjust_bodytemperature(-8 * TEMPERATURE_DAMAGE_COEFFICIENT, M.get_body_temp_normal()) if(prob(10)) - M?.mind.adjust_experience(/datum/skill/gaming, 5) + M.mind?.adjust_experience(/datum/skill/gaming, 5) ..() /datum/reagent/consumable/shamblers diff --git a/code/modules/reagents/chemistry/reagents/drug_reagents.dm b/code/modules/reagents/chemistry/reagents/drug_reagents.dm index 2e10f5be432..84aa0ee6832 100644 --- a/code/modules/reagents/chemistry/reagents/drug_reagents.dm +++ b/code/modules/reagents/chemistry/reagents/drug_reagents.dm @@ -418,7 +418,7 @@ /datum/reagent/drug/happiness/addiction_act_stage1(mob/living/M)// all work and no play makes jack a dull boy var/datum/component/mood/mood = M.GetComponent(/datum/component/mood) - mood.setSanity(min(mood.sanity, SANITY_DISTURBED)) + mood?.setSanity(min(mood.sanity, SANITY_DISTURBED)) M.Jitter(5) if(prob(20)) M.emote(pick("twitch","laugh","frown")) @@ -426,7 +426,7 @@ /datum/reagent/drug/happiness/addiction_act_stage2(mob/living/M) var/datum/component/mood/mood = M.GetComponent(/datum/component/mood) - mood.setSanity(min(mood.sanity, SANITY_UNSTABLE)) + mood?.setSanity(min(mood.sanity, SANITY_UNSTABLE)) M.Jitter(10) if(prob(30)) M.emote(pick("twitch","laugh","frown")) @@ -434,7 +434,7 @@ /datum/reagent/drug/happiness/addiction_act_stage3(mob/living/M) var/datum/component/mood/mood = M.GetComponent(/datum/component/mood) - mood.setSanity(min(mood.sanity, SANITY_CRAZY)) + mood?.setSanity(min(mood.sanity, SANITY_CRAZY)) M.Jitter(15) if(prob(40)) M.emote(pick("twitch","laugh","frown")) @@ -442,7 +442,7 @@ /datum/reagent/drug/happiness/addiction_act_stage4(mob/living/carbon/human/M) var/datum/component/mood/mood = M.GetComponent(/datum/component/mood) - mood.setSanity(SANITY_INSANE) + mood?.setSanity(SANITY_INSANE) M.Jitter(20) if(prob(50)) M.emote(pick("twitch","laugh","frown")) diff --git a/code/modules/reagents/chemistry/reagents/medicine_reagents.dm b/code/modules/reagents/chemistry/reagents/medicine_reagents.dm index 592924afaea..1bcccb55e18 100644 --- a/code/modules/reagents/chemistry/reagents/medicine_reagents.dm +++ b/code/modules/reagents/chemistry/reagents/medicine_reagents.dm @@ -1217,7 +1217,7 @@ M.confused = max(0, M.confused-6) M.disgust = max(0, M.disgust-6) var/datum/component/mood/mood = M.GetComponent(/datum/component/mood) - if(mood.sanity <= SANITY_NEUTRAL) // only take effect if in negative sanity and then... + if(mood != null && mood.sanity <= SANITY_NEUTRAL) // only take effect if in negative sanity and then... mood.setSanity(min(mood.sanity+5, SANITY_NEUTRAL)) // set minimum to prevent unwanted spiking over neutral ..() . = 1 diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 8526225df1a..a82f67be66e 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -16,6 +16,7 @@ #include "chain_pull_through_space.dm" #include "component_tests.dm" #include "keybinding_init.dm" +#include "metabolizing.dm" #include "outfit_sanity.dm" #include "plantgrowth_tests.dm" #include "reagent_id_typos.dm" diff --git a/code/modules/unit_tests/metabolizing.dm b/code/modules/unit_tests/metabolizing.dm new file mode 100644 index 00000000000..895762c0ecc --- /dev/null +++ b/code/modules/unit_tests/metabolizing.dm @@ -0,0 +1,19 @@ +/datum/unit_test/metabolization/Run() + // Pause natural mob life so it can be handled entirely by the test + SSmobs.pause() + + var/mob/living/carbon/human/human = allocate(/mob/living/carbon/human) + var/mob/living/carbon/monkey/monkey = allocate(/mob/living/carbon/monkey) + + for (var/reagent_type in subtypesof(/datum/reagent)) + test_reagent(human, reagent_type) + test_reagent(monkey, reagent_type) + +/datum/unit_test/metabolization/proc/test_reagent(mob/living/carbon/C, reagent_type) + C.reagents.add_reagent(reagent_type, 10) + C.reagents.metabolize(C, can_overdose = TRUE) + C.reagents.clear_reagents() + +/datum/unit_test/metabolization/Destroy() + SSmobs.ignite() + return ..()