Source:NetHack 5.0.0/src/mhitm.c
Jump to navigation
Jump to search
Below is the full text to mhitm.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/mhitm.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 mhitm.c $NHDT-Date: 1732979463 2024/11/30 07:11:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.253 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2011. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. #include "artifact.h" 8. 9. static const char brief_feeling[] = 10. "have a %s feeling for a moment, then it passes."; 11. 12. staticfn void noises(struct monst *, struct attack *); 13. staticfn void pre_mm_attack(struct monst *, struct monst *); 14. staticfn void missmm(struct monst *, struct monst *, struct attack *); 15. staticfn int hitmm(struct monst *, struct monst *, struct attack *, 16. struct obj *, int); 17. staticfn int gazemm(struct monst *, struct monst *, struct attack *); 18. staticfn int gulpmm(struct monst *, struct monst *, struct attack *); 19. staticfn int explmm(struct monst *, struct monst *, struct attack *); 20. staticfn int mdamagem(struct monst *, struct monst *, struct attack *, 21. struct obj *, int); 22. staticfn void mswingsm(struct monst *, struct monst *, struct obj *); 23. staticfn int passivemm(struct monst *, struct monst *, boolean, int, 24. struct obj *); 25. 26. staticfn void 27. noises(struct monst *magr, struct attack *mattk) 28. { 29. boolean farq = (mdistu(magr) > 15); 30. 31. if (!Deaf && (farq != gf.far_noise || svm.moves - gn.noisetime > 10)) { 32. gf.far_noise = farq; 33. gn.noisetime = svm.moves; 34. You_hear("%s%s.", 35. (mattk->aatyp == AT_EXPL) ? "an explosion" : "some noises", 36. farq ? " in the distance" : ""); 37. } 38. } 39. 40. staticfn void 41. pre_mm_attack(struct monst *magr, struct monst *mdef) 42. { 43. boolean showit = FALSE; 44. 45. /* unhiding or unmimicking happens even if hero can't see it 46. because the formerly concealed monster is now in action */ 47. if (M_AP_TYPE(mdef)) { 48. seemimic(mdef); 49. showit |= gv.vis; 50. } else if (mdef->mundetected) { 51. mdef->mundetected = 0; 52. showit |= gv.vis; 53. } 54. if (M_AP_TYPE(magr)) { 55. seemimic(magr); 56. showit |= gv.vis; 57. } else if (magr->mundetected) { 58. magr->mundetected = 0; 59. showit |= gv.vis; 60. } 61. 62. if (gv.vis) { 63. if (!canspotmon(magr)) 64. map_invisible(magr->mx, magr->my); 65. else if (showit) 66. newsym(magr->mx, magr->my); 67. if (!canspotmon(mdef)) 68. map_invisible(mdef->mx, mdef->my); 69. else if (showit) 70. newsym(mdef->mx, mdef->my); 71. } 72. } 73. 74. /* feedback for when a monster-vs-monster attack misses */ 75. staticfn void 76. missmm( 77. struct monst *magr, /* attacker */ 78. struct monst *mdef, /* defender */ 79. struct attack *mattk) /* attack and damage types */ 80. { 81. pre_mm_attack(magr, mdef); 82. 83. if (gv.vis) { 84. pline("%s %s %s.", Monnam(magr), 85. (magr->mcan || !could_seduce(magr, mdef, mattk)) ? "misses" 86. : "pretends to be friendly to", 87. mon_nam_too(mdef, magr)); 88. } else { 89. noises(magr, mattk); 90. } 91. } 92. 93. /* 94. * fightm() -- fight some other monster 95. * 96. * Returns: 97. * 0 - Monster did nothing. 98. * 1 - If the monster made an attack. The monster might have died. 99. * 100. * There is an exception to the above. If mtmp has the hero swallowed, 101. * then we report that the monster did nothing so it will continue to 102. * digest the hero. 103. */ 104. /* have monsters fight each other */ 105. int 106. fightm(struct monst *mtmp) 107. { 108. struct monst *mon, *nmon; 109. int result, has_u_swallowed; 110. /* perhaps the monster will resist Conflict */ 111. if (resist_conflict(mtmp)) 112. return 0; 113. 114. if (u.ustuck == mtmp) { 115. /* perhaps we're holding it... */ 116. if (itsstuck(mtmp)) 117. return 0; 118. } 119. has_u_swallowed = engulfing_u(mtmp); 120. 121. for (mon = fmon; mon; mon = nmon) { 122. nmon = mon->nmon; 123. if (nmon == mtmp) 124. nmon = mtmp->nmon; 125. /* Be careful to ignore monsters that are already dead, since we 126. * might be calling this before we've cleaned them up. This can 127. * happen if the monster attacked a cockatrice bare-handedly, for 128. * instance. 129. */ 130. if (mon != mtmp && !DEADMONSTER(mon)) { 131. if (monnear(mtmp, mon->mx, mon->my)) { 132. if (!u.uswallow && (mtmp == u.ustuck)) { 133. if (!rn2(4)) { 134. set_ustuck((struct monst *) 0); 135. pline("%s releases you!", Monnam(mtmp)); 136. } else 137. break; 138. } 139. 140. /* mtmp can be killed */ 141. gb.bhitpos.x = mon->mx, gb.bhitpos.y = mon->my; 142. gn.notonhead = FALSE; 143. result = mattackm(mtmp, mon); 144. 145. if (result & M_ATTK_AGR_DIED) 146. return 1; /* mtmp died */ 147. /* 148. * If mtmp has the hero swallowed, lie and say there 149. * was no attack (this allows mtmp to digest the hero). 150. */ 151. if (has_u_swallowed) 152. return 0; 153. 154. /* allow attacked monsters a chance to hit back, primarily 155. to allow monsters that resist conflict to respond */ 156. if ((result & (M_ATTK_HIT | M_ATTK_DEF_DIED)) == M_ATTK_HIT 157. && rn2(4) && mon->movement > rn2(NORMAL_SPEED)) { 158. if (mon->movement > NORMAL_SPEED) 159. mon->movement -= NORMAL_SPEED; 160. else 161. mon->movement = 0; 162. gb.bhitpos.x = mtmp->mx, gb.bhitpos.y = mtmp->my; 163. gn.notonhead = FALSE; 164. (void) mattackm(mon, mtmp); /* return attack */ 165. } 166. 167. return (result & M_ATTK_HIT) ? 1 : 0; 168. } 169. } 170. } 171. return 0; 172. } 173. 174. /* 175. * mdisplacem() -- attacker moves defender out of the way; 176. * returns same results as mattackm(). 177. */ 178. int 179. mdisplacem( 180. struct monst *magr, 181. struct monst *mdef, 182. boolean quietly) 183. { 184. struct permonst *pa, *pd; 185. int tx, ty, fx, fy; 186. 187. /* sanity checks; could matter if we unexpectedly get a long worm */ 188. if (!magr || !mdef || magr == mdef) 189. return M_ATTK_MISS; 190. pa = magr->data, pd = mdef->data; 191. tx = mdef->mx, ty = mdef->my; /* destination */ 192. fx = magr->mx, fy = magr->my; /* current location */ 193. if (m_at(fx, fy) != magr || m_at(tx, ty) != mdef) 194. return M_ATTK_MISS; 195. 196. /* The 1 in 7 failure below matches the chance in do_attack() 197. * for pet displacement. 198. */ 199. if (!rn2(7)) 200. return M_ATTK_MISS; 201. 202. /* Grid bugs cannot displace at an angle. */ 203. if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx 204. && magr->my != mdef->my) 205. return M_ATTK_MISS; 206. 207. /* undetected monster becomes un-hidden if it is displaced */ 208. if (mdef->mundetected) 209. mdef->mundetected = 0; 210. if (M_AP_TYPE(mdef) && M_AP_TYPE(mdef) != M_AP_MONSTER) 211. seemimic(mdef); 212. /* wake up the displaced defender */ 213. mdef->msleeping = 0; 214. mdef->mstrategy &= ~STRAT_WAITMASK; 215. finish_meating(mdef); 216. 217. /* 218. * Set up the visibility of action. 219. * You can observe monster displacement if you can see both of 220. * the monsters involved. 221. */ 222. gv.vis = (canspotmon(magr) && canspotmon(mdef)); 223. 224. if (touch_petrifies(pd) && !resists_ston(magr)) { 225. if (!which_armor(magr, W_ARMG)) { 226. if (poly_when_stoned(pa)) { 227. mon_to_stone(magr); 228. return M_ATTK_HIT; /* no damage during the polymorph */ 229. } 230. if (!quietly && canspotmon(magr)) { 231. if (gv.vis) { 232. pline("%s tries to move %s out of %s way.", Monnam(magr), 233. mon_nam(mdef), is_rider(pa) ? "the" : mhis(magr)); 234. } 235. pline_mon(magr, "%s turns to stone!", Monnam(magr)); 236. } 237. monstone(magr); 238. if (!DEADMONSTER(magr)) 239. return M_ATTK_HIT; /* lifesaved */ 240. else if (magr->mtame && !gv.vis) 241. You(brief_feeling, "peculiarly sad"); 242. return M_ATTK_AGR_DIED; 243. } 244. } 245. 246. remove_monster(fx, fy); /* pick up from orig position */ 247. if (mdef->wormno) 248. remove_worm(mdef); 249. else 250. remove_monster(tx, ty); 251. place_monster(magr, tx, ty); /* put down at target spot */ 252. place_monster(mdef, fx, fy); 253. if (mdef->wormno) /* now put down tail */ 254. place_worm_tail_randomly(mdef, fx, fy); 255. /* either creature might move into or out of a poison gas cloud */ 256. update_monster_region(magr); 257. update_monster_region(mdef); 258. 259. if (gv.vis && !quietly) 260. pline("%s moves %s out of %s way!", Monnam(magr), mon_nam(mdef), 261. is_rider(pa) ? "the" : mhis(magr)); 262. newsym(fx, fy); /* see it */ 263. newsym(tx, ty); /* all happen */ 264. flush_screen(0); /* make sure it shows up */ 265. 266. return M_ATTK_HIT; 267. } 268. 269. /* 270. * mattackm() -- a monster attacks another monster. 271. * 272. * --------- aggressor died 273. * / ------- defender died 274. * / / ----- defender was hit 275. * / / / 276. * x x x 277. * 278. * 0x8 M_ATTK_AGR_DONE 279. * 0x4 M_ATTK_AGR_DIED 280. * 0x2 M_ATTK_DEF_DIED 281. * 0x1 M_ATTK_HIT 282. * 0x0 M_ATTK_MISS 283. * 284. * Each successive attack has a lower probability of hitting. Some rely on 285. * success of previous attacks. ** this doesn't seem to be implemented -dl ** 286. * 287. * Attacker has targeted <bhitpos.x,bhitpos.y> rather than 288. * <mdef->mx,mdef->my>; matters for long worms. 289. * 290. * In the case of exploding monsters, the monster dies as well. 291. */ 292. int 293. mattackm( 294. struct monst *magr, 295. struct monst *mdef) 296. { 297. int i, /* loop counter */ 298. tmp, /* armor class difference */ 299. strike = 0, /* hit this attack */ 300. attk, /* attack attempted this time */ 301. struck = 0, /* hit at least once */ 302. res[NATTK], /* results of all attacks */ 303. dieroll = 0; 304. struct attack *mattk, alt_attk; 305. struct obj *mwep; 306. struct permonst *pa, *pd; 307. 308. if (!magr || !mdef) 309. return M_ATTK_MISS; /* mike@genat */ 310. if (helpless(magr)) 311. return M_ATTK_MISS; 312. pa = magr->data; 313. pd = mdef->data; 314. 315. /* Grid bugs cannot attack at an angle. */ 316. if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx 317. && magr->my != mdef->my) 318. return M_ATTK_MISS; 319. 320. /* Calculate the armour class differential. */ 321. tmp = find_mac(mdef) + magr->m_lev; 322. if (mdef->mconf || helpless(mdef)) { 323. tmp += 4; 324. mdef->msleeping = 0; 325. } 326. 327. /* mundetected monsters become un-hidden if they are attacked */ 328. if (mdef->mundetected) { 329. mdef->mundetected = 0; 330. newsym(mdef->mx, mdef->my); 331. if (canseemon(mdef) && !sensemon(mdef)) { 332. if (Unaware) { 333. boolean justone = (mdef->data->geno & G_UNIQ) != 0L; 334. const char *montype; 335. 336. montype = noname_monnam(mdef, justone ? ARTICLE_THE 337. : ARTICLE_NONE); 338. if (!justone) 339. montype = makeplural(montype); 340. You("dream of %s.", montype); 341. } else { 342. if (iflags.last_msg == PLNMSG_HIDE_UNDER 343. && mdef->m_id == gl.last_hider) 344. pline_mon(mdef, "%s emerges from hiding.", Monnam(mdef)); 345. else if (mdef->m_id == gl.last_hider) 346. You("notice %s.", mon_nam(mdef)); 347. else 348. pline("Suddenly, you notice %s.", a_monnam(mdef)); 349. } 350. } 351. } 352. 353. /* Elves hate orcs. */ 354. if (is_elf(pa) && is_orc(pd)) 355. tmp++; 356. 357. /* Set up the visibility of action */ 358. gv.vis = ((cansee(magr->mx, magr->my) && canspotmon(magr)) 359. || (cansee(mdef->mx, mdef->my) && canspotmon(mdef))); 360. 361. /* Set flag indicating monster has moved this turn. Necessary since a 362. * monster might get an attack out of sequence (i.e. before its move) in 363. * some cases, in which case this still counts as its move for the round 364. * and it shouldn't move again. 365. */ 366. magr->mlstmv = svm.moves; 367. 368. /* controls whether a mind flayer uses all of its tentacle-for-DRIN 369. attacks; when fighting a headless monster, stop after the first 370. one because repeating the same failing hit (or even an ordinary 371. tentacle miss) is very verbose and makes the flayer look stupid */ 372. gs.skipdrin = FALSE; 373. 374. /* Now perform all attacks for the monster. */ 375. for (i = 0; i < NATTK; i++) { 376. res[i] = M_ATTK_MISS; 377. 378. /* target might no longer be there */ 379. if (i > 0 && (m_at(gb.bhitpos.x, gb.bhitpos.y) != mdef 380. || DEADMONSTER(magr) || DEADMONSTER(mdef))) 381. continue; 382. 383. mattk = getmattk(magr, mdef, i, res, &alt_attk); 384. /* reduce verbosity for mind flayer attacking creature without a 385. head (or worm's tail); this is similar to monster with multiple 386. attacks after a wildmiss against displaced or invisible hero */ 387. if (gs.skipdrin && mattk->aatyp == AT_TENT && mattk->adtyp == AD_DRIN) 388. continue; 389. mwep = (struct obj *) 0; 390. attk = 1; 391. 392. switch (mattk->aatyp) { 393. case AT_WEAP: /* "hand to hand" attacks */ 394. if (distmin(magr->mx, magr->my, mdef->mx, mdef->my) > 1) { 395. /* D: Do a ranged attack here! */ 396. strike = (thrwmm(magr, mdef) == M_ATTK_MISS) ? 0 : 1; 397. if (strike) 398. /* don't really know if we hit or not; pretend we did */ 399. res[i] |= M_ATTK_HIT; 400. if (DEADMONSTER(mdef)) 401. res[i] = M_ATTK_DEF_DIED; 402. if (DEADMONSTER(magr)) 403. res[i] |= M_ATTK_AGR_DIED; 404. break; 405. } 406. if (magr->weapon_check == NEED_WEAPON || !MON_WEP(magr)) { 407. magr->weapon_check = NEED_HTH_WEAPON; 408. if (mon_wield_item(magr) != 0) 409. return M_ATTK_MISS; 410. } 411. possibly_unwield(magr, FALSE); 412. if ((mwep = MON_WEP(magr)) != 0) { 413. if (gv.vis) 414. mswingsm(magr, mdef, mwep); 415. tmp += hitval(mwep, mdef); 416. } 417. FALLTHROUGH; 418. /*FALLTHRU*/ 419. case AT_CLAW: 420. case AT_KICK: 421. case AT_BITE: 422. case AT_STNG: 423. case AT_TUCH: 424. case AT_BUTT: 425. case AT_TENT: 426. if (mattk->aatyp == AT_KICK && mtrapped_in_pit(magr)) 427. continue; 428. /* Nymph that teleported away on first attack? */ 429. if (distmin(magr->mx, magr->my, mdef->mx, mdef->my) > 1) 430. /* Continue because the monster may have a ranged attack. */ 431. continue; 432. /* Monsters won't attack cockatrices physically if they 433. * have a weapon instead. This instinct doesn't work for 434. * players, or under conflict or confusion. 435. */ 436. if (!magr->mconf && !Conflict && mwep && mattk->aatyp != AT_WEAP 437. && touch_petrifies(mdef->data)) { 438. strike = 0; 439. break; 440. } 441. dieroll = rnd(20 + i); 442. strike = (tmp > dieroll); 443. /* KMH -- don't accumulate to-hit bonuses */ 444. if (mwep) 445. tmp -= hitval(mwep, mdef); 446. if (strike) { 447. /* for eel AT_TUCH+AD_WRAP attack: can't grab an unsolid 448. target; the unsolid test is redundant since failed_grab 449. checks it too, but is cheap and avoids calling failed_grab 450. for ordinary targets */ 451. if (unsolid(mdef->data) && failed_grab(magr, mdef, mattk)) { 452. strike = 0; 453. break; 454. } 455. res[i] = hitmm(magr, mdef, mattk, mwep, dieroll); 456. if ((mdef->data == &mons[PM_BLACK_PUDDING] 457. || mdef->data == &mons[PM_BROWN_PUDDING]) 458. && (mwep && (objects[mwep->otyp].oc_material == IRON 459. || objects[mwep->otyp].oc_material == METAL)) 460. && mdef->mhp > 1 && !mdef->mcan) { 461. struct monst *mclone; 462. 463. if ((mclone = clone_mon(mdef, 0, 0)) != 0) { 464. if (gv.vis && canspotmon(mdef)) 465. pline("%s divides as %s hits it!", 466. Monnam(mdef), mon_nam(magr)); 467. (void) mintrap(mclone, NO_TRAP_FLAGS); 468. if (DEADMONSTER(magr)) 469. res[i] |= M_ATTK_AGR_DIED; 470. } 471. } 472. } else 473. missmm(magr, mdef, mattk); 474. break; 475. 476. case AT_HUGS: /* automatic if prev two attacks succeed */ 477. strike = (i >= 2 && res[i - 1] == M_ATTK_HIT 478. && res[i - 2] == M_ATTK_HIT); 479. if (strike) { 480. /* note: monsters with hug attacks don't wear cloaks or gloves 481. so this doesn't need a special case for hugging a shade 482. while covered by blessed armor (which does damage but does 483. not achieve a successful hold); likewise, rope golems can't 484. wield weapons so ability to choke isn't affected by such */ 485. if (failed_grab(magr, mdef, mattk)) 486. strike = 0; 487. else 488. res[i] = hitmm(magr, mdef, mattk, (struct obj *) 0, 0); 489. } 490. break; 491. 492. case AT_GAZE: 493. strike = 0; 494. res[i] = gazemm(magr, mdef, mattk); 495. break; 496. 497. case AT_EXPL: 498. /* D: Prevent explosions from a distance */ 499. if (distmin(magr->mx, magr->my, mdef->mx, mdef->my) > 1) 500. continue; 501. 502. res[i] = explmm(magr, mdef, mattk); 503. if (res[i] == M_ATTK_MISS) { /* cancelled--no attack */ 504. strike = 0; 505. attk = 0; 506. } else 507. strike = 1; /* automatic hit */ 508. break; 509. 510. case AT_ENGL: 511. if (mdef->data == &mons[PM_SHADE]) { /* no silver teeth... */ 512. if (gv.vis) 513. pline("%s attempt to engulf %s is futile.", 514. s_suffix(Monnam(magr)), mon_nam(mdef)); 515. strike = 0; 516. break; 517. } 518. if (u.usteed && mdef == u.usteed) { 519. strike = 0; 520. break; 521. } 522. /* D: Prevent engulf from a distance */ 523. if (distmin(magr->mx, magr->my, mdef->mx, mdef->my) > 1) 524. continue; 525. /* Engulfing attacks are directed at the hero if possible. -dlc */ 526. if (engulfing_u(magr)) { 527. strike = 0; 528. } else if ((strike = (tmp > rnd(20 + i))) != 0) { 529. if (failed_grab(magr, mdef, mattk)) 530. strike = 0; /* purple worm can't swallow unsolid mons */ 531. else 532. res[i] = gulpmm(magr, mdef, mattk); 533. } else { 534. missmm(magr, mdef, mattk); 535. } 536. break; 537. 538. case AT_BREA: 539. case AT_SPIT: 540. /* 541. * Ranged attacks aren't allowed at point blank range. 542. * 543. * That impacts pet use of ranged attacks. It's rather arbitrary 544. * but various parts of the code assume it to be the case, not to 545. * mention a part of player tactics when fighting dragons. 546. */ 547. if (!monnear(magr, mdef->mx, mdef->my)) { 548. int mmtmp = ((mattk->aatyp == AT_BREA) 549. ? breamm(magr, mattk, mdef) 550. : spitmm(magr, mattk, mdef)); 551. 552. strike = (mmtmp == M_ATTK_MISS) ? 0 : 1; 553. /* We don't really know if we hit or not; pretend we did. */ 554. if (strike) 555. res[i] |= M_ATTK_HIT; 556. if (DEADMONSTER(mdef)) 557. res[i] = M_ATTK_DEF_DIED; 558. if (DEADMONSTER(magr)) 559. res[i] |= M_ATTK_AGR_DIED; 560. } else { 561. strike = 0; 562. attk = 0; 563. } 564. break; 565. 566. default: /* no attack */ 567. strike = 0; 568. attk = 0; 569. break; 570. } 571. 572. if (attk && !(res[i] & M_ATTK_AGR_DIED) 573. && distmin(magr->mx, magr->my, mdef->mx, mdef->my) <= 1) 574. res[i] = passivemm(magr, mdef, strike, 575. (res[i] & M_ATTK_DEF_DIED), mwep); 576. 577. if (res[i] & M_ATTK_DEF_DIED) 578. return res[i]; 579. if (res[i] & M_ATTK_AGR_DIED) 580. return res[i]; 581. /* return if aggressor can no longer attack */ 582. if ((res[i] & M_ATTK_AGR_DONE) || helpless(magr)) 583. return res[i]; 584. /* eg. defender was knocked into a level teleport trap */ 585. if (mon_offmap(mdef)) 586. return res[i]; 587. if (res[i] & M_ATTK_HIT) 588. struck = 1; /* at least one hit */ 589. } /* for (;i < NATTK;) loop */ 590. 591. return (struck ? M_ATTK_HIT : M_ATTK_MISS); 592. } 593. 594. /* can't hold an unsolid target (ghosts, lights, vortices, most elementals) 595. or a long worm tail */ 596. boolean 597. failed_grab( 598. struct monst *magr, 599. struct monst *mdef, 600. struct attack *mattk) 601. { 602. if ((unsolid(mdef->data) || gn.notonhead) 603. /* hug attack: most holders (owlbear, python, pit fiend, &c); 604. wrap damage: eel grabbing, trapper/lurker-above engulfing; 605. stick-to damage: mimic, lichen; 606. digestion damage: purple worm swallowing */ 607. && (mattk->aatyp == AT_HUGS || mattk->adtyp == AD_WRAP 608. || mattk->adtyp == AD_STCK || mattk->adtyp == AD_DGST)) { 609. if ((gv.vis && canspotmon(mdef)) /* mon-vs-mon */ 610. || magr == &gy.youmonst || mdef == &gy.youmonst) { 611. char magrnam[BUFSZ], mdefnam[BUFSZ]; 612. boolean tailmiss = gn.notonhead; 613. const char *verb = (mattk->adtyp == AD_DGST) ? "gulp" 614. : (mattk->adtyp == AD_STCK) ? "adhere" 615. : "grab"; 616. 617. /* beware of "Foo's grab passes through Bar's ghost"; 618. mon_nam(x_monnam) calls s_suffix() for named ghosts and 619. s_suffix() uses a single static buffer; make copies of both 620. names to overcome that [note: comment predates 'tailmiss'] */ 621. Strcpy(magrnam, (magr == &gy.youmonst) ? "Your" 622. : s_suffix(Monnam(magr))); 623. if (!tailmiss) { 624. Strcpy(mdefnam, (mdef == &gy.youmonst) ? "you" 625. : mon_nam(mdef)); 626. } else { 627. /* hero poly'd into long worm can't grow tail 628. so no 'youmonst' handling is needed here */ 629. Sprintf(mdefnam, "%s tail", s_suffix(some_mon_nam(mdef))); 630. } 631. /* unsolid grab misses are actually somewhat iffy--how come 632. ordinary attacks don't also pass right through? */ 633. pline("%.99s %s attempt %s %.99s!", magrnam, verb, 634. !tailmiss ? "passes right through" : "fails to hold", 635. mdefnam); 636. } 637. return TRUE; 638. } 639. return FALSE; 640. } 641. 642. /* Returns the result of mdamagem(). */ 643. staticfn int 644. hitmm( 645. struct monst *magr, 646. struct monst *mdef, 647. struct attack *mattk, 648. struct obj *mwep, 649. int dieroll) 650. { 651. int compat; 652. boolean weaponhit = (mattk->aatyp == AT_WEAP 653. || (mattk->aatyp == AT_CLAW && mwep)), 654. silverhit = (weaponhit && mwep 655. && objects[mwep->otyp].oc_material == SILVER); 656. 657. pre_mm_attack(magr, mdef); 658. 659. compat = !magr->mcan ? could_seduce(magr, mdef, mattk) : 0; 660. if (!compat && shade_miss(magr, mdef, mwep, FALSE, gv.vis)) 661. return M_ATTK_MISS; /* bypass mdamagem() */ 662. 663. if (gv.vis) { 664. char buf[BUFSZ], magr_name[BUFSZ]; 665. 666. Strcpy(magr_name, Monnam(magr)); 667. if (compat) { 668. Snprintf(buf, sizeof buf, "%s %s", magr_name, 669. mdef->mcansee ? "smiles at" : "talks to"); 670. pline("%s %s %s.", buf, mon_nam(mdef), 671. (compat == 2) ? "engagingly" : "seductively"); 672. } else { 673. buf[0] = '\0'; 674. switch (mattk->aatyp) { 675. case AT_BITE: 676. Snprintf(buf, sizeof buf, "%s bites", magr_name); 677. break; 678. case AT_STNG: 679. Snprintf(buf, sizeof buf, "%s stings", magr_name); 680. break; 681. case AT_BUTT: 682. Snprintf(buf, sizeof buf, "%s butts", magr_name); 683. break; 684. case AT_TUCH: 685. Snprintf(buf, sizeof buf, "%s touches", magr_name); 686. break; 687. case AT_TENT: 688. Snprintf(buf, sizeof buf, "%s tentacles suck", 689. s_suffix(magr_name)); 690. break; 691. case AT_HUGS: 692. if (magr != u.ustuck) { 693. Snprintf(buf, sizeof buf, "%s squeezes", magr_name); 694. break; 695. } 696. FALLTHROUGH; 697. /*FALLTHRU*/ 698. default: 699. if (!weaponhit || !mwep || !mwep->oartifact) 700. Snprintf(buf, sizeof buf, "%s hits", magr_name); 701. break; 702. } 703. if (*buf) 704. pline("%s %s.", buf, mon_nam_too(mdef, magr)); 705. 706. if (mon_hates_silver(mdef) && silverhit) { 707. char *mdef_name = mon_nam_too(mdef, magr); 708. 709. /* note: mon_nam_too returns a modifiable buffer; so 710. does s_suffix, but it returns a single static buffer 711. and we might be calling it twice for this message */ 712. Strcpy(magr_name, s_suffix(magr_name)); 713. if (!noncorporeal(mdef->data) && !amorphous(mdef->data)) { 714. if (mdef != magr) { 715. mdef_name = s_suffix(mdef_name); 716. } else { 717. (void) strsubst(mdef_name, "himself", "his own"); 718. (void) strsubst(mdef_name, "herself", "her own"); 719. (void) strsubst(mdef_name, "itself", "its own"); 720. } 721. Strcat(mdef_name, " flesh"); 722. } 723. 724. pline("%s %s sears %s!", magr_name, /* s_suffix(magr_name), */ 725. simpleonames(mwep), mdef_name); 726. } 727. } 728. } else 729. noises(magr, mattk); 730. 731. return mdamagem(magr, mdef, mattk, mwep, dieroll); 732. } 733. 734. /* Returns the same values as mdamagem(). */ 735. staticfn int 736. gazemm(struct monst *magr, struct monst *mdef, struct attack *mattk) 737. { 738. char buf[BUFSZ]; 739. /* an Archon's gaze affects target even if Archon itself is blinded */ 740. boolean archon = (magr->data == &mons[PM_ARCHON] 741. && mattk->adtyp == AD_BLND), 742. altmesg = (archon && !magr->mcansee); 743. 744. /* bring target out of hiding even if hero doesn't see it happen (this 745. is already done in pre_mm_attack() and shouldn't be needed here) */ 746. if (mdef->data->mlet == S_MIMIC && M_AP_TYPE(mdef) != M_AP_NOTHING) 747. seemimic(mdef); 748. mdef->mundetected = 0; 749. 750. if (gv.vis) { 751. Sprintf(buf, "%s gazes %s", 752. altmesg ? Adjmonnam(magr, "blinded") : Monnam(magr), 753. altmesg ? "toward" : "at"); 754. pline("%s %s...", buf, 755. canspotmon(mdef) ? mon_nam(mdef) : "something"); 756. } 757. 758. if (magr->mcan || !mdef->mcansee 759. || (archon ? resists_blnd(mdef) : !magr->mcansee) 760. || (magr->minvis && !perceives(mdef->data)) || mdef->msleeping) { 761. if (gv.vis && canspotmon(mdef)) 762. pline("but nothing happens."); 763. return M_ATTK_MISS; 764. } 765. /* call mon_reflects 2x, first test, then, if visible, print message */ 766. if (magr->data == &mons[PM_MEDUSA] && mon_reflects(mdef, (char *) 0)) { 767. if (canseemon(mdef)) 768. (void) mon_reflects(mdef, "The gaze is reflected away by %s %s."); 769. if (mdef->mcansee) { 770. if (mon_reflects(magr, (char *) 0)) { 771. if (canseemon(magr)) 772. (void) mon_reflects(magr, 773. "The gaze is reflected away by %s %s."); 774. return M_ATTK_MISS; 775. } 776. if (mdef->minvis && !perceives(magr->data)) { 777. if (canseemon(magr)) { 778. pline( 779. "%s doesn't seem to notice that %s gaze was reflected.", 780. Monnam(magr), mhis(magr)); 781. } 782. return M_ATTK_MISS; 783. } 784. if (canseemon(magr)) 785. pline_mon(magr, "%s is turned to stone!", Monnam(magr)); 786. monstone(magr); 787. if (!DEADMONSTER(magr)) 788. return M_ATTK_MISS; 789. return M_ATTK_AGR_DIED; 790. } 791. } else if (archon) { 792. mhitm_ad_blnd(magr, mattk, mdef, (struct mhitm_data *) 0); 793. /* an Archon's blinding radiance also stuns; 794. this is different from the way the hero gets stunned because 795. a stunned monster recovers randomly instead of via countdown; 796. both cases make an effort to prevent the target from being 797. continuously stunned due to repeated gaze attacks */ 798. if (rn2(2)) 799. mdef->mstun = 1; 800. } 801. 802. return mdamagem(magr, mdef, mattk, (struct obj *) 0, 0); 803. } 804. 805. /* return True if magr is allowed to swallow mdef, False otherwise */ 806. boolean 807. engulf_target(struct monst *magr, struct monst *mdef) 808. { 809. struct rm *lev; 810. int ax, ay, dx, dy; 811. boolean uatk = (magr == &gy.youmonst), 812. udef = (mdef == &gy.youmonst); 813. 814. /* can't swallow something that's too big */ 815. if (mdef->data->msize >= MZ_HUGE 816. || (magr->data->msize < mdef->data->msize && !is_whirly(magr->data))) 817. return FALSE; 818. 819. /* can't (move to) swallow if trapped. TODO: could do some? */ 820. if (mdef->mtrapped || magr->mtrapped) 821. return FALSE; 822. 823. /* if attacker is phasing in solid rock and defender can't move there, 824. or vice versa, don't allow engulf to succeed; otherwise expelling 825. might not be able to place attacker and defender both back on map; 826. when defender is the hero, a sanity_check complaint about placing 827. the hero on top of a monster can occur */ 828. dx = (mdef == &gy.youmonst) ? u.ux : mdef->mx; 829. dy = (mdef == &gy.youmonst) ? u.uy : mdef->my; 830. lev = &levl[dx][dy]; 831. if (!(udef ? Passes_walls : passes_walls(mdef->data)) 832. && (IS_OBSTRUCTED(lev->typ) || closed_door(dx, dy) || IS_TREE(lev->typ) 833. /* not passes_bars(); engulfer isn't squeezing through */ 834. || (lev->typ == IRONBARS && !is_whirly(magr->data)))) 835. return FALSE; 836. ax = (magr == &gy.youmonst) ? u.ux : magr->mx; 837. ay = (magr == &gy.youmonst) ? u.uy : magr->my; 838. lev = &levl[ax][ay]; 839. if (!(uatk ? Passes_walls : passes_walls(magr->data)) 840. && (IS_OBSTRUCTED(lev->typ) || closed_door(ax, ay) || IS_TREE(lev->typ) 841. || (lev->typ == IRONBARS && !is_whirly(mdef->data)))) 842. return FALSE; 843. 844. return TRUE; 845. } 846. 847. /* Returns the same values as mattackm(). */ 848. staticfn int 849. gulpmm( 850. struct monst *magr, 851. struct monst *mdef, 852. struct attack *mattk) 853. { 854. coordxy ax, ay, dx, dy; 855. int status; 856. struct obj *obj; 857. 858. if (!engulf_target(magr, mdef)) 859. return M_ATTK_MISS; 860. 861. if (gv.vis) { 862. pline("%s %s %s.", Monnam(magr), 863. digests(magr->data) ? "swallows" 864. : enfolds(magr->data) ? "encloses" 865. : "engulfs", 866. mon_nam(mdef)); 867. } 868. if (!flaming(magr->data)) { 869. for (obj = mdef->minvent; obj; obj = obj->nobj) 870. (void) snuff_lit(obj); 871. } 872. 873. if (is_vampshifter(mdef) 874. && newcham(mdef, &mons[mdef->cham], NO_NC_FLAGS)) { 875. if (gv.vis) { 876. /* 'it' -- previous form is no longer available and 877. using that would be excessively verbose */ 878. pline("%s expels %s.", Monnam(magr), 879. canspotmon(mdef) ? "it" : something); 880. if (canspotmon(mdef)) { 881. pline("It turns into %s.", 882. x_monnam(mdef, ARTICLE_A, (char *) 0, 883. (SUPPRESS_NAME | SUPPRESS_IT 884. | SUPPRESS_INVISIBLE), FALSE)); 885. } 886. } 887. return M_ATTK_HIT; /* bypass mdamagem() */ 888. } 889. 890. /* 891. * All of this manipulation is needed to keep the display correct. 892. * There is a flush at the next pline(). 893. */ 894. ax = magr->mx; 895. ay = magr->my; 896. dx = mdef->mx; 897. dy = mdef->my; 898. /* 899. * Leave the defender in the monster chain at its current position, 900. * but don't leave it on the screen. Move the aggressor to the 901. * defender's position. 902. */ 903. remove_monster(dx, dy); 904. remove_monster(ax, ay); 905. place_monster(magr, dx, dy); 906. newsym(ax, ay); /* erase old position */ 907. newsym(dx, dy); /* update new position */ 908. 909. gm.mswallower = magr; /* corpse_chance() wants this */ 910. status = mdamagem(magr, mdef, mattk, (struct obj *) 0, 0); 911. gm.mswallower = (struct monst *) 0; /* reset */ 912. 913. if ((status & (M_ATTK_AGR_DIED | M_ATTK_DEF_DIED)) 914. == (M_ATTK_AGR_DIED | M_ATTK_DEF_DIED)) { 915. ; /* both died -- do nothing */ 916. } else if (status & M_ATTK_DEF_DIED) { /* defender died */ 917. /* 918. * Note: mdamagem() -> monkilled() -> mondead() -> m_detach() 919. * -> relmon() used to call remove_monster() for the dead 920. * monster even when it wasn't the one on the map, so we 921. * needed to put magr back after mdef was killed and removed 922. * from their shared spot. But now [5.0] relmon() calls 923. * mon_leaving_level() and that checks whether the monster at 924. * dying monster's coordinates is that dying monster and only 925. * removes it when they match. So magr is still at mdef's 926. * former spot these days. 927. * 928. * We still potentially do one fixup: if the gulp targeted 929. * an inhospitable location, magr will return to its previous 930. * spot instead of staying. 931. */ 932. if (!goodpos(dx, dy, magr, MM_IGNOREWATER)) { 933. if (m_at(dx, dy) == magr) { 934. remove_monster(dx, dy); 935. newsym(dx, dy); 936. } 937. dx = ax, dy = ay; /* magr's spot at start of the attack */ 938. } 939. if (m_at(dx, dy) != magr) { 940. place_monster(magr, dx, dy); 941. newsym(dx, dy); 942. } 943. /* aggressor moves to <dx,dy> and might encounter trouble there */ 944. if (minliquid(magr) 945. || (t_at(dx, dy) 946. && mintrap(magr, NO_TRAP_FLAGS) == Trap_Killed_Mon)) 947. status |= M_ATTK_AGR_DIED; 948. } else if (status & M_ATTK_AGR_DIED) { /* aggressor died */ 949. place_monster(mdef, dx, dy); 950. newsym(dx, dy); 951. } else { /* both alive, put them back */ 952. if (cansee(dx, dy)) { 953. pline("%s is %s!", Monnam(mdef), 954. digests(magr->data) ? "regurgitated" 955. : enfolds(magr->data) ? "released" 956. : "expelled"); 957. } 958. 959. remove_monster(dx,dy); 960. place_monster(magr, ax, ay); 961. place_monster(mdef, dx, dy); 962. newsym(ax, ay); 963. newsym(dx, dy); 964. } 965. 966. return status; 967. } 968. 969. staticfn int 970. explmm(struct monst *magr, struct monst *mdef, struct attack *mattk) 971. { 972. int result; 973. 974. if (magr->mcan) 975. return M_ATTK_MISS; 976. 977. if (cansee(magr->mx, magr->my)) 978. pline_mon(magr, "%s explodes!", Monnam(magr)); 979. else 980. noises(magr, mattk); 981. 982. /* monster explosion types which actually create an explosion */ 983. if (mattk->adtyp == AD_FIRE || mattk->adtyp == AD_COLD 984. || mattk->adtyp == AD_ELEC) { 985. mon_explodes(magr, mattk); 986. /* unconditionally set AGR_DIED here; lifesaving is accounted below */ 987. result = M_ATTK_AGR_DIED | (DEADMONSTER(mdef) ? M_ATTK_DEF_DIED : 0); 988. } else { 989. result = mdamagem(magr, mdef, mattk, (struct obj *) 0, 0); 990. } 991. 992. /* Kill off aggressor if it didn't die. */ 993. if (!(result & M_ATTK_AGR_DIED)) { 994. boolean was_leashed = (magr->mleashed != 0); 995. 996. mondead(magr); 997. if (!DEADMONSTER(magr)) 998. return result; /* life saved */ 999. result |= M_ATTK_AGR_DIED; 1000. 1001. /* mondead() -> m_detach() -> m_unleash() always suppresses 1002. the m_unleash() slack message, so deliver it here instead */ 1003. if (was_leashed) 1004. Your("leash falls slack."); 1005. } 1006. if (magr->mtame) /* give this one even if it was visible */ 1007. You(brief_feeling, "melancholy"); 1008. 1009. return result; 1010. } 1011. 1012. /* 1013. * See comment at top of mattackm(), for return values. 1014. */ 1015. staticfn int 1016. mdamagem( 1017. struct monst *magr, 1018. struct monst *mdef, 1019. struct attack *mattk, 1020. struct obj *mwep, 1021. int dieroll) 1022. { 1023. struct permonst *pa = magr->data, *pd = mdef->data; 1024. struct mhitm_data mhm; 1025. mhm.damage = d((int) mattk->damn, (int) mattk->damd); 1026. mhm.hitflags = M_ATTK_MISS; 1027. mhm.permdmg = 0; 1028. mhm.specialdmg = 0; 1029. mhm.dieroll = dieroll; 1030. mhm.done = FALSE; 1031. 1032. if ((touch_petrifies(pd) /* or flesh_petrifies() */ 1033. || (mattk->adtyp == AD_DGST && pd == &mons[PM_MEDUSA])) 1034. && !resists_ston(magr)) { 1035. long protector = attk_protection((int) mattk->aatyp), 1036. wornitems = magr->misc_worn_check; 1037. 1038. /* wielded weapon gives same protection as gloves here */ 1039. if (mwep) 1040. wornitems |= W_ARMG; 1041. 1042. if (protector == 0L 1043. || (protector != ~0L && (wornitems & protector) != protector)) { 1044. if (poly_when_stoned(pa)) { 1045. mon_to_stone(magr); 1046. return M_ATTK_HIT; /* no damage during the polymorph */ 1047. } 1048. if (gv.vis && canspotmon(magr)) 1049. pline_mon(magr, "%s turns to stone!", Monnam(magr)); 1050. monstone(magr); 1051. if (!DEADMONSTER(magr)) 1052. return M_ATTK_HIT; /* lifesaved */ 1053. else if (magr->mtame && !gv.vis) 1054. You(brief_feeling, "peculiarly sad"); 1055. return M_ATTK_AGR_DIED; 1056. } 1057. } 1058. 1059. mhitm_adtyping(magr, mattk, mdef, &mhm); 1060. 1061. if (mhitm_knockback(magr, mdef, mattk, &mhm.hitflags, 1062. (MON_WEP(magr) != 0)) 1063. && ((mhm.hitflags & (M_ATTK_DEF_DIED | M_ATTK_HIT)) != 0 1064. || mon_offmap(mdef))) 1065. return mhm.hitflags; 1066. 1067. if (mhm.done) 1068. return mhm.hitflags; 1069. 1070. if (!mhm.damage) 1071. return mhm.hitflags; 1072. 1073. mdef->mhp -= mhm.damage; 1074. if (mdef->mhp < 1) { 1075. if (m_at(mdef->mx, mdef->my) == magr) { /* see gulpmm() */ 1076. remove_monster(mdef->mx, mdef->my); 1077. mdef->mhp = 1; /* otherwise place_monster will complain */ 1078. place_monster(mdef, mdef->mx, mdef->my); 1079. mdef->mhp = 0; 1080. } 1081. if (mattk->aatyp == AT_WEAP || mattk->aatyp == AT_CLAW) 1082. gm.mkcorpstat_norevive = troll_baned(mdef, mwep) ? TRUE : FALSE; 1083. gz.zombify = (!mwep && zombie_maker(magr) 1084. && (mattk->aatyp == AT_TUCH 1085. || mattk->aatyp == AT_CLAW 1086. || mattk->aatyp == AT_BITE) 1087. && zombie_form(mdef->data) != NON_PM); 1088. monkilled(mdef, "", (int) mattk->adtyp); 1089. gz.zombify = FALSE; /* reset */ 1090. gm.mkcorpstat_norevive = FALSE; 1091. if (!DEADMONSTER(mdef)) 1092. return mhm.hitflags; /* mdef lifesaved */ 1093. else if (mhm.hitflags == M_ATTK_AGR_DIED) 1094. return (M_ATTK_DEF_DIED | M_ATTK_AGR_DIED); 1095. 1096. if (mattk->adtyp == AD_DGST) { 1097. /* various checks similar to dog_eat and meatobj. 1098. * after monkilled() to provide better message ordering */ 1099. if (ismnum(mdef->cham)) { 1100. (void) newcham(magr, (struct permonst *) 0, NC_SHOW_MSG); 1101. } else if (pd == &mons[PM_GREEN_SLIME] && !slimeproof(pa)) { 1102. (void) newcham(magr, &mons[PM_GREEN_SLIME], NC_SHOW_MSG); 1103. } else if (pd == &mons[PM_WRAITH]) { 1104. (void) grow_up(magr, (struct monst *) 0); 1105. /* don't grow up twice */ 1106. return (M_ATTK_DEF_DIED 1107. | (!DEADMONSTER(magr) ? 0 : M_ATTK_AGR_DIED)); 1108. } else if (pd == &mons[PM_NURSE]) { 1109. healmon(magr, magr->mhpmax, 0); 1110. } 1111. mon_givit(magr, pd); 1112. } 1113. /* caveat: above digestion handling doesn't keep `pa' up to date */ 1114. 1115. return (M_ATTK_DEF_DIED 1116. | (grow_up(magr, mdef) ? 0 : M_ATTK_AGR_DIED)); 1117. } 1118. return (mhm.hitflags == M_ATTK_AGR_DIED) ? M_ATTK_AGR_DIED : M_ATTK_HIT; 1119. } 1120. 1121. int 1122. mon_poly(struct monst *magr, struct monst *mdef, int dmg) 1123. { 1124. static const char freaky[] = " undergoes a freakish metamorphosis"; 1125. struct permonst *oldform = mdef->data; 1126. 1127. if (mdef == &gy.youmonst) { 1128. if (Antimagic) { 1129. shieldeff(u.ux, u.uy); 1130. } else if (Unchanging) { 1131. ; /* just take a little damage */ 1132. } else { 1133. /* system shock might take place in polyself() */ 1134. if (u.ulycn == NON_PM) { 1135. You("are subjected to a freakish metamorphosis."); 1136. polyself(POLY_NOFLAGS); 1137. } else if (u.umonnum != u.ulycn) { 1138. You_feel("an unnatural urge coming on."); 1139. you_were(); 1140. } else { 1141. You_feel("a natural urge coming on."); 1142. you_unwere(FALSE); 1143. } 1144. dmg = 0; 1145. } 1146. } else { 1147. char Before[BUFSZ]; 1148. 1149. Strcpy(Before, Monnam(mdef)); 1150. if (resists_magm(mdef)) { 1151. /* Magic resistance */ 1152. if (gv.vis) 1153. shieldeff_mon(mdef); 1154. } else if (resist(mdef, WAND_CLASS, 0, TELL)) { 1155. /* general resistance to magic... */ 1156. ; 1157. } else if (!rn2(25) && mdef->cham == NON_PM 1158. && (mdef->mcan 1159. || pm_to_cham(monsndx(mdef->data)) != NON_PM)) { 1160. /* system shock; this variation takes away half of mon's HP 1161. rather than kill outright */ 1162. if (gv.vis) 1163. pline("%s shudders!", Before); 1164. 1165. dmg += (mdef->mhpmax + 1) / 2; 1166. mdef->mhp -= dmg; 1167. dmg = 0; 1168. if (DEADMONSTER(mdef)) { 1169. if (magr == &gy.youmonst) 1170. xkilled(mdef, XKILL_GIVEMSG | XKILL_NOCORPSE); 1171. else 1172. monkilled(mdef, "", AD_RBRE); 1173. } 1174. } else if (newcham(mdef, (struct permonst *) 0, NO_NC_FLAGS)) { 1175. if (gv.vis) { /* either seen or adjacent */ 1176. boolean was_seen = !!strcmpi("It", Before), 1177. verbosely = flags.verbose || !was_seen; 1178. 1179. if (canspotmon(mdef)) 1180. pline("%s%s%s turns into %s.", Before, 1181. verbosely ? freaky : "", verbosely ? " and" : "", 1182. x_monnam(mdef, ARTICLE_A, (char *) 0, 1183. (SUPPRESS_NAME | SUPPRESS_IT 1184. | SUPPRESS_INVISIBLE), FALSE)); 1185. else if (was_seen || magr == &gy.youmonst) 1186. pline("%s%s%s.", Before, freaky, 1187. !was_seen ? "" : " and disappears"); 1188. } 1189. dmg = 0; 1190. if (can_teleport(magr->data)) { 1191. if (magr == &gy.youmonst) 1192. tele(); 1193. else if (!tele_restrict(magr)) 1194. (void) rloc(magr, RLOC_MSG); 1195. } 1196. } else { 1197. if (gv.vis && flags.verbose) 1198. pline1(nothing_happens); 1199. } 1200. } 1201. /* when a transformation has happened, can't attack again for poly 1202. effect during next turn or two; not enforced for poly'd hero */ 1203. if (mdef->data != oldform && magr != &gy.youmonst) 1204. magr->mspec_used += rnd(2); 1205. 1206. return dmg; 1207. } 1208. 1209. void 1210. paralyze_monst(struct monst *mon, int amt) 1211. { 1212. if (amt > 127) 1213. amt = 127; 1214. 1215. mon->mcanmove = 0; 1216. mon->mfrozen = amt; 1217. mon->meating = 0; /* terminate any meal-in-progress */ 1218. mon->mstrategy &= ~STRAT_WAITFORU; 1219. } 1220. 1221. /* `mon' is hit by a sleep attack; return 1 if it's affected, 0 otherwise */ 1222. int 1223. sleep_monst(struct monst *mon, int amt, int how) 1224. { 1225. /* reveal mimic unless already asleep or paralyzed (won't be 'busy') */ 1226. if (how >= 0 && !mon->msleeping && !mon->mfrozen 1227. && mon->data->mlet == S_MIMIC && (M_AP_TYPE(mon) == M_AP_FURNITURE 1228. || M_AP_TYPE(mon) == M_AP_OBJECT)) 1229. seemimic(mon); 1230. 1231. if (resists_sleep(mon) || defended(mon, AD_SLEE) 1232. || (how >= 0 && resist(mon, (char) how, 0, NOTELL))) { 1233. shieldeff(mon->mx, mon->my); 1234. } else if (mon->mcanmove) { 1235. finish_meating(mon); /* terminate any meal-in-progress */ 1236. amt += (int) mon->mfrozen; 1237. if (amt > 0) { /* sleep for N turns */ 1238. mon->mcanmove = 0; 1239. mon->mfrozen = min(amt, 127); 1240. } else { /* sleep until awakened */ 1241. mon->msleeping = 1; 1242. } 1243. return 1; 1244. } 1245. return 0; 1246. } 1247. 1248. /* sleeping grabber releases, engulfer doesn't; don't use for paralysis! */ 1249. void 1250. slept_monst(struct monst *mon) 1251. { 1252. if (helpless(mon) && mon == u.ustuck 1253. && !sticks(gy.youmonst.data) && !u.uswallow) { 1254. pline_mon(mon, "%s grip relaxes.", s_suffix(Monnam(mon))); 1255. unstuck(mon); 1256. } 1257. } 1258. 1259. void 1260. rustm(struct monst *mdef, struct obj *obj) 1261. { 1262. int dmgtyp = ERODE_NONE, chance = 1; 1263. 1264. if (!mdef || !obj) 1265. return; /* just in case */ 1266. /* AD_ACID and AD_ENCH are handled in passivemm() and passiveum() */ 1267. if (dmgtype(mdef->data, AD_CORR)) { 1268. dmgtyp = ERODE_CORRODE; 1269. } else if (dmgtype(mdef->data, AD_RUST)) { 1270. dmgtyp = ERODE_RUST; 1271. } else if (dmgtype(mdef->data, AD_FIRE) 1272. /* steam vortex: fire resist applies, fire damage doesn't */ 1273. && mdef->data != &mons[PM_STEAM_VORTEX]) { 1274. dmgtyp = ERODE_BURN; 1275. chance = 6; 1276. } 1277. 1278. if (dmgtyp != ERODE_NONE && !rn2(chance)) 1279. (void) erode_obj(obj, (char *) 0, dmgtyp, EF_GREASE | EF_VERBOSE); 1280. } 1281. 1282. staticfn void 1283. mswingsm( 1284. struct monst *magr, /* attacker */ 1285. struct monst *mdef, /* defender */ 1286. struct obj *otemp) /* attacker's weapon */ 1287. { 1288. if (flags.verbose && !Blind && mon_visible(magr)) { 1289. boolean bash = (is_pole(otemp) && !is_art(otemp, ART_SNICKERSNEE) 1290. && (dist2(magr->mx, magr->my, mdef->mx, mdef->my) 1291. <= 2)); 1292. 1293. pline("%s %s %s%s %s at %s.", Monnam(magr), mswings_verb(otemp, bash), 1294. (otemp->quan > 1L) ? "one of " : "", mhis(magr), xname(otemp), 1295. mon_nam(mdef)); 1296. } 1297. } 1298. 1299. /* 1300. * Passive responses by defenders. Does not replicate responses already 1301. * handled above. Returns same values as mattackm. 1302. */ 1303. staticfn int 1304. passivemm( 1305. struct monst *magr, 1306. struct monst *mdef, 1307. boolean mhitb, 1308. int mdead, 1309. struct obj *mwep) 1310. { 1311. struct permonst *mddat = mdef->data; 1312. struct permonst *madat = magr->data; 1313. char buf[BUFSZ]; 1314. int i, tmp; 1315. int mhit = mhitb ? M_ATTK_HIT : M_ATTK_MISS; 1316. 1317. for (i = 0;; i++) { 1318. if (i >= NATTK) 1319. return (mdead | mhit); /* no passive attacks */ 1320. if (mddat->mattk[i].aatyp == AT_NONE) 1321. break; 1322. } 1323. if (mddat->mattk[i].damn) 1324. tmp = d((int) mddat->mattk[i].damn, (int) mddat->mattk[i].damd); 1325. else if (mddat->mattk[i].damd) 1326. tmp = d((int) mddat->mlevel + 1, (int) mddat->mattk[i].damd); 1327. else 1328. tmp = 0; 1329. 1330. /* These affect the enemy even if defender killed */ 1331. switch (mddat->mattk[i].adtyp) { 1332. case AD_ACID: 1333. if (mhitb && !rn2(2)) { 1334. Strcpy(buf, Monnam(magr)); 1335. if (canseemon(magr)) 1336. pline("%s is splashed by %s %s!", buf, 1337. s_suffix(mon_nam(mdef)), hliquid("acid")); 1338. if (resists_acid(magr)) { 1339. if (canseemon(magr)) 1340. pline("%s is not affected.", Monnam(magr)); 1341. tmp = 0; 1342. } 1343. } else 1344. tmp = 0; 1345. if (!rn2(30)) 1346. erode_armor(magr, ERODE_CORRODE); 1347. if (!rn2(6)) 1348. acid_damage(MON_WEP(magr)); 1349. goto assess_dmg; 1350. case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ 1351. if (mhitb && !mdef->mcan && mwep) { 1352. (void) drain_item(mwep, FALSE); 1353. /* No message */ 1354. } 1355. break; 1356. default: 1357. break; 1358. } 1359. if (mdead || mdef->mcan) 1360. return (mdead | mhit); 1361. 1362. /* These affect the enemy only if defender is still alive */ 1363. if (rn2(3)) 1364. switch (mddat->mattk[i].adtyp) { 1365. case AD_PLYS: /* Floating eye */ 1366. if (tmp > 127) 1367. tmp = 127; 1368. if (mddat == &mons[PM_FLOATING_EYE]) { 1369. if (!rn2(4)) 1370. tmp = 127; 1371. if (magr->mcansee && haseyes(madat) && mdef->mcansee 1372. && (perceives(madat) || !mdef->minvis)) { 1373. /* construct format string; guard against '%' in Monnam */ 1374. Strcpy(buf, s_suffix(Monnam(mdef))); 1375. (void) strNsubst(buf, "%", "%%", 0); 1376. Strcat(buf, " gaze is reflected by %s %s."); 1377. if (mon_reflects(magr, 1378. canseemon(magr) ? buf : (char *) 0)) 1379. return (mdead | mhit); 1380. Strcpy(buf, Monnam(magr)); 1381. if (canseemon(magr)) 1382. pline("%s is frozen by %s gaze!", buf, 1383. s_suffix(mon_nam(mdef))); 1384. paralyze_monst(magr, tmp); 1385. return (mdead | mhit); 1386. } 1387. } else { /* gelatinous cube */ 1388. Strcpy(buf, Monnam(magr)); 1389. if (canseemon(magr)) 1390. pline("%s is frozen by %s.", buf, mon_nam(mdef)); 1391. paralyze_monst(magr, tmp); 1392. return (mdead | mhit); 1393. } 1394. return 1; 1395. case AD_COLD: 1396. if (resists_cold(magr)) { 1397. if (canseemon(magr)) { 1398. pline_mon(magr, "%s is mildly chilly.", Monnam(magr)); 1399. golemeffects(magr, AD_COLD, tmp); 1400. } 1401. tmp = 0; 1402. break; 1403. } 1404. if (canseemon(magr)) 1405. pline_mon(magr, "%s is suddenly very cold!", Monnam(magr)); 1406. healmon(mdef, tmp/2, tmp/2); 1407. if (mdef->mhpmax > ((int) (mdef->m_lev + 1) * 8)) 1408. (void) split_mon(mdef, magr); 1409. break; 1410. case AD_STUN: 1411. if (!magr->mstun) { 1412. magr->mstun = 1; 1413. if (canseemon(magr)) 1414. pline_mon(magr, "%s %s...", Monnam(magr), 1415. makeplural(stagger(magr->data, "stagger"))); 1416. } 1417. tmp = 0; 1418. break; 1419. case AD_FIRE: 1420. if (resists_fire(magr)) { 1421. if (canseemon(magr)) { 1422. pline_mon(magr, "%s is mildly warmed.", Monnam(magr)); 1423. golemeffects(magr, AD_FIRE, tmp); 1424. } 1425. tmp = 0; 1426. break; 1427. } 1428. if (canseemon(magr)) 1429. pline_mon(magr, "%s is suddenly very hot!", Monnam(magr)); 1430. break; 1431. case AD_ELEC: 1432. if (resists_elec(magr)) { 1433. if (canseemon(magr)) { 1434. pline_mon(magr, "%s is mildly tingled.", Monnam(magr)); 1435. golemeffects(magr, AD_ELEC, tmp); 1436. } 1437. tmp = 0; 1438. break; 1439. } 1440. if (canseemon(magr)) 1441. pline_mon(magr, "%s is jolted with electricity!", 1442. Monnam(magr)); 1443. break; 1444. default: 1445. tmp = 0; 1446. break; 1447. } 1448. else 1449. tmp = 0; 1450. 1451. assess_dmg: 1452. if ((magr->mhp -= tmp) <= 0) { 1453. monkilled(magr, "", (int) mddat->mattk[i].adtyp); 1454. return (mdead | mhit | M_ATTK_AGR_DIED); 1455. } 1456. return (mdead | mhit); 1457. } 1458. 1459. /* hero or monster has successfully hit target mon with drain energy attack */ 1460. void 1461. xdrainenergym(struct monst *mon, boolean givemsg) 1462. { 1463. if (mon->mspec_used < 20 /* limit draining */ 1464. && (attacktype(mon->data, AT_MAGC) 1465. || attacktype(mon->data, AT_BREA))) { 1466. mon->mspec_used += d(2, 2); 1467. if (givemsg) 1468. pline_mon(mon, "%s seems lethargic.", Monnam(mon)); 1469. } 1470. } 1471. 1472. /* "aggressive defense"; what type of armor prevents specified attack 1473. from touching its target? */ 1474. long 1475. attk_protection(int aatyp) 1476. { 1477. long w_mask = 0L; 1478. 1479. switch (aatyp) { 1480. case AT_NONE: 1481. case AT_SPIT: 1482. case AT_EXPL: 1483. case AT_BOOM: 1484. case AT_GAZE: 1485. case AT_BREA: 1486. case AT_MAGC: 1487. w_mask = ~0L; /* special case; no defense needed */ 1488. break; 1489. case AT_CLAW: 1490. case AT_TUCH: 1491. case AT_WEAP: 1492. w_mask = W_ARMG; /* caller needs to check for weapon */ 1493. break; 1494. case AT_KICK: 1495. w_mask = W_ARMF; 1496. break; 1497. case AT_BUTT: 1498. w_mask = W_ARMH; 1499. break; 1500. case AT_HUGS: 1501. w_mask = (W_ARMC | W_ARMG); /* attacker needs both to be protected */ 1502. break; 1503. case AT_BITE: 1504. case AT_STNG: 1505. case AT_ENGL: 1506. case AT_TENT: 1507. default: 1508. w_mask = 0L; /* no defense available */ 1509. break; 1510. } 1511. return w_mask; 1512. } 1513. 1514. /*mhitm.c*/