OSDN Git Service

use const
[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-2018            */
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 #if 0 /*JP*/
2647             Sprintf(buf, "The lapidifying %s %s %s",
2648                     x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2649                              (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2650                               | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2651                     amorphous(mtmp->data) ? "coalesces on the"
2652                        : is_flyer(mtmp->data) ? "drops to the"
2653                           : "writhes on the",
2654                     surface(x,y));
2655 #else
2656             Sprintf(buf, "\90Î\89»\82µ\82Â\82Â\82 \82é%s\82ª%s%s",
2657                     x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2658                              (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2659                               | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2660                     surface(x,y),
2661                     amorphous(mtmp->data) ? "\82Ì\8fã\82Å\97Z\8d\87\82µ\82½"
2662                        : is_flyer(mtmp->data) ? "\82É\97\8e\82¿\82½"
2663                           : "\82Ì\8fã\82Å\90g\82à\82¾\82¦\82½");
2664 #endif
2665             mtmp->mcanmove = 1;
2666             mtmp->mfrozen = 0;
2667             if (mtmp->mhpmax <= 0)
2668                 mtmp->mhpmax = 10;
2669             mtmp->mhp = mtmp->mhpmax;
2670             /* this can happen if previously a fog cloud */
2671             if (u.uswallow && (mtmp == u.ustuck))
2672                 expels(mtmp, mtmp->data, FALSE);
2673             if (in_door) {
2674                 coord new_xy;
2675
2676                 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
2677                     rloc_to(mtmp, new_xy.x, new_xy.y);
2678                 }
2679             }
2680             if (canspotmon(mtmp)) {
2681 /*JP
2682                 pline("%s!", buf);
2683 */
2684                 pline("%s\81I", buf);
2685                 display_nhwindow(WIN_MESSAGE, FALSE);
2686             }
2687             newcham(mtmp, &mons[mndx], FALSE, FALSE);
2688             if (mtmp->data == &mons[mndx])
2689                 mtmp->cham = NON_PM;
2690             else
2691                 mtmp->cham = mndx;
2692             if (canspotmon(mtmp)) {
2693 #if 0 /*JP*/
2694                 pline("%s rises from the %s with renewed agility!",
2695                       Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2696 #else
2697                 pline("%s\82Í\8b@\95q\82³\82ð\8eæ\82è\96ß\82µ\82Ä%s\82©\82ç\95\9c\8a\88\82µ\82½\81I",
2698                       Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2699 #endif
2700             }
2701             newsym(mtmp->mx, mtmp->my);
2702             return FALSE;   /* didn't petrify */
2703         }
2704     }
2705     return TRUE;
2706 }
2707
2708 /* drop monster into "limbo" - that is, migrate to the current level */
2709 void
2710 m_into_limbo(mtmp)
2711 struct monst *mtmp;
2712 {
2713     unstuck(mtmp);
2714     mdrop_special_objs(mtmp);
2715     migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_APPROX_XY, NULL);
2716 }
2717
2718 /* make monster mtmp next to you (if possible);
2719    might place monst on far side of a wall or boulder */
2720 void
2721 mnexto(mtmp)
2722 struct monst *mtmp;
2723 {
2724     coord mm;
2725     boolean couldspot = canspotmon(mtmp);
2726
2727     if (mtmp == u.usteed) {
2728         /* Keep your steed in sync with you instead */
2729         mtmp->mx = u.ux;
2730         mtmp->my = u.uy;
2731         return;
2732     }
2733
2734     if (!enexto(&mm, u.ux, u.uy, mtmp->data)) {
2735         m_into_limbo(mtmp);
2736         return;
2737     }
2738     if (!isok(mm.x, mm.y))
2739         return;
2740     rloc_to(mtmp, mm.x, mm.y);
2741     if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) {
2742         mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */
2743         if (!couldspot && canspotmon(mtmp))
2744 #if 0 /*JP*/
2745             pline("%s suddenly %s!", Amonnam(mtmp),
2746                   !Blind ? "appears" : "arrives");
2747 #else
2748             pline("\93Ë\91R%s\82ª\8c»\82ê\82½\81I", Amonnam(mtmp));
2749 #endif
2750     }
2751     return;
2752 }
2753
2754 /* like mnexto() but requires destination to be directly accessible */
2755 void
2756 maybe_mnexto(mtmp)
2757 struct monst *mtmp;
2758 {
2759     coord mm;
2760     struct permonst *ptr = mtmp->data;
2761     boolean diagok = !NODIAG(ptr - mons);
2762     int tryct = 20;
2763
2764     do {
2765         if (!enexto(&mm, u.ux, u.uy, ptr))
2766             return;
2767         if (couldsee(mm.x, mm.y)
2768             /* don't move grid bugs diagonally */
2769             && (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) {
2770             rloc_to(mtmp, mm.x, mm.y);
2771             return;
2772         }
2773     } while (--tryct > 0);
2774 }
2775
2776 /* mnearto()
2777  * Put monster near (or at) location if possible.
2778  * Returns:
2779  *  true if relocation was successful
2780  *  false otherwise
2781  */
2782 boolean
2783 mnearto(mtmp, x, y, move_other)
2784 register struct monst *mtmp;
2785 xchar x, y;
2786 boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */
2787 {
2788     struct monst *othermon = (struct monst *) 0;
2789     xchar newx, newy;
2790     coord mm;
2791
2792     if (mtmp->mx == x && mtmp->my == y)
2793         return TRUE;
2794
2795     if (move_other && (othermon = m_at(x, y)) != 0) {
2796         if (othermon->wormno)
2797             remove_worm(othermon);
2798         else
2799             remove_monster(x, y);
2800     }
2801
2802     newx = x;
2803     newy = y;
2804     if (!goodpos(newx, newy, mtmp, 0)) {
2805         /* Actually we have real problems if enexto ever fails.
2806          * Migrating_mons that need to be placed will cause
2807          * no end of trouble.
2808          */
2809         if (!enexto(&mm, newx, newy, mtmp->data))
2810             return FALSE;
2811         if (!isok(mm.x,mm.y))
2812             return FALSE;
2813         newx = mm.x;
2814         newy = mm.y;
2815     }
2816     rloc_to(mtmp, newx, newy);
2817
2818     if (move_other && othermon) {
2819         xchar oldx = othermon->mx, oldy = othermon->my;
2820
2821         othermon->mx = othermon->my = 0;
2822         (void) mnearto(othermon, x, y, FALSE);
2823         if (othermon->mx == 0 && othermon->my == 0) {
2824             /* reloc failed */
2825             othermon->mx = oldx;
2826             othermon->my = oldy;
2827             m_into_limbo(othermon);
2828         }
2829     }
2830
2831     return TRUE;
2832 }
2833
2834 /* monster responds to player action; not the same as a passive attack;
2835    assumes reason for response has been tested, and response _must_ be made */
2836 void
2837 m_respond(mtmp)
2838 struct monst *mtmp;
2839 {
2840     if (mtmp->data->msound == MS_SHRIEK) {
2841         if (!Deaf) {
2842 /*JP
2843             pline("%s shrieks.", Monnam(mtmp));
2844 */
2845             pline("%s\82Í\8bà\90Ø\82è\90º\82ð\82 \82°\82½\81D", Monnam(mtmp));
2846             stop_occupation();
2847         }
2848         if (!rn2(10)) {
2849             if (!rn2(13))
2850                 (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
2851             else
2852                 (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS);
2853         }
2854         aggravate();
2855     }
2856     if (mtmp->data == &mons[PM_MEDUSA]) {
2857         register int i;
2858
2859         for (i = 0; i < NATTK; i++)
2860             if (mtmp->data->mattk[i].aatyp == AT_GAZE) {
2861                 (void) gazemu(mtmp, &mtmp->data->mattk[i]);
2862                 break;
2863             }
2864     }
2865 }
2866
2867 /* Called whenever the player attacks mtmp; also called in other situations
2868    where mtmp gets annoyed at the player. Handles mtmp getting annoyed at the
2869    attack and any ramifications that might have. Useful also in situations
2870    where mtmp was already hostile; it checks for situations where the player
2871    shouldn't be attacking and any ramifications /that/ might have. */
2872 void
2873 setmangry(mtmp, via_attack)
2874 struct monst *mtmp;
2875 boolean via_attack;
2876 {
2877     if (via_attack && sengr_at("Elbereth", u.ux, u.uy, TRUE)) {
2878 /*JP
2879         You_feel("like a hypocrite.");
2880 */
2881         You_feel("\8bU\91P\8eÒ\82Ì\82æ\82¤\82È\8bC\82ª\82µ\82½\81D");
2882         /* AIS: Yes, I know alignment penalties and bonuses aren't balanced
2883            at the moment. This is about correct relative to other "small"
2884            penalties; it should be fairly large, as attacking while standing
2885            on an Elbereth means that you're requesting peace and then
2886            violating your own request. I know 5 isn't actually large, but
2887            it's intentionally larger than the 1s and 2s that are normally
2888            given for this sort of thing. */
2889         adjalign(-5);
2890
2891         if (!Blind)
2892 /*JP
2893             pline("The engraving beneath you fades.");
2894 */
2895             pline("\82 \82È\82½\82Ì\91«\8c³\82Ì\95\8e\9a\82ª\94\96\82ê\82½\81D");
2896         del_engr_at(u.ux, u.uy);
2897     }
2898
2899     /* AIS: Should this be in both places, or just in wakeup()? */
2900     mtmp->mstrategy &= ~STRAT_WAITMASK;
2901     if (!mtmp->mpeaceful)
2902         return;
2903     if (mtmp->mtame)
2904         return;
2905     mtmp->mpeaceful = 0;
2906     if (mtmp->ispriest) {
2907         if (p_coaligned(mtmp))
2908             adjalign(-5); /* very bad */
2909         else
2910             adjalign(2);
2911     } else
2912         adjalign(-1); /* attacking peaceful monsters is bad */
2913     if (couldsee(mtmp->mx, mtmp->my)) {
2914         if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
2915 /*JP
2916             pline("%s gets angry!", Monnam(mtmp));
2917 */
2918             pline("%s\82Í\93{\82Á\82½\81I", Monnam(mtmp));
2919         else if (flags.verbose && !Deaf)
2920             growl(mtmp);
2921     }
2922
2923     /* attacking your own quest leader will anger his or her guardians */
2924     if (!context.mon_moving /* should always be the case here */
2925         && mtmp->data == &mons[quest_info(MS_LEADER)]) {
2926         struct monst *mon;
2927         struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
2928         int got_mad = 0;
2929
2930         /* guardians will sense this attack even if they can't see it */
2931         for (mon = fmon; mon; mon = mon->nmon) {
2932             if (DEADMONSTER(mon))
2933                 continue;
2934             if (mon->data == q_guardian && mon->mpeaceful) {
2935                 mon->mpeaceful = 0;
2936                 if (canseemon(mon))
2937                     ++got_mad;
2938             }
2939         }
2940         if (got_mad && !Hallucination) {
2941             const char *who = q_guardian->mname;
2942
2943 #if 0 /*JP*/
2944             if (got_mad > 1)
2945                 who = makeplural(who);
2946             pline_The("%s %s to be angry too...",
2947                       who, vtense(who, "appear"));
2948 #else
2949             pline("%s\82à\93{\82Á\82½\82æ\82¤\82¾\81D\81D\81D", who);
2950 #endif
2951         }
2952     }
2953
2954     /* make other peaceful monsters react */
2955     if (!context.mon_moving) {
2956         static const char *const Exclam[] = {
2957 /*JP
2958             "Gasp!", "Uh-oh.", "Oh my!", "What?", "Why?",
2959 */
2960             "\82®\82Í\82Á\81I", "\82¤\82í\81D", "Oh my!", "\82È\82É\82Á\81H", "\82È\82ñ\82¾\81H",
2961         };
2962         struct monst *mon;
2963         int mndx = monsndx(mtmp->data);
2964
2965         for (mon = fmon; mon; mon = mon->nmon) {
2966             if (DEADMONSTER(mon))
2967                 continue;
2968             if (mon == mtmp) /* the mpeaceful test catches this since mtmp */
2969                 continue;    /* is no longer peaceful, but be explicit...  */
2970
2971             if (!mindless(mon->data) && mon->mpeaceful
2972                 && couldsee(mon->mx, mon->my) && !mon->msleeping
2973                 && mon->mcansee && m_canseeu(mon)) {
2974                 boolean exclaimed = FALSE;
2975
2976                 if (humanoid(mon->data) || mon->isshk || mon->ispriest) {
2977                     if (is_watch(mon->data)) {
2978 /*JP
2979                         verbalize("Halt!  You're under arrest!");
2980 */
2981                         verbalize("\8e~\82Ü\82ê\81I\91ß\95ß\82·\82é\81I");
2982                         (void) angry_guards(!!Deaf);
2983                     } else {
2984                         if (!rn2(5)) {
2985                             verbalize("%s", Exclam[mon->m_id % SIZE(Exclam)]);
2986                             exclaimed = TRUE;
2987                         }
2988                         /* shopkeepers and temple priests might gasp in
2989                            surprise, but they won't become angry here */
2990                         if (mon->isshk || mon->ispriest)
2991                             continue;
2992
2993                         if (mon->data->mlevel < rn2(10)) {
2994                             monflee(mon, rn2(50) + 25, TRUE, !exclaimed);
2995                             exclaimed = TRUE;
2996                         }
2997                         if (mon->mtame) {
2998                             /* mustn't set mpeaceful to 0 as below;
2999                                perhaps reduce tameness? */
3000                         } else {
3001                             mon->mpeaceful = 0;
3002                             adjalign(-1);
3003                             if (!exclaimed)
3004 /*JP
3005                                 pline("%s gets angry!", Monnam(mon));
3006 */
3007                                 pline("%s\82Í\93{\82Á\82½\81I", Monnam(mon));
3008                         }
3009                     }
3010                 } else if (mon->data->mlet == mtmp->data->mlet
3011                            && big_little_match(mndx, monsndx(mon->data))
3012                            && !rn2(3)) {
3013                     if (!rn2(4)) {
3014                         growl(mon);
3015                         exclaimed = TRUE;
3016                     }
3017                     if (rn2(6))
3018                         monflee(mon, rn2(25) + 15, TRUE, !exclaimed);
3019                 }
3020             }
3021         }
3022     }
3023 }
3024
3025 /* wake up a monster, possibly making it angry in the process */
3026 void
3027 wakeup(mtmp, via_attack)
3028 register struct monst *mtmp;
3029 boolean via_attack;
3030 {
3031     mtmp->msleeping = 0;
3032     if (mtmp->m_ap_type) {
3033         seemimic(mtmp);
3034     } else if (context.forcefight && !context.mon_moving
3035                && mtmp->mundetected) {
3036         mtmp->mundetected = 0;
3037         newsym(mtmp->mx, mtmp->my);
3038     }
3039     finish_meating(mtmp);
3040     if (via_attack)
3041         setmangry(mtmp, TRUE);
3042 }
3043
3044 /* Wake up nearby monsters without angering them. */
3045 void
3046 wake_nearby()
3047 {
3048     register struct monst *mtmp;
3049
3050     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3051         if (DEADMONSTER(mtmp))
3052             continue;
3053         if (distu(mtmp->mx, mtmp->my) < u.ulevel * 20) {
3054             mtmp->msleeping = 0;
3055             if (!unique_corpstat(mtmp->data))
3056                 mtmp->mstrategy &= ~STRAT_WAITMASK;
3057             if (mtmp->mtame) {
3058                 if (!mtmp->isminion)
3059                     EDOG(mtmp)->whistletime = moves;
3060                 /* Clear mtrack. This is to fix up a pet who is
3061                    stuck "fleeing" its master. */
3062                 memset(mtmp->mtrack, 0, sizeof(mtmp->mtrack));
3063             }
3064         }
3065     }
3066 }
3067
3068 /* Wake up monsters near some particular location. */
3069 void
3070 wake_nearto(x, y, distance)
3071 register int x, y, distance;
3072 {
3073     register struct monst *mtmp;
3074
3075     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3076         if (DEADMONSTER(mtmp))
3077             continue;
3078         if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
3079             mtmp->msleeping = 0;
3080             if (!unique_corpstat(mtmp->data))
3081                 mtmp->mstrategy &= ~STRAT_WAITMASK;
3082         }
3083     }
3084 }
3085
3086 /* NOTE: we must check for mimicry before calling this routine */
3087 void
3088 seemimic(mtmp)
3089 register struct monst *mtmp;
3090 {
3091     boolean is_blocker_appear = (is_lightblocker_mappear(mtmp));
3092
3093     if (has_mcorpsenm(mtmp))
3094         freemcorpsenm(mtmp);
3095
3096     mtmp->m_ap_type = M_AP_NOTHING;
3097     mtmp->mappearance = 0;
3098
3099     /*
3100      *  Discovered mimics don't block light.
3101      */
3102     if (is_blocker_appear
3103         && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
3104         unblock_point(mtmp->mx, mtmp->my);
3105
3106     newsym(mtmp->mx, mtmp->my);
3107 }
3108
3109 /* force all chameleons to become normal */
3110 void
3111 rescham()
3112 {
3113     register struct monst *mtmp;
3114     int mcham;
3115
3116     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3117         if (DEADMONSTER(mtmp))
3118             continue;
3119         mcham = (int) mtmp->cham;
3120         if (mcham >= LOW_PM) {
3121             (void) newcham(mtmp, &mons[mcham], FALSE, FALSE);
3122             mtmp->cham = NON_PM;
3123         }
3124         if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
3125             new_were(mtmp);
3126         if (mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) {
3127             seemimic(mtmp);
3128             /* we pretend that the mimic doesn't
3129                know that it has been unmasked */
3130             mtmp->msleeping = 1;
3131         }
3132     }
3133 }
3134
3135 /* Let the chameleons change again -dgk */
3136 void
3137 restartcham()
3138 {
3139     register struct monst *mtmp;
3140
3141     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3142         if (DEADMONSTER(mtmp))
3143             continue;
3144         mtmp->cham = pm_to_cham(monsndx(mtmp->data));
3145         if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping
3146             && cansee(mtmp->mx, mtmp->my)) {
3147             set_mimic_sym(mtmp);
3148             newsym(mtmp->mx, mtmp->my);
3149         }
3150     }
3151 }
3152
3153 /* called when restoring a monster from a saved level; protection
3154    against shape-changing might be different now than it was at the
3155    time the level was saved. */
3156 void
3157 restore_cham(mon)
3158 struct monst *mon;
3159 {
3160     int mcham;
3161
3162     if (Protection_from_shape_changers) {
3163         mcham = (int) mon->cham;
3164         if (mcham >= LOW_PM) {
3165             mon->cham = NON_PM;
3166             (void) newcham(mon, &mons[mcham], FALSE, FALSE);
3167         } else if (is_were(mon->data) && !is_human(mon->data)) {
3168             new_were(mon);
3169         }
3170     } else if (mon->cham == NON_PM) {
3171         mon->cham = pm_to_cham(monsndx(mon->data));
3172     }
3173 }
3174
3175 /* unwatched hiders may hide again; if so, returns True */
3176 STATIC_OVL boolean
3177 restrap(mtmp)
3178 register struct monst *mtmp;
3179 {
3180     struct trap *t;
3181
3182     if (mtmp->mcan || mtmp->m_ap_type || cansee(mtmp->mx, mtmp->my)
3183         || rn2(3) || mtmp == u.ustuck
3184         /* can't hide while trapped except in pits */
3185         || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
3186             && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))
3187         || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
3188         return FALSE;
3189
3190     if (mtmp->data->mlet == S_MIMIC) {
3191         set_mimic_sym(mtmp);
3192         return TRUE;
3193     } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) {
3194         mtmp->mundetected = 1;
3195         return TRUE;
3196     }
3197
3198     return FALSE;
3199 }
3200
3201 /* monster/hero tries to hide under something at the current location */
3202 boolean
3203 hideunder(mtmp)
3204 struct monst *mtmp;
3205 {
3206     struct trap *t;
3207     boolean undetected = FALSE, is_u = (mtmp == &youmonst);
3208     xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
3209
3210     if (mtmp == u.ustuck) {
3211         ; /* can't hide if holding you or held by you */
3212     } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
3213                     : (mtmp->mtrapped && (t = t_at(x, y)) != 0
3214                        && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) {
3215         ; /* can't hide while stuck in a non-pit trap */
3216     } else if (mtmp->data->mlet == S_EEL) {
3217         undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
3218     } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
3219         struct obj *otmp = level.objects[x][y];
3220
3221         /* most monsters won't hide under cockatrice corpse */
3222         if (otmp->nexthere || otmp->otyp != CORPSE
3223             || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp))
3224             || !touch_petrifies(&mons[otmp->corpsenm]))
3225             undetected = TRUE;
3226     }
3227
3228     if (is_u)
3229         u.uundetected = undetected;
3230     else
3231         mtmp->mundetected = undetected;
3232     return undetected;
3233 }
3234
3235 /* called when returning to a previously visited level */
3236 void
3237 hide_monst(mon)
3238 struct monst *mon;
3239 {
3240     boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL;
3241
3242     if ((is_hider(mon->data) || hider_under)
3243         && !(mon->mundetected || mon->m_ap_type)) {
3244         xchar x = mon->mx, y = mon->my;
3245         char save_viz = viz_array[y][x];
3246
3247         /* override vision, forcing hero to be unable to see monster's spot */
3248         viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE);
3249         if (is_hider(mon->data))
3250             (void) restrap(mon);
3251         /* try again if mimic missed its 1/3 chance to hide */
3252         if (mon->data->mlet == S_MIMIC && !mon->m_ap_type)
3253             (void) restrap(mon);
3254         if (hider_under)
3255             (void) hideunder(mon);
3256         viz_array[y][x] = save_viz;
3257     }
3258 }
3259
3260 static short *animal_list = 0; /* list of PM values for animal monsters */
3261 static int animal_list_count;
3262
3263 void
3264 mon_animal_list(construct)
3265 boolean construct;
3266 {
3267     if (construct) {
3268         short animal_temp[SPECIAL_PM];
3269         int i, n;
3270
3271         /* if (animal_list) impossible("animal_list already exists"); */
3272
3273         for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
3274             if (is_animal(&mons[i]))
3275                 animal_temp[n++] = i;
3276         /* if (n == 0) animal_temp[n++] = NON_PM; */
3277
3278         animal_list = (short *) alloc(n * sizeof *animal_list);
3279         (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp,
3280                       n * sizeof *animal_list);
3281         animal_list_count = n;
3282     } else { /* release */
3283         if (animal_list)
3284             free((genericptr_t) animal_list), animal_list = 0;
3285         animal_list_count = 0;
3286     }
3287 }
3288
3289 STATIC_OVL int
3290 pick_animal()
3291 {
3292     int res;
3293
3294     if (!animal_list)
3295         mon_animal_list(TRUE);
3296
3297     res = animal_list[rn2(animal_list_count)];
3298     /* rogue level should use monsters represented by uppercase letters
3299        only, but since chameleons aren't generated there (not uppercase!)
3300        we don't perform a lot of retries */
3301     if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet))
3302         res = animal_list[rn2(animal_list_count)];
3303     return res;
3304 }
3305
3306 void
3307 decide_to_shapeshift(mon, shiftflags)
3308 struct monst *mon;
3309 int shiftflags;
3310 {
3311     struct permonst *ptr = 0;
3312     int mndx;
3313     unsigned was_female = mon->female;
3314     boolean msg = FALSE, dochng = FALSE;
3315
3316     if ((shiftflags & SHIFT_MSG)
3317         || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon)))
3318         msg = TRUE;
3319
3320     if (!is_vampshifter(mon)) {
3321         /* regular shapeshifter */
3322         if (!rn2(6))
3323             dochng = TRUE;
3324     } else {
3325         /* The vampire has to be in good health (mhp) to maintain
3326          * its shifted form.
3327          *
3328          * If we're shifted and getting low on hp, maybe shift back, or
3329          * if we're a fog cloud at full hp, maybe pick a different shape.
3330          * If we're not already shifted and in good health, maybe shift.
3331          */
3332         if (mon->data->mlet != S_VAMPIRE) {
3333             if ((mon->mhp <= (mon->mhpmax + 5) / 6) && rn2(4)
3334                 && mon->cham >= LOW_PM) {
3335                 ptr = &mons[mon->cham];
3336                 dochng = TRUE;
3337             } else if (mon->data == &mons[PM_FOG_CLOUD]
3338                      && mon->mhp == mon->mhpmax && !rn2(4)
3339                      && (!canseemon(mon)
3340                          || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM)) {
3341                 /* if a fog cloud, maybe change to wolf or vampire bat;
3342                    those are more likely to take damage--at least when
3343                    tame--and then switch back to vampire; they'll also
3344                    switch to fog cloud if they encounter a closed door */
3345                 mndx = pickvampshape(mon);
3346                 if (mndx >= LOW_PM) {
3347                     ptr = &mons[mndx];
3348                     dochng = (ptr != mon->data);
3349                 }
3350             }
3351         } else {
3352             if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6)
3353                 && (!canseemon(mon)
3354                     || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM))
3355                 dochng = TRUE; /* 'ptr' stays Null */
3356         }
3357     }
3358     if (dochng) {
3359         if (newcham(mon, ptr, FALSE, msg) && is_vampshifter(mon)) {
3360             /* for vampshift, override the 10% chance for sex change */
3361             ptr = mon->data;
3362             if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr))
3363                 mon->female = was_female;
3364         }
3365     }
3366 }
3367
3368 STATIC_OVL int
3369 pickvampshape(mon)
3370 struct monst *mon;
3371 {
3372     int mndx = mon->cham, wolfchance = 10;
3373     /* avoid picking monsters with lowercase display symbols ('d' for wolf
3374        and 'v' for fog cloud) on rogue level*/
3375     boolean uppercase_only = Is_rogue_level(&u.uz);
3376
3377     switch (mndx) {
3378     case PM_VLAD_THE_IMPALER:
3379         /* ensure Vlad can keep carrying the Candelabrum */
3380         if (mon_has_special(mon))
3381             break; /* leave mndx as is */
3382         wolfchance = 3;
3383     /*FALLTHRU*/
3384     case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */
3385         if (!rn2(wolfchance) && !uppercase_only) {
3386             mndx = PM_WOLF;
3387             break;
3388         }
3389     /*FALLTHRU*/
3390     case PM_VAMPIRE: /* any vampire can become fog or bat */
3391         mndx = (!rn2(4) && !uppercase_only) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
3392         break;
3393     }
3394     return mndx;
3395 }
3396
3397 /* nonshapechangers who warrant special polymorph handling */
3398 STATIC_OVL boolean
3399 isspecmon(mon)
3400 struct monst *mon;
3401 {
3402     return (mon->isshk || mon->ispriest || mon->isgd
3403             || mon->m_id == quest_status.leader_m_id);
3404 }
3405
3406 /* restrict certain special monsters (shopkeepers, aligned priests,
3407    vault guards) to forms that allow them to behave sensibly (catching
3408    gold, speaking?) so that they don't need too much extra code */
3409 STATIC_OVL boolean
3410 validspecmon(mon, mndx)
3411 struct monst *mon;
3412 int mndx;
3413 {
3414     if (mndx == NON_PM)
3415         return TRUE; /* caller wants random */
3416
3417     if (!accept_newcham_form(mndx))
3418         return FALSE; /* geno'd or !polyok */
3419
3420     if (isspecmon(mon)) {
3421         struct permonst *ptr = &mons[mndx];
3422
3423         /* reject notake because object manipulation is expected
3424            and nohead because speech capability is expected */
3425         if (notake(ptr) || !has_head(ptr))
3426             return FALSE;
3427         /* [should we check ptr->msound here too?] */
3428     }
3429     return TRUE; /* potential new form is ok */
3430 }
3431
3432 /* prevent wizard mode user from specifying invalid vampshifter shape */
3433 boolean
3434 validvamp(mon, mndx_p, monclass)
3435 struct monst *mon;
3436 int *mndx_p, monclass;
3437 {
3438     /* simplify caller's usage */
3439     if (!is_vampshifter(mon))
3440         return validspecmon(mon, *mndx_p);
3441
3442     if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD
3443         || *mndx_p == PM_VLAD_THE_IMPALER) {
3444         /* player picked some type of vampire; use mon's self */
3445         *mndx_p = mon->cham;
3446         return TRUE;
3447     }
3448     if (mon->cham == PM_VLAD_THE_IMPALER && mon_has_special(mon)) {
3449         /* Vlad with Candelabrum; override choice, then accept it */
3450         *mndx_p = PM_VLAD_THE_IMPALER;
3451         return TRUE;
3452     }
3453     /* basic vampires can't become wolves; any can become fog or bat
3454        (we don't enforce upper-case only for rogue level here) */
3455     if (*mndx_p == PM_WOLF)
3456         return (boolean) (mon->cham != PM_VAMPIRE);
3457     if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT)
3458         return TRUE;
3459
3460     /* if we get here, specific type was no good; try by class */
3461     switch (monclass) {
3462     case S_VAMPIRE:
3463         *mndx_p = mon->cham;
3464         break;
3465     case S_BAT:
3466         *mndx_p = PM_VAMPIRE_BAT;
3467         break;
3468     case S_VORTEX:
3469         *mndx_p = PM_FOG_CLOUD;
3470         break;
3471     case S_DOG:
3472         if (mon->cham != PM_VAMPIRE) {
3473             *mndx_p = PM_WOLF;
3474             break;
3475         }
3476     /*FALLTHRU*/
3477     default:
3478         *mndx_p = NON_PM;
3479         break;
3480     }
3481     return (boolean) (*mndx_p != NON_PM);
3482 }
3483
3484 int
3485 select_newcham_form(mon)
3486 struct monst *mon;
3487 {
3488     int mndx = NON_PM, tryct;
3489
3490     switch (mon->cham) {
3491     case PM_SANDESTIN:
3492         if (rn2(7))
3493             mndx = pick_nasty();
3494         break;
3495     case PM_DOPPELGANGER:
3496         if (!rn2(7)) {
3497             mndx = pick_nasty();
3498         } else if (rn2(3)) { /* role monsters */
3499             mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
3500         } else if (!rn2(3)) { /* quest guardians */
3501             mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT);
3502             /* avoid own role's guardian */
3503             if (mndx == urole.guardnum)
3504                 mndx = NON_PM;
3505         } else { /* general humanoids */
3506             tryct = 5;
3507             do {
3508                 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3509                 if (humanoid(&mons[mndx]) && polyok(&mons[mndx]))
3510                     break;
3511             } while (--tryct > 0);
3512             if (!tryct)
3513                 mndx = NON_PM;
3514         }
3515         break;
3516     case PM_CHAMELEON:
3517         if (!rn2(3))
3518             mndx = pick_animal();
3519         break;
3520     case PM_VLAD_THE_IMPALER:
3521     case PM_VAMPIRE_LORD:
3522     case PM_VAMPIRE:
3523         mndx = pickvampshape(mon);
3524         break;
3525     case NON_PM: /* ordinary */
3526       {
3527         struct obj *m_armr = which_armor(mon, W_ARM);
3528
3529         if (m_armr && Is_dragon_scales(m_armr))
3530             mndx = (int) (Dragon_scales_to_pm(m_armr) - mons);
3531         else if (m_armr && Is_dragon_mail(m_armr))
3532             mndx = (int) (Dragon_mail_to_pm(m_armr) - mons);
3533       }
3534         break;
3535     }
3536
3537     /* for debugging: allow control of polymorphed monster */
3538     if (wizard && iflags.mon_polycontrol) {
3539         char pprompt[BUFSZ], buf[BUFSZ] = DUMMY;
3540         int monclass;
3541
3542         Sprintf(pprompt, "Change %s @ %s into what kind of monster?",
3543                 noit_mon_nam(mon),
3544                 coord_desc((int) mon->mx, (int) mon->my, buf,
3545                            (iflags.getpos_coords != GPCOORDS_NONE)
3546                               ? iflags.getpos_coords : GPCOORDS_MAP));
3547         tryct = 5;
3548         do {
3549             monclass = 0;
3550             getlin(pprompt, buf);
3551             mungspaces(buf);
3552             /* for ESC, take form selected above (might be NON_PM) */
3553             if (*buf == '\033')
3554                 break;
3555             /* for "*", use NON_PM to pick an arbitrary shape below */
3556             if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
3557                 mndx = NON_PM;
3558                 break;
3559             }
3560             mndx = name_to_mon(buf);
3561             if (mndx == NON_PM) {
3562                 /* didn't get a type, so check whether it's a class
3563                    (single letter or text match with def_monsyms[]) */
3564                 monclass = name_to_monclass(buf, &mndx);
3565                 if (monclass && mndx == NON_PM)
3566                     mndx = mkclass_poly(monclass);
3567             }
3568             if (mndx >= LOW_PM) {
3569                 /* got a specific type of monster; use it if we can */
3570                 if (validvamp(mon, &mndx, monclass))
3571                     break;
3572                 /* can't; revert to random in case we exhaust tryct */
3573                 mndx = NON_PM;
3574             }
3575
3576             pline("It can't become that.");
3577         } while (--tryct > 0);
3578         if (!tryct)
3579             pline1(thats_enough_tries);
3580         if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass))
3581             mndx = pickvampshape(mon); /* don't resort to arbitrary */
3582     }
3583
3584     /* if no form was specified above, pick one at random now */
3585     if (mndx == NON_PM) {
3586         tryct = 50;
3587         do {
3588             mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3589         } while (--tryct > 0 && !validspecmon(mon, mndx)
3590                  /* try harder to select uppercase monster on rogue level */
3591                  && (tryct > 40 && Is_rogue_level(&u.uz)
3592                      && !isupper((uchar) mons[mndx].mlet)));
3593     }
3594     return mndx;
3595 }
3596
3597 /* this used to be inline within newcham() but monpolycontrol needs it too */
3598 STATIC_OVL struct permonst *
3599 accept_newcham_form(mndx)
3600 int mndx;
3601 {
3602     struct permonst *mdat;
3603
3604     if (mndx == NON_PM)
3605         return 0;
3606     mdat = &mons[mndx];
3607     if ((mvitals[mndx].mvflags & G_GENOD) != 0)
3608         return 0;
3609     if (is_placeholder(mdat))
3610         return 0;
3611     /* select_newcham_form() might deliberately pick a player
3612        character type (random selection never does) which
3613        polyok() rejects, so we need a special case here */
3614     if (is_mplayer(mdat))
3615         return mdat;
3616     /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */
3617     return polyok(mdat) ? mdat : 0;
3618 }
3619
3620 void
3621 mgender_from_permonst(mtmp, mdat)
3622 struct monst *mtmp;
3623 struct permonst *mdat;
3624 {
3625     if (is_male(mdat)) {
3626         if (mtmp->female)
3627             mtmp->female = FALSE;
3628     } else if (is_female(mdat)) {
3629         if (!mtmp->female)
3630             mtmp->female = TRUE;
3631     } else if (!is_neuter(mdat)) {
3632         if (!rn2(10))
3633             mtmp->female = !mtmp->female;
3634     }
3635 }
3636
3637 /* make a chameleon take on another shape, or a polymorph target
3638    (possibly self-inflicted) become a different monster;
3639    returns 1 if it actually changes form */
3640 int
3641 newcham(mtmp, mdat, polyspot, msg)
3642 struct monst *mtmp;
3643 struct permonst *mdat;
3644 boolean polyspot; /* change is the result of wand or spell of polymorph */
3645 boolean msg;      /* "The oldmon turns into a newmon!" */
3646 {
3647     int hpn, hpd;
3648     int mndx, tryct;
3649     struct permonst *olddata = mtmp->data;
3650     char *p, oldname[BUFSZ], l_oldname[BUFSZ], newname[BUFSZ];
3651
3652     /* Riders are immune to polymorph and green slime
3653        (but apparent Rider might actually be a doppelganger) */
3654     if (mtmp->cham == NON_PM) { /* not a shapechanger */
3655         if (is_rider(olddata))
3656             return 0;
3657         /* make Nazgul and erinyes immune too, to reduce chance of
3658            anomalous extinction feedback during final disclsoure */
3659         if (mbirth_limit(monsndx(olddata)) < MAXMONNO)
3660             return 0;
3661     }
3662
3663     if (msg) {
3664         /* like Monnam() but never mention saddle */
3665         Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3666                                  SUPPRESS_SADDLE, FALSE));
3667         oldname[0] = highc(oldname[0]);
3668     }
3669     /* we need this one whether msg is true or not */
3670     Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3671                                has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE));
3672
3673     /* mdat = 0 -> caller wants a random monster shape */
3674     if (mdat == 0) {
3675         /* select_newcham_form() loops when resorting to random but
3676            it doesn't always pick that so we still retry here too */
3677         tryct = 20;
3678         do {
3679             mndx = select_newcham_form(mtmp);
3680             mdat = accept_newcham_form(mndx);
3681             /* for the first several tries we require upper-case on
3682                the rogue level (after that, we take whatever we get) */
3683             if (tryct > 15 && Is_rogue_level(&u.uz)
3684                 && mdat && !isupper((uchar) mdat->mlet))
3685                 mdat = 0;
3686             if (mdat)
3687                 break;
3688         } while (--tryct > 0);
3689         if (!tryct)
3690             return 0;
3691     } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
3692         return 0; /* passed in mdat is genocided */
3693
3694     if (mdat == olddata)
3695         return 0; /* still the same monster */
3696
3697     mgender_from_permonst(mtmp, mdat);
3698     /* Endgame mplayers start out as "Foo the Bar", but some of the
3699      * titles are inappropriate when polymorphed, particularly into
3700      * the opposite sex.  Player characters don't use ranks when
3701      * polymorphed, so dropping rank for mplayers seems reasonable.
3702      */
3703     if (In_endgame(&u.uz) && is_mplayer(olddata)
3704         && has_mname(mtmp) && (p = strstr(MNAME(mtmp), " the ")) != 0)
3705         *p = '\0';
3706
3707     if (mtmp->wormno) { /* throw tail away */
3708         wormgone(mtmp);
3709         place_monster(mtmp, mtmp->mx, mtmp->my);
3710     }
3711     if (mtmp->m_ap_type && mdat->mlet != S_MIMIC)
3712         seemimic(mtmp); /* revert to normal monster */
3713
3714     /* (this code used to try to adjust the monster's health based on
3715        a normal one of its type but there are too many special cases
3716        which need to handled in order to do that correctly, so just
3717        give the new form the same proportion of HP as its old one had) */
3718     hpn = mtmp->mhp;
3719     hpd = mtmp->mhpmax;
3720     /* set level and hit points */
3721     newmonhp(mtmp, monsndx(mdat));
3722     /* new hp: same fraction of max as before */
3723 #ifndef LINT
3724     mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd);
3725 #endif
3726     /* sanity check (potential overflow) */
3727     if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax)
3728         mtmp->mhp = mtmp->mhpmax;
3729     /* unlikely but not impossible; a 1HD creature with 1HP that changes
3730        into a 0HD creature will require this statement */
3731     if (!mtmp->mhp)
3732         mtmp->mhp = 1;
3733
3734     /* take on the new form... */
3735     set_mon_data(mtmp, mdat, 0);
3736
3737     if (emits_light(olddata) != emits_light(mtmp->data)) {
3738         /* used to give light, now doesn't, or vice versa,
3739            or light's range has changed */
3740         if (emits_light(olddata))
3741             del_light_source(LS_MONSTER, monst_to_any(mtmp));
3742         if (emits_light(mtmp->data))
3743             new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
3744                              LS_MONSTER, monst_to_any(mtmp));
3745     }
3746     if (!mtmp->perminvis || pm_invisible(olddata))
3747         mtmp->perminvis = pm_invisible(mdat);
3748     mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
3749     if (mtmp->mundetected)
3750         (void) hideunder(mtmp);
3751     if (u.ustuck == mtmp) {
3752         if (u.uswallow) {
3753             if (!attacktype(mdat, AT_ENGL)) {
3754                 /* Does mdat care? */
3755                 if (!noncorporeal(mdat) && !amorphous(mdat)
3756                     && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) {
3757                     char msgtrail[BUFSZ];
3758
3759                     if (is_vampshifter(mtmp)) {
3760 #if 0 /*JP*/
3761                         Sprintf(msgtrail, " which was a shapeshifted %s",
3762                                 noname_monnam(mtmp, ARTICLE_NONE));
3763 #else
3764                         Sprintf(msgtrail, "(\8eÀ\8dÛ\82É\82Í\8c`\82ð\95Ï\82¦\82½%s)",
3765                                 noname_monnam(mtmp, ARTICLE_NONE));
3766 #endif
3767                     } else if (is_animal(mdat)) {
3768 /*JP
3769                         Strcpy(msgtrail, "'s stomach");
3770 */
3771                         Strcpy(msgtrail, "\82Ì\88Ý");
3772                     } else {
3773                         msgtrail[0] = '\0';
3774                     }
3775
3776                     /* Do this even if msg is FALSE */
3777 #if 0 /*JP*/
3778                     You("%s %s%s!",
3779                         (amorphous(olddata) || is_whirly(olddata))
3780                             ? "emerge from" : "break out of",
3781                         l_oldname, msgtrail);
3782 #else
3783                     You("%s%s%s\81I", l_oldname, msgtrail,
3784                         (amorphous(olddata) || is_whirly(olddata))
3785                             ? "\82©\82ç\94ò\82Ñ\8fo\82µ\82½" : "\82ð\94j\82è\8fo\82½"
3786                         );
3787 #endif
3788                     msg = FALSE; /* message has been given */
3789                     mtmp->mhp = 1; /* almost dead */
3790                 }
3791                 expels(mtmp, olddata, FALSE);
3792             } else {
3793                 /* update swallow glyphs for new monster */
3794                 swallowed(0);
3795             }
3796         } else if (!sticks(mdat) && !sticks(youmonst.data))
3797             unstuck(mtmp);
3798     }
3799
3800 #ifndef DCC30_BUG
3801     if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
3802 #else
3803     /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
3804      * same expression.
3805      */
3806     if (mdat == &mons[PM_LONG_WORM]
3807         && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
3808 #endif
3809         /* we can now create worms with tails - 11/91 */
3810         initworm(mtmp, rn2(5));
3811         if (count_wsegs(mtmp))
3812             place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
3813     }
3814
3815     newsym(mtmp->mx, mtmp->my);
3816
3817     if (msg) {
3818         Strcpy(newname, noname_monnam(mtmp, ARTICLE_A));
3819         /* oldname was capitalized above; newname will be lower case */
3820 #if 0 /*JP*/
3821         if (!strcmpi(newname, "it")) { /* can't see or sense it now */
3822 #else
3823         if (!strcmpi(newname, "\89½\8eÒ\82©")) { /* can't see or sense it now */
3824 #endif
3825 #if 0 /*JP*/
3826             if (!!strcmpi(oldname, "it")) /* could see or sense it before */
3827 #else
3828             if (!!strcmpi(oldname, "\89½\8eÒ\82©")) /* could see or sense it before */
3829 #endif
3830                 pline("%s disappears!", oldname);
3831             (void) usmellmon(mdat);
3832         } else { /* can see or sense it now */
3833 #if 0 /*JP*/
3834             if (!strcmpi(oldname, "it")) /* couldn't see or sense it before */
3835 #else
3836             if (!strcmpi(oldname, "\89½\8eÒ\82©")) /* couldn't see or sense it before */
3837 #endif
3838                 pline("%s appears!", upstart(newname));
3839             else
3840 /*JP
3841             pline("%s turns into %s!", oldname, newname);
3842 */
3843             pline("%s\82Í%s\82É\82È\82Á\82½\81I", oldname, newname);
3844         }
3845     }
3846
3847     /* when polymorph trap/wand/potion produces a vampire, turn in into
3848        a full-fledged vampshifter unless shape-changing is blocked */
3849     if (mtmp->cham == NON_PM && mdat->mlet == S_VAMPIRE
3850         && !Protection_from_shape_changers)
3851         mtmp->cham = pm_to_cham(monsndx(mdat));
3852
3853     possibly_unwield(mtmp, polyspot); /* might lose use of weapon */
3854     mon_break_armor(mtmp, polyspot);
3855     if (!(mtmp->misc_worn_check & W_ARMG))
3856 #if 0 /*JP*/
3857         mselftouch(mtmp, "No longer petrify-resistant, ",
3858                    !context.mon_moving);
3859 #else
3860         mselftouch(mtmp, "\90Î\89»\82Ö\82Ì\92ï\8dR\97Í\82ª\82È\82­\82È\82Á\82Ä\81C",
3861                    !context.mon_moving);
3862 #endif
3863     m_dowear(mtmp, FALSE);
3864
3865     /* This ought to re-test can_carry() on each item in the inventory
3866      * rather than just checking ex-giants & boulders, but that'd be
3867      * pretty expensive to perform.  If implemented, then perhaps
3868      * minvent should be sorted in order to drop heaviest items first.
3869      */
3870     /* former giants can't continue carrying boulders */
3871     if (mtmp->minvent && !throws_rocks(mdat)) {
3872         register struct obj *otmp, *otmp2;
3873
3874         for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
3875             otmp2 = otmp->nobj;
3876             if (otmp->otyp == BOULDER) {
3877                 /* this keeps otmp from being polymorphed in the
3878                    same zap that the monster that held it is polymorphed */
3879                 if (polyspot)
3880                     bypass_obj(otmp);
3881                 obj_extract_self(otmp);
3882                 /* probably ought to give some "drop" message here */
3883                 if (flooreffects(otmp, mtmp->mx, mtmp->my, ""))
3884                     continue;
3885                 place_object(otmp, mtmp->mx, mtmp->my);
3886             }
3887         }
3888     }
3889
3890     return 1;
3891 }
3892
3893 /* sometimes an egg will be special */
3894 #define BREEDER_EGG (!rn2(77))
3895
3896 /*
3897  * Determine if the given monster number can be hatched from an egg.
3898  * Return the monster number to use as the egg's corpsenm.  Return
3899  * NON_PM if the given monster can't be hatched.
3900  */
3901 int
3902 can_be_hatched(mnum)
3903 int mnum;
3904 {
3905     /* ranger quest nemesis has the oviparous bit set, making it
3906        be possible to wish for eggs of that unique monster; turn
3907        such into ordinary eggs rather than forbidding them outright */
3908     if (mnum == PM_SCORPIUS)
3909         mnum = PM_SCORPION;
3910
3911     mnum = little_to_big(mnum);
3912     /*
3913      * Queen bees lay killer bee eggs (usually), but killer bees don't
3914      * grow into queen bees.  Ditto for [winged-]gargoyles.
3915      */
3916     if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE
3917         || (lays_eggs(&mons[mnum])
3918             && (BREEDER_EGG
3919                 || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
3920         return mnum;
3921     return NON_PM;
3922 }
3923
3924 /* type of egg laid by #sit; usually matches parent */
3925 int
3926 egg_type_from_parent(mnum, force_ordinary)
3927 int mnum; /* parent monster; caller must handle lays_eggs() check */
3928 boolean force_ordinary;
3929 {
3930     if (force_ordinary || !BREEDER_EGG) {
3931         if (mnum == PM_QUEEN_BEE)
3932             mnum = PM_KILLER_BEE;
3933         else if (mnum == PM_WINGED_GARGOYLE)
3934             mnum = PM_GARGOYLE;
3935     }
3936     return mnum;
3937 }
3938
3939 /* decide whether an egg of the indicated monster type is viable;
3940    also used to determine whether an egg or tin can be created... */
3941 boolean
3942 dead_species(m_idx, egg)
3943 int m_idx;
3944 boolean egg;
3945 {
3946     int alt_idx;
3947
3948     /* generic eggs are unhatchable and have corpsenm of NON_PM */
3949     if (m_idx < LOW_PM)
3950         return TRUE;
3951     /*
3952      * For monsters with both baby and adult forms, genociding either
3953      * form kills all eggs of that monster.  Monsters with more than
3954      * two forms (small->large->giant mimics) are more or less ignored;
3955      * fortunately, none of them have eggs.  Species extinction due to
3956      * overpopulation does not kill eggs.
3957      */
3958     alt_idx = egg ? big_to_little(m_idx) : m_idx;
3959     return (boolean) ((mvitals[m_idx].mvflags & G_GENOD) != 0
3960                       || (mvitals[alt_idx].mvflags & G_GENOD) != 0);
3961 }
3962
3963 /* kill off any eggs of genocided monsters */
3964 STATIC_OVL void
3965 kill_eggs(obj_list)
3966 struct obj *obj_list;
3967 {
3968     struct obj *otmp;
3969
3970     for (otmp = obj_list; otmp; otmp = otmp->nobj)
3971         if (otmp->otyp == EGG) {
3972             if (dead_species(otmp->corpsenm, TRUE)) {
3973                 /*
3974                  * It seems we could also just catch this when
3975                  * it attempted to hatch, so we wouldn't have to
3976                  * search all of the objlists.. or stop all
3977                  * hatch timers based on a corpsenm.
3978                  */
3979                 kill_egg(otmp);
3980             }
3981 #if 0 /* not used */
3982         } else if (otmp->otyp == TIN) {
3983             if (dead_species(otmp->corpsenm, FALSE))
3984                 otmp->corpsenm = NON_PM; /* empty tin */
3985         } else if (otmp->otyp == CORPSE) {
3986             if (dead_species(otmp->corpsenm, FALSE))
3987                 ; /* not yet implemented... */
3988 #endif
3989         } else if (Has_contents(otmp)) {
3990             kill_eggs(otmp->cobj);
3991         }
3992 }
3993
3994 /* kill all members of genocided species */
3995 void
3996 kill_genocided_monsters()
3997 {
3998     struct monst *mtmp, *mtmp2;
3999     boolean kill_cham;
4000     int mndx;
4001
4002     /*
4003      * Called during genocide, and again upon level change.  The latter
4004      * catches up with any migrating monsters as they finally arrive at
4005      * their intended destinations, so possessions get deposited there.
4006      *
4007      * Chameleon handling:
4008      *  1) if chameleons have been genocided, destroy them
4009      *     regardless of current form;
4010      *  2) otherwise, force every chameleon which is imitating
4011      *     any genocided species to take on a new form.
4012      */
4013     for (mtmp = fmon; mtmp; mtmp = mtmp2) {
4014         mtmp2 = mtmp->nmon;
4015         if (DEADMONSTER(mtmp))
4016             continue;
4017         mndx = monsndx(mtmp->data);
4018         kill_cham = (mtmp->cham >= LOW_PM
4019                      && (mvitals[mtmp->cham].mvflags & G_GENOD));
4020         if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) {
4021             if (mtmp->cham >= LOW_PM && !kill_cham)
4022                 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
4023             else
4024                 mondead(mtmp);
4025         }
4026         if (mtmp->minvent)
4027             kill_eggs(mtmp->minvent);
4028     }
4029
4030     kill_eggs(invent);
4031     kill_eggs(fobj);
4032     kill_eggs(migrating_objs);
4033     kill_eggs(level.buriedobjlist);
4034 }
4035
4036 void
4037 golemeffects(mon, damtype, dam)
4038 register struct monst *mon;
4039 int damtype, dam;
4040 {
4041     int heal = 0, slow = 0;
4042
4043     if (mon->data == &mons[PM_FLESH_GOLEM]) {
4044         if (damtype == AD_ELEC)
4045             heal = (dam + 5) / 6;
4046         else if (damtype == AD_FIRE || damtype == AD_COLD)
4047             slow = 1;
4048     } else if (mon->data == &mons[PM_IRON_GOLEM]) {
4049         if (damtype == AD_ELEC)
4050             slow = 1;
4051         else if (damtype == AD_FIRE)
4052             heal = dam;
4053     } else {
4054         return;
4055     }
4056     if (slow) {
4057         if (mon->mspeed != MSLOW)
4058             mon_adjust_speed(mon, -1, (struct obj *) 0);
4059     }
4060     if (heal) {
4061         if (mon->mhp < mon->mhpmax) {
4062             mon->mhp += heal;
4063             if (mon->mhp > mon->mhpmax)
4064                 mon->mhp = mon->mhpmax;
4065             if (cansee(mon->mx, mon->my))
4066 /*JP
4067                 pline("%s seems healthier.", Monnam(mon));
4068 */
4069                 pline("%s\82Í\8c³\8bC\82É\82È\82Á\82½\82æ\82¤\82É\8c©\82¦\82é\81D", Monnam(mon));
4070         }
4071     }
4072 }
4073
4074 boolean
4075 angry_guards(silent)
4076 boolean silent;
4077 {
4078     struct monst *mtmp;
4079     int ct = 0, nct = 0, sct = 0, slct = 0;
4080
4081     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4082         if (DEADMONSTER(mtmp))
4083             continue;
4084         if (is_watch(mtmp->data) && mtmp->mpeaceful) {
4085             ct++;
4086             if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
4087                 if (distu(mtmp->mx, mtmp->my) == 2)
4088                     nct++;
4089                 else
4090                     sct++;
4091             }
4092             if (mtmp->msleeping || mtmp->mfrozen) {
4093                 slct++;
4094                 mtmp->msleeping = mtmp->mfrozen = 0;
4095             }
4096             mtmp->mpeaceful = 0;
4097         }
4098     }
4099     if (ct) {
4100         if (!silent) { /* do we want pline msgs? */
4101             if (slct)
4102 #if 0 /*JP*/
4103                 pline_The("guard%s wake%s up!", slct > 1 ? "s" : "",
4104                           slct == 1 ? "s" : "");
4105 #else
4106                 pline("\94Ô\95º\82Í\96Ú\82ð\8ao\82Ü\82µ\82½\81I");
4107 #endif
4108             if (nct || sct) {
4109                 if (nct)
4110 #if 0 /*JP*/
4111                     pline_The("guard%s get%s angry!", nct == 1 ? "" : "s",
4112                               nct == 1 ? "s" : "");
4113 #else
4114                     pline("\94Ô\95º\82Í\93{\82Á\82½\81I");
4115 #endif
4116                 else if (!Blind)
4117 #if 0 /*JP*/
4118                     You_see("%sangry guard%s approaching!",
4119                             sct == 1 ? "an " : "", sct > 1 ? "s" : "");
4120 #else
4121                     You("\93{\82Á\82½\94Ô\95º\82ª\8bß\8añ\82Á\82Ä\82­\82é\82Ì\82ð\8c©\82½\81I");
4122 #endif
4123             } else
4124 /*JP
4125                 You_hear("the shrill sound of a guard's whistle.");
4126 */
4127                 You_hear("\94Ô\95º\82Ì\93J\82ª\82¯\82½\82½\82Ü\82µ\82­\96Â\82é\82Ì\82ð\95·\82¢\82½\81D");
4128         }
4129         return TRUE;
4130     }
4131     return FALSE;
4132 }
4133
4134 void
4135 pacify_guards()
4136 {
4137     struct monst *mtmp;
4138
4139     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4140         if (DEADMONSTER(mtmp))
4141             continue;
4142         if (is_watch(mtmp->data))
4143             mtmp->mpeaceful = 1;
4144     }
4145 }
4146
4147 void
4148 mimic_hit_msg(mtmp, otyp)
4149 struct monst *mtmp;
4150 short otyp;
4151 {
4152     short ap = mtmp->mappearance;
4153
4154     switch (mtmp->m_ap_type) {
4155     case M_AP_NOTHING:
4156     case M_AP_FURNITURE:
4157     case M_AP_MONSTER:
4158         break;
4159     case M_AP_OBJECT:
4160         if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
4161 #if 0 /*JP*/
4162             pline("%s seems a more vivid %s than before.",
4163                   The(simple_typename(ap)),
4164                   c_obj_colors[objects[ap].oc_color]);
4165 #else
4166             pline("%s\82Í\88È\91O\82æ\82è\82æ\82è\91N\82â\82©\82È%s\82É\82È\82Á\82½\82æ\82¤\82¾\81D",
4167                   The(simple_typename(ap)),
4168                   c_obj_colors[objects[ap].oc_color]);
4169 #endif
4170         }
4171         break;
4172     }
4173 }
4174
4175 boolean
4176 usmellmon(mdat)
4177 struct permonst *mdat;
4178 {
4179     int mndx;
4180     boolean nonspecific = FALSE;
4181     boolean msg_given = FALSE;
4182
4183     if (mdat) {
4184         if (!olfaction(youmonst.data))
4185             return FALSE;
4186         mndx = monsndx(mdat);
4187         switch (mndx) {
4188         case PM_ROTHE:
4189         case PM_MINOTAUR:
4190 /*JP
4191             You("notice a bovine smell.");
4192 */
4193             You("\8b\8d\82Ì\82æ\82¤\82È\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4194             msg_given = TRUE;
4195             break;
4196         case PM_CAVEMAN:
4197         case PM_CAVEWOMAN:
4198         case PM_BARBARIAN:
4199         case PM_NEANDERTHAL:
4200 /*JP
4201             You("smell body odor.");
4202 */
4203             pline("\91Ì\8fL\82Ì\82æ\82¤\82È\82É\82¨\82¢\82ª\82µ\82½\81D");
4204             msg_given = TRUE;
4205             break;
4206         /*
4207         case PM_PESTILENCE:
4208         case PM_FAMINE:
4209         case PM_DEATH:
4210             break;
4211         */
4212         case PM_HORNED_DEVIL:
4213         case PM_BALROG:
4214         case PM_ASMODEUS:
4215         case PM_DISPATER:
4216         case PM_YEENOGHU:
4217         case PM_ORCUS:
4218             break;
4219         case PM_HUMAN_WEREJACKAL:
4220         case PM_HUMAN_WERERAT:
4221         case PM_HUMAN_WEREWOLF:
4222         case PM_WEREJACKAL:
4223         case PM_WERERAT:
4224         case PM_WEREWOLF:
4225         case PM_OWLBEAR:
4226 /*JP
4227             You("detect an odor reminiscent of an animal's den.");
4228 */
4229             pline("\93®\95¨\82Ì\82Ë\82®\82ç\82ð\8ev\82¢\8fo\82·\82æ\82¤\82È\82É\82¨\82¢\82ª\82µ\82½\81D");
4230             msg_given = TRUE;
4231             break;
4232         /*
4233         case PM_PURPLE_WORM:
4234             break;
4235         */
4236         case PM_STEAM_VORTEX:
4237 /*JP
4238             You("smell steam.");
4239 */
4240             pline("\8fö\8bC\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4241             msg_given = TRUE;
4242             break;
4243         case PM_GREEN_SLIME:
4244 /*JP
4245             pline("%s stinks.", Something);
4246 */
4247             pline("\88«\8fL\82ª\82µ\82½\81D");
4248             msg_given = TRUE;
4249             break;
4250         case PM_VIOLET_FUNGUS:
4251         case PM_SHRIEKER:
4252 /*JP
4253             You("smell mushrooms.");
4254 */
4255             pline("\82«\82Ì\82±\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4256             msg_given = TRUE;
4257             break;
4258         /* These are here to avoid triggering the
4259            nonspecific treatment through the default case below*/
4260         case PM_WHITE_UNICORN:
4261         case PM_GRAY_UNICORN:
4262         case PM_BLACK_UNICORN:
4263         case PM_JELLYFISH:
4264             break;
4265         default:
4266             nonspecific = TRUE;
4267             break;
4268         }
4269
4270         if (nonspecific)
4271             switch (mdat->mlet) {
4272             case S_DOG:
4273 /*JP
4274                 You("notice a dog smell.");
4275 */
4276                 You("\8c¢\82Ì\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4277                 msg_given = TRUE;
4278                 break;
4279             case S_DRAGON:
4280 /*JP
4281                 You("smell a dragon!");
4282 */
4283                 pline("\83h\83\89\83S\83\93\82Ì\82É\82¨\82¢\82ª\82·\82é\81I");
4284                 msg_given = TRUE;
4285                 break;
4286             case S_FUNGUS:
4287 /*JP
4288                 pline("%s smells moldy.", Something);
4289 */
4290                 pline("\89½\82©\91Û\82Ì\82æ\82¤\82È\82É\82¨\82¢\82ª\82·\82é\81D");
4291                 msg_given = TRUE;
4292                 break;
4293             case S_UNICORN:
4294 #if 0 /*JP*/
4295                 You("detect a%s odor reminiscent of a stable.",
4296                     (mndx == PM_PONY) ? "n" : " strong");
4297 #else
4298                 pline("\94n\8f¬\89®\82ð\8ev\82¢\8fo\82·\82æ\82¤\82È%s\82É\82¨\82¢\82ª\82µ\82½\81D",
4299                     (mndx == PM_PONY) ? "" : "\8b­\82¢");
4300 #endif
4301                 msg_given = TRUE;
4302                 break;
4303             case S_ZOMBIE:
4304 /*JP
4305                 You("smell rotting flesh.");
4306 */
4307                 pline("\95\85\82Á\82½\93÷\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4308                 msg_given = TRUE;
4309                 break;
4310             case S_EEL:
4311 /*JP
4312                 You("smell fish.");
4313 */
4314                 pline("\8b\9b\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4315                 msg_given = TRUE;
4316                 break;
4317             case S_ORC:
4318                 if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
4319 /*JP
4320                     You("notice an attractive smell.");
4321 */
4322                     You("\96£\97Í\93I\82È\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4323                 else
4324 /*JP
4325                     pline("A foul stench makes you feel a little nauseated.");
4326 */
4327                     pline("\82Þ\82©\82Â\82­\82æ\82¤\82È\88«\8fL\82Å\8f­\82µ\8bC\95ª\82ª\88«\82­\82È\82Á\82½\81D");
4328                 msg_given = TRUE;
4329                 break;
4330             default:
4331                 break;
4332             }
4333     }
4334     return msg_given ? TRUE : FALSE;
4335 }
4336
4337 /*mon.c*/