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