]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/subr.c
1 /* $NetBSD: subr.c,v 1.10 2003/08/07 09:36:51 agc 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. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
40 static char sccsid
[] = "@(#)subr.c 8.1 (Berkeley) 5/31/93";
42 __RCSID("$NetBSD: subr.c,v 1.10 2003/08/07 09:36:51 agc Exp $");
46 /* Re-coding of advent in C: subroutines from main */
53 /* Statement functions */
58 if (place
[objj
] == -1)
68 if (place
[objj
] == loc
|| toting(objj
))
78 if (place
[objj
] == loc
|| fixed
[objj
] == loc
)
88 return ((1 - pbotl
) * water
+ (pbotl
/ 2) * (water
+ oil
));
99 return (liq2(-1 - i
));
103 liqloc(locc
) /* may want to clean this one up a bit */
108 j
= ((i
* 2) % 8) - 5;
111 return (liq2(j
* l
+ 1));
118 if (cond
[l
] & setbit
[n
])
135 if ((cond
[loc
] % 2) == 0 && (prop
[lamp
] == 0 || !here(lamp
)))
156 if (newloc
!= loc
&& !forced(loc
) && !bitset(loc
, 3)) {
157 for (i
= 1; i
<= 5; i
++) {
158 if (odloc
[i
] != newloc
|| !dseen
[i
])
165 loc
= newloc
; /* 74 */
166 if (loc
== 0 || forced(loc
) || bitset(newloc
, 3))
173 if (dflag
== 1) { /* 6000 */
174 if (loc
< 15 || pct(95))
177 for (i
= 1; i
<= 2; i
++) {
179 if (pct(50) && saved
== -1)
180 dloc
[j
] = 0; /* 6001 */
182 for (i
= 1; i
<= 5; i
++) {
185 odloc
[i
] = dloc
[i
]; /* 6002 */
191 dtotal
= attack
= stick
= 0; /* 6010 */
192 for (i
= 1; i
<= 6; i
++) { /* loop to 6030 */
196 for (kk
= travel
[dloc
[i
]]; kk
!= 0; kk
= kk
->next
) {
198 if (newloc
> 300 || newloc
< 15 || newloc
== odloc
[i
]
199 || (j
> 1 && newloc
== tk
[j
- 1]) || j
>= 20
200 || newloc
== dloc
[i
] || forced(newloc
)
201 || (i
== 6 && bitset(newloc
, 3))
202 || kk
->conditions
== 100)
206 tk
[j
] = odloc
[i
]; /* 6016 */
212 dseen
[i
] = (dseen
[i
] && loc
>= 15) || (dloc
[i
] == loc
|| odloc
[i
] == loc
);
214 continue; /* i.e. goto 6030 */
216 if (i
== 6) { /* pirate's spotted him */
217 if (loc
== chloc
|| prop
[chest
] >= 0)
220 for (j
= 50; j
<= maxtrs
; j
++) { /* loop to 6020 */
221 if (j
== pyram
&& (loc
== plac
[pyram
]
222 || loc
== plac
[emrald
]))
229 if (tally
== tally2
+ 1 && k
== 0 && place
[chest
] == 0
230 && here(lamp
) && prop
[lamp
] == 1)
232 if (odloc
[6] != dloc
[6] && pct(20))
234 continue; /* to 6030 */
236 if (place
[messag
] == 0)
238 move(messag
, chloc2
);
239 for (j
= 50; j
<= maxtrs
; j
++) { /* loop to 6023 */
240 if (j
== pyram
&& (loc
== plac
[pyram
]
241 || loc
== plac
[emrald
]))
243 if (at(j
) && fixed
[j
] == 0)
248 l6024
: dloc
[6] = odloc
[6] = chloc
;
253 move(messag
, chloc2
);
257 if (odloc
[i
] != dloc
[i
])
262 if (ran(1000) < 95 * (dflag
- 2))
268 printf("There are %d threatening little dwarves ", dtotal
);
269 printf("in the room with you.\n");
279 printf("%d of them throw knives at you!\n", attack
);
281 l82
: if (stick
<= 1) { /* 82 */
286 printf("%d of them get you!\n", stick
); /* 83 */
301 if ((tkk
= travel
[newloc
= loc
]) == 0)
305 if (k
== cave
) { /* 40 */
312 if (k
== look
) { /* 30 */
319 if (k
== back
) { /* 20 */
332 for (; tkk
!= 0; tkk
= tkk
->next
)
333 if (tkk
->tverb
== 1 || tkk
->tverb
== k
)
339 l11
: ll1
= tkk
->conditions
; /* 11 */
341 newloc
= ll1
; /* newloc=conditions */
342 k
= newloc
% 100; /* k used for prob */
344 if (newloc
<= 100) { /* 13 */
345 if (newloc
!= 0 && !pct(newloc
))
347 l16
: newloc
= ll2
; /* newloc=location */
351 switch (specials()) { /* to 30000 */
361 rspeak(newloc
- 500);
365 if (toting(k
) || (newloc
> 200 && at(k
)))
369 if (prop
[k
] != (newloc
/ 100) - 3)
370 goto l16
; /* newloc still conditions */
371 l12
: /* alternative to probability move */
372 for (; tkk
!= 0; tkk
= tkk
->next
)
373 if (tkk
->tloc
!= ll2
|| tkk
->conditions
!= ll1
)
385 struct travlist
*tk2
, *j
;
387 if (forced(k
= oldloc
))
388 k
= oldlc2
; /* k=location */
396 for (; tkk
!= 0; tkk
= tkk
->next
) { /* 21 */
399 k
= tkk
->tverb
; /* k back to verb */
405 if (forced(ll
) && k
== j
->tloc
)
423 switch (newloc
-= 300) {
425 newloc
= 99 + 100 - loc
;
426 if (holdng
== 0 || (holdng
== 1 && toting(emrald
)))
434 case 3: /* to 30300 */
445 if (prop
[troll
] == 1) {
449 move(troll2
+ 100, 0);
450 move(troll
, plac
[troll
]);
451 move(troll
+ 100, fixd
[troll
]);
456 newloc
= plac
[troll
] + fixd
[troll
] - loc
; /* 30310 */
457 if (prop
[troll
] == 0)
467 if (prop
[spices
] < 0)
478 if (k
>= 43 && k
<= 50)
480 if (k
== 29 || k
== 30)
482 if (k
== 7 || k
== 36 || k
== 37)
484 if (k
== 11 || k
== 19)
486 if (verb
== find
|| verb
== invent
)
488 if (k
== 62 || k
== 65)
499 printf("Please tell jim@rand.org that fatal bug %d happened.\n", n
);
508 for (hint
= 4; hint
<= hntmax
; hint
++) {
511 if (!bitset(loc
, hint
))
514 if (hintlc
[hint
] < hints
[hint
][1])
518 if (prop
[grate
] == 0 && !here(keys
))
522 if (here(bird
) && toting(rod
) && obj
== bird
)
524 continue; /* i.e. goto l40030 */
526 if (here(snake
) && !here(bird
))
530 if (atloc
[loc
] == 0 && atloc
[oldloc
] == 0
531 && atloc
[oldlc2
] == 0 && holdng
> 1)
535 if (prop
[emrald
] != -1 && prop
[pyram
] == -1)
539 goto l40010
; /* 40900 */
543 l40010
: hintlc
[hint
] = 0;
544 if (!yes(hints
[hint
][3], 0, 54))
546 printf("I am prepared to give you a hint, but it will ");
547 printf("cost you %d points.\n", hints
[hint
][2]);
548 hinted
[hint
] = yes(175, hints
[hint
][4], 54);
549 l40020
: hintlc
[hint
] = 0;
560 i
= vocab(wd1
, -1, 0);
561 if (i
== 62 || i
== 65 || i
== 71 || i
== 2025) {
566 printf("\nOkay, \"%s\".\n", wd2
);
575 return (2011); /* 9010 */
577 if (obj
== plant
&& prop
[plant
] <= 0)
579 if (obj
== bear
&& prop
[bear
] == 1)
581 if (obj
== chain
&& prop
[bear
] != 0)
585 if (obj
== water
|| obj
== oil
) {
586 if (here(bottle
) && liq() == obj
) {
591 if (toting(bottle
) && prop
[bottle
] == 1)
593 if (prop
[bottle
] != 1)
599 l9017
: if (holdng
>= 7) {
610 if (!toting(cage
)) { /* 9013 */
614 prop
[bird
] = 1; /* 9015 */
616 l9014
: if ((obj
== bird
|| obj
== cage
) && prop
[bird
] != 0)
617 carry(bird
+ cage
- obj
, loc
);
620 if (obj
== bottle
&& k
!= 0)
632 if (obj
== bottle
&& k
!= 0)
634 if (obj
== cage
&& prop
[bird
] != 0)
645 if (toting(rod2
) && obj
== rod
&& !toting(rod
))
649 if (obj
== bird
&& here(snake
)) {
657 if (obj
== coins
&& here(vend
)) { /* 9024 */
663 if (obj
== bird
&& at(dragon
) && prop
[dragon
] == 0) { /* 9025 */
667 if (place
[snake
] == plac
[snake
])
671 if (obj
== bear
&& at(troll
)) { /* 9026 */
674 move(troll
+ 100, 0);
675 move(troll2
, plac
[troll
]);
676 move(troll2
+ 100, fixd
[troll
]);
681 if (obj
!= vase
|| loc
== plac
[pillow
]) { /* 9027 */
685 prop
[vase
] = 2; /* 9028 */
688 pspeak(vase
, prop
[vase
] + 1);
698 if (obj
== clam
|| obj
== oyster
) {
718 if (obj
== door
&& prop
[door
] == 1)
724 if (obj
== grate
|| obj
== chain
)
726 if (spk
!= 31 || !here(keys
))
730 spk
= 172; /* 9049: lock */
731 if (prop
[chain
] != 0)
733 if (loc
!= plac
[chain
])
746 if (prop
[chain
] == 0)
754 fixed
[bear
] = 2 - prop
[bear
];
764 k
= 34 + prop
[grate
]; /* 9043 */
768 k
= k
+ 2 * prop
[grate
];
777 for (i
= 1; i
<= 5; i
++)
778 if (dloc
[i
] == loc
&& dflag
>= 2)
782 if (obj
== 0) { /* 9122 */
786 obj
= obj
* 100 + snake
;
787 if (at(dragon
) && prop
[dragon
] == 0)
788 obj
= obj
* 100 + dragon
;
790 obj
= obj
* 100 + troll
;
791 if (here(bear
) && prop
[bear
] == 0)
792 obj
= obj
* 100 + bear
;
796 if (here(bird
) && verb
!= throw)
798 if (here(clam
) || here(oyster
))
799 obj
= 100 * obj
+ clam
;
804 if (obj
== bird
) { /* 9124 */
810 if (place
[snake
] == plac
[snake
])
816 if (obj
== clam
|| obj
== oyster
)
822 if (obj
== dwarf
&& closed
)
829 spk
= 165 + (prop
[bear
] + 1) / 2;
830 if (obj
!= dragon
|| prop
[dragon
] != 0)
836 if (!weq(wd1
, "y") && !weq(wd1
, "yes"))
841 k
= (plac
[dragon
] + fixd
[dragon
]) / 2;
842 move(dragon
+ 100, -1);
846 for (obj
= 1; obj
<= 100; obj
++)
847 if (place
[obj
] == plac
[dragon
] || place
[obj
] == fixd
[dragon
])
859 if (toting(rod2
) && obj
== rod
&& !toting(rod
))
863 if (obj
>= 50 && obj
<= maxtrs
&& at(troll
)) {
864 spk
= 159; /* 9178 */
867 move(troll
+ 100, 0);
868 drop(troll2
, plac
[troll
]);
869 drop(troll2
+ 100, fixd
[troll
]);
873 if (obj
== food
&& here(bear
)) {
874 obj
= bear
; /* 9177 */
879 for (i
= 1; i
<= 5; i
++) {
880 if (dloc
[i
] == loc
) {
882 if (ran(3) == 0 || saved
!= -1)
899 if (at(dragon
) && prop
[dragon
] == 0)
904 if (here(bear
) && prop
[bear
] == 0) {
924 if (obj
== snake
|| obj
== dragon
|| obj
== troll
) {
926 if (obj
== dragon
&& prop
[dragon
] != 0)
930 if (obj
!= snake
|| closed
|| !here(bird
))
969 if (liqloc(loc
) == 0)
971 if (liqloc(loc
) == 0 || !toting(vase
))
976 return (9020); /* advent/10 goes to 9024 */
978 if (obj
!= 0 && obj
!= bottle
)
980 if (obj
== 0 && !here(bottle
))
983 if (liqloc(loc
) == 0)
989 prop
[bottle
] = ((cond
[loc
] % 4) / 2) * 2;
1004 prop
[grate
] = prop
[fissur
] = 0;
1005 for (i
= 1; i
<= 6; i
++) {
1010 move(troll
+ 100, 0);
1011 move(troll2
, plac
[troll
]);
1012 move(troll2
+ 100, fixd
[troll
]);
1014 if (prop
[bear
] != 3)
1030 prop
[bottle
] = put(bottle
, 115, 1);
1031 prop
[plant
] = put(plant
, 115, 0);
1032 prop
[oyster
] = put(oyster
, 115, 0);
1033 prop
[lamp
] = put(lamp
, 115, 0);
1034 prop
[rod
] = put(rod
, 115, 0);
1035 prop
[dwarf
] = put(dwarf
, 115, 0);
1041 prop
[snake
] = put(snake
, 116, 1);
1042 prop
[bird
] = put(bird
, 116, 1);
1043 prop
[cage
] = put(cage
, 116, 0);
1044 prop
[rod2
] = put(rod2
, 116, 0);
1045 prop
[pillow
] = put(pillow
, 116, 0);
1047 prop
[mirror
] = put(mirror
, 115, 0);
1048 fixed
[mirror
] = 116;
1050 for (i
= 1; i
<= 100; i
++)