OSDN Git Service

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