Commit | Line | Data |
---|---|---|
2a1cfdf5 WJ |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
35 | static char sccsid[] = "@(#)cypher.c 5.3 (Berkeley) 6/1/90"; | |
36 | #endif /* not lint */ | |
37 | ||
38 | #include "externs.h" | |
39 | ||
40 | cypher() | |
41 | { | |
42 | register int n; | |
43 | int junk; | |
44 | int lflag = -1; | |
45 | char buffer[10]; | |
46 | ||
47 | while (wordtype[wordnumber] == ADJS) | |
48 | wordnumber++; | |
49 | while (wordnumber <= wordcount) { | |
50 | switch(wordvalue[wordnumber]) { | |
51 | ||
52 | case UP: | |
53 | if (location[position].access || wiz || tempwiz) { | |
54 | if (!location[position].access) | |
55 | puts("Zap! A gust of wind lifts you up."); | |
56 | if (!move(location[position].up, AHEAD)) | |
57 | return(-1); | |
58 | } else { | |
59 | puts("There is no way up"); | |
60 | return(-1); | |
61 | } | |
62 | lflag = 0; | |
63 | break; | |
64 | ||
65 | case DOWN: | |
66 | if (!move(location[position].down, AHEAD)) | |
67 | return(-1); | |
68 | lflag = 0; | |
69 | break; | |
70 | ||
71 | case LEFT: | |
72 | if (!move(left, LEFT)) | |
73 | return(-1); | |
74 | lflag = 0; | |
75 | break; | |
76 | ||
77 | case RIGHT: | |
78 | if (!move(right, RIGHT)) | |
79 | return(-1); | |
80 | lflag = 0; | |
81 | break; | |
82 | ||
83 | case AHEAD: | |
84 | if (!move(ahead, AHEAD)) | |
85 | return(-1); | |
86 | lflag = 0; | |
87 | break; | |
88 | ||
89 | case BACK: | |
90 | if (!move(back, BACK)) | |
91 | return(-1); | |
92 | lflag = 0; | |
93 | break; | |
94 | ||
95 | case SHOOT: | |
96 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
97 | for (n=0; n < NUMOFOBJECTS; n++) | |
98 | if (testbit(location[position].objects,n) && *objsht[n]){ | |
99 | wordvalue[wordnumber+1] = n; | |
100 | wordnumber = shoot(); | |
101 | } | |
102 | wordnumber++; | |
103 | wordnumber++; | |
104 | } | |
105 | else | |
106 | shoot(); | |
107 | break; | |
108 | ||
109 | case TAKE: | |
110 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
111 | for (n=0; n < NUMOFOBJECTS; n++) | |
112 | if (testbit(location[position].objects,n) && *objsht[n]){ | |
113 | wordvalue[wordnumber+1] = n; | |
114 | wordnumber = take(location[position].objects); | |
115 | } | |
116 | wordnumber++; | |
117 | wordnumber++; | |
118 | } | |
119 | else | |
120 | take(location[position].objects); | |
121 | break; | |
122 | ||
123 | case DROP: | |
124 | ||
125 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
126 | for (n=0; n < NUMOFOBJECTS; n++) | |
127 | if (testbit(inven,n)){ | |
128 | wordvalue[wordnumber+1] = n; | |
129 | wordnumber = drop("Dropped"); | |
130 | } | |
131 | wordnumber++; | |
132 | wordnumber++; | |
133 | } | |
134 | else | |
135 | drop("Dropped"); | |
136 | break; | |
137 | ||
138 | ||
139 | case KICK: | |
140 | case THROW: | |
141 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
142 | for (n=0; n < NUMOFOBJECTS; n++) | |
143 | if (testbit(inven,n) || | |
144 | testbit(location[position].objects, n) && *objsht[n]){ | |
145 | wordvalue[wordnumber+1] = n; | |
146 | wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); | |
147 | } | |
148 | wordnumber += 2; | |
149 | } else | |
150 | throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); | |
151 | break; | |
152 | ||
153 | case TAKEOFF: | |
154 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
155 | for (n=0; n < NUMOFOBJECTS; n++) | |
156 | if (testbit(wear,n)){ | |
157 | wordvalue[wordnumber+1] = n; | |
158 | wordnumber = takeoff(); | |
159 | } | |
160 | wordnumber += 2; | |
161 | } | |
162 | else | |
163 | takeoff(); | |
164 | break; | |
165 | ||
166 | ||
167 | case DRAW: | |
168 | ||
169 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
170 | for (n=0; n < NUMOFOBJECTS; n++) | |
171 | if (testbit(wear,n)){ | |
172 | wordvalue[wordnumber+1] = n; | |
173 | wordnumber = draw(); | |
174 | } | |
175 | wordnumber += 2; | |
176 | } | |
177 | else | |
178 | draw(); | |
179 | break; | |
180 | ||
181 | ||
182 | case PUTON: | |
183 | ||
184 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
185 | for (n=0; n < NUMOFOBJECTS; n++) | |
186 | if (testbit(location[position].objects,n) && *objsht[n]){ | |
187 | wordvalue[wordnumber+1] = n; | |
188 | wordnumber = puton(); | |
189 | } | |
190 | wordnumber += 2; | |
191 | } | |
192 | else | |
193 | puton(); | |
194 | break; | |
195 | ||
196 | case WEARIT: | |
197 | ||
198 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
199 | for (n=0; n < NUMOFOBJECTS; n++) | |
200 | if (testbit(inven,n)){ | |
201 | wordvalue[wordnumber+1] = n; | |
202 | wordnumber = wearit(); | |
203 | } | |
204 | wordnumber += 2; | |
205 | } | |
206 | else | |
207 | wearit(); | |
208 | break; | |
209 | ||
210 | ||
211 | case EAT: | |
212 | ||
213 | if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ | |
214 | for (n=0; n < NUMOFOBJECTS; n++) | |
215 | if (testbit(inven,n)){ | |
216 | wordvalue[wordnumber+1] = n; | |
217 | wordnumber = eat(); | |
218 | } | |
219 | wordnumber += 2; | |
220 | } | |
221 | else | |
222 | eat(); | |
223 | break; | |
224 | ||
225 | ||
226 | case PUT: | |
227 | put(); | |
228 | break; | |
229 | ||
230 | ||
231 | case INVEN: | |
232 | if (ucard(inven)){ | |
233 | puts("You are holding:\n"); | |
234 | for (n=0; n < NUMOFOBJECTS; n++) | |
235 | if (testbit(inven,n)) | |
236 | printf("\t%s\n", objsht[n]); | |
237 | printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."),(WEIGHT ? carrying*100/WEIGHT : -1)); | |
238 | printf("Your arms are %d%% full.\n",encumber*100/CUMBER); | |
239 | } | |
240 | else | |
241 | puts("You aren't carrying anything."); | |
242 | ||
243 | if (ucard(wear)){ | |
244 | puts("\nYou are wearing:\n"); | |
245 | for (n=0; n < NUMOFOBJECTS; n++) | |
246 | if (testbit(wear,n)) | |
247 | printf("\t%s\n", objsht[n]); | |
248 | } | |
249 | else | |
250 | puts("\nYou are stark naked."); | |
251 | if (card(injuries,NUMOFINJURIES)){ | |
252 | puts("\nYou have suffered:\n"); | |
253 | for (n=0; n < NUMOFINJURIES; n++) | |
254 | if (injuries[n]) | |
255 | printf("\t%s\n",ouch[n]); | |
256 | printf("\nYou can still carry up to %d kilogram%s\n",WEIGHT,(WEIGHT == 1 ? "." : "s.")); | |
257 | } | |
258 | else | |
259 | puts("\nYou are in perfect health."); | |
260 | break; | |
261 | ||
262 | case USE: | |
263 | lflag = use(); | |
264 | break; | |
265 | ||
266 | case LOOK: | |
267 | if (!notes[CANTSEE] || testbit(inven,LAMPON) || testbit(location[position].objects,LAMPON) || matchlight){ | |
268 | beenthere[position] = 2; | |
269 | writedes(); | |
270 | printobjs(); | |
271 | if (matchlight){ | |
272 | puts("\nYour match splutters out."); | |
273 | matchlight = 0; | |
274 | } | |
275 | } else | |
276 | puts("I can't see anything."); | |
277 | return(-1); | |
278 | break; | |
279 | ||
280 | case SU: | |
281 | if (wiz || tempwiz){ | |
282 | printf("\nRoom (was %d) = ", position); | |
283 | fgets(buffer,10,stdin); | |
284 | if (*buffer != '\n') | |
285 | sscanf(buffer,"%d", &position); | |
286 | printf("Time (was %d) = ",time); | |
287 | fgets(buffer,10,stdin); | |
288 | if (*buffer != '\n') | |
289 | sscanf(buffer,"%d", &time); | |
290 | printf("Fuel (was %d) = ",fuel); | |
291 | fgets(buffer,10,stdin); | |
292 | if (*buffer != '\n') | |
293 | sscanf(buffer,"%d", &fuel); | |
294 | printf("Torps (was %d) = ",torps); | |
295 | fgets(buffer,10,stdin); | |
296 | if (*buffer != '\n') | |
297 | sscanf(buffer,"%d", &torps); | |
298 | printf("CUMBER (was %d) = ",CUMBER); | |
299 | fgets(buffer,10,stdin); | |
300 | if (*buffer != '\n') | |
301 | sscanf(buffer,"%d", &CUMBER); | |
302 | printf("WEIGHT (was %d) = ",WEIGHT); | |
303 | fgets(buffer,10,stdin); | |
304 | if (*buffer != '\n') | |
305 | sscanf(buffer,"%d",&WEIGHT); | |
306 | printf("Clock (was %d) = ",clock); | |
307 | fgets(buffer,10,stdin); | |
308 | if (*buffer != '\n') | |
309 | sscanf(buffer,"%d",&clock); | |
310 | printf("Wizard (was %d, %d) = ",wiz, tempwiz); | |
311 | fgets(buffer,10,stdin); | |
312 | if (*buffer != '\n'){ | |
313 | sscanf(buffer,"%d",&junk); | |
314 | if (!junk) | |
315 | tempwiz = wiz = 0; | |
316 | } | |
317 | printf("\nDONE.\n"); | |
318 | return(0); | |
319 | } | |
320 | else | |
321 | puts("You aren't a wizard."); | |
322 | break; | |
323 | ||
324 | case SCORE: | |
325 | printf("\tPLEASURE\tPOWER\t\tEGO\n"); | |
326 | printf("\t%3d\t\t%3d\t\t%3d\n\n",pleasure,power,ego); | |
327 | printf("This gives you the rating of %s in %d turns.\n",rate(),time); | |
328 | printf("You have visited %d out of %d rooms this run (%d%%).\n",card(beenthere,NUMOFROOMS),NUMOFROOMS,card(beenthere,NUMOFROOMS)*100/NUMOFROOMS); | |
329 | break; | |
330 | ||
331 | case KNIFE: | |
332 | case KILL: | |
333 | murder(); | |
334 | break; | |
335 | ||
336 | case UNDRESS: | |
337 | case RAVAGE: | |
338 | ravage(); | |
339 | break; | |
340 | ||
341 | case SAVE: | |
342 | save(); | |
343 | break; | |
344 | ||
345 | case FOLLOW: | |
346 | lflag = follow(); | |
347 | break; | |
348 | ||
349 | case GIVE: | |
350 | give(); | |
351 | break; | |
352 | ||
353 | case KISS: | |
354 | kiss(); | |
355 | break; | |
356 | ||
357 | case LOVE: | |
358 | love(); | |
359 | break; | |
360 | ||
361 | case RIDE: | |
362 | lflag = ride(); | |
363 | break; | |
364 | ||
365 | case DRIVE: | |
366 | lflag = drive(); | |
367 | break; | |
368 | ||
369 | case LIGHT: | |
370 | light(); | |
371 | break; | |
372 | ||
373 | case LAUNCH: | |
374 | if (!launch()) | |
375 | return(-1); | |
376 | else | |
377 | lflag = 0; | |
378 | break; | |
379 | ||
380 | case LANDIT: | |
381 | if (!land()) | |
382 | return(-1); | |
383 | else | |
384 | lflag = 0; | |
385 | break; | |
386 | ||
387 | case TIME: | |
388 | chime(); | |
389 | break; | |
390 | ||
391 | case SLEEP: | |
392 | zzz(); | |
393 | break; | |
394 | ||
395 | case DIG: | |
396 | dig(); | |
397 | break; | |
398 | ||
399 | case JUMP: | |
400 | lflag = jump(); | |
401 | break; | |
402 | ||
403 | case BURY: | |
404 | bury(); | |
405 | break; | |
406 | ||
407 | case SWIM: | |
408 | puts("Surf's up!"); | |
409 | break; | |
410 | ||
411 | case DRINK: | |
412 | drink(); | |
413 | break; | |
414 | ||
415 | case QUIT: | |
416 | die(); | |
417 | ||
418 | default: | |
419 | puts("How's that?"); | |
420 | return(-1); | |
421 | break; | |
422 | ||
423 | ||
424 | } | |
425 | if (wordnumber < wordcount && *words[wordnumber++] == ',') | |
426 | continue; | |
427 | else return(lflag); | |
428 | } | |
429 | return(lflag); | |
430 | } |