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 17:07:17 -06:00
committed by GitHub
parent 23b09f8a14
commit ed2f04f486
92 changed files with 688 additions and 592 deletions
@@ -35,36 +35,22 @@
if(!targetting_datum)
CRASH("No target datum was supplied in the blackboard for [controller.pawn]")
var/list/enemy_refs = controller.blackboard[shitlist_key]
if (!length(enemy_refs))
finish_action(controller, succeeded = FALSE)
return
var/list/enemies_list = list()
for (var/datum/weakref/enemy_ref as anything in enemy_refs)
var/atom/enemy = enemy_ref.resolve()
if (!can_attack_target(living_mob, enemy, targetting_datum))
controller.blackboard[shitlist_key] -= enemy_ref
continue
enemies_list += enemy
var/list/enemies_list = controller.blackboard[shitlist_key]
if (!length(enemies_list))
finish_action(controller, succeeded = FALSE)
return
var/datum/weakref/weak_target = controller.blackboard[target_key]
var/atom/target = weak_target?.resolve()
if (target && (locate(target) in enemies_list)) // Don't bother changing
if (controller.blackboard[target_key] in enemies_list) // Don't bother changing
finish_action(controller, succeeded = FALSE)
return
var/atom/new_target = pick_final_target(controller, enemies_list)
controller.blackboard[target_key] = WEAKREF(new_target)
controller.set_blackboard_key(target_key, new_target)
var/atom/potential_hiding_location = targetting_datum.find_hidden_mobs(living_mob, new_target)
if(potential_hiding_location) //If they're hiding inside of something, we need to know so we can go for that instead initially.
controller.blackboard[hiding_location_key] = WEAKREF(potential_hiding_location)
controller.set_blackboard_key(hiding_location_key, potential_hiding_location)
finish_action(controller, succeeded = TRUE)