distance
From ZDoom Wiki
Similar to the Pythagorean Theorem, this function does all the necessary calculations to return the distance (in grid units) between tid1 and tid2.
function int distance (int tid1, int tid2)
{
int x, y, z, d, r;
x = GetActorX(tid1) - GetActorX(tid2) >> 16;
y = GetActorY(tid1) - GetActorY(tid2) >> 16;
z = GetActorZ(tid2) - GetActorZ(tid2) >> 16;
d = x*x + y*y + z*z + 1 >> 1;
while (d > r)
d -= r++;
return r;
}

