xref: /minix3/games/adventure/subr.c (revision 0819c9f89b6d110be1d10f1cda48f41db00ca70f)
1*0819c9f8SThomas Cort /*	$NetBSD: subr.c,v 1.13 2009/08/25 06:56:52 dholland Exp $	*/
2*0819c9f8SThomas Cort 
3*0819c9f8SThomas Cort /*-
4*0819c9f8SThomas Cort  * Copyright (c) 1991, 1993
5*0819c9f8SThomas Cort  *	The Regents of the University of California.  All rights reserved.
6*0819c9f8SThomas Cort  *
7*0819c9f8SThomas Cort  * The game adventure was originally written in Fortran by Will Crowther
8*0819c9f8SThomas Cort  * and Don Woods.  It was later translated to C and enhanced by Jim
9*0819c9f8SThomas Cort  * Gillogly.  This code is derived from software contributed to Berkeley
10*0819c9f8SThomas Cort  * by Jim Gillogly at The Rand Corporation.
11*0819c9f8SThomas Cort  *
12*0819c9f8SThomas Cort  * Redistribution and use in source and binary forms, with or without
13*0819c9f8SThomas Cort  * modification, are permitted provided that the following conditions
14*0819c9f8SThomas Cort  * are met:
15*0819c9f8SThomas Cort  * 1. Redistributions of source code must retain the above copyright
16*0819c9f8SThomas Cort  *    notice, this list of conditions and the following disclaimer.
17*0819c9f8SThomas Cort  * 2. Redistributions in binary form must reproduce the above copyright
18*0819c9f8SThomas Cort  *    notice, this list of conditions and the following disclaimer in the
19*0819c9f8SThomas Cort  *    documentation and/or other materials provided with the distribution.
20*0819c9f8SThomas Cort  * 3. Neither the name of the University nor the names of its contributors
21*0819c9f8SThomas Cort  *    may be used to endorse or promote products derived from this software
22*0819c9f8SThomas Cort  *    without specific prior written permission.
23*0819c9f8SThomas Cort  *
24*0819c9f8SThomas Cort  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25*0819c9f8SThomas Cort  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26*0819c9f8SThomas Cort  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27*0819c9f8SThomas Cort  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28*0819c9f8SThomas Cort  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29*0819c9f8SThomas Cort  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30*0819c9f8SThomas Cort  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31*0819c9f8SThomas Cort  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32*0819c9f8SThomas Cort  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33*0819c9f8SThomas Cort  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34*0819c9f8SThomas Cort  * SUCH DAMAGE.
35*0819c9f8SThomas Cort  */
36*0819c9f8SThomas Cort 
37*0819c9f8SThomas Cort #include <sys/cdefs.h>
38*0819c9f8SThomas Cort #ifndef lint
39*0819c9f8SThomas Cort #if 0
40*0819c9f8SThomas Cort static char sccsid[] = "@(#)subr.c	8.1 (Berkeley) 5/31/93";
41*0819c9f8SThomas Cort #else
42*0819c9f8SThomas Cort __RCSID("$NetBSD: subr.c,v 1.13 2009/08/25 06:56:52 dholland Exp $");
43*0819c9f8SThomas Cort #endif
44*0819c9f8SThomas Cort #endif				/* not lint */
45*0819c9f8SThomas Cort 
46*0819c9f8SThomas Cort /*      Re-coding of advent in C: subroutines from main                 */
47*0819c9f8SThomas Cort 
48*0819c9f8SThomas Cort #include <stdio.h>
49*0819c9f8SThomas Cort #include <stdlib.h>
50*0819c9f8SThomas Cort #include "hdr.h"
51*0819c9f8SThomas Cort #include "extern.h"
52*0819c9f8SThomas Cort 
53*0819c9f8SThomas Cort static void badmove(void);
54*0819c9f8SThomas Cort static int bitset(int, int);
55*0819c9f8SThomas Cort static int dropper(void);
56*0819c9f8SThomas Cort static int liq2(int);
57*0819c9f8SThomas Cort static int mback(void);
58*0819c9f8SThomas Cort static int specials(void);
59*0819c9f8SThomas Cort static int trbridge(void);
60*0819c9f8SThomas Cort 
61*0819c9f8SThomas Cort /*              Statement functions     */
62*0819c9f8SThomas Cort int
toting(int objj)63*0819c9f8SThomas Cort toting(int objj)
64*0819c9f8SThomas Cort {
65*0819c9f8SThomas Cort 	if (place[objj] == -1)
66*0819c9f8SThomas Cort 		return (TRUE);
67*0819c9f8SThomas Cort 	else
68*0819c9f8SThomas Cort 		return (FALSE);
69*0819c9f8SThomas Cort }
70*0819c9f8SThomas Cort 
71*0819c9f8SThomas Cort int
here(int objj)72*0819c9f8SThomas Cort here(int objj)
73*0819c9f8SThomas Cort {
74*0819c9f8SThomas Cort 	if (place[objj] == loc || toting(objj))
75*0819c9f8SThomas Cort 		return (TRUE);
76*0819c9f8SThomas Cort 	else
77*0819c9f8SThomas Cort 		return (FALSE);
78*0819c9f8SThomas Cort }
79*0819c9f8SThomas Cort 
80*0819c9f8SThomas Cort int
at(int objj)81*0819c9f8SThomas Cort at(int objj)
82*0819c9f8SThomas Cort {
83*0819c9f8SThomas Cort 	if (place[objj] == loc || fixed[objj] == loc)
84*0819c9f8SThomas Cort 		return (TRUE);
85*0819c9f8SThomas Cort 	else
86*0819c9f8SThomas Cort 		return (FALSE);
87*0819c9f8SThomas Cort }
88*0819c9f8SThomas Cort 
89*0819c9f8SThomas Cort static int
liq2(int pbotl)90*0819c9f8SThomas Cort liq2(int pbotl)
91*0819c9f8SThomas Cort {
92*0819c9f8SThomas Cort 	return ((1 - pbotl) * water + (pbotl / 2) * (water + oil));
93*0819c9f8SThomas Cort }
94*0819c9f8SThomas Cort 
95*0819c9f8SThomas Cort int
liq(void)96*0819c9f8SThomas Cort liq(void)
97*0819c9f8SThomas Cort {
98*0819c9f8SThomas Cort 	int     i;
99*0819c9f8SThomas Cort 	i = prop[bottle];
100*0819c9f8SThomas Cort 	if (i > -1 - i)
101*0819c9f8SThomas Cort 		return (liq2(i));
102*0819c9f8SThomas Cort 	else
103*0819c9f8SThomas Cort 		return (liq2(-1 - i));
104*0819c9f8SThomas Cort }
105*0819c9f8SThomas Cort 
106*0819c9f8SThomas Cort /* may want to clean this one up a bit */
107*0819c9f8SThomas Cort int
liqloc(int locc)108*0819c9f8SThomas Cort liqloc(int locc)
109*0819c9f8SThomas Cort {
110*0819c9f8SThomas Cort 	int     i, j, l;
111*0819c9f8SThomas Cort 	i = cond[locc] / 2;
112*0819c9f8SThomas Cort 	j = ((i * 2) % 8) - 5;
113*0819c9f8SThomas Cort 	l = cond[locc] / 4;
114*0819c9f8SThomas Cort 	l = l % 2;
115*0819c9f8SThomas Cort 	return (liq2(j * l + 1));
116*0819c9f8SThomas Cort }
117*0819c9f8SThomas Cort 
118*0819c9f8SThomas Cort static int
bitset(int l,int n)119*0819c9f8SThomas Cort bitset(int l, int n)
120*0819c9f8SThomas Cort {
121*0819c9f8SThomas Cort 	if (cond[l] & setbit[n])
122*0819c9f8SThomas Cort 		return (TRUE);
123*0819c9f8SThomas Cort 	return (FALSE);
124*0819c9f8SThomas Cort }
125*0819c9f8SThomas Cort 
126*0819c9f8SThomas Cort int
forced(int locc)127*0819c9f8SThomas Cort forced(int locc)
128*0819c9f8SThomas Cort {
129*0819c9f8SThomas Cort 	if (cond[locc] == 2)
130*0819c9f8SThomas Cort 		return (TRUE);
131*0819c9f8SThomas Cort 	return (FALSE);
132*0819c9f8SThomas Cort }
133*0819c9f8SThomas Cort 
134*0819c9f8SThomas Cort int
dark(void)135*0819c9f8SThomas Cort dark(void)
136*0819c9f8SThomas Cort {
137*0819c9f8SThomas Cort 	if ((cond[loc] % 2) == 0 && (prop[lamp] == 0 || !here(lamp)))
138*0819c9f8SThomas Cort 		return (TRUE);
139*0819c9f8SThomas Cort 	return (FALSE);
140*0819c9f8SThomas Cort }
141*0819c9f8SThomas Cort 
142*0819c9f8SThomas Cort int
pct(int n)143*0819c9f8SThomas Cort pct(int n)
144*0819c9f8SThomas Cort {
145*0819c9f8SThomas Cort 	if (ran(100) < n)
146*0819c9f8SThomas Cort 		return (TRUE);
147*0819c9f8SThomas Cort 	return (FALSE);
148*0819c9f8SThomas Cort }
149*0819c9f8SThomas Cort 
150*0819c9f8SThomas Cort 
151*0819c9f8SThomas Cort int
fdwarf(void)152*0819c9f8SThomas Cort fdwarf(void)
153*0819c9f8SThomas Cort {				/* 71 */
154*0819c9f8SThomas Cort 	int     i, j;
155*0819c9f8SThomas Cort 	struct travlist *kk;
156*0819c9f8SThomas Cort 
157*0819c9f8SThomas Cort 	if (newloc != loc && !forced(loc) && !bitset(loc, 3)) {
158*0819c9f8SThomas Cort 		for (i = 1; i <= 5; i++) {
159*0819c9f8SThomas Cort 			if (odloc[i] != newloc || !dseen[i])
160*0819c9f8SThomas Cort 				continue;
161*0819c9f8SThomas Cort 			newloc = loc;
162*0819c9f8SThomas Cort 			rspeak(2);
163*0819c9f8SThomas Cort 			break;
164*0819c9f8SThomas Cort 		}
165*0819c9f8SThomas Cort 	}
166*0819c9f8SThomas Cort 	loc = newloc;		/* 74 */
167*0819c9f8SThomas Cort 	if (loc == 0 || forced(loc) || bitset(newloc, 3))
168*0819c9f8SThomas Cort 		return (2000);
169*0819c9f8SThomas Cort 	if (dflag == 0) {
170*0819c9f8SThomas Cort 		if (loc >= 15)
171*0819c9f8SThomas Cort 			dflag = 1;
172*0819c9f8SThomas Cort 		return (2000);
173*0819c9f8SThomas Cort 	}
174*0819c9f8SThomas Cort 	if (dflag == 1) {	/* 6000 */
175*0819c9f8SThomas Cort 		if (loc < 15 || pct(95))
176*0819c9f8SThomas Cort 			return (2000);
177*0819c9f8SThomas Cort 		dflag = 2;
178*0819c9f8SThomas Cort 		for (i = 1; i <= 2; i++) {
179*0819c9f8SThomas Cort 			j = 1 + ran(5);
180*0819c9f8SThomas Cort 			if (pct(50) && saved == -1)
181*0819c9f8SThomas Cort 				dloc[j] = 0;	/* 6001 */
182*0819c9f8SThomas Cort 		}
183*0819c9f8SThomas Cort 		for (i = 1; i <= 5; i++) {
184*0819c9f8SThomas Cort 			if (dloc[i] == loc)
185*0819c9f8SThomas Cort 				dloc[i] = daltloc;
186*0819c9f8SThomas Cort 			odloc[i] = dloc[i];	/* 6002 */
187*0819c9f8SThomas Cort 		}
188*0819c9f8SThomas Cort 		rspeak(3);
189*0819c9f8SThomas Cort 		drop(axe, loc);
190*0819c9f8SThomas Cort 		return (2000);
191*0819c9f8SThomas Cort 	}
192*0819c9f8SThomas Cort 	dtotal = attack = stick = 0;	/* 6010 */
193*0819c9f8SThomas Cort 	for (i = 1; i <= 6; i++) {	/* loop to 6030 */
194*0819c9f8SThomas Cort 		if (dloc[i] == 0)
195*0819c9f8SThomas Cort 			continue;
196*0819c9f8SThomas Cort 		j = 1;
197*0819c9f8SThomas Cort 		for (kk = travel[dloc[i]]; kk != 0; kk = kk->next) {
198*0819c9f8SThomas Cort 			newloc = kk->tloc;
199*0819c9f8SThomas Cort 			if (newloc > 300 || newloc < 15 || newloc == odloc[i]
200*0819c9f8SThomas Cort 			    || (j > 1 && newloc == tk[j - 1]) || j >= 20
201*0819c9f8SThomas Cort 			    || newloc == dloc[i] || forced(newloc)
202*0819c9f8SThomas Cort 			    || (i == 6 && bitset(newloc, 3))
203*0819c9f8SThomas Cort 			    || kk->conditions == 100)
204*0819c9f8SThomas Cort 				continue;
205*0819c9f8SThomas Cort 			tk[j++] = newloc;
206*0819c9f8SThomas Cort 		}
207*0819c9f8SThomas Cort 		tk[j] = odloc[i];	/* 6016 */
208*0819c9f8SThomas Cort 		if (j >= 2)
209*0819c9f8SThomas Cort 			j--;
210*0819c9f8SThomas Cort 		j = 1 + ran(j);
211*0819c9f8SThomas Cort 		odloc[i] = dloc[i];
212*0819c9f8SThomas Cort 		dloc[i] = tk[j];
213*0819c9f8SThomas Cort 		dseen[i] = (dseen[i] && loc >= 15) ||
214*0819c9f8SThomas Cort 		    (dloc[i] == loc || odloc[i] == loc);
215*0819c9f8SThomas Cort 		if (!dseen[i])
216*0819c9f8SThomas Cort 			continue;	/* i.e. goto 6030 */
217*0819c9f8SThomas Cort 		dloc[i] = loc;
218*0819c9f8SThomas Cort 		if (i == 6) {	/* pirate's spotted him */
219*0819c9f8SThomas Cort 			if (loc == chloc || prop[chest] >= 0)
220*0819c9f8SThomas Cort 				continue;
221*0819c9f8SThomas Cort 			k = 0;
222*0819c9f8SThomas Cort 			for (j = 50; j <= maxtrs; j++) { /* loop to 6020 */
223*0819c9f8SThomas Cort 				if (j == pyramid && (loc == plac[pyramid]
224*0819c9f8SThomas Cort 					|| loc == plac[emerald]))
225*0819c9f8SThomas Cort 					goto l6020;
226*0819c9f8SThomas Cort 				if (toting(j))
227*0819c9f8SThomas Cort 					goto l6022;
228*0819c9f8SThomas Cort 		l6020:		if (here(j))
229*0819c9f8SThomas Cort 					k = 1;
230*0819c9f8SThomas Cort 			}	/* 6020 */
231*0819c9f8SThomas Cort 			if (tally == tally2 + 1 && k == 0 && place[chest] == 0
232*0819c9f8SThomas Cort 			    && here(lamp) && prop[lamp] == 1)
233*0819c9f8SThomas Cort 				goto l6025;
234*0819c9f8SThomas Cort 			if (odloc[6] != dloc[6] && pct(20))
235*0819c9f8SThomas Cort 				rspeak(127);
236*0819c9f8SThomas Cort 			continue;	/* to 6030 */
237*0819c9f8SThomas Cort 	l6022:		rspeak(128);
238*0819c9f8SThomas Cort 			if (place[message] == 0)
239*0819c9f8SThomas Cort 				move(chest, chloc);
240*0819c9f8SThomas Cort 			move(message, chloc2);
241*0819c9f8SThomas Cort 			for (j = 50; j <= maxtrs; j++) { /* loop to 6023 */
242*0819c9f8SThomas Cort 				if (j == pyramid && (loc == plac[pyramid]
243*0819c9f8SThomas Cort 					|| loc == plac[emerald]))
244*0819c9f8SThomas Cort 					continue;
245*0819c9f8SThomas Cort 				if (at(j) && fixed[j] == 0)
246*0819c9f8SThomas Cort 					carry(j, loc);
247*0819c9f8SThomas Cort 				if (toting(j))
248*0819c9f8SThomas Cort 					drop(j, chloc);
249*0819c9f8SThomas Cort 			}
250*0819c9f8SThomas Cort 	l6024:		dloc[6] = odloc[6] = chloc;
251*0819c9f8SThomas Cort 			dseen[6] = FALSE;
252*0819c9f8SThomas Cort 			continue;
253*0819c9f8SThomas Cort 	l6025:		rspeak(186);
254*0819c9f8SThomas Cort 			move(chest, chloc);
255*0819c9f8SThomas Cort 			move(message, chloc2);
256*0819c9f8SThomas Cort 			goto l6024;
257*0819c9f8SThomas Cort 		}
258*0819c9f8SThomas Cort 		dtotal++;	/* 6027 */
259*0819c9f8SThomas Cort 		if (odloc[i] != dloc[i])
260*0819c9f8SThomas Cort 			continue;
261*0819c9f8SThomas Cort 		attack++;
262*0819c9f8SThomas Cort 		if (knfloc >= 0)
263*0819c9f8SThomas Cort 			knfloc = loc;
264*0819c9f8SThomas Cort 		if (ran(1000) < 95 * (dflag - 2))
265*0819c9f8SThomas Cort 			stick++;
266*0819c9f8SThomas Cort 	}			/* 6030 */
267*0819c9f8SThomas Cort 	if (dtotal == 0)
268*0819c9f8SThomas Cort 		return (2000);
269*0819c9f8SThomas Cort 	if (dtotal != 1) {
270*0819c9f8SThomas Cort 		printf("There are %d threatening little dwarves ", dtotal);
271*0819c9f8SThomas Cort 		printf("in the room with you.\n");
272*0819c9f8SThomas Cort 	} else
273*0819c9f8SThomas Cort 		rspeak(4);
274*0819c9f8SThomas Cort 	if (attack == 0)
275*0819c9f8SThomas Cort 		return (2000);
276*0819c9f8SThomas Cort 	if (dflag == 2)
277*0819c9f8SThomas Cort 		dflag = 3;
278*0819c9f8SThomas Cort 	if (saved != -1)
279*0819c9f8SThomas Cort 		dflag = 20;
280*0819c9f8SThomas Cort 	if (attack != 1) {
281*0819c9f8SThomas Cort 		printf("%d of them throw knives at you!\n", attack);
282*0819c9f8SThomas Cort 		k = 6;
283*0819c9f8SThomas Cort l82:		if (stick <= 1) {	/* 82 */
284*0819c9f8SThomas Cort 			rspeak(k + stick);
285*0819c9f8SThomas Cort 			if (stick == 0)
286*0819c9f8SThomas Cort 				return (2000);
287*0819c9f8SThomas Cort 		} else
288*0819c9f8SThomas Cort 			printf("%d of them get you!\n", stick);	/* 83 */
289*0819c9f8SThomas Cort 		oldloc2 = loc;
290*0819c9f8SThomas Cort 		return (99);
291*0819c9f8SThomas Cort 	}
292*0819c9f8SThomas Cort 	rspeak(5);
293*0819c9f8SThomas Cort 	k = 52;
294*0819c9f8SThomas Cort 	goto l82;
295*0819c9f8SThomas Cort }
296*0819c9f8SThomas Cort 
297*0819c9f8SThomas Cort 
298*0819c9f8SThomas Cort /* label 8              */
299*0819c9f8SThomas Cort int
march(void)300*0819c9f8SThomas Cort march(void)
301*0819c9f8SThomas Cort {
302*0819c9f8SThomas Cort 	int     ll1, ll2;
303*0819c9f8SThomas Cort 
304*0819c9f8SThomas Cort 	if ((tkk = travel[newloc = loc]) == 0)
305*0819c9f8SThomas Cort 		bug(26);
306*0819c9f8SThomas Cort 	if (k == null)
307*0819c9f8SThomas Cort 		return (2);
308*0819c9f8SThomas Cort 	if (k == cave) {	/* 40                   */
309*0819c9f8SThomas Cort 		if (loc < 8)
310*0819c9f8SThomas Cort 			rspeak(57);
311*0819c9f8SThomas Cort 		if (loc >= 8)
312*0819c9f8SThomas Cort 			rspeak(58);
313*0819c9f8SThomas Cort 		return (2);
314*0819c9f8SThomas Cort 	}
315*0819c9f8SThomas Cort 	if (k == look) {	/* 30                   */
316*0819c9f8SThomas Cort 		if (detail++ < 3)
317*0819c9f8SThomas Cort 			rspeak(15);
318*0819c9f8SThomas Cort 		wasdark = FALSE;
319*0819c9f8SThomas Cort 		abb[loc] = 0;
320*0819c9f8SThomas Cort 		return (2);
321*0819c9f8SThomas Cort 	}
322*0819c9f8SThomas Cort 	if (k == back) {	/* 20                   */
323*0819c9f8SThomas Cort 		switch (mback()) {
324*0819c9f8SThomas Cort 		case 2:
325*0819c9f8SThomas Cort 			return (2);
326*0819c9f8SThomas Cort 		case 9:
327*0819c9f8SThomas Cort 			goto l9;
328*0819c9f8SThomas Cort 		default:
329*0819c9f8SThomas Cort 			bug(100);
330*0819c9f8SThomas Cort 		}
331*0819c9f8SThomas Cort 	}
332*0819c9f8SThomas Cort 	oldloc2 = oldloc;
333*0819c9f8SThomas Cort 	oldloc = loc;
334*0819c9f8SThomas Cort l9:
335*0819c9f8SThomas Cort 	for (; tkk != 0; tkk = tkk->next)
336*0819c9f8SThomas Cort 		if (tkk->tverb == 1 || tkk->tverb == k)
337*0819c9f8SThomas Cort 			break;
338*0819c9f8SThomas Cort 	if (tkk == 0) {
339*0819c9f8SThomas Cort 		badmove();
340*0819c9f8SThomas Cort 		return (2);
341*0819c9f8SThomas Cort 	}
342*0819c9f8SThomas Cort l11:	ll1 = tkk->conditions;	/* 11                   */
343*0819c9f8SThomas Cort 	ll2 = tkk->tloc;
344*0819c9f8SThomas Cort 	newloc = ll1;		/* newloc=conditions    */
345*0819c9f8SThomas Cort 	k = newloc % 100;	/* k used for prob      */
346*0819c9f8SThomas Cort 	if (newloc <= 300) {
347*0819c9f8SThomas Cort 		if (newloc <= 100) {	/* 13                   */
348*0819c9f8SThomas Cort 			if (newloc != 0 && !pct(newloc))
349*0819c9f8SThomas Cort 				goto l12;	/* 14   */
350*0819c9f8SThomas Cort 	l16:		newloc = ll2;	/* newloc=location      */
351*0819c9f8SThomas Cort 			if (newloc <= 300)
352*0819c9f8SThomas Cort 				return (2);
353*0819c9f8SThomas Cort 			if (newloc <= 500)
354*0819c9f8SThomas Cort 				switch (specials()) {	/* to 30000           */
355*0819c9f8SThomas Cort 				case 2:
356*0819c9f8SThomas Cort 					return (2);
357*0819c9f8SThomas Cort 				case 12:
358*0819c9f8SThomas Cort 					goto l12;
359*0819c9f8SThomas Cort 				case 99:
360*0819c9f8SThomas Cort 					return (99);
361*0819c9f8SThomas Cort 				default:
362*0819c9f8SThomas Cort 					bug(101);
363*0819c9f8SThomas Cort 				}
364*0819c9f8SThomas Cort 			rspeak(newloc - 500);
365*0819c9f8SThomas Cort 			newloc = loc;
366*0819c9f8SThomas Cort 			return (2);
367*0819c9f8SThomas Cort 		}
368*0819c9f8SThomas Cort 		if (toting(k) || (newloc > 200 && at(k)))
369*0819c9f8SThomas Cort 			goto l16;
370*0819c9f8SThomas Cort 		goto l12;
371*0819c9f8SThomas Cort 	}
372*0819c9f8SThomas Cort 	if (prop[k] != (newloc / 100) - 3)
373*0819c9f8SThomas Cort 		goto l16;	/* newloc still conditions */
374*0819c9f8SThomas Cort l12:				/* alternative to probability move      */
375*0819c9f8SThomas Cort 	for (; tkk != 0; tkk = tkk->next)
376*0819c9f8SThomas Cort 		if (tkk->tloc != ll2 || tkk->conditions != ll1)
377*0819c9f8SThomas Cort 			break;
378*0819c9f8SThomas Cort 	if (tkk == 0)
379*0819c9f8SThomas Cort 		bug(25);
380*0819c9f8SThomas Cort 	goto l11;
381*0819c9f8SThomas Cort }
382*0819c9f8SThomas Cort 
383*0819c9f8SThomas Cort /* 20                   */
384*0819c9f8SThomas Cort static int
mback(void)385*0819c9f8SThomas Cort mback(void)
386*0819c9f8SThomas Cort {
387*0819c9f8SThomas Cort 	struct travlist *tk2, *j;
388*0819c9f8SThomas Cort 	int     ll;
389*0819c9f8SThomas Cort 	if (forced(k = oldloc))
390*0819c9f8SThomas Cort 		k = oldloc2;	/* k=location           */
391*0819c9f8SThomas Cort 	oldloc2 = oldloc;
392*0819c9f8SThomas Cort 	oldloc = loc;
393*0819c9f8SThomas Cort 	tk2 = 0;
394*0819c9f8SThomas Cort 	if (k == loc) {
395*0819c9f8SThomas Cort 		rspeak(91);
396*0819c9f8SThomas Cort 		return (2);
397*0819c9f8SThomas Cort 	}
398*0819c9f8SThomas Cort 	for (; tkk != 0; tkk = tkk->next) {	/* 21                   */
399*0819c9f8SThomas Cort 		ll = tkk->tloc;
400*0819c9f8SThomas Cort 		if (ll == k) {
401*0819c9f8SThomas Cort 			k = tkk->tverb;	/* k back to verb       */
402*0819c9f8SThomas Cort 			tkk = travel[loc];
403*0819c9f8SThomas Cort 			return (9);
404*0819c9f8SThomas Cort 		}
405*0819c9f8SThomas Cort 		if (ll <= 300) {
406*0819c9f8SThomas Cort 			j = travel[loc];
407*0819c9f8SThomas Cort 			if (forced(ll) && k == j->tloc)
408*0819c9f8SThomas Cort 				tk2 = tkk;
409*0819c9f8SThomas Cort 		}
410*0819c9f8SThomas Cort 	}
411*0819c9f8SThomas Cort 	tkk = tk2;		/* 23                   */
412*0819c9f8SThomas Cort 	if (tkk != 0) {
413*0819c9f8SThomas Cort 		k = tkk->tverb;
414*0819c9f8SThomas Cort 		tkk = travel[loc];
415*0819c9f8SThomas Cort 		return (9);
416*0819c9f8SThomas Cort 	}
417*0819c9f8SThomas Cort 	rspeak(140);
418*0819c9f8SThomas Cort 	return (2);
419*0819c9f8SThomas Cort }
420*0819c9f8SThomas Cort 
421*0819c9f8SThomas Cort /* 30000                */
422*0819c9f8SThomas Cort static int
specials(void)423*0819c9f8SThomas Cort specials(void)
424*0819c9f8SThomas Cort {
425*0819c9f8SThomas Cort 	switch (newloc -= 300) {
426*0819c9f8SThomas Cort 		case 1:		/* 30100                */
427*0819c9f8SThomas Cort 		newloc = 99 + 100 - loc;
428*0819c9f8SThomas Cort 		if (holding == 0 || (holding == 1 && toting(emerald)))
429*0819c9f8SThomas Cort 			return (2);
430*0819c9f8SThomas Cort 		newloc = loc;
431*0819c9f8SThomas Cort 		rspeak(117);
432*0819c9f8SThomas Cort 		return (2);
433*0819c9f8SThomas Cort 	case 2:		/* 30200                */
434*0819c9f8SThomas Cort 		drop(emerald, loc);
435*0819c9f8SThomas Cort 		return (12);
436*0819c9f8SThomas Cort 	case 3:		/* to 30300             */
437*0819c9f8SThomas Cort 		return (trbridge());
438*0819c9f8SThomas Cort 	default:
439*0819c9f8SThomas Cort 		bug(29);
440*0819c9f8SThomas Cort 	}
441*0819c9f8SThomas Cort }
442*0819c9f8SThomas Cort 
443*0819c9f8SThomas Cort /* 30300                */
444*0819c9f8SThomas Cort static int
trbridge(void)445*0819c9f8SThomas Cort trbridge(void)
446*0819c9f8SThomas Cort {
447*0819c9f8SThomas Cort 	if (prop[troll] == 1) {
448*0819c9f8SThomas Cort 		pspeak(troll, 1);
449*0819c9f8SThomas Cort 		prop[troll] = 0;
450*0819c9f8SThomas Cort 		move(troll2, 0);
451*0819c9f8SThomas Cort 		move(troll2 + 100, 0);
452*0819c9f8SThomas Cort 		move(troll, plac[troll]);
453*0819c9f8SThomas Cort 		move(troll + 100, fixd[troll]);
454*0819c9f8SThomas Cort 		juggle(chasm);
455*0819c9f8SThomas Cort 		newloc = loc;
456*0819c9f8SThomas Cort 		return (2);
457*0819c9f8SThomas Cort 	}
458*0819c9f8SThomas Cort 	newloc = plac[troll] + fixd[troll] - loc;	/* 30310    */
459*0819c9f8SThomas Cort 	if (prop[troll] == 0)
460*0819c9f8SThomas Cort 		prop[troll] = 1;
461*0819c9f8SThomas Cort 	if (!toting(bear))
462*0819c9f8SThomas Cort 		return (2);
463*0819c9f8SThomas Cort 	rspeak(162);
464*0819c9f8SThomas Cort 	prop[chasm] = 1;
465*0819c9f8SThomas Cort 	prop[troll] = 2;
466*0819c9f8SThomas Cort 	drop(bear, newloc);
467*0819c9f8SThomas Cort 	fixed[bear] = -1;
468*0819c9f8SThomas Cort 	prop[bear] = 3;
469*0819c9f8SThomas Cort 	if (prop[spices] < 0)
470*0819c9f8SThomas Cort 		tally2++;
471*0819c9f8SThomas Cort 	oldloc2 = newloc;
472*0819c9f8SThomas Cort 	return (99);
473*0819c9f8SThomas Cort }
474*0819c9f8SThomas Cort 
475*0819c9f8SThomas Cort /* 20                   */
476*0819c9f8SThomas Cort static void
badmove(void)477*0819c9f8SThomas Cort badmove(void)
478*0819c9f8SThomas Cort {
479*0819c9f8SThomas Cort 	spk = 12;
480*0819c9f8SThomas Cort 	if (k >= 43 && k <= 50)
481*0819c9f8SThomas Cort 		spk = 9;
482*0819c9f8SThomas Cort 	if (k == 29 || k == 30)
483*0819c9f8SThomas Cort 		spk = 9;
484*0819c9f8SThomas Cort 	if (k == 7 || k == 36 || k == 37)
485*0819c9f8SThomas Cort 		spk = 10;
486*0819c9f8SThomas Cort 	if (k == 11 || k == 19)
487*0819c9f8SThomas Cort 		spk = 11;
488*0819c9f8SThomas Cort 	if (verb == find || verb == invent)
489*0819c9f8SThomas Cort 		spk = 59;
490*0819c9f8SThomas Cort 	if (k == 62 || k == 65)
491*0819c9f8SThomas Cort 		spk = 42;
492*0819c9f8SThomas Cort 	if (k == 17)
493*0819c9f8SThomas Cort 		spk = 80;
494*0819c9f8SThomas Cort 	rspeak(spk);
495*0819c9f8SThomas Cort }
496*0819c9f8SThomas Cort 
497*0819c9f8SThomas Cort void
bug(int n)498*0819c9f8SThomas Cort bug(int n)
499*0819c9f8SThomas Cort {
500*0819c9f8SThomas Cort 	printf("Please tell jim@rand.org that fatal bug %d happened.\n", n);
501*0819c9f8SThomas Cort 	exit(1);
502*0819c9f8SThomas Cort }
503*0819c9f8SThomas Cort 
504*0819c9f8SThomas Cort /* 2600 &c              */
505*0819c9f8SThomas Cort void
checkhints(void)506*0819c9f8SThomas Cort checkhints(void)
507*0819c9f8SThomas Cort {
508*0819c9f8SThomas Cort 	int     hint;
509*0819c9f8SThomas Cort 	for (hint = 4; hint <= hintmax; hint++) {
510*0819c9f8SThomas Cort 		if (hinted[hint])
511*0819c9f8SThomas Cort 			continue;
512*0819c9f8SThomas Cort 		if (!bitset(loc, hint))
513*0819c9f8SThomas Cort 			hintlc[hint] = -1;
514*0819c9f8SThomas Cort 		hintlc[hint]++;
515*0819c9f8SThomas Cort 		if (hintlc[hint] < hints[hint][1])
516*0819c9f8SThomas Cort 			continue;
517*0819c9f8SThomas Cort 		switch (hint) {
518*0819c9f8SThomas Cort 		case 4:	/* 40400 */
519*0819c9f8SThomas Cort 			if (prop[grate] == 0 && !here(keys))
520*0819c9f8SThomas Cort 				goto l40010;
521*0819c9f8SThomas Cort 			goto l40020;
522*0819c9f8SThomas Cort 		case 5:	/* 40500 */
523*0819c9f8SThomas Cort 			if (here(bird) && toting(rod) && obj == bird)
524*0819c9f8SThomas Cort 				goto l40010;
525*0819c9f8SThomas Cort 			continue;	/* i.e. goto l40030 */
526*0819c9f8SThomas Cort 		case 6:	/* 40600 */
527*0819c9f8SThomas Cort 			if (here(snake) && !here(bird))
528*0819c9f8SThomas Cort 				goto l40010;
529*0819c9f8SThomas Cort 			goto l40020;
530*0819c9f8SThomas Cort 		case 7:	/* 40700 */
531*0819c9f8SThomas Cort 			if (atloc[loc] == 0 && atloc[oldloc] == 0
532*0819c9f8SThomas Cort 			    && atloc[oldloc2] == 0 && holding > 1)
533*0819c9f8SThomas Cort 				goto l40010;
534*0819c9f8SThomas Cort 			goto l40020;
535*0819c9f8SThomas Cort 		case 8:	/* 40800 */
536*0819c9f8SThomas Cort 			if (prop[emerald] != -1 && prop[pyramid] == -1)
537*0819c9f8SThomas Cort 				goto l40010;
538*0819c9f8SThomas Cort 			goto l40020;
539*0819c9f8SThomas Cort 		case 9:
540*0819c9f8SThomas Cort 			goto l40010;	/* 40900 */
541*0819c9f8SThomas Cort 		default:
542*0819c9f8SThomas Cort 			bug(27);
543*0819c9f8SThomas Cort 		}
544*0819c9f8SThomas Cort l40010:	hintlc[hint] = 0;
545*0819c9f8SThomas Cort 		if (!yes(hints[hint][3], 0, 54))
546*0819c9f8SThomas Cort 			continue;
547*0819c9f8SThomas Cort 		printf("I am prepared to give you a hint, but it will ");
548*0819c9f8SThomas Cort 		printf("cost you %d points.\n", hints[hint][2]);
549*0819c9f8SThomas Cort 		hinted[hint] = yes(175, hints[hint][4], 54);
550*0819c9f8SThomas Cort l40020:	hintlc[hint] = 0;
551*0819c9f8SThomas Cort 	}
552*0819c9f8SThomas Cort }
553*0819c9f8SThomas Cort 
554*0819c9f8SThomas Cort /* 9030                 */
555*0819c9f8SThomas Cort int
trsay(void)556*0819c9f8SThomas Cort trsay(void)
557*0819c9f8SThomas Cort {
558*0819c9f8SThomas Cort 	int     i;
559*0819c9f8SThomas Cort 	if (*wd2 != 0)
560*0819c9f8SThomas Cort 		copystr(wd2, wd1);
561*0819c9f8SThomas Cort 	i = vocab(wd1, -1, 0);
562*0819c9f8SThomas Cort 	if (i == 62 || i == 65 || i == 71 || i == 2025) {
563*0819c9f8SThomas Cort 		*wd2 = 0;
564*0819c9f8SThomas Cort 		obj = 0;
565*0819c9f8SThomas Cort 		return (2630);
566*0819c9f8SThomas Cort 	}
567*0819c9f8SThomas Cort 	printf("\nOkay, \"%s\".\n", wd2);
568*0819c9f8SThomas Cort 	return (2012);
569*0819c9f8SThomas Cort }
570*0819c9f8SThomas Cort 
571*0819c9f8SThomas Cort /* 9010                 */
572*0819c9f8SThomas Cort int
trtake(void)573*0819c9f8SThomas Cort trtake(void)
574*0819c9f8SThomas Cort {
575*0819c9f8SThomas Cort 	if (toting(obj))
576*0819c9f8SThomas Cort 		return (2011);	/* 9010 */
577*0819c9f8SThomas Cort 	spk = 25;
578*0819c9f8SThomas Cort 	if (obj == plant && prop[plant] <= 0)
579*0819c9f8SThomas Cort 		spk = 115;
580*0819c9f8SThomas Cort 	if (obj == bear && prop[bear] == 1)
581*0819c9f8SThomas Cort 		spk = 169;
582*0819c9f8SThomas Cort 	if (obj == chain && prop[bear] != 0)
583*0819c9f8SThomas Cort 		spk = 170;
584*0819c9f8SThomas Cort 	if (fixed[obj] != 0)
585*0819c9f8SThomas Cort 		return (2011);
586*0819c9f8SThomas Cort 	if (obj == water || obj == oil) {
587*0819c9f8SThomas Cort 		if (here(bottle) && liq() == obj) {
588*0819c9f8SThomas Cort 			obj = bottle;
589*0819c9f8SThomas Cort 			goto l9017;
590*0819c9f8SThomas Cort 		}
591*0819c9f8SThomas Cort 		obj = bottle;
592*0819c9f8SThomas Cort 		if (toting(bottle) && prop[bottle] == 1)
593*0819c9f8SThomas Cort 			return (9220);
594*0819c9f8SThomas Cort 		if (prop[bottle] != 1)
595*0819c9f8SThomas Cort 			spk = 105;
596*0819c9f8SThomas Cort 		if (!toting(bottle))
597*0819c9f8SThomas Cort 			spk = 104;
598*0819c9f8SThomas Cort 		return (2011);
599*0819c9f8SThomas Cort 	}
600*0819c9f8SThomas Cort l9017:	if (holding >= 7) {
601*0819c9f8SThomas Cort 		rspeak(92);
602*0819c9f8SThomas Cort 		return (2012);
603*0819c9f8SThomas Cort 	}
604*0819c9f8SThomas Cort 	if (obj == bird) {
605*0819c9f8SThomas Cort 		if (prop[bird] != 0)
606*0819c9f8SThomas Cort 			goto l9014;
607*0819c9f8SThomas Cort 		if (toting(rod)) {
608*0819c9f8SThomas Cort 			rspeak(26);
609*0819c9f8SThomas Cort 			return (2012);
610*0819c9f8SThomas Cort 		}
611*0819c9f8SThomas Cort 		if (!toting(cage)) {	/* 9013 */
612*0819c9f8SThomas Cort 			rspeak(27);
613*0819c9f8SThomas Cort 			return (2012);
614*0819c9f8SThomas Cort 		}
615*0819c9f8SThomas Cort 		prop[bird] = 1;	/* 9015 */
616*0819c9f8SThomas Cort 	}
617*0819c9f8SThomas Cort l9014:	if ((obj == bird || obj == cage) && prop[bird] != 0)
618*0819c9f8SThomas Cort 		carry(bird + cage - obj, loc);
619*0819c9f8SThomas Cort 	carry(obj, loc);
620*0819c9f8SThomas Cort 	k = liq();
621*0819c9f8SThomas Cort 	if (obj == bottle && k != 0)
622*0819c9f8SThomas Cort 		place[k] = -1;
623*0819c9f8SThomas Cort 	return (2009);
624*0819c9f8SThomas Cort }
625*0819c9f8SThomas Cort 
626*0819c9f8SThomas Cort /* 9021                 */
627*0819c9f8SThomas Cort static int
dropper(void)628*0819c9f8SThomas Cort dropper(void)
629*0819c9f8SThomas Cort {
630*0819c9f8SThomas Cort 	k = liq();
631*0819c9f8SThomas Cort 	if (k == obj)
632*0819c9f8SThomas Cort 		obj = bottle;
633*0819c9f8SThomas Cort 	if (obj == bottle && k != 0)
634*0819c9f8SThomas Cort 		place[k] = 0;
635*0819c9f8SThomas Cort 	if (obj == cage && prop[bird] != 0)
636*0819c9f8SThomas Cort 		drop(bird, loc);
637*0819c9f8SThomas Cort 	if (obj == bird)
638*0819c9f8SThomas Cort 		prop[bird] = 0;
639*0819c9f8SThomas Cort 	drop(obj, loc);
640*0819c9f8SThomas Cort 	return (2012);
641*0819c9f8SThomas Cort }
642*0819c9f8SThomas Cort 
643*0819c9f8SThomas Cort /* 9020                 */
644*0819c9f8SThomas Cort int
trdrop(void)645*0819c9f8SThomas Cort trdrop(void)
646*0819c9f8SThomas Cort {
647*0819c9f8SThomas Cort 	if (toting(rod2) && obj == rod && !toting(rod))
648*0819c9f8SThomas Cort 		obj = rod2;
649*0819c9f8SThomas Cort 	if (!toting(obj))
650*0819c9f8SThomas Cort 		return (2011);
651*0819c9f8SThomas Cort 	if (obj == bird && here(snake)) {
652*0819c9f8SThomas Cort 		rspeak(30);
653*0819c9f8SThomas Cort 		if (closed)
654*0819c9f8SThomas Cort 			return (19000);
655*0819c9f8SThomas Cort 		destroy(snake);
656*0819c9f8SThomas Cort 		prop[snake] = 1;
657*0819c9f8SThomas Cort 		return (dropper());
658*0819c9f8SThomas Cort 	}
659*0819c9f8SThomas Cort 	if (obj == coins && here(vend)) {	/* 9024                 */
660*0819c9f8SThomas Cort 		destroy(coins);
661*0819c9f8SThomas Cort 		drop(batter, loc);
662*0819c9f8SThomas Cort 		pspeak(batter, 0);
663*0819c9f8SThomas Cort 		return (2012);
664*0819c9f8SThomas Cort 	}
665*0819c9f8SThomas Cort 	if (obj == bird && at(dragon) && prop[dragon] == 0) {	/* 9025 */
666*0819c9f8SThomas Cort 		rspeak(154);
667*0819c9f8SThomas Cort 		destroy(bird);
668*0819c9f8SThomas Cort 		prop[bird] = 0;
669*0819c9f8SThomas Cort 		if (place[snake] == plac[snake])
670*0819c9f8SThomas Cort 			tally2--;
671*0819c9f8SThomas Cort 		return (2012);
672*0819c9f8SThomas Cort 	}
673*0819c9f8SThomas Cort 	if (obj == bear && at(troll)) {	/* 9026                 */
674*0819c9f8SThomas Cort 		rspeak(163);
675*0819c9f8SThomas Cort 		move(troll, 0);
676*0819c9f8SThomas Cort 		move(troll + 100, 0);
677*0819c9f8SThomas Cort 		move(troll2, plac[troll]);
678*0819c9f8SThomas Cort 		move(troll2 + 100, fixd[troll]);
679*0819c9f8SThomas Cort 		juggle(chasm);
680*0819c9f8SThomas Cort 		prop[troll] = 2;
681*0819c9f8SThomas Cort 		return (dropper());
682*0819c9f8SThomas Cort 	}
683*0819c9f8SThomas Cort 	if (obj != vase || loc == plac[pillow]) { /* 9027       */
684*0819c9f8SThomas Cort 		rspeak(54);
685*0819c9f8SThomas Cort 		return (dropper());
686*0819c9f8SThomas Cort 	}
687*0819c9f8SThomas Cort 	prop[vase] = 2;		/* 9028                 */
688*0819c9f8SThomas Cort 	if (at(pillow))
689*0819c9f8SThomas Cort 		prop[vase] = 0;
690*0819c9f8SThomas Cort 	pspeak(vase, prop[vase] + 1);
691*0819c9f8SThomas Cort 	if (prop[vase] != 0)
692*0819c9f8SThomas Cort 		fixed[vase] = -1;
693*0819c9f8SThomas Cort 	return (dropper());
694*0819c9f8SThomas Cort }
695*0819c9f8SThomas Cort 
696*0819c9f8SThomas Cort /* 9040                 */
697*0819c9f8SThomas Cort int
tropen(void)698*0819c9f8SThomas Cort tropen(void)
699*0819c9f8SThomas Cort {
700*0819c9f8SThomas Cort 	if (obj == clam || obj == oyster) {
701*0819c9f8SThomas Cort 		k = 0;		/* 9046                 */
702*0819c9f8SThomas Cort 		if (obj == oyster)
703*0819c9f8SThomas Cort 			k = 1;
704*0819c9f8SThomas Cort 		spk = 124 + k;
705*0819c9f8SThomas Cort 		if (toting(obj))
706*0819c9f8SThomas Cort 			spk = 120 + k;
707*0819c9f8SThomas Cort 		if (!toting(trident))
708*0819c9f8SThomas Cort 			spk = 122 + k;
709*0819c9f8SThomas Cort 		if (verb == lock)
710*0819c9f8SThomas Cort 			spk = 61;
711*0819c9f8SThomas Cort 		if (spk != 124)
712*0819c9f8SThomas Cort 			return (2011);
713*0819c9f8SThomas Cort 		destroy(clam);
714*0819c9f8SThomas Cort 		drop(oyster, loc);
715*0819c9f8SThomas Cort 		drop(pearl, 105);
716*0819c9f8SThomas Cort 		return (2011);
717*0819c9f8SThomas Cort 	}
718*0819c9f8SThomas Cort 	if (obj == door)
719*0819c9f8SThomas Cort 		spk = 111;
720*0819c9f8SThomas Cort 	if (obj == door && prop[door] == 1)
721*0819c9f8SThomas Cort 		spk = 54;
722*0819c9f8SThomas Cort 	if (obj == cage)
723*0819c9f8SThomas Cort 		spk = 32;
724*0819c9f8SThomas Cort 	if (obj == keys)
725*0819c9f8SThomas Cort 		spk = 55;
726*0819c9f8SThomas Cort 	if (obj == grate || obj == chain)
727*0819c9f8SThomas Cort 		spk = 31;
728*0819c9f8SThomas Cort 	if (spk != 31 || !here(keys))
729*0819c9f8SThomas Cort 		return (2011);
730*0819c9f8SThomas Cort 	if (obj == chain) {
731*0819c9f8SThomas Cort 		if (verb == lock) {
732*0819c9f8SThomas Cort 			spk = 172;	/* 9049: lock           */
733*0819c9f8SThomas Cort 			if (prop[chain] != 0)
734*0819c9f8SThomas Cort 				spk = 34;
735*0819c9f8SThomas Cort 			if (loc != plac[chain])
736*0819c9f8SThomas Cort 				spk = 173;
737*0819c9f8SThomas Cort 			if (spk != 172)
738*0819c9f8SThomas Cort 				return (2011);
739*0819c9f8SThomas Cort 			prop[chain] = 2;
740*0819c9f8SThomas Cort 			if (toting(chain))
741*0819c9f8SThomas Cort 				drop(chain, loc);
742*0819c9f8SThomas Cort 			fixed[chain] = -1;
743*0819c9f8SThomas Cort 			return (2011);
744*0819c9f8SThomas Cort 		}
745*0819c9f8SThomas Cort 		spk = 171;
746*0819c9f8SThomas Cort 		if (prop[bear] == 0)
747*0819c9f8SThomas Cort 			spk = 41;
748*0819c9f8SThomas Cort 		if (prop[chain] == 0)
749*0819c9f8SThomas Cort 			spk = 37;
750*0819c9f8SThomas Cort 		if (spk != 171)
751*0819c9f8SThomas Cort 			return (2011);
752*0819c9f8SThomas Cort 		prop[chain] = 0;
753*0819c9f8SThomas Cort 		fixed[chain] = 0;
754*0819c9f8SThomas Cort 		if (prop[bear] != 3)
755*0819c9f8SThomas Cort 			prop[bear] = 2;
756*0819c9f8SThomas Cort 		fixed[bear] = 2 - prop[bear];
757*0819c9f8SThomas Cort 		return (2011);
758*0819c9f8SThomas Cort 	}
759*0819c9f8SThomas Cort 	if (isclosing) {
760*0819c9f8SThomas Cort 		k = 130;
761*0819c9f8SThomas Cort 		if (!panic)
762*0819c9f8SThomas Cort 			clock2 = 15;
763*0819c9f8SThomas Cort 		panic = TRUE;
764*0819c9f8SThomas Cort 		return (2010);
765*0819c9f8SThomas Cort 	}
766*0819c9f8SThomas Cort 	k = 34 + prop[grate];	/* 9043                 */
767*0819c9f8SThomas Cort 	prop[grate] = 1;
768*0819c9f8SThomas Cort 	if (verb == lock)
769*0819c9f8SThomas Cort 		prop[grate] = 0;
770*0819c9f8SThomas Cort 	k = k + 2 * prop[grate];
771*0819c9f8SThomas Cort 	return (2010);
772*0819c9f8SThomas Cort }
773*0819c9f8SThomas Cort 
774*0819c9f8SThomas Cort /* 9120                         */
775*0819c9f8SThomas Cort int
trkill(void)776*0819c9f8SThomas Cort trkill(void)
777*0819c9f8SThomas Cort {
778*0819c9f8SThomas Cort 	int     i;
779*0819c9f8SThomas Cort 	for (i = 1; i <= 5; i++)
780*0819c9f8SThomas Cort 		if (dloc[i] == loc && dflag >= 2)
781*0819c9f8SThomas Cort 			break;
782*0819c9f8SThomas Cort 	if (i == 6)
783*0819c9f8SThomas Cort 		i = 0;
784*0819c9f8SThomas Cort 	if (obj == 0) {		/* 9122                         */
785*0819c9f8SThomas Cort 		if (i != 0)
786*0819c9f8SThomas Cort 			obj = dwarf;
787*0819c9f8SThomas Cort 		if (here(snake))
788*0819c9f8SThomas Cort 			obj = obj * 100 + snake;
789*0819c9f8SThomas Cort 		if (at(dragon) && prop[dragon] == 0)
790*0819c9f8SThomas Cort 			obj = obj * 100 + dragon;
791*0819c9f8SThomas Cort 		if (at(troll))
792*0819c9f8SThomas Cort 			obj = obj * 100 + troll;
793*0819c9f8SThomas Cort 		if (here(bear) && prop[bear] == 0)
794*0819c9f8SThomas Cort 			obj = obj * 100 + bear;
795*0819c9f8SThomas Cort 		if (obj > 100)
796*0819c9f8SThomas Cort 			return (8000);
797*0819c9f8SThomas Cort 		if (obj == 0) {
798*0819c9f8SThomas Cort 			if (here(bird) && verb != throw)
799*0819c9f8SThomas Cort 				obj = bird;
800*0819c9f8SThomas Cort 			if (here(clam) || here(oyster))
801*0819c9f8SThomas Cort 				obj = 100 * obj + clam;
802*0819c9f8SThomas Cort 			if (obj > 100)
803*0819c9f8SThomas Cort 				return (8000);
804*0819c9f8SThomas Cort 		}
805*0819c9f8SThomas Cort 	}
806*0819c9f8SThomas Cort 	if (obj == bird) {	/* 9124                         */
807*0819c9f8SThomas Cort 		spk = 137;
808*0819c9f8SThomas Cort 		if (closed)
809*0819c9f8SThomas Cort 			return (2011);
810*0819c9f8SThomas Cort 		destroy(bird);
811*0819c9f8SThomas Cort 		prop[bird] = 0;
812*0819c9f8SThomas Cort 		if (place[snake] == plac[snake])
813*0819c9f8SThomas Cort 			tally2++;
814*0819c9f8SThomas Cort 		spk = 45;
815*0819c9f8SThomas Cort 	}
816*0819c9f8SThomas Cort 	if (obj == 0)
817*0819c9f8SThomas Cort 		spk = 44;	/* 9125                         */
818*0819c9f8SThomas Cort 	if (obj == clam || obj == oyster)
819*0819c9f8SThomas Cort 		spk = 150;
820*0819c9f8SThomas Cort 	if (obj == snake)
821*0819c9f8SThomas Cort 		spk = 46;
822*0819c9f8SThomas Cort 	if (obj == dwarf)
823*0819c9f8SThomas Cort 		spk = 49;
824*0819c9f8SThomas Cort 	if (obj == dwarf && closed)
825*0819c9f8SThomas Cort 		return (19000);
826*0819c9f8SThomas Cort 	if (obj == dragon)
827*0819c9f8SThomas Cort 		spk = 147;
828*0819c9f8SThomas Cort 	if (obj == troll)
829*0819c9f8SThomas Cort 		spk = 157;
830*0819c9f8SThomas Cort 	if (obj == bear)
831*0819c9f8SThomas Cort 		spk = 165 + (prop[bear] + 1) / 2;
832*0819c9f8SThomas Cort 	if (obj != dragon || prop[dragon] != 0)
833*0819c9f8SThomas Cort 		return (2011);
834*0819c9f8SThomas Cort 	rspeak(49);
835*0819c9f8SThomas Cort 	verb = 0;
836*0819c9f8SThomas Cort 	obj = 0;
837*0819c9f8SThomas Cort 	getin(&wd1, &wd2);
838*0819c9f8SThomas Cort 	if (!weq(wd1, "y") && !weq(wd1, "yes"))
839*0819c9f8SThomas Cort 		return (2608);
840*0819c9f8SThomas Cort 	pspeak(dragon, 1);
841*0819c9f8SThomas Cort 	prop[dragon] = 2;
842*0819c9f8SThomas Cort 	prop[rug] = 0;
843*0819c9f8SThomas Cort 	k = (plac[dragon] + fixd[dragon]) / 2;
844*0819c9f8SThomas Cort 	move(dragon + 100, -1);
845*0819c9f8SThomas Cort 	move(rug + 100, 0);
846*0819c9f8SThomas Cort 	move(dragon, k);
847*0819c9f8SThomas Cort 	move(rug, k);
848*0819c9f8SThomas Cort 	for (obj = 1; obj <= 100; obj++)
849*0819c9f8SThomas Cort 		if (place[obj] == plac[dragon] || place[obj] == fixd[dragon])
850*0819c9f8SThomas Cort 			move(obj, k);
851*0819c9f8SThomas Cort 	loc = k;
852*0819c9f8SThomas Cort 	k = null;
853*0819c9f8SThomas Cort 	return (8);
854*0819c9f8SThomas Cort }
855*0819c9f8SThomas Cort 
856*0819c9f8SThomas Cort /* 9170: throw                  */
857*0819c9f8SThomas Cort int
trtoss(void)858*0819c9f8SThomas Cort trtoss(void)
859*0819c9f8SThomas Cort {
860*0819c9f8SThomas Cort 	int     i;
861*0819c9f8SThomas Cort 	if (toting(rod2) && obj == rod && !toting(rod))
862*0819c9f8SThomas Cort 		obj = rod2;
863*0819c9f8SThomas Cort 	if (!toting(obj))
864*0819c9f8SThomas Cort 		return (2011);
865*0819c9f8SThomas Cort 	if (obj >= 50 && obj <= maxtrs && at(troll)) {
866*0819c9f8SThomas Cort 		spk = 159;	/* 9178                 */
867*0819c9f8SThomas Cort 		drop(obj, 0);
868*0819c9f8SThomas Cort 		move(troll, 0);
869*0819c9f8SThomas Cort 		move(troll + 100, 0);
870*0819c9f8SThomas Cort 		drop(troll2, plac[troll]);
871*0819c9f8SThomas Cort 		drop(troll2 + 100, fixd[troll]);
872*0819c9f8SThomas Cort 		juggle(chasm);
873*0819c9f8SThomas Cort 		return (2011);
874*0819c9f8SThomas Cort 	}
875*0819c9f8SThomas Cort 	if (obj == food && here(bear)) {
876*0819c9f8SThomas Cort 		obj = bear;	/* 9177                 */
877*0819c9f8SThomas Cort 		return (9210);
878*0819c9f8SThomas Cort 	}
879*0819c9f8SThomas Cort 	if (obj != axe)
880*0819c9f8SThomas Cort 		return (9020);
881*0819c9f8SThomas Cort 	for (i = 1; i <= 5; i++) {
882*0819c9f8SThomas Cort 		if (dloc[i] == loc) {
883*0819c9f8SThomas Cort 			spk = 48;	/* 9172                 */
884*0819c9f8SThomas Cort 			if (ran(3) == 0 || saved != -1)
885*0819c9f8SThomas Cort 	l9175:		{
886*0819c9f8SThomas Cort 				rspeak(spk);
887*0819c9f8SThomas Cort 				drop(axe, loc);
888*0819c9f8SThomas Cort 				k = null;
889*0819c9f8SThomas Cort 				return (8);
890*0819c9f8SThomas Cort 			}
891*0819c9f8SThomas Cort 			dseen[i] = FALSE;
892*0819c9f8SThomas Cort 			dloc[i] = 0;
893*0819c9f8SThomas Cort 			spk = 47;
894*0819c9f8SThomas Cort 			dkill++;
895*0819c9f8SThomas Cort 			if (dkill == 1)
896*0819c9f8SThomas Cort 				spk = 149;
897*0819c9f8SThomas Cort 			goto l9175;
898*0819c9f8SThomas Cort 		}
899*0819c9f8SThomas Cort 	}
900*0819c9f8SThomas Cort 	spk = 152;
901*0819c9f8SThomas Cort 	if (at(dragon) && prop[dragon] == 0)
902*0819c9f8SThomas Cort 		goto l9175;
903*0819c9f8SThomas Cort 	spk = 158;
904*0819c9f8SThomas Cort 	if (at(troll))
905*0819c9f8SThomas Cort 		goto l9175;
906*0819c9f8SThomas Cort 	if (here(bear) && prop[bear] == 0) {
907*0819c9f8SThomas Cort 		spk = 164;
908*0819c9f8SThomas Cort 		drop(axe, loc);
909*0819c9f8SThomas Cort 		fixed[axe] = -1;
910*0819c9f8SThomas Cort 		prop[axe] = 1;
911*0819c9f8SThomas Cort 		juggle(bear);
912*0819c9f8SThomas Cort 		return (2011);
913*0819c9f8SThomas Cort 	}
914*0819c9f8SThomas Cort 	obj = 0;
915*0819c9f8SThomas Cort 	return (9120);
916*0819c9f8SThomas Cort }
917*0819c9f8SThomas Cort 
918*0819c9f8SThomas Cort /* 9210                 */
919*0819c9f8SThomas Cort int
trfeed(void)920*0819c9f8SThomas Cort trfeed(void)
921*0819c9f8SThomas Cort {
922*0819c9f8SThomas Cort 	if (obj == bird) {
923*0819c9f8SThomas Cort 		spk = 100;
924*0819c9f8SThomas Cort 		return (2011);
925*0819c9f8SThomas Cort 	}
926*0819c9f8SThomas Cort 	if (obj == snake || obj == dragon || obj == troll) {
927*0819c9f8SThomas Cort 		spk = 102;
928*0819c9f8SThomas Cort 		if (obj == dragon && prop[dragon] != 0)
929*0819c9f8SThomas Cort 			spk = 110;
930*0819c9f8SThomas Cort 		if (obj == troll)
931*0819c9f8SThomas Cort 			spk = 182;
932*0819c9f8SThomas Cort 		if (obj != snake || closed || !here(bird))
933*0819c9f8SThomas Cort 			return (2011);
934*0819c9f8SThomas Cort 		spk = 101;
935*0819c9f8SThomas Cort 		destroy(bird);
936*0819c9f8SThomas Cort 		prop[bird] = 0;
937*0819c9f8SThomas Cort 		tally2++;
938*0819c9f8SThomas Cort 		return (2011);
939*0819c9f8SThomas Cort 	}
940*0819c9f8SThomas Cort 	if (obj == dwarf) {
941*0819c9f8SThomas Cort 		if (!here(food))
942*0819c9f8SThomas Cort 			return (2011);
943*0819c9f8SThomas Cort 		spk = 103;
944*0819c9f8SThomas Cort 		dflag++;
945*0819c9f8SThomas Cort 		return (2011);
946*0819c9f8SThomas Cort 	}
947*0819c9f8SThomas Cort 	if (obj == bear) {
948*0819c9f8SThomas Cort 		if (prop[bear] == 0)
949*0819c9f8SThomas Cort 			spk = 102;
950*0819c9f8SThomas Cort 		if (prop[bear] == 3)
951*0819c9f8SThomas Cort 			spk = 110;
952*0819c9f8SThomas Cort 		if (!here(food))
953*0819c9f8SThomas Cort 			return (2011);
954*0819c9f8SThomas Cort 		destroy(food);
955*0819c9f8SThomas Cort 		prop[bear] = 1;
956*0819c9f8SThomas Cort 		fixed[axe] = 0;
957*0819c9f8SThomas Cort 		prop[axe] = 0;
958*0819c9f8SThomas Cort 		spk = 168;
959*0819c9f8SThomas Cort 		return (2011);
960*0819c9f8SThomas Cort 	}
961*0819c9f8SThomas Cort 	spk = 14;
962*0819c9f8SThomas Cort 	return (2011);
963*0819c9f8SThomas Cort }
964*0819c9f8SThomas Cort 
965*0819c9f8SThomas Cort /* 9220 */
966*0819c9f8SThomas Cort int
trfill(void)967*0819c9f8SThomas Cort trfill(void)
968*0819c9f8SThomas Cort {
969*0819c9f8SThomas Cort 	if (obj == vase) {
970*0819c9f8SThomas Cort 		spk = 29;
971*0819c9f8SThomas Cort 		if (liqloc(loc) == 0)
972*0819c9f8SThomas Cort 			spk = 144;
973*0819c9f8SThomas Cort 		if (liqloc(loc) == 0 || !toting(vase))
974*0819c9f8SThomas Cort 			return (2011);
975*0819c9f8SThomas Cort 		rspeak(145);
976*0819c9f8SThomas Cort 		prop[vase] = 2;
977*0819c9f8SThomas Cort 		fixed[vase] = -1;
978*0819c9f8SThomas Cort 		return (9020);	/* advent/10 goes to 9024 */
979*0819c9f8SThomas Cort 	}
980*0819c9f8SThomas Cort 	if (obj != 0 && obj != bottle)
981*0819c9f8SThomas Cort 		return (2011);
982*0819c9f8SThomas Cort 	if (obj == 0 && !here(bottle))
983*0819c9f8SThomas Cort 		return (8000);
984*0819c9f8SThomas Cort 	spk = 107;
985*0819c9f8SThomas Cort 	if (liqloc(loc) == 0)
986*0819c9f8SThomas Cort 		spk = 106;
987*0819c9f8SThomas Cort 	if (liq() != 0)
988*0819c9f8SThomas Cort 		spk = 105;
989*0819c9f8SThomas Cort 	if (spk != 107)
990*0819c9f8SThomas Cort 		return (2011);
991*0819c9f8SThomas Cort 	prop[bottle] = ((cond[loc] % 4) / 2) * 2;
992*0819c9f8SThomas Cort 	k = liq();
993*0819c9f8SThomas Cort 	if (toting(bottle))
994*0819c9f8SThomas Cort 		place[k] = -1;
995*0819c9f8SThomas Cort 	if (k == oil)
996*0819c9f8SThomas Cort 		spk = 108;
997*0819c9f8SThomas Cort 	return (2011);
998*0819c9f8SThomas Cort }
999*0819c9f8SThomas Cort 
1000*0819c9f8SThomas Cort /* 10000 */
1001*0819c9f8SThomas Cort void
closing(void)1002*0819c9f8SThomas Cort closing(void)
1003*0819c9f8SThomas Cort {
1004*0819c9f8SThomas Cort 	int     i;
1005*0819c9f8SThomas Cort 
1006*0819c9f8SThomas Cort 	prop[grate] = prop[fissure] = 0;
1007*0819c9f8SThomas Cort 	for (i = 1; i <= 6; i++) {
1008*0819c9f8SThomas Cort 		dseen[i] = FALSE;
1009*0819c9f8SThomas Cort 		dloc[i] = 0;
1010*0819c9f8SThomas Cort 	}
1011*0819c9f8SThomas Cort 	move(troll, 0);
1012*0819c9f8SThomas Cort 	move(troll + 100, 0);
1013*0819c9f8SThomas Cort 	move(troll2, plac[troll]);
1014*0819c9f8SThomas Cort 	move(troll2 + 100, fixd[troll]);
1015*0819c9f8SThomas Cort 	juggle(chasm);
1016*0819c9f8SThomas Cort 	if (prop[bear] != 3)
1017*0819c9f8SThomas Cort 		destroy(bear);
1018*0819c9f8SThomas Cort 	prop[chain] = 0;
1019*0819c9f8SThomas Cort 	fixed[chain] = 0;
1020*0819c9f8SThomas Cort 	prop[axe] = 0;
1021*0819c9f8SThomas Cort 	fixed[axe] = 0;
1022*0819c9f8SThomas Cort 	rspeak(129);
1023*0819c9f8SThomas Cort 	clock1 = -1;
1024*0819c9f8SThomas Cort 	isclosing = TRUE;
1025*0819c9f8SThomas Cort }
1026*0819c9f8SThomas Cort 
1027*0819c9f8SThomas Cort /* 11000 */
1028*0819c9f8SThomas Cort void
caveclose(void)1029*0819c9f8SThomas Cort caveclose(void)
1030*0819c9f8SThomas Cort {
1031*0819c9f8SThomas Cort 	int     i;
1032*0819c9f8SThomas Cort 	prop[bottle] = put(bottle, 115, 1);
1033*0819c9f8SThomas Cort 	prop[plant] = put(plant, 115, 0);
1034*0819c9f8SThomas Cort 	prop[oyster] = put(oyster, 115, 0);
1035*0819c9f8SThomas Cort 	prop[lamp] = put(lamp, 115, 0);
1036*0819c9f8SThomas Cort 	prop[rod] = put(rod, 115, 0);
1037*0819c9f8SThomas Cort 	prop[dwarf] = put(dwarf, 115, 0);
1038*0819c9f8SThomas Cort 	loc = 115;
1039*0819c9f8SThomas Cort 	oldloc = 115;
1040*0819c9f8SThomas Cort 	newloc = 115;
1041*0819c9f8SThomas Cort 
1042*0819c9f8SThomas Cort 	put(grate, 116, 0);
1043*0819c9f8SThomas Cort 	prop[snake] = put(snake, 116, 1);
1044*0819c9f8SThomas Cort 	prop[bird] = put(bird, 116, 1);
1045*0819c9f8SThomas Cort 	prop[cage] = put(cage, 116, 0);
1046*0819c9f8SThomas Cort 	prop[rod2] = put(rod2, 116, 0);
1047*0819c9f8SThomas Cort 	prop[pillow] = put(pillow, 116, 0);
1048*0819c9f8SThomas Cort 
1049*0819c9f8SThomas Cort 	prop[mirror] = put(mirror, 115, 0);
1050*0819c9f8SThomas Cort 	fixed[mirror] = 116;
1051*0819c9f8SThomas Cort 
1052*0819c9f8SThomas Cort 	for (i = 1; i <= 100; i++)
1053*0819c9f8SThomas Cort 		if (toting(i))
1054*0819c9f8SThomas Cort 			destroy(i);
1055*0819c9f8SThomas Cort 	rspeak(132);
1056*0819c9f8SThomas Cort 	closed = TRUE;
1057*0819c9f8SThomas Cort }
1058