]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - games/adventure/main.c
This commit was generated by cvs2svn to compensate for changes in r37074,
[FreeBSD/FreeBSD.git] / games / adventure / main.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 static char copyright[] =
41 "@(#) Copyright (c) 1991, 1993\n\
42         The Regents of the University of California.  All rights reserved.\n";
43 #endif /* not lint */
44
45 #ifndef lint
46 static char sccsid[] = "@(#)main.c      8.1 (Berkeley) 6/2/93";
47 #endif /* not lint */
48
49 /*      Re-coding of advent in C: main program                          */
50
51 #include <sys/file.h>
52 #include <signal.h>
53 #include <stdio.h>
54 #include "hdr.h"
55
56
57 main(argc,argv)
58 int argc;
59 char **argv;
60 {
61         extern int errno;
62         register int i;
63         int rval,ll;
64         struct text *kk;
65         extern trapdel();
66
67         /* revoke */
68         setgid(getgid());
69
70         init();         /* Initialize everything */
71         signal(2,trapdel);
72
73         if (argc > 1)   /* Restore file specified */
74         {               /* Restart is label 8305 (Fortran) */
75                 i = restore(argv[1]);       /* See what we've got */
76                 switch(i)
77                 {
78                     case 0:     /* The restore worked fine */
79                         yea=Start(0);
80                         k=null;
81                         unlink(argv[1]);/* Don't re-use the save */
82                         goto l8;        /* Get where we're going */
83                     case 1:             /* Couldn't open it */
84                         exit(0);        /* So give up */
85                     case 2:             /* Oops -- file was altered */
86                         rspeak(202);    /* You dissolve */
87                         exit(0);        /* File could be non-adventure */
88                 }                       /* So don't unlink it. */
89         }
90
91         startup();              /* prepare for a user           */
92
93         for (;;)                        /* main command loop (label 2)  */
94         {       if (newloc<9 && newloc!=0 && closng)
95                 {       rspeak(130);    /* if closing leave only by     */
96                         newloc=loc;     /*      main office             */
97                         if (!panic) clock2=15;
98                         panic=TRUE;
99                 }
100
101                 rval=fdwarf();          /* dwarf stuff                  */
102                 if (rval==99) die(99);
103
104         l2000:  if (loc==0) die(99);    /* label 2000                   */
105                 kk = &stext[loc];
106                 if ((abb[loc]%abbnum)==0 || kk->seekadr==0)
107                         kk = &ltext[loc];
108                 if (!forced(loc) && dark(0))
109                 {       if (wzdark && pct(35))
110                         {       die(90);
111                                 goto l2000;
112                         }
113                         kk = &rtext[16];
114                 }
115         l2001:  if (toting(bear)) rspeak(141);  /* 2001                 */
116                 speak(kk);
117                 k=1;
118                 if (forced(loc))
119                         goto l8;
120                 if (loc==33 && pct(25)&&!closng) rspeak(8);
121                 if (!dark(0))
122                 {       abb[loc]++;
123                         for (i=atloc[loc]; i!=0; i=linkx[i])     /*2004  */
124                         {       obj=i;
125                                 if (obj>100) obj -= 100;
126                                 if (obj==steps && toting(nugget)) continue;
127                                 if (prop[obj]<0)
128                                 {       if (closed) continue;
129                                         prop[obj]=0;
130                                         if (obj==rug||obj==chain)
131                                                 prop[obj]=1;
132                                         tally--;
133                                         if (tally==tally2 && tally != 0)
134                                                 if (limit>35) limit=35;
135                                 }
136                                 ll =  prop[obj];   /* 2006         */
137                                 if (obj==steps && loc==fixed[steps])
138                                         ll = 1;
139                                 pspeak(obj, ll);
140                         }                                       /* 2008 */
141                         goto l2012;
142         l2009:          k=54;                   /* 2009                 */
143         l2010:          spk=k;
144         l2011:          rspeak(spk);
145                 }
146         l2012:  verb=0;                         /* 2012                 */
147                 obj=0;
148         l2600:  checkhints();                   /* to 2600-2602         */
149                 if (closed)
150                 {       if (prop[oyster]<0 && toting(oyster))
151                                 pspeak(oyster,1);
152                         for (i=1; i<100; i++)
153                                 if (toting(i)&&prop[i]<0)       /*2604  */
154                                         prop[i] = -1-prop[i];
155                 }
156                 wzdark=dark(0);                 /* 2605                 */
157                 if (knfloc>0 && knfloc!=loc) knfloc=1;
158                 getin(&wd1,&wd2);
159                 if (delhit)                     /* user typed a DEL     */
160                 {       delhit=0;               /* reset counter        */
161                         copystr("quit",wd1);    /* pretend he's quitting*/
162                         *wd2=0;
163                 }
164         l2608:  if ((foobar = -foobar)>0) foobar=0;     /* 2608         */
165                 /* should check here for "magic mode"                   */
166                 turns++;
167                 if (demo && turns>=SHORT) done(1);      /* to 13000     */
168
169                 if (verb==say && *wd2!=0) verb=0;
170                 if (verb==say)
171                         goto l4090;
172                 if (tally==0 && loc>=15 && loc!=33) clock1--;
173                 if (clock1==0)
174                 {       closing();                      /* to 10000     */
175                         goto l19999;
176                 }
177                 if (clock1<0) clock2--;
178                 if (clock2==0)
179                 {       caveclose();            /* to 11000             */
180                         continue;               /* back to 2            */
181                 }
182                 if (prop[lamp]==1) limit--;
183                 if (limit<=30 && here(batter) && prop[batter]==0
184                         && here(lamp))
185                 {       rspeak(188);            /* 12000                */
186                         prop[batter]=1;
187                         if (toting(batter)) drop(batter,loc);
188                         limit=limit+2500;
189                         lmwarn=FALSE;
190                         goto l19999;
191                 }
192                 if (limit==0)
193                 {       limit = -1;             /* 12400                */
194                         prop[lamp]=0;
195                         rspeak(184);
196                         goto l19999;
197                 }
198                 if (limit<0&&loc<=8)
199                 {       rspeak(185);            /* 12600                */
200                         gaveup=TRUE;
201                         done(2);                /* to 20000             */
202                 }
203                 if (limit<=30)
204                 {       if (lmwarn|| !here(lamp)) goto l19999;  /*12200*/
205                         lmwarn=TRUE;
206                         spk=187;
207                         if (place[batter]==0) spk=183;
208                         if (prop[batter]==1) spk=189;
209                         rspeak(spk);
210                 }
211         l19999: k=43;
212                 if (liqloc(loc)==water) k=70;
213                 if (weq(wd1,"enter") &&
214                     (weq(wd2,"strea")||weq(wd2,"water")))
215                         goto l2010;
216                 if (weq(wd1,"enter") && *wd2!=0) goto l2800;
217                 if ((!weq(wd1,"water")&&!weq(wd1,"oil"))
218                     || (!weq(wd2,"plant")&&!weq(wd2,"door")))
219                         goto l2610;
220                 if (at(vocab(wd2,1))) copystr("pour",wd2);
221
222         l2610:  if (weq(wd1,"west"))
223                         if (++iwest==10) rspeak(17);
224         l2630:  i=vocab(wd1,-1);
225                 if (i== -1)
226                 {       spk=60;                 /* 3000         */
227                         if (pct(20)) spk=61;
228                         if (pct(20)) spk=13;
229                         rspeak(spk);
230                         goto l2600;
231                 }
232                 k=i%1000;
233                 kq=i/1000+1;
234                 switch(kq)
235                 {   case 1: goto l8;
236                     case 2: goto l5000;
237                     case 3: goto l4000;
238                     case 4: goto l2010;
239                     default:
240                         printf("Error 22\n");
241                         exit(0);
242                 }
243
244         l8:
245                 switch(march())
246                 {   case 2: continue;           /* i.e. goto l2         */
247                     case 99:
248                         switch(die(99))
249                         {   case 2000: goto l2000;
250                             default: bug(111);
251                         }
252                     default: bug(110);
253                 }
254
255         l2800:  copystr(wd2,wd1);
256                 *wd2=0;
257                 goto l2610;
258
259         l4000:  verb=k;
260                 spk=actspk[verb];
261                 if (*wd2!=0 && verb!=say) goto l2800;
262                 if (verb==say) obj= *wd2;
263                 if (obj!=0) goto l4090;
264         l4080:
265                 switch(verb)
266                 {   case 1:                     /* take = 8010          */
267                         if (atloc[loc]==0||linkx[atloc[loc]]!=0) goto l8000;
268                         for (i=1; i<=5; i++)
269                                 if (dloc[i]==loc&&dflag>=2) goto l8000;
270                         obj=atloc[loc];
271                         goto l9010;
272                     case 2: case 3: case 9:     /* 8000 : drop,say,wave */
273                     case 10: case 16: case 17:  /* calm,rub,toss        */
274                     case 19: case 21: case 28:  /* find,feed,break      */
275                     case 29:                    /* wake                 */
276                 l8000:  printf("%s what?\n",wd1);
277                         obj=0;
278                         goto l2600;
279                     case 4: case 6:             /* 8040 open,lock       */
280                         spk=28;
281                         if (here(clam)) obj=clam;
282                         if (here(oyster)) obj=oyster;
283                         if (at(door)) obj=door;
284                         if (at(grate)) obj=grate;
285                         if (obj!=0 && here(chain)) goto l8000;
286                         if (here(chain)) obj=chain;
287                         if (obj==0) goto l2011;
288                         goto l9040;
289                     case 5: goto l2009;         /* nothing              */
290                     case 7: goto l9070;         /* on                   */
291                     case 8: goto l9080;         /* off                  */
292                     case 11: goto l8000;        /* walk                 */
293                     case 12: goto l9120;        /* kill                 */
294                     case 13: goto l9130;        /* pour                 */
295                     case 14:                    /* eat: 8140            */
296                         if (!here(food)) goto l8000;
297                 l8142:  dstroy(food);
298                         spk=72;
299                         goto l2011;
300                     case 15: goto l9150;        /* drink                */
301                     case 18:                    /* quit: 8180           */
302                         gaveup=yes(22,54,54);
303                         if (gaveup) done(2);    /* 8185                 */
304                         goto l2012;
305                     case 20:                    /* invent=8200          */
306                         spk=98;
307                         for (i=1; i<=100; i++)
308                         {       if (i!=bear && toting(i))
309                                 {       if (spk==98) rspeak(99);
310                                         blklin=FALSE;
311                                         pspeak(i,-1);
312                                         blklin=TRUE;
313                                         spk=0;
314                                 }
315                         }
316                         if (toting(bear)) spk=141;
317                         goto l2011;
318                     case 22: goto l9220;        /* fill                 */
319                     case 23: goto l9230;        /* blast                */
320                     case 24:                    /* score: 8240          */
321                         scorng=TRUE;
322                         printf("If you were to quit now, you would score");
323                         printf(" %d out of a possible ",score());
324                         printf("%d.",mxscor);
325                         scorng=FALSE;
326                         gaveup=yes(143,54,54);
327                         if (gaveup) done(2);
328                         goto l2012;
329                     case 25:                    /* foo: 8250            */
330                         k=vocab(wd1,3);
331                         spk=42;
332                         if (foobar==1-k) goto l8252;
333                         if (foobar!=0) spk=151;
334                         goto l2011;
335                 l8252:  foobar=k;
336                         if (k!=4) goto l2009;
337                         foobar=0;
338                         if (place[eggs]==plac[eggs]
339                                 ||(toting(eggs)&&loc==plac[eggs])) goto l2011;
340                         if (place[eggs]==0&&place[troll]==0&&prop[troll]==0)
341                                 prop[troll]=1;
342                         k=2;
343                         if (here(eggs)) k=1;
344                         if (loc==plac[eggs]) k=0;
345                         move(eggs,plac[eggs]);
346                         pspeak(eggs,k);
347                         goto l2012;
348                     case 26:                    /* brief=8260           */
349                         spk=156;
350                         abbnum=10000;
351                         detail=3;
352                         goto l2011;
353                     case 27:                    /* read=8270            */
354                         if (here(magzin)) obj=magzin;
355                         if (here(tablet)) obj=obj*100+tablet;
356                         if (here(messag)) obj=obj*100+messag;
357                         if (closed&&toting(oyster)) obj=oyster;
358                         if (obj>100||obj==0||dark(0)) goto l8000;
359                         goto l9270;
360                     case 30:                    /* suspend=8300         */
361                         spk=201;
362                         if (demo) goto l2011;
363                         printf("I can suspend your adventure for you so");
364                         printf(" you can resume later, but\n");
365                         printf("you will have to wait at least");
366                         printf(" %d minutes before continuing.",latncy);
367                         if (!yes(200,54,54)) goto l2012;
368                         datime(&saved,&savet);
369                         ciao(argv[0]);          /* Do we quit? */
370                         continue;               /* Maybe not */
371                     case 31:                    /* hours=8310           */
372                         printf("Colossal cave is closed 9am-5pm Mon ");
373                         printf("through Fri except holidays.\n");
374                         goto l2012;
375                     default: bug(23);
376                 }
377
378         l4090:
379                 switch(verb)
380                 {   case 1:                     /* take = 9010          */
381         l9010:          switch(trtake())
382                         {   case 2011: goto l2011;
383                             case 9220: goto l9220;
384                             case 2009: goto l2009;
385                             case 2012: goto l2012;
386                             default: bug(102);
387                         }
388         l9020:      case 2:                     /* drop = 9020          */
389                         switch(trdrop())
390                         {   case 2011: goto l2011;
391                             case 19000: done(3);
392                             case 2012: goto l2012;
393                             default: bug(105);
394                         }
395         l9030:      case 3:
396                         switch(trsay())
397                         {   case 2012: goto l2012;
398                             case 2630: goto l2630;
399                             default: bug(107);
400                         }
401         l9040:      case 4:  case 6:            /* open, close          */
402                         switch(tropen())
403                         {   case 2011: goto l2011;
404                             case 2010: goto l2010;
405                             default: bug(106);
406                         }
407                     case 5: goto l2009;         /* nothing              */
408                     case 7:                     /* on   9070            */
409         l9070:          if (!here(lamp))  goto l2011;
410                         spk=184;
411                         if (limit<0) goto l2011;
412                         prop[lamp]=1;
413                         rspeak(39);
414                         if (wzdark) goto l2000;
415                         goto l2012;
416
417                     case 8:                     /* off                  */
418         l9080:          if (!here(lamp)) goto l2011;
419                         prop[lamp]=0;
420                         rspeak(40);
421                         if (dark(0)) rspeak(16);
422                         goto l2012;
423
424                     case 9:                     /* wave                 */
425                         if ((!toting(obj))&&(obj!=rod||!toting(rod2)))
426                                 spk=29;
427                         if (obj!=rod||!at(fissur)||!toting(obj)||closng)
428                                 goto l2011;
429                         prop[fissur]=1-prop[fissur];
430                         pspeak(fissur,2-prop[fissur]);
431                         goto l2012;
432                     case 10: case 11: case 18:  /* calm, walk, quit     */
433                     case 24: case 25: case 26:  /* score, foo, brief    */
434                     case 30: case 31:           /* suspend, hours       */
435                              goto l2011;
436         l9120:      case 12:                    /* kill                 */
437                         switch(trkill())
438                         {   case 8000: goto l8000;
439                             case 8: goto l8;
440                             case 2011: goto l2011;
441                             case 2608: goto l2608;
442                             case 19000: done(3);
443                             default: bug(112);
444                         }
445         l9130:      case 13:                    /* pour                 */
446                         if (obj==bottle||obj==0) obj=liq(0);
447                         if (obj==0) goto l8000;
448                         if (!toting(obj)) goto l2011;
449                         spk=78;
450                         if (obj!=oil&&obj!=water) goto l2011;
451                         prop[bottle]=1;
452                         place[obj]=0;
453                         spk=77;
454                         if (!(at(plant)||at(door))) goto l2011;
455                         if (at(door))
456                         {       prop[door]=0;   /* 9132                 */
457                                 if (obj==oil) prop[door]=1;
458                                 spk=113+prop[door];
459                                 goto l2011;
460                         }
461                         spk=112;
462                         if (obj!=water) goto l2011;
463                         pspeak(plant,prop[plant]+1);
464                         prop[plant]=(prop[plant]+2)% 6;
465                         prop[plant2]=prop[plant]/2;
466                         k=null;
467                         goto l8;
468                     case 14:                    /* 9140 - eat           */
469                         if (obj==food) goto l8142;
470                         if (obj==bird||obj==snake||obj==clam||obj==oyster
471                             ||obj==dwarf||obj==dragon||obj==troll
472                             ||obj==bear) spk=71;
473                         goto l2011;
474         l9150:      case 15:                    /* 9150 - drink         */
475                         if (obj==0&&liqloc(loc)!=water&&(liq(0)!=water
476                                 ||!here(bottle))) goto l8000;
477                         if (obj!=0&&obj!=water) spk=110;
478                         if (spk==110||liq(0)!=water||!here(bottle))
479                                 goto l2011;
480                         prop[bottle]=1;
481                         place[water]=0;
482                         spk=74;
483                         goto l2011;
484                     case 16:                    /* 9160: rub            */
485                         if (obj!=lamp) spk=76;
486                         goto l2011;
487                     case 17:                    /* 9170: throw          */
488                         switch(trtoss())
489                         {   case 2011: goto l2011;
490                             case 9020: goto l9020;
491                             case 9120: goto l9120;
492                             case 8: goto l8;
493                             case 9210: goto l9210;
494                             default: bug(113);
495                         }
496                     case 19: case 20:           /* 9190: find, invent   */
497                         if (at(obj)||(liq(0)==obj&&at(bottle))
498                                 ||k==liqloc(loc)) spk=94;
499                         for (i=1; i<=5; i++)
500                                 if (dloc[i]==loc&&dflag>=2&&obj==dwarf)
501                                         spk=94;
502                         if (closed) spk=138;
503                         if (toting(obj)) spk=24;
504                         goto l2011;
505         l9210:      case 21:                    /* feed                 */
506                         switch(trfeed())
507                         {   case 2011: goto l2011;
508                             default: bug(114);
509                         }
510         l9220:      case 22:                    /* fill                 */
511                         switch(trfill())
512                         {   case 2011: goto l2011;
513                             case 8000: goto l8000;
514                             case 9020: goto l9020;
515                             default: bug(115);
516                         }
517         l9230:      case 23:                    /* blast                */
518                         if (prop[rod2]<0||!closed) goto l2011;
519                         bonus=133;
520                         if (loc==115) bonus=134;
521                         if (here(rod2)) bonus=135;
522                         rspeak(bonus);
523                         done(2);
524         l9270:      case 27:                    /* read                 */
525                         if (dark(0)) goto l5190;
526                         if (obj==magzin) spk=190;
527                         if (obj==tablet) spk=196;
528                         if (obj==messag) spk=191;
529                         if (obj==oyster&&hinted[2]&&toting(oyster)) spk=194;
530                         if (obj!=oyster||hinted[2]||!toting(oyster)
531                                 ||!closed) goto l2011;
532                         hinted[2]=yes(192,193,54);
533                         goto l2012;
534         l9280:      case 28:                    /* break                */
535                         if (obj==mirror) spk=148;
536                         if (obj==vase&&prop[vase]==0)
537                         {       spk=198;
538                                 if (toting(vase)) drop(vase,loc);
539                                 prop[vase]=2;
540                                 fixed[vase]= -1;
541                                 goto l2011;
542                         }
543                         if (obj!=mirror||!closed) goto l2011;
544                         rspeak(197);
545                         done(3);
546
547         l9290:      case 29:                    /* wake                 */
548                         if (obj!=dwarf||!closed) goto l2011;
549                         rspeak(199);
550                         done(3);
551
552                     default: bug(24);
553                 }
554
555         l5000:
556                 obj=k;
557                 if (fixed[k]!=loc && !here(k)) goto l5100;
558         l5010:  if (*wd2!=0) goto l2800;
559                 if (verb!=0) goto l4090;
560                 printf("What do you want to do with the %s?\n",wd1);
561                 goto l2600;
562         l5100:  if (k!=grate) goto l5110;
563                 if (loc==1||loc==4||loc==7) k=dprssn;
564                 if (loc>9&&loc<15) k=entrnc;
565                 if (k!=grate) goto l8;
566         l5110:  if (k!=dwarf) goto l5120;
567                 for (i=1; i<=5; i++)
568                         if (dloc[i]==loc&&dflag>=2) goto l5010;
569         l5120:  if ((liq(0)==k&&here(bottle))||k==liqloc(loc)) goto l5010;
570                 if (obj!=plant||!at(plant2)||prop[plant2]==0) goto l5130;
571                 obj=plant2;
572                 goto l5010;
573         l5130:  if (obj!=knife||knfloc!=loc) goto l5140;
574                 knfloc = -1;
575                 spk=116;
576                 goto l2011;
577         l5140:  if (obj!=rod||!here(rod2)) goto l5190;
578                 obj=rod2;
579                 goto l5010;
580         l5190:  if ((verb==find||verb==invent)&&*wd2==0) goto l5010;
581                 printf("I see no %s here\n",wd1);
582                 goto l2012;
583         }
584 }