From 4e9731712ad253f1b95b1436aa1414ed24e68968 Mon Sep 17 00:00:00 2001 From: Seth Scherer Date: Tue, 1 Mar 2022 23:32:43 -0500 Subject: [PATCH] Dehardcodes SSmapping (#65077) Essentially SSmapping had a list for each theme of ruin (space, lava, ice, ice underground). These were all filled with an if statement checking the ruin templates type. Now, i've given ruins a ruin_type var, which is then used to dynamically add to a single list of ruins, which separates lists of ruins by ruin type. Good for downstreams who may have more ruin types Changelog cl refactor: Dehardcoded SSmapping ruin types. /cl --- code/__DEFINES/maps.dm | 4 +- code/controllers/subsystem/mapping.dm | 83 ++++++++++++++------------- code/datums/ruins.dm | 2 + code/datums/ruins/icemoon.dm | 4 ++ code/datums/ruins/lavaland.dm | 2 + code/datums/ruins/space.dm | 2 + code/modules/admin/verbs/debug.dm | 18 ++---- code/modules/mapping/map_template.dm | 3 + 8 files changed, 64 insertions(+), 54 deletions(-) diff --git a/code/__DEFINES/maps.dm b/code/__DEFINES/maps.dm index 7a5c4ff986c..9335a9214fa 100644 --- a/code/__DEFINES/maps.dm +++ b/code/__DEFINES/maps.dm @@ -166,7 +166,7 @@ require only minor tweaks. #define BIOME_HIGH_HUMIDITY "high_humidity" // Bluespace shelter deploy checks for survival capsules -/// Shelter spot is allowed +/// Shelter spot is allowed #define SHELTER_DEPLOY_ALLOWED "allowed" /// Shelter spot has turfs that restrict deployment #define SHELTER_DEPLOY_BAD_TURFS "bad turfs" @@ -174,5 +174,5 @@ require only minor tweaks. #define SHELTER_DEPLOY_BAD_AREA "bad area" /// Shelter spot has anchored objects that restrict deployment #define SHELTER_DEPLOY_ANCHORED_OBJECTS "anchored objects" -/// Shelter spot is out of bounds from the maps x/y coordinates +/// Shelter spot is out of bounds from the maps x/y coordinates #define SHELTER_DEPLOY_OUTSIDE_MAP "outside map" diff --git a/code/controllers/subsystem/mapping.dm b/code/controllers/subsystem/mapping.dm index 0a19cc60089..c96172757cc 100644 --- a/code/controllers/subsystem/mapping.dm +++ b/code/controllers/subsystem/mapping.dm @@ -14,10 +14,9 @@ SUBSYSTEM_DEF(mapping) var/list/map_templates = list() var/list/ruins_templates = list() - var/list/space_ruins_templates = list() - var/list/lava_ruins_templates = list() - var/list/ice_ruins_templates = list() - var/list/ice_ruins_underground_templates = list() + + ///List of ruins, separated by their theme + var/list/themed_ruins = list() var/datum/space_level/isolated_ruins_z //Created on demand during ruin loading. @@ -91,32 +90,10 @@ SUBSYSTEM_DEF(mapping) load_new_z_level("_maps/RandomZLevels/VR/vrhub.dmm", "Virtual Reality Hub") to_chat(world, span_boldannounce("Virtual reality loaded.")) - // Generate mining ruins loading_ruins = TRUE - var/list/lava_ruins = levels_by_trait(ZTRAIT_LAVA_RUINS) - if (lava_ruins.len) - seedRuins(lava_ruins, CONFIG_GET(number/lavaland_budget), list(/area/lavaland/surface/outdoors/unexplored), lava_ruins_templates) - for (var/lava_z in lava_ruins) - spawn_rivers(lava_z) - - var/list/ice_ruins = levels_by_trait(ZTRAIT_ICE_RUINS) - if (ice_ruins.len) - // needs to be whitelisted for underground too so place_below ruins work - seedRuins(ice_ruins, CONFIG_GET(number/icemoon_budget), list(/area/icemoon/surface/outdoors/unexplored, /area/icemoon/underground/unexplored), ice_ruins_templates) - for (var/ice_z in ice_ruins) - spawn_rivers(ice_z, 4, /turf/open/openspace/icemoon, /area/icemoon/surface/outdoors/unexplored/rivers) - - var/list/ice_ruins_underground = levels_by_trait(ZTRAIT_ICE_RUINS_UNDERGROUND) - if (ice_ruins_underground.len) - seedRuins(ice_ruins_underground, CONFIG_GET(number/icemoon_budget), list(/area/icemoon/underground/unexplored), ice_ruins_underground_templates) - for (var/ice_z in ice_ruins_underground) - spawn_rivers(ice_z, 4, level_trait(ice_z, ZTRAIT_BASETURF), /area/icemoon/underground/unexplored/rivers) - - // Generate deep space ruins - var/list/space_ruins = levels_by_trait(ZTRAIT_SPACE_RUINS) - if (space_ruins.len) - seedRuins(space_ruins, CONFIG_GET(number/space_budget), list(/area/space), space_ruins_templates) + setup_ruins() loading_ruins = FALSE + #endif // Run map generation after ruin generation to prevent issues run_map_generation() @@ -130,6 +107,37 @@ SUBSYSTEM_DEF(mapping) SSticker.OnRoundstart(CALLBACK(src, .proc/spawn_maintenance_loot)) return ..() +/** + * ##setup_ruins + * + * Sets up all of the ruins to be spawned + */ +/datum/controller/subsystem/mapping/proc/setup_ruins() + // Generate mining ruins + var/list/lava_ruins = levels_by_trait(ZTRAIT_LAVA_RUINS) + if (lava_ruins.len) + seedRuins(lava_ruins, CONFIG_GET(number/lavaland_budget), list(/area/lavaland/surface/outdoors/unexplored), themed_ruins[ZTRAIT_LAVA_RUINS]) + for (var/lava_z in lava_ruins) + spawn_rivers(lava_z) + + var/list/ice_ruins = levels_by_trait(ZTRAIT_ICE_RUINS) + if (ice_ruins.len) + // needs to be whitelisted for underground too so place_below ruins work + seedRuins(ice_ruins, CONFIG_GET(number/icemoon_budget), list(/area/icemoon/surface/outdoors/unexplored, /area/icemoon/underground/unexplored), themed_ruins[ZTRAIT_ICE_RUINS]) + for (var/ice_z in ice_ruins) + spawn_rivers(ice_z, 4, /turf/open/openspace/icemoon, /area/icemoon/surface/outdoors/unexplored/rivers) + + var/list/ice_ruins_underground = levels_by_trait(ZTRAIT_ICE_RUINS_UNDERGROUND) + if (ice_ruins_underground.len) + seedRuins(ice_ruins_underground, CONFIG_GET(number/icemoon_budget), list(/area/icemoon/underground/unexplored), themed_ruins[ZTRAIT_ICE_RUINS_UNDERGROUND]) + for (var/ice_z in ice_ruins_underground) + spawn_rivers(ice_z, 4, level_trait(ice_z, ZTRAIT_BASETURF), /area/icemoon/underground/unexplored/rivers) + + // Generate deep space ruins + var/list/space_ruins = levels_by_trait(ZTRAIT_SPACE_RUINS) + if (space_ruins.len) + seedRuins(space_ruins, CONFIG_GET(number/space_budget), list(/area/space), themed_ruins[ZTRAIT_SPACE_RUINS]) + /datum/controller/subsystem/mapping/proc/wipe_reservations(wipe_safety_delay = 100) if(clearing_reserved_turfs || !initialized) //in either case this is just not needed. return @@ -185,10 +193,10 @@ Used by the AI doomsday and the self-destruct nuke. initialized = SSmapping.initialized map_templates = SSmapping.map_templates ruins_templates = SSmapping.ruins_templates - space_ruins_templates = SSmapping.space_ruins_templates - lava_ruins_templates = SSmapping.lava_ruins_templates - ice_ruins_templates = SSmapping.ice_ruins_templates - ice_ruins_underground_templates = SSmapping.ice_ruins_underground_templates + + for (var/theme in SSmapping.themed_ruins) + themed_ruins[theme] = SSmapping.themed_ruins[theme] + shuttle_templates = SSmapping.shuttle_templates shelter_templates = SSmapping.shelter_templates unused_turfs = SSmapping.unused_turfs @@ -428,14 +436,9 @@ GLOBAL_LIST_EMPTY(the_station_areas) map_templates[R.name] = R ruins_templates[R.name] = R - if(istype(R, /datum/map_template/ruin/lavaland)) - lava_ruins_templates[R.name] = R - else if(istype(R, /datum/map_template/ruin/icemoon/underground)) - ice_ruins_underground_templates[R.name] = R - else if(istype(R, /datum/map_template/ruin/icemoon)) - ice_ruins_templates[R.name] = R - else if(istype(R, /datum/map_template/ruin/space)) - space_ruins_templates[R.name] = R + if (!(R.ruin_type in themed_ruins)) + themed_ruins[R.ruin_type] = list() + themed_ruins[R.ruin_type][R.name] = R /datum/controller/subsystem/mapping/proc/preloadShuttleTemplates() var/list/unbuyable = generateMapList("unbuyableshuttles.txt") diff --git a/code/datums/ruins.dm b/code/datums/ruins.dm index fd1061b9383..2a7b73d1f7e 100644 --- a/code/datums/ruins.dm +++ b/code/datums/ruins.dm @@ -17,6 +17,8 @@ var/prefix = null var/suffix = null + var/ruin_type = null + /datum/map_template/ruin/New() if(!name && id) name = id diff --git a/code/datums/ruins/icemoon.dm b/code/datums/ruins/icemoon.dm index b7ffbc57865..ebe5b786d53 100644 --- a/code/datums/ruins/icemoon.dm +++ b/code/datums/ruins/icemoon.dm @@ -4,6 +4,8 @@ prefix = "_maps/RandomRuins/IceRuins/" allow_duplicates = FALSE cost = 5 + ruin_type = ZTRAIT_ICE_RUINS + default_area = /area/icemoon/surface/outdoors/unexplored // above ground only @@ -71,6 +73,8 @@ /datum/map_template/ruin/icemoon/underground name = "underground ruin" + ruin_type = ZTRAIT_ICE_RUINS_UNDERGROUND + default_area = /area/icemoon/underground/unexplored /datum/map_template/ruin/icemoon/underground/abandonedvillage name = "Abandoned Village" diff --git a/code/datums/ruins/lavaland.dm b/code/datums/ruins/lavaland.dm index 97df891af8a..21b9dffa117 100644 --- a/code/datums/ruins/lavaland.dm +++ b/code/datums/ruins/lavaland.dm @@ -1,7 +1,9 @@ // Hey! Listen! Update \config\lavaruinblacklist.txt with your new ruins! /datum/map_template/ruin/lavaland + ruin_type = ZTRAIT_LAVA_RUINS prefix = "_maps/RandomRuins/LavaRuins/" + default_area = /area/lavaland/surface/outdoors/unexplored /datum/map_template/ruin/lavaland/biodome cost = 5 diff --git a/code/datums/ruins/space.dm b/code/datums/ruins/space.dm index 78f99d428f6..78b66556c82 100644 --- a/code/datums/ruins/space.dm +++ b/code/datums/ruins/space.dm @@ -4,6 +4,8 @@ prefix = "_maps/RandomRuins/SpaceRuins/" cost = 1 allow_duplicates = FALSE + ruin_type = ZTRAIT_SPACE_RUINS + default_area = /area/space /datum/map_template/ruin/space/zoo id = "zoo" diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm index 2fbcb87e1bf..8369e4d03ce 100644 --- a/code/modules/admin/verbs/debug.dm +++ b/code/modules/admin/verbs/debug.dm @@ -654,18 +654,12 @@ But you can call procs that are of type /mob/living/carbon/human/proc/ for that exists[L.ruin_template] = landmark var/list/names = list() - names += "---- Space Ruins ----" - for(var/name in SSmapping.space_ruins_templates) - names[name] = list(SSmapping.space_ruins_templates[name], ZTRAIT_SPACE_RUINS, list(/area/space)) - names += "---- Lava Ruins ----" - for(var/name in SSmapping.lava_ruins_templates) - names[name] = list(SSmapping.lava_ruins_templates[name], ZTRAIT_LAVA_RUINS, list(/area/lavaland/surface/outdoors/unexplored)) - names += "---- Ice Ruins ----" - for(var/name in SSmapping.ice_ruins_templates) - names[name] = list(SSmapping.ice_ruins_templates[name], ZTRAIT_ICE_RUINS, list(/area/icemoon/surface/outdoors/unexplored, /area/icemoon/underground/unexplored)) - names += "---- Ice Underground Ruins ----" - for(var/name in SSmapping.ice_ruins_underground_templates) - names[name] = list(SSmapping.ice_ruins_underground_templates[name], ZTRAIT_ICE_RUINS_UNDERGROUND, list(/area/icemoon/underground/unexplored)) + for (var/theme in SSmapping.themed_ruins) + names += "---- [theme] ----" + for (var/name in SSmapping.themed_ruins[theme]) + var/datum/map_template/ruin/ruin = SSmapping.themed_ruins[theme][name] + names[name] = list(ruin, theme, list(ruin.default_area)) + var/ruinname = input("Select ruin", "Spawn Ruin") as null|anything in sort_list(names) var/data = names[ruinname] diff --git a/code/modules/mapping/map_template.dm b/code/modules/mapping/map_template.dm index c132bad24d1..76e25931bc9 100644 --- a/code/modules/mapping/map_template.dm +++ b/code/modules/mapping/map_template.dm @@ -8,6 +8,9 @@ var/keep_cached_map = FALSE var/station_id = null // used to override the root id when generating + ///Default area associated with the map template + var/default_area + ///if true, turfs loaded from this template are placed on top of the turfs already there, defaults to TRUE var/should_place_on_top = TRUE