OpenCores
URL https://opencores.org/ocsvn/ion/ion/trunk

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [adventure/] [init.c] - Blame information for rev 229

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 90 ja_rd
#include "misc.h"
2
#include "main.h"
3
#include "share.h"
4
#include "funcs.h"
5
#include <stdio.h>
6
 
7
#include "adv_baremetal.h"
8
 
9
#define TRUE  (0==0)
10
#define FALSE (0!=0)
11
 
12
/*
13
 * INITIALISATION
14
 */
15
 
16
/*  CURRENT LIMITS:
17
 *     12500 WORDS OF MESSAGE TEXT (LINES, LINSIZ).
18
 *      885 TRAVEL OPTIONS (TRAVEL, TRVSIZ).
19
 *      330 VOCABULARY WORDS (KTAB, ATAB, TABSIZ).
20
 *      185 LOCATIONS (LTEXT, STEXT, KEY, COND, ABB, ATLOC, LOCSND, LOCSIZ).
21
 *      100 OBJECTS (PLAC, PLACE, FIXD, FIXED, LINK (TWICE), PTEXT, PROP,
22
 *                    OBJSND, OBJTXT).
23
 *       35 "ACTION" VERBS (ACTSPK, VRBSIZ).
24
 *      277 RANDOM MESSAGES (RTEXT, RTXSIZ).
25
 *       12 DIFFERENT PLAYER CLASSIFICATIONS (CTEXT, CVAL, CLSMAX).
26
 *       20 HINTS (HINTLC, HINTED, HINTS, HNTSIZ).
27
 *         5 "# OF TURNS" THRESHHOLDS (TTEXT, TRNVAL, TRNSIZ).
28
 *  THERE ARE ALSO LIMITS WHICH CANNOT BE EXCEEDED DUE TO THE STRUCTURE OF
29
 *  THE DATABASE.  (E.G., THE VOCABULARY USES N/1000 TO DETERMINE WORD TYPE,
30
 *  SO THERE CAN'T BE MORE THAN 1000 WORDS.)  THESE UPPER LIMITS ARE:
31
 *      1000 NON-SYNONYMOUS VOCABULARY WORDS
32
 *      300 LOCATIONS
33
 *      100 OBJECTS */
34
 
35
 
