Adds Submap (PoI) Seeding Procedure

Mostly ports /tg/'s method of seeding submaps into specific z-levels.
Due to the low number of submaps present, all of the PoIs are guaranteed to spawn. As more are added, this should fix itself.
This commit is contained in:
Neerti
2017-11-21 19:21:39 -05:00
parent 0a5aa36f7a
commit fe33977812
12 changed files with 166 additions and 20 deletions

View File

@@ -6,3 +6,6 @@
#define MAP_LEVEL_SEALED 0x010 // Z-levels that don't allow random transit at edge #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_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. #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.

View File

@@ -51,9 +51,10 @@ var/datum/controller/process/planet/planet_controller = null
//Redraw weather icons //Redraw weather icons
for(var/T in P.planet_floors) for(var/T in P.planet_floors)
var/turf/simulated/turf = T var/turf/simulated/turf = T
turf.overlays -= turf.weather_overlay // turf.overlays -= turf.weather_overlay
turf.weather_overlay = new_overlay turf.weather_overlay = new_overlay
turf.overlays += turf.weather_overlay // turf.overlays += turf.weather_overlay
turf.update_icon()
SCHECK SCHECK
//Sun light needs changing //Sun light needs changing

View File

@@ -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("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])")) 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) if(map_loading)
admin_notice("<span class='danger'>Another map is attempting to be loaded before first map released lock. Delaying.</span>", R_DEBUG) admin_notice("<span class='danger'>Another map is attempting to be loaded before first map released lock. Delaying.</span>", R_DEBUG)
else else if(!quiet)
admin_notice("<span class='danger'>Map is now being built. Locking.</span>", R_DEBUG) admin_notice("<span class='danger'>Map is now being built. Locking.</span>", R_DEBUG)
//disallow more than one map to load at once, multithreading it will just cause race conditions //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 air_processing_killed = TRUE
map_loading = TRUE map_loading = TRUE
/datum/controller/master/StopLoadingMap(bounds = null) /datum/controller/master/StopLoadingMap(var/quiet = TRUE)
admin_notice("<span class='danger'>Map is finished. Unlocking.</span>", R_DEBUG) if(!quiet)
admin_notice("<span class='danger'>Map is finished. Unlocking.</span>", R_DEBUG)
air_processing_killed = FALSE air_processing_killed = FALSE
map_loading = FALSE map_loading = FALSE
for(var/S in subsystems) for(var/S in subsystems)

View File

@@ -13,10 +13,10 @@ SUBSYSTEM_DEF(creation)
var/map_loading = FALSE var/map_loading = FALSE
/datum/controller/subsystem/creation/StartLoadingMap() /datum/controller/subsystem/creation/StartLoadingMap(var/quiet)
map_loading = TRUE map_loading = TRUE
/datum/controller/subsystem/creation/StopLoadingMap() /datum/controller/subsystem/creation/StopLoadingMap(var/quiet)
map_loading = FALSE map_loading = FALSE
/datum/controller/subsystem/creation/proc/initialize_late_atoms() /datum/controller/subsystem/creation/proc/initialize_late_atoms()

View File

@@ -5,6 +5,8 @@ var/list/flooring_cache = list()
if(lava) if(lava)
return return
overlays.Cut()
if(flooring) if(flooring)
// Set initial icon and strings. // Set initial icon and strings.
name = flooring.name name = flooring.name
@@ -20,7 +22,6 @@ var/list/flooring_cache = list()
flooring_override = icon_state flooring_override = icon_state
// Apply edges, corners, and inner corners. // Apply edges, corners, and inner corners.
overlays.Cut()
var/has_border = 0 var/has_border = 0
if(flooring.flags & TURF_HAS_EDGES) if(flooring.flags & TURF_HAS_EDGES)
for(var/step_dir in cardinal) for(var/step_dir in cardinal)

View File

@@ -20,12 +20,12 @@ var/list/grass_types = list(
grass_chance = 0 grass_chance = 0
var/tree_chance = 2 var/tree_chance = 2
/turf/simulated/floor/outdoors/grass/sif/New() /turf/simulated/floor/outdoors/grass/sif/initialize()
if(tree_chance && prob(tree_chance)) if(tree_chance && prob(tree_chance))
new /obj/structure/flora/tree/sif(src) new /obj/structure/flora/tree/sif(src)
..() ..()
/turf/simulated/floor/outdoors/grass/New() /turf/simulated/floor/outdoors/grass/initialize()
if(prob(50)) if(prob(50))
icon_state += "2" icon_state += "2"
//edge_blending_priority++ //edge_blending_priority++

View File

@@ -40,7 +40,10 @@ var/list/outdoor_turfs = list()
/turf/simulated/proc/make_indoors() /turf/simulated/proc/make_indoors()
outdoors = FALSE 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) qdel(weather_overlay)
update_icon() update_icon()

