📄 main.c
字号:
/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * The game adventure was originally written in Fortran by Will Crowther * and Don Woods. It was later translated to C and enhanced by Jim * Gillogly. This code is derived from software contributed to Berkeley * by Jim Gillogly at The Rand Corporation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char copyright[] ="@(#) Copyright (c) 1991, 1993\n\ The Regents of the University of California. All rights reserved.\n";#endif /* not lint */#ifndef lintstatic char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/2/93";#endif /* not lint *//* Re-coding of advent in C: main program */#include <sys/file.h>#include <stdio.h>#include "hdr.h"main(argc,argv)int argc;char **argv;{ extern int errno; register int i; int rval,ll; struct text *kk; extern trapdel(); init(); /* Initialize everything */ signal(2,trapdel); if (argc > 1) /* Restore file specified */ { /* Restart is label 8305 (Fortran) */ i = restore(argv[1]); /* See what we've got */ switch(i) { case 0: /* The restore worked fine */ yea=Start(0); k=null; unlink(argv[1]);/* Don't re-use the save */ goto l8; /* Get where we're going */ case 1: /* Couldn't open it */ exit(0); /* So give up */ case 2: /* Oops -- file was altered */ rspeak(202); /* You dissolve */ exit(0); /* File could be non-adventure */ } /* So don't unlink it. */ } startup(); /* prepare for a user */ for (;;) /* main command loop (label 2) */ { if (newloc<9 && newloc!=0 && closng) { rspeak(130); /* if closing leave only by */ newloc=loc; /* main office */ if (!panic) clock2=15; panic=TRUE; } rval=fdwarf(); /* dwarf stuff */ if (rval==99) die(99); l2000: if (loc==0) die(99); /* label 2000 */ kk = &stext[loc]; if ((abb[loc]%abbnum)==0 || kk->seekadr==0) kk = <ext[loc]; if (!forced(loc) && dark(0)) { if (wzdark && pct(35)) { die(90); goto l2000; } kk = &rtext[16]; } l2001: if (toting(bear)) rspeak(141); /* 2001 */ speak(kk); k=1; if (forced(loc)) goto l8; if (loc==33 && pct(25)&&!closng) rspeak(8); if (!dark(0)) { abb[loc]++; for (i=atloc[loc]; i!=0; i=link[i]) /*2004 */ { obj=i; if (obj>100) obj -= 100; if (obj==steps && toting(nugget)) continue; if (prop[obj]<0) { if (closed) continue; prop[obj]=0; if (obj==rug||obj==chain) prop[obj]=1; tally--; if (tally==tally2 && tally != 0) if (limit>35) limit=35; } ll = prop[obj]; /* 2006 */ if (obj==steps && loc==fixed[steps]) ll = 1; pspeak(obj, ll); } /* 2008 */ goto l2012; l2009: k=54; /* 2009 */ l2010: spk=k; l2011: rspeak(spk); } l2012: verb=0; /* 2012 */ obj=0; l2600: checkhints(); /* to 2600-2602 */ if (closed) { if (prop[oyster]<0 && toting(oyster)) pspeak(oyster,1); for (i=1; i<100; i++) if (toting(i)&&prop[i]<0) /*2604 */ prop[i] = -1-prop[i]; } wzdark=dark(0); /* 2605 */ if (knfloc>0 && knfloc!=loc) knfloc=1; getin(&wd1,&wd2); if (delhit) /* user typed a DEL */ { delhit=0; /* reset counter */ copystr("quit",wd1); /* pretend he's quitting*/ *wd2=0; } l2608: if ((foobar = -foobar)>0) foobar=0; /* 2608 */ /* should check here for "magic mode" */ turns++; if (demo && turns>=SHORT) done(1); /* to 13000 */ if (verb==say && *wd2!=0) verb=0; if (verb==say) goto l4090; if (tally==0 && loc>=15 && loc!=33) clock1--; if (clock1==0) { closing(); /* to 10000 */ goto l19999; } if (clock1<0) clock2--; if (clock2==0) { caveclose(); /* to 11000 */ continue; /* back to 2 */ } if (prop[lamp]==1) limit--; if (limit<=30 && here(batter) && prop[batter]==0 && here(lamp)) { rspeak(188); /* 12000 */ prop[batter]=1; if (toting(batter)) drop(batter,loc); limit=limit+2500; lmwarn=FALSE; goto l19999; } if (limit==0) { limit = -1; /* 12400 */ prop[lamp]=0; rspeak(184); goto l19999; } if (limit<0&&loc<=8) { rspeak(185); /* 12600 */ gaveup=TRUE; done(2); /* to 20000 */ } if (limit<=30) { if (lmwarn|| !here(lamp)) goto l19999; /*12200*/ lmwarn=TRUE; spk=187; if (place[batter]==0) spk=183; if (prop[batter]==1) spk=189; rspeak(spk); } l19999: k=43; if (liqloc(loc)==water) k=70; if (weq(wd1,"enter") && (weq(wd2,"strea")||weq(wd2,"water"))) goto l2010; if (weq(wd1,"enter") && *wd2!=0) goto l2800; if ((!weq(wd1,"water")&&!weq(wd1,"oil")) || (!weq(wd2,"plant")&&!weq(wd2,"door"))) goto l2610; if (at(vocab(wd2,1))) copystr("pour",wd2); l2610: if (weq(wd1,"west")) if (++iwest==10) rspeak(17); l2630: i=vocab(wd1,-1); if (i== -1) { spk=60; /* 3000 */ if (pct(20)) spk=61; if (pct(20)) spk=13; rspeak(spk); goto l2600; } k=i%1000; kq=i/1000+1; switch(kq) { case 1: goto l8; case 2: goto l5000; case 3: goto l4000; case 4: goto l2010; default: printf("Error 22\n"); exit(0); } l8: switch(march()) { case 2: continue; /* i.e. goto l2 */ case 99: switch(die(99)) { case 2000: goto l2000; default: bug(111); } default: bug(110); } l2800: copystr(wd2,wd1); *wd2=0; goto l2610; l4000: verb=k; spk=actspk[verb]; if (*wd2!=0 && verb!=say) goto l2800; if (verb==say) obj= *wd2; if (obj!=0) goto l4090; l4080: switch(verb) { case 1: /* take = 8010 */ if (atloc[loc]==0||link[atloc[loc]]!=0) goto l8000; for (i=1; i<=5; i++) if (dloc[i]==loc&&dflag>=2) goto l8000; obj=atloc[loc]; goto l9010; case 2: case 3: case 9: /* 8000 : drop,say,wave */ case 10: case 16: case 17: /* calm,rub,toss */ case 19: case 21: case 28: /* find,feed,break */ case 29: /* wake */ l8000: printf("%s what?\n",wd1); obj=0; goto l2600; case 4: case 6: /* 8040 open,lock */ spk=28; if (here(clam)) obj=clam; if (here(oyster)) obj=oyster; if (at(door)) obj=door; if (at(grate)) obj=grate; if (obj!=0 && here(chain)) goto l8000; if (here(chain)) obj=chain; if (obj==0) goto l2011; goto l9040; case 5: goto l2009; /* nothing */ case 7: goto l9070; /* on */ case 8: goto l9080; /* off */ case 11: goto l8000; /* walk */ case 12: goto l9120; /* kill */ case 13: goto l9130; /* pour */ case 14: /* eat: 8140 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -