summaryrefslogtreecommitdiffstats
path: root/adventure/init.c
blob: d4b028e173c768bcc617e07e6445ea5b2fbf0d45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*	$NetBSD: init.c,v 1.21 2014/03/22 20:07:05 dholland Exp $	*/

/*-
 * Copyright (c) 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * The game adventure was originally written in Fortran by Will Crowther
 * and Don Woods.  It was later translated to C and enhanced by Jim
 * Gillogly.  This code is derived from software contributed to Berkeley
 * by Jim Gillogly at The Rand Corporation.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)init.c	8.1 (Berkeley) 6/2/93";
#else
__RCSID("$NetBSD: init.c,v 1.21 2014/03/22 20:07:05 dholland Exp $");
#endif
#endif /* not lint */

/*      Re-coding of advent in C: data initialization */

#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

#include "hdr.h"
#include "extern.h"

static void linkdata(void);

int     blklin = TRUE;

int     setbit[16] = {1, 2, 4, 010, 020, 040, 0100, 0200, 0400, 01000, 02000, 
		      04000, 010000, 020000, 040000, 0100000};

volatile sig_atomic_t delhit;
int     yea;

int     loc, newloc, oldloc, oldloc2, wasdark, gaveup, kq, k, k2;
char   *wd1, *wd2;		/* the complete words */
int     verb, obj, spk;
int     saveday, savet, maxscore, latency;

struct hashtab voc[HTSIZE];

struct text rtext[RTXSIZE];	/* random text messages */

struct text mtext[MAGSIZE];	/* magic messages */

int     classes;

struct text ctext[CLSMAX];	/* classes of adventurer */
int     cval[CLSMAX];

struct text ptext[101];		/* object descriptions */

struct text ltext[LOCSIZE];	/* long loc description */
struct text stext[LOCSIZE];	/* short loc descriptions */

struct travlist *travel[LOCSIZE], *tkk;	/* travel is closer to keys(...) */

int     atloc[LOCSIZE];

int     plac[101];		/* initial object placement */
int     fixd[101], fixed[101];	/* location fixed? */

int     actspeak[35];		/* rtext msg for verb <n> */

int     cond[LOCSIZE];		/* various condition bits */

int     hintmax;
int     hints[20][5];		/* info on hints */
int     hinted[20], hintlc[20];

int     place[101], prop[101], links[201];
int     abb[LOCSIZE];

int     maxtrs, tally, tally2;	/* treasure values */

int     keys, lamp, grate, cage, rod, rod2, steps,	/* mnemonics */
        bird, door, pillow, snake, fissure, tablet, clam, oyster,
        magazine, dwarf, knife, food, bottle, water, oil, plant, plant2,
        axe, mirror, dragon, chasm, troll, troll2, bear, message,
        vend, batter, nugget, coins, chest, eggs, trident, vase,
        emerald, pyramid, pearl, rug, chain, spices, back, look, cave,
        null, entrance, depression, say, lock, throw,
        find, invent;

static int enter, /*stream,*/ pour;

int     chloc, chloc2, dseen[7], dloc[7],	/* dwarf stuff */
        odloc[7], dflag, daltloc;

int     tk[21], stick, dtotal, attack;
int     turns, lmwarn, iwest, knfloc, detail,	/* various flags and
						 * counters */
        abbnum, maxdie, numdie, holding, dkill, foobar, bonus, clock1,
        clock2, saved, isclosing, panic, closed, scoring;

int     demo, limit;

/* everything for 1st time run */
void
init(void)
{
	rdata();		/* read data from orig. file */
	linkdata();
	poof();
}

char *
decr(int a, int b, int c, int d, int e)
{
	static char buf[6];

	buf[0] = a - '+';
	buf[1] = b - '-';
	buf[2] = c - '#';
	buf[3] = d - '&';
	buf[4] = e - '%';
	buf[5] = 0;
	return buf;
}

