init.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* $NetBSD: init.c,v 1.14 2003/08/07 09:36:50 agc Exp $ */
  2. /*-
  3. * Copyright (c) 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * The game adventure was originally written in Fortran by Will Crowther
  7. * and Don Woods. It was later translated to C and enhanced by Jim
  8. * Gillogly. This code is derived from software contributed to Berkeley
  9. * by Jim Gillogly at The Rand Corporation.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. */
  35. #include <sys/cdefs.h>
  36. #ifndef lint
  37. #if 0
  38. static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/2/93";
  39. #else
  40. __RCSID("$NetBSD: init.c,v 1.14 2003/08/07 09:36:50 agc Exp $");
  41. #endif
  42. #endif /* not lint */
  43. /* Re-coding of advent in C: data initialization */
  44. #include <sys/types.h>
  45. #include <signal.h>
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <time.h>
  49. #include <unistd.h>
  50. #include "hdr.h"
  51. #include "extern.h"
  52. int blklin = TRUE;
  53. int setbit[16] = {1, 2, 4, 010, 020, 040, 0100, 0200, 0400, 01000, 02000, 04000,
  54. 010000, 020000, 040000, 0100000};
  55. int datfd; /* message file descriptor */
  56. volatile sig_atomic_t delhit;
  57. int yea;
  58. int loc, newloc, oldloc, oldlc2, wzdark, gaveup, kq, k, k2;
  59. char *wd1, *wd2; /* the complete words */
  60. int verb, obj, spk;
  61. int saveday, savet, mxscor, latncy;
  62. struct hashtab voc[HTSIZE];
  63. struct text rtext[RTXSIZ]; /* random text messages */
  64. struct text mtext[MAGSIZ]; /* magic messages */
  65. int clsses;
  66. struct text ctext[CLSMAX]; /* classes of adventurer */
  67. int cval[CLSMAX];
  68. struct text ptext[101]; /* object descriptions */
  69. struct text ltext[LOCSIZ]; /* long loc description */
  70. struct text stext[LOCSIZ]; /* short loc descriptions */
  71. struct travlist *travel[LOCSIZ], *tkk; /* travel is closer to keys(...) */
  72. int atloc[LOCSIZ];
  73. int plac[101]; /* initial object placement */
  74. int fixd[101], fixed[101]; /* location fixed? */
  75. int actspk[35]; /* rtext msg for verb <n> */
  76. int cond[LOCSIZ]; /* various condition bits */
  77. int hntmax;
  78. int hints[20][5]; /* info on hints */
  79. int hinted[20], hintlc[20];
  80. int place[101], prop[101], links[201];
  81. int abb[LOCSIZ];
  82. int maxtrs, tally, tally2; /* treasure values */
  83. int keys, lamp, grate, cage, rod, rod2, steps, /* mnemonics */
  84. bird, door, pillow, snake, fissur, tablet, clam, oyster,
  85. magzin, dwarf, knife, food, bottle, water, oil, plant, plant2,
  86. axe, mirror, dragon, chasm, troll, troll2, bear, messag,
  87. vend, batter, nugget, coins, chest, eggs, tridnt, vase,
  88. emrald, pyram, pearl, rug, chain, spices, back, look, cave,
  89. null, entrnc, dprssn, enter, stream, pour, say, lock, throw,
  90. find, invent;
  91. int chloc, chloc2, dseen[7], dloc[7], /* dwarf stuff */
  92. odloc[7], dflag, daltlc;
  93. int tk[21], stick, dtotal, attack;
  94. int turns, lmwarn, iwest, knfloc, detail, /* various flags and
  95. * counters */
  96. abbnum, maxdie, numdie, holdng, dkill, foobar, bonus, clock1,
  97. clock2, saved, closng, panic, closed, scorng;
  98. int demo, limit;
  99. void
  100. init() /* everything for 1st time run */
  101. {
  102. rdata(); /* read data from orig. file */
  103. linkdata();
  104. poof();
  105. }
  106. char *
  107. decr(a, b, c, d, e)
  108. char a, b, c, d, e;
  109. {
  110. static char buf[6];
  111. buf[0] = a - '+';
  112. buf[1] = b - '-';
  113. buf[2] = c - '#';
  114. buf[3] = d - '&';
  115. buf[4] = e - '%';
  116. buf[5] = 0;
  117. return buf;
  118. }
  119. void
  120. linkdata()
  121. { /* secondary data manipulation */
  122. int i, j;
  123. /* array linkages */
  124. for (i = 1; i <= LOCSIZ; i++)
  125. if (ltext[i].seekadr != 0 && travel[i] != 0)
  126. if ((travel[i]->tverb) == 1)
  127. cond[i] = 2;
  128. for (j = 100; j > 0; j--)
  129. if (fixd[j] > 0) {
  130. drop(j + 100, fixd[j]);
  131. drop(j, plac[j]);
  132. }
  133. for (j = 100; j > 0; j--) {
  134. fixed[j] = fixd[j];
  135. if (plac[j] != 0 && fixd[j] <= 0)
  136. drop(j, plac[j]);
  137. }
  138. maxtrs = 79;
  139. tally = 0;
  140. tally2 = 0;
  141. for (i = 50; i <= maxtrs; i++) {
  142. if (ptext[i].seekadr != 0)
  143. prop[i] = -1;
  144. tally -= prop[i];
  145. }
  146. /* define mnemonics */
  147. keys = vocab(DECR('k', 'e', 'y', 's', '\0'), 1, 0);
  148. lamp = vocab(DECR('l', 'a', 'm', 'p', '\0'), 1, 0);
  149. grate = vocab(DECR('g', 'r', 'a', 't', 'e'), 1, 0);
  150. cage = vocab(DECR('c', 'a', 'g', 'e', '\0'), 1, 0);
  151. rod = vocab(DECR('r', 'o', 'd', '\0', '\0'), 1, 0);
  152. rod2 = rod + 1;
  153. steps = vocab(DECR('s', 't', 'e', 'p', 's'), 1, 0);
  154. bird = vocab(DECR('b', 'i', 'r', 'd', '\0'), 1, 0);
  155. door = vocab(DECR('d', 'o', 'o', 'r', '\0'), 1, 0);
  156. pillow = vocab(DECR('p', 'i', 'l', 'l', 'o'), 1, 0);
  157. snake = vocab(DECR('s', 'n', 'a', 'k', 'e'), 1, 0);
  158. fissur = vocab(DECR('f', 'i', 's', 's', 'u'), 1, 0);
  159. tablet = vocab(DECR('t', 'a', 'b', 'l', 'e'), 1, 0);
  160. clam = vocab(DECR('c', 'l', 'a', 'm', '\0'), 1, 0);
  161. oyster = vocab(DECR('o', 'y', 's', 't', 'e'), 1, 0);
  162. magzin = vocab(DECR('m', 'a', 'g', 'a', 'z'), 1, 0);
  163. dwarf = vocab(DECR('d', 'w', 'a', 'r', 'f'), 1, 0);
  164. knife = vocab(DECR('k', 'n', 'i', 'f', 'e'), 1, 0);
  165. food = vocab(DECR('f', 'o', 'o', 'd', '\0'), 1, 0);
  166. bottle = vocab(DECR('b', 'o', 't', 't', 'l'), 1, 0);
  167. water = vocab(DECR('w', 'a', 't', 'e', 'r'), 1, 0);
  168. oil = vocab(DECR('o', 'i', 'l', '\0', '\0'), 1, 0);
  169. plant = vocab(DECR('p', 'l', 'a', 'n', 't'), 1, 0);
  170. plant2 = plant + 1;
  171. axe = vocab(DECR('a', 'x', 'e', '\0', '\0'), 1, 0);
  172. mirror = vocab(DECR('m', 'i', 'r', 'r', 'o'), 1, 0);
  173. dragon = vocab(DECR('d', 'r', 'a', 'g', 'o'), 1, 0);
  174. chasm = vocab(DECR('c', 'h', 'a', 's', 'm'), 1, 0);
  175. troll = vocab(DECR('t', 'r', 'o', 'l', 'l'), 1, 0);
  176. troll2 = troll + 1;
  177. bear = vocab(DECR('b', 'e', 'a', 'r', '\0'), 1, 0);
  178. messag = vocab(DECR('m', 'e', 's', 's', 'a'), 1, 0);
  179. vend = vocab(DECR('v', 'e', 'n', 'd', 'i'), 1, 0);
  180. batter = vocab(DECR('b', 'a', 't', 't', 'e'), 1, 0);
  181. nugget = vocab(DECR('g', 'o', 'l', 'd', '\0'), 1, 0);
  182. coins = vocab(DECR('c', 'o', 'i', 'n', 's'), 1, 0);
  183. chest = vocab(DECR('c', 'h', 'e', 's', 't'), 1, 0);
  184. eggs = vocab(DECR('e', 'g', 'g', 's', '\0'), 1, 0);
  185. tridnt = vocab(DECR('t', 'r', 'i', 'd', 'e'), 1, 0);
  186. vase = vocab(DECR('v', 'a', 's', 'e', '\0'), 1, 0);
  187. emrald = vocab(DECR('e', 'm', 'e', 'r', 'a'), 1, 0);
  188. pyram = vocab(DECR('p', 'y', 'r', 'a', 'm'), 1, 0);
  189. pearl = vocab(DECR('p', 'e', 'a', 'r', 'l'), 1, 0);
  190. rug = vocab(DECR('r', 'u', 'g', '\0', '\0'), 1, 0);
  191. chain = vocab(DECR('c', 'h', 'a', 'i', 'n'), 1, 0);
  192. back = vocab(DECR('b', 'a', 'c', 'k', '\0'), 0, 0);
  193. look = vocab(DECR('l', 'o', 'o', 'k', '\0'), 0, 0);
  194. cave = vocab(DECR('c', 'a', 'v', 'e', '\0'), 0, 0);
  195. null = vocab(DECR('n', 'u', 'l', 'l', '\0'), 0, 0);
  196. entrnc = vocab(DECR('e', 'n', 't', 'r', 'a'), 0, 0);
  197. dprssn = vocab(DECR('d', 'e', 'p', 'r', 'e'), 0, 0);
  198. enter = vocab(DECR('e', 'n', 't', 'e', 'r'), 0, 0);
  199. pour = vocab(DECR('p', 'o', 'u', 'r', '\0'), 2, 0);
  200. say = vocab(DECR('s', 'a', 'y', '\0', '\0'), 2, 0);
  201. lock = vocab(DECR('l', 'o', 'c', 'k', '\0'), 2, 0);
  202. throw = vocab(DECR('t', 'h', 'r', 'o', 'w'), 2, 0);
  203. find = vocab(DECR('f', 'i', 'n', 'd', '\0'), 2, 0);
  204. invent = vocab(DECR('i', 'n', 'v', 'e', 'n'), 2, 0);
  205. /* initialize dwarves */
  206. chloc = 114;
  207. chloc2 = 140;
  208. for (i = 1; i <= 6; i++)
  209. dseen[i] = FALSE;
  210. dflag = 0;
  211. dloc[1] = 19;
  212. dloc[2] = 27;
  213. dloc[3] = 33;
  214. dloc[4] = 44;
  215. dloc[5] = 64;
  216. dloc[6] = chloc;
  217. daltlc = 18;
  218. /* random flags & ctrs */
  219. turns = 0;
  220. lmwarn = FALSE;
  221. iwest = 0;
  222. knfloc = 0;
  223. detail = 0;
  224. abbnum = 5;
  225. for (i = 0; i <= 4; i++)
  226. if (rtext[2 * i + 81].seekadr != 0)
  227. maxdie = i + 1;
  228. numdie = holdng = dkill = foobar = bonus = 0;
  229. clock1 = 30;
  230. clock2 = 50;
  231. saved = 0;
  232. closng = panic = closed = scorng = FALSE;
  233. }
  234. void
  235. trapdel(n) /* come here if he hits a del */
  236. int n __attribute__((__unused__));
  237. {
  238. delhit = 1; /* main checks, treats as QUIT */
  239. signal(SIGINT, trapdel);/* catch subsequent DELs */
  240. }
  241. void
  242. startup()
  243. {
  244. demo = Start();
  245. srand((int) (time((time_t *) NULL))); /* random seed */
  246. #if 0
  247. srand(371); /* non-random seed */
  248. #endif
  249. hinted[3] = yes(65, 1, 0);
  250. newloc = 1;
  251. delhit = 0;
  252. limit = 330;
  253. if (hinted[3])
  254. limit = 1000; /* better batteries if instrucs */
  255. }