dinit.c 12 KB

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