static void
linkdata(void)
{				/* secondary data manipulation */
	int     i, j;

	/* array linkages */
	for (i = 1; i < LOCSIZE; i++)
		if (ltext[i].seekadr != 0 && travel[i] != 0)
			if ((travel[i]->tverb) == 1)
				cond[i] = 2;
	for (j = 100; j > 0; j--)
		if (fixd[j] > 0) {
			drop(j + 100, fixd[j]);
			drop(j, plac[j]);
		}
	for (j = 100; j > 0; j--) {
		fixed[j] = fixd[j];
		if (plac[j] != 0 && fixd[j] <= 0)
			drop(j, plac[j]);
	}

	maxtrs = 79;
	tally = 0;
	tally2 = 0;

	for (i = 50; i <= maxtrs; i++) {
		if (ptext[i].seekadr != 0)
			prop[i] = -1;
		tally -= prop[i];
	}

	/* define mnemonics */
	keys = vocab(DECR('k', 'e', 'y', 's', '\0'), 1, 0);
	lamp = vocab(DECR('l', 'a', 'm', 'p', '\0'), 1, 0);
	grate = vocab(DECR('g', 'r', 'a', 't', 'e'), 1, 0);
	cage = vocab(DECR('c', 'a', 'g', 'e', '\0'), 1, 0);
	rod = vocab(DECR('r', 'o', 'd', '\0', '\0'), 1, 0);
	rod2 = rod + 1;
	steps = vocab(DECR('s', 't', 'e', 'p', 's'), 1, 0);
	bird = vocab(DECR('b', 'i', 'r', 'd', '\0'), 1, 0);
	door = vocab(DECR('d', 'o', 'o', 'r', '\0'), 1, 0);
	pillow = vocab(DECR('p', 'i', 'l', 'l', 'o'), 1, 0);
	snake = vocab(DECR('s', 'n', 'a', 'k', 'e'), 1, 0);
	fissure = vocab(DECR('f', 'i', 's', 's', 'u'), 1, 0);
	tablet = vocab(DECR('t', 'a', 'b', 'l', 'e'), 1, 0);
	clam = vocab(DECR('c', 'l', 'a', 'm', '\0'), 1, 0);
	oyster = vocab(DECR('o', 'y', 's', 't', 'e'), 1, 0);
	magazine = vocab(DECR('m', 'a', 'g', 'a', 'z'), 1, 0);
	dwarf = vocab(DECR('d', 'w', 'a', 'r', 'f'), 1, 0);
	knife = vocab(DECR('k', 'n', 'i', 'f', 'e'), 1, 0);
	food = vocab(DECR('f', 'o', 'o', 'd', '\0'), 1, 0);
	bottle = vocab(DECR('b', 'o', 't', 't', 'l'), 1, 0);
	water = vocab(DECR('w', 'a', 't', 'e', 'r'), 1, 0);
	oil = vocab(DECR('o', 'i', 'l', '\0', '\0'), 1, 0);
	plant = vocab(DECR('p', 'l', 'a', 'n', 't'), 1, 0);
	plant2 = plant + 1;
	axe = vocab(DECR('a', 'x', 'e', '\0', '\0'), 1, 0);
	mirror = vocab(DECR('m', 'i', 'r', 'r', 'o'), 1, 0);
	dragon = vocab(DECR('d', 'r', 'a', 'g', 'o'), 1, 0);
	chasm = vocab(DECR('c', 'h', 'a', 's', 'm'), 1, 0);
	troll = vocab(DECR('t', 'r', 'o', 'l', 'l'), 1, 0);
	troll2 = troll + 1;
	bear = vocab(DECR('b', 'e', 'a', 'r', '\0'), 1, 0);
	message = vocab(DECR('m', 'e', 's', 's', 'a'), 1, 0);
	vend = vocab(DECR('v', 'e', 'n', 'd', 'i'), 1, 0);
	batter = vocab(DECR('b', 'a', 't', 't', 'e'), 1, 0);

	nugget = vocab(DECR('g', 'o', 'l', 'd', '\0'), 1, 0);
	coins = vocab(DECR('c', 'o', 'i', 'n', 's'), 1, 0);
	chest = vocab(DECR('c', 'h', 'e', 's', 't'), 1, 0);
	eggs = vocab(DECR('e', 'g', 'g', 's', '\0'), 1, 0);
	trident = vocab(DECR('t', 'r', 'i', 'd', 'e'), 1, 0);
	vase = vocab(DECR('v', 'a', 's', 'e', '\0'), 1, 0);
	emerald = vocab(DECR('e', 'm', 'e', 'r', 'a'), 1, 0);
	pyramid = vocab(DECR('p', 'y', 'r', 'a', 'm'), 1, 0);
	pearl = vocab(DECR('p', 'e', 'a', 'r', 'l'), 1, 0);
	rug = vocab(DECR('r', 'u', 'g', '\0', '\0'), 1, 0);
	chain = vocab(DECR('c', 'h', 'a', 'i', 'n'), 1, 0);

	back = vocab(DECR('b', 'a', 'c', 'k', '\0'), 0, 0);
	look = vocab(DECR('l', 'o', 'o', 'k', '\0'), 0, 0);
	cave = vocab(DECR('c', 'a', 'v', 'e', '\0'), 0, 0);
	null = vocab(DECR('n', 'u', 'l', 'l', '\0'), 0, 0);
	entrance = vocab(DECR('e', 'n', 't', 'r', 'a'), 0, 0);
	depression = vocab(DECR('d', 'e', 'p', 'r', 'e'), 0, 0);
	enter = vocab(DECR('e', 'n', 't', 'e', 'r'), 0, 0);

	pour = vocab(DECR('p', 'o', 'u', 'r', '\0'), 2, 0);
	say = vocab(DECR('s', 'a', 'y', '\0', '\0'), 2, 0);
	lock = vocab(DECR('l', 'o', 'c', 'k', '\0'), 2, 0);
	throw = vocab(DECR('t', 'h', 'r', 'o', 'w'), 2, 0);
	find = vocab(DECR('f', 'i', 'n', 'd', '\0'), 2, 0);
	invent = vocab(DECR('i', 'n', 'v', 'e', 'n'), 2, 0);

	/* initialize dwarves */
	chloc = 114;
	chloc2 = 140;
	for (i = 1; i <= 6; i++)
		dseen[i] = FALSE;
	dflag = 0;
	dloc[1] = 19;
	dloc[2] = 27;
	dloc[3] = 33;
	dloc[4] = 44;
	dloc[5] = 64;
	dloc[6] = chloc;
	daltloc = 18;

	/* random flags & ctrs */
	turns = 0;
	lmwarn = FALSE;
	iwest = 0;
	knfloc = 0;
	detail = 0;
	abbnum = 5;
	for (i = 0; i <= 4; i++)
		if (rtext[2 * i + 81].seekadr != 0)
			maxdie = i + 1;
	numdie = holding = dkill = foobar = bonus = 0;
	clock1 = 30;
	clock2 = 50;
	saved = 0;
	isclosing = panic = closed = scoring = FALSE;
}

/* come here if he hits a del */
void
trapdel(int n __unused)
{
	delhit = 1;		/* main checks, treats as QUIT */
	signal(SIGINT, trapdel);/* catch subsequent DELs */
}


void
startup(void)
{
	demo = Start();
	srand((int)time(NULL));	/* random seed */
#if 0
	srand(371);		/* non-random seed */
#endif
	hinted[3] = yes(65, 1, 0);
	newloc = 1;
	delhit = 0;
	limit = 330;
	if (hinted[3])
		limit = 1000;	/* better batteries if instrucs */
}