]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/subr.c
1 /* $NetBSD: subr.c,v 1.8 1998/09/14 09:29:08 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.8 1998/09/14 09:29:08 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)
502 printf("Please tell jim@rand.org that fatal bug %d happened.\n", n
);
511 for (hint
= 4; hint
<= hntmax
; hint
++) {
514 if (!bitset(loc
, hint
))
517 if (hintlc
[hint
] < hints
[hint
][1])
521 if (prop
[grate
] == 0 && !here(keys
))
525 if (here(bird
) && toting(rod
) && obj
== bird
)
527 continue; /* i.e. goto l40030 */
529 if (here(snake
) && !here(bird
))
533 if (atloc
[loc
] == 0 && atloc
[oldloc
] == 0
534 && atloc
[oldlc2
] == 0 && holdng
> 1)
538 if (prop
[emrald
] != -1 && prop
[pyram
] == -1)
542 goto l40010
; /* 40900 */
546 l40010
: hintlc
[hint
] = 0;
547 if (!yes(hints
[hint
][3], 0, 54))
549 printf("I am prepared to give you a hint, but it will ");
550 printf("cost you %d points.\n", hints
[hint
][2]);
551 hinted
[hint
] = yes(175, hints
[hint
][4], 54);
552 l40020
: hintlc
[hint
] = 0;
563 i
= vocab(wd1
, -1, 0);
564 if (i
== 62 || i
== 65 || i
== 71 || i
== 2025) {
569 printf("\nOkay, \"%s\".\n", wd2
);
578 return (2011); /* 9010 */
580 if (obj
== plant
&& prop
[plant
] <= 0)
582 if (obj
== bear
&& prop
[bear
] == 1)
584 if (obj
== chain
&& prop
[bear
] != 0)
588 if (obj
== water
|| obj
== oil
) {
589 if (here(bottle
) && liq() == obj
) {
594 if (toting(bottle
) && prop
[bottle
] == 1)
596 if (prop
[bottle
] != 1)
602 l9017
: if (holdng
>= 7) {
613 if (!toting(cage
)) { /* 9013 */
617 prop
[bird
] = 1; /* 9015 */
619 l9014
: if ((obj
== bird
|| obj
== cage
) && prop
[bird
] != 0)
620 carry(bird
+ cage
- obj
, loc
);
623 if (obj
== bottle
&& k
!= 0)
635 if (obj
== bottle
&& k
!= 0)
637 if (obj
== cage
&& prop
[bird
] != 0)
648 if (toting(rod2
) && obj
== rod
&& !toting(rod
))
652 if (obj
== bird
&& here(snake
)) {
660 if (obj
== coins
&& here(vend
)) { /* 9024 */
666 if (obj
== bird
&& at(dragon
) && prop
[dragon
] == 0) { /* 9025 */
670 if (place
[snake
] == plac
[snake
])
674 if (obj
== bear
&& at(troll
)) { /* 9026 */
677 move(troll
+ 100, 0);
678 move(troll2
, plac
[troll
]);
679 move(troll2
+ 100, fixd
[troll
]);
684 if (obj
!= vase
|| loc
== plac
[pillow
]) { /* 9027 */
688 prop
[vase
] = 2; /* 9028 */
691 pspeak(vase
, prop
[vase
] + 1);
701 if (obj
== clam
|| obj
== oyster
) {
721 if (obj
== door
&& prop
[door
] == 1)
727 if (obj
== grate
|| obj
== chain
)
729 if (spk
!= 31 || !here(keys
))
733 spk
= 172; /* 9049: lock */
734 if (prop
[chain
] != 0)
736 if (loc
!= plac
[chain
])
749 if (prop
[chain
] == 0)
757 fixed
[bear
] = 2 - prop
[bear
];
767 k
= 34 + prop
[grate
]; /* 9043 */
771 k
= k
+ 2 * prop
[grate
];
780 for (i
= 1; i
<= 5; i
++)
781 if (dloc
[i
] == loc
&& dflag
>= 2)
785 if (obj
== 0) { /* 9122 */
789 obj
= obj
* 100 + snake
;
790 if (at(dragon
) && prop
[dragon
] == 0)
791 obj
= obj
* 100 + dragon
;
793 obj
= obj
* 100 + troll
;
794 if (here(bear
) && prop
[bear
] == 0)
795 obj
= obj
* 100 + bear
;
799 if (here(bird
) && verb
!= throw)
801 if (here(clam
) || here(oyster
))
802 obj
= 100 * obj
+ clam
;
807 if (obj
== bird
) { /* 9124 */
813 if (place
[snake
] == plac
[snake
])
819 if (obj
== clam
|| obj
== oyster
)
825 if (obj
== dwarf
&& closed
)
832 spk
= 165 + (prop
[bear
] + 1) / 2;
833 if (obj
!= dragon
|| prop
[dragon
] != 0)
839 if (!weq(wd1
, "y") && !weq(wd1
, "yes"))
844 k
= (plac
[dragon
] + fixd
[dragon
]) / 2;
845 move(dragon
+ 100, -1);
849 for (obj
= 1; obj
<= 100; obj
++)
850 if (place
[obj
] == plac
[dragon
] || place
[obj
] == fixd
[dragon
])
862 if (toting(rod2
) && obj
== rod
&& !toting(rod
))
866 if (obj
>= 50 && obj
<= maxtrs
&& at(troll
)) {
867 spk
= 159; /* 9178 */
870 move(troll
+ 100, 0);
871 drop(troll2
, plac
[troll
]);
872 drop(troll2
+ 100, fixd
[troll
]);
876 if (obj
== food
&& here(bear
)) {
877 obj
= bear
; /* 9177 */
882 for (i
= 1; i
<= 5; i
++) {
883 if (dloc
[i
] == loc
) {
885 if (ran(3) == 0 || saved
!= -1)
902 if (at(dragon
) && prop
[dragon
] == 0)
907 if (here(bear
) && prop
[bear
] == 0) {
927 if (obj
== snake
|| obj
== dragon
|| obj
== troll
) {
929 if (obj
== dragon
&& prop
[dragon
] != 0)
933 if (obj
!= snake
|| closed
|| !here(bird
))
972 if (liqloc(loc
) == 0)
974 if (liqloc(loc
) == 0 || !toting(vase
))
979 return (9020); /* advent/10 goes to 9024 */
981 if (obj
!= 0 && obj
!= bottle
)
983 if (obj
== 0 && !here(bottle
))
986 if (liqloc(loc
) == 0)
992 prop
[bottle
] = ((cond
[loc
] % 4) / 2) * 2;
1007 prop
[grate
] = prop
[fissur
] = 0;
1008 for (i
= 1; i
<= 6; i
++) {
1013 move(troll
+ 100, 0);
1014 move(troll2
, plac
[troll
]);
1015 move(troll2
+ 100, fixd
[troll
]);
1017 if (prop
[bear
] != 3)
1033 prop
[bottle
] = put(bottle
, 115, 1);
1034 prop
[plant
] = put(plant
, 115, 0);
1035 prop
[oyster
] = put(oyster
, 115, 0);
1036 prop
[lamp
] = put(lamp
, 115, 0);
1037 prop
[rod
] = put(rod
, 115, 0);
1038 prop
[dwarf
] = put(dwarf
, 115, 0);
1044 prop
[snake
] = put(snake
, 116, 1);
1045 prop
[bird
] = put(bird
, 116, 1);
1046 prop
[cage
] = put(cage
, 116, 0);
1047 prop
[rod2
] = put(rod2
, 116, 0);
1048 prop
[pillow
] = put(pillow
, 116, 0);
1050 prop
[mirror
] = put(mirror
, 115, 0);
1051 fixed
[mirror
] = 116;
1053 for (i
= 1; i
<= 100; i
++)