-WARNS6 cleanup (1441 warnings)
[dragonfly.git] / games / battlestar / com6.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  * @(#)com6.c   8.1 (Berkeley) 5/31/93
34  * $FreeBSD: src/games/battlestar/com6.c,v 1.9.2.1 2001/03/05 11:45:35 kris Exp $
35  * $DragonFly: src/games/battlestar/com6.c,v 1.4 2006/08/08 16:47:20 pavalos Exp $
36  */
37
38 #include <signal.h>
39 #include "externs.h"
40 #include "pathnames.h"
41
42 static void post (unsigned int ch);
43
44 int
45 launch(void)
46 {
47         if (testbit(location[position].objects,VIPER) && !notes[CANTLAUNCH]){
48                 if (fuel > 4){
49                         clearbit(location[position].objects,VIPER);
50                         position = location[position].up;
51                         notes[LAUNCHED] = 1;
52                         gtime++;
53                         fuel -= 4;
54                         puts("You climb into the viper and prepare for launch.");
55                         puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
56                         return(1);
57                 }
58                 else
59                         puts("Not enough fuel to launch.");
60          }
61          else
62                 puts("Can't launch.");
63          return(0);
64 }
65
66 int
67 land(void)
68 {
69         if (notes[LAUNCHED] && testbit(location[position].objects,LAND) && location[position].down){
70                 notes[LAUNCHED] = 0;
71                 position = location[position].down;
72                 setbit(location[position].objects,VIPER);
73                 fuel -= 2;
74                 gtime++;
75                 puts("You are down.");
76                 return(1);
77         }
78         else
79                 puts("You can't land here.");
80         return(0);
81 }
82
83 void
84 die(int sig)    /* endgame */
85 {
86         sig = 0;
87         printf("bye.\nYour rating was %s.\n", rate());
88         post(' ');
89         exit(0);
90 }
91
92 void
93 live(void)
94 {
95         puts("\nYou win!");
96         post('!');
97         exit(0);
98 }
99
100 #include <sys/time.h>
101
102 static FILE *score_fp;
103
104 void
105 open_score_file(void)
106 {
107         if ((score_fp = fopen(_PATH_SCORE,"a")) == NULL)
108                 perror(_PATH_SCORE);
109 }
110
111 static void
112 post(unsigned int ch)
113 {
114         struct timeval tv;
115         char *date;
116         time_t tvsec;
117         int s;
118
119         if (score_fp == NULL)
120                 return;
121
122         s = sigblock(sigmask(SIGINT));
123
124         gettimeofday(&tv, (struct timezone *)0);        /* can't call time */
125         tvsec = (time_t) tv.tv_sec;
126         date = ctime(&tvsec);
127         date[24] = '\0';
128
129         fprintf(score_fp, "%s  %8s  %c%20s", date, uname, ch, rate());
130         if (wiz)
131                 fprintf(score_fp, "   wizard\n");
132         else if (tempwiz)
133                 fprintf(score_fp, "   WIZARD!\n");
134         else
135                 fprintf(score_fp, "\n");
136
137         sigsetmask(s);
138 }
139
140 const char *
141 rate(void)
142 {
143         int score;
144
145         score = max(max(pleasure,power),ego);
146         if (score == pleasure){
147                 if (score < 5)
148                         return("novice");
149                 else if (score < 20)
150                         return("junior voyeur");
151                 else if (score < 35)
152                         return("Don Juan");
153                 else return("Marquis De Sade");
154         }
155         else if (score == power){
156                 if (score < 5)
157                         return("serf");
158                 else if (score < 8)
159                         return("Samurai");
160                 else if (score < 13)
161                         return("Klingon");
162                 else if (score < 22)
163                         return("Darth Vader");
164                 else return("Sauron the Great");
165         }
166         else{
167                 if (score < 5)
168                         return("Polyanna");
169                 else if (score < 10)
170                         return("philanthropist");
171                 else if (score < 20)
172                         return("Tattoo");
173                 else return("Mr. Roarke");
174         }
175 }
176
177 int
178 drive(void)
179 {
180         if (testbit(location[position].objects,CAR)){
181                 puts("You hop in the car and turn the key.  There is a perceptible grating noise,");
182                 puts("and an explosion knocks you unconscious...");
183                 clearbit(location[position].objects,CAR);
184                 setbit(location[position].objects,CRASH);
185                 injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
186                 gtime += 15;
187                 zzz();
188                 return(0);
189         }
190         else
191                 puts("There is nothing to drive here.");
192         return(-1);
193 }
194
195 int
196 ride(void)
197 {
198         if (testbit(location[position].objects,HORSE)){
199                 puts("You climb onto the stallion and kick it in the guts.  The stupid steed launches");
200                 puts("forward through bush and fern.  You are thrown and the horse gallups off.");
201                 clearbit(location[position].objects,HORSE);
202                 while (!(position = rnd(NUMOFROOMS+1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere);
203                 setbit(location[position].objects,HORSE);
204                 if (location[position].north)
205                         position = location[position].north;
206                 else if (location[position].south)
207                         position = location[position].south;
208                 else if (location[position].east)
209                         position = location[position].east;
210                 else
211                         position = location[position].west;
212                 return(0);
213         }
214         else puts("There is no horse here.");
215         return(-1);
216 }
217
218 void
219 light(void)     /* synonyms = {strike, smoke} */
220 {               /* for matches, cigars */
221         if (testbit(inven,MATCHES) && matchcount){
222                 puts("Your match splutters to life.");
223                 gtime++;
224                 matchlight = 1;
225                 matchcount--;
226                 if (position == 217){
227                         puts("The whole bungalow explodes with an intense blast.");
228                         die(0);
229                 }
230         }
231         else puts("You're out of matches.");
232 }