diff --git a/code/__HELPERS/_lists.dm b/code/__HELPERS/_lists.dm index 9c4cc3eafa8..97ca579156e 100644 --- a/code/__HELPERS/_lists.dm +++ b/code/__HELPERS/_lists.dm @@ -894,14 +894,6 @@ used_key_list[input_key] = 1 return input_key -///Flattens a keyed list into a list of its contents -/proc/flatten_list(list/key_list) - if(!islist(key_list)) - return null - . = list() - for(var/key in key_list) - . |= LIST_VALUE_WRAP_LISTS(key_list[key]) - ///Make a normal list an associative one /proc/make_associative(list/flat_list) . = list() @@ -959,6 +951,14 @@ UNTYPED_LIST_ADD(keys, key) return keys +/// Turns an associative list into a flat list of values +/proc/assoc_to_values(list/key_list) + if(!islist(key_list)) + return null + . = list() + for(var/key in key_list) + . |= LIST_VALUE_WRAP_LISTS(key_list[key]) + ///compare two lists, returns TRUE if they are the same /proc/compare_list(list/l,list/d) if(!islist(l) || !islist(d)) diff --git a/code/controllers/subsystem/dynamic/dynamic_testing.dm b/code/controllers/subsystem/dynamic/dynamic_testing.dm index 9787a29397d..fe9da13d231 100644 --- a/code/controllers/subsystem/dynamic/dynamic_testing.dm +++ b/code/controllers/subsystem/dynamic/dynamic_testing.dm @@ -59,9 +59,9 @@ ADMIN_VERB(dynamic_tester, R_DEBUG, "Dynamic Tester", "See dynamic probabilities data["tier"] = tier data["num_players"] = num_players - data["roundstart_ruleset_report"] = flatten_list(roundstart_ruleset_report) - data["light_midround_ruleset_report"] = flatten_list(light_midround_ruleset_report) - data["heavy_midround_ruleset_report"] = flatten_list(heavy_midround_ruleset_report) + data["roundstart_ruleset_report"] = assoc_to_values(roundstart_ruleset_report) + data["light_midround_ruleset_report"] = assoc_to_values(light_midround_ruleset_report) + data["heavy_midround_ruleset_report"] = assoc_to_values(heavy_midround_ruleset_report) return data diff --git a/code/controllers/subsystem/economy.dm b/code/controllers/subsystem/economy.dm index 9125936600f..6af019a3556 100644 --- a/code/controllers/subsystem/economy.dm +++ b/code/controllers/subsystem/economy.dm @@ -24,7 +24,7 @@ SUBSYSTEM_DEF(economy) var/techweb_bounty = 250 /** * List of normal (no department ones) accounts' identifiers with associated datum accounts, for big O performance. - * A list of sole account datums can be obtained with flatten_list(), another variable would be redundant rn. + * A list of sole account datums can be obtained with assoc_to_values(), another variable would be redundant rn. */ var/list/bank_accounts_by_id = list() /// A list of bank accounts indexed by their assigned job typepath. diff --git a/code/datums/materials/basemats.dm b/code/datums/materials/basemats.dm index 4a447f3c02f..7b3daf48461 100644 --- a/code/datums/materials/basemats.dm +++ b/code/datums/materials/basemats.dm @@ -329,7 +329,7 @@ Unless you know what you're doing, only use the first three numbers. They're in SIGNAL_HANDLER if(prob(67)) return - var/list/elegible_fish_sources = flatten_list(GLOB.preset_fish_sources) + var/list/elegible_fish_sources = assoc_to_values(GLOB.preset_fish_sources) for(var/datum/fish_source/source as anything in elegible_fish_sources) if(source.fish_source_flags & FISH_SOURCE_FLAG_NO_BLUESPACE_ROD) elegible_fish_sources -= source diff --git a/code/datums/quirks/negative_quirks/food_allergy.dm b/code/datums/quirks/negative_quirks/food_allergy.dm index ba2c1711032..1f8a6e9e829 100644 --- a/code/datums/quirks/negative_quirks/food_allergy.dm +++ b/code/datums/quirks/negative_quirks/food_allergy.dm @@ -39,7 +39,7 @@ GLOBAL_LIST_INIT(possible_food_allergies, list( if(target_foodtypes != NONE) // Got a preference, don't care return - target_foodtypes = pick(flatten_list(GLOB.possible_food_allergies)) + target_foodtypes = pick(assoc_to_values(GLOB.possible_food_allergies)) /datum/quirk/item_quirk/food_allergic/add_unique(client/client_source) var/what_are_we_actually_killed_by = english_list(bitfield_to_list(target_foodtypes, FOOD_FLAGS_IC)) // This should never be more than one thing but just in case we can support it diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index c97d4d4fbe1..9c5ea9e820d 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -396,7 +396,7 @@ var/turf/this_turf = get_turf(src) for(var/atom/movable/movable_atom in contents) //so machines like microwaves dont dump out signalers after cooking - if(wires && (movable_atom in flatten_list(wires.assemblies))) + if(wires && (movable_atom in assoc_to_values(wires.assemblies))) continue if(subset && !(movable_atom in subset)) diff --git a/code/game/machinery/computer/communications.dm b/code/game/machinery/computer/communications.dm index 0c2ceb23c44..ab687c53805 100644 --- a/code/game/machinery/computer/communications.dm +++ b/code/game/machinery/computer/communications.dm @@ -261,7 +261,7 @@ if (can_buy_shuttles_or_fail_reason != FALSE) to_chat(user, span_alert("[can_buy_shuttles_or_fail_reason]")) return - var/list/shuttles = flatten_list(SSmapping.shuttle_templates) + var/list/shuttles = assoc_to_values(SSmapping.shuttle_templates) var/datum/map_template/shuttle/shuttle = locate(params["shuttle"]) in shuttles if (!istype(shuttle)) return diff --git a/code/game/machinery/dna_infuser/dna_infusion.dm b/code/game/machinery/dna_infuser/dna_infusion.dm index 2ea3b09ca7c..b2de63a3a2d 100644 --- a/code/game/machinery/dna_infuser/dna_infusion.dm +++ b/code/game/machinery/dna_infuser/dna_infusion.dm @@ -25,7 +25,7 @@ ///returns /datum/infuser_entry that matches an item being used for infusion, returns a fly mutation on failure /atom/movable/proc/get_infusion_entry() as /datum/infuser_entry var/datum/infuser_entry/found - for(var/datum/infuser_entry/entry as anything in flatten_list(GLOB.infuser_entries)) + for(var/datum/infuser_entry/entry as anything in assoc_to_values(GLOB.infuser_entries)) if(entry.tier == DNA_MUTANT_UNOBTAINABLE) continue if(is_type_in_list(src, entry.input_obj_or_mob)) diff --git a/code/game/machinery/dna_infuser/infuser_book.dm b/code/game/machinery/dna_infuser/infuser_book.dm index 416ed038d64..370d7a87c1e 100644 --- a/code/game/machinery/dna_infuser/infuser_book.dm +++ b/code/game/machinery/dna_infuser/infuser_book.dm @@ -29,7 +29,7 @@ var/list/data = list() // Collect all info from each intry. var/list/entry_data = list() - for(var/datum/infuser_entry/entry as anything in flatten_list(GLOB.infuser_entries)) + for(var/datum/infuser_entry/entry as anything in assoc_to_values(GLOB.infuser_entries)) if(entry.tier == DNA_MUTANT_UNOBTAINABLE) continue var/list/individual_entry_data = list() diff --git a/code/game/objects/items/crab17.dm b/code/game/objects/items/crab17.dm index 2664cff95d4..b2254fa2e65 100644 --- a/code/game/objects/items/crab17.dm +++ b/code/game/objects/items/crab17.dm @@ -22,7 +22,7 @@ var/turf/targetturf = get_safe_random_station_turf_equal_weight() if (!targetturf) return FALSE - var/list/accounts_to_rob = flatten_list(SSeconomy.bank_accounts_by_id) + var/list/accounts_to_rob = assoc_to_values(SSeconomy.bank_accounts_by_id) var/mob/living/L if(isliving(user)) L = user @@ -201,7 +201,7 @@ * Grabs the accounts to be robbed and puts them in accounts_to_rob, tells the accounts they're being drained and calls dump() to start draining. */ /obj/structure/checkoutmachine/proc/start_dumping() - accounts_to_rob = flatten_list(SSeconomy.bank_accounts_by_id) + accounts_to_rob = assoc_to_values(SSeconomy.bank_accounts_by_id) accounts_to_rob -= bogdanoff?.get_bank_account() for(var/i in accounts_to_rob) var/datum/bank_account/B = i diff --git a/code/modules/admin/smites/retcon.dm b/code/modules/admin/smites/retcon.dm index 461b7b330bb..33beb3542e8 100644 --- a/code/modules/admin/smites/retcon.dm +++ b/code/modules/admin/smites/retcon.dm @@ -27,7 +27,7 @@ /datum/smite/retcon/proc/delete_bank_account(mob/living/target) var/name = target.real_name - var/account_list = flatten_list(SSeconomy.bank_accounts_by_id) + var/account_list = assoc_to_values(SSeconomy.bank_accounts_by_id) for(var/datum/bank_account/account in account_list) if(account.account_holder == name) qdel(account) diff --git a/code/modules/admin/verbs/hiddenprints.dm b/code/modules/admin/verbs/hiddenprints.dm index a2c5ad63f24..89834411f47 100644 --- a/code/modules/admin/verbs/hiddenprints.dm +++ b/code/modules/admin/verbs/hiddenprints.dm @@ -8,7 +8,7 @@ if(!islist(victim_hiddenprints)) victim_hiddenprints = list() - var/list/hiddenprints = flatten_list(victim_hiddenprints) + var/list/hiddenprints = assoc_to_values(victim_hiddenprints) list_clear_nulls(hiddenprints) if(!length(hiddenprints)) diff --git a/code/modules/antagonists/heretic/heretic_knowledge.dm b/code/modules/antagonists/heretic/heretic_knowledge.dm index 726e6247dc2..97e701c717d 100644 --- a/code/modules/antagonists/heretic/heretic_knowledge.dm +++ b/code/modules/antagonists/heretic/heretic_knowledge.dm @@ -540,7 +540,7 @@ /datum/heretic_knowledge/ultimate/on_research(mob/user, datum/antagonist/heretic/our_heretic) . = ..() var/total_points = 0 - for(var/datum/heretic_knowledge/knowledge as anything in flatten_list(our_heretic.researched_knowledge)) + for(var/datum/heretic_knowledge/knowledge as anything in assoc_to_values(our_heretic.researched_knowledge)) total_points += knowledge.cost log_heretic_knowledge("[key_name(user)] gained knowledge of their final ritual at [gameTimestamp()]. \ diff --git a/code/modules/hallucination/delusions.dm b/code/modules/hallucination/delusions.dm index c90b60d2f41..b52f031a547 100644 --- a/code/modules/hallucination/delusions.dm +++ b/code/modules/hallucination/delusions.dm @@ -56,7 +56,7 @@ /datum/hallucination/delusion/Destroy() if(!QDELETED(hallucinator) && LAZYLEN(delusions)) - hallucinator.client?.images -= flatten_list(delusions) + hallucinator.client?.images -= assoc_to_values(delusions) LAZYNULL(delusions) return ..() diff --git a/code/modules/unit_tests/blindness.dm b/code/modules/unit_tests/blindness.dm index 8836f80611f..9d47e45ca5a 100644 --- a/code/modules/unit_tests/blindness.dm +++ b/code/modules/unit_tests/blindness.dm @@ -1,4 +1,4 @@ -#define HAS_SCREEN_OVERLAY(mob, type) (locate(type) in flatten_list(mob.screens)) +#define HAS_SCREEN_OVERLAY(mob, type) (locate(type) in assoc_to_values(mob.screens)) #define HAS_CLIENT_COLOR(mob, type) (locate(type) in mob.client_colours) /** diff --git a/code/modules/unit_tests/dna_infusion.dm b/code/modules/unit_tests/dna_infusion.dm index e7b6f182146..4abe0e16e54 100644 --- a/code/modules/unit_tests/dna_infusion.dm +++ b/code/modules/unit_tests/dna_infusion.dm @@ -2,7 +2,7 @@ /datum/unit_test/valid_dna_infusion /datum/unit_test/valid_dna_infusion/Run() - for(var/datum/infuser_entry/infuser_entry as anything in flatten_list(GLOB.infuser_entries)) + for(var/datum/infuser_entry/infuser_entry as anything in assoc_to_values(GLOB.infuser_entries)) for(var/input_type in infuser_entry.input_obj_or_mob) if(ispath(input_type, /mob/living)) continue @@ -35,7 +35,7 @@ /datum/infuser_entry/fly, )) // Fetch the globally instantiated DNA Infuser entries. - for(var/datum/infuser_entry/infuser_entry as anything in flatten_list(GLOB.infuser_entries)) + for(var/datum/infuser_entry/infuser_entry as anything in assoc_to_values(GLOB.infuser_entries)) var/output_organs = infuser_entry.output_organs var/mob/living/carbon/human/lab_rat = allocate(/mob/living/carbon/human/consistent) var/list/obj/item/organ/inserted_organs = list() diff --git a/code/modules/unit_tests/high_five.dm b/code/modules/unit_tests/high_five.dm index 16b7e3f9545..e5b8e1cef67 100644 --- a/code/modules/unit_tests/high_five.dm +++ b/code/modules/unit_tests/high_five.dm @@ -12,8 +12,8 @@ TEST_ASSERT_NOTNULL(offer_guy.has_status_effect(/datum/status_effect/offering/no_item_received/high_five), \ "Offerer doesn't have the high five offer status effect after offering (giving) to takers nearby") - var/atom/movable/screen/alert/give/highfive/alert_to_click = locate() in flatten_list(take_guy.alerts) - var/atom/movable/screen/alert/give/highfive/bystander_alert_we_dont_click = locate() in flatten_list(random_bystander.alerts) + var/atom/movable/screen/alert/give/highfive/alert_to_click = locate() in assoc_to_values(take_guy.alerts) + var/atom/movable/screen/alert/give/highfive/bystander_alert_we_dont_click = locate() in assoc_to_values(random_bystander.alerts) TEST_ASSERT_NOTNULL(alert_to_click, "Taker had no alert to click to accept the high five offer") TEST_ASSERT_NOTNULL(bystander_alert_we_dont_click, "Bystander had no alert from the high fiver offer")