From: Eric S. Raymond Date: Wed, 7 Jun 2017 05:12:49 +0000 (-0400) Subject: Move more globals into the game state block. X-Git-Tag: 1.1~588 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=91ad0185ffcbda83f115433c630b40e4ea6f7a41;p=open-adventure.git Move more globals into the game state block. --- diff --git a/actions1.c b/actions1.c index b9a0dd2..fb28827 100644 --- a/actions1.c +++ b/actions1.c @@ -133,8 +133,8 @@ L5110: if(K == DWARF && ATDWRF(LOC) > 0) goto L5010; L5120: if(OBJ != PLANT || !AT(PLANT2) || PROP[PLANT2] == 0) goto L5130; OBJ=PLANT2; goto L5010; -L5130: if(OBJ != KNIFE || KNFLOC != LOC) goto L5140; - KNFLOC= -1; +L5130: if(OBJ != KNIFE || game.knfloc != LOC) goto L5140; + game.knfloc= -1; SPK=116; return(2011); L5140: if(OBJ != ROD || !HERE(ROD2)) goto L5190; @@ -247,14 +247,14 @@ L9049: SPK=172; /* Light. Applicable only to lamp and urn. */ -L8070: if(HERE(LAMP) && PROP[LAMP] == 0 && LIMIT >= 0)OBJ=LAMP; +L8070: if(HERE(LAMP) && PROP[LAMP] == 0 && game.limit >= 0)OBJ=LAMP; if(HERE(URN) && PROP[URN] == 1)OBJ=OBJ*NOBJECTS+URN; if(OBJ == 0 || OBJ > NOBJECTS) return(8000); L9070: if(OBJ == URN) goto L9073; if(OBJ != LAMP) return(2011); SPK=184; - if(LIMIT < 0) return(2011); + if(game.limit < 0) return(2011); PROP[LAMP]=1; RSPEAK(39); if(game.wzdark) return(2000); @@ -446,13 +446,13 @@ L8240: score(-1); L8250: K=VOCAB(WD1,3); SPK=42; - if(FOOBAR == 1-K) goto L8252; - if(FOOBAR != 0)SPK=151; + if(game.foobar == 1-K) goto L8252; + if(game.foobar != 0)SPK=151; return(2011); -L8252: FOOBAR=K; +L8252: game.foobar=K; if(K != 4) return(2009); - FOOBAR=0; + game.foobar=0; if(PLACE[EGGS] == PLAC[EGGS] || (TOTING(EGGS) && LOC == PLAC[EGGS])) return(2011); /* Bring back troll if we steal the eggs back from him before crossing. */ @@ -534,8 +534,8 @@ L8305: DATIME(&I,&K); * needs to be saved, include it. Overkill can't hurt. Pad the last savwds * with junk variables to bring it up to 7 values. */ SAVWDS(game.abbnum,game.blklin,game.bonus,game.clock1,game.clock2,game.closed,game.closng); - SAVWDS(game.detail,DFLAG,game.dkill,game.dtotal,FOOBAR,HOLDNG,IWEST); - SAVWDS(KNFLOC,LIMIT,LL,LMWARN,LOC,NEWLOC,NUMDIE); + SAVWDS(game.detail,game.dflag,game.dkill,game.dtotal,game.foobar,game.holdng,game.iwest); + SAVWDS(game.knfloc,game.limit,LL,game.lmwarn,LOC,NEWLOC,NUMDIE); SAVWDS(OBJ,game.oldlc2,game.oldloc,OLDOBJ,PANIC,SAVED,SETUP); SAVWDS(SPK,TALLY,THRESH,TRNDEX,TRNLUZ,TURNS,OBJTXT[OYSTER]); SAVWDS(VERB,WD1,WD1X,WD2,game.wzdark,game.zzword,OBJSND[BIRD]); diff --git a/actions2.c b/actions2.c index 67ef05c..3078408 100644 --- a/actions2.c +++ b/actions2.c @@ -29,7 +29,7 @@ L9011: if(FIXED[OBJ] != 0) return(2011); if(!TOTING(BOTTLE))SPK=104; return(2011); L9017: SPK=92; - if(HOLDNG >= 7) return(2011); + if(game.holdng >= 7) return(2011); if(OBJ != BIRD || PROP[BIRD] == 1 || -1-PROP[BIRD] == 1) goto L9014; if(PROP[BIRD] == 2) goto L9015; if(!TOTING(CAGE))SPK=27; @@ -232,7 +232,7 @@ int throw(FILE *cmdin) { return(attack(cmdin)); L9172: SPK=48; - if(randrange(NDWARVES+1) < DFLAG) goto L9175; + if(randrange(NDWARVES+1) < game.dflag) goto L9175; game.dseen[I]=false; game.dloc[I]=0; SPK=47; @@ -287,7 +287,7 @@ L9212: if(OBJ != SNAKE && OBJ != DRAGON && OBJ != TROLL) goto L9213; L9213: if(OBJ != DWARF) goto L9214; if(!HERE(FOOD)) return(2011); SPK=103; - DFLAG=DFLAG+2; + game.dflag=game.dflag+2; return(2011); L9214: if(OBJ != BEAR) goto L9215; diff --git a/advent.h b/advent.h index 1c22e14..6f1c086 100644 --- a/advent.h +++ b/advent.h @@ -25,8 +25,15 @@ struct game_t { long closng; long conds; long detail; + long dflag; long dkill; long dtotal; + long foobar; + long holdng; + long iwest; + long knfloc; + long limit; + long lmwarn; long oldloc; long oldlc2; long wzdark; @@ -38,7 +45,7 @@ struct game_t { extern struct game_t game; -extern long ABB[], ATLOC[], BLKLIN, DFLAG, FIXED[], HOLDNG, +extern long ABB[], ATLOC[], FIXED[], LINK[], LNLENG, LNPOSN, PARMS[], PLACE[]; extern char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[], MAP2[]; @@ -105,11 +112,10 @@ extern void score(long); extern long AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CLAM, CLSHNT, COINS, DALTLC, DOOR, DPRSSN, DRAGON, DWARF, EGGS, - EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOBAR, FOOD, + EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, HINTED[], HINTLC[], - I, INVENT, IGO, IWEST, J, JADE, K, K2, KEYS, KK, - KNFLOC, KNIFE, KQ, L, LAMP, LIMIT, LL, - LMWARN, LOC, LOCK, LOOK, + I, INVENT, IGO, J, JADE, K, K2, KEYS, KK, + KNIFE, KQ, L, LAMP, LL, LOC, LOCK, LOOK, MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, OGRE, OIL, OLDOBJ, OYSTER, diff --git a/init.c b/init.c index 4af5ce9..4bb7cc2 100644 --- a/init.c +++ b/init.c @@ -318,7 +318,7 @@ L1106: /*etc*/ ; * prior loc of each dwarf, initially garbage. DALTLC is alternate initial loc * for dwarf, in case one of them starts out on top of the adventurer. (No 2 * of the 5 initial locs are adjacent.) game.dseen is true if dwarf has seen him. - * DFLAG controls the level of activation of all this: + * game.dflag controls the level of activation of all this: * 0 No dwarf stuff yet (wait until reaches Hall Of Mists) * 1 Reached Hall Of Mists, but hasn't met first dwarf * 2 Met first dwarf, others start moving, no knives thrown yet @@ -333,7 +333,7 @@ L1106: /*etc*/ ; for (I=1; I<=NDWARVES; I++) { game.dseen[I]=false; } /* end loop */ - DFLAG=0; + game.dflag=0; game.dloc[1]=19; game.dloc[2]=27; game.dloc[3]=33; @@ -350,12 +350,12 @@ L1106: /*etc*/ ; * game.conds Min value for cond(loc) if loc has any hints * game.detail How often we've said "not allowed to give more detail" * game.dkill # of dwarves killed (unused in scoring, needed for msg) - * FOOBAR Current progress in saying "FEE FIE FOE FOO". - * HOLDNG Number of objects being carried + * game.foobar Current progress in saying "FEE FIE FOE FOO". + * game.holdng Number of objects being carried * IGO How many times he's said "go XXX" instead of "XXX" - * IWEST How many times he's said "west" instead of "w" - * KNFLOC 0 if no knife here, loc if knife here, -1 after caveat - * LIMIT Lifetime of lamp (not set here) + * game.iwest How many times he's said "west" instead of "w" + * game.knfloc 0 if no knife here, loc if knife here, -1 after caveat + * game.limit Lifetime of lamp (not set here) * MAXDIE Number of reincarnation messages available (up to 5) * NUMDIE Number of times killed so far * THRESH Next #turns threshhold (-1 if none) @@ -369,19 +369,19 @@ L1106: /*etc*/ ; THRESH= -1; if(TRNVLS > 0)THRESH=MOD(TRNVAL[1],100000)+1; TRNLUZ=0; - LMWARN=false; + game.lmwarn=false; IGO=0; - IWEST=0; - KNFLOC=0; + game.iwest=0; + game.knfloc=0; game.detail=0; game.abbnum=5; for (I=0; I<=4; I++) { {long x = 2*I+81; if(RTEXT[x] != 0)MAXDIE=I+1;} } /* end loop */ NUMDIE=0; - HOLDNG=0; + game.holdng=0; game.dkill=0; - FOOBAR=0; + game.foobar=0; game.bonus=0; game.clock1=30; game.clock2=50; diff --git a/main.c b/main.c index b3310bb..3239fc3 100644 --- a/main.c +++ b/main.c @@ -14,8 +14,8 @@ struct game_t game; -long ABB[186], ATLOC[186], DFLAG, - FIXED[NOBJECTS+1], HOLDNG, +long ABB[186], ATLOC[186], + FIXED[NOBJECTS+1], LINK[NOBJECTS*2 + 1], LNLENG, LNPOSN, PARMS[26], PLACE[NOBJECTS+1], SETUP = 0; @@ -25,13 +25,11 @@ long AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CLAM, CLSHNT, COINS, DALTLC, DOOR, DPRSSN, DRAGON, DWARF, EGGS, - EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOBAR, FOOD, + EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, HINTED[21], HINTLC[21], - I, INVENT, IGO, IWEST, J, JADE, K, K2, KEYS, KK, - KNFLOC, KNIFE, KQ, L, LAMP, LIMIT, LL, - LMWARN, LOC, LOCK, LOOK, - MAGZIN, MAXDIE, MAXTRS, - MESSAG, MIRROR, MXSCOR, + I, INVENT, IGO, J, JADE, K, K2, KEYS, KK, + KNIFE, KQ, L, LAMP, LL, LOC, LOCK, LOOK, + MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, OGRE, OIL, OLDOBJ, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PROP[NOBJECTS+1], PYRAM, @@ -97,7 +95,7 @@ int main(int argc, char *argv[]) { * game.closed says whether we're all the way closed * game.closng says whether it's closing time yet * CLSHNT says whether he's read the clue in the endgame - * LMWARN says whether he's been warned about lamp going dim + * game.lmwarn says whether he's been warned about lamp going dim * NOVICE says whether he asked for instructions at start-up * PANIC says whether he's found out he's trapped in the cave * game.wzdark says whether the loc he's leaving was dark */ @@ -135,8 +133,8 @@ L1: SETUP= -1; NOVICE=YES(stdin, 65,1,0); NEWLOC=1; LOC=1; - LIMIT=330; - if(NOVICE)LIMIT=1000; + game.limit=330; + if(NOVICE)game.limit=1000; if (logfp) fprintf(logfp, "seed %ld\n", seedval); @@ -199,16 +197,16 @@ L74: LOC=NEWLOC; * end in maze, but c'est la vie. They'll wait for him outside the dead end. */ if(LOC == 0 || FORCED(LOC) || CNDBIT(NEWLOC,3)) goto L2000; - if(DFLAG != 0) goto L6000; - if(INDEEP(LOC))DFLAG=1; + if(game.dflag != 0) goto L6000; + if(INDEEP(LOC))game.dflag=1; goto L2000; /* When we encounter the first dwarf, we kill 0, 1, or 2 of the 5 dwarves. If * any of the survivors is at loc, replace him with the alternate. */ -L6000: if(DFLAG != 1) goto L6010; +L6000: if(game.dflag != 1) goto L6010; if(!INDEEP(LOC) || (PCT(95) && (!CNDBIT(LOC,4) || PCT(85)))) goto L2000; - DFLAG=2; + game.dflag=2; for (I=1; I<=2; I++) { J=1+randrange(NDWARVES-1); if(PCT(50))game.dloc[J]=0; @@ -300,8 +298,8 @@ L6025: RSPEAK(186); L6027: game.dtotal=game.dtotal+1; if(game.odloc[I] != game.dloc[I]) goto L6030; ATTACK=ATTACK+1; - if(KNFLOC >= 0)KNFLOC=LOC; - if(randrange(1000) < 95*(DFLAG-2))STICK=STICK+1; + if(game.knfloc >= 0)game.knfloc=LOC; + if(randrange(1000) < 95*(game.dflag-2))STICK=STICK+1; L6030: /*etc*/ ; } /* end loop */ @@ -313,7 +311,7 @@ L6030: /*etc*/ ; SETPRM(1,game.dtotal,0); RSPEAK(4+1/game.dtotal); if(ATTACK == 0) goto L2000; - if(DFLAG == 2)DFLAG=3; + if(game.dflag == 2)game.dflag=3; SETPRM(1,ATTACK,0); K=6; if(ATTACK > 1)K=250; @@ -413,15 +411,15 @@ L2603: if(!game.closed) goto L2605; if(TOTING(I) && PROP[I] < 0)PROP[I]= -1-PROP[I]; } /* end loop */ L2605: game.wzdark=DARK(0); - if(KNFLOC > 0 && KNFLOC != LOC)KNFLOC=0; + if(game.knfloc > 0 && game.knfloc != LOC)game.knfloc=0; I=0; if (!GETIN(cmdin, WD1,WD1X,WD2,WD2X)) return false; -/* Every input, check "FOOBAR" flag. If zero, nothing's going on. If pos, +/* Every input, check "game.foobar" flag. If zero, nothing's going on. If pos, * make neg. If neg, he skipped a word, so make it zero. */ -L2607: FOOBAR=(FOOBAR>0 ? -FOOBAR : 0); +L2607: game.foobar=(game.foobar>0 ? -game.foobar : 0); TURNS=TURNS+1; if(TURNS == THRESH) { SPEAK(TTEXT[TRNDEX]); @@ -437,11 +435,11 @@ L2607: FOOBAR=(FOOBAR>0 ? -FOOBAR : 0); if(game.clock1 == 0) goto L10000; if(game.clock1 < 0)game.clock2=game.clock2-1; if(game.clock2 == 0) goto L11000; - if(PROP[LAMP] == 1)LIMIT=LIMIT-1; - if(LIMIT <= 30 && HERE(BATTER) && PROP[BATTER] == 0 && HERE(LAMP)) goto + if(PROP[LAMP] == 1)game.limit=game.limit-1; + if(game.limit <= 30 && HERE(BATTER) && PROP[BATTER] == 0 && HERE(LAMP)) goto L12000; - if(LIMIT == 0) goto L12400; - if(LIMIT <= 30) goto L12200; + if(game.limit == 0) goto L12400; + if(game.limit <= 30) goto L12200; L19999: K=43; if(LIQLOC(LOC) == WATER)K=70; V1=VOCAB(WD1,-1); @@ -454,8 +452,8 @@ L19999: K=43; L2610: if(V1 == 1000+CAGE && V2 == 1000+BIRD && HERE(CAGE) && HERE(BIRD)) WD1=MAKEWD(301200308); L2620: if(WD1 == MAKEWD(23051920)) { - IWEST=IWEST+1; - if(IWEST == 10)RSPEAK(17); + game.iwest=game.iwest+1; + if(game.iwest == 10)RSPEAK(17); } if(WD1 != MAKEWD( 715) || WD2 == 0) goto L2630; IGO=IGO+1; @@ -578,7 +576,7 @@ L30000: NEWLOC=NEWLOC-300; * be used for actual motion, but can be spotted by "go back". */ L30100: NEWLOC=99+100-LOC; /* ESR: an instance of NOBJECTS? */ - if(HOLDNG == 0 || (HOLDNG == 1 && TOTING(EMRALD))) return true; + if(game.holdng == 0 || (game.holdng == 1 && TOTING(EMRALD))) return true; NEWLOC=LOC; RSPEAK(117); return true; @@ -759,7 +757,7 @@ L40010: HINTLC[HINT]=0; SETPRM(1,HINTS[HINT][2],HINTS[HINT][2]); RSPEAK(261); HINTED[HINT]=YES(cmdin,175,HINTS[HINT][4],54); - if(HINTED[HINT] && LIMIT > 30)LIMIT=LIMIT+30*HINTS[HINT][2]; + if(HINTED[HINT] && game.limit > 30)game.limit=game.limit+30*HINTS[HINT][2]; L40020: HINTLC[HINT]=0; L40030: goto L2602; @@ -774,7 +772,7 @@ L40200: if(PLACE[BIRD] == LOC && TOTING(ROD) && OLDOBJ == BIRD) goto L40010; L40300: if(HERE(SNAKE) && !HERE(BIRD)) goto L40010; goto L40020; -L40400: if(ATLOC[LOC] == 0 && ATLOC[game.oldloc] == 0 && ATLOC[game.oldlc2] == 0 && HOLDNG > +L40400: if(ATLOC[LOC] == 0 && ATLOC[game.oldloc] == 0 && ATLOC[game.oldlc2] == 0 && game.holdng > 1) goto L40010; goto L40020; @@ -783,7 +781,7 @@ L40500: if(PROP[EMRALD] != -1 && PROP[PYRAM] == -1) goto L40010; L40600: goto L40010; -L40700: if(DFLAG == 0) goto L40010; +L40700: if(game.dflag == 0) goto L40010; goto L40020; L40800: if(ATLOC[LOC] == 0 && ATLOC[game.oldloc] == 0 && ATLOC[game.oldlc2] == 0) goto @@ -910,19 +908,19 @@ L11000: PROP[BOTTLE]=PUT(BOTTLE,115,1); L12000: RSPEAK(188); PROP[BATTER]=1; if(TOTING(BATTER))DROP(BATTER,LOC); - LIMIT=LIMIT+2500; - LMWARN=false; + game.limit=game.limit+2500; + game.lmwarn=false; goto L19999; -L12200: if(LMWARN || !HERE(LAMP)) goto L19999; - LMWARN=true; +L12200: if(game.lmwarn || !HERE(LAMP)) goto L19999; + game.lmwarn=true; SPK=187; if(PLACE[BATTER] == 0)SPK=183; if(PROP[BATTER] == 1)SPK=189; RSPEAK(SPK); goto L19999; -L12400: LIMIT= -1; +L12400: game.limit= -1; PROP[LAMP]=0; if(HERE(LAMP))RSPEAK(184); goto L19999; diff --git a/misc.c b/misc.c index 784ae53..f211eac 100644 --- a/misc.c +++ b/misc.c @@ -549,12 +549,12 @@ long TEMP; /* Start toting an object, removing it from the list of things at its former * location. Incr holdng unless it was already being toted. If OBJECT>NOBJECTS - * (moving "fixed" second loc), don't change PLACE or HOLDNG. */ + * (moving "fixed" second loc), don't change PLACE or game.holdng. */ if(OBJECT > NOBJECTS) goto L5; if(PLACE[OBJECT] == -1)return; PLACE[OBJECT]= -1; - HOLDNG=HOLDNG+1; + game.holdng=game.holdng+1; L5: if(ATLOC[WHERE] != OBJECT) goto L6; ATLOC[WHERE]=LINK[OBJECT]; return; @@ -568,10 +568,10 @@ L8: LINK[TEMP]=LINK[OBJECT]; void DROP(long OBJECT, long WHERE) { /* Place an object at a given loc, prefixing it onto the ATLOC list. Decr - * HOLDNG if the object was being toted. */ + * game.holdng if the object was being toted. */ if(OBJECT > NOBJECTS) goto L1; - if(PLACE[OBJECT] == -1)HOLDNG=HOLDNG-1; + if(PLACE[OBJECT] == -1)game.holdng=game.holdng-1; PLACE[OBJECT]=WHERE; goto L2; L1: {long x = OBJECT-NOBJECTS; FIXED[x]=WHERE;} @@ -592,7 +592,7 @@ long AT, I; AT=0; - if(DFLAG < 2)return(AT); + if(game.dflag < 2)return(AT); AT= -1; for (I=1; I<=NDWARVES-1; I++) { if(game.dloc[I] == WHERE) goto L2; diff --git a/score.c b/score.c index d4cd697..bee722d 100644 --- a/score.c +++ b/score.c @@ -46,7 +46,7 @@ L20010: /*etc*/ ; } /* end loop */ /* Now look at how he finished and how far he got. MAXDIE and NUMDIE tell us - * how well he survived. DFLAG will + * how well he survived. game.dflag will * tell us if he ever got suitably deep into the cave. game.closng still indicates * whether he reached the endgame. And if he got as far as "cave closed" * (indicated by "game.closed"), then bonus is zero for mundane exits or 133, 134, @@ -56,7 +56,7 @@ L20010: /*etc*/ ; MXSCOR=MXSCOR+MAXDIE*10; if(MODE == 0)SCORE=SCORE+4; MXSCOR=MXSCOR+4; - if(DFLAG != 0)SCORE=SCORE+25; + if(game.dflag != 0)SCORE=SCORE+25; MXSCOR=MXSCOR+25; if(game.closng)SCORE=SCORE+25; MXSCOR=MXSCOR+25;