Files
Bubberstation/code/datums/elements/basic_eating.dm
tralezab ce20a5b85e Cows can eat wheat off the ground. If cows see wheat on the ground, they'll try to go eat it (+ moonicorns with galaxy thistle) (#69253)
About The Pull Request

Cows are now grazers, they love eatin' wheat and it even heals them if hurt. If they see it just on the ground, they might eat it all! Careful, botanists! While tamed, cows won't eat off the ground if they're busy ferrying you around.

FYI: this is going to conflict with #69247 and so thiss should not be merged until that is

Why It's Good For The Game

Wanted to add this with the original port of cows to basic mobs, didn't have the TECH to do so. Now I do, now it's done. I also wanted it ready for the future where mice and rats are ported, so they'd seek out cheese to eat. I also also think it's a neat way for a cow to heal.
2022-08-30 15:39:30 -07:00

52 lines
1.7 KiB
Plaintext

/**
* ## basic eating element!
*
* Small behavior for non-carbons to eat certain stuff they interact with
*/
/datum/element/basic_eating
element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH
id_arg_index = 2
///Path of the reagent added
var/heal_amt
/// Types the animal can eat.
var/list/food_types
/datum/element/basic_eating/Attach(datum/target, heal_amt = 0, food_types = list())
. = ..()
if(!isliving(target))
return ELEMENT_INCOMPATIBLE
src.heal_amt = heal_amt
src.food_types = food_types
//this lets players eat
RegisterSignal(target, COMSIG_LIVING_UNARMED_ATTACK, .proc/on_unarm_attack)
//this lets ai eat. yes, i'm serious
RegisterSignal(target, COMSIG_HOSTILE_PRE_ATTACKINGTARGET, .proc/on_pre_attackingtarget)
/datum/element/basic_eating/Detach(datum/target)
UnregisterSignal(target, list(COMSIG_LIVING_UNARMED_ATTACK, COMSIG_HOSTILE_PRE_ATTACKINGTARGET))
return ..()
/datum/element/basic_eating/proc/on_unarm_attack(mob/living/eater, atom/target, proximity, modifiers)
SIGNAL_HANDLER
try_eating(eater, target)
/datum/element/basic_eating/proc/on_pre_attackingtarget(mob/living/eater, atom/target)
SIGNAL_HANDLER
try_eating(eater, target)
/datum/element/basic_eating/proc/try_eating(mob/living/eater, atom/target)
if(eater.combat_mode)
return
if(!is_type_in_list(target, food_types))
return
var/eat_verb = pick("bite","chew","nibble","gnaw","gobble","chomp")
var/healed = heal_amt && eater.health < eater.maxHealth
if(heal_amt)
eater.heal_overall_damage(heal_amt)
eater.visible_message(span_notice("[eater] [eat_verb]s [target]."), span_notice("You [eat_verb] [target][healed ? ", restoring some health" : ""]."))
playsound(eater.loc,'sound/items/eatfood.ogg', rand(10,50), TRUE)
qdel(target)