From f317c0b09d650227768e4d6cbddc76f63734cbb3 Mon Sep 17 00:00:00 2001 From: Incoming Date: Tue, 23 Sep 2014 16:10:13 -0400 Subject: [PATCH] Predictably Random Z-levels and the SPACECUBE The layout of the accessible z levels in relation to each other are now lain out in a massive preshuffled SPACECUBE. Every Z-level is no more than two screens from every other Z-level, and can be moved through in a predictable order* with a little ingenuity *Except z.6 See pull for the full details --- code/_globalvars/lists/mapping.dm | 6 +- code/controllers/master_controller.dm | 1 + code/game/turfs/space/space.dm | 112 +++++++++++++++++++------- 3 files changed, 90 insertions(+), 29 deletions(-) diff --git a/code/_globalvars/lists/mapping.dm b/code/_globalvars/lists/mapping.dm index 2d26a49903f..6de9affff95 100644 --- a/code/_globalvars/lists/mapping.dm +++ b/code/_globalvars/lists/mapping.dm @@ -1,3 +1,7 @@ +#define Z_NORTH 1 +#define Z_EAST 2 +#define Z_SOUTH 3 +#define Z_WEST 4 var/list/cardinal = list( NORTH, SOUTH, EAST, WEST ) var/list/alldirs = list(NORTH, SOUTH, EAST, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST) @@ -8,7 +12,7 @@ var/list/alldirs = list(NORTH, SOUTH, EAST, WEST, NORTHEAST, NORTHWEST, SOUTHEAS //Was list("3" = 30, "4" = 70). //Spacing should be a reliable method of getting rid of a body -- Urist. //Go away Urist, I'm restoring this to the longer list. ~Errorage -var/list/accessable_z_levels = list("1" = 5, "3" = 10, "4" = 15, "5" = 10, "6" = 60) +var/list/accessable_z_levels = list(1,3,4,5,6,6) var/global/list/global_map = null //list/global_map = list(list(1,5),list(4,3))//an array of map Z levels. diff --git a/code/controllers/master_controller.dm b/code/controllers/master_controller.dm index 3b54156cee6..f2b4aab85fe 100644 --- a/code/controllers/master_controller.dm +++ b/code/controllers/master_controller.dm @@ -73,6 +73,7 @@ var/global/pipe_processing_killed = 0 world.tick_lag = config.Ticklag setup_objects() + setup_map_transistions() setupgenetics() setupfactions() diff --git a/code/game/turfs/space/space.dm b/code/game/turfs/space/space.dm index 0273efd720f..33a098b624d 100644 --- a/code/game/turfs/space/space.dm +++ b/code/game/turfs/space/space.dm @@ -8,6 +8,10 @@ thermal_conductivity = OPEN_HEAT_TRANSFER_COEFFICIENT heat_capacity = 700000 + var/transition //These is used in transistions as a way to tell where on the "cube" of space you're transitioning from/to + var/destination_x + var/destination_y + /turf/space/New() if(!istype(src, /turf/space/transit)) icon_state = "[((x + y) ^ ~(x * y) + z) % 25]" @@ -50,37 +54,15 @@ inertial_drift(A) - if (A.x <= TRANSITIONEDGE || A.x >= (world.maxx - TRANSITIONEDGE - 1) || A.y <= TRANSITIONEDGE || A.y >= (world.maxy - TRANSITIONEDGE - 1)) - var/move_to_z = src.z - var/safety = 1 + if(transition) - while(move_to_z == src.z) - var/move_to_z_str = pickweight(accessable_z_levels) - move_to_z = text2num(move_to_z_str) - safety++ - if(safety > 10) - break + if(destination_x) + A.x = destination_x - if(!move_to_z) - return + if(destination_y) + A.y = destination_y - A.z = move_to_z - - if(src.x <= TRANSITIONEDGE) - A.x = world.maxx - TRANSITIONEDGE - 2 - A.y = rand(TRANSITIONEDGE + 2, world.maxy - TRANSITIONEDGE - 2) - - else if (A.x >= (world.maxx - TRANSITIONEDGE - 1)) - A.x = TRANSITIONEDGE + 1 - A.y = rand(TRANSITIONEDGE + 2, world.maxy - TRANSITIONEDGE - 2) - - else if (src.y <= TRANSITIONEDGE) - A.y = world.maxy - TRANSITIONEDGE -2 - A.x = rand(TRANSITIONEDGE + 2, world.maxx - TRANSITIONEDGE - 2) - - else if (A.y >= (world.maxy - TRANSITIONEDGE - 1)) - A.y = TRANSITIONEDGE + 1 - A.x = rand(TRANSITIONEDGE + 2, world.maxx - TRANSITIONEDGE - 2) + A.z = text2num(transition) if(isliving(A)) var/mob/living/L = A @@ -127,3 +109,77 @@ /turf/space/handle_slip() return + +/turf/space/proc/Assign_Destination() + + if(transition) + if(x <= TRANSITIONEDGE) //west + destination_x = world.maxx - TRANSITIONEDGE - 2 + else if (x >= (world.maxx - TRANSITIONEDGE - 1)) //east + destination_x = TRANSITIONEDGE + 1 + else if (y <= TRANSITIONEDGE) //south + destination_y = world.maxy - TRANSITIONEDGE - 2 + else if (y >= (world.maxy - TRANSITIONEDGE - 1)) //north + destination_y = TRANSITIONEDGE + 1 + +/datum/controller/game_controller/proc/setup_map_transistions() //listamania + var/list/unplaced_z_levels = accessable_z_levels + var/list/free_zones = list("A", "B", "C", "D", "E", "F") + var/list/zone_connections = list("D ","C ","B ","E ","A ","C ","F ","E ","A ","D ","F ","B ","A ","E ","F ","C ","A ","B ","F ","D ","D ","C ","B ","E") //This describes the borders of a cube based on free zones, really! + var/text_zone_connections = list2text(zone_connections) + var/list/final_zone_connections = list() + var/list/turfs_needing_transition = list() + var/list/turfs_needing_destinations = list() + var/list/z_level_order = list() + var/z_level + var/placement + + for(var/turf/space/S in world) //Define the transistions of the z levels + if (S.x == TRANSITIONEDGE || S.x == (world.maxx - TRANSITIONEDGE - 1) || S.y == TRANSITIONEDGE || S.y == (world.maxy - TRANSITIONEDGE - 1)) + turfs_needing_transition += S + + while(free_zones.len != 0) //Assign the sides of the cube + if(!unplaced_z_levels) //if we're somehow unable to fill the cube, pad with deep space + z_level = 6 + else + z_level = pick(unplaced_z_levels) + placement = pick(free_zones) + text_zone_connections = replacetext(text_zone_connections, placement, "[z_level]") + + for(var/turf/space/S in turfs_needing_transition) //pass the identity zone to the relevent turfs + if(S.transition && prob(50)) //In z = 6 (deep space) it's a bit of a crapshoot in terms of navigation + continue + if(S.z == z_level) + S.transition = z_level + if(!(S in turfs_needing_destinations)) + turfs_needing_destinations += S + if(S.z != 6) //deep space turfs need to hang around in case they get reassigned a zone + turfs_needing_transition -= S + + z_level_order += z_level + unplaced_z_levels -= z_level + free_zones -= placement + + zone_connections = text2list(replacetext(text_zone_connections, " ", "\n")) //Convert the string back into a list + + final_zone_connections.len = z_level_order.len + + var/list/temp = list() + for(var/j=1, j<= 24, j++) + temp += zone_connections[j] + if(temp.len == 4) //Chunks of cardinal directions + final_zone_connections[z_level_order[j/4]] += temp + temp = list() + + for(var/turf/space/S in turfs_needing_destinations) //replace the identity zone with the destination z-level + var/list/directions = final_zone_connections[S.transition] + if(S.x <= TRANSITIONEDGE) + S.transition = directions[Z_WEST] + else if(S.x >= (world.maxx - TRANSITIONEDGE - 1)) + S.transition = directions[Z_EAST] + else if(S.y <= TRANSITIONEDGE) + S.transition = directions[Z_SOUTH] + else + S.transition = directions[Z_NORTH] + + S.Assign_Destination() \ No newline at end of file