Home | History | Annotate | Line # | Download | only in battlestar
command1.c revision 1.3
      1  1.3  jmc /*	$NetBSD: command1.c,v 1.3 2005/07/01 06:04:54 jmc 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[] = "@(#)com1.c	8.2 (Berkeley) 4/28/95";
     36  1.1   tv #else
     37  1.3  jmc __RCSID("$NetBSD: command1.c,v 1.3 2005/07/01 06:04:54 jmc 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.3  jmc moveplayer(int thataway, int token)
     45  1.1   tv {
     46  1.1   tv 	wordnumber++;
     47  1.1   tv 	if ((!notes[CANTMOVE] && !notes[LAUNCHED]) ||
     48  1.1   tv 	    testbit(location[position].objects, LAND) ||
     49  1.1   tv 	    (fuel > 0 && notes[LAUNCHED])) {
     50  1.1   tv 		if (thataway) {
     51  1.1   tv 			position = thataway;
     52  1.1   tv 			newway(token);
     53  1.1   tv 			ourtime++;
     54  1.1   tv 		} else {
     55  1.1   tv 			puts("You can't go this way.");
     56  1.1   tv 			newway(token);
     57  1.1   tv 			whichway(location[position]);
     58  1.1   tv 			return (0);
     59  1.1   tv 		}
     60  1.1   tv 	} else {
     61  1.3  jmc 		if (notes[CANTMOVE] && !notes[LAUNCHED]) {
     62  1.3  jmc 			printf("You aren't able to move; you better drop ");
     63  1.3  jmc 			puts("something.");
     64  1.3  jmc 		} else {
     65  1.3  jmc 			printf("You are out of fuel; ");
     66  1.3  jmc 			puts("now you will rot in space forever!");
     67  1.3  jmc 		}
     68  1.1   tv 	}
     69  1.1   tv 	return (1);
     70  1.1   tv }
     71  1.1   tv 
     72  1.3  jmc /* Converts day to night and vice versa. 	    */
     73  1.1   tv void
     74  1.3  jmc convert(int tothis)
     75  1.3  jmc {
     76  1.1   tv 	const struct objs *p;
     77  1.1   tv 	unsigned int     i, j;
     78  1.1   tv 
     79  1.1   tv 	if (tothis == TONIGHT) {
     80  1.1   tv 		for (i = 1; i <= NUMOFROOMS; i++)
     81  1.1   tv 			for (j = 0; j < NUMOFWORDS; j++)
     82  1.1   tv 				nightfile[i].objects[j] = dayfile[i].objects[j];
     83  1.1   tv 		for (p = nightobjs; p->room != 0; p++)
     84  1.1   tv 			setbit(nightfile[p->room].objects, p->obj);
     85  1.1   tv 		location = nightfile;
     86  1.1   tv 	} else {
     87  1.1   tv 		for (i = 1; i <= NUMOFROOMS; i++)
     88  1.1   tv 			for (j = 0; j < NUMOFWORDS; j++)
     89  1.1   tv 				dayfile[i].objects[j] = nightfile[i].objects[j];
     90  1.1   tv 		for (p = nightobjs; p->room != 0; p++)
     91  1.1   tv 			clearbit(dayfile[p->room].objects, p->obj);
     92  1.1   tv 		location = dayfile;
     93  1.1   tv 	}
     94  1.1   tv }
     95  1.1   tv 
     96  1.1   tv void
     97  1.1   tv news()
     98  1.1   tv {
     99  1.1   tv 	int     n;
    100  1.1   tv 	int     hurt;
    101  1.1   tv 
    102  1.1   tv 	if (ourtime > 30 && position < 32) {
    103  1.3  jmc 		printf("An explosion of shuddering magnitude splinters ");
    104  1.3  jmc 		puts("bulkheads and");
    105  1.3  jmc 		printf("ruptures the battlestar's hull.  You are sucked out ");
    106  1.3  jmc 		puts("into the");
    107  1.1   tv 		puts("frozen void of space and killed.");
    108  1.1   tv 		die();
    109  1.1   tv 	}
    110  1.1   tv 	if (ourtime > 20 && position < 32)
    111  1.1   tv 		puts("Explosions rock the battlestar.");
    112  1.1   tv 	if (ourtime > snooze) {
    113  1.1   tv 		puts("You drop from exhaustion...");
    114  1.1   tv 		zzz();
    115  1.1   tv 	}
    116  1.1   tv 	if (ourtime > snooze - 5)
    117  1.1   tv 		puts("You're getting tired.");
    118  1.1   tv 	if (ourtime > (rythmn + CYCLE)) {
    119  1.1   tv 		if (location == nightfile) {
    120  1.1   tv 			convert(TODAY);
    121  1.1   tv 			if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
    122  1.3  jmc 				printf("Dew lit sunbeams stretch out from a ");
    123  1.3  jmc 				puts("watery sunrise and herald the dawn.");
    124  1.3  jmc 				printf("You awake from a misty dream-world ");
    125  1.3  jmc 				puts("into stark reality.");
    126  1.1   tv 				puts("It is day.");
    127  1.1   tv 			}
    128  1.1   tv 		} else {
    129  1.1   tv 			convert(TONIGHT);
    130  1.1   tv 			clearbit(location[POOLS].objects, BATHGOD);
    131  1.1   tv 			if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
    132  1.3  jmc 				printf("The dying sun sinks into the ocean, ");
    133  1.3  jmc 				puts("leaving a blood-stained sunset.");
    134  1.3  jmc 				printf("The sky slowly fades from orange to ");
    135  1.3  jmc 				puts("violet to black.  A few stars");
    136  1.1   tv 				puts("flicker on, and it is night.");
    137  1.3  jmc 				printf("The world seems completely different ");
    138  1.3  jmc 				puts("at night.");
    139  1.1   tv 			}
    140  1.1   tv 		}
    141  1.1   tv 		rythmn = ourtime - ourtime % CYCLE;
    142  1.1   tv 	}
    143  1.1   tv 	if (!wiz && !tempwiz)
    144  1.3  jmc 		if ((testbit(inven, TALISMAN) || testbit(wear, TALISMAN)) &&
    145  1.3  jmc 		    (testbit(inven, MEDALION) || testbit(wear, MEDALION)) &&
    146  1.3  jmc 		    (testbit(inven, AMULET) || testbit(wear, AMULET))) {
    147  1.1   tv 			tempwiz = 1;
    148  1.3  jmc 			printf("The three amulets glow and reenforce each ");
    149  1.3  jmc 			puts("other in power.\nYou are now a wizard.");
    150  1.1   tv 		}
    151  1.1   tv 	if (testbit(location[position].objects, ELF)) {
    152  1.1   tv 		printf("%s\n", objdes[ELF]);
    153  1.1   tv 		fight(ELF, rnd(30));
    154  1.1   tv 	}
    155  1.1   tv 	if (testbit(location[position].objects, DARK)) {
    156  1.1   tv 		printf("%s\n", objdes[DARK]);
    157  1.1   tv 		fight(DARK, 100);
    158  1.1   tv 	}
    159  1.1   tv 	if (testbit(location[position].objects, WOODSMAN)) {
    160  1.1   tv 		printf("%s\n", objdes[WOODSMAN]);
    161  1.1   tv 		fight(WOODSMAN, 50);
    162  1.1   tv 	}
    163  1.1   tv 	switch (position) {
    164  1.1   tv 
    165  1.1   tv 	case 267:
    166  1.1   tv 	case 257:		/* entering a cave */
    167  1.1   tv 	case 274:
    168  1.1   tv 	case 246:
    169  1.1   tv 		notes[CANTSEE] = 1;
    170  1.1   tv 		break;
    171  1.1   tv 	case 160:
    172  1.1   tv 	case 216:		/* leaving a cave */
    173  1.1   tv 	case 230:
    174  1.1   tv 	case 231:
    175  1.1   tv 	case 232:
    176  1.1   tv 		notes[CANTSEE] = 0;
    177  1.1   tv 		break;
    178  1.1   tv 	}
    179  1.1   tv 	if (testbit(location[position].objects, GIRL))
    180  1.1   tv 		meetgirl = 1;
    181  1.1   tv 	if (meetgirl && CYCLE * 1.5 - ourtime < 10) {
    182  1.1   tv 		setbit(location[GARDEN].objects, GIRLTALK);
    183  1.1   tv 		setbit(location[GARDEN].objects, LAMPON);
    184  1.1   tv 		setbit(location[GARDEN].objects, ROPE);
    185  1.1   tv 	}
    186  1.1   tv 	if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) {
    187  1.1   tv 		clearbit(location[DOCK].objects, GIRL);
    188  1.1   tv 		clearbit(location[DOCK].objects, MAN);
    189  1.1   tv 	}
    190  1.1   tv 	if (meetgirl && ourtime - CYCLE * 1.5 > 10) {
    191  1.1   tv 		clearbit(location[GARDEN].objects, GIRLTALK);
    192  1.1   tv 		clearbit(location[GARDEN].objects, LAMPON);
    193  1.1   tv 		clearbit(location[GARDEN].objects, ROPE);
    194  1.1   tv 		meetgirl = 0;
    195  1.1   tv 	}
    196  1.1   tv 	if (testbit(location[position].objects, CYLON)) {
    197  1.1   tv 		puts("Oh my God, you're being shot at by an alien spacecraft!");
    198  1.3  jmc 		printf("The targeting computer says we have %d seconds ",
    199  1.1   tv 		    ourclock);
    200  1.3  jmc 		printf("to attack!\n");
    201  1.1   tv 		fflush(stdout);
    202  1.1   tv 		sleep(1);
    203  1.1   tv 		if (!visual()) {
    204  1.1   tv 			hurt = rnd(NUMOFINJURIES);
    205  1.1   tv 			injuries[hurt] = 1;
    206  1.3  jmc 			printf("Laser blasts sear the cockpit, and the alien ");
    207  1.3  jmc 			puts("veers off in a victory roll.");
    208  1.1   tv 			puts("The viper shudders under a terrible explosion.");
    209  1.3  jmc 			printf("I'm afraid you have suffered %s.\n",
    210  1.3  jmc 			    ouch[hurt]);
    211  1.1   tv 		} else
    212  1.1   tv 			clearbit(location[position].objects, CYLON);
    213  1.1   tv 	}
    214  1.1   tv 	if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
    215  1.1   tv 		puts("I'm afraid you have suffered fatal injuries.");
    216  1.1   tv 		die();
    217  1.1   tv 	}
    218  1.1   tv 	for (n = 0; n < NUMOFINJURIES; n++)
    219  1.1   tv 		if (injuries[n] == 1) {
    220  1.1   tv 			injuries[n] = 2;
    221  1.1   tv 			if (WEIGHT > 5)
    222  1.1   tv 				WEIGHT -= 5;
    223  1.1   tv 			else
    224  1.1   tv 				WEIGHT = 0;
    225  1.1   tv 		}
    226  1.1   tv 	if (injuries[ARM] == 2) {
    227  1.1   tv 		if (CUMBER > 5)
    228  1.1   tv 			CUMBER -= 5;
    229  1.1   tv 		else
    230  1.1   tv 			CUMBER = 0;
    231  1.1   tv 		injuries[ARM]++;
    232  1.1   tv 	}
    233  1.1   tv 	if (injuries[RIBS] == 2) {
    234  1.1   tv 		if (CUMBER > 2)
    235  1.1   tv 			CUMBER -= 2;
    236  1.1   tv 		else
    237  1.1   tv 			CUMBER = 0;
    238  1.1   tv 		injuries[RIBS]++;
    239  1.1   tv 	}
    240  1.1   tv 	if (injuries[SPINE] == 2) {
    241  1.1   tv 		WEIGHT = 0;
    242  1.1   tv 		injuries[SPINE]++;
    243  1.1   tv 	}
    244  1.1   tv 	if (carrying > WEIGHT || encumber > CUMBER)
    245  1.1   tv 		notes[CANTMOVE] = 1;
    246  1.1   tv 	else
    247  1.1   tv 		notes[CANTMOVE] = 0;
    248  1.1   tv }
    249  1.1   tv 
    250  1.1   tv void
    251  1.3  jmc crash(void)
    252  1.1   tv {
    253  1.1   tv 	int     hurt1, hurt2;
    254  1.1   tv 
    255  1.1   tv 	fuel--;
    256  1.1   tv 	if (!location[position].flyhere ||
    257  1.1   tv 	    (testbit(location[position].objects, LAND) && fuel <= 0)) {
    258  1.1   tv 		if (!location[position].flyhere)
    259  1.1   tv 			puts("You're flying too low.  We're going to crash!");
    260  1.1   tv 		else {
    261  1.1   tv 			puts("You're out of fuel.  We'll have to crash land!");
    262  1.1   tv 			if (!location[position].down) {
    263  1.3  jmc 				printf("Your viper strikes the ground and ");
    264  1.3  jmc 				puts("explodes into fiery fragments.");
    265  1.3  jmc 				printf("Thick black smoke billows up from the");
    266  1.3  jmc 				puts(" wreckage.");
    267  1.1   tv 				die();
    268  1.1   tv 			}
    269  1.1   tv 			position = location[position].down;
    270  1.1   tv 		}
    271  1.1   tv 		notes[LAUNCHED] = 0;
    272  1.1   tv 		setbit(location[position].objects, CRASH);
    273  1.1   tv 		ourtime += rnd(CYCLE / 4);
    274  1.3  jmc 		printf("The viper explodes into the ground and you lose ");
    275  1.3  jmc 		puts("consciousness...");
    276  1.1   tv 		zzz();
    277  1.1   tv 		hurt1 = rnd(NUMOFINJURIES - 2) + 2;
    278  1.1   tv 		hurt2 = rnd(NUMOFINJURIES - 2) + 2;
    279  1.1   tv 		injuries[hurt1] = 1;
    280  1.1   tv 		injuries[hurt2] = 1;
    281  1.1   tv 		injuries[0] = 1;/* abrasions */
    282  1.1   tv 		injuries[1] = 1;/* lacerations */
    283  1.1   tv 		printf("I'm afraid you have suffered %s and %s.\n",
    284  1.1   tv 		    ouch[hurt1], ouch[hurt2]);
    285  1.1   tv 	}
    286  1.1   tv }
    287