]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/com6.c
A couple more checks for file descriptor < 3 missed earlier.
[bsdgames-darwin.git] / battlestar / com6.c
1 /* $NetBSD: com6.c,v 1.13 1999/09/13 17:15:42 jsm Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)com6.c 8.2 (Berkeley) 4/28/95";
40 #else
41 __RCSID("$NetBSD: com6.c,v 1.13 1999/09/13 17:15:42 jsm Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include "extern.h"
46 #include "pathnames.h"
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 ourtime++;
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 } else
62 puts("Not enough fuel to launch.");
63 } else
64 puts("Can't launch.");
65 return (0);
66 }
67
68 int
69 land()
70 {
71 if (notes[LAUNCHED] && testbit(location[position].objects, LAND) &&
72 location[position].down) {
73 notes[LAUNCHED] = 0;
74 position = location[position].down;
75 setbit(location[position].objects, VIPER);
76 fuel -= 2;
77 ourtime++;
78 puts("You are down.");
79 return (1);
80 } else
81 puts("You can't land here.");
82 return (0);
83 }
84
85 void
86 die()
87 { /* endgame */
88 printf("bye.\nYour rating was %s.\n", rate());
89 post(' ');
90 exit(0);
91 }
92
93 void
94 diesig(dummy)
95 int dummy __attribute__((__unused__));
96 {
97 die();
98 }
99
100 void
101 live()
102 {
103 puts("\nYou win!");
104 post('!');
105 exit(0);
106 }
107
108 static FILE *score_fp;
109
110 void
111 open_score_file()
112 {
113 score_fp = fopen(_PATH_SCORE, "a");
114 if (score_fp == NULL)
115 warn("open %s for append", _PATH_SCORE);
116 if (score_fp != NULL && fileno(score_fp) < 3)
117 exit(1);
118 }
119
120 void
121 post(ch)
122 char ch;
123 {
124 struct timeval tv;
125 time_t tvsec;
126 char *date;
127 sigset_t sigset, osigset;
128
129 sigemptyset(&sigset);
130 sigaddset(&sigset, SIGINT);
131 sigprocmask(SIG_BLOCK, &sigset, &osigset);
132 gettimeofday(&tv, (struct timezone *) 0); /* can't call time */
133 tvsec = (time_t) tv.tv_sec;
134 date = ctime(&tvsec);
135 date[24] = '\0';
136 if (score_fp != NULL) {
137 fprintf(score_fp, "%s %8s %c%20s", date, uname, ch, rate());
138 if (wiz)
139 fprintf(score_fp, " wizard\n");
140 else
141 if (tempwiz)
142 fprintf(score_fp, " WIZARD!\n");
143 else
144 fprintf(score_fp, "\n");
145 }
146 sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
147 }
148
149 const char *
150 rate()
151 {
152 int score;
153
154 score = max(max(pleasure, power), ego);
155 if (score == pleasure) {
156 if (score < 5)
157 return ("novice");
158 else
159 if (score < 20)
160 return ("junior voyeur");
161 else
162 if (score < 35)
163 return ("Don Juan");
164 else
165 return ("Marquis De Sade");
166 } else
167 if (score == power) {
168 if (score < 5)
169 return ("serf");
170 else
171 if (score < 8)
172 return ("Samurai");
173 else
174 if (score < 13)
175 return ("Klingon");
176 else
177 if (score < 22)
178 return ("Darth Vader");
179 else
180 return ("Sauron the Great");
181 } else {
182 if (score < 5)
183 return ("Polyanna");
184 else
185 if (score < 10)
186 return ("philanthropist");
187 else
188 if (score < 20)
189 return ("Tattoo");
190 else
191 return ("Mr. Roarke");
192 }
193 }
194
195 int
196 drive()
197 {
198 if (testbit(location[position].objects, CAR)) {
199 puts("You hop in the car and turn the key. There is a perceptible grating noise,");
200 puts("and an explosion knocks you unconscious...");
201 clearbit(location[position].objects, CAR);
202 setbit(location[position].objects, CRASH);
203 injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
204 ourtime += 15;
205 zzz();
206 return (0);
207 } else
208 puts("There is nothing to drive here.");
209 return (-1);
210 }
211
212 int
213 ride()
214 {
215 if (testbit(location[position].objects, HORSE)) {
216 puts("You climb onto the stallion and kick it in the guts. The stupid steed launches");
217 puts("forward through bush and fern. You are thrown and the horse gallups off.");
218 clearbit(location[position].objects, HORSE);
219 while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere);
220 setbit(location[position].objects, HORSE);
221 if (location[position].north)
222 position = location[position].north;
223 else
224 if (location[position].south)
225 position = location[position].south;
226 else
227 if (location[position].east)
228 position = location[position].east;
229 else
230 position = location[position].west;
231 return (0);
232 } else
233 puts("There is no horse here.");
234 return (-1);
235 }
236
237 void
238 light()
239 { /* synonyms = {strike, smoke} *//* for
240 * matches, cigars */
241 if (testbit(inven, MATCHES) && matchcount) {
242 puts("Your match splutters to life.");
243 ourtime++;
244 matchlight = 1;
245 matchcount--;
246 if (position == 217) {
247 puts("The whole bungalow explodes with an intense blast.");
248 die();
249 }
250 } else
251 puts("You're out of matches.");
252 }