From c2a367e278bc7942d141e28cd28f08b9f35ed410 Mon Sep 17 00:00:00 2001 From: Atermonera Date: Sun, 31 Oct 2021 12:09:13 -0800 Subject: [PATCH] Fixes temp sector initialization --- code/modules/overmap/spacetravel.dm | 28 +++++++++++++++++++++++++++- maps/~map_system/maps.dm | 10 +++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/code/modules/overmap/spacetravel.dm b/code/modules/overmap/spacetravel.dm index ae1bca7335..386d3be0b6 100644 --- a/code/modules/overmap/spacetravel.dm +++ b/code/modules/overmap/spacetravel.dm @@ -14,7 +14,19 @@ // But pick an empty z level to use map_z += global.using_map.get_empty_zlevel() . = ..() +<<<<<<< HEAD testing("Temporary sector at [x],[y],[z] was created, corresponding zlevel is [english_list(map_z)].") +======= + loc = locate(nx, ny, global.using_map.overmap_z) + x = nx + y = ny + 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]].") +>>>>>>> 51f5290fa1a... Fixes temp sector initialization (#8325) /obj/effect/overmap/visitable/sector/temporary/Destroy() for(var/zlevel in map_z) @@ -22,6 +34,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"]`") @@ -44,7 +59,14 @@ var/obj/effect/overmap/visitable/sector/temporary/res = locate() in overmap_turf if(istype(res)) return res +<<<<<<< HEAD return new /obj/effect/overmap/visitable/sector/temporary(overmap_turf) +======= + res = new /obj/effect/overmap/visitable/sector/temporary(x, y) + if(QDELETED(res)) + res = null + return res +>>>>>>> 51f5290fa1a... Fixes temp sector initialization (#8325) /atom/movable/proc/lost_in_space() for(var/atom/movable/AM in contents) @@ -130,8 +152,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()) testing("spacetravel chose [nz],[ny],[nz] in sector [TM] @ ([TM.x],[TM.y],[TM.z])") @@ -143,5 +167,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() diff --git a/maps/~map_system/maps.dm b/maps/~map_system/maps.dm index 48a8963e36..9fc0487392 100644 --- a/maps/~map_system/maps.dm +++ b/maps/~map_system/maps.dm @@ -205,13 +205,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.