// C Header File // Created 12/27/2002; 6:20:41 PM /*---------------------------------------------------------------------------*/ /* useful macros */ /*---------------------------------------------------------------------------*/ #define ABS(a) (((a)<0) ? -(a): (a)) #define SPECIAL_SGN(a) (((a)<0) ? 0 : 1) short RayBlocked (short x1, short y1, short x2, short y2); #ifndef __RAYLINE_H__ #define __RAYLINE_H__ //Returns 1 if a ray is blocked by a wall, otherwise returns 0 short RayBlocked (register short x1, register short y1, register short x2, register short y2) { short d, x, y; register short ax, ay; register short sx, sy; short dx, dy; //accuracy [0...6] #define RAY_ACCURACY 0 #define RAY_ADJ (6-RAY_ACCURACY) x1 >>= RAY_ADJ; y1 >>= RAY_ADJ; x2 >>= RAY_ADJ; y2 >>= RAY_ADJ; dx = x2 - x1; ax = ABS (dx) << 1; sx = SPECIAL_SGN (dx); dy = y2 - y1; ay = ABS (dy) << 1; sy = SPECIAL_SGN (dy); x = x1; y = y1; if (ax > ay) { /* x dominant */ d = ay - (ax >> 1); do { if (fc-> map_data[(y >> RAY_ACCURACY) * fc->map_width + (x >> RAY_ACCURACY)] > 0) return 1; if (x == x2) return 0; if (d >= 0) { if (sy) y += 1; else y -= 1; d -= ax; } if (sx) { x += 1; } else { x -= 1; } d += ay; } while (1); } else { /* y dominant */ d = ax - (ay >> 1); do { if (fc-> map_data[(y >> RAY_ACCURACY) * fc->map_width + (x >> RAY_ACCURACY)] > 0) return 1; if (y == y2) return 0; if (d >= 0) { if (sx) x += 1; else x -= 1; d -= ay; } if (sy) { y += 1; } else { y -= 1; } d += ax; } while (1); } return 0; } #endif