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