From 058095b2f59d6acfd4caf648aeee10c30fc208ae Mon Sep 17 00:00:00 2001 From: TalkingCactus Date: Tue, 30 Aug 2016 14:13:55 -0400 Subject: [PATCH] ports https://github.com/tgstation/tgstation/pull/19981 Special thanks to MrStonedOne. --- code/__HELPERS/lists.dm | 8 ++++++++ code/__HELPERS/unsorted.dm | 2 +- .../mob/living/simple_animal/hostile/hostile.dm | 10 ++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/code/__HELPERS/lists.dm b/code/__HELPERS/lists.dm index 265a5fd453..e7807a881e 100644 --- a/code/__HELPERS/lists.dm +++ b/code/__HELPERS/lists.dm @@ -67,6 +67,14 @@ return 0 return L[A.type] +//returns a new list with only atoms that are in typecache L +/proc/typecache_filter_list(list/atoms, list/typecache) + . = list() + for (var/thing in atoms) + var/atom/A = thing + if (typecache[A.type]) + . += A + //Like typesof() or subtypesof(), but returns a typecache instead of a list /proc/typecacheof(path, ignore_root_path) if(ispath(path)) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index b0c46aedd0..e6ee163408 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -543,7 +543,7 @@ Turf and target are seperate in case you want to teleport some distance from a t return 0 if(current.opacity) return 0 - for(var/atom/A in current) + for(var/thing in current) if(A.opacity) return 0 current = get_step_towards(current, target_turf) diff --git a/code/modules/mob/living/simple_animal/hostile/hostile.dm b/code/modules/mob/living/simple_animal/hostile/hostile.dm index 8ae70d4554..315bdb385b 100644 --- a/code/modules/mob/living/simple_animal/hostile/hostile.dm +++ b/code/modules/mob/living/simple_animal/hostile/hostile.dm @@ -87,14 +87,16 @@ if(!search_objects) var/list/Mobs = hearers(vision_range, targets_from) - src //Remove self, so we don't suicide . += Mobs - for(var/M in mechas_list) - if(get_dist(M, targets_from) <= vision_range && can_see(targets_from, M, vision_range)) - . += M + + var/static/hostile_machines = typecacheof(list(/obj/machinery/porta_turret, /obj/mecha)) + + for(var/HM in typecache_filter_list(range(vision_range, targets_from), hostile_machines)) + if(can_see(targets_from, HM, vision_range)) + . += HM else var/list/Objects = oview(vision_range, targets_from) . += Objects - /mob/living/simple_animal/hostile/proc/FindTarget(var/list/possible_targets, var/HasTargetsList = 0)//Step 2, filter down possible targets to things we actually care about . = list() if(!HasTargetsList)