command6.c revision 1.2 1 /* $NetBSD: command6.c,v 1.2 2003/08/07 09:37:01 agc 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.2 2003/08/07 09:37:01 agc Exp $");
38 #endif
39 #endif /* not lint */
40
41 #include "extern.h"
42 #include "pathnames.h"
43
44 int
45 launch()
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 puts("You climb into the viper and prepare for launch.");
55 puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
56 return (1);
57 } else
58 puts("Not enough fuel to launch.");
59 } else
60 puts("Can't launch.");
61 return (0);
62 }
63
64 int
65 land()
66 {
67 if (notes[LAUNCHED] && testbit(location[position].objects, LAND) &&
68 location[position].down) {
69 notes[LAUNCHED] = 0;
70 position = location[position].down;
71 setbit(location[position].objects, VIPER);
72 fuel -= 2;
73 ourtime++;
74 puts("You are down.");
75 return (1);
76 } else
77 puts("You can't land here.");
78 return (0);
79 }
80
81 void
82 die()
83 { /* endgame */
84 printf("bye.\nYour rating was %s.\n", rate());
85 post(' ');
86 exit(0);
87 }
88
89 void
90 diesig(dummy)
91 int dummy __attribute__((__unused__));
92 {
93 die();
94 }
95
96 void
97 live()
98 {
99 puts("\nYou win!");
100 post('!');
101 exit(0);
102 }
103
104 static FILE *score_fp;
105
106 void
107 open_score_file()
108 {
109 score_fp = fopen(_PATH_SCORE, "a");
110 if (score_fp == NULL)
111 warn("open %s for append", _PATH_SCORE);
112 if (score_fp != NULL && fileno(score_fp) < 3)
113 exit(1);
114 }
115
116 void
117 post(ch)
118 char ch;
119 {
120 time_t tv;
121 char *date;
122 sigset_t sigset, osigset;
123
124 sigemptyset(&sigset);
125 sigaddset(&sigset, SIGINT);
126 sigprocmask(SIG_BLOCK, &sigset, &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, 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()
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()
183 {
184 if (testbit(location[position].objects, CAR)) {
185 puts("You hop in the car and turn the key. There is a perceptible grating noise,");
186 puts("and an explosion knocks you unconscious...");
187 clearbit(location[position].objects, CAR);
188 setbit(location[position].objects, CRASH);
189 injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
190 ourtime += 15;
191 zzz();
192 return (0);
193 } else
194 puts("There is nothing to drive here.");
195 return (-1);
196 }
197
198 int
199 ride()
200 {
201 if (testbit(location[position].objects, HORSE)) {
202 puts("You climb onto the stallion and kick it in the guts. The stupid steed launches");
203 puts("forward through bush and fern. You are thrown and the horse gallops off.");
204 clearbit(location[position].objects, HORSE);
205 while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere)
206 continue;
207 setbit(location[position].objects, HORSE);
208 if (location[position].north)
209 position = location[position].north;
210 else if (location[position].south)
211 position = location[position].south;
212 else if (location[position].east)
213 position = location[position].east;
214 else
215 position = location[position].west;
216 return (0);
217 } else
218 puts("There is no horse here.");
219 return (-1);
220 }
221
222 void
223 light()
224 { /* synonyms = {strike, smoke} *//* for
225 * matches, cigars */
226 if (testbit(inven, MATCHES) && matchcount) {
227 puts("Your match splutters to life.");
228 ourtime++;
229 matchlight = 1;
230 matchcount--;
231 if (position == 217) {
232 puts("The whole bungalow explodes with an intense blast.");
233 die();
234 }
235 } else
236 puts("You're out of matches.");
237 }
238
239 void
240 dooropen()
241 { /* synonyms = {open, unlock} */
242 wordnumber++;
243 if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS
244 && wordvalue[wordnumber] == DOOR) {
245 switch(position) {
246 case 189:
247 case 231:
248 if (location[189].north == 231)
249 puts("The door is already open.");
250 else
251 puts("The door does not budge.");
252 break;
253 case 30:
254 if (location[30].west == 25)
255 puts("The door is gone.");
256 else
257 puts("The door is locked tight.");
258 break;
259 case 31:
260 puts("That's one immovable door.");
261 break;
262 case 20:
263 puts("The door is already ajar.");
264 break;
265 default:
266 puts("What door?");
267 }
268 } else
269 puts("That doesn't open.");
270 }
271