Skip to content

Commit

Permalink
hunting behaviors no longer share a cooldown (tgstation#87670)
Browse files Browse the repository at this point in the history
## About The Pull Request
all hunting subtrees were sharing a singular cooldown. this makes it so
each subtree has its own cooldown

## Why It's Good For The Game
fixes hunting subtree cooldowns affecting other subtrees. 

## Changelog
:cl:
/:cl:
  • Loading branch information
Ben10Omintrix authored Nov 9, 2024
1 parent 27d9f99 commit bf2a1b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
8 changes: 5 additions & 3 deletions code/__DEFINES/ai/ai_blackboard.dm
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
#define BB_BANE_BATMAN "BB_bane_batman"
//yep that's it

///Hunting BB keys
//Hunting BB keys
///key that holds our current hunting target
#define BB_CURRENT_HUNTING_TARGET "BB_current_hunting_target"
///key that holds our less priority hunting target
#define BB_LOW_PRIORITY_HUNTING_TARGET "BB_low_priority_hunting_target"
#define BB_HUNTING_COOLDOWN "BB_HUNTING_COOLDOWN"

///key that holds the cooldown for our hunting subtree
#define BB_HUNTING_COOLDOWN(type) "BB_HUNTING_COOLDOWN_[type]"
///Basic Mob Keys

///Targeting subtrees
Expand Down
15 changes: 5 additions & 10 deletions code/datums/ai/hunting_behavior/hunting_behaviors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@
/datum/ai_planning_subtree/find_and_hunt_target/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
if(!SPT_PROB(hunt_chance, seconds_per_tick))
return
if(controller.blackboard[BB_HUNTING_COOLDOWN] >= world.time)
return
var/mob/living/living_pawn = controller.pawn
// We can't hunt if we're indisposed
if(HAS_TRAIT(controller.pawn, TRAIT_HANDS_BLOCKED) || living_pawn.stat != CONSCIOUS)

if(controller.blackboard[BB_HUNTING_COOLDOWN(type)] >= world.time)
return

var/atom/hunted = controller.blackboard[target_key]
// We're not hunting anything, look around for something
if(isnull(hunted))
if(!controller.blackboard_key_exists(target_key))
controller.queue_behavior(finding_behavior, target_key, hunt_targets, hunt_range)
return

Expand All @@ -44,7 +39,7 @@
// we may accidentally be executing another tree's hunt - not ideal,
// try to set a unique target key if you have multiple

controller.queue_behavior(hunting_behavior, target_key, BB_HUNTING_COOLDOWN)
controller.queue_behavior(hunting_behavior, target_key, BB_HUNTING_COOLDOWN(type))
if(finish_planning)
return SUBTREE_RETURN_FINISH_PLANNING //If we're hunting we're too busy for anything else

Expand Down Expand Up @@ -115,7 +110,7 @@

/datum/ai_behavior/hunt_target/finish_action(datum/ai_controller/controller, succeeded, hunting_target_key, hunting_cooldown_key)
. = ..()
if(succeeded)
if(succeeded && hunting_cooldown_key)
controller.set_blackboard_key(hunting_cooldown_key, world.time + hunt_cooldown)
else if(hunting_target_key)
controller.clear_blackboard_key(hunting_target_key)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/basic/slime/ai/pet_command.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

var/mob/living/basic/slime/slime_pawn = controller.pawn
if(isslime(slime_pawn) && slime_pawn.can_feed_on(controller.blackboard[BB_CURRENT_PET_TARGET], check_friendship = TRUE))
controller.queue_behavior(hunting_behavior, BB_CURRENT_PET_TARGET, BB_HUNTING_COOLDOWN)
controller.queue_behavior(hunting_behavior, BB_CURRENT_PET_TARGET)
return SUBTREE_RETURN_FINISH_PLANNING

return ..()

0 comments on commit bf2a1b7

Please sign in to comment.