Home | History | Annotate | Line # | Download | only in battlestar
command4.c revision 1.2
      1 /*	$NetBSD: command4.c,v 1.2 2003/08/07 09:37:00 agc 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. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #ifndef lint
     34 #if 0
     35 static char sccsid[] = "@(#)com4.c	8.2 (Berkeley) 4/28/95";
     36 #else
     37 __RCSID("$NetBSD: command4.c,v 1.2 2003/08/07 09:37:00 agc Exp $");
     38 #endif
     39 #endif				/* not lint */
     40 
     41 #include "extern.h"
     42 
     43 int
     44 take(from)
     45 	unsigned int from[];
     46 {
     47 	int     firstnumber, heavy, bulky, value;
     48 
     49 	firstnumber = wordnumber;
     50 	if (wordnumber < wordcount && wordvalue[wordnumber + 1] == OFF) {
     51 		wordnumber++;
     52 		wordvalue[wordnumber] = TAKEOFF;
     53 		wordtype[wordnumber] = VERB;
     54 		return (cypher());
     55 	} else {
     56 		wordnumber++;
     57 		while (wordnumber <= wordcount && wordtype[wordnumber] == OBJECT) {
     58 			value = wordvalue[wordnumber];
     59 			printf("%s:\n", objsht[value]);
     60 			heavy = (carrying + objwt[value]) <= WEIGHT;
     61 			bulky = (encumber + objcumber[value]) <= CUMBER;
     62 			if ((testbit(from, value) || wiz || tempwiz) && heavy && bulky && !testbit(inven, value)) {
     63 				setbit(inven, value);
     64 				carrying += objwt[value];
     65 				encumber += objcumber[value];
     66 				ourtime++;
     67 				if (testbit(from, value))
     68 					printf("Taken.\n");
     69 				else
     70 					printf("Zap! Taken from thin air.\n");
     71 				clearbit(from, value);
     72 				if (value == MEDALION)
     73 					win--;
     74 			} else if (testbit(inven, value))
     75 				printf("You're already holding %s%s.\n",
     76 				    A_OR_AN_OR_BLANK(value),
     77 				    objsht[value]);
     78 			else if (!testbit(from, value))
     79 				printf("I don't see any %s around here.\n", objsht[value]);
     80 			else if (!heavy)
     81 				printf("The %s %stoo heavy.\n", objsht[value],
     82 				    IS_OR_ARE(value));
     83 			else
     84 				printf("The %s %stoo cumbersome to hold.\n",
     85 				    objsht[value], IS_OR_ARE(value));
     86 			if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
     87 				wordnumber++;
     88 			else
     89 				return (firstnumber);
     90 		}
     91 	}
     92 	/* special cases with their own return()'s */
     93 
     94 	if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS)
     95 		switch (wordvalue[wordnumber]) {
     96 
     97 		case SWORD:
     98 			if (testbit(from, SWORD)) {
     99 				wordtype[wordnumber--] = OBJECT;
    100 				return (take(from));
    101 			}
    102 			if (testbit(from, TWO_HANDED)) {
    103 				wordvalue[wordnumber] = TWO_HANDED;
    104 				wordtype[wordnumber--] = OBJECT;
    105 				return (take(from));
    106 			}
    107 			wordvalue[wordnumber] = BROAD;
    108 			wordtype[wordnumber--] = OBJECT;
    109 			return (take(from));
    110 
    111 		case BODY:
    112 			if (testbit(from, MAID)) {
    113 				wordvalue[wordnumber] = MAID;
    114 				wordtype[wordnumber--] = OBJECT;
    115 				return (take(from));
    116 			} else if (testbit(from, DEADWOOD)) {
    117 				wordvalue[wordnumber] = DEADWOOD;
    118 				wordtype[wordnumber--] = OBJECT;
    119 				return (take(from));
    120 			} else if (testbit(from, DEADNATIVE)) {
    121 				wordvalue[wordnumber] = DEADNATIVE;
    122 				wordtype[wordnumber--] = OBJECT;
    123 				return (take(from));
    124 			} else {
    125 				if (testbit(from, DEADGOD)) {
    126 					wordvalue[wordnumber] = DEADGOD;
    127 					wordtype[wordnumber--] = OBJECT;
    128 					return (take(from));
    129 				} else {
    130 					wordvalue[wordnumber] = DEADTIME;
    131 					wordtype[wordnumber--] = OBJECT;
    132 					return (take(from));
    133 				}
    134 			}
    135 			break;
    136 
    137 		case AMULET:
    138 			if (testbit(location[position].objects, AMULET)) {
    139 				puts("The amulet is warm to the touch, and its beauty catches your breath.");
    140 				puts("A mist falls over your eyes, but then it is gone.  Sounds seem clearer");
    141 				puts("and sharper but far away as if in a dream.  The sound of purling water");
    142 				puts("reaches you from afar.  The mist falls again, and your heart leaps in horror.");
    143 				puts("The gold freezes your hands and fathomless darkness engulfs your soul.");
    144 			}
    145 			wordtype[wordnumber--] = OBJECT;
    146 			return (take(from));
    147 
    148 		case MEDALION:
    149 			if (testbit(location[position].objects, MEDALION)) {
    150 				puts("The medallion is warm, and it rekindles your spirit with the warmth of life.");
    151 				puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate.");
    152 			}
    153 			wordtype[wordnumber--] = OBJECT;
    154 			return (take(from));
    155 
    156 		case TALISMAN:
    157 			if (testbit(location[position].objects, TALISMAN)) {
    158 				puts("The talisman is cold to the touch, and it sends a chill down your spine.");
    159 			}
    160 			wordtype[wordnumber--] = OBJECT;
    161 			return (take(from));
    162 
    163 		case NORMGOD:
    164 			if (testbit(location[position].objects, BATHGOD) && (testbit(wear, AMULET) || testbit(inven, AMULET))) {
    165 				puts("She offers a delicate hand, and you help her out of the sparkling springs.");
    166 				puts("Water droplets like liquid silver bedew her golden skin, but when they part");
    167 				puts("from her, they fall as teardrops.  She wraps a single cloth around her and");
    168 				puts("ties it at the waist.  Around her neck hangs a golden amulet.");
    169 				puts("She bids you to follow her, and walks away.");
    170 				pleasure++;
    171 				followgod = ourtime;
    172 				clearbit(location[position].objects, BATHGOD);
    173 			} else
    174 				if (!testbit(location[position].objects, BATHGOD))
    175 					puts("You're in no position to take her.");
    176 				else
    177 					puts("She moves away from you.");
    178 			break;
    179 
    180 		default:
    181 			puts("It doesn't seem to work.");
    182 		}
    183 	else
    184 		puts("You've got to be kidding.");
    185 	return (firstnumber);
    186 }
    187 
    188 int
    189 throw(name)
    190 	const char   *name;
    191 {
    192 	unsigned int     n;
    193 	int     deposit = 0;
    194 	int     first, value;
    195 
    196 	first = wordnumber;
    197 	if (drop(name) != -1) {
    198 		switch (wordvalue[wordnumber]) {
    199 
    200 		case AHEAD:
    201 			deposit = ahead;
    202 			break;
    203 
    204 		case BACK:
    205 			deposit = back;
    206 			break;
    207 
    208 		case LEFT:
    209 			deposit = left;
    210 			break;
    211 
    212 		case RIGHT:
    213 			deposit = right;
    214 			break;
    215 
    216 		case UP:
    217 			deposit = location[position].up * (location[position].access || position == FINAL);
    218 			break;
    219 
    220 		case DOWN:
    221 			deposit = location[position].down;
    222 			break;
    223 		}
    224 		wordnumber = first + 1;
    225 		while (wordnumber <= wordcount) {
    226 			value = wordvalue[wordnumber];
    227 			if (deposit && testbit(location[position].objects, value)) {
    228 				clearbit(location[position].objects, value);
    229 				if (value != GRENADE)
    230 					setbit(location[deposit].objects, value);
    231 				else {
    232 					puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel.");
    233 					for (n = 0; n < NUMOFWORDS; n++)
    234 						location[deposit].objects[n] = 0;
    235 					setbit(location[deposit].objects, CHAR);
    236 				}
    237 				if (value == ROPE && position == FINAL)
    238 					location[position].access = 1;
    239 				switch (deposit) {
    240 				case 189:
    241 				case 231:
    242 					puts("The stone door is unhinged.");
    243 					location[189].north = 231;
    244 					location[231].south = 189;
    245 					break;
    246 				case 30:
    247 					puts("The wooden door is blown open.");
    248 					location[30].west = 25;
    249 					break;
    250 				case 31:
    251 					puts("The door is not damaged.");
    252 				}
    253 			} else
    254 				if (value == GRENADE && testbit(location[position].objects, value)) {
    255 					puts("You are blown into shreds when your grenade explodes.");
    256 					die();
    257 				}
    258 			if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
    259 				wordnumber++;
    260 			else
    261 				return (first);
    262 		}
    263 		return (first);
    264 	}
    265 	return (first);
    266 }
    267 
    268 int
    269 drop(name)
    270 	const char   *name;
    271 {
    272 
    273 	int     firstnumber, value;
    274 
    275 	firstnumber = wordnumber;
    276 	wordnumber++;
    277 	while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) {
    278 		value = wordvalue[wordnumber];
    279 		if (value == BODY) {	/* special case */
    280 			wordtype[wordnumber] = OBJECT;
    281 			if (testbit(inven, MAID) || testbit(location[position].objects, MAID))
    282 				value = MAID;
    283 			else if (testbit(inven, DEADWOOD) || testbit(location[position].objects, DEADWOOD))
    284 				value = DEADWOOD;
    285 			else if (testbit(inven, DEADGOD) || testbit(location[position].objects, DEADGOD))
    286 				value = DEADGOD;
    287 			else if (testbit(inven, DEADTIME) || testbit(location[position].objects, DEADTIME))
    288 				value = DEADTIME;
    289 			else if (testbit(inven, DEADNATIVE) || testbit(location[position].objects, DEADNATIVE))
    290 				value = DEADNATIVE;
    291 		}
    292 		if (wordtype[wordnumber] == NOUNS && value == DOOR) {
    293 			if (*name == 'K')
    294 				puts("You hurt your foot.");
    295 			else
    296 				puts("You're not holding a door.");
    297 		} else if (objsht[value] == NULL) {
    298 			if (*name == 'K')
    299 				puts("That's not for kicking!");
    300 			else
    301 				puts("You don't have that.");
    302 		} else {
    303 			printf("%s:\n", objsht[value]);
    304 			if (testbit(inven, value)) {
    305 				clearbit(inven, value);
    306 				carrying -= objwt[value];
    307 				encumber -= objcumber[value];
    308 				if (value == BOMB) {
    309 					puts("The bomb explodes.  A blinding white light and immense concussion obliterate us.");
    310 					die();
    311 				}
    312 				if (value != AMULET && value != MEDALION && value != TALISMAN)
    313 					setbit(location[position].objects, value);
    314 				else
    315 					tempwiz = 0;
    316 				ourtime++;
    317 				if (*name == 'K')
    318 					puts("Drop kicked.");
    319 				else
    320 					printf("%s.\n", name);
    321 			} else {
    322 				if (*name != 'K') {
    323 					printf("You aren't holding the %s.\n", objsht[value]);
    324 					if (testbit(location[position].objects, value)) {
    325 						if (*name == 'T')
    326 							puts("Kicked instead.");
    327 						else if (*name == 'G')
    328 							puts("Given anyway.");
    329 					}
    330 				} else if (testbit(location[position].objects, value))
    331 					puts("Kicked.");
    332 				else if (testbit(wear, value))
    333 					puts("Not while it's being worn.");
    334 				else
    335 					puts("Not found.");
    336 			}
    337 		}
    338 		if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
    339 			wordnumber++;
    340 		else
    341 			return (firstnumber);
    342 	}
    343 	puts("Do what?");
    344 	return (-1);
    345 }
    346 
    347 int
    348 takeoff()
    349 {
    350 	wordnumber = take(wear);
    351 	return (drop("Dropped"));
    352 }
    353 
    354 int
    355 puton()
    356 {
    357 	wordnumber = take(location[position].objects);
    358 	return (wearit());
    359 }
    360 
    361 int
    362 eat()
    363 {
    364 	int     firstnumber, value;
    365 
    366 	firstnumber = wordnumber;
    367 	wordnumber++;
    368 	while (wordnumber <= wordcount) {
    369 		value = wordvalue[wordnumber];
    370 		if (wordtype[wordnumber] != OBJECT || objsht[value] == NULL)
    371 			value = -2;
    372 		switch (value) {
    373 
    374 		case -2:
    375 			puts("You can't eat that!");
    376 			return (firstnumber);
    377 
    378 		case -1:
    379 			puts("Eat what?");
    380 			return (firstnumber);
    381 
    382 		default:
    383 			printf("You can't eat %s%s!\n",
    384 			    A_OR_AN_OR_BLANK(value), objsht[value]);
    385 			return (firstnumber);
    386 
    387 		case PAPAYAS:
    388 		case PINEAPPLE:
    389 		case KIWI:
    390 		case COCONUTS:	/* eatable things */
    391 		case MANGO:
    392 
    393 			printf("%s:\n", objsht[value]);
    394 			if (testbit(inven, value) &&
    395 			    ourtime > ate - CYCLE &&
    396 			    testbit(inven, KNIFE)) {
    397 				clearbit(inven, value);
    398 				carrying -= objwt[value];
    399 				encumber -= objcumber[value];
    400 				ate = max(ourtime, ate) + CYCLE / 3;
    401 				snooze += CYCLE / 10;
    402 				ourtime++;
    403 				puts("Eaten.  You can explore a little longer now.");
    404 			} else if (!testbit(inven, value))
    405 				printf("You aren't holding the %s.\n", objsht[value]);
    406 			else if (!testbit(inven, KNIFE))
    407 				puts("You need a knife.");
    408 			else
    409 				puts("You're stuffed.");
    410 			if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
    411 				wordnumber++;
    412 			else
    413 				return (firstnumber);
    414 		}		/* end switch */
    415 	}			/* end while */
    416 	return (firstnumber);
    417 }
    418