]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/cypher.c
Declare variables in extern.h as extern, and add non-extern
[bsdgames-darwin.git] / battlestar / cypher.c
1 /* $NetBSD: cypher.c,v 1.9 1999/07/28 01:45:42 hubertf 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[] = "@(#)cypher.c 8.2 (Berkeley) 4/28/95";
40 #else
41 __RCSID("$NetBSD: cypher.c,v 1.9 1999/07/28 01:45:42 hubertf Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include "extern.h"
46
47 int
48 cypher()
49 {
50 int n;
51 int junk;
52 int lflag = -1;
53 char buffer[10];
54 char *filename, *rfilename;
55 size_t filename_len;
56
57 while (wordtype[wordnumber] == ADJS)
58 wordnumber++;
59 while (wordnumber <= wordcount) {
60 switch (wordvalue[wordnumber]) {
61
62 case UP:
63 if (location[position].access || wiz || tempwiz) {
64 if (!location[position].access)
65 puts("Zap! A gust of wind lifts you up.");
66 if (!move(location[position].up, AHEAD))
67 return (-1);
68 } else {
69 puts("There is no way up");
70 return (-1);
71 }
72 lflag = 0;
73 break;
74
75 case DOWN:
76 if (!move(location[position].down, AHEAD))
77 return (-1);
78 lflag = 0;
79 break;
80
81 case LEFT:
82 if (!move(left, LEFT))
83 return (-1);
84 lflag = 0;
85 break;
86
87 case RIGHT:
88 if (!move(right, RIGHT))
89 return (-1);
90 lflag = 0;
91 break;
92
93 case AHEAD:
94 if (!move(ahead, AHEAD))
95 return (-1);
96 lflag = 0;
97 break;
98
99 case BACK:
100 if (!move(back, BACK))
101 return (-1);
102 lflag = 0;
103 break;
104
105 case SHOOT:
106 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
107 for (n = 0; n < NUMOFOBJECTS; n++)
108 if (testbit(location[position].objects, n) && objsht[n]) {
109 wordvalue[wordnumber + 1] = n;
110 wordnumber = shoot();
111 }
112 wordnumber++;
113 wordnumber++;
114 } else
115 shoot();
116 break;
117
118 case TAKE:
119 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
120 for (n = 0; n < NUMOFOBJECTS; n++)
121 if (testbit(location[position].objects, n) && objsht[n]) {
122 wordvalue[wordnumber + 1] = n;
123 /* Some objects (type NOUNS)
124 * have special treatment in
125 * take(). For these we
126 * must set the type to NOUNS.
127 * However for SWORD and BODY
128 * all it does is find which
129 * of many objects is meant,
130 * so we need do nothing here.
131 * BATHGOD must become
132 * NORMGOD as well. NOUNS
133 * with no special case
134 * must be included here to
135 * get the right error. DOOR
136 * cannot occur as an object
137 * so need not be included. */
138 switch(n) {
139 case BATHGOD:
140 wordvalue[wordnumber + 1] = NORMGOD;
141 case NORMGOD:
142 case AMULET:
143 case MEDALION:
144 case TALISMAN:
145 case MAN:
146 case TIMER:
147 case NATIVE:
148 wordtype[wordnumber + 1] = NOUNS;
149 break;
150 default:
151 wordtype[wordnumber + 1] = OBJECT;
152 }
153 wordnumber = take(location[position].objects);
154 }
155 wordnumber++;
156 wordnumber++;
157 } else
158 take(location[position].objects);
159 break;
160
161 case DROP:
162
163 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
164 for (n = 0; n < NUMOFOBJECTS; n++)
165 if (testbit(inven, n)) {
166 wordvalue[wordnumber + 1] = n;
167 wordnumber = drop("Dropped");
168 }
169 wordnumber++;
170 wordnumber++;
171 } else
172 drop("Dropped");
173 break;
174
175
176 case KICK:
177 case THROW:
178 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
179 for (n = 0; n < NUMOFOBJECTS; n++)
180 if (testbit(inven, n) ||
181 (testbit(location[position].objects, n) && objsht[n])) {
182 wordvalue[wordnumber + 1] = n;
183 wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
184 }
185 wordnumber += 2;
186 } else
187 throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
188 break;
189
190 case TAKEOFF:
191 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
192 for (n = 0; n < NUMOFOBJECTS; n++)
193 if (testbit(wear, n)) {
194 wordvalue[wordnumber + 1] = n;
195 wordnumber = takeoff();
196 }
197 wordnumber += 2;
198 } else
199 takeoff();
200 break;
201
202
203 case DRAW:
204
205 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
206 for (n = 0; n < NUMOFOBJECTS; n++)
207 if (testbit(wear, n)) {
208 wordvalue[wordnumber + 1] = n;
209 wordnumber = draw();
210 }
211 wordnumber += 2;
212 } else
213 draw();
214 break;
215
216
217 case PUTON:
218
219 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
220 for (n = 0; n < NUMOFOBJECTS; n++)
221 if (testbit(location[position].objects, n) && objsht[n]) {
222 wordvalue[wordnumber + 1] = n;
223 wordnumber = puton();
224 }
225 wordnumber += 2;
226 } else
227 puton();
228 break;
229
230 case WEARIT:
231
232 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
233 for (n = 0; n < NUMOFOBJECTS; n++)
234 if (testbit(inven, n)) {
235 wordvalue[wordnumber + 1] = n;
236 wordnumber = wearit();
237 }
238 wordnumber += 2;
239 } else
240 wearit();
241 break;
242
243
244 case EAT:
245
246 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
247 for (n = 0; n < NUMOFOBJECTS; n++)
248 if (testbit(inven, n)) {
249 wordvalue[wordnumber + 1] = n;
250 wordnumber = eat();
251 }
252 wordnumber += 2;
253 } else
254 eat();
255 break;
256
257
258 case PUT:
259 put();
260 break;
261
262
263 case INVEN:
264 if (ucard(inven)) {
265 puts("You are holding:\n");
266 for (n = 0; n < NUMOFOBJECTS; n++)
267 if (testbit(inven, n))
268 printf("\t%s\n", objsht[n]);
269 printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."), (WEIGHT ? carrying * 100 / WEIGHT : -1));
270 printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER);
271 } else
272 puts("You aren't carrying anything.");
273
274 if (ucard(wear)) {
275 puts("\nYou are wearing:\n");
276 for (n = 0; n < NUMOFOBJECTS; n++)
277 if (testbit(wear, n))
278 printf("\t%s\n", objsht[n]);
279 } else
280 puts("\nYou are stark naked.");
281 if (card(injuries, NUMOFINJURIES)) {
282 puts("\nYou have suffered:\n");
283 for (n = 0; n < NUMOFINJURIES; n++)
284 if (injuries[n])
285 printf("\t%s\n", ouch[n]);
286 printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT, (WEIGHT == 1 ? "." : "s."));
287 } else
288 puts("\nYou are in perfect health.");
289 break;
290
291 case USE:
292 lflag = use();
293 break;
294
295 case LOOK:
296 if (!notes[CANTSEE] || testbit(inven, LAMPON) ||
297 testbit(location[position].objects, LAMPON)
298 || matchlight) {
299 beenthere[position] = 2;
300 writedes();
301 printobjs();
302 if (matchlight) {
303 puts("\nYour match splutters out.");
304 matchlight = 0;
305 }
306 } else
307 puts("I can't see anything.");
308 return (-1);
309 break;
310
311 case SU:
312 if (wiz || tempwiz) {
313 printf("\nRoom (was %d) = ", position);
314 fgets(buffer, 10, stdin);
315 if (*buffer != '\n')
316 sscanf(buffer, "%d", &position);
317 printf("Time (was %d) = ", ourtime);
318 fgets(buffer, 10, stdin);
319 if (*buffer != '\n')
320 sscanf(buffer, "%d", &ourtime);
321 printf("Fuel (was %d) = ", fuel);
322 fgets(buffer, 10, stdin);
323 if (*buffer != '\n')
324 sscanf(buffer, "%d", &fuel);
325 printf("Torps (was %d) = ", torps);
326 fgets(buffer, 10, stdin);
327 if (*buffer != '\n')
328 sscanf(buffer, "%d", &torps);
329 printf("CUMBER (was %d) = ", CUMBER);
330 fgets(buffer, 10, stdin);
331 if (*buffer != '\n')
332 sscanf(buffer, "%d", &CUMBER);
333 printf("WEIGHT (was %d) = ", WEIGHT);
334 fgets(buffer, 10, stdin);
335 if (*buffer != '\n')
336 sscanf(buffer, "%d", &WEIGHT);
337 printf("Clock (was %d) = ", ourclock);
338 fgets(buffer, 10, stdin);
339 if (*buffer != '\n')
340 sscanf(buffer, "%d", &ourclock);
341 printf("Wizard (was %d, %d) = ", wiz, tempwiz);
342 fgets(buffer, 10, stdin);
343 if (*buffer != '\n') {
344 sscanf(buffer, "%d", &junk);
345 if (!junk)
346 tempwiz = wiz = 0;
347 }
348 printf("\nDONE.\n");
349 return (0);
350 } else
351 puts("You aren't a wizard.");
352 break;
353
354 case SCORE:
355 printf("\tPLEASURE\tPOWER\t\tEGO\n");
356 printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego);
357 printf("This gives you the rating of %s in %d turns.\n", rate(), ourtime);
358 printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere, NUMOFROOMS), NUMOFROOMS, card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS);
359 break;
360
361 case KNIFE:
362 case KILL:
363 murder();
364 break;
365
366 case UNDRESS:
367 case RAVAGE:
368 ravage();
369 break;
370
371 case SAVE:
372 printf("\nSave file name (default %s) ",
373 DEFAULT_SAVE_FILE);
374 filename = fgetln(stdin, &filename_len);
375 if (filename_len == 0
376 || (filename_len == 1 && filename[0] == '\n'))
377 rfilename = save_file_name(DEFAULT_SAVE_FILE,
378 strlen(DEFAULT_SAVE_FILE));
379 else {
380 if (filename[filename_len - 1] == '\n')
381 filename_len--;
382 rfilename = save_file_name(filename,
383 filename_len);
384 }
385 save(rfilename);
386 free(rfilename);
387 break;
388
389 case FOLLOW:
390 lflag = follow();
391 break;
392
393 case GIVE:
394 give();
395 break;
396
397 case KISS:
398 kiss();
399 break;
400
401 case LOVE:
402 love();
403 break;
404
405 case RIDE:
406 lflag = ride();
407 break;
408
409 case DRIVE:
410 lflag = drive();
411 break;
412
413 case LIGHT:
414 light();
415 break;
416
417 case LAUNCH:
418 if (!launch())
419 return (-1);
420 else
421 lflag = 0;
422 break;
423
424 case LANDIT:
425 if (!land())
426 return (-1);
427 else
428 lflag = 0;
429 break;
430
431 case TIME:
432 chime();
433 break;
434
435 case SLEEP:
436 zzz();
437 break;
438
439 case DIG:
440 dig();
441 break;
442
443 case JUMP:
444 lflag = jump();
445 break;
446
447 case BURY:
448 bury();
449 break;
450
451 case SWIM:
452 puts("Surf's up!");
453 break;
454
455 case DRINK:
456 drink();
457 break;
458
459 case QUIT:
460 die();
461
462 default:
463 puts("How's that?");
464 return (-1);
465 break;
466
467
468 }
469 if (wordnumber < wordcount && *words[wordnumber++] == ',')
470 continue;
471 else
472 return (lflag);
473 }
474 return (lflag);
475 }