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