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
/🆑
This commit is contained in:
MrMelbert
2023-04-23 18:07:17 -05:00
committed by GitHub
parent 23b09f8a14
commit ed2f04f486
92 changed files with 688 additions and 592 deletions
@@ -56,6 +56,6 @@
devour.Grant(src)
var/datum/action/adjust_vision/bileworm/adjust_vision = new(src)
adjust_vision.Grant(src)
ai_controller.blackboard[BB_BILEWORM_SPEW_BILE] = WEAKREF(spew_bile)
ai_controller.blackboard[BB_BILEWORM_RESURFACE] = WEAKREF(resurface)
ai_controller.blackboard[BB_BILEWORM_DEVOUR] = WEAKREF(devour)
ai_controller.set_blackboard_key(BB_BILEWORM_SPEW_BILE, spew_bile)
ai_controller.set_blackboard_key(BB_BILEWORM_RESURFACE, resurface)
ai_controller.set_blackboard_key(BB_BILEWORM_DEVOUR, devour)
@@ -15,7 +15,7 @@
to_chat(burrower, span_warning("Couldn't burrow anywhere near the target!"))
if(burrower.ai_controller?.ai_status == AI_STATUS_ON)
//this is a valid reason to give up on a target
burrower.ai_controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET] = null
burrower.ai_controller.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET)
return
playsound(burrower, 'sound/effects/break_stone.ogg', 50, TRUE)
new /obj/effect/temp_visual/mook_dust(get_turf(burrower))
@@ -13,17 +13,15 @@
/datum/ai_planning_subtree/bileworm_attack/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
var/datum/weakref/weak_target = controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET]
var/mob/living/target = weak_target?.resolve()
var/mob/living/target = controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET]
if(QDELETED(target))
return
var/datum/weakref/weak_action = controller.blackboard[BB_BILEWORM_RESURFACE]
var/datum/action/cooldown/mob_cooldown/resurface = weak_action?.resolve()
var/datum/action/cooldown/mob_cooldown/resurface = controller.blackboard[BB_BILEWORM_RESURFACE]
//because one ability is always INFINITY cooldown, this actually works to check which ability should be used
//sometimes it will try to spew bile on infinity cooldown, but that's okay because as soon as resurface is ready it will attempt that
if(resurface && resurface.next_use_time <= world.time)
if(!QDELETED(resurface) && resurface.next_use_time <= world.time)
controller.queue_behavior(/datum/ai_behavior/targeted_mob_ability/and_plan_execute, BB_BILEWORM_RESURFACE, BB_BASIC_MOB_CURRENT_TARGET)
else
controller.queue_behavior(/datum/ai_behavior/targeted_mob_ability/and_plan_execute, BB_BILEWORM_SPEW_BILE, BB_BASIC_MOB_CURRENT_TARGET)
@@ -33,8 +31,7 @@
/datum/ai_planning_subtree/bileworm_execute/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
var/datum/weakref/weak_target = controller.blackboard[BB_BASIC_MOB_EXECUTION_TARGET]
var/mob/living/target = weak_target?.resolve()
var/mob/living/target = controller.blackboard[BB_BASIC_MOB_EXECUTION_TARGET]
if(QDELETED(target) || target.stat < UNCONSCIOUS)
return