From 2a9642940a5a8d50e0d40780db02235dce341779 Mon Sep 17 00:00:00 2001 From: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Date: Tue, 15 Oct 2024 06:12:31 -0500 Subject: [PATCH] ghosts can no longer duplicate themselves in the mob subsystem list tracking them (#3361) ## About The Pull Request we have areas with a virtual z level of 0 which means if you traveled into it, you wouldnt get cleaned up from your old z level! you could then walk back into it and be added to that z level a second time idle mobs cant be added to 0 either! ## Why It's Good For The Game This is bad! ## Changelog :cl: fix: ghosts cannot duplicate themselves across multiple z levels. /:cl: --- code/controllers/subsystem/mobs.dm | 1 + code/game/atoms_movable.dm | 2 +- code/game/machinery/navbeacon.dm | 11 ++++++-- code/modules/mob/dead/dead.dm | 11 ++++---- code/modules/mob/living/login.dm | 5 ++-- .../mob/living/simple_animal/simple_animal.dm | 26 +++++++++---------- .../chemistry/reagents/trickwine_reagents.dm | 2 +- 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/code/controllers/subsystem/mobs.dm b/code/controllers/subsystem/mobs.dm index b5d8210c802f..d2e0505b3583 100644 --- a/code/controllers/subsystem/mobs.dm +++ b/code/controllers/subsystem/mobs.dm @@ -40,5 +40,6 @@ SUBSYSTEM_DEF(mobs) L.Life(seconds, times_fired) else GLOB.mob_living_list.Remove(L) + stack_trace("[L] no longer exists in mob_living_list") if (MC_TICK_CHECK) return diff --git a/code/game/atoms_movable.dm b/code/game/atoms_movable.dm index 79326ab9e2ad..7a1f7a36283a 100644 --- a/code/game/atoms_movable.dm +++ b/code/game/atoms_movable.dm @@ -540,7 +540,7 @@ var/previous_virtual_z = OldLoc?.virtual_z() || 0 var/current_virtual_z = virtual_z() - if(current_virtual_z && current_virtual_z != previous_virtual_z) + if(current_virtual_z != previous_virtual_z) on_virtual_z_change(current_virtual_z, previous_virtual_z) SEND_SIGNAL(src, COMSIG_MOVABLE_MOVED, OldLoc, Dir, Forced, old_locs) diff --git a/code/game/machinery/navbeacon.dm b/code/game/machinery/navbeacon.dm index b54c192f4407..abee7fe954f7 100644 --- a/code/game/machinery/navbeacon.dm +++ b/code/game/machinery/navbeacon.dm @@ -46,11 +46,15 @@ return ..() /obj/machinery/navbeacon/on_virtual_z_change(new_virtual_z, previous_virtual_z) + ..() + if(!codes) + return + if(!codes["patrol"]) + return if(previous_virtual_z) LAZYREMOVEASSOC(GLOB.navbeacons, "[previous_virtual_z]", src) if(new_virtual_z) LAZYADDASSOCLIST(GLOB.navbeacons, "[new_virtual_z]", src) - ..() // set the transponder codes assoc list from codes_txt /obj/machinery/navbeacon/proc/set_codes() @@ -71,7 +75,10 @@ codes[e] = "1" /obj/machinery/navbeacon/proc/glob_lists_deregister() - LAZYREMOVE(GLOB.navbeacons["[virtual_z()]"], src) + if(!codes) + return + if(codes["patrol"]) + LAZYREMOVE(GLOB.navbeacons["[virtual_z()]"], src) GLOB.deliverybeacons -= src GLOB.deliverybeacontags -= location GLOB.wayfindingbeacons -= src diff --git a/code/modules/mob/dead/dead.dm b/code/modules/mob/dead/dead.dm index 85c60a15b031..490efbbabef8 100644 --- a/code/modules/mob/dead/dead.dm +++ b/code/modules/mob/dead/dead.dm @@ -96,18 +96,17 @@ INITIALIZE_IMMEDIATE(/mob/dead) return /mob/dead/Destroy() - for(var/level in SSmobs.dead_players_by_virtual_z) - LAZYREMOVEASSOC(SSmobs.dead_players_by_virtual_z, level, src) - // Forgive me for this one. This loop can be replaced by the line below by the one brave enough to fix - // observers not cleanly removing themselves from the dead_players_by_virtual_z /list when they should - //LAZYREMOVEASSOC(SSmobs.dead_players_by_virtual_z, "[virtual_z()]", src) + //Observers should no longer be duplicating themselves across virtual z so it SHOULD be fine to only check its virtual z. + LAZYREMOVEASSOC(SSmobs.dead_players_by_virtual_z, "[virtual_z()]", src) return ..() /mob/dead/Login() . = ..() if(!client) return - LAZYADDASSOCLIST(SSmobs.dead_players_by_virtual_z, "[virtual_z()]", src) + var/virt_z = virtual_z() + if(virt_z) + LAZYADDASSOCLIST(SSmobs.dead_players_by_virtual_z, "[virt_z]", src) /mob/dead/Logout() . = ..() diff --git a/code/modules/mob/living/login.dm b/code/modules/mob/living/login.dm index 62098a940937..18ddbe375da9 100644 --- a/code/modules/mob/living/login.dm +++ b/code/modules/mob/living/login.dm @@ -18,8 +18,9 @@ var/virtual_z = virtual_z() - LAZYADDASSOCLIST(SSmobs.players_by_virtual_z, "[virtual_z]", src) - SSidlenpcpool.try_wakeup_virtual_z(virtual_z) + if(virtual_z) + LAZYADDASSOCLIST(SSmobs.players_by_virtual_z, "[virtual_z]", src) + SSidlenpcpool.try_wakeup_virtual_z(virtual_z) //Vents if(ventcrawler) diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index 3670e14a6405..55ea24c81d7d 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -630,30 +630,29 @@ GLOB.simple_animals[togglestatus] += list(src) AIStatus = togglestatus - var/virt_z = "[virtual_z()]" + var/virt_z = virtual_z() if(!virt_z) return switch(togglestatus) if(AI_Z_OFF) - LAZYADDASSOCLIST(SSidlenpcpool.idle_mobs_by_virtual_level, virt_z, src) - + LAZYADDASSOCLIST(SSidlenpcpool.idle_mobs_by_virtual_level, "[virt_z]", src) else - LAZYREMOVEASSOC(SSidlenpcpool.idle_mobs_by_virtual_level, virt_z, src) + LAZYREMOVEASSOC(SSidlenpcpool.idle_mobs_by_virtual_level, "[virt_z]", src) /mob/living/simple_animal/proc/check_should_sleep() if (pulledby || shouldwakeup) toggle_ai(AI_ON) return - var/virt_z = "[virtual_z()]" - if(!virt_z) - return - var/players_on_virtual_z = LAZYACCESS(SSmobs.players_by_virtual_z, virt_z) - if(!length(players_on_virtual_z)) - toggle_ai(AI_Z_OFF) - else if(AIStatus == AI_Z_OFF) - toggle_ai(AI_ON) + var/virt_z = virtual_z() + var/players_on_virtual_z = 0 + if(virt_z) + players_on_virtual_z = LAZYACCESS(SSmobs.players_by_virtual_z, "[virt_z]") + if(!length(players_on_virtual_z)) + toggle_ai(AI_Z_OFF) + else if(AIStatus == AI_Z_OFF) + toggle_ai(AI_ON) /mob/living/simple_animal/adjustHealth(amount, updating_health = TRUE, forced = FALSE) . = ..() @@ -665,6 +664,7 @@ . = ..() if(previous_virtual_z) LAZYREMOVEASSOC(SSidlenpcpool.idle_mobs_by_virtual_level, "[previous_virtual_z]", src) - toggle_ai(initial(AIStatus)) + if(QDELETED(src)) + return if(new_virtual_z) check_should_sleep() diff --git a/code/modules/reagents/chemistry/reagents/trickwine_reagents.dm b/code/modules/reagents/chemistry/reagents/trickwine_reagents.dm index ff82cd185fb2..eea549fb7475 100644 --- a/code/modules/reagents/chemistry/reagents/trickwine_reagents.dm +++ b/code/modules/reagents/chemistry/reagents/trickwine_reagents.dm @@ -30,7 +30,7 @@ if(!iscarbon(M)) var/mob/living/simple_animal/hostile/hostile_target = M var/hostile_ai_status = hostile_target.AIStatus - hostile_target.AIStatus = AI_OFF + hostile_target.toggle_ai(AI_OFF) addtimer(VARSET_CALLBACK(hostile_target, AIStatus, hostile_ai_status),reac_volume) M.Jitter(3 * reac_volume) M.Dizzy(2 * reac_volume)