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