36
/*  DESCRIPTION OF THE DATABASE FORMAT
37
 *
38
 *
39
 *  THE DATA FILE CONTAINS SEVERAL SECTIONS.  EACH BEGINS WITH A LINE CONTAINING
40
 *  A NUMBER IDENTIFYING THE SECTION, AND ENDS WITH A LINE CONTAINING "-1".
41
 *
42
 *  SECTION 1: LONG FORM DESCRIPTIONS.  EACH LINE CONTAINS A LOCATION NUMBER,
43
 *      A TAB, AND A LINE OF TEXT.  THE SET OF (NECESSARILY ADJACENT) LINES
44
 *      WHOSE NUMBERS ARE X FORM THE LONG DESCRIPTION OF LOCATION X.
45
 *  SECTION 2: SHORT FORM DESCRIPTIONS.  SAME FORMAT AS LONG FORM.  NOT ALL
46
 *      PLACES HAVE SHORT DESCRIPTIONS.
47
 *  SECTION 3: TRAVEL TABLE.  EACH LINE CONTAINS A LOCATION NUMBER (X), A SECOND
48
 *      LOCATION NUMBER (Y), AND A LIST OF MOTION NUMBERS (SEE SECTION 4).
49
 *      EACH MOTION REPRESENTS A VERB WHICH WILL GO TO Y IF CURRENTLY AT X.
50
 *      Y, IN TURN, IS INTERPRETED AS FOLLOWS.  LET M=Y/1000, N=Y MOD 1000.
51
 *              IF N<=300       IT IS THE LOCATION TO GO TO.
52
 *              IF 300<N<=500   N-300 IS USED IN A COMPUTED GOTO TO
53
 *                                      A SECTION OF SPECIAL CODE.
54
 *              IF N>500        MESSAGE N-500 FROM SECTION 6 IS PRINTED,
55
 *                                      AND HE STAYS WHEREVER HE IS.
56
 *      MEANWHILE, M SPECIFIES THE CONDITIONS ON THE MOTION.
57
 *              IF M=0          IT'S UNCONDITIONAL.
58
 *              IF 0<M<100      IT IS DONE WITH M% PROBABILITY.
59
 *              IF M=100        UNCONDITIONAL, BUT FORBIDDEN TO DWARVES.
60
 *              IF 100<M<=200   HE MUST BE CARRYING OBJECT M-100.
61
 *              IF 200<M<=300   MUST BE CARRYING OR IN SAME ROOM AS M-200.
62
 *              IF 300<M<=400   PROP(M MOD 100) MUST *NOT* BE 0.
63
 *              IF 400<M<=500   PROP(M MOD 100) MUST *NOT* BE 1.
64
 *              IF 500<M<=600   PROP(M MOD 100) MUST *NOT* BE 2, ETC.
65
 *      IF THE CONDITION (IF ANY) IS NOT MET, THEN THE NEXT *DIFFERENT*
66
 *      "DESTINATION" VALUE IS USED (UNLESS IT FAILS TO MEET *ITS* CONDITIONS,
67
 *      IN WHICH CASE THE NEXT IS FOUND, ETC.).  TYPICALLY, THE NEXT DEST WILL
68
 *      BE FOR ONE OF THE SAME VERBS, SO THAT ITS ONLY USE IS AS THE ALTERNATE
69
 *      DESTINATION FOR THOSE VERBS.  FOR INSTANCE:
70
 *              15      110022  29      31      34      35      23      43
71
 *              15      14      29
72
 *      THIS SAYS THAT, FROM LOC 15, ANY OF THE VERBS 29, 31, ETC., WILL TAKE
73
 *      HIM TO 22 IF HE'S CARRYING OBJECT 10, AND OTHERWISE WILL GO TO 14.
74
 *              11      303008  49
75
 *              11      9       50
76
 *      THIS SAYS THAT, FROM 11, 49 TAKES HIM TO 8 UNLESS PROP(3)=0, IN WHICH
77
 *      CASE HE GOES TO 9.  VERB 50 TAKES HIM TO 9 REGARDLESS OF PROP(3).
78
 *  SECTION 4: VOCABULARY.  EACH LINE CONTAINS A NUMBER (N), A TAB, AND A
79
 *      FIVE-LETTER WORD.  CALL M=N/1000.  IF M=0, THEN THE WORD IS A MOTION
80
 *      VERB FOR USE IN TRAVELLING (SEE SECTION 3).  ELSE, IF M=1, THE WORD IS
81
 *      AN OBJECT.  ELSE, IF M=2, THE WORD IS AN ACTION VERB (SUCH AS "CARRY"
82
 *      OR "ATTACK").  ELSE, IF M=3, THE WORD IS A SPECIAL CASE VERB (SUCH AS
83
 *      "DIG") AND N MOD 1000 IS AN INDEX INTO SECTION 6.  OBJECTS FROM 50 TO
84
 *      (CURRENTLY, ANYWAY) 79 ARE CONSIDERED TREASURES (FOR PIRATE, CLOSEOUT).
85
 *  SECTION 5: OBJECT DESCRIPTIONS.  EACH LINE CONTAINS A NUMBER (N), A TAB,
86
 *      AND A MESSAGE.  IF N IS FROM 1 TO 100, THE MESSAGE IS THE "INVENTORY"
87
 *      MESSAGE FOR OBJECT N.  OTHERWISE, N SHOULD BE 000, 100, 200, ETC., AND
88
 *      THE MESSAGE SHOULD BE THE DESCRIPTION OF THE PRECEDING OBJECT WHEN ITS
89
 *      PROP VALUE IS N/100.  THE N/100 IS USED ONLY TO DISTINGUISH MULTIPLE
90
 *      MESSAGES FROM MULTI-LINE MESSAGES; THE PROP INFO ACTUALLY REQUIRES ALL
91
 *      MESSAGES FOR AN OBJECT TO BE PRESENT AND CONSECUTIVE.  PROPERTIES WHICH
92
 *      PRODUCE NO MESSAGE SHOULD BE GIVEN THE MESSAGE ">$<".
93
 *  SECTION 6: ARBITRARY MESSAGES.  SAME FORMAT AS SECTIONS 1, 2, AND 5, EXCEPT
94
 *      THE NUMBERS BEAR NO RELATION TO ANYTHING (EXCEPT FOR SPECIAL VERBS
95
 *      IN SECTION 4).
96
 *  SECTION 7: OBJECT LOCATIONS.  EACH LINE CONTAINS AN OBJECT NUMBER AND ITS
97
 *      INITIAL LOCATION (ZERO (OR OMITTED) IF NONE).  IF THE OBJECT IS
98
 *      IMMOVABLE, THE LOCATION IS FOLLOWED BY A "-1".  IF IT HAS TWO LOCATIONS
99
 *      (E.G. THE GRATE) THE FIRST LOCATION IS FOLLOWED WITH THE SECOND, AND
100
 *      THE OBJECT IS ASSUMED TO BE IMMOVABLE.
101
 *  SECTION 8: ACTION DEFAULTS.  EACH LINE CONTAINS AN "ACTION-VERB" NUMBER AND
102
 *      THE INDEX (IN SECTION 6) OF THE DEFAULT MESSAGE FOR THE VERB.
103
 *  SECTION 9: LOCATION ATTRIBUTES.  EACH LINE CONTAINS A NUMBER (N) AND UP TO
104
 *      20 LOCATION NUMBERS.  BIT N (WHERE 0 IS THE UNITS BIT) IS SET IN
105
 *      COND(LOC) FOR EACH LOC GIVEN.  THE COND BITS CURRENTLY ASSIGNED ARE:
106
 *              0        LIGHT
107
 *              1       IF BIT 2 IS ON: ON FOR OIL, OFF FOR WATER
108
 *              2       LIQUID ASSET, SEE BIT 1
109
 *              3       PIRATE DOESN'T GO HERE UNLESS FOLLOWING PLAYER
110
 *              4       CANNOT USE "BACK" TO MOVE AWAY
111
 *      BITS PAST 10 INDICATE AREAS OF INTEREST TO "HINT" ROUTINES:
112
 *              11      TRYING TO GET INTO CAVE
113
 *              12      TRYING TO CATCH BIRD
114
 *              13      TRYING TO DEAL WITH SNAKE
115
 *              14      LOST IN MAZE
116
 *              15      PONDERING DARK ROOM
117
 *              16      AT WITT'S END
118
 *              17      CLIFF WITH URN
119
 *              18      LOST IN FOREST
120
 *              19      TRYING TO DEAL WITH OGRE
121
 *              20      FOUND ALL TREASURES EXCEPT JADE
122
 *      COND(LOC) IS SET TO 2, OVERRIDING ALL OTHER BITS, IF LOC HAS FORCED
123
 *      MOTION.
124
 *  SECTION 10: CLASS MESSAGES.  EACH LINE CONTAINS A NUMBER (N), A TAB, AND A
125
 *      MESSAGE DESCRIBING A CLASSIFICATION OF PLAYER.  THE SCORING SECTION
126
 *      SELECTS THE APPROPRIATE MESSAGE, WHERE EACH MESSAGE IS CONSIDERED TO
127
 *      APPLY TO PLAYERS WHOSE SCORES ARE HIGHER THAN THE PREVIOUS N BUT NOT
128
 *      HIGHER THAN THIS N.  NOTE THAT THESE SCORES PROBABLY CHANGE WITH EVERY
129
 *      MODIFICATION (AND PARTICULARLY EXPANSION) OF THE PROGRAM.
130
 *  SECTION 11: HINTS.  EACH LINE CONTAINS A HINT NUMBER (ADD 10 TO GET COND
131
 *      BIT; SEE SECTION 9), THE NUMBER OF TURNS HE MUST BE AT THE RIGHT LOC(S)
132
 *      BEFORE TRIGGERING THE HINT, THE POINTS DEDUCTED FOR TAKING THE HINT,
133
 *      THE MESSAGE NUMBER (SECTION 6) OF THE QUESTION, AND THE MESSAGE NUMBER
134
 *      OF THE HINT.  THESE VALUES ARE STASHED IN THE "HINTS" ARRAY.  HNTMAX IS
135
 *      SET TO THE MAX HINT NUMBER (<= HNTSIZ).
136
 *  SECTION 12: UNUSED IN THIS VERSION.
137
 *  SECTION 13: SOUNDS AND TEXT.  EACH LINE CONTAINS EITHER 2 OR 3 NUMBERS.  IF
138
 *      2 (CALL THEM N AND S), N IS A LOCATION AND MESSAGE ABS(S) FROM SECTION
139
 *      6 IS THE SOUND HEARD THERE.  IF S<0, THE SOUND THERE DROWNS OUT ALL
140
 *      OTHER NOISES.  IF 3 NUMBERS (CALL THEM N, S, AND T), N IS AN OBJECT
141
 *      NUMBER AND S+PROP(N) IS THE PROPERTY MESSAGE (FROM SECTION 5) IF HE
142
 *      LISTENS TO THE OBJECT, AND T+PROP(N) IS THE TEXT IF HE READS IT.  IF
143
 *      S OR T IS -1, THE OBJECT HAS NO SOUND OR TEXT, RESPECTIVELY.  NEITHER
144
 *      S NOR T IS ALLOWED TO BE 0.
145
 *  SECTION 14: TURN THRESHHOLDS.  EACH LINE CONTAINS A NUMBER (N), A TAB, AND
146
 *      A MESSAGE BERATING THE PLAYER FOR TAKING SO MANY TURNS.  THE MESSAGES
147
 *      MUST BE IN THE PROPER (ASCENDING) ORDER.  THE MESSAGE GETS PRINTED IF
148
 *      THE PLAYER EXCEEDS N MOD 100000 TURNS, AT WHICH TIME N/100000 POINTS
149
 *      GET DEDUCTED FROM HIS SCORE.
150
 *  SECTION 0: END OF DATABASE. */
