diff --git a/code/__defines/map.dm b/code/__defines/map.dm index 9419415e1c..13b1bfd795 100644 --- a/code/__defines/map.dm +++ b/code/__defines/map.dm @@ -6,3 +6,6 @@ #define MAP_LEVEL_SEALED 0x010 // Z-levels that don't allow random transit at edge #define MAP_LEVEL_EMPTY 0x020 // Empty Z-levels that may be used for various things (currently used by bluespace jump) #define MAP_LEVEL_CONSOLES 0x040 // Z-levels available to various consoles, such as the crew monitor (when that gets coded in). Defaults to station_levels if unset. + +// Misc map defines. +#define SUBMAP_MAP_EDGE_PAD 15 // Automatically created submaps are forbidden from being this close to the main map's edge. \ No newline at end of file diff --git a/code/controllers/Processes/planet.dm b/code/controllers/Processes/planet.dm index 063d6d3fb9..f9fd57f788 100644 --- a/code/controllers/Processes/planet.dm +++ b/code/controllers/Processes/planet.dm @@ -51,9 +51,10 @@ var/datum/controller/process/planet/planet_controller = null //Redraw weather icons for(var/T in P.planet_floors) var/turf/simulated/turf = T - turf.overlays -= turf.weather_overlay + // turf.overlays -= turf.weather_overlay turf.weather_overlay = new_overlay - turf.overlays += turf.weather_overlay + // turf.overlays += turf.weather_overlay + turf.update_icon() SCHECK //Sun light needs changing diff --git a/code/controllers/master.dm b/code/controllers/master.dm index 5056e82e7b..4ca4bebf0a 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -540,10 +540,10 @@ var/datum/controller/master/Master = new() stat("Byond:", "(FPS:[world.fps]) (TickCount:[world.time/world.tick_lag]) (TickDrift:[round(Master.tickdrift,1)]([round((Master.tickdrift/(world.time/world.tick_lag))*100,0.1)]%))") stat("Master Controller:", statclick.update("(TickRate:[Master.processing]) (Iteration:[Master.iteration])")) -/datum/controller/master/StartLoadingMap() +/datum/controller/master/StartLoadingMap(var/quiet = TRUE) if(map_loading) admin_notice("Another map is attempting to be loaded before first map released lock. Delaying.", R_DEBUG) - else + else if(!quiet) admin_notice("Map is now being built. Locking.", R_DEBUG) //disallow more than one map to load at once, multithreading it will just cause race conditions @@ -557,8 +557,9 @@ var/datum/controller/master/Master = new() air_processing_killed = TRUE map_loading = TRUE -/datum/controller/master/StopLoadingMap(bounds = null) - admin_notice("Map is finished. Unlocking.", R_DEBUG) +/datum/controller/master/StopLoadingMap(var/quiet = TRUE) + if(!quiet) + admin_notice("Map is finished. Unlocking.", R_DEBUG) air_processing_killed = FALSE map_loading = FALSE for(var/S in subsystems) diff --git a/code/controllers/subsystems/creation.dm b/code/controllers/subsystems/creation.dm index e92a0447c8..d6f4b3c9c5 100644 --- a/code/controllers/subsystems/creation.dm +++ b/code/controllers/subsystems/creation.dm @@ -13,10 +13,10 @@ SUBSYSTEM_DEF(creation) var/map_loading = FALSE -/datum/controller/subsystem/creation/StartLoadingMap() +/datum/controller/subsystem/creation/StartLoadingMap(var/quiet) map_loading = TRUE -/datum/controller/subsystem/creation/StopLoadingMap() +/datum/controller/subsystem/creation/StopLoadingMap(var/quiet) map_loading = FALSE /datum/controller/subsystem/creation/proc/initialize_late_atoms() diff --git a/code/game/turfs/simulated/floor_icon.dm b/code/game/turfs/simulated/floor_icon.dm index 9a7fec800a..4bc4911f2e 100644 --- a/code/game/turfs/simulated/floor_icon.dm +++ b/code/game/turfs/simulated/floor_icon.dm @@ -5,6 +5,8 @@ var/list/flooring_cache = list() if(lava) return + overlays.Cut() + if(flooring) // Set initial icon and strings. name = flooring.name @@ -20,7 +22,6 @@ var/list/flooring_cache = list() flooring_override = icon_state // Apply edges, corners, and inner corners. - overlays.Cut() var/has_border = 0 if(flooring.flags & TURF_HAS_EDGES) for(var/step_dir in cardinal) diff --git a/code/game/turfs/simulated/outdoors/grass.dm b/code/game/turfs/simulated/outdoors/grass.dm index 6693c45874..1870f8bd81 100644 --- a/code/game/turfs/simulated/outdoors/grass.dm +++ b/code/game/turfs/simulated/outdoors/grass.dm @@ -20,12 +20,12 @@ var/list/grass_types = list( grass_chance = 0 var/tree_chance = 2 -/turf/simulated/floor/outdoors/grass/sif/New() +/turf/simulated/floor/outdoors/grass/sif/initialize() if(tree_chance && prob(tree_chance)) new /obj/structure/flora/tree/sif(src) ..() -/turf/simulated/floor/outdoors/grass/New() +/turf/simulated/floor/outdoors/grass/initialize() if(prob(50)) icon_state += "2" //edge_blending_priority++ diff --git a/code/game/turfs/simulated/outdoors/outdoors.dm b/code/game/turfs/simulated/outdoors/outdoors.dm index e5c6465329..941aa5abc9 100644 --- a/code/game/turfs/simulated/outdoors/outdoors.dm +++ b/code/game/turfs/simulated/outdoors/outdoors.dm @@ -40,7 +40,10 @@ var/list/outdoor_turfs = list() /turf/simulated/proc/make_indoors() outdoors = FALSE - planet_controller.unallocateTurf(src) + if(planet_controller) + planet_controller.unallocateTurf(src) + else // This is happening during map gen, if there's no planet_controller (hopefully). + outdoor_turfs -= src qdel(weather_overlay) update_icon() diff --git a/code/game/turfs/simulated/water.dm b/code/game/turfs/simulated/water.dm index 8e32a004d9..6f2c606c0d 100644 --- a/code/game/turfs/simulated/water.dm +++ b/code/game/turfs/simulated/water.dm @@ -19,8 +19,8 @@ update_icon() /turf/simulated/floor/water/update_icon() - ..() // To get the edges. This also gets rid of other overlays so it needs to go first. overlays.Cut() + ..() // To get the edges. icon_state = water_state var/image/floorbed_sprite = image(icon = 'icons/turf/outdoors.dmi', icon_state = under_state) underlays.Add(floorbed_sprite) diff --git a/code/modules/maps/tg/map_template.dm b/code/modules/maps/tg/map_template.dm index 3aaf324463..54b08c74d9 100644 --- a/code/modules/maps/tg/map_template.dm +++ b/code/modules/maps/tg/map_template.dm @@ -18,6 +18,12 @@ var/list/global/map_templates = list() 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/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/static/dmm_suite/maploader = new /datum/map_template/New(path = null, rename = null) @@ -111,7 +117,7 @@ var/list/global/map_templates = list() log_game("Z-level [name] loaded at at [x],[y],[world.maxz]") return TRUE -/datum/map_template/proc/load(turf/T, centered = FALSE) +/datum/map_template/proc/load(turf/T, centered = FALSE, dont_init = FALSE) var/old_T = T if(centered) T = locate(T.x - round(width/2) , T.y - round(height/2) , T.z) @@ -133,7 +139,8 @@ var/list/global/map_templates = list() // repopulate_sorted_areas() //initialize things that are normally initialized after map load - initTemplateBounds(bounds) + if(!dont_init) + initTemplateBounds(bounds) log_game("[name] loaded at at [T.x],[T.y],[T.z]") loaded++ @@ -163,4 +170,118 @@ var/list/global/map_templates = list() //❤ - Cyberboss /proc/load_new_z_level(var/file, var/name) var/datum/map_template/template = new(file, name) - template.load_new_z() \ No newline at end of file + template.load_new_z() + +// Very similar to the /tg/ version. +/proc/seed_submaps(var/list/z_levels, var/budget = 0, var/whitelist = /area/space, var/desired_map_template_type = null) + set background = TRUE + + if(!z_levels || !z_levels.len) + admin_notice("seed_submaps() was not given any Z-levels.", R_DEBUG) + return + + for(var/zl in z_levels) + var/turf/T = locate(1, 1, zl) + if(!T) + admin_notice("Z level [zl] does not exist - Not generating submaps", R_DEBUG) + return + + var/overall_sanity = 100 // If the proc fails to place a submap more than this, the whole thing aborts. + var/list/potential_submaps = list() // Submaps we may or may not place. + var/list/priority_submaps = list() // Submaps that will always be placed. + + // Lets go find some submaps to make. + for(var/map in map_templates) + var/datum/map_template/MT = map_templates[map] + if(!MT.allow_duplicates && MT.loaded > 0) // This probably won't be an issue but we might as well. + continue + if(!istype(MT, desired_map_template_type)) // Not the type wanted. + continue + if(MT.cost && MT.cost < 0) // Negative costs always get spawned. + priority_submaps += MT + else + potential_submaps += MT + + CHECK_TICK + + var/list/loaded_submap_names = list() + + // Now lets start choosing some. + while(budget > 0 && overall_sanity > 0) + overall_sanity-- + var/datum/map_template/chosen_template = null + + if(potential_submaps.len) + if(priority_submaps.len) // Do these first. + chosen_template = pick(priority_submaps) + else + chosen_template = pick(potential_submaps) + + else // We're out of submaps. + admin_notice("Submap loader had no submaps to pick from with [budget] left to spend.", R_DEBUG) + break + + CHECK_TICK + + // Can we afford it? + if(chosen_template.cost > budget) + continue + + // If so, try to place it. + var/specific_sanity = 100 // A hundred chances to place the chosen submap. + while(specific_sanity > 0) + specific_sanity-- + var/width_border = TRANSITIONEDGE + SUBMAP_MAP_EDGE_PAD + round(chosen_template.width / 2) + var/height_border = TRANSITIONEDGE + SUBMAP_MAP_EDGE_PAD + round(chosen_template.height / 2) + var/z_level = pick(z_levels) + var/turf/T = locate(rand(width_border, world.maxx - width_border), rand(height_border, world.maxy - height_border), z_level) + var/valid = TRUE + + for(var/turf/check in chosen_template.get_affected_turfs(T,1)) + var/area/new_area = get_area(check) + if(!(istype(new_area, whitelist))) + valid = FALSE // Probably overlapping something important. + // world << "Invalid due to overlapping with area [new_area.type], when wanting area [whitelist]." + break + CHECK_TICK + + CHECK_TICK + + if(!valid) + continue + + admin_notice("Submap \"[chosen_template.name]\" placed at ([T.x], [T.y], [T.z])", R_DEBUG) + + // Do loading here. + chosen_template.load(T, centered = TRUE, dont_init = TRUE) // This is run before the main map's initialization routine, so that can initilize our submaps for us instead. + + CHECK_TICK + + if(loaded_submap_names[chosen_template.name]) + loaded_submap_names[chosen_template.name] += 1 + else + loaded_submap_names[chosen_template.name] = 1 + + if(chosen_template.cost >= 0) + budget -= chosen_template.cost + + if(chosen_template in priority_submaps) // Always remove priority submaps. + priority_submaps -= chosen_template + else if(!chosen_template.allow_duplicates) + potential_submaps -= chosen_template + + break // Load the next submap. + + var/list/pretty_submap_list = list() + for(var/submap_name in loaded_submap_names) + var/count = loaded_submap_names[submap_name] + if(count > 1) + pretty_submap_list += "[count] [submap_name]" + else + pretty_submap_list += "[submap_name]" + + if(!overall_sanity) + admin_notice("Submap loader gave up with [budget] left to spend.", R_DEBUG) + else + admin_notice("Submaps loaded.", R_DEBUG) + admin_notice("Loaded: [english_list(pretty_submap_list)]", R_DEBUG) \ No newline at end of file diff --git a/maps/southern_cross/southern_cross_defines.dm b/maps/southern_cross/southern_cross_defines.dm index 4a6782094b..fb70f74cbf 100644 --- a/maps/southern_cross/southern_cross_defines.dm +++ b/maps/southern_cross/southern_cross_defines.dm @@ -65,9 +65,19 @@ else return ..() -/datum/map/northern_star/perform_map_generation() +/datum/map/southern_cross/perform_map_generation() + // First, place a bunch of submaps. This comes before tunnel/forest generation as to not interfere with the submap. + + // Cave submaps are first. + seed_submaps(list(Z_LEVEL_SURFACE_MINE), 100, /area/mine/unexplored, /datum/map_template/cave) + // Wilderness is next. + seed_submaps(list(Z_LEVEL_SURFACE_WILD), 100, /area/surface/outside/wilderness, /datum/map_template/surface) + // If Space submaps are made, add a line to make them here as well. + + // Now for the tunnels. new /datum/random_map/automata/cave_system(null, 1, 1, Z_LEVEL_SURFACE_MINE, world.maxx, world.maxy) // Create the mining Z-level. new /datum/random_map/noise/ore(null, 1, 1, Z_LEVEL_SURFACE_MINE, 64, 64) // Create the mining ore distribution map. + // Todo: Forest generation. return 1 /datum/map_z_level/southern_cross/station diff --git a/maps/submaps/cave_submaps/cave.dm b/maps/submaps/cave_submaps/cave.dm index 87ab786d79..afe12a7bca 100644 --- a/maps/submaps/cave_submaps/cave.dm +++ b/maps/submaps/cave_submaps/cave.dm @@ -17,13 +17,16 @@ name = "Abandoned Relay" desc = "An unregistered comms relay, abandoned to the elements." mappath = 'maps/submaps/cave_submaps/deadBeacon.dmm' + cost = 10 /datum/map_template/cave/prepper1 name = "Prepper Bunker" desc = "A little hideaway for someone with more time and money than sense." mappath = 'maps/submaps/cave_submaps/prepper1.dmm' + cost = 10 /datum/map_template/cave/qshuttle name = "Quarantined Shuttle" desc = "An emergency landing turned viral outbreak turned tragedy." - mappath = 'maps/submaps/cave_submaps/quarantineshuttle.dmm' \ No newline at end of file + mappath = 'maps/submaps/cave_submaps/quarantineshuttle.dmm' + cost = 20 \ No newline at end of file diff --git a/maps/submaps/surface_submaps/forest.dm b/maps/submaps/surface_submaps/forest.dm index 6cd100a497..485fe17b1f 100644 --- a/maps/submaps/surface_submaps/forest.dm +++ b/maps/submaps/surface_submaps/forest.dm @@ -8,7 +8,7 @@ /datum/map_template/surface name = "Surface Content" - desc = "Used to make the surface by 17% less boring." + desc = "Used to make the surface be 17% less boring." // To be added: Templates for surface exploration when they are made. @@ -16,8 +16,11 @@ name = "Farm 1" desc = "A small farm tended by a farmbot." mappath = 'maps/submaps/surface_submaps/farm1.dmm' + cost = 10 /datum/map_template/surface/spider1 name = "Spider Nest 1" desc = "A small spider nest, in the forest." - mappath = 'maps/submaps/surface_submaps/spider1.dmm' \ No newline at end of file + mappath = 'maps/submaps/surface_submaps/spider1.dmm' + allow_duplicates = TRUE + cost = 5 \ No newline at end of file