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