Source:NetHack 3.6.2/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 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/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 3.6	polyself.c	$NHDT-Date: 1556497911 2019/04/29 00:31:51 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.132 $ */
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 both youmonst.m_id
9.  * and youmonst.mx will always remain 0 when it handles the case of the
10.  * 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. STATIC_DCL void FDECL(check_strangling, (BOOLEAN_P));
25. STATIC_DCL void FDECL(polyman, (const char *, const char *));
26. STATIC_DCL void NDECL(break_armor);
27. STATIC_DCL void FDECL(drop_weapon, (int));
28. STATIC_DCL int FDECL(armor_to_dragon, (int));
29. STATIC_DCL void NDECL(newman);
30. STATIC_DCL void NDECL(polysense);
31. 
32. STATIC_VAR const char no_longer_petrify_resistant[] =
33.     "No longer petrify-resistant, you";
34. 
35. /* controls whether taking on new form or becoming new man can also
36.    change sex (ought to be an arg to polymon() and newman() instead) */
37. STATIC_VAR int sex_change_ok = 0;
38. 
39. /* update the youmonst.data structure pointer and intrinsics */
40. void
41. set_uasmon()
42. {
43.     struct permonst *mdat = &mons[u.umonnum];
44. 
45.     set_mon_data(&youmonst, mdat);
46. 
47. #define PROPSET(PropIndx, ON)                          \
48.     do {                                               \
49.         if (ON)                                        \
50.             u.uprops[PropIndx].intrinsic |= FROMFORM;  \
51.         else                                           \
52.             u.uprops[PropIndx].intrinsic &= ~FROMFORM; \
53.     } while (0)
54. 
55.     PROPSET(FIRE_RES, resists_fire(&youmonst));
56.     PROPSET(COLD_RES, resists_cold(&youmonst));
57.     PROPSET(SLEEP_RES, resists_sleep(&youmonst));
58.     PROPSET(DISINT_RES, resists_disint(&youmonst));
59.     PROPSET(SHOCK_RES, resists_elec(&youmonst));
60.     PROPSET(POISON_RES, resists_poison(&youmonst));
61.     PROPSET(ACID_RES, resists_acid(&youmonst));
62.     PROPSET(STONE_RES, resists_ston(&youmonst));
63.     {
64.         /* resists_drli() takes wielded weapon into account; suppress it */
65.         struct obj *save_uwep = uwep;
66. 
67.         uwep = 0;
68.         PROPSET(DRAIN_RES, resists_drli(&youmonst));
69.         uwep = save_uwep;
70.     }
71.     /* resists_magm() takes wielded, worn, and carried equipment into
72.        into account; cheat and duplicate its monster-specific part */
73.     PROPSET(ANTIMAGIC, (dmgtype(mdat, AD_MAGM)
74.                         || mdat == &mons[PM_BABY_GRAY_DRAGON]
75.                         || dmgtype(mdat, AD_RBRE)));
76.     PROPSET(SICK_RES, (mdat->mlet == S_FUNGUS || mdat == &mons[PM_GHOUL]));
77. 
78.     PROPSET(STUNNED, (mdat == &mons[PM_STALKER] || is_bat(mdat)));
79.     PROPSET(HALLUC_RES, dmgtype(mdat, AD_HALU));
80.     PROPSET(SEE_INVIS, perceives(mdat));
81.     PROPSET(TELEPAT, telepathic(mdat));
82.     /* note that Infravision uses mons[race] rather than usual mons[role] */
83.     PROPSET(INFRAVISION, infravision(Upolyd ? mdat : &mons[urace.malenum]));
84.     PROPSET(INVIS, pm_invisible(mdat));
85.     PROPSET(TELEPORT, can_teleport(mdat));
86.     PROPSET(TELEPORT_CONTROL, control_teleport(mdat));
87.     PROPSET(LEVITATION, is_floater(mdat));
88.     /* floating eye is the only 'floater'; it is also flagged as a 'flyer';
89.        suppress flying for it so that enlightenment doesn't confusingly
90.        show latent flight capability always blocked by levitation */
91.     PROPSET(FLYING, (is_flyer(mdat) && !is_floater(mdat)));
92.     PROPSET(SWIMMING, is_swimmer(mdat));
93.     /* [don't touch MAGICAL_BREATHING here; both Amphibious and Breathless
94.        key off of it but include different monster forms...] */
95.     PROPSET(PASSES_WALLS, passes_walls(mdat));
96.     PROPSET(REGENERATION, regenerates(mdat));
97.     PROPSET(REFLECTING, (mdat == &mons[PM_SILVER_DRAGON]));
98. #undef PROPSET
99. 
100.     float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
101.     polysense();
102. 
103. #ifdef STATUS_HILITES
104.     if (VIA_WINDOWPORT())
105.         status_initialize(REASSESS_ONLY);
106. #endif
107. }
108. 
109. /* Levitation overrides Flying; set or clear BFlying|I_SPECIAL */
110. void
111. float_vs_flight()
112. {
113.     boolean stuck_in_floor = (u.utrap && u.utraptype != TT_PIT);
114. 
115.     /* floating overrides flight; so does being trapped in the floor */
116.     if ((HLevitation || ELevitation)
117.         || ((HFlying || EFlying) && stuck_in_floor))
118.         BFlying |= I_SPECIAL;
119.     else
120.         BFlying &= ~I_SPECIAL;
121.     /* being trapped on the ground (bear trap, web, molten lava survived
122.        with fire resistance, former lava solidified via cold, tethered
123.        to a buried iron ball) overrides floating--the floor is reachable */
124.     if ((HLevitation || ELevitation) && stuck_in_floor)
125.         BLevitation |= I_SPECIAL;
126.     else
127.         BLevitation &= ~I_SPECIAL;
128.     context.botl = TRUE;
129. }
130. 
131. /* for changing into form that's immune to strangulation */
132. STATIC_OVL void
133. check_strangling(on)
134. boolean on;
135. {
136.     /* on -- maybe resume strangling */
137.     if (on) {
138.         /* when Strangled is already set, polymorphing from one
139.            vulnerable form into another causes the counter to be reset */
140.         if (uamul && uamul->otyp == AMULET_OF_STRANGULATION
141.             && can_be_strangled(&youmonst)) {
142.             Strangled = 6L;
143.             context.botl = TRUE;
144.             Your("%s %s your %s!", simpleonames(uamul),
145.                  Strangled ? "still constricts" : "begins constricting",
146.                  body_part(NECK)); /* "throat" */
147.             makeknown(AMULET_OF_STRANGULATION);
148.         }
149. 
150.     /* off -- maybe block strangling */
151.     } else {
152.         if (Strangled && !can_be_strangled(&youmonst)) {
153.             Strangled = 0L;
154.             context.botl = TRUE;
155.             You("are no longer being strangled.");
156.         }
157.     }
158. }
159. 
160. /* make a (new) human out of the player */
161. STATIC_OVL void
162. polyman(fmt, arg)
163. const char *fmt, *arg;
164. {
165.     boolean sticky = (sticks(youmonst.data) && u.ustuck && !u.uswallow),
166.             was_mimicking = (U_AP_TYPE == M_AP_OBJECT);
167.     boolean was_blind = !!Blind;
168. 
169.     if (Upolyd) {
170.         u.acurr = u.macurr; /* restore old attribs */
171.         u.amax = u.mamax;
172.         u.umonnum = u.umonster;
173.         flags.female = u.mfemale;
174.     }
175.     set_uasmon();
176. 
177.     u.mh = u.mhmax = 0;
178.     u.mtimedone = 0;
179.     skinback(FALSE);
180.     u.uundetected = 0;
181. 
182.     if (sticky)
183.         uunstick();
184.     find_ac();
185.     if (was_mimicking) {
186.         if (multi < 0)
187.             unmul("");
188.         youmonst.m_ap_type = M_AP_NOTHING;
189.     }
190. 
191.     newsym(u.ux, u.uy);
192. 
193.     You(fmt, arg);
194.     /* check whether player foolishly genocided self while poly'd */
195.     if (ugenocided()) {
196.         /* intervening activity might have clobbered genocide info */
197.         struct kinfo *kptr = find_delayed_killer(POLYMORPH);
198. 
199.         if (kptr != (struct kinfo *) 0 && kptr->name[0]) {
200.             killer.format = kptr->format;
201.             Strcpy(killer.name, kptr->name);
202.         } else {
203.             killer.format = KILLED_BY;
204.             Strcpy(killer.name, "self-genocide");
205.         }
206.         dealloc_killer(kptr);
207.         done(GENOCIDED);
208.     }
209. 
210.     if (u.twoweap && !could_twoweap(youmonst.data))
211.         untwoweapon();
212. 
213.     if (u.utrap && u.utraptype == TT_PIT) {
214.         set_utrap(rn1(6, 2), TT_PIT); /* time to escape resets */
215.     }
216.     if (was_blind && !Blind) { /* reverting from eyeless */
217.         Blinded = 1L;
218.         make_blinded(0L, TRUE); /* remove blindness */
219.     }
220.     check_strangling(TRUE);
221. 
222.     if (!Levitation && !u.ustuck && is_pool_or_lava(u.ux, u.uy))
223.         spoteffects(TRUE);
224. 
225.     see_monsters();
226. }
227. 
228. void
229. change_sex()
230. {
231.     /* setting u.umonster for caveman/cavewoman or priest/priestess
232.        swap unintentionally makes `Upolyd' appear to be true */
233.     boolean already_polyd = (boolean) Upolyd;
234. 
235.     /* Some monsters are always of one sex and their sex can't be changed;
236.      * Succubi/incubi can change, but are handled below.
237.      *
238.      * !already_polyd check necessary because is_male() and is_female()
239.      * are true if the player is a priest/priestess.
240.      */
241.     if (!already_polyd
242.         || (!is_male(youmonst.data) && !is_female(youmonst.data)
243.             && !is_neuter(youmonst.data)))
244.         flags.female = !flags.female;
245.     if (already_polyd) /* poly'd: also change saved sex */
246.         u.mfemale = !u.mfemale;
247.     max_rank_sz(); /* [this appears to be superfluous] */
248.     if ((already_polyd ? u.mfemale : flags.female) && urole.name.f)
249.         Strcpy(pl_character, urole.name.f);
250.     else
251.         Strcpy(pl_character, urole.name.m);
252.     u.umonster = ((already_polyd ? u.mfemale : flags.female)
253.                   && urole.femalenum != NON_PM)
254.                      ? urole.femalenum
255.                      : urole.malenum;
256.     if (!already_polyd) {
257.         u.umonnum = u.umonster;
258.     } else if (u.umonnum == PM_SUCCUBUS || u.umonnum == PM_INCUBUS) {
259.         flags.female = !flags.female;
260.         /* change monster type to match new sex */
261.         u.umonnum = (u.umonnum == PM_SUCCUBUS) ? PM_INCUBUS : PM_SUCCUBUS;
262.         set_uasmon();
263.     }
264. }
265. 
266. STATIC_OVL void
267. newman()
268. {
269.     int i, oldlvl, newlvl, hpmax, enmax;
270. 
271.     oldlvl = u.ulevel;
272.     newlvl = oldlvl + rn1(5, -2);     /* new = old + {-2,-1,0,+1,+2} */
273.     if (newlvl > 127 || newlvl < 1) { /* level went below 0? */
274.         goto dead; /* old level is still intact (in case of lifesaving) */
275.     }
276.     if (newlvl > MAXULEV)
277.         newlvl = MAXULEV;
278.     /* If your level goes down, your peak level goes down by
279.        the same amount so that you can't simply use blessed
280.        full healing to undo the decrease.  But if your level
281.        goes up, your peak level does *not* undergo the same
282.        adjustment; you might end up losing out on the chance
283.        to regain some levels previously lost to other causes. */
284.     if (newlvl < oldlvl)
285.         u.ulevelmax -= (oldlvl - newlvl);
286.     if (u.ulevelmax < newlvl)
287.         u.ulevelmax = newlvl;
288.     u.ulevel = newlvl;
289. 
290.     if (sex_change_ok && !rn2(10))
291.         change_sex();
292. 
293.     adjabil(oldlvl, (int) u.ulevel);
294.     reset_rndmonst(NON_PM); /* new monster generation criteria */
295. 
296.     /* random experience points for the new experience level */
297.     u.uexp = rndexp(FALSE);
298. 
299.     /* set up new attribute points (particularly Con) */
300.     redist_attr();
301. 
302.     /*
303.      * New hit points:
304.      *  remove level-gain based HP from any extra HP accumulated
305.      *  (the "extra" might actually be negative);
306.      *  modify the extra, retaining {80%, 90%, 100%, or 110%};
307.      *  add in newly generated set of level-gain HP.
308.      *
309.      * (This used to calculate new HP in direct proportion to old HP,
310.      * but that was subject to abuse:  accumulate a large amount of
311.      * extra HP, drain level down to 1, then polyself to level 2 or 3
312.      * [lifesaving capability needed to handle level 0 and -1 cases]
313.      * and the extra got multiplied by 2 or 3.  Repeat the level
314.      * drain and polyself steps until out of lifesaving capability.)
315.      */
316.     hpmax = u.uhpmax;
317.     for (i = 0; i < oldlvl; i++)
318.         hpmax -= (int) u.uhpinc[i];
319.     /* hpmax * rn1(4,8) / 10; 0.95*hpmax on average */
320.     hpmax = rounddiv((long) hpmax * (long) rn1(4, 8), 10);
321.     for (i = 0; (u.ulevel = i) < newlvl; i++)
322.         hpmax += newhp();
323.     if (hpmax < u.ulevel)
324.         hpmax = u.ulevel; /* min of 1 HP per level */
325.     /* retain same proportion for current HP; u.uhp * hpmax / u.uhpmax */
326.     u.uhp = rounddiv((long) u.uhp * (long) hpmax, u.uhpmax);
327.     u.uhpmax = hpmax;
328.     /*
329.      * Do the same for spell power.
330.      */
331.     enmax = u.uenmax;
332.     for (i = 0; i < oldlvl; i++)
333.         enmax -= (int) u.ueninc[i];
334.     enmax = rounddiv((long) enmax * (long) rn1(4, 8), 10);
335.     for (i = 0; (u.ulevel = i) < newlvl; i++)
336.         enmax += newpw();
337.     if (enmax < u.ulevel)
338.         enmax = u.ulevel;
339.     u.uen = rounddiv((long) u.uen * (long) enmax,
340.                      ((u.uenmax < 1) ? 1 : u.uenmax));
341.     u.uenmax = enmax;
342.     /* [should alignment record be tweaked too?] */
343. 
344.     u.uhunger = rn1(500, 500);
345.     if (Sick)
346.         make_sick(0L, (char *) 0, FALSE, SICK_ALL);
347.     if (Stoned)
348.         make_stoned(0L, (char *) 0, 0, (char *) 0);
349.     if (u.uhp <= 0) {
350.         if (Polymorph_control) { /* even when Stunned || Unaware */
351.             if (u.uhp <= 0)
352.                 u.uhp = 1;
353.         } else {
354.         dead: /* we come directly here if their experience level went to 0 or
355.                  less */
356.             Your("new form doesn't seem healthy enough to survive.");
357.             killer.format = KILLED_BY_AN;
358.             Strcpy(killer.name, "unsuccessful polymorph");
359.             done(DIED);
360.             newuhs(FALSE);
361.             return; /* lifesaved */
362.         }
363.     }
364.     newuhs(FALSE);
365.     polyman("feel like a new %s!",
366.             /* use saved gender we're about to revert to, not current */
367.             ((Upolyd ? u.mfemale : flags.female) && urace.individual.f)
368.                 ? urace.individual.f
369.                 : (urace.individual.m)
370.                    ? urace.individual.m
371.                    : urace.noun);
372.     if (Slimed) {
373.         Your("body transforms, but there is still slime on you.");
374.         make_slimed(10L, (const char *) 0);
375.     }
376. 
377.     context.botl = 1;
378.     see_monsters();
379.     (void) encumber_msg();
380. 
381.     retouch_equipment(2);
382.     if (!uarmg)
383.         selftouch(no_longer_petrify_resistant);
384. }
385. 
386. void
387. polyself(psflags)
388. int psflags;
389. {
390.     char buf[BUFSZ] = DUMMY;
391.     int old_light, new_light, mntmp, class, tryct;
392.     boolean forcecontrol = (psflags == 1), monsterpoly = (psflags == 2),
393.             draconian = (uarm && Is_dragon_armor(uarm)),
394.             iswere = (u.ulycn >= LOW_PM), isvamp = is_vampire(youmonst.data),
395.             controllable_poly = Polymorph_control && !(Stunned || Unaware);
396. 
397.     if (Unchanging) {
398.         pline("You fail to transform!");
399.         return;
400.     }
401.     /* being Stunned|Unaware doesn't negate this aspect of Poly_control */
402.     if (!Polymorph_control && !forcecontrol && !draconian && !iswere
403.         && !isvamp) {
404.         if (rn2(20) > ACURR(A_CON)) {
405.             You1(shudder_for_moment);
406.             losehp(rnd(30), "system shock", KILLED_BY_AN);
407.             exercise(A_CON, FALSE);
408.             return;
409.         }
410.     }
411.     old_light = emits_light(youmonst.data);
412.     mntmp = NON_PM;
413. 
414.     if (monsterpoly && isvamp)
415.         goto do_vampyr;
416. 
417.     if (controllable_poly || forcecontrol) {
418.         tryct = 5;
419.         do {
420.             mntmp = NON_PM;
421.             getlin("Become what kind of monster? [type the name]", buf);
422.             (void) mungspaces(buf);
423.             if (*buf == '\033') {
424.                 /* user is cancelling controlled poly */
425.                 if (forcecontrol) { /* wizard mode #polyself */
426.                     pline1(Never_mind);
427.                     return;
428.                 }
429.                 Strcpy(buf, "*"); /* resort to random */
430.             }
431.             if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
432.                 /* explicitly requesting random result */
433.                 tryct = 0; /* will skip thats_enough_tries */
434.                 continue;  /* end do-while(--tryct > 0) loop */
435.             }
436.             class = 0;
437.             mntmp = name_to_mon(buf);
438.             if (mntmp < LOW_PM) {
439.             by_class:
440.                 class = name_to_monclass(buf, &mntmp);
441.                 if (class && mntmp == NON_PM)
442.                     mntmp = mkclass_poly(class);
443.             }
444.             if (mntmp < LOW_PM) {
445.                 if (!class)
446.                     pline("I've never heard of such monsters.");
447.                 else
448.                     You_cant("polymorph into any of those.");
449.             } else if (iswere && (were_beastie(mntmp) == u.ulycn
450.                                   || mntmp == counter_were(u.ulycn)
451.                                   || (Upolyd && mntmp == PM_HUMAN))) {
452.                 goto do_shift;
453.                 /* Note:  humans are illegal as monsters, but an
454.                  * illegal monster forces newman(), which is what we
455.                  * want if they specified a human.... */
456.             } else if (!polyok(&mons[mntmp])
457.                        && !(mntmp == PM_HUMAN || your_race(&mons[mntmp])
458.                             || mntmp == urole.malenum
459.                             || mntmp == urole.femalenum)) {
460.                 const char *pm_name;
461. 
462.                 /* mkclass_poly() can pick a !polyok()
463.                    candidate; if so, usually try again */
464.                 if (class) {
465.                     if (rn2(3) || --tryct > 0)
466.                         goto by_class;
467.                     /* no retries left; put one back on counter
468.                        so that end of loop decrement will yield
469.                        0 and trigger thats_enough_tries message */
470.                     ++tryct;
471.                 }
472.                 pm_name = mons[mntmp].mname;
473.                 if (the_unique_pm(&mons[mntmp]))
474.                     pm_name = the(pm_name);
475.                 else if (!type_is_pname(&mons[mntmp]))
476.                     pm_name = an(pm_name);
477.                 You_cant("polymorph into %s.", pm_name);
478.             } else
479.                 break;
480.         } while (--tryct > 0);
481.         if (!tryct)
482.             pline1(thats_enough_tries);
483.         /* allow skin merging, even when polymorph is controlled */
484.         if (draconian && (tryct <= 0 || mntmp == armor_to_dragon(uarm->otyp)))
485.             goto do_merge;
486.         if (isvamp && (tryct <= 0 || mntmp == PM_WOLF || mntmp == PM_FOG_CLOUD
487.                        || is_bat(&mons[mntmp])))
488.             goto do_vampyr;
489.     } else if (draconian || iswere || isvamp) {
490.         /* special changes that don't require polyok() */
491.         if (draconian) {
492.         do_merge:
493.             mntmp = armor_to_dragon(uarm->otyp);
494.             if (!(mvitals[mntmp].mvflags & G_GENOD)) {
495.                 /* allow G_EXTINCT */
496.                 if (Is_dragon_scales(uarm)) {
497.                     /* dragon scales remain intact as uskin */
498.                     You("merge with your scaly armor.");
499.                 } else { /* dragon scale mail */
500.                     /* d.scale mail first reverts to scales */
501.                     char *p, *dsmail;
502. 
503.                     /* similar to noarmor(invent.c),
504.                        shorten to "<color> scale mail" */
505.                     dsmail = strcpy(buf, simpleonames(uarm));
506.                     if ((p = strstri(dsmail, " dragon ")) != 0)
507.                         while ((p[1] = p[8]) != '\0')
508.                             ++p;
509.                     /* tricky phrasing; dragon scale mail
510.                        is singular, dragon scales are plural */
511.                     Your("%s reverts to scales as you merge with them.",
512.                          dsmail);
513.                     /* uarm->spe enchantment remains unchanged;
514.                        re-converting scales to mail poses risk
515.                        of evaporation due to over enchanting */
516.                     uarm->otyp += GRAY_DRAGON_SCALES - GRAY_DRAGON_SCALE_MAIL;
517.                     uarm->dknown = 1;
518.                     context.botl = 1; /* AC is changing */
519.                 }
520.                 uskin = uarm;
521.                 uarm = (struct obj *) 0;
522.                 /* save/restore hack */
523.                 uskin->owornmask |= I_SPECIAL;
524.                 update_inventory();
525.             }
526.         } else if (iswere) {
527.         do_shift:
528.             if (Upolyd && were_beastie(mntmp) != u.ulycn)
529.                 mntmp = PM_HUMAN; /* Illegal; force newman() */
530.             else
531.                 mntmp = u.ulycn;
532.         } else if (isvamp) {
533.         do_vampyr:
534.             if (mntmp < LOW_PM || (mons[mntmp].geno & G_UNIQ))
535.                 mntmp = (youmonst.data != &mons[PM_VAMPIRE] && !rn2(10))
536.                             ? PM_WOLF
537.                             : !rn2(4) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
538.             if (controllable_poly) {
539.                 Sprintf(buf, "Become %s?", an(mons[mntmp].mname));
540.                 if (yn(buf) != 'y')
541.                     return;
542.             }
543.         }
544.         /* if polymon fails, "you feel" message has been given
545.            so don't follow up with another polymon or newman;
546.            sex_change_ok left disabled here */
547.         if (mntmp == PM_HUMAN)
548.             newman(); /* werecritter */
549.         else
550.             (void) polymon(mntmp);
551.         goto made_change; /* maybe not, but this is right anyway */
552.     }
553. 
554.     if (mntmp < LOW_PM) {
555.         tryct = 200;
556.         do {
557.             /* randomly pick an "ordinary" monster */
558.             mntmp = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
559.             if (polyok(&mons[mntmp]) && !is_placeholder(&mons[mntmp]))
560.                 break;
561.         } while (--tryct > 0);
562.     }
563. 
564.     /* The below polyok() fails either if everything is genocided, or if
565.      * we deliberately chose something illegal to force newman().
566.      */
567.     sex_change_ok++;
568.     if (!polyok(&mons[mntmp]) || (!forcecontrol && !rn2(5))
569.         || your_race(&mons[mntmp])) {
570.         newman();
571.     } else {
572.         (void) polymon(mntmp);
573.     }
574.     sex_change_ok--; /* reset */
575. 
576. made_change:
577.     new_light = emits_light(youmonst.data);
578.     if (old_light != new_light) {
579.         if (old_light)
580.             del_light_source(LS_MONSTER, monst_to_any(&youmonst));
581.         if (new_light == 1)
582.             ++new_light; /* otherwise it's undetectable */
583.         if (new_light)
584.             new_light_source(u.ux, u.uy, new_light, LS_MONSTER,
585.                              monst_to_any(&youmonst));
586.     }
587. }
588. 
589. /* (try to) make a mntmp monster out of the player;
590.    returns 1 if polymorph successful */
591. int
592. polymon(mntmp)
593. int mntmp;
594. {
595.     char buf[BUFSZ];
596.     boolean sticky = sticks(youmonst.data) && u.ustuck && !u.uswallow,
597.             was_blind = !!Blind, dochange = FALSE;
598.     int mlvl;
599. 
600.     if (mvitals[mntmp].mvflags & G_GENOD) { /* allow G_EXTINCT */
601.         You_feel("rather %s-ish.", mons[mntmp].mname);
602.         exercise(A_WIS, TRUE);
603.         return 0;
604.     }
605. 
606.     /* KMH, conduct */
607.     u.uconduct.polyselfs++;
608. 
609.     /* exercise used to be at the very end but only Wis was affected
610.        there since the polymorph was always in effect by then */
611.     exercise(A_CON, FALSE);
612.     exercise(A_WIS, TRUE);
613. 
614.     if (!Upolyd) {
615.         /* Human to monster; save human stats */
616.         u.macurr = u.acurr;
617.         u.mamax = u.amax;
618.         u.mfemale = flags.female;
619.     } else {
620.         /* Monster to monster; restore human stats, to be
621.          * immediately changed to provide stats for the new monster
622.          */
623.         u.acurr = u.macurr;
624.         u.amax = u.mamax;
625.         flags.female = u.mfemale;
626.     }
627. 
628.     /* if stuck mimicking gold, stop immediately */
629.     if (multi < 0 && U_AP_TYPE == M_AP_OBJECT
630.         && youmonst.data->mlet != S_MIMIC)
631.         unmul("");
632.     /* if becoming a non-mimic, stop mimicking anything */
633.     if (mons[mntmp].mlet != S_MIMIC) {
634.         /* as in polyman() */
635.         youmonst.m_ap_type = M_AP_NOTHING;
636.     }
637.     if (is_male(&mons[mntmp])) {
638.         if (flags.female)
639.             dochange = TRUE;
640.     } else if (is_female(&mons[mntmp])) {
641.         if (!flags.female)
642.             dochange = TRUE;
643.     } else if (!is_neuter(&mons[mntmp]) && mntmp != u.ulycn) {
644.         if (sex_change_ok && !rn2(10))
645.             dochange = TRUE;
646.     }
647. 
648.     Strcpy(buf, (u.umonnum != mntmp) ? "" : "new ");
649.     if (dochange) {
650.         flags.female = !flags.female;
651.         Strcat(buf, (is_male(&mons[mntmp]) || is_female(&mons[mntmp]))
652.                        ? "" : flags.female ? "female " : "male ");
653.     }
654.     Strcat(buf, mons[mntmp].mname);
655.     You("%s %s!", (u.umonnum != mntmp) ? "turn into" : "feel like", an(buf));
656. 
657.     if (Stoned && poly_when_stoned(&mons[mntmp])) {
658.         /* poly_when_stoned already checked stone golem genocide */
659.         mntmp = PM_STONE_GOLEM;
660.         make_stoned(0L, "You turn to stone!", 0, (char *) 0);
661.     }
662. 
663.     u.mtimedone = rn1(500, 500);
664.     u.umonnum = mntmp;
665.     set_uasmon();
666. 
667.     /* New stats for monster, to last only as long as polymorphed.
668.      * Currently only strength gets changed.
669.      */
670.     if (strongmonst(&mons[mntmp]))
671.         ABASE(A_STR) = AMAX(A_STR) = STR18(100);
672. 
673.     if (Stone_resistance && Stoned) { /* parnes@eniac.seas.upenn.edu */
674.         make_stoned(0L, "You no longer seem to be petrifying.", 0,
675.                     (char *) 0);
676.     }
677.     if (Sick_resistance && Sick) {
678.         make_sick(0L, (char *) 0, FALSE, SICK_ALL);
679.         You("no longer feel sick.");
680.     }
681.     if (Slimed) {
682.         if (flaming(youmonst.data)) {
683.             make_slimed(0L, "The slime burns away!");
684.         } else if (mntmp == PM_GREEN_SLIME) {
685.             /* do it silently */
686.             make_slimed(0L, (char *) 0);
687.         }
688.     }
689.     check_strangling(FALSE); /* maybe stop strangling */
690.     if (nohands(youmonst.data))
691.         Glib = 0;
692. 
693.     /*
694.     mlvl = adj_lev(&mons[mntmp]);
695.      * We can't do the above, since there's no such thing as an
696.      * "experience level of you as a monster" for a polymorphed character.
697.      */
698.     mlvl = (int) mons[mntmp].mlevel;
699.     if (youmonst.data->mlet == S_DRAGON && mntmp >= PM_GRAY_DRAGON) {
700.         u.mhmax = In_endgame(&u.uz) ? (8 * mlvl) : (4 * mlvl + d(mlvl, 4));
701.     } else if (is_golem(youmonst.data)) {
702.         u.mhmax = golemhp(mntmp);
703.     } else {
704.         if (!mlvl)
705.             u.mhmax = rnd(4);
706.         else
707.             u.mhmax = d(mlvl, 8);
708.         if (is_home_elemental(&mons[mntmp]))
709.             u.mhmax *= 3;
710.     }
711.     u.mh = u.mhmax;
712. 
713.     if (u.ulevel < mlvl) {
714.         /* Low level characters can't become high level monsters for long */
715. #ifdef DUMB
716.         /* DRS/NS 2.2.6 messes up -- Peter Kendell */
717.         int mtd = u.mtimedone, ulv = u.ulevel;
718. 
719.         u.mtimedone = mtd * ulv / mlvl;
720. #else
721.         u.mtimedone = u.mtimedone * u.ulevel / mlvl;
722. #endif
723.     }
724. 
725.     if (uskin && mntmp != armor_to_dragon(uskin->otyp))
726.         skinback(FALSE);
727.     break_armor();
728.     drop_weapon(1);
729.     (void) hideunder(&youmonst);
730. 
731.     if (u.utrap && u.utraptype == TT_PIT) {
732.         set_utrap(rn1(6, 2), TT_PIT); /* time to escape resets */
733.     }
734.     if (was_blind && !Blind) { /* previous form was eyeless */
735.         Blinded = 1L;
736.         make_blinded(0L, TRUE); /* remove blindness */
737.     }
738.     newsym(u.ux, u.uy); /* Change symbol */
739. 
740.     /* [note:  this 'sticky' handling is only sufficient for changing from
741.        grabber to engulfer or vice versa because engulfing by poly'd hero
742.        always ends immediately so won't be in effect during a polymorph] */
743.     if (!sticky && !u.uswallow && u.ustuck && sticks(youmonst.data))
744.         u.ustuck = 0;
745.     else if (sticky && !sticks(youmonst.data))
746.         uunstick();
747. 
748.     if (u.usteed) {
749.         if (touch_petrifies(u.usteed->data) && !Stone_resistance && rnl(3)) {
750.             pline("%s touch %s.", no_longer_petrify_resistant,
751.                   mon_nam(u.usteed));
752.             Sprintf(buf, "riding %s", an(u.usteed->data->mname));
753.             instapetrify(buf);
754.         }
755.         if (!can_ride(u.usteed))
756.             dismount_steed(DISMOUNT_POLY);
757.     }
758. 
759.     if (flags.verbose) {
760.         static const char use_thec[] = "Use the command #%s to %s.";
761.         static const char monsterc[] = "monster";
762. 
763.         if (can_breathe(youmonst.data))
764.             pline(use_thec, monsterc, "use your breath weapon");
765.         if (attacktype(youmonst.data, AT_SPIT))
766.             pline(use_thec, monsterc, "spit venom");
767.         if (youmonst.data->mlet == S_NYMPH)
768.             pline(use_thec, monsterc, "remove an iron ball");
769.         if (attacktype(youmonst.data, AT_GAZE))
770.             pline(use_thec, monsterc, "gaze at monsters");
771.         if (is_hider(youmonst.data))
772.             pline(use_thec, monsterc, "hide");
773.         if (is_were(youmonst.data))
774.             pline(use_thec, monsterc, "summon help");
775.         if (webmaker(youmonst.data))
776.             pline(use_thec, monsterc, "spin a web");
777.         if (u.umonnum == PM_GREMLIN)
778.             pline(use_thec, monsterc, "multiply in a fountain");
779.         if (is_unicorn(youmonst.data))
780.             pline(use_thec, monsterc, "use your horn");
781.         if (is_mind_flayer(youmonst.data))
782.             pline(use_thec, monsterc, "emit a mental blast");
783.         if (youmonst.data->msound == MS_SHRIEK) /* worthless, actually */
784.             pline(use_thec, monsterc, "shriek");
785.         if (is_vampire(youmonst.data))
786.             pline(use_thec, monsterc, "change shape");
787. 
788.         if (lays_eggs(youmonst.data) && flags.female &&
789.             !(youmonst.data == &mons[PM_GIANT_EEL]
790.                 || youmonst.data == &mons[PM_ELECTRIC_EEL]))
791.             pline(use_thec, "sit",
792.                   eggs_in_water(youmonst.data) ?
793.                       "spawn in the water" : "lay an egg");
794.     }
795. 
796.     /* you now know what an egg of your type looks like */
797.     if (lays_eggs(youmonst.data)) {
798.         learn_egg_type(u.umonnum);
799.         /* make queen bees recognize killer bee eggs */
800.         learn_egg_type(egg_type_from_parent(u.umonnum, TRUE));
801.     }
802.     find_ac();
803.     if ((!Levitation && !u.ustuck && !Flying && is_pool_or_lava(u.ux, u.uy))
804.         || (Underwater && !Swimming))
805.         spoteffects(TRUE);
806.     if (Passes_walls && u.utrap
807.         && (u.utraptype == TT_INFLOOR || u.utraptype == TT_BURIEDBALL)) {
808.         if (u.utraptype == TT_INFLOOR) {
809.             pline_The("rock seems to no longer trap you.");
810.         } else {
811.             pline_The("buried ball is no longer bound to you.");
812.             buried_ball_to_freedom();
813.         }
814.         reset_utrap(TRUE);
815.     } else if (likes_lava(youmonst.data) && u.utrap
816.                && u.utraptype == TT_LAVA) {
817.         pline_The("%s now feels soothing.", hliquid("lava"));
818.         reset_utrap(TRUE);
819.     }
820.     if (amorphous(youmonst.data) || is_whirly(youmonst.data)
821.         || unsolid(youmonst.data)) {
822.         if (Punished) {
823.             You("slip out of the iron chain.");
824.             unpunish();
825.         } else if (u.utrap && u.utraptype == TT_BURIEDBALL) {
826.             You("slip free of the buried ball and chain.");
827.             buried_ball_to_freedom();
828.         }
829.     }
830.     if (u.utrap && (u.utraptype == TT_WEB || u.utraptype == TT_BEARTRAP)
831.         && (amorphous(youmonst.data) || is_whirly(youmonst.data)
832.             || unsolid(youmonst.data) || (youmonst.data->msize <= MZ_SMALL
833.                                           && u.utraptype == TT_BEARTRAP))) {
834.         You("are no longer stuck in the %s.",
835.             u.utraptype == TT_WEB ? "web" : "bear trap");
836.         /* probably should burn webs too if PM_FIRE_ELEMENTAL */
837.         reset_utrap(TRUE);
838.     }
839.     if (webmaker(youmonst.data) && u.utrap && u.utraptype == TT_WEB) {
840.         You("orient yourself on the web.");
841.         reset_utrap(TRUE);
842.     }
843.     check_strangling(TRUE); /* maybe start strangling */
844. 
845.     context.botl = 1;
846.     vision_full_recalc = 1;
847.     see_monsters();
848.     (void) encumber_msg();
849. 
850.     retouch_equipment(2);
851.     /* this might trigger a recursive call to polymon() [stone golem
852.        wielding cockatrice corpse and hit by stone-to-flesh, becomes
853.        flesh golem above, now gets transformed back into stone golem] */
854.     if (!uarmg)
855.         selftouch(no_longer_petrify_resistant);
856.     return 1;
857. }
858. 
859. STATIC_OVL void
860. break_armor()
861. {
862.     register struct obj *otmp;
863. 
864.     if (breakarm(youmonst.data)) {
865.         if ((otmp = uarm) != 0) {
866.             if (donning(otmp))
867.                 cancel_don();
868.             You("break out of your armor!");
869.             exercise(A_STR, FALSE);
870.             (void) Armor_gone();
871.             useup(otmp);
872.         }
873.         if ((otmp = uarmc) != 0) {
874.             if (otmp->oartifact) {
875.                 Your("%s falls off!", cloak_simple_name(otmp));
876.                 (void) Cloak_off();
877.                 dropx(otmp);
878.             } else {
879.                 Your("%s tears apart!", cloak_simple_name(otmp));
880.                 (void) Cloak_off();
881.                 useup(otmp);
882.             }
883.         }
884.         if (uarmu) {
885.             Your("shirt rips to shreds!");
886.             useup(uarmu);
887.         }
888.     } else if (sliparm(youmonst.data)) {
889.         if (((otmp = uarm) != 0) && (racial_exception(&youmonst, otmp) < 1)) {
890.             if (donning(otmp))
891.                 cancel_don();
892.             Your("armor falls around you!");
893.             (void) Armor_gone();
894.             dropx(otmp);
895.         }
896.         if ((otmp = uarmc) != 0) {
897.             if (is_whirly(youmonst.data))
898.                 Your("%s falls, unsupported!", cloak_simple_name(otmp));
899.             else
900.                 You("shrink out of your %s!", cloak_simple_name(otmp));
901.             (void) Cloak_off();
902.             dropx(otmp);
903.         }
904.         if ((otmp = uarmu) != 0) {
905.             if (is_whirly(youmonst.data))
906.                 You("seep right through your shirt!");
907.             else
908.                 You("become much too small for your shirt!");
909.             setworn((struct obj *) 0, otmp->owornmask & W_ARMU);
910.             dropx(otmp);
911.         }
912.     }
913.     if (has_horns(youmonst.data)) {
914.         if ((otmp = uarmh) != 0) {
915.             if (is_flimsy(otmp) && !donning(otmp)) {
916.                 char hornbuf[BUFSZ];
917. 
918.                 /* Future possibilities: This could damage/destroy helmet */
919.                 Sprintf(hornbuf, "horn%s", plur(num_horns(youmonst.data)));
920.                 Your("%s %s through %s.", hornbuf, vtense(hornbuf, "pierce"),
921.                      yname(otmp));
922.             } else {
923.                 if (donning(otmp))
924.                     cancel_don();
925.                 Your("%s falls to the %s!", helm_simple_name(otmp),
926.                      surface(u.ux, u.uy));
927.                 (void) Helmet_off();
928.                 dropx(otmp);
929.             }
930.         }
931.     }
932.     if (nohands(youmonst.data) || verysmall(youmonst.data)) {
933.         if ((otmp = uarmg) != 0) {
934.             if (donning(otmp))
935.                 cancel_don();
936.             /* Drop weapon along with gloves */
937.             You("drop your gloves%s!", uwep ? " and weapon" : "");
938.             drop_weapon(0);
939.             (void) Gloves_off();
940.             dropx(otmp);
941.         }
942.         if ((otmp = uarms) != 0) {
943.             You("can no longer hold your shield!");
944.             (void) Shield_off();
945.             dropx(otmp);
946.         }
947.         if ((otmp = uarmh) != 0) {
948.             if (donning(otmp))
949.                 cancel_don();
950.             Your("%s falls to the %s!", helm_simple_name(otmp),
951.                  surface(u.ux, u.uy));
952.             (void) Helmet_off();
953.             dropx(otmp);
954.         }
955.     }
956.     if (nohands(youmonst.data) || verysmall(youmonst.data)
957.         || slithy(youmonst.data) || youmonst.data->mlet == S_CENTAUR) {
958.         if ((otmp = uarmf) != 0) {
959.             if (donning(otmp))
960.                 cancel_don();
961.             if (is_whirly(youmonst.data))
962.                 Your("boots fall away!");
963.             else
964.                 Your("boots %s off your feet!",
965.                      verysmall(youmonst.data) ? "slide" : "are pushed");
966.             (void) Boots_off();
967.             dropx(otmp);
968.         }
969.     }
970. }
971. 
972. STATIC_OVL void
973. drop_weapon(alone)
974. int alone;
975. {
976.     struct obj *otmp;
977.     const char *what, *which, *whichtoo;
978.     boolean candropwep, candropswapwep, updateinv = TRUE;
979. 
980.     if (uwep) {
981.         /* !alone check below is currently superfluous but in the
982.          * future it might not be so if there are monsters which cannot
983.          * wear gloves but can wield weapons
984.          */
985.         if (!alone || cantwield(youmonst.data)) {
986.             candropwep = canletgo(uwep, "");
987.             candropswapwep = !u.twoweap || canletgo(uswapwep, "");
988.             if (alone) {
989.                 what = (candropwep && candropswapwep) ? "drop" : "release";
990.                 which = is_sword(uwep) ? "sword" : weapon_descr(uwep);
991.                 if (u.twoweap) {
992.                     whichtoo =
993.                         is_sword(uswapwep) ? "sword" : weapon_descr(uswapwep);
994.                     if (strcmp(which, whichtoo))
995.                         which = "weapon";
996.                 }
997.                 if (uwep->quan != 1L || u.twoweap)
998.                     which = makeplural(which);
999. 
1000.                 You("find you must %s %s %s!", what,
1001.                     the_your[!!strncmp(which, "corpse", 6)], which);
1002.             }
1003.             /* if either uwep or wielded uswapwep is flagged as 'in_use'
1004.                then don't drop it or explicitly update inventory; leave
1005.                those actions to caller (or caller's caller, &c) */
1006.             if (u.twoweap) {
1007.                 otmp = uswapwep;
1008.                 uswapwepgone();
1009.                 if (otmp->in_use)
1010.                     updateinv = FALSE;
1011.                 else if (candropswapwep)
1012.                     dropx(otmp);
1013.             }
1014.             otmp = uwep;
1015.             uwepgone();
1016.             if (otmp->in_use)
1017.                 updateinv = FALSE;
1018.             else if (candropwep)
1019.                 dropx(otmp);
1020. 
1021.             if (updateinv)
1022.                 update_inventory();
1023.         } else if (!could_twoweap(youmonst.data)) {
1024.             untwoweapon();
1025.         }
1026.     }
1027. }
1028. 
1029. void
1030. rehumanize()
1031. {
1032.     boolean was_flying = (Flying != 0);
1033. 
1034.     /* You can't revert back while unchanging */
1035.     if (Unchanging) {
1036.         if (u.mh < 1) {
1037.             killer.format = NO_KILLER_PREFIX;
1038.             Strcpy(killer.name, "killed while stuck in creature form");
1039.             done(DIED);
1040.         } else if (uamul && uamul->otyp == AMULET_OF_UNCHANGING) {
1041.             Your("%s %s!", simpleonames(uamul), otense(uamul, "fail"));
1042.             uamul->dknown = 1;
1043.             makeknown(AMULET_OF_UNCHANGING);
1044.         }
1045.     }
1046. 
1047.     if (emits_light(youmonst.data))
1048.         del_light_source(LS_MONSTER, monst_to_any(&youmonst));
1049.     polyman("return to %s form!", urace.adj);
1050. 
1051.     if (u.uhp < 1) {
1052.         /* can only happen if some bit of code reduces u.uhp
1053.            instead of u.mh while poly'd */
1054.         Your("old form was not healthy enough to survive.");
1055.         Sprintf(killer.name, "reverting to unhealthy %s form", urace.adj);
1056.         killer.format = KILLED_BY;
1057.         done(DIED);
1058.     }
1059.     nomul(0);
1060. 
1061.     context.botl = 1;
1062.     vision_full_recalc = 1;
1063.     (void) encumber_msg();
1064.     if (was_flying && !Flying && u.usteed)
1065.         You("and %s return gently to the %s.",
1066.             mon_nam(u.usteed), surface(u.ux, u.uy));
1067.     retouch_equipment(2);
1068.     if (!uarmg)
1069.         selftouch(no_longer_petrify_resistant);
1070. }
1071. 
1072. int
1073. dobreathe()
1074. {
1075.     struct attack *mattk;
1076. 
1077.     if (Strangled) {
1078.         You_cant("breathe.  Sorry.");
1079.         return 0;
1080.     }
1081.     if (u.uen < 15) {
1082.         You("don't have enough energy to breathe!");
1083.         return 0;
1084.     }
1085.     u.uen -= 15;
1086.     context.botl = 1;
1087. 
1088.     if (!getdir((char *) 0))
1089.         return 0;
1090. 
1091.     mattk = attacktype_fordmg(youmonst.data, AT_BREA, AD_ANY);
1092.     if (!mattk)
1093.         impossible("bad breath attack?"); /* mouthwash needed... */
1094.     else if (!u.dx && !u.dy && !u.dz)
1095.         ubreatheu(mattk);
1096.     else
1097.         buzz((int) (20 + mattk->adtyp - 1), (int) mattk->damn, u.ux, u.uy,
1098.              u.dx, u.dy);
1099.     return 1;
1100. }
1101. 
1102. int
1103. dospit()
1104. {
1105.     struct obj *otmp;
1106.     struct attack *mattk;
1107. 
1108.     if (!getdir((char *) 0))
1109.         return 0;
1110.     mattk = attacktype_fordmg(youmonst.data, AT_SPIT, AD_ANY);
1111.     if (!mattk) {
1112.         impossible("bad spit attack?");
1113.     } else {
1114.         switch (mattk->adtyp) {
1115.         case AD_BLND:
1116.         case AD_DRST:
1117.             otmp = mksobj(BLINDING_VENOM, TRUE, FALSE);
1118.             break;
1119.         default:
1120.             impossible("bad attack type in dospit");
1121.             /*FALLTHRU*/
1122.         case AD_ACID:
1123.             otmp = mksobj(ACID_VENOM, TRUE, FALSE);
1124.             break;
1125.         }
1126.         otmp->spe = 1; /* to indicate it's yours */
1127.         throwit(otmp, 0L, FALSE);
1128.     }
1129.     return 1;
1130. }
1131. 
1132. int
1133. doremove()
1134. {
1135.     if (!Punished) {
1136.         if (u.utrap && u.utraptype == TT_BURIEDBALL) {
1137.             pline_The("ball and chain are buried firmly in the %s.",
1138.                       surface(u.ux, u.uy));
1139.             return 0;
1140.         }
1141.         You("are not chained to anything!");
1142.         return 0;
1143.     }
1144.     unpunish();
1145.     return 1;
1146. }
1147. 
1148. int
1149. dospinweb()
1150. {
1151.     register struct trap *ttmp = t_at(u.ux, u.uy);
1152. 
1153.     if (Levitation || Is_airlevel(&u.uz) || Underwater
1154.         || Is_waterlevel(&u.uz)) {
1155.         You("must be on the ground to spin a web.");
1156.         return 0;
1157.     }
1158.     if (u.uswallow) {
1159.         You("release web fluid inside %s.", mon_nam(u.ustuck));
1160.         if (is_animal(u.ustuck->data)) {
1161.             expels(u.ustuck, u.ustuck->data, TRUE);
1162.             return 0;
1163.         }
1164.         if (is_whirly(u.ustuck->data)) {
1165.             int i;
1166. 
1167.             for (i = 0; i < NATTK; i++)
1168.                 if (u.ustuck->data->mattk[i].aatyp == AT_ENGL)
1169.                     break;
1170.             if (i == NATTK)
1171.                 impossible("Swallower has no engulfing attack?");
1172.             else {
1173.                 char sweep[30];
1174. 
1175.                 sweep[0] = '\0';
1176.                 switch (u.ustuck->data->mattk[i].adtyp) {
1177.                 case AD_FIRE:
1178.                     Strcpy(sweep, "ignites and ");
1179.                     break;
1180.                 case AD_ELEC:
1181.                     Strcpy(sweep, "fries and ");
1182.                     break;
1183.                 case AD_COLD:
1184.                     Strcpy(sweep, "freezes, shatters and ");
1185.                     break;
1186.                 }
1187.                 pline_The("web %sis swept away!", sweep);
1188.             }
1189.             return 0;
1190.         } /* default: a nasty jelly-like creature */
1191.         pline_The("web dissolves into %s.", mon_nam(u.ustuck));
1192.         return 0;
1193.     }
1194.     if (u.utrap) {
1195.         You("cannot spin webs while stuck in a trap.");
1196.         return 0;
1197.     }
1198.     exercise(A_DEX, TRUE);
1199.     if (ttmp) {
1200.         switch (ttmp->ttyp) {
1201.         case PIT:
1202.         case SPIKED_PIT:
1203.             You("spin a web, covering up the pit.");
1204.             deltrap(ttmp);
1205.             bury_objs(u.ux, u.uy);
1206.             newsym(u.ux, u.uy);
1207.             return 1;
1208.         case SQKY_BOARD:
1209.             pline_The("squeaky board is muffled.");
1210.             deltrap(ttmp);
1211.             newsym(u.ux, u.uy);
1212.             return 1;
1213.         case TELEP_TRAP:
1214.         case LEVEL_TELEP:
1215.         case MAGIC_PORTAL:
1216.         case VIBRATING_SQUARE:
1217.             Your("webbing vanishes!");
1218.             return 0;
1219.         case WEB:
1220.             You("make the web thicker.");
1221.             return 1;
1222.         case HOLE:
1223.         case TRAPDOOR:
1224.             You("web over the %s.",
1225.                 (ttmp->ttyp == TRAPDOOR) ? "trap door" : "hole");
1226.             deltrap(ttmp);
1227.             newsym(u.ux, u.uy);
1228.             return 1;
1229.         case ROLLING_BOULDER_TRAP:
1230.             You("spin a web, jamming the trigger.");
1231.             deltrap(ttmp);
1232.             newsym(u.ux, u.uy);
1233.             return 1;
1234.         case ARROW_TRAP:
1235.         case DART_TRAP:
1236.         case BEAR_TRAP:
1237.         case ROCKTRAP:
1238.         case FIRE_TRAP:
1239.         case LANDMINE:
1240.         case SLP_GAS_TRAP:
1241.         case RUST_TRAP:
1242.         case MAGIC_TRAP:
1243.         case ANTI_MAGIC:
1244.         case POLY_TRAP:
1245.             You("have triggered a trap!");
1246.             dotrap(ttmp, 0);
1247.             return 1;
1248.         default:
1249.             impossible("Webbing over trap type %d?", ttmp->ttyp);
1250.             return 0;
1251.         }
1252.     } else if (On_stairs(u.ux, u.uy)) {
1253.         /* cop out: don't let them hide the stairs */
1254.         Your("web fails to impede access to the %s.",
1255.              (levl[u.ux][u.uy].typ == STAIRS) ? "stairs" : "ladder");
1256.         return 1;
1257.     }
1258.     ttmp = maketrap(u.ux, u.uy, WEB);
1259.     if (ttmp) {
1260.         ttmp->madeby_u = 1;
1261.         feeltrap(ttmp);
1262.     }
1263.     return 1;
1264. }
1265. 
1266. int
1267. dosummon()
1268. {
1269.     int placeholder;
1270.     if (u.uen < 10) {
1271.         You("lack the energy to send forth a call for help!");
1272.         return 0;
1273.     }
1274.     u.uen -= 10;
1275.     context.botl = 1;
1276. 
1277.     You("call upon your brethren for help!");
1278.     exercise(A_WIS, TRUE);
1279.     if (!were_summon(youmonst.data, TRUE, &placeholder, (char *) 0))
1280.         pline("But none arrive.");
1281.     return 1;
1282. }
1283. 
1284. int
1285. dogaze()
1286. {
1287.     register struct monst *mtmp;
1288.     int looked = 0;
1289.     char qbuf[QBUFSZ];
1290.     int i;
1291.     uchar adtyp = 0;
1292. 
1293.     for (i = 0; i < NATTK; i++) {
1294.         if (youmonst.data->mattk[i].aatyp == AT_GAZE) {
1295.             adtyp = youmonst.data->mattk[i].adtyp;
1296.             break;
1297.         }
1298.     }
1299.     if (adtyp != AD_CONF && adtyp != AD_FIRE) {
1300.         impossible("gaze attack %d?", adtyp);
1301.         return 0;
1302.     }
1303. 
1304.     if (Blind) {
1305.         You_cant("see anything to gaze at.");
1306.         return 0;
1307.     } else if (Hallucination) {
1308.         You_cant("gaze at anything you can see.");
1309.         return 0;
1310.     }
1311.     if (u.uen < 15) {
1312.         You("lack the energy to use your special gaze!");
1313.         return 0;
1314.     }
1315.     u.uen -= 15;
1316.     context.botl = 1;
1317. 
1318.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
1319.         if (DEADMONSTER(mtmp))
1320.             continue;
1321.         if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) {
1322.             looked++;
1323.             if (Invis && !perceives(mtmp->data)) {
1324.                 pline("%s seems not to notice your gaze.", Monnam(mtmp));
1325.             } else if (mtmp->minvis && !See_invisible) {
1326.                 You_cant("see where to gaze at %s.", Monnam(mtmp));
1327.             } else if (M_AP_TYPE(mtmp) == M_AP_FURNITURE
1328.                        || M_AP_TYPE(mtmp) == M_AP_OBJECT) {
1329.                 looked--;
1330.                 continue;
1331.             } else if (flags.safe_dog && mtmp->mtame && !Confusion) {
1332.                 You("avoid gazing at %s.", y_monnam(mtmp));
1333.             } else {
1334.                 if (flags.confirm && mtmp->mpeaceful && !Confusion) {
1335.                     Sprintf(qbuf, "Really %s %s?",
1336.                             (adtyp == AD_CONF) ? "confuse" : "attack",
1337.                             mon_nam(mtmp));
1338.                     if (yn(qbuf) != 'y')
1339.                         continue;
1340.                 }
1341.                 setmangry(mtmp, TRUE);
1342.                 if (!mtmp->mcanmove || mtmp->mstun || mtmp->msleeping
1343.                     || !mtmp->mcansee || !haseyes(mtmp->data)) {
1344.                     looked--;
1345.                     continue;
1346.                 }
1347.                 /* No reflection check for consistency with when a monster
1348.                  * gazes at *you*--only medusa gaze gets reflected then.
1349.                  */
1350.                 if (adtyp == AD_CONF) {
1351.                     if (!mtmp->mconf)
1352.                         Your("gaze confuses %s!", mon_nam(mtmp));
1353.                     else
1354.                         pline("%s is getting more and more confused.",
1355.                               Monnam(mtmp));
1356.                     mtmp->mconf = 1;
1357.                 } else if (adtyp == AD_FIRE) {
1358.                     int dmg = d(2, 6), lev = (int) u.ulevel;
1359. 
1360.                     You("attack %s with a fiery gaze!", mon_nam(mtmp));
1361.                     if (resists_fire(mtmp)) {
1362.                         pline_The("fire doesn't burn %s!", mon_nam(mtmp));
1363.                         dmg = 0;
1364.                     }
1365.                     if (lev > rn2(20))
1366.                         (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
1367.                     if (lev > rn2(20))
1368.                         (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
1369.                     if (lev > rn2(25))
1370.                         (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
1371.                     if (dmg)
1372.                         mtmp->mhp -= dmg;
1373.                     if (DEADMONSTER(mtmp))
1374.                         killed(mtmp);
1375.                 }
1376.                 /* For consistency with passive() in uhitm.c, this only
1377.                  * affects you if the monster is still alive.
1378.                  */
1379.                 if (DEADMONSTER(mtmp))
1380.                     continue;
1381. 
1382.                 if (mtmp->data == &mons[PM_FLOATING_EYE] && !mtmp->mcan) {
1383.                     if (!Free_action) {
1384.                         You("are frozen by %s gaze!",
1385.                             s_suffix(mon_nam(mtmp)));
1386.                         nomul((u.ulevel > 6 || rn2(4))
1387.                                   ? -d((int) mtmp->m_lev + 1,
1388.                                        (int) mtmp->data->mattk[0].damd)
1389.                                   : -200);
1390.                         multi_reason = "frozen by a monster's gaze";
1391.                         nomovemsg = 0;
1392.                         return 1;
1393.                     } else
1394.                         You("stiffen momentarily under %s gaze.",
1395.                             s_suffix(mon_nam(mtmp)));
1396.                 }
1397.                 /* Technically this one shouldn't affect you at all because
1398.                  * the Medusa gaze is an active monster attack that only
1399.                  * works on the monster's turn, but for it to *not* have an
1400.                  * effect would be too weird.
1401.                  */
1402.                 if (mtmp->data == &mons[PM_MEDUSA] && !mtmp->mcan) {
1403.                     pline("Gazing at the awake %s is not a very good idea.",
1404.                           l_monnam(mtmp));
1405.                     /* as if gazing at a sleeping anything is fruitful... */
1406.                     You("turn to stone...");
1407.                     killer.format = KILLED_BY;
1408.                     Strcpy(killer.name, "deliberately meeting Medusa's gaze");
1409.                     done(STONING);
1410.                 }
1411.             }
1412.         }
1413.     }
1414.     if (!looked)
1415.         You("gaze at no place in particular.");
1416.     return 1;
1417. }
1418. 
1419. int
1420. dohide()
1421. {
1422.     boolean ismimic = youmonst.data->mlet == S_MIMIC,
1423.             on_ceiling = is_clinger(youmonst.data) || Flying;
1424. 
1425.     /* can't hide while being held (or holding) or while trapped
1426.        (except for floor hiders [trapper or mimic] in pits) */
1427.     if (u.ustuck || (u.utrap && (u.utraptype != TT_PIT || on_ceiling))) {
1428.         You_cant("hide while you're %s.",
1429.                  !u.ustuck ? "trapped"
1430.                    : u.uswallow ? (is_animal(u.ustuck->data) ? "swallowed"
1431.                                                              : "engulfed")
1432.                      : !sticks(youmonst.data) ? "being held"
1433.                        : (humanoid(u.ustuck->data) ? "holding someone"
1434.                                                    : "holding that creature"));
1435.         if (u.uundetected
1436.             || (ismimic && U_AP_TYPE != M_AP_NOTHING)) {
1437.             u.uundetected = 0;
1438.             youmonst.m_ap_type = M_AP_NOTHING;
1439.             newsym(u.ux, u.uy);
1440.         }
1441.         return 0;
1442.     }
1443.     /* note: the eel and hides_under cases are hypothetical;
1444.        such critters aren't offered the option of hiding via #monster */
1445.     if (youmonst.data->mlet == S_EEL && !is_pool(u.ux, u.uy)) {
1446.         if (IS_FOUNTAIN(levl[u.ux][u.uy].typ))
1447.             The("fountain is not deep enough to hide in.");
1448.         else
1449.             There("is no %s to hide in here.", hliquid("water"));
1450.         u.uundetected = 0;
1451.         return 0;
1452.     }
1453.     if (hides_under(youmonst.data) && !level.objects[u.ux][u.uy]) {
1454.         There("is nothing to hide under here.");
1455.         u.uundetected = 0;
1456.         return 0;
1457.     }
1458.     /* Planes of Air and Water */
1459.     if (on_ceiling && !has_ceiling(&u.uz)) {
1460.         There("is nowhere to hide above you.");
1461.         u.uundetected = 0;
1462.         return 0;
1463.     }
1464.     if ((is_hider(youmonst.data) && !Flying) /* floor hider */
1465.         && (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))) {
1466.         There("is nowhere to hide beneath you.");
1467.         u.uundetected = 0;
1468.         return 0;
1469.     }
1470.     /* TODO? inhibit floor hiding at furniture locations, or
1471.      * else make youhiding() give smarter messages at such spots.
1472.      */
1473. 
1474.     if (u.uundetected || (ismimic && U_AP_TYPE != M_AP_NOTHING)) {
1475.         youhiding(FALSE, 1); /* "you are already hiding" */
1476.         return 0;
1477.     }
1478. 
1479.     if (ismimic) {
1480.         /* should bring up a dialog "what would you like to imitate?" */
1481.         youmonst.m_ap_type = M_AP_OBJECT;
1482.         youmonst.mappearance = STRANGE_OBJECT;
1483.     } else
1484.         u.uundetected = 1;
1485.     newsym(u.ux, u.uy);
1486.     youhiding(FALSE, 0); /* "you are now hiding" */
1487.     return 1;
1488. }
1489. 
1490. int
1491. dopoly()
1492. {
1493.     struct permonst *savedat = youmonst.data;
1494. 
1495.     if (is_vampire(youmonst.data)) {
1496.         polyself(2);
1497.         if (savedat != youmonst.data) {
1498.             You("transform into %s.", an(youmonst.data->mname));
1499.             newsym(u.ux, u.uy);
1500.         }
1501.     }
1502.     return 1;
1503. }
1504. 
1505. int
1506. domindblast()
1507. {
1508.     struct monst *mtmp, *nmon;
1509. 
1510.     if (u.uen < 10) {
1511.         You("concentrate but lack the energy to maintain doing so.");
1512.         return 0;
1513.     }
1514.     u.uen -= 10;
1515.     context.botl = 1;
1516. 
1517.     You("concentrate.");
1518.     pline("A wave of psychic energy pours out.");
1519.     for (mtmp = fmon; mtmp; mtmp = nmon) {
1520.         int u_sen;
1521. 
1522.         nmon = mtmp->nmon;
1523.         if (DEADMONSTER(mtmp))
1524.             continue;
1525.         if (distu(mtmp->mx, mtmp->my) > BOLT_LIM * BOLT_LIM)
1526.             continue;
1527.         if (mtmp->mpeaceful)
1528.             continue;
1529.         u_sen = telepathic(mtmp->data) && !mtmp->mcansee;
1530.         if (u_sen || (telepathic(mtmp->data) && rn2(2)) || !rn2(10)) {
1531.             You("lock in on %s %s.", s_suffix(mon_nam(mtmp)),
1532.                 u_sen ? "telepathy"
1533.                       : telepathic(mtmp->data) ? "latent telepathy" : "mind");
1534.             mtmp->mhp -= rnd(15);
1535.             if (DEADMONSTER(mtmp))
1536.                 killed(mtmp);
1537.         }
1538.     }
1539.     return 1;
1540. }
1541. 
1542. void
1543. uunstick()
1544. {
1545.     if (!u.ustuck) {
1546.         impossible("uunstick: no ustuck?");
1547.         return;
1548.     }
1549.     pline("%s is no longer in your clutches.", Monnam(u.ustuck));
1550.     u.ustuck = 0;
1551. }
1552. 
1553. void
1554. skinback(silently)
1555. boolean silently;
1556. {
1557.     if (uskin) {
1558.         if (!silently)
1559.             Your("skin returns to its original form.");
1560.         uarm = uskin;
1561.         uskin = (struct obj *) 0;
1562.         /* undo save/restore hack */
1563.         uarm->owornmask &= ~I_SPECIAL;
1564.     }
1565. }
1566. 
1567. const char *
1568. mbodypart(mon, part)
1569. struct monst *mon;
1570. int part;
1571. {
1572.     static NEARDATA const char
1573.         *humanoid_parts[] = { "arm",       "eye",  "face",         "finger",
1574.                               "fingertip", "foot", "hand",         "handed",
1575.                               "head",      "leg",  "light headed", "neck",
1576.                               "spine",     "toe",  "hair",         "blood",
1577.                               "lung",      "nose", "stomach" },
1578.         *jelly_parts[] = { "pseudopod", "dark spot", "front",
1579.                            "pseudopod extension", "pseudopod extremity",
1580.                            "pseudopod root", "grasp", "grasped",
1581.                            "cerebral area", "lower pseudopod", "viscous",
1582.                            "middle", "surface", "pseudopod extremity",
1583.                            "ripples", "juices", "surface", "sensor",
1584.                            "stomach" },
1585.         *animal_parts[] = { "forelimb",  "eye",           "face",
1586.                             "foreclaw",  "claw tip",      "rear claw",
1587.                             "foreclaw",  "clawed",        "head",
1588.                             "rear limb", "light headed",  "neck",
1589.                             "spine",     "rear claw tip", "fur",
1590.                             "blood",     "lung",          "nose",
1591.                             "stomach" },
1592.         *bird_parts[] = { "wing",     "eye",  "face",         "wing",
1593.                           "wing tip", "foot", "wing",         "winged",
1594.                           "head",     "leg",  "light headed", "neck",
1595.                           "spine",    "toe",  "feathers",     "blood",
1596.                           "lung",     "bill", "stomach" },
1597.         *horse_parts[] = { "foreleg",  "eye",           "face",
1598.                            "forehoof", "hoof tip",      "rear hoof",
1599.                            "forehoof", "hooved",        "head",
1600.                            "rear leg", "light headed",  "neck",
1601.                            "backbone", "rear hoof tip", "mane",
1602.                            "blood",    "lung",          "nose",
1603.                            "stomach" },
1604.         *sphere_parts[] = { "appendage", "optic nerve", "body", "tentacle",
1605.                             "tentacle tip", "lower appendage", "tentacle",
1606.                             "tentacled", "body", "lower tentacle",
1607.                             "rotational", "equator", "body",
1608.                             "lower tentacle tip", "cilia", "life force",
1609.                             "retina", "olfactory nerve", "interior" },
1610.         *fungus_parts[] = { "mycelium", "visual area", "front",
1611.                             "hypha",    "hypha",       "root",
1612.                             "strand",   "stranded",    "cap area",
1613.                             "rhizome",  "sporulated",  "stalk",
1614.                             "root",     "rhizome tip", "spores",
1615.                             "juices",   "gill",        "gill",
1616.                             "interior" },
1617.         *vortex_parts[] = { "region",        "eye",           "front",
1618.                             "minor current", "minor current", "lower current",
1619.                             "swirl",         "swirled",       "central core",
1620.                             "lower current", "addled",        "center",
1621.                             "currents",      "edge",          "currents",
1622.                             "life force",    "center",        "leading edge",
1623.                             "interior" },
1624.         *snake_parts[] = { "vestigial limb", "eye", "face", "large scale",
1625.                            "large scale tip", "rear region", "scale gap",
1626.                            "scale gapped", "head", "rear region",
1627.                            "light headed", "neck", "length", "rear scale",
1628.                            "scales", "blood", "lung", "forked tongue",
1629.                            "stomach" },
1630.         *worm_parts[] = { "anterior segment", "light sensitive cell",
1631.                           "clitellum", "setae", "setae", "posterior segment",
1632.                           "segment", "segmented", "anterior segment",
1633.                           "posterior", "over stretched", "clitellum",
1634.                           "length", "posterior setae", "setae", "blood",
1635.                           "skin", "prostomium", "stomach" },
1636.         *fish_parts[] = { "fin", "eye", "premaxillary", "pelvic axillary",
1637.                           "pelvic fin", "anal fin", "pectoral fin", "finned",
1638.                           "head", "peduncle", "played out", "gills",
1639.                           "dorsal fin", "caudal fin", "scales", "blood",
1640.                           "gill", "nostril", "stomach" };
1641.     /* claw attacks are overloaded in mons[]; most humanoids with
1642.        such attacks should still reference hands rather than claws */
1643.     static const char not_claws[] = {
1644.         S_HUMAN,     S_MUMMY,   S_ZOMBIE, S_ANGEL, S_NYMPH, S_LEPRECHAUN,
1645.         S_QUANTMECH, S_VAMPIRE, S_ORC,    S_GIANT, /* quest nemeses */
1646.         '\0' /* string terminator; assert( S_xxx != 0 ); */
1647.     };
1648.     struct permonst *mptr = mon->data;
1649. 
1650.     /* some special cases */
1651.     if (mptr->mlet == S_DOG || mptr->mlet == S_FELINE
1652.         || mptr->mlet == S_RODENT || mptr == &mons[PM_OWLBEAR]) {
1653.         switch (part) {
1654.         case HAND:
1655.             return "paw";
1656.         case HANDED:
1657.             return "pawed";
1658.         case FOOT:
1659.             return "rear paw";
1660.         case ARM:
1661.         case LEG:
1662.             return horse_parts[part]; /* "foreleg", "rear leg" */
1663.         default:
1664.             break; /* for other parts, use animal_parts[] below */
1665.         }
1666.     } else if (mptr->mlet == S_YETI) { /* excl. owlbear due to 'if' above */
1667.         /* opposable thumbs, hence "hands", "arms", "legs", &c */
1668.         return humanoid_parts[part]; /* yeti/sasquatch, monkey/ape */
1669.     }
1670.     if ((part == HAND || part == HANDED)
1671.         && (humanoid(mptr) && attacktype(mptr, AT_CLAW)
1672.             && !index(not_claws, mptr->mlet) && mptr != &mons[PM_STONE_GOLEM]
1673.             && mptr != &mons[PM_INCUBUS] && mptr != &mons[PM_SUCCUBUS]))
1674.         return (part == HAND) ? "claw" : "clawed";
1675.     if ((mptr == &mons[PM_MUMAK] || mptr == &mons[PM_MASTODON])
1676.         && part == NOSE)
1677.         return "trunk";
1678.     if (mptr == &mons[PM_SHARK] && part == HAIR)
1679.         return "skin"; /* sharks don't have scales */
1680.     if ((mptr == &mons[PM_JELLYFISH] || mptr == &mons[PM_KRAKEN])
1681.         && (part == ARM || part == FINGER || part == HAND || part == FOOT
1682.             || part == TOE))
1683.         return "tentacle";
1684.     if (mptr == &mons[PM_FLOATING_EYE] && part == EYE)
1685.         return "cornea";
1686.     if (humanoid(mptr) && (part == ARM || part == FINGER || part == FINGERTIP
1687.                            || part == HAND || part == HANDED))
1688.         return humanoid_parts[part];
1689.     if (mptr == &mons[PM_RAVEN])
1690.         return bird_parts[part];
1691.     if (mptr->mlet == S_CENTAUR || mptr->mlet == S_UNICORN
1692.         || (mptr == &mons[PM_ROTHE] && part != HAIR))
1693.         return horse_parts[part];
1694.     if (mptr->mlet == S_LIGHT) {
1695.         if (part == HANDED)
1696.             return "rayed";
1697.         else if (part == ARM || part == FINGER || part == FINGERTIP
1698.                  || part == HAND)
1699.             return "ray";
1700.         else
1701.             return "beam";
1702.     }
1703.     if (mptr == &mons[PM_STALKER] && part == HEAD)
1704.         return "head";
1705.     if (mptr->mlet == S_EEL && mptr != &mons[PM_JELLYFISH])
1706.         return fish_parts[part];
1707.     if (mptr->mlet == S_WORM)
1708.         return worm_parts[part];
1709.     if (slithy(mptr) || (mptr->mlet == S_DRAGON && part == HAIR))
1710.         return snake_parts[part];
1711.     if (mptr->mlet == S_EYE)
1712.         return sphere_parts[part];
1713.     if (mptr->mlet == S_JELLY || mptr->mlet == S_PUDDING
1714.         || mptr->mlet == S_BLOB || mptr == &mons[PM_JELLYFISH])
1715.         return jelly_parts[part];
1716.     if (mptr->mlet == S_VORTEX || mptr->mlet == S_ELEMENTAL)
1717.         return vortex_parts[part];
1718.     if (mptr->mlet == S_FUNGUS)
1719.         return fungus_parts[part];
1720.     if (humanoid(mptr))
1721.         return humanoid_parts[part];
1722.     return animal_parts[part];
1723. }
1724. 
1725. const char *
1726. body_part(part)
1727. int part;
1728. {
1729.     return mbodypart(&youmonst, part);
1730. }
1731. 
1732. int
1733. poly_gender()
1734. {
1735.     /* Returns gender of polymorphed player;
1736.      * 0/1=same meaning as flags.female, 2=none.
1737.      */
1738.     if (is_neuter(youmonst.data) || !humanoid(youmonst.data))
1739.         return 2;
1740.     return flags.female;
1741. }
1742. 
1743. void
1744. ugolemeffects(damtype, dam)
1745. int damtype, dam;
1746. {
1747.     int heal = 0;
1748. 
1749.     /* We won't bother with "slow"/"haste" since players do not
1750.      * have a monster-specific slow/haste so there is no way to
1751.      * restore the old velocity once they are back to human.
1752.      */
1753.     if (u.umonnum != PM_FLESH_GOLEM && u.umonnum != PM_IRON_GOLEM)
1754.         return;
1755.     switch (damtype) {
1756.     case AD_ELEC:
1757.         if (u.umonnum == PM_FLESH_GOLEM)
1758.             heal = (dam + 5) / 6; /* Approx 1 per die */
1759.         break;
1760.     case AD_FIRE:
1761.         if (u.umonnum == PM_IRON_GOLEM)
1762.             heal = dam;
1763.         break;
1764.     }
1765.     if (heal && (u.mh < u.mhmax)) {
1766.         u.mh += heal;
1767.         if (u.mh > u.mhmax)
1768.             u.mh = u.mhmax;
1769.         context.botl = 1;
1770.         pline("Strangely, you feel better than before.");
1771.         exercise(A_STR, TRUE);
1772.     }
1773. }
1774. 
1775. STATIC_OVL int
1776. armor_to_dragon(atyp)
1777. int atyp;
1778. {
1779.     switch (atyp) {
1780.     case GRAY_DRAGON_SCALE_MAIL:
1781.     case GRAY_DRAGON_SCALES:
1782.         return PM_GRAY_DRAGON;
1783.     case SILVER_DRAGON_SCALE_MAIL:
1784.     case SILVER_DRAGON_SCALES:
1785.         return PM_SILVER_DRAGON;
1786. #if 0 /* DEFERRED */
1787.     case SHIMMERING_DRAGON_SCALE_MAIL:
1788.     case SHIMMERING_DRAGON_SCALES:
1789.         return PM_SHIMMERING_DRAGON;
1790. #endif
1791.     case RED_DRAGON_SCALE_MAIL:
1792.     case RED_DRAGON_SCALES:
1793.         return PM_RED_DRAGON;
1794.     case ORANGE_DRAGON_SCALE_MAIL:
1795.     case ORANGE_DRAGON_SCALES:
1796.         return PM_ORANGE_DRAGON;
1797.     case WHITE_DRAGON_SCALE_MAIL:
1798.     case WHITE_DRAGON_SCALES:
1799.         return PM_WHITE_DRAGON;
1800.     case BLACK_DRAGON_SCALE_MAIL:
1801.     case BLACK_DRAGON_SCALES:
1802.         return PM_BLACK_DRAGON;
1803.     case BLUE_DRAGON_SCALE_MAIL:
1804.     case BLUE_DRAGON_SCALES:
1805.         return PM_BLUE_DRAGON;
1806.     case GREEN_DRAGON_SCALE_MAIL:
1807.     case GREEN_DRAGON_SCALES:
1808.         return PM_GREEN_DRAGON;
1809.     case YELLOW_DRAGON_SCALE_MAIL:
1810.     case YELLOW_DRAGON_SCALES:
1811.         return PM_YELLOW_DRAGON;
1812.     default:
1813.         return -1;
1814.     }
1815. }
1816. 
1817. /* some species have awareness of other species */
1818. static void
1819. polysense()
1820. {
1821.     short warnidx = NON_PM;
1822. 
1823.     context.warntype.speciesidx = NON_PM;
1824.     context.warntype.species = 0;
1825.     context.warntype.polyd = 0;
1826.     HWarn_of_mon &= ~FROMRACE;
1827. 
1828.     switch (u.umonnum) {
1829.     case PM_PURPLE_WORM:
1830.         warnidx = PM_SHRIEKER;
1831.         break;
1832.     case PM_VAMPIRE:
1833.     case PM_VAMPIRE_LORD:
1834.         context.warntype.polyd = M2_HUMAN | M2_ELF;
1835.         HWarn_of_mon |= FROMRACE;
1836.         return;
1837.     }
1838.     if (warnidx >= LOW_PM) {
1839.         context.warntype.speciesidx = warnidx;
1840.         context.warntype.species = &mons[warnidx];
1841.         HWarn_of_mon |= FROMRACE;
1842.     }
1843. }
1844. 
1845. /* True iff hero's role or race has been genocided */
1846. boolean
1847. ugenocided()
1848. {
1849.     return (boolean) ((mvitals[urole.malenum].mvflags & G_GENOD)
1850.                       || (urole.femalenum != NON_PM
1851.                           && (mvitals[urole.femalenum].mvflags & G_GENOD))
1852.                       || (mvitals[urace.malenum].mvflags & G_GENOD)
1853.                       || (urace.femalenum != NON_PM
1854.                           && (mvitals[urace.femalenum].mvflags & G_GENOD)));
1855. }
1856. 
1857. /* how hero feels "inside" after self-genocide of role or race */
1858. const char *
1859. udeadinside()
1860. {
1861.     /* self-genocide used to always say "you feel dead inside" but that
1862.        seems silly when you're polymorphed into something undead;
1863.        monkilled() distinguishes between living (killed) and non (destroyed)
1864.        for monster death message; we refine the nonliving aspect a bit */
1865.     return !nonliving(youmonst.data)
1866.              ? "dead"          /* living, including demons */
1867.              : !weirdnonliving(youmonst.data)
1868.                  ? "condemned" /* undead plus manes */
1869.                  : "empty";    /* golems plus vortices */
1870. }
1871. 
1872. /*polyself.c*/