Added the z-level manager system from TG (#19532)

Added the z-level manager system from TG, mostly
This commit is contained in:
Fluffy
2024-07-22 13:00:38 +00:00
committed by GitHub
parent 0a9176841c
commit 1345beac4b
90 changed files with 614 additions and 245 deletions
+5 -34
View File
@@ -1,6 +1,3 @@
// If you add a more comprehensive system, just untick this file.
// Because this shit before was, for some reason, a bitfield.
GLOBAL_LIST_EMPTY(z_levels)
var/list/list/connected_z_cache = list()
// If the height is more than 1, we mark all contained levels as connected.
@@ -10,43 +7,16 @@ var/list/list/connected_z_cache = list()
return
if(_height)
height = _height
for(var/i = (loc.z - height + 1) to (loc.z-1))
if (GLOB.z_levels.len <i)
GLOB.z_levels.len = i
GLOB.z_levels[i] = TRUE
/obj/effect/landmark/map_data/Initialize()
..()
return INITIALIZE_HINT_QDEL
/proc/HasAbove(var/z)
if(z >= world.maxz || z < 1 || z > GLOB.z_levels.len)
return 0
return GLOB.z_levels[z]
/proc/HasBelow(var/z)
if(z > world.maxz || z < 2 || (z-1) > GLOB.z_levels.len)
return 0
return GLOB.z_levels[z-1]
// Thankfully, no bitwise magic is needed here.
/proc/GetAbove(var/atom/atom)
var/turf/turf = get_turf(atom)
if(!turf)
return null
return HasAbove(turf.z) ? get_step(turf, UP) : null
/proc/GetBelow(var/atom/atom)
var/turf/turf = get_turf(atom)
if(!turf)
return null
return HasBelow(turf.z) ? get_step(turf, DOWN) : null
/proc/GetConnectedZlevels(z)
. = list(z)
for(var/level = z, HasBelow(level), level--)
for(var/level = z, SSmapping.multiz_levels[level][Z_LEVEL_DOWN], level--)
. |= level-1
for(var/level = z, HasAbove(level), level++)
for(var/level = z, SSmapping.multiz_levels[level][Z_LEVEL_UP], level++)
. |= level+1
/proc/AreConnectedZLevels(var/zA, var/zB)
@@ -76,10 +46,11 @@ var/list/list/connected_z_cache = list()
CRASH("Expected atom.")
if (!ref.z)
ref = get_turf(ref)
var/turf/T = get_turf(ref)
switch (dir)
if (UP)
. = GET_ABOVE(ref)
. = GET_TURF_ABOVE(T)
if (DOWN)
. = GET_BELOW(ref)
. = GET_TURF_BELOW(T)
else
. = get_step(ref, dir)
-5
View File
@@ -3,8 +3,3 @@
return 0
/proc/HasBelow(var/z)
return 0
// These give either the turf or null.
/proc/GetAbove(var/turf/turf)
return null
/proc/GetBelow(var/turf/turf)
return null
+4 -2
View File
@@ -229,7 +229,8 @@
collapse_kit()
/obj/structure/hoist/proc/can_move_dir(direction)
var/turf/dest = direction == UP ? GetAbove(source_hook) : GetBelow(source_hook)
var/turf/T = get_turf(source_hook)
var/turf/dest = direction == UP ? GET_TURF_ABOVE(T) : GET_TURF_BELOW(T)
switch(direction)
if (UP)
if (!isopenturf(dest)) // can't move into a solid tile
@@ -247,7 +248,8 @@
/obj/structure/hoist/proc/move_dir(direction)
if (!can_move_dir(direction))
return FALSE
var/turf/move_dest = direction == UP ? GetAbove(source_hook) : GetBelow(source_hook)
var/turf/T = get_turf(source_hook)
var/turf/move_dest = direction == UP ? GET_TURF_ABOVE(T) : GET_TURF_BELOW(T)
source_hook.forceMove(move_dest)
if (hoistee)
hoistee.hoist_act(move_dest)
+4 -2
View File
@@ -13,7 +13,8 @@
/obj/item/ladder_mobile/proc/place_ladder(atom/A, mob/user)
if (isopenturf(A)) //Place into open space
var/turf/below_loc = GetBelow(A)
var/turf/T = get_turf(A)
var/turf/below_loc = GET_TURF_BELOW(T)
if (!below_loc || (istype(/turf/space, below_loc)))
to_chat(user, SPAN_NOTICE("Why would you do that?! There is only infinite space there..."))
return
@@ -32,7 +33,8 @@
qdel(src)
else if (istype(A, /turf/simulated/floor) || istype(A, /turf/unsimulated/floor)) //Place onto Floor
var/turf/upper_loc = GetAbove(A)
var/turf/T = get_turf(A)
var/turf/upper_loc = GET_TURF_ABOVE(T)
if (!upper_loc || !isopenturf(upper_loc))
to_chat(user, SPAN_NOTICE("There is something above. You can't deploy!"))
return
+8 -5
View File
@@ -40,7 +40,8 @@
to_chat(src, SPAN_WARNING("You lack means of travel in that direction."))
return FALSE
var/turf/destination = (direction == UP) ? GetAbove(src) : GetBelow(src)
var/turf/T = get_turf(src)
var/turf/destination = (direction == UP) ? GET_TURF_ABOVE(T) : GET_TURF_BELOW(T)
if(!destination)
to_chat(src, SPAN_NOTICE("There is nothing of interest in this direction."))
@@ -104,14 +105,16 @@
return ..()
/mob/abstract/eye/zMove(direction)
var/turf/destination = (direction == UP) ? GetAbove(src) : GetBelow(src)
var/turf/T = get_turf(src)
var/turf/destination = (direction == UP) ? GET_TURF_ABOVE(T) : GET_TURF_BELOW(T)
if(destination)
setLoc(destination)
else
to_chat(owner, SPAN_NOTICE("There is nothing of interest in this direction."))
/mob/abstract/observer/zMove(direction)
var/turf/destination = (direction == UP) ? GetAbove(src) : GetBelow(src)
var/turf/T = get_turf(src)
var/turf/destination = (direction == UP) ? GET_TURF_ABOVE(T) : GET_TURF_BELOW(T)
if(destination)
forceMove(destination)
else
@@ -151,9 +154,9 @@
/mob/living/carbon/human/proc/climb(var/direction, var/turf/source, var/climb_bonus)
var/turf/destination
if(direction == UP)
destination = GetAbove(source)
destination = GET_TURF_ABOVE(source)
else
destination = GetBelow(source)
destination = GET_TURF_BELOW(source)
if(!destination)
return
+4 -3
View File
@@ -167,7 +167,8 @@
node1 = target
break
var/turf/above = GetAbove(src)
var/turf/current_turf = get_turf(src)
var/turf/above = GET_TURF_ABOVE(current_turf)
if(above)
for(var/obj/machinery/atmospherics/target in above)
if(target.initialize_directions && istype(target, /obj/machinery/atmospherics/pipe/zpipe/down))
@@ -210,7 +211,8 @@
node1 = target
break
var/turf/below = GetBelow(src)
var/turf/T = get_turf(src)
var/turf/below = GET_TURF_BELOW(T)
if(below)
for(var/obj/machinery/atmospherics/target in below)
if(target.initialize_directions && istype(target, /obj/machinery/atmospherics/pipe/zpipe/up))
@@ -219,7 +221,6 @@
break
var/turf/T = src.loc // hide if turf is not intact
hide(!T.is_plating())
////////////////////////////////
+5 -3
View File
@@ -34,7 +34,8 @@
. = ..()
// the upper will connect to the lower
if(allowed_directions & DOWN) //we only want to do the top one, as it will initialize the ones before it.
for(var/obj/structure/ladder/L in GetBelow(src))
var/turf/T = get_turf(src)
for(var/obj/structure/ladder/L in GET_TURF_BELOW(T))
if(L.allowed_directions & UP)
target_down = L
L.target_up = src
@@ -237,7 +238,7 @@
/obj/structure/stairs/Initialize()
. = ..()
for(var/turf/turf in locs)
var/turf/simulated/open/above = GetAbove(turf)
var/turf/simulated/open/above = GET_TURF_ABOVE(turf)
if(!above)
log_asset("Stair created without z-level above: ([loc.x], [loc.y], [loc.z])")
return INITIALIZE_HINT_QDEL
@@ -264,7 +265,8 @@
var/atom/movable/AM = bumped_atom
// This is hackish but whatever.
var/turf/target = get_step(GetAbove(AM), dir)
var/turf/T = get_turf(AM)
var/turf/target = get_step(GET_TURF_ABOVE(T), dir)
if(!target)
return
if(target.z > (z + 1)) //Prevents wheelchair fuckery. Basically, you teleport twice because both the wheelchair + your mob collide with the stairs.
+7 -4
View File
@@ -181,7 +181,8 @@
* Updates the turf with open turf's variables and basically resets it properly.
*/
/turf/simulated/open/proc/update(mapload = FALSE)
below = GetBelow(src)
var/turf/T = get_turf(src)
below = GET_TURF_BELOW(T)
// Edge case for when an open turf is above space on the lowest level.
if (below)
@@ -211,7 +212,8 @@
. = ..()
if(distance <= 2)
var/depth = 1
for(var/T = GetBelow(src); isopenspace(T); T = GetBelow(T))
var/turf/current_turf = get_turf(src)
for(var/turf/T = GET_TURF_BELOW(current_turf); isopenspace(T); T = GET_TURF_BELOW(T))
depth += 1
. += "It is about [depth] level\s deep."
@@ -259,7 +261,8 @@
if(ishuman(user) && user.a_intent == I_GRAB)
var/mob/living/carbon/human/H = user
var/turf/climbing_wall = GetBelow(H)
var/turf/T = get_turf(H)
var/turf/climbing_wall = GET_TURF_BELOW(T)
var/climb_bonus = 0
if(istype(climbing_wall, /turf/simulated/mineral))
climb_bonus = 20
@@ -276,7 +279,7 @@
//Returns the roof type of the turf below
/turf/simulated/open/get_roof_type()
var/turf/t = GetBelow(src)
var/turf/t = GET_TURF_BELOW(src)
if(!t)
return null
return t.roof_type
+2 -2
View File
@@ -3,9 +3,9 @@
return
/turf/proc/is_above_space()
var/turf/T = GetBelow(src)
var/turf/T = GET_TURF_BELOW(src)
while (T && (T.z_flags & ZM_MIMIC_BELOW))
T = GetBelow(T)
T = GET_TURF_BELOW(T)
return isspaceturf(T)
/turf/update_icon()
+1 -1
View File
@@ -54,7 +54,7 @@
CRASH("Attempt to enable Z-mimic on already-enabled turf!")
shadower = new(src)
SSzcopy.openspace_turfs += 1
var/turf/under = GetBelow(src)
var/turf/under = GET_TURF_BELOW(src)
if (under)
below = under
below.above = src