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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)subr.c 8.1 (Berkeley) 5/31/93
35 * $FreeBSD: src/games/adventure/subr.c,v 1.7.2.1 2001/03/05 11:43:11 kris Exp $
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 != NULL; 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);
207 if (!dseen[i]) /* 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 == pyram && (loc == plac[pyram]
216 || loc == plac[emrald]))
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[messag] == 0)
232 move(messag, chloc2);
233 for (j = 50; j <= maxtrs; j++) { /* loop to 6023 */
234 if (j == pyram && (loc == plac[pyram]
235 || loc == plac[emrald]))
237 if (at(j) && fixed[j] == 0)
242 l6024: dloc[6] = odloc[6] = chloc;
247 move(messag, 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 */
295 if ((tkk = travel[newloc = loc]) == 0)
299 if (k == cave) { /* 40 */
306 if (k == look) { /* 30 */
313 if (k == back) { /* 20 */
326 for (; tkk != 0; tkk = tkk->next)
327 if (tkk->tverb == 1 || tkk->tverb == k)
333 l11: ll1 = tkk->conditions; /* 11 */
335 newloc = ll1; /* newloc=conditions */
336 k = newloc % 100; /* k used for prob */
338 if (newloc <= 100) { /* 13 */
339 if (newloc != 0 && !pct(newloc)) /* 14 */
341 l16: newloc = ll2; /* newloc=location */
345 switch (specials()) { /* to 30000 */
355 rspeak(newloc - 500);
359 if (toting(k) || (newloc > 200 && at(k)))
363 if (prop[k] != (newloc / 100) - 3) /* newloc still conditions */
365 l12: /* alternative to probability move */
366 for (; tkk != 0; tkk = tkk->next)
367 if (tkk->tloc != ll2 || tkk->conditions != ll1)
378 struct travlist *tk2, *j;
381 if (forced(k = oldloc)) /* 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 (holdng == 0 || (holdng == 1 && toting(emrald)))
428 case 3: /* to 30300 */
441 if (prop[troll] == 1) {
445 move(troll2 + 100, 0);
446 move(troll, plac[troll]);
447 move(troll + 100, fixd[troll]);
452 newloc = plac[troll] + fixd[troll] - loc; /* 30310 */
453 if (prop[troll] == 0)
463 if (prop[spices] < 0)
474 if (k >= 43 && k <= 50)
476 if (k == 29 || k == 30)
478 if (k == 7 || k == 36 || k == 37)
480 if (k == 11 || k == 19)
482 if (verb == find || verb == invent)
484 if (k == 62 || k == 65)
494 printf("Please tell jim@rand.org that fatal bug %d happened.\n", n);
504 for (hint = 4; hint <= hntmax; hint++) {
507 if (!bitset(loc, hint))
510 if (hintlc[hint] < hints[hint][1])
514 if (prop[grate] == 0 && !here(keys))
518 if (here(bird) && toting(rod) && obj == bird)
520 continue; /* i.e. goto l40030 */
522 if (here(snake) && !here(bird))
526 if (atloc[loc] == 0 && atloc[oldloc] == 0
527 && atloc[oldlc2] == 0 && holdng > 1)
531 if (prop[emrald] != -1 && prop[pyram] == -1)
539 l40010: hintlc[hint] = 0;
540 if (!yes(hints[hint][3], 0, 54))
542 printf("I am prepared to give you a hint, but it will ");
543 printf("cost you %d points.\n", hints[hint][2]);
544 hinted[hint] = yes(175, hints[hint][4], 54);
545 l40020: hintlc[hint] = 0;
557 i = vocab(wd1, -1, 0);
558 if (i == 62 || i == 65 || i == 71 || i == 2025) {
563 printf("\nOkay, \"%s\".\n", wd2);
571 if (toting(obj)) /* 9010 */
574 if (obj == plant && prop[plant] <= 0)
576 if (obj == bear && prop[bear] == 1)
578 if (obj == chain && prop[bear] != 0)
582 if (obj == water || obj == oil) {
583 if (here(bottle) && liq() == obj) {
588 if (toting(bottle) && prop[bottle] == 1)
590 if (prop[bottle] != 1)
596 l9017: if (holdng >= 7) {
607 if (!toting(cage)) { /* 9013 */
611 prop[bird] = 1; /* 9015 */
613 l9014: if ((obj == bird || obj == cage) && prop[bird] != 0)
614 carry(bird + cage - obj, loc);
617 if (obj == bottle && k != 0)
629 if (obj == bottle && k != 0)
631 if (obj == cage && prop[bird] != 0)
643 if (toting(rod2) && obj == rod && !toting(rod))
647 if (obj == bird && here(snake)) {
655 if (obj == coins && here(vend)) { /* 9024 */
661 if (obj == bird && at(dragon) && prop[dragon] == 0) { /* 9025 */
665 if (place[snake] == plac[snake])
669 if (obj == bear && at(troll)) { /* 9026 */
672 move(troll + 100, 0);
673 move(troll2, plac[troll]);
674 move(troll2 + 100, fixd[troll]);
679 if (obj != vase || loc == plac[pillow]) { /* 9027 */
683 prop[vase] = 2; /* 9028 */
686 pspeak(vase, prop[vase] + 1);
696 if (obj == clam || obj == oyster) {
716 if (obj == door && prop[door] == 1)
722 if (obj == grate || obj == chain)
724 if (spk != 31 || !here(keys))
728 spk = 172; /* 9049: lock */
729 if (prop[chain] != 0)
731 if (loc != plac[chain])
744 if (prop[chain] == 0)
752 fixed[bear] = 2 - prop[bear];
762 k = 34 + prop[grate]; /* 9043 */
766 k = k + 2 * prop[grate];
776 for (i = 1; i <= 5; i++)
777 if (dloc[i] == loc && dflag >= 2)
781 if (obj == 0) { /* 9122 */
785 obj = obj * 100 + snake;
786 if (at(dragon) && prop[dragon] == 0)
787 obj = obj * 100 + dragon;
789 obj = obj * 100 + troll;
790 if (here(bear) && prop[bear] == 0)
791 obj = obj * 100 + bear;
795 if (here(bird) && verb != throw)
797 if (here(clam) || here(oyster))
798 obj = 100 * obj + clam;
803 if (obj == bird) { /* 9124 */
809 if (place[snake] == plac[snake])
813 if (obj == 0) /* 9125 */
815 if (obj == clam || obj == oyster)
821 if (obj == dwarf && closed)
828 spk = 165 + (prop[bear] + 1) / 2;
829 if (obj != dragon || prop[dragon] != 0)
835 if (strncmp(wd1, "y", 1) && strncmp(wd1, "yes", 3))
840 k = (plac[dragon] + fixd[dragon]) / 2;
841 move(dragon + 100, -1);
845 for (obj = 1; obj <= 100; obj++)
846 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) {
898 if (at(dragon) && prop[dragon] == 0)
903 if (here(bear) && prop[bear] == 0) {
923 if (obj == snake || obj == dragon || obj == troll) {
925 if (obj == dragon && prop[dragon] != 0)
929 if (obj != snake || closed || !here(bird))
968 if (liqloc(loc) == 0)
970 if (liqloc(loc) == 0 || !toting(vase))
975 return (9020); /* advent/10 goes to 9024 */
977 if (obj != 0 && obj != bottle)
979 if (obj == 0 && !here(bottle))
982 if (liqloc(loc) == 0)
988 prop[bottle] = ((cond[loc] % 4) / 2) * 2;
1003 prop[grate] = prop[fissur] = 0;
1004 for (i = 1; i <= 6; i++) {
1009 move(troll + 100, 0);
1010 move(troll2, plac[troll]);
1011 move(troll2 + 100, fixd[troll]);
1013 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++)