OSDN Git Service

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