installer: Re-add the TEST_DEV command which was removed accidentally.
[dragonfly.git] / games / battlestar / cypher.c
blob09341b1aec872e674a8a5e8bca4988f332659f47
1 /*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
33 * @(#)cypher.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/battlestar/cypher.c,v 1.7.2.1 2001/03/05 11:45:36 kris Exp $
35 * $DragonFly: src/games/battlestar/cypher.c,v 1.3 2006/08/08 16:47:20 pavalos Exp $
38 #include "externs.h"
40 int
41 cypher(void)
43 int n;
44 int junk;
45 int lflag = -1;
46 char buffer[10];
48 while (wordtype[wordnumber] == ADJS)
49 wordnumber++;
50 while (wordnumber <= wordcount) {
51 switch(wordvalue[wordnumber]) {
53 case UP:
54 if (location[position].access || wiz || tempwiz) {
55 if (!location[position].access)
56 puts("Zap! A gust of wind lifts you up.");
57 if (!battlestar_move(location[position].up, AHEAD))
58 return(-1);
59 } else {
60 puts("There is no way up");
61 return(-1);
63 lflag = 0;
64 break;
66 case DOWN:
67 if (!battlestar_move(location[position].down,
68 AHEAD))
69 return(-1);
70 lflag = 0;
71 break;
73 case LEFT:
74 if (!battlestar_move(left, LEFT))
75 return(-1);
76 lflag = 0;
77 break;
79 case RIGHT:
80 if (!battlestar_move(right, RIGHT))
81 return(-1);
82 lflag = 0;
83 break;
85 case AHEAD:
86 if (!battlestar_move(ahead, AHEAD))
87 return(-1);
88 lflag = 0;
89 break;
91 case BACK:
92 if (!battlestar_move(back, BACK))
93 return(-1);
94 lflag = 0;
95 break;
97 case SHOOT:
98 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
99 for (n=0; n < NUMOFOBJECTS; n++)
100 if (testbit(location[position].objects,n) && objsht[n]){
101 wordvalue[wordnumber+1] = n;
102 wordnumber = shoot();
104 wordnumber++;
105 wordnumber++;
107 else
108 shoot();
109 break;
111 case TAKE:
112 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
113 for (n=0; n < NUMOFOBJECTS; n++)
114 if (testbit(location[position].objects,n) && objsht[n]){
115 wordvalue[wordnumber+1] = n;
116 wordnumber = take(location[position].objects);
118 wordnumber++;
119 wordnumber++;
121 else
122 take(location[position].objects);
123 break;
125 case DROP:
127 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
128 for (n=0; n < NUMOFOBJECTS; n++)
129 if (testbit(inven,n)){
130 wordvalue[wordnumber+1] = n;
131 wordnumber = drop("Dropped");
133 wordnumber++;
134 wordnumber++;
136 else
137 drop("Dropped");
138 break;
141 case KICK:
142 case THROW:
143 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
144 for (n=0; n < NUMOFOBJECTS; n++)
145 if ((testbit(inven,n) ||
146 testbit(location[position].objects, n)) && objsht[n]){
147 wordvalue[wordnumber+1] = n;
148 wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
150 wordnumber += 2;
151 } else
152 throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
153 break;
155 case TAKEOFF:
156 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
157 for (n=0; n < NUMOFOBJECTS; n++)
158 if (testbit(wear,n)){
159 wordvalue[wordnumber+1] = n;
160 wordnumber = takeoff();
162 wordnumber += 2;
164 else
165 takeoff();
166 break;
169 case DRAW:
171 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
172 for (n=0; n < NUMOFOBJECTS; n++)
173 if (testbit(wear,n)){
174 wordvalue[wordnumber+1] = n;
175 wordnumber = draw();
177 wordnumber += 2;
179 else
180 draw();
181 break;
184 case PUTON:
186 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
187 for (n=0; n < NUMOFOBJECTS; n++)
188 if (testbit(location[position].objects,n) && objsht[n]){
189 wordvalue[wordnumber+1] = n;
190 wordnumber = puton();
192 wordnumber += 2;
194 else
195 puton();
196 break;
198 case WEARIT:
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();
206 wordnumber += 2;
208 else
209 wearit();
210 break;
213 case EAT:
215 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
216 for (n=0; n < NUMOFOBJECTS; n++)
217 if (testbit(inven,n)){
218 wordvalue[wordnumber+1] = n;
219 wordnumber = eat();
221 wordnumber += 2;
223 else
224 eat();
225 break;
228 case PUT:
229 put();
230 break;
233 case INVEN:
234 if (ucard(inven)){
235 puts("You are holding:\n");
236 for (n=0; n < NUMOFOBJECTS; n++)
237 if (testbit(inven,n))
238 printf("\t%s\n", objsht[n]);
239 printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."),(WEIGHT ? carrying*100/WEIGHT : -1));
240 printf("Your arms are %d%% full.\n",encumber*100/CUMBER);
242 else
243 puts("You aren't carrying anything.");
245 if (ucard(wear)){
246 puts("\nYou are wearing:\n");
247 for (n=0; n < NUMOFOBJECTS; n++)
248 if (testbit(wear,n))
249 printf("\t%s\n", objsht[n]);
251 else
252 puts("\nYou are stark naked.");
253 if (card(injuries,NUMOFINJURIES)){
254 puts("\nYou have suffered:\n");
255 for (n=0; n < NUMOFINJURIES; n++)
256 if (injuries[n])
257 printf("\t%s\n",ouch[n]);
258 printf("\nYou can still carry up to %d kilogram%s\n",WEIGHT,(WEIGHT == 1 ? "." : "s."));
260 else
261 puts("\nYou are in perfect health.");
262 break;
264 case USE:
265 lflag = use();
266 break;
268 case LOOK:
269 if (!notes[CANTSEE] || testbit(inven,LAMPON) || testbit(location[position].objects,LAMPON) || matchlight){
270 beenthere[position] = 2;
271 writedes();
272 printobjs();
273 if (matchlight){
274 puts("\nYour match splutters out.");
275 matchlight = 0;
277 } else
278 puts("I can't see anything.");
279 return(-1);
280 break;
282 case SU:
283 if (wiz || tempwiz){
284 printf("\nRoom (was %d) = ", position);
285 fgets(buffer,10,stdin);
286 if (*buffer != '\n')
287 sscanf(buffer,"%d", &position);
288 printf("Time (was %d) = ",gtime);
289 fgets(buffer,10,stdin);
290 if (*buffer != '\n')
291 sscanf(buffer,"%d", &gtime);
292 printf("Fuel (was %d) = ",fuel);
293 fgets(buffer,10,stdin);
294 if (*buffer != '\n')
295 sscanf(buffer,"%d", &fuel);
296 printf("Torps (was %d) = ",torps);
297 fgets(buffer,10,stdin);
298 if (*buffer != '\n')
299 sscanf(buffer,"%d", &torps);
300 printf("CUMBER (was %d) = ",CUMBER);
301 fgets(buffer,10,stdin);
302 if (*buffer != '\n')
303 sscanf(buffer,"%d", &CUMBER);
304 printf("WEIGHT (was %d) = ",WEIGHT);
305 fgets(buffer,10,stdin);
306 if (*buffer != '\n')
307 sscanf(buffer,"%d",&WEIGHT);
308 printf("Clock (was %d) = ",gclock);
309 fgets(buffer,10,stdin);
310 if (*buffer != '\n')
311 sscanf(buffer,"%d",&gclock);
312 printf("Wizard (was %d, %d) = ",wiz, tempwiz);
313 fgets(buffer,10,stdin);
314 if (*buffer != '\n'){
315 sscanf(buffer,"%d",&junk);
316 if (!junk)
317 tempwiz = wiz = 0;
319 printf("\nDONE.\n");
320 return(0);
322 else
323 puts("You aren't a wizard.");
324 break;
326 case SCORE:
327 printf("\tPLEASURE\tPOWER\t\tEGO\n");
328 printf("\t%3d\t\t%3d\t\t%3d\n\n",pleasure,power,ego);
329 printf("This gives you the rating of %s in %d turns.\n",rate(),gtime);
330 printf("You have visited %d out of %d rooms this run (%d%%).\n",card(beenthere,NUMOFROOMS),NUMOFROOMS,card(beenthere,NUMOFROOMS)*100/NUMOFROOMS);
331 break;
333 case KNIFE:
334 case KILL:
335 murder();
336 break;
338 case UNDRESS:
339 case RAVAGE:
340 ravage();
341 break;
343 case SAVE:
344 save();
345 break;
347 case FOLLOW:
348 lflag = follow();
349 break;
351 case GIVE:
352 give();
353 break;
355 case KISS:
356 kiss();
357 break;
359 case LOVE:
360 love();
361 break;
363 case RIDE:
364 lflag = ride();
365 break;
367 case DRIVE:
368 lflag = drive();
369 break;
371 case LIGHT:
372 light();
373 break;
375 case LAUNCH:
376 if (!launch())
377 return(-1);
378 else
379 lflag = 0;
380 break;
382 case LANDIT:
383 if (!land())
384 return(-1);
385 else
386 lflag = 0;
387 break;
389 case TIME:
390 chime();
391 break;
393 case SLEEP:
394 zzz();
395 break;
397 case DIG:
398 dig();
399 break;
401 case JUMP:
402 lflag = jump();
403 break;
405 case BURY:
406 bury();
407 break;
409 case SWIM:
410 puts("Surf's up!");
411 break;
413 case DRINK:
414 drink();
415 break;
417 case QUIT:
418 die(0);
420 default:
421 puts("How's that?");
422 return(-1);
423 break;
427 if (wordnumber < wordcount && *words[wordnumber++] == ',')
428 continue;
429 else return(lflag);
431 return(lflag);