From 7f5d9d7e09d553af09bf7f3781b0d09084273d46 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:48:27 -0700 Subject: [PATCH] Tick checks unplanned controllers (#87506) Shakes fist at random overtime --- code/_globalvars/lists/basic_ai.dm | 2 +- .../subsystem/unplanned_controllers.dm | 25 ++++++++++++++++--- code/datums/ai/_ai_controller.dm | 3 +++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/code/_globalvars/lists/basic_ai.dm b/code/_globalvars/lists/basic_ai.dm index a8646bb8d7f92..561d874c4e915 100644 --- a/code/_globalvars/lists/basic_ai.dm +++ b/code/_globalvars/lists/basic_ai.dm @@ -12,7 +12,7 @@ GLOBAL_LIST_INIT(ai_controllers_by_status, list( GLOBAL_LIST_EMPTY(ai_controllers_by_zlevel) ///basic ai controllers that are currently performing idled behaviors -GLOBAL_LIST_INIT(unplanned_controllers, list( +GLOBAL_LIST_INIT_TYPED(unplanned_controllers, /list/datum/ai_controller, list( AI_STATUS_ON = list(), AI_STATUS_IDLE = list(), )) diff --git a/code/controllers/subsystem/unplanned_controllers.dm b/code/controllers/subsystem/unplanned_controllers.dm index 3fb5f46dd069d..57b4ed68f169b 100644 --- a/code/controllers/subsystem/unplanned_controllers.dm +++ b/code/controllers/subsystem/unplanned_controllers.dm @@ -1,18 +1,37 @@ +GLOBAL_LIST_EMPTY(unplanned_controller_subsystems) /// Handles making mobs perform lightweight "idle" behaviors such as wandering around when they have nothing planned SUBSYSTEM_DEF(unplanned_controllers) name = "Unplanned AI Controllers" - flags = SS_POST_FIRE_TIMING|SS_BACKGROUND|SS_NO_INIT + flags = SS_POST_FIRE_TIMING|SS_BACKGROUND priority = FIRE_PRIORITY_UNPLANNED_NPC init_order = INIT_ORDER_AI_CONTROLLERS wait = 0.25 SECONDS runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME ///what ai status are we interested in var/target_status = AI_STATUS_ON + var/list/current_run = list() + +/datum/controller/subsystem/unplanned_controllers/Initialize() + ..() + GLOB.unplanned_controller_subsystems += src + return SS_INIT_SUCCESS + +/datum/controller/subsystem/unplanned_controllers/Destroy() + GLOB.unplanned_controller_subsystems -= src + return ..() /datum/controller/subsystem/unplanned_controllers/stat_entry(msg) msg = "Planning AIs:[length(GLOB.unplanned_controllers[target_status])]" return ..() /datum/controller/subsystem/unplanned_controllers/fire(resumed) - for(var/datum/ai_controller/ai_controller as anything in GLOB.unplanned_controllers[target_status]) - ai_controller.idle_behavior.perform_idle_behavior(wait * 0.1, ai_controller) + if(!resumed) + src.current_run = GLOB.unplanned_controllers[target_status].Copy() + var/list/current_run = src.current_run // cache for sonic speed + while(length(current_run)) + var/datum/ai_controller/unplanned = current_run[current_run.len] + current_run.len-- + if(!QDELETED(unplanned)) + unplanned.idle_behavior.perform_idle_behavior(wait * 0.1, unplanned) + if (MC_TICK_CHECK) + return diff --git a/code/datums/ai/_ai_controller.dm b/code/datums/ai/_ai_controller.dm index 07e3851a1aeab..b8bd03d7cc501 100644 --- a/code/datums/ai/_ai_controller.dm +++ b/code/datums/ai/_ai_controller.dm @@ -466,6 +466,9 @@ multiple modular subtrees with behaviors if(isnull(ai_status) || ai_status == AI_STATUS_OFF) return GLOB.unplanned_controllers[ai_status] -= src + for(var/datum/controller/subsystem/unplanned_controllers/potential_holder as anything in GLOB.unplanned_controller_subsystems) + if(potential_holder.target_status == ai_status) + potential_holder.current_run -= src /datum/ai_controller/proc/modify_cooldown(datum/ai_behavior/behavior, new_cooldown) behavior_cooldowns[behavior] = new_cooldown