ID:1149616
 
Code:
        a_oview(distance, atom/center=src)
var/list/atoms = list()
var/top = center.y+distance
var/bottom = center.y-distance
var/left = center.x-distance
var/right = center.x+distance

for(var/yy = top, yy >= bottom, yy--)
for(var/xx = left, xx <= right, xx++)
var/ay = ((yy + world.maxy - 1) % world.maxy) + 1
var/ax = ((xx + world.maxx - 1) % world.maxx) + 1
var/turf/T = locate(ax,ay,center.z)
var/atom/A = locate() in T
for(A in T)
if(A != center)
atoms.Add(A)

return atoms


Problem description:

Basically I'm wondering how i could re-organize the list and store them in order by their distance...basically process the closest atom in priority to another one similar that is further away.

anyone :P?
Please don't bump unless the post is off the page and it's been 24 hours, it just becomes an annoyance.
In response to A.T.H.K
A.T.H.K wrote:
Please don't bump unless the post is off the page and it's been 24 hours, it just becomes an annoyance.

Sorry.
Galactic Soldier wrote:
Here, twerp. e.e
I should probably use the Swap() instead and use the same array in the arguments to make it more efficient, but whatever, I'm going to bed. Goodnight. D:

proc/a_oview(distance, atom/center = src)
> return global.distance_order(center, oview(distance, center))
>
> proc/distance_order(source, objects[])
> var/distances[objects.len]
>
> for(var/x = 1 to objects.len)
> distances[x] = get_dist(source, objects[x])
>
> . = new/list(objects.len)
>
> for(var/index = distances.len, index > 0, index --)
> var
> max = max(distances)
> pos = distances.Find(max)
>
> .[index] = objects[pos]
> distances[pos] = -1

I went ahead and did it. Enjoy. I left it in separate procedures just incase you wanted to extend functionality outside of oview(). :3

proc/a_oview(distance, atom/center = src)
> return global.distance_order(center, oview(distance, center))
>
> proc/distance_order(source, objects[])
> var/distances[objects.len]
>
> for(var/x = 1 to objects.len)
> distances[x] = get_dist(source, objects[x])
>
> for(var/index = distances.len, index > 0, index --)
> var
> max = max(distances)
> pos = distances.Find(max)
>
> objects.Swap(index, pos)
> distances.Swap(index, pos)
> distances[index] = -1
>
> return objects


Thanks :3