OSDN Git Service

upgrade to 3.6.1
[jnethack/source.git] / src / mon.c
1 /* NetHack 3.6  mon.c   $NHDT-Date: 1522540516 2018/03/31 23:55:16 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.250 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Derek S. Ray, 2015. */
4 /* NetHack may be freely redistributed.  See license for details. */
5
6 /* JNetHack Copyright */
7 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
8 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016            */
9 /* JNetHack may be freely redistributed.  See license for details. */
10
11 /* If you're using precompiled headers, you don't want this either */
12 #ifdef MICROPORT_BUG
13 #define MKROOM_H
14 #endif
15
16 #include "hack.h"
17 #include "mfndpos.h"
18 #include <ctype.h>
19
20 STATIC_VAR boolean vamp_rise_msg, disintegested;
21
22 STATIC_DCL void FDECL(sanity_check_single_mon, (struct monst *, BOOLEAN_P,
23                                                 const char *));
24 STATIC_DCL boolean FDECL(restrap, (struct monst *));
25 STATIC_DCL long FDECL(mm_aggression, (struct monst *, struct monst *));
26 STATIC_DCL long FDECL(mm_displacement, (struct monst *, struct monst *));
27 STATIC_DCL int NDECL(pick_animal);
28 STATIC_DCL void FDECL(kill_eggs, (struct obj *));
29 STATIC_DCL int FDECL(pickvampshape, (struct monst *));
30 STATIC_DCL boolean FDECL(isspecmon, (struct monst *));
31 STATIC_DCL boolean FDECL(validspecmon, (struct monst *, int));
32 STATIC_DCL struct permonst *FDECL(accept_newcham_form, (int));
33 STATIC_DCL struct obj *FDECL(make_corpse, (struct monst *, unsigned));
34 STATIC_DCL void FDECL(m_detach, (struct monst *, struct permonst *));
35 STATIC_DCL void FDECL(lifesaved_monster, (struct monst *));
36
37 #define LEVEL_SPECIFIC_NOCORPSE(mdat) \
38     (Is_rogue_level(&u.uz)            \
39      || (level.flags.graveyard && is_undead(mdat) && rn2(3)))
40
41 #if 0
42 /* part of the original warning code which was replaced in 3.3.1 */
43 const char *warnings[] = {
44 /*JP
45     "white", "pink", "red", "ruby", "purple", "black"
46 */
47     "\94\92\82¢", "\83s\83\93\83N\90F\82Ì", "\90Ô\82¢", "\83\8b\83r\81[\90F\82Ì", "\8e\87\82Ì", "\8d\95\82¢"
48 };
49 #endif /* 0 */
50
51
52 void
53 sanity_check_single_mon(mtmp, chk_geno, msg)
54 struct monst *mtmp;
55 boolean chk_geno;
56 const char *msg;
57 {
58     if (DEADMONSTER(mtmp))
59         return;
60     if (mtmp->data < &mons[LOW_PM] || mtmp->data >= &mons[NUMMONS]) {
61         impossible("illegal mon data %s; mnum=%d (%s)",
62                    fmt_ptr((genericptr_t) mtmp->data), mtmp->mnum, msg);
63     } else {
64         int mndx = monsndx(mtmp->data);
65
66         if (mtmp->mnum != mndx) {
67             impossible("monster mnum=%d, monsndx=%d (%s)",
68                        mtmp->mnum, mndx, msg);
69             mtmp->mnum = mndx;
70         }
71         if (chk_geno && (mvitals[mndx].mvflags & G_GENOD) != 0)
72             impossible("genocided %s in play (%s)", mons[mndx].mname, msg);
73     }
74     if (mtmp->isshk && !has_eshk(mtmp))
75         impossible("shk without eshk (%s)", msg);
76     if (mtmp->ispriest && !has_epri(mtmp))
77         impossible("priest without epri (%s)", msg);
78     if (mtmp->isgd && !has_egd(mtmp))
79         impossible("guard without egd (%s)", msg);
80     if (mtmp->isminion && !has_emin(mtmp))
81         impossible("minion without emin (%s)", msg);
82     /* guardian angel on astral level is tame but has emin rather than edog */
83     if (mtmp->mtame && !has_edog(mtmp) && !mtmp->isminion)
84         impossible("pet without edog (%s)", msg);
85 }
86
87 void
88 mon_sanity_check()
89 {
90     int x, y;
91     struct monst *mtmp, *m;
92
93     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
94         sanity_check_single_mon(mtmp, TRUE, "fmon");
95         if (DEADMONSTER(mtmp))
96             continue;
97         x = mtmp->mx, y = mtmp->my;
98         if (!isok(x, y) && !(mtmp->isgd && x == 0 && y == 0)) {
99             impossible("mon (%s) claims to be at <%d,%d>?",
100                        fmt_ptr((genericptr_t) mtmp), x, y);
101         } else if (mtmp == u.usteed) {
102             /* steed is in fmon list but not on the map; its
103                <mx,my> coordinates should match hero's location */
104             if (x != u.ux || y != u.uy)
105                 impossible("steed (%s) claims to be at <%d,%d>?",
106                            fmt_ptr((genericptr_t) mtmp), x, y);
107         } else if (level.monsters[x][y] != mtmp) {
108             impossible("mon (%s) at <%d,%d> is not there!",
109                        fmt_ptr((genericptr_t) mtmp), x, y);
110         } else if (mtmp->wormno) {
111             sanity_check_worm(mtmp);
112         }
113     }
114
115     for (x = 0; x < COLNO; x++)
116         for (y = 0; y < ROWNO; y++)
117             if ((mtmp = level.monsters[x][y]) != 0) {
118                 for (m = fmon; m; m = m->nmon)
119                     if (m == mtmp)
120                         break;
121                 if (!m)
122                     impossible("map mon (%s) at <%d,%d> not in fmon list!",
123                                fmt_ptr((genericptr_t) mtmp), x, y);
124                 else if (mtmp == u.usteed)
125                     impossible("steed (%s) is on the map at <%d,%d>!",
126                                fmt_ptr((genericptr_t) mtmp), x, y);
127                 else if ((mtmp->mx != x || mtmp->my != y)
128                          && mtmp->data != &mons[PM_LONG_WORM])
129                     impossible("map mon (%s) at <%d,%d> is found at <%d,%d>?",
130                                fmt_ptr((genericptr_t) mtmp),
131                                mtmp->mx, mtmp->my, x, y);
132             }
133
134     for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) {
135         sanity_check_single_mon(mtmp, FALSE, "migr");
136     }
137 }
138
139
140 /* convert the monster index of an undead to its living counterpart */
141 int
142 undead_to_corpse(mndx)
143 int mndx;
144 {
145     switch (mndx) {
146     case PM_KOBOLD_ZOMBIE:
147     case PM_KOBOLD_MUMMY:
148         mndx = PM_KOBOLD;
149         break;
150     case PM_DWARF_ZOMBIE:
151     case PM_DWARF_MUMMY:
152         mndx = PM_DWARF;
153         break;
154     case PM_GNOME_ZOMBIE:
155     case PM_GNOME_MUMMY:
156         mndx = PM_GNOME;
157         break;
158     case PM_ORC_ZOMBIE:
159     case PM_ORC_MUMMY:
160         mndx = PM_ORC;
161         break;
162     case PM_ELF_ZOMBIE:
163     case PM_ELF_MUMMY:
164         mndx = PM_ELF;
165         break;
166     case PM_VAMPIRE:
167     case PM_VAMPIRE_LORD:
168 #if 0 /* DEFERRED */
169     case PM_VAMPIRE_MAGE:
170 #endif
171     case PM_HUMAN_ZOMBIE:
172     case PM_HUMAN_MUMMY:
173         mndx = PM_HUMAN;
174         break;
175     case PM_GIANT_ZOMBIE:
176     case PM_GIANT_MUMMY:
177         mndx = PM_GIANT;
178         break;
179     case PM_ETTIN_ZOMBIE:
180     case PM_ETTIN_MUMMY:
181         mndx = PM_ETTIN;
182         break;
183     default:
184         break;
185     }
186     return mndx;
187 }
188
189 /* Convert the monster index of some monsters (such as quest guardians)
190  * to their generic species type.
191  *
192  * Return associated character class monster, rather than species
193  * if mode is 1.
194  */
195 int
196 genus(mndx, mode)
197 int mndx, mode;
198 {
199     switch (mndx) {
200     /* Quest guardians */
201     case PM_STUDENT:
202         mndx = mode ? PM_ARCHEOLOGIST : PM_HUMAN;
203         break;
204     case PM_CHIEFTAIN:
205         mndx = mode ? PM_BARBARIAN : PM_HUMAN;
206         break;
207     case PM_NEANDERTHAL:
208         mndx = mode ? PM_CAVEMAN : PM_HUMAN;
209         break;
210     case PM_ATTENDANT:
211         mndx = mode ? PM_HEALER : PM_HUMAN;
212         break;
213     case PM_PAGE:
214         mndx = mode ? PM_KNIGHT : PM_HUMAN;
215         break;
216     case PM_ABBOT:
217         mndx = mode ? PM_MONK : PM_HUMAN;
218         break;
219     case PM_ACOLYTE:
220         mndx = mode ? PM_PRIEST : PM_HUMAN;
221         break;
222     case PM_HUNTER:
223         mndx = mode ? PM_RANGER : PM_HUMAN;
224         break;
225     case PM_THUG:
226         mndx = mode ? PM_ROGUE : PM_HUMAN;
227         break;
228     case PM_ROSHI:
229         mndx = mode ? PM_SAMURAI : PM_HUMAN;
230         break;
231     case PM_GUIDE:
232         mndx = mode ? PM_TOURIST : PM_HUMAN;
233         break;
234     case PM_APPRENTICE:
235         mndx = mode ? PM_WIZARD : PM_HUMAN;
236         break;
237     case PM_WARRIOR:
238         mndx = mode ? PM_VALKYRIE : PM_HUMAN;
239         break;
240     default:
241         if (mndx >= LOW_PM && mndx < NUMMONS) {
242             struct permonst *ptr = &mons[mndx];
243
244             if (is_human(ptr))
245                 mndx = PM_HUMAN;
246             else if (is_elf(ptr))
247                 mndx = PM_ELF;
248             else if (is_dwarf(ptr))
249                 mndx = PM_DWARF;
250             else if (is_gnome(ptr))
251                 mndx = PM_GNOME;
252             else if (is_orc(ptr))
253                 mndx = PM_ORC;
254         }
255         break;
256     }
257     return mndx;
258 }
259
260 /* return monster index if chameleon, or NON_PM if not */
261 int
262 pm_to_cham(mndx)
263 int mndx;
264 {
265     int mcham = NON_PM;
266
267     /*
268      * As of 3.6.0 we just check M2_SHAPESHIFTER instead of having a
269      * big switch statement with hardcoded shapeshifter types here.
270      */
271     if (mndx >= LOW_PM && is_shapeshifter(&mons[mndx]))
272         mcham = mndx;
273     return mcham;
274 }
275
276 /* for deciding whether corpse will carry along full monster data */
277 #define KEEPTRAITS(mon)                                                 \
278     ((mon)->isshk || (mon)->mtame || unique_corpstat((mon)->data)       \
279      || is_reviver((mon)->data)                                         \
280         /* normally quest leader will be unique, */                     \
281         /* but he or she might have been polymorphed  */                \
282      || (mon)->m_id == quest_status.leader_m_id                         \
283         /* special cancellation handling for these */                   \
284      || (dmgtype((mon)->data, AD_SEDU) || dmgtype((mon)->data, AD_SSEX)))
285
286 /* Creates a monster corpse, a "special" corpse, or nothing if it doesn't
287  * leave corpses.  Monsters which leave "special" corpses should have
288  * G_NOCORPSE set in order to prevent wishing for one, finding tins of one,
289  * etc....
290  */
291 STATIC_OVL struct obj *
292 make_corpse(mtmp, corpseflags)
293 register struct monst *mtmp;
294 unsigned corpseflags;
295 {
296     register struct permonst *mdat = mtmp->data;
297     int num;
298     struct obj *obj = (struct obj *) 0;
299     struct obj *otmp = (struct obj *) 0;
300     int x = mtmp->mx, y = mtmp->my;
301     int mndx = monsndx(mdat);
302     unsigned corpstatflags = corpseflags;
303     boolean burythem = ((corpstatflags & CORPSTAT_BURIED) != 0);
304
305     switch (mndx) {
306     case PM_GRAY_DRAGON:
307     case PM_SILVER_DRAGON:
308 #if 0 /* DEFERRED */
309     case PM_SHIMMERING_DRAGON:
310 #endif
311     case PM_RED_DRAGON:
312     case PM_ORANGE_DRAGON:
313     case PM_WHITE_DRAGON:
314     case PM_BLACK_DRAGON:
315     case PM_BLUE_DRAGON:
316     case PM_GREEN_DRAGON:
317     case PM_YELLOW_DRAGON:
318         /* Make dragon scales.  This assumes that the order of the
319            dragons is the same as the order of the scales. */
320         if (!rn2(mtmp->mrevived ? 20 : 3)) {
321             num = GRAY_DRAGON_SCALES + monsndx(mdat) - PM_GRAY_DRAGON;
322             obj = mksobj_at(num, x, y, FALSE, FALSE);
323             obj->spe = 0;
324             obj->cursed = obj->blessed = FALSE;
325         }
326         goto default_1;
327     case PM_WHITE_UNICORN:
328     case PM_GRAY_UNICORN:
329     case PM_BLACK_UNICORN:
330         if (mtmp->mrevived && rn2(2)) {
331             if (canseemon(mtmp))
332 #if 0 /*JP*/
333                 pline("%s recently regrown horn crumbles to dust.",
334                       s_suffix(Monnam(mtmp)));
335 #else
336                 pline("\8dÅ\8bß\8dÄ\90\82µ\82½%s\82Ì\8ap\82Í\95²\81X\82É\82È\82Á\82½\81D",
337                       Monnam(mtmp));
338 #endif
339         } else {
340             obj = mksobj_at(UNICORN_HORN, x, y, TRUE, FALSE);
341             if (obj && mtmp->mrevived)
342                 obj->degraded_horn = 1;
343         }
344         goto default_1;
345     case PM_LONG_WORM:
346         (void) mksobj_at(WORM_TOOTH, x, y, TRUE, FALSE);
347         goto default_1;
348     case PM_VAMPIRE:
349     case PM_VAMPIRE_LORD:
350         /* include mtmp in the mkcorpstat() call */
351         num = undead_to_corpse(mndx);
352         corpstatflags |= CORPSTAT_INIT;
353         obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
354         obj->age -= 100; /* this is an *OLD* corpse */
355         break;
356     case PM_KOBOLD_MUMMY:
357     case PM_DWARF_MUMMY:
358     case PM_GNOME_MUMMY:
359     case PM_ORC_MUMMY:
360     case PM_ELF_MUMMY:
361     case PM_HUMAN_MUMMY:
362     case PM_GIANT_MUMMY:
363     case PM_ETTIN_MUMMY:
364     case PM_KOBOLD_ZOMBIE:
365     case PM_DWARF_ZOMBIE:
366     case PM_GNOME_ZOMBIE:
367     case PM_ORC_ZOMBIE:
368     case PM_ELF_ZOMBIE:
369     case PM_HUMAN_ZOMBIE:
370     case PM_GIANT_ZOMBIE:
371     case PM_ETTIN_ZOMBIE:
372         num = undead_to_corpse(mndx);
373         corpstatflags |= CORPSTAT_INIT;
374         obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
375         obj->age -= 100; /* this is an *OLD* corpse */
376         break;
377     case PM_IRON_GOLEM:
378         num = d(2, 6);
379         while (num--)
380             obj = mksobj_at(IRON_CHAIN, x, y, TRUE, FALSE);
381         free_mname(mtmp); /* don't christen obj */
382         break;
383     case PM_GLASS_GOLEM:
384         num = d(2, 4); /* very low chance of creating all glass gems */
385         while (num--)
386             obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE);
387         free_mname(mtmp);
388         break;
389     case PM_CLAY_GOLEM:
390         obj = mksobj_at(ROCK, x, y, FALSE, FALSE);
391         obj->quan = (long) (rn2(20) + 50);
392         obj->owt = weight(obj);
393         free_mname(mtmp);
394         break;
395     case PM_STONE_GOLEM:
396         corpstatflags &= ~CORPSTAT_INIT;
397         obj =
398             mkcorpstat(STATUE, (struct monst *) 0, mdat, x, y, corpstatflags);
399         break;
400     case PM_WOOD_GOLEM:
401         num = d(2, 4);
402         while (num--) {
403             obj = mksobj_at(QUARTERSTAFF, x, y, TRUE, FALSE);
404         }
405         free_mname(mtmp);
406         break;
407     case PM_LEATHER_GOLEM:
408         num = d(2, 4);
409         while (num--)
410             obj = mksobj_at(LEATHER_ARMOR, x, y, TRUE, FALSE);
411         free_mname(mtmp);
412         break;
413     case PM_GOLD_GOLEM:
414         /* Good luck gives more coins */
415         obj = mkgold((long) (200 - rnl(101)), x, y);
416         free_mname(mtmp);
417         break;
418     case PM_PAPER_GOLEM:
419         num = rnd(4);
420         while (num--)
421             obj = mksobj_at(SCR_BLANK_PAPER, x, y, TRUE, FALSE);
422         free_mname(mtmp);
423         break;
424     /* expired puddings will congeal into a large blob;
425        like dragons, relies on the order remaining consistent */
426     case PM_GRAY_OOZE:
427     case PM_BROWN_PUDDING:
428     case PM_GREEN_SLIME:
429     case PM_BLACK_PUDDING:
430         /* we have to do this here because most other places
431            expect there to be an object coming back; not this one */
432         obj = mksobj_at(GLOB_OF_BLACK_PUDDING - (PM_BLACK_PUDDING - mndx),
433                         x, y, TRUE, FALSE);
434
435         while (obj && (otmp = obj_nexto(obj)) != (struct obj *) 0) {
436             pudding_merge_message(obj, otmp);
437             obj = obj_meld(&obj, &otmp);
438         }
439         free_mname(mtmp);
440         return obj;
441     default_1:
442     default:
443         if (mvitals[mndx].mvflags & G_NOCORPSE) {
444             return (struct obj *) 0;
445         } else {
446             corpstatflags |= CORPSTAT_INIT;
447             /* preserve the unique traits of some creatures */
448             obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0,
449                              mdat, x, y, corpstatflags);
450             if (burythem) {
451                 boolean dealloc;
452
453                 (void) bury_an_obj(obj, &dealloc);
454                 newsym(x, y);
455                 return dealloc ? (struct obj *) 0 : obj;
456             }
457         }
458         break;
459     }
460     /* All special cases should precede the G_NOCORPSE check */
461
462     if (!obj) return NULL;
463
464     /* if polymorph or undead turning has killed this monster,
465        prevent the same attack beam from hitting its corpse */
466     if (context.bypasses)
467         bypass_obj(obj);
468
469     if (has_mname(mtmp))
470         obj = oname(obj, MNAME(mtmp));
471
472     /*  Avoid "It was hidden under a green mold corpse!"
473      *  during Blind combat. An unseen monster referred to as "it"
474      *  could be killed and leave a corpse.  If a hider then hid
475      *  underneath it, you could be told the corpse type of a
476      *  monster that you never knew was there without this.
477      *  The code in hitmu() substitutes the word "something"
478      *  if the corpses obj->dknown is 0.
479      */
480     if (Blind && !sensemon(mtmp))
481         obj->dknown = 0;
482
483     stackobj(obj);
484     newsym(x, y);
485     return obj;
486 }
487
488 /* check mtmp and water/lava for compatibility, 0 (survived), 1 (died) */
489 int
490 minliquid(mtmp)
491 register struct monst *mtmp;
492 {
493     boolean inpool, inlava, infountain;
494
495     /* [what about ceiling clingers?] */
496     inpool = (is_pool(mtmp->mx, mtmp->my)
497               && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
498     inlava = (is_lava(mtmp->mx, mtmp->my)
499               && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
500     infountain = IS_FOUNTAIN(levl[mtmp->mx][mtmp->my].typ);
501
502     /* Flying and levitation keeps our steed out of the liquid */
503     /* (but not water-walking or swimming) */
504     if (mtmp == u.usteed && (Flying || Levitation))
505         return 0;
506
507     /* Gremlin multiplying won't go on forever since the hit points
508      * keep going down, and when it gets to 1 hit point the clone
509      * function will fail.
510      */
511     if (mtmp->data == &mons[PM_GREMLIN] && (inpool || infountain) && rn2(3)) {
512         if (split_mon(mtmp, (struct monst *) 0))
513             dryup(mtmp->mx, mtmp->my, FALSE);
514         if (inpool)
515             water_damage_chain(mtmp->minvent, FALSE);
516         return 0;
517     } else if (mtmp->data == &mons[PM_IRON_GOLEM] && inpool && !rn2(5)) {
518         int dam = d(2, 6);
519
520         if (cansee(mtmp->mx, mtmp->my))
521 /*JP
522             pline("%s rusts.", Monnam(mtmp));
523 */
524             pline("%s\82Í\8eK\82Ñ\82½\81D", Monnam(mtmp));
525         mtmp->mhp -= dam;
526         if (mtmp->mhpmax > dam)
527             mtmp->mhpmax -= dam;
528         if (mtmp->mhp < 1) {
529             mondead(mtmp);
530             if (mtmp->mhp < 1)
531                 return 1;
532         }
533         water_damage_chain(mtmp->minvent, FALSE);
534         return 0;
535     }
536
537     if (inlava) {
538         /*
539          * Lava effects much as water effects. Lava likers are able to
540          * protect their stuff. Fire resistant monsters can only protect
541          * themselves  --ALI
542          */
543         if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) {
544             if (!resists_fire(mtmp)) {
545                 if (cansee(mtmp->mx, mtmp->my)) {
546                     struct attack *dummy = &mtmp->data->mattk[0];
547                     const char *how = on_fire(mtmp->data, dummy);
548
549 #if 0 /*JP*/
550                     pline("%s %s.", Monnam(mtmp),
551                           !strcmp(how, "boiling") ? "boils away"
552                              : !strcmp(how, "melting") ? "melts away"
553                                 : "burns to a crisp");
554 #else /*mon.c:on_fire()\82Ì\95Ô\82è\92l*/
555                     pline("%s\82Í%s\82½\81D", Monnam(mtmp),
556                           !strcmp(how, "\95¦\93«\82µ\82½") ? "\95¦\93«\82µ"
557                              : !strcmp(how, "\97n\82¯\82½") ? "\97n\82¯\82½"
558                                 : "\94R\82¦\82Ä\83p\83\8a\83p\83\8a\82É\82È\82Á");
559 #endif
560                 }
561                 mondead(mtmp);
562             } else {
563                 mtmp->mhp -= 1;
564                 if (mtmp->mhp < 1) {
565                     if (cansee(mtmp->mx, mtmp->my))
566 /*JP
567                         pline("%s surrenders to the fire.", Monnam(mtmp));
568 */
569                         pline("%s\82Í\89\8a\82É\93Û\82Ü\82ê\82½\81D", Monnam(mtmp));
570                     mondead(mtmp);
571                 } else if (cansee(mtmp->mx, mtmp->my))
572 /*JP
573                     pline("%s burns slightly.", Monnam(mtmp));
574 */
575                     pline("%s\82Í\82¿\82å\82Á\82Æ\8fÅ\82°\82½\81D", Monnam(mtmp));
576             }
577             if (mtmp->mhp > 0) {
578                 (void) fire_damage_chain(mtmp->minvent, FALSE, FALSE,
579                                          mtmp->mx, mtmp->my);
580                 (void) rloc(mtmp, FALSE);
581                 return 0;
582             }
583             return 1;
584         }
585     } else if (inpool) {
586         /* Most monsters drown in pools.  flooreffects() will take care of
587          * water damage to dead monsters' inventory, but survivors need to
588          * be handled here.  Swimmers are able to protect their stuff...
589          */
590         if (!is_clinger(mtmp->data) && !is_swimmer(mtmp->data)
591             && !amphibious(mtmp->data)) {
592             if (cansee(mtmp->mx, mtmp->my)) {
593 /*JP
594                 pline("%s drowns.", Monnam(mtmp));
595 */
596                 pline("%s\82Í\93M\82ê\82½\81D", Monnam(mtmp));
597             }
598             if (u.ustuck && u.uswallow && u.ustuck == mtmp) {
599                 /* This can happen after a purple worm plucks you off a
600                 flying steed while you are over water. */
601 #if 0 /*JP*/
602                 pline("%s sinks as %s rushes in and flushes you out.",
603                       Monnam(mtmp), hliquid("water"));
604 #else /*hliquid\82Í\95s\8e©\91R\82É\82È\82é\82Ì\82Å\82Æ\82è\82 \82¦\82¸\8eg\82í\82È\82¢*/
605                 pline("%s\82Í\90\85\97¬\82É\92¾\82Ý\81D\82 \82È\82½\82ð\93f\82«\8fo\82µ\82½\81D",
606                       Monnam(mtmp));
607 #endif
608             }
609             mondead(mtmp);
610             if (mtmp->mhp > 0) {
611                 water_damage_chain(mtmp->minvent, FALSE);
612                 (void) rloc(mtmp, FALSE);
613                 return 0;
614             }
615             return 1;
616         }
617     } else {
618         /* but eels have a difficult time outside */
619         if (mtmp->data->mlet == S_EEL && !Is_waterlevel(&u.uz)) {
620             /* as mhp gets lower, the rate of further loss slows down */
621             if (mtmp->mhp > 1 && rn2(mtmp->mhp) > rn2(8))
622                 mtmp->mhp--;
623             monflee(mtmp, 2, FALSE, FALSE);
624         }
625     }
626     return 0;
627 }
628
629 int
630 mcalcmove(mon)
631 struct monst *mon;
632 {
633     int mmove = mon->data->mmove;
634     int mmove_adj;
635
636     /* Note: MSLOW's `+ 1' prevents slowed speed 1 getting reduced to 0;
637      *       MFAST's `+ 2' prevents hasted speed 1 from becoming a no-op;
638      *       both adjustments have negligible effect on higher speeds.
639      */
640     if (mon->mspeed == MSLOW)
641         mmove = (2 * mmove + 1) / 3;
642     else if (mon->mspeed == MFAST)
643         mmove = (4 * mmove + 2) / 3;
644
645     if (mon == u.usteed && u.ugallop && context.mv) {
646         /* increase movement by a factor of 1.5; also increase variance of
647            movement speed (if it's naturally 24, we don't want it to always
648            become 36) */
649         mmove = ((rn2(2) ? 4 : 5) * mmove) / 3;
650     }
651
652     /* Randomly round the monster's speed to a multiple of NORMAL_SPEED. This
653        makes it impossible for the player to predict when they'll get a free
654        turn (thus preventing exploits like "melee kiting"), while retaining
655        guarantees about shopkeepers not being outsped by a normal-speed player,
656        normal-speed players being unable to open up a gap when fleeing a
657        normal-speed monster, etc.*/
658     mmove_adj = mmove % NORMAL_SPEED;
659     mmove -= mmove_adj;
660     if (rn2(NORMAL_SPEED) < mmove_adj)
661         mmove += NORMAL_SPEED;
662
663     return mmove;
664 }
665
666 /* actions that happen once per ``turn'', regardless of each
667    individual monster's metabolism; some of these might need to
668    be reclassified to occur more in proportion with movement rate */
669 void
670 mcalcdistress()
671 {
672     struct monst *mtmp;
673
674     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
675         if (DEADMONSTER(mtmp))
676             continue;
677
678         /* must check non-moving monsters once/turn in case
679          * they managed to end up in liquid */
680         if (mtmp->data->mmove == 0) {
681             if (vision_full_recalc)
682                 vision_recalc(0);
683             if (minliquid(mtmp))
684                 continue;
685         }
686
687         /* regenerate hit points */
688         mon_regen(mtmp, FALSE);
689
690         /* possibly polymorph shapechangers and lycanthropes */
691         if (mtmp->cham >= LOW_PM)
692             decide_to_shapeshift(mtmp, (canspotmon(mtmp)
693                                         || (u.uswallow && mtmp == u.ustuck))
694                                           ? SHIFT_MSG : 0);
695         were_change(mtmp);
696
697         /* gradually time out temporary problems */
698         if (mtmp->mblinded && !--mtmp->mblinded)
699             mtmp->mcansee = 1;
700         if (mtmp->mfrozen && !--mtmp->mfrozen)
701             mtmp->mcanmove = 1;
702         if (mtmp->mfleetim && !--mtmp->mfleetim)
703             mtmp->mflee = 0;
704
705         /* FIXME: mtmp->mlstmv ought to be updated here */
706     }
707 }
708
709 int
710 movemon()
711 {
712     register struct monst *mtmp, *nmtmp;
713     register boolean somebody_can_move = FALSE;
714
715     /*
716      * Some of you may remember the former assertion here that
717      * because of deaths and other actions, a simple one-pass
718      * algorithm wasn't possible for movemon.  Deaths are no longer
719      * removed to the separate list fdmon; they are simply left in
720      * the chain with hit points <= 0, to be cleaned up at the end
721      * of the pass.
722      *
723      * The only other actions which cause monsters to be removed from
724      * the chain are level migrations and losedogs().  I believe losedogs()
725      * is a cleanup routine not associated with monster movements, and
726      * monsters can only affect level migrations on themselves, not others
727      * (hence the fetching of nmon before moving the monster).  Currently,
728      * monsters can jump into traps, read cursed scrolls of teleportation,
729      * and drink cursed potions of raise level to change levels.  These are
730      * all reflexive at this point.  Should one monster be able to level
731      * teleport another, this scheme would have problems.
732      */
733
734     for (mtmp = fmon; mtmp; mtmp = nmtmp) {
735         /* end monster movement early if hero is flagged to leave the level */
736         if (u.utotype
737 #ifdef SAFERHANGUP
738             /* or if the program has lost contact with the user */
739             || program_state.done_hup
740 #endif
741             ) {
742             somebody_can_move = FALSE;
743             break;
744         }
745         nmtmp = mtmp->nmon;
746         /* one dead monster needs to perform a move after death:
747            vault guard whose temporary corridor is still on the map */
748         if (mtmp->isgd && !mtmp->mx && mtmp->mhp <= 0)
749             (void) gd_move(mtmp);
750         if (DEADMONSTER(mtmp))
751             continue;
752
753         /* Find a monster that we have not treated yet. */
754         if (mtmp->movement < NORMAL_SPEED)
755             continue;
756
757         mtmp->movement -= NORMAL_SPEED;
758         if (mtmp->movement >= NORMAL_SPEED)
759             somebody_can_move = TRUE;
760
761         if (vision_full_recalc)
762             vision_recalc(0); /* vision! */
763
764         /* reset obj bypasses before next monster moves */
765         if (context.bypasses)
766             clear_bypasses();
767         clear_splitobjs();
768         if (minliquid(mtmp))
769             continue;
770
771         if (is_hider(mtmp->data)) {
772             /* unwatched mimics and piercers may hide again  [MRS] */
773             if (restrap(mtmp))
774                 continue;
775             if (mtmp->m_ap_type == M_AP_FURNITURE
776                 || mtmp->m_ap_type == M_AP_OBJECT)
777                 continue;
778             if (mtmp->mundetected)
779                 continue;
780         } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected
781                    && (mtmp->mflee || distu(mtmp->mx, mtmp->my) > 2)
782                    && !canseemon(mtmp) && !rn2(4)) {
783             /* some eels end up stuck in isolated pools, where they
784                can't--or at least won't--move, so they never reach
785                their post-move chance to re-hide */
786             if (hideunder(mtmp))
787                 continue;
788         }
789
790         /* continue if the monster died fighting */
791         if (Conflict && !mtmp->iswiz && mtmp->mcansee) {
792             /* Note:
793              *  Conflict does not take effect in the first round.
794              *  Therefore, A monster when stepping into the area will
795              *  get to swing at you.
796              *
797              *  The call to fightm() must be _last_.  The monster might
798              *  have died if it returns 1.
799              */
800             if (couldsee(mtmp->mx, mtmp->my)
801                 && (distu(mtmp->mx, mtmp->my) <= BOLT_LIM * BOLT_LIM)
802                 && fightm(mtmp))
803                 continue; /* mon might have died */
804         }
805         if (dochugw(mtmp)) /* otherwise just move the monster */
806             continue;
807     }
808
809     if (any_light_source())
810         vision_full_recalc = 1; /* in case a mon moved with a light source */
811     /* reset obj bypasses after last monster has moved */
812     if (context.bypasses)
813         clear_bypasses();
814     clear_splitobjs();
815     /* remove dead monsters; dead vault guard will be left at <0,0>
816        if temporary corridor out of vault hasn't been removed yet */
817     dmonsfree();
818
819     /* a monster may have levteleported player -dlc */
820     if (u.utotype) {
821         deferred_goto();
822         /* changed levels, so these monsters are dormant */
823         somebody_can_move = FALSE;
824     }
825
826     return somebody_can_move;
827 }
828
829 #define mstoning(obj)                                       \
830     (ofood(obj) && (touch_petrifies(&mons[(obj)->corpsenm]) \
831                     || (obj)->corpsenm == PM_MEDUSA))
832
833 /*
834  * Maybe eat a metallic object (not just gold).
835  * Return value: 0 => nothing happened, 1 => monster ate something,
836  * 2 => monster died (it must have grown into a genocided form, but
837  * that can't happen at present because nothing which eats objects
838  * has young and old forms).
839  */
840 int
841 meatmetal(mtmp)
842 register struct monst *mtmp;
843 {
844     register struct obj *otmp;
845     struct permonst *ptr;
846     int poly, grow, heal, mstone;
847
848     /* If a pet, eating is handled separately, in dog.c */
849     if (mtmp->mtame)
850         return 0;
851
852     /* Eats topmost metal object if it is there */
853     for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp;
854          otmp = otmp->nexthere) {
855         /* Don't eat indigestible/choking/inappropriate objects */
856         if ((mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp))
857             || (otmp->otyp == AMULET_OF_STRANGULATION)
858             || (otmp->otyp == RIN_SLOW_DIGESTION))
859             continue;
860         if (is_metallic(otmp) && !obj_resists(otmp, 5, 95)
861             && touch_artifact(otmp, mtmp)) {
862             if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) {
863                 if (canseemon(mtmp) && flags.verbose) {
864 #if 0 /*JP*/
865                     pline("%s eats %s!", Monnam(mtmp),
866                           distant_name(otmp, doname));
867 #else
868                     pline("%s\82Í%s\82ð\90H\82×\82Ä\82¢\82é\81I", Monnam(mtmp),
869                           distant_name(otmp,doname));
870 #endif
871                 }
872                 /* The object's rustproofing is gone now */
873                 otmp->oerodeproof = 0;
874                 mtmp->mstun = 1;
875                 if (canseemon(mtmp) && flags.verbose) {
876 #if 0 /*JP*/
877                     pline("%s spits %s out in disgust!", Monnam(mtmp),
878                           distant_name(otmp, doname));
879 #else
880                     pline("%s\82Í%s\82ð\83y\83b\82Æ\93f\82«\8fo\82µ\82½\81I", Monnam(mtmp),
881                           distant_name(otmp,doname));
882 #endif
883                 }
884             } else {
885                 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
886 #if 0 /*JP*/
887                     pline("%s eats %s!", Monnam(mtmp),
888                           distant_name(otmp, doname));
889 #else
890                     pline("%s\82Í%s\82ð\90H\82×\82Ä\82¢\82é\81I", Monnam(mtmp),
891                           distant_name(otmp,doname));
892 #endif
893                 else if (flags.verbose)
894 /*JP
895                     You_hear("a crunching sound.");
896 */
897                     You_hear("\83o\83\8a\83o\83\8a\82Æ\90H\82×\82é\89¹\82ð\95·\82¢\82½\81D");
898                 mtmp->meating = otmp->owt / 2 + 1;
899                 /* Heal up to the object's weight in hp */
900                 if (mtmp->mhp < mtmp->mhpmax) {
901                     mtmp->mhp += objects[otmp->otyp].oc_weight;
902                     if (mtmp->mhp > mtmp->mhpmax)
903                         mtmp->mhp = mtmp->mhpmax;
904                 }
905                 if (otmp == uball) {
906                     unpunish();
907                     delobj(otmp);
908                 } else if (otmp == uchain) {
909                     unpunish(); /* frees uchain */
910                 } else {
911                     poly = polyfodder(otmp);
912                     grow = mlevelgain(otmp);
913                     heal = mhealup(otmp);
914                     mstone = mstoning(otmp);
915                     delobj(otmp);
916                     ptr = mtmp->data;
917                     if (poly) {
918                         if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
919                             ptr = mtmp->data;
920                     } else if (grow) {
921                         ptr = grow_up(mtmp, (struct monst *) 0);
922                     } else if (mstone) {
923                         if (poly_when_stoned(ptr)) {
924                             mon_to_stone(mtmp);
925                             ptr = mtmp->data;
926                         } else if (!resists_ston(mtmp)) {
927                             if (canseemon(mtmp))
928 /*JP
929                                 pline("%s turns to stone!", Monnam(mtmp));
930 */
931                                 pline("%s\82Í\90Î\82É\82È\82Á\82½\81I", Monnam(mtmp));
932                             monstone(mtmp);
933                             ptr = (struct permonst *) 0;
934                         }
935                     } else if (heal) {
936                         mtmp->mhp = mtmp->mhpmax;
937                     }
938                     if (!ptr)
939                         return 2; /* it died */
940                 }
941                 /* Left behind a pile? */
942                 if (rnd(25) < 3)
943                     (void) mksobj_at(ROCK, mtmp->mx, mtmp->my, TRUE, FALSE);
944                 newsym(mtmp->mx, mtmp->my);
945                 return 1;
946             }
947         }
948     }
949     return 0;
950 }
951
952 /* monster eats a pile of objects */
953 int
954 meatobj(mtmp) /* for gelatinous cubes */
955 struct monst *mtmp;
956 {
957     struct obj *otmp, *otmp2;
958     struct permonst *ptr, *original_ptr = mtmp->data;
959     int poly, grow, heal, eyes, count = 0, ecount = 0;
960     char buf[BUFSZ];
961
962     buf[0] = '\0';
963     /* If a pet, eating is handled separately, in dog.c */
964     if (mtmp->mtame)
965         return 0;
966
967     /* eat organic objects, including cloth and wood, if present;
968        engulf others, except huge rocks and metal attached to player
969        [despite comment at top, doesn't assume that eater is a g.cube] */
970     for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
971         otmp2 = otmp->nexthere;
972
973         /* touch sensitive items */
974         if (otmp->otyp == CORPSE && is_rider(&mons[otmp->corpsenm])) {
975             /* Rider corpse isn't just inedible; can't engulf it either */
976             (void) revive_corpse(otmp);
977
978         /* untouchable (or inaccessible) items */
979         } else if ((otmp->otyp == CORPSE
980                     && touch_petrifies(&mons[otmp->corpsenm])
981                     && !resists_ston(mtmp))
982                    /* don't engulf boulders and statues or ball&chain */
983                    || otmp->oclass == ROCK_CLASS
984                    || otmp == uball || otmp == uchain
985                    /* normally mtmp won't have stepped onto scare monster
986                       scroll, but if it does, don't eat or engulf that
987                       (note: scrolls inside eaten containers will still
988                       become engulfed) */
989                    || otmp->otyp == SCR_SCARE_MONSTER) {
990             /* do nothing--neither eaten nor engulfed */
991             continue;
992
993         /* inedible items -- engulf these */
994         } else if (!is_organic(otmp) || obj_resists(otmp, 5, 95)
995                    || !touch_artifact(otmp, mtmp)
996                    /* redundant due to non-organic composition but
997                       included for emphasis */
998                    || (otmp->otyp == AMULET_OF_STRANGULATION
999                        || otmp->otyp == RIN_SLOW_DIGESTION)
1000                    /* cockatrice corpses handled above; this
1001                       touch_petrifies() check catches eggs */
1002                    || ((otmp->otyp == CORPSE || otmp->otyp == EGG
1003                         || otmp->globby)
1004                        && ((touch_petrifies(&mons[otmp->corpsenm])
1005                             && !resists_ston(mtmp))
1006                            || (otmp->corpsenm == PM_GREEN_SLIME
1007                                && !slimeproof(mtmp->data))))) {
1008             /* engulf */
1009             ++ecount;
1010             if (ecount == 1)
1011 #if 0 /*JP*/
1012                 Sprintf(buf, "%s engulfs %s.", Monnam(mtmp),
1013                         distant_name(otmp, doname));
1014 #else
1015                 Sprintf(buf, "%s\82Í%s\82ð\88ù\82Ý\8d\9e\82ñ\82¾\81D", Monnam(mtmp),
1016                         distant_name(otmp,doname));
1017 #endif
1018             else if (ecount == 2)
1019 /*JP
1020                 Sprintf(buf, "%s engulfs several objects.", Monnam(mtmp));
1021 */
1022                 Sprintf(buf, "%s\82Í\82¢\82­\82Â\82©\82Ì\95¨\82ð\88ù\82Ý\8d\9e\82ñ\82¾\81D", Monnam(mtmp));
1023             obj_extract_self(otmp);
1024             (void) mpickobj(mtmp, otmp); /* slurp */
1025
1026         /* lastly, edible items; yum! */
1027         } else {
1028             /* devour */
1029             ++count;
1030             if (cansee(mtmp->mx, mtmp->my)) {
1031                 if (flags.verbose)
1032 #if 0 /*JP*/
1033                     pline("%s eats %s!", Monnam(mtmp),
1034                           distant_name(otmp, doname));
1035 #else
1036                     pline("%s\82Í%s\82ð\90H\82×\82Ä\82¢\82é\81I", Monnam(mtmp),
1037                           distant_name(otmp, doname));
1038 #endif
1039                 /* give this one even if !verbose */
1040                 if (otmp->oclass == SCROLL_CLASS
1041                     && !strcmpi(OBJ_DESCR(objects[otmp->otyp]), "YUM YUM"))
1042                     pline("Yum%c", otmp->blessed ? '!' : '.');
1043             } else {
1044                 if (flags.verbose)
1045 /*JP
1046                 You_hear("a slurping sound.");
1047 */
1048                 You_hear("\82²\82­\82ñ\82Æ\88ù\82Ý\8d\9e\82Þ\89¹\82ð\95·\82¢\82½\81D");
1049             }
1050             /* Heal up to the object's weight in hp */
1051             if (mtmp->mhp < mtmp->mhpmax) {
1052                 mtmp->mhp += objects[otmp->otyp].oc_weight;
1053                 if (mtmp->mhp > mtmp->mhpmax)
1054                     mtmp->mhp = mtmp->mhpmax;
1055             }
1056             if (Has_contents(otmp)) {
1057                 register struct obj *otmp3;
1058
1059                 /* contents of eaten containers become engulfed; this
1060                    is arbitrary, but otherwise g.cubes are too powerful */
1061                 while ((otmp3 = otmp->cobj) != 0) {
1062                     obj_extract_self(otmp3);
1063                     if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) {
1064                         otmp3->age = monstermoves - otmp3->age;
1065                         start_corpse_timeout(otmp3);
1066                     }
1067                     (void) mpickobj(mtmp, otmp3);
1068                 }
1069             }
1070             poly = polyfodder(otmp);
1071             grow = mlevelgain(otmp);
1072             heal = mhealup(otmp);
1073             eyes = (otmp->otyp == CARROT);
1074             delobj(otmp); /* munch */
1075             ptr = mtmp->data;
1076             if (poly) {
1077                 if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
1078                     ptr = mtmp->data;
1079             } else if (grow) {
1080                 ptr = grow_up(mtmp, (struct monst *) 0);
1081             } else if (heal) {
1082                 mtmp->mhp = mtmp->mhpmax;
1083             }
1084             if ((eyes || heal) && !mtmp->mcansee)
1085                 mcureblindness(mtmp, canseemon(mtmp));
1086             /* in case it polymorphed or died */
1087             if (ptr != original_ptr)
1088                 return !ptr ? 2 : 1;
1089         }
1090
1091         /* Engulf & devour is instant, so don't set meating */
1092         if (mtmp->minvis)
1093             newsym(mtmp->mx, mtmp->my);
1094     }
1095
1096     if (ecount > 0) {
1097         if (cansee(mtmp->mx, mtmp->my) && flags.verbose && buf[0])
1098             pline1(buf);
1099         else if (flags.verbose)
1100 #if 0 /*JP*/
1101             You_hear("%s slurping sound%s.",
1102                      (ecount == 1) ? "a" : "several", plur(ecount));
1103 #else
1104             You_hear("\83Y\83\8b\83Y\83\8b\82Æ\82¢\82¤\89¹\82ð\95·\82¢\82½\81D");
1105 #endif
1106     }
1107     return (count > 0 || ecount > 0) ? 1 : 0;
1108 }
1109
1110 void
1111 mpickgold(mtmp)
1112 register struct monst *mtmp;
1113 {
1114     register struct obj *gold;
1115     int mat_idx;
1116
1117     if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) {
1118         mat_idx = objects[gold->otyp].oc_material;
1119         obj_extract_self(gold);
1120         add_to_minv(mtmp, gold);
1121         if (cansee(mtmp->mx, mtmp->my)) {
1122             if (flags.verbose && !mtmp->isgd)
1123 #if 0 /*JP*/
1124                 pline("%s picks up some %s.", Monnam(mtmp),
1125                       mat_idx == GOLD ? "gold" : "money");
1126 #else
1127                 pline("%s\82Í\82¨\8bà\82ð\8fE\82Á\82½\81D", Monnam(mtmp));
1128 #endif
1129             newsym(mtmp->mx, mtmp->my);
1130         }
1131     }
1132 }
1133
1134 boolean
1135 mpickstuff(mtmp, str)
1136 register struct monst *mtmp;
1137 register const char *str;
1138 {
1139     register struct obj *otmp, *otmp2, *otmp3;
1140     int carryamt = 0;
1141
1142     /* prevent shopkeepers from leaving the door of their shop */
1143     if (mtmp->isshk && inhishop(mtmp))
1144         return FALSE;
1145
1146     for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
1147         otmp2 = otmp->nexthere;
1148         /* Nymphs take everything.  Most monsters don't pick up corpses. */
1149         if (!str ? searches_for_item(mtmp, otmp)
1150                  : !!(index(str, otmp->oclass))) {
1151             if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
1152                 /* let a handful of corpse types thru to can_carry() */
1153                 && !touch_petrifies(&mons[otmp->corpsenm])
1154                 && otmp->corpsenm != PM_LIZARD
1155                 && !acidic(&mons[otmp->corpsenm]))
1156                 continue;
1157             if (!touch_artifact(otmp, mtmp))
1158                 continue;
1159             carryamt = can_carry(mtmp, otmp);
1160             if (carryamt == 0)
1161                 continue;
1162             if (is_pool(mtmp->mx, mtmp->my))
1163                 continue;
1164             /* handle cases where the critter can only get some */
1165             otmp3 = otmp;
1166             if (carryamt != otmp->quan) {
1167                 otmp3 = splitobj(otmp, carryamt);
1168             }
1169             if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
1170 #if 0 /*JP*/
1171                 pline("%s picks up %s.", Monnam(mtmp),
1172                       (distu(mtmp->mx, mtmp->my) <= 5)
1173                           ? doname(otmp3)
1174                           : distant_name(otmp3, doname));
1175 #else
1176                 pline("%s\82Í%s\82ð\8fE\82Á\82½\81D", Monnam(mtmp),
1177                       (distu(mtmp->mx, mtmp->my) <= 5)
1178                           ? doname(otmp3)
1179                           : distant_name(otmp3, doname));
1180 #endif
1181             obj_extract_self(otmp3);      /* remove from floor */
1182             (void) mpickobj(mtmp, otmp3); /* may merge and free otmp3 */
1183             m_dowear(mtmp, FALSE);
1184             newsym(mtmp->mx, mtmp->my);
1185             return TRUE; /* pick only one object */
1186         }
1187     }
1188     return FALSE;
1189 }
1190
1191 int
1192 curr_mon_load(mtmp)
1193 struct monst *mtmp;
1194 {
1195     int curload = 0;
1196     struct obj *obj;
1197
1198     for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1199         if (obj->otyp != BOULDER || !throws_rocks(mtmp->data))
1200             curload += obj->owt;
1201     }
1202
1203     return curload;
1204 }
1205
1206 int
1207 max_mon_load(mtmp)
1208 struct monst *mtmp;
1209 {
1210     long maxload;
1211
1212     /* Base monster carrying capacity is equal to human maximum
1213      * carrying capacity, or half human maximum if not strong.
1214      * (for a polymorphed player, the value used would be the
1215      * non-polymorphed carrying capacity instead of max/half max).
1216      * This is then modified by the ratio between the monster weights
1217      * and human weights.  Corpseless monsters are given a capacity
1218      * proportional to their size instead of weight.
1219      */
1220     if (!mtmp->data->cwt)
1221         maxload = (MAX_CARR_CAP * (long) mtmp->data->msize) / MZ_HUMAN;
1222     else if (!strongmonst(mtmp->data)
1223              || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN)))
1224         maxload = (MAX_CARR_CAP * (long) mtmp->data->cwt) / WT_HUMAN;
1225     else
1226         maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/
1227
1228     if (!strongmonst(mtmp->data))
1229         maxload /= 2;
1230
1231     if (maxload < 1)
1232         maxload = 1;
1233
1234     return (int) maxload;
1235 }
1236
1237 /* for restricting monsters' object-pickup.
1238  *
1239  * to support the new pet behavior, this now returns the max # of objects
1240  * that a given monster could pick up from a pile. frequently this will be
1241  * otmp->quan, but special cases for 'only one' now exist so.
1242  *
1243  * this will probably cause very amusing behavior with pets and gold coins.
1244  *
1245  * TODO: allow picking up 2-N objects from a pile of N based on weight.
1246  *       Change from 'int' to 'long' to accomate big stacks of gold.
1247  *       Right now we fake it by reporting a partial quantity, but the
1248  *       likesgold handling m_move results in picking up the whole stack.
1249  */
1250 int
1251 can_carry(mtmp, otmp)
1252 struct monst *mtmp;
1253 struct obj *otmp;
1254 {
1255     int iquan, otyp = otmp->otyp, newload = otmp->owt;
1256     struct permonst *mdat = mtmp->data;
1257     short nattk = 0;
1258
1259     if (notake(mdat))
1260         return 0; /* can't carry anything */
1261
1262     if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])
1263         && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp))
1264         return 0;
1265     if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm]))
1266         return 0;
1267     if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp)
1268         && (otyp != BELL_OF_OPENING || !is_covetous(mdat)))
1269         return 0;
1270
1271     /* hostile monsters who like gold will pick up the whole stack;
1272        tame mosnters with hands will pick up the partial stack */
1273     iquan = (otmp->quan > (long) LARGEST_INT)
1274                ? 20000 + rn2(LARGEST_INT - 20000 + 1)
1275                : (int) otmp->quan;
1276
1277     /* monsters without hands can't pick up multiple objects at once
1278      * unless they have an engulfing attack
1279      *
1280      * ...dragons, of course, can always carry gold pieces and gems somehow
1281      */
1282     if (iquan > 1) {
1283         boolean glomper = FALSE;
1284
1285         if (mtmp->data->mlet == S_DRAGON
1286             && (otmp->oclass == COIN_CLASS
1287                 || otmp->oclass == GEM_CLASS))
1288             glomper = TRUE;
1289         else
1290             for (nattk = 0; nattk < NATTK; nattk++)
1291                 if (mtmp->data->mattk[nattk].aatyp == AT_ENGL) {
1292                     glomper = TRUE;
1293                     break;
1294                 }
1295         if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper)
1296             return 1;
1297     }
1298
1299     /* steeds don't pick up stuff (to avoid shop abuse) */
1300     if (mtmp == u.usteed)
1301         return 0;
1302     if (mtmp->isshk)
1303         return iquan; /* no limit */
1304     if (mtmp->mpeaceful && !mtmp->mtame)
1305         return 0;
1306     /* otherwise players might find themselves obligated to violate
1307      * their alignment if the monster takes something they need
1308      */
1309
1310     /* special--boulder throwers carry unlimited amounts of boulders */
1311     if (throws_rocks(mdat) && otyp == BOULDER)
1312         return iquan;
1313
1314     /* nymphs deal in stolen merchandise, but not boulders or statues */
1315     if (mdat->mlet == S_NYMPH)
1316         return (otmp->oclass == ROCK_CLASS) ? 0 : iquan;
1317
1318     if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp))
1319         return 0;
1320
1321     return iquan;
1322 }
1323
1324 /* return number of acceptable neighbour positions */
1325 int
1326 mfndpos(mon, poss, info, flag)
1327 struct monst *mon;
1328 coord *poss; /* coord poss[9] */
1329 long *info;  /* long info[9] */
1330 long flag;
1331 {
1332     struct permonst *mdat = mon->data;
1333     register struct trap *ttmp;
1334     xchar x, y, nx, ny;
1335     int cnt = 0;
1336     uchar ntyp;
1337     uchar nowtyp;
1338     boolean wantpool, poolok, lavaok, nodiag;
1339     boolean rockok = FALSE, treeok = FALSE, thrudoor;
1340     int maxx, maxy;
1341     boolean poisongas_ok, in_poisongas;
1342     NhRegion *gas_reg;
1343     int gas_glyph = cmap_to_glyph(S_poisoncloud);
1344
1345     x = mon->mx;
1346     y = mon->my;
1347     nowtyp = levl[x][y].typ;
1348
1349     nodiag = NODIAG(mdat - mons);
1350     wantpool = mdat->mlet == S_EEL;
1351     poolok = (is_flyer(mdat) || is_clinger(mdat)
1352               || (is_swimmer(mdat) && !wantpool));
1353     lavaok = (is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat));
1354     thrudoor = ((flag & (ALLOW_WALL | BUSTDOOR)) != 0L);
1355     poisongas_ok = ((nonliving(mdat) || is_vampshifter(mon)
1356                      || breathless(mdat)) || resists_poison(mon));
1357     in_poisongas = ((gas_reg = visible_region_at(x,y)) != 0
1358                     && gas_reg->glyph == gas_glyph);
1359
1360     if (flag & ALLOW_DIG) {
1361         struct obj *mw_tmp;
1362
1363         /* need to be specific about what can currently be dug */
1364         if (!needspick(mdat)) {
1365             rockok = treeok = TRUE;
1366         } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed
1367                    && mon->weapon_check == NO_WEAPON_WANTED) {
1368             rockok = is_pick(mw_tmp);
1369             treeok = is_axe(mw_tmp);
1370         } else {
1371             rockok = (m_carrying(mon, PICK_AXE)
1372                       || (m_carrying(mon, DWARVISH_MATTOCK)
1373                           && !which_armor(mon, W_ARMS)));
1374             treeok = (m_carrying(mon, AXE) || (m_carrying(mon, BATTLE_AXE)
1375                                                && !which_armor(mon, W_ARMS)));
1376         }
1377         if (rockok || treeok)
1378             thrudoor = TRUE;
1379     }
1380
1381 nexttry: /* eels prefer the water, but if there is no water nearby,
1382             they will crawl over land */
1383     if (mon->mconf) {
1384         flag |= ALLOW_ALL;
1385         flag &= ~NOTONL;
1386     }
1387     if (!mon->mcansee)
1388         flag |= ALLOW_SSM;
1389     maxx = min(x + 1, COLNO - 1);
1390     maxy = min(y + 1, ROWNO - 1);
1391     for (nx = max(1, x - 1); nx <= maxx; nx++)
1392         for (ny = max(0, y - 1); ny <= maxy; ny++) {
1393             if (nx == x && ny == y)
1394                 continue;
1395             ntyp = levl[nx][ny].typ;
1396             if (IS_ROCK(ntyp)
1397                 && !((flag & ALLOW_WALL) && may_passwall(nx, ny))
1398                 && !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx, ny)))
1399                 continue;
1400             /* KMH -- Added iron bars */
1401             if (ntyp == IRONBARS && !(flag & ALLOW_BARS))
1402                 continue;
1403             if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon))
1404                 && (((levl[nx][ny].doormask & D_CLOSED) && !(flag & OPENDOOR))
1405                     || ((levl[nx][ny].doormask & D_LOCKED)
1406                         && !(flag & UNLOCKDOOR))) && !thrudoor)
1407                 continue;
1408             /* avoid poison gas? */
1409             if (!poisongas_ok && !in_poisongas
1410                 && (gas_reg = visible_region_at(nx,ny)) != 0
1411                 && gas_reg->glyph == gas_glyph)
1412                 continue;
1413             /* first diagonal checks (tight squeezes handled below) */
1414             if (nx != x && ny != y
1415                 && (nodiag
1416                     || (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN))
1417                     || (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN))
1418                     || ((IS_DOOR(nowtyp) || IS_DOOR(ntyp))
1419                         && Is_rogue_level(&u.uz))
1420                     /* mustn't pass between adjacent long worm segments,
1421                        but can attack that way */
1422                     || (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny)
1423                         && !m_at(nx, ny) && (nx != u.ux || ny != u.uy))))
1424                 continue;
1425             if ((is_pool(nx, ny) == wantpool || poolok)
1426                 && (lavaok || !is_lava(nx, ny))) {
1427                 int dispx, dispy;
1428                 boolean monseeu = (mon->mcansee
1429                                    && (!Invis || perceives(mdat)));
1430                 boolean checkobj = OBJ_AT(nx, ny);
1431
1432                 /* Displacement also displaces the Elbereth/scare monster,
1433                  * as long as you are visible.
1434                  */
1435                 if (Displaced && monseeu && mon->mux == nx && mon->muy == ny) {
1436                     dispx = u.ux;
1437                     dispy = u.uy;
1438                 } else {
1439                     dispx = nx;
1440                     dispy = ny;
1441                 }
1442
1443                 info[cnt] = 0;
1444                 if (onscary(dispx, dispy, mon)) {
1445                     if (!(flag & ALLOW_SSM))
1446                         continue;
1447                     info[cnt] |= ALLOW_SSM;
1448                 }
1449                 if ((nx == u.ux && ny == u.uy)
1450                     || (nx == mon->mux && ny == mon->muy)) {
1451                     if (nx == u.ux && ny == u.uy) {
1452                         /* If it's right next to you, it found you,
1453                          * displaced or no.  We must set mux and muy
1454                          * right now, so when we return we can tell
1455                          * that the ALLOW_U means to attack _you_ and
1456                          * not the image.
1457                          */
1458                         mon->mux = u.ux;
1459                         mon->muy = u.uy;
1460                     }
1461                     if (!(flag & ALLOW_U))
1462                         continue;
1463                     info[cnt] |= ALLOW_U;
1464                 } else {
1465                     if (MON_AT(nx, ny)) {
1466                         struct monst *mtmp2 = m_at(nx, ny);
1467                         long mmflag = flag | mm_aggression(mon, mtmp2);
1468
1469                         if (mmflag & ALLOW_M) {
1470                             info[cnt] |= ALLOW_M;
1471                             if (mtmp2->mtame) {
1472                                 if (!(mmflag & ALLOW_TM))
1473                                     continue;
1474                                 info[cnt] |= ALLOW_TM;
1475                             }
1476                         } else {
1477                             mmflag = flag | mm_displacement(mon, mtmp2);
1478                             if (!(mmflag & ALLOW_MDISP))
1479                                 continue;
1480                             info[cnt] |= ALLOW_MDISP;
1481                         }
1482                     }
1483                     /* Note: ALLOW_SANCT only prevents movement, not
1484                        attack, into a temple. */
1485                     if (level.flags.has_temple && *in_rooms(nx, ny, TEMPLE)
1486                         && !*in_rooms(x, y, TEMPLE)
1487                         && in_your_sanctuary((struct monst *) 0, nx, ny)) {
1488                         if (!(flag & ALLOW_SANCT))
1489                             continue;
1490                         info[cnt] |= ALLOW_SANCT;
1491                     }
1492                 }
1493                 if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
1494                     if (flag & NOGARLIC)
1495                         continue;
1496                     info[cnt] |= NOGARLIC;
1497                 }
1498                 if (checkobj && sobj_at(BOULDER, nx, ny)) {
1499                     if (!(flag & ALLOW_ROCK))
1500                         continue;
1501                     info[cnt] |= ALLOW_ROCK;
1502                 }
1503                 if (monseeu && onlineu(nx, ny)) {
1504                     if (flag & NOTONL)
1505                         continue;
1506                     info[cnt] |= NOTONL;
1507                 }
1508                 /* check for diagonal tight squeeze */
1509                 if (nx != x && ny != y && bad_rock(mdat, x, ny)
1510                     && bad_rock(mdat, nx, y) && cant_squeeze_thru(mon))
1511                     continue;
1512                 /* The monster avoids a particular type of trap if it's
1513                  * familiar with the trap type.  Pets get ALLOW_TRAPS
1514                  * and checking is done in dogmove.c.  In either case,
1515                  * "harmless" traps are neither avoided nor marked in info[].
1516                  */
1517                 if ((ttmp = t_at(nx, ny)) != 0) {
1518                     if (ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) {
1519                         impossible(
1520                          "A monster looked at a very strange trap of type %d.",
1521                                    ttmp->ttyp);
1522                             continue;
1523                     }
1524                     if ((ttmp->ttyp != RUST_TRAP
1525                          || mdat == &mons[PM_IRON_GOLEM])
1526                         && ttmp->ttyp != STATUE_TRAP
1527                         && ((ttmp->ttyp != PIT && ttmp->ttyp != SPIKED_PIT
1528                              && ttmp->ttyp != TRAPDOOR && ttmp->ttyp != HOLE)
1529                             || (!is_flyer(mdat) && !is_floater(mdat)
1530                                 && !is_clinger(mdat)) || Sokoban)
1531                         && (ttmp->ttyp != SLP_GAS_TRAP || !resists_sleep(mon))
1532                         && (ttmp->ttyp != BEAR_TRAP
1533                             || (mdat->msize > MZ_SMALL && !amorphous(mdat)
1534                                 && !is_flyer(mdat) && !is_floater(mdat)
1535                                 && !is_whirly(mdat) && !unsolid(mdat)))
1536                         && (ttmp->ttyp != FIRE_TRAP || !resists_fire(mon))
1537                         && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat))
1538                         && (ttmp->ttyp != WEB
1539                             || (!amorphous(mdat) && !webmaker(mdat)
1540                                 && !is_whirly(mdat) && !unsolid(mdat)))
1541                         && (ttmp->ttyp != ANTI_MAGIC || !resists_magm(mon))) {
1542                         if (!(flag & ALLOW_TRAPS)) {
1543                             if (mon->mtrapseen & (1L << (ttmp->ttyp - 1)))
1544                                 continue;
1545                         }
1546                         info[cnt] |= ALLOW_TRAPS;
1547                     }
1548                 }
1549                 poss[cnt].x = nx;
1550                 poss[cnt].y = ny;
1551                 cnt++;
1552             }
1553         }
1554     if (!cnt && wantpool && !is_pool(x, y)) {
1555         wantpool = FALSE;
1556         goto nexttry;
1557     }
1558     return cnt;
1559 }
1560
1561 /* Monster against monster special attacks; for the specified monster
1562    combinations, this allows one monster to attack another adjacent one
1563    in the absence of Conflict.  There is no provision for targetting
1564    other monsters; just hand to hand fighting when they happen to be
1565    next to each other. */
1566 STATIC_OVL long
1567 mm_aggression(magr, mdef)
1568 struct monst *magr, /* monster that is currently deciding where to move */
1569              *mdef; /* another monster which is next to it */
1570 {
1571     /* supposedly purple worms are attracted to shrieking because they
1572        like to eat shriekers, so attack the latter when feasible */
1573     if (magr->data == &mons[PM_PURPLE_WORM]
1574         && mdef->data == &mons[PM_SHRIEKER])
1575         return ALLOW_M | ALLOW_TM;
1576     /* Various other combinations such as dog vs cat, cat vs rat, and
1577        elf vs orc have been suggested.  For the time being we don't
1578        support those. */
1579     return 0L;
1580 }
1581
1582 /* Monster displacing another monster out of the way */
1583 STATIC_OVL long
1584 mm_displacement(magr, mdef)
1585 struct monst *magr, /* monster that is currently deciding where to move */
1586              *mdef; /* another monster which is next to it */
1587 {
1588     struct permonst *pa = magr->data, *pd = mdef->data;
1589
1590     /* if attacker can't barge through, there's nothing to do;
1591        or if defender can barge through too, don't let attacker
1592        do so, otherwise they might just end up swapping places
1593        again when defender gets its chance to move */
1594     if ((pa->mflags3 & M3_DISPLACES) != 0 && (pd->mflags3 & M3_DISPLACES) == 0
1595         /* no displacing grid bugs diagonally */
1596         && !(magr->mx != mdef->mx && magr->my != mdef->my
1597              && NODIAG(monsndx(pd)))
1598         /* no displacing trapped monsters or multi-location longworms */
1599         && !mdef->mtrapped && (!mdef->wormno || !count_wsegs(mdef))
1600         /* riders can move anything; others, same size or smaller only */
1601         && (is_rider(pa) || pa->msize >= pd->msize))
1602         return ALLOW_MDISP;
1603     return 0L;
1604 }
1605
1606 /* Is the square close enough for the monster to move or attack into? */
1607 boolean
1608 monnear(mon, x, y)
1609 struct monst *mon;
1610 int x, y;
1611 {
1612     int distance = dist2(mon->mx, mon->my, x, y);
1613
1614     if (distance == 2 && NODIAG(mon->data - mons))
1615         return 0;
1616     return (boolean) (distance < 3);
1617 }
1618
1619 /* really free dead monsters */
1620 void
1621 dmonsfree()
1622 {
1623     struct monst **mtmp, *freetmp;
1624     int count = 0;
1625
1626     for (mtmp = &fmon; *mtmp;) {
1627         freetmp = *mtmp;
1628         if (freetmp->mhp <= 0 && !freetmp->isgd) {
1629             *mtmp = freetmp->nmon;
1630             freetmp->nmon = NULL;
1631             dealloc_monst(freetmp);
1632             count++;
1633         } else
1634             mtmp = &(freetmp->nmon);
1635     }
1636
1637     if (count != iflags.purge_monsters)
1638         impossible("dmonsfree: %d removed doesn't match %d pending",
1639                    count, iflags.purge_monsters);
1640     iflags.purge_monsters = 0;
1641 }
1642
1643 /* called when monster is moved to larger structure */
1644 void
1645 replmon(mtmp, mtmp2)
1646 struct monst *mtmp, *mtmp2;
1647 {
1648     struct obj *otmp;
1649
1650     /* transfer the monster's inventory */
1651     for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
1652         if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
1653             impossible("replmon: minvent inconsistency");
1654         otmp->ocarry = mtmp2;
1655     }
1656     mtmp->minvent = 0;
1657
1658     /* remove the old monster from the map and from `fmon' list */
1659     relmon(mtmp, (struct monst **) 0);
1660
1661     /* finish adding its replacement */
1662     if (mtmp != u.usteed) /* don't place steed onto the map */
1663         place_monster(mtmp2, mtmp2->mx, mtmp2->my);
1664     if (mtmp2->wormno)      /* update level.monsters[wseg->wx][wseg->wy] */
1665         place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */
1666     if (emits_light(mtmp2->data)) {
1667         /* since this is so rare, we don't have any `mon_move_light_source' */
1668         new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
1669                          LS_MONSTER, monst_to_any(mtmp2));
1670         /* here we rely on fact that `mtmp' hasn't actually been deleted */
1671         del_light_source(LS_MONSTER, monst_to_any(mtmp));
1672     }
1673     mtmp2->nmon = fmon;
1674     fmon = mtmp2;
1675     if (u.ustuck == mtmp)
1676         u.ustuck = mtmp2;
1677     if (u.usteed == mtmp)
1678         u.usteed = mtmp2;
1679     if (mtmp2->isshk)
1680         replshk(mtmp, mtmp2);
1681
1682     /* discard the old monster */
1683     dealloc_monst(mtmp);
1684 }
1685
1686 /* release mon from the display and the map's monster list,
1687    maybe transfer it to one of the other monster lists */
1688 void
1689 relmon(mon, monst_list)
1690 struct monst *mon;
1691 struct monst **monst_list; /* &migrating_mons or &mydogs or null */
1692 {
1693     struct monst *mtmp;
1694     boolean unhide = (monst_list != 0);
1695     int mx = mon->mx, my = mon->my;
1696
1697     if (!fmon)
1698         panic("relmon: no fmon available.");
1699
1700     if (unhide) {
1701         /* can't remain hidden across level changes (exception: wizard
1702            clone can continue imitating some other monster form); also,
1703            might be imitating a boulder so need line-of-sight unblocking */
1704         mon->mundetected = 0;
1705         if (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)
1706             seemimic(mon);
1707     }
1708
1709     if (mon->wormno)
1710         remove_worm(mon);
1711     else
1712         remove_monster(mx, my);
1713
1714     if (mon == fmon) {
1715         fmon = fmon->nmon;
1716     } else {
1717         for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1718             if (mtmp->nmon == mon)
1719                 break;
1720
1721         if (mtmp)
1722             mtmp->nmon = mon->nmon;
1723         else
1724             panic("relmon: mon not in list.");
1725     }
1726
1727     if (unhide) {
1728         newsym(mx, my);
1729         /* insert into mydogs or migrating_mons */
1730         mon->nmon = *monst_list;
1731         *monst_list = mon;
1732     } else {
1733         /* orphan has no next monster */
1734         mon->nmon = 0;
1735     }
1736 }
1737
1738 void
1739 copy_mextra(mtmp2, mtmp1)
1740 struct monst *mtmp2, *mtmp1;
1741 {
1742     if (!mtmp2 || !mtmp1 || !mtmp1->mextra)
1743         return;
1744
1745     if (!mtmp2->mextra)
1746         mtmp2->mextra = newmextra();
1747     if (MNAME(mtmp1)) {
1748         new_mname(mtmp2, (int) strlen(MNAME(mtmp1)) + 1);
1749         Strcpy(MNAME(mtmp2), MNAME(mtmp1));
1750     }
1751     if (EGD(mtmp1)) {
1752         if (!EGD(mtmp2))
1753             newegd(mtmp2);
1754         *EGD(mtmp2) = *EGD(mtmp1);
1755     }
1756     if (EPRI(mtmp1)) {
1757         if (!EPRI(mtmp2))
1758             newepri(mtmp2);
1759         *EPRI(mtmp2) = *EPRI(mtmp1);
1760     }
1761     if (ESHK(mtmp1)) {
1762         if (!ESHK(mtmp2))
1763             neweshk(mtmp2);
1764         *ESHK(mtmp2) = *ESHK(mtmp1);
1765     }
1766     if (EMIN(mtmp1)) {
1767         if (!EMIN(mtmp2))
1768             newemin(mtmp2);
1769         *EMIN(mtmp2) = *EMIN(mtmp1);
1770     }
1771     if (EDOG(mtmp1)) {
1772         if (!EDOG(mtmp2))
1773             newedog(mtmp2);
1774         *EDOG(mtmp2) = *EDOG(mtmp1);
1775     }
1776     if (has_mcorpsenm(mtmp1))
1777         MCORPSENM(mtmp2) = MCORPSENM(mtmp1);
1778 }
1779
1780 void
1781 dealloc_mextra(m)
1782 struct monst *m;
1783 {
1784     struct mextra *x = m->mextra;
1785
1786     if (x) {
1787         if (x->mname)
1788             free((genericptr_t) x->mname);
1789         if (x->egd)
1790             free((genericptr_t) x->egd);
1791         if (x->epri)
1792             free((genericptr_t) x->epri);
1793         if (x->eshk)
1794             free((genericptr_t) x->eshk);
1795         if (x->emin)
1796             free((genericptr_t) x->emin);
1797         if (x->edog)
1798             free((genericptr_t) x->edog);
1799         /* [no action needed for x->mcorpsenm] */
1800
1801         free((genericptr_t) x);
1802         m->mextra = (struct mextra *) 0;
1803     }
1804 }
1805
1806 void
1807 dealloc_monst(mon)
1808 struct monst *mon;
1809 {
1810     if (mon->nmon)
1811         panic("dealloc_monst with nmon");
1812     if (mon->mextra)
1813         dealloc_mextra(mon);
1814     free((genericptr_t) mon);
1815 }
1816
1817 /* remove effects of mtmp from other data structures */
1818 STATIC_OVL void
1819 m_detach(mtmp, mptr)
1820 struct monst *mtmp;
1821 struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
1822 {
1823     if (mtmp == context.polearm.hitmon)
1824         context.polearm.hitmon = 0;
1825     if (mtmp->mleashed)
1826         m_unleash(mtmp, FALSE);
1827     /* to prevent an infinite relobj-flooreffects-hmon-killed loop */
1828     mtmp->mtrapped = 0;
1829     mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
1830     relobj(mtmp, 0, FALSE);
1831     remove_monster(mtmp->mx, mtmp->my);
1832     if (emits_light(mptr))
1833         del_light_source(LS_MONSTER, monst_to_any(mtmp));
1834     if (mtmp->m_ap_type)
1835         seemimic(mtmp);
1836     newsym(mtmp->mx, mtmp->my);
1837     unstuck(mtmp);
1838     fill_pit(mtmp->mx, mtmp->my);
1839
1840     if (mtmp->isshk)
1841         shkgone(mtmp);
1842     if (mtmp->wormno)
1843         wormgone(mtmp);
1844     iflags.purge_monsters++;
1845 }
1846
1847 /* find the worn amulet of life saving which will save a monster */
1848 struct obj *
1849 mlifesaver(mon)
1850 struct monst *mon;
1851 {
1852     if (!nonliving(mon->data) || is_vampshifter(mon)) {
1853         struct obj *otmp = which_armor(mon, W_AMUL);
1854
1855         if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING)
1856             return otmp;
1857     }
1858     return (struct obj *) 0;
1859 }
1860
1861 STATIC_OVL void
1862 lifesaved_monster(mtmp)
1863 struct monst *mtmp;
1864 {
1865     boolean surviver;
1866     struct obj *lifesave = mlifesaver(mtmp);
1867
1868     if (lifesave) {
1869         /* not canseemon; amulets are on the head, so you don't want
1870          * to show this for a long worm with only a tail visible.
1871          * Nor do you check invisibility, because glowing and
1872          * disintegrating amulets are always visible. */
1873         if (cansee(mtmp->mx, mtmp->my)) {
1874 /*JP
1875             pline("But wait...");
1876 */
1877             pline("\82¿\82å\82Á\82Æ\82Ü\82Á\82½\81D\81D\81D");
1878 /*JP
1879             pline("%s medallion begins to glow!", s_suffix(Monnam(mtmp)));
1880 */
1881             pline("%s\82Ì\96\82\8f\9c\82¯\82ª\8bP\82«\82Í\82\82ß\82½\81I", Monnam(mtmp));
1882             makeknown(AMULET_OF_LIFE_SAVING);
1883             /* amulet is visible, but monster might not be */
1884             if (canseemon(mtmp)) {
1885                 if (attacktype(mtmp->data, AT_EXPL)
1886                     || attacktype(mtmp->data, AT_BOOM))
1887 /*JP
1888                     pline("%s reconstitutes!", Monnam(mtmp));
1889 */
1890                     pline("%s\82Í\8dÄ\8d\\90¬\82³\82ê\82½\81I", Monnam(mtmp));
1891                 else
1892 /*JP
1893                     pline("%s looks much better!", Monnam(mtmp));
1894 */
1895                     pline("%s\82Í\82·\82Á\82©\82è\89ñ\95\9c\82µ\82½\82æ\82¤\82¾\81I", Monnam(mtmp));
1896             }
1897 /*JP
1898             pline_The("medallion crumbles to dust!");
1899 */
1900             pline("\96\82\8f\9c\82¯\82Í\82±\82È\82²\82È\82É\82­\82¾\82¯\82½\81I");
1901         }
1902         m_useup(mtmp, lifesave);
1903
1904         surviver = !(mvitals[monsndx(mtmp->data)].mvflags & G_GENOD);
1905         mtmp->mcanmove = 1;
1906         mtmp->mfrozen = 0;
1907         if (mtmp->mtame && !mtmp->isminion) {
1908             wary_dog(mtmp, !surviver);
1909         }
1910         if (mtmp->mhpmax <= 0)
1911             mtmp->mhpmax = 10;
1912         mtmp->mhp = mtmp->mhpmax;
1913         if (surviver)
1914             return;
1915
1916         /* genocided monster can't be life-saved */
1917         if (cansee(mtmp->mx, mtmp->my))
1918 /*JP
1919             pline("Unfortunately, %s is still genocided...", mon_nam(mtmp));
1920 */
1921             pline("\8ec\94O\82È\82ª\82ç%s\82Í\8bs\8eE\82³\82ê\82Ä\82¢\82é\81D\81D\81D", mon_nam(mtmp));
1922         mtmp->mhp = 0;
1923     }
1924 }
1925
1926 void
1927 mondead(mtmp)
1928 register struct monst *mtmp;
1929 {
1930     struct permonst *mptr;
1931     int tmp;
1932
1933     mtmp->mhp = 0; /* in case caller hasn't done this */
1934     lifesaved_monster(mtmp);
1935     if (mtmp->mhp > 0)
1936         return;
1937
1938     if (is_vampshifter(mtmp)) {
1939         int mndx = mtmp->cham;
1940         int x = mtmp->mx, y = mtmp->my;
1941
1942         /* this only happens if shapeshifted */
1943         if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
1944             && !(mvitals[mndx].mvflags & G_GENOD)) {
1945             char buf[BUFSZ];
1946             boolean in_door = (amorphous(mtmp->data)
1947                                && closed_door(mtmp->mx, mtmp->my)),
1948                 /* alternate message phrasing for some monster types */
1949                 spec_mon = (nonliving(mtmp->data)
1950                             || noncorporeal(mtmp->data)
1951                             || amorphous(mtmp->data)),
1952                 spec_death = (disintegested /* disintegrated or digested */
1953                               || noncorporeal(mtmp->data)
1954                               || amorphous(mtmp->data));
1955
1956             /* construct a format string before transformation;
1957                will be capitalized when used, expects one %s arg */
1958 #if 0 /*JP*/
1959             Sprintf(buf, "%s suddenly %s and rises as %%s!",
1960                     x_monnam(mtmp, ARTICLE_THE,
1961                              spec_mon ? (char *) 0 : "seemingly dead",
1962                              SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1963                                  | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1964                              FALSE),
1965                     spec_death ? "reconstitutes" : "transforms");
1966 #else
1967             Sprintf(buf, "%s%s\82Í\93Ë\91R%s\81C%%s\82Æ\82µ\82Ä\91h\82Á\82½\81I",
1968                     spec_death ? "" : "\8e\80\82ñ\82¾\82æ\82¤\82É\8ev\82í\82ê\82½",
1969                     x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
1970                              SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1971                                  | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1972                              FALSE),
1973                     spec_death ? "\8dÄ\8d\\90¬\82³\82ê" : "\95Ï\89»\82µ");
1974 #endif
1975             mtmp->mcanmove = 1;
1976             mtmp->mfrozen = 0;
1977             if (mtmp->mhpmax <= 0)
1978                 mtmp->mhpmax = 10;
1979             mtmp->mhp = mtmp->mhpmax;
1980             /* this can happen if previously a fog cloud */
1981             if (u.uswallow && (mtmp == u.ustuck))
1982                 expels(mtmp, mtmp->data, FALSE);
1983             if (in_door) {
1984                 coord new_xy;
1985
1986                 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
1987                     rloc_to(mtmp, new_xy.x, new_xy.y);
1988                 }
1989             }
1990             newcham(mtmp, &mons[mndx], FALSE, FALSE);
1991             if (mtmp->data == &mons[mndx])
1992                 mtmp->cham = NON_PM;
1993             else
1994                 mtmp->cham = mndx;
1995             if (canspotmon(mtmp)) {
1996                 /* was using a_monnam(mtmp) but that's weird if mtmp is named:
1997                    "Dracula suddenly transforms and rises as Dracula" */
1998                 pline(upstart(buf), an(mtmp->data->mname));
1999                 vamp_rise_msg = TRUE;
2000             }
2001             newsym(x, y);
2002             return;
2003         }
2004     }
2005
2006     /* dead vault guard is actually kept at coordinate <0,0> until
2007        his temporary corridor to/from the vault has been removed;
2008        need to do this after life-saving and before m_detach() */
2009     if (mtmp->isgd && !grddead(mtmp))
2010         return;
2011
2012     /* Player is thrown from his steed when it dies */
2013     if (mtmp == u.usteed)
2014         dismount_steed(DISMOUNT_GENERIC);
2015
2016     mptr = mtmp->data; /* save this for m_detach() */
2017     /* restore chameleon, lycanthropes to true form at death */
2018     if (mtmp->cham >= LOW_PM) {
2019         set_mon_data(mtmp, &mons[mtmp->cham], -1);
2020         mtmp->cham = NON_PM;
2021     } else if (mtmp->data == &mons[PM_WEREJACKAL])
2022         set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL], -1);
2023     else if (mtmp->data == &mons[PM_WEREWOLF])
2024         set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF], -1);
2025     else if (mtmp->data == &mons[PM_WERERAT])
2026         set_mon_data(mtmp, &mons[PM_HUMAN_WERERAT], -1);
2027
2028     /*
2029      * mvitals[].died does double duty as total number of dead monsters
2030      * and as experience factor for the player killing more monsters.
2031      * this means that a dragon dying by other means reduces the
2032      * experience the player gets for killing a dragon directly; this
2033      * is probably not too bad, since the player likely finagled the
2034      * first dead dragon via ring of conflict or pets, and extinguishing
2035      * based on only player kills probably opens more avenues of abuse
2036      * for rings of conflict and such.
2037      */
2038     tmp = monsndx(mtmp->data);
2039     if (mvitals[tmp].died < 255)
2040         mvitals[tmp].died++;
2041
2042     /* if it's a (possibly polymorphed) quest leader, mark him as dead */
2043     if (mtmp->m_id == quest_status.leader_m_id)
2044         quest_status.leader_is_dead = TRUE;
2045 #ifdef MAIL
2046     /* if the mail daemon dies, no more mail delivery.  -3. */
2047     if (tmp == PM_MAIL_DAEMON)
2048         mvitals[tmp].mvflags |= G_GENOD;
2049 #endif
2050
2051     if (mtmp->data->mlet == S_KOP) {
2052         /* Dead Kops may come back. */
2053         switch (rnd(5)) {
2054         case 1: /* returns near the stairs */
2055             (void) makemon(mtmp->data, xdnstair, ydnstair, NO_MM_FLAGS);
2056             break;
2057         case 2: /* randomly */
2058             (void) makemon(mtmp->data, 0, 0, NO_MM_FLAGS);
2059             break;
2060         default:
2061             break;
2062         }
2063     }
2064     if (mtmp->iswiz)
2065         wizdead();
2066     if (mtmp->data->msound == MS_NEMESIS)
2067         nemdead();
2068     if (mtmp->data == &mons[PM_MEDUSA])
2069         u.uachieve.killed_medusa = 1;
2070     if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
2071         unmap_object(mtmp->mx, mtmp->my);
2072     m_detach(mtmp, mptr);
2073 }
2074
2075 /* TRUE if corpse might be dropped, magr may die if mon was swallowed */
2076 boolean
2077 corpse_chance(mon, magr, was_swallowed)
2078 struct monst *mon;
2079 struct monst *magr;    /* killer, if swallowed */
2080 boolean was_swallowed; /* digestion */
2081 {
2082     struct permonst *mdat = mon->data;
2083     int i, tmp;
2084
2085     if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) {
2086         if (cansee(mon->mx, mon->my) && !was_swallowed)
2087 /*JP
2088             pline("%s body crumbles into dust.", s_suffix(Monnam(mon)));
2089 */
2090             pline("%s\82Ì\91Ì\82Í\95²\81X\82É\82È\82Á\82½\81D", Monnam(mon));
2091         return FALSE;
2092     }
2093
2094     /* Gas spores always explode upon death */
2095     for (i = 0; i < NATTK; i++) {
2096         if (mdat->mattk[i].aatyp == AT_BOOM) {
2097             if (mdat->mattk[i].damn)
2098                 tmp = d((int) mdat->mattk[i].damn, (int) mdat->mattk[i].damd);
2099             else if (mdat->mattk[i].damd)
2100                 tmp = d((int) mdat->mlevel + 1, (int) mdat->mattk[i].damd);
2101             else
2102                 tmp = 0;
2103             if (was_swallowed && magr) {
2104                 if (magr == &youmonst) {
2105 /*JP
2106                     There("is an explosion in your %s!", body_part(STOMACH));
2107 */
2108                     pline("%s\82Ì\92\86\82Å\94\9a\94­\82ª\8bN\82«\82½\81I", body_part(STOMACH));
2109 #if 0 /*JP*/
2110                     Sprintf(killer.name, "%s explosion",
2111                             s_suffix(mdat->mname));
2112 #else
2113                     Sprintf(killer.name, "%s\82Ì\94\9a\94­\82Å", mdat->mname);
2114 #endif
2115                     losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN);
2116                 } else {
2117 /*JP
2118                     You_hear("an explosion.");
2119 */
2120                     You_hear("\94\9a\94­\89¹\82ð\95·\82¢\82½\81D");
2121                     magr->mhp -= tmp;
2122                     if (magr->mhp < 1)
2123                         mondied(magr);
2124                     if (magr->mhp < 1) { /* maybe lifesaved */
2125                         if (canspotmon(magr))
2126 /*JP
2127                             pline("%s rips open!", Monnam(magr));
2128 */
2129                             pline("%s\82Í\83r\83\8a\82Á\82Æ\94j\82ê\82½\81I", Monnam(magr));
2130                     } else if (canseemon(magr))
2131 /*JP
2132                         pline("%s seems to have indigestion.", Monnam(magr));
2133 */
2134                         pline("%s\82Í\8fÁ\89»\95s\97Ç\82Ì\82æ\82¤\82¾\81D", Monnam(magr));
2135                 }
2136
2137                 return FALSE;
2138             }
2139
2140 /*JP
2141             Sprintf(killer.name, "%s explosion", s_suffix(mdat->mname));
2142 */
2143             Sprintf(killer.name, "%s\82Ì\94\9a\94­\82Å", mdat->mname);
2144             killer.format = KILLED_BY_AN;
2145             explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS);
2146             killer.name[0] = '\0';
2147             killer.format = 0;
2148             return FALSE;
2149         }
2150     }
2151
2152     /* must duplicate this below check in xkilled() since it results in
2153      * creating no objects as well as no corpse
2154      */
2155     if (LEVEL_SPECIFIC_NOCORPSE(mdat))
2156         return FALSE;
2157
2158     if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned)
2159         || is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat) || mon->isshk)
2160         return TRUE;
2161     tmp = 2 + ((mdat->geno & G_FREQ) < 2) + verysmall(mdat);
2162     return (boolean) !rn2(tmp);
2163 }
2164
2165 /* drop (perhaps) a cadaver and remove monster */
2166 void
2167 mondied(mdef)
2168 register struct monst *mdef;
2169 {
2170     mondead(mdef);
2171     if (mdef->mhp > 0)
2172         return; /* lifesaved */
2173
2174     if (corpse_chance(mdef, (struct monst *) 0, FALSE)
2175         && (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my)))
2176         (void) make_corpse(mdef, CORPSTAT_NONE);
2177 }
2178
2179 /* monster disappears, not dies */
2180 void
2181 mongone(mdef)
2182 struct monst *mdef;
2183 {
2184     mdef->mhp = 0; /* can skip some inventory bookkeeping */
2185
2186     /* dead vault guard is actually kept at coordinate <0,0> until
2187        his temporary corridor to/from the vault has been removed */
2188     if (mdef->isgd && !grddead(mdef))
2189         return;
2190     /* hero is thrown from his steed when it disappears */
2191     if (mdef == u.usteed)
2192         dismount_steed(DISMOUNT_GENERIC);
2193     /* stuck to you? release */
2194     unstuck(mdef);
2195     /* drop special items like the Amulet so that a dismissed Kop or nurse
2196        can't remove them from the game */
2197     mdrop_special_objs(mdef);
2198     /* release rest of monster's inventory--it is removed from game */
2199     discard_minvent(mdef);
2200     m_detach(mdef, mdef->data);
2201 }
2202
2203 /* drop a statue or rock and remove monster */
2204 void
2205 monstone(mdef)
2206 struct monst *mdef;
2207 {
2208     struct obj *otmp, *obj, *oldminvent;
2209     xchar x = mdef->mx, y = mdef->my;
2210     boolean wasinside = FALSE;
2211
2212     if (!vamp_stone(mdef)) /* vampshifter reverts to vampire */
2213         return;
2214
2215     /* we have to make the statue before calling mondead, to be able to
2216      * put inventory in it, and we have to check for lifesaving before
2217      * making the statue....
2218      */
2219     mdef->mhp = 0; /* in case caller hasn't done this */
2220     lifesaved_monster(mdef);
2221     if (mdef->mhp > 0)
2222         return;
2223
2224     mdef->mtrapped = 0; /* (see m_detach) */
2225
2226     if ((int) mdef->data->msize > MZ_TINY
2227         || !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) {
2228         oldminvent = 0;
2229         /* some objects may end up outside the statue */
2230         while ((obj = mdef->minvent) != 0) {
2231             obj_extract_self(obj);
2232             if (obj->owornmask)
2233                 update_mon_intrinsics(mdef, obj, FALSE, TRUE);
2234             obj_no_longer_held(obj);
2235             if (obj->owornmask & W_WEP)
2236                 setmnotwielded(mdef, obj);
2237             obj->owornmask = 0L;
2238             if (obj->otyp == BOULDER
2239 #if 0 /* monsters don't carry statues */
2240                 ||  (obj->otyp == STATUE
2241                      && mons[obj->corpsenm].msize >= mdef->data->msize)
2242 #endif
2243                 /* invocation tools resist even with 0% resistance */
2244                 || obj_resists(obj, 0, 0)) {
2245 /*JP
2246                 if (flooreffects(obj, x, y, "fall"))
2247 */
2248                 if (flooreffects(obj, x, y, "\97\8e\82¿\82é"))
2249                     continue;
2250                 place_object(obj, x, y);
2251             } else {
2252                 if (obj->lamplit)
2253                     end_burn(obj, TRUE);
2254                 obj->nobj = oldminvent;
2255                 oldminvent = obj;
2256             }
2257         }
2258         /* defer statue creation until after inventory removal
2259            so that saved monster traits won't retain any stale
2260            item-conferred attributes */
2261         otmp = mkcorpstat(STATUE, mdef, mdef->data, x, y, CORPSTAT_NONE);
2262         if (has_mname(mdef))
2263             otmp = oname(otmp, MNAME(mdef));
2264         while ((obj = oldminvent) != 0) {
2265             oldminvent = obj->nobj;
2266             (void) add_to_container(otmp, obj);
2267         }
2268         /* Archeologists should not break unique statues */
2269         if (mdef->data->geno & G_UNIQ)
2270             otmp->spe = 1;
2271         otmp->owt = weight(otmp);
2272     } else
2273         otmp = mksobj_at(ROCK, x, y, TRUE, FALSE);
2274
2275     stackobj(otmp);
2276     /* mondead() already does this, but we must do it before the newsym */
2277     if (glyph_is_invisible(levl[x][y].glyph))
2278         unmap_object(x, y);
2279     if (cansee(x, y))
2280         newsym(x, y);
2281     /* We don't currently trap the hero in the statue in this case but we
2282      * could */
2283     if (u.uswallow && u.ustuck == mdef)
2284         wasinside = TRUE;
2285     mondead(mdef);
2286     if (wasinside) {
2287         if (is_animal(mdef->data))
2288 #if 0 /*JP*/
2289             You("%s through an opening in the new %s.",
2290                 locomotion(youmonst.data, "jump"), xname(otmp));
2291 #else
2292             You("\90V\82µ\82­\82Å\82«\82½%s\82©\82ç%s\81D",
2293                 xname(otmp), jumpedthrough(youmonst.data, "\94ò\82Ñ\8fo\82½"));
2294 #endif
2295     }
2296 }
2297
2298 /* another monster has killed the monster mdef */
2299 void
2300 monkilled(mdef, fltxt, how)
2301 struct monst *mdef;
2302 const char *fltxt;
2303 int how;
2304 {
2305     boolean be_sad = FALSE; /* true if unseen pet is killed */
2306
2307     if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my))
2308         && fltxt)
2309 #if 0 /*JP*/
2310         pline("%s is %s%s%s!", Monnam(mdef),
2311               nonliving(mdef->data) ? "destroyed" : "killed",
2312               *fltxt ? " by the " : "", fltxt);
2313 #else
2314         {
2315             if(*fltxt)
2316                 pline("%s\82Í%s\82É\82æ\82Á\82Ä%s\81I", Monnam(mdef), fltxt,
2317                       nonliving(mdef->data) ? "\93|\82³\82ê\82½" : "\8eE\82³\82ê\82½");
2318             else
2319                 pline("%s\82Í%s\81I", Monnam(mdef), 
2320                       nonliving(mdef->data) ? "\93|\82³\82ê\82½" : "\8eE\82³\82ê\82½");
2321         }
2322 #endif
2323     else
2324         be_sad = (mdef->mtame != 0);
2325
2326     /* no corpses if digested or disintegrated */
2327     disintegested = (how == AD_DGST || how == -AD_RBRE);
2328     if (disintegested)
2329         mondead(mdef);
2330     else
2331         mondied(mdef);
2332
2333     if (be_sad && mdef->mhp <= 0)
2334 /*JP
2335         You("have a sad feeling for a moment, then it passes.");
2336 */
2337         You("\94ß\82µ\82¢\8bC\8e\9d\82É\82¨\82»\82í\82ê\82½\82ª\81C\82·\82®\82É\89ß\82¬\82³\82Á\82½\81D");
2338 }
2339
2340 void
2341 unstuck(mtmp)
2342 struct monst *mtmp;
2343 {
2344     if (u.ustuck == mtmp) {
2345         if (u.uswallow) {
2346             u.ux = mtmp->mx;
2347             u.uy = mtmp->my;
2348             u.uswallow = 0;
2349             u.uswldtim = 0;
2350             if (Punished && uchain->where != OBJ_FLOOR)
2351                 placebc();
2352             vision_full_recalc = 1;
2353             docrt();
2354             /* prevent swallower (mtmp might have just poly'd into something
2355                without an engulf attack) from immediately re-engulfing */
2356             if (attacktype(mtmp->data, AT_ENGL) && !mtmp->mspec_used)
2357                 mtmp->mspec_used = rnd(2);
2358         }
2359         u.ustuck = 0;
2360     }
2361 }
2362
2363 void
2364 killed(mtmp)
2365 struct monst *mtmp;
2366 {
2367     xkilled(mtmp, XKILL_GIVEMSG);
2368 }
2369
2370 /* the player has killed the monster mtmp */
2371 void
2372 xkilled(mtmp, xkill_flags)
2373 struct monst *mtmp;
2374 int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */
2375 {
2376     int tmp, mndx, x = mtmp->mx, y = mtmp->my;
2377     struct permonst *mdat;
2378     struct obj *otmp;
2379     struct trap *t;
2380     boolean wasinside = u.uswallow && (u.ustuck == mtmp),
2381             burycorpse = FALSE,
2382             nomsg = (xkill_flags & XKILL_NOMSG) != 0,
2383             nocorpse = (xkill_flags & XKILL_NOCORPSE) != 0,
2384             noconduct = (xkill_flags & XKILL_NOCONDUCT) != 0;
2385
2386     mtmp->mhp = 0; /* caller will usually have already done this */
2387     if (!noconduct) /* KMH, conduct */
2388         u.uconduct.killer++;
2389
2390     if (!nomsg) {
2391         boolean namedpet = has_mname(mtmp) && !Hallucination;
2392
2393 #if 0 /*JP*/
2394         You("%s %s!",
2395             nonliving(mtmp->data) ? "destroy" : "kill",
2396             !(wasinside || canspotmon(mtmp)) ? "it"
2397               : !mtmp->mtame ? mon_nam(mtmp)
2398                 : x_monnam(mtmp, namedpet ? ARTICLE_NONE : ARTICLE_THE,
2399                            "poor", namedpet ? SUPPRESS_SADDLE : 0, FALSE));
2400 #else
2401         You("%s%s\82ð\93|\82µ\82½\81I",
2402             !(wasinside || canspotmon(mtmp)) ? "\82»\82ê"
2403               : mtmp->mtame ? "\82©\82í\82¢\82»\82¤\82È" : "",
2404                 mon_nam(mtmp));
2405 #endif
2406     }
2407
2408     if (mtmp->mtrapped && (t = t_at(x, y)) != 0
2409         && (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
2410         if (sobj_at(BOULDER, x, y))
2411             nocorpse = TRUE; /* Prevent corpses/treasure being created
2412                                 "on top" of boulder that is about to fall in.
2413                                 This is out of order, but cannot be helped
2414                                 unless this whole routine is rearranged. */
2415         if (m_carrying(mtmp, BOULDER))
2416             burycorpse = TRUE;
2417     }
2418
2419     /* your pet knows who just killed it...watch out */
2420     if (mtmp->mtame && !mtmp->isminion)
2421         EDOG(mtmp)->killed_by_u = 1;
2422
2423     if (wasinside && thrownobj && thrownobj != uball) {
2424         /* thrown object has killed hero's engulfer; add it to mon's
2425            inventory now so that it will be placed with mon's other
2426            stuff prior to lookhere/autopickup when hero is expelled
2427            below (as a side-effect, this missile has immunity from
2428            being consumed [for this shot/throw only]) */
2429         mpickobj(mtmp, thrownobj);
2430         /* let throwing code know that missile has been disposed of */
2431         thrownobj = 0;
2432     }
2433
2434     vamp_rise_msg = FALSE; /* might get set in mondead(); only checked below */
2435     disintegested = nocorpse; /* alternate vamp_rise message needed if true */
2436     /* dispose of monster and make cadaver */
2437     if (stoned)
2438         monstone(mtmp);
2439     else
2440         mondead(mtmp);
2441     disintegested = FALSE; /* reset */
2442
2443     if (mtmp->mhp > 0) { /* monster lifesaved */
2444         /* Cannot put the non-visible lifesaving message in
2445          * lifesaved_monster() since the message appears only when _you_
2446          * kill it (as opposed to visible lifesaving which always appears).
2447          */
2448         stoned = FALSE;
2449         if (!cansee(x, y) && !vamp_rise_msg)
2450 /*JP
2451             pline("Maybe not...");
2452 */
2453             pline("\82¢\82â\81C\88á\82¤\82©\82à\81D\81D\81D");
2454         return;
2455     }
2456
2457     mdat = mtmp->data; /* note: mondead can change mtmp->data */
2458     mndx = monsndx(mdat);
2459
2460     if (stoned) {
2461         stoned = FALSE;
2462         goto cleanup;
2463     }
2464
2465     if (nocorpse || LEVEL_SPECIFIC_NOCORPSE(mdat))
2466         goto cleanup;
2467
2468 #ifdef MAIL
2469     if (mdat == &mons[PM_MAIL_DAEMON]) {
2470         stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE));
2471     }
2472 #endif
2473     if (accessible(x, y) || is_pool(x, y)) {
2474         struct obj *cadaver;
2475         int otyp;
2476
2477         /* illogical but traditional "treasure drop" */
2478         if (!rn2(6) && !(mvitals[mndx].mvflags & G_NOCORPSE)
2479             /* no extra item from swallower or steed */
2480             && (x != u.ux || y != u.uy)
2481             /* no extra item from kops--too easy to abuse */
2482             && mdat->mlet != S_KOP
2483             /* no items from cloned monsters */
2484             && !mtmp->mcloned) {
2485             otmp = mkobj(RANDOM_CLASS, TRUE);
2486             /* don't create large objects from small monsters */
2487             otyp = otmp->otyp;
2488             if (mdat->msize < MZ_HUMAN && otyp != FIGURINE
2489                 /* oc_big is also oc_bimanual and oc_bulky */
2490                 && (otmp->owt > 30 || objects[otyp].oc_big)) {
2491                 delobj(otmp);
2492 #if 0 /*JP*/
2493             } else if (!flooreffects(otmp, x, y, nomsg ? "" : "fall")) {
2494 #else
2495             } else if (!flooreffects(otmp, x, y, nomsg ? "" : "\97\8e\82¿\82é")) {
2496 #endif
2497                 place_object(otmp, x, y);
2498                 stackobj(otmp);
2499             }
2500         }
2501         /* corpse--none if hero was inside the monster */
2502         if (!wasinside && corpse_chance(mtmp, (struct monst *) 0, FALSE)) {
2503             cadaver = make_corpse(mtmp, burycorpse ? CORPSTAT_BURIED
2504                                                    : CORPSTAT_NONE);
2505             if (burycorpse && cadaver && cansee(x, y) && !mtmp->minvis
2506                 && cadaver->where == OBJ_BURIED && !nomsg) {
2507 /*JP
2508                 pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp)));
2509 */
2510                 pline("%s\82Ì\8e\80\91Ì\82Í\96\84\82Ü\82Á\82Ä\82µ\82Ü\82Á\82½\81D", Monnam(mtmp));
2511             }
2512         }
2513     }
2514     if (wasinside)
2515         spoteffects(TRUE); /* poor man's expels() */
2516     /* monster is gone, corpse or other object might now be visible */
2517     newsym(x, y);
2518
2519 cleanup:
2520     /* punish bad behaviour */
2521     if (is_human(mdat)
2522         && (!always_hostile(mdat) && mtmp->malign <= 0)
2523         && (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD)
2524         && u.ualign.type != A_CHAOTIC) {
2525         HTelepat &= ~INTRINSIC;
2526         change_luck(-2);
2527 /*JP
2528         You("murderer!");
2529 */
2530         You("\8eE\90l\8bS\82¾\81I");
2531         if (Blind && !Blind_telepat)
2532             see_monsters(); /* Can't sense monsters any more. */
2533     }
2534     if ((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame)
2535         change_luck(-1);
2536     if (is_unicorn(mdat) && sgn(u.ualign.type) == sgn(mdat->maligntyp)) {
2537         change_luck(-5);
2538 /*JP
2539         You_feel("guilty...");
2540 */
2541         You("\8dß\82ð\8a´\82\82½\81D\81D\81D");
2542     }
2543
2544     /* give experience points */
2545     tmp = experience(mtmp, (int) mvitals[mndx].died);
2546     more_experienced(tmp, 0);
2547     newexplevel(); /* will decide if you go up */
2548
2549     /* adjust alignment points */
2550     if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */
2551         adjalign(-(u.ualign.record + (int) ALIGNLIM / 2));
2552 #if 0 /*JP*/
2553         pline("That was %sa bad idea...",
2554               u.uevent.qcompleted ? "probably " : "");
2555 #else
2556         pline("%s\82æ\82­\82È\82¢\8ds\88×\82¾\82Á\82½\81D\81D\81D",
2557               u.uevent.qcompleted ? "\82½\82Ô\82ñ" : "");
2558 #endif
2559     } else if (mdat->msound == MS_NEMESIS) { /* Real good! */
2560         adjalign((int) (ALIGNLIM / 4));
2561     } else if (mdat->msound == MS_GUARDIAN) { /* Bad */
2562         adjalign(-(int) (ALIGNLIM / 8));
2563         if (!Hallucination)
2564 /*JP
2565             pline("That was probably a bad idea...");
2566 */
2567             pline("\82æ\82­\82È\82¢\8ds\88×\82¾\82Á\82½\81D\81D\81D");
2568         else
2569 /*JP
2570             pline("Whoopsie-daisy!");
2571 */
2572             pline("\83V\83\93\83W\83}\83b\83^\81[\81I");
2573     } else if (mtmp->ispriest) {
2574         adjalign((p_coaligned(mtmp)) ? -2 : 2);
2575         /* cancel divine protection for killing your priest */
2576         if (p_coaligned(mtmp))
2577             u.ublessed = 0;
2578         if (mdat->maligntyp == A_NONE)
2579             adjalign((int) (ALIGNLIM / 4)); /* BIG bonus */
2580     } else if (mtmp->mtame) {
2581         adjalign(-15); /* bad!! */
2582         /* your god is mighty displeased... */
2583         if (!Hallucination)
2584 /*JP
2585             You_hear("the rumble of distant thunder...");
2586 */
2587             You_hear("\89\93\82­\82Å\97\8b\96Â\82ð\95·\82¢\82½\81D\81D\81D");
2588         else
2589 /*JP
2590             You_hear("the studio audience applaud!");
2591 */
2592             pline("\92®\8fO\82Ì\8a\85\8dÑ\82ð\97\81\82Ñ\82½\81I");
2593     } else if (mtmp->mpeaceful)
2594         adjalign(-5);
2595
2596     /* malign was already adjusted for u.ualign.type and randomization */
2597     adjalign(mtmp->malign);
2598 }
2599
2600 /* changes the monster into a stone monster of the same type
2601    this should only be called when poly_when_stoned() is true */
2602 void
2603 mon_to_stone(mtmp)
2604 struct monst *mtmp;
2605 {
2606     if (mtmp->data->mlet == S_GOLEM) {
2607         /* it's a golem, and not a stone golem */
2608         if (canseemon(mtmp))
2609 /*JP
2610             pline("%s solidifies...", Monnam(mtmp));
2611 */
2612             pline("%s\82Í\8bÃ\8cÅ\82µ\82½\81D\81D\81D", Monnam(mtmp));
2613         if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) {
2614             if (canseemon(mtmp))
2615 /*JP
2616                 pline("Now it's %s.", an(mtmp->data->mname));
2617 */
2618                 pline("\82È\82ñ\82Æ%s\82É\82È\82Á\82Ä\82µ\82Ü\82Á\82½\81D", mtmp->data->mname);
2619         } else {
2620             if (canseemon(mtmp))
2621 /*JP
2622                 pline("... and returns to normal.");
2623 */
2624                 pline("\81D\81D\81D\82»\82µ\82Ä\95\81\92Ê\82É\96ß\82Á\82½\81D");
2625         }
2626     } else
2627         impossible("Can't polystone %s!", a_monnam(mtmp));
2628 }
2629
2630 boolean
2631 vamp_stone(mtmp)
2632 struct monst *mtmp;
2633 {
2634     if (is_vampshifter(mtmp)) {
2635         int mndx = mtmp->cham;
2636         int x = mtmp->mx, y = mtmp->my;
2637
2638         /* this only happens if shapeshifted */
2639         if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
2640             && !(mvitals[mndx].mvflags & G_GENOD)) {
2641             char buf[BUFSZ];
2642             boolean in_door = (amorphous(mtmp->data)
2643                                && closed_door(mtmp->mx, mtmp->my));
2644
2645             /* construct a format string before transformation */
2646             Sprintf(buf, "The lapidifying %s %s %s",
2647                     x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2648                              (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2649                               | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2650                     amorphous(mtmp->data) ? "coalesces on the"
2651                        : is_flyer(mtmp->data) ? "drops to the"
2652                           : "writhes on the",
2653                     surface(x,y));
2654             mtmp->mcanmove = 1;
2655             mtmp->mfrozen = 0;
2656             if (mtmp->mhpmax <= 0)
2657                 mtmp->mhpmax = 10;
2658             mtmp->mhp = mtmp->mhpmax;
2659             /* this can happen if previously a fog cloud */
2660             if (u.uswallow && (mtmp == u.ustuck))
2661                 expels(mtmp, mtmp->data, FALSE);
2662             if (in_door) {
2663                 coord new_xy;
2664
2665                 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
2666                     rloc_to(mtmp, new_xy.x, new_xy.y);
2667                 }
2668             }
2669             if (canspotmon(mtmp)) {
2670                 pline("%s!", buf);
2671                 display_nhwindow(WIN_MESSAGE, FALSE);
2672             }
2673             newcham(mtmp, &mons[mndx], FALSE, FALSE);
2674             if (mtmp->data == &mons[mndx])
2675                 mtmp->cham = NON_PM;
2676             else
2677                 mtmp->cham = mndx;
2678             if (canspotmon(mtmp)) {
2679                 pline("%s rises from the %s with renewed agility!",
2680                       Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2681             }
2682             newsym(mtmp->mx, mtmp->my);
2683             return FALSE;   /* didn't petrify */
2684         }
2685     }
2686     return TRUE;
2687 }
2688
2689 /* drop monster into "limbo" - that is, migrate to the current level */
2690 void
2691 m_into_limbo(mtmp)
2692 struct monst *mtmp;
2693 {
2694     unstuck(mtmp);
2695     mdrop_special_objs(mtmp);
2696     migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_APPROX_XY, NULL);
2697 }
2698
2699 /* make monster mtmp next to you (if possible);
2700    might place monst on far side of a wall or boulder */
2701 void
2702 mnexto(mtmp)
2703 struct monst *mtmp;
2704 {
2705     coord mm;
2706     boolean couldspot = canspotmon(mtmp);
2707
2708     if (mtmp == u.usteed) {
2709         /* Keep your steed in sync with you instead */
2710         mtmp->mx = u.ux;
2711         mtmp->my = u.uy;
2712         return;
2713     }
2714
2715     if (!enexto(&mm, u.ux, u.uy, mtmp->data)) {
2716         m_into_limbo(mtmp);
2717         return;
2718     }
2719     if (!isok(mm.x, mm.y))
2720         return;
2721     rloc_to(mtmp, mm.x, mm.y);
2722     if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) {
2723         mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */
2724         if (!couldspot && canspotmon(mtmp))
2725 #if 0 /*JP*/
2726             pline("%s suddenly %s!", Amonnam(mtmp),
2727                   !Blind ? "appears" : "arrives");
2728 #else
2729             pline("\93Ë\91R%s\82ª\8c»\82ê\82½\81I", Amonnam(mtmp));
2730 #endif
2731     }
2732     return;
2733 }
2734
2735 /* like mnexto() but requires destination to be directly accessible */
2736 void
2737 maybe_mnexto(mtmp)
2738 struct monst *mtmp;
2739 {
2740     coord mm;
2741     struct permonst *ptr = mtmp->data;
2742     boolean diagok = !NODIAG(ptr - mons);
2743     int tryct = 20;
2744
2745     do {
2746         if (!enexto(&mm, u.ux, u.uy, ptr))
2747             return;
2748         if (couldsee(mm.x, mm.y)
2749             /* don't move grid bugs diagonally */
2750             && (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) {
2751             rloc_to(mtmp, mm.x, mm.y);
2752             return;
2753         }
2754     } while (--tryct > 0);
2755 }
2756
2757 /* mnearto()
2758  * Put monster near (or at) location if possible.
2759  * Returns:
2760  *  true if relocation was successful
2761  *  false otherwise
2762  */
2763 boolean
2764 mnearto(mtmp, x, y, move_other)
2765 register struct monst *mtmp;
2766 xchar x, y;
2767 boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */
2768 {
2769     struct monst *othermon = (struct monst *) 0;
2770     xchar newx, newy;
2771     coord mm;
2772
2773     if (mtmp->mx == x && mtmp->my == y)
2774         return TRUE;
2775
2776     if (move_other && (othermon = m_at(x, y)) != 0) {
2777         if (othermon->wormno)
2778             remove_worm(othermon);
2779         else
2780             remove_monster(x, y);
2781     }
2782
2783     newx = x;
2784     newy = y;
2785     if (!goodpos(newx, newy, mtmp, 0)) {
2786         /* Actually we have real problems if enexto ever fails.
2787          * Migrating_mons that need to be placed will cause
2788          * no end of trouble.
2789          */
2790         if (!enexto(&mm, newx, newy, mtmp->data))
2791             return FALSE;
2792         if (!isok(mm.x,mm.y))
2793             return FALSE;
2794         newx = mm.x;
2795         newy = mm.y;
2796     }
2797     rloc_to(mtmp, newx, newy);
2798
2799     if (move_other && othermon) {
2800         xchar oldx = othermon->mx, oldy = othermon->my;
2801
2802         othermon->mx = othermon->my = 0;
2803         (void) mnearto(othermon, x, y, FALSE);
2804         if (othermon->mx == 0 && othermon->my == 0) {
2805             /* reloc failed */
2806             othermon->mx = oldx;
2807             othermon->my = oldy;
2808             m_into_limbo(othermon);
2809         }
2810     }
2811
2812     return TRUE;
2813 }
2814
2815 /* monster responds to player action; not the same as a passive attack;
2816    assumes reason for response has been tested, and response _must_ be made */
2817 void
2818 m_respond(mtmp)
2819 struct monst *mtmp;
2820 {
2821     if (mtmp->data->msound == MS_SHRIEK) {
2822         if (!Deaf) {
2823 /*JP
2824             pline("%s shrieks.", Monnam(mtmp));
2825 */
2826             pline("%s\82Í\8bà\90Ø\82è\90º\82ð\82 \82°\82½\81D", Monnam(mtmp));
2827             stop_occupation();
2828         }
2829         if (!rn2(10)) {
2830             if (!rn2(13))
2831                 (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
2832             else
2833                 (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS);
2834         }
2835         aggravate();
2836     }
2837     if (mtmp->data == &mons[PM_MEDUSA]) {
2838         register int i;
2839
2840         for (i = 0; i < NATTK; i++)
2841             if (mtmp->data->mattk[i].aatyp == AT_GAZE) {
2842                 (void) gazemu(mtmp, &mtmp->data->mattk[i]);
2843                 break;
2844             }
2845     }
2846 }
2847
2848 /* Called whenever the player attacks mtmp; also called in other situations
2849    where mtmp gets annoyed at the player. Handles mtmp getting annoyed at the
2850    attack and any ramifications that might have. Useful also in situations
2851    where mtmp was already hostile; it checks for situations where the player
2852    shouldn't be attacking and any ramifications /that/ might have. */
2853 void
2854 setmangry(mtmp, via_attack)
2855 struct monst *mtmp;
2856 boolean via_attack;
2857 {
2858     if (via_attack && sengr_at("Elbereth", u.ux, u.uy, TRUE)) {
2859         You_feel("like a hypocrite.");
2860         /* AIS: Yes, I know alignment penalties and bonuses aren't balanced
2861            at the moment. This is about correct relative to other "small"
2862            penalties; it should be fairly large, as attacking while standing
2863            on an Elbereth means that you're requesting peace and then
2864            violating your own request. I know 5 isn't actually large, but
2865            it's intentionally larger than the 1s and 2s that are normally
2866            given for this sort of thing. */
2867         adjalign(-5);
2868
2869         if (!Blind)
2870             pline("The engraving beneath you fades.");
2871         del_engr_at(u.ux, u.uy);
2872     }
2873
2874     /* AIS: Should this be in both places, or just in wakeup()? */
2875     mtmp->mstrategy &= ~STRAT_WAITMASK;
2876     if (!mtmp->mpeaceful)
2877         return;
2878     if (mtmp->mtame)
2879         return;
2880     mtmp->mpeaceful = 0;
2881     if (mtmp->ispriest) {
2882         if (p_coaligned(mtmp))
2883             adjalign(-5); /* very bad */
2884         else
2885             adjalign(2);
2886     } else
2887         adjalign(-1); /* attacking peaceful monsters is bad */
2888     if (couldsee(mtmp->mx, mtmp->my)) {
2889         if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
2890 /*JP
2891             pline("%s gets angry!", Monnam(mtmp));
2892 */
2893             pline("%s\82Í\93{\82Á\82½\81I", Monnam(mtmp));
2894         else if (flags.verbose && !Deaf)
2895             growl(mtmp);
2896     }
2897
2898     /* attacking your own quest leader will anger his or her guardians */
2899     if (!context.mon_moving /* should always be the case here */
2900         && mtmp->data == &mons[quest_info(MS_LEADER)]) {
2901         struct monst *mon;
2902         struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
2903         int got_mad = 0;
2904
2905         /* guardians will sense this attack even if they can't see it */
2906         for (mon = fmon; mon; mon = mon->nmon) {
2907             if (DEADMONSTER(mon))
2908                 continue;
2909             if (mon->data == q_guardian && mon->mpeaceful) {
2910                 mon->mpeaceful = 0;
2911                 if (canseemon(mon))
2912                     ++got_mad;
2913             }
2914         }
2915         if (got_mad && !Hallucination) {
2916             const char *who = q_guardian->mname;
2917
2918 #if 0 /*JP*/
2919             if (got_mad > 1)
2920                 who = makeplural(who);
2921             pline_The("%s %s to be angry too...",
2922                       who, vtense(who, "appear"));
2923 #else
2924             pline("%s\82à\93{\82Á\82½\82æ\82¤\82¾\81D\81D\81D", who);
2925 #endif
2926         }
2927     }
2928
2929     /* make other peaceful monsters react */
2930     if (!context.mon_moving) {
2931         static const char *const Exclam[] = {
2932             "Gasp!", "Uh-oh.", "Oh my!", "What?", "Why?",
2933         };
2934         struct monst *mon;
2935         int mndx = monsndx(mtmp->data);
2936
2937         for (mon = fmon; mon; mon = mon->nmon) {
2938             if (DEADMONSTER(mon))
2939                 continue;
2940             if (mon == mtmp) /* the mpeaceful test catches this since mtmp */
2941                 continue;    /* is no longer peaceful, but be explicit...  */
2942
2943             if (!mindless(mon->data) && mon->mpeaceful
2944                 && couldsee(mon->mx, mon->my) && !mon->msleeping
2945                 && mon->mcansee && m_canseeu(mon)) {
2946                 boolean exclaimed = FALSE;
2947
2948                 if (humanoid(mon->data) || mon->isshk || mon->ispriest) {
2949                     if (is_watch(mon->data)) {
2950                         verbalize("Halt!  You're under arrest!");
2951                         (void) angry_guards(!!Deaf);
2952                     } else {
2953                         if (!rn2(5)) {
2954                             verbalize("%s", Exclam[mon->m_id % SIZE(Exclam)]);
2955                             exclaimed = TRUE;
2956                         }
2957                         /* shopkeepers and temple priests might gasp in
2958                            surprise, but they won't become angry here */
2959                         if (mon->isshk || mon->ispriest)
2960                             continue;
2961
2962                         if (mon->data->mlevel < rn2(10)) {
2963                             monflee(mon, rn2(50) + 25, TRUE, !exclaimed);
2964                             exclaimed = TRUE;
2965                         }
2966                         if (mon->mtame) {
2967                             /* mustn't set mpeaceful to 0 as below;
2968                                perhaps reduce tameness? */
2969                         } else {
2970                             mon->mpeaceful = 0;
2971                             adjalign(-1);
2972                             if (!exclaimed)
2973                                 pline("%s gets angry!", Monnam(mon));
2974                         }
2975                     }
2976                 } else if (mon->data->mlet == mtmp->data->mlet
2977                            && big_little_match(mndx, monsndx(mon->data))
2978                            && !rn2(3)) {
2979                     if (!rn2(4)) {
2980                         growl(mon);
2981                         exclaimed = TRUE;
2982                     }
2983                     if (rn2(6))
2984                         monflee(mon, rn2(25) + 15, TRUE, !exclaimed);
2985                 }
2986             }
2987         }
2988     }
2989 }
2990
2991 /* wake up a monster, possibly making it angry in the process */
2992 void
2993 wakeup(mtmp, via_attack)
2994 register struct monst *mtmp;
2995 boolean via_attack;
2996 {
2997     mtmp->msleeping = 0;
2998     if (mtmp->m_ap_type) {
2999         seemimic(mtmp);
3000     } else if (context.forcefight && !context.mon_moving
3001                && mtmp->mundetected) {
3002         mtmp->mundetected = 0;
3003         newsym(mtmp->mx, mtmp->my);
3004     }
3005     finish_meating(mtmp);
3006     if (via_attack)
3007         setmangry(mtmp, TRUE);
3008 }
3009
3010 /* Wake up nearby monsters without angering them. */
3011 void
3012 wake_nearby()
3013 {
3014     register struct monst *mtmp;
3015
3016     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3017         if (DEADMONSTER(mtmp))
3018             continue;
3019         if (distu(mtmp->mx, mtmp->my) < u.ulevel * 20) {
3020             mtmp->msleeping = 0;
3021             if (!unique_corpstat(mtmp->data))
3022                 mtmp->mstrategy &= ~STRAT_WAITMASK;
3023             if (mtmp->mtame) {
3024                 if (!mtmp->isminion)
3025                     EDOG(mtmp)->whistletime = moves;
3026                 /* Clear mtrack. This is to fix up a pet who is
3027                    stuck "fleeing" its master. */
3028                 memset(mtmp->mtrack, 0, sizeof(mtmp->mtrack));
3029             }
3030         }
3031     }
3032 }
3033
3034 /* Wake up monsters near some particular location. */
3035 void
3036 wake_nearto(x, y, distance)
3037 register int x, y, distance;
3038 {
3039     register struct monst *mtmp;
3040
3041     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3042         if (DEADMONSTER(mtmp))
3043             continue;
3044         if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
3045             mtmp->msleeping = 0;
3046             if (!unique_corpstat(mtmp->data))
3047                 mtmp->mstrategy &= ~STRAT_WAITMASK;
3048         }
3049     }
3050 }
3051
3052 /* NOTE: we must check for mimicry before calling this routine */
3053 void
3054 seemimic(mtmp)
3055 register struct monst *mtmp;
3056 {
3057     boolean is_blocker_appear = (is_lightblocker_mappear(mtmp));
3058
3059     if (has_mcorpsenm(mtmp))
3060         freemcorpsenm(mtmp);
3061
3062     mtmp->m_ap_type = M_AP_NOTHING;
3063     mtmp->mappearance = 0;
3064
3065     /*
3066      *  Discovered mimics don't block light.
3067      */
3068     if (is_blocker_appear
3069         && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
3070         unblock_point(mtmp->mx, mtmp->my);
3071
3072     newsym(mtmp->mx, mtmp->my);
3073 }
3074
3075 /* force all chameleons to become normal */
3076 void
3077 rescham()
3078 {
3079     register struct monst *mtmp;
3080     int mcham;
3081
3082     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3083         if (DEADMONSTER(mtmp))
3084             continue;
3085         mcham = (int) mtmp->cham;
3086         if (mcham >= LOW_PM) {
3087             (void) newcham(mtmp, &mons[mcham], FALSE, FALSE);
3088             mtmp->cham = NON_PM;
3089         }
3090         if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
3091             new_were(mtmp);
3092         if (mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) {
3093             seemimic(mtmp);
3094             /* we pretend that the mimic doesn't
3095                know that it has been unmasked */
3096             mtmp->msleeping = 1;
3097         }
3098     }
3099 }
3100
3101 /* Let the chameleons change again -dgk */
3102 void
3103 restartcham()
3104 {
3105     register struct monst *mtmp;
3106
3107     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3108         if (DEADMONSTER(mtmp))
3109             continue;
3110         mtmp->cham = pm_to_cham(monsndx(mtmp->data));
3111         if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping
3112             && cansee(mtmp->mx, mtmp->my)) {
3113             set_mimic_sym(mtmp);
3114             newsym(mtmp->mx, mtmp->my);
3115         }
3116     }
3117 }
3118
3119 /* called when restoring a monster from a saved level; protection
3120    against shape-changing might be different now than it was at the
3121    time the level was saved. */
3122 void
3123 restore_cham(mon)
3124 struct monst *mon;
3125 {
3126     int mcham;
3127
3128     if (Protection_from_shape_changers) {
3129         mcham = (int) mon->cham;
3130         if (mcham >= LOW_PM) {
3131             mon->cham = NON_PM;
3132             (void) newcham(mon, &mons[mcham], FALSE, FALSE);
3133         } else if (is_were(mon->data) && !is_human(mon->data)) {
3134             new_were(mon);
3135         }
3136     } else if (mon->cham == NON_PM) {
3137         mon->cham = pm_to_cham(monsndx(mon->data));
3138     }
3139 }
3140
3141 /* unwatched hiders may hide again; if so, returns True */
3142 STATIC_OVL boolean
3143 restrap(mtmp)
3144 register struct monst *mtmp;
3145 {
3146     struct trap *t;
3147
3148     if (mtmp->mcan || mtmp->m_ap_type || cansee(mtmp->mx, mtmp->my)
3149         || rn2(3) || mtmp == u.ustuck
3150         /* can't hide while trapped except in pits */
3151         || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
3152             && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))
3153         || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
3154         return FALSE;
3155
3156     if (mtmp->data->mlet == S_MIMIC) {
3157         set_mimic_sym(mtmp);
3158         return TRUE;
3159     } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) {
3160         mtmp->mundetected = 1;
3161         return TRUE;
3162     }
3163
3164     return FALSE;
3165 }
3166
3167 /* monster/hero tries to hide under something at the current location */
3168 boolean
3169 hideunder(mtmp)
3170 struct monst *mtmp;
3171 {
3172     struct trap *t;
3173     boolean undetected = FALSE, is_u = (mtmp == &youmonst);
3174     xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
3175
3176     if (mtmp == u.ustuck) {
3177         ; /* can't hide if holding you or held by you */
3178     } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
3179                     : (mtmp->mtrapped && (t = t_at(x, y)) != 0
3180                        && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) {
3181         ; /* can't hide while stuck in a non-pit trap */
3182     } else if (mtmp->data->mlet == S_EEL) {
3183         undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
3184     } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
3185         struct obj *otmp = level.objects[x][y];
3186
3187         /* most monsters won't hide under cockatrice corpse */
3188         if (otmp->nexthere || otmp->otyp != CORPSE
3189             || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp))
3190             || !touch_petrifies(&mons[otmp->corpsenm]))
3191             undetected = TRUE;
3192     }
3193
3194     if (is_u)
3195         u.uundetected = undetected;
3196     else
3197         mtmp->mundetected = undetected;
3198     return undetected;
3199 }
3200
3201 /* called when returning to a previously visited level */
3202 void
3203 hide_monst(mon)
3204 struct monst *mon;
3205 {
3206     boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL;
3207
3208     if ((is_hider(mon->data) || hider_under)
3209         && !(mon->mundetected || mon->m_ap_type)) {
3210         xchar x = mon->mx, y = mon->my;
3211         char save_viz = viz_array[y][x];
3212
3213         /* override vision, forcing hero to be unable to see monster's spot */
3214         viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE);
3215         if (is_hider(mon->data))
3216             (void) restrap(mon);
3217         /* try again if mimic missed its 1/3 chance to hide */
3218         if (mon->data->mlet == S_MIMIC && !mon->m_ap_type)
3219             (void) restrap(mon);
3220         if (hider_under)
3221             (void) hideunder(mon);
3222         viz_array[y][x] = save_viz;
3223     }
3224 }
3225
3226 static short *animal_list = 0; /* list of PM values for animal monsters */
3227 static int animal_list_count;
3228
3229 void
3230 mon_animal_list(construct)
3231 boolean construct;
3232 {
3233     if (construct) {
3234         short animal_temp[SPECIAL_PM];
3235         int i, n;
3236
3237         /* if (animal_list) impossible("animal_list already exists"); */
3238
3239         for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
3240             if (is_animal(&mons[i]))
3241                 animal_temp[n++] = i;
3242         /* if (n == 0) animal_temp[n++] = NON_PM; */
3243
3244         animal_list = (short *) alloc(n * sizeof *animal_list);
3245         (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp,
3246                       n * sizeof *animal_list);
3247         animal_list_count = n;
3248     } else { /* release */
3249         if (animal_list)
3250             free((genericptr_t) animal_list), animal_list = 0;
3251         animal_list_count = 0;
3252     }
3253 }
3254
3255 STATIC_OVL int
3256 pick_animal()
3257 {
3258     int res;
3259
3260     if (!animal_list)
3261         mon_animal_list(TRUE);
3262
3263     res = animal_list[rn2(animal_list_count)];
3264     /* rogue level should use monsters represented by uppercase letters
3265        only, but since chameleons aren't generated there (not uppercase!)
3266        we don't perform a lot of retries */
3267     if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet))
3268         res = animal_list[rn2(animal_list_count)];
3269     return res;
3270 }
3271
3272 void
3273 decide_to_shapeshift(mon, shiftflags)
3274 struct monst *mon;
3275 int shiftflags;
3276 {
3277     struct permonst *ptr = 0;
3278     int mndx;
3279     unsigned was_female = mon->female;
3280     boolean msg = FALSE, dochng = FALSE;
3281
3282     if ((shiftflags & SHIFT_MSG)
3283         || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon)))
3284         msg = TRUE;
3285
3286     if (!is_vampshifter(mon)) {
3287         /* regular shapeshifter */
3288         if (!rn2(6))
3289             dochng = TRUE;
3290     } else {
3291         /* The vampire has to be in good health (mhp) to maintain
3292          * its shifted form.
3293          *
3294          * If we're shifted and getting low on hp, maybe shift back, or
3295          * if we're a fog cloud at full hp, maybe pick a different shape.
3296          * If we're not already shifted and in good health, maybe shift.
3297          */
3298         if (mon->data->mlet != S_VAMPIRE) {
3299             if ((mon->mhp <= (mon->mhpmax + 5) / 6) && rn2(4)
3300                 && mon->cham >= LOW_PM) {
3301                 ptr = &mons[mon->cham];
3302                 dochng = TRUE;
3303             } else if (mon->data == &mons[PM_FOG_CLOUD]
3304                      && mon->mhp == mon->mhpmax && !rn2(4)
3305                      && (!canseemon(mon)
3306                          || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM)) {
3307                 /* if a fog cloud, maybe change to wolf or vampire bat;
3308                    those are more likely to take damage--at least when
3309                    tame--and then switch back to vampire; they'll also
3310                    switch to fog cloud if they encounter a closed door */
3311                 mndx = pickvampshape(mon);
3312                 if (mndx >= LOW_PM) {
3313                     ptr = &mons[mndx];
3314                     dochng = (ptr != mon->data);
3315                 }
3316             }
3317         } else {
3318             if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6)
3319                 && (!canseemon(mon)
3320                     || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM))
3321                 dochng = TRUE; /* 'ptr' stays Null */
3322         }
3323     }
3324     if (dochng) {
3325         if (newcham(mon, ptr, FALSE, msg) && is_vampshifter(mon)) {
3326             /* for vampshift, override the 10% chance for sex change */
3327             ptr = mon->data;
3328             if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr))
3329                 mon->female = was_female;
3330         }
3331     }
3332 }
3333
3334 STATIC_OVL int
3335 pickvampshape(mon)
3336 struct monst *mon;
3337 {
3338     int mndx = mon->cham, wolfchance = 10;
3339     /* avoid picking monsters with lowercase display symbols ('d' for wolf
3340        and 'v' for fog cloud) on rogue level*/
3341     boolean uppercase_only = Is_rogue_level(&u.uz);
3342
3343     switch (mndx) {
3344     case PM_VLAD_THE_IMPALER:
3345         /* ensure Vlad can keep carrying the Candelabrum */
3346         if (mon_has_special(mon))
3347             break; /* leave mndx as is */
3348         wolfchance = 3;
3349     /*FALLTHRU*/
3350     case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */
3351         if (!rn2(wolfchance) && !uppercase_only) {
3352             mndx = PM_WOLF;
3353             break;
3354         }
3355     /*FALLTHRU*/
3356     case PM_VAMPIRE: /* any vampire can become fog or bat */
3357         mndx = (!rn2(4) && !uppercase_only) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
3358         break;
3359     }
3360     return mndx;
3361 }
3362
3363 /* nonshapechangers who warrant special polymorph handling */
3364 STATIC_OVL boolean
3365 isspecmon(mon)
3366 struct monst *mon;
3367 {
3368     return (mon->isshk || mon->ispriest || mon->isgd
3369             || mon->m_id == quest_status.leader_m_id);
3370 }
3371
3372 /* restrict certain special monsters (shopkeepers, aligned priests,
3373    vault guards) to forms that allow them to behave sensibly (catching
3374    gold, speaking?) so that they don't need too much extra code */
3375 STATIC_OVL boolean
3376 validspecmon(mon, mndx)
3377 struct monst *mon;
3378 int mndx;
3379 {
3380     if (mndx == NON_PM)
3381         return TRUE; /* caller wants random */
3382
3383     if (!accept_newcham_form(mndx))
3384         return FALSE; /* geno'd or !polyok */
3385
3386     if (isspecmon(mon)) {
3387         struct permonst *ptr = &mons[mndx];
3388
3389         /* reject notake because object manipulation is expected
3390            and nohead because speech capability is expected */
3391         if (notake(ptr) || !has_head(ptr))
3392             return FALSE;
3393         /* [should we check ptr->msound here too?] */
3394     }
3395     return TRUE; /* potential new form is ok */
3396 }
3397
3398 /* prevent wizard mode user from specifying invalid vampshifter shape */
3399 boolean
3400 validvamp(mon, mndx_p, monclass)
3401 struct monst *mon;
3402 int *mndx_p, monclass;
3403 {
3404     /* simplify caller's usage */
3405     if (!is_vampshifter(mon))
3406         return validspecmon(mon, *mndx_p);
3407
3408     if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD
3409         || *mndx_p == PM_VLAD_THE_IMPALER) {
3410         /* player picked some type of vampire; use mon's self */
3411         *mndx_p = mon->cham;
3412         return TRUE;
3413     }
3414     if (mon->cham == PM_VLAD_THE_IMPALER && mon_has_special(mon)) {
3415         /* Vlad with Candelabrum; override choice, then accept it */
3416         *mndx_p = PM_VLAD_THE_IMPALER;
3417         return TRUE;
3418     }
3419     /* basic vampires can't become wolves; any can become fog or bat
3420        (we don't enforce upper-case only for rogue level here) */
3421     if (*mndx_p == PM_WOLF)
3422         return (boolean) (mon->cham != PM_VAMPIRE);
3423     if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT)
3424         return TRUE;
3425
3426     /* if we get here, specific type was no good; try by class */
3427     switch (monclass) {
3428     case S_VAMPIRE:
3429         *mndx_p = mon->cham;
3430         break;
3431     case S_BAT:
3432         *mndx_p = PM_VAMPIRE_BAT;
3433         break;
3434     case S_VORTEX:
3435         *mndx_p = PM_FOG_CLOUD;
3436         break;
3437     case S_DOG:
3438         if (mon->cham != PM_VAMPIRE) {
3439             *mndx_p = PM_WOLF;
3440             break;
3441         }
3442     /*FALLTHRU*/
3443     default:
3444         *mndx_p = NON_PM;
3445         break;
3446     }
3447     return (boolean) (*mndx_p != NON_PM);
3448 }
3449
3450 int
3451 select_newcham_form(mon)
3452 struct monst *mon;
3453 {
3454     int mndx = NON_PM, tryct;
3455
3456     switch (mon->cham) {
3457     case PM_SANDESTIN:
3458         if (rn2(7))
3459             mndx = pick_nasty();
3460         break;
3461     case PM_DOPPELGANGER:
3462         if (!rn2(7)) {
3463             mndx = pick_nasty();
3464         } else if (rn2(3)) { /* role monsters */
3465             mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
3466         } else if (!rn2(3)) { /* quest guardians */
3467             mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT);
3468             /* avoid own role's guardian */
3469             if (mndx == urole.guardnum)
3470                 mndx = NON_PM;
3471         } else { /* general humanoids */
3472             tryct = 5;
3473             do {
3474                 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3475                 if (humanoid(&mons[mndx]) && polyok(&mons[mndx]))
3476                     break;
3477             } while (--tryct > 0);
3478             if (!tryct)
3479                 mndx = NON_PM;
3480         }
3481         break;
3482     case PM_CHAMELEON:
3483         if (!rn2(3))
3484             mndx = pick_animal();
3485         break;
3486     case PM_VLAD_THE_IMPALER:
3487     case PM_VAMPIRE_LORD:
3488     case PM_VAMPIRE:
3489         mndx = pickvampshape(mon);
3490         break;
3491     case NON_PM: /* ordinary */
3492       {
3493         struct obj *m_armr = which_armor(mon, W_ARM);
3494
3495         if (m_armr && Is_dragon_scales(m_armr))
3496             mndx = (int) (Dragon_scales_to_pm(m_armr) - mons);
3497         else if (m_armr && Is_dragon_mail(m_armr))
3498             mndx = (int) (Dragon_mail_to_pm(m_armr) - mons);
3499       }
3500         break;
3501     }
3502
3503     /* for debugging: allow control of polymorphed monster */
3504     if (wizard && iflags.mon_polycontrol) {
3505         char pprompt[BUFSZ], buf[BUFSZ] = DUMMY;
3506         int monclass;
3507
3508         Sprintf(pprompt, "Change %s @ %s into what kind of monster?",
3509                 noit_mon_nam(mon),
3510                 coord_desc((int) mon->mx, (int) mon->my, buf,
3511                            (iflags.getpos_coords != GPCOORDS_NONE)
3512                               ? iflags.getpos_coords : GPCOORDS_MAP));
3513         tryct = 5;
3514         do {
3515             monclass = 0;
3516             getlin(pprompt, buf);
3517             mungspaces(buf);
3518             /* for ESC, take form selected above (might be NON_PM) */
3519             if (*buf == '\033')
3520                 break;
3521             /* for "*", use NON_PM to pick an arbitrary shape below */
3522             if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
3523                 mndx = NON_PM;
3524                 break;
3525             }
3526             mndx = name_to_mon(buf);
3527             if (mndx == NON_PM) {
3528                 /* didn't get a type, so check whether it's a class
3529                    (single letter or text match with def_monsyms[]) */
3530                 monclass = name_to_monclass(buf, &mndx);
3531                 if (monclass && mndx == NON_PM)
3532                     mndx = mkclass_poly(monclass);
3533             }
3534             if (mndx >= LOW_PM) {
3535                 /* got a specific type of monster; use it if we can */
3536                 if (validvamp(mon, &mndx, monclass))
3537                     break;
3538                 /* can't; revert to random in case we exhaust tryct */
3539                 mndx = NON_PM;
3540             }
3541
3542             pline("It can't become that.");
3543         } while (--tryct > 0);
3544         if (!tryct)
3545             pline1(thats_enough_tries);
3546         if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass))
3547             mndx = pickvampshape(mon); /* don't resort to arbitrary */
3548     }
3549
3550     /* if no form was specified above, pick one at random now */
3551     if (mndx == NON_PM) {
3552         tryct = 50;
3553         do {
3554             mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3555         } while (--tryct > 0 && !validspecmon(mon, mndx)
3556                  /* try harder to select uppercase monster on rogue level */
3557                  && (tryct > 40 && Is_rogue_level(&u.uz)
3558                      && !isupper((uchar) mons[mndx].mlet)));
3559     }
3560     return mndx;
3561 }
3562
3563 /* this used to be inline within newcham() but monpolycontrol needs it too */
3564 STATIC_OVL struct permonst *
3565 accept_newcham_form(mndx)
3566 int mndx;
3567 {
3568     struct permonst *mdat;
3569
3570     if (mndx == NON_PM)
3571         return 0;
3572     mdat = &mons[mndx];
3573     if ((mvitals[mndx].mvflags & G_GENOD) != 0)
3574         return 0;
3575     if (is_placeholder(mdat))
3576         return 0;
3577     /* select_newcham_form() might deliberately pick a player
3578        character type (random selection never does) which
3579        polyok() rejects, so we need a special case here */
3580     if (is_mplayer(mdat))
3581         return mdat;
3582     /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */
3583     return polyok(mdat) ? mdat : 0;
3584 }
3585
3586 void
3587 mgender_from_permonst(mtmp, mdat)
3588 struct monst *mtmp;
3589 struct permonst *mdat;
3590 {
3591     if (is_male(mdat)) {
3592         if (mtmp->female)
3593             mtmp->female = FALSE;
3594     } else if (is_female(mdat)) {
3595         if (!mtmp->female)
3596             mtmp->female = TRUE;
3597     } else if (!is_neuter(mdat)) {
3598         if (!rn2(10))
3599             mtmp->female = !mtmp->female;
3600     }
3601 }
3602
3603 /* make a chameleon take on another shape, or a polymorph target
3604    (possibly self-inflicted) become a different monster;
3605    returns 1 if it actually changes form */
3606 int
3607 newcham(mtmp, mdat, polyspot, msg)
3608 struct monst *mtmp;
3609 struct permonst *mdat;
3610 boolean polyspot; /* change is the result of wand or spell of polymorph */
3611 boolean msg;      /* "The oldmon turns into a newmon!" */
3612 {
3613     int hpn, hpd;
3614     int mndx, tryct;
3615     struct permonst *olddata = mtmp->data;
3616     char *p, oldname[BUFSZ], l_oldname[BUFSZ], newname[BUFSZ];
3617
3618     /* Riders are immune to polymorph and green slime
3619        (but apparent Rider might actually be a doppelganger) */
3620     if (mtmp->cham == NON_PM) { /* not a shapechanger */
3621         if (is_rider(olddata))
3622             return 0;
3623         /* make Nazgul and erinyes immune too, to reduce chance of
3624            anomalous extinction feedback during final disclsoure */
3625         if (mbirth_limit(monsndx(olddata)) < MAXMONNO)
3626             return 0;
3627     }
3628
3629     if (msg) {
3630         /* like Monnam() but never mention saddle */
3631         Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3632                                  SUPPRESS_SADDLE, FALSE));
3633         oldname[0] = highc(oldname[0]);
3634     }
3635     /* we need this one whether msg is true or not */
3636     Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3637                                has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE));
3638
3639     /* mdat = 0 -> caller wants a random monster shape */
3640     if (mdat == 0) {
3641         /* select_newcham_form() loops when resorting to random but
3642            it doesn't always pick that so we still retry here too */
3643         tryct = 20;
3644         do {
3645             mndx = select_newcham_form(mtmp);
3646             mdat = accept_newcham_form(mndx);
3647             /* for the first several tries we require upper-case on
3648                the rogue level (after that, we take whatever we get) */
3649             if (tryct > 15 && Is_rogue_level(&u.uz)
3650                 && mdat && !isupper((uchar) mdat->mlet))
3651                 mdat = 0;
3652             if (mdat)
3653                 break;
3654         } while (--tryct > 0);
3655         if (!tryct)
3656             return 0;
3657     } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
3658         return 0; /* passed in mdat is genocided */
3659
3660     if (mdat == olddata)
3661         return 0; /* still the same monster */
3662
3663     mgender_from_permonst(mtmp, mdat);
3664     /* Endgame mplayers start out as "Foo the Bar", but some of the
3665      * titles are inappropriate when polymorphed, particularly into
3666      * the opposite sex.  Player characters don't use ranks when
3667      * polymorphed, so dropping rank for mplayers seems reasonable.
3668      */
3669     if (In_endgame(&u.uz) && is_mplayer(olddata)
3670         && has_mname(mtmp) && (p = strstr(MNAME(mtmp), " the ")) != 0)
3671         *p = '\0';
3672
3673     if (mtmp->wormno) { /* throw tail away */
3674         wormgone(mtmp);
3675         place_monster(mtmp, mtmp->mx, mtmp->my);
3676     }
3677     if (mtmp->m_ap_type && mdat->mlet != S_MIMIC)
3678         seemimic(mtmp); /* revert to normal monster */
3679
3680     /* (this code used to try to adjust the monster's health based on
3681        a normal one of its type but there are too many special cases
3682        which need to handled in order to do that correctly, so just
3683        give the new form the same proportion of HP as its old one had) */
3684     hpn = mtmp->mhp;
3685     hpd = mtmp->mhpmax;
3686     /* set level and hit points */
3687     newmonhp(mtmp, monsndx(mdat));
3688     /* new hp: same fraction of max as before */
3689 #ifndef LINT
3690     mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd);
3691 #endif
3692     /* sanity check (potential overflow) */
3693     if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax)
3694         mtmp->mhp = mtmp->mhpmax;
3695     /* unlikely but not impossible; a 1HD creature with 1HP that changes
3696        into a 0HD creature will require this statement */
3697     if (!mtmp->mhp)
3698         mtmp->mhp = 1;
3699
3700     /* take on the new form... */
3701     set_mon_data(mtmp, mdat, 0);
3702
3703     if (emits_light(olddata) != emits_light(mtmp->data)) {
3704         /* used to give light, now doesn't, or vice versa,
3705            or light's range has changed */
3706         if (emits_light(olddata))
3707             del_light_source(LS_MONSTER, monst_to_any(mtmp));
3708         if (emits_light(mtmp->data))
3709             new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
3710                              LS_MONSTER, monst_to_any(mtmp));
3711     }
3712     if (!mtmp->perminvis || pm_invisible(olddata))
3713         mtmp->perminvis = pm_invisible(mdat);
3714     mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
3715     if (mtmp->mundetected)
3716         (void) hideunder(mtmp);
3717     if (u.ustuck == mtmp) {
3718         if (u.uswallow) {
3719             if (!attacktype(mdat, AT_ENGL)) {
3720                 /* Does mdat care? */
3721                 if (!noncorporeal(mdat) && !amorphous(mdat)
3722                     && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) {
3723                     char msgtrail[BUFSZ];
3724
3725                     if (is_vampshifter(mtmp)) {
3726                         Sprintf(msgtrail, " which was a shapeshifted %s",
3727                                 noname_monnam(mtmp, ARTICLE_NONE));
3728                     } else if (is_animal(mdat)) {
3729 /*JP
3730                         Strcpy(msgtrail, "'s stomach");
3731 */
3732                         Strcpy(msgtrail, "\82Ì\88Ý");
3733                     } else {
3734                         msgtrail[0] = '\0';
3735                     }
3736
3737                     /* Do this even if msg is FALSE */
3738 #if 0 /*JP*/
3739                     You("%s %s%s!",
3740                         (amorphous(olddata) || is_whirly(olddata))
3741                             ? "emerge from" : "break out of",
3742                         l_oldname, msgtrail);
3743 #else
3744                     You("%s%s%s\81I", l_oldname, msgtrail,
3745                         (amorphous(olddata) || is_whirly(olddata))
3746                             ? "\82©\82ç\94ò\82Ñ\8fo\82µ\82½" : "\82ð\94j\82è\8fo\82½"
3747                         );
3748 #endif
3749                     msg = FALSE; /* message has been given */
3750                     mtmp->mhp = 1; /* almost dead */
3751                 }
3752                 expels(mtmp, olddata, FALSE);
3753             } else {
3754                 /* update swallow glyphs for new monster */
3755                 swallowed(0);
3756             }
3757         } else if (!sticks(mdat) && !sticks(youmonst.data))
3758             unstuck(mtmp);
3759     }
3760
3761 #ifndef DCC30_BUG
3762     if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
3763 #else
3764     /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
3765      * same expression.
3766      */
3767     if (mdat == &mons[PM_LONG_WORM]
3768         && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
3769 #endif
3770         /* we can now create worms with tails - 11/91 */
3771         initworm(mtmp, rn2(5));
3772         if (count_wsegs(mtmp))
3773             place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
3774     }
3775
3776     newsym(mtmp->mx, mtmp->my);
3777
3778     if (msg) {
3779         Strcpy(newname, noname_monnam(mtmp, ARTICLE_A));
3780         /* oldname was capitalized above; newname will be lower case */
3781 #if 0 /*JP*/
3782         if (!strcmpi(newname, "it")) { /* can't see or sense it now */
3783 #else
3784         if (!strcmpi(newname, "\89½\8eÒ\82©")) { /* can't see or sense it now */
3785 #endif
3786 #if 0 /*JP*/
3787             if (!!strcmpi(oldname, "it")) /* could see or sense it before */
3788 #else
3789             if (!!strcmpi(oldname, "\89½\8eÒ\82©")) /* could see or sense it before */
3790 #endif
3791                 pline("%s disappears!", oldname);
3792             (void) usmellmon(mdat);
3793         } else { /* can see or sense it now */
3794 #if 0 /*JP*/
3795             if (!strcmpi(oldname, "it")) /* couldn't see or sense it before */
3796 #else
3797             if (!strcmpi(oldname, "\89½\8eÒ\82©")) /* couldn't see or sense it before */
3798 #endif
3799                 pline("%s appears!", upstart(newname));
3800             else
3801 /*JP
3802             pline("%s turns into %s!", oldname, newname);
3803 */
3804             pline("%s\82Í%s\82É\82È\82Á\82½\81I", oldname, newname);
3805         }
3806     }
3807
3808     /* when polymorph trap/wand/potion produces a vampire, turn in into
3809        a full-fledged vampshifter unless shape-changing is blocked */
3810     if (mtmp->cham == NON_PM && mdat->mlet == S_VAMPIRE
3811         && !Protection_from_shape_changers)
3812         mtmp->cham = pm_to_cham(monsndx(mdat));
3813
3814     possibly_unwield(mtmp, polyspot); /* might lose use of weapon */
3815     mon_break_armor(mtmp, polyspot);
3816     if (!(mtmp->misc_worn_check & W_ARMG))
3817 #if 0 /*JP*/
3818         mselftouch(mtmp, "No longer petrify-resistant, ",
3819                    !context.mon_moving);
3820 #else
3821         mselftouch(mtmp, "\90Î\89»\82Ö\82Ì\92ï\8dR\97Í\82ª\82È\82­\82È\82Á\82Ä\81C",
3822                    !context.mon_moving);
3823 #endif
3824     m_dowear(mtmp, FALSE);
3825
3826     /* This ought to re-test can_carry() on each item in the inventory
3827      * rather than just checking ex-giants & boulders, but that'd be
3828      * pretty expensive to perform.  If implemented, then perhaps
3829      * minvent should be sorted in order to drop heaviest items first.
3830      */
3831     /* former giants can't continue carrying boulders */
3832     if (mtmp->minvent && !throws_rocks(mdat)) {
3833         register struct obj *otmp, *otmp2;
3834
3835         for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
3836             otmp2 = otmp->nobj;
3837             if (otmp->otyp == BOULDER) {
3838                 /* this keeps otmp from being polymorphed in the
3839                    same zap that the monster that held it is polymorphed */
3840                 if (polyspot)
3841                     bypass_obj(otmp);
3842                 obj_extract_self(otmp);
3843                 /* probably ought to give some "drop" message here */
3844                 if (flooreffects(otmp, mtmp->mx, mtmp->my, ""))
3845                     continue;
3846                 place_object(otmp, mtmp->mx, mtmp->my);
3847             }
3848         }
3849     }
3850
3851     return 1;
3852 }
3853
3854 /* sometimes an egg will be special */
3855 #define BREEDER_EGG (!rn2(77))
3856
3857 /*
3858  * Determine if the given monster number can be hatched from an egg.
3859  * Return the monster number to use as the egg's corpsenm.  Return
3860  * NON_PM if the given monster can't be hatched.
3861  */
3862 int
3863 can_be_hatched(mnum)
3864 int mnum;
3865 {
3866     /* ranger quest nemesis has the oviparous bit set, making it
3867        be possible to wish for eggs of that unique monster; turn
3868        such into ordinary eggs rather than forbidding them outright */
3869     if (mnum == PM_SCORPIUS)
3870         mnum = PM_SCORPION;
3871
3872     mnum = little_to_big(mnum);
3873     /*
3874      * Queen bees lay killer bee eggs (usually), but killer bees don't
3875      * grow into queen bees.  Ditto for [winged-]gargoyles.
3876      */
3877     if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE
3878         || (lays_eggs(&mons[mnum])
3879             && (BREEDER_EGG
3880                 || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
3881         return mnum;
3882     return NON_PM;
3883 }
3884
3885 /* type of egg laid by #sit; usually matches parent */
3886 int
3887 egg_type_from_parent(mnum, force_ordinary)
3888 int mnum; /* parent monster; caller must handle lays_eggs() check */
3889 boolean force_ordinary;
3890 {
3891     if (force_ordinary || !BREEDER_EGG) {
3892         if (mnum == PM_QUEEN_BEE)
3893             mnum = PM_KILLER_BEE;
3894         else if (mnum == PM_WINGED_GARGOYLE)
3895             mnum = PM_GARGOYLE;
3896     }
3897     return mnum;
3898 }
3899
3900 /* decide whether an egg of the indicated monster type is viable;
3901    also used to determine whether an egg or tin can be created... */
3902 boolean
3903 dead_species(m_idx, egg)
3904 int m_idx;
3905 boolean egg;
3906 {
3907     int alt_idx;
3908
3909     /* generic eggs are unhatchable and have corpsenm of NON_PM */
3910     if (m_idx < LOW_PM)
3911         return TRUE;
3912     /*
3913      * For monsters with both baby and adult forms, genociding either
3914      * form kills all eggs of that monster.  Monsters with more than
3915      * two forms (small->large->giant mimics) are more or less ignored;
3916      * fortunately, none of them have eggs.  Species extinction due to
3917      * overpopulation does not kill eggs.
3918      */
3919     alt_idx = egg ? big_to_little(m_idx) : m_idx;
3920     return (boolean) ((mvitals[m_idx].mvflags & G_GENOD) != 0
3921                       || (mvitals[alt_idx].mvflags & G_GENOD) != 0);
3922 }
3923
3924 /* kill off any eggs of genocided monsters */
3925 STATIC_OVL void
3926 kill_eggs(obj_list)
3927 struct obj *obj_list;
3928 {
3929     struct obj *otmp;
3930
3931     for (otmp = obj_list; otmp; otmp = otmp->nobj)
3932         if (otmp->otyp == EGG) {
3933             if (dead_species(otmp->corpsenm, TRUE)) {
3934                 /*
3935                  * It seems we could also just catch this when
3936                  * it attempted to hatch, so we wouldn't have to
3937                  * search all of the objlists.. or stop all
3938                  * hatch timers based on a corpsenm.
3939                  */
3940                 kill_egg(otmp);
3941             }
3942 #if 0 /* not used */
3943         } else if (otmp->otyp == TIN) {
3944             if (dead_species(otmp->corpsenm, FALSE))
3945                 otmp->corpsenm = NON_PM; /* empty tin */
3946         } else if (otmp->otyp == CORPSE) {
3947             if (dead_species(otmp->corpsenm, FALSE))
3948                 ; /* not yet implemented... */
3949 #endif
3950         } else if (Has_contents(otmp)) {
3951             kill_eggs(otmp->cobj);
3952         }
3953 }
3954
3955 /* kill all members of genocided species */
3956 void
3957 kill_genocided_monsters()
3958 {
3959     struct monst *mtmp, *mtmp2;
3960     boolean kill_cham;
3961     int mndx;
3962
3963     /*
3964      * Called during genocide, and again upon level change.  The latter
3965      * catches up with any migrating monsters as they finally arrive at
3966      * their intended destinations, so possessions get deposited there.
3967      *
3968      * Chameleon handling:
3969      *  1) if chameleons have been genocided, destroy them
3970      *     regardless of current form;
3971      *  2) otherwise, force every chameleon which is imitating
3972      *     any genocided species to take on a new form.
3973      */
3974     for (mtmp = fmon; mtmp; mtmp = mtmp2) {
3975         mtmp2 = mtmp->nmon;
3976         if (DEADMONSTER(mtmp))
3977             continue;
3978         mndx = monsndx(mtmp->data);
3979         kill_cham = (mtmp->cham >= LOW_PM
3980                      && (mvitals[mtmp->cham].mvflags & G_GENOD));
3981         if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) {
3982             if (mtmp->cham >= LOW_PM && !kill_cham)
3983                 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
3984             else
3985                 mondead(mtmp);
3986         }
3987         if (mtmp->minvent)
3988             kill_eggs(mtmp->minvent);
3989     }
3990
3991     kill_eggs(invent);
3992     kill_eggs(fobj);
3993     kill_eggs(migrating_objs);
3994     kill_eggs(level.buriedobjlist);
3995 }
3996
3997 void
3998 golemeffects(mon, damtype, dam)
3999 register struct monst *mon;
4000 int damtype, dam;
4001 {
4002     int heal = 0, slow = 0;
4003
4004     if (mon->data == &mons[PM_FLESH_GOLEM]) {
4005         if (damtype == AD_ELEC)
4006             heal = (dam + 5) / 6;
4007         else if (damtype == AD_FIRE || damtype == AD_COLD)
4008             slow = 1;
4009     } else if (mon->data == &mons[PM_IRON_GOLEM]) {
4010         if (damtype == AD_ELEC)
4011             slow = 1;
4012         else if (damtype == AD_FIRE)
4013             heal = dam;
4014     } else {
4015         return;
4016     }
4017     if (slow) {
4018         if (mon->mspeed != MSLOW)
4019             mon_adjust_speed(mon, -1, (struct obj *) 0);
4020     }
4021     if (heal) {
4022         if (mon->mhp < mon->mhpmax) {
4023             mon->mhp += heal;
4024             if (mon->mhp > mon->mhpmax)
4025                 mon->mhp = mon->mhpmax;
4026             if (cansee(mon->mx, mon->my))
4027 /*JP
4028                 pline("%s seems healthier.", Monnam(mon));
4029 */
4030                 pline("%s\82Í\8c³\8bC\82É\82È\82Á\82½\82æ\82¤\82É\8c©\82¦\82é\81D", Monnam(mon));
4031         }
4032     }
4033 }
4034
4035 boolean
4036 angry_guards(silent)
4037 boolean silent;
4038 {
4039     struct monst *mtmp;
4040     int ct = 0, nct = 0, sct = 0, slct = 0;
4041
4042     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4043         if (DEADMONSTER(mtmp))
4044             continue;
4045         if (is_watch(mtmp->data) && mtmp->mpeaceful) {
4046             ct++;
4047             if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
4048                 if (distu(mtmp->mx, mtmp->my) == 2)
4049                     nct++;
4050                 else
4051                     sct++;
4052             }
4053             if (mtmp->msleeping || mtmp->mfrozen) {
4054                 slct++;
4055                 mtmp->msleeping = mtmp->mfrozen = 0;
4056             }
4057             mtmp->mpeaceful = 0;
4058         }
4059     }
4060     if (ct) {
4061         if (!silent) { /* do we want pline msgs? */
4062             if (slct)
4063 #if 0 /*JP*/
4064                 pline_The("guard%s wake%s up!", slct > 1 ? "s" : "",
4065                           slct == 1 ? "s" : "");
4066 #else
4067                 pline("\94Ô\95º\82Í\96Ú\82ð\8ao\82Ü\82µ\82½\81I");
4068 #endif
4069             if (nct || sct) {
4070                 if (nct)
4071 #if 0 /*JP*/
4072                     pline_The("guard%s get%s angry!", nct == 1 ? "" : "s",
4073                               nct == 1 ? "s" : "");
4074 #else
4075                     pline("\94Ô\95º\82Í\93{\82Á\82½\81I");
4076 #endif
4077                 else if (!Blind)
4078 #if 0 /*JP*/
4079                     You_see("%sangry guard%s approaching!",
4080                             sct == 1 ? "an " : "", sct > 1 ? "s" : "");
4081 #else
4082                     You("\93{\82Á\82½\94Ô\95º\82ª\8bß\8añ\82Á\82Ä\82­\82é\82Ì\82ð\8c©\82½\81I");
4083 #endif
4084             } else
4085 /*JP
4086                 You_hear("the shrill sound of a guard's whistle.");
4087 */
4088                 You_hear("\94Ô\95º\82Ì\93J\82ª\82¯\82½\82½\82Ü\82µ\82­\96Â\82é\82Ì\82ð\95·\82¢\82½\81D");
4089         }
4090         return TRUE;
4091     }
4092     return FALSE;
4093 }
4094
4095 void
4096 pacify_guards()
4097 {
4098     struct monst *mtmp;
4099
4100     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4101         if (DEADMONSTER(mtmp))
4102             continue;
4103         if (is_watch(mtmp->data))
4104             mtmp->mpeaceful = 1;
4105     }
4106 }
4107
4108 void
4109 mimic_hit_msg(mtmp, otyp)
4110 struct monst *mtmp;
4111 short otyp;
4112 {
4113     short ap = mtmp->mappearance;
4114
4115     switch (mtmp->m_ap_type) {
4116     case M_AP_NOTHING:
4117     case M_AP_FURNITURE:
4118     case M_AP_MONSTER:
4119         break;
4120     case M_AP_OBJECT:
4121         if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
4122 #if 0 /*JP*/
4123             pline("%s seems a more vivid %s than before.",
4124                   The(simple_typename(ap)),
4125                   c_obj_colors[objects[ap].oc_color]);
4126 #else
4127             pline("%s\82Í\88È\91O\82æ\82è\82æ\82è\91N\82â\82©\82È%s\82É\82È\82Á\82½\82æ\82¤\82¾\81D",
4128                   The(simple_typename(ap)),
4129                   c_obj_colors[objects[ap].oc_color]);
4130 #endif
4131         }
4132         break;
4133     }
4134 }
4135
4136 boolean
4137 usmellmon(mdat)
4138 struct permonst *mdat;
4139 {
4140     int mndx;
4141     boolean nonspecific = FALSE;
4142     boolean msg_given = FALSE;
4143
4144     if (mdat) {
4145         if (!olfaction(youmonst.data))
4146             return FALSE;
4147         mndx = monsndx(mdat);
4148         switch (mndx) {
4149         case PM_ROTHE:
4150         case PM_MINOTAUR:
4151 /*JP
4152             You("notice a bovine smell.");
4153 */
4154             You("\8b\8d\82Ì\82æ\82¤\82È\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4155             msg_given = TRUE;
4156             break;
4157         case PM_CAVEMAN:
4158         case PM_CAVEWOMAN:
4159         case PM_BARBARIAN:
4160         case PM_NEANDERTHAL:
4161 /*JP
4162             You("smell body odor.");
4163 */
4164             pline("\91Ì\8fL\82Ì\82æ\82¤\82È\82É\82¨\82¢\82ª\82µ\82½\81D");
4165             msg_given = TRUE;
4166             break;
4167         /*
4168         case PM_PESTILENCE:
4169         case PM_FAMINE:
4170         case PM_DEATH:
4171             break;
4172         */
4173         case PM_HORNED_DEVIL:
4174         case PM_BALROG:
4175         case PM_ASMODEUS:
4176         case PM_DISPATER:
4177         case PM_YEENOGHU:
4178         case PM_ORCUS:
4179             break;
4180         case PM_HUMAN_WEREJACKAL:
4181         case PM_HUMAN_WERERAT:
4182         case PM_HUMAN_WEREWOLF:
4183         case PM_WEREJACKAL:
4184         case PM_WERERAT:
4185         case PM_WEREWOLF:
4186         case PM_OWLBEAR:
4187 /*JP
4188             You("detect an odor reminiscent of an animal's den.");
4189 */
4190             pline("\93®\95¨\82Ì\82Ë\82®\82ç\82ð\8ev\82¢\8fo\82·\82æ\82¤\82È\82É\82¨\82¢\82ª\82µ\82½\81D");
4191             msg_given = TRUE;
4192             break;
4193         /*
4194         case PM_PURPLE_WORM:
4195             break;
4196         */
4197         case PM_STEAM_VORTEX:
4198 /*JP
4199             You("smell steam.");
4200 */
4201             pline("\8fö\8bC\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4202             msg_given = TRUE;
4203             break;
4204         case PM_GREEN_SLIME:
4205 /*JP
4206             pline("%s stinks.", Something);
4207 */
4208             pline("\88«\8fL\82ª\82µ\82½\81D");
4209             msg_given = TRUE;
4210             break;
4211         case PM_VIOLET_FUNGUS:
4212         case PM_SHRIEKER:
4213 /*JP
4214             You("smell mushrooms.");
4215 */
4216             pline("\82«\82Ì\82±\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4217             msg_given = TRUE;
4218             break;
4219         /* These are here to avoid triggering the
4220            nonspecific treatment through the default case below*/
4221         case PM_WHITE_UNICORN:
4222         case PM_GRAY_UNICORN:
4223         case PM_BLACK_UNICORN:
4224         case PM_JELLYFISH:
4225             break;
4226         default:
4227             nonspecific = TRUE;
4228             break;
4229         }
4230
4231         if (nonspecific)
4232             switch (mdat->mlet) {
4233             case S_DOG:
4234 /*JP
4235                 You("notice a dog smell.");
4236 */
4237                 You("\8c¢\82Ì\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4238                 msg_given = TRUE;
4239                 break;
4240             case S_DRAGON:
4241 /*JP
4242                 You("smell a dragon!");
4243 */
4244                 pline("\83h\83\89\83S\83\93\82Ì\82É\82¨\82¢\82ª\82·\82é\81I");
4245                 msg_given = TRUE;
4246                 break;
4247             case S_FUNGUS:
4248 /*JP
4249                 pline("%s smells moldy.", Something);
4250 */
4251                 pline("\89½\82©\91Û\82Ì\82æ\82¤\82È\82É\82¨\82¢\82ª\82·\82é\81D");
4252                 msg_given = TRUE;
4253                 break;
4254             case S_UNICORN:
4255 #if 0 /*JP*/
4256                 You("detect a%s odor reminiscent of a stable.",
4257                     (mndx == PM_PONY) ? "n" : " strong");
4258 #else
4259                 pline("\94n\8f¬\89®\82ð\8ev\82¢\8fo\82·\82æ\82¤\82È%s\82É\82¨\82¢\82ª\82µ\82½\81D",
4260                     (mndx == PM_PONY) ? "" : "\8b­\82¢");
4261 #endif
4262                 msg_given = TRUE;
4263                 break;
4264             case S_ZOMBIE:
4265 /*JP
4266                 You("smell rotting flesh.");
4267 */
4268                 pline("\95\85\82Á\82½\93÷\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4269                 msg_given = TRUE;
4270                 break;
4271             case S_EEL:
4272 /*JP
4273                 You("smell fish.");
4274 */
4275                 pline("\8b\9b\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4276                 msg_given = TRUE;
4277                 break;
4278             case S_ORC:
4279                 if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
4280 /*JP
4281                     You("notice an attractive smell.");
4282 */
4283                     You("\96£\97Í\93I\82È\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4284                 else
4285 /*JP
4286                     pline("A foul stench makes you feel a little nauseated.");
4287 */
4288                     pline("\82Þ\82©\82Â\82­\82æ\82¤\82È\88«\8fL\82Å\8f­\82µ\8bC\95ª\82ª\88«\82­\82È\82Á\82½\81D");
4289                 msg_given = TRUE;
4290                 break;
4291             default:
4292                 break;
4293             }
4294     }
4295     return msg_given ? TRUE : FALSE;
4296 }
4297
4298 /*mon.c*/