xref: /original-bsd/games/adventure/init.c (revision ff39075d)
1 /*-
2  * Copyright (c) 1991, 1993 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * The game adventure was originally written in Fortran by Will Crowther
6  * and Don Woods.  It was later translated to C and enhanced by Jim
7  * Gillogly.  This code is derived from software contributed to Berkeley
8  * by Jim Gillogly at The Rand Corporation.
9  *
10  * %sccs.include.redist.c%
11  */
12 
13 /*      Re-coding of advent in C: data initialization                   */
14 
15 #include <sys/types.h>
16 #include <stdio.h>
17 #include "hdr.h"
18 
19 int blklin = TRUE;
20 
21 int setbit[16] = {1,2,4,010,020,040,0100,0200,0400,01000,02000,04000,
22 		  010000,020000,040000,0100000};
23 
24 
25 init(command)                           /* everything for 1st time run  */
26 char *command;                          /* command we were called with  */
27 {
28 	rdata();                        /* read data from orig. file    */
29 	linkdata();
30 	poof();
31 }
32 
33 char *decr(a,b,c,d,e)
34 char a,b,c,d,e;
35 {
36 	static char buf[6];
37 
38 	buf[0] = a-'+';
39 	buf[1] = b-'-';
40 	buf[2] = c-'#';
41 	buf[3] = d-'&';
42 	buf[4] = e-'%';
43 	buf[5] = 0;
44 	return buf;
45 }
46 
47 linkdata()                              /*  secondary data manipulation */
48 {       register int i,j;
49 
50 	/*      array linkages          */
51 	for (i=1; i<=LOCSIZ; i++)
52 		if (ltext[i].seekadr!=0 && travel[i] != 0)
53 			if ((travel[i]->tverb)==1) cond[i]=2;
54 	for (j=100; j>0; j--)
55 		if (fixd[j]>0)
56 		{       drop(j+100,fixd[j]);
57 			drop(j,plac[j]);
58 		}
59 	for (j=100; j>0; j--)
60 	{       fixed[j]=fixd[j];
61 		if (plac[j]!=0 && fixd[j]<=0) drop(j,plac[j]);
62 	}
63 
64 	maxtrs=79;
65 	tally=0;
66 	tally2=0;
67 
68 	for (i=50; i<=maxtrs; i++)
69 	{       if (ptext[i].seekadr!=0) prop[i] = -1;
70 		tally -= prop[i];
71 	}
72 
73 	/* define mnemonics */
74 	keys = vocab(DECR(k,e,y,s,\0), 1);
75 	lamp = vocab(DECR(l,a,m,p,\0), 1);
76 	grate = vocab(DECR(g,r,a,t,e), 1);
77 	cage  = vocab(DECR(c,a,g,e,\0),1);
78 	rod   = vocab(DECR(r,o,d,\0,\0),1);
79 	rod2=rod+1;
80 	steps=vocab(DECR(s,t,e,p,s),1);
81 	bird  = vocab(DECR(b,i,r,d,\0),1);
82 	door  = vocab(DECR(d,o,o,r,\0),1);
83 	pillow= vocab(DECR(p,i,l,l,o), 1);
84 	snake = vocab(DECR(s,n,a,k,e), 1);
85 	fissur= vocab(DECR(f,i,s,s,u), 1);
86 	tablet= vocab(DECR(t,a,b,l,e), 1);
87 	clam  = vocab(DECR(c,l,a,m,\0),1);
88 	oyster= vocab(DECR(o,y,s,t,e), 1);
89 	magzin= vocab(DECR(m,a,g,a,z), 1);
90 	dwarf = vocab(DECR(d,w,a,r,f), 1);
91 	knife = vocab(DECR(k,n,i,f,e), 1);
92 	food  = vocab(DECR(f,o,o,d,\0),1);
93 	bottle= vocab(DECR(b,o,t,t,l), 1);
94 	water = vocab(DECR(w,a,t,e,r), 1);
95 	oil   = vocab(DECR(o,i,l,\0,\0),1);
96 	plant = vocab(DECR(p,l,a,n,t), 1);
97 	plant2=plant+1;
98 	axe   = vocab(DECR(a,x,e,\0,\0),1);
99 	mirror= vocab(DECR(m,i,r,r,o), 1);
100 	dragon= vocab(DECR(d,r,a,g,o), 1);
101 	chasm = vocab(DECR(c,h,a,s,m), 1);
102 	troll = vocab(DECR(t,r,o,l,l), 1);
103 	troll2=troll+1;
104 	bear  = vocab(DECR(b,e,a,r,\0),1);
105 	messag= vocab(DECR(m,e,s,s,a), 1);
106 	vend  = vocab(DECR(v,e,n,d,i), 1);
107 	batter= vocab(DECR(b,a,t,t,e), 1);
108 
109 	nugget= vocab(DECR(g,o,l,d,\0),1);
110 	coins = vocab(DECR(c,o,i,n,s), 1);
111 	chest = vocab(DECR(c,h,e,s,t), 1);
112 	eggs  = vocab(DECR(e,g,g,s,\0),1);
113 	tridnt= vocab(DECR(t,r,i,d,e), 1);
114 	vase  = vocab(DECR(v,a,s,e,\0),1);
115 	emrald= vocab(DECR(e,m,e,r,a), 1);
116 	pyram = vocab(DECR(p,y,r,a,m), 1);
117 	pearl = vocab(DECR(p,e,a,r,l), 1);
118 	rug   = vocab(DECR(r,u,g,\0,\0),1);
119 	chain = vocab(DECR(c,h,a,i,n), 1);
120 
121 	back  = vocab(DECR(b,a,c,k,\0),0);
122 	look  = vocab(DECR(l,o,o,k,\0),0);
123 	cave  = vocab(DECR(c,a,v,e,\0),0);
124 	null  = vocab(DECR(n,u,l,l,\0),0);
125 	entrnc= vocab(DECR(e,n,t,r,a), 0);
126 	dprssn= vocab(DECR(d,e,p,r,e), 0);
127 	enter = vocab(DECR(e,n,t,e,r), 0);
128 
129 	pour  = vocab(DECR(p,o,u,r,\0), 2);
130 	say   = vocab(DECR(s,a,y,\0,\0),2);
131 	lock  = vocab(DECR(l,o,c,k,\0),2);
132 	throw = vocab(DECR(t,h,r,o,w), 2);
133 	find  = vocab(DECR(f,i,n,d,\0),2);
134 	invent= vocab(DECR(i,n,v,e,n), 2);
135 
136 	/* initialize dwarves */
137 	chloc=114;
138 	chloc2=140;
139 	for (i=1; i<=6; i++)
140 		dseen[i]=FALSE;
141 	dflag=0;
142 	dloc[1]=19;
143 	dloc[2]=27;
144 	dloc[3]=33;
145 	dloc[4]=44;
146 	dloc[5]=64;
147 	dloc[6]=chloc;
148 	daltlc=18;
149 
150 	/* random flags & ctrs */
151 	turns=0;
152 	lmwarn=FALSE;
153 	iwest=0;
154 	knfloc=0;
155 	detail=0;
156 	abbnum=5;
157 	for (i=0; i<=4; i++)
158 		if (rtext[2*i+81].seekadr!=0) maxdie=i+1;
159 	numdie=holdng=dkill=foobar=bonus=0;
160 	clock1=30;
161 	clock2=50;
162 	saved=0;
163 	closng=panic=closed=scorng=FALSE;
164 }
165 
166 
167 
168 trapdel()                               /* come here if he hits a del   */
169 {	delhit++;			/* main checks, treats as QUIT  */
170 	signal(2,trapdel);		/* catch subsequent DELs        */
171 }
172 
173 
174 startup()
175 {
176 	time_t time();
177 
178 	demo=start(0);
179 	srand((int)(time((time_t *)NULL)));	/* random seed */
180 	/* srand(371);				/* non-random seed */
181 	hinted[3]=yes(65,1,0);
182 	newloc=1;
183 	delhit = 0;
184 	limit=330;
185 	if (hinted[3]) limit=1000;      /* better batteries if instrucs */
186 }
187