Eliminate globals.

This commit is contained in:
Eric S. Raymond 2017-06-07 14:03:33 -04:00
parent 2deb1b9f7f
commit 14fee6b979
5 changed files with 28 additions and 24 deletions

View file

@ -437,10 +437,7 @@ L9230: if(game.prop[ROD2] < 0 || !game.closed) return(2011);
/* Score. Call scoring routine but tell it to return. */ /* Score. Call scoring routine but tell it to return. */
L8240: score(-1); L8240: score(-1);
SETPRM(1,SCORE,MXSCOR); return(2012);
SETPRM(3,game.turns,game.turns);
RSPEAK(259);
return(2012);
/* FEE FIE FOE FOO (AND FUM). Advance to next state if given in proper order. /* 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 * Look up WD1 in section 3 of vocab to determine which word we've got. Last

View file

@ -6,6 +6,9 @@
#define LINESIZE 100 #define LINESIZE 100
#define NDWARVES 6 #define NDWARVES 6
#define PIRATE NDWARVES /* must be NDWARVES-1 when zero-origin */ #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 typedef struct lcg_state
{ {
@ -129,18 +132,18 @@ extern long MOD(long,long);
extern void set_seed(long); extern void set_seed(long);
extern unsigned long get_next_lcg_value(void); extern unsigned long get_next_lcg_value(void);
extern long randrange(long); extern long randrange(long);
extern void score(long); extern void score(long);
/* vocabulary items */
extern long AMBER, ATTACK, AXE, BACK, BATTER, BEAR, extern long AMBER, ATTACK, AXE, BACK, BATTER, BEAR,
BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, 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, EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, INVENT,
J, JADE, K, KEYS, KNIFE, L, LAMP, LOCK, LOOK, JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGZIN, MESSAG, MIRROR, NUGGET, NUL,
MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, NUGGET, NUL, OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAM,
OGRE, OIL, OLDOBJ, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAM, RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SCORE, SECT, SIGN, SNAKE,
RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2,
SCORE, SECT, SIGN, SNAKE, SPK, STEPS, STICK, URN, VASE, VEND, VOLCAN, WATER;
STREAM, THROW, TRIDNT, TROLL, TROLL2, /* evrything else */
URN, V1, V2, VASE, VEND, extern long I, J, K, L, MAXDIE, SPK, V1, V2, VRSION, WD1, WD1X, WD2, WD2X;
VOLCAN, VRSION, WATER, WD1, WD1X, WD2, WD2X;

6
init.c
View file

@ -215,14 +215,13 @@ L1106: /*etc*/ ;
if(PLAC[K] != 0 && FIXD[K] <= 0)DROP(K,PLAC[K]); if(PLAC[K] != 0 && FIXD[K] <= 0)DROP(K,PLAC[K]);
} /* end loop */ } /* 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 * 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 * described. game.tally keeps track of how many are not yet found, so we know
* when to close the cave. */ * when to close the cave. */
MAXTRS=79;
game.tally=0; game.tally=0;
for (I=50; I<=MAXTRS; I++) { for (I=MINTRS; I<=MAXTRS; I++) {
if(PTEXT[I] != 0)game.prop[I]= -1; if(PTEXT[I] != 0)game.prop[I]= -1;
game.tally=game.tally-game.prop[I]; game.tally=game.tally-game.prop[I];
} /* end loop */ } /* end loop */
@ -341,7 +340,6 @@ L1106: /*etc*/ ;
game.dloc[4]=44; game.dloc[4]=44;
game.dloc[5]=64; game.dloc[5]=64;
game.dloc[6]=game.chloc; game.dloc[6]=game.chloc;
DALTLC=18;
/* Other random flags and counters, as follows: /* Other random flags and counters, as follows:
* game.abbnum How often we should print non-abbreviated descriptions * game.abbnum How often we should print non-abbreviated descriptions

6
main.c
View file

@ -19,11 +19,11 @@ char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129];
long AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, long AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD,
BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, 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, EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD,
GRATE, HINT, I, INVENT, J, JADE, K, KEYS, GRATE, HINT, I, INVENT, J, JADE, K, KEYS,
KNIFE, L, LAMP, LOCK, LOOK, MAGZIN, MAXDIE, MAXTRS, KNIFE, L, LAMP, LOCK, LOOK, MAGZIN, MAXDIE,
MESSAG, MIRROR, MXSCOR, NUGGET, NUL, OGRE, OIL, OYSTER, MESSAG, MIRROR, NUGGET, NUL, OGRE, OIL, OYSTER,
PEARL, PILLOW, PLANT, PLANT2, PYRAM, RESER, ROD, ROD2, PEARL, PILLOW, PLANT, PLANT2, PYRAM, RESER, ROD, ROD2,
RUBY, RUG, SAPPH, SAY, SCORE, SECT, SIGN, SNAKE, SPK, RUBY, RUG, SAPPH, SAY, SCORE, SECT, SIGN, SNAKE, SPK,
STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2, STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2,

10
score.c
View file

@ -7,7 +7,8 @@
*/ */
void score(long MODE) { 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: /* The present scoring algorithm is as follows:
* Objective: Points: Present total possible: * Objective: Points: Present total possible:
@ -88,7 +89,12 @@ L20020: MXSCOR=MXSCOR+45;
/* Return to score command if that's where we came from. */ /* 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. */ /* that should be good enough. Let's tell him all about it. */