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