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