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