// --------------------------------------------------------------------------------------------
function find_nearest(ENTITY* ent)
{
var you_handle;
var _dist=1000;
var _ndist;
var dist_to_nearest;
for(you = ent_next(NULL); you; you = ent_next(you))
{
if(you.id == goblin)
{
_ndist = vec_dist(ent.x, you.x);
if (_ndist < _dist) { _dist = _ndist; you_handle = handle(you); }
}
}
dist_to_nearest = _dist; //nearest entity to "ent"
you = ptr_for_handle(you_handle); //you to nearest found
if(you)
{
VECTOR temp;
vec_set(temp.x,you.x);
vec_sub(temp.x,my.x);
vec_to_angle(my.pan,temp);
if(vec_dist(ent.x, you.x) < 50) _goblin_loose_hp(); //maybe take some hp when close
}
}
// --------------------------------------------------------------------------------------------