Skip to content

Commit

Permalink
[MIRROR] Fixes runtime in z level update (#2224) (#3098)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: John Willard <[email protected]>
  • Loading branch information
3 people authored Apr 29, 2024
1 parent e895411 commit 656f6db
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
..()
Expand Down

0 comments on commit 656f6db

Please sign in to comment.