Remove some more unused headers.
[dragonfly.git] / games / battlestar / cypher.c
1 /*-
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
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. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)cypher.c 8.1 (Berkeley) 5/31/93
30  * $FreeBSD: src/games/battlestar/cypher.c,v 1.7.2.1 2001/03/05 11:45:36 kris Exp $
31  * $DragonFly: src/games/battlestar/cypher.c,v 1.3 2006/08/08 16:47:20 pavalos Exp $
32  */
33
34 #include "externs.h"
35
36 int
37 cypher(void)
38 {
39         int n;
40         int junk;
41         int lflag;
42         char buffer[10];
43
44         lflag = -1;
45         while (wordtype[wordnumber] == ADJS)
46                 wordnumber++;
47         while (wordnumber <= wordcount) {
48                 switch (wordvalue[wordnumber]) {
49                 case UP:
50                         if (location[position].access || wiz || tempwiz) {
51                                 if (!location[position].access)
52                                         puts("Zap!  A gust of wind lifts you up.");
53                                 if (!battlestar_move(location[position].up, AHEAD))
54                                         return (-1);
55                         } else {
56                                 puts("There is no way up");
57                                 return (-1);
58                         }
59                         lflag = 0;
60                         break;
61
62                 case DOWN:
63                         if (!battlestar_move(location[position].down, AHEAD))
64                                 return (-1);
65                         lflag = 0;
66                         break;
67
68                 case LEFT:
69                         if (!battlestar_move(left, LEFT))
70                                 return (-1);
71                         lflag = 0;
72                         break;
73
74                 case RIGHT:
75                         if (!battlestar_move(right, RIGHT))
76                                 return (-1);
77                         lflag = 0;
78                         break;
79
80                 case AHEAD:
81                         if (!battlestar_move(ahead, AHEAD))
82                                 return (-1);
83                         lflag = 0;
84                         break;
85
86                 case BACK:
87                         if (!battlestar_move(back, BACK))
88                                 return (-1);
89                         lflag = 0;
90                         break;
91
92                 case SHOOT:
93                         if (wordnumber < wordcount &&
94                             wordvalue[wordnumber + 1] == EVERYTHING) {
95                                 for (n = 0; n < NUMOFOBJECTS; n++)
96                                         if (testbit(location[position].objects,
97                                             n) && objsht[n]) {
98                                                 wordvalue[wordnumber + 1] = n;
99                                                 wordnumber = shoot();
100                                         }
101                                 wordnumber++;
102                                 wordnumber++;
103                         } else
104                                 shoot();
105                         break;
106
107                 case TAKE:
108                         if (wordnumber < wordcount &&
109                             wordvalue[wordnumber + 1] == EVERYTHING) {
110                                 for (n = 0; n < NUMOFOBJECTS; n++)
111                                         if (testbit(location[position].objects,
112                                             n) && objsht[n]) {
113                                                 wordvalue[wordnumber + 1] = n;
114                                                 wordnumber =
115                                                         take(location[position].objects);
116                                         }
117                                 wordnumber++;
118                                 wordnumber++;
119                         } else
120                                 take(location[position].objects);
121                         break;
122
123                 case DROP:
124                         if (wordnumber < wordcount &&
125                             wordvalue[wordnumber + 1] == EVERYTHING) {
126                                 for (n = 0; n < NUMOFOBJECTS; n++)
127                                         if (testbit(inven, n)) {
128                                                 wordvalue[wordnumber + 1] = n;
129                                                 wordnumber = drop("Dropped");
130                                         }
131                                 wordnumber++;
132                                 wordnumber++;
133                         } else
134                                 drop("Dropped");
135                         break;
136
137                 case KICK:
138                 case THROW:
139                         if (wordnumber < wordcount &&
140                             wordvalue[wordnumber + 1] == EVERYTHING) {
141                                 for (n = 0; n < NUMOFOBJECTS; n++) {
142                                         if ((testbit(inven, n) ||
143                                              testbit(location[position].objects, n)) && objsht[n]) {
144                                                 wordvalue[wordnumber + 1] = n;
145                                                 wordnumber = throw(wordvalue[wordnumber] ==
146                                                         KICK ? "Kicked" : "Thrown");
147                                         }
148                                 }
149                                 wordnumber += 2;
150                         } else
151                                 throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
152                         break;
153
154                 case TAKEOFF:
155                         if (wordnumber < wordcount &&
156                             wordvalue[wordnumber + 1] == EVERYTHING) {
157                                 for (n = 0; n < NUMOFOBJECTS; n++)
158                                         if (testbit(wear, n)) {
159                                                 wordvalue[wordnumber + 1] = n;
160                                                 wordnumber = takeoff();
161                                         }
162                                 wordnumber += 2;
163                         } else
164                                 takeoff();
165                         break;
166
167                 case DRAW:
168                         if (wordnumber < wordcount &&
169                             wordvalue[wordnumber + 1] == EVERYTHING) {
170                                 for (n = 0; n < NUMOFOBJECTS; n++)
171                                         if (testbit(wear, n)) {
172                                                 wordvalue[wordnumber + 1] = n;
173                                                 wordnumber = draw();
174                                         }
175                                 wordnumber += 2;
176                         } else
177                                 draw();
178                         break;
179
180                 case PUTON:
181                         if (wordnumber < wordcount &&
182                             wordvalue[wordnumber + 1] == EVERYTHING) {
183                                 for (n = 0; n < NUMOFOBJECTS; n++)
184                                         if (testbit(location[position].objects,
185                                             n) && objsht[n]) {
186                                                 wordvalue[wordnumber + 1] = n;
187                                                 wordnumber = puton();
188                                         }
189                                 wordnumber += 2;
190                         } else
191                                 puton();
192                         break;
193
194                 case WEARIT:
195                         if (wordnumber < wordcount &&
196                             wordvalue[wordnumber + 1] == EVERYTHING) {
197                                 for (n = 0; n < NUMOFOBJECTS; n++)
198                                         if (testbit(inven, n)) {
199                                                 wordvalue[wordnumber + 1] = n;
200                                                 wordnumber = wearit();
201                                         }
202                                 wordnumber += 2;
203                         } else
204                                 wearit();
205                         break;
206
207                 case EAT:
208                         if (wordnumber < wordcount &&
209                             wordvalue[wordnumber + 1] == EVERYTHING) {
210                                 for (n = 0; n < NUMOFOBJECTS; n++)
211                                         if (testbit(inven, n)) {
212                                                 wordvalue[wordnumber + 1] = n;
213                                                 wordnumber = eat();
214                                         }
215                                 wordnumber += 2;
216                         } else
217                                 eat();
218                         break;
219
220                 case PUT:
221                         put();
222                         break;
223
224                 case INVEN:
225                         if (ucard(inven)) {
226                                 puts("You are holding:\n");
227                                 for (n = 0; n < NUMOFOBJECTS; n++)
228                                         if (testbit(inven, n))
229                                                 printf("\t%s\n", objsht[n]);
230                                 printf("\n= %d kilogram%s (%d%%)\n", carrying,
231                                        (carrying == 1 ? "." : "s."),
232                                        (WEIGHT ? carrying * 100 / WEIGHT : -1));
233                                 printf("Your arms are %d%% full.\n",
234                                        encumber * 100 / CUMBER);
235                         } else
236                                 puts("You aren't carrying anything.");
237
238                         if (ucard(wear)) {
239                                 puts("\nYou are wearing:\n");
240                                 for (n = 0; n < NUMOFOBJECTS; n++)
241                                         if (testbit(wear, n))
242                                                 printf("\t%s\n", objsht[n]);
243                         } else
244                                 puts("\nYou are stark naked.");
245                         if (card(injuries, NUMOFINJURIES)) {
246                                 puts("\nYou have suffered:\n");
247                                 for (n = 0; n < NUMOFINJURIES; n++)
248                                         if (injuries[n])
249                                                 printf("\t%s\n", ouch[n]);
250                                 printf("\nYou can still carry up to %d kilogram%s\n",
251                                     WEIGHT, (WEIGHT == 1 ? "." : "s."));
252                         } else
253                                 puts("\nYou are in perfect health.");
254                         break;
255
256                 case USE:
257                         lflag = use();
258                         break;
259
260                 case LOOK:
261                         if (!notes[CANTSEE] || testbit(inven, LAMPON) ||
262                             testbit(location[position].objects, LAMPON) ||
263                             matchlight) {
264                                 beenthere[position] = 2;
265                                 writedes();
266                                 printobjs();
267                                 if (matchlight) {
268                                         puts("\nYour match splutters out.");
269                                         matchlight = 0;
270                                 }
271                         } else
272                                 puts("I can't see anything.");
273                         return (-1);
274                         break;
275
276                 case SU:
277                         if (wiz || tempwiz) {
278                                 printf("\nRoom (was %d) = ", position);
279                                 fgets(buffer, 10, stdin);
280                                 if (*buffer != '\n')
281                                         sscanf(buffer, "%d", &position);
282                                 printf("Time (was %d) = ", gtime);
283                                 fgets(buffer, 10, stdin);
284                                 if (*buffer != '\n')
285                                         sscanf(buffer, "%d", &gtime);
286                                 printf("Fuel (was %d) = ", fuel);
287                                 fgets(buffer, 10, stdin);
288                                 if (*buffer != '\n')
289                                         sscanf(buffer, "%d", &fuel);
290                                 printf("Torps (was %d) = ", torps);
291                                 fgets(buffer, 10, stdin);
292                                 if (*buffer != '\n')
293                                         sscanf(buffer, "%d", &torps);
294                                 printf("CUMBER (was %d) = ", CUMBER);
295                                 fgets(buffer, 10, stdin);
296                                 if (*buffer != '\n')
297                                         sscanf(buffer, "%d", &CUMBER);
298                                 printf("WEIGHT (was %d) = ", WEIGHT);
299                                 fgets(buffer, 10, stdin);
300                                 if (*buffer != '\n')
301                                         sscanf(buffer, "%d", &WEIGHT);
302                                 printf("Clock (was %d) = ", gclock);
303                                 fgets(buffer, 10, stdin);
304                                 if (*buffer != '\n')
305                                         sscanf(buffer, "%d", &gclock);
306                                 printf("Wizard (was %d, %d) = ", wiz, tempwiz);
307                                 fgets(buffer, 10, stdin);
308                                 if (*buffer != '\n') {
309                                         sscanf(buffer, "%d", &junk);
310                                         if (!junk)
311                                                 tempwiz = wiz = 0;
312                                 }
313                                 printf("\nDONE.\n");
314                                 return (0);
315                         } else
316                                 puts("You aren't a wizard.");
317                         break;
318
319                 case SCORE:
320                         printf("\tPLEASURE\tPOWER\t\tEGO\n");
321                         printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego);
322                         printf("This gives you the rating of %s in %d turns.\n",
323                             rate(), gtime);
324                         printf("You have visited %d out of %d rooms this run (%d%%).\n",
325                             card(beenthere, NUMOFROOMS), NUMOFROOMS,
326                             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(0);
415
416                 default:
417                         puts("How's that?");
418                         return (-1);
419                         break;
420                 }
421                 if (wordnumber < wordcount && *words[wordnumber++] == ',')
422                         continue;
423                 else
424                         return (lflag);
425         }
426         return (lflag);
427 }