Files
Cirrial 31d4eb04f1 Fix Stoat Steal Behaviour (and some other AI stuff hopefully) (#94153)
## About The Pull Request

Two main things. 

Multiple instances of use of a proc in AI controllers seemingly assuming
the default behaviour will work for them, but what ends up happening is
`search_tactic` gets redefined and redefined with no defaut search range
parameter, so nothing ends up passed to the `search_tactic` child procs,
so they all call `oview` with `null` and this... somehow doesn't
runtime? Has behaviour that works some of the time??? I hate this
fucking language. Anyway.

Stoat steal items behaviour was completely broken and apparently was not
tested once since it was merged in. I've made the corrections I can, but
I haven't figured out why stoat AI never enters idle, so we have a
behaviour that leads to the stoat running up to an item, grabbing it,
and then just staying there, unmoving. I've sunk too many hours into
this, I'm just going to call it fixed and let someone else figure out
what exciting additions there need to be to a behaviour that was never
functional in the first place.

## Why It's Good For The Game

i don't know man i just want the pain to stop 

okay, generally speaking, when people write AI behaviours, they want
those AI behaviours to do something and not just silently fail for six
months or longer

## Changelog
🆑
fix: Stoats have a chance to try and grab items like they always should
have.
/🆑
2025-11-28 13:35:53 +02:00

61 lines
2.5 KiB
Plaintext

///simple behavior to make mobs randomly drag things around
/datum/ai_planning_subtree/steal_items/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
var/mob/living/living_pawn = controller.pawn
if(living_pawn.pulling)
if(prob(controller.blackboard[BB_GUILTY_CONSCIOUS_CHANCE]))
controller.queue_behavior(/datum/ai_behavior/stop_dragging)
return
if(!prob(controller.blackboard[BB_STEAL_CHANCE]))
return
if(!controller.blackboard_key_exists(BB_ITEM_TO_STEAL))
controller.queue_behavior(/datum/ai_behavior/find_and_set/find_stealable, BB_ITEM_TO_STEAL, /obj/item)
return
controller.queue_behavior(/datum/ai_behavior/drag_target, BB_ITEM_TO_STEAL)
return SUBTREE_RETURN_FINISH_PLANNING
/datum/ai_behavior/find_and_set/find_stealable
behavior_flags = AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION
action_cooldown = 2 MINUTES
/datum/ai_behavior/find_and_set/find_stealable/search_tactic(datum/ai_controller/controller, locate_path, search_range = SEARCH_TACTIC_DEFAULT_RANGE)
var/mob/living/living_pawn = controller.pawn
var/list/possible_items = shuffle_inplace(oview(search_range, controller.pawn))
for(var/obj/item/possible_item in possible_items)
if(possible_item.pulledby || possible_item.anchored)
continue
if(can_see(living_pawn, possible_item))
return possible_item
/datum/ai_behavior/stop_dragging
behavior_flags = AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION
/datum/ai_behavior/stop_dragging/perform(seconds_per_tick, datum/ai_controller/controller)
var/mob/living/living_pawn = controller.pawn
living_pawn.stop_pulling()
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED
/datum/ai_behavior/drag_target
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT | AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION | AI_BEHAVIOR_REQUIRE_REACH
/datum/ai_behavior/drag_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/drag_target/perform(seconds_per_tick, datum/ai_controller/controller, target_key)
var/atom/movable/target = controller.blackboard[target_key]
if(QDELETED(target) || target.anchored || target.pulledby)
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_FAILED
var/mob/living/our_mob = controller.pawn
our_mob.start_pulling(target)
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED
/datum/ai_behavior/drag_target/finish_action(datum/ai_controller/controller, succeeded, target_key)
. = ..()
controller.clear_blackboard_key(target_key)