This one I can see producing overhead...
get_closest()
var/mob/closest
var/end = 0
for(var/mob/M in world)
if(M!=src)
var/low = get_dist(src, M)
if(!end || (low < end))
closest = M
end = low
return closest
replaced by this:
get_closest()
var/index = 0
var/dist = 0
for(var/a = 1, a < players.len, a++)
var/distance = (get_difference_location(players[a],players[0]))
if(!dist || (distance < dist))
index=a
dist=distance
return index
get_difference_location(mob/a, mob/b)
return( (a.x-b.x)+(a.y-b.y)+(a.z-b.z) )
You made a good choice leaving the sqrt() out of the distance formula; it's relatively slow. However, you may end up with negative distances; abs() should fix that.
The two procs return different things. The first returns a mob, while the second returns an index of player[]. I suppose you're aware of this where you're using it, but I doubt it would make any difference to just return the mob at player[index] like the first proc.
Does your proc return anything at distance 0? I don't think it does. Instead of initializing dist to 0, leave it undefined (null). In the iteration, instead of !dist, use isnull(dist).
Sorry for not really answering your question, though.