]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/cypher.c
add sanity checks when saving/restoring games (PR#6138 by Joseph Myers <jsm28@cam...
[bsdgames-darwin.git] / battlestar / cypher.c
1 /* $NetBSD: cypher.c,v 1.7 1998/08/24 00:25:32 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.7 1998/08/24 00:25:32 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
55 while (wordtype[wordnumber] == ADJS)
56 wordnumber++;
57 while (wordnumber <= wordcount) {
58 switch (wordvalue[wordnumber]) {
59
60 case UP:
61 if (location[position].access || wiz || tempwiz) {
62 if (!location[position].access)
63 puts("Zap! A gust of wind lifts you up.");
64 if (!move(location[position].up, AHEAD))
65 return (-1);
66 } else {
67 puts("There is no way up");
68 return (-1);
69 }
70 lflag = 0;
71 break;
72
73 case DOWN:
74 if (!move(location[position].down, AHEAD))
75 return (-1);
76 lflag = 0;
77 break;
78
79 case LEFT:
80 if (!move(left, LEFT))
81 return (-1);
82 lflag = 0;
83 break;
84
85 case RIGHT:
86 if (!move(right, RIGHT))
87 return (-1);
88 lflag = 0;
89 break;
90
91 case AHEAD:
92 if (!move(ahead, AHEAD))
93 return (-1);
94 lflag = 0;
95 break;
96
97 case BACK:
98 if (!move(back, BACK))
99 return (-1);
100 lflag = 0;
101 break;
102
103 case SHOOT:
104 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
105 for (n = 0; n < NUMOFOBJECTS; n++)
106 if (testbit(location[position].objects, n) && objsht[n]) {
107 wordvalue[wordnumber + 1] = n;
108 wordnumber = shoot();
109 }
110 wordnumber++;
111 wordnumber++;
112 } else
113 shoot();
114 break;
115
116 case TAKE:
117 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
118 for (n = 0; n < NUMOFOBJECTS; n++)
119 if (testbit(location[position].objects, n) && objsht[n]) {
120 wordvalue[wordnumber + 1] = n;
121 wordnumber = take(location[position].objects);
122 }
123 wordnumber++;
124 wordnumber++;
125 } else
126 take(location[position].objects);
127 break;
128
129 case DROP:
130
131 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
132 for (n = 0; n < NUMOFOBJECTS; n++)
133 if (testbit(inven, n)) {
134 wordvalue[wordnumber + 1] = n;
135 wordnumber = drop("Dropped");
136 }
137 wordnumber++;
138 wordnumber++;
139 } else
140 drop("Dropped");
141 break;
142
143
144 case KICK:
145 case THROW:
146 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
147 for (n = 0; n < NUMOFOBJECTS; n++)
148 if (testbit(inven, n) ||
149 (testbit(location[position].objects, n) && objsht[n])) {
150 wordvalue[wordnumber + 1] = n;
151 wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
152 }
153 wordnumber += 2;
154 } else
155 throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
156 break;
157
158 case TAKEOFF:
159 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
160 for (n = 0; n < NUMOFOBJECTS; n++)
161 if (testbit(wear, n)) {
162 wordvalue[wordnumber + 1] = n;
163 wordnumber = takeoff();
164 }
165 wordnumber += 2;
166 } else
167 takeoff();
168 break;
169
170
171 case DRAW:
172
173 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
174 for (n = 0; n < NUMOFOBJECTS; n++)
175 if (testbit(wear, n)) {
176 wordvalue[wordnumber + 1] = n;
177 wordnumber = draw();
178 }
179 wordnumber += 2;
180 } else
181 draw();
182 break;
183
184
185 case PUTON:
186
187 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
188 for (n = 0; n < NUMOFOBJECTS; n++)
189 if (testbit(location[position].objects, n) && objsht[n]) {
190 wordvalue[wordnumber + 1] = n;
191 wordnumber = puton();
192 }
193 wordnumber += 2;
194 } else
195 puton();
196 break;
197
198 case WEARIT:
199
200 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
201 for (n = 0; n < NUMOFOBJECTS; n++)
202 if (testbit(inven, n)) {
203 wordvalue[wordnumber + 1] = n;
204 wordnumber = wearit();
205 }
206 wordnumber += 2;
207 } else
208 wearit();
209 break;
210
211
212 case EAT:
213
214 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
215 for (n = 0; n < NUMOFOBJECTS; n++)
216 if (testbit(inven, n)) {
217 wordvalue[wordnumber + 1] = n;
218 wordnumber = eat();
219 }
220 wordnumber += 2;
221 } else
222 eat();
223 break;
224
225
226 case PUT:
227 put();
228 break;
229
230
231 case INVEN:
232 if (ucard(inven)) {
233 puts("You are holding:\n");
234 for (n = 0; n < NUMOFOBJECTS; n++)
235 if (testbit(inven, n))
236 printf("\t%s\n", objsht[n]);
237 printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."), (WEIGHT ? carrying * 100 / WEIGHT : -1));
238 printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER);
239 } else
240 puts("You aren't carrying anything.");
241
242 if (ucard(wear)) {
243 puts("\nYou are wearing:\n");
244 for (n = 0; n < NUMOFOBJECTS; n++)
245 if (testbit(wear, n))
246 printf("\t%s\n", objsht[n]);
247 } else
248 puts("\nYou are stark naked.");
249 if (card(injuries, NUMOFINJURIES)) {
250 puts("\nYou have suffered:\n");
251 for (n = 0; n < NUMOFINJURIES; n++)
252 if (injuries[n])
253 printf("\t%s\n", ouch[n]);
254 printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT, (WEIGHT == 1 ? "." : "s."));
255 } else
256 puts("\nYou are in perfect health.");
257 break;
258
259 case USE:
260 lflag = use();
261 break;
262
263 case LOOK:
264 if (!notes[CANTSEE] || testbit(inven, LAMPON) ||
265 testbit(location[position].objects, LAMPON)
266 || matchlight) {
267 beenthere[position] = 2;
268 writedes();
269 printobjs();
270 if (matchlight) {
271 puts("\nYour match splutters out.");
272 matchlight = 0;
273 }
274 } else
275 puts("I can't see anything.");
276 return (-1);
277 break;
278
279 case SU:
280 if (wiz || tempwiz) {
281 printf("\nRoom (was %d) = ", position);
282 fgets(buffer, 10, stdin);
283 if (*buffer != '\n')
284 sscanf(buffer, "%d", &position);
285 printf("Time (was %d) = ", ourtime);
286 fgets(buffer, 10, stdin);
287 if (*buffer != '\n')
288 sscanf(buffer, "%d", &ourtime);
289 printf("Fuel (was %d) = ", fuel);
290 fgets(buffer, 10, stdin);
291 if (*buffer != '\n')
292 sscanf(buffer, "%d", &fuel);
293 printf("Torps (was %d) = ", torps);
294 fgets(buffer, 10, stdin);
295 if (*buffer != '\n')
296 sscanf(buffer, "%d", &torps);
297 printf("CUMBER (was %d) = ", CUMBER);
298 fgets(buffer, 10, stdin);
299 if (*buffer != '\n')
300 sscanf(buffer, "%d", &CUMBER);
301 printf("WEIGHT (was %d) = ", WEIGHT);
302 fgets(buffer, 10, stdin);
303 if (*buffer != '\n')
304 sscanf(buffer, "%d", &WEIGHT);
305 printf("Clock (was %d) = ", ourclock);
306 fgets(buffer, 10, stdin);
307 if (*buffer != '\n')
308 sscanf(buffer, "%d", &ourclock);
309 printf("Wizard (was %d, %d) = ", wiz, tempwiz);
310 fgets(buffer, 10, stdin);
311 if (*buffer != '\n') {
312 sscanf(buffer, "%d", &junk);
313 if (!junk)
314 tempwiz = wiz = 0;
315 }
316 printf("\nDONE.\n");
317 return (0);
318 } else
319 puts("You aren't a wizard.");
320 break;
321
322 case SCORE:
323 printf("\tPLEASURE\tPOWER\t\tEGO\n");
324 printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego);
325 printf("This gives you the rating of %s in %d turns.\n", rate(), ourtime);
326 printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere, NUMOFROOMS), NUMOFROOMS, card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS);
327 break;
328
329 case KNIFE:
330 case KILL:
331 murder();
332 break;
333
334 case UNDRESS:
335 case RAVAGE:
336 ravage();
337 break;
338
339 case SAVE:
340 save();
341 break;
342
343 case FOLLOW:
344 lflag = follow();
345 break;
346
347 case GIVE:
348 give();
349 break;
350
351 case KISS:
352 kiss();
353 break;
354
355 case LOVE:
356 love();
357 break;
358
359 case RIDE:
360 lflag = ride();
361 break;
362
363 case DRIVE:
364 lflag = drive();
365 break;
366
367 case LIGHT:
368 light();
369 break;
370
371 case LAUNCH:
372 if (!launch())
373 return (-1);
374 else
375 lflag = 0;
376 break;
377
378 case LANDIT:
379 if (!land())
380 return (-1);
381 else
382 lflag = 0;
383 break;
384
385 case TIME:
386 chime();
387 break;
388
389 case SLEEP:
390 zzz();
391 break;
392
393 case DIG:
394 dig();
395 break;
396
397 case JUMP:
398 lflag = jump();
399 break;
400
401 case BURY:
402 bury();
403 break;
404
405 case SWIM:
406 puts("Surf's up!");
407 break;
408
409 case DRINK:
410 drink();
411 break;
412
413 case QUIT:
414 die();
415
416 default:
417 puts("How's that?");
418 return (-1);
419 break;
420
421
422 }
423 if (wordnumber < wordcount && *words[wordnumber++] == ',')
424 continue;
425 else
426 return (lflag);
427 }
428 return (lflag);
429 }