/*
**  Usage:
**      inst = instance_farthest_from(instance, object, n);
**
**  Arguments:
**      instance    an instance id
**      object      an object_index, or keyword "all"
**      n           proximity
**
**  Returns:
**      inst        (nth) farthest instance id of type
**                  (object) from the given (instance),
**                  or keyword "noone" if none found.
**
**  copyright (c) 2006, John Leffingwell
**  www.planetxot.com
*/

var instance,object,n,list,farthest;
instance = argument0;
object = argument1;
n = argument2;
if (instance.object_index == object) n-=1;
n = min(max(1,n),instance_number(object));
list = ds_priority_create();
farthest = noone;
with (object) if (id != instance) ds_priority_add(list,id,distance_to_object(instance));
repeat (n) farthest = ds_priority_delete_max(list);
ds_priority_destroy(list);
return farthest;