Files
Bubberstation/code/datums/ai/hauntium/hauntium_subtrees.dm
MrMelbert ed2f04f486 Experiment with replacing weakrefs in AI blackboard with deleting signals, ideally making it easier to work with and harder to cause hard deletes (#74791)
## About The Pull Request

Replaces weakref usage in AI blackboards with deleting signals

All blackboard var setting must go through setters rather than directly

## Why It's Good For The Game

This both makes it a ton easier to develop AI for, and also makes it
harder for hard deletes to sneak in, as has been seen with recent 515
prs showing hard deletes in AI blackboards

(To quantify "making it easier to develop AI", I found multiple bugs in
existing AI code due to the usage of weakrefs.)

I'm looking for `@Jacquerel` `@tralezab` 's opinions on the matter, also
maybe `@LemonInTheDark` if they're interested

## Changelog

🆑 Melbert
refactor: Mob ai refactored once again
/🆑
2023-04-23 17:07:17 -06:00

25 lines
1.1 KiB
Plaintext

/datum/ai_planning_subtree/haunted/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
var/obj/item/item_pawn = controller.pawn
if(ismob(item_pawn.loc)) //We're being held, maybe escape?
if(controller.blackboard[BB_LIKES_EQUIPPER])//don't unequip from people it's okay with
return
if(SPT_PROB(HAUNTED_ITEM_ESCAPE_GRASP_CHANCE, seconds_per_tick))
controller.queue_behavior(/datum/ai_behavior/item_escape_grasp)
return SUBTREE_RETURN_FINISH_PLANNING
if(!SPT_PROB(HAUNTED_ITEM_ATTACK_HAUNT_CHANCE, seconds_per_tick))
return
var/list/to_haunt_list = controller.blackboard[BB_TO_HAUNT_LIST]
for(var/mob/living/haunt_target as anything in to_haunt_list)
if(to_haunt_list[haunt_target] <= 0)
controller.remove_thing_from_blackboard_key(BB_TO_HAUNT_LIST, haunt_target)
continue
if(get_dist(haunt_target, item_pawn) <= 7)
controller.set_blackboard_key(BB_HAUNT_TARGET, haunt_target)
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/ghostly/haunted, BB_HAUNT_TARGET, BB_HAUNTED_THROW_ATTEMPT_COUNT)
return SUBTREE_RETURN_FINISH_PLANNING