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