From ab04fe4d413a36a91d26551f942f4881f54179be Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 6 Jun 2017 21:46:17 -0400 Subject: [PATCH] More more globals into the game state block. --- actions1.c | 14 +++++++------- advent.h | 9 ++++++--- main.c | 50 +++++++++++++++++++++++++------------------------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/actions1.c b/actions1.c index 6a751d7..d9fa2e5 100644 --- a/actions1.c +++ b/actions1.c @@ -536,9 +536,9 @@ L8305: DATIME(&I,&K); SAVWDS(ABBNUM,BLKLIN,BONUS,CLOCK1,CLOCK2,CLOSED,CLOSNG); SAVWDS(DETAIL,DFLAG,DKILL,DTOTAL,FOOBAR,HOLDNG,IWEST); SAVWDS(KNFLOC,LIMIT,LL,LMWARN,LOC,NEWLOC,NUMDIE); - SAVWDS(OBJ,OLDLC2,OLDLOC,OLDOBJ,PANIC,SAVED,SETUP); + SAVWDS(OBJ,game.oldlc2,game.oldloc,OLDOBJ,PANIC,SAVED,SETUP); SAVWDS(SPK,TALLY,THRESH,TRNDEX,TRNLUZ,TURNS,OBJTXT[OYSTER]); - SAVWDS(VERB,WD1,WD1X,WD2,WZDARK,ZZWORD,OBJSND[BIRD]); + SAVWDS(VERB,WD1,WD1X,WD2,WZDARK,game.zzword,OBJSND[BIRD]); SAVWDS(OBJTXT[SIGN],CLSHNT,NOVICE,K,K,K,K); SAVARR(ABB,LOCSIZ); SAVARR(ATLOC,LOCSIZ); @@ -554,7 +554,7 @@ L8305: DATIME(&I,&K); SAVWRD(KK,K); if(K != 0) goto L8318; K=NUL; - ZZWORD=RNDVOC(3,ZZWORD); + game.zzword=RNDVOC(3,game.zzword); if(KK > 0) return(8); RSPEAK(266); exit(0); @@ -585,8 +585,8 @@ L8320: if(PROP[RUG] != 2)SPK=224; L9320: if(OBJ != RUG) return(2011); SPK=223; if(PROP[RUG] != 2) return(2011); - OLDLC2=OLDLOC; - OLDLOC=LOC; + game.oldlc2=game.oldloc; + game.oldloc=LOC; NEWLOC=PLACE[RUG]+FIXED[RUG]-LOC; SPK=226; if(PROP[SAPPH] >= 0)SPK=227; @@ -601,7 +601,7 @@ L8330: SPK=228; RSPEAK(labs(K)); if(K < 0) return(2012); SPK=0; -L8332: SETPRM(1,ZZWORD,0); +L8332: SETPRM(1,game.zzword,0); /* 8335 */ for (I=1; I<=NOBJECTS; I++) { if(!HERE(I) || OBJSND[I] == 0 || PROP[I] < 0) goto L8335; PSPEAK(I,OBJSND[I]+PROP[I]); @@ -617,7 +617,7 @@ L8340: if(!AT(RESER) && LOC != FIXED[RESER]-1) return(2011); PSPEAK(RESER,PROP[RESER]+1); PROP[RESER]=1-PROP[RESER]; if(AT(RESER)) return(2012); - OLDLC2=LOC; + game.oldlc2=LOC; NEWLOC=0; RSPEAK(241); return(2); diff --git a/advent.h b/advent.h index 3dff47b..3e5dc9a 100644 --- a/advent.h +++ b/advent.h @@ -14,6 +14,9 @@ typedef long token_t; /* word token - someday this will be a character array */ typedef long vocab_t; /* index into a vocabulary array */ struct game_t { + long oldloc; + long oldlc2; + long zzword; long dseen[NDWARVES+1]; long dloc[NDWARVES+1]; long odloc[NDWARVES+1]; @@ -90,7 +93,7 @@ extern long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CHLOC, CHLOC2, CLAM, CLOCK1, CLOCK2, CLOSED, CLOSNG, CLSHNT, COINS, CONDS, DALTLC, DETAIL, - DKILL, DOOR, DPRSSN, DRAGON, DTOTAL, DWARF, EGGS, + DKILL, DOOR, DPRSSN, DRAGON, DTOTAL, DWARF, EGGS, EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOBAR, FOOD, GRATE, HINT, HINTED[], HINTLC[], I, INVENT, IGO, IWEST, J, JADE, K, K2, KEYS, KK, @@ -98,7 +101,7 @@ extern long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, LMWARN, LOC, LOCK, LOOK, MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, - OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, + OGRE, OIL, OLDOBJ, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PROP[], PYRAM, RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAVED, SAY, SCORE, SECT, SETUP, SIGN, SNAKE, SPK, STEPS, STICK, @@ -106,5 +109,5 @@ extern long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, TRNDEX, TRNLUZ, TROLL, TROLL2, TURNS, URN, V1, V2, VASE, VEND, VERB, VOLCAN, VRSION, WATER, WD1, WD1X, WD2, WD2X, - WZDARK, ZZWORD; + WZDARK; diff --git a/main.c b/main.c index 75982c6..c5b4523 100644 --- a/main.c +++ b/main.c @@ -34,15 +34,15 @@ long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BONUS, MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, - OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, + OGRE, OIL, 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, STREAM, TALLY, THRESH, THROW, TK[21], TRIDNT, TRNDEX, TRNLUZ, TROLL, TROLL2, - TURNS, URN, V1, V2, VASE, VEND, VERB, + TURNS, URN, V1, V2, VASE, VEND, VERB, VOLCAN, VRSION = 25, WATER, WD1, WD1X, WD2, WD2X, - WZDARK = false, ZZWORD; + WZDARK = false; FILE *logfp; bool oldstyle = false; lcg_state lcgstate; @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) { L1: SETUP= -1; I=0; - ZZWORD=RNDVOC(3,0); + game.zzword=RNDVOC(3,0); NOVICE=YES(stdin, 65,1,0); NEWLOC=1; LOC=1; @@ -160,7 +160,7 @@ static bool fallback_handler(char *buf) // autogenerated, so don't charge user time for it. --TURNS; // here we reconfigure any global game state that uses random numbers - ZZWORD=RNDVOC(3,0); + game.zzword=RNDVOC(3,0); return true; } return false; @@ -323,7 +323,7 @@ L6030: /*etc*/ ; SETPRM(1,STICK,0); RSPEAK(K+1+2/(1+STICK)); if(STICK == 0) goto L2000; - OLDLC2=LOC; + game.oldlc2=LOC; goto L99; @@ -521,9 +521,9 @@ L8000: SETPRM(1,WD1,WD1X); * * Given the current location in "LOC", and a motion verb number in "K", put * the new location in "NEWLOC". The current loc is saved in "OLgame.dloc" in case - * he wants to retreat. The current OLgame.dloc is saved in OLDLC2, in case he + * he wants to retreat. The current OLgame.dloc is saved in game.oldlc2, in case he * dies. (if he does, NEWLOC will be limbo, and OLgame.dloc will be what killed - * him, so we need OLDLC2, which is the last place he was safe.) */ + * him, so we need game.oldlc2, which is the last place he was safe.) */ L8: KK=KEY[LOC]; NEWLOC=LOC; @@ -532,8 +532,8 @@ L8: KK=KEY[LOC]; if(K == BACK) goto L20; if(K == LOOK) goto L30; if(K == CAVE) goto L40; - OLDLC2=OLDLOC; - OLDLOC=LOC; + game.oldlc2=game.oldloc; + game.oldloc=LOC; L9: LL=labs(TRAVEL[KK]); if(MOD(LL,1000) == 1 || MOD(LL,1000) == K) goto L10; @@ -616,18 +616,18 @@ L30310: NEWLOC=PLAC[TROLL]+FIXD[TROLL]-LOC; DROP(BEAR,NEWLOC); FIXED[BEAR]= -1; PROP[BEAR]=3; - OLDLC2=NEWLOC; + game.oldlc2=NEWLOC; goto L99; /* End of specials. */ -/* Handle "go back". Look for verb which goes from LOC to OLDLOC, or to OLDLC2 - * If OLDLOC has forced-motion. K2 saves entry -> forced loc -> previous loc. */ +/* Handle "go back". Look for verb which goes from LOC to game.oldloc, or to game.oldlc2 + * If game.oldloc has forced-motion. K2 saves entry -> forced loc -> previous loc. */ -L20: K=OLDLOC; - if(FORCED(K))K=OLDLC2; - OLDLC2=OLDLOC; - OLDLOC=LOC; +L20: K=game.oldloc; + if(FORCED(K))K=game.oldlc2; + game.oldlc2=game.oldloc; + game.oldloc=LOC; K2=0; if(K == LOC)K2=91; if(CNDBIT(LOC,4))K2=274; @@ -693,7 +693,7 @@ L50: SPK=12; * snide messages available. Each death results in a message (81, 83, etc.) * which offers reincarnation; if accepted, this results in message 82, 84, * etc. The last time, if he wants another chance, he gets a snide remark as - * we exit. When reincarnated, all objects being carried get dropped at OLDLC2 + * we exit. When reincarnated, all objects being carried get dropped at game.oldlc2 * (presumably the last place prior to being killed) without change of props. * the loop runs backwards to assure that the bird is dropped before the cage. * (this kluge could be changed once we're sure all references to bird and cage @@ -701,12 +701,12 @@ L50: SPK=12; * it in the cave). It is turned off and left outside the building (only if he * was carrying it, of course). He himself is left inside the building (and * heaven help him if he tries to xyzzy back into the cave without the lamp!). - * OLDLOC is zapped so he can't just "retreat". */ + * game.oldloc is zapped so he can't just "retreat". */ /* The easiest way to get killed is to fall into a pit in pitch darkness. */ L90: RSPEAK(23); - OLDLC2=LOC; + game.oldlc2=LOC; /* Okay, he's dead. Let's get on with it. */ @@ -720,13 +720,13 @@ L99: if(CLOSNG) goto L95; /* 98 */ for (J=1; J<=NOBJECTS; J++) { I=NOBJECTS + 1 - J; if(!TOTING(I)) goto L98; - K=OLDLC2; + K=game.oldlc2; if(I == LAMP)K=1; DROP(I,K); L98: /*etc*/ ; } /* end loop */ LOC=3; - OLDLOC=LOC; + game.oldloc=LOC; goto L2000; /* He died during closing time. No resurrection. Tally up a death and exit. */ @@ -774,7 +774,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[OLDLOC] == 0 && ATLOC[OLDLC2] == 0 && HOLDNG > +L40400: if(ATLOC[LOC] == 0 && ATLOC[game.oldloc] == 0 && ATLOC[game.oldlc2] == 0 && HOLDNG > 1) goto L40010; goto L40020; @@ -786,7 +786,7 @@ L40600: goto L40010; L40700: if(DFLAG == 0) goto L40010; goto L40020; -L40800: if(ATLOC[LOC] == 0 && ATLOC[OLDLOC] == 0 && ATLOC[OLDLC2] == 0) goto +L40800: if(ATLOC[LOC] == 0 && ATLOC[game.oldloc] == 0 && ATLOC[game.oldlc2] == 0) goto L40010; goto L40030; @@ -875,7 +875,7 @@ L11000: PROP[BOTTLE]=PUT(BOTTLE,115,1); PROP[ROD]=PUT(ROD,115,0); PROP[DWARF]=PUT(DWARF,115,0); LOC=115; - OLDLOC=115; + game.oldloc=115; NEWLOC=115; /* Leave the grate with normal (non-negative) property. Reuse sign. */ -- 2.31.1