From ea0f5b98023f7071640d8aebbf69367c4bb5bdab Mon Sep 17 00:00:00 2001 From: Krausus Date: Wed, 3 Aug 2016 20:08:51 -0400 Subject: [PATCH] Ports typecaches and their use in the tesla --- code/__HELPERS/lists.dm | 31 ++++++++++++++++++++++++- code/modules/power/tesla/energy_ball.dm | 6 ++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/code/__HELPERS/lists.dm b/code/__HELPERS/lists.dm index 29ccb098cb9..53285c92fa1 100644 --- a/code/__HELPERS/lists.dm +++ b/code/__HELPERS/lists.dm @@ -58,12 +58,41 @@ return 0 //Checks for specific types in a list -/proc/is_type_in_list(var/atom/A, var/list/L) +/proc/is_type_in_list(atom/A, list/L) + if(!L || !L.len || !A) + return 0 for(var/type in L) if(istype(A, type)) return 1 return 0 +//Checks for specific types in specifically structured (Assoc "type" = TRUE) lists ('typecaches') +/proc/is_type_in_typecache(atom/A, list/L) + if(!L || !L.len || !A) + return 0 + return L[A.type] + +//Like typesof() or subtypesof(), but returns a typecache instead of a list +/proc/typecacheof(path, ignore_root_path) + if(ispath(path)) + var/list/types = ignore_root_path ? subtypesof(path) : typesof(path) + var/list/L = list() + for(var/T in types) + L[T] = TRUE + return L + else if(islist(path)) + var/list/pathlist = path + var/list/L = list() + if(ignore_root_path) + for(var/P in pathlist) + for(var/T in subtypesof(P)) + L[T] = TRUE + else + for(var/P in pathlist) + for(var/T in typesof(P)) + L[T] = TRUE + return L + //Removes any null entries from the list /proc/listclearnulls(list/list) if(istype(list)) diff --git a/code/modules/power/tesla/energy_ball.dm b/code/modules/power/tesla/energy_ball.dm index af3d37e4481..14407ef9202 100644 --- a/code/modules/power/tesla/energy_ball.dm +++ b/code/modules/power/tesla/energy_ball.dm @@ -1,7 +1,7 @@ #define TESLA_DEFAULT_POWER 1738260 #define TESLA_MINI_POWER 869130 -var/list/blacklisted_tesla_types = list(/obj/machinery/atmospherics, +var/list/blacklisted_tesla_types = typecacheof(list(/obj/machinery/atmospherics, /obj/machinery/power/emitter, /obj/machinery/field/generator, /mob/living/simple_animal, @@ -15,7 +15,7 @@ var/list/blacklisted_tesla_types = list(/obj/machinery/atmospherics, /obj/machinery/field/containment, /obj/structure/disposalpipe, /obj/structure/sign, - /obj/machinery/gateway) + /obj/machinery/gateway)) /obj/singularity/energy_ball name = "energy ball" @@ -175,7 +175,7 @@ var/list/blacklisted_tesla_types = list(/obj/machinery/atmospherics, closest_atom = A closest_dist = dist - else if(closest_grounding_rod || is_type_in_list(A, blacklisted_tesla_types)) + else if(closest_grounding_rod || is_type_in_typecache(A, blacklisted_tesla_types)) continue else if(istype(A, /mob/living))