]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/command6.c
convert __attribute__s to applicable cdefs.h macros
[bsdgames-darwin.git] / battlestar / command6.c
1 /* $NetBSD: command6.c,v 1.4 2007/12/15 19:44:39 perry 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.4 2007/12/15 19:44:39 perry Exp $");
38 #endif
39 #endif /* not lint */
40
41 #include "extern.h"
42 #include "pathnames.h"
43
44 int
45 launch(void)
46 {
47 if (testbit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) {
48 if (fuel > 4) {
49 clearbit(location[position].objects, VIPER);
50 position = location[position].up;
51 notes[LAUNCHED] = 1;
52 ourtime++;
53 fuel -= 4;
54 printf("You climb into the viper and prepare for ");
55 puts("launch.");
56 printf("With a touch of your thumb the turbo engines ");
57 printf("ignite, thrusting you back into\nyour seat.\n");
58 return (1);
59 } else
60 puts("Not enough fuel to launch.");
61 } else
62 puts("Can't launch.");
63 return (0);
64 }
65
66 int
67 land(void)
68 {
69 if (notes[LAUNCHED] && testbit(location[position].objects, LAND) &&
70 location[position].down) {
71 notes[LAUNCHED] = 0;
72 position = location[position].down;
73 setbit(location[position].objects, VIPER);
74 fuel -= 2;
75 ourtime++;
76 puts("You are down.");
77 return (1);
78 } else
79 puts("You can't land here.");
80 return (0);
81 }
82
83 void
84 die(void)
85 { /* endgame */
86 printf("bye.\nYour rating was %s.\n", rate());
87 post(' ');
88 exit(0);
89 }
90
91 void
92 diesig(int dummy __unused)
93 {
94 die();
95 }
96
97 void
98 live(void)
99 {
100 puts("\nYou win!");
101 post('!');
102 exit(0);
103 }
104
105 static FILE *score_fp;
106
107 void
108 open_score_file(void)
109 {
110 score_fp = fopen(_PATH_SCORE, "a");
111 if (score_fp == NULL)
112 warn("open %s for append", _PATH_SCORE);
113 if (score_fp != NULL && fileno(score_fp) < 3)
114 exit(1);
115 }
116
117 void
118 post(int ch)
119 {
120 time_t tv;
121 char *date;
122 sigset_t isigset, osigset;
123
124 sigemptyset(&isigset);
125 sigaddset(&isigset, SIGINT);
126 sigprocmask(SIG_BLOCK, &isigset, &osigset);
127 tv = time(NULL);
128 date = ctime(&tv);
129 date[24] = '\0';
130 if (score_fp != NULL) {
131 fprintf(score_fp, "%s %8s %c%20s", date, username,
132 ch, rate());
133 if (wiz)
134 fprintf(score_fp, " wizard\n");
135 else
136 if (tempwiz)
137 fprintf(score_fp, " WIZARD!\n");
138 else
139 fprintf(score_fp, "\n");
140 }
141 sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
142 }
143
144 const char *
145 rate(void)
146 {
147 int score;
148
149 score = max(max(pleasure, power), ego);
150 if (score == pleasure) {
151 if (score < 5)
152 return ("novice");
153 else if (score < 20)
154 return ("junior voyeur");
155 else if (score < 35)
156 return ("Don Juan");
157 else
158 return ("Marquis De Sade");
159 } else if (score == power) {
160 if (score < 5)
161 return ("serf");
162 else if (score < 8)
163 return ("Samurai");
164 else if (score < 13)
165 return ("Klingon");
166 else if (score < 22)
167 return ("Darth Vader");
168 else
169 return ("Sauron the Great");
170 } else {
171 if (score < 5)
172 return ("Polyanna");
173 else if (score < 10)
174 return ("philanthropist");
175 else if (score < 20)
176 return ("Tattoo");
177 else
178 return ("Mr. Roarke");
179 }
180 }
181
182 int
183 drive(void)
184 {
185 if (testbit(location[position].objects, CAR)) {
186 printf("You hop in the car and turn the key. There is ");
187 puts("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 ourtime += 15;
193 zzz();
194 return (0);
195 } else
196 puts("There is nothing to drive here.");
197 return (-1);
198 }
199
200 int
201 ride(void)
202 {
203 if (testbit(location[position].objects, HORSE)) {
204 printf("You climb onto the stallion and kick it in the guts.");
205 puts(" The stupid steed launches");
206 printf("forward through bush and fern. You are thrown and ");
207 puts("the horse gallops off.");
208 clearbit(location[position].objects, HORSE);
209 while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE ||
210 !beenthere[position] || location[position].flyhere)
211 continue;
212 setbit(location[position].objects, HORSE);
213 if (location[position].north)
214 position = location[position].north;
215 else if (location[position].south)
216 position = location[position].south;
217 else if (location[position].east)
218 position = location[position].east;
219 else
220 position = location[position].west;
221 return (0);
222 } else
223 puts("There is no horse here.");
224 return (-1);
225 }
226
227 void
228 light(void)
229 { /* synonyms = {strike, smoke} *//* for
230 * matches, cigars */
231 if (testbit(inven, MATCHES) && matchcount) {
232 puts("Your match splutters to life.");
233 ourtime++;
234 matchlight = 1;
235 matchcount--;
236 if (position == 217) {
237 printf("The whole bungalow explodes with an ");
238 puts("intense blast.");
239 die();
240 }
241 } else
242 puts("You're out of matches.");
243 }
244
245 void
246 dooropen(void)
247 { /* synonyms = {open, unlock} */
248 wordnumber++;
249 if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS
250 && wordvalue[wordnumber] == DOOR) {
251 switch(position) {
252 case 189:
253 case 231:
254 if (location[189].north == 231)
255 puts("The door is already open.");
256 else
257 puts("The door does not budge.");
258 break;
259 case 30:
260 if (location[30].west == 25)
261 puts("The door is gone.");
262 else
263 puts("The door is locked tight.");
264 break;
265 case 31:
266 puts("That's one immovable door.");
267 break;
268 case 20:
269 puts("The door is already ajar.");
270 break;
271 default:
272 puts("What door?");
273 }
274 } else
275 puts("That doesn't open.");
276 }