Magic-number elimination.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 2 Jul 2017 18:47:21 +0000 (14:47 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 2 Jul 2017 18:47:21 +0000 (14:47 -0400)
actions.c
advent.h
init.c
main.c
score.c

index 0a5b8edb30ba09bcbb50c55ded35b0eec4a5a464..aa488e018bf39a74bae0f07759761998d216d95f 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -166,10 +166,9 @@ static int attack(struct command_t *command)
 
 static int bigwords(token_t foo)
 /*  FEE FIE FOE FOO (AND FUM).  Advance to next state if given in proper order.
- *  Look up foo in section 3 of vocab to determine which word we've got.  Last
- *  word zips the eggs back to the giant room (unless already there). */
+ *  Look up foo in special section of vocab to determine which word we've got.
+ *  Last word zips the eggs back to the giant room (unless already there). */
 {
-    //int k = vocab(foo, 3);
     char word[6];
     packed_to_token(foo, word);
     int k = (int) get_special_vocab_id(word);
@@ -362,7 +361,7 @@ static int vcarry(token_t verb, token_t obj)
     if (obj == BOTTLE && LIQUID() != 0)
         game.place[LIQUID()] = CARRIED;
     if (GSTONE(obj) && game.prop[obj] != 0) {
-        game.prop[obj] = 0;
+        game.prop[obj] = STATE_GROUND;
         game.prop[CAVITY] = CAVITY_EMPTY;
     }
     rspeak(OK_MAN);
index c0c6265f8bbf09a4453b530fc8f5689032826c19..2ef6a59bdf59ea88f26d5138a72a6a26f3011768 100644 (file)
--- a/advent.h
+++ b/advent.h
 #define PANICTIME      15         // time left after closing
 #define BATTERYLIFE    2500       // turn limit increment from batteries
 #define WORD_NOT_FOUND -1         // "Word not found" flag value for the vocab hash functions.
-#define NOT_YET_FOUND  -1        // 'Not found" state of treasures */
 #define CARRIED        -1         // Player is toting it
 #define READ_MODE      "rb"       // b is not needed for POSIX but harmless
 #define WRITE_MODE     "wb"       // b is not needed for POSIX but harmless
 
+/* Special object-state values - integers > 0 are object-specific */
+#define STATE_NOTFOUND  -1       // 'Not found" state of treasures */
+#define STATE_GROUND   0         // After discovered, before messed with
+
 /*
  *  MOD(N,M)    = Arithmetic modulus
  *  AT(OBJ)     = true if on either side of two-placed object
diff --git a/init.c b/init.c
index 12f68b6017f9346097d82ff4b349e6704263e95a..2fffc279c1ee7f691efa0d35eeac8ef9d34c5499 100644 (file)
--- a/init.c
+++ b/init.c
@@ -91,7 +91,7 @@ long initialise(void)
     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
         if (objects[treasure].is_treasure) {
             if (objects[treasure].inventory != 0)
-                game.prop[treasure] = NOT_YET_FOUND;
+                game.prop[treasure] = STATE_NOTFOUND;
             game.tally = game.tally - game.prop[treasure];
         }
     }
diff --git a/main.c b/main.c
index 2a1f436a19d4142eac816be066f127eb993a859e..8dcaa52eda8e465e4e2a31817acd6ffc8e46b5d4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -185,7 +185,7 @@ static void checkhints(void)
                     game.hintlc[hint] = 0;
                     return;
                 case 4:        /* dark */
-                    if (game.prop[EMERALD] != NOT_YET_FOUND && game.prop[PYRAMID] == NOT_YET_FOUND)
+                    if (game.prop[EMERALD] != STATE_NOTFOUND && game.prop[PYRAMID] == STATE_NOTFOUND)
                         break;
                     game.hintlc[hint] = 0;
                     return;
@@ -1076,7 +1076,7 @@ L2607:
         packed_to_token(command.wd2, word2);
         V1 = get_vocab_id(word1);
         V2 = get_vocab_id(word2);
-        if (V1 == ENTER && (V2 == STREAM || V2 == 1000 + WATER)) {
+        if (V1 == ENTER && (V2 == STREAM || V2 == PROMOTE_WORD(WATER))) {
             if (LIQLOC(game.loc) == WATER) {
                 rspeak(FEET_WET);
             } else {
diff --git a/score.c b/score.c
index 00ee001dafd69ca200334637fbd5b0b50bddba38..e858681c40b535cbb82becdeb08c1e9d03741550 100644 (file)
--- a/score.c
+++ b/score.c
@@ -45,9 +45,9 @@ long score(enum termination mode)
                 k = 14;
             if (i > CHEST)
                 k = 16;
-            if (game.prop[i] >= 0)
+            if (game.prop[i] > STATE_NOTFOUND)
                 score += 2;
-            if (game.place[i] == LOC_BUILDING && game.prop[i] == 0)
+            if (game.place[i] == LOC_BUILDING && game.prop[i] == STATE_GROUND)
                 score += k - 2;
             mxscor += k;
         }