Fixes temp sector initialization (#8325)

* Fixes temp sector initialization

* More aggressively free temp sectors, tweaks

* lazyadd list init
This commit is contained in:
Atermonera
2022-01-04 18:46:33 -08:00
committed by atermonera
parent a2ba682ac8
commit 2efe5343db
2 changed files with 27 additions and 7 deletions
+18 -6
View File
@@ -10,10 +10,12 @@
loc = locate(nx, ny, global.using_map.overmap_z)
x = nx
y = ny
var/emptyz = global.using_map.get_empty_zlevel()
map_z += emptyz
map_sectors["[emptyz]"] = src
testing("Temporary sector at [x],[y] was created, corresponding zlevel is [emptyz].")
if(!map_z[1])
log_and_message_admins("Could not create empty sector at [nx], [ny]. No available z levels to allocate.")
return INITIALIZE_HINT_QDEL
map_sectors["[map_z[1]]"] = src
testing("Temporary sector at [x],[y] was created, corresponding zlevel is [map_z[1]].")
/obj/effect/overmap/visitable/sector/temporary/Destroy()
for(var/zlevel in map_z)
@@ -21,6 +23,9 @@
testing("Temporary sector at [x],[y] was destroyed, returning empty zlevel [map_z[1]] to map datum.")
return ..()
/obj/effect/overmap/visitable/sector/temporary/find_z_levels()
LAZYADD(map_z, global.using_map.get_empty_zlevel())
/obj/effect/overmap/visitable/sector/temporary/proc/is_empty(var/mob/observer)
if(!LAZYLEN(map_z))
log_and_message_admins("CANARY: [src] tried to check is_empty, but map_z is `[map_z || "null"]`")
@@ -43,7 +48,10 @@
var/obj/effect/overmap/visitable/sector/temporary/res = locate() in overmap_turf
if(istype(res))
return res
return new /obj/effect/overmap/visitable/sector/temporary(x, y)
res = new /obj/effect/overmap/visitable/sector/temporary(x, y)
if(QDELETED(res))
res = null
return res
/atom/movable/proc/lost_in_space()
for(var/atom/movable/AM in contents)
@@ -128,8 +136,10 @@
if(O != M && O.in_space && prob(50))
TM = O
break
if(!TM)
if(!istype(TM))
TM = get_deepspace(M.x,M.y)
if(!istype(TM))
return
nz = pick(TM.get_space_zlevels())
var/turf/dest = locate(nx,ny,nz)
@@ -139,5 +149,7 @@
var/mob/D = A
if(D.pulling)
D.pulling.forceMove(dest)
else
to_world("CANARY: Could not move [A] to [nx], [ny], [nz]: [dest ? "[dest]" : "null"]")
M.cleanup()
+9 -1
View File
@@ -183,13 +183,21 @@ var/list/all_maps = list()
return text2num(pickweight(candidates))
/datum/map/proc/get_empty_zlevel()
// Try to free up a z level from existing temp sectors
if(!empty_levels.len)
for(var/Z in map_sectors)
var/obj/effect/overmap/visitable/sector/temporary/T = map_sectors[Z]
T.cleanup() // If we can release some of these, do that.
// Else, we need to buy a new one.
if(!empty_levels.len)
world.increment_max_z()
empty_levels += world.maxz
return pick_n_take(empty_levels)
/datum/map/proc/cache_empty_zlevel(var/z)
empty_levels |= z
if(z) // Else, it's not a valid z and we want to expunge it
empty_levels |= z
// Get a list of 'nearby' or 'connected' zlevels.
// You should at least return a list with the given z if nothing else.