OSDN Git Service

patch artifact
[jnethack/source.git] / src / muse.c
1 /* NetHack 3.6  muse.c  $NHDT-Date: 1447987786 2015/11/20 02:49:46 $  $NHDT-Branch: master $:$NHDT-Revision: 1.68 $ */
2 /*      Copyright (C) 1990 by Ken Arromdee                         */
3 /* NetHack may be freely redistributed.  See license for details.  */
4
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016            */
8 /* JNetHack may be freely redistributed.  See license for details. */
9
10 /*
11  * Monster item usage routines.
12  */
13
14 #include "hack.h"
15
16 extern const int monstr[];
17
18 boolean m_using = FALSE;
19
20 /* Let monsters use magic items.  Arbitrary assumptions: Monsters only use
21  * scrolls when they can see, monsters know when wands have 0 charges,
22  * monsters cannot recognize if items are cursed are not, monsters which
23  * are confused don't know not to read scrolls, etc....
24  */
25
26 STATIC_DCL struct permonst *FDECL(muse_newcham_mon, (struct monst *));
27 STATIC_DCL int FDECL(precheck, (struct monst *, struct obj *));
28 STATIC_DCL void FDECL(mzapmsg, (struct monst *, struct obj *, BOOLEAN_P));
29 STATIC_DCL void FDECL(mreadmsg, (struct monst *, struct obj *));
30 STATIC_DCL void FDECL(mquaffmsg, (struct monst *, struct obj *));
31 STATIC_PTR int FDECL(mbhitm, (struct monst *, struct obj *));
32 STATIC_DCL void FDECL(mbhit, (struct monst *, int,
33                               int FDECL((*), (MONST_P, OBJ_P)),
34                               int FDECL((*), (OBJ_P, OBJ_P)), struct obj *));
35 STATIC_DCL void FDECL(you_aggravate, (struct monst *));
36 STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *, struct obj *,
37                                             BOOLEAN_P, BOOLEAN_P));
38 STATIC_DCL boolean FDECL(cures_stoning, (struct monst *, struct obj *,
39                                          BOOLEAN_P));
40 STATIC_DCL boolean FDECL(mcould_eat_tin, (struct monst *));
41 STATIC_DCL boolean FDECL(muse_unslime, (struct monst *, struct obj *,
42                                         BOOLEAN_P));
43 STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *));
44 STATIC_DCL boolean FDECL(green_mon, (struct monst *));
45
46 static struct musable {
47     struct obj *offensive;
48     struct obj *defensive;
49     struct obj *misc;
50     int has_offense, has_defense, has_misc;
51     /* =0, no capability; otherwise, different numbers.
52      * If it's an object, the object is also set (it's 0 otherwise).
53      */
54 } m;
55 static int trapx, trapy;
56 static boolean zap_oseen; /* for wands which use mbhitm and are zapped at
57                            * players.  We usually want an oseen local to
58                            * the function, but this is impossible since the
59                            * function mbhitm has to be compatible with the
60                            * normal zap routines, and those routines don't
61                            * remember who zapped the wand. */
62
63 /* Any preliminary checks which may result in the monster being unable to use
64  * the item.  Returns 0 if nothing happened, 2 if the monster can't do
65  * anything (i.e. it teleported) and 1 if it's dead.
66  */
67 STATIC_OVL int
68 precheck(mon, obj)
69 struct monst *mon;
70 struct obj *obj;
71 {
72     boolean vis;
73
74     if (!obj)
75         return 0;
76     vis = cansee(mon->mx, mon->my);
77
78     if (obj->oclass == POTION_CLASS) {
79         coord cc;
80 /*JP
81         static const char *empty = "The potion turns out to be empty.";
82 */
83         static const char *empty = "\96ò\82Í\8bó\82Á\82Û\82Å\82 \82é\82±\82Æ\82ª\82í\82©\82Á\82½\81D";
84         const char *potion_descr;
85         struct monst *mtmp;
86
87         potion_descr = OBJ_DESCR(objects[obj->otyp]);
88         if (potion_descr && !strcmp(potion_descr, "milky")) {
89             if (!(mvitals[PM_GHOST].mvflags & G_GONE)
90                 && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) {
91                 if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST]))
92                     return 0;
93                 mquaffmsg(mon, obj);
94                 m_useup(mon, obj);
95                 mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS);
96                 if (!mtmp) {
97                     if (vis)
98                         pline1(empty);
99                 } else {
100                     if (vis) {
101 #if 0 /*JP*/
102                         pline(
103                             "As %s opens the bottle, an enormous %s emerges!",
104                               mon_nam(mon),
105                               Hallucination ? rndmonnam(NULL)
106                                             : (const char *) "ghost");
107 #else
108                         pline(
109                             "%s\82ª\95r\82ð\8aJ\82¯\82é\82Æ\81C\8b\90\91å\82È%s\82ª\8fo\82Ä\82«\82½\81I",
110                               mon_nam(mon),
111                               Hallucination ? rndmonnam(NULL)
112                                             : (const char *)"\97H\97ì");
113 #endif
114 /*JP
115                         pline("%s is frightened to death, and unable to move.",
116 */
117                         pline("%s\82Í\82Ü\82Á\82³\82¨\82É\82È\82Á\82Ä\8bÁ\82«\81C\93®\82¯\82È\82­\82È\82Á\82½\81D",
118                               Monnam(mon));
119                     }
120                     paralyze_monst(mon, 3);
121                 }
122                 return 2;
123             }
124         }
125 /*JP
126         if (potion_descr && !strcmp(potion_descr, "smoky")
127 */
128         if (potion_descr && !strcmp(potion_descr, "\89\8c\82Ì\8fo\82Ä\82¢\82é\96ò")
129             && !(mvitals[PM_DJINNI].mvflags & G_GONE)
130             && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) {
131             if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI]))
132                 return 0;
133             mquaffmsg(mon, obj);
134             m_useup(mon, obj);
135             mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS);
136             if (!mtmp) {
137                 if (vis)
138                     pline1(empty);
139             } else {
140                 if (vis)
141 /*JP
142                     pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp));
143 */
144                     pline("\89\8c\82Ì\92\86\82©\82ç\81C%s\82ª\8c»\82í\82ê\82½\81I", a_monnam(mtmp));
145 /*JP
146                 pline("%s speaks.", vis ? Monnam(mtmp) : Something);
147 */
148                 pline("%s\82Í\98b\82µ\82½\81D", vis ? Monnam(mtmp) : Something);
149                 /* I suspect few players will be upset that monsters */
150                 /* can't wish for wands of death here.... */
151                 if (rn2(2)) {
152 /*JP
153                     verbalize("You freed me!");
154 */
155                     verbalize("\89ð\95ú\82µ\82Ä\82­\82ê\82½\82Ì\82Í\82¨\91O\82©\81I");
156                     mtmp->mpeaceful = 1;
157                     set_malign(mtmp);
158                 } else {
159 /*JP
160                     verbalize("It is about time.");
161 */
162                     verbalize("\82³\82ç\82Î\82¾\81I");
163                     if (vis)
164 /*JP
165                         pline("%s vanishes.", Monnam(mtmp));
166 */
167                         pline("%s\82Í\8fÁ\82¦\82½\81D", Monnam(mtmp));
168                     mongone(mtmp);
169                 }
170             }
171             return 2;
172         }
173     }
174     if (obj->oclass == WAND_CLASS && obj->cursed
175         && !rn2(WAND_BACKFIRE_CHANCE)) {
176         int dam = d(obj->spe + 2, 6);
177
178         if (!Deaf) {
179             if (vis)
180 #if 0 /*JP*/
181                 pline("%s zaps %s, which suddenly explodes!", Monnam(mon),
182                       an(xname(obj)));
183 #else
184                 pline("%s\82Í%s\82ð\82Ó\82è\82©\82´\82µ\82½\81C\82»\82ê\82Í\93Ë\91R\94\9a\94­\82µ\82½\81I", Monnam(mon),
185                       an(xname(obj)));
186 #endif
187             else
188 /*JP
189                 You_hear("a zap and an explosion in the distance.");
190 */
191                 You_hear("\89\93\95û\82Ì\8fñ\82Ì\89¹\82Æ\94\9a\94­\89¹\82ð\95·\82¢\82½\81D");
192         }
193         m_useup(mon, obj);
194         if (mon->mhp <= dam) {
195             monkilled(mon, "", AD_RBRE);
196             return 1;
197         } else
198             mon->mhp -= dam;
199         m.has_defense = m.has_offense = m.has_misc = 0;
200         /* Only one needed to be set to 0 but the others are harmless */
201     }
202     return 0;
203 }
204
205 STATIC_OVL void
206 mzapmsg(mtmp, otmp, self)
207 struct monst *mtmp;
208 struct obj *otmp;
209 boolean self;
210 {
211     if (!canseemon(mtmp)) {
212         if (!Deaf)
213 #if 0 /*JP*/
214             You_hear("a %s zap.", (distu(mtmp->mx, mtmp->my)
215                                    <= (BOLT_LIM + 1) * (BOLT_LIM + 1))
216                                       ? "nearby"
217                                       : "distant");
218 #else
219             You_hear("%s\82­\82Å\8fñ\82Ì\89¹\82ð\95·\82¢\82½\81D", (distu(mtmp->mx, mtmp->my)
220                                    <= (BOLT_LIM + 1) * (BOLT_LIM + 1))
221                                       ? "\8bß"
222                                       : "\89\93");
223 #endif
224     } else if (self) {
225 #if 0 /*JP*/
226         pline("%s zaps %sself with %s!", Monnam(mtmp), mhim(mtmp),
227               doname(otmp));
228 #else
229         pline("%s\82Í\8e©\95ª\8e©\90g\82É%s\82ð\82Ó\82è\82©\82´\82µ\82½\81I", Monnam(mtmp),
230               doname(otmp));
231 #endif
232     } else {
233 /*JP
234         pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp)));
235 */
236         pline("%s\82Í%s\82ð\82Ó\82è\82©\82´\82µ\82½\81I", Monnam(mtmp), an(xname(otmp)));
237         stop_occupation();
238     }
239 }
240
241 STATIC_OVL void
242 mreadmsg(mtmp, otmp)
243 struct monst *mtmp;
244 struct obj *otmp;
245 {
246     boolean vismon = canseemon(mtmp);
247     char onambuf[BUFSZ];
248     short saverole;
249     unsigned savebknown;
250
251     if (!vismon && Deaf)
252         return; /* no feedback */
253
254     otmp->dknown = 1; /* seeing or hearing it read reveals its label */
255     /* shouldn't be able to hear curse/bless status of unseen scrolls;
256        for priest characters, bknown will always be set during naming */
257     savebknown = otmp->bknown;
258     saverole = Role_switch;
259     if (!vismon) {
260         otmp->bknown = 0;
261         if (Role_if(PM_PRIEST))
262             Role_switch = 0;
263     }
264     Strcpy(onambuf, singular(otmp, doname));
265     Role_switch = saverole;
266     otmp->bknown = savebknown;
267
268     if (vismon)
269 /*JP
270         pline("%s reads %s!", Monnam(mtmp), onambuf);
271 */
272         pline("%s\82Í%s\82ð\93Ç\82ñ\82¾\81I", Monnam(mtmp), onambuf);
273     else
274 #if 0 /*JP*/
275         You_hear("%s reading %s.",
276                  x_monnam(mtmp, ARTICLE_A, (char *) 0,
277                           (SUPPRESS_IT | SUPPRESS_INVISIBLE | SUPPRESS_SADDLE),
278                           FALSE),
279                  onambuf);
280 #else
281         You_hear("%s\82ª%s\82ð\93Ç\82ñ\82Å\82¢\82é\90º\82ð\95·\82¢\82½\81D",
282                  x_monnam(mtmp, ARTICLE_A, (char *)0,
283                           (SUPPRESS_IT|SUPPRESS_INVISIBLE|SUPPRESS_SADDLE),
284                           FALSE),
285                  onambuf);
286 #endif
287
288     if (mtmp->mconf)
289 /*JP
290         pline("Being confused, %s mispronounces the magic words...",
291 */
292         pline("\8d¬\97\90\82µ\82Ä\82¢\82é\82Ì\82Å\81C%s\82Í\8eô\95\82ð\8aÔ\88á\82Á\82Ä\8f¥\82¦\82Ä\82µ\82Ü\82Á\82½\81D\81D\81D",
293               vismon ? mon_nam(mtmp) : mhe(mtmp));
294 }
295
296 STATIC_OVL void
297 mquaffmsg(mtmp, otmp)
298 struct monst *mtmp;
299 struct obj *otmp;
300 {
301     if (canseemon(mtmp)) {
302         otmp->dknown = 1;
303 /*JP
304         pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname));
305 */
306         pline("%s\82Í%s\82ð\88ù\82ñ\82¾\81I", Monnam(mtmp), singular(otmp, doname));
307     } else if (!Deaf)
308 /*JP
309         You_hear("a chugging sound.");
310 */
311         You_hear("\83S\83N\83b\81I\82Æ\82¢\82¤\89¹\82ð\95·\82¢\82½\81D");
312 }
313
314 /* Defines for various types of stuff.  The order in which monsters prefer
315  * to use them is determined by the order of the code logic, not the
316  * numerical order in which they are defined.
317  */
318 #define MUSE_SCR_TELEPORTATION 1
319 #define MUSE_WAN_TELEPORTATION_SELF 2
320 #define MUSE_POT_HEALING 3
321 #define MUSE_POT_EXTRA_HEALING 4
322 #define MUSE_WAN_DIGGING 5
323 #define MUSE_TRAPDOOR 6
324 #define MUSE_TELEPORT_TRAP 7
325 #define MUSE_UPSTAIRS 8
326 #define MUSE_DOWNSTAIRS 9
327 #define MUSE_WAN_CREATE_MONSTER 10
328 #define MUSE_SCR_CREATE_MONSTER 11
329 #define MUSE_UP_LADDER 12
330 #define MUSE_DN_LADDER 13
331 #define MUSE_SSTAIRS 14
332 #define MUSE_WAN_TELEPORTATION 15
333 #define MUSE_BUGLE 16
334 #define MUSE_UNICORN_HORN 17
335 #define MUSE_POT_FULL_HEALING 18
336 #define MUSE_LIZARD_CORPSE 19
337 /*
338 #define MUSE_INNATE_TPT 9999
339  * We cannot use this.  Since monsters get unlimited teleportation, if they
340  * were allowed to teleport at will you could never catch them.  Instead,
341  * assume they only teleport at random times, despite the inconsistency
342  * that if you polymorph into one you teleport at will.
343  */
344
345 /* Select a defensive item/action for a monster.  Returns TRUE iff one is
346    found. */
347 boolean
348 find_defensive(mtmp)
349 struct monst *mtmp;
350 {
351     register struct obj *obj = 0;
352     struct trap *t;
353     int x = mtmp->mx, y = mtmp->my;
354     boolean stuck = (mtmp == u.ustuck);
355     boolean immobile = (mtmp->data->mmove == 0);
356     int fraction;
357
358     if (is_animal(mtmp->data) || mindless(mtmp->data))
359         return FALSE;
360     if (dist2(x, y, mtmp->mux, mtmp->muy) > 25)
361         return FALSE;
362     if (u.uswallow && stuck)
363         return FALSE;
364
365     m.defensive = (struct obj *) 0;
366     m.has_defense = 0;
367
368     /* since unicorn horns don't get used up, the monster would look
369      * silly trying to use the same cursed horn round after round
370      */
371     if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) {
372         if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) {
373             for (obj = mtmp->minvent; obj; obj = obj->nobj)
374                 if (obj->otyp == UNICORN_HORN && !obj->cursed)
375                     break;
376         }
377         if (obj || is_unicorn(mtmp->data)) {
378             m.defensive = obj;
379             m.has_defense = MUSE_UNICORN_HORN;
380             return TRUE;
381         }
382     }
383
384     if (mtmp->mconf || mtmp->mstun) {
385         struct obj *liztin = 0;
386
387         for (obj = mtmp->minvent; obj; obj = obj->nobj) {
388             if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) {
389                 m.defensive = obj;
390                 m.has_defense = MUSE_LIZARD_CORPSE;
391                 return TRUE;
392             } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) {
393                 liztin = obj;
394             }
395         }
396         /* confused or stunned monster might not be able to open tin */
397         if (liztin && mcould_eat_tin(mtmp) && rn2(3)) {
398             m.defensive = liztin;
399             /* tin and corpse ultimately end up being handled the same */
400             m.has_defense = MUSE_LIZARD_CORPSE;
401             return TRUE;
402         }
403     }
404
405     /* It so happens there are two unrelated cases when we might want to
406      * check specifically for healing alone.  The first is when the monster
407      * is blind (healing cures blindness).  The second is when the monster
408      * is peaceful; then we don't want to flee the player, and by
409      * coincidence healing is all there is that doesn't involve fleeing.
410      * These would be hard to combine because of the control flow.
411      * Pestilence won't use healing even when blind.
412      */
413     if (!mtmp->mcansee && !nohands(mtmp->data)
414         && mtmp->data != &mons[PM_PESTILENCE]) {
415         if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
416             m.defensive = obj;
417             m.has_defense = MUSE_POT_FULL_HEALING;
418             return TRUE;
419         }
420         if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
421             m.defensive = obj;
422             m.has_defense = MUSE_POT_EXTRA_HEALING;
423             return TRUE;
424         }
425         if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
426             m.defensive = obj;
427             m.has_defense = MUSE_POT_HEALING;
428             return TRUE;
429         }
430     }
431
432     fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3;
433     if (mtmp->mhp >= mtmp->mhpmax
434         || (mtmp->mhp >= 10 && mtmp->mhp * fraction >= mtmp->mhpmax))
435         return FALSE;
436
437     if (mtmp->mpeaceful) {
438         if (!nohands(mtmp->data)) {
439             if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
440                 m.defensive = obj;
441                 m.has_defense = MUSE_POT_FULL_HEALING;
442                 return TRUE;
443             }
444             if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
445                 m.defensive = obj;
446                 m.has_defense = MUSE_POT_EXTRA_HEALING;
447                 return TRUE;
448             }
449             if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
450                 m.defensive = obj;
451                 m.has_defense = MUSE_POT_HEALING;
452                 return TRUE;
453             }
454         }
455         return FALSE;
456     }
457
458     if (stuck || immobile) {
459         ; /* fleeing by stairs or traps is not possible */
460     } else if (levl[x][y].typ == STAIRS) {
461         if (x == xdnstair && y == ydnstair) {
462             if (!is_floater(mtmp->data))
463                 m.has_defense = MUSE_DOWNSTAIRS;
464         } else if (x == xupstair && y == yupstair) {
465             /* don't let monster leave the dungeon with the Amulet */
466             if (ledger_no(&u.uz) != 1)
467                 m.has_defense = MUSE_UPSTAIRS;
468         } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) {
469             if (sstairs.up || !is_floater(mtmp->data))
470                 m.has_defense = MUSE_SSTAIRS;
471         }
472     } else if (levl[x][y].typ == LADDER) {
473         if (x == xupladder && y == yupladder) {
474             m.has_defense = MUSE_UP_LADDER;
475         } else if (x == xdnladder && y == ydnladder) {
476             if (!is_floater(mtmp->data))
477                 m.has_defense = MUSE_DN_LADDER;
478         } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) {
479             if (sstairs.up || !is_floater(mtmp->data))
480                 m.has_defense = MUSE_SSTAIRS;
481         }
482     } else {
483         /* Note: trap doors take precedence over teleport traps. */
484         int xx, yy, i, locs[10][2];
485         boolean ignore_boulders = (verysmall(mtmp->data)
486                                    || throws_rocks(mtmp->data)
487                                    || passes_walls(mtmp->data)),
488             diag_ok = !NODIAG(monsndx(mtmp->data));
489
490         for (i = 0; i < 10; ++i) /* 10: 9 spots plus sentinel */
491             locs[i][0] = locs[i][1] = 0;
492         /* collect viable spots; monster's <mx,my> comes first */
493         locs[0][0] = x, locs[0][1] = y;
494         i = 1;
495         for (xx = x - 1; xx <= x + 1; xx++)
496             for (yy = y - 1; yy <= y + 1; yy++)
497                 if (isok(xx, yy) && (xx != x || yy != y)) {
498                     locs[i][0] = xx, locs[i][1] = yy;
499                     ++i;
500                 }
501         /* look for a suitable trap among the viable spots */
502         for (i = 0; i < 10; ++i) {
503             xx = locs[i][0], yy = locs[i][1];
504             if (!xx)
505                 break; /* we've run out of spots */
506             /* skip if it's hero's location
507                or a diagonal spot and monster can't move diagonally
508                or some other monster is there */
509             if ((xx == u.ux && yy == u.uy)
510                 || (xx != x && yy != y && !diag_ok)
511                 || (level.monsters[xx][yy] && !(xx == x && yy == y)))
512                 continue;
513             /* skip if there's no trap or can't/won't move onto trap */
514             if ((t = t_at(xx, yy)) == 0
515                 || (!ignore_boulders && sobj_at(BOULDER, xx, yy))
516                 || onscary(xx, yy, mtmp))
517                 continue;
518             /* use trap if it's the correct type */
519             if ((t->ttyp == TRAPDOOR || t->ttyp == HOLE)
520                 && !is_floater(mtmp->data)
521                 && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
522                 && Can_fall_thru(&u.uz)) {
523                 trapx = xx;
524                 trapy = yy;
525                 m.has_defense = MUSE_TRAPDOOR;
526                 break; /* no need to look at any other spots */
527             } else if (t->ttyp == TELEP_TRAP) {
528                 trapx = xx;
529                 trapy = yy;
530                 m.has_defense = MUSE_TELEPORT_TRAP;
531             }
532         }
533     }
534
535     if (nohands(mtmp->data)) /* can't use objects */
536         goto botm;
537
538     if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE)) != 0) {
539         int xx, yy;
540         struct monst *mon;
541
542         /* Distance is arbitrary.  What we really want to do is
543          * have the soldier play the bugle when it sees or
544          * remembers soldiers nearby...
545          */
546         for (xx = x - 3; xx <= x + 3; xx++) {
547             for (yy = y - 3; yy <= y + 3; yy++) {
548                 if (!isok(xx, yy) || (xx == x && yy == y))
549                     continue;
550                 if ((mon = m_at(xx, yy)) != 0 && is_mercenary(mon->data)
551                     && mon->data != &mons[PM_GUARD]
552                     && (mon->msleeping || !mon->mcanmove)) {
553                     m.defensive = obj;
554                     m.has_defense = MUSE_BUGLE;
555                     goto toot; /* double break */
556                 }
557             }
558         }
559     toot:
560         ;
561     }
562
563     /* use immediate physical escape prior to attempting magic */
564     if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */
565         goto botm;
566
567     /* kludge to cut down on trap destruction (particularly portals) */
568     t = t_at(x, y);
569     if (t && (t->ttyp == PIT || t->ttyp == SPIKED_PIT || t->ttyp == WEB
570               || t->ttyp == BEAR_TRAP))
571         t = 0; /* ok for monster to dig here */
572
573 #define nomore(x)       if (m.has_defense == x) continue;
574     /* selection could be improved by collecting all possibilities
575        into an array and then picking one at random */
576     for (obj = mtmp->minvent; obj; obj = obj->nobj) {
577         /* don't always use the same selection pattern */
578         if (m.has_defense && !rn2(3))
579             break;
580
581         /* nomore(MUSE_WAN_DIGGING); */
582         if (m.has_defense == MUSE_WAN_DIGGING)
583             break;
584         if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t
585             && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
586             && !is_floater(mtmp->data)
587             /* monsters digging in Sokoban can ruin things */
588             && !Sokoban
589             /* digging wouldn't be effective; assume they know that */
590             && !(levl[x][y].wall_info & W_NONDIGGABLE)
591             && !(Is_botlevel(&u.uz) || In_endgame(&u.uz))
592             && !(is_ice(x, y) || is_pool(x, y) || is_lava(x, y))
593             && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER]
594                  && In_V_tower(&u.uz))) {
595             m.defensive = obj;
596             m.has_defense = MUSE_WAN_DIGGING;
597         }
598         nomore(MUSE_WAN_TELEPORTATION_SELF);
599         nomore(MUSE_WAN_TELEPORTATION);
600         if (obj->otyp == WAN_TELEPORTATION && obj->spe > 0) {
601             /* use the TELEP_TRAP bit to determine if they know
602              * about noteleport on this level or not.  Avoids
603              * ineffective re-use of teleportation.  This does
604              * mean if the monster leaves the level, they'll know
605              * about teleport traps.
606              */
607             if (!level.flags.noteleport
608                 || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) {
609                 m.defensive = obj;
610                 m.has_defense = (mon_has_amulet(mtmp))
611                                     ? MUSE_WAN_TELEPORTATION
612                                     : MUSE_WAN_TELEPORTATION_SELF;
613             }
614         }
615         nomore(MUSE_SCR_TELEPORTATION);
616         if (obj->otyp == SCR_TELEPORTATION && mtmp->mcansee
617             && haseyes(mtmp->data)
618             && (!obj->cursed || (!(mtmp->isshk && inhishop(mtmp))
619                                  && !mtmp->isgd && !mtmp->ispriest))) {
620             /* see WAN_TELEPORTATION case above */
621             if (!level.flags.noteleport
622                 || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) {
623                 m.defensive = obj;
624                 m.has_defense = MUSE_SCR_TELEPORTATION;
625             }
626         }
627
628         if (mtmp->data != &mons[PM_PESTILENCE]) {
629             nomore(MUSE_POT_FULL_HEALING);
630             if (obj->otyp == POT_FULL_HEALING) {
631                 m.defensive = obj;
632                 m.has_defense = MUSE_POT_FULL_HEALING;
633             }
634             nomore(MUSE_POT_EXTRA_HEALING);
635             if (obj->otyp == POT_EXTRA_HEALING) {
636                 m.defensive = obj;
637                 m.has_defense = MUSE_POT_EXTRA_HEALING;
638             }
639             nomore(MUSE_WAN_CREATE_MONSTER);
640             if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
641                 m.defensive = obj;
642                 m.has_defense = MUSE_WAN_CREATE_MONSTER;
643             }
644             nomore(MUSE_POT_HEALING);
645             if (obj->otyp == POT_HEALING) {
646                 m.defensive = obj;
647                 m.has_defense = MUSE_POT_HEALING;
648             }
649         } else { /* Pestilence */
650             nomore(MUSE_POT_FULL_HEALING);
651             if (obj->otyp == POT_SICKNESS) {
652                 m.defensive = obj;
653                 m.has_defense = MUSE_POT_FULL_HEALING;
654             }
655             nomore(MUSE_WAN_CREATE_MONSTER);
656             if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
657                 m.defensive = obj;
658                 m.has_defense = MUSE_WAN_CREATE_MONSTER;
659             }
660         }
661         nomore(MUSE_SCR_CREATE_MONSTER);
662         if (obj->otyp == SCR_CREATE_MONSTER) {
663             m.defensive = obj;
664             m.has_defense = MUSE_SCR_CREATE_MONSTER;
665         }
666     }
667 botm:
668     return (boolean) !!m.has_defense;
669 #undef nomore
670 }
671
672 /* Perform a defensive action for a monster.  Must be called immediately
673  * after find_defensive().  Return values are 0: did something, 1: died,
674  * 2: did something and can't attack again (i.e. teleported).
675  */
676 int
677 use_defensive(mtmp)
678 struct monst *mtmp;
679 {
680     int i, fleetim, how = 0;
681     struct obj *otmp = m.defensive;
682     boolean vis, vismon, oseen;
683 /*JP
684     const char *mcsa = "%s can see again.";
685 */
686     const char *mcsa = "%s\82Í\82Ü\82½\8c©\82¦\82é\82æ\82¤\82É\82È\82Á\82½\81D";
687
688     if ((i = precheck(mtmp, otmp)) != 0)
689         return i;
690     vis = cansee(mtmp->mx, mtmp->my);
691     vismon = canseemon(mtmp);
692     oseen = otmp && vismon;
693
694     /* when using defensive choice to run away, we want monster to avoid
695        rushing right straight back; don't override if already scared */
696     fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0;
697 #define m_flee(m)                          \
698     if (fleetim && !m->iswiz) {            \
699         monflee(m, fleetim, FALSE, FALSE); \
700     }
701
702     switch (m.has_defense) {
703     case MUSE_UNICORN_HORN:
704         if (vismon) {
705             if (otmp)
706 /*JP
707                 pline("%s uses a unicorn horn!", Monnam(mtmp));
708 */
709                 pline("%s\82Í\83\86\83j\83R\81[\83\93\82Ì\8ap\82ð\8eg\82Á\82½\81I", Monnam(mtmp));
710             else
711 /*JP
712                 pline_The("tip of %s's horn glows!", mon_nam(mtmp));
713 */
714                 pline("%s\82Ì\8ap\82Ì\90æ\92[\82ª\8bP\82¢\82½\81I", mon_nam(mtmp));
715         }
716         if (!mtmp->mcansee) {
717             mtmp->mcansee = 1;
718             mtmp->mblinded = 0;
719             if (vismon)
720                 pline(mcsa, Monnam(mtmp));
721         } else if (mtmp->mconf || mtmp->mstun) {
722             mtmp->mconf = mtmp->mstun = 0;
723             if (vismon)
724 /*JP
725                 pline("%s seems steadier now.", Monnam(mtmp));
726 */
727                 pline("%s\82Í\95½\90Ã\82ð\82Æ\82è\82à\82Ç\82µ\82½\81D", Monnam(mtmp));
728         } else
729             impossible("No need for unicorn horn?");
730         return 2;
731     case MUSE_BUGLE:
732         if (vismon)
733 /*JP
734             pline("%s plays %s!", Monnam(mtmp), doname(otmp));
735 */
736             pline("%s\82Í%s\82ð\90\81\82¢\82½\81I", Monnam(mtmp), doname(otmp));
737         else if (!Deaf)
738 /*JP
739             You_hear("a bugle playing reveille!");
740 */
741             You_hear("\8bN\8f°\83\89\83b\83p\82Ì\89¹\82ð\95·\82¢\82½\81I");
742         awaken_soldiers(mtmp);
743         return 2;
744     case MUSE_WAN_TELEPORTATION_SELF:
745         if ((mtmp->isshk && inhishop(mtmp)) || mtmp->isgd || mtmp->ispriest)
746             return 2;
747         m_flee(mtmp);
748         mzapmsg(mtmp, otmp, TRUE);
749         otmp->spe--;
750         how = WAN_TELEPORTATION;
751     mon_tele:
752         if (tele_restrict(mtmp)) { /* mysterious force... */
753             if (vismon && how)     /* mentions 'teleport' */
754                 makeknown(how);
755             /* monster learns that teleportation isn't useful here */
756             if (level.flags.noteleport)
757                 mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1));
758             return 2;
759         }
760         if ((mon_has_amulet(mtmp) || On_W_tower_level(&u.uz)) && !rn2(3)) {
761             if (vismon)
762 /*JP
763                 pline("%s seems disoriented for a moment.", Monnam(mtmp));
764 */
765                 pline("%s\82Í\88ê\8fu\95û\8cü\8a´\8ao\82ð\8e¸\82Á\82½\81D", Monnam(mtmp));
766             return 2;
767         }
768         if (oseen && how)
769             makeknown(how);
770         (void) rloc(mtmp, TRUE);
771         return 2;
772     case MUSE_WAN_TELEPORTATION:
773         zap_oseen = oseen;
774         mzapmsg(mtmp, otmp, FALSE);
775         otmp->spe--;
776         m_using = TRUE;
777         mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp);
778         /* monster learns that teleportation isn't useful here */
779         if (level.flags.noteleport)
780             mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1));
781         m_using = FALSE;
782         return 2;
783     case MUSE_SCR_TELEPORTATION: {
784         int obj_is_cursed = otmp->cursed;
785
786         if (mtmp->isshk || mtmp->isgd || mtmp->ispriest)
787             return 2;
788         m_flee(mtmp);
789         mreadmsg(mtmp, otmp);
790         m_useup(mtmp, otmp); /* otmp might be free'ed */
791         how = SCR_TELEPORTATION;
792         if (obj_is_cursed || mtmp->mconf) {
793             int nlev;
794             d_level flev;
795
796             if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) {
797                 if (vismon)
798 /*JP
799                     pline("%s seems very disoriented for a moment.",
800 */
801                     pline("%s\82Í\88ê\8fu\95û\8cü\8a´\8ao\82ð\8e¸\82Á\82½\81D",
802                           Monnam(mtmp));
803                 return 2;
804             }
805             nlev = random_teleport_level();
806             if (nlev == depth(&u.uz)) {
807                 if (vismon)
808 /*JP
809                     pline("%s shudders for a moment.", Monnam(mtmp));
810 */
811                     pline("%s\82Í\88ê\8fu\90k\82¦\82½\81D", Monnam(mtmp));
812                 return 2;
813             }
814             get_level(&flev, nlev);
815             migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM,
816                              (coord *) 0);
817             if (oseen)
818                 makeknown(SCR_TELEPORTATION);
819         } else
820             goto mon_tele;
821         return 2;
822     }
823     case MUSE_WAN_DIGGING: {
824         struct trap *ttmp;
825
826         m_flee(mtmp);
827         mzapmsg(mtmp, otmp, FALSE);
828         otmp->spe--;
829         if (oseen)
830             makeknown(WAN_DIGGING);
831         if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ)
832             || IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ)
833             || (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0)
834             || (sstairs.sx && sstairs.sx == mtmp->mx
835                 && sstairs.sy == mtmp->my)) {
836 /*JP
837             pline_The("digging ray is ineffective.");
838 */
839             pline("\8c@\8dí\8cõ\90ü\82Í\8cø\89Ê\82ª\82È\82¢\81D");
840             return 2;
841         }
842         if (!Can_dig_down(&u.uz) && !levl[mtmp->mx][mtmp->my].candig) {
843             if (canseemon(mtmp))
844 /*JP
845                 pline_The("%s here is too hard to dig in.",
846 */
847                         pline("\82±\82±\82Ì%s\82Í\8cÅ\82­\82Ä\8c@\82ê\82È\82¢\81D",
848                           surface(mtmp->mx, mtmp->my));
849             return 2;
850         }
851         ttmp = maketrap(mtmp->mx, mtmp->my, HOLE);
852         if (!ttmp)
853             return 2;
854         seetrap(ttmp);
855         if (vis) {
856 #if 0 /*JP*/
857             pline("%s has made a hole in the %s.", Monnam(mtmp),
858                   surface(mtmp->mx, mtmp->my));
859 #else
860             pline("%s\82Í%s\82É\8c\8a\82ð\8aJ\82¯\82½\81D", Monnam(mtmp),
861                   surface(mtmp->mx, mtmp->my));
862 #endif
863 #if 0 /*JP*/
864             pline("%s %s through...", Monnam(mtmp),
865                   is_flyer(mtmp->data) ? "dives" : "falls");
866 #else
867             pline("%s\82Í\92Ê\82è\94²\82¯\82Ä%s\81D\81D\81D", Monnam(mtmp),
868                   is_flyer(mtmp->data) ? "\94ò\82Ñ\82±\82ñ\82¾" : "\97\8e\82¿\82½");
869 #endif
870         } else if (!Deaf)
871 #if 0 /*JP*/
872             You_hear("%s crash through the %s.", something,
873                      surface(mtmp->mx, mtmp->my));
874 #else
875             You_hear("\89½\82©\82ª%s\82ð\92Ê\82è\94²\82¯\82Ä\97\8e\82¿\82é\89¹\82ð\95·\82¢\82½\81D\81D\81D",
876                      surface(mtmp->mx, mtmp->my));
877 #endif
878         /* we made sure that there is a level for mtmp to go to */
879         migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
880                          (coord *) 0);
881         return 2;
882     }
883     case MUSE_WAN_CREATE_MONSTER: {
884         coord cc;
885         /* pm: 0 => random, eel => aquatic, croc => amphibious */
886         struct permonst *pm =
887             !is_pool(mtmp->mx, mtmp->my)
888                 ? 0
889                 : &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
890         struct monst *mon;
891
892         if (!enexto(&cc, mtmp->mx, mtmp->my, pm))
893             return 0;
894         mzapmsg(mtmp, otmp, FALSE);
895         otmp->spe--;
896         mon = makemon((struct permonst *) 0, cc.x, cc.y, NO_MM_FLAGS);
897         if (mon && canspotmon(mon) && oseen)
898             makeknown(WAN_CREATE_MONSTER);
899         return 2;
900     }
901     case MUSE_SCR_CREATE_MONSTER: {
902         coord cc;
903         struct permonst *pm = 0, *fish = 0;
904         int cnt = 1;
905         struct monst *mon;
906         boolean known = FALSE;
907
908         if (!rn2(73))
909             cnt += rnd(4);
910         if (mtmp->mconf || otmp->cursed)
911             cnt += 12;
912         if (mtmp->mconf)
913             pm = fish = &mons[PM_ACID_BLOB];
914         else if (is_pool(mtmp->mx, mtmp->my))
915             fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
916         mreadmsg(mtmp, otmp);
917         while (cnt--) {
918             /* `fish' potentially gives bias towards water locations;
919                `pm' is what to actually create (0 => random) */
920             if (!enexto(&cc, mtmp->mx, mtmp->my, fish))
921                 break;
922             mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS);
923             if (mon && canspotmon(mon))
924                 known = TRUE;
925         }
926         /* The only case where we don't use oseen.  For wands, you
927          * have to be able to see the monster zap the wand to know
928          * what type it is.  For teleport scrolls, you have to see
929          * the monster to know it teleported.
930          */
931         if (known)
932             makeknown(SCR_CREATE_MONSTER);
933         else if (!objects[SCR_CREATE_MONSTER].oc_name_known
934                  && !objects[SCR_CREATE_MONSTER].oc_uname)
935             docall(otmp);
936         m_useup(mtmp, otmp);
937         return 2;
938     }
939     case MUSE_TRAPDOOR:
940         /* trap doors on "bottom" levels of dungeons are rock-drop
941          * trap doors, not holes in the floor.  We check here for
942          * safety.
943          */
944         if (Is_botlevel(&u.uz))
945             return 0;
946         m_flee(mtmp);
947         if (vis) {
948             struct trap *t = t_at(trapx, trapy);
949
950 #if 0 /*JP*/
951             pline("%s %s into a %s!", Monnam(mtmp),
952                   makeplural(locomotion(mtmp->data, "jump")),
953                   t->ttyp == TRAPDOOR ? "trap door" : "hole");
954 #else
955             pline("%s\82Í%s\82É%s\93ü\82Á\82½\81I", Monnam(mtmp),
956                   t->ttyp == TRAPDOOR ? "\97\8e\82µ\94à" : "\8c\8a",
957                   jconj(locomotion(mtmp->data, "\94ò\82Ô"), "\82Ä"));
958 #endif
959             if (levl[trapx][trapy].typ == SCORR) {
960                 levl[trapx][trapy].typ = CORR;
961                 unblock_point(trapx, trapy);
962             }
963             seetrap(t_at(trapx, trapy));
964         }
965
966         /*  don't use rloc_to() because worm tails must "move" */
967         remove_monster(mtmp->mx, mtmp->my);
968         newsym(mtmp->mx, mtmp->my); /* update old location */
969         place_monster(mtmp, trapx, trapy);
970         if (mtmp->wormno)
971             worm_move(mtmp);
972         newsym(trapx, trapy);
973
974         migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
975                          (coord *) 0);
976         return 2;
977     case MUSE_UPSTAIRS:
978         /* Monsters without amulets escape the dungeon and are
979          * gone for good when they leave up the up stairs.
980          * Monsters with amulets would reach the endlevel,
981          * which we cannot allow since that would leave the
982          * player stranded.
983          */
984         if (ledger_no(&u.uz) == 1) {
985             if (mon_has_special(mtmp))
986                 return 0;
987             if (vismon)
988 /*JP
989                 pline("%s escapes the dungeon!", Monnam(mtmp));
990 */
991                 pline("%s\82Í\96À\8b{\82©\82ç\93¦\91\96\82µ\82½\81I", Monnam(mtmp));
992             mongone(mtmp);
993             return 2;
994         }
995         m_flee(mtmp);
996         if (Inhell && mon_has_amulet(mtmp) && !rn2(4)
997             && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) {
998             if (vismon)
999 #if 0 /*JP*/
1000                 pline(
1001     "As %s climbs the stairs, a mysterious force momentarily surrounds %s...",
1002                       mon_nam(mtmp), mhim(mtmp));
1003 #else
1004                 pline(
1005     "%s\82ª\8aK\92i\82ð\82Ì\82Ú\82ë\82¤\82Æ\82·\82é\82Æ\8aï\96­\82È\97Í\82ª%s\82ð\82Â\82Â\82ñ\82¾\81D\81D\81D",
1006                       mon_nam(mtmp), mhim(mtmp));
1007 #endif
1008             /* simpler than for the player; this will usually be
1009                the Wizard and he'll immediately go right to the
1010                upstairs, so there's not much point in having any
1011                chance for a random position on the current level */
1012             migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
1013                              (coord *) 0);
1014         } else {
1015             if (vismon)
1016 /*JP
1017                 pline("%s escapes upstairs!", Monnam(mtmp));
1018 */
1019                 pline("%s\82Í\8aK\92i\82ð\82Ì\82Ú\82Á\82Ä\93¦\82°\82½\81I", Monnam(mtmp));
1020             migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_STAIRS_DOWN,
1021                              (coord *) 0);
1022         }
1023         return 2;
1024     case MUSE_DOWNSTAIRS:
1025         m_flee(mtmp);
1026         if (vismon)
1027 /*JP
1028             pline("%s escapes downstairs!", Monnam(mtmp));
1029 */
1030             pline("%s\82Í\8aK\92i\82ð\8d~\82è\82Ä\93¦\82°\82½\81I", Monnam(mtmp));
1031         migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_STAIRS_UP,
1032                          (coord *) 0);
1033         return 2;
1034     case MUSE_UP_LADDER:
1035         m_flee(mtmp);
1036         if (vismon)
1037 /*JP
1038             pline("%s escapes up the ladder!", Monnam(mtmp));
1039 */
1040             pline("%s\82Í\82Í\82µ\82²\82ð\82Ì\82Ú\82Á\82Ä\93¦\82°\82½\81I", Monnam(mtmp));
1041         migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_LADDER_DOWN,
1042                          (coord *) 0);
1043         return 2;
1044     case MUSE_DN_LADDER:
1045         m_flee(mtmp);
1046         if (vismon)
1047 /*JP
1048             pline("%s escapes down the ladder!", Monnam(mtmp));
1049 */
1050             pline("%s\82Í\82Í\82µ\82²\82ð\8d~\82è\82Ä\93¦\82°\82½\81I", Monnam(mtmp));
1051         migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_LADDER_UP,
1052                          (coord *) 0);
1053         return 2;
1054     case MUSE_SSTAIRS:
1055         m_flee(mtmp);
1056         if (vismon)
1057 #if 0 /*JP*/
1058             pline("%s escapes %sstairs!", Monnam(mtmp),
1059                   sstairs.up ? "up" : "down");
1060 #else
1061             pline("%s\82Í\8aK\92i\82ð%s\93¦\82°\82½\81I", Monnam(mtmp),
1062                   sstairs.up ? "\82Ì\82Ú\82Á\82Ä" : "\8d~\82è\82Ä");
1063 #endif
1064         /* going from the Valley to Castle (Stronghold) has no sstairs
1065            to target, but having sstairs.<sx,sy> == <0,0> will work the
1066            same as specifying MIGR_RANDOM when mon_arrive() eventually
1067            places the monster, so we can use MIGR_SSTAIRS unconditionally */
1068         migrate_to_level(mtmp, ledger_no(&sstairs.tolev), MIGR_SSTAIRS,
1069                          (coord *) 0);
1070         return 2;
1071     case MUSE_TELEPORT_TRAP:
1072         m_flee(mtmp);
1073         if (vis) {
1074 #if 0 /*JP*/
1075             pline("%s %s onto a teleport trap!", Monnam(mtmp),
1076                   makeplural(locomotion(mtmp->data, "jump")));
1077 #else
1078             pline("%s\82Í\8fu\8aÔ\88Ú\93®\82Ìã©\82É\94ò\82Ñ\8d\9e\82ñ\82¾\81I", Monnam(mtmp));
1079 #endif
1080             seetrap(t_at(trapx, trapy));
1081         }
1082         /*  don't use rloc_to() because worm tails must "move" */
1083         remove_monster(mtmp->mx, mtmp->my);
1084         newsym(mtmp->mx, mtmp->my); /* update old location */
1085         place_monster(mtmp, trapx, trapy);
1086         if (mtmp->wormno)
1087             worm_move(mtmp);
1088         newsym(trapx, trapy);
1089
1090         goto mon_tele;
1091     case MUSE_POT_HEALING:
1092         mquaffmsg(mtmp, otmp);
1093         i = d(6 + 2 * bcsign(otmp), 4);
1094         mtmp->mhp += i;
1095         if (mtmp->mhp > mtmp->mhpmax)
1096             mtmp->mhp = ++mtmp->mhpmax;
1097         if (!otmp->cursed && !mtmp->mcansee) {
1098             mtmp->mcansee = 1;
1099             mtmp->mblinded = 0;
1100             if (vismon)
1101                 pline(mcsa, Monnam(mtmp));
1102         }
1103         if (vismon)
1104 /*JP
1105             pline("%s looks better.", Monnam(mtmp));
1106 */
1107             pline("%s\82Í\8bC\95ª\82ª\82æ\82­\82È\82Á\82½\82æ\82¤\82¾\81D", Monnam(mtmp));
1108         if (oseen)
1109             makeknown(POT_HEALING);
1110         m_useup(mtmp, otmp);
1111         return 2;
1112     case MUSE_POT_EXTRA_HEALING:
1113         mquaffmsg(mtmp, otmp);
1114         i = d(6 + 2 * bcsign(otmp), 8);
1115         mtmp->mhp += i;
1116         if (mtmp->mhp > mtmp->mhpmax)
1117             mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2));
1118         if (!mtmp->mcansee) {
1119             mtmp->mcansee = 1;
1120             mtmp->mblinded = 0;
1121             if (vismon)
1122                 pline(mcsa, Monnam(mtmp));
1123         }
1124         if (vismon)
1125 /*JP
1126             pline("%s looks much better.", Monnam(mtmp));
1127 */
1128             pline("%s\82Í\82Æ\82Ä\82à\8bC\95ª\82ª\82æ\82­\82È\82Á\82½\82æ\82¤\82¾\81D", Monnam(mtmp));
1129         if (oseen)
1130             makeknown(POT_EXTRA_HEALING);
1131         m_useup(mtmp, otmp);
1132         return 2;
1133     case MUSE_POT_FULL_HEALING:
1134         mquaffmsg(mtmp, otmp);
1135         if (otmp->otyp == POT_SICKNESS)
1136             unbless(otmp); /* Pestilence */
1137         mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4));
1138         if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) {
1139             mtmp->mcansee = 1;
1140             mtmp->mblinded = 0;
1141             if (vismon)
1142                 pline(mcsa, Monnam(mtmp));
1143         }
1144         if (vismon)
1145 /*JP
1146             pline("%s looks completely healed.", Monnam(mtmp));
1147 */
1148             pline("%s\82Í\8a®\91S\82É\89ñ\95\9c\82µ\82½\82æ\82¤\82¾\81D", Monnam(mtmp));
1149         if (oseen)
1150             makeknown(otmp->otyp);
1151         m_useup(mtmp, otmp);
1152         return 2;
1153     case MUSE_LIZARD_CORPSE:
1154         /* not actually called for its unstoning effect */
1155         mon_consume_unstone(mtmp, otmp, FALSE, FALSE);
1156         return 2;
1157     case 0:
1158         return 0; /* i.e. an exploded wand */
1159     default:
1160         impossible("%s wanted to perform action %d?", Monnam(mtmp),
1161                    m.has_defense);
1162         break;
1163     }
1164     return 0;
1165 #undef m_flee
1166 }
1167
1168 int
1169 rnd_defensive_item(mtmp)
1170 struct monst *mtmp;
1171 {
1172     struct permonst *pm = mtmp->data;
1173     int difficulty = monstr[(monsndx(pm))];
1174     int trycnt = 0;
1175
1176     if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
1177         || pm->mlet == S_GHOST || pm->mlet == S_KOP)
1178         return 0;
1179 try_again:
1180     switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + (difficulty > 8))) {
1181     case 6:
1182     case 9:
1183         if (level.flags.noteleport && ++trycnt < 2)
1184             goto try_again;
1185         if (!rn2(3))
1186             return WAN_TELEPORTATION;
1187     /* else FALLTHRU */
1188     case 0:
1189     case 1:
1190         return SCR_TELEPORTATION;
1191     case 8:
1192     case 10:
1193         if (!rn2(3))
1194             return WAN_CREATE_MONSTER;
1195     /* else FALLTHRU */
1196     case 2:
1197         return SCR_CREATE_MONSTER;
1198     case 3:
1199         return POT_HEALING;
1200     case 4:
1201         return POT_EXTRA_HEALING;
1202     case 5:
1203         return (mtmp->data != &mons[PM_PESTILENCE]) ? POT_FULL_HEALING
1204                                                     : POT_SICKNESS;
1205     case 7:
1206         if (is_floater(pm) || mtmp->isshk || mtmp->isgd || mtmp->ispriest)
1207             return 0;
1208         else
1209             return WAN_DIGGING;
1210     }
1211     /*NOTREACHED*/
1212     return 0;
1213 }
1214
1215 #define MUSE_WAN_DEATH 1
1216 #define MUSE_WAN_SLEEP 2
1217 #define MUSE_WAN_FIRE 3
1218 #define MUSE_WAN_COLD 4
1219 #define MUSE_WAN_LIGHTNING 5
1220 #define MUSE_WAN_MAGIC_MISSILE 6
1221 #define MUSE_WAN_STRIKING 7
1222 #define MUSE_SCR_FIRE 8
1223 #define MUSE_POT_PARALYSIS 9
1224 #define MUSE_POT_BLINDNESS 10
1225 #define MUSE_POT_CONFUSION 11
1226 #define MUSE_FROST_HORN 12
1227 #define MUSE_FIRE_HORN 13
1228 #define MUSE_POT_ACID 14
1229 /*#define MUSE_WAN_TELEPORTATION 15*/
1230 #define MUSE_POT_SLEEPING 16
1231 #define MUSE_SCR_EARTH 17
1232
1233 /* Select an offensive item/action for a monster.  Returns TRUE iff one is
1234  * found.
1235  */
1236 boolean
1237 find_offensive(mtmp)
1238 struct monst *mtmp;
1239 {
1240     register struct obj *obj;
1241     boolean reflection_skip = (Reflecting && rn2(2));
1242     struct obj *helmet = which_armor(mtmp, W_ARMH);
1243
1244     m.offensive = (struct obj *) 0;
1245     m.has_offense = 0;
1246     if (mtmp->mpeaceful || is_animal(mtmp->data) || mindless(mtmp->data)
1247         || nohands(mtmp->data))
1248         return FALSE;
1249     if (u.uswallow)
1250         return FALSE;
1251     if (in_your_sanctuary(mtmp, 0, 0))
1252         return FALSE;
1253     if (dmgtype(mtmp->data, AD_HEAL)
1254         && !uwep && !uarmu && !uarm && !uarmh
1255         && !uarms && !uarmg && !uarmc && !uarmf)
1256         return FALSE;
1257     /* all offensive items require orthogonal or diagonal targetting */
1258     if (!lined_up(mtmp))
1259         return FALSE;
1260
1261 #define nomore(x)       if (m.has_offense == x) continue;
1262     /* this picks the last viable item rather than prioritizing choices */
1263     for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1264         if (!reflection_skip) {
1265             nomore(MUSE_WAN_DEATH);
1266             if (obj->otyp == WAN_DEATH && obj->spe > 0) {
1267                 m.offensive = obj;
1268                 m.has_offense = MUSE_WAN_DEATH;
1269             }
1270             nomore(MUSE_WAN_SLEEP);
1271             if (obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) {
1272                 m.offensive = obj;
1273                 m.has_offense = MUSE_WAN_SLEEP;
1274             }
1275             nomore(MUSE_WAN_FIRE);
1276             if (obj->otyp == WAN_FIRE && obj->spe > 0) {
1277                 m.offensive = obj;
1278                 m.has_offense = MUSE_WAN_FIRE;
1279             }
1280             nomore(MUSE_FIRE_HORN);
1281             if (obj->otyp == FIRE_HORN && obj->spe > 0) {
1282                 m.offensive = obj;
1283                 m.has_offense = MUSE_FIRE_HORN;
1284             }
1285             nomore(MUSE_WAN_COLD);
1286             if (obj->otyp == WAN_COLD && obj->spe > 0) {
1287                 m.offensive = obj;
1288                 m.has_offense = MUSE_WAN_COLD;
1289             }
1290             nomore(MUSE_FROST_HORN);
1291             if (obj->otyp == FROST_HORN && obj->spe > 0) {
1292                 m.offensive = obj;
1293                 m.has_offense = MUSE_FROST_HORN;
1294             }
1295             nomore(MUSE_WAN_LIGHTNING);
1296             if (obj->otyp == WAN_LIGHTNING && obj->spe > 0) {
1297                 m.offensive = obj;
1298                 m.has_offense = MUSE_WAN_LIGHTNING;
1299             }
1300             nomore(MUSE_WAN_MAGIC_MISSILE);
1301             if (obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) {
1302                 m.offensive = obj;
1303                 m.has_offense = MUSE_WAN_MAGIC_MISSILE;
1304             }
1305         }
1306         nomore(MUSE_WAN_STRIKING);
1307         if (obj->otyp == WAN_STRIKING && obj->spe > 0) {
1308             m.offensive = obj;
1309             m.has_offense = MUSE_WAN_STRIKING;
1310         }
1311         nomore(MUSE_POT_PARALYSIS);
1312         if (obj->otyp == POT_PARALYSIS && multi >= 0) {
1313             m.offensive = obj;
1314             m.has_offense = MUSE_POT_PARALYSIS;
1315         }
1316         nomore(MUSE_POT_BLINDNESS);
1317         if (obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) {
1318             m.offensive = obj;
1319             m.has_offense = MUSE_POT_BLINDNESS;
1320         }
1321         nomore(MUSE_POT_CONFUSION);
1322         if (obj->otyp == POT_CONFUSION) {
1323             m.offensive = obj;
1324             m.has_offense = MUSE_POT_CONFUSION;
1325         }
1326         nomore(MUSE_POT_SLEEPING);
1327         if (obj->otyp == POT_SLEEPING) {
1328             m.offensive = obj;
1329             m.has_offense = MUSE_POT_SLEEPING;
1330         }
1331         nomore(MUSE_POT_ACID);
1332         if (obj->otyp == POT_ACID) {
1333             m.offensive = obj;
1334             m.has_offense = MUSE_POT_ACID;
1335         }
1336         /* we can safely put this scroll here since the locations that
1337          * are in a 1 square radius are a subset of the locations that
1338          * are in wand or throwing range (in other words, always lined_up())
1339          */
1340         nomore(MUSE_SCR_EARTH);
1341         if (obj->otyp == SCR_EARTH
1342             && ((helmet && is_metallic(helmet)) || mtmp->mconf
1343                 || amorphous(mtmp->data) || passes_walls(mtmp->data)
1344                 || noncorporeal(mtmp->data) || unsolid(mtmp->data)
1345                 || !rn2(10))
1346             && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2
1347             && mtmp->mcansee && haseyes(mtmp->data)
1348             && !Is_rogue_level(&u.uz)
1349             && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
1350             m.offensive = obj;
1351             m.has_offense = MUSE_SCR_EARTH;
1352         }
1353 #if 0
1354         nomore(MUSE_SCR_FIRE);
1355         if (obj->otyp == SCR_FIRE && resists_fire(mtmp)
1356             && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2
1357             && mtmp->mcansee && haseyes(mtmp->data)) {
1358             m.offensive = obj;
1359             m.has_offense = MUSE_SCR_FIRE;
1360         }
1361 #endif /* 0 */
1362     }
1363     return (boolean) !!m.has_offense;
1364 #undef nomore
1365 }
1366
1367 STATIC_PTR
1368 int
1369 mbhitm(mtmp, otmp)
1370 register struct monst *mtmp;
1371 register struct obj *otmp;
1372 {
1373     int tmp;
1374
1375     boolean reveal_invis = FALSE;
1376     if (mtmp != &youmonst) {
1377         mtmp->msleeping = 0;
1378         if (mtmp->m_ap_type)
1379             seemimic(mtmp);
1380     }
1381     switch (otmp->otyp) {
1382     case WAN_STRIKING:
1383         reveal_invis = TRUE;
1384         if (mtmp == &youmonst) {
1385             if (zap_oseen)
1386                 makeknown(WAN_STRIKING);
1387             if (Antimagic) {
1388                 shieldeff(u.ux, u.uy);
1389 /*JP
1390                 pline("Boing!");
1391 */
1392                 pline("\83{\83C\83\93\81I");
1393             } else if (rnd(20) < 10 + u.uac) {
1394 /*JP
1395                 pline_The("wand hits you!");
1396 */
1397                 pline("\8fñ\82Í\82 \82È\82½\82É\96½\92\86\82µ\82½\81I");
1398                 tmp = d(2, 12);
1399                 if (Half_spell_damage)
1400                     tmp = (tmp + 1) / 2;
1401 /*JP
1402                 losehp(tmp, "wand", KILLED_BY_AN);
1403 */
1404                 losehp(tmp, "\8fÕ\8c\82\82Ì\8fñ\82É\82æ\82Á\82Ä", KILLED_BY_AN);
1405             } else
1406 /*JP
1407                 pline_The("wand misses you.");
1408 */
1409                 pline("\8fñ\82Í\82Í\82¸\82ê\82½\81D");
1410             stop_occupation();
1411             nomul(0);
1412         } else if (resists_magm(mtmp)) {
1413             shieldeff(mtmp->mx, mtmp->my);
1414 /*JP
1415             pline("Boing!");
1416 */
1417             pline("\83{\83C\83\93\81I");
1418         } else if (rnd(20) < 10 + find_mac(mtmp)) {
1419             tmp = d(2, 12);
1420 /*JP
1421             hit("wand", mtmp, exclam(tmp));
1422 */
1423             hit("\8fñ", mtmp, exclam(tmp));
1424             (void) resist(mtmp, otmp->oclass, tmp, TELL);
1425             if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
1426                 makeknown(WAN_STRIKING);
1427         } else {
1428 /*JP
1429             miss("wand", mtmp);
1430 */
1431             miss("\8fñ", mtmp);
1432             if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
1433                 makeknown(WAN_STRIKING);
1434         }
1435         break;
1436     case WAN_TELEPORTATION:
1437         if (mtmp == &youmonst) {
1438             if (zap_oseen)
1439                 makeknown(WAN_TELEPORTATION);
1440             tele();
1441         } else {
1442             /* for consistency with zap.c, don't identify */
1443             if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) {
1444                 if (cansee(mtmp->mx, mtmp->my))
1445 /*JP
1446                     pline("%s resists the magic!", Monnam(mtmp));
1447 */
1448                     pline("%s\82Í\96\82\96@\82ð\96h\82¢\82¾\81I", Monnam(mtmp));
1449             } else if (!tele_restrict(mtmp))
1450                 (void) rloc(mtmp, TRUE);
1451         }
1452         break;
1453     case WAN_CANCELLATION:
1454     case SPE_CANCELLATION:
1455         (void) cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE);
1456         break;
1457     }
1458     if (reveal_invis) {
1459         if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y)
1460             && !canspotmon(mtmp))
1461             map_invisible(bhitpos.x, bhitpos.y);
1462     }
1463     return 0;
1464 }
1465
1466 /* A modified bhit() for monsters.  Based on bhit() in zap.c.  Unlike
1467  * buzz(), bhit() doesn't take into account the possibility of a monster
1468  * zapping you, so we need a special function for it.  (Unless someone wants
1469  * to merge the two functions...)
1470  */
1471 STATIC_OVL void
1472 mbhit(mon, range, fhitm, fhito, obj)
1473 struct monst *mon;  /* monster shooting the wand */
1474 register int range; /* direction and range */
1475 int FDECL((*fhitm), (MONST_P, OBJ_P));
1476 int FDECL((*fhito), (OBJ_P, OBJ_P)); /* fns called when mon/obj hit */
1477 struct obj *obj;                     /* 2nd arg to fhitm/fhito */
1478 {
1479     register struct monst *mtmp;
1480     register struct obj *otmp;
1481     register uchar typ;
1482     int ddx, ddy;
1483
1484     bhitpos.x = mon->mx;
1485     bhitpos.y = mon->my;
1486     ddx = sgn(mon->mux - mon->mx);
1487     ddy = sgn(mon->muy - mon->my);
1488
1489     while (range-- > 0) {
1490         int x, y;
1491
1492         bhitpos.x += ddx;
1493         bhitpos.y += ddy;
1494         x = bhitpos.x;
1495         y = bhitpos.y;
1496
1497         if (!isok(x, y)) {
1498             bhitpos.x -= ddx;
1499             bhitpos.y -= ddy;
1500             break;
1501         }
1502         if (find_drawbridge(&x, &y))
1503             switch (obj->otyp) {
1504             case WAN_STRIKING:
1505                 destroy_drawbridge(x, y);
1506             }
1507         if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
1508             (*fhitm)(&youmonst, obj);
1509             range -= 3;
1510         } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
1511             if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp))
1512                 map_invisible(bhitpos.x, bhitpos.y);
1513             (*fhitm)(mtmp, obj);
1514             range -= 3;
1515         }
1516         /* modified by GAN to hit all objects */
1517         if (fhito) {
1518             int hitanything = 0;
1519             register struct obj *next_obj;
1520
1521             for (otmp = level.objects[bhitpos.x][bhitpos.y]; otmp;
1522                  otmp = next_obj) {
1523                 /* Fix for polymorph bug, Tim Wright */
1524                 next_obj = otmp->nexthere;
1525                 hitanything += (*fhito)(otmp, obj);
1526             }
1527             if (hitanything)
1528                 range--;
1529         }
1530         typ = levl[bhitpos.x][bhitpos.y].typ;
1531         if (IS_DOOR(typ) || typ == SDOOR) {
1532             switch (obj->otyp) {
1533             /* note: monsters don't use opening or locking magic
1534                at present, but keep these as placeholders */
1535             case WAN_OPENING:
1536             case WAN_LOCKING:
1537             case WAN_STRIKING:
1538                 if (doorlock(obj, bhitpos.x, bhitpos.y)) {
1539                     if (zap_oseen)
1540                         makeknown(obj->otyp);
1541                     /* if a shop door gets broken, add it to
1542                        the shk's fix list (no cost to player) */
1543                     if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
1544                         && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE))
1545                         add_damage(bhitpos.x, bhitpos.y, 0L);
1546                 }
1547                 break;
1548             }
1549         }
1550         if (!ZAP_POS(typ)
1551             || (IS_DOOR(typ) && (levl[bhitpos.x][bhitpos.y].doormask
1552                                  & (D_LOCKED | D_CLOSED)))) {
1553             bhitpos.x -= ddx;
1554             bhitpos.y -= ddy;
1555             break;
1556         }
1557     }
1558 }
1559
1560 /* Perform an offensive action for a monster.  Must be called immediately
1561  * after find_offensive().  Return values are same as use_defensive().
1562  */
1563 int
1564 use_offensive(mtmp)
1565 struct monst *mtmp;
1566 {
1567     int i;
1568     struct obj *otmp = m.offensive;
1569     boolean oseen;
1570
1571     /* offensive potions are not drunk, they're thrown */
1572     if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0)
1573         return i;
1574     oseen = otmp && canseemon(mtmp);
1575
1576     switch (m.has_offense) {
1577     case MUSE_WAN_DEATH:
1578     case MUSE_WAN_SLEEP:
1579     case MUSE_WAN_FIRE:
1580     case MUSE_WAN_COLD:
1581     case MUSE_WAN_LIGHTNING:
1582     case MUSE_WAN_MAGIC_MISSILE:
1583         mzapmsg(mtmp, otmp, FALSE);
1584         otmp->spe--;
1585         if (oseen)
1586             makeknown(otmp->otyp);
1587         m_using = TRUE;
1588         buzz((int) (-30 - (otmp->otyp - WAN_MAGIC_MISSILE)),
1589              (otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, mtmp->mx, mtmp->my,
1590              sgn(mtmp->mux - mtmp->mx), sgn(mtmp->muy - mtmp->my));
1591         m_using = FALSE;
1592         return (mtmp->mhp <= 0) ? 1 : 2;
1593     case MUSE_FIRE_HORN:
1594     case MUSE_FROST_HORN:
1595         if (oseen) {
1596             makeknown(otmp->otyp);
1597 /*JP
1598             pline("%s plays a %s!", Monnam(mtmp), xname(otmp));
1599 */
1600             pline("%s\82Í%s\82ð\90\81\82¢\82½\81I", Monnam(mtmp), xname(otmp));
1601         } else
1602 /*JP
1603             You_hear("a horn being played.");
1604 */
1605             You_hear("\83z\83\8b\83\93\82Ì\89¹\82ð\95·\82¢\82½\81D");
1606         otmp->spe--;
1607         m_using = TRUE;
1608         buzz(-30 - ((otmp->otyp == FROST_HORN) ? AD_COLD - 1 : AD_FIRE - 1),
1609              rn1(6, 6), mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx),
1610              sgn(mtmp->muy - mtmp->my));
1611         m_using = FALSE;
1612         return (mtmp->mhp <= 0) ? 1 : 2;
1613     case MUSE_WAN_TELEPORTATION:
1614     case MUSE_WAN_STRIKING:
1615         zap_oseen = oseen;
1616         mzapmsg(mtmp, otmp, FALSE);
1617         otmp->spe--;
1618         m_using = TRUE;
1619         mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp);
1620         m_using = FALSE;
1621         return 2;
1622     case MUSE_SCR_EARTH: {
1623         /* TODO: handle steeds */
1624         register int x, y;
1625         /* don't use monster fields after killing it */
1626         boolean confused = (mtmp->mconf ? TRUE : FALSE);
1627         int mmx = mtmp->mx, mmy = mtmp->my;
1628         boolean is_cursed = otmp->cursed;
1629
1630         mreadmsg(mtmp, otmp);
1631         /* Identify the scroll */
1632         if (canspotmon(mtmp)) {
1633 #if 0 /*JP*/
1634             pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my),
1635                       otmp->blessed ? "around" : "above", mon_nam(mtmp));
1636 #else
1637             pline("%s\82Ì%s\82Ì%s\82©\82ç\83S\83\8d\83S\83\8d\82Æ\89¹\82ª\95·\82±\82¦\82Ä\82«\82½\81D",
1638                       mon_nam(mtmp),
1639                       otmp->blessed ? "\82Ü\82í\82è" : "\90^\8fã",
1640                       ceiling(mtmp->mx, mtmp->my));
1641 #endif
1642             if (oseen)
1643                 makeknown(otmp->otyp);
1644         } else if (cansee(mtmp->mx, mtmp->my)) {
1645 /*JP
1646             pline_The("%s rumbles in the middle of nowhere!",
1647 */
1648             pline_The("\82Ç\82±\82©\82Ì%s\82©\82ç\83S\83\8d\83S\83\8d\82Æ\89¹\82ª\95·\82±\82¦\82Ä\82«\82½\81D",
1649                       ceiling(mtmp->mx, mtmp->my));
1650             if (mtmp->minvis)
1651                 map_invisible(mtmp->mx, mtmp->my);
1652             if (oseen)
1653                 makeknown(otmp->otyp);
1654         }
1655
1656         /* Loop through the surrounding squares */
1657         for (x = mmx - 1; x <= mmx + 1; x++) {
1658             for (y = mmy - 1; y <= mmy + 1; y++) {
1659                 /* Is this a suitable spot? */
1660                 if (isok(x, y) && !closed_door(x, y)
1661                     && !IS_ROCK(levl[x][y].typ) && !IS_AIR(levl[x][y].typ)
1662                     && (((x == mmx) && (y == mmy)) ? !otmp->blessed
1663                                                    : !otmp->cursed)
1664                     && (x != u.ux || y != u.uy)) {
1665                     (void) drop_boulder_on_monster(x, y, confused, FALSE);
1666                 }
1667             }
1668         }
1669         m_useup(mtmp, otmp);
1670         /* Attack the player */
1671         if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !is_cursed) {
1672             drop_boulder_on_player(confused, !is_cursed, FALSE, TRUE);
1673         }
1674
1675         return (mtmp->mhp <= 0) ? 1 : 2;
1676     }
1677 #if 0
1678     case MUSE_SCR_FIRE: {
1679         boolean vis = cansee(mtmp->mx, mtmp->my);
1680
1681         mreadmsg(mtmp, otmp);
1682         if (mtmp->mconf) {
1683             if (vis)
1684 /*JP
1685                 pline("Oh, what a pretty fire!");
1686 */
1687                 pline("\82í\82\9f\81C\82«\82ê\82¢\82È\89\8a\82¾\81I");
1688         } else {
1689             struct monst *mtmp2;
1690             int num;
1691
1692             if (vis)
1693 /*JP
1694                 pline_The("scroll erupts in a tower of flame!");
1695 */
1696                 pline("\8aª\95¨\82©\82ç\89Î\92\8c\82ª\97§\82¿\8f¸\82Á\82½\81I");
1697             shieldeff(mtmp->mx, mtmp->my);
1698 /*JP
1699             pline("%s is uninjured.", Monnam(mtmp));
1700 */
1701             pline("%s\82Í\8f\9d\82Â\82©\82È\82©\82Á\82½\81D", Monnam(mtmp));
1702             (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
1703             (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
1704             (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
1705             num = (2 * (rn1(3, 3) + 2 * bcsign(otmp)) + 1) / 3;
1706             if (Fire_resistance)
1707 /*JP
1708                 You("are not harmed.");
1709 */
1710                 You("\8f\9d\82Â\82©\82È\82©\82Á\82½\81D");
1711             burn_away_slime();
1712             if (Half_spell_damage)
1713                 num = (num + 1) / 2;
1714             else
1715 /*JP
1716                 losehp(num, "scroll of fire", KILLED_BY_AN);
1717 */
1718                 losehp(num, "\89\8a\82Ì\8aª\95¨\82Å", KILLED_BY_AN);
1719             for (mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) {
1720                 if (DEADMONSTER(mtmp2)) continue;
1721                 if (mtmp == mtmp2) continue;
1722                 if (dist2(mtmp2->mx, mtmp2->my, mtmp->mx, mtmp->my) < 3) {
1723                     if (resists_fire(mtmp2)) continue;
1724                     mtmp2->mhp -= num;
1725                     if (resists_cold(mtmp2))
1726                         mtmp2->mhp -= 3 * num;
1727                     if (mtmp2->mhp < 1) {
1728                         mondied(mtmp2);
1729                         break;
1730                     }
1731                 }
1732             }
1733         }
1734         return 2;
1735     }
1736 #endif /* 0 */
1737     case MUSE_POT_PARALYSIS:
1738     case MUSE_POT_BLINDNESS:
1739     case MUSE_POT_CONFUSION:
1740     case MUSE_POT_SLEEPING:
1741     case MUSE_POT_ACID:
1742         /* Note: this setting of dknown doesn't suffice.  A monster
1743          * which is out of sight might throw and it hits something _in_
1744          * sight, a problem not existing with wands because wand rays
1745          * are not objects.  Also set dknown in mthrowu.c.
1746          */
1747         if (cansee(mtmp->mx, mtmp->my)) {
1748             otmp->dknown = 1;
1749 /*JP
1750             pline("%s hurls %s!", Monnam(mtmp), singular(otmp, doname));
1751 */
1752             pline("%s\82Í%s\82ð\8b­\82­\93\8a\82°\82Â\82¯\82½\81I", Monnam(mtmp), singular(otmp, doname));
1753         }
1754         m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx),
1755                 sgn(mtmp->muy - mtmp->my),
1756                 distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp);
1757         return 2;
1758     case 0:
1759         return 0; /* i.e. an exploded wand */
1760     default:
1761         impossible("%s wanted to perform action %d?", Monnam(mtmp),
1762                    m.has_offense);
1763         break;
1764     }
1765     return 0;
1766 }
1767
1768 int
1769 rnd_offensive_item(mtmp)
1770 struct monst *mtmp;
1771 {
1772     struct permonst *pm = mtmp->data;
1773     int difficulty = monstr[(monsndx(pm))];
1774
1775     if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
1776         || pm->mlet == S_GHOST || pm->mlet == S_KOP)
1777         return 0;
1778     if (difficulty > 7 && !rn2(35))
1779         return WAN_DEATH;
1780     switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) {
1781     case 0: {
1782         struct obj *helmet = which_armor(mtmp, W_ARMH);
1783
1784         if ((helmet && is_metallic(helmet)) || amorphous(pm)
1785             || passes_walls(pm) || noncorporeal(pm) || unsolid(pm))
1786             return SCR_EARTH;
1787     } /* fall through */
1788     case 1:
1789         return WAN_STRIKING;
1790     case 2:
1791         return POT_ACID;
1792     case 3:
1793         return POT_CONFUSION;
1794     case 4:
1795         return POT_BLINDNESS;
1796     case 5:
1797         return POT_SLEEPING;
1798     case 6:
1799         return POT_PARALYSIS;
1800     case 7:
1801     case 8:
1802         return WAN_MAGIC_MISSILE;
1803     case 9:
1804         return WAN_SLEEP;
1805     case 10:
1806         return WAN_FIRE;
1807     case 11:
1808         return WAN_COLD;
1809     case 12:
1810         return WAN_LIGHTNING;
1811     }
1812     /*NOTREACHED*/
1813     return 0;
1814 }
1815
1816 #define MUSE_POT_GAIN_LEVEL 1
1817 #define MUSE_WAN_MAKE_INVISIBLE 2
1818 #define MUSE_POT_INVISIBILITY 3
1819 #define MUSE_POLY_TRAP 4
1820 #define MUSE_WAN_POLYMORPH 5
1821 #define MUSE_POT_SPEED 6
1822 #define MUSE_WAN_SPEED_MONSTER 7
1823 #define MUSE_BULLWHIP 8
1824 #define MUSE_POT_POLYMORPH 9
1825
1826 boolean
1827 find_misc(mtmp)
1828 struct monst *mtmp;
1829 {
1830     register struct obj *obj;
1831     struct permonst *mdat = mtmp->data;
1832     int x = mtmp->mx, y = mtmp->my;
1833     struct trap *t;
1834     int xx, yy, pmidx = NON_PM;
1835     boolean immobile = (mdat->mmove == 0);
1836     boolean stuck = (mtmp == u.ustuck);
1837
1838     m.misc = (struct obj *) 0;
1839     m.has_misc = 0;
1840     if (is_animal(mdat) || mindless(mdat))
1841         return 0;
1842     if (u.uswallow && stuck)
1843         return FALSE;
1844
1845     /* We arbitrarily limit to times when a player is nearby for the
1846      * same reason as Junior Pac-Man doesn't have energizers eaten until
1847      * you can see them...
1848      */
1849     if (dist2(x, y, mtmp->mux, mtmp->muy) > 36)
1850         return FALSE;
1851
1852     if (!stuck && !immobile && (mtmp->cham == NON_PM)
1853         && monstr[(pmidx = monsndx(mdat))] < 6) {
1854         boolean ignore_boulders = (verysmall(mdat) || throws_rocks(mdat)
1855                                    || passes_walls(mdat)),
1856             diag_ok = !NODIAG(pmidx);
1857
1858         for (xx = x - 1; xx <= x + 1; xx++)
1859             for (yy = y - 1; yy <= y + 1; yy++)
1860                 if (isok(xx, yy) && (xx != u.ux || yy != u.uy)
1861                     && (diag_ok || xx == x || yy == y)
1862                     && ((xx == x && yy == y) || !level.monsters[xx][yy]))
1863                     if ((t = t_at(xx, yy)) != 0
1864                         && (ignore_boulders || !sobj_at(BOULDER, xx, yy))
1865                         && !onscary(xx, yy, mtmp)) {
1866                         /* use trap if it's the correct type */
1867                         if (t->ttyp == POLY_TRAP) {
1868                             trapx = xx;
1869                             trapy = yy;
1870                             m.has_misc = MUSE_POLY_TRAP;
1871                             return TRUE;
1872                         }
1873                     }
1874     }
1875     if (nohands(mdat))
1876         return 0;
1877
1878 #define nomore(x)       if (m.has_misc == x) continue
1879     /*
1880      * [bug?]  Choice of item is not prioritized; the last viable one
1881      * in the monster's inventory will be chosen.
1882      * 'nomore()' is nearly worthless because it only screens checking
1883      * of duplicates when there is no alternate type in between them.
1884      */
1885     for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1886         /* Monsters shouldn't recognize cursed items; this kludge is
1887            necessary to prevent serious problems though... */
1888         if (obj->otyp == POT_GAIN_LEVEL
1889             && (!obj->cursed
1890                 || (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) {
1891             m.misc = obj;
1892             m.has_misc = MUSE_POT_GAIN_LEVEL;
1893         }
1894         nomore(MUSE_BULLWHIP);
1895         if (obj->otyp == BULLWHIP && !mtmp->mpeaceful
1896             /* the random test prevents whip-wielding
1897                monster from attempting disarm every turn */
1898             && uwep && !rn2(5) && obj == MON_WEP(mtmp)
1899             /* hero's location must be known and adjacent */
1900             && mtmp->mux == u.ux && mtmp->muy == u.uy
1901             && distu(mtmp->mx, mtmp->my) <= 2
1902             /* don't bother if it can't work (this doesn't
1903                prevent cursed weapons from being targetted) */
1904             && (canletgo(uwep, "")
1905                 || (u.twoweap && canletgo(uswapwep, "")))) {
1906             m.misc = obj;
1907             m.has_misc = MUSE_BULLWHIP;
1908         }
1909         /* Note: peaceful/tame monsters won't make themselves
1910          * invisible unless you can see them.  Not really right, but...
1911          */
1912         nomore(MUSE_WAN_MAKE_INVISIBLE);
1913         if (obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && !mtmp->minvis
1914             && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible)
1915             && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
1916             m.misc = obj;
1917             m.has_misc = MUSE_WAN_MAKE_INVISIBLE;
1918         }
1919         nomore(MUSE_POT_INVISIBILITY);
1920         if (obj->otyp == POT_INVISIBILITY && !mtmp->minvis
1921             && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible)
1922             && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
1923             m.misc = obj;
1924             m.has_misc = MUSE_POT_INVISIBILITY;
1925         }
1926         nomore(MUSE_WAN_SPEED_MONSTER);
1927         if (obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0
1928             && mtmp->mspeed != MFAST && !mtmp->isgd) {
1929             m.misc = obj;
1930             m.has_misc = MUSE_WAN_SPEED_MONSTER;
1931         }
1932         nomore(MUSE_POT_SPEED);
1933         if (obj->otyp == POT_SPEED && mtmp->mspeed != MFAST && !mtmp->isgd) {
1934             m.misc = obj;
1935             m.has_misc = MUSE_POT_SPEED;
1936         }
1937         nomore(MUSE_WAN_POLYMORPH);
1938         if (obj->otyp == WAN_POLYMORPH && obj->spe > 0
1939             && (mtmp->cham == NON_PM) && monstr[monsndx(mdat)] < 6) {
1940             m.misc = obj;
1941             m.has_misc = MUSE_WAN_POLYMORPH;
1942         }
1943         nomore(MUSE_POT_POLYMORPH);
1944         if (obj->otyp == POT_POLYMORPH && (mtmp->cham == NON_PM)
1945             && monstr[monsndx(mdat)] < 6) {
1946             m.misc = obj;
1947             m.has_misc = MUSE_POT_POLYMORPH;
1948         }
1949     }
1950     return (boolean) !!m.has_misc;
1951 #undef nomore
1952 }
1953
1954 /* type of monster to polymorph into; defaults to one suitable for the
1955    current level rather than the totally arbitrary choice of newcham() */
1956 static struct permonst *
1957 muse_newcham_mon(mon)
1958 struct monst *mon;
1959 {
1960     struct obj *m_armr;
1961
1962     if ((m_armr = which_armor(mon, W_ARM)) != 0) {
1963         if (Is_dragon_scales(m_armr))
1964             return Dragon_scales_to_pm(m_armr);
1965         else if (Is_dragon_mail(m_armr))
1966             return Dragon_mail_to_pm(m_armr);
1967     }
1968     return rndmonst();
1969 }
1970
1971 int
1972 use_misc(mtmp)
1973 struct monst *mtmp;
1974 {
1975     int i;
1976     struct obj *otmp = m.misc;
1977     boolean vis, vismon, oseen;
1978     char nambuf[BUFSZ];
1979
1980     if ((i = precheck(mtmp, otmp)) != 0)
1981         return i;
1982     vis = cansee(mtmp->mx, mtmp->my);
1983     vismon = canseemon(mtmp);
1984     oseen = otmp && vismon;
1985
1986     switch (m.has_misc) {
1987     case MUSE_POT_GAIN_LEVEL:
1988         mquaffmsg(mtmp, otmp);
1989         if (otmp->cursed) {
1990             if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) {
1991                 register int tolev = depth(&u.uz) - 1;
1992                 d_level tolevel;
1993
1994                 get_level(&tolevel, tolev);
1995                 /* insurance against future changes... */
1996                 if (on_level(&tolevel, &u.uz))
1997                     goto skipmsg;
1998                 if (vismon) {
1999 #if 0 /*JP*/
2000                     pline("%s rises up, through the %s!", Monnam(mtmp),
2001                           ceiling(mtmp->mx, mtmp->my));
2002 #else
2003                     pline("%s\82Í%s\82ð\93Ë\82«\94²\82¯\82½\81I", Monnam(mtmp),
2004                           ceiling(mtmp->mx, mtmp->my));
2005 #endif
2006                     if (!objects[POT_GAIN_LEVEL].oc_name_known
2007                         && !objects[POT_GAIN_LEVEL].oc_uname)
2008                         docall(otmp);
2009                 }
2010                 m_useup(mtmp, otmp);
2011                 migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM,
2012                                  (coord *) 0);
2013                 return 2;
2014             } else {
2015             skipmsg:
2016                 if (vismon) {
2017 /*JP
2018                     pline("%s looks uneasy.", Monnam(mtmp));
2019 */
2020                     pline("%s\82Í\95s\88À\82°\82É\8c©\82¦\82é\81D", Monnam(mtmp));
2021                     if (!objects[POT_GAIN_LEVEL].oc_name_known
2022                         && !objects[POT_GAIN_LEVEL].oc_uname)
2023                         docall(otmp);
2024                 }
2025                 m_useup(mtmp, otmp);
2026                 return 2;
2027             }
2028         }
2029         if (vismon)
2030 /*JP
2031             pline("%s seems more experienced.", Monnam(mtmp));
2032 */
2033             pline("%s\82Í\8co\8c±\82ð\90Ï\82ñ\82¾\82æ\82¤\82É\8c©\82¦\82é\81D", Monnam(mtmp));
2034         if (oseen)
2035             makeknown(POT_GAIN_LEVEL);
2036         m_useup(mtmp, otmp);
2037         if (!grow_up(mtmp, (struct monst *) 0))
2038             return 1;
2039         /* grew into genocided monster */
2040         return 2;
2041     case MUSE_WAN_MAKE_INVISIBLE:
2042     case MUSE_POT_INVISIBILITY:
2043         if (otmp->otyp == WAN_MAKE_INVISIBLE) {
2044             mzapmsg(mtmp, otmp, TRUE);
2045             otmp->spe--;
2046         } else
2047             mquaffmsg(mtmp, otmp);
2048         /* format monster's name before altering its visibility */
2049         Strcpy(nambuf, mon_nam(mtmp));
2050         mon_set_minvis(mtmp);
2051         if (vismon && mtmp->minvis) { /* was seen, now invisible */
2052             if (canspotmon(mtmp))
2053 #if 0 /*JP*/
2054                 pline("%s body takes on a %s transparency.",
2055                       upstart(s_suffix(nambuf)),
2056                       Hallucination ? "normal" : "strange");
2057 #else
2058                 pline("%s%s\82Ì\91Ì\82Í\93§\89ß\90«\82ð\82à\82Á\82½\81D",
2059                       Hallucination ? "\82 \82½\82è\82Ü\82¦\82È\82±\82Æ\82¾\82ª" : "\8aï\96­\82È\82±\82Æ\82É",
2060                       nambuf);
2061 #endif
2062             else
2063 /*JP
2064                 pline("Suddenly you cannot see %s.", nambuf);
2065 */
2066                 pline("%s\82Í\93Ë\91R\8c©\82¦\82È\82­\82È\82Á\82½\81D", nambuf);
2067             if (oseen)
2068                 makeknown(otmp->otyp);
2069         }
2070         if (otmp->otyp == POT_INVISIBILITY) {
2071             if (otmp->cursed)
2072                 you_aggravate(mtmp);
2073             m_useup(mtmp, otmp);
2074         }
2075         return 2;
2076     case MUSE_WAN_SPEED_MONSTER:
2077         mzapmsg(mtmp, otmp, TRUE);
2078         otmp->spe--;
2079         mon_adjust_speed(mtmp, 1, otmp);
2080         return 2;
2081     case MUSE_POT_SPEED:
2082         mquaffmsg(mtmp, otmp);
2083         /* note difference in potion effect due to substantially
2084            different methods of maintaining speed ratings:
2085            player's character becomes "very fast" temporarily;
2086            monster becomes "one stage faster" permanently */
2087         mon_adjust_speed(mtmp, 1, otmp);
2088         m_useup(mtmp, otmp);
2089         return 2;
2090     case MUSE_WAN_POLYMORPH:
2091         mzapmsg(mtmp, otmp, TRUE);
2092         otmp->spe--;
2093         (void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE);
2094         if (oseen)
2095             makeknown(WAN_POLYMORPH);
2096         return 2;
2097     case MUSE_POT_POLYMORPH:
2098         mquaffmsg(mtmp, otmp);
2099         if (vismon)
2100 /*JP
2101             pline("%s suddenly mutates!", Monnam(mtmp));
2102 */
2103             pline("%s\82Í\93Ë\91R\95Ï\89»\82µ\82½\81I", Monnam(mtmp));
2104         (void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE);
2105         if (oseen)
2106             makeknown(POT_POLYMORPH);
2107         m_useup(mtmp, otmp);
2108         return 2;
2109     case MUSE_POLY_TRAP:
2110         if (vismon)
2111 #if 0 /*JP*/
2112             pline("%s deliberately %s onto a polymorph trap!", Monnam(mtmp),
2113                   makeplural(locomotion(mtmp->data, "jump")));
2114 #else
2115             pline("%s\82Í\82í\82´\82Æ\95Ï\89»\82Ìã©\82É\94ò\82Ñ\82±\82ñ\82¾\81I", Monnam(mtmp));
2116 #endif
2117         if (vis)
2118             seetrap(t_at(trapx, trapy));
2119
2120         /*  don't use rloc() due to worms */
2121         remove_monster(mtmp->mx, mtmp->my);
2122         newsym(mtmp->mx, mtmp->my);
2123         place_monster(mtmp, trapx, trapy);
2124         if (mtmp->wormno)
2125             worm_move(mtmp);
2126         newsym(trapx, trapy);
2127
2128         (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
2129         return 2;
2130     case MUSE_BULLWHIP:
2131         /* attempt to disarm hero */
2132         {
2133 /*JP
2134             const char *The_whip = vismon ? "The bullwhip" : "A whip";
2135 */
2136             const char *The_whip = vismon ? "\95Ú" : "\95Ú";
2137             int where_to = rn2(4);
2138             struct obj *obj = uwep;
2139             const char *hand;
2140             char the_weapon[BUFSZ];
2141
2142             if (!obj || !canletgo(obj, "")
2143                 || (u.twoweap && canletgo(uswapwep, "") && rn2(2)))
2144                 obj = uswapwep;
2145             if (!obj)
2146                 break; /* shouldn't happen after find_misc() */
2147
2148             Strcpy(the_weapon, the(xname(obj)));
2149             hand = body_part(HAND);
2150             if (bimanual(obj))
2151                 hand = makeplural(hand);
2152
2153             if (vismon)
2154 #if 0 /*JP*/
2155                 pline("%s flicks a bullwhip towards your %s!", Monnam(mtmp),
2156                       hand);
2157 #else
2158                 pline("%s\82Í\82 \82È\82½\82Ì%s\82É\8cü\82©\82Á\82Ä\95Ú\82ð\91Å\82Á\82½\81I", Monnam(mtmp),
2159                       hand);
2160 #endif
2161             if (obj->otyp == HEAVY_IRON_BALL) {
2162 /*JP
2163                 pline("%s fails to wrap around %s.", The_whip, the_weapon);
2164 */
2165                 pline("%s\82Í%s\82É\82Í\82©\82ç\82Ý\82Â\82©\82È\82©\82Á\82½\81D", The_whip, the_weapon);
2166                 return 1;
2167             }
2168 #if 0 /*JP*/
2169             pline("%s wraps around %s you're wielding!", The_whip,
2170                   the_weapon);
2171 #else
2172             pline("%s\82Í\82 \82È\82½\82Ì\91\95\94õ\82µ\82Ä\82¢\82é%s\82É\82©\82ç\82Ý\82Â\82¢\82½\81I", The_whip,
2173                   the_weapon);
2174 #endif
2175             if (welded(obj)) {
2176 #if 0 /*JP*/
2177                 pline("%s welded to your %s%c",
2178                       !is_plural(obj) ? "It is" : "They are", hand,
2179                       !obj->bknown ? '!' : '.');
2180 #else
2181                 pline("\82µ\82©\82µ\81C\82»\82ê\82Í\82Ü\82¾\82 \82È\82½\82Ì%s\82Ì\92\86\82É\82 \82é%s",
2182                       hand,
2183                       !obj->bknown ? "\81I" : "\81D");
2184 #endif
2185                 /* obj->bknown = 1; */ /* welded() takes care of this */
2186                 where_to = 0;
2187             }
2188             if (!where_to) {
2189 #if 0 /*JP*/
2190                 pline_The("whip slips free."); /* not `The_whip' */
2191 #else
2192                 pline("\95Ú\82Í\82Ù\82Ç\82¯\82½\81D");  /* not `The_whip' */
2193 #endif
2194                 return 1;
2195             } else if (where_to == 3 && mon_hates_silver(mtmp)
2196                        && objects[obj->otyp].oc_material == SILVER) {
2197                 /* this monster won't want to catch a silver
2198                    weapon; drop it at hero's feet instead */
2199                 where_to = 2;
2200             }
2201             remove_worn_item(obj, FALSE);
2202             freeinv(obj);
2203             switch (where_to) {
2204             case 1: /* onto floor beneath mon */
2205 #if 0 /*JP*/
2206                 pline("%s yanks %s from your %s!", Monnam(mtmp), the_weapon,
2207                       hand);
2208 #else
2209                 pline("%s\82Í%s\82ð\82 \82È\82½\82Ì%s\82©\82ç\82®\82¢\82Æ\82Ð\82Á\82Ï\82Á\82½\81I", Monnam(mtmp), the_weapon,
2210                       hand);
2211 #endif
2212                 place_object(obj, mtmp->mx, mtmp->my);
2213                 break;
2214             case 2: /* onto floor beneath you */
2215 #if 0 /*JP*/
2216                 pline("%s yanks %s to the %s!", Monnam(mtmp), the_weapon,
2217                       surface(u.ux, u.uy));
2218 #else
2219                 pline("%s\82Í%s\82ð%s\82É\88ø\82«\97\8e\82µ\82½\81I", Monnam(mtmp), the_weapon,
2220                       surface(u.ux, u.uy));
2221 #endif
2222                 dropy(obj);
2223                 break;
2224             case 3: /* into mon's inventory */
2225 /*JP
2226                 pline("%s snatches %s!", Monnam(mtmp), the_weapon);
2227 */
2228                 pline("%s\82Í%s\82ð\92D\82Á\82½\81I", Monnam(mtmp), the_weapon);
2229                 (void) mpickobj(mtmp, obj);
2230                 break;
2231             }
2232             return 1;
2233         }
2234         return 0;
2235     case 0:
2236         return 0; /* i.e. an exploded wand */
2237     default:
2238         impossible("%s wanted to perform action %d?", Monnam(mtmp),
2239                    m.has_misc);
2240         break;
2241     }
2242     return 0;
2243 }
2244
2245 STATIC_OVL void
2246 you_aggravate(mtmp)
2247 struct monst *mtmp;
2248 {
2249 /*JP
2250     pline("For some reason, %s presence is known to you.",
2251 */
2252     pline("\82È\82º\82©\81C\82 \82È\82½\82Í%s\82Ì\91\8dÝ\82É\8bC\82ª\82Â\82¢\82½\81D",
2253           s_suffix(noit_mon_nam(mtmp)));
2254     cls();
2255 #ifdef CLIPPING
2256     cliparound(mtmp->mx, mtmp->my);
2257 #endif
2258     show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp));
2259     display_self();
2260 /*JP
2261     You_feel("aggravated at %s.", noit_mon_nam(mtmp));
2262 */
2263     You("%s\82É\95 \82ª\82½\82Á\82½\81D", mon_nam(mtmp));
2264     display_nhwindow(WIN_MAP, TRUE);
2265     docrt();
2266     if (unconscious()) {
2267         multi = -1;
2268 /*JP
2269         nomovemsg = "Aggravated, you are jolted into full consciousness.";
2270 */
2271         nomovemsg = "\95 \82ª\82½\82Á\82Ä\82¢\82Ä\81C\83s\83\8a\83s\83\8a\82µ\82Ä\82¢\82é\81D";
2272     }
2273     newsym(mtmp->mx, mtmp->my);
2274     if (!canspotmon(mtmp))
2275         map_invisible(mtmp->mx, mtmp->my);
2276 }
2277
2278 int
2279 rnd_misc_item(mtmp)
2280 struct monst *mtmp;
2281 {
2282     struct permonst *pm = mtmp->data;
2283     int difficulty = monstr[(monsndx(pm))];
2284
2285     if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
2286         || pm->mlet == S_GHOST || pm->mlet == S_KOP)
2287         return 0;
2288     /* Unlike other rnd_item functions, we only allow _weak_ monsters
2289      * to have this item; after all, the item will be used to strengthen
2290      * the monster and strong monsters won't use it at all...
2291      */
2292     if (difficulty < 6 && !rn2(30))
2293         return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH;
2294
2295     if (!rn2(40) && !nonliving(pm) && !is_vampshifter(mtmp))
2296         return AMULET_OF_LIFE_SAVING;
2297
2298     switch (rn2(3)) {
2299     case 0:
2300         if (mtmp->isgd)
2301             return 0;
2302         return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER;
2303     case 1:
2304         if (mtmp->mpeaceful && !See_invisible)
2305             return 0;
2306         return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE;
2307     case 2:
2308         return POT_GAIN_LEVEL;
2309     }
2310     /*NOTREACHED*/
2311     return 0;
2312 }
2313
2314 boolean
2315 searches_for_item(mon, obj)
2316 struct monst *mon;
2317 struct obj *obj;
2318 {
2319     int typ = obj->otyp;
2320
2321     if (is_animal(mon->data) || mindless(mon->data)
2322         || mon->data == &mons[PM_GHOST]) /* don't loot bones piles */
2323         return FALSE;
2324
2325     if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY)
2326         return (boolean) (!mon->minvis && !mon->invis_blkd
2327                           && !attacktype(mon->data, AT_GAZE));
2328     if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED)
2329         return (boolean) (mon->mspeed != MFAST);
2330
2331     switch (obj->oclass) {
2332     case WAND_CLASS:
2333         if (obj->spe <= 0)
2334             return FALSE;
2335         if (typ == WAN_DIGGING)
2336             return (boolean) !is_floater(mon->data);
2337         if (typ == WAN_POLYMORPH)
2338             return (boolean) (monstr[monsndx(mon->data)] < 6);
2339         if (objects[typ].oc_dir == RAY || typ == WAN_STRIKING
2340             || typ == WAN_TELEPORTATION || typ == WAN_CREATE_MONSTER)
2341             return TRUE;
2342         break;
2343     case POTION_CLASS:
2344         if (typ == POT_HEALING || typ == POT_EXTRA_HEALING
2345             || typ == POT_FULL_HEALING || typ == POT_POLYMORPH
2346             || typ == POT_GAIN_LEVEL || typ == POT_PARALYSIS
2347             || typ == POT_SLEEPING || typ == POT_ACID || typ == POT_CONFUSION)
2348             return TRUE;
2349         if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE))
2350             return TRUE;
2351         break;
2352     case SCROLL_CLASS:
2353         if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER
2354             || typ == SCR_EARTH || typ == SCR_FIRE)
2355             return TRUE;
2356         break;
2357     case AMULET_CLASS:
2358         if (typ == AMULET_OF_LIFE_SAVING)
2359             return (boolean) !(nonliving(mon->data) || is_vampshifter(mon));
2360         if (typ == AMULET_OF_REFLECTION)
2361             return TRUE;
2362         break;
2363     case TOOL_CLASS:
2364         if (typ == PICK_AXE)
2365             return (boolean) needspick(mon->data);
2366         if (typ == UNICORN_HORN)
2367             return (boolean) (!obj->cursed && !is_unicorn(mon->data));
2368         if (typ == FROST_HORN || typ == FIRE_HORN)
2369             return (obj->spe > 0);
2370         break;
2371     case FOOD_CLASS:
2372         if (typ == CORPSE)
2373             return (boolean) (((mon->misc_worn_check & W_ARMG) != 0L
2374                                && touch_petrifies(&mons[obj->corpsenm]))
2375                               || (!resists_ston(mon)
2376                                   && cures_stoning(mon, obj, FALSE)));
2377         if (typ == TIN)
2378             return (boolean) (mcould_eat_tin(mon)
2379                               && (!resists_ston(mon)
2380                                   && cures_stoning(mon, obj, TRUE)));
2381         if (typ == EGG)
2382             return (boolean) touch_petrifies(&mons[obj->corpsenm]);
2383         break;
2384     default:
2385         break;
2386     }
2387
2388     return FALSE;
2389 }
2390
2391 boolean
2392 mon_reflects(mon, str)
2393 struct monst *mon;
2394 const char *str;
2395 {
2396     struct obj *orefl = which_armor(mon, W_ARMS);
2397
2398     if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) {
2399         if (str) {
2400 /*JP
2401             pline(str, s_suffix(mon_nam(mon)), "shield");
2402 */
2403             pline(str, mon_nam(mon), "\8f\82");
2404             makeknown(SHIELD_OF_REFLECTION);
2405         }
2406         return TRUE;
2407     } else if (arti_reflects(MON_WEP(mon))) {
2408         /* due to wielded artifact weapon */
2409         if (str)
2410 /*JP
2411             pline(str, s_suffix(mon_nam(mon)), "weapon");
2412 */
2413             pline(str, mon_nam(mon), "\95\90\8aí");
2414         return TRUE;
2415     } else if ((orefl = which_armor(mon, W_AMUL))
2416                && orefl->otyp == AMULET_OF_REFLECTION) {
2417         if (str) {
2418 /*JP
2419             pline(str, s_suffix(mon_nam(mon)), "amulet");
2420 */
2421             pline(str, mon_nam(mon), "\96\82\8f\9c\82¯");
2422             makeknown(AMULET_OF_REFLECTION);
2423         }
2424         return TRUE;
2425     } else if ((orefl = which_armor(mon, W_ARM))
2426                && (orefl->otyp == SILVER_DRAGON_SCALES
2427                    || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) {
2428         if (str)
2429 /*JP
2430             pline(str, s_suffix(mon_nam(mon)), "armor");
2431 */
2432             pline(str, mon_nam(mon), "\8aZ");
2433         return TRUE;
2434     } else if (mon->data == &mons[PM_SILVER_DRAGON]
2435                || mon->data == &mons[PM_CHROMATIC_DRAGON]) {
2436         /* Silver dragons only reflect when mature; babies do not */
2437         if (str)
2438 /*JP
2439             pline(str, s_suffix(mon_nam(mon)), "scales");
2440 */
2441             pline(str, mon_nam(mon), "\97Ø");
2442         return TRUE;
2443     }
2444     return FALSE;
2445 }
2446
2447 boolean
2448 ureflects(fmt, str)
2449 const char *fmt, *str;
2450 {
2451     /* Check from outermost to innermost objects */
2452     if (EReflecting & W_ARMS) {
2453         if (fmt && str) {
2454 /*JP
2455             pline(fmt, str, "shield");
2456 */
2457             pline(fmt, str, "\8f\82");
2458             makeknown(SHIELD_OF_REFLECTION);
2459         }
2460         return TRUE;
2461     } else if (EReflecting & W_WEP) {
2462         /* Due to wielded artifact weapon */
2463         if (fmt && str)
2464 /*JP
2465             pline(fmt, str, "weapon");
2466 */
2467             pline(fmt, str, "\95\90\8aí");
2468         return TRUE;
2469     } else if (EReflecting & W_AMUL) {
2470         if (fmt && str) {
2471 /*JP
2472             pline(fmt, str, "medallion");
2473 */
2474             pline(fmt, str, "\83\81\83_\83\8a\83I\83\93");
2475             makeknown(AMULET_OF_REFLECTION);
2476         }
2477         return TRUE;
2478     } else if (EReflecting & W_ARM) {
2479         if (fmt && str)
2480 /*JP
2481             pline(fmt, str, uskin ? "luster" : "armor");
2482 */
2483             pline(fmt, str, uskin ? "\82Â\82â" : "\8aZ");
2484         return TRUE;
2485     } else if (youmonst.data == &mons[PM_SILVER_DRAGON]) {
2486         if (fmt && str)
2487 /*JP
2488             pline(fmt, str, "scales");
2489 */
2490             pline(fmt, str, "\97Ø");
2491         return TRUE;
2492     }
2493     return FALSE;
2494 }
2495
2496 /* TRUE if the monster ate something */
2497 boolean
2498 munstone(mon, by_you)
2499 struct monst *mon;
2500 boolean by_you;
2501 {
2502     struct obj *obj;
2503     boolean tinok;
2504
2505     if (resists_ston(mon))
2506         return FALSE;
2507     if (mon->meating || !mon->mcanmove || mon->msleeping)
2508         return FALSE;
2509     mon->mstrategy &= ~STRAT_WAITFORU;
2510
2511     tinok = mcould_eat_tin(mon);
2512     for (obj = mon->minvent; obj; obj = obj->nobj) {
2513         if (cures_stoning(mon, obj, tinok)) {
2514             mon_consume_unstone(mon, obj, by_you, TRUE);
2515             return TRUE;
2516         }
2517     }
2518     return FALSE;
2519 }
2520
2521 STATIC_OVL void
2522 mon_consume_unstone(mon, obj, by_you, stoning)
2523 struct monst *mon;
2524 struct obj *obj;
2525 boolean by_you;
2526 boolean stoning;
2527 {
2528     boolean vis = canseemon(mon), tinned = obj->otyp == TIN,
2529             food = obj->otyp == CORPSE || tinned,
2530             acid = obj->otyp == POT_ACID
2531                    || (food && acidic(&mons[obj->corpsenm])),
2532             lizard = food && obj->corpsenm == PM_LIZARD;
2533     int nutrit = food ? dog_nutrition(mon, obj) : 0; /* also sets meating */
2534
2535     /* give a "<mon> is slowing down" message and also remove
2536        intrinsic speed (comparable to similar effect on the hero) */
2537     if (stoning)
2538         mon_adjust_speed(mon, -3, (struct obj *) 0);
2539
2540     if (vis) {
2541         long save_quan = obj->quan;
2542
2543         obj->quan = 1L;
2544 #if 0 /*JP*/
2545         pline("%s %s %s.", Monnam(mon),
2546               (obj->oclass == POTION_CLASS)
2547                   ? "quaffs"
2548                   : (obj->otyp == TIN) ? "opens and eats the contents of"
2549                                        : "eats",
2550               distant_name(obj, doname));
2551 #else
2552         pline("%s\82Í%s\82ð%s\81D", Monnam(mon),
2553               distant_name(obj, doname),
2554               (obj->oclass == POTION_CLASS)
2555                   ? "\88ù\82ñ\82¾"
2556                   : (obj->otyp == TIN) ? "\8aJ\82¯\82Ä\92\86\90g\82ð\90H\82×\82½"
2557                                        : "\90H\82×\82½");
2558 #endif
2559         obj->quan = save_quan;
2560     } else if (!Deaf)
2561 #if 0 /*JP*/
2562         You_hear("%s.",
2563                  (obj->oclass == POTION_CLASS) ? "drinking" : "chewing");
2564 #else
2565         You_hear("%s\82Æ\82¢\82¤\89¹\82ð\95·\82¢\82½\81D",
2566                  (obj->otyp == POT_ACID) ? "\83S\83N\83\93" : "\83N\83`\83\83\83N\83`\83\83");
2567 #endif
2568
2569     m_useup(mon, obj);
2570     /* obj is now gone */
2571
2572     if (acid && !tinned && !resists_acid(mon)) {
2573         mon->mhp -= rnd(15);
2574         if (vis)
2575 /*JP
2576             pline("%s has a very bad case of stomach acid.", Monnam(mon));
2577 */
2578             pline("%s\82Í\88Ý\8e_\82Ì\92²\8eq\82ª\82Æ\82Ä\82à\88«\82¢\81D", Monnam(mon));
2579         if (mon->mhp <= 0) {
2580 /*JP
2581             pline("%s dies!", Monnam(mon));
2582 */
2583             pline("%s\82Í\8e\80\82ñ\82¾\81I", Monnam(mon));
2584             if (by_you)
2585                 xkilled(mon, 0);
2586             else
2587                 mondead(mon);
2588             return;
2589         }
2590     }
2591     if (stoning && vis) {
2592         if (Hallucination)
2593 /*JP
2594             pline("What a pity - %s just ruined a future piece of art!",
2595 */
2596             pline("\82È\82ñ\82Ä\82±\82Æ\82¾\81I%s\82Í\8c|\8fp\8dì\95i\82É\82È\82ê\82½\82©\82à\82µ\82ê\82È\82¢\82Ì\82É\81I",
2597                   mon_nam(mon));
2598         else
2599 /*JP
2600             pline("%s seems limber!", Monnam(mon));
2601 */
2602             pline("%s\82Í\91Ì\82ª\8f_\82ç\82©\82­\82È\82Á\82½\82æ\82¤\82É\8c©\82¦\82é\81I", Monnam(mon));
2603     }
2604     if (lizard && (mon->mconf || mon->mstun)) {
2605         mon->mconf = 0;
2606         mon->mstun = 0;
2607         if (vis && !is_bat(mon->data) && mon->data != &mons[PM_STALKER])
2608 /*JP
2609             pline("%s seems steadier now.", Monnam(mon));
2610 */
2611             pline("%s\82Í\82æ\82è\8fä\95v\82É\82È\82Á\82½\82æ\82¤\82¾\81D", Monnam(mon));
2612     }
2613     if (mon->mtame && !mon->isminion && nutrit > 0) {
2614         struct edog *edog = EDOG(mon);
2615
2616         if (edog->hungrytime < monstermoves)
2617             edog->hungrytime = monstermoves;
2618         edog->hungrytime += nutrit;
2619         mon->mconf = 0;
2620     }
2621     /* use up monster's next move */
2622     mon->movement -= NORMAL_SPEED;
2623     mon->mlstmv = monstermoves;
2624 }
2625
2626 /* decide whether obj can cure petrification; also used when picking up */
2627 STATIC_OVL boolean
2628 cures_stoning(mon, obj, tinok)
2629 struct monst *mon;
2630 struct obj *obj;
2631 boolean tinok;
2632 {
2633     if (obj->otyp == POT_ACID)
2634         return TRUE;
2635     if (obj->otyp != CORPSE && (obj->otyp != TIN || !tinok))
2636         return FALSE;
2637     /* corpse, or tin that mon can open */
2638     return (boolean) (obj->corpsenm == PM_LIZARD
2639                       || (acidic(&mons[obj->corpsenm])
2640                           && (obj->corpsenm != PM_GREEN_SLIME
2641                               || slimeproof(mon->data))));
2642 }
2643
2644 STATIC_OVL boolean
2645 mcould_eat_tin(mon)
2646 struct monst *mon;
2647 {
2648     struct obj *obj, *mwep;
2649     boolean welded_wep;
2650
2651     /* monkeys who manage to steal tins can't open and eat them
2652        even if they happen to also have the appropriate tool */
2653     if (is_animal(mon->data))
2654         return FALSE;
2655
2656     mwep = MON_WEP(mon);
2657     welded_wep = mwep && mwelded(mwep);
2658     /* this is different from the player; tin opener or dagger doesn't
2659        have to be wielded, and knife can be used instead of dagger */
2660     for (obj = mon->minvent; obj; obj = obj->nobj) {
2661         /* if stuck with a cursed weapon, don't check rest of inventory */
2662         if (welded_wep && obj != mwep)
2663             continue;
2664
2665         if (obj->otyp == TIN_OPENER
2666             || (obj->oclass == WEAPON_CLASS
2667                 && (objects[obj->otyp].oc_skill == P_DAGGER
2668                     || objects[obj->otyp].oc_skill == P_KNIFE)))
2669             return TRUE;
2670     }
2671     return FALSE;
2672 }
2673
2674 /* TRUE if monster does something to avoid turning into green slime */
2675 boolean
2676 munslime(mon, by_you)
2677 struct monst *mon;
2678 boolean by_you;
2679 {
2680     struct obj *obj, odummy;
2681
2682     /*
2683      * muse_unslime() gives "mon starts turning green", "mon zaps
2684      * itself with a wand of fire", and "mon's slime burns away"
2685      * messages.  Monsters who don't get any chance at that just have
2686      * (via our caller) newcham()'s "mon turns into slime" feedback.
2687      */
2688
2689     if (slimeproof(mon->data))
2690         return FALSE;
2691     if (mon->meating || !mon->mcanmove || mon->msleeping)
2692         return FALSE;
2693     mon->mstrategy &= ~STRAT_WAITFORU;
2694
2695     /* if monster can breathe fire, do so upon self; a monster who deals
2696        fire damage by biting, clawing, gazing, and especially exploding
2697        isn't able to cure itself of green slime with its own attack
2698        [possible extension: monst capable of casting high level clerical
2699        spells could toss pillar of fire at self--probably too suicidal] */
2700     if (!mon->mcan && !mon->mspec_used
2701         && attacktype_fordmg(mon->data, AT_BREA, AD_FIRE)) {
2702         odummy = zeroobj; /* otyp == STRANGE_OBJECT */
2703         return muse_unslime(mon, &odummy, by_you);
2704     }
2705
2706     for (obj = mon->minvent; obj; obj = obj->nobj)
2707         if (cures_sliming(mon, obj))
2708             return muse_unslime(mon, obj, by_you);
2709
2710     /* TODO: check for and move onto an adjacent fire trap */
2711
2712     return FALSE;
2713 }
2714
2715 /* mon uses an item--selected by caller--to burn away incipient slime */
2716 STATIC_OVL boolean
2717 muse_unslime(mon, obj, by_you)
2718 struct monst *mon;
2719 struct obj *obj;
2720 boolean by_you; /* true: if mon kills itself, hero gets credit/blame */
2721 {
2722     struct obj *odummyp;
2723     int otyp = obj->otyp, dmg;
2724     boolean vis = canseemon(mon), res = TRUE;
2725
2726     if (vis)
2727         pline("%s starts turning %s.", Monnam(mon),
2728               green_mon(mon) ? "into ooze" : hcolor(NH_GREEN));
2729     /* -4 => sliming, causes quiet loss of enhanced speed */
2730     mon_adjust_speed(mon, -4, (struct obj *) 0);
2731
2732     if (otyp == STRANGE_OBJECT) {
2733         /* monster is using fire breath on self */
2734         if (vis)
2735             pline("%s breathes fire on %sself.", Monnam(mon), mhim(mon));
2736         if (!rn2(3))
2737             mon->mspec_used = rn1(10, 5);
2738         /* -21 => monster's fire breath; 1 => # of damage dice */
2739         (void) zhitm(mon, by_you ? 21 : -21, 1, &odummyp);
2740     } else if (otyp == SCR_FIRE) {
2741         mreadmsg(mon, obj);
2742         if (mon->mconf) {
2743             if (cansee(mon->mx, mon->my))
2744                 pline("Oh, what a pretty fire!");
2745             if (vis && !objects[otyp].oc_name_known
2746                 && !objects[otyp].oc_uname)
2747                 docall(obj);
2748             m_useup(mon, obj); /* after docall() */
2749             vis = FALSE;       /* skip makeknown() below */
2750             res = FALSE;       /* failed to cure sliming */
2751         } else {
2752             m_useup(mon, obj); /* before explode() */
2753             dmg = (2 * (rn1(3, 3) + 2 * bcsign(obj)) + 1) / 3;
2754             /* -11 => monster's fireball */
2755             explode(mon->mx, mon->my, -11, dmg, SCROLL_CLASS,
2756                     /* by_you: override -11 for mon but not others */
2757                     by_you ? -EXPL_FIERY : EXPL_FIERY);
2758         }
2759     } else { /* wand/horn of fire w/ positive charge count */
2760         mzapmsg(mon, obj, TRUE);
2761         obj->spe--;
2762         /* -1 => monster's wand of fire; 2 => # of damage dice */
2763         (void) zhitm(mon, by_you ? 1 : -1, 2, &odummyp);
2764     }
2765
2766     if (vis) {
2767         if (res && mon->mhp > 0)
2768             pline("%s slime is burned away!", s_suffix(Monnam(mon)));
2769         if (otyp != STRANGE_OBJECT)
2770             makeknown(otyp);
2771     }
2772     /* use up monster's next move */
2773     mon->movement -= NORMAL_SPEED;
2774     mon->mlstmv = monstermoves;
2775     return res;
2776 }
2777
2778 /* decide whether obj can be used to cure green slime */
2779 STATIC_OVL int
2780 cures_sliming(mon, obj)
2781 struct monst *mon;
2782 struct obj *obj;
2783 {
2784     /* scroll of fire, non-empty wand or horn of fire */
2785     if (obj->otyp == SCR_FIRE)
2786         return (haseyes(mon->data) && mon->mcansee);
2787     /* hero doesn't need hands or even limbs to zap, so mon doesn't either */
2788     return ((obj->otyp == WAN_FIRE || obj->otyp == FIRE_HORN)
2789             && obj->spe > 0);
2790 }
2791
2792 /* TRUE if monster appears to be green; for active TEXTCOLOR, we go by
2793    the display color, otherwise we just pick things that seem plausibly
2794    green (which doesn't necessarily match the TEXTCOLOR categorization) */
2795 STATIC_OVL boolean
2796 green_mon(mon)
2797 struct monst *mon;
2798 {
2799     struct permonst *ptr = mon->data;
2800
2801     if (Hallucination)
2802         return FALSE;
2803 #ifdef TEXTCOLOR
2804     if (iflags.use_color)
2805         return (ptr->mcolor == CLR_GREEN || ptr->mcolor == CLR_BRIGHT_GREEN);
2806 #endif
2807     /* approximation */
2808     if (strstri(ptr->mname, "green"))
2809         return TRUE;
2810     switch (monsndx(ptr)) {
2811     case PM_FOREST_CENTAUR:
2812     case PM_GARTER_SNAKE:
2813     case PM_GECKO:
2814     case PM_GREMLIN:
2815     case PM_HOMUNCULUS:
2816     case PM_JUIBLEX:
2817     case PM_LEPRECHAUN:
2818     case PM_LICHEN:
2819     case PM_LIZARD:
2820     case PM_WOOD_NYMPH:
2821         return TRUE;
2822     default:
2823         if (is_elf(ptr) && !is_prince(ptr) && !is_lord(ptr)
2824             && ptr != &mons[PM_GREY_ELF])
2825             return TRUE;
2826         break;
2827     }
2828     return FALSE;
2829 }
2830
2831 /*muse.c*/