Source:NetHack 5.0.0/src/uhitm.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to uhitm.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/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 5.0	uhitm.c	$NHDT-Date: 1752823766 2025/07/17 23:29:26 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.477 $ */
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 const char brief_feeling[] =
9.     "have a %s feeling for a moment, then it passes.";
10. 
11. staticfn boolean mhitm_mgc_atk_negated(struct monst *, struct monst *,
12.                                      boolean) NONNULLPTRS;
13. staticfn boolean known_hitum(struct monst *, struct obj *, int *, int, int,
14.                            struct attack *, int) NONNULLARG13;
15. staticfn boolean theft_petrifies(struct obj *) NONNULLARG1;
16. staticfn void mhitm_really_poison(struct monst *, struct attack *,
17.                                   struct monst *, struct mhitm_data *);
18. staticfn void steal_it(struct monst *, struct attack *) NONNULLARG1;
19. /* hitum_cleave() has contradictory information. There's a comment
20.  * beside the 1st arg 'target' stating non-null, but later on there
21.  * is a test for 'target' being null */
22. staticfn boolean hitum_cleave(struct monst *, struct attack *) NO_NNARGS;
23. staticfn boolean double_punch(void);
24. staticfn boolean hitum(struct monst *, struct attack *) NONNULLARG1;
25. staticfn void hmon_hitmon_barehands(struct _hitmon_data *,
26.                              struct monst *) NONNULLARG12;
27. staticfn void hmon_hitmon_weapon_ranged(struct _hitmon_data *, struct monst *,
28.                              struct obj *) NONNULLARG123;
29. staticfn boolean backstabbable(struct monst *) NONNULLARG1;
30. staticfn void hmon_hitmon_weapon_melee(struct _hitmon_data *, struct monst *,
31.                              struct obj *) NONNULLARG123;
32. staticfn void hmon_hitmon_weapon(struct _hitmon_data *, struct monst *,
33.                              struct obj *) NONNULLARG123;
34. staticfn void hmon_hitmon_potion(struct _hitmon_data *, struct monst *,
35.                              struct obj *) NONNULLARG123;
36. staticfn void hmon_hitmon_misc_obj(struct _hitmon_data *, struct monst *,
37.                              struct obj *) NONNULLARG123;
38. staticfn void hmon_hitmon_do_hit(struct _hitmon_data *, struct monst *,
39.                              struct obj *) NONNULLARG12;
40. staticfn void hmon_hitmon_dmg_recalc(struct _hitmon_data *, struct obj *);
41. staticfn void hmon_hitmon_poison(struct _hitmon_data *, struct monst *,
42.                              struct obj *) NONNULLARG123;
43. staticfn void hmon_hitmon_jousting(struct _hitmon_data *, struct monst *,
44.                              struct obj *) NONNULLARG123;
45. staticfn void hmon_hitmon_stagger(struct _hitmon_data *, struct monst *,
46.                              struct obj *) NONNULLARG12;
47. staticfn void hmon_hitmon_pet(struct _hitmon_data *, struct monst *,
48.                              struct obj *) NONNULLARG12;
49. staticfn void hmon_hitmon_splitmon(struct _hitmon_data *, struct monst *,
50.                              struct obj *) NONNULLARG12;
51. staticfn void hmon_hitmon_msg_hit(struct _hitmon_data *, struct monst *,
52.                              struct obj *) NONNULLARG12;
53. staticfn void hmon_hitmon_msg_silver(struct _hitmon_data *, struct monst *,
54.                              struct obj *) NONNULLARG12;
55. staticfn void hmon_hitmon_msg_lightobj(struct _hitmon_data *, struct monst *,
56.                              struct obj *) NONNULLARG12;
57. staticfn boolean hmon_hitmon(struct monst *, struct obj *, int, int)
58.                              NONNULLARG1;
59. staticfn int joust(struct monst *, struct obj *) NONNULLARG12;
60. staticfn void demonpet(void);
61. staticfn boolean m_slips_free(struct monst *, struct attack *) NONNULLPTRS;
62. staticfn void start_engulf(struct monst *) NONNULLARG1;
63. staticfn void end_engulf(void);
64. staticfn int gulpum(struct monst *, struct attack *) NONNULLPTRS;
65. staticfn boolean hmonas(struct monst *) NONNULLARG1;
66. staticfn void nohandglow(struct monst *) NONNULLARG1;
67. staticfn boolean mhurtle_to_doom(struct monst *, int,
68.                              struct permonst **) NONNULLARG13;
69. staticfn void first_weapon_hit(struct obj *) NONNULLARG1;
70. staticfn boolean shade_aware(struct obj *) NO_NNARGS;
71. 
72. #define PROJECTILE(obj) ((obj) && is_ammo(obj))
73. 
74. staticfn boolean
75. mhitm_mgc_atk_negated(
76.     struct monst *magr, struct monst *mdef,
77.     boolean verbosely) /* give mesg if magical cancellation prevents damage */
78. {
79.     int armpro;
80.     boolean negated;
81. 
82.     /* mcan doesn't apply to youmonst; hero can't be cancelled */
83.     if (magr != &gy.youmonst && magr->mcan)
84.         return TRUE; /* no message if attacker has been cancelled */
85. 
86.     armpro = magic_negation(mdef);
87.     negated = !(rn2(10) >= 3 * armpro);
88.     if (negated) {
89.         /* attack has been thwarted by negation, aka magical cancellation */
90.         if (verbosely) {
91.             if (mdef == &gy.youmonst)
92.                 You("avoid harm.");
93.             else if (gv.vis && canseemon(mdef))
94.                 pline_mon(mdef, "%s avoids harm.", Monnam(mdef));
95.         }
96.         return TRUE;
97.     }
98.     return FALSE;
99. }
100. 
101. /* multi_reason is usually a literal string; here we generate one that
102.    has the causing monster's type included */
103. void
104. dynamic_multi_reason(struct monst *mon, const char *verb, boolean by_gaze)
105. {
106.     /* combination of noname_monnam() and m_monnam(), more or less;
107.        accurate regardless of visibility or hallucination (only seen
108.        if game ends) and without personal name (M2_PNAME excepted) */
109.     char *who = x_monnam(mon, ARTICLE_A, (char *) 0,
110.                          (SUPPRESS_IT | SUPPRESS_INVISIBLE
111.                           | SUPPRESS_HALLUCINATION | SUPPRESS_SADDLE
112.                           | SUPPRESS_NAME),
113.                          FALSE),
114.          *p = gm.multireasonbuf;
115. 
116.     /* prefix info for done_in_by() */
117.     Sprintf(p, "%u:", mon->m_id);
118.     p = eos(p);
119.     Sprintf(p, "%s by %s%s", verb,
120.             !by_gaze ? who : s_suffix(who),
121.             !by_gaze ? "" : " gaze");
122.     gm.multi_reason = p;
123. }
124. 
125. void
126. erode_armor(struct monst *mdef, int hurt)
127. {
128.     struct obj *target;
129. 
130.     /* What the following code does: it keeps looping until it
131.      * finds a target for the rust monster.
132.      * Head, feet, etc... not covered by metal, or covered by
133.      * rusty metal, are not targets.  However, your body always
134.      * is, no matter what covers it.
135.      */
136.     while (1) {
137.         switch (rn2(5)) {
138.         case 0:
139.             target = which_armor(mdef, W_ARMH);
140.             if (!target
141.                 || erode_obj(target, xname(target), hurt, EF_GREASE)
142.                        == ER_NOTHING)
143.                 continue;
144.             break;
145.         case 1:
146.             target = which_armor(mdef, W_ARMC);
147.             if (target) {
148.                 (void) erode_obj(target, xname(target), hurt,
149.                                  EF_GREASE | EF_VERBOSE);
150.                 break;
151.             }
152.             if ((target = which_armor(mdef, W_ARM)) != (struct obj *) 0) {
153.                 (void) erode_obj(target, xname(target), hurt,
154.                                  EF_GREASE | EF_VERBOSE);
155.             } else if ((target = which_armor(mdef, W_ARMU))
156.                        != (struct obj *) 0) {
157.                 (void) erode_obj(target, xname(target), hurt,
158.                                  EF_GREASE | EF_VERBOSE);
159.             }
160.             break;
161.         case 2:
162.             target = which_armor(mdef, W_ARMS);
163.             if (!target
164.                 || erode_obj(target, xname(target), hurt, EF_GREASE)
165.                        == ER_NOTHING)
166.                 continue;
167.             break;
168.         case 3:
169.             target = which_armor(mdef, W_ARMG);
170.             if (!target
171.                 || erode_obj(target, xname(target), hurt, EF_GREASE)
172.                        == ER_NOTHING)
173.                 continue;
174.             break;
175.         case 4:
176.             target = which_armor(mdef, W_ARMF);
177.             if (!target
178.                 || erode_obj(target, xname(target), hurt, EF_GREASE)
179.                        == ER_NOTHING)
180.                 continue;
181.             break;
182.         }
183.         break; /* Out of while loop */
184.     }
185. }
186. 
187. /* FALSE means it's OK to attack */
188. boolean
189. attack_checks(
190.     struct monst *mtmp, /* target */
191.     struct obj *wep)    /* uwep for do_attack(), null for kick_monster() */
192. {
193.     int glyph;
194. 
195.     /* if you're close enough to attack, alert any waiting monster */
196.     mtmp->mstrategy &= ~STRAT_WAITMASK;
197. 
198.     if (engulfing_u(mtmp))
199.         return FALSE;
200. 
201.     if (svc.context.forcefight) {
202.         /* Do this in the caller, after we have checked that the monster
203.          * didn't die from the blow.  Reason: putting the 'I' there
204.          * causes the hero to forget the square's contents since
205.          * both 'I' and remembered contents are stored in .glyph.
206.          * If the monster dies immediately from the blow, the 'I' will
207.          * not stay there, so the player will have suddenly forgotten
208.          * the square's contents for no apparent reason.
209.         if (!canspotmon(mtmp)
210.             && !glyph_is_invisible(levl[gb.bhitpos.x][gb.bhitpos.y].glyph))
211.             map_invisible(gb.bhitpos.x, gb.bhitpos.y);
212.          */
213.         return FALSE;
214.     }
215. 
216.     /* cache the shown glyph;
217.        cases which might change it (by placing or removing
218.        'remembered, unseen monster' glyph or revealing a mimic)
219.        always return without further reference to this */
220.     glyph = glyph_at(gb.bhitpos.x, gb.bhitpos.y);
221. 
222.     /* Put up an invisible monster marker, but with exceptions for
223.      * monsters that hide and monsters you've been warned about.
224.      * The former already prints a warning message and
225.      * prevents you from hitting the monster just via the hidden monster
226.      * code below; if we also did that here, similar behavior would be
227.      * happening two turns in a row.  The latter shows a glyph on
228.      * the screen, so you know something is there.
229.      */
230.     if (!canspotmon(mtmp)
231.         && !glyph_is_warning(glyph) && !glyph_is_invisible(glyph)
232.         && !(!Blind && mtmp->mundetected && hides_under(mtmp->data))) {
233.         pline("Wait!  There's %s there you can't see!", something);
234.         map_invisible(gb.bhitpos.x, gb.bhitpos.y);
235.         /* if it was an invisible mimic, treat it as if we stumbled
236.          * onto a visible mimic
237.          */
238.         if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers) {
239.             if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
240.                 /* applied pole-arm attack is too far to get stuck */
241.                 && m_next2u(mtmp))
242.                 set_ustuck(mtmp);
243.         }
244.         /* #H7329 - if hero is on engraved "Elbereth", this will end up
245.          * assessing an alignment penalty and removing the engraving
246.          * even though no attack actually occurs.  Since it also angers
247.          * peacefuls, we're operating as if an attack attempt did occur
248.          * and the Elbereth behavior is consistent.
249.          */
250.         wakeup(mtmp, TRUE); /* always necessary; also un-mimics mimics */
251.         return TRUE;
252.     }
253. 
254.     if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers && !sensemon(mtmp)
255.         && !glyph_is_warning(glyph)) {
256.         /* If a hidden mimic was in a square where a player remembers
257.          * some (probably different) unseen monster, the player is in
258.          * luck--he attacks it even though it's hidden.
259.          */
260.         if (glyph_is_invisible(glyph)) {
261.             seemimic(mtmp);
262.             return FALSE;
263.         }
264.         stumble_onto_mimic(mtmp);
265.         return TRUE;
266.     }
267. 
268.     if (mtmp->mundetected && !canseemon(mtmp)
269.         && !glyph_is_warning(glyph)
270.         && (hides_under(mtmp->data) || mtmp->data->mlet == S_EEL)) {
271.         mtmp->mundetected = mtmp->msleeping = 0;
272.         newsym(mtmp->mx, mtmp->my);
273.         if (glyph_is_invisible(glyph)) {
274.             seemimic(mtmp);
275.             return FALSE;
276.         }
277.         if (!tp_sensemon(mtmp) && !Detect_monsters) {
278.             struct obj *obj;
279.             char lmonbuf[BUFSZ];
280.             boolean notseen;
281. 
282.             Strcpy(lmonbuf, l_monnam(mtmp));
283.             /* might be unseen if invisible and hero can't see invisible */
284.             notseen = !strcmp(lmonbuf, "it"); /* note: not strcmpi() */
285.             if (!Blind && Hallucination)
286.                 pline("A %s %s %s!", mtmp->mtame ? "tame" : "wild",
287.                       notseen ? "creature" : (const char *) lmonbuf,
288.                       notseen ? "is present" : "appears");
289.             else if (Blind || (is_pool(mtmp->mx, mtmp->my) && !Underwater))
290.                 pline("Wait!  There's a hidden monster there!");
291.             else if ((obj = svl.level.objects[mtmp->mx][mtmp->my]) != 0)
292.                 pline("Wait!  There's %s hiding under %s!",
293.                       notseen ? something : (const char *) an(lmonbuf),
294.                       doname(obj));
295.             return TRUE;
296.         }
297.     }
298. 
299.     /*
300.      * make sure to wake up a monster from the above cases if the
301.      * hero can sense that the monster is there.
302.      */
303.     if ((mtmp->mundetected || M_AP_TYPE(mtmp)) && sensemon(mtmp)) {
304.         mtmp->mundetected = 0;
305.         wakeup(mtmp, TRUE);
306.     }
307. 
308.     if (flags.confirm && mtmp->mpeaceful
309.         && !Confusion && !Hallucination && !Stunned) {
310.         /* Intelligent chaotic weapons (Stormbringer) want blood */
311.         if (is_art(wep, ART_STORMBRINGER)) {
312.             go.override_confirmation = TRUE;
313.             return FALSE;
314.         }
315.         if (canspotmon(mtmp)) {
316.             char qbuf[QBUFSZ];
317. 
318.             Sprintf(qbuf, "Really attack %s?", mon_nam(mtmp));
319.             if (!paranoid_query(ParanoidHit, qbuf)) {
320.                 svc.context.move = 0;
321.                 return TRUE;
322.             }
323.         }
324.     }
325. 
326.     return FALSE;
327. }
328. 
329. /* it is unchivalrous for a knight to attack the defenseless or from behind */
330. void
331. check_caitiff(struct monst *mtmp)
332. {
333.     if (u.ualign.record <= -10)
334.         return;
335. 
336.     if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL
337.         && !is_undead(mtmp->data)
338.         && (helpless(mtmp)
339.             || (mtmp->mflee && !mtmp->mavenge))) {
340.         You("caitiff!");
341.         adjalign(-1);
342.     } else if (Role_if(PM_SAMURAI) && mtmp->mpeaceful) {
343.         /* attacking peaceful creatures is bad for the samurai's giri */
344.         You("dishonorably attack the innocent!");
345.         adjalign(-1);
346.     }
347. }
348. 
349. /* maybe unparalyze monster */
350. void
351. mon_maybe_unparalyze(struct monst *mtmp)
352. {
353.     if (!mtmp->mcanmove) {
354.         if (!rn2(10)) {
355.             mtmp->mcanmove = 1;
356.             mtmp->mfrozen = 0;
357.         }
358.     }
359. }
360. 
361. /* how easy it is for hero to hit a monster,
362.    using attack type aatyp and/or weapon.
363.    larger value == easier to hit */
364. int
365. find_roll_to_hit(
366.     struct monst *mtmp,
367.     uchar aatyp,        /* usually AT_WEAP or AT_KICK */
368.     struct obj *weapon, /* uwep or uswapwep or NULL */
369.     int *attk_count,
370.     int *role_roll_penalty)
371. {
372.     int tmp, tmp2;
373. 
374.     *role_roll_penalty = 0; /* default is `none' */
375. 
376.     tmp = 1 + abon() + find_mac(mtmp) + u.uhitinc
377.           + (sgn(Luck) * ((abs(Luck) + 2) / 3))
378.           + maybe_polyd(gy.youmonst.data->mlevel, u.ulevel);
379. 
380.     /* some actions should occur only once during multiple attacks */
381.     if (!(*attk_count)++) {
382.         /* knight's chivalry or samurai's giri */
383.         check_caitiff(mtmp);
384.     }
385. 
386.     /* adjust vs. monster state */
387.     if (mtmp->mstun)
388.         tmp += 2;
389.     if (mtmp->mflee)
390.         tmp += 2;
391.     if (mtmp->msleeping)
392.         tmp += 2;
393.     if (!mtmp->mcanmove)
394.         tmp += 4;
395. 
396.     /* role/race adjustments */
397.     if (Role_if(PM_MONK) && !Upolyd) {
398.         if (uarm)
399.             tmp -= (*role_roll_penalty = gu.urole.spelarmr);
400.         else if (!uwep && !uarms)
401.             tmp += (u.ulevel / 3) + 2;
402.     }
403.     if (is_orc(mtmp->data)
404.         && maybe_polyd(is_elf(gy.youmonst.data), Race_if(PM_ELF)))
405.         tmp++;
406. 
407.     /* encumbrance: with a lot of luggage, your agility diminishes */
408.     if ((tmp2 = near_capacity()) != 0)
409.         tmp -= (tmp2 * 2) - 1;
410.     if (u.utrap)
411.         tmp -= 3;
412. 
413.     /*
414.      * hitval applies if making a weapon attack while wielding a weapon;
415.      * weapon_hit_bonus applies if doing a weapon attack even bare-handed
416.      * or if kicking as martial artist
417.      */
418.     if (aatyp == AT_WEAP || aatyp == AT_CLAW) {
419.         if (weapon)
420.             tmp += hitval(weapon, mtmp);
421.         tmp += weapon_hit_bonus(weapon);
422.     } else if (aatyp == AT_KICK && martial_bonus()) {
423.         tmp += weapon_hit_bonus((struct obj *) 0);
424.     }
425. 
426.     return tmp;
427. }
428. 
429. /* temporarily override 'safepet' (by faking use of 'F' prefix) when possibly
430.    unintentionally attacking peaceful monsters and optionally pets */
431. boolean
432. force_attack(struct monst *mtmp, boolean pets_too)
433. {
434.     boolean attacked, save_Forcefight;
435. 
436.     save_Forcefight = svc.context.forcefight;
437.     /* always set forcefight On for hostiles and peacefuls, maybe for pets */
438.     if (pets_too || !mtmp->mtame)
439.         svc.context.forcefight = TRUE;
440.     attacked = do_attack(mtmp);
441.     svc.context.forcefight = save_Forcefight;
442.     return attacked;
443. }
444. 
445. /* try to attack; return False if monster evaded;
446.    u.dx and u.dy must be set */
447. boolean
448. do_attack(struct monst *mtmp)
449. {
450.     struct permonst *mdat = mtmp->data;
451. 
452.     /* This section of code provides protection against accidentally
453.      * hitting peaceful (like '@') and tame (like 'd') monsters.
454.      * Protection is provided as long as player is not: blind, confused,
455.      * hallucinating or stunned.
456.      * changes by wwp 5/16/85
457.      * More changes 12/90, -dkh-. if its tame and safepet, (and protected
458.      * 07/92) then we assume that you're not trying to attack. Instead,
459.      * you'll usually just swap places if this is a movement command
460.      */
461.     /* Intelligent chaotic weapons (Stormbringer) want blood */
462.     if (is_safemon(mtmp) && !svc.context.forcefight) {
463.         if (!u_wield_art(ART_STORMBRINGER)) {
464.             /* There are some additional considerations: this won't work
465.              * if in a shop or Punished or you miss a random roll or
466.              * if you can walk thru walls and your pet cannot (KAA) or
467.              * if your pet is a long worm with a tail.
468.              * There's also a chance of displacing a "frozen" monster:
469.              * sleeping monsters might magically walk in their sleep.
470.              * This block of code used to only be called for pets; now
471.              * that it also applies to peacefuls, non-pets mustn't be
472.              * forced to flee.
473.              */
474.             boolean foo = (Punished || !rn2(7)
475.                            || (is_longworm(mtmp->data) && mtmp->wormno)
476.                            || (IS_OBSTRUCTED(levl[u.ux][u.uy].typ)
477.                                && !passes_walls(mtmp->data))),
478.                     inshop = FALSE;
479.             char *p;
480. 
481.             /* only check for in-shop if don't already have reason to stop */
482.             if (!foo) {
483.                 for (p = in_rooms(mtmp->mx, mtmp->my, SHOPBASE); *p; p++)
484.                     if (tended_shop(&svr.rooms[*p - ROOMOFFSET])) {
485.                         inshop = TRUE;
486.                         break;
487.                     }
488.             }
489.             if (inshop || foo) {
490.                 char buf[BUFSZ];
491. 
492.                 if (!svc.context.travel && !svc.context.run)
493.                     if (canspotmon(mtmp) && mtmp->isshk)
494.                         return ECMD_TIME | dopay();
495. 
496.                 if (mtmp->mtame) /* see 'additional considerations' above */
497.                     monflee(mtmp, rnd(6), FALSE, FALSE);
498.                 Strcpy(buf, y_monnam(mtmp));
499.                 buf[0] = highc(buf[0]);
500.                 You("stop.  %s is in the way!", buf);
501.                 end_running(TRUE);
502.                 return TRUE;
503.             } else if (mtmp->mfrozen || helpless(mtmp)
504.                        || (mtmp->data->mmove == 0 && rn2(6))) {
505.                 pline("%s doesn't seem to move!", Monnam(mtmp));
506.                 end_running(TRUE);
507.                 return TRUE;
508.             } else
509.                 return FALSE;
510.         }
511.     }
512. 
513.     /* possibly set in attack_checks;
514.        examined in known_hitum, called via hitum or hmonas below */
515.     go.override_confirmation = FALSE;
516.     /* attack_checks() used to use <u.ux+u.dx,u.uy+u.dy> directly, now
517.        it uses gb.bhitpos instead; it might map an invisible monster there */
518.     gb.bhitpos.x = u.ux + u.dx;
519.     gb.bhitpos.y = u.uy + u.dy;
520.     gn.notonhead = (gb.bhitpos.x != mtmp->mx || gb.bhitpos.y != mtmp->my);
521.     if (attack_checks(mtmp, uwep))
522.         return TRUE;
523. 
524.     if (Upolyd && noattacks(gy.youmonst.data)) {
525.         /* certain "pacifist" monsters don't attack */
526.         You("have no way to attack monsters physically.");
527.         mtmp->mstrategy &= ~STRAT_WAITMASK;
528.         goto atk_done;
529.     }
530. 
531.     if (check_capacity("You cannot fight while so heavily loaded.")
532.         /* consume extra nutrition during combat; maybe pass out */
533.         || overexertion())
534.         goto atk_done;
535. 
536.     if (u.twoweap && !can_twoweapon())
537.         untwoweapon();
538. 
539.     if (gu.unweapon) {
540.         gu.unweapon = FALSE;
541.         if (flags.verbose) {
542.             if (uwep)
543.                 You("begin bashing monsters with %s.", yname(uwep));
544.             else if (!cantwield(gy.youmonst.data))
545.                 You("begin %s monsters with your %s %s.",
546.                     ing_suffix(Role_if(PM_MONK) ? "strike" : "bash"),
547.                     uarmg ? "gloved" : "bare", /* Del Lamb */
548.                     makeplural(body_part(HAND)));
549.         }
550.     }
551.     exercise(A_STR, TRUE); /* you're exercising muscles */
552.     /* andrew@orca: prevent unlimited pick-axe attacks */
553.     u_wipe_engr(3);
554. 
555.     /* Is the "it died" check actually correct? */
556.     if (mdat->mlet == S_LEPRECHAUN && !mtmp->mfrozen && !helpless(mtmp)
557.         && !mtmp->mconf && mtmp->mcansee && !rn2(7)
558.         && (m_move(mtmp, 0) == MMOVE_DIED /* it died */
559.             || mtmp->mx != u.ux + u.dx
560.             || mtmp->my != u.uy + u.dy)) { /* it moved */
561.         You("miss wildly and stumble forwards.");
562.         return FALSE;
563.     }
564. 
565.     if (Upolyd)
566.         (void) hmonas(mtmp);
567.     else
568.         (void) hitum(mtmp, gy.youmonst.data->mattk);
569.     mtmp->mstrategy &= ~STRAT_WAITMASK;
570. 
571.  atk_done:
572.     /* see comment in attack_checks() */
573.     /* we only need to check for this if we did an attack_checks()
574.      * and it returned 0 (it's okay to attack), and the monster didn't
575.      * evade.
576.      */
577.     if (svc.context.forcefight && !DEADMONSTER(mtmp) && !canspotmon(mtmp)
578.         && !glyph_is_invisible(levl[u.ux + u.dx][u.uy + u.dy].glyph)
579.         && !engulfing_u(mtmp))
580.         map_invisible(u.ux + u.dx, u.uy + u.dy);
581. 
582.     return TRUE;
583. }
584. 
585. /* really hit target monster; returns TRUE if it still lives */
586. staticfn boolean
587. known_hitum(
588.     struct monst *mon,  /* target */
589.     struct obj *weapon, /* uwep or uswapwep */
590.     int *mhit,          /* *mhit is 1 or 0; hit (1) gets changed to miss (0)
591.                          * for decapitation attack against headless target */
592.     int rollneeded,     /* rollneeded and armorpenalty are used for monks  +*/
593.     int armorpenalty,   /*+ wearing suits so miss message can vary for missed
594.                          *  because of penalty vs would have missed anyway  */
595.     struct attack *uattk,
596.     int dieroll)
597. {
598.     boolean malive = TRUE,
599.             /* hmon() might destroy weapon; remember aspect for cutworm */
600.             slice_or_chop = (weapon && (is_blade(weapon) || is_axe(weapon)));
601. 
602.     if (go.override_confirmation) {
603.         /* this may need to be generalized if weapons other than
604.            Stormbringer acquire similar anti-social behavior... */
605.         if (flags.verbose)
606.             Your("bloodthirsty blade attacks!");
607.     }
608. 
609.     if (!*mhit) {
610.         missum(mon, uattk, (rollneeded + armorpenalty > dieroll));
611.     } else {
612.         int oldhp = mon->mhp;
613.         long oldweaphit = u.uconduct.weaphit;
614. 
615.         /* KMH, conduct */
616.         if (weapon && (weapon->oclass == WEAPON_CLASS || is_weptool(weapon)))
617.             u.uconduct.weaphit++;
618. 
619.         /* we hit the monster; be careful: it might die or
620.            be knocked into a different location */
621.         gn.notonhead = (mon->mx != gb.bhitpos.x || mon->my != gb.bhitpos.y);
622.         malive = hmon(mon, weapon, HMON_MELEE, dieroll);
623.         if (malive) {
624.             /* monster still alive */
625.             if (!rn2(25) && mon->mhp < mon->mhpmax / 2
626.                 && !engulfing_u(mon)) {
627.                 /* maybe should regurgitate if swallowed? */
628.                 monflee(mon, !rn2(3) ? rnd(100) : 0, FALSE, TRUE);
629. 
630.                 if (u.ustuck == mon && !u.uswallow
631.                     && !sticks(gy.youmonst.data))
632.                     set_ustuck((struct monst *) 0);
633.             }
634.             /* Vorpal Blade hit converted to miss */
635.             /* could be headless monster or worm tail */
636.             if (mon->mhp == oldhp) {
637.                 *mhit = 0;
638.                 /* a miss does not break conduct */
639.                 u.uconduct.weaphit = oldweaphit;
640.             }
641.             if (mon->wormno && *mhit)
642.                 cutworm(mon, gb.bhitpos.x, gb.bhitpos.y, slice_or_chop);
643.         }
644.     }
645.     return malive;
646. }
647. 
648. /* hit the monster next to you and the monsters to the left and right of it;
649.    return False if the primary target is killed, True otherwise */
650. staticfn boolean
651. hitum_cleave(
652.     struct monst *target, /* non-Null; forcefight at nothing doesn't cleave +*/
653.     struct attack *uattk) /*+ but we don't enforce that here; Null works ok */
654. {
655.     /* swings will be delivered in alternate directions; with consecutive
656.        attacks it will simulate normal swing and backswing; when swings
657.        are non-consecutive, hero will sometimes start a series of attacks
658.        with a backswing--that doesn't impact actual play, just spoils the
659.        simulation attempt a bit */
660.     static boolean clockwise = FALSE;
661.     int i;
662.     coord save_bhitpos;
663.     boolean save_notonhead;
664.     int count, umort, x = u.ux, y = u.uy;
665. 
666.     /* find the direction toward primary target */
667.     i = xytodir(u.dx, u.dy);
668.     if (i == DIR_ERR) {
669.         impossible("hitum_cleave: unknown target direction [%d,%d,%d]?",
670.                    u.dx, u.dy, u.dz);
671.         return TRUE; /* target hasn't been killed */
672.     }
673.     /* adjust direction by two so that loop's increment (for clockwise)
674.        or decrement (for counter-clockwise) will point at the spot next
675.        to primary target */
676.     i = clockwise ? DIR_LEFT2(i) : DIR_RIGHT2(i);
677.     umort = u.umortality; /* used to detect life-saving */
678.     save_bhitpos = gb.bhitpos;
679.     save_notonhead = gn.notonhead;
680. 
681.     /*
682.      * Three attacks:  adjacent to primary, primary, adjacent on other
683.      * side.  Primary target must be present or we wouldn't have gotten
684.      * here (forcefight at thin air won't 'cleave').  However, the
685.      * first attack might kill it (gas spore explosion, weak long worm
686.      * occupying both spots) so we don't assume that it's still present
687.      * on the second attack.
688.      */
689.     for (count = 3; count > 0; --count) {
690.         struct monst *mtmp;
691.         int tx, ty, tmp, dieroll, mhit, attknum = 0, armorpenalty;
692. 
693.         /* ++i, wrap 8 to i=0 /or/ --i, wrap -1 to i=7 */
694.         i = clockwise ? DIR_RIGHT(i) : DIR_LEFT(i);
695. 
696.         tx = x + xdir[i], ty = y + ydir[i]; /* current target location */
697.         if (!isok(tx, ty))
698.             continue;
699.         mtmp = m_at(tx, ty);
700.         if (!mtmp) {
701.             if (glyph_is_invisible(levl[tx][ty].glyph))
702.                 (void) unmap_invisible(tx, ty);
703.             continue;
704.         }
705. 
706.         tmp = find_roll_to_hit(mtmp, uattk->aatyp, uwep,
707.                                &attknum, &armorpenalty);
708.         mon_maybe_unparalyze(mtmp);
709.         dieroll = rnd(20);
710.         mhit = (tmp > dieroll);
711.         gb.bhitpos.x = tx, gb.bhitpos.y = ty; /* normally set by do_attack() */
712.         gn.notonhead = (mtmp->mx != tx || mtmp->my != ty);
713.         (void) known_hitum(mtmp, uwep, &mhit, tmp, armorpenalty,
714.                            uattk, dieroll);
715.         (void) passive(mtmp, uwep, mhit, !DEADMONSTER(mtmp), AT_WEAP, !uwep);
716. 
717.         /* stop attacking if weapon is gone or hero got paralyzed or
718.            killed (and then life-saved) by passive counter-attack */
719.         if (!uwep || gm.multi < 0 || u.umortality > umort)
720.             break;
721.     }
722.     /* set up for next time */
723.     clockwise = !clockwise; /* alternate */
724.     gb.bhitpos = save_bhitpos; /* in case somebody relies on bhitpos
725.                                 * designating the primary target */
726.     gn.notonhead = save_notonhead;
727. 
728.     /* return False if primary target died, True otherwise; note: if 'target'
729.        was nonNull upon entry then it's still nonNull even if *target died */
730.     return (target && DEADMONSTER(target)) ? FALSE : TRUE;
731. }
732. 
733. /* returns True if hero is fighting without a weapon and without a shield and
734.    has sufficient skill in bare-handed/martial arts to attack twice */
735. staticfn boolean
736. double_punch(void)
737. {
738.     /* note: P_BARE_HANDED_COMBAT and P_MARTIAL_ARTS are equivalent */
739.     int skl_lvl = P_SKILL(P_BARE_HANDED_COMBAT);
740. 
741.     /*
742.      * Chance to attempt a second bare-handed or martial arts hit:
743.      *  restricted  (0),        [not applicable; no one is restricted]
744.      *  unskilled   (1) :  0%
745.      *  basic       (2) :  0%
746.      *  skilled     (3) : 20%
747.      *  expert      (4) : 40%
748.      *  master      (5) : 60%
749.      *  grandmaster (6) : 80%
750.      */
751.     if (!uwep && !uarms && skl_lvl > P_BASIC)
752.         return (skl_lvl - P_BASIC) > rn2(5);
753.     return FALSE;
754. }
755. 
756. /* hit target monster; returns TRUE if it still lives */
757. staticfn boolean
758. hitum(struct monst *mon, struct attack *uattk)
759. {
760.     boolean malive, wep_was_destroyed = FALSE;
761.     struct obj *wepbefore = uwep,
762.         *secondwep = u.twoweap ? uswapwep : (struct obj *) 0;
763.     int tmp, dieroll, mhit, armorpenalty, attknum = 0,
764.         x = u.ux + u.dx, y = u.uy + u.dy, oldumort = u.umortality;
765. 
766.     /* Cleaver attacks three spots, 'mon' and one on either side of 'mon';
767.        it can't be part of dual-wielding but we guard against that anyway;
768.        cleave return value reflects status of primary target ('mon') */
769.     if (u_wield_art(ART_CLEAVER) && !u.twoweap
770.         && !u.uswallow && !u.ustuck && !NODIAG(u.umonnum))
771.         return hitum_cleave(mon, uattk);
772. 
773.     /* 0: single hit, 1: first of two hits; affects strength bonus and
774.        silver rings; known_hitum() -> hmon() -> hmon_hitmon() will copy
775.        gt.twohits into struct _hitmon_data hmd.twohits */
776.     gt.twohits = (uwep ? u.twoweap : double_punch()) ? 1 : 0;
777. 
778.     tmp = find_roll_to_hit(mon, uattk->aatyp, uwep, &attknum, &armorpenalty);
779.     mon_maybe_unparalyze(mon);
780.     dieroll = rnd(20);
781.     mhit = (tmp > dieroll || u.uswallow);
782.     if (tmp > dieroll)
783.         exercise(A_DEX, TRUE);
784. 
785.     /* gb.bhitpos is set up by caller */
786.     malive = known_hitum(mon, uwep, &mhit, tmp, armorpenalty, uattk, dieroll);
787.     if (wepbefore && !uwep)
788.         wep_was_destroyed = TRUE;
789.     (void) passive(mon, uwep, mhit, malive, AT_WEAP, wep_was_destroyed);
790. 
791.     /* second attack for two-weapon combat or skilled unarmed combat;
792.        won't occur if Stormbringer overrode confirmation (assumes
793.        Stormbringer is primary weapon), or if hero became paralyzed by
794.        passive counter-attack, or if hero was killed by passive
795.        counter-attack and got life-saved, or if monster was killed or
796.        knocked to different location */
797.     if (gt.twohits && !(go.override_confirmation
798.                         || gm.multi < 0 || u.umortality > oldumort
799.                         || !malive || m_at(x, y) != mon)) {
800.         gt.twohits = 2; /* second of 2 hits */
801.         tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, &attknum,
802.                                &armorpenalty);
803.         mon_maybe_unparalyze(mon);
804.         dieroll = rnd(20);
805.         mhit = (tmp > dieroll || u.uswallow);
806.         malive = known_hitum(mon, secondwep, &mhit, tmp, armorpenalty, uattk,
807.                              dieroll);
808.         /* second passive counter-attack only occurs if second attack hits */
809.         if (mhit)
810.             (void) passive(mon, secondwep, mhit, malive, AT_WEAP,
811.                            secondwep && !uswapwep);
812.     }
813.     gt.twohits = 0;
814.     return malive;
815. }
816. 
817. /* general "damage monster" routine; return True if mon still alive */
818. boolean
819. hmon(struct monst *mon,
820.      struct obj *obj,
821.      int thrown, /* HMON_xxx (0 => hand-to-hand, other => ranged) */
822.      int dieroll)
823. {
824.     boolean result, anger_guards;
825. 
826.     anger_guards = (mon->mpeaceful
827.                     && (mon->ispriest || mon->isshk || is_watch(mon->data)));
828.     result = hmon_hitmon(mon, obj, thrown, dieroll);
829.     if (mon->ispriest && !rn2(2))
830.         ghod_hitsu(mon);
831.     if (anger_guards)
832.         (void) angry_guards(!!Deaf);
833.     return result;
834. }
835. 
836. /* hero hits monster bare handed */
837. staticfn void
838. hmon_hitmon_barehands(struct _hitmon_data *hmd, struct monst *mon)
839. {
840.     long spcdmgflg, silverhit = 0L; /* worn masks */
841. 
842.     if (hmd->mdat == &mons[PM_SHADE]) {
843.         hmd->dmg = 0;
844.     } else {
845.         /* note: 1..2 or 1..4 can be substantially increased by
846.            strength bonus or skill bonus, usually both... */
847.         hmd->dmg = rnd(!martial_bonus() ? 2 : 4);
848.         hmd->use_weapon_skill = TRUE;
849.         hmd->train_weapon_skill = (hmd->dmg > 1);
850.     }
851. 
852.     /* Blessed gloves give bonuses when fighting 'bare-handed'.  So do
853.        silver rings.  Note:  rings are worn under gloves, so you don't
854.        get both bonuses, and two silver rings don't give double bonus.
855.        When making only one hit, both rings are checked (backwards
856.        compatibility => playability), but when making two hits, only the
857.        ring on the hand making the attack is checked. */
858.     spcdmgflg = uarmg ? W_ARMG
859.               : (((hmd->twohits == 0 || hmd->twohits == 1) ? W_RINGR : 0L)
860.                  | ((hmd->twohits == 0 || hmd->twohits == 2) ? W_RINGL : 0L));
861.     hmd->dmg += special_dmgval(&gy.youmonst, mon, spcdmgflg, &silverhit);
862. 
863.     /* copy silverhit info back into struct _hitmon_data *hmd */
864.     switch (hmd->twohits) {
865.     case 0: /* only one hit being attempted; a silver ring on either hand
866.              * applies but having silver rings on both is same as just one */
867.         hmd->barehand_silver_rings = (silverhit & (W_RINGR | W_RINGL)) ? 1 : 0;
868.         break;
869.     case 1: /* first of two or more hit attempts; right ring applies */
870.         hmd->barehand_silver_rings = (silverhit & W_RINGR) ? 1 : 0;
871.         break;
872.     case 2: /* second of two or more hit attempts; left ring applies */
873.         hmd->barehand_silver_rings = (silverhit & W_RINGL) ? 1 : 0;
874.         break;
875.     default: /* third or later of more than two hit attempts (poly'd hero);
876.               * rings were applied on first and second hits */
877.         hmd->barehand_silver_rings = 0;
878.         break;
879.     }
880.     if (hmd->barehand_silver_rings > 0)
881.         hmd->silvermsg = TRUE;
882. }
883. 
884. staticfn void
885. hmon_hitmon_weapon_ranged(
886.     struct _hitmon_data *hmd,
887.     struct monst *mon,
888.     struct obj *obj)    /* obj is not NULL */
889. {
890.     /* then do only 1-2 points of damage and don't use or
891.        train weapon's skill */
892.     if (hmd->mdat == &mons[PM_SHADE] && !shade_glare(obj))
893.         hmd->dmg = 0;
894.     else
895.         hmd->dmg = rnd(2);
896.     if (hmd->material == SILVER && mon_hates_silver(mon)) {
897.         hmd->silvermsg = hmd->silverobj = TRUE;
898.         /* if it will already inflict dmg, make it worse */
899.         hmd->dmg += rnd((hmd->dmg) ? 20 : 10);
900.     }
901.     if (!hmd->thrown && obj == uwep && obj->otyp == BOOMERANG
902.         && rnl(4) == 4 - 1) {
903.         boolean more_than_1 = (obj->quan > 1L);
904. 
905.         pline("As you hit %s, %s%s breaks into splinters.",
906.               mon_nam(mon), more_than_1 ? "one of " : "",
907.               yname(obj));
908.         if (!more_than_1)
909.             uwepgone(); /* set gu.unweapon */
910.         useup(obj);
911.         if (!more_than_1)
912.             obj = (struct obj *) 0;
913.         hmd->hittxt = TRUE;
914.         if (hmd->mdat != &mons[PM_SHADE])
915.             hmd->dmg++;
916.     }
917. }
918. 
919. /* can monster be stabbed in the back? */
920. staticfn boolean
921. backstabbable(struct monst *mon)
922. {
923.     return !amorphous(mon->data)
924.         && !is_whirly(mon->data)
925.         && !noncorporeal(mon->data)
926.         && mon->data->mlet != S_BLOB
927.         && mon->data->mlet != S_EYE
928.         && mon->data->mlet != S_FUNGUS
929.         && canseemon(mon)
930.         && (mon->mflee || helpless(mon));
931. }
932. 
933. staticfn void
934. hmon_hitmon_weapon_melee(
935.     struct _hitmon_data *hmd,
936.     struct monst *mon,
937.     struct obj *obj)    /* obj is not NULL */
938. {
939.     int wtype;
940.     struct obj *monwep;
941. 
942.     /* "normal" weapon usage */
943.     hmd->use_weapon_skill = TRUE;
944.     hmd->dmg = dmgval(obj, mon);
945.     /* a minimal hit doesn't exercise proficiency */
946.     hmd->train_weapon_skill = (hmd->dmg > 1);
947. 
948.     /* Healer with anatomy knowledge */
949.     if (Role_if(PM_HEALER) && hmd->hand_to_hand
950.         && obj->oclass == WEAPON_CLASS
951.         && objects[obj->otyp].oc_skill == P_KNIFE)
952.         hmd->dmg += min(3, svm.mvitals[monsndx(mon->data)].died / 6);
953. 
954.     /* special attack actions */
955.     if (!hmd->train_weapon_skill || mon == u.ustuck || u.twoweap
956.         /* Cleaver can hit up to three targets at once so don't
957.            let it also hit from behind or shatter foes' weapons */
958.         || (hmd->hand_to_hand && is_art(obj, ART_CLEAVER))) {
959.         ; /* no special bonuses */
960.     } else if (Role_if(PM_ROGUE) && backstabbable(mon) && !Upolyd
961.                /* multi-shot throwing is too powerful here */
962.                && hmd->hand_to_hand) {
963.         You("strike %s from behind!", mon_nam(mon));
964.         hmd->dmg += rnd(u.ulevel);
965.         hmd->hittxt = TRUE;
966.     } else if (hmd->dieroll == 2 && obj == uwep
967.                && obj->oclass == WEAPON_CLASS
968.                && (bimanual(obj)
969.                    || (Role_if(PM_SAMURAI) && obj->otyp == KATANA
970.                        && !uarms))
971.                && ((wtype = uwep_skill_type()) != P_NONE
972.                    && P_SKILL(wtype) >= P_SKILLED)
973.                && ((monwep = MON_WEP(mon)) != 0
974.                    && !is_flimsy(monwep)
975.                    && !obj_resists(monwep,
976.                                    50 + 15 * (greatest_erosion(obj)
977.                                               - greatest_erosion(monwep)),
978.                                    100))) {
979.         static const char from_your_blow[] = " from the force of your blow!";
980.         char buf[BUFSZ];
981.         /*
982.          * 2.5% chance of shattering defender's weapon when
983.          * using a two-handed weapon; less if uwep is rusted.
984.          * [dieroll == 2 is most successful non-beheading or
985.          * -bisecting hit, in case of special artifact damage;
986.          * the percentage chance is (1/20)*(50/100).]
987.          * If attacker's weapon is rustier than defender's,
988.          * the obj_resists chance is increased so the shatter
989.          * chance is decreased; if less rusty, then vice versa.
990.          */
991.         setmnotwielded(mon, monwep);
992.         mon->weapon_check = NEED_WEAPON;
993.         if (canseemon(mon))
994.             /* Yobjnam2(X,"shatter") yields "Shk's X shatters" if X is owned
995.                by a shop or "Mon's X shatters" if X is carried by a monster
996.                (or "{Your|The} X shatters" if {carried by hero|last resort})*/
997.             Strcpy(buf, Yobjnam2(monwep, "shatter"));
998.         else /* hero is blind or can't see invisible mon */
999.             /* construct "Its weapon shatters"; not an exact replacement
1000.                for Yobjnam2() if an unseen mon other than the shopkeeper
1001.                is wielding a shop-owned weapon; telepathy or extended
1002.                monster detection will name mon but not its weapon */
1003.             Sprintf(buf, "%s weapon%s %s", s_suffix(Monnam(mon)),
1004.                     plur(monwep->quan), otense(monwep, "shatter"));
1005.         buf[sizeof buf - sizeof from_your_blow] = '\0';
1006.         pline("%s%s", buf, from_your_blow);
1007.         m_useupall(mon, monwep);
1008.         /* If someone just shattered MY weapon, I'd flee! */
1009.         if (rn2(4)) {
1010.             monflee(mon, d(2, 3), TRUE, TRUE);
1011.         }
1012.         hmd->hittxt = TRUE;
1013.     }
1014. 
1015.     if (obj->oartifact
1016.         && artifact_hit(&gy.youmonst, mon, obj, &hmd->dmg, hmd->dieroll)) {
1017.         /* artifact_hit updates 'tmp' but doesn't inflict any
1018.            damage; however, it might cause carried items to be
1019.            destroyed and they might do so */
1020.         if (DEADMONSTER(mon)) { /* artifact killed monster */
1021.             hmd->doreturn = TRUE;
1022.             hmd->retval = FALSE;
1023.             return;
1024.             /*return FALSE;*/
1025.         }
1026.         /* perhaps artifact tried to behead a headless monster */
1027.         if (hmd->dmg == 0) {
1028.             hmd->doreturn = TRUE;
1029.             hmd->retval = TRUE;
1030.             return;
1031.             /*return TRUE;*/
1032.         }
1033.         hmd->hittxt = TRUE;
1034.     }
1035.     if (hmd->material == SILVER && mon_hates_silver(mon)) {
1036.         hmd->silvermsg = hmd->silverobj = TRUE;
1037.     }
1038.     if (artifact_light(obj) && obj->lamplit
1039.         && mon_hates_light(mon))
1040.         hmd->lightobj = TRUE;
1041.     if (u.usteed && !hmd->thrown && hmd->dmg > 0
1042.         && weapon_type(obj) == P_LANCE && mon != u.ustuck) {
1043.         hmd->jousting = joust(mon, obj);
1044.         /* exercise skill even for minimal damage hits */
1045.         if (hmd->jousting)
1046.             hmd->train_weapon_skill = TRUE;
1047.     }
1048.     if (hmd->thrown == HMON_THROWN
1049.         && (is_ammo(obj) || is_missile(obj))) {
1050.         if (ammo_and_launcher(obj, uwep)) {
1051.             /* elves and samurai do extra damage using their own
1052.                bows with their own arrows; they're highly trained */
1053.             if (Role_if(PM_SAMURAI) && obj->otyp == YA
1054.                 && uwep->otyp == YUMI)
1055.                 hmd->dmg++;
1056.             else if (Race_if(PM_ELF) && obj->otyp == ELVEN_ARROW
1057.                      && uwep->otyp == ELVEN_BOW)
1058.                 hmd->dmg++;
1059.             hmd->train_weapon_skill = (hmd->dmg > 0);
1060.         }
1061.         if (obj->opoisoned && is_poisonable(obj))
1062.             hmd->ispoisoned = TRUE;
1063.     }
1064.     /* permapoisoned is non-ammo/missile, limit the poison */
1065.     if (permapoisoned(obj) && hmd->dieroll <= 5)
1066.         hmd->ispoisoned = TRUE;
1067. }
1068. 
1069. staticfn void
1070. hmon_hitmon_weapon(
1071.     struct _hitmon_data *hmd,
1072.     struct monst *mon,
1073.     struct obj *obj)   /* obj is not NULL */
1074. {
1075.     /* is it not a melee weapon? */
1076.     if (/* if you strike with a bow... */
1077.         is_launcher(obj)
1078.         /* or strike with a missile in your hand... */
1079.         || (!hmd->thrown && (is_missile(obj) || is_ammo(obj)))
1080.         /* or use a pole at short range and not mounted... */
1081.         || (!hmd->thrown && !u.usteed && is_pole(obj)
1082.             && !is_art(obj,ART_SNICKERSNEE))
1083.         /* or throw a missile without the proper bow... */
1084.         || (is_ammo(obj) && (hmd->thrown != HMON_THROWN
1085.                              || !ammo_and_launcher(obj, uwep)))) {
1086.         hmon_hitmon_weapon_ranged(hmd, mon, obj);
1087.     } else {
1088.         hmon_hitmon_weapon_melee(hmd, mon, obj);
1089.         if (hmd->doreturn)
1090.             return;
1091.     }
1092. }
1093. 
1094. staticfn void
1095. hmon_hitmon_potion(
1096.     struct _hitmon_data *hmd,
1097.     struct monst *mon,
1098.     struct obj *obj)    /* obj is not NULL */
1099. {
1100.     if (obj->quan > 1L)
1101.         obj = splitobj(obj, 1L);
1102.     else
1103.         setuwep((struct obj *) 0);
1104.     freeinv(obj);
1105.     potionhit(mon, obj,
1106.               hmd->hand_to_hand ? POTHIT_HERO_BASH : POTHIT_HERO_THROW);
1107.     if (DEADMONSTER(mon)) {
1108.         hmd->doreturn = TRUE;
1109.         hmd->retval = FALSE; /* killed */
1110.         return;
1111.     }
1112.     hmd->hittxt = TRUE;
1113.     /* in case potion effect causes transformation */
1114.     hmd->mdat = mon->data;
1115.     hmd->dmg = (hmd->mdat == &mons[PM_SHADE]) ? 0 : 1;
1116. }
1117. 
1118. staticfn void
1119. hmon_hitmon_misc_obj(
1120.     struct _hitmon_data *hmd,
1121.     struct monst *mon,
1122.     struct obj *obj)    /* obj is not NULL */
1123. {
1124.     switch (obj->otyp) {
1125.     case BOULDER:         /* 1d20 */
1126.     case HEAVY_IRON_BALL: /* 1d25 */
1127.     case IRON_CHAIN:      /* 1d4+1 */
1128.         hmd->dmg = dmgval(obj, mon);
1129.         break;
1130.     case MIRROR:
1131.         if (breaktest(obj)) {
1132.             You("break %s.  That's bad luck!", ysimple_name(obj));
1133.             change_luck(-2);
1134.             useup(obj);
1135.             obj = (struct obj *) 0;
1136.             hmd->unarmed = FALSE; /* avoid obj==0 confusion */
1137.             hmd->get_dmg_bonus = FALSE;
1138.             hmd->hittxt = TRUE;
1139.         }
1140.         hmd->dmg = 1;
1141.         break;
1142.     case EXPENSIVE_CAMERA:
1143.         You("succeed in destroying %s.  Congratulations!",
1144.             ysimple_name(obj));
1145.         release_camera_demon(obj, u.ux, u.uy);
1146.         useup(obj);
1147.         hmd->doreturn = TRUE;
1148.         hmd->retval = TRUE;
1149.         return;
1150.         /*return TRUE;*/
1151.     case CORPSE: /* fixed by polder@cs.vu.nl */
1152.         if (touch_petrifies(&mons[obj->corpsenm])) {
1153.             hmd->dmg = 1;
1154.             hmd->hittxt = TRUE;
1155.             You("hit %s with %s.", mon_nam(mon),
1156.                 corpse_xname(obj, (const char *) 0,
1157.                              obj->dknown ? CXN_PFX_THE
1158.                              : CXN_ARTICLE));
1159.             observe_object(obj);
1160.             if (!munstone(mon, TRUE))
1161.                 minstapetrify(mon, TRUE);
1162.             if (resists_ston(mon))
1163.                 break;
1164.             /* note: hp may be <= 0 even if munstoned==TRUE */
1165.             hmd->doreturn = TRUE;
1166.             hmd->retval = !DEADMONSTER(mon);
1167.             return;
1168.             /*return (boolean) !DEADMONSTER(mon);*/
1169. #if 0
1170.         } else if (touch_petrifies(mdat)) {
1171.             ; /* maybe turn the corpse into a statue? */
1172. #endif
1173.         }
1174.         hmd->dmg = (ismnum(obj->corpsenm) ? mons[obj->corpsenm].msize
1175.                     : 0) + 1;
1176.         break;
1177. 
1178. #define useup_eggs(o)                    \
1179.     do {                                 \
1180.         if (hmd->thrown)                 \
1181.             obfree(o, (struct obj *) 0); \
1182.         else                             \
1183.             useupall(o);                 \
1184.         o = (struct obj *) 0;            \
1185.     } while (0) /* now gone */
1186.     case EGG: {
1187.         long cnt = obj->quan;
1188. 
1189.         hmd->dmg = 1; /* nominal physical damage */
1190.         hmd->get_dmg_bonus = FALSE;
1191.         hmd->hittxt = TRUE; /* message always given */
1192.         /* egg is always either used up or transformed, so next
1193.            hand-to-hand attack should yield a "bashing" mesg */
1194.         if (obj == uwep)
1195.             gu.unweapon = TRUE;
1196.         if (obj->spe && ismnum(obj->corpsenm)) {
1197.             if (obj->quan < 5L)
1198.                 change_luck((schar) - (obj->quan));
1199.             else
1200.                 change_luck(-5);
1201.         }
1202. 
1203.         if (ismnum(obj->corpsenm)
1204.             && touch_petrifies(&mons[obj->corpsenm])) {
1205.             /*learn_egg_type(obj->corpsenm);*/
1206.             pline("Splat!  You hit %s with %s %s egg%s!",
1207.                   mon_nam(mon),
1208.                   obj->known ? "the" : cnt > 1L ? "some" : "a",
1209.                   obj->known ? mons[obj->corpsenm].pmnames[NEUTRAL]
1210.                   : "petrifying",
1211.                   plur(cnt));
1212.             obj->known = 1; /* (not much point...) */
1213.             useup_eggs(obj);
1214.             if (!munstone(mon, TRUE))
1215.                 minstapetrify(mon, TRUE);
1216.             if (resists_ston(mon))
1217.                 break;
1218.             hmd->doreturn = TRUE;
1219.             hmd->retval = !DEADMONSTER(mon);
1220.             return;
1221.             /*return (boolean) (!DEADMONSTER(mon));*/
1222.         } else { /* ordinary egg(s) */
1223.             enum monnums mnum = obj->corpsenm;
1224.             const char *eggp =
1225.                 (ismnum(mnum) && obj->known)
1226.                     ? the(mons[mnum].pmnames[NEUTRAL])
1227.                     : (cnt > 1L) ? "some" : "an";
1228. 
1229.             You("hit %s with %s egg%s.", mon_nam(mon), eggp,
1230.                 plur(cnt));
1231.             if (touch_petrifies(hmd->mdat) && !stale_egg(obj)) {
1232.                 pline_The("egg%s %s alive any more...", plur(cnt),
1233.                           (cnt == 1L) ? "isn't" : "aren't");
1234.                 if (obj->timed)
1235.                     obj_stop_timers(obj);
1236.                 obj->otyp = ROCK;
1237.                 obj->oclass = GEM_CLASS;
1238.                 obj->oartifact = 0;
1239.                 obj->spe = 0;
1240.                 obj->known = obj->dknown = obj->bknown = 0;
1241.                 obj->owt = weight(obj);
1242.                 if (hmd->thrown)
1243.                     place_object(obj, mon->mx, mon->my);
1244.             } else if (obj->corpsenm == PM_PYROLISK) {
1245.                 useup_eggs(obj);
1246.                 explode(mon->mx, mon->my, -11, d(3, 6), 0, EXPL_FIERY);
1247.                 hmd->doreturn = TRUE;
1248.                 hmd->retval = !DEADMONSTER(mon);
1249.                 return;
1250.             } else {
1251.                 pline("Splat!");
1252.                 useup_eggs(obj);
1253.                 exercise(A_WIS, FALSE);
1254.             }
1255.         }
1256.         break;
1257. #undef useup_eggs
1258.     }
1259.     case CLOVE_OF_GARLIC: /* no effect against demons */
1260.         if (is_undead(hmd->mdat) || is_vampshifter(mon)) {
1261.             monflee(mon, d(2, 4), FALSE, TRUE);
1262.         }
1263.         hmd->dmg = 1;
1264.         break;
1265.     case CREAM_PIE:
1266.     case BLINDING_VENOM:
1267.         mon->msleeping = 0;
1268.         if (can_blnd(&gy.youmonst, mon,
1269.                      (uchar) ((obj->otyp == BLINDING_VENOM)
1270.                               ? AT_SPIT
1271.                               : AT_WEAP),
1272.                      obj)) {
1273.             if (Blind) {
1274.                 pline(obj->otyp == CREAM_PIE ? "Splat!"
1275.                       : "Splash!");
1276.             } else if (obj->otyp == BLINDING_VENOM) {
1277.                 pline_The("venom blinds %s%s!", mon_nam(mon),
1278.                           mon->mcansee ? "" : " further");
1279.             } else {
1280.                 char *whom = mon_nam(mon);
1281.                 char *what = The(xname(obj));
1282. 
1283.                 if (!hmd->thrown && obj->quan > 1L)
1284.                     what = An(singular(obj, xname));
1285.                 /* note: s_suffix returns a modifiable buffer */
1286.                 if (haseyes(hmd->mdat)
1287.                     && hmd->mdat != &mons[PM_FLOATING_EYE])
1288.                     whom = strcat(strcat(s_suffix(whom), " "),
1289.                                   mbodypart(mon, FACE));
1290.                 pline("%s %s over %s!", what,
1291.                       vtense(what, "splash"), whom);
1292.             }
1293.             setmangry(mon, TRUE);
1294.             mon->mcansee = 0;
1295.             hmd->dmg = rn1(25, 21);
1296.             if (((int) mon->mblinded + hmd->dmg) > 127)
1297.                 mon->mblinded = 127;
1298.             else
1299.                 mon->mblinded += hmd->dmg;
1300.         } else {
1301.             pline(obj->otyp == CREAM_PIE ? "Splat!" : "Splash!");
1302.             setmangry(mon, TRUE);
1303.         }
1304.         {
1305.             boolean more_than_1 = (obj->quan > 1L);
1306. 
1307.             if (hmd->thrown)
1308.                 obfree(obj, (struct obj *) 0);
1309.             else
1310.                 useup(obj);
1311. 
1312.             if (!more_than_1)
1313.                 obj = (struct obj *) 0;
1314.         }
1315.         hmd->hittxt = TRUE;
1316.         hmd->get_dmg_bonus = FALSE;
1317.         hmd->dmg = 0;
1318.         break;
1319.     case ACID_VENOM: /* thrown (or spit) */
1320.         if (resists_acid(mon)) {
1321.             Your("venom hits %s harmlessly.", mon_nam(mon));
1322.             hmd->dmg = 0;
1323.         } else {
1324.             Your("venom burns %s!", mon_nam(mon));
1325.             hmd->dmg = dmgval(obj, mon);
1326.         }
1327.         {
1328.             boolean more_than_1 = (obj->quan > 1L);
1329. 
1330.             if (hmd->thrown)
1331.                 obfree(obj, (struct obj *) 0);
1332.             else
1333.                 useup(obj);
1334. 
1335.             if (!more_than_1)
1336.                 obj = (struct obj *) 0;
1337.         }
1338.         hmd->hittxt = TRUE;
1339.         hmd->get_dmg_bonus = FALSE;
1340.         break;
1341.     default:
1342.         if ((objects[obj->otyp].oc_material == VEGGY ||
1343.              objects[obj->otyp].oc_material == PAPER) &&
1344.             obj->oclass != SPBOOK_CLASS) {
1345.             /* vegetables (and similar) do no damage, because they
1346.                aren't rigid enough; paper objects also do no damage,
1347.                except for books */
1348.             hmd->dmg = 0;
1349.             hmd->get_dmg_bonus = FALSE;
1350.             break;
1351.         }
1352.         /* non-weapons can damage because of their weight */
1353.         /* (but not too much) */
1354.         hmd->dmg = (obj->owt + 99) / 100;
1355.         hmd->dmg = (hmd->dmg <= 1) ? 1 : rnd(hmd->dmg);
1356.         if (hmd->dmg > 6)
1357.             hmd->dmg = 6;
1358.         /* wet towel has modest damage bonus beyond its weight,
1359.            based on its wetness */
1360.         if (is_wet_towel(obj)) {
1361.             boolean doubld = (mon->data == &mons[PM_IRON_GOLEM]);
1362. 
1363.             /* wielded wet towel should probably use whip skill
1364.                (but not by setting objects[TOWEL].oc_skill==P_WHIP
1365.                because that would turn towel into a weptool);
1366.                due to low weight, tmp always starts at 1 here, and
1367.                due to wet towel's definition, obj->spe is 1..7 */
1368.             hmd->dmg += obj->spe * (doubld ? 2 : 1);
1369.             hmd->dmg = rnd(hmd->dmg); /* wet towel damage not capped at 6 */
1370.             /* usually lose some wetness but defer doing so
1371.                until after hit message */
1372.             hmd->dryit = (rn2(obj->spe + 1) > 0);
1373.         }
1374.         /* things like silver wands can arrive here so we
1375.            need another silver check; blessed check too */
1376.         if (hmd->material == SILVER && mon_hates_silver(mon)) {
1377.             hmd->dmg += rnd(20);
1378.             hmd->silvermsg = hmd->silverobj = TRUE;
1379.         }
1380.         if (obj->blessed && mon_hates_blessings(mon))
1381.             hmd->dmg += rnd(4);
1382.     }
1383. }
1384. 
1385. /* do the actual hitting monster with obj/fists */
1386. staticfn void
1387. hmon_hitmon_do_hit(
1388.     struct _hitmon_data *hmd,
1389.     struct monst *mon,
1390.     struct obj *obj)    /* obj can be NULL */
1391. {
1392.     if (!obj) { /* attack with bare hands */
1393.         hmon_hitmon_barehands(hmd, mon);
1394.     } else {
1395.         /* obj is not NULL here because of the !obj check in this if block,
1396.          , so no guard is needed ahead of stone_missile(obj) */
1397.         /* stone missile does not hurt xorn or earth elemental, but doesn't
1398.            pass all the way through and continue on to some further target */
1399.         if ((hmd->thrown == HMON_THROWN
1400.              || hmd->thrown == HMON_KICKED) /* not Applied */
1401.             && stone_missile(obj) && passes_rocks(hmd->mdat)) {
1402.             hit(mshot_xname(obj), mon, " but does no harm.");
1403.             wakeup(mon, TRUE);
1404.             hmd->doreturn = TRUE;
1405.             hmd->retval = TRUE;
1406.             return;
1407.         }
1408.         /* remember obj's name since it might end up being destroyed and
1409.            we'll want to use it after that */
1410.         if (!(artifact_light(obj) && obj->lamplit))
1411.             Strcpy(hmd->saved_oname, cxname(obj));
1412.         else
1413.             Strcpy(hmd->saved_oname, bare_artifactname(obj));
1414. 
1415.         if (obj->oclass == WEAPON_CLASS || is_weptool(obj)
1416.             || obj->oclass == GEM_CLASS) {
1417.             hmon_hitmon_weapon(hmd, mon, obj);
1418.             if (hmd->doreturn)
1419.                 return;
1420.         /* attacking with non-weapons */
1421.         } else if (obj->oclass == POTION_CLASS) {
1422.             hmon_hitmon_potion(hmd, mon, obj);
1423.             if (hmd->doreturn)
1424.                 return;
1425.         } else {
1426.             if (hmd->mdat == &mons[PM_SHADE] && !shade_aware(obj)) {
1427.                 hmd->dmg = 0;
1428.             } else {
1429.                 hmon_hitmon_misc_obj(hmd, mon, obj);
1430.             }
1431.         }
1432.     }
1433. }
1434. 
1435. staticfn void
1436. hmon_hitmon_dmg_recalc(struct _hitmon_data *hmd, struct obj *obj)
1437. {
1438.     int dmgbonus = 0, strbonus, absbonus;
1439. 
1440.     /*
1441.      * Potential bonus (or penalty) from worn ring of increase damage
1442.      * (or intrinsic bonus from eating same) or from strength.  Strength
1443.      * bonus is increased for melee with two-handed weapons and decreased
1444.      * for dual attacks (but when both hit, the total for the two is more
1445.      * than the bonus for a regular single hit).
1446.      */
1447.     if (hmd->get_dmg_bonus) {
1448.         /* for dual attacks, udaminc applies to both, and two-handed
1449.            weapons use it as-is */
1450.         dmgbonus = u.udaminc;
1451.         /* throwing using a propellor gets an increase-damage bonus
1452.            but not a strength one; other attacks get both;
1453.            for dual attacks, 3/4 of the strength bonus is used; when
1454.            both attacks hit, overall bonus is 3/2 rather than doubled;
1455.            melee hit with two-handed weapon uses 3/2 strength bonus to
1456.            approximately match double hit with two-weapon ('approximate'
1457.            because udaminc skews in favor of two-weapon); the 3/2 factor
1458.            for two-handed strength does not apply to polearms unless
1459.            hero is simply bashing with one of those and does not apply
1460.            to jousting because lances are one-handed */
1461.         if (hmd->thrown != HMON_THROWN
1462.             || !obj || !uwep || !ammo_and_launcher(obj, uwep)) {
1463.             strbonus = dbon();
1464.             absbonus = abs(strbonus);
1465.             if (hmd->twohits)
1466.                 strbonus = ((3 * absbonus + 2) / 4) * sgn(strbonus);
1467.             else if (hmd->thrown == HMON_MELEE && uwep && bimanual(uwep))
1468.                 strbonus = ((3 * absbonus + 1) / 2) * sgn(strbonus);
1469.             dmgbonus += strbonus;
1470.         }
1471.     }
1472. 
1473.     /*
1474.      * Potential bonus (or penalty) from weapon skill.
1475.      * 'use_weapon_skill' is True for hand-to-hand ordinary weapon,
1476.      * applied or jousting polearm or lance, thrown missile (dart,
1477.      * shuriken, boomerang), or shot ammo (arrow, bolt, rock/gem when
1478.      * wielding corresponding launcher).
1479.      * It is False for hand-to-hand or thrown non-weapon, hand-to-hand
1480.      * polearm or lance when not mounted, hand-to-hand missile or ammo
1481.      * or launcher, thrown non-missile, or thrown ammo (including rocks)
1482.      * when not wielding corresponding launcher.
1483.      */
1484.     if (hmd->use_weapon_skill) {
1485.         struct obj *skillwep = obj;
1486. 
1487.         if (PROJECTILE(obj) && ammo_and_launcher(obj, uwep))
1488.             skillwep = uwep;
1489.         dmgbonus += weapon_dam_bonus(skillwep);
1490. 
1491.         /* hit for more than minimal damage (before being adjusted
1492.            for damage or skill bonus) trains the skill toward future
1493.            enhancement */
1494.         if (hmd->train_weapon_skill) {
1495.             /* [this assumes that `!thrown' implies wielded...] */
1496.             int wtype = hmd->thrown ? weapon_type(skillwep)
1497.                                     : uwep_skill_type();
1498.             use_skill(wtype, 1);
1499.         }
1500.     }
1501. 
1502.     /* apply combined damage+strength and skill bonuses */
1503.     hmd->dmg += dmgbonus;
1504.     /* don't let penalty, if bonus is negative, turn a hit into a miss */
1505.     if (hmd->dmg < 1)
1506.         hmd->dmg = 1;
1507. }
1508. 
1509. staticfn void
1510. hmon_hitmon_poison(
1511.     struct _hitmon_data *hmd,
1512.     struct monst *mon,
1513.     struct obj *obj)    /* obj is not NULL */
1514. {
1515.     int nopoison = (10 - (obj->owt / 10));
1516. 
1517.     if (nopoison < 2)
1518.         nopoison = 2;
1519.     if (Role_if(PM_SAMURAI)) {
1520.         You("dishonorably use a poisoned weapon!");
1521.         adjalign(-sgn(u.ualign.type));
1522.     } else if (u.ualign.type == A_LAWFUL && u.ualign.record > -10) {
1523.         You_feel("like an evil coward for using a poisoned weapon.");
1524.         adjalign(-1);
1525.     }
1526.     if (!permapoisoned(obj) && !rn2(nopoison)) {
1527.         /* remove poison now in case obj ends up in a bones file */
1528.         obj->opoisoned = FALSE;
1529.         /* defer "obj is no longer poisoned" until after hit message */
1530.         hmd->unpoisonmsg = TRUE;
1531.     }
1532.     if (resists_poison(mon))
1533.         hmd->needpoismsg = TRUE;
1534.     else if (rn2(10))
1535.         hmd->dmg += rnd(6);
1536.     else
1537.         hmd->poiskilled = TRUE;
1538. }
1539. 
1540. staticfn void
1541. hmon_hitmon_jousting(
1542.     struct _hitmon_data *hmd,
1543.     struct monst *mon, /* target */
1544.     struct obj *obj) /* lance; obj is not NULL */
1545. {
1546.     hmd->dmg += d(2, (obj == uwep) ? 10 : 2); /* [was in dmgval()] */
1547.     You("joust %s%s", mon_nam(mon), canseemon(mon) ? exclam(hmd->dmg) : ".");
1548.     /* if this hit just broke the never-hit-with-wielded-weapon conduct
1549.        (handled by caller...), give a livelog message for that now */
1550.     if (u.uconduct.weaphit <= 1)
1551.         first_weapon_hit(obj);
1552. 
1553.     if (hmd->jousting < 0) {
1554.         /* (must be either primary or secondary weapon to get here) */
1555.         set_twoweap(FALSE); /* sets u.twoweap = FALSE;
1556.                              * untwoweapon() is too verbose here */
1557.         if (obj == uwep)
1558.             uwepgone(); /* set gu.unweapon */
1559.         pline("%s shatters on impact!", Yname2(obj));
1560.         /* minor side-effect: broken lance won't split puddings */
1561.         useup(obj);
1562.         obj = (struct obj *) 0;
1563.     }
1564.     if (mhurtle_to_doom(mon, hmd->dmg, &hmd->mdat))
1565.         hmd->already_killed = TRUE;
1566.     hmd->hittxt = TRUE;
1567. }
1568. 
1569. staticfn void
1570. hmon_hitmon_stagger(
1571.     struct _hitmon_data *hmd,
1572.     struct monst *mon,
1573.     struct obj *obj UNUSED)
1574. {
1575.     /* VERY small chance of stunning opponent if unarmed. */
1576.     if (rnd(100) < P_SKILL(P_BARE_HANDED_COMBAT) && !bigmonst(hmd->mdat)
1577.         && !thick_skinned(hmd->mdat)) {
1578.         if (canspotmon(mon))
1579.             pline("%s %s from your powerful strike!", Monnam(mon),
1580.                   makeplural(stagger(mon->data, "stagger")));
1581.         if (mhurtle_to_doom(mon, hmd->dmg, &hmd->mdat))
1582.             hmd->already_killed = TRUE;
1583.         hmd->hittxt = TRUE;
1584.     }
1585. }
1586. 
1587. staticfn void
1588. hmon_hitmon_pet(
1589.     struct _hitmon_data *hmd,
1590.     struct monst *mon,
1591.     struct obj *obj UNUSED)
1592. {
1593.     if (mon->mtame && hmd->dmg > 0) {
1594.         /* do this even if the pet is being killed or migrating (affects revival) */
1595.         abuse_dog(mon); /* reduces tameness */
1596.         /* flee if still alive and still tame; if already suffering from
1597.            untimed fleeing, no effect, otherwise increases timed fleeing */
1598.         if (mon->mtame && !hmd->destroyed)
1599.             monflee(mon, 10 * rnd(hmd->dmg), FALSE, FALSE);
1600.     }
1601. }
1602. 
1603. staticfn void
1604. hmon_hitmon_splitmon(
1605.     struct _hitmon_data *hmd,
1606.     struct monst *mon,
1607.     struct obj *obj)    /* obj can be NULL but guards are in place below */
1608. {
1609.     if ((hmd->mdat == &mons[PM_BLACK_PUDDING]
1610.          || hmd->mdat == &mons[PM_BROWN_PUDDING])
1611.         /* pudding is alive and healthy enough to split */
1612.         && mon->mhp > 1 && !mon->mcan && !hmd->offmap
1613.         /* iron weapon using melee or polearm hit [3.6.1: metal weapon too;
1614.            also allow either or both weapons to cause split when twoweap] */
1615.         && obj && (obj == uwep || (u.twoweap && obj == uswapwep))
1616.         && ((hmd->material == IRON
1617.              /* allow scalpel and tsurugi to split puddings */
1618.              || hmd->material == METAL)
1619.             /* but not bashing with darts, arrows or ya */
1620.             && !(is_ammo(obj) || is_missile(obj)))
1621.         && hmd->hand_to_hand) {
1622.         struct monst *mclone;
1623.         char withwhat[BUFSZ];
1624. 
1625.         if ((mclone = clone_mon(mon, 0, 0)) != 0) {
1626.             withwhat[0] = '\0';
1627.             if (u.twoweap && flags.verbose)
1628.                 Sprintf(withwhat, " with %s", yname(obj));
1629.             pline("%s divides as you hit it%s!", Monnam(mon), withwhat);
1630.             hmd->hittxt = TRUE;
1631.             (void) mintrap(mclone, NO_TRAP_FLAGS);
1632.         }
1633.     }
1634. }
1635. 
1636. staticfn void
1637. hmon_hitmon_msg_hit(
1638.     struct _hitmon_data *hmd,
1639.     struct monst *mon,
1640.     struct obj *obj)   /* obj can be NULL for hand_to_hand; otherwise not */
1641. {
1642.     if (!hmd->hittxt /*( thrown => obj exists )*/
1643.         && (!hmd->destroyed
1644.             || (hmd->thrown && gm.m_shot.n > 1
1645.                 && gm.m_shot.o == obj->otyp))) {
1646.         if (hmd->thrown)
1647.             hit(mshot_xname(obj), mon, exclam(hmd->dmg));
1648.         else if (!flags.verbose)
1649.             You("hit it.");
1650.         else /* hand_to_hand */
1651.             You("%s %s%s",
1652.                 (obj && (is_shield(obj)
1653.                          || obj->otyp == HEAVY_IRON_BALL)) ? "bash"
1654.                 : (obj && (objects[obj->otyp].oc_skill == P_WHIP
1655.                            || is_wet_towel(obj))) ? "lash"
1656.                   : Role_if(PM_BARBARIAN) ? "smite"
1657.                     : "hit",
1658.                 mon_nam(mon), canseemon(mon) ? exclam(hmd->dmg) : ".");
1659.     }
1660. }
1661. 
1662. staticfn void
1663. hmon_hitmon_msg_silver(
1664.     struct _hitmon_data *hmd,
1665.     struct monst *mon,
1666.     struct obj *obj UNUSED)
1667. {
1668.     const char *fmt;
1669.     char *whom = mon_nam(mon);
1670.     char silverobjbuf[BUFSZ];
1671. 
1672.     if (canspotmon(mon)) {
1673.         if (hmd->barehand_silver_rings == 1)
1674.             fmt = "Your silver ring sears %s!";
1675.         else if (hmd->barehand_silver_rings == 2)
1676.             fmt = "Your silver rings sear %s!";
1677.         else if (hmd->silverobj && hmd->saved_oname[0]) {
1678.             /* guard constructed format string against '%' in
1679.                saved_oname[] from xname(via cxname()) */
1680.             Snprintf(silverobjbuf, sizeof(silverobjbuf), "Your %s%s %s",
1681.                      strstri(hmd->saved_oname, "silver") ? "" : "silver ",
1682.                      hmd->saved_oname, vtense(hmd->saved_oname, "sear"));
1683.             (void) strNsubst(silverobjbuf, "%", "%%", 0);
1684.             strncat(silverobjbuf, " %s!",
1685.                     sizeof(silverobjbuf) - (strlen(silverobjbuf) + 1));
1686.             fmt = silverobjbuf;
1687.         } else
1688.             fmt = "The silver sears %s!";
1689.     } else {
1690.         *whom = highc(*whom); /* "it" -> "It" */
1691.         fmt = "%s is seared!";
1692.     }
1693.     /* note: s_suffix returns a modifiable buffer */
1694.     if (!noncorporeal(hmd->mdat) && !amorphous(hmd->mdat))
1695.         whom = strcat(s_suffix(whom), " flesh");
1696.     DISABLE_WARNING_FORMAT_NONLITERAL
1697.     pline(fmt, whom);
1698.     RESTORE_WARNING_FORMAT_NONLITERAL
1699. }
1700. 
1701. staticfn void
1702. hmon_hitmon_msg_lightobj(
1703.     struct _hitmon_data *hmd,
1704.     struct monst *mon,
1705.     struct obj *obj UNUSED)
1706. {
1707.     const char *fmt;
1708.     char *whom = mon_nam(mon);
1709.     char emitlightobjbuf[BUFSZ];
1710. 
1711.     if (canspotmon(mon)) {
1712.         if (hmd->saved_oname[0]) {
1713.             Sprintf(emitlightobjbuf,
1714.                     "%s radiance penetrates deep into",
1715.                     s_suffix(hmd->saved_oname));
1716.             Strcat(emitlightobjbuf, " %s!");
1717.             fmt = emitlightobjbuf;
1718.         } else
1719.             fmt = "The light sears %s!";
1720.     } else {
1721.         *whom = highc(*whom); /* "it" -> "It" */
1722.         fmt = "%s is seared!";
1723.     }
1724.     /* note: s_suffix returns a modifiable buffer */
1725.     if (!noncorporeal(hmd->mdat) && !amorphous(hmd->mdat))
1726.         whom = strcat(s_suffix(whom), " flesh");
1727.     DISABLE_WARNING_FORMAT_NONLITERAL
1728.     pline(fmt, whom);
1729.     RESTORE_WARNING_FORMAT_NONLITERAL
1730. }
1731. 
1732. /*
1733.  * These will segfault if passed a NULL obj pointer:
1734.  *       hmon_hitmon_weapon_ranged,
1735.  *       hmon_hitmon_weapon_melee,
1736.  *       hmon_hitmon_weapon,
1737.  *       hmon_hitmon_potion,
1738.  *       hmon_hitmon_misc_obj,
1739.  *       hmon_hitmon_poison,
1740.  *       hmon_hitmon_jousting,
1741.  *
1742.  * These are equipped to handle a NULL obj pointer:
1743.  *       hmon_hitmon_stagger,       - obj arg is unused
1744.  *       hmon_hitmon_pet,           - obj arg is unused
1745.  *       hmon_hitmon_msg_silver,    - obj arg is unused
1746.  *       hmon_hitmon_msg_lightobj,  - obj arg is unused
1747.  *       hmon_hitmon_do_hit,        - has obj and !obj code paths
1748.  *       hmon_hitmon_splitmon,      - has !obj guards
1749.  *       hmon_hitmon_msg_hit,       - has !obj guards exc. thrown which is ok
1750.  */
1751. 
1752. /* guts of hmon(); returns True if 'mon' survives */
1753. staticfn boolean
1754. hmon_hitmon(
1755.     struct monst *mon,
1756.     struct obj *obj,
1757.     int thrown, /* HMON_xxx (0 => hand-to-hand, other => ranged) */
1758.     int dieroll)
1759. {
1760.     struct _hitmon_data hmd;
1761.     boolean maybe_knockback = FALSE;
1762. 
1763.     hmd.dmg = 0;
1764.     hmd.thrown = thrown;
1765.     hmd.twohits = thrown ? 0 : gt.twohits;
1766.     hmd.dieroll = dieroll;
1767.     hmd.mdat = mon->data;
1768.     hmd.use_weapon_skill = FALSE;
1769.     hmd.train_weapon_skill = FALSE;
1770.     hmd.barehand_silver_rings = 0;
1771.     hmd.silvermsg = FALSE;
1772.     hmd.silverobj = FALSE;
1773.     hmd.lightobj = FALSE;
1774.     hmd.material = obj ? objects[obj->otyp].oc_material
1775.                        : NO_MATERIAL;
1776.     hmd.jousting = 0;
1777.     hmd.hittxt = FALSE;
1778.     hmd.get_dmg_bonus = TRUE;
1779.     hmd.unarmed = !uwep && !uarm && !uarms;
1780.     hmd.hand_to_hand = (thrown == HMON_MELEE
1781.                         /* not grapnels; applied implies uwep */
1782.                         || (thrown == HMON_APPLIED && is_pole(uwep)));
1783.     hmd.ispoisoned = FALSE;
1784.     hmd.unpoisonmsg = FALSE;
1785.     hmd.needpoismsg = FALSE;
1786.     hmd.poiskilled = FALSE;
1787.     hmd.already_killed = FALSE;
1788.     hmd.offmap = FALSE;
1789.     hmd.destroyed = FALSE;
1790.     hmd.dryit = FALSE;
1791.     hmd.doreturn = FALSE;
1792.     hmd.retval = FALSE;
1793.     hmd.saved_oname[0] = '\0';
1794. 
1795.     hmon_hitmon_do_hit(&hmd, mon, obj);
1796.     if (hmd.doreturn)
1797.         return hmd.retval;
1798. 
1799.     /*
1800.      ***** NOTE: perhaps obj is undefined! (if !thrown && BOOMERANG)
1801.      *      *OR* if attacking bare-handed!
1802.      * Note too: the cases where obj might get destroyed do not
1803.      *      set 'use_weapon_skill', bare-handed does.
1804.      */
1805. 
1806.     if (hmd.dmg > 0)
1807.         hmon_hitmon_dmg_recalc(&hmd, obj);
1808. 
1809.     if (hmd.ispoisoned)
1810.         hmon_hitmon_poison(&hmd, mon, obj);
1811. 
1812.     if (hmd.dmg < 1) {
1813.         boolean mon_is_shade = (mon->data == &mons[PM_SHADE]);
1814. 
1815.         /* make sure that negative damage adjustment can't result
1816.            in inadvertently boosting the victim's hit points */
1817.         hmd.dmg = (hmd.get_dmg_bonus && !mon_is_shade) ? 1 : 0;
1818.         if (mon_is_shade && !hmd.hittxt
1819.             && thrown != HMON_THROWN && thrown != HMON_KICKED)
1820.             /* this gives "harmlessly passes through" feedback even when
1821.                hero doesn't see it happen; presumably sensed by touch? */
1822.             hmd.hittxt = shade_miss(&gy.youmonst, mon, obj, FALSE, TRUE);
1823.     }
1824. 
1825.     if (hmd.jousting) {
1826.         hmon_hitmon_jousting(&hmd, mon, obj);
1827.     } else if (hmd.unarmed && hmd.dmg > 1 && !thrown && !obj && !Upolyd) {
1828.         hmon_hitmon_stagger(&hmd, mon, obj);
1829.     } else if (!hmd.unarmed && hmd.dmg > 1 && !thrown && !Upolyd
1830.                && !u.twoweap && uwep) {
1831.         maybe_knockback = TRUE;
1832.     }
1833. 
1834.     if (!hmd.already_killed) {
1835.         if (obj && (obj == uwep || (obj == uswapwep && u.twoweap))
1836.             /* known_hitum 'what counts as a weapon' criteria */
1837.             && (obj->oclass == WEAPON_CLASS || is_weptool(obj))
1838.             && (thrown == HMON_MELEE || thrown == HMON_APPLIED)
1839.             /* if jousting, the hit was already logged */
1840.             && !hmd.jousting
1841.             /* note: caller has already incremented u.uconduct.weaphit
1842.                so we test for 1; 0 shouldn't be able to happen here... */
1843.             && hmd.dmg > 0 && u.uconduct.weaphit <= 1)
1844.             first_weapon_hit(obj);
1845.         mon->mhp -= hmd.dmg;
1846.     }
1847.     /* adjustments might have made tmp become less than what
1848.        a level-draining artifact has already done to max HP */
1849.     if (mon->mhp > mon->mhpmax)
1850.         mon->mhp = mon->mhpmax;
1851.     if (mon->mx == 0) {
1852.         /*
1853.          * jousting can lead to:
1854.          *     mhurtle_to_doom()
1855.          *      mhurtle()
1856.          *       mintrap()
1857.          *        trapeffect_hole()
1858.          *         trapeffect_level_telep()
1859.          *          migrate_to_level()
1860.          * Set offmap in that situation so code to follow can test for it.*/
1861.         hmd.offmap = TRUE;
1862.     }
1863.     if (DEADMONSTER(mon))
1864.         hmd.destroyed = TRUE;
1865. 
1866.     hmon_hitmon_pet(&hmd, mon, obj);
1867. 
1868.     hmon_hitmon_splitmon(&hmd, mon, obj);
1869. 
1870.     hmon_hitmon_msg_hit(&hmd, mon, obj);
1871. 
1872.     if (hmd.dryit) { /* dryit implies wet towel, so 'obj' is still intact */
1873.         assert(obj != NULL);
1874.         dry_a_towel(obj, -1, TRUE);
1875.     }
1876. 
1877.     if (hmd.silvermsg)
1878.         hmon_hitmon_msg_silver(&hmd, mon, obj);
1879. 
1880.     if (hmd.lightobj)
1881.         hmon_hitmon_msg_lightobj(&hmd, mon, obj);
1882. 
1883.     /* if a "no longer poisoned" message is coming, it will be last;
1884.        obj->opoisoned was cleared above and any message referring to
1885.        "poisoned <obj>" has now been given; we want just "<obj>" for
1886.        last message, so reformat while obj is still accessible */
1887.     if (hmd.unpoisonmsg) {
1888.         assert(obj != NULL);
1889.         Strcpy(hmd.saved_oname, cxname(obj));
1890.     }
1891. 
1892.     /* [note: thrown obj might go away during killed()/xkilled() call
1893.        (via 'thrownobj'; if swallowed, it gets added to engulfer's
1894.        minvent and might merge with a stack that's already there)] */
1895.     /* already_killed and poiskilled won't apply for Trollsbane */
1896. 
1897.     if (hmd.needpoismsg)
1898.         pline_The("poison doesn't seem to affect %s.", mon_nam(mon));
1899.     if (hmd.poiskilled) {
1900.         pline_The("poison was deadly...");
1901.         if (!hmd.already_killed)
1902.             xkilled(mon, XKILL_NOMSG);
1903.         hmd.destroyed = TRUE; /* return FALSE; */
1904.     } else if (hmd.destroyed) {
1905.         if (!hmd.already_killed) {
1906.             if (troll_baned(mon, obj))
1907.                 gm.mkcorpstat_norevive = TRUE;
1908.             killed(mon); /* takes care of most messages */
1909.             gm.mkcorpstat_norevive = FALSE;
1910.         }
1911.     } else if (u.umconf && hmd.hand_to_hand) {
1912.         nohandglow(mon);
1913.         if (!mon->mconf && !resist(mon, SPBOOK_CLASS, 0, NOTELL)) {
1914.             mon->mconf = 1;
1915.             if (!mon->mstun && !helpless(mon) && canseemon(mon))
1916.                 pline("%s appears confused.", Monnam(mon));
1917.         }
1918.     }
1919.     if (hmd.unpoisonmsg)
1920.         Your("%s %s no longer poisoned.", hmd.saved_oname,
1921.              vtense(hmd.saved_oname, "are"));
1922. 
1923.     if (!hmd.destroyed && !hmd.offmap) {
1924.         int hitflags = M_ATTK_HIT;
1925. 
1926.         wakeup(mon, TRUE);
1927.         if (maybe_knockback
1928.             && mhitm_knockback(&gy.youmonst, mon, gy.youmonst.data->mattk,
1929.                                &hitflags, TRUE)) {
1930.             if ((hitflags & M_ATTK_DEF_DIED) != 0)
1931.                 hmd.destroyed = TRUE;
1932.         }
1933.     }
1934.     return hmd.destroyed ? FALSE : TRUE;
1935. }
1936. 
1937. 
1938. /* joust or martial arts punch is knocking the target back; that might
1939.    kill 'mon' (via trap) before known_hitum() has a chance to do so;
1940.    return True if we kill mon, False otherwise */
1941. staticfn boolean
1942. mhurtle_to_doom(
1943.     struct monst *mon,         /* target monster */
1944.     int tmp,                   /* amount of pending damage */
1945.     struct permonst **mptr)    /* caller's cached copy of mon->data */
1946. {
1947.     /* only hurtle if pending physical damage (tmp) isn't going to kill mon */
1948.     if (tmp < mon->mhp) {
1949.         mhurtle(mon, u.dx, u.dy, 1);
1950.         /* update caller's cached mon->data in case mon was pushed into
1951.            a polymorph trap or is a vampshifter whose current form has
1952.            been killed by a trap so that it reverted to original form */
1953.         *mptr = mon->data;
1954.         if (DEADMONSTER(mon))
1955.             return TRUE;
1956.     }
1957.     return FALSE; /* mon isn't dead yet */
1958. }
1959. 
1960. /* gamelog version of "you've broken never-hit-with-wielded-weapon conduct;
1961.    the conduct is tracked in known_hitum(); we're called by hmon_hitmon() */
1962. staticfn void
1963. first_weapon_hit(struct obj *weapon)
1964. {
1965.     char buf[BUFSZ];
1966. 
1967.     /* avoid xname() since that includes "named <foo>" and we don't want
1968.        player-supplied <foo> in livelog */
1969.     buf[0] = '\0';
1970.     /* include "cursed" if known but don't bother with blessed */
1971.     if (weapon->cursed && weapon->bknown)
1972.         Strcat(buf, "cursed "); /* normally supplied by doname() */
1973.     if (obj_is_pname(weapon)) {
1974.         Strcat(buf, ONAME(weapon)); /* fully IDed artifact */
1975.     } else {
1976.         Strcat(buf, simpleonames(weapon));
1977.         if (weapon->oartifact && weapon->dknown)
1978.             Sprintf(eos(buf), " named %s", bare_artifactname(weapon));
1979.     }
1980. 
1981.     /* when a hit breaks the never-hit-with-wielded-weapon conduct
1982.        (handled by caller) we need to log the message about that before
1983.        monster is possibly killed; otherwise getting log entry sequence
1984.          N : killed for the first time
1985.          N : hit with a wielded weapon for the first time
1986.        reported on the same turn (N) looks "suboptimal" */
1987.     livelog_printf(LL_CONDUCT,
1988.                    "hit with a wielded weapon (%s) for the first time", buf);
1989. }
1990. 
1991. staticfn boolean
1992. shade_aware(struct obj *obj)
1993. {
1994.     if (!obj)
1995.         return FALSE;
1996.     /*
1997.      * The things in this list either
1998.      * 1) affect shades.
1999.      *  OR
2000.      * 2) are dealt with properly by other routines
2001.      *    when it comes to shades.
2002.      */
2003.     if (obj->otyp == BOULDER
2004.         || obj->otyp == HEAVY_IRON_BALL
2005.         || obj->otyp == IRON_CHAIN      /* dmgval handles those first three */
2006.         || obj->otyp == MIRROR          /* silver in the reflective surface */
2007.         || obj->otyp == CLOVE_OF_GARLIC /* causes shades to flee */
2008.         || objects[obj->otyp].oc_material == SILVER)
2009.         return TRUE;
2010.     return FALSE;
2011. }
2012. 
2013. /* used for hero vs monster and monster vs monster; also handles
2014.    monster vs hero but that won't happen because hero can't be a shade */
2015. boolean
2016. shade_miss(
2017.     struct monst *magr,
2018.     struct monst *mdef,
2019.     struct obj *obj,
2020.     boolean thrown,
2021.     boolean verbose)
2022. {
2023.     const char *what, *whose, *target;
2024.     boolean youagr = (magr == &gy.youmonst), youdef = (mdef == &gy.youmonst);
2025. 
2026.     /* we're using dmgval() for zero/not-zero, not for actual damage amount */
2027.     if (mdef->data != &mons[PM_SHADE] || (obj && dmgval(obj, mdef)))
2028.         return FALSE;
2029. 
2030.     if (verbose
2031.         && ((youdef || cansee(mdef->mx, mdef->my) || sensemon(mdef))
2032.             || (magr == &gy.youmonst && m_next2u(mdef)))) {
2033.         static const char harmlessly_thru[] = " harmlessly through ";
2034. 
2035.         what = (!obj || shade_aware(obj)) ? "attack" : cxname(obj);
2036.         target = youdef ? "you" : mon_nam(mdef);
2037.         if (!thrown) {
2038.             whose = youagr ? "Your" : s_suffix(Monnam(magr));
2039.             pline("%s %s %s%s%s.", whose, what,
2040.                   vtense(what, "pass"), harmlessly_thru, target);
2041.         } else {
2042.             pline("%s %s%s%s.", The(what), /* note: not pline_The() */
2043.                   vtense(what, "pass"), harmlessly_thru, target);
2044.         }
2045.         if (!youdef && !canspotmon(mdef))
2046.             map_invisible(mdef->mx, mdef->my);
2047.     }
2048.     if (!youdef)
2049.         mdef->msleeping = 0;
2050.     return TRUE;
2051. }
2052. 
2053. /* check whether slippery clothing protects from hug or wrap attack */
2054. /* [currently assumes that you are the attacker] */
2055. staticfn boolean
2056. m_slips_free(struct monst *mdef, struct attack *mattk)
2057. {
2058.     struct obj *obj;
2059. 
2060.     if (mattk->adtyp == AD_DRIN) {
2061.         /* intelligence drain attacks the head */
2062.         obj = which_armor(mdef, W_ARMH);
2063.     } else {
2064.         /* grabbing attacks the body */
2065.         obj = which_armor(mdef, W_ARMC); /* cloak */
2066.         if (!obj)
2067.             obj = which_armor(mdef, W_ARM); /* suit */
2068.         if (!obj)
2069.             obj = which_armor(mdef, W_ARMU); /* shirt */
2070.     }
2071. 
2072.     /* if monster's cloak/armor is greased, your grab slips off; this
2073.        protection might fail (33% chance) when the armor is cursed */
2074.     if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK)
2075.         && (!obj->cursed || rn2(3))) {
2076.         You("%s %s %s %s!",
2077.             (mattk->adtyp == AD_WRAP) ? "slip off of"
2078.                                       : "grab, but cannot hold onto",
2079.             s_suffix(mon_nam(mdef)), obj->greased ? "greased" : "slippery",
2080.             /* avoid "slippery slippery cloak"
2081.                for undiscovered oilskin cloak */
2082.             (obj->greased || objects[obj->otyp].oc_name_known)
2083.                 ? xname(obj)
2084.                 : cloak_simple_name(obj));
2085. 
2086.         if (obj->greased && !rn2(2)) {
2087.             pline_The("grease wears off.");
2088.             obj->greased = 0;
2089.         }
2090.         return TRUE;
2091.     }
2092.     return FALSE;
2093. }
2094. 
2095. /* used when hitting a monster with a lance while mounted;
2096.    1: joust hit; 0: ordinary hit; -1: joust but break lance */
2097. staticfn int
2098. joust(struct monst *mon, /* target */
2099.       struct obj *obj)   /* weapon */
2100. {
2101.     int skill_rating, joust_dieroll;
2102. 
2103.     if (Fumbling || Stunned)
2104.         return 0;
2105.     /* sanity check; lance must be wielded in order to joust */
2106.     if (obj != uwep && (obj != uswapwep || !u.twoweap))
2107.         return 0;
2108.     /* can't joust while trapped--not enough room to maneuver;
2109.      * TODO? if the steed is trapped in a pit, perhaps the hero ought to be
2110.      * able to joust against a monster that's in a conjoined pit */
2111.     if (u.utrap)
2112.         return 0;
2113. 
2114.     /* if using two weapons, use worse of lance and two-weapon skills */
2115.     skill_rating = P_SKILL(weapon_type(obj)); /* lance skill */
2116.     if (u.twoweap && P_SKILL(P_TWO_WEAPON_COMBAT) < skill_rating)
2117.         skill_rating = P_SKILL(P_TWO_WEAPON_COMBAT);
2118.     if (skill_rating == P_ISRESTRICTED)
2119.         skill_rating = P_UNSKILLED; /* 0=>1 */
2120. 
2121.     /* odds to joust are expert:80%, skilled:60%, basic:40%, unskilled:20% */
2122.     if ((joust_dieroll = rn2(5)) < skill_rating) {
2123.         if (joust_dieroll == 0 && rnl(50) == (50 - 1) && !unsolid(mon->data)
2124.             && !obj_resists(obj, 0, 100))
2125.             return -1; /* hit that breaks lance */
2126.         return 1;      /* successful joust */
2127.     }
2128.     return 0; /* no joust bonus; revert to ordinary attack */
2129. }
2130. 
2131. /* send in a demon pet for the hero; exercise wisdom */
2132. staticfn void
2133. demonpet(void)
2134. {
2135.     int i;
2136.     struct permonst *pm;
2137.     struct monst *dtmp;
2138. 
2139.     pline("Some hell-p has arrived!");
2140.     i = !rn2(6) ? ndemon(u.ualign.type) : NON_PM;
2141.     pm = i != NON_PM ? &mons[i] : gy.youmonst.data;
2142.     if ((dtmp = makemon(pm, u.ux, u.uy, NO_MM_FLAGS)) != 0)
2143.         (void) tamedog(dtmp, (struct obj *) 0, FALSE);
2144.     exercise(A_WIS, TRUE);
2145. }
2146. 
2147. staticfn boolean
2148. theft_petrifies(struct obj *otmp)
2149. {
2150.     if (uarmg || otmp->otyp != CORPSE
2151.         || !touch_petrifies(&mons[otmp->corpsenm]) || Stone_resistance)
2152.         return FALSE;
2153. 
2154. #if 0   /* no poly_when_stoned() critter has theft capability */
2155.     if (poly_when_stoned(gy.youmonst.data) && polymon(PM_STONE_GOLEM)) {
2156.         display_nhwindow(WIN_MESSAGE, FALSE);   /* --More-- */
2157.         return TRUE;
2158.     }
2159. #endif
2160. 
2161.     /* stealing this corpse is fatal... */
2162.     instapetrify(corpse_xname(otmp, "stolen", CXN_ARTICLE));
2163.     /* apparently wasn't fatal after all... */
2164.     return TRUE;
2165. }
2166. 
2167. /*
2168.  * Player uses theft attack against monster.
2169.  *
2170.  * If the target is wearing body armor, take all of its possessions;
2171.  * otherwise, take one object.  [Is this really the behavior we want?]
2172.  */
2173. staticfn void
2174. steal_it(struct monst *mdef, struct attack *mattk)
2175. {
2176.     struct obj *otmp, *gold = 0, *ustealo, **minvent_ptr;
2177.     long unwornmask;
2178. 
2179.     otmp = mdef->minvent;
2180.     if (!otmp || (otmp->oclass == COIN_CLASS && !otmp->nobj))
2181.         return; /* nothing to take */
2182. 
2183.     /* look for worn body armor */
2184.     ustealo = (struct obj *) 0;
2185.     if (could_seduce(&gy.youmonst, mdef, mattk) && mdef->mcanmove) {
2186.         /* find armor, and move it to end of inventory in the process */
2187.         minvent_ptr = &mdef->minvent;
2188.         while ((otmp = *minvent_ptr) != 0)
2189.             if (otmp->owornmask & W_ARM) {
2190.                 if (ustealo)
2191.                     panic("steal_it: multiple worn suits");
2192.                 *minvent_ptr = otmp->nobj; /* take armor out of minvent */
2193.                 ustealo = otmp;
2194.                 ustealo->nobj = (struct obj *) 0;
2195.             } else {
2196.                 minvent_ptr = &otmp->nobj;
2197.             }
2198.         *minvent_ptr = ustealo; /* put armor back into minvent */
2199.     }
2200.     gold = findgold(mdef->minvent);
2201. 
2202.     if (ustealo) { /* we will be taking everything */
2203.         char heshe[20];
2204. 
2205.         /* 5.0: this uses hero's base gender rather than nymph femininity
2206.            but was using hardcoded pronouns She/her for target monster;
2207.            switch to dynamic pronoun */
2208.         if (gender(mdef) == (int) u.mfemale
2209.             && gy.youmonst.data->mlet == S_NYMPH)
2210.             You("charm %s.  %s gladly hands over %s%s possessions.",
2211.                 mon_nam(mdef), upstart(strcpy(heshe, mhe(mdef))),
2212.                 !gold ? "" : "most of ", mhis(mdef));
2213.         else
2214.             You("seduce %s and %s starts to take off %s clothes.",
2215.                 mon_nam(mdef), mhe(mdef), mhis(mdef));
2216.     }
2217. 
2218.     /* prevent gold from being stolen so that steal-item isn't a superset
2219.        of steal-gold; shuffling it out of minvent before selecting next
2220.        item, and then back in case hero or monster dies (hero touching
2221.        stolen c'trice corpse or monster wielding one and having gloves
2222.        stolen) is less bookkeeping than skipping it within the loop or
2223.        taking it out once and then trying to figure out how to put it back */
2224.     if (gold)
2225.         obj_extract_self(gold);
2226. 
2227.     while ((otmp = mdef->minvent) != 0) {
2228.         if (gold) /* put 'mdef's gold back after remembering mdef->minvent */
2229.             mpickobj(mdef, gold), gold = 0;
2230.         if (!Upolyd)
2231.             break; /* no longer have ability to steal */
2232.         unwornmask = otmp->owornmask;
2233.         /* this would take place when doname() formats the object for
2234.            the hold_another_object() call, but we want to do it before
2235.            otmp gets removed from mdef's inventory */
2236.         if (otmp->oartifact && !Blind)
2237.             find_artifact(otmp);
2238.         /* take the object away from the monster */
2239.         extract_from_minvent(mdef, otmp, TRUE, FALSE);
2240.         /* special message for final item; no need to check owornmask because
2241.          * ustealo is only set on objects with (owornmask & W_ARM) */
2242.         if (otmp == ustealo)
2243.             pline("%s finishes taking off %s suit.", Monnam(mdef),
2244.                   mhis(mdef));
2245.         /* give the object to the character */
2246.         otmp = hold_another_object(otmp, "You snatched but dropped %s.",
2247.                                    doname(otmp), "You steal: ");
2248.         /* might have dropped otmp, and it might have broken or left level */
2249.         if (!otmp || otmp->where != OBJ_INVENT)
2250.             continue;
2251.         if (theft_petrifies(otmp))
2252.             break; /* stop thieving even though hero survived */
2253.         /* more take-away handling, after theft message */
2254.         if (unwornmask & W_WEP) { /* stole wielded weapon */
2255.             possibly_unwield(mdef, FALSE);
2256.         } else if (unwornmask & W_ARMG) { /* stole worn gloves */
2257.             mselftouch(mdef, (const char *) 0, TRUE);
2258.             if (DEADMONSTER(mdef)) /* it's now a statue */
2259.                 break; /* can't continue stealing */
2260.         }
2261. 
2262.         if (!ustealo)
2263.             break; /* only taking one item */
2264. 
2265.         /* take gold out of minvent before making next selection; if it
2266.            is the only thing left, the loop will terminate and it will be
2267.            put back below */
2268.         if ((gold = findgold(mdef->minvent)) != 0)
2269.             obj_extract_self(gold);
2270.     }
2271. 
2272.     /* put gold back; won't happen if either hero or 'mdef' dies because
2273.        gold will be back in monster's inventory at either of those times
2274.        (so will be present in mdef's minvent for bones, or in its statue
2275.        now if it has just been turned into one) */
2276.     if (gold)
2277.         mpickobj(mdef, gold);
2278. }
2279. 
2280. void
2281. mhitm_ad_rust(
2282.     struct monst *magr, struct attack *mattk,
2283.     struct monst *mdef, struct mhitm_data *mhm)
2284. {
2285.     struct permonst *pd = mdef->data;
2286. 
2287.     if (magr == &gy.youmonst) {
2288.         /* uhitm */
2289.         if (completelyrusts(pd)) { /* iron golem */
2290.             /* note: the life-saved case is hypothetical because
2291.                life-saving doesn't work for golems */
2292.             pline("%s %s to pieces!", Monnam(mdef),
2293.                   !mlifesaver(mdef) ? "falls" : "starts to fall");
2294.             xkilled(mdef, XKILL_NOMSG);
2295.             mhm->hitflags |= M_ATTK_DEF_DIED;
2296.         }
2297.         erode_armor(mdef, ERODE_RUST);
2298.         mhm->damage = 0; /* damageum(), int tmp */
2299.     } else if (mdef == &gy.youmonst) {
2300.         /* mhitu */
2301.         hitmsg(magr, mattk);
2302.         if (magr->mcan) {
2303.             return;
2304.         }
2305.         if (completelyrusts(pd)) {
2306.             You("rust!");
2307.             /* KMH -- this is okay with unchanging */
2308.             rehumanize();
2309.             return;
2310.         }
2311.         erode_armor(&gy.youmonst, ERODE_RUST);
2312.     } else {
2313.         /* mhitm */
2314.         if (magr->mcan)
2315.             return;
2316.         if (completelyrusts(pd)) { /* PM_IRON_GOLEM */
2317.             if (gv.vis && canseemon(mdef))
2318.                 pline_mon(mdef, "%s %s to pieces!", Monnam(mdef),
2319.                       !mlifesaver(mdef) ? "falls" : "starts to fall");
2320.             monkilled(mdef, (char *) 0, AD_RUST);
2321.             if (!DEADMONSTER(mdef)) {
2322.                 mhm->hitflags = M_ATTK_MISS;
2323.                 mhm->done = TRUE;
2324.                 return;
2325.             }
2326.             mhm->hitflags = (M_ATTK_DEF_DIED | (grow_up(magr, mdef) ? 0
2327.                                             : M_ATTK_AGR_DIED));
2328.             mhm->done = TRUE;
2329.             return;
2330.         }
2331.         erode_armor(mdef, ERODE_RUST);
2332.         mdef->mstrategy &= ~STRAT_WAITFORU;
2333.         mhm->damage = 0; /* mdamagem(), int tmp */
2334.     }
2335. }
2336. 
2337. void
2338. mhitm_ad_corr(
2339.     struct monst *magr, struct attack *mattk,
2340.     struct monst *mdef, struct mhitm_data *mhm)
2341. {
2342.     if (magr == &gy.youmonst) {
2343.         /* uhitm */
2344.         erode_armor(mdef, ERODE_CORRODE);
2345.         mhm->damage = 0;
2346.     } else if (mdef == &gy.youmonst) {
2347.         /* mhitu */
2348.         hitmsg(magr, mattk);
2349.         if (magr->mcan)
2350.             return;
2351.         erode_armor(mdef, ERODE_CORRODE);
2352.     } else {
2353.         /* mhitm */
2354.         if (magr->mcan)
2355.             return;
2356.         erode_armor(mdef, ERODE_CORRODE);
2357.         mdef->mstrategy &= ~STRAT_WAITFORU;
2358.         mhm->damage = 0;
2359.     }
2360. }
2361. 
2362. void
2363. mhitm_ad_dcay(
2364.     struct monst *magr, struct attack *mattk,
2365.     struct monst *mdef, struct mhitm_data *mhm)
2366. {
2367.     struct permonst *pd = mdef->data;
2368. 
2369.     if (magr == &gy.youmonst) {
2370.         /* uhitm */
2371.         if (completelyrots(pd)) { /* wood golem or leather golem */
2372.             pline("%s %s to pieces!", Monnam(mdef),
2373.                   !mlifesaver(mdef) ? "falls" : "starts to fall");
2374.             xkilled(mdef, XKILL_NOMSG);
2375.         }
2376.         erode_armor(mdef, ERODE_ROT);
2377.         mhm->damage = 0;
2378.     } else if (mdef == &gy.youmonst) {
2379.         /* mhitu */
2380.         hitmsg(magr, mattk);
2381.         if (magr->mcan)
2382.             return;
2383.         if (completelyrots(pd)) {
2384.             You("rot!");
2385.             /* KMH -- this is okay with unchanging */
2386.             rehumanize();
2387.             return;
2388.         }
2389.         erode_armor(mdef, ERODE_ROT);
2390.     } else {
2391.         /* mhitm */
2392.         if (magr->mcan)
2393.             return;
2394.         if (completelyrots(pd)) { /* PM_WOOD_GOLEM || PM_LEATHER_GOLEM */
2395.             /* note: the life-saved case is hypothetical because
2396.                life-saving doesn't work for golems */
2397.             if (gv.vis && canseemon(mdef))
2398.                 pline_mon(mdef, "%s %s to pieces!", Monnam(mdef),
2399.                       !mlifesaver(mdef) ? "falls" : "starts to fall");
2400.             monkilled(mdef, (char *) 0, AD_DCAY);
2401.             if (!DEADMONSTER(mdef)) {
2402.                 mhm->done = TRUE;
2403.                 mhm->hitflags = M_ATTK_MISS;
2404.                 return;
2405.             }
2406.             mhm->done = TRUE;
2407.             mhm->hitflags = (M_ATTK_DEF_DIED
2408.                              | (grow_up(magr, mdef) ? 0 : M_ATTK_AGR_DIED));
2409.             return;
2410.         }
2411.         erode_armor(mdef, ERODE_ROT);
2412.         mdef->mstrategy &= ~STRAT_WAITFORU;
2413.         mhm->damage = 0;
2414.     }
2415. }
2416. 
2417. void
2418. mhitm_ad_dren(
2419.     struct monst *magr, struct attack *mattk,
2420.     struct monst *mdef, struct mhitm_data *mhm)
2421. {
2422.     boolean negated = mhitm_mgc_atk_negated(magr, mdef, FALSE);
2423. 
2424.     if (magr == &gy.youmonst) {
2425.         /* uhitm */
2426.         if (!negated && !rn2(4))
2427.             xdrainenergym(mdef, TRUE);
2428.         mhm->damage = 0;
2429.     } else if (mdef == &gy.youmonst) {
2430.         /* mhitu */
2431.         hitmsg(magr, mattk);
2432.         if (!negated && !rn2(4)) /* 25% chance */
2433.             drain_en(mhm->damage, FALSE);
2434.         mhm->damage = 0;
2435.     } else {
2436.         /* mhitm */
2437.         if (!negated && !rn2(4))
2438.             xdrainenergym(mdef, (boolean) (gv.vis && canspotmon(mdef)
2439.                                            && mattk->aatyp != AT_ENGL));
2440.         mhm->damage = 0;
2441.     }
2442. }
2443. 
2444. void
2445. mhitm_ad_drli(
2446.     struct monst *magr, struct attack *mattk,
2447.     struct monst *mdef, struct mhitm_data *mhm)
2448. {
2449.     if (magr == &gy.youmonst) {
2450.         /* uhitm */
2451.         if (!rn2(3) && !(resists_drli(mdef) || defended(mdef, AD_DRLI))
2452.             && !mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2453.             mhm->damage = d(2, 6); /* Stormbringer uses monhp_per_lvl
2454.                                     * (usually 1d8) */
2455.             pline("%s becomes weaker!", Monnam(mdef));
2456.             if (mdef->mhpmax - mhm->damage > (int) mdef->m_lev) {
2457.                 mdef->mhpmax -= mhm->damage;
2458.             } else {
2459.                 /* limit floor of mhpmax reduction to current m_lev + 1;
2460.                    avoid increasing it if somehow already less than that */
2461.                 if (mdef->mhpmax > (int) mdef->m_lev)
2462.                     mdef->mhpmax = (int) mdef->m_lev + 1;
2463.             }
2464.             mdef->mhp -= mhm->damage;
2465.             /* !m_lev: level 0 monster is killed regardless of hit points
2466.                rather than drop to level -1; note: some non-living creatures
2467.                (golems, vortices) are subject to life-drain */
2468.             if (DEADMONSTER(mdef) || !mdef->m_lev) {
2469.                 pline("%s %s!", Monnam(mdef),
2470.                       nonliving(mdef->data) ? "expires" : "dies");
2471.                 xkilled(mdef, XKILL_NOMSG);
2472.             } else
2473.                 mdef->m_lev--;
2474.             mhm->damage = 0; /* damage has already been inflicted */
2475. 
2476.             /* unlike hitting with Stormbringer, wounded hero doesn't
2477.                heal any from the drained life */
2478.         }
2479.     } else if (mdef == &gy.youmonst) {
2480.         /* mhitu */
2481.         hitmsg(magr, mattk);
2482.         if (!rn2(3) && !Drain_resistance
2483.             && !mhitm_mgc_atk_negated(magr, mdef, TRUE)){
2484.             losexp("life drainage");
2485. 
2486.             /* unlike hitting with Stormbringer, wounded attacker doesn't
2487.                heal any from the drained life */
2488.         }
2489.     } else {
2490.         /* mhitm */
2491.         /* mhitm_ad_deth gets redirected here for Death's touch */
2492.         boolean is_death = (mattk->adtyp == AD_DETH);
2493. 
2494.         if (is_death
2495.             || (!rn2(3) && !(resists_drli(mdef) || defended(mdef, AD_DRLI))
2496.                 && !mhitm_mgc_atk_negated(magr, mdef, TRUE))) {
2497.             if (!is_death) /* Stormbringer uses monhp_per_lvl (1d8) */
2498.                 mhm->damage = d(2, 6);
2499.             if (gv.vis && canspotmon(mdef))
2500.                 pline_mon(mdef, "%s becomes weaker!", Monnam(mdef));
2501.             if (mdef->mhpmax - mhm->damage > (int) mdef->m_lev) {
2502.                 mdef->mhpmax -= mhm->damage;
2503.             } else {
2504.                 /* limit floor of mhpmax reduction to current m_lev + 1;
2505.                    avoid increasing it if somehow already less than that */
2506.                 if (mdef->mhpmax > (int) mdef->m_lev)
2507.                     mdef->mhpmax = (int) mdef->m_lev + 1;
2508.             }
2509.             if (mdef->m_lev == 0) /* automatic kill if drained past level 0 */
2510.                 mhm->damage = mdef->mhp;
2511.             else
2512.                 mdef->m_lev--;
2513. 
2514.             /* unlike hitting with Stormbringer, wounded attacker doesn't
2515.                heal any from the drained life */
2516.         }
2517.     }
2518. }
2519. 
2520. void
2521. mhitm_ad_fire(
2522.     struct monst *magr, struct attack *mattk,
2523.     struct monst *mdef, struct mhitm_data *mhm)
2524. {
2525.     struct permonst *pd = mdef->data;
2526.     const int orig_dmg = mhm->damage; /* damage coming into the function */
2527. 
2528.     if (magr == &gy.youmonst) {
2529.         /* uhitm */
2530.         if (mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2531.             mhm->damage = 0;
2532.             return;
2533.         }
2534.         if (!Blind)
2535.             pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk));
2536.         if (completelyburns(pd)) { /* paper golem or straw golem */
2537.             if (!Blind)
2538.                 /* note: the life-saved case is hypothetical because
2539.                    life-saving doesn't work for golems */
2540.                 pline("%s %s!", Monnam(mdef),
2541.                       !mlifesaver(mdef) ? "burns completely"
2542.                                         : "is totally engulfed in flames");
2543.             else
2544.                 You("smell burning%s.",
2545.                     (pd == &mons[PM_PAPER_GOLEM]) ? " paper"
2546.                       : (pd == &mons[PM_STRAW_GOLEM]) ? " straw" : "");
2547.             xkilled(mdef, XKILL_NOMSG | XKILL_NOCORPSE);
2548.             mhm->damage = 0;
2549.             return;
2550.             /* Don't return yet; keep hp<1 and mhm.damage=0 for pet msg */
2551.         }
2552.         if (resists_fire(mdef) || defended(mdef, AD_FIRE)) {
2553.             if (!Blind)
2554.                 pline_The("fire doesn't heat %s!", mon_nam(mdef));
2555.             golemeffects(mdef, AD_FIRE, mhm->damage);
2556.             shieldeff(mdef->mx, mdef->my);
2557.             mhm->damage = 0;
2558.         }
2559.         mhm->damage += destroy_items(mdef, AD_FIRE, orig_dmg);
2560.         ignite_items(mdef->minvent);
2561.     } else if (mdef == &gy.youmonst) {
2562.         /* mhitu */
2563.         hitmsg(magr, mattk);
2564.         if (!mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2565.             pline("You're %s!", on_fire(pd, mattk));
2566.             if (completelyburns(pd)) { /* paper or straw golem */
2567.                 You("go up in flames!");
2568.                 monstunseesu(M_SEEN_FIRE);
2569.                 /* KMH -- this is okay with unchanging */
2570.                 rehumanize();
2571.                 return;
2572.             } else if (Fire_resistance) {
2573.                 pline_The("fire doesn't feel hot!");
2574.                 monstseesu(M_SEEN_FIRE);
2575.                 mhm->damage = 0;
2576.             } else {
2577.                 monstunseesu(M_SEEN_FIRE);
2578.             }
2579.             if ((int) magr->m_lev > rn2(20)) {
2580.                 (void) destroy_items(&gy.youmonst, AD_FIRE, orig_dmg);
2581.                 ignite_items(gi.invent);
2582.             }
2583.             burn_away_slime();
2584.         } else {
2585.             mhm->damage = 0;
2586.         }
2587.     } else {
2588.         /* mhitm */
2589.         if (mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2590.             mhm->damage = 0;
2591.             return;
2592.         }
2593.         if (gv.vis && canseemon(mdef))
2594.             pline_mon(mdef, "%s is %s!", Monnam(mdef), on_fire(pd, mattk));
2595.         if (completelyburns(pd)) { /* paper golem or straw golem */
2596.             /* note: the life-saved case is hypothetical because
2597.                life-saving doesn't work for golems */
2598.             if (gv.vis && canseemon(mdef))
2599.                 pline_mon(mdef, "%s %s!", Monnam(mdef),
2600.                       !mlifesaver(mdef) ? "burns completely"
2601.                                         : "is totally engulfed in flames");
2602.             monkilled(mdef, (char *) 0, AD_FIRE);
2603.             if (!DEADMONSTER(mdef)) {
2604.                 mhm->hitflags = M_ATTK_MISS;
2605.                 mhm->done = TRUE;
2606.                 return;
2607.             }
2608.             mhm->hitflags = (M_ATTK_DEF_DIED
2609.                              | (grow_up(magr, mdef) ? 0 : M_ATTK_AGR_DIED));
2610.             mhm->done = TRUE;
2611.             return;
2612.         }
2613.         if (resists_fire(mdef) || defended(mdef, AD_FIRE)) {
2614.             if (gv.vis && canseemon(mdef))
2615.                 pline_The("fire doesn't seem to burn %s!", mon_nam(mdef));
2616.             shieldeff(mdef->mx, mdef->my);
2617.             golemeffects(mdef, AD_FIRE, mhm->damage);
2618.             mhm->damage = 0;
2619.         }
2620.         mhm->damage += destroy_items(mdef, AD_FIRE, orig_dmg);
2621.         ignite_items(mdef->minvent);
2622.     }
2623. }
2624. 
2625. void
2626. mhitm_ad_cold(
2627.     struct monst *magr, struct attack *mattk,
2628.     struct monst *mdef, struct mhitm_data *mhm)
2629. {
2630.     const int orig_dmg = mhm->damage;
2631. 
2632.     if (magr == &gy.youmonst) {
2633.         /* uhitm */
2634.         if (mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2635.             mhm->damage = 0;
2636.             return;
2637.         }
2638.         if (!Blind)
2639.             pline("%s is covered in frost!", Monnam(mdef));
2640.         if (resists_cold(mdef) || defended(mdef, AD_COLD)) {
2641.             shieldeff(mdef->mx, mdef->my);
2642.             if (!Blind)
2643.                 pline_The("frost doesn't chill %s!", mon_nam(mdef));
2644.             golemeffects(mdef, AD_COLD, mhm->damage);
2645.             mhm->damage = 0;
2646.         }
2647.         mhm->damage += destroy_items(mdef, AD_COLD, orig_dmg);
2648.     } else if (mdef == &gy.youmonst) {
2649.         /* mhitu */
2650.         hitmsg(magr, mattk);
2651.         if (!mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2652.             pline("You're covered in frost!");
2653.             if (Cold_resistance) {
2654.                 pline_The("frost doesn't seem cold!");
2655.                 monstseesu(M_SEEN_COLD);
2656.                 mhm->damage = 0;
2657.             } else {
2658.                 monstunseesu(M_SEEN_COLD);
2659.             }
2660.             if ((int) magr->m_lev > rn2(20))
2661.                 (void) destroy_items(&gy.youmonst, AD_COLD, orig_dmg);
2662.         } else
2663.             mhm->damage = 0;
2664.     } else {
2665.         /* mhitm */
2666.         if (mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2667.             mhm->damage = 0;
2668.             return;
2669.         }
2670.         if (gv.vis && canseemon(mdef))
2671.             pline_mon(mdef, "%s is covered in frost!", Monnam(mdef));
2672.         if (resists_cold(mdef) || defended(mdef, AD_COLD)) {
2673.             if (gv.vis && canseemon(mdef))
2674.                 pline_The("frost doesn't seem to chill %s!", mon_nam(mdef));
2675.             shieldeff(mdef->mx, mdef->my);
2676.             golemeffects(mdef, AD_COLD, mhm->damage);
2677.             mhm->damage = 0;
2678.         }
2679.         mhm->damage += destroy_items(mdef, AD_COLD, orig_dmg);
2680.     }
2681. }
2682. 
2683. void
2684. mhitm_ad_elec(
2685.     struct monst *magr, struct attack *mattk,
2686.     struct monst *mdef, struct mhitm_data *mhm)
2687. {
2688.     const int orig_dmg = mhm->damage;
2689. 
2690.     if (magr == &gy.youmonst) {
2691.         /* uhitm */
2692.         if (mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2693.             mhm->damage = 0;
2694.             return;
2695.         }
2696.         if (!Blind)
2697.             pline("%s is zapped!", Monnam(mdef));
2698.         if (resists_elec(mdef) || defended(mdef, AD_ELEC)) {
2699.             if (!Blind)
2700.                 pline_The("zap doesn't shock %s!", mon_nam(mdef));
2701.             golemeffects(mdef, AD_ELEC, mhm->damage);
2702.             shieldeff(mdef->mx, mdef->my);
2703.             mhm->damage = 0;
2704.         }
2705.         mhm->damage += destroy_items(mdef, AD_ELEC, orig_dmg);
2706.     } else if (mdef == &gy.youmonst) {
2707.         /* mhitu */
2708.         hitmsg(magr, mattk);
2709.         if (!mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2710.             You("get zapped!");
2711.             if (Shock_resistance) {
2712.                 pline_The("zap doesn't shock you!");
2713.                 monstseesu(M_SEEN_ELEC);
2714.                 mhm->damage = 0;
2715.             } else {
2716.                 monstunseesu(M_SEEN_ELEC);
2717.             }
2718.             if ((int) magr->m_lev > rn2(20))
2719.                 (void) destroy_items(&gy.youmonst, AD_ELEC, orig_dmg);
2720.         } else
2721.             mhm->damage = 0;
2722.     } else {
2723.         /* mhitm */
2724.         if (mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2725.             mhm->damage = 0;
2726.             return;
2727.         }
2728.         if (gv.vis && canseemon(mdef))
2729.             pline_mon(mdef, "%s gets zapped!", Monnam(mdef));
2730.         if (resists_elec(mdef) || defended(mdef, AD_ELEC)) {
2731.             if (gv.vis && canseemon(mdef))
2732.                 pline_The("zap doesn't shock %s!", mon_nam(mdef));
2733.             shieldeff(mdef->mx, mdef->my);
2734.             golemeffects(mdef, AD_ELEC, mhm->damage);
2735.             mhm->damage = 0;
2736.         }
2737.         mhm->damage += destroy_items(mdef, AD_ELEC, orig_dmg);
2738.     }
2739. }
2740. 
2741. void
2742. mhitm_ad_acid(
2743.     struct monst *magr, struct attack *mattk,
2744.     struct monst *mdef, struct mhitm_data *mhm)
2745. {
2746.     if (magr == &gy.youmonst) {
2747.         /* uhitm */
2748.         if (resists_acid(mdef) || defended(mdef, AD_ACID))
2749.             mhm->damage = 0;
2750.     } else if (mdef == &gy.youmonst) {
2751.         /* mhitu */
2752.         hitmsg(magr, mattk);
2753.         if (!magr->mcan && !rn2(3))
2754.             if (Acid_resistance) {
2755.                 pline("You're covered in %s, but it seems harmless.",
2756.                       hliquid("acid"));
2757.                 monstseesu(M_SEEN_ACID);
2758.                 mhm->damage = 0;
2759.             } else {
2760.                 pline("You're covered in %s!  It burns!", hliquid("acid"));
2761.                 exercise(A_STR, FALSE);
2762.                 monstunseesu(M_SEEN_ACID);
2763.             }
2764.         else
2765.             mhm->damage = 0;
2766.     } else {
2767.         /* mhitm */
2768.         if (magr->mcan) {
2769.             mhm->damage = 0;
2770.             return;
2771.         }
2772.         if (resists_acid(mdef) || defended(mdef, AD_ACID)) {
2773.             if (gv.vis && canseemon(mdef))
2774.                 pline("%s is covered in %s, but it seems harmless.",
2775.                       Monnam(mdef), hliquid("acid"));
2776.             mhm->damage = 0;
2777.         } else if (gv.vis && canseemon(mdef)) {
2778.             pline_mon(mdef, "%s is covered in %s!", Monnam(mdef), hliquid("acid"));
2779.             pline("It burns %s!", mon_nam(mdef));
2780.         }
2781.         if (!rn2(30))
2782.             erode_armor(mdef, ERODE_CORRODE);
2783.         if (!rn2(6))
2784.             acid_damage(MON_WEP(mdef));
2785.     }
2786. }
2787. 
2788. /* steal gold */
2789. void
2790. mhitm_ad_sgld(
2791.     struct monst *magr, struct attack *mattk,
2792.     struct monst *mdef, struct mhitm_data *mhm)
2793. {
2794.     struct permonst *pa = magr->data;
2795.     struct permonst *pd = mdef->data;
2796. 
2797.     if (magr == &gy.youmonst) {
2798.         /* uhitm */
2799.         struct obj *mongold = findgold(mdef->minvent);
2800. 
2801.         if (mongold) {
2802.             obj_extract_self(mongold);
2803.             if (merge_choice(gi.invent, mongold)
2804.                     || inv_cnt(FALSE) < invlet_basic) {
2805.                 addinv(mongold);
2806.                 Your("purse feels heavier.");
2807.             } else {
2808.                 You("grab %s's gold, but find no room in your knapsack.",
2809.                     mon_nam(mdef));
2810.                 dropy(mongold);
2811.             }
2812.         }
2813.         exercise(A_DEX, TRUE);
2814.         mhm->damage = 0;
2815.     } else if (mdef == &gy.youmonst) {
2816.         /* mhitu */
2817.         hitmsg(magr, mattk);
2818.         if (pd->mlet == pa->mlet)
2819.             return;
2820.         if (!magr->mcan)
2821.             stealgold(magr);
2822.     } else {
2823.         /* mhitm */
2824.         char buf[BUFSZ];
2825. 
2826.         mhm->damage = 0;
2827.         if (magr->mcan)
2828.             return;
2829.         /* technically incorrect; no check for stealing gold from
2830.          * between mdef's feet...
2831.          */
2832.         {
2833.             struct obj *gold = findgold(mdef->minvent);
2834. 
2835.             if (!gold)
2836.                 return;
2837.             obj_extract_self(gold);
2838.             add_to_minv(magr, gold);
2839.         }
2840.         mdef->mstrategy &= ~STRAT_WAITFORU;
2841.         Strcpy(buf, Monnam(magr));
2842.         if (gv.vis && canseemon(mdef)) {
2843.             pline("%s steals some gold from %s.", buf, mon_nam(mdef));
2844.         }
2845.         if (!tele_restrict(magr)) {
2846.             boolean couldspot = canspotmon(magr);
2847. 
2848.             mhm->hitflags = M_ATTK_AGR_DONE;
2849.             (void) rloc(magr, RLOC_NOMSG);
2850.             /* TODO: use RLOC_MSG instead? */
2851.             if (gv.vis && couldspot && !canspotmon(magr))
2852.                 pline("%s suddenly disappears!", buf);
2853.         }
2854.     }
2855. }
2856. 
2857. 
2858. void
2859. mhitm_ad_tlpt(
2860.     struct monst *magr, struct attack *mattk,
2861.     struct monst *mdef, struct mhitm_data *mhm)
2862. {
2863.     if (magr == &gy.youmonst) {
2864.         /* uhitm */
2865.         if (mhm->damage <= 0)
2866.             mhm->damage = 1;
2867.         if (mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2868.             pline("%s is not affected.", Monnam(mdef));
2869.         } else {
2870.             char nambuf[BUFSZ];
2871.             boolean u_saw_mon = (canseemon(mdef) || engulfing_u(mdef));
2872. 
2873.             /* record the name before losing sight of monster */
2874.             Strcpy(nambuf, Monnam(mdef));
2875.             if (u_teleport_mon(mdef, FALSE) && u_saw_mon
2876.                 && !(canseemon(mdef) || engulfing_u(mdef)))
2877.                 pline("%s suddenly disappears!", nambuf);
2878.             if (mhm->damage >= mdef->mhp) { /* see hitmu(mhitu.c) */
2879.                 if (mdef->mhp == 1)
2880.                     ++mdef->mhp;
2881.                 mhm->damage = mdef->mhp - 1;
2882.             }
2883.         }
2884.     } else if (mdef == &gy.youmonst) {
2885.         /* mhitu */
2886.         int tmphp;
2887. 
2888.         hitmsg(magr, mattk);
2889.         if (mhitm_mgc_atk_negated(magr, mdef, FALSE)) {
2890.             You("are not affected.");
2891.         } else {
2892.             if (flags.verbose)
2893.                 Your("position suddenly seems %suncertain!",
2894.                      (Teleport_control && !Stunned && !unconscious()) ? ""
2895.                      : "very ");
2896.             tele();
2897.             /* As of 3.6.2:  make sure damage isn't fatal; previously, it
2898.                was possible to be teleported and then drop dead at
2899.                the destination when QM's 1d4 damage gets applied below;
2900.                even though that wasn't "wrong", it seemed strange,
2901.                particularly if the teleportation had been controlled
2902.                [applying the damage first and not teleporting if fatal
2903.                is another alternative but it has its own complications] */
2904.             if ((Half_physical_damage ? (mhm->damage - 1) / 2 : mhm->damage)
2905.                 >= (tmphp = (Upolyd ? u.mh : u.uhp))) {
2906.                 mhm->damage = tmphp - 1;
2907.                 if (Half_physical_damage)
2908.                     mhm->damage *= 2; /* doesn't actually increase damage;
2909.                                        * we only get here if half the
2910.                                        * original damage would have
2911.                                        * been fatal, so double reduced
2912.                                        * damage will be less than original */
2913.                 if (mhm->damage < 1) { /* implies (tmphp <= 1) */
2914.                     mhm->damage = 1;
2915.                     /* this might increase current HP beyond maximum HP but it
2916.                        will be immediately reduced by caller, so that should
2917.                        be indistinguishable from zero damage; we don't drop
2918.                        damage all the way to zero because that inhibits any
2919.                        passive counterattack if poly'd hero has one */
2920.                     if (Upolyd && u.mh == 1)
2921.                         ++u.mh;
2922.                     else if (!Upolyd && u.uhp == 1)
2923.                         ++u.uhp;
2924.                     /* [don't set context.botl here] */
2925.                 }
2926.             }
2927.         }
2928.     } else {
2929.         /* mhitm */
2930.         if (magr->mcan || mhm->damage >= mdef->mhp || tele_restrict(mdef)) {
2931.             ; /* no negation message */
2932.         } else if (mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
2933.             if (gv.vis)
2934.                 pline_mon(mdef, "%s is not affected.", Monnam(mdef));
2935.         } else {
2936.             char mdef_Monnam[BUFSZ];
2937.             boolean wasseen = canspotmon(mdef);
2938. 
2939.             /* save the name before monster teleports, otherwise
2940.                we'll get "it" in the suddenly disappears message */
2941.             if (gv.vis && wasseen)
2942.                 Strcpy(mdef_Monnam, Monnam(mdef));
2943.             mdef->mstrategy &= ~STRAT_WAITFORU;
2944.             (void) rloc(mdef, RLOC_NOMSG);
2945.             /* TODO: use RLOC_MSG instead? */
2946.             if (gv.vis && wasseen && !canspotmon(mdef) && mdef != u.usteed)
2947.                 pline("%s suddenly disappears!", mdef_Monnam);
2948.             if (mhm->damage >= mdef->mhp) { /* see hitmu(mhitu.c) */
2949.                 if (mdef->mhp == 1)
2950.                     ++mdef->mhp;
2951.                 mhm->damage = mdef->mhp - 1;
2952.             }
2953.         }
2954.     }
2955. }
2956. 
2957. void
2958. mhitm_ad_blnd(
2959.     struct monst *magr,     /* attacker */
2960.     struct attack *mattk,   /* magr's attack */
2961.     struct monst *mdef,     /* defender */
2962.     struct mhitm_data *mhm) /* optional for monster vs monster */
2963. {
2964.     if (magr == &gy.youmonst) {
2965.         /* uhitm */
2966.         if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) {
2967.             if (!Blind && mdef->mcansee)
2968.                 pline("%s is blinded.", Monnam(mdef));
2969.             mdef->mcansee = 0;
2970.             mhm->damage += mdef->mblinded;
2971.             if (mhm->damage > 127)
2972.                 mhm->damage = 127;
2973.             mdef->mblinded = mhm->damage;
2974.         }
2975.         mhm->damage = 0;
2976.     } else if (mdef == &gy.youmonst) {
2977.         /* mhitu */
2978.         if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) {
2979.             if (!Blind)
2980.                 pline("%s blinds you!", Monnam(magr));
2981.             make_blinded(BlindedTimeout + (long) mhm->damage, FALSE);
2982.             if (!Blind) /* => Eyes of the Overworld */
2983.                 Your1(vision_clears);
2984.         }
2985.         mhm->damage = 0;
2986.     } else {
2987.         /* mhitm */
2988.         if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) {
2989.             char buf[BUFSZ];
2990.             unsigned rnd_tmp;
2991. 
2992.             if (gv.vis && mdef->mcansee && canspotmon(mdef)) {
2993.                 /* feedback for becoming blinded is given if observed
2994.                    telepathically (canspotmon suffices) but additional
2995.                    info about archon's glow is only given if seen */
2996.                 Snprintf(buf, sizeof buf, "%s is blinded", Monnam(mdef));
2997.                 if (mdef->data == &mons[PM_ARCHON] && canseemon(mdef))
2998.                     Snprintf(eos(buf), sizeof buf - strlen(buf),
2999.                              " by %s radiance", s_suffix(mon_nam(magr)));
3000.                 pline("%s.", buf);
3001.             }
3002.             rnd_tmp = d((int) mattk->damn, (int) mattk->damd);
3003.             if ((rnd_tmp += mdef->mblinded) > 127)
3004.                 rnd_tmp = 127;
3005.             mdef->mblinded = rnd_tmp;
3006.             mdef->mcansee = 0;
3007.             mdef->mstrategy &= ~STRAT_WAITFORU;
3008.         }
3009.         if (mhm)
3010.             mhm->damage = 0;
3011.     }
3012. }
3013. 
3014. void
3015. mhitm_ad_curs(
3016.     struct monst *magr, struct attack *mattk,
3017.     struct monst *mdef, struct mhitm_data *mhm)
3018. {
3019.     struct permonst *pa = magr->data;
3020.     struct permonst *pd = mdef->data;
3021. 
3022.     if (magr == &gy.youmonst) {
3023.         /* uhitm */
3024.         if (night() && !rn2(10) && !mdef->mcan) {
3025.             if (pd == &mons[PM_CLAY_GOLEM]) {
3026.                 if (!Blind)
3027.                     pline("Some writing vanishes from %s head!",
3028.                           s_suffix(mon_nam(mdef)));
3029.                 xkilled(mdef, XKILL_NOMSG);
3030.                 /* Don't return yet; keep hp<1 and mhm.damage=0 for pet msg */
3031.             } else {
3032.                 mdef->mcan = 1;
3033.                 You("chuckle.");
3034.             }
3035.         }
3036.         mhm->damage = 0;
3037.     } else if (mdef == &gy.youmonst) {
3038.         /* mhitu */
3039.         hitmsg(magr, mattk);
3040.         if (!night() && pa == &mons[PM_GREMLIN])
3041.             return;
3042.         if (!magr->mcan && !rn2(10)) {
3043.             if (!Deaf) {
3044.                 Soundeffect(se_laughter, 40);
3045.                 if (Blind) {
3046.                     You_hear("laughter.");
3047.                 } else {
3048.                     pline_mon(magr, "%s chuckles.", Monnam(magr));
3049.                 }
3050.             }
3051.             if (u.umonnum == PM_CLAY_GOLEM) {
3052.                 pline("Some writing vanishes from your head!");
3053.                 /* KMH -- this is okay with unchanging */
3054.                 rehumanize();
3055.                 return;
3056.             }
3057.             mon_give_prop(magr, attrcurse());
3058.         }
3059.     } else {
3060.         /* mhitm */
3061.         if (!night() && (pa == &mons[PM_GREMLIN]))
3062.             return;
3063.         if (!magr->mcan && !rn2(10)) {
3064.             mdef->mcan = 1; /* cancelled regardless of lifesave */
3065.             mdef->mstrategy &= ~STRAT_WAITFORU;
3066.             if (is_were(pd) && pd->mlet != S_HUMAN)
3067.                 were_change(mdef);
3068.             if (pd == &mons[PM_CLAY_GOLEM]) {
3069.                 if (gv.vis && canseemon(mdef)) {
3070.                     pline("Some writing vanishes from %s head!",
3071.                           s_suffix(mon_nam(mdef)));
3072.                     pline_mon(mdef, "%s is destroyed!", Monnam(mdef));
3073.                 }
3074.                 mondied(mdef);
3075.                 if (!DEADMONSTER(mdef)) {
3076.                     mhm->hitflags = M_ATTK_MISS;
3077.                     mhm->done = TRUE;
3078.                     return;
3079.                 } else if (mdef->mtame && !gv.vis) {
3080.                     You(brief_feeling, "strangely sad");
3081.                 }
3082.                 mhm->hitflags = (M_ATTK_DEF_DIED
3083.                                  | (grow_up(magr, mdef) ? 0
3084.                                     : M_ATTK_AGR_DIED));
3085.                 mhm->done = TRUE;
3086.                 return;
3087.             }
3088.             if (!Deaf) {
3089.                 if (!gv.vis)
3090.                     You_hear("laughter.");
3091.                 else if (canseemon(magr))
3092.                     pline_mon(magr, "%s chuckles.", Monnam(magr));
3093.             }
3094.         }
3095.     }
3096. }
3097. 
3098. /* Helper for mhitm_ad_drst(), containing some code that is also called from
3099.  * mhitm_ad_phys (for poisoned weapons) and shouldn't be subject to magic
3100.  * cancellation or a 1/8 chance roll.
3101.  * In this specific case, the "mhitm" in the name ACTUALLY means just that -
3102.  * this should be called only for monster versus monster situations. */
3103. staticfn void
3104. mhitm_really_poison(struct monst *magr, struct attack *mattk,
3105.                     struct monst *mdef, struct mhitm_data *mhm)
3106. {
3107.     if (gv.vis && canspotmon(magr))
3108.         pline("%s %s was poisoned!", s_suffix(Monnam(magr)),
3109.               mpoisons_subj(magr, mattk));
3110.     if (resists_poison(mdef)) {
3111.         if (gv.vis && canspotmon(mdef) && canspotmon(magr))
3112.             pline_The("poison doesn't seem to affect %s.",
3113.                         mon_nam(mdef));
3114.     } else {
3115.         mhm->damage += rn1(10, 6);
3116.         if (mhm->damage >= mdef->mhp && gv.vis && canspotmon(mdef))
3117.             pline_The("poison was deadly...");
3118.     }
3119. }
3120. 
3121. void
3122. mhitm_ad_drst(
3123.     struct monst *magr, struct attack *mattk,
3124.     struct monst *mdef, struct mhitm_data *mhm)
3125. {
3126.     boolean negated = mhitm_mgc_atk_negated(magr, mdef, FALSE);
3127.     struct permonst *pa = magr->data;
3128. 
3129.     if (magr == &gy.youmonst) {
3130.         /* uhitm */
3131.         if (!negated && !rn2(8)) {
3132.             Your("%s was poisoned!", mpoisons_subj(magr, mattk));
3133.             if (resists_poison(mdef)) {
3134.                 pline_The("poison doesn't seem to affect %s.", mon_nam(mdef));
3135.             } else {
3136.                 if (!rn2(10)) {
3137.                     Your("poison was deadly...");
3138.                     mhm->damage = mdef->mhp;
3139.                 } else
3140.                     mhm->damage += rn1(10, 6);
3141.             }
3142.         }
3143.     } else if (mdef == &gy.youmonst) {
3144.         /* mhitu */
3145.         int ptmp = A_STR;  /* A_STR == 0 */
3146.         char buf[BUFSZ];
3147. 
3148.         switch (mattk->adtyp) {
3149.         case AD_DRST: ptmp = A_STR; break;
3150.         case AD_DRDX: ptmp = A_DEX; break;
3151.         case AD_DRCO: ptmp = A_CON; break;
3152.         }
3153.         hitmsg(magr, mattk);
3154.         if (!negated && !rn2(8)) {
3155.             Sprintf(buf, "%s %s", s_suffix(Monnam(magr)),
3156.                     mpoisons_subj(magr, mattk));
3157.             poisoned(buf, ptmp, pmname(pa, Mgender(magr)), 30, FALSE);
3158.         }
3159.     } else {
3160.         /* mhitm */
3161.         if (!negated && !rn2(8)) {
3162.             mhitm_really_poison(magr, mattk, mdef, mhm);
3163.         }
3164.     }
3165. }
3166. 
3167. void
3168. mhitm_ad_drin(
3169.     struct monst *magr, struct attack *mattk,
3170.     struct monst *mdef, struct mhitm_data *mhm)
3171. {
3172.     struct permonst *pd = mdef->data;
3173.     struct obj *amu;
3174.     boolean lifsav;
3175. 
3176.     /*
3177.      * Mind flayers have multiple AD_DRIN attacks (3 for plain mind flayer,
3178.      * 5 for master mind flayer).  If one of those kills the target, skip
3179.      * the others (for rest of attacker's current move).  To check whether
3180.      * hero has been killed, we check mortality counter.  For a monster,
3181.      * we check whether it was wearing an amulet of life-saving before the
3182.      * attack and no longer wearing any amulet after the attack.
3183.      */
3184. 
3185.     if (magr == &gy.youmonst) {
3186.         /* uhitm */
3187.         struct obj *helmet;
3188. 
3189.         if (gn.notonhead || !has_head(pd)) {
3190.             pline("%s doesn't seem harmed.", Monnam(mdef));
3191.             /* hero should skip remaining AT_TENT+AD_DRIN attacks
3192.                because they'll be just as harmless as this one (and also
3193.                to reduce verbosity) */
3194.             gs.skipdrin = TRUE;
3195.             mhm->damage = 0;
3196.             if (!Unchanging && pd == &mons[PM_GREEN_SLIME]) {
3197.                 if (!Slimed) {
3198.                     You("suck in some slime and don't feel very well.");
3199.                     make_slimed(10L, (char *) 0);
3200.                 }
3201.             }
3202.             return;
3203.         }
3204.         if (m_slips_free(mdef, mattk))
3205.             return;
3206. 
3207.         if ((helmet = which_armor(mdef, W_ARMH)) != 0 && rn2(8)) {
3208.             pline("%s %s blocks your attack to %s head.",
3209.                   s_suffix(Monnam(mdef)), helm_simple_name(helmet),
3210.                   mhis(mdef));
3211.             return;
3212.         }
3213.         amu = which_armor(mdef, W_AMUL);
3214.         lifsav = amu && amu->otyp == AMULET_OF_LIFE_SAVING;
3215. 
3216.         (void) eat_brains(&gy.youmonst, mdef, TRUE, &mhm->damage);
3217. 
3218.         /* skip further AD_DRIN if amulet of life-saving got used up */
3219.         if (lifsav && !which_armor(mdef, W_AMUL))
3220.             gs.skipdrin = TRUE;
3221. 
3222.     } else if (mdef == &gy.youmonst) {
3223.         /* mhitu */
3224.         hitmsg(magr, mattk);
3225.         if (defends(AD_DRIN, uwep) || !has_head(pd)) {
3226.             You("don't seem harmed.");
3227.             /* attacker should skip remaining AT_TENT+AD_DRIN attacks */
3228.             gs.skipdrin = TRUE;
3229.             /* Not clear what to do for green slimes */
3230.             return;
3231.         }
3232.         if (u_slip_free(magr, mattk))
3233.             return;
3234. 
3235.         if (uarmh && rn2(8)) {
3236.             /* not body_part(HEAD) */
3237.             Your("%s blocks the attack to your head.",
3238.                  helm_simple_name(uarmh));
3239.             return;
3240.         }
3241.         /* negative armor class doesn't reduce this damage */
3242.         if (Half_physical_damage)
3243.             mhm->damage = (mhm->damage + 1) / 2;
3244.         mdamageu(magr, mhm->damage);
3245.         mhm->damage = 0; /* don't inflict a second dose below */
3246. 
3247.         if (!uarmh || uarmh->otyp != DUNCE_CAP) {
3248.             int oldmort = u.umortality,
3249.                 mhitu = eat_brains(magr, mdef, TRUE, (int *) 0);
3250. 
3251.             /* skip further AD_DRIN if hero's number of deaths went up */
3252.             if (u.umortality > oldmort)
3253.                 gs.skipdrin = TRUE;
3254.             /* eat_brains() will miss if target is mindless (won't
3255.                happen here--hero is considered to retain his mind
3256.                regardless of current shape) or is noncorporeal
3257.                (can't happen here--no one can poly into a ghost
3258.                or shade) so this check for missing is academic */
3259.             if (mhitu == M_ATTK_MISS)
3260.                 return;
3261.         }
3262.         /* adjattrib gives dunce cap message when appropriate */
3263.         (void) adjattrib(A_INT, -rnd(2), FALSE);
3264.         if (!rn2(5)) {
3265.             losespells();
3266.             gs.skipdrin = TRUE;
3267.         }
3268.         if (!rn2(5)) {
3269.             drain_weapon_skill(rnd(2));
3270.             gs.skipdrin = TRUE;
3271.         }
3272.     } else {
3273.         /* mhitm */
3274.         char buf[BUFSZ];
3275. 
3276.         if (gn.notonhead || !has_head(pd)) {
3277.             if (gv.vis && canspotmon(mdef))
3278.                 pline_mon(mdef, "%s doesn't seem harmed.", Monnam(mdef));
3279.             /* Not clear what to do for green slimes */
3280.             mhm->damage = 0;
3281.             /* don't bother with additional DRIN attacks since they wouldn't
3282.                be able to hit target on head either */
3283.             gs.skipdrin = TRUE; /* affects mattackm()'s attack loop */
3284.             return;
3285.         }
3286.         if ((mdef->misc_worn_check & W_ARMH) && rn2(8)) {
3287.             if (gv.vis && canspotmon(magr) && canseemon(mdef)) {
3288.                 Strcpy(buf, s_suffix(Monnam(mdef)));
3289.                 pline("%s helmet blocks %s attack to %s head.", buf,
3290.                       s_suffix(mon_nam(magr)), mhis(mdef));
3291.             }
3292.             return;
3293.         }
3294.         amu = which_armor(mdef, W_AMUL);
3295.         lifsav = amu && amu->otyp == AMULET_OF_LIFE_SAVING;
3296. 
3297.         mhm->hitflags = eat_brains(magr, mdef, gv.vis, &mhm->damage);
3298. 
3299.         /* skip further AD_DRIN if amulet of life-saving got used up */
3300.         if (lifsav && !which_armor(mdef, W_AMUL))
3301.             gs.skipdrin = TRUE;
3302.     }
3303. }
3304. 
3305. void
3306. mhitm_ad_stck(
3307.     struct monst *magr, struct attack *mattk,
3308.     struct monst *mdef, struct mhitm_data *mhm)
3309. {
3310.     boolean negated = mhitm_mgc_atk_negated(magr, mdef, FALSE);
3311.     struct permonst *pd = mdef->data;
3312.     boolean barbs = (magr->data == &mons[PM_BARBED_DEVIL]);
3313. 
3314.     if (magr == &gy.youmonst) {
3315.         /* uhitm */
3316.         if (!negated && !sticks(pd) && m_next2u(mdef)) {
3317.             set_ustuck(mdef); /* it's now stuck to you */
3318.             if (barbs)
3319.                 Your("barbs stick to %s!", y_monnam(mdef));
3320.         }
3321.     } else if (mdef == &gy.youmonst) {
3322.         /* mhitu */
3323.         hitmsg(magr, mattk);
3324.         if (!negated && !u.ustuck && !sticks(pd)) {
3325.             set_ustuck(magr);
3326.             if (barbs)
3327.                 pline("The barbs stick to you!");
3328.         }
3329.     } else {
3330.         /* mhitm */
3331.         if (negated)
3332.             mhm->damage = 0;
3333.     }
3334. }
3335. 
3336. void
3337. mhitm_ad_wrap(
3338.     struct monst *magr, struct attack *mattk,
3339.     struct monst *mdef, struct mhitm_data *mhm)
3340. {
3341.     struct permonst *pd = mdef->data, *pa = magr->data;
3342.     boolean coil = slithy(pa) && (pa->mlet == S_SNAKE || pa->mlet == S_NAGA);
3343. 
3344.     if (magr == &gy.youmonst) {
3345.         /* uhitm */
3346.         if (!sticks(pd)) {
3347.             boolean tailmiss = !gn.notonhead;
3348. 
3349.             if (!u.ustuck && !tailmiss && !rn2(10)) {
3350.                 if (m_slips_free(mdef, mattk)) {
3351.                     mhm->damage = 0;
3352.                 } else {
3353.                     You("%s yourself around %s!",
3354.                         coil ? "coil" : "swing", mon_nam(mdef));
3355.                     set_ustuck(mdef);
3356.                 }
3357.             } else if (u.ustuck == mdef && !tailmiss) {
3358.                 /* Monsters don't wear amulets of magical breathing */
3359.                 if (is_pool(u.ux, u.uy) && !cant_drown(pd)) {
3360.                     You("drown %s...", mon_nam(mdef));
3361.                     mhm->damage = mdef->mhp;
3362.                 } else if (mattk->aatyp == AT_HUGS)
3363.                     pline("%s is being crushed.", Monnam(mdef));
3364.             } else {
3365.                 mhm->damage = 0;
3366.                 if (flags.verbose) {
3367.                     if (coil && !tailmiss)
3368.                         You("brush against %s.", mon_nam(mdef));
3369.                     else
3370.                         You("brush against %s %s.", s_suffix(mon_nam(mdef)),
3371.                             tailmiss ? "tail" : mbodypart(mdef, LEG));
3372.                 }
3373.             }
3374.         } else
3375.             mhm->damage = 0;
3376.     } else if (mdef == &gy.youmonst) {
3377.         /* mhitu */
3378.         if ((!magr->mcan || u.ustuck == magr) && !sticks(pd)) {
3379.             if (!u.ustuck && !rn2(10)) {
3380.                 if (u_slip_free(magr, mattk)) {
3381.                     mhm->damage = 0;
3382.                 } else {
3383.                     set_ustuck(magr); /* before message, for botl update */
3384.                     urgent_pline("%s %s itself around you!",
3385.                                  Some_Monnam(magr),
3386.                                  coil ? "coils" : "swings");
3387.                 }
3388.             } else if (u.ustuck == magr) {
3389.                 if (is_pool(magr->mx, magr->my) && !Swimming && !Amphibious
3390.                     && !Breathless) {
3391.                     boolean moat = (levl[magr->mx][magr->my].typ != POOL)
3392.                                    && !is_waterwall(magr->mx, magr->my)
3393.                                    && !Is_medusa_level(&u.uz)
3394.                                    && !Is_waterlevel(&u.uz);
3395. 
3396.                     urgent_pline("%s drowns you...", Monnam(magr));
3397.                     svk.killer.format = KILLED_BY_AN;
3398.                     Sprintf(svk.killer.name, "%s by %s",
3399.                             moat ? "moat" : "pool of water",
3400.                             an(pmname(magr->data, Mgender(magr))));
3401.                     done(DROWNING);
3402.                 } else if (mattk->aatyp == AT_HUGS) {
3403.                     You("are being crushed.");
3404.                 }
3405.             } else {
3406.                 mhm->damage = 0;
3407.                 if (flags.verbose) {
3408.                     if (coil)
3409.                         pline_mon(magr, "%s brushes against you.",
3410.                                   Monnam(magr));
3411.                     else
3412.                         pline_mon(magr, "%s brushes against your %s.",
3413.                                   Monnam(magr), body_part(LEG));
3414.                 }
3415.             }
3416.         } else
3417.             mhm->damage = 0;
3418.     } else {
3419.         /* mhitm */
3420.         if (magr->mcan)
3421.             mhm->damage = 0;
3422. 
3423.         if (!mhm->damage && (canseemon(magr) || canseemon(mdef))) {
3424.             pline("%s brushes against %s.",
3425.                   Some_Monnam(magr), some_mon_nam(mdef));
3426.         }
3427.     }
3428. }
3429. 
3430. void
3431. mhitm_ad_plys(
3432.     struct monst *magr, struct attack *mattk,
3433.     struct monst *mdef, struct mhitm_data *mhm)
3434. {
3435.     if (magr == &gy.youmonst) {
3436.         /* uhitm */
3437.         if (!rn2(3) && mhm->damage < mdef->mhp
3438.             && !mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
3439.             if (!Blind)
3440.                 pline("%s is frozen by you!", Monnam(mdef));
3441.             paralyze_monst(mdef, rnd(10));
3442.         }
3443.     } else if (mdef == &gy.youmonst) {
3444.         /* mhitu */
3445.         hitmsg(magr, mattk);
3446.         if (gm.multi >= 0 && !rn2(3)
3447.             && !mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
3448.             if (Free_action) {
3449.                 You("momentarily stiffen.");
3450.             } else {
3451.                 if (Blind)
3452.                     You("are frozen!");
3453.                 else
3454.                     You("are frozen by %s!", mon_nam(magr));
3455.                 gn.nomovemsg = You_can_move_again;
3456.                 nomul(-rnd(10));
3457.                 /* set gm.multi_reason;
3458.                    3.6.x used "paralyzed by a monster"; be more specific */
3459.                 dynamic_multi_reason(magr, "paralyzed", FALSE);
3460.                 exercise(A_DEX, FALSE);
3461.             }
3462.         }
3463.     } else {
3464.         /* mhitm */
3465.         if (mdef->mcanmove && !rn2(3)
3466.             && !mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
3467.             if (gv.vis && canspotmon(mdef)) {
3468.                 char buf[BUFSZ];
3469. 
3470.                 Strcpy(buf, Monnam(mdef));
3471.                 pline("%s is frozen by %s.", buf, mon_nam(magr));
3472.             }
3473.             paralyze_monst(mdef, rnd(10));
3474.         }
3475.     }
3476. }
3477. 
3478. void
3479. mhitm_ad_slee(
3480.     struct monst *magr, struct attack *mattk,
3481.     struct monst *mdef,
3482.     struct mhitm_data *mhm UNUSED)
3483. {
3484.     if (magr == &gy.youmonst) {
3485.         /* uhitm */
3486.         if (!mdef->msleeping && !mhitm_mgc_atk_negated(magr, mdef, FALSE)
3487.             && sleep_monst(mdef, rnd(10), -1)) {
3488.             if (!Blind)
3489.                 pline("%s is put to sleep by you!", Monnam(mdef));
3490.             slept_monst(mdef);
3491.         }
3492.     } else if (mdef == &gy.youmonst) {
3493.         /* mhitu */
3494.         hitmsg(magr, mattk);
3495.         if (gm.multi >= 0 && !rn2(5)
3496.             && !mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
3497.             if (Sleep_resistance) {
3498.                 monstseesu(M_SEEN_SLEEP);
3499.                 return;
3500.             }
3501.             monstunseesu(M_SEEN_SLEEP);
3502.             fall_asleep(-rnd(10), TRUE);
3503.             if (Blind)
3504.                 You("are put to sleep!");
3505.             else
3506.                 You("are put to sleep by %s!", mon_nam(magr));
3507.         }
3508.     } else {
3509.         /* mhitm */
3510.         if (!mdef->msleeping && sleep_monst(mdef, rnd(10), -1)
3511.             && sleep_monst(mdef, rnd(10), -1)) {
3512.             if (gv.vis && canspotmon(mdef)) {
3513.                 char buf[BUFSZ];
3514. 
3515.                 Strcpy(buf, Monnam(mdef));
3516.                 pline("%s is put to sleep by %s.", buf, mon_nam(magr));
3517.             }
3518.             mdef->mstrategy &= ~STRAT_WAITFORU;
3519.             slept_monst(mdef);
3520.         }
3521.     }
3522. }
3523. 
3524. /* slime */
3525. void
3526. mhitm_ad_slim(
3527.     struct monst *magr, struct attack *mattk,
3528.     struct monst *mdef, struct mhitm_data *mhm)
3529. {
3530.     boolean negated = mhitm_mgc_atk_negated(magr, mdef, FALSE);
3531.     struct permonst *pd = mdef->data;
3532. 
3533.     if (magr == &gy.youmonst) {
3534.         /* uhitm */
3535.         if (negated)
3536.             return; /* physical damage only */
3537.         if (!rn2(4) && !slimeproof(pd)) {
3538.             if (!munslime(mdef, TRUE) && !DEADMONSTER(mdef)) {
3539.                 /* this assumes newcham() won't fail; since hero has
3540.                    a slime attack, green slimes haven't been geno'd */
3541.                 You("turn %s into slime.", mon_nam(mdef));
3542.                 if (newcham(mdef, &mons[PM_GREEN_SLIME], NO_NC_FLAGS))
3543.                     pd = mdef->data;
3544.             }
3545.             /* munslime attempt could have been fatal */
3546.             if (DEADMONSTER(mdef)) {
3547.                 mhm->hitflags = M_ATTK_DEF_DIED; /* skip death message */
3548.                 mhm->done = TRUE;
3549.                 return;
3550.             }
3551.             mhm->damage = 0;
3552.         }
3553.     } else if (mdef == &gy.youmonst) {
3554.         /* mhitu */
3555.         hitmsg(magr, mattk);
3556.         if (negated) {
3557.             if (!magr->mcan)
3558.                 You("escape harm.");
3559.             return;
3560.         }
3561.         if (flaming(pd)) {
3562.             pline_The("slime burns away!");
3563.             mhm->damage = 0;
3564.         } else if (Unchanging || noncorporeal(pd)
3565.                    || pd == &mons[PM_GREEN_SLIME]) {
3566.             You("are unaffected.");
3567.             mhm->damage = 0;
3568.         } else if (!Slimed) {
3569.             You("don't feel very well.");
3570.             make_slimed(10L, (char *) 0);
3571.             delayed_killer(SLIMED, KILLED_BY_AN,
3572.                            pmname(magr->data, Mgender(magr)));
3573.         } else
3574.             pline("Yuck!");
3575.     } else {
3576.         /* mhitm */
3577.         if (negated)
3578.             return; /* physical damage only */
3579.         if (!rn2(4) && !slimeproof(pd)) {
3580.             if (!munslime(mdef, FALSE) && !DEADMONSTER(mdef)) {
3581.                 unsigned ncflags = NO_NC_FLAGS;
3582. 
3583.                 if (gv.vis && canseemon(mdef))
3584.                     ncflags |= NC_SHOW_MSG;
3585.                 if (newcham(mdef, &mons[PM_GREEN_SLIME], ncflags))
3586.                     pd = mdef->data;
3587.                 mdef->mstrategy &= ~STRAT_WAITFORU;
3588.                 mhm->hitflags = M_ATTK_HIT;
3589.             }
3590.             /* munslime attempt could have been fatal,
3591.                potentially to multiple monsters (SCR_FIRE) */
3592.             if (DEADMONSTER(magr))
3593.                 mhm->hitflags |= M_ATTK_AGR_DIED;
3594.             if (DEADMONSTER(mdef))
3595.                 mhm->hitflags |= M_ATTK_DEF_DIED;
3596.             mhm->damage = 0;
3597.         }
3598.     }
3599.     nhUse(pd);
3600. }
3601. 
3602. void
3603. mhitm_ad_ench(
3604.     struct monst *magr, struct attack *mattk,
3605.     struct monst *mdef,
3606.     struct mhitm_data *mhm UNUSED)
3607. {
3608.     if (magr == &gy.youmonst) {
3609.         /* uhitm */
3610.         /* there's no msomearmor() function, so just do damage */
3611.     } else if (mdef == &gy.youmonst) {
3612.         /* mhitu */
3613.         boolean negated = mhitm_mgc_atk_negated(magr, mdef, FALSE);
3614. 
3615.         hitmsg(magr, mattk);
3616.         /* uncancelled is sufficient enough; please
3617.            don't make this attack less frequent */
3618.         if (!negated) {
3619.             struct obj *obj = some_armor(mdef);
3620. 
3621.             if (!obj) {
3622.                 /* some rings are susceptible;
3623.                    amulets and blindfolds aren't (at present) */
3624.                 switch (rn2(5)) {
3625.                 case 0:
3626.                     break;
3627.                 case 1:
3628.                     obj = uright;
3629.                     break;
3630.                 case 2:
3631.                     obj = uleft;
3632.                     break;
3633.                 case 3:
3634.                     obj = uamul;
3635.                     break;
3636.                 case 4:
3637.                     obj = ublindf;
3638.                     break;
3639.                 }
3640.             }
3641.             if (obj && drain_item(obj, FALSE)) {
3642.                 pline("%s less effective.", Yobjnam2(obj, "seem"));
3643.             }
3644.         }
3645.     } else {
3646.         /* mhitm */
3647.         /* there's no msomearmor() function, so just do damage */
3648.     }
3649. }
3650. 
3651. void
3652. mhitm_ad_slow(
3653.     struct monst *magr, struct attack *mattk,
3654.     struct monst *mdef,
3655.     struct mhitm_data *mhm UNUSED)
3656. {
3657.     boolean negated = mhitm_mgc_atk_negated(magr, mdef, FALSE);
3658. 
3659.     if (defended(mdef, AD_SLOW))
3660.         return;
3661. 
3662.     if (magr == &gy.youmonst) {
3663.         /* uhitm */
3664.         if (!negated && mdef->mspeed != MSLOW) {
3665.             unsigned int oldspeed = mdef->mspeed;
3666. 
3667.             mon_adjust_speed(mdef, -1, (struct obj *) 0);
3668.             if (mdef->mspeed != oldspeed && canseemon(mdef))
3669.                 pline("%s slows down.", Monnam(mdef));
3670.         }
3671.     } else if (mdef == &gy.youmonst) {
3672.         /* mhitu */
3673.         hitmsg(magr, mattk);
3674.         if (!negated && HFast && !rn2(4))
3675.             u_slow_down();
3676.     } else {
3677.         /* mhitm */
3678.         if (!negated && mdef->mspeed != MSLOW) {
3679.             unsigned int oldspeed = mdef->mspeed;
3680. 
3681.             mon_adjust_speed(mdef, -1, (struct obj *) 0);
3682.             mdef->mstrategy &= ~STRAT_WAITFORU;
3683.             if (mdef->mspeed != oldspeed && gv.vis && canspotmon(mdef))
3684.                 pline_mon(mdef, "%s slows down.", Monnam(mdef));
3685.         }
3686.     }
3687. }
3688. 
3689. void
3690. mhitm_ad_conf(
3691.     struct monst *magr, struct attack *mattk,
3692.     struct monst *mdef, struct mhitm_data *mhm)
3693. {
3694.     if (magr == &gy.youmonst) {
3695.         /* uhitm */
3696.         if (!mdef->mconf) {
3697.             if (canseemon(mdef))
3698.                 pline("%s looks confused.", Monnam(mdef));
3699.             mdef->mconf = 1;
3700.         }
3701.     } else if (mdef == &gy.youmonst) {
3702.         /* mhitu */
3703.         hitmsg(magr, mattk);
3704.         if (!magr->mcan && !rn2(4) && !magr->mspec_used) {
3705.             magr->mspec_used = magr->mspec_used + (mhm->damage + rn2(6));
3706.             if (Confusion)
3707.                 You("are getting even more confused.");
3708.             else
3709.                 You("are getting confused.");
3710.             make_confused(HConfusion + mhm->damage, FALSE);
3711.         }
3712.         mhm->damage = 0;
3713.     } else {
3714.         /* mhitm */
3715.         /* Since confusing another monster doesn't have a real time
3716.          * limit, setting spec_used would not really be right (though
3717.          * we still should check for it).
3718.          */
3719.         if (!magr->mcan && !mdef->mconf && !magr->mspec_used) {
3720.             if (gv.vis && canseemon(mdef))
3721.                 pline_mon(mdef, "%s looks confused.", Monnam(mdef));
3722.             mdef->mconf = 1;
3723.             mdef->mstrategy &= ~STRAT_WAITFORU;
3724.         }
3725.     }
3726. }
3727. 
3728. void
3729. mhitm_ad_poly(
3730.     struct monst *magr, struct attack *mattk,
3731.     struct monst *mdef, struct mhitm_data *mhm)
3732. {
3733.     boolean negated = (mhitm_mgc_atk_negated(magr, mdef, FALSE)
3734.                        || magr->mspec_used);
3735. 
3736.     if (magr == &gy.youmonst) {
3737.         /* uhitm */
3738.         /* require weaponless attack in order to honor AD_POLY */
3739.         if (!uwep && mhm->damage < mdef->mhp) {
3740.             if (negated) {
3741.                 /* assume that you can tell by touch if blinded */
3742.                 pline("%s is not transformed.", Monnam(mdef));
3743.             } else {
3744.                 mhm->damage = mon_poly(&gy.youmonst, mdef, mhm->damage);
3745.                 if (DEADMONSTER(mdef))
3746.                     mhm->hitflags |= M_ATTK_DEF_DIED;
3747.                 mhm->hitflags |= M_ATTK_HIT;
3748.                 mhm->done = TRUE;
3749.             }
3750.         }
3751.     } else if (mdef == &gy.youmonst) {
3752.         /* mhitu */
3753.         hitmsg(magr, mattk);
3754.         if (Maybe_Half_Phys(mhm->damage) < (Upolyd ? u.mh : u.uhp)) {
3755.             if (negated) {
3756.                 if (magr->mcan)
3757.                     You("aren't transformed.");
3758.             } else {
3759.                 mhm->damage = mon_poly(magr, &gy.youmonst, mhm->damage);
3760.                 mhm->hitflags |= M_ATTK_HIT;
3761.                 mhm->done = TRUE;
3762.             }
3763.         }
3764.     } else {
3765.         /* mhitm */
3766.         if (mhm->damage < mdef->mhp && !negated) {
3767.             mhm->damage = mon_poly(magr, mdef, mhm->damage);
3768.             if (DEADMONSTER(mdef))
3769.                 mhm->hitflags |= M_ATTK_DEF_DIED;
3770.             mhm->hitflags |= M_ATTK_HIT;
3771.             mhm->done = TRUE;
3772.         }
3773.     }
3774. }
3775. 
3776. void
3777. mhitm_ad_famn(
3778.     struct monst *magr,
3779.     struct attack *mattk UNUSED,
3780.     struct monst *mdef, struct mhitm_data *mhm)
3781. {
3782.     struct permonst *pd = mdef->data;
3783. 
3784.     if (magr == &gy.youmonst) {
3785.         /* uhitm; hero can't polymorph into anything with this attack
3786.            so this won't happen; if it could, it would be the same as
3787.            the mhitm case except for messaging */
3788.         goto mhitm_famn;
3789.     } else if (mdef == &gy.youmonst) {
3790.         /* mhitu */
3791.         pline_mon(magr, "%s reaches out, and your body shrivels.",
3792.                   Monnam(magr));
3793.         exercise(A_CON, FALSE);
3794.         if (!is_fainted())
3795.             morehungry(rn1(40, 40));
3796.         /* plus the normal damage */
3797.     } else {
3798.  mhitm_famn:
3799.         /* mhitm; it's possible for Famine to hit another monster;
3800.            if target is something that doesn't eat, it won't be harmed;
3801.            otherwise, just inflict the normal damage */
3802.         if (!(carnivorous(pd) || herbivorous(pd) || metallivorous(pd)))
3803.             mhm->damage = 0;
3804.     }
3805. }
3806. 
3807. void
3808. mhitm_ad_pest(
3809.     struct monst *magr, struct attack *mattk,
3810.     struct monst *mdef, struct mhitm_data *mhm)
3811. {
3812.     struct attack alt_attk;
3813.     struct permonst *pa = magr->data;
3814. 
3815.     if (magr == &gy.youmonst) {
3816.         /* uhitm; hero can't polymorph into anything with this attack
3817.            so this won't happen; if it could, it would be the same as
3818.            the mhitm case except for messaging */
3819.         goto mhitm_pest;
3820.     } else if (mdef == &gy.youmonst) {
3821.         /* mhitu */
3822.         pline_mon(magr, "%s reaches out, and you feel fever and chills.",
3823.                   Monnam(magr));
3824.         (void) diseasemu(pa);
3825.         /* plus the normal damage */
3826.     } else {
3827.  mhitm_pest:
3828.         /* mhitm; it's possible for Pestilence to hit another monster;
3829.            treat it the same as an attack for AD_DISE damage */
3830.         alt_attk = *mattk;
3831.         alt_attk.adtyp = AD_DISE;
3832.         mhitm_ad_dise(magr, &alt_attk, mdef, mhm);
3833.     }
3834. }
3835. 
3836. void
3837. mhitm_ad_deth(
3838.     struct monst *magr,
3839.     struct attack *mattk,
3840.     struct monst *mdef, struct mhitm_data *mhm)
3841. {
3842.     struct permonst *pd = mdef->data;
3843. 
3844.     if (magr == &gy.youmonst) {
3845.         /* uhitm; hero can't polymorph into anything with this attack
3846.            so this won't happen; if it could, it would be the same as
3847.            the mhitm case except for messaging */
3848.         goto mhitm_deth;
3849.     } else if (mdef == &gy.youmonst) {
3850.         /* mhitu */
3851.         pline_mon(magr, "%s reaches out with its deadly touch.", Monnam(magr));
3852.         if (is_undead(pd)) {
3853.             /* still does some damage */
3854.             mhm->damage = (mhm->damage + 1) / 2;
3855.             pline("Was that the touch of death?");
3856.             return;
3857.         }
3858.         switch (rn2(20)) {
3859.         case 19:
3860.         case 18:
3861.         case 17:
3862.             if (!Antimagic) {
3863.                 touch_of_death(magr);
3864.                 mhm->damage = 0;
3865.                 return;
3866.             }
3867.             FALLTHROUGH;
3868.             /*FALLTHRU*/
3869.         default: /* case 16: ... case 5: */
3870.             You_feel("your life force draining away...");
3871.             mhm->permdmg = 1; /* actual damage done by caller */
3872.             return;
3873.         case 4:
3874.         case 3:
3875.         case 2:
3876.         case 1:
3877.         case 0:
3878.             if (Antimagic)
3879.                 shieldeff(u.ux, u.uy);
3880.             pline("Lucky for you, it didn't work!");
3881.             mhm->damage = 0;
3882.             return;
3883.         }
3884.     } else {
3885.  mhitm_deth:
3886.         /* mhitm; it's possible for Death to hit another monster;
3887.            if target is undead, it will take some damage but less than an
3888.            undead hero would; otherwise, just inflict the normal damage */
3889.         if (is_undead(pd) && mhm->damage > 1)
3890.             mhm->damage = rnd(mhm->damage / 2);
3891.         /* simulate Death's touch with drain life attack */
3892.         mhitm_ad_drli(magr, mattk, mdef, mhm);
3893.     }
3894. }
3895. 
3896. void
3897. mhitm_ad_halu(
3898.     struct monst *magr,
3899.     struct attack *mattk UNUSED,
3900.     struct monst *mdef, struct mhitm_data *mhm)
3901. {
3902.     struct permonst *pd = mdef->data;
3903. 
3904.     if (magr == &gy.youmonst) {
3905.         /* uhitm */
3906.         mhm->damage = 0;
3907.     } else if (mdef == &gy.youmonst) {
3908.         /* mhitu */
3909.         mhm->damage = 0;
3910.     } else {
3911.         /* mhitm */
3912.         if (!magr->mcan && haseyes(pd) && mdef->mcansee) {
3913.             if (gv.vis && canseemon(mdef))
3914.                 pline_mon(mdef, "%s looks %sconfused.", Monnam(mdef),
3915.                       mdef->mconf ? "more " : "");
3916.             mdef->mconf = 1;
3917.             mdef->mstrategy &= ~STRAT_WAITFORU;
3918.         }
3919.         mhm->damage = 0;
3920.     }
3921. }
3922. 
3923. boolean
3924. do_stone_u(struct monst *mtmp)
3925. {
3926.     if (!Stoned && !Stone_resistance
3927.         && !(poly_when_stoned(gy.youmonst.data)
3928.              && polymon(PM_STONE_GOLEM))) {
3929.         int kformat = KILLED_BY_AN;
3930.         const char *kname = pmname(mtmp->data, Mgender(mtmp));
3931. 
3932.         if (mtmp->data->geno & G_UNIQ) {
3933.             if (!type_is_pname(mtmp->data))
3934.                 kname = the(kname);
3935.             kformat = KILLED_BY;
3936.         }
3937.         make_stoned(5L, (char *) 0, kformat, kname);
3938.         return 1;
3939.         /* done_in_by(mtmp, STONING); */
3940.     }
3941.     return 0;
3942. }
3943. 
3944. void
3945. do_stone_mon(
3946.     struct monst *magr,
3947.     struct attack *mattk,
3948.     struct monst *mdef, struct mhitm_data *mhm)
3949. {
3950.     struct permonst *pd = mdef->data;
3951. 
3952.     /* may die from the acid if it eats a stone-curing corpse */
3953.     if (munstone(mdef, FALSE))
3954.         goto post_stone;
3955.     if (poly_when_stoned(pd)) {
3956.         mon_to_stone(mdef);
3957.         mhm->damage = 0;
3958.         return;
3959.     }
3960.     if (!resists_ston(mdef)) {
3961.         if (gv.vis && canseemon(mdef))
3962.             pline_mon(mdef, "%s turns to stone!", Monnam(mdef));
3963.         monstone(mdef);
3964.  post_stone:
3965.         if (!DEADMONSTER(mdef)) {
3966.             mhm->hitflags = M_ATTK_MISS;
3967.             mhm->done = TRUE;
3968.             return;
3969.         } else if (mdef->mtame && !gv.vis) {
3970.             You(brief_feeling, "peculiarly sad");
3971.         }
3972.         mhm->hitflags = (M_ATTK_DEF_DIED
3973.                          | (grow_up(magr, mdef) ? 0 : M_ATTK_AGR_DIED));
3974.         mhm->done = TRUE;
3975.         return;
3976.     }
3977.     mhm->damage = (mattk->adtyp == AD_STON ? 0 : 1);
3978. }
3979. 
3980. void
3981. mhitm_ad_phys(
3982.     struct monst *magr, struct attack *mattk,
3983.     struct monst *mdef, struct mhitm_data *mhm)
3984. {
3985.     struct permonst *pa = magr->data;
3986.     struct permonst *pd = mdef->data;
3987. 
3988.     if (magr == &gy.youmonst) {
3989.         /* uhitm */
3990.         if (pd == &mons[PM_SHADE]) {
3991.             mhm->damage = 0;
3992.             if (!mhm->specialdmg)
3993.                 impossible("bad shade attack function flow?");
3994.         }
3995.         mhm->damage += mhm->specialdmg;
3996. 
3997.         if (mattk->aatyp == AT_WEAP) {
3998.             /* hmonas() uses known_hitum() to deal physical damage,
3999.                then also damageum() for non-AD_PHYS; don't inflict
4000.                extra physical damage for unusual damage types */
4001.             mhm->damage = 0;
4002.         } else if (mattk->aatyp == AT_KICK
4003.                    || mattk->aatyp == AT_CLAW
4004.                    || mattk->aatyp == AT_TUCH
4005.                    || mattk->aatyp == AT_HUGS) {
4006.             if (thick_skinned(pd))
4007.                 mhm->damage = (mattk->aatyp == AT_KICK) ? 0
4008.                               : (mhm->damage + 1) / 2;
4009.             /* add ring(s) of increase damage */
4010.             if (u.udaminc > 0) {
4011.                 /* applies even if damage was 0 */
4012.                 mhm->damage += u.udaminc;
4013.             } else if (mhm->damage > 0) {
4014.                 /* ring(s) might be negative; avoid converting
4015.                    0 to non-0 or positive to non-positive */
4016.                 mhm->damage += u.udaminc;
4017.                 if (mhm->damage < 1)
4018.                     mhm->damage = 1;
4019.             }
4020.         }
4021.     } else if (mdef == &gy.youmonst) {
4022.         /* mhitu */
4023.         if (mattk->aatyp == AT_HUGS && !sticks(pd)) {
4024.             if (!u.ustuck && rn2(2)) {
4025.                 if (u_slip_free(magr, mattk)) {
4026.                     mhm->damage = 0;
4027.                     mhm->hitflags |= M_ATTK_MISS;
4028.                 } else {
4029.                     set_ustuck(magr);
4030.                     pline_mon(magr, "%s grabs you!", Monnam(magr));
4031.                     mhm->hitflags |= M_ATTK_HIT;
4032.                 }
4033.             } else if (u.ustuck == magr) {
4034.                 exercise(A_STR, FALSE);
4035.                 You("are being %s.",
4036.                     (pa == &mons[PM_ROPE_GOLEM]) ? "choked" : "crushed");
4037.             }
4038.         } else { /* hand to hand weapon */
4039.             struct obj *otmp = MON_WEP(magr);
4040. 
4041.             if (mattk->aatyp == AT_WEAP && otmp) {
4042.                 struct obj *marmg;
4043.                 int tmp;
4044.                 boolean was_poisoned = (otmp->opoisoned
4045.                                         || permapoisoned(otmp));
4046. 
4047.                 if (otmp->otyp == CORPSE
4048.                     && touch_petrifies(&mons[otmp->corpsenm])) {
4049.                     mhm->damage = 1;
4050.                     pline_mon(magr, "%s hits you with the %s corpse.",
4051.                               Monnam(magr),
4052.                               mons[otmp->corpsenm].pmnames[NEUTRAL]);
4053.                     if (!Stoned) {
4054.                         if (do_stone_u(magr)) {
4055.                             mhm->hitflags = M_ATTK_HIT;
4056.                             mhm->done = 1;
4057.                             return;
4058.                         }
4059.                     }
4060.                 }
4061.                 mhm->damage += dmgval(otmp, mdef);
4062.                 if ((marmg = which_armor(magr, W_ARMG)) != 0
4063.                     && marmg->otyp == GAUNTLETS_OF_POWER)
4064.                     mhm->damage += rn1(4, 3); /* 3..6 */
4065.                 if (mhm->damage <= 0)
4066.                     mhm->damage = 1;
4067.                 if (!otmp->oartifact
4068.                     || !artifact_hit(magr, mdef, otmp, &mhm->damage,
4069.                                      gm.mhitu_dieroll)) {
4070.                     hitmsg(magr, mattk);
4071.                     mhm->hitflags |= M_ATTK_HIT;
4072.                 }
4073.                 if (!mhm->damage)
4074.                     return;
4075.                 if (objects[otmp->otyp].oc_material == SILVER
4076.                     && Hate_silver) {
4077.                     pline_The("silver sears your flesh!");
4078.                     exercise(A_CON, FALSE);
4079.                 }
4080.                 /* this redundancy necessary because you have
4081.                    to take the damage _before_ being cloned;
4082.                    need to have at least 2 hp left to split */
4083.                 tmp = mhm->damage;
4084.                 if (u.uac < 0)
4085.                     tmp -= rnd(-u.uac);
4086.                 if (tmp < 1)
4087.                     tmp = 1;
4088.                 if (Half_physical_damage)
4089.                     tmp = (tmp + 1) / 2;
4090. 
4091.                 if (u.mh - tmp > 1
4092.                     && (objects[otmp->otyp].oc_material == IRON
4093.                         /* relevant 'metal' objects are scalpel and tsurugi */
4094.                         || objects[otmp->otyp].oc_material == METAL)
4095.                     && (u.umonnum == PM_BLACK_PUDDING
4096.                         || u.umonnum == PM_BROWN_PUDDING)) {
4097.                     if (tmp > 1)
4098.                         exercise(A_STR, FALSE);
4099.                     /* inflict damage now; we know it can't be fatal */
4100.                     u.mh -= tmp;
4101.                     disp.botl = TRUE;
4102.                     mhm->damage = 0; /* don't inflict more damage below */
4103.                     if (cloneu())
4104.                         You("divide as %s hits you!", mon_nam(magr));
4105.                 }
4106.                 rustm(&gy.youmonst, otmp);
4107.                 if (was_poisoned && gm.mhitu_dieroll <= 5) {
4108.                     char buf[BUFSZ];
4109. 
4110.                     /* similar to mhitm_really_poison, but we don't use the
4111.                      * exact same values, nor do we want same 1/8 chance of
4112.                      * poison taking (use 1/4, same as in the mhitm case). */
4113.                     Sprintf(buf, "%s %s", s_suffix(Monnam(magr)),
4114.                             mpoisons_subj(magr, mattk));
4115.                     /* arbitrary, but most poison sources in the game are
4116.                      * strength-based. With hpdamchance = 10, HP damage occurs
4117.                      * 1/2 of the time and it will hit Str rest of the time.
4118.                      * (This is the same as poisoned ammo.) */
4119.                     poisoned(buf, A_STR, pmname(magr->data, Mgender(magr)),
4120.                              10, FALSE);
4121.                 }
4122.             } else if (mattk->aatyp != AT_TUCH || mhm->damage != 0
4123.                        || magr != u.ustuck) {
4124.                 hitmsg(magr, mattk);
4125.                 mhm->hitflags |= M_ATTK_HIT;
4126.             }
4127.         }
4128.     } else {
4129.         /* mhitm */
4130.         struct obj *mwep = MON_WEP(magr);
4131.         boolean vis = canseemon(magr) && canseemon(mdef);
4132. 
4133.         if (mattk->aatyp != AT_WEAP && mattk->aatyp != AT_CLAW)
4134.             mwep = 0;
4135. 
4136.         if (shade_miss(magr, mdef, mwep, FALSE, vis)) {
4137.             mhm->damage = 0;
4138.         } else if (mattk->aatyp == AT_KICK && thick_skinned(pd)) {
4139.             /* [no 'kicking boots' check needed; monsters with kick attacks
4140.                can't wear boots and monsters that wear boots don't kick] */
4141.             mhm->damage = 0;
4142.         } else if (mwep) { /* non-Null 'mwep' implies AT_WEAP || AT_CLAW */
4143.             struct obj *marmg;
4144. 
4145.             if (mwep->otyp == CORPSE
4146.                 && touch_petrifies(&mons[mwep->corpsenm])) {
4147.                 do_stone_mon(magr, mattk, mdef, mhm);
4148.                 if (mhm->done)
4149.                     return;
4150.             }
4151. 
4152.             mhm->damage += dmgval(mwep, mdef);
4153.             if ((marmg = which_armor(magr, W_ARMG)) != 0
4154.                 && marmg->otyp == GAUNTLETS_OF_POWER)
4155.                 mhm->damage += rn1(4, 3); /* 3..6 */
4156.             if (mhm->damage < 1) /* is this necessary?  mhitu.c has it... */
4157.                 mhm->damage = 1;
4158.             if (mwep->oartifact) {
4159.                 /* when magr's weapon is an artifact, caller suppressed its
4160.                    usual 'hit' message in case artifact_hit() delivers one;
4161.                    now we'll know and might need to deliver skipped message
4162.                    (note: if there's no message there'll be no auxiliary
4163.                    damage so the message here isn't coming too late) */
4164.                 if (!artifact_hit(magr, mdef, mwep, &mhm->damage,
4165.                                   mhm->dieroll)) {
4166.                     if (gv.vis)
4167.                         pline_mon(magr, "%s hits %s.", Monnam(magr),
4168.                               mon_nam_too(mdef, magr));
4169.                     mhm->hitflags |= M_ATTK_HIT;
4170.                 }
4171.                 /* artifact_hit updates 'tmp' but doesn't inflict any
4172.                    damage; however, it might cause carried items to be
4173.                    destroyed and they might do so */
4174.                 if (DEADMONSTER(mdef)) {
4175.                     mhm->hitflags = (M_ATTK_DEF_DIED
4176.                                      | (grow_up(magr, mdef) ? 0
4177.                                         : M_ATTK_AGR_DIED));
4178.                     mhm->done = TRUE;
4179.                     return;
4180.                 }
4181.             }
4182.             if (mhm->damage)
4183.                 rustm(mdef, mwep);
4184.             if ((mwep->opoisoned || permapoisoned(mwep)) && !rn2(4)) {
4185.                 /* 1/4 chance of weapon poison applying is the same as in
4186.                  * uhitm and mhitu cases. But since we don't need to call
4187.                  * any special functions or go through tangled hmon_hitmon
4188.                  * code, we can just jump straight to the poisoning. */
4189.                 mhitm_really_poison(magr, mattk, mdef, mhm);
4190.             }
4191.         } else if (pa == &mons[PM_PURPLE_WORM] && pd == &mons[PM_SHRIEKER]) {
4192.             /* hack to enhance mm_aggression(); we don't want purple
4193.                worm's bite attack to kill a shrieker because then it
4194.                won't swallow the corpse; but if the target survives,
4195.                the subsequent engulf attack should accomplish that */
4196.             if (mhm->damage >= mdef->mhp && mdef->mhp > 1)
4197.                 mhm->damage = mdef->mhp - 1;
4198.         }
4199.     }
4200. }
4201. 
4202. void
4203. mhitm_ad_ston(
4204.     struct monst *magr, struct attack *mattk,
4205.     struct monst *mdef, struct mhitm_data *mhm)
4206. {
4207.     if (magr == &gy.youmonst) {
4208.         /* uhitm */
4209.         if (!munstone(mdef, TRUE))
4210.             minstapetrify(mdef, TRUE);
4211.         mhm->damage = 0;
4212.     } else if (mdef == &gy.youmonst) {
4213.         /* mhitu */
4214.         hitmsg(magr, mattk);
4215.         if (!rn2(3)) {
4216.             if (magr->mcan) {
4217.                 if (!Deaf)
4218.                     You_hear("a cough from %s!", mon_nam(magr));
4219.             } else {
4220.                 if (Hallucination && !Blind) {
4221.                     Soundeffect(se_cockatrice_hiss, 50);
4222.                     You_hear("hissing."); /* You_hear() deals with Deaf */
4223.                     pline("%s appears to be blowing you a kiss...",
4224.                           Monnam(magr));
4225.                 } else if (!Deaf) {
4226.                     You_hear("%s hissing!", s_suffix(mon_nam(magr)));
4227.                 } else if (!Blind) {
4228.                     pline("%s seems to grimace.", Monnam(magr));
4229.                 }
4230.                 /*
4231.                  * 5.0:  New moon is no longer overridden by carrying a
4232.                  * lizard corpse.  Having the moon's impact on terrestrial
4233.                  * activity be affected by carrying a dead critter felt
4234.                  * silly.
4235.                  *
4236.                  * That behavior dated to when there were no corpse objects
4237.                  * yet; "dead lizard" was a distinct item.  With a lizard
4238.                  * corpse, hero can eat it to survive petrification and
4239.                  * probably retain a partly eaten corpse for future use.
4240.                  *
4241.                  * Maintaining foodless conduct during a new moon might
4242.                  * become a little harder.  Clearing out cockatrice nests
4243.                  * during a new moon could become quite a bit harder.
4244.                  */
4245.                 if (!rn2(10) || flags.moonphase == NEW_MOON) {
4246.                     if (do_stone_u(magr)) {
4247.                         mhm->hitflags = M_ATTK_HIT;
4248.                         mhm->done = TRUE;
4249.                         return;
4250.                     }
4251.                 }
4252.             }
4253.         }
4254.     } else {
4255.         /* mhitm */
4256.         if (magr->mcan)
4257.             return;
4258.         do_stone_mon(magr, mattk, mdef, mhm);
4259.         if (mhm->done)
4260.             return;
4261.     }
4262. }
4263. 
4264. void
4265. mhitm_ad_were(
4266.     struct monst *magr, struct attack *mattk,
4267.     struct monst *mdef, struct mhitm_data *mhm)
4268. {
4269.     struct permonst *pa = magr->data;
4270. 
4271.     if (magr == &gy.youmonst) {
4272.         /* uhitm */
4273.         mhitm_ad_phys(magr, mattk, mdef, mhm);
4274.         if (mhm->done)
4275.             return;
4276.     } else if (mdef == &gy.youmonst) {
4277.         /* mhitu */
4278.         hitmsg(magr, mattk);
4279.         if (!rn2(4) && u.ulycn == NON_PM
4280.             && !Protection_from_shape_changers && !defends(AD_WERE, uwep)
4281.             && !mhitm_mgc_atk_negated(magr, mdef, TRUE)) {
4282.             urgent_pline("You feel feverish.");
4283.             exercise(A_CON, FALSE);
4284.             set_ulycn(monsndx(pa));
4285.             retouch_equipment(2);
4286.         }
4287.     } else {
4288.         /* mhitm */
4289.         mhitm_ad_phys(magr, mattk, mdef, mhm);
4290.         if (mhm->done)
4291.             return;
4292.     }
4293. }
4294. 
4295. void
4296. mhitm_ad_heal(
4297.     struct monst *magr, struct attack *mattk,
4298.     struct monst *mdef, struct mhitm_data *mhm)
4299. {
4300.     struct permonst *pd = mdef->data;
4301. 
4302.     if (magr == &gy.youmonst) {
4303.         /* uhitm */
4304.         mhitm_ad_phys(magr, mattk, mdef, mhm);
4305.         if (mhm->done)
4306.             return;
4307.     } else if (mdef == &gy.youmonst) {
4308.         /* mhitu */
4309.         /* a cancelled nurse is just an ordinary monster,
4310.          * nurses don't heal those that cause petrification */
4311.         if (magr->mcan || (Upolyd && touch_petrifies(pd))) {
4312.             hitmsg(magr, mattk);
4313.             return;
4314.         }
4315.         /* weapon check should match the one in sounds.c for MS_NURSE */
4316.         if (!(uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))
4317.             && !uarmu && !uarm && !uarmc
4318.             && !uarms && !uarmg && !uarmf && !uarmh) {
4319.             boolean goaway = FALSE;
4320. 
4321.             pline_mon(magr, "%s hits!  (I hope you don't mind.)",
4322.                       Monnam(magr));
4323.             if (Upolyd) {
4324.                 u.mh += rnd(7);
4325.                 if (!rn2(7)) {
4326.                     /* no upper limit necessary; effect is temporary */
4327.                     u.mhmax++;
4328.                     if (!rn2(13))
4329.                         goaway = TRUE;
4330.                 }
4331.                 if (u.mh > u.mhmax)
4332.                     u.mh = u.mhmax;
4333.             } else {
4334.                 u.uhp += rnd(7);
4335.                 if (!rn2(7)) {
4336.                     /* hard upper limit via nurse care: 25 * ulevel */
4337.                     if (u.uhpmax < 5 * u.ulevel + d(2 * u.ulevel, 10)) {
4338.                         u.uhpmax++;
4339.                         if (u.uhpmax > u.uhppeak)
4340.                             u.uhppeak = u.uhpmax;
4341.                     }
4342.                     if (!rn2(13))
4343.                         goaway = TRUE;
4344.                 }
4345.                 if (u.uhp > u.uhpmax)
4346.                     u.uhp = u.uhpmax;
4347.             }
4348.             if (!rn2(3))
4349.                 exercise(A_STR, TRUE);
4350.             if (!rn2(3))
4351.                 exercise(A_CON, TRUE);
4352.             if (Sick)
4353.                 make_sick(0L, (char *) 0, FALSE, SICK_ALL);
4354.             disp.botl = TRUE;
4355.             if (goaway) {
4356.                 mongone(magr);
4357.                 mhm->done = TRUE;
4358.                 mhm->hitflags = M_ATTK_DEF_DIED; /* return 2??? */
4359.                 return;
4360.             } else if (!rn2(33)) {
4361.                 if (!tele_restrict(magr))
4362.                     (void) rloc(magr, RLOC_MSG);
4363.                 monflee(magr, d(3, 6), TRUE, FALSE);
4364.                 mhm->done = TRUE;
4365.                 mhm->hitflags = M_ATTK_HIT | M_ATTK_DEF_DIED; /* return 3??? */
4366.                 return;
4367.             }
4368.             mhm->damage = 0;
4369.         } else {
4370.             if (Role_if(PM_HEALER)) {
4371.                 if (!Deaf && !(svm.moves % 5)) {
4372.                     SetVoice(magr, 0, 80, 0);
4373.                     verbalize("Doc, I can't help you unless you cooperate.");
4374.                 }
4375.                 mhm->damage = 0;
4376.             } else
4377.                 hitmsg(magr, mattk);
4378.         }
4379.     } else {
4380.         /* mhitm */
4381.         mhitm_ad_phys(magr, mattk, mdef, mhm);
4382.         if (mhm->done)
4383.             return;
4384.     }
4385. }
4386. 
4387. void
4388. mhitm_ad_stun(
4389.     struct monst *magr, struct attack *mattk,
4390.     struct monst *mdef, struct mhitm_data *mhm)
4391. {
4392.     struct permonst *pd = mdef->data;
4393. 
4394.     if (magr == &gy.youmonst) {
4395.         /* uhitm */
4396.         if (!Blind)
4397.             pline("%s %s for a moment.", Monnam(mdef),
4398.                   makeplural(stagger(pd, "stagger")));
4399.         mdef->mstun = 1;
4400.         mhitm_ad_phys(magr, mattk, mdef, mhm);
4401.         if (mhm->done)
4402.             return;
4403.     } else if (mdef == &gy.youmonst) {
4404.         /* mhitu */
4405.         hitmsg(magr, mattk);
4406.         if (!magr->mcan && !rn2(4)) {
4407.             make_stunned((HStun & TIMEOUT) + (long) mhm->damage, TRUE);
4408.             mhm->damage /= 2;
4409.         }
4410.     } else {
4411.         /* mhitm */
4412.         if (magr->mcan)
4413.             return;
4414.         if (canseemon(mdef))
4415.             pline_mon(mdef, "%s %s for a moment.", Monnam(mdef),
4416.                   makeplural(stagger(pd, "stagger")));
4417.         mdef->mstun = 1;
4418.         mhitm_ad_phys(magr, mattk, mdef, mhm);
4419.         if (mhm->done)
4420.             return;
4421.     }
4422. }
4423. 
4424. void
4425. mhitm_ad_legs(
4426.     struct monst *magr, struct attack *mattk,
4427.     struct monst *mdef, struct mhitm_data *mhm)
4428. {
4429.     if (magr == &gy.youmonst) {
4430.         /* uhitm */
4431. #if 0
4432.         if (u.ucancelled) {
4433.             mhm->damage = 0;
4434.             return;
4435.         }
4436. #endif
4437.         mhitm_ad_phys(magr, mattk, mdef, mhm);
4438.         if (mhm->done)
4439.             return;
4440.     } else if (mdef == &gy.youmonst) {
4441.         /* mhitu */
4442.         long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE;
4443.         const char *sidestr = (side == RIGHT_SIDE) ? "right" : "left",
4444.                    *Monst_name = Monnam(magr), *leg = body_part(LEG);
4445. 
4446.         /* This case is too obvious to ignore, but Nethack is not in
4447.          * general very good at considering height--most short monsters
4448.          * still _can_ attack you when you're flying or mounted.
4449.          */
4450.         if ((u.usteed || Levitation || Flying) && !is_flyer(magr->data)) {
4451.             pline("%s tries to reach your %s %s!", Monst_name, sidestr, leg);
4452.             mhm->damage = 0;
4453.         } else if (magr->mcan) {
4454.             pline_mon(magr, "%s nuzzles against your %s %s!", Monnam(magr),
4455.                   sidestr, leg);
4456.             mhm->damage = 0;
4457.         } else {
4458.             if (uarmf) {
4459.                 if (rn2(2) && (uarmf->otyp == LOW_BOOTS
4460.                                || uarmf->otyp == IRON_SHOES)) {
4461.                     pline("%s pricks the exposed part of your %s %s!",
4462.                           Monst_name, sidestr, leg);
4463.                 } else if (!rn2(5)) {
4464.                     pline("%s pricks through your %s boot!", Monst_name,
4465.                           sidestr);
4466.                 } else {
4467.                     pline("%s scratches your %s boot!", Monst_name,
4468.                           sidestr);
4469.                     mhm->damage = 0;
4470.                     return;
4471.                 }
4472.             } else
4473.                 pline("%s pricks your %s %s!", Monst_name, sidestr, leg);
4474. 
4475.             set_wounded_legs(side, rnd(60 - ACURR(A_DEX)));
4476.             exercise(A_STR, FALSE);
4477.             exercise(A_DEX, FALSE);
4478.         }
4479.     } else {
4480.         /* mhitm */
4481.         if (magr->mcan) {
4482.             mhm->damage = 0;
4483.             return;
4484.         }
4485.         mhitm_ad_phys(magr, mattk, mdef, mhm);
4486.         if (mhm->done)
4487.             return;
4488.     }
4489. }
4490. 
4491. void
4492. mhitm_ad_dgst(
4493.     struct monst *magr,
4494.     struct attack *mattk UNUSED,
4495.     struct monst *mdef, struct mhitm_data *mhm)
4496. {
4497.     struct permonst *pd = mdef->data;
4498. 
4499.     if (magr == &gy.youmonst) {
4500.         /* uhitm */
4501.         mhm->damage = 0;
4502.     } else if (mdef == &gy.youmonst) {
4503.         /* mhitu */
4504.         mhm->damage = 0;
4505.     } else {
4506.         /* mhitm */
4507.         int num;
4508.         struct obj *obj;
4509. 
4510.         /* eating a Rider or its corpse is fatal */
4511.         if (is_rider(pd)) {
4512.             if (gv.vis && canseemon(magr))
4513.                 pline_mon(magr, "%s %s!", Monnam(magr),
4514.                       (pd == &mons[PM_FAMINE])
4515.                           ? "belches feebly, shrivels up and dies"
4516.                           : (pd == &mons[PM_PESTILENCE])
4517.                                 ? "coughs spasmodically and collapses"
4518.                                 : "vomits violently and drops dead");
4519.             mondied(magr);
4520.             if (!DEADMONSTER(magr)) {
4521.                 mhm->hitflags = M_ATTK_MISS; /* lifesaved */
4522.                 mhm->done = TRUE;
4523.                 return;
4524.             } else if (magr->mtame && !gv.vis)
4525.                 You(brief_feeling, "queasy");
4526.             mhm->hitflags = M_ATTK_AGR_DIED;
4527.             mhm->done = TRUE;
4528.             return;
4529.         }
4530.         if (flags.verbose && !Deaf) {
4531.             /* Soundeffect? */
4532.             SetVoice(magr, 0, 80, 0);
4533.             verbalize("Burrrrp!");
4534.         }
4535.         wake_nearto(magr->mx, magr->my, 2 * 2); /* Burrrrp! */
4536.         mhm->damage = mdef->mhp;
4537.         /* Use up amulet of life saving */
4538.         if ((obj = mlifesaver(mdef)) != 0)
4539.             m_useup(mdef, obj);
4540. 
4541.         /* Is a corpse for nutrition possible?  It may kill magr */
4542.         if (!corpse_chance(mdef, magr, TRUE) || DEADMONSTER(magr))
4543.             return;
4544. 
4545.         /* Pets get nutrition from swallowing monster whole.
4546.          * No nutrition from G_NOCORPSE monster, eg, undead.
4547.          * DGST monsters don't die from undead corpses
4548.          */
4549.         num = monsndx(pd);
4550.         if (magr->mtame && !magr->isminion
4551.             && !(svm.mvitals[num].mvflags & G_NOCORPSE)) {
4552.             struct obj *virtualcorpse = mksobj(CORPSE, FALSE, FALSE);
4553.             int nutrit;
4554. 
4555.             set_corpsenm(virtualcorpse, num);
4556.             nutrit = dog_nutrition(magr, virtualcorpse);
4557.             dealloc_obj(virtualcorpse);
4558. 
4559.             /* only 50% nutrition, 25% of normal eating time */
4560.             if (magr->meating > 1)
4561.                 magr->meating = (magr->meating + 3) / 4;
4562.             if (nutrit > 1)
4563.                 nutrit /= 2;
4564.             EDOG(magr)->hungrytime += nutrit;
4565.         }
4566.     }
4567. }
4568. 
4569. void
4570. mhitm_ad_samu(
4571.     struct monst *magr, struct attack *mattk,
4572.     struct monst *mdef, struct mhitm_data *mhm)
4573. {
4574.     if (magr == &gy.youmonst) {
4575.         /* uhitm */
4576.         mhm->damage = 0;
4577.     } else if (mdef == &gy.youmonst) {
4578.         /* mhitu */
4579.         hitmsg(magr, mattk);
4580.         /* when the Wizard or quest nemesis hits, there's a 1/20 chance
4581.            to steal a quest artifact (any, not just the one for the hero's
4582.            own role) or the Amulet or one of the invocation tools */
4583.         if (!rn2(20))
4584.             stealamulet(magr);
4585.     } else {
4586.         /* mhitm */
4587.         mhm->damage = 0;
4588.     }
4589. }
4590. 
4591. /* disease */
4592. void
4593. mhitm_ad_dise(
4594.     struct monst *magr, struct attack *mattk,
4595.     struct monst *mdef, struct mhitm_data *mhm)
4596. {
4597.     struct permonst *pa = magr->data, *pd = mdef->data;
4598. 
4599.     if (magr == &gy.youmonst) {
4600.         /* uhitm; hero can't polymorph into anything with this attack so
4601.            this won't happen; if it could, it would be the same as the
4602.            mhitm case except for messaging */
4603.         goto mhitm_dise;
4604.     } else if (mdef == &gy.youmonst) {
4605.         /* mhitu */
4606.         hitmsg(magr, mattk);
4607.         if (!diseasemu(pa))
4608.             mhm->damage = 0;
4609.     } else {
4610.  mhitm_dise:
4611.         /* mhitm; protected monsters use the same criteria as for poly'd
4612.            hero gaining sick resistance combined with any hero wielding a
4613.            weapon or wearing dragon scales/mail that guards against disease */
4614.         if (pd->mlet == S_FUNGUS || pd == &mons[PM_GHOUL]
4615.             || defended(mdef, AD_DISE))
4616.             mhm->damage = 0;
4617.         /* else does ordinary damage */
4618.     }
4619. }
4620. 
4621. /* seduce and also steal item */
4622. void
4623. mhitm_ad_sedu(
4624.     struct monst *magr, struct attack *mattk,
4625.     struct monst *mdef, struct mhitm_data *mhm)
4626. {
4627.     struct permonst *pa = magr->data;
4628. 
4629.     if (magr == &gy.youmonst) {
4630.         /* uhitm */
4631.         steal_it(mdef, mattk);
4632.         mhm->damage = 0;
4633.     } else if (mdef == &gy.youmonst) {
4634.         /* mhitu */
4635.         char buf[BUFSZ];
4636. 
4637.         if (is_animal(magr->data)) {
4638.             hitmsg(magr, mattk);
4639.             if (magr->mcan)
4640.                 return;
4641.             /* Continue below */
4642.         } else if (dmgtype(gy.youmonst.data, AD_SEDU)
4643.                    /* !SYSOPT_SEDUCE: when hero is attacking and AD_SSEX
4644.                       is disabled, it would be changed to another damage
4645.                       type, but when defending, it remains as-is */
4646.                    || dmgtype(gy.youmonst.data, AD_SSEX)) {
4647.             pline_mon(magr, "%s %s.", Monnam(magr),
4648.                   Deaf ? "says something but you can't hear it"
4649.                   : magr->minvent
4650.                     ? "brags about the goods some dungeon explorer provided"
4651.                   : "makes some remarks about how difficult theft is lately");
4652.             if (!tele_restrict(magr))
4653.                 (void) rloc(magr, RLOC_MSG);
4654.             mhm->hitflags = M_ATTK_AGR_DONE; /* return 3??? */
4655.             mhm->done = TRUE;
4656.             return;
4657.         } else if (magr->mcan) {
4658.             if (!Blind)
4659.                 pline("%s tries to %s you, but you seem %s.",
4660.                       Adjmonnam(magr, "plain"),
4661.                       flags.female ? "charm" : "seduce",
4662.                       flags.female ? "unaffected" : "uninterested");
4663.             if (rn2(3)) {
4664.                 if (!tele_restrict(magr))
4665.                     (void) rloc(magr, RLOC_MSG);
4666.                 mhm->hitflags = M_ATTK_AGR_DONE; /* return 3??? */
4667.                 mhm->done = TRUE;
4668.                 return;
4669.             }
4670.             return;
4671.         }
4672.         buf[0] = '\0';
4673.         switch (steal(magr, buf)) {
4674.         case -1:
4675.             mhm->hitflags = M_ATTK_AGR_DIED; /* return 2??? */
4676.             mhm->done = TRUE;
4677.             return;
4678.         case 0:
4679.             return;
4680.         default:
4681.             if (!is_animal(magr->data) && !tele_restrict(magr))
4682.                 (void) rloc(magr, RLOC_MSG);
4683.             if (is_animal(magr->data) && *buf) {
4684.                 if (canseemon(magr))
4685.                     pline_mon(magr, "%s tries to %s away with %s.",
4686.                               Monnam(magr),
4687.                               locomotion(magr->data, "run"), buf);
4688.             }
4689.             monflee(magr, 0, FALSE, FALSE);
4690.             mhm->hitflags = M_ATTK_AGR_DONE; /* return 3??? */
4691.             mhm->done = TRUE;
4692.             return;
4693.         }
4694.     } else {
4695.         /* mhitm */
4696.         struct obj *obj;
4697. 
4698.         if (magr->mcan)
4699.             return;
4700.         /* find an object to steal, non-cursed if magr is tame */
4701.         for (obj = mdef->minvent; obj; obj = obj->nobj)
4702.             if (!magr->mtame || !obj->cursed)
4703.                 break;
4704. 
4705.         if (obj) {
4706.             char buf[BUFSZ];
4707.             char onambuf[BUFSZ], mdefnambuf[BUFSZ];
4708. 
4709.             /* make a special x_monnam() call that never omits
4710.                the saddle, and save it for later messages */
4711.             Strcpy(mdefnambuf,
4712.                    x_monnam(mdef, ARTICLE_THE, (char *) 0, 0, FALSE));
4713. 
4714.             if (u.usteed == mdef && obj == which_armor(mdef, W_SADDLE))
4715.                 /* "You can no longer ride <steed>." */
4716.                 dismount_steed(DISMOUNT_POLY);
4717.             extract_from_minvent(mdef, obj, TRUE, FALSE);
4718.             /* add_to_minv() might free 'obj' [if it merges] */
4719.             if (gv.vis)
4720.                 Strcpy(onambuf, doname(obj));
4721.             (void) add_to_minv(magr, obj);
4722.             Strcpy(buf, Monnam(magr));
4723.             if (gv.vis && canseemon(mdef)) {
4724.                 pline("%s steals %s from %s!", buf, onambuf, mdefnambuf);
4725.             }
4726.             possibly_unwield(mdef, FALSE);
4727.             mdef->mstrategy &= ~STRAT_WAITFORU;
4728.             mselftouch(mdef, (const char *) 0, FALSE);
4729.             if (DEADMONSTER(mdef)) {
4730.                 mhm->hitflags = (M_ATTK_DEF_DIED
4731.                                  | (grow_up(magr, mdef) ? 0
4732.                                     : M_ATTK_AGR_DIED));
4733.                 mhm->done = TRUE;
4734.                 return;
4735.             }
4736.             if (pa->mlet == S_NYMPH && !tele_restrict(magr)) {
4737.                 boolean couldspot = canspotmon(magr);
4738. 
4739.                 mhm->hitflags = M_ATTK_AGR_DONE;
4740.                 (void) rloc(magr, RLOC_NOMSG);
4741.                 /* TODO: use RLOC_MSG instead? */
4742.                 if (gv.vis && couldspot && !canspotmon(magr))
4743.                     pline("%s suddenly disappears!", buf);
4744.             }
4745.         }
4746.         mhm->damage = 0;
4747.     }
4748. }
4749. 
4750. void
4751. mhitm_ad_ssex(struct monst *magr, struct attack *mattk, struct monst *mdef,
4752.               struct mhitm_data *mhm)
4753. {
4754.     if (magr == &gy.youmonst) {
4755.         /* uhitm */
4756.         mhitm_ad_sedu(magr, mattk, mdef, mhm);
4757.         if (mhm->done)
4758.             return;
4759.     } else if (mdef == &gy.youmonst) {
4760.         /* mhitu */
4761.         if (SYSOPT_SEDUCE) {
4762.             if (could_seduce(magr, mdef, mattk) == 1 && !magr->mcan)
4763.                 if (doseduce(magr)) {
4764.                     mhm->hitflags = M_ATTK_AGR_DONE;
4765.                     mhm->done = TRUE;
4766.                     return;
4767.                 }
4768.             return;
4769.         }
4770.         mhitm_ad_sedu(magr, mattk, mdef, mhm);
4771.         if (mhm->done)
4772.             return;
4773.     } else {
4774.         /* mhitm */
4775.         mhitm_ad_sedu(magr, mattk, mdef, mhm);
4776.         if (mhm->done)
4777.             return;
4778.     }
4779. }
4780. 
4781. void
4782. mhitm_adtyping(
4783.     struct monst *magr, struct attack *mattk,
4784.     struct monst *mdef, struct mhitm_data *mhm)
4785. {
4786.     switch (mattk->adtyp) {
4787.     case AD_STUN: mhitm_ad_stun(magr, mattk, mdef, mhm); break;
4788.     case AD_LEGS: mhitm_ad_legs(magr, mattk, mdef, mhm); break;
4789.     case AD_WERE: mhitm_ad_were(magr, mattk, mdef, mhm); break;
4790.     case AD_HEAL: mhitm_ad_heal(magr, mattk, mdef, mhm); break;
4791.     case AD_PHYS: mhitm_ad_phys(magr, mattk, mdef, mhm); break;
4792.     case AD_FIRE: mhitm_ad_fire(magr, mattk, mdef, mhm); break;
4793.     case AD_COLD: mhitm_ad_cold(magr, mattk, mdef, mhm); break;
4794.     case AD_ELEC: mhitm_ad_elec(magr, mattk, mdef, mhm); break;
4795.     case AD_ACID: mhitm_ad_acid(magr, mattk, mdef, mhm); break;
4796.     case AD_STON: mhitm_ad_ston(magr, mattk, mdef, mhm); break;
4797.     case AD_SSEX: mhitm_ad_ssex(magr, mattk, mdef, mhm); break;
4798.     case AD_SITM:
4799.     case AD_SEDU: mhitm_ad_sedu(magr, mattk, mdef, mhm); break;
4800.     case AD_SGLD: mhitm_ad_sgld(magr, mattk, mdef, mhm); break;
4801.     case AD_TLPT: mhitm_ad_tlpt(magr, mattk, mdef, mhm); break;
4802.     case AD_BLND: mhitm_ad_blnd(magr, mattk, mdef, mhm); break;
4803.     case AD_CURS: mhitm_ad_curs(magr, mattk, mdef, mhm); break;
4804.     case AD_DRLI: mhitm_ad_drli(magr, mattk, mdef, mhm); break;
4805.     case AD_RUST: mhitm_ad_rust(magr, mattk, mdef, mhm); break;
4806.     case AD_CORR: mhitm_ad_corr(magr, mattk, mdef, mhm); break;
4807.     case AD_DCAY: mhitm_ad_dcay(magr, mattk, mdef, mhm); break;
4808.     case AD_DREN: mhitm_ad_dren(magr, mattk, mdef, mhm); break;
4809.     case AD_DRST:
4810.     case AD_DRDX:
4811.     case AD_DRCO: mhitm_ad_drst(magr, mattk, mdef, mhm); break;
4812.     case AD_DRIN: mhitm_ad_drin(magr, mattk, mdef, mhm); break;
4813.     case AD_STCK: mhitm_ad_stck(magr, mattk, mdef, mhm); break;
4814.     case AD_WRAP: mhitm_ad_wrap(magr, mattk, mdef, mhm); break;
4815.     case AD_PLYS: mhitm_ad_plys(magr, mattk, mdef, mhm); break;
4816.     case AD_SLEE: mhitm_ad_slee(magr, mattk, mdef, mhm); break;
4817.     case AD_SLIM: mhitm_ad_slim(magr, mattk, mdef, mhm); break;
4818.     case AD_ENCH: mhitm_ad_ench(magr, mattk, mdef, mhm); break;
4819.     case AD_SLOW: mhitm_ad_slow(magr, mattk, mdef, mhm); break;
4820.     case AD_CONF: mhitm_ad_conf(magr, mattk, mdef, mhm); break;
4821.     case AD_POLY: mhitm_ad_poly(magr, mattk, mdef, mhm); break;
4822.     case AD_DISE: mhitm_ad_dise(magr, mattk, mdef, mhm); break;
4823.     case AD_SAMU: mhitm_ad_samu(magr, mattk, mdef, mhm); break;
4824.     case AD_DETH: mhitm_ad_deth(magr, mattk, mdef, mhm); break;
4825.     case AD_PEST: mhitm_ad_pest(magr, mattk, mdef, mhm); break;
4826.     case AD_FAMN: mhitm_ad_famn(magr, mattk, mdef, mhm); break;
4827.     case AD_DGST: mhitm_ad_dgst(magr, mattk, mdef, mhm); break;
4828.     case AD_HALU: mhitm_ad_halu(magr, mattk, mdef, mhm); break;
4829.     default:
4830.         mhm->damage = 0;
4831.     }
4832. }
4833. 
4834. int
4835. damageum(
4836.     struct monst *mdef,   /* target */
4837.     struct attack *mattk, /* hero's attack */
4838.     int specialdmg) /* blessed and/or silver bonus against various things */
4839. {
4840.     struct mhitm_data mhm;
4841. 
4842.     mhm.damage = d((int) mattk->damn, (int) mattk->damd);
4843.     mhm.hitflags = M_ATTK_MISS;
4844.     mhm.permdmg = 0;
4845.     mhm.specialdmg = specialdmg;
4846.     mhm.done = FALSE;
4847. 
4848.     if (is_demon(gy.youmonst.data) && !rn2(13) && !uwep
4849.         && u.umonnum != PM_AMOROUS_DEMON && u.umonnum != PM_BALROG) {
4850.         demonpet();
4851.         return M_ATTK_MISS;
4852.     }
4853. 
4854.     mhitm_adtyping(&gy.youmonst, mattk, mdef, &mhm);
4855. 
4856.     if (mhm.done)
4857.         return mhm.hitflags;
4858. 
4859.     mdef->mstrategy &= ~STRAT_WAITFORU; /* in case player is very fast */
4860.     mdef->mhp -= mhm.damage;
4861.     if (DEADMONSTER(mdef)) {
4862.         /* troll killed by Trollsbane won't auto-revive; FIXME? same when
4863.            Trollsbane is wielded as primary and two-weaponing kills with
4864.            secondary, which matches monster vs monster behavior but is
4865.            different from the non-poly'd hero vs monster behavior */
4866.         if (mattk->aatyp == AT_WEAP || mattk->aatyp == AT_CLAW)
4867.             gm.mkcorpstat_norevive = troll_baned(mdef, uwep) ? TRUE : FALSE;
4868.         /* (DEADMONSTER(mdef) and !mhm.damage => already killed) */
4869.         if (mdef->mtame && !cansee(mdef->mx, mdef->my)) {
4870.             You_feel("embarrassed for a moment.");
4871.             if (mhm.damage)
4872.                 xkilled(mdef, XKILL_NOMSG);
4873.         } else if (!flags.verbose) {
4874.             You("destroy it!");
4875.             if (mhm.damage)
4876.                 xkilled(mdef, XKILL_NOMSG);
4877.         } else if (mhm.damage) {
4878.             killed(mdef); /* regular "you kill <mdef>" message */
4879.         }
4880.         gm.mkcorpstat_norevive = FALSE;
4881.         return M_ATTK_DEF_DIED;
4882.     }
4883.     return M_ATTK_HIT;
4884. }
4885. 
4886. /* Hero, as a monster which is capable of an exploding attack mattk, is
4887.  * exploding at a target monster mdef, or just exploding at nothing (e.g. with
4888.  * forcefight) if mdef is null.
4889.  */
4890. int
4891. explum(struct monst *mdef, struct attack *mattk)
4892. {
4893.     int tmp = d((int) mattk->damn, (int) mattk->damd);
4894. 
4895.     switch (mattk->adtyp) {
4896.     case AD_BLND:
4897.         if (mdef && !resists_blnd(mdef)) {
4898.             pline("%s is blinded by your flash of light!", Monnam(mdef));
4899.             mdef->mblinded = min((int) mdef->mblinded + tmp, 127);
4900.             mdef->mcansee = 0;
4901.         }
4902.         break;
4903.     case AD_HALU:
4904.         if (mdef && haseyes(mdef->data) && mdef->mcansee) {
4905.             pline("%s is affected by your flash of light!", Monnam(mdef));
4906.             mdef->mconf = 1;
4907.         }
4908.         break;
4909.     case AD_COLD:
4910.     case AD_FIRE:
4911.     case AD_ELEC:
4912.         /* See comment in mon_explodes() and in zap.c for an explanation
4913.            of this math.  Here, the player is causing the explosion, so it
4914.            should be in the +20 to +29 range instead of negative. */
4915.         explode(u.ux, u.uy, (mattk->adtyp - 1) + 20, tmp, MON_EXPLODE,
4916.                 adtyp_to_expltype(mattk->adtyp));
4917.         if (mdef && DEADMONSTER(mdef)) {
4918.             /* Other monsters may have died too, but return this if the actual
4919.                target died. */
4920.             return M_ATTK_DEF_DIED;
4921.         }
4922.         break;
4923.     default:
4924.         break;
4925.     }
4926.     wake_nearto(u.ux, u.uy, 7 * 7); /* same radius as exploding monster */
4927.     return M_ATTK_HIT;
4928. }
4929. 
4930. staticfn void
4931. start_engulf(struct monst *mdef)
4932. {
4933.     boolean u_digest = digests(gy.youmonst.data),
4934.             u_enfold = enfolds(gy.youmonst.data);
4935. 
4936.     if (!Invisible) {
4937.         map_location(u.ux, u.uy, TRUE);
4938.         tmp_at(DISP_ALWAYS, mon_to_glyph(&gy.youmonst, rn2_on_display_rng));
4939.         tmp_at(mdef->mx, mdef->my);
4940.     }
4941.     You("%s %s%s!",
4942.         u_digest ? "swallow" : u_enfold ? "enclose" : "engulf",
4943.         mon_nam(mdef), u_digest ? " whole" : "");
4944.     nh_delay_output();
4945.     nh_delay_output();
4946. }
4947. 
4948. staticfn void
4949. end_engulf(void)
4950. {
4951.     if (!Invisible) {
4952.         tmp_at(DISP_END, 0);
4953.         newsym(u.ux, u.uy);
4954.     }
4955. }
4956. 
4957. staticfn int
4958. gulpum(struct monst *mdef, struct attack *mattk)
4959. {
4960.     static char msgbuf[BUFSZ]; /* for gn.nomovemsg */
4961.     int tmp;
4962.     int dam = d((int) mattk->damn, (int) mattk->damd);
4963.     boolean fatal_gulp,
4964.             u_digest = digests(gy.youmonst.data),
4965.             u_enfold = enfolds(gy.youmonst.data);
4966.     struct obj *otmp;
4967.     struct permonst *pd = mdef->data;
4968.     const char *expel_verb = u_digest ? "regurgitate"
4969.                              : u_enfold ? "release"
4970.                                : "expel";
4971. 
4972.     /* Not totally the same as for real monsters.  Specifically, these
4973.      * don't take multiple moves.  (It's just too hard, for too little
4974.      * result, to program monsters which attack from inside you, which
4975.      * would be necessary if done accurately.)  Instead, we arbitrarily
4976.      * kill the monster immediately for AD_DGST and we regurgitate them
4977.      * after exactly 1 round of attack otherwise.  -KAA
4978.      */
4979. 
4980.     if (!engulf_target(&gy.youmonst, mdef))
4981.         return M_ATTK_MISS;
4982. 
4983.     if (!(u_digest && u.uhunger >= 1500) && !u.uswallow) {
4984.         if (!flaming(gy.youmonst.data)) {
4985.             for (otmp = mdef->minvent; otmp; otmp = otmp->nobj)
4986.                 (void) snuff_lit(otmp);
4987.         }
4988. 
4989.         /* force vampire in bat, cloud, or wolf form to revert back to
4990.            vampire form now instead of dealing with that when it dies */
4991.         if (is_vampshifter(mdef)
4992.             && newcham(mdef, &mons[mdef->cham], NO_NC_FLAGS)) {
4993.             You("%s it, then %s it.",
4994.                 u_digest ? "swallow" : u_enfold ? "enclose" : "engulf",
4995.                 expel_verb);
4996.             if (canspotmon(mdef)) {
4997.                 /* Avoiding a_monnam here: if the target is named, it gives us
4998.                    a sequence like "You bite Dracula.  You swallow it, then
4999.                    regurgitate it.  It turns into Dracula." */
5000.                 pline("It turns into %s.",
5001.                       x_monnam(mdef, ARTICLE_A, (char *) 0,
5002.                                (SUPPRESS_NAME | SUPPRESS_IT
5003.                                 | SUPPRESS_INVISIBLE), FALSE));
5004.             } else {
5005.                 map_invisible(mdef->mx, mdef->my);
5006.             }
5007.             return M_ATTK_HIT;
5008.         }
5009. 
5010.         /* engulfing a cockatrice or digesting a Rider or Medusa */
5011.         fatal_gulp = (touch_petrifies(pd) && !Stone_resistance)
5012.                      || (mattk->adtyp == AD_DGST
5013.                          && (is_rider(pd) || (pd == &mons[PM_MEDUSA]
5014.                                               && !Stone_resistance)));
5015. 
5016.         if (mattk->adtyp == AD_DGST && (!Slow_digestion || fatal_gulp))
5017.             eating_conducts(pd);
5018. 
5019.         if (fatal_gulp && !is_rider(pd)) { /* petrification */
5020.             char kbuf[BUFSZ];
5021.             const char *mnam = pmname(pd, Mgender(mdef));
5022. 
5023.             if (!type_is_pname(pd))
5024.                 mnam = an(mnam);
5025.             You("%s %s.", u_digest ? "englut" : "engulf", mon_nam(mdef));
5026.             Sprintf(kbuf, "%s %s%s",
5027.                     u_digest ? "swallowing"
5028.                     : u_enfold ? "enclosing"
5029.                       : "engulfing",
5030.                     mnam, u_digest ? " whole" : "");
5031.             instapetrify(kbuf);
5032.         } else {
5033.             start_engulf(mdef);
5034.             switch (mattk->adtyp) {
5035.             case AD_DGST:
5036.                 /* eating a Rider or its corpse is fatal */
5037.                 if (is_rider(pd)) {
5038.                     pline("Unfortunately, digesting any of it is fatal.");
5039.                     end_engulf();
5040.                     Sprintf(svk.killer.name, "unwisely tried to eat %s",
5041.                             pmname(pd, Mgender(mdef)));
5042.                     svk.killer.format = NO_KILLER_PREFIX;
5043.                     done(DIED);
5044.                     return M_ATTK_MISS; /* lifesaved */
5045.                 }
5046. 
5047.                 if (Slow_digestion) {
5048.                     dam = 0;
5049.                     break;
5050.                 }
5051. 
5052.                 /* Use up amulet of life saving */
5053.                 if ((otmp = mlifesaver(mdef)) != 0)
5054.                     m_useup(mdef, otmp);
5055. 
5056.                 newuhs(FALSE);
5057.                 /* start_engulf() issues "you engulf <mdef>" above; this
5058.                    used to specify XKILL_NOMSG but we need "you kill <mdef>"
5059.                    in case we're also going to get "welcome to level N+1";
5060.                    "you totally digest <mdef>" will be coming soon (after
5061.                    several turns) but the level-gain message seems out of
5062.                    order if the kill message is left implicit */
5063.                 gm.mswallower = &gy.youmonst;
5064.                 xkilled(mdef, XKILL_GIVEMSG | XKILL_NOCORPSE);
5065.                 if (!DEADMONSTER(mdef)) { /* monster lifesaved */
5066.                     You("hurriedly regurgitate the sizzling in your %s.",
5067.                         body_part(STOMACH));
5068.                 } else {
5069.                     tmp = 1 + (pd->cwt >> 8);
5070.                     if (corpse_chance(mdef, &gy.youmonst, TRUE)
5071.                         && !(svm.mvitals[monsndx(pd)].mvflags & G_NOCORPSE)) {
5072.                         /* nutrition only if there can be a corpse */
5073.                         u.uhunger += (pd->cnutrit + 1) / 2;
5074.                     } else {
5075.                         tmp = 0;
5076.                     }
5077.                     Sprintf(msgbuf, "You totally digest %s.", mon_nam(mdef));
5078.                     if (tmp != 0) {
5079.                         /* setting afternmv = end_engulf is tempting,
5080.                          * but will cause problems if the player is
5081.                          * attacked (which uses his real location) or
5082.                          * if his See_invisible wears off
5083.                          */
5084.                         You("digest %s.", mon_nam(mdef));
5085.                         if (Slow_digestion)
5086.                             tmp *= 2;
5087.                         nomul(-tmp);
5088.                         gm.multi_reason = "digesting something";
5089.                         gn.nomovemsg = msgbuf;
5090.                         /* possible intrinsic once totally digested */
5091.                         gc.corpsenm_digested = monsndx(pd);
5092.                         ga.afternmv = Finish_digestion;
5093.                     } else
5094.                         pline1(msgbuf);
5095.                     if (pd == &mons[PM_GREEN_SLIME]) {
5096.                         Sprintf(msgbuf, "%s isn't sitting well with you.",
5097.                                 The(pmname(pd, Mgender(mdef))));
5098.                         if (!Unchanging) {
5099.                             make_slimed(5L, (char *) 0);
5100.                         }
5101.                     } else
5102.                         exercise(A_CON, TRUE);
5103.                 }
5104.                 gm.mswallower = (struct monst *) 0;
5105.                 end_engulf();
5106.                 return M_ATTK_DEF_DIED;
5107.             case AD_PHYS:
5108.                 if (gy.youmonst.data == &mons[PM_FOG_CLOUD]) {
5109.                     pline("%s is laden with your moisture.", Monnam(mdef));
5110.                     if ((breathless(pd) || amphibious(pd)) && !flaming(pd)) {
5111.                         dam = 0;
5112.                         pline("%s seems unharmed.", Monnam(mdef));
5113.                     }
5114.                 } else {
5115.                     pline("%s is %s!", Monnam(mdef),
5116.                           enfolds(gy.youmonst.data) ? "being squashed"
5117.                             : "pummeled with your debris");
5118.                 }
5119.                 break;
5120.             case AD_ACID:
5121.                 pline("%s is covered with your goo!", Monnam(mdef));
5122.                 if (resists_acid(mdef)) {
5123.                     pline("It seems harmless to %s.", mon_nam(mdef));
5124.                     dam = 0;
5125.                 }
5126.                 break;
5127.             case AD_BLND:
5128.                 if (can_blnd(&gy.youmonst, mdef, mattk->aatyp,
5129.                              (struct obj *) 0)) {
5130.                     if (mdef->mcansee)
5131.                         pline("%s can't see in there!", Monnam(mdef));
5132.                     mdef->mcansee = 0;
5133.                     dam += mdef->mblinded;
5134.                     if (dam > 127)
5135.                         dam = 127;
5136.                     mdef->mblinded = dam;
5137.                 }
5138.                 dam = 0;
5139.                 break;
5140.             case AD_ELEC:
5141.                 if (rn2(2)) {
5142.                     pline_The("air around %s crackles with electricity.",
5143.                               mon_nam(mdef));
5144.                     if (resists_elec(mdef)) {
5145.                         pline("%s seems unhurt.", Monnam(mdef));
5146.                         dam = 0;
5147.                     }
5148.                     golemeffects(mdef, (int) mattk->adtyp, dam);
5149.                 } else
5150.                     dam = 0;
5151.                 break;
5152.             case AD_COLD:
5153.                 if (rn2(2)) {
5154.                     if (resists_cold(mdef)) {
5155.                         pline("%s seems mildly chilly.", Monnam(mdef));
5156.                         dam = 0;
5157.                     } else
5158.                         pline("%s is freezing to death!", Monnam(mdef));
5159.                     golemeffects(mdef, (int) mattk->adtyp, dam);
5160.                 } else
5161.                     dam = 0;
5162.                 break;
5163.             case AD_FIRE:
5164.                 if (rn2(2)) {
5165.                     if (resists_fire(mdef)) {
5166.                         pline("%s seems mildly hot.", Monnam(mdef));
5167.                         dam = 0;
5168.                     } else
5169.                         pline("%s is burning to a crisp!", Monnam(mdef));
5170.                     golemeffects(mdef, (int) mattk->adtyp, dam);
5171.                 } else
5172.                     dam = 0;
5173.                 break;
5174.             case AD_DREN:
5175.                 if (!rn2(4))
5176.                     xdrainenergym(mdef, TRUE);
5177.                 dam = 0;
5178.                 break;
5179.             }
5180.             end_engulf();
5181.             mdef->mhp -= dam;
5182.             if (DEADMONSTER(mdef)) {
5183.                 killed(mdef);
5184.                 if (DEADMONSTER(mdef)) /* not lifesaved */
5185.                     return M_ATTK_DEF_DIED;
5186.             }
5187.             You("%s %s!", expel_verb, mon_nam(mdef));
5188.             if ((Slow_digestion || is_animal(gy.youmonst.data)) && u_digest) {
5189.                 pline("Obviously, you didn't like %s taste.",
5190.                       s_suffix(mon_nam(mdef)));
5191.             }
5192.         }
5193.     }
5194.     return M_ATTK_MISS;
5195. }
5196. 
5197. void
5198. missum(
5199.     struct monst *mdef,
5200.     struct attack *mattk,
5201.     boolean wouldhavehit)
5202. {
5203.     if (wouldhavehit) /* monk is missing due to penalty for wearing suit */
5204.         Your("armor is rather cumbersome...");
5205. 
5206.     if (could_seduce(&gy.youmonst, mdef, mattk))
5207.         You("pretend to be friendly to %s.", mon_nam(mdef));
5208.     else if (canspotmon(mdef) && flags.verbose)
5209.         You("miss %s.", mon_nam(mdef));
5210.     else
5211.         You("miss it.");
5212.     if (!helpless(mdef))
5213.         wakeup(mdef, TRUE);
5214. }
5215. 
5216. /* check whether equipment protects against knockback */
5217. boolean
5218. m_is_steadfast(struct monst *mtmp)
5219. {
5220.     boolean is_u = (mtmp == &gy.youmonst);
5221.     struct obj *otmp = is_u ? uwep : MON_WEP(mtmp);
5222. 
5223.     /* must be on the ground (or in water) */
5224.     if ((is_u ? (Flying || Levitation)
5225.               : (is_flyer(mtmp->data) || is_floater(mtmp->data)))
5226.         || Is_airlevel(&u.uz) /* air or cloud */
5227.         || (Is_waterlevel(&u.uz) && !is_pool(u.ux, u.uy))) /* air bubble */
5228.         return FALSE;
5229. 
5230.     if (is_art(otmp, ART_GIANTSLAYER))
5231.         return TRUE;
5232. 
5233.     /* steadfast if carrying any loadstone (and not floating or flying);
5234.        'is_u' test not needed here; m_carrying() is 'youmonst' aware */
5235.     if (m_carrying(mtmp, LOADSTONE))
5236.         return TRUE;
5237.     /* when mounted and steed is target of knockback, check the rider for
5238.        a loadstone too (Giantslayer's protection doesn't extend to steed) */
5239.     if (u.usteed && mtmp == u.usteed && carrying(LOADSTONE))
5240.         return TRUE;
5241. 
5242.     return FALSE;
5243. }
5244. 
5245. /* monster hits another monster hard enough to knock it back? */
5246. boolean
5247. mhitm_knockback(
5248.     struct monst *magr,   /* attacker; might be hero */
5249.     struct monst *mdef,   /* defender; might be hero (only if magr isn't)  */
5250.     struct attack *mattk, /* attack type and damage info */
5251.     int *hitflags,        /* modified if magr or mdef dies */
5252.     boolean weapon_used)  /* True: via weapon hit */
5253. {
5254.     char magrbuf[BUFSZ], mdefbuf[BUFSZ];
5255.     struct obj *otmp;
5256.     const char *knockedhow;
5257.     coordxy dx, dy, defx, defy;
5258.     int knockdistance = rn2(3) ? 1 : 2; /* 67%: 1 step, 33%: 2 steps */
5259.     int chance = 6; /* 1/6 chance of attack knocking back a monster */
5260.     boolean u_agr = (magr == &gy.youmonst);
5261.     boolean u_def = (mdef == &gy.youmonst);
5262.     boolean was_u = FALSE, dismount = FALSE;
5263.     struct obj *wep = weapon_used ? (u_agr ? uwep : MON_WEP(magr))
5264.                                   : (struct obj *) 0;
5265. 
5266.     if (wep && is_art(wep, ART_OGRESMASHER))
5267.         chance = 2;
5268. 
5269.     if (rn2(chance))
5270.         return FALSE;
5271. 
5272.     /* only certain attacks qualify for knockback */
5273.     if (!((mattk->adtyp == AD_PHYS)
5274.           && (mattk->aatyp == AT_CLAW
5275.               || mattk->aatyp == AT_KICK
5276.               || mattk->aatyp == AT_BUTT
5277.               || mattk->aatyp == AT_WEAP)))
5278.         return FALSE;
5279. 
5280.     /* don't knockback if attacker also wants to grab or engulf */
5281.     if (attacktype(magr->data, AT_ENGL)
5282.         || attacktype(magr->data, AT_HUGS)
5283.         || sticks(magr->data))
5284.         return FALSE;
5285. 
5286.     /* decide where the first step will place the target; not accurate
5287.        for being knocked out of saddle but doesn't need to be; used for
5288.        test_move() and for message before actual hurtle */
5289.     defx = u_def ? u.ux : mdef->mx;
5290.     defy = u_def ? u.uy : mdef->my;
5291.     dx = sgn(defx - (u_agr ? u.ux : magr->mx));
5292.     dy = sgn(defy - (u_agr ? u.uy : magr->my));
5293. 
5294.     /* can't move most targets into or out of a doorway diagonally */
5295.     if (u_def) {
5296.         if (!test_move(defx, defy, dx, dy, TEST_MOVE))
5297.             return FALSE;
5298.     } else {
5299.         /* subset of test_move() */
5300.         if (!isok(defx + dx, defy + dy))
5301.             return FALSE;
5302.         if (IS_DOOR(levl[defx][defy].typ)
5303.             && (defx - magr->mx && defy - magr->my)
5304.             && !doorless_door(defx, defy))
5305.             return FALSE;
5306.     }
5307. 
5308.     /* if hero is stuck to a cursed saddle, knock the steed back */
5309.     if (u_def && u.usteed) {
5310.         if ((otmp = which_armor(u.usteed, W_SADDLE)) != 0 && otmp->cursed) {
5311.             mdef = u.usteed;
5312.             was_u = TRUE;
5313.             u_def = FALSE;
5314.         } else {
5315.             dismount = TRUE; /* saddle is not cursed; knock hero out of it */
5316.         }
5317.     }
5318. 
5319.     /* monsters must be alive */
5320.     if ((!u_agr && DEADMONSTER(magr))
5321.         || (!u_def && DEADMONSTER(mdef)))
5322.         return FALSE;
5323. 
5324.     /* attacker must be much larger than defender */
5325.     if (!(magr->data->msize > (mdef->data->msize + 1)))
5326.         return FALSE;
5327. 
5328.     /* no knockback with a flimsy or non-blunt weapon */
5329.     if (wep && (is_flimsy(wep) || !is_blunt_weapon(wep)))
5330.         return FALSE;
5331. 
5332.     /* needs a solid physical hit */
5333.     if (unsolid(magr->data))
5334.         return FALSE;
5335. 
5336.     /* the attack must have hit */
5337.     /* mon-vs-mon code path doesn't set up hitflags */
5338.     if ((u_agr || u_def) && !(*hitflags & M_ATTK_HIT))
5339.         return FALSE;
5340. 
5341.     /* steadfast defender cannot be pushed around */
5342.     if (m_is_steadfast(mdef)) {
5343.         if (u_def || (u.usteed && mdef == u.usteed)) {
5344.             mdefbuf[0] = '\0';
5345.             if (u.usteed)
5346.                 Snprintf(mdefbuf, sizeof mdefbuf, "and %s ",
5347.                          y_monnam(u.usteed));
5348.             You("%sdon't budge.", mdefbuf);
5349.         } else if (canseemon(mdef)) {
5350.             pline("%s doesn't budge.", Monnam(mdef));
5351.         }
5352.         return FALSE;
5353.     }
5354. 
5355.     /* subtly vary the message text if monster won't actually move */
5356.     knockedhow = dismount ? "out of your saddle"
5357.                  : will_hurtle(mdef, defx + dx, defy + dy) ? "backward"
5358.                    : "back";
5359. 
5360.     /* give the message */
5361.     if (u_def || canseemon(mdef)) {
5362.         Strcpy(magrbuf, u_agr ? "You" : Monnam(magr));
5363.         Strcpy(mdefbuf, (u_def || was_u) ? "you" : y_monnam(mdef));
5364.         if (was_u)
5365.             Snprintf(eos(mdefbuf), sizeof mdefbuf - strlen(mdefbuf),
5366.                      " and %s", y_monnam(u.usteed));
5367.         /*
5368.          * uhitm: You knock the gnome back with a powerful blow!
5369.          * mhitu: The red dragon knocks you back with a forceful blow!
5370.          * mhitm: The fire giant knocks the gnome back with a forceful strike!
5371.          */
5372.         pline("%s %s %s %s with a %s %s!",
5373.               magrbuf, vtense(magrbuf, "knock"), mdefbuf, knockedhow,
5374.               rn2(2) ? "forceful" : "powerful", rn2(2) ? "blow" : "strike");
5375.     } else if (u_agr) {
5376.         /* hero knocks unseen foe back; noticed by touch */
5377.         You_feel("%s be knocked %s!", some_mon_nam(mdef), knockedhow);
5378.     }
5379. 
5380.     if (u.ustuck && (u_def || u_agr))
5381.         unstuck(u.ustuck);
5382. 
5383.     /* do the actual knockback effect */
5384.     if (u_def) {
5385.         if (dismount) {
5386.             /* normally u.dx,u.dy indicates the direction hero is throwing,
5387.                zapping, &c but here it is used to pass preferred direction
5388.                for dismount to dismount_steed (for DISMOUNT_KNOCKED only) */
5389.             u.dx = dx;
5390.             u.dy = dy;
5391.             dismount_steed(DISMOUNT_KNOCKED);
5392.         } else {
5393.             hurtle(dx, dy, knockdistance, FALSE);
5394.             *hitflags |= M_ATTK_HIT;
5395.         }
5396.         set_apparxy(magr); /* update magr's idea of where you are */
5397.         if (!Stunned && !rn2(4))
5398.             make_stunned((long) (knockdistance + 1), TRUE); /* 2 or 3 */
5399.     } else {
5400.         mhurtle(mdef, dx, dy, knockdistance);
5401.         if (!u_agr)
5402.             *hitflags |= M_ATTK_HIT;
5403.         if (DEADMONSTER(mdef)) {
5404.             if (!was_u)
5405.                 *hitflags |= M_ATTK_DEF_DIED;
5406.         } else if (!rn2(4)) {
5407.             mdef->mstun = 1;
5408.             /* if steed and hero were knocked back, update attacker's idea
5409.                of where hero is */
5410.             if (mdef == u.usteed)
5411.                 set_apparxy(magr);
5412.         }
5413.     }
5414.     if (!u_agr) {
5415.         if (DEADMONSTER(magr))
5416.             *hitflags |= M_ATTK_AGR_DIED;
5417.     }
5418. 
5419.     return TRUE;
5420. }
5421. 
5422. /* attack monster as a monster; returns True if mon survives */
5423. staticfn boolean
5424. hmonas(struct monst *mon)
5425. {
5426.     struct attack *mattk, alt_attk;
5427.     struct obj *weapon, **originalweapon;
5428.     boolean altwep = FALSE, weapon_used = FALSE, odd_claw = TRUE;
5429.     int i, tmp, dieroll, armorpenalty, sum[NATTK],
5430.         dhit = 0, attknum = 0, multi_claw = 0, multi_weap = 0;
5431.     boolean monster_survived;
5432. 
5433.     /* not used here but umpteen mhitm_ad_xxxx() need this */
5434.     gv.vis = (canseemon(mon) || m_next2u(mon));
5435. 
5436.     /* with just one touch/claw/weapon attack, both rings matter;
5437.        with more than one, alternate right and left when checking
5438.        whether silver ring causes successful hit */
5439.     for (i = 0; i < NATTK; i++) {
5440.         sum[i] = M_ATTK_MISS;
5441.         mattk = getmattk(&gy.youmonst, mon, i, sum, &alt_attk);
5442.         if (mattk->aatyp == AT_WEAP)
5443.             ++multi_weap;
5444.         if (mattk->aatyp == AT_WEAP
5445.             || mattk->aatyp == AT_CLAW || mattk->aatyp == AT_TUCH)
5446.             ++multi_claw;
5447.     }
5448.     multi_claw = (multi_claw > 1); /* switch from count to yes/no */
5449.     gt.twohits = 0;
5450. 
5451.     gs.skipdrin = FALSE; /* [see mattackm(mhitm.c)] */
5452. 
5453.     for (i = 0; i < NATTK; i++) {
5454.         /* sum[i] = M_ATTK_MISS; -- now done above */
5455. 
5456.         /* target might have been knocked back so no longer in range, or an
5457.            engulfing vampshifted fog cloud killed and reverted to vampire
5458.            that's placed at another spot (hero occupies mon's first spot) */
5459.         if (i > 0 && (m_at(gb.bhitpos.x, gb.bhitpos.y) != mon
5460.                       || DEADMONSTER(mon)))
5461.             continue;
5462. 
5463.         mattk = getmattk(&gy.youmonst, mon, i, sum, &alt_attk);
5464.         if (gs.skipdrin && mattk->aatyp == AT_TENT && mattk->adtyp == AD_DRIN)
5465.             continue;
5466.         weapon = 0;
5467.         switch (mattk->aatyp) {
5468.         case AT_WEAP:
5469.             /* if (!uwep) goto weaponless; */
5470.  use_weapon:
5471.             odd_claw = !odd_claw; /* see case AT_CLAW,AT_TUCH below */
5472.             /* if we've already hit with a two-handed weapon, we don't
5473.                get to make another weapon attack (note:  monsters who
5474.                use weapons do not have this restriction, but they also
5475.                never have the opportunity to use two weapons) */
5476.             if (weapon_used && (sum[i - 1] > M_ATTK_MISS)
5477.                 && uwep && bimanual(uwep))
5478.                 continue;
5479.             /* Certain monsters don't use weapons when encountered as enemies,
5480.              * but players who polymorph into them have hands or claws and
5481.              * thus should be able to use weapons.  This shouldn't prohibit
5482.              * the use of most special abilities, either.
5483.              * If monster has multiple claw attacks, only one can use weapon.
5484.              */
5485.             weapon_used = TRUE;
5486.             /* Potential problem: if the monster gets multiple weapon attacks,
5487.              * we currently allow the player to get each of these as a weapon
5488.              * attack.  Is this really desirable?
5489.              */
5490.             /* approximate two-weapon mode; known_hitum() -> hmon() -> &c
5491.                might destroy the weapon argument, but it might also already
5492.                be Null, and we want to track that for passive() */
5493.             originalweapon = (altwep && uswapwep) ? &uswapwep : &uwep;
5494.             if (uswapwep /* set up 'altwep' flag for next iteration */
5495.                 /* only consider secondary when wielding one-handed primary */
5496.                 && uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))
5497.                 && !bimanual(uwep)
5498.                 /* only switch if not wearing shield and not at artifact;
5499.                    shield limitation is iffy since still get extra swings
5500.                    if polyform has them, but it matches twoweap behavior;
5501.                    twoweap also only allows primary to be an artifact, so
5502.                    if alternate weapon is one, don't use it */
5503.                 && !uarms && !uswapwep->oartifact
5504.                 /* only switch to uswapwep if it's a weapon */
5505.                 && (uswapwep->oclass == WEAPON_CLASS || is_weptool(uswapwep))
5506.                 /* only switch if uswapwep is not bow, arrows, or darts */
5507.                 && !(is_launcher(uswapwep) || is_ammo(uswapwep)
5508.                      || is_missile(uswapwep)) /* dart, shuriken, boomerang */
5509.                 /* and not two-handed and not incapable of being wielded */
5510.                 && !bimanual(uswapwep)
5511.                 && !(objects[uswapwep->otyp].oc_material == SILVER
5512.                      && Hate_silver))
5513.                 altwep = !altwep; /* toggle for next attack */
5514.             weapon = *originalweapon;
5515.             if (!weapon) /* no need to go beyond no-gloves to rings; not ...*/
5516.                 originalweapon = &uarmg; /*... subject to erosion damage */
5517. 
5518.             tmp = find_roll_to_hit(mon, AT_WEAP, weapon, &attknum,
5519.                                    &armorpenalty);
5520.             mon_maybe_unparalyze(mon);
5521.             dieroll = rnd(20);
5522.             dhit = (tmp > dieroll || u.uswallow);
5523.             if (multi_weap > 1)
5524.                 ++gt.twohits;
5525.             /* caller must set gb.bhitpos */
5526.             monster_survived = known_hitum(mon, weapon, &dhit, tmp,
5527.                                            armorpenalty, mattk, dieroll);
5528.             /* originalweapon points to an equipment slot which might
5529.                now be empty if the weapon was destroyed during the hit;
5530.                passive(,weapon,...) won't call passive_obj() in that case */
5531.             weapon = *originalweapon; /* might receive passive erosion */
5532.             if (!monster_survived) {
5533.                 /* enemy dead, before any special abilities used */
5534.                 sum[i] = M_ATTK_DEF_DIED;
5535.                 break;
5536.             } else
5537.                 sum[i] = dhit ? M_ATTK_HIT : M_ATTK_MISS;
5538.             /* might be a worm that gets cut in half; if so, early return */
5539.             if (m_at(u.ux + u.dx, u.uy + u.dy) != mon) {
5540.                 i = NATTK; /* skip additional attacks */
5541.                 /* proceed with uswapwep->cursed check, then exit loop */
5542.                 goto passivedone;
5543.             }
5544.             /* Do not print "You hit" message; known_hitum already did it. */
5545.             if (dhit && mattk->adtyp != AD_SPEL && mattk->adtyp != AD_PHYS)
5546.                 sum[i] = damageum(mon, mattk, 0);
5547.             break;
5548.         case AT_CLAW:
5549.             if (uwep && !cantwield(gy.youmonst.data) && !weapon_used)
5550.                 goto use_weapon;
5551.             FALLTHROUGH;
5552.             /*FALLTHRU*/
5553.         case AT_TUCH:
5554.             if (uwep && gy.youmonst.data->mlet == S_LICH && !weapon_used)
5555.                 goto use_weapon;
5556.             FALLTHROUGH;
5557.             /*FALLTHRU*/
5558.         case AT_KICK:
5559.             if (mattk->aatyp == AT_KICK && mtrapped_in_pit(&gy.youmonst))
5560.                 continue;
5561.             FALLTHROUGH;
5562.             /*FALLTHRU*/
5563.         case AT_BITE:
5564.         case AT_STNG:
5565.         case AT_BUTT:
5566.         case AT_TENT:
5567.         /*weaponless:*/
5568.             tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0,
5569.                                    &attknum, &armorpenalty);
5570.             mon_maybe_unparalyze(mon);
5571.             dieroll = rnd(20);
5572.             dhit = (tmp > dieroll || u.uswallow);
5573.             if (dhit) {
5574.                 int compat, specialdmg;
5575.                 long silverhit = 0L;
5576.                 const char *verb = 0; /* verb or body part */
5577. 
5578.                 if (!u.uswallow
5579.                     && (compat = could_seduce(&gy.youmonst, mon, mattk))
5580.                        != 0) {
5581.                     You("%s %s %s.",
5582.                         (mon->mcansee && haseyes(mon->data)) ? "smile at"
5583.                                                              : "talk to",
5584.                         mon_nam(mon),
5585.                         (compat == 2) ? "engagingly" : "seductively");
5586.                     /* doesn't anger it; no wakeup() */
5587.                     sum[i] = damageum(mon, mattk, 0);
5588.                     break;
5589.                 }
5590.                 wakeup(mon, TRUE);
5591. 
5592.                 specialdmg = 0; /* blessed and/or silver bonus */
5593.                 switch (mattk->aatyp) {
5594.                 case AT_CLAW:
5595.                 case AT_TUCH:
5596.                     /* verb=="claws" may be overridden below */
5597.                     verb = (mattk->aatyp == AT_TUCH) ? "touch" : "claws";
5598.                     /* decide if silver-hater will be hit by silver ring(s);
5599.                        for 'multi_claw' where attacks alternate right/left,
5600.                        assume 'even' claw or touch attacks use dominant hand
5601.                        or paw, 'odd' ones use non-dominant hand for ring
5602.                        interaction; even vs odd is based on actual attacks
5603.                        rather than on index into mon->dat->mattk[] so that
5604.                        {bite,claw,claw} instead of {claw,claw,bite} doesn't
5605.                        make poly'd hero mysteriously switch handedness */
5606.                     odd_claw = !odd_claw;
5607.                     specialdmg = special_dmgval(&gy.youmonst, mon,
5608.                                                 W_ARMG
5609.                                                 | ((odd_claw || !multi_claw)
5610.                                                    ? W_RINGL : 0L)
5611.                                                 | ((!odd_claw || !multi_claw)
5612.                                                    ? W_RINGR : 0L),
5613.                                                 &silverhit);
5614.                     break;
5615.                 case AT_TENT:
5616.                     /* assumes mind flayer's tentacles-on-head rather
5617.                        than sea monster's tentacle-as-arm */
5618.                     verb = "tentacles";
5619.                     break;
5620.                 case AT_KICK:
5621.                     verb = "kick";
5622.                     specialdmg = special_dmgval(&gy.youmonst, mon, W_ARMF,
5623.                                                 &silverhit);
5624.                     break;
5625.                 case AT_BUTT:
5626.                     verb = "head butt"; /* mbodypart(mon,HEAD)=="head" */
5627.                     /* hypothetical; if any form with a head-butt attack
5628.                        could wear a helmet, it would hit shades when
5629.                        wearing a blessed (or silver) one */
5630.                     specialdmg = special_dmgval(&gy.youmonst, mon, W_ARMH,
5631.                                                 &silverhit);
5632.                     break;
5633.                 case AT_BITE:
5634.                     verb = "bite";
5635.                     break;
5636.                 case AT_STNG:
5637.                     verb = "sting";
5638.                     break;
5639.                 default:
5640.                     verb = "hit";
5641.                     break;
5642.                 }
5643.                 if (mon->data == &mons[PM_SHADE] && !specialdmg) {
5644.                     if (!strcmp(verb, "hit")
5645.                         || (mattk->aatyp == AT_CLAW && humanoid(mon->data)))
5646.                         verb = "attack";
5647.                     Your("%s %s harmlessly through %s.",
5648.                          verb, vtense(verb, "pass"), mon_nam(mon));
5649.                 } else {
5650.                     /* either not a shade or no special silver/blessed damage,
5651.                        other unsolid monsters are immune to AT_TUCH+AD_WRAP */
5652.                     if (failed_grab(&gy.youmonst, mon, mattk))
5653.                         break; /* miss; message already given */
5654. 
5655.                     if (mattk->aatyp == AT_TENT) {
5656.                         Your("tentacles suck %s.", mon_nam(mon));
5657.                     } else {
5658.                         if (mattk->aatyp == AT_CLAW)
5659.                             verb = "hit"; /* not "claws" */
5660.                         You("%s %s.", verb, mon_nam(mon));
5661.                         if (silverhit && flags.verbose)
5662.                             silver_sears(&gy.youmonst, mon, silverhit);
5663.                     }
5664.                     sum[i] = damageum(mon, mattk, specialdmg);
5665.                 }
5666.             } else { /* !dhit */
5667.                 missum(mon, mattk, (tmp + armorpenalty > dieroll));
5668.             }
5669.             break;
5670. 
5671.         case AT_HUGS: {
5672.             int specialdmg;
5673.             long silverhit = 0L;
5674.             boolean byhand = hug_throttles(&mons[u.umonnum]), /* rope golem */
5675.                     unconcerned = (byhand && !can_be_strangled(mon));
5676. 
5677.             if (sticks(mon->data) || u.uswallow || gn.notonhead
5678.                 || (byhand && (uwep || !has_head(mon->data)))) {
5679.                 /* can't hold a holder due to subsequent ambiguity over
5680.                    who is holding whom; can't hug engulfer from inside;
5681.                    can't hug a worm tail (would immobilize entire worm!);
5682.                    byhand: can't choke something that lacks a head;
5683.                    not allowed to make a choking hug if wielding a weapon
5684.                    (but might have grabbed w/o weapon, then wielded one,
5685.                    and may even be attacking a different monster now) */
5686.                 if (byhand && uwep && u.ustuck
5687.                     && !(sticks(u.ustuck->data) || u.uswallow))
5688.                     uunstick();
5689.                 continue; /* not 'break'; bypass passive counter-attack */
5690.             }
5691.             /* automatic if prev two attacks succeed, or if
5692.                already grabbed in a previous attack */
5693.             dhit = 1;
5694.             wakeup(mon, TRUE);
5695.             /* choking hug/throttling grab uses hands (gloves or rings);
5696.                normal hug uses outermost of cloak/suit/shirt */
5697.             specialdmg = special_dmgval(&gy.youmonst, mon,
5698.                                         byhand ? (W_ARMG | W_RINGL | W_RINGR)
5699.                                                : (W_ARMC | W_ARM | W_ARMU),
5700.                                         &silverhit);
5701.             if (unconcerned) {
5702.                 /* strangling something which can't be strangled */
5703.                 if (mattk != &alt_attk) {
5704.                     alt_attk = *mattk;
5705.                     mattk = &alt_attk;
5706.                 }
5707.                 /* change damage to 1d1; not strangling but still
5708.                    doing [minimal] physical damage to victim's body */
5709.                 mattk->damn = mattk->damd = 1;
5710.                 /* don't give 'unconcerned' feedback if there is extra damage
5711.                    or if it is nearly destroyed or if creature doesn't have
5712.                    the mental ability to be concerned in the first place */
5713.                 if (specialdmg || mindless(mon->data)
5714.                     || mon->mhp <= 1 + max(u.udaminc, 1))
5715.                     unconcerned = FALSE;
5716.             }
5717.             if (mon->data == &mons[PM_SHADE]) {
5718.                 const char *verb = byhand ? "grasp" : "hug";
5719. 
5720.                 /* hugging a shade; successful if blessed outermost armor
5721.                    for normal hug, or blessed gloves or silver ring(s) for
5722.                    choking hug; deals damage but never grabs hold */
5723.                 if (specialdmg) {
5724.                     You("%s %s%s", verb, mon_nam(mon), exclam(specialdmg));
5725.                     if (silverhit && flags.verbose)
5726.                         silver_sears(&gy.youmonst, mon, silverhit);
5727.                     sum[i] = damageum(mon, mattk, specialdmg);
5728.                 } else {
5729.                     Your("%s passes harmlessly through %s.",
5730.                          verb, mon_nam(mon));
5731.                 }
5732.                 break;
5733.             }
5734.             /* can't grab unsolid creatures (checked after shade handling) */
5735.             if (failed_grab(&gy.youmonst, mon, mattk))
5736.                 break;
5737.             /* hug attack against ordinary foe */
5738.             if (mon == u.ustuck) {
5739.                 pline("%s is being %s%s.", Monnam(mon),
5740.                       byhand ? "throttled" : "crushed",
5741.                       /* extra feedback for non-breather being choked */
5742.                       unconcerned ? " but doesn't seem concerned" : "");
5743.                 if (silverhit && flags.verbose)
5744.                     silver_sears(&gy.youmonst, mon, silverhit);
5745.                 sum[i] = damageum(mon, mattk, specialdmg);
5746.             } else if (i >= 2 && (sum[i - 1] > M_ATTK_MISS)
5747.                        && (sum[i - 2] > M_ATTK_MISS)) {
5748.                 /* in case we're hugging a new target while already
5749.                    holding something else; yields feedback
5750.                    "<u.ustuck> is no longer in your clutches" */
5751.                 if (u.ustuck && u.ustuck != mon)
5752.                     uunstick();
5753.                 You("grab %s!", mon_nam(mon));
5754.                 set_ustuck(mon);
5755.                 if (silverhit && flags.verbose)
5756.                     silver_sears(&gy.youmonst, mon, silverhit);
5757.                 sum[i] = damageum(mon, mattk, specialdmg);
5758.             }
5759.             break; /* AT_HUGS */
5760.         }
5761. 
5762.         case AT_EXPL: /* automatic hit if next to */
5763.             dhit = -1;
5764.             wakeup(mon, TRUE);
5765.             You("explode!");
5766.             sum[i] = explum(mon, mattk);
5767.             break;
5768. 
5769.         case AT_ENGL:
5770.             tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0,
5771.                                    &attknum, &armorpenalty);
5772.             mon_maybe_unparalyze(mon);
5773.             if ((dhit = (tmp > rnd(20 + i)))) {
5774.                 wakeup(mon, TRUE);
5775.                 /* can't engulf unsolid creatures */
5776.                 if (mon->data == &mons[PM_SHADE]) {
5777.                     /* no specialdmg check needed */
5778.                     Your("attempt to surround %s is harmless.", mon_nam(mon));
5779.                 } else if (failed_grab(&gy.youmonst, mon, mattk)) {
5780.                     ; /* non-shade miss; message already given */
5781.                 } else {
5782.                     sum[i] = gulpum(mon, mattk);
5783.                     if (sum[i] == M_ATTK_DEF_DIED
5784.                         && (mon->data->mlet == S_ZOMBIE
5785.                             || mon->data->mlet == S_MUMMY)
5786.                         && rn2(5) && !Sick_resistance) {
5787.                         You_feel("%ssick.", (Sick) ? "very " : "");
5788.                         mdamageu(mon, rnd(8));
5789.                     }
5790.                 }
5791.             } else {
5792.                 missum(mon, mattk, FALSE);
5793.             }
5794.             break;
5795. 
5796.         case AT_MAGC:
5797.             /* No check for uwep; if wielding nothing we want to
5798.              * do the normal 1-2 points bare hand damage...
5799.              */
5800.             if ((gy.youmonst.data->mlet == S_KOBOLD
5801.                  || gy.youmonst.data->mlet == S_ORC
5802.                  || gy.youmonst.data->mlet == S_GNOME) && !weapon_used)
5803.                 goto use_weapon;
5804.             FALLTHROUGH;
5805.             /*FALLTHRU*/
5806. 
5807.         case AT_NONE:
5808.         case AT_BOOM:
5809.             continue;
5810.         /* Not break--avoid passive attacks from enemy */
5811. 
5812.         case AT_BREA:
5813.         case AT_SPIT:
5814.         case AT_GAZE: /* all done using #monster command */
5815.             dhit = 0;
5816.             break;
5817. 
5818.         default: /* Strange... */
5819.             impossible("strange attack of yours (%d)", mattk->aatyp);
5820.         }
5821.         if (dhit == -1) {
5822.             u.mh = -1; /* dead in the current form */
5823.             rehumanize();
5824.         }
5825.         if (sum[i] == M_ATTK_DEF_DIED) {
5826.             /* defender dead */
5827.             (void) passive(mon, weapon, 1, 0, mattk->aatyp, FALSE);
5828.         } else {
5829.             (void) passive(mon, weapon, (sum[i] != M_ATTK_MISS), 1,
5830.                            mattk->aatyp, FALSE);
5831.         }
5832. 
5833.         if (mhitm_knockback(&gy.youmonst, mon, mattk, &sum[i], weapon_used))
5834.             break;
5835. 
5836.         /* don't use sum[i] beyond this point;
5837.            'i' will be out of bounds if we get here via 'goto' */
5838.  passivedone:
5839.         /* when using dual weapons, cursed secondary weapon doesn't weld,
5840.            it gets dropped; do the same when multiple AT_WEAP attacks
5841.            simulate twoweap */
5842.         if (uswapwep && weapon == uswapwep && weapon->cursed) {
5843.             drop_uswapwep();
5844.             break; /* don't proceed with additional attacks */
5845.         }
5846.         /* stop attacking if defender has died;
5847.            needed to defer this until after uswapwep->cursed check */
5848.         if (DEADMONSTER(mon))
5849.             break;
5850.         if (!Upolyd)
5851.             break; /* No extra attacks if no longer a monster */
5852.         if (gm.multi < 0)
5853.             break; /* If paralyzed while attacking, i.e. floating eye */
5854.     }
5855. 
5856.     gv.vis = FALSE; /* reset */
5857.     gt.twohits = 0;
5858.     /* return value isn't used, but make it match hitum()'s */
5859.     return !DEADMONSTER(mon);
5860. }
5861. 
5862. /*      Special (passive) attacks on you by monsters done here.
5863.  */
5864. int
5865. passive(
5866.     struct monst *mon,
5867.     struct obj *weapon, /* uwep or uswapwep or uarmg or uarmf or Null */
5868.     boolean mhitb,
5869.     boolean maliveb,
5870.     uchar aatyp,
5871.     boolean wep_was_destroyed)
5872. {
5873.     struct permonst *ptr = mon->data;
5874.     int i, tmp;
5875.     int mhit = mhitb ? M_ATTK_HIT : M_ATTK_MISS;
5876.     int malive = maliveb ? M_ATTK_HIT : M_ATTK_MISS;
5877. 
5878.     for (i = 0;; i++) {
5879.         if (i >= NATTK)
5880.             return (malive | mhit); /* no passive attacks */
5881.         if (ptr->mattk[i].aatyp == AT_NONE)
5882.             break; /* try this one */
5883.     }
5884.     /* Note: tmp not always used */
5885.     if (ptr->mattk[i].damn)
5886.         tmp = d((int) ptr->mattk[i].damn, (int) ptr->mattk[i].damd);
5887.     else if (ptr->mattk[i].damd)
5888.         tmp = d((int) mon->m_lev + 1, (int) ptr->mattk[i].damd);
5889.     else
5890.         tmp = 0;
5891. 
5892.     /*  These affect you even if they just died.
5893.      */
5894.     switch (ptr->mattk[i].adtyp) {
5895.     case AD_FIRE:
5896.         if (mhitb && !mon->mcan && weapon) {
5897.             if (aatyp == AT_KICK) {
5898.                 if (uarmf && !rn2(6))
5899.                     (void) erode_obj(uarmf, xname(uarmf), ERODE_BURN,
5900.                                      EF_GREASE | EF_VERBOSE);
5901.             } else if (aatyp == AT_WEAP || aatyp == AT_CLAW
5902.                        || aatyp == AT_MAGC || aatyp == AT_TUCH)
5903.                 passive_obj(mon, weapon, &(ptr->mattk[i]));
5904.         }
5905.         break;
5906.     case AD_ACID:
5907.         if (mhitb && rn2(2)) {
5908.             if (Blind || !flags.verbose)
5909.                 You("are splashed!");
5910.             else
5911.                 You("are splashed by %s %s!", s_suffix(mon_nam(mon)),
5912.                     hliquid("acid"));
5913. 
5914.             if (!Acid_resistance) {
5915.                 mdamageu(mon, tmp);
5916.                 monstunseesu(M_SEEN_ACID);
5917.             } else {
5918.                 monstseesu(M_SEEN_ACID);
5919.             }
5920.             if (!rn2(30))
5921.                 erode_armor(&gy.youmonst, ERODE_CORRODE);
5922.         }
5923.         if (mhitb && weapon) {
5924.             if (aatyp == AT_KICK) {
5925.                 if (uarmf && !rn2(6))
5926.                     (void) erode_obj(uarmf, xname(uarmf), ERODE_CORRODE,
5927.                                      EF_GREASE | EF_VERBOSE);
5928.             } else if (aatyp == AT_WEAP || aatyp == AT_CLAW
5929.                        || aatyp == AT_MAGC || aatyp == AT_TUCH)
5930.                 passive_obj(mon, weapon, &(ptr->mattk[i]));
5931.         }
5932.         exercise(A_STR, FALSE);
5933.         break;
5934.     case AD_STON:
5935.         if (mhitb) { /* successful attack */
5936.             long protector = attk_protection((int) aatyp);
5937. 
5938.             /* hero using monsters' AT_MAGC attack is hitting hand to
5939.                hand rather than casting a spell */
5940.             if (aatyp == AT_MAGC)
5941.                 protector = W_ARMG;
5942. 
5943.             if (protector == 0L /* no protection */
5944.                 || (protector == W_ARMG && !uarmg
5945.                     && !uwep && !wep_was_destroyed)
5946.                 || (protector == W_ARMF && !uarmf)
5947.                 || (protector == W_ARMH && !uarmh)
5948.                 || (protector == (W_ARMC | W_ARMG) && (!uarmc || !uarmg))) {
5949.                 if (!Stone_resistance
5950.                     && !(poly_when_stoned(gy.youmonst.data)
5951.                          && polymon(PM_STONE_GOLEM))) {
5952.                     done_in_by(mon, STONING); /* "You turn to stone..." */
5953.                     return M_ATTK_DEF_DIED;
5954.                 }
5955.             }
5956.         }
5957.         break;
5958.     case AD_RUST:
5959.         if (mhitb && !mon->mcan && weapon) {
5960.             if (aatyp == AT_KICK) {
5961.                 if (uarmf)
5962.                     (void) erode_obj(uarmf, xname(uarmf), ERODE_RUST,
5963.                                      EF_GREASE | EF_VERBOSE);
5964.             } else if (aatyp == AT_WEAP || aatyp == AT_CLAW
5965.                        || aatyp == AT_MAGC || aatyp == AT_TUCH)
5966.                 passive_obj(mon, weapon, &(ptr->mattk[i]));
5967.         }
5968.         break;
5969.     case AD_CORR:
5970.         if (mhitb && !mon->mcan && weapon) {
5971.             if (aatyp == AT_KICK) {
5972.                 if (uarmf)
5973.                     (void) erode_obj(uarmf, xname(uarmf), ERODE_CORRODE,
5974.                                      EF_GREASE | EF_VERBOSE);
5975.             } else if (aatyp == AT_WEAP || aatyp == AT_CLAW
5976.                        || aatyp == AT_MAGC || aatyp == AT_TUCH)
5977.                 passive_obj(mon, weapon, &(ptr->mattk[i]));
5978.         }
5979.         break;
5980.     case AD_MAGM:
5981.         /* wrath of gods for attacking Oracle */
5982.         if (Antimagic) {
5983.             shieldeff(u.ux, u.uy);
5984.             monstseesu(M_SEEN_MAGR);
5985.             pline("A hail of magic missiles narrowly misses you!");
5986.         } else {
5987.             You("are hit by magic missiles appearing from thin air!");
5988.             mdamageu(mon, tmp);
5989.             monstunseesu(M_SEEN_MAGR);
5990.         }
5991.         break;
5992.     case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */
5993.         if (mhitb) {
5994.             if (aatyp == AT_KICK) {
5995.                 if (!weapon)
5996.                     break;
5997.             } else if (aatyp == AT_BITE || aatyp == AT_BUTT
5998.                        || (aatyp >= AT_STNG && aatyp < AT_WEAP)) {
5999.                 break; /* no object involved */
6000.             } else {
6001.                 /*
6002.                  * TODO:  #H2668 - if hitting with a ring that has a
6003.                  * positive enchantment, it ought to be subject to
6004.                  * having that enchantment reduced.  But we don't have
6005.                  * sufficient information here to know which hand/ring
6006.                  * has delivered a weaponless blow.
6007.                  */
6008.                 ;
6009.             }
6010.             passive_obj(mon, weapon, &(ptr->mattk[i]));
6011.         }
6012.         break;
6013.     default:
6014.         break;
6015.     }
6016. 
6017.     /*  These only affect you if they still live.
6018.      */
6019.     if (malive && !mon->mcan && rn2(3)) {
6020.         switch (ptr->mattk[i].adtyp) {
6021.         case AD_PLYS:
6022.             if (ptr == &mons[PM_FLOATING_EYE]) {
6023.                 if (!canseemon(mon)) {
6024.                     break;
6025.                 }
6026.                 if (mon->mcansee) {
6027.                     if (ureflects("%s gaze is reflected by your %s.",
6028.                                   s_suffix(Monnam(mon)))) {
6029.                         ;
6030.                     } else if (Hallucination && rn2(4)) {
6031.                         /* [it's the hero who should be getting paralyzed
6032.                            and isn't; this message describes the monster's
6033.                            reaction rather than the hero's escape] */
6034.                         pline("%s looks %s%s.", Monnam(mon),
6035.                               !rn2(2) ? "" : "rather ",
6036.                               !rn2(2) ? "numb" : "stupefied");
6037.                     } else if (Free_action) {
6038.                         You("momentarily stiffen under %s gaze!",
6039.                             s_suffix(mon_nam(mon)));
6040.                     } else {
6041.                         You("are frozen by %s gaze!", s_suffix(mon_nam(mon)));
6042.                         nomul((ACURR(A_WIS) > 12 || rn2(4)) ? -tmp : -127);
6043.                         /* set gm.multi_reason;
6044.                            3.6.x used "frozen by a monster's gaze" */
6045.                         dynamic_multi_reason(mon, "frozen", TRUE);
6046.                         gn.nomovemsg = 0;
6047.                     }
6048.                 } else {
6049.                     pline("%s cannot defend itself.",
6050.                           Adjmonnam(mon, "blind"));
6051.                     if (!rn2(500))
6052.                         change_luck(-1);
6053.                 }
6054.             } else if (Free_action) {
6055.                 You("momentarily stiffen.");
6056.             } else { /* gelatinous cube */
6057.                 You("are frozen by %s!", mon_nam(mon));
6058.                 gn.nomovemsg = You_can_move_again;
6059.                 nomul(-tmp);
6060.                 /* set gm.multi_reason;
6061.                    3.6.x used "frozen by a monster"; be more specific */
6062.                 dynamic_multi_reason(mon, "frozen", FALSE);
6063.                 exercise(A_DEX, FALSE);
6064.             }
6065.             break;
6066.         case AD_COLD: /* brown mold or blue jelly */
6067.             if (monnear(mon, u.ux, u.uy)) {
6068.                 if (Cold_resistance) {
6069.                     shieldeff(u.ux, u.uy);
6070.                     You_feel("a mild chill.");
6071.                     monstseesu(M_SEEN_COLD);
6072.                     ugolemeffects(AD_COLD, tmp);
6073.                     break;
6074.                 }
6075.                 monstunseesu(M_SEEN_COLD);
6076.                 You("are suddenly very cold!");
6077.                 mdamageu(mon, tmp);
6078.                 /* monster gets stronger with your heat! */
6079.                 healmon(mon, (tmp + rn2(2)) / 2, (tmp + 1) / 2);
6080.                 /* at a certain point, the monster will reproduce! */
6081.                 if (mon->mhpmax > (((int) mon->m_lev) + 1) * 8)
6082.                     (void) split_mon(mon, &gy.youmonst);
6083.             }
6084.             break;
6085.         case AD_STUN: /* specifically yellow mold */
6086.             if (!Stunned)
6087.                 make_stunned((long) tmp, TRUE);
6088.             break;
6089.         case AD_FIRE:
6090.             if (monnear(mon, u.ux, u.uy)) {
6091.                 if (Fire_resistance) {
6092.                     shieldeff(u.ux, u.uy);
6093.                     You_feel("mildly warm.");
6094.                     monstseesu(M_SEEN_FIRE);
6095.                     ugolemeffects(AD_FIRE, tmp);
6096.                     break;
6097.                 }
6098.                 monstunseesu(M_SEEN_FIRE);
6099.                 You("are suddenly very hot!");
6100.                 mdamageu(mon, tmp); /* fire damage */
6101.             }
6102.             break;
6103.         case AD_ELEC:
6104.             if (Shock_resistance) {
6105.                 shieldeff(u.ux, u.uy);
6106.                 You_feel("a mild tingle.");
6107.                 monstseesu(M_SEEN_ELEC);
6108.                 ugolemeffects(AD_ELEC, tmp);
6109.                 break;
6110.             }
6111.             monstunseesu(M_SEEN_ELEC);
6112.             You("are jolted with electricity!");
6113.             mdamageu(mon, tmp);
6114.             break;
6115.         default:
6116.             break;
6117.         }
6118.     }
6119.     return (malive | mhit);
6120. }
6121. 
6122. /*
6123.  * Special (passive) attacks on an attacking object by monsters done here.
6124.  * Assumes the attack was successful.
6125.  */
6126. void
6127. passive_obj(
6128.     struct monst *mon,
6129.     struct obj *obj,      /* null means pick uwep, uswapwep or uarmg */
6130.     struct attack *mattk) /* null means we find one internally */
6131. {
6132.     struct permonst *ptr = mon->data;
6133.     int i;
6134. 
6135.     /* [this first bit is obsolete; we're not called with Null anymore] */
6136.     /* if caller hasn't specified an object, use uwep, uswapwep or uarmg */
6137.     if (!obj) {
6138.         obj = (u.twoweap && uswapwep && !rn2(2)) ? uswapwep : uwep;
6139.         if (!obj && mattk->adtyp == AD_ENCH)
6140.             obj = uarmg; /* no weapon? then must be gloves */
6141.         if (!obj)
6142.             return; /* no object to affect */
6143.     }
6144. 
6145.     /* if caller hasn't specified an attack, find one */
6146.     if (!mattk) {
6147.         for (i = 0;; i++) {
6148.             if (i >= NATTK)
6149.                 return; /* no passive attacks */
6150.             if (ptr->mattk[i].aatyp == AT_NONE)
6151.                 break; /* try this one */
6152.         }
6153.         mattk = &(ptr->mattk[i]);
6154.     }
6155. 
6156.     switch (mattk->adtyp) {
6157.     case AD_FIRE:
6158.         if (!rn2(6) && !mon->mcan
6159.             /* steam vortex: fire resist applies, fire damage doesn't */
6160.             && mon->data != &mons[PM_STEAM_VORTEX]) {
6161.             (void) erode_obj(obj, NULL, ERODE_BURN, EF_NONE);
6162.         }
6163.         break;
6164.     case AD_ACID:
6165.         if (!rn2(6)) {
6166.             (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_GREASE);
6167.         }
6168.         break;
6169.     case AD_RUST:
6170.         if (!mon->mcan) {
6171.             (void) erode_obj(obj, (char *) 0, ERODE_RUST, EF_GREASE);
6172.         }
6173.         break;
6174.     case AD_CORR:
6175.         if (!mon->mcan) {
6176.             (void) erode_obj(obj, (char *) 0, ERODE_CORRODE, EF_GREASE);
6177.         }
6178.         break;
6179.     case AD_ENCH:
6180.         if (!mon->mcan) {
6181.             if (drain_item(obj, TRUE) && carried(obj)
6182.                 && (obj->known || obj->oclass == ARMOR_CLASS)) {
6183.                 pline("%s less effective.", Yobjnam2(obj, "seem"));
6184.             }
6185.             break;
6186.         }
6187.         FALLTHROUGH;
6188.         /* FALLTHRU */
6189.     default:
6190.         break;
6191.     }
6192. 
6193.     if (carried(obj))
6194.         update_inventory();
6195. }
6196. 
6197. DISABLE_WARNING_FORMAT_NONLITERAL
6198. 
6199. /* used by stumble_onto_mimic() and bhitm() cases WAN_LOCKING, WAN_OPENING */
6200. void
6201. that_is_a_mimic(
6202.     struct monst *mtmp, /* a hidden mimic (nonnull) */
6203.     unsigned mimic_flags) /* 0, MIM_REVEAL, MIM_OMIT_WAIT, REVEAL+OMIT */
6204. {
6205.     static char generic[] = "a monster";
6206.     char fmtbuf[BUFSZ];
6207.     const char *what = NULL;
6208.     boolean reveal_it = (mimic_flags & MIM_REVEAL) != 0,
6209.             omit_wait = (mimic_flags & MIM_OMIT_WAIT) != 0;
6210. 
6211.     Strcpy(fmtbuf, "Wait!  That's %s!");
6212.     if (Blind) {
6213.         if (!Blind_telepat)
6214.             what = generic; /* with default fmt */
6215.         else if (M_AP_TYPE(mtmp) == M_AP_MONSTER)
6216.             what = a_monnam(mtmp); /* differs from what was sensed */
6217.     } else {
6218.         coordxy x = mtmp->mx, y = mtmp->my;
6219.         int glyph = glyph_at(x, y);
6220. 
6221.         if (glyph_is_cmap(glyph)) {
6222.             int sym = glyph_to_cmap(glyph);
6223. 
6224.             if (M_AP_TYPE(mtmp) == M_AP_FURNITURE
6225.                 || (M_AP_TYPE(mtmp) == M_AP_OBJECT && sym == S_trapped_chest))
6226.                 Snprintf(fmtbuf, sizeof fmtbuf, "That %s actually is %%s!",
6227.                          defsyms[sym].explanation);
6228.         } else if (glyph_is_object(glyph)) {
6229.             boolean fakeobj;
6230.             const char *otmp_name;
6231.             struct obj *otmp = NULL;
6232. 
6233.             fakeobj = object_from_map(glyph, x, y, &otmp);
6234.             otmp_name = (otmp && otmp->otyp != STRANGE_OBJECT)
6235.                         ? simpleonames(otmp) : "strange object";
6236.             Snprintf(fmtbuf, sizeof fmtbuf, "%s %s %s %%s!",
6237.                      (otmp && is_plural(otmp)) ? "Those" : "That",
6238.                      otmp_name, otmp ? otense(otmp, "are") : "is");
6239.             if (fakeobj && otmp) {
6240.                 otmp->where = OBJ_FREE; /* object_from_map set to OBJ_FLOOR */
6241.                 dealloc_obj(otmp);
6242.             }
6243.         } else if (glyph_is_monster(glyph)) {
6244.             const char *mtmp_name;
6245.             int mndx = glyph_to_mon(glyph);
6246. 
6247.             assert(mndx >= LOW_PM && mndx <= HIGH_PM);
6248.             mtmp_name = pmname(&mons[mndx], Mgender(mtmp));
6249.             Snprintf(fmtbuf, sizeof fmtbuf,
6250.                      "Wait!  That %s is really %%s!", mtmp_name);
6251.         }
6252. 
6253.         /* cloned Wiz starts out mimicking some other monster and
6254.            might make himself invisible before being revealed */
6255.         if (mtmp->minvis && !See_invisible)
6256.             what = generic;
6257.         else if (M_AP_TYPE(mtmp) == M_AP_MONSTER)
6258.             what = x_monnam(mtmp, ARTICLE_A, (char *) NULL, EXACT_NAME, TRUE);
6259.         else if (mtmp->data->mlet == S_MIMIC
6260.                  && (M_AP_TYPE(mtmp) == M_AP_OBJECT
6261.                      || M_AP_TYPE(mtmp) == M_AP_FURNITURE)
6262.                  && (mtmp->msleeping || mtmp->mfrozen))
6263.             /* BUG: this will misclassify a paralyzed mimic as sleeping */
6264.             what = x_monnam(mtmp, ARTICLE_A, "sleeping", 0, FALSE);
6265.         else
6266.             what = a_monnam(mtmp);
6267.     }
6268. 
6269.     if (what) {
6270.         int i = (omit_wait && !strncmp(fmtbuf, "Wait!  ", 7)) ? 7 : 0;
6271. 
6272.         pline(&fmtbuf[i], what);
6273.     }
6274.     if (reveal_it)
6275.         seemimic(mtmp);
6276. }
6277. 
6278. RESTORE_WARNING_FORMAT_NONLITERAL
6279. 
6280. /* Note: caller must ascertain mtmp is mimicking... */
6281. void
6282. stumble_onto_mimic(struct monst *mtmp)
6283. {
6284.     that_is_a_mimic(mtmp, MIM_REVEAL);
6285. 
6286.     if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
6287.         /* must be adjacent; attack via polearm could be from farther away */
6288.         && m_next2u(mtmp))
6289.         set_ustuck(mtmp);
6290. 
6291.     wakeup(mtmp, FALSE); /* clears mimicking */
6292.     /* if hero is blind, wakeup() won't display the monster even though
6293.        it's no longer concealed */
6294.     if (!canspotmon(mtmp)
6295.         && !glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
6296.         map_invisible(mtmp->mx, mtmp->my);
6297. }
6298. 
6299. boolean
6300. disguised_as_non_mon(struct monst *mtmp)
6301. {
6302.     return (!sensemon(mtmp)
6303.             && M_AP_TYPE(mtmp)
6304.             && M_AP_TYPE(mtmp) != M_AP_MONSTER);
6305. }
6306. 
6307. boolean
6308. disguised_as_mon(struct monst *mtmp)
6309. {
6310.     return (M_AP_TYPE(mtmp)
6311.             && M_AP_TYPE(mtmp) == M_AP_MONSTER);
6312. }
6313. 
6314. staticfn void
6315. nohandglow(struct monst *mon)
6316. {
6317.     char *hands;
6318.     boolean altfeedback;
6319. 
6320.     if (!u.umconf || mon->mconf)
6321.         return;
6322. 
6323.     hands = makeplural(body_part(HAND));
6324.     altfeedback = (Blind || Invisible); /* Invisible == Invis && !See_invis */
6325.     if (u.umconf == 1) {
6326.         if (altfeedback)
6327.             Your("%s stop tingling.", hands);
6328.         else
6329.             Your("%s stop glowing %s.", hands, hcolor(NH_RED));
6330.     } else {
6331.         if (altfeedback)
6332.             pline_The("tingling in your %s lessens.", hands);
6333.         else
6334.             Your("%s no longer glow so brightly %s.", hands, hcolor(NH_RED));
6335.     }
6336.     u.umconf--;
6337. }
6338. 
6339. /* returns 1 if light flash has noticeable effect on 'mtmp', 0 otherwise */
6340. int
6341. flash_hits_mon(
6342.     struct monst *mtmp,
6343.     struct obj *otmp) /* source of flash */
6344. {
6345.     struct rm *lev;
6346.     coordxy mx = mtmp->mx, my = mtmp->my;
6347.     int tmp, amt, useeit, res = 0;
6348. 
6349.     if (gn.notonhead)
6350.         return 0;
6351.     lev = &levl[mx][my];
6352.     useeit = canseemon(mtmp);
6353. 
6354.     if (M_AP_TYPE(mtmp) != M_AP_NOTHING) {
6355.         char whatbuf[BUFSZ];
6356.         int oldglyph = glyph_at(mx, my);
6357. 
6358.         /* 'altmon' probably doesn't matter here because 'whatbuf' will
6359.            only be shown if the glyph changes and wakeup() doesn't call
6360.            seemimic() for M_AP_MONSTER */
6361.         mhidden_description(mtmp, MHID_ALTMON, whatbuf);
6362. 
6363.         wakeup(mtmp, FALSE); /* -> seemimic() -> newsym(); also calls
6364.                               * finish_meating() to end quickmimic */
6365. 
6366.         /* if glyph has changed then hero saw something happen */
6367.         if (glyph_at(mx, my) != oldglyph) {
6368.             pline("That %s is really %s%c", whatbuf,
6369.                   /* y_monnam()+a_monnam() */
6370.                   x_monnam(mtmp, mtmp->mtame ? ARTICLE_YOUR : ARTICLE_A,
6371.                            (char *) 0, 0, FALSE),
6372.                   mtmp->mtame ? '.' : '!');
6373.             res = 1;
6374.         }
6375.     }
6376. 
6377.     if (mtmp->msleeping && haseyes(mtmp->data)) {
6378.         mtmp->msleeping = 0;
6379.         if (useeit) {
6380.             pline_The("flash awakens %s.", mon_nam(mtmp));
6381.             res = 1;
6382.         }
6383.     } else if (mtmp->data->mlet != S_LIGHT) {
6384.         if (!resists_blnd(mtmp)) {
6385.             tmp = dist2(otmp->ox, otmp->oy, mx, my);
6386.             if (useeit) {
6387.                 pline("%s is blinded by the flash!", Monnam(mtmp));
6388.                 res = 1;
6389.             }
6390.             if (mtmp->data == &mons[PM_GREMLIN]) {
6391.                 /* Rule #1: Keep them out of the light. */
6392.                 amt = (otmp->otyp == WAN_LIGHT) ? d(1 + otmp->spe, 4)
6393.                                                 : rnd(min(mtmp->mhp, 4));
6394.                 light_hits_gremlin(mtmp, amt);
6395.             }
6396.             if (!DEADMONSTER(mtmp)) {
6397.                 if (!svc.context.mon_moving)
6398.                     setmangry(mtmp, TRUE);
6399.                 if (tmp < 9 && !mtmp->isshk && rn2(4))
6400.                     monflee(mtmp, rn2(4) ? rnd(100) : 0, FALSE, TRUE);
6401.                 mtmp->mcansee = 0;
6402.                 mtmp->mblinded = (tmp < 3) ? 0 : rnd(1 + 50 / tmp);
6403.             }
6404.         } else if (useeit) {
6405.             if (resists_blnd_by_arti(mtmp))
6406.                 shieldeff(mx, my);
6407.             if (flags.verbose) {
6408.                 if (lev->lit)
6409.                     pline("The flash of light shines on %s.", mon_nam(mtmp));
6410.                 else
6411.                     pline("%s is illuminated.", Monnam(mtmp));
6412.                 res = 2; /* 'message has been given' temporary value */
6413.             }
6414.         }
6415.     }
6416.     if (res) {
6417.         if (!lev->lit)
6418.             display_nhwindow(WIN_MESSAGE, TRUE);
6419.         res &= 1; /* change temporary 2 back to 0 */
6420.     }
6421.     return res;
6422. }
6423. 
6424. void
6425. light_hits_gremlin(struct monst *mon, int dmg)
6426. {
6427.     if (!Deaf && mdistu(mon) <= 90) {
6428.         /* cry of pain can be heard somewhat farther than the waking radius */
6429.         pline_mon(mon, "%s %s!", Monnam(mon),
6430.                   (dmg > mon->mhp / 2) ? "wails in agony"
6431.                                        : "cries out in pain");
6432.     } else if (canseemon(mon)) {
6433.         pline_mon(mon, "%s recoils from the light!", Monnam(mon));
6434.     }
6435.     mon->mhp -= dmg;
6436.     wake_nearto(mon->mx, mon->my, 30);
6437.     if (DEADMONSTER(mon)) {
6438.         if (svc.context.mon_moving)
6439.             monkilled(mon, (char *) 0, AD_BLND);
6440.         else
6441.             killed(mon);
6442.     } else if (cansee(mon->mx, mon->my) && !canspotmon(mon)) {
6443.         map_invisible(mon->mx, mon->my);
6444.     }
6445. }
6446. 
6447. /*uhitm.c*/