]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/com6.c
Wording, punctuation and line length improvements. Also adjust test
[bsdgames-darwin.git] / battlestar / com6.c
1 /* $NetBSD: com6.c,v 1.16 2000/09/10 10:51:17 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.16 2000/09/10 10:51:17 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 time_t tv;
125 char *date;
126 sigset_t sigset, osigset;
127
128 sigemptyset(&sigset);
129 sigaddset(&sigset, SIGINT);
130 sigprocmask(SIG_BLOCK, &sigset, &osigset);
131 tv = time(NULL);
132 date = ctime(&tv);
133 date[24] = '\0';
134 if (score_fp != NULL) {
135 fprintf(score_fp, "%s %8s %c%20s", date, username, ch, rate());
136 if (wiz)
137 fprintf(score_fp, " wizard\n");
138 else
139 if (tempwiz)
140 fprintf(score_fp, " WIZARD!\n");
141 else
142 fprintf(score_fp, "\n");
143 }
144 sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
145 }
146
147 const char *
148 rate()
149 {
150 int score;
151
152 score = max(max(pleasure, power), ego);
153 if (score == pleasure) {
154 if (score < 5)
155 return ("novice");
156 else
157 if (score < 20)
158 return ("junior voyeur");
159 else
160 if (score < 35)
161 return ("Don Juan");
162 else
163 return ("Marquis De Sade");
164 } else
165 if (score == power) {
166 if (score < 5)
167 return ("serf");
168 else
169 if (score < 8)
170 return ("Samurai");
171 else
172 if (score < 13)
173 return ("Klingon");
174 else
175 if (score < 22)
176 return ("Darth Vader");
177 else
178 return ("Sauron the Great");
179 } else {
180 if (score < 5)
181 return ("Polyanna");
182 else
183 if (score < 10)
184 return ("philanthropist");
185 else
186 if (score < 20)
187 return ("Tattoo");
188 else
189 return ("Mr. Roarke");
190 }
191 }
192
193 int
194 drive()
195 {
196 if (testbit(location[position].objects, CAR)) {
197 puts("You hop in the car and turn the key. There is a perceptible grating noise,");
198 puts("and an explosion knocks you unconscious...");
199 clearbit(location[position].objects, CAR);
200 setbit(location[position].objects, CRASH);
201 injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
202 ourtime += 15;
203 zzz();
204 return (0);
205 } else
206 puts("There is nothing to drive here.");
207 return (-1);
208 }
209
210 int
211 ride()
212 {
213 if (testbit(location[position].objects, HORSE)) {
214 puts("You climb onto the stallion and kick it in the guts. The stupid steed launches");
215 puts("forward through bush and fern. You are thrown and the horse gallops off.");
216 clearbit(location[position].objects, HORSE);
217 while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere);
218 setbit(location[position].objects, HORSE);
219 if (location[position].north)
220 position = location[position].north;
221 else
222 if (location[position].south)
223 position = location[position].south;
224 else
225 if (location[position].east)
226 position = location[position].east;
227 else
228 position = location[position].west;
229 return (0);
230 } else
231 puts("There is no horse here.");
232 return (-1);
233 }
234
235 void
236 light()
237 { /* synonyms = {strike, smoke} *//* for
238 * matches, cigars */
239 if (testbit(inven, MATCHES) && matchcount) {
240 puts("Your match splutters to life.");
241 ourtime++;
242 matchlight = 1;
243 matchcount--;
244 if (position == 217) {
245 puts("The whole bungalow explodes with an intense blast.");
246 die();
247 }
248 } else
249 puts("You're out of matches.");
250 }