]> git.pond.sub.org Git - empserver/commitdiff
(dirindex): Narrow member type to signed char to save cache.
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 25 Sep 2005 09:15:27 +0000 (09:15 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 25 Sep 2005 09:15:27 +0000 (09:15 +0000)
(pathcost): Catch bad direction characters (should not happen).

include/path.h
src/lib/common/path.c
src/lib/global/dir.c

index 497dbe7fe706981918386ae92a086cc43fcb6dc8..25c57b2b4dd28344a736c05cbf4408ea39bc5c87 100644 (file)
@@ -51,7 +51,7 @@
 #define        DIR_FIRST       1
 #define        DIR_LAST        6
 
-extern int dirindex[];
+extern signed char dirindex['z'-'a'+1];
 extern int diroff[][2];
 extern s_char dirch[];
 
index 98d55b2b473ec930b0efb88efa0a2136a50c269c..b6e33e9c2c19105894a6d001229c1fc03c906568 100644 (file)
@@ -307,8 +307,9 @@ bp_clear_cachepath(void)
 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;
@@ -321,7 +322,12 @@ pathcost(struct sctstr *start, s_char *path, int mob_type)
            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);
index 2780777842734d3b27f37d79d1c87d4abeeac1cf..3c503242d2418514d61d9593cb2e91efa74be838 100644 (file)
@@ -55,8 +55,9 @@ int diroff[][2] = {
 
 /* 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 */