From e712f4c0e05bfa842e342f60f7ea3e33da9199fd Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 2 Jul 2017 14:47:21 -0400 Subject: [PATCH] Magic-number elimination. --- actions.c | 7 +++---- advent.h | 5 ++++- init.c | 2 +- main.c | 4 ++-- score.c | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/actions.c b/actions.c index 0a5b8ed..aa488e0 100644 --- 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); diff --git a/advent.h b/advent.h index c0c6265..2ef6a59 100644 --- a/advent.h +++ b/advent.h @@ -19,11 +19,14 @@ #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 12f68b6..2fffc27 100644 --- 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 2a1f436..8dcaa52 100644 --- 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 00ee001..e858681 100644 --- 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; } -- 2.31.1