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