mirror of
https://github.com/KabKebab/GS13.git
synced 2026-07-18 03:21:30 +01:00
Uploading all files.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
The code in this module originally evolved from dmm_suite and has since been
|
||||
specialized for SS13 and otherwise tweaked to fit /tg/station's needs.
|
||||
|
||||
dmm_suite version 1.0
|
||||
Released January 30th, 2011.
|
||||
|
||||
NOTE: Map saving functionality removed
|
||||
|
||||
defines the object /dmm_suite
|
||||
- Provides the proc load_map()
|
||||
- Loads the specified map file onto the specified z-level.
|
||||
- provides the proc write_map()
|
||||
- Returns a text string of the map in dmm format
|
||||
ready for output to a file.
|
||||
- provides the proc save_map()
|
||||
- Returns a .dmm file if map is saved
|
||||
- Returns FALSE if map fails to save
|
||||
|
||||
The dmm_suite provides saving and loading of map files in BYOND's native DMM map
|
||||
format. It approximates the map saving and loading processes of the Dream Maker
|
||||
and Dream Seeker programs so as to allow editing, saving, and loading of maps at
|
||||
runtime.
|
||||
|
||||
------------------------
|
||||
|
||||
To save a map at runtime, create an instance of /dmm_suite, and then call
|
||||
write_map(), which accepts three arguments:
|
||||
- A turf representing one corner of a three dimensional grid (Required).
|
||||
- Another turf representing the other corner of the same grid (Required).
|
||||
- Any, or a combination, of several bit flags (Optional, see documentation).
|
||||
|
||||
The order in which the turfs are supplied does not matter, the /dmm_writer will
|
||||
determine the grid containing both, in much the same way as DM's block() function.
|
||||
write_map() will then return a string representing the saved map in dmm format;
|
||||
this string can then be saved to a file, or used for any other purose.
|
||||
|
||||
------------------------
|
||||
|
||||
To load a map at runtime, create an instance of /dmm_suite, and then call load_map(),
|
||||
which accepts two arguments:
|
||||
- A .dmm file to load (Required).
|
||||
- A number representing the z-level on which to start loading the map (Optional).
|
||||
|
||||
The /dmm_suite will load the map file starting on the specified z-level. If no
|
||||
z-level was specified, world.maxz will be increased so as to fit the map. Note
|
||||
that if you wish to load a map onto a z-level that already has objects on it,
|
||||
you will have to handle the removal of those objects. Otherwise the new map will
|
||||
simply load the new objects on top of the old ones.
|
||||
|
||||
Also note that all type paths specified in the .dmm file must exist in the world's
|
||||
code, and that the /dmm_reader trusts that files to be loaded are in fact valid
|
||||
.dmm files. Errors in the .dmm format will cause runtime errors.
|
||||
@@ -0,0 +1,63 @@
|
||||
dmm_suite{
|
||||
/*
|
||||
|
||||
dmm_suite version 1.0
|
||||
Released January 30th, 2011.
|
||||
|
||||
NOTE: Map saving functionality removed
|
||||
|
||||
defines the object /dmm_suite
|
||||
- Provides the proc load_map()
|
||||
- Loads the specified map file onto the specified z-level.
|
||||
- provides the proc write_map()
|
||||
- Returns a text string of the map in dmm format
|
||||
ready for output to a file.
|
||||
- provides the proc save_map()
|
||||
- Returns a .dmm file if map is saved
|
||||
- Returns FALSE if map fails to save
|
||||
|
||||
The dmm_suite provides saving and loading of map files in BYOND's native DMM map
|
||||
format. It approximates the map saving and loading processes of the Dream Maker
|
||||
and Dream Seeker programs so as to allow editing, saving, and loading of maps at
|
||||
runtime.
|
||||
|
||||
------------------------
|
||||
|
||||
To save a map at runtime, create an instance of /dmm_suite, and then call
|
||||
write_map(), which accepts three arguments:
|
||||
- A turf representing one corner of a three dimensional grid (Required).
|
||||
- Another turf representing the other corner of the same grid (Required).
|
||||
- Any, or a combination, of several bit flags (Optional, see documentation).
|
||||
|
||||
The order in which the turfs are supplied does not matter, the /dmm_writer will
|
||||
determine the grid containing both, in much the same way as DM's block() function.
|
||||
write_map() will then return a string representing the saved map in dmm format;
|
||||
this string can then be saved to a file, or used for any other purose.
|
||||
|
||||
------------------------
|
||||
|
||||
To load a map at runtime, create an instance of /dmm_suite, and then call load_map(),
|
||||
which accepts two arguments:
|
||||
- A .dmm file to load (Required).
|
||||
- A number representing the z-level on which to start loading the map (Optional).
|
||||
|
||||
The /dmm_suite will load the map file starting on the specified z-level. If no
|
||||
z-level was specified, world.maxz will be increased so as to fit the map. Note
|
||||
that if you wish to load a map onto a z-level that already has objects on it,
|
||||
you will have to handle the removal of those objects. Otherwise the new map will
|
||||
simply load the new objects on top of the old ones.
|
||||
|
||||
Also note that all type paths specified in the .dmm file must exist in the world's
|
||||
code, and that the /dmm_reader trusts that files to be loaded are in fact valid
|
||||
.dmm files. Errors in the .dmm format will cause runtime errors.
|
||||
|
||||
*/
|
||||
|
||||
verb/load_map(var/dmm_file as file, var/x_offset as num, var/y_offset as num, var/z_offset as num, var/cropMap as num, var/measureOnly as num, no_changeturf as num){
|
||||
// dmm_file: A .dmm file to load (Required).
|
||||
// z_offset: A number representing the z-level on which to start loading the map (Optional).
|
||||
// cropMap: When true, the map will be cropped to fit the existing world dimensions (Optional).
|
||||
// measureOnly: When true, no changes will be made to the world (Optional).
|
||||
// no_changeturf: When true, turf/AfterChange won't be called on loaded turfs
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/datum/map_template
|
||||
var/name = "Default Template Name"
|
||||
var/width = 0
|
||||
var/height = 0
|
||||
var/mappath = null
|
||||
var/loaded = 0 // Times loaded this round
|
||||
var/datum/parsed_map/cached_map
|
||||
var/keep_cached_map = FALSE
|
||||
|
||||
/datum/map_template/New(path = null, rename = null, cache = FALSE)
|
||||
if(path)
|
||||
mappath = path
|
||||
if(mappath)
|
||||
preload_size(mappath, cache)
|
||||
if(rename)
|
||||
name = rename
|
||||
|
||||
/datum/map_template/proc/preload_size(path, cache = FALSE)
|
||||
var/datum/parsed_map/parsed = new(file(path))
|
||||
var/bounds = parsed?.bounds
|
||||
if(bounds)
|
||||
width = bounds[MAP_MAXX] // Assumes all templates are rectangular, have a single Z level, and begin at 1,1,1
|
||||
height = bounds[MAP_MAXY]
|
||||
if(cache)
|
||||
cached_map = parsed
|
||||
return bounds
|
||||
|
||||
/datum/parsed_map/proc/initTemplateBounds()
|
||||
var/list/obj/machinery/atmospherics/atmos_machines = list()
|
||||
var/list/obj/structure/cable/cables = list()
|
||||
var/list/atom/atoms = list()
|
||||
var/list/area/areas = list()
|
||||
|
||||
var/list/turfs = block( locate(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ]),
|
||||
locate(bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ]))
|
||||
var/list/border = block(locate(max(bounds[MAP_MINX]-1, 1), max(bounds[MAP_MINY]-1, 1), bounds[MAP_MINZ]),
|
||||
locate(min(bounds[MAP_MAXX]+1, world.maxx), min(bounds[MAP_MAXY]+1, world.maxy), bounds[MAP_MAXZ])) - turfs
|
||||
for(var/L in turfs)
|
||||
var/turf/B = L
|
||||
atoms += B
|
||||
areas |= B.loc
|
||||
for(var/A in B)
|
||||
atoms += A
|
||||
if(istype(A, /obj/structure/cable))
|
||||
cables += A
|
||||
continue
|
||||
if(istype(A, /obj/machinery/atmospherics))
|
||||
atmos_machines += A
|
||||
for(var/L in border)
|
||||
var/turf/T = L
|
||||
T.air_update_turf(TRUE) //calculate adjacent turfs along the border to prevent runtimes
|
||||
|
||||
SSmapping.reg_in_areas_in_z(areas)
|
||||
SSatoms.InitializeAtoms(atoms)
|
||||
SSmachines.setup_template_powernets(cables)
|
||||
SSair.setup_template_machinery(atmos_machines)
|
||||
|
||||
/datum/map_template/proc/load_new_z()
|
||||
var/x = round((world.maxx - width)/2)
|
||||
var/y = round((world.maxy - height)/2)
|
||||
|
||||
var/datum/space_level/level = SSmapping.add_new_zlevel(name, list(ZTRAIT_AWAY = TRUE))
|
||||
var/datum/parsed_map/parsed = load_map(file(mappath), x, y, level.z_value, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS), placeOnTop=TRUE)
|
||||
var/list/bounds = parsed.bounds
|
||||
if(!bounds)
|
||||
return FALSE
|
||||
|
||||
repopulate_sorted_areas()
|
||||
|
||||
//initialize things that are normally initialized after map load
|
||||
parsed.initTemplateBounds()
|
||||
smooth_zlevel(world.maxz)
|
||||
log_game("Z-level [name] loaded at at [x],[y],[world.maxz]")
|
||||
|
||||
return level
|
||||
|
||||
/datum/map_template/proc/load(turf/T, centered = FALSE)
|
||||
if(centered)
|
||||
T = locate(T.x - round(width/2) , T.y - round(height/2) , T.z)
|
||||
if(!T)
|
||||
return
|
||||
if(T.x+width > world.maxx)
|
||||
return
|
||||
if(T.y+height > world.maxy)
|
||||
return
|
||||
|
||||
// Accept cached maps, but don't save them automatically - we don't want
|
||||
// ruins clogging up memory for the whole round.
|
||||
var/datum/parsed_map/parsed = cached_map || new(file(mappath))
|
||||
cached_map = keep_cached_map ? parsed : null
|
||||
if(!parsed.load(T.x, T.y, T.z, cropMap=TRUE, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS), placeOnTop=TRUE))
|
||||
return
|
||||
var/list/bounds = parsed.bounds
|
||||
if(!bounds)
|
||||
return
|
||||
|
||||
if(!SSmapping.loading_ruins) //Will be done manually during mapping ss init
|
||||
repopulate_sorted_areas()
|
||||
|
||||
//initialize things that are normally initialized after map load
|
||||
parsed.initTemplateBounds()
|
||||
|
||||
log_game("[name] loaded at at [T.x],[T.y],[T.z]")
|
||||
return bounds
|
||||
|
||||
/datum/map_template/proc/get_affected_turfs(turf/T, centered = FALSE)
|
||||
var/turf/placement = T
|
||||
if(centered)
|
||||
var/turf/corner = locate(placement.x - round(width/2), placement.y - round(height/2), placement.z)
|
||||
if(corner)
|
||||
placement = corner
|
||||
return block(placement, locate(placement.x+width-1, placement.y+height-1, placement.z))
|
||||
|
||||
|
||||
//for your ever biggening badminnery kevinz000
|
||||
//❤ - Cyberboss
|
||||
/proc/load_new_z_level(var/file, var/name)
|
||||
var/datum/map_template/template = new(file, name)
|
||||
template.load_new_z()
|
||||
@@ -0,0 +1,216 @@
|
||||
//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(/turf/open/space)
|
||||
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)
|
||||
return
|
||||
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 = ""
|
||||
var/late = FALSE
|
||||
|
||||
/obj/effect/mapping_helpers/Initialize()
|
||||
..()
|
||||
return late ? INITIALIZE_HINT_LATELOAD : INITIALIZE_HINT_QDEL
|
||||
|
||||
|
||||
//airlock helpers
|
||||
/obj/effect/mapping_helpers/airlock
|
||||
layer = DOOR_HELPER_LAYER
|
||||
|
||||
/obj/effect/mapping_helpers/airlock/cyclelink_helper
|
||||
name = "airlock cyclelink helper"
|
||||
icon_state = "airlock_cyclelink_helper"
|
||||
|
||||
/obj/effect/mapping_helpers/airlock/cyclelink_helper/Initialize(mapload)
|
||||
. = ..()
|
||||
if(!mapload)
|
||||
log_world("### MAP WARNING, [src] spawned outside of mapload!")
|
||||
return
|
||||
var/obj/machinery/door/airlock/airlock = locate(/obj/machinery/door/airlock) in loc
|
||||
if(airlock)
|
||||
if(airlock.cyclelinkeddir)
|
||||
log_world("### MAP WARNING, [src] at [AREACOORD(src)] tried to set [airlock] cyclelinkeddir, but it's already set!")
|
||||
else
|
||||
airlock.cyclelinkeddir = dir
|
||||
else
|
||||
log_world("### MAP WARNING, [src] failed to find an airlock at [AREACOORD(src)]")
|
||||
|
||||
|
||||
/obj/effect/mapping_helpers/airlock/locked
|
||||
name = "airlock lock helper"
|
||||
icon_state = "airlock_locked_helper"
|
||||
|
||||
/obj/effect/mapping_helpers/airlock/locked/Initialize(mapload)
|
||||
. = ..()
|
||||
if(!mapload)
|
||||
log_world("### MAP WARNING, [src] spawned outside of mapload!")
|
||||
return
|
||||
var/obj/machinery/door/airlock/airlock = locate(/obj/machinery/door/airlock) in loc
|
||||
if(airlock)
|
||||
if(airlock.locked)
|
||||
log_world("### MAP WARNING, [src] at [AREACOORD(src)] tried to bolt [airlock] but it's already locked!")
|
||||
else
|
||||
airlock.locked = TRUE
|
||||
else
|
||||
log_world("### MAP WARNING, [src] failed to find an airlock at [AREACOORD(src)]")
|
||||
|
||||
/obj/effect/mapping_helpers/airlock/unres
|
||||
name = "airlock unresctricted side helper"
|
||||
icon_state = "airlock_unres_helper"
|
||||
|
||||
/obj/effect/mapping_helpers/airlock/unres/Initialize(mapload)
|
||||
. = ..()
|
||||
if(!mapload)
|
||||
log_world("### MAP WARNING, [src] spawned outside of mapload!")
|
||||
return
|
||||
var/obj/machinery/door/airlock/airlock = locate(/obj/machinery/door/airlock) in loc
|
||||
if(airlock)
|
||||
airlock.unres_sides ^= dir
|
||||
else
|
||||
log_world("### MAP WARNING, [src] failed to find an airlock at [AREACOORD(src)]")
|
||||
|
||||
|
||||
//needs to do its thing before spawn_rivers() is called
|
||||
INITIALIZE_IMMEDIATE(/obj/effect/mapping_helpers/no_lava)
|
||||
|
||||
/obj/effect/mapping_helpers/no_lava
|
||||
icon_state = "no_lava"
|
||||
|
||||
/obj/effect/mapping_helpers/no_lava/Initialize()
|
||||
. = ..()
|
||||
var/turf/T = get_turf(src)
|
||||
T.flags_1 |= NO_LAVA_GEN_1
|
||||
|
||||
/// Adds the map it is on to the z_is_planet list
|
||||
/obj/effect/mapping_helpers/planet_z
|
||||
name = "planet z helper"
|
||||
layer = POINT_LAYER
|
||||
|
||||
/obj/effect/mapping_helpers/planet_z/Initialize()
|
||||
. = ..()
|
||||
var/datum/space_level/S = SSmapping.get_level(z)
|
||||
S.traits[ZTRAIT_PLANET] = TRUE
|
||||
|
||||
|
||||
//This helper applies components to things on the map directly.
|
||||
/obj/effect/mapping_helpers/component_injector
|
||||
name = "Component Injector"
|
||||
late = TRUE
|
||||
var/target_type
|
||||
var/target_name
|
||||
var/component_type
|
||||
|
||||
//Late init so everything is likely ready and loaded (no warranty)
|
||||
/obj/effect/mapping_helpers/component_injector/LateInitialize()
|
||||
if(!ispath(component_type,/datum/component))
|
||||
CRASH("Wrong component type in [type] - [component_type] is not a component")
|
||||
var/turf/T = get_turf(src)
|
||||
for(var/atom/A in T.GetAllContents())
|
||||
if(A == src)
|
||||
continue
|
||||
if(target_name && A.name != target_name)
|
||||
continue
|
||||
if(target_type && !istype(A,target_type))
|
||||
continue
|
||||
var/cargs = build_args()
|
||||
A.AddComponent(arglist(cargs))
|
||||
qdel(src)
|
||||
return
|
||||
|
||||
/obj/effect/mapping_helpers/component_injector/proc/build_args()
|
||||
return list(component_type)
|
||||
|
||||
/obj/effect/mapping_helpers/component_injector/infective
|
||||
name = "Infective Injector"
|
||||
icon_state = "component_infective"
|
||||
component_type = /datum/component/infective
|
||||
var/disease_type
|
||||
|
||||
/obj/effect/mapping_helpers/component_injector/infective/build_args()
|
||||
if(!ispath(disease_type,/datum/disease))
|
||||
CRASH("Wrong disease type passed in.")
|
||||
var/datum/disease/D = new disease_type()
|
||||
return list(component_type,D)
|
||||
@@ -0,0 +1,31 @@
|
||||
// global datum that will preload variables on atoms instanciation
|
||||
GLOBAL_VAR_INIT(use_preloader, FALSE)
|
||||
GLOBAL_DATUM_INIT(_preloader, /datum/map_preloader, new)
|
||||
|
||||
/// Preloader datum
|
||||
/datum/map_preloader
|
||||
parent_type = /datum
|
||||
var/list/attributes
|
||||
var/target_path
|
||||
|
||||
/datum/map_preloader/proc/setup(list/the_attributes, path)
|
||||
if(the_attributes.len)
|
||||
GLOB.use_preloader = TRUE
|
||||
attributes = the_attributes
|
||||
target_path = path
|
||||
|
||||
/datum/map_preloader/proc/load(atom/what)
|
||||
GLOB.use_preloader = FALSE
|
||||
for(var/attribute in attributes)
|
||||
var/value = attributes[attribute]
|
||||
if(islist(value))
|
||||
value = deepCopyList(value)
|
||||
what.vars[attribute] = value
|
||||
|
||||
/area/template_noop
|
||||
name = "Area Passthrough"
|
||||
|
||||
/turf/template_noop
|
||||
name = "Turf Passthrough"
|
||||
icon_state = "noop"
|
||||
bullet_bounce_sound = null
|
||||
@@ -0,0 +1,474 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
//SS13 Optimized Map loader
|
||||
//////////////////////////////////////////////////////////////
|
||||
#define SPACE_KEY "space"
|
||||
|
||||
/datum/grid_set
|
||||
var/xcrd
|
||||
var/ycrd
|
||||
var/zcrd
|
||||
var/gridLines
|
||||
|
||||
/datum/parsed_map
|
||||
var/original_path
|
||||
var/key_len = 0
|
||||
var/list/grid_models = list()
|
||||
var/list/gridSets = list()
|
||||
|
||||
var/list/modelCache
|
||||
|
||||
/// Unoffset bounds. Null on parse failure.
|
||||
var/list/parsed_bounds
|
||||
/// Offset bounds. Same as parsed_bounds until load().
|
||||
var/list/bounds
|
||||
|
||||
// raw strings used to represent regexes more accurately
|
||||
// '' used to avoid confusing syntax highlighting
|
||||
var/static/regex/dmmRegex = new(@'"([a-zA-Z]+)" = \(((?:.|\n)*?)\)\n(?!\t)|\((\d+),(\d+),(\d+)\) = \{"([a-zA-Z\n]*)"\}', "g")
|
||||
var/static/regex/trimQuotesRegex = new(@'^[\s\n]+"?|"?[\s\n]+$|^"|"$', "g")
|
||||
var/static/regex/trimRegex = new(@'^[\s\n]+|[\s\n]+$', "g")
|
||||
|
||||
#ifdef TESTING
|
||||
var/turfsSkipped = 0
|
||||
#endif
|
||||
|
||||
/// Shortcut function to parse a map and apply it to the world.
|
||||
///
|
||||
/// - `dmm_file`: A .dmm file to load (Required).
|
||||
/// - `x_offset`, `y_offset`, `z_offset`: Positions representign where to load the map (Optional).
|
||||
/// - `cropMap`: When true, the map will be cropped to fit the existing world dimensions (Optional).
|
||||
/// - `measureOnly`: When true, no changes will be made to the world (Optional).
|
||||
/// - `no_changeturf`: When true, [turf/AfterChange] won't be called on loaded turfs
|
||||
/// - `x_lower`, `x_upper`, `y_lower`, `y_upper`: Coordinates (relative to the map) to crop to (Optional).
|
||||
/// - `placeOnTop`: Whether to use [turf/PlaceOnTop] rather than [turf/ChangeTurf] (Optional).
|
||||
/proc/load_map(dmm_file as file, x_offset as num, y_offset as num, z_offset as num, cropMap as num, measureOnly as num, no_changeturf as num, x_lower = -INFINITY as num, x_upper = INFINITY as num, y_lower = -INFINITY as num, y_upper = INFINITY as num, placeOnTop = FALSE as num)
|
||||
var/datum/parsed_map/parsed = new(dmm_file, x_lower, x_upper, y_lower, y_upper, measureOnly)
|
||||
if(parsed.bounds && !measureOnly)
|
||||
parsed.load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop)
|
||||
return parsed
|
||||
|
||||
/// Parse a map, possibly cropping it.
|
||||
/datum/parsed_map/New(tfile, x_lower = -INFINITY, x_upper = INFINITY, y_lower = -INFINITY, y_upper=INFINITY, measureOnly=FALSE)
|
||||
if(isfile(tfile))
|
||||
original_path = "[tfile]"
|
||||
tfile = file2text(tfile)
|
||||
else if(isnull(tfile))
|
||||
// create a new datum without loading a map
|
||||
return
|
||||
|
||||
bounds = parsed_bounds = list(1.#INF, 1.#INF, 1.#INF, -1.#INF, -1.#INF, -1.#INF)
|
||||
var/stored_index = 1
|
||||
|
||||
//multiz lool
|
||||
while(dmmRegex.Find(tfile, stored_index))
|
||||
stored_index = dmmRegex.next
|
||||
|
||||
// "aa" = (/type{vars=blah})
|
||||
if(dmmRegex.group[1]) // Model
|
||||
var/key = dmmRegex.group[1]
|
||||
if(grid_models[key]) // Duplicate model keys are ignored in DMMs
|
||||
continue
|
||||
if(key_len != length(key))
|
||||
if(!key_len)
|
||||
key_len = length(key)
|
||||
else
|
||||
CRASH("Inconsistent key length in DMM")
|
||||
if(!measureOnly)
|
||||
grid_models[key] = dmmRegex.group[2]
|
||||
|
||||
// (1,1,1) = {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
|
||||
else if(dmmRegex.group[3]) // Coords
|
||||
if(!key_len)
|
||||
CRASH("Coords before model definition in DMM")
|
||||
|
||||
var/curr_x = text2num(dmmRegex.group[3])
|
||||
|
||||
if(curr_x < x_lower || curr_x > x_upper)
|
||||
continue
|
||||
|
||||
var/datum/grid_set/gridSet = new
|
||||
|
||||
gridSet.xcrd = curr_x
|
||||
//position of the currently processed square
|
||||
gridSet.ycrd = text2num(dmmRegex.group[4])
|
||||
gridSet.zcrd = text2num(dmmRegex.group[5])
|
||||
|
||||
bounds[MAP_MINX] = min(bounds[MAP_MINX], CLAMP(gridSet.xcrd, x_lower, x_upper))
|
||||
bounds[MAP_MINZ] = min(bounds[MAP_MINZ], gridSet.zcrd)
|
||||
bounds[MAP_MAXZ] = max(bounds[MAP_MAXZ], gridSet.zcrd)
|
||||
|
||||
var/list/gridLines = splittext(dmmRegex.group[6], "\n")
|
||||
gridSet.gridLines = gridLines
|
||||
|
||||
var/leadingBlanks = 0
|
||||
while(leadingBlanks < gridLines.len && gridLines[++leadingBlanks] == "")
|
||||
if(leadingBlanks > 1)
|
||||
gridLines.Cut(1, leadingBlanks) // Remove all leading blank lines.
|
||||
|
||||
if(!gridLines.len) // Skip it if only blank lines exist.
|
||||
continue
|
||||
|
||||
gridSets += gridSet
|
||||
|
||||
if(gridLines.len && gridLines[gridLines.len] == "")
|
||||
gridLines.Cut(gridLines.len) // Remove only one blank line at the end.
|
||||
|
||||
bounds[MAP_MINY] = min(bounds[MAP_MINY], CLAMP(gridSet.ycrd, y_lower, y_upper))
|
||||
gridSet.ycrd += gridLines.len - 1 // Start at the top and work down
|
||||
bounds[MAP_MAXY] = max(bounds[MAP_MAXY], CLAMP(gridSet.ycrd, y_lower, y_upper))
|
||||
|
||||
var/maxx = gridSet.xcrd
|
||||
if(gridLines.len) //Not an empty map
|
||||
maxx = max(maxx, gridSet.xcrd + length(gridLines[1]) / key_len - 1)
|
||||
|
||||
bounds[MAP_MAXX] = CLAMP(max(bounds[MAP_MAXX], maxx), x_lower, x_upper)
|
||||
CHECK_TICK
|
||||
|
||||
// Indicate failure to parse any coordinates by nulling bounds
|
||||
if(bounds[1] == 1.#INF)
|
||||
bounds = null
|
||||
parsed_bounds = bounds
|
||||
|
||||
/// Load the parsed map into the world. See [/proc/load_map] for arguments.
|
||||
/datum/parsed_map/proc/load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop)
|
||||
//How I wish for RAII
|
||||
Master.StartLoadingMap()
|
||||
. = _load_impl(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop)
|
||||
Master.StopLoadingMap()
|
||||
|
||||
// Do not call except via load() above.
|
||||
/datum/parsed_map/proc/_load_impl(x_offset = 1, y_offset = 1, z_offset = world.maxz + 1, cropMap = FALSE, no_changeturf = FALSE, x_lower = -INFINITY, x_upper = INFINITY, y_lower = -INFINITY, y_upper = INFINITY, placeOnTop = FALSE)
|
||||
var/list/areaCache = list()
|
||||
var/list/modelCache = build_cache(no_changeturf)
|
||||
var/space_key = modelCache[SPACE_KEY]
|
||||
var/list/bounds
|
||||
src.bounds = bounds = list(1.#INF, 1.#INF, 1.#INF, -1.#INF, -1.#INF, -1.#INF)
|
||||
|
||||
for(var/I in gridSets)
|
||||
var/datum/grid_set/gset = I
|
||||
var/ycrd = gset.ycrd + y_offset - 1
|
||||
var/zcrd = gset.zcrd + z_offset - 1
|
||||
if(!cropMap && ycrd > world.maxy)
|
||||
world.maxy = ycrd // Expand Y here. X is expanded in the loop below
|
||||
var/zexpansion = zcrd > world.maxz
|
||||
if(zexpansion)
|
||||
if(cropMap)
|
||||
continue
|
||||
else
|
||||
while (zcrd > world.maxz) //create a new z_level if needed
|
||||
world.incrementMaxZ()
|
||||
if(!no_changeturf)
|
||||
WARNING("Z-level expansion occurred without no_changeturf set, this may cause problems when /turf/AfterChange is called")
|
||||
|
||||
for(var/line in gset.gridLines)
|
||||
if((ycrd - y_offset + 1) < y_lower || (ycrd - y_offset + 1) > y_upper) //Reverse operation and check if it is out of bounds of cropping.
|
||||
--ycrd
|
||||
continue
|
||||
if(ycrd <= world.maxy && ycrd >= 1)
|
||||
var/xcrd = gset.xcrd + x_offset - 1
|
||||
for(var/tpos = 1 to length(line) - key_len + 1 step key_len)
|
||||
if((xcrd - x_offset + 1) < x_lower || (xcrd - x_offset + 1) > x_upper) //Same as above.
|
||||
++xcrd
|
||||
continue //X cropping.
|
||||
if(xcrd > world.maxx)
|
||||
if(cropMap)
|
||||
break
|
||||
else
|
||||
world.maxx = xcrd
|
||||
|
||||
if(xcrd >= 1)
|
||||
var/model_key = copytext(line, tpos, tpos + key_len)
|
||||
var/no_afterchange = no_changeturf || zexpansion
|
||||
if(!no_afterchange || (model_key != space_key))
|
||||
var/list/cache = modelCache[model_key]
|
||||
if(!cache)
|
||||
CRASH("Undefined model key in DMM: [model_key]")
|
||||
build_coordinate(areaCache, cache, locate(xcrd, ycrd, zcrd), no_afterchange, placeOnTop)
|
||||
|
||||
// only bother with bounds that actually exist
|
||||
bounds[MAP_MINX] = min(bounds[MAP_MINX], xcrd)
|
||||
bounds[MAP_MINY] = min(bounds[MAP_MINY], ycrd)
|
||||
bounds[MAP_MINZ] = min(bounds[MAP_MINZ], zcrd)
|
||||
bounds[MAP_MAXX] = max(bounds[MAP_MAXX], xcrd)
|
||||
bounds[MAP_MAXY] = max(bounds[MAP_MAXY], ycrd)
|
||||
bounds[MAP_MAXZ] = max(bounds[MAP_MAXZ], zcrd)
|
||||
#ifdef TESTING
|
||||
else
|
||||
++turfsSkipped
|
||||
#endif
|
||||
CHECK_TICK
|
||||
++xcrd
|
||||
--ycrd
|
||||
|
||||
CHECK_TICK
|
||||
|
||||
if(!no_changeturf)
|
||||
for(var/t in block(locate(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ]), locate(bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ])))
|
||||
var/turf/T = t
|
||||
//we do this after we load everything in. if we don't; we'll have weird atmos bugs regarding atmos adjacent turfs
|
||||
T.AfterChange(CHANGETURF_IGNORE_AIR)
|
||||
|
||||
#ifdef TESTING
|
||||
if(turfsSkipped)
|
||||
testing("Skipped loading [turfsSkipped] default turfs")
|
||||
#endif
|
||||
|
||||
return TRUE
|
||||
|
||||
/datum/parsed_map/proc/build_cache(no_changeturf, bad_paths=null)
|
||||
if(modelCache && !bad_paths)
|
||||
return modelCache
|
||||
. = modelCache = list()
|
||||
var/list/grid_models = src.grid_models
|
||||
for(var/model_key in grid_models)
|
||||
var/model = grid_models[model_key]
|
||||
var/list/members = list() //will contain all members (paths) in model (in our example : /turf/unsimulated/wall and /area/mine/explored)
|
||||
var/list/members_attributes = list() //will contain lists filled with corresponding variables, if any (in our example : list(icon_state = "rock") and list())
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//Constructing members and corresponding variables lists
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
var/index = 1
|
||||
var/old_position = 1
|
||||
var/dpos
|
||||
|
||||
while(dpos != 0)
|
||||
//finding next member (e.g /turf/unsimulated/wall{icon_state = "rock"} or /area/mine/explored)
|
||||
dpos = find_next_delimiter_position(model, old_position, ",", "{", "}") //find next delimiter (comma here) that's not within {...}
|
||||
|
||||
var/full_def = trim_text(copytext(model, old_position, dpos)) //full definition, e.g : /obj/foo/bar{variables=derp}
|
||||
var/variables_start = findtext(full_def, "{")
|
||||
var/path_text = trim_text(copytext(full_def, 1, variables_start))
|
||||
var/atom_def = text2path(path_text) //path definition, e.g /obj/foo/bar
|
||||
old_position = dpos + 1
|
||||
|
||||
if(!ispath(atom_def, /atom)) // Skip the item if the path does not exist. Fix your crap, mappers!
|
||||
if(bad_paths)
|
||||
LAZYOR(bad_paths[path_text], model_key)
|
||||
continue
|
||||
members.Add(atom_def)
|
||||
|
||||
//transform the variables in text format into a list (e.g {var1="derp"; var2; var3=7} => list(var1="derp", var2, var3=7))
|
||||
var/list/fields = list()
|
||||
|
||||
if(variables_start)//if there's any variable
|
||||
full_def = copytext(full_def,variables_start+1,length(full_def))//removing the last '}'
|
||||
fields = readlist(full_def, ";")
|
||||
if(fields.len)
|
||||
if(!trim(fields[fields.len]))
|
||||
--fields.len
|
||||
for(var/I in fields)
|
||||
var/value = fields[I]
|
||||
if(istext(value))
|
||||
fields[I] = apply_text_macros(value)
|
||||
|
||||
//then fill the members_attributes list with the corresponding variables
|
||||
members_attributes.len++
|
||||
members_attributes[index++] = fields
|
||||
|
||||
CHECK_TICK
|
||||
|
||||
//check and see if we can just skip this turf
|
||||
//So you don't have to understand this horrid statement, we can do this if
|
||||
// 1. no_changeturf is set
|
||||
// 2. the space_key isn't set yet
|
||||
// 3. there are exactly 2 members
|
||||
// 4. with no attributes
|
||||
// 5. and the members are world.turf and world.area
|
||||
// Basically, if we find an entry like this: "XXX" = (/turf/default, /area/default)
|
||||
// We can skip calling this proc every time we see XXX
|
||||
if(no_changeturf \
|
||||
&& !(.[SPACE_KEY]) \
|
||||
&& members.len == 2 \
|
||||
&& members_attributes.len == 2 \
|
||||
&& length(members_attributes[1]) == 0 \
|
||||
&& length(members_attributes[2]) == 0 \
|
||||
&& (world.area in members) \
|
||||
&& (world.turf in members))
|
||||
|
||||
.[SPACE_KEY] = model_key
|
||||
continue
|
||||
|
||||
|
||||
.[model_key] = list(members, members_attributes)
|
||||
|
||||
/datum/parsed_map/proc/build_coordinate(list/areaCache, list/model, turf/crds, no_changeturf as num, placeOnTop as num)
|
||||
var/index
|
||||
var/list/members = model[1]
|
||||
var/list/members_attributes = model[2]
|
||||
|
||||
////////////////
|
||||
//Instanciation
|
||||
////////////////
|
||||
|
||||
//The next part of the code assumes there's ALWAYS an /area AND a /turf on a given tile
|
||||
//first instance the /area and remove it from the members list
|
||||
index = members.len
|
||||
if(members[index] != /area/template_noop)
|
||||
GLOB._preloader.setup(members_attributes[index])//preloader for assigning set variables on atom creation
|
||||
var/atype = members[index]
|
||||
var/atom/instance = areaCache[atype]
|
||||
if (!instance)
|
||||
instance = GLOB.areas_by_type[atype]
|
||||
if (!instance)
|
||||
instance = new atype(null)
|
||||
areaCache[atype] = instance
|
||||
if(crds)
|
||||
instance.contents.Add(crds)
|
||||
|
||||
if(GLOB.use_preloader && instance)
|
||||
GLOB._preloader.load(instance)
|
||||
|
||||
//then instance the /turf and, if multiple tiles are presents, simulates the DMM underlays piling effect
|
||||
|
||||
var/first_turf_index = 1
|
||||
while(!ispath(members[first_turf_index], /turf)) //find first /turf object in members
|
||||
first_turf_index++
|
||||
|
||||
//turn off base new Initialization until the whole thing is loaded
|
||||
SSatoms.map_loader_begin()
|
||||
//instanciate the first /turf
|
||||
var/turf/T
|
||||
if(members[first_turf_index] != /turf/template_noop)
|
||||
T = instance_atom(members[first_turf_index],members_attributes[first_turf_index],crds,no_changeturf,placeOnTop)
|
||||
|
||||
if(T)
|
||||
//if others /turf are presents, simulates the underlays piling effect
|
||||
index = first_turf_index + 1
|
||||
while(index <= members.len - 1) // Last item is an /area
|
||||
var/underlay = T.appearance
|
||||
T = instance_atom(members[index],members_attributes[index],crds,no_changeturf,placeOnTop)//instance new turf
|
||||
T.underlays += underlay
|
||||
index++
|
||||
|
||||
//finally instance all remainings objects/mobs
|
||||
for(index in 1 to first_turf_index-1)
|
||||
instance_atom(members[index],members_attributes[index],crds,no_changeturf,placeOnTop)
|
||||
//Restore initialization to the previous value
|
||||
SSatoms.map_loader_stop()
|
||||
|
||||
////////////////
|
||||
//Helpers procs
|
||||
////////////////
|
||||
|
||||
//Instance an atom at (x,y,z) and gives it the variables in attributes
|
||||
/datum/parsed_map/proc/instance_atom(path,list/attributes, turf/crds, no_changeturf, placeOnTop)
|
||||
GLOB._preloader.setup(attributes, path)
|
||||
|
||||
if(crds)
|
||||
if(ispath(path, /turf))
|
||||
if(placeOnTop)
|
||||
. = crds.PlaceOnTop(null, path, CHANGETURF_DEFER_CHANGE | (no_changeturf ? CHANGETURF_SKIP : NONE))
|
||||
else if(!no_changeturf)
|
||||
. = crds.ChangeTurf(path, null, CHANGETURF_DEFER_CHANGE)
|
||||
else
|
||||
. = create_atom(path, crds)//first preloader pass
|
||||
else
|
||||
. = create_atom(path, crds)//first preloader pass
|
||||
|
||||
if(GLOB.use_preloader && .)//second preloader pass, for those atoms that don't ..() in New()
|
||||
GLOB._preloader.load(.)
|
||||
|
||||
//custom CHECK_TICK here because we don't want things created while we're sleeping to not initialize
|
||||
if(TICK_CHECK)
|
||||
SSatoms.map_loader_stop()
|
||||
stoplag()
|
||||
SSatoms.map_loader_begin()
|
||||
|
||||
/datum/parsed_map/proc/create_atom(path, crds)
|
||||
set waitfor = FALSE
|
||||
. = new path (crds)
|
||||
|
||||
//text trimming (both directions) helper proc
|
||||
//optionally removes quotes before and after the text (for variable name)
|
||||
/datum/parsed_map/proc/trim_text(what as text,trim_quotes=0)
|
||||
if(trim_quotes)
|
||||
return trimQuotesRegex.Replace(what, "")
|
||||
else
|
||||
return trimRegex.Replace(what, "")
|
||||
|
||||
|
||||
//find the position of the next delimiter,skipping whatever is comprised between opening_escape and closing_escape
|
||||
//returns 0 if reached the last delimiter
|
||||
/datum/parsed_map/proc/find_next_delimiter_position(text as text,initial_position as num, delimiter=",",opening_escape="\"",closing_escape="\"")
|
||||
var/position = initial_position
|
||||
var/next_delimiter = findtext(text,delimiter,position,0)
|
||||
var/next_opening = findtext(text,opening_escape,position,0)
|
||||
|
||||
while((next_opening != 0) && (next_opening < next_delimiter))
|
||||
position = findtext(text,closing_escape,next_opening + 1,0)+1
|
||||
next_delimiter = findtext(text,delimiter,position,0)
|
||||
next_opening = findtext(text,opening_escape,position,0)
|
||||
|
||||
return next_delimiter
|
||||
|
||||
|
||||
//build a list from variables in text form (e.g {var1="derp"; var2; var3=7} => list(var1="derp", var2, var3=7))
|
||||
//return the filled list
|
||||
/datum/parsed_map/proc/readlist(text as text, delimiter=",")
|
||||
. = list()
|
||||
if (!text)
|
||||
return
|
||||
|
||||
var/position
|
||||
var/old_position = 1
|
||||
|
||||
while(position != 0)
|
||||
// find next delimiter that is not within "..."
|
||||
position = find_next_delimiter_position(text,old_position,delimiter)
|
||||
|
||||
// check if this is a simple variable (as in list(var1, var2)) or an associative one (as in list(var1="foo",var2=7))
|
||||
var/equal_position = findtext(text,"=",old_position, position)
|
||||
|
||||
var/trim_left = trim_text(copytext(text,old_position,(equal_position ? equal_position : position)))
|
||||
var/left_constant = delimiter == ";" ? trim_left : parse_constant(trim_left)
|
||||
old_position = position + 1
|
||||
|
||||
if(equal_position && !isnum(left_constant))
|
||||
// Associative var, so do the association.
|
||||
// Note that numbers cannot be keys - the RHS is dropped if so.
|
||||
var/trim_right = trim_text(copytext(text,equal_position+1,position))
|
||||
var/right_constant = parse_constant(trim_right)
|
||||
.[left_constant] = right_constant
|
||||
|
||||
else // simple var
|
||||
. += list(left_constant)
|
||||
|
||||
/datum/parsed_map/proc/parse_constant(text)
|
||||
// number
|
||||
var/num = text2num(text)
|
||||
if(isnum(num))
|
||||
return num
|
||||
|
||||
// string
|
||||
if(findtext(text,"\"",1,2))
|
||||
return copytext(text,2,findtext(text,"\"",3,0))
|
||||
|
||||
// list
|
||||
if(copytext(text,1,6) == "list(")
|
||||
return readlist(copytext(text,6,length(text)))
|
||||
|
||||
// typepath
|
||||
var/path = text2path(text)
|
||||
if(ispath(path))
|
||||
return path
|
||||
|
||||
// file
|
||||
if(copytext(text,1,2) == "'")
|
||||
return file(copytext(text,2,length(text)))
|
||||
|
||||
// null
|
||||
if(text == "null")
|
||||
return null
|
||||
|
||||
// not parsed:
|
||||
// - pops: /obj{name="foo"}
|
||||
// - new(), newlist(), icon(), matrix(), sound()
|
||||
|
||||
// fallback: string
|
||||
return text
|
||||
|
||||
/datum/parsed_map/Destroy()
|
||||
..()
|
||||
return QDEL_HINT_HARDDEL_NOW
|
||||
@@ -0,0 +1,135 @@
|
||||
/datum/map_template/ruin/proc/try_to_place(z,allowed_areas)
|
||||
var/sanity = PLACEMENT_TRIES
|
||||
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 = 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 TRUE
|
||||
return FALSE
|
||||
|
||||
|
||||
/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)
|
||||
var/list/ruins_availible = list() //we can try these in the current pass
|
||||
var/forced_z //If set we won't pick z level and use this one instead.
|
||||
|
||||
//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
|
||||
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(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 = PLACEMENT_TRIES
|
||||
var/failed_to_place = TRUE
|
||||
var/z_placed = 0
|
||||
while(placement_tries > 0)
|
||||
placement_tries--
|
||||
z_placed = pick(z_levels)
|
||||
if(!current_pick.try_to_place(forced_z ? forced_z : z_placed,whitelist))
|
||||
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] = forced_z ? forced_z : z_placed //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
|
||||
forced_z = 0
|
||||
|
||||
//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.")
|
||||
@@ -0,0 +1,14 @@
|
||||
/datum/space_level
|
||||
var/name = "NAME MISSING"
|
||||
var/list/neigbours = list()
|
||||
var/list/traits
|
||||
var/z_value = 1 //actual z placement
|
||||
var/linkage = SELFLOOPING
|
||||
var/xi
|
||||
var/yi //imaginary placements on the grid
|
||||
|
||||
/datum/space_level/New(new_z, new_name, list/new_traits = list())
|
||||
z_value = new_z
|
||||
name = new_name
|
||||
traits = new_traits
|
||||
set_linkage(new_traits[ZTRAIT_LINKAGE])
|
||||
@@ -0,0 +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 ..()
|
||||
@@ -0,0 +1,143 @@
|
||||
/datum/space_level/proc/set_linkage(new_linkage)
|
||||
linkage = new_linkage
|
||||
if(linkage == SELFLOOPING)
|
||||
neigbours = list(TEXT_NORTH,TEXT_SOUTH,TEXT_EAST,TEXT_WEST)
|
||||
for(var/A in neigbours)
|
||||
neigbours[A] = src
|
||||
|
||||
/datum/space_level/proc/set_neigbours(list/L)
|
||||
for(var/datum/space_transition_point/P in L)
|
||||
if(P.x == xi)
|
||||
if(P.y == yi+1)
|
||||
neigbours[TEXT_NORTH] = P.spl
|
||||
P.spl.neigbours[TEXT_SOUTH] = src
|
||||
else if(P.y == yi-1)
|
||||
neigbours[TEXT_SOUTH] = P.spl
|
||||
P.spl.neigbours[TEXT_NORTH] = src
|
||||
else if(P.y == yi)
|
||||
if(P.x == xi+1)
|
||||
neigbours[TEXT_EAST] = P.spl
|
||||
P.spl.neigbours[TEXT_WEST] = src
|
||||
else if(P.x == xi-1)
|
||||
neigbours[TEXT_WEST] = P.spl
|
||||
P.spl.neigbours[TEXT_EAST] = src
|
||||
|
||||
/datum/space_transition_point //this is explicitly utilitarian datum type made specially for the space map generation and are absolutely unusable for anything else
|
||||
var/list/neigbours = list()
|
||||
var/x
|
||||
var/y
|
||||
var/datum/space_level/spl
|
||||
|
||||
/datum/space_transition_point/New(nx, ny, list/point_grid)
|
||||
if(!point_grid)
|
||||
qdel(src)
|
||||
return
|
||||
var/list/L = point_grid[1]
|
||||
if(nx > point_grid.len || ny > L.len)
|
||||
qdel(src)
|
||||
return
|
||||
x = nx
|
||||
y = ny
|
||||
if(point_grid[x][y])
|
||||
return
|
||||
point_grid[x][y] = src
|
||||
|
||||
/datum/space_transition_point/proc/set_neigbours(list/grid)
|
||||
var/max_X = grid.len
|
||||
var/list/max_Y = grid[1]
|
||||
max_Y = max_Y.len
|
||||
neigbours.Cut()
|
||||
if(x+1 <= max_X)
|
||||
neigbours |= grid[x+1][y]
|
||||
if(x-1 >= 1)
|
||||
neigbours |= grid[x-1][y]
|
||||
if(y+1 <= max_Y)
|
||||
neigbours |= grid[x][y+1]
|
||||
if(y-1 >= 1)
|
||||
neigbours |= grid[x][y-1]
|
||||
|
||||
/datum/controller/subsystem/mapping/proc/setup_map_transitions() //listamania
|
||||
var/list/SLS = list()
|
||||
var/list/cached_z_list = z_list
|
||||
var/conf_set_len = 0
|
||||
for(var/A in cached_z_list)
|
||||
var/datum/space_level/D = A
|
||||
if (D.linkage == CROSSLINKED)
|
||||
SLS.Add(D)
|
||||
conf_set_len++
|
||||
var/list/point_grid[conf_set_len*2+1][conf_set_len*2+1]
|
||||
var/list/grid = list()
|
||||
var/datum/space_transition_point/P
|
||||
for(var/i = 1, i<=conf_set_len*2+1, i++)
|
||||
for(var/j = 1, j<=conf_set_len*2+1, j++)
|
||||
P = new/datum/space_transition_point(i,j, point_grid)
|
||||
point_grid[i][j] = P
|
||||
grid.Add(P)
|
||||
for(var/datum/space_transition_point/pnt in grid)
|
||||
pnt.set_neigbours(point_grid)
|
||||
P = point_grid[conf_set_len+1][conf_set_len+1]
|
||||
var/list/possible_points = list()
|
||||
var/list/used_points = list()
|
||||
grid.Cut()
|
||||
while(SLS.len)
|
||||
var/datum/space_level/D = pick_n_take(SLS)
|
||||
D.xi = P.x
|
||||
D.yi = P.y
|
||||
P.spl = D
|
||||
possible_points |= P.neigbours
|
||||
used_points |= P
|
||||
possible_points.Remove(used_points)
|
||||
D.set_neigbours(used_points)
|
||||
P = pick(possible_points)
|
||||
CHECK_TICK
|
||||
|
||||
//Lists below are pre-calculated values arranged in the list in such a way to be easily accessable in the loop by the counter
|
||||
//Its either this or madness with lotsa math
|
||||
|
||||
var/list/x_pos_beginning = list(1, 1, world.maxx - TRANSITIONEDGE, 1) //x values of the lowest-leftest turfs of the respective 4 blocks on each side of zlevel
|
||||
var/list/y_pos_beginning = list(world.maxy - TRANSITIONEDGE, 1, 1 + TRANSITIONEDGE, 1 + TRANSITIONEDGE) //y values respectively
|
||||
var/list/x_pos_ending = list(world.maxx, world.maxx, world.maxx, 1 + TRANSITIONEDGE) //x values of the highest-rightest turfs of the respective 4 blocks on each side of zlevel
|
||||
var/list/y_pos_ending = list(world.maxy, 1 + TRANSITIONEDGE, world.maxy - TRANSITIONEDGE, world.maxy - TRANSITIONEDGE) //y values respectively
|
||||
var/list/x_pos_transition = list(1, 1, TRANSITIONEDGE + 2, world.maxx - TRANSITIONEDGE - 1) //values of x for the transition from respective blocks on the side of zlevel, 1 is being translated into turfs respective x value later in the code
|
||||
var/list/y_pos_transition = list(TRANSITIONEDGE + 2, world.maxy - TRANSITIONEDGE - 1, 1, 1) //values of y for the transition from respective blocks on the side of zlevel, 1 is being translated into turfs respective y value later in the code
|
||||
|
||||
for(var/I in cached_z_list)
|
||||
var/datum/space_level/D = I
|
||||
if(!D.neigbours.len)
|
||||
continue
|
||||
var/zlevelnumber = D.z_value
|
||||
for(var/side in 1 to 4)
|
||||
var/turf/beginning = locate(x_pos_beginning[side], y_pos_beginning[side], zlevelnumber)
|
||||
var/turf/ending = locate(x_pos_ending[side], y_pos_ending[side], zlevelnumber)
|
||||
var/list/turfblock = block(beginning, ending)
|
||||
var/dirside = 2**(side-1)
|
||||
var/zdestination = zlevelnumber
|
||||
if(D.neigbours["[dirside]"] && D.neigbours["[dirside]"] != D)
|
||||
D = D.neigbours["[dirside]"]
|
||||
zdestination = D.z_value
|
||||
else
|
||||
dirside = turn(dirside, 180)
|
||||
while(D.neigbours["[dirside]"] && D.neigbours["[dirside]"] != D)
|
||||
D = D.neigbours["[dirside]"]
|
||||
zdestination = D.z_value
|
||||
D = I
|
||||
for(var/turf/open/space/S in turfblock)
|
||||
S.destination_x = x_pos_transition[side] == 1 ? S.x : x_pos_transition[side]
|
||||
S.destination_y = y_pos_transition[side] == 1 ? S.y : y_pos_transition[side]
|
||||
S.destination_z = zdestination
|
||||
|
||||
// Mirage border code
|
||||
var/mirage_dir
|
||||
if(S.x == 1 + TRANSITIONEDGE)
|
||||
mirage_dir |= WEST
|
||||
else if(S.x == world.maxx - TRANSITIONEDGE)
|
||||
mirage_dir |= EAST
|
||||
if(S.y == 1 + TRANSITIONEDGE)
|
||||
mirage_dir |= SOUTH
|
||||
else if(S.y == world.maxy - TRANSITIONEDGE)
|
||||
mirage_dir |= NORTH
|
||||
if(!mirage_dir)
|
||||
continue
|
||||
|
||||
var/turf/place = locate(S.destination_x, S.destination_y, S.destination_z)
|
||||
S.AddComponent(/datum/component/mirage_border, place, mirage_dir)
|
||||
@@ -0,0 +1,73 @@
|
||||
// Look up levels[z].traits[trait]
|
||||
/datum/controller/subsystem/mapping/proc/level_trait(z, trait)
|
||||
if (!isnum(z) || z < 1)
|
||||
return null
|
||||
if (z_list)
|
||||
if (z > z_list.len)
|
||||
stack_trace("Unmanaged z-level [z]! maxz = [world.maxz], z_list.len = [z_list.len]")
|
||||
return list()
|
||||
var/datum/space_level/S = get_level(z)
|
||||
return S.traits[trait]
|
||||
else
|
||||
var/list/default = DEFAULT_MAP_TRAITS
|
||||
if (z > default.len)
|
||||
stack_trace("Unmanaged z-level [z]! maxz = [world.maxz], default.len = [default.len]")
|
||||
return list()
|
||||
return default[z][DL_TRAITS][trait]
|
||||
|
||||
// Check if levels[z] has any of the specified traits
|
||||
/datum/controller/subsystem/mapping/proc/level_has_any_trait(z, list/traits)
|
||||
for (var/I in traits)
|
||||
if (level_trait(z, I))
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
// Check if levels[z] has all of the specified traits
|
||||
/datum/controller/subsystem/mapping/proc/level_has_all_traits(z, list/traits)
|
||||
for (var/I in traits)
|
||||
if (!level_trait(z, I))
|
||||
return FALSE
|
||||
return TRUE
|
||||
|
||||
// Get a list of all z which have the specified trait
|
||||
/datum/controller/subsystem/mapping/proc/levels_by_trait(trait)
|
||||
. = list()
|
||||
var/list/_z_list = z_list
|
||||
for(var/A in _z_list)
|
||||
var/datum/space_level/S = A
|
||||
if (S.traits[trait])
|
||||
. += S.z_value
|
||||
|
||||
// Get a list of all z which have any of the specified traits
|
||||
/datum/controller/subsystem/mapping/proc/levels_by_any_trait(list/traits)
|
||||
. = list()
|
||||
var/list/_z_list = z_list
|
||||
for(var/A in _z_list)
|
||||
var/datum/space_level/S = A
|
||||
for (var/trait in traits)
|
||||
if (S.traits[trait])
|
||||
. += S.z_value
|
||||
break
|
||||
|
||||
// Attempt to get the turf below the provided one according to Z traits
|
||||
/datum/controller/subsystem/mapping/proc/get_turf_below(turf/T)
|
||||
if (!T)
|
||||
return
|
||||
var/offset = level_trait(T.z, ZTRAIT_DOWN)
|
||||
if (!offset)
|
||||
return
|
||||
return locate(T.x, T.y, T.z + offset)
|
||||
|
||||
// Attempt to get the turf above the provided one according to Z traits
|
||||
/datum/controller/subsystem/mapping/proc/get_turf_above(turf/T)
|
||||
if (!T)
|
||||
return
|
||||
var/offset = level_trait(T.z, ZTRAIT_UP)
|
||||
if (!offset)
|
||||
return
|
||||
return locate(T.x, T.y, T.z + offset)
|
||||
|
||||
// Prefer not to use this one too often
|
||||
/datum/controller/subsystem/mapping/proc/get_station_center()
|
||||
var/station_z = levels_by_trait(ZTRAIT_STATION)[1]
|
||||
return locate(round(world.maxx * 0.5, 1), round(world.maxy * 0.5, 1), station_z)
|
||||
@@ -0,0 +1,33 @@
|
||||
// Populate the space level list and prepare space transitions
|
||||
/datum/controller/subsystem/mapping/proc/InitializeDefaultZLevels()
|
||||
if (z_list) // subsystem/Recover or badminnery, no need
|
||||
return
|
||||
|
||||
z_list = list()
|
||||
var/list/default_map_traits = DEFAULT_MAP_TRAITS
|
||||
|
||||
if (default_map_traits.len != world.maxz)
|
||||
WARNING("More or less map attributes pre-defined ([default_map_traits.len]) than existent z-levels ([world.maxz]). Ignoring the larger.")
|
||||
if (default_map_traits.len > world.maxz)
|
||||
default_map_traits.Cut(world.maxz + 1)
|
||||
|
||||
for (var/I in 1 to default_map_traits.len)
|
||||
var/list/features = default_map_traits[I]
|
||||
var/datum/space_level/S = new(I, features[DL_NAME], features[DL_TRAITS])
|
||||
z_list += S
|
||||
|
||||
/datum/controller/subsystem/mapping/proc/add_new_zlevel(name, traits = list(), z_type = /datum/space_level)
|
||||
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_NEW_Z, args)
|
||||
var/new_z = z_list.len + 1
|
||||
if (world.maxz < new_z)
|
||||
world.incrementMaxZ()
|
||||
CHECK_TICK
|
||||
// TODO: sleep here if the Z level needs to be cleared
|
||||
var/datum/space_level/S = new z_type(new_z, name, traits)
|
||||
z_list += S
|
||||
return S
|
||||
|
||||
/datum/controller/subsystem/mapping/proc/get_level(z)
|
||||
if (z_list && z >= 1 && z <= z_list.len)
|
||||
return z_list[z]
|
||||
CRASH("Unmanaged z-level [z]! maxz = [world.maxz], z_list.len = [z_list ? z_list.len : "null"]")
|
||||
@@ -0,0 +1,98 @@
|
||||
/// An error report generated by [parsed_map/check_for_errors].
|
||||
/datum/map_report
|
||||
var/original_path
|
||||
var/list/bad_paths = list()
|
||||
var/list/bad_keys = list()
|
||||
/// Whether this map can be loaded safely despite the errors.
|
||||
var/loadable = TRUE
|
||||
var/crashed = TRUE
|
||||
|
||||
var/static/tag_number = 0
|
||||
|
||||
/datum/map_report/New(datum/parsed_map/map)
|
||||
original_path = map.original_path || "Untitled"
|
||||
|
||||
/// Show a rendered version of this report to a client.
|
||||
/datum/map_report/proc/show_to(client/C)
|
||||
var/list/html = list()
|
||||
html += "<p>Report for map file <tt>[original_path]</tt></p>"
|
||||
if(crashed)
|
||||
html += "<p><b>Validation crashed</b>: check the runtime logs.</p>"
|
||||
if(!loadable)
|
||||
html += "<p><b>Not loadable</b>: some tiles are missing their turfs or areas.</p>"
|
||||
|
||||
if(bad_paths.len)
|
||||
html += "<p>Bad paths: <ol>"
|
||||
for(var/path in bad_paths)
|
||||
var/list/keys = bad_paths[path]
|
||||
html += "<li><tt>[path]</tt>: used in ([keys.len]): <tt>[keys.Join("</tt>, <tt>")]</tt>"
|
||||
html += "</ol></p>"
|
||||
|
||||
if(bad_keys.len)
|
||||
html += "<p>Bad keys: <ul>"
|
||||
for(var/key in bad_keys)
|
||||
var/list/messages = bad_keys[key]
|
||||
html += "<li><tt>[key]</tt>"
|
||||
if(messages.len == 1)
|
||||
html += ": [bad_keys[key][1]]"
|
||||
else
|
||||
html += "<ul><li>[messages.Join("</li><li>")]</li></ul>"
|
||||
html += "</li>"
|
||||
html += "</ul></p>"
|
||||
C << browse(html.Join(), "window=[tag];size=600x400")
|
||||
|
||||
/datum/map_report/Topic(href, href_list)
|
||||
. = ..()
|
||||
if(. || !check_rights(R_ADMIN, FALSE) || !usr.client.holder.CheckAdminHref(href, href_list))
|
||||
return
|
||||
|
||||
if (href_list["show"])
|
||||
show_to(usr)
|
||||
|
||||
|
||||
/// Check a parsed but not yet loaded map for errors.
|
||||
///
|
||||
/// Returns a [/datum/map_report] if there are errors or `FALSE` otherwise.
|
||||
/datum/parsed_map/proc/check_for_errors()
|
||||
var/datum/map_report/report = new(src)
|
||||
. = report
|
||||
|
||||
// build_cache will check bad paths for us
|
||||
var/list/modelCache = build_cache(TRUE, report.bad_paths)
|
||||
|
||||
for(var/path in report.bad_paths)
|
||||
if(copytext(path, 1, 7) == "/turf/" || copytext(path, 1, 7) == "/area/")
|
||||
report.loadable = FALSE
|
||||
|
||||
// check for tiles with the wrong number of turfs or areas
|
||||
for(var/key in modelCache)
|
||||
if(key == SPACE_KEY)
|
||||
continue
|
||||
var/model = modelCache[key]
|
||||
var/list/members = model[1]
|
||||
|
||||
var/turfs = 0
|
||||
var/areas = 0
|
||||
for(var/i in 1 to members.len)
|
||||
var/atom/path = members[i]
|
||||
|
||||
turfs += ispath(path, /turf)
|
||||
areas += ispath(path, /area)
|
||||
|
||||
if(turfs == 0)
|
||||
report.loadable = FALSE
|
||||
LAZYADD(report.bad_keys[key], "no turf")
|
||||
else if(turfs > 1)
|
||||
LAZYADD(report.bad_keys[key], "[turfs] stacked turfs")
|
||||
|
||||
if(areas != 1)
|
||||
report.loadable = FALSE
|
||||
LAZYADD(report.bad_keys[key], "[areas] areas instead of 1")
|
||||
|
||||
// return the report
|
||||
if(report.bad_paths.len || report.bad_keys.len || !report.loadable)
|
||||
// keep the report around so it can be referenced later
|
||||
report.tag = "mapreport_[++report.tag_number]"
|
||||
report.crashed = FALSE
|
||||
else
|
||||
return FALSE
|
||||
Reference in New Issue
Block a user