X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=init.c;h=eed89a41f4a1c0150c8fa59b1f19af223c943df4;hb=c3add5c2066face7535108706bb86dc41971ad9f;hp=1e4ec5e837a39dbf3ae174465084bcca7e0c0cd8;hpb=5286f6b3bd5213d0da417580a892aafb0e0e2fcb;p=open-adventure.git diff --git a/init.c b/init.c index 1e4ec5e..eed89a4 100644 --- a/init.c +++ b/init.c @@ -1,9 +1,12 @@ +#include +#include +#include +#include + #include "misc.h" #include "main.h" #include "share.h" #include "funcs.h" -#include -#include /* * Initialisation @@ -16,7 +19,7 @@ * 185 locations (LTEXT, STEXT, KEY, COND, ABB, ATLOC, LOCSND, LOCSIZ). * 100 objects (PLAC, PLACE, FIXD, FIXED, LINK (TWICE), PTEXT, PROP, * OBJSND, OBJTXT). - * 35 "action" verbs (ACTSPK, VRBSIZ). + * 35 "action" verbs (ACTVERB, VRBSIZ). * 277 random messages (RTEXT, RTXSIZ). * 12 different player classifications (CTEXT, CVAL, CLSMAX). * 20 hints (HINTLC, HINTED, HINTS, HNTSIZ). @@ -32,7 +35,7 @@ /* Description of the database format * * - * The data file contains several sections. each begins with a line containing + * The data file contains several sections. Each begins with a line containing * a number identifying the section, and ends with a line containing "-1". * * Section 1: Long form descriptions. Each line contains a location number, @@ -147,7 +150,7 @@ /* The various messages (sections 1, 2, 5, 6, etc.) may include certain * special character sequences to denote that the program must provide - * parameters to insert into a message when the message is printed. these + * parameters to insert into a message when the message is printed. These * sequences are: * %S = The letter 'S' or nothing (if a given value is exactly 1) * %W = A word (up to 10 characters) @@ -170,7 +173,8 @@ static int finish_init(void); static void quick_io(void); void initialise(void) { - printf("Initialising...\n"); + if (oldstyle) + printf("Initialising...\n"); if(!quick_init()){raw_init(); report(); quick_save();} finish_init(); } @@ -178,6 +182,9 @@ void initialise(void) { static int raw_init(void) { printf("Couldn't find adventure.data, using adventure.text...\n"); + FILE *OPENED=fopen("adventure.text","r" /* NOT binary */); + if(!OPENED){printf("Can't read adventure.text!\n"); exit(0);} + /* Clear out the various text-pointer arrays. All text is stored in array * lines; each line is preceded by a word pointing to the next pointer (i.e. * the word following the end of the line). The pointer is negative if this is @@ -208,10 +215,10 @@ L1001: /*etc*/ ; CLSSES=0; TRNVLS=0; -/* Start new data section. sect is the section number. */ +/* Start new data section. Sect is the section number. */ -L1002: SECT=GETNUM(1); - OLDLOC= -1; +L1002: SECT=GETNUM(OPENED); + game.oldloc= -1; switch (SECT) { case 0: return(0); case 1: goto L1004; case 2: goto L1004; case 3: goto L1030; case 4: goto L1040; case 5: goto L1004; case 6: goto L1004; case 7: goto L1050; case 8: goto L1060; case @@ -225,7 +232,7 @@ L1002: SECT=GETNUM(1); L1004: KK=LINUSE; L1005: LINUSE=KK; - LOC=GETNUM(1); + LOC=GETNUM(OPENED); if(LNLENG >= LNPOSN+70)BUG(0); if(LOC == -1) goto L1002; if(LNLENG < LNPOSN)BUG(1); @@ -234,8 +241,8 @@ L1006: KK=KK+1; LINES[KK]=GETTXT(false,false,false,KK); if(LINES[KK] != -1) goto L1006; LINES[LINUSE]=KK; - if(LOC == OLDLOC) goto L1005; - OLDLOC=LOC; + if(LOC == game.oldloc) goto L1005; + game.oldloc=LOC; LINES[LINUSE]= -KK; if(SECT == 14) goto L1014; if(SECT == 10) goto L1012; @@ -270,21 +277,21 @@ L1014: TRNVLS=TRNVLS+1; goto L1005; /* The stuff for section 3 is encoded here. Each "from-location" gets a - * contiguous section of the "TRAVEL" array. each entry in travel is - * NEWLOC*1000 + KEYWORD (from section 4, motion verbs), and is negated if + * contiguous section of the "TRAVEL" array. Each entry in travel is + * game.newloc*1000 + KEYWORD (from section 4, motion verbs), and is negated if * this is the last entry for this location. KEY(N) is the index in travel * of the first option at location N. */ -L1030: LOC=GETNUM(1); +L1030: LOC=GETNUM(OPENED); if(LOC == -1) goto L1002; - NEWLOC=GETNUM(0); + game.newloc=GETNUM(NULL); if(KEY[LOC] != 0) goto L1033; KEY[LOC]=TRVS; goto L1035; L1033: TRVS--; TRAVEL[TRVS]= -TRAVEL[TRVS]; TRVS++; -L1035: L=GETNUM(0); +L1035: L=GETNUM(NULL); if(L == 0) goto L1039; - TRAVEL[TRVS]=NEWLOC*1000+L; + TRAVEL[TRVS]=game.newloc*1000+L; TRVS=TRVS+1; if(TRVS == TRVSIZ)BUG(3); goto L1035; @@ -299,11 +306,11 @@ L1039: TRVS--; TRAVEL[TRVS]= -TRAVEL[TRVS]; TRVS++; * would make it harder to detect particular input words.) */ L1040: J=10000; - /* 1042 */ for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) { -L1043: KTAB[TABNDX]=GETNUM(1); + for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) { + KTAB[TABNDX]=GETNUM(OPENED); if(KTAB[TABNDX] == -1) goto L1002; J=J+7; -L1042: ATAB[TABNDX]=GETTXT(true,true,true,0)+J*J; + ATAB[TABNDX]=GETTXT(true,true,true,0)+J*J; } /* end loop */ BUG(4); @@ -311,24 +318,24 @@ L1042: ATAB[TABNDX]=GETTXT(true,true,true,0)+J*J; * plac contains initial locations of objects. FIXD is -1 for immovable * objects (including the snake), or = second loc for two-placed objects. */ -L1050: OBJ=GETNUM(1); +L1050: OBJ=GETNUM(OPENED); if(OBJ == -1) goto L1002; - PLAC[OBJ]=GETNUM(0); - FIXD[OBJ]=GETNUM(0); + PLAC[OBJ]=GETNUM(NULL); + FIXD[OBJ]=GETNUM(NULL); goto L1050; -/* Read default message numbers for action verbs, store in ACTSPK. */ +/* Read default message numbers for action verbs, store in ACTVERB. */ -L1060: VERB=GETNUM(1); +L1060: VERB=GETNUM(OPENED); if(VERB == -1) goto L1002; - ACTSPK[VERB]=GETNUM(0); + ACTVERB[VERB]=GETNUM(NULL); goto L1060; /* Read info about available liquids and other conditions, store in COND. */ -L1070: K=GETNUM(1); +L1070: K=GETNUM(OPENED); if(K == -1) goto L1002; -L1071: LOC=GETNUM(0); +L1071: LOC=GETNUM(NULL); if(LOC == 0) goto L1070; if(CNDBIT(LOC,K)) BUG(8); COND[LOC]=COND[LOC]+SETBIT(K); @@ -337,21 +344,21 @@ L1071: LOC=GETNUM(0); /* Read data for hints. */ L1080: HNTMAX=0; -L1081: K=GETNUM(1); +L1081: K=GETNUM(OPENED); if(K == -1) goto L1002; if(K <= 0 || K > HNTSIZ)BUG(7); - /* 1083 */ for (I=1; I<=4; I++) { -L1083: HINTS[K][I] =GETNUM(0); + for (I=1; I<=4; I++) { + HINTS[K][I] =GETNUM(NULL); } /* end loop */ HNTMAX=(HNTMAX>K ? HNTMAX : K); goto L1081; /* Read the sound/text info, store in OBJSND, OBJTXT, LOCSND. */ -L1090: K=GETNUM(1); +L1090: K=GETNUM(OPENED); if(K == -1) goto L1002; - KK=GETNUM(0); - I=GETNUM(0); + KK=GETNUM(NULL); + I=GETNUM(NULL); if(I == 0) goto L1092; OBJSND[K]=(KK>0 ? KK : 0); OBJTXT[K]=(I>0 ? I : 0); @@ -372,11 +379,11 @@ L1092: LOCSND[K]=KK; * description is printed. Counts modulo 5 unless "LOOK" is used. */ static int finish_init(void) { - /* 1101 */ for (I=1; I<=100; I++) { + for (I=1; I<=100; I++) { PLACE[I]=0; PROP[I]=0; LINK[I]=0; -L1101: {long x = I+100; LINK[x]=0;} + {long x = I+100; LINK[x]=0;} } /* end loop */ /* 1102 */ for (I=1; I<=LOCSIZ; I++) { @@ -402,33 +409,33 @@ L1102: ATLOC[I]=0; L1106: /*etc*/ ; } /* end loop */ - /* 1107 */ for (I=1; I<=100; I++) { + for (I=1; I<=100; I++) { K=101-I; FIXED[K]=FIXD[K]; -L1107: if(PLAC[K] != 0 && FIXD[K] <= 0)DROP(K,PLAC[K]); + if(PLAC[K] != 0 && FIXD[K] <= 0)DROP(K,PLAC[K]); } /* end loop */ /* Treasures, as noted earlier, are objects 50 through MAXTRS (CURRENTLY 79). * Their props are initially -1, and are set to 0 the first time they are - * described. 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. */ MAXTRS=79; - TALLY=0; - /* 1200 */ for (I=50; I<=MAXTRS; I++) { + game.tally=0; + for (I=50; I<=MAXTRS; I++) { if(PTEXT[I] != 0)PROP[I]= -1; -L1200: TALLY=TALLY-PROP[I]; + game.tally=game.tally-PROP[I]; } /* end loop */ /* Clear the hint stuff. HINTLC(I) is how long he's been at LOC with cond bit * I. HINTED(I) is true iff hint I has been used. */ - /* 1300 */ for (I=1; I<=HNTMAX; I++) { + for (I=1; I<=HNTMAX; I++) { HINTED[I]=false; -L1300: HINTLC[I]=0; + HINTLC[I]=0; } /* end loop */ -/* Define some handy mnemonics. these correspond to object numbers. */ +/* Define some handy mnemonics. These correspond to object numbers. */ AXE=VOCWRD(12405,1); BATTER=VOCWRD(201202005,1); @@ -512,7 +519,7 @@ L1300: HINTLC[I]=0; * 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.) 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 @@ -524,10 +531,10 @@ L1300: HINTLC[I]=0; CHLOC=114; CHLOC2=140; - /* 1700 */ for (I=1; I<=6; I++) { -L1700: DSEEN[I]=false; + for (I=1; I<=6; I++) { + DSEEN[I]=false; } /* end loop */ - DFLAG=0; + game.dflag=0; DLOC[1]=19; DLOC[2]=27; DLOC[3]=33; @@ -537,56 +544,56 @@ L1700: DSEEN[I]=false; DALTLC=18; /* Other random flags and counters, as follows: - * ABBNUM How often we should print non-abbreviated descriptions - * BONUS Used to determine amount of bonus if he reaches closing - * CLOCK1 Number of turns from finding last treasure till closing - * CLOCK2 Number of turns from first warning till blinding flash + * game.abbnum How often we should print non-abbreviated descriptions + * game.bonus Used to determine amount of bonus if he reaches closing + * game.clock1 Number of turns from finding last treasure till closing + * game.clock2 Number of turns from first warning till blinding flash * CONDS Min value for cond(loc) if loc has any hints - * DETAIL How often we've said "not allowed to give more detail" - * DKILL Number 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.detail How often we've said "not allowed to give more detail" + * game.dkill Number of dwarves killed (unused in scoring, needed for msg) + * 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) - * TRNDEX Index in TRNVAL of next threshhold (section 14 of database) - * TRNLUZ # points lost so far due to number of turns used - * TURNS Tallies how many commands he's given (ignores yes/no) + * game.numdie Number of times killed so far + * game.thresh Next #turns threshhold (-1 if none) + * game.trndex Index in TRNVAL of next threshhold (section 14 of database) + * game.trnluz # points lost so far due to number of turns used + * game.turns Tallies how many commands he's given (ignores yes/no) * Logicals were explained earlier */ - TURNS=0; - TRNDEX=1; - THRESH= -1; - if(TRNVLS > 0)THRESH=MOD(TRNVAL[1],100000)+1; - TRNLUZ=0; - LMWARN=false; + game.turns=0; + game.trndex=1; + game.thresh= -1; + if(TRNVLS > 0)game.thresh=MOD(TRNVAL[1],100000)+1; + game.trnluz=0; + game.lmwarn=false; IGO=0; - IWEST=0; - KNFLOC=0; - DETAIL=0; - ABBNUM=5; - /* 1800 */ for (I=0; I<=4; I++) { -L1800: {long x = 2*I+81; if(RTEXT[x] != 0)MAXDIE=I+1;} + 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; - DKILL=0; - FOOBAR=0; - BONUS=0; - CLOCK1=30; - CLOCK2=50; + game.numdie=0; + game.holdng=0; + game.dkill=0; + game.foobar=0; + game.bonus=0; + game.clock1=30; + game.clock2=50; CONDS=SETBIT(11); - SAVED=0; - CLOSNG=false; - PANIC=false; - CLOSED=false; + game.saved=0; + game.closng=false; + game.panic=false; + game.closed=false; CLSHNT=false; - NOVICE=false; - SETUP=1; + game.novice=false; + game.setup=1; /* if we can ever think of how, we should save it at this point */ @@ -596,25 +603,25 @@ L1800: {long x = 2*I+81; if(RTEXT[x] != 0)MAXDIE=I+1;} /* Report on amount of arrays actually used, to permit reductions. */ static void report(void) { - /* 1998 */ for (K=1; K<=LOCSIZ; K++) { + for (K=1; K<=LOCSIZ; K++) { KK=LOCSIZ+1-K; if(LTEXT[KK] != 0) goto L1997; -L1998: /*etc*/ ; + /*etc*/ ; } /* end loop */ OBJ=0; -L1997: /* 1996 */ for (K=1; K<=100; K++) { -L1996: if(PTEXT[K] != 0)OBJ=OBJ+1; +L1997: for (K=1; K<=100; K++) { + if(PTEXT[K] != 0)OBJ=OBJ+1; } /* end loop */ - /* 1995 */ for (K=1; K<=TABNDX; K++) { -L1995: if(KTAB[K]/1000 == 2)VERB=KTAB[K]-2000; + for (K=1; K<=TABNDX; K++) { + if(KTAB[K]/1000 == 2)VERB=KTAB[K]-2000; } /* end loop */ - /* 1994 */ for (K=1; K<=RTXSIZ; K++) { + for (K=1; K<=RTXSIZ; K++) { J=RTXSIZ+1-K; if(RTEXT[J] != 0) goto L1993; -L1994: /*etc*/ ; + /*etc*/ ; } /* end loop */ L1993: SETPRM(1,LINUSE,LINSIZ); @@ -690,12 +697,12 @@ static void quick_io(void) { quick_array(ATAB,TABSIZ); quick_array(PLAC,100); quick_array(FIXD,100); - quick_array(ACTSPK,VRBSIZ); + quick_array(ACTVERB,VRBSIZ); quick_array((long *)HINTS,(HNTMAX+1)*5-1); } static void quick_item(W)long *W; { - if(init_reading && fread(W,sizeof(long),1,f) != 1)return; + if(init_reading && fread(W,sizeof(long),1,f) != 1)return; init_cksum = MOD(init_cksum*13+(*W),60000000); if(!init_reading)fwrite(W,sizeof(long),1,f); }