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