Files
Bubberstation/code/datums/ai/hauntium/haunted_controller.dm
SkyratBot ab16ced352 [MIRROR] Fixes Hauntium runtiming to hell (get it) due to real fake weakrefs [MDB IGNORE] (#11447)
* Fixes Hauntium runtiming to hell (get it) due to real fake weakrefs (#64779)

Hauntium AI was recently changed to use weakrefs to cut back on hard deletes
Unfortunately, not all cases of hauntium AI assigning references were swapped to weakrefs.
Meaning the haunting list ended up being some weird combination of hard references to mobs and weak references.

These hard references in the list caused a million runtimes a second because the ai was, of course, trying to resolve() hard references which doesn't work and it was doing it every second

Hauntium should now properly use weakrefs in the cases it's used in.

Spooky things actually haunt again

* Fixes Hauntium runtiming to hell (get it) due to real fake weakrefs

Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
2022-02-11 10:30:11 +00:00

48 lines
1.6 KiB
Plaintext

/datum/ai_controller/haunted
movement_delay = 0.4 SECONDS
blackboard = list(
BB_TO_HAUNT_LIST = list(),
BB_LIKES_EQUIPPER = FALSE,
BB_HAUNT_TARGET,
BB_HAUNTED_THROW_ATTEMPT_COUNT,
)
planning_subtrees = list(/datum/ai_planning_subtree/haunted)
idle_behavior = /datum/idle_behavior/idle_ghost_item
/datum/ai_controller/haunted/TryPossessPawn(atom/new_pawn)
if(!isitem(new_pawn))
return AI_CONTROLLER_INCOMPATIBLE
RegisterSignal(new_pawn, COMSIG_ITEM_EQUIPPED, .proc/on_equip)
return ..() //Run parent at end
/datum/ai_controller/haunted/UnpossessPawn()
UnregisterSignal(pawn, COMSIG_ITEM_EQUIPPED)
return ..() //Run parent at end
///Signal response for when the item is picked up; stops listening for follow up equips, just waits for a drop.
/datum/ai_controller/haunted/proc/on_equip(datum/source, mob/equipper, slot)
SIGNAL_HANDLER
UnregisterSignal(pawn, COMSIG_ITEM_EQUIPPED)
var/haunt_equipper = TRUE
if(isliving(equipper))
var/mob/living/possibly_cool = equipper
if(possibly_cool.mob_biotypes & MOB_UNDEAD)
haunt_equipper = FALSE
if(haunt_equipper)
//You have now become one of the victims of the HAAAAUNTTIIIINNGGG OOOOOO~~~
blackboard[BB_TO_HAUNT_LIST][WEAKREF(equipper)] += HAUNTED_ITEM_AGGRO_ADDITION
else
blackboard[BB_LIKES_EQUIPPER] = TRUE
RegisterSignal(pawn, COMSIG_ITEM_DROPPED, .proc/on_dropped)
///Flip it so we listen for equip again but not for drop.
/datum/ai_controller/haunted/proc/on_dropped(datum/source, mob/user)
SIGNAL_HANDLER
RegisterSignal(pawn, COMSIG_ITEM_EQUIPPED, .proc/on_equip)
blackboard[BB_LIKES_EQUIPPER] = FALSE
UnregisterSignal(pawn, COMSIG_ITEM_DROPPED)