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

Subversion Repositories ion

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

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

powered by: WebSVN 2.1.0

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