1 /* @(#)init.c 8.1 (Berkeley) 6/2/93 */
2 /* $NetBSD: init.c,v 1.21 2014/03/22 20:07:05 dholland Exp $ */
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: data initialization */
40 #include <sys/types.h>
50 static void linkdata(void);
54 int setbit
[16] = {1, 2, 4, 010, 020, 040, 0100, 0200, 0400, 01000, 02000,
55 04000, 010000, 020000, 040000, 0100000};
57 volatile sig_atomic_t delhit
;
60 int loc
, newloc
, oldloc
, oldloc2
, wasdark
, gaveup
, kq
, k
, k2
;
61 char *wd1
, *wd2
; /* the complete words */
63 int saveday
, savet
, maxscore
, latency
;
65 struct hashtab voc
[HTSIZE
];
67 struct text rtext
[RTXSIZE
]; /* random text messages */
69 struct text mtext
[MAGSIZE
]; /* magic messages */
73 struct text ctext
[CLSMAX
]; /* classes of adventurer */
76 struct text ptext
[101]; /* object descriptions */
78 struct text ltext
[LOCSIZE
]; /* long loc description */
79 struct text stext
[LOCSIZE
]; /* short loc descriptions */
81 struct travlist
*travel
[LOCSIZE
], *tkk
; /* travel is closer to keys(...) */
85 int plac
[101]; /* initial object placement */
86 int fixd
[101], fixed
[101]; /* location fixed? */
88 int actspeak
[35]; /* rtext msg for verb <n> */
90 int cond
[LOCSIZE
]; /* various condition bits */
93 int hints
[20][5]; /* info on hints */
94 int hinted
[20], hintlc
[20];
96 int place
[101], prop
[101], links
[201];
99 int maxtrs
, tally
, tally2
; /* treasure values */
101 int keys
, lamp
, grate
, cage
, rod
, rod2
, steps
, /* mnemonics */
102 bird
, door
, pillow
, snake
, fissure
, tablet
, clam
, oyster
,
103 magazine
, dwarf
, knife
, food
, bottle
, water
, oil
, plant
, plant2
,
104 axe
, mirror
, dragon
, chasm
, troll
, troll2
, bear
, message
,
105 vend
, batter
, nugget
, coins
, chest
, eggs
, trident
, vase
,
106 emerald
, pyramid
, pearl
, rug
, chain
, spices
, back
, look
, cave
,
107 null
, entrance
, depression
, say
, lock
, throw,
110 static int enter
, /*stream,*/ pour
;
112 int chloc
, chloc2
, dseen
[7], dloc
[7], /* dwarf stuff */
113 odloc
[7], dflag
, daltloc
;
115 int tk
[21], stick
, dtotal
, attack
;
116 int turns
, lmwarn
, iwest
, knfloc
, detail
, /* various flags and
118 abbnum
, maxdie
, numdie
, holding
, dkill
, foobar
, bonus
, clock1
,
119 clock2
, saved
, isclosing
, panic
, closed
, scoring
;
123 /* everything for 1st time run */
127 rdata(); /* read data from orig. file */
133 decr(int a
, int b
, int c
, int d
, int e
)
148 { /* secondary data manipulation */
152 for (i
= 1; i
< LOCSIZE
; i
++)
153 if (ltext
[i
].seekadr
!= 0 && travel
[i
] != 0)
154 if ((travel
[i
]->tverb
) == 1)
156 for (j
= 100; j
> 0; j
--)
158 drop(j
+ 100, fixd
[j
]);
161 for (j
= 100; j
> 0; j
--) {
163 if (plac
[j
] != 0 && fixd
[j
] <= 0)
171 for (i
= 50; i
<= maxtrs
; i
++) {
172 if (ptext
[i
].seekadr
!= 0)
177 /* define mnemonics */
178 keys
= vocab(DECR('k', 'e', 'y', 's', '\0'), 1, 0);
179 lamp
= vocab(DECR('l', 'a', 'm', 'p', '\0'), 1, 0);
180 grate
= vocab(DECR('g', 'r', 'a', 't', 'e'), 1, 0);
181 cage
= vocab(DECR('c', 'a', 'g', 'e', '\0'), 1, 0);
182 rod
= vocab(DECR('r', 'o', 'd', '\0', '\0'), 1, 0);
184 steps
= vocab(DECR('s', 't', 'e', 'p', 's'), 1, 0);
185 bird
= vocab(DECR('b', 'i', 'r', 'd', '\0'), 1, 0);
186 door
= vocab(DECR('d', 'o', 'o', 'r', '\0'), 1, 0);
187 pillow
= vocab(DECR('p', 'i', 'l', 'l', 'o'), 1, 0);
188 snake
= vocab(DECR('s', 'n', 'a', 'k', 'e'), 1, 0);
189 fissure
= vocab(DECR('f', 'i', 's', 's', 'u'), 1, 0);
190 tablet
= vocab(DECR('t', 'a', 'b', 'l', 'e'), 1, 0);
191 clam
= vocab(DECR('c', 'l', 'a', 'm', '\0'), 1, 0);
192 oyster
= vocab(DECR('o', 'y', 's', 't', 'e'), 1, 0);
193 magazine
= vocab(DECR('m', 'a', 'g', 'a', 'z'), 1, 0);
194 dwarf
= vocab(DECR('d', 'w', 'a', 'r', 'f'), 1, 0);
195 knife
= vocab(DECR('k', 'n', 'i', 'f', 'e'), 1, 0);
196 food
= vocab(DECR('f', 'o', 'o', 'd', '\0'), 1, 0);
197 bottle
= vocab(DECR('b', 'o', 't', 't', 'l'), 1, 0);
198 water
= vocab(DECR('w', 'a', 't', 'e', 'r'), 1, 0);
199 oil
= vocab(DECR('o', 'i', 'l', '\0', '\0'), 1, 0);
200 plant
= vocab(DECR('p', 'l', 'a', 'n', 't'), 1, 0);
202 axe
= vocab(DECR('a', 'x', 'e', '\0', '\0'), 1, 0);
203 mirror
= vocab(DECR('m', 'i', 'r', 'r', 'o'), 1, 0);
204 dragon
= vocab(DECR('d', 'r', 'a', 'g', 'o'), 1, 0);
205 chasm
= vocab(DECR('c', 'h', 'a', 's', 'm'), 1, 0);
206 troll
= vocab(DECR('t', 'r', 'o', 'l', 'l'), 1, 0);
208 bear
= vocab(DECR('b', 'e', 'a', 'r', '\0'), 1, 0);
209 message
= vocab(DECR('m', 'e', 's', 's', 'a'), 1, 0);
210 vend
= vocab(DECR('v', 'e', 'n', 'd', 'i'), 1, 0);
211 batter
= vocab(DECR('b', 'a', 't', 't', 'e'), 1, 0);
213 nugget
= vocab(DECR('g', 'o', 'l', 'd', '\0'), 1, 0);
214 coins
= vocab(DECR('c', 'o', 'i', 'n', 's'), 1, 0);
215 chest
= vocab(DECR('c', 'h', 'e', 's', 't'), 1, 0);
216 eggs
= vocab(DECR('e', 'g', 'g', 's', '\0'), 1, 0);
217 trident
= vocab(DECR('t', 'r', 'i', 'd', 'e'), 1, 0);
218 vase
= vocab(DECR('v', 'a', 's', 'e', '\0'), 1, 0);
219 emerald
= vocab(DECR('e', 'm', 'e', 'r', 'a'), 1, 0);
220 pyramid
= vocab(DECR('p', 'y', 'r', 'a', 'm'), 1, 0);
221 pearl
= vocab(DECR('p', 'e', 'a', 'r', 'l'), 1, 0);
222 rug
= vocab(DECR('r', 'u', 'g', '\0', '\0'), 1, 0);
223 chain
= vocab(DECR('c', 'h', 'a', 'i', 'n'), 1, 0);
225 back
= vocab(DECR('b', 'a', 'c', 'k', '\0'), 0, 0);
226 look
= vocab(DECR('l', 'o', 'o', 'k', '\0'), 0, 0);
227 cave
= vocab(DECR('c', 'a', 'v', 'e', '\0'), 0, 0);
228 null
= vocab(DECR('n', 'u', 'l', 'l', '\0'), 0, 0);
229 entrance
= vocab(DECR('e', 'n', 't', 'r', 'a'), 0, 0);
230 depression
= vocab(DECR('d', 'e', 'p', 'r', 'e'), 0, 0);
231 enter
= vocab(DECR('e', 'n', 't', 'e', 'r'), 0, 0);
233 pour
= vocab(DECR('p', 'o', 'u', 'r', '\0'), 2, 0);
234 say
= vocab(DECR('s', 'a', 'y', '\0', '\0'), 2, 0);
235 lock
= vocab(DECR('l', 'o', 'c', 'k', '\0'), 2, 0);
236 throw = vocab(DECR('t', 'h', 'r', 'o', 'w'), 2, 0);
237 find
= vocab(DECR('f', 'i', 'n', 'd', '\0'), 2, 0);
238 invent
= vocab(DECR('i', 'n', 'v', 'e', 'n'), 2, 0);
240 /* initialize dwarves */
243 for (i
= 1; i
<= 6; i
++)
254 /* random flags & ctrs */
261 for (i
= 0; i
<= 4; i
++)
262 if (rtext
[2 * i
+ 81].seekadr
!= 0)
264 numdie
= holding
= dkill
= foobar
= bonus
= 0;
268 isclosing
= panic
= closed
= scoring
= FALSE
;
271 /* come here if he hits a del */
273 trapdel(int n __unused
)
275 delhit
= 1; /* main checks, treats as QUIT */
276 signal(SIGINT
, trapdel
);/* catch subsequent DELs */
284 srand((int)time(NULL
)); /* random seed */
286 srand(371); /* non-random seed */
288 hinted
[3] = yes(65, 1, 0);
293 limit
= 1000; /* better batteries if instrucs */