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