monster.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: monster.c
  4. *
  5. * DESCRIPTION:
  6. * This module handles most aspects of monsters in the game.
  7. * It provides the monster definitions.
  8. * Handles monster creation.
  9. * All monster movement, including attacking the player (including special
  10. * attacks) is handled here.
  11. * Also handles loading and saving monster state data.
  12. *
  13. * =============================================================================
  14. * EXPORTED VARIABLES
  15. *
  16. * monstnamelist : The character code for displaying each monster
  17. * monsttilelist : The gfx tile for each monster
  18. * monster : The monster data
  19. * lastmonst : The name of the last monster being processed.
  20. * last_monst_id : The id of the last monster being processed.
  21. * last_monst_hx : The x location of the last monster hit by the player
  22. * last_monst_hy : The y location of the last monster hit by the player
  23. * rmst : The random monster creation countdown.
  24. *
  25. * =============================================================================
  26. * EXPORTED FUNCTIONS
  27. *
  28. * createmonster
  29. * mon_has_item : Checks if a monster has a specific item
  30. * fullhit : Do full damage to a monster
  31. * ifblind : Display the monster hir, accounting for blindness
  32. * hitmonster : Function to hit a monster
  33. * hitm : Function to just hit a monster (no checks for AC)
  34. * hitplayer : Function for a monster to hit the player
  35. * makemonst : Make a monster number appropriate to a dungeon level
  36. * randmonst : Create a random monster on the current cave level
  37. * teleportmonst : Teleport a monster
  38. * movemonst : Move monsters.
  39. * parse2 : Function to call when player is not to move, but monsters are
  40. * write_monster_data : Function to write the monster data to the save file
  41. * read_monster_data : Function to read the monster data from the save file
  42. *
  43. * =============================================================================
  44. */
  45. #include "monster.h"
  46. #include "dungeon.h"
  47. #include "header.h"
  48. #include "itm.h"
  49. #include "player.h"
  50. #include "saveutils.h"
  51. #include "show.h"
  52. #include "sphere.h"
  53. #include "ularn_game.h"
  54. #include "ularn_win.h"
  55. /* =============================================================================
  56. * Exported variables
  57. */
  58. char monstnamelist[MONST_COUNT] = {
  59. ' ', 'l', 'G', 'H', 'J', 'K', 'O', 'S', 'c', 'j', 't', 'A', 'E', 'L',
  60. 'N', 'Q', 'R', 'Z', 'a', 'b', 'h', 'i', 'C', 'T', 'Y', 'd', 'e', 'g',
  61. 'm', 'v', 'z', 'F', 'W', 'f', 'l', 'o', 'r', 'X', 'V', ' ', 'p', 'q',
  62. 's', 'y', 'U', 'k', 'M', 'w', 'D', 'D', 'P', 'x', 'n', 'D', 'D', 'u',
  63. 'D', '1', '2', '3', '4', '5', '6', '7', '9', '0'};
  64. /*
  65. * Tile numbers to use for monsters
  66. */
  67. int monsttilelist[MONST_COUNT] = {
  68. 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  69. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
  70. 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
  71. 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63};
  72. /*
  73. * for the monster data
  74. *
  75. * array to do rnd() to create monsters <= a given level
  76. */
  77. char monstlevel[] = {5, 11, 17, 22, 27, 33, 39, 42, 46, 50, 53, 56};
  78. struct monst monster[MONST_COUNT] = {
  79. /*NAME LV AC DAM ATT INT GOLD HP EXP FLAGS
  80. ----------------------------------------------------------------------------------------------
  81. */
  82. {"unseen attacker", 0, 0, 0, 0, 1, 0, 0, 0, 0},
  83. {"lemming", 1, 0, 0, 0, 3, 0, 0, 1, FL_HEAD},
  84. {"gnome", 1, 10, 1, 0, 8, 30, 2, 2, FL_HEAD | FL_INFRAVIS},
  85. {"hobgoblin", 1, 13, 2, 0, 5, 25, 3, 2, FL_HEAD | FL_SLOW},
  86. {"jackal", 1, 7, 1, 0, 4, 0, 1, 1, FL_HEAD},
  87. {"kobold", 1, 15, 1, 0, 7, 10, 1, 1, FL_HEAD | FL_INFRAVIS},
  88. {"orc", 2, 15, 3, 0, 9, 40, 5, 2, FL_HEAD},
  89. {"snake", 2, 10, 1, 0, 3, 0, 3, 1, FL_HEAD},
  90. {"giant centipede", 2, 13, 1, 4, 3, 0, 2, 2, FL_HEAD},
  91. {"jaculi", 2, 9, 1, 0, 3, 0, 2, 1, FL_HEAD},
  92. {"troglodyte", 2, 10, 2, 0, 5, 80, 5, 3, FL_HEAD | FL_SLOW},
  93. {"giant ant", 2, 8, 1, 4, 4, 0, 5, 4, FL_HEAD},
  94. {"floating eye", 3, 8, 2, 0, 3, 0, 7, 2, FL_FLY},
  95. {"leprechaun", 3, 3, 0, 8, 3, 1500, 15, 40, FL_HEAD},
  96. {"nymph", 3, 3, 0, 14, 9, 0, 20, 40, FL_HEAD},
  97. {"quasit", 3, 5, 3, 0, 3, 0, 14, 10, FL_HEAD},
  98. {"rust monster", 3, 5, 0, 1, 3, 0, 18, 20, FL_HEAD},
  99. {"zombie", 3, 12, 3, 0, 3, 0, 9, 7, FL_HEAD | FL_UNDEAD},
  100. {"assassin bug", 4, 4, 3, 0, 3, 0, 23, 13, FL_HEAD},
  101. {"bugbear", 4, 5, 4, 15, 5, 40, 24, 33, FL_HEAD | FL_INFRAVIS},
  102. {"hell hound", 4, 5, 2, 2, 6, 0, 20, 33, FL_HEAD},
  103. {"ice lizard", 4, 11, 3, 10, 6, 50, 19, 23, FL_HEAD | FL_SLOW},
  104. {"centaur", 4, 6, 4, 0, 10, 40, 25, 43, FL_HEAD},
  105. {"troll", 5, 9, 5, 0, 9, 80, 55, 250, FL_HEAD},
  106. {"yeti", 5, 8, 4, 0, 5, 50, 45, 90, FL_HEAD},
  107. {"white dragon", 5, 4, 5, 5, 16, 500, 65, 1000, FL_HEAD},
  108. {"elf", 5, 3, 3, 0, 15, 50, 25, 33, FL_HEAD | FL_INFRAVIS},
  109. {"gelatinous cube", 5, 9, 3, 0, 3, 0, 24, 43, 0},
  110. {"metamorph", 6, 9, 3, 0, 3, 0, 32, 40, FL_SLOW},
  111. {"vortex", 6, 5, 4, 0, 3, 0, 33, 53, 0},
  112. {"ziller", 6, 15, 3, 0, 3, 0, 34, 33, FL_HEAD},
  113. {"violet fungus", 6, 12, 3, 0, 3, 0, 39, 90, 0},
  114. {"wraith", 6, 3, 1, 6, 3, 0, 36, 300, FL_HEAD | FL_FLY | FL_UNDEAD},
  115. {"forvalaka", 6, 3, 5, 0, 7, 0, 55, 270, FL_HEAD | FL_INFRAVIS},
  116. {"lama nobe", 7, 14, 7, 0, 6, 0, 36, 70, FL_HEAD},
  117. {"osequip", 7, 4, 7, 16, 4, 0, 36, 90, FL_HEAD},
  118. {"rothe", 7, 15, 5, 0, 3, 100, 53, 230, FL_HEAD | FL_INFRAVIS},
  119. {"xorn", 7, 6, 7, 0, 13, 0, 63, 290, FL_INFRAVIS},
  120. {"vampire", 7, 5, 4, 6, 17, 0, 55, 950, FL_HEAD | FL_FLY | FL_UNDEAD},
  121. {"invisible stalker", 7, 5, 6, 0, 5, 0, 55, 330, FL_HEAD | FL_SLOW},
  122. {"poltergeist", 8, 1, 8, 0, 3, 0, 55, 430, FL_SPIRIT},
  123. {"disenchantress", 8, 3, 1, 9, 3, 0, 57, 500, FL_HEAD},
  124. {"shambling mound", 8, 13, 5, 0, 6, 0, 47, 390, 0},
  125. {"yellow mold", 8, 12, 4, 0, 3, 0, 37, 240, 0},
  126. {"umber hulk", 8, 6, 7, 11, 14, 0, 67, 600, FL_HEAD | FL_INFRAVIS},
  127. {"gnome king", 9, -1, 10, 0, 18, 2000, 120, 3000, FL_HEAD | FL_INFRAVIS},
  128. {"mimic", 9, 9, 7, 0, 8, 0, 57, 100, 0},
  129. {"water lord", 9, -10, 15, 7, 20, 0, 155, 15000, FL_HEAD | FL_NOBEHEAD},
  130. {"bronze dragon", 9, 5, 9, 3, 16, 300, 90, 4000, FL_HEAD | FL_FLY},
  131. {"green dragon", 9, 4, 4, 10, 15, 200, 80, 2500, FL_HEAD | FL_FLY},
  132. {"purple worm", 9, -1, 13, 0, 3, 100, 130, 15000, FL_HEAD},
  133. {"xvart", 9, -2, 14, 0, 13, 0, 100, 1000, FL_HEAD | FL_SLOW},
  134. {"spirit naga", 10, -20, 15, 12, 23, 0, 100, 20000,
  135. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_SPIRIT | FL_INFRAVIS},
  136. {"silver dragon", 10, -4, 10, 3, 20, 700, 110, 10000, FL_HEAD | FL_FLY},
  137. {"platinum dragon", 10, -7, 15, 13, 22, 1000, 150, 25000, FL_HEAD | FL_FLY},
  138. {"green urchin", 10, -5, 12, 0, 3, 0, 95, 5000, 0},
  139. {"red dragon", 10, -4, 13, 3, 19, 800, 120, 14000, FL_HEAD | FL_FLY},
  140. {"type I demon lord", 12, -40, 20, 3, 20, 0, 150, 50000,
  141. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
  142. {"type II demon lord", 13, -45, 25, 5, 22, 0, 200, 75000,
  143. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
  144. {"type III demon lord", 14, -50, 30, 9, 24, 0, 250, 100000,
  145. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
  146. {"type IV demon lord", 15, -55, 35, 11, 26, 0, 300, 125000,
  147. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
  148. {"type V demon lord", 16, -60, 40, 13, 28, 0, 350, 150000,
  149. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
  150. {"type VI demon lord", 17, -65, 45, 13, 30, 0, 400, 175000,
  151. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
  152. {"type VII demon lord", 18, -70, 50, 6, 32, 0, 450, 200000,
  153. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
  154. {"demon prince", 19, -90, 80, 6, 40, 0, 1000, 500000,
  155. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
  156. {"God of Hellfire", 20, -120, 100, 6, 100, 0, 32767, 1000000,
  157. FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS}};
  158. char lastmonst[40]; /* name of the current monster */
  159. MonsterIdType last_monst_id =
  160. MONST_NONE; /* the last monster hitting the player */
  161. int last_monst_hx; /* x location of the last monster hit by player */
  162. int last_monst_hy; /* y location of the last monster hit by player */
  163. char rmst = 80; /* Random monster creation timer */
  164. /* =============================================================================
  165. * Local variables
  166. */
  167. /*
  168. * Monster movement area for the current monster movement
  169. */
  170. static int move_xl, move_yl;
  171. static int move_xh, move_yh;
  172. /*
  173. * The maximum path distance for smart monster movement
  174. */
  175. static int distance;
  176. /*
  177. * The new location for the last monster moved
  178. * These will be set to -1 if the monster died.
  179. */
  180. static int movedx, movedy;
  181. /*
  182. * Rustable armour data
  183. */
  184. #define ARMORTYPES 6
  185. static short rustarm[ARMORTYPES][2] = {{OSTUDLEATHER, -2}, {ORING, -4},
  186. {OCHAIN, -5}, {OSPLINT, -6},
  187. {OPLATE, -8}, {OPLATEARMOR, -9}};
  188. /* =============================================================================
  189. * Local functions
  190. */
  191. /* =============================================================================
  192. * FUNCTION: checkloss
  193. *
  194. * DESCRIPTION:
  195. * Function to subtract hp from user and flag bottomline display.
  196. * Note: if x > c[HP] this routine could kill the player!
  197. *
  198. * PARAMETERS:
  199. *
  200. * x : The number of hitpoints for the player to lose.
  201. *
  202. * RETURN VALUE:
  203. *
  204. * None.
  205. */
  206. static void checkloss(int x) {
  207. if (x > 0) {
  208. losehp(DIED_MONSTER, x);
  209. UpdateStatus();
  210. }
  211. }
  212. /* =============================================================================
  213. * FUNCTION: dropsomething
  214. *
  215. * DESCRIPTION:
  216. * Function to create an object when a monster dies
  217. *
  218. * PARAMETERS:
  219. *
  220. * x : The x location
  221. *
  222. * y : The y location
  223. *
  224. * monst : The monster id.
  225. *
  226. * RETURN VALUE:
  227. *
  228. * None.
  229. */
  230. static void dropsomething(int x, int y, MonsterIdType monst) {
  231. switch (monst) {
  232. case ORC:
  233. case NYMPH:
  234. case ELF:
  235. case TROGLODYTE:
  236. case TROLL:
  237. case ROTHE:
  238. case VIOLETFUNGI:
  239. case PLATINUMDRAGON:
  240. case GNOMEKING:
  241. case REDDRAGON:
  242. something(x, y, level);
  243. return;
  244. case LEPRECHAUN:
  245. if (rnd(101) >= 75)
  246. creategem();
  247. if (rnd(5) == 1)
  248. dropsomething(x, y, LEPRECHAUN);
  249. case LEMMING:
  250. return;
  251. default:
  252. break;
  253. }
  254. }
  255. /* =============================================================================
  256. * FUNCTION: rust_armour
  257. *
  258. * DESCRIPTION:
  259. * Function to rust armour.
  260. *
  261. * PARAMETERS:
  262. *
  263. * None.
  264. *
  265. * RETURN VALUE:
  266. *
  267. * Returns a pointer to the format string to print.
  268. */
  269. static char *rust_armour(void) {
  270. int Armour;
  271. int ArmourId = NULL;
  272. int Shield;
  273. int Rusted = 0;
  274. int i;
  275. int Found;
  276. char *p;
  277. Armour = c[WEAR];
  278. Shield = c[SHIELD];
  279. /*
  280. * Rust the shield, if present and rustable, first
  281. */
  282. if (Shield != -1) {
  283. if (ivenarg[Shield] > -1) {
  284. adjustivenarg(Shield, -1);
  285. Rusted = 1;
  286. }
  287. }
  288. /*
  289. * If nothing rusted yet then rust the armour if possible
  290. */
  291. if (!Rusted && (Armour != -1)) {
  292. /* find the armor in table */
  293. ArmourId = iven[Armour];
  294. i = 0;
  295. Found = 0;
  296. while ((i < ARMORTYPES) && !Found) {
  297. if (ArmourId == rustarm[i][0])
  298. Found = 1;
  299. else
  300. i++;
  301. }
  302. if (Found) {
  303. if (ivenarg[Armour] > rustarm[i][1]) {
  304. adjustivenarg(Armour, -1);
  305. Rusted = 1;
  306. }
  307. }
  308. }
  309. /* if rusting did not occur */
  310. if (!Rusted) {
  311. switch (ArmourId) {
  312. case OLEATHER:
  313. p = "\nThe %s hit you -- you are lucky you have leather on.";
  314. break;
  315. case OSSPLATE:
  316. p = "\nThe %s hit you -- you are fortunate to have stainless steel "
  317. "armor!";
  318. break;
  319. case OELVENCHAIN:
  320. p = "\nThe %s hit you -- you are very lucky to have such strong elven "
  321. "chain!";
  322. break;
  323. default:
  324. p = "\nThe %s hit you.";
  325. break;
  326. }
  327. } else {
  328. UlarnBeep();
  329. p = "\nThe %s hit you -- your armor feels weaker.";
  330. }
  331. return p;
  332. }
  333. /* =============================================================================
  334. * FUNCTION: spattack
  335. *
  336. * DESCRIPTION:
  337. * Function to process special attacks from monsters
  338. *
  339. * atckno monster effect
  340. * ---------------------------------------------------
  341. * 0 none
  342. * 1 rust eat armor
  343. * 2 hell hound breathe light fire
  344. * 3 dragon breathe fire
  345. * 4 giant centipede weakening strength
  346. * 5 white dragon cold breath
  347. * 6 wraith drain level
  348. * 7 waterlord water gusher
  349. * 8 leprechaun steal gold
  350. * 9 disenchantress disenchant weapon or armor
  351. * 10 ice lizard hits with barbed tail
  352. * 11 umber hulk confusion
  353. * 12 spirit naga cast spells taken from special attacks
  354. * 13 platinum dragon psionics
  355. * 14 nymph steal objects
  356. * 15 bugbear bite
  357. * 16 osequip
  358. *
  359. * PARAMETERS:
  360. *
  361. * x : THe special attack number.
  362. *
  363. * xx : The x coordinate of the monster.
  364. *
  365. * yy : The y coordinate of the monster.
  366. *
  367. * RETURN VALUE:
  368. *
  369. * Returns 1 if must do a show1cell(xx,yy)
  370. * return, 0 otherwise
  371. */
  372. static char spsel[] = {1, 2, 3, 5, 6, 8, 9, 11, 13, 14};
  373. static int spattack(int x, int xx, int yy) {
  374. int i;
  375. int m;
  376. char *p = 0;
  377. int need_beep = 0;
  378. int need_show = 0;
  379. int Attempt;
  380. int Disenchant;
  381. MonsterIdType monst;
  382. vxy(xx, yy); /* verify x & y coordinates */
  383. monst = mitem[xx][yy].mon;
  384. /*
  385. * cancel only works 5% of time for demon prince and god
  386. */
  387. if (c[CANCELLATION]) {
  388. if (monst >= DEMONPRINCE) {
  389. if (rnd(100) >= 95)
  390. return 0;
  391. } else
  392. return 0;
  393. }
  394. /* staff of power cancels demonlords/wraiths/vampires 75% of time */
  395. /* lucifer is unaffected */
  396. if (monst != LUCIFER) {
  397. if ((monst >= DEMONLORD) || (monst == WRAITH) || (monst == VAMPIRE))
  398. if (player_has_item(OPSTAFF))
  399. if (rnd(100) < 75)
  400. return 0;
  401. }
  402. /* if have cube of undead control, undead monsters do nothing */
  403. if ((monster[monst].flags & FL_UNDEAD) != 0)
  404. if ((c[CUBEofUNDEAD]) || (c[UNDEADPRO]))
  405. return 0;
  406. switch (x) {
  407. case 1:
  408. p = rust_armour();
  409. /* Recalculate the AC and WC */
  410. recalc();
  411. break;
  412. case 2:
  413. i = rnd(15) + 8 - c[AC];
  414. if (c[FIRERESISTANCE])
  415. p = "\nThe %s's flame doesn't faze you!";
  416. else {
  417. p = "\nThe %s breathes fire at you!";
  418. need_beep = 1;
  419. }
  420. checkloss(i);
  421. break;
  422. case 3:
  423. i = rnd(20) + 25 - c[AC];
  424. if (c[FIRERESISTANCE])
  425. p = "\nThe %s's flame doesn't faze you!";
  426. else {
  427. p = "\nThe %s breathes fire at you!";
  428. need_beep = 1;
  429. }
  430. checkloss(i);
  431. break;
  432. case 4:
  433. if (c[STRENGTH] > 3) {
  434. p = "\nThe %s stung you! You feel weaker.";
  435. need_beep = 1;
  436. adjust_ability(STRENGTH, -1);
  437. } else
  438. p = "\nThe %s stung you!";
  439. break;
  440. case 5:
  441. p = "\nThe %s blasts you with his cold breath.";
  442. i = rnd(15) + 18 - c[AC];
  443. need_beep = 1;
  444. checkloss(i);
  445. break;
  446. case 6:
  447. if (player_has_item(OLIFEPRESERVER))
  448. /* Life preserver prevents all drain life attacks */
  449. return 0;
  450. p = "\nThe %s drains you of your life energy!";
  451. loselevel();
  452. if (monst == DEMONPRINCE)
  453. losemspells(1);
  454. if (monst == LUCIFER) {
  455. loselevel();
  456. losemspells(2);
  457. for (i = STRENGTH; i <= DEXTERITY; i++)
  458. adjust_ability(i, -1);
  459. }
  460. need_beep = 1;
  461. break;
  462. case 7:
  463. p = "\nThe %s got you with a gusher!";
  464. i = rnd(15) + 25 - c[AC];
  465. need_beep = 1;
  466. checkloss(i);
  467. break;
  468. case 8:
  469. /* he has a device of no theft */
  470. if (c[NOTHEFT])
  471. return 0;
  472. if (c[GOLD]) {
  473. p = "\nThe %s hit you. Your purse feels lighter.";
  474. if (c[GOLD] > 32767)
  475. c[GOLD] >>= 1;
  476. else
  477. c[GOLD] -= rnd((int)(1 + (c[GOLD] >> 1)));
  478. if (c[GOLD] < 0)
  479. c[GOLD] = 0;
  480. } else
  481. p = "\nThe %s couldn't find any gold to steal.";
  482. disappear(xx, yy);
  483. need_beep = 1;
  484. need_show = 1;
  485. break;
  486. case 9:
  487. /* disenchant */
  488. Attempt = 50;
  489. Disenchant = 0;
  490. while ((Attempt > 0) && (!Disenchant)) {
  491. /* randomly select item */
  492. i = rund(IVENSIZE);
  493. m = iven[i];
  494. if ((m != ONOTHING) && (ivenarg[i] > 0) && (m != OSCROLL) &&
  495. (m != OPOTION)) {
  496. /* This item can be disenchanted */
  497. Disenchant = 3;
  498. if (ivenarg[i] < Disenchant)
  499. Disenchant = ivenarg[i];
  500. adjustivenarg(i, -Disenchant);
  501. p = "\nThe %s hits you with a spell of disenchantment! ";
  502. need_beep = 1;
  503. show3(i);
  504. Disenchant = 1;
  505. }
  506. Attempt--;
  507. }
  508. /*
  509. * Set the message if the disenchant failed.
  510. */
  511. if (!Disenchant)
  512. p = "\nThe %s nearly misses.";
  513. break;
  514. case 10:
  515. p = "\nThe %s hit you with its barbed tail.";
  516. i = rnd(25) - c[AC];
  517. need_beep = 1;
  518. checkloss(i);
  519. break;
  520. case 11:
  521. if (wizard)
  522. return 0;
  523. p = "\nThe %s has confused you.";
  524. need_beep = 1;
  525. c[CONFUSE] += 10 + rnd(10);
  526. break;
  527. case 12:
  528. /* performs any number of other special attacks */
  529. need_show = spattack(spsel[rund(10)], xx, yy);
  530. break;
  531. case 13:
  532. p = "\nThe %s flattens you with it's psionics!";
  533. i = rnd(15) + 30 - c[AC];
  534. need_beep = 1;
  535. checkloss(i);
  536. break;
  537. case 14:
  538. /* he has device of no theft */
  539. if (c[NOTHEFT])
  540. return 0;
  541. if (emptyhanded() == 1)
  542. p = "\nThe %s couldn't find anything to steal.";
  543. else {
  544. Printf("\nThe %s picks your pocket and takes:", lastmonst);
  545. if (stealsomething(xx, yy) == 0)
  546. Print(" nothing");
  547. teleportmonst(xx, yy, mitem[xx][yy].mon);
  548. need_beep = 1;
  549. need_show = 1;
  550. }
  551. break;
  552. case 15:
  553. i = rnd(10) + 5 - c[AC];
  554. p = "\nThe %s bit you!";
  555. need_beep = 1;
  556. checkloss(i);
  557. break;
  558. case 16:
  559. i = rnd(15) + 10 - c[AC];
  560. p = "\nThe %s bit you!";
  561. need_beep = 1;
  562. checkloss(i);
  563. break;
  564. }
  565. /*
  566. * This attack needs a beep to be played to alert the player
  567. * to bad things.
  568. */
  569. if (need_beep)
  570. UlarnBeep();
  571. /*
  572. * If a message has been set then display the message
  573. */
  574. if (p) {
  575. Printf(p, lastmonst);
  576. recalc();
  577. UpdateStatus();
  578. }
  579. return need_show;
  580. }
  581. /* =============================================================================
  582. * FUNCTION:
  583. *
  584. * DESCRIPTION:
  585. * Function to actually perform the monster movement.
  586. * This function sets MovedX & MovedY to the new monster position, or -1
  587. * if the monster was killed or otherwise removed from the level.
  588. *
  589. * PARAMETERS:
  590. *
  591. * sx : The starting x coordinate of the monster
  592. *
  593. * sy : The starting y coordinate of the monster
  594. *
  595. * dx : The destination x coordinate for the monster
  596. *
  597. * dy : The destination y coordinate for the monster
  598. *
  599. * RETURN VALUE:
  600. *
  601. * None.
  602. */
  603. static void mmove(int sx, int sy, int dx, int dy) {
  604. MonsterIdType monst_id;
  605. int monst_killed = 0;
  606. int have_talisman;
  607. int trap_damage;
  608. int it;
  609. int i;
  610. int n;
  611. char *who;
  612. char *trap_msg;
  613. if ((dx == playerx) && (dy == playery)) {
  614. /* The destination is the player, so the monster attacks */
  615. hitplayer(sx, sy);
  616. moved[sx][sy] = 1;
  617. movedx = sx;
  618. movedy = sy;
  619. return;
  620. }
  621. monst_id = mitem[sx][sy].mon;
  622. it = item[dx][dy];
  623. /* Copy the monster and items it is carrying to the new location */
  624. for (i = 0; i < mitem[sx][sy].n; i++) {
  625. mitem[dx][dy].it[i].item = mitem[sx][sy].it[i].item;
  626. mitem[dx][dy].it[i].itemarg = mitem[sx][sy].it[i].itemarg;
  627. mitem[sx][sy].it[i].item = ONOTHING;
  628. mitem[sx][sy].it[i].itemarg = 0;
  629. }
  630. mitem[dx][dy].n = mitem[sx][sy].n;
  631. mitem[dx][dy].mon = mitem[sx][sy].mon;
  632. /* monsters that move are obviously awake */
  633. stealth[dx][dy] |= STEALTH_AWAKE;
  634. hitp[dx][dy] = hitp[sx][sy];
  635. /* clear the monster from the old location */
  636. mitem[sx][sy].mon = MONST_NONE;
  637. mitem[sx][sy].n = 0;
  638. hitp[sx][sy] = 0;
  639. /* mark this monster as moved */
  640. moved[dx][dy] = 1;
  641. /* perform special processing for monsters */
  642. if (monst_id == LEMMING) {
  643. /* 2% chance moving a lemming creates a new lemming
  644. * in the old spot, holy shit, ten percent? Damn!
  645. */
  646. if (rnd(100) <= 2) {
  647. mitem[sx][sy].mon = LEMMING;
  648. hitp[sx][sy] = hitp[dx][dy];
  649. }
  650. }
  651. if (monst_id == LEPRECHAUN) {
  652. /* leprechaun takes gold and gems */
  653. switch (it) {
  654. case OGOLDPILE:
  655. case OMAXGOLD:
  656. case OKGOLD:
  657. case ODGOLD:
  658. case ODIAMOND:
  659. case ORUBY:
  660. case OEMERALD:
  661. case OSAPPHIRE:
  662. if (mitem[dx][dy].n < 6) {
  663. n = mitem[dx][dy].n;
  664. mitem[dx][dy].it[n].item = item[dx][dy];
  665. mitem[dx][dy].it[n].itemarg = iarg[dx][dy];
  666. mitem[dx][dy].n++;
  667. }
  668. item[dx][dy] = ONOTHING;
  669. iarg[dx][dy] = 0;
  670. break;
  671. default:
  672. break;
  673. }
  674. }
  675. if (monst_id == TROLL) {
  676. /* if a troll regenerate him */
  677. if ((gtime & 1) == 0)
  678. if (monster[monst_id].hitpoints > hitp[dx][dy])
  679. hitp[dx][dy]++;
  680. }
  681. /* check for monsters walking into traps and spheres of annihilation */
  682. trap_damage = 0;
  683. trap_msg = NULL;
  684. who = "";
  685. if (it == OANNIHILATION) {
  686. /* demons dispel spheres */
  687. if (monst_id >= DEMONLORD) {
  688. have_talisman = player_has_item(OSPHTALISMAN);
  689. if ((!have_talisman) ||
  690. (have_talisman && (monst_id == LUCIFER) && (rnd(10) > 7))) {
  691. /* delete the sphere */
  692. trap_msg = "\nThe %s%s dispels the sphere!";
  693. rmsphere(dx, dy);
  694. } else {
  695. /* monster annihilated */
  696. trap_msg = "\nThe %s%s is destroyed by the sphere of annihilation!";
  697. mitem[dx][dy].mon = MONST_NONE;
  698. mitem[dx][dy].n = 0;
  699. hitp[dx][dy] = 0;
  700. monst_killed = 1;
  701. }
  702. } else {
  703. /* monster annihilated */
  704. trap_msg = "\nThe %s%s is destroyed by the sphere of annihilation!";
  705. mitem[dx][dy].mon = MONST_NONE;
  706. mitem[dx][dy].n = 0;
  707. hitp[dx][dy] = 0;
  708. monst_killed = 1;
  709. }
  710. } else if (it == OTRAPARROW) {
  711. who = "An arrow";
  712. trap_damage = rnd(10) + level;
  713. } else if (it == ODARTRAP) {
  714. who = "A dart";
  715. trap_damage = rnd(6);
  716. } else if (it == OTELEPORTER) {
  717. /* monster hits teleport trap */
  718. if (monst_id < DEMONLORD) {
  719. trap_msg = "\nThe %s%s gets teleported.";
  720. teleportmonst(dx, dy, mitem[dx][dy].mon);
  721. dx = movedx;
  722. dy = movedy;
  723. }
  724. } else if (it == OPIT) {
  725. if ((monster[monst_id].flags & FL_FLY) == 0) {
  726. /* non-flying monsters can fall into pits and trap doors */
  727. trap_msg = "\nThe %s%s fell into a pit.";
  728. mitem[dx][dy].mon = MONST_NONE;
  729. hitp[dx][dy] = 0;
  730. monst_killed = 1;
  731. }
  732. } else if (it == OTRAPDOOR) {
  733. if ((monster[monst_id].flags & FL_FLY) == 0) {
  734. /* non-flying monsters can fall into pits and trap doors */
  735. trap_msg = "\nThe %s%s fell through a trapdoor.";
  736. mitem[dx][dy].mon = MONST_NONE;
  737. hitp[dx][dy] = 0;
  738. monst_killed = 1;
  739. }
  740. } else if ((it == OELEVATORUP) || (it == OELEVATORDOWN)) {
  741. /* The monster enters an elevator */
  742. if (monst_id < DEMONLORD) {
  743. trap_msg = "\nThe %s%s is carried away by an elevator!";
  744. mitem[dx][dy].mon = MONST_NONE;
  745. hitp[dx][dy] = 0;
  746. monst_killed = 1;
  747. }
  748. }
  749. if (trap_damage > 0) {
  750. /* the monster was damaged by a trap */
  751. hitp[dx][dy] -= (short)trap_damage;
  752. if (hitp[dx][dy] <= 0) {
  753. /* the trap killed the monster */
  754. mitem[dx][dy].mon = MONST_NONE;
  755. trap_msg = "\n%s hits and kills the %s.";
  756. monst_killed = 1;
  757. } else
  758. trap_msg = "\n%s hits the %s.";
  759. }
  760. /*
  761. * Store the location to which this monster has been moved, or -1 if
  762. * the monster was destroyed
  763. */
  764. if (monst_killed) {
  765. movedx = -1;
  766. movedy = -1;
  767. } else {
  768. movedx = dx;
  769. movedy = dy;
  770. }
  771. /* if blind don't show where monsters are */
  772. if (c[BLINDCOUNT])
  773. return;
  774. if (know[dx][dy] != OUNKNOWN) {
  775. if (trap_msg != NULL) {
  776. Printf(trap_msg, who, monster[monst_id].name);
  777. UlarnBeep();
  778. }
  779. }
  780. if ((monst_id >= DEMONLORD) && (monst_id <= LUCIFER) && (c[EYEOFLARN] == 0))
  781. /*
  782. * don't update the screen for demonlords and above if the player
  783. * doesn't have the eye of larn as the player can't see the monster.
  784. */
  785. return;
  786. /* Update the screen */
  787. if (know[sx][sy] != OUNKNOWN)
  788. show1cell(sx, sy);
  789. if (know[dx][dy] != OUNKNOWN)
  790. show1cell(dx, dy);
  791. }
  792. /* =============================================================================
  793. * FUNCTION: valid_monst_move
  794. *
  795. * DESCRIPTION:
  796. * Check if the location x, y is a valid place for monster monst_id to move
  797. * or attack.
  798. * Does NOT check if the location is already occupied by another monster.
  799. *
  800. * PARAMETERS:
  801. *
  802. * x : The x coordinate to check
  803. *
  804. * y : THe y coordinate to check
  805. *
  806. * monst_id : The monster id
  807. *
  808. * RETURN VALUE:
  809. *
  810. * 0 if the monster cannot occupy to this position
  811. * 1 if the monster can occupy to this postion
  812. */
  813. static int valid_monst_move(int x, int y, MonsterIdType monst_id) {
  814. int tmpitem;
  815. int at_entrance; /* flag indicating that this is the dungeon entrance */
  816. int at_player; /* flag that this is the player's location */
  817. int blocked; /* flag that the monster canot move here (wall etc) */
  818. int monster_special; /* flag that there is a special reason the monster */
  819. /* can't move here */
  820. tmpitem = item[x][y];
  821. at_player = (x == playerx) && (y == playery);
  822. at_entrance = (x == 33) && (y == MAXY - 1) && (level == 1);
  823. /*
  824. * A monster cannot pass through a closed door or a wall.
  825. * However, while a monster cannot hit the player through a closed door
  826. * a monster can hit a player who is walking through walls.
  827. */
  828. blocked = (tmpitem == OCLOSEDDOOR) || ((tmpitem == OWALL) && !at_player);
  829. /*
  830. * Vampires will not move onto mirrors.
  831. */
  832. monster_special = (monst_id == VAMPIRE) && (tmpitem == OMIRROR);
  833. if (monst_id >= DEMONPRINCE)
  834. /* walls and closed doors are no hindrance to a demon prince or above */
  835. blocked = 0;
  836. if (at_entrance || blocked || monster_special)
  837. /* Return 0 (false) to indicate illegal position */
  838. return 0;
  839. else
  840. return 1;
  841. }
  842. /* =============================================================================
  843. * FUNCTION: smart_move
  844. *
  845. * DESCRIPTION:
  846. * Function to move smart monsters.
  847. *
  848. * PARAMETERS:
  849. *
  850. * x : The x coordinate of the monster.
  851. *
  852. * y : The y coordinate of the monster.
  853. *
  854. * RETURN VALUE:
  855. *
  856. * None.
  857. */
  858. static void smart_move(int x, int y) {
  859. int sx, sy;
  860. int xl, yl;
  861. int xh, yh;
  862. int xtmp, ytmp;
  863. int path_dist;
  864. int found_path;
  865. MonsterIdType monst;
  866. int on_map;
  867. int z;
  868. monst = mitem[x][y].mon;
  869. /* get the screen region to check for monster movement */
  870. xl = move_xl - 2;
  871. yl = move_yl - 2;
  872. xh = move_xh + 2;
  873. yh = move_yh + 2;
  874. vxy(xl, yl);
  875. vxy(xh, yh);
  876. for (sy = yl; sy <= yh; sy++) {
  877. for (sx = xl; sx <= xh; sx++) {
  878. if (valid_monst_move(sx, sy, monst)) {
  879. if (monst >= DEMONPRINCE)
  880. /* Monsters of rank DEMONPRICE and above ignore traps etc */
  881. screen[sx][sy] = 0;
  882. else {
  883. /* smart monsters will avoid traps */
  884. switch (item[sx][sy]) {
  885. case OELEVATORUP:
  886. case OELEVATORDOWN:
  887. case OTRAPARROW:
  888. case ODARTRAP:
  889. case OTELEPORTER:
  890. /* all monsters avoid there traps */
  891. screen[sx][sy] = 127;
  892. break;
  893. case OPIT:
  894. case OTRAPDOOR:
  895. if ((monster[monst].flags & FL_FLY) != 0)
  896. /* flying monsters ignore pits and trap doors. */
  897. screen[sx][sy] = 0;
  898. else
  899. screen[sx][sy] = 127;
  900. break;
  901. default:
  902. screen[sx][sy] = 0;
  903. break;
  904. }
  905. }
  906. } else
  907. /* not valid for this monster to move here */
  908. screen[sx][sy] = 127;
  909. /* if valid move */
  910. } /* for sx */
  911. } /* for sy */
  912. /* Mark the player's location */
  913. screen[playerx][playery] = 1;
  914. /* now perform proximity ripple from playerx, playery to monster */
  915. xl = move_xl - 1;
  916. yl = move_yl - 1;
  917. xh = move_xh + 1;
  918. yh = move_yh + 1;
  919. vxy(xl, yl);
  920. vxy(xh, yh);
  921. path_dist = 1;
  922. found_path = 0;
  923. while ((path_dist < distance) && (!found_path)) {
  924. for (sy = yl; sy <= yh; sy++) {
  925. for (sx = xl; sx <= xh; sx++) {
  926. if (screen[sx][sy] == path_dist) {
  927. /*
  928. * This square is path_dist steps from the player, so advance
  929. * the path by one in all directions not already part of a path.
  930. */
  931. for (z = 1; z < 9; z++) {
  932. xtmp = sx + diroffx[z];
  933. ytmp = sy + diroffy[z];
  934. if ((xtmp >= 0) && (xtmp < MAXX) && (ytmp >= 0) && (ytmp < MAXY)) {
  935. /* This square is within the map */
  936. if (screen[xtmp][ytmp] == 0) {
  937. /*
  938. * a valid position that is not part of a path has been found,
  939. * so mark it as path_dist + 1 away from the player
  940. */
  941. screen[xtmp][ytmp] = (char)(path_dist + 1);
  942. if ((xtmp == x) && (ytmp == y))
  943. found_path = 1;
  944. }
  945. } /* if xtmp, ytmp on map */
  946. } /* for each direction */
  947. } /* if found path end */
  948. } /* for sx */
  949. } /* for sy */
  950. path_dist++;
  951. }
  952. if (found_path) {
  953. /* did find connectivity */
  954. /*
  955. * Now find the square with a distance 1 lower than the distance to the
  956. * monster being moved.
  957. */
  958. path_dist = screen[x][y] - 1;
  959. for (z = 1; z < 9; z++) {
  960. xl = x + diroffx[z];
  961. yl = y + diroffy[z];
  962. if (level == 0)
  963. /*
  964. * On the home level monsters can move right to the edge
  965. * of the map
  966. */
  967. on_map = checkxy(xl, yl);
  968. else
  969. /*
  970. * In the dungeon and volcano monsters can not move onto the
  971. * outer border of walls.
  972. */
  973. on_map =
  974. ((xl >= 1) && (xl < (MAXX - 1)) && (yl >= 1) && (yl < (MAXY - 1)));
  975. if (on_map) {
  976. if (screen[xl][yl] == path_dist) {
  977. if (mitem[xl][yl].mon == MONST_NONE) {
  978. mmove(x, y, xl, yl);
  979. return;
  980. }
  981. }
  982. }
  983. }
  984. }
  985. }
  986. /* =============================================================================
  987. * FUNCTION: dumb_move
  988. *
  989. * DESCRIPTION:
  990. * Function to move dumb monsters.
  991. *
  992. * PARAMETERS:
  993. *
  994. * x : The x coordinate of the monster.
  995. *
  996. * y : The y coordinate of the monster.
  997. *
  998. * RETURN VALUE:
  999. *
  1000. * None.
  1001. */
  1002. static void dumb_move(int x, int y) {
  1003. MonsterIdType monst_id;
  1004. short w1[9], w1x[9], w1y[9];
  1005. int xl, yl;
  1006. int xh, yh;
  1007. int tx, ty;
  1008. int j, k;
  1009. int tmp;
  1010. monst_id = mitem[x][y].mon;
  1011. xl = x - 1;
  1012. yl = y - 1;
  1013. xh = x + 2;
  1014. yh = y + 2;
  1015. if (x < playerx)
  1016. xl++;
  1017. else if (x > playerx)
  1018. xh--;
  1019. if (y < playery)
  1020. yl++;
  1021. else if (y > playery)
  1022. yh--;
  1023. if (xl < 0)
  1024. xl = 0;
  1025. if (xh > MAXX)
  1026. xh = MAXX;
  1027. if (yl < 0)
  1028. yl = 0;
  1029. if (yh > MAXY)
  1030. yh = MAXY;
  1031. for (k = 0; k < 9; k++)
  1032. w1[k] = 10000;
  1033. /* For each square compute distance to player */
  1034. tmp = 0;
  1035. for (tx = xl; tx < xh; tx++) {
  1036. for (ty = yl; ty < yh; ty++) {
  1037. if (valid_monst_move(tx, ty, monst_id) &&
  1038. (mitem[tx][ty].mon == MONST_NONE)) {
  1039. w1[tmp] = (short)((playerx - tx) * (playerx - tx) +
  1040. (playery - ty) * (playery - ty));
  1041. w1x[tmp] = (short)tx;
  1042. w1y[tmp] = (short)ty;
  1043. }
  1044. tmp++;
  1045. }
  1046. }
  1047. /* find the closest square in the search area */
  1048. j = 0;
  1049. for (k = 1; k < 9; k++)
  1050. if (w1[k] < w1[j])
  1051. j = k;
  1052. if ((w1[j] < 10000) && ((x != w1x[j]) || (y != w1y[j])))
  1053. mmove(x, y, w1x[j], w1y[j]);
  1054. }
  1055. /* =============================================================================
  1056. * FUNCTION: scared_move
  1057. *
  1058. * DESCRIPTION:
  1059. * Function to move scared monsters.
  1060. *
  1061. * PARAMETERS:
  1062. *
  1063. * x : The x coordinate of the monster.
  1064. *
  1065. * y : The y coordinate of the monster.
  1066. *
  1067. * RETURN VALUE:
  1068. *
  1069. * None.
  1070. */
  1071. static void scared_move(int x, int y) {
  1072. int nx, ny;
  1073. /* move in random direction */
  1074. nx = x + rnd(3) - 2;
  1075. ny = y + rnd(3) - 2;
  1076. if (nx < 0)
  1077. nx = 0;
  1078. if (nx >= MAXX)
  1079. nx = MAXX - 1;
  1080. if (ny < 0)
  1081. ny = 0;
  1082. if (ny >= MAXY)
  1083. ny = MAXY - 1;
  1084. if (valid_monst_move(nx, ny, mitem[x][y].mon) &&
  1085. (mitem[nx][ny].mon == MONST_NONE))
  1086. /* This is a valid place to move, so move there */
  1087. mmove(x, y, nx, ny);
  1088. return;
  1089. }
  1090. /* =============================================================================
  1091. * FUNCTION: movemt
  1092. *
  1093. * DESCRIPTION:
  1094. * This routine is responsible for determining where one monster at (x,y)
  1095. * will move to.
  1096. *
  1097. * PARAMETERS:
  1098. *
  1099. * x : The x coordinate of the monster.
  1100. *
  1101. * y : The y coordinate of the monster.
  1102. *
  1103. * RETURN VALUE:
  1104. *
  1105. * None.
  1106. */
  1107. static void movemt(int x, int y) {
  1108. int Scared;
  1109. MonsterIdType monst;
  1110. monst = mitem[x][y].mon;
  1111. /* half speed monsters only move every other turn */
  1112. if ((monster[monst].flags & FL_SLOW) != 0)
  1113. if ((gtime & 1) == 1)
  1114. return;
  1115. /* choose destination randomly if scared */
  1116. /* Check for hand of fear */
  1117. Scared = player_has_item(OHANDofFEAR);
  1118. if (c[SCAREMONST])
  1119. /*
  1120. * hand of fear is scarier (may work on higher level monsters) if scare
  1121. * monster is in effect.
  1122. */
  1123. Scared++;
  1124. else if ((Scared == 1) && (rnd(10) > 4))
  1125. /*
  1126. * Hand of fear alone is only effective 60% of the time
  1127. */
  1128. Scared = 0;
  1129. if ((monst > DEMONLORD) || (monst == PLATINUMDRAGON))
  1130. /*
  1131. * A demon lord or higher is only scared if the player has both
  1132. * the hand of fear and scare monster active.
  1133. * Even then, only half the time
  1134. */
  1135. Scared = (Scared <= 1) ? 0 : (rnd(10) > 5);
  1136. /* Call the appropriate move routine */
  1137. if (Scared)
  1138. scared_move(x, y);
  1139. else if (monster[monst].intelligence > 10 - c[HARDGAME])
  1140. smart_move(x, y);
  1141. else
  1142. dumb_move(x, y);
  1143. }
  1144. /* =============================================================================
  1145. * Exported functions
  1146. */
  1147. /* =============================================================================
  1148. * FUNCTION: createmonster
  1149. */
  1150. void createmonster(MonsterIdType mon) {
  1151. int x, y, k, i;
  1152. if (mon < 1 || mon > MAXMONST + 8) {
  1153. UlarnBeep();
  1154. Printf("\ncan't createmonst(%d)\n", (long)mon);
  1155. nap(3000);
  1156. return;
  1157. }
  1158. while ((monster[mon].flags & FL_GENOCIDED) != 0 && (mon < MAXMONST)) {
  1159. mon++; /* genocided? */
  1160. }
  1161. /* choose direction, then try all */
  1162. for (k = rnd(8), i = -8; i < 0; i++, k++) {
  1163. if (k > 8)
  1164. k = 1; /* wraparound the diroff arrays */
  1165. x = playerx + diroffx[k];
  1166. y = playery + diroffy[k];
  1167. /* if we can create a monster here */
  1168. if (cgood(x, y, 0, 1)) {
  1169. mitem[x][y].mon = (char)mon;
  1170. hitp[x][y] = monster[mon].hitpoints;
  1171. stealth[x][y] = 0; /* New monsters are not seen or awake */
  1172. switch (mon) {
  1173. case ROTHE:
  1174. case POLTERGEIST:
  1175. case VAMPIRE:
  1176. /* These monsters are initially awake */
  1177. stealth[x][y] |= STEALTH_AWAKE;
  1178. break;
  1179. default:
  1180. break;
  1181. };
  1182. return;
  1183. }
  1184. }
  1185. }
  1186. /* =============================================================================
  1187. * FUNCTION: mon_has_item
  1188. */
  1189. int mon_has_item(int x, int y, int Item) {
  1190. int has_item;
  1191. int i;
  1192. has_item = 0;
  1193. if (mitem[x][y].mon != 0) {
  1194. for (i = 0; i < mitem[x][y].n; i++)
  1195. if (mitem[x][y].it[i].item == Item)
  1196. has_item = 1;
  1197. }
  1198. return has_item;
  1199. }
  1200. /* =============================================================================
  1201. * FUNCTION: fullhit
  1202. */
  1203. int fullhit(int xx) {
  1204. int i;
  1205. if ((xx < 0) || (xx > 20))
  1206. return 0; /* fullhits are out of range */
  1207. if (c[LANCEDEATH])
  1208. return 10000; /* lance of death */
  1209. i = xx * ((c[WCLASS] >> 1) + c[STRENGTH] + c[STREXTRA] - c[HARDGAME] - 12 +
  1210. c[MOREDAM]);
  1211. return (i >= 1) ? i : xx;
  1212. }
  1213. /* =============================================================================
  1214. * FUNCTION: ifblind
  1215. */
  1216. void ifblind(int x, int y) {
  1217. char *s;
  1218. vxy(x, y); /* verify correct x,y coordinates */
  1219. if (c[BLINDCOUNT]) {
  1220. last_monst_id = MONST_NONE;
  1221. s = "monster";
  1222. } else {
  1223. last_monst_id = mitem[x][y].mon;
  1224. s = monster[last_monst_id].name;
  1225. }
  1226. strcpy(lastmonst, s);
  1227. }
  1228. /* =============================================================================
  1229. * FUNCTION: hitmonster
  1230. */
  1231. void hitmonster(int x, int y) {
  1232. int tmp, damag, flag;
  1233. MonsterIdType monst;
  1234. if (c[TIMESTOP])
  1235. return; /* not if time stopped */
  1236. vxy(x, y); /* verify coordinates are within range */
  1237. if ((monst = mitem[x][y].mon) == MONST_NONE)
  1238. return;
  1239. hit3flag = 1;
  1240. ifblind(x, y);
  1241. tmp = monster[monst].armorclass + c[LEVEL] + c[DEXTERITY] + c[WCLASS] / 4 -
  1242. 12 - c[HARDGAME];
  1243. /* need at least random chance to hit */
  1244. if ((rnd(20) < tmp) || (rnd(71) < 5)) {
  1245. Print("\nYou hit");
  1246. flag = 1;
  1247. damag = fullhit(1);
  1248. if (damag < 9999)
  1249. damag = rnd(damag) + 1;
  1250. } else {
  1251. Print("\nYou missed");
  1252. flag = 0;
  1253. }
  1254. Printf(" the %s.", lastmonst);
  1255. /*
  1256. * If the monser was hit, deal with weapon dulling.
  1257. */
  1258. if (flag &&
  1259. (monst == RUSTMONSTER || monst == DISENCHANTRESS || monst == CUBE) &&
  1260. (c[WIELD] >= 0)) {
  1261. /* if it's not already dulled to hell */
  1262. if (((ivenarg[c[WIELD]] > -10) &&
  1263. ((iven[c[WIELD]] == OSLAYER) || (iven[c[WIELD]] == ODAGGER) ||
  1264. (iven[c[WIELD]] == OSPEAR) || (iven[c[WIELD]] == OFLAIL) ||
  1265. (iven[c[WIELD]] == OBATTLEAXE) || (iven[c[WIELD]] == OLONGSWORD) ||
  1266. (iven[c[WIELD]] == O2SWORD) || (iven[c[WIELD]] == OLANCE) ||
  1267. (iven[c[WIELD]] == OHAMMER) || (iven[c[WIELD]] == OVORPAL) ||
  1268. (iven[c[WIELD]] == OBELT))) ||
  1269. (ivenarg[c[WIELD]] > 0)) {
  1270. Printf("\nYour weapon is dulled by the %s.", lastmonst);
  1271. UlarnBeep();
  1272. adjustivenarg(c[WIELD], -1);
  1273. } else if (ivenarg[c[WIELD]] <= -10) {
  1274. /* Destroy the weapon if it is too badly damaged */
  1275. Printf("\nYour weapon disintegrates!");
  1276. /* Adjust character attributes for the destroyed item */
  1277. adjustcvalues(iven[c[WIELD]], ivenarg[c[WIELD]]);
  1278. /* Destroy the item */
  1279. iven[c[WIELD]] = ONOTHING;
  1280. ivenarg[c[WIELD]] = 0;
  1281. /* No longer wielding anything */
  1282. c[WIELD] = -1;
  1283. /* Didn't hit after all... */
  1284. flag = 0;
  1285. }
  1286. /* Recalculate WC */
  1287. recalc();
  1288. UpdateStatus();
  1289. }
  1290. if (flag) {
  1291. hitm(x, y, damag, 0);
  1292. if ((monst >= DEMONLORD) && (c[LANCEDEATH]) && (hitp[x][y]))
  1293. Printf("\nYour lance of death tickles the %s!", lastmonst);
  1294. }
  1295. if (monst == METAMORPH) {
  1296. if (hitp[x][y] < 25 && hitp[x][y] > 0) {
  1297. mitem[x][y].mon = (char)(BRONZEDRAGON + rund(9));
  1298. show1cell(x, y);
  1299. }
  1300. }
  1301. if (mitem[x][y].mon == LEMMING)
  1302. if (rnd(100) <= 10)
  1303. createmonster(LEMMING); /* was 40, now 10 */
  1304. }
  1305. /* =============================================================================
  1306. * FUNCTION: hitm
  1307. */
  1308. int hitm(int x, int y, int amt, int SpellFlag) {
  1309. MonsterIdType monst;
  1310. int hpoints;
  1311. int amt2;
  1312. vxy(x, y); /* verify coordinates are within range */
  1313. amt2 = amt; /* save initial damage so we can return it */
  1314. monst = mitem[x][y].mon;
  1315. /* if half damage curse adjust damage points */
  1316. if (c[HALFDAM])
  1317. amt >>= 1;
  1318. if (amt <= 0) {
  1319. amt2 = 1;
  1320. amt = 1;
  1321. }
  1322. last_monst_hx = (char)x;
  1323. last_monst_hy = (char)y;
  1324. /* make sure hitting monst wakes the monster */
  1325. stealth[x][y] |= STEALTH_AWAKE;
  1326. if (c[HOLDMONST] > 0) {
  1327. /*
  1328. * Hit a monster breaks hold monster spell.
  1329. * Set HOLDMONST counter to 1 so the next regen will cancel the effect.
  1330. */
  1331. c[HOLDMONST] = 1;
  1332. }
  1333. /* if a dragon and orb(s) of dragon slaying */
  1334. if (c[SLAYING]) {
  1335. switch (monst) {
  1336. case WHITEDRAGON:
  1337. case REDDRAGON:
  1338. case GREENDRAGON:
  1339. case BRONZEDRAGON:
  1340. case PLATINUMDRAGON:
  1341. case SILVERDRAGON:
  1342. amt *= 3;
  1343. break;
  1344. default:
  1345. break;
  1346. }
  1347. }
  1348. if (!SpellFlag) {
  1349. /* Deal with weapon based effects */
  1350. /* Deal with Vorpy */
  1351. if ((c[WIELD] > 0) && (iven[c[WIELD]] == OVORPAL) && (rnd(20) == 1) &&
  1352. ((monster[monst].flags & FL_HEAD) != 0) &&
  1353. ((monster[monst].flags & FL_NOBEHEAD) == 0)) {
  1354. Printf("\nThe Vorpal Blade beheads the %s!", lastmonst);
  1355. amt = hitp[x][y];
  1356. }
  1357. if (monst >= DEMONLORD) {
  1358. if (c[LANCEDEATH])
  1359. amt = 300;
  1360. if (iven[c[WIELD]] == OSLAYER)
  1361. amt = 10000;
  1362. }
  1363. }
  1364. hpoints = hitp[x][y];
  1365. if (hpoints <= amt) {
  1366. int i;
  1367. Printf("\nThe %s died!", lastmonst);
  1368. raiseexperience((long)monster[monst].experience);
  1369. disappear(x, y);
  1370. if (mitem[x][y].n > 0) {
  1371. for (i = 0; i < mitem[x][y].n; i++) {
  1372. createitem(x, y, mitem[x][y].it[i].item, mitem[x][y].it[i].itemarg);
  1373. }
  1374. beenhere[level] -= mitem[x][y].n;
  1375. if (beenhere[level] < 1)
  1376. beenhere[level] = 1;
  1377. mitem[x][y].n = 0;
  1378. if ((amt = monster[monst].gold) > 0)
  1379. dropgold(rnd(amt) + amt);
  1380. } else {
  1381. if ((amt = monster[monst].gold) > 0)
  1382. dropgold(rnd(amt) + amt);
  1383. dropsomething(x, y, monst);
  1384. }
  1385. show1cell(x, y);
  1386. showcell(playerx, playery);
  1387. recalc();
  1388. UpdateStatus();
  1389. hitp[x][y] = 0;
  1390. return hpoints;
  1391. }
  1392. hitp[x][y] = (short)(hpoints - amt);
  1393. return amt2;
  1394. }
  1395. /* =============================================================================
  1396. * FUNCTION: hitplayer
  1397. */
  1398. void hitplayer(int x, int y) {
  1399. register int dam, bias;
  1400. int hit_success;
  1401. int at_chance;
  1402. MonsterIdType mster;
  1403. vxy(x, y); /* verify coordinates are within range */
  1404. last_monst_id = mitem[x][y].mon;
  1405. mster = mitem[x][y].mon;
  1406. if (know[x][y] == OUNKNOWN)
  1407. show1cell(x, y);
  1408. bias = (c[HARDGAME]) + 1;
  1409. hitflag = hit2flag = hit3flag = 1;
  1410. yrepcount = 0;
  1411. ifblind(x, y);
  1412. if (mster == LEMMING)
  1413. return;
  1414. if ((monster[mster].flags & FL_INFRAVIS) == 0) {
  1415. /* Monsters without infravision might miss invisible players */
  1416. if (c[INVISIBILITY])
  1417. if (rnd(33) < 20) {
  1418. Printf("\nThe %s misses wildly!", lastmonst);
  1419. return;
  1420. }
  1421. }
  1422. if ((mster < DEMONLORD) && (mster != PLATINUMDRAGON)) {
  1423. if (c[CHARMCOUNT]) {
  1424. if (rnd(30) + 5 * monster[mster].level - c[CHARISMA] < 30) {
  1425. Printf("\nThe %s is awestruck by your magnificence!", lastmonst);
  1426. return;
  1427. }
  1428. }
  1429. }
  1430. dam = monster[mster].damage;
  1431. dam += rnd((int)((dam < 1) ? 1 : dam)) + monster[mster].level;
  1432. /*
  1433. * demon lords/prince/god of hellfire damage is reduced if wielding
  1434. * Slayer
  1435. */
  1436. if (mster >= DEMONLORD) {
  1437. if (iven[c[WIELD]] == OSLAYER)
  1438. /* does between 1/10 and 1/2 damage */
  1439. dam = (rnd(5) * dam) / 10;
  1440. }
  1441. /*
  1442. * spirit naga's and poltergeist's damage is halved if scarab of
  1443. * negate spirit
  1444. */
  1445. if (c[NEGATESPIRIT] || c[SPIRITPRO])
  1446. if ((monster[mster].flags & FL_SPIRIT) != 0)
  1447. dam = (int)dam / 2;
  1448. /* halved if undead and cube of undead control */
  1449. if (c[CUBEofUNDEAD] || c[UNDEADPRO])
  1450. if ((monster[mster].flags & FL_UNDEAD) != 0)
  1451. dam = (int)dam / 2;
  1452. hit_success = 0;
  1453. at_chance = max(c[AC], 1);
  1454. if (monster[mster].attack > 0) {
  1455. /*
  1456. * If the hit isn't good enough to do a special attack on its own then
  1457. * a monster has a 1:at_chance of performing a special attack
  1458. */
  1459. if (((dam + bias + 8) > c[AC]) || (rnd(at_chance) == 1)) {
  1460. if (spattack(monster[mster].attack, x, y))
  1461. /* The monster successfully performed a special attack */
  1462. return;
  1463. else {
  1464. /*
  1465. * The monster did a special attack and failed to affect the player,
  1466. * so note that the monster hit and weaken the normal attack.
  1467. */
  1468. hit_success = 1;
  1469. bias -= 2;
  1470. }
  1471. }
  1472. }
  1473. if (((dam + bias) > c[AC]) || (rnd(at_chance) == 1)) {
  1474. Printf("\n The %s hit you.", lastmonst);
  1475. hit_success = 1;
  1476. /* Reduce the damage by the player's AC */
  1477. dam -= c[AC];
  1478. if (dam < 0)
  1479. dam = 0;
  1480. if (dam > 0) {
  1481. losehp(DIED_MONSTER, dam);
  1482. UpdateStatus();
  1483. }
  1484. }
  1485. if (hit_success == 0)
  1486. Printf("\n The %s missed.", lastmonst);
  1487. }
  1488. /* =============================================================================
  1489. * FUNCTION: makemonst
  1490. */
  1491. int makemonst(int lev) {
  1492. int tmp;
  1493. int min_monst_id;
  1494. int max_monst_id;
  1495. int num_ids;
  1496. if (lev < 1)
  1497. lev = 1;
  1498. if (lev > 12)
  1499. lev = 12;
  1500. tmp = WATERLORD;
  1501. if (lev < 5) {
  1502. min_monst_id = 1;
  1503. max_monst_id = monstlevel[lev - 1];
  1504. } else {
  1505. min_monst_id = monstlevel[lev - 4] + 1;
  1506. max_monst_id = monstlevel[lev - 1];
  1507. }
  1508. num_ids = (max_monst_id - min_monst_id) + 1;
  1509. while (tmp == WATERLORD)
  1510. tmp = min_monst_id + rund(num_ids);
  1511. while ((monster[tmp].flags & FL_GENOCIDED) != 0 && (tmp < MAXMONST))
  1512. tmp++;
  1513. if (level <= DBOTTOM)
  1514. if (rnd(100) < 10)
  1515. tmp = LEMMING;
  1516. return tmp;
  1517. }
  1518. /* =============================================================================
  1519. * FUNCTION: randmonst
  1520. */
  1521. void randmonst(void) {
  1522. /* don't make monsters if time is stopped */
  1523. if (c[TIMESTOP])
  1524. return;
  1525. rmst--;
  1526. if (rmst <= 0) {
  1527. rmst = (char)(120 - (level << 2));
  1528. fillmonst(makemonst(level));
  1529. }
  1530. }
  1531. /* =============================================================================
  1532. * FUNCTION: teleportmonst
  1533. */
  1534. void teleportmonst(int xx, int yy, int monst) {
  1535. int i;
  1536. int x, y;
  1537. int trys;
  1538. /* max # of teleport attempts */
  1539. for (trys = 10; trys > 0; --trys) {
  1540. x = rnd(MAXX - 2);
  1541. y = rnd(MAXY - 2);
  1542. if ((item[x][y] == ONOTHING) && (mitem[x][y].mon == MONST_NONE) &&
  1543. ((playerx != x) || (playery != y))) {
  1544. mitem[x][y].mon = (char)monst;
  1545. mitem[xx][yy].mon = MONST_NONE;
  1546. hitp[x][y] = monster[monst].hitpoints;
  1547. hitp[xx][yy] = 0;
  1548. for (i = 0; i < mitem[xx][yy].n; i++) {
  1549. mitem[x][y].it[i].item = mitem[xx][yy].it[i].item;
  1550. mitem[x][y].it[i].itemarg = mitem[xx][yy].it[i].itemarg;
  1551. mitem[xx][yy].it[i].item = ONOTHING;
  1552. mitem[xx][yy].it[i].itemarg = 0;
  1553. }
  1554. mitem[x][y].n = mitem[xx][yy].n;
  1555. mitem[xx][yy].n = 0;
  1556. /* store the new location */
  1557. movedx = x;
  1558. movedy = y;
  1559. show1cell(xx, yy);
  1560. return;
  1561. }
  1562. }
  1563. }
  1564. /* =============================================================================
  1565. * FUNCTION: movemonst
  1566. */
  1567. void movemonst(void) {
  1568. int i, j;
  1569. /* no action if time is stopped */
  1570. if (c[TIMESTOP])
  1571. return;
  1572. /* Check for haste self */
  1573. if (c[HASTESELF])
  1574. if ((c[HASTESELF] & 1) == 0)
  1575. return;
  1576. /* move the spheres of annihilation if any */
  1577. movsphere();
  1578. /* no action if monsters are held */
  1579. if (c[HOLDMONST])
  1580. return;
  1581. if (c[AGGRAVATE]) {
  1582. /* determine window of monsters to move */
  1583. move_yl = playery - 5;
  1584. move_yh = playery + 6;
  1585. move_xl = playerx - 10;
  1586. move_xh = playerx + 11;
  1587. distance = 40; /* depth of intelligent monster movement */
  1588. } else {
  1589. move_yl = playery - 3;
  1590. move_yh = playery + 4;
  1591. move_xl = playerx - 5;
  1592. move_xh = playerx + 6;
  1593. distance = 17; /* depth of intelligent monster movement */
  1594. }
  1595. if (level == 0) {
  1596. /* if on outside level monsters can move in perimeter */
  1597. if (move_yl < 0)
  1598. move_yl = 0;
  1599. if (move_yh > MAXY)
  1600. move_yh = MAXY;
  1601. if (move_xl < 0)
  1602. move_xl = 0;
  1603. if (move_xh > MAXX)
  1604. move_xh = MAXX;
  1605. } else {
  1606. /* if in a dungeon monsters can't be on the perimeter (wall there) */
  1607. if (move_yl < 1)
  1608. move_yl = 1;
  1609. if (move_yh > MAXY - 1)
  1610. move_yh = MAXY - 1;
  1611. if (move_xl < 1)
  1612. move_xl = 1;
  1613. if (move_xh > MAXX - 1)
  1614. move_xh = MAXX - 1;
  1615. }
  1616. /* now reset monster moved flags */
  1617. for (j = move_yl; j < move_yh; j++)
  1618. for (i = move_xl; i < move_xh; i++)
  1619. moved[i][j] = 0;
  1620. /*
  1621. * Move the last monster hit by the player
  1622. * This is mainly to make monster hit by spells move towards the player,
  1623. * even if out of the normal movement range.
  1624. * If the last monster hit by the player no longer exists then
  1625. * last_monst_hx and last_monst_hy will be out of the map range
  1626. * (actually set to -1).
  1627. */
  1628. if ((last_monst_hx >= 0) && (last_monst_hx < MAXX) && (last_monst_hy >= 0) &&
  1629. (last_monst_hy < MAXY)) {
  1630. moved[last_monst_hx][last_monst_hy] = 0;
  1631. if (mitem[last_monst_hx][last_monst_hy].mon != MONST_NONE) {
  1632. movemt(last_monst_hx, last_monst_hy);
  1633. last_monst_hx = (char)movedx;
  1634. last_monst_hy = (char)movedy;
  1635. }
  1636. }
  1637. if (c[AGGRAVATE] || !c[STEALTH]) {
  1638. /* move monsters for aggravation or not stealthed */
  1639. for (j = move_yl; j < move_yh;
  1640. j++) { /* look thru all locations in window */
  1641. for (i = move_xl; i < move_xh; i++) {
  1642. if ((mitem[i][j].mon != MONST_NONE) && (moved[i][j] == 0))
  1643. /* if there is a monster to move and it isn't already moved */
  1644. movemt(i, j);
  1645. }
  1646. }
  1647. } else {
  1648. for (j = move_yl; j < move_yh; j++) {
  1649. for (i = move_xl; i < move_xh; i++) {
  1650. if ((mitem[i][j].mon != MONST_NONE) && (moved[i][j] == 0)) {
  1651. /* if there is a monster to move and it isn't already moved */
  1652. if ((stealth[i][j] & STEALTH_AWAKE) != 0)
  1653. /* Move awake monsters */
  1654. movemt(i, j);
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. /* =============================================================================
  1661. * FUNCTION: parse2
  1662. */
  1663. void parse2(void) {
  1664. /* move the monsters */
  1665. if (c[HASTEMONST])
  1666. movemonst();
  1667. movemonst();
  1668. randmonst();
  1669. regen();
  1670. }
  1671. /* =============================================================================
  1672. * FUNCTION: write_monster_data
  1673. */
  1674. void write_monster_data(FILE *fp) {
  1675. int i;
  1676. char genocided;
  1677. /* write the random nonster generation time */
  1678. bwrite(fp, (char *)&rmst, sizeof(rmst));
  1679. /* Write genocide status */
  1680. for (i = 0; i < MAXMONST; i++) {
  1681. genocided = (char)((monster[i].flags & FL_GENOCIDED) != 0);
  1682. bwrite(fp, &genocided, sizeof(genocided));
  1683. }
  1684. }
  1685. /* =============================================================================
  1686. * FUNCTION: read_monster_data
  1687. */
  1688. void read_monster_data(FILE *fp) {
  1689. int i;
  1690. char genocided;
  1691. /* read the random nonster generation time */
  1692. bread(fp, (char *)&rmst, sizeof(rmst));
  1693. /* read genocide status */
  1694. for (i = 0; i < MAXMONST; i++) {
  1695. bread(fp, &genocided, sizeof(genocided));
  1696. if (genocided)
  1697. monster[i].flags |= FL_GENOCIDED;
  1698. }
  1699. }