From: Eric S. Raymond Date: Wed, 7 Jun 2017 18:03:33 +0000 (-0400) Subject: Eliminate globals. X-Git-Tag: 1.1~559 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=14fee6b979b9803e8d499f19c4cd1e0373665155;p=open-adventure.git Eliminate globals. --- diff --git a/actions1.c b/actions1.c index 100ef83..f1de63b 100644 --- a/actions1.c +++ b/actions1.c @@ -437,10 +437,7 @@ L9230: if(game.prop[ROD2] < 0 || !game.closed) return(2011); /* Score. Call scoring routine but tell it to return. */ L8240: score(-1); - SETPRM(1,SCORE,MXSCOR); - SETPRM(3,game.turns,game.turns); - RSPEAK(259); - return(2012); + return(2012); /* FEE FIE FOE FOO (AND FUM). Advance to next state if given in proper order. * Look up WD1 in section 3 of vocab to determine which word we've got. Last diff --git a/advent.h b/advent.h index 33ed6cf..827c53f 100644 --- a/advent.h +++ b/advent.h @@ -6,6 +6,9 @@ #define LINESIZE 100 #define NDWARVES 6 #define PIRATE NDWARVES /* must be NDWARVES-1 when zero-origin */ +#define DALTLC 18 /* alternate dwarf location; low room */ +#define MINTRS 50 +#define MAXTRS 79 typedef struct lcg_state { @@ -129,18 +132,18 @@ extern long MOD(long,long); extern void set_seed(long); extern unsigned long get_next_lcg_value(void); extern long randrange(long); - extern void score(long); + +/* vocabulary items */ extern long AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, - CLAM, COINS, DALTLC, DOOR, DPRSSN, DRAGON, DWARF, EGGS, - EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, I, INVENT, - J, JADE, K, KEYS, KNIFE, L, LAMP, LOCK, LOOK, - MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, NUGGET, NUL, - OGRE, OIL, OLDOBJ, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAM, - RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, - SCORE, SECT, SIGN, SNAKE, SPK, STEPS, STICK, - STREAM, THROW, TRIDNT, TROLL, TROLL2, - URN, V1, V2, VASE, VEND, - VOLCAN, VRSION, WATER, WD1, WD1X, WD2, WD2X; + CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS, + EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, INVENT, + JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGZIN, MESSAG, MIRROR, NUGGET, NUL, + OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAM, + RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SCORE, SECT, SIGN, SNAKE, + STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2, + URN, VASE, VEND, VOLCAN, WATER; +/* evrything else */ +extern long I, J, K, L, MAXDIE, SPK, V1, V2, VRSION, WD1, WD1X, WD2, WD2X; diff --git a/init.c b/init.c index 0e6ae1c..3d967ef 100644 --- a/init.c +++ b/init.c @@ -215,14 +215,13 @@ L1106: /*etc*/ ; if(PLAC[K] != 0 && FIXD[K] <= 0)DROP(K,PLAC[K]); } /* end loop */ -/* Treasures, as noted earlier, are objects 50 through MAXTRS (CURRENTLY 79). +/* Treasures, as noted earlier, are objects MINTRS through MAXTRS * Their props are initially -1, and are set to 0 the first time they are * described. game.tally keeps track of how many are not yet found, so we know * when to close the cave. */ - MAXTRS=79; game.tally=0; - for (I=50; I<=MAXTRS; I++) { + for (I=MINTRS; I<=MAXTRS; I++) { if(PTEXT[I] != 0)game.prop[I]= -1; game.tally=game.tally-game.prop[I]; } /* end loop */ @@ -341,7 +340,6 @@ L1106: /*etc*/ ; game.dloc[4]=44; game.dloc[5]=64; game.dloc[6]=game.chloc; - DALTLC=18; /* Other random flags and counters, as follows: * game.abbnum How often we should print non-abbreviated descriptions diff --git a/main.c b/main.c index 78577af..c6a1eef 100644 --- a/main.c +++ b/main.c @@ -19,11 +19,11 @@ char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129]; long AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, - CLAM, COINS, DALTLC, DOOR, DPRSSN, DRAGON, DWARF, EGGS, + CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS, EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, I, INVENT, J, JADE, K, KEYS, - KNIFE, L, LAMP, LOCK, LOOK, MAGZIN, MAXDIE, MAXTRS, - MESSAG, MIRROR, MXSCOR, NUGGET, NUL, OGRE, OIL, OYSTER, + KNIFE, L, LAMP, LOCK, LOOK, MAGZIN, MAXDIE, + MESSAG, MIRROR, NUGGET, NUL, OGRE, OIL, OYSTER, PEARL, PILLOW, PLANT, PLANT2, PYRAM, RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SCORE, SECT, SIGN, SNAKE, SPK, STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2, diff --git a/score.c b/score.c index ef80e68..d0915b2 100644 --- a/score.c +++ b/score.c @@ -7,7 +7,8 @@ */ void score(long MODE) { - /* <0 if scoring, >0 if quitting, =0 if died or won */ +/* arg is <0 if scoring, >0 if quitting, =0 if died or won */ + long MXSCOR = 0; /* The present scoring algorithm is as follows: * Objective: Points: Present total possible: @@ -88,7 +89,12 @@ L20020: MXSCOR=MXSCOR+45; /* Return to score command if that's where we came from. */ - if(MODE < 0) return; + if(MODE < 0) { + SETPRM(1,SCORE,MXSCOR); + SETPRM(3,game.turns,game.turns); + RSPEAK(259); + return; + } /* that should be good enough. Let's tell him all about it. */