Home | History | Annotate | Line # | Download | only in adventure
init.c revision 1.7
      1 /*	$NetBSD: init.c,v 1.7 1997/10/11 01:53:28 lukem 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.7 1997/10/11 01:53:28 lukem 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 <unistd.h>
     57 #include "hdr.h"
     58 #include "extern.h"
     59 
     60 int     blklin = TRUE;
     61 
     62 int     setbit[16] = {1, 2, 4, 010, 020, 040, 0100, 0200, 0400, 01000, 02000, 04000,
     63 010000, 020000, 040000, 0100000};
     64 
     65 
     66 void
     67 init(command)			/* everything for 1st time run */
     68 	char   *command;	/* command we were called with */
     69 {
     70 	rdata();		/* read data from orig. file */
     71 	linkdata();
     72 	poof();
     73 }
     74 
     75 char   *
     76 decr(a, b, c, d, e)
     77 	char    a, b, c, d, e;
     78 {
     79 	static char buf[6];
     80 
     81 	buf[0] = a - '+';
     82 	buf[1] = b - '-';
     83 	buf[2] = c - '#';
     84 	buf[3] = d - '&';
     85 	buf[4] = e - '%';
     86 	buf[5] = 0;
     87 	return buf;
     88 }
     89 
     90 void
     91 linkdata()
     92 {				/* secondary data manipulation */
     93 	int     i, j;
     94 
     95 	/* array linkages */
     96 	for (i = 1; i <= LOCSIZ; i++)
     97 		if (ltext[i].seekadr != 0 && travel[i] != 0)
     98 			if ((travel[i]->tverb) == 1)
     99 				cond[i] = 2;
    100 	for (j = 100; j > 0; j--)
    101 		if (fixd[j] > 0) {
    102 			drop(j + 100, fixd[j]);
    103 			drop(j, plac[j]);
    104 		}
    105 	for (j = 100; j > 0; j--) {
    106 		fixed[j] = fixd[j];
    107 		if (plac[j] != 0 && fixd[j] <= 0)
    108 			drop(j, plac[j]);
    109 	}
    110 
    111 	maxtrs = 79;
    112 	tally = 0;
    113 	tally2 = 0;
    114 
    115 	for (i = 50; i <= maxtrs; i++) {
    116 		if (ptext[i].seekadr != 0)
    117 			prop[i] = -1;
    118 		tally -= prop[i];
    119 	}
    120 
    121 	/* define mnemonics */
    122 	keys = vocab(DECR('k', 'e', 'y', 's', '\0'), 1, 0);
    123 	lamp = vocab(DECR('l', 'a', 'm', 'p', '\0'), 1, 0);
    124 	grate = vocab(DECR('g', 'r', 'a', 't', 'e'), 1, 0);
    125 	cage = vocab(DECR('c', 'a', 'g', 'e', '\0'), 1, 0);
    126 	rod = vocab(DECR('r', 'o', 'd', '\0', '\0'), 1, 0);
    127 	rod2 = rod + 1;
    128 	steps = vocab(DECR('s', 't', 'e', 'p', 's'), 1, 0);
    129 	bird = vocab(DECR('b', 'i', 'r', 'd', '\0'), 1, 0);
    130 	door = vocab(DECR('d', 'o', 'o', 'r', '\0'), 1, 0);
    131 	pillow = vocab(DECR('p', 'i', 'l', 'l', 'o'), 1, 0);
    132 	snake = vocab(DECR('s', 'n', 'a', 'k', 'e'), 1, 0);
    133 	fissur = vocab(DECR('f', 'i', 's', 's', 'u'), 1, 0);
    134 	tablet = vocab(DECR('t', 'a', 'b', 'l', 'e'), 1, 0);
    135 	clam = vocab(DECR('c', 'l', 'a', 'm', '\0'), 1, 0);
    136 	oyster = vocab(DECR('o', 'y', 's', 't', 'e'), 1, 0);
    137 	magzin = vocab(DECR('m', 'a', 'g', 'a', 'z'), 1, 0);
    138 	dwarf = vocab(DECR('d', 'w', 'a', 'r', 'f'), 1, 0);
    139 	knife = vocab(DECR('k', 'n', 'i', 'f', 'e'), 1, 0);
    140 	food = vocab(DECR('f', 'o', 'o', 'd', '\0'), 1, 0);
    141 	bottle = vocab(DECR('b', 'o', 't', 't', 'l'), 1, 0);
    142 	water = vocab(DECR('w', 'a', 't', 'e', 'r'), 1, 0);
    143 	oil = vocab(DECR('o', 'i', 'l', '\0', '\0'), 1, 0);
    144 	plant = vocab(DECR('p', 'l', 'a', 'n', 't'), 1, 0);
    145 	plant2 = plant + 1;
    146 	axe = vocab(DECR('a', 'x', 'e', '\0', '\0'), 1, 0);
    147 	mirror = vocab(DECR('m', 'i', 'r', 'r', 'o'), 1, 0);
    148 	dragon = vocab(DECR('d', 'r', 'a', 'g', 'o'), 1, 0);
    149 	chasm = vocab(DECR('c', 'h', 'a', 's', 'm'), 1, 0);
    150 	troll = vocab(DECR('t', 'r', 'o', 'l', 'l'), 1, 0);
    151 	troll2 = troll + 1;
    152 	bear = vocab(DECR('b', 'e', 'a', 'r', '\0'), 1, 0);
    153 	messag = vocab(DECR('m', 'e', 's', 's', 'a'), 1, 0);
    154 	vend = vocab(DECR('v', 'e', 'n', 'd', 'i'), 1, 0);
    155 	batter = vocab(DECR('b', 'a', 't', 't', 'e'), 1, 0);
    156 
    157 	nugget = vocab(DECR('g', 'o', 'l', 'd', '\0'), 1, 0);
    158 	coins = vocab(DECR('c', 'o', 'i', 'n', 's'), 1, 0);
    159 	chest = vocab(DECR('c', 'h', 'e', 's', 't'), 1, 0);
    160 	eggs = vocab(DECR('e', 'g', 'g', 's', '\0'), 1, 0);
    161 	tridnt = vocab(DECR('t', 'r', 'i', 'd', 'e'), 1, 0);
    162 	vase = vocab(DECR('v', 'a', 's', 'e', '\0'), 1, 0);
    163 	emrald = vocab(DECR('e', 'm', 'e', 'r', 'a'), 1, 0);
    164 	pyram = vocab(DECR('p', 'y', 'r', 'a', 'm'), 1, 0);
    165 	pearl = vocab(DECR('p', 'e', 'a', 'r', 'l'), 1, 0);
    166 	rug = vocab(DECR('r', 'u', 'g', '\0', '\0'), 1, 0);
    167 	chain = vocab(DECR('c', 'h', 'a', 'i', 'n'), 1, 0);
    168 
    169 	back = vocab(DECR('b', 'a', 'c', 'k', '\0'), 0, 0);
    170 	look = vocab(DECR('l', 'o', 'o', 'k', '\0'), 0, 0);
    171 	cave = vocab(DECR('c', 'a', 'v', 'e', '\0'), 0, 0);
    172 	null = vocab(DECR('n', 'u', 'l', 'l', '\0'), 0, 0);
    173 	entrnc = vocab(DECR('e', 'n', 't', 'r', 'a'), 0, 0);
    174 	dprssn = vocab(DECR('d', 'e', 'p', 'r', 'e'), 0, 0);
    175 	enter = vocab(DECR('e', 'n', 't', 'e', 'r'), 0, 0);
    176 
    177 	pour = vocab(DECR('p', 'o', 'u', 'r', '\0'), 2, 0);
    178 	say = vocab(DECR('s', 'a', 'y', '\0', '\0'), 2, 0);
    179 	lock = vocab(DECR('l', 'o', 'c', 'k', '\0'), 2, 0);
    180 	throw = vocab(DECR('t', 'h', 'r', 'o', 'w'), 2, 0);
    181 	find = vocab(DECR('f', 'i', 'n', 'd', '\0'), 2, 0);
    182 	invent = vocab(DECR('i', 'n', 'v', 'e', 'n'), 2, 0);
    183 
    184 	/* initialize dwarves */
    185 	chloc = 114;
    186 	chloc2 = 140;
    187 	for (i = 1; i <= 6; i++)
    188 		dseen[i] = FALSE;
    189 	dflag = 0;
    190 	dloc[1] = 19;
    191 	dloc[2] = 27;
    192 	dloc[3] = 33;
    193 	dloc[4] = 44;
    194 	dloc[5] = 64;
    195 	dloc[6] = chloc;
    196 	daltlc = 18;
    197 
    198 	/* random flags & ctrs */
    199 	turns = 0;
    200 	lmwarn = FALSE;
    201 	iwest = 0;
    202 	knfloc = 0;
    203 	detail = 0;
    204 	abbnum = 5;
    205 	for (i = 0; i <= 4; i++)
    206 		if (rtext[2 * i + 81].seekadr != 0)
    207 			maxdie = i + 1;
    208 	numdie = holdng = dkill = foobar = bonus = 0;
    209 	clock1 = 30;
    210 	clock2 = 50;
    211 	saved = 0;
    212 	closng = panic = closed = scorng = FALSE;
    213 }
    214 
    215 
    216 
    217 void
    218 trapdel(n)			/* come here if he hits a del */
    219 	int     n;
    220 {
    221 	delhit++;		/* main checks, treats as QUIT */
    222 	signal(SIGINT, trapdel);/* catch subsequent DELs */
    223 }
    224 
    225 
    226 void
    227 startup()
    228 {
    229 	demo = Start(0);
    230 	srand((int) (time((time_t *) NULL)));	/* random seed */
    231 #if 0
    232 	srand(371);		/* non-random seed */
    233 #endif
    234 	hinted[3] = yes(65, 1, 0);
    235 	newloc = 1;
    236 	delhit = 0;
    237 	limit = 330;
    238 	if (hinted[3])
    239 		limit = 1000;	/* better batteries if instrucs */
    240 }
    241