From dcacb06269f97a8e951734cbf9005fca79e0ea5a Mon Sep 17 00:00:00 2001 From: ninjanomnom Date: Tue, 23 Jan 2018 01:01:18 -0500 Subject: [PATCH] makes templates use PlaceOnTop --- code/game/turfs/ChangeTurf.dm | 27 +++++++++++++++++++++------ code/modules/mapping/map_template.dm | 4 ++-- code/modules/mapping/reader.dm | 23 +++++++++++++---------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/code/game/turfs/ChangeTurf.dm b/code/game/turfs/ChangeTurf.dm index a55f546c1a0..27dbb363ea4 100644 --- a/code/game/turfs/ChangeTurf.dm +++ b/code/game/turfs/ChangeTurf.dm @@ -1,3 +1,8 @@ +// This is a list of turf types we dont want to assign to baseturfs unless through initialization or explicitly +GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list( + /turf/open/space, + ))) + /turf/proc/empty(turf_type=/turf/open/space, baseturf_type, list/ignore_typecache, flags) // Remove all atoms except observers, landmarks, docking ports var/static/list/ignored_atoms = typecacheof(list(/mob/dead, /obj/effect/landmark, /obj/docking_port, /atom/movable/lighting_object)) @@ -126,10 +131,13 @@ /turf/proc/PlaceOnBottom(list/new_baseturfs, turf/fake_turf_type) if(fake_turf_type) if(!new_baseturfs) + if(!length(baseturfs)) + baseturfs = list(baseturfs) var/list/old_baseturfs = baseturfs.Copy() assemble_baseturfs(fake_turf_type) if(!length(baseturfs)) baseturfs = list(baseturfs) + baseturfs -= baseturfs & GLOB.blacklisted_automated_baseturfs baseturfs += old_baseturfs return else if(!length(new_baseturfs)) @@ -142,22 +150,27 @@ // Make a new turf and put it on top // The args behave identical to PlaceOnBottom except they go on top -/turf/proc/PlaceOnTop(list/new_baseturfs, turf/fake_turf_type) +// Returns the new turf +/turf/proc/PlaceOnTop(list/new_baseturfs, turf/fake_turf_type, flags) var/turf/newT if(fake_turf_type) if(!new_baseturfs) // If no baseturfs list then we want to create one from the turf type - var/list/old_baseturfs = baseturfs.Copy() - newT = ChangeTurf(fake_turf_type) - newT.assemble_baseturfs(initial(fake_turf_type.baseturfs)) // The baseturfs list is created like roundstart if(!length(baseturfs)) + baseturfs = list(baseturfs) + var/list/old_baseturfs = baseturfs.Copy() + old_baseturfs += type + newT = ChangeTurf(fake_turf_type, null, flags) + newT.assemble_baseturfs(initial(fake_turf_type.baseturfs)) // The baseturfs list is created like roundstart + if(!length(newT.baseturfs)) newT.baseturfs = list(baseturfs) + newT.baseturfs -= newT.baseturfs & GLOB.blacklisted_automated_baseturfs newT.baseturfs.Insert(1, old_baseturfs) // The old baseturfs are put underneath return newT if(!length(baseturfs)) baseturfs = list(baseturfs) baseturfs += type baseturfs += new_baseturfs - return ChangeTurf(fake_turf_type) + return ChangeTurf(fake_turf_type, null, flags) if(!length(baseturfs)) baseturfs = list(baseturfs) baseturfs += type @@ -169,9 +182,10 @@ baseturfs += new_baseturfs else change_type = new_baseturfs - return ChangeTurf(change_type) + return ChangeTurf(change_type, null, flags) // Copy an existing turf and put it on top +// Returns the new turf /turf/proc/CopyOnTop(turf/copytarget, ignore_bottom=1, depth=INFINITY) var/list/new_baseturfs = list() new_baseturfs += baseturfs @@ -179,6 +193,7 @@ if(depth) var/list/target_baseturfs = copytarget.baseturfs + target_baseturfs -= target_baseturfs & GLOB.blacklisted_automated_baseturfs var/base_len = length(target_baseturfs) if(!base_len) if(!ignore_bottom) diff --git a/code/modules/mapping/map_template.dm b/code/modules/mapping/map_template.dm index 3f1d3e78abf..7cc91781ef7 100644 --- a/code/modules/mapping/map_template.dm +++ b/code/modules/mapping/map_template.dm @@ -53,7 +53,7 @@ var/y = round((world.maxy - height)/2) var/datum/space_level/level = SSmapping.add_new_zlevel(name, UNAFFECTED, list(ZTRAIT_AWAY = TRUE)) - var/list/bounds = maploader.load_map(file(mappath), x, y, level.z_value, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS)) + var/list/bounds = maploader.load_map(file(mappath), x, y, level.z_value, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS), placeOnTop=TRUE) if(!bounds) return FALSE @@ -75,7 +75,7 @@ if(T.y+height > world.maxy) return - var/list/bounds = maploader.load_map(file(mappath), T.x, T.y, T.z, cropMap=TRUE, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS)) + var/list/bounds = maploader.load_map(file(mappath), T.x, T.y, T.z, cropMap=TRUE, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS), placeOnTop=TRUE) if(!bounds) return diff --git a/code/modules/mapping/reader.dm b/code/modules/mapping/reader.dm index 365679f5d3e..0e090a86c6e 100644 --- a/code/modules/mapping/reader.dm +++ b/code/modules/mapping/reader.dm @@ -29,21 +29,21 @@ GLOBAL_DATUM_INIT(_preloader, /dmm_suite/preloader, new) * 2) Read the map line by line, parsing the result (using parse_grid) * */ -/dmm_suite/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, lower_crop_x as num, lower_crop_y as num, upper_crop_x as num, upper_crop_y as num) +/dmm_suite/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, lower_crop_x as num, lower_crop_y as num, upper_crop_x as num, upper_crop_y as num, placeOnTop as num) //How I wish for RAII Master.StartLoadingMap() space_key = null #ifdef TESTING turfsSkipped = 0 #endif - . = load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf, lower_crop_x, upper_crop_x, lower_crop_y, upper_crop_y) + . = load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf, lower_crop_x, upper_crop_x, lower_crop_y, upper_crop_y, placeOnTop) #ifdef TESTING if(turfsSkipped) testing("Skipped loading [turfsSkipped] default turfs") #endif Master.StopLoadingMap() -/dmm_suite/proc/load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf, x_lower = -INFINITY, x_upper = INFINITY, y_lower = -INFINITY, y_upper = INFINITY) +/dmm_suite/proc/load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf, x_lower = -INFINITY, x_upper = INFINITY, y_lower = -INFINITY, y_upper = INFINITY, placeOnTop = FALSE) var/tfile = dmm_file//the map file we're creating if(isfile(tfile)) tfile = file2text(tfile) @@ -156,7 +156,7 @@ GLOBAL_DATUM_INIT(_preloader, /dmm_suite/preloader, new) if(!no_afterchange || (model_key != space_key)) if(!grid_models[model_key]) throw EXCEPTION("Undefined model key in DMM.") - parse_grid(grid_models[model_key], model_key, xcrd, ycrd, zcrd, no_changeturf || zexpansion) + parse_grid(grid_models[model_key], model_key, xcrd, ycrd, zcrd, no_changeturf || zexpansion, placeOnTop) #ifdef TESTING else ++turfsSkipped @@ -198,7 +198,7 @@ GLOBAL_DATUM_INIT(_preloader, /dmm_suite/preloader, new) * 4) Instanciates the atom with its variables * */ -/dmm_suite/proc/parse_grid(model as text, model_key as text, xcrd as num,ycrd as num,zcrd as num, no_changeturf as num) +/dmm_suite/proc/parse_grid(model as text, model_key as text, xcrd as num,ycrd as num,zcrd as num, no_changeturf as num, placeOnTop as num) /*Method parse_grid() - Accepts a text string containing a comma separated list of type paths of the same construction as those contained in a .dmm file, and instantiates them. @@ -312,20 +312,20 @@ GLOBAL_DATUM_INIT(_preloader, /dmm_suite/preloader, new) //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) + 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)//instance new turf + 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) + instance_atom(members[index],members_attributes[index],crds,no_changeturf,placeOnTop) //Restore initialization to the previous value SSatoms.map_loader_stop() @@ -334,12 +334,15 @@ GLOBAL_DATUM_INIT(_preloader, /dmm_suite/preloader, new) //////////////// //Instance an atom at (x,y,z) and gives it the variables in attributes -/dmm_suite/proc/instance_atom(path,list/attributes, turf/crds, no_changeturf) +/dmm_suite/proc/instance_atom(path,list/attributes, turf/crds, no_changeturf, placeOnTop) GLOB._preloader.setup(attributes, path) if(crds) if(!no_changeturf && ispath(path, /turf)) - . = crds.ChangeTurf(path, null, CHANGETURF_DEFER_CHANGE) + if(placeOnTop) + . = crds.PlaceOnTop(null, path, CHANGETURF_DEFER_CHANGE) + else + . = crds.ChangeTurf(path, null, CHANGETURF_DEFER_CHANGE) else . = create_atom(path, crds)//first preloader pass