OSDN Git Service

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