151
 
152
/*  THE VARIOUS MESSAGES (SECTIONS 1, 2, 5, 6, ETC.) MAY INCLUDE CERTAIN
153
 *  SPECIAL CHARACTER SEQUENCES TO DENOTE THAT THE PROGRAM MUST PROVIDE
154
 *  PARAMETERS TO INSERT INTO A MESSAGE WHEN THE MESSAGE IS PRINTED.  THESE
155
 *  SEQUENCES ARE:
156
 *      %S = THE LETTER 'S' OR NOTHING (IF A GIVEN VALUE IS EXACTLY 1)
157
 *      %W = A WORD (UP TO 10 CHARACTERS)
158
 *      %L = A WORD MAPPED TO LOWER-CASE LETTERS
159
 *      %U = A WORD MAPPED TO UPPER-CASE LETTERS
160
 *      %C = A WORD MAPPED TO LOWER-CASE, FIRST LETTER CAPITALISED
161
 *      %T = SEVERAL WORDS OF TEXT, ENDING WITH A WORD OF -1
162
 *      %1 = A 1-DIGIT NUMBER
163
 *      %2 = A 2-DIGIT NUMBER
164
 *      ...
165
 *      %9 = A 9-DIGIT NUMBER
166
 *      %B = VARIABLE NUMBER OF BLANKS
167
 *      %! = THE ENTIRE MESSAGE SHOULD BE SUPPRESSED */
168
 
169
initialise() {
170
        puts("Initialising...\n");
171
        /* quick init disabled in embedded version */
172
        /* if(!quick_init()){ */
173
            raw_init(); report(); prompt_use_walkthrough();
174
            /*quick_save();*/
175
        /*}*/
176
        finish_init();
177
}
178
 
