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