slightly redoes how animals hunt for food (#87166)

## About The Pull Request
before, if u wanted to make ur animal hunt for food, u had to give them
the find food subtree, the attacking subtree, and had to edit their
targeting stratedgy to include items. this makes it so u only have to
give them just 1 subtree which will handle everything it needs to. also
makes it alot more customizable, u can now set a hunger cooldown for ur
animals, and cute emotes for them to play after eating food

## Why It's Good For The Game
makes it more convenient for future devs to include food hunting
behaviors to their animals, while also making it more customizable

## Changelog
🆑
code: animals' food hunting behavior has been refactored, please report
any bugs
/🆑
This commit is contained in:
Ben10Omintrix
2024-10-15 03:18:37 +03:00
committed by GitHub
parent 3b6305acee
commit a99a1e6383
18 changed files with 96 additions and 60 deletions
@@ -9,6 +9,7 @@
update_speed(basic_mob)
RegisterSignals(basic_mob, list(POST_BASIC_MOB_UPDATE_VARSPEED, COMSIG_MOB_MOVESPEED_UPDATED), PROC_REF(update_speed))
RegisterSignal(basic_mob, COMSIG_MOB_ATE, PROC_REF(on_mob_eat))
return ..() //Run parent at end
@@ -44,3 +45,8 @@
/datum/ai_controller/basic_controller/proc/update_speed(mob/living/basic/basic_mob)
SIGNAL_HANDLER
movement_delay = basic_mob.cached_multiplicative_slowdown
/datum/ai_controller/basic_controller/proc/on_mob_eat()
SIGNAL_HANDLER
var/food_cooldown = blackboard[BB_EAT_FOOD_COOLDOWN] || EAT_FOOD_COOLDOWN
set_blackboard_key(BB_NEXT_FOOD_EAT, world.time + food_cooldown)
@@ -0,0 +1,27 @@
///behavior for general interactions with any targets
/datum/ai_behavior/interact_with_target
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT | AI_BEHAVIOR_REQUIRE_REACH
///should we be clearing the target after the fact?
var/clear_target = TRUE
/datum/ai_behavior/interact_with_target/setup(datum/ai_controller/controller, target_key)
. = ..()
var/atom/target = controller.blackboard[target_key]
if(QDELETED(target))
return FALSE
set_movement_target(controller, target)
/datum/ai_behavior/interact_with_target/perform(seconds_per_tick, datum/ai_controller/controller, target_key)
var/atom/target = controller.blackboard[target_key]
if(QDELETED(target) || !pre_interact(controller, target))
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_FAILED
controller.ai_interact(target)
return AI_BEHAVIOR_SUCCEEDED | AI_BEHAVIOR_DELAY
/datum/ai_behavior/interact_with_target/finish_action(datum/ai_controller/controller, succeeded, target_key)
. = ..()
if(clear_target || !succeeded)
controller.clear_blackboard_key(target_key)
/datum/ai_behavior/interact_with_target/proc/pre_interact(datum/ai_controller/controller, target)
return TRUE
@@ -4,11 +4,33 @@
var/datum/ai_behavior/finding_behavior = /datum/ai_behavior/find_and_set/in_list
///key of foods list
var/food_list_key = BB_BASIC_FOODS
///key where we store our food
var/found_food_key = BB_TARGET_FOOD
///key holding any emotes we play after eating food
var/emotes_blackboard_list = BB_EAT_EMOTES
/datum/ai_planning_subtree/find_food/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
. = ..()
if(controller.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET))
// Busy with something
if(controller.blackboard[BB_NEXT_FOOD_EAT] > world.time)
return
if(!controller.blackboard_key_exists(found_food_key))
controller.queue_behavior(finding_behavior, found_food_key, controller.blackboard[food_list_key])
return
controller.queue_behavior(/datum/ai_behavior/interact_with_target/eat_food, found_food_key, emotes_blackboard_list)
return SUBTREE_RETURN_FINISH_PLANNING
controller.queue_behavior(finding_behavior, BB_BASIC_MOB_CURRENT_TARGET, controller.blackboard[food_list_key])
/datum/ai_behavior/interact_with_target/eat_food
///default list of actions we take after eating
var/list/food_actions = list(
"eats up happily!",
"chomps with glee!",
)
/datum/ai_behavior/interact_with_target/eat_food/perform(seconds_per_tick, datum/ai_controller/controller, target_key, emotes_blackboard_list)
. = ..()
if(. & AI_BEHAVIOR_FAILED)
return
var/list/emotes_to_pick = controller.blackboard[emotes_blackboard_list] || food_actions
if(!length(emotes_to_pick))
return
var/mob/living/living_pawn = controller.pawn
living_pawn.manual_emote(pick(emotes_to_pick))