OSDN Git Service

update year to 2019
[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-2019            */
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 #if 0 /*JP*/
1116     int mat_idx;
1117 #endif
1118
1119     if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) {
1120 #if 0 /*JP*/
1121         mat_idx = objects[gold->otyp].oc_material;
1122 #endif
1123         obj_extract_self(gold);
1124         add_to_minv(mtmp, gold);
1125         if (cansee(mtmp->mx, mtmp->my)) {
1126             if (flags.verbose && !mtmp->isgd)
1127 #if 0 /*JP*/
1128                 pline("%s picks up some %s.", Monnam(mtmp),
1129                       mat_idx == GOLD ? "gold" : "money");
1130 #else
1131                 pline("%s\82Í\82¨\8bà\82ð\8fE\82Á\82½\81D", Monnam(mtmp));
1132 #endif
1133             newsym(mtmp->mx, mtmp->my);
1134         }
1135     }
1136 }
1137
1138 boolean
1139 mpickstuff(mtmp, str)
1140 register struct monst *mtmp;
1141 register const char *str;
1142 {
1143     register struct obj *otmp, *otmp2, *otmp3;
1144     int carryamt = 0;
1145
1146     /* prevent shopkeepers from leaving the door of their shop */
1147     if (mtmp->isshk && inhishop(mtmp))
1148         return FALSE;
1149
1150     for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
1151         otmp2 = otmp->nexthere;
1152         /* Nymphs take everything.  Most monsters don't pick up corpses. */
1153         if (!str ? searches_for_item(mtmp, otmp)
1154                  : !!(index(str, otmp->oclass))) {
1155             if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
1156                 /* let a handful of corpse types thru to can_carry() */
1157                 && !touch_petrifies(&mons[otmp->corpsenm])
1158                 && otmp->corpsenm != PM_LIZARD
1159                 && !acidic(&mons[otmp->corpsenm]))
1160                 continue;
1161             if (!touch_artifact(otmp, mtmp))
1162                 continue;
1163             carryamt = can_carry(mtmp, otmp);
1164             if (carryamt == 0)
1165                 continue;
1166             if (is_pool(mtmp->mx, mtmp->my))
1167                 continue;
1168             /* handle cases where the critter can only get some */
1169             otmp3 = otmp;
1170             if (carryamt != otmp->quan) {
1171                 otmp3 = splitobj(otmp, carryamt);
1172             }
1173             if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
1174 #if 0 /*JP*/
1175                 pline("%s picks up %s.", Monnam(mtmp),
1176                       (distu(mtmp->mx, mtmp->my) <= 5)
1177                           ? doname(otmp3)
1178                           : distant_name(otmp3, doname));
1179 #else
1180                 pline("%s\82Í%s\82ð\8fE\82Á\82½\81D", Monnam(mtmp),
1181                       (distu(mtmp->mx, mtmp->my) <= 5)
1182                           ? doname(otmp3)
1183                           : distant_name(otmp3, doname));
1184 #endif
1185             obj_extract_self(otmp3);      /* remove from floor */
1186             (void) mpickobj(mtmp, otmp3); /* may merge and free otmp3 */
1187             m_dowear(mtmp, FALSE);
1188             newsym(mtmp->mx, mtmp->my);
1189             return TRUE; /* pick only one object */
1190         }
1191     }
1192     return FALSE;
1193 }
1194
1195 int
1196 curr_mon_load(mtmp)
1197 struct monst *mtmp;
1198 {
1199     int curload = 0;
1200     struct obj *obj;
1201
1202     for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1203         if (obj->otyp != BOULDER || !throws_rocks(mtmp->data))
1204             curload += obj->owt;
1205     }
1206
1207     return curload;
1208 }
1209
1210 int
1211 max_mon_load(mtmp)
1212 struct monst *mtmp;
1213 {
1214     long maxload;
1215
1216     /* Base monster carrying capacity is equal to human maximum
1217      * carrying capacity, or half human maximum if not strong.
1218      * (for a polymorphed player, the value used would be the
1219      * non-polymorphed carrying capacity instead of max/half max).
1220      * This is then modified by the ratio between the monster weights
1221      * and human weights.  Corpseless monsters are given a capacity
1222      * proportional to their size instead of weight.
1223      */
1224     if (!mtmp->data->cwt)
1225         maxload = (MAX_CARR_CAP * (long) mtmp->data->msize) / MZ_HUMAN;
1226     else if (!strongmonst(mtmp->data)
1227              || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN)))
1228         maxload = (MAX_CARR_CAP * (long) mtmp->data->cwt) / WT_HUMAN;
1229     else
1230         maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/
1231
1232     if (!strongmonst(mtmp->data))
1233         maxload /= 2;
1234
1235     if (maxload < 1)
1236         maxload = 1;
1237
1238     return (int) maxload;
1239 }
1240
1241 /* for restricting monsters' object-pickup.
1242  *
1243  * to support the new pet behavior, this now returns the max # of objects
1244  * that a given monster could pick up from a pile. frequently this will be
1245  * otmp->quan, but special cases for 'only one' now exist so.
1246  *
1247  * this will probably cause very amusing behavior with pets and gold coins.
1248  *
1249  * TODO: allow picking up 2-N objects from a pile of N based on weight.
1250  *       Change from 'int' to 'long' to accomate big stacks of gold.
1251  *       Right now we fake it by reporting a partial quantity, but the
1252  *       likesgold handling m_move results in picking up the whole stack.
1253  */
1254 int
1255 can_carry(mtmp, otmp)
1256 struct monst *mtmp;
1257 struct obj *otmp;
1258 {
1259     int iquan, otyp = otmp->otyp, newload = otmp->owt;
1260     struct permonst *mdat = mtmp->data;
1261     short nattk = 0;
1262
1263     if (notake(mdat))
1264         return 0; /* can't carry anything */
1265
1266     if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])
1267         && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp))
1268         return 0;
1269     if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm]))
1270         return 0;
1271     if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp)
1272         && (otyp != BELL_OF_OPENING || !is_covetous(mdat)))
1273         return 0;
1274
1275     /* hostile monsters who like gold will pick up the whole stack;
1276        tame mosnters with hands will pick up the partial stack */
1277     iquan = (otmp->quan > (long) LARGEST_INT)
1278                ? 20000 + rn2(LARGEST_INT - 20000 + 1)
1279                : (int) otmp->quan;
1280
1281     /* monsters without hands can't pick up multiple objects at once
1282      * unless they have an engulfing attack
1283      *
1284      * ...dragons, of course, can always carry gold pieces and gems somehow
1285      */
1286     if (iquan > 1) {
1287         boolean glomper = FALSE;
1288
1289         if (mtmp->data->mlet == S_DRAGON
1290             && (otmp->oclass == COIN_CLASS
1291                 || otmp->oclass == GEM_CLASS))
1292             glomper = TRUE;
1293         else
1294             for (nattk = 0; nattk < NATTK; nattk++)
1295                 if (mtmp->data->mattk[nattk].aatyp == AT_ENGL) {
1296                     glomper = TRUE;
1297                     break;
1298                 }
1299         if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper)
1300             return 1;
1301     }
1302
1303     /* steeds don't pick up stuff (to avoid shop abuse) */
1304     if (mtmp == u.usteed)
1305         return 0;
1306     if (mtmp->isshk)
1307         return iquan; /* no limit */
1308     if (mtmp->mpeaceful && !mtmp->mtame)
1309         return 0;
1310     /* otherwise players might find themselves obligated to violate
1311      * their alignment if the monster takes something they need
1312      */
1313
1314     /* special--boulder throwers carry unlimited amounts of boulders */
1315     if (throws_rocks(mdat) && otyp == BOULDER)
1316         return iquan;
1317
1318     /* nymphs deal in stolen merchandise, but not boulders or statues */
1319     if (mdat->mlet == S_NYMPH)
1320         return (otmp->oclass == ROCK_CLASS) ? 0 : iquan;
1321
1322     if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp))
1323         return 0;
1324
1325     return iquan;
1326 }
1327
1328 /* return number of acceptable neighbour positions */
1329 int
1330 mfndpos(mon, poss, info, flag)
1331 struct monst *mon;
1332 coord *poss; /* coord poss[9] */
1333 long *info;  /* long info[9] */
1334 long flag;
1335 {
1336     struct permonst *mdat = mon->data;
1337     register struct trap *ttmp;
1338     xchar x, y, nx, ny;
1339     int cnt = 0;
1340     uchar ntyp;
1341     uchar nowtyp;
1342     boolean wantpool, poolok, lavaok, nodiag;
1343     boolean rockok = FALSE, treeok = FALSE, thrudoor;
1344     int maxx, maxy;
1345     boolean poisongas_ok, in_poisongas;
1346     NhRegion *gas_reg;
1347     int gas_glyph = cmap_to_glyph(S_poisoncloud);
1348
1349     x = mon->mx;
1350     y = mon->my;
1351     nowtyp = levl[x][y].typ;
1352
1353     nodiag = NODIAG(mdat - mons);
1354     wantpool = mdat->mlet == S_EEL;
1355     poolok = (is_flyer(mdat) || is_clinger(mdat)
1356               || (is_swimmer(mdat) && !wantpool));
1357     lavaok = (is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat));
1358     thrudoor = ((flag & (ALLOW_WALL | BUSTDOOR)) != 0L);
1359     poisongas_ok = ((nonliving(mdat) || is_vampshifter(mon)
1360                      || breathless(mdat)) || resists_poison(mon));
1361     in_poisongas = ((gas_reg = visible_region_at(x,y)) != 0
1362                     && gas_reg->glyph == gas_glyph);
1363
1364     if (flag & ALLOW_DIG) {
1365         struct obj *mw_tmp;
1366
1367         /* need to be specific about what can currently be dug */
1368         if (!needspick(mdat)) {
1369             rockok = treeok = TRUE;
1370         } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed
1371                    && mon->weapon_check == NO_WEAPON_WANTED) {
1372             rockok = is_pick(mw_tmp);
1373             treeok = is_axe(mw_tmp);
1374         } else {
1375             rockok = (m_carrying(mon, PICK_AXE)
1376                       || (m_carrying(mon, DWARVISH_MATTOCK)
1377                           && !which_armor(mon, W_ARMS)));
1378             treeok = (m_carrying(mon, AXE) || (m_carrying(mon, BATTLE_AXE)
1379                                                && !which_armor(mon, W_ARMS)));
1380         }
1381         if (rockok || treeok)
1382             thrudoor = TRUE;
1383     }
1384
1385 nexttry: /* eels prefer the water, but if there is no water nearby,
1386             they will crawl over land */
1387     if (mon->mconf) {
1388         flag |= ALLOW_ALL;
1389         flag &= ~NOTONL;
1390     }
1391     if (!mon->mcansee)
1392         flag |= ALLOW_SSM;
1393     maxx = min(x + 1, COLNO - 1);
1394     maxy = min(y + 1, ROWNO - 1);
1395     for (nx = max(1, x - 1); nx <= maxx; nx++)
1396         for (ny = max(0, y - 1); ny <= maxy; ny++) {
1397             if (nx == x && ny == y)
1398                 continue;
1399             ntyp = levl[nx][ny].typ;
1400             if (IS_ROCK(ntyp)
1401                 && !((flag & ALLOW_WALL) && may_passwall(nx, ny))
1402                 && !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx, ny)))
1403                 continue;
1404             /* KMH -- Added iron bars */
1405             if (ntyp == IRONBARS && !(flag & ALLOW_BARS))
1406                 continue;
1407             if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon))
1408                 && (((levl[nx][ny].doormask & D_CLOSED) && !(flag & OPENDOOR))
1409                     || ((levl[nx][ny].doormask & D_LOCKED)
1410                         && !(flag & UNLOCKDOOR))) && !thrudoor)
1411                 continue;
1412             /* avoid poison gas? */
1413             if (!poisongas_ok && !in_poisongas
1414                 && (gas_reg = visible_region_at(nx,ny)) != 0
1415                 && gas_reg->glyph == gas_glyph)
1416                 continue;
1417             /* first diagonal checks (tight squeezes handled below) */
1418             if (nx != x && ny != y
1419                 && (nodiag
1420                     || (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN))
1421                     || (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN))
1422                     || ((IS_DOOR(nowtyp) || IS_DOOR(ntyp))
1423                         && Is_rogue_level(&u.uz))
1424                     /* mustn't pass between adjacent long worm segments,
1425                        but can attack that way */
1426                     || (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny)
1427                         && !m_at(nx, ny) && (nx != u.ux || ny != u.uy))))
1428                 continue;
1429             if ((is_pool(nx, ny) == wantpool || poolok)
1430                 && (lavaok || !is_lava(nx, ny))) {
1431                 int dispx, dispy;
1432                 boolean monseeu = (mon->mcansee
1433                                    && (!Invis || perceives(mdat)));
1434                 boolean checkobj = OBJ_AT(nx, ny);
1435
1436                 /* Displacement also displaces the Elbereth/scare monster,
1437                  * as long as you are visible.
1438                  */
1439                 if (Displaced && monseeu && mon->mux == nx && mon->muy == ny) {
1440                     dispx = u.ux;
1441                     dispy = u.uy;
1442                 } else {
1443                     dispx = nx;
1444                     dispy = ny;
1445                 }
1446
1447                 info[cnt] = 0;
1448                 if (onscary(dispx, dispy, mon)) {
1449                     if (!(flag & ALLOW_SSM))
1450                         continue;
1451                     info[cnt] |= ALLOW_SSM;
1452                 }
1453                 if ((nx == u.ux && ny == u.uy)
1454                     || (nx == mon->mux && ny == mon->muy)) {
1455                     if (nx == u.ux && ny == u.uy) {
1456                         /* If it's right next to you, it found you,
1457                          * displaced or no.  We must set mux and muy
1458                          * right now, so when we return we can tell
1459                          * that the ALLOW_U means to attack _you_ and
1460                          * not the image.
1461                          */
1462                         mon->mux = u.ux;
1463                         mon->muy = u.uy;
1464                     }
1465                     if (!(flag & ALLOW_U))
1466                         continue;
1467                     info[cnt] |= ALLOW_U;
1468                 } else {
1469                     if (MON_AT(nx, ny)) {
1470                         struct monst *mtmp2 = m_at(nx, ny);
1471                         long mmflag = flag | mm_aggression(mon, mtmp2);
1472
1473                         if (mmflag & ALLOW_M) {
1474                             info[cnt] |= ALLOW_M;
1475                             if (mtmp2->mtame) {
1476                                 if (!(mmflag & ALLOW_TM))
1477                                     continue;
1478                                 info[cnt] |= ALLOW_TM;
1479                             }
1480                         } else {
1481                             mmflag = flag | mm_displacement(mon, mtmp2);
1482                             if (!(mmflag & ALLOW_MDISP))
1483                                 continue;
1484                             info[cnt] |= ALLOW_MDISP;
1485                         }
1486                     }
1487                     /* Note: ALLOW_SANCT only prevents movement, not
1488                        attack, into a temple. */
1489                     if (level.flags.has_temple && *in_rooms(nx, ny, TEMPLE)
1490                         && !*in_rooms(x, y, TEMPLE)
1491                         && in_your_sanctuary((struct monst *) 0, nx, ny)) {
1492                         if (!(flag & ALLOW_SANCT))
1493                             continue;
1494                         info[cnt] |= ALLOW_SANCT;
1495                     }
1496                 }
1497                 if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
1498                     if (flag & NOGARLIC)
1499                         continue;
1500                     info[cnt] |= NOGARLIC;
1501                 }
1502                 if (checkobj && sobj_at(BOULDER, nx, ny)) {
1503                     if (!(flag & ALLOW_ROCK))
1504                         continue;
1505                     info[cnt] |= ALLOW_ROCK;
1506                 }
1507                 if (monseeu && onlineu(nx, ny)) {
1508                     if (flag & NOTONL)
1509                         continue;
1510                     info[cnt] |= NOTONL;
1511                 }
1512                 /* check for diagonal tight squeeze */
1513                 if (nx != x && ny != y && bad_rock(mdat, x, ny)
1514                     && bad_rock(mdat, nx, y) && cant_squeeze_thru(mon))
1515                     continue;
1516                 /* The monster avoids a particular type of trap if it's
1517                  * familiar with the trap type.  Pets get ALLOW_TRAPS
1518                  * and checking is done in dogmove.c.  In either case,
1519                  * "harmless" traps are neither avoided nor marked in info[].
1520                  */
1521                 if ((ttmp = t_at(nx, ny)) != 0) {
1522                     if (ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) {
1523                         impossible(
1524                          "A monster looked at a very strange trap of type %d.",
1525                                    ttmp->ttyp);
1526                             continue;
1527                     }
1528                     if ((ttmp->ttyp != RUST_TRAP
1529                          || mdat == &mons[PM_IRON_GOLEM])
1530                         && ttmp->ttyp != STATUE_TRAP
1531                         && ((ttmp->ttyp != PIT && ttmp->ttyp != SPIKED_PIT
1532                              && ttmp->ttyp != TRAPDOOR && ttmp->ttyp != HOLE)
1533                             || (!is_flyer(mdat) && !is_floater(mdat)
1534                                 && !is_clinger(mdat)) || Sokoban)
1535                         && (ttmp->ttyp != SLP_GAS_TRAP || !resists_sleep(mon))
1536                         && (ttmp->ttyp != BEAR_TRAP
1537                             || (mdat->msize > MZ_SMALL && !amorphous(mdat)
1538                                 && !is_flyer(mdat) && !is_floater(mdat)
1539                                 && !is_whirly(mdat) && !unsolid(mdat)))
1540                         && (ttmp->ttyp != FIRE_TRAP || !resists_fire(mon))
1541                         && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat))
1542                         && (ttmp->ttyp != WEB
1543                             || (!amorphous(mdat) && !webmaker(mdat)
1544                                 && !is_whirly(mdat) && !unsolid(mdat)))
1545                         && (ttmp->ttyp != ANTI_MAGIC || !resists_magm(mon))) {
1546                         if (!(flag & ALLOW_TRAPS)) {
1547                             if (mon->mtrapseen & (1L << (ttmp->ttyp - 1)))
1548                                 continue;
1549                         }
1550                         info[cnt] |= ALLOW_TRAPS;
1551                     }
1552                 }
1553                 poss[cnt].x = nx;
1554                 poss[cnt].y = ny;
1555                 cnt++;
1556             }
1557         }
1558     if (!cnt && wantpool && !is_pool(x, y)) {
1559         wantpool = FALSE;
1560         goto nexttry;
1561     }
1562     return cnt;
1563 }
1564
1565 /* Monster against monster special attacks; for the specified monster
1566    combinations, this allows one monster to attack another adjacent one
1567    in the absence of Conflict.  There is no provision for targetting
1568    other monsters; just hand to hand fighting when they happen to be
1569    next to each other. */
1570 STATIC_OVL long
1571 mm_aggression(magr, mdef)
1572 struct monst *magr, /* monster that is currently deciding where to move */
1573              *mdef; /* another monster which is next to it */
1574 {
1575     /* supposedly purple worms are attracted to shrieking because they
1576        like to eat shriekers, so attack the latter when feasible */
1577     if (magr->data == &mons[PM_PURPLE_WORM]
1578         && mdef->data == &mons[PM_SHRIEKER])
1579         return ALLOW_M | ALLOW_TM;
1580     /* Various other combinations such as dog vs cat, cat vs rat, and
1581        elf vs orc have been suggested.  For the time being we don't
1582        support those. */
1583     return 0L;
1584 }
1585
1586 /* Monster displacing another monster out of the way */
1587 STATIC_OVL long
1588 mm_displacement(magr, mdef)
1589 struct monst *magr, /* monster that is currently deciding where to move */
1590              *mdef; /* another monster which is next to it */
1591 {
1592     struct permonst *pa = magr->data, *pd = mdef->data;
1593
1594     /* if attacker can't barge through, there's nothing to do;
1595        or if defender can barge through too, don't let attacker
1596        do so, otherwise they might just end up swapping places
1597        again when defender gets its chance to move */
1598     if ((pa->mflags3 & M3_DISPLACES) != 0 && (pd->mflags3 & M3_DISPLACES) == 0
1599         /* no displacing grid bugs diagonally */
1600         && !(magr->mx != mdef->mx && magr->my != mdef->my
1601              && NODIAG(monsndx(pd)))
1602         /* no displacing trapped monsters or multi-location longworms */
1603         && !mdef->mtrapped && (!mdef->wormno || !count_wsegs(mdef))
1604         /* riders can move anything; others, same size or smaller only */
1605         && (is_rider(pa) || pa->msize >= pd->msize))
1606         return ALLOW_MDISP;
1607     return 0L;
1608 }
1609
1610 /* Is the square close enough for the monster to move or attack into? */
1611 boolean
1612 monnear(mon, x, y)
1613 struct monst *mon;
1614 int x, y;
1615 {
1616     int distance = dist2(mon->mx, mon->my, x, y);
1617
1618     if (distance == 2 && NODIAG(mon->data - mons))
1619         return 0;
1620     return (boolean) (distance < 3);
1621 }
1622
1623 /* really free dead monsters */
1624 void
1625 dmonsfree()
1626 {
1627     struct monst **mtmp, *freetmp;
1628     int count = 0;
1629
1630     for (mtmp = &fmon; *mtmp;) {
1631         freetmp = *mtmp;
1632         if (freetmp->mhp <= 0 && !freetmp->isgd) {
1633             *mtmp = freetmp->nmon;
1634             freetmp->nmon = NULL;
1635             dealloc_monst(freetmp);
1636             count++;
1637         } else
1638             mtmp = &(freetmp->nmon);
1639     }
1640
1641     if (count != iflags.purge_monsters)
1642         impossible("dmonsfree: %d removed doesn't match %d pending",
1643                    count, iflags.purge_monsters);
1644     iflags.purge_monsters = 0;
1645 }
1646
1647 /* called when monster is moved to larger structure */
1648 void
1649 replmon(mtmp, mtmp2)
1650 struct monst *mtmp, *mtmp2;
1651 {
1652     struct obj *otmp;
1653
1654     /* transfer the monster's inventory */
1655     for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
1656         if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
1657             impossible("replmon: minvent inconsistency");
1658         otmp->ocarry = mtmp2;
1659     }
1660     mtmp->minvent = 0;
1661
1662     /* remove the old monster from the map and from `fmon' list */
1663     relmon(mtmp, (struct monst **) 0);
1664
1665     /* finish adding its replacement */
1666     if (mtmp != u.usteed) /* don't place steed onto the map */
1667         place_monster(mtmp2, mtmp2->mx, mtmp2->my);
1668     if (mtmp2->wormno)      /* update level.monsters[wseg->wx][wseg->wy] */
1669         place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */
1670     if (emits_light(mtmp2->data)) {
1671         /* since this is so rare, we don't have any `mon_move_light_source' */
1672         new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
1673                          LS_MONSTER, monst_to_any(mtmp2));
1674         /* here we rely on fact that `mtmp' hasn't actually been deleted */
1675         del_light_source(LS_MONSTER, monst_to_any(mtmp));
1676     }
1677     mtmp2->nmon = fmon;
1678     fmon = mtmp2;
1679     if (u.ustuck == mtmp)
1680         u.ustuck = mtmp2;
1681     if (u.usteed == mtmp)
1682         u.usteed = mtmp2;
1683     if (mtmp2->isshk)
1684         replshk(mtmp, mtmp2);
1685
1686     /* discard the old monster */
1687     dealloc_monst(mtmp);
1688 }
1689
1690 /* release mon from the display and the map's monster list,
1691    maybe transfer it to one of the other monster lists */
1692 void
1693 relmon(mon, monst_list)
1694 struct monst *mon;
1695 struct monst **monst_list; /* &migrating_mons or &mydogs or null */
1696 {
1697     struct monst *mtmp;
1698     boolean unhide = (monst_list != 0);
1699     int mx = mon->mx, my = mon->my;
1700
1701     if (!fmon)
1702         panic("relmon: no fmon available.");
1703
1704     if (unhide) {
1705         /* can't remain hidden across level changes (exception: wizard
1706            clone can continue imitating some other monster form); also,
1707            might be imitating a boulder so need line-of-sight unblocking */
1708         mon->mundetected = 0;
1709         if (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)
1710             seemimic(mon);
1711     }
1712
1713     if (mon->wormno)
1714         remove_worm(mon);
1715     else
1716         remove_monster(mx, my);
1717
1718     if (mon == fmon) {
1719         fmon = fmon->nmon;
1720     } else {
1721         for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1722             if (mtmp->nmon == mon)
1723                 break;
1724
1725         if (mtmp)
1726             mtmp->nmon = mon->nmon;
1727         else
1728             panic("relmon: mon not in list.");
1729     }
1730
1731     if (unhide) {
1732         newsym(mx, my);
1733         /* insert into mydogs or migrating_mons */
1734         mon->nmon = *monst_list;
1735         *monst_list = mon;
1736     } else {
1737         /* orphan has no next monster */
1738         mon->nmon = 0;
1739     }
1740 }
1741
1742 void
1743 copy_mextra(mtmp2, mtmp1)
1744 struct monst *mtmp2, *mtmp1;
1745 {
1746     if (!mtmp2 || !mtmp1 || !mtmp1->mextra)
1747         return;
1748
1749     if (!mtmp2->mextra)
1750         mtmp2->mextra = newmextra();
1751     if (MNAME(mtmp1)) {
1752         new_mname(mtmp2, (int) strlen(MNAME(mtmp1)) + 1);
1753         Strcpy(MNAME(mtmp2), MNAME(mtmp1));
1754     }
1755     if (EGD(mtmp1)) {
1756         if (!EGD(mtmp2))
1757             newegd(mtmp2);
1758         *EGD(mtmp2) = *EGD(mtmp1);
1759     }
1760     if (EPRI(mtmp1)) {
1761         if (!EPRI(mtmp2))
1762             newepri(mtmp2);
1763         *EPRI(mtmp2) = *EPRI(mtmp1);
1764     }
1765     if (ESHK(mtmp1)) {
1766         if (!ESHK(mtmp2))
1767             neweshk(mtmp2);
1768         *ESHK(mtmp2) = *ESHK(mtmp1);
1769     }
1770     if (EMIN(mtmp1)) {
1771         if (!EMIN(mtmp2))
1772             newemin(mtmp2);
1773         *EMIN(mtmp2) = *EMIN(mtmp1);
1774     }
1775     if (EDOG(mtmp1)) {
1776         if (!EDOG(mtmp2))
1777             newedog(mtmp2);
1778         *EDOG(mtmp2) = *EDOG(mtmp1);
1779     }
1780     if (has_mcorpsenm(mtmp1))
1781         MCORPSENM(mtmp2) = MCORPSENM(mtmp1);
1782 }
1783
1784 void
1785 dealloc_mextra(m)
1786 struct monst *m;
1787 {
1788     struct mextra *x = m->mextra;
1789
1790     if (x) {
1791         if (x->mname)
1792             free((genericptr_t) x->mname);
1793         if (x->egd)
1794             free((genericptr_t) x->egd);
1795         if (x->epri)
1796             free((genericptr_t) x->epri);
1797         if (x->eshk)
1798             free((genericptr_t) x->eshk);
1799         if (x->emin)
1800             free((genericptr_t) x->emin);
1801         if (x->edog)
1802             free((genericptr_t) x->edog);
1803         /* [no action needed for x->mcorpsenm] */
1804
1805         free((genericptr_t) x);
1806         m->mextra = (struct mextra *) 0;
1807     }
1808 }
1809
1810 void
1811 dealloc_monst(mon)
1812 struct monst *mon;
1813 {
1814     if (mon->nmon)
1815         panic("dealloc_monst with nmon");
1816     if (mon->mextra)
1817         dealloc_mextra(mon);
1818     free((genericptr_t) mon);
1819 }
1820
1821 /* remove effects of mtmp from other data structures */
1822 STATIC_OVL void
1823 m_detach(mtmp, mptr)
1824 struct monst *mtmp;
1825 struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
1826 {
1827     if (mtmp == context.polearm.hitmon)
1828         context.polearm.hitmon = 0;
1829     if (mtmp->mleashed)
1830         m_unleash(mtmp, FALSE);
1831     /* to prevent an infinite relobj-flooreffects-hmon-killed loop */
1832     mtmp->mtrapped = 0;
1833     mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
1834     relobj(mtmp, 0, FALSE);
1835     remove_monster(mtmp->mx, mtmp->my);
1836     if (emits_light(mptr))
1837         del_light_source(LS_MONSTER, monst_to_any(mtmp));
1838     if (mtmp->m_ap_type)
1839         seemimic(mtmp);
1840     newsym(mtmp->mx, mtmp->my);
1841     unstuck(mtmp);
1842     fill_pit(mtmp->mx, mtmp->my);
1843
1844     if (mtmp->isshk)
1845         shkgone(mtmp);
1846     if (mtmp->wormno)
1847         wormgone(mtmp);
1848     iflags.purge_monsters++;
1849 }
1850
1851 /* find the worn amulet of life saving which will save a monster */
1852 struct obj *
1853 mlifesaver(mon)
1854 struct monst *mon;
1855 {
1856     if (!nonliving(mon->data) || is_vampshifter(mon)) {
1857         struct obj *otmp = which_armor(mon, W_AMUL);
1858
1859         if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING)
1860             return otmp;
1861     }
1862     return (struct obj *) 0;
1863 }
1864
1865 STATIC_OVL void
1866 lifesaved_monster(mtmp)
1867 struct monst *mtmp;
1868 {
1869     boolean surviver;
1870     struct obj *lifesave = mlifesaver(mtmp);
1871
1872     if (lifesave) {
1873         /* not canseemon; amulets are on the head, so you don't want
1874          * to show this for a long worm with only a tail visible.
1875          * Nor do you check invisibility, because glowing and
1876          * disintegrating amulets are always visible. */
1877         if (cansee(mtmp->mx, mtmp->my)) {
1878 /*JP
1879             pline("But wait...");
1880 */
1881             pline("\82¿\82å\82Á\82Æ\82Ü\82Á\82½\81D\81D\81D");
1882 /*JP
1883             pline("%s medallion begins to glow!", s_suffix(Monnam(mtmp)));
1884 */
1885             pline("%s\82Ì\96\82\8f\9c\82¯\82ª\8bP\82«\82Í\82\82ß\82½\81I", Monnam(mtmp));
1886             makeknown(AMULET_OF_LIFE_SAVING);
1887             /* amulet is visible, but monster might not be */
1888             if (canseemon(mtmp)) {
1889                 if (attacktype(mtmp->data, AT_EXPL)
1890                     || attacktype(mtmp->data, AT_BOOM))
1891 /*JP
1892                     pline("%s reconstitutes!", Monnam(mtmp));
1893 */
1894                     pline("%s\82Í\8dÄ\8d\\90¬\82³\82ê\82½\81I", Monnam(mtmp));
1895                 else
1896 /*JP
1897                     pline("%s looks much better!", Monnam(mtmp));
1898 */
1899                     pline("%s\82Í\82·\82Á\82©\82è\89ñ\95\9c\82µ\82½\82æ\82¤\82¾\81I", Monnam(mtmp));
1900             }
1901 /*JP
1902             pline_The("medallion crumbles to dust!");
1903 */
1904             pline("\96\82\8f\9c\82¯\82Í\82±\82È\82²\82È\82É\82­\82¾\82¯\82½\81I");
1905         }
1906         m_useup(mtmp, lifesave);
1907
1908         surviver = !(mvitals[monsndx(mtmp->data)].mvflags & G_GENOD);
1909         mtmp->mcanmove = 1;
1910         mtmp->mfrozen = 0;
1911         if (mtmp->mtame && !mtmp->isminion) {
1912             wary_dog(mtmp, !surviver);
1913         }
1914         if (mtmp->mhpmax <= 0)
1915             mtmp->mhpmax = 10;
1916         mtmp->mhp = mtmp->mhpmax;
1917         if (surviver)
1918             return;
1919
1920         /* genocided monster can't be life-saved */
1921         if (cansee(mtmp->mx, mtmp->my))
1922 /*JP
1923             pline("Unfortunately, %s is still genocided...", mon_nam(mtmp));
1924 */
1925             pline("\8ec\94O\82È\82ª\82ç%s\82Í\8bs\8eE\82³\82ê\82Ä\82¢\82é\81D\81D\81D", mon_nam(mtmp));
1926         mtmp->mhp = 0;
1927     }
1928 }
1929
1930 void
1931 mondead(mtmp)
1932 register struct monst *mtmp;
1933 {
1934     struct permonst *mptr;
1935     int tmp;
1936
1937     mtmp->mhp = 0; /* in case caller hasn't done this */
1938     lifesaved_monster(mtmp);
1939     if (mtmp->mhp > 0)
1940         return;
1941
1942     if (is_vampshifter(mtmp)) {
1943         int mndx = mtmp->cham;
1944         int x = mtmp->mx, y = mtmp->my;
1945
1946         /* this only happens if shapeshifted */
1947         if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
1948             && !(mvitals[mndx].mvflags & G_GENOD)) {
1949             char buf[BUFSZ];
1950             boolean in_door = (amorphous(mtmp->data)
1951                                && closed_door(mtmp->mx, mtmp->my)),
1952 #if 0 /*JP*/
1953                 /* alternate message phrasing for some monster types */
1954                 spec_mon = (nonliving(mtmp->data)
1955                             || noncorporeal(mtmp->data)
1956                             || amorphous(mtmp->data)),
1957 #endif
1958                 spec_death = (disintegested /* disintegrated or digested */
1959                               || noncorporeal(mtmp->data)
1960                               || amorphous(mtmp->data));
1961
1962             /* construct a format string before transformation;
1963                will be capitalized when used, expects one %s arg */
1964 #if 0 /*JP*/
1965             Sprintf(buf, "%s suddenly %s and rises as %%s!",
1966                     x_monnam(mtmp, ARTICLE_THE,
1967                              spec_mon ? (char *) 0 : "seemingly dead",
1968                              SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1969                                  | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1970                              FALSE),
1971                     spec_death ? "reconstitutes" : "transforms");
1972 #else
1973             Sprintf(buf, "%s%s\82Í\93Ë\91R%s\81C%%s\82Æ\82µ\82Ä\91h\82Á\82½\81I",
1974                     spec_death ? "" : "\8e\80\82ñ\82¾\82æ\82¤\82É\8ev\82í\82ê\82½",
1975                     x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
1976                              SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1977                                  | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1978                              FALSE),
1979                     spec_death ? "\8dÄ\8d\\90¬\82³\82ê" : "\95Ï\89»\82µ");
1980 #endif
1981             mtmp->mcanmove = 1;
1982             mtmp->mfrozen = 0;
1983             if (mtmp->mhpmax <= 0)
1984                 mtmp->mhpmax = 10;
1985             mtmp->mhp = mtmp->mhpmax;
1986             /* this can happen if previously a fog cloud */
1987             if (u.uswallow && (mtmp == u.ustuck))
1988                 expels(mtmp, mtmp->data, FALSE);
1989             if (in_door) {
1990                 coord new_xy;
1991
1992                 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
1993                     rloc_to(mtmp, new_xy.x, new_xy.y);
1994                 }
1995             }
1996             newcham(mtmp, &mons[mndx], FALSE, FALSE);
1997             if (mtmp->data == &mons[mndx])
1998                 mtmp->cham = NON_PM;
1999             else
2000                 mtmp->cham = mndx;
2001             if (canspotmon(mtmp)) {
2002                 /* was using a_monnam(mtmp) but that's weird if mtmp is named:
2003                    "Dracula suddenly transforms and rises as Dracula" */
2004                 pline(upstart(buf), an(mtmp->data->mname));
2005                 vamp_rise_msg = TRUE;
2006             }
2007             newsym(x, y);
2008             return;
2009         }
2010     }
2011
2012     /* dead vault guard is actually kept at coordinate <0,0> until
2013        his temporary corridor to/from the vault has been removed;
2014        need to do this after life-saving and before m_detach() */
2015     if (mtmp->isgd && !grddead(mtmp))
2016         return;
2017
2018     /* Player is thrown from his steed when it dies */
2019     if (mtmp == u.usteed)
2020         dismount_steed(DISMOUNT_GENERIC);
2021
2022     mptr = mtmp->data; /* save this for m_detach() */
2023     /* restore chameleon, lycanthropes to true form at death */
2024     if (mtmp->cham >= LOW_PM) {
2025         set_mon_data(mtmp, &mons[mtmp->cham], -1);
2026         mtmp->cham = NON_PM;
2027     } else if (mtmp->data == &mons[PM_WEREJACKAL])
2028         set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL], -1);
2029     else if (mtmp->data == &mons[PM_WEREWOLF])
2030         set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF], -1);
2031     else if (mtmp->data == &mons[PM_WERERAT])
2032         set_mon_data(mtmp, &mons[PM_HUMAN_WERERAT], -1);
2033
2034     /*
2035      * mvitals[].died does double duty as total number of dead monsters
2036      * and as experience factor for the player killing more monsters.
2037      * this means that a dragon dying by other means reduces the
2038      * experience the player gets for killing a dragon directly; this
2039      * is probably not too bad, since the player likely finagled the
2040      * first dead dragon via ring of conflict or pets, and extinguishing
2041      * based on only player kills probably opens more avenues of abuse
2042      * for rings of conflict and such.
2043      */
2044     tmp = monsndx(mtmp->data);
2045     if (mvitals[tmp].died < 255)
2046         mvitals[tmp].died++;
2047
2048     /* if it's a (possibly polymorphed) quest leader, mark him as dead */
2049     if (mtmp->m_id == quest_status.leader_m_id)
2050         quest_status.leader_is_dead = TRUE;
2051 #ifdef MAIL
2052     /* if the mail daemon dies, no more mail delivery.  -3. */
2053     if (tmp == PM_MAIL_DAEMON)
2054         mvitals[tmp].mvflags |= G_GENOD;
2055 #endif
2056
2057     if (mtmp->data->mlet == S_KOP) {
2058         /* Dead Kops may come back. */
2059         switch (rnd(5)) {
2060         case 1: /* returns near the stairs */
2061             (void) makemon(mtmp->data, xdnstair, ydnstair, NO_MM_FLAGS);
2062             break;
2063         case 2: /* randomly */
2064             (void) makemon(mtmp->data, 0, 0, NO_MM_FLAGS);
2065             break;
2066         default:
2067             break;
2068         }
2069     }
2070     if (mtmp->iswiz)
2071         wizdead();
2072     if (mtmp->data->msound == MS_NEMESIS)
2073         nemdead();
2074     if (mtmp->data == &mons[PM_MEDUSA])
2075         u.uachieve.killed_medusa = 1;
2076     if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
2077         unmap_object(mtmp->mx, mtmp->my);
2078     m_detach(mtmp, mptr);
2079 }
2080
2081 /* TRUE if corpse might be dropped, magr may die if mon was swallowed */
2082 boolean
2083 corpse_chance(mon, magr, was_swallowed)
2084 struct monst *mon;
2085 struct monst *magr;    /* killer, if swallowed */
2086 boolean was_swallowed; /* digestion */
2087 {
2088     struct permonst *mdat = mon->data;
2089     int i, tmp;
2090
2091     if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) {
2092         if (cansee(mon->mx, mon->my) && !was_swallowed)
2093 /*JP
2094             pline("%s body crumbles into dust.", s_suffix(Monnam(mon)));
2095 */
2096             pline("%s\82Ì\91Ì\82Í\95²\81X\82É\82È\82Á\82½\81D", Monnam(mon));
2097         return FALSE;
2098     }
2099
2100     /* Gas spores always explode upon death */
2101     for (i = 0; i < NATTK; i++) {
2102         if (mdat->mattk[i].aatyp == AT_BOOM) {
2103             if (mdat->mattk[i].damn)
2104                 tmp = d((int) mdat->mattk[i].damn, (int) mdat->mattk[i].damd);
2105             else if (mdat->mattk[i].damd)
2106                 tmp = d((int) mdat->mlevel + 1, (int) mdat->mattk[i].damd);
2107             else
2108                 tmp = 0;
2109             if (was_swallowed && magr) {
2110                 if (magr == &youmonst) {
2111 /*JP
2112                     There("is an explosion in your %s!", body_part(STOMACH));
2113 */
2114                     pline("%s\82Ì\92\86\82Å\94\9a\94­\82ª\8bN\82«\82½\81I", body_part(STOMACH));
2115 #if 0 /*JP*/
2116                     Sprintf(killer.name, "%s explosion",
2117                             s_suffix(mdat->mname));
2118 #else
2119                     Sprintf(killer.name, "%s\82Ì\94\9a\94­\82Å", mdat->mname);
2120 #endif
2121                     losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN);
2122                 } else {
2123 /*JP
2124                     You_hear("an explosion.");
2125 */
2126                     You_hear("\94\9a\94­\89¹\82ð\95·\82¢\82½\81D");
2127                     magr->mhp -= tmp;
2128                     if (magr->mhp < 1)
2129                         mondied(magr);
2130                     if (magr->mhp < 1) { /* maybe lifesaved */
2131                         if (canspotmon(magr))
2132 /*JP
2133                             pline("%s rips open!", Monnam(magr));
2134 */
2135                             pline("%s\82Í\83r\83\8a\82Á\82Æ\94j\82ê\82½\81I", Monnam(magr));
2136                     } else if (canseemon(magr))
2137 /*JP
2138                         pline("%s seems to have indigestion.", Monnam(magr));
2139 */
2140                         pline("%s\82Í\8fÁ\89»\95s\97Ç\82Ì\82æ\82¤\82¾\81D", Monnam(magr));
2141                 }
2142
2143                 return FALSE;
2144             }
2145
2146 /*JP
2147             Sprintf(killer.name, "%s explosion", s_suffix(mdat->mname));
2148 */
2149             Sprintf(killer.name, "%s\82Ì\94\9a\94­\82Å", mdat->mname);
2150             killer.format = KILLED_BY_AN;
2151             explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS);
2152             killer.name[0] = '\0';
2153             killer.format = 0;
2154             return FALSE;
2155         }
2156     }
2157
2158     /* must duplicate this below check in xkilled() since it results in
2159      * creating no objects as well as no corpse
2160      */
2161     if (LEVEL_SPECIFIC_NOCORPSE(mdat))
2162         return FALSE;
2163
2164     if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned)
2165         || is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat) || mon->isshk)
2166         return TRUE;
2167     tmp = 2 + ((mdat->geno & G_FREQ) < 2) + verysmall(mdat);
2168     return (boolean) !rn2(tmp);
2169 }
2170
2171 /* drop (perhaps) a cadaver and remove monster */
2172 void
2173 mondied(mdef)
2174 register struct monst *mdef;
2175 {
2176     mondead(mdef);
2177     if (mdef->mhp > 0)
2178         return; /* lifesaved */
2179
2180     if (corpse_chance(mdef, (struct monst *) 0, FALSE)
2181         && (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my)))
2182         (void) make_corpse(mdef, CORPSTAT_NONE);
2183 }
2184
2185 /* monster disappears, not dies */
2186 void
2187 mongone(mdef)
2188 struct monst *mdef;
2189 {
2190     mdef->mhp = 0; /* can skip some inventory bookkeeping */
2191
2192     /* dead vault guard is actually kept at coordinate <0,0> until
2193        his temporary corridor to/from the vault has been removed */
2194     if (mdef->isgd && !grddead(mdef))
2195         return;
2196     /* hero is thrown from his steed when it disappears */
2197     if (mdef == u.usteed)
2198         dismount_steed(DISMOUNT_GENERIC);
2199     /* stuck to you? release */
2200     unstuck(mdef);
2201     /* drop special items like the Amulet so that a dismissed Kop or nurse
2202        can't remove them from the game */
2203     mdrop_special_objs(mdef);
2204     /* release rest of monster's inventory--it is removed from game */
2205     discard_minvent(mdef);
2206     m_detach(mdef, mdef->data);
2207 }
2208
2209 /* drop a statue or rock and remove monster */
2210 void
2211 monstone(mdef)
2212 struct monst *mdef;
2213 {
2214     struct obj *otmp, *obj, *oldminvent;
2215     xchar x = mdef->mx, y = mdef->my;
2216     boolean wasinside = FALSE;
2217
2218     if (!vamp_stone(mdef)) /* vampshifter reverts to vampire */
2219         return;
2220
2221     /* we have to make the statue before calling mondead, to be able to
2222      * put inventory in it, and we have to check for lifesaving before
2223      * making the statue....
2224      */
2225     mdef->mhp = 0; /* in case caller hasn't done this */
2226     lifesaved_monster(mdef);
2227     if (mdef->mhp > 0)
2228         return;
2229
2230     mdef->mtrapped = 0; /* (see m_detach) */
2231
2232     if ((int) mdef->data->msize > MZ_TINY
2233         || !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) {
2234         oldminvent = 0;
2235         /* some objects may end up outside the statue */
2236         while ((obj = mdef->minvent) != 0) {
2237             obj_extract_self(obj);
2238             if (obj->owornmask)
2239                 update_mon_intrinsics(mdef, obj, FALSE, TRUE);
2240             obj_no_longer_held(obj);
2241             if (obj->owornmask & W_WEP)
2242                 setmnotwielded(mdef, obj);
2243             obj->owornmask = 0L;
2244             if (obj->otyp == BOULDER
2245 #if 0 /* monsters don't carry statues */
2246                 ||  (obj->otyp == STATUE
2247                      && mons[obj->corpsenm].msize >= mdef->data->msize)
2248 #endif
2249                 /* invocation tools resist even with 0% resistance */
2250                 || obj_resists(obj, 0, 0)) {
2251 /*JP
2252                 if (flooreffects(obj, x, y, "fall"))
2253 */
2254                 if (flooreffects(obj, x, y, "\97\8e\82¿\82é"))
2255                     continue;
2256                 place_object(obj, x, y);
2257             } else {
2258                 if (obj->lamplit)
2259                     end_burn(obj, TRUE);
2260                 obj->nobj = oldminvent;
2261                 oldminvent = obj;
2262             }
2263         }
2264         /* defer statue creation until after inventory removal
2265            so that saved monster traits won't retain any stale
2266            item-conferred attributes */
2267         otmp = mkcorpstat(STATUE, mdef, mdef->data, x, y, CORPSTAT_NONE);
2268         if (has_mname(mdef))
2269             otmp = oname(otmp, MNAME(mdef));
2270         while ((obj = oldminvent) != 0) {
2271             oldminvent = obj->nobj;
2272             (void) add_to_container(otmp, obj);
2273         }
2274         /* Archeologists should not break unique statues */
2275         if (mdef->data->geno & G_UNIQ)
2276             otmp->spe = 1;
2277         otmp->owt = weight(otmp);
2278     } else
2279         otmp = mksobj_at(ROCK, x, y, TRUE, FALSE);
2280
2281     stackobj(otmp);
2282     /* mondead() already does this, but we must do it before the newsym */
2283     if (glyph_is_invisible(levl[x][y].glyph))
2284         unmap_object(x, y);
2285     if (cansee(x, y))
2286         newsym(x, y);
2287     /* We don't currently trap the hero in the statue in this case but we
2288      * could */
2289     if (u.uswallow && u.ustuck == mdef)
2290         wasinside = TRUE;
2291     mondead(mdef);
2292     if (wasinside) {
2293         if (is_animal(mdef->data))
2294 #if 0 /*JP*/
2295             You("%s through an opening in the new %s.",
2296                 locomotion(youmonst.data, "jump"), xname(otmp));
2297 #else
2298             You("\90V\82µ\82­\82Å\82«\82½%s\82©\82ç%s\81D",
2299                 xname(otmp), jumpedthrough(youmonst.data, "\94ò\82Ñ\8fo\82½"));
2300 #endif
2301     }
2302 }
2303
2304 /* another monster has killed the monster mdef */
2305 void
2306 monkilled(mdef, fltxt, how)
2307 struct monst *mdef;
2308 const char *fltxt;
2309 int how;
2310 {
2311     boolean be_sad = FALSE; /* true if unseen pet is killed */
2312
2313     if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my))
2314         && fltxt)
2315 #if 0 /*JP*/
2316         pline("%s is %s%s%s!", Monnam(mdef),
2317               nonliving(mdef->data) ? "destroyed" : "killed",
2318               *fltxt ? " by the " : "", fltxt);
2319 #else
2320         {
2321             if(*fltxt)
2322                 pline("%s\82Í%s\82É\82æ\82Á\82Ä%s\81I", Monnam(mdef), fltxt,
2323                       nonliving(mdef->data) ? "\93|\82³\82ê\82½" : "\8eE\82³\82ê\82½");
2324             else
2325                 pline("%s\82Í%s\81I", Monnam(mdef), 
2326                       nonliving(mdef->data) ? "\93|\82³\82ê\82½" : "\8eE\82³\82ê\82½");
2327         }
2328 #endif
2329     else
2330         be_sad = (mdef->mtame != 0);
2331
2332     /* no corpses if digested or disintegrated */
2333     disintegested = (how == AD_DGST || how == -AD_RBRE);
2334     if (disintegested)
2335         mondead(mdef);
2336     else
2337         mondied(mdef);
2338
2339     if (be_sad && mdef->mhp <= 0)
2340 /*JP
2341         You("have a sad feeling for a moment, then it passes.");
2342 */
2343         You("\94ß\82µ\82¢\8bC\8e\9d\82É\82¨\82»\82í\82ê\82½\82ª\81C\82·\82®\82É\89ß\82¬\82³\82Á\82½\81D");
2344 }
2345
2346 void
2347 unstuck(mtmp)
2348 struct monst *mtmp;
2349 {
2350     if (u.ustuck == mtmp) {
2351         if (u.uswallow) {
2352             u.ux = mtmp->mx;
2353             u.uy = mtmp->my;
2354             u.uswallow = 0;
2355             u.uswldtim = 0;
2356             if (Punished && uchain->where != OBJ_FLOOR)
2357                 placebc();
2358             vision_full_recalc = 1;
2359             docrt();
2360             /* prevent swallower (mtmp might have just poly'd into something
2361                without an engulf attack) from immediately re-engulfing */
2362             if (attacktype(mtmp->data, AT_ENGL) && !mtmp->mspec_used)
2363                 mtmp->mspec_used = rnd(2);
2364         }
2365         u.ustuck = 0;
2366     }
2367 }
2368
2369 void
2370 killed(mtmp)
2371 struct monst *mtmp;
2372 {
2373     xkilled(mtmp, XKILL_GIVEMSG);
2374 }
2375
2376 /* the player has killed the monster mtmp */
2377 void
2378 xkilled(mtmp, xkill_flags)
2379 struct monst *mtmp;
2380 int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */
2381 {
2382     int tmp, mndx, x = mtmp->mx, y = mtmp->my;
2383     struct permonst *mdat;
2384     struct obj *otmp;
2385     struct trap *t;
2386     boolean wasinside = u.uswallow && (u.ustuck == mtmp),
2387             burycorpse = FALSE,
2388             nomsg = (xkill_flags & XKILL_NOMSG) != 0,
2389             nocorpse = (xkill_flags & XKILL_NOCORPSE) != 0,
2390             noconduct = (xkill_flags & XKILL_NOCONDUCT) != 0;
2391
2392     mtmp->mhp = 0; /* caller will usually have already done this */
2393     if (!noconduct) /* KMH, conduct */
2394         u.uconduct.killer++;
2395
2396     if (!nomsg) {
2397 #if 0 /*JP*/
2398         boolean namedpet = has_mname(mtmp) && !Hallucination;
2399
2400         You("%s %s!",
2401             nonliving(mtmp->data) ? "destroy" : "kill",
2402             !(wasinside || canspotmon(mtmp)) ? "it"
2403               : !mtmp->mtame ? mon_nam(mtmp)
2404                 : x_monnam(mtmp, namedpet ? ARTICLE_NONE : ARTICLE_THE,
2405                            "poor", namedpet ? SUPPRESS_SADDLE : 0, FALSE));
2406 #else
2407         You("%s%s\82ð\93|\82µ\82½\81I",
2408             !(wasinside || canspotmon(mtmp)) ? "\82»\82ê"
2409               : mtmp->mtame ? "\82©\82í\82¢\82»\82¤\82È" : "",
2410                 mon_nam(mtmp));
2411 #endif
2412     }
2413
2414     if (mtmp->mtrapped && (t = t_at(x, y)) != 0
2415         && (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
2416         if (sobj_at(BOULDER, x, y))
2417             nocorpse = TRUE; /* Prevent corpses/treasure being created
2418                                 "on top" of boulder that is about to fall in.
2419                                 This is out of order, but cannot be helped
2420                                 unless this whole routine is rearranged. */
2421         if (m_carrying(mtmp, BOULDER))
2422             burycorpse = TRUE;
2423     }
2424
2425     /* your pet knows who just killed it...watch out */
2426     if (mtmp->mtame && !mtmp->isminion)
2427         EDOG(mtmp)->killed_by_u = 1;
2428
2429     if (wasinside && thrownobj && thrownobj != uball) {
2430         /* thrown object has killed hero's engulfer; add it to mon's
2431            inventory now so that it will be placed with mon's other
2432            stuff prior to lookhere/autopickup when hero is expelled
2433            below (as a side-effect, this missile has immunity from
2434            being consumed [for this shot/throw only]) */
2435         mpickobj(mtmp, thrownobj);
2436         /* let throwing code know that missile has been disposed of */
2437         thrownobj = 0;
2438     }
2439
2440     vamp_rise_msg = FALSE; /* might get set in mondead(); only checked below */
2441     disintegested = nocorpse; /* alternate vamp_rise message needed if true */
2442     /* dispose of monster and make cadaver */
2443     if (stoned)
2444         monstone(mtmp);
2445     else
2446         mondead(mtmp);
2447     disintegested = FALSE; /* reset */
2448
2449     if (mtmp->mhp > 0) { /* monster lifesaved */
2450         /* Cannot put the non-visible lifesaving message in
2451          * lifesaved_monster() since the message appears only when _you_
2452          * kill it (as opposed to visible lifesaving which always appears).
2453          */
2454         stoned = FALSE;
2455         if (!cansee(x, y) && !vamp_rise_msg)
2456 /*JP
2457             pline("Maybe not...");
2458 */
2459             pline("\82¢\82â\81C\88á\82¤\82©\82à\81D\81D\81D");
2460         return;
2461     }
2462
2463     mdat = mtmp->data; /* note: mondead can change mtmp->data */
2464     mndx = monsndx(mdat);
2465
2466     if (stoned) {
2467         stoned = FALSE;
2468         goto cleanup;
2469     }
2470
2471     if (nocorpse || LEVEL_SPECIFIC_NOCORPSE(mdat))
2472         goto cleanup;
2473
2474 #ifdef MAIL
2475     if (mdat == &mons[PM_MAIL_DAEMON]) {
2476         stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE));
2477     }
2478 #endif
2479     if (accessible(x, y) || is_pool(x, y)) {
2480         struct obj *cadaver;
2481         int otyp;
2482
2483         /* illogical but traditional "treasure drop" */
2484         if (!rn2(6) && !(mvitals[mndx].mvflags & G_NOCORPSE)
2485             /* no extra item from swallower or steed */
2486             && (x != u.ux || y != u.uy)
2487             /* no extra item from kops--too easy to abuse */
2488             && mdat->mlet != S_KOP
2489             /* no items from cloned monsters */
2490             && !mtmp->mcloned) {
2491             otmp = mkobj(RANDOM_CLASS, TRUE);
2492             /* don't create large objects from small monsters */
2493             otyp = otmp->otyp;
2494             if (mdat->msize < MZ_HUMAN && otyp != FIGURINE
2495                 /* oc_big is also oc_bimanual and oc_bulky */
2496                 && (otmp->owt > 30 || objects[otyp].oc_big)) {
2497                 delobj(otmp);
2498 #if 0 /*JP*/
2499             } else if (!flooreffects(otmp, x, y, nomsg ? "" : "fall")) {
2500 #else
2501             } else if (!flooreffects(otmp, x, y, nomsg ? "" : "\97\8e\82¿\82é")) {
2502 #endif
2503                 place_object(otmp, x, y);
2504                 stackobj(otmp);
2505             }
2506         }
2507         /* corpse--none if hero was inside the monster */
2508         if (!wasinside && corpse_chance(mtmp, (struct monst *) 0, FALSE)) {
2509             cadaver = make_corpse(mtmp, burycorpse ? CORPSTAT_BURIED
2510                                                    : CORPSTAT_NONE);
2511             if (burycorpse && cadaver && cansee(x, y) && !mtmp->minvis
2512                 && cadaver->where == OBJ_BURIED && !nomsg) {
2513 /*JP
2514                 pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp)));
2515 */
2516                 pline("%s\82Ì\8e\80\91Ì\82Í\96\84\82Ü\82Á\82Ä\82µ\82Ü\82Á\82½\81D", Monnam(mtmp));
2517             }
2518         }
2519     }
2520     if (wasinside)
2521         spoteffects(TRUE); /* poor man's expels() */
2522     /* monster is gone, corpse or other object might now be visible */
2523     newsym(x, y);
2524
2525 cleanup:
2526     /* punish bad behaviour */
2527     if (is_human(mdat)
2528         && (!always_hostile(mdat) && mtmp->malign <= 0)
2529         && (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD)
2530         && u.ualign.type != A_CHAOTIC) {
2531         HTelepat &= ~INTRINSIC;
2532         change_luck(-2);
2533 /*JP
2534         You("murderer!");
2535 */
2536         You("\8eE\90l\8bS\82¾\81I");
2537         if (Blind && !Blind_telepat)
2538             see_monsters(); /* Can't sense monsters any more. */
2539     }
2540     if ((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame)
2541         change_luck(-1);
2542     if (is_unicorn(mdat) && sgn(u.ualign.type) == sgn(mdat->maligntyp)) {
2543         change_luck(-5);
2544 /*JP
2545         You_feel("guilty...");
2546 */
2547         You("\8dß\82ð\8a´\82\82½\81D\81D\81D");
2548     }
2549
2550     /* give experience points */
2551     tmp = experience(mtmp, (int) mvitals[mndx].died);
2552     more_experienced(tmp, 0);
2553     newexplevel(); /* will decide if you go up */
2554
2555     /* adjust alignment points */
2556     if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */
2557         adjalign(-(u.ualign.record + (int) ALIGNLIM / 2));
2558 #if 0 /*JP*/
2559         pline("That was %sa bad idea...",
2560               u.uevent.qcompleted ? "probably " : "");
2561 #else
2562         pline("%s\82æ\82­\82È\82¢\8ds\88×\82¾\82Á\82½\81D\81D\81D",
2563               u.uevent.qcompleted ? "\82½\82Ô\82ñ" : "");
2564 #endif
2565     } else if (mdat->msound == MS_NEMESIS) { /* Real good! */
2566         adjalign((int) (ALIGNLIM / 4));
2567     } else if (mdat->msound == MS_GUARDIAN) { /* Bad */
2568         adjalign(-(int) (ALIGNLIM / 8));
2569         if (!Hallucination)
2570 /*JP
2571             pline("That was probably a bad idea...");
2572 */
2573             pline("\82æ\82­\82È\82¢\8ds\88×\82¾\82Á\82½\81D\81D\81D");
2574         else
2575 /*JP
2576             pline("Whoopsie-daisy!");
2577 */
2578             pline("\83V\83\93\83W\83}\83b\83^\81[\81I");
2579     } else if (mtmp->ispriest) {
2580         adjalign((p_coaligned(mtmp)) ? -2 : 2);
2581         /* cancel divine protection for killing your priest */
2582         if (p_coaligned(mtmp))
2583             u.ublessed = 0;
2584         if (mdat->maligntyp == A_NONE)
2585             adjalign((int) (ALIGNLIM / 4)); /* BIG bonus */
2586     } else if (mtmp->mtame) {
2587         adjalign(-15); /* bad!! */
2588         /* your god is mighty displeased... */
2589         if (!Hallucination)
2590 /*JP
2591             You_hear("the rumble of distant thunder...");
2592 */
2593             You_hear("\89\93\82­\82Å\97\8b\96Â\82ð\95·\82¢\82½\81D\81D\81D");
2594         else
2595 /*JP
2596             You_hear("the studio audience applaud!");
2597 */
2598             pline("\92®\8fO\82Ì\8a\85\8dÑ\82ð\97\81\82Ñ\82½\81I");
2599     } else if (mtmp->mpeaceful)
2600         adjalign(-5);
2601
2602     /* malign was already adjusted for u.ualign.type and randomization */
2603     adjalign(mtmp->malign);
2604 }
2605
2606 /* changes the monster into a stone monster of the same type
2607    this should only be called when poly_when_stoned() is true */
2608 void
2609 mon_to_stone(mtmp)
2610 struct monst *mtmp;
2611 {
2612     if (mtmp->data->mlet == S_GOLEM) {
2613         /* it's a golem, and not a stone golem */
2614         if (canseemon(mtmp))
2615 /*JP
2616             pline("%s solidifies...", Monnam(mtmp));
2617 */
2618             pline("%s\82Í\8bÃ\8cÅ\82µ\82½\81D\81D\81D", Monnam(mtmp));
2619         if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) {
2620             if (canseemon(mtmp))
2621 /*JP
2622                 pline("Now it's %s.", an(mtmp->data->mname));
2623 */
2624                 pline("\82È\82ñ\82Æ%s\82É\82È\82Á\82Ä\82µ\82Ü\82Á\82½\81D", mtmp->data->mname);
2625         } else {
2626             if (canseemon(mtmp))
2627 /*JP
2628                 pline("... and returns to normal.");
2629 */
2630                 pline("\81D\81D\81D\82»\82µ\82Ä\95\81\92Ê\82É\96ß\82Á\82½\81D");
2631         }
2632     } else
2633         impossible("Can't polystone %s!", a_monnam(mtmp));
2634 }
2635
2636 boolean
2637 vamp_stone(mtmp)
2638 struct monst *mtmp;
2639 {
2640     if (is_vampshifter(mtmp)) {
2641         int mndx = mtmp->cham;
2642         int x = mtmp->mx, y = mtmp->my;
2643
2644         /* this only happens if shapeshifted */
2645         if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
2646             && !(mvitals[mndx].mvflags & G_GENOD)) {
2647             char buf[BUFSZ];
2648             boolean in_door = (amorphous(mtmp->data)
2649                                && closed_door(mtmp->mx, mtmp->my));
2650
2651             /* construct a format string before transformation */
2652 #if 0 /*JP*/
2653             Sprintf(buf, "The lapidifying %s %s %s",
2654                     x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2655                              (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2656                               | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2657                     amorphous(mtmp->data) ? "coalesces on the"
2658                        : is_flyer(mtmp->data) ? "drops to the"
2659                           : "writhes on the",
2660                     surface(x,y));
2661 #else
2662             Sprintf(buf, "\90Î\89»\82µ\82Â\82Â\82 \82é%s\82ª%s%s",
2663                     x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2664                              (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2665                               | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2666                     surface(x,y),
2667                     amorphous(mtmp->data) ? "\82Ì\8fã\82Å\97Z\8d\87\82µ\82½"
2668                        : is_flyer(mtmp->data) ? "\82É\97\8e\82¿\82½"
2669                           : "\82Ì\8fã\82Å\90g\82à\82¾\82¦\82½");
2670 #endif
2671             mtmp->mcanmove = 1;
2672             mtmp->mfrozen = 0;
2673             if (mtmp->mhpmax <= 0)
2674                 mtmp->mhpmax = 10;
2675             mtmp->mhp = mtmp->mhpmax;
2676             /* this can happen if previously a fog cloud */
2677             if (u.uswallow && (mtmp == u.ustuck))
2678                 expels(mtmp, mtmp->data, FALSE);
2679             if (in_door) {
2680                 coord new_xy;
2681
2682                 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
2683                     rloc_to(mtmp, new_xy.x, new_xy.y);
2684                 }
2685             }
2686             if (canspotmon(mtmp)) {
2687 /*JP
2688                 pline("%s!", buf);
2689 */
2690                 pline("%s\81I", buf);
2691                 display_nhwindow(WIN_MESSAGE, FALSE);
2692             }
2693             newcham(mtmp, &mons[mndx], FALSE, FALSE);
2694             if (mtmp->data == &mons[mndx])
2695                 mtmp->cham = NON_PM;
2696             else
2697                 mtmp->cham = mndx;
2698             if (canspotmon(mtmp)) {
2699 #if 0 /*JP*/
2700                 pline("%s rises from the %s with renewed agility!",
2701                       Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2702 #else
2703                 pline("%s\82Í\8b@\95q\82³\82ð\8eæ\82è\96ß\82µ\82Ä%s\82©\82ç\95\9c\8a\88\82µ\82½\81I",
2704                       Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2705 #endif
2706             }
2707             newsym(mtmp->mx, mtmp->my);
2708             return FALSE;   /* didn't petrify */
2709         }
2710     }
2711     return TRUE;
2712 }
2713
2714 /* drop monster into "limbo" - that is, migrate to the current level */
2715 void
2716 m_into_limbo(mtmp)
2717 struct monst *mtmp;
2718 {
2719     unstuck(mtmp);
2720     mdrop_special_objs(mtmp);
2721     migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_APPROX_XY, NULL);
2722 }
2723
2724 /* make monster mtmp next to you (if possible);
2725    might place monst on far side of a wall or boulder */
2726 void
2727 mnexto(mtmp)
2728 struct monst *mtmp;
2729 {
2730     coord mm;
2731     boolean couldspot = canspotmon(mtmp);
2732
2733     if (mtmp == u.usteed) {
2734         /* Keep your steed in sync with you instead */
2735         mtmp->mx = u.ux;
2736         mtmp->my = u.uy;
2737         return;
2738     }
2739
2740     if (!enexto(&mm, u.ux, u.uy, mtmp->data)) {
2741         m_into_limbo(mtmp);
2742         return;
2743     }
2744     if (!isok(mm.x, mm.y))
2745         return;
2746     rloc_to(mtmp, mm.x, mm.y);
2747     if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) {
2748         mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */
2749         if (!couldspot && canspotmon(mtmp))
2750 #if 0 /*JP*/
2751             pline("%s suddenly %s!", Amonnam(mtmp),
2752                   !Blind ? "appears" : "arrives");
2753 #else
2754             pline("\93Ë\91R%s\82ª\8c»\82ê\82½\81I", Amonnam(mtmp));
2755 #endif
2756     }
2757     return;
2758 }
2759
2760 /* like mnexto() but requires destination to be directly accessible */
2761 void
2762 maybe_mnexto(mtmp)
2763 struct monst *mtmp;
2764 {
2765     coord mm;
2766     struct permonst *ptr = mtmp->data;
2767     boolean diagok = !NODIAG(ptr - mons);
2768     int tryct = 20;
2769
2770     do {
2771         if (!enexto(&mm, u.ux, u.uy, ptr))
2772             return;
2773         if (couldsee(mm.x, mm.y)
2774             /* don't move grid bugs diagonally */
2775             && (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) {
2776             rloc_to(mtmp, mm.x, mm.y);
2777             return;
2778         }
2779     } while (--tryct > 0);
2780 }
2781
2782 /* mnearto()
2783  * Put monster near (or at) location if possible.
2784  * Returns:
2785  *  true if relocation was successful
2786  *  false otherwise
2787  */
2788 boolean
2789 mnearto(mtmp, x, y, move_other)
2790 register struct monst *mtmp;
2791 xchar x, y;
2792 boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */
2793 {
2794     struct monst *othermon = (struct monst *) 0;
2795     xchar newx, newy;
2796     coord mm;
2797
2798     if (mtmp->mx == x && mtmp->my == y)
2799         return TRUE;
2800
2801     if (move_other && (othermon = m_at(x, y)) != 0) {
2802         if (othermon->wormno)
2803             remove_worm(othermon);
2804         else
2805             remove_monster(x, y);
2806     }
2807
2808     newx = x;
2809     newy = y;
2810     if (!goodpos(newx, newy, mtmp, 0)) {
2811         /* Actually we have real problems if enexto ever fails.
2812          * Migrating_mons that need to be placed will cause
2813          * no end of trouble.
2814          */
2815         if (!enexto(&mm, newx, newy, mtmp->data))
2816             return FALSE;
2817         if (!isok(mm.x,mm.y))
2818             return FALSE;
2819         newx = mm.x;
2820         newy = mm.y;
2821     }
2822     rloc_to(mtmp, newx, newy);
2823
2824     if (move_other && othermon) {
2825         xchar oldx = othermon->mx, oldy = othermon->my;
2826
2827         othermon->mx = othermon->my = 0;
2828         (void) mnearto(othermon, x, y, FALSE);
2829         if (othermon->mx == 0 && othermon->my == 0) {
2830             /* reloc failed */
2831             othermon->mx = oldx;
2832             othermon->my = oldy;
2833             m_into_limbo(othermon);
2834         }
2835     }
2836
2837     return TRUE;
2838 }
2839
2840 /* monster responds to player action; not the same as a passive attack;
2841    assumes reason for response has been tested, and response _must_ be made */
2842 void
2843 m_respond(mtmp)
2844 struct monst *mtmp;
2845 {
2846     if (mtmp->data->msound == MS_SHRIEK) {
2847         if (!Deaf) {
2848 /*JP
2849             pline("%s shrieks.", Monnam(mtmp));
2850 */
2851             pline("%s\82Í\8bà\90Ø\82è\90º\82ð\82 \82°\82½\81D", Monnam(mtmp));
2852             stop_occupation();
2853         }
2854         if (!rn2(10)) {
2855             if (!rn2(13))
2856                 (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
2857             else
2858                 (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS);
2859         }
2860         aggravate();
2861     }
2862     if (mtmp->data == &mons[PM_MEDUSA]) {
2863         register int i;
2864
2865         for (i = 0; i < NATTK; i++)
2866             if (mtmp->data->mattk[i].aatyp == AT_GAZE) {
2867                 (void) gazemu(mtmp, &mtmp->data->mattk[i]);
2868                 break;
2869             }
2870     }
2871 }
2872
2873 /* Called whenever the player attacks mtmp; also called in other situations
2874    where mtmp gets annoyed at the player. Handles mtmp getting annoyed at the
2875    attack and any ramifications that might have. Useful also in situations
2876    where mtmp was already hostile; it checks for situations where the player
2877    shouldn't be attacking and any ramifications /that/ might have. */
2878 void
2879 setmangry(mtmp, via_attack)
2880 struct monst *mtmp;
2881 boolean via_attack;
2882 {
2883     if (via_attack && sengr_at("Elbereth", u.ux, u.uy, TRUE)) {
2884 /*JP
2885         You_feel("like a hypocrite.");
2886 */
2887         You_feel("\8bU\91P\8eÒ\82Ì\82æ\82¤\82È\8bC\82ª\82µ\82½\81D");
2888         /* AIS: Yes, I know alignment penalties and bonuses aren't balanced
2889            at the moment. This is about correct relative to other "small"
2890            penalties; it should be fairly large, as attacking while standing
2891            on an Elbereth means that you're requesting peace and then
2892            violating your own request. I know 5 isn't actually large, but
2893            it's intentionally larger than the 1s and 2s that are normally
2894            given for this sort of thing. */
2895         adjalign(-5);
2896
2897         if (!Blind)
2898 /*JP
2899             pline("The engraving beneath you fades.");
2900 */
2901             pline("\82 \82È\82½\82Ì\91«\8c³\82Ì\95\8e\9a\82ª\94\96\82ê\82½\81D");
2902         del_engr_at(u.ux, u.uy);
2903     }
2904
2905     /* AIS: Should this be in both places, or just in wakeup()? */
2906     mtmp->mstrategy &= ~STRAT_WAITMASK;
2907     if (!mtmp->mpeaceful)
2908         return;
2909     if (mtmp->mtame)
2910         return;
2911     mtmp->mpeaceful = 0;
2912     if (mtmp->ispriest) {
2913         if (p_coaligned(mtmp))
2914             adjalign(-5); /* very bad */
2915         else
2916             adjalign(2);
2917     } else
2918         adjalign(-1); /* attacking peaceful monsters is bad */
2919     if (couldsee(mtmp->mx, mtmp->my)) {
2920         if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
2921 /*JP
2922             pline("%s gets angry!", Monnam(mtmp));
2923 */
2924             pline("%s\82Í\93{\82Á\82½\81I", Monnam(mtmp));
2925         else if (flags.verbose && !Deaf)
2926             growl(mtmp);
2927     }
2928
2929     /* attacking your own quest leader will anger his or her guardians */
2930     if (!context.mon_moving /* should always be the case here */
2931         && mtmp->data == &mons[quest_info(MS_LEADER)]) {
2932         struct monst *mon;
2933         struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
2934         int got_mad = 0;
2935
2936         /* guardians will sense this attack even if they can't see it */
2937         for (mon = fmon; mon; mon = mon->nmon) {
2938             if (DEADMONSTER(mon))
2939                 continue;
2940             if (mon->data == q_guardian && mon->mpeaceful) {
2941                 mon->mpeaceful = 0;
2942                 if (canseemon(mon))
2943                     ++got_mad;
2944             }
2945         }
2946         if (got_mad && !Hallucination) {
2947             const char *who = q_guardian->mname;
2948
2949 #if 0 /*JP*/
2950             if (got_mad > 1)
2951                 who = makeplural(who);
2952             pline_The("%s %s to be angry too...",
2953                       who, vtense(who, "appear"));
2954 #else
2955             pline("%s\82à\93{\82Á\82½\82æ\82¤\82¾\81D\81D\81D", who);
2956 #endif
2957         }
2958     }
2959
2960     /* make other peaceful monsters react */
2961     if (!context.mon_moving) {
2962         static const char *const Exclam[] = {
2963 /*JP
2964             "Gasp!", "Uh-oh.", "Oh my!", "What?", "Why?",
2965 */
2966             "\82®\82Í\82Á\81I", "\82¤\82í\81D", "Oh my!", "\82È\82É\82Á\81H", "\82È\82ñ\82¾\81H",
2967         };
2968         struct monst *mon;
2969         int mndx = monsndx(mtmp->data);
2970
2971         for (mon = fmon; mon; mon = mon->nmon) {
2972             if (DEADMONSTER(mon))
2973                 continue;
2974             if (mon == mtmp) /* the mpeaceful test catches this since mtmp */
2975                 continue;    /* is no longer peaceful, but be explicit...  */
2976
2977             if (!mindless(mon->data) && mon->mpeaceful
2978                 && couldsee(mon->mx, mon->my) && !mon->msleeping
2979                 && mon->mcansee && m_canseeu(mon)) {
2980                 boolean exclaimed = FALSE;
2981
2982                 if (humanoid(mon->data) || mon->isshk || mon->ispriest) {
2983                     if (is_watch(mon->data)) {
2984 /*JP
2985                         verbalize("Halt!  You're under arrest!");
2986 */
2987                         verbalize("\8e~\82Ü\82ê\81I\91ß\95ß\82·\82é\81I");
2988                         (void) angry_guards(!!Deaf);
2989                     } else {
2990                         if (!rn2(5)) {
2991                             verbalize("%s", Exclam[mon->m_id % SIZE(Exclam)]);
2992                             exclaimed = TRUE;
2993                         }
2994                         /* shopkeepers and temple priests might gasp in
2995                            surprise, but they won't become angry here */
2996                         if (mon->isshk || mon->ispriest)
2997                             continue;
2998
2999                         if (mon->data->mlevel < rn2(10)) {
3000                             monflee(mon, rn2(50) + 25, TRUE, !exclaimed);
3001                             exclaimed = TRUE;
3002                         }
3003                         if (mon->mtame) {
3004                             /* mustn't set mpeaceful to 0 as below;
3005                                perhaps reduce tameness? */
3006                         } else {
3007                             mon->mpeaceful = 0;
3008                             adjalign(-1);
3009                             if (!exclaimed)
3010 /*JP
3011                                 pline("%s gets angry!", Monnam(mon));
3012 */
3013                                 pline("%s\82Í\93{\82Á\82½\81I", Monnam(mon));
3014                         }
3015                     }
3016                 } else if (mon->data->mlet == mtmp->data->mlet
3017                            && big_little_match(mndx, monsndx(mon->data))
3018                            && !rn2(3)) {
3019                     if (!rn2(4)) {
3020                         growl(mon);
3021                         exclaimed = TRUE;
3022                     }
3023                     if (rn2(6))
3024                         monflee(mon, rn2(25) + 15, TRUE, !exclaimed);
3025                 }
3026             }
3027         }
3028     }
3029 }
3030
3031 /* wake up a monster, possibly making it angry in the process */
3032 void
3033 wakeup(mtmp, via_attack)
3034 register struct monst *mtmp;
3035 boolean via_attack;
3036 {
3037     mtmp->msleeping = 0;
3038     if (mtmp->m_ap_type) {
3039         seemimic(mtmp);
3040     } else if (context.forcefight && !context.mon_moving
3041                && mtmp->mundetected) {
3042         mtmp->mundetected = 0;
3043         newsym(mtmp->mx, mtmp->my);
3044     }
3045     finish_meating(mtmp);
3046     if (via_attack)
3047         setmangry(mtmp, TRUE);
3048 }
3049
3050 /* Wake up nearby monsters without angering them. */
3051 void
3052 wake_nearby()
3053 {
3054     register struct monst *mtmp;
3055
3056     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3057         if (DEADMONSTER(mtmp))
3058             continue;
3059         if (distu(mtmp->mx, mtmp->my) < u.ulevel * 20) {
3060             mtmp->msleeping = 0;
3061             if (!unique_corpstat(mtmp->data))
3062                 mtmp->mstrategy &= ~STRAT_WAITMASK;
3063             if (mtmp->mtame) {
3064                 if (!mtmp->isminion)
3065                     EDOG(mtmp)->whistletime = moves;
3066                 /* Clear mtrack. This is to fix up a pet who is
3067                    stuck "fleeing" its master. */
3068                 memset(mtmp->mtrack, 0, sizeof(mtmp->mtrack));
3069             }
3070         }
3071     }
3072 }
3073
3074 /* Wake up monsters near some particular location. */
3075 void
3076 wake_nearto(x, y, distance)
3077 register int x, y, distance;
3078 {
3079     register struct monst *mtmp;
3080
3081     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3082         if (DEADMONSTER(mtmp))
3083             continue;
3084         if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
3085             mtmp->msleeping = 0;
3086             if (!unique_corpstat(mtmp->data))
3087                 mtmp->mstrategy &= ~STRAT_WAITMASK;
3088         }
3089     }
3090 }
3091
3092 /* NOTE: we must check for mimicry before calling this routine */
3093 void
3094 seemimic(mtmp)
3095 register struct monst *mtmp;
3096 {
3097     boolean is_blocker_appear = (is_lightblocker_mappear(mtmp));
3098
3099     if (has_mcorpsenm(mtmp))
3100         freemcorpsenm(mtmp);
3101
3102     mtmp->m_ap_type = M_AP_NOTHING;
3103     mtmp->mappearance = 0;
3104
3105     /*
3106      *  Discovered mimics don't block light.
3107      */
3108     if (is_blocker_appear
3109         && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
3110         unblock_point(mtmp->mx, mtmp->my);
3111
3112     newsym(mtmp->mx, mtmp->my);
3113 }
3114
3115 /* force all chameleons to become normal */
3116 void
3117 rescham()
3118 {
3119     register struct monst *mtmp;
3120     int mcham;
3121
3122     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3123         if (DEADMONSTER(mtmp))
3124             continue;
3125         mcham = (int) mtmp->cham;
3126         if (mcham >= LOW_PM) {
3127             (void) newcham(mtmp, &mons[mcham], FALSE, FALSE);
3128             mtmp->cham = NON_PM;
3129         }
3130         if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
3131             new_were(mtmp);
3132         if (mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) {
3133             seemimic(mtmp);
3134             /* we pretend that the mimic doesn't
3135                know that it has been unmasked */
3136             mtmp->msleeping = 1;
3137         }
3138     }
3139 }
3140
3141 /* Let the chameleons change again -dgk */
3142 void
3143 restartcham()
3144 {
3145     register struct monst *mtmp;
3146
3147     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3148         if (DEADMONSTER(mtmp))
3149             continue;
3150         mtmp->cham = pm_to_cham(monsndx(mtmp->data));
3151         if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping
3152             && cansee(mtmp->mx, mtmp->my)) {
3153             set_mimic_sym(mtmp);
3154             newsym(mtmp->mx, mtmp->my);
3155         }
3156     }
3157 }
3158
3159 /* called when restoring a monster from a saved level; protection
3160    against shape-changing might be different now than it was at the
3161    time the level was saved. */
3162 void
3163 restore_cham(mon)
3164 struct monst *mon;
3165 {
3166     int mcham;
3167
3168     if (Protection_from_shape_changers) {
3169         mcham = (int) mon->cham;
3170         if (mcham >= LOW_PM) {
3171             mon->cham = NON_PM;
3172             (void) newcham(mon, &mons[mcham], FALSE, FALSE);
3173         } else if (is_were(mon->data) && !is_human(mon->data)) {
3174             new_were(mon);
3175         }
3176     } else if (mon->cham == NON_PM) {
3177         mon->cham = pm_to_cham(monsndx(mon->data));
3178     }
3179 }
3180
3181 /* unwatched hiders may hide again; if so, returns True */
3182 STATIC_OVL boolean
3183 restrap(mtmp)
3184 register struct monst *mtmp;
3185 {
3186     struct trap *t;
3187
3188     if (mtmp->mcan || mtmp->m_ap_type || cansee(mtmp->mx, mtmp->my)
3189         || rn2(3) || mtmp == u.ustuck
3190         /* can't hide while trapped except in pits */
3191         || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
3192             && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))
3193         || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
3194         return FALSE;
3195
3196     if (mtmp->data->mlet == S_MIMIC) {
3197         set_mimic_sym(mtmp);
3198         return TRUE;
3199     } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) {
3200         mtmp->mundetected = 1;
3201         return TRUE;
3202     }
3203
3204     return FALSE;
3205 }
3206
3207 /* monster/hero tries to hide under something at the current location */
3208 boolean
3209 hideunder(mtmp)
3210 struct monst *mtmp;
3211 {
3212     struct trap *t;
3213     boolean undetected = FALSE, is_u = (mtmp == &youmonst);
3214     xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
3215
3216     if (mtmp == u.ustuck) {
3217         ; /* can't hide if holding you or held by you */
3218     } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
3219                     : (mtmp->mtrapped && (t = t_at(x, y)) != 0
3220                        && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) {
3221         ; /* can't hide while stuck in a non-pit trap */
3222     } else if (mtmp->data->mlet == S_EEL) {
3223         undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
3224     } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
3225         struct obj *otmp = level.objects[x][y];
3226
3227         /* most monsters won't hide under cockatrice corpse */
3228         if (otmp->nexthere || otmp->otyp != CORPSE
3229             || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp))
3230             || !touch_petrifies(&mons[otmp->corpsenm]))
3231             undetected = TRUE;
3232     }
3233
3234     if (is_u)
3235         u.uundetected = undetected;
3236     else
3237         mtmp->mundetected = undetected;
3238     return undetected;
3239 }
3240
3241 /* called when returning to a previously visited level */
3242 void
3243 hide_monst(mon)
3244 struct monst *mon;
3245 {
3246     boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL;
3247
3248     if ((is_hider(mon->data) || hider_under)
3249         && !(mon->mundetected || mon->m_ap_type)) {
3250         xchar x = mon->mx, y = mon->my;
3251         char save_viz = viz_array[y][x];
3252
3253         /* override vision, forcing hero to be unable to see monster's spot */
3254         viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE);
3255         if (is_hider(mon->data))
3256             (void) restrap(mon);
3257         /* try again if mimic missed its 1/3 chance to hide */
3258         if (mon->data->mlet == S_MIMIC && !mon->m_ap_type)
3259             (void) restrap(mon);
3260         if (hider_under)
3261             (void) hideunder(mon);
3262         viz_array[y][x] = save_viz;
3263     }
3264 }
3265
3266 static short *animal_list = 0; /* list of PM values for animal monsters */
3267 static int animal_list_count;
3268
3269 void
3270 mon_animal_list(construct)
3271 boolean construct;
3272 {
3273     if (construct) {
3274         short animal_temp[SPECIAL_PM];
3275         int i, n;
3276
3277         /* if (animal_list) impossible("animal_list already exists"); */
3278
3279         for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
3280             if (is_animal(&mons[i]))
3281                 animal_temp[n++] = i;
3282         /* if (n == 0) animal_temp[n++] = NON_PM; */
3283
3284         animal_list = (short *) alloc(n * sizeof *animal_list);
3285         (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp,
3286                       n * sizeof *animal_list);
3287         animal_list_count = n;
3288     } else { /* release */
3289         if (animal_list)
3290             free((genericptr_t) animal_list), animal_list = 0;
3291         animal_list_count = 0;
3292     }
3293 }
3294
3295 STATIC_OVL int
3296 pick_animal()
3297 {
3298     int res;
3299
3300     if (!animal_list)
3301         mon_animal_list(TRUE);
3302
3303     res = animal_list[rn2(animal_list_count)];
3304     /* rogue level should use monsters represented by uppercase letters
3305        only, but since chameleons aren't generated there (not uppercase!)
3306        we don't perform a lot of retries */
3307     if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet))
3308         res = animal_list[rn2(animal_list_count)];
3309     return res;
3310 }
3311
3312 void
3313 decide_to_shapeshift(mon, shiftflags)
3314 struct monst *mon;
3315 int shiftflags;
3316 {
3317     struct permonst *ptr = 0;
3318     int mndx;
3319     unsigned was_female = mon->female;
3320     boolean msg = FALSE, dochng = FALSE;
3321
3322     if ((shiftflags & SHIFT_MSG)
3323         || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon)))
3324         msg = TRUE;
3325
3326     if (!is_vampshifter(mon)) {
3327         /* regular shapeshifter */
3328         if (!rn2(6))
3329             dochng = TRUE;
3330     } else {
3331         /* The vampire has to be in good health (mhp) to maintain
3332          * its shifted form.
3333          *
3334          * If we're shifted and getting low on hp, maybe shift back, or
3335          * if we're a fog cloud at full hp, maybe pick a different shape.
3336          * If we're not already shifted and in good health, maybe shift.
3337          */
3338         if (mon->data->mlet != S_VAMPIRE) {
3339             if ((mon->mhp <= (mon->mhpmax + 5) / 6) && rn2(4)
3340                 && mon->cham >= LOW_PM) {
3341                 ptr = &mons[mon->cham];
3342                 dochng = TRUE;
3343             } else if (mon->data == &mons[PM_FOG_CLOUD]
3344                      && mon->mhp == mon->mhpmax && !rn2(4)
3345                      && (!canseemon(mon)
3346                          || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM)) {
3347                 /* if a fog cloud, maybe change to wolf or vampire bat;
3348                    those are more likely to take damage--at least when
3349                    tame--and then switch back to vampire; they'll also
3350                    switch to fog cloud if they encounter a closed door */
3351                 mndx = pickvampshape(mon);
3352                 if (mndx >= LOW_PM) {
3353                     ptr = &mons[mndx];
3354                     dochng = (ptr != mon->data);
3355                 }
3356             }
3357         } else {
3358             if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6)
3359                 && (!canseemon(mon)
3360                     || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM))
3361                 dochng = TRUE; /* 'ptr' stays Null */
3362         }
3363     }
3364     if (dochng) {
3365         if (newcham(mon, ptr, FALSE, msg) && is_vampshifter(mon)) {
3366             /* for vampshift, override the 10% chance for sex change */
3367             ptr = mon->data;
3368             if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr))
3369                 mon->female = was_female;
3370         }
3371     }
3372 }
3373
3374 STATIC_OVL int
3375 pickvampshape(mon)
3376 struct monst *mon;
3377 {
3378     int mndx = mon->cham, wolfchance = 10;
3379     /* avoid picking monsters with lowercase display symbols ('d' for wolf
3380        and 'v' for fog cloud) on rogue level*/
3381     boolean uppercase_only = Is_rogue_level(&u.uz);
3382
3383     switch (mndx) {
3384     case PM_VLAD_THE_IMPALER:
3385         /* ensure Vlad can keep carrying the Candelabrum */
3386         if (mon_has_special(mon))
3387             break; /* leave mndx as is */
3388         wolfchance = 3;
3389     /*FALLTHRU*/
3390     case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */
3391         if (!rn2(wolfchance) && !uppercase_only) {
3392             mndx = PM_WOLF;
3393             break;
3394         }
3395     /*FALLTHRU*/
3396     case PM_VAMPIRE: /* any vampire can become fog or bat */
3397         mndx = (!rn2(4) && !uppercase_only) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
3398         break;
3399     }
3400     return mndx;
3401 }
3402
3403 /* nonshapechangers who warrant special polymorph handling */
3404 STATIC_OVL boolean
3405 isspecmon(mon)
3406 struct monst *mon;
3407 {
3408     return (mon->isshk || mon->ispriest || mon->isgd
3409             || mon->m_id == quest_status.leader_m_id);
3410 }
3411
3412 /* restrict certain special monsters (shopkeepers, aligned priests,
3413    vault guards) to forms that allow them to behave sensibly (catching
3414    gold, speaking?) so that they don't need too much extra code */
3415 STATIC_OVL boolean
3416 validspecmon(mon, mndx)
3417 struct monst *mon;
3418 int mndx;
3419 {
3420     if (mndx == NON_PM)
3421         return TRUE; /* caller wants random */
3422
3423     if (!accept_newcham_form(mndx))
3424         return FALSE; /* geno'd or !polyok */
3425
3426     if (isspecmon(mon)) {
3427         struct permonst *ptr = &mons[mndx];
3428
3429         /* reject notake because object manipulation is expected
3430            and nohead because speech capability is expected */
3431         if (notake(ptr) || !has_head(ptr))
3432             return FALSE;
3433         /* [should we check ptr->msound here too?] */
3434     }
3435     return TRUE; /* potential new form is ok */
3436 }
3437
3438 /* prevent wizard mode user from specifying invalid vampshifter shape */
3439 boolean
3440 validvamp(mon, mndx_p, monclass)
3441 struct monst *mon;
3442 int *mndx_p, monclass;
3443 {
3444     /* simplify caller's usage */
3445     if (!is_vampshifter(mon))
3446         return validspecmon(mon, *mndx_p);
3447
3448     if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD
3449         || *mndx_p == PM_VLAD_THE_IMPALER) {
3450         /* player picked some type of vampire; use mon's self */
3451         *mndx_p = mon->cham;
3452         return TRUE;
3453     }
3454     if (mon->cham == PM_VLAD_THE_IMPALER && mon_has_special(mon)) {
3455         /* Vlad with Candelabrum; override choice, then accept it */
3456         *mndx_p = PM_VLAD_THE_IMPALER;
3457         return TRUE;
3458     }
3459     /* basic vampires can't become wolves; any can become fog or bat
3460        (we don't enforce upper-case only for rogue level here) */
3461     if (*mndx_p == PM_WOLF)
3462         return (boolean) (mon->cham != PM_VAMPIRE);
3463     if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT)
3464         return TRUE;
3465
3466     /* if we get here, specific type was no good; try by class */
3467     switch (monclass) {
3468     case S_VAMPIRE:
3469         *mndx_p = mon->cham;
3470         break;
3471     case S_BAT:
3472         *mndx_p = PM_VAMPIRE_BAT;
3473         break;
3474     case S_VORTEX:
3475         *mndx_p = PM_FOG_CLOUD;
3476         break;
3477     case S_DOG:
3478         if (mon->cham != PM_VAMPIRE) {
3479             *mndx_p = PM_WOLF;
3480             break;
3481         }
3482     /*FALLTHRU*/
3483     default:
3484         *mndx_p = NON_PM;
3485         break;
3486     }
3487     return (boolean) (*mndx_p != NON_PM);
3488 }
3489
3490 int
3491 select_newcham_form(mon)
3492 struct monst *mon;
3493 {
3494     int mndx = NON_PM, tryct;
3495
3496     switch (mon->cham) {
3497     case PM_SANDESTIN:
3498         if (rn2(7))
3499             mndx = pick_nasty();
3500         break;
3501     case PM_DOPPELGANGER:
3502         if (!rn2(7)) {
3503             mndx = pick_nasty();
3504         } else if (rn2(3)) { /* role monsters */
3505             mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
3506         } else if (!rn2(3)) { /* quest guardians */
3507             mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT);
3508             /* avoid own role's guardian */
3509             if (mndx == urole.guardnum)
3510                 mndx = NON_PM;
3511         } else { /* general humanoids */
3512             tryct = 5;
3513             do {
3514                 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3515                 if (humanoid(&mons[mndx]) && polyok(&mons[mndx]))
3516                     break;
3517             } while (--tryct > 0);
3518             if (!tryct)
3519                 mndx = NON_PM;
3520         }
3521         break;
3522     case PM_CHAMELEON:
3523         if (!rn2(3))
3524             mndx = pick_animal();
3525         break;
3526     case PM_VLAD_THE_IMPALER:
3527     case PM_VAMPIRE_LORD:
3528     case PM_VAMPIRE:
3529         mndx = pickvampshape(mon);
3530         break;
3531     case NON_PM: /* ordinary */
3532       {
3533         struct obj *m_armr = which_armor(mon, W_ARM);
3534
3535         if (m_armr && Is_dragon_scales(m_armr))
3536             mndx = (int) (Dragon_scales_to_pm(m_armr) - mons);
3537         else if (m_armr && Is_dragon_mail(m_armr))
3538             mndx = (int) (Dragon_mail_to_pm(m_armr) - mons);
3539       }
3540         break;
3541     }
3542
3543     /* for debugging: allow control of polymorphed monster */
3544     if (wizard && iflags.mon_polycontrol) {
3545         char pprompt[BUFSZ], buf[BUFSZ] = DUMMY;
3546         int monclass;
3547
3548         Sprintf(pprompt, "Change %s @ %s into what kind of monster?",
3549                 noit_mon_nam(mon),
3550                 coord_desc((int) mon->mx, (int) mon->my, buf,
3551                            (iflags.getpos_coords != GPCOORDS_NONE)
3552                               ? iflags.getpos_coords : GPCOORDS_MAP));
3553         tryct = 5;
3554         do {
3555             monclass = 0;
3556             getlin(pprompt, buf);
3557             mungspaces(buf);
3558             /* for ESC, take form selected above (might be NON_PM) */
3559             if (*buf == '\033')
3560                 break;
3561             /* for "*", use NON_PM to pick an arbitrary shape below */
3562             if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
3563                 mndx = NON_PM;
3564                 break;
3565             }
3566             mndx = name_to_mon(buf);
3567             if (mndx == NON_PM) {
3568                 /* didn't get a type, so check whether it's a class
3569                    (single letter or text match with def_monsyms[]) */
3570                 monclass = name_to_monclass(buf, &mndx);
3571                 if (monclass && mndx == NON_PM)
3572                     mndx = mkclass_poly(monclass);
3573             }
3574             if (mndx >= LOW_PM) {
3575                 /* got a specific type of monster; use it if we can */
3576                 if (validvamp(mon, &mndx, monclass))
3577                     break;
3578                 /* can't; revert to random in case we exhaust tryct */
3579                 mndx = NON_PM;
3580             }
3581
3582             pline("It can't become that.");
3583         } while (--tryct > 0);
3584         if (!tryct)
3585             pline1(thats_enough_tries);
3586         if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass))
3587             mndx = pickvampshape(mon); /* don't resort to arbitrary */
3588     }
3589
3590     /* if no form was specified above, pick one at random now */
3591     if (mndx == NON_PM) {
3592         tryct = 50;
3593         do {
3594             mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3595         } while (--tryct > 0 && !validspecmon(mon, mndx)
3596                  /* try harder to select uppercase monster on rogue level */
3597                  && (tryct > 40 && Is_rogue_level(&u.uz)
3598                      && !isupper((uchar) mons[mndx].mlet)));
3599     }
3600     return mndx;
3601 }
3602
3603 /* this used to be inline within newcham() but monpolycontrol needs it too */
3604 STATIC_OVL struct permonst *
3605 accept_newcham_form(mndx)
3606 int mndx;
3607 {
3608     struct permonst *mdat;
3609
3610     if (mndx == NON_PM)
3611         return 0;
3612     mdat = &mons[mndx];
3613     if ((mvitals[mndx].mvflags & G_GENOD) != 0)
3614         return 0;
3615     if (is_placeholder(mdat))
3616         return 0;
3617     /* select_newcham_form() might deliberately pick a player
3618        character type (random selection never does) which
3619        polyok() rejects, so we need a special case here */
3620     if (is_mplayer(mdat))
3621         return mdat;
3622     /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */
3623     return polyok(mdat) ? mdat : 0;
3624 }
3625
3626 void
3627 mgender_from_permonst(mtmp, mdat)
3628 struct monst *mtmp;
3629 struct permonst *mdat;
3630 {
3631     if (is_male(mdat)) {
3632         if (mtmp->female)
3633             mtmp->female = FALSE;
3634     } else if (is_female(mdat)) {
3635         if (!mtmp->female)
3636             mtmp->female = TRUE;
3637     } else if (!is_neuter(mdat)) {
3638         if (!rn2(10))
3639             mtmp->female = !mtmp->female;
3640     }
3641 }
3642
3643 /* make a chameleon take on another shape, or a polymorph target
3644    (possibly self-inflicted) become a different monster;
3645    returns 1 if it actually changes form */
3646 int
3647 newcham(mtmp, mdat, polyspot, msg)
3648 struct monst *mtmp;
3649 struct permonst *mdat;
3650 boolean polyspot; /* change is the result of wand or spell of polymorph */
3651 boolean msg;      /* "The oldmon turns into a newmon!" */
3652 {
3653     int hpn, hpd;
3654     int mndx, tryct;
3655     struct permonst *olddata = mtmp->data;
3656     char *p, oldname[BUFSZ], l_oldname[BUFSZ], newname[BUFSZ];
3657
3658     /* Riders are immune to polymorph and green slime
3659        (but apparent Rider might actually be a doppelganger) */
3660     if (mtmp->cham == NON_PM) { /* not a shapechanger */
3661         if (is_rider(olddata))
3662             return 0;
3663         /* make Nazgul and erinyes immune too, to reduce chance of
3664            anomalous extinction feedback during final disclsoure */
3665         if (mbirth_limit(monsndx(olddata)) < MAXMONNO)
3666             return 0;
3667     }
3668
3669     if (msg) {
3670         /* like Monnam() but never mention saddle */
3671         Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3672                                  SUPPRESS_SADDLE, FALSE));
3673         oldname[0] = highc(oldname[0]);
3674     }
3675     /* we need this one whether msg is true or not */
3676     Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3677                                has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE));
3678
3679     /* mdat = 0 -> caller wants a random monster shape */
3680     if (mdat == 0) {
3681         /* select_newcham_form() loops when resorting to random but
3682            it doesn't always pick that so we still retry here too */
3683         tryct = 20;
3684         do {
3685             mndx = select_newcham_form(mtmp);
3686             mdat = accept_newcham_form(mndx);
3687             /* for the first several tries we require upper-case on
3688                the rogue level (after that, we take whatever we get) */
3689             if (tryct > 15 && Is_rogue_level(&u.uz)
3690                 && mdat && !isupper((uchar) mdat->mlet))
3691                 mdat = 0;
3692             if (mdat)
3693                 break;
3694         } while (--tryct > 0);
3695         if (!tryct)
3696             return 0;
3697     } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
3698         return 0; /* passed in mdat is genocided */
3699
3700     if (mdat == olddata)
3701         return 0; /* still the same monster */
3702
3703     mgender_from_permonst(mtmp, mdat);
3704     /* Endgame mplayers start out as "Foo the Bar", but some of the
3705      * titles are inappropriate when polymorphed, particularly into
3706      * the opposite sex.  Player characters don't use ranks when
3707      * polymorphed, so dropping rank for mplayers seems reasonable.
3708      */
3709     if (In_endgame(&u.uz) && is_mplayer(olddata)
3710         && has_mname(mtmp) && (p = strstr(MNAME(mtmp), " the ")) != 0)
3711         *p = '\0';
3712
3713     if (mtmp->wormno) { /* throw tail away */
3714         wormgone(mtmp);
3715         place_monster(mtmp, mtmp->mx, mtmp->my);
3716     }
3717     if (mtmp->m_ap_type && mdat->mlet != S_MIMIC)
3718         seemimic(mtmp); /* revert to normal monster */
3719
3720     /* (this code used to try to adjust the monster's health based on
3721        a normal one of its type but there are too many special cases
3722        which need to handled in order to do that correctly, so just
3723        give the new form the same proportion of HP as its old one had) */
3724     hpn = mtmp->mhp;
3725     hpd = mtmp->mhpmax;
3726     /* set level and hit points */
3727     newmonhp(mtmp, monsndx(mdat));
3728     /* new hp: same fraction of max as before */
3729 #ifndef LINT
3730     mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd);
3731 #endif
3732     /* sanity check (potential overflow) */
3733     if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax)
3734         mtmp->mhp = mtmp->mhpmax;
3735     /* unlikely but not impossible; a 1HD creature with 1HP that changes
3736        into a 0HD creature will require this statement */
3737     if (!mtmp->mhp)
3738         mtmp->mhp = 1;
3739
3740     /* take on the new form... */
3741     set_mon_data(mtmp, mdat, 0);
3742
3743     if (emits_light(olddata) != emits_light(mtmp->data)) {
3744         /* used to give light, now doesn't, or vice versa,
3745            or light's range has changed */
3746         if (emits_light(olddata))
3747             del_light_source(LS_MONSTER, monst_to_any(mtmp));
3748         if (emits_light(mtmp->data))
3749             new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
3750                              LS_MONSTER, monst_to_any(mtmp));
3751     }
3752     if (!mtmp->perminvis || pm_invisible(olddata))
3753         mtmp->perminvis = pm_invisible(mdat);
3754     mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
3755     if (mtmp->mundetected)
3756         (void) hideunder(mtmp);
3757     if (u.ustuck == mtmp) {
3758         if (u.uswallow) {
3759             if (!attacktype(mdat, AT_ENGL)) {
3760                 /* Does mdat care? */
3761                 if (!noncorporeal(mdat) && !amorphous(mdat)
3762                     && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) {
3763                     char msgtrail[BUFSZ];
3764
3765                     if (is_vampshifter(mtmp)) {
3766 #if 0 /*JP*/
3767                         Sprintf(msgtrail, " which was a shapeshifted %s",
3768                                 noname_monnam(mtmp, ARTICLE_NONE));
3769 #else
3770                         Sprintf(msgtrail, "(\8eÀ\8dÛ\82É\82Í\8c`\82ð\95Ï\82¦\82½%s)",
3771                                 noname_monnam(mtmp, ARTICLE_NONE));
3772 #endif
3773                     } else if (is_animal(mdat)) {
3774 /*JP
3775                         Strcpy(msgtrail, "'s stomach");
3776 */
3777                         Strcpy(msgtrail, "\82Ì\88Ý");
3778                     } else {
3779                         msgtrail[0] = '\0';
3780                     }
3781
3782                     /* Do this even if msg is FALSE */
3783 #if 0 /*JP*/
3784                     You("%s %s%s!",
3785                         (amorphous(olddata) || is_whirly(olddata))
3786                             ? "emerge from" : "break out of",
3787                         l_oldname, msgtrail);
3788 #else
3789                     You("%s%s%s\81I", l_oldname, msgtrail,
3790                         (amorphous(olddata) || is_whirly(olddata))
3791                             ? "\82©\82ç\94ò\82Ñ\8fo\82µ\82½" : "\82ð\94j\82è\8fo\82½"
3792                         );
3793 #endif
3794                     msg = FALSE; /* message has been given */
3795                     mtmp->mhp = 1; /* almost dead */
3796                 }
3797                 expels(mtmp, olddata, FALSE);
3798             } else {
3799                 /* update swallow glyphs for new monster */
3800                 swallowed(0);
3801             }
3802         } else if (!sticks(mdat) && !sticks(youmonst.data))
3803             unstuck(mtmp);
3804     }
3805
3806 #ifndef DCC30_BUG
3807     if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
3808 #else
3809     /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
3810      * same expression.
3811      */
3812     if (mdat == &mons[PM_LONG_WORM]
3813         && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
3814 #endif
3815         /* we can now create worms with tails - 11/91 */
3816         initworm(mtmp, rn2(5));
3817         if (count_wsegs(mtmp))
3818             place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
3819     }
3820
3821     newsym(mtmp->mx, mtmp->my);
3822
3823     if (msg) {
3824         Strcpy(newname, noname_monnam(mtmp, ARTICLE_A));
3825         /* oldname was capitalized above; newname will be lower case */
3826 #if 0 /*JP*/
3827         if (!strcmpi(newname, "it")) { /* can't see or sense it now */
3828 #else
3829         if (!strcmpi(newname, "\89½\8eÒ\82©")) { /* can't see or sense it now */
3830 #endif
3831 #if 0 /*JP*/
3832             if (!!strcmpi(oldname, "it")) /* could see or sense it before */
3833 #else
3834             if (!!strcmpi(oldname, "\89½\8eÒ\82©")) /* could see or sense it before */
3835 #endif
3836                 pline("%s disappears!", oldname);
3837             (void) usmellmon(mdat);
3838         } else { /* can see or sense it now */
3839 #if 0 /*JP*/
3840             if (!strcmpi(oldname, "it")) /* couldn't see or sense it before */
3841 #else
3842             if (!strcmpi(oldname, "\89½\8eÒ\82©")) /* couldn't see or sense it before */
3843 #endif
3844                 pline("%s appears!", upstart(newname));
3845             else
3846 /*JP
3847             pline("%s turns into %s!", oldname, newname);
3848 */
3849             pline("%s\82Í%s\82É\82È\82Á\82½\81I", oldname, newname);
3850         }
3851     }
3852
3853     /* when polymorph trap/wand/potion produces a vampire, turn in into
3854        a full-fledged vampshifter unless shape-changing is blocked */
3855     if (mtmp->cham == NON_PM && mdat->mlet == S_VAMPIRE
3856         && !Protection_from_shape_changers)
3857         mtmp->cham = pm_to_cham(monsndx(mdat));
3858
3859     possibly_unwield(mtmp, polyspot); /* might lose use of weapon */
3860     mon_break_armor(mtmp, polyspot);
3861     if (!(mtmp->misc_worn_check & W_ARMG))
3862 #if 0 /*JP*/
3863         mselftouch(mtmp, "No longer petrify-resistant, ",
3864                    !context.mon_moving);
3865 #else
3866         mselftouch(mtmp, "\90Î\89»\82Ö\82Ì\92ï\8dR\97Í\82ª\82È\82­\82È\82Á\82Ä\81C",
3867                    !context.mon_moving);
3868 #endif
3869     m_dowear(mtmp, FALSE);
3870
3871     /* This ought to re-test can_carry() on each item in the inventory
3872      * rather than just checking ex-giants & boulders, but that'd be
3873      * pretty expensive to perform.  If implemented, then perhaps
3874      * minvent should be sorted in order to drop heaviest items first.
3875      */
3876     /* former giants can't continue carrying boulders */
3877     if (mtmp->minvent && !throws_rocks(mdat)) {
3878         register struct obj *otmp, *otmp2;
3879
3880         for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
3881             otmp2 = otmp->nobj;
3882             if (otmp->otyp == BOULDER) {
3883                 /* this keeps otmp from being polymorphed in the
3884                    same zap that the monster that held it is polymorphed */
3885                 if (polyspot)
3886                     bypass_obj(otmp);
3887                 obj_extract_self(otmp);
3888                 /* probably ought to give some "drop" message here */
3889                 if (flooreffects(otmp, mtmp->mx, mtmp->my, ""))
3890                     continue;
3891                 place_object(otmp, mtmp->mx, mtmp->my);
3892             }
3893         }
3894     }
3895
3896     return 1;
3897 }
3898
3899 /* sometimes an egg will be special */
3900 #define BREEDER_EGG (!rn2(77))
3901
3902 /*
3903  * Determine if the given monster number can be hatched from an egg.
3904  * Return the monster number to use as the egg's corpsenm.  Return
3905  * NON_PM if the given monster can't be hatched.
3906  */
3907 int
3908 can_be_hatched(mnum)
3909 int mnum;
3910 {
3911     /* ranger quest nemesis has the oviparous bit set, making it
3912        be possible to wish for eggs of that unique monster; turn
3913        such into ordinary eggs rather than forbidding them outright */
3914     if (mnum == PM_SCORPIUS)
3915         mnum = PM_SCORPION;
3916
3917     mnum = little_to_big(mnum);
3918     /*
3919      * Queen bees lay killer bee eggs (usually), but killer bees don't
3920      * grow into queen bees.  Ditto for [winged-]gargoyles.
3921      */
3922     if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE
3923         || (lays_eggs(&mons[mnum])
3924             && (BREEDER_EGG
3925                 || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
3926         return mnum;
3927     return NON_PM;
3928 }
3929
3930 /* type of egg laid by #sit; usually matches parent */
3931 int
3932 egg_type_from_parent(mnum, force_ordinary)
3933 int mnum; /* parent monster; caller must handle lays_eggs() check */
3934 boolean force_ordinary;
3935 {
3936     if (force_ordinary || !BREEDER_EGG) {
3937         if (mnum == PM_QUEEN_BEE)
3938             mnum = PM_KILLER_BEE;
3939         else if (mnum == PM_WINGED_GARGOYLE)
3940             mnum = PM_GARGOYLE;
3941     }
3942     return mnum;
3943 }
3944
3945 /* decide whether an egg of the indicated monster type is viable;
3946    also used to determine whether an egg or tin can be created... */
3947 boolean
3948 dead_species(m_idx, egg)
3949 int m_idx;
3950 boolean egg;
3951 {
3952     int alt_idx;
3953
3954     /* generic eggs are unhatchable and have corpsenm of NON_PM */
3955     if (m_idx < LOW_PM)
3956         return TRUE;
3957     /*
3958      * For monsters with both baby and adult forms, genociding either
3959      * form kills all eggs of that monster.  Monsters with more than
3960      * two forms (small->large->giant mimics) are more or less ignored;
3961      * fortunately, none of them have eggs.  Species extinction due to
3962      * overpopulation does not kill eggs.
3963      */
3964     alt_idx = egg ? big_to_little(m_idx) : m_idx;
3965     return (boolean) ((mvitals[m_idx].mvflags & G_GENOD) != 0
3966                       || (mvitals[alt_idx].mvflags & G_GENOD) != 0);
3967 }
3968
3969 /* kill off any eggs of genocided monsters */
3970 STATIC_OVL void
3971 kill_eggs(obj_list)
3972 struct obj *obj_list;
3973 {
3974     struct obj *otmp;
3975
3976     for (otmp = obj_list; otmp; otmp = otmp->nobj)
3977         if (otmp->otyp == EGG) {
3978             if (dead_species(otmp->corpsenm, TRUE)) {
3979                 /*
3980                  * It seems we could also just catch this when
3981                  * it attempted to hatch, so we wouldn't have to
3982                  * search all of the objlists.. or stop all
3983                  * hatch timers based on a corpsenm.
3984                  */
3985                 kill_egg(otmp);
3986             }
3987 #if 0 /* not used */
3988         } else if (otmp->otyp == TIN) {
3989             if (dead_species(otmp->corpsenm, FALSE))
3990                 otmp->corpsenm = NON_PM; /* empty tin */
3991         } else if (otmp->otyp == CORPSE) {
3992             if (dead_species(otmp->corpsenm, FALSE))
3993                 ; /* not yet implemented... */
3994 #endif
3995         } else if (Has_contents(otmp)) {
3996             kill_eggs(otmp->cobj);
3997         }
3998 }
3999
4000 /* kill all members of genocided species */
4001 void
4002 kill_genocided_monsters()
4003 {
4004     struct monst *mtmp, *mtmp2;
4005     boolean kill_cham;
4006     int mndx;
4007
4008     /*
4009      * Called during genocide, and again upon level change.  The latter
4010      * catches up with any migrating monsters as they finally arrive at
4011      * their intended destinations, so possessions get deposited there.
4012      *
4013      * Chameleon handling:
4014      *  1) if chameleons have been genocided, destroy them
4015      *     regardless of current form;
4016      *  2) otherwise, force every chameleon which is imitating
4017      *     any genocided species to take on a new form.
4018      */
4019     for (mtmp = fmon; mtmp; mtmp = mtmp2) {
4020         mtmp2 = mtmp->nmon;
4021         if (DEADMONSTER(mtmp))
4022             continue;
4023         mndx = monsndx(mtmp->data);
4024         kill_cham = (mtmp->cham >= LOW_PM
4025                      && (mvitals[mtmp->cham].mvflags & G_GENOD));
4026         if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) {
4027             if (mtmp->cham >= LOW_PM && !kill_cham)
4028                 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
4029             else
4030                 mondead(mtmp);
4031         }
4032         if (mtmp->minvent)
4033             kill_eggs(mtmp->minvent);
4034     }
4035
4036     kill_eggs(invent);
4037     kill_eggs(fobj);
4038     kill_eggs(migrating_objs);
4039     kill_eggs(level.buriedobjlist);
4040 }
4041
4042 void
4043 golemeffects(mon, damtype, dam)
4044 register struct monst *mon;
4045 int damtype, dam;
4046 {
4047     int heal = 0, slow = 0;
4048
4049     if (mon->data == &mons[PM_FLESH_GOLEM]) {
4050         if (damtype == AD_ELEC)
4051             heal = (dam + 5) / 6;
4052         else if (damtype == AD_FIRE || damtype == AD_COLD)
4053             slow = 1;
4054     } else if (mon->data == &mons[PM_IRON_GOLEM]) {
4055         if (damtype == AD_ELEC)
4056             slow = 1;
4057         else if (damtype == AD_FIRE)
4058             heal = dam;
4059     } else {
4060         return;
4061     }
4062     if (slow) {
4063         if (mon->mspeed != MSLOW)
4064             mon_adjust_speed(mon, -1, (struct obj *) 0);
4065     }
4066     if (heal) {
4067         if (mon->mhp < mon->mhpmax) {
4068             mon->mhp += heal;
4069             if (mon->mhp > mon->mhpmax)
4070                 mon->mhp = mon->mhpmax;
4071             if (cansee(mon->mx, mon->my))
4072 /*JP
4073                 pline("%s seems healthier.", Monnam(mon));
4074 */
4075                 pline("%s\82Í\8c³\8bC\82É\82È\82Á\82½\82æ\82¤\82É\8c©\82¦\82é\81D", Monnam(mon));
4076         }
4077     }
4078 }
4079
4080 boolean
4081 angry_guards(silent)
4082 boolean silent;
4083 {
4084     struct monst *mtmp;
4085     int ct = 0, nct = 0, sct = 0, slct = 0;
4086
4087     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4088         if (DEADMONSTER(mtmp))
4089             continue;
4090         if (is_watch(mtmp->data) && mtmp->mpeaceful) {
4091             ct++;
4092             if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
4093                 if (distu(mtmp->mx, mtmp->my) == 2)
4094                     nct++;
4095                 else
4096                     sct++;
4097             }
4098             if (mtmp->msleeping || mtmp->mfrozen) {
4099                 slct++;
4100                 mtmp->msleeping = mtmp->mfrozen = 0;
4101             }
4102             mtmp->mpeaceful = 0;
4103         }
4104     }
4105     if (ct) {
4106         if (!silent) { /* do we want pline msgs? */
4107             if (slct)
4108 #if 0 /*JP*/
4109                 pline_The("guard%s wake%s up!", slct > 1 ? "s" : "",
4110                           slct == 1 ? "s" : "");
4111 #else
4112                 pline("\94Ô\95º\82Í\96Ú\82ð\8ao\82Ü\82µ\82½\81I");
4113 #endif
4114             if (nct || sct) {
4115                 if (nct)
4116 #if 0 /*JP*/
4117                     pline_The("guard%s get%s angry!", nct == 1 ? "" : "s",
4118                               nct == 1 ? "s" : "");
4119 #else
4120                     pline("\94Ô\95º\82Í\93{\82Á\82½\81I");
4121 #endif
4122                 else if (!Blind)
4123 #if 0 /*JP*/
4124                     You_see("%sangry guard%s approaching!",
4125                             sct == 1 ? "an " : "", sct > 1 ? "s" : "");
4126 #else
4127                     You("\93{\82Á\82½\94Ô\95º\82ª\8bß\8añ\82Á\82Ä\82­\82é\82Ì\82ð\8c©\82½\81I");
4128 #endif
4129             } else
4130 /*JP
4131                 You_hear("the shrill sound of a guard's whistle.");
4132 */
4133                 You_hear("\94Ô\95º\82Ì\93J\82ª\82¯\82½\82½\82Ü\82µ\82­\96Â\82é\82Ì\82ð\95·\82¢\82½\81D");
4134         }
4135         return TRUE;
4136     }
4137     return FALSE;
4138 }
4139
4140 void
4141 pacify_guards()
4142 {
4143     struct monst *mtmp;
4144
4145     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4146         if (DEADMONSTER(mtmp))
4147             continue;
4148         if (is_watch(mtmp->data))
4149             mtmp->mpeaceful = 1;
4150     }
4151 }
4152
4153 void
4154 mimic_hit_msg(mtmp, otyp)
4155 struct monst *mtmp;
4156 short otyp;
4157 {
4158     short ap = mtmp->mappearance;
4159
4160     switch (mtmp->m_ap_type) {
4161     case M_AP_NOTHING:
4162     case M_AP_FURNITURE:
4163     case M_AP_MONSTER:
4164         break;
4165     case M_AP_OBJECT:
4166         if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
4167 #if 0 /*JP*/
4168             pline("%s seems a more vivid %s than before.",
4169                   The(simple_typename(ap)),
4170                   c_obj_colors[objects[ap].oc_color]);
4171 #else
4172             pline("%s\82Í\88È\91O\82æ\82è\82æ\82è\91N\82â\82©\82È%s\82É\82È\82Á\82½\82æ\82¤\82¾\81D",
4173                   The(simple_typename(ap)),
4174                   c_obj_colors[objects[ap].oc_color]);
4175 #endif
4176         }
4177         break;
4178     }
4179 }
4180
4181 boolean
4182 usmellmon(mdat)
4183 struct permonst *mdat;
4184 {
4185     int mndx;
4186     boolean nonspecific = FALSE;
4187     boolean msg_given = FALSE;
4188
4189     if (mdat) {
4190         if (!olfaction(youmonst.data))
4191             return FALSE;
4192         mndx = monsndx(mdat);
4193         switch (mndx) {
4194         case PM_ROTHE:
4195         case PM_MINOTAUR:
4196 /*JP
4197             You("notice a bovine smell.");
4198 */
4199             You("\8b\8d\82Ì\82æ\82¤\82È\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4200             msg_given = TRUE;
4201             break;
4202         case PM_CAVEMAN:
4203         case PM_CAVEWOMAN:
4204         case PM_BARBARIAN:
4205         case PM_NEANDERTHAL:
4206 /*JP
4207             You("smell body odor.");
4208 */
4209             pline("\91Ì\8fL\82Ì\82æ\82¤\82È\82É\82¨\82¢\82ª\82µ\82½\81D");
4210             msg_given = TRUE;
4211             break;
4212         /*
4213         case PM_PESTILENCE:
4214         case PM_FAMINE:
4215         case PM_DEATH:
4216             break;
4217         */
4218         case PM_HORNED_DEVIL:
4219         case PM_BALROG:
4220         case PM_ASMODEUS:
4221         case PM_DISPATER:
4222         case PM_YEENOGHU:
4223         case PM_ORCUS:
4224             break;
4225         case PM_HUMAN_WEREJACKAL:
4226         case PM_HUMAN_WERERAT:
4227         case PM_HUMAN_WEREWOLF:
4228         case PM_WEREJACKAL:
4229         case PM_WERERAT:
4230         case PM_WEREWOLF:
4231         case PM_OWLBEAR:
4232 /*JP
4233             You("detect an odor reminiscent of an animal's den.");
4234 */
4235             pline("\93®\95¨\82Ì\82Ë\82®\82ç\82ð\8ev\82¢\8fo\82·\82æ\82¤\82È\82É\82¨\82¢\82ª\82µ\82½\81D");
4236             msg_given = TRUE;
4237             break;
4238         /*
4239         case PM_PURPLE_WORM:
4240             break;
4241         */
4242         case PM_STEAM_VORTEX:
4243 /*JP
4244             You("smell steam.");
4245 */
4246             pline("\8fö\8bC\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4247             msg_given = TRUE;
4248             break;
4249         case PM_GREEN_SLIME:
4250 /*JP
4251             pline("%s stinks.", Something);
4252 */
4253             pline("\88«\8fL\82ª\82µ\82½\81D");
4254             msg_given = TRUE;
4255             break;
4256         case PM_VIOLET_FUNGUS:
4257         case PM_SHRIEKER:
4258 /*JP
4259             You("smell mushrooms.");
4260 */
4261             pline("\82«\82Ì\82±\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4262             msg_given = TRUE;
4263             break;
4264         /* These are here to avoid triggering the
4265            nonspecific treatment through the default case below*/
4266         case PM_WHITE_UNICORN:
4267         case PM_GRAY_UNICORN:
4268         case PM_BLACK_UNICORN:
4269         case PM_JELLYFISH:
4270             break;
4271         default:
4272             nonspecific = TRUE;
4273             break;
4274         }
4275
4276         if (nonspecific)
4277             switch (mdat->mlet) {
4278             case S_DOG:
4279 /*JP
4280                 You("notice a dog smell.");
4281 */
4282                 You("\8c¢\82Ì\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4283                 msg_given = TRUE;
4284                 break;
4285             case S_DRAGON:
4286 /*JP
4287                 You("smell a dragon!");
4288 */
4289                 pline("\83h\83\89\83S\83\93\82Ì\82É\82¨\82¢\82ª\82·\82é\81I");
4290                 msg_given = TRUE;
4291                 break;
4292             case S_FUNGUS:
4293 /*JP
4294                 pline("%s smells moldy.", Something);
4295 */
4296                 pline("\89½\82©\91Û\82Ì\82æ\82¤\82È\82É\82¨\82¢\82ª\82·\82é\81D");
4297                 msg_given = TRUE;
4298                 break;
4299             case S_UNICORN:
4300 #if 0 /*JP*/
4301                 You("detect a%s odor reminiscent of a stable.",
4302                     (mndx == PM_PONY) ? "n" : " strong");
4303 #else
4304                 pline("\94n\8f¬\89®\82ð\8ev\82¢\8fo\82·\82æ\82¤\82È%s\82É\82¨\82¢\82ª\82µ\82½\81D",
4305                     (mndx == PM_PONY) ? "" : "\8b­\82¢");
4306 #endif
4307                 msg_given = TRUE;
4308                 break;
4309             case S_ZOMBIE:
4310 /*JP
4311                 You("smell rotting flesh.");
4312 */
4313                 pline("\95\85\82Á\82½\93÷\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4314                 msg_given = TRUE;
4315                 break;
4316             case S_EEL:
4317 /*JP
4318                 You("smell fish.");
4319 */
4320                 pline("\8b\9b\82Ì\82É\82¨\82¢\82ª\82µ\82½\81D");
4321                 msg_given = TRUE;
4322                 break;
4323             case S_ORC:
4324                 if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
4325 /*JP
4326                     You("notice an attractive smell.");
4327 */
4328                     You("\96£\97Í\93I\82È\82É\82¨\82¢\82É\8bC\95t\82¢\82½\81D");
4329                 else
4330 /*JP
4331                     pline("A foul stench makes you feel a little nauseated.");
4332 */
4333                     pline("\82Þ\82©\82Â\82­\82æ\82¤\82È\88«\8fL\82Å\8f­\82µ\8bC\95ª\82ª\88«\82­\82È\82Á\82½\81D");
4334                 msg_given = TRUE;
4335                 break;
4336             default:
4337                 break;
4338             }
4339     }
4340     return msg_given ? TRUE : FALSE;
4341 }
4342
4343 /*mon.c*/