rendered paste body public boolean hasLoS(int objId, int sourceX, int sourceY, short sourceZ, int targetX , int targetY , short targetZ)
{
byte EAST=1, WEST=2, SOUTH=4, NORTH=8;
float m;
float b;
int x;
int y;
byte NSEW;
short newZ;
boolean LoS;
GeoDataBuffer geobuf;
GeoSubCell cellData;
// I know i will use this one day ...
//short originalSourceZ, originalTargetZ;
//originalSourceZ = sourceZ;
//originalTargetZ = targetZ;
geobuf =checkGeoBuffer(objId, sourceX, sourceY, sourceZ, targetX, targetY, targetZ);
if (geobuf != null)
{
return geobuf.hadLoS;
}
LoS = true;
newZ =sourceZ;
// avoid / 0 error
if (sourceX != targetX)
{
m = (float) (sourceY - targetY) / (sourceX - targetX);
}
else
{
m =0;
}
b = sourceY - (m*sourceX);
if ( sourceX == targetX ) // vertical line
{
if (sourceY > targetY) //north
{
for (y=sourceY;y > targetY;y = y - 16)
{
cellData = getGeoInfoNearest(sourceX, y & 0xFFFFFFF0,newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ( (NSEW & SOUTH) == 0)
{
LoS = false;
break;
}
}
}
else
{
for (y=sourceY;y < targetY;y=y + 16)
{
cellData = getGeoInfoNearest(sourceX, (y+16) & 0xFFFFFFF0,newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ( (NSEW & NORTH) == 0)
{
LoS = false;
break;
}
}
}
}
else if (targetY==sourceY) // Horizontal Line or m=0
{
if (sourceX > targetX) // west
{
for (x=sourceX;x > targetX;x=x - 16)
{
cellData = getGeoInfoNearest(x & 0xFFFFFFF0,sourceY,newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ( (NSEW & WEST) == 0)
{
LoS = false;
break;
}
}
}
else // EAST
{
for (x=sourceX;x < targetX;x=x + 16)
{
cellData = getGeoInfoNearest((x +16)& 0xFFFFFFF0,sourceY,newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ( (NSEW & EAST) == 0)
{
LoS = false;
break;
}
}
}
}
else if (( m > 0 && m <= 1) || ( m < 0 && m >= -1) ) // east west line -- so more X's to verify than Y's
{
if ( sourceX < targetX) // going East
{
for (x=sourceX;x < targetX ; x = x + 16)
{
y = (int)((m*(float)x) +(float) b);
cellData = getGeoInfoNearest((x + 16) & 0xFFFFFFF0 , y , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & EAST) == 0)
{
LoS = false;
break;
}
}
if ( m > 0 ) // North bound
{
for (y=sourceY;y < targetY; y = y + 16)
{
x = (int) (( (float)y -(float) b) / m);
cellData = getGeoInfoNearest( x , (y + 16) & 0xFFFFFFF0 , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & NORTH) == 0)
{
LoS = false;
break;
}
}
}
else // South Bound
{
for (y=sourceY;y > targetY; y = y - 16)
{
x = (int) (( (float)y -(float) b) / m);
cellData = getGeoInfoNearest( x , y & 0xFFFFFFF0, newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & SOUTH) == 0)
{
LoS = false;
break;
}
}
}
}
else // going West
{
for ( x=sourceX;x > targetX ; x = x - 16)
{
y = (int)((m*(float)x) +(float) b);
cellData = getGeoInfoNearest( x & 0xFFFFFFF0 ,y , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & WEST) == 0)
{
LoS = false;
break;
}
}
if ( m > 0 ) // North
{
for ( y=sourceY;y < targetY; y = y + 16)
{
x = (int) (( (float)y -(float) b) / m);
cellData = getGeoInfoNearest(x ,(y + 16) & 0xFFFFFFF0 , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & NORTH) == 0)
{
LoS = false;
break;
}
}
}
else // South
{
for ( y = sourceY;y > targetY; y = y - 16)
{
x = (int) (( (float)y -(float) b) / m);
cellData = getGeoInfoNearest( x , y & 0xFFFFFFF0 , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & SOUTH) == 0)
{
LoS = false;
break;
}
}
}
}
}
else if ( m > 1 || m < -1) //north south line -- so, more y's to verify than x's
{
if (sourceY > targetY) // going north
{
for ( y = sourceY ; y > targetY ; y = y - 16)
{
//y = (m * x) + b;
x = (int) (((float)y-(float)b) / m);
cellData = getGeoInfoNearest( x , y & 0xFFFFFFF0 , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & NORTH) == 0)
{
LoS = false;
break;
}
}
if ( m > 0 ) // EAST Bound
{
for ( x = sourceX;x < targetX; x = x + 16)
{
y = (int)((m*(float)x) +(float) b);
cellData = getGeoInfoNearest( (x + 16) & 0xFFFFFFF0 , y , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & EAST) == 0)
{
LoS = false;
break;
}
}
}
else // West Bound
{
for ( x = sourceX;x > targetX; x = x - 16)
{
y = (int)((m*(float)x) +(float) b);
cellData = getGeoInfoNearest( (x + 16) & 0xFFFFFFF0 , y , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & WEST) == 0)
{
LoS = false;
break;
}
}
}
}
else // going South
{
for ( y = sourceY ; y < targetY ; y = y + 16)
{
//y = (m * x ) + b;
x =(int) (((float)y-(float)b)/m);
cellData = getGeoInfoNearest(x ,(y+16) & 0xFFFFFFF0, newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & SOUTH) == 0)
{
LoS = false;
break;
}
}
if (m > 0) // WEST bound
{
for ( x = sourceX;x > targetX ; x = x - 16)
{
y = (int)((m*(float)x) +(float) b);
cellData = getGeoInfoNearest( x & 0xFFFFFFF0 , y , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & WEST) == 0)
{
LoS = false;
break;
}
}
}
else // EAST bound
{
for ( x = sourceX;x < targetX ; x = x + 16)
{
y = (int)((m*(float)x) +(float) b);
cellData = getGeoInfoNearest((x +16) & 0xFFFFFFF0 ,y , newZ);
NSEW = cellData.getNSEW();
newZ = cellData.getZ();
if ((NSEW & EAST) == 0)
{
LoS = false;
break;
}
}
}
}
}
geobuf = geoRequestBuffer.get(objId);
geobuf.hadLoS = LoS;
return LoS;
}