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