]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/subr.c
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
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.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
40 static char sccsid
[] = "@(#)subr.c 8.1 (Berkeley) 5/31/93";
43 /* Re-coding of advent in C: subroutines from main */
47 /* Statement functions */
50 { if (place
[objj
] == -1) return(TRUE
);
56 { if (place
[objj
]==loc
|| toting(objj
)) return(TRUE
);
62 { if (place
[objj
]==loc
|| fixed
[objj
]==loc
) return(TRUE
);
68 { return((1-pbotl
)*water
+(pbotl
/2)*(water
+oil
));
74 if (i
>-1-i
) return(liq2(i
));
75 else return(liq2(-1-i
));
78 liqloc(locc
) /* may want to clean this one up a bit */
90 { if (cond
[l
] & setbit
[n
]) return(TRUE
);
96 { if (cond
[locc
]==2) return(TRUE
);
101 { if ((cond
[loc
]%2
)==0 && (prop
[lamp
]==0 || !here(lamp
)))
108 { if (ran(100)<n
) return(TRUE
);
115 register struct travlist
*kk
;
117 if (newloc
!=loc
&&!forced(loc
)&&!bitset(loc
,3))
118 { for (i
=1; i
<=5; i
++)
119 { if (odloc
[i
]!=newloc
||!dseen
[i
]) continue;
126 if (loc
==0||forced(loc
)||bitset(newloc
,3)) return(2000);
128 { if (loc
>=15) dflag
=1;
131 if (dflag
==1) /* 6000 */
132 { if (loc
<15||pct(95)) return(2000);
136 if (pct(50)&&saved
== -1) dloc
[j
]=0; /* 6001 */
139 { if (dloc
[i
]==loc
) dloc
[i
]=daltlc
;
140 odloc
[i
]=dloc
[i
]; /* 6002 */
146 dtotal
=attack
=stick
=0; /* 6010 */
147 for (i
=1; i
<=6; i
++) /* loop to 6030 */
148 { if (dloc
[i
]==0) continue;
150 for (kk
=travel
[dloc
[i
]]; kk
!=0; kk
=kk
->next
)
152 if (newloc
>300||newloc
<15||newloc
==odloc
[i
]
153 ||(j
>1&&newloc
==tk
[j
-1])||j
>=20
154 ||newloc
==dloc
[i
]||forced(newloc
)
155 ||(i
==6&&bitset(newloc
,3))
156 ||kk
->conditions
==100) continue;
159 tk
[j
]=odloc
[i
]; /* 6016 */
164 dseen
[i
]=(dseen
[i
]&&loc
>=15)||(dloc
[i
]==loc
||odloc
[i
]==loc
);
165 if (!dseen
[i
]) continue; /* i.e. goto 6030 */
167 if (i
==6) /* pirate's spotted him */
168 { if (loc
==chloc
||prop
[chest
]>=0) continue;
170 for (j
=50; j
<=maxtrs
; j
++) /* loop to 6020 */
171 { if (j
==pyram
&&(loc
==plac
[pyram
]
172 || loc
==plac
[emrald
])) goto l6020
;
173 if (toting(j
)) goto l6022
;
174 l6020
: if (here(j
)) k
=1;
176 if (tally
==tally2
+1 && k
==0 && place
[chest
]==0
177 &&here(lamp
) && prop
[lamp
]==1) goto l6025
;
178 if (odloc
[6]!=dloc
[6]&&pct(20))
180 continue; /* to 6030 */
182 if (place
[messag
]==0) move(chest
,chloc
);
184 for (j
=50; j
<=maxtrs
; j
++) /* loop to 6023 */
185 { if (j
==pyram
&& (loc
==plac
[pyram
]
186 || loc
==plac
[emrald
])) continue;
187 if (at(j
)&&fixed
[j
]==0) carry(j
,loc
);
188 if (toting(j
)) drop(j
,chloc
);
190 l6024
: dloc
[6]=odloc
[6]=chloc
;
199 if (odloc
[i
]!=dloc
[i
]) continue;
201 if (knfloc
>=0) knfloc
=loc
;
202 if (ran(1000)<95*(dflag
-2)) stick
++;
204 if (dtotal
==0) return(2000);
206 { printf("There are %d threatening little dwarves ",dtotal
);
207 printf("in the room with you.\n");
210 if (attack
==0) return(2000);
211 if (dflag
==2) dflag
=3;
212 if (saved
!= -1) dflag
=20;
214 { printf("%d of them throw knives at you!\n",attack
);
216 l82
: if (stick
<=1) /* 82 */
218 if (stick
==0) return(2000);
221 printf("%d of them get you!\n",stick
); /* 83 */
231 march() /* label 8 */
232 { register int ll1
,ll2
;
234 if ((tkk
=travel
[newloc
=loc
])==0) bug(26);
235 if (k
==null
) return(2);
236 if (k
==cave
) /* 40 */
237 { if (loc
<8) rspeak(57);
238 if (loc
>=8) rspeak(58);
241 if (k
==look
) /* 30 */
242 { if (detail
++<3) rspeak(15);
247 if (k
==back
) /* 20 */
257 for (; tkk
!=0; tkk
=tkk
->next
)
258 if (tkk
->tverb
==1 || tkk
->tverb
==k
) break;
263 l11
: ll1
=tkk
->conditions
; /* 11 */
265 newloc
=ll1
; /* newloc=conditions */
266 k
=newloc%100
; /* k used for prob */
268 { if (newloc
<=100) /* 13 */
269 { if (newloc
!=0&&!pct(newloc
)) goto l12
; /* 14 */
270 l16
: newloc
=ll2
; /* newloc=location */
271 if (newloc
<=300) return(2);
273 switch(specials())/* to 30000 */
283 if (toting(k
)||(newloc
>200&&at(k
))) goto l16
;
286 if (prop
[k
]!=(newloc
/100)-3) goto l16
; /* newloc still conditions*/
287 l12
: /* alternative to probability move */
288 for (; tkk
!=0; tkk
=tkk
->next
)
289 if (tkk
->tloc
!=ll2
|| tkk
->conditions
!=ll1
) break;
297 { register struct travlist
*tk2
,*j
;
299 if (forced(k
=oldloc
)) k
=oldlc2
; /* k=location */
307 for (; tkk
!=0; tkk
=tkk
->next
) /* 21 */
310 { k
=tkk
->tverb
; /* k back to verb */
316 if (forced(ll
) && k
==j
->tloc
) tk2
=tkk
;
330 specials() /* 30000 */
331 { switch(newloc
-= 300)
332 { case 1: /* 30100 */
334 if (holdng
==0||(holdng
==1&&toting(emrald
))) return(2);
341 case 3: /* to 30300 */
348 trbridge() /* 30300 */
349 { if (prop
[troll
]==1)
354 move(troll
,plac
[troll
]);
355 move(troll
+100,fixd
[troll
]);
360 newloc
=plac
[troll
]+fixd
[troll
]-loc
; /* 30310 */
361 if (prop
[troll
]==0) prop
[troll
]=1;
362 if (!toting(bear
)) return(2);
369 if (prop
[spices
]<0) tally2
++;
377 if (k
>=43 && k
<=50) spk
=9;
378 if (k
==29||k
==30) spk
=9;
379 if (k
==7||k
==36||k
==37) spk
=10;
380 if (k
==11||k
==19) spk
=11;
381 if (verb
==find
||verb
==invent
) spk
=59;
382 if (k
==62||k
==65) spk
=42;
390 { printf("Please tell jim@rand.org that fatal bug %d happened.\n",n
);
395 checkhints() /* 2600 &c */
397 for (hint
=4; hint
<=hntmax
; hint
++)
398 { if (hinted
[hint
]) continue;
399 if (!bitset(loc
,hint
)) hintlc
[hint
]= -1;
401 if (hintlc
[hint
]<hints
[hint
][1]) continue;
403 { case 4: /* 40400 */
404 if (prop
[grate
]==0&&!here(keys
)) goto l40010
;
407 if (here(bird
)&&toting(rod
)&&obj
==bird
) goto l40010
;
408 continue; /* i.e. goto l40030 */
410 if (here(snake
)&&!here(bird
)) goto l40010
;
413 if (atloc
[loc
]==0&&atloc
[oldloc
]==0
414 && atloc
[oldlc2
]==0&&holdng
>1) goto l40010
;
417 if (prop
[emrald
]!= -1&&prop
[pyram
]== -1) goto l40010
;
420 goto l40010
; /* 40900 */
423 l40010
: hintlc
[hint
]=0;
424 if (!yes(hints
[hint
][3],0,54)) continue;
425 printf("I am prepared to give you a hint, but it will ");
426 printf("cost you %d points.\n",hints
[hint
][2]);
427 hinted
[hint
]=yes(175,hints
[hint
][4],54);
428 l40020
: hintlc
[hint
]=0;
435 if (*wd2
!=0) copystr(wd2
,wd1
);
437 if (i
==62||i
==65||i
==71||i
==2025)
442 printf("\nOkay, \"%s\".\n",wd2
);
449 if (toting(obj
)) return(2011); /* 9010 */
451 if (obj
==plant
&&prop
[plant
]<=0) spk
=115;
452 if (obj
==bear
&&prop
[bear
]==1) spk
=169;
453 if (obj
==chain
&&prop
[bear
]!=0) spk
=170;
454 if (fixed
[obj
]!=0) return(2011);
455 if (obj
==water
||obj
==oil
)
456 { if (here(bottle
)&&liq(0)==obj
)
461 if (toting(bottle
)&&prop
[bottle
]==1)
463 if (prop
[bottle
]!=1) spk
=105;
464 if (!toting(bottle
)) spk
=104;
467 l9017
: if (holdng
>=7)
472 { if (prop
[bird
]!=0) goto l9014
;
477 if (!toting(cage
)) /* 9013 */
481 prop
[bird
]=1; /* 9015 */
483 l9014
: if ((obj
==bird
||obj
==cage
)&&prop
[bird
]!=0)
484 carry(bird
+cage
-obj
,loc
);
487 if (obj
==bottle
&& k
!=0) place
[k
] = -1;
494 if (k
==obj
) obj
=bottle
;
495 if (obj
==bottle
&&k
!=0) place
[k
]=0;
496 if (obj
==cage
&&prop
[bird
]!=0) drop(bird
,loc
);
497 if (obj
==bird
) prop
[bird
]=0;
504 if (toting(rod2
)&&obj
==rod
&&!toting(rod
)) obj
=rod2
;
505 if (!toting(obj
)) return(2011);
506 if (obj
==bird
&&here(snake
))
508 if (closed
) return(19000);
513 if (obj
==coins
&&here(vend
)) /* 9024 */
519 if (obj
==bird
&&at(dragon
)&&prop
[dragon
]==0) /* 9025 */
523 if (place
[snake
]==plac
[snake
]) tally2
--;
526 if (obj
==bear
&&at(troll
)) /* 9026 */
530 move(troll2
,plac
[troll
]);
531 move(troll2
+100,fixd
[troll
]);
536 if (obj
!=vase
||loc
==plac
[pillow
]) /* 9027 */
540 prop
[vase
]=2; /* 9028 */
541 if (at(pillow
)) prop
[vase
]=0;
542 pspeak(vase
,prop
[vase
]+1);
543 if (prop
[vase
]!=0) fixed
[vase
] = -1;
549 { if (obj
==clam
||obj
==oyster
)
551 if (obj
==oyster
) k
=1;
553 if (toting(obj
)) spk
=120+k
;
554 if (!toting(tridnt
)) spk
=122+k
;
555 if (verb
==lock
) spk
=61;
556 if (spk
!=124) return(2011);
562 if (obj
==door
) spk
=111;
563 if (obj
==door
&&prop
[door
]==1) spk
=54;
564 if (obj
==cage
) spk
=32;
565 if (obj
==keys
) spk
=55;
566 if (obj
==grate
||obj
==chain
) spk
=31;
567 if (spk
!=31||!here(keys
)) return(2011);
570 { spk
=172; /* 9049: lock */
571 if (prop
[chain
]!=0) spk
=34;
572 if (loc
!=plac
[chain
]) spk
=173;
573 if (spk
!=172) return(2011);
575 if (toting(chain
)) drop(chain
,loc
);
580 if (prop
[bear
]==0) spk
=41;
581 if (prop
[chain
]==0) spk
=37;
582 if (spk
!=171) return(2011);
585 if (prop
[bear
]!=3) prop
[bear
]=2;
586 fixed
[bear
]=2-prop
[bear
];
591 if (!panic
) clock2
=15;
595 k
=34+prop
[grate
]; /* 9043 */
597 if (verb
==lock
) prop
[grate
]=0;
606 if (dloc
[i
]==loc
&&dflag
>=2) break;
608 if (obj
==0) /* 9122 */
609 { if (i
!=0) obj
=dwarf
;
610 if (here(snake
)) obj
=obj
*100+snake
;
611 if (at(dragon
)&&prop
[dragon
]==0) obj
=obj
*100+dragon
;
612 if (at(troll
)) obj
=obj
*100+troll
;
613 if (here(bear
)&&prop
[bear
]==0) obj
=obj
*100+bear
;
614 if (obj
>100) return(8000);
616 { if (here(bird
)&&verb
!=throw) obj
=bird
;
617 if (here(clam
)||here(oyster
)) obj
=100*obj
+clam
;
618 if (obj
>100) return(8000);
621 if (obj
==bird
) /* 9124 */
623 if (closed
) return(2011);
626 if (place
[snake
]==plac
[snake
]) tally2
++;
629 if (obj
==0) spk
=44; /* 9125 */
630 if (obj
==clam
||obj
==oyster
) spk
=150;
631 if (obj
==snake
) spk
=46;
632 if (obj
==dwarf
) spk
=49;
633 if (obj
==dwarf
&&closed
) return(19000);
634 if (obj
==dragon
) spk
=147;
635 if (obj
==troll
) spk
=157;
636 if (obj
==bear
) spk
=165+(prop
[bear
]+1)/2;
637 if (obj
!=dragon
||prop
[dragon
]!=0) return(2011);
642 if (!weq(wd1
,"y")&&!weq(wd1
,"yes")) return(2608);
646 k
=(plac
[dragon
]+fixd
[dragon
])/2;
651 for (obj
=1; obj
<=100; obj
++)
652 if (place
[obj
]==plac
[dragon
]||place
[obj
]==fixd
[dragon
])
660 trtoss() /* 9170: throw */
662 if (toting(rod2
)&&obj
==rod
&&!toting(rod
)) obj
=rod2
;
663 if (!toting(obj
)) return(2011);
664 if (obj
>=50&&obj
<=maxtrs
&&at(troll
))
665 { spk
=159; /* 9178 */
669 drop(troll2
,plac
[troll
]);
670 drop(troll2
+100,fixd
[troll
]);
674 if (obj
==food
&&here(bear
))
675 { obj
=bear
; /* 9177 */
678 if (obj
!=axe
) return(9020);
682 if (ran(3)==0||saved
!= -1)
683 l9175
: { rspeak(spk
);
692 if (dkill
==1) spk
=149;
697 if (at(dragon
)&&prop
[dragon
]==0)
700 if (at(troll
)) goto l9175
;
701 if (here(bear
)&&prop
[bear
]==0)
719 if (obj
==snake
||obj
==dragon
||obj
==troll
)
721 if (obj
==dragon
&&prop
[dragon
]!=0) spk
=110;
722 if (obj
==troll
) spk
=182;
723 if (obj
!=snake
||closed
||!here(bird
)) return(2011);
731 { if (!here(food
)) return(2011);
737 { if (prop
[bear
]==0) spk
=102;
738 if (prop
[bear
]==3) spk
=110;
739 if (!here(food
)) return(2011);
755 if (liqloc(loc
)==0) spk
=144;
756 if (liqloc(loc
)==0||!toting(vase
)) return(2011);
760 return(9020); /* advent/10 goes to 9024 */
762 if (obj
!=0&&obj
!=bottle
) return(2011);
763 if (obj
==0&&!here(bottle
)) return(8000);
765 if (liqloc(loc
)==0) spk
=106;
766 if (liq(0)!=0) spk
=105;
767 if (spk
!=107) return(2011);
768 prop
[bottle
]=((cond
[loc
]%4
)/2)*2;
770 if (toting(bottle
)) place
[k
]= -1;
776 closing() /* 10000 */
779 prop
[grate
]=prop
[fissur
]=0;
786 move(troll2
,plac
[troll
]);
787 move(troll2
+100,fixd
[troll
]);
789 if(prop
[bear
]!=3) dstroy(bear
);
801 caveclose() /* 11000 */
803 prop
[bottle
]=put(bottle
,115,1);
804 prop
[plant
]=put(plant
,115,0);
805 prop
[oyster
]=put(oyster
,115,0);
806 prop
[lamp
]=put(lamp
,115,0);
807 prop
[rod
]=put(rod
,115,0);
808 prop
[dwarf
]=put(dwarf
,115,0);
814 prop
[snake
]=put(snake
,116,1);
815 prop
[bird
]=put(bird
,116,1);
816 prop
[cage
]=put(cage
,116,0);
817 prop
[rod2
]=put(rod2
,116,0);
818 prop
[pillow
]=put(pillow
,116,0);
820 prop
[mirror
]=put(mirror
,115,0);
823 for (i
=1; i
<=100; i
++)
824 if (toting(i
)) dstroy(i
);