Magic-number elimination.

This commit is contained in:
Eric S. Raymond 2017-06-13 18:54:53 -04:00
parent d61cab352e
commit dc6a5751ed
3 changed files with 10 additions and 8 deletions

View file

@ -11,7 +11,8 @@
#define MAXTRS 79 #define MAXTRS 79
#define MAXPARMS 25 #define MAXPARMS 25
#define INVLIMIT 7 #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 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 GSTONE(OBJ) ((OBJ) == EMRALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
#define FOREST(LOC) ((LOC) >= 145 && (LOC) <= 166) #define FOREST(LOC) ((LOC) >= 145 && (LOC) <= 166)
#define VOCWRD(LETTRS,SECT) (VOCAB(MAKEWD(LETTRS),SECT)) #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 /* The following two functions were added to fix a bug (game.clock1 decremented
* while in forest). They should probably be replaced by using another * while in forest). They should probably be replaced by using another

12
main.c
View file

@ -384,8 +384,8 @@ static bool dwarfmove(void)
if (kk != 0) if (kk != 0)
do { do {
game.newloc=MOD(labs(TRAVEL[kk])/1000,1000); game.newloc=MOD(labs(TRAVEL[kk])/1000,1000);
/* Have we avoided a dwarf enciounter? */ /* Have we avoided a dwarf encounter? */
bool avoided = (game.newloc > 300 || bool avoided = (SPECIAL(game.newloc) ||
!INDEEP(game.newloc) || !INDEEP(game.newloc) ||
game.newloc == game.odloc[i] || game.newloc == game.odloc[i] ||
(j > 1 && game.newloc == TK[j-1]) || (j > 1 && game.newloc == TK[j-1]) ||
@ -529,7 +529,7 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
for (;;) { for (;;) {
LL=MOD((labs(TRAVEL[KK])/1000),1000); LL=MOD((labs(TRAVEL[KK])/1000),1000);
if (LL != motion) { if (LL != motion) {
if (LL <= 300) { if (!SPECIAL(LL)) {
if (FORCED(LL) && MOD((labs(TRAVEL[KEY[LL]])/1000),1000) == motion) if (FORCED(LL) && MOD((labs(TRAVEL[KEY[LL]])/1000),1000) == motion)
K2=KK; K2=KK;
} }
@ -607,7 +607,7 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
for (;;) { for (;;) {
game.newloc=LL/1000; game.newloc=LL/1000;
motion=MOD(game.newloc,100); motion=MOD(game.newloc,100);
if (game.newloc <= 300) { if (!SPECIAL(game.newloc)) {
if (game.newloc <= 100) { if (game.newloc <= 100) {
if (game.newloc == 0 || PCT(game.newloc)) if (game.newloc == 0 || PCT(game.newloc))
break; break;
@ -628,10 +628,10 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
} }
game.newloc=MOD(LL,1000); game.newloc=MOD(LL,1000);
if (game.newloc <= 300) if (!SPECIAL(game.newloc))
return true; return true;
if (game.newloc <= 500) { if (game.newloc <= 500) {
game.newloc=game.newloc-300; game.newloc=game.newloc-SPECIALBASE;
switch (game.newloc) switch (game.newloc)
{ {
case 1: case 1:

2
misc.c
View file

@ -367,7 +367,7 @@ void MOVE(long object, long where)
from=game.fixed[object-NOBJECTS]; from=game.fixed[object-NOBJECTS];
else else
from=game.place[object]; from=game.place[object];
if (from > 0 && from <= 300) if (from > 0 && !SPECIAL(from))
CARRY(object,from); CARRY(object,from);
DROP(object,where); DROP(object,where);
} }