mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
Multi-Z code formatting and utilities.
* Global procs should start with /proc * Use to_chat() macro * Added utility to find all z-levels are connected (transitively adjacent) and utility to test if two levels are connected.
This commit is contained in:
@@ -11,25 +11,35 @@ var/z_levels = 0 // Each bit represents a connection between adjacent levels. S
|
||||
qdel(src)
|
||||
|
||||
// The storage of connections between adjacent levels means some bitwise magic is needed.
|
||||
proc/HasAbove(var/z)
|
||||
/proc/HasAbove(var/z)
|
||||
if(z >= world.maxz || z > 16 || z < 1)
|
||||
return 0
|
||||
return z_levels & (1 << (z - 1))
|
||||
|
||||
proc/HasBelow(var/z)
|
||||
/proc/HasBelow(var/z)
|
||||
if(z > world.maxz || z > 17 || z < 2)
|
||||
return 0
|
||||
return z_levels & (1 << (z - 2))
|
||||
|
||||
// Thankfully, no bitwise magic is needed here.
|
||||
proc/GetAbove(var/atom/atom)
|
||||
/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)
|
||||
/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--)
|
||||
. |= level-1
|
||||
for(var/level = z, HasAbove(level), level++)
|
||||
. |= level+1
|
||||
|
||||
proc/AreConnectedZLevels(var/zA, var/zB)
|
||||
return zA == zB || (zB in GetConnectedZlevels(zA))
|
||||
|
||||
Reference in New Issue
Block a user