From 9897bdc248bc78eaabc129cf9d986ed26c8cc3c2 Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Sun, 16 Sep 2018 15:21:23 +0300 Subject: [PATCH] Let's cull some more lists (#40246) * memes * autolathe, also more debug info * more stuff, archdrops is big * remove archdrops, test statelists * mineralspawnchancelist * woops --- code/__HELPERS/typelists.dm | 43 +++++++++++++++++++ code/game/atoms.dm | 5 ++- code/game/machinery/autolathe.dm | 1 + code/game/objects/items.dm | 8 +++- code/game/turfs/simulated/floor.dm | 7 ++- .../turfs/simulated/floor/mineral_floor.dm | 3 +- code/game/turfs/simulated/minerals.dm | 12 +++--- tgstation.dme | 1 + 8 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 code/__HELPERS/typelists.dm diff --git a/code/__HELPERS/typelists.dm b/code/__HELPERS/typelists.dm new file mode 100644 index 00000000000..3519eb60f3a --- /dev/null +++ b/code/__HELPERS/typelists.dm @@ -0,0 +1,43 @@ +GLOBAL_LIST_EMPTY(typelists) + +#ifndef TESTING + +/datum/proc/typelist(key, list/values = list()) + var/list/mytypelist = GLOB.typelists[type] || (GLOB.typelists[type] = list()) + return mytypelist[key] || (mytypelist[key] = values.Copy()) + +#else +// mostly the same code as above, just more verbose, slower and has tallying for saved lists +/datum/proc/typelist(key, list/values) + if (!values) + values = list() + GLOB.typelistkeys |= key + if (GLOB.typelists[type]) + if (GLOB.typelists[type][key]) + GLOB.typelists[type]["[key]-saved"]++ + return GLOB.typelists[type][key] + else + GLOB.typelists[type][key] = values.Copy() + else + GLOB.typelists[type] = list() + GLOB.typelists[type][key] = values.Copy() + return GLOB.typelists[type][key] + +GLOBAL_LIST_EMPTY(typelistkeys) + +/proc/tallytypelistsavings() + var/savings = list() + var/saveditems = list() + for (var/key in GLOB.typelistkeys) + savings[key] = 0 + saveditems[key] = 0 + + for (var/type in GLOB.typelists) + for (var/saving in savings) + if (GLOB.typelists[type]["[saving]-saved"]) + savings[saving] += GLOB.typelists[type]["[saving]-saved"] + saveditems[saving] += (GLOB.typelists[type]["[saving]-saved"] * length(GLOB.typelists[type][saving])) + + for (var/saving in savings) + to_chat(world, "Savings for [saving]: [savings[saving]] lists, [saveditems[saving]] items") +#endif diff --git a/code/game/atoms.dm b/code/game/atoms.dm index ddf8b0fa512..f981ad49d25 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -74,6 +74,9 @@ var/turf/T = loc T.has_opaque_atom = TRUE // No need to recalculate it in this case, it's guaranteed to be on afterwards anyways. + if (canSmoothWith) + canSmoothWith = typelist("canSmoothWith", canSmoothWith) + ComponentInitialize() return INITIALIZE_HINT_NORMAL @@ -693,4 +696,4 @@ Proc for attack log creation, because really why not /atom/movable/proc/get_filter(name) if(filter_data && filter_data[name]) - return filters[filter_data.Find(name)] \ No newline at end of file + return filters[filter_data.Find(name)] diff --git a/code/game/machinery/autolathe.dm b/code/game/machinery/autolathe.dm index 84059e8029b..0560bde81e2 100644 --- a/code/game/machinery/autolathe.dm +++ b/code/game/machinery/autolathe.dm @@ -201,6 +201,7 @@ else for(var/i=1, i<=multiplier, i++) var/obj/item/new_item = new being_built.build_path(A) + new_item.materials = new_item.materials.Copy() for(var/mat in materials_used) new_item.materials[mat] = materials_used[mat] / multiplier new_item.autolathe_crafted(src) diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 56c270b091a..9d264c87e02 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -108,8 +108,12 @@ GLOBAL_VAR_INIT(rpg_loot_items, FALSE) var/list/juice_results //A reagent list containing blah blah... but when JUICED in a grinder! /obj/item/Initialize() - if (!materials) - materials = list() + + materials = typelist("materials", materials) + + if (attack_verb) + attack_verb = typelist("attack_verb", attack_verb) + . = ..() for(var/path in actions_types) new path(src) diff --git a/code/game/turfs/simulated/floor.dm b/code/game/turfs/simulated/floor.dm index 777cbedd26a..6e858405150 100644 --- a/code/game/turfs/simulated/floor.dm +++ b/code/game/turfs/simulated/floor.dm @@ -22,10 +22,9 @@ tiled_dirt = TRUE /turf/open/floor/Initialize(mapload) - if (!broken_states) - broken_states = list("damaged1", "damaged2", "damaged3", "damaged4", "damaged5") - if (!burnt_states) - burnt_states = list() + + broken_states = typelist("broken_states", broken_states) + burnt_states = typelist("burnt_states", burnt_states) if(!broken && broken_states && (icon_state in broken_states)) broken = TRUE if(!burnt && burnt_states && (icon_state in burnt_states)) diff --git a/code/game/turfs/simulated/floor/mineral_floor.dm b/code/game/turfs/simulated/floor/mineral_floor.dm index a470e3e0a17..a77417e4e4c 100644 --- a/code/game/turfs/simulated/floor/mineral_floor.dm +++ b/code/game/turfs/simulated/floor/mineral_floor.dm @@ -20,8 +20,7 @@ if(!broken_states) broken_states = list("[initial(icon_state)]_dam") . = ..() - if (!icons) - icons = list() + icons = typelist("icons", icons) /turf/open/floor/mineral/update_icon() diff --git a/code/game/turfs/simulated/minerals.dm b/code/game/turfs/simulated/minerals.dm index 61c7950e88c..24a6ad61cb7 100644 --- a/code/game/turfs/simulated/minerals.dm +++ b/code/game/turfs/simulated/minerals.dm @@ -131,17 +131,17 @@ T.ChangeTurf(type) /turf/closed/mineral/random - var/mineralSpawnChanceList + var/list/mineralSpawnChanceList = list(/turf/closed/mineral/uranium = 5, /turf/closed/mineral/diamond = 1, /turf/closed/mineral/gold = 10, + /turf/closed/mineral/silver = 12, /turf/closed/mineral/plasma = 20, /turf/closed/mineral/iron = 40, /turf/closed/mineral/titanium = 11, + /turf/closed/mineral/gibtonite = 4, /turf/open/floor/plating/asteroid/airless/cave = 2, /turf/closed/mineral/bscrystal = 1) //Currently, Adamantine won't spawn as it has no uses. -Durandan var/mineralChance = 13 var/display_icon_state = "rock" /turf/closed/mineral/random/Initialize() - if (!mineralSpawnChanceList) - mineralSpawnChanceList = list( - /turf/closed/mineral/uranium = 5, /turf/closed/mineral/diamond = 1, /turf/closed/mineral/gold = 10, - /turf/closed/mineral/silver = 12, /turf/closed/mineral/plasma = 20, /turf/closed/mineral/iron = 40, /turf/closed/mineral/titanium = 11, - /turf/closed/mineral/gibtonite = 4, /turf/open/floor/plating/asteroid/airless/cave = 2, /turf/closed/mineral/bscrystal = 1) + + mineralSpawnChanceList = typelist("mineralSpawnChanceList", mineralSpawnChanceList) + if (display_icon_state) icon_state = display_icon_state . = ..() diff --git a/tgstation.dme b/tgstation.dme index ad74d981703..71425a80b6a 100755 --- a/tgstation.dme +++ b/tgstation.dme @@ -133,6 +133,7 @@ #include "code\__HELPERS\text.dm" #include "code\__HELPERS\time.dm" #include "code\__HELPERS\type2type.dm" +#include "code\__HELPERS\typelists.dm" #include "code\__HELPERS\unsorted.dm" #include "code\__HELPERS\view.dm" #include "code\__HELPERS\sorts\__main.dm"