command6.c revision 1.5 1 1.5 dholland /* $NetBSD: command6.c,v 1.5 2009/08/12 05:20:38 dholland 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.5 dholland __RCSID("$NetBSD: command6.c,v 1.5 2009/08/12 05:20:38 dholland 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.1 tv char *date;
124 1.3 jmc sigset_t isigset, osigset;
125 1.1 tv
126 1.3 jmc sigemptyset(&isigset);
127 1.3 jmc sigaddset(&isigset, SIGINT);
128 1.3 jmc sigprocmask(SIG_BLOCK, &isigset, &osigset);
129 1.1 tv tv = time(NULL);
130 1.1 tv date = ctime(&tv);
131 1.1 tv date[24] = '\0';
132 1.1 tv if (score_fp != NULL) {
133 1.3 jmc fprintf(score_fp, "%s %8s %c%20s", date, username,
134 1.3 jmc ch, rate());
135 1.1 tv if (wiz)
136 1.1 tv fprintf(score_fp, " wizard\n");
137 1.1 tv else
138 1.1 tv if (tempwiz)
139 1.1 tv fprintf(score_fp, " WIZARD!\n");
140 1.1 tv else
141 1.1 tv fprintf(score_fp, "\n");
142 1.1 tv }
143 1.1 tv sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
144 1.1 tv }
145 1.1 tv
146 1.3 jmc const char *
147 1.3 jmc rate(void)
148 1.1 tv {
149 1.1 tv int score;
150 1.1 tv
151 1.1 tv score = max(max(pleasure, power), ego);
152 1.1 tv if (score == pleasure) {
153 1.1 tv if (score < 5)
154 1.1 tv return ("novice");
155 1.1 tv else if (score < 20)
156 1.1 tv return ("junior voyeur");
157 1.1 tv else if (score < 35)
158 1.1 tv return ("Don Juan");
159 1.1 tv else
160 1.1 tv return ("Marquis De Sade");
161 1.1 tv } else if (score == power) {
162 1.1 tv if (score < 5)
163 1.1 tv return ("serf");
164 1.1 tv else if (score < 8)
165 1.1 tv return ("Samurai");
166 1.1 tv else if (score < 13)
167 1.1 tv return ("Klingon");
168 1.1 tv else if (score < 22)
169 1.1 tv return ("Darth Vader");
170 1.1 tv else
171 1.1 tv return ("Sauron the Great");
172 1.1 tv } else {
173 1.1 tv if (score < 5)
174 1.1 tv return ("Polyanna");
175 1.1 tv else if (score < 10)
176 1.1 tv return ("philanthropist");
177 1.1 tv else if (score < 20)
178 1.1 tv return ("Tattoo");
179 1.1 tv else
180 1.1 tv return ("Mr. Roarke");
181 1.1 tv }
182 1.1 tv }
183 1.1 tv
184 1.1 tv int
185 1.3 jmc drive(void)
186 1.1 tv {
187 1.1 tv if (testbit(location[position].objects, CAR)) {
188 1.3 jmc printf("You hop in the car and turn the key. There is ");
189 1.3 jmc puts("a perceptible grating noise,");
190 1.1 tv puts("and an explosion knocks you unconscious...");
191 1.1 tv clearbit(location[position].objects, CAR);
192 1.1 tv setbit(location[position].objects, CRASH);
193 1.1 tv injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
194 1.1 tv ourtime += 15;
195 1.1 tv zzz();
196 1.1 tv return (0);
197 1.1 tv } else
198 1.1 tv puts("There is nothing to drive here.");
199 1.1 tv return (-1);
200 1.1 tv }
201 1.1 tv
202 1.1 tv int
203 1.3 jmc ride(void)
204 1.1 tv {
205 1.1 tv if (testbit(location[position].objects, HORSE)) {
206 1.3 jmc printf("You climb onto the stallion and kick it in the guts.");
207 1.3 jmc puts(" The stupid steed launches");
208 1.3 jmc printf("forward through bush and fern. You are thrown and ");
209 1.3 jmc puts("the horse gallops off.");
210 1.1 tv clearbit(location[position].objects, HORSE);
211 1.3 jmc while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE ||
212 1.3 jmc !beenthere[position] || location[position].flyhere)
213 1.1 tv continue;
214 1.1 tv setbit(location[position].objects, HORSE);
215 1.1 tv if (location[position].north)
216 1.1 tv position = location[position].north;
217 1.1 tv else if (location[position].south)
218 1.1 tv position = location[position].south;
219 1.1 tv else if (location[position].east)
220 1.1 tv position = location[position].east;
221 1.1 tv else
222 1.1 tv position = location[position].west;
223 1.1 tv return (0);
224 1.1 tv } else
225 1.1 tv puts("There is no horse here.");
226 1.1 tv return (-1);
227 1.1 tv }
228 1.1 tv
229 1.1 tv void
230 1.3 jmc light(void)
231 1.1 tv { /* synonyms = {strike, smoke} *//* for
232 1.1 tv * matches, cigars */
233 1.1 tv if (testbit(inven, MATCHES) && matchcount) {
234 1.1 tv puts("Your match splutters to life.");
235 1.1 tv ourtime++;
236 1.1 tv matchlight = 1;
237 1.1 tv matchcount--;
238 1.1 tv if (position == 217) {
239 1.3 jmc printf("The whole bungalow explodes with an ");
240 1.3 jmc puts("intense blast.");
241 1.1 tv die();
242 1.1 tv }
243 1.1 tv } else
244 1.1 tv puts("You're out of matches.");
245 1.1 tv }
246 1.1 tv
247 1.1 tv void
248 1.3 jmc dooropen(void)
249 1.1 tv { /* synonyms = {open, unlock} */
250 1.1 tv wordnumber++;
251 1.1 tv if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS
252 1.1 tv && wordvalue[wordnumber] == DOOR) {
253 1.1 tv switch(position) {
254 1.1 tv case 189:
255 1.1 tv case 231:
256 1.1 tv if (location[189].north == 231)
257 1.1 tv puts("The door is already open.");
258 1.1 tv else
259 1.1 tv puts("The door does not budge.");
260 1.1 tv break;
261 1.1 tv case 30:
262 1.1 tv if (location[30].west == 25)
263 1.1 tv puts("The door is gone.");
264 1.1 tv else
265 1.1 tv puts("The door is locked tight.");
266 1.1 tv break;
267 1.1 tv case 31:
268 1.1 tv puts("That's one immovable door.");
269 1.1 tv break;
270 1.1 tv case 20:
271 1.1 tv puts("The door is already ajar.");
272 1.1 tv break;
273 1.1 tv default:
274 1.1 tv puts("What door?");
275 1.1 tv }
276 1.1 tv } else
277 1.1 tv puts("That doesn't open.");
278 1.1 tv }
279