Source:NetHack 3.6.5/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 3.6.5. To link to a particular line, write [[Source:NetHack 3.6.5/src/uhitm.c#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

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