jobSize--;
int cx = coord.x >> 4;
int cz = coord.z >> 4;
CompassReader cr = getReader( coord.getWorld() );
// Am I standing on it?
if ( cr.hasBeacon( cx, cz ) )
{
callback.calculatedDirection( true, true, -999, 0 );
if ( jobSize() < 2 )
cleanUp();
return;
}
// spiral outward...
for (int offset = 1; offset < maxRange; offset++)
{
int minX = cx - offset;
int minZ = cz - offset;
int maxX = cx + offset;
int maxZ = cz + offset;
int closest = Integer.MAX_VALUE;
int chosen_x = cx;
int chosen_z = cz;
for (int z = minZ; z <= maxZ; z++)
{
if ( cr.hasBeacon( minX, z ) )
{
int closeness = dist( cx, cz, minX, z );
if ( closeness < closest )
{
closest = closeness;
chosen_x = minX;
chosen_z = z;
}
}
if ( cr.hasBeacon( maxX, z ) )
{
int closeness = dist( cx, cz, maxX, z );
if ( closeness < closest )
{
closest = closeness;
chosen_x = maxX;
chosen_z = z;
}
}
}
for (int x = minX + 1; x < maxX; x++)
{
if ( cr.hasBeacon( x, minZ ) )
{
int closeness = dist( cx, cz, x, minZ );
if ( closeness < closest )
{
closest = closeness;
chosen_x = x;
chosen_z = minZ;
}
}
if ( cr.hasBeacon( x, maxZ ) )
{
int closeness = dist( cx, cz, x, maxZ );
if ( closeness < closest )
{
closest = closeness;