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