Skip to content

Commit

Permalink
Merge pull request #3236 from MistakeNot4892/nutrition
Browse files Browse the repository at this point in the history
Nutrition and hydration adjustments.
  • Loading branch information
out-of-phaze authored Aug 9, 2023
2 parents f39572e + 4d0558a commit fdabdf7
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 63 deletions.
18 changes: 0 additions & 18 deletions code/modules/mob/living/carbon/carbon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -319,24 +319,6 @@
/mob/living/carbon/get_max_hydration()
return 400

/mob/living/carbon/proc/set_nutrition(var/amt)
nutrition = clamp(amt, 0, get_max_nutrition())

/mob/living/carbon/get_nutrition(var/amt)
return nutrition

/mob/living/carbon/adjust_nutrition(var/amt)
set_nutrition(nutrition + amt)

/mob/living/carbon/get_hydration(var/amt)
return hydration

/mob/living/carbon/proc/set_hydration(var/amt)
hydration = clamp(amt, 0, get_max_hydration())

/mob/living/carbon/adjust_hydration(var/amt)
set_hydration(hydration + amt)

/mob/living/carbon/fluid_act(var/datum/reagents/fluids)
..()
if(QDELETED(src) || !fluids?.total_volume || !touching)
Expand Down
3 changes: 0 additions & 3 deletions code/modules/mob/living/carbon/carbon_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
var/lastpuke = 0
var/lastcough = 0

var/nutrition = 400
var/hydration = 400

var/obj/item/tank/internal = null//Human/Monkey
var/decl/species/species // Contains environment tolerances and language information, set during New().

Expand Down
28 changes: 28 additions & 0 deletions code/modules/mob/living/carbon/human/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1312,3 +1312,31 @@
if(safety > FLASH_PROTECTION_NONE)
flash_strength = (flash_strength / 2)
. = ..()

/mob/living/carbon/human/handle_nutrition_and_hydration()
..()

// Apply stressors.
if(!client)
return

var/nut = get_nutrition()
var/maxnut = get_max_nutrition()
if(nut < (maxnut * 0.3))
add_stressor(/datum/stressor/hungry_very, STRESSOR_DURATION_INDEFINITE)
else
remove_stressor(/datum/stressor/hungry_very)
if(nut < (maxnut * 0.5))
add_stressor(/datum/stressor/hungry, STRESSOR_DURATION_INDEFINITE)
else
remove_stressor(/datum/stressor/hungry)
var/hyd = get_hydration()
var/maxhyd = get_max_hydration()
if(hyd < (maxhyd * 0.3))
add_stressor(/datum/stressor/thirsty_very, STRESSOR_DURATION_INDEFINITE)
else
remove_stressor(/datum/stressor/thirsty_very)
if(hyd < (maxhyd * 0.5))
add_stressor(/datum/stressor/thirsty, STRESSOR_DURATION_INDEFINITE)
else
remove_stressor(/datum/stressor/thirsty)
7 changes: 0 additions & 7 deletions code/modules/mob/living/carbon/human/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,6 @@

return 1

/mob/living/carbon/human/handle_nutrition_and_hydration()
if(nutrition > 0)
adjust_nutrition(-species.hunger_factor)
if(hydration > 0)
adjust_hydration(-species.thirst_factor)
..()

/mob/living/carbon/human/handle_regular_hud_updates()
if(hud_updateflag) // update our mob's hud overlays, AKA what others see flaoting above our head
handle_hud_list()
Expand Down
45 changes: 25 additions & 20 deletions code/modules/mob/living/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,33 @@

return 1

/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)
return my_species.hunger_factor
return 0

/mob/living/proc/handle_nutrition_and_hydration()
SHOULD_CALL_PARENT(TRUE)
var/nut = get_nutrition()
var/maxnut = get_max_nutrition()
if(nut < (maxnut * 0.3))
add_stressor(/datum/stressor/hungry_very, STRESSOR_DURATION_INDEFINITE)
else
remove_stressor(/datum/stressor/hungry_very)
if(nut < (maxnut * 0.5))
add_stressor(/datum/stressor/hungry, STRESSOR_DURATION_INDEFINITE)
else
remove_stressor(/datum/stressor/hungry)
var/hyd = get_hydration()
var/maxhyd = get_max_hydration()
if(hyd < (maxhyd * 0.3))
add_stressor(/datum/stressor/thirsty_very, STRESSOR_DURATION_INDEFINITE)
else
remove_stressor(/datum/stressor/thirsty_very)
if(hyd < (maxhyd * 0.5))
add_stressor(/datum/stressor/thirsty, STRESSOR_DURATION_INDEFINITE)
else
remove_stressor(/datum/stressor/thirsty)
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
Expand Down
18 changes: 12 additions & 6 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -842,20 +842,26 @@ default behaviour is:
/mob/living/proc/get_max_nutrition()
return 500

/mob/living/proc/get_nutrition()
return get_max_nutrition()
/mob/living/proc/set_nutrition(var/amt)
nutrition = clamp(amt, 0, get_max_nutrition())

/mob/living/proc/get_nutrition(var/amt)
return nutrition

/mob/living/proc/adjust_nutrition(var/amt)
return
set_nutrition(nutrition + amt)

/mob/living/proc/get_max_hydration()
return 500

/mob/living/proc/get_hydration()
return get_max_hydration()
/mob/living/proc/get_hydration(var/amt)
return hydration

/mob/living/proc/set_hydration(var/amt)
hydration = clamp(amt, 0, get_max_hydration())

/mob/living/proc/adjust_hydration(var/amt)
return
set_hydration(hydration + amt)

/mob/living/proc/has_chemical_effect(var/chem, var/threshold_over, var/threshold_under)
var/val = GET_CHEMICAL_EFFECT(src, chem)
Expand Down
3 changes: 3 additions & 0 deletions code/modules/mob/living/living_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
var/list/stasis_sources
var/stasis_value

var/nutrition = 400
var/hydration = 400

var/original_fingerprint_seed
var/fingerprint
var/original_genetic_seed
Expand Down
9 changes: 9 additions & 0 deletions code/modules/mob/living/silicon/silicon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@
QDEL_NULL_LIST(stock_parts)
return ..()

/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()

/mob/living/silicon/get_hydration()
return get_max_hydration()

/mob/living/silicon/fully_replace_character_name(new_name)
..()
create_or_update_account(new_name)
Expand Down
10 changes: 10 additions & 0 deletions code/modules/mob/living/simple_animal/simple_animal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,13 @@ 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/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()

/mob/living/simple_animal/get_hydration()
return get_max_hydration()
14 changes: 7 additions & 7 deletions mods/content/xenobiology/slime/_slime.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down
8 changes: 6 additions & 2 deletions mods/content/xenobiology/slime/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit fdabdf7

Please sign in to comment.