double
pathcost(struct sctstr *start, s_char *path, int mob_type)
{
- register int o;
- register int cx, cy;
+ unsigned i;
+ int o;
+ int cx, cy;
double cost = 0.0;
struct sctstr *sp;
int sx, sy, offset;
path++;
continue;
}
- o = dirindex[(int)((*path) - 'a')];
+ i = *path - 'a';
+ if (CANT_HAPPEN(i >= sizeof(dirindex) / sizeof(*dirindex)))
+ break;
+ o = dirindex[i];
+ if (CANT_HAPPEN(o) < 0)
+ break;
cx += diroff[o][0];
cy += diroff[o][1];
sx = XNORM(cx);
/* this maps a character from a to z into the diroff mappings. It
keeps us from having to loop if we don't want to */
-int dirindex[] = { 0, 4, 0, 0, 0, 0, 5, 0, 0, 2, 0, 0, 8,
- 3, 0, 0, 0, 0, 0, 0, 1, 7, 0, 0, 6, 0
+signed char dirindex[] = {
+ -1, 4, -1, -1, -1, -1, 5, 0, -1, 2, -1, -1, 8,
+ 3, -1, -1, -1, -1, -1, -1, 1, 7, -1, -1, 6, -1
};
/* must agree with dirch[] and DIR_ defines */