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