* __P removal from games/
[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  * @(#)com1.c   8.1 (Berkeley) 5/31/93
34  * $FreeBSD: src/games/battlestar/com1.c,v 1.7.2.1 2001/03/05 11:45:35 kris Exp $
35  * $DragonFly: src/games/battlestar/com1.c,v 1.3 2003/11/12 14:53:52 eirikn Exp $
36  */
37
38 #include "externs.h"
39
40 void     convert (int);
41
42 int
43 battlestar_move(thataway, token)
44 int thataway, token;
45 {
46         wordnumber++;
47         if ((!notes[CANTMOVE] && !notes[LAUNCHED]) ||
48             ((testbit(location[position].objects, LAND) || fuel > 0) &&
49             notes[LAUNCHED]))
50                 if (thataway) {
51                         position = thataway;
52                         newway(token);
53                         gtime++;
54                 }
55                 else {
56                         puts("You can't go this way.");
57                         newway(token);
58                         whichway(location[position]);
59                         return(0);
60                 }
61         else if (notes[CANTMOVE] && !notes[LAUNCHED])
62                 puts("You aren't able to move; you better drop something.");
63         else
64                 puts("You are out of fuel; now you will rot in space forever!");
65         return(1);
66 }
67
68 void
69 convert(tothis)         /* Converts day to night and vice versa.            */
70 int tothis;             /* Day objects are permanent.  Night objects are added*/
71 {                       /* at dusk, and subtracted at dawn.             */
72         const struct objs *p;
73         int i, j;
74
75         if (tothis == TONIGHT) {
76                 for (i = 1; i <= NUMOFROOMS; i++)
77                         for (j = 0; j < NUMOFWORDS; j++)
78                                 nightfile[i].objects[j] = dayfile[i].objects[j];
79                 for (p = nightobjs; p->room != 0; p++)
80                         setbit(nightfile[p->room].objects, p->obj);
81                 location = nightfile;
82         } else {
83                 for (i = 1; i <= NUMOFROOMS; i++)
84                         for (j = 0; j < NUMOFWORDS; j++)
85                                 dayfile[i].objects[j] = nightfile[i].objects[j];
86                 for (p = nightobjs; p->room != 0; p++)
87                         clearbit(dayfile[p->room].objects, p->obj);
88                 location = dayfile;
89         }
90 }
91
92 void
93 news()
94 {
95         int n;
96         int hurt;
97
98         if (gtime > 30 && position < 32){
99                 puts("An explosion of shuddering magnitude splinters bulkheads and");
100                 puts("ruptures the battlestar's hull.  You are sucked out into the");
101                 puts("frozen void of space and killed.");
102                 die(0);
103         }
104         if (gtime > 20 && position < 32)
105                 puts("Explosions rock the battlestar.");
106         if (gtime > snooze){
107                 puts("You drop from exhaustion...");
108                 zzz();
109         }
110         if (gtime > snooze - 5)
111                 puts("You're getting tired.");
112         if (gtime > (rythmn + CYCLE)) {
113                 if (location == nightfile) {
114                         convert(TODAY);
115                         if (OUTSIDE && gtime - rythmn - CYCLE < 10) {
116                                 puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn.");
117                                 puts("You awake from a misty dream-world into stark reality.");
118                                 puts("It is day.");
119                         }
120                 } else {
121                         convert(TONIGHT);
122                         clearbit(location[POOLS].objects, BATHGOD);
123                         if (OUTSIDE && gtime - rythmn - CYCLE < 10) {
124                                 puts("The dying sun sinks into the ocean, leaving a blood stained sunset.");
125                                 puts("The sky slowly fades from orange to violet to black.  A few stars");
126                                 puts("flicker on, and it is night.");
127                                 puts("The world seems completly different at night.");
128                         }
129                 }
130                 rythmn = gtime - gtime % CYCLE;
131         }
132         if (!wiz && !tempwiz)
133                 if ((testbit(inven,TALISMAN) || testbit(wear,TALISMAN)) && (testbit(inven,MEDALION) || testbit(wear,MEDALION)) && (testbit(inven,AMULET) || testbit(wear,AMULET))){
134                         tempwiz = 1;
135                         puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard.");
136         }
137         if (testbit(location[position].objects,ELF)){
138                 printf("%s\n",objdes[ELF]);
139                 fight(ELF,rnd(30));
140         }
141         if (testbit(location[position].objects,DARK)){
142                 printf("%s\n",objdes[DARK]);
143                 fight(DARK,100);
144         }
145         if (testbit(location[position].objects,WOODSMAN)){
146                 printf("%s\n",objdes[WOODSMAN]);
147                 fight(WOODSMAN,50);
148         }
149         switch(position){
150
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",gclock);
185                 fflush(stdout);
186                 sleep(1);
187                 if (!visual()){
188                         hurt = rnd(NUMOFINJURIES);
189                         injuries[hurt] = 1;
190                         puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll.");
191                         puts("The viper shudders under a terrible explosion.");
192                         printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
193                 }
194                 else
195                         clearbit(location[position].objects,CYLON);
196         }
197         if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){
198                 puts("I'm afraid you have suffered fatal injuries.");
199                 die(0);
200         }
201         for (n=0; n < NUMOFINJURIES; n++)
202                 if (injuries[n] == 1){
203                         injuries[n] = 2;
204                         if (WEIGHT > 5)
205                                 WEIGHT -= 5;
206                         else
207                                 WEIGHT = 0;
208                 }
209         if (injuries[ARM] == 2){
210                 CUMBER -= 5;
211                 injuries[ARM]++;
212         }
213         if (injuries[RIBS] == 2){
214                 CUMBER -= 2;
215                 injuries[RIBS]++;
216         }
217         if (injuries[SPINE] == 2){
218                 WEIGHT = 0;
219                 injuries[SPINE]++;
220         }
221         if (carrying > WEIGHT || encumber > CUMBER)
222                 notes[CANTMOVE] = 1;
223         else
224                 notes[CANTMOVE] = 0;
225 }
226
227 void
228 crash()
229 {
230         int hurt1,hurt2;
231
232         fuel--;
233         if (!location[position].flyhere || (testbit(location[position].objects,LAND) && fuel <= 0)){
234                 if (!location[position].flyhere)
235                         puts("You're flying too low.  We're going to crash!");
236                 else{
237                         puts("You're out of fuel.  We'll have to crash land!");
238                         if (!location[position].down){
239                                 puts("Your viper strikes the ground and explodes into firey fragments.");
240                                 puts("Thick black smoke billows up from the wreckage.");
241                                 die(0);
242                         }
243                         position = location[position].down;
244                 }
245                 notes[LAUNCHED] = 0;
246                 setbit(location[position].objects,CRASH);
247                 gtime += rnd(CYCLE/4);
248                 puts("The viper explodes into the ground and you lose consciousness...");
249                 zzz();
250                 hurt1 = rnd(NUMOFINJURIES - 2) + 2;
251                 hurt2 = rnd(NUMOFINJURIES - 2) + 2;
252                 injuries[hurt1] = 1;
253                 injuries[hurt2] = 1;
254                 injuries[0] = 1;        /* abrasions */
255                 injuries[1] = 1;        /* lacerations */
256                 printf("I'm afraid you have suffered %s and %s.\n",ouch[hurt1],ouch[hurt2]);
257         }
258 }