]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/command6.c
fix typo.
[bsdgames-darwin.git] / battlestar / command6.c
1 /* $NetBSD: command6.c,v 1.7 2010/04/02 19:34:44 christos 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)com6.c 8.2 (Berkeley) 4/28/95";
36 #else
37 __RCSID("$NetBSD: command6.c,v 1.7 2010/04/02 19:34:44 christos Exp $");
38 #endif
39 #endif /* not lint */
40
41 #include "extern.h"
42 #include "pathnames.h"
43
44 static void post(int);
45
46 int
47 launch(void)
48 {
49 if (testbit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) {
50 if (fuel > 4) {
51 clearbit(location[position].objects, VIPER);
52 position = location[position].up;
53 notes[LAUNCHED] = 1;
54 ourtime++;
55 fuel -= 4;
56 printf("You climb into the viper and prepare for ");
57 puts("launch.");
58 printf("With a touch of your thumb the turbo engines ");
59 printf("ignite, thrusting you back into\nyour seat.\n");
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(void)
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(void)
87 { /* endgame */
88 printf("bye.\nYour rating was %s.\n", rate());
89 post(' ');
90 exit(0);
91 }
92
93 void
94 diesig(int dummy __unused)
95 {
96 die();
97 }
98
99 void
100 live(void)
101 {
102 puts("\nYou win!");
103 post('!');
104 exit(0);
105 }
106
107 static FILE *score_fp;
108
109 void
110 open_score_file(void)
111 {
112 score_fp = fopen(_PATH_SCORE, "a");
113 if (score_fp == NULL)
114 warn("open %s for append", _PATH_SCORE);
115 if (score_fp != NULL && fileno(score_fp) < 3)
116 exit(1);
117 }
118
119 static void
120 post(int ch)
121 {
122 time_t tv;
123 sigset_t isigset, osigset;
124
125 sigemptyset(&isigset);
126 sigaddset(&isigset, SIGINT);
127 sigprocmask(SIG_BLOCK, &isigset, &osigset);
128 tv = time(NULL);
129 if (score_fp != NULL) {
130 fprintf(score_fp, "%24.24s %8s %c%20s", ctime(&tv), username,
131 ch, rate());
132 if (wiz)
133 fprintf(score_fp, " wizard\n");
134 else
135 if (tempwiz)
136 fprintf(score_fp, " WIZARD!\n");
137 else
138 fprintf(score_fp, "\n");
139 }
140 sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
141 }
142
143 const char *
144 rate(void)
145 {
146 int score;
147
148 score = max(max(pleasure, power), ego);
149 if (score == pleasure) {
150 if (score < 5)
151 return ("novice");
152 else if (score < 20)
153 return ("junior voyeur");
154 else if (score < 35)
155 return ("Don Juan");
156 else
157 return ("Marquis De Sade");
158 } else if (score == power) {
159 if (score < 5)
160 return ("serf");
161 else if (score < 8)
162 return ("Samurai");
163 else if (score < 13)
164 return ("Klingon");
165 else if (score < 22)
166 return ("Darth Vader");
167 else
168 return ("Sauron the Great");
169 } else {
170 if (score < 5)
171 return ("Polyanna");
172 else if (score < 10)
173 return ("philanthropist");
174 else if (score < 20)
175 return ("Tattoo");
176 else
177 return ("Mr. Roarke");
178 }
179 }
180
181 int
182 drive(void)
183 {
184 if (testbit(location[position].objects, CAR)) {
185 printf("You hop in the car and turn the key. There is ");
186 puts("a perceptible grating noise,");
187 puts("and an explosion knocks you unconscious...");
188 clearbit(location[position].objects, CAR);
189 setbit(location[position].objects, CRASH);
190 injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
191 ourtime += 15;
192 zzz();
193 return (0);
194 } else
195 puts("There is nothing to drive here.");
196 return (-1);
197 }
198
199 int
200 ride(void)
201 {
202 if (testbit(location[position].objects, HORSE)) {
203 printf("You climb onto the stallion and kick it in the guts.");
204 puts(" The stupid steed launches");
205 printf("forward through bush and fern. You are thrown and ");
206 puts("the horse gallops off.");
207 clearbit(location[position].objects, HORSE);
208 while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE ||
209 !beenthere[position] || location[position].flyhere)
210 continue;
211 setbit(location[position].objects, HORSE);
212 if (location[position].north)
213 position = location[position].north;
214 else if (location[position].south)
215 position = location[position].south;
216 else if (location[position].east)
217 position = location[position].east;
218 else
219 position = location[position].west;
220 return (0);
221 } else
222 puts("There is no horse here.");
223 return (-1);
224 }
225
226 void
227 light(void)
228 { /* synonyms = {strike, smoke} *//* for
229 * matches, cigars */
230 if (testbit(inven, MATCHES) && matchcount) {
231 puts("Your match splutters to life.");
232 ourtime++;
233 matchlight = 1;
234 matchcount--;
235 if (position == 217) {
236 printf("The whole bungalow explodes with an ");
237 puts("intense blast.");
238 die();
239 }
240 } else
241 puts("You're out of matches.");
242 }
243
244 void
245 dooropen(void)
246 { /* synonyms = {open, unlock} */
247 wordnumber++;
248 if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS
249 && wordvalue[wordnumber] == DOOR) {
250 switch(position) {
251 case 189:
252 case 231:
253 if (location[189].north == 231)
254 puts("The door is already open.");
255 else
256 puts("The door does not budge.");
257 break;
258 case 30:
259 if (location[30].west == 25)
260 puts("The door is gone.");
261 else
262 puts("The door is locked tight.");
263 break;
264 case 31:
265 puts("That's one immovable door.");
266 break;
267 case 20:
268 puts("The door is already ajar.");
269 break;
270 default:
271 puts("What door?");
272 }
273 } else
274 puts("That doesn't open.");
275 }