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