diff --git a/code/modules/mapping/mapping_helpers.dm b/code/modules/mapping/mapping_helpers/_mapping_helpers.dm
similarity index 59%
rename from code/modules/mapping/mapping_helpers.dm
rename to code/modules/mapping/mapping_helpers/_mapping_helpers.dm
index a7f84fd71f..99184b1c3e 100644
--- a/code/modules/mapping/mapping_helpers.dm
+++ b/code/modules/mapping/mapping_helpers/_mapping_helpers.dm
@@ -1,90 +1,4 @@
//Landmarks and other helpers which speed up the mapping process and reduce the number of unique instances/subtypes of items/turf/ect
-
-
-
-/obj/effect/baseturf_helper //Set the baseturfs of every turf in the /area/ it is placed.
- name = "baseturf editor"
- icon = 'icons/effects/mapping_helpers.dmi'
- icon_state = ""
-
- var/list/baseturf_to_replace
- var/baseturf
-
- layer = POINT_LAYER
-
-/obj/effect/baseturf_helper/Initialize()
- . = ..()
- return INITIALIZE_HINT_LATELOAD
-
-/obj/effect/baseturf_helper/LateInitialize()
- if(!baseturf_to_replace)
- baseturf_to_replace = typecacheof(list(/turf/open/space,/turf/baseturf_bottom))
- else if(!length(baseturf_to_replace))
- baseturf_to_replace = list(baseturf_to_replace = TRUE)
- else if(baseturf_to_replace[baseturf_to_replace[1]] != TRUE) // It's not associative
- var/list/formatted = list()
- for(var/i in baseturf_to_replace)
- formatted[i] = TRUE
- baseturf_to_replace = formatted
-
- var/area/our_area = get_area(src)
- for(var/i in get_area_turfs(our_area, z))
- replace_baseturf(i)
-
- qdel(src)
-
-/obj/effect/baseturf_helper/proc/replace_baseturf(turf/thing)
- var/list/baseturf_cache = thing.baseturfs
- if(length(baseturf_cache))
- for(var/i in baseturf_cache)
- if(baseturf_to_replace[i])
- baseturf_cache -= i
- if(!baseturf_cache.len)
- thing.assemble_baseturfs(baseturf)
- else
- thing.PlaceOnBottom(null, baseturf)
- else if(baseturf_to_replace[thing.baseturfs])
- thing.assemble_baseturfs(baseturf)
- else
- thing.PlaceOnBottom(null, baseturf)
-
-/obj/effect/baseturf_helper/space
- name = "space baseturf editor"
- baseturf = /turf/open/space
-
-/obj/effect/baseturf_helper/asteroid
- name = "asteroid baseturf editor"
- baseturf = /turf/open/floor/plating/asteroid
-
-/obj/effect/baseturf_helper/asteroid/airless
- name = "asteroid airless baseturf editor"
- baseturf = /turf/open/floor/plating/asteroid/airless
-
-/obj/effect/baseturf_helper/asteroid/basalt
- name = "asteroid basalt baseturf editor"
- baseturf = /turf/open/floor/plating/asteroid/basalt
-
-/obj/effect/baseturf_helper/asteroid/snow
- name = "asteroid snow baseturf editor"
- baseturf = /turf/open/floor/plating/asteroid/snow
-
-/obj/effect/baseturf_helper/beach/sand
- name = "beach sand baseturf editor"
- baseturf = /turf/open/floor/plating/beach/sand
-
-/obj/effect/baseturf_helper/beach/water
- name = "water baseturf editor"
- baseturf = /turf/open/floor/plating/beach/water
-
-/obj/effect/baseturf_helper/lava
- name = "lava baseturf editor"
- baseturf = /turf/open/lava/smooth
-
-/obj/effect/baseturf_helper/lava_land/surface
- name = "lavaland baseturf editor"
- baseturf = /turf/open/lava/smooth/lava_land_surface
-
-
/obj/effect/mapping_helpers
icon = 'icons/effects/mapping_helpers.dmi'
icon_state = ""
@@ -94,7 +8,6 @@
..()
return late ? INITIALIZE_HINT_LATELOAD : INITIALIZE_HINT_QDEL
-
//airlock helpers
/obj/effect/mapping_helpers/airlock
layer = DOOR_HELPER_LAYER
diff --git a/code/modules/mapping/mapping_helpers/baseturf.dm b/code/modules/mapping/mapping_helpers/baseturf.dm
new file mode 100644
index 0000000000..f4bd0d7c7f
--- /dev/null
+++ b/code/modules/mapping/mapping_helpers/baseturf.dm
@@ -0,0 +1,82 @@
+/obj/effect/baseturf_helper //Set the baseturfs of every turf in the /area/ it is placed.
+ name = "baseturf editor"
+ icon = 'icons/effects/mapping_helpers.dmi'
+ icon_state = ""
+
+ var/list/baseturf_to_replace
+ var/baseturf
+
+ layer = POINT_LAYER
+
+/obj/effect/baseturf_helper/Initialize()
+ . = ..()
+ return INITIALIZE_HINT_LATELOAD
+
+/obj/effect/baseturf_helper/LateInitialize()
+ if(!baseturf_to_replace)
+ baseturf_to_replace = typecacheof(list(/turf/open/space,/turf/baseturf_bottom))
+ else if(!length(baseturf_to_replace))
+ baseturf_to_replace = list(baseturf_to_replace = TRUE)
+ else if(baseturf_to_replace[baseturf_to_replace[1]] != TRUE) // It's not associative
+ var/list/formatted = list()
+ for(var/i in baseturf_to_replace)
+ formatted[i] = TRUE
+ baseturf_to_replace = formatted
+
+ var/area/our_area = get_area(src)
+ for(var/i in get_area_turfs(our_area, z))
+ replace_baseturf(i)
+
+ qdel(src)
+
+/obj/effect/baseturf_helper/proc/replace_baseturf(turf/thing)
+ var/list/baseturf_cache = thing.baseturfs
+ if(length(baseturf_cache))
+ for(var/i in baseturf_cache)
+ if(baseturf_to_replace[i])
+ baseturf_cache -= i
+ if(!baseturf_cache.len)
+ thing.assemble_baseturfs(baseturf)
+ else
+ thing.PlaceOnBottom(null, baseturf)
+ else if(baseturf_to_replace[thing.baseturfs])
+ thing.assemble_baseturfs(baseturf)
+ else
+ thing.PlaceOnBottom(null, baseturf)
+
+/obj/effect/baseturf_helper/space
+ name = "space baseturf editor"
+ baseturf = /turf/open/space
+
+/obj/effect/baseturf_helper/asteroid
+ name = "asteroid baseturf editor"
+ baseturf = /turf/open/floor/plating/asteroid
+
+/obj/effect/baseturf_helper/asteroid/airless
+ name = "asteroid airless baseturf editor"
+ baseturf = /turf/open/floor/plating/asteroid/airless
+
+/obj/effect/baseturf_helper/asteroid/basalt
+ name = "asteroid basalt baseturf editor"
+ baseturf = /turf/open/floor/plating/asteroid/basalt
+
+/obj/effect/baseturf_helper/asteroid/snow
+ name = "asteroid snow baseturf editor"
+ baseturf = /turf/open/floor/plating/asteroid/snow
+
+/obj/effect/baseturf_helper/beach/sand
+ name = "beach sand baseturf editor"
+ baseturf = /turf/open/floor/plating/beach/sand
+
+/obj/effect/baseturf_helper/beach/water
+ name = "water baseturf editor"
+ baseturf = /turf/open/floor/plating/beach/water
+
+/obj/effect/baseturf_helper/lava
+ name = "lava baseturf editor"
+ baseturf = /turf/open/lava/smooth
+
+/obj/effect/baseturf_helper/lava_land/surface
+ name = "lavaland baseturf editor"
+ baseturf = /turf/open/lava/smooth/lava_land_surface
+
diff --git a/code/modules/mapping/mapping_helpers/network_builder/_network_builder.dm b/code/modules/mapping/mapping_helpers/network_builder/_network_builder.dm
new file mode 100644
index 0000000000..b5cd470a32
--- /dev/null
+++ b/code/modules/mapping/mapping_helpers/network_builder/_network_builder.dm
@@ -0,0 +1,38 @@
+//Builds networks like power cables/atmos lines/etc
+//Just a holder parent type for now..
+/obj/effect/network_builder
+ /// set var to true to not del on lateload
+ var/custom_spawned = FALSE
+
+ /// what directions we know connections are in
+ var/list/network_directions
+
+/obj/effect/network_builder/Initialize(mapload)
+ . = ..()
+ var/conflict = check_duplicates()
+ if(conflict)
+ stack_trace("WARNING: [type] network building helper found check_duplicates() conflict [conflict] in its location.!")
+ return INITIALIZE_HINT_QDEL
+ if(!mapload)
+ if(GLOB.Debug2)
+ custom_spawned = TRUE
+ return INITIALIZE_HINT_NORMAL
+ else
+ return INITIALIZE_HINT_QDEL
+ return INITIALIZE_HINT_LATELOAD
+
+/// How this works: On LateInitialize, detect all directions that this should be applicable to, and do what it needs to do, and then inform all network builders in said directions that it's been around since it won't be around afterwards.
+/obj/effect/network_builder/LateInitialize()
+ scan_directions()
+ build_network()
+ if(!custom_spawned)
+ qdel(src)
+
+/obj/effect/network_builder/proc/check_duplicates()
+ CRASH("Base abstract network builder tried to check duplicates.")
+
+/obj/effect/network_builder/proc/scan_directions()
+ CRASH("Base abstract network builder tried to scan directions.")
+
+/obj/effect/network_builder/proc/build_network()
+ CRASH("Base abstract network builder tried to build network.")
diff --git a/code/modules/mapping/mapping_helpers/network_builder/atmos_pipe.dm b/code/modules/mapping/mapping_helpers/network_builder/atmos_pipe.dm
new file mode 100644
index 0000000000..1183ec0434
--- /dev/null
+++ b/code/modules/mapping/mapping_helpers/network_builder/atmos_pipe.dm
@@ -0,0 +1,159 @@
+#define NO_KNOT 0
+#define KNOT_AUTO 1
+#define KNOT_FORCED 2
+
+/* Automatically places pipes on init based on any pipes connecting to it and adjacent helpers. Only supports cardinals.
+ * Conflicts with ANY PIPE ON ITS LAYER, as well as atmos network build helpers on the same layer, as well as any pipe on all layers. Do those manually.
+*/
+/obj/effect/network_builder/atmos_pipe
+ name = "atmos pipe autobuilder"
+ icon_state = "atmospipebuilder"
+
+ /// Layer to put our pipes on
+ var/pipe_layer = PIPING_LAYER_DEFAULT
+
+ /// Color to set our pipes to
+ var/pipe_color
+
+ /// Whether or not pipes we make are visible
+ var/visible_pipes = FALSE
+
+ color = null
+
+/obj/effect/network_builder/atmos_pipe/check_duplicates()
+ for(var/obj/effect/network_builder/atmos_pipe/other in loc)
+ if(other.pipe_layer == pipe_layer)
+ return other
+ for(var/obj/machinery/atmospherics/A in loc)
+ if(A.pipe_flags & PIPING_ALL_LAYER)
+ return A
+ if(A.pipe_layer == pipe_layer)
+ return A
+ return FALSE
+
+/// Scans directions, sets network_directions to have every direction that we can link to. If there's another power cable builder detected, make sure they know we're here by adding us to their cable directions list before we're deleted.
+/obj/effect/network_builder/atmos_pipe/scan_directions()
+ var/turf/T
+ for(var/i in GLOB.cardinal)
+ if(i in network_directions)
+ continue //we're already set, that means another builder set us.
+ T = get_step(loc, i)
+ if(!T)
+ continue
+ var/found = FALSE
+ for(var/obj/effect/network_builder/atmos_pipe/other in T)
+ if(other.pipe_layer == pipe_layer)
+ network_directions += i
+ LAZYADD(other.network_directions, turn(i, 180))
+ found = TRUE
+ break
+ if(found)
+ continue
+ for(var/obj/machinery/atmospherics/A in T)
+ if((A.pipe_layer == pipe_layer) && (A.initialize_directions & i))
+ network_directions += i
+ break
+ return network_directions
+
+/// Directions should only ever have cardinals.
+/obj/effect/network_builder/atmos_pipe/build_network(list/directions = pipe_directions)
+ if(!length(directions) <= 1)
+ return
+ var/obj/machinery/atmospherics/pipe/built
+ switch(length(directions))
+ if(2) //straight pipe
+ built = new /obj/machinery/atmospherics/simple(loc)
+ built.setDir(directions[1] | directions[2])
+ if(3) //manifold
+ var/list/missing = directions ^ GLOB.cardinal
+ missing = missing[1]
+ built = new /obj/machinery/atmospherics/pipe/manifold(loc)
+ built.setDir(missing)
+ if(4) //4 way manifold
+ built = new /obj/machinery/atmospherics/pipe/manifold4w(loc)
+ built.SetInitDirections()
+ built.on_construction(pipe_color, piping_layer)
+
+/obj/item/pipe/wrench_act(mob/living/user, obj/item/wrench/W)
+ if(!isturf(loc))
+ return TRUE
+
+ add_fingerprint(user)
+
+ var/obj/machinery/atmospherics/fakeA = pipe_type
+ var/flags = initial(fakeA.pipe_flags)
+ for(var/obj/machinery/atmospherics/M in loc)
+ if((M.pipe_flags & flags & PIPING_ONE_PER_TURF)) //Only one dense/requires density object per tile, eg connectors/cryo/heater/coolers.
+ to_chat(user, "Something is hogging the tile!")
+ return TRUE
+ if((M.piping_layer != piping_layer) && !((M.pipe_flags | flags) & PIPING_ALL_LAYER)) //don't continue if either pipe goes across all layers
+ continue
+ if(M.GetInitDirections() & SSair.get_init_dirs(pipe_type, fixed_dir())) // matches at least one direction on either type of pipe
+ to_chat(user, "There is already a pipe at that location!")
+ return TRUE
+ // no conflicts found
+
+ var/obj/machinery/atmospherics/A = new pipe_type(loc)
+ build_pipe(A)
+ A.on_construction(color, piping_layer)
+ transfer_fingerprints_to(A)
+
+ W.play_tool_sound(src)
+ user.visible_message( \
+ "[user] fastens \the [src].", \
+ "You fasten \the [src].", \
+ "You hear ratcheting.")
+
+ qdel(src)
+
+/obj/item/pipe/proc/build_pipe(obj/machinery/atmospherics/A)
+ A.setDir(fixed_dir())
+ A.SetInitDirections()
+
+ if(pipename)
+ A.name = pipename
+ if(A.on)
+ // Certain pre-mapped subtypes are on by default, we want to preserve
+ // every other aspect of these subtypes (name, pre-set filters, etc.)
+ // but they shouldn't turn on automatically when wrenched.
+ A.on = FALSE
+
+/obj/effect/network_builder/atmos_pipe/proc/spawn_wires(list/directions)
+ if(!length(directions))
+ return
+ else if(length(directions) == 1)
+ var/knot = (knot == KNOT_FORCED) || ((knot == KNOT_AUTO) && should_auto_knot())
+ if(knot)
+ var/dir = directions[1]
+ new /obj/structure/cable(loc, cable_color, NONE, directions[1])
+ else
+ if(knot == KNOT_FORCED)
+ for(var/d in directions)
+ new /obj/structure/cable(loc, cable_color, NONE, d)
+ else
+ var/knot = (knot == KNOT_FORCED) || ((knot == KNOT_AUTO) && should_auto_knot())
+ var/dirs = length(directions)
+ for(var/i in dirs)
+ var/li = i - 1
+ if(li < 1)
+ li = dirs + li
+ new /obj/structure/cable(loc, cable_color, directions[i], directions[li])
+ if(knot)
+ new /obj/structure/cable(loc, cable_color, NONE, directions[i])
+ knot = FALSE
+
+/obj/effect/network_builder/atmos_pipe/distro
+ name = "distro line autobuilder"
+ piping_layer = PIPING_LAYER_MIN
+ pixel_x = -PIPING_LAYER_P_X
+ pixel_y = -PIPING_LAYER_P_Y
+ pipe_color = rgb(130,43,255)
+ color = rgb(130,43,255)
+
+/obj/effect/network_builder/atmos_pipe/scrubbers
+ name = "scrubbers line autobuilder"
+ piping_layer = PIPING_LAYER_MAX
+ pixel_x = PIPING_LAYER_P_X
+ pixel_y = PIPING_LAYER_P_Y
+ pipe_color = rgb(255,0,0)
+ color = rgb(255,0,0)
diff --git a/code/modules/mapping/mapping_helpers/network_builder/power_cables.dm b/code/modules/mapping/mapping_helpers/network_builder/power_cables.dm
new file mode 100644
index 0000000000..db89454349
--- /dev/null
+++ b/code/modules/mapping/mapping_helpers/network_builder/power_cables.dm
@@ -0,0 +1,97 @@
+#define NO_KNOT 0
+#define KNOT_AUTO 1
+#define KNOT_FORCED 2
+
+/// Automatically links on init to power cables and other cable builder helpers. Only supports cardinals.
+/obj/effect/network_builder/power_cable
+ name = "power line autobuilder"
+ icon_state = "powerlinebuilder"
+
+ /// Whether or not we forcefully make a knot
+ var/knot = NO_KNOT
+
+ /// cable color as from GLOB.cable_colors
+ var/cable_color = "red"
+
+ color = "ff0000"
+
+/obj/effect/network_builder/power_cable/check_duplicates()
+ return (locate(/obj/structure/cable) in loc) || (locate(/obj/effect/network_builder/power_cable) in loc)
+
+/// Scans directions, sets network_directions to have every direction that we can link to. If there's another power cable builder detected, make sure they know we're here by adding us to their cable directions list before we're deleted.
+/obj/effect/network_builder/power_cable/scan_directions()
+ var/turf/T
+ for(var/i in GLOB.cardinal)
+ if(i in network_directions)
+ continue //we're already set, that means another builder set us.
+ T = get_step(loc, i)
+ if(!T)
+ continue
+ var/obj/effect/network_builder/power_cable/other = locate() in T
+ if(other)
+ network_directions += i
+ LAZYADD(other.network_directions, turn(i, 180))
+ continue
+ for(var/obj/structure/cable/C in T)
+ if(C.d1 == turn(i, 180) || C.d2 == turn(i, 180))
+ network_directions += i
+ continue
+ return network_directions
+
+/// Directions should only ever have cardinals.
+/obj/effect/network_builder/power_cable/build_network(list/directions = network_directions)
+ if(!length(directions))
+ return
+ else if(length(directions) == 1)
+ var/knot = (knot == KNOT_FORCED) || ((knot == KNOT_AUTO) && should_auto_knot())
+ if(knot)
+ var/dir = directions[1]
+ new /obj/structure/cable(loc, cable_color, NONE, directions[1])
+ else
+ if(knot == KNOT_FORCED)
+ for(var/d in directions)
+ new /obj/structure/cable(loc, cable_color, NONE, d)
+ else
+ var/knot = (knot == KNOT_FORCED) || ((knot == KNOT_AUTO) && should_auto_knot())
+ var/dirs = length(directions)
+ for(var/i in dirs)
+ var/li = i - 1
+ if(li < 1)
+ li = dirs + li
+ new /obj/structure/cable(loc, cable_color, directions[i], directions[li])
+ if(knot)
+ new /obj/structure/cable(loc, cable_color, NONE, directions[i])
+ knot = FALSE
+
+/obj/effect/network_builder/power_cable/proc/should_auto_knot()
+ return (locate(/obj/machinery/terminal) in loc)
+
+/obj/effect/network_buidler/power_cable/knot
+ icon_state = "powerlinebuilderknot"
+ knot = KNOT_FORCED
+
+/obj/effect/network_builder/power_cable/auto
+ icon_state = "powerlinebuilderauto"
+ knot = KNOT_AUTO
+
+#define AUTODEF_COLOR(hex, enum) \
+/obj/effect/network_builder/power_cable/##enum \
+ color = #hex \
+ cable_color = #enum \
+/obj/effect/network_builder/power_cable/knot/##enum \
+ color = #hex \
+ cable_color = #enum \
+/obj/effect/network_builder/power_cable/auto/##enum \
+ color = #hex \
+ cable_color = #enum
+
+AUTODEF_COLOR("#ff0000", "red")
+AUTODEF_COLOR("#ffffff", "white")
+AUTODEF_COLOR("#00ffff", "cyan")
+AUTODEF_COLOR("#ff8000", "orange")
+AUTODEF_COLOR("#ff3cc8", "pink")
+AUTODEF_COLOR("#1919c8", "blue")
+AUTODEF_COLOR("#00aa00", "green")
+AUTODEF_COLOR("#ffff00", "yellow")
+
+#undef AUTODEF_COLOR
diff --git a/code/modules/mapping/ruins.dm b/code/modules/mapping/ruins.dm
index 9c578badb1..d88c7543f0 100644
--- a/code/modules/mapping/ruins.dm
+++ b/code/modules/mapping/ruins.dm
@@ -1,171 +1,171 @@
-/datum/map_template/ruin/proc/try_to_place(z,allowed_areas,turf/forced_turf)
- var/sanity = forced_turf ? 1 : PLACEMENT_TRIES
- if(SSmapping.level_trait(z,ZTRAIT_ISOLATED_RUINS))
- return place_on_isolated_level(z)
- while(sanity > 0)
- sanity--
- var/width_border = TRANSITIONEDGE + SPACERUIN_MAP_EDGE_PAD + round(width / 2)
- var/height_border = TRANSITIONEDGE + SPACERUIN_MAP_EDGE_PAD + round(height / 2)
- var/turf/central_turf = forced_turf ? forced_turf : locate(rand(width_border, world.maxx - width_border), rand(height_border, world.maxy - height_border), z)
- var/valid = TRUE
-
- for(var/turf/check in get_affected_turfs(central_turf,1))
- var/area/new_area = get_area(check)
- if(!(istype(new_area, allowed_areas)) || check.flags_1 & NO_RUINS_1)
- valid = FALSE
- break
-
- if(!valid)
- continue
-
- testing("Ruin \"[name]\" placed at ([central_turf.x], [central_turf.y], [central_turf.z])")
-
- for(var/i in get_affected_turfs(central_turf, 1))
- var/turf/T = i
- for(var/mob/living/simple_animal/monster in T)
- qdel(monster)
- for(var/obj/structure/flora/ash/plant in T)
- qdel(plant)
-
- load(central_turf,centered = TRUE)
- loaded++
-
- for(var/turf/T in get_affected_turfs(central_turf, 1))
- T.flags_1 |= NO_RUINS_1
-
- new /obj/effect/landmark/ruin(central_turf, src)
- return central_turf
-
-/datum/map_template/ruin/proc/place_on_isolated_level(z)
- var/datum/turf_reservation/reservation = SSmapping.RequestBlockReservation(width, height, z) //Make the new level creation work with different traits.
- if(!reservation)
- return
- var/turf/placement = locate(reservation.bottom_left_coords[1],reservation.bottom_left_coords[2],reservation.bottom_left_coords[3])
- load(placement)
- loaded++
- for(var/turf/T in get_affected_turfs(placement))
- T.flags_1 |= NO_RUINS_1
- var/turf/center = locate(placement.x + round(width/2),placement.y + round(height/2),placement.z)
- new /obj/effect/landmark/ruin(center, src)
- return center
-
-/proc/seedRuins(list/z_levels = null, budget = 0, whitelist = /area/space, list/potentialRuins)
- if(!z_levels || !z_levels.len)
- WARNING("No Z levels provided - Not generating ruins")
- return
-
- for(var/zl in z_levels)
- var/turf/T = locate(1, 1, zl)
- if(!T)
- WARNING("Z level [zl] does not exist - Not generating ruins")
- return
-
- var/list/ruins = potentialRuins.Copy()
-
- var/list/forced_ruins = list() //These go first on the z level associated (same random one by default) or if the assoc value is a turf to the specified turf.
- var/list/ruins_availible = list() //we can try these in the current pass
-
- //Set up the starting ruin list
- for(var/key in ruins)
- var/datum/map_template/ruin/R = ruins[key]
- if(R.cost > budget) //Why would you do that
- continue
- if(R.always_place)
- forced_ruins[R] = -1
- if(R.unpickable)
- continue
- ruins_availible[R] = R.placement_weight
-
- while(budget > 0 && (ruins_availible.len || forced_ruins.len))
- var/datum/map_template/ruin/current_pick
- var/forced = FALSE
- var/forced_z //If set we won't pick z level and use this one instead.
- var/forced_turf //If set we place the ruin centered on the given turf
- if(forced_ruins.len) //We have something we need to load right now, so just pick it
- for(var/ruin in forced_ruins)
- current_pick = ruin
- if(isturf(forced_ruins[ruin]))
- var/turf/T = forced_ruins[ruin]
- forced_z = T.z //In case of chained ruins
- forced_turf = T
- else if(forced_ruins[ruin] > 0) //Load into designated z
- forced_z = forced_ruins[ruin]
- forced = TRUE
- break
- else //Otherwise just pick random one
- current_pick = pickweight(ruins_availible)
-
- var/placement_tries = forced_turf ? 1 : PLACEMENT_TRIES //Only try once if we target specific turf
- var/failed_to_place = TRUE
- var/target_z = 0
- var/turf/placed_turf //Where the ruin ended up if we succeeded
- outer:
- while(placement_tries > 0)
- placement_tries--
- target_z = pick(z_levels)
- if(forced_z)
- target_z = forced_z
- if(current_pick.always_spawn_with) //If the ruin has part below, make sure that z exists.
- for(var/v in current_pick.always_spawn_with)
- if(current_pick.always_spawn_with[v] == PLACE_BELOW)
- var/turf/T = locate(1,1,target_z)
- if(!SSmapping.get_turf_below(T))
- if(forced_z)
- continue outer
- else
- break outer
-
- placed_turf = current_pick.try_to_place(target_z,whitelist,forced_turf)
- if(!placed_turf)
- continue
- else
- failed_to_place = FALSE
- break
-
- //That's done remove from priority even if it failed
- if(forced)
- //TODO : handle forced ruins with multiple variants
- forced_ruins -= current_pick
- forced = FALSE
-
- if(failed_to_place)
- for(var/datum/map_template/ruin/R in ruins_availible)
- if(R.id == current_pick.id)
- ruins_availible -= R
- log_world("Failed to place [current_pick.name] ruin.")
- else
- budget -= current_pick.cost
- if(!current_pick.allow_duplicates)
- for(var/datum/map_template/ruin/R in ruins_availible)
- if(R.id == current_pick.id)
- ruins_availible -= R
- if(current_pick.never_spawn_with)
- for(var/blacklisted_type in current_pick.never_spawn_with)
- for(var/possible_exclusion in ruins_availible)
- if(istype(possible_exclusion,blacklisted_type))
- ruins_availible -= possible_exclusion
- if(current_pick.always_spawn_with)
- for(var/v in current_pick.always_spawn_with)
- for(var/ruin_name in SSmapping.ruins_templates) //Because we might want to add space templates as linked of lava templates.
- var/datum/map_template/ruin/linked = SSmapping.ruins_templates[ruin_name] //why are these assoc, very annoying.
- if(istype(linked,v))
- switch(current_pick.always_spawn_with[v])
- if(PLACE_SAME_Z)
- forced_ruins[linked] = target_z //I guess you might want a chain somehow
- if(PLACE_LAVA_RUIN)
- forced_ruins[linked] = pick(SSmapping.levels_by_trait(ZTRAIT_LAVA_RUINS))
- if(PLACE_SPACE_RUIN)
- forced_ruins[linked] = pick(SSmapping.levels_by_trait(ZTRAIT_SPACE_RUINS))
- if(PLACE_DEFAULT)
- forced_ruins[linked] = -1
- if(PLACE_BELOW)
- forced_ruins[linked] = SSmapping.get_turf_below(placed_turf)
- if(PLACE_ISOLATED)
- forced_ruins[linked] = SSmapping.get_isolated_ruin_z()
-
- //Update the availible list
- for(var/datum/map_template/ruin/R in ruins_availible)
- if(R.cost > budget)
- ruins_availible -= R
-
- log_world("Ruin loader finished with [budget] left to spend.")
+/datum/map_template/ruin/proc/try_to_place(z,allowed_areas,turf/forced_turf)
+ var/sanity = forced_turf ? 1 : PLACEMENT_TRIES
+ if(SSmapping.level_trait(z,ZTRAIT_ISOLATED_RUINS))
+ return place_on_isolated_level(z)
+ while(sanity > 0)
+ sanity--
+ var/width_border = TRANSITIONEDGE + SPACERUIN_MAP_EDGE_PAD + round(width / 2)
+ var/height_border = TRANSITIONEDGE + SPACERUIN_MAP_EDGE_PAD + round(height / 2)
+ var/turf/central_turf = forced_turf ? forced_turf : locate(rand(width_border, world.maxx - width_border), rand(height_border, world.maxy - height_border), z)
+ var/valid = TRUE
+
+ for(var/turf/check in get_affected_turfs(central_turf,1))
+ var/area/new_area = get_area(check)
+ if(!(istype(new_area, allowed_areas)) || check.flags_1 & NO_RUINS_1)
+ valid = FALSE
+ break
+
+ if(!valid)
+ continue
+
+ testing("Ruin \"[name]\" placed at ([central_turf.x], [central_turf.y], [central_turf.z])")
+
+ for(var/i in get_affected_turfs(central_turf, 1))
+ var/turf/T = i
+ for(var/mob/living/simple_animal/monster in T)
+ qdel(monster)
+ for(var/obj/structure/flora/ash/plant in T)
+ qdel(plant)
+
+ load(central_turf,centered = TRUE)
+ loaded++
+
+ for(var/turf/T in get_affected_turfs(central_turf, 1))
+ T.flags_1 |= NO_RUINS_1
+
+ new /obj/effect/landmark/ruin(central_turf, src)
+ return central_turf
+
+/datum/map_template/ruin/proc/place_on_isolated_level(z)
+ var/datum/turf_reservation/reservation = SSmapping.RequestBlockReservation(width, height, z) //Make the new level creation work with different traits.
+ if(!reservation)
+ return
+ var/turf/placement = locate(reservation.bottom_left_coords[1],reservation.bottom_left_coords[2],reservation.bottom_left_coords[3])
+ load(placement)
+ loaded++
+ for(var/turf/T in get_affected_turfs(placement))
+ T.flags_1 |= NO_RUINS_1
+ var/turf/center = locate(placement.x + round(width/2),placement.y + round(height/2),placement.z)
+ new /obj/effect/landmark/ruin(center, src)
+ return center
+
+/proc/seedRuins(list/z_levels = null, budget = 0, whitelist = /area/space, list/potentialRuins)
+ if(!z_levels || !z_levels.len)
+ WARNING("No Z levels provided - Not generating ruins")
+ return
+
+ for(var/zl in z_levels)
+ var/turf/T = locate(1, 1, zl)
+ if(!T)
+ WARNING("Z level [zl] does not exist - Not generating ruins")
+ return
+
+ var/list/ruins = potentialRuins.Copy()
+
+ var/list/forced_ruins = list() //These go first on the z level associated (same random one by default) or if the assoc value is a turf to the specified turf.
+ var/list/ruins_availible = list() //we can try these in the current pass
+
+ //Set up the starting ruin list
+ for(var/key in ruins)
+ var/datum/map_template/ruin/R = ruins[key]
+ if(R.cost > budget) //Why would you do that
+ continue
+ if(R.always_place)
+ forced_ruins[R] = -1
+ if(R.unpickable)
+ continue
+ ruins_availible[R] = R.placement_weight
+
+ while(budget > 0 && (ruins_availible.len || forced_ruins.len))
+ var/datum/map_template/ruin/current_pick
+ var/forced = FALSE
+ var/forced_z //If set we won't pick z level and use this one instead.
+ var/forced_turf //If set we place the ruin centered on the given turf
+ if(forced_ruins.len) //We have something we need to load right now, so just pick it
+ for(var/ruin in forced_ruins)
+ current_pick = ruin
+ if(isturf(forced_ruins[ruin]))
+ var/turf/T = forced_ruins[ruin]
+ forced_z = T.z //In case of chained ruins
+ forced_turf = T
+ else if(forced_ruins[ruin] > 0) //Load into designated z
+ forced_z = forced_ruins[ruin]
+ forced = TRUE
+ break
+ else //Otherwise just pick random one
+ current_pick = pickweight(ruins_availible)
+
+ var/placement_tries = forced_turf ? 1 : PLACEMENT_TRIES //Only try once if we target specific turf
+ var/failed_to_place = TRUE
+ var/target_z = 0
+ var/turf/placed_turf //Where the ruin ended up if we succeeded
+ outer:
+ while(placement_tries > 0)
+ placement_tries--
+ target_z = pick(z_levels)
+ if(forced_z)
+ target_z = forced_z
+ if(current_pick.always_spawn_with) //If the ruin has part below, make sure that z exists.
+ for(var/v in current_pick.always_spawn_with)
+ if(current_pick.always_spawn_with[v] == PLACE_BELOW)
+ var/turf/T = locate(1,1,target_z)
+ if(!SSmapping.get_turf_below(T))
+ if(forced_z)
+ continue outer
+ else
+ break outer
+
+ placed_turf = current_pick.try_to_place(target_z,whitelist,forced_turf)
+ if(!placed_turf)
+ continue
+ else
+ failed_to_place = FALSE
+ break
+
+ //That's done remove from priority even if it failed
+ if(forced)
+ //TODO : handle forced ruins with multiple variants
+ forced_ruins -= current_pick
+ forced = FALSE
+
+ if(failed_to_place)
+ for(var/datum/map_template/ruin/R in ruins_availible)
+ if(R.id == current_pick.id)
+ ruins_availible -= R
+ log_world("Failed to place [current_pick.name] ruin.")
+ else
+ budget -= current_pick.cost
+ if(!current_pick.allow_duplicates)
+ for(var/datum/map_template/ruin/R in ruins_availible)
+ if(R.id == current_pick.id)
+ ruins_availible -= R
+ if(current_pick.never_spawn_with)
+ for(var/blacklisted_type in current_pick.never_spawn_with)
+ for(var/possible_exclusion in ruins_availible)
+ if(istype(possible_exclusion,blacklisted_type))
+ ruins_availible -= possible_exclusion
+ if(current_pick.always_spawn_with)
+ for(var/v in current_pick.always_spawn_with)
+ for(var/ruin_name in SSmapping.ruins_templates) //Because we might want to add space templates as linked of lava templates.
+ var/datum/map_template/ruin/linked = SSmapping.ruins_templates[ruin_name] //why are these assoc, very annoying.
+ if(istype(linked,v))
+ switch(current_pick.always_spawn_with[v])
+ if(PLACE_SAME_Z)
+ forced_ruins[linked] = target_z //I guess you might want a chain somehow
+ if(PLACE_LAVA_RUIN)
+ forced_ruins[linked] = pick(SSmapping.levels_by_trait(ZTRAIT_LAVA_RUINS))
+ if(PLACE_SPACE_RUIN)
+ forced_ruins[linked] = pick(SSmapping.levels_by_trait(ZTRAIT_SPACE_RUINS))
+ if(PLACE_DEFAULT)
+ forced_ruins[linked] = -1
+ if(PLACE_BELOW)
+ forced_ruins[linked] = SSmapping.get_turf_below(placed_turf)
+ if(PLACE_ISOLATED)
+ forced_ruins[linked] = SSmapping.get_isolated_ruin_z()
+
+ //Update the availible list
+ for(var/datum/map_template/ruin/R in ruins_availible)
+ if(R.cost > budget)
+ ruins_availible -= R
+
+ log_world("Ruin loader finished with [budget] left to spend.")
diff --git a/code/modules/mapping/space_management/space_reservation.dm b/code/modules/mapping/space_management/space_reservation.dm
index b514796bc5..43fe69d633 100644
--- a/code/modules/mapping/space_management/space_reservation.dm
+++ b/code/modules/mapping/space_management/space_reservation.dm
@@ -1,85 +1,85 @@
-
-//Yes, they can only be rectangular.
-//Yes, I'm sorry.
-/datum/turf_reservation
- var/list/reserved_turfs = list()
- var/width = 0
- var/height = 0
- var/bottom_left_coords[3]
- var/top_right_coords[3]
- var/wipe_reservation_on_release = TRUE
- var/turf_type = /turf/open/space
- var/borderturf
-
-/datum/turf_reservation/transit
- turf_type = /turf/open/space/transit
- borderturf = /turf/open/space/transit/border
-
-/datum/turf_reservation/proc/Release()
- var/v = reserved_turfs.Copy()
- for(var/i in reserved_turfs)
- reserved_turfs -= i
- SSmapping.used_turfs -= i
- SSmapping.reserve_turfs(v)
-
-/datum/turf_reservation/transit/Release()
- for(var/turf/open/space/transit/T in reserved_turfs)
- for(var/atom/movable/AM in T)
- T.throw_atom(AM)
- . = ..()
-
-/datum/turf_reservation/proc/Reserve(width, height, zlevel)
- if(width > world.maxx || height > world.maxy || width < 1 || height < 1)
- return FALSE
- var/list/avail = SSmapping.unused_turfs["[zlevel]"]
- var/turf/BL
- var/turf/TR
- var/list/turf/final = list()
- var/passing = FALSE
- for(var/i in avail)
- CHECK_TICK
- BL = i
- if(!(BL.flags_1 & UNUSED_RESERVATION_TURF_1))
- continue
- if(BL.x + width > world.maxx || BL.y + height > world.maxy)
- continue
- TR = locate(BL.x + width - 1, BL.y + height - 1, BL.z)
- if(!(TR.flags_1 & UNUSED_RESERVATION_TURF_1))
- continue
- final = block(BL, TR)
- if(!final)
- continue
- passing = TRUE
- for(var/I in final)
- var/turf/checking = I
- if(!(checking.flags_1 & UNUSED_RESERVATION_TURF_1))
- passing = FALSE
- break
- if(!passing)
- continue
- break
- if(!passing || !istype(BL) || !istype(TR))
- return FALSE
- bottom_left_coords = list(BL.x, BL.y, BL.z)
- top_right_coords = list(TR.x, TR.y, TR.z)
- for(var/i in final)
- var/turf/T = i
- reserved_turfs |= T
- T.flags_1 &= ~UNUSED_RESERVATION_TURF_1
- SSmapping.unused_turfs["[T.z]"] -= T
- SSmapping.used_turfs[T] = src
- if(borderturf && (T.x == BL.x || T.x == TR.x || T.y == BL.y || T.y == TR.y))
- T.ChangeTurf(borderturf, borderturf)
- else
- T.ChangeTurf(turf_type, turf_type)
- src.width = width
- src.height = height
- return TRUE
-
-/datum/turf_reservation/New()
- LAZYADD(SSmapping.turf_reservations, src)
-
-/datum/turf_reservation/Destroy()
- Release()
- LAZYREMOVE(SSmapping.turf_reservations, src)
- return ..()
+
+//Yes, they can only be rectangular.
+//Yes, I'm sorry.
+/datum/turf_reservation
+ var/list/reserved_turfs = list()
+ var/width = 0
+ var/height = 0
+ var/bottom_left_coords[3]
+ var/top_right_coords[3]
+ var/wipe_reservation_on_release = TRUE
+ var/turf_type = /turf/open/space
+ var/borderturf
+
+/datum/turf_reservation/transit
+ turf_type = /turf/open/space/transit
+ borderturf = /turf/open/space/transit/border
+
+/datum/turf_reservation/proc/Release()
+ var/v = reserved_turfs.Copy()
+ for(var/i in reserved_turfs)
+ reserved_turfs -= i
+ SSmapping.used_turfs -= i
+ SSmapping.reserve_turfs(v)
+
+/datum/turf_reservation/transit/Release()
+ for(var/turf/open/space/transit/T in reserved_turfs)
+ for(var/atom/movable/AM in T)
+ T.throw_atom(AM)
+ . = ..()
+
+/datum/turf_reservation/proc/Reserve(width, height, zlevel)
+ if(width > world.maxx || height > world.maxy || width < 1 || height < 1)
+ return FALSE
+ var/list/avail = SSmapping.unused_turfs["[zlevel]"]
+ var/turf/BL
+ var/turf/TR
+ var/list/turf/final = list()
+ var/passing = FALSE
+ for(var/i in avail)
+ CHECK_TICK
+ BL = i
+ if(!(BL.flags_1 & UNUSED_RESERVATION_TURF_1))
+ continue
+ if(BL.x + width > world.maxx || BL.y + height > world.maxy)
+ continue
+ TR = locate(BL.x + width - 1, BL.y + height - 1, BL.z)
+ if(!(TR.flags_1 & UNUSED_RESERVATION_TURF_1))
+ continue
+ final = block(BL, TR)
+ if(!final)
+ continue
+ passing = TRUE
+ for(var/I in final)
+ var/turf/checking = I
+ if(!(checking.flags_1 & UNUSED_RESERVATION_TURF_1))
+ passing = FALSE
+ break
+ if(!passing)
+ continue
+ break
+ if(!passing || !istype(BL) || !istype(TR))
+ return FALSE
+ bottom_left_coords = list(BL.x, BL.y, BL.z)
+ top_right_coords = list(TR.x, TR.y, TR.z)
+ for(var/i in final)
+ var/turf/T = i
+ reserved_turfs |= T
+ T.flags_1 &= ~UNUSED_RESERVATION_TURF_1
+ SSmapping.unused_turfs["[T.z]"] -= T
+ SSmapping.used_turfs[T] = src
+ if(borderturf && (T.x == BL.x || T.x == TR.x || T.y == BL.y || T.y == TR.y))
+ T.ChangeTurf(borderturf, borderturf)
+ else
+ T.ChangeTurf(turf_type, turf_type)
+ src.width = width
+ src.height = height
+ return TRUE
+
+/datum/turf_reservation/New()
+ LAZYADD(SSmapping.turf_reservations, src)
+
+/datum/turf_reservation/Destroy()
+ Release()
+ LAZYREMOVE(SSmapping.turf_reservations, src)
+ return ..()
diff --git a/icons/effects/mapping_helpers.dmi b/icons/effects/mapping_helpers.dmi
index dec83046b9..037c1aa660 100644
Binary files a/icons/effects/mapping_helpers.dmi and b/icons/effects/mapping_helpers.dmi differ
diff --git a/tgstation.dme b/tgstation.dme
index 994c6af817..36bc39d902 100755
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -800,11 +800,11 @@
#include "code\game\objects\effects\decals\decal.dm"
#include "code\game\objects\effects\decals\misc.dm"
#include "code\game\objects\effects\decals\remains.dm"
-#include "code\game\objects\effects\decals\cleanable\aliens.dm"
-#include "code\game\objects\effects\decals\cleanable\gibs.dm"
-#include "code\game\objects\effects\decals\cleanable\humans.dm"
-#include "code\game\objects\effects\decals\cleanable\misc.dm"
-#include "code\game\objects\effects\decals\cleanable\robots.dm"
+#include "code\game\objects\effects\decals\Cleanable\aliens.dm"
+#include "code\game\objects\effects\decals\Cleanable\gibs.dm"
+#include "code\game\objects\effects\decals\Cleanable\humans.dm"
+#include "code\game\objects\effects\decals\Cleanable\misc.dm"
+#include "code\game\objects\effects\decals\Cleanable\robots.dm"
#include "code\game\objects\effects\decals\turfdecal\dirt.dm"
#include "code\game\objects\effects\decals\turfdecal\markings.dm"
#include "code\game\objects\effects\decals\turfdecal\tilecoloring.dm"
@@ -2010,11 +2010,15 @@
#include "code\modules\lighting\lighting_turf.dm"
#include "code\modules\mapping\dmm_suite.dm"
#include "code\modules\mapping\map_template.dm"
-#include "code\modules\mapping\mapping_helpers.dm"
#include "code\modules\mapping\preloader.dm"
#include "code\modules\mapping\reader.dm"
#include "code\modules\mapping\ruins.dm"
#include "code\modules\mapping\verify.dm"
+#include "code\modules\mapping\mapping_helpers\_mapping_helpers.dm"
+#include "code\modules\mapping\mapping_helpers\baseturf.dm"
+#include "code\modules\mapping\mapping_helpers\network_builder\_network_builder.dm"
+#include "code\modules\mapping\mapping_helpers\network_builder\atmos_pipe.dm"
+#include "code\modules\mapping\mapping_helpers\network_builder\power_cables.dm"
#include "code\modules\mapping\space_management\multiz_helpers.dm"
#include "code\modules\mapping\space_management\space_level.dm"
#include "code\modules\mapping\space_management\space_reservation.dm"