command7.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* $NetBSD: command7.c,v 1.2 2003/08/07 09:37:01 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[] = "@(#)com7.c 8.2 (Berkeley) 4/28/95";
  34. #else
  35. __RCSID("$NetBSD: command7.c,v 1.2 2003/08/07 09:37:01 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "extern.h"
  39. int
  40. fight(enemy, strength)
  41. int enemy, strength;
  42. {
  43. int lifeline = 0;
  44. int hurt;
  45. char auxbuf[LINELENGTH];
  46. char *next;
  47. int i;
  48. int exhaustion;
  49. exhaustion = 0;
  50. fighton:
  51. ourtime++;
  52. snooze -= 5;
  53. if (snooze > ourtime)
  54. exhaustion = CYCLE / (snooze - ourtime);
  55. else {
  56. puts("You collapse exhausted, and he pulverizes your skull.");
  57. die();
  58. }
  59. if (snooze - ourtime < 20)
  60. puts("You look tired! I hope you're able to fight.");
  61. next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0);
  62. for (i = 0; next && i < 10; i++)
  63. next = getword(next, words[i], -1);
  64. parse();
  65. switch (wordvalue[wordnumber]) {
  66. case KILL:
  67. case SMITE:
  68. if (testbit(inven, TWO_HANDED))
  69. hurt = rnd(70) - 2 * card(injuries, NUMOFINJURIES) - ucard(wear) - exhaustion;
  70. else if (testbit(inven, SWORD) || testbit(inven, BROAD))
  71. hurt = rnd(50) % (WEIGHT - carrying) - card(injuries, NUMOFINJURIES) - encumber - exhaustion;
  72. else if (testbit(inven, KNIFE) || testbit(inven, MALLET) || testbit(inven, CHAIN) || testbit(inven, MACE) || testbit(inven, HALBERD))
  73. hurt = rnd(15) - card(injuries, NUMOFINJURIES) - exhaustion;
  74. else
  75. hurt = rnd(7) - encumber;
  76. if (hurt < 5)
  77. switch (rnd(3)) {
  78. case 0:
  79. puts("You swung wide and missed.");
  80. break;
  81. case 1:
  82. puts("He checked your blow. CLASH! CLANG!");
  83. break;
  84. case 2:
  85. puts("His filthy tunic hangs by one less thread.");
  86. break;
  87. }
  88. else if (hurt < 10) {
  89. switch (rnd(3)) {
  90. case 0:
  91. puts("He's bleeding.");
  92. break;
  93. case 1:
  94. puts("A trickle of blood runs down his face.");
  95. break;
  96. case 2:
  97. puts("A huge purple bruise is forming on the side of his face.");
  98. break;
  99. }
  100. lifeline++;
  101. } else if (hurt < 20) {
  102. switch (rnd(3)) {
  103. case 0:
  104. puts("He staggers back quavering.");
  105. break;
  106. case 1:
  107. puts("He jumps back with his hand over the wound.");
  108. break;
  109. case 2:
  110. puts("His shirt falls open with a swath across the chest.");
  111. break;
  112. }
  113. lifeline += 5;
  114. } else if (hurt < 30) {
  115. switch (rnd(3)) {
  116. case 0:
  117. printf("A bloody gash opens up on his %s side.\n", (rnd(2) ? "left" : "right"));
  118. break;
  119. case 1:
  120. puts("The steel bites home and scrapes along his ribs.");
  121. break;
  122. case 2:
  123. puts("You pierce him, and his breath hisses through clenched teeth.");
  124. break;
  125. }
  126. lifeline += 10;
  127. } else if (hurt < 40) {
  128. switch (rnd(3)) {
  129. case 0:
  130. puts("You smite him to the ground.");
  131. if (strength - lifeline > 20)
  132. puts("But in a flurry of steel he regains his feet!");
  133. break;
  134. case 1:
  135. puts("The force of your blow sends him to his knees.");
  136. puts("His arm swings lifeless at his side.");
  137. break;
  138. case 2:
  139. puts("Clutching his blood drenched shirt, he collapses stunned.");
  140. break;
  141. }
  142. lifeline += 20;
  143. } else {
  144. switch (rnd(3)) {
  145. case 0:
  146. puts("His ribs crack under your powerful swing, flooding his lungs with blood.");
  147. break;
  148. case 1:
  149. puts("You shatter his upheld arm in a spray of blood. The blade continues deep");
  150. puts("into his back, severing the spinal cord.");
  151. lifeline += 25;
  152. break;
  153. case 2:
  154. puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground.");
  155. lifeline += 25;
  156. break;
  157. }
  158. lifeline += 30;
  159. }
  160. break;
  161. case BACK:
  162. if (enemy == DARK && lifeline > strength * 0.33) {
  163. puts("He throws you back against the rock and pummels your face.");
  164. if (testbit(inven, AMULET) || testbit(wear, AMULET)) {
  165. printf("Lifting the amulet from you, ");
  166. if (testbit(inven, MEDALION) || testbit(wear, MEDALION)) {
  167. puts("his power grows and the walls of\nthe earth tremble.");
  168. puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse.");
  169. puts("The planet is consumed by darkness.");
  170. die();
  171. }
  172. if (testbit(inven, AMULET)) {
  173. clearbit(inven, AMULET);
  174. carrying -= objwt[AMULET];
  175. encumber -= objcumber[AMULET];
  176. } else
  177. clearbit(wear, AMULET);
  178. puts("he flees down the dark caverns.");
  179. clearbit(location[position].objects, DARK);
  180. injuries[SKULL] = 1;
  181. followfight = ourtime;
  182. return (0);
  183. } else {
  184. puts("I'm afraid you have been killed.");
  185. die();
  186. }
  187. } else {
  188. puts("You escape stunned and disoriented from the fight.");
  189. puts("A victorious bellow echoes from the battlescene.");
  190. if (back && position != back)
  191. moveplayer(back, BACK);
  192. else if (ahead && position != ahead)
  193. moveplayer(ahead, AHEAD);
  194. else if (left && position != left)
  195. moveplayer(left, LEFT);
  196. else if (right && position != right)
  197. moveplayer(right, RIGHT);
  198. else
  199. moveplayer(location[position].down, AHEAD);
  200. return (0);
  201. }
  202. case SHOOT:
  203. if (testbit(inven, LASER)) {
  204. if (strength - lifeline <= 50) {
  205. printf("The %s took a direct hit!\n", objsht[enemy]);
  206. lifeline += 50;
  207. } else {
  208. puts("With his bare hand he deflects the laser blast and whips the pistol from you!");
  209. clearbit(inven, LASER);
  210. setbit(location[position].objects, LASER);
  211. carrying -= objwt[LASER];
  212. encumber -= objcumber[LASER];
  213. }
  214. } else
  215. puts("Unfortunately, you don't have a blaster handy.");
  216. break;
  217. case DROP:
  218. case DRAW:
  219. cypher();
  220. ourtime--;
  221. break;
  222. default:
  223. puts("You don't have a chance; he is too quick.");
  224. break;
  225. }
  226. if (lifeline >= strength) {
  227. printf("You have killed the %s.\n", objsht[enemy]);
  228. if (enemy == ELF || enemy == DARK)
  229. puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!");
  230. clearbit(location[position].objects, enemy);
  231. power += 2;
  232. notes[JINXED]++;
  233. return (0);
  234. }
  235. puts("He attacks...");
  236. /* Some embellishments. */
  237. hurt = rnd(NUMOFINJURIES) - (testbit(inven, SHIELD) != 0) - (testbit(wear, MAIL) != 0) - (testbit(wear, HELM) != 0);
  238. hurt += (testbit(wear, AMULET) != 0) + (testbit(wear, MEDALION) != 0) + (testbit(wear, TALISMAN) != 0);
  239. hurt = hurt < 0 ? 0 : hurt;
  240. hurt = hurt >= NUMOFINJURIES ? NUMOFINJURIES - 1 : hurt;
  241. if (!injuries[hurt]) {
  242. injuries[hurt] = 1;
  243. printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
  244. } else
  245. puts("You emerge unscathed.");
  246. if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
  247. puts("I'm afraid you have suffered fatal injuries.");
  248. die();
  249. }
  250. goto fighton;
  251. }