command4.c 12 KB

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