]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/com4.c
add sanity checks when saving/restoring games (PR#6138 by Joseph Myers <jsm28@cam...
[bsdgames-darwin.git] / battlestar / com4.c
1 /* $NetBSD: com4.c,v 1.6 1997/10/11 02:07:04 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)com4.c 8.2 (Berkeley) 4/28/95";
40 #else
41 __RCSID("$NetBSD: com4.c,v 1.6 1997/10/11 02:07:04 lukem Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include "extern.h"
46
47 int
48 take(from)
49 unsigned int from[];
50 {
51 int firstnumber, heavy, bulky, value;
52 int n;
53
54 firstnumber = wordnumber;
55 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == OFF) {
56 wordnumber++;
57 wordvalue[wordnumber] = TAKEOFF;
58 return (cypher());
59 } else {
60 while (wordtype[++wordnumber] == ADJS);
61 while (wordnumber <= wordcount && wordtype[wordnumber] == OBJECT) {
62 value = wordvalue[wordnumber];
63 printf("%s:\n", objsht[value]);
64 for (n = 0; objsht[value][n]; n++);
65 heavy = (carrying + objwt[value]) <= WEIGHT;
66 bulky = (encumber + objcumber[value]) <= CUMBER;
67 if ((testbit(from, value) || wiz || tempwiz) && heavy && bulky && !testbit(inven, value)) {
68 setbit(inven, value);
69 carrying += objwt[value];
70 encumber += objcumber[value];
71 ourtime++;
72 if (testbit(from, value))
73 printf("Taken.\n");
74 else
75 printf("Zap! Taken from thin air.\n");
76 clearbit(from, value);
77 if (value == MEDALION)
78 win--;
79 } else
80 if (testbit(inven, value))
81 printf("You're already holding%s%s.\n", (objsht[value][n - 1] == 's' ? " " : " a "), objsht[value]);
82 else
83 if (!heavy)
84 printf("The %s %s too heavy.\n", objsht[value], (objsht[value][n - 1] == 's' ? "are" : "is"));
85 else
86 if (!bulky)
87 printf("The %s %s too cumbersome to hold.\n", objsht[value], (objsht[value][n - 1] == 's' ? "are" : "is"));
88 else
89 printf("I dont see any %s around here.\n", objsht[value]);
90 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
91 wordnumber++;
92 else
93 return (firstnumber);
94 }
95 }
96 /* special cases with their own return()'s */
97
98 if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS)
99 switch (wordvalue[wordnumber]) {
100
101 case SWORD:
102 if (testbit(from, SWORD)) {
103 wordtype[wordnumber--] = OBJECT;
104 return (take(from));
105 }
106 if (testbit(from, TWO_HANDED)) {
107 wordvalue[wordnumber] = TWO_HANDED;
108 wordtype[wordnumber--] = OBJECT;
109 return (take(from));
110 }
111 wordvalue[wordnumber] = BROAD;
112 wordtype[wordnumber--] = OBJECT;
113 return (take(from));
114
115 case BODY:
116 if (testbit(from, MAID)) {
117 wordvalue[wordnumber] = MAID;
118 wordtype[wordnumber--] = OBJECT;
119 return (take(from));
120 } else
121 if (testbit(from, DEADWOOD)) {
122 wordvalue[wordnumber] = DEADWOOD;
123 wordtype[wordnumber--] = OBJECT;
124 return (take(from));
125 } else
126 if (testbit(from, DEADNATIVE)) {
127 wordvalue[wordnumber] = DEADNATIVE;
128 wordtype[wordnumber--] = OBJECT;
129 return (take(from));
130 } else
131 if (testbit(from, DEADGOD)) {
132 wordvalue[wordnumber] = DEADGOD;
133 wordtype[wordnumber--] = OBJECT;
134 return (take(from));
135 } else {
136 wordvalue[wordnumber] = DEADTIME;
137 wordtype[wordnumber--] = OBJECT;
138 return (take(from));
139 }
140 break;
141
142 case AMULET:
143 if (testbit(location[position].objects, AMULET)) {
144 puts("The amulet is warm to the touch, and its beauty catches your breath.");
145 puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer");
146 puts("and sharper but far away as if in a dream. The sound of purling water reaches");
147 puts("you from afar. The mist falls again, and your heart leaps in horror. The gold");
148 puts("freezes your hands and fathomless darkness engulfs your soul.");
149 }
150 wordtype[wordnumber--] = OBJECT;
151 return (take(from));
152
153 case MEDALION:
154 if (testbit(location[position].objects, MEDALION)) {
155 puts("The medallion is warm, and it rekindles your spirit with the warmth of life.");
156 puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate.");
157 }
158 wordtype[wordnumber--] = OBJECT;
159 return (take(from));
160
161 case TALISMAN:
162 if (testbit(location[position].objects, TALISMAN)) {
163 puts("The talisman is cold to the touch, and it sends a chill down your spine.");
164 }
165 wordtype[wordnumber--] = OBJECT;
166 return (take(from));
167
168 case NORMGOD:
169 if (testbit(location[position].objects, BATHGOD) && (testbit(wear, AMULET) || testbit(inven, AMULET))) {
170 puts("She offers a delicate hand, and you help her out of the sparkling springs.");
171 puts("Water droplets like liquid silver bedew her golden skin, but when they part");
172 puts("from her, they fall as teardrops. She wraps a single cloth around her and");
173 puts("ties it at the waist. Around her neck hangs a golden amulet.");
174 puts("She bids you to follow her.");
175 pleasure++;
176 followgod = ourtime;
177 clearbit(location[position].objects, BATHGOD);
178 } else
179 if (!testbit(location[position].objects, BATHGOD))
180 puts("You're in no position to take her.");
181 else
182 puts("She moves away from you.");
183 break;
184
185 default:
186 puts("It doesn't seem to work.");
187 }
188 else
189 puts("You've got to be kidding.");
190 return (firstnumber);
191 }
192
193 int
194 throw(name)
195 char *name;
196 {
197 int n;
198 int deposit = 0;
199 int first, value;
200
201 first = wordnumber;
202 if (drop(name) != -1) {
203 switch (wordvalue[wordnumber]) {
204
205 case AHEAD:
206 deposit = ahead;
207 break;
208
209 case BACK:
210 deposit = back;
211 break;
212
213 case LEFT:
214 deposit = left;
215 break;
216
217 case RIGHT:
218 deposit = right;
219 break;
220
221 case UP:
222 deposit = location[position].up * (location[position].access || position == FINAL);
223 break;
224
225 case DOWN:
226 deposit = location[position].down;
227 break;
228 }
229 wordnumber = first;
230 while (wordtype[++wordnumber] == ADJS);
231 while (wordnumber <= wordcount) {
232 value = wordvalue[wordnumber];
233 if (deposit && testbit(location[position].objects, value)) {
234 clearbit(location[position].objects, value);
235 if (value != GRENADE)
236 setbit(location[deposit].objects, value);
237 else {
238 puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel.");
239 for (n = 0; n < NUMOFWORDS; n++)
240 location[deposit].objects[n] = 0;
241 setbit(location[deposit].objects, CHAR);
242 }
243 if (value == ROPE && position == FINAL)
244 location[position].access = 1;
245 switch (deposit) {
246 case 189:
247 case 231:
248 puts("The stone door is unhinged.");
249 location[189].north = 231;
250 location[231].south = 189;
251 break;
252 case 30:
253 puts("The wooden door is blown open.");
254 location[30].west = 25;
255 break;
256 case 31:
257 puts("The door is not damaged.");
258 }
259 } else
260 if (value == GRENADE && testbit(location[position].objects, value)) {
261 puts("You are blown into shreds when your grenade explodes.");
262 die();
263 }
264 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
265 wordnumber++;
266 else
267 return (first);
268 }
269 return (first);
270 }
271 return (first);
272 }
273
274 int
275 drop(name)
276 char *name;
277 {
278
279 int firstnumber, value;
280
281 firstnumber = wordnumber;
282 while (wordtype[++wordnumber] == ADJS);
283 while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) {
284 value = wordvalue[wordnumber];
285 printf("%s:\n", objsht[value]);
286 if (testbit(inven, value)) {
287 clearbit(inven, value);
288 carrying -= objwt[value];
289 encumber -= objcumber[value];
290 if (value == BOMB) {
291 puts("The bomb explodes. A blinding white light and immense concussion obliterate us.");
292 die();
293 }
294 if (value != AMULET && value != MEDALION && value != TALISMAN)
295 setbit(location[position].objects, value);
296 else
297 tempwiz = 0;
298 ourtime++;
299 if (*name == 'K')
300 puts("Drop kicked.");
301 else
302 printf("%s.\n", name);
303 } else {
304 if (*name != 'K') {
305 printf("You aren't holding the %s.\n", objsht[value]);
306 if (testbit(location[position].objects, value)) {
307 if (*name == 'T')
308 puts("Kicked instead.");
309 else
310 if (*name == 'G')
311 puts("Given anyway.");
312 }
313 } else
314 puts("Kicked.");
315 }
316 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
317 wordnumber++;
318 else
319 return (firstnumber);
320 }
321 puts("Do what?");
322 return (-1);
323 }
324
325 int
326 takeoff()
327 {
328 wordnumber = take(wear);
329 return (drop("Dropped"));
330 }
331
332 int
333 puton()
334 {
335 wordnumber = take(location[position].objects);
336 return (wearit());
337 }
338
339 int
340 eat()
341 {
342 int firstnumber, value;
343
344 firstnumber = wordnumber;
345 while (wordtype[++wordnumber] == ADJS);
346 while (wordnumber <= wordcount) {
347 value = wordvalue[wordnumber];
348 switch (value) {
349
350 case -1:
351 puts("Eat what?");
352 return (firstnumber);
353
354 default:
355 printf("You can't eat%s%s!\n",
356 wordtype[wordnumber] == OBJECT &&
357 objsht[value]
358 [strlen(objsht[value]) - 1] == 's' ?
359 " " : " a ",
360 words[wordnumber]);
361 return (firstnumber);
362
363 case PAPAYAS:
364 case PINEAPPLE:
365 case KIWI:
366 case COCONUTS: /* eatable things */
367 case MANGO:
368
369 printf("%s:\n", objsht[value]);
370 if (testbit(inven, value) &&
371 ourtime > ate - CYCLE &&
372 testbit(inven, KNIFE)) {
373 clearbit(inven, value);
374 carrying -= objwt[value];
375 encumber -= objcumber[value];
376 ate = max(ourtime, ate) + CYCLE / 3;
377 snooze += CYCLE / 10;
378 ourtime++;
379 puts("Eaten. You can explore a little longer now.");
380 } else
381 if (ourtime < ate - CYCLE)
382 puts("You're stuffed.");
383 else
384 if (!testbit(inven, KNIFE))
385 puts("You need a knife.");
386 else
387 printf("You aren't holding the %s.\n", objsht[value]);
388 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
389 wordnumber++;
390 else
391 return (firstnumber);
392 } /* end switch */
393 } /* end while */
394 return (firstnumber);
395 }