Home | History | Annotate | Line # | Download | only in battlestar
command5.c revision 1.2
      1  1.2  agc /*	$NetBSD: command5.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[] = "@(#)com5.c	8.2 (Berkeley) 4/28/95";
     36  1.1   tv #else
     37  1.2  agc __RCSID("$NetBSD: command5.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 void
     44  1.1   tv kiss()
     45  1.1   tv {
     46  1.1   tv 	while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount)
     47  1.1   tv 		continue;
     48  1.1   tv 	/* The goddess must be "taken" first if bathing. */
     49  1.1   tv 	if (wordtype[wordnumber] == NOUNS && wordvalue[wordnumber] == NORMGOD
     50  1.1   tv 	    && testbit(location[position].objects, BATHGOD)) {
     51  1.1   tv 		wordvalue[--wordnumber] = TAKE;
     52  1.1   tv 		cypher();
     53  1.1   tv 		return;
     54  1.1   tv 	}
     55  1.1   tv 	if (wordtype[wordnumber] == NOUNS) {
     56  1.1   tv 		if (testbit(location[position].objects, wordvalue[wordnumber])) {
     57  1.1   tv 			pleasure++;
     58  1.1   tv 			printf("Kissed.\n");
     59  1.1   tv 			switch (wordvalue[wordnumber]) {
     60  1.1   tv 			case NORMGOD:
     61  1.1   tv 				switch (godready++) {
     62  1.1   tv 				case 0:
     63  1.1   tv 					puts("She squirms and avoids your advances.");
     64  1.1   tv 					break;
     65  1.1   tv 				case 1:
     66  1.1   tv 					puts("She is coming around; she didn't fight it as much.");
     67  1.1   tv 					break;
     68  1.1   tv 				case 2:
     69  1.1   tv 					puts("She's beginning to like it.");
     70  1.1   tv 					break;
     71  1.1   tv 				default:
     72  1.1   tv 					puts("She's gone limp.");
     73  1.1   tv 
     74  1.1   tv 				}
     75  1.1   tv 				break;
     76  1.1   tv 			case NATIVE:
     77  1.1   tv 				puts("Her lips are warm and her body robust.  She pulls you down to the ground.");
     78  1.1   tv 				break;
     79  1.1   tv 			case TIMER:
     80  1.1   tv 				puts("The old man blushes.");
     81  1.1   tv 				break;
     82  1.1   tv 			case MAN:
     83  1.1   tv 				puts("The dwarf punches you in the kneecap.");
     84  1.1   tv 				break;
     85  1.1   tv 			default:
     86  1.1   tv 				pleasure--;
     87  1.1   tv 			}
     88  1.1   tv 		} else
     89  1.1   tv 			puts("I see nothing like that here.");
     90  1.1   tv 	} else
     91  1.1   tv 		puts("I'd prefer not to.");
     92  1.1   tv }
     93  1.1   tv 
     94  1.1   tv void
     95  1.1   tv love()
     96  1.1   tv {
     97  1.1   tv 	int     n;
     98  1.1   tv 
     99  1.1   tv 	while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount)
    100  1.1   tv 		continue;
    101  1.1   tv 	if (wordtype[wordnumber] == NOUNS) {
    102  1.1   tv 		if ((testbit(location[position].objects, BATHGOD) ||
    103  1.1   tv 		    testbit(location[position].objects, NORMGOD)) &&
    104  1.1   tv 		    wordvalue[wordnumber] == NORMGOD) {
    105  1.1   tv 			if (loved) {
    106  1.1   tv 				printf("Loved.\n");
    107  1.1   tv 				return;
    108  1.1   tv 			}
    109  1.1   tv 			if (godready >= 2) {
    110  1.1   tv 				puts("She cuddles up to you, and her mouth starts to work:\n'That was my sister's amulet.  The lovely goddess, Purl, was she.  The Empire\ncaptured her just after the Darkness came.  My other sister, Vert, was killed\nby the Dark Lord himself.  He took her amulet and warped its power.\nYour quest was foretold by my father before he died, but to get the Dark Lord's\namulet you must use cunning and skill.  I will leave you my amulet,");
    111  1.1   tv 				puts("which you may use as you wish.  As for me, I am the last goddess of the\nwaters.  My father was the Island King, and the rule is rightfully mine.'\n\nShe pulls the throne out into a large bed.");
    112  1.1   tv 				power++;
    113  1.1   tv 				pleasure += 15;
    114  1.1   tv 				ego++;
    115  1.1   tv 				if (card(injuries, NUMOFINJURIES)) {
    116  1.1   tv 					puts("Her kisses revive you; your wounds are healed.\n");
    117  1.1   tv 					for (n = 0; n < NUMOFINJURIES; n++)
    118  1.1   tv 						injuries[n] = 0;
    119  1.1   tv 					WEIGHT = MAXWEIGHT;
    120  1.1   tv 					CUMBER = MAXCUMBER;
    121  1.1   tv 				}
    122  1.1   tv 				printf("Goddess:\n");
    123  1.1   tv 				if (!loved)
    124  1.1   tv 					setbit(location[position].objects, MEDALION);
    125  1.1   tv 				loved = 1;
    126  1.1   tv 				ourtime += 10;
    127  1.1   tv 				printf("Loved.\n");
    128  1.1   tv 				zzz();
    129  1.1   tv 				return;
    130  1.1   tv 			} else {
    131  1.1   tv 				puts("You wish!");
    132  1.1   tv 				return;
    133  1.1   tv 			}
    134  1.1   tv 		}
    135  1.1   tv 		if (testbit(location[position].objects, wordvalue[wordnumber])) {
    136  1.1   tv 			if (wordvalue[wordnumber] == NATIVE) {
    137  1.1   tv 				puts("The girl is easy prey.  She peels off her sarong and indulges you.");
    138  1.1   tv 				power++;
    139  1.1   tv 				pleasure += 5;
    140  1.1   tv 				printf("Girl:\n");
    141  1.1   tv 				ourtime += 10;
    142  1.1   tv 				printf("Loved.\n");
    143  1.1   tv 				zzz();
    144  1.1   tv 			}
    145  1.1   tv 			if (wordvalue[wordnumber] == MAN ||
    146  1.1   tv 			    wordvalue[wordnumber] == BODY ||
    147  1.1   tv 			    wordvalue[wordnumber] == ELF ||
    148  1.1   tv 			    wordvalue[wordnumber] == TIMER)
    149  1.1   tv 				puts("Kinky!");
    150  1.1   tv 			else
    151  1.1   tv 				puts("It doesn't seem to work.");
    152  1.1   tv 		} else
    153  1.1   tv 			puts("Where's your lover?");
    154  1.1   tv 	} else
    155  1.1   tv 		puts("It doesn't seem to work.");
    156  1.1   tv }
    157  1.1   tv 
    158  1.1   tv int
    159  1.1   tv zzz()
    160  1.1   tv {
    161  1.1   tv 	int     oldtime;
    162  1.1   tv 	int     n;
    163  1.1   tv 
    164  1.1   tv 	oldtime = ourtime;
    165  1.1   tv 	if ((snooze - ourtime) < (0.75 * CYCLE)) {
    166  1.1   tv 		ourtime += 0.75 * CYCLE - (snooze - ourtime);
    167  1.1   tv 		printf("<zzz>");
    168  1.1   tv 		for (n = 0; n < ourtime - oldtime; n++)
    169  1.1   tv 			printf(".");
    170  1.1   tv 		printf("\n");
    171  1.1   tv 		snooze += 3 * (ourtime - oldtime);
    172  1.1   tv 		if (notes[LAUNCHED]) {
    173  1.1   tv 			fuel -= (ourtime - oldtime);
    174  1.1   tv 			if (location[position].down) {
    175  1.1   tv 				position = location[position].down;
    176  1.1   tv 				crash();
    177  1.1   tv 			} else
    178  1.1   tv 				notes[LAUNCHED] = 0;
    179  1.1   tv 		}
    180  1.1   tv 		if (OUTSIDE && rnd(100) < 50) {
    181  1.1   tv 			puts("You are awakened abruptly by the sound of someone nearby.");
    182  1.1   tv 			switch (rnd(4)) {
    183  1.1   tv 			case 0:
    184  1.1   tv 				if (ucard(inven)) {
    185  1.1   tv 					n = rnd(NUMOFOBJECTS);
    186  1.1   tv 					while (!testbit(inven, n))
    187  1.1   tv 						n = rnd(NUMOFOBJECTS);
    188  1.1   tv 					clearbit(inven, n);
    189  1.1   tv 					if (n != AMULET && n != MEDALION && n != TALISMAN)
    190  1.1   tv 						setbit(location[position].objects, n);
    191  1.1   tv 					carrying -= objwt[n];
    192  1.1   tv 					encumber -= objcumber[n];
    193  1.1   tv 				}
    194  1.1   tv 				puts("A fiendish little Elf is stealing your treasures!");
    195  1.1   tv 				fight(ELF, 10);
    196  1.1   tv 				break;
    197  1.1   tv 			case 1:
    198  1.1   tv 				setbit(location[position].objects, DEADWOOD);
    199  1.1   tv 				break;
    200  1.1   tv 			case 2:
    201  1.1   tv 				setbit(location[position].objects, HALBERD);
    202  1.1   tv 				break;
    203  1.1   tv 			default:
    204  1.1   tv 				break;
    205  1.1   tv 			}
    206  1.1   tv 		}
    207  1.1   tv 	} else
    208  1.1   tv 		return (0);
    209  1.1   tv 	return (1);
    210  1.1   tv }
    211  1.1   tv 
    212  1.1   tv void
    213  1.1   tv chime()
    214  1.1   tv {
    215  1.1   tv 	if ((ourtime / CYCLE + 1) % 2 && OUTSIDE)
    216  1.1   tv 		switch ((ourtime % CYCLE) / (CYCLE / 7)) {
    217  1.1   tv 		case 0:
    218  1.1   tv 			puts("It is just after sunrise.");
    219  1.1   tv 			break;
    220  1.1   tv 		case 1:
    221  1.1   tv 			puts("It is early morning.");
    222  1.1   tv 			break;
    223  1.1   tv 		case 2:
    224  1.1   tv 			puts("It is late morning.");
    225  1.1   tv 			break;
    226  1.1   tv 		case 3:
    227  1.1   tv 			puts("It is near noon.");
    228  1.1   tv 			break;
    229  1.1   tv 		case 4:
    230  1.1   tv 			puts("It is early afternoon.");
    231  1.1   tv 			break;
    232  1.1   tv 		case 5:
    233  1.1   tv 			puts("It is late afternoon.");
    234  1.1   tv 			break;
    235  1.1   tv 		case 6:
    236  1.1   tv 			puts("It is near sunset.");
    237  1.1   tv 			break;
    238  1.1   tv 		}
    239  1.1   tv 	else if (OUTSIDE)
    240  1.1   tv 		switch ((ourtime % CYCLE) / (CYCLE / 7)) {
    241  1.1   tv 		case 0:
    242  1.1   tv 			puts("It is just after sunset.");
    243  1.1   tv 			break;
    244  1.1   tv 		case 1:
    245  1.1   tv 			puts("It is early evening.");
    246  1.1   tv 			break;
    247  1.1   tv 		case 2:
    248  1.1   tv 			puts("The evening is getting old.");
    249  1.1   tv 			break;
    250  1.1   tv 		case 3:
    251  1.1   tv 			puts("It is near midnight.");
    252  1.1   tv 			break;
    253  1.1   tv 		case 4:
    254  1.1   tv 			puts("These are the wee hours of the morning.");
    255  1.1   tv 			break;
    256  1.1   tv 		case 5:
    257  1.1   tv 			puts("The night is waning.");
    258  1.1   tv 			break;
    259  1.1   tv 		case 6:
    260  1.1   tv 			puts("It is almost morning.");
    261  1.1   tv 			break;
    262  1.1   tv 		}
    263  1.1   tv 	else
    264  1.1   tv 		puts("I can't tell the time in here.");
    265  1.1   tv }
    266  1.1   tv 
    267  1.1   tv int
    268  1.1   tv give()
    269  1.1   tv {
    270  1.1   tv 	int     obj = -1, result = -1, person = 0, firstnumber, last1, last2;
    271  1.1   tv 
    272  1.1   tv 	last1 = last2 = 0;
    273  1.1   tv 	firstnumber = wordnumber;
    274  1.1   tv 	while (wordtype[++wordnumber] != OBJECT && wordvalue[wordnumber] != AMULET && wordvalue[wordnumber] != MEDALION && wordvalue[wordnumber] != TALISMAN && wordnumber <= wordcount)
    275  1.1   tv 		continue;
    276  1.1   tv 	if (wordnumber <= wordcount) {
    277  1.1   tv 		obj = wordvalue[wordnumber];
    278  1.1   tv 		if (obj == EVERYTHING)
    279  1.1   tv 			wordtype[wordnumber] = -1;
    280  1.1   tv 		last1 = wordnumber;
    281  1.1   tv 	}
    282  1.1   tv 	wordnumber = firstnumber;
    283  1.1   tv 	while ((wordtype[++wordnumber] != NOUNS || wordvalue[wordnumber] == obj) && wordnumber <= wordcount);
    284  1.1   tv 	if (wordtype[wordnumber] == NOUNS) {
    285  1.1   tv 		person = wordvalue[wordnumber];
    286  1.1   tv 		last2 = wordnumber;
    287  1.1   tv 	}
    288  1.1   tv 	/* Setting wordnumber to last1 - 1 looks wrong if last1 is 0, e.g.,
    289  1.1   tv 	 * plain `give'.  However, detecting this case is liable to detect
    290  1.1   tv 	 * `give foo' as well, which would give a confusing error.  We
    291  1.1   tv 	 * need to make sure the -1 value can cause no problems if it arises.
    292  1.1   tv 	 * If in the below we get to the drop("Given") then drop will look
    293  1.1   tv 	 * at word 0 for an object to give, and fail, which is OK; then
    294  1.1   tv 	 * result will be -1 and we get to the end, where wordnumber gets
    295  1.1   tv 	 * set to something more sensible.  If we get to "I don't think
    296  1.1   tv 	 * that is possible" then again wordnumber is set to something
    297  1.1   tv 	 * sensible.  The wordnumber we leave with still isn't right if
    298  1.1   tv 	 * you include words the game doesn't know in your command, but
    299  1.1   tv 	 * that's no worse than what other commands than give do in
    300  1.1   tv 	 * the same place.  */
    301  1.1   tv 	wordnumber = last1 - 1;
    302  1.1   tv 	if (person && testbit(location[position].objects, person)) {
    303  1.1   tv 		if (person == NORMGOD && godready < 2 && !(obj == RING || obj == BRACELET))
    304  1.1   tv 			puts("The goddess won't look at you.");
    305  1.1   tv 		else
    306  1.1   tv 			result = drop("Given");
    307  1.1   tv 	} else {
    308  1.1   tv 		puts("I don't think that is possible.");
    309  1.1   tv 		wordnumber = max(last1, last2) + 1;
    310  1.1   tv 		return (0);
    311  1.1   tv 	}
    312  1.1   tv 	if (result != -1 && (testbit(location[position].objects, obj) || obj == AMULET || obj == MEDALION || obj == TALISMAN)) {
    313  1.1   tv 		clearbit(location[position].objects, obj);
    314  1.1   tv 		ourtime++;
    315  1.1   tv 		ego++;
    316  1.1   tv 		switch (person) {
    317  1.1   tv 		case NATIVE:
    318  1.1   tv 			puts("She accepts it shyly.");
    319  1.1   tv 			ego += 2;
    320  1.1   tv 			break;
    321  1.1   tv 		case NORMGOD:
    322  1.1   tv 			if (obj == RING || obj == BRACELET) {
    323  1.1   tv 				puts("She takes the charm and puts it on.  A little kiss on the cheek is");
    324  1.1   tv 				puts("your reward.");
    325  1.1   tv 				ego += 5;
    326  1.1   tv 				godready += 3;
    327  1.1   tv 			}
    328  1.1   tv 			if (obj == AMULET || obj == MEDALION || obj == TALISMAN) {
    329  1.1   tv 				win++;
    330  1.1   tv 				ego += 5;
    331  1.1   tv 				power -= 5;
    332  1.1   tv 				if (win >= 3) {
    333  1.1   tv 					puts("The powers of the earth are now legitimate.  You have destroyed the Darkness");
    334  1.1   tv 					puts("and restored the goddess to her throne.  The entire island celebrates with");
    335  1.1   tv 					puts("dancing and spring feasts.  As a measure of her gratitude, the goddess weds you");
    336  1.1   tv 					puts("in the late summer and crowns you Prince Liverwort, Lord of Fungus.");
    337  1.1   tv 					puts("\nBut, as the year wears on and autumn comes along, you become restless and");
    338  1.1   tv 					puts("yearn for adventure.  The goddess, too, realizes that the marriage can't last.");
    339  1.1   tv 					puts("She becomes bored and takes several more natives as husbands.  One evening,");
    340  1.1   tv 					puts("after having been out drinking with the girls, she kicks the throne particularly");
    341  1.1   tv 					puts("hard and wakes you up.  (If you want to win this game, you're going to have to\nshoot her!)");
    342  1.1   tv 					clearbit(location[position].objects, MEDALION);
    343  1.1   tv 					wintime = ourtime;
    344  1.1   tv 				}
    345  1.1   tv 			}
    346  1.1   tv 			break;
    347  1.1   tv 		case TIMER:
    348  1.1   tv 			if (obj == COINS) {
    349  1.1   tv 				puts("He fingers the coins for a moment and then looks up agape.  `Kind you are and");
    350  1.1   tv 				puts("I mean to repay you as best I can.'  Grabbing a pencil and cocktail napkin...\n");
    351  1.1   tv 				printf("+-----------------------------------------------------------------------------+\n");
    352  1.1   tv 				printf("|				   xxxxxxxx\\				      |\n");
    353  1.1   tv 				printf("|				       xxxxx\\	CLIFFS			      |\n");
    354  1.1   tv 				printf("|		FOREST			  xxx\\				      |\n");
    355  1.1   tv 				printf("|				\\\\	     x\\        	OCEAN		      |\n");
    356  1.1   tv 				printf("|				||	       x\\			      |\n");
    357  1.1   tv 				printf("|				||  ROAD	x\\			      |\n");
    358  1.1   tv 				printf("|				||		x\\			      |\n");
    359  1.1   tv 				printf("|		SECRET		||	  .........			      |\n");
    360  1.1   tv 				printf("|		 - + -		||	   ........			      |\n");
    361  1.1   tv 				printf("|		ENTRANCE	||		...      BEACH		      |\n");
    362  1.1   tv 				printf("|				||		...		  E	      |\n");
    363  1.1   tv 				printf("|				||		...		  |	      |\n");
    364  1.1   tv 				printf("|				//		...	    N <-- + --- S     |\n");
    365  1.1   tv 				printf("|		PALM GROVE     //		...		  |	      |\n");
    366  1.1   tv 				printf("|			      //		...		  W	      |\n");
    367  1.1   tv 				printf("+-----------------------------------------------------------------------------+\n");
    368  1.1   tv 				puts("\n`This map shows a secret entrance to the catacombs.");
    369  1.1   tv 				puts("You will know when you arrive because I left an old pair of shoes there.'");
    370  1.1   tv 			}
    371  1.1   tv 			break;
    372  1.1   tv 		}
    373  1.1   tv 	}
    374  1.1   tv 	wordnumber = max(last1, last2) + 1;
    375  1.1   tv 	return (firstnumber);
    376  1.1   tv }
    377