179
raw_init() {
180
        puts("Couldn't find adventure.data, using adventure.text...\n");
181
 
182
/*  CLEAR OUT THE VARIOUS TEXT-POINTER ARRAYS.  ALL TEXT IS STORED IN ARRAY
183
 *  LINES; EACH LINE IS PRECEDED BY A WORD POINTING TO THE NEXT POINTER (I.E.
184
 *  THE WORD FOLLOWING THE END OF THE LINE).  THE POINTER IS NEGATIVE IF THIS IS
185
 *  FIRST LINE OF A MESSAGE.  THE TEXT-POINTER ARRAYS CONTAIN INDICES OF
186
 *  POINTER-WORDS IN LINES.  STEXT(N) IS SHORT DESCRIPTION OF LOCATION N.
187
 *  LTEXT(N) IS LONG DESCRIPTION.  PTEXT(N) POINTS TO MESSAGE FOR PROP(N)=0.
188
 *  SUCCESSIVE PROP MESSAGES ARE FOUND BY CHASING POINTERS.  RTEXT CONTAINS
189
 *  SECTION 6'S STUFF.  CTEXT(N) POINTS TO A PLAYER-CLASS MESSAGE.  TTEXT IS FOR
190
 *  SECTION 14.  WE ALSO CLEAR COND (SEE DESCRIPTION OF SECTION 9 FOR DETAILS). */
191
 
192
        /* 1001 */ for (I=1; I<=300; I++) {
193
        if(I <= 100)PTEXT[I]=0;
194
        if(I <= RTXSIZ)RTEXT[I]=0;
195
        if(I <= CLSMAX)CTEXT[I]=0;
196
        if(I <= 100)OBJSND[I]=0;
197
        if(I <= 100)OBJTXT[I]=0;
198
        if(I > LOCSIZ) goto L1001;
199
        STEXT[I]=0;
200
        LTEXT[I]=0;
201
        COND[I]=0;
202
        KEY[I]=0;
203
        LOCSND[I]=0;
204
L1001:  /*etc*/ ;
205
        } /* end loop */
206
 
207
        LINUSE=1;
208
        TRVS=1;
209
        CLSSES=0;
210
        TRNVLS=0;
211
 
212
/*  START NEW DATA SECTION.  SECT IS THE SECTION NUMBER. */
213
 
214
L1002:  SECT=GETNUM(1);
215
 
216
        OLDLOC= -1;
217
        switch (SECT) { case 0: return(0); case 1: goto L1004; case 2: goto
218
                L1004; case 3: goto L1030; case 4: goto L1040; case 5: goto L1004;
219
                case 6: goto L1004; case 7: goto L1050; case 8: goto L1060; case
220
                9: goto L1070; case 10: goto L1004; case 11: goto L1080; case 12:
221
                break; case 13: goto L1090; case 14: goto L1004; }
222
/*            (0)  (1)  (2)  (3)  (4)  (5)  (6)  (7)  (8)  (9)
223
 *           (10) (11) (12) (13) (14) */
224
        BUG(9);
225
 
226
/*  SECTIONS 1, 2, 5, 6, 10, 14.  READ MESSAGES AND SET UP POINTERS. */
227
 
228
L1004:  KK=LINUSE;
229
L1005:  LINUSE=KK;
230
        LOC=GETNUM(1);
231
        if(LNLENG >= LNPOSN+70)BUG(0);
232
        if(LOC == -1) goto L1002;
233
        if(LNLENG < LNPOSN)BUG(1);
234
L1006:  KK=KK+1;
235
        if(KK >= LINSIZ)BUG(2);
236
        LINES[KK]=GETTXT(FALSE,FALSE,FALSE,KK);
237
        if(LINES[KK] != -1) goto L1006;
238
        LINES[LINUSE]=KK;
239
        if(LOC == OLDLOC) goto L1005;
240
        OLDLOC=LOC;
241
        LINES[LINUSE]= -KK;
242
        if(SECT == 14) goto L1014;
243
        if(SECT == 10) goto L1012;
244
        if(SECT == 6) goto L1011;
245
        if(SECT == 5) goto L1010;
246
        if(LOC > LOCSIZ)BUG(10);
247
        if(SECT == 1) goto L1008;
248
 
249
        STEXT[LOC]=LINUSE;
250
         goto L1005;
251
 
252
L1008:  LTEXT[LOC]=LINUSE;
253
         goto L1005;
254
 
255
L1010:  if(LOC > 0 && LOC <= 100)PTEXT[LOC]=LINUSE;
256
         goto L1005;
257
 
258
L1011:  if(LOC > RTXSIZ)BUG(6);
259
        RTEXT[LOC]=LINUSE;
260
         goto L1005;
261
 
262
L1012:  CLSSES=CLSSES+1;
263
        if(CLSSES > CLSMAX)BUG(11);
264
        CTEXT[CLSSES]=LINUSE;
265
        CVAL[CLSSES]=LOC;
266
         goto L1005;
267
 
268
L1014:  TRNVLS=TRNVLS+1;
269
        if(TRNVLS > TRNSIZ)BUG(11);
270
        TTEXT[TRNVLS]=LINUSE;
271
        TRNVAL[TRNVLS]=LOC;
272
         goto L1005;
273
 
274
/*  THE STUFF FOR SECTION 3 IS ENCODED HERE.  EACH "FROM-LOCATION" GETS A
275
 *  CONTIGUOUS SECTION OF THE "TRAVEL" ARRAY.  EACH ENTRY IN TRAVEL IS
276
 *  NEWLOC*1000 + KEYWORD (FROM SECTION 4, MOTION VERBS), AND IS NEGATED IF
277
 *  THIS IS THE LAST ENTRY FOR THIS LOCATION.  KEY(N) IS THE INDEX IN TRAVEL
278
 *  OF THE FIRST OPTION AT LOCATION N. */
279
 
280
L1030:  LOC=GETNUM(1);
281
        if(LOC == -1) goto L1002;
282
        NEWLOC=GETNUM(0);
283
        if(KEY[LOC] != 0) goto L1033;
284
        KEY[LOC]=TRVS;
285
         goto L1035;
286
L1033:  TRVS--; TRAVEL[TRVS]= -TRAVEL[TRVS]; TRVS++;
287
L1035:  L=GETNUM(0);
288
        if(L == 0) goto L1039;
289
        TRAVEL[TRVS]=NEWLOC*1000+L;
290
        TRVS=TRVS+1;
291
        if(TRVS == TRVSIZ)BUG(3);
292
         goto L1035;
293
L1039:  TRVS--; TRAVEL[TRVS]= -TRAVEL[TRVS]; TRVS++;
294
         goto L1030;
295
 
296
/*  HERE WE READ IN THE VOCABULARY.  KTAB(N) IS THE WORD NUMBER, ATAB(N) IS
297
 *  THE CORRESPONDING WORD.  THE -1 AT THE END OF SECTION 4 IS LEFT IN KTAB
298
 *  AS AN END-MARKER.  THE WORDS ARE GIVEN A MINIMAL HASH TO MAKE DECIPHERING
299
 *  THE CORE-IMAGE HARDER.  (WE DON'T USE GETTXT'S HASH SINCE THAT WOULD FORCE
300
 *  US TO HASH EACH INPUT LINE TO MAKE COMPARISONS WORK, AND THAT IN TURN
301
 *  WOULD MAKE IT HARDER TO DETECT PARTICULAR INPUT WORDS.) */
302
 
303
L1040:  J=10000;
304
        /* 1042 */ for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) {
305
L1043:  KTAB[TABNDX]=GETNUM(1);
306
        if(KTAB[TABNDX] == -1) goto L1002;
307
        J=J+7;
308
L1042:  ATAB[TABNDX]=GETTXT(TRUE,TRUE,TRUE,0)+J*J;
309
        } /* end loop */
