Files
Bubberstation/code/datums/ai/objects/mod.dm
SkyratBot e6f66d3a4a [MIRROR] Experiment with replacing weakrefs in AI blackboard with deleting signals, ideally making it easier to work with and harder to cause hard deletes [MDB IGNORE] (#20719)
* 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
/🆑

* Experiment with replacing weakrefs in AI blackboard with deleting signals, ideally making it easier to work with and harder to cause hard deletes

---------

Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
2023-04-26 21:17:15 +01:00

49 lines
1.8 KiB
Plaintext

/// An AI controller for the MODsuit pathfinder module. It's activated by implant and attaches itself to the user.
/datum/ai_controller/mod
blackboard = list(
BB_MOD_TARGET,
BB_MOD_IMPLANT,
)
max_target_distance = MOD_AI_RANGE //a little spicy but its one specific item that summons it, and it doesn't run otherwise
ai_movement = /datum/ai_movement/jps
///ID card generated from the suit's required access. Used for pathing.
var/obj/item/card/id/advanced/id_card
/datum/ai_controller/mod/TryPossessPawn(atom/new_pawn)
if(!istype(new_pawn, /obj/item/mod/control))
return AI_CONTROLLER_INCOMPATIBLE
var/obj/item/mod/control/mod = new_pawn
id_card = new /obj/item/card/id/advanced/simple_bot()
if(length(mod.req_access))
id_card.set_access(mod.req_access)
return ..() //Run parent at end
/datum/ai_controller/mod/UnpossessPawn(destroy)
QDEL_NULL(id_card)
return ..() //Run parent at end
/datum/ai_controller/mod/SelectBehaviors(seconds_per_tick)
current_behaviors = list()
if(blackboard[BB_MOD_TARGET] && blackboard[BB_MOD_IMPLANT])
queue_behavior(/datum/ai_behavior/mod_attach)
/datum/ai_controller/mod/get_access()
return id_card
/datum/ai_behavior/mod_attach
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT|AI_BEHAVIOR_MOVE_AND_PERFORM
/datum/ai_behavior/mod_attach/perform(seconds_per_tick, datum/ai_controller/controller)
. = ..()
if(!controller.pawn.Adjacent(controller.blackboard[BB_MOD_TARGET]))
return
var/obj/item/implant/mod/implant = controller.blackboard[BB_MOD_IMPLANT]
implant.module.attach(controller.blackboard[BB_MOD_TARGET])
finish_action(controller, TRUE)
/datum/ai_behavior/mod_attach/finish_action(datum/ai_controller/controller, succeeded)
. = ..()
controller.clear_blackboard_key(BB_MOD_TARGET)
var/obj/item/implant/mod/implant = controller.blackboard[BB_MOD_IMPLANT]
implant.end_recall(succeeded)