When outputing a code listing, properly display
[dragonfly.git] / games / battlestar / com4.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. 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.
20  *
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.
32  *
33  * @(#)com4.c   8.1 (Berkeley) 5/31/93
34  * $FreeBSD: src/games/battlestar/com4.c,v 1.8.2.1 2001/03/05 11:45:35 kris Exp $
35  * $DragonFly: src/games/battlestar/com4.c,v 1.3 2006/08/08 16:47:20 pavalos Exp $
36  */
37
38 #include "externs.h"
39
40 int
41 take(unsigned int from[])
42 {
43         int firstnumber, heavy, bulky, value;
44         int n;
45
46         firstnumber = wordnumber;
47         if (wordnumber < wordcount && wordvalue[wordnumber+1] == OFF){
48                 wordnumber++;
49                 wordvalue[wordnumber] = TAKEOFF;
50                 return(cypher());
51         }
52         else {
53                 while(wordtype[++wordnumber] == ADJS);
54                 while(wordnumber<=wordcount && wordtype[wordnumber] == OBJECT){
55                         value = wordvalue[wordnumber];
56                         printf("%s:\n", objsht[value]);
57                         for (n=0; objsht[value][n]; n++);
58                         heavy = (carrying + objwt[value]) <= WEIGHT;
59                         bulky = (encumber + objcumber[value]) <= CUMBER;
60                         if ((testbit(from,value) || wiz || tempwiz) && heavy && bulky && !testbit(inven,value)){
61                                 setbit(inven,value);
62                                 carrying += objwt[value];
63                                 encumber += objcumber[value];
64                                 gtime++;
65                                 if (testbit(from,value))
66                                         printf("Taken.\n");
67                                 else
68                                         printf("Zap! Taken from thin air.\n");
69                                 clearbit(from,value);
70                                 if (value == MEDALION)
71                                         bs_win--;
72                         }
73                         else if (testbit(inven,value))
74                                 printf("You're already holding%s%s.\n", (objsht[value][n-1] == 's' ? " " : " a "),objsht[value]);
75                         else if (!heavy)
76                                 printf("The %s %s too heavy.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is"));
77                         else if (!bulky)
78                                 printf("The %s %s too cumbersome to hold.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is"));
79                         else
80                                 printf("I dont see any %s around here.\n", objsht[value]);
81                         if (wordnumber < wordcount -1 && wordvalue[++wordnumber] == AND)
82                                 wordnumber++;
83                         else
84                                 return(firstnumber);
85                 }
86         }
87                             /* special cases with their own return()'s */
88
89         if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS)
90                 switch(wordvalue[wordnumber]){
91
92                         case SWORD:
93                                 if (testbit(from, SWORD)){
94                                         wordtype[wordnumber--] = OBJECT;
95                                         return(take(from));
96                                 }
97                                 if (testbit(from, TWO_HANDED)){
98                                         wordvalue[wordnumber] = TWO_HANDED;
99                                         wordtype[wordnumber--] = OBJECT;
100                                         return(take(from));
101                                 }
102                                 wordvalue[wordnumber] = BROAD;
103                                 wordtype[wordnumber--] = OBJECT;
104                                 return(take(from));
105
106                         case BODY:
107                                 if (testbit(from,MAID)){
108                                         wordvalue[wordnumber] = MAID;
109                                         wordtype[wordnumber--] = OBJECT;
110                                         return(take(from));
111                                 }
112                                 else if (testbit(from,DEADWOOD)){
113                                         wordvalue[wordnumber] = DEADWOOD;
114                                         wordtype[wordnumber--] = OBJECT;
115                                         return(take(from));
116                                 }
117                                 else if (testbit(from,DEADNATIVE)){
118                                         wordvalue[wordnumber] = DEADNATIVE;
119                                         wordtype[wordnumber--] = OBJECT;
120                                         return(take(from));
121                                 }
122                                 else if (testbit(from,DEADGOD)){
123                                         wordvalue[wordnumber] = DEADGOD;
124                                         wordtype[wordnumber--] = OBJECT;
125                                         return(take(from));
126                                 }
127                                 else {
128                                         wordvalue[wordnumber] = DEADTIME;
129                                         wordtype[wordnumber--] = OBJECT;
130                                         return(take(from));
131                                 }
132                                 break;
133
134                         case AMULET:
135                                 if (testbit(location[position].objects,AMULET)){
136                                         puts("The amulet is warm to the touch, and its beauty catches your breath.");
137                                         puts("A mist falls over your eyes, but then it is gone.  Sounds seem clearer");
138                                         puts("and sharper but far away as if in a dream.  The sound of purling water reaches");
139                                         puts("you from afar.  The mist falls again, and your heart leaps in horror.  The gold");
140                                         puts("freezes your hands and fathomless darkness engulfs your soul.");
141                                 }
142                                 wordtype[wordnumber--] = OBJECT;
143                                 return(take(from));
144
145                         case MEDALION:
146                                 if (testbit(location[position].objects, MEDALION)){
147                                         puts("The medallion is warm, and it rekindles your spirit with the warmth of life.");
148                                         puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate.");
149                                 }
150                                 wordtype[wordnumber--] = OBJECT;
151                                 return(take(from));
152
153                         case TALISMAN:
154                                 if (testbit(location[position].objects,TALISMAN)){
155                                         puts("The talisman is cold to the touch, and it sends a chill down your spine.");
156                                 }
157                                 wordtype[wordnumber--] = OBJECT;
158                                 return(take(from));
159
160                         case NORMGOD:
161                                 if (testbit(location[position].objects,BATHGOD) && (testbit(wear,AMULET) || testbit(inven,AMULET))){
162                                         puts("She offers a delicate hand, and you help her out of the sparkling springs.");
163                                         puts("Water droplets like liquid silver bedew her golden skin, but when they part");
164                                         puts("from her, they fall as teardrops.  She wraps a single cloth around her and");
165                                         puts("ties it at the waist.  Around her neck hangs a golden amulet.");
166                                         puts("She bids you to follow her.");
167                                         pleasure++;
168                                         followgod = gtime;
169                                         clearbit(location[position].objects,BATHGOD);
170                                 } else if (!testbit(location[position].objects,BATHGOD))
171                                         puts("You're in no position to take her.");
172                                 else
173                                         puts("She moves away from you.");
174                                 break;
175
176                         default:
177                                 puts("It doesn't seem to work.");
178                 }
179         else
180                 puts("You've got to be kidding.");
181         return(firstnumber);
182 }
183
184 int
185 throw(const char *name)
186 {
187         int n;
188         int deposit = 0;
189         int first, value;
190
191         first = wordnumber;
192         if (drop(name) != -1){
193                 switch(wordvalue[wordnumber]){
194
195                         case AHEAD:
196                                 deposit = ahead;
197                                 break;
198
199                         case BACK:
200                                 deposit = back;
201                                 break;
202
203                         case LEFT:
204                                 deposit = left;
205                                 break;
206
207                         case RIGHT:
208                                 deposit = right;
209                                 break;
210
211                         case UP:
212                                 deposit = location[position].up * (location[position].access || position == FINAL);
213                                 break;
214
215                         case DOWN:
216                                 deposit = location[position].down;
217                                 break;
218                 }
219                 wordnumber = first;
220                 while (wordtype[++wordnumber] == ADJS);
221                 while (wordnumber <= wordcount){
222                         value = wordvalue[wordnumber];
223                         if (deposit && testbit(location[position].objects,value)){
224                                 clearbit(location[position].objects,value);
225                                 if (value != GRENADE)
226                                         setbit(location[deposit].objects,value);
227                                 else{
228                                         puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel.");
229                                         for (n = 0; n < NUMOFWORDS; n ++)
230                                                 location[deposit].objects[n] = 0;
231                                         setbit(location[deposit].objects,CHAR);
232                                 }
233                                 if (value == ROPE && position == FINAL)
234                                         location[position].access = 1;
235                                 switch(deposit){
236                                         case 189:
237                                         case 231:
238                                                 puts("The stone door is unhinged.");
239                                                 location[189].north = 231;
240                                                 location[231].south = 189;
241                                                 break;
242                                         case 30:
243                                                 puts("The wooden door is blown open.");
244                                                 location[30].west = 25;
245                                                 break;
246                                         case 31:
247                                                 puts("The door is not damaged.");
248                                 }
249                         }
250                         else if (value == GRENADE && testbit(location[position].objects,value)){
251                                 puts("You are blown into shreds when your grenade explodes.");
252                                 die(0);
253                         }
254                         if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
255                                 wordnumber++;
256                         else
257                                 return(first);
258                 }
259                 return(first);
260         }
261         return(first);
262 }
263
264 int
265 drop(const char *name)
266 {
267
268         int firstnumber, value;
269
270         firstnumber = wordnumber;
271         while (wordtype[++wordnumber] == ADJS)
272                 ;
273         while (wordnumber<=wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) {
274                 value = wordvalue[wordnumber];
275                 printf("%s:\n", objsht[value]);
276                 if (testbit(inven,value)){
277                         clearbit(inven,value);
278                         carrying -= objwt[value];
279                         encumber -= objcumber[value];
280                         if (value == BOMB){
281                                 puts("The bomb explodes.  A blinding white light and immense concussion obliterate us.");
282                                 die(0);
283                         }
284                         if (value != AMULET && value != MEDALION && value != TALISMAN)
285                                 setbit(location[position].objects,value);
286                         else
287                                 tempwiz = 0;
288                         gtime++;
289                         if (*name == 'K')
290                                 puts("Drop kicked.");
291                         else
292                                 printf("%s.\n", name);
293                 }
294                 else {
295                         if (*name != 'K') {
296                                 printf("You aren't holding the %s.\n", objsht[value]);
297                                 if (testbit(location[position].objects,value)) {
298                                         if (*name == 'T')
299                                                 puts("Kicked instead.");
300                                         else if (*name == 'G')
301                                                 puts("Given anyway.");
302                                 }
303                         } else
304                                 puts("Kicked.");
305                 }
306                 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
307                         wordnumber++;
308                 else
309                         return(firstnumber);
310         }
311         puts("Do what?");
312         return(-1);
313 }
314
315 int
316 takeoff(void)
317 {
318         wordnumber = take(wear);
319         return(drop("Dropped"));
320 }
321
322 int
323 puton(void)
324 {
325         wordnumber = take(location[position].objects);
326         return(wearit());
327 }
328
329 int
330 eat(void)
331 {
332         int firstnumber, value;
333
334         firstnumber = wordnumber;
335         while(wordtype[++wordnumber] == ADJS);
336         while(wordnumber <= wordcount){
337                 value = wordvalue[wordnumber];
338                 switch(value){
339
340                         case -1:
341                                 puts("Eat what?");
342                                 return(firstnumber);
343
344                         default:
345                                 printf("You can't eat%s%s!\n",
346                                         wordtype[wordnumber] == OBJECT &&
347                                         objsht[value]
348                                         [strlen(objsht[value]) - 1] == 's' ?
349                                         " " : " a ",
350                                         words[wordnumber]);
351                                 return(firstnumber);
352
353                         case PAPAYAS:
354                         case PINEAPPLE:
355                         case KIWI:
356                         case COCONUTS:  /* eatable things */
357                         case MANGO:
358
359                                 printf("%s:\n",objsht[value]);
360                                 if (testbit(inven,value) && gtime > ate - CYCLE && testbit(inven,KNIFE)){
361                                         clearbit(inven,value);
362                                         carrying -= objwt[value];
363                                         encumber -= objcumber[value];
364                                         ate = max(gtime,ate) + CYCLE/3;
365                                         snooze += CYCLE/10;
366                                         gtime++;
367                                         puts("Eaten.  You can explore a little longer now.");
368                                 }
369                                 else if (gtime < ate - CYCLE)
370                                         puts("You're stuffed.");
371                                 else if (!testbit(inven,KNIFE))
372                                         puts("You need a knife.");
373                                 else
374                                         printf("You aren't holding the %s.\n", objsht[value]);
375                                 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
376                                         wordnumber++;
377                                 else
378                                         return(firstnumber);
379                 } /* end switch */
380         } /* end while */
381         return(firstnumber);
382 }