310
        BUG(4);
311
 
312
/*  READ IN THE INITIAL LOCATIONS FOR EACH OBJECT.  ALSO THE IMMOVABILITY INFO.
313
 *  PLAC CONTAINS INITIAL LOCATIONS OF OBJECTS.  FIXD IS -1 FOR IMMOVABLE
314
 *  OBJECTS (INCLUDING THE SNAKE), OR = SECOND LOC FOR TWO-PLACED OBJECTS. */
315
 
316
L1050:  OBJ=GETNUM(1);
317
        if(OBJ == -1) goto L1002;
318
        PLAC[OBJ]=GETNUM(0);
319
        FIXD[OBJ]=GETNUM(0);
320
         goto L1050;
321
 
322
/*  READ DEFAULT MESSAGE NUMBERS FOR ACTION VERBS, STORE IN ACTSPK. */
323
 
324
L1060:  VERB=GETNUM(1);
325
        if(VERB == -1) goto L1002;
326
        ACTSPK[VERB]=GETNUM(0);
327
         goto L1060;
328
 
329
/*  READ INFO ABOUT AVAILABLE LIQUIDS AND OTHER CONDITIONS, STORE IN COND. */
330
 
331
L1070:  K=GETNUM(1);
332
        if(K == -1) goto L1002;
333
L1071:  LOC=GETNUM(0);
334
        if(LOC == 0) goto L1070;
335
        if(CNDBIT(LOC,K)) BUG(8);
336
        COND[LOC]=COND[LOC]+SETBIT(K);
337
         goto L1071;
338
 
339
/*  READ DATA FOR HINTS. */
340
 
341
L1080:  HNTMAX=0;
342
L1081:  K=GETNUM(1);
343
        if(K == -1) goto L1002;
344
        if(K <= 0 || K > HNTSIZ)BUG(7);
345
        /* 1083 */ for (I=1; I<=4; I++) {
346
L1083:  HINTS[K][I] =GETNUM(0);
347
        } /* end loop */
348
        HNTMAX=(HNTMAX>K ? HNTMAX : K);
349
         goto L1081;
350
 
351
/*  READ THE SOUND/TEXT INFO, STORE IN OBJSND, OBJTXT, LOCSND. */
352
 
353
L1090:  K=GETNUM(1);
354
        if(K == -1) goto L1002;
355
        KK=GETNUM(0);
356
        I=GETNUM(0);
357
        if(I == 0) goto L1092;
358
        OBJSND[K]=(KK>0 ? KK : 0);
359
        OBJTXT[K]=(I>0 ? I : 0);
360
         goto L1090;
361
 
362
L1092:  LOCSND[K]=KK;
363
         goto L1090;
364
}
365
 
366
/*  FINISH CONSTRUCTING INTERNAL DATA FORMAT */
367
 
