OSDN Git Service

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