tweak: Implements requested changes to ai init

- In mob/living init, makes sure there is no pre-existing ai_holder before calling its init
- In the initialize_ai_holder, double checks if we got a pre-existing ai_holder and properly GCs it if so
- Furthermore, checks if the ai_holder_type was valid by checking if ai_holder is null, if so - logs a debug message and returns.
This commit is contained in:
Runa Dacino
2023-07-29 14:18:05 +02:00
committed by GitHub
parent 5c02c5a60a
commit 79715765d0
+9 -1
View File
@@ -15,7 +15,8 @@
var/ai_holder_type = null // Which ai_holder datum to give to the mob when initialized. If null, nothing happens.
/mob/living/Initialize()
initialize_ai_holder()
if(!ai_holder)
initialize_ai_holder()
return ..()
/mob/living/Destroy()
@@ -34,8 +35,15 @@
//Extracted from mob/living/Initialize() so that we may call it at any time after a mob was created
/mob/living/proc/initialize_ai_holder()
if(ai_holder) //Making double sure we clean up and properly GC the original ai_holder
var/old_holder = ai_holder
ai_holder = null
qdel(old_holder)
if(ai_holder_type)
ai_holder = new ai_holder_type(src)
if(!ai_holder)
log_debug("[src] could not initialize ai_holder of type [ai_holder_type]")
return
if(istype(src, /mob/living/carbon/human))
var/mob/living/carbon/human/H = src
H.hud_used = new /datum/hud(H)