Magic-number elimination.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 2 Jul 2017 17:22:50 +0000 (13:22 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 2 Jul 2017 17:22:50 +0000 (13:22 -0400)
actions.c
advent.h
init.c
main.c

index ad09b4a254f0b584cdbbdef5124aa53eb91705f0..076a2b29bd61cf67140e25a5208ebbbaefeff593 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -825,7 +825,7 @@ static int lock(token_t verb, token_t obj)
         return bivalve(verb, obj);
     if (obj == DOOR)
         spk = RUSTY_DOOR;
-    if (obj == DOOR && game.prop[DOOR] == 1)
+    if (obj == DOOR && game.prop[DOOR] == DOOR_UNRUSTED)
         spk = OK_MAN;
     if (obj == CAGE)
         spk = NO_LOCK;
@@ -869,7 +869,7 @@ static int pour(token_t verb, token_t obj)
         rspeak(spk);
         return GO_CLEAROBJ;
     }
-    if (HERE(URN) && game.prop[URN] == 0)
+    if (HERE(URN) && game.prop[URN] == URN_EMPTY)
         return fill(verb, URN);
     game.prop[BOTTLE] = EMPTY_BOTTLE;
     game.place[obj] = LOC_NOWHERE;
@@ -952,7 +952,7 @@ static int rub(token_t verb, token_t obj)
     int spk = actions[verb].message;
     if (obj != LAMP)
         spk = PECULIAR_NOTHING;
-    if (obj == URN && game.prop[URN] == 2) {
+    if (obj == URN && game.prop[URN] == URN_LIT) {
         DESTROY(URN);
         drop(AMBER, game.loc);
         game.prop[AMBER] = 1;
index a7f5ac4c71d1814a1b653271e942c0a41b174e2e..b9b2e0c996608e9eb309197ae727ee1eaf72e94f 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -19,6 +19,7 @@
 #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
diff --git a/init.c b/init.c
index 5372714566f336ddd0e65090ea5afee59f94195b..87a51616877d9de7468079d260709b50ac0fdb2a 100644 (file)
--- a/init.c
+++ b/init.c
@@ -92,7 +92,7 @@ long initialise(void)
     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
         if (objects[treasure].is_treasure) {
             if (objects[treasure].inventory != 0)
-                game.prop[treasure] = -1;
+                game.prop[treasure] = NOT_YET_FOUND;
             game.tally = game.tally - game.prop[treasure];
         }
     }
diff --git a/main.c b/main.c
index 1269efaf935fcc289b6023d4deb151d90c3300b0..7eb21dab571a9be8d7c381f89ddac3d67eafb91a 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] != -1 && game.prop[PYRAMID] == -1)
+                    if (game.prop[EMERALD] != NOT_YET_FOUND && game.prop[PYRAMID] == NOT_YET_FOUND)
                         break;
                     game.hintlc[hint] = 0;
                     return;