1109e8aa7Sedward /* 21f2fb9e6Sbostic * Copyright (c) 1983 Regents of the University of California. 31f2fb9e6Sbostic * All rights reserved. 41f2fb9e6Sbostic * 51f2fb9e6Sbostic * Redistribution and use in source and binary forms are permitted 6e7767740Sbostic * provided that the above copyright notice and this paragraph are 7e7767740Sbostic * duplicated in all such forms and that any documentation, 8e7767740Sbostic * advertising materials, and other materials related to such 9e7767740Sbostic * distribution and use acknowledge that the software was developed 10e7767740Sbostic * by the University of California, Berkeley. The name of the 11e7767740Sbostic * University may not be used to endorse or promote products derived 12e7767740Sbostic * from this software without specific prior written permission. 13e7767740Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14e7767740Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15e7767740Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16109e8aa7Sedward */ 17109e8aa7Sedward 18849ca828Sedward #ifndef lint 19*43ded9bfSedward static char sccsid[] = "@(#)com4.c 5.3 (Berkeley) 09/30/89"; 201f2fb9e6Sbostic #endif /* not lint */ 21849ca828Sedward 22849ca828Sedward #include "externs.h" 23849ca828Sedward 24849ca828Sedward take(from) 25849ca828Sedward unsigned int from[]; 26849ca828Sedward { 27849ca828Sedward int firstnumber, heavy, bulky, value; 28849ca828Sedward register int n; 29849ca828Sedward 30849ca828Sedward firstnumber = wordnumber; 31849ca828Sedward if (wordnumber < wordcount && wordvalue[wordnumber+1] == OFF){ 32849ca828Sedward wordnumber++; 33849ca828Sedward wordvalue[wordnumber] = TAKEOFF; 34849ca828Sedward return(cypher()); 35849ca828Sedward } 36849ca828Sedward else { 37849ca828Sedward while(wordtype[++wordnumber] == ADJS); 38849ca828Sedward while(wordnumber<=wordcount && wordtype[wordnumber] == OBJECT){ 39849ca828Sedward value = wordvalue[wordnumber]; 40849ca828Sedward printf("%s:\n", objsht[value]); 41849ca828Sedward for (n=0; objsht[value][n]; n++); 42849ca828Sedward heavy = (carrying + objwt[value]) <= WEIGHT; 43849ca828Sedward bulky = (encumber + objcumber[value]) <= CUMBER; 44849ca828Sedward if ((testbit(from,value) || wiz || tempwiz) && heavy && bulky && !testbit(inven,value)){ 45849ca828Sedward setbit(inven,value); 46849ca828Sedward carrying += objwt[value]; 47849ca828Sedward encumber += objcumber[value]; 48849ca828Sedward time++; 49849ca828Sedward if (testbit(from,value)) 50849ca828Sedward printf("Taken.\n"); 51849ca828Sedward else 52849ca828Sedward printf("Zap! Taken from thin air.\n"); 53849ca828Sedward clearbit(from,value); 54849ca828Sedward if (value == MEDALION) 55849ca828Sedward win--; 56849ca828Sedward } 57849ca828Sedward else if (testbit(inven,value)) 58849ca828Sedward printf("You're already holding%s%s.\n", (objsht[value][n-1] == 's' ? " " : " a "),objsht[value]); 59849ca828Sedward else if (!heavy) 60849ca828Sedward printf("The %s %s too heavy.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is")); 61849ca828Sedward else if (!bulky) 62849ca828Sedward printf("The %s %s too cumbersome to hold.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is")); 63849ca828Sedward else 64849ca828Sedward printf("I dont see any %s around here.\n", objsht[value]); 65849ca828Sedward if (wordnumber < wordcount -1 && wordvalue[++wordnumber] == AND) 66849ca828Sedward wordnumber++; 67849ca828Sedward else 68849ca828Sedward return(firstnumber); 69849ca828Sedward } 70849ca828Sedward } 71849ca828Sedward /* special cases with their own return()'s */ 72849ca828Sedward 73849ca828Sedward if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS) 74849ca828Sedward switch(wordvalue[wordnumber]){ 75849ca828Sedward 76849ca828Sedward case SWORD: 77849ca828Sedward if (testbit(from, SWORD)){ 78849ca828Sedward wordtype[wordnumber--] = OBJECT; 79849ca828Sedward return(take(from)); 80849ca828Sedward } 81849ca828Sedward if (testbit(from, TWO_HANDED)){ 82849ca828Sedward wordvalue[wordnumber] = TWO_HANDED; 83849ca828Sedward wordtype[wordnumber--] = OBJECT; 84849ca828Sedward return(take(from)); 85849ca828Sedward } 86849ca828Sedward wordvalue[wordnumber] = BROAD; 87849ca828Sedward wordtype[wordnumber--] = OBJECT; 88849ca828Sedward return(take(from)); 89849ca828Sedward 90849ca828Sedward case BODY: 91849ca828Sedward if (testbit(from,MAID)){ 92849ca828Sedward wordvalue[wordnumber] = MAID; 93849ca828Sedward wordtype[wordnumber--] = OBJECT; 94849ca828Sedward return(take(from)); 95849ca828Sedward } 96849ca828Sedward else if (testbit(from,DEADWOOD)){ 97849ca828Sedward wordvalue[wordnumber] = DEADWOOD; 98849ca828Sedward wordtype[wordnumber--] = OBJECT; 99849ca828Sedward return(take(from)); 100849ca828Sedward } 101849ca828Sedward else if (testbit(from,DEADNATIVE)){ 102849ca828Sedward wordvalue[wordnumber] = DEADNATIVE; 103849ca828Sedward wordtype[wordnumber--] = OBJECT; 104849ca828Sedward return(take(from)); 105849ca828Sedward } 106849ca828Sedward else if (testbit(from,DEADGOD)){ 107849ca828Sedward wordvalue[wordnumber] = DEADGOD; 108849ca828Sedward wordtype[wordnumber--] = OBJECT; 109849ca828Sedward return(take(from)); 110849ca828Sedward } 111849ca828Sedward else { 112849ca828Sedward wordvalue[wordnumber] = DEADTIME; 113849ca828Sedward wordtype[wordnumber--] = OBJECT; 114849ca828Sedward return(take(from)); 115849ca828Sedward } 116849ca828Sedward break; 117849ca828Sedward 118849ca828Sedward case AMULET: 119849ca828Sedward if (testbit(location[position].objects,AMULET)){ 1207f30157aSedward puts("The amulet is warm to the touch, and its beauty catches your breath."); 1217f30157aSedward puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer"); 122849ca828Sedward puts("and sharper but far away as if in a dream. The sound of purling water reaches"); 1237f30157aSedward puts("you from afar. The mist falls again, and your heart leaps in horror. The gold"); 124849ca828Sedward puts("freezes your hands and fathomless darkness engulfs your soul."); 125849ca828Sedward } 126849ca828Sedward wordtype[wordnumber--] = OBJECT; 127849ca828Sedward return(take(from)); 128849ca828Sedward 129849ca828Sedward case MEDALION: 130849ca828Sedward if (testbit(location[position].objects, MEDALION)){ 1317f30157aSedward puts("The medallion is warm, and it rekindles your spirit with the warmth of life."); 132849ca828Sedward puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate."); 133849ca828Sedward } 134849ca828Sedward wordtype[wordnumber--] = OBJECT; 135849ca828Sedward return(take(from)); 136849ca828Sedward 137849ca828Sedward case TALISMAN: 138849ca828Sedward if (testbit(location[position].objects,TALISMAN)){ 1397f30157aSedward puts("The talisman is cold to the touch, and it sends a chill down your spine."); 140849ca828Sedward } 141849ca828Sedward wordtype[wordnumber--] = OBJECT; 142849ca828Sedward return(take(from)); 143849ca828Sedward 144849ca828Sedward case NORMGOD: 145849ca828Sedward if (testbit(location[position].objects,BATHGOD) && (testbit(wear,AMULET) || testbit(inven,AMULET))){ 1467f30157aSedward puts("She offers a delicate hand, and you help her out of the sparkling springs."); 147849ca828Sedward puts("Water droplets like liquid silver bedew her golden skin, but when they part"); 148849ca828Sedward puts("from her, they fall as teardrops. She wraps a single cloth around her and"); 149849ca828Sedward puts("ties it at the waist. Around her neck hangs a golden amulet."); 150849ca828Sedward puts("She bids you to follow her."); 151849ca828Sedward pleasure++; 152849ca828Sedward followgod = time; 153849ca828Sedward clearbit(location[position].objects,BATHGOD); 154849ca828Sedward } else if (!testbit(location[position].objects,BATHGOD)) 155849ca828Sedward puts("You're in no position to take her."); 156849ca828Sedward else 157849ca828Sedward puts("She moves away from you."); 158849ca828Sedward break; 159849ca828Sedward 160849ca828Sedward default: 161849ca828Sedward puts("It doesn't seem to work."); 162849ca828Sedward } 163849ca828Sedward else 164849ca828Sedward puts("You've got to be kidding."); 165849ca828Sedward return(firstnumber); 166849ca828Sedward } 167849ca828Sedward 1687f30157aSedward throw(name) 1697f30157aSedward char *name; 170849ca828Sedward { 171849ca828Sedward int n; 172849ca828Sedward int deposit = 0; 173849ca828Sedward int first, value; 174849ca828Sedward 175849ca828Sedward first = wordnumber; 1767f30157aSedward if (drop(name) != -1){ 177849ca828Sedward switch(wordvalue[wordnumber]){ 178849ca828Sedward 179849ca828Sedward case AHEAD: 180849ca828Sedward deposit = ahead; 181849ca828Sedward break; 182849ca828Sedward 183849ca828Sedward case BACK: 184849ca828Sedward deposit = back; 185849ca828Sedward break; 186849ca828Sedward 187849ca828Sedward case LEFT: 188849ca828Sedward deposit = left; 189849ca828Sedward break; 190849ca828Sedward 191849ca828Sedward case RIGHT: 192849ca828Sedward deposit = right; 193849ca828Sedward break; 194849ca828Sedward 195849ca828Sedward case UP: 196849ca828Sedward deposit = location[position].up * (location[position].access || position == FINAL); 197849ca828Sedward break; 198849ca828Sedward 199849ca828Sedward case DOWN: 200849ca828Sedward deposit = location[position].down; 201849ca828Sedward break; 202849ca828Sedward } 203849ca828Sedward wordnumber = first; 204849ca828Sedward while (wordtype[++wordnumber] == ADJS); 205849ca828Sedward while (wordnumber <= wordcount){ 206849ca828Sedward value = wordvalue[wordnumber]; 207849ca828Sedward if (deposit && testbit(location[position].objects,value)){ 208849ca828Sedward clearbit(location[position].objects,value); 209849ca828Sedward if (value != GRENADE) 210849ca828Sedward setbit(location[deposit].objects,value); 211849ca828Sedward else{ 212849ca828Sedward puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel."); 213849ca828Sedward for (n = 0; n < NUMOFWORDS; n ++) 214849ca828Sedward location[deposit].objects[n] = 0; 215849ca828Sedward setbit(location[deposit].objects,CHAR); 216849ca828Sedward } 217849ca828Sedward if (value == ROPE && position == FINAL) 218849ca828Sedward location[position].access = 1; 219849ca828Sedward switch(deposit){ 220849ca828Sedward case 189: 221849ca828Sedward case 231: 222849ca828Sedward puts("The stone door is unhinged."); 223849ca828Sedward location[189].north = 231; 224849ca828Sedward location[231].south = 189; 225849ca828Sedward break; 226849ca828Sedward case 30: 227849ca828Sedward puts("The wooden door is blown open."); 228849ca828Sedward location[30].west = 25; 229849ca828Sedward break; 230849ca828Sedward case 31: 231849ca828Sedward puts("The door is not damaged."); 232849ca828Sedward } 233849ca828Sedward } 234849ca828Sedward else if (value == GRENADE && testbit(location[position].objects,value)){ 235849ca828Sedward puts("You are blown into shreds when your grenade explodes."); 236849ca828Sedward die(); 237849ca828Sedward } 238849ca828Sedward if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) 239849ca828Sedward wordnumber++; 240849ca828Sedward else 241849ca828Sedward return(first); 242849ca828Sedward } 243849ca828Sedward return(first); 244849ca828Sedward } 245849ca828Sedward return(first); 246849ca828Sedward } 247849ca828Sedward 248849ca828Sedward drop(name) 249849ca828Sedward char *name; 250849ca828Sedward { 251849ca828Sedward 252849ca828Sedward int firstnumber, value; 253849ca828Sedward 254849ca828Sedward firstnumber = wordnumber; 2557f30157aSedward while (wordtype[++wordnumber] == ADJS) 2567f30157aSedward ; 257849ca828Sedward while (wordnumber<=wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) { 258849ca828Sedward value = wordvalue[wordnumber]; 259849ca828Sedward printf("%s:\n", objsht[value]); 260849ca828Sedward if (testbit(inven,value)){ 261849ca828Sedward clearbit(inven,value); 262849ca828Sedward carrying -= objwt[value]; 263849ca828Sedward encumber -= objcumber[value]; 264849ca828Sedward if (value == BOMB){ 265849ca828Sedward puts("The bomb explodes. A blinding white light and immense concussion obliterate us."); 266849ca828Sedward die(); 267849ca828Sedward } 268849ca828Sedward if (value != AMULET && value != MEDALION && value != TALISMAN) 269849ca828Sedward setbit(location[position].objects,value); 270849ca828Sedward else 271849ca828Sedward tempwiz = 0; 272849ca828Sedward time++; 2737f30157aSedward if (*name == 'K') 2747f30157aSedward puts("Drop kicked."); 2757f30157aSedward else 276849ca828Sedward printf("%s.\n", name); 277849ca828Sedward } 278849ca828Sedward else { 2797f30157aSedward if (*name != 'K') { 280849ca828Sedward printf("You aren't holding the %s.\n", objsht[value]); 281849ca828Sedward if (testbit(location[position].objects,value)) { 282849ca828Sedward if (*name == 'T') 283849ca828Sedward puts("Kicked instead."); 2847f30157aSedward else if (*name == 'G') 285849ca828Sedward puts("Given anyway."); 286849ca828Sedward } 2877f30157aSedward } else 2887f30157aSedward puts("Kicked."); 289849ca828Sedward } 290849ca828Sedward if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) 291849ca828Sedward wordnumber++; 292849ca828Sedward else 293849ca828Sedward return(firstnumber); 294849ca828Sedward } 295849ca828Sedward puts("Do what?"); 296849ca828Sedward return(-1); 297849ca828Sedward } 298849ca828Sedward 299849ca828Sedward takeoff() 300849ca828Sedward { 301849ca828Sedward wordnumber = take(wear); 302849ca828Sedward return(drop("Dropped")); 303849ca828Sedward } 304849ca828Sedward 305849ca828Sedward puton() 306849ca828Sedward { 307849ca828Sedward wordnumber = take(location[position].objects); 308849ca828Sedward return(wearit()); 309849ca828Sedward } 310849ca828Sedward 311849ca828Sedward eat() 312849ca828Sedward { 313849ca828Sedward int firstnumber, value; 314849ca828Sedward 315849ca828Sedward firstnumber = wordnumber; 316849ca828Sedward while(wordtype[++wordnumber] == ADJS); 317849ca828Sedward while(wordnumber <= wordcount){ 318849ca828Sedward value = wordvalue[wordnumber]; 319849ca828Sedward switch(value){ 320849ca828Sedward 321849ca828Sedward case -1: 322849ca828Sedward puts("Eat what?"); 323849ca828Sedward return(firstnumber); 324849ca828Sedward 325849ca828Sedward default: 326*43ded9bfSedward printf("You can't eat%s%s!\n", 327*43ded9bfSedward wordtype[wordnumber] == OBJECT && 328*43ded9bfSedward objsht[value] 329*43ded9bfSedward [strlen(objsht[value]) - 1] == 's' ? 330*43ded9bfSedward " " : " a ", 331*43ded9bfSedward words[wordnumber]); 332849ca828Sedward return(firstnumber); 333849ca828Sedward 334849ca828Sedward case PAPAYAS: 335849ca828Sedward case PINEAPPLE: 336849ca828Sedward case KIWI: 337849ca828Sedward case COCONUTS: /* eatable things */ 338849ca828Sedward case MANGO: 339849ca828Sedward 340849ca828Sedward printf("%s:\n",objsht[value]); 341849ca828Sedward if (testbit(inven,value) && time > ate - CYCLE && testbit(inven,KNIFE)){ 342849ca828Sedward clearbit(inven,value); 343849ca828Sedward carrying -= objwt[value]; 344849ca828Sedward encumber -= objcumber[value]; 345849ca828Sedward ate = max(time,ate) + CYCLE/3; 346849ca828Sedward snooze += CYCLE/10; 347849ca828Sedward time++; 3487f30157aSedward puts("Eaten. You can explore a little longer now."); 349849ca828Sedward } 350849ca828Sedward else if (time < ate - CYCLE) 3517f30157aSedward puts("You're stuffed."); 352849ca828Sedward else if (!testbit(inven,KNIFE)) 353849ca828Sedward puts("You need a knife."); 354849ca828Sedward else 355849ca828Sedward printf("You aren't holding the %s.\n", objsht[value]); 356849ca828Sedward if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) 357849ca828Sedward wordnumber++; 358849ca828Sedward else 359849ca828Sedward return(firstnumber); 360849ca828Sedward } /* end switch */ 361849ca828Sedward } /* end while */ 362849ca828Sedward return(firstnumber); 363849ca828Sedward } 364