1 /* INIT-- DUNGEON INITIALIZATION SUBROUTINE */
2
3 /*COPYRIGHT 1980, INFOCOM COMPUTERS AND COMMUNICATIONS, CAMBRIDGE MA. 02142*/
4 /* ALL RIGHTS RESERVED, COMMERCIAL USAGE STRICTLY PROHIBITED */
5 /* WRITTEN BY R. M. SUPNIK */
6
7 #include <stdio.h>
8
9 #ifdef __AMOS__
10 #include <amos.h>
11 #endif
12
13 #include "funcs.h"
14 #include "vars.h"
15
16 /* This is here to avoid depending on the existence of <stdlib.h> */
17
18 extern void srand P((unsigned int));
19
20 FILE *dbfile;
21
22 #ifndef TEXTFILE
23 #ifdef __AMOS__
24 #define TEXTFILE "lib:dtextc.dat"
25 #else /* ! __AMOS__ */
26 #ifdef unix
27 #define TEXTFILE "/usr/games/lib/dunlib/dtextc.dat"
28 #else /* ! unix */
29 I need a definition for TEXTFILE
30 #endif /* ! unix */
31 #endif /* ! __AMOS__ */
32 #endif /* ! TEXTFILE */
33
34 #ifndef LOCALTEXTFILE
35 #define LOCALTEXTFILE "dtextc.dat"
36 #endif
37
38 /* Read a single two byte integer from the index file */
39
40 #define rdint(indxfile) \
41 (ch = getc(indxfile), \
42 ((ch > 127) ? (ch - 256) : (ch)) * 256 + getc(indxfile))
43
44 /* Read a number of two byte integers from the index file */
45
46 static void rdints(c, pi, indxfile)
47 integer c;
48 integer *pi;
49 FILE *indxfile;
50 {
51 integer ch; /* Local variable for rdint */
52
53 while (c-- != 0)
54 *pi++ = rdint(indxfile);
55 }
56
57 /* Read a partial array of integers. These are stored as index,value
58 * pairs.
59 */
60
rdpartialints(c,pi,indxfile)61 static void rdpartialints(c, pi, indxfile)
62 integer c;
63 integer *pi;
64 FILE *indxfile;
65 {
66 integer ch; /* Local variable for rdint */
67
68 while (1) {
69 int i;
70
71 if (c < 255) {
72 i = getc(indxfile);
73 if (i == 255)
74 return;
75 }
76 else {
77 i = rdint(indxfile);
78 if (i == -1)
79 return;
80 }
81
82 pi[i] = rdint(indxfile);
83 }
84 }
85
86 /* Read a number of one byte flags from the index file */
87
rdflags(c,pf,indxfile)88 static void rdflags(c, pf, indxfile)
89 integer c;
90 logical *pf;
91 FILE *indxfile;
92 {
93 while (c-- != 0)
94 *pf++ = getc(indxfile);
95 }
96
init_()97 logical init_()
98 {
99 /* System generated locals */
100 integer i__1;
101 logical ret_val;
102
103 /* Local variables */
104 integer xmax, r2max, dirmax, recno;
105 integer i, j, k;
106 register integer ch;
107 register FILE *indxfile;
108 integer mmax, omax, rmax, vmax, amax, cmax, fmax, smax;
109
110 more_init();
111
112 /* FIRST CHECK FOR PROTECTION VIOLATION */
113
114 if (protected()) {
115 goto L10000;
116 }
117 /* !PROTECTION VIOLATION? */
118 more_output("There appears before you a threatening figure clad all over");
119 more_output("in heavy black armor. His legs seem like the massive trunk");
120 more_output("of the oak tree. His broad shoulders and helmeted head loom");
121 more_output("high over your own puny frame, and you realize that his powerful");
122 more_output("arms could easily crush the very life from your body. There");
123 more_output("hangs from his belt a veritable arsenal of deadly weapons:");
124 more_output("sword, mace, ball and chain, dagger, lance, and trident.");
125 more_output("He speaks with a commanding voice:");
126 more_output("");
127 more_output(" \"You shall not pass.\"");
128 more_output("");
129 more_output("As he grabs you by the neck all grows dim about you.");
130 exit_();
131
132 /* NOW START INITIALIZATION PROPER */
133
134 L10000:
135 ret_val = FALSE_;
136 /* !ASSUME INIT FAILS. */
137 mmax = 1050;
138 /* !SET UP ARRAY LIMITS. */
139 omax = 220;
140 rmax = 200;
141 vmax = 4;
142 amax = 4;
143 cmax = 25;
144 fmax = 46;
145 smax = 22;
146 xmax = 900;
147 r2max = 20;
148 dirmax = 15;
149
150 rmsg_1.mlnt = 0;
151 /* !INIT ARRAY COUNTERS. */
152 objcts_1.olnt = 0;
153 rooms_1.rlnt = 0;
154 vill_1.vlnt = 0;
155 advs_1.alnt = 0;
156 cevent_1.clnt = 0;
157 exits_1.xlnt = 1;
158 oroom2_1.r2lnt = 0;
159
160 state_1.ltshft = 10;
161 /* !SET UP STATE VARIABLES. */
162 state_1.mxscor = state_1.ltshft;
163 state_1.egscor = 0;
164 state_1.egmxsc = 0;
165 state_1.mxload = 100;
166 state_1.rwscor = 0;
167 state_1.deaths = 0;
168 state_1.moves = 0;
169 time_1.pltime = 0;
170 state_1.mungrm = 0;
171 state_1.hs = 0;
172 prsvec_1.prsa = 0;
173 /* !CLEAR PARSE VECTOR. */
174 prsvec_1.prsi = 0;
175 prsvec_1.prso = 0;
176 prsvec_1.prscon = 1;
177 orphs_1.oflag = 0;
178 /* !CLEAR ORPHANS. */
179 orphs_1.oact = 0;
180 orphs_1.oslot = 0;
181 orphs_1.oprep = 0;
182 orphs_1.oname = 0;
183 hack_1.thfflg = FALSE_;
184 /* !THIEF NOT INTRODUCED BUT */
185 hack_1.thfact = TRUE_;
186 /* !IS ACTIVE. */
187 hack_1.swdact = FALSE_;
188 /* !SWORD IS INACTIVE. */
189 hack_1.swdsta = 0;
190 /* !SWORD IS OFF. */
191
192 recno = 1;
193 /* !INIT DB FILE POINTER. */
194 star_1.mbase = 0;
195 /* !INIT MELEE BASE. */
196 /* INIT, PAGE 3 */
197
198 /* INIT ALL ARRAYS. */
199
200 i__1 = cmax;
201 for (i = 1; i <= i__1; ++i) {
202 /* !CLEAR CLOCK EVENTS */
203 cevent_1.cflag[i - 1] = FALSE_;
204 cevent_1.ctick[i - 1] = 0;
205 cevent_1.cactio[i - 1] = 0;
206 /* L5: */
207 }
208
209 i__1 = fmax;
210 for (i = 1; i <= i__1; ++i) {
211 /* !CLEAR FLAGS. */
212 flags[i - 1] = FALSE_;
213 /* L10: */
214 }
215 findex_1.buoyf = TRUE_;
216 /* !SOME START AS TRUE. */
217 findex_1.egyptf = TRUE_;
218 findex_1.cagetf = TRUE_;
219 findex_1.mr1f = TRUE_;
220 findex_1.mr2f = TRUE_;
221 findex_1.follwf = TRUE_;
222 i__1 = smax;
223 for (i = 1; i <= i__1; ++i) {
224 /* !CLEAR SWITCHES. */
225 switch_[i - 1] = 0;
226 /* L12: */
227 }
228 findex_1.ormtch = 4;
229 /* !NUMBER OF MATCHES. */
230 findex_1.lcell = 1;
231 findex_1.pnumb = 1;
232 findex_1.mdir = 270;
233 findex_1.mloc = rindex_1.mrb;
234 findex_1.cphere = 10;
235
236 i__1 = r2max;
237 for (i = 1; i <= i__1; ++i) {
238 /* !CLEAR ROOM 2 ARRAY. */
239 oroom2_1.rroom2[i - 1] = 0;
240 oroom2_1.oroom2[i - 1] = 0;
241 /* L15: */
242 }
243
244 i__1 = xmax;
245 for (i = 1; i <= i__1; ++i) {
246 /* !CLEAR TRAVEL ARRAY. */
247 exits_1.travel[i - 1] = 0;
248 /* L20: */
249 }
250
251 i__1 = vmax;
252 for (i = 1; i <= i__1; ++i) {
253 /* !CLEAR VILLAINS ARRAYS. */
254 vill_1.vopps[i - 1] = 0;
255 vill_1.vprob[i - 1] = 0;
256 vill_1.villns[i - 1] = 0;
257 vill_1.vbest[i - 1] = 0;
258 vill_1.vmelee[i - 1] = 0;
259 /* L30: */
260 }
261
262 i__1 = omax;
263 for (i = 1; i <= i__1; ++i) {
264 /* !CLEAR OBJECT ARRAYS. */
265 objcts_1.odesc1[i - 1] = 0;
266 objcts_1.odesc2[i - 1] = 0;
267 objcts_1.odesco[i - 1] = 0;
268 objcts_1.oread[i - 1] = 0;
269 objcts_1.oactio[i - 1] = 0;
270 objcts_1.oflag1[i - 1] = 0;
271 objcts_1.oflag2[i - 1] = 0;
272 objcts_1.ofval[i - 1] = 0;
273 objcts_1.otval[i - 1] = 0;
274 objcts_1.osize[i - 1] = 0;
275 objcts_1.ocapac[i - 1] = 0;
276 objcts_1.ocan[i - 1] = 0;
277 objcts_1.oadv[i - 1] = 0;
278 objcts_1.oroom[i - 1] = 0;
279 /* L40: */
280 }
281
282 i__1 = rmax;
283 for (i = 1; i <= i__1; ++i) {
284 /* !CLEAR ROOM ARRAYS. */
285 rooms_1.rdesc1[i - 1] = 0;
286 rooms_1.rdesc2[i - 1] = 0;
287 rooms_1.ractio[i - 1] = 0;
288 rooms_1.rflag[i - 1] = 0;
289 rooms_1.rval[i - 1] = 0;
290 rooms_1.rexit[i - 1] = 0;
291 /* L50: */
292 }
293
294 i__1 = mmax;
295 for (i = 1; i <= i__1; ++i) {
296 /* !CLEAR MESSAGE DIRECTORY. */
297 rmsg_1.rtext[i - 1] = 0;
298 /* L60: */
299 }
300
301 i__1 = amax;
302 for (i = 1; i <= i__1; ++i) {
303 /* !CLEAR ADVENTURER'S ARRAYS. */
304 advs_1.aroom[i - 1] = 0;
305 advs_1.ascore[i - 1] = 0;
306 advs_1.avehic[i - 1] = 0;
307 advs_1.aobj[i - 1] = 0;
308 advs_1.aactio[i - 1] = 0;
309 advs_1.astren[i - 1] = 0;
310 advs_1.aflag[i - 1] = 0;
311 /* L70: */
312 }
313
314 debug_1.dbgflg = 0;
315 debug_1.prsflg = 0;
316 debug_1.gdtflg = 0;
317
318 #ifdef ALLOW_GDT
319
320 /* allow setting gdtflg true if user id matches wizard id */
321 /* this way, the wizard doesn't have to recompile to use gdt */
322
323 if (wizard()) {
324 debug_1.gdtflg = 1;
325 }
326
327 #endif /* ALLOW_GDT */
328
329 screen_1.fromdr = 0;
330 /* !INIT SCOL GOODIES. */
331 screen_1.scolrm = 0;
332 screen_1.scolac = 0;
333 /* INIT, PAGE 4 */
334
335 /* NOW RESTORE FROM EXISTING INDEX FILE. */
336
337 #ifdef __AMOS__
338 if ((dbfile = fdopen(ropen(LOCALTEXTFILE, 0), BINREAD)) == NULL &&
339 (dbfile = fdopen(ropen(TEXTFILE, 0), BINREAD)) == NULL)
340 #else
341 if ((dbfile = fopen(LOCALTEXTFILE, BINREAD)) == NULL &&
342 (dbfile = fopen(TEXTFILE, BINREAD)) == NULL)
343 #endif
344 goto L1950;
345
346 indxfile = dbfile;
347
348 i = rdint(indxfile);
349 j = rdint(indxfile);
350 k = rdint(indxfile);
351
352 /* !GET VERSION. */
353 if (i != vers_1.vmaj || j != vers_1.vmin) {
354 goto L1925;
355 }
356
357 state_1.mxscor = rdint(indxfile);
358 star_1.strbit = rdint(indxfile);
359 state_1.egmxsc = rdint(indxfile);
360
361 rooms_1.rlnt = rdint(indxfile);
362 rdints(rooms_1.rlnt, &rooms_1.rdesc1[0], indxfile);
363 rdints(rooms_1.rlnt, &rooms_1.rdesc2[0], indxfile);
364 rdints(rooms_1.rlnt, &rooms_1.rexit[0], indxfile);
365 rdpartialints(rooms_1.rlnt, &rooms_1.ractio[0], indxfile);
366 rdpartialints(rooms_1.rlnt, &rooms_1.rval[0], indxfile);
367 rdints(rooms_1.rlnt, &rooms_1.rflag[0], indxfile);
368
369 exits_1.xlnt = rdint(indxfile);
370 rdints(exits_1.xlnt, &exits_1.travel[0], indxfile);
371
372 objcts_1.olnt = rdint(indxfile);
373 rdints(objcts_1.olnt, &objcts_1.odesc1[0], indxfile);
374 rdints(objcts_1.olnt, &objcts_1.odesc2[0], indxfile);
375 rdpartialints(objcts_1.olnt, &objcts_1.odesco[0], indxfile);
376 rdpartialints(objcts_1.olnt, &objcts_1.oactio[0], indxfile);
377 rdints(objcts_1.olnt, &objcts_1.oflag1[0], indxfile);
378 rdpartialints(objcts_1.olnt, &objcts_1.oflag2[0], indxfile);
379 rdpartialints(objcts_1.olnt, &objcts_1.ofval[0], indxfile);
380 rdpartialints(objcts_1.olnt, &objcts_1.otval[0], indxfile);
381 rdints(objcts_1.olnt, &objcts_1.osize[0], indxfile);
382 rdpartialints(objcts_1.olnt, &objcts_1.ocapac[0], indxfile);
383 rdints(objcts_1.olnt, &objcts_1.oroom[0], indxfile);
384 rdpartialints(objcts_1.olnt, &objcts_1.oadv[0], indxfile);
385 rdpartialints(objcts_1.olnt, &objcts_1.ocan[0], indxfile);
386 rdpartialints(objcts_1.olnt, &objcts_1.oread[0], indxfile);
387
388 oroom2_1.r2lnt = rdint(indxfile);
389 rdints(oroom2_1.r2lnt, &oroom2_1.oroom2[0], indxfile);
390 rdints(oroom2_1.r2lnt, &oroom2_1.rroom2[0], indxfile);
391
392 cevent_1.clnt = rdint(indxfile);
393 rdints(cevent_1.clnt, &cevent_1.ctick[0], indxfile);
394 rdints(cevent_1.clnt, &cevent_1.cactio[0], indxfile);
395 rdflags(cevent_1.clnt, &cevent_1.cflag[0], indxfile);
396
397 vill_1.vlnt = rdint(indxfile);
398 rdints(vill_1.vlnt, &vill_1.villns[0], indxfile);
399 rdpartialints(vill_1.vlnt, &vill_1.vprob[0], indxfile);
400 rdpartialints(vill_1.vlnt, &vill_1.vopps[0], indxfile);
401 rdints(vill_1.vlnt, &vill_1.vbest[0], indxfile);
402 rdints(vill_1.vlnt, &vill_1.vmelee[0], indxfile);
403
404 advs_1.alnt = rdint(indxfile);
405 rdints(advs_1.alnt, &advs_1.aroom[0], indxfile);
406 rdpartialints(advs_1.alnt, &advs_1.ascore[0], indxfile);
407 rdpartialints(advs_1.alnt, &advs_1.avehic[0], indxfile);
408 rdints(advs_1.alnt, &advs_1.aobj[0], indxfile);
409 rdints(advs_1.alnt, &advs_1.aactio[0], indxfile);
410 rdints(advs_1.alnt, &advs_1.astren[0], indxfile);
411 rdpartialints(advs_1.alnt, &advs_1.aflag[0], indxfile);
412
413 star_1.mbase = rdint(indxfile);
414 rmsg_1.mlnt = rdint(indxfile);
415 rdints(rmsg_1.mlnt, &rmsg_1.rtext[0], indxfile);
416
417 /* Save location of start of message text */
418 rmsg_1.mrloc = ftell(indxfile);
419
420 /* !INIT DONE. */
421
422 /* INIT, PAGE 5 */
423
424 /* THE INTERNAL DATA BASE IS NOW ESTABLISHED. */
425 /* SET UP TO PLAY THE GAME. */
426
427 itime_(&time_1.shour, &time_1.smin, &time_1.ssec);
428 srand(time_1.shour ^ (time_1.smin ^ time_1.ssec));
429
430 play_1.winner = aindex_1.player;
431 last_1.lastit = advs_1.aobj[aindex_1.player - 1];
432 play_1.here = advs_1.aroom[play_1.winner - 1];
433 hack_1.thfpos = objcts_1.oroom[oindex_1.thief - 1];
434 state_1.bloc = objcts_1.oroom[oindex_1.ballo - 1];
435 ret_val = TRUE_;
436
437 return ret_val;
438 /* INIT, PAGE 6 */
439
440 /* ERRORS-- INIT FAILS. */
441
442 L1925:
443 more_output(NULL);
444 printf("%s is version %1d.%1d%c.\n", TEXTFILE, i, j, k);
445 more_output(NULL);
446 printf("I require version %1d.%1d%c.\n", vers_1.vmaj, vers_1.vmin,
447 vers_1.vedit);
448 goto L1975;
449 L1950:
450 more_output(NULL);
451 printf("I can't open %s.\n", TEXTFILE);
452 L1975:
453 more_output("Suddenly a sinister, wraithlike figure appears before you,");
454 more_output("seeming to float in the air. In a low, sorrowful voice he says,");
455 more_output("\"Alas, the very nature of the world has changed, and the dungeon");
456 more_output("cannot be found. All must now pass away.\" Raising his oaken staff");
457 more_output("in farewell, he fades into the spreading darkness. In his place");
458 more_output("appears a tastefully lettered sign reading:");
459 more_output("");
460 more_output(" INITIALIZATION FAILURE");
461 more_output("");
462 more_output("The darkness becomes all encompassing, and your vision fails.");
463 return ret_val;
464
465 } /* init_ */
466