From abf820bb5c8bcf51207ef941dbe00b7c425bf023 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 4 Jul 2017 14:40:10 -0400 Subject: [PATCH] Magic-number elimination. --- actions.c | 9 ++++----- advent.h | 2 +- main.c | 2 +- score.c | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/actions.c b/actions.c index 73f8f2e..34d0e48 100644 --- 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; diff --git a/advent.h b/advent.h index aaae641..98a52d2 100644 --- 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 00b8e46..3ae2615 100644 --- 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 e858681..c31ee6a 100644 --- 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; } -- 2.31.1