368
/*  HAVING READ IN THE DATABASE, CERTAIN THINGS ARE NOW CONSTRUCTED.  PROPS ARE
369
 *  SET TO ZERO.  WE FINISH SETTING UP COND BY CHECKING FOR FORCED-MOTION TRAVEL
370
 *  ENTRIES.  THE PLAC AND FIXD ARRAYS ARE USED TO SET UP ATLOC(N) AS THE FIRST
371
 *  OBJECT AT LOCATION N, AND LINK(OBJ) AS THE NEXT OBJECT AT THE SAME LOCATION
372
 *  AS OBJ.  (OBJ>100 INDICATES THAT FIXED(OBJ-100)=LOC; LINK(OBJ) IS STILL THE
373
 *  CORRECT LINK TO USE.)  ABB IS ZEROED; IT CONTROLS WHETHER THE ABBREVIATED
374
 *  DESCRIPTION IS PRINTED.  COUNTS MOD 5 UNLESS "LOOK" IS USED. */
375
 
376
finish_init() {
377
        /* 1101 */ for (I=1; I<=100; I++) {
378
        PLACE[I]=0;
379
        PROP[I]=0;
380
        LINK[I]=0;
381
L1101:  {long x = I+100; LINK[x]=0;}
382
        } /* end loop */
383
 
384
        /* 1102 */ for (I=1; I<=LOCSIZ; I++) {
385
        ABB[I]=0;
386
        if(LTEXT[I] == 0 || KEY[I] == 0) goto L1102;
387
        K=KEY[I];
388
        if(MOD(IABS(TRAVEL[K]),1000) == 1)COND[I]=2;
389
L1102:  ATLOC[I]=0;
390
        } /* end loop */
391
 
392
/*  SET UP THE ATLOC AND LINK ARRAYS AS DESCRIBED ABOVE.  WE'LL USE THE DROP
393
 *  SUBROUTINE, WHICH PREFACES NEW OBJECTS ON THE LISTS.  SINCE WE WANT THINGS
394
 *  IN THE OTHER ORDER, WE'LL RUN THE LOOP BACKWARDS.  IF THE OBJECT IS IN TWO
395
 *  LOCS, WE DROP IT TWICE.  THIS ALSO SETS UP "PLACE" AND "FIXED" AS COPIES OF
396
 *  "PLAC" AND "FIXD".  ALSO, SINCE TWO-PLACED OBJECTS ARE TYPICALLY BEST
397
 *  DESCRIBED LAST, WE'LL DROP THEM FIRST. */
398
 
399
        /* 1106 */ for (I=1; I<=100; I++) {
400
        K=101-I;
401
        if(FIXD[K] <= 0) goto L1106;
402
        DROP(K+100,FIXD[K]);
403
        DROP(K,PLAC[K]);
404
L1106:  /*etc*/ ;
405
        } /* end loop */
406
 
407
        /* 1107 */ for (I=1; I<=100; I++) {
408
        K=101-I;
409
        FIXED[K]=FIXD[K];
410
L1107:  if(PLAC[K] != 0 && FIXD[K] <= 0)DROP(K,PLAC[K]);
411
        } /* end loop */
412
 
413
/*  TREASURES, AS NOTED EARLIER, ARE OBJECTS 50 THROUGH MAXTRS (CURRENTLY 79).
414
 *  THEIR PROPS ARE INITIALLY -1, AND ARE SET TO 0 THE FIRST TIME THEY ARE
415
 *  DESCRIBED.  TALLY KEEPS TRACK OF HOW MANY ARE NOT YET FOUND, SO WE KNOW
416
 *  WHEN TO CLOSE THE CAVE. */
417
 
418
        MAXTRS=79;
419
        TALLY=0;
420
        /* 1200 */ for (I=50; I<=MAXTRS; I++) {
421
        if(PTEXT[I] != 0)PROP[I]= -1;
422
L1200:  TALLY=TALLY-PROP[I];
423
        } /* end loop */
424
 
425
/*  CLEAR THE HINT STUFF.  HINTLC(I) IS HOW LONG HE'S BEEN AT LOC WITH COND BIT
426
 *  I.  HINTED(I) IS TRUE IFF HINT I HAS BEEN USED. */
427
 
428
        /* 1300 */ for (I=1; I<=HNTMAX; I++) {
429
        HINTED[I]=FALSE;
430
L1300:  HINTLC[I]=0;
431
        } /* end loop */
432
 
433
/*  DEFINE SOME HANDY MNEMONICS.  THESE CORRESPOND TO OBJECT NUMBERS. */
434
 
435
        AXE=VOCWRD(12405,1);
436
        BATTER=VOCWRD(201202005,1);
437
        BEAR=VOCWRD(2050118,1);
438
        BIRD=VOCWRD(2091804,1);
439
        BLOOD=VOCWRD(212151504,1);
440
        BOTTLE=VOCWRD(215202012,1);
441
        CAGE=VOCWRD(3010705,1);
442
        CAVITY=VOCWRD(301220920,1);
443
        CHASM=VOCWRD(308011913,1);
444
        CLAM=VOCWRD(3120113,1);
445
        DOOR=VOCWRD(4151518,1);
446
        DRAGON=VOCWRD(418010715,1);
447
        DWARF=VOCWRD(423011806,1);
448
        FISSUR=VOCWRD(609191921,1);
449
        FOOD=VOCWRD(6151504,1);
450
        GRATE=VOCWRD(718012005,1);
451
        KEYS=VOCWRD(11052519,1);
452
        KNIFE=VOCWRD(1114090605,1);
453
        LAMP=VOCWRD(12011316,1);
454
        MAGZIN=VOCWRD(1301070126,1);
455
        MESSAG=VOCWRD(1305191901,1);
456
        MIRROR=VOCWRD(1309181815,1);
457
        OGRE=VOCWRD(15071805,1);
458
        OIL=VOCWRD(150912,1);
459
        OYSTER=VOCWRD(1525192005,1);
460
        PILLOW=VOCWRD(1609121215,1);
461
        PLANT=VOCWRD(1612011420,1);
462
        PLANT2=PLANT+1;
463
        RESER=VOCWRD(1805190518,1);
464
        ROD=VOCWRD(181504,1);
465
        ROD2=ROD+1;
466
        SIGN=VOCWRD(19090714,1);
467
        SNAKE=VOCWRD(1914011105,1);
468
        STEPS=VOCWRD(1920051619,1);
469
        TROLL=VOCWRD(2018151212,1);
470
        TROLL2=TROLL+1;
471
        URN=VOCWRD(211814,1);
472
        VEND=VOCWRD(1755140409,1);
473
        VOLCAN=VOCWRD(1765120301,1);
474
        WATER=VOCWRD(1851200518,1);
475
 
476
/*  OBJECTS FROM 50 THROUGH WHATEVER ARE TREASURES.  HERE ARE A FEW. */
477
 
478
        AMBER=VOCWRD(113020518,1);
479
        CHAIN=VOCWRD(308010914,1);
480
        CHEST=VOCWRD(308051920,1);
481
        COINS=VOCWRD(315091419,1);
482
        EGGS=VOCWRD(5070719,1);
483
        EMRALD=VOCWRD(513051801,1);
484
        JADE=VOCWRD(10010405,1);
485
        NUGGET=VOCWRD(7151204,1);
486
        PEARL=VOCWRD(1605011812,1);
487
        PYRAM=VOCWRD(1625180113,1);
488
        RUBY=VOCWRD(18210225,1);
489
        RUG=VOCWRD(182107,1);
490
        SAPPH=VOCWRD(1901161608,1);
491
        TRIDNT=VOCWRD(2018090405,1);
492
        VASE=VOCWRD(22011905,1);
493
 
494
/*  THESE ARE MOTION-VERB NUMBERS. */
495
 
496
        BACK=VOCWRD(2010311,0);
497
        CAVE=VOCWRD(3012205,0);
498
        DPRSSN=VOCWRD(405161805,0);
499
        ENTER=VOCWRD(514200518,0);
500
        ENTRNC=VOCWRD(514201801,0);
501
        LOOK=VOCWRD(12151511,0);
502
        NUL=VOCWRD(14211212,0);
503
        STREAM=VOCWRD(1920180501,0);
504
 
505
/*  AND SOME ACTION VERBS. */
506
 
507
        FIND=VOCWRD(6091404,2);
508
        INVENT=VOCWRD(914220514,2);
509
        LOCK=VOCWRD(12150311,2);
510
        SAY=VOCWRD(190125,2);
511
        THROW=VOCWRD(2008181523,2);
512
 
513
/*  INITIALISE THE DWARVES.  DLOC IS LOC OF DWARVES, HARD-WIRED IN.  ODLOC IS
514
 *  PRIOR LOC OF EACH DWARF, INITIALLY GARBAGE.  DALTLC IS ALTERNATE INITIAL LOC
515
 *  FOR DWARF, IN CASE ONE OF THEM STARTS OUT ON TOP OF THE ADVENTURER.  (NO 2
516
 *  OF THE 5 INITIAL LOCS ARE ADJACENT.)  DSEEN IS TRUE IF DWARF HAS SEEN HIM.
517
 *  DFLAG CONTROLS THE LEVEL OF ACTIVATION OF ALL THIS:
518
 *      0        NO DWARF STUFF YET (WAIT UNTIL REACHES HALL OF MISTS)
519
 *      1       REACHED HALL OF MISTS, BUT HASN'T MET FIRST DWARF
520
 *      2       MET FIRST DWARF, OTHERS START MOVING, NO KNIVES THROWN YET
521
 *      3       A KNIFE HAS BEEN THROWN (FIRST SET ALWAYS MISSES)
522
 *      3+      DWARVES ARE MAD (INCREASES THEIR ACCURACY)
523
 *  SIXTH DWARF IS SPECIAL (THE PIRATE).  HE ALWAYS STARTS AT HIS CHEST'S
524
 *  EVENTUAL LOCATION INSIDE THE MAZE.  THIS LOC IS SAVED IN CHLOC FOR REF.
525
 *  THE DEAD END IN THE OTHER MAZE HAS ITS LOC STORED IN CHLOC2. */
526
 
527
        CHLOC=114;
528
        CHLOC2=140;
529
        /* 1700 */ for (I=1; I<=6; I++) {
530
L1700:  DSEEN[I]=FALSE;
531
        } /* end loop */
532
        DFLAG=0;
533
        DLOC[1]=19;
534
        DLOC[2]=27;
535
        DLOC[3]=33;
536
        DLOC[4]=44;
537
        DLOC[5]=64;
538
        DLOC[6]=CHLOC;
539
        DALTLC=18;
540
 
541
/*  OTHER RANDOM FLAGS AND COUNTERS, AS FOLLOWS:
542
 *      ABBNUM  HOW OFTEN WE SHOULD PRINT NON-ABBREVIATED DESCRIPTIONS
543
 *      BONUS   USED TO DETERMINE AMOUNT OF BONUS IF HE REACHES CLOSING
544
 *      CLOCK1  NUMBER OF TURNS FROM FINDING LAST TREASURE TILL CLOSING
545
 *      CLOCK2  NUMBER OF TURNS FROM FIRST WARNING TILL BLINDING FLASH
546
 *      CONDS   MIN VALUE FOR COND(LOC) IF LOC HAS ANY HINTS
547
 *      DETAIL  HOW OFTEN WE'VE SAID "NOT ALLOWED TO GIVE MORE DETAIL"
548
 *      DKILL   NUMBER OF DWARVES KILLED (UNUSED IN SCORING, NEEDED FOR MSG)
549
 *      FOOBAR  CURRENT PROGRESS IN SAYING "FEE FIE FOE FOO".
550
 *      HOLDNG  NUMBER OF OBJECTS BEING CARRIED
551
 *      IGO     HOW MANY TIMES HE'S SAID "GO XXX" INSTEAD OF "XXX"
552
 *      IWEST   HOW MANY TIMES HE'S SAID "WEST" INSTEAD OF "W"
553
 *      KNFLOC  0 IF NO KNIFE HERE, LOC IF KNIFE HERE, -1 AFTER CAVEAT
554
 *      LIMIT   LIFETIME OF LAMP (NOT SET HERE)
555
 *      MAXDIE  NUMBER OF REINCARNATION MESSAGES AVAILABLE (UP TO 5)
556
 *      NUMDIE  NUMBER OF TIMES KILLED SO FAR
557
 *      THRESH  NEXT #TURNS THRESHHOLD (-1 IF NONE)
558
 *      TRNDEX  INDEX IN TRNVAL OF NEXT THRESHHOLD (SECTION 14 OF DATABASE)
559
 *      TRNLUZ  # POINTS LOST SO FAR DUE TO NUMBER OF TURNS USED
560
 *      TURNS   TALLIES HOW MANY COMMANDS HE'S GIVEN (IGNORES YES/NO)
561
 *      LOGICALS WERE EXPLAINED EARLIER */
562
 
563
        TURNS=0;
564
        TRNDEX=1;
565
        THRESH= -1;
566
        if(TRNVLS > 0)THRESH=MOD(TRNVAL[1],100000)+1;
567
        TRNLUZ=0;
568
        LMWARN=FALSE;
569
        IGO=0;
570
        IWEST=0;
571
        KNFLOC=0;
572
        DETAIL=0;
573
        ABBNUM=5;
574
        /* 1800 */ for (I=0; I<=4; I++) {
575
L1800:  {long x = 2*I+81; if(RTEXT[x] != 0)MAXDIE=I+1;}
576
        } /* end loop */
577
        NUMDIE=0;
578
        HOLDNG=0;
579
        DKILL=0;
580
        FOOBAR=0;
581
        BONUS=0;
582
        CLOCK1=30;
583
        CLOCK2=50;
584
        CONDS=SETBIT(11);
585
        SAVED=0;
586
        CLOSNG=FALSE;
587
        PANIC=FALSE;
588
        CLOSED=FALSE;
589
        CLSHNT=FALSE;
590
        NOVICE=FALSE;
591
        SETUP=1;
592
 
593
        /* if we can ever think of how, we should save it at this point */
594
 
595
        return(0); /* then we won't actually return from initialisation */
596
}
597
 
