Source:NetHack 3.6.2/src/uhitm.c
Jump to navigation
Jump to search
Below is the full text to uhitm.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/uhitm.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 3.6 uhitm.c $NHDT-Date: 1555720104 2019/04/20 00:28:24 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.207 $ */ 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. 8. STATIC_DCL boolean FDECL(known_hitum, (struct monst *, struct obj *, int *, 9. int, int, struct attack *, int)); 10. STATIC_DCL boolean FDECL(theft_petrifies, (struct obj *)); 11. STATIC_DCL void FDECL(steal_it, (struct monst *, struct attack *)); 12. STATIC_DCL boolean FDECL(hitum_cleave, (struct monst *, struct attack *)); 13. STATIC_DCL boolean FDECL(hitum, (struct monst *, struct attack *)); 14. STATIC_DCL boolean FDECL(hmon_hitmon, (struct monst *, struct obj *, int, 15. int)); 16. STATIC_DCL int FDECL(joust, (struct monst *, struct obj *)); 17. STATIC_DCL void NDECL(demonpet); 18. STATIC_DCL boolean FDECL(m_slips_free, (struct monst *, struct attack *)); 19. STATIC_DCL int FDECL(explum, (struct monst *, struct attack *)); 20. STATIC_DCL void FDECL(start_engulf, (struct monst *)); 21. STATIC_DCL void NDECL(end_engulf); 22. STATIC_DCL int FDECL(gulpum, (struct monst *, struct attack *)); 23. STATIC_DCL boolean FDECL(hmonas, (struct monst *)); 24. STATIC_DCL void FDECL(nohandglow, (struct monst *)); 25. STATIC_DCL boolean FDECL(shade_aware, (struct obj *)); 26. 27. extern boolean notonhead; /* for long worms */ 28. 29. /* Used to flag attacks caused by Stormbringer's maliciousness. */ 30. static boolean override_confirmation = FALSE; 31. 32. #define PROJECTILE(obj) ((obj) && is_ammo(obj)) 33. 34. void 35. erode_armor(mdef, hurt) 36. struct monst *mdef; 37. int hurt; 38. { 39. struct obj *target; 40. 41. /* What the following code does: it keeps looping until it 42. * finds a target for the rust monster. 43. * Head, feet, etc... not covered by metal, or covered by 44. * rusty metal, are not targets. However, your body always 45. * is, no matter what covers it. 46. */ 47. while (1) { 48. switch (rn2(5)) { 49. case 0: 50. target = which_armor(mdef, W_ARMH); 51. if (!target 52. || erode_obj(target, xname(target), hurt, EF_GREASE) 53. == ER_NOTHING) 54. continue; 55. break; 56. case 1: 57. target = which_armor(mdef, W_ARMC); 58. if (target) { 59. (void) erode_obj(target, xname(target), hurt, 60. EF_GREASE | EF_VERBOSE); 61. break; 62. } 63. if ((target = which_armor(mdef, W_ARM)) != (struct obj *) 0) { 64. (void) erode_obj(target, xname(target), hurt, 65. EF_GREASE | EF_VERBOSE); 66. } else if ((target = which_armor(mdef, W_ARMU)) 67. != (struct obj *) 0) { 68. (void) erode_obj(target, xname(target), hurt, 69. EF_GREASE | EF_VERBOSE); 70. } 71. break; 72. case 2: 73. target = which_armor(mdef, W_ARMS); 74. if (!target 75. || erode_obj(target, xname(target), hurt, EF_GREASE) 76. == ER_NOTHING) 77. continue; 78. break; 79. case 3: 80. target = which_armor(mdef, W_ARMG); 81. if (!target 82. || erode_obj(target, xname(target), hurt, EF_GREASE) 83. == ER_NOTHING) 84. continue; 85. break; 86. case 4: 87. target = which_armor(mdef, W_ARMF); 88. if (!target 89. || erode_obj(target, xname(target), hurt, EF_GREASE) 90. == ER_NOTHING) 91. continue; 92. break; 93. } 94. break; /* Out of while loop */ 95. } 96. } 97. 98. /* FALSE means it's OK to attack */ 99. boolean 100. attack_checks(mtmp, wep) 101. register struct monst *mtmp; 102. struct obj *wep; /* uwep for attack(), null for kick_monster() */ 103. { 104. int glyph; 105. 106. /* if you're close enough to attack, alert any waiting monster */ 107. mtmp->mstrategy &= ~STRAT_WAITMASK; 108. 109. if (u.uswallow && mtmp == u.ustuck) 110. return FALSE; 111. 112. if (context.forcefight) { 113. /* Do this in the caller, after we checked that the monster 114. * didn't die from the blow. Reason: putting the 'I' there 115. * causes the hero to forget the square's contents since 116. * both 'I' and remembered contents are stored in .glyph. 117. * If the monster dies immediately from the blow, the 'I' will 118. * not stay there, so the player will have suddenly forgotten 119. * the square's contents for no apparent reason. 120. if (!canspotmon(mtmp) 121. && !glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) 122. map_invisible(bhitpos.x, bhitpos.y); 123. */ 124. return FALSE; 125. } 126. 127. /* cache the shown glyph; 128. cases which might change it (by placing or removing 129. 'rembered, unseen monster' glyph or revealing a mimic) 130. always return without further reference to this */ 131. glyph = glyph_at(bhitpos.x, bhitpos.y); 132. 133. /* Put up an invisible monster marker, but with exceptions for 134. * monsters that hide and monsters you've been warned about. 135. * The former already prints a warning message and 136. * prevents you from hitting the monster just via the hidden monster 137. * code below; if we also did that here, similar behavior would be 138. * happening two turns in a row. The latter shows a glyph on 139. * the screen, so you know something is there. 140. */ 141. if (!canspotmon(mtmp) 142. && !glyph_is_warning(glyph) && !glyph_is_invisible(glyph) 143. && !(!Blind && mtmp->mundetected && hides_under(mtmp->data))) { 144. pline("Wait! There's %s there you can't see!", something); 145. map_invisible(bhitpos.x, bhitpos.y); 146. /* if it was an invisible mimic, treat it as if we stumbled 147. * onto a visible mimic 148. */ 149. if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers 150. /* applied pole-arm attack is too far to get stuck */ 151. && distu(mtmp->mx, mtmp->my) <= 2) { 152. if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)) 153. u.ustuck = mtmp; 154. } 155. /* #H7329 - if hero is on engraved "Elbereth", this will end up 156. * assessing an alignment penalty and removing the engraving 157. * even though no attack actually occurs. Since it also angers 158. * peacefuls, we're operating as if an attack attempt did occur 159. * and the Elbereth behavior is consistent. 160. */ 161. wakeup(mtmp, TRUE); /* always necessary; also un-mimics mimics */ 162. return TRUE; 163. } 164. 165. if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers && !sensemon(mtmp) 166. && !glyph_is_warning(glyph)) { 167. /* If a hidden mimic was in a square where a player remembers 168. * some (probably different) unseen monster, the player is in 169. * luck--he attacks it even though it's hidden. 170. */ 171. if (glyph_is_invisible(glyph)) { 172. seemimic(mtmp); 173. return FALSE; 174. } 175. stumble_onto_mimic(mtmp); 176. return TRUE; 177. } 178. 179. if (mtmp->mundetected && !canseemon(mtmp) 180. && !glyph_is_warning(glyph) 181. && (hides_under(mtmp->data) || mtmp->data->mlet == S_EEL)) { 182. mtmp->mundetected = mtmp->msleeping = 0; 183. newsym(mtmp->mx, mtmp->my); 184. if (glyph_is_invisible(glyph)) { 185. seemimic(mtmp); 186. return FALSE; 187. } 188. if (!((Blind ? Blind_telepat : Unblind_telepat) || Detect_monsters)) { 189. struct obj *obj; 190. 191. if (!Blind && Hallucination) 192. pline("A %s %s appeared!", 193. mtmp->mtame ? "tame" : "wild", l_monnam(mtmp)); 194. else if (Blind || (is_pool(mtmp->mx, mtmp->my) && !Underwater)) 195. pline("Wait! There's a hidden monster there!"); 196. else if ((obj = level.objects[mtmp->mx][mtmp->my]) != 0) 197. pline("Wait! There's %s hiding under %s!", 198. an(l_monnam(mtmp)), doname(obj)); 199. return TRUE; 200. } 201. } 202. 203. /* 204. * make sure to wake up a monster from the above cases if the 205. * hero can sense that the monster is there. 206. */ 207. if ((mtmp->mundetected || M_AP_TYPE(mtmp)) && sensemon(mtmp)) { 208. mtmp->mundetected = 0; 209. wakeup(mtmp, TRUE); 210. } 211. 212. if (flags.confirm && mtmp->mpeaceful 213. && !Confusion && !Hallucination && !Stunned) { 214. /* Intelligent chaotic weapons (Stormbringer) want blood */ 215. if (wep && wep->oartifact == ART_STORMBRINGER) { 216. override_confirmation = TRUE; 217. return FALSE; 218. } 219. if (canspotmon(mtmp)) { 220. char qbuf[QBUFSZ]; 221. 222. Sprintf(qbuf, "Really attack %s?", mon_nam(mtmp)); 223. if (!paranoid_query(ParanoidHit, qbuf)) { 224. context.move = 0; 225. return TRUE; 226. } 227. } 228. } 229. 230. return FALSE; 231. } 232. 233. /* 234. * It is unchivalrous for a knight to attack the defenseless or from behind. 235. */ 236. void 237. check_caitiff(mtmp) 238. struct monst *mtmp; 239. { 240. if (u.ualign.record <= -10) 241. return; 242. 243. if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL 244. && (!mtmp->mcanmove || mtmp->msleeping 245. || (mtmp->mflee && !mtmp->mavenge))) { 246. You("caitiff!"); 247. adjalign(-1); 248. } else if (Role_if(PM_SAMURAI) && mtmp->mpeaceful) { 249. /* attacking peaceful creatures is bad for the samurai's giri */ 250. You("dishonorably attack the innocent!"); 251. adjalign(-1); 252. } 253. } 254. 255. int 256. find_roll_to_hit(mtmp, aatyp, weapon, attk_count, role_roll_penalty) 257. register struct monst *mtmp; 258. uchar aatyp; /* usually AT_WEAP or AT_KICK */ 259. struct obj *weapon; /* uwep or uswapwep or NULL */ 260. int *attk_count, *role_roll_penalty; 261. { 262. int tmp, tmp2; 263. 264. *role_roll_penalty = 0; /* default is `none' */ 265. 266. tmp = 1 + Luck + abon() + find_mac(mtmp) + u.uhitinc 267. + maybe_polyd(youmonst.data->mlevel, u.ulevel); 268. 269. /* some actions should occur only once during multiple attacks */ 270. if (!(*attk_count)++) { 271. /* knight's chivalry or samurai's giri */ 272. check_caitiff(mtmp); 273. } 274. 275. /* adjust vs. (and possibly modify) monster state */ 276. if (mtmp->mstun) 277. tmp += 2; 278. if (mtmp->mflee) 279. tmp += 2; 280. 281. if (mtmp->msleeping) { 282. mtmp->msleeping = 0; 283. tmp += 2; 284. } 285. if (!mtmp->mcanmove) { 286. tmp += 4; 287. if (!rn2(10)) { 288. mtmp->mcanmove = 1; 289. mtmp->mfrozen = 0; 290. } 291. } 292. 293. /* role/race adjustments */ 294. if (Role_if(PM_MONK) && !Upolyd) { 295. if (uarm) 296. tmp -= (*role_roll_penalty = urole.spelarmr); 297. else if (!uwep && !uarms) 298. tmp += (u.ulevel / 3) + 2; 299. } 300. if (is_orc(mtmp->data) 301. && maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF))) 302. tmp++; 303. 304. /* encumbrance: with a lot of luggage, your agility diminishes */ 305. if ((tmp2 = near_capacity()) != 0) 306. tmp -= (tmp2 * 2) - 1; 307. if (u.utrap) 308. tmp -= 3; 309. 310. /* 311. * hitval applies if making a weapon attack while wielding a weapon; 312. * weapon_hit_bonus applies if doing a weapon attack even bare-handed 313. * or if kicking as martial artist 314. */ 315. if (aatyp == AT_WEAP || aatyp == AT_CLAW) { 316. if (weapon) 317. tmp += hitval(weapon, mtmp); 318. tmp += weapon_hit_bonus(weapon); 319. } else if (aatyp == AT_KICK && martial_bonus()) { 320. tmp += weapon_hit_bonus((struct obj *) 0); 321. } 322. 323. return tmp; 324. } 325. 326. /* try to attack; return False if monster evaded; 327. u.dx and u.dy must be set */ 328. boolean 329. attack(mtmp) 330. register struct monst *mtmp; 331. { 332. register struct permonst *mdat = mtmp->data; 333. 334. /* This section of code provides protection against accidentally 335. * hitting peaceful (like '@') and tame (like 'd') monsters. 336. * Protection is provided as long as player is not: blind, confused, 337. * hallucinating or stunned. 338. * changes by wwp 5/16/85 339. * More changes 12/90, -dkh-. if its tame and safepet, (and protected 340. * 07/92) then we assume that you're not trying to attack. Instead, 341. * you'll usually just swap places if this is a movement command 342. */ 343. /* Intelligent chaotic weapons (Stormbringer) want blood */ 344. if (is_safepet(mtmp) && !context.forcefight) { 345. if (!uwep || uwep->oartifact != ART_STORMBRINGER) { 346. /* There are some additional considerations: this won't work 347. * if in a shop or Punished or you miss a random roll or 348. * if you can walk thru walls and your pet cannot (KAA) or 349. * if your pet is a long worm with a tail. 350. * There's also a chance of displacing a "frozen" monster: 351. * sleeping monsters might magically walk in their sleep. 352. */ 353. boolean foo = (Punished || !rn2(7) 354. || (is_longworm(mtmp->data) && mtmp->wormno)), 355. inshop = FALSE; 356. char *p; 357. 358. /* only check for in-shop if don't already have reason to stop */ 359. if (!foo) { 360. for (p = in_rooms(mtmp->mx, mtmp->my, SHOPBASE); *p; p++) 361. if (tended_shop(&rooms[*p - ROOMOFFSET])) { 362. inshop = TRUE; 363. break; 364. } 365. } 366. if (inshop || foo || (IS_ROCK(levl[u.ux][u.uy].typ) 367. && !passes_walls(mtmp->data))) { 368. char buf[BUFSZ]; 369. 370. monflee(mtmp, rnd(6), FALSE, FALSE); 371. Strcpy(buf, y_monnam(mtmp)); 372. buf[0] = highc(buf[0]); 373. You("stop. %s is in the way!", buf); 374. context.travel = context.travel1 = context.mv = context.run 375. = 0; 376. return TRUE; 377. } else if ((mtmp->mfrozen || (!mtmp->mcanmove) 378. || (mtmp->data->mmove == 0)) && rn2(6)) { 379. pline("%s doesn't seem to move!", Monnam(mtmp)); 380. context.travel = context.travel1 = context.mv = context.run 381. = 0; 382. return TRUE; 383. } else 384. return FALSE; 385. } 386. } 387. 388. /* possibly set in attack_checks; 389. examined in known_hitum, called via hitum or hmonas below */ 390. override_confirmation = FALSE; 391. /* attack_checks() used to use <u.ux+u.dx,u.uy+u.dy> directly, now 392. it uses bhitpos instead; it might map an invisible monster there */ 393. bhitpos.x = u.ux + u.dx; 394. bhitpos.y = u.uy + u.dy; 395. notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); 396. if (attack_checks(mtmp, uwep)) 397. return TRUE; 398. 399. if (Upolyd && noattacks(youmonst.data)) { 400. /* certain "pacifist" monsters don't attack */ 401. You("have no way to attack monsters physically."); 402. mtmp->mstrategy &= ~STRAT_WAITMASK; 403. goto atk_done; 404. } 405. 406. if (check_capacity("You cannot fight while so heavily loaded.") 407. /* consume extra nutrition during combat; maybe pass out */ 408. || overexertion()) 409. goto atk_done; 410. 411. if (u.twoweap && !can_twoweapon()) 412. untwoweapon(); 413. 414. if (unweapon) { 415. unweapon = FALSE; 416. if (flags.verbose) { 417. if (uwep) 418. You("begin bashing monsters with %s.", yname(uwep)); 419. else if (!cantwield(youmonst.data)) 420. You("begin %s monsters with your %s %s.", 421. ing_suffix(Role_if(PM_MONK) ? "strike" : "bash"), 422. uarmg ? "gloved" : "bare", /* Del Lamb */ 423. makeplural(body_part(HAND))); 424. } 425. } 426. exercise(A_STR, TRUE); /* you're exercising muscles */ 427. /* andrew@orca: prevent unlimited pick-axe attacks */ 428. u_wipe_engr(3); 429. 430. /* Is the "it died" check actually correct? */ 431. if (mdat->mlet == S_LEPRECHAUN && !mtmp->mfrozen && !mtmp->msleeping 432. && !mtmp->mconf && mtmp->mcansee && !rn2(7) 433. && (m_move(mtmp, 0) == 2 /* it died */ 434. || mtmp->mx != u.ux + u.dx 435. || mtmp->my != u.uy + u.dy)) { /* it moved */ 436. You("miss wildly and stumble forwards."); 437. return FALSE; 438. } 439. 440. if (Upolyd) 441. (void) hmonas(mtmp); 442. else 443. (void) hitum(mtmp, youmonst.data->mattk); 444. mtmp->mstrategy &= ~STRAT_WAITMASK; 445. 446. atk_done: 447. /* see comment in attack_checks() */ 448. /* we only need to check for this if we did an attack_checks() 449. * and it returned 0 (it's okay to attack), and the monster didn't 450. * evade. 451. */ 452. if (context.forcefight && !DEADMONSTER(mtmp) && !canspotmon(mtmp) 453. && !glyph_is_invisible(levl[u.ux + u.dx][u.uy + u.dy].glyph) 454. && !(u.uswallow && mtmp == u.ustuck)) 455. map_invisible(u.ux + u.dx, u.uy + u.dy); 456. 457. return TRUE; 458. } 459. 460. /* really hit target monster; returns TRUE if it still lives */ 461. STATIC_OVL boolean 462. known_hitum(mon, weapon, mhit, rollneeded, armorpenalty, uattk, dieroll) 463. register struct monst *mon; 464. struct obj *weapon; 465. int *mhit; 466. int rollneeded, armorpenalty; /* for monks */ 467. struct attack *uattk; 468. int dieroll; 469. { 470. boolean malive = TRUE, 471. /* hmon() might destroy weapon; remember aspect for cutworm */ 472. slice_or_chop = (weapon && (is_blade(weapon) || is_axe(weapon))); 473. 474. if (override_confirmation) { 475. /* this may need to be generalized if weapons other than 476. Stormbringer acquire similar anti-social behavior... */ 477. if (flags.verbose) 478. Your("bloodthirsty blade attacks!"); 479. } 480. 481. if (!*mhit) { 482. missum(mon, uattk, (rollneeded + armorpenalty > dieroll)); 483. } else { 484. int oldhp = mon->mhp; 485. long oldweaphit = u.uconduct.weaphit; 486. 487. /* KMH, conduct */ 488. if (weapon && (weapon->oclass == WEAPON_CLASS || is_weptool(weapon))) 489. u.uconduct.weaphit++; 490. 491. /* we hit the monster; be careful: it might die or 492. be knocked into a different location */ 493. notonhead = (mon->mx != bhitpos.x || mon->my != bhitpos.y); 494. malive = hmon(mon, weapon, HMON_MELEE, dieroll); 495. if (malive) { 496. /* monster still alive */ 497. if (!rn2(25) && mon->mhp < mon->mhpmax / 2 498. && !(u.uswallow && mon == u.ustuck)) { 499. /* maybe should regurgitate if swallowed? */ 500. monflee(mon, !rn2(3) ? rnd(100) : 0, FALSE, TRUE); 501. 502. if (u.ustuck == mon && !u.uswallow && !sticks(youmonst.data)) 503. u.ustuck = 0; 504. } 505. /* Vorpal Blade hit converted to miss */ 506. /* could be headless monster or worm tail */ 507. if (mon->mhp == oldhp) { 508. *mhit = 0; 509. /* a miss does not break conduct */ 510. u.uconduct.weaphit = oldweaphit; 511. } 512. if (mon->wormno && *mhit) 513. cutworm(mon, bhitpos.x, bhitpos.y, slice_or_chop); 514. } 515. } 516. return malive; 517. } 518. 519. /* hit the monster next to you and the monsters to the left and right of it; 520. return False if the primary target is killed, True otherwise */ 521. STATIC_OVL boolean 522. hitum_cleave(target, uattk) 523. struct monst *target; /* non-Null; forcefight at nothing doesn't cleave... */ 524. struct attack *uattk; /* ... but we don't enforce that here; Null works ok */ 525. { 526. /* swings will be delivered in alternate directions; with consecutive 527. attacks it will simulate normal swing and backswing; when swings 528. are non-consecutive, hero will sometimes start a series of attacks 529. with a backswing--that doesn't impact actual play, just spoils the 530. simulation attempt a bit */ 531. static boolean clockwise = FALSE; 532. unsigned i; 533. coord save_bhitpos; 534. int count, umort, x = u.ux, y = u.uy; 535. 536. /* find the direction toward primary target */ 537. for (i = 0; i < 8; ++i) 538. if (xdir[i] == u.dx && ydir[i] == u.dy) 539. break; 540. if (i == 8) { 541. impossible("hitum_cleave: unknown target direction [%d,%d,%d]?", 542. u.dx, u.dy, u.dz); 543. return TRUE; /* target hasn't been killed */ 544. } 545. /* adjust direction by two so that loop's increment (for clockwise) 546. or decrement (for counter-clockwise) will point at the spot next 547. to primary target */ 548. i = (i + (clockwise ? 6 : 2)) % 8; 549. umort = u.umortality; /* used to detect life-saving */ 550. save_bhitpos = bhitpos; 551. 552. /* 553. * Three attacks: adjacent to primary, primary, adjacent on other 554. * side. Primary target must be present or we wouldn't have gotten 555. * here (forcefight at thin air won't 'cleave'). However, the 556. * first attack might kill it (gas spore explosion, weak long worm 557. * occupying both spots) so we don't assume that it's still present 558. * on the second attack. 559. */ 560. for (count = 3; count > 0; --count) { 561. struct monst *mtmp; 562. int tx, ty, tmp, dieroll, mhit, attknum, armorpenalty; 563. 564. /* ++i, wrap 8 to i=0 /or/ --i, wrap -1 to i=7 */ 565. i = (i + (clockwise ? 1 : 7)) % 8; 566. 567. tx = x + xdir[i], ty = y + ydir[i]; /* current target location */ 568. if (!isok(tx, ty)) 569. continue; 570. mtmp = m_at(tx, ty); 571. if (!mtmp) { 572. if (glyph_is_invisible(levl[tx][ty].glyph)) 573. (void) unmap_invisible(tx, ty); 574. continue; 575. } 576. 577. tmp = find_roll_to_hit(mtmp, uattk->aatyp, uwep, 578. &attknum, &armorpenalty); 579. dieroll = rnd(20); 580. mhit = (tmp > dieroll); 581. bhitpos.x = tx, bhitpos.y = ty; /* normally set up by attack() */ 582. (void) known_hitum(mtmp, uwep, &mhit, tmp, armorpenalty, 583. uattk, dieroll); 584. (void) passive(mtmp, uwep, mhit, !DEADMONSTER(mtmp), AT_WEAP, !uwep); 585. 586. /* stop attacking if weapon is gone or hero got killed and 587. life-saved after passive counter-attack */ 588. if (!uwep || u.umortality > umort) 589. break; 590. } 591. /* set up for next time */ 592. clockwise = !clockwise; /* alternate */ 593. bhitpos = save_bhitpos; /* in case somebody relies on bhitpos 594. * designating the primary target */ 595. 596. /* return False if primary target died, True otherwise; note: if 'target' 597. was nonNull upon entry then it's still nonNull even if *target died */ 598. return (target && DEADMONSTER(target)) ? FALSE : TRUE; 599. } 600. 601. /* hit target monster; returns TRUE if it still lives */ 602. STATIC_OVL boolean 603. hitum(mon, uattk) 604. struct monst *mon; 605. struct attack *uattk; 606. { 607. boolean malive, wep_was_destroyed = FALSE; 608. struct obj *wepbefore = uwep; 609. int armorpenalty, attknum = 0, x = u.ux + u.dx, y = u.uy + u.dy, 610. tmp = find_roll_to_hit(mon, uattk->aatyp, uwep, 611. &attknum, &armorpenalty); 612. int dieroll = rnd(20); 613. int mhit = (tmp > dieroll || u.uswallow); 614. 615. /* Cleaver attacks three spots, 'mon' and one on either side of 'mon'; 616. it can't be part of dual-wielding but we guard against that anyway; 617. cleave return value reflects status of primary target ('mon') */ 618. if (uwep && uwep->oartifact == ART_CLEAVER && !u.twoweap 619. && !u.uswallow && !u.ustuck && !NODIAG(u.umonnum)) 620. return hitum_cleave(mon, uattk); 621. 622. if (tmp > dieroll) 623. exercise(A_DEX, TRUE); 624. /* bhitpos is set up by caller */ 625. malive = known_hitum(mon, uwep, &mhit, tmp, armorpenalty, uattk, dieroll); 626. if (wepbefore && !uwep) 627. wep_was_destroyed = TRUE; 628. (void) passive(mon, uwep, mhit, malive, AT_WEAP, wep_was_destroyed); 629. 630. /* second attack for two-weapon combat; won't occur if Stormbringer 631. overrode confirmation (assumes Stormbringer is primary weapon) 632. or if the monster was killed or knocked to different location */ 633. if (u.twoweap && !override_confirmation && malive && m_at(x, y) == mon) { 634. tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, &attknum, 635. &armorpenalty); 636. dieroll = rnd(20); 637. mhit = (tmp > dieroll || u.uswallow); 638. malive = known_hitum(mon, uswapwep, &mhit, tmp, armorpenalty, uattk, 639. dieroll); 640. /* second passive counter-attack only occurs if second attack hits */ 641. if (mhit) 642. (void) passive(mon, uswapwep, mhit, malive, AT_WEAP, !uswapwep); 643. } 644. return malive; 645. } 646. 647. /* general "damage monster" routine; return True if mon still alive */ 648. boolean 649. hmon(mon, obj, thrown, dieroll) 650. struct monst *mon; 651. struct obj *obj; 652. int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */ 653. int dieroll; 654. { 655. boolean result, anger_guards; 656. 657. anger_guards = (mon->mpeaceful 658. && (mon->ispriest || mon->isshk || is_watch(mon->data))); 659. result = hmon_hitmon(mon, obj, thrown, dieroll); 660. if (mon->ispriest && !rn2(2)) 661. ghod_hitsu(mon); 662. if (anger_guards) 663. (void) angry_guards(!!Deaf); 664. return result; 665. } 666. 667. /* guts of hmon() */ 668. STATIC_OVL boolean 669. hmon_hitmon(mon, obj, thrown, dieroll) 670. struct monst *mon; 671. struct obj *obj; 672. int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */ 673. int dieroll; 674. { 675. int tmp; 676. struct permonst *mdat = mon->data; 677. int barehand_silver_rings = 0; 678. /* The basic reason we need all these booleans is that we don't want 679. * a "hit" message when a monster dies, so we have to know how much 680. * damage it did _before_ outputting a hit message, but any messages 681. * associated with the damage don't come out until _after_ outputting 682. * a hit message. 683. */ 684. boolean hittxt = FALSE, destroyed = FALSE, already_killed = FALSE; 685. boolean get_dmg_bonus = TRUE; 686. boolean ispoisoned = FALSE, needpoismsg = FALSE, poiskilled = FALSE, 687. unpoisonmsg = FALSE; 688. boolean silvermsg = FALSE, silverobj = FALSE; 689. boolean lightobj = FALSE; 690. boolean valid_weapon_attack = FALSE; 691. boolean unarmed = !uwep && !uarm && !uarms; 692. boolean hand_to_hand = (thrown == HMON_MELEE 693. /* not grapnels; applied implies uwep */ 694. || (thrown == HMON_APPLIED && is_pole(uwep))); 695. int jousting = 0; 696. long silverhit = 0L; 697. int wtype; 698. struct obj *monwep; 699. char unconventional[BUFSZ]; /* substituted for word "attack" in msg */ 700. char saved_oname[BUFSZ]; 701. 702. unconventional[0] = '\0'; 703. saved_oname[0] = '\0'; 704. 705. wakeup(mon, TRUE); 706. if (!obj) { /* attack with bare hands */ 707. if (mdat == &mons[PM_SHADE]) 708. tmp = 0; 709. else if (martial_bonus()) 710. tmp = rnd(4); /* bonus for martial arts */ 711. else 712. tmp = rnd(2); 713. valid_weapon_attack = (tmp > 1); 714. /* Blessed gloves give bonuses when fighting 'bare-handed'. So do 715. silver rings. Note: rings are worn under gloves, so you don't 716. get both bonuses, and two silver rings don't give double bonus. */ 717. tmp += special_dmgval(&youmonst, mon, (W_ARMG | W_RINGL | W_RINGR), 718. &silverhit); 719. barehand_silver_rings += (((silverhit & W_RINGL) ? 1 : 0) 720. + ((silverhit & W_RINGR) ? 1 : 0)); 721. if (barehand_silver_rings > 0) 722. silvermsg = TRUE; 723. } else { 724. if (!(artifact_light(obj) && obj->lamplit)) 725. Strcpy(saved_oname, cxname(obj)); 726. else 727. Strcpy(saved_oname, bare_artifactname(obj)); 728. if (obj->oclass == WEAPON_CLASS || is_weptool(obj) 729. || obj->oclass == GEM_CLASS) { 730. /* is it not a melee weapon? */ 731. if (/* if you strike with a bow... */ 732. is_launcher(obj) 733. /* or strike with a missile in your hand... */ 734. || (!thrown && (is_missile(obj) || is_ammo(obj))) 735. /* or use a pole at short range and not mounted... */ 736. || (!thrown && !u.usteed && is_pole(obj)) 737. /* or throw a missile without the proper bow... */ 738. || (is_ammo(obj) && (thrown != HMON_THROWN 739. || !ammo_and_launcher(obj, uwep)))) { 740. /* then do only 1-2 points of damage */ 741. if (mdat == &mons[PM_SHADE] && !shade_glare(obj)) 742. tmp = 0; 743. else 744. tmp = rnd(2); 745. if (objects[obj->otyp].oc_material == SILVER 746. && mon_hates_silver(mon)) { 747. silvermsg = TRUE; 748. silverobj = TRUE; 749. /* if it will already inflict dmg, make it worse */ 750. tmp += rnd((tmp) ? 20 : 10); 751. } 752. if (!thrown && obj == uwep && obj->otyp == BOOMERANG 753. && rnl(4) == 4 - 1) { 754. boolean more_than_1 = (obj->quan > 1L); 755. 756. pline("As you hit %s, %s%s breaks into splinters.", 757. mon_nam(mon), more_than_1 ? "one of " : "", 758. yname(obj)); 759. if (!more_than_1) 760. uwepgone(); /* set unweapon */ 761. useup(obj); 762. if (!more_than_1) 763. obj = (struct obj *) 0; 764. hittxt = TRUE; 765. if (mdat != &mons[PM_SHADE]) 766. tmp++; 767. } 768. } else { 769. tmp = dmgval(obj, mon); 770. /* a minimal hit doesn't exercise proficiency */ 771. valid_weapon_attack = (tmp > 1); 772. if (!valid_weapon_attack || mon == u.ustuck || u.twoweap 773. /* Cleaver can hit up to three targets at once so don't 774. let it also hit from behind or shatter foes' weapons */ 775. || (hand_to_hand && obj->oartifact == ART_CLEAVER)) { 776. ; /* no special bonuses */ 777. } else if (mon->mflee && Role_if(PM_ROGUE) && !Upolyd 778. /* multi-shot throwing is too powerful here */ 779. && hand_to_hand) { 780. You("strike %s from behind!", mon_nam(mon)); 781. tmp += rnd(u.ulevel); 782. hittxt = TRUE; 783. } else if (dieroll == 2 && obj == uwep 784. && obj->oclass == WEAPON_CLASS 785. && (bimanual(obj) 786. || (Role_if(PM_SAMURAI) && obj->otyp == KATANA 787. && !uarms)) 788. && ((wtype = uwep_skill_type()) != P_NONE 789. && P_SKILL(wtype) >= P_SKILLED) 790. && ((monwep = MON_WEP(mon)) != 0 791. && !is_flimsy(monwep) 792. && !obj_resists(monwep, 793. 50 + 15 * (greatest_erosion(obj) 794. - greatest_erosion(monwep)), 795. 100))) { 796. /* 797. * 2.5% chance of shattering defender's weapon when 798. * using a two-handed weapon; less if uwep is rusted. 799. * [dieroll == 2 is most successful non-beheading or 800. * -bisecting hit, in case of special artifact damage; 801. * the percentage chance is (1/20)*(50/100).] 802. * If attacker's weapon is rustier than defender's, 803. * the obj_resists chance is increased so the shatter 804. * chance is decreased; if less rusty, then vice versa. 805. */ 806. setmnotwielded(mon, monwep); 807. mon->weapon_check = NEED_WEAPON; 808. pline("%s from the force of your blow!", 809. Yobjnam2(monwep, "shatter")); 810. m_useupall(mon, monwep); 811. /* If someone just shattered MY weapon, I'd flee! */ 812. if (rn2(4)) { 813. monflee(mon, d(2, 3), TRUE, TRUE); 814. } 815. hittxt = TRUE; 816. } 817. 818. if (obj->oartifact 819. && artifact_hit(&youmonst, mon, obj, &tmp, dieroll)) { 820. if (DEADMONSTER(mon)) /* artifact killed monster */ 821. return FALSE; 822. if (tmp == 0) 823. return TRUE; 824. hittxt = TRUE; 825. } 826. if (objects[obj->otyp].oc_material == SILVER 827. && mon_hates_silver(mon)) { 828. silvermsg = TRUE; 829. silverobj = TRUE; 830. } 831. if (artifact_light(obj) && obj->lamplit 832. && mon_hates_light(mon)) 833. lightobj = TRUE; 834. if (u.usteed && !thrown && tmp > 0 835. && weapon_type(obj) == P_LANCE && mon != u.ustuck) { 836. jousting = joust(mon, obj); 837. /* exercise skill even for minimal damage hits */ 838. if (jousting) 839. valid_weapon_attack = TRUE; 840. } 841. if (thrown == HMON_THROWN 842. && (is_ammo(obj) || is_missile(obj))) { 843. if (ammo_and_launcher(obj, uwep)) { 844. /* Elves and Samurai do extra damage using 845. * their bows&arrows; they're highly trained. 846. */ 847. if (Role_if(PM_SAMURAI) && obj->otyp == YA 848. && uwep->otyp == YUMI) 849. tmp++; 850. else if (Race_if(PM_ELF) && obj->otyp == ELVEN_ARROW 851. && uwep->otyp == ELVEN_BOW) 852. tmp++; 853. } 854. if (obj->opoisoned && is_poisonable(obj)) 855. ispoisoned = TRUE; 856. } 857. } 858. } else if (obj->oclass == POTION_CLASS) { 859. if (obj->quan > 1L) 860. obj = splitobj(obj, 1L); 861. else 862. setuwep((struct obj *) 0); 863. freeinv(obj); 864. potionhit(mon, obj, 865. hand_to_hand ? POTHIT_HERO_BASH : POTHIT_HERO_THROW); 866. if (DEADMONSTER(mon)) 867. return FALSE; /* killed */ 868. hittxt = TRUE; 869. /* in case potion effect causes transformation */ 870. mdat = mon->data; 871. tmp = (mdat == &mons[PM_SHADE]) ? 0 : 1; 872. } else { 873. if (mdat == &mons[PM_SHADE] && !shade_aware(obj)) { 874. tmp = 0; 875. Strcpy(unconventional, cxname(obj)); 876. } else { 877. switch (obj->otyp) { 878. case BOULDER: /* 1d20 */ 879. case HEAVY_IRON_BALL: /* 1d25 */ 880. case IRON_CHAIN: /* 1d4+1 */ 881. tmp = dmgval(obj, mon); 882. break; 883. case MIRROR: 884. if (breaktest(obj)) { 885. You("break %s. That's bad luck!", ysimple_name(obj)); 886. change_luck(-2); 887. useup(obj); 888. obj = (struct obj *) 0; 889. unarmed = FALSE; /* avoid obj==0 confusion */ 890. get_dmg_bonus = FALSE; 891. hittxt = TRUE; 892. } 893. tmp = 1; 894. break; 895. case EXPENSIVE_CAMERA: 896. You("succeed in destroying %s. Congratulations!", 897. ysimple_name(obj)); 898. release_camera_demon(obj, u.ux, u.uy); 899. useup(obj); 900. return TRUE; 901. case CORPSE: /* fixed by polder@cs.vu.nl */ 902. if (touch_petrifies(&mons[obj->corpsenm])) { 903. tmp = 1; 904. hittxt = TRUE; 905. You("hit %s with %s.", mon_nam(mon), 906. corpse_xname(obj, (const char *) 0, 907. obj->dknown ? CXN_PFX_THE 908. : CXN_ARTICLE)); 909. obj->dknown = 1; 910. if (!munstone(mon, TRUE)) 911. minstapetrify(mon, TRUE); 912. if (resists_ston(mon)) 913. break; 914. /* note: hp may be <= 0 even if munstoned==TRUE */ 915. return (boolean) !DEADMONSTER(mon); 916. #if 0 917. } else if (touch_petrifies(mdat)) { 918. ; /* maybe turn the corpse into a statue? */ 919. #endif 920. } 921. tmp = (obj->corpsenm >= LOW_PM ? mons[obj->corpsenm].msize 922. : 0) + 1; 923. break; 924. 925. #define useup_eggs(o) \ 926. do { \ 927. if (thrown) \ 928. obfree(o, (struct obj *) 0); \ 929. else \ 930. useupall(o); \ 931. o = (struct obj *) 0; \ 932. } while (0) /* now gone */ 933. case EGG: { 934. long cnt = obj->quan; 935. 936. tmp = 1; /* nominal physical damage */ 937. get_dmg_bonus = FALSE; 938. hittxt = TRUE; /* message always given */ 939. /* egg is always either used up or transformed, so next 940. hand-to-hand attack should yield a "bashing" mesg */ 941. if (obj == uwep) 942. unweapon = TRUE; 943. if (obj->spe && obj->corpsenm >= LOW_PM) { 944. if (obj->quan < 5L) 945. change_luck((schar) - (obj->quan)); 946. else 947. change_luck(-5); 948. } 949. 950. if (touch_petrifies(&mons[obj->corpsenm])) { 951. /*learn_egg_type(obj->corpsenm);*/ 952. pline("Splat! You hit %s with %s %s egg%s!", 953. mon_nam(mon), 954. obj->known ? "the" : cnt > 1L ? "some" : "a", 955. obj->known ? mons[obj->corpsenm].mname 956. : "petrifying", 957. plur(cnt)); 958. obj->known = 1; /* (not much point...) */ 959. useup_eggs(obj); 960. if (!munstone(mon, TRUE)) 961. minstapetrify(mon, TRUE); 962. if (resists_ston(mon)) 963. break; 964. return (boolean) (!DEADMONSTER(mon)); 965. } else { /* ordinary egg(s) */ 966. const char *eggp = (obj->corpsenm != NON_PM 967. && obj->known) 968. ? the(mons[obj->corpsenm].mname) 969. : (cnt > 1L) ? "some" : "an"; 970. 971. You("hit %s with %s egg%s.", mon_nam(mon), eggp, 972. plur(cnt)); 973. if (touch_petrifies(mdat) && !stale_egg(obj)) { 974. pline_The("egg%s %s alive any more...", plur(cnt), 975. (cnt == 1L) ? "isn't" : "aren't"); 976. if (obj->timed) 977. obj_stop_timers(obj); 978. obj->otyp = ROCK; 979. obj->oclass = GEM_CLASS; 980. obj->oartifact = 0; 981. obj->spe = 0; 982. obj->known = obj->dknown = obj->bknown = 0; 983. obj->owt = weight(obj); 984. if (thrown) 985. place_object(obj, mon->mx, mon->my); 986. } else { 987. pline("Splat!"); 988. useup_eggs(obj); 989. exercise(A_WIS, FALSE); 990. } 991. } 992. break; 993. #undef useup_eggs 994. } 995. case CLOVE_OF_GARLIC: /* no effect against demons */ 996. if (is_undead(mdat) || is_vampshifter(mon)) { 997. monflee(mon, d(2, 4), FALSE, TRUE); 998. } 999. tmp = 1; 1000. break; 1001. case CREAM_PIE: 1002. case BLINDING_VENOM: 1003. mon->msleeping = 0; 1004. if (can_blnd(&youmonst, mon, 1005. (uchar) ((obj->otyp == BLINDING_VENOM) 1006. ? AT_SPIT 1007. : AT_WEAP), 1008. obj)) { 1009. if (Blind) { 1010. pline(obj->otyp == CREAM_PIE ? "Splat!" 1011. : "Splash!"); 1012. } else if (obj->otyp == BLINDING_VENOM) { 1013. pline_The("venom blinds %s%s!", mon_nam(mon), 1014. mon->mcansee ? "" : " further"); 1015. } else { 1016. char *whom = mon_nam(mon); 1017. char *what = The(xname(obj)); 1018. 1019. if (!thrown && obj->quan > 1L) 1020. what = An(singular(obj, xname)); 1021. /* note: s_suffix returns a modifiable buffer */ 1022. if (haseyes(mdat) 1023. && mdat != &mons[PM_FLOATING_EYE]) 1024. whom = strcat(strcat(s_suffix(whom), " "), 1025. mbodypart(mon, FACE)); 1026. pline("%s %s over %s!", what, 1027. vtense(what, "splash"), whom); 1028. } 1029. setmangry(mon, TRUE); 1030. mon->mcansee = 0; 1031. tmp = rn1(25, 21); 1032. if (((int) mon->mblinded + tmp) > 127) 1033. mon->mblinded = 127; 1034. else 1035. mon->mblinded += tmp; 1036. } else { 1037. pline(obj->otyp == CREAM_PIE ? "Splat!" : "Splash!"); 1038. setmangry(mon, TRUE); 1039. } 1040. if (thrown) 1041. obfree(obj, (struct obj *) 0); 1042. else 1043. useup(obj); 1044. hittxt = TRUE; 1045. get_dmg_bonus = FALSE; 1046. tmp = 0; 1047. break; 1048. case ACID_VENOM: /* thrown (or spit) */ 1049. if (resists_acid(mon)) { 1050. Your("venom hits %s harmlessly.", mon_nam(mon)); 1051. tmp = 0; 1052. } else { 1053. Your("venom burns %s!", mon_nam(mon)); 1054. tmp = dmgval(obj, mon); 1055. } 1056. if (thrown) 1057. obfree(obj, (struct obj *) 0); 1058. else 1059. useup(obj); 1060. hittxt = TRUE; 1061. get_dmg_bonus = FALSE; 1062. break; 1063. default: 1064. /* non-weapons can damage because of their weight */ 1065. /* (but not too much) */ 1066. tmp = obj->owt / 100; 1067. if (is_wet_towel(obj)) { 1068. /* wielded wet towel should probably use whip skill 1069. (but not by setting objects[TOWEL].oc_skill==P_WHIP 1070. because that would turn towel into a weptool) */ 1071. tmp += obj->spe; 1072. if (rn2(obj->spe + 1)) /* usually lose some wetness */ 1073. dry_a_towel(obj, -1, TRUE); 1074. } 1075. if (tmp < 1) 1076. tmp = 1; 1077. else 1078. tmp = rnd(tmp); 1079. if (tmp > 6) 1080. tmp = 6; 1081. /* 1082. * Things like silver wands can arrive here so 1083. * so we need another silver check. 1084. */ 1085. if (objects[obj->otyp].oc_material == SILVER 1086. && mon_hates_silver(mon)) { 1087. tmp += rnd(20); 1088. silvermsg = TRUE; 1089. silverobj = TRUE; 1090. } 1091. } 1092. } 1093. } 1094. } 1095. 1096. /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) 1097. * *OR* if attacking bare-handed!! */ 1098. 1099. if (get_dmg_bonus && tmp > 0) { 1100. tmp += u.udaminc; 1101. /* If you throw using a propellor, you don't get a strength 1102. * bonus but you do get an increase-damage bonus. 1103. */ 1104. if (thrown != HMON_THROWN || !obj || !uwep 1105. || !ammo_and_launcher(obj, uwep)) 1106. tmp += dbon(); 1107. } 1108. 1109. if (valid_weapon_attack) { 1110. struct obj *wep; 1111. 1112. /* to be valid a projectile must have had the correct projector */ 1113. wep = PROJECTILE(obj) ? uwep : obj; 1114. tmp += weapon_dam_bonus(wep); 1115. /* [this assumes that `!thrown' implies wielded...] */ 1116. wtype = thrown ? weapon_type(wep) : uwep_skill_type(); 1117. use_skill(wtype, 1); 1118. } 1119. 1120. if (ispoisoned) { 1121. int nopoison = (10 - (obj->owt / 10)); 1122. 1123. if (nopoison < 2) 1124. nopoison = 2; 1125. if (Role_if(PM_SAMURAI)) { 1126. You("dishonorably use a poisoned weapon!"); 1127. adjalign(-sgn(u.ualign.type)); 1128. } else if (u.ualign.type == A_LAWFUL && u.ualign.record > -10) { 1129. You_feel("like an evil coward for using a poisoned weapon."); 1130. adjalign(-1); 1131. } 1132. if (obj && !rn2(nopoison)) { 1133. /* remove poison now in case obj ends up in a bones file */ 1134. obj->opoisoned = FALSE; 1135. /* defer "obj is no longer poisoned" until after hit message */ 1136. unpoisonmsg = TRUE; 1137. } 1138. if (resists_poison(mon)) 1139. needpoismsg = TRUE; 1140. else if (rn2(10)) 1141. tmp += rnd(6); 1142. else 1143. poiskilled = TRUE; 1144. } 1145. if (tmp < 1) { 1146. /* make sure that negative damage adjustment can't result 1147. in inadvertently boosting the victim's hit points */ 1148. tmp = 0; 1149. if (mdat == &mons[PM_SHADE]) { 1150. if (!hittxt) { 1151. const char *what = *unconventional ? unconventional : "attack"; 1152. 1153. Your("%s %s harmlessly through %s.", what, 1154. vtense(what, "pass"), mon_nam(mon)); 1155. hittxt = TRUE; 1156. } 1157. } else { 1158. if (get_dmg_bonus) 1159. tmp = 1; 1160. } 1161. } 1162. 1163. if (jousting) { 1164. tmp += d(2, (obj == uwep) ? 10 : 2); /* [was in dmgval()] */ 1165. You("joust %s%s", mon_nam(mon), canseemon(mon) ? exclam(tmp) : "."); 1166. if (jousting < 0) { 1167. pline("%s shatters on impact!", Yname2(obj)); 1168. /* (must be either primary or secondary weapon to get here) */ 1169. u.twoweap = FALSE; /* untwoweapon() is too verbose here */ 1170. if (obj == uwep) 1171. uwepgone(); /* set unweapon */ 1172. /* minor side-effect: broken lance won't split puddings */ 1173. useup(obj); 1174. obj = 0; 1175. } 1176. /* avoid migrating a dead monster */ 1177. if (mon->mhp > tmp) { 1178. mhurtle(mon, u.dx, u.dy, 1); 1179. mdat = mon->data; /* in case of a polymorph trap */ 1180. if (DEADMONSTER(mon)) 1181. already_killed = TRUE; 1182. } 1183. hittxt = TRUE; 1184. } else if (unarmed && tmp > 1 && !thrown && !obj && !Upolyd) { 1185. /* VERY small chance of stunning opponent if unarmed. */ 1186. if (rnd(100) < P_SKILL(P_BARE_HANDED_COMBAT) && !bigmonst(mdat) 1187. && !thick_skinned(mdat)) { 1188. if (canspotmon(mon)) 1189. pline("%s %s from your powerful strike!", Monnam(mon), 1190. makeplural(stagger(mon->data, "stagger"))); 1191. /* avoid migrating a dead monster */ 1192. if (mon->mhp > tmp) { 1193. mhurtle(mon, u.dx, u.dy, 1); 1194. mdat = mon->data; /* in case of a polymorph trap */ 1195. if (DEADMONSTER(mon)) 1196. already_killed = TRUE; 1197. } 1198. hittxt = TRUE; 1199. } 1200. } 1201. 1202. if (!already_killed) 1203. mon->mhp -= tmp; 1204. /* adjustments might have made tmp become less than what 1205. a level draining artifact has already done to max HP */ 1206. if (mon->mhp > mon->mhpmax) 1207. mon->mhp = mon->mhpmax; 1208. if (DEADMONSTER(mon)) 1209. destroyed = TRUE; 1210. if (mon->mtame && tmp > 0) { 1211. /* do this even if the pet is being killed (affects revival) */ 1212. abuse_dog(mon); /* reduces tameness */ 1213. /* flee if still alive and still tame; if already suffering from 1214. untimed fleeing, no effect, otherwise increases timed fleeing */ 1215. if (mon->mtame && !destroyed) 1216. monflee(mon, 10 * rnd(tmp), FALSE, FALSE); 1217. } 1218. if ((mdat == &mons[PM_BLACK_PUDDING] || mdat == &mons[PM_BROWN_PUDDING]) 1219. /* pudding is alive and healthy enough to split */ 1220. && mon->mhp > 1 && !mon->mcan 1221. /* iron weapon using melee or polearm hit [3.6.1: metal weapon too; 1222. also allow either or both weapons to cause split when twoweap] */ 1223. && obj && (obj == uwep || (u.twoweap && obj == uswapwep)) 1224. && ((objects[obj->otyp].oc_material == IRON 1225. /* allow scalpel and tsurugi to split puddings */ 1226. || objects[obj->otyp].oc_material == METAL) 1227. /* but not bashing with darts, arrows or ya */ 1228. && !(is_ammo(obj) || is_missile(obj))) 1229. && hand_to_hand) { 1230. struct monst *mclone; 1231. if ((mclone = clone_mon(mon, 0, 0)) != 0) { 1232. char withwhat[BUFSZ]; 1233. 1234. withwhat[0] = '\0'; 1235. if (u.twoweap && flags.verbose) 1236. Sprintf(withwhat, " with %s", yname(obj)); 1237. pline("%s divides as you hit it%s!", Monnam(mon), withwhat); 1238. hittxt = TRUE; 1239. mintrap(mclone); 1240. } 1241. } 1242. 1243. if (!hittxt /*( thrown => obj exists )*/ 1244. && (!destroyed 1245. || (thrown && m_shot.n > 1 && m_shot.o == obj->otyp))) { 1246. if (thrown) 1247. hit(mshot_xname(obj), mon, exclam(tmp)); 1248. else if (!flags.verbose) 1249. You("hit it."); 1250. else 1251. You("%s %s%s", 1252. (obj && (is_shield(obj) || obj->otyp == HEAVY_IRON_BALL)) 1253. ? "bash" : Role_if(PM_BARBARIAN) ? "smite" : "hit", 1254. mon_nam(mon), canseemon(mon) ? exclam(tmp) : "."); 1255. } 1256. 1257. if (silvermsg) { 1258. const char *fmt; 1259. char *whom = mon_nam(mon); 1260. char silverobjbuf[BUFSZ]; 1261. 1262. if (canspotmon(mon)) { 1263. if (barehand_silver_rings == 1) 1264. fmt = "Your silver ring sears %s!"; 1265. else if (barehand_silver_rings == 2) 1266. fmt = "Your silver rings sear %s!"; 1267. else if (silverobj && saved_oname[0]) { 1268. /* guard constructed format string against '%' in 1269. saved_oname[] from xname(via cxname()) */ 1270. Sprintf(silverobjbuf, "Your %s%s %s", 1271. strstri(saved_oname, "silver") ? "" : "silver ", 1272. saved_oname, vtense(saved_oname, "sear")); 1273. (void) strNsubst(silverobjbuf, "%", "%%", 0); 1274. Strcat(silverobjbuf, " %s!"); 1275. fmt = silverobjbuf; 1276. } else 1277. fmt = "The silver sears %s!"; 1278. } else { 1279. *whom = highc(*whom); /* "it" -> "It" */ 1280. fmt = "%s is seared!"; 1281. } 1282. /* note: s_suffix returns a modifiable buffer */ 1283. if (!noncorporeal(mdat) && !amorphous(mdat)) 1284. whom = strcat(s_suffix(whom), " flesh"); 1285. pline(fmt, whom); 1286. } 1287. if (lightobj) { 1288. const char *fmt; 1289. char *whom = mon_nam(mon); 1290. char emitlightobjbuf[BUFSZ]; 1291. 1292. if (canspotmon(mon)) { 1293. if (saved_oname[0]) { 1294. Sprintf(emitlightobjbuf, 1295. "%s radiance penetrates deep into", 1296. s_suffix(saved_oname)); 1297. Strcat(emitlightobjbuf, " %s!"); 1298. fmt = emitlightobjbuf; 1299. } else 1300. fmt = "The light sears %s!"; 1301. } else { 1302. *whom = highc(*whom); /* "it" -> "It" */ 1303. fmt = "%s is seared!"; 1304. } 1305. /* note: s_suffix returns a modifiable buffer */ 1306. if (!noncorporeal(mdat) && !amorphous(mdat)) 1307. whom = strcat(s_suffix(whom), " flesh"); 1308. pline(fmt, whom); 1309. } 1310. /* if a "no longer poisoned" message is coming, it will be last; 1311. obj->opoisoned was cleared above and any message referring to 1312. "poisoned <obj>" has now been given; we want just "<obj>" for 1313. last message, so reformat while obj is still accessible */ 1314. if (unpoisonmsg) 1315. Strcpy(saved_oname, cxname(obj)); 1316. 1317. /* [note: thrown obj might go away during killed()/xkilled() call 1318. (via 'thrownobj'; if swallowed, it gets added to engulfer's 1319. minvent and might merge with a stack that's already there)] */ 1320. 1321. if (needpoismsg) 1322. pline_The("poison doesn't seem to affect %s.", mon_nam(mon)); 1323. if (poiskilled) { 1324. pline_The("poison was deadly..."); 1325. if (!already_killed) 1326. xkilled(mon, XKILL_NOMSG); 1327. destroyed = TRUE; /* return FALSE; */ 1328. } else if (destroyed) { 1329. if (!already_killed) 1330. killed(mon); /* takes care of most messages */ 1331. } else if (u.umconf && hand_to_hand) { 1332. nohandglow(mon); 1333. if (!mon->mconf && !resist(mon, SPBOOK_CLASS, 0, NOTELL)) { 1334. mon->mconf = 1; 1335. if (!mon->mstun && mon->mcanmove && !mon->msleeping 1336. && canseemon(mon)) 1337. pline("%s appears confused.", Monnam(mon)); 1338. } 1339. } 1340. if (unpoisonmsg) 1341. Your("%s %s no longer poisoned.", saved_oname, 1342. vtense(saved_oname, "are")); 1343. 1344. return destroyed ? FALSE : TRUE; 1345. } 1346. 1347. STATIC_OVL boolean 1348. shade_aware(obj) 1349. struct obj *obj; 1350. { 1351. if (!obj) 1352. return FALSE; 1353. /* 1354. * The things in this list either 1355. * 1) affect shades. 1356. * OR 1357. * 2) are dealt with properly by other routines 1358. * when it comes to shades. 1359. */ 1360. if (obj->otyp == BOULDER 1361. || obj->otyp == HEAVY_IRON_BALL 1362. || obj->otyp == IRON_CHAIN /* dmgval handles those first three */ 1363. || obj->otyp == MIRROR /* silver in the reflective surface */ 1364. || obj->otyp == CLOVE_OF_GARLIC /* causes shades to flee */ 1365. || objects[obj->otyp].oc_material == SILVER) 1366. return TRUE; 1367. return FALSE; 1368. } 1369. 1370. /* check whether slippery clothing protects from hug or wrap attack */ 1371. /* [currently assumes that you are the attacker] */ 1372. STATIC_OVL boolean 1373. m_slips_free(mdef, mattk) 1374. struct monst *mdef; 1375. struct attack *mattk; 1376. { 1377. struct obj *obj; 1378. 1379. if (mattk->adtyp == AD_DRIN) { 1380. /* intelligence drain attacks the head */ 1381. obj = which_armor(mdef, W_ARMH); 1382. } else { 1383. /* grabbing attacks the body */ 1384. obj = which_armor(mdef, W_ARMC); /* cloak */ 1385. if (!obj) 1386. obj = which_armor(mdef, W_ARM); /* suit */ 1387. if (!obj) 1388. obj = which_armor(mdef, W_ARMU); /* shirt */ 1389. } 1390. 1391. /* if monster's cloak/armor is greased, your grab slips off; this 1392. protection might fail (33% chance) when the armor is cursed */ 1393. if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK) 1394. && (!obj->cursed || rn2(3))) { 1395. You("%s %s %s %s!", 1396. mattk->adtyp == AD_WRAP ? "slip off of" 1397. : "grab, but cannot hold onto", 1398. s_suffix(mon_nam(mdef)), obj->greased ? "greased" : "slippery", 1399. /* avoid "slippery slippery cloak" 1400. for undiscovered oilskin cloak */ 1401. (obj->greased || objects[obj->otyp].oc_name_known) 1402. ? xname(obj) 1403. : cloak_simple_name(obj)); 1404. 1405. if (obj->greased && !rn2(2)) { 1406. pline_The("grease wears off."); 1407. obj->greased = 0; 1408. } 1409. return TRUE; 1410. } 1411. return FALSE; 1412. } 1413. 1414. /* used when hitting a monster with a lance while mounted; 1415. 1: joust hit; 0: ordinary hit; -1: joust but break lance */ 1416. STATIC_OVL int 1417. joust(mon, obj) 1418. struct monst *mon; /* target */ 1419. struct obj *obj; /* weapon */ 1420. { 1421. int skill_rating, joust_dieroll; 1422. 1423. if (Fumbling || Stunned) 1424. return 0; 1425. /* sanity check; lance must be wielded in order to joust */ 1426. if (obj != uwep && (obj != uswapwep || !u.twoweap)) 1427. return 0; 1428. 1429. /* if using two weapons, use worse of lance and two-weapon skills */ 1430. skill_rating = P_SKILL(weapon_type(obj)); /* lance skill */ 1431. if (u.twoweap && P_SKILL(P_TWO_WEAPON_COMBAT) < skill_rating) 1432. skill_rating = P_SKILL(P_TWO_WEAPON_COMBAT); 1433. if (skill_rating == P_ISRESTRICTED) 1434. skill_rating = P_UNSKILLED; /* 0=>1 */ 1435. 1436. /* odds to joust are expert:80%, skilled:60%, basic:40%, unskilled:20% */ 1437. if ((joust_dieroll = rn2(5)) < skill_rating) { 1438. if (joust_dieroll == 0 && rnl(50) == (50 - 1) && !unsolid(mon->data) 1439. && !obj_resists(obj, 0, 100)) 1440. return -1; /* hit that breaks lance */ 1441. return 1; /* successful joust */ 1442. } 1443. return 0; /* no joust bonus; revert to ordinary attack */ 1444. } 1445. 1446. /* 1447. * Send in a demon pet for the hero. Exercise wisdom. 1448. * 1449. * This function used to be inline to damageum(), but the Metrowerks compiler 1450. * (DR4 and DR4.5) screws up with an internal error 5 "Expression Too 1451. * Complex." 1452. * Pulling it out makes it work. 1453. */ 1454. STATIC_OVL void 1455. demonpet() 1456. { 1457. int i; 1458. struct permonst *pm; 1459. struct monst *dtmp; 1460. 1461. pline("Some hell-p has arrived!"); 1462. i = !rn2(6) ? ndemon(u.ualign.type) : NON_PM; 1463. pm = i != NON_PM ? &mons[i] : youmonst.data; 1464. if ((dtmp = makemon(pm, u.ux, u.uy, NO_MM_FLAGS)) != 0) 1465. (void) tamedog(dtmp, (struct obj *) 0); 1466. exercise(A_WIS, TRUE); 1467. } 1468. 1469. STATIC_OVL boolean 1470. theft_petrifies(otmp) 1471. struct obj *otmp; 1472. { 1473. if (uarmg || otmp->otyp != CORPSE 1474. || !touch_petrifies(&mons[otmp->corpsenm]) || Stone_resistance) 1475. return FALSE; 1476. 1477. #if 0 /* no poly_when_stoned() critter has theft capability */ 1478. if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) { 1479. display_nhwindow(WIN_MESSAGE, FALSE); /* --More-- */ 1480. return TRUE; 1481. } 1482. #endif 1483. 1484. /* stealing this corpse is fatal... */ 1485. instapetrify(corpse_xname(otmp, "stolen", CXN_ARTICLE)); 1486. /* apparently wasn't fatal after all... */ 1487. return TRUE; 1488. } 1489. 1490. /* 1491. * Player uses theft attack against monster. 1492. * 1493. * If the target is wearing body armor, take all of its possessions; 1494. * otherwise, take one object. [Is this really the behavior we want?] 1495. */ 1496. STATIC_OVL void 1497. steal_it(mdef, mattk) 1498. struct monst *mdef; 1499. struct attack *mattk; 1500. { 1501. struct obj *otmp, *stealoid, **minvent_ptr; 1502. long unwornmask; 1503. 1504. if (!mdef->minvent) 1505. return; /* nothing to take */ 1506. 1507. /* look for worn body armor */ 1508. stealoid = (struct obj *) 0; 1509. if (could_seduce(&youmonst, mdef, mattk)) { 1510. /* find armor, and move it to end of inventory in the process */ 1511. minvent_ptr = &mdef->minvent; 1512. while ((otmp = *minvent_ptr) != 0) 1513. if (otmp->owornmask & W_ARM) { 1514. if (stealoid) 1515. panic("steal_it: multiple worn suits"); 1516. *minvent_ptr = otmp->nobj; /* take armor out of minvent */ 1517. stealoid = otmp; 1518. stealoid->nobj = (struct obj *) 0; 1519. } else { 1520. minvent_ptr = &otmp->nobj; 1521. } 1522. *minvent_ptr = stealoid; /* put armor back into minvent */ 1523. } 1524. 1525. if (stealoid) { /* we will be taking everything */ 1526. if (gender(mdef) == (int) u.mfemale && youmonst.data->mlet == S_NYMPH) 1527. You("charm %s. She gladly hands over her possessions.", 1528. mon_nam(mdef)); 1529. else 1530. You("seduce %s and %s starts to take off %s clothes.", 1531. mon_nam(mdef), mhe(mdef), mhis(mdef)); 1532. } 1533. 1534. while ((otmp = mdef->minvent) != 0) { 1535. if (!Upolyd) 1536. break; /* no longer have ability to steal */ 1537. /* take the object away from the monster */ 1538. obj_extract_self(otmp); 1539. if ((unwornmask = otmp->owornmask) != 0L) { 1540. mdef->misc_worn_check &= ~unwornmask; 1541. if (otmp->owornmask & W_WEP) 1542. setmnotwielded(mdef, otmp); 1543. otmp->owornmask = 0L; 1544. update_mon_intrinsics(mdef, otmp, FALSE, FALSE); 1545. /* give monster a chance to wear other equipment on its next 1546. move instead of waiting until it picks something up */ 1547. mdef->misc_worn_check |= I_SPECIAL; 1548. 1549. if (otmp == stealoid) /* special message for final item */ 1550. pline("%s finishes taking off %s suit.", Monnam(mdef), 1551. mhis(mdef)); 1552. } 1553. /* give the object to the character */ 1554. otmp = hold_another_object(otmp, "You snatched but dropped %s.", 1555. doname(otmp), "You steal: "); 1556. /* might have dropped otmp, and it might have broken or left level */ 1557. if (!otmp || otmp->where != OBJ_INVENT) 1558. continue; 1559. if (theft_petrifies(otmp)) 1560. break; /* stop thieving even though hero survived */ 1561. /* more take-away handling, after theft message */ 1562. if (unwornmask & W_WEP) { /* stole wielded weapon */ 1563. possibly_unwield(mdef, FALSE); 1564. } else if (unwornmask & W_ARMG) { /* stole worn gloves */ 1565. mselftouch(mdef, (const char *) 0, TRUE); 1566. if (DEADMONSTER(mdef)) /* it's now a statue */ 1567. return; /* can't continue stealing */ 1568. } 1569. 1570. if (!stealoid) 1571. break; /* only taking one item */ 1572. } 1573. } 1574. 1575. int 1576. damageum(mdef, mattk, specialdmg) 1577. register struct monst *mdef; 1578. register struct attack *mattk; 1579. int specialdmg; /* blessed and/or silver bonus against various things */ 1580. { 1581. register struct permonst *pd = mdef->data; 1582. int armpro, tmp = d((int) mattk->damn, (int) mattk->damd); 1583. boolean negated; 1584. struct obj *mongold; 1585. 1586. armpro = magic_negation(mdef); 1587. /* since hero can't be cancelled, only defender's armor applies */ 1588. negated = !(rn2(10) >= 3 * armpro); 1589. 1590. if (is_demon(youmonst.data) && !rn2(13) && !uwep 1591. && u.umonnum != PM_SUCCUBUS && u.umonnum != PM_INCUBUS 1592. && u.umonnum != PM_BALROG) { 1593. demonpet(); 1594. return 0; 1595. } 1596. switch (mattk->adtyp) { 1597. case AD_STUN: 1598. if (!Blind) 1599. pline("%s %s for a moment.", Monnam(mdef), 1600. makeplural(stagger(pd, "stagger"))); 1601. mdef->mstun = 1; 1602. goto physical; 1603. case AD_LEGS: 1604. #if 0 1605. if (u.ucancelled) { 1606. tmp = 0; 1607. break; 1608. } 1609. #endif 1610. goto physical; 1611. case AD_WERE: /* no special effect on monsters */ 1612. case AD_HEAL: /* likewise */ 1613. case AD_PHYS: 1614. physical: 1615. if (pd == &mons[PM_SHADE]) { 1616. tmp = 0; 1617. if (!specialdmg) 1618. impossible("bad shade attack function flow?"); 1619. } 1620. tmp += specialdmg; 1621. 1622. if (mattk->aatyp == AT_WEAP) { 1623. /* hmonas() uses known_hitum() to deal physical damage, 1624. then also damageum() for non-AD_PHYS; don't inflict 1625. extra physical damage for unusual damage types */ 1626. tmp = 0; 1627. } else if (mattk->aatyp == AT_KICK 1628. || mattk->aatyp == AT_CLAW 1629. || mattk->aatyp == AT_TUCH 1630. || mattk->aatyp == AT_HUGS) { 1631. if (thick_skinned(pd)) 1632. tmp = (mattk->aatyp == AT_KICK) ? 0 : (tmp + 1) / 2; 1633. /* add ring(s) of increase damage */ 1634. if (u.udaminc > 0) { 1635. /* applies even if damage was 0 */ 1636. tmp += u.udaminc; 1637. } else if (tmp > 0) { 1638. /* ring(s) might be negative; avoid converting 1639. 0 to non-0 or positive to non-positive */ 1640. tmp += u.udaminc; 1641. if (tmp < 1) 1642. tmp = 1; 1643. } 1644. } 1645. break; 1646. case AD_FIRE: 1647. if (negated) { 1648. tmp = 0; 1649. break; 1650. } 1651. if (!Blind) 1652. pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk)); 1653. if (completelyburns(pd)) { /* paper golem or straw golem */ 1654. if (!Blind) 1655. pline("%s burns completely!", Monnam(mdef)); 1656. else 1657. You("smell burning%s.", 1658. (pd == &mons[PM_PAPER_GOLEM]) ? " paper" 1659. : (pd == &mons[PM_STRAW_GOLEM]) ? " straw" : ""); 1660. xkilled(mdef, XKILL_NOMSG | XKILL_NOCORPSE); 1661. tmp = 0; 1662. break; 1663. /* Don't return yet; keep hp<1 and tmp=0 for pet msg */ 1664. } 1665. tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); 1666. tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); 1667. if (resists_fire(mdef)) { 1668. if (!Blind) 1669. pline_The("fire doesn't heat %s!", mon_nam(mdef)); 1670. golemeffects(mdef, AD_FIRE, tmp); 1671. shieldeff(mdef->mx, mdef->my); 1672. tmp = 0; 1673. } 1674. /* only potions damage resistant players in destroy_item */ 1675. tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE); 1676. break; 1677. case AD_COLD: 1678. if (negated) { 1679. tmp = 0; 1680. break; 1681. } 1682. if (!Blind) 1683. pline("%s is covered in frost!", Monnam(mdef)); 1684. if (resists_cold(mdef)) { 1685. shieldeff(mdef->mx, mdef->my); 1686. if (!Blind) 1687. pline_The("frost doesn't chill %s!", mon_nam(mdef)); 1688. golemeffects(mdef, AD_COLD, tmp); 1689. tmp = 0; 1690. } 1691. tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD); 1692. break; 1693. case AD_ELEC: 1694. if (negated) { 1695. tmp = 0; 1696. break; 1697. } 1698. if (!Blind) 1699. pline("%s is zapped!", Monnam(mdef)); 1700. tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); 1701. if (resists_elec(mdef)) { 1702. if (!Blind) 1703. pline_The("zap doesn't shock %s!", mon_nam(mdef)); 1704. golemeffects(mdef, AD_ELEC, tmp); 1705. shieldeff(mdef->mx, mdef->my); 1706. tmp = 0; 1707. } 1708. /* only rings damage resistant players in destroy_item */ 1709. tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC); 1710. break; 1711. case AD_ACID: 1712. if (resists_acid(mdef)) 1713. tmp = 0; 1714. break; 1715. case AD_STON: 1716. if (!munstone(mdef, TRUE)) 1717. minstapetrify(mdef, TRUE); 1718. tmp = 0; 1719. break; 1720. case AD_SSEX: 1721. case AD_SEDU: 1722. case AD_SITM: 1723. steal_it(mdef, mattk); 1724. tmp = 0; 1725. break; 1726. case AD_SGLD: 1727. /* This you as a leprechaun, so steal 1728. real gold only, no lesser coins */ 1729. mongold = findgold(mdef->minvent); 1730. if (mongold) { 1731. obj_extract_self(mongold); 1732. if (merge_choice(invent, mongold) || inv_cnt(FALSE) < 52) { 1733. addinv(mongold); 1734. Your("purse feels heavier."); 1735. } else { 1736. You("grab %s's gold, but find no room in your knapsack.", 1737. mon_nam(mdef)); 1738. dropy(mongold); 1739. } 1740. } 1741. exercise(A_DEX, TRUE); 1742. tmp = 0; 1743. break; 1744. case AD_TLPT: 1745. if (tmp <= 0) 1746. tmp = 1; 1747. if (!negated) { 1748. char nambuf[BUFSZ]; 1749. boolean u_saw_mon = (canseemon(mdef) 1750. || (u.uswallow && u.ustuck == mdef)); 1751. 1752. /* record the name before losing sight of monster */ 1753. Strcpy(nambuf, Monnam(mdef)); 1754. if (u_teleport_mon(mdef, FALSE) && u_saw_mon 1755. && !(canseemon(mdef) || (u.uswallow && u.ustuck == mdef))) 1756. pline("%s suddenly disappears!", nambuf); 1757. if (tmp >= mdef->mhp) { /* see hitmu(mhitu.c) */ 1758. if (mdef->mhp == 1) 1759. ++mdef->mhp; 1760. tmp = mdef->mhp - 1; 1761. } 1762. } 1763. break; 1764. case AD_BLND: 1765. if (can_blnd(&youmonst, mdef, mattk->aatyp, (struct obj *) 0)) { 1766. if (!Blind && mdef->mcansee) 1767. pline("%s is blinded.", Monnam(mdef)); 1768. mdef->mcansee = 0; 1769. tmp += mdef->mblinded; 1770. if (tmp > 127) 1771. tmp = 127; 1772. mdef->mblinded = tmp; 1773. } 1774. tmp = 0; 1775. break; 1776. case AD_CURS: 1777. if (night() && !rn2(10) && !mdef->mcan) { 1778. if (pd == &mons[PM_CLAY_GOLEM]) { 1779. if (!Blind) 1780. pline("Some writing vanishes from %s head!", 1781. s_suffix(mon_nam(mdef))); 1782. xkilled(mdef, XKILL_NOMSG); 1783. /* Don't return yet; keep hp<1 and tmp=0 for pet msg */ 1784. } else { 1785. mdef->mcan = 1; 1786. You("chuckle."); 1787. } 1788. } 1789. tmp = 0; 1790. break; 1791. case AD_DRLI: 1792. if (!negated && !rn2(3) && !resists_drli(mdef)) { 1793. int xtmp = d(2, 6); 1794. 1795. pline("%s suddenly seems weaker!", Monnam(mdef)); 1796. mdef->mhpmax -= xtmp; 1797. mdef->mhp -= xtmp; 1798. /* !m_lev: level 0 monster is killed regardless of hit points 1799. rather than drop to level -1 */ 1800. if (DEADMONSTER(mdef) || !mdef->m_lev) { 1801. pline("%s dies!", Monnam(mdef)); 1802. xkilled(mdef, XKILL_NOMSG); 1803. } else 1804. mdef->m_lev--; 1805. tmp = 0; 1806. } 1807. break; 1808. case AD_RUST: 1809. if (pd == &mons[PM_IRON_GOLEM]) { 1810. pline("%s falls to pieces!", Monnam(mdef)); 1811. xkilled(mdef, XKILL_NOMSG); 1812. } 1813. erode_armor(mdef, ERODE_RUST); 1814. tmp = 0; 1815. break; 1816. case AD_CORR: 1817. erode_armor(mdef, ERODE_CORRODE); 1818. tmp = 0; 1819. break; 1820. case AD_DCAY: 1821. if (pd == &mons[PM_WOOD_GOLEM] || pd == &mons[PM_LEATHER_GOLEM]) { 1822. pline("%s falls to pieces!", Monnam(mdef)); 1823. xkilled(mdef, XKILL_NOMSG); 1824. } 1825. erode_armor(mdef, ERODE_ROT); 1826. tmp = 0; 1827. break; 1828. case AD_DREN: 1829. if (!negated && !rn2(4)) 1830. xdrainenergym(mdef, TRUE); 1831. tmp = 0; 1832. break; 1833. case AD_DRST: 1834. case AD_DRDX: 1835. case AD_DRCO: 1836. if (!negated && !rn2(8)) { 1837. Your("%s was poisoned!", mpoisons_subj(&youmonst, mattk)); 1838. if (resists_poison(mdef)) { 1839. pline_The("poison doesn't seem to affect %s.", mon_nam(mdef)); 1840. } else { 1841. if (!rn2(10)) { 1842. Your("poison was deadly..."); 1843. tmp = mdef->mhp; 1844. } else 1845. tmp += rn1(10, 6); 1846. } 1847. } 1848. break; 1849. case AD_DRIN: { 1850. struct obj *helmet; 1851. 1852. if (notonhead || !has_head(pd)) { 1853. pline("%s doesn't seem harmed.", Monnam(mdef)); 1854. tmp = 0; 1855. if (!Unchanging && pd == &mons[PM_GREEN_SLIME]) { 1856. if (!Slimed) { 1857. You("suck in some slime and don't feel very well."); 1858. make_slimed(10L, (char *) 0); 1859. } 1860. } 1861. break; 1862. } 1863. if (m_slips_free(mdef, mattk)) 1864. break; 1865. 1866. if ((helmet = which_armor(mdef, W_ARMH)) != 0 && rn2(8)) { 1867. pline("%s %s blocks your attack to %s head.", 1868. s_suffix(Monnam(mdef)), helm_simple_name(helmet), 1869. mhis(mdef)); 1870. break; 1871. } 1872. 1873. (void) eat_brains(&youmonst, mdef, TRUE, &tmp); 1874. break; 1875. } 1876. case AD_STCK: 1877. if (!negated && !sticks(pd)) 1878. u.ustuck = mdef; /* it's now stuck to you */ 1879. break; 1880. case AD_WRAP: 1881. if (!sticks(pd)) { 1882. if (!u.ustuck && !rn2(10)) { 1883. if (m_slips_free(mdef, mattk)) { 1884. tmp = 0; 1885. } else { 1886. You("swing yourself around %s!", mon_nam(mdef)); 1887. u.ustuck = mdef; 1888. } 1889. } else if (u.ustuck == mdef) { 1890. /* Monsters don't wear amulets of magical breathing */ 1891. if (is_pool(u.ux, u.uy) && !is_swimmer(pd) 1892. && !amphibious(pd)) { 1893. You("drown %s...", mon_nam(mdef)); 1894. tmp = mdef->mhp; 1895. } else if (mattk->aatyp == AT_HUGS) 1896. pline("%s is being crushed.", Monnam(mdef)); 1897. } else { 1898. tmp = 0; 1899. if (flags.verbose) 1900. You("brush against %s %s.", s_suffix(mon_nam(mdef)), 1901. mbodypart(mdef, LEG)); 1902. } 1903. } else 1904. tmp = 0; 1905. break; 1906. case AD_PLYS: 1907. if (!negated && mdef->mcanmove && !rn2(3) && tmp < mdef->mhp) { 1908. if (!Blind) 1909. pline("%s is frozen by you!", Monnam(mdef)); 1910. paralyze_monst(mdef, rnd(10)); 1911. } 1912. break; 1913. case AD_SLEE: 1914. if (!negated && !mdef->msleeping && sleep_monst(mdef, rnd(10), -1)) { 1915. if (!Blind) 1916. pline("%s is put to sleep by you!", Monnam(mdef)); 1917. slept_monst(mdef); 1918. } 1919. break; 1920. case AD_SLIM: 1921. if (negated) 1922. break; /* physical damage only */ 1923. if (!rn2(4) && !slimeproof(pd)) { 1924. if (!munslime(mdef, TRUE) && !DEADMONSTER(mdef)) { 1925. /* this assumes newcham() won't fail; since hero has 1926. a slime attack, green slimes haven't been geno'd */ 1927. You("turn %s into slime.", mon_nam(mdef)); 1928. if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, FALSE)) 1929. pd = mdef->data; 1930. } 1931. /* munslime attempt could have been fatal */ 1932. if (DEADMONSTER(mdef)) 1933. return 2; /* skip death message */ 1934. tmp = 0; 1935. } 1936. break; 1937. case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ 1938. /* there's no msomearmor() function, so just do damage */ 1939. /* if (negated) break; */ 1940. break; 1941. case AD_SLOW: 1942. if (!negated && mdef->mspeed != MSLOW) { 1943. unsigned int oldspeed = mdef->mspeed; 1944. 1945. mon_adjust_speed(mdef, -1, (struct obj *) 0); 1946. if (mdef->mspeed != oldspeed && canseemon(mdef)) 1947. pline("%s slows down.", Monnam(mdef)); 1948. } 1949. break; 1950. case AD_CONF: 1951. if (!mdef->mconf) { 1952. if (canseemon(mdef)) 1953. pline("%s looks confused.", Monnam(mdef)); 1954. mdef->mconf = 1; 1955. } 1956. break; 1957. default: 1958. tmp = 0; 1959. break; 1960. } 1961. 1962. mdef->mstrategy &= ~STRAT_WAITFORU; /* in case player is very fast */ 1963. mdef->mhp -= tmp; 1964. if (DEADMONSTER(mdef)) { 1965. if (mdef->mtame && !cansee(mdef->mx, mdef->my)) { 1966. You_feel("embarrassed for a moment."); 1967. if (tmp) 1968. xkilled(mdef, XKILL_NOMSG); /* !tmp but hp<1: already killed */ 1969. } else if (!flags.verbose) { 1970. You("destroy it!"); 1971. if (tmp) 1972. xkilled(mdef, XKILL_NOMSG); 1973. } else if (tmp) 1974. killed(mdef); 1975. return 2; 1976. } 1977. return 1; 1978. } 1979. 1980. STATIC_OVL int 1981. explum(mdef, mattk) 1982. register struct monst *mdef; 1983. register struct attack *mattk; 1984. { 1985. boolean resistance; /* only for cold/fire/elec */ 1986. register int tmp = d((int) mattk->damn, (int) mattk->damd); 1987. 1988. You("explode!"); 1989. switch (mattk->adtyp) { 1990. case AD_BLND: 1991. if (!resists_blnd(mdef)) { 1992. pline("%s is blinded by your flash of light!", Monnam(mdef)); 1993. mdef->mblinded = min((int) mdef->mblinded + tmp, 127); 1994. mdef->mcansee = 0; 1995. } 1996. break; 1997. case AD_HALU: 1998. if (haseyes(mdef->data) && mdef->mcansee) { 1999. pline("%s is affected by your flash of light!", Monnam(mdef)); 2000. mdef->mconf = 1; 2001. } 2002. break; 2003. case AD_COLD: 2004. resistance = resists_cold(mdef); 2005. goto common; 2006. case AD_FIRE: 2007. resistance = resists_fire(mdef); 2008. goto common; 2009. case AD_ELEC: 2010. resistance = resists_elec(mdef); 2011. common: 2012. if (!resistance) { 2013. pline("%s gets blasted!", Monnam(mdef)); 2014. mdef->mhp -= tmp; 2015. if (DEADMONSTER(mdef)) { 2016. killed(mdef); 2017. return 2; 2018. } 2019. } else { 2020. shieldeff(mdef->mx, mdef->my); 2021. if (is_golem(mdef->data)) 2022. golemeffects(mdef, (int) mattk->adtyp, tmp); 2023. else 2024. pline_The("blast doesn't seem to affect %s.", mon_nam(mdef)); 2025. } 2026. break; 2027. default: 2028. break; 2029. } 2030. return 1; 2031. } 2032. 2033. STATIC_OVL void 2034. start_engulf(mdef) 2035. struct monst *mdef; 2036. { 2037. if (!Invisible) { 2038. map_location(u.ux, u.uy, TRUE); 2039. tmp_at(DISP_ALWAYS, mon_to_glyph(&youmonst, rn2_on_display_rng)); 2040. tmp_at(mdef->mx, mdef->my); 2041. } 2042. You("engulf %s!", mon_nam(mdef)); 2043. delay_output(); 2044. delay_output(); 2045. } 2046. 2047. STATIC_OVL void 2048. end_engulf() 2049. { 2050. if (!Invisible) { 2051. tmp_at(DISP_END, 0); 2052. newsym(u.ux, u.uy); 2053. } 2054. } 2055. 2056. STATIC_OVL int 2057. gulpum(mdef, mattk) 2058. register struct monst *mdef; 2059. register struct attack *mattk; 2060. { 2061. #ifdef LINT /* static char msgbuf[BUFSZ]; */ 2062. char msgbuf[BUFSZ]; 2063. #else 2064. static char msgbuf[BUFSZ]; /* for nomovemsg */ 2065. #endif 2066. register int tmp; 2067. register int dam = d((int) mattk->damn, (int) mattk->damd); 2068. boolean fatal_gulp; 2069. struct obj *otmp; 2070. struct permonst *pd = mdef->data; 2071. 2072. /* Not totally the same as for real monsters. Specifically, these 2073. * don't take multiple moves. (It's just too hard, for too little 2074. * result, to program monsters which attack from inside you, which 2075. * would be necessary if done accurately.) Instead, we arbitrarily 2076. * kill the monster immediately for AD_DGST and we regurgitate them 2077. * after exactly 1 round of attack otherwise. -KAA 2078. */ 2079. 2080. if (!engulf_target(&youmonst, mdef)) 2081. return 0; 2082. 2083. if (u.uhunger < 1500 && !u.uswallow) { 2084. for (otmp = mdef->minvent; otmp; otmp = otmp->nobj) 2085. (void) snuff_lit(otmp); 2086. 2087. /* force vampire in bat, cloud, or wolf form to revert back to 2088. vampire form now instead of dealing with that when it dies */ 2089. if (is_vampshifter(mdef) 2090. && newcham(mdef, &mons[mdef->cham], FALSE, FALSE)) { 2091. You("engulf it, then expel it."); 2092. if (canspotmon(mdef)) 2093. pline("It turns into %s.", a_monnam(mdef)); 2094. else 2095. map_invisible(mdef->mx, mdef->my); 2096. return 1; 2097. } 2098. 2099. /* engulfing a cockatrice or digesting a Rider or Medusa */ 2100. fatal_gulp = (touch_petrifies(pd) && !Stone_resistance) 2101. || (mattk->adtyp == AD_DGST 2102. && (is_rider(pd) || (pd == &mons[PM_MEDUSA] 2103. && !Stone_resistance))); 2104. 2105. if ((mattk->adtyp == AD_DGST && !Slow_digestion) || fatal_gulp) 2106. eating_conducts(pd); 2107. 2108. if (fatal_gulp && !is_rider(pd)) { /* petrification */ 2109. char kbuf[BUFSZ]; 2110. const char *mname = pd->mname; 2111. 2112. if (!type_is_pname(pd)) 2113. mname = an(mname); 2114. You("englut %s.", mon_nam(mdef)); 2115. Sprintf(kbuf, "swallowing %s whole", mname); 2116. instapetrify(kbuf); 2117. } else { 2118. start_engulf(mdef); 2119. switch (mattk->adtyp) { 2120. case AD_DGST: 2121. /* eating a Rider or its corpse is fatal */ 2122. if (is_rider(pd)) { 2123. pline("Unfortunately, digesting any of it is fatal."); 2124. end_engulf(); 2125. Sprintf(killer.name, "unwisely tried to eat %s", 2126. pd->mname); 2127. killer.format = NO_KILLER_PREFIX; 2128. done(DIED); 2129. return 0; /* lifesaved */ 2130. } 2131. 2132. if (Slow_digestion) { 2133. dam = 0; 2134. break; 2135. } 2136. 2137. /* Use up amulet of life saving */ 2138. if ((otmp = mlifesaver(mdef)) != 0) 2139. m_useup(mdef, otmp); 2140. 2141. newuhs(FALSE); 2142. /* start_engulf() issues "you engulf <mdef>" above; this 2143. used to specify XKILL_NOMSG but we need "you kill <mdef>" 2144. in case we're also going to get "welcome to level N+1"; 2145. "you totally digest <mdef>" will be coming soon (after 2146. several turns) but the level-gain message seems out of 2147. order if the kill message is left implicit */ 2148. xkilled(mdef, XKILL_GIVEMSG | XKILL_NOCORPSE); 2149. if (!DEADMONSTER(mdef)) { /* monster lifesaved */ 2150. You("hurriedly regurgitate the sizzling in your %s.", 2151. body_part(STOMACH)); 2152. } else { 2153. tmp = 1 + (pd->cwt >> 8); 2154. if (corpse_chance(mdef, &youmonst, TRUE) 2155. && !(mvitals[monsndx(pd)].mvflags & G_NOCORPSE)) { 2156. /* nutrition only if there can be a corpse */ 2157. u.uhunger += (pd->cnutrit + 1) / 2; 2158. } else 2159. tmp = 0; 2160. Sprintf(msgbuf, "You totally digest %s.", mon_nam(mdef)); 2161. if (tmp != 0) { 2162. /* setting afternmv = end_engulf is tempting, 2163. * but will cause problems if the player is 2164. * attacked (which uses his real location) or 2165. * if his See_invisible wears off 2166. */ 2167. You("digest %s.", mon_nam(mdef)); 2168. if (Slow_digestion) 2169. tmp *= 2; 2170. nomul(-tmp); 2171. multi_reason = "digesting something"; 2172. nomovemsg = msgbuf; 2173. } else 2174. pline1(msgbuf); 2175. if (pd == &mons[PM_GREEN_SLIME]) { 2176. Sprintf(msgbuf, "%s isn't sitting well with you.", 2177. The(pd->mname)); 2178. if (!Unchanging) { 2179. make_slimed(5L, (char *) 0); 2180. } 2181. } else 2182. exercise(A_CON, TRUE); 2183. } 2184. end_engulf(); 2185. return 2; 2186. case AD_PHYS: 2187. if (youmonst.data == &mons[PM_FOG_CLOUD]) { 2188. pline("%s is laden with your moisture.", Monnam(mdef)); 2189. if (amphibious(pd) && !flaming(pd)) { 2190. dam = 0; 2191. pline("%s seems unharmed.", Monnam(mdef)); 2192. } 2193. } else 2194. pline("%s is pummeled with your debris!", Monnam(mdef)); 2195. break; 2196. case AD_ACID: 2197. pline("%s is covered with your goo!", Monnam(mdef)); 2198. if (resists_acid(mdef)) { 2199. pline("It seems harmless to %s.", mon_nam(mdef)); 2200. dam = 0; 2201. } 2202. break; 2203. case AD_BLND: 2204. if (can_blnd(&youmonst, mdef, mattk->aatyp, 2205. (struct obj *) 0)) { 2206. if (mdef->mcansee) 2207. pline("%s can't see in there!", Monnam(mdef)); 2208. mdef->mcansee = 0; 2209. dam += mdef->mblinded; 2210. if (dam > 127) 2211. dam = 127; 2212. mdef->mblinded = dam; 2213. } 2214. dam = 0; 2215. break; 2216. case AD_ELEC: 2217. if (rn2(2)) { 2218. pline_The("air around %s crackles with electricity.", 2219. mon_nam(mdef)); 2220. if (resists_elec(mdef)) { 2221. pline("%s seems unhurt.", Monnam(mdef)); 2222. dam = 0; 2223. } 2224. golemeffects(mdef, (int) mattk->adtyp, dam); 2225. } else 2226. dam = 0; 2227. break; 2228. case AD_COLD: 2229. if (rn2(2)) { 2230. if (resists_cold(mdef)) { 2231. pline("%s seems mildly chilly.", Monnam(mdef)); 2232. dam = 0; 2233. } else 2234. pline("%s is freezing to death!", Monnam(mdef)); 2235. golemeffects(mdef, (int) mattk->adtyp, dam); 2236. } else 2237. dam = 0; 2238. break; 2239. case AD_FIRE: 2240. if (rn2(2)) { 2241. if (resists_fire(mdef)) { 2242. pline("%s seems mildly hot.", Monnam(mdef)); 2243. dam = 0; 2244. } else 2245. pline("%s is burning to a crisp!", Monnam(mdef)); 2246. golemeffects(mdef, (int) mattk->adtyp, dam); 2247. } else 2248. dam = 0; 2249. break; 2250. case AD_DREN: 2251. if (!rn2(4)) 2252. xdrainenergym(mdef, TRUE); 2253. dam = 0; 2254. break; 2255. } 2256. end_engulf(); 2257. mdef->mhp -= dam; 2258. if (DEADMONSTER(mdef)) { 2259. killed(mdef); 2260. if (DEADMONSTER(mdef)) /* not lifesaved */ 2261. return 2; 2262. } 2263. You("%s %s!", is_animal(youmonst.data) ? "regurgitate" : "expel", 2264. mon_nam(mdef)); 2265. if (Slow_digestion || is_animal(youmonst.data)) { 2266. pline("Obviously, you didn't like %s taste.", 2267. s_suffix(mon_nam(mdef))); 2268. } 2269. } 2270. } 2271. return 0; 2272. } 2273. 2274. void 2275. missum(mdef, mattk, wouldhavehit) 2276. register struct monst *mdef; 2277. register struct attack *mattk; 2278. boolean wouldhavehit; 2279. { 2280. if (wouldhavehit) /* monk is missing due to penalty for wearing suit */ 2281. Your("armor is rather cumbersome..."); 2282. 2283. if (could_seduce(&youmonst, mdef, mattk)) 2284. You("pretend to be friendly to %s.", mon_nam(mdef)); 2285. else if (canspotmon(mdef) && flags.verbose) 2286. You("miss %s.", mon_nam(mdef)); 2287. else 2288. You("miss it."); 2289. if (!mdef->msleeping && mdef->mcanmove) 2290. wakeup(mdef, TRUE); 2291. } 2292. 2293. /* attack monster as a monster; returns True if mon survives */ 2294. STATIC_OVL boolean 2295. hmonas(mon) 2296. register struct monst *mon; 2297. { 2298. struct attack *mattk, alt_attk; 2299. struct obj *weapon, **originalweapon; 2300. boolean altwep = FALSE, weapon_used = FALSE, odd_claw = TRUE; 2301. int i, tmp, armorpenalty, sum[NATTK], nsum = 0, dhit = 0, attknum = 0; 2302. int dieroll, multi_claw = 0; 2303. 2304. /* with just one touch/claw/weapon attack, both rings matter; 2305. with more than one, alternate right and left when checking 2306. whether silver ring causes successful hit */ 2307. for (i = 0; i < NATTK; i++) { 2308. sum[i] = 0; 2309. mattk = getmattk(&youmonst, mon, i, sum, &alt_attk); 2310. if (mattk->aatyp == AT_WEAP 2311. || mattk->aatyp == AT_CLAW || mattk->aatyp == AT_TUCH) 2312. ++multi_claw; 2313. } 2314. multi_claw = (multi_claw > 1); /* switch from count to yes/no */ 2315. 2316. for (i = 0; i < NATTK; i++) { 2317. /* sum[i] = 0; -- now done above */ 2318. mattk = getmattk(&youmonst, mon, i, sum, &alt_attk); 2319. weapon = 0; 2320. switch (mattk->aatyp) { 2321. case AT_WEAP: 2322. /* if (!uwep) goto weaponless; */ 2323. use_weapon: 2324. odd_claw = !odd_claw; /* see case AT_CLAW,AT_TUCH below */ 2325. /* if we've already hit with a two-handed weapon, we don't 2326. get to make another weapon attack (note: monsters who 2327. use weapons do not have this restriction, but they also 2328. never have the opportunity to use two weapons) */ 2329. if (weapon_used && sum[i - 1] && uwep && bimanual(uwep)) 2330. continue; 2331. /* Certain monsters don't use weapons when encountered as enemies, 2332. * but players who polymorph into them have hands or claws and 2333. * thus should be able to use weapons. This shouldn't prohibit 2334. * the use of most special abilities, either. 2335. * If monster has multiple claw attacks, only one can use weapon. 2336. */ 2337. weapon_used = TRUE; 2338. /* Potential problem: if the monster gets multiple weapon attacks, 2339. * we currently allow the player to get each of these as a weapon 2340. * attack. Is this really desirable? 2341. */ 2342. /* approximate two-weapon mode; known_hitum() -> hmon() -> &c 2343. might destroy the weapon argument, but it might also already 2344. be Null, and we want to track that for passive() */ 2345. originalweapon = (altwep && uswapwep) ? &uswapwep : &uwep; 2346. if (uswapwep /* set up 'altwep' flag for next iteration */ 2347. /* only consider seconary when wielding one-handed primary */ 2348. && uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)) 2349. && !bimanual(uwep) 2350. /* only switch if not wearing shield and not at artifact; 2351. shield limitation is iffy since still get extra swings 2352. if polyform has them, but it matches twoweap behavior; 2353. twoweap also only allows primary to be an artifact, so 2354. if alternate weapon is one, don't use it */ 2355. && !uarms && !uswapwep->oartifact 2356. /* only switch to uswapwep if it's a weapon */ 2357. && (uswapwep->oclass == WEAPON_CLASS || is_weptool(uswapwep)) 2358. /* only switch if uswapwep is not bow, arrows, or darts */ 2359. && !(is_launcher(uswapwep) || is_ammo(uswapwep) 2360. || is_missile(uswapwep)) /* dart, shuriken, boomerang */ 2361. /* and not two-handed and not incapable of being wielded */ 2362. && !bimanual(uswapwep) 2363. && !(objects[uswapwep->otyp].oc_material == SILVER 2364. && Hate_silver)) 2365. altwep = !altwep; /* toggle for next attack */ 2366. weapon = *originalweapon; 2367. if (!weapon) /* no need to go beyond no-gloves to rings; not ...*/ 2368. originalweapon = &uarmg; /*... subject to erosion damage */ 2369. 2370. tmp = find_roll_to_hit(mon, AT_WEAP, weapon, &attknum, 2371. &armorpenalty); 2372. dieroll = rnd(20); 2373. dhit = (tmp > dieroll || u.uswallow); 2374. /* caller must set bhitpos */ 2375. if (!known_hitum(mon, weapon, &dhit, tmp, 2376. armorpenalty, mattk, dieroll)) { 2377. /* enemy dead, before any special abilities used */ 2378. sum[i] = 2; 2379. break; 2380. } else 2381. sum[i] = dhit; 2382. /* originalweapon points to an equipment slot which might 2383. now be empty if the weapon was destroyed during the hit; 2384. passive(,weapon,...) won't call passive_obj() in that case */ 2385. weapon = *originalweapon; /* might receive passive erosion */ 2386. /* might be a worm that gets cut in half; if so, early return */ 2387. if (m_at(u.ux + u.dx, u.uy + u.dy) != mon) { 2388. i = NATTK; /* skip additional attacks */ 2389. /* proceed with uswapwep->cursed check, then exit loop */ 2390. goto passivedone; 2391. } 2392. /* Do not print "You hit" message; known_hitum already did it. */ 2393. if (dhit && mattk->adtyp != AD_SPEL && mattk->adtyp != AD_PHYS) 2394. sum[i] = damageum(mon, mattk, 0); 2395. break; 2396. case AT_CLAW: 2397. if (uwep && !cantwield(youmonst.data) && !weapon_used) 2398. goto use_weapon; 2399. /*FALLTHRU*/ 2400. case AT_TUCH: 2401. if (uwep && youmonst.data->mlet == S_LICH && !weapon_used) 2402. goto use_weapon; 2403. /*FALLTHRU*/ 2404. case AT_KICK: 2405. case AT_BITE: 2406. case AT_STNG: 2407. case AT_BUTT: 2408. case AT_TENT: 2409. /*weaponless:*/ 2410. tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0, 2411. &attknum, &armorpenalty); 2412. dieroll = rnd(20); 2413. dhit = (tmp > dieroll || u.uswallow); 2414. if (dhit) { 2415. int compat, specialdmg; 2416. long silverhit = 0L; 2417. const char *verb = 0; /* verb or body part */ 2418. 2419. if (!u.uswallow 2420. && (compat = could_seduce(&youmonst, mon, mattk)) != 0) { 2421. You("%s %s %s.", 2422. (mon->mcansee && haseyes(mon->data)) ? "smile at" 2423. : "talk to", 2424. mon_nam(mon), 2425. (compat == 2) ? "engagingly" : "seductively"); 2426. /* doesn't anger it; no wakeup() */ 2427. sum[i] = damageum(mon, mattk, 0); 2428. break; 2429. } 2430. wakeup(mon, TRUE); 2431. 2432. specialdmg = 0; /* blessed and/or silver bonus */ 2433. switch (mattk->aatyp) { 2434. case AT_CLAW: 2435. case AT_TUCH: 2436. /* verb=="claws" may be overridden below */ 2437. verb = (mattk->aatyp == AT_TUCH) ? "touch" : "claws"; 2438. /* decide if silver-hater will be hit by silver ring(s); 2439. for 'multi_claw' where attacks alternate right/left, 2440. assume 'even' claw or touch attacks use right hand 2441. or paw, 'odd' ones use left for ring interaction; 2442. even vs odd is based on actual attacks rather 2443. than on index into mon->dat->mattk[] so that {bite, 2444. claw,claw} instead of {claw,claw,bite} doesn't 2445. make poly'd hero mysteriously become left-handed */ 2446. odd_claw = !odd_claw; 2447. specialdmg = special_dmgval(&youmonst, mon, 2448. W_ARMG 2449. | ((odd_claw || !multi_claw) 2450. ? W_RINGL : 0L) 2451. | ((!odd_claw || !multi_claw) 2452. ? W_RINGR : 0L), 2453. &silverhit); 2454. break; 2455. case AT_TENT: 2456. /* assumes mind flayer's tentacles-on-head rather 2457. than sea monster's tentacle-as-arm */ 2458. verb = "tentacles"; 2459. break; 2460. case AT_KICK: 2461. verb = "kick"; 2462. specialdmg = special_dmgval(&youmonst, mon, W_ARMF, 2463. &silverhit); 2464. break; 2465. case AT_BUTT: 2466. verb = "head butt"; /* mbodypart(mon,HEAD)=="head" */ 2467. /* hypothetical; if any form with a head-butt attack 2468. could wear a helmet, it would hit shades when 2469. wearing a blessed (or silver) one */ 2470. specialdmg = special_dmgval(&youmonst, mon, W_ARMH, 2471. &silverhit); 2472. break; 2473. case AT_BITE: 2474. verb = "bite"; 2475. break; 2476. case AT_STNG: 2477. verb = "sting"; 2478. break; 2479. default: 2480. verb = "hit"; 2481. break; 2482. } 2483. if (mon->data == &mons[PM_SHADE] && !specialdmg) { 2484. if (!strcmp(verb, "hit") 2485. || (mattk->aatyp == AT_CLAW && humanoid(mon->data))) 2486. verb = "attack"; 2487. Your("%s %s harmlessly through %s.", 2488. verb, vtense(verb, "pass"), mon_nam(mon)); 2489. } else { 2490. if (mattk->aatyp == AT_TENT) { 2491. Your("tentacles suck %s.", mon_nam(mon)); 2492. } else { 2493. if (mattk->aatyp == AT_CLAW) 2494. verb = "hit"; /* not "claws" */ 2495. You("%s %s.", verb, mon_nam(mon)); 2496. if (silverhit && flags.verbose) 2497. silver_sears(&youmonst, mon, silverhit); 2498. } 2499. sum[i] = damageum(mon, mattk, specialdmg); 2500. } 2501. } else { /* !dhit */ 2502. missum(mon, mattk, (tmp + armorpenalty > dieroll)); 2503. } 2504. break; 2505. 2506. case AT_HUGS: { 2507. int specialdmg; 2508. long silverhit = 0L; 2509. boolean byhand = hug_throttles(&mons[u.umonnum]), /* rope golem */ 2510. unconcerned = (byhand && !can_be_strangled(mon)); 2511. 2512. if (sticks(mon->data) || u.uswallow || notonhead 2513. || (byhand && (uwep || !has_head(mon->data)))) { 2514. /* can't hold a holder due to subsequent ambiguity over 2515. who is holding whom; can't hug engulfer from inside; 2516. can't hug a worm tail (would immobilize entire worm!); 2517. byhand: can't choke something that lacks a head; 2518. not allowed to make a choking hug if wielding a weapon 2519. (but might have grabbed w/o weapon, then wielded one, 2520. and may even be attacking a different monster now) */ 2521. if (byhand && uwep && u.ustuck 2522. && !(sticks(u.ustuck->data) || u.uswallow)) 2523. uunstick(); 2524. continue; /* not 'break'; bypass passive counter-attack */ 2525. } 2526. /* automatic if prev two attacks succeed, or if 2527. already grabbed in a previous attack */ 2528. dhit = 1; 2529. wakeup(mon, TRUE); 2530. /* choking hug/throttling grab uses hands (gloves or rings); 2531. normal hug uses outermost of cloak/suit/shirt */ 2532. specialdmg = special_dmgval(&youmonst, mon, 2533. byhand ? (W_ARMG | W_RINGL | W_RINGR) 2534. : (W_ARMC | W_ARM | W_ARMU), 2535. &silverhit); 2536. if (unconcerned) { 2537. /* strangling something which can't be strangled */ 2538. if (mattk != &alt_attk) { 2539. alt_attk = *mattk; 2540. mattk = &alt_attk; 2541. } 2542. /* change damage to 1d1; not strangling but still 2543. doing [minimal] physical damage to victim's body */ 2544. mattk->damn = mattk->damd = 1; 2545. /* don't give 'unconcerned' feedback if there is extra damage 2546. or if it is nearly destroyed or if creature doesn't have 2547. the mental ability to be concerned in the first place */ 2548. if (specialdmg || mindless(mon->data) 2549. || mon->mhp <= 1 + max(u.udaminc, 1)) 2550. unconcerned = FALSE; 2551. } 2552. if (mon->data == &mons[PM_SHADE]) { 2553. const char *verb = byhand ? "grasp" : "hug"; 2554. 2555. /* hugging a shade; successful if blessed outermost armor 2556. for normal hug, or blessed gloves or silver ring(s) for 2557. choking hug; deals damage but never grabs hold */ 2558. if (specialdmg) { 2559. You("%s %s%s", verb, mon_nam(mon), exclam(specialdmg)); 2560. if (silverhit && flags.verbose) 2561. silver_sears(&youmonst, mon, silverhit); 2562. sum[i] = damageum(mon, mattk, specialdmg); 2563. } else { 2564. Your("%s passes harmlessly through %s.", 2565. verb, mon_nam(mon)); 2566. } 2567. break; 2568. } 2569. /* hug attack against ordinary foe */ 2570. if (mon == u.ustuck) { 2571. pline("%s is being %s%s.", Monnam(mon), 2572. byhand ? "throttled" : "crushed", 2573. /* extra feedback for non-breather being choked */ 2574. unconcerned ? " but doesn't seem concerned" : ""); 2575. if (silverhit && flags.verbose) 2576. silver_sears(&youmonst, mon, silverhit); 2577. sum[i] = damageum(mon, mattk, specialdmg); 2578. } else if (i >= 2 && sum[i - 1] && sum[i - 2]) { 2579. /* in case we're hugging a new target while already 2580. holding something else; yields feedback 2581. "<u.ustuck> is no longer in your clutches" */ 2582. if (u.ustuck && u.ustuck != mon) 2583. uunstick(); 2584. You("grab %s!", mon_nam(mon)); 2585. u.ustuck = mon; 2586. if (silverhit && flags.verbose) 2587. silver_sears(&youmonst, mon, silverhit); 2588. sum[i] = damageum(mon, mattk, specialdmg); 2589. } 2590. break; /* AT_HUGS */ 2591. } 2592. 2593. case AT_EXPL: /* automatic hit if next to */ 2594. dhit = -1; 2595. wakeup(mon, TRUE); 2596. sum[i] = explum(mon, mattk); 2597. break; 2598. 2599. case AT_ENGL: 2600. tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0, 2601. &attknum, &armorpenalty); 2602. if ((dhit = (tmp > rnd(20 + i)))) { 2603. wakeup(mon, TRUE); 2604. if (mon->data == &mons[PM_SHADE]) 2605. Your("attempt to surround %s is harmless.", mon_nam(mon)); 2606. else { 2607. sum[i] = gulpum(mon, mattk); 2608. if (sum[i] == 2 && (mon->data->mlet == S_ZOMBIE 2609. || mon->data->mlet == S_MUMMY) 2610. && rn2(5) && !Sick_resistance) { 2611. You_feel("%ssick.", (Sick) ? "very " : ""); 2612. mdamageu(mon, rnd(8)); 2613. } 2614. } 2615. } else { 2616. missum(mon, mattk, FALSE); 2617. } 2618. break; 2619. 2620. case AT_MAGC: 2621. /* No check for uwep; if wielding nothing we want to 2622. * do the normal 1-2 points bare hand damage... 2623. */ 2624. if ((youmonst.data->mlet == S_KOBOLD 2625. || youmonst.data->mlet == S_ORC 2626. || youmonst.data->mlet == S_GNOME) && !weapon_used) 2627. goto use_weapon; 2628. /*FALLTHRU*/ 2629. 2630. case AT_NONE: 2631. case AT_BOOM: 2632. continue; 2633. /* Not break--avoid passive attacks from enemy */ 2634. 2635. case AT_BREA: 2636. case AT_SPIT: 2637. case AT_GAZE: /* all done using #monster command */ 2638. dhit = 0; 2639. break; 2640. 2641. default: /* Strange... */ 2642. impossible("strange attack of yours (%d)", mattk->aatyp); 2643. } 2644. if (dhit == -1) { 2645. u.mh = -1; /* dead in the current form */ 2646. rehumanize(); 2647. } 2648. if (sum[i] == 2) { 2649. /* defender dead */ 2650. (void) passive(mon, weapon, 1, 0, mattk->aatyp, FALSE); 2651. nsum = 0; /* return value below used to be 'nsum > 0' */ 2652. } else { 2653. (void) passive(mon, weapon, sum[i], 1, mattk->aatyp, FALSE); 2654. nsum |= sum[i]; 2655. } 2656. 2657. /* don't use sum[i] beyond this point; 2658. 'i' will be out of bounds if we get here via 'goto' */ 2659. passivedone: 2660. /* when using dual weapons, cursed secondary weapon doesn't weld, 2661. it gets dropped; do the same when multiple AT_WEAP attacks 2662. simulate twoweap */ 2663. if (uswapwep && weapon == uswapwep && weapon->cursed) { 2664. drop_uswapwep(); 2665. break; /* don't proceed with additional attacks */ 2666. } 2667. /* stop attacking if defender has died; 2668. needed to defer this until after uswapwep->cursed check */ 2669. if (DEADMONSTER(mon)) 2670. break; 2671. if (!Upolyd) 2672. break; /* No extra attacks if no longer a monster */ 2673. if (multi < 0) 2674. break; /* If paralyzed while attacking, i.e. floating eye */ 2675. } 2676. /* return value isn't used, but make it match hitum()'s */ 2677. return !DEADMONSTER(mon); 2678. } 2679. 2680. /* Special (passive) attacks on you by monsters done here. 2681. */ 2682. int 2683. passive(mon, weapon, mhit, malive, aatyp, wep_was_destroyed) 2684. struct monst *mon; 2685. struct obj *weapon; /* uwep or uswapwep or uarmg or uarmf or Null */ 2686. boolean mhit; 2687. int malive; 2688. uchar aatyp; 2689. boolean wep_was_destroyed; 2690. { 2691. register struct permonst *ptr = mon->data; 2692. register int i, tmp; 2693. 2694. for (i = 0;; i++) { 2695. if (i >= NATTK) 2696. return (malive | mhit); /* no passive attacks */ 2697. if (ptr->mattk[i].aatyp == AT_NONE) 2698. break; /* try this one */ 2699. } 2700. /* Note: tmp not always used */ 2701. if (ptr->mattk[i].damn) 2702. tmp = d((int) ptr->mattk[i].damn, (int) ptr->mattk[i].damd); 2703. else if (ptr->mattk[i].damd) 2704. tmp = d((int) mon->m_lev + 1, (int) ptr->mattk[i].damd); 2705. else 2706. tmp = 0; 2707. 2708. /* These affect you even if they just died. 2709. */ 2710. switch (ptr->mattk[i].adtyp) { 2711. case AD_FIRE: 2712. if (mhit && !mon->mcan && weapon) { 2713. if (aatyp == AT_KICK) { 2714. if (uarmf && !rn2(6)) 2715. (void) erode_obj(uarmf, xname(uarmf), ERODE_BURN, 2716. EF_GREASE | EF_VERBOSE); 2717. } else if (aatyp == AT_WEAP || aatyp == AT_CLAW 2718. || aatyp == AT_MAGC || aatyp == AT_TUCH) 2719. passive_obj(mon, weapon, &(ptr->mattk[i])); 2720. } 2721. break; 2722. case AD_ACID: 2723. if (mhit && rn2(2)) { 2724. if (Blind || !flags.verbose) 2725. You("are splashed!"); 2726. else 2727. You("are splashed by %s %s!", s_suffix(mon_nam(mon)), 2728. hliquid("acid")); 2729. 2730. if (!Acid_resistance) 2731. mdamageu(mon, tmp); 2732. if (!rn2(30)) 2733. erode_armor(&youmonst, ERODE_CORRODE); 2734. } 2735. if (mhit && weapon) { 2736. if (aatyp == AT_KICK) { 2737. if (uarmf && !rn2(6)) 2738. (void) erode_obj(uarmf, xname(uarmf), ERODE_CORRODE, 2739. EF_GREASE | EF_VERBOSE); 2740. } else if (aatyp == AT_WEAP || aatyp == AT_CLAW 2741. || aatyp == AT_MAGC || aatyp == AT_TUCH) 2742. passive_obj(mon, weapon, &(ptr->mattk[i])); 2743. } 2744. exercise(A_STR, FALSE); 2745. break; 2746. case AD_STON: 2747. if (mhit) { /* successful attack */ 2748. long protector = attk_protection((int) aatyp); 2749. 2750. /* hero using monsters' AT_MAGC attack is hitting hand to 2751. hand rather than casting a spell */ 2752. if (aatyp == AT_MAGC) 2753. protector = W_ARMG; 2754. 2755. if (protector == 0L /* no protection */ 2756. || (protector == W_ARMG && !uarmg 2757. && !uwep && !wep_was_destroyed) 2758. || (protector == W_ARMF && !uarmf) 2759. || (protector == W_ARMH && !uarmh) 2760. || (protector == (W_ARMC | W_ARMG) && (!uarmc || !uarmg))) { 2761. if (!Stone_resistance 2762. && !(poly_when_stoned(youmonst.data) 2763. && polymon(PM_STONE_GOLEM))) { 2764. done_in_by(mon, STONING); /* "You turn to stone..." */ 2765. return 2; 2766. } 2767. } 2768. } 2769. break; 2770. case AD_RUST: 2771. if (mhit && !mon->mcan && weapon) { 2772. if (aatyp == AT_KICK) { 2773. if (uarmf) 2774. (void) erode_obj(uarmf, xname(uarmf), ERODE_RUST, 2775. EF_GREASE | EF_VERBOSE); 2776. } else if (aatyp == AT_WEAP || aatyp == AT_CLAW 2777. || aatyp == AT_MAGC || aatyp == AT_TUCH) 2778. passive_obj(mon, weapon, &(ptr->mattk[i])); 2779. } 2780. break; 2781. case AD_CORR: 2782. if (mhit && !mon->mcan && weapon) { 2783. if (aatyp == AT_KICK) { 2784. if (uarmf) 2785. (void) erode_obj(uarmf, xname(uarmf), ERODE_CORRODE, 2786. EF_GREASE | EF_VERBOSE); 2787. } else if (aatyp == AT_WEAP || aatyp == AT_CLAW 2788. || aatyp == AT_MAGC || aatyp == AT_TUCH) 2789. passive_obj(mon, weapon, &(ptr->mattk[i])); 2790. } 2791. break; 2792. case AD_MAGM: 2793. /* wrath of gods for attacking Oracle */ 2794. if (Antimagic) { 2795. shieldeff(u.ux, u.uy); 2796. pline("A hail of magic missiles narrowly misses you!"); 2797. } else { 2798. You("are hit by magic missiles appearing from thin air!"); 2799. mdamageu(mon, tmp); 2800. } 2801. break; 2802. case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ 2803. if (mhit) { 2804. if (aatyp == AT_KICK) { 2805. if (!weapon) 2806. break; 2807. } else if (aatyp == AT_BITE || aatyp == AT_BUTT 2808. || (aatyp >= AT_STNG && aatyp < AT_WEAP)) { 2809. break; /* no object involved */ 2810. } 2811. passive_obj(mon, weapon, &(ptr->mattk[i])); 2812. } 2813. break; 2814. default: 2815. break; 2816. } 2817. 2818. /* These only affect you if they still live. 2819. */ 2820. if (malive && !mon->mcan && rn2(3)) { 2821. switch (ptr->mattk[i].adtyp) { 2822. case AD_PLYS: 2823. if (ptr == &mons[PM_FLOATING_EYE]) { 2824. if (!canseemon(mon)) { 2825. break; 2826. } 2827. if (mon->mcansee) { 2828. if (ureflects("%s gaze is reflected by your %s.", 2829. s_suffix(Monnam(mon)))) { 2830. ; 2831. } else if (Free_action) { 2832. You("momentarily stiffen under %s gaze!", 2833. s_suffix(mon_nam(mon))); 2834. } else if (Hallucination && rn2(4)) { 2835. pline("%s looks %s%s.", Monnam(mon), 2836. !rn2(2) ? "" : "rather ", 2837. !rn2(2) ? "numb" : "stupified"); 2838. } else { 2839. You("are frozen by %s gaze!", s_suffix(mon_nam(mon))); 2840. nomul((ACURR(A_WIS) > 12 || rn2(4)) ? -tmp : -127); 2841. multi_reason = "frozen by a monster's gaze"; 2842. nomovemsg = 0; 2843. } 2844. } else { 2845. pline("%s cannot defend itself.", 2846. Adjmonnam(mon, "blind")); 2847. if (!rn2(500)) 2848. change_luck(-1); 2849. } 2850. } else if (Free_action) { 2851. You("momentarily stiffen."); 2852. } else { /* gelatinous cube */ 2853. You("are frozen by %s!", mon_nam(mon)); 2854. nomovemsg = You_can_move_again; 2855. nomul(-tmp); 2856. multi_reason = "frozen by a monster"; 2857. exercise(A_DEX, FALSE); 2858. } 2859. break; 2860. case AD_COLD: /* brown mold or blue jelly */ 2861. if (monnear(mon, u.ux, u.uy)) { 2862. if (Cold_resistance) { 2863. shieldeff(u.ux, u.uy); 2864. You_feel("a mild chill."); 2865. ugolemeffects(AD_COLD, tmp); 2866. break; 2867. } 2868. You("are suddenly very cold!"); 2869. mdamageu(mon, tmp); 2870. /* monster gets stronger with your heat! */ 2871. mon->mhp += tmp / 2; 2872. if (mon->mhpmax < mon->mhp) 2873. mon->mhpmax = mon->mhp; 2874. /* at a certain point, the monster will reproduce! */ 2875. if (mon->mhpmax > ((int) (mon->m_lev + 1) * 8)) 2876. (void) split_mon(mon, &youmonst); 2877. } 2878. break; 2879. case AD_STUN: /* specifically yellow mold */ 2880. if (!Stunned) 2881. make_stunned((long) tmp, TRUE); 2882. break; 2883. case AD_FIRE: 2884. if (monnear(mon, u.ux, u.uy)) { 2885. if (Fire_resistance) { 2886. shieldeff(u.ux, u.uy); 2887. You_feel("mildly warm."); 2888. ugolemeffects(AD_FIRE, tmp); 2889. break; 2890. } 2891. You("are suddenly very hot!"); 2892. mdamageu(mon, tmp); /* fire damage */ 2893. } 2894. break; 2895. case AD_ELEC: 2896. if (Shock_resistance) { 2897. shieldeff(u.ux, u.uy); 2898. You_feel("a mild tingle."); 2899. ugolemeffects(AD_ELEC, tmp); 2900. break; 2901. } 2902. You("are jolted with electricity!"); 2903. mdamageu(mon, tmp); 2904. break; 2905. default: 2906. break; 2907. } 2908. } 2909. return (malive | mhit); 2910. } 2911. 2912. /* 2913. * Special (passive) attacks on an attacking object by monsters done here. 2914. * Assumes the attack was successful. 2915. */ 2916. void 2917. passive_obj(mon, obj, mattk) 2918. struct monst *mon; 2919. struct obj *obj; /* null means pick uwep, uswapwep or uarmg */ 2920. struct attack *mattk; /* null means we find one internally */ 2921. { 2922. struct permonst *ptr = mon->data; 2923. int i; 2924. 2925. /* [this first bit is obsolete; we're not called with Null anymore] */ 2926. /* if caller hasn't specified an object, use uwep, uswapwep or uarmg */ 2927. if (!obj) { 2928. obj = (u.twoweap && uswapwep && !rn2(2)) ? uswapwep : uwep; 2929. if (!obj && mattk->adtyp == AD_ENCH) 2930. obj = uarmg; /* no weapon? then must be gloves */ 2931. if (!obj) 2932. return; /* no object to affect */ 2933. } 2934. 2935. /* if caller hasn't specified an attack, find one */ 2936. if (!mattk) { 2937. for (i = 0;; i++) { 2938. if (i >= NATTK) 2939. return; /* no passive attacks */ 2940. if (ptr->mattk[i].aatyp == AT_NONE) 2941. break; /* try this one */ 2942. } 2943. mattk = &(ptr->mattk[i]); 2944. } 2945. 2946. switch (mattk->adtyp) { 2947. case AD_FIRE: 2948. if (!rn2(6) && !mon->mcan 2949. /* steam vortex: fire resist applies, fire damage doesn't */ 2950. && mon->data != &mons[PM_STEAM_VORTEX]) { 2951. (void) erode_obj(obj, NULL, ERODE_BURN, EF_NONE); 2952. } 2953. break; 2954. case AD_ACID: 2955. if (!rn2(6)) { 2956. (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_GREASE); 2957. } 2958. break; 2959. case AD_RUST: 2960. if (!mon->mcan) { 2961. (void) erode_obj(obj, (char *) 0, ERODE_RUST, EF_GREASE); 2962. } 2963. break; 2964. case AD_CORR: 2965. if (!mon->mcan) { 2966. (void) erode_obj(obj, (char *) 0, ERODE_CORRODE, EF_GREASE); 2967. } 2968. break; 2969. case AD_ENCH: 2970. if (!mon->mcan) { 2971. if (drain_item(obj, TRUE) && carried(obj) 2972. && (obj->known || obj->oclass == ARMOR_CLASS)) { 2973. pline("%s less effective.", Yobjnam2(obj, "seem")); 2974. } 2975. break; 2976. } 2977. default: 2978. break; 2979. } 2980. 2981. if (carried(obj)) 2982. update_inventory(); 2983. } 2984. 2985. /* Note: caller must ascertain mtmp is mimicking... */ 2986. void 2987. stumble_onto_mimic(mtmp) 2988. struct monst *mtmp; 2989. { 2990. const char *fmt = "Wait! That's %s!", *generic = "a monster", *what = 0; 2991. 2992. if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)) 2993. u.ustuck = mtmp; 2994. 2995. if (Blind) { 2996. if (!Blind_telepat) 2997. what = generic; /* with default fmt */ 2998. else if (M_AP_TYPE(mtmp) == M_AP_MONSTER) 2999. what = a_monnam(mtmp); /* differs from what was sensed */ 3000. } else { 3001. int glyph = levl[u.ux + u.dx][u.uy + u.dy].glyph; 3002. 3003. if (glyph_is_cmap(glyph) && (glyph_to_cmap(glyph) == S_hcdoor 3004. || glyph_to_cmap(glyph) == S_vcdoor)) 3005. fmt = "The door actually was %s!"; 3006. else if (glyph_is_object(glyph) && glyph_to_obj(glyph) == GOLD_PIECE) 3007. fmt = "That gold was %s!"; 3008. 3009. /* cloned Wiz starts out mimicking some other monster and 3010. might make himself invisible before being revealed */ 3011. if (mtmp->minvis && !See_invisible) 3012. what = generic; 3013. else 3014. what = a_monnam(mtmp); 3015. } 3016. if (what) 3017. pline(fmt, what); 3018. 3019. wakeup(mtmp, FALSE); /* clears mimicking */ 3020. /* if hero is blind, wakeup() won't display the monster even though 3021. it's no longer concealed */ 3022. if (!canspotmon(mtmp) 3023. && !glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) 3024. map_invisible(mtmp->mx, mtmp->my); 3025. } 3026. 3027. STATIC_OVL void 3028. nohandglow(mon) 3029. struct monst *mon; 3030. { 3031. char *hands = makeplural(body_part(HAND)); 3032. 3033. if (!u.umconf || mon->mconf) 3034. return; 3035. if (u.umconf == 1) { 3036. if (Blind) 3037. Your("%s stop tingling.", hands); 3038. else 3039. Your("%s stop glowing %s.", hands, hcolor(NH_RED)); 3040. } else { 3041. if (Blind) 3042. pline_The("tingling in your %s lessens.", hands); 3043. else 3044. Your("%s no longer glow so brightly %s.", hands, hcolor(NH_RED)); 3045. } 3046. u.umconf--; 3047. } 3048. 3049. int 3050. flash_hits_mon(mtmp, otmp) 3051. struct monst *mtmp; 3052. struct obj *otmp; /* source of flash */ 3053. { 3054. int tmp, amt, res = 0, useeit = canseemon(mtmp); 3055. 3056. if (mtmp->msleeping) { 3057. mtmp->msleeping = 0; 3058. if (useeit) { 3059. pline_The("flash awakens %s.", mon_nam(mtmp)); 3060. res = 1; 3061. } 3062. } else if (mtmp->data->mlet != S_LIGHT) { 3063. if (!resists_blnd(mtmp)) { 3064. tmp = dist2(otmp->ox, otmp->oy, mtmp->mx, mtmp->my); 3065. if (useeit) { 3066. pline("%s is blinded by the flash!", Monnam(mtmp)); 3067. res = 1; 3068. } 3069. if (mtmp->data == &mons[PM_GREMLIN]) { 3070. /* Rule #1: Keep them out of the light. */ 3071. amt = otmp->otyp == WAN_LIGHT ? d(1 + otmp->spe, 4) 3072. : rn2(min(mtmp->mhp, 4)); 3073. light_hits_gremlin(mtmp, amt); 3074. } 3075. if (!DEADMONSTER(mtmp)) { 3076. if (!context.mon_moving) 3077. setmangry(mtmp, TRUE); 3078. if (tmp < 9 && !mtmp->isshk && rn2(4)) 3079. monflee(mtmp, rn2(4) ? rnd(100) : 0, FALSE, TRUE); 3080. mtmp->mcansee = 0; 3081. mtmp->mblinded = (tmp < 3) ? 0 : rnd(1 + 50 / tmp); 3082. } 3083. } 3084. } 3085. return res; 3086. } 3087. 3088. void 3089. light_hits_gremlin(mon, dmg) 3090. struct monst *mon; 3091. int dmg; 3092. { 3093. pline("%s %s!", Monnam(mon), 3094. (dmg > mon->mhp / 2) ? "wails in agony" : "cries out in pain"); 3095. mon->mhp -= dmg; 3096. wake_nearto(mon->mx, mon->my, 30); 3097. if (DEADMONSTER(mon)) { 3098. if (context.mon_moving) 3099. monkilled(mon, (char *) 0, AD_BLND); 3100. else 3101. killed(mon); 3102. } else if (cansee(mon->mx, mon->my) && !canspotmon(mon)) { 3103. map_invisible(mon->mx, mon->my); 3104. } 3105. } 3106. 3107. /*uhitm.c*/