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