]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/subr.c
1 /* $NetBSD: subr.c,v 1.4 1997/10/10 11:59:53 lukem Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
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.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
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
41 #include <sys/cdefs.h>
44 static char sccsid
[] = "@(#)subr.c 8.1 (Berkeley) 5/31/93";
46 __RCSID("$NetBSD: subr.c,v 1.4 1997/10/10 11:59:53 lukem Exp $");
50 /* Re-coding of advent in C: subroutines from main */
56 /* Statement functions */
60 { if (place
[objj
] == -1) return(TRUE
);
67 { if (place
[objj
]==loc
|| toting(objj
)) return(TRUE
);
74 { if (place
[objj
]==loc
|| fixed
[objj
]==loc
) return(TRUE
);
81 { return((1-pbotl
)*water
+(pbotl
/2)*(water
+oil
));
88 if (i
>-1-i
) return(liq2(i
));
89 else return(liq2(-1-i
));
93 liqloc(locc
) /* may want to clean this one up a bit */
106 { if (cond
[l
] & setbit
[n
]) return(TRUE
);
113 { if (cond
[locc
]==2) return(TRUE
);
119 { if ((cond
[loc
]%2
)==0 && (prop
[lamp
]==0 || !here(lamp
)))
127 { if (ran(100)<n
) return(TRUE
);
137 if (newloc
!=loc
&&!forced(loc
)&&!bitset(loc
,3))
138 { for (i
=1; i
<=5; i
++)
139 { if (odloc
[i
]!=newloc
||!dseen
[i
]) continue;
146 if (loc
==0||forced(loc
)||bitset(newloc
,3)) return(2000);
148 { if (loc
>=15) dflag
=1;
151 if (dflag
==1) /* 6000 */
152 { if (loc
<15||pct(95)) return(2000);
156 if (pct(50)&&saved
== -1) dloc
[j
]=0; /* 6001 */
159 { if (dloc
[i
]==loc
) dloc
[i
]=daltlc
;
160 odloc
[i
]=dloc
[i
]; /* 6002 */
166 dtotal
=attack
=stick
=0; /* 6010 */
167 for (i
=1; i
<=6; i
++) /* loop to 6030 */
168 { if (dloc
[i
]==0) continue;
170 for (kk
=travel
[dloc
[i
]]; kk
!=0; kk
=kk
->next
)
172 if (newloc
>300||newloc
<15||newloc
==odloc
[i
]
173 ||(j
>1&&newloc
==tk
[j
-1])||j
>=20
174 ||newloc
==dloc
[i
]||forced(newloc
)
175 ||(i
==6&&bitset(newloc
,3))
176 ||kk
->conditions
==100) continue;
179 tk
[j
]=odloc
[i
]; /* 6016 */
184 dseen
[i
]=(dseen
[i
]&&loc
>=15)||(dloc
[i
]==loc
||odloc
[i
]==loc
);
185 if (!dseen
[i
]) continue; /* i.e. goto 6030 */
187 if (i
==6) /* pirate's spotted him */
188 { if (loc
==chloc
||prop
[chest
]>=0) continue;
190 for (j
=50; j
<=maxtrs
; j
++) /* loop to 6020 */
191 { if (j
==pyram
&&(loc
==plac
[pyram
]
192 || loc
==plac
[emrald
])) goto l6020
;
193 if (toting(j
)) goto l6022
;
194 l6020
: if (here(j
)) k
=1;
196 if (tally
==tally2
+1 && k
==0 && place
[chest
]==0
197 &&here(lamp
) && prop
[lamp
]==1) goto l6025
;
198 if (odloc
[6]!=dloc
[6]&&pct(20))
200 continue; /* to 6030 */
202 if (place
[messag
]==0) move(chest
,chloc
);
204 for (j
=50; j
<=maxtrs
; j
++) /* loop to 6023 */
205 { if (j
==pyram
&& (loc
==plac
[pyram
]
206 || loc
==plac
[emrald
])) continue;
207 if (at(j
)&&fixed
[j
]==0) carry(j
,loc
);
208 if (toting(j
)) drop(j
,chloc
);
210 l6024
: dloc
[6]=odloc
[6]=chloc
;
219 if (odloc
[i
]!=dloc
[i
]) continue;
221 if (knfloc
>=0) knfloc
=loc
;
222 if (ran(1000)<95*(dflag
-2)) stick
++;
224 if (dtotal
==0) return(2000);
226 { printf("There are %d threatening little dwarves ",dtotal
);
227 printf("in the room with you.\n");
230 if (attack
==0) return(2000);
231 if (dflag
==2) dflag
=3;
232 if (saved
!= -1) dflag
=20;
234 { printf("%d of them throw knives at you!\n",attack
);
236 l82
: if (stick
<=1) /* 82 */
238 if (stick
==0) return(2000);
241 printf("%d of them get you!\n",stick
); /* 83 */
252 march() /* label 8 */
255 if ((tkk
=travel
[newloc
=loc
])==0) bug(26);
256 if (k
==null
) return(2);
257 if (k
==cave
) /* 40 */
258 { if (loc
<8) rspeak(57);
259 if (loc
>=8) rspeak(58);
262 if (k
==look
) /* 30 */
263 { if (detail
++<3) rspeak(15);
268 if (k
==back
) /* 20 */
278 for (; tkk
!=0; tkk
=tkk
->next
)
279 if (tkk
->tverb
==1 || tkk
->tverb
==k
) break;
284 l11
: ll1
=tkk
->conditions
; /* 11 */
286 newloc
=ll1
; /* newloc=conditions */
287 k
=newloc%100
; /* k used for prob */
289 { if (newloc
<=100) /* 13 */
290 { if (newloc
!=0&&!pct(newloc
)) goto l12
; /* 14 */
291 l16
: newloc
=ll2
; /* newloc=location */
292 if (newloc
<=300) return(2);
294 switch(specials())/* to 30000 */
304 if (toting(k
)||(newloc
>200&&at(k
))) goto l16
;
307 if (prop
[k
]!=(newloc
/100)-3) goto l16
; /* newloc still conditions*/
308 l12
: /* alternative to probability move */
309 for (; tkk
!=0; tkk
=tkk
->next
)
310 if (tkk
->tloc
!=ll2
|| tkk
->conditions
!=ll1
) break;
319 { struct travlist
*tk2
,*j
;
321 if (forced(k
=oldloc
)) k
=oldlc2
; /* k=location */
329 for (; tkk
!=0; tkk
=tkk
->next
) /* 21 */
332 { k
=tkk
->tverb
; /* k back to verb */
338 if (forced(ll
) && k
==j
->tloc
) tk2
=tkk
;
353 specials() /* 30000 */
354 { switch(newloc
-= 300)
355 { case 1: /* 30100 */
357 if (holdng
==0||(holdng
==1&&toting(emrald
))) return(2);
364 case 3: /* to 30300 */
372 trbridge() /* 30300 */
373 { if (prop
[troll
]==1)
378 move(troll
,plac
[troll
]);
379 move(troll
+100,fixd
[troll
]);
384 newloc
=plac
[troll
]+fixd
[troll
]-loc
; /* 30310 */
385 if (prop
[troll
]==0) prop
[troll
]=1;
386 if (!toting(bear
)) return(2);
393 if (prop
[spices
]<0) tally2
++;
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;
416 { printf("Please tell jim@rand.org that fatal bug %d happened.\n",n
);
422 checkhints() /* 2600 &c */
424 for (hint
=4; hint
<=hntmax
; hint
++)
425 { if (hinted
[hint
]) continue;
426 if (!bitset(loc
,hint
)) hintlc
[hint
]= -1;
428 if (hintlc
[hint
]<hints
[hint
][1]) continue;
430 { case 4: /* 40400 */
431 if (prop
[grate
]==0&&!here(keys
)) goto l40010
;
434 if (here(bird
)&&toting(rod
)&&obj
==bird
) goto l40010
;
435 continue; /* i.e. goto l40030 */
437 if (here(snake
)&&!here(bird
)) goto l40010
;
440 if (atloc
[loc
]==0&&atloc
[oldloc
]==0
441 && atloc
[oldlc2
]==0&&holdng
>1) goto l40010
;
444 if (prop
[emrald
]!= -1&&prop
[pyram
]== -1) goto l40010
;
447 goto l40010
; /* 40900 */
450 l40010
: hintlc
[hint
]=0;
451 if (!yes(hints
[hint
][3],0,54)) continue;
452 printf("I am prepared to give you a hint, but it will ");
453 printf("cost you %d points.\n",hints
[hint
][2]);
454 hinted
[hint
]=yes(175,hints
[hint
][4],54);
455 l40020
: hintlc
[hint
]=0;
464 if (*wd2
!=0) copystr(wd2
,wd1
);
466 if (i
==62||i
==65||i
==71||i
==2025)
471 printf("\nOkay, \"%s\".\n",wd2
);
478 { if (toting(obj
)) return(2011); /* 9010 */
480 if (obj
==plant
&&prop
[plant
]<=0) spk
=115;
481 if (obj
==bear
&&prop
[bear
]==1) spk
=169;
482 if (obj
==chain
&&prop
[bear
]!=0) spk
=170;
483 if (fixed
[obj
]!=0) return(2011);
484 if (obj
==water
||obj
==oil
)
485 { if (here(bottle
)&&liq(0)==obj
)
490 if (toting(bottle
)&&prop
[bottle
]==1)
492 if (prop
[bottle
]!=1) spk
=105;
493 if (!toting(bottle
)) spk
=104;
496 l9017
: if (holdng
>=7)
501 { if (prop
[bird
]!=0) goto l9014
;
506 if (!toting(cage
)) /* 9013 */
510 prop
[bird
]=1; /* 9015 */
512 l9014
: if ((obj
==bird
||obj
==cage
)&&prop
[bird
]!=0)
513 carry(bird
+cage
-obj
,loc
);
516 if (obj
==bottle
&& k
!=0) place
[k
] = -1;
524 if (k
==obj
) obj
=bottle
;
525 if (obj
==bottle
&&k
!=0) place
[k
]=0;
526 if (obj
==cage
&&prop
[bird
]!=0) drop(bird
,loc
);
527 if (obj
==bird
) prop
[bird
]=0;
535 if (toting(rod2
)&&obj
==rod
&&!toting(rod
)) obj
=rod2
;
536 if (!toting(obj
)) return(2011);
537 if (obj
==bird
&&here(snake
))
539 if (closed
) return(19000);
544 if (obj
==coins
&&here(vend
)) /* 9024 */
550 if (obj
==bird
&&at(dragon
)&&prop
[dragon
]==0) /* 9025 */
554 if (place
[snake
]==plac
[snake
]) tally2
--;
557 if (obj
==bear
&&at(troll
)) /* 9026 */
561 move(troll2
,plac
[troll
]);
562 move(troll2
+100,fixd
[troll
]);
567 if (obj
!=vase
||loc
==plac
[pillow
]) /* 9027 */
571 prop
[vase
]=2; /* 9028 */
572 if (at(pillow
)) prop
[vase
]=0;
573 pspeak(vase
,prop
[vase
]+1);
574 if (prop
[vase
]!=0) fixed
[vase
] = -1;
581 { if (obj
==clam
||obj
==oyster
)
583 if (obj
==oyster
) k
=1;
585 if (toting(obj
)) spk
=120+k
;
586 if (!toting(tridnt
)) spk
=122+k
;
587 if (verb
==lock
) spk
=61;
588 if (spk
!=124) return(2011);
594 if (obj
==door
) spk
=111;
595 if (obj
==door
&&prop
[door
]==1) spk
=54;
596 if (obj
==cage
) spk
=32;
597 if (obj
==keys
) spk
=55;
598 if (obj
==grate
||obj
==chain
) spk
=31;
599 if (spk
!=31||!here(keys
)) return(2011);
602 { spk
=172; /* 9049: lock */
603 if (prop
[chain
]!=0) spk
=34;
604 if (loc
!=plac
[chain
]) spk
=173;
605 if (spk
!=172) return(2011);
607 if (toting(chain
)) drop(chain
,loc
);
612 if (prop
[bear
]==0) spk
=41;
613 if (prop
[chain
]==0) spk
=37;
614 if (spk
!=171) return(2011);
617 if (prop
[bear
]!=3) prop
[bear
]=2;
618 fixed
[bear
]=2-prop
[bear
];
623 if (!panic
) clock2
=15;
627 k
=34+prop
[grate
]; /* 9043 */
629 if (verb
==lock
) prop
[grate
]=0;
639 if (dloc
[i
]==loc
&&dflag
>=2) break;
641 if (obj
==0) /* 9122 */
642 { if (i
!=0) obj
=dwarf
;
643 if (here(snake
)) obj
=obj
*100+snake
;
644 if (at(dragon
)&&prop
[dragon
]==0) obj
=obj
*100+dragon
;
645 if (at(troll
)) obj
=obj
*100+troll
;
646 if (here(bear
)&&prop
[bear
]==0) obj
=obj
*100+bear
;
647 if (obj
>100) return(8000);
649 { if (here(bird
)&&verb
!=throw) obj
=bird
;
650 if (here(clam
)||here(oyster
)) obj
=100*obj
+clam
;
651 if (obj
>100) return(8000);
654 if (obj
==bird
) /* 9124 */
656 if (closed
) return(2011);
659 if (place
[snake
]==plac
[snake
]) tally2
++;
662 if (obj
==0) spk
=44; /* 9125 */
663 if (obj
==clam
||obj
==oyster
) spk
=150;
664 if (obj
==snake
) spk
=46;
665 if (obj
==dwarf
) spk
=49;
666 if (obj
==dwarf
&&closed
) return(19000);
667 if (obj
==dragon
) spk
=147;
668 if (obj
==troll
) spk
=157;
669 if (obj
==bear
) spk
=165+(prop
[bear
]+1)/2;
670 if (obj
!=dragon
||prop
[dragon
]!=0) return(2011);
675 if (!weq(wd1
,"y")&&!weq(wd1
,"yes")) return(2608);
679 k
=(plac
[dragon
]+fixd
[dragon
])/2;
684 for (obj
=1; obj
<=100; obj
++)
685 if (place
[obj
]==plac
[dragon
]||place
[obj
]==fixd
[dragon
])
694 trtoss() /* 9170: throw */
696 if (toting(rod2
)&&obj
==rod
&&!toting(rod
)) obj
=rod2
;
697 if (!toting(obj
)) return(2011);
698 if (obj
>=50&&obj
<=maxtrs
&&at(troll
))
699 { spk
=159; /* 9178 */
703 drop(troll2
,plac
[troll
]);
704 drop(troll2
+100,fixd
[troll
]);
708 if (obj
==food
&&here(bear
))
709 { obj
=bear
; /* 9177 */
712 if (obj
!=axe
) return(9020);
716 if (ran(3)==0||saved
!= -1)
717 l9175
: { rspeak(spk
);
726 if (dkill
==1) spk
=149;
731 if (at(dragon
)&&prop
[dragon
]==0)
734 if (at(troll
)) goto l9175
;
735 if (here(bear
)&&prop
[bear
]==0)
754 if (obj
==snake
||obj
==dragon
||obj
==troll
)
756 if (obj
==dragon
&&prop
[dragon
]!=0) spk
=110;
757 if (obj
==troll
) spk
=182;
758 if (obj
!=snake
||closed
||!here(bird
)) return(2011);
766 { if (!here(food
)) return(2011);
772 { if (prop
[bear
]==0) spk
=102;
773 if (prop
[bear
]==3) spk
=110;
774 if (!here(food
)) return(2011);
791 if (liqloc(loc
)==0) spk
=144;
792 if (liqloc(loc
)==0||!toting(vase
)) return(2011);
796 return(9020); /* advent/10 goes to 9024 */
798 if (obj
!=0&&obj
!=bottle
) return(2011);
799 if (obj
==0&&!here(bottle
)) return(8000);
801 if (liqloc(loc
)==0) spk
=106;
802 if (liq(0)!=0) spk
=105;
803 if (spk
!=107) return(2011);
804 prop
[bottle
]=((cond
[loc
]%4
)/2)*2;
806 if (toting(bottle
)) place
[k
]= -1;
813 closing() /* 10000 */
816 prop
[grate
]=prop
[fissur
]=0;
823 move(troll2
,plac
[troll
]);
824 move(troll2
+100,fixd
[troll
]);
826 if(prop
[bear
]!=3) dstroy(bear
);
839 caveclose() /* 11000 */
841 prop
[bottle
]=put(bottle
,115,1);
842 prop
[plant
]=put(plant
,115,0);
843 prop
[oyster
]=put(oyster
,115,0);
844 prop
[lamp
]=put(lamp
,115,0);
845 prop
[rod
]=put(rod
,115,0);
846 prop
[dwarf
]=put(dwarf
,115,0);
852 prop
[snake
]=put(snake
,116,1);
853 prop
[bird
]=put(bird
,116,1);
854 prop
[cage
]=put(cage
,116,0);
855 prop
[rod2
]=put(rod2
,116,0);
856 prop
[pillow
]=put(pillow
,116,0);
858 prop
[mirror
]=put(mirror
,115,0);
861 for (i
=1; i
<=100; i
++)
862 if (toting(i
)) dstroy(i
);