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