View File

@@ -19,8 +19,8 @@
update_icon() update_icon()
/turf/simulated/floor/water/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() overlays.Cut()
..() // To get the edges.
icon_state = water_state icon_state = water_state
var/image/floorbed_sprite = image(icon = 'icons/turf/outdoors.dmi', icon_state = under_state) var/image/floorbed_sprite = image(icon = 'icons/turf/outdoors.dmi', icon_state = under_state)
underlays.Add(floorbed_sprite) underlays.Add(floorbed_sprite)

View File

@@ -18,6 +18,12 @@ var/list/global/map_templates = list()
var/mappath = null var/mappath = null
var/loaded = 0 // Times loaded this round 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/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 var/static/dmm_suite/maploader = new
/datum/map_template/New(path = null, rename = null) /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]") log_game("Z-level [name] loaded at at [x],[y],[world.maxz]")
return TRUE 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 var/old_T = T
if(centered) if(centered)
T = locate(T.x - round(width/2) , T.y - round(height/2) , T.z) 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() // repopulate_sorted_areas()
//initialize things that are normally initialized after map load //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]") log_game("[name] loaded at at [T.x],[T.y],[T.z]")
loaded++ loaded++
@@ -163,4 +170,118 @@ var/list/global/map_templates = list()
//❤ - Cyberboss //❤ - Cyberboss
/proc/load_new_z_level(var/file, var/name) /proc/load_new_z_level(var/file, var/name)
var/datum/map_template/template = new(file, name) var/datum/map_template/template = new(file, name)
template.load_new_z() 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] <b>[submap_name]</b>"
else
pretty_submap_list += "<b>[submap_name]</b>"
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)

View File

@@ -65,9 +65,19 @@
else else
return ..() 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/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. 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 return 1
/datum/map_z_level/southern_cross/station /datum/map_z_level/southern_cross/station

View File

@@ -17,13 +17,16 @@
name = "Abandoned Relay" name = "Abandoned Relay"
desc = "An unregistered comms relay, abandoned to the elements." desc = "An unregistered comms relay, abandoned to the elements."
mappath = 'maps/submaps/cave_submaps/deadBeacon.dmm' mappath = 'maps/submaps/cave_submaps/deadBeacon.dmm'
cost = 10
/datum/map_template/cave/prepper1 /datum/map_template/cave/prepper1
name = "Prepper Bunker" name = "Prepper Bunker"
desc = "A little hideaway for someone with more time and money than sense." desc = "A little hideaway for someone with more time and money than sense."
mappath = 'maps/submaps/cave_submaps/prepper1.dmm' mappath = 'maps/submaps/cave_submaps/prepper1.dmm'
cost = 10
/datum/map_template/cave/qshuttle /datum/map_template/cave/qshuttle
name = "Quarantined Shuttle" name = "Quarantined Shuttle"
desc = "An emergency landing turned viral outbreak turned tragedy." desc = "An emergency landing turned viral outbreak turned tragedy."
mappath = 'maps/submaps/cave_submaps/quarantineshuttle.dmm' mappath = 'maps/submaps/cave_submaps/quarantineshuttle.dmm'
cost = 20

View File

@@ -8,7 +8,7 @@
/datum/map_template/surface /datum/map_template/surface
name = "Surface Content" 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. // To be added: Templates for surface exploration when they are made.
@@ -16,8 +16,11 @@
name = "Farm 1" name = "Farm 1"
desc = "A small farm tended by a farmbot." desc = "A small farm tended by a farmbot."
mappath = 'maps/submaps/surface_submaps/farm1.dmm' mappath = 'maps/submaps/surface_submaps/farm1.dmm'
cost = 10
/datum/map_template/surface/spider1 /datum/map_template/surface/spider1
name = "Spider Nest 1" name = "Spider Nest 1"
desc = "A small spider nest, in the forest." desc = "A small spider nest, in the forest."
mappath = 'maps/submaps/surface_submaps/spider1.dmm' mappath = 'maps/submaps/surface_submaps/spider1.dmm'
allow_duplicates = TRUE
cost = 5