potion.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: potion.c
  4. *
  5. * DESCRIPTION:
  6. * This module contains definitions and functions for handling potions.
  7. *
  8. * =============================================================================
  9. * EXPORTED VARIABLES
  10. *
  11. * potionname : The name of each potion
  12. *
  13. * =============================================================================
  14. * EXPORTED FUNCTIONS
  15. *
  16. * newpotion : Function to create a new potion with the required probabilities
  17. * quaffpotion : Function to process quaffing a potion.
  18. *
  19. * =============================================================================
  20. */
  21. #include "potion.h"
  22. #include "dungeon.h"
  23. #include "header.h"
  24. #include "itm.h"
  25. #include "monster.h"
  26. #include "player.h"
  27. #include "ularn_win.h"
  28. /* =============================================================================
  29. * Exported variables
  30. */
  31. /* name array for magic potions */
  32. char *potionname[MAXPOTION] = {" sleep",
  33. " healing",
  34. " raise level",
  35. " increase ability",
  36. " wisdom",
  37. " strength",
  38. " raise charisma",
  39. " dizziness",
  40. " learning",
  41. " gold detection",
  42. " monster detection",
  43. " forgetfulness",
  44. " water",
  45. " blindness",
  46. " confusion",
  47. " heroism",
  48. " sturdiness",
  49. " giant strength",
  50. " fire resistance",
  51. " treasure finding",
  52. " instant healing",
  53. " cure dianthroritis",
  54. " poison",
  55. " see invisible",
  56. " ",
  57. " ",
  58. " ",
  59. " ",
  60. " ",
  61. " ",
  62. " ",
  63. " ",
  64. " ",
  65. " ",
  66. " "};
  67. /* =============================================================================
  68. * Local variables
  69. */
  70. /*
  71. * Array to return a potion number created with appropriate probability
  72. * of occurrence.
  73. * Each potion appears in this array a number of times proportionate to
  74. * its probability of occurence.
  75. */
  76. #define POTION_PROB_SIZE 41
  77. static char potprob[POTION_PROB_SIZE] = {
  78. PSLEEP, PSLEEP, PHEALING, PHEALING, PHEALING, PRAISELEVEL, PINCABILITY,
  79. PINCABILITY, PWISDOM, PWISDOM, PSTRENGTH, PSTRENGTH, PCHARISMA, PCHARISMA,
  80. PDIZZINESS, PDIZZINESS, PLEARNING, PGOLDDET, PGOLDDET, PGOLDDET, PMONSTDET,
  81. PMONSTDET, PMONSTDET, PFORGETFUL, PFORGETFUL, PWATER, PWATER, PBLINDNESS,
  82. PCONFUSION, PHEROISM, PSTURDINESS, PGIANTSTR, PFIRERESIST, PTREASURE,
  83. PTREASURE, PINSTHEAL, PINSTHEAL,
  84. /* No Cure Dianthroritis */
  85. PPOISON, PPOISON, PSEEINVIS, PSEEINVIS};
  86. /* =============================================================================
  87. * Exported functions
  88. */
  89. /* =============================================================================
  90. * FUNCTION: newpotion
  91. */
  92. int newpotion(void) { return potprob[rund(POTION_PROB_SIZE)]; }
  93. /* =============================================================================
  94. * FUNCTION: quaffpotion
  95. */
  96. void quaffpotion(int pot) {
  97. int i, j;
  98. int k;
  99. /* check for within bounds */
  100. if (pot < 0 || pot >= MAXPOTION)
  101. return;
  102. if (potionknown[pot] == 0)
  103. potionknown[pot] = 1;
  104. Printf("\nYou drink a potion of %s.", &potionname[pot][1]);
  105. /*
  106. * In the switch, if no status/attr changes then use return,
  107. * else use break to get the UpdateStatusAndEffects call.
  108. */
  109. switch (pot) {
  110. case PSLEEP:
  111. Print("\n You fall asleep...");
  112. i = rnd(11) - (c[CONSTITUTION] >> 2) + 2;
  113. while (--i > 0) {
  114. parse2();
  115. nap(1000);
  116. }
  117. Print("\n.. you wake up.");
  118. return;
  119. case PHEALING:
  120. Print("\n You feel better.");
  121. if (c[HP] == c[HPMAX])
  122. /* Already fully healed, so increase max hp */
  123. raisemhp(1);
  124. else if ((c[HP] += rnd(20) + 20 + c[LEVEL]) > c[HPMAX])
  125. c[HP] = c[HPMAX];
  126. break;
  127. case PRAISELEVEL:
  128. Print("\n You feel much more skillful!");
  129. raiselevel();
  130. raisemhp(1);
  131. break;
  132. case PINCABILITY:
  133. Print("\n You feel strange for a moment.");
  134. i = ABILITY_FIRST + rund(ABILITY_COUNT);
  135. c[i]++;
  136. break;
  137. case PWISDOM:
  138. Print("\n You feel more self-confident!");
  139. c[WISDOM] += rnd(2);
  140. break;
  141. case PSTRENGTH:
  142. Print("\n Wow! You feel great!");
  143. if (c[STRENGTH] < 12)
  144. c[STRENGTH] = 12;
  145. else
  146. c[STRENGTH]++;
  147. break;
  148. case PCHARISMA:
  149. Print("\n You feel charismatic!");
  150. c[CHARISMA]++;
  151. break;
  152. case PDIZZINESS:
  153. Print("\n You become dizzy!");
  154. if (--c[STRENGTH] < 3)
  155. c[STRENGTH] = 3;
  156. break;
  157. case PLEARNING:
  158. Print("\n You feel clever!");
  159. c[INTELLIGENCE]++;
  160. break;
  161. case PGOLDDET:
  162. Print("\n You feel greedy...");
  163. nap(2000);
  164. for (i = 0; i < MAXY; i++) {
  165. for (j = 0; j < MAXX; j++)
  166. if ((item[j][i] == OGOLDPILE) || (item[j][i] == OMAXGOLD))
  167. show1cell(j, i);
  168. }
  169. showplayer();
  170. return;
  171. case PMONSTDET:
  172. for (i = 0; i < MAXY; i++) {
  173. for (j = 0; j < MAXX; j++)
  174. if (mitem[j][i].mon)
  175. show1cell(j, i);
  176. }
  177. return;
  178. case PFORGETFUL:
  179. Print("\n You stagger for a moment...");
  180. for (i = 0; i < MAXY; i++)
  181. for (j = 0; j < MAXX; j++)
  182. know[j][i] = OUNKNOWN;
  183. nap(2000);
  184. draws(0, MAXX, 0, MAXY);
  185. return;
  186. case PWATER:
  187. return;
  188. case PBLINDNESS:
  189. Print("\n You can't see anything!");
  190. c[BLINDCOUNT] += 250; /* dang, that's a long time. */
  191. /* erase the character, too! */
  192. showplayer();
  193. return;
  194. case PCONFUSION:
  195. Print("\n You feel confused.");
  196. c[CONFUSE] += 20 + rnd(9);
  197. return;
  198. case PHEROISM:
  199. Print("\n WOW! You feel fantastic!");
  200. if (c[HERO] == 0)
  201. for (i = ABILITY_FIRST; i <= ABILITY_LAST; i++)
  202. c[i] += PHEROISM_BOOST;
  203. c[HERO] += 250;
  204. break;
  205. case PSTURDINESS:
  206. Print("\n You feel healthier!");
  207. c[CONSTITUTION]++;
  208. break;
  209. case PGIANTSTR:
  210. Print("\n You now have incredible bulging muscles!");
  211. if (c[GIANTSTR] == 0)
  212. c[STREXTRA] += PGIANTSTR_BOOST;
  213. c[GIANTSTR] += 700;
  214. break;
  215. case PFIRERESIST:
  216. Print("\n You feel a chill run up your spine!");
  217. c[FIRERESISTANCE] += 1000;
  218. break;
  219. case PTREASURE:
  220. Print("\n You feel greedy...");
  221. nap(2000);
  222. for (i = 0; i < MAXY; i++) {
  223. for (j = 0; j < MAXX; j++) {
  224. k = item[j][i];
  225. if ((k == ODIAMOND) || (k == ORUBY) || (k == OEMERALD) ||
  226. (k == OMAXGOLD) || (k == OSAPPHIRE) || (k == OLARNEYE) ||
  227. (k == OGOLDPILE))
  228. show1cell(j, i);
  229. }
  230. }
  231. showplayer();
  232. return;
  233. case PINSTHEAL:
  234. c[HP] = c[HPMAX];
  235. removecurse();
  236. break;
  237. case PCUREDIANTH:
  238. Print("\n You don't seem to be affected.");
  239. return;
  240. case PPOISON:
  241. Print("\n You feel a sickness engulf you!");
  242. c[HALFDAM] += 200 + rnd(200);
  243. return;
  244. case PSEEINVIS:
  245. Print("\n You feel your vision sharpen.");
  246. c[SEEINVISIBLE] += rnd(1000) + 400;
  247. monstnamelist[INVISIBLESTALKER] = 'I';
  248. return;
  249. default:
  250. break;
  251. }
  252. /* show new stats */
  253. UpdateStatusAndEffects();
  254. return;
  255. }