Remove some more unused headers.
[dragonfly.git] / games / battlestar / command6.c
CommitLineData
6693db17 1/*-
984263bc
MD
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.
6693db17 13 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
1de703da
MD
28 *
29 * @(#)com6.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/battlestar/com6.c,v 1.9.2.1 2001/03/05 11:45:35 kris Exp $
5c7cac79 31 * $DragonFly: src/games/battlestar/com6.c,v 1.4 2006/08/08 16:47:20 pavalos Exp $
984263bc
MD
32 */
33
984263bc 34#include <signal.h>
6693db17 35#include <sys/time.h>
984263bc
MD
36#include "externs.h"
37#include "pathnames.h"
38
6693db17
SW
39static FILE *score_fp;
40static void post(unsigned int ch);
984263bc
MD
41
42int
5c7cac79 43launch(void)
984263bc 44{
6693db17
SW
45 if (testbit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) {
46 if (fuel > 4) {
47 clearbit(location[position].objects, VIPER);
984263bc
MD
48 position = location[position].up;
49 notes[LAUNCHED] = 1;
50 gtime++;
51 fuel -= 4;
52 puts("You climb into the viper and prepare for launch.");
53 puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
6693db17
SW
54 return (1);
55 } else
984263bc 56 puts("Not enough fuel to launch.");
6693db17 57 } else
984263bc 58 puts("Can't launch.");
6693db17 59 return (0);
984263bc
MD
60}
61
62int
5c7cac79 63land(void)
984263bc 64{
6693db17
SW
65 if (notes[LAUNCHED] && testbit(location[position].objects, LAND) &&
66 location[position].down) {
984263bc
MD
67 notes[LAUNCHED] = 0;
68 position = location[position].down;
6693db17 69 setbit(location[position].objects, VIPER);
984263bc
MD
70 fuel -= 2;
71 gtime++;
72 puts("You are down.");
6693db17
SW
73 return (1);
74 } else
984263bc 75 puts("You can't land here.");
6693db17 76 return (0);
984263bc
MD
77}
78
79void
6693db17 80die(int sig __unused) /* endgame */
984263bc 81{
984263bc
MD
82 printf("bye.\nYour rating was %s.\n", rate());
83 post(' ');
84 exit(0);
85}
86
87void
5c7cac79 88live(void)
984263bc
MD
89{
90 puts("\nYou win!");
91 post('!');
92 exit(0);
93}
94
984263bc 95void
5c7cac79 96open_score_file(void)
984263bc 97{
6693db17 98 if ((score_fp = fopen(_PATH_SCORE, "a")) == NULL)
984263bc
MD
99 perror(_PATH_SCORE);
100}
101
102static void
5c7cac79 103post(unsigned int ch)
984263bc
MD
104{
105 struct timeval tv;
106 char *date;
107 time_t tvsec;
108 int s;
109
110 if (score_fp == NULL)
111 return;
112
113 s = sigblock(sigmask(SIGINT));
114
6693db17
SW
115 gettimeofday(&tv, NULL); /* can't call time */
116 tvsec = (time_t)tv.tv_sec;
984263bc
MD
117 date = ctime(&tvsec);
118 date[24] = '\0';
119
120 fprintf(score_fp, "%s %8s %c%20s", date, uname, ch, rate());
121 if (wiz)
122 fprintf(score_fp, " wizard\n");
123 else if (tempwiz)
124 fprintf(score_fp, " WIZARD!\n");
125 else
126 fprintf(score_fp, "\n");
127
128 sigsetmask(s);
129}
130
131const char *
5c7cac79 132rate(void)
984263bc
MD
133{
134 int score;
135
6693db17
SW
136 score = max(max(pleasure, power), ego);
137 if (score == pleasure) {
984263bc 138 if (score < 5)
6693db17 139 return ("novice");
984263bc 140 else if (score < 20)
6693db17 141 return ("junior voyeur");
984263bc 142 else if (score < 35)
6693db17
SW
143 return ("Don Juan");
144 else
145 return ("Marquis De Sade");
146 } else if (score == power) {
984263bc 147 if (score < 5)
6693db17 148 return ("serf");
984263bc 149 else if (score < 8)
6693db17 150 return ("Samurai");
984263bc 151 else if (score < 13)
6693db17 152 return ("Klingon");
984263bc 153 else if (score < 22)
6693db17
SW
154 return ("Darth Vader");
155 else
156 return ("Sauron the Great");
157 } else {
984263bc 158 if (score < 5)
6693db17 159 return ("Polyanna");
984263bc 160 else if (score < 10)
6693db17 161 return ("philanthropist");
984263bc 162 else if (score < 20)
6693db17
SW
163 return ("Tattoo");
164 else
165 return ("Mr. Roarke");
984263bc
MD
166 }
167}
168
169int
5c7cac79 170drive(void)
984263bc 171{
6693db17 172 if (testbit(location[position].objects, CAR)) {
984263bc
MD
173 puts("You hop in the car and turn the key. There is a perceptible grating noise,");
174 puts("and an explosion knocks you unconscious...");
6693db17
SW
175 clearbit(location[position].objects, CAR);
176 setbit(location[position].objects, CRASH);
984263bc
MD
177 injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
178 gtime += 15;
179 zzz();
6693db17
SW
180 return (0);
181 } else
984263bc 182 puts("There is nothing to drive here.");
6693db17 183 return (-1);
984263bc
MD
184}
185
186int
5c7cac79 187ride(void)
984263bc 188{
6693db17 189 if (testbit(location[position].objects, HORSE)) {
984263bc
MD
190 puts("You climb onto the stallion and kick it in the guts. The stupid steed launches");
191 puts("forward through bush and fern. You are thrown and the horse gallups off.");
6693db17
SW
192 clearbit(location[position].objects, HORSE);
193 while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE ||
194 !beenthere[position] || location[position].flyhere)
195 ; /* nothing */
196 setbit(location[position].objects, HORSE);
984263bc
MD
197 if (location[position].north)
198 position = location[position].north;
199 else if (location[position].south)
200 position = location[position].south;
201 else if (location[position].east)
202 position = location[position].east;
203 else
204 position = location[position].west;
6693db17
SW
205 return (0);
206 } else
207 puts("There is no horse here.");
208 return (-1);
984263bc
MD
209}
210
211void
6693db17
SW
212light(void) /* synonyms = {strike, smoke} */
213{ /* for matches, cigars */
214 if (testbit(inven, MATCHES) && matchcount) {
984263bc
MD
215 puts("Your match splutters to life.");
216 gtime++;
217 matchlight = 1;
218 matchcount--;
6693db17 219 if (position == 217) {
984263bc
MD
220 puts("The whole bungalow explodes with an intense blast.");
221 die(0);
222 }
6693db17
SW
223 } else
224 puts("You're out of matches.");
984263bc 225}