NetBSD/games/battlestar/command1.c

287 lines
8.2 KiB
C
Raw Normal View History

2005-07-01 10:04:46 +04:00
/* $NetBSD: command1.c,v 1.3 2005/07/01 06:04:54 jmc Exp $ */
1995-03-21 18:03:38 +03:00
1993-03-21 12:45:37 +03:00
/*
1995-03-21 18:03:38 +03:00
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
1993-03-21 12:45:37 +03:00
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
1997-10-10 15:39:08 +04:00
#include <sys/cdefs.h>
1993-03-21 12:45:37 +03:00
#ifndef lint
1995-03-21 18:03:38 +03:00
#if 0
1997-01-07 14:56:32 +03:00
static char sccsid[] = "@(#)com1.c 8.2 (Berkeley) 4/28/95";
1995-03-21 18:03:38 +03:00
#else
2005-07-01 10:04:46 +04:00
__RCSID("$NetBSD: command1.c,v 1.3 2005/07/01 06:04:54 jmc Exp $");
1995-03-21 18:03:38 +03:00
#endif
1997-10-11 06:06:55 +04:00
#endif /* not lint */
1993-03-21 12:45:37 +03:00
1997-01-07 14:56:32 +03:00
#include "extern.h"
1993-03-21 12:45:37 +03:00
1997-10-10 15:39:08 +04:00
int
2005-07-01 10:04:46 +04:00
moveplayer(int thataway, int token)
1993-03-21 12:45:37 +03:00
{
wordnumber++;
1997-10-10 15:39:08 +04:00
if ((!notes[CANTMOVE] && !notes[LAUNCHED]) ||
testbit(location[position].objects, LAND) ||
(fuel > 0 && notes[LAUNCHED])) {
1993-03-21 12:45:37 +03:00
if (thataway) {
position = thataway;
newway(token);
1997-10-10 15:39:08 +04:00
ourtime++;
1997-10-11 06:06:55 +04:00
} else {
1993-03-21 12:45:37 +03:00
puts("You can't go this way.");
newway(token);
whichway(location[position]);
1997-10-11 06:06:55 +04:00
return (0);
1993-03-21 12:45:37 +03:00
}
} else {
2005-07-01 10:04:46 +04:00
if (notes[CANTMOVE] && !notes[LAUNCHED]) {
printf("You aren't able to move; you better drop ");
puts("something.");
} else {
printf("You are out of fuel; ");
puts("now you will rot in space forever!");
}
}
1997-10-11 06:06:55 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}
2005-07-01 10:04:46 +04:00
/* Converts day to night and vice versa. */
1997-10-10 15:39:08 +04:00
void
2005-07-01 10:04:46 +04:00
convert(int tothis)
{
const struct objs *p;
1999-09-18 23:38:46 +04:00
unsigned int i, j;
1993-03-21 12:45:37 +03:00
if (tothis == TONIGHT) {
for (i = 1; i <= NUMOFROOMS; i++)
for (j = 0; j < NUMOFWORDS; j++)
nightfile[i].objects[j] = dayfile[i].objects[j];
for (p = nightobjs; p->room != 0; p++)
setbit(nightfile[p->room].objects, p->obj);
location = nightfile;
} else {
for (i = 1; i <= NUMOFROOMS; i++)
for (j = 0; j < NUMOFWORDS; j++)
dayfile[i].objects[j] = nightfile[i].objects[j];
for (p = nightobjs; p->room != 0; p++)
clearbit(dayfile[p->room].objects, p->obj);
location = dayfile;
}
}
1997-10-10 15:39:08 +04:00
void
1993-03-21 12:45:37 +03:00
news()
{
1997-10-11 06:06:55 +04:00
int n;
int hurt;
1993-03-21 12:45:37 +03:00
1997-10-11 06:06:55 +04:00
if (ourtime > 30 && position < 32) {
2005-07-01 10:04:46 +04:00
printf("An explosion of shuddering magnitude splinters ");
puts("bulkheads and");
printf("ruptures the battlestar's hull. You are sucked out ");
puts("into the");
1993-03-21 12:45:37 +03:00
puts("frozen void of space and killed.");
die();
}
1997-10-10 15:39:08 +04:00
if (ourtime > 20 && position < 32)
1993-03-21 12:45:37 +03:00
puts("Explosions rock the battlestar.");
1997-10-11 06:06:55 +04:00
if (ourtime > snooze) {
1993-03-21 12:45:37 +03:00
puts("You drop from exhaustion...");
zzz();
}
1997-10-10 15:39:08 +04:00
if (ourtime > snooze - 5)
1993-03-21 12:45:37 +03:00
puts("You're getting tired.");
1997-10-10 15:39:08 +04:00
if (ourtime > (rythmn + CYCLE)) {
1993-03-21 12:45:37 +03:00
if (location == nightfile) {
convert(TODAY);
1997-10-10 15:39:08 +04:00
if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
2005-07-01 10:04:46 +04:00
printf("Dew lit sunbeams stretch out from a ");
puts("watery sunrise and herald the dawn.");
printf("You awake from a misty dream-world ");
puts("into stark reality.");
1993-03-21 12:45:37 +03:00
puts("It is day.");
}
} else {
convert(TONIGHT);
clearbit(location[POOLS].objects, BATHGOD);
1997-10-10 15:39:08 +04:00
if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
2005-07-01 10:04:46 +04:00
printf("The dying sun sinks into the ocean, ");
puts("leaving a blood-stained sunset.");
printf("The sky slowly fades from orange to ");
puts("violet to black. A few stars");
1993-03-21 12:45:37 +03:00
puts("flicker on, and it is night.");
2005-07-01 10:04:46 +04:00
printf("The world seems completely different ");
puts("at night.");
1993-03-21 12:45:37 +03:00
}
}
1997-10-10 15:39:08 +04:00
rythmn = ourtime - ourtime % CYCLE;
1993-03-21 12:45:37 +03:00
}
if (!wiz && !tempwiz)
2005-07-01 10:04:46 +04:00
if ((testbit(inven, TALISMAN) || testbit(wear, TALISMAN)) &&
(testbit(inven, MEDALION) || testbit(wear, MEDALION)) &&
(testbit(inven, AMULET) || testbit(wear, AMULET))) {
1993-03-21 12:45:37 +03:00
tempwiz = 1;
2005-07-01 10:04:46 +04:00
printf("The three amulets glow and reenforce each ");
puts("other in power.\nYou are now a wizard.");
1997-10-11 06:06:55 +04:00
}
if (testbit(location[position].objects, ELF)) {
printf("%s\n", objdes[ELF]);
fight(ELF, rnd(30));
1993-03-21 12:45:37 +03:00
}
1997-10-11 06:06:55 +04:00
if (testbit(location[position].objects, DARK)) {
printf("%s\n", objdes[DARK]);
fight(DARK, 100);
1993-03-21 12:45:37 +03:00
}
1997-10-11 06:06:55 +04:00
if (testbit(location[position].objects, WOODSMAN)) {
printf("%s\n", objdes[WOODSMAN]);
fight(WOODSMAN, 50);
1993-03-21 12:45:37 +03:00
}
1997-10-11 06:06:55 +04:00
switch (position) {
case 267:
case 257: /* entering a cave */
case 274:
case 246:
notes[CANTSEE] = 1;
break;
case 160:
case 216: /* leaving a cave */
case 230:
case 231:
case 232:
notes[CANTSEE] = 0;
break;
1993-03-21 12:45:37 +03:00
}
if (testbit(location[position].objects, GIRL))
meetgirl = 1;
1997-10-11 06:06:55 +04:00
if (meetgirl && CYCLE * 1.5 - ourtime < 10) {
setbit(location[GARDEN].objects, GIRLTALK);
setbit(location[GARDEN].objects, LAMPON);
setbit(location[GARDEN].objects, ROPE);
1993-03-21 12:45:37 +03:00
}
1997-10-11 06:06:55 +04:00
if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) {
1993-03-21 12:45:37 +03:00
clearbit(location[DOCK].objects, GIRL);
1997-10-11 06:06:55 +04:00
clearbit(location[DOCK].objects, MAN);
1993-03-21 12:45:37 +03:00
}
1997-10-11 06:06:55 +04:00
if (meetgirl && ourtime - CYCLE * 1.5 > 10) {
clearbit(location[GARDEN].objects, GIRLTALK);
clearbit(location[GARDEN].objects, LAMPON);
clearbit(location[GARDEN].objects, ROPE);
1993-03-21 12:45:37 +03:00
meetgirl = 0;
}
1997-10-11 06:06:55 +04:00
if (testbit(location[position].objects, CYLON)) {
1993-03-21 12:45:37 +03:00
puts("Oh my God, you're being shot at by an alien spacecraft!");
2005-07-01 10:04:46 +04:00
printf("The targeting computer says we have %d seconds ",
1997-10-10 15:39:08 +04:00
ourclock);
2005-07-01 10:04:46 +04:00
printf("to attack!\n");
1993-03-21 12:45:37 +03:00
fflush(stdout);
sleep(1);
1997-10-11 06:06:55 +04:00
if (!visual()) {
1993-03-21 12:45:37 +03:00
hurt = rnd(NUMOFINJURIES);
injuries[hurt] = 1;
2005-07-01 10:04:46 +04:00
printf("Laser blasts sear the cockpit, and the alien ");
puts("veers off in a victory roll.");
1993-03-21 12:45:37 +03:00
puts("The viper shudders under a terrible explosion.");
2005-07-01 10:04:46 +04:00
printf("I'm afraid you have suffered %s.\n",
ouch[hurt]);
1997-10-11 06:06:55 +04:00
} else
clearbit(location[position].objects, CYLON);
1993-03-21 12:45:37 +03:00
}
1997-10-11 06:06:55 +04:00
if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
1993-03-21 12:45:37 +03:00
puts("I'm afraid you have suffered fatal injuries.");
die();
}
1997-10-11 06:06:55 +04:00
for (n = 0; n < NUMOFINJURIES; n++)
if (injuries[n] == 1) {
1993-03-21 12:45:37 +03:00
injuries[n] = 2;
if (WEIGHT > 5)
WEIGHT -= 5;
else
WEIGHT = 0;
}
1997-10-11 06:06:55 +04:00
if (injuries[ARM] == 2) {
if (CUMBER > 5)
CUMBER -= 5;
else
CUMBER = 0;
1993-03-21 12:45:37 +03:00
injuries[ARM]++;
}
1997-10-11 06:06:55 +04:00
if (injuries[RIBS] == 2) {
if (CUMBER > 2)
CUMBER -= 2;
else
CUMBER = 0;
1993-03-21 12:45:37 +03:00
injuries[RIBS]++;
}
1997-10-11 06:06:55 +04:00
if (injuries[SPINE] == 2) {
1993-03-21 12:45:37 +03:00
WEIGHT = 0;
injuries[SPINE]++;
}
if (carrying > WEIGHT || encumber > CUMBER)
notes[CANTMOVE] = 1;
else
notes[CANTMOVE] = 0;
}
1997-10-10 15:39:08 +04:00
void
2005-07-01 10:04:46 +04:00
crash(void)
1993-03-21 12:45:37 +03:00
{
1997-10-11 06:06:55 +04:00
int hurt1, hurt2;
1993-03-21 12:45:37 +03:00
fuel--;
1997-10-10 15:39:08 +04:00
if (!location[position].flyhere ||
1997-10-11 06:06:55 +04:00
(testbit(location[position].objects, LAND) && fuel <= 0)) {
1993-03-21 12:45:37 +03:00
if (!location[position].flyhere)
puts("You're flying too low. We're going to crash!");
1997-10-11 06:06:55 +04:00
else {
1993-03-21 12:45:37 +03:00
puts("You're out of fuel. We'll have to crash land!");
1997-10-11 06:06:55 +04:00
if (!location[position].down) {
2005-07-01 10:04:46 +04:00
printf("Your viper strikes the ground and ");
puts("explodes into fiery fragments.");
printf("Thick black smoke billows up from the");
puts(" wreckage.");
1993-03-21 12:45:37 +03:00
die();
}
position = location[position].down;
}
notes[LAUNCHED] = 0;
1997-10-11 06:06:55 +04:00
setbit(location[position].objects, CRASH);
ourtime += rnd(CYCLE / 4);
2005-07-01 10:04:46 +04:00
printf("The viper explodes into the ground and you lose ");
puts("consciousness...");
1993-03-21 12:45:37 +03:00
zzz();
hurt1 = rnd(NUMOFINJURIES - 2) + 2;
hurt2 = rnd(NUMOFINJURIES - 2) + 2;
injuries[hurt1] = 1;
injuries[hurt2] = 1;
1997-10-11 06:06:55 +04:00
injuries[0] = 1;/* abrasions */
injuries[1] = 1;/* lacerations */
1997-10-10 15:39:08 +04:00
printf("I'm afraid you have suffered %s and %s.\n",
ouch[hurt1], ouch[hurt2]);
1993-03-21 12:45:37 +03:00
}
}