From 656f6db4669fa1104d087c421e7a8b246a1572bf Mon Sep 17 00:00:00 2001 From: Iajret Creature <122297233+Steals-The-PRs@users.noreply.github.com> Date: Mon, 29 Apr 2024 07:17:20 +0300 Subject: [PATCH] [MIRROR] Fixes runtime in z level update (#2224) (#3098) * Fixes runtime in z level update (#82898) ## About The Pull Request re-adds the check that they are actually being moved to a new z level in the update z level proc so it doesn't check null z level for cliented mobs and ai controllers. ## Why It's Good For The Game Saw this runtime on moth.fans and thought i should fix it. ## Changelog Nothing player-facing. * Fixes runtime in z level update --------- Co-authored-by: NovaBot <154629622+NovaBot13@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> --- code/modules/mob/living/living.dm | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 78ee0bd5b28..6c4a6a0583f 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -1855,25 +1855,27 @@ GLOBAL_LIST_EMPTY(fire_appearances) return //Check the amount of clients exists on the Z level we're leaving from, - //this excludes us as we haven't added ourselves to the new z level yet. + //this excludes us because at this point we are not registered to any z level. var/old_level_new_clients = (registered_z ? SSmobs.clients_by_zlevel[registered_z].len : null) //No one is left after we're gone, shut off inactive ones if(registered_z && old_level_new_clients == 0) for(var/datum/ai_controller/controller as anything in SSai_controllers.ai_controllers_by_zlevel[registered_z]) controller.set_ai_status(AI_STATUS_OFF) - //Check the amount of clients exists on the Z level we're moving towards, excluding ourselves. - var/new_level_old_clients = SSmobs.clients_by_zlevel[new_z].len + if(new_z) + //Check the amount of clients exists on the Z level we're moving towards, excluding ourselves. + var/new_level_old_clients = SSmobs.clients_by_zlevel[new_z].len + + //We'll add ourselves to the list now so get_expected_ai_status() will know we're on the z level. + SSmobs.clients_by_zlevel[new_z] += src + + if(new_level_old_clients == 0) //No one was here before, wake up all the AIs. + for (var/datum/ai_controller/controller as anything in SSai_controllers.ai_controllers_by_zlevel[new_z]) + //We don't set them directly on, for instances like AIs acting while dead and other cases that may exist in the future. + //This isn't a problem for AIs with a client since the client will prevent this from being called anyway. + controller.set_ai_status(controller.get_expected_ai_status()) registered_z = new_z - //We'll add ourselves to the list now so get_expected_ai_status() will know we're on the z level. - SSmobs.clients_by_zlevel[registered_z] += src - - if(new_level_old_clients == 0) //No one was here before, wake up all the AIs. - for (var/datum/ai_controller/controller as anything in SSai_controllers.ai_controllers_by_zlevel[new_z]) - //We don't set them directly on, for instances like AIs acting while dead and other cases that may exist in the future. - //This isn't a problem for AIs with a client since the client will prevent this from being called anyway. - controller.set_ai_status(controller.get_expected_ai_status()) /mob/living/on_changed_z_level(turf/old_turf, turf/new_turf, same_z_layer, notify_contents) ..()