/datum/map_template var/name = "Default Template Name" var/desc = "Some text should go here. Maybe." var/template_group = null // If this is set, no more than one template in the same group will be spawned, per submap seeding. var/width = 0 var/height = 0 var/mappath = null var/loaded = 0 // Times loaded this round var/annihilate = FALSE // If true, all (movable) atoms at the location where the map is loaded will be deleted before the map is loaded in. var/fixed_orientation = FALSE // If true, the submap will not be rotated randomly when loaded. var/cost = null /* The map generator has a set 'budget' it spends to place down different submaps. It will pick available submaps randomly until it runs out. The cost of a submap should roughly corrispond with several factors such as size, loot, difficulty, desired scarcity, etc. Set to -1 to force the submap to always be made. */ var/allow_duplicates = FALSE // If false, only one map template will be spawned by the game. Doesn't affect admins spawning then manually. var/discard_prob = 0 // If non-zero, there is a chance that the map seeding algorithm will skip this template when selecting potential templates to use. /datum/map_template/New(path = null, rename = null) if(path) mappath = path if(mappath) spawn(1) preload_size(mappath) if(rename) name = rename /datum/map_template/proc/preload_size(path, orientation = 0) var/bounds = SSmapping.maploader.load_map(file(path), 1, 1, 1, cropMap=FALSE, measureOnly=TRUE, orientation=orientation) if(bounds) if(orientation & (90 | 270)) width = bounds[MAP_MAXY] height = bounds[MAP_MAXX] else width = bounds[MAP_MAXX] // Assumes all templates are rectangular, have a single Z level, and begin at 1,1,1 height = bounds[MAP_MAXY] return bounds /datum/map_template/proc/initTemplateBounds(var/list/bounds) if (SSatoms.atom_init_stage == INITIALIZATION_INSSATOMS) return // let proper initialisation handle it later var/prev_shuttle_queue_state = SSshuttles.block_init_queue SSshuttles.block_init_queue = TRUE var/machinery_was_awake = SSmachines.suspend() // Suspend machinery (if it was not already suspended) var/list/atom/atoms = list() var/list/area/areas = list() var/list/obj/structure/cable/cables = list() var/list/obj/machinery/atmospherics/atmos_machines = list() var/list/turf/turfs = block(locate(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ]), locate(bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ])) 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 else if(istype(A, /obj/machinery/atmospherics)) atmos_machines += A atoms |= areas admin_notice("Initializing newly created atom(s) in submap.", R_DEBUG) SSatoms.InitializeAtoms(atoms) admin_notice("Initializing atmos pipenets and machinery in submap.", R_DEBUG) SSmachines.setup_atmos_machinery(atmos_machines) admin_notice("Rebuilding powernets due to submap creation.", R_DEBUG) SSmachines.setup_powernets_for_cables(cables) // Ensure all machines in loaded areas get notified of power status for(var/I in areas) var/area/A = I A.power_change() if(machinery_was_awake) SSmachines.wake() // Wake only if it was awake before we tried to suspended it. SSshuttles.block_init_queue = prev_shuttle_queue_state SSshuttles.process_init_queues() // We will flush the queue unless there were other blockers, in which case they will do it. admin_notice("Submap initializations finished.", R_DEBUG) /datum/map_template/proc/load_new_z(var/centered = FALSE, var/orientation = 0) var/x = 1 var/y = 1 if(centered) x = round((world.maxx - width)/2) y = round((world.maxy - height)/2) var/list/bounds = SSmapping.maploader.load_map(file(mappath), x, y, no_changeturf = TRUE, orientation=orientation) if(!bounds) return FALSE // repopulate_sorted_areas() //initialize things that are normally initialized after map load initTemplateBounds(bounds) log_game("Z-level [name] loaded at at [x],[y],[world.maxz]") return TRUE /datum/map_template/proc/load(turf/T, centered = FALSE, orientation = 0) var/old_T = T if(centered) T = locate(T.x - round(((orientation%180) ? height : width)/2) , T.y - round(((orientation%180) ? width : height)/2) , T.z) // %180 catches East/West (90,270) rotations on true, North/South (0,180) rotations on false if(!T) return if(T.x+width > world.maxx) return if(T.y+height > world.maxy) return if(annihilate) annihilate_bounds(old_T, centered, orientation) var/list/bounds = SSmapping.maploader.load_map(file(mappath), T.x, T.y, T.z, cropMap=TRUE, orientation = orientation) 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 initTemplateBounds(bounds) log_game("[name] loaded at at [T.x],[T.y],[T.z]") loaded++ return TRUE /datum/map_template/proc/get_affected_turfs(turf/T, centered = FALSE, orientation = 0) var/turf/placement = T if(centered) var/turf/corner = locate(placement.x - round(((orientation%180) ? height : width)/2), placement.y - round(((orientation%180) ? width : height)/2), placement.z) // %180 catches East/West (90,270) rotations on true, North/South (0,180) rotations on false if(corner) placement = corner return block(placement, locate(placement.x+((orientation%180) ? height : width)-1, placement.y+((orientation%180) ? width : height)-1, placement.z)) /datum/map_template/proc/annihilate_bounds(turf/origin, centered = FALSE, orientation = 0) var/deleted_atoms = 0 admin_notice("Annihilating objects in submap loading locatation.", R_DEBUG) var/list/turfs_to_clean = get_affected_turfs(origin, centered, orientation) if(turfs_to_clean.len) for(var/turf/T in turfs_to_clean) for(var/atom/movable/AM in T) ++deleted_atoms qdel(AM) admin_notice("Annihilated [deleted_atoms] objects.", R_DEBUG) //for your ever biggening badminnery kevinz000 //❤ - Cyberboss /proc/load_new_z_level(var/file, var/name, var/orientation = 0) var/datum/map_template/template = new(file, name) template.load_new_z(orientation)