]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/subr.c
1 /* $NetBSD: subr.c,v 1.6 1998/08/24 22:07:37 hubertf 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.6 1998/08/24 22:07:37 hubertf Exp $");
50 /* Re-coding of advent in C: subroutines from main */
56 /* Statement functions */
61 if (place
[objj
] == -1)
71 if (place
[objj
] == loc
|| toting(objj
))
81 if (place
[objj
] == loc
|| fixed
[objj
] == loc
)
91 return ((1 - pbotl
) * water
+ (pbotl
/ 2) * (water
+ oil
));
102 return (liq2(-1 - i
));
106 liqloc(locc
) /* may want to clean this one up a bit */
111 j
= ((i
* 2) % 8) - 5;
114 return (liq2(j
* l
+ 1));
121 if (cond
[l
] & setbit
[n
])
138 if ((cond
[loc
] % 2) == 0 && (prop
[lamp
] == 0 || !here(lamp
)))
159 if (newloc
!= loc
&& !forced(loc
) && !bitset(loc
, 3)) {
160 for (i
= 1; i
<= 5; i
++) {
161 if (odloc
[i
] != newloc
|| !dseen
[i
])
168 loc
= newloc
; /* 74 */
169 if (loc
== 0 || forced(loc
) || bitset(newloc
, 3))
176 if (dflag
== 1) { /* 6000 */
177 if (loc
< 15 || pct(95))
180 for (i
= 1; i
<= 2; i
++) {
182 if (pct(50) && saved
== -1)
183 dloc
[j
] = 0; /* 6001 */
185 for (i
= 1; i
<= 5; i
++) {
188 odloc
[i
] = dloc
[i
]; /* 6002 */
194 dtotal
= attack
= stick
= 0; /* 6010 */
195 for (i
= 1; i
<= 6; i
++) { /* loop to 6030 */
199 for (kk
= travel
[dloc
[i
]]; kk
!= 0; kk
= kk
->next
) {
201 if (newloc
> 300 || newloc
< 15 || newloc
== odloc
[i
]
202 || (j
> 1 && newloc
== tk
[j
- 1]) || j
>= 20
203 || newloc
== dloc
[i
] || forced(newloc
)
204 || (i
== 6 && bitset(newloc
, 3))
205 || kk
->conditions
== 100)
209 tk
[j
] = odloc
[i
]; /* 6016 */
215 dseen
[i
] = (dseen
[i
] && loc
>= 15) || (dloc
[i
] == loc
|| odloc
[i
] == loc
);
217 continue; /* i.e. goto 6030 */
219 if (i
== 6) { /* pirate's spotted him */
220 if (loc
== chloc
|| prop
[chest
] >= 0)
223 for (j
= 50; j
<= maxtrs
; j
++) { /* loop to 6020 */
224 if (j
== pyram
&& (loc
== plac
[pyram
]
225 || loc
== plac
[emrald
]))
232 if (tally
== tally2
+ 1 && k
== 0 && place
[chest
] == 0
233 && here(lamp
) && prop
[lamp
] == 1)
235 if (odloc
[6] != dloc
[6] && pct(20))
237 continue; /* to 6030 */
239 if (place
[messag
] == 0)
241 move(messag
, chloc2
);
242 for (j
= 50; j
<= maxtrs
; j
++) { /* loop to 6023 */
243 if (j
== pyram
&& (loc
== plac
[pyram
]
244 || loc
== plac
[emrald
]))
246 if (at(j
) && fixed
[j
] == 0)
251 l6024
: dloc
[6] = odloc
[6] = chloc
;
256 move(messag
, chloc2
);
260 if (odloc
[i
] != dloc
[i
])
265 if (ran(1000) < 95 * (dflag
- 2))
271 printf("There are %d threatening little dwarves ", dtotal
);
272 printf("in the room with you.\n");
282 printf("%d of them throw knives at you!\n", attack
);
284 l82
: if (stick
<= 1) { /* 82 */
289 printf("%d of them get you!\n", stick
); /* 83 */
304 if ((tkk
= travel
[newloc
= loc
]) == 0)
308 if (k
== cave
) { /* 40 */
315 if (k
== look
) { /* 30 */
322 if (k
== back
) { /* 20 */
335 for (; tkk
!= 0; tkk
= tkk
->next
)
336 if (tkk
->tverb
== 1 || tkk
->tverb
== k
)
342 l11
: ll1
= tkk
->conditions
; /* 11 */
344 newloc
= ll1
; /* newloc=conditions */
345 k
= newloc
% 100; /* k used for prob */
347 if (newloc
<= 100) { /* 13 */
348 if (newloc
!= 0 && !pct(newloc
))
350 l16
: newloc
= ll2
; /* newloc=location */
354 switch (specials()) { /* to 30000 */
364 rspeak(newloc
- 500);
368 if (toting(k
) || (newloc
> 200 && at(k
)))
372 if (prop
[k
] != (newloc
/ 100) - 3)
373 goto l16
; /* newloc still conditions */
374 l12
: /* alternative to probability move */
375 for (; tkk
!= 0; tkk
= tkk
->next
)
376 if (tkk
->tloc
!= ll2
|| tkk
->conditions
!= ll1
)
388 struct travlist
*tk2
, *j
;
390 if (forced(k
= oldloc
))
391 k
= oldlc2
; /* k=location */
399 for (; tkk
!= 0; tkk
= tkk
->next
) { /* 21 */
402 k
= tkk
->tverb
; /* k back to verb */
408 if (forced(ll
) && k
== j
->tloc
)
426 switch (newloc
-= 300) {
428 newloc
= 99 + 100 - loc
;
429 if (holdng
== 0 || (holdng
== 1 && toting(emrald
)))
437 case 3: /* to 30300 */
448 if (prop
[troll
] == 1) {
452 move(troll2
+ 100, 0);
453 move(troll
, plac
[troll
]);
454 move(troll
+ 100, fixd
[troll
]);
459 newloc
= plac
[troll
] + fixd
[troll
] - loc
; /* 30310 */
460 if (prop
[troll
] == 0)
470 if (prop
[spices
] < 0)
481 if (k
>= 43 && k
<= 50)
483 if (k
== 29 || k
== 30)
485 if (k
== 7 || k
== 36 || k
== 37)
487 if (k
== 11 || k
== 19)
489 if (verb
== find
|| verb
== invent
)
491 if (k
== 62 || k
== 65)
503 printf("Please tell jim@rand.org that fatal bug %d happened.\n", n
);
512 for (hint
= 4; hint
<= hntmax
; hint
++) {
515 if (!bitset(loc
, hint
))
518 if (hintlc
[hint
] < hints
[hint
][1])
522 if (prop
[grate
] == 0 && !here(keys
))
526 if (here(bird
) && toting(rod
) && obj
== bird
)
528 continue; /* i.e. goto l40030 */
530 if (here(snake
) && !here(bird
))
534 if (atloc
[loc
] == 0 && atloc
[oldloc
] == 0
535 && atloc
[oldlc2
] == 0 && holdng
> 1)
539 if (prop
[emrald
] != -1 && prop
[pyram
] == -1)
543 goto l40010
; /* 40900 */
547 l40010
: hintlc
[hint
] = 0;
548 if (!yes(hints
[hint
][3], 0, 54))
550 printf("I am prepared to give you a hint, but it will ");
551 printf("cost you %d points.\n", hints
[hint
][2]);
552 hinted
[hint
] = yes(175, hints
[hint
][4], 54);
553 l40020
: hintlc
[hint
] = 0;
565 i
= vocab(wd1
, -1, 0);
566 if (i
== 62 || i
== 65 || i
== 71 || i
== 2025) {
571 printf("\nOkay, \"%s\".\n", wd2
);
580 return (2011); /* 9010 */
582 if (obj
== plant
&& prop
[plant
] <= 0)
584 if (obj
== bear
&& prop
[bear
] == 1)
586 if (obj
== chain
&& prop
[bear
] != 0)
590 if (obj
== water
|| obj
== oil
) {
591 if (here(bottle
) && liq() == obj
) {
596 if (toting(bottle
) && prop
[bottle
] == 1)
598 if (prop
[bottle
] != 1)
604 l9017
: if (holdng
>= 7) {
615 if (!toting(cage
)) { /* 9013 */
619 prop
[bird
] = 1; /* 9015 */
621 l9014
: if ((obj
== bird
|| obj
== cage
) && prop
[bird
] != 0)
622 carry(bird
+ cage
- obj
, loc
);
625 if (obj
== bottle
&& k
!= 0)
637 if (obj
== bottle
&& k
!= 0)
639 if (obj
== cage
&& prop
[bird
] != 0)
650 if (toting(rod2
) && obj
== rod
&& !toting(rod
))
654 if (obj
== bird
&& here(snake
)) {
662 if (obj
== coins
&& here(vend
)) { /* 9024 */
668 if (obj
== bird
&& at(dragon
) && prop
[dragon
] == 0) { /* 9025 */
672 if (place
[snake
] == plac
[snake
])
676 if (obj
== bear
&& at(troll
)) { /* 9026 */
679 move(troll
+ 100, 0);
680 move(troll2
, plac
[troll
]);
681 move(troll2
+ 100, fixd
[troll
]);
686 if (obj
!= vase
|| loc
== plac
[pillow
]) { /* 9027 */
690 prop
[vase
] = 2; /* 9028 */
693 pspeak(vase
, prop
[vase
] + 1);
703 if (obj
== clam
|| obj
== oyster
) {
723 if (obj
== door
&& prop
[door
] == 1)
729 if (obj
== grate
|| obj
== chain
)
731 if (spk
!= 31 || !here(keys
))
735 spk
= 172; /* 9049: lock */
736 if (prop
[chain
] != 0)
738 if (loc
!= plac
[chain
])
751 if (prop
[chain
] == 0)
759 fixed
[bear
] = 2 - prop
[bear
];
769 k
= 34 + prop
[grate
]; /* 9043 */
773 k
= k
+ 2 * prop
[grate
];
782 for (i
= 1; i
<= 5; i
++)
783 if (dloc
[i
] == loc
&& dflag
>= 2)
787 if (obj
== 0) { /* 9122 */
791 obj
= obj
* 100 + snake
;
792 if (at(dragon
) && prop
[dragon
] == 0)
793 obj
= obj
* 100 + dragon
;
795 obj
= obj
* 100 + troll
;
796 if (here(bear
) && prop
[bear
] == 0)
797 obj
= obj
* 100 + bear
;
801 if (here(bird
) && verb
!= throw)
803 if (here(clam
) || here(oyster
))
804 obj
= 100 * obj
+ clam
;
809 if (obj
== bird
) { /* 9124 */
815 if (place
[snake
] == plac
[snake
])
821 if (obj
== clam
|| obj
== oyster
)
827 if (obj
== dwarf
&& closed
)
834 spk
= 165 + (prop
[bear
] + 1) / 2;
835 if (obj
!= dragon
|| prop
[dragon
] != 0)
841 if (!weq(wd1
, "y") && !weq(wd1
, "yes"))
846 k
= (plac
[dragon
] + fixd
[dragon
]) / 2;
847 move(dragon
+ 100, -1);
851 for (obj
= 1; obj
<= 100; obj
++)
852 if (place
[obj
] == plac
[dragon
] || place
[obj
] == fixd
[dragon
])
864 if (toting(rod2
) && obj
== rod
&& !toting(rod
))
868 if (obj
>= 50 && obj
<= maxtrs
&& at(troll
)) {
869 spk
= 159; /* 9178 */
872 move(troll
+ 100, 0);
873 drop(troll2
, plac
[troll
]);
874 drop(troll2
+ 100, fixd
[troll
]);
878 if (obj
== food
&& here(bear
)) {
879 obj
= bear
; /* 9177 */
884 for (i
= 1; i
<= 5; i
++) {
885 if (dloc
[i
] == loc
) {
887 if (ran(3) == 0 || saved
!= -1)
904 if (at(dragon
) && prop
[dragon
] == 0)
909 if (here(bear
) && prop
[bear
] == 0) {
929 if (obj
== snake
|| obj
== dragon
|| obj
== troll
) {
931 if (obj
== dragon
&& prop
[dragon
] != 0)
935 if (obj
!= snake
|| closed
|| !here(bird
))
974 if (liqloc(loc
) == 0)
976 if (liqloc(loc
) == 0 || !toting(vase
))
981 return (9020); /* advent/10 goes to 9024 */
983 if (obj
!= 0 && obj
!= bottle
)
985 if (obj
== 0 && !here(bottle
))
988 if (liqloc(loc
) == 0)
994 prop
[bottle
] = ((cond
[loc
] % 4) / 2) * 2;
1009 prop
[grate
] = prop
[fissur
] = 0;
1010 for (i
= 1; i
<= 6; i
++) {
1015 move(troll
+ 100, 0);
1016 move(troll2
, plac
[troll
]);
1017 move(troll2
+ 100, fixd
[troll
]);
1019 if (prop
[bear
] != 3)
1036 prop
[bottle
] = put(bottle
, 115, 1);
1037 prop
[plant
] = put(plant
, 115, 0);
1038 prop
[oyster
] = put(oyster
, 115, 0);
1039 prop
[lamp
] = put(lamp
, 115, 0);
1040 prop
[rod
] = put(rod
, 115, 0);
1041 prop
[dwarf
] = put(dwarf
, 115, 0);
1047 prop
[snake
] = put(snake
, 116, 1);
1048 prop
[bird
] = put(bird
, 116, 1);
1049 prop
[cage
] = put(cage
, 116, 0);
1050 prop
[rod2
] = put(rod2
, 116, 0);
1051 prop
[pillow
] = put(pillow
, 116, 0);
1053 prop
[mirror
] = put(mirror
, 115, 0);
1054 fixed
[mirror
] = 116;
1056 for (i
= 1; i
<= 100; i
++)