Annotation of src/games/adventure/init.c, Revision 1.21
1.21 ! dholland 1: /* $NetBSD: init.c,v 1.20 2011/08/31 16:24:55 plunky Exp $ */
1.2 cgd 2:
1.1 jtc 3: /*-
4: * Copyright (c) 1993
5: * The Regents of the University of California. All rights reserved.
6: *
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.
11: *
12: * Redistribution and use in source and binary forms, with or without
13: * modification, are permitted provided that the following conditions
14: * are met:
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.
1.14 agc 20: * 3. Neither the name of the University nor the names of its contributors
1.1 jtc 21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
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
34: * SUCH DAMAGE.
35: */
36:
1.5 christos 37: #include <sys/cdefs.h>
1.1 jtc 38: #ifndef lint
1.2 cgd 39: #if 0
1.1 jtc 40: static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/2/93";
1.2 cgd 41: #else
1.21 ! dholland 42: __RCSID("$NetBSD: init.c,v 1.20 2011/08/31 16:24:55 plunky Exp $");
1.2 cgd 43: #endif
1.1 jtc 44: #endif /* not lint */
45:
1.7 lukem 46: /* Re-coding of advent in C: data initialization */
1.1 jtc 47:
48: #include <sys/types.h>
1.4 mrg 49: #include <signal.h>
1.1 jtc 50: #include <stdio.h>
1.5 christos 51: #include <stdlib.h>
1.8 perry 52: #include <time.h>
1.5 christos 53: #include <unistd.h>
1.8 perry 54:
1.1 jtc 55: #include "hdr.h"
1.5 christos 56: #include "extern.h"
1.1 jtc 57:
1.18 dholland 58: static void linkdata(void);
59:
1.7 lukem 60: int blklin = TRUE;
1.1 jtc 61:
1.15 jmc 62: int setbit[16] = {1, 2, 4, 010, 020, 040, 0100, 0200, 0400, 01000, 02000,
63: 04000, 010000, 020000, 040000, 0100000};
1.1 jtc 64:
1.12 hubertf 65: volatile sig_atomic_t delhit;
66: int yea;
67:
1.19 dholland 68: int loc, newloc, oldloc, oldloc2, wasdark, gaveup, kq, k, k2;
1.12 hubertf 69: char *wd1, *wd2; /* the complete words */
70: int verb, obj, spk;
1.19 dholland 71: int saveday, savet, maxscore, latency;
1.12 hubertf 72:
73: struct hashtab voc[HTSIZE];
74:
1.19 dholland 75: struct text rtext[RTXSIZE]; /* random text messages */
1.12 hubertf 76:
1.19 dholland 77: struct text mtext[MAGSIZE]; /* magic messages */
1.12 hubertf 78:
1.19 dholland 79: int classes;
1.12 hubertf 80:
81: struct text ctext[CLSMAX]; /* classes of adventurer */
82: int cval[CLSMAX];
83:
84: struct text ptext[101]; /* object descriptions */
85:
1.19 dholland 86: struct text ltext[LOCSIZE]; /* long loc description */
87: struct text stext[LOCSIZE]; /* short loc descriptions */
1.12 hubertf 88:
1.19 dholland 89: struct travlist *travel[LOCSIZE], *tkk; /* travel is closer to keys(...) */
1.12 hubertf 90:
1.19 dholland 91: int atloc[LOCSIZE];
1.12 hubertf 92:
93: int plac[101]; /* initial object placement */
94: int fixd[101], fixed[101]; /* location fixed? */
95:
1.19 dholland 96: int actspeak[35]; /* rtext msg for verb <n> */
1.12 hubertf 97:
1.19 dholland 98: int cond[LOCSIZE]; /* various condition bits */
1.12 hubertf 99:
1.19 dholland 100: int hintmax;
1.12 hubertf 101: int hints[20][5]; /* info on hints */
102: int hinted[20], hintlc[20];
103:
104: int place[101], prop[101], links[201];
1.19 dholland 105: int abb[LOCSIZE];
1.12 hubertf 106:
107: int maxtrs, tally, tally2; /* treasure values */
108:
109: int keys, lamp, grate, cage, rod, rod2, steps, /* mnemonics */
1.19 dholland 110: bird, door, pillow, snake, fissure, tablet, clam, oyster,
111: magazine, dwarf, knife, food, bottle, water, oil, plant, plant2,
112: axe, mirror, dragon, chasm, troll, troll2, bear, message,
113: vend, batter, nugget, coins, chest, eggs, trident, vase,
114: emerald, pyramid, pearl, rug, chain, spices, back, look, cave,
115: null, entrance, depression, say, lock, throw,
1.12 hubertf 116: find, invent;
117:
1.18 dholland 118: static int enter, /*stream,*/ pour;
119:
1.12 hubertf 120: int chloc, chloc2, dseen[7], dloc[7], /* dwarf stuff */
1.19 dholland 121: odloc[7], dflag, daltloc;
1.12 hubertf 122:
123: int tk[21], stick, dtotal, attack;
124: int turns, lmwarn, iwest, knfloc, detail, /* various flags and
125: * counters */
1.19 dholland 126: abbnum, maxdie, numdie, holding, dkill, foobar, bonus, clock1,
127: clock2, saved, isclosing, panic, closed, scoring;
1.12 hubertf 128:
1.13 christos 129: int demo, limit;
1.1 jtc 130:
1.15 jmc 131: /* everything for 1st time run */
1.5 christos 132: void
1.15 jmc 133: init(void)
1.1 jtc 134: {
1.7 lukem 135: rdata(); /* read data from orig. file */
1.1 jtc 136: linkdata();
137: poof();
138: }
139:
1.21 ! dholland 140: __noinline char *
1.15 jmc 141: decr(int a, int b, int c, int d, int e)
1.1 jtc 142: {
143: static char buf[6];
144:
1.7 lukem 145: buf[0] = a - '+';
146: buf[1] = b - '-';
147: buf[2] = c - '#';
148: buf[3] = d - '&';
149: buf[4] = e - '%';
1.1 jtc 150: buf[5] = 0;
151: return buf;
152: }
153:
1.18 dholland 154: static void
1.15 jmc 155: linkdata(void)
1.7 lukem 156: { /* secondary data manipulation */
157: int i, j;
158:
159: /* array linkages */
1.19 dholland 160: for (i = 1; i < LOCSIZE; i++)
1.7 lukem 161: if (ltext[i].seekadr != 0 && travel[i] != 0)
162: if ((travel[i]->tverb) == 1)
163: cond[i] = 2;
164: for (j = 100; j > 0; j--)
165: if (fixd[j] > 0) {
166: drop(j + 100, fixd[j]);
167: drop(j, plac[j]);
1.1 jtc 168: }
1.7 lukem 169: for (j = 100; j > 0; j--) {
170: fixed[j] = fixd[j];
171: if (plac[j] != 0 && fixd[j] <= 0)
172: drop(j, plac[j]);
1.1 jtc 173: }
174:
1.7 lukem 175: maxtrs = 79;
176: tally = 0;
177: tally2 = 0;
178:
179: for (i = 50; i <= maxtrs; i++) {
180: if (ptext[i].seekadr != 0)
181: prop[i] = -1;
1.1 jtc 182: tally -= prop[i];
183: }
184:
185: /* define mnemonics */
1.7 lukem 186: keys = vocab(DECR('k', 'e', 'y', 's', '\0'), 1, 0);
187: lamp = vocab(DECR('l', 'a', 'm', 'p', '\0'), 1, 0);
188: grate = vocab(DECR('g', 'r', 'a', 't', 'e'), 1, 0);
189: cage = vocab(DECR('c', 'a', 'g', 'e', '\0'), 1, 0);
190: rod = vocab(DECR('r', 'o', 'd', '\0', '\0'), 1, 0);
191: rod2 = rod + 1;
192: steps = vocab(DECR('s', 't', 'e', 'p', 's'), 1, 0);
193: bird = vocab(DECR('b', 'i', 'r', 'd', '\0'), 1, 0);
194: door = vocab(DECR('d', 'o', 'o', 'r', '\0'), 1, 0);
195: pillow = vocab(DECR('p', 'i', 'l', 'l', 'o'), 1, 0);
196: snake = vocab(DECR('s', 'n', 'a', 'k', 'e'), 1, 0);
1.19 dholland 197: fissure = vocab(DECR('f', 'i', 's', 's', 'u'), 1, 0);
1.7 lukem 198: tablet = vocab(DECR('t', 'a', 'b', 'l', 'e'), 1, 0);
199: clam = vocab(DECR('c', 'l', 'a', 'm', '\0'), 1, 0);
200: oyster = vocab(DECR('o', 'y', 's', 't', 'e'), 1, 0);
1.19 dholland 201: magazine = vocab(DECR('m', 'a', 'g', 'a', 'z'), 1, 0);
1.7 lukem 202: dwarf = vocab(DECR('d', 'w', 'a', 'r', 'f'), 1, 0);
203: knife = vocab(DECR('k', 'n', 'i', 'f', 'e'), 1, 0);
204: food = vocab(DECR('f', 'o', 'o', 'd', '\0'), 1, 0);
205: bottle = vocab(DECR('b', 'o', 't', 't', 'l'), 1, 0);
206: water = vocab(DECR('w', 'a', 't', 'e', 'r'), 1, 0);
207: oil = vocab(DECR('o', 'i', 'l', '\0', '\0'), 1, 0);
208: plant = vocab(DECR('p', 'l', 'a', 'n', 't'), 1, 0);
209: plant2 = plant + 1;
210: axe = vocab(DECR('a', 'x', 'e', '\0', '\0'), 1, 0);
211: mirror = vocab(DECR('m', 'i', 'r', 'r', 'o'), 1, 0);
212: dragon = vocab(DECR('d', 'r', 'a', 'g', 'o'), 1, 0);
213: chasm = vocab(DECR('c', 'h', 'a', 's', 'm'), 1, 0);
214: troll = vocab(DECR('t', 'r', 'o', 'l', 'l'), 1, 0);
215: troll2 = troll + 1;
216: bear = vocab(DECR('b', 'e', 'a', 'r', '\0'), 1, 0);
1.19 dholland 217: message = vocab(DECR('m', 'e', 's', 's', 'a'), 1, 0);
1.7 lukem 218: vend = vocab(DECR('v', 'e', 'n', 'd', 'i'), 1, 0);
219: batter = vocab(DECR('b', 'a', 't', 't', 'e'), 1, 0);
220:
221: nugget = vocab(DECR('g', 'o', 'l', 'd', '\0'), 1, 0);
222: coins = vocab(DECR('c', 'o', 'i', 'n', 's'), 1, 0);
223: chest = vocab(DECR('c', 'h', 'e', 's', 't'), 1, 0);
224: eggs = vocab(DECR('e', 'g', 'g', 's', '\0'), 1, 0);
1.19 dholland 225: trident = vocab(DECR('t', 'r', 'i', 'd', 'e'), 1, 0);
1.7 lukem 226: vase = vocab(DECR('v', 'a', 's', 'e', '\0'), 1, 0);
1.19 dholland 227: emerald = vocab(DECR('e', 'm', 'e', 'r', 'a'), 1, 0);
228: pyramid = vocab(DECR('p', 'y', 'r', 'a', 'm'), 1, 0);
1.7 lukem 229: pearl = vocab(DECR('p', 'e', 'a', 'r', 'l'), 1, 0);
230: rug = vocab(DECR('r', 'u', 'g', '\0', '\0'), 1, 0);
231: chain = vocab(DECR('c', 'h', 'a', 'i', 'n'), 1, 0);
232:
233: back = vocab(DECR('b', 'a', 'c', 'k', '\0'), 0, 0);
234: look = vocab(DECR('l', 'o', 'o', 'k', '\0'), 0, 0);
235: cave = vocab(DECR('c', 'a', 'v', 'e', '\0'), 0, 0);
236: null = vocab(DECR('n', 'u', 'l', 'l', '\0'), 0, 0);
1.19 dholland 237: entrance = vocab(DECR('e', 'n', 't', 'r', 'a'), 0, 0);
238: depression = vocab(DECR('d', 'e', 'p', 'r', 'e'), 0, 0);
1.7 lukem 239: enter = vocab(DECR('e', 'n', 't', 'e', 'r'), 0, 0);
240:
241: pour = vocab(DECR('p', 'o', 'u', 'r', '\0'), 2, 0);
242: say = vocab(DECR('s', 'a', 'y', '\0', '\0'), 2, 0);
243: lock = vocab(DECR('l', 'o', 'c', 'k', '\0'), 2, 0);
244: throw = vocab(DECR('t', 'h', 'r', 'o', 'w'), 2, 0);
245: find = vocab(DECR('f', 'i', 'n', 'd', '\0'), 2, 0);
246: invent = vocab(DECR('i', 'n', 'v', 'e', 'n'), 2, 0);
1.1 jtc 247:
248: /* initialize dwarves */
1.7 lukem 249: chloc = 114;
250: chloc2 = 140;
251: for (i = 1; i <= 6; i++)
252: dseen[i] = FALSE;
253: dflag = 0;
254: dloc[1] = 19;
255: dloc[2] = 27;
256: dloc[3] = 33;
257: dloc[4] = 44;
258: dloc[5] = 64;
259: dloc[6] = chloc;
1.19 dholland 260: daltloc = 18;
1.1 jtc 261:
262: /* random flags & ctrs */
1.7 lukem 263: turns = 0;
264: lmwarn = FALSE;
265: iwest = 0;
266: knfloc = 0;
267: detail = 0;
268: abbnum = 5;
269: for (i = 0; i <= 4; i++)
270: if (rtext[2 * i + 81].seekadr != 0)
271: maxdie = i + 1;
1.19 dholland 272: numdie = holding = dkill = foobar = bonus = 0;
1.7 lukem 273: clock1 = 30;
274: clock2 = 50;
275: saved = 0;
1.19 dholland 276: isclosing = panic = closed = scoring = FALSE;
1.1 jtc 277: }
278:
1.15 jmc 279: /* come here if he hits a del */
1.5 christos 280: void
1.17 perry 281: trapdel(int n __unused)
1.7 lukem 282: {
1.10 hubertf 283: delhit = 1; /* main checks, treats as QUIT */
1.7 lukem 284: signal(SIGINT, trapdel);/* catch subsequent DELs */
1.1 jtc 285: }
286:
287:
1.5 christos 288: void
1.15 jmc 289: startup(void)
1.1 jtc 290: {
1.9 hubertf 291: demo = Start();
1.20 plunky 292: srand((int)time(NULL)); /* random seed */
1.5 christos 293: #if 0
1.7 lukem 294: srand(371); /* non-random seed */
1.5 christos 295: #endif
1.7 lukem 296: hinted[3] = yes(65, 1, 0);
297: newloc = 1;
1.1 jtc 298: delhit = 0;
1.7 lukem 299: limit = 330;
300: if (hinted[3])
301: limit = 1000; /* better batteries if instrucs */
1.1 jtc 302: }
CVSweb <webmaster@jp.NetBSD.org>