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