Source:NetHack 5.0.0/src/mondata.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to mondata.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/mondata.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	mondata.c	$NHDT-Date: 1738638877 2025/02/03 19:14:37 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.140 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2011. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. /*
8.  *      These routines provide basic data for any type of monster.
9.  */
10. 
11. /* set up an individual monster's base type (initial creation, shapechange) */
12. void
13. set_mon_data(struct monst *mon, struct permonst *ptr)
14. {
15.     int new_speed, old_speed = mon->data ? mon->data->mmove : 0;
16.     short *movement_p = (mon == &gy.youmonst) ? &u.umovement : &mon->movement;
17. 
18.     mon->data = ptr;
19.     mon->mnum = (short) monsndx(ptr);
20. 
21.     if (*movement_p) { /* used to adjust poly'd hero as well as monsters */
22.         new_speed = ptr->mmove;
23.         /* prorate unused movement if new form is slower so that
24.            it doesn't get extra moves leftover from previous form;
25.            if new form is faster, leave unused movement as is */
26.         if (new_speed < old_speed) {
27.             /*
28.              * Some static analysis warns that this might divide by 0
29.                mon->movement = new_speed * mon->movement / old_speed;
30.              * so add a redundant test to suppress that.
31.              */
32.             *movement_p *= new_speed;
33.             if (old_speed > 0) /* old > new and new >= 0, so always True */
34.                 *movement_p /= old_speed;
35.         }
36.     }
37.     return;
38. }
39. 
40. /* does monster-type have any attack for a specific type of damage? */
41. struct attack *
42. attacktype_fordmg(struct permonst *ptr, int atyp, int dtyp)
43. {
44.     struct attack *a;
45. 
46.     for (a = &ptr->mattk[0]; a < &ptr->mattk[NATTK]; a++)
47.         if (a->aatyp == atyp && (dtyp == AD_ANY || a->adtyp == dtyp))
48.             return a;
49.     return (struct attack *) 0;
50. }
51. 
52. /* does monster-type have a particular type of attack */
53. boolean
54. attacktype(struct permonst *ptr, int atyp)
55. {
56.     return attacktype_fordmg(ptr, atyp, AD_ANY) ? TRUE : FALSE;
57. }
58. 
59. /* returns True if monster doesn't attack, False if it does */
60. boolean
61. noattacks(struct permonst *ptr)
62. {
63.     int i;
64.     struct attack *mattk = ptr->mattk;
65. 
66.     for (i = 0; i < NATTK; i++) {
67.         /* AT_BOOM "passive attack" (gas spore's explosion upon death)
68.            isn't an attack as far as our callers are concerned */
69.         if (mattk[i].aatyp == AT_BOOM)
70.             continue;
71. 
72.         if (mattk[i].aatyp)
73.             return FALSE;
74.     }
75.     return TRUE;
76. }
77. 
78. /* does monster-type transform into something else when petrified? */
79. boolean
80. poly_when_stoned(struct permonst *ptr)
81. {
82.     /* non-stone golems turn into stone golems unless latter is genocided */
83.     return (boolean) (is_golem(ptr) && ptr != &mons[PM_STONE_GOLEM]
84.                       && !(svm.mvitals[PM_STONE_GOLEM].mvflags & G_GENOD));
85.     /* allow G_EXTINCT */
86. }
87. 
88. /* is 'mon' (possibly youmonst) protected against damage type 'adtype' via
89.    wielded weapon or worn dragon scales? [or by virtue of being a dragon?] */
90. boolean
91. defended(struct monst *mon, int adtyp)
92. {
93.     struct obj *o, otemp;
94.     int mndx;
95.     boolean is_you = (mon == &gy.youmonst);
96. 
97.     /* is 'mon' wielding an artifact that protects against 'adtyp'? */
98.     o = is_you ? uwep : MON_WEP(mon);
99.     if (o && o->oartifact && defends(adtyp, o))
100.         return TRUE;
101. 
102.     /* if 'mon' is an adult dragon, treat it as if it was wearing scales
103.        so that it has the same benefit as a hero wearing dragon scales */
104.     mndx = monsndx(mon->data);
105.     if (mndx >= PM_GRAY_DRAGON && mndx <= PM_YELLOW_DRAGON) {
106.         /* a dragon is its own suit...  if mon is poly'd hero, we don't
107.            care about embedded scales (uskin) because being a dragon with
108.            embedded scales is no better than just being a dragon */
109.         otemp = cg.zeroobj;
110.         otemp.oclass = ARMOR_CLASS;
111.         otemp.otyp = GRAY_DRAGON_SCALES + (mndx - PM_GRAY_DRAGON);
112.         /* defends() and Is_dragon_armor() only care about otyp so ignore
113.            the rest of otemp's fields */
114.         o = &otemp;
115.     } else {
116.         /* ordinary case: not an adult dragon */
117.         o = is_you ? uarm : which_armor(mon, W_ARM);
118.     }
119.     /* is 'mon' wearing dragon scales that protect against 'adtyp'? */
120.     if (o && Is_dragon_armor(o) && defends(adtyp, o))
121.         return TRUE;
122. 
123.     return FALSE;
124. }
125. 
126. /* returns True if monster resists particular elemental damage;
127.    handles 'carry' effects of artifacts as well as worn/wielded items */
128. boolean
129. Resists_Elem(struct monst *mon, int propindx)
130. {
131.     struct obj *o;
132.     long slotmask;
133.     boolean is_you = (mon == &gy.youmonst);
134.     int u_resist = 0, damgtype = 0, rsstmask = 0;
135. 
136.     /*
137.      * Main damage/resistance types, mostly matching dragon breath values.
138.      *  propindx = property index, fire (1), cold, (2) through stone (8);
139.      *  damgtype = damage type, 2 through 9 (0 and 1 aren't used here);
140.      *  rsstmask = resistance mask, 1, 2, 4, ..., 64, 128.
141.      */
142. 
143.     switch (propindx) {
144.     case FIRE_RES:   /* 1 */
145.     case COLD_RES:   /* 2 */
146.     case SLEEP_RES:  /* 3 */
147.     case DISINT_RES: /* 4 */
148.     case SHOCK_RES:  /* 5 */
149.     case POISON_RES: /* 6 */
150.     case ACID_RES:   /* 7 */
151.     case STONE_RES:  /* 8 */
152.         damgtype = propindx + 1; /* valid for propindx 1..8, damgtype 2..9 */
153.         rsstmask = 1 << (propindx - 1); /* valid for propindx 1..8 */
154.         u_resist = u.uprops[propindx].intrinsic
155.                    || u.uprops[propindx].extrinsic;
156.         break;
157. 
158.     /* accept these, but we expect callers to use their routines directly */
159.     case ANTIMAGIC:
160.         return resists_magm(mon);
161.     case DRAIN_RES:
162.         return resists_drli(mon);
163.     case BLND_RES:
164.         return resists_blnd(mon);
165. 
166.     default:
167.         impossible("Resists_Elem(%d), unexpected property type", propindx);
168.         return FALSE;
169.     }
170. 
171.     if (is_you ? u_resist : ((mon_resistancebits(mon) & rsstmask) != 0))
172.         return TRUE;
173.     /* check for resistance granted by wielded weapon */
174.     o = is_you ? uwep : MON_WEP(mon);
175.     if (o && o->oartifact && defends(damgtype, o))
176.         return TRUE;
177.     /* check for resistance granted by worn or carried items */
178.     o = is_you ? gi.invent : mon->minvent;
179.     slotmask = W_ARMOR | W_ACCESSORY;
180.     if (!is_you /* assumes monsters don't wield non-weapons */
181.         || (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))))
182.         slotmask |= W_WEP;
183.     if (is_you && u.twoweap)
184.         slotmask |= W_SWAPWEP;
185.     for (; o; o = o->nobj)
186.         if (((o->owornmask & slotmask) != 0L
187.              && objects[o->otyp].oc_oprop == propindx)
188.             || ((o->owornmask & W_ARMC) == W_ARMC
189.                 /* worn apron confers a pair of resistances but
190.                    objects[ALCHEMY_SMOCK].oc_oprop can only represent one;
191.                    we check both so won't need to know which one that is */
192.                 && o->otyp == ALCHEMY_SMOCK
193.                 && (propindx == POISON_RES || propindx == ACID_RES))
194.             || (o->oartifact && defends_when_carried(damgtype, o)))
195.             return TRUE;
196.     return FALSE;
197. }
198. 
199. /* returns True if monster is drain-life resistant */
200. boolean
201. resists_drli(struct monst *mon)
202. {
203.     struct permonst *ptr = mon->data;
204. 
205.     if (is_undead(ptr) || is_demon(ptr) || is_were(ptr)
206.         /* is_were() doesn't handle hero in human form */
207.         || (mon == &gy.youmonst && u.ulycn >= LOW_PM)
208.         || ptr == &mons[PM_DEATH] || is_vampshifter(mon))
209.         return TRUE;
210.     return defended(mon, AD_DRLI);
211. }
212. 
213. /* True if monster is magic-missile (actually, general magic) resistant */
214. boolean
215. resists_magm(struct monst *mon)
216. {
217.     struct permonst *ptr = mon->data;
218.     boolean is_you = (mon == &gy.youmonst);
219.     long slotmask;
220.     struct obj *o;
221. 
222.     /* as of 3.2.0:  gray dragons, Angels, Oracle, Yeenoghu */
223.     if (dmgtype(ptr, AD_MAGM) || ptr == &mons[PM_BABY_GRAY_DRAGON]
224.         || dmgtype(ptr, AD_RBRE)) /* Chromatic Dragon */
225.         return TRUE;
226.     /* check for magic resistance granted by wielded weapon */
227.     o = is_you ? uwep : MON_WEP(mon);
228.     if (o && o->oartifact && defends(AD_MAGM, o))
229.         return TRUE;
230.     /* check for magic resistance granted by worn or carried items */
231.     o = is_you ? gi.invent : mon->minvent;
232.     slotmask = W_ARMOR | W_ACCESSORY;
233.     if (!is_you /* assumes monsters don't wield non-weapons */
234.         || (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))))
235.         slotmask |= W_WEP;
236.     if (is_you && u.twoweap)
237.         slotmask |= W_SWAPWEP;
238.     for (; o; o = o->nobj)
239.         if (((o->owornmask & slotmask) != 0L
240.              && objects[o->otyp].oc_oprop == ANTIMAGIC)
241.             || (o->oartifact && defends_when_carried(AD_MAGM, o)))
242.             return TRUE;
243.     return FALSE;
244. }
245. 
246. /* True if monster is resistant to light-induced blindness */
247. boolean
248. resists_blnd(struct monst *mon)
249. {
250.     struct permonst *ptr = mon->data;
251.     boolean is_you = (mon == &gy.youmonst);
252. 
253.     if (is_you ? (Blind || Unaware)
254.                : (mon->mblinded || !mon->mcansee || !haseyes(ptr)
255.                   /* BUG: temporary sleep sets mfrozen, but since
256.                           paralysis does too, we can't check it */
257.                   || mon->msleeping))
258.         return TRUE;
259.     /* yellow light, Archon; !dust vortex, !cobra, !raven */
260.     if (dmgtype_fromattack(ptr, AD_BLND, AT_EXPL)
261.         || dmgtype_fromattack(ptr, AD_BLND, AT_GAZE))
262.         return TRUE;
263.     /* Sunsword */
264.     if (resists_blnd_by_arti(mon))
265.         return TRUE;
266.     /* catchall */
267.     if (is_you && Blnd_resist) {
268.         impossible("'Blnd_resist' but not resists_blnd()?");
269.         return TRUE;
270.     }
271.     return FALSE;
272. }
273. 
274. /* True iff monster is resistant to light-induced blindness due to worn
275.    or wielded magical equipment (used to decide whether to show sparkle
276.    animation when resisting) */
277. boolean
278. resists_blnd_by_arti(struct monst *mon)
279. {
280.     struct obj *o;
281.     boolean is_you = (mon == &gy.youmonst);
282. 
283.     o = is_you ? uwep : MON_WEP(mon);
284.     if (o && o->oartifact && defends(AD_BLND, o))
285.         return TRUE;
286.     o = is_you ? gi.invent : mon->minvent;
287.     for (; o; o = o->nobj)
288.         if (defends_when_carried(AD_BLND, o))
289.             return TRUE;
290. #if 0   /* omit this; the Eyes of the Overworld have no carry property and
291.          * their worn property is magic resistance rather than blindness
292.          * resistance; wearing them blocks blindness without actually
293.          * preventing it, so don't classify them as providing resistance */
294.     if (is_you && is_art(uamul, ART_EYES_OF_THE_OVERWORLD))
295.         return TRUE;
296. #endif /* 0 */
297.     return FALSE;
298. }
299. 
300. /* True iff monster can be blinded by the given attack;
301.    note: may return True when mdef is blind (e.g. new cream-pie attack)
302.    magr can be NULL.
303. */
304. boolean
305. can_blnd(
306.     struct monst *magr, /* NULL == no specific aggressor */
307.     struct monst *mdef,
308.     uchar aatyp,
309.     struct obj *obj) /* aatyp == AT_WEAP, AT_SPIT */
310. {
311.     boolean is_you = (mdef == &gy.youmonst);
312.     boolean check_visor = FALSE;
313.     struct obj *o;
314. 
315.     /* no eyes protect against all attacks for now */
316.     if (!haseyes(mdef->data))
317.         return FALSE;
318. 
319.     /* if monster has been permanently blinded, the deed is already done */
320.     if (!is_you && mon_perma_blind(mdef))
321.         return FALSE;
322. 
323.     /* /corvus oculum corvi non eruit/
324.        a saying expressed in Latin rather than a zoological observation:
325.        "a crow will not pluck out the eye of another crow"
326.        so prevent ravens from blinding each other */
327.     if (magr && magr->data == &mons[PM_RAVEN] && mdef->data == &mons[PM_RAVEN])
328.         return FALSE;
329. 
330.     switch (aatyp) {
331.     case AT_EXPL:
332.     case AT_BOOM:
333.     case AT_GAZE:
334.     case AT_MAGC:
335.     case AT_BREA: /* assumed to be lightning */
336.         /* light-based attacks may be cancelled or resisted */
337.         if (magr && magr->mcan)
338.             return FALSE;
339.         return !resists_blnd(mdef);
340. 
341.     case AT_WEAP:
342.     case AT_SPIT:
343.     case AT_NONE:
344.         /* an object is used (thrown/spit/other) */
345.         if (obj && (obj->otyp == CREAM_PIE)) {
346.             if (is_you && Blindfolded)
347.                 return FALSE;
348.         } else if (obj && (obj->otyp == BLINDING_VENOM)) {
349.             /* all ublindf, including LENSES, protect, cream-pies too */
350.             if (is_you && (ublindf || u.ucreamed))
351.                 return FALSE;
352.             check_visor = TRUE;
353.         } else if (obj && (obj->otyp == POT_BLINDNESS)) {
354.             return TRUE; /* no defense */
355.         } else
356.             return FALSE; /* other objects cannot cause blindness yet */
357.         if ((magr == &gy.youmonst) && u.uswallow)
358.             return FALSE; /* can't affect eyes while inside monster */
359.         break;
360. 
361.     case AT_ENGL:
362.         if (is_you && (Blindfolded || Unaware || u.ucreamed))
363.             return FALSE;
364.         if (!is_you && mdef->msleeping)
365.             return FALSE;
366.         break;
367. 
368.     case AT_CLAW:
369.         /* e.g. raven: all ublindf, including LENSES, protect */
370.         if (is_you && ublindf)
371.             return FALSE;
372.         if ((magr == &gy.youmonst) && u.uswallow)
373.             return FALSE; /* can't affect eyes while inside monster */
374.         check_visor = TRUE;
375.         break;
376. 
377.     case AT_TUCH:
378.     case AT_STNG:
379.         /* some physical, blind-inducing attacks can be cancelled */
380.         if (magr && magr->mcan)
381.             return FALSE;
382.         break;
383. 
384.     default:
385.         break;
386.     }
387. 
388.     /* check if wearing a visor (only checked if visor might help) */
389.     if (check_visor) {
390.         o = (mdef == &gy.youmonst) ? gi.invent : mdef->minvent;
391.         for (; o; o = o->nobj)
392.             if ((o->owornmask & W_ARMH)
393.                 && objdescr_is(o, "visored helmet"))
394.                 return FALSE;
395.     }
396. 
397.     return TRUE;
398. }
399. 
400. /* returns True if monster can attack at range */
401. boolean
402. ranged_attk(struct permonst *ptr)
403. {
404.     int i;
405. 
406.     for (i = 0; i < NATTK; i++)
407.         if (DISTANCE_ATTK_TYPE(ptr->mattk[i].aatyp))
408.             return TRUE;
409.     return FALSE;
410. }
411. 
412. #if defined(MAKEDEFS_C) \
413.     || (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG)
414. /*
415.  * If adding a new monster, include a guestimate for difficulty,
416.  * build the program, then run it in wizard mode and use the
417.  * #mondifficulty command.  If it reports a discrepancy, update
418.  * the monsters array with the more accurate value (or possibly
419.  * modify the 'mstrength()' algorithm to generate the guessed one).
420.  */
421. static boolean mstrength_ranged_attk(struct permonst *);
422. 
423. 
424. /* This routine is designed to return an integer value which represents
425.    an approximation of monster strength.  It uses a similar method of
426.    determination as "experience()" to arrive at the strength. */
427. int
428. mstrength(struct permonst *ptr)
429. {
430.     int i, tmp2, n, tmp = ptr->mlevel;
431. 
432.     if (tmp > 49) /* special fixed hp monster */
433.         tmp = 2 * (tmp - 6) / 4;
434. 
435.     /* for creation in groups */
436.     n = (!!(ptr->geno & G_SGROUP));
437.     n += (!!(ptr->geno & G_LGROUP)) << 1;
438. 
439.     /* for ranged attacks */
440.     if (mstrength_ranged_attk(ptr))
441.         n++;
442. 
443.     /* for higher ac values */
444.     n += (ptr->ac < 4);
445.     n += (ptr->ac < 0);
446. 
447.     /* for very fast monsters */
448.     n += (ptr->mmove >= 18);
449. 
450.     /* for each attack and "special" attack */
451.     for (i = 0; i < NATTK; i++) {
452.         tmp2 = ptr->mattk[i].aatyp;
453.         n += (tmp2 > 0);
454.         n += (tmp2 == AT_MAGC);
455.         n += (tmp2 == AT_WEAP && (ptr->mflags2 & M2_STRONG));
456.         if (tmp2 == AT_EXPL) {
457.             int tmp3 = ptr->mattk[i].adtyp;
458.             /* {freezing,flaming,shocking} spheres are fairly weak but
459.                can destroy equipment; {yellow,black} lights can't */
460.             n += ((tmp3 == AD_COLD || tmp3 == AD_FIRE) ? 3
461.                   : (tmp3 == AD_ELEC) ? 5
462.                     : 0);
463.         }
464.     }
465. 
466.     /* for each "special" damage type */
467.     for (i = 0; i < NATTK; i++) {
468.         tmp2 = ptr->mattk[i].adtyp;
469.         if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_DRST)
470.             || (tmp2 == AD_DRDX) || (tmp2 == AD_DRCO) || (tmp2 == AD_WERE))
471.             n += 2;
472.         else if (strcmp(ptr->pmnames[NEUTRAL], "grid bug"))
473.             n += (tmp2 != AD_PHYS);
474.         n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23);
475.     }
476. 
477.     /* Leprechauns are a special case.  They have many hit dice so they can
478.        hit and are hard to kill, but they don't really do much damage. */
479.     if (!strcmp(ptr->pmnames[NEUTRAL], "leprechaun"))
480.         n -= 2;
481. 
482.     /* despite group and poison increments, soldier ants and killer bees are
483.        underestimated by the formula, so have an artificial +1 difficulty */
484.     if (!strcmp(ptr->pmnames[NEUTRAL], "killer bee") ||
485.         !strcmp(ptr->pmnames[NEUTRAL], "soldier ant"))
486.         n += 2; /* +1 after 'tmp += n/2' below */
487. 
488.     /* finally, adjust the monster level  0 <= n <= 24 (approx.) */
489.     if (n == 0)
490.         tmp -= 1;
491.     else if (n < 6)
492.         tmp += (n / 3 + 1);
493.     else
494.         tmp += (n / 2);
495. 
496.     return (tmp >= 0) ? tmp : 0;
497. }
498. 
499. /* returns True if monster can attack at range */
500. staticfn boolean
501. mstrength_ranged_attk(struct permonst *ptr)
502. {
503.     int i, j;
504.     int atk_mask = (1 << AT_BREA) | (1 << AT_SPIT) | (1 << AT_GAZE);
505. 
506.     for (i = 0; i < NATTK; i++) {
507.         if ((j = ptr->mattk[i].aatyp) >= AT_WEAP
508.             || (j < 32 && (atk_mask & (1 << j)) != 0))
509.             return TRUE;
510.     }
511.     return FALSE;
512. }
513. #endif /* (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || DEBUG || MAKEDEFS_C */
514. 
515. /* True if specific monster is especially affected by silver weapons */
516. boolean
517. mon_hates_silver(struct monst *mon)
518. {
519.     return (boolean) (is_vampshifter(mon) || hates_silver(mon->data));
520. }
521. 
522. /* True if monster-type is especially affected by silver weapons */
523. boolean
524. hates_silver(struct permonst *ptr)
525. {
526.     return (boolean) (is_were(ptr) || ptr->mlet == S_VAMPIRE || is_demon(ptr)
527.                       || ptr == &mons[PM_SHADE]
528.                       || (ptr->mlet == S_IMP && ptr != &mons[PM_TENGU]));
529. }
530. 
531. /* True if specific monster is especially affected by blessed objects */
532. boolean
533. mon_hates_blessings(struct monst *mon)
534. {
535.     return (boolean) (is_vampshifter(mon) || hates_blessings(mon->data));
536. }
537. 
538. /* True if monster-type is especially affected by blessed objects */
539. boolean
540. hates_blessings(struct permonst *ptr)
541. {
542.     return (boolean) (is_undead(ptr) || is_demon(ptr));
543. }
544. 
545. /* True if specific monster is especially affected by light-emitting weapons */
546. boolean
547. mon_hates_light(struct monst *mon)
548. {
549.     return (boolean) hates_light(mon->data);
550. }
551. 
552. /* True iff the type of monster pass through iron bars */
553. boolean
554. passes_bars(struct permonst *mptr)
555. {
556.     return (boolean) (passes_walls(mptr) || amorphous(mptr) || unsolid(mptr)
557.                       || is_whirly(mptr) || verysmall(mptr)
558.                       /* rust monsters and some puddings can destroy bars */
559.                       || dmgtype(mptr, AD_RUST) || dmgtype(mptr, AD_CORR)
560.                       /* rock moles can eat bars */
561.                       || metallivorous(mptr)
562.                       || (slithy(mptr) && !bigmonst(mptr)));
563. }
564. 
565. /* returns True if monster can blow (whistle, etc) */
566. boolean
567. can_blow(struct monst *mtmp)
568. {
569.     if ((is_silent(mtmp->data) || mtmp->data->msound == MS_BUZZ)
570.         && (breathless(mtmp->data) || verysmall(mtmp->data)
571.             || !has_head(mtmp->data) || mtmp->data->mlet == S_EEL))
572.         return FALSE;
573.     if ((mtmp == &gy.youmonst) && Strangled)
574.         return FALSE;
575.     return TRUE;
576. }
577. 
578. /* for casting spells and reading scrolls while blind */
579. boolean
580. can_chant(struct monst *mtmp)
581. {
582.     if ((mtmp == &gy.youmonst && Strangled)
583.         || is_silent(mtmp->data) || !has_head(mtmp->data)
584.         || mtmp->data->msound == MS_BUZZ || mtmp->data->msound == MS_BURBLE)
585.         return FALSE;
586.     return TRUE;
587. }
588. 
589. /* True if mon is vulnerable to strangulation */
590. boolean
591. can_be_strangled(struct monst *mon)
592. {
593.     struct obj *mamul;
594.     boolean nonbreathing, nobrainer;
595. 
596.     /* For amulet of strangulation support:  here we're considering
597.        strangulation to be loss of blood flow to the brain due to
598.        constriction of the arteries in the neck, so all headless
599.        creatures are immune (no neck) as are mindless creatures
600.        who don't need to breathe (brain, if any, doesn't care).
601.        Mindless creatures who do need to breath are vulnerable, as
602.        are non-breathing creatures which have higher brain function. */
603.     if (!has_head(mon->data))
604.         return FALSE;
605.     if (mon == &gy.youmonst) {
606.         /* hero can't be mindless but poly'ing into mindless form can
607.            confer strangulation protection */
608.         nobrainer = mindless(gy.youmonst.data);
609.         nonbreathing = Breathless;
610.     } else {
611.         nobrainer = mindless(mon->data);
612.         /* monsters don't wear amulets of magical breathing,
613.            so second part doesn't achieve anything useful... */
614.         nonbreathing = (breathless(mon->data)
615.                         || ((mamul = which_armor(mon, W_AMUL)) != 0
616.                             && (mamul->otyp == AMULET_OF_MAGICAL_BREATHING)));
617.     }
618.     return (boolean) (!nobrainer || !nonbreathing);
619. }
620. 
621. /* returns True if monster can track well */
622. boolean
623. can_track(struct permonst *ptr)
624. {
625.     if (u_wield_art(ART_EXCALIBUR))
626.         return TRUE;
627.     return (boolean) haseyes(ptr);
628. }
629. 
630. /* creature will slide out of armor */
631. boolean
632. sliparm(struct permonst *ptr)
633. {
634.     return (boolean) (is_whirly(ptr) || ptr->msize <= MZ_SMALL
635.                       || noncorporeal(ptr));
636. }
637. 
638. /* creature will break out of armor */
639. boolean
640. breakarm(struct permonst *ptr)
641. {
642.     if (sliparm(ptr))
643.         return FALSE;
644. 
645.     return (boolean) (bigmonst(ptr)
646.                       || (ptr->msize > MZ_SMALL && !humanoid(ptr))
647.                       /* special cases of humanoids that cannot wear suits */
648.                       || ptr == &mons[PM_MARILITH]
649.                       || ptr == &mons[PM_WINGED_GARGOYLE]);
650. }
651. 
652. /* creature sticks other creatures it hits */
653. boolean
654. sticks(struct permonst *ptr)
655. {
656.     return (boolean) (dmgtype(ptr, AD_STCK)
657.                       || (dmgtype(ptr, AD_WRAP) && !attacktype(ptr, AT_ENGL))
658.                       || attacktype(ptr, AT_HUGS));
659. }
660. 
661. /* some monster-types can't vomit */
662. boolean
663. cantvomit(struct permonst *ptr)
664. {
665.     /* rats and mice are incapable of vomiting; likewise with horses;
666.        which other creatures have the same limitation? */
667.     if (ptr->mlet == S_RODENT && ptr != &mons[PM_ROCK_MOLE]
668.         && ptr != &mons[PM_WOODCHUCK])
669.         return TRUE;
670.     if (ptr == &mons[PM_WARHORSE] || ptr == &mons[PM_HORSE]
671.         || ptr == &mons[PM_PONY])
672.         return TRUE;
673.     return FALSE;
674. }
675. 
676. /* number of horns this type of monster has on its head */
677. int
678. num_horns(struct permonst *ptr)
679. {
680.     switch (monsndx(ptr)) {
681.     case PM_HORNED_DEVIL: /* ? "more than one" */
682.     case PM_MINOTAUR:
683.     case PM_ASMODEUS:
684.     case PM_BALROG:
685.         return 2;
686.     case PM_WHITE_UNICORN:
687.     case PM_GRAY_UNICORN:
688.     case PM_BLACK_UNICORN:
689.     case PM_KI_RIN:
690.         return 1;
691.     default:
692.         break;
693.     }
694.     return 0;
695. }
696. 
697. /* does monster-type deal out a particular type of damage from a particular
698.    type of attack? */
699. struct attack *
700. dmgtype_fromattack(struct permonst *ptr, int dtyp, int atyp)
701. {
702.     struct attack *a;
703. 
704.     for (a = &ptr->mattk[0]; a < &ptr->mattk[NATTK]; a++)
705.         if (a->adtyp == dtyp && (atyp == AT_ANY || a->aatyp == atyp))
706.             return a;
707.     return (struct attack *) 0;
708. }
709. 
710. /* does monster-type deal out a particular type of damage from any attack */
711. boolean
712. dmgtype(struct permonst *ptr, int dtyp)
713. {
714.     return dmgtype_fromattack(ptr, dtyp, AT_ANY) ? TRUE : FALSE;
715. }
716. 
717. /* returns the maximum damage a defender can do to the attacker via
718.    a passive defense */
719. int
720. max_passive_dmg(struct monst *mdef, struct monst *magr)
721. {
722.     int i, dmg, multi2 = 0;
723.     uchar adtyp;
724. 
725.     /* each attack by magr can result in passive damage */
726.     for (i = 0; i < NATTK; i++)
727.         switch (magr->data->mattk[i].aatyp) {
728.         case AT_CLAW:
729.         case AT_BITE:
730.         case AT_KICK:
731.         case AT_BUTT:
732.         case AT_TUCH:
733.         case AT_STNG:
734.         case AT_HUGS:
735.         case AT_ENGL:
736.         case AT_TENT:
737.         case AT_WEAP:
738.             multi2++;
739.             break;
740.         default:
741.             break;
742.         }
743. 
744.     dmg = 0;
745.     for (i = 0; i < NATTK; i++)
746.         if (mdef->data->mattk[i].aatyp == AT_NONE
747.             || mdef->data->mattk[i].aatyp == AT_BOOM) {
748.             adtyp = mdef->data->mattk[i].adtyp;
749.             if ((adtyp == AD_FIRE && completelyburns(magr->data))
750.                 || (adtyp == AD_DCAY && completelyrots(magr->data))
751.                 || (adtyp == AD_RUST && completelyrusts(magr->data))) {
752.                 dmg = magr->mhp;
753.             } else if ((adtyp == AD_ACID && !resists_acid(magr))
754.                        || (adtyp == AD_COLD && !resists_cold(magr))
755.                        || (adtyp == AD_FIRE && !resists_fire(magr))
756.                        || (adtyp == AD_ELEC && !resists_elec(magr))
757.                        || adtyp == AD_PHYS) {
758.                 dmg = mdef->data->mattk[i].damn;
759.                 if (!dmg)
760.                     dmg = mdef->data->mlevel + 1;
761.                 dmg *= mdef->data->mattk[i].damd;
762.             }
763.             dmg *= multi2;
764.             break;
765.         }
766.     return dmg;
767. }
768. 
769. /* determine whether two monster types are from the same species */
770. boolean
771. same_race(struct permonst *pm1, struct permonst *pm2)
772. {
773.     char let1 = pm1->mlet, let2 = pm2->mlet;
774. 
775.     if (pm1 == pm2)
776.         return TRUE; /* exact match */
777.     /* player races have their own predicates */
778.     if (is_human(pm1))
779.         return is_human(pm2);
780.     if (is_elf(pm1))
781.         return is_elf(pm2);
782.     if (is_dwarf(pm1))
783.         return is_dwarf(pm2);
784.     if (is_gnome(pm1))
785.         return is_gnome(pm2);
786.     if (is_orc(pm1))
787.         return is_orc(pm2);
788.     /* other creatures are less precise */
789.     if (is_giant(pm1))
790.         return is_giant(pm2); /* open to quibbling here */
791.     if (is_golem(pm1))
792.         return is_golem(pm2); /* even moreso... */
793.     if (is_mind_flayer(pm1))
794.         return is_mind_flayer(pm2);
795.     if (let1 == S_KOBOLD || pm1 == &mons[PM_KOBOLD_ZOMBIE]
796.         || pm1 == &mons[PM_KOBOLD_MUMMY])
797.         return (let2 == S_KOBOLD || pm2 == &mons[PM_KOBOLD_ZOMBIE]
798.                 || pm2 == &mons[PM_KOBOLD_MUMMY]);
799.     if (let1 == S_OGRE)
800.         return (let2 == S_OGRE);
801.     if (let1 == S_NYMPH)
802.         return (let2 == S_NYMPH);
803.     if (let1 == S_CENTAUR)
804.         return (let2 == S_CENTAUR);
805.     if (is_unicorn(pm1))
806.         return is_unicorn(pm2);
807.     if (let1 == S_DRAGON)
808.         return (let2 == S_DRAGON);
809.     if (let1 == S_NAGA)
810.         return (let2 == S_NAGA);
811.     /* other critters get steadily messier */
812.     if (is_rider(pm1))
813.         return is_rider(pm2); /* debatable */
814.     if (is_minion(pm1))
815.         return is_minion(pm2); /* [needs work?] */
816.     /* tengu don't match imps (first test handled case of both being tengu) */
817.     if (pm1 == &mons[PM_TENGU] || pm2 == &mons[PM_TENGU])
818.         return FALSE;
819.     if (let1 == S_IMP)
820.         return (let2 == S_IMP);
821.     /* and minor demons (imps) don't match major demons */
822.     else if (let2 == S_IMP)
823.         return FALSE;
824.     if (is_demon(pm1))
825.         return is_demon(pm2);
826.     if (is_undead(pm1)) {
827.         if (let1 == S_ZOMBIE)
828.             return (let2 == S_ZOMBIE);
829.         if (let1 == S_MUMMY)
830.             return (let2 == S_MUMMY);
831.         if (let1 == S_VAMPIRE)
832.             return (let2 == S_VAMPIRE);
833.         if (let1 == S_LICH)
834.             return (let2 == S_LICH);
835.         if (let1 == S_WRAITH)
836.             return (let2 == S_WRAITH);
837.         if (let1 == S_GHOST)
838.             return (let2 == S_GHOST);
839.     } else if (is_undead(pm2))
840.         return FALSE;
841. 
842.     /* check for monsters which grow into more mature forms */
843.     if (let1 == let2) {
844.         int m1 = monsndx(pm1), m2 = monsndx(pm2), prv, nxt;
845. 
846.         /* we know m1 != m2 (very first check above); test all smaller
847.            forms of m1 against m2, then all larger ones; don't need to
848.            make the corresponding tests for variants of m2 against m1 */
849.         for (prv = m1, nxt = big_to_little(m1); nxt != prv;
850.              prv = nxt, nxt = big_to_little(nxt))
851.             if (nxt == m2)
852.                 return TRUE;
853.         for (prv = m1, nxt = little_to_big(m1); nxt != prv;
854.              prv = nxt, nxt = little_to_big(nxt))
855.             if (nxt == m2)
856.                 return TRUE;
857.     }
858.     /* not caught by little/big handling */
859.     if (pm1 == &mons[PM_GARGOYLE] || pm1 == &mons[PM_WINGED_GARGOYLE])
860.         return (pm2 == &mons[PM_GARGOYLE]
861.                 || pm2 == &mons[PM_WINGED_GARGOYLE]);
862.     if (pm1 == &mons[PM_KILLER_BEE] || pm1 == &mons[PM_QUEEN_BEE])
863.         return (pm2 == &mons[PM_KILLER_BEE] || pm2 == &mons[PM_QUEEN_BEE]);
864. 
865.     if (is_longworm(pm1))
866.         return is_longworm(pm2); /* handles tail */
867.     /* [currently there's no reason to bother matching up
868.         assorted bugs and blobs with their closest variants] */
869.     /* didn't match */
870.     return FALSE;
871. }
872. 
873. /* for handling alternate spellings */
874. struct alt_spl {
875.     const char *name;
876.     short pm_val;
877.     int genderhint;
878. };
879. 
880. /* figure out what type of monster a user-supplied string is specifying;
881.    ignore anything past the monster name */
882. int
883. name_to_mon(const char *in_str, int *gender_name_var)
884. {
885.     return name_to_monplus(in_str, (const char **) 0, gender_name_var);
886. }
887. 
888. /* figure out what type of monster a user-supplied string is specifying;
889.    return a pointer to whatever is past the monster name--necessary if
890.    caller wants to strip off the name and it matches one of the alternate
891.    names rather the canonical mons[].mname */
892. int
893. name_to_monplus(
894.     const char *in_str,
895.     const char **remainder_p,
896.     int *gender_name_var)
897. {
898.     /* Be careful.  We must check the entire string in case it was
899.      * something such as "ettin zombie corpse".  The calling routine
900.      * doesn't know about the "corpse" until the monster name has
901.      * already been taken off the front, so we have to be able to
902.      * read the name with extraneous stuff such as "corpse" stuck on
903.      * the end.
904.      * This causes a problem for names which prefix other names such
905.      * as "ettin" on "ettin zombie".  In this case we want the _longest_
906.      * name which exists.
907.      * This also permits plurals created by adding suffixes such as 's'
908.      * or 'es'.  Other plurals must still be handled explicitly.
909.      */
910.     int i;
911.     int mntmp = NON_PM;
912.     char *s, *str, *term;
913.     char buf[BUFSZ];
914.     int len, mgend, matchgend = -1;
915.     size_t slen;
916.     boolean exact_match = FALSE;
917. 
918.     if (remainder_p)
919.         *remainder_p = (const char *) 0;
920. 
921.     str = strcpy(buf, in_str);
922. 
923.     if (!strncmp(str, "a ", 2))
924.         str += 2;
925.     else if (!strncmp(str, "an ", 3))
926.         str += 3;
927.     else if (!strncmp(str, "the ", 4))
928.         str += 4;
929. 
930.     slen = strlen(str);
931.     term = str + slen;
932. 
933.     if ((s = strstri(str, "vortices")) != 0)
934.         Strcpy(s + 4, "ex");
935.     /* be careful with "ies"; "priest", "zombies" */
936.     else if (slen > 3 && !strcmpi(term - 3, "ies")
937.              && (slen < 7 || strcmpi(term - 7, "zombies")))
938.         Strcpy(term - 3, "y");
939.     /* luckily no monster names end in fe or ve with ves plurals */
940.     else if (slen > 3 && !strcmpi(term - 3, "ves"))
941.         Strcpy(term - 3, "f");
942. 
943.     slen = strlen(str); /* length possibly needs recomputing */
944. 
945.     {
946.         static const struct alt_spl names[] = {
947.             /* Alternate spellings */
948.             { "grey dragon", PM_GRAY_DRAGON, NEUTRAL },
949.             { "baby grey dragon", PM_BABY_GRAY_DRAGON, NEUTRAL },
950.             { "grey unicorn", PM_GRAY_UNICORN, NEUTRAL },
951.             { "grey ooze", PM_GRAY_OOZE, NEUTRAL },
952.             { "gray-elf", PM_GREY_ELF, NEUTRAL },
953.             { "mindflayer", PM_MIND_FLAYER, NEUTRAL },
954.             { "master mindflayer", PM_MASTER_MIND_FLAYER, NEUTRAL },
955.             /* More alternates; priest and priestess are separate monster
956.                types but that isn't the case for {aligned,high} priests */
957.             { "aligned priest", PM_ALIGNED_CLERIC, MALE },
958.             { "aligned priestess", PM_ALIGNED_CLERIC, FEMALE },
959.             { "high priest", PM_HIGH_CLERIC, MALE },
960.             { "high priestess", PM_HIGH_CLERIC, FEMALE },
961.             /* Inappropriate singularization by -ves check above */
962.             { "master of thief", PM_MASTER_OF_THIEVES, NEUTRAL },
963.             /* Potential misspellings where we want to avoid falling back
964.                to the rank title prefix (input has been singularized) */
965.             { "master thief", PM_MASTER_OF_THIEVES, NEUTRAL },
966.             { "master of assassin", PM_MASTER_ASSASSIN, NEUTRAL },
967.             { "master-lich", PM_MASTER_LICH, NEUTRAL }, /* cf arch-lich */
968.             { "masterlich", PM_MASTER_LICH, NEUTRAL }, /* cf demilich */
969.             /* Outdated names */
970.             { "invisible stalker", PM_STALKER, NEUTRAL },
971.             { "high-elf", PM_ELVEN_MONARCH, NEUTRAL }, /* PM_HIGH_ELF is
972.                                                         * obsolete */
973.             /* other misspellings or incorrect words */
974.             { "wood-elf", PM_WOODLAND_ELF, NEUTRAL },
975.             { "wood elf", PM_WOODLAND_ELF, NEUTRAL },
976.             { "woodland nymph", PM_WOOD_NYMPH, NEUTRAL },
977.             { "halfling", PM_HOBBIT, NEUTRAL },    /* potential guess for
978.                                                     * polyself */
979.             { "genie", PM_DJINNI, NEUTRAL }, /* potential guess for
980.                                               * ^G/#wizgenesis */
981.             /* prefix used to workaround duplicate monster names for
982.                monsters with alternate forms */
983.             { "human wererat", PM_HUMAN_WERERAT, NEUTRAL },
984.             { "human werejackal", PM_HUMAN_WEREJACKAL, NEUTRAL },
985.             { "human werewolf", PM_HUMAN_WEREWOLF, NEUTRAL },
986.             /* for completeness */
987.             { "rat wererat", PM_WERERAT, NEUTRAL },
988.             { "jackal werejackal", PM_WEREJACKAL, NEUTRAL },
989.             { "wolf werewolf", PM_WEREWOLF, NEUTRAL },
990.             /* Hyphenated names -- it would be nice to handle these via
991.                fuzzymatch() but it isn't able to ignore trailing stuff */
992.             { "ki rin", PM_KI_RIN, NEUTRAL },
993.             { "kirin", PM_KI_RIN, NEUTRAL },
994.             { "uruk hai", PM_URUK_HAI, NEUTRAL },
995.             { "orc captain", PM_ORC_CAPTAIN, NEUTRAL },
996.             { "woodland elf", PM_WOODLAND_ELF, NEUTRAL },
997.             { "green elf", PM_GREEN_ELF, NEUTRAL },
998.             { "grey elf", PM_GREY_ELF, NEUTRAL },
999.             { "gray elf", PM_GREY_ELF, NEUTRAL },
1000.             { "elf lady", PM_ELF_NOBLE, FEMALE },
1001.             { "elf lord", PM_ELF_NOBLE, MALE },
1002.             { "elf noble", PM_ELF_NOBLE, NEUTRAL },
1003.             { "olog hai", PM_OLOG_HAI, NEUTRAL },
1004.             { "arch lich", PM_ARCH_LICH, NEUTRAL },
1005.             { "archlich", PM_ARCH_LICH, NEUTRAL },
1006.             /* Some irregular plurals */
1007.             { "incubi", PM_AMOROUS_DEMON, MALE },
1008.             { "succubi", PM_AMOROUS_DEMON, FEMALE },
1009.             { "violet fungi", PM_VIOLET_FUNGUS, NEUTRAL },
1010.             { "homunculi", PM_HOMUNCULUS, NEUTRAL },
1011.             { "baluchitheria", PM_BALUCHITHERIUM, NEUTRAL },
1012.             { "lurkers above", PM_LURKER_ABOVE, NEUTRAL },
1013.             { "cavemen", PM_CAVE_DWELLER, MALE },
1014.             { "cavewomen", PM_CAVE_DWELLER, FEMALE },
1015.             { "watchmen", PM_WATCHMAN, NEUTRAL },
1016.             { "djinn", PM_DJINNI, NEUTRAL },
1017.             { "mumakil", PM_MUMAK, NEUTRAL },
1018.             { "erinyes", PM_ERINYS, NEUTRAL },
1019.             /* end of list */
1020.             { 0, NON_PM, NEUTRAL }
1021.         };
1022.         const struct alt_spl *namep;
1023. 
1024.         for (namep = names; namep->name; namep++) {
1025.             len = (int) strlen(namep->name);
1026.             if (!strncmpi(str, namep->name, len)
1027.                 /* force full word (which could conceivably be possessive) */
1028.                 && (!str[len] || str[len] == ' ' || str[len] == '\)) {
1029.                 if (remainder_p)
1030.                     *remainder_p = in_str + (&str[len] - buf);
1031.                 if (gender_name_var)
1032.                     *gender_name_var = namep->genderhint;
1033.                 return namep->pm_val;
1034.             }
1035.         }
1036.     }
1037. 
1038.     for (len = 0, i = LOW_PM; i < NUMMONS; i++) {
1039.       for (mgend = MALE; mgend < NUM_MGENDERS; mgend++) {
1040.         size_t m_i_len;
1041. 
1042.         if (!mons[i].pmnames[mgend])
1043.             continue;
1044. 
1045.         m_i_len = strlen(mons[i].pmnames[mgend]);
1046.         if (m_i_len > (size_t) len
1047.             && !strncmpi(mons[i].pmnames[mgend], str, (int) m_i_len)) {
1048.             if (m_i_len == slen) {
1049.                 mntmp = i;
1050.                 len = (int) m_i_len;
1051.                 matchgend = mgend;
1052.                 exact_match = TRUE;
1053.                 break; /* exact match */
1054.             } else if (slen > m_i_len
1055.                        && (str[m_i_len] == ' '
1056.                            || !strcmpi(&str[m_i_len], "s")
1057.                            || !strncmpi(&str[m_i_len], "s ", 2)
1058.                            || !strcmpi(&str[m_i_len], "'")
1059.                            || !strncmpi(&str[m_i_len], "' ", 2)
1060.                            || !strcmpi(&str[m_i_len], "'s")
1061.                            || !strncmpi(&str[m_i_len], "'s ", 3)
1062.                            || !strcmpi(&str[m_i_len], "es")
1063.                            || !strncmpi(&str[m_i_len], "es ", 3))) {
1064.                 mntmp = i;
1065.                 len = (int) m_i_len;
1066.                 matchgend = mgend;
1067.             }
1068.         }
1069.       }
1070.       if (exact_match)
1071.         break;
1072.     }
1073.     /* FIXME: some titles have gender; title_to_mon() doesn't propagate it */
1074.     if (mntmp == NON_PM)
1075.         mntmp = title_to_mon(str, (int *) 0, &len);
1076.     if (len && remainder_p)
1077.         *remainder_p = in_str + (&str[len] - buf);
1078.     if (gender_name_var && matchgend != -1) {
1079.         /* don't override with neuter if caller has already specified male
1080.            or female and we've matched the neuter name */
1081.         if (*gender_name_var == -1 || matchgend != NEUTRAL)
1082.             *gender_name_var = matchgend;
1083.     }
1084.     return mntmp;
1085. }
1086. 
1087. /* monster class from user input; used for genocide and controlled polymorph;
1088.    returns 0 rather than MAXMCLASSES if no match is found */
1089. int
1090. name_to_monclass(const char *in_str, int * mndx_p)
1091. {
1092.     /* Single letters are matched against def_monsyms[].sym; words
1093.        or phrases are first matched against def_monsyms[].explain
1094.        to check class description; if not found there, then against
1095.        mons[].pmnames[] to test individual monster types.  Input can be a
1096.        substring of the full description or pmname, but to be accepted,
1097.        such partial matches must start at beginning of a word.  Some
1098.        class descriptions include "foo or bar" and "foo or other foo"
1099.        so we don't want to accept "or", "other", "or other" there. */
1100.     static NEARDATA const char *const falsematch[] = {
1101.         /* multiple-letter input which matches any of these gets rejected */
1102.         "an", "the", "or", "other", "or other", 0
1103.     };
1104.     /* positive pm_val => specific monster; negative => class */
1105.     static NEARDATA const struct alt_spl truematch[] = {
1106.         /* "long worm" won't match "worm" class but would accidentally match
1107.            "long worm tail" class before the comparison with monster types */
1108.         { "long worm", PM_LONG_WORM, NEUTRAL },
1109.         /* matches wrong--or at least suboptimal--class */
1110.         { "demon", -S_DEMON, NEUTRAL }, /* hits "imp or minor demon" */
1111.         /* matches specific monster (overly restrictive) */
1112.         { "devil", -S_DEMON, NEUTRAL }, /* always "horned devil" */
1113.         /* some plausible guesses which need help */
1114.         { "bug", -S_XAN, NEUTRAL },  /* would match bugbear... */
1115.         { "fish", -S_EEL, NEUTRAL }, /* wouldn't match anything */
1116.         /* end of list */
1117.         { 0, NON_PM, NEUTRAL}
1118.     };
1119.     const char *p, *x;
1120.     int i, len;
1121. 
1122.     if (mndx_p)
1123.         *mndx_p = NON_PM; /* haven't [yet] matched a specific type */
1124. 
1125.     if (!in_str || !in_str[0]) {
1126.         /* empty input */
1127.         return 0;
1128.     } else if (!in_str[1]) {
1129.         /* single character */
1130.         i = def_char_to_monclass(*in_str);
1131.         if (i == S_MIMIC_DEF) { /* ']' -> 'm' */
1132.             i = S_MIMIC;
1133.         } else if (i == S_WORM_TAIL) { /* '~' -> 'w' */
1134.             i = S_WORM;
1135.             if (mndx_p)
1136.                 *mndx_p = PM_LONG_WORM;
1137.         } else if (i == MAXMCLASSES) /* maybe 'I' */
1138.             i = (*in_str == DEF_INVISIBLE) ? S_invisible : 0;
1139.         return i;
1140.     } else {
1141.         /* multiple characters */
1142.         if (!strcmpi(in_str, "long")) /* not enough to match "long worm" */
1143.             return 0; /* avoid false whole-word match with "long worm tail" */
1144.         in_str = makesingular(in_str);
1145.         /* check for special cases */
1146.         for (i = 0; falsematch[i]; i++)
1147.             if (!strcmpi(in_str, falsematch[i]))
1148.                 return 0;
1149.         for (i = 0; truematch[i].name; i++)
1150.             if (!strcmpi(in_str, truematch[i].name)) {
1151.                 i = truematch[i].pm_val;
1152.                 if (i < 0)
1153.                     return -i; /* class */
1154.                 if (mndx_p)
1155.                     *mndx_p = i; /* monster */
1156.                 return mons[i].mlet;
1157.             }
1158.         /* check monster class descriptions */
1159.         len = (int) strlen(in_str);
1160.         for (i = 1; i < MAXMCLASSES; i++) {
1161.             x = def_monsyms[i].explain;
1162.             if ((p = strstri(x, in_str)) != 0 && (p == x || *(p - 1) == ' ')
1163.                 && ((int) strlen(p) >= len
1164.                     && (p[len] == '\0' || p[len] == ' ')))
1165.                 return i;
1166.         }
1167.         /* check individual species names */
1168.         i = name_to_mon(in_str, (int *) 0);
1169.         if (i != NON_PM) {
1170.             if (mndx_p)
1171.                 *mndx_p = i;
1172.             return mons[i].mlet;
1173.         }
1174.     }
1175.     return 0;
1176. }
1177. 
1178. /* returns 3 values (0=male, 1=female, 2=none) */
1179. int
1180. gender(struct monst *mtmp)
1181. {
1182.     if (is_neuter(mtmp->data))
1183.         return 2;
1184.     return mtmp->female;
1185. }
1186. 
1187. /* Like gender(), but unseen humanoids are "it" rather than "he" or "she"
1188.    and lower animals and such are "it" even when seen; hallucination might
1189.    yield "they".  This is the one we want to use when printing messages. */
1190. int
1191. pronoun_gender(
1192.     struct monst *mtmp,
1193.     unsigned pg_flags) /* flags&1: 'no it' unless neuter,
1194.                         * flags&2: random if hallucinating */
1195. {
1196.     boolean override_vis = (pg_flags & PRONOUN_NO_IT) ? TRUE : FALSE,
1197.             hallu_rand = (pg_flags & PRONOUN_HALLU) ? TRUE : FALSE;
1198. 
1199.     if (hallu_rand && Hallucination)
1200.         return rn2(4); /* 0..3 */
1201.     if (!override_vis && !canspotmon(mtmp))
1202.         return 2;
1203.     if (is_neuter(mtmp->data))
1204.         return 2;
1205.     return (humanoid(mtmp->data) || (mtmp->data->geno & G_UNIQ)
1206.             || type_is_pname(mtmp->data)) ? (int) mtmp->female : 2;
1207. }
1208. 
1209. /* used for nearby monsters when you go to another level */
1210. boolean
1211. levl_follower(struct monst *mtmp)
1212. {
1213.     if (mtmp == u.usteed)
1214.         return TRUE;
1215. 
1216.     /* Wizard with Amulet won't bother trying to follow across levels */
1217.     if (mtmp->iswiz && mon_has_amulet(mtmp))
1218.         return FALSE;
1219.     /* some monsters will follow even while intending to flee from you */
1220.     if (mtmp->mtame || mtmp->iswiz || is_fshk(mtmp))
1221.         return TRUE;
1222.     /* stalking types follow, but won't when fleeing unless you hold
1223.        the Amulet */
1224.     return (boolean) ((mtmp->data->mflags2 & M2_STALK)
1225.                       && (!mtmp->mflee || u.uhave.amulet));
1226. }
1227. 
1228. static const short grownups[][2] = {
1229.     { PM_CHICKATRICE, PM_COCKATRICE },
1230.     { PM_LITTLE_DOG, PM_DOG },
1231.     { PM_DOG, PM_LARGE_DOG },
1232.     { PM_HELL_HOUND_PUP, PM_HELL_HOUND },
1233.     { PM_WINTER_WOLF_CUB, PM_WINTER_WOLF },
1234.     { PM_KITTEN, PM_HOUSECAT },
1235.     { PM_HOUSECAT, PM_LARGE_CAT },
1236.     { PM_PONY, PM_HORSE },
1237.     { PM_HORSE, PM_WARHORSE },
1238.     { PM_KOBOLD, PM_LARGE_KOBOLD },
1239.     { PM_LARGE_KOBOLD, PM_KOBOLD_LEADER },
1240.     { PM_GNOME, PM_GNOME_LEADER },
1241.     { PM_GNOME_LEADER, PM_GNOME_RULER },
1242.     { PM_DWARF, PM_DWARF_LEADER },
1243.     { PM_DWARF_LEADER, PM_DWARF_RULER },
1244.     { PM_MIND_FLAYER, PM_MASTER_MIND_FLAYER },
1245.     { PM_ORC, PM_ORC_CAPTAIN },
1246.     { PM_HILL_ORC, PM_ORC_CAPTAIN },
1247.     { PM_MORDOR_ORC, PM_ORC_CAPTAIN },
1248.     { PM_URUK_HAI, PM_ORC_CAPTAIN },
1249.     { PM_SEWER_RAT, PM_GIANT_RAT },
1250.     { PM_CAVE_SPIDER, PM_GIANT_SPIDER },
1251.     { PM_OGRE, PM_OGRE_LEADER },
1252.     { PM_OGRE_LEADER, PM_OGRE_TYRANT },
1253.     { PM_ELF, PM_ELF_NOBLE },
1254.     { PM_WOODLAND_ELF, PM_ELF_NOBLE },
1255.     { PM_GREEN_ELF, PM_ELF_NOBLE },
1256.     { PM_GREY_ELF, PM_ELF_NOBLE },
1257.     { PM_ELF_NOBLE, PM_ELVEN_MONARCH },
1258.     { PM_LICH, PM_DEMILICH },
1259.     { PM_DEMILICH, PM_MASTER_LICH },
1260.     { PM_MASTER_LICH, PM_ARCH_LICH },
1261.     { PM_VAMPIRE, PM_VAMPIRE_LEADER },
1262.     { PM_BAT, PM_GIANT_BAT },
1263.     { PM_BABY_GRAY_DRAGON, PM_GRAY_DRAGON },
1264.     { PM_BABY_GOLD_DRAGON, PM_GOLD_DRAGON },
1265.     { PM_BABY_SILVER_DRAGON, PM_SILVER_DRAGON },
1266. #if 0 /* DEFERRED */
1267.     {PM_BABY_SHIMMERING_DRAGON, PM_SHIMMERING_DRAGON},
1268. #endif
1269.     { PM_BABY_RED_DRAGON, PM_RED_DRAGON },
1270.     { PM_BABY_WHITE_DRAGON, PM_WHITE_DRAGON },
1271.     { PM_BABY_ORANGE_DRAGON, PM_ORANGE_DRAGON },
1272.     { PM_BABY_BLACK_DRAGON, PM_BLACK_DRAGON },
1273.     { PM_BABY_BLUE_DRAGON, PM_BLUE_DRAGON },
1274.     { PM_BABY_GREEN_DRAGON, PM_GREEN_DRAGON },
1275.     { PM_BABY_YELLOW_DRAGON, PM_YELLOW_DRAGON },
1276.     { PM_RED_NAGA_HATCHLING, PM_RED_NAGA },
1277.     { PM_BLACK_NAGA_HATCHLING, PM_BLACK_NAGA },
1278.     { PM_GOLDEN_NAGA_HATCHLING, PM_GOLDEN_NAGA },
1279.     { PM_GUARDIAN_NAGA_HATCHLING, PM_GUARDIAN_NAGA },
1280.     { PM_SMALL_MIMIC, PM_LARGE_MIMIC },
1281.     { PM_LARGE_MIMIC, PM_GIANT_MIMIC },
1282.     { PM_BABY_LONG_WORM, PM_LONG_WORM },
1283.     { PM_BABY_PURPLE_WORM, PM_PURPLE_WORM },
1284.     { PM_BABY_CROCODILE, PM_CROCODILE },
1285.     { PM_SOLDIER, PM_SERGEANT },
1286.     { PM_SERGEANT, PM_LIEUTENANT },
1287.     { PM_LIEUTENANT, PM_CAPTAIN },
1288.     { PM_WATCHMAN, PM_WATCH_CAPTAIN },
1289.     { PM_ALIGNED_CLERIC, PM_HIGH_CLERIC },
1290.     { PM_STUDENT, PM_ARCHEOLOGIST },
1291.     { PM_ATTENDANT, PM_HEALER },
1292.     { PM_PAGE, PM_KNIGHT },
1293.     { PM_ACOLYTE, PM_CLERIC },
1294.     { PM_APPRENTICE, PM_WIZARD },
1295.     { PM_MANES, PM_LEMURE },
1296.     { PM_KEYSTONE_KOP, PM_KOP_SERGEANT },
1297.     { PM_KOP_SERGEANT, PM_KOP_LIEUTENANT },
1298.     { PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN },
1299.     { NON_PM, NON_PM }
1300. };
1301. 
1302. int
1303. little_to_big(int montype)
1304. {
1305.     int i;
1306. 
1307.     for (i = 0; grownups[i][0] >= LOW_PM; i++)
1308.         if (montype == grownups[i][0]) {
1309.             montype = grownups[i][1];
1310.             break;
1311.         }
1312.     return montype;
1313. }
1314. 
1315. int
1316. big_to_little(int montype)
1317. {
1318.     int i;
1319. 
1320.     for (i = 0; grownups[i][0] >= LOW_PM; i++)
1321.         if (montype == grownups[i][1]) {
1322.             montype = grownups[i][0];
1323.             break;
1324.         }
1325.     return montype;
1326. }
1327. 
1328. /* determine whether two permonst indices are part of the same progression;
1329.    existence of progressions with more than one step makes it a bit tricky */
1330. boolean
1331. big_little_match(int montyp1, int montyp2)
1332. {
1333.     int l, b;
1334. 
1335.     /* simplest case: both are same pm */
1336.     if (montyp1 == montyp2)
1337.         return TRUE;
1338.     /* assume it isn't possible to grow from one class letter to another */
1339.     if (mons[montyp1].mlet != mons[montyp2].mlet)
1340.         return FALSE;
1341.     /* check whether montyp1 can grow up into montyp2 */
1342.     for (l = montyp1; (b = little_to_big(l)) != l; l = b)
1343.         if (b == montyp2)
1344.             return TRUE;
1345.     /* check whether montyp2 can grow up into montyp1 */
1346.     for (l = montyp2; (b = little_to_big(l)) != l; l = b)
1347.         if (b == montyp1)
1348.             return TRUE;
1349.     /* neither grows up to become the other; no match */
1350.     return FALSE;
1351. }
1352. 
1353. /*
1354.  * Return the permonst ptr for the race of the monster.
1355.  * Returns correct pointer for non-polymorphed and polymorphed
1356.  * player.  It does not return a pointer to player role character.
1357.  */
1358. const struct permonst *
1359. raceptr(struct monst *mtmp)
1360. {
1361.     if (mtmp == &gy.youmonst && !Upolyd)
1362.         return &mons[gu.urace.mnum];
1363.     return mtmp->data;
1364. }
1365. 
1366. typedef const char *const locoverbs[4];
1367. static locoverbs levitate = { "float", "Float", "wobble", "Wobble" },
1368.                  flys = { "fly", "Fly", "flutter", "Flutter" },
1369.                  flyl = { "fly", "Fly", "stagger", "Stagger" },
1370.                  slither = { "slither", "Slither", "falter", "Falter" },
1371.                  /* it would be useful to incorporate "swim" but we lack
1372.                   * sufficient information to know whether water is involved
1373.                  swim = { "swim", "Swim", "flop", "Flop" },
1374.                   */
1375.                  ooze = { "ooze", "Ooze", "tremble", "Tremble" },
1376.                  immobile = { "wiggle", "Wiggle", "pulsate", "Pulsate" },
1377.                  crawl = { "crawl", "Crawl", "falter", "Falter" };
1378. 
1379. const char *
1380. locomotion(const struct permonst *ptr, const char *def)
1381. {
1382.     int locoindx = (*def != highc(*def)) ? 0 : 1;
1383. 
1384.     return (is_floater(ptr) ? levitate[locoindx]
1385.             : (is_flyer(ptr) && ptr->msize <= MZ_SMALL) ? flys[locoindx]
1386.               : (is_flyer(ptr) && ptr->msize > MZ_SMALL) ? flyl[locoindx]
1387.                 : slithy(ptr) ? slither[locoindx]
1388.                   : amorphous(ptr) ? ooze[locoindx]
1389.                     : !ptr->mmove ? immobile[locoindx]
1390.                       : nolimbs(ptr) ? crawl[locoindx]
1391.                         : def);
1392. }
1393. 
1394. const char *
1395. stagger(const struct permonst *ptr, const char *def)
1396. {
1397.     int locoindx = (*def != highc(*def)) ? 2 : 3;
1398. 
1399.     return (is_floater(ptr) ? levitate[locoindx]
1400.             : (is_flyer(ptr) && ptr->msize <= MZ_SMALL) ? flys[locoindx]
1401.               : (is_flyer(ptr) && ptr->msize > MZ_SMALL) ? flyl[locoindx]
1402.                 : slithy(ptr) ? slither[locoindx]
1403.                   : amorphous(ptr) ? ooze[locoindx]
1404.                     : !ptr->mmove ? immobile[locoindx]
1405.                       : nolimbs(ptr) ? crawl[locoindx]
1406.                         : def);
1407. }
1408. 
1409. /* return phrase describing the effect of fire attack on a type of monster */
1410. const char *
1411. on_fire(struct permonst *mptr, struct attack *mattk)
1412. {
1413.     const char *what;
1414. 
1415.     switch (monsndx(mptr)) {
1416.     case PM_FLAMING_SPHERE:
1417.     case PM_FIRE_VORTEX:
1418.     case PM_FIRE_ELEMENTAL:
1419.     case PM_SALAMANDER:
1420.         what = "already on fire";
1421.         break;
1422.     case PM_WATER_ELEMENTAL:
1423.     case PM_FOG_CLOUD:
1424.     case PM_STEAM_VORTEX:
1425.         what = "boiling";
1426.         break;
1427.     case PM_ICE_VORTEX:
1428.     case PM_GLASS_GOLEM:
1429.         what = "melting";
1430.         break;
1431.     case PM_STONE_GOLEM:
1432.     case PM_CLAY_GOLEM:
1433.     case PM_GOLD_GOLEM:
1434.     case PM_AIR_ELEMENTAL:
1435.     case PM_EARTH_ELEMENTAL:
1436.     case PM_DUST_VORTEX:
1437.     case PM_ENERGY_VORTEX:
1438.         what = "heating up";
1439.         break;
1440.     default:
1441.         what = (mattk->aatyp == AT_HUGS) ? "being roasted" : "on fire";
1442.         break;
1443.     }
1444.     return what;
1445. }
1446. 
1447. /* similar to on_fire(); creature is summoned in a cloud of <something> */
1448. const char *
1449. msummon_environ(struct permonst *mptr, const char **cloud)
1450. {
1451.     const char *what;
1452.     int mndx = ((mptr->mlet == S_ANGEL) ? PM_ANGEL
1453.                 : (mptr->mlet == S_LIGHT) ? PM_YELLOW_LIGHT
1454.                   : monsndx(mptr));
1455. 
1456.     *cloud = "cloud"; /* default is "cloud of <something>" */
1457.     switch (mndx) {
1458.     case PM_WATER_DEMON:
1459.     case PM_AIR_ELEMENTAL:
1460.     case PM_WATER_ELEMENTAL:
1461.     case PM_FOG_CLOUD:
1462.     case PM_ICE_VORTEX:
1463.     case PM_FREEZING_SPHERE:
1464.         what = "vapor";
1465.         break;
1466.     case PM_STEAM_VORTEX:
1467.         what = "steam";
1468.         break;
1469.     case PM_ENERGY_VORTEX:
1470.     case PM_SHOCKING_SPHERE:
1471.         *cloud = "shower"; /* "shower of sparks" instead of "cloud of..." */
1472.         what = "sparks";
1473.         break;
1474.     case PM_EARTH_ELEMENTAL:
1475.     case PM_DUST_VORTEX:
1476.         what = "dust";
1477.         break;
1478.     case PM_FIRE_ELEMENTAL:
1479.     case PM_FIRE_VORTEX:
1480.     case PM_FLAMING_SPHERE:
1481.     /*case PM_SALAMANDER:*/
1482.         *cloud = "ball"; /* "ball of flame" instead of "cloud of..." */
1483.         what = "flame";
1484.         break;
1485.     case PM_ANGEL: /* actually any 'A'-class */
1486.     case PM_YELLOW_LIGHT: /* any 'y'-class */
1487.         *cloud = "flash"; /* "flash of light" instead of "cloud of..." */
1488.         what = "light";
1489.         break;
1490.     default:
1491.         what = "smoke";
1492.         break;
1493.     }
1494.     return what;
1495. }
1496. 
1497. /*
1498.  * Returns:
1499.  *      True if monster is presumed to have a sense of smell.
1500.  *      False if monster definitely does not have a sense of smell.
1501.  *
1502.  * Do not base this on presence of a head or nose, since many
1503.  * creatures sense smells other ways (feelers, forked-tongues, etc).
1504.  * We're assuming all insects can smell at a distance too.
1505.  */
1506. boolean
1507. olfaction(struct permonst *mdat)
1508. {
1509.     if (is_golem(mdat)
1510.         || mdat->mlet == S_EYE /* spheres  */
1511.         || mdat->mlet == S_JELLY || mdat->mlet == S_PUDDING
1512.         || mdat->mlet == S_BLOB || mdat->mlet == S_VORTEX
1513.         || mdat->mlet == S_ELEMENTAL
1514.         || mdat->mlet == S_FUNGUS /* mushrooms and fungi */
1515.         || mdat->mlet == S_LIGHT)
1516.         return FALSE;
1517.     return TRUE;
1518. }
1519. 
1520. /* Convert attack damage type AD_foo to M_SEEN_bar */
1521. unsigned long
1522. cvt_adtyp_to_mseenres(uchar adtyp)
1523. {
1524.     switch (adtyp) {
1525.     case AD_MAGM: return M_SEEN_MAGR;
1526.     case AD_FIRE: return M_SEEN_FIRE;
1527.     case AD_COLD: return M_SEEN_COLD;
1528.     case AD_SLEE: return M_SEEN_SLEEP;
1529.     case AD_DISN: return M_SEEN_DISINT;
1530.     case AD_ELEC: return M_SEEN_ELEC;
1531.     case AD_DRST: return M_SEEN_POISON;
1532.     case AD_ACID: return M_SEEN_ACID;
1533.     /* M_SEEN_REFL has no corresponding AD_foo type */
1534.     default: return M_SEEN_NOTHING;
1535.     }
1536. }
1537. 
1538. /* Convert property resistance to M_SEEN_bar */
1539. unsigned long
1540. cvt_prop_to_mseenres(uchar prop)
1541. {
1542.     switch (prop) {
1543.     case ANTIMAGIC: return M_SEEN_MAGR;
1544.     case FIRE_RES: return M_SEEN_FIRE;
1545.     case COLD_RES: return M_SEEN_COLD;
1546.     case SLEEP_RES: return M_SEEN_SLEEP;
1547.     case DISINT_RES: return M_SEEN_DISINT;
1548.     case POISON_RES: return M_SEEN_POISON;
1549.     case SHOCK_RES: return M_SEEN_ELEC;
1550.     case ACID_RES: return M_SEEN_ACID;
1551.     case REFLECTING: return M_SEEN_REFL;
1552.     default: return M_SEEN_NOTHING;
1553.     }
1554. }
1555. 
1556. /* Monsters in line of sight remember hero resisting effect M_SEEN_foo */
1557. void
1558. monstseesu(unsigned long seenres)
1559. {
1560.     struct monst *mtmp;
1561. 
1562.     if (seenres == M_SEEN_NOTHING || u.uswallow)
1563.         return;
1564. 
1565.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1566.         if (!DEADMONSTER(mtmp) && m_canseeu(mtmp))
1567.             m_setseenres(mtmp, seenres);
1568. }
1569. 
1570. /* Monsters in line of sight forget hero resistance to M_SEEN_foo */
1571. void
1572. monstunseesu(unsigned long seenres)
1573. {
1574.     struct monst *mtmp;
1575. 
1576.     if (seenres == M_SEEN_NOTHING || u.uswallow)
1577.         return;
1578. 
1579.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1580.         if (!DEADMONSTER(mtmp) && m_canseeu(mtmp))
1581.             m_clearseenres(mtmp, seenres);
1582. }
1583. 
1584. /* give monster mtmp the same intrinsics hero has */
1585. void
1586. give_u_to_m_resistances(struct monst *mtmp)
1587. {
1588.     int intr;
1589. 
1590.     /* convert the hero's current set of intrinsics to their monster
1591.        equivalents -- FIRE_RES to MR_FIRE, COLD_RES to MR_COLD, etc -- and
1592.        add each to the mintrinsics field for the given monster */
1593.     for (intr = FIRE_RES; intr <= STONE_RES; intr++) {
1594.         if ((u.uprops[intr].intrinsic & INTRINSIC) != 0L) {
1595.             mtmp->mintrinsics |= (unsigned short) res_to_mr(intr);
1596.         }
1597.     }
1598. }
1599. 
1600. /* Can monster resist conflict caused by hero?
1601. 
1602.    High-CHA heroes will be able to 'convince' monsters
1603.    (through the magic of the ring, of course) to fight
1604.    for them much more easily than low-CHA ones.
1605. */
1606. boolean
1607. resist_conflict(struct monst *mtmp)
1608. {
1609.     /* always a small chance at 19 */
1610.     int resist_chance = min(19, (ACURR(A_CHA) - mtmp->m_lev + u.ulevel));
1611. 
1612.     return (rnd(20) > resist_chance);
1613. }
1614. 
1615. /* does monster mtmp know traps of type ttyp */
1616. boolean
1617. mon_knows_traps(struct monst *mtmp, int ttyp)
1618. {
1619.     if (ttyp == ALL_TRAPS)
1620.         return (boolean)(mtmp->mtrapseen);
1621.     else if (ttyp == NO_TRAP)
1622.         return !(boolean)(mtmp->mtrapseen);
1623.     else
1624.         return ((mtmp->mtrapseen & (1L << (ttyp - 1))) != 0);
1625. }
1626. 
1627. /* monster mtmp learns all traps of type ttyp */
1628. void
1629. mon_learns_traps(struct monst *mtmp, int ttyp)
1630. {
1631.     if (ttyp == ALL_TRAPS)
1632.         mtmp->mtrapseen = ~0L;
1633.     else if (ttyp == NO_TRAP)
1634.         mtmp->mtrapseen = 0L;
1635.     else
1636.         mtmp->mtrapseen |= (1L << (ttyp - 1));
1637. }
1638. 
1639. /* monsters see a trap trigger, and remember it */
1640. void
1641. mons_see_trap(struct trap *ttmp)
1642. {
1643.     struct monst *mtmp;
1644.     coordxy tx = ttmp->tx, ty = ttmp->ty;
1645.     int maxdist = levl[tx][ty].lit ? 7*7 : 2;
1646. 
1647.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
1648.         if (is_animal(mtmp->data) || mindless(mtmp->data)
1649.             || !haseyes(mtmp->data) || !mtmp->mcansee)
1650.             continue;
1651.         if (dist2(mtmp->mx, mtmp->my, tx, ty) > maxdist)
1652.             continue;
1653.         if (!m_cansee(mtmp, tx, ty))
1654.             continue;
1655.         mon_learns_traps(mtmp, ttmp->ttyp);
1656.     }
1657. }
1658. 
1659. int
1660. get_atkdam_type(int adtyp)
1661. {
1662.     if (adtyp == AD_RBRE) {
1663.         static const int rnd_breath_typ[] = {
1664.             AD_MAGM, AD_FIRE, AD_COLD, AD_SLEE,
1665.             AD_DISN, AD_ELEC, AD_DRST, AD_ACID };
1666.         return ROLL_FROM(rnd_breath_typ);
1667.     }
1668.     return adtyp;
1669. }
1670. 
1671. /*mondata.c*/