From 8188f08cc7653f9cbbead7b3d13b4fe9946ef868 Mon Sep 17 00:00:00 2001 From: Constable Glist <87862013+ImJustKisik@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:19:40 +0700 Subject: [PATCH] remove lack of faster xenoarch init (#2720) --- baystation12.dme | 1 + code/_helpers/lists.dm | 20 +++-- .../subsystems/initialization/misc_late.dm | 89 ------------------- .../subsystems/initialization/xenoarch.dm | 85 ++++++++++++++++++ code/controllers/subsystems/machines.dm | 5 +- code/controllers/subsystems/mapping.dm | 2 + code/modules/mining/mine_turfs.dm | 16 ++-- code/modules/xenoarcheaology/sampling.dm | 4 +- code/modules/xenoarcheaology/tools/tools.dm | 8 +- maps/mapsystem/maps.dm | 3 +- 10 files changed, 116 insertions(+), 117 deletions(-) create mode 100644 code/controllers/subsystems/initialization/xenoarch.dm diff --git a/baystation12.dme b/baystation12.dme index a837576e39875..32a76d5f25dc7 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -243,6 +243,7 @@ #include "code\controllers\subsystems\initialization\persistence.dm" #include "code\controllers\subsystems\initialization\robots.dm" #include "code\controllers\subsystems\initialization\webhooks.dm" +#include "code\controllers\subsystems\initialization\xenoarch.dm" #include "code\controllers\subsystems\processing\circuit.dm" #include "code\controllers\subsystems\processing\disposals.dm" #include "code\controllers\subsystems\processing\fast_process.dm" diff --git a/code/_helpers/lists.dm b/code/_helpers/lists.dm index 1da8edf278d86..dff483c6d15c4 100644 --- a/code/_helpers/lists.dm +++ b/code/_helpers/lists.dm @@ -237,13 +237,19 @@ Checks if a list has the same entries and values as an element of big. return len return null -//Pick a random element from the list and remove it from the list. -/proc/pick_n_take(list/listfrom) - if (length(listfrom) > 0) - var/picked = pick(listfrom) - listfrom -= picked - return picked - return null +/// Pick a random element from the list and remove it from the list. +/proc/pick_n_take(list/list_to_pick) + RETURN_TYPE(list_to_pick[_].type) + + var/list_length = length(list_to_pick) + if(!list_length) + return null + + var/picked_index = rand(1, list_length) + var/picked = list_to_pick[picked_index] + list_to_pick.Cut(picked_index, picked_index + 1) + + return picked /// Remove and return the last element of the list, or null. diff --git a/code/controllers/subsystems/initialization/misc_late.dm b/code/controllers/subsystems/initialization/misc_late.dm index 27cab259e3086..75d9de9a90fa8 100644 --- a/code/controllers/subsystems/initialization/misc_late.dm +++ b/code/controllers/subsystems/initialization/misc_late.dm @@ -16,7 +16,6 @@ SUBSYSTEM_DEF(init_misc_late) var/singleton/asset_cache/asset_cache = GET_SINGLETON(/singleton/asset_cache) asset_cache.load() init_recipes() - init_xenoarch() GLOBAL_VAR_INIT(microwave_maximum_item_storage, 0) @@ -54,91 +53,3 @@ GLOBAL_LIST_EMPTY(microwave_accepts_items) /proc/cmp_microwave_recipes_by_weight_dsc(datum/microwave_recipe/a, datum/microwave_recipe/b) return a.weight - b.weight - - -GLOBAL_LIST_EMPTY(xeno_artifact_turfs) -GLOBAL_LIST_EMPTY(xeno_digsite_turfs) - -/datum/controller/subsystem/init_misc_late/proc/init_xenoarch() - var/list/queue = list() - var/list/site_turfs = list() - var/list/artifact_turfs = list() - var/datum/map/map = GLOB.using_map - if (!map) - GLOB.xeno_artifact_turfs = list() - GLOB.xeno_digsite_turfs = list() - return - var/list/banned_levels = map.admin_levels + map.escape_levels - for (var/turf/simulated/mineral/M in world) - if (!M.density) - continue - if (M.z in banned_levels) - continue - if (!M.geologic_data) - M.geologic_data = new (M) - if (!prob(0.5)) - continue - var/has_space = TRUE - for (var/turf/T as anything in site_turfs) - if (T.z != M.z) - continue - if (abs(T.x - M.x) > 3) - continue - if (abs(T.y - M.y) > 3) - continue - has_space = FALSE - break - if (!has_space) - continue - site_turfs += M - queue.Cut() - queue += M - for (var/turf/simulated/mineral/T in orange(2, M)) - if (!T.density) - continue - if (T.finds) - continue - queue += T - var/site_turf_count = rand(4, 12) - if (site_turf_count < length(queue)) - for (var/i = length(queue) - site_turf_count to 1 step -1) - var/selected = rand(1, length(queue)) - queue.Cut(selected, selected + 1) - var/site_type = get_random_digsite_type() - for (var/turf/simulated/mineral/T as anything in queue) - if (!T.finds) - var/list/finds = list() - if (prob(50)) - finds += new /datum/find (site_type, rand(10, 190)) - else if (prob(75)) - finds += new /datum/find (site_type, rand(10, 90)) - finds += new /datum/find (site_type, rand(110, 190)) - else - finds += new /datum/find (site_type, rand(10, 50)) - finds += new /datum/find (site_type, rand(60, 140)) - finds += new /datum/find (site_type, rand(150, 190)) - var/datum/find/F = finds[1] - if (F.excavation_required <= F.view_range) - T.archaeo_overlay = "overlay_archaeo[rand(1, 3)]" - T.update_icon() - T.finds = finds - if (site_type == DIGSITE_GARDEN) - continue - if (site_type == DIGSITE_ANIMAL) - continue - artifact_turfs += T - CHECK_TICK - GLOB.xeno_digsite_turfs = site_turfs - GLOB.xeno_artifact_turfs = list() - for (var/i = rand(6, 12) to 1 step -1) - var/len = length(artifact_turfs) - if (len < 1) - break - var/selected = rand(1, len) - var/turf/simulated/mineral/T = artifact_turfs[selected] - artifact_turfs.Cut(selected, selected + 1) - // Failsafe for invalid turf types - if (!istype(T)) - continue - GLOB.xeno_artifact_turfs += T - T.artifact_find = new diff --git a/code/controllers/subsystems/initialization/xenoarch.dm b/code/controllers/subsystems/initialization/xenoarch.dm new file mode 100644 index 0000000000000..06f97013ec5a8 --- /dev/null +++ b/code/controllers/subsystems/initialization/xenoarch.dm @@ -0,0 +1,85 @@ +SUBSYSTEM_DEF(xenoarch) + name = "Xenoarcheology" + flags = SS_NO_FIRE + init_order = SS_INIT_XENOARCH + var/static/list/xeno_artifact_turfs = list() + var/static/list/xeno_digsite_turfs = list() + +/datum/controller/subsystem/xenoarch/Initialize(start_uptime) + var/datum/map/map = GLOB.using_map + if (!map) + return + + var/list/artifact_turfs = list() + var/static/excavation_turf_chance = 0.5 + var/list/banned_levels = map.admin_levels + map.escape_levels + for(var/z_level_index in mining_walls) + if(text2num(z_level_index) in banned_levels) + continue + + var/list/mining_turfs = mining_walls[z_level_index] + if(!length(mining_turfs)) + continue + + for(var/turf/simulated/mineral/mineral_turf as anything in mining_turfs) + if (!mineral_turf.density) + continue + + if (!mineral_turf.geologic_data) + mineral_turf.geologic_data = new(mineral_turf) + + if(!prob(excavation_turf_chance)) + continue + + xeno_digsite_turfs += mineral_turf + var/list/possible_site_turfs = list() + for(var/turf/simulated/mineral/T in RANGE_TURFS(mineral_turf, 2)) + if(!T.density) + continue + + if(T.finds) + continue + + possible_site_turfs += T + + possible_site_turfs = shuffle(possible_site_turfs) + LIST_RESIZE(possible_site_turfs, min(rand(4, 12), length(possible_site_turfs))) + + var/site_type = get_random_digsite_type() + for(var/turf/simulated/mineral/T as anything in possible_site_turfs) + if(!T.finds) + var/list/finds = list() + if (prob(50)) + finds += new /datum/find (site_type, rand(10, 190)) + else if (prob(75)) + finds += new /datum/find (site_type, rand(10, 90)) + finds += new /datum/find (site_type, rand(110, 190)) + else + finds += new /datum/find (site_type, rand(10, 50)) + finds += new /datum/find (site_type, rand(60, 140)) + finds += new /datum/find (site_type, rand(150, 190)) + var/datum/find/F = finds[1] + if (F.excavation_required <= F.view_range) + T.archaeo_overlay = "overlay_archaeo[rand(1, 3)]" + T.update_icon() + T.finds = finds + + if(site_type == DIGSITE_GARDEN) + continue + + if(site_type == DIGSITE_ANIMAL) + continue + + artifact_turfs += T + + CHECK_TICK + + var/xeno_artifact_turfs_amount = min(rand(6, 12), length(artifact_turfs)) + for (var/i = 1 to xeno_artifact_turfs_amount) + var/turf/simulated/mineral/selected_mineral = pick_n_take(artifact_turfs) + // Failsafe for invalid turf types + if (!istype(selected_mineral)) + continue + + xeno_artifact_turfs += selected_mineral + selected_mineral.artifact_find = new diff --git a/code/controllers/subsystems/machines.dm b/code/controllers/subsystems/machines.dm index 5e790fe1d778e..e4b1642b3cec1 100644 --- a/code/controllers/subsystems/machines.dm +++ b/code/controllers/subsystems/machines.dm @@ -45,13 +45,12 @@ SUBSYSTEM_DEF(machines) var/static/cost_powernets = 0 var/static/cost_power_objects = 0 var/static/list/pipenets = list() - var/static/list/machinery = list() - var/static/list/machinery_by_type = list() var/static/list/powernets = list() var/static/list/power_objects = list() var/static/list/processing = list() var/static/list/queue = list() - + var/static/list/machinery = list() + var/static/list/machinery_by_type = list() /datum/controller/subsystem/machines/Recover() current_step = SSMACHINES_PIPENETS diff --git a/code/controllers/subsystems/mapping.dm b/code/controllers/subsystems/mapping.dm index aed6e8b0d9662..83e9de98861ca 100644 --- a/code/controllers/subsystems/mapping.dm +++ b/code/controllers/subsystems/mapping.dm @@ -25,6 +25,8 @@ SUBSYSTEM_DEF(mapping) space_ruins_templates = SSmapping.space_ruins_templates exoplanet_ruins_templates = SSmapping.exoplanet_ruins_templates away_sites_templates = SSmapping.away_sites_templates + submaps = SSmapping.submaps + submap_archetypes = SSmapping.submap_archetypes /datum/controller/subsystem/mapping/proc/preloadTemplates(path = "maps/templates/") //see master controller setup var/list/filelist = flist(path) diff --git a/code/modules/mining/mine_turfs.dm b/code/modules/mining/mine_turfs.dm index 7a41280f9c118..41a946580e23b 100644 --- a/code/modules/mining/mine_turfs.dm +++ b/code/modules/mining/mine_turfs.dm @@ -41,16 +41,13 @@ var/global/list/mining_floors = list() /turf/simulated/mineral/Initialize() . = ..() - if (!mining_walls["[src.z]"]) - mining_walls["[src.z]"] = list() - mining_walls["[src.z]"] += src + LAZYADDASSOCLIST(mining_walls, "[z]", src) MineralSpread() update_icon(1) /turf/simulated/mineral/Destroy() - if (mining_walls["[src.z]"]) - mining_walls["[src.z]"] -= src - GLOB.xeno_artifact_turfs -= src + LAZYREMOVEASSOC(mining_walls, "[z]", src) + SSxenoarch.xeno_artifact_turfs -= src return ..() /turf/simulated/mineral/can_build_cable() @@ -423,15 +420,12 @@ var/global/list/mining_floors = list() /turf/simulated/floor/asteroid/Initialize() . = ..() - if (!mining_floors["[src.z]"]) - mining_floors["[src.z]"] = list() - mining_floors["[src.z]"] += src + LAZYADDASSOCLIST(mining_floors, "[z]", src) if(prob(20)) overlay_detail = "asteroid[rand(0,9)]" /turf/simulated/floor/asteroid/Destroy() - if (mining_floors["[src.z]"]) - mining_floors["[src.z]"] -= src + LAZYREMOVEASSOC(mining_floors, "[z]", src) return ..() /turf/simulated/floor/asteroid/ex_act(severity) diff --git a/code/modules/xenoarcheaology/sampling.dm b/code/modules/xenoarcheaology/sampling.dm index 1c03574c19599..6f012352fdb22 100644 --- a/code/modules/xenoarcheaology/sampling.dm +++ b/code/modules/xenoarcheaology/sampling.dm @@ -70,14 +70,14 @@ artifact_distance = rand() artifact_id = container.artifact_find.artifact_id else - for (var/turf/simulated/mineral/T as anything in GLOB.xeno_artifact_turfs) + for (var/turf/simulated/mineral/T as anything in SSxenoarch.xeno_artifact_turfs) if(T.artifact_find) var/cur_dist = get_dist(container, T) * 2 if( (artifact_distance < 0 || cur_dist < artifact_distance)) artifact_distance = cur_dist + rand() * 2 - 1 artifact_id = T.artifact_find.artifact_id else - GLOB.xeno_artifact_turfs -= T + SSxenoarch.xeno_artifact_turfs -= T /obj/item/device/core_sampler name = "core sampler" diff --git a/code/modules/xenoarcheaology/tools/tools.dm b/code/modules/xenoarcheaology/tools/tools.dm index 8d2a4a1dedc79..e8e3a335728e8 100644 --- a/code/modules/xenoarcheaology/tools/tools.dm +++ b/code/modules/xenoarcheaology/tools/tools.dm @@ -57,7 +57,7 @@ var/nearestSimpleTargetDist = -1 var/turf/cur_turf = get_turf(src) - for (var/turf/simulated/mineral/T as anything in GLOB.xeno_artifact_turfs) + for (var/turf/simulated/mineral/T as anything in SSxenoarch.xeno_artifact_turfs) if(T.density && T.artifact_find) if(T.z == cur_turf.z) var/cur_dist = get_dist(cur_turf, T) * 2 @@ -65,16 +65,16 @@ nearestTargetDist = cur_dist + rand() * 2 - 1 nearestTargetId = T.artifact_find.artifact_id else - GLOB.xeno_artifact_turfs -= T + SSxenoarch.xeno_artifact_turfs -= T - for(var/turf/simulated/mineral/T as anything in GLOB.xeno_digsite_turfs) + for(var/turf/simulated/mineral/T as anything in SSxenoarch.xeno_artifact_turfs) if(T.density && T.finds && length(T.finds)) if(T.z == cur_turf.z) var/cur_dist = get_dist(cur_turf, T) * 2 if(nearestSimpleTargetDist < 0 || cur_dist < nearestSimpleTargetDist) nearestSimpleTargetDist = cur_dist + rand() * 2 - 1 else - GLOB.xeno_digsite_turfs -= T + SSxenoarch.xeno_digsite_turfs -= T if(nearestTargetDist >= 0) to_chat(user, SPAN_NOTICE("Exotic energy detected on wavelength '[nearestTargetId]' in a radius of [nearestTargetDist]m[nearestSimpleTargetDist > 0 ? "; small anomaly detected in a radius of [nearestSimpleTargetDist]m" : ""]")) diff --git a/maps/mapsystem/maps.dm b/maps/mapsystem/maps.dm index 17f11970624b1..5cc721a1184f1 100644 --- a/maps/mapsystem/maps.dm +++ b/maps/mapsystem/maps.dm @@ -423,8 +423,9 @@ var/global/const/MAP_HAS_RANK = 2 //Rank system, also togglable if(!use_overmap) return + var/static/list/exoplanet_types = subtypesof(/obj/overmap/visitable/sector/exoplanet) for(var/i = 0, i < num_exoplanets, i++) - var/exoplanet_type = pick(subtypesof(/obj/overmap/visitable/sector/exoplanet)) + var/exoplanet_type = pick(exoplanet_types) var/obj/overmap/visitable/sector/exoplanet/new_planet = new exoplanet_type(null, planet_size[1], planet_size[2]) new_planet.build_level()