From 4d0558a3531f9d90129864f8e3bab75bb2f5f0f3 Mon Sep 17 00:00:00 2001 From: MistakeNot4892 Date: Tue, 18 Jul 2023 23:21:59 +1000 Subject: [PATCH] Further refinement of nutrition/thirst procs. --- code/modules/mob/living/carbon/human/human.dm | 7 +++-- code/modules/mob/living/life.dm | 30 +++++++++++++++---- code/modules/mob/living/silicon/silicon.dm | 4 +-- .../mob/living/simple_animal/simple_animal.dm | 5 ++-- mods/content/xenobiology/slime/_slime.dm | 14 ++++----- mods/content/xenobiology/slime/life.dm | 8 +++-- 6 files changed, 47 insertions(+), 21 deletions(-) diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 75f8240a50f..925374f0cd5 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -1293,10 +1293,11 @@ /mob/living/carbon/human/handle_nutrition_and_hydration() ..() - apply_nutrition_and_hydration_stressors() -/mob/living/carbon/human/proc/apply_nutrition_and_hydration_stressors() - SHOULD_CALL_PARENT(TRUE) + // Apply stressors. + if(!client) + return + var/nut = get_nutrition() var/maxnut = get_max_nutrition() if(nut < (maxnut * 0.3)) diff --git a/code/modules/mob/living/life.dm b/code/modules/mob/living/life.dm index c15f5ba2b36..2b6f6123600 100644 --- a/code/modules/mob/living/life.dm +++ b/code/modules/mob/living/life.dm @@ -51,13 +51,33 @@ return 1 -/mob/living/proc/handle_nutrition_and_hydration() +/mob/living/proc/experiences_hunger_and_thirst() + return TRUE + +/mob/living/proc/get_hunger_factor() + var/decl/species/my_species = get_species() + if(my_species) + return my_species.hunger_factor + return 0 + +/mob/living/proc/get_thirst_factor() var/decl/species/my_species = get_species() if(my_species) - if(nutrition > 0 && my_species.hunger_factor) - adjust_nutrition(-(my_species.hunger_factor)) - if(hydration > 0 && my_species.thirst_factor) - adjust_hydration(-(my_species.thirst_factor)) + return my_species.hunger_factor + return 0 + +/mob/living/proc/handle_nutrition_and_hydration() + SHOULD_CALL_PARENT(TRUE) + if(!experiences_hunger_and_thirst()) + return + if(get_nutrition() > 0) + var/hunger_factor = get_hunger_factor() + if(hunger_factor) + adjust_nutrition(-(hunger_factor)) + if(get_hydration() > 0) + var/thirst_factor = get_thirst_factor() + if(thirst_factor) + adjust_hydration(-(thirst_factor)) /mob/living/proc/handle_breathing() return diff --git a/code/modules/mob/living/silicon/silicon.dm b/code/modules/mob/living/silicon/silicon.dm index 7be30b91b9e..bca9a56d5e7 100644 --- a/code/modules/mob/living/silicon/silicon.dm +++ b/code/modules/mob/living/silicon/silicon.dm @@ -75,8 +75,8 @@ QDEL_NULL_LIST(stock_parts) return ..() -/mob/living/silicon/handle_nutrition_and_hydration() - return // Doesn't really apply to robots. Maybe unify this with cells in the future. +/mob/living/silicon/experiences_hunger_and_thirst() + return FALSE // Doesn't really apply to robots. Maybe unify this with cells in the future. /mob/living/silicon/get_nutrition() return get_max_nutrition() diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index b1a7c559d8b..6aec880fae9 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -643,8 +643,9 @@ var/global/list/simplemob_icon_bitflag_cache = list() /mob/living/simple_animal/proc/can_act() return !(QDELETED(src) || incapacitated() || (is_aquatic && !submerged())) -/mob/living/simple_animal/handle_nutrition_and_hydration() - return // They need a reliable way to recover nutrition/hydration before this is made general. +/mob/living/simple_animal/experiences_hunger_and_thirst() + // return !supernatural && !isSynthetic() + return FALSE // They need a reliable way to recover nutrition/hydration before this is made general. /mob/living/simple_animal/get_nutrition() return get_max_nutrition() diff --git a/mods/content/xenobiology/slime/_slime.dm b/mods/content/xenobiology/slime/_slime.dm index 196cbce3528..bdda4007942 100644 --- a/mods/content/xenobiology/slime/_slime.dm +++ b/mods/content/xenobiology/slime/_slime.dm @@ -22,13 +22,13 @@ bone_amount = 0 ai = /datum/ai/slime hud_type = /datum/hud/slime + nutrition = 800 var/is_adult = FALSE var/mutation_chance = 30 // Chance of mutating, should be between 25 and 35 var/powerlevel = 0 // 0-10 controls how much electricity they are generating var/amount_grown = 0 // controls how long the slime has been overfed, if 10, grows or reproduces var/weakref/feeding_on - var/nutrition = 800 var/toxloss = 0 var/hurt_temperature = T0C-50 // slime keeps taking damage when its bodytemperature is below this var/die_temperature = 50 // slime dies instantly when its bodytemperature is below this @@ -292,6 +292,12 @@ /mob/living/slime/check_has_mouth() return 0 +/mob/living/slime/set_nutrition(amt) + ..() + +/mob/living/slime/get_hydration() + return get_nutrition() + /mob/living/slime/proc/gain_nutrition(var/amount) adjust_nutrition(amount) if(prob(amount * 2)) // Gain around one level per 50 nutrition @@ -300,12 +306,6 @@ powerlevel = 10 adjustToxLoss(-10) -/mob/living/slime/get_nutrition() - return nutrition - -/mob/living/slime/adjust_nutrition(var/amt) - nutrition = clamp(nutrition + amt, 0, get_max_nutrition()) - /mob/living/slime/proc/get_hunger_state() . = 0 if (nutrition < get_starve_nutrition()) diff --git a/mods/content/xenobiology/slime/life.dm b/mods/content/xenobiology/slime/life.dm index 78a1de1c752..67c8e65c3a7 100644 --- a/mods/content/xenobiology/slime/life.dm +++ b/mods/content/xenobiology/slime/life.dm @@ -80,9 +80,13 @@ if(length(contents) != last_contents_length) queue_icon_update() -/mob/living/slime/handle_nutrition_and_hydration() +/mob/living/slime/get_hunger_factor() + return (0.1 + 0.05 * is_adult) + +/mob/living/slime/get_thirst_factor() + return 0 - adjust_nutrition(-(0.1 + 0.05 * is_adult)) +/mob/living/slime/handle_nutrition_and_hydration() // Digest whatever we've got floating around in our goop. if(length(contents))