1 /* $NetBSD: command4.c,v 1.1 2001/10/19 03:06:11 tv Exp $ */ 2 3 /* 4 * Copyright (c) 1983, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #include <sys/cdefs.h> 37 #ifndef lint 38 #if 0 39 static char sccsid[] = "@(#)com4.c 8.2 (Berkeley) 4/28/95"; 40 #else 41 __RCSID("$NetBSD: command4.c,v 1.1 2001/10/19 03:06:11 tv Exp $"); 42 #endif 43 #endif /* not lint */ 44 45 #include "extern.h" 46 47 int 48 take(from) 49 unsigned int from[]; 50 { 51 int firstnumber, heavy, bulky, value; 52 53 firstnumber = wordnumber; 54 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == OFF) { 55 wordnumber++; 56 wordvalue[wordnumber] = TAKEOFF; 57 wordtype[wordnumber] = VERB; 58 return (cypher()); 59 } else { 60 wordnumber++; 61 while (wordnumber <= wordcount && wordtype[wordnumber] == OBJECT) { 62 value = wordvalue[wordnumber]; 63 printf("%s:\n", objsht[value]); 64 heavy = (carrying + objwt[value]) <= WEIGHT; 65 bulky = (encumber + objcumber[value]) <= CUMBER; 66 if ((testbit(from, value) || wiz || tempwiz) && heavy && bulky && !testbit(inven, value)) { 67 setbit(inven, value); 68 carrying += objwt[value]; 69 encumber += objcumber[value]; 70 ourtime++; 71 if (testbit(from, value)) 72 printf("Taken.\n"); 73 else 74 printf("Zap! Taken from thin air.\n"); 75 clearbit(from, value); 76 if (value == MEDALION) 77 win--; 78 } else if (testbit(inven, value)) 79 printf("You're already holding %s%s.\n", 80 A_OR_AN_OR_BLANK(value), 81 objsht[value]); 82 else if (!testbit(from, value)) 83 printf("I don't see any %s around here.\n", objsht[value]); 84 else if (!heavy) 85 printf("The %s %stoo heavy.\n", objsht[value], 86 IS_OR_ARE(value)); 87 else 88 printf("The %s %stoo cumbersome to hold.\n", 89 objsht[value], IS_OR_ARE(value)); 90 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) 91 wordnumber++; 92 else 93 return (firstnumber); 94 } 95 } 96 /* special cases with their own return()'s */ 97 98 if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS) 99 switch (wordvalue[wordnumber]) { 100 101 case SWORD: 102 if (testbit(from, SWORD)) { 103 wordtype[wordnumber--] = OBJECT; 104 return (take(from)); 105 } 106 if (testbit(from, TWO_HANDED)) { 107 wordvalue[wordnumber] = TWO_HANDED; 108 wordtype[wordnumber--] = OBJECT; 109 return (take(from)); 110 } 111 wordvalue[wordnumber] = BROAD; 112 wordtype[wordnumber--] = OBJECT; 113 return (take(from)); 114 115 case BODY: 116 if (testbit(from, MAID)) { 117 wordvalue[wordnumber] = MAID; 118 wordtype[wordnumber--] = OBJECT; 119 return (take(from)); 120 } else if (testbit(from, DEADWOOD)) { 121 wordvalue[wordnumber] = DEADWOOD; 122 wordtype[wordnumber--] = OBJECT; 123 return (take(from)); 124 } else if (testbit(from, DEADNATIVE)) { 125 wordvalue[wordnumber] = DEADNATIVE; 126 wordtype[wordnumber--] = OBJECT; 127 return (take(from)); 128 } else { 129 if (testbit(from, DEADGOD)) { 130 wordvalue[wordnumber] = DEADGOD; 131 wordtype[wordnumber--] = OBJECT; 132 return (take(from)); 133 } else { 134 wordvalue[wordnumber] = DEADTIME; 135 wordtype[wordnumber--] = OBJECT; 136 return (take(from)); 137 } 138 } 139 break; 140 141 case AMULET: 142 if (testbit(location[position].objects, AMULET)) { 143 puts("The amulet is warm to the touch, and its beauty catches your breath."); 144 puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer"); 145 puts("and sharper but far away as if in a dream. The sound of purling water"); 146 puts("reaches you from afar. The mist falls again, and your heart leaps in horror."); 147 puts("The gold freezes your hands and fathomless darkness engulfs your soul."); 148 } 149 wordtype[wordnumber--] = OBJECT; 150 return (take(from)); 151 152 case MEDALION: 153 if (testbit(location[position].objects, MEDALION)) { 154 puts("The medallion is warm, and it rekindles your spirit with the warmth of life."); 155 puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate."); 156 } 157 wordtype[wordnumber--] = OBJECT; 158 return (take(from)); 159 160 case TALISMAN: 161 if (testbit(location[position].objects, TALISMAN)) { 162 puts("The talisman is cold to the touch, and it sends a chill down your spine."); 163 } 164 wordtype[wordnumber--] = OBJECT; 165 return (take(from)); 166 167 case NORMGOD: 168 if (testbit(location[position].objects, BATHGOD) && (testbit(wear, AMULET) || testbit(inven, AMULET))) { 169 puts("She offers a delicate hand, and you help her out of the sparkling springs."); 170 puts("Water droplets like liquid silver bedew her golden skin, but when they part"); 171 puts("from her, they fall as teardrops. She wraps a single cloth around her and"); 172 puts("ties it at the waist. Around her neck hangs a golden amulet."); 173 puts("She bids you to follow her, and walks away."); 174 pleasure++; 175 followgod = ourtime; 176 clearbit(location[position].objects, BATHGOD); 177 } else 178 if (!testbit(location[position].objects, BATHGOD)) 179 puts("You're in no position to take her."); 180 else 181 puts("She moves away from you."); 182 break; 183 184 default: 185 puts("It doesn't seem to work."); 186 } 187 else 188 puts("You've got to be kidding."); 189 return (firstnumber); 190 } 191 192 int 193 throw(name) 194 const char *name; 195 { 196 unsigned int n; 197 int deposit = 0; 198 int first, value; 199 200 first = wordnumber; 201 if (drop(name) != -1) { 202 switch (wordvalue[wordnumber]) { 203 204 case AHEAD: 205 deposit = ahead; 206 break; 207 208 case BACK: 209 deposit = back; 210 break; 211 212 case LEFT: 213 deposit = left; 214 break; 215 216 case RIGHT: 217 deposit = right; 218 break; 219 220 case UP: 221 deposit = location[position].up * (location[position].access || position == FINAL); 222 break; 223 224 case DOWN: 225 deposit = location[position].down; 226 break; 227 } 228 wordnumber = first + 1; 229 while (wordnumber <= wordcount) { 230 value = wordvalue[wordnumber]; 231 if (deposit && testbit(location[position].objects, value)) { 232 clearbit(location[position].objects, value); 233 if (value != GRENADE) 234 setbit(location[deposit].objects, value); 235 else { 236 puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel."); 237 for (n = 0; n < NUMOFWORDS; n++) 238 location[deposit].objects[n] = 0; 239 setbit(location[deposit].objects, CHAR); 240 } 241 if (value == ROPE && position == FINAL) 242 location[position].access = 1; 243 switch (deposit) { 244 case 189: 245 case 231: 246 puts("The stone door is unhinged."); 247 location[189].north = 231; 248 location[231].south = 189; 249 break; 250 case 30: 251 puts("The wooden door is blown open."); 252 location[30].west = 25; 253 break; 254 case 31: 255 puts("The door is not damaged."); 256 } 257 } else 258 if (value == GRENADE && testbit(location[position].objects, value)) { 259 puts("You are blown into shreds when your grenade explodes."); 260 die(); 261 } 262 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) 263 wordnumber++; 264 else 265 return (first); 266 } 267 return (first); 268 } 269 return (first); 270 } 271 272 int 273 drop(name) 274 const char *name; 275 { 276 277 int firstnumber, value; 278 279 firstnumber = wordnumber; 280 wordnumber++; 281 while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) { 282 value = wordvalue[wordnumber]; 283 if (value == BODY) { /* special case */ 284 wordtype[wordnumber] = OBJECT; 285 if (testbit(inven, MAID) || testbit(location[position].objects, MAID)) 286 value = MAID; 287 else if (testbit(inven, DEADWOOD) || testbit(location[position].objects, DEADWOOD)) 288 value = DEADWOOD; 289 else if (testbit(inven, DEADGOD) || testbit(location[position].objects, DEADGOD)) 290 value = DEADGOD; 291 else if (testbit(inven, DEADTIME) || testbit(location[position].objects, DEADTIME)) 292 value = DEADTIME; 293 else if (testbit(inven, DEADNATIVE) || testbit(location[position].objects, DEADNATIVE)) 294 value = DEADNATIVE; 295 } 296 if (wordtype[wordnumber] == NOUNS && value == DOOR) { 297 if (*name == 'K') 298 puts("You hurt your foot."); 299 else 300 puts("You're not holding a door."); 301 } else if (objsht[value] == NULL) { 302 if (*name == 'K') 303 puts("That's not for kicking!"); 304 else 305 puts("You don't have that."); 306 } else { 307 printf("%s:\n", objsht[value]); 308 if (testbit(inven, value)) { 309 clearbit(inven, value); 310 carrying -= objwt[value]; 311 encumber -= objcumber[value]; 312 if (value == BOMB) { 313 puts("The bomb explodes. A blinding white light and immense concussion obliterate us."); 314 die(); 315 } 316 if (value != AMULET && value != MEDALION && value != TALISMAN) 317 setbit(location[position].objects, value); 318 else 319 tempwiz = 0; 320 ourtime++; 321 if (*name == 'K') 322 puts("Drop kicked."); 323 else 324 printf("%s.\n", name); 325 } else { 326 if (*name != 'K') { 327 printf("You aren't holding the %s.\n", objsht[value]); 328 if (testbit(location[position].objects, value)) { 329 if (*name == 'T') 330 puts("Kicked instead."); 331 else if (*name == 'G') 332 puts("Given anyway."); 333 } 334 } else if (testbit(location[position].objects, value)) 335 puts("Kicked."); 336 else if (testbit(wear, value)) 337 puts("Not while it's being worn."); 338 else 339 puts("Not found."); 340 } 341 } 342 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) 343 wordnumber++; 344 else 345 return (firstnumber); 346 } 347 puts("Do what?"); 348 return (-1); 349 } 350 351 int 352 takeoff() 353 { 354 wordnumber = take(wear); 355 return (drop("Dropped")); 356 } 357 358 int 359 puton() 360 { 361 wordnumber = take(location[position].objects); 362 return (wearit()); 363 } 364 365 int 366 eat() 367 { 368 int firstnumber, value; 369 370 firstnumber = wordnumber; 371 wordnumber++; 372 while (wordnumber <= wordcount) { 373 value = wordvalue[wordnumber]; 374 if (wordtype[wordnumber] != OBJECT || objsht[value] == NULL) 375 value = -2; 376 switch (value) { 377 378 case -2: 379 puts("You can't eat that!"); 380 return (firstnumber); 381 382 case -1: 383 puts("Eat what?"); 384 return (firstnumber); 385 386 default: 387 printf("You can't eat %s%s!\n", 388 A_OR_AN_OR_BLANK(value), objsht[value]); 389 return (firstnumber); 390 391 case PAPAYAS: 392 case PINEAPPLE: 393 case KIWI: 394 case COCONUTS: /* eatable things */ 395 case MANGO: 396 397 printf("%s:\n", objsht[value]); 398 if (testbit(inven, value) && 399 ourtime > ate - CYCLE && 400 testbit(inven, KNIFE)) { 401 clearbit(inven, value); 402 carrying -= objwt[value]; 403 encumber -= objcumber[value]; 404 ate = max(ourtime, ate) + CYCLE / 3; 405 snooze += CYCLE / 10; 406 ourtime++; 407 puts("Eaten. You can explore a little longer now."); 408 } else if (!testbit(inven, value)) 409 printf("You aren't holding the %s.\n", objsht[value]); 410 else if (!testbit(inven, KNIFE)) 411 puts("You need a knife."); 412 else 413 puts("You're stuffed."); 414 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) 415 wordnumber++; 416 else 417 return (firstnumber); 418 } /* end switch */ 419 } /* end while */ 420 return (firstnumber); 421 } 422