598
/*  REPORT ON AMOUNT OF ARRAYS ACTUALLY USED, TO PERMIT REDUCTIONS. */
599
 
600
report() {
601
        /* 1998 */ for (K=1; K<=LOCSIZ; K++) {
602
        KK=LOCSIZ+1-K;
603
        if(LTEXT[KK] != 0) goto L1997;
604
L1998:  /*etc*/ ;
605
        } /* end loop */
606
 
607
        OBJ=0;
608
L1997:  /* 1996 */ for (K=1; K<=100; K++) {
609
L1996:  if(PTEXT[K] != 0)OBJ=OBJ+1;
610
        } /* end loop */
611
 
612
        /* 1995 */ for (K=1; K<=TABNDX; K++) {
613
L1995:  if((KTAB[K]/1000) == 2){ VERB=KTAB[K]-2000; } // po_num(KTAB[K]); puts(" --> "); po_num(KTAB[K]/1000); puts("\n");
614
        } /* end loop */
615
 
616
        /* 1994 */ for (K=1; K<=RTXSIZ; K++) {
617
        J=RTXSIZ+1-K;
618
        if(RTEXT[J] != 0) goto L1993;
619
L1994:  /*etc*/ ;
620
        } /* end loop */
621
 
622
L1993:  SETPRM(1,LINUSE,LINSIZ);
623
        SETPRM(3,TRVS,TRVSIZ);
624
        SETPRM(5,TABNDX,TABSIZ);
625
        SETPRM(7,KK,LOCSIZ);
626
        SETPRM(9,OBJ,100);
627
        SETPRM(11,VERB,VRBSIZ);
628
        SETPRM(13,J,RTXSIZ);
629
        SETPRM(15,CLSSES,CLSMAX);
630
        SETPRM(17,HNTMAX,HNTSIZ);
631
        SETPRM(19,TRNVLS,TRNSIZ);
632
        RSPEAK(267);
633
        TYPE0();
634
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.