// returns the closest target within view
NearestTarget()
set background = 1
if(active_targets.len)
var/mob/target = active_targets[active_targets.len]
var/distance = get_dist(src, target)
for(var/mob/T in active_targets)
var/tmp_distance = get_dist(src, T)
if(!T.ko && tmp_distance < distance)
distance = tmp_distance
target = T
if((target in oview(src)) && !target.ko)
return target
return null
Problem description:
Basically eating up too much cpu. How do I make this more efficient?
If I'm not mistaken, the above should make potential_targets only contain the list of objects that exist both in the active_targets list and in the oview().
Looping through this list might largely reduce the number of list elements you need to iterate over, depending on how active_targets was originally defined.