Source:NetHack 5.0.0/src/polyself.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to polyself.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/polyself.c#line12]], for example.

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

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

1. /* NetHack 5.0	polyself.c	$NHDT-Date: 1772101811 2026/02/26 02:30:11 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.227 $ */
2. /*      Copyright (C) 1987, 1988, 1989 by Ken Arromdee */
3. /* NetHack may be freely redistributed.  See license for details. */
4. 
5. /*
6.  * Polymorph self routine.
7.  *
8.  * Note:  the light source handling code assumes that gy.youmonst.m_id
9.  * always remains 1 and gy.youmonst.mx will always remain 0 when it handles
10.  * the case of the player polymorphed into a light-emitting monster.
11.  *
12.  * Transformation sequences:
13.  *              /-> polymon                 poly into monster form
14.  *    polyself =
15.  *              \-> newman -> polyman       fail to poly, get human form
16.  *
17.  *    rehumanize -> polyman                 return to original form
18.  *
19.  *    polymon (called directly)             usually golem petrification
20.  */
21. 
22. #include "hack.h"
23. 
24. staticfn void check_strangling(boolean);
25. staticfn void polyman(const char *, const char *);
26. staticfn void dropp(struct obj *);
27. staticfn void break_armor(void);
28. staticfn void drop_weapon(int);
29. staticfn int armor_to_dragon(int);
30. staticfn void newman(void);
31. staticfn void polysense(void);
32. 
33. static const char no_longer_petrify_resistant[] =
34.     "No longer petrify-resistant, you";
35. 
36. /* update the gy.youmonst.data structure pointer and intrinsics */
37. void
38. set_uasmon(void)
39. {
40.     struct permonst *mdat = &mons[u.umonnum];
41.     boolean was_vampshifter = valid_vampshiftform(gy.youmonst.cham, u.umonnum);
42. 
43.     set_mon_data(&gy.youmonst, mdat);
44.     gy.youmonst.m_id = 1;
45. 
46.     if (Protection_from_shape_changers)
47.         gy.youmonst.cham = NON_PM;
48.     else if (is_vampire(gy.youmonst.data))
49.         gy.youmonst.cham = gy.youmonst.mnum;
50.     /* assume hero-as-chameleon/doppelganger/sandestin doesn't change shape */
51.     else if (!was_vampshifter)
52.         gy.youmonst.cham = NON_PM;
53.     u.mcham = gy.youmonst.cham; /* for save/restore since youmonst isn't */
54. 
55. #define PROPSET(PropIndx, ON)                          \
56.     do {                                               \
57.         if (ON)                                        \
58.             u.uprops[PropIndx].intrinsic |= FROMFORM;  \
59.         else                                           \
60.             u.uprops[PropIndx].intrinsic &= ~FROMFORM; \
61.     } while (0)
62. #define resist_from_form(MRtyp) ((gy.youmonst.data->mresists & (MRtyp)) != 0)
63. 
64.     PROPSET(FIRE_RES, resist_from_form(MR_FIRE));
65.     PROPSET(COLD_RES, resist_from_form( MR_COLD));
66.     PROPSET(SLEEP_RES, resist_from_form(MR_SLEEP));
67.     PROPSET(DISINT_RES, resist_from_form(MR_DISINT));
68.     PROPSET(SHOCK_RES, resist_from_form(MR_ELEC));
69.     PROPSET(POISON_RES, resist_from_form(MR_POISON));
70.     PROPSET(ACID_RES, resist_from_form(MR_ACID));
71.     PROPSET(STONE_RES, resist_from_form(MR_STONE));
72.     {
73.         /* resists_drli() takes wielded weapon into account; suppress it */
74.         struct obj *save_uwep = uwep;
75. 
76.         uwep = 0;
77.         PROPSET(DRAIN_RES, resists_drli(&gy.youmonst));
78.         uwep = save_uwep;
79.     }
80.     /* resists_magm() takes wielded, worn, and carried equipment into
81.        into account; cheat and duplicate its monster-specific part */
82.     PROPSET(ANTIMAGIC, (dmgtype(mdat, AD_MAGM)
83.                         || mdat == &mons[PM_BABY_GRAY_DRAGON]
84.                         || dmgtype(mdat, AD_RBRE)));
85.     PROPSET(SICK_RES, (mdat->mlet == S_FUNGUS || mdat == &mons[PM_GHOUL]));
86. 
87.     PROPSET(STUNNED, (mdat == &mons[PM_STALKER] || is_bat(mdat)));
88.     PROPSET(HALLUC_RES, dmgtype(mdat, AD_HALU));
89.     PROPSET(SEE_INVIS, perceives(mdat));
90.     PROPSET(TELEPAT, telepathic(mdat));
91.     /* note that Infravision uses mons[race] rather than usual mons[role] */
92.     PROPSET(INFRAVISION, infravision(Upolyd ? mdat : &mons[gu.urace.mnum]));
93.     PROPSET(INVIS, pm_invisible(mdat));
94.     PROPSET(TELEPORT, can_teleport(mdat));
95.     PROPSET(TELEPORT_CONTROL, control_teleport(mdat));
96.     PROPSET(LEVITATION, is_floater(mdat));
97.     /* floating eye is the only 'floater'; it is also flagged as a 'flyer';
98.        suppress flying for it so that enlightenment doesn't confusingly
99.        show latent flight capability always blocked by levitation */
100.     PROPSET(FLYING, (is_flyer(mdat) && !is_floater(mdat)));
101.     PROPSET(SWIMMING, is_swimmer(mdat));
102.     /* [don't touch MAGICAL_BREATHING here; both Amphibious and Breathless
103.        key off of it but include different monster forms...] */
104.     PROPSET(PASSES_WALLS, passes_walls(mdat));
105.     PROPSET(REGENERATION, regenerates(mdat));
106.     PROPSET(REFLECTING, (mdat == &mons[PM_SILVER_DRAGON]));
107.     PROPSET(BLINDED, !haseyes(mdat));
108.     PROPSET(BLND_RES, (dmgtype_fromattack(mdat, AD_BLND, AT_EXPL)
109.                        || dmgtype_fromattack(mdat, AD_BLND, AT_GAZE)));
110. #undef PROPSET
111. #undef resist_from_form
112. 
113.     /* whether the player is flying/floating depends on their steed,
114.        which won't be known during the restore process: but BFlying
115.        and BStealth should be set correctly already in that case, so
116.        there's nothing to do */
117.     if (!program_state.restoring)
118.         float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
119.     polysense();
120. 
121. #ifdef STATUS_HILITES
122.     if (VIA_WINDOWPORT())
123.         status_initialize(REASSESS_ONLY);
124. #endif
125.     /* we can reset this now, having just done what it is meant to trigger */
126.     gw.were_changes = 0L;
127. }
128. 
129. /* Levitation overrides Flying; set or clear BFlying|I_SPECIAL */
130. void
131. float_vs_flight(void)
132. {
133.     boolean stuck_in_floor = (u.utrap && u.utraptype != TT_PIT);
134. 
135.     /* floating overrides flight; so does being trapped in the floor */
136.     if ((HLevitation || ELevitation)
137.         || ((HFlying || EFlying) && stuck_in_floor))
138.         BFlying |= I_SPECIAL;
139.     else
140.         BFlying &= ~I_SPECIAL;
141.     /* being trapped on the ground (bear trap, web, molten lava survived
142.        with fire resistance, former lava solidified via cold, tethered
143.        to a buried iron ball) overrides floating--the floor is reachable */
144.     if ((HLevitation || ELevitation) && stuck_in_floor)
145.         BLevitation |= I_SPECIAL;
146.     else
147.         BLevitation &= ~I_SPECIAL;
148. 
149.     /* riding blocks stealth unless hero+steed fly, so a change in flying
150.        might cause a change in stealth */
151.     steed_vs_stealth();
152. 
153.     disp.botl = TRUE;
154. }
155. 
156. /* riding blocks stealth unless hero+steed fly */
157. void
158. steed_vs_stealth(void)
159. {
160.     if (u.usteed && !Flying && !Levitation)
161.         BStealth |= FROMOUTSIDE;
162.     else
163.         BStealth &= ~FROMOUTSIDE;
164. }
165. 
166. /* for changing into form that's immune to strangulation */
167. staticfn void
168. check_strangling(boolean on)
169. {
170.     /* on -- maybe resume strangling */
171.     if (on) {
172.         boolean was_strangled = (Strangled != 0L);
173. 
174.         /* when Strangled is already set, polymorphing from one
175.            vulnerable form into another causes the counter to be reset */
176.         if (uamul && uamul->otyp == AMULET_OF_STRANGULATION
177.             && can_be_strangled(&gy.youmonst)) {
178.             Strangled = 6L;
179.             disp.botl = TRUE;
180.             Your("%s %s your %s!", simpleonames(uamul),
181.                  was_strangled ? "still constricts" : "begins constricting",
182.                  body_part(NECK)); /* "throat" */
183.             makeknown(AMULET_OF_STRANGULATION);
184.         }
185. 
186.     /* off -- maybe block strangling */
187.     } else {
188.         if (Strangled && !can_be_strangled(&gy.youmonst)) {
189.             Strangled = 0L;
190.             disp.botl = TRUE;
191.             You("are no longer being strangled.");
192.         }
193.     }
194. }
195. 
196. DISABLE_WARNING_FORMAT_NONLITERAL
197. 
198. /* make a (new) human out of the player */
199. staticfn void
200. polyman(const char *fmt, const char *arg)
201. {
202.     boolean sticking = (sticks(gy.youmonst.data) && u.ustuck && !u.uswallow),
203.             was_mimicking = (U_AP_TYPE != M_AP_NOTHING);
204.     boolean was_blind = !!Blind,
205.             had_see_invis = !!See_invisible;
206. 
207.     if (Upolyd) {
208.         u.acurr = u.macurr; /* restore old attribs */
209.         u.amax = u.mamax;
210.         u.umonnum = u.umonster;
211.         flags.female = u.mfemale;
212.     }
213.     set_uasmon();
214. 
215.     u.mh = u.mhmax = 0;
216.     u.mtimedone = 0;
217.     skinback(FALSE);
218.     u.uundetected = 0;
219. 
220.     if (sticking)
221.         uunstick();
222.     find_ac();
223.     if (was_mimicking) {
224.         if (gm.multi < 0)
225.             unmul("");
226.         gy.youmonst.m_ap_type = M_AP_NOTHING;
227.         gy.youmonst.mappearance = 0;
228.     }
229. 
230.     newsym(u.ux, u.uy);
231. 
232.     urgent_pline(fmt, arg);
233.     /* check whether player foolishly genocided self while poly'd */
234.     if (ugenocided()) {
235.         /* intervening activity might have clobbered genocide info */
236.         struct kinfo *kptr = find_delayed_killer(POLYMORPH);
237. 
238.         if (kptr != (struct kinfo *) 0 && kptr->name[0]) {
239.             svk.killer.format = kptr->format;
240.             Strcpy(svk.killer.name, kptr->name);
241.         } else {
242.             svk.killer.format = KILLED_BY;
243.             Strcpy(svk.killer.name, "self-genocide");
244.         }
245.         dealloc_killer(kptr);
246.         done(GENOCIDED);
247.     }
248. 
249.     if (!!See_invisible ^ had_see_invis)
250.         set_mimic_blocking(); /* See_invisible just toggled */
251. 
252.     if (u.twoweap && !could_twoweap(gy.youmonst.data))
253.         untwoweapon();
254. 
255.     if (u.utrap && u.utraptype == TT_PIT) {
256.         set_utrap(rn1(6, 2), TT_PIT); /* time to escape resets */
257.     }
258.     if (was_blind && !Blind) { /* reverting from eyeless */
259.         set_itimeout(&HBlinded, 1L);
260.         make_blinded(0L, TRUE); /* remove blindness */
261.     }
262.     check_strangling(TRUE);
263. 
264.     if (!Levitation && !u.ustuck && is_pool_or_lava(u.ux, u.uy))
265.         spoteffects(TRUE);
266. 
267.     see_monsters();
268. }
269. 
270. RESTORE_WARNING_FORMAT_NONLITERAL
271. 
272. void
273. change_sex(void)
274. {
275.     /* Some monsters are always of one sex and their sex can't be changed;
276.      * Succubi/incubi can change, but are handled below.
277.      *
278.      * !Upolyd check necessary because is_male() and is_female()
279.      * may be true for certain roles
280.      */
281.     if (!Upolyd
282.         || (!is_male(gy.youmonst.data) && !is_female(gy.youmonst.data)
283.             && !is_neuter(gy.youmonst.data)))
284.         flags.female = !flags.female;
285.     if (Upolyd) /* poly'd: also change saved sex */
286.         u.mfemale = !u.mfemale;
287.     max_rank_sz(); /* [this appears to be superfluous] */
288.     if ((Upolyd ? u.mfemale : flags.female) && gu.urole.name.f)
289.         Strcpy(svp.pl_character, gu.urole.name.f);
290.     else
291.         Strcpy(svp.pl_character, gu.urole.name.m);
292.     if (!Upolyd) {
293.         u.umonnum = u.umonster;
294.     } else if (u.umonnum == PM_AMOROUS_DEMON) {
295.         flags.female = !flags.female;
296. #if 0
297.         /* change monster type to match new sex; disabled with
298.            PM_AMOROUS_DEMON */
299.         u.umonnum = (u.umonnum == PM_SUCCUBUS) ? PM_INCUBUS : PM_SUCCUBUS;
300. #endif
301.         set_uasmon();
302.     }
303. }
304. 
305. /* log a message if non-poly'd hero's gender has changed */
306. void
307. livelog_newform(boolean viapoly, int oldgend, int newgend)
308. {
309.     char buf[BUFSZ];
310.     const char *oldrole, *oldrank, *newrole, *newrank;
311. 
312.     /*
313.      * TODO?
314.      *  Give other logging feedback here instead of in newman().
315.      */
316. 
317.     if (!Upolyd) {
318.         if (newgend != oldgend) {
319.             oldrole = (oldgend && gu.urole.name.f) ? gu.urole.name.f
320.                                                   : gu.urole.name.m;
321.             newrole = (newgend && gu.urole.name.f) ? gu.urole.name.f
322.                                                   : gu.urole.name.m;
323.             oldrank = rank_of(u.ulevel, Role_switch, oldgend);
324.             newrank = rank_of(u.ulevel, Role_switch, newgend);
325.             Sprintf(buf, "%.10s %.30s", genders[flags.female].adj, newrank);
326.             livelog_printf(LL_MINORAC, "%s into %s",
327.                            viapoly ? "polymorphed" : "transformed",
328.                            an(strcmp(newrole, oldrole) ? newrole
329.                               : strcmp(newrank, oldrank) ? newrank
330.                                 : buf));
331.         }
332.     }
333. }
334. 
335. staticfn void
336. newman(void)
337. {
338.     const char *newform;
339.     int i, oldlvl, newlvl, oldgend, newgend, hpmax, enmax;
340. 
341.     oldlvl = u.ulevel;
342.     newlvl = oldlvl + rn1(5, -2);     /* new = old + {-2,-1,0,+1,+2} */
343.     if (newlvl > 127 || newlvl < 1) { /* level went below 0? */
344.         goto dead; /* old level is still intact (in case of lifesaving) */
345.     }
346.     if (newlvl > MAXULEV)
347.         newlvl = MAXULEV;
348.     /* If your level goes down, your peak level goes down by
349.        the same amount so that you can't simply use blessed
350.        full healing to undo the decrease.  But if your level
351.        goes up, your peak level does *not* undergo the same
352.        adjustment; you might end up losing out on the chance
353.        to regain some levels previously lost to other causes. */
354.     if (newlvl < oldlvl)
355.         u.ulevelmax -= (oldlvl - newlvl);
356.     if (u.ulevelmax < newlvl)
357.         u.ulevelmax = newlvl;
358.     u.ulevel = newlvl;
359. 
360.     oldgend = poly_gender();
361.     if (gs.sex_change_ok && !rn2(10))
362.         change_sex();
363. 
364.     adjabil(oldlvl, (int) u.ulevel);
365. 
366.     /* random experience points for the new experience level */
367.     u.uexp = rndexp(FALSE);
368. 
369.     /* set up new attribute points (particularly Con) */
370.     redist_attr();
371. 
372.     /*
373.      * New hit points:
374.      *  remove "level gain"-based HP from any extra HP accumulated
375.      *  (the "extra" might actually be negative);
376.      *  modify the extra, retaining {80%, 90%, 100%, or 110%};
377.      *  add in newly generated set of level-gain HP.
378.      *
379.      * (This used to calculate new HP in direct proportion to old HP,
380.      * but that was subject to abuse:  accumulate a large amount of
381.      * extra HP, drain level down to 1, then polyself to level 2 or 3
382.      * [lifesaving capability needed to handle level 0 and -1 cases]
383.      * and the extra got multiplied by 2 or 3.  Repeat the level
384.      * drain and polyself steps until out of lifesaving capability.)
385.      */
386.     hpmax = u.uhpmax;
387.     for (i = 0; i < oldlvl; i++)
388.         hpmax -= (int) u.uhpinc[i];
389.     /* hpmax * rn1(4,8) / 10; 0.95*hpmax on average */
390.     hpmax = rounddiv((long) hpmax * (long) rn1(4, 8), 10);
391.     for (i = 0; (u.ulevel = i) < newlvl; i++)
392.         hpmax += newhp();
393.     if (hpmax < u.ulevel)
394.         hpmax = u.ulevel; /* min of 1 HP per level */
395.     /* retain same proportion for current HP; u.uhp * hpmax / u.uhpmax */
396.     u.uhp = rounddiv((long) u.uhp * (long) hpmax, u.uhpmax);
397.     setuhpmax(hpmax, TRUE); /* might reduce u.uhp */
398.     /*
399.      * Do the same for spell power.
400.      */
401.     enmax = u.uenmax;
402.     for (i = 0; i < oldlvl; i++)
403.         enmax -= (int) u.ueninc[i];
404.     enmax = rounddiv((long) enmax * (long) rn1(4, 8), 10);
405.     for (i = 0; (u.ulevel = i) < newlvl; i++)
406.         enmax += newpw();
407.     if (enmax < u.ulevel)
408.         enmax = u.ulevel;
409.     u.uen = rounddiv((long) u.uen * (long) enmax,
410.                      ((u.uenmax < 1) ? 1 : u.uenmax));
411.     u.uenmax = enmax;
412.     /* [should alignment record be tweaked too?] */
413. 
414.     u.uhunger = rn1(500, 500);
415.     if (Sick)
416.         make_sick(0L, (char *) 0, FALSE, SICK_ALL);
417.     if (Stoned)
418.         make_stoned(0L, (char *) 0, 0, (char *) 0);
419.     if (u.uhp <= 0) {
420.         if (Polymorph_control) { /* even when Stunned || Unaware */
421.             if (u.uhp <= 0)
422.                 u.uhp = 1;
423.         } else {
424.  dead:      /* we come directly here if experience level went to 0 or less */
425.             urgent_pline(
426.                      "Your new form doesn't seem healthy enough to survive.");
427.             svk.killer.format = KILLED_BY_AN;
428.             Strcpy(svk.killer.name, "unsuccessful polymorph");
429.             done(DIED);
430.             /* must have been life-saved to get here */
431.             newuhs(FALSE);
432.             encumber_msg(); /* used to be done by redist_attr() */
433.             return; /* lifesaved */
434.         }
435.     }
436.     newuhs(FALSE);
437.     /* use saved gender we're about to revert to, not current */
438.     newform = ((Upolyd ? u.mfemale : flags.female) && gu.urace.individual.f)
439.                 ? gu.urace.individual.f
440.                 : (gu.urace.individual.m)
441.                    ? gu.urace.individual.m
442.                    : gu.urace.noun;
443.     polyman("You feel like a new %s!", newform);
444. 
445.     newgend = poly_gender();
446.     /* note: newman() bypasses achievements for new ranks attained and
447.        doesn't log "new <form>" when that isn't accompanied by level change */
448.     if (newlvl != oldlvl)
449.         livelog_printf(LL_MINORAC, "became experience level %d as a new %s",
450.                        newlvl, newform);
451.     else
452.         livelog_newform(TRUE, oldgend, newgend);
453. 
454.     if (Slimed) {
455.         Your("body transforms, but there is still slime on you.");
456.         make_slimed(10L, (const char *) 0);
457.     }
458. 
459.     disp.botl = TRUE;
460.     see_monsters();
461.     encumber_msg();
462. 
463.     retouch_equipment(2);
464.     if (!uarmg)
465.         selftouch(no_longer_petrify_resistant);
466. }
467. 
468. void
469. polyself(int psflags)
470. {
471.     char buf[BUFSZ];
472.     int old_light, new_light, mntmp, class, tryct, gvariant = NEUTRAL;
473.     boolean forcecontrol = ((psflags & POLY_CONTROLLED) != 0),
474.             low_control = ((psflags & POLY_LOW_CTRL) != 0),
475.             monsterpoly = ((psflags & POLY_MONSTER) != 0),
476.             formrevert = ((psflags & POLY_REVERT) != 0),
477.             draconian = (uarm && Is_dragon_armor(uarm)),
478.             iswere = (ismnum(u.ulycn)),
479.             isvamp = (is_vampire(gy.youmonst.data)
480.                       || is_vampshifter(&gy.youmonst)),
481.             controllable_poly = Polymorph_control && !(Stunned || Unaware);
482. 
483.     if (Unchanging) {
484.         You("fail to transform!");
485.         return;
486.     }
487.     /* being Stunned|Unaware doesn't negate this aspect of Poly_control */
488.     if (!Polymorph_control && !forcecontrol && !draconian && !iswere
489.         && !isvamp) {
490.         if (rn2(20) > ACURR(A_CON)) {
491.             You1(shudder_for_moment);
492.             losehp(rnd(30), "system shock", KILLED_BY_AN);
493.             exercise(A_CON, FALSE);
494.             return;
495.         }
496.     }
497.     old_light = emits_light(gy.youmonst.data);
498.     mntmp = NON_PM;
499. 
500.     if (formrevert) {
501.         mntmp = gy.youmonst.cham;
502.         monsterpoly = TRUE;
503.         controllable_poly = FALSE;
504.     }
505. 
506.     if (forcecontrol && low_control
507.         && (draconian || monsterpoly || isvamp || iswere))
508.         forcecontrol = FALSE;
509. 
510.     if (monsterpoly && isvamp)
511.         goto do_vampyr;
512. 
513.     if (controllable_poly || forcecontrol) {
514.         buf[0] = '\0';
515.         tryct = 5;
516. 
517.         do {
518.             mntmp = NON_PM;
519.             getlin("Become what kind of monster? [type the name]", buf);
520.             (void) mungspaces(buf);
521.             if (*buf == '\033') {
522.                 /* user is cancelling controlled poly */
523.                 if (forcecontrol) { /* wizard mode #polyself */
524.                     pline1(Never_mind);
525.                     return;
526.                 }
527.                 Strcpy(buf, "*"); /* resort to random */
528.             }
529.             if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
530.                 /* explicitly requesting random result */
531.                 tryct = 0; /* will skip thats_enough_tries */
532.                 continue;  /* end do-while(--tryct > 0) loop */
533.             }
534.             class = 0;
535.             mntmp = name_to_mon(buf, &gvariant);
536.             if (mntmp < LOW_PM) {
537.  by_class:
538.                 class = name_to_monclass(buf, &mntmp);
539.                 if (class && mntmp == NON_PM)
540.                     mntmp = (draconian && class == S_DRAGON)
541.                             ? armor_to_dragon(uarm->otyp)
542.                             : mkclass_poly(class);
543. 
544.             /* placeholder monsters are for corpses and all flagged
545.                M2_NOPOLY but they are reasonable polymorph targets;
546.                pick a suitable substitute (which might be geno'd) */
547.             } else if (is_placeholder(&mons[mntmp])
548.                        /* when your own race, fall to !polyok() case */
549.                        && !your_race(&mons[mntmp])
550.                        /* same for generic human, even if hero isn't human */
551.                        && mntmp != PM_HUMAN) {
552.                 /* far less general than mkclass() */
553.                 if (mntmp == PM_ORC)
554.                     mntmp = rn2(3) ? PM_HILL_ORC : PM_MORDOR_ORC;
555.                 else if (mntmp == PM_ELF)
556.                     mntmp = rn2(3) ? PM_GREEN_ELF : PM_GREY_ELF;
557.                 else if (mntmp == PM_GIANT)
558.                     mntmp = rn2(3) ? PM_STONE_GIANT : PM_HILL_GIANT;
559.                 /* note: PM_DWARF and PM_GNOME are ordinary monsters and
560.                    no longer flagged no-poly so have no need for placeholder
561.                    handling; PM_HUMAN is a placeholder without a suitable
562.                    substitute so gets handled differently below */
563.             }
564. 
565.             if (mntmp < LOW_PM) {
566.                 if (!class)
567.                     pline("I've never heard of such monsters.");
568.                 else
569.                     You_cant("polymorph into any of those.");
570.             } else if (wizard && Upolyd
571.                        && (mntmp == u.umonster
572.                            /* "priest" and "priestess" match the monster
573.                               rather than the role; override that unless
574.                               the text explicitly contains "aligned" */
575.                            || (u.umonster == PM_CLERIC
576.                                && mntmp == PM_ALIGNED_CLERIC
577.                                && !strstri(buf, "aligned")))) {
578.                 /* in wizard mode, picking own role while poly'd reverts to
579.                    normal without newman()'s chance of level or sex change */
580.                 rehumanize();
581.                 old_light = 0; /* rehumanize() extinguishes u-as-mon light */
582.                 goto made_change;
583.             } else if (iswere && (were_beastie(mntmp) == u.ulycn
584.                                   || mntmp == counter_were(u.ulycn)
585.                                   || (Upolyd && mntmp == PM_HUMAN))) {
586.                 goto do_shift;
587.             } else if (!polyok(&mons[mntmp])
588.                        /* Note:  humans are illegal as monsters, but an
589.                           illegal monster forces newman(), which is what
590.                           we want if they specified a human.... (unless
591.                           they specified a unique monster) */
592.                        && !(mntmp == PM_HUMAN
593.                             || (your_race(&mons[mntmp])
594.                                 && (mons[mntmp].geno & G_UNIQ) == 0)
595.                             || mntmp == gu.urole.mnum)) {
596.                 const char *pm_name;
597. 
598.                 /* mkclass_poly() can pick a !polyok()
599.                    candidate; if so, usually try again */
600.                 if (class) {
601.                     if (rn2(3) || --tryct > 0)
602.                         goto by_class;
603.                     /* no retries left; put one back on counter
604.                        so that end of loop decrement will yield
605.                        0 and trigger thats_enough_tries message */
606.                     ++tryct;
607.                 }
608.                 pm_name = pmname(&mons[mntmp], flags.female ? FEMALE : MALE);
609.                 if (the_unique_pm(&mons[mntmp]))
610.                     pm_name = the(pm_name);
611.                 else if (!type_is_pname(&mons[mntmp]))
612.                     pm_name = an(pm_name);
613.                 You_cant("polymorph into %s.", pm_name);
614.             } else
615.                 break;
616.         } while (--tryct > 0);
617. 
618.         if (!tryct)
619.             pline1(thats_enough_tries);
620.         /* allow skin merging, even when polymorph is controlled */
621.         if (draconian && (tryct <= 0 || mntmp == armor_to_dragon(uarm->otyp)))
622.             goto do_merge;
623.         if (isvamp && (tryct <= 0 || mntmp == PM_WOLF || mntmp == PM_FOG_CLOUD
624.                        || is_bat(&mons[mntmp])))
625.             goto do_vampyr;
626.     } else if (draconian || iswere || isvamp) {
627.         /* special changes that don't require polyok() */
628.         if (draconian) {
629.  do_merge:
630.             mntmp = armor_to_dragon(uarm->otyp);
631.             if (!(svm.mvitals[mntmp].mvflags & G_GENOD)) {
632.                 unsigned was_lit = uarm->lamplit;
633.                 int arm_light = artifact_light(uarm) ? arti_light_radius(uarm)
634.                                                      : 0;
635. 
636.                 /* allow G_EXTINCT */
637.                 if (Is_dragon_scales(uarm)) {
638.                     /* dragon scales remain intact as uskin */
639.                     You("merge with your scaly armor.");
640.                 } else { /* dragon scale mail reverts to scales */
641.                     /* similar to noarmor(invent.c),
642.                        shorten to "<color> scale mail" */
643.                     Strcpy(buf, simpleonames(uarm));
644.                     strsubst(buf, " dragon ", " ");
645.                     /* tricky phrasing; dragon scale mail is singular, dragon
646.                        scales are plural (note: we don't use "set of scales",
647.                        which usually overrides the distinction, here) */
648.                     Your("%s reverts to scales as you merge with them.", buf);
649.                     /* uarm->spe enchantment remains unchanged;
650.                        re-converting scales to mail poses risk
651.                        of evaporation due to over enchanting */
652.                     uarm->otyp += GRAY_DRAGON_SCALES - GRAY_DRAGON_SCALE_MAIL;
653.                     observe_object(uarm);
654.                     disp.botl = TRUE; /* AC is changing */
655.                 }
656.                 uskin = uarm;
657.                 uarm = (struct obj *) 0;
658.                 /* save/restore hack */
659.                 uskin->owornmask |= I_SPECIAL;
660.                 if (was_lit)
661.                     maybe_adjust_light(uskin, arm_light);
662.                 update_inventory();
663.             }
664.         } else if (iswere) {
665.  do_shift:
666.             if (Upolyd && were_beastie(mntmp) != u.ulycn)
667.                 mntmp = PM_HUMAN; /* Illegal; force newman() */
668.             else
669.                 mntmp = u.ulycn;
670.         } else if (isvamp) {
671.  do_vampyr:
672.             if (mntmp < LOW_PM || (mons[mntmp].geno & G_UNIQ)) {
673.                 mntmp = (gy.youmonst.data == &mons[PM_VAMPIRE_LEADER]
674.                          && !rn2(10)) ? PM_WOLF
675.                                       : !rn2(4) ? PM_FOG_CLOUD
676.                                                 : PM_VAMPIRE_BAT;
677.                 if (ismnum(gy.youmonst.cham)
678.                     && !is_vampire(gy.youmonst.data) && !rn2(2))
679.                     mntmp = gy.youmonst.cham;
680.             }
681.             if (controllable_poly) {
682.                 Sprintf(buf, "Become %s?",
683.                         an(pmname(&mons[mntmp], gvariant)));
684.                 if (y_n(buf) != 'y')
685.                     return;
686.             }
687.         }
688.         /* if polymon fails, "you feel" message has been given
689.            so don't follow up with another polymon or newman;
690.            sex_change_ok left disabled here */
691.         if (mntmp == PM_HUMAN)
692.             newman(); /* werecritter */
693.         else
694.             (void) polymon(mntmp);
695.         goto made_change; /* maybe not, but this is right anyway */
696.     }
697. 
698.     if (mntmp < LOW_PM) {
699.         tryct = 200;
700.         do {
701.             /* randomly pick an "ordinary" monster */
702.             mntmp = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
703.             if (polyok(&mons[mntmp]) && !is_placeholder(&mons[mntmp]))
704.                 break;
705.         } while (--tryct > 0);
706.     }
707. 
708.     /* The below polyok() fails either if everything is genocided, or if
709.      * we deliberately chose something illegal to force newman().
710.      */
711.     gs.sex_change_ok++;
712.     if (!polyok(&mons[mntmp]) || (!forcecontrol && !rn2(5))
713.         || your_race(&mons[mntmp])) {
714.         newman();
715.     } else {
716.         (void) polymon(mntmp);
717.     }
718.     gs.sex_change_ok--; /* reset */
719. 
720.  made_change:
721.     new_light = emits_light(gy.youmonst.data);
722.     if (old_light != new_light) {
723.         if (old_light)
724.             del_light_source(LS_MONSTER, monst_to_any(&gy.youmonst));
725.         if (new_light == 1)
726.             ++new_light; /* otherwise it's undetectable */
727.         if (new_light)
728.             new_light_source(u.ux, u.uy, new_light, LS_MONSTER,
729.                              monst_to_any(&gy.youmonst));
730.     }
731. }
732. 
733. /* (try to) make a mntmp monster out of the player; return 1 if successful */
734. int
735. polymon(int mntmp)
736. {
737.     char buf[BUFSZ], ustuckNam[BUFSZ];
738.     boolean sticking = sticks(gy.youmonst.data) && u.ustuck && !u.uswallow,
739.             was_blind = !!Blind, dochange = FALSE, was_expelled = FALSE,
740.             was_hiding_under = u.uundetected && hides_under(gy.youmonst.data);
741.     int mlvl, newMaxStr;
742. 
743.     if (svm.mvitals[mntmp].mvflags & G_GENOD) { /* allow G_EXTINCT */
744.         You_feel("rather %s-ish.",
745.                  pmname(&mons[mntmp], flags.female ? FEMALE : MALE));
746.         exercise(A_WIS, TRUE);
747.         return 0;
748.     }
749. 
750.     /* KMH, conduct */
751.     if (!u.uconduct.polyselfs++)
752.         livelog_printf(LL_CONDUCT,
753.                        "changed form for the first time, becoming %s",
754.                        an(pmname(&mons[mntmp], flags.female ? FEMALE : MALE)));
755. 
756.     /* exercise used to be at the very end but only Wis was affected
757.        there since the polymorph was always in effect by then */
758.     exercise(A_CON, FALSE);
759.     exercise(A_WIS, TRUE);
760. 
761.     if (!Upolyd) {
762.         /* Human to monster; save human stats */
763.         u.macurr = u.acurr;
764.         u.mamax = u.amax;
765.         u.mfemale = flags.female;
766.     } else {
767.         /* Monster to monster; restore human stats, to be
768.          * immediately changed to provide stats for the new monster
769.          */
770.         u.acurr = u.macurr;
771.         u.amax = u.mamax;
772.         flags.female = u.mfemale;
773.     }
774. 
775.     /* if stuck mimicking gold, stop immediately */
776.     if (gm.multi < 0 && U_AP_TYPE == M_AP_OBJECT
777.         && gy.youmonst.data->mlet != S_MIMIC)
778.         unmul("");
779.     /* if becoming a non-mimic, stop mimicking anything */
780.     if (mons[mntmp].mlet != S_MIMIC) {
781.         /* as in polyman() */
782.         gy.youmonst.m_ap_type = M_AP_NOTHING;
783.         gy.youmonst.mappearance = 0;
784.     }
785.     if (is_male(&mons[mntmp])) {
786.         if (flags.female)
787.             dochange = TRUE;
788.     } else if (is_female(&mons[mntmp])) {
789.         if (!flags.female)
790.             dochange = TRUE;
791.     } else if (!is_neuter(&mons[mntmp]) && mntmp != u.ulycn) {
792.         if (gs.sex_change_ok && !rn2(10))
793.             dochange = TRUE;
794.     }
795. 
796.     Strcpy(ustuckNam, u.ustuck ? Some_Monnam(u.ustuck) : "");
797. 
798.     Strcpy(buf, (u.umonnum != mntmp) ? "" : "new ");
799.     if (dochange) {
800.         flags.female = !flags.female;
801.         Strcat(buf, (is_male(&mons[mntmp]) || is_female(&mons[mntmp]))
802.                        ? "" : flags.female ? "female " : "male ");
803.     }
804.     Strcat(buf, pmname(&mons[mntmp], flags.female ? FEMALE : MALE));
805.     You("%s %s!", (u.umonnum != mntmp) ? "turn into" : "feel like", an(buf));
806. 
807.     if (Stoned && poly_when_stoned(&mons[mntmp])) {
808.         /* poly_when_stoned already checked stone golem genocide */
809.         mntmp = PM_STONE_GOLEM;
810.         make_stoned(0L, "You turn to stone!", 0, (char *) 0);
811.     }
812. 
813.     u.mtimedone = rn1(500, 500);
814.     u.umonnum = mntmp;
815.     set_uasmon();
816. 
817.     /* New stats for monster, to last only as long as polymorphed.
818.      * Currently only strength gets changed.
819.      */
820.     newMaxStr = uasmon_maxStr();
821.     if (strongmonst(&mons[mntmp])) {
822.         ABASE(A_STR) = AMAX(A_STR) = (schar) newMaxStr;
823.     } else {
824.         /* not a strongmonst(); if hero has exceptional strength, remove it
825.            (note: removal is temporary until returning to original form);
826.            we don't attempt to enforce lower maximum for wimpy forms;
827.            unlike for strongmonst, current strength does not get set to max */
828.         AMAX(A_STR) = (schar) newMaxStr;
829.         /* make sure current is not higher than max (strip exceptional Str) */
830.         if (ABASE(A_STR) > AMAX(A_STR))
831.             ABASE(A_STR) = AMAX(A_STR);
832.     }
833. 
834.     if (Stone_resistance && Stoned) { /* parnes@eniac.seas.upenn.edu */
835.         make_stoned(0L, "You no longer seem to be petrifying.", 0,
836.                     (char *) 0);
837.     }
838.     if (Sick_resistance && Sick) {
839.         make_sick(0L, (char *) 0, FALSE, SICK_ALL);
840.         You("no longer feel sick.");
841.     }
842.     if (Slimed) {
843.         if (flaming(gy.youmonst.data)) {
844.             make_slimed(0L, "The slime burns away!");
845.         } else if (mntmp == PM_GREEN_SLIME) {
846.             /* do it silently */
847.             make_slimed(0L, (char *) 0);
848.         }
849.     }
850.     check_strangling(FALSE); /* maybe stop strangling */
851.     if (nohands(gy.youmonst.data))
852.         make_glib(0);
853. 
854.     /*
855.     mlvl = adj_lev(&mons[mntmp]);
856.      * We can't do the above, since there's no such thing as an
857.      * "experience level of you as a monster" for a polymorphed character.
858.      */
859.     mlvl = (int) mons[mntmp].mlevel;
860.     if (gy.youmonst.data->mlet == S_DRAGON && mntmp >= PM_GRAY_DRAGON) {
861.         u.mhmax = In_endgame(&u.uz) ? (8 * mlvl) : (4 * mlvl + d(mlvl, 4));
862.     } else if (is_golem(gy.youmonst.data)) {
863.         u.mhmax = golemhp(mntmp);
864.     } else {
865.         if (!mlvl)
866.             u.mhmax = rnd(4);
867.         else
868.             u.mhmax = d(mlvl, 8);
869.         if (is_home_elemental(&mons[mntmp]))
870.             u.mhmax *= 3;
871.     }
872.     u.mh = u.mhmax;
873. 
874.     if (u.ulevel < mlvl) {
875.         /* Low level characters can't become high level monsters for long */
876. #ifdef DUMB
877.         /* DRS/NS 2.2.6 messes up -- Peter Kendell */
878.         int mtd = u.mtimedone, ulv = u.ulevel;
879. 
880.         u.mtimedone = mtd * ulv / mlvl;
881. #else
882.         u.mtimedone = u.mtimedone * u.ulevel / mlvl;
883. #endif
884.     }
885. 
886.     if (uskin && mntmp != armor_to_dragon(uskin->otyp))
887.         skinback(FALSE);
888.     break_armor();
889.     drop_weapon(1);
890.     find_ac(); /* (repeated below) */
891.     /* if hiding under something and can't hide anymore, unhide now;
892.        but don't auto-hide when not already hiding-under */
893.     if (was_hiding_under)
894.         (void) hideunder(&gy.youmonst);
895. 
896.     if (u.utrap && u.utraptype == TT_PIT) {
897.         set_utrap(rn1(6, 2), TT_PIT); /* time to escape resets */
898.     }
899.     if (was_blind && !Blind) { /* previous form was eyeless */
900.         set_itimeout(&HBlinded, 1L);
901.         make_blinded(0L, TRUE); /* remove blindness */
902.     }
903.     newsym(u.ux, u.uy); /* Change symbol */
904. 
905.     /* you now know what an egg of your type looks like; [moved from
906.        below in case expels() -> spoteffects() drops hero onto any eggs] */
907.     if (lays_eggs(gy.youmonst.data)) {
908.         learn_egg_type(u.umonnum);
909.         /* make queen bees recognize killer bee eggs */
910.         learn_egg_type(egg_type_from_parent(u.umonnum, TRUE));
911.     }
912. 
913.     if (u.uswallow) {
914.         uchar usiz;
915. 
916.         /* if new form can't be swallowed, make engulfer expel hero */
917.         if (unsolid(gy.youmonst.data)
918.             /* subset of engulf_target() */
919.             || (usiz = gy.youmonst.data->msize) >= MZ_HUGE
920.             || (u.ustuck->data->msize < usiz && !is_whirly(u.ustuck->data))) {
921.             boolean expels_mesg = TRUE;
922. 
923.             if (unsolid(gy.youmonst.data)) {
924.                 if (canspotmon(u.ustuck)) /* [see below for explanation] */
925.                     Strcpy(ustuckNam, Monnam(u.ustuck));
926.                 pline("%s can no longer contain you.", ustuckNam);
927.                 expels_mesg = FALSE;
928.             }
929.             expels(u.ustuck, u.ustuck->data, expels_mesg);
930.             was_expelled = TRUE;
931.             /* FIXME? if expels() triggered rehumanize then we should
932.                return early */
933.         }
934. 
935.     /* [note:  this 'sticking' handling is only sufficient for changing from
936.        grabber to engulfer or vice versa because engulfing by poly'd hero
937.        always ends immediately so won't be in effect during a polymorph] */
938.     } else if (u.ustuck && !sticking /* && !u.uswallow */
939.                /* being held; if now capable of holding, make holder
940.                   release so that hero doesn't automagically start holding
941.                   it; or, release if no longer capable of being held */
942.                && (sticks(gy.youmonst.data) || unsolid(gy.youmonst.data))) {
943.         /* u.ustuck name was saved above in case we're changing from can-see
944.            to can't-see; but might have changed from can't-see to can-see so
945.            override here if hero knows who u.ustuck is */
946.         if (canspotmon(u.ustuck))
947.             Strcpy(ustuckNam, Monnam(u.ustuck));
948.         set_ustuck((struct monst *) 0);
949.         pline("%s loses its grip on you.", ustuckNam);
950.     } else if (sticking && !sticks(gy.youmonst.data)) {
951.         /* was holding onto u.ustuck but no longer capable of that */
952.         uunstick();
953.     }
954. 
955.     if (u.usteed) {
956.         if (touch_petrifies(u.usteed->data) && !Stone_resistance && rnl(3)) {
957.             pline("%s touch %s.", no_longer_petrify_resistant,
958.                   mon_nam(u.usteed));
959.             Sprintf(buf, "riding %s",
960.                     an(pmname(u.usteed->data, Mgender(u.usteed))));
961.             instapetrify(buf);
962.         }
963.         if (!can_ride(u.usteed))
964.             dismount_steed(DISMOUNT_POLY);
965.     }
966. 
967.     find_ac();
968.     if (((!Levitation && !u.ustuck && !Flying && is_pool_or_lava(u.ux, u.uy))
969.          || (Underwater && !Swimming))
970.         /* if expelled above, expels() already called spoteffects() */
971.         && !was_expelled) {
972.         spoteffects(TRUE);
973.         /* FIXME? if spoteffects() triggered rehumanize then we should
974.            return early */
975.     }
976.     if (Passes_walls && u.utrap
977.         && (u.utraptype == TT_INFLOOR || u.utraptype == TT_BURIEDBALL)) {
978.         if (u.utraptype == TT_INFLOOR) {
979.             pline_The("rock seems to no longer trap you.");
980.         } else {
981.             pline_The("buried ball is no longer bound to you.");
982.             buried_ball_to_freedom();
983.         }
984.         reset_utrap(TRUE);
985.     } else if (likes_lava(gy.youmonst.data) && u.utrap
986.                && u.utraptype == TT_LAVA) {
987.         pline_The("%s now feels soothing.", hliquid("lava"));
988.         reset_utrap(TRUE);
989.     }
990.     if (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data)
991.         || unsolid(gy.youmonst.data)) {
992.         if (Punished) {
993.             You("slip out of the iron chain.");
994.             unpunish();
995.         } else if (u.utrap && u.utraptype == TT_BURIEDBALL) {
996.             You("slip free of the buried ball and chain.");
997.             buried_ball_to_freedom();
998.         }
999.     }
1000.     if (u.utrap && (u.utraptype == TT_WEB || u.utraptype == TT_BEARTRAP)
1001.         && (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data)
1002.             || unsolid(gy.youmonst.data)
1003.             || (gy.youmonst.data->msize <= MZ_SMALL
1004.                 && u.utraptype == TT_BEARTRAP))) {
1005.         You("are no longer stuck in the %s.",
1006.             u.utraptype == TT_WEB ? "web" : "bear trap");
1007.         /* probably should burn webs too if PM_FIRE_ELEMENTAL */
1008.         reset_utrap(TRUE);
1009.     }
1010.     if (webmaker(gy.youmonst.data) && u.utrap && u.utraptype == TT_WEB) {
1011.         You("orient yourself on the web.");
1012.         reset_utrap(TRUE);
1013.     }
1014.     check_strangling(TRUE); /* maybe start strangling */
1015. 
1016.     disp.botl = TRUE;
1017.     gv.vision_full_recalc = 1;
1018.     see_monsters();
1019.     encumber_msg();
1020. 
1021.     retouch_equipment(2);
1022.     /* this might trigger a recursive call to polymon() [stone golem
1023.        wielding cockatrice corpse and hit by stone-to-flesh, becomes
1024.        flesh golem above, now gets transformed back into stone golem;
1025.        fortunately neither form uses #monster] */
1026.     if (!uarmg)
1027.         selftouch(no_longer_petrify_resistant);
1028. 
1029.     /* the explanation of '#monster' used to be shown sooner, but there are
1030.        possible fatalities above and it isn't useful unless hero survives */
1031.     if (flags.verbose) {
1032.         static const char use_thec[] = "Use the command #%s to %s.";
1033.         static const char monsterc[] = "monster";
1034.         struct permonst *uptr = gy.youmonst.data;
1035.         boolean might_hide = (is_hider(uptr) || hides_under(uptr));
1036. 
1037.         if (can_breathe(uptr))
1038.             pline(use_thec, monsterc, "use your breath weapon");
1039.         if (attacktype(uptr, AT_SPIT))
1040.             pline(use_thec, monsterc, "spit venom");
1041.         if (uptr->mlet == S_NYMPH)
1042.             pline(use_thec, monsterc, "remove an iron ball");
1043.         if (attacktype(uptr, AT_GAZE))
1044.             pline(use_thec, monsterc, "gaze at monsters");
1045.         if (might_hide && webmaker(uptr))
1046.             pline(use_thec, monsterc, "hide or to spin a web");
1047.         else if (might_hide)
1048.             pline(use_thec, monsterc, "hide");
1049.         else if (webmaker(uptr))
1050.             pline(use_thec, monsterc, "spin a web");
1051.         if (is_were(uptr))
1052.             pline(use_thec, monsterc, "summon help");
1053.         if (u.umonnum == PM_GREMLIN)
1054.             pline(use_thec, monsterc, "multiply in a fountain");
1055.         if (is_unicorn(uptr))
1056.             pline(use_thec, monsterc, "use your horn");
1057.         if (is_mind_flayer(uptr))
1058.             pline(use_thec, monsterc, "emit a mental blast");
1059.         if (uptr->msound == MS_SHRIEK) /* worthless, actually */
1060.             pline(use_thec, monsterc, "shriek");
1061.         if (is_vampire(uptr) || is_vampshifter(&gy.youmonst))
1062.             pline(use_thec, monsterc, "change shape");
1063. 
1064.         if (lays_eggs(uptr) && flags.female
1065.             && !(uptr == &mons[PM_GIANT_EEL]
1066.                  || uptr == &mons[PM_ELECTRIC_EEL]))
1067.             pline(use_thec, "sit",
1068.                   eggs_in_water(uptr) ? "spawn in the water" : "lay an egg");
1069.     }
1070.     return 1;
1071. }
1072. 
1073. /* determine hero's temporary strength value used while polymorphed;
1074.    hero poly'd into M2_STRONG monster usually gets 18/100 strength but
1075.    there are exceptions; non-M2_STRONG get maximum strength set to 18 */
1076. schar
1077. uasmon_maxStr(void)
1078. {
1079.     const struct Race *R;
1080.     int newMaxStr;
1081.     int mndx = u.umonnum;
1082.     struct permonst *ptr = &mons[mndx];
1083. 
1084.     if (is_orc(ptr)) {
1085.         if (mndx != PM_URUK_HAI && mndx != PM_ORC_CAPTAIN)
1086.             mndx = PM_ORC;
1087.     } else if (is_elf(ptr)) {
1088.         mndx = PM_ELF;
1089.     } else if (is_dwarf(ptr)) {
1090.         mndx = PM_DWARF;
1091.     } else if (is_gnome(ptr)) {
1092.         mndx = PM_GNOME;
1093. #if 0   /* use the mons[] value for humans */
1094.     } else if (is_human(ptr)) {
1095.         mndx = PM_HUMAN;
1096. #endif
1097.     }
1098.     R = character_race(mndx);
1099. 
1100.     if (strongmonst(ptr)) {
1101.         /* ettins, titans and minotaurs don't pass the is_giant() test;
1102.            giant mummies and giant zombies do but we throttle those */
1103.         boolean live_H = is_giant(ptr) && !is_undead(ptr);
1104. 
1105.         /* hero orcs are limited to 18/50 for maximum strength, so treat
1106.            hero poly'd into an orc the same; goblins, orc shamans, and orc
1107.            zombies don't have strongmonst() attribute so won't get here;
1108.            hobgoblins and orc mummies do get here and are limited to 18/50
1109.            like normal orcs; however, orc captains and Uruk-hai retain 18/100
1110.            strength; hero gnomes are also limited to 18/50; hero elves are
1111.            limited to 18/00 regardless of whether they're strongmonst, but
1112.            the two strongmonst types (monarchs and nobles) have current
1113.            strength set to 18 [by polymon()], the others don't */
1114.         newMaxStr = R ? R->attrmax[A_STR] : live_H ? STR19(19) : STR18(100);
1115.     } else {
1116.         newMaxStr = R ? R->attrmax[A_STR] : 18; /* 18 is same as STR18(0) */
1117.     }
1118.     return (schar) newMaxStr;
1119. }
1120. 
1121. /* dropx() jacket for break_armor() */
1122. staticfn void
1123. dropp(struct obj *obj)
1124. {
1125.     struct obj *otmp;
1126. 
1127.     /*
1128.      * Dropping worn armor while polymorphing might put hero into water
1129.      * (loss of levitation boots or water walking boots that the new
1130.      * form can't wear), where emergency_disrobe() could remove it from
1131.      * inventory.  Without this, dropx() could trigger an 'object lost'
1132.      * panic.  Right now, boots are the only armor which might encounter
1133.      * this situation, but handle it for all armor.
1134.      *
1135.      * Hypothetically, 'obj' could have merged with something (not
1136.      * applicable for armor) and no longer be a valid pointer, so scan
1137.      * inventory for it instead of trusting obj->where.
1138.      */
1139.     for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
1140.         if (otmp == obj) {
1141.             dropx(obj);
1142.             /* Note that otmp->nobj is pointing at fobj now,
1143.              * as a result of:
1144.              * dropx() -> dropy() -> dropz() -> place_object(),
1145.              * and no longer pointing at the next obj in inventory.
1146.              * That would be an issue if this loop were allowed
1147.              * to continue, but the break statement that
1148.              * follows prevents the loop from continuing on with
1149.              * objects on the floor.
1150.              */
1151.             break;
1152.         }
1153.     }
1154. }
1155. 
1156. staticfn void
1157. break_armor(void)
1158. {
1159.     struct obj *otmp;
1160.     struct permonst *uptr = gy.youmonst.data;
1161. 
1162.     if (breakarm(uptr)) {
1163.         if ((otmp = uarm) != 0) {
1164.             if (donning(otmp))
1165.                 cancel_don();
1166.             /* for gold DSM, we don't want Armor_gone() to report that it
1167.                stops shining _after_ we've been told that it is destroyed */
1168.             if (otmp->lamplit)
1169.                 end_burn(otmp, FALSE);
1170. 
1171.             You("break out of your armor!");
1172.             exercise(A_STR, FALSE);
1173.             (void) Armor_gone();
1174.             useup(otmp);
1175.         }
1176.         if ((otmp = uarmc) != 0
1177.             /* mummy wrapping adapts to small and very big sizes */
1178.             && (otmp->otyp != MUMMY_WRAPPING || !WrappingAllowed(uptr))) {
1179.             if (otmp->otyp == MUMMY_WRAPPING) {
1180.                 /* doesn't have a clasp to break open */
1181.                 Your("%s tears apart!", cloak_simple_name(otmp));
1182.                 (void) Cloak_off();
1183.                 useup(otmp);
1184.             } else if (otmp->otyp == ALCHEMY_SMOCK) {
1185.                 pline_The("knot on your %s is pulled apart!", cloak_simple_name(otmp));
1186.                 (void) Cloak_off();
1187.                 dropp(otmp);
1188.             } else {
1189.                 pline_The("clasp on your %s breaks open!", cloak_simple_name(otmp));
1190.                 (void) Cloak_off();
1191.                 dropp(otmp);
1192.             }
1193.         }
1194.         if (uarmu) {
1195.             Your("shirt rips to shreds!");
1196.             useup(uarmu);
1197.         }
1198.     } else if (sliparm(uptr)) {
1199.         if ((otmp = uarm) != 0 && racial_exception(&gy.youmonst, otmp) < 1) {
1200.             if (donning(otmp))
1201.                 cancel_don();
1202.             Your("armor falls around you!");
1203.             /* [note: _gone() instead of _off() dates to when life-saving
1204.                could force fire resisting armor back on if hero burned in
1205.                hell (3.0, predating Gehennom); the armor isn't actually
1206.                gone here but also isn't available to be put back on] */
1207.             (void) Armor_gone();
1208.             dropp(otmp);
1209.         }
1210.         if ((otmp = uarmc) != 0
1211.             /* mummy wrapping adapts to small and very big sizes */
1212.             && (otmp->otyp != MUMMY_WRAPPING || !WrappingAllowed(uptr))) {
1213.             if (is_whirly(uptr))
1214.                 Your("%s falls, unsupported!", cloak_simple_name(otmp));
1215.             else
1216.                 You("shrink out of your %s!", cloak_simple_name(otmp));
1217.             (void) Cloak_off();
1218.             dropp(otmp);
1219.         }
1220.         if ((otmp = uarmu) != 0) {
1221.             if (is_whirly(uptr))
1222.                 You("seep right through your shirt!");
1223.             else
1224.                 You("become much too small for your shirt!");
1225.             setworn((struct obj *) 0, otmp->owornmask & W_ARMU);
1226.             dropp(otmp);
1227.         }
1228.     }
1229.     if (has_horns(uptr)) {
1230.         if ((otmp = uarmh) != 0) {
1231.             if (is_flimsy(otmp) && !donning(otmp)) {
1232.                 char hornbuf[BUFSZ];
1233. 
1234.                 /* Future possibilities: This could damage/destroy helmet */
1235.                 Sprintf(hornbuf, "horn%s", plur(num_horns(uptr)));
1236.                 Your("%s %s through %s.", hornbuf, vtense(hornbuf, "pierce"),
1237.                      yname(otmp));
1238.             } else {
1239.                 if (donning(otmp))
1240.                     cancel_don();
1241.                 Your("%s falls to the %s!", helm_simple_name(otmp),
1242.                      surface(u.ux, u.uy));
1243.                 (void) Helmet_off();
1244.                 dropp(otmp);
1245.             }
1246.         }
1247.     }
1248.     if (nohands(uptr) || verysmall(uptr)) {
1249.         if ((otmp = uarmg) != 0) {
1250.             if (donning(otmp))
1251.                 cancel_don();
1252.             /* Drop weapon along with gloves */
1253.             You("drop your gloves%s!", uwep ? " and weapon" : "");
1254.             drop_weapon(0);
1255.             (void) Gloves_off();
1256.             /* Glib manipulation (ends immediately) handled by Gloves_off */
1257.             dropp(otmp);
1258.         }
1259.         if ((otmp = uarms) != 0) {
1260.             You("can no longer hold your shield!");
1261.             (void) Shield_off();
1262.             dropp(otmp);
1263.         }
1264.         if ((otmp = uarmh) != 0) {
1265.             if (donning(otmp))
1266.                 cancel_don();
1267.             Your("%s falls to the %s!", helm_simple_name(otmp),
1268.                  surface(u.ux, u.uy));
1269.             (void) Helmet_off();
1270.             dropp(otmp);
1271.         }
1272.     }
1273.     if (nohands(uptr) || verysmall(uptr)
1274.         || slithy(uptr) || uptr->mlet == S_CENTAUR) {
1275.         if ((otmp = uarmf) != 0) {
1276.             if (donning(otmp))
1277.                 cancel_don();
1278.             if (is_whirly(uptr))
1279.                 Your("boots fall away!");
1280.             else
1281.                 Your("boots %s off your feet!",
1282.                      verysmall(uptr) ? "slide" : "are pushed");
1283.             (void) Boots_off();
1284.             dropp(otmp);
1285.         }
1286.     }
1287.     /* not armor, but eyewear shouldn't stay worn without a head to wear
1288.        it/them on (should also come off if head is too tiny or too huge,
1289.        but putting accessories on doesn't reject those cases [yet?]);
1290.        amulet stays worn */
1291.     if ((otmp = ublindf) != 0 && !has_head(uptr)) {
1292.         int l;
1293.         const char *eyewear = simpleonames(otmp); /* blindfold|towel|lenses */
1294. 
1295.         if (!strncmp(eyewear, "pair of ", l = 8)) /* lenses */
1296.             eyewear += l;
1297.         Your("%s %s off!", eyewear, vtense(eyewear, "fall"));
1298.         (void) Blindf_off((struct obj *) 0); /* Null: skip usual off mesg */
1299.         dropp(otmp);
1300.     }
1301.     /* rings stay worn even when no hands */
1302. }
1303. 
1304. staticfn void
1305. drop_weapon(int alone)
1306. {
1307.     struct obj *otmp;
1308.     const char *what, *which, *whichtoo;
1309.     boolean candropwep, candropswapwep, updateinv = TRUE;
1310. 
1311.     if (uwep) {
1312.         /* !alone check below is currently superfluous but in the
1313.          * future it might not be so if there are monsters which cannot
1314.          * wear gloves but can wield weapons
1315.          */
1316.         if (!alone || cantwield(gy.youmonst.data)) {
1317.             candropwep = canletgo(uwep, "");
1318.             candropswapwep = !u.twoweap || canletgo(uswapwep, "");
1319.             if (alone) {
1320.                 what = (candropwep && candropswapwep) ? "drop" : "release";
1321.                 which = is_sword(uwep) ? "sword" : weapon_descr(uwep);
1322.                 if (u.twoweap) {
1323.                     whichtoo =
1324.                         is_sword(uswapwep) ? "sword" : weapon_descr(uswapwep);
1325.                     if (strcmp(which, whichtoo))
1326.                         which = "weapon";
1327.                 }
1328.                 if (uwep->quan != 1L || u.twoweap)
1329.                     which = makeplural(which);
1330. 
1331.                 You("find you must %s %s %s!", what,
1332.                     the_your[!!strncmp(which, "corpse", 6)], which);
1333.             }
1334.             /* if either uwep or wielded uswapwep is flagged as 'in_use'
1335.                then don't drop it or explicitly update inventory; leave
1336.                those actions to caller (or caller's caller, &c) */
1337.             if (u.twoweap) {
1338.                 otmp = uswapwep;
1339.                 uswapwepgone();
1340.                 if (otmp->in_use)
1341.                     updateinv = FALSE;
1342.                 else if (candropswapwep)
1343.                     dropx(otmp);
1344.             }
1345.             otmp = uwep;
1346.             uwepgone();
1347.             if (otmp->in_use)
1348.                 updateinv = FALSE;
1349.             else if (candropwep)
1350.                 dropx(otmp);
1351.             /* [note: dropp vs dropx -- if heart of ahriman is wielded, we
1352.                might be losing levitation by dropping it; but that won't
1353.                happen until the drop, unlike Boots_off() dumping hero into
1354.                water and triggering emergency_disrobe() before dropx()] */
1355. 
1356.             if (updateinv)
1357.                 update_inventory();
1358.         } else if (!could_twoweap(gy.youmonst.data)) {
1359.             untwoweapon();
1360.         }
1361.     }
1362. }
1363. 
1364. /* return to original form, usually either due to polymorph timing out
1365.    or dying from loss of hit points while being polymorphed */
1366. void
1367. rehumanize(void)
1368. {
1369.     boolean was_flying = (Flying != 0);
1370. 
1371.     /* You can't revert back while unchanging */
1372.     if (Unchanging) {
1373.         if (u.mh < 1) {
1374.             svk.killer.format = NO_KILLER_PREFIX;
1375.             Strcpy(svk.killer.name, "killed while stuck in creature form");
1376.             done(DIED);
1377.             /* can get to here if declining to die in explore or wizard
1378.                mode; since we're wearing an amulet of unchanging we can't
1379.                be wearing an amulet of life-saving */
1380.             return; /* don't rehumanize after all */
1381.         } else if (uamul && uamul->otyp == AMULET_OF_UNCHANGING) {
1382.             Your("%s %s!", simpleonames(uamul), otense(uamul, "fail"));
1383.             observe_object(uamul);
1384.             makeknown(AMULET_OF_UNCHANGING);
1385.         }
1386.     }
1387. 
1388.     /*
1389.      * Right now, dying while being a shifted vampire (bat, cloud, wolf)
1390.      * reverts to human rather than to vampire.
1391.      */
1392. 
1393.     if (emits_light(gy.youmonst.data))
1394.         del_light_source(LS_MONSTER, monst_to_any(&gy.youmonst));
1395.     polyman("You return to %s form!", gu.urace.adj);
1396. 
1397.     if (u.uhp < 1) {
1398.         /* can only happen if some bit of code reduces u.uhp
1399.            instead of u.mh while poly'd */
1400.         Your("old form was not healthy enough to survive.");
1401.         Sprintf(svk.killer.name, "reverting to unhealthy %s form",
1402.                 gu.urace.adj);
1403.         svk.killer.format = KILLED_BY;
1404.         done(DIED);
1405.     }
1406.     nomul(0);
1407. 
1408.     disp.botl = TRUE;
1409.     gv.vision_full_recalc = 1;
1410.     encumber_msg();
1411.     update_inventory();
1412.     if (was_flying && !Flying && u.usteed)
1413.         You("and %s return gently to the %s.",
1414.             mon_nam(u.usteed), surface(u.ux, u.uy));
1415.     retouch_equipment(2);
1416.     if (!uarmg)
1417.         selftouch(no_longer_petrify_resistant);
1418. }
1419. 
1420. int
1421. dobreathe(void)
1422. {
1423.     struct attack *mattk;
1424. 
1425.     if (Strangled) {
1426.         You_cant("breathe.  Sorry.");
1427.         return ECMD_OK;
1428.     }
1429.     if (u.uen < 15) {
1430.         You("don't have enough energy to breathe!");
1431.         return ECMD_OK;
1432.     }
1433.     u.uen -= 15;
1434.     disp.botl = TRUE;
1435. 
1436.     if (!getdir((char *) 0))
1437.         return ECMD_CANCEL;
1438. 
1439.     mattk = attacktype_fordmg(gy.youmonst.data, AT_BREA, AD_ANY);
1440.     if (!mattk)
1441.         impossible("bad breath attack?"); /* mouthwash needed... */
1442.     else if (!u.dx && !u.dy && !u.dz)
1443.         ubreatheu(mattk);
1444.     else
1445.         ubuzz(BZ_U_BREATH(BZ_OFS_AD(mattk->adtyp)), (int) mattk->damn);
1446.     return ECMD_TIME;
1447. }
1448. 
1449. int
1450. dospit(void)
1451. {
1452.     struct obj *otmp;
1453.     struct attack *mattk;
1454. 
1455.     if (!getdir((char *) 0))
1456.         return ECMD_CANCEL;
1457.     mattk = attacktype_fordmg(gy.youmonst.data, AT_SPIT, AD_ANY);
1458.     if (!mattk) {
1459.         impossible("bad spit attack?");
1460.     } else {
1461.         switch (mattk->adtyp) {
1462.         case AD_BLND:
1463.         case AD_DRST:
1464.             otmp = mksobj(BLINDING_VENOM, TRUE, FALSE);
1465.             break;
1466.         default:
1467.             impossible("bad attack type in dospit");
1468.             FALLTHROUGH;
1469.             /*FALLTHRU*/
1470.         case AD_ACID:
1471.             otmp = mksobj(ACID_VENOM, TRUE, FALSE);
1472.             break;
1473.         }
1474.         otmp->spe = 1; /* to indicate it's yours */
1475.         throwit(otmp, 0L, FALSE, (struct obj *) 0);
1476.     }
1477.     return ECMD_TIME;
1478. }
1479. 
1480. int
1481. doremove(void)
1482. {
1483.     if (!Punished) {
1484.         if (u.utrap && u.utraptype == TT_BURIEDBALL) {
1485.             pline_The("ball and chain are buried firmly in the %s.",
1486.                       surface(u.ux, u.uy));
1487.             return ECMD_OK;
1488.         }
1489.         You("are not chained to anything!");
1490.         return ECMD_OK;
1491.     }
1492.     unpunish();
1493.     return ECMD_TIME;
1494. }
1495. 
1496. int
1497. dospinweb(void)
1498. {
1499.     coordxy x = u.ux, y = u.uy;
1500.     struct trap *ttmp = t_at(x, y);
1501.     /* disallow webs on water, lava, air & cloud */
1502.     boolean reject_terrain = is_pool_or_lava(x, y) || IS_AIR(levl[x][y].typ);
1503. 
1504.     /* [at the time this was written, it was not possible to be both a
1505.        webmaker and a flyer, but with the advent of amulet of flying that
1506.        became a possibility; at present hero can spin a web while flying] */
1507.     if (Levitation || reject_terrain) {
1508.         You("must be on %s ground to spin a web.",
1509.             reject_terrain ? "solid" : "the");
1510.         return ECMD_OK;
1511.     }
1512.     if (u.uswallow) {
1513.         You("release web fluid inside %s.", mon_nam(u.ustuck));
1514.         if (is_animal(u.ustuck->data)) {
1515.             expels(u.ustuck, u.ustuck->data, TRUE);
1516.             return ECMD_OK;
1517.         }
1518.         if (is_whirly(u.ustuck->data)) {
1519.             int i;
1520. 
1521.             for (i = 0; i < NATTK; i++)
1522.                 if (u.ustuck->data->mattk[i].aatyp == AT_ENGL)
1523.                     break;
1524.             if (i == NATTK)
1525.                 impossible("Swallower has no engulfing attack?");
1526.             else {
1527.                 char sweep[30];
1528. 
1529.                 sweep[0] = '\0';
1530.                 switch (u.ustuck->data->mattk[i].adtyp) {
1531.                 case AD_FIRE:
1532.                     Strcpy(sweep, "ignites and ");
1533.                     break;
1534.                 case AD_ELEC:
1535.                     Strcpy(sweep, "fries and ");
1536.                     break;
1537.                 case AD_COLD:
1538.                     Strcpy(sweep, "freezes, shatters and ");
1539.                     break;
1540.                 }
1541.                 pline_The("web %sis swept away!", sweep);
1542.             }
1543.             return ECMD_OK;
1544.         } /* default: a nasty jelly-like creature */
1545.         pline_The("web dissolves into %s.", mon_nam(u.ustuck));
1546.         return ECMD_OK;
1547.     }
1548.     if (u.utrap) {
1549.         You("cannot spin webs while stuck in a trap.");
1550.         return ECMD_OK;
1551.     }
1552.     exercise(A_DEX, TRUE);
1553.     if (ttmp) {
1554.         switch (ttmp->ttyp) {
1555.         case PIT:
1556.         case SPIKED_PIT:
1557.             You("spin a web, covering up the pit.");
1558.             deltrap(ttmp);
1559.             bury_objs(x, y);
1560.             newsym(x, y);
1561.             return ECMD_TIME;
1562.         case SQKY_BOARD:
1563.             pline_The("squeaky board is muffled.");
1564.             deltrap(ttmp);
1565.             newsym(x, y);
1566.             return ECMD_TIME;
1567.         case TELEP_TRAP:
1568.         case LEVEL_TELEP:
1569.         case MAGIC_PORTAL:
1570.         case VIBRATING_SQUARE:
1571.             Your("webbing vanishes!");
1572.             return ECMD_OK;
1573.         case WEB:
1574.             You("make the web thicker.");
1575.             return ECMD_TIME;
1576.         case HOLE:
1577.         case TRAPDOOR:
1578.             You("web over the %s.",
1579.                 (ttmp->ttyp == TRAPDOOR) ? "trap door" : "hole");
1580.             deltrap(ttmp);
1581.             newsym(x, y);
1582.             return ECMD_TIME;
1583.         case ROLLING_BOULDER_TRAP:
1584.             You("spin a web, jamming the trigger.");
1585.             deltrap(ttmp);
1586.             newsym(x, y);
1587.             return ECMD_TIME;
1588.         case ARROW_TRAP:
1589.         case DART_TRAP:
1590.         case BEAR_TRAP:
1591.         case ROCKTRAP:
1592.         case FIRE_TRAP:
1593.         case LANDMINE:
1594.         case SLP_GAS_TRAP:
1595.         case RUST_TRAP:
1596.         case MAGIC_TRAP:
1597.         case ANTI_MAGIC:
1598.         case POLY_TRAP:
1599.             You("have triggered a trap!");
1600.             dotrap(ttmp, NO_TRAP_FLAGS);
1601.             return ECMD_TIME;
1602.         default:
1603.             impossible("Webbing over trap type %d?", ttmp->ttyp);
1604.             return ECMD_OK;
1605.         }
1606.     } else if (On_stairs(x, y)) {
1607.         /* cop out: don't let them hide the stairs */
1608.         Your("web fails to impede access to the %s.",
1609.              (levl[x][y].typ == STAIRS) ? "stairs" : "ladder");
1610.         return ECMD_TIME;
1611.     }
1612.     ttmp = maketrap(x, y, WEB);
1613.     if (ttmp) {
1614.         You("spin a web.");
1615.         ttmp->madeby_u = 1;
1616.         feeltrap(ttmp);
1617.         if (*in_rooms(x, y, SHOPBASE))
1618.             add_damage(x, y, SHOP_WEB_COST);
1619.     }
1620.     return ECMD_TIME;
1621. }
1622. 
1623. int
1624. dosummon(void)
1625. {
1626.     int placeholder;
1627.     if (u.uen < 10) {
1628.         You("lack the energy to send forth a call for help!");
1629.         return ECMD_OK;
1630.     }
1631.     u.uen -= 10;
1632.     disp.botl = TRUE;
1633. 
1634.     You("call upon your brethren for help!");
1635.     exercise(A_WIS, TRUE);
1636.     if (!were_summon(gy.youmonst.data, TRUE, &placeholder, (char *) 0))
1637.         pline("But none arrive.");
1638.     return ECMD_TIME;
1639. }
1640. 
1641. int
1642. dogaze(void)
1643. {
1644.     struct monst *mtmp;
1645.     int looked = 0;
1646.     char qbuf[QBUFSZ];
1647.     int i;
1648.     uchar adtyp = 0;
1649. 
1650.     for (i = 0; i < NATTK; i++) {
1651.         if (gy.youmonst.data->mattk[i].aatyp == AT_GAZE) {
1652.             adtyp = gy.youmonst.data->mattk[i].adtyp;
1653.             break;
1654.         }
1655.     }
1656.     if (adtyp != AD_CONF && adtyp != AD_FIRE) {
1657.         impossible("gaze attack %d?", adtyp);
1658.         return ECMD_OK;
1659.     }
1660. 
1661.     if (Blind) {
1662.         You_cant("see anything to gaze at.");
1663.         return ECMD_OK;
1664.     } else if (Hallucination) {
1665.         You_cant("gaze at anything you can see.");
1666.         return ECMD_OK;
1667.     }
1668.     if (u.uen < 15) {
1669.         You("lack the energy to use your special gaze!");
1670.         return ECMD_OK;
1671.     }
1672.     u.uen -= 15;
1673.     disp.botl = TRUE;
1674. 
1675.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
1676.         if (DEADMONSTER(mtmp))
1677.             continue;
1678.         if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) {
1679.             looked++;
1680.             if (Invis && !perceives(mtmp->data)) {
1681.                 pline("%s seems not to notice your gaze.", Monnam(mtmp));
1682.             } else if (mtmp->minvis && !See_invisible) {
1683.                 You_cant("see where to gaze at %s.", Monnam(mtmp));
1684.             } else if (M_AP_TYPE(mtmp) == M_AP_FURNITURE
1685.                        || M_AP_TYPE(mtmp) == M_AP_OBJECT) {
1686.                 looked--;
1687.                 continue;
1688.             } else if (flags.safe_dog && mtmp->mtame && !Confusion) {
1689.                 You("avoid gazing at %s.", y_monnam(mtmp));
1690.             } else {
1691.                 if (flags.confirm && mtmp->mpeaceful && !Confusion) {
1692.                     Sprintf(qbuf, "Really %s %s?",
1693.                             (adtyp == AD_CONF) ? "confuse" : "attack",
1694.                             mon_nam(mtmp));
1695.                     if (y_n(qbuf) != 'y')
1696.                         continue;
1697.                 }
1698.                 setmangry(mtmp, TRUE);
1699.                 if (helpless(mtmp) || mtmp->mstun
1700.                     || !mtmp->mcansee || !haseyes(mtmp->data)) {
1701.                     looked--;
1702.                     continue;
1703.                 }
1704.                 /* No reflection check for consistency with when a monster
1705.                  * gazes at *you*--only medusa gaze gets reflected then.
1706.                  */
1707.                 if (adtyp == AD_CONF) {
1708.                     if (!mtmp->mconf)
1709.                         Your("gaze confuses %s!", mon_nam(mtmp));
1710.                     else
1711.                         pline("%s is getting more and more confused.",
1712.                               Monnam(mtmp));
1713.                     mtmp->mconf = 1;
1714.                 } else if (adtyp == AD_FIRE) {
1715.                     int dmg = d(2, 6), orig_dmg = dmg, lev = (int) u.ulevel;
1716. 
1717.                     You("attack %s with a fiery gaze!", mon_nam(mtmp));
1718.                     if (resists_fire(mtmp)) {
1719.                         pline_The("fire doesn't burn %s!", mon_nam(mtmp));
1720.                         dmg = 0;
1721.                     }
1722.                     if (lev > rn2(20)) {
1723.                         dmg += destroy_items(mtmp, AD_FIRE, orig_dmg);
1724.                         ignite_items(mtmp->minvent);
1725.                     }
1726.                     if (dmg)
1727.                         mtmp->mhp -= dmg;
1728.                     if (DEADMONSTER(mtmp))
1729.                         killed(mtmp);
1730.                 }
1731.                 /* For consistency with passive() in uhitm.c, this only
1732.                  * affects you if the monster is still alive.
1733.                  */
1734.                 if (DEADMONSTER(mtmp))
1735.                     continue;
1736. 
1737.                 if (mtmp->data == &mons[PM_FLOATING_EYE] && !mtmp->mcan) {
1738.                     if (!Free_action) {
1739.                         You("are frozen by %s gaze!",
1740.                             s_suffix(mon_nam(mtmp)));
1741.                         nomul((u.ulevel > 6 || rn2(4))
1742.                                   ? -d((int) mtmp->m_lev + 1,
1743.                                        (int) mtmp->data->mattk[0].damd)
1744.                                   : -200);
1745.                         gm.multi_reason = "frozen by a monster's gaze";
1746.                         gn.nomovemsg = 0;
1747.                         return ECMD_TIME;
1748.                     } else
1749.                         You("stiffen momentarily under %s gaze.",
1750.                             s_suffix(mon_nam(mtmp)));
1751.                 }
1752.                 /* Technically this one shouldn't affect you at all because
1753.                  * the Medusa gaze is an active monster attack that only
1754.                  * works on the monster's turn, but for it to *not* have an
1755.                  * effect would be too weird.
1756.                  */
1757.                 if (mtmp->data == &mons[PM_MEDUSA] && !mtmp->mcan) {
1758.                     pline("Gazing at the awake %s is not a very good idea.",
1759.                           l_monnam(mtmp));
1760.                     /* as if gazing at a sleeping anything is fruitful... */
1761.                     urgent_pline("You turn to stone...");
1762.                     svk.killer.format = KILLED_BY;
1763.                     Strcpy(svk.killer.name,
1764.                            "deliberately meeting Medusa's gaze");
1765.                     done(STONING);
1766.                 }
1767.             }
1768.         }
1769.     }
1770.     if (!looked)
1771.         You("gaze at no place in particular.");
1772.     return ECMD_TIME;
1773. }
1774. 
1775. /* called by domonability() for #monster */
1776. int
1777. dohide(void)
1778. {
1779.     boolean ismimic = gy.youmonst.data->mlet == S_MIMIC,
1780.             on_ceiling = is_clinger(gy.youmonst.data) || Flying;
1781. 
1782.     /* can't hide while being held (or holding) or while trapped
1783.        (except for floor hiders [trapper or mimic] in pits) */
1784.     if (u.ustuck || (u.utrap && (u.utraptype != TT_PIT || on_ceiling))) {
1785.         You_cant("hide while you're %s.",
1786.                  !u.ustuck ? "trapped"
1787.                    : u.uswallow ? (digests(u.ustuck->data) ? "swallowed"
1788.                                                            : "engulfed")
1789.                      : !sticks(gy.youmonst.data) ? "being held"
1790.                        : (humanoid(u.ustuck->data) ? "holding someone"
1791.                                                    : "holding that creature"));
1792.         if (u.uundetected || (ismimic && U_AP_TYPE != M_AP_NOTHING)) {
1793.             u.uundetected = 0;
1794.             gy.youmonst.m_ap_type = M_AP_NOTHING;
1795.             newsym(u.ux, u.uy);
1796.         }
1797.         return ECMD_OK;
1798.     }
1799.     /* note: hero-as-eel handling is incomplete but unnecessary;
1800.        such critters aren't offered the option of hiding via #monster */
1801.     if (gy.youmonst.data->mlet == S_EEL && !is_pool(u.ux, u.uy)) {
1802.         if (IS_FOUNTAIN(levl[u.ux][u.uy].typ))
1803.             pline_The("fountain is not deep enough to hide in.");
1804.         else
1805.             There("is no %s to hide in here.", hliquid("water"));
1806.         u.uundetected = 0;
1807.         return ECMD_OK;
1808.     }
1809.     if (hides_under(gy.youmonst.data)) {
1810.         long ct = 0L;
1811.         struct obj *otmp, *otop = svl.level.objects[u.ux][u.uy];
1812. 
1813.         if (!otop) {
1814.             There("is nothing to hide under here.");
1815.             u.uundetected = 0;
1816.             return ECMD_OK;
1817.         }
1818.         for (otmp = otop;
1819.              otmp && otmp->otyp == CORPSE
1820.                   && touch_petrifies(&mons[otmp->corpsenm]);
1821.              otmp = otmp->nexthere)
1822.             ct += otmp->quan;
1823.         /* otmp will be Null iff the entire pile consists of 'trice corpses */
1824.         if (!otmp && !Stone_resistance) {
1825.             char kbuf[BUFSZ];
1826.             const char *corpse_name = cxname(otop);
1827. 
1828.             /* for the plural case, we'll say "cockatrice corpses" or
1829.                "chickatrice corpses" depending on the top of the pile
1830.                even if both types are present */
1831.             if (ct == 1)
1832.                 corpse_name = an(corpse_name);
1833.             /* no need to check poly_when_stoned(); no hide-underers can
1834.                turn into stone golems instead of becoming petrified */
1835.             pline("Hiding under %s%s is a fatal mistake...",
1836.                   corpse_name, plur(ct));
1837.             Sprintf(kbuf, "hiding under %s%s", corpse_name, plur(ct));
1838.             instapetrify(kbuf);
1839.             /* only reach here if life-saved */
1840.             u.uundetected = 0;
1841.             return ECMD_TIME;
1842.         }
1843.     }
1844.     /* Planes of Air and Water */
1845.     if (on_ceiling && !has_ceiling(&u.uz)) {
1846.         There("is nowhere to hide above you.");
1847.         u.uundetected = 0;
1848.         return ECMD_OK;
1849.     }
1850.     if ((is_hider(gy.youmonst.data) && !Flying) /* floor hider */
1851.         && (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))) {
1852.         There("is nowhere to hide beneath you.");
1853.         u.uundetected = 0;
1854.         return ECMD_OK;
1855.     }
1856.     /* TODO? inhibit floor hiding at furniture locations, or
1857.      * else make youhiding() give smarter messages at such spots.
1858.      */
1859. 
1860.     if (u.uundetected || (ismimic && U_AP_TYPE != M_AP_NOTHING)) {
1861.         youhiding(FALSE, 1); /* "you are already hiding" */
1862.         return ECMD_OK;
1863.     }
1864. 
1865.     if (ismimic) {
1866.         /* should bring up a dialog "what would you like to imitate?" */
1867.         gy.youmonst.m_ap_type = M_AP_OBJECT;
1868.         gy.youmonst.mappearance = STRANGE_OBJECT;
1869.     } else
1870.         u.uundetected = 1;
1871.     newsym(u.ux, u.uy);
1872.     youhiding(FALSE, 0); /* "you are now hiding" */
1873.     return ECMD_TIME;
1874. }
1875. 
1876. int
1877. dopoly(void)
1878. {
1879.     struct permonst *savedat = gy.youmonst.data;
1880. 
1881.     if (is_vampire(gy.youmonst.data) || is_vampshifter(&gy.youmonst)) {
1882.         polyself(POLY_MONSTER);
1883.         if (savedat != gy.youmonst.data) {
1884.             You("transform into %s.",
1885.                 an(pmname(gy.youmonst.data, Ugender)));
1886.             newsym(u.ux, u.uy);
1887.         }
1888.     }
1889.     return ECMD_TIME;
1890. }
1891. 
1892. /* #monster for hero-as-mind_flayer giving psychic blast */
1893. int
1894. domindblast(void)
1895. {
1896.     struct monst *mtmp, *nmon;
1897.     int dmg;
1898. 
1899.     if (u.uen < 10) {
1900.         You("concentrate but lack the energy to maintain doing so.");
1901.         return ECMD_OK;
1902.     }
1903.     u.uen -= 10;
1904.     disp.botl = TRUE;
1905. 
1906.     You("concentrate.");
1907.     pline("A wave of psychic energy pours out.");
1908.     for (mtmp = fmon; mtmp; mtmp = nmon) {
1909.         int u_sen;
1910. 
1911.         nmon = mtmp->nmon;
1912.         if (DEADMONSTER(mtmp))
1913.             continue;
1914.         if (mdistu(mtmp) > BOLT_LIM * BOLT_LIM)
1915.             continue;
1916.         if (mtmp->mpeaceful)
1917.             continue;
1918.         if (mindless(mtmp->data))
1919.             continue;
1920.         u_sen = telepathic(mtmp->data) && !mtmp->mcansee;
1921.         if (u_sen || (telepathic(mtmp->data) && rn2(2)) || !rn2(10)) {
1922.             dmg = rnd(15);
1923.             /* wake it up first, to bring hidden monster out of hiding;
1924.                but in case it is currently peaceful, don't make it hostile
1925.                unless it will survive the psychic blast, otherwise hero
1926.                would avoid the penalty for killing it while peaceful */
1927.             wakeup(mtmp, (dmg > mtmp->mhp) ? TRUE : FALSE);
1928.             You("lock in on %s %s.", s_suffix(mon_nam(mtmp)),
1929.                 u_sen ? "telepathy"
1930.                 : telepathic(mtmp->data) ? "latent telepathy"
1931.                   : "mind");
1932.             mtmp->mhp -= dmg;
1933.             if (DEADMONSTER(mtmp))
1934.                 killed(mtmp);
1935.         }
1936.     }
1937.     return ECMD_TIME;
1938. }
1939. 
1940. void
1941. uunstick(void)
1942. {
1943.     struct monst *mtmp = u.ustuck;
1944. 
1945.     if (!mtmp) {
1946.         impossible("uunstick: no ustuck?");
1947.         return;
1948.     }
1949.     set_ustuck((struct monst *) 0); /* before pline() */
1950.     pline("%s is no longer in your clutches.", Monnam(mtmp));
1951. }
1952. 
1953. void
1954. skinback(boolean silently)
1955. {
1956.     if (uskin) {
1957.         int old_light = arti_light_radius(uskin);
1958. 
1959.         if (!silently)
1960.             Your("skin returns to its original form.");
1961.         uarm = uskin;
1962.         uskin = (struct obj *) 0;
1963.         /* undo save/restore hack */
1964.         uarm->owornmask &= ~I_SPECIAL;
1965. 
1966.         if (artifact_light(uarm))
1967.             maybe_adjust_light(uarm, old_light);
1968.     }
1969. }
1970. 
1971. const char *
1972. mbodypart(struct monst *mon, int part)
1973. {
1974.     static NEARDATA const char
1975.         *humanoid_parts[] = { "arm",       "eye",  "face",         "finger",
1976.                               "fingertip", "foot", "hand",         "handed",
1977.                               "head",      "leg",  "light headed", "neck",
1978.                               "spine",     "toe",  "hair",         "blood",
1979.                               "lung",      "nose", "stomach" },
1980.         *jelly_parts[] = { "pseudopod", "dark spot", "front",
1981.                            "pseudopod extension", "pseudopod extremity",
1982.                            "pseudopod root", "grasp", "grasped",
1983.                            "cerebral area", "lower pseudopod", "viscous",
1984.                            "middle", "surface", "pseudopod extremity",
1985.                            "ripples", "juices", "surface", "sensor",
1986.                            "stomach" },
1987.         *animal_parts[] = { "forelimb",  "eye",           "face",
1988.                             "foreclaw",  "claw tip",      "rear claw",
1989.                             "foreclaw",  "clawed",        "head",
1990.                             "rear limb", "light headed",  "neck",
1991.                             "spine",     "rear claw tip", "fur",
1992.                             "blood",     "lung",          "nose",
1993.                             "stomach" },
1994.         *bird_parts[] = { "wing",     "eye",  "face",         "wing",
1995.                           "wing tip", "foot", "wing",         "winged",
1996.                           "head",     "leg",  "light headed", "neck",
1997.                           "spine",    "toe",  "feathers",     "blood",
1998.                           "lung",     "bill", "stomach" },
1999.         *horse_parts[] = { "foreleg",  "eye",           "face",
2000.                            "forehoof", "hoof tip",      "rear hoof",
2001.                            "forehoof", "hooved",        "head",
2002.                            "rear leg", "light headed",  "neck",
2003.                            "backbone", "rear hoof tip", "mane",
2004.                            "blood",    "lung",          "nose",
2005.                            "stomach" },
2006.         *sphere_parts[] = { "appendage", "optic nerve", "body", "tentacle",
2007.                             "tentacle tip", "lower appendage", "tentacle",
2008.                             "tentacled", "body", "lower tentacle",
2009.                             "rotational", "equator", "body",
2010.                             "lower tentacle tip", "cilia", "life force",
2011.                             "retina", "olfactory nerve", "interior" },
2012.         *fungus_parts[] = { "mycelium", "visual area", "front",
2013.                             "hypha",    "hypha",       "root",
2014.                             "strand",   "stranded",    "cap area",
2015.                             "rhizome",  "sporulated",  "stalk",
2016.                             "root",     "rhizome tip", "spores",
2017.                             "juices",   "gill",        "gill",
2018.                             "interior" },
2019.         *vortex_parts[] = { "region",        "eye",           "front",
2020.                             "minor current", "minor current", "lower current",
2021.                             "swirl",         "swirled",       "central core",
2022.                             "lower current", "addled",        "center",
2023.                             "currents",      "edge",          "currents",
2024.                             "life force",    "center",        "leading edge",
2025.                             "interior" },
2026.         *snake_parts[] = { "vestigial limb", "eye", "face", "large scale",
2027.                            "large scale tip", "rear region", "scale gap",
2028.                            "scale gapped", "head", "rear region",
2029.                            "light headed", "neck", "length", "rear scale",
2030.                            "scales", "blood", "lung", "forked tongue",
2031.                            "stomach" },
2032.         *worm_parts[] = { "anterior segment", "light sensitive cell",
2033.                           "clitellum", "setae", "setae", "posterior segment",
2034.                           "segment", "segmented", "anterior segment",
2035.                           "posterior", "over stretched", "clitellum",
2036.                           "length", "posterior setae", "setae", "blood",
2037.                           "skin", "prostomium", "stomach" },
2038.         *spider_parts[] = { "pedipalp", "eye", "face", "pedipalp", "tarsus",
2039.                             "claw", "pedipalp", "palped", "cephalothorax",
2040.                             "leg", "spun out", "cephalothorax", "abdomen",
2041.                             "claw", "hair", "hemolymph", "book lung",
2042.                             "labrum", "digestive tract" },
2043.         *fish_parts[] = { "fin", "eye", "premaxillary", "pelvic axillary",
2044.                           "pelvic fin", "anal fin", "pectoral fin", "finned",
2045.                           "head", "peduncle", "played out", "gills",
2046.                           "dorsal fin", "caudal fin", "scales", "blood",
2047.                           "gill", "nostril", "stomach" };
2048.     /* claw attacks are overloaded in mons[]; most humanoids with
2049.        such attacks should still reference hands rather than claws */
2050.     static const char not_claws[] = {
2051.         S_HUMAN,     S_MUMMY,   S_ZOMBIE, S_ANGEL, S_NYMPH, S_LEPRECHAUN,
2052.         S_QUANTMECH, S_VAMPIRE, S_ORC,    S_GIANT, /* quest nemeses */
2053.         '\0' /* string terminator; assert( S_xxx != 0 ); */
2054.     };
2055.     struct permonst *mptr = mon->data;
2056. 
2057.     if (part <= NO_PART) {
2058.         impossible("mbodypart: bad part %d", part);
2059.         return "mystery part";
2060.     }
2061. 
2062.     /* some special cases */
2063.     if (mptr->mlet == S_DOG || mptr->mlet == S_FELINE
2064.         || mptr->mlet == S_RODENT || mptr == &mons[PM_OWLBEAR]) {
2065.         switch (part) {
2066.         case HAND:
2067.             return "paw";
2068.         case HANDED:
2069.             return "pawed";
2070.         case FOOT:
2071.             return "rear paw";
2072.         case ARM:
2073.         case LEG:
2074.             return horse_parts[part]; /* "foreleg", "rear leg" */
2075.         default:
2076.             break; /* for other parts, use animal_parts[] below */
2077.         }
2078.     } else if (mptr->mlet == S_YETI) { /* excl. owlbear due to 'if' above */
2079.         /* opposable thumbs, hence "hands", "arms", "legs", &c */
2080.         return humanoid_parts[part]; /* yeti/sasquatch, monkey/ape */
2081.     }
2082.     if ((part == HAND || part == HANDED)
2083.         && (humanoid(mptr) && attacktype(mptr, AT_CLAW)
2084.             && !strchr(not_claws, mptr->mlet) && mptr != &mons[PM_STONE_GOLEM]
2085.             && mptr != &mons[PM_AMOROUS_DEMON]))
2086.         return (part == HAND) ? "claw" : "clawed";
2087.     if ((mptr == &mons[PM_MUMAK] || mptr == &mons[PM_MASTODON])
2088.         && part == NOSE)
2089.         return "trunk";
2090.     if (mptr == &mons[PM_SHARK] && part == HAIR)
2091.         return "skin"; /* sharks don't have scales */
2092.     if ((mptr == &mons[PM_JELLYFISH] || mptr == &mons[PM_KRAKEN])
2093.         && (part == ARM || part == FINGER || part == HAND || part == FOOT
2094.             || part == TOE))
2095.         return "tentacle";
2096.     if (mptr == &mons[PM_FLOATING_EYE] && part == EYE)
2097.         return "cornea";
2098.     if (humanoid(mptr) && (part == ARM || part == FINGER || part == FINGERTIP
2099.                            || part == HAND || part == HANDED))
2100.         return humanoid_parts[part];
2101.     if (mptr->mlet == S_COCKATRICE)
2102.         return (part == HAIR) ? snake_parts[part] : bird_parts[part];
2103.     if (mptr == &mons[PM_RAVEN])
2104.         return bird_parts[part];
2105.     if (mptr->mlet == S_CENTAUR || mptr->mlet == S_UNICORN
2106.         || mptr == &mons[PM_KI_RIN]
2107.         || (mptr == &mons[PM_ROTHE] && part != HAIR))
2108.         return horse_parts[part];
2109.     if (mptr->mlet == S_LIGHT) {
2110.         if (part == HANDED)
2111.             return "rayed";
2112.         else if (part == ARM || part == FINGER || part == FINGERTIP
2113.                  || part == HAND)
2114.             return "ray";
2115.         else
2116.             return "beam";
2117.     }
2118.     if (mptr == &mons[PM_STALKER] && part == HEAD)
2119.         return "head";
2120.     if (mptr->mlet == S_EEL && mptr != &mons[PM_JELLYFISH])
2121.         return fish_parts[part];
2122.     if (mptr->mlet == S_WORM)
2123.         return worm_parts[part];
2124.     if (mptr->mlet == S_SPIDER)
2125.         return spider_parts[part];
2126.     if (slithy(mptr) || (mptr->mlet == S_DRAGON && part == HAIR))
2127.         return snake_parts[part];
2128.     if (mptr->mlet == S_EYE)
2129.         return sphere_parts[part];
2130.     if (mptr->mlet == S_JELLY || mptr->mlet == S_PUDDING
2131.         || mptr->mlet == S_BLOB || mptr == &mons[PM_JELLYFISH])
2132.         return jelly_parts[part];
2133.     if (mptr->mlet == S_VORTEX || mptr->mlet == S_ELEMENTAL)
2134.         return vortex_parts[part];
2135.     if (mptr->mlet == S_FUNGUS)
2136.         return fungus_parts[part];
2137.     if (humanoid(mptr))
2138.         return humanoid_parts[part];
2139.     return animal_parts[part];
2140. }
2141. 
2142. const char *
2143. body_part(int part)
2144. {
2145.     return mbodypart(&gy.youmonst, part);
2146. }
2147. 
2148. int
2149. poly_gender(void)
2150. {
2151.     /* Returns gender of polymorphed player;
2152.      * 0/1=same meaning as flags.female, 2=none.
2153.      */
2154.     if (is_neuter(gy.youmonst.data) || !humanoid(gy.youmonst.data))
2155.         return 2;
2156.     return flags.female;
2157. }
2158. 
2159. void
2160. ugolemeffects(int damtype, int dam)
2161. {
2162.     int heal = 0;
2163. 
2164.     /* We won't bother with "slow"/"haste" since players do not
2165.      * have a monster-specific slow/haste so there is no way to
2166.      * restore the old velocity once they are back to human.
2167.      */
2168.     if (u.umonnum != PM_FLESH_GOLEM && u.umonnum != PM_IRON_GOLEM)
2169.         return;
2170.     switch (damtype) {
2171.     case AD_ELEC:
2172.         if (u.umonnum == PM_FLESH_GOLEM)
2173.             heal = (dam + 5) / 6; /* Approx 1 per die */
2174.         break;
2175.     case AD_FIRE:
2176.         if (u.umonnum == PM_IRON_GOLEM)
2177.             heal = dam;
2178.         break;
2179.     }
2180.     if (heal && (u.mh < u.mhmax)) {
2181.         u.mh += heal;
2182.         if (u.mh > u.mhmax)
2183.             u.mh = u.mhmax;
2184.         disp.botl = TRUE;
2185.         pline("Strangely, you feel better than before.");
2186.         exercise(A_STR, TRUE);
2187.     }
2188. }
2189. 
2190. staticfn int
2191. armor_to_dragon(int atyp)
2192. {
2193.     switch (atyp) {
2194.     case GRAY_DRAGON_SCALE_MAIL:
2195.     case GRAY_DRAGON_SCALES:
2196.         return PM_GRAY_DRAGON;
2197.     case SILVER_DRAGON_SCALE_MAIL:
2198.     case SILVER_DRAGON_SCALES:
2199.         return PM_SILVER_DRAGON;
2200.     case GOLD_DRAGON_SCALE_MAIL:
2201.     case GOLD_DRAGON_SCALES:
2202.         return PM_GOLD_DRAGON;
2203. #if 0 /* DEFERRED */
2204.     case SHIMMERING_DRAGON_SCALE_MAIL:
2205.     case SHIMMERING_DRAGON_SCALES:
2206.         return PM_SHIMMERING_DRAGON;
2207. #endif
2208.     case RED_DRAGON_SCALE_MAIL:
2209.     case RED_DRAGON_SCALES:
2210.         return PM_RED_DRAGON;
2211.     case ORANGE_DRAGON_SCALE_MAIL:
2212.     case ORANGE_DRAGON_SCALES:
2213.         return PM_ORANGE_DRAGON;
2214.     case WHITE_DRAGON_SCALE_MAIL:
2215.     case WHITE_DRAGON_SCALES:
2216.         return PM_WHITE_DRAGON;
2217.     case BLACK_DRAGON_SCALE_MAIL:
2218.     case BLACK_DRAGON_SCALES:
2219.         return PM_BLACK_DRAGON;
2220.     case BLUE_DRAGON_SCALE_MAIL:
2221.     case BLUE_DRAGON_SCALES:
2222.         return PM_BLUE_DRAGON;
2223.     case GREEN_DRAGON_SCALE_MAIL:
2224.     case GREEN_DRAGON_SCALES:
2225.         return PM_GREEN_DRAGON;
2226.     case YELLOW_DRAGON_SCALE_MAIL:
2227.     case YELLOW_DRAGON_SCALES:
2228.         return PM_YELLOW_DRAGON;
2229.     default:
2230.         return NON_PM;
2231.     }
2232. }
2233. 
2234. /* some species have awareness of other species */
2235. staticfn void
2236. polysense(void)
2237. {
2238.     short warnidx = NON_PM;
2239. 
2240.     svc.context.warntype.speciesidx = NON_PM;
2241.     svc.context.warntype.species = 0;
2242.     svc.context.warntype.polyd = 0;
2243.     HWarn_of_mon &= ~FROMRACE;
2244. 
2245.     switch (u.umonnum) {
2246.     case PM_PURPLE_WORM:
2247.     case PM_BABY_PURPLE_WORM:
2248.         warnidx = PM_SHRIEKER;
2249.         break;
2250.     case PM_VAMPIRE:
2251.     case PM_VAMPIRE_LEADER:
2252.         svc.context.warntype.polyd = M2_HUMAN | M2_ELF;
2253.         HWarn_of_mon |= FROMRACE;
2254.         return;
2255.     }
2256.     if (ismnum(warnidx)) {
2257.         svc.context.warntype.speciesidx = warnidx;
2258.         svc.context.warntype.species = &mons[warnidx];
2259.         HWarn_of_mon |= FROMRACE;
2260.     }
2261. }
2262. 
2263. /* True iff hero's role or race has been genocided */
2264. boolean
2265. ugenocided(void)
2266. {
2267.     return ((svm.mvitals[gu.urole.mnum].mvflags & G_GENOD)
2268.             || (svm.mvitals[gu.urace.mnum].mvflags & G_GENOD));
2269. }
2270. 
2271. /* how hero feels "inside" after self-genocide of role or race */
2272. const char *
2273. udeadinside(void)
2274. {
2275.     /* self-genocide used to always say "you feel dead inside" but that
2276.        seems silly when you're polymorphed into something undead;
2277.        monkilled() distinguishes between living (killed) and non (destroyed)
2278.        for monster death message; we refine the nonliving aspect a bit */
2279.     return !nonliving(gy.youmonst.data)
2280.              ? "dead"          /* living, including demons */
2281.              : !weirdnonliving(gy.youmonst.data)
2282.                  ? "condemned" /* undead plus manes */
2283.                  : "empty";    /* golems plus vortices */
2284. }
2285. 
2286. /*polyself.c*/