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