From e8d64fa92f933b854a65316f83f77aa6448b6db4 Mon Sep 17 00:00:00 2001 From: CHOMPStation2 <58959929+CHOMPStation2@users.noreply.github.com> Date: Sat, 29 Jul 2023 23:23:58 -0700 Subject: [PATCH] [MIRROR] Adds means for staff to initialize new mob ai or modify existing ai type (#6676) Co-authored-by: Heroman3003 <31296024+Heroman3003@users.noreply.github.com> Co-authored-by: CHOMPStation2 --- code/modules/admin/view_variables/helpers.dm | 1 + code/modules/admin/view_variables/topic.dm | 23 +++++++++++++++++++ code/modules/ai/ai_holder.dm | 24 +++++++++++++++----- 3 files changed, 42 insertions(+), 6 deletions(-) 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 diff --git a/code/modules/ai/ai_holder.dm b/code/modules/ai/ai_holder.dm index 20cbf4ad6d..9813fe0b7c 100644 --- a/code/modules/ai/ai_holder.dm +++ b/code/modules/ai/ai_holder.dm @@ -15,12 +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() - 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) + if(!ai_holder) + initialize_ai_holder() return ..() /mob/living/Destroy() @@ -37,6 +33,22 @@ 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) //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) + 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.