diff --git a/code/modules/overmap/sectors.dm b/code/modules/overmap/sectors.dm index 5ec8358037c..21456cb7cc2 100644 --- a/code/modules/overmap/sectors.dm +++ b/code/modules/overmap/sectors.dm @@ -49,6 +49,12 @@ LAZYADD(SSshuttles.sectors_to_initialize, src) //Queued for further init. Will populate the waypoint lists; waypoints not spawned yet will be added in as they spawn. SSshuttles.process_init_queues() +// You generally shouldn't destroy these. +/obj/effect/overmap/visitable/Destroy() + testing("Deleting [src] overmap sector at [x],[y]") + unregister_z_levels() + return ..() + //This is called later in the init order by SSshuttles to populate sector objects. Importantly for subtypes, shuttles will be created by then. /obj/effect/overmap/visitable/proc/populate_sector_objects() @@ -78,6 +84,19 @@ global.using_map.map_levels |= map_z */ +/obj/effect/overmap/visitable/proc/unregister_z_levels() + map_sectors -= map_z + + global.using_map.player_levels -= map_z + if(!in_space) + global.using_map.sealed_levels -= map_z + /* VOREStation Removal - We have a map system that does this already. + if(base) + global.using_map.station_levels -= map_z + global.using_map.contact_levels -= map_z + global.using_map.map_levels -= map_z + */ + /obj/effect/overmap/visitable/proc/get_space_zlevels() if(in_space) return map_z @@ -117,6 +136,9 @@ /obj/effect/overmap/visitable/proc/generate_skybox() return +/obj/effect/overmap/visitable/proc/cleanup() + return FALSE + /obj/effect/overmap/visitable/MouseEntered(location, control, params) openToolTip(user = usr, tip_src = src, params = params, title = name) diff --git a/code/modules/overmap/spacetravel.dm b/code/modules/overmap/spacetravel.dm index f3efcd3fc48..473fcc1ab59 100644 --- a/code/modules/overmap/spacetravel.dm +++ b/code/modules/overmap/spacetravel.dm @@ -1,24 +1,24 @@ -//list used to cache empty zlevels to avoid nedless map bloat -var/list/cached_space = list() - //Space stragglers go here - /obj/effect/overmap/visitable/sector/temporary name = "Deep Space" invisibility = 101 known = 0 + in_space = TRUE -/obj/effect/overmap/visitable/sector/temporary/New(var/nx, var/ny, var/nz) +/obj/effect/overmap/visitable/sector/temporary/New(var/nx, var/ny) loc = locate(nx, ny, global.using_map.overmap_z) x = nx y = ny - map_z += nz - map_sectors["[nz]"] = src - testing("Temporary sector at [x],[y] was created, corresponding zlevel is [nz].") + 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].") /obj/effect/overmap/visitable/sector/temporary/Destroy() - map_sectors["[map_z]"] = null - testing("Temporary sector at [x],[y] was deleted.") + for(var/zlevel in map_z) + using_map.cache_empty_zlevel(zlevel) + testing("Temporary sector at [x],[y] was destroyed, returning empty zlevel [map_z[1]] to map datum.") + return ..() /obj/effect/overmap/visitable/sector/temporary/proc/can_die(var/mob/observer) testing("Checking if sector at [map_z[1]] can die.") @@ -28,6 +28,10 @@ var/list/cached_space = list() return 0 return 1 +/obj/effect/overmap/visitable/sector/temporary/cleanup() + if(can_die()) + qdel(src) + proc/get_deepspace(x,y) var/turf/unsimulated/map/overmap_turf = locate(x,y,global.using_map.overmap_z) if(!istype(overmap_turf)) @@ -35,13 +39,7 @@ proc/get_deepspace(x,y) var/obj/effect/overmap/visitable/sector/temporary/res = locate() in overmap_turf if(istype(res)) return res - else if(cached_space.len) - res = cached_space[cached_space.len] - cached_space -= res - res.forceMove(overmap_turf) - return res - else - return new /obj/effect/overmap/visitable/sector/temporary(x, y, global.using_map.get_empty_zlevel()) + return new /obj/effect/overmap/visitable/sector/temporary(x, y) /atom/movable/proc/lost_in_space() for(var/atom/movable/AM in contents) @@ -139,9 +137,4 @@ proc/overmap_spacetravel(var/turf/space/T, var/atom/movable/A) if(D.pulling) D.pulling.forceMove(dest) - if(istype(M, /obj/effect/overmap/visitable/sector/temporary)) - var/obj/effect/overmap/visitable/sector/temporary/source = M - if (source.can_die()) - testing("Caching [M] for future use") - source.moveToNullspace() - cached_space += source + M.cleanup() diff --git a/maps/~map_system/maps.dm b/maps/~map_system/maps.dm index 6ea94de079e..007e638593b 100644 --- a/maps/~map_system/maps.dm +++ b/maps/~map_system/maps.dm @@ -34,7 +34,7 @@ var/list/all_maps = list() var/static/list/sealed_levels = list() // Z-levels that don't allow random transit at edge var/static/list/xenoarch_exempt_levels = list() //Z-levels exempt from xenoarch finds and digsites spawning. var/static/list/persist_levels = list() // Z-levels where SSpersistence should persist between rounds. Defaults to station_levels if unset. - var/static/list/empty_levels = null // Empty Z-levels that may be used for various things (currently used by bluespace jump) + var/static/list/empty_levels = list() // Empty Z-levels that may be used for various things var/static/list/mappable_levels = list()// List of levels where mapping or other similar devices might work fully // End Static Lists @@ -201,10 +201,13 @@ var/list/all_maps = list() return text2num(pickweight(candidates)) /datum/map/proc/get_empty_zlevel() - if(empty_levels == null) + if(!empty_levels.len) world.increment_max_z() - empty_levels = list(world.maxz) - return pick(empty_levels) + empty_levels += world.maxz + return pick_n_take(empty_levels) + +/datum/map/proc/cache_empty_zlevel(var/z) + 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.