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