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