Home | History | Annotate | Line # | Download | only in battlestar
command1.c revision 1.1
      1  1.1  tv /*	$NetBSD: command1.c,v 1.1 2001/10/19 03:06:11 tv 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.1  tv  * 3. All advertising materials mentioning features or use of this software
     16  1.1  tv  *    must display the following acknowledgement:
     17  1.1  tv  *	This product includes software developed by the University of
     18  1.1  tv  *	California, Berkeley and its contributors.
     19  1.1  tv  * 4. Neither the name of the University nor the names of its contributors
     20  1.1  tv  *    may be used to endorse or promote products derived from this software
     21  1.1  tv  *    without specific prior written permission.
     22  1.1  tv  *
     23  1.1  tv  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  tv  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  tv  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  tv  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  tv  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  tv  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  tv  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  tv  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  tv  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  tv  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  tv  * SUCH DAMAGE.
     34  1.1  tv  */
     35  1.1  tv 
     36  1.1  tv #include <sys/cdefs.h>
     37  1.1  tv #ifndef lint
     38  1.1  tv #if 0
     39  1.1  tv static char sccsid[] = "@(#)com1.c	8.2 (Berkeley) 4/28/95";
     40  1.1  tv #else
     41  1.1  tv __RCSID("$NetBSD: command1.c,v 1.1 2001/10/19 03:06:11 tv Exp $");
     42  1.1  tv #endif
     43  1.1  tv #endif				/* not lint */
     44  1.1  tv 
     45  1.1  tv #include "extern.h"
     46  1.1  tv 
     47  1.1  tv int
     48  1.1  tv moveplayer(thataway, token)
     49  1.1  tv 	int     thataway, token;
     50  1.1  tv {
     51  1.1  tv 	wordnumber++;
     52  1.1  tv 	if ((!notes[CANTMOVE] && !notes[LAUNCHED]) ||
     53  1.1  tv 	    testbit(location[position].objects, LAND) ||
     54  1.1  tv 	    (fuel > 0 && notes[LAUNCHED])) {
     55  1.1  tv 		if (thataway) {
     56  1.1  tv 			position = thataway;
     57  1.1  tv 			newway(token);
     58  1.1  tv 			ourtime++;
     59  1.1  tv 		} else {
     60  1.1  tv 			puts("You can't go this way.");
     61  1.1  tv 			newway(token);
     62  1.1  tv 			whichway(location[position]);
     63  1.1  tv 			return (0);
     64  1.1  tv 		}
     65  1.1  tv 	} else {
     66  1.1  tv 		if (notes[CANTMOVE] && !notes[LAUNCHED])
     67  1.1  tv 			puts("You aren't able to move; you better drop something.");
     68  1.1  tv 		else
     69  1.1  tv 			puts("You are out of fuel; now you will rot in space forever!");
     70  1.1  tv 	}
     71  1.1  tv 	return (1);
     72  1.1  tv }
     73  1.1  tv 
     74  1.1  tv void
     75  1.1  tv convert(tothis)			/* Converts day to night and vice versa. 	    */
     76  1.1  tv 	int     tothis;		/* Day objects are permanent.  Night objects
     77  1.1  tv 				 * are added */
     78  1.1  tv {				/* at dusk, and subtracted at dawn.		 */
     79  1.1  tv 	const struct objs *p;
     80  1.1  tv 	unsigned int     i, j;
     81  1.1  tv 
     82  1.1  tv 	if (tothis == TONIGHT) {
     83  1.1  tv 		for (i = 1; i <= NUMOFROOMS; i++)
     84  1.1  tv 			for (j = 0; j < NUMOFWORDS; j++)
     85  1.1  tv 				nightfile[i].objects[j] = dayfile[i].objects[j];
     86  1.1  tv 		for (p = nightobjs; p->room != 0; p++)
     87  1.1  tv 			setbit(nightfile[p->room].objects, p->obj);
     88  1.1  tv 		location = nightfile;
     89  1.1  tv 	} else {
     90  1.1  tv 		for (i = 1; i <= NUMOFROOMS; i++)
     91  1.1  tv 			for (j = 0; j < NUMOFWORDS; j++)
     92  1.1  tv 				dayfile[i].objects[j] = nightfile[i].objects[j];
     93  1.1  tv 		for (p = nightobjs; p->room != 0; p++)
     94  1.1  tv 			clearbit(dayfile[p->room].objects, p->obj);
     95  1.1  tv 		location = dayfile;
     96  1.1  tv 	}
     97  1.1  tv }
     98  1.1  tv 
     99  1.1  tv void
    100  1.1  tv news()
    101  1.1  tv {
    102  1.1  tv 	int     n;
    103  1.1  tv 	int     hurt;
    104  1.1  tv 
    105  1.1  tv 	if (ourtime > 30 && position < 32) {
    106  1.1  tv 		puts("An explosion of shuddering magnitude splinters bulkheads and");
    107  1.1  tv 		puts("ruptures the battlestar's hull.  You are sucked out into the");
    108  1.1  tv 		puts("frozen void of space and killed.");
    109  1.1  tv 		die();
    110  1.1  tv 	}
    111  1.1  tv 	if (ourtime > 20 && position < 32)
    112  1.1  tv 		puts("Explosions rock the battlestar.");
    113  1.1  tv 	if (ourtime > snooze) {
    114  1.1  tv 		puts("You drop from exhaustion...");
    115  1.1  tv 		zzz();
    116  1.1  tv 	}
    117  1.1  tv 	if (ourtime > snooze - 5)
    118  1.1  tv 		puts("You're getting tired.");
    119  1.1  tv 	if (ourtime > (rythmn + CYCLE)) {
    120  1.1  tv 		if (location == nightfile) {
    121  1.1  tv 			convert(TODAY);
    122  1.1  tv 			if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
    123  1.1  tv 				puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn.");
    124  1.1  tv 				puts("You awake from a misty dream-world into stark reality.");
    125  1.1  tv 				puts("It is day.");
    126  1.1  tv 			}
    127  1.1  tv 		} else {
    128  1.1  tv 			convert(TONIGHT);
    129  1.1  tv 			clearbit(location[POOLS].objects, BATHGOD);
    130  1.1  tv 			if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
    131  1.1  tv 				puts("The dying sun sinks into the ocean, leaving a blood-stained sunset.");
    132  1.1  tv 				puts("The sky slowly fades from orange to violet to black.  A few stars");
    133  1.1  tv 				puts("flicker on, and it is night.");
    134  1.1  tv 				puts("The world seems completely different at night.");
    135  1.1  tv 			}
    136  1.1  tv 		}
    137  1.1  tv 		rythmn = ourtime - ourtime % CYCLE;
    138  1.1  tv 	}
    139  1.1  tv 	if (!wiz && !tempwiz)
    140  1.1  tv 		if ((testbit(inven, TALISMAN) || testbit(wear, TALISMAN)) && (testbit(inven, MEDALION) || testbit(wear, MEDALION)) && (testbit(inven, AMULET) || testbit(wear, AMULET))) {
    141  1.1  tv 			tempwiz = 1;
    142  1.1  tv 			puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard.");
    143  1.1  tv 		}
    144  1.1  tv 	if (testbit(location[position].objects, ELF)) {
    145  1.1  tv 		printf("%s\n", objdes[ELF]);
    146  1.1  tv 		fight(ELF, rnd(30));
    147  1.1  tv 	}
    148  1.1  tv 	if (testbit(location[position].objects, DARK)) {
    149  1.1  tv 		printf("%s\n", objdes[DARK]);
    150  1.1  tv 		fight(DARK, 100);
    151  1.1  tv 	}
    152  1.1  tv 	if (testbit(location[position].objects, WOODSMAN)) {
    153  1.1  tv 		printf("%s\n", objdes[WOODSMAN]);
    154  1.1  tv 		fight(WOODSMAN, 50);
    155  1.1  tv 	}
    156  1.1  tv 	switch (position) {
    157  1.1  tv 
    158  1.1  tv 	case 267:
    159  1.1  tv 	case 257:		/* entering a cave */
    160  1.1  tv 	case 274:
    161  1.1  tv 	case 246:
    162  1.1  tv 		notes[CANTSEE] = 1;
    163  1.1  tv 		break;
    164  1.1  tv 	case 160:
    165  1.1  tv 	case 216:		/* leaving a cave */
    166  1.1  tv 	case 230:
    167  1.1  tv 	case 231:
    168  1.1  tv 	case 232:
    169  1.1  tv 		notes[CANTSEE] = 0;
    170  1.1  tv 		break;
    171  1.1  tv 	}
    172  1.1  tv 	if (testbit(location[position].objects, GIRL))
    173  1.1  tv 		meetgirl = 1;
    174  1.1  tv 	if (meetgirl && CYCLE * 1.5 - ourtime < 10) {
    175  1.1  tv 		setbit(location[GARDEN].objects, GIRLTALK);
    176  1.1  tv 		setbit(location[GARDEN].objects, LAMPON);
    177  1.1  tv 		setbit(location[GARDEN].objects, ROPE);
    178  1.1  tv 	}
    179  1.1  tv 	if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) {
    180  1.1  tv 		clearbit(location[DOCK].objects, GIRL);
    181  1.1  tv 		clearbit(location[DOCK].objects, MAN);
    182  1.1  tv 	}
    183  1.1  tv 	if (meetgirl && ourtime - CYCLE * 1.5 > 10) {
    184  1.1  tv 		clearbit(location[GARDEN].objects, GIRLTALK);
    185  1.1  tv 		clearbit(location[GARDEN].objects, LAMPON);
    186  1.1  tv 		clearbit(location[GARDEN].objects, ROPE);
    187  1.1  tv 		meetgirl = 0;
    188  1.1  tv 	}
    189  1.1  tv 	if (testbit(location[position].objects, CYLON)) {
    190  1.1  tv 		puts("Oh my God, you're being shot at by an alien spacecraft!");
    191  1.1  tv 		printf("The targeting computer says we have %d seconds to attack!\n",
    192  1.1  tv 		    ourclock);
    193  1.1  tv 		fflush(stdout);
    194  1.1  tv 		sleep(1);
    195  1.1  tv 		if (!visual()) {
    196  1.1  tv 			hurt = rnd(NUMOFINJURIES);
    197  1.1  tv 			injuries[hurt] = 1;
    198  1.1  tv 			puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll.");
    199  1.1  tv 			puts("The viper shudders under a terrible explosion.");
    200  1.1  tv 			printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
    201  1.1  tv 		} else
    202  1.1  tv 			clearbit(location[position].objects, CYLON);
    203  1.1  tv 	}
    204  1.1  tv 	if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
    205  1.1  tv 		puts("I'm afraid you have suffered fatal injuries.");
    206  1.1  tv 		die();
    207  1.1  tv 	}
    208  1.1  tv 	for (n = 0; n < NUMOFINJURIES; n++)
    209  1.1  tv 		if (injuries[n] == 1) {
    210  1.1  tv 			injuries[n] = 2;
    211  1.1  tv 			if (WEIGHT > 5)
    212  1.1  tv 				WEIGHT -= 5;
    213  1.1  tv 			else
    214  1.1  tv 				WEIGHT = 0;
    215  1.1  tv 		}
    216  1.1  tv 	if (injuries[ARM] == 2) {
    217  1.1  tv 		if (CUMBER > 5)
    218  1.1  tv 			CUMBER -= 5;
    219  1.1  tv 		else
    220  1.1  tv 			CUMBER = 0;
    221  1.1  tv 		injuries[ARM]++;
    222  1.1  tv 	}
    223  1.1  tv 	if (injuries[RIBS] == 2) {
    224  1.1  tv 		if (CUMBER > 2)
    225  1.1  tv 			CUMBER -= 2;
    226  1.1  tv 		else
    227  1.1  tv 			CUMBER = 0;
    228  1.1  tv 		injuries[RIBS]++;
    229  1.1  tv 	}
    230  1.1  tv 	if (injuries[SPINE] == 2) {
    231  1.1  tv 		WEIGHT = 0;
    232  1.1  tv 		injuries[SPINE]++;
    233  1.1  tv 	}
    234  1.1  tv 	if (carrying > WEIGHT || encumber > CUMBER)
    235  1.1  tv 		notes[CANTMOVE] = 1;
    236  1.1  tv 	else
    237  1.1  tv 		notes[CANTMOVE] = 0;
    238  1.1  tv }
    239  1.1  tv 
    240  1.1  tv void
    241  1.1  tv crash()
    242  1.1  tv {
    243  1.1  tv 	int     hurt1, hurt2;
    244  1.1  tv 
    245  1.1  tv 	fuel--;
    246  1.1  tv 	if (!location[position].flyhere ||
    247  1.1  tv 	    (testbit(location[position].objects, LAND) && fuel <= 0)) {
    248  1.1  tv 		if (!location[position].flyhere)
    249  1.1  tv 			puts("You're flying too low.  We're going to crash!");
    250  1.1  tv 		else {
    251  1.1  tv 			puts("You're out of fuel.  We'll have to crash land!");
    252  1.1  tv 			if (!location[position].down) {
    253  1.1  tv 				puts("Your viper strikes the ground and explodes into fiery fragments.");
    254  1.1  tv 				puts("Thick black smoke billows up from the wreckage.");
    255  1.1  tv 				die();
    256  1.1  tv 			}
    257  1.1  tv 			position = location[position].down;
    258  1.1  tv 		}
    259  1.1  tv 		notes[LAUNCHED] = 0;
    260  1.1  tv 		setbit(location[position].objects, CRASH);
    261  1.1  tv 		ourtime += rnd(CYCLE / 4);
    262  1.1  tv 		puts("The viper explodes into the ground and you lose consciousness...");
    263  1.1  tv 		zzz();
    264  1.1  tv 		hurt1 = rnd(NUMOFINJURIES - 2) + 2;
    265  1.1  tv 		hurt2 = rnd(NUMOFINJURIES - 2) + 2;
    266  1.1  tv 		injuries[hurt1] = 1;
    267  1.1  tv 		injuries[hurt2] = 1;
    268  1.1  tv 		injuries[0] = 1;/* abrasions */
    269  1.1  tv 		injuries[1] = 1;/* lacerations */
    270  1.1  tv 		printf("I'm afraid you have suffered %s and %s.\n",
    271  1.1  tv 		    ouch[hurt1], ouch[hurt2]);
    272  1.1  tv 	}
    273  1.1  tv }
    274