Makes food/drink code easier to read (#18673)

* Change

* Container drank, for beakers too

* Fimx

* oops
This commit is contained in:
Guti
2025-11-05 23:40:18 +01:00
committed by GitHub
parent 34f10ee604
commit f8b05adc3b
4 changed files with 124 additions and 115 deletions
+3
View File
@@ -797,6 +797,9 @@
///from base of obj/item/reagent_containers/food/snacks/attack(): (mob/living/eater, mob/feeder)
#define COMSIG_FOOD_EATEN "food_eaten"
//Drink
#define COMSIG_CONTAINER_DRANK "container_drank"
//Gibs
///from base of /obj/effect/decal/cleanable/blood/gibs/streak(): (list/directions, list/diseases)
+41 -37
View File
@@ -22,22 +22,22 @@
/obj/item/reagent_containers/food/drinks/Initialize(mapload)
. = ..()
if (prob(cant_chance))
cant_open = 1
cant_open = TRUE
/obj/item/reagent_containers/food/drinks/on_reagent_change()
if (reagents.reagent_list.len > 0)
var/datum/reagent/R = reagents.get_master_reagent()
if(R.price_tag)
price_tag = R.price_tag
var/datum/reagent/reagent = reagents.get_master_reagent()
if(reagent.price_tag)
price_tag = reagent.price_tag
else
price_tag = null
return
/obj/item/reagent_containers/food/drinks/Destroy()
if(food_inserted_micros)
for(var/mob/M in food_inserted_micros)
M.dropInto(loc)
food_inserted_micros -= M
for(var/mob/mob in food_inserted_micros)
mob.dropInto(loc)
food_inserted_micros -= mob
. = ..()
return
@@ -52,22 +52,22 @@
to_chat(user, span_warning("You cannot drop anything into \the [src] without opening it first."))
return
var/obj/item/holder/H = W
var/obj/item/holder/holder = W
if(!food_inserted_micros)
food_inserted_micros = list()
var/mob/living/M = H.held_mob
var/mob/living/living_mob = holder.held_mob
M.forceMove(src)
H.held_mob = null
user.drop_from_inventory(H)
qdel(H)
living_mob.forceMove(src)
holder.held_mob = null
user.drop_from_inventory(holder)
qdel(holder)
food_inserted_micros += M
food_inserted_micros += living_mob
to_chat(user, span_warning("You drop [M] into \the [src]."))
to_chat(M, span_warning("[user] drops you into \the [src]."))
to_chat(user, span_warning("You drop [living_mob] into \the [src]."))
to_chat(living_mob, span_warning("[user] drops you into \the [src]."))
return
return ..()
@@ -86,13 +86,21 @@
return ..()
/obj/item/reagent_containers/food/drinks/proc/On_Consume(var/mob/living/M, var/mob/user, var/changed = FALSE)
if(!user)
user = M
/obj/item/reagent_containers/food/drinks/proc/On_Consume(var/mob/living/eater, var/mob/feeder, var/changed = FALSE)
SEND_SIGNAL(src, COMSIG_CONTAINER_DRANK, eater, feeder)
if(!feeder)
feeder = eater
if(food_inserted_micros && food_inserted_micros.len)
for(var/mob/living/F in food_inserted_micros)
for(var/mob/living/micro in food_inserted_micros)
if(!can_food_vore(eater, micro))
continue
if(!can_animal_vore(eater, micro)) //If the one doing the eating is a simple mob controlled by AI, check mob vore prefs
continue
var/do_nom = FALSE
if(!reagents.total_volume)
do_nom = TRUE
else
@@ -101,22 +109,18 @@
do_nom = TRUE
if(do_nom)
if(!can_food_vore(M, F))
continue
if(isanimal(M) && !F.allowmobvore && !M.ckey) //If the one doing the eating is a simple mob controlled by AI, check mob vore prefs
continue
F.forceMove(M.vore_selected)
food_inserted_micros -= F
micro.forceMove(eater.vore_selected)
food_inserted_micros -= micro
if(!reagents.total_volume && changed)
M.visible_message(span_notice("[M] finishes drinking from \the [src]."),span_notice("You finish drinking from \the [src]."))
eater.visible_message(span_notice("[eater] finishes drinking from \the [src]."),span_notice("You finish drinking from \the [src]."))
if(trash)
user.drop_from_inventory(src) //so icons update :[
feeder.drop_from_inventory(src) //so icons update :[
if(ispath(trash,/obj/item))
var/obj/item/TrashItem = new trash(user)
user.put_in_hands(TrashItem)
var/obj/item/TrashItem = new trash(feeder)
feeder.put_in_hands(TrashItem)
else if(istype(trash,/obj/item))
user.put_in_hands(trash)
feeder.put_in_hands(trash)
qdel(src)
return
@@ -144,7 +148,7 @@
if(standard_feed_mob(user, M))
return
return 0
return FALSE
/obj/item/reagent_containers/food/drinks/afterattack(obj/target, mob/user, proximity)
if(!proximity) return
@@ -158,23 +162,23 @@
/obj/item/reagent_containers/food/drinks/standard_feed_mob(var/mob/user, var/mob/target)
if(!is_open_container())
to_chat(user, span_notice("You need to open [src]!"))
return 1
return TRUE
var/original_volume = reagents.total_volume
.=..()
var/changed = !(reagents.total_volume == original_volume)
On_Consume(target,user,changed)
On_Consume(target, user, changed)
return
/obj/item/reagent_containers/food/drinks/standard_dispenser_refill(var/mob/user, var/obj/structure/reagent_dispensers/target)
if(!is_open_container())
to_chat(user, span_notice("You need to open [src]!"))
return 1
return TRUE
return ..()
/obj/item/reagent_containers/food/drinks/standard_pour_into(var/mob/user, var/atom/target)
if(!is_open_container())
to_chat(user, span_notice("You need to open [src]!"))
return 1
return TRUE
return ..()
/obj/item/reagent_containers/food/drinks/self_feed_message(var/mob/user)
@@ -194,7 +198,7 @@
to_chat(user, span_notice("You swallow a gulp from \the [src]."))
/obj/item/reagent_containers/food/drinks/feed_sound(var/mob/user)
playsound(src, 'sound/items/drink.ogg', rand(10, 50), 1)
playsound(src, 'sound/items/drink.ogg', rand(10, 50), TRUE)
/obj/item/reagent_containers/food/drinks/examine(mob/user)
. = ..()
+79 -78
View File
@@ -57,10 +57,14 @@
reagents.add_reagent(REAGENT_ID_NUTRIMENT,(nutriment_amt*2),nutriment_desc)
//Placeholder for effect that trigger on eating that aren't tied to reagents.
/obj/item/reagent_containers/food/snacks/proc/On_Consume(var/mob/living/M)
/obj/item/reagent_containers/food/snacks/proc/On_Consume(var/mob/living/eater, var/mob/living/feeder)
SEND_SIGNAL(src, COMSIG_FOOD_EATEN, eater, feeder)
if(food_inserted_micros && food_inserted_micros.len)
for(var/mob/living/F in food_inserted_micros)
var/do_nom = FALSE
for(var/mob/living/micro in food_inserted_micros)
if(!can_food_vore(eater, micro))
continue
var/do_nom
if(!reagents.total_volume)
do_nom = TRUE
@@ -70,19 +74,17 @@
do_nom = TRUE
if(do_nom)
if(!can_food_vore(M, F))
continue
F.forceMove(M.vore_selected)
food_inserted_micros -= F
micro.forceMove(eater.vore_selected)
food_inserted_micros -= micro
if(!reagents.total_volume)
M.balloon_alert_visible("eats \the [src].","finishes eating \the [src].")
eater.balloon_alert_visible("eats \the [src].","finishes eating \the [src].")
M.drop_from_inventory(src) // Drop food from inventory so it doesn't end up staying on the hud after qdel, and so inhands go away
eater.drop_from_inventory(src) // Drop food from inventory so it doesn't end up staying on the hud after qdel, and so inhands go away
if(trash)
var/obj/item/TrashItem = new trash(M)
M.put_in_hands(TrashItem)
var/obj/item/TrashItem = new trash(eater)
eater.put_in_hands(TrashItem)
qdel(src)
/obj/item/reagent_containers/food/snacks/attack_self(mob/user as mob)
@@ -92,12 +94,12 @@
if(canned && !user.incapacitated())
uncan(user)
/obj/item/reagent_containers/food/snacks/attack(mob/living/M as mob, mob/user as mob, def_zone)
/obj/item/reagent_containers/food/snacks/attack(mob/living/eater as mob, mob/user as mob, def_zone)
if(reagents && !reagents.total_volume)
balloon_alert(user, "none of \the [src] left!")
user.drop_from_inventory(src)
qdel(src)
return 0
return FALSE
if(package)
balloon_alert(user, "the package is in the way!")
@@ -107,82 +109,81 @@
balloon_alert(user, "the can is closed!")
return FALSE
if(istype(M, /mob/living/carbon))
if(istype(eater, /mob/living/carbon))
//TODO: replace with standard_feed_mob() call.
if(!M.consume_liquid_belly)
if(!eater.consume_liquid_belly)
if(liquid_belly_check())
to_chat(user, span_infoplain("[user == M ? "You can't" : "\The [M] can't"] consume that, it contains something produced from a belly!"))
to_chat(user, span_infoplain("[user == eater ? "You can't" : "\The [eater] can't"] consume that, it contains something produced from a belly!"))
return FALSE
var/swallow_whole = FALSE
var/obj/belly/belly_target // These are surprise tools that will help us later
var/fullness = M.nutrition + (M.reagents.get_reagent_amount(REAGENT_ID_NUTRIMENT) * 25)
if(M == user) //If you're eating it yourself
if(ishuman(M))
var/mob/living/carbon/human/H = M
if(!H.check_has_mouth())
var/fullness = eater.nutrition + (eater.reagents.get_reagent_amount(REAGENT_ID_NUTRIMENT) * 25)
if(eater == user) //If you're eating it yourself
if(ishuman(eater))
var/mob/living/carbon/human/human_eater = eater
if(!human_eater.check_has_mouth())
balloon_alert(user, "you don't have a mouth!")
return
var/obj/item/blocked = null
if(survivalfood)
blocked = H.check_mouth_coverage_survival()
blocked = human_eater.check_mouth_coverage_survival()
else
blocked = H.check_mouth_coverage()
blocked = human_eater.check_mouth_coverage()
if(blocked)
balloon_alert(user, "\the [blocked] is in the way!")
return
user.setClickCooldown(user.get_attack_speed(src)) //puts a limit on how fast people can eat/drink things
if (fullness <= 50)
to_chat(M, span_danger("You hungrily chew out a piece of [src] and gobble it!"))
to_chat(eater, span_danger("You hungrily chew out a piece of [src] and gobble it!"))
if (fullness > 50 && fullness <= 150)
to_chat(M, span_notice("You hungrily begin to eat [src]."))
to_chat(eater, span_notice("You hungrily begin to eat [src]."))
if (fullness > 150 && fullness <= 350)
to_chat(M, span_notice("You take a bite of [src]."))
to_chat(eater, span_notice("You take a bite of [src]."))
if (fullness > 350 && fullness <= 550)
to_chat(M, span_notice("You chew a bit of [src], despite feeling rather full."))
to_chat(eater, span_notice("You chew a bit of [src], despite feeling rather full."))
if (fullness > 550 && fullness <= 650)
to_chat(M, span_notice("You swallow some more of the [src], causing your belly to swell out a little."))
to_chat(eater, span_notice("You swallow some more of the [src], causing your belly to swell out a little."))
if (fullness > 650 && fullness <= 1000)
to_chat(M, span_notice("You stuff yourself with the [src]. Your stomach feels very heavy."))
to_chat(eater, span_notice("You stuff yourself with the [src]. Your stomach feels very heavy."))
if (fullness > 1000 && fullness <= 3000)
to_chat(M, span_notice("You swallow down the hunk of [src]. Surely you have to have some limits?"))
to_chat(eater, span_notice("You swallow down the hunk of [src]. Surely you have to have some limits?"))
if (fullness > 3000 && fullness <= 5500)
to_chat(M, span_danger("You force the piece of [src] down. You can feel your stomach getting firm as it reaches its limits."))
to_chat(eater, span_danger("You force the piece of [src] down. You can feel your stomach getting firm as it reaches its limits."))
if (fullness > 5500 && fullness <= 6000)
to_chat(M, span_danger("You glug down the bite of [src], you are reaching the very limits of what you can eat, but maybe a few more bites could be managed..."))
to_chat(eater, span_danger("You glug down the bite of [src], you are reaching the very limits of what you can eat, but maybe a few more bites could be managed..."))
if (fullness > 6000) // There has to be a limit eventually.
to_chat(M, span_danger("Nope. That's it. You literally cannot force any more of [src] to go down your throat. It's fair to say you're full."))
return 0
to_chat(eater, span_danger("Nope. That's it. You literally cannot force any more of [src] to go down your throat. It's fair to say you're full."))
return FALSE
else if(user.a_intent == I_HURT)
return ..()
else
if(ishuman(M))
var/mob/living/carbon/human/H = M
if(!H.check_has_mouth())
// to_chat(user, "Where do you intend to put \the [src]? \The [H] doesn't have a mouth!")
balloon_alert(user, "\the [H] doesn't have a mouth!")
if(ishuman(eater))
var/mob/living/carbon/human/human_eater = eater
if(!human_eater.check_has_mouth())
balloon_alert(user, "\the [human_eater] doesn't have a mouth!")
return
var/obj/item/blocked = null
var/unconcious = FALSE
blocked = H.check_mouth_coverage()
blocked = human_eater.check_mouth_coverage()
if(survivalfood)
blocked = H.check_mouth_coverage_survival()
if(H.stat && H.check_mouth_coverage())
blocked = human_eater.check_mouth_coverage_survival()
if(human_eater.stat && human_eater.check_mouth_coverage())
unconcious = TRUE
blocked = H.check_mouth_coverage()
blocked = human_eater.check_mouth_coverage()
if(isliving(user)) // We definitely are, but never hurts to check
var/mob/living/L = user
swallow_whole = L.stuffing_feeder
var/mob/living/feeder = user
swallow_whole = feeder.stuffing_feeder
if(swallow_whole)
belly_target = tgui_input_list(user, "Choose Belly", "Belly Choice", M.feedable_bellies())
belly_target = tgui_input_list(user, "Choose Belly", "Belly Choice", human_eater.feedable_bellies())
if(unconcious)
to_chat(user, span_warning("You can't feed [H] through \the [blocked] while they are unconcious!"))
to_chat(user, span_warning("You can't feed [human_eater] through \the [blocked] while they are unconcious!"))
return
if(blocked)
@@ -191,35 +192,35 @@
return
if(swallow_whole)
if(!(M.feeding))
balloon_alert(user, "you can't feed [H] a whole [src] as they refuse to be fed whole things!")
if(!(human_eater.feeding))
balloon_alert(user, "you can't feed [human_eater] a whole [src] as they refuse to be fed whole things!")
return
if(!belly_target)
balloon_alert(user, "you can't feed [H] a whole [src] as they don't appear to have a belly to fit it!")
balloon_alert(user, "you can't feed [human_eater] a whole [src] as they don't appear to have a belly to fit it!")
return
if(swallow_whole)
user.balloon_alert_visible("[user] attempts to make [M] consume [src] whole into their [belly_target].")
user.balloon_alert_visible("[user] attempts to make [human_eater] consume [src] whole into their [belly_target].")
else
user.balloon_alert_visible("[user] attempts to feed [M] [src].")
user.balloon_alert_visible("[user] attempts to feed [human_eater] [src].")
var/feed_duration = 3 SECONDS
if(swallow_whole)
feed_duration = 5 SECONDS
user.setClickCooldown(user.get_attack_speed(src))
if(!do_mob(user, M, feed_duration)) return
if(!do_mob(user, human_eater, feed_duration)) return
if(swallow_whole && !belly_target) return // Just in case we lost belly mid-feed
if(swallow_whole)
add_attack_logs(user,M,"Whole-fed with [src.name] containing [reagentlist(src)] into [belly_target]", admin_notify = FALSE)
user.visible_message("[user] successfully forces [src] into [M]'s [belly_target].")
user.balloon_alert_visible("forces [src] into [M]'s [belly_target]")
add_attack_logs(user, human_eater,"Whole-fed with [src.name] containing [reagentlist(src)] into [belly_target]", admin_notify = FALSE)
user.visible_message("[user] successfully forces [src] into [human_eater]'s [belly_target].")
user.balloon_alert_visible("forces [src] into [human_eater]'s [belly_target]")
else
add_attack_logs(user,M,"Fed with [src.name] containing [reagentlist(src)]", admin_notify = FALSE)
user.visible_message("[user] feeds [M] [src].")
user.balloon_alert_visible("feeds [M] [src].")
add_attack_logs(user, human_eater,"Fed with [src.name] containing [reagentlist(src)]", admin_notify = FALSE)
user.visible_message("[user] feeds [human_eater] [src].")
user.balloon_alert_visible("feeds [human_eater] [src].")
else
balloon_alert(user, "this creature does not seem to have a mouth!")
@@ -228,19 +229,19 @@
if(swallow_whole)
user.drop_item()
forceMove(belly_target)
return 1
return TRUE
else if(reagents) //Handle ingestion of the reagent.
playsound(M, eating_sound, rand(10,50), 1)
playsound(eater, eating_sound, rand(10,50), 1)
if(reagents.total_volume)
if(reagents.total_volume > bitesize)
reagents.trans_to_mob(M, bitesize, CHEM_INGEST)
reagents.trans_to_mob(eater, bitesize, CHEM_INGEST)
else
reagents.trans_to_mob(M, reagents.total_volume, CHEM_INGEST)
reagents.trans_to_mob(eater, reagents.total_volume, CHEM_INGEST)
bitecount++
On_Consume(M)
return 1
On_Consume(eater, user)
return TRUE
return 0
return FALSE
/obj/item/reagent_containers/food/snacks/examine(mob/user)
. = ..()
@@ -265,8 +266,8 @@
// Eating with forks
if(istype(W,/obj/item/material/kitchen/utensil))
var/obj/item/material/kitchen/utensil/U = W
U.load_food(user, src)
var/obj/item/material/kitchen/utensil/utensil = W
utensil.load_food(user, src)
return
if(food_can_insert_micro && istype(W, /obj/item/holder))
@@ -279,23 +280,23 @@
balloon_alert(user, "open \the [src] first!")
return
var/obj/item/holder/H = W
var/obj/item/holder/holder = W
if(!food_inserted_micros)
food_inserted_micros = list()
var/mob/living/M = H.held_mob
var/mob/living/living_mob = holder.held_mob
M.forceMove(src)
H.held_mob = null
user.drop_from_inventory(H)
qdel(H)
living_mob.forceMove(src)
holder.held_mob = null
user.drop_from_inventory(holder)
qdel(holder)
food_inserted_micros += M
food_inserted_micros += living_mob
to_chat(user, "Stuffed [M] into \the [src].")
balloon_alert(user, "stuffs [M] into \the [src].")
to_chat(M, span_warning("[user] stuffs you into \the [src]."))
to_chat(user, "Stuffed [living_mob] into \the [src].")
balloon_alert(user, "stuffs [living_mob] into \the [src].")
to_chat(living_mob, span_warning("[user] stuffs you into \the [src]."))
return
if (is_sliceable())
@@ -118,6 +118,7 @@
return FALSE
user.setClickCooldown(user.get_attack_speed(src)) //puts a limit on how fast people can eat/drink things
SEND_SIGNAL(src, COMSIG_CONTAINER_DRANK, target, user)
if(user == target)
self_feed_message(user)
reagents.trans_to_mob(user, issmall(user) ? CEILING(amount_per_transfer_from_this/2, 1) : amount_per_transfer_from_this, CHEM_INGEST)