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