From 39a06b30132bd519e8d0169c7b635036f6d8004d Mon Sep 17 00:00:00 2001 From: Runa Dacino Date: Fri, 28 Jul 2023 21:28:18 +0200 Subject: [PATCH 1/3] tweak: Moves ai_holder init into its own proc Moves the logic for initializing an ai_holder from mob/living/Initialize() into its own proc, replacing the original code with a call of this proc. Functionally, nothing has been changed. However, this enables ai reinitialization for gms --- code/modules/ai/ai_holder.dm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/code/modules/ai/ai_holder.dm b/code/modules/ai/ai_holder.dm index 307d3870b2..347fff2b5c 100644 --- a/code/modules/ai/ai_holder.dm +++ b/code/modules/ai/ai_holder.dm @@ -15,12 +15,7 @@ var/ai_holder_type = null // Which ai_holder datum to give to the mob when initialized. If null, nothing happens. /mob/living/Initialize() - if(ai_holder_type) - ai_holder = new ai_holder_type(src) - if(istype(src, /mob/living/carbon/human)) - var/mob/living/carbon/human/H = src - H.hud_used = new /datum/hud(H) - H.create_mob_hud(H.hud_used) + initialize_ai_holder() return ..() /mob/living/Destroy() @@ -37,6 +32,15 @@ ai_holder.manage_processing(AI_PROCESSING) return ..() +//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_type) + ai_holder = new ai_holder_type(src) + if(istype(src, /mob/living/carbon/human)) + var/mob/living/carbon/human/H = src + H.hud_used = new /datum/hud(H) + H.create_mob_hud(H.hud_used) + /datum/ai_holder var/mob/living/holder = null // The mob this datum is going to control. var/stance = STANCE_IDLE // Determines if the mob should be doing a specific thing, e.g. attacking, following, standing around, etc. From 5c02c5a60a8a3841217110430ad56598e543eb85 Mon Sep 17 00:00:00 2001 From: Runa Dacino Date: Fri, 28 Jul 2023 21:30:01 +0200 Subject: [PATCH 2/3] Adds: New button in VV dropdown for adding/modifying mob ai Adds a new button to the dropdown of "View Variables" for mobs that works for subtypes of mob/living. This new button automates setting a new ai type for a mob, making sure it's properly garbage collected and then simplifies setting faction, intent and ensures carbon mobs wake up. --- code/modules/admin/view_variables/helpers.dm | 1 + code/modules/admin/view_variables/topic.dm | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/code/modules/admin/view_variables/helpers.dm b/code/modules/admin/view_variables/helpers.dm index bad05eb138..594689dd6c 100644 --- a/code/modules/admin/view_variables/helpers.dm +++ b/code/modules/admin/view_variables/helpers.dm @@ -48,6 +48,7 @@ + diff --git a/code/modules/admin/view_variables/topic.dm b/code/modules/admin/view_variables/topic.dm index 6554626777..2eb09daa24 100644 --- a/code/modules/admin/view_variables/topic.dm +++ b/code/modules/admin/view_variables/topic.dm @@ -157,6 +157,29 @@ if(usr.client) usr.client.cmd_assume_direct_control(M) + else if(href_list["give_ai"]) + if(!check_rights(0)) return + + var/mob/M = locate(href_list["give_ai"]) + if(!istype(M, /mob/living)) + to_chat(usr, span_notice("This can only be used on instances of type /mob/living")) + return + var/mob/living/L = M + if(L.client || L.teleop) + to_chat(usr, span_warning("This cannot be used on player mobs!")) + return + + if(L.ai_holder) //Cleaning up the original ai + var/ai_holder_old = L.ai_holder + L.ai_holder = null + qdel(ai_holder_old) //Only way I could make #TESTING - Unable to be GC'd to stop. del() logs show it works. + L.ai_holder_type = tgui_input_list(usr, "Choose AI holder", "AI Type", typesof(/datum/ai_holder/)) + L.initialize_ai_holder() + L.faction = sanitize(tgui_input_text(usr, "Please input AI faction", "AI faction", "neutral")) + L.a_intent = tgui_input_list(usr, "Please choose AI intent", "AI intent", list(I_HURT, I_HELP)) + if(tgui_alert(usr, "Make mob wake up? This is needed for carbon mobs.", "Wake mob?", list("Yes", "No")) == "Yes") + L.AdjustSleeping(-100) + else if(href_list["make_skeleton"]) if(!check_rights(R_FUN)) return From 79715765d0d3ecdfb314baabbec236e44c557839 Mon Sep 17 00:00:00 2001 From: Runa Dacino Date: Sat, 29 Jul 2023 14:18:05 +0200 Subject: [PATCH 3/3] 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. --- code/modules/ai/ai_holder.dm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/modules/ai/ai_holder.dm b/code/modules/ai/ai_holder.dm index 347fff2b5c..731ff4de0f 100644 --- a/code/modules/ai/ai_holder.dm +++ b/code/modules/ai/ai_holder.dm @@ -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)