Skip to content

Commit

Permalink
ghosts can no longer duplicate themselves in the mob subsystem list t…
Browse files Browse the repository at this point in the history
…racking them (shiptest-ss13#3361)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## 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!
<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

## Why It's Good For The Game
This is bad!

<!-- Please add a short description of why you think these changes would
benefit the game. If you can't justify it in words, it might not be
worth adding. -->

## Changelog

:cl:
fix: ghosts cannot duplicate themselves across multiple z levels.
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->
  • Loading branch information
FalloutFalcon authored and MrCat15352 committed Dec 27, 2024
1 parent f5ad084 commit b1a9ec5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 25 deletions.
1 change: 1 addition & 0 deletions code/controllers/subsystem/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions code/game/machinery/navbeacon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions code/modules/mob/dead/dead.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
. = ..()
Expand Down
5 changes: 3 additions & 2 deletions code/modules/mob/living/login.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions code/modules/mob/living/simple_animal/simple_animal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
. = ..()
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b1a9ec5

Please sign in to comment.