home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume14 / umoria4 / part06 < prev    next >
Internet Message Format  |  1992-08-31  |  57KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v14i038:  umoria4 - single player dungeon simulation (ver. 5.5), Part06/39
  5. Message-ID: <3396@master.CNA.TEK.COM>
  6. Date: 20 Aug 92 18:02:48 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 2078
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: grabiner@math.harvard.edu (David Grabiner)
  12. Posting-number: Volume 14, Issue 38
  13. Archive-name: umoria4/Part06
  14. Supersedes: umoria3: Volume 9, Issue 55-97; Volume 10, Issue 15-17
  15. Environment: Curses, Unix, Mac, MS-DOS, Atari-ST, Amiga, VMS
  16.  
  17.  
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 6 (of 39)."
  26. # Contents:  source/creature.c util/printit/pr_monst.c
  27. # Wrapped by billr@saab on Thu Aug 20 09:11:27 1992
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'source/creature.c' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'source/creature.c'\"
  31. else
  32. echo shar: Extracting \"'source/creature.c'\" \(46325 characters\)
  33. sed "s/^X//" >'source/creature.c' <<'END_OF_FILE'
  34. X/* source/creature.c: handle monster movement and attacks
  35. X
  36. X   Copyright (c) 1989-92 James E. Wilson, Robert A. Koeneke
  37. X
  38. X   This software may be copied and distributed for educational, research, and
  39. X   not for profit purposes provided that this copyright and statement are
  40. X   included in all such copies. */
  41. X
  42. X#ifdef __TURBOC__
  43. X#include    <stdio.h>
  44. X#include    <stdlib.h>
  45. X#endif /* __TURBOC__ */
  46. X#include "config.h"
  47. X#include "constant.h"
  48. X#include "types.h"
  49. X#include "externs.h"
  50. X
  51. X#ifdef USG
  52. X#ifndef ATARIST_MWC
  53. X#include <string.h>
  54. X#else
  55. Xchar *strcat();
  56. Xchar *strcpy();
  57. X#endif
  58. X#else
  59. X#include <strings.h>
  60. X#endif
  61. X
  62. X#if defined(LINT_ARGS)
  63. Xstatic int movement_rate(int16);
  64. Xstatic int check_mon_lite(int, int);
  65. Xstatic void get_moves(int, int *);
  66. Xstatic void make_attack(int);
  67. Xstatic void make_move(int, int *, int32u *);
  68. Xstatic void mon_cast_spell(int, int *);
  69. Xstatic void mon_move(int, int32u *);
  70. X#endif
  71. X
  72. X#ifdef ATARIST_TC
  73. X/* Include this to get prototypes for standard library functions.  */
  74. X#include <stdlib.h>
  75. X#endif
  76. X
  77. X
  78. X/* Updates screen when monsters move about        -RAK-    */
  79. Xvoid update_mon(monptr)
  80. Xint monptr;
  81. X{
  82. X  register int flag;
  83. X  register cave_type *c_ptr;
  84. X  register monster_type *m_ptr;
  85. X  register creature_type *r_ptr;
  86. X#ifdef ATARIST_MWC
  87. X  int32u holder;
  88. X#endif
  89. X
  90. X  m_ptr = &m_list[monptr];
  91. X  flag = FALSE;
  92. X  if ((m_ptr->cdis <= MAX_SIGHT) &&
  93. X      !(py.flags.status & PY_BLIND) &&
  94. X      (panel_contains((int)m_ptr->fy, (int)m_ptr->fx)))
  95. X    {
  96. X      /* Wizard sight.         */
  97. X      if (wizard)
  98. X    flag = TRUE;
  99. X      /* Normal sight.         */
  100. X      else if (los(char_row, char_col, (int)m_ptr->fy, (int)m_ptr->fx))
  101. X    {
  102. X      c_ptr = &cave[m_ptr->fy][m_ptr->fx];
  103. X      r_ptr = &c_list[m_ptr->mptr];
  104. X      if (c_ptr->pl || c_ptr->tl ||
  105. X          (find_flag && m_ptr->cdis < 2 && player_light))
  106. X        {
  107. X#ifdef ATARIST_MWC
  108. X          holder = CM_INVISIBLE;
  109. X          if ((holder & r_ptr->cmove) == 0)
  110. X#else
  111. X          if ((CM_INVISIBLE & r_ptr->cmove) == 0)
  112. X#endif
  113. X        flag = TRUE;
  114. X          else if (py.flags.see_inv)
  115. X        {
  116. X          flag = TRUE;
  117. X#ifdef ATARIST_MWC
  118. X          c_recall[m_ptr->mptr].r_cmove |= holder;
  119. X#else
  120. X          c_recall[m_ptr->mptr].r_cmove |= CM_INVISIBLE;
  121. X#endif
  122. X        }
  123. X        }
  124. X      /* Infra vision.     */
  125. X      else if ((py.flags.see_infra > 0) &&
  126. X           (m_ptr->cdis <= py.flags.see_infra) &&
  127. X           (CD_INFRA & r_ptr->cdefense))
  128. X        {
  129. X          flag = TRUE;
  130. X          c_recall[m_ptr->mptr].r_cdefense |= CD_INFRA;
  131. X        }
  132. X    }
  133. X    }
  134. X  /* Light it up.     */
  135. X  if (flag)
  136. X    {
  137. X      if (!m_ptr->ml)
  138. X    {
  139. X      disturb (1, 0);
  140. X      m_ptr->ml = TRUE;
  141. X      lite_spot((int)m_ptr->fy, (int)m_ptr->fx);
  142. X      screen_change = TRUE; /* notify inven_command */
  143. X    }
  144. X    }
  145. X  /* Turn it off.     */
  146. X  else if (m_ptr->ml)
  147. X    {
  148. X      m_ptr->ml = FALSE;
  149. X      lite_spot((int)m_ptr->fy, (int)m_ptr->fx);
  150. X      screen_change = TRUE; /* notify inven_command */
  151. X    }
  152. X}
  153. X
  154. X
  155. X/* Given speed,     returns number of moves this turn.    -RAK-    */
  156. X/* NOTE: Player must always move at least once per iteration,      */
  157. X/*     a slowed player is handled by moving monsters faster     */
  158. Xstatic int movement_rate(speed)
  159. Xregister int16 speed;
  160. X{
  161. X  if (speed > 0)
  162. X    {
  163. X      if (py.flags.rest != 0)
  164. X    return 1;
  165. X      else
  166. X    return speed;
  167. X    }
  168. X  else
  169. X    {
  170. X      /* speed must be negative here */
  171. X      return ((turn % (2 - speed)) == 0);
  172. X    }
  173. X}
  174. X
  175. X
  176. X/* Makes sure a new creature gets lit up.            -CJS- */
  177. Xstatic int check_mon_lite(y, x)
  178. Xint y, x;
  179. X{
  180. X  register int monptr;
  181. X
  182. X  monptr = cave[y][x].cptr;
  183. X  if (monptr <= 1)
  184. X    return FALSE;
  185. X  else
  186. X    {
  187. X      update_mon(monptr);
  188. X      return m_list[monptr].ml;
  189. X    }
  190. X}
  191. X
  192. X
  193. X/* Choose correct directions for monster movement    -RAK-    */
  194. Xstatic void get_moves(monptr, mm)
  195. Xint monptr;
  196. Xregister int *mm;
  197. X{
  198. X  int y, ay, x, ax, move_val;
  199. X
  200. X  y = m_list[monptr].fy - char_row;
  201. X  x = m_list[monptr].fx - char_col;
  202. X  if (y < 0)
  203. X    {
  204. X      move_val = 8;
  205. X      ay = -y;
  206. X    }
  207. X  else
  208. X    {
  209. X      move_val = 0;
  210. X      ay = y;
  211. X    }
  212. X  if (x > 0)
  213. X    {
  214. X      move_val += 4;
  215. X      ax = x;
  216. X    }
  217. X  else
  218. X    ax = -x;
  219. X  /* this has the advantage of preventing the diamond maneuvre, also faster */
  220. X  if (ay > (ax << 1))
  221. X    move_val += 2;
  222. X  else if (ax > (ay << 1))
  223. X    move_val++;
  224. X  switch(move_val)
  225. X    {
  226. X    case 0:
  227. X      mm[0] = 9;
  228. X      if (ay > ax)
  229. X    {
  230. X      mm[1] = 8;
  231. X      mm[2] = 6;
  232. X      mm[3] = 7;
  233. X      mm[4] = 3;
  234. X    }
  235. X      else
  236. X    {
  237. X      mm[1] = 6;
  238. X      mm[2] = 8;
  239. X      mm[3] = 3;
  240. X      mm[4] = 7;
  241. X    }
  242. X      break;
  243. X    case 1: case 9:
  244. X      mm[0] = 6;
  245. X      if (y < 0)
  246. X    {
  247. X      mm[1] = 3;
  248. X      mm[2] = 9;
  249. X      mm[3] = 2;
  250. X      mm[4] = 8;
  251. X    }
  252. X      else
  253. X    {
  254. X      mm[1] = 9;
  255. X      mm[2] = 3;
  256. X      mm[3] = 8;
  257. X      mm[4] = 2;
  258. X    }
  259. X      break;
  260. X    case 2: case 6:
  261. X      mm[0] = 8;
  262. X      if (x < 0)
  263. X    {
  264. X      mm[1] = 9;
  265. X      mm[2] = 7;
  266. X      mm[3] = 6;
  267. X      mm[4] = 4;
  268. X    }
  269. X      else
  270. X    {
  271. X      mm[1] = 7;
  272. X      mm[2] = 9;
  273. X      mm[3] = 4;
  274. X      mm[4] = 6;
  275. X    }
  276. X      break;
  277. X    case 4:
  278. X      mm[0] = 7;
  279. X      if (ay > ax)
  280. X    {
  281. X      mm[1] = 8;
  282. X      mm[2] = 4;
  283. X      mm[3] = 9;
  284. X      mm[4] = 1;
  285. X    }
  286. X      else
  287. X    {
  288. X      mm[1] = 4;
  289. X      mm[2] = 8;
  290. X      mm[3] = 1;
  291. X      mm[4] = 9;
  292. X    }
  293. X      break;
  294. X    case 5: case 13:
  295. X      mm[0] = 4;
  296. X      if (y < 0)
  297. X    {
  298. X      mm[1] = 1;
  299. X      mm[2] = 7;
  300. X      mm[3] = 2;
  301. X      mm[4] = 8;
  302. X    }
  303. X      else
  304. X    {
  305. X      mm[1] = 7;
  306. X      mm[2] = 1;
  307. X      mm[3] = 8;
  308. X      mm[4] = 2;
  309. X    }
  310. X      break;
  311. X    case 8:
  312. X      mm[0] = 3;
  313. X      if (ay > ax)
  314. X    {
  315. X      mm[1] = 2;
  316. X      mm[2] = 6;
  317. X      mm[3] = 1;
  318. X      mm[4] = 9;
  319. X    }
  320. X      else
  321. X    {
  322. X      mm[1] = 6;
  323. X      mm[2] = 2;
  324. X      mm[3] = 9;
  325. X      mm[4] = 1;
  326. X    }
  327. X      break;
  328. X    case 10: case 14:
  329. X      mm[0] = 2;
  330. X      if (x < 0)
  331. X    {
  332. X      mm[1] = 3;
  333. X      mm[2] = 1;
  334. X      mm[3] = 6;
  335. X      mm[4] = 4;
  336. X    }
  337. X      else
  338. X    {
  339. X      mm[1] = 1;
  340. X      mm[2] = 3;
  341. X      mm[3] = 4;
  342. X      mm[4] = 6;
  343. X    }
  344. X      break;
  345. X    case 12:
  346. X      mm[0] = 1;
  347. X      if (ay > ax)
  348. X    {
  349. X      mm[1] = 2;
  350. X      mm[2] = 4;
  351. X      mm[3] = 3;
  352. X      mm[4] = 7;
  353. X    }
  354. X      else
  355. X    {
  356. X      mm[1] = 4;
  357. X      mm[2] = 2;
  358. X      mm[3] = 7;
  359. X      mm[4] = 3;
  360. X    }
  361. X      break;
  362. X    }
  363. X}
  364. X
  365. X
  366. X/* Make an attack on the player (chuckle.)        -RAK-    */
  367. Xstatic void make_attack(monptr)
  368. Xint monptr;
  369. X{
  370. X  int attype, adesc, adice, asides;
  371. X  int i, j, damage, flag, attackn, notice, visible;
  372. X  int32 gold;
  373. X  int8u *attstr;
  374. X  vtype cdesc, tmp_str, ddesc;
  375. X  register creature_type *r_ptr;
  376. X  monster_type *m_ptr;
  377. X  register struct misc *p_ptr;
  378. X  register struct flags *f_ptr;
  379. X  register inven_type *i_ptr;
  380. X#ifdef ATARIST_MWC
  381. X  int32u holder;
  382. X#endif
  383. X
  384. X  if (death)  /* don't beat a dead body! */
  385. X    return;
  386. X
  387. X  m_ptr = &m_list[monptr];
  388. X  r_ptr = &c_list[m_ptr->mptr];
  389. X  if (!m_ptr->ml)
  390. X    (void) strcpy(cdesc, "It ");
  391. X  else
  392. X    (void) sprintf(cdesc, "The %s ", r_ptr->name);
  393. X  /* For "DIED_FROM" string       */
  394. X#ifdef ATARIST_MWC
  395. X  holder = CM_WIN;
  396. X  if (holder & r_ptr->cmove)
  397. X#else
  398. X  if (CM_WIN & r_ptr->cmove)
  399. X#endif
  400. X    (void) sprintf(ddesc, "The %s", r_ptr->name);
  401. X  else if (is_a_vowel (r_ptr->name[0]))
  402. X    (void) sprintf(ddesc, "an %s", r_ptr->name);
  403. X  else
  404. X    (void) sprintf (ddesc, "a %s", r_ptr->name);
  405. X  /* End DIED_FROM           */
  406. X
  407. X  attackn = 0;
  408. X  attstr = r_ptr->damage;
  409. X  while ((*attstr != 0) && !death)
  410. X    {
  411. X      attype = monster_attacks[*attstr].attack_type;
  412. X      adesc = monster_attacks[*attstr].attack_desc;
  413. X      adice = monster_attacks[*attstr].attack_dice;
  414. X      asides = monster_attacks[*attstr].attack_sides;
  415. X      attstr++;
  416. X      flag = FALSE;
  417. X      if ((py.flags.protevil > 0) && (r_ptr->cdefense & CD_EVIL) &&
  418. X      ((py.misc.lev + 1) > r_ptr->level))
  419. X    {
  420. X      if (m_ptr->ml)
  421. X        c_recall[m_ptr->mptr].r_cdefense |= CD_EVIL;
  422. X      attype = 99;
  423. X      adesc = 99;
  424. X    }
  425. X      p_ptr = &py.misc;
  426. X      switch(attype)
  427. X    {
  428. X    case 1:          /*Normal attack  */
  429. X      if (test_hit(60, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  430. X               CLA_MISC_HIT))
  431. X        flag = TRUE;
  432. X      break;
  433. X    case 2:          /*Lose Strength*/
  434. X      if (test_hit(-3, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  435. X               CLA_MISC_HIT))
  436. X        flag = TRUE;
  437. X      break;
  438. X    case 3:          /*Confusion attack*/
  439. X      if (test_hit(10, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  440. X               CLA_MISC_HIT))
  441. X        flag = TRUE;
  442. X      break;
  443. X    case 4:          /*Fear attack    */
  444. X      if (test_hit(10, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  445. X               CLA_MISC_HIT))
  446. X        flag = TRUE;
  447. X      break;
  448. X    case 5:          /*Fire attack    */
  449. X      if (test_hit(10, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  450. X               CLA_MISC_HIT))
  451. X        flag = TRUE;
  452. X      break;
  453. X    case 6:          /*Acid attack    */
  454. X      if (test_hit(0, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  455. X               CLA_MISC_HIT))
  456. X        flag = TRUE;
  457. X      break;
  458. X    case 7:          /*Cold attack    */
  459. X      if (test_hit(10, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  460. X               CLA_MISC_HIT))
  461. X        flag = TRUE;
  462. X      break;
  463. X    case 8:          /*Lightning attack*/
  464. X      if (test_hit(10, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  465. X               CLA_MISC_HIT))
  466. X        flag = TRUE;
  467. X      break;
  468. X    case 9:          /*Corrosion attack*/
  469. X      if (test_hit(0, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  470. X               CLA_MISC_HIT))
  471. X        flag = TRUE;
  472. X      break;
  473. X    case 10:      /*Blindness attack*/
  474. X      if (test_hit(2, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  475. X               CLA_MISC_HIT))
  476. X        flag = TRUE;
  477. X      break;
  478. X    case 11:      /*Paralysis attack*/
  479. X      if (test_hit(2, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  480. X               CLA_MISC_HIT))
  481. X        flag = TRUE;
  482. X      break;
  483. X    case 12:      /*Steal Money    */
  484. X      if ((test_hit(5, (int)r_ptr->level, 0, (int)py.misc.lev,
  485. X            CLA_MISC_HIT))
  486. X          && (py.misc.au > 0))
  487. X        flag = TRUE;
  488. X      break;
  489. X    case 13:      /*Steal Object   */
  490. X      if ((test_hit(2, (int)r_ptr->level, 0, (int)py.misc.lev,
  491. X            CLA_MISC_HIT))
  492. X          && (inven_ctr > 0))
  493. X        flag = TRUE;
  494. X      break;
  495. X    case 14:      /*Poison           */
  496. X      if (test_hit(5, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  497. X               CLA_MISC_HIT))
  498. X        flag = TRUE;
  499. X      break;
  500. X    case 15:      /*Lose dexterity*/
  501. X      if (test_hit(0, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  502. X               CLA_MISC_HIT))
  503. X        flag = TRUE;
  504. X      break;
  505. X    case 16:      /*Lose constitution*/
  506. X      if (test_hit(0, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  507. X               CLA_MISC_HIT))
  508. X        flag = TRUE;
  509. X      break;
  510. X    case 17:      /*Lose intelligence*/
  511. X      if (test_hit(2, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  512. X               CLA_MISC_HIT))
  513. X        flag = TRUE;
  514. X      break;
  515. X    case 18:      /*Lose wisdom*/
  516. X      if (test_hit(2, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  517. X               CLA_MISC_HIT))
  518. X        flag = TRUE;
  519. X      break;
  520. X    case 19:      /*Lose experience*/
  521. X      if (test_hit(5, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  522. X               CLA_MISC_HIT))
  523. X        flag = TRUE;
  524. X      break;
  525. X    case 20:      /*Aggravate monsters*/
  526. X      flag = TRUE;
  527. X      break;
  528. X    case 21:      /*Disenchant      */
  529. X      if (test_hit(20, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  530. X               CLA_MISC_HIT))
  531. X        flag = TRUE;
  532. X      break;
  533. X    case 22:      /*Eat food      */
  534. X      if (test_hit(5, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  535. X               CLA_MISC_HIT))
  536. X        flag = TRUE;
  537. X      break;
  538. X    case 23:      /*Eat light      */
  539. X      if (test_hit(5, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  540. X               CLA_MISC_HIT))
  541. X        flag = TRUE;
  542. X      break;
  543. X    case 24:      /*Eat charges      */
  544. X      if ((test_hit(15, (int)r_ptr->level, 0, p_ptr->pac+p_ptr->ptoac,
  545. X            CLA_MISC_HIT)) &&
  546. X          (inven_ctr > 0))    /* check to make sure an object exists */
  547. X        flag = TRUE;
  548. X      break;
  549. X    case 99:
  550. X      flag = TRUE;
  551. X      break;
  552. X    default:
  553. X      break;
  554. X    }
  555. X      if (flag)
  556. X    {
  557. X      /* can not strcat to cdesc because the creature may have
  558. X         multiple attacks */
  559. X      disturb (1, 0);
  560. X      (void) strcpy(tmp_str, cdesc);
  561. X      switch(adesc)
  562. X        {
  563. X        case 1: msg_print(strcat(tmp_str, "hits you.")); break;
  564. X        case 2: msg_print(strcat(tmp_str, "bites you.")); break;
  565. X        case 3: msg_print(strcat(tmp_str, "claws you.")); break;
  566. X        case 4: msg_print(strcat(tmp_str, "stings you.")); break;
  567. X        case 5: msg_print(strcat(tmp_str, "touches you.")); break;
  568. X#if 0
  569. X        case 6: msg_print(strcat(tmp_str, "kicks you.")); break;
  570. X#endif
  571. X        case 7: msg_print(strcat(tmp_str, "gazes at you.")); break;
  572. X        case 8: msg_print(strcat(tmp_str, "breathes on you.")); break;
  573. X        case 9: msg_print(strcat(tmp_str, "spits on you.")); break;
  574. X        case 10: msg_print(strcat(tmp_str,"makes a horrible wail."));break;
  575. X#if 0
  576. X        case 11: msg_print(strcat(tmp_str, "embraces you.")); break;
  577. X#endif
  578. X        case 12: msg_print(strcat(tmp_str, "crawls on you.")); break;
  579. X        case 13:
  580. X          msg_print(strcat(tmp_str, "releases a cloud of spores.")); break;
  581. X        case 14: msg_print(strcat(tmp_str, "begs you for money.")); break;
  582. X        case 15: msg_print("You've been slimed!"); break;
  583. X        case 16: msg_print(strcat(tmp_str, "crushes you.")); break;
  584. X        case 17: msg_print(strcat(tmp_str, "tramples you.")); break;
  585. X        case 18: msg_print(strcat(tmp_str, "drools on you.")); break;
  586. X        case 19:
  587. X          switch(randint(9))
  588. X        {
  589. X        case 1: msg_print(strcat(tmp_str, "insults you!")); break;
  590. X        case 2:
  591. X          msg_print(strcat(tmp_str, "insults your mother!")); break;
  592. X        case 3:
  593. X          msg_print(strcat(tmp_str, "gives you the finger!")); break;
  594. X        case 4: msg_print(strcat(tmp_str, "humiliates you!")); break;
  595. X        case 5: msg_print(strcat(tmp_str, "wets on your leg!")); break;
  596. X        case 6: msg_print(strcat(tmp_str, "defiles you!")); break;
  597. X        case 7: msg_print(strcat(tmp_str, "dances around you!"));break;
  598. X        case 8:
  599. X          msg_print(strcat(tmp_str, "makes obscene gestures!")); break;
  600. X        case 9: msg_print(strcat(tmp_str, "moons you!!!")); break;
  601. X        }
  602. X          break;
  603. X        case 99: msg_print(strcat(tmp_str, "is repelled.")); break;
  604. X        default: break;
  605. X        }
  606. X
  607. X      notice = TRUE;
  608. X      /* always fail to notice attack if creature invisible, set notice
  609. X         and visible here since creature may be visible when attacking
  610. X         and then teleport afterwards (becoming effectively invisible) */
  611. X      if (!m_ptr->ml)
  612. X        {
  613. X          visible = FALSE;
  614. X          notice = FALSE;
  615. X        }
  616. X      else
  617. X        visible = TRUE;
  618. X
  619. X      damage = damroll (adice, asides);
  620. X      switch(attype)
  621. X        {
  622. X        case 1:    /*Normal attack    */
  623. X          /* round half-way case down */
  624. X          damage -= ((p_ptr->pac+p_ptr->ptoac) * damage) / 200;
  625. X          take_hit(damage, ddesc);
  626. X          break;
  627. X        case 2:    /*Lose Strength*/
  628. X          take_hit(damage, ddesc);
  629. X          if (py.flags.sustain_str)
  630. X        msg_print("You feel weaker for a moment, but it passes.");
  631. X          else if (randint(2) == 1)
  632. X        {
  633. X          msg_print("You feel weaker.");
  634. X          (void) dec_stat (A_STR);
  635. X        }
  636. X          else
  637. X        notice = FALSE;
  638. X          break;
  639. X        case 3:    /*Confusion attack*/
  640. X          f_ptr = &py.flags;
  641. X          take_hit(damage, ddesc);
  642. X          if (randint(2) == 1)
  643. X        {
  644. X          if (f_ptr->confused < 1)
  645. X            {
  646. X              msg_print("You feel confused.");
  647. X              f_ptr->confused += randint((int)r_ptr->level);
  648. X            }
  649. X          else
  650. X            notice = FALSE;
  651. X          f_ptr->confused += 3;
  652. X        }
  653. X          else
  654. X        notice = FALSE;
  655. X          break;
  656. X        case 4:    /*Fear attack    */
  657. X          f_ptr = &py.flags;
  658. X          take_hit(damage, ddesc);
  659. X          if (player_saves())
  660. X        msg_print("You resist the effects!");
  661. X          else if (f_ptr->afraid < 1)
  662. X        {
  663. X          msg_print("You are suddenly afraid!");
  664. X          f_ptr->afraid += 3 + randint((int)r_ptr->level);
  665. X        }
  666. X          else
  667. X        {
  668. X          f_ptr->afraid += 3;
  669. X          notice = FALSE;
  670. X        }
  671. X          break;
  672. X        case 5:    /*Fire attack    */
  673. X          msg_print("You are enveloped in flames!");
  674. X          fire_dam(damage, ddesc);
  675. X          break;
  676. X        case 6:    /*Acid attack    */
  677. X          msg_print("You are covered in acid!");
  678. X          acid_dam(damage, ddesc);
  679. X          break;
  680. X        case 7:    /*Cold attack    */
  681. X          msg_print("You are covered with frost!");
  682. X          cold_dam(damage, ddesc);
  683. X          break;
  684. X        case 8:    /*Lightning attack*/
  685. X          msg_print("Lightning strikes you!");
  686. X          light_dam(damage, ddesc);
  687. X          break;
  688. X        case 9:    /*Corrosion attack*/
  689. X          msg_print("A stinging red gas swirls about you.");
  690. X          corrode_gas(ddesc);
  691. X          take_hit(damage, ddesc);
  692. X          break;
  693. X        case 10:    /*Blindness attack*/
  694. X          f_ptr = &py.flags;
  695. X          take_hit(damage, ddesc);
  696. X          if (f_ptr->blind < 1)
  697. X        {
  698. X          f_ptr->blind += 10 + randint((int)r_ptr->level);
  699. X          msg_print("Your eyes begin to sting.");
  700. X        }
  701. X          else
  702. X        {
  703. X          f_ptr->blind += 5;
  704. X          notice = FALSE;
  705. X        }
  706. X          break;
  707. X        case 11:    /*Paralysis attack*/
  708. X          f_ptr = &py.flags;
  709. X          take_hit(damage, ddesc);
  710. X          if (player_saves())
  711. X        msg_print("You resist the effects!");
  712. X          else if (f_ptr->paralysis < 1)
  713. X        {
  714. X          if (f_ptr->free_act)
  715. X            msg_print("You are unaffected.");
  716. X          else
  717. X            {
  718. X              f_ptr->paralysis = randint((int)r_ptr->level) + 3;
  719. X              msg_print("You are paralyzed.");
  720. X            }
  721. X        }
  722. X          else
  723. X        notice = FALSE;
  724. X          break;
  725. X        case 12:    /*Steal Money      */
  726. X          if ((py.flags.paralysis < 1) &&
  727. X          (randint(124) < py.stats.use_stat[A_DEX]))
  728. X        msg_print("You quickly protect your money pouch!");
  729. X          else
  730. X        {
  731. X          gold = (p_ptr->au/10) + randint(25);
  732. X          if (gold > p_ptr->au)
  733. X            p_ptr->au = 0;
  734. X          else
  735. X            p_ptr->au -= gold;
  736. X          msg_print("Your purse feels lighter.");
  737. X          prt_gold();
  738. X        }
  739. X          if (randint(2) == 1)
  740. X        {
  741. X          msg_print("There is a puff of smoke!");
  742. X          teleport_away(monptr, MAX_SIGHT);
  743. X        }
  744. X          break;
  745. X        case 13:    /*Steal Object     */
  746. X          if ((py.flags.paralysis < 1) &&
  747. X          (randint(124) < py.stats.use_stat[A_DEX]))
  748. X        msg_print("You grab hold of your backpack!");
  749. X          else
  750. X        {
  751. X          i = randint(inven_ctr) - 1;
  752. X          inven_destroy(i);
  753. X          msg_print("Your backpack feels lighter.");
  754. X        }
  755. X          if (randint(2) == 1)
  756. X        {
  757. X          msg_print("There is a puff of smoke!");
  758. X          teleport_away(monptr, MAX_SIGHT);
  759. X        }
  760. X          break;
  761. X        case 14:    /*Poison     */
  762. X          f_ptr = &py.flags;
  763. X          take_hit(damage, ddesc);
  764. X          msg_print("You feel very sick.");
  765. X          f_ptr->poisoned += randint((int)r_ptr->level)+5;
  766. X          break;
  767. X        case 15:    /*Lose dexterity */
  768. X          f_ptr = &py.flags;
  769. X          take_hit(damage, ddesc);
  770. X          if (f_ptr->sustain_dex)
  771. X        msg_print("You feel clumsy for a moment, but it passes.");
  772. X          else
  773. X        {
  774. X          msg_print("You feel more clumsy.");
  775. X          (void) dec_stat (A_DEX);
  776. X        }
  777. X          break;
  778. X        case 16:    /*Lose constitution */
  779. X          f_ptr = &py.flags;
  780. X          take_hit(damage, ddesc);
  781. X          if (f_ptr->sustain_con)
  782. X        msg_print("Your body resists the effects of the disease.");
  783. X          else
  784. X        {
  785. X          msg_print("Your health is damaged!");
  786. X          (void) dec_stat (A_CON);
  787. X        }
  788. X          break;
  789. X        case 17:    /*Lose intelligence */
  790. X          f_ptr = &py.flags;
  791. X          take_hit(damage, ddesc);
  792. X          msg_print("You have trouble thinking clearly.");
  793. X          if (f_ptr->sustain_int)
  794. X        msg_print("But your mind quickly clears.");
  795. X          else
  796. X        (void) dec_stat (A_INT);
  797. X          break;
  798. X        case 18:    /*Lose wisdom       */
  799. X          f_ptr = &py.flags;
  800. X          take_hit(damage, ddesc);
  801. X          if (f_ptr->sustain_wis)
  802. X        msg_print("Your wisdom is sustained.");
  803. X          else
  804. X        {
  805. X          msg_print("Your wisdom is drained.");
  806. X          (void) dec_stat (A_WIS);
  807. X        }
  808. X          break;
  809. X        case 19:    /*Lose experience  */
  810. X          msg_print("You feel your life draining away!");
  811. X          lose_exp(damage + (py.misc.exp / 100)*MON_DRAIN_LIFE);
  812. X          break;
  813. X        case 20:    /*Aggravate monster*/
  814. X          (void) aggravate_monster(20);
  815. X          break;
  816. X        case 21:    /*Disenchant       */
  817. X          flag = FALSE;
  818. X          switch(randint(7))
  819. X        {
  820. X        case 1: i = INVEN_WIELD; break;
  821. X        case 2: i = INVEN_BODY;     break;
  822. X        case 3: i = INVEN_ARM;     break;
  823. X        case 4: i = INVEN_OUTER; break;
  824. X        case 5: i = INVEN_HANDS; break;
  825. X        case 6: i = INVEN_HEAD;     break;
  826. X        case 7: i = INVEN_FEET;     break;
  827. X        }
  828. X          i_ptr = &inventory[i];
  829. X          if (i_ptr->tohit > 0)
  830. X        {
  831. X          i_ptr->tohit -= randint(2);
  832. X          /* don't send it below zero */
  833. X          if (i_ptr->tohit < 0)
  834. X            i_ptr->tohit = 0;
  835. X          flag = TRUE;
  836. X        }
  837. X          if (i_ptr->todam > 0)
  838. X        {
  839. X          i_ptr->todam -= randint(2);
  840. X          /* don't send it below zero */
  841. X          if (i_ptr->todam < 0)
  842. X            i_ptr->todam = 0;
  843. X          flag = TRUE;
  844. X        }
  845. X          if (i_ptr->toac > 0)
  846. X        {
  847. X          i_ptr->toac  -= randint(2);
  848. X          /* don't send it below zero */
  849. X          if (i_ptr->toac < 0)
  850. X            i_ptr->toac = 0;
  851. X          flag = TRUE;
  852. X        }
  853. X          if (flag)
  854. X        {
  855. X          msg_print("There is a static feeling in the air.");
  856. X          calc_bonuses ();
  857. X        }
  858. X          else
  859. X        notice = FALSE;
  860. X          break;
  861. X        case 22:    /*Eat food       */
  862. X          if (find_range(TV_FOOD, TV_NEVER, &i, &j))
  863. X        {
  864. X          inven_destroy(i);
  865. X          msg_print ("It got at your rations!");
  866. X        }
  867. X          else
  868. X        notice = FALSE;
  869. X          break;
  870. X        case 23:    /*Eat light       */
  871. X          i_ptr = &inventory[INVEN_LIGHT];
  872. X          if (i_ptr->p1 > 0)
  873. X        {
  874. X          i_ptr->p1 -= (250 + randint(250));
  875. X          if (i_ptr->p1 < 1)  i_ptr->p1 = 1;
  876. X          if (py.flags.blind < 1)
  877. X            msg_print("Your light dims.");
  878. X          else
  879. X            notice = FALSE;
  880. X        }
  881. X          else
  882. X        notice = FALSE;
  883. X          break;
  884. X        case 24:    /*Eat charges      */
  885. X          i = randint(inven_ctr) - 1;
  886. X          j = r_ptr->level;
  887. X          i_ptr = &inventory[i];
  888. X          if (((i_ptr->tval == TV_STAFF) || (i_ptr->tval == TV_WAND))
  889. X          && (i_ptr->p1 > 0))
  890. X        {
  891. X          m_ptr->hp += j*i_ptr->p1;
  892. X          i_ptr->p1 = 0;
  893. X          if (! known2_p (i_ptr))
  894. X            add_inscribe (i_ptr, ID_EMPTY);
  895. X          msg_print("Energy drains from your pack!");
  896. X        }
  897. X          else
  898. X        notice = FALSE;
  899. X          break;
  900. X        case 99:
  901. X          notice = FALSE;
  902. X          break;
  903. X        default:
  904. X          notice = FALSE;
  905. X          break;
  906. X        }
  907. X
  908. X      /* Moved here from mon_move, so that monster only confused if it
  909. X         actually hits.  A monster that has been repelled has not hit
  910. X         the player, so it should not be confused.  */
  911. X      if (py.flags.confuse_monster && adesc != 99)
  912. X        {
  913. X          msg_print("Your hands stop glowing.");
  914. X          py.flags.confuse_monster = FALSE;
  915. X          if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  916. X          (CD_NO_SLEEP & r_ptr->cdefense))
  917. X        (void) sprintf(tmp_str, "%sis unaffected.", cdesc);
  918. X          else
  919. X        {
  920. X          (void) sprintf(tmp_str, "%sappears confused.", cdesc);
  921. X          m_ptr->confused = TRUE;
  922. X        }
  923. X          msg_print(tmp_str);
  924. X          if (visible && !death && randint(4) == 1)
  925. X        c_recall[m_ptr->mptr].r_cdefense |= r_ptr->cdefense &
  926. X          CD_NO_SLEEP;
  927. X        }
  928. X
  929. X      /* increase number of attacks if notice true, or if visible and had
  930. X         previously noticed the attack (in which case all this does is
  931. X         help player learn damage), note that in the second case do
  932. X         not increase attacks if creature repelled (no damage done) */
  933. X      if ((notice ||
  934. X           (visible && c_recall[m_ptr->mptr].r_attacks[attackn] != 0 &&
  935. X        attype != 99))
  936. X          && c_recall[m_ptr->mptr].r_attacks[attackn] < MAX_UCHAR)
  937. X        c_recall[m_ptr->mptr].r_attacks[attackn]++;
  938. X      if (death && c_recall[m_ptr->mptr].r_deaths < MAX_SHORT)
  939. X        c_recall[m_ptr->mptr].r_deaths++;
  940. X    }
  941. X      else
  942. X    {
  943. X      if ((adesc >= 1 && adesc <= 3) || (adesc == 6))
  944. X        {
  945. X          disturb (1, 0);
  946. X          (void) strcpy(tmp_str, cdesc);
  947. X          msg_print(strcat(tmp_str, "misses you."));
  948. X        }
  949. X    }
  950. X      if (attackn < MAX_MON_NATTACK-1)
  951. X    attackn++;
  952. X      else
  953. X    break;
  954. X    }
  955. X}
  956. X
  957. X
  958. X/* Make the move if possible, five choices        -RAK-    */
  959. Xstatic void make_move(monptr, mm, rcmove)
  960. Xint monptr;
  961. Xint *mm;
  962. Xint32u *rcmove;
  963. X{
  964. X  int i, newy, newx, do_turn, do_move, stuck_door;
  965. X  int32u movebits;
  966. X  register cave_type *c_ptr;
  967. X  register monster_type *m_ptr;
  968. X  register inven_type *t_ptr;
  969. X#ifdef ATARIST_MWC
  970. X  int32u holder;
  971. X#endif
  972. X
  973. X  i = 0;
  974. X  do_turn = FALSE;
  975. X  do_move = FALSE;
  976. X  m_ptr = &m_list[monptr];
  977. X  movebits = c_list[m_ptr->mptr].cmove;
  978. X  do
  979. X    {
  980. X      /* Get new position        */
  981. X      newy = m_ptr->fy;
  982. X      newx = m_ptr->fx;
  983. X      (void) mmove(mm[i], &newy, &newx);
  984. X      c_ptr = &cave[newy][newx];
  985. X      if (c_ptr->fval != BOUNDARY_WALL)
  986. X    {
  987. X      /* Floor is open?           */
  988. X      if (c_ptr->fval <= MAX_OPEN_SPACE)
  989. X        do_move = TRUE;
  990. X      /* Creature moves through walls? */
  991. X#ifdef ATARIST_MWC
  992. X      else if (movebits & (holder = CM_PHASE))
  993. X#else
  994. X      else if (movebits & CM_PHASE)
  995. X#endif
  996. X        {
  997. X          do_move = TRUE;
  998. X#ifdef ATARIST_MWC
  999. X          *rcmove |= holder;
  1000. X#else
  1001. X          *rcmove |= CM_PHASE;
  1002. X#endif
  1003. X        }
  1004. X      /* Creature can open doors?       */
  1005. X      else if (c_ptr->tptr != 0)
  1006. X        {
  1007. X          t_ptr = &t_list[c_ptr->tptr];
  1008. X#ifdef ATARIST_MWC
  1009. X          if (movebits & (holder = CM_OPEN_DOOR))
  1010. X#else
  1011. X          if (movebits & CM_OPEN_DOOR)
  1012. X#endif
  1013. X        {     /* Creature can open doors.             */
  1014. X          stuck_door = FALSE;
  1015. X          if (t_ptr->tval == TV_CLOSED_DOOR)
  1016. X            {
  1017. X              do_turn = TRUE;
  1018. X              if (t_ptr->p1 == 0)        /* Closed doors     */
  1019. X            do_move = TRUE;
  1020. X              else if (t_ptr->p1 > 0)           /* Locked doors    */
  1021. X            {
  1022. X              if (randint((m_ptr->hp+1)*(50+t_ptr->p1)) <
  1023. X                  40*(m_ptr->hp-10-t_ptr->p1))
  1024. X                t_ptr->p1 = 0;
  1025. X            }
  1026. X              else if (t_ptr->p1 < 0)           /* Stuck doors    */
  1027. X            {
  1028. X              if (randint((m_ptr->hp+1)*(50-t_ptr->p1)) <
  1029. X                  40*(m_ptr->hp-10+t_ptr->p1))
  1030. X                {
  1031. X                  msg_print("You hear a door burst open!");
  1032. X                  disturb (1, 0);
  1033. X                  stuck_door = TRUE;
  1034. X                  do_move = TRUE;
  1035. X                }
  1036. X            }
  1037. X            }
  1038. X          else if (t_ptr->tval == TV_SECRET_DOOR)
  1039. X            {
  1040. X              do_turn = TRUE;
  1041. X              do_move = TRUE;
  1042. X            }
  1043. X          if (do_move)
  1044. X            {
  1045. X              invcopy(t_ptr, OBJ_OPEN_DOOR);
  1046. X              if (stuck_door) /* 50% chance of breaking door */
  1047. X            t_ptr->p1 = 1 - randint(2);
  1048. X              c_ptr->fval = CORR_FLOOR;
  1049. X              lite_spot(newy, newx);
  1050. X#ifdef ATARIST_MWC
  1051. X              *rcmove |= holder;
  1052. X#else
  1053. X              *rcmove |= CM_OPEN_DOOR;
  1054. X#endif
  1055. X              do_move = FALSE;
  1056. X            }
  1057. X        }
  1058. X          else
  1059. X        {     /* Creature can not open doors, must bash them   */
  1060. X          if (t_ptr->tval == TV_CLOSED_DOOR)
  1061. X            {
  1062. X              do_turn = TRUE;
  1063. X              if (randint((m_ptr->hp+1)*(80+abs(t_ptr->p1))) <
  1064. X              40*(m_ptr->hp-20-abs(t_ptr->p1)))
  1065. X            {
  1066. X              invcopy(t_ptr, OBJ_OPEN_DOOR);
  1067. X              /* 50% chance of breaking door */
  1068. X              t_ptr->p1 = 1 - randint(2);
  1069. X              c_ptr->fval = CORR_FLOOR;
  1070. X              lite_spot(newy, newx);
  1071. X              msg_print ("You hear a door burst open!");
  1072. X              disturb (1, 0);
  1073. X            }
  1074. X            }
  1075. X        }
  1076. X        }
  1077. X      /* Glyph of warding present?       */
  1078. X      if (do_move && (c_ptr->tptr != 0) &&
  1079. X          (t_list[c_ptr->tptr].tval == TV_VIS_TRAP) &&
  1080. X          (t_list[c_ptr->tptr].subval == 99))
  1081. X        {
  1082. X          if (randint(OBJ_RUNE_PROT) < c_list[m_ptr->mptr].level)
  1083. X        {
  1084. X          if ((newy==char_row) && (newx==char_col))
  1085. X            msg_print("The rune of protection is broken!");
  1086. X          (void) delete_object(newy, newx);
  1087. X        }
  1088. X          else
  1089. X        {
  1090. X          do_move = FALSE;
  1091. X          /* If the creature moves only to attack, */
  1092. X          /* don't let it move if the glyph prevents */
  1093. X          /* it from attacking */
  1094. X          if (movebits & CM_ATTACK_ONLY)
  1095. X            do_turn = TRUE;
  1096. X        }
  1097. X        }
  1098. X      /* Creature has attempted to move on player?       */
  1099. X      if (do_move)
  1100. X        if (c_ptr->cptr == 1)
  1101. X          {
  1102. X        /* if the monster is not lit, must call update_mon, it may
  1103. X           be faster than character, and hence could have just
  1104. X           moved next to character this same turn */
  1105. X        if (!m_ptr->ml)
  1106. X          update_mon(monptr);
  1107. X        make_attack(monptr);
  1108. X        do_move = FALSE;
  1109. X        do_turn = TRUE;
  1110. X          }
  1111. X      /* Creature is attempting to move on other creature?       */
  1112. X        else if ((c_ptr->cptr > 1) &&
  1113. X             ((newy != m_ptr->fy) ||
  1114. X              (newx != m_ptr->fx)))
  1115. X          {
  1116. X        /* Creature eats other creatures?     */
  1117. X#ifdef ATARIST_MWC
  1118. X        if ((movebits & (holder = CM_EATS_OTHER)) &&
  1119. X#else
  1120. X        if ((movebits & CM_EATS_OTHER) &&
  1121. X#endif
  1122. X            (c_list[m_ptr->mptr].mexp >=
  1123. X             c_list[m_list[c_ptr->cptr].mptr].mexp))
  1124. X          {
  1125. X            if (m_list[c_ptr->cptr].ml)
  1126. X#ifdef ATARIST_MWC
  1127. X              *rcmove |= holder;
  1128. X#else
  1129. X              *rcmove |= CM_EATS_OTHER;
  1130. X#endif
  1131. X            /* It ate an already processed monster. Handle normally. */
  1132. X            if (monptr < c_ptr->cptr)
  1133. X              delete_monster((int) c_ptr->cptr);
  1134. X            /* If it eats this monster, an already processed monster
  1135. X               will take its place, causing all kinds of havoc.  Delay
  1136. X               the kill a bit. */
  1137. X            else
  1138. X              fix1_delete_monster((int) c_ptr->cptr);
  1139. X          }
  1140. X        else
  1141. X          do_move = FALSE;
  1142. X          }
  1143. X      /* Creature has been allowed move.     */
  1144. X      if (do_move)
  1145. X        {
  1146. X          /* Pick up or eat an object           */
  1147. X#ifdef ATARIST_MWC
  1148. X          if (movebits & (holder = CM_PICKS_UP))
  1149. X#else
  1150. X          if (movebits & CM_PICKS_UP)
  1151. X#endif
  1152. X        {
  1153. X          c_ptr = &cave[newy][newx];
  1154. X
  1155. X          if ((c_ptr->tptr != 0)
  1156. X              && (t_list[c_ptr->tptr].tval <= TV_MAX_OBJECT))
  1157. X            {
  1158. X#ifdef ATARIST_MWC
  1159. X              *rcmove |= holder;
  1160. X#else
  1161. X              *rcmove |= CM_PICKS_UP;
  1162. X#endif
  1163. X              (void) delete_object(newy, newx);
  1164. X            }
  1165. X        }
  1166. X          /* Move creature record               */
  1167. X          move_rec((int)m_ptr->fy, (int)m_ptr->fx, newy, newx);
  1168. X          if (m_ptr->ml)
  1169. X        {
  1170. X          m_ptr->ml = FALSE;
  1171. X          lite_spot ((int)m_ptr->fy, (int)m_ptr->fx);
  1172. X        }
  1173. X          m_ptr->fy = newy;
  1174. X          m_ptr->fx = newx;
  1175. X          m_ptr->cdis = distance (char_row, char_col, newy, newx);
  1176. X          do_turn = TRUE;
  1177. X        }
  1178. X    }
  1179. X      i++;
  1180. X      /* Up to 5 attempts at moving,   give up.      */
  1181. X    }
  1182. X  while ((!do_turn) && (i < 5));
  1183. X}
  1184. X
  1185. X
  1186. X/* Creatures can cast spells too.  (Dragon Breath)    -RAK-    */
  1187. X/* cast_spell = true if creature changes position    */
  1188. X/* took_turn  = true if creature casts a spell        */
  1189. Xstatic void mon_cast_spell(monptr, took_turn)
  1190. Xint monptr;
  1191. Xint *took_turn;
  1192. X{
  1193. X  int32u i;
  1194. X  int y, x, chance, thrown_spell, r1;
  1195. X  register int k;
  1196. X  int spell_choice[30];
  1197. X  vtype cdesc, outval, ddesc;
  1198. X  register monster_type *m_ptr;
  1199. X  register creature_type *r_ptr;
  1200. X#ifdef ATARIST_MWC
  1201. X  int32u holder;
  1202. X#endif
  1203. X
  1204. X  if (death)
  1205. X    return;
  1206. X
  1207. X  m_ptr = &m_list[monptr];
  1208. X  r_ptr = &c_list[m_ptr->mptr];
  1209. X  chance = (int)(r_ptr->spells & CS_FREQ);
  1210. X  /* 1 in x chance of casting spell           */
  1211. X  if (randint(chance) != 1)
  1212. X    *took_turn    = FALSE;
  1213. X  /* Must be within certain range           */
  1214. X  else if (m_ptr->cdis > MAX_SPELL_DIS)
  1215. X    *took_turn    = FALSE;
  1216. X  /* Must have unobstructed Line-Of-Sight       */
  1217. X  else if (!los(char_row, char_col, (int)m_ptr->fy, (int)m_ptr->fx))
  1218. X    *took_turn    = FALSE;
  1219. X  else    /* Creature is going to cast a spell     */
  1220. X    {
  1221. X      *took_turn  = TRUE;
  1222. X      /* Check to see if monster should be lit. */
  1223. X      update_mon (monptr);
  1224. X      /* Describe the attack                   */
  1225. X      if (m_ptr->ml)
  1226. X    (void) sprintf(cdesc, "The %s ", r_ptr->name);
  1227. X      else
  1228. X    (void) strcpy(cdesc, "It ");
  1229. X      /* For "DIED_FROM" string     */
  1230. X#ifdef ATARIST_MWC
  1231. X      holder = CM_WIN;
  1232. X      if (holder & r_ptr->cmove)
  1233. X#else
  1234. X      if (CM_WIN & r_ptr->cmove)
  1235. X#endif
  1236. X    (void) sprintf(ddesc, "The %s", r_ptr->name);
  1237. X      else if (is_a_vowel (r_ptr->name[0]))
  1238. X    (void) sprintf (ddesc, "an %s", r_ptr->name);
  1239. X      else
  1240. X    (void) sprintf(ddesc, "a %s", r_ptr->name);
  1241. X      /* End DIED_FROM               */
  1242. X
  1243. X      /* Extract all possible spells into spell_choice */
  1244. X#ifdef ATARIST_MWC
  1245. X      holder = ~CS_FREQ;
  1246. X      i = (r_ptr->spells & holder);
  1247. X#else
  1248. X      i = (r_ptr->spells & ~CS_FREQ);
  1249. X#endif
  1250. X      k = 0;
  1251. X      while (i != 0)
  1252. X    {
  1253. X      spell_choice[k] = bit_pos(&i);
  1254. X      k++;
  1255. X    }
  1256. X      /* Choose a spell to cast                   */
  1257. X      thrown_spell = spell_choice[randint(k) - 1];
  1258. X      thrown_spell++;
  1259. X      /* all except teleport_away() and drain mana spells always disturb */
  1260. X      if (thrown_spell > 6 && thrown_spell != 17)
  1261. X    disturb (1, 0);
  1262. X      /* save some code/data space here, with a small time penalty */
  1263. X      if ((thrown_spell < 14 && thrown_spell > 6) || (thrown_spell == 16))
  1264. X    {
  1265. X      (void) strcat(cdesc, "casts a spell.");
  1266. X      msg_print(cdesc);
  1267. X    }
  1268. X      /* Cast the spell.                 */
  1269. X      switch(thrown_spell)
  1270. X    {
  1271. X    case 5:     /*Teleport Short*/
  1272. X      teleport_away(monptr, 5);
  1273. X      break;
  1274. X    case 6:     /*Teleport Long */
  1275. X      teleport_away(monptr, MAX_SIGHT);
  1276. X      break;
  1277. X    case 7:     /*Teleport To     */
  1278. X      teleport_to((int)m_ptr->fy, (int)m_ptr->fx);
  1279. X      break;
  1280. X    case 8:     /*Light Wound     */
  1281. X      if (player_saves())
  1282. X        msg_print("You resist the effects of the spell.");
  1283. X      else
  1284. X        take_hit(damroll(3, 8), ddesc);
  1285. X      break;
  1286. X    case 9:     /*Serious Wound */
  1287. X      if (player_saves())
  1288. X        msg_print("You resist the effects of the spell.");
  1289. X      else
  1290. X        take_hit(damroll(8, 8), ddesc);
  1291. X      break;
  1292. X    case 10:  /*Hold Person      */
  1293. X      if (py.flags.free_act)
  1294. X        msg_print("You are unaffected.");
  1295. X      else if (player_saves())
  1296. X        msg_print("You resist the effects of the spell.");
  1297. X      else if (py.flags.paralysis > 0)
  1298. X        py.flags.paralysis += 2;
  1299. X      else
  1300. X        py.flags.paralysis = randint(5)+4;
  1301. X      break;
  1302. X    case 11:  /*Cause Blindness*/
  1303. X      if (player_saves())
  1304. X        msg_print("You resist the effects of the spell.");
  1305. X      else if (py.flags.blind > 0)
  1306. X        py.flags.blind += 6;
  1307. X      else
  1308. X        py.flags.blind += 12 + randint(3);
  1309. X      break;
  1310. X    case 12:  /*Cause Confuse */
  1311. X      if (player_saves())
  1312. X        msg_print("You resist the effects of the spell.");
  1313. X      else if (py.flags.confused > 0)
  1314. X        py.flags.confused += 2;
  1315. X      else
  1316. X        py.flags.confused = randint(5) + 3;
  1317. X      break;
  1318. X    case 13:  /*Cause Fear      */
  1319. X      if (player_saves())
  1320. X        msg_print("You resist the effects of the spell.");
  1321. X      else if (py.flags.afraid > 0)
  1322. X        py.flags.afraid += 2;
  1323. X      else
  1324. X        py.flags.afraid = randint(5) + 3;
  1325. X      break;
  1326. X    case 14:  /*Summon Monster*/
  1327. X      (void) strcat(cdesc, "magically summons a monster!");
  1328. X      msg_print(cdesc);
  1329. X      y = char_row;
  1330. X      x = char_col;
  1331. X      /* in case compact_monster() is called,it needs monptr */
  1332. X      hack_monptr = monptr;
  1333. X      (void) summon_monster(&y, &x, FALSE);
  1334. X      hack_monptr = -1;
  1335. X      update_mon ((int)cave[y][x].cptr);
  1336. X      break;
  1337. X    case 15:  /*Summon Undead*/
  1338. X      (void) strcat(cdesc, "magically summons an undead!");
  1339. X      msg_print(cdesc);
  1340. X      y = char_row;
  1341. X      x = char_col;
  1342. X      /* in case compact_monster() is called,it needs monptr */
  1343. X      hack_monptr = monptr;
  1344. X      (void) summon_undead(&y, &x);
  1345. X      hack_monptr = -1;
  1346. X      update_mon ((int)cave[y][x].cptr);
  1347. X      break;
  1348. X    case 16:  /*Slow Person     */
  1349. X      if (py.flags.free_act)
  1350. X        msg_print("You are unaffected.");
  1351. X      else if (player_saves())
  1352. X        msg_print("You resist the effects of the spell.");
  1353. X      else if (py.flags.slow > 0)
  1354. X        py.flags.slow += 2;
  1355. X      else
  1356. X        py.flags.slow = randint(5) + 3;
  1357. X      break;
  1358. X    case 17:  /*Drain Mana     */
  1359. X      if (py.misc.cmana > 0)
  1360. X        {
  1361. X          disturb (1, 0);
  1362. X          (void) sprintf(outval, "%sdraws psychic energy from you!",cdesc);
  1363. X          msg_print(outval);
  1364. X          if (m_ptr->ml)
  1365. X        {
  1366. X          (void) sprintf(outval, "%sappears healthier.", cdesc);
  1367. X          msg_print(outval);
  1368. X        }
  1369. X          r1 = (randint((int)r_ptr->level) >> 1) + 1;
  1370. X          if (r1 > py.misc.cmana)
  1371. X        {
  1372. X          r1 = py.misc.cmana;
  1373. X          py.misc.cmana = 0;
  1374. X          py.misc.cmana_frac = 0;
  1375. X        }
  1376. X          else
  1377. X        py.misc.cmana -= r1;
  1378. X          prt_cmana();
  1379. X          m_ptr->hp += 6*(r1);
  1380. X        }
  1381. X      break;
  1382. X    case 20:  /*Breath Light */
  1383. X      (void) strcat(cdesc, "breathes lightning.");
  1384. X      msg_print(cdesc);
  1385. X      breath(GF_LIGHTNING, char_row, char_col, (m_ptr->hp / 4), ddesc,
  1386. X         monptr);
  1387. X      break;
  1388. X    case 21:  /*Breath Gas     */
  1389. X      (void) strcat(cdesc, "breathes gas.");
  1390. X      msg_print(cdesc);
  1391. X      breath(GF_POISON_GAS, char_row, char_col, (m_ptr->hp / 3), ddesc,
  1392. X         monptr);
  1393. X      break;
  1394. X    case 22:  /*Breath Acid     */
  1395. X      (void) strcat(cdesc, "breathes acid.");
  1396. X      msg_print(cdesc);
  1397. X      breath(GF_ACID, char_row, char_col, (m_ptr->hp / 3), ddesc, monptr);
  1398. X      break;
  1399. X    case 23:  /*Breath Frost */
  1400. X      (void) strcat(cdesc, "breathes frost.");
  1401. X      msg_print(cdesc);
  1402. X      breath(GF_FROST, char_row, char_col, (m_ptr->hp / 3), ddesc, monptr);
  1403. X      break;
  1404. X    case 24:  /*Breath Fire     */
  1405. X      (void) strcat(cdesc, "breathes fire.");
  1406. X      msg_print(cdesc);
  1407. X      breath(GF_FIRE, char_row, char_col, (m_ptr->hp / 3), ddesc, monptr);
  1408. X      break;
  1409. X    default:
  1410. X      (void) strcat (cdesc, "cast unknown spell.");
  1411. X      msg_print(cdesc);
  1412. X    }
  1413. X      /* End of spells                       */
  1414. X      if (m_ptr->ml)
  1415. X    {
  1416. X      c_recall[m_ptr->mptr].r_spells |= 1L << (thrown_spell-1);
  1417. X      if ((c_recall[m_ptr->mptr].r_spells & CS_FREQ) != CS_FREQ)
  1418. X        c_recall[m_ptr->mptr].r_spells++;
  1419. X      if (death && c_recall[m_ptr->mptr].r_deaths < MAX_SHORT)
  1420. X        c_recall[m_ptr->mptr].r_deaths++;
  1421. X    }
  1422. X    }
  1423. X}
  1424. X
  1425. X
  1426. X/* Places creature adjacent to given location        -RAK-    */
  1427. X/* Rats and Flys are fun!                     */
  1428. Xint multiply_monster(y, x, cr_index, monptr)
  1429. Xint y, x, cr_index;
  1430. Xint monptr;
  1431. X{
  1432. X  register int i, j, k;
  1433. X  register cave_type *c_ptr;
  1434. X  int result;
  1435. X#ifdef ATARIST_MWC
  1436. X  int32u holder;
  1437. X#endif
  1438. X
  1439. X  i = 0;
  1440. X  do
  1441. X    {
  1442. X      j = y - 2 + randint(3);
  1443. X      k = x - 2 + randint(3);
  1444. X      /* don't create a new creature on top of the old one, that causes
  1445. X     invincible/invisible creatures to appear */
  1446. X      if (in_bounds(j, k) && (j != y || k != x))
  1447. X    {
  1448. X      c_ptr = &cave[j][k];
  1449. X      if ((c_ptr->fval <= MAX_OPEN_SPACE) && (c_ptr->tptr == 0) &&
  1450. X          (c_ptr->cptr != 1))
  1451. X        {
  1452. X          if (c_ptr->cptr > 1)     /* Creature there already?    */
  1453. X        {
  1454. X          /* Some critters are cannibalistic!        */
  1455. X#ifdef ATARIST_MWC
  1456. X          holder = CM_EATS_OTHER;
  1457. X          if ((c_list[cr_index].cmove & holder)
  1458. X#else
  1459. X          if ((c_list[cr_index].cmove & CM_EATS_OTHER)
  1460. X#endif
  1461. X              /* Check the experience level -CJS- */
  1462. X             && c_list[cr_index].mexp >=
  1463. X              c_list[m_list[c_ptr->cptr].mptr].mexp)
  1464. X            {
  1465. X              /* It ate an already processed monster.Handle normally.*/
  1466. X              if (monptr < c_ptr->cptr)
  1467. X            delete_monster((int) c_ptr->cptr);
  1468. X              /* If it eats this monster, an already processed mosnter
  1469. X             will take its place, causing all kinds of havoc.
  1470. X             Delay the kill a bit. */
  1471. X              else
  1472. X            fix1_delete_monster((int) c_ptr->cptr);
  1473. X
  1474. X              /* in case compact_monster() is called,it needs monptr */
  1475. X              hack_monptr = monptr;
  1476. X              /* Place_monster() may fail if monster list full.  */
  1477. X              result = place_monster(j, k, cr_index, FALSE);
  1478. X              hack_monptr = -1;
  1479. X              if (! result)
  1480. X            return FALSE;
  1481. X              mon_tot_mult++;
  1482. X              return check_mon_lite(j, k);
  1483. X            }
  1484. X        }
  1485. X          else
  1486. X        /* All clear,  place a monster      */
  1487. X        {
  1488. X          /* in case compact_monster() is called,it needs monptr */
  1489. X          hack_monptr = monptr;
  1490. X          /* Place_monster() may fail if monster list full.  */
  1491. X          result = place_monster(j, k, cr_index, FALSE);
  1492. X          hack_monptr = -1;
  1493. X          if (! result)
  1494. X            return FALSE;
  1495. X          mon_tot_mult++;
  1496. X          return check_mon_lite(j, k);
  1497. X        }
  1498. X        }
  1499. X    }
  1500. X      i++;
  1501. X    }
  1502. X  while (i <= 18);
  1503. X  return FALSE;
  1504. X}
  1505. X
  1506. X
  1507. X/* Move the critters about the dungeon            -RAK-    */
  1508. Xstatic void mon_move(monptr, rcmove)
  1509. Xint monptr;
  1510. Xint32u *rcmove;
  1511. X{
  1512. X  register int i, j;
  1513. X  int k, move_test, dir;
  1514. X#ifdef M_XENIX
  1515. X  /* Avoid 'register' bug.  */
  1516. X  creature_type *r_ptr;
  1517. X#else
  1518. X  register creature_type *r_ptr;
  1519. X#endif
  1520. X  register monster_type *m_ptr;
  1521. X  int mm[9];
  1522. X#ifdef ATARIST_MWC
  1523. X  int32u holder;
  1524. X#endif
  1525. X  int rest_val;
  1526. X
  1527. X  m_ptr = &m_list[monptr];
  1528. X  r_ptr = &c_list[m_ptr->mptr];
  1529. X  /* Does the critter multiply?                   */
  1530. X  /* rest could be negative, to be safe, only use mod with positive values. */
  1531. X  rest_val = abs (py.flags.rest);
  1532. X#ifdef ATARIST_MWC
  1533. X  holder = CM_MULTIPLY;
  1534. X  if ((r_ptr->cmove & holder) && (MAX_MON_MULT >= mon_tot_mult) &&
  1535. X#else
  1536. X  if ((r_ptr->cmove & CM_MULTIPLY) && (MAX_MON_MULT >= mon_tot_mult) &&
  1537. X#endif
  1538. X      ((rest_val % MON_MULT_ADJ) == 0))
  1539. X    {
  1540. X      k = 0;
  1541. X      for (i = m_ptr->fy-1; i <= m_ptr->fy+1; i++)
  1542. X    for (j = m_ptr->fx-1; j <= m_ptr->fx+1; j++)
  1543. X      if (in_bounds(i, j) && (cave[i][j].cptr > 1))
  1544. X        k++;
  1545. X      /* can't call randint with a value of zero, increment counter
  1546. X     to allow creature multiplication */
  1547. X      if (k == 0)
  1548. X    k++;
  1549. X      if ((k < 4) && (randint(k*MON_MULT_ADJ) == 1))
  1550. X    if (multiply_monster((int)m_ptr->fy, (int)m_ptr->fx,
  1551. X             (int)m_ptr->mptr, monptr))
  1552. X#ifdef ATARIST_MWC
  1553. X      *rcmove |= holder;
  1554. X#else
  1555. X      *rcmove |= CM_MULTIPLY;
  1556. X#endif
  1557. X    }
  1558. X  move_test = FALSE;
  1559. X
  1560. X  /* if in wall, must immediately escape to a clear area */
  1561. X#ifdef ATARIST_MWC
  1562. X  holder = CM_PHASE;
  1563. X  if (!(r_ptr->cmove & holder) &&
  1564. X#else
  1565. X  if (!(r_ptr->cmove & CM_PHASE) &&
  1566. X#endif
  1567. X      (cave[m_ptr->fy][m_ptr->fx].fval >= MIN_CAVE_WALL))
  1568. X    {
  1569. X      /* If the monster is already dead, don't kill it again!
  1570. X     This can happen for monsters moving faster than the player.  They
  1571. X     will get multiple moves, but should not if they die on the first
  1572. X     move.  This is only a problem for monsters stuck in rock.  */
  1573. X      if (m_ptr->hp < 0)
  1574. X    return;
  1575. X
  1576. X      k = 0;
  1577. X      dir = 1;
  1578. X      /* note direction of for loops matches direction of keypad from 1 to 9*/
  1579. X      /* do not allow attack against the player */
  1580. X      /* Must cast fy-1 to signed int, so that a nagative value of i will
  1581. X     fail the comparison.  */
  1582. X      for (i = m_ptr->fy+1; i >= (int)(m_ptr->fy-1); i--)
  1583. X    for (j = m_ptr->fx-1; j <= m_ptr->fx+1; j++)
  1584. X      {
  1585. X        if ((dir != 5) && (cave[i][j].fval <= MAX_OPEN_SPACE)
  1586. X        && (cave[i][j].cptr != 1))
  1587. X          mm[k++] = dir;
  1588. X        dir++;
  1589. X      }
  1590. X      if (k != 0)
  1591. X    {
  1592. X      /* put a random direction first */
  1593. X      dir = randint (k) - 1;
  1594. X      i = mm[0];
  1595. X      mm[0] = mm[dir];
  1596. X      mm[dir] = i;
  1597. X      make_move (monptr, mm, rcmove);
  1598. X      /* this can only fail if mm[0] has a rune of protection */
  1599. X    }
  1600. X      /* if still in a wall, let it dig itself out, but also apply some
  1601. X     more damage */
  1602. X      if (cave[m_ptr->fy][m_ptr->fx].fval >= MIN_CAVE_WALL)
  1603. X    {
  1604. X      /* in case the monster dies, may need to call fix1_delete_monster()
  1605. X         instead of delete_monsters() */
  1606. X      hack_monptr = monptr;
  1607. X      i = mon_take_hit(monptr, damroll (8, 8));
  1608. X      hack_monptr = -1;
  1609. X      if (i >= 0)
  1610. X        {
  1611. X          msg_print("You hear a scream muffled by rock!");
  1612. X          prt_experience();
  1613. X        }
  1614. X      else
  1615. X        {
  1616. X          msg_print ("A creature digs itself out from the rock!");
  1617. X          (void) twall ((int)m_ptr->fy, (int)m_ptr->fx, 1, 0);
  1618. X        }
  1619. X    }
  1620. X      return;  /* monster movement finished */
  1621. X    }
  1622. X  /* Creature is confused?  Chance it becomes un-confused  */
  1623. X  else if (m_ptr->confused)
  1624. X    {
  1625. X      mm[0] = randint(9);
  1626. X      mm[1] = randint(9);
  1627. X      mm[2] = randint(9);
  1628. X      mm[3] = randint(9);
  1629. X      mm[4] = randint(9);
  1630. X      /* don't move him if he is not supposed to move! */
  1631. X      if (!(r_ptr->cmove & CM_ATTACK_ONLY))
  1632. X    make_move(monptr, mm, rcmove);
  1633. X      if (randint(8) == 1)
  1634. X    m_ptr->confused = FALSE;
  1635. X      move_test = TRUE;
  1636. X    }
  1637. X  /* Creature may cast a spell */
  1638. X  else if (r_ptr->spells != 0)
  1639. X    mon_cast_spell(monptr, &move_test);
  1640. X  if (!move_test)
  1641. X    {
  1642. X      /* 75% random movement */
  1643. X      if ((r_ptr->cmove & CM_75_RANDOM) && (randint(100) < 75))
  1644. X    {
  1645. X      mm[0] = randint(9);
  1646. X      mm[1] = randint(9);
  1647. X      mm[2] = randint(9);
  1648. X      mm[3] = randint(9);
  1649. X      mm[4] = randint(9);
  1650. X      *rcmove |= CM_75_RANDOM;
  1651. X      make_move(monptr, mm, rcmove);
  1652. X    }
  1653. X      /* 40% random movement */
  1654. X      else if ((r_ptr->cmove & CM_40_RANDOM) && (randint(100) < 40))
  1655. X    {
  1656. X      mm[0] = randint(9);
  1657. X      mm[1] = randint(9);
  1658. X      mm[2] = randint(9);
  1659. X      mm[3] = randint(9);
  1660. X      mm[4] = randint(9);
  1661. X      *rcmove |= CM_40_RANDOM;
  1662. X      make_move(monptr, mm, rcmove);
  1663. X    }
  1664. X      /* 20% random movement */
  1665. X      else if ((r_ptr->cmove & CM_20_RANDOM) && (randint(100) < 20))
  1666. X    {
  1667. X      mm[0] = randint(9);
  1668. X      mm[1] = randint(9);
  1669. X      mm[2] = randint(9);
  1670. X      mm[3] = randint(9);
  1671. X      mm[4] = randint(9);
  1672. X      *rcmove |= CM_20_RANDOM;
  1673. X      make_move(monptr, mm, rcmove);
  1674. X    }
  1675. X      /* Normal movement */
  1676. X      else if (r_ptr->cmove & CM_MOVE_NORMAL)
  1677. X    {
  1678. X      if (randint(200) == 1)
  1679. X        {
  1680. X          mm[0] = randint(9);
  1681. X          mm[1] = randint(9);
  1682. X          mm[2] = randint(9);
  1683. X          mm[3] = randint(9);
  1684. X          mm[4] = randint(9);
  1685. X        }
  1686. X      else
  1687. X        get_moves(monptr, mm);
  1688. X      *rcmove |= CM_MOVE_NORMAL;
  1689. X      make_move(monptr, mm, rcmove);
  1690. X    }
  1691. X      /* Attack, but don't move */
  1692. X      else if (r_ptr->cmove & CM_ATTACK_ONLY)
  1693. X    {
  1694. X      if (m_ptr->cdis < 2)
  1695. X        {
  1696. X          get_moves(monptr, mm);
  1697. X          make_move(monptr, mm, rcmove);
  1698. X        }
  1699. X      else
  1700. X        /* Learn that the monster does does not move when it should have
  1701. X           moved, but didn't.  */
  1702. X        *rcmove |= CM_ATTACK_ONLY;
  1703. X    }
  1704. X      else if ((r_ptr->cmove & CM_ONLY_MAGIC) && (m_ptr->cdis < 2))
  1705. X    {
  1706. X      /* A little hack for Quylthulgs, so that one will eventually notice
  1707. X         that they have no physical attacks.  */
  1708. X      if (c_recall[m_ptr->mptr].r_attacks[0] < MAX_UCHAR)
  1709. X        c_recall[m_ptr->mptr].r_attacks[0]++;
  1710. X      /* Another little hack for Quylthulgs, so that one can eventually
  1711. X         learn their speed.  */
  1712. X      if (c_recall[m_ptr->mptr].r_attacks[0] > 20)
  1713. X        c_recall[m_ptr->mptr].r_cmove |= CM_ONLY_MAGIC;
  1714. X    }
  1715. X    }
  1716. X}
  1717. X
  1718. X
  1719. X/* Creatures movement and attacking are done from here    -RAK-    */
  1720. Xvoid creatures(attack)
  1721. Xint attack;
  1722. X{
  1723. X  register int i, k;
  1724. X  register monster_type *m_ptr;
  1725. X  recall_type *r_ptr;
  1726. X  int32u notice, rcmove;
  1727. X  int wake, ignore;
  1728. X  vtype cdesc;
  1729. X#ifdef ATARIST_MWC
  1730. X  int32u holder;
  1731. X#endif
  1732. X
  1733. X  /* Process the monsters  */
  1734. X  for (i = mfptr - 1; i >= MIN_MONIX && !death; i--)
  1735. X    {
  1736. X      m_ptr = &m_list[i];
  1737. X      /* Get rid of an eaten/breathed on monster.  Note: Be sure not to
  1738. X     process this monster. This is necessary because we can't delete
  1739. X     monsters while scanning the m_list here. */
  1740. X      if (m_ptr->hp < 0)
  1741. X    {
  1742. X      fix2_delete_monster(i);
  1743. X      continue;
  1744. X    }
  1745. X
  1746. X      m_ptr->cdis = distance(char_row, char_col,
  1747. X                 (int)m_ptr->fy, (int)m_ptr->fx);
  1748. X      if (attack)   /* Attack is argument passed to CREATURE*/
  1749. X    {
  1750. X      k = movement_rate(m_ptr->cspeed);
  1751. X      if (k <= 0)
  1752. X        update_mon(i);
  1753. X      else
  1754. X        while (k > 0)
  1755. X          {
  1756. X        k--;
  1757. X        wake = FALSE;
  1758. X        ignore = FALSE;
  1759. X        rcmove = 0;
  1760. X        if (m_ptr->ml || (m_ptr->cdis <= c_list[m_ptr->mptr].aaf)
  1761. X            /* Monsters trapped in rock must be given a turn also,
  1762. X               so that they will die/dig out immediately.  */
  1763. X#ifdef ATARIST_MWC
  1764. X            || ((! (c_list[m_ptr->mptr].cmove & (holder = CM_PHASE)))
  1765. X#else
  1766. X            || ((! (c_list[m_ptr->mptr].cmove & CM_PHASE))
  1767. X#endif
  1768. X            && cave[m_ptr->fy][m_ptr->fx].fval >= MIN_CAVE_WALL))
  1769. X          {
  1770. X            if (m_ptr->csleep > 0)
  1771. X              if (py.flags.aggravate)
  1772. X            m_ptr->csleep = 0;
  1773. X              else if ((py.flags.rest == 0 && py.flags.paralysis < 1)
  1774. X                   || (randint(50) == 1))
  1775. X            {
  1776. X              notice = randint(1024);
  1777. X              if (notice*notice*notice <= (1L << (29 - py.misc.stl)))
  1778. X                {
  1779. X                  m_ptr->csleep -= (100 / m_ptr->cdis);
  1780. X                  if (m_ptr->csleep > 0)
  1781. X                ignore = TRUE;
  1782. X                  else
  1783. X                {
  1784. X                  wake = TRUE;
  1785. X                  /* force it to be exactly zero */
  1786. X                  m_ptr->csleep = 0;
  1787. X                }
  1788. X                }
  1789. X            }
  1790. X            if (m_ptr->stunned != 0)
  1791. X              {
  1792. X            /* NOTE: Balrog = 100*100 = 10000, it always
  1793. X               recovers instantly */
  1794. X            if (randint(5000) < c_list[m_ptr->mptr].level
  1795. X                * c_list[m_ptr->mptr].level)
  1796. X              m_ptr->stunned = 0;
  1797. X            else
  1798. X              m_ptr->stunned--;
  1799. X            if (m_ptr->stunned == 0)
  1800. X              {
  1801. X                if (!m_ptr->ml)
  1802. X                  (void) strcpy(cdesc, "It ");
  1803. X                else
  1804. X                  (void) sprintf(cdesc, "The %s ",
  1805. X                         c_list[m_ptr->mptr].name);
  1806. X                msg_print(strcat(cdesc,
  1807. X                         "recovers and glares at you."));
  1808. X              }
  1809. X              }
  1810. X            if ((m_ptr->csleep == 0) && (m_ptr->stunned == 0))
  1811. X              mon_move (i, &rcmove);
  1812. X          }
  1813. X
  1814. X        update_mon(i);
  1815. X        if (m_ptr->ml)
  1816. X          {
  1817. X            r_ptr = &c_recall[m_ptr->mptr];
  1818. X            if (wake)
  1819. X              {
  1820. X            if (r_ptr->r_wake < MAX_UCHAR)
  1821. X              r_ptr->r_wake++;
  1822. X              }
  1823. X            else if (ignore)
  1824. X              {
  1825. X            if (r_ptr->r_ignore < MAX_UCHAR)
  1826. X              r_ptr->r_ignore++;
  1827. X              }
  1828. X            r_ptr->r_cmove |= rcmove;
  1829. X          }
  1830. X          }
  1831. X    }
  1832. X      else
  1833. X    update_mon(i);
  1834. X
  1835. X      /* Get rid of an eaten/breathed on monster.  This is necessary because
  1836. X     we can't delete monsters while scanning the m_list here.  This
  1837. X     monster may have been killed during mon_move(). */
  1838. X      if (m_ptr->hp < 0)
  1839. X    {
  1840. X      fix2_delete_monster(i);
  1841. X      continue;
  1842. X    }
  1843. X    }
  1844. X  /* End processing monsters       */
  1845. X}
  1846. END_OF_FILE
  1847. if test 46325 -ne `wc -c <'source/creature.c'`; then
  1848.     echo shar: \"'source/creature.c'\" unpacked with wrong size!
  1849. fi
  1850. # end of 'source/creature.c'
  1851. fi
  1852. if test -f 'util/printit/pr_monst.c' -a "${1}" != "-c" ; then 
  1853.   echo shar: Will not clobber existing file \"'util/printit/pr_monst.c'\"
  1854. else
  1855. echo shar: Extracting \"'util/printit/pr_monst.c'\" \(6250 characters\)
  1856. sed "s/^X//" >'util/printit/pr_monst.c' <<'END_OF_FILE'
  1857. X/* util/printit/pr_monst.c: pretty print monster info
  1858. X
  1859. X   Copyright (c) 1990-1992 Carlton Hommel, James E. Wilson
  1860. X
  1861. X   This software may be copied and distributed for educational, research, and
  1862. X   not for profit purposes provided that this copyright and statement are
  1863. X   included in all such copies. */
  1864. X
  1865. X#include "config.h"
  1866. X#include "constant.h"
  1867. X#include "types.h"
  1868. X
  1869. Xextern creature_type c_list[];
  1870. X
  1871. Xmain()
  1872. X{
  1873. X    int i;
  1874. X    creature_type *c;
  1875. X
  1876. X    printf("     Lvl(Ep) [  HD, AC]\tspd aaf/{sleep}\t\t    Name");
  1877. X    printf("\tDamage(special) <Defense> {Moves} /* Spells */\n");
  1878. X    for (i=0; i<MAX_CREATURES; i++) {
  1879. X      c = &c_list[i];
  1880. X      call_it(c);
  1881. X    }
  1882. X    return 0;
  1883. X}
  1884. X
  1885. Xcall_it(c)
  1886. Xcreature_type *c;
  1887. X{
  1888. X    /* Line 1 */
  1889. X    printf("'%c' ", c->cchar);
  1890. X    printf("%2d", c->level);
  1891. X    printf("(%4d) ", c->mexp);
  1892. X    printf("[%2dd%d, %2d]\t", c->hd[0], c->hd[1], c->ac);
  1893. X
  1894. X    printf("%2d ", ((int)c->speed)-10);
  1895. X    printf("%2d/", c->aaf);
  1896. X    printf("{%d}\t", c->sleep*10);
  1897. X
  1898. X    printf("%20.20s\t", c->name);
  1899. X    print_damage(c->damage);
  1900. X    printf("\t");
  1901. X
  1902. X    print_flags_cdefense(c->cdefense);
  1903. X    printf(" ");
  1904. X    print_flags_cmove(c->cmove);
  1905. X    printf(" ");
  1906. X    print_flags_spells(c->spells);
  1907. X
  1908. X    printf("\n");
  1909. X
  1910. X}
  1911. X
  1912. Xprint_damage(attstr)
  1913. Xint8u attstr[4];
  1914. X{
  1915. X  int attype, adesc, adice, asides;
  1916. X  int count;
  1917. X  char damstr[50];
  1918. X
  1919. X  extern struct m_attack_type monster_attacks[];
  1920. X
  1921. X  for (count=0; count<4; count++) {
  1922. X        if (attstr[count] == 0) continue;
  1923. X    attype = monster_attacks[attstr[count]].attack_type;
  1924. X    adesc  = monster_attacks[attstr[count]].attack_desc;
  1925. X    adice  = monster_attacks[attstr[count]].attack_dice;
  1926. X    asides = monster_attacks[attstr[count]].attack_sides;
  1927. X
  1928. X    sprintf(damstr, "%dd%d", adice, asides);
  1929. X    switch(attype) {
  1930. X    case 1:  printf("%s ", damstr);        break;
  1931. X    case 2:  printf("%s(-Str) ", damstr);    break;
  1932. X    case 3:  printf("%s(Conf) ", damstr);    break;
  1933. X    case 4:  printf("%s(Fear) ", damstr);    break;
  1934. X    case 5:  printf("%s(Fire) ", damstr);    break;
  1935. X    case 6:  printf("%s(Acid) ", damstr);    break;
  1936. X    case 7:  printf("%s(Cold) ", damstr);    break;
  1937. X    case 8:  printf("%s(Zap) ", damstr);    break;
  1938. X    case 9:  printf("%s(Acid) ", damstr);    break;
  1939. X    case 10: printf("%s(Blind) ", damstr);    break;
  1940. X    case 11: printf("%s(Paral) ", damstr);    break;
  1941. X    case 12: printf("%s(-Money) ", damstr);    break;
  1942. X    case 13: printf("%s(-Object) ", damstr);break;
  1943. X    case 14: printf("%s(Poison) ", damstr);    break;
  1944. X    case 15: printf("%s(-Dex) ", damstr);    break;
  1945. X    case 16: printf("%s(-Con ) ", damstr);    break;
  1946. X    case 17: printf("%s(-Int ) ", damstr);    break;
  1947. X    case 18: printf("%s(-Wis) ", damstr);    break;
  1948. X    case 19: printf("%s(-Exp) ", damstr);    break;
  1949. X    case 20: printf("%s(Aggr) ", damstr);    break;
  1950. X    case 21: printf("%s(-Magic) ", damstr);    break;
  1951. X    case 22: printf("%s(-Food) ", damstr);    break;
  1952. X    case 23: printf("%s(-Light) ", damstr);    break;
  1953. X    case 24: printf("%s(-Charges) ", damstr);break;
  1954. X    default:
  1955. X    case 99: printf("%s(Blank) ", damstr);    break;
  1956. X    }
  1957. X
  1958. X    }
  1959. X}
  1960. X
  1961. Xprint_flags_spells(spells)
  1962. Xunsigned long spells;
  1963. X{
  1964. X    int count;
  1965. X    unsigned long mask;
  1966. X    int chance;
  1967. X
  1968. X    if (spells == 0)
  1969. X    return;
  1970. X
  1971. X    printf("/* ");
  1972. X    chance = (int)spells & CS_FREQ;
  1973. X    printf("%2.1f%% ", 1.0 / chance * 100.0);
  1974. X    for (count=4,mask=0x010; count<32; mask <<= 1, count++) {
  1975. X    switch (spells & mask) {
  1976. X    case CS_TEL_SHORT:    printf("CS_TEL_SHORT ");break;
  1977. X    case CS_TEL_LONG:    printf("CS_TEL_LONG ");    break;
  1978. X    case CS_TEL_TO:        printf("CS_TEL_TO ");    break;
  1979. X    case CS_LGHT_WND:    printf("CS_LGHT_WND ");    break;
  1980. X    case CS_SER_WND:    printf("CS_SER_WND ");    break;
  1981. X    case CS_HOLD_PER:    printf("CS_HOLD_PER ");    break;
  1982. X    case CS_BLIND:        printf("CS_BLIND ");    break;
  1983. X    case CS_CONFUSE:    printf("CS_CONFUSE ");    break;
  1984. X    case CS_FEAR:        printf("CS_FEAR ");    break;
  1985. X    case CS_SUMMON_MON:    printf("CS_SUMMON_MON ");break;
  1986. X    case CS_SUMMON_UND:    printf("CS_SUMMON_UND ");break;
  1987. X    case CS_SLOW_PER:    printf("CS_SLOW_PER ");    break;
  1988. X    case CS_DRAIN_MANA:    printf("CS_DRAIN_MANA ");break;
  1989. X    case CS_BR_LIGHT:    printf("CS_BR_LIGHT ");    break;
  1990. X    case CS_BR_GAS:        printf("CS_BR_GAS ");    break;
  1991. X    case CS_BR_ACID:    printf("CS_BR_ACID ");    break;
  1992. X    case CS_BR_FROST:    printf("CS_BR_FROST ");    break;
  1993. X    case CS_BR_FIRE:    printf("CS_BR_FIRE ");    break;
  1994. X    }
  1995. X    }
  1996. X    printf("*/");
  1997. X}
  1998. X
  1999. Xprint_flags_cmove(cmove)
  2000. Xunsigned long cmove;
  2001. X{
  2002. X    int count;
  2003. X    unsigned long mask;
  2004. X
  2005. X    if (cmove == 0)
  2006. X    return;
  2007. X
  2008. X    printf("<");
  2009. X    for (count=0,mask=0x01; count<32; mask <<= 1, count++) {
  2010. X    switch (cmove & mask) {
  2011. X    case CM_ATTACK_ONLY:    printf("CM_ATTACK_ONLY ");    break;
  2012. X    case CM_MOVE_NORMAL:    /*printf("CM_MOVE_NORMAL ");*/    break;
  2013. X    case CM_20_RANDOM:    printf("CM_20_RANDOM ");    break;
  2014. X    case CM_40_RANDOM:    printf("CM_40_RANDOM ");    break;
  2015. X    case CM_75_RANDOM:    printf("CM_75_RANDOM ");    break;
  2016. X    case CM_INVISIBLE:    printf("CM_INVISIBLE ");    break;
  2017. X    case CM_OPEN_DOOR:    printf("CM_OPEN_DOOR ");    break;
  2018. X    case CM_PHASE:        printf("CM_PHASE ");        break;
  2019. X    case CM_EATS_OTHER:    printf("CM_EATS_OTHER ");    break;
  2020. X    case CM_PICKS_UP:    printf("CM_PICKS_UP ");        break;
  2021. X    case CM_MULTIPLY:    printf("CM_MULTIPLY ");        break;
  2022. X    case CM_CARRY_OBJ:    printf("CM_CARRY_OTHER ");    break;
  2023. X    case CM_CARRY_GOLD:    printf("CM_CARRY_GOLD ");    break;
  2024. X    case CM_60_RANDOM:    printf("CM_60_RANDOM ");    break;
  2025. X    case CM_90_RANDOM:    printf("CM_90_RANDOM ");    break;
  2026. X    case CM_1D2_OBJ:    printf("CM_1D2_OBJ ");        break;
  2027. X    case CM_2D2_OBJ:    printf("CM_2D2_OBJ ");        break;
  2028. X    case CM_4D2_OBJ:    printf("CM_4D2_OBJ ");        break;
  2029. X    case CM_WIN:        printf("CM_WIN ");        break;
  2030. X    }
  2031. X    }
  2032. X    printf(">");
  2033. X}
  2034. X
  2035. Xprint_flags_cdefense(cdefense)
  2036. Xunsigned int cdefense;
  2037. X{
  2038. X    int count;
  2039. X    unsigned int mask;
  2040. X
  2041. X    if (cdefense == 0)
  2042. X    return;
  2043. X
  2044. X    printf("{");
  2045. X    for (count=0,mask=0x01; count<16; mask <<= 1, count++) {
  2046. X    switch (cdefense & mask) {
  2047. X    case CD_DRAGON:        printf("CD_DRAGON ");    break;
  2048. X    case CD_ANIMAL:        printf("CD_ANIMAL ");    break;
  2049. X    case CD_EVIL:        printf("CD_EVIL ");    break;
  2050. X    case CD_UNDEAD:        printf("CD_UNDEAD ");    break;
  2051. X    case CD_FROST:        printf("CD_FROST ");    break;
  2052. X    case CD_FIRE:        printf("CD_FIRE ");    break;
  2053. X    case CD_POISON:        printf("CD_POISON ");    break;
  2054. X    case CD_ACID:        printf("CD_ACID ");    break;
  2055. X    case CD_LIGHT:        printf("CD_LIGHT ");    break;
  2056. X    case CD_STONE:        printf("CD_STONE ");    break;
  2057. X    case CD_NO_SLEEP:    printf("CD_NO_SLEEP ");    break;
  2058. X    case CD_INFRA:        printf("CD_INFRA ");    break;
  2059. X    case CD_MAX_HP:        printf("CD_MAX_HP ");    break;
  2060. X    }
  2061. X    }
  2062. X    printf("}");
  2063. X}
  2064. END_OF_FILE
  2065. if test 6250 -ne `wc -c <'util/printit/pr_monst.c'`; then
  2066.     echo shar: \"'util/printit/pr_monst.c'\" unpacked with wrong size!
  2067. fi
  2068. # end of 'util/printit/pr_monst.c'
  2069. fi
  2070. echo shar: End of archive 6 \(of 39\).
  2071. cp /dev/null ark6isdone
  2072. MISSING=""
  2073. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 ; do
  2074.     if test ! -f ark${I}isdone ; then
  2075.     MISSING="${MISSING} ${I}"
  2076.     fi
  2077. done
  2078. if test "${MISSING}" = "" ; then
  2079.     echo You have unpacked all 39 archives.
  2080.     echo "Now run "bldfiles.sh" to build split files"
  2081.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2082. else
  2083.     echo You still need to unpack the following archives:
  2084.     echo "        " ${MISSING}
  2085. fi
  2086. ##  End of shell archive.
  2087. exit 0
  2088.