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