The best way to do it would probably be to have the baddy already know the x and y of each wall tile in the area, and have precomputed paths to get around them, but that can be a pain for the scripters (though you could have a one-time function to compute and store the information). There's also Kaimetsu's checkpath function (would need to be adapted, it's for determining where a projectile would stop).
PHP Code:
function CheckPath() {
tx = int(arg[0]); ty = int(arg[1]);
stepx = 1 / vx; stepy = 1 / vy;
if (stepx < 0) {dirx = -1; stepx = -stepx; }
else dirx = 1;
if (stepy < 0) {diry = -1; stepy = -stepy; }
else diry = 1;
tempx = arg[0] - tx; if (dirx == -1) tempx = 1-tempx;
tempy = arg[1] - ty; if (diry == -1) tempy = 1-tempy;
bankx = stepx * (1-tempx);
banky = stepy * (1-tempy);
dist = 0;
while(true) {
if (bankx < banky) {dist += bankx; temp = 0;}
else {dist += banky; temp = 1;}
if (dist > mag) break;
if (temp == 0) {
banky -= bankx; bankx = stepx;
tx+=dirx;
}
else {
bankx -= banky; banky = stepy;
ty+=diry;
}
if (tx < 0 || tx > 63 || ty < 0 || ty > 63) break;
if (onwall(tx, ty)) {
tx = arg[0] + vx * dist;
ty = arg[1] + vy * dist;
if(temp == 0) {tempx = dirx; tempy = 0;}
else {tempx = 0; tempy = diry;}
r = {tx, ty, tempx, tempy}; r = 0;
return;
}
}
r = -1;
}