From dc6a5751ed04ff15103c9852c8dc7427298b6945 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 13 Jun 2017 18:54:53 -0400 Subject: [PATCH] Magic-number elimination. --- advent.h | 4 +++- main.c | 12 ++++++------ misc.c | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/advent.h b/advent.h index 477b8b8..ee8e3fa 100644 --- a/advent.h +++ b/advent.h @@ -11,7 +11,8 @@ #define MAXTRS 79 #define MAXPARMS 25 #define INVLIMIT 7 -#define INTRANSITIVE -1 /* illegal object number */ +#define INTRANSITIVE -1 /* illegal object number */ +#define SPECIALBASE 300 /* base umber of special rooms */ typedef struct lcg_state { @@ -146,6 +147,7 @@ extern int saveresume(FILE *, bool); #define GSTONE(OBJ) ((OBJ) == EMRALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH) #define FOREST(LOC) ((LOC) >= 145 && (LOC) <= 166) #define VOCWRD(LETTRS,SECT) (VOCAB(MAKEWD(LETTRS),SECT)) +#define SPECIAL(LOC) ((LOC) > SPECIALBASE) /* The following two functions were added to fix a bug (game.clock1 decremented * while in forest). They should probably be replaced by using another diff --git a/main.c b/main.c index 1f866d8..27a7a09 100644 --- a/main.c +++ b/main.c @@ -384,8 +384,8 @@ static bool dwarfmove(void) if (kk != 0) do { game.newloc=MOD(labs(TRAVEL[kk])/1000,1000); - /* Have we avoided a dwarf enciounter? */ - bool avoided = (game.newloc > 300 || + /* Have we avoided a dwarf encounter? */ + bool avoided = (SPECIAL(game.newloc) || !INDEEP(game.newloc) || game.newloc == game.odloc[i] || (j > 1 && game.newloc == TK[j-1]) || @@ -529,7 +529,7 @@ static bool playermove(FILE *cmdin, token_t verb, int motion) for (;;) { LL=MOD((labs(TRAVEL[KK])/1000),1000); if (LL != motion) { - if (LL <= 300) { + if (!SPECIAL(LL)) { if (FORCED(LL) && MOD((labs(TRAVEL[KEY[LL]])/1000),1000) == motion) K2=KK; } @@ -607,7 +607,7 @@ static bool playermove(FILE *cmdin, token_t verb, int motion) for (;;) { game.newloc=LL/1000; motion=MOD(game.newloc,100); - if (game.newloc <= 300) { + if (!SPECIAL(game.newloc)) { if (game.newloc <= 100) { if (game.newloc == 0 || PCT(game.newloc)) break; @@ -628,10 +628,10 @@ static bool playermove(FILE *cmdin, token_t verb, int motion) } game.newloc=MOD(LL,1000); - if (game.newloc <= 300) + if (!SPECIAL(game.newloc)) return true; if (game.newloc <= 500) { - game.newloc=game.newloc-300; + game.newloc=game.newloc-SPECIALBASE; switch (game.newloc) { case 1: diff --git a/misc.c b/misc.c index c47ce1d..6f33146 100644 --- a/misc.c +++ b/misc.c @@ -367,7 +367,7 @@ void MOVE(long object, long where) from=game.fixed[object-NOBJECTS]; else from=game.place[object]; - if (from > 0 && from <= 300) + if (from > 0 && !SPECIAL(from)) CARRY(object,from); DROP(object,where); } -- 2.31.1