1 /* @(#)subr.c 8.1 (Berkeley) 5/31/93 */
2 /* $NetBSD: subr.c,v 1.13 2009/08/25 06:56:52 dholland Exp $ */
5 * Copyright (c) 1991, 1993
6 * The Regents of the University of California. All rights reserved.
8 * The game adventure was originally written in Fortran by Will Crowther
9 * and Don Woods. It was later translated to C and enhanced by Jim
10 * Gillogly. This code is derived from software contributed to Berkeley
11 * by Jim Gillogly at The Rand Corporation.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 /* Re-coding of advent in C: subroutines from main */
45 static void badmove(void);
46 static int bitset(int, int);
47 static int dropper(void);
49 static int mback(void);
50 static int specials(void);
51 static int trbridge(void);
53 /* Statement functions */
57 if (place[objj] == -1)
66 if (place[objj] == loc || toting(objj))
75 if (place[objj] == loc || fixed[objj] == loc)
84 return ((1 - pbotl) * water + (pbotl / 2) * (water + oil));
95 return (liq2(-1 - i));
98 /* may want to clean this one up a bit */
104 j = ((i * 2) % 8) - 5;
107 return (liq2(j * l + 1));
113 if (cond[l] & setbit[n])
129 if ((cond[loc] % 2) == 0 && (prop[lamp] == 0 || !here(lamp)))
149 if (newloc != loc && !forced(loc) && !bitset(loc, 3)) {
150 for (i = 1; i <= 5; i++) {
151 if (odloc[i] != newloc || !dseen[i])
158 loc = newloc; /* 74 */
159 if (loc == 0 || forced(loc) || bitset(newloc, 3))
166 if (dflag == 1) { /* 6000 */
167 if (loc < 15 || pct(95))
170 for (i = 1; i <= 2; i++) {
172 if (pct(50) && saved == -1)
173 dloc[j] = 0; /* 6001 */
175 for (i = 1; i <= 5; i++) {
178 odloc[i] = dloc[i]; /* 6002 */
184 dtotal = attack = stick = 0; /* 6010 */
185 for (i = 1; i <= 6; i++) { /* loop to 6030 */
189 for (kk = travel[dloc[i]]; kk != 0; kk = kk->next) {
191 if (newloc > 300 || newloc < 15 || newloc == odloc[i]
192 || (j > 1 && newloc == tk[j - 1]) || j >= 20
193 || newloc == dloc[i] || forced(newloc)
194 || (i == 6 && bitset(newloc, 3))
195 || kk->conditions == 100)
199 tk[j] = odloc[i]; /* 6016 */
205 dseen[i] = (dseen[i] && loc >= 15) ||
206 (dloc[i] == loc || odloc[i] == loc);
208 continue; /* i.e. goto 6030 */
210 if (i == 6) { /* pirate's spotted him */
211 if (loc == chloc || prop[chest] >= 0)
214 for (j = 50; j <= maxtrs; j++) { /* loop to 6020 */
215 if (j == pyramid && (loc == plac[pyramid]
216 || loc == plac[emerald]))
223 if (tally == tally2 + 1 && k == 0 && place[chest] == 0
224 && here(lamp) && prop[lamp] == 1)
226 if (odloc[6] != dloc[6] && pct(20))
228 continue; /* to 6030 */
230 if (place[message] == 0)
232 move(message, chloc2);
233 for (j = 50; j <= maxtrs; j++) { /* loop to 6023 */
234 if (j == pyramid && (loc == plac[pyramid]
235 || loc == plac[emerald]))
237 if (at(j) && fixed[j] == 0)
242 l6024: dloc[6] = odloc[6] = chloc;
247 move(message, chloc2);
251 if (odloc[i] != dloc[i])
256 if (ran(1000) < 95 * (dflag - 2))
262 printf("There are %d threatening little dwarves ", dtotal);
263 printf("in the room with you.\n");
273 printf("%d of them throw knives at you!\n", attack);
275 l82: if (stick <= 1) { /* 82 */
280 printf("%d of them get you!\n", stick); /* 83 */
296 if ((tkk = travel[newloc = loc]) == 0)
300 if (k == cave) { /* 40 */
307 if (k == look) { /* 30 */
314 if (k == back) { /* 20 */
327 for (; tkk != 0; tkk = tkk->next)
328 if (tkk->tverb == 1 || tkk->tverb == k)
334 l11: ll1 = tkk->conditions; /* 11 */
336 newloc = ll1; /* newloc=conditions */
337 k = newloc % 100; /* k used for prob */
339 if (newloc <= 100) { /* 13 */
340 if (newloc != 0 && !pct(newloc))
342 l16: newloc = ll2; /* newloc=location */
346 switch (specials()) { /* to 30000 */
356 rspeak(newloc - 500);
360 if (toting(k) || (newloc > 200 && at(k)))
364 if (prop[k] != (newloc / 100) - 3)
365 goto l16; /* newloc still conditions */
366 l12: /* alternative to probability move */
367 for (; tkk != 0; tkk = tkk->next)
368 if (tkk->tloc != ll2 || tkk->conditions != ll1)
379 struct travlist *tk2, *j;
381 if (forced(k = oldloc))
382 k = oldloc2; /* k=location */
390 for (; tkk != 0; tkk = tkk->next) { /* 21 */
393 k = tkk->tverb; /* k back to verb */
399 if (forced(ll) && k == j->tloc)
417 switch (newloc -= 300) {
419 newloc = 99 + 100 - loc;
420 if (holding == 0 || (holding == 1 && toting(emerald)))
428 case 3: /* to 30300 */
439 if (prop[troll] == 1) {
443 move(troll2 + 100, 0);
444 move(troll, plac[troll]);
445 move(troll + 100, fixd[troll]);
450 newloc = plac[troll] + fixd[troll] - loc; /* 30310 */
451 if (prop[troll] == 0)
461 if (prop[spices] < 0)
472 if (k >= 43 && k <= 50)
474 if (k == 29 || k == 30)
476 if (k == 7 || k == 36 || k == 37)
478 if (k == 11 || k == 19)
480 if (verb == find || verb == invent)
482 if (k == 62 || k == 65)
492 printf("Please tell jim@rand.org that fatal bug %d happened.\n", n);
501 for (hint = 4; hint <= hintmax; hint++) {
504 if (!bitset(loc, hint))
507 if (hintlc[hint] < hints[hint][1])
511 if (prop[grate] == 0 && !here(keys))
515 if (here(bird) && toting(rod) && obj == bird)
517 continue; /* i.e. goto l40030 */
519 if (here(snake) && !here(bird))
523 if (atloc[loc] == 0 && atloc[oldloc] == 0
524 && atloc[oldloc2] == 0 && holding > 1)
528 if (prop[emerald] != -1 && prop[pyramid] == -1)
532 goto l40010; /* 40900 */
536 l40010: hintlc[hint] = 0;
537 if (!yes(hints[hint][3], 0, 54))
539 printf("I am prepared to give you a hint, but it will ");
540 printf("cost you %d points.\n", hints[hint][2]);
541 hinted[hint] = yes(175, hints[hint][4], 54);
542 l40020: hintlc[hint] = 0;
553 i = vocab(wd1, -1, 0);
554 if (i == 62 || i == 65 || i == 71 || i == 2025) {
559 printf("\nOkay, \"%s\".\n", wd2);
568 return (2011); /* 9010 */
570 if (obj == plant && prop[plant] <= 0)
572 if (obj == bear && prop[bear] == 1)
574 if (obj == chain && prop[bear] != 0)
578 if (obj == water || obj == oil) {
579 if (here(bottle) && liq() == obj) {
584 if (toting(bottle) && prop[bottle] == 1)
586 if (prop[bottle] != 1)
592 l9017: if (holding >= 7) {
603 if (!toting(cage)) { /* 9013 */
607 prop[bird] = 1; /* 9015 */
609 l9014: if ((obj == bird || obj == cage) && prop[bird] != 0)
610 carry(bird + cage - obj, loc);
613 if (obj == bottle && k != 0)
625 if (obj == bottle && k != 0)
627 if (obj == cage && prop[bird] != 0)
639 if (toting(rod2) && obj == rod && !toting(rod))
643 if (obj == bird && here(snake)) {
651 if (obj == coins && here(vend)) { /* 9024 */
657 if (obj == bird && at(dragon) && prop[dragon] == 0) { /* 9025 */
661 if (place[snake] == plac[snake])
665 if (obj == bear && at(troll)) { /* 9026 */
668 move(troll + 100, 0);
669 move(troll2, plac[troll]);
670 move(troll2 + 100, fixd[troll]);
675 if (obj != vase || loc == plac[pillow]) { /* 9027 */
679 prop[vase] = 2; /* 9028 */
682 pspeak(vase, prop[vase] + 1);
692 if (obj == clam || obj == oyster) {
699 if (!toting(trident))
712 if (obj == door && prop[door] == 1)
718 if (obj == grate || obj == chain)
720 if (spk != 31 || !here(keys))
724 spk = 172; /* 9049: lock */
725 if (prop[chain] != 0)
727 if (loc != plac[chain])
740 if (prop[chain] == 0)
748 fixed[bear] = 2 - prop[bear];
758 k = 34 + prop[grate]; /* 9043 */
762 k = k + 2 * prop[grate];
771 for (i = 1; i <= 5; i++)
772 if (dloc[i] == loc && dflag >= 2)
776 if (obj == 0) { /* 9122 */
780 obj = obj * 100 + snake;
781 if (at(dragon) && prop[dragon] == 0)
782 obj = obj * 100 + dragon;
784 obj = obj * 100 + troll;
785 if (here(bear) && prop[bear] == 0)
786 obj = obj * 100 + bear;
790 if (here(bird) && verb != throw)
792 if (here(clam) || here(oyster))
793 obj = 100 * obj + clam;
798 if (obj == bird) { /* 9124 */
804 if (place[snake] == plac[snake])
810 if (obj == clam || obj == oyster)
816 if (obj == dwarf && closed)
823 spk = 165 + (prop[bear] + 1) / 2;
824 if (obj != dragon || prop[dragon] != 0)
830 if (!weq(wd1, "y") && !weq(wd1, "yes"))
835 k = (plac[dragon] + fixd[dragon]) / 2;
836 move(dragon + 100, -1);
840 for (obj = 1; obj <= 100; obj++)
841 if (place[obj] == plac[dragon] || place[obj] == fixd[dragon])
853 if (toting(rod2) && obj == rod && !toting(rod))
857 if (obj >= 50 && obj <= maxtrs && at(troll)) {
858 spk = 159; /* 9178 */
861 move(troll + 100, 0);
862 drop(troll2, plac[troll]);
863 drop(troll2 + 100, fixd[troll]);
867 if (obj == food && here(bear)) {
868 obj = bear; /* 9177 */
873 for (i = 1; i <= 5; i++) {
874 if (dloc[i] == loc) {
876 if (ran(3) == 0 || saved != -1)
893 if (at(dragon) && prop[dragon] == 0)
898 if (here(bear) && prop[bear] == 0) {
918 if (obj == snake || obj == dragon || obj == troll) {
920 if (obj == dragon && prop[dragon] != 0)
924 if (obj != snake || closed || !here(bird))
963 if (liqloc(loc) == 0)
965 if (liqloc(loc) == 0 || !toting(vase))
970 return (9020); /* advent/10 goes to 9024 */
972 if (obj != 0 && obj != bottle)
974 if (obj == 0 && !here(bottle))
977 if (liqloc(loc) == 0)
983 prop[bottle] = ((cond[loc] % 4) / 2) * 2;
998 prop[grate] = prop[fissure] = 0;
999 for (i = 1; i <= 6; i++) {
1004 move(troll + 100, 0);
1005 move(troll2, plac[troll]);
1006 move(troll2 + 100, fixd[troll]);
1008 if (prop[bear] != 3)
1024 prop[bottle] = put(bottle, 115, 1);
1025 prop[plant] = put(plant, 115, 0);
1026 prop[oyster] = put(oyster, 115, 0);
1027 prop[lamp] = put(lamp, 115, 0);
1028 prop[rod] = put(rod, 115, 0);
1029 prop[dwarf] = put(dwarf, 115, 0);
1035 prop[snake] = put(snake, 116, 1);
1036 prop[bird] = put(bird, 116, 1);
1037 prop[cage] = put(cage, 116, 0);
1038 prop[rod2] = put(rod2, 116, 0);
1039 prop[pillow] = put(pillow, 116, 0);
1041 prop[mirror] = put(mirror, 115, 0);
1042 fixed[mirror] = 116;
1044 for (i = 1; i <= 100; i++)