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