From 978168523abcc3e4f06c23df57dc47541cd995ca Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 6 Jun 2017 11:12:00 -0400 Subject: [PATCH] Magic-number elimination. --- actions1.c | 8 ++++---- actions2.c | 2 +- advent.h | 1 + compile.c | 2 +- init.c | 5 ++++- main.c | 16 ++++++++-------- misc.c | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/actions1.c b/actions1.c index a1a7cd2..8a7ccad 100644 --- a/actions1.c +++ b/actions1.c @@ -542,13 +542,13 @@ L8305: DATIME(&I,&K); SAVWDS(OBJTXT[SIGN],CLSHNT,NOVICE,K,K,K,K); SAVARR(ABB,LOCSIZ); SAVARR(ATLOC,LOCSIZ); - SAVARR(DLOC,6); - SAVARR(DSEEN,6); + SAVARR(DLOC,NDWARVES); + SAVARR(DSEEN,NDWARVES); SAVARR(FIXED,NOBJECTS); SAVARR(HINTED,HNTSIZ); SAVARR(HINTLC,HNTSIZ); - SAVARR(LINK,200); - SAVARR(ODLOC,6); + SAVARR(LINK,NOBJECTS*2); + SAVARR(ODLOC,NDWARVES); SAVARR(PLACE,NOBJECTS); SAVARR(PROP,NOBJECTS); SAVWRD(KK,K); diff --git a/actions2.c b/actions2.c index a169c48..295f188 100644 --- a/actions2.c +++ b/actions2.c @@ -232,7 +232,7 @@ int throw(FILE *cmdin) { return(attack(cmdin)); L9172: SPK=48; - if(randrange(7) < DFLAG) goto L9175; + if(randrange(NDWARVES+1) < DFLAG) goto L9175; DSEEN[I]=false; DLOC[I]=0; SPK=47; diff --git a/advent.h b/advent.h index 443ab0a..396454e 100644 --- a/advent.h +++ b/advent.h @@ -2,6 +2,7 @@ #include #define LINESIZE 100 +#define NDWARVES 6 typedef struct lcg_state { diff --git a/compile.c b/compile.c index 9ffaf4c..c501e5b 100644 --- a/compile.c +++ b/compile.c @@ -550,7 +550,7 @@ void write_files(FILE* c_file, FILE* header_file) fprintf(header_file, "#define RTXSIZ 277\n"); fprintf(header_file, "#define CLSMAX 12\n"); fprintf(header_file, "#define LOCSIZ 185\n"); - fprintf(header_file, "#define LINSIZ 12500\n"); + fprintf(header_file, "#define LINSIZ %d\n", LINSIZ); fprintf(header_file, "#define TRNSIZ 5\n"); fprintf(header_file, "#define TABSIZ 330\n"); fprintf(header_file, "#define VRBSIZ 35\n"); diff --git a/init.c b/init.c index aedbeec..53552f7 100644 --- a/init.c +++ b/init.c @@ -30,7 +30,10 @@ * 300 locations * 100 objects */ -/* Note: the object count limit has been abstracted as NOBJECTS */ +/* Note: + * - the object count limit has been abstracted as NOBJECTS + * - the random message limit has been abstracted as RTXSIZE + */ /* Description of the database format * diff --git a/main.c b/main.c index 120642b..640a6fb 100644 --- a/main.c +++ b/main.c @@ -14,7 +14,7 @@ long ABB[186], ATLOC[186], BLKLIN = true, DFLAG, DLOC[7], FIXED[NOBJECTS+1], HOLDNG, - LINK[201], LNLENG, LNPOSN, + LINK[NOBJECTS*2 + 1], LNLENG, LNPOSN, PARMS[26], PLACE[NOBJECTS+1], SETUP = 0; char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129]; @@ -23,7 +23,7 @@ long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BONUS, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CHLOC, CHLOC2, CLAM, CLOCK1, CLOCK2, CLOSED, CLOSNG, CLSHNT, COINS, CONDS, DALTLC, DETAIL, - DKILL, DOOR, DPRSSN, DRAGON, DSEEN[7], DTOTAL, DWARF, EGGS, + DKILL, DOOR, DPRSSN, DRAGON, DSEEN[NDWARVES+1], DTOTAL, DWARF, EGGS, EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOBAR, FOOD, GRATE, HINT, HINTED[21], HINTLC[21], I, INVENT, IGO, IWEST, J, JADE, K, K2, KEYS, KK, @@ -32,7 +32,7 @@ long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BONUS, MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, - ODLOC[7], OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, + ODLOC[NDWARVES+1], OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PROP[NOBJECTS+1], PYRAM, RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAVED, SAY, SCORE, SECT, SIGN, SNAKE, SPK, STEPS, STICK, @@ -179,7 +179,7 @@ static bool do_command(FILE *cmdin) { * (dwarves rooted in place) let him get out (and attacked). */ L71: if(NEWLOC == LOC || FORCED(LOC) || CNDBIT(LOC,3)) goto L74; - /* 73 */ for (I=1; I<=5; I++) { + /* 73 */ for (I=1; I<=NDWARVES-1; I++) { if(ODLOC[I] != NEWLOC || !DSEEN[I]) goto L73; NEWLOC=LOC; RSPEAK(2); @@ -210,10 +210,10 @@ L6000: if(DFLAG != 1) goto L6010; if(!INDEEP(LOC) || (PCT(95) && (!CNDBIT(LOC,4) || PCT(85)))) goto L2000; DFLAG=2; for (I=1; I<=2; I++) { - J=1+randrange(5); + J=1+randrange(NDWARVES-1); if(PCT(50))DLOC[J]=0; } /* end loop */ - for (I=1; I<=5; I++) { + for (I=1; I<=NDWARVES-1; I++) { if(DLOC[I] == LOC)DLOC[I]=DALTLC; ODLOC[I]=DLOC[I]; } /* end loop */ @@ -229,7 +229,7 @@ L6000: if(DFLAG != 1) goto L6010; L6010: DTOTAL=0; ATTACK=0; STICK=0; - /* 6030 */ for (I=1; I<=6; I++) { + /* 6030 */ for (I=1; I<=NDWARVES; I++) { if(DLOC[I] == 0) goto L6030; /* Fill TK array with all the places this dwarf might go. */ J=1; @@ -827,7 +827,7 @@ L41000: if(TALLY == 1 && PROP[JADE] < 0) goto L40010; L10000: PROP[GRATE]=0; PROP[FISSUR]=0; - for (I=1; I<=6; I++) { + for (I=1; I<=NDWARVES; I++) { DSEEN[I]=false; DLOC[I]=0; } /* end loop */ diff --git a/misc.c b/misc.c index 0126d69..46772d5 100644 --- a/misc.c +++ b/misc.c @@ -593,7 +593,7 @@ long AT, I; AT=0; if(DFLAG < 2)return(AT); AT= -1; - for (I=1; I<=5; I++) { + for (I=1; I<=NDWARVES-1; I++) { if(DLOC[I] == WHERE) goto L2; if(DLOC[I] != 0)AT=0; } /* end loop */ -- 2.31.1