Removes most hard-coded z level checks

This commit is contained in:
Crazylemon64
2016-07-31 21:29:03 -07:00
parent f54de64a73
commit bf2bcbce67
122 changed files with 325 additions and 410 deletions
@@ -0,0 +1,7 @@
/proc/is_on_level_name(atom/A,name)
var/datum/space_level/S = space_manager.get_zlev_by_name(name)
return A.z == S.zpos
// For expansion later
/proc/atoms_share_level(atom/A, atom/B)
return A.z == B.z
@@ -0,0 +1,62 @@
/proc/is_level_reachable(z)
return check_level_trait(z, REACHABLE)
/proc/is_station_level(z)
return check_level_trait(z, STATION_LEVEL)
/proc/is_station_contact(z)
return check_level_trait(z, STATION_CONTACT)
/proc/is_teleport_allowed(z)
return !check_level_trait(z, BLOCK_TELEPORT)
/proc/is_admin_level(z)
return check_level_trait(z, ADMIN_LEVEL)
/proc/is_away_level(z)
return check_level_trait(z, AWAY_LEVEL)
/proc/is_mining_level(z)
return check_level_trait(z, ORE_LEVEL)
/proc/is_ai_allowed(z)
return check_level_trait(z, AI_OK)
/proc/level_blocks_magic(z)
return check_level_trait(z, IMPEDES_MAGIC)
/proc/level_boosts_signal(z)
return check_level_trait(z, BOOSTS_SIGNAL)
// Used for the nuke disk, or for checking if players survived through xenos
/proc/is_secure_level(z)
var/secure = check_level_trait(z, STATION_LEVEL)
if(!secure)
// This is to allow further admin levels later, other than centcomm
secure = (z == level_name_to_num(CENTCOMM))
return secure
var/list/default_map_traits = MAP_TRANSITION_CONFIG
/proc/check_level_trait(z, trait)
if(z == 0)
return 0 // If you're nowhere, you have no traits
var/list/trait_list
if(space_manager.initialized)
var/datum/space_level/S = space_manager.get_zlev(z)
trait_list = S.flags
else
trait_list = default_map_traits[z]
trait_list = trait_list["attributes"]
return (trait in trait_list)
/proc/levels_by_trait(trait)
var/list/result = list()
for(var/A in space_manager.z_list)
var/datum/space_level/S = space_manager.z_list[A]
if(trait in S.flags)
result |= S
return result
/proc/level_name_to_num(name)
var/datum/space_level/S = space_manager.get_zlev_by_name(name)
return S.zpos
+5 -3
View File
@@ -1,7 +1,7 @@
/datum/space_level
var/name = "Your config settings failed, you need to fix this for the datum space levels to work"
var/zpos = 1
var/flags = 0 // We'll use this to keep track of whether you can teleport/etc
var/flags = list() // We'll use this to keep track of whether you can teleport/etc
// Map transition stuff
var/list/neighbors = list()
@@ -19,8 +19,9 @@
var/dirt_count = 0
var/list/init_list = list()
/datum/space_level/New(z, name, transition_type = SELFLOOPING)
/datum/space_level/New(z, name, transition_type = SELFLOOPING, traits = list(BLOCK_TELEPORT))
zpos = z
flags = traits
set_linkage(transition_type)
build_space_destination_arrays()
@@ -57,7 +58,8 @@
linkage = transition_type
if(transition_type == SELFLOOPING)
link_to_self() // `link_to_self` is defined in space_transitions.dm
if(transition_type == UNAFFECTED)
reset_connections()
/datum/space_level/proc/resume_init()
if(dirt_count > 0)
@@ -20,6 +20,7 @@
var/list/direction_cache = list()
/datum/space_level/proc/link_to_self()
reset_connections()
neighbors = list()
var/list/L = list(Z_LEVEL_NORTH,Z_LEVEL_SOUTH,Z_LEVEL_EAST,Z_LEVEL_WEST)
for(var/A in L)
@@ -279,7 +280,7 @@
/datum/spacewalk_grid/proc/get_height()
return 1 + max_y - min_y
// This function is called repeatedly to build the map
// This function chooses an available point next to any node in the grid
/datum/spacewalk_grid/proc/get_empty_node()
var/datum/point/P = pick(available_nodes)
if(isnull(P))
@@ -287,6 +288,12 @@
consume_node(P)
return P
// This function is called repeatedly to build the map
/datum/spacewalk_grid/proc/add_level(datum/space_level/S)
var/datum/point/P = get_empty_node()
P.set_space_level(S)
// This proc substantiates the grid of points used to determine routes between levels
// Separating this from initialization gives us time in which we can add more crosslink z levels
// before we bake in all our connections
@@ -318,16 +325,10 @@
D = pick(crosslinks)
crosslinks.Remove(D)
// We now choose a point in our imaginary grid adjacent to our current location
P = point_grid.get_empty_node()
// Let our z level know where in the imaginary grid it is
// This will also handle establishing neighborship with other z levels
P.set_space_level(D)
point_grid.add_level(D)
// A heavy proc - loops through all space turfs and sets its destination
// Loops through border space turfs and sets its destination
// based on its space level's linkage
// Takes 0.6 seconds per call on my machine - could have each z level
// have its own space turf cache, but I don't want to complicate this more
// than is necessary
/datum/zlev_manager/proc/setup_space_destinations()
var/timer = start_watch()
log_debug("Assigning space turf destinations...")
@@ -3,9 +3,11 @@ var/global/datum/zlev_manager/space_manager = new
/datum/zlev_manager
// A list of z-levels
var/list/z_list = list()
var/list/levels_by_name = list()
var/list/heaps = list()
var/datum/spacewalk_grid/linkage_map
var/initialized = 0
// Populate our space level list
// and prepare space transitions
@@ -14,18 +16,24 @@ var/global/datum/zlev_manager/space_manager = new
var/k = 1
// First take care of "Official" z levels, without visiting levels outside of the list
for(var/A in map_transition_config)
// `A` is the name
// `map_transition_config[A]` is the transition type
z_list["[k]"] = new /datum/space_level(k, A, transition_type = map_transition_config[A])
for(var/list/features in map_transition_config)
if(k > world.maxz)
CRASH("More map transitions defined than existent z levels - [num_official_z_levels]")
CRASH("More map attributes pre-defined than existent z levels - [num_official_z_levels]")
var/name = features["name"]
var/linking = features["linkage"]
var/list/attributes = features["attributes"]
attributes = attributes.Copy() // Clone the list so it can't be changed on accident
var/datum/space_level/S = new /datum/space_level(k, name, transition_type = linking, traits = attributes)
z_list["[k]"] = S
levels_by_name[name] = S
k++
// Then, we take care of unmanaged z levels
// They get the default linkage of SELFLOOPING
for(var/i = k, i <= world.maxz, i++)
z_list["[i]"] = new /datum/space_level(i)
initialized = 1
/datum/zlev_manager/proc/get_zlev(z)
@@ -34,6 +42,11 @@ var/global/datum/zlev_manager/space_manager = new
else
return z_list["[z]"]
/datum/zlev_manager/proc/get_zlev_by_name(A)
if(!(A in levels_by_name))
throw EXCEPTION("Non-existent z level: '[A]'")
return levels_by_name[A]
/*
* "Dirt" management
* "Dirt" is used to keep track of whether a z level should automatically have
@@ -88,10 +101,14 @@ var/global/datum/zlev_manager/space_manager = new
// Increments the max z-level by one
// For convenience's sake returns the z-level added
/datum/zlev_manager/proc/add_new_zlevel(name, linkage = SELFLOOPING)
/datum/zlev_manager/proc/add_new_zlevel(name, linkage = SELFLOOPING, traits = list(BLOCK_TELEPORT))
if(name in levels_by_name)
throw EXCEPTION("Name already in use: [name]")
world.maxz++
var/our_z = world.maxz
z_list["[our_z]"] = new /datum/space_level(our_z,name, transition_type = linkage)
var/datum/space_level/S = new /datum/space_level(our_z, name, transition_type = linkage, traits = traits)
levels_by_name[name] = S
z_list["[our_z]"] = S
return our_z
/datum/zlev_manager/proc/cut_levels_downto(new_maxz)