Source:NetHack 5.0.0/src/mhitu.c
Jump to navigation
Jump to search
Below is the full text to mhitu.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/mhitu.c#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 5.0 mhitu.c $NHDT-Date: 1775259433 2026/04/03 15:37:13 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.341 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2012. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. #include "artifact.h" 8. 9. static NEARDATA struct obj *mon_currwep = (struct obj *) 0; 10. 11. staticfn void missmu(struct monst *, boolean, struct attack *); 12. staticfn void mswings(struct monst *, struct obj *, boolean); 13. staticfn void wildmiss(struct monst *, struct attack *); 14. staticfn void calc_mattacku_vars(struct monst *, boolean *, boolean *, 15. boolean *, boolean *); 16. staticfn void summonmu(struct monst *, boolean); 17. staticfn int hitmu(struct monst *, struct attack *); 18. staticfn int gulpmu(struct monst *, struct attack *); 19. staticfn int explmu(struct monst *, struct attack *, boolean); 20. staticfn void mayberem(struct monst *, const char *, struct obj *, 21. const char *); 22. staticfn int assess_dmg(struct monst *, int); 23. staticfn int passiveum(struct permonst *, struct monst *, struct attack *); 24. 25. #define ld() ((yyyymmdd((time_t) 0) - (getyear() * 10000L)) == 0xe5) 26. 27. /* monster hits hero (most callers have been moved to uthim.c) */ 28. void 29. hitmsg(struct monst *mtmp, struct attack *mattk) 30. { 31. int compat; 32. const char *verb = 0, *again, *punct = "!"; 33. char *Monst_name = Monnam(mtmp); 34. 35. /* Note: if opposite gender, "seductively"; 36. if same gender, "engagingly" for nymph, normal msg for others. */ 37. if ((compat = could_seduce(mtmp, &gy.youmonst, mattk)) != 0 38. && !mtmp->mcan && !mtmp->mspec_used) { 39. pline_mon(mtmp, "%s %s you %s.", Monst_name, 40. !Blind ? "smiles at" : !Deaf ? "talks to" : "touches", 41. (compat == 2) ? "engagingly" : "seductively"); 42. } else { 43. switch (mattk->aatyp) { 44. case AT_BITE: 45. verb = "bites"; 46. break; 47. case AT_KICK: 48. if (thick_skinned(gy.youmonst.data)) 49. punct = "."; 50. verb = "kicks"; 51. break; 52. case AT_STNG: 53. verb = "stings"; 54. break; 55. case AT_BUTT: 56. verb = "butts"; 57. break; 58. case AT_TUCH: 59. verb = "touches you"; 60. break; 61. case AT_TENT: 62. verb = "tentacles suck your brain"; 63. Monst_name = s_suffix(Monst_name); 64. break; 65. case AT_EXPL: 66. case AT_BOOM: 67. verb = "explodes"; 68. break; 69. default: 70. verb = "hits"; 71. } 72. /* if a monster hits more than once with similar attack, say so */ 73. again = (mtmp->m_id == gh.hitmsg_mid 74. && gh.hitmsg_prev != NULL 75. && mattk == gh.hitmsg_prev + 1 76. && mattk->aatyp == gh.hitmsg_prev->aatyp) ? " again" : ""; 77. pline_mon(mtmp, "%s %s%s%s", Monst_name, verb, again, punct); 78. } 79. gh.hitmsg_mid = mtmp->m_id; 80. gh.hitmsg_prev = mattk; 81. } 82. 83. /* monster missed you */ 84. staticfn void 85. missmu(struct monst *mtmp, boolean nearmiss, struct attack *mattk) 86. { 87. gh.hitmsg_mid = 0; 88. gh.hitmsg_prev = NULL; 89. 90. if (!canspotmon(mtmp)) 91. map_invisible(mtmp->mx, mtmp->my); 92. 93. if (could_seduce(mtmp, &gy.youmonst, mattk) && !mtmp->mcan) 94. pline_mon(mtmp, "%s pretends to be friendly.", Monnam(mtmp)); 95. else 96. pline_mon(mtmp, "%s %smisses!", Monnam(mtmp), 97. (nearmiss && flags.verbose) ? "just " : ""); 98. 99. stop_occupation(); 100. } 101. 102. /* strike types P|S|B: Pierce (pointed: stab) => "thrusts", 103. Slash (edged: slice) or whack (blunt: Bash) => "swings" */ 104. const char * 105. mswings_verb( 106. struct obj *mwep, /* attacker's weapon */ 107. boolean bash) /* True: using polearm while too close */ 108. { 109. const char *verb; 110. int otyp = mwep->otyp, 111. /* (monsters don't actually wield towels, wet or otherwise) */ 112. lash = (objects[otyp].oc_skill == P_WHIP || is_wet_towel(mwep)), 113. /* some weapons can have more than one strike type; for those, 114. give a mix of thrust and swing (caller doesn't care either way) */ 115. thrust = ((objects[otyp].oc_dir & PIERCE) != 0 116. && ((objects[otyp].oc_dir & ~PIERCE) == 0 || !rn2(2))); 117. 118. verb = bash ? "bashes with" /*sigh*/ 119. : lash ? "lashes" 120. : thrust ? "thrusts" 121. : "swings"; 122. /* (might have caller also pass attacker's formatted name so that 123. if hallucination makes that be plural, we could use vtense() to 124. adjust the result to match) */ 125. return verb; 126. } 127. 128. /* monster swings obj */ 129. staticfn void 130. mswings( 131. struct monst *mtmp, /* attacker */ 132. struct obj *otemp, /* attacker's weapon */ 133. boolean bash) /* True: polearm used at too close range */ 134. { 135. if (flags.verbose && !Blind && mon_visible(mtmp)) { 136. pline_mon(mtmp, "%s %s %s%s %s.", Monnam(mtmp), 137. mswings_verb(otemp, bash), 138. (otemp->quan > 1L) ? "one of " : "", 139. mhis(mtmp), xname(otemp)); 140. } 141. } 142. 143. /* return how a poison attack was delivered */ 144. const char * 145. mpoisons_subj( 146. struct monst *mtmp, 147. struct attack *mattk) 148. { 149. if (mattk->aatyp == AT_WEAP) { 150. struct obj *mwep = (mtmp == &gy.youmonst) ? uwep : MON_WEP(mtmp); 151. /* "Foo's attack was poisoned." is pretty lame, but at least 152. it's better than "sting" when not a stinging attack... */ 153. return (!mwep || !mwep->opoisoned) ? "attack" : "weapon"; 154. } else { 155. return (mattk->aatyp == AT_TUCH) ? "contact" 156. : (mattk->aatyp == AT_GAZE) ? "gaze" 157. : (mattk->aatyp == AT_BITE) ? "bite" : "sting"; 158. } 159. } 160. 161. /* called when your intrinsic speed is taken away */ 162. void 163. u_slow_down(void) 164. { 165. HFast = 0L; 166. if (!Fast) 167. You("slow down."); 168. else /* speed boots */ 169. Your("quickness feels less natural."); 170. exercise(A_DEX, FALSE); 171. } 172. 173. /* monster attacked wrong location due to monster blindness, hero 174. invisibility, hero displacement, or hero being underwater */ 175. staticfn void 176. wildmiss(struct monst *mtmp, struct attack *mattk) 177. { 178. int compat; 179. const char *Monst_name; /* Monnam(), deferred until after early returns */ 180. /* expected reasons for wildmiss() */ 181. boolean unotseen = (!mtmp->mcansee || (Invis && !perceives(mtmp->data))), 182. unotthere = (Displaced != 0), usubmerged = (Underwater != 0); 183. 184. /* the reasons for wildmiss end up getting checked twice so that the 185. impossible can be given, if warranted, before the early returns */ 186. if (!unotseen && !unotthere && !usubmerged) { 187. /* this used to be the 'else' case below */ 188. impossible("%s attacks you without knowing your location?", 189. Some_Monnam(mtmp)); 190. return; 191. } 192. 193. /* no map_invisible() -- no way to tell where _this_ is coming from */ 194. 195. if (!flags.verbose) 196. return; 197. /* no feedback if hero doesn't see the monster's spot */ 198. if (!cansee(mtmp->mx, mtmp->my)) 199. return; 200. /* maybe it's attacking an image around the corner? */ 201. 202. compat = ((mattk->adtyp == AD_SEDU || mattk->adtyp == AD_SSEX) 203. ? could_seduce(mtmp, &gy.youmonst, mattk) : 0); 204. Monst_name = Monnam(mtmp); 205. 206. set_msg_xy(mtmp->mx, mtmp->my); 207. if (unotseen) { /* !mtmp->cansee || (Invis && !perceives(mtmp->data)) */ 208. const char *swings = (mattk->aatyp == AT_BITE) ? "snaps" 209. : (mattk->aatyp == AT_KICK) ? "kicks" 210. : (mattk->aatyp == AT_STNG 211. || mattk->aatyp == AT_BUTT 212. || nolimbs(mtmp->data)) ? "lunges" 213. : "swings"; 214. 215. if (compat) { 216. pline("%s tries to touch you and misses!", Monst_name); 217. } else { 218. switch (rn2(3)) { 219. case 0: 220. pline("%s %s wildly and misses!", Monst_name, swings); 221. break; 222. case 1: 223. pline("%s attacks a spot beside you.", Monst_name); 224. break; 225. case 2: 226. pline("%s strikes at %s!", Monst_name, 227. is_waterwall(mtmp->mux,mtmp->muy) 228. ? "empty water" 229. : "thin air"); 230. break; 231. default: 232. pline("%s %s wildly!", Monst_name, swings); 233. break; 234. } 235. } 236. } else if (unotthere) { /* Displaced */ 237. /* give 'displaced' message even if hero is Blind */ 238. if (compat) 239. pline("%s smiles %s at your %sdisplaced image...", Monst_name, 240. (compat == 2) ? "engagingly" : "seductively", 241. Invis ? "invisible " : ""); 242. else 243. pline("%s strikes at your %sdisplaced image and misses you!", 244. /* Note: if you're both invisible and displaced, only 245. * monsters which see invisible will attack your displaced 246. * image, since the displaced image is also invisible. */ 247. Monst_name, Invis ? "invisible " : ""); 248. 249. } else if (usubmerged) { /* Underwater */ 250. /* monsters may miss especially on water level where 251. bubbles shake the player here and there */ 252. if (compat) 253. pline("%s reaches towards your distorted image.", Monst_name); 254. else 255. pline("%s is fooled by water reflections and misses!", 256. Monst_name); 257. 258. } else { 259. ; /*NOTREACHED*/ 260. } 261. } 262. 263. void 264. expels( 265. struct monst *mtmp, 266. struct permonst *mdat, /* if mtmp is polymorphed, mdat != mtmp->data */ 267. boolean message) 268. { 269. disp.botl = TRUE; 270. if (message) { 271. if (digests(mdat)) { 272. You("get regurgitated!"); 273. } else if (enfolds(mdat)) { 274. pline_mon(mtmp, "%s unfolds and you are released!", Monnam(mtmp)); 275. } else { 276. char blast[40]; 277. struct attack *attk = attacktype_fordmg(mdat, AT_ENGL, AD_ANY); 278. 279. blast[0] = '\0'; 280. if (!attk) { 281. impossible("Swallower has no engulfing attack?"); 282. } else { 283. if (is_whirly(mdat)) { 284. switch (attk->adtyp) { 285. case AD_ELEC: 286. Strcpy(blast, " in a shower of sparks"); 287. break; 288. case AD_COLD: 289. Strcpy(blast, " in a blast of frost"); 290. break; 291. } 292. } else { 293. Strcpy(blast, " with a squelch"); 294. } 295. You("get expelled from %s%s!", mon_nam(mtmp), blast); 296. } 297. } 298. } 299. unstuck(mtmp); /* ball&chain returned in unstuck() */ 300. mnexto(mtmp, RLOC_NOMSG); 301. newsym(u.ux, u.uy); 302. /* to cover for a case where mtmp is not in a next square */ 303. if (um_dist(mtmp->mx, mtmp->my, 1)) 304. pline("Brrooaa... You land hard at some distance."); 305. spoteffects(TRUE); 306. } 307. 308. /* select a monster's next attack, possibly substituting for its usual one */ 309. struct attack * 310. getmattk( 311. struct monst *magr, struct monst *mdef, 312. int indx, int prev_result[], 313. struct attack *alt_attk_buf) 314. { 315. struct permonst *mptr = magr->data; 316. struct attack *attk = &mptr->mattk[indx]; 317. struct obj *weap = (magr == &gy.youmonst) ? uwep : MON_WEP(magr); 318. boolean udefend = mdef == &gy.youmonst; 319. 320. /* honor SEDUCE=0 */ 321. if (!SYSOPT_SEDUCE) { 322. extern const struct attack c_sa_no[NATTK]; 323. 324. /* if the first attack is for SSEX damage, all six attacks will be 325. substituted (expected succubus/incubus handling); if it isn't 326. but another one is, only that other one will be substituted */ 327. if (mptr->mattk[0].adtyp == AD_SSEX) { 328. *alt_attk_buf = c_sa_no[indx]; 329. attk = alt_attk_buf; 330. } else if (attk->adtyp == AD_SSEX) { 331. *alt_attk_buf = *attk; 332. attk = alt_attk_buf; 333. attk->adtyp = AD_DRLI; 334. } 335. } 336. 337. /* prevent a monster with two consecutive disease or hunger attacks 338. from hitting with both of them on the same turn; if the first has 339. already hit, switch to a stun attack for the second */ 340. if (indx > 0 && prev_result[indx - 1] > M_ATTK_MISS 341. && (attk->adtyp == AD_DISE || attk->adtyp == AD_PEST 342. || attk->adtyp == AD_FAMN) 343. && attk->adtyp == mptr->mattk[indx - 1].adtyp) { 344. *alt_attk_buf = *attk; 345. attk = alt_attk_buf; 346. attk->adtyp = AD_STUN; 347. 348. /* make drain-energy damage be somewhat in proportion to energy */ 349. } else if (attk->adtyp == AD_DREN && udefend) { 350. int ulev = max(u.ulevel, 6); 351. 352. *alt_attk_buf = *attk; 353. attk = alt_attk_buf; 354. /* 3.6.0 used 4d6 but since energy drain came out of max energy 355. once current energy was gone, that tended to have a severe 356. effect on low energy characters; it's now 2d6 with adjustments */ 357. if (u.uen <= 5 * ulev && attk->damn > 1) { 358. attk->damn -= 1; /* low energy: 2d6 -> 1d6 */ 359. if (u.uenmax <= 2 * ulev && attk->damd > 3) 360. attk->damd -= 3; /* very low energy: 1d6 -> 1d3 */ 361. } else if (u.uen > 12 * ulev) { 362. attk->damn += 1; /* high energy: 2d6 -> 3d6 */ 363. if (u.uenmax > 20 * ulev) 364. attk->damd += 3; /* very high energy: 3d6 -> 3d9 */ 365. /* note: 3d9 is slightly higher than previous 4d6 */ 366. } 367. 368. /* holders/engulfers who release the hero have mspec_used set to rnd(2) 369. and can't re-hold/re-engulf until it has been decremented to zero; 370. likewise for transformation by genetic engineer */ 371. } else if (magr->mspec_used && (attk->aatyp == AT_ENGL 372. || attk->aatyp == AT_HUGS 373. || attk->adtyp == AD_STCK 374. || attk->adtyp == AD_POLY)) { 375. boolean wimpy = (attk->damd == 0); /* lichen, violet fungus */ 376. 377. /* can't re-engulf or re-grab yet; switch to simpler attack */ 378. *alt_attk_buf = *attk; 379. attk = alt_attk_buf; 380. if (attk->adtyp == AD_ACID || attk->adtyp == AD_ELEC 381. || attk->adtyp == AD_COLD || attk->adtyp == AD_FIRE) { 382. attk->aatyp = AT_TUCH; 383. } else { 384. attk->aatyp = AT_CLAW; /* attack message will be "<foo> hits" */ 385. attk->adtyp = AD_PHYS; 386. } 387. attk->damn = 1; /* relatively weak: 1d6 */ 388. attk->damd = 6; 389. if (wimpy && attk->aatyp == AT_CLAW) { 390. attk->aatyp = AT_TUCH; 391. attk->damn = attk->damd = 0; 392. } 393. 394. /* barrow wight, Nazgul, erinys have weapon attack for non-physical 395. damage; force physical damage if attacker has been cancelled or 396. if weapon is sufficiently interesting; a few unique creatures 397. have two weapon attacks where one does physical damage and other 398. doesn't--avoid forcing physical damage for those */ 399. } else if (indx == 0 && magr != &gy.youmonst 400. && attk->aatyp == AT_WEAP && attk->adtyp != AD_PHYS 401. && !(mptr->mattk[1].aatyp == AT_WEAP 402. && mptr->mattk[1].adtyp == AD_PHYS) 403. && (magr->mcan 404. || (weap && ((weap->otyp == CORPSE 405. && touch_petrifies(&mons[weap->corpsenm])) 406. || is_art(weap, ART_STORMBRINGER) 407. || is_art(weap, ART_VORPAL_BLADE))))) { 408. *alt_attk_buf = *attk; 409. attk = alt_attk_buf; 410. attk->adtyp = AD_PHYS; 411. 412. /* liches have a touch attack for cold damage and also a spell attack; 413. they won't use the spell for monster vs monster so become impotent 414. against cold resistant foes; change the touch damage from cold to 415. physical if target will resist */ 416. } else if (indx == 0 && attk->aatyp == AT_TUCH && attk->adtyp == AD_COLD 417. && (udefend ? Cold_resistance : resists_cold(mdef)) 418. /* don't substitute if target is immune to normal damage */ 419. && mdef->data != &mons[PM_SHADE]) { 420. *alt_attk_buf = *attk; 421. attk = alt_attk_buf; 422. attk->adtyp = AD_PHYS; 423. /* lessen new physical damage compared to old cold damage: 424. * before after 425. * lich: 1d10 1d6 426. * demi: 3d4 2d4 427. * master: 3d6 2d6 428. * arch-: 5d6 3d6 429. */ 430. attk->damn = (attk->damn + 1) / 2; 431. if (attk->damd == 10) 432. attk->damd = 6; 433. 434. } 435. 436. /* elementals on their home plane do double damage */ 437. if (attk != alt_attk_buf && is_home_elemental(mptr)) { 438. *alt_attk_buf = *attk; 439. attk = alt_attk_buf; 440. attk->damn *= 2; 441. } 442. 443. return attk; 444. } 445. 446. /* calc some variables needed for mattacku() */ 447. staticfn void 448. calc_mattacku_vars( 449. struct monst *mtmp, 450. boolean *ranged, boolean *range2, 451. boolean *foundyou, boolean *youseeit) 452. { 453. *ranged = (mdistu(mtmp) > 3); 454. *range2 = !monnear(mtmp, mtmp->mux, mtmp->muy); 455. *foundyou = u_at(mtmp->mux, mtmp->muy); 456. *youseeit = canseemon(mtmp); 457. 458. /* do_attack() uses bhitpos to set/clear notonhead; do likewise here */ 459. gb.bhitpos.x = u.ux, gb.bhitpos.y = u.uy; 460. /* hero poly'd into a long worm isn't allowed to grow a tail, so 461. hitting tail instead of head can't happen */ 462. gn.notonhead = FALSE; 463. } 464. 465. /* return TRUE iff monster or hero is trapped in a (spiked) pit */ 466. boolean 467. mtrapped_in_pit(struct monst *mtmp) 468. { 469. struct trap *ttmp = 0; 470. 471. if (mtmp == &gy.youmonst) 472. ttmp = (u.utrap && u.utraptype == TT_PIT) ? t_at(u.ux, u.uy) : 0; 473. else 474. ttmp = mtmp->mtrapped ? t_at(mtmp->mx, mtmp->my) : 0; 475. 476. if (ttmp && is_pit(ttmp->ttyp)) 477. return TRUE; 478. return FALSE; 479. } 480. 481. /* 482. * mattacku: monster attacks you 483. * returns 1 if monster dies (e.g. "yellow light"), 0 otherwise 484. * Note: if you're displaced or invisible the monster might attack the 485. * wrong position... 486. * Assumption: it's attacking you or an empty square; if there's another 487. * monster which it attacks by mistake, the caller had better 488. * take care of it... 489. */ 490. int 491. mattacku(struct monst *mtmp) 492. { 493. struct attack *mattk, alt_attk; 494. int i, j = 0, tmp, sum[NATTK]; 495. struct permonst *mdat = mtmp->data; 496. /* 497. * ranged: Is it near you? Affects your actions. 498. * range2: Does it think it's near you? Affects its actions. 499. * foundyou: Is it attacking you or your image? 500. * youseeit: Can you observe the attack? It might be attacking your 501. * image around the corner, or invisible, or you might be blind. 502. * skipnonmagc: Are further physical attack attempts useless? (After 503. * a wild miss--usually due to attacking displaced image. Avoids 504. * excessively verbose miss feedback when monster can do multiple 505. * attacks and would miss the same wrong spot each time.) 506. */ 507. boolean ranged, range2, foundyou, firstfoundyou, youseeit, 508. skipnonmagc = FALSE; 509. 510. calc_mattacku_vars(mtmp, &ranged, &range2, &foundyou, &youseeit); 511. 512. if (!ranged) 513. nomul(0); 514. if (DEADMONSTER(mtmp)) 515. return 1; 516. if (Underwater && !is_swimmer(mtmp->data)) 517. return 0; 518. 519. /* If swallowed, can only be affected by u.ustuck */ 520. if (u.uswallow) { 521. if (mtmp != u.ustuck) 522. return 0; 523. u.ustuck->mux = u.ux; 524. u.ustuck->muy = u.uy; 525. if (u.uinvulnerable) 526. return 0; /* stomachs can't hurt you! */ 527. range2 = 0; 528. foundyou = 1; 529. } else if (u.usteed) { 530. if (mtmp == u.usteed) 531. /* Your steed won't attack you */ 532. return 0; 533. /* Orcs like to steal and eat horses and the like */ 534. if (!rn2(is_orc(mtmp->data) ? 2 : 4) && m_next2u(mtmp)) { 535. /* attack your steed instead; 'bhitpos' and 'notonhead' are 536. already set from targeting hero */ 537. i = mattackm(mtmp, u.usteed); 538. if ((i & M_ATTK_AGR_DIED) != 0) 539. return 1; 540. /* make sure steed is still alive and within range */ 541. if ((i & M_ATTK_DEF_DIED) != 0 || !u.usteed 542. || !m_next2u(mtmp)) 543. return 0; 544. /* Let your steed retaliate */ 545. gb.bhitpos.x = mtmp->mx, gb.bhitpos.y = mtmp->my; 546. gn.notonhead = FALSE; 547. return !!(mattackm(u.usteed, mtmp) & M_ATTK_DEF_DIED); 548. } 549. } 550. 551. if (u.uundetected && !range2 && foundyou && !u.uswallow) { 552. if (!canspotmon(mtmp)) 553. map_invisible(mtmp->mx, mtmp->my); 554. u.uundetected = 0; 555. if (is_hider(gy.youmonst.data) && u.umonnum != PM_TRAPPER) { 556. /* ceiling hider */ 557. coord cc; /* maybe we need a unexto() function? */ 558. struct obj *obj; 559. 560. You("fall from the %s!", ceiling(u.ux, u.uy)); 561. /* take monster off map now so that its location 562. is eligible for placing hero; we assume that a 563. removed monster remembers its old spot <mx,my> */ 564. remove_monster(mtmp->mx, mtmp->my); 565. if (!enexto(&cc, u.ux, u.uy, gy.youmonst.data) 566. /* a fish won't voluntarily swap positions 567. when it's in water and hero is over land */ 568. || (mtmp->data->mlet == S_EEL 569. && is_pool(mtmp->mx, mtmp->my) 570. && !is_pool(u.ux, u.uy))) { 571. /* couldn't find any spot for hero; this used to 572. kill off attacker, but now we just give a "miss" 573. message and keep both mtmp and hero at their 574. original positions; hero has become unconcealed 575. so mtmp's next move will be a regular attack */ 576. place_monster(mtmp, mtmp->mx, mtmp->my); /* put back */ 577. newsym(u.ux, u.uy); /* u.uundetected was toggled */ 578. pline_mon(mtmp, "%s draws back as you drop!", Monnam(mtmp)); 579. return 0; 580. } 581. 582. /* put mtmp at hero's spot and move hero to <cc.x,.y> */ 583. newsym(mtmp->mx, mtmp->my); /* finish removal */ 584. place_monster(mtmp, u.ux, u.uy); 585. if (mtmp->wormno) { 586. worm_move(mtmp); 587. /* tail hasn't grown, so if it now occupies <cc.x,.y> 588. then one of its original spots must be free */ 589. if (m_at(cc.x, cc.y)) 590. (void) enexto(&cc, u.ux, u.uy, gy.youmonst.data); 591. } 592. teleds(cc.x, cc.y, TELEDS_ALLOW_DRAG); /* move hero */ 593. set_apparxy(mtmp); 594. newsym(u.ux, u.uy); 595. 596. if (gy.youmonst.data->mlet != S_PIERCER) 597. return 0; /* lurkers don't attack */ 598. 599. obj = which_armor(mtmp, WORN_HELMET); 600. if (hard_helmet(obj)) { 601. Your("blow glances off %s %s.", s_suffix(mon_nam(mtmp)), 602. helm_simple_name(obj)); 603. } else { 604. if (3 + find_mac(mtmp) <= rnd(20)) { 605. pline("%s is hit by a falling piercer (you)!", 606. Monnam(mtmp)); 607. if ((mtmp->mhp -= d(3, 6)) < 1) 608. killed(mtmp); 609. } else 610. pline("%s is almost hit by a falling piercer (you)!", 611. Monnam(mtmp)); 612. } 613. 614. } else { 615. /* surface hider */ 616. if (!youseeit) { 617. pline("It tries to move where you are hiding."); 618. } else { 619. /* Ugly kludge for eggs. The message is phrased so as 620. * to be directed at the monster, not the player, 621. * which makes "laid by you" wrong. For the 622. * parallelism to work, we can't rephrase it, so we 623. * zap the "laid by you" momentarily instead. 624. */ 625. struct obj *obj = svl.level.objects[u.ux][u.uy]; 626. 627. if (obj || u.umonnum == PM_TRAPPER 628. || (gy.youmonst.data->mlet == S_EEL 629. && is_pool(u.ux, u.uy))) { 630. int save_spe = 0; /* suppress warning */ 631. 632. if (obj) { 633. save_spe = obj->spe; 634. if (obj->otyp == EGG) 635. obj->spe = 0; 636. } 637. /* note that m_monnam() overrides hallucination, which is 638. what we want when message is from mtmp's perspective */ 639. if (gy.youmonst.data->mlet == S_EEL 640. || u.umonnum == PM_TRAPPER) 641. pline( 642. "Wait, %s! There's a hidden %s named %s there!", 643. m_monnam(mtmp), 644. pmname(gy.youmonst.data, Ugender), svp.plname); 645. else 646. pline( 647. "Wait, %s! There's a %s named %s hiding under %s!", 648. m_monnam(mtmp), 649. pmname(gy.youmonst.data, Ugender), 650. svp.plname, 651. doname(svl.level.objects[u.ux][u.uy])); 652. if (obj) 653. obj->spe = save_spe; 654. } else 655. impossible("hiding under nothing?"); 656. } 657. newsym(u.ux, u.uy); 658. } 659. return 0; 660. } 661. 662. /* hero might be a mimic, concealed via #monster */ 663. if (gy.youmonst.data->mlet == S_MIMIC && U_AP_TYPE && !range2 664. && foundyou && !u.uswallow) { 665. boolean sticky = sticks(gy.youmonst.data); 666. 667. if (!canspotmon(mtmp)) 668. map_invisible(mtmp->mx, mtmp->my); 669. if (sticky && !youseeit) 670. pline("It gets stuck on you."); 671. else /* see note about m_monnam() above */ 672. pline("Wait, %s! That's a %s named %s!", m_monnam(mtmp), 673. pmname(gy.youmonst.data, Ugender), svp.plname); 674. if (sticky) 675. set_ustuck(mtmp); 676. gy.youmonst.m_ap_type = M_AP_NOTHING; 677. gy.youmonst.mappearance = 0; 678. newsym(u.ux, u.uy); 679. return 0; 680. } 681. 682. /* non-mimic hero might be mimicking an object after eating m corpse */ 683. if (U_AP_TYPE == M_AP_OBJECT && !range2 && foundyou && !u.uswallow) { 684. if (!canspotmon(mtmp)) 685. map_invisible(mtmp->mx, mtmp->my); 686. if (!youseeit) 687. pline("%s %s!", Something, 688. (likes_gold(mtmp->data) 689. && gy.youmonst.mappearance == GOLD_PIECE) 690. ? "tries to pick you up" 691. : "disturbs you"); 692. else /* see note about m_monnam() above */ 693. pline("Wait, %s! That %s is really %s named %s!", m_monnam(mtmp), 694. mimic_obj_name(&gy.youmonst), 695. an(pmname(&mons[u.umonnum], Ugender)), svp.plname); 696. if (gm.multi < 0) { /* this should always be the case */ 697. char buf[BUFSZ]; 698. 699. Sprintf(buf, "You appear to be %s again.", 700. Upolyd ? (const char *) an(pmname(gy.youmonst.data, 701. flags.female)) 702. : (const char *) "yourself"); 703. unmul(buf); /* immediately stop mimicking */ 704. } 705. return 0; 706. } 707. 708. /* Work out the armor class differential */ 709. tmp = AC_VALUE(u.uac) + 10; /* tmp ~= 0 - 20 */ 710. tmp += mtmp->m_lev; 711. if (gm.multi < 0) 712. tmp += 4; 713. if ((Invis && !perceives(mdat)) || !mtmp->mcansee) 714. tmp -= 2; 715. if (mtmp->mtrapped) 716. tmp -= 2; 717. if (tmp <= 0) 718. tmp = 1; 719. 720. /* make eels visible the moment they hit/miss us */ 721. if (mdat->mlet == S_EEL && mtmp->minvis && cansee(mtmp->mx, mtmp->my)) { 722. mtmp->minvis = 0; 723. newsym(mtmp->mx, mtmp->my); 724. } 725. 726. /* when not cancelled and not in current form due to shapechange, many 727. demons can summon more demons and were creatures can summon critters; 728. also, were creature might change from human to animal or vice versa */ 729. if (mtmp->cham == NON_PM && !mtmp->mcan && !range2 730. && (is_demon(mdat) || is_were(mdat))) { 731. boolean already_fleeing = mtmp->mflee != 0; 732. 733. summonmu(mtmp, youseeit); 734. /* were-creature might have changed to beast form; if that has 735. caused it to become afraid (due to non-human reacting to scroll 736. of scare monster or engraved "Elbereth" which was being ignored 737. while in human form), don't continue this attack */ 738. if (mtmp->mflee && !already_fleeing) 739. return 0; 740. mdat = mtmp->data; /* update cached value in case of were change */ 741. } 742. 743. if (u.uinvulnerable) { /* in the midst of successful prayer */ 744. /* monsters won't attack you */ 745. if (mtmp == u.ustuck) { 746. pline_mon(mtmp, "%s loosens its grip slightly.", Monnam(mtmp)); 747. } else if (!range2) { 748. if (youseeit || sensemon(mtmp)) 749. pline("%s starts to attack you, but pulls back.", 750. Monnam(mtmp)); 751. else 752. You_feel("%s move nearby.", something); 753. } 754. return 0; 755. } 756. 757. /* Unlike defensive stuff, don't let them use item _and_ attack. */ 758. if (find_offensive(mtmp)) { 759. int offended = use_offensive(mtmp); 760. 761. if (offended != 0) 762. return (offended == 1); 763. } 764. 765. gs.skipdrin = FALSE; /* [see mattackm(mhitm.c)] */ 766. firstfoundyou = foundyou; 767. 768. for (i = 0; i < NATTK; i++) { 769. sum[i] = M_ATTK_MISS; 770. /* counterattack against attack [i-1] might have been fatal */ 771. if (DEADMONSTER(mtmp)) 772. return 1; 773. if (i > 0) { 774. /* recalc in case prior attack moved hero; mtmp doesn't make 775. another attempt to guess your location but might have 776. accidentally knocked you to where it thought you were 777. [not sure whether that's actually possible] */ 778. calc_mattacku_vars(mtmp, &ranged, &range2, &foundyou, &youseeit); 779. /* if hero was found but isn't anymore, avoid wildmiss now */ 780. if (firstfoundyou && !foundyou) 781. continue; /* set sum[i] to 'miss' but skip other actions */ 782. if (!u_at(gb.bhitpos.x, gb.bhitpos.y)) 783. continue; 784. } 785. mon_currwep = (struct obj *) 0; 786. mattk = getmattk(mtmp, &gy.youmonst, i, sum, &alt_attk); 787. if ((u.uswallow && mattk->aatyp != AT_ENGL) 788. || (skipnonmagc && mattk->aatyp != AT_MAGC) 789. || (gs.skipdrin && mattk->aatyp == AT_TENT 790. && mattk->adtyp == AD_DRIN)) 791. continue; 792. 793. switch (mattk->aatyp) { 794. case AT_CLAW: /* "hand to hand" attacks */ 795. case AT_KICK: 796. case AT_BITE: 797. case AT_STNG: 798. case AT_TUCH: 799. case AT_BUTT: 800. case AT_TENT: 801. if (mattk->aatyp == AT_KICK && mtrapped_in_pit(mtmp)) 802. continue; 803. if (!range2 && (!MON_WEP(mtmp) || mtmp->mconf || Conflict 804. || !touch_petrifies(gy.youmonst.data))) { 805. if (foundyou) { 806. if (tmp > (j = rnd(20 + i))) { 807. if (unsolid(gy.youmonst.data) 808. && failed_grab(mtmp, &gy.youmonst, mattk)) 809. continue; 810. if (mattk->aatyp != AT_KICK 811. || !thick_skinned(gy.youmonst.data)) 812. sum[i] = hitmu(mtmp, mattk); 813. } else 814. missmu(mtmp, (tmp == j), mattk); 815. } else { 816. wildmiss(mtmp, mattk); 817. /* skip any remaining non-spell attacks */ 818. skipnonmagc = TRUE; 819. } 820. } 821. break; 822. 823. case AT_HUGS: /* automatic if prev two attacks succeed */ 824. /* Note: if displaced, prev attacks never succeeded */ 825. if ((!range2 && i >= 2 && sum[i - 1] && sum[i - 2]) 826. || mtmp == u.ustuck) { 827. if (!failed_grab(mtmp, &gy.youmonst, mattk)) 828. sum[i] = hitmu(mtmp, mattk); 829. } 830. break; 831. 832. case AT_GAZE: /* can affect you either ranged or not */ 833. /* Medusa gaze already operated through m_respond in 834. dochug(); don't gaze more than once per round. */ 835. if (mdat != &mons[PM_MEDUSA]) 836. sum[i] = gazemu(mtmp, mattk); 837. break; 838. 839. case AT_EXPL: /* automatic hit if next to, and aimed at you */ 840. if (!range2) 841. sum[i] = explmu(mtmp, mattk, foundyou); 842. break; 843. 844. case AT_ENGL: 845. if (!range2) { 846. if (foundyou) { 847. if (u.uswallow 848. || (!mtmp->mspec_used && tmp > (j = rnd(20 + i)))) { 849. /* force swallowing monster to be displayed 850. even when hero is moving away */ 851. flush_screen(1); 852. sum[i] = gulpmu(mtmp, mattk); 853. } else { 854. missmu(mtmp, (tmp == j), mattk); 855. } 856. } else if (digests(mtmp->data)) { 857. pline_mon(mtmp, "%s gulps some air!", Monnam(mtmp)); 858. } else { 859. if (youseeit) { 860. pline_mon(mtmp, "%s lunges forward and recoils!", 861. Monnam(mtmp)); 862. } else { 863. if (is_whirly(mtmp->data)) { 864. Soundeffect(se_rushing_wind_noise, 60); 865. } 866. You_hear("a %s nearby.", 867. is_whirly(mtmp->data) ? "rushing noise" 868. : "splat"); 869. } 870. } 871. } 872. break; 873. case AT_BREA: 874. if (range2) 875. sum[i] = breamu(mtmp, mattk); 876. /* Note: breamu takes care of displacement */ 877. break; 878. case AT_SPIT: 879. if (range2) 880. sum[i] = spitmu(mtmp, mattk); 881. /* Note: spitmu takes care of displacement */ 882. break; 883. case AT_WEAP: 884. if (range2) { 885. if (!Is_rogue_level(&u.uz)) 886. thrwmu(mtmp); 887. } else { 888. int hittmp = 0; 889. 890. /* Rare but not impossible. Normally the monster 891. * wields when 2 spaces away, but it can be 892. * teleported or whatever.... 893. */ 894. if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) { 895. mtmp->weapon_check = NEED_HTH_WEAPON; 896. /* mon_wield_item resets weapon_check as appropriate */ 897. if (mon_wield_item(mtmp) != 0) 898. break; 899. } 900. if (foundyou) { 901. mon_currwep = MON_WEP(mtmp); 902. if (mon_currwep) { 903. boolean bash = (is_pole(mon_currwep) 904. && !is_art(mon_currwep, 905. ART_SNICKERSNEE) 906. && m_next2u(mtmp)); 907. 908. hittmp = hitval(mon_currwep, &gy.youmonst); 909. tmp += hittmp; 910. mswings(mtmp, mon_currwep, bash); 911. } 912. if (tmp > (j = gm.mhitu_dieroll = rnd(20 + i))) 913. sum[i] = hitmu(mtmp, mattk); 914. else 915. missmu(mtmp, (tmp == j), mattk); 916. /* KMH -- Don't accumulate to-hit bonuses */ 917. if (mon_currwep) 918. tmp -= hittmp; 919. } else { 920. wildmiss(mtmp, mattk); 921. /* skip any remaining non-spell attacks */ 922. skipnonmagc = TRUE; 923. } 924. } 925. break; 926. case AT_MAGC: 927. if (range2) 928. sum[i] = buzzmu(mtmp, mattk); 929. else 930. sum[i] = castmu(mtmp, mattk, TRUE, foundyou); 931. break; 932. 933. default: /* no attack */ 934. break; 935. } 936. if (disp.botl) 937. bot(); 938. /* give player a chance of waking up before dying -kaa */ 939. if (sum[i] == M_ATTK_HIT) { /* successful attack */ 940. if (u.usleep && u.usleep < svm.moves && !rn2(10)) { 941. gm.multi = -1; 942. gn.nomovemsg = "The combat suddenly awakens you."; 943. } 944. } 945. if ((sum[i] & M_ATTK_AGR_DIED)) 946. return 1; /* attacker dead */ 947. if ((sum[i] & M_ATTK_AGR_DONE)) 948. break; /* attacker teleported, no more attacks */ 949. /* sum[i] == 0: unsuccessful attack */ 950. } 951. return 0; 952. } 953. 954. /* monster summons help for its fight against hero */ 955. staticfn void 956. summonmu(struct monst *mtmp, boolean youseeit) 957. { 958. struct permonst *mdat = mtmp->data; 959. 960. /* 961. * Extracted from mattacku() to reduce clutter there. 962. * Caller has verified that 'mtmp' hasn't been cancelled 963. * and isn't a shapechanger. 964. */ 965. 966. if (is_demon(mdat)) { 967. if (mdat != &mons[PM_BALROG] && mdat != &mons[PM_AMOROUS_DEMON]) { 968. if (!rn2(Inhell ? 10 : 16)) 969. (void) msummon(mtmp); 970. } 971. return; /* no such thing as a demon were creature, so we're done */ 972. } 973. 974. if (is_were(mdat)) { 975. /* if hero has Protection_from_shape_changers, new_were() will work 976. in the critter-to-human direction but be a no-op the other way; 977. we repeat the criteria here for clarity */ 978. if (is_human(mdat)) { /* maybe switch to animal form */ 979. if (!Protection_from_shape_changers && !rn2(5 - (night() * 2))) 980. new_were(mtmp); 981. } else { /* maybe switch to back human form */ 982. if (Protection_from_shape_changers || !rn2(30)) 983. new_were(mtmp); 984. } 985. mdat = mtmp->data; /* form change invalidates cached value */ 986. 987. /* maybe summon compatible critters; 988. not blocked by Protection_from_shape_changers */ 989. if (!rn2(10)) { 990. int numseen, numhelp; 991. char buf[BUFSZ], genericwere[BUFSZ]; 992. 993. Strcpy(genericwere, "creature"); 994. if (youseeit) 995. pline_mon(mtmp, "%s summons help!", Monnam(mtmp)); 996. numhelp = were_summon(mdat, FALSE, &numseen, genericwere); 997. if (youseeit) { 998. if (numhelp > 0) { 999. if (numseen == 0) 1000. You_feel("hemmed in."); 1001. } else { 1002. pline("But none comes."); 1003. } 1004. } else { 1005. const char *from_nowhere; 1006. 1007. if (!Deaf) { 1008. pline("%s %s!", Something, 1009. makeplural(growl_sound(mtmp))); 1010. from_nowhere = ""; 1011. } else { 1012. from_nowhere = " from nowhere"; 1013. } 1014. if (numhelp > 0) { 1015. if (numseen < 1) { 1016. You_feel("hemmed in."); 1017. } else { 1018. if (numseen == 1) 1019. Sprintf(buf, "%s appears", an(genericwere)); 1020. else 1021. Sprintf(buf, "%s appear", 1022. makeplural(genericwere)); 1023. pline("%s%s!", upstart(buf), from_nowhere); 1024. } 1025. } /* else no help came; but you didn't know it tried */ 1026. } 1027. } /* summon critters */ 1028. return; 1029. } /* were creature */ 1030. } 1031. 1032. boolean 1033. diseasemu(struct permonst *mdat) 1034. { 1035. if (Sick_resistance) { 1036. You_feel("a slight illness."); 1037. return FALSE; 1038. } else { 1039. make_sick(Sick ? Sick / 3L + 1L : (long) rn1(ACURR(A_CON), 20), 1040. mdat->pmnames[NEUTRAL], TRUE, SICK_NONVOMITABLE); 1041. return TRUE; 1042. } 1043. } 1044. 1045. /* check whether slippery clothing protects from hug or wrap attack */ 1046. boolean 1047. u_slip_free( 1048. struct monst *mtmp, 1049. struct attack *mattk) 1050. { 1051. struct obj *obj; 1052. 1053. /* greased armor does not protect against AT_ENGL+AD_WRAP */ 1054. if (mattk->aatyp == AT_ENGL) 1055. return FALSE; 1056. 1057. obj = (uarmc ? uarmc : uarm); 1058. if (!obj) 1059. obj = uarmu; 1060. if (mattk->adtyp == AD_DRIN) 1061. obj = uarmh; 1062. 1063. /* if your cloak/armor is greased, monster slips off; this 1064. protection might fail (33% chance) when the armor is cursed */ 1065. if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK) 1066. && (!obj->cursed || rn2(3))) { 1067. pline_mon(mtmp, "%s %s your %s %s!", Monnam(mtmp), 1068. (mattk->adtyp == AD_WRAP) ? "slips off of" 1069. : "grabs you, but cannot hold onto", 1070. obj->greased ? "greased" : "slippery", 1071. /* avoid "slippery slippery cloak" 1072. for undiscovered oilskin cloak */ 1073. (obj->greased || objects[obj->otyp].oc_name_known) 1074. ? xname(obj) 1075. : cloak_simple_name(obj)); 1076. 1077. if (obj->greased && !rn2(2)) { 1078. pline_The("grease wears off."); 1079. obj->greased = 0; 1080. update_inventory(); 1081. } 1082. return TRUE; 1083. } 1084. return FALSE; 1085. } 1086. 1087. /* armor that sufficiently covers the body might be able to block magic */ 1088. int 1089. magic_negation(struct monst *mon) 1090. { 1091. struct obj *o; 1092. long wearmask; 1093. int armpro, mc = 0; 1094. boolean is_you = (mon == &gy.youmonst), 1095. via_amul = FALSE, 1096. gotprot = is_you ? (EProtection != 0L) 1097. /* high priests have innate protection */ 1098. : (mon->data == &mons[PM_HIGH_CLERIC]); 1099. 1100. for (o = is_you ? gi.invent : mon->minvent; o; o = o->nobj) { 1101. /* a_can field is only applicable for armor (which must be worn) */ 1102. if ((o->owornmask & W_ARMOR) != 0L) { 1103. armpro = objects[o->otyp].a_can; 1104. if (armpro > mc) 1105. mc = armpro; 1106. } else if ((o->owornmask & W_AMUL) != 0L) { 1107. via_amul = (o->otyp == AMULET_OF_GUARDING); 1108. } 1109. /* if we've already confirmed Protection, skip additional checks */ 1110. if (is_you || gotprot) 1111. continue; 1112. 1113. /* omit W_SWAPWEP+W_QUIVER; W_ART+W_ARTI handled by protects() */ 1114. wearmask = W_ARMOR | W_ACCESSORY; 1115. if (o->oclass == WEAPON_CLASS || is_weptool(o)) 1116. wearmask |= W_WEP; 1117. if (protects(o, ((o->owornmask & wearmask) != 0L) ? TRUE : FALSE)) 1118. gotprot = TRUE; 1119. } 1120. 1121. if (gotprot) { 1122. /* extrinsic Protection increases mc by 1 (2 for amulet of guarding); 1123. multiple sources don't provide multiple increments */ 1124. mc += via_amul ? 2 : 1; 1125. if (mc > 3) 1126. mc = 3; 1127. } else if (mc < 1) { 1128. /* intrinsic Protection is weaker (play balance; obtaining divine 1129. protection is too easy); it confers minimum mc 1 instead of 0 */ 1130. if ((is_you && ((HProtection && u.ublessed > 0) || u.uspellprot)) 1131. /* aligned priests and angels have innate intrinsic Protection */ 1132. || (mon->data == &mons[PM_ALIGNED_CLERIC] 1133. || is_minion(mon->data))) 1134. mc = 1; 1135. } 1136. return mc; 1137. } 1138. 1139. /* 1140. * hitmu: monster hits you 1141. * returns MM_ flags 1142. */ 1143. staticfn int 1144. hitmu(struct monst *mtmp, struct attack *mattk) 1145. { 1146. struct permonst *mdat = mtmp->data; 1147. struct permonst *olduasmon = gy.youmonst.data; 1148. int res; 1149. struct mhitm_data mhm; 1150. mhm.hitflags = M_ATTK_MISS; 1151. mhm.permdmg = 0; 1152. mhm.specialdmg = 0; 1153. mhm.done = FALSE; 1154. 1155. if (!canspotmon(mtmp)) 1156. map_invisible(mtmp->mx, mtmp->my); 1157. 1158. /* If the monster is undetected & hits you, you should know where 1159. * the attack came from. 1160. */ 1161. if (mtmp->mundetected && (hides_under(mdat) || mdat->mlet == S_EEL)) { 1162. mtmp->mundetected = 0; 1163. if (!tp_sensemon(mtmp) && !Detect_monsters) { 1164. struct obj *obj; 1165. const char *what; 1166. char Amonbuf[BUFSZ]; 1167. 1168. if ((obj = svl.level.objects[mtmp->mx][mtmp->my]) != 0) { 1169. if (Blind && !obj->dknown) 1170. what = something; 1171. else if (is_pool(mtmp->mx, mtmp->my) && !Underwater) 1172. what = "the water"; 1173. else 1174. what = doname(obj); 1175. 1176. Strcpy(Amonbuf, Amonnam(mtmp)); 1177. /* mtmp might be invisible with hero unable to see same */ 1178. if (!strcmp(Amonbuf, "It")) /* note: not strcmpi() */ 1179. Strcpy(Amonbuf, Something); 1180. pline("%s was hidden under %s!", Amonbuf, what); 1181. } 1182. newsym(mtmp->mx, mtmp->my); 1183. } 1184. } 1185. 1186. /* First determine the base damage done */ 1187. mhm.damage = d((int) mattk->damn, (int) mattk->damd); 1188. if ((is_undead(mdat) || is_vampshifter(mtmp)) && midnight()) 1189. mhm.damage += d((int) mattk->damn, (int) mattk->damd); /* extra dmg */ 1190. 1191. mhitm_adtyping(mtmp, mattk, &gy.youmonst, &mhm); 1192. 1193. (void) mhitm_knockback(mtmp, &gy.youmonst, mattk, &mhm.hitflags, 1194. (MON_WEP(mtmp) != 0)); 1195. 1196. if (mhm.done) 1197. return mhm.hitflags; 1198. 1199. if ((Upolyd ? u.mh : u.uhp) < 1) { 1200. /* already dead? call rehumanize() or done_in_by() as appropriate */ 1201. mdamageu(mtmp, 1); 1202. mhm.damage = 0; 1203. } 1204. 1205. /* Negative armor class reduces damage done instead of fully protecting 1206. * against hits. 1207. */ 1208. if (mhm.damage && u.uac < 0) { 1209. mhm.damage -= rnd(-u.uac); 1210. if (mhm.damage < 1) 1211. mhm.damage = 1; 1212. } 1213. 1214. if (mhm.damage > 0) { 1215. /* [Half_physical_damage isn't applied to mhm.permdmg] */ 1216. if (Half_physical_damage 1217. /* Mitre of Holiness, even if not currently blessed */ 1218. || (Role_if(PM_CLERIC) && uarmh && is_quest_artifact(uarmh) 1219. && mon_hates_blessings(mtmp))) 1220. mhm.damage = (mhm.damage + 1) / 2; 1221. 1222. if (mhm.permdmg) { /* Death's life force drain */ 1223. int lowerlimit, *hpmax_p; 1224. /* 1225. * Apply some of the damage to permanent hit points: 1226. * polymorphed 100% against poly'd hpmax 1227. * hpmax > 25*lvl 100% against normal hpmax 1228. * hpmax > 10*lvl 50..100% 1229. * hpmax > 5*lvl 25..75% 1230. * otherwise 0..50% 1231. * Never reduces hpmax below 1 hit point per level. 1232. */ 1233. mhm.permdmg = rn2(mhm.damage / 2 + 1); 1234. if (Upolyd || u.uhpmax > 25 * u.ulevel) 1235. mhm.permdmg = mhm.damage; 1236. else if (u.uhpmax > 10 * u.ulevel) 1237. mhm.permdmg += mhm.damage / 2; 1238. else if (u.uhpmax > 5 * u.ulevel) 1239. mhm.permdmg += mhm.damage / 4; 1240. 1241. if (Upolyd) { 1242. hpmax_p = &u.mhmax; 1243. /* [can't use gy.youmonst.m_lev] */ 1244. lowerlimit = min((int) gy.youmonst.data->mlevel, u.ulevel); 1245. } else { 1246. hpmax_p = &u.uhpmax; 1247. lowerlimit = minuhpmax(1); 1248. } 1249. if (*hpmax_p - mhm.permdmg > lowerlimit) 1250. *hpmax_p -= mhm.permdmg; 1251. else if (*hpmax_p > lowerlimit) 1252. *hpmax_p = lowerlimit; 1253. /* else unlikely... 1254. * already at or below minimum threshold, do nothing to hpmax */ 1255. disp.botl = TRUE; 1256. } 1257. 1258. mdamageu(mtmp, mhm.damage); 1259. } 1260. 1261. if (mhm.damage) 1262. res = passiveum(olduasmon, mtmp, mattk); 1263. else 1264. res = M_ATTK_HIT; 1265. stop_occupation(); 1266. return res; 1267. } 1268. 1269. /* An interface for use when taking a blindfold off, for example, 1270. * to see if an engulfing attack should immediately take affect, like 1271. * a passive attack. TRUE if engulfing blindness occurred */ 1272. boolean 1273. gulp_blnd_check(void) 1274. { 1275. struct attack *mattk; 1276. 1277. if (!Blinded && u.uswallow 1278. && (mattk = attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)) 1279. && can_blnd(u.ustuck, &gy.youmonst, mattk->aatyp, (struct obj *) 0)) { 1280. ++u.uswldtim; /* compensate for gulpmu change */ 1281. (void) gulpmu(u.ustuck, mattk); 1282. return TRUE; 1283. } 1284. return FALSE; 1285. } 1286. 1287. /* monster swallows you, or damage if already swallowed (u.uswallow != 0) */ 1288. staticfn int 1289. gulpmu(struct monst *mtmp, struct attack *mattk) 1290. { 1291. struct trap *t = t_at(u.ux, u.uy); 1292. int tmp = d((int) mattk->damn, (int) mattk->damd); 1293. int tim_tmp; 1294. struct obj *otmp2, *nextobj; 1295. int i; 1296. boolean physical_damage = FALSE; 1297. 1298. if (!u.uswallow) { /* swallows you */ 1299. int omx = mtmp->mx, omy = mtmp->my; 1300. 1301. if (!engulf_target(mtmp, &gy.youmonst)) 1302. return M_ATTK_MISS; 1303. if ((t && is_pit(t->ttyp)) && sobj_at(BOULDER, u.ux, u.uy)) 1304. return M_ATTK_MISS; 1305. if (failed_grab(mtmp, &gy.youmonst, mattk)) 1306. return M_ATTK_MISS; 1307. 1308. if (Punished) 1309. unplacebc(); /* ball&chain go away */ 1310. remove_monster(omx, omy); 1311. mtmp->mtrapped = 0; /* no longer on old trap */ 1312. place_monster(mtmp, u.ux, u.uy); 1313. set_ustuck(mtmp); 1314. newsym(mtmp->mx, mtmp->my); 1315. /* 5.0: dismount for all engulfers, not just for purple worms */ 1316. if (u.usteed) { 1317. char buf[BUFSZ]; 1318. 1319. Strcpy(buf, mon_nam(u.usteed)); 1320. urgent_pline("%s %s forward and plucks you off %s!", 1321. Some_Monnam(mtmp), 1322. /* 't', purple 'w' */ 1323. is_animal(mtmp->data) ? "lunges" 1324. /* 'v', air 'E' */ 1325. : is_whirly(mtmp->data) ? "whirls" 1326. /* none (some 'v', already whirling) */ 1327. : unsolid(mtmp->data) ? "flows" 1328. /* ochre 'j', Juiblex */ 1329. : amorphous(mtmp->data) ? "oozes" 1330. /* none (all AT_ENGL are already covered) */ 1331. : "surges", 1332. buf); 1333. dismount_steed(DISMOUNT_ENGULFED); 1334. } else { 1335. urgent_pline("%s %s!", Monnam(mtmp), 1336. digests(mtmp->data) ? "swallows you whole" 1337. : enfolds(mtmp->data) ? "folds itself around you" 1338. : "engulfs you"); 1339. } 1340. stop_occupation(); 1341. reset_occupations(); /* behave as if you had moved */ 1342. 1343. if (u.utrap) { 1344. You("are released from the %s!", 1345. (u.utraptype == TT_WEB) ? "web" : "trap"); 1346. reset_utrap(FALSE); 1347. } 1348. 1349. i = number_leashed(); 1350. if (i > 0) { 1351. const char *s = (i > 1) ? "leashes" : "leash"; 1352. 1353. pline_The("%s %s loose.", s, vtense(s, "snap")); 1354. unleash_all(); 1355. } 1356. 1357. if (touch_petrifies(gy.youmonst.data) && !resists_ston(mtmp)) { 1358. /* put the attacker back where it started; 1359. the resulting statue will end up there 1360. [note: if poly'd hero could ride or non-poly'd hero could 1361. acquire touch_petrifies() capability somehow, this code 1362. would need to deal with possibility of steed having taken 1363. engulfer's previous spot when hero was forcibly dismounted] */ 1364. remove_monster(mtmp->mx, mtmp->my); /* u.ux,u.uy */ 1365. place_monster(mtmp, omx, omy); 1366. minstapetrify(mtmp, TRUE); 1367. /* normally unstuck() would do this, but we're not 1368. fully swallowed yet so that won't work here */ 1369. if (Punished) 1370. placebc(); 1371. set_ustuck((struct monst *) 0); 1372. return (!DEADMONSTER(mtmp)) ? M_ATTK_MISS : M_ATTK_AGR_DIED; 1373. } 1374. 1375. display_nhwindow(WIN_MESSAGE, FALSE); 1376. vision_recalc(2); /* hero can't see anything */ 1377. u.uswallow = 1; 1378. /* for digestion, shorter time is more dangerous; 1379. for other swallowings, longer time means more 1380. chances for the swallower to attack */ 1381. if (mattk->adtyp == AD_DGST) { 1382. /* having good armor & high constitution makes 1383. it take longer for you to be digested, but 1384. you'll end up trapped inside for longer too */ 1385. tim_tmp = (int)ACURR(A_CON) + 10 - (int)u.uac + rn2(20); 1386. if (tim_tmp < 0) 1387. tim_tmp = 0; 1388. tim_tmp /= (int) mtmp->m_lev; 1389. tim_tmp += 3; 1390. } else { 1391. /* higher level attacker takes longer to eject hero */ 1392. tim_tmp = rnd((int) mtmp->m_lev + 10 / 2); 1393. } 1394. /* u.uswldtim always set > 1 */ 1395. u.uswldtim = (unsigned) ((tim_tmp < 2) ? 2 : tim_tmp); 1396. swallowed(1); /* update the map display, shows hero swallowed */ 1397. if (!flaming(mtmp->data)) { 1398. for (otmp2 = gi.invent; otmp2; otmp2 = nextobj) { 1399. nextobj = otmp2->nobj; 1400. (void) snuff_lit(otmp2); 1401. } 1402. } 1403. } 1404. 1405. if (mtmp != u.ustuck) 1406. return M_ATTK_MISS; 1407. if (Punished) { 1408. /* ball&chain are in limbo while swallowed; update their internal 1409. location to be at swallower's spot */ 1410. if (uchain->where == OBJ_FREE) 1411. uchain->ox = mtmp->mx, uchain->oy = mtmp->my; 1412. if (uball->where == OBJ_FREE) 1413. uball->ox = mtmp->mx, uball->oy = mtmp->my; 1414. } 1415. if (u.uswldtim > 0) 1416. u.uswldtim -= 1; 1417. 1418. switch (mattk->adtyp) { 1419. case AD_DGST: 1420. physical_damage = TRUE; 1421. if (Slow_digestion) { 1422. /* Messages are handled below */ 1423. u.uswldtim = 0; 1424. tmp = 0; 1425. } else if (u.uswldtim == 0) { 1426. pline("%s totally digests you!", Monnam(mtmp)); 1427. tmp = u.uhp; 1428. if (Half_physical_damage) 1429. tmp *= 2; /* sorry */ 1430. } else { 1431. pline("%s%s digests you!", Monnam(mtmp), 1432. (u.uswldtim == 2) ? " thoroughly" 1433. : (u.uswldtim == 1) ? " utterly" : ""); 1434. exercise(A_STR, FALSE); 1435. } 1436. break; 1437. case AD_PHYS: 1438. physical_damage = TRUE; 1439. if (mtmp->data == &mons[PM_FOG_CLOUD]) { 1440. You("are laden with moisture and %s", 1441. flaming(gy.youmonst.data) 1442. ? "are smoldering out!" 1443. : Breathless ? "find it mildly uncomfortable." 1444. : amphibious(gy.youmonst.data) 1445. ? "feel comforted." 1446. : "can barely breathe!"); 1447. if ((Amphibious || Breathless) && !flaming(gy.youmonst.data)) 1448. tmp = 0; 1449. } else { 1450. You("are %s!", enfolds(mtmp->data) ? "being squashed" 1451. : "pummeled with debris"); 1452. exercise(A_STR, FALSE); 1453. } 1454. break; 1455. case AD_ACID: 1456. if (Acid_resistance) { 1457. You("are covered with a seemingly harmless goo."); 1458. /* NB: the monst[un]seesu calls in gulpmu are no-ops since the 1459. hero must be currently swallowed for the attack to hit... */ 1460. monstseesu(M_SEEN_ACID); 1461. tmp = 0; 1462. } else { 1463. if (Hallucination) 1464. pline("Ouch! You've been slimed!"); 1465. else 1466. You("are covered in slime! It burns!"); 1467. exercise(A_STR, FALSE); 1468. monstunseesu(M_SEEN_ACID); 1469. } 1470. break; 1471. case AD_BLND: 1472. if (can_blnd(mtmp, &gy.youmonst, mattk->aatyp, (struct obj *) 0)) { 1473. if (!Blind) { 1474. long was_blinded = Blinded; 1475. 1476. if (!Blinded) 1477. You_cant("see in here!"); 1478. make_blinded((long) tmp, FALSE); 1479. if (!was_blinded && !Blind) 1480. Your1(vision_clears); 1481. } else 1482. /* keep him blind until disgorged */ 1483. incr_itimeout(&HBlinded, 1L); 1484. } 1485. tmp = 0; 1486. break; 1487. case AD_ELEC: 1488. if (!mtmp->mcan && rn2(2)) { 1489. pline_The("air around you crackles with electricity."); 1490. if (Shock_resistance) { 1491. shieldeff(u.ux, u.uy); 1492. You("seem unhurt."); 1493. monstseesu(M_SEEN_ELEC); 1494. ugolemeffects(AD_ELEC, tmp); 1495. tmp = 0; 1496. } else { 1497. monstunseesu(M_SEEN_ELEC); 1498. } 1499. } else 1500. tmp = 0; 1501. break; 1502. case AD_COLD: 1503. if (!mtmp->mcan && rn2(2)) { 1504. if (Cold_resistance) { 1505. shieldeff(u.ux, u.uy); 1506. You_feel("mildly chilly."); 1507. monstseesu(M_SEEN_COLD); 1508. ugolemeffects(AD_COLD, tmp); 1509. tmp = 0; 1510. } else { 1511. You("are freezing to death!"); 1512. monstunseesu(M_SEEN_COLD); 1513. } 1514. } else 1515. tmp = 0; 1516. break; 1517. case AD_FIRE: 1518. if (!mtmp->mcan && rn2(2)) { 1519. if (Fire_resistance) { 1520. shieldeff(u.ux, u.uy); 1521. You_feel("mildly hot."); 1522. monstseesu(M_SEEN_FIRE); 1523. ugolemeffects(AD_FIRE, tmp); 1524. tmp = 0; 1525. } else { 1526. You("are burning to a crisp!"); 1527. monstunseesu(M_SEEN_FIRE); 1528. } 1529. burn_away_slime(); 1530. } else 1531. tmp = 0; 1532. break; 1533. case AD_DISE: 1534. if (!diseasemu(mtmp->data)) 1535. tmp = 0; 1536. break; 1537. case AD_DREN: 1538. /* AC magic cancellation doesn't help when engulfed */ 1539. if (!mtmp->mcan && rn2(4)) /* 75% chance */ 1540. drain_en(tmp, FALSE); 1541. tmp = 0; 1542. break; 1543. default: 1544. physical_damage = TRUE; 1545. tmp = 0; 1546. break; 1547. } 1548. 1549. if (physical_damage) { 1550. /* same damage reduction for AC as in hitmu */ 1551. if (u.uac < 0) 1552. tmp -= rnd(-u.uac); 1553. if (tmp < 0) 1554. tmp = 1; 1555. 1556. tmp = Maybe_Half_Phys(tmp); 1557. } 1558. 1559. gm.mswallower = mtmp; /* match gulpmm() */ 1560. mdamageu(mtmp, tmp); 1561. gm.mswallower = 0; 1562. if (tmp) 1563. stop_occupation(); 1564. 1565. if (!u.uswallow) { 1566. ; /* life-saving has already expelled swallowed hero */ 1567. } else if (touch_petrifies(gy.youmonst.data) && !resists_ston(mtmp)) { 1568. pline("%s very hurriedly %s you!", Monnam(mtmp), 1569. digests(mtmp->data) ? "regurgitates" 1570. : enfolds(mtmp->data) ? "releases" 1571. : "expels"); 1572. expels(mtmp, mtmp->data, FALSE); 1573. } else if (!u.uswldtim || gy.youmonst.data->msize >= MZ_HUGE) { 1574. /* As of 3.6.2: u.uswldtim used to be set to 0 by life-saving but it 1575. expels now so the !u.uswldtim case is no longer possible; 1576. however, polymorphing into a huge form while already 1577. swallowed is still possible */ 1578. You("get %s!", digests(mtmp->data) ? "regurgitated" 1579. : enfolds(mtmp->data) ? "released" 1580. : "expelled"); 1581. if (flags.verbose 1582. && (digests(mtmp->data) && Slow_digestion)) 1583. pline("Obviously %s doesn't like your taste.", mon_nam(mtmp)); 1584. expels(mtmp, mtmp->data, FALSE); 1585. } 1586. return M_ATTK_HIT; 1587. } 1588. 1589. /* monster explodes in your face */ 1590. staticfn int 1591. explmu( 1592. struct monst *mtmp, 1593. struct attack *mattk, 1594. boolean ufound) 1595. { 1596. boolean kill_agr = TRUE; 1597. boolean not_affected; 1598. int tmp; 1599. 1600. if (mtmp->mcan) 1601. return M_ATTK_MISS; 1602. 1603. tmp = d((int) mattk->damn, (int) mattk->damd); 1604. not_affected = defended(mtmp, (int) mattk->adtyp); 1605. 1606. if (!ufound) { 1607. pline("%s explodes at a spot in %s!", 1608. canseemon(mtmp) ? Monnam(mtmp) : "It", 1609. is_waterwall(mtmp->mux,mtmp->muy) ? "empty water" 1610. : "thin air"); 1611. } else { 1612. hitmsg(mtmp, mattk); 1613. } 1614. 1615. switch (mattk->adtyp) { 1616. case AD_COLD: 1617. case AD_FIRE: 1618. case AD_ELEC: 1619. mon_explodes(mtmp, mattk); 1620. if (!DEADMONSTER(mtmp)) 1621. kill_agr = FALSE; /* lifesaving? */ 1622. break; 1623. case AD_BLND: 1624. not_affected = resists_blnd(&gy.youmonst); 1625. if (ufound && !not_affected) { 1626. /* sometimes you're affected even if it's invisible */ 1627. if (mon_visible(mtmp) || (rnd(tmp /= 2) > u.ulevel)) { 1628. You("are blinded by a blast of light!"); 1629. make_blinded((long) tmp, FALSE); 1630. if (!Blind) 1631. Your1(vision_clears); 1632. } else if (flags.verbose) 1633. You("get the impression it was not terribly bright."); 1634. } 1635. break; 1636. case AD_HALU: 1637. not_affected |= Blind || (u.umonnum == PM_BLACK_LIGHT 1638. || u.umonnum == PM_VIOLET_FUNGUS 1639. || dmgtype(gy.youmonst.data, AD_STUN)); 1640. if (ufound && !not_affected) { 1641. boolean chg; 1642. if (!Hallucination) 1643. You("are caught in a blast of kaleidoscopic light!"); 1644. /* avoid hallucinating the black light as it dies */ 1645. mondead(mtmp); /* remove it from map now */ 1646. kill_agr = FALSE; /* already killed (maybe lifesaved) */ 1647. chg = 1648. make_hallucinated(HHallucination + (long) tmp, FALSE, 0L); 1649. You("%s.", chg ? "are freaked out" : "seem unaffected"); 1650. } 1651. break; 1652. default: 1653. impossible("unknown exploder damage type %d", mattk->adtyp); 1654. break; 1655. } 1656. if (not_affected) { 1657. You("seem unaffected by it."); 1658. ugolemeffects((int) mattk->adtyp, tmp); 1659. } 1660. if (kill_agr && !DEADMONSTER(mtmp)) 1661. mondead(mtmp); 1662. wake_nearto(mtmp->mx, mtmp->my, 7 * 7); 1663. return (!DEADMONSTER(mtmp)) ? M_ATTK_MISS : M_ATTK_AGR_DIED; 1664. } 1665. 1666. /* monster gazes at you */ 1667. int 1668. gazemu(struct monst *mtmp, struct attack *mattk) 1669. { 1670. static const char *const reactions[] = { 1671. "confused", /* [0] */ 1672. "stunned", /* [1] */ 1673. "puzzled", "dazzled", /* [2,3] */ 1674. "irritated", "inflamed", /* [4,5] */ 1675. "tired", /* [6] */ 1676. "dulled", /* [7] */ 1677. }; 1678. int react = -1; 1679. boolean is_medusa, reflectable, 1680. cancelled = (mtmp->mcan != 0), already = FALSE, 1681. mcanseeu = (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) 1682. && mtmp->mcansee); 1683. 1684. if (m_seenres(mtmp, cvt_adtyp_to_mseenres(mattk->adtyp))) 1685. return M_ATTK_MISS; 1686. 1687. is_medusa = (mtmp->data == &mons[PM_MEDUSA]); 1688. reflectable = (Reflecting && couldsee(mtmp->mx, mtmp->my) && is_medusa); 1689. /* assumes that hero has to see monster's gaze in order to be 1690. affected, rather than monster just having to look at hero; 1691. Unaware: asleep or unconscious => not blind but won't see; 1692. when hallucinating, hero's brain doesn't register what 1693. it's seeing correctly so the gaze is usually ineffective 1694. [this could be taken a lot farther and select a gaze effect 1695. appropriate to what's currently being displayed, giving 1696. ordinary monsters a gaze attack when hero thinks he or she 1697. is facing a gazing creature, but let's not go that far...] */ 1698. if ((Hallucination && rn2(4)) || (Unaware && !reflectable)) 1699. cancelled = TRUE; 1700. 1701. switch (mattk->adtyp) { 1702. case AD_STON: 1703. /* note: Medusa is the only monster with stoning gaze, so 1704. 'is_medusa' will always be True here */ 1705. if (cancelled || !mtmp->mcansee) { 1706. if (!canseemon(mtmp)) 1707. break; /* silently */ 1708. if (Unaware) { /* can't see attacker even though not blind */ 1709. react = is_medusa ? 4 : 2; /* irritated or puzzled */ 1710. break; 1711. } 1712. if (is_medusa && Hallucination && !rn2(3)) 1713. pline("Someone seems overdue for a serpent cut."); 1714. else 1715. pline_mon(mtmp, "%s %s.", Monnam(mtmp), 1716. (is_medusa && mtmp->mcan && !react) 1717. ? "doesn't look all that ugly" 1718. : "gazes ineffectually"); 1719. break; 1720. } 1721. if (reflectable) { 1722. /* hero has line of sight to Medusa and she's not blind */ 1723. boolean useeit = canseemon(mtmp); 1724. 1725. if (useeit) 1726. (void) ureflects("%s gaze is reflected by your %s.", 1727. s_suffix(Monnam(mtmp))); 1728. if (mon_reflects(mtmp, !useeit ? (char *) 0 1729. : "The gaze is reflected away by %s %s!")) 1730. break; 1731. if (!m_canseeu(mtmp)) { /* probably you're invisible */ 1732. if (useeit) 1733. pline( 1734. "%s doesn't seem to notice that %s gaze was reflected.", 1735. Monnam(mtmp), mhis(mtmp)); 1736. break; 1737. } 1738. if (useeit) 1739. pline_mon(mtmp, "%s is turned to stone!", Monnam(mtmp)); 1740. gs.stoned = TRUE; 1741. killed(mtmp); 1742. 1743. if (!DEADMONSTER(mtmp)) 1744. break; 1745. return M_ATTK_AGR_DIED; 1746. } 1747. if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) 1748. && !Stone_resistance && !Unaware) { 1749. You("meet %s gaze.", s_suffix(mon_nam(mtmp))); 1750. stop_occupation(); 1751. if (poly_when_stoned(gy.youmonst.data) && polymon(PM_STONE_GOLEM)) 1752. break; 1753. urgent_pline("You turn to stone..."); 1754. svk.killer.format = KILLED_BY; 1755. Strcpy(svk.killer.name, pmname(mtmp->data, Mgender(mtmp))); 1756. done(STONING); 1757. } 1758. break; 1759. case AD_CONF: 1760. if (mcanseeu && !mtmp->mspec_used && rn2(5)) { 1761. if (cancelled) { 1762. react = 0; /* "confused" */ 1763. already = (mtmp->mconf != 0); 1764. } else { 1765. int conf = d(3, 4); 1766. 1767. mtmp->mspec_used = mtmp->mspec_used + (conf + rn2(6)); 1768. if (!Confusion) 1769. pline_mon(mtmp, "%s gaze confuses you!", 1770. s_suffix(Monnam(mtmp))); 1771. else 1772. You("are getting more and more confused."); 1773. make_confused(HConfusion + conf, FALSE); 1774. stop_occupation(); 1775. } 1776. } 1777. break; 1778. case AD_STUN: 1779. if (mcanseeu && !mtmp->mspec_used && rn2(5)) { 1780. if (cancelled) { 1781. react = 1; /* "stunned" */ 1782. already = (mtmp->mstun != 0); 1783. } else { 1784. int stun = d(2, 6); 1785. 1786. mtmp->mspec_used = mtmp->mspec_used + (stun + rn2(6)); 1787. pline_mon(mtmp, "%s stares piercingly at you!", Monnam(mtmp)); 1788. make_stunned((HStun & TIMEOUT) + (long) stun, TRUE); 1789. stop_occupation(); 1790. } 1791. } 1792. break; 1793. case AD_BLND: 1794. if (canseemon(mtmp) && !resists_blnd(&gy.youmonst) 1795. && mdistu(mtmp) <= BOLT_LIM * BOLT_LIM) { 1796. if (cancelled) { 1797. react = rn1(2, 2); /* "puzzled" || "dazzled" */ 1798. already = (mtmp->mcansee == 0); 1799. /* Archons gaze every round; we don't want cancelled ones 1800. giving the "seems puzzled/dazzled" message that often */ 1801. if (mtmp->mcan && mtmp->data == &mons[PM_ARCHON] && rn2(5)) 1802. react = -1; 1803. } else { 1804. int blnd = d((int) mattk->damn, (int) mattk->damd); 1805. 1806. You("are blinded by %s radiance!", s_suffix(mon_nam(mtmp))); 1807. make_blinded((long) blnd, FALSE); 1808. stop_occupation(); 1809. /* not blind at this point implies you're wearing 1810. the Eyes of the Overworld; make them block this 1811. particular stun attack too */ 1812. if (!Blind) { 1813. Your1(vision_clears); 1814. } else { 1815. long oldstun = (HStun & TIMEOUT), newstun = (long) rnd(3); 1816. 1817. /* we don't want to increment stun duration every time 1818. or sighted hero will become incapacitated */ 1819. make_stunned(max(oldstun, newstun), TRUE); 1820. } 1821. } 1822. } 1823. break; 1824. case AD_FIRE: 1825. if (mcanseeu && !mtmp->mspec_used && rn2(5)) { 1826. if (cancelled) { 1827. react = rn1(2, 4); /* "irritated" || "inflamed" */ 1828. } else { 1829. int dmg = d(2, 6), orig_dmg = dmg, lev = (int) mtmp->m_lev; 1830. 1831. pline_mon(mtmp, "%s attacks you with a fiery gaze!", 1832. Monnam(mtmp)); 1833. stop_occupation(); 1834. if (Fire_resistance) { 1835. shieldeff(u.ux, u.uy); 1836. pline_The("fire doesn't feel hot!"); 1837. monstseesu(M_SEEN_FIRE); 1838. ugolemeffects(AD_FIRE, d(12, 6)); 1839. dmg = 0; 1840. } else { 1841. monstunseesu(M_SEEN_FIRE); 1842. } 1843. burn_away_slime(); 1844. if (lev > rn2(20)) 1845. (void) burnarmor(&gy.youmonst); 1846. if (lev > rn2(20)) { 1847. (void) destroy_items(&gy.youmonst, AD_FIRE, orig_dmg); 1848. ignite_items(gi.invent); 1849. } 1850. if (dmg) 1851. mdamageu(mtmp, dmg); 1852. } 1853. } 1854. break; 1855. #ifdef PM_BEHOLDER /* work in progress */ 1856. case AD_SLEE: 1857. if (mcanseeu && gm.multi >= 0 && !rn2(5) && !Sleep_resistance) { 1858. if (cancelled) { 1859. react = 6; /* "tired" */ 1860. already = (mtmp->mfrozen != 0); /* can't happen... */ 1861. } else { 1862. fall_asleep(-rnd(10), TRUE); 1863. pline("%s gaze makes you very sleepy...", 1864. s_suffix(Monnam(mtmp))); 1865. monstunseesu(M_SEEN_SLEEP); 1866. } 1867. } 1868. break; 1869. case AD_SLOW: 1870. if (mcanseeu 1871. && (HFast & (INTRINSIC | TIMEOUT)) && !defended(mtmp, AD_SLOW) 1872. && !rn2(4)) { 1873. if (cancelled) { 1874. react = 7; /* "dulled" */ 1875. already = (mtmp->mspeed == MSLOW); 1876. } else { 1877. u_slow_down(); 1878. stop_occupation(); 1879. } 1880. } 1881. break; 1882. #endif /* BEHOLDER */ 1883. default: 1884. impossible("Gaze attack %d?", mattk->adtyp); 1885. break; 1886. } 1887. if (react >= 0) { 1888. if (Hallucination && rn2(3)) 1889. react = rn2(SIZE(reactions)); 1890. /* cancelled/hallucinatory feedback; monster might look "confused", 1891. "stunned",&c but we don't actually set corresponding attribute */ 1892. pline_mon(mtmp, "%s looks %s%s.", Monnam(mtmp), 1893. !rn2(3) ? "" : already ? "quite " 1894. : (!rn2(2) ? "a bit " : "somewhat "), 1895. reactions[react]); 1896. } 1897. return M_ATTK_MISS; 1898. } 1899. 1900. /* mtmp hits you for n points damage */ 1901. void 1902. mdamageu(struct monst *mtmp, int n) 1903. { 1904. if (n < 0) { 1905. impossible("mdamageu for negative damage? (%d)", n); 1906. n = 0; 1907. } 1908. 1909. disp.botl = TRUE; 1910. if (Upolyd) { 1911. u.mh -= n; 1912. showdamage(n); 1913. /* caller might have reduced mhmax before calling mdamageu() */ 1914. if (u.mh > u.mhmax) 1915. u.mh = u.mhmax; 1916. if (u.mh < 1) 1917. rehumanize(); 1918. } else { 1919. u.uhp -= n; 1920. showdamage(n); 1921. /* caller might have reduced uhpmax before calling mdamageu() */ 1922. if (u.uhp > u.uhpmax) 1923. u.uhp = u.uhpmax; 1924. if (u.uhp < 1) 1925. done_in_by(mtmp, DIED); 1926. } 1927. } 1928. 1929. /* returns 0 if seduction impossible, 1930. * 1 if fine, 1931. * 2 if wrong gender for nymph 1932. */ 1933. int 1934. could_seduce( 1935. struct monst *magr, struct monst *mdef, 1936. struct attack *mattk) /* non-Null: current atk; Null: genrl capability */ 1937. { 1938. struct permonst *pagr; 1939. boolean agrinvis, defperc; 1940. xint16 genagr, gendef; 1941. int adtyp; 1942. 1943. if (is_animal(magr->data)) 1944. return 0; 1945. if (magr == &gy.youmonst) { 1946. pagr = gy.youmonst.data; 1947. agrinvis = (Invis != 0); 1948. genagr = poly_gender(); 1949. } else { 1950. pagr = magr->data; 1951. agrinvis = magr->minvis; 1952. genagr = gender(magr); 1953. } 1954. if (mdef == &gy.youmonst) { 1955. defperc = (See_invisible != 0); 1956. gendef = poly_gender(); 1957. } else { 1958. defperc = perceives(mdef->data); 1959. gendef = gender(mdef); 1960. } 1961. 1962. adtyp = mattk ? mattk->adtyp 1963. : dmgtype(pagr, AD_SSEX) ? AD_SSEX 1964. : dmgtype(pagr, AD_SEDU) ? AD_SEDU 1965. : AD_PHYS; 1966. if (adtyp == AD_SSEX && !SYSOPT_SEDUCE) 1967. adtyp = AD_SEDU; 1968. 1969. if (agrinvis && !defperc && adtyp == AD_SEDU) 1970. return 0; 1971. 1972. /* nymphs have two attacks, one for steal-item damage and the other 1973. for seduction, both pass the could_seduce() test; 1974. incubi/succubi have three attacks, their claw attacks for damage 1975. don't pass the test */ 1976. if ((pagr->mlet != S_NYMPH && pagr != &mons[PM_AMOROUS_DEMON]) 1977. || (adtyp != AD_SEDU && adtyp != AD_SSEX && adtyp != AD_SITM)) 1978. return 0; 1979. 1980. return (genagr == 1 - gendef) ? 1 : (pagr->mlet == S_NYMPH) ? 2 : 0; 1981. } 1982. 1983. /* returns 1 if monster teleported (or hero leaves monster's vicinity) */ 1984. int 1985. doseduce(struct monst *mon) 1986. { 1987. struct obj *ring, *nring; 1988. boolean fem = (mon->data == &mons[PM_AMOROUS_DEMON] 1989. && Mgender(mon) == FEMALE); /* otherwise incubus */ 1990. boolean seewho, naked; /* True iff no armor */ 1991. int attr_tot, tried_gloves = 0; 1992. char qbuf[QBUFSZ], Who[QBUFSZ]; 1993. 1994. if (mon->mcan || mon->mspec_used) { 1995. pline_mon(mon, "%s acts as though %s has got a %sheadache.", 1996. Monnam(mon), mhe(mon), mon->mcan ? "severe " : ""); 1997. return 0; 1998. } 1999. if (unresponsive()) { 2000. pline_mon(mon, "%s seems dismayed at your lack of response.", 2001. Monnam(mon)); 2002. return 0; 2003. } 2004. seewho = canseemon(mon); 2005. if (!seewho) 2006. pline("Someone caresses you..."); 2007. else 2008. You_feel("very attracted to %s.", mon_nam(mon)); 2009. /* cache the seducer's name in a local buffer */ 2010. Strcpy(Who, (!seewho ? (fem ? "She" : "He") : Monnam(mon))); 2011. 2012. /* if in the process of putting armor on or taking armor off, 2013. interrupt that activity now */ 2014. (void) stop_donning((struct obj *) 0); 2015. /* don't try to take off gloves if cursed weapon blocks them */ 2016. if (welded(uwep)) 2017. tried_gloves = 1; 2018. 2019. for (ring = gi.invent; ring; ring = nring) { 2020. nring = ring->nobj; 2021. if (ring->otyp != RIN_ADORNMENT) 2022. continue; 2023. if (fem) { 2024. if (ring->owornmask && uarmg) { 2025. /* don't take off worn ring if gloves are in the way */ 2026. if (!tried_gloves++) 2027. mayberem(mon, Who, uarmg, "gloves"); 2028. if (uarmg) 2029. continue; /* next ring might not be worn */ 2030. } 2031. /* confirmation prompt when charisma is high bypassed if deaf */ 2032. if (!Deaf && rn2(20) < ACURR(A_CHA)) { 2033. (void) safe_qbuf(qbuf, "\"That ", 2034. " looks pretty. May I have it?\"", ring, 2035. xname, simpleonames, "ring"); 2036. makeknown(RIN_ADORNMENT); 2037. SetVoice(mon, 0, 80, 0); 2038. if (y_n(qbuf) == 'n') 2039. continue; 2040. } else 2041. pline("%s decides she'd like %s, and takes it.", 2042. Who, yname(ring)); 2043. makeknown(RIN_ADORNMENT); 2044. /* might be in left or right ring slot or weapon/alt-wep/quiver */ 2045. if (ring->owornmask) 2046. remove_worn_item(ring, FALSE); 2047. freeinv(ring); 2048. (void) mpickobj(mon, ring); 2049. } else { 2050. if (uleft && uright && uleft->otyp == RIN_ADORNMENT 2051. && uright->otyp == RIN_ADORNMENT) 2052. break; 2053. if (ring == uleft || ring == uright) 2054. continue; 2055. if (uarmg) { 2056. /* don't put on ring if gloves are in the way */ 2057. if (!tried_gloves++) 2058. mayberem(mon, Who, uarmg, "gloves"); 2059. if (uarmg) 2060. break; /* no point trying further rings */ 2061. } 2062. /* confirmation prompt when charisma is high bypassed if deaf */ 2063. if (!Deaf && rn2(20) < ACURR(A_CHA)) { 2064. (void) safe_qbuf(qbuf, "\"That ", 2065. " looks pretty. Would you wear it for me?\"", 2066. ring, xname, simpleonames, "ring"); 2067. makeknown(RIN_ADORNMENT); 2068. SetVoice(mon, 0, 80, 0); 2069. if (y_n(qbuf) == 'n') 2070. continue; 2071. } else { 2072. pline("%s decides you'd look prettier wearing %s,", 2073. Who, yname(ring)); 2074. pline("and puts it on your finger."); 2075. } 2076. makeknown(RIN_ADORNMENT); 2077. if (!uright) { 2078. pline("%s puts %s on your right %s.", 2079. Who, the(xname(ring)), body_part(HAND)); 2080. setworn(ring, RIGHT_RING); 2081. } else if (!uleft) { 2082. pline("%s puts %s on your left %s.", 2083. Who, the(xname(ring)), body_part(HAND)); 2084. setworn(ring, LEFT_RING); 2085. } else if (uright && uright->otyp != RIN_ADORNMENT) { 2086. /* note: the "replaces" message might be inaccurate if 2087. hero's location changes and the process gets interrupted, 2088. but trying to figure that out in advance in order to use 2089. alternate wording is not worth the effort */ 2090. pline("%s replaces %s with %s.", 2091. Who, yname(uright), yname(ring)); 2092. Ring_gone(uright); 2093. /* ring removal might cause loss of levitation which could 2094. drop hero onto trap that transports hero somewhere else */ 2095. if (u.utotype || !m_next2u(mon)) 2096. return 1; 2097. setworn(ring, RIGHT_RING); 2098. } else if (uleft && uleft->otyp != RIN_ADORNMENT) { 2099. /* see "replaces" note above */ 2100. pline("%s replaces %s with %s.", 2101. Who, yname(uleft), yname(ring)); 2102. Ring_gone(uleft); 2103. if (u.utotype || !m_next2u(mon)) 2104. return 1; 2105. setworn(ring, LEFT_RING); 2106. } else 2107. impossible("ring replacement"); 2108. Ring_on(ring); 2109. prinv((char *) 0, ring, 0L); 2110. } 2111. } 2112. 2113. naked = (!uarmc && !uarmf && !uarmg && !uarms && !uarmh && !uarmu); 2114. urgent_pline("%s %s%s.", Who, 2115. Deaf ? "seems to murmur into your ear" 2116. : naked ? "murmurs sweet nothings into your ear" 2117. : "murmurs in your ear", 2118. naked ? "" : ", while helping you undress"); 2119. mayberem(mon, Who, uarmc, cloak_simple_name(uarmc)); 2120. if (!uarmc) 2121. mayberem(mon, Who, uarm, suit_simple_name(uarm)); 2122. mayberem(mon, Who, uarmf, "boots"); 2123. if (!tried_gloves) 2124. mayberem(mon, Who, uarmg, "gloves"); 2125. mayberem(mon, Who, uarms, "shield"); 2126. mayberem(mon, Who, uarmh, helm_simple_name(uarmh)); 2127. if (!uarmc && !uarm) 2128. mayberem(mon, Who, uarmu, "shirt"); 2129. 2130. /* removing armor (levitation boots, or levitation ring to make 2131. room for adornment ring with incubus case) might result in the 2132. hero falling through a trap door or landing on a teleport trap 2133. and changing location, so hero might not be adjacent to seducer 2134. any more (mayberem() has its own adjacency test so we don't need 2135. to check after each potential removal) */ 2136. if (u.utotype || !m_next2u(mon)) 2137. return 1; 2138. 2139. if (uarm || uarmc) { 2140. if (!Deaf) { 2141. if (!(ld() && mon->female)) { 2142. SetVoice(mon, 0, 80, 0); 2143. verbalize("You're such a %s; I wish...", 2144. flags.female ? "sweet lady" : "nice guy"); 2145. } else { 2146. struct obj *yourgloves = u_carried_gloves(); 2147. 2148. /* have her call your gloves by their correct 2149. name, possibly revealing them to you */ 2150. if (yourgloves) 2151. observe_object(yourgloves); 2152. verbalize("Well, then you owe me %s%s!", 2153. yourgloves ? yname(yourgloves) 2154. : "twelve pairs of gloves", 2155. yourgloves ? " and eleven more pairs of gloves" 2156. : ""); 2157. } 2158. } else if (seewho) 2159. pline_mon(mon, "%s appears to sigh.", Monnam(mon)); 2160. /* else no regret message if can't see or hear seducer */ 2161. 2162. if (!tele_restrict(mon)) 2163. (void) rloc(mon, RLOC_MSG); 2164. return 1; 2165. } 2166. if (u.ualign.type == A_CHAOTIC) 2167. adjalign(1); 2168. 2169. /* by this point you have discovered mon's identity, blind or not... */ 2170. urgent_pline( 2171. "Time stands still while you and %s lie in each other's arms...", 2172. noit_mon_nam(mon)); 2173. /* 3.6.1: a combined total for charisma plus intelligence of 35-1 2174. used to guarantee successful outcome; now total maxes out at 32 2175. as far as deciding what will happen; chance for bad outcome when 2176. Cha+Int is 32 or more is 2/35, a bit over 5.7% */ 2177. attr_tot = ACURR(A_CHA) + ACURR(A_INT); 2178. if (rn2(35) > min(attr_tot, 32)) { 2179. /* Don't bother with mspec_used here... it didn't get tired! */ 2180. pline("%s seems to have enjoyed it more than you...", 2181. noit_Monnam(mon)); 2182. switch (rn2(5)) { 2183. case 0: 2184. You_feel("drained of energy."); 2185. u.uen = 0; 2186. u.uenmax -= rnd(Half_physical_damage ? 5 : 10); 2187. exercise(A_CON, FALSE); 2188. if (u.uenmax < 0) 2189. u.uenmax = 0; 2190. break; 2191. case 1: 2192. You("are down in the dumps."); 2193. (void) adjattrib(A_CON, -1, TRUE); 2194. exercise(A_CON, FALSE); 2195. disp.botl = TRUE; 2196. break; 2197. case 2: 2198. Your("senses are dulled."); 2199. (void) adjattrib(A_WIS, -1, TRUE); 2200. exercise(A_WIS, FALSE); 2201. disp.botl = TRUE; 2202. break; 2203. case 3: 2204. if (!resists_drli(&gy.youmonst)) { 2205. You_feel("out of shape."); 2206. losexp("overexertion"); 2207. } else { 2208. You("have a curious feeling..."); 2209. } 2210. exercise(A_CON, FALSE); 2211. exercise(A_DEX, FALSE); 2212. exercise(A_WIS, FALSE); 2213. break; 2214. case 4: { 2215. int tmp; 2216. 2217. You_feel("exhausted."); 2218. exercise(A_STR, FALSE); 2219. tmp = rn1(10, 6); 2220. losehp(Maybe_Half_Phys(tmp), "exhaustion", KILLED_BY); 2221. break; 2222. } /* case 4 */ 2223. } /* switch */ 2224. } else { 2225. mon->mspec_used = rnd(100); /* monster is worn out */ 2226. You("seem to have enjoyed it more than %s...", noit_mon_nam(mon)); 2227. switch (rn2(5)) { 2228. case 0: 2229. You_feel("raised to your full potential."); 2230. exercise(A_CON, TRUE); 2231. u.uen = (u.uenmax += rnd(5)); 2232. if (u.uenmax > u.uenpeak) 2233. u.uenpeak = u.uenmax; 2234. break; 2235. case 1: 2236. You_feel("good enough to do it again."); 2237. (void) adjattrib(A_CON, 1, TRUE); 2238. exercise(A_CON, TRUE); 2239. disp.botl = TRUE; 2240. break; 2241. case 2: 2242. You("will always remember %s...", noit_mon_nam(mon)); 2243. (void) adjattrib(A_WIS, 1, TRUE); 2244. exercise(A_WIS, TRUE); 2245. disp.botl = TRUE; 2246. break; 2247. case 3: 2248. pline("That was a very educational experience."); 2249. pluslvl(FALSE); 2250. exercise(A_WIS, TRUE); 2251. break; 2252. case 4: 2253. You_feel("restored to health!"); 2254. u.uhp = u.uhpmax; 2255. if (Upolyd) 2256. u.mh = u.mhmax; 2257. exercise(A_STR, TRUE); 2258. disp.botl = TRUE; 2259. break; 2260. } 2261. } 2262. 2263. if (mon->mtame) { /* don't charge */ 2264. ; 2265. } else if (rn2(20) < ACURR(A_CHA)) { 2266. pline("%s demands that you pay %s, but you refuse...", 2267. noit_Monnam(mon), noit_mhim(mon)); 2268. } else if (u.umonnum == PM_LEPRECHAUN) { 2269. pline_mon(mon, "%s tries to take your gold, but fails...", 2270. noit_Monnam(mon)); 2271. } else { 2272. long cost; 2273. long umoney = money_cnt(gi.invent); 2274. 2275. if (umoney > (long) LARGEST_INT - 10L) 2276. cost = (long) rnd(LARGEST_INT) + 500L; 2277. else 2278. cost = (long) rnd((int) umoney + 10) + 500L; 2279. if (mon->mpeaceful) { 2280. cost /= 5L; 2281. if (!cost) 2282. cost = 1L; 2283. } 2284. if (cost > umoney) 2285. cost = umoney; 2286. if (!cost) { 2287. if (!Deaf) { 2288. SetVoice(mon, 0, 80, 0); 2289. verbalize("It's on the house!"); 2290. } else { 2291. pline("No charge."); 2292. } 2293. } else { 2294. pline_mon(mon, "%s takes %ld %s for services rendered!", 2295. noit_Monnam(mon), cost, currency(cost)); 2296. money2mon(mon, cost); 2297. disp.botl = TRUE; 2298. } 2299. } 2300. if (!rn2(25)) 2301. mon->mcan = 1; /* monster is worn out */ 2302. if (!tele_restrict(mon)) 2303. (void) rloc(mon, RLOC_MSG); 2304. return 1; 2305. } 2306. 2307. /* 'mon' tries to remove a piece of hero's armor */ 2308. staticfn void 2309. mayberem(struct monst *mon, 2310. const char *seducer, /* only used for alternate message */ 2311. struct obj *obj, const char *str) 2312. { 2313. char qbuf[QBUFSZ]; 2314. 2315. if (!obj || !obj->owornmask) 2316. return; 2317. /* removal of a previous item might have sent the hero elsewhere 2318. (loss of levitation that leads to landing on a transport trap) */ 2319. if (u.utotype || !m_next2u(mon)) 2320. return; 2321. 2322. /* being deaf overrides confirmation prompt for high charisma */ 2323. if (Deaf) { 2324. pline("%s takes off your %s.", seducer, str); 2325. } else if (rn2(20) < ACURR(A_CHA)) { 2326. SetVoice(mon, 0, 80, 0); /* y_n aka yn_function is set up for this */ 2327. Sprintf(qbuf, "\"Shall I remove your %s, %s?\"", str, 2328. (!rn2(2) ? "lover" : !rn2(2) ? "dear" : "sweetheart")); 2329. if (y_n(qbuf) == 'n') 2330. return; 2331. } else { 2332. char hairbuf[BUFSZ]; 2333. 2334. Sprintf(hairbuf, "let me run my fingers through your %s", 2335. body_part(HAIR)); 2336. SetVoice(mon, 0, 80, 0); 2337. verbalize("Take off your %s; %s.", str, 2338. (obj == uarm) 2339. ? "let's get a little closer" 2340. : (obj == uarmc || obj == uarms) 2341. ? "it's in the way" 2342. : (obj == uarmf) 2343. ? "let me rub your feet" 2344. : (obj == uarmg) 2345. ? "they're too clumsy" 2346. : (obj == uarmu) 2347. ? "let me massage you" 2348. /* obj == uarmh */ 2349. : hairbuf); 2350. } 2351. remove_worn_item(obj, TRUE); 2352. } 2353. 2354. staticfn int 2355. assess_dmg(struct monst *mtmp, int tmp) 2356. { 2357. if ((mtmp->mhp -= tmp) <= 0) { 2358. pline_mon(mtmp, "%s dies!", Monnam(mtmp)); 2359. xkilled(mtmp, XKILL_NOMSG); 2360. if (!DEADMONSTER(mtmp)) 2361. return M_ATTK_HIT; 2362. return M_ATTK_AGR_DIED; 2363. } 2364. return M_ATTK_HIT; 2365. } 2366. 2367. #if 0 2368. /* returns True if monster has a range attack in its repertoire 2369. that it will actually utilize. Caller provides the assessment 2370. callback (optional). Callback returns 0 if the attack is 2371. active */ 2372. 2373. boolean 2374. ranged_attk_assessed( 2375. struct monst *mtmp, 2376. boolean (*assessfunc)(struct monst *, int)) 2377. { 2378. int i; 2379. struct permonst *ptr = mtmp->data; 2380. 2381. for (i = 0; i < NATTK; i++) 2382. if (DISTANCE_ATTK_TYPE(ptr->mattk[i].aatyp)) { 2383. if (!assessfunc || (*assessfunc)(mtmp, i) == 0) 2384. return TRUE; 2385. } 2386. return FALSE; 2387. } 2388. #endif 2389. 2390. /* can be used as ranged_attk_assessed() callback. 2391. Returns TRUE if monster is avoiding use of this attack */ 2392. boolean 2393. mon_avoiding_this_attack( 2394. struct monst *mtmp, 2395. int attkidx) 2396. { 2397. struct permonst *ptr = mtmp->data; 2398. int typ = -1; 2399. 2400. if (attkidx >= 0 2401. && (typ = get_atkdam_type(ptr->mattk[attkidx].adtyp)) >= 0 2402. && m_seenres(mtmp, cvt_adtyp_to_mseenres(typ))) 2403. return TRUE; 2404. return FALSE; 2405. } 2406. 2407. /* 2408. * This would be equivalent to: 2409. * ranged_attk_assessed(mtmp, mon_avoiding_this_attack) 2410. * but without the added assessment function call overhead. 2411. */ 2412. boolean 2413. ranged_attk_available(struct monst *mtmp) 2414. { 2415. int i, typ = -1; 2416. struct permonst *ptr = mtmp->data; 2417. 2418. for (i = 0; i < NATTK; i++) { 2419. if (DISTANCE_ATTK_TYPE(ptr->mattk[i].aatyp) 2420. && (typ = get_atkdam_type(ptr->mattk[i].adtyp)) >= 0 2421. && m_seenres(mtmp, cvt_adtyp_to_mseenres(typ)) == 0) 2422. return TRUE; 2423. } 2424. return FALSE; 2425. } 2426. 2427. /* FIXME: 2428. * sequencing issue: a monster's attack might cause poly'd hero 2429. * to revert to normal form. The messages for passive counterattack 2430. * would look better if they came before reverting form, but we need 2431. * to know whether hero reverted in order to decide whether passive 2432. * damage applies. 2433. */ 2434. staticfn int 2435. passiveum( 2436. struct permonst *olduasmon, 2437. struct monst *mtmp, 2438. struct attack *mattk) 2439. { 2440. int i, tmp; 2441. struct attack *oldu_mattk = 0; 2442. 2443. /* 2444. * mattk == mtmp's attack that hit you; 2445. * oldu_mattk == your passive counterattack (even if mtmp's attack 2446. * has already caused you to revert to normal form). 2447. */ 2448. for (i = 0; !oldu_mattk; i++) { 2449. if (i >= NATTK) 2450. return M_ATTK_HIT; 2451. if (olduasmon->mattk[i].aatyp == AT_NONE 2452. || olduasmon->mattk[i].aatyp == AT_BOOM) 2453. oldu_mattk = &olduasmon->mattk[i]; 2454. } 2455. if (oldu_mattk->damn) 2456. tmp = d((int) oldu_mattk->damn, (int) oldu_mattk->damd); 2457. else if (oldu_mattk->damd) 2458. tmp = d((int) olduasmon->mlevel + 1, (int) oldu_mattk->damd); 2459. else 2460. tmp = 0; 2461. 2462. /* These affect the enemy even if you were "killed" (rehumanized) */ 2463. switch (oldu_mattk->adtyp) { 2464. case AD_ACID: 2465. if (!rn2(2)) { 2466. pline_mon(mtmp, "%s is splashed by %s%s!", Monnam(mtmp), 2467. /* temporary? hack for sequencing issue: "your acid" 2468. looks strange coming immediately after player has 2469. been told that hero has reverted to normal form */ 2470. !Upolyd ? "" : "your ", hliquid("acid")); 2471. if (resists_acid(mtmp)) { 2472. pline_mon(mtmp, "%s is not affected.", Monnam(mtmp)); 2473. tmp = 0; 2474. } 2475. } else 2476. tmp = 0; 2477. if (!rn2(30)) 2478. erode_armor(mtmp, ERODE_CORRODE); 2479. if (!rn2(6)) 2480. acid_damage(MON_WEP(mtmp)); 2481. return assess_dmg(mtmp, tmp); 2482. case AD_STON: /* cockatrice */ 2483. { 2484. long protector = attk_protection((int) mattk->aatyp), 2485. wornitems = mtmp->misc_worn_check; 2486. 2487. /* wielded weapon gives same protection as gloves here */ 2488. if (MON_WEP(mtmp) != 0) 2489. wornitems |= W_ARMG; 2490. 2491. if (!resists_ston(mtmp) 2492. && (protector == 0L 2493. || (protector != ~0L 2494. && (wornitems & protector) != protector))) { 2495. if (poly_when_stoned(mtmp->data)) { 2496. mon_to_stone(mtmp); 2497. return 1; 2498. } 2499. pline_mon(mtmp, "%s turns to stone!", Monnam(mtmp)); 2500. gs.stoned = 1; 2501. xkilled(mtmp, XKILL_NOMSG); 2502. if (!DEADMONSTER(mtmp)) 2503. return M_ATTK_HIT; 2504. return M_ATTK_AGR_DIED; 2505. } 2506. return M_ATTK_HIT; 2507. } 2508. case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ 2509. if (mon_currwep) { 2510. /* by_you==True: passive counterattack to hero's action 2511. is hero's fault */ 2512. (void) drain_item(mon_currwep, TRUE); 2513. /* No message */ 2514. } 2515. return M_ATTK_HIT; 2516. default: 2517. break; 2518. } 2519. if (!Upolyd) 2520. return M_ATTK_HIT; 2521. 2522. /* These affect the enemy only if you are still a monster */ 2523. if (rn2(3)) 2524. switch (oldu_mattk->adtyp) { 2525. case AD_PHYS: 2526. if (oldu_mattk->aatyp == AT_BOOM) { 2527. You("explode!"); 2528. /* KMH, balance patch -- this is okay with unchanging */ 2529. rehumanize(); 2530. return assess_dmg(mtmp, tmp); 2531. } 2532. break; 2533. case AD_PLYS: /* Floating eye */ 2534. if (tmp > 127) 2535. tmp = 127; 2536. if (u.umonnum == PM_FLOATING_EYE) { 2537. if (!rn2(4)) 2538. tmp = 127; 2539. if (mtmp->mcansee && haseyes(mtmp->data) && rn2(3) 2540. && (perceives(mtmp->data) || !Invis)) { 2541. if (Blind) { 2542. pline("As a blind %s, you cannot defend yourself.", 2543. pmname(gy.youmonst.data, 2544. flags.female ? FEMALE : MALE)); 2545. } else { 2546. if (mon_reflects(mtmp, 2547. "Your gaze is reflected by %s %s.")) 2548. return 1; 2549. pline_mon(mtmp, "%s is frozen by your gaze!", 2550. Monnam(mtmp)); 2551. paralyze_monst(mtmp, tmp); 2552. return M_ATTK_AGR_DONE; 2553. } 2554. } 2555. } else { /* gelatinous cube */ 2556. pline_mon(mtmp, "%s is frozen by you.", Monnam(mtmp)); 2557. paralyze_monst(mtmp, tmp); 2558. return M_ATTK_AGR_DONE; 2559. } 2560. return M_ATTK_HIT; 2561. case AD_COLD: /* Brown mold or blue jelly */ 2562. if (resists_cold(mtmp)) { 2563. shieldeff(mtmp->mx, mtmp->my); 2564. pline_mon(mtmp, "%s is mildly chilly.", Monnam(mtmp)); 2565. golemeffects(mtmp, AD_COLD, tmp); 2566. tmp = 0; 2567. break; 2568. } 2569. pline_mon(mtmp, "%s is suddenly very cold!", Monnam(mtmp)); 2570. u.mh += (tmp + rn2(2)) / 2; 2571. if (u.mhmax < u.mh) 2572. u.mhmax = u.mh; 2573. if (u.mhmax > (((int) gy.youmonst.data->mlevel + 1) * 8)) 2574. (void) split_mon(&gy.youmonst, mtmp); 2575. break; 2576. case AD_STUN: /* Yellow mold */ 2577. if (!mtmp->mstun) { 2578. mtmp->mstun = 1; 2579. pline_mon(mtmp, "%s %s.", Monnam(mtmp), 2580. makeplural(stagger(mtmp->data, "stagger"))); 2581. } 2582. tmp = 0; 2583. break; 2584. case AD_FIRE: /* Red mold */ 2585. if (resists_fire(mtmp)) { 2586. shieldeff(mtmp->mx, mtmp->my); 2587. pline_mon(mtmp, "%s is mildly warm.", Monnam(mtmp)); 2588. golemeffects(mtmp, AD_FIRE, tmp); 2589. tmp = 0; 2590. break; 2591. } 2592. pline_mon(mtmp, "%s is suddenly very hot!", Monnam(mtmp)); 2593. break; 2594. case AD_ELEC: 2595. if (resists_elec(mtmp)) { 2596. shieldeff(mtmp->mx, mtmp->my); 2597. pline_mon(mtmp, "%s is slightly tingled.", Monnam(mtmp)); 2598. golemeffects(mtmp, AD_ELEC, tmp); 2599. tmp = 0; 2600. break; 2601. } 2602. pline_mon(mtmp, "%s is jolted with your electricity!", 2603. Monnam(mtmp)); 2604. break; 2605. default: 2606. tmp = 0; 2607. break; 2608. } 2609. else 2610. tmp = 0; 2611. 2612. return assess_dmg(mtmp, tmp); 2613. } 2614. 2615. struct monst * 2616. cloneu(void) 2617. { 2618. struct monst *mon; 2619. int mndx = monsndx(gy.youmonst.data); 2620. 2621. if (u.mh <= 1) 2622. return (struct monst *) 0; 2623. if (svm.mvitals[mndx].mvflags & G_EXTINCT) 2624. return (struct monst *) 0; 2625. mon = makemon(gy.youmonst.data, u.ux, u.uy, 2626. NO_MINVENT | MM_EDOG | MM_NOMSG); 2627. if (!mon) 2628. return NULL; 2629. mon->mcloned = 1; 2630. mon = christen_monst(mon, svp.plname); 2631. initedog(mon, TRUE); 2632. mon->m_lev = gy.youmonst.data->mlevel; 2633. mon->mhpmax = u.mhmax; 2634. mon->mhp = u.mh / 2; 2635. u.mh -= mon->mhp; 2636. disp.botl = TRUE; 2637. return mon; 2638. } 2639. 2640. #undef ld 2641. 2642. /*mhitu.c*/