From d272f4fa309522750e6c2fd81040e4829648760b Mon Sep 17 00:00:00 2001 From: MistakeNot4892 Date: Sat, 27 Aug 2022 13:54:54 +1000 Subject: [PATCH] Adding some generalized reagent processing for animals. --- .../simple_mob/subtypes/animal/animal.dm | 9 ++++ .../subtypes/animal/sif/grafadreka.dm | 50 ++++++++++++------- code/modules/reagents/reagents/_reagents.dm | 3 ++ code/modules/reagents/reagents/food_drinks.dm | 13 +++-- code/modules/reagents/reagents/medicine.dm | 6 +++ code/modules/reagents/reagents/toxins.dm | 10 +++- 6 files changed, 67 insertions(+), 24 deletions(-) diff --git a/code/modules/mob/living/simple_mob/subtypes/animal/animal.dm b/code/modules/mob/living/simple_mob/subtypes/animal/animal.dm index 72edf494d9..040266740b 100644 --- a/code/modules/mob/living/simple_mob/subtypes/animal/animal.dm +++ b/code/modules/mob/living/simple_mob/subtypes/animal/animal.dm @@ -53,6 +53,12 @@ /mob/living/simple_mob/animal/proc/has_appetite() return TRUE +/mob/living/simple_mob/animal/proc/add_nutrition(var/amt) + nutrition = clamp(nutrition + amt, 0, max_nutrition) + +/mob/living/simple_mob/animal/proc/remove_nutrition(var/amt) + nutrition = clamp(nutrition - amt, 0, max_nutrition) + /mob/living/simple_mob/animal/get_snow_footprint_state() if(!hovering) return "snow_animalprints" @@ -123,3 +129,6 @@ snack.dropInto(loc) else snack.animal_consumed(src) + +/mob/living/simple_mob/animal/proc/get_dietary_food_modifier(var/datum/reagent/nutriment/food) + return 0.3 diff --git a/code/modules/mob/living/simple_mob/subtypes/animal/sif/grafadreka.dm b/code/modules/mob/living/simple_mob/subtypes/animal/sif/grafadreka.dm index b58cb034e6..e938c364fd 100644 --- a/code/modules/mob/living/simple_mob/subtypes/animal/sif/grafadreka.dm +++ b/code/modules/mob/living/simple_mob/subtypes/animal/sif/grafadreka.dm @@ -288,28 +288,24 @@ var/global/list/last_drake_howl = list() setMoveCooldown(1 SECOND) spend_sap(2) +/mob/living/simple_mob/animal/sif/grafadreka/get_dietary_food_modifier(var/datum/reagent/nutriment/food) + if(food.allergen_type & ALLERGEN_MEAT) + return ..() + return 0.1 + /mob/living/simple_mob/animal/sif/grafadreka/Life() . = ..() + // Don't make clientless drakes lose nutrition or they'll all go feral. + if(stat == CONSCIOUS && !resting && client) + remove_nutrition(0.3) + // Process food and sap chems. - if(stat == CONSCIOUS && client) // Hibernating drakes don't get hungy. - // by default we lose nutrition. Hungry hungry drakes. - - var/food_val = (resting || !client) ? 0 : -0.3 // Don't make clientless drakes lose nutrition or they'll all go feral. - - // Very basic metabolism. - if(reagents?.total_volume) - for(var/datum/reagent/chem in reagents.reagent_list) - var/removing = min(REM, chem.volume) - if(istype(chem, /datum/reagent/nutriment)) - var/datum/reagent/nutriment/food = chem - food_val += (food.nutriment_factor * removing) * ((food.allergen_type & ALLERGEN_MEAT) ? 0.3 : 0.1) - else if(istype(chem, /datum/reagent/toxin/sifslurry)) - add_sap(removing * 3) - reagents.remove_reagent(chem.id, removing) - - if(food_val != 0) - nutrition = clamp(nutrition + food_val, 0, max_nutrition) + if(reagents?.total_volume) + for(var/datum/reagent/chem in reagents.reagent_list) + var/removed = min(chem.ingest_met, chem.volume) + chem.affect_animal(src, removed) + reagents.remove_reagent(chem.id, removed) /mob/living/simple_mob/animal/sif/grafadreka/proc/has_sap(var/amt) return stored_sap >= amt @@ -648,10 +644,26 @@ var/global/list/last_drake_howl = list() name = "drake's pannier" /mob/living/simple_mob/animal/sif/grafadreka/trained/attackby(obj/item/O, mob/user) - if(user.a_intent == I_HURT || (istype(O, /obj/item/stack/medical) && user.a_intent == I_HELP)) + + // bonk + if(user.a_intent == I_HURT) return ..() + + // Pass some items down to heal or run injection etc. + var/static/list/allow_type_to_pass = list( + /obj/item/healthanalyzer, + /obj/item/stack/medical, + /obj/item/reagent_containers/syringe + ) + if(user.a_intent == I_HELP) + for(var/pass_type in allow_type_to_pass) + if(istype(O, pass_type)) + return ..() + + // Open our storage, if we have it. if(pannier) return pannier.attackby(O, user) + return ..() /mob/living/simple_mob/animal/sif/grafadreka/trained/add_glow() diff --git a/code/modules/reagents/reagents/_reagents.dm b/code/modules/reagents/reagents/_reagents.dm index fa59c30a3a..a3322c3f06 100644 --- a/code/modules/reagents/reagents/_reagents.dm +++ b/code/modules/reagents/reagents/_reagents.dm @@ -170,6 +170,9 @@ remove_self(removed) return +/datum/reagent/proc/affect_animal(var/mob/living/simple_mob/animal/M, var/removed) + return + /datum/reagent/proc/affect_blood(var/mob/living/carbon/M, var/alien, var/removed) return diff --git a/code/modules/reagents/reagents/food_drinks.dm b/code/modules/reagents/reagents/food_drinks.dm index 330276bd1e..00e3c153b5 100644 --- a/code/modules/reagents/reagents/food_drinks.dm +++ b/code/modules/reagents/reagents/food_drinks.dm @@ -36,6 +36,10 @@ if(data[taste]/totalFlavor < 0.1) data -= taste +/datum/reagent/nutriment/affect_animal(var/mob/living/simple_mob/animal/M, var/removed) + M.add_nutrition((nutriment_factor * removed) * M.get_dietary_food_modifier(src) * 0.5) + return ..() + /datum/reagent/nutriment/affect_blood(var/mob/living/carbon/M, var/alien, var/removed) if(!injectable && alien != IS_SLIME) M.adjustToxLoss(0.1 * removed) @@ -45,9 +49,12 @@ /datum/reagent/nutriment/affect_ingest(var/mob/living/carbon/M, var/alien, var/removed) switch(alien) - if(IS_DIONA) return - if(IS_UNATHI) removed *= 0.5 - if(issmall(M)) removed *= 2 // Small bodymass, more effect from lower volume. + if(IS_DIONA) + return + if(IS_UNATHI) + removed *= 0.5 + if(issmall(M)) + removed *= 2 // Small bodymass, more effect from lower volume. if(!(M.species.allergens & allergen_type)) //assuming it doesn't cause a horrible reaction, we'll be ok! M.heal_organ_damage(0.5 * removed, 0) M.adjust_nutrition(nutriment_factor * removed) diff --git a/code/modules/reagents/reagents/medicine.dm b/code/modules/reagents/reagents/medicine.dm index 41c81c214b..72be8b2157 100644 --- a/code/modules/reagents/reagents/medicine.dm +++ b/code/modules/reagents/reagents/medicine.dm @@ -52,6 +52,12 @@ overdose_mod = 0.25 scannable = 1 +/datum/reagent/bicaridine/affect_animal(var/mob/living/simple_mob/animal/M, var/removed) + if(istype(M, /mob/living/simple_mob/animal/sif/grafadreka)) + var/mob/living/simple_mob/animal/sif/grafadreka/drake = M + drake.sap_heal_threshold = clamp(drake.sap_heal_threshold + (0.1 * removed), 0, 1) + return ..() + /datum/reagent/bicaridine/affect_blood(var/mob/living/carbon/M, var/alien, var/removed) var/chem_effective = 1 * M.species.chem_strength_heal if(alien == IS_SLIME) diff --git a/code/modules/reagents/reagents/toxins.dm b/code/modules/reagents/reagents/toxins.dm index f15e8443cd..1bf8d04acb 100644 --- a/code/modules/reagents/reagents/toxins.dm +++ b/code/modules/reagents/reagents/toxins.dm @@ -442,15 +442,21 @@ color = "#C6E2FF" strength = 2 overdose = 20 + var/sap_regen_power = 12 /datum/reagent/toxin/sifslurry/affect_blood(var/mob/living/carbon/M, var/alien, var/removed) if(alien == IS_DIONA) // Symbiotic bacteria. M.adjust_nutrition(strength * removed) return - else - M.add_modifier(/datum/modifier/slow_pulse, 30 SECONDS) + M.add_modifier(/datum/modifier/slow_pulse, 30 SECONDS) ..() +/datum/reagent/toxin/sifslurry/affect_animal(var/mob/living/simple_mob/animal/M, var/removed) + if(istype(M, /mob/living/simple_mob/animal/sif/grafadreka)) + var/mob/living/simple_mob/animal/sif/grafadreka/drake = M + drake.add_sap(removed * sap_regen_power) + return ..() + /datum/reagent/toxin/sifslurry/overdose(var/mob/living/carbon/M, var/alien, var/removed) // Overdose effect. if(alien == IS_DIONA) return