Magic-number elimination.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 4 Jul 2017 18:40:10 +0000 (14:40 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 4 Jul 2017 18:40:10 +0000 (14:40 -0400)
actions.c
advent.h
main.c
score.c

index 73f8f2e7ac89fb3ae72690ef0a3ddeb0da5026ca..34d0e48ef8d291bbfd364bf0bedfb73908cebe3a 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -386,8 +386,8 @@ static int vcarry(token_t verb, token_t obj)
     carry(obj, game.loc);
     if (obj == BOTTLE && LIQUID() != NO_OBJECT)
         game.place[LIQUID()] = CARRIED;
-    if (GSTONE(obj) && game.prop[obj] != STATE_GROUND) {
-        game.prop[obj] = STATE_GROUND;
+    if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
+        game.prop[obj] = STATE_FOUND;
         game.prop[CAVITY] = CAVITY_EMPTY;
     }
     rspeak(OK_MAN);
@@ -662,7 +662,7 @@ static int feed(token_t verb, token_t obj)
             DESTROY(FOOD);
             game.prop[BEAR] = SITTING_BEAR;
             game.fixed[AXE] = 0;
-            game.prop[AXE] = 0;
+            game.prop[AXE] = AXE_HERE;
             spk = BEAR_TAMED;
         }
     } else if (obj == OGRE) {
@@ -1110,7 +1110,6 @@ static int say(struct command_t *command)
     char word1[TOKLEN + 1];
     packed_to_token(command->wd1, word1);
     int wd = (int) get_vocab_id(word1);
-    /* FIXME: magic numbers */
     if (wd == MOTION_WORD(XYZZY) ||
         wd == MOTION_WORD(PLUGH) ||
         wd == MOTION_WORD(PLOVER) ||
@@ -1224,7 +1223,7 @@ static int wave(token_t verb, token_t obj)
 
     if (game.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] < 0) {
         drop(JADE, game.loc);
-        game.prop[JADE] = 0;
+        game.prop[JADE] = STATE_FOUND;
         --game.tally;
         rspeak(NECKLACE_FLY);
         return GO_CLEAROBJ;
index aaae64117d155c34392aacc5714c15d855a72ba7..98a52d250e4f57376322a1ad7a365383f1e99d84 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -27,7 +27,7 @@
 
 /* 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
+#define STATE_FOUND    0         // After discovered, before messed with
 #define STATE_IN_CAVITY        1         // State value common to all gemstones
 
 /* Map a state property value to a negative range, where the object cannot be
diff --git a/main.c b/main.c
index 00b8e4617b8e22e47eb61a6d974c809a451dad8e..3ae2615908bbc5536ad3c102135cafac7b178297 100644 (file)
--- a/main.c
+++ b/main.c
@@ -915,7 +915,7 @@ static void listobjects(void)
             if (game.prop[obj] < 0) {
                 if (game.closed)
                     continue;
-                game.prop[obj] = 0;
+                game.prop[obj] = STATE_FOUND;
                 if (obj == RUG)
                     game.prop[RUG] = RUG_DRAGON;
                 if (obj == CHAIN)
diff --git a/score.c b/score.c
index e858681c40b535cbb82becdeb08c1e9d03741550..c31ee6a88dc2ec7bcc0d0c856869b0f4d585c5cf 100644 (file)
--- a/score.c
+++ b/score.c
@@ -47,7 +47,7 @@ long score(enum termination mode)
                 k = 16;
             if (game.prop[i] > STATE_NOTFOUND)
                 score += 2;
-            if (game.place[i] == LOC_BUILDING && game.prop[i] == STATE_GROUND)
+            if (game.place[i] == LOC_BUILDING && game.prop[i] == STATE_FOUND)
                 score += k - 2;
             mxscor += k;
         }