1 /* NetHack 3.6 muse.c $NHDT-Date: 1447987786 2015/11/20 02:49:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.68 $ */
2 /* Copyright (C) 1990 by Ken Arromdee */
3 /* NetHack may be freely redistributed. See license for details. */
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016 */
8 /* JNetHack may be freely redistributed. See license for details. */
11 * Monster item usage routines.
16 extern const int monstr[];
18 boolean m_using = FALSE;
20 /* Let monsters use magic items. Arbitrary assumptions: Monsters only use
21 * scrolls when they can see, monsters know when wands have 0 charges,
22 * monsters cannot recognize if items are cursed are not, monsters which
23 * are confused don't know not to read scrolls, etc....
26 STATIC_DCL struct permonst *FDECL(muse_newcham_mon, (struct monst *));
27 STATIC_DCL int FDECL(precheck, (struct monst *, struct obj *));
28 STATIC_DCL void FDECL(mzapmsg, (struct monst *, struct obj *, BOOLEAN_P));
29 STATIC_DCL void FDECL(mreadmsg, (struct monst *, struct obj *));
30 STATIC_DCL void FDECL(mquaffmsg, (struct monst *, struct obj *));
31 STATIC_PTR int FDECL(mbhitm, (struct monst *, struct obj *));
32 STATIC_DCL void FDECL(mbhit, (struct monst *, int,
33 int FDECL((*), (MONST_P, OBJ_P)),
34 int FDECL((*), (OBJ_P, OBJ_P)), struct obj *));
35 STATIC_DCL void FDECL(you_aggravate, (struct monst *));
36 STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *, struct obj *,
37 BOOLEAN_P, BOOLEAN_P));
38 STATIC_DCL boolean FDECL(cures_stoning, (struct monst *, struct obj *,
40 STATIC_DCL boolean FDECL(mcould_eat_tin, (struct monst *));
41 STATIC_DCL boolean FDECL(muse_unslime, (struct monst *, struct obj *,
43 STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *));
44 STATIC_DCL boolean FDECL(green_mon, (struct monst *));
46 static struct musable {
47 struct obj *offensive;
48 struct obj *defensive;
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).
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. */
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.
76 vis = cansee(mon->mx, mon->my);
78 if (obj->oclass == POTION_CLASS) {
81 static const char *empty = "The potion turns out to be empty.";
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;
87 potion_descr = OBJ_DESCR(objects[obj->otyp]);
88 if (potion_descr && !strcmp(potion_descr, "milky")) {
89 if (!(mvitals[PM_GHOST].mvflags & G_GONE)
90 && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) {
91 if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST]))
95 mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS);
103 "As %s opens the bottle, an enormous %s emerges!",
105 Hallucination ? rndmonnam(NULL)
106 : (const char *) "ghost");
109 "%s
\82ª
\95r
\82ð
\8aJ
\82¯
\82é
\82Æ
\81C
\8b\90\91å
\82È%s
\82ª
\8fo
\82Ä
\82«
\82½
\81I",
111 Hallucination ? rndmonnam(NULL)
112 : (const char *)"
\97H
\97ì");
115 pline("%s is frightened to death, and unable to move.",
117 pline("%s
\82Í
\82Ü
\82Á
\82³
\82¨
\82É
\82È
\82Á
\82Ä
\8bÁ
\82«
\81C
\93®
\82¯
\82È
\82
\82È
\82Á
\82½
\81D",
120 paralyze_monst(mon, 3);
126 if (potion_descr && !strcmp(potion_descr, "smoky")
128 if (potion_descr && !strcmp(potion_descr, "
\89\8c\82Ì
\8fo
\82Ä
\82¢
\82é
\96ò")
129 && !(mvitals[PM_DJINNI].mvflags & G_GONE)
130 && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) {
131 if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI]))
135 mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS);
142 pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp));
144 pline("
\89\8c\82Ì
\92\86\82©
\82ç
\81C%s
\82ª
\8c»
\82í
\82ê
\82½
\81I", a_monnam(mtmp));
146 pline("%s speaks.", vis ? Monnam(mtmp) : Something);
148 pline("%s
\82Í
\98b
\82µ
\82½
\81D", vis ? Monnam(mtmp) : Something);
149 /* I suspect few players will be upset that monsters */
150 /* can't wish for wands of death here.... */
153 verbalize("You freed me!");
155 verbalize("
\89ð
\95ú
\82µ
\82Ä
\82
\82ê
\82½
\82Ì
\82Í
\82¨
\91O
\82©
\81I");
160 verbalize("It is about time.");
162 verbalize("
\82³
\82ç
\82Î
\82¾
\81I");
165 pline("%s vanishes.", Monnam(mtmp));
167 pline("%s
\82Í
\8fÁ
\82¦
\82½
\81D", Monnam(mtmp));
174 if (obj->oclass == WAND_CLASS && obj->cursed
175 && !rn2(WAND_BACKFIRE_CHANCE)) {
176 int dam = d(obj->spe + 2, 6);
181 pline("%s zaps %s, which suddenly explodes!", Monnam(mon),
184 pline("%s
\82Í%s
\82ð
\82Ó
\82è
\82©
\82´
\82µ
\82½
\81C
\82»
\82ê
\82Í
\93Ë
\91R
\94\9a\94
\82µ
\82½
\81I", Monnam(mon),
189 You_hear("a zap and an explosion in the distance.");
191 You_hear("
\89\93\95û
\82Ì
\8fñ
\82Ì
\89¹
\82Æ
\94\9a\94
\89¹
\82ð
\95·
\82¢
\82½
\81D");
194 if (mon->mhp <= dam) {
195 monkilled(mon, "", AD_RBRE);
199 m.has_defense = m.has_offense = m.has_misc = 0;
200 /* Only one needed to be set to 0 but the others are harmless */
206 mzapmsg(mtmp, otmp, self)
211 if (!canseemon(mtmp)) {
214 You_hear("a %s zap.", (distu(mtmp->mx, mtmp->my)
215 <= (BOLT_LIM + 1) * (BOLT_LIM + 1))
219 You_hear("%s
\82
\82Å
\8fñ
\82Ì
\89¹
\82ð
\95·
\82¢
\82½
\81D", (distu(mtmp->mx, mtmp->my)
220 <= (BOLT_LIM + 1) * (BOLT_LIM + 1))
226 pline("%s zaps %sself with %s!", Monnam(mtmp), mhim(mtmp),
229 pline("%s
\82Í
\8e©
\95ª
\8e©
\90g
\82É%s
\82ð
\82Ó
\82è
\82©
\82´
\82µ
\82½
\81I", Monnam(mtmp),
234 pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp)));
236 pline("%s
\82Í%s
\82ð
\82Ó
\82è
\82©
\82´
\82µ
\82½
\81I", Monnam(mtmp), an(xname(otmp)));
246 boolean vismon = canseemon(mtmp);
252 return; /* no feedback */
254 otmp->dknown = 1; /* seeing or hearing it read reveals its label */
255 /* shouldn't be able to hear curse/bless status of unseen scrolls;
256 for priest characters, bknown will always be set during naming */
257 savebknown = otmp->bknown;
258 saverole = Role_switch;
261 if (Role_if(PM_PRIEST))
264 Strcpy(onambuf, singular(otmp, doname));
265 Role_switch = saverole;
266 otmp->bknown = savebknown;
270 pline("%s reads %s!", Monnam(mtmp), onambuf);
272 pline("%s
\82Í%s
\82ð
\93Ç
\82ñ
\82¾
\81I", Monnam(mtmp), onambuf);
275 You_hear("%s reading %s.",
276 x_monnam(mtmp, ARTICLE_A, (char *) 0,
277 (SUPPRESS_IT | SUPPRESS_INVISIBLE | SUPPRESS_SADDLE),
281 You_hear("%s
\82ª%s
\82ð
\93Ç
\82ñ
\82Å
\82¢
\82é
\90º
\82ð
\95·
\82¢
\82½
\81D",
282 x_monnam(mtmp, ARTICLE_A, (char *)0,
283 (SUPPRESS_IT|SUPPRESS_INVISIBLE|SUPPRESS_SADDLE),
290 pline("Being confused, %s mispronounces the magic words...",
292 pline("
\8d¬
\97\90\82µ
\82Ä
\82¢
\82é
\82Ì
\82Å
\81C%s
\82Í
\8eô
\95¶
\82ð
\8aÔ
\88á
\82Á
\82Ä
\8f¥
\82¦
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D
\81D
\81D",
293 vismon ? mon_nam(mtmp) : mhe(mtmp));
297 mquaffmsg(mtmp, otmp)
301 if (canseemon(mtmp)) {
304 pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname));
306 pline("%s
\82Í%s
\82ð
\88ù
\82ñ
\82¾
\81I", Monnam(mtmp), singular(otmp, doname));
309 You_hear("a chugging sound.");
311 You_hear("
\83S
\83N
\83b
\81I
\82Æ
\82¢
\82¤
\89¹
\82ð
\95·
\82¢
\82½
\81D");
314 /* Defines for various types of stuff. The order in which monsters prefer
315 * to use them is determined by the order of the code logic, not the
316 * numerical order in which they are defined.
318 #define MUSE_SCR_TELEPORTATION 1
319 #define MUSE_WAN_TELEPORTATION_SELF 2
320 #define MUSE_POT_HEALING 3
321 #define MUSE_POT_EXTRA_HEALING 4
322 #define MUSE_WAN_DIGGING 5
323 #define MUSE_TRAPDOOR 6
324 #define MUSE_TELEPORT_TRAP 7
325 #define MUSE_UPSTAIRS 8
326 #define MUSE_DOWNSTAIRS 9
327 #define MUSE_WAN_CREATE_MONSTER 10
328 #define MUSE_SCR_CREATE_MONSTER 11
329 #define MUSE_UP_LADDER 12
330 #define MUSE_DN_LADDER 13
331 #define MUSE_SSTAIRS 14
332 #define MUSE_WAN_TELEPORTATION 15
333 #define MUSE_BUGLE 16
334 #define MUSE_UNICORN_HORN 17
335 #define MUSE_POT_FULL_HEALING 18
336 #define MUSE_LIZARD_CORPSE 19
338 #define MUSE_INNATE_TPT 9999
339 * We cannot use this. Since monsters get unlimited teleportation, if they
340 * were allowed to teleport at will you could never catch them. Instead,
341 * assume they only teleport at random times, despite the inconsistency
342 * that if you polymorph into one you teleport at will.
345 /* Select a defensive item/action for a monster. Returns TRUE iff one is
351 register struct obj *obj = 0;
353 int x = mtmp->mx, y = mtmp->my;
354 boolean stuck = (mtmp == u.ustuck);
355 boolean immobile = (mtmp->data->mmove == 0);
358 if (is_animal(mtmp->data) || mindless(mtmp->data))
360 if (dist2(x, y, mtmp->mux, mtmp->muy) > 25)
362 if (u.uswallow && stuck)
365 m.defensive = (struct obj *) 0;
368 /* since unicorn horns don't get used up, the monster would look
369 * silly trying to use the same cursed horn round after round
371 if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) {
372 if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) {
373 for (obj = mtmp->minvent; obj; obj = obj->nobj)
374 if (obj->otyp == UNICORN_HORN && !obj->cursed)
377 if (obj || is_unicorn(mtmp->data)) {
379 m.has_defense = MUSE_UNICORN_HORN;
384 if (mtmp->mconf || mtmp->mstun) {
385 struct obj *liztin = 0;
387 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
388 if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) {
390 m.has_defense = MUSE_LIZARD_CORPSE;
392 } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) {
396 /* confused or stunned monster might not be able to open tin */
397 if (liztin && mcould_eat_tin(mtmp) && rn2(3)) {
398 m.defensive = liztin;
399 /* tin and corpse ultimately end up being handled the same */
400 m.has_defense = MUSE_LIZARD_CORPSE;
405 /* It so happens there are two unrelated cases when we might want to
406 * check specifically for healing alone. The first is when the monster
407 * is blind (healing cures blindness). The second is when the monster
408 * is peaceful; then we don't want to flee the player, and by
409 * coincidence healing is all there is that doesn't involve fleeing.
410 * These would be hard to combine because of the control flow.
411 * Pestilence won't use healing even when blind.
413 if (!mtmp->mcansee && !nohands(mtmp->data)
414 && mtmp->data != &mons[PM_PESTILENCE]) {
415 if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
417 m.has_defense = MUSE_POT_FULL_HEALING;
420 if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
422 m.has_defense = MUSE_POT_EXTRA_HEALING;
425 if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
427 m.has_defense = MUSE_POT_HEALING;
432 fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3;
433 if (mtmp->mhp >= mtmp->mhpmax
434 || (mtmp->mhp >= 10 && mtmp->mhp * fraction >= mtmp->mhpmax))
437 if (mtmp->mpeaceful) {
438 if (!nohands(mtmp->data)) {
439 if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
441 m.has_defense = MUSE_POT_FULL_HEALING;
444 if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
446 m.has_defense = MUSE_POT_EXTRA_HEALING;
449 if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
451 m.has_defense = MUSE_POT_HEALING;
458 if (stuck || immobile) {
459 ; /* fleeing by stairs or traps is not possible */
460 } else if (levl[x][y].typ == STAIRS) {
461 if (x == xdnstair && y == ydnstair) {
462 if (!is_floater(mtmp->data))
463 m.has_defense = MUSE_DOWNSTAIRS;
464 } else if (x == xupstair && y == yupstair) {
465 /* don't let monster leave the dungeon with the Amulet */
466 if (ledger_no(&u.uz) != 1)
467 m.has_defense = MUSE_UPSTAIRS;
468 } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) {
469 if (sstairs.up || !is_floater(mtmp->data))
470 m.has_defense = MUSE_SSTAIRS;
472 } else if (levl[x][y].typ == LADDER) {
473 if (x == xupladder && y == yupladder) {
474 m.has_defense = MUSE_UP_LADDER;
475 } else if (x == xdnladder && y == ydnladder) {
476 if (!is_floater(mtmp->data))
477 m.has_defense = MUSE_DN_LADDER;
478 } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) {
479 if (sstairs.up || !is_floater(mtmp->data))
480 m.has_defense = MUSE_SSTAIRS;
483 /* Note: trap doors take precedence over teleport traps. */
484 int xx, yy, i, locs[10][2];
485 boolean ignore_boulders = (verysmall(mtmp->data)
486 || throws_rocks(mtmp->data)
487 || passes_walls(mtmp->data)),
488 diag_ok = !NODIAG(monsndx(mtmp->data));
490 for (i = 0; i < 10; ++i) /* 10: 9 spots plus sentinel */
491 locs[i][0] = locs[i][1] = 0;
492 /* collect viable spots; monster's <mx,my> comes first */
493 locs[0][0] = x, locs[0][1] = y;
495 for (xx = x - 1; xx <= x + 1; xx++)
496 for (yy = y - 1; yy <= y + 1; yy++)
497 if (isok(xx, yy) && (xx != x || yy != y)) {
498 locs[i][0] = xx, locs[i][1] = yy;
501 /* look for a suitable trap among the viable spots */
502 for (i = 0; i < 10; ++i) {
503 xx = locs[i][0], yy = locs[i][1];
505 break; /* we've run out of spots */
506 /* skip if it's hero's location
507 or a diagonal spot and monster can't move diagonally
508 or some other monster is there */
509 if ((xx == u.ux && yy == u.uy)
510 || (xx != x && yy != y && !diag_ok)
511 || (level.monsters[xx][yy] && !(xx == x && yy == y)))
513 /* skip if there's no trap or can't/won't move onto trap */
514 if ((t = t_at(xx, yy)) == 0
515 || (!ignore_boulders && sobj_at(BOULDER, xx, yy))
516 || onscary(xx, yy, mtmp))
518 /* use trap if it's the correct type */
519 if ((t->ttyp == TRAPDOOR || t->ttyp == HOLE)
520 && !is_floater(mtmp->data)
521 && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
522 && Can_fall_thru(&u.uz)) {
525 m.has_defense = MUSE_TRAPDOOR;
526 break; /* no need to look at any other spots */
527 } else if (t->ttyp == TELEP_TRAP) {
530 m.has_defense = MUSE_TELEPORT_TRAP;
535 if (nohands(mtmp->data)) /* can't use objects */
538 if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE)) != 0) {
542 /* Distance is arbitrary. What we really want to do is
543 * have the soldier play the bugle when it sees or
544 * remembers soldiers nearby...
546 for (xx = x - 3; xx <= x + 3; xx++) {
547 for (yy = y - 3; yy <= y + 3; yy++) {
548 if (!isok(xx, yy) || (xx == x && yy == y))
550 if ((mon = m_at(xx, yy)) != 0 && is_mercenary(mon->data)
551 && mon->data != &mons[PM_GUARD]
552 && (mon->msleeping || !mon->mcanmove)) {
554 m.has_defense = MUSE_BUGLE;
555 goto toot; /* double break */
563 /* use immediate physical escape prior to attempting magic */
564 if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */
567 /* kludge to cut down on trap destruction (particularly portals) */
569 if (t && (t->ttyp == PIT || t->ttyp == SPIKED_PIT || t->ttyp == WEB
570 || t->ttyp == BEAR_TRAP))
571 t = 0; /* ok for monster to dig here */
573 #define nomore(x) if (m.has_defense == x) continue;
574 /* selection could be improved by collecting all possibilities
575 into an array and then picking one at random */
576 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
577 /* don't always use the same selection pattern */
578 if (m.has_defense && !rn2(3))
581 /* nomore(MUSE_WAN_DIGGING); */
582 if (m.has_defense == MUSE_WAN_DIGGING)
584 if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t
585 && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
586 && !is_floater(mtmp->data)
587 /* monsters digging in Sokoban can ruin things */
589 /* digging wouldn't be effective; assume they know that */
590 && !(levl[x][y].wall_info & W_NONDIGGABLE)
591 && !(Is_botlevel(&u.uz) || In_endgame(&u.uz))
592 && !(is_ice(x, y) || is_pool(x, y) || is_lava(x, y))
593 && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER]
594 && In_V_tower(&u.uz))) {
596 m.has_defense = MUSE_WAN_DIGGING;
598 nomore(MUSE_WAN_TELEPORTATION_SELF);
599 nomore(MUSE_WAN_TELEPORTATION);
600 if (obj->otyp == WAN_TELEPORTATION && obj->spe > 0) {
601 /* use the TELEP_TRAP bit to determine if they know
602 * about noteleport on this level or not. Avoids
603 * ineffective re-use of teleportation. This does
604 * mean if the monster leaves the level, they'll know
605 * about teleport traps.
607 if (!level.flags.noteleport
608 || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) {
610 m.has_defense = (mon_has_amulet(mtmp))
611 ? MUSE_WAN_TELEPORTATION
612 : MUSE_WAN_TELEPORTATION_SELF;
615 nomore(MUSE_SCR_TELEPORTATION);
616 if (obj->otyp == SCR_TELEPORTATION && mtmp->mcansee
617 && haseyes(mtmp->data)
618 && (!obj->cursed || (!(mtmp->isshk && inhishop(mtmp))
619 && !mtmp->isgd && !mtmp->ispriest))) {
620 /* see WAN_TELEPORTATION case above */
621 if (!level.flags.noteleport
622 || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) {
624 m.has_defense = MUSE_SCR_TELEPORTATION;
628 if (mtmp->data != &mons[PM_PESTILENCE]) {
629 nomore(MUSE_POT_FULL_HEALING);
630 if (obj->otyp == POT_FULL_HEALING) {
632 m.has_defense = MUSE_POT_FULL_HEALING;
634 nomore(MUSE_POT_EXTRA_HEALING);
635 if (obj->otyp == POT_EXTRA_HEALING) {
637 m.has_defense = MUSE_POT_EXTRA_HEALING;
639 nomore(MUSE_WAN_CREATE_MONSTER);
640 if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
642 m.has_defense = MUSE_WAN_CREATE_MONSTER;
644 nomore(MUSE_POT_HEALING);
645 if (obj->otyp == POT_HEALING) {
647 m.has_defense = MUSE_POT_HEALING;
649 } else { /* Pestilence */
650 nomore(MUSE_POT_FULL_HEALING);
651 if (obj->otyp == POT_SICKNESS) {
653 m.has_defense = MUSE_POT_FULL_HEALING;
655 nomore(MUSE_WAN_CREATE_MONSTER);
656 if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
658 m.has_defense = MUSE_WAN_CREATE_MONSTER;
661 nomore(MUSE_SCR_CREATE_MONSTER);
662 if (obj->otyp == SCR_CREATE_MONSTER) {
664 m.has_defense = MUSE_SCR_CREATE_MONSTER;
668 return (boolean) !!m.has_defense;
672 /* Perform a defensive action for a monster. Must be called immediately
673 * after find_defensive(). Return values are 0: did something, 1: died,
674 * 2: did something and can't attack again (i.e. teleported).
680 int i, fleetim, how = 0;
681 struct obj *otmp = m.defensive;
682 boolean vis, vismon, oseen;
684 const char *mcsa = "%s can see again.";
686 const char *mcsa = "%s
\82Í
\82Ü
\82½
\8c©
\82¦
\82é
\82æ
\82¤
\82É
\82È
\82Á
\82½
\81D";
688 if ((i = precheck(mtmp, otmp)) != 0)
690 vis = cansee(mtmp->mx, mtmp->my);
691 vismon = canseemon(mtmp);
692 oseen = otmp && vismon;
694 /* when using defensive choice to run away, we want monster to avoid
695 rushing right straight back; don't override if already scared */
696 fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0;
698 if (fleetim && !m->iswiz) { \
699 monflee(m, fleetim, FALSE, FALSE); \
702 switch (m.has_defense) {
703 case MUSE_UNICORN_HORN:
707 pline("%s uses a unicorn horn!", Monnam(mtmp));
709 pline("%s
\82Í
\83\86\83j
\83R
\81[
\83\93\82Ì
\8ap
\82ð
\8eg
\82Á
\82½
\81I", Monnam(mtmp));
712 pline_The("tip of %s's horn glows!", mon_nam(mtmp));
714 pline("%s
\82Ì
\8ap
\82Ì
\90æ
\92[
\82ª
\8bP
\82¢
\82½
\81I", mon_nam(mtmp));
716 if (!mtmp->mcansee) {
720 pline(mcsa, Monnam(mtmp));
721 } else if (mtmp->mconf || mtmp->mstun) {
722 mtmp->mconf = mtmp->mstun = 0;
725 pline("%s seems steadier now.", Monnam(mtmp));
727 pline("%s
\82Í
\95½
\90Ã
\82ð
\82Æ
\82è
\82à
\82Ç
\82µ
\82½
\81D", Monnam(mtmp));
729 impossible("No need for unicorn horn?");
734 pline("%s plays %s!", Monnam(mtmp), doname(otmp));
736 pline("%s
\82Í%s
\82ð
\90\81\82¢
\82½
\81I", Monnam(mtmp), doname(otmp));
739 You_hear("a bugle playing reveille!");
741 You_hear("
\8bN
\8f°
\83\89\83b
\83p
\82Ì
\89¹
\82ð
\95·
\82¢
\82½
\81I");
742 awaken_soldiers(mtmp);
744 case MUSE_WAN_TELEPORTATION_SELF:
745 if ((mtmp->isshk && inhishop(mtmp)) || mtmp->isgd || mtmp->ispriest)
748 mzapmsg(mtmp, otmp, TRUE);
750 how = WAN_TELEPORTATION;
752 if (tele_restrict(mtmp)) { /* mysterious force... */
753 if (vismon && how) /* mentions 'teleport' */
755 /* monster learns that teleportation isn't useful here */
756 if (level.flags.noteleport)
757 mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1));
760 if ((mon_has_amulet(mtmp) || On_W_tower_level(&u.uz)) && !rn2(3)) {
763 pline("%s seems disoriented for a moment.", Monnam(mtmp));
765 pline("%s
\82Í
\88ê
\8fu
\95û
\8cü
\8a´
\8ao
\82ð
\8e¸
\82Á
\82½
\81D", Monnam(mtmp));
770 (void) rloc(mtmp, TRUE);
772 case MUSE_WAN_TELEPORTATION:
774 mzapmsg(mtmp, otmp, FALSE);
777 mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp);
778 /* monster learns that teleportation isn't useful here */
779 if (level.flags.noteleport)
780 mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1));
783 case MUSE_SCR_TELEPORTATION: {
784 int obj_is_cursed = otmp->cursed;
786 if (mtmp->isshk || mtmp->isgd || mtmp->ispriest)
789 mreadmsg(mtmp, otmp);
790 m_useup(mtmp, otmp); /* otmp might be free'ed */
791 how = SCR_TELEPORTATION;
792 if (obj_is_cursed || mtmp->mconf) {
796 if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) {
799 pline("%s seems very disoriented for a moment.",
801 pline("%s
\82Í
\88ê
\8fu
\95û
\8cü
\8a´
\8ao
\82ð
\8e¸
\82Á
\82½
\81D",
805 nlev = random_teleport_level();
806 if (nlev == depth(&u.uz)) {
809 pline("%s shudders for a moment.", Monnam(mtmp));
811 pline("%s
\82Í
\88ê
\8fu
\90k
\82¦
\82½
\81D", Monnam(mtmp));
814 get_level(&flev, nlev);
815 migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM,
818 makeknown(SCR_TELEPORTATION);
823 case MUSE_WAN_DIGGING: {
827 mzapmsg(mtmp, otmp, FALSE);
830 makeknown(WAN_DIGGING);
831 if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ)
832 || IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ)
833 || (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0)
834 || (sstairs.sx && sstairs.sx == mtmp->mx
835 && sstairs.sy == mtmp->my)) {
837 pline_The("digging ray is ineffective.");
839 pline("
\8c@
\8dí
\8cõ
\90ü
\82Í
\8cø
\89Ê
\82ª
\82È
\82¢
\81D");
842 if (!Can_dig_down(&u.uz) && !levl[mtmp->mx][mtmp->my].candig) {
845 pline_The("%s here is too hard to dig in.",
847 pline("
\82±
\82±
\82Ì%s
\82Í
\8cÅ
\82
\82Ä
\8c@
\82ê
\82È
\82¢
\81D",
848 surface(mtmp->mx, mtmp->my));
851 ttmp = maketrap(mtmp->mx, mtmp->my, HOLE);
857 pline("%s has made a hole in the %s.", Monnam(mtmp),
858 surface(mtmp->mx, mtmp->my));
860 pline("%s
\82Í%s
\82É
\8c\8a\82ð
\8aJ
\82¯
\82½
\81D", Monnam(mtmp),
861 surface(mtmp->mx, mtmp->my));
864 pline("%s %s through...", Monnam(mtmp),
865 is_flyer(mtmp->data) ? "dives" : "falls");
867 pline("%s
\82Í
\92Ê
\82è
\94²
\82¯
\82Ä%s
\81D
\81D
\81D", Monnam(mtmp),
868 is_flyer(mtmp->data) ? "
\94ò
\82Ñ
\82±
\82ñ
\82¾" : "
\97\8e\82¿
\82½");
872 You_hear("%s crash through the %s.", something,
873 surface(mtmp->mx, mtmp->my));
875 You_hear("
\89½
\82©
\82ª%s
\82ð
\92Ê
\82è
\94²
\82¯
\82Ä
\97\8e\82¿
\82é
\89¹
\82ð
\95·
\82¢
\82½
\81D
\81D
\81D",
876 surface(mtmp->mx, mtmp->my));
878 /* we made sure that there is a level for mtmp to go to */
879 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
883 case MUSE_WAN_CREATE_MONSTER: {
885 /* pm: 0 => random, eel => aquatic, croc => amphibious */
886 struct permonst *pm =
887 !is_pool(mtmp->mx, mtmp->my)
889 : &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
892 if (!enexto(&cc, mtmp->mx, mtmp->my, pm))
894 mzapmsg(mtmp, otmp, FALSE);
896 mon = makemon((struct permonst *) 0, cc.x, cc.y, NO_MM_FLAGS);
897 if (mon && canspotmon(mon) && oseen)
898 makeknown(WAN_CREATE_MONSTER);
901 case MUSE_SCR_CREATE_MONSTER: {
903 struct permonst *pm = 0, *fish = 0;
906 boolean known = FALSE;
910 if (mtmp->mconf || otmp->cursed)
913 pm = fish = &mons[PM_ACID_BLOB];
914 else if (is_pool(mtmp->mx, mtmp->my))
915 fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
916 mreadmsg(mtmp, otmp);
918 /* `fish' potentially gives bias towards water locations;
919 `pm' is what to actually create (0 => random) */
920 if (!enexto(&cc, mtmp->mx, mtmp->my, fish))
922 mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS);
923 if (mon && canspotmon(mon))
926 /* The only case where we don't use oseen. For wands, you
927 * have to be able to see the monster zap the wand to know
928 * what type it is. For teleport scrolls, you have to see
929 * the monster to know it teleported.
932 makeknown(SCR_CREATE_MONSTER);
933 else if (!objects[SCR_CREATE_MONSTER].oc_name_known
934 && !objects[SCR_CREATE_MONSTER].oc_uname)
940 /* trap doors on "bottom" levels of dungeons are rock-drop
941 * trap doors, not holes in the floor. We check here for
944 if (Is_botlevel(&u.uz))
948 struct trap *t = t_at(trapx, trapy);
951 pline("%s %s into a %s!", Monnam(mtmp),
952 makeplural(locomotion(mtmp->data, "jump")),
953 t->ttyp == TRAPDOOR ? "trap door" : "hole");
955 pline("%s
\82Í%s
\82É%s
\93ü
\82Á
\82½
\81I", Monnam(mtmp),
956 t->ttyp == TRAPDOOR ? "
\97\8e\82µ
\94à" : "
\8c\8a",
957 jconj(locomotion(mtmp->data, "
\94ò
\82Ô"), "
\82Ä"));
959 if (levl[trapx][trapy].typ == SCORR) {
960 levl[trapx][trapy].typ = CORR;
961 unblock_point(trapx, trapy);
963 seetrap(t_at(trapx, trapy));
966 /* don't use rloc_to() because worm tails must "move" */
967 remove_monster(mtmp->mx, mtmp->my);
968 newsym(mtmp->mx, mtmp->my); /* update old location */
969 place_monster(mtmp, trapx, trapy);
972 newsym(trapx, trapy);
974 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
978 /* Monsters without amulets escape the dungeon and are
979 * gone for good when they leave up the up stairs.
980 * Monsters with amulets would reach the endlevel,
981 * which we cannot allow since that would leave the
984 if (ledger_no(&u.uz) == 1) {
985 if (mon_has_special(mtmp))
989 pline("%s escapes the dungeon!", Monnam(mtmp));
991 pline("%s
\82Í
\96À
\8b{
\82©
\82ç
\93¦
\91\96\82µ
\82½
\81I", Monnam(mtmp));
996 if (Inhell && mon_has_amulet(mtmp) && !rn2(4)
997 && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) {
1001 "As %s climbs the stairs, a mysterious force momentarily surrounds %s...",
1002 mon_nam(mtmp), mhim(mtmp));
1005 "%s
\82ª
\8aK
\92i
\82ð
\82Ì
\82Ú
\82ë
\82¤
\82Æ
\82·
\82é
\82Æ
\8aï
\96
\82È
\97Í
\82ª%s
\82ð
\82Â
\82Â
\82ñ
\82¾
\81D
\81D
\81D",
1006 mon_nam(mtmp), mhim(mtmp));
1008 /* simpler than for the player; this will usually be
1009 the Wizard and he'll immediately go right to the
1010 upstairs, so there's not much point in having any
1011 chance for a random position on the current level */
1012 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
1017 pline("%s escapes upstairs!", Monnam(mtmp));
1019 pline("%s
\82Í
\8aK
\92i
\82ð
\82Ì
\82Ú
\82Á
\82Ä
\93¦
\82°
\82½
\81I", Monnam(mtmp));
1020 migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_STAIRS_DOWN,
1024 case MUSE_DOWNSTAIRS:
1028 pline("%s escapes downstairs!", Monnam(mtmp));
1030 pline("%s
\82Í
\8aK
\92i
\82ð
\8d~
\82è
\82Ä
\93¦
\82°
\82½
\81I", Monnam(mtmp));
1031 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_STAIRS_UP,
1034 case MUSE_UP_LADDER:
1038 pline("%s escapes up the ladder!", Monnam(mtmp));
1040 pline("%s
\82Í
\82Í
\82µ
\82²
\82ð
\82Ì
\82Ú
\82Á
\82Ä
\93¦
\82°
\82½
\81I", Monnam(mtmp));
1041 migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_LADDER_DOWN,
1044 case MUSE_DN_LADDER:
1048 pline("%s escapes down the ladder!", Monnam(mtmp));
1050 pline("%s
\82Í
\82Í
\82µ
\82²
\82ð
\8d~
\82è
\82Ä
\93¦
\82°
\82½
\81I", Monnam(mtmp));
1051 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_LADDER_UP,
1058 pline("%s escapes %sstairs!", Monnam(mtmp),
1059 sstairs.up ? "up" : "down");
1061 pline("%s
\82Í
\8aK
\92i
\82ð%s
\93¦
\82°
\82½
\81I", Monnam(mtmp),
1062 sstairs.up ? "
\82Ì
\82Ú
\82Á
\82Ä" : "
\8d~
\82è
\82Ä");
1064 /* going from the Valley to Castle (Stronghold) has no sstairs
1065 to target, but having sstairs.<sx,sy> == <0,0> will work the
1066 same as specifying MIGR_RANDOM when mon_arrive() eventually
1067 places the monster, so we can use MIGR_SSTAIRS unconditionally */
1068 migrate_to_level(mtmp, ledger_no(&sstairs.tolev), MIGR_SSTAIRS,
1071 case MUSE_TELEPORT_TRAP:
1075 pline("%s %s onto a teleport trap!", Monnam(mtmp),
1076 makeplural(locomotion(mtmp->data, "jump")));
1078 pline("%s
\82Í
\8fu
\8aÔ
\88Ú
\93®
\82Ìã©
\82É
\94ò
\82Ñ
\8d\9e\82ñ
\82¾
\81I", Monnam(mtmp));
1080 seetrap(t_at(trapx, trapy));
1082 /* don't use rloc_to() because worm tails must "move" */
1083 remove_monster(mtmp->mx, mtmp->my);
1084 newsym(mtmp->mx, mtmp->my); /* update old location */
1085 place_monster(mtmp, trapx, trapy);
1088 newsym(trapx, trapy);
1091 case MUSE_POT_HEALING:
1092 mquaffmsg(mtmp, otmp);
1093 i = d(6 + 2 * bcsign(otmp), 4);
1095 if (mtmp->mhp > mtmp->mhpmax)
1096 mtmp->mhp = ++mtmp->mhpmax;
1097 if (!otmp->cursed && !mtmp->mcansee) {
1101 pline(mcsa, Monnam(mtmp));
1105 pline("%s looks better.", Monnam(mtmp));
1107 pline("%s
\82Í
\8bC
\95ª
\82ª
\82æ
\82
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D", Monnam(mtmp));
1109 makeknown(POT_HEALING);
1110 m_useup(mtmp, otmp);
1112 case MUSE_POT_EXTRA_HEALING:
1113 mquaffmsg(mtmp, otmp);
1114 i = d(6 + 2 * bcsign(otmp), 8);
1116 if (mtmp->mhp > mtmp->mhpmax)
1117 mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2));
1118 if (!mtmp->mcansee) {
1122 pline(mcsa, Monnam(mtmp));
1126 pline("%s looks much better.", Monnam(mtmp));
1128 pline("%s
\82Í
\82Æ
\82Ä
\82à
\8bC
\95ª
\82ª
\82æ
\82
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D", Monnam(mtmp));
1130 makeknown(POT_EXTRA_HEALING);
1131 m_useup(mtmp, otmp);
1133 case MUSE_POT_FULL_HEALING:
1134 mquaffmsg(mtmp, otmp);
1135 if (otmp->otyp == POT_SICKNESS)
1136 unbless(otmp); /* Pestilence */
1137 mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4));
1138 if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) {
1142 pline(mcsa, Monnam(mtmp));
1146 pline("%s looks completely healed.", Monnam(mtmp));
1148 pline("%s
\82Í
\8a®
\91S
\82É
\89ñ
\95\9c\82µ
\82½
\82æ
\82¤
\82¾
\81D", Monnam(mtmp));
1150 makeknown(otmp->otyp);
1151 m_useup(mtmp, otmp);
1153 case MUSE_LIZARD_CORPSE:
1154 /* not actually called for its unstoning effect */
1155 mon_consume_unstone(mtmp, otmp, FALSE, FALSE);
1158 return 0; /* i.e. an exploded wand */
1160 impossible("%s wanted to perform action %d?", Monnam(mtmp),
1169 rnd_defensive_item(mtmp)
1172 struct permonst *pm = mtmp->data;
1173 int difficulty = monstr[(monsndx(pm))];
1176 if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
1177 || pm->mlet == S_GHOST || pm->mlet == S_KOP)
1180 switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + (difficulty > 8))) {
1183 if (level.flags.noteleport && ++trycnt < 2)
1186 return WAN_TELEPORTATION;
1190 return SCR_TELEPORTATION;
1194 return WAN_CREATE_MONSTER;
1197 return SCR_CREATE_MONSTER;
1201 return POT_EXTRA_HEALING;
1203 return (mtmp->data != &mons[PM_PESTILENCE]) ? POT_FULL_HEALING
1206 if (is_floater(pm) || mtmp->isshk || mtmp->isgd || mtmp->ispriest)
1215 #define MUSE_WAN_DEATH 1
1216 #define MUSE_WAN_SLEEP 2
1217 #define MUSE_WAN_FIRE 3
1218 #define MUSE_WAN_COLD 4
1219 #define MUSE_WAN_LIGHTNING 5
1220 #define MUSE_WAN_MAGIC_MISSILE 6
1221 #define MUSE_WAN_STRIKING 7
1222 #define MUSE_SCR_FIRE 8
1223 #define MUSE_POT_PARALYSIS 9
1224 #define MUSE_POT_BLINDNESS 10
1225 #define MUSE_POT_CONFUSION 11
1226 #define MUSE_FROST_HORN 12
1227 #define MUSE_FIRE_HORN 13
1228 #define MUSE_POT_ACID 14
1229 /*#define MUSE_WAN_TELEPORTATION 15*/
1230 #define MUSE_POT_SLEEPING 16
1231 #define MUSE_SCR_EARTH 17
1233 /* Select an offensive item/action for a monster. Returns TRUE iff one is
1237 find_offensive(mtmp)
1240 register struct obj *obj;
1241 boolean reflection_skip = (Reflecting && rn2(2));
1242 struct obj *helmet = which_armor(mtmp, W_ARMH);
1244 m.offensive = (struct obj *) 0;
1246 if (mtmp->mpeaceful || is_animal(mtmp->data) || mindless(mtmp->data)
1247 || nohands(mtmp->data))
1251 if (in_your_sanctuary(mtmp, 0, 0))
1253 if (dmgtype(mtmp->data, AD_HEAL)
1254 && !uwep && !uarmu && !uarm && !uarmh
1255 && !uarms && !uarmg && !uarmc && !uarmf)
1257 /* all offensive items require orthogonal or diagonal targetting */
1258 if (!lined_up(mtmp))
1261 #define nomore(x) if (m.has_offense == x) continue;
1262 /* this picks the last viable item rather than prioritizing choices */
1263 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1264 if (!reflection_skip) {
1265 nomore(MUSE_WAN_DEATH);
1266 if (obj->otyp == WAN_DEATH && obj->spe > 0) {
1268 m.has_offense = MUSE_WAN_DEATH;
1270 nomore(MUSE_WAN_SLEEP);
1271 if (obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) {
1273 m.has_offense = MUSE_WAN_SLEEP;
1275 nomore(MUSE_WAN_FIRE);
1276 if (obj->otyp == WAN_FIRE && obj->spe > 0) {
1278 m.has_offense = MUSE_WAN_FIRE;
1280 nomore(MUSE_FIRE_HORN);
1281 if (obj->otyp == FIRE_HORN && obj->spe > 0) {
1283 m.has_offense = MUSE_FIRE_HORN;
1285 nomore(MUSE_WAN_COLD);
1286 if (obj->otyp == WAN_COLD && obj->spe > 0) {
1288 m.has_offense = MUSE_WAN_COLD;
1290 nomore(MUSE_FROST_HORN);
1291 if (obj->otyp == FROST_HORN && obj->spe > 0) {
1293 m.has_offense = MUSE_FROST_HORN;
1295 nomore(MUSE_WAN_LIGHTNING);
1296 if (obj->otyp == WAN_LIGHTNING && obj->spe > 0) {
1298 m.has_offense = MUSE_WAN_LIGHTNING;
1300 nomore(MUSE_WAN_MAGIC_MISSILE);
1301 if (obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) {
1303 m.has_offense = MUSE_WAN_MAGIC_MISSILE;
1306 nomore(MUSE_WAN_STRIKING);
1307 if (obj->otyp == WAN_STRIKING && obj->spe > 0) {
1309 m.has_offense = MUSE_WAN_STRIKING;
1311 nomore(MUSE_POT_PARALYSIS);
1312 if (obj->otyp == POT_PARALYSIS && multi >= 0) {
1314 m.has_offense = MUSE_POT_PARALYSIS;
1316 nomore(MUSE_POT_BLINDNESS);
1317 if (obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) {
1319 m.has_offense = MUSE_POT_BLINDNESS;
1321 nomore(MUSE_POT_CONFUSION);
1322 if (obj->otyp == POT_CONFUSION) {
1324 m.has_offense = MUSE_POT_CONFUSION;
1326 nomore(MUSE_POT_SLEEPING);
1327 if (obj->otyp == POT_SLEEPING) {
1329 m.has_offense = MUSE_POT_SLEEPING;
1331 nomore(MUSE_POT_ACID);
1332 if (obj->otyp == POT_ACID) {
1334 m.has_offense = MUSE_POT_ACID;
1336 /* we can safely put this scroll here since the locations that
1337 * are in a 1 square radius are a subset of the locations that
1338 * are in wand or throwing range (in other words, always lined_up())
1340 nomore(MUSE_SCR_EARTH);
1341 if (obj->otyp == SCR_EARTH
1342 && ((helmet && is_metallic(helmet)) || mtmp->mconf
1343 || amorphous(mtmp->data) || passes_walls(mtmp->data)
1344 || noncorporeal(mtmp->data) || unsolid(mtmp->data)
1346 && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2
1347 && mtmp->mcansee && haseyes(mtmp->data)
1348 && !Is_rogue_level(&u.uz)
1349 && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
1351 m.has_offense = MUSE_SCR_EARTH;
1354 nomore(MUSE_SCR_FIRE);
1355 if (obj->otyp == SCR_FIRE && resists_fire(mtmp)
1356 && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2
1357 && mtmp->mcansee && haseyes(mtmp->data)) {
1359 m.has_offense = MUSE_SCR_FIRE;
1363 return (boolean) !!m.has_offense;
1370 register struct monst *mtmp;
1371 register struct obj *otmp;
1375 boolean reveal_invis = FALSE;
1376 if (mtmp != &youmonst) {
1377 mtmp->msleeping = 0;
1378 if (mtmp->m_ap_type)
1381 switch (otmp->otyp) {
1383 reveal_invis = TRUE;
1384 if (mtmp == &youmonst) {
1386 makeknown(WAN_STRIKING);
1388 shieldeff(u.ux, u.uy);
1392 pline("
\83{
\83C
\83\93\81I");
1393 } else if (rnd(20) < 10 + u.uac) {
1395 pline_The("wand hits you!");
1397 pline("
\8fñ
\82Í
\82 \82È
\82½
\82É
\96½
\92\86\82µ
\82½
\81I");
1399 if (Half_spell_damage)
1400 tmp = (tmp + 1) / 2;
1402 losehp(tmp, "wand", KILLED_BY_AN);
1404 losehp(tmp, "
\8fÕ
\8c\82\82Ì
\8fñ
\82É
\82æ
\82Á
\82Ä", KILLED_BY_AN);
1407 pline_The("wand misses you.");
1409 pline("
\8fñ
\82Í
\82Í
\82¸
\82ê
\82½
\81D");
1412 } else if (resists_magm(mtmp)) {
1413 shieldeff(mtmp->mx, mtmp->my);
1417 pline("
\83{
\83C
\83\93\81I");
1418 } else if (rnd(20) < 10 + find_mac(mtmp)) {
1421 hit("wand", mtmp, exclam(tmp));
1423 hit("
\8fñ", mtmp, exclam(tmp));
1424 (void) resist(mtmp, otmp->oclass, tmp, TELL);
1425 if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
1426 makeknown(WAN_STRIKING);
1432 if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
1433 makeknown(WAN_STRIKING);
1436 case WAN_TELEPORTATION:
1437 if (mtmp == &youmonst) {
1439 makeknown(WAN_TELEPORTATION);
1442 /* for consistency with zap.c, don't identify */
1443 if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) {
1444 if (cansee(mtmp->mx, mtmp->my))
1446 pline("%s resists the magic!", Monnam(mtmp));
1448 pline("%s
\82Í
\96\82\96@
\82ð
\96h
\82¢
\82¾
\81I", Monnam(mtmp));
1449 } else if (!tele_restrict(mtmp))
1450 (void) rloc(mtmp, TRUE);
1453 case WAN_CANCELLATION:
1454 case SPE_CANCELLATION:
1455 (void) cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE);
1459 if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y)
1460 && !canspotmon(mtmp))
1461 map_invisible(bhitpos.x, bhitpos.y);
1466 /* A modified bhit() for monsters. Based on bhit() in zap.c. Unlike
1467 * buzz(), bhit() doesn't take into account the possibility of a monster
1468 * zapping you, so we need a special function for it. (Unless someone wants
1469 * to merge the two functions...)
1472 mbhit(mon, range, fhitm, fhito, obj)
1473 struct monst *mon; /* monster shooting the wand */
1474 register int range; /* direction and range */
1475 int FDECL((*fhitm), (MONST_P, OBJ_P));
1476 int FDECL((*fhito), (OBJ_P, OBJ_P)); /* fns called when mon/obj hit */
1477 struct obj *obj; /* 2nd arg to fhitm/fhito */
1479 register struct monst *mtmp;
1480 register struct obj *otmp;
1484 bhitpos.x = mon->mx;
1485 bhitpos.y = mon->my;
1486 ddx = sgn(mon->mux - mon->mx);
1487 ddy = sgn(mon->muy - mon->my);
1489 while (range-- > 0) {
1502 if (find_drawbridge(&x, &y))
1503 switch (obj->otyp) {
1505 destroy_drawbridge(x, y);
1507 if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
1508 (*fhitm)(&youmonst, obj);
1510 } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
1511 if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp))
1512 map_invisible(bhitpos.x, bhitpos.y);
1513 (*fhitm)(mtmp, obj);
1516 /* modified by GAN to hit all objects */
1518 int hitanything = 0;
1519 register struct obj *next_obj;
1521 for (otmp = level.objects[bhitpos.x][bhitpos.y]; otmp;
1523 /* Fix for polymorph bug, Tim Wright */
1524 next_obj = otmp->nexthere;
1525 hitanything += (*fhito)(otmp, obj);
1530 typ = levl[bhitpos.x][bhitpos.y].typ;
1531 if (IS_DOOR(typ) || typ == SDOOR) {
1532 switch (obj->otyp) {
1533 /* note: monsters don't use opening or locking magic
1534 at present, but keep these as placeholders */
1538 if (doorlock(obj, bhitpos.x, bhitpos.y)) {
1540 makeknown(obj->otyp);
1541 /* if a shop door gets broken, add it to
1542 the shk's fix list (no cost to player) */
1543 if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
1544 && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE))
1545 add_damage(bhitpos.x, bhitpos.y, 0L);
1551 || (IS_DOOR(typ) && (levl[bhitpos.x][bhitpos.y].doormask
1552 & (D_LOCKED | D_CLOSED)))) {
1560 /* Perform an offensive action for a monster. Must be called immediately
1561 * after find_offensive(). Return values are same as use_defensive().
1568 struct obj *otmp = m.offensive;
1571 /* offensive potions are not drunk, they're thrown */
1572 if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0)
1574 oseen = otmp && canseemon(mtmp);
1576 switch (m.has_offense) {
1577 case MUSE_WAN_DEATH:
1578 case MUSE_WAN_SLEEP:
1581 case MUSE_WAN_LIGHTNING:
1582 case MUSE_WAN_MAGIC_MISSILE:
1583 mzapmsg(mtmp, otmp, FALSE);
1586 makeknown(otmp->otyp);
1588 buzz((int) (-30 - (otmp->otyp - WAN_MAGIC_MISSILE)),
1589 (otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, mtmp->mx, mtmp->my,
1590 sgn(mtmp->mux - mtmp->mx), sgn(mtmp->muy - mtmp->my));
1592 return (mtmp->mhp <= 0) ? 1 : 2;
1593 case MUSE_FIRE_HORN:
1594 case MUSE_FROST_HORN:
1596 makeknown(otmp->otyp);
1598 pline("%s plays a %s!", Monnam(mtmp), xname(otmp));
1600 pline("%s
\82Í%s
\82ð
\90\81\82¢
\82½
\81I", Monnam(mtmp), xname(otmp));
1603 You_hear("a horn being played.");
1605 You_hear("
\83z
\83\8b\83\93\82Ì
\89¹
\82ð
\95·
\82¢
\82½
\81D");
1608 buzz(-30 - ((otmp->otyp == FROST_HORN) ? AD_COLD - 1 : AD_FIRE - 1),
1609 rn1(6, 6), mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx),
1610 sgn(mtmp->muy - mtmp->my));
1612 return (mtmp->mhp <= 0) ? 1 : 2;
1613 case MUSE_WAN_TELEPORTATION:
1614 case MUSE_WAN_STRIKING:
1616 mzapmsg(mtmp, otmp, FALSE);
1619 mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp);
1622 case MUSE_SCR_EARTH: {
1623 /* TODO: handle steeds */
1625 /* don't use monster fields after killing it */
1626 boolean confused = (mtmp->mconf ? TRUE : FALSE);
1627 int mmx = mtmp->mx, mmy = mtmp->my;
1628 boolean is_cursed = otmp->cursed;
1630 mreadmsg(mtmp, otmp);
1631 /* Identify the scroll */
1632 if (canspotmon(mtmp)) {
1634 pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my),
1635 otmp->blessed ? "around" : "above", mon_nam(mtmp));
1637 pline("%s
\82Ì%s
\82Ì%s
\82©
\82ç
\83S
\83\8d\83S
\83\8d\82Æ
\89¹
\82ª
\95·
\82±
\82¦
\82Ä
\82«
\82½
\81D",
1639 otmp->blessed ? "
\82Ü
\82í
\82è" : "
\90^
\8fã",
1640 ceiling(mtmp->mx, mtmp->my));
1643 makeknown(otmp->otyp);
1644 } else if (cansee(mtmp->mx, mtmp->my)) {
1646 pline_The("%s rumbles in the middle of nowhere!",
1648 pline_The("
\82Ç
\82±
\82©
\82Ì%s
\82©
\82ç
\83S
\83\8d\83S
\83\8d\82Æ
\89¹
\82ª
\95·
\82±
\82¦
\82Ä
\82«
\82½
\81D",
1649 ceiling(mtmp->mx, mtmp->my));
1651 map_invisible(mtmp->mx, mtmp->my);
1653 makeknown(otmp->otyp);
1656 /* Loop through the surrounding squares */
1657 for (x = mmx - 1; x <= mmx + 1; x++) {
1658 for (y = mmy - 1; y <= mmy + 1; y++) {
1659 /* Is this a suitable spot? */
1660 if (isok(x, y) && !closed_door(x, y)
1661 && !IS_ROCK(levl[x][y].typ) && !IS_AIR(levl[x][y].typ)
1662 && (((x == mmx) && (y == mmy)) ? !otmp->blessed
1664 && (x != u.ux || y != u.uy)) {
1665 (void) drop_boulder_on_monster(x, y, confused, FALSE);
1669 m_useup(mtmp, otmp);
1670 /* Attack the player */
1671 if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !is_cursed) {
1672 drop_boulder_on_player(confused, !is_cursed, FALSE, TRUE);
1675 return (mtmp->mhp <= 0) ? 1 : 2;
1678 case MUSE_SCR_FIRE: {
1679 boolean vis = cansee(mtmp->mx, mtmp->my);
1681 mreadmsg(mtmp, otmp);
1685 pline("Oh, what a pretty fire!");
1687 pline("
\82í
\82\9f\81C
\82«
\82ê
\82¢
\82È
\89\8a\82¾
\81I");
1689 struct monst *mtmp2;
1694 pline_The("scroll erupts in a tower of flame!");
1696 pline("
\8aª
\95¨
\82©
\82ç
\89Î
\92\8c\82ª
\97§
\82¿
\8f¸
\82Á
\82½
\81I");
1697 shieldeff(mtmp->mx, mtmp->my);
1699 pline("%s is uninjured.", Monnam(mtmp));
1701 pline("%s
\82Í
\8f\9d\82Â
\82©
\82È
\82©
\82Á
\82½
\81D", Monnam(mtmp));
1702 (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
1703 (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
1704 (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
1705 num = (2 * (rn1(3, 3) + 2 * bcsign(otmp)) + 1) / 3;
1706 if (Fire_resistance)
1708 You("are not harmed.");
1710 You("
\8f\9d\82Â
\82©
\82È
\82©
\82Á
\82½
\81D");
1712 if (Half_spell_damage)
1713 num = (num + 1) / 2;
1716 losehp(num, "scroll of fire", KILLED_BY_AN);
1718 losehp(num, "
\89\8a\82Ì
\8aª
\95¨
\82Å", KILLED_BY_AN);
1719 for (mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) {
1720 if (DEADMONSTER(mtmp2)) continue;
1721 if (mtmp == mtmp2) continue;
1722 if (dist2(mtmp2->mx, mtmp2->my, mtmp->mx, mtmp->my) < 3) {
1723 if (resists_fire(mtmp2)) continue;
1725 if (resists_cold(mtmp2))
1726 mtmp2->mhp -= 3 * num;
1727 if (mtmp2->mhp < 1) {
1737 case MUSE_POT_PARALYSIS:
1738 case MUSE_POT_BLINDNESS:
1739 case MUSE_POT_CONFUSION:
1740 case MUSE_POT_SLEEPING:
1742 /* Note: this setting of dknown doesn't suffice. A monster
1743 * which is out of sight might throw and it hits something _in_
1744 * sight, a problem not existing with wands because wand rays
1745 * are not objects. Also set dknown in mthrowu.c.
1747 if (cansee(mtmp->mx, mtmp->my)) {
1750 pline("%s hurls %s!", Monnam(mtmp), singular(otmp, doname));
1752 pline("%s
\82Í%s
\82ð
\8b
\82
\93\8a\82°
\82Â
\82¯
\82½
\81I", Monnam(mtmp), singular(otmp, doname));
1754 m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx),
1755 sgn(mtmp->muy - mtmp->my),
1756 distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp);
1759 return 0; /* i.e. an exploded wand */
1761 impossible("%s wanted to perform action %d?", Monnam(mtmp),
1769 rnd_offensive_item(mtmp)
1772 struct permonst *pm = mtmp->data;
1773 int difficulty = monstr[(monsndx(pm))];
1775 if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
1776 || pm->mlet == S_GHOST || pm->mlet == S_KOP)
1778 if (difficulty > 7 && !rn2(35))
1780 switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) {
1782 struct obj *helmet = which_armor(mtmp, W_ARMH);
1784 if ((helmet && is_metallic(helmet)) || amorphous(pm)
1785 || passes_walls(pm) || noncorporeal(pm) || unsolid(pm))
1787 } /* fall through */
1789 return WAN_STRIKING;
1793 return POT_CONFUSION;
1795 return POT_BLINDNESS;
1797 return POT_SLEEPING;
1799 return POT_PARALYSIS;
1802 return WAN_MAGIC_MISSILE;
1810 return WAN_LIGHTNING;
1816 #define MUSE_POT_GAIN_LEVEL 1
1817 #define MUSE_WAN_MAKE_INVISIBLE 2
1818 #define MUSE_POT_INVISIBILITY 3
1819 #define MUSE_POLY_TRAP 4
1820 #define MUSE_WAN_POLYMORPH 5
1821 #define MUSE_POT_SPEED 6
1822 #define MUSE_WAN_SPEED_MONSTER 7
1823 #define MUSE_BULLWHIP 8
1824 #define MUSE_POT_POLYMORPH 9
1830 register struct obj *obj;
1831 struct permonst *mdat = mtmp->data;
1832 int x = mtmp->mx, y = mtmp->my;
1834 int xx, yy, pmidx = NON_PM;
1835 boolean immobile = (mdat->mmove == 0);
1836 boolean stuck = (mtmp == u.ustuck);
1838 m.misc = (struct obj *) 0;
1840 if (is_animal(mdat) || mindless(mdat))
1842 if (u.uswallow && stuck)
1845 /* We arbitrarily limit to times when a player is nearby for the
1846 * same reason as Junior Pac-Man doesn't have energizers eaten until
1847 * you can see them...
1849 if (dist2(x, y, mtmp->mux, mtmp->muy) > 36)
1852 if (!stuck && !immobile && (mtmp->cham == NON_PM)
1853 && monstr[(pmidx = monsndx(mdat))] < 6) {
1854 boolean ignore_boulders = (verysmall(mdat) || throws_rocks(mdat)
1855 || passes_walls(mdat)),
1856 diag_ok = !NODIAG(pmidx);
1858 for (xx = x - 1; xx <= x + 1; xx++)
1859 for (yy = y - 1; yy <= y + 1; yy++)
1860 if (isok(xx, yy) && (xx != u.ux || yy != u.uy)
1861 && (diag_ok || xx == x || yy == y)
1862 && ((xx == x && yy == y) || !level.monsters[xx][yy]))
1863 if ((t = t_at(xx, yy)) != 0
1864 && (ignore_boulders || !sobj_at(BOULDER, xx, yy))
1865 && !onscary(xx, yy, mtmp)) {
1866 /* use trap if it's the correct type */
1867 if (t->ttyp == POLY_TRAP) {
1870 m.has_misc = MUSE_POLY_TRAP;
1878 #define nomore(x) if (m.has_misc == x) continue
1880 * [bug?] Choice of item is not prioritized; the last viable one
1881 * in the monster's inventory will be chosen.
1882 * 'nomore()' is nearly worthless because it only screens checking
1883 * of duplicates when there is no alternate type in between them.
1885 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1886 /* Monsters shouldn't recognize cursed items; this kludge is
1887 necessary to prevent serious problems though... */
1888 if (obj->otyp == POT_GAIN_LEVEL
1890 || (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) {
1892 m.has_misc = MUSE_POT_GAIN_LEVEL;
1894 nomore(MUSE_BULLWHIP);
1895 if (obj->otyp == BULLWHIP && !mtmp->mpeaceful
1896 /* the random test prevents whip-wielding
1897 monster from attempting disarm every turn */
1898 && uwep && !rn2(5) && obj == MON_WEP(mtmp)
1899 /* hero's location must be known and adjacent */
1900 && mtmp->mux == u.ux && mtmp->muy == u.uy
1901 && distu(mtmp->mx, mtmp->my) <= 2
1902 /* don't bother if it can't work (this doesn't
1903 prevent cursed weapons from being targetted) */
1904 && (canletgo(uwep, "")
1905 || (u.twoweap && canletgo(uswapwep, "")))) {
1907 m.has_misc = MUSE_BULLWHIP;
1909 /* Note: peaceful/tame monsters won't make themselves
1910 * invisible unless you can see them. Not really right, but...
1912 nomore(MUSE_WAN_MAKE_INVISIBLE);
1913 if (obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && !mtmp->minvis
1914 && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible)
1915 && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
1917 m.has_misc = MUSE_WAN_MAKE_INVISIBLE;
1919 nomore(MUSE_POT_INVISIBILITY);
1920 if (obj->otyp == POT_INVISIBILITY && !mtmp->minvis
1921 && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible)
1922 && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
1924 m.has_misc = MUSE_POT_INVISIBILITY;
1926 nomore(MUSE_WAN_SPEED_MONSTER);
1927 if (obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0
1928 && mtmp->mspeed != MFAST && !mtmp->isgd) {
1930 m.has_misc = MUSE_WAN_SPEED_MONSTER;
1932 nomore(MUSE_POT_SPEED);
1933 if (obj->otyp == POT_SPEED && mtmp->mspeed != MFAST && !mtmp->isgd) {
1935 m.has_misc = MUSE_POT_SPEED;
1937 nomore(MUSE_WAN_POLYMORPH);
1938 if (obj->otyp == WAN_POLYMORPH && obj->spe > 0
1939 && (mtmp->cham == NON_PM) && monstr[monsndx(mdat)] < 6) {
1941 m.has_misc = MUSE_WAN_POLYMORPH;
1943 nomore(MUSE_POT_POLYMORPH);
1944 if (obj->otyp == POT_POLYMORPH && (mtmp->cham == NON_PM)
1945 && monstr[monsndx(mdat)] < 6) {
1947 m.has_misc = MUSE_POT_POLYMORPH;
1950 return (boolean) !!m.has_misc;
1954 /* type of monster to polymorph into; defaults to one suitable for the
1955 current level rather than the totally arbitrary choice of newcham() */
1956 static struct permonst *
1957 muse_newcham_mon(mon)
1962 if ((m_armr = which_armor(mon, W_ARM)) != 0) {
1963 if (Is_dragon_scales(m_armr))
1964 return Dragon_scales_to_pm(m_armr);
1965 else if (Is_dragon_mail(m_armr))
1966 return Dragon_mail_to_pm(m_armr);
1976 struct obj *otmp = m.misc;
1977 boolean vis, vismon, oseen;
1980 if ((i = precheck(mtmp, otmp)) != 0)
1982 vis = cansee(mtmp->mx, mtmp->my);
1983 vismon = canseemon(mtmp);
1984 oseen = otmp && vismon;
1986 switch (m.has_misc) {
1987 case MUSE_POT_GAIN_LEVEL:
1988 mquaffmsg(mtmp, otmp);
1990 if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) {
1991 register int tolev = depth(&u.uz) - 1;
1994 get_level(&tolevel, tolev);
1995 /* insurance against future changes... */
1996 if (on_level(&tolevel, &u.uz))
2000 pline("%s rises up, through the %s!", Monnam(mtmp),
2001 ceiling(mtmp->mx, mtmp->my));
2003 pline("%s
\82Í%s
\82ð
\93Ë
\82«
\94²
\82¯
\82½
\81I", Monnam(mtmp),
2004 ceiling(mtmp->mx, mtmp->my));
2006 if (!objects[POT_GAIN_LEVEL].oc_name_known
2007 && !objects[POT_GAIN_LEVEL].oc_uname)
2010 m_useup(mtmp, otmp);
2011 migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM,
2018 pline("%s looks uneasy.", Monnam(mtmp));
2020 pline("%s
\82Í
\95s
\88À
\82°
\82É
\8c©
\82¦
\82é
\81D", Monnam(mtmp));
2021 if (!objects[POT_GAIN_LEVEL].oc_name_known
2022 && !objects[POT_GAIN_LEVEL].oc_uname)
2025 m_useup(mtmp, otmp);
2031 pline("%s seems more experienced.", Monnam(mtmp));
2033 pline("%s
\82Í
\8co
\8c±
\82ð
\90Ï
\82ñ
\82¾
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81D", Monnam(mtmp));
2035 makeknown(POT_GAIN_LEVEL);
2036 m_useup(mtmp, otmp);
2037 if (!grow_up(mtmp, (struct monst *) 0))
2039 /* grew into genocided monster */
2041 case MUSE_WAN_MAKE_INVISIBLE:
2042 case MUSE_POT_INVISIBILITY:
2043 if (otmp->otyp == WAN_MAKE_INVISIBLE) {
2044 mzapmsg(mtmp, otmp, TRUE);
2047 mquaffmsg(mtmp, otmp);
2048 /* format monster's name before altering its visibility */
2049 Strcpy(nambuf, mon_nam(mtmp));
2050 mon_set_minvis(mtmp);
2051 if (vismon && mtmp->minvis) { /* was seen, now invisible */
2052 if (canspotmon(mtmp))
2054 pline("%s body takes on a %s transparency.",
2055 upstart(s_suffix(nambuf)),
2056 Hallucination ? "normal" : "strange");
2058 pline("%s%s
\82Ì
\91Ì
\82Í
\93§
\89ß
\90«
\82ð
\82à
\82Á
\82½
\81D",
2059 Hallucination ? "
\82 \82½
\82è
\82Ü
\82¦
\82È
\82±
\82Æ
\82¾
\82ª" : "
\8aï
\96
\82È
\82±
\82Æ
\82É",
2064 pline("Suddenly you cannot see %s.", nambuf);
2066 pline("%s
\82Í
\93Ë
\91R
\8c©
\82¦
\82È
\82
\82È
\82Á
\82½
\81D", nambuf);
2068 makeknown(otmp->otyp);
2070 if (otmp->otyp == POT_INVISIBILITY) {
2072 you_aggravate(mtmp);
2073 m_useup(mtmp, otmp);
2076 case MUSE_WAN_SPEED_MONSTER:
2077 mzapmsg(mtmp, otmp, TRUE);
2079 mon_adjust_speed(mtmp, 1, otmp);
2081 case MUSE_POT_SPEED:
2082 mquaffmsg(mtmp, otmp);
2083 /* note difference in potion effect due to substantially
2084 different methods of maintaining speed ratings:
2085 player's character becomes "very fast" temporarily;
2086 monster becomes "one stage faster" permanently */
2087 mon_adjust_speed(mtmp, 1, otmp);
2088 m_useup(mtmp, otmp);
2090 case MUSE_WAN_POLYMORPH:
2091 mzapmsg(mtmp, otmp, TRUE);
2093 (void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE);
2095 makeknown(WAN_POLYMORPH);
2097 case MUSE_POT_POLYMORPH:
2098 mquaffmsg(mtmp, otmp);
2101 pline("%s suddenly mutates!", Monnam(mtmp));
2103 pline("%s
\82Í
\93Ë
\91R
\95Ï
\89»
\82µ
\82½
\81I", Monnam(mtmp));
2104 (void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE);
2106 makeknown(POT_POLYMORPH);
2107 m_useup(mtmp, otmp);
2109 case MUSE_POLY_TRAP:
2112 pline("%s deliberately %s onto a polymorph trap!", Monnam(mtmp),
2113 makeplural(locomotion(mtmp->data, "jump")));
2115 pline("%s
\82Í
\82í
\82´
\82Æ
\95Ï
\89»
\82Ìã©
\82É
\94ò
\82Ñ
\82±
\82ñ
\82¾
\81I", Monnam(mtmp));
2118 seetrap(t_at(trapx, trapy));
2120 /* don't use rloc() due to worms */
2121 remove_monster(mtmp->mx, mtmp->my);
2122 newsym(mtmp->mx, mtmp->my);
2123 place_monster(mtmp, trapx, trapy);
2126 newsym(trapx, trapy);
2128 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
2131 /* attempt to disarm hero */
2134 const char *The_whip = vismon ? "The bullwhip" : "A whip";
2136 const char *The_whip = vismon ? "
\95Ú" : "
\95Ú";
2137 int where_to = rn2(4);
2138 struct obj *obj = uwep;
2140 char the_weapon[BUFSZ];
2142 if (!obj || !canletgo(obj, "")
2143 || (u.twoweap && canletgo(uswapwep, "") && rn2(2)))
2146 break; /* shouldn't happen after find_misc() */
2148 Strcpy(the_weapon, the(xname(obj)));
2149 hand = body_part(HAND);
2151 hand = makeplural(hand);
2155 pline("%s flicks a bullwhip towards your %s!", Monnam(mtmp),
2158 pline("%s
\82Í
\82 \82È
\82½
\82Ì%s
\82É
\8cü
\82©
\82Á
\82Ä
\95Ú
\82ð
\91Å
\82Á
\82½
\81I", Monnam(mtmp),
2161 if (obj->otyp == HEAVY_IRON_BALL) {
2163 pline("%s fails to wrap around %s.", The_whip, the_weapon);
2165 pline("%s
\82Í%s
\82É
\82Í
\82©
\82ç
\82Ý
\82Â
\82©
\82È
\82©
\82Á
\82½
\81D", The_whip, the_weapon);
2169 pline("%s wraps around %s you're wielding!", The_whip,
2172 pline("%s
\82Í
\82 \82È
\82½
\82Ì
\91\95\94õ
\82µ
\82Ä
\82¢
\82é%s
\82É
\82©
\82ç
\82Ý
\82Â
\82¢
\82½
\81I", The_whip,
2177 pline("%s welded to your %s%c",
2178 !is_plural(obj) ? "It is" : "They are", hand,
2179 !obj->bknown ? '!' : '.');
2181 pline("
\82µ
\82©
\82µ
\81C
\82»
\82ê
\82Í
\82Ü
\82¾
\82 \82È
\82½
\82Ì%s
\82Ì
\92\86\82É
\82 \82é%s",
2183 !obj->bknown ? "
\81I" : "
\81D");
2185 /* obj->bknown = 1; */ /* welded() takes care of this */
2190 pline_The("whip slips free."); /* not `The_whip' */
2192 pline("
\95Ú
\82Í
\82Ù
\82Ç
\82¯
\82½
\81D"); /* not `The_whip' */
2195 } else if (where_to == 3 && mon_hates_silver(mtmp)
2196 && objects[obj->otyp].oc_material == SILVER) {
2197 /* this monster won't want to catch a silver
2198 weapon; drop it at hero's feet instead */
2201 remove_worn_item(obj, FALSE);
2204 case 1: /* onto floor beneath mon */
2206 pline("%s yanks %s from your %s!", Monnam(mtmp), the_weapon,
2209 pline("%s
\82Í%s
\82ð
\82 \82È
\82½
\82Ì%s
\82©
\82ç
\82®
\82¢
\82Æ
\82Ð
\82Á
\82Ï
\82Á
\82½
\81I", Monnam(mtmp), the_weapon,
2212 place_object(obj, mtmp->mx, mtmp->my);
2214 case 2: /* onto floor beneath you */
2216 pline("%s yanks %s to the %s!", Monnam(mtmp), the_weapon,
2217 surface(u.ux, u.uy));
2219 pline("%s
\82Í%s
\82ð%s
\82É
\88ø
\82«
\97\8e\82µ
\82½
\81I", Monnam(mtmp), the_weapon,
2220 surface(u.ux, u.uy));
2224 case 3: /* into mon's inventory */
2226 pline("%s snatches %s!", Monnam(mtmp), the_weapon);
2228 pline("%s
\82Í%s
\82ð
\92D
\82Á
\82½
\81I", Monnam(mtmp), the_weapon);
2229 (void) mpickobj(mtmp, obj);
2236 return 0; /* i.e. an exploded wand */
2238 impossible("%s wanted to perform action %d?", Monnam(mtmp),
2250 pline("For some reason, %s presence is known to you.",
2252 pline("
\82È
\82º
\82©
\81C
\82 \82È
\82½
\82Í%s
\82Ì
\91¶
\8dÝ
\82É
\8bC
\82ª
\82Â
\82¢
\82½
\81D",
2253 s_suffix(noit_mon_nam(mtmp)));
2256 cliparound(mtmp->mx, mtmp->my);
2258 show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp));
2261 You_feel("aggravated at %s.", noit_mon_nam(mtmp));
2263 You("%s
\82É
\95 \82ª
\82½
\82Á
\82½
\81D", mon_nam(mtmp));
2264 display_nhwindow(WIN_MAP, TRUE);
2266 if (unconscious()) {
2269 nomovemsg = "Aggravated, you are jolted into full consciousness.";
2271 nomovemsg = "
\95 \82ª
\82½
\82Á
\82Ä
\82¢
\82Ä
\81C
\83s
\83\8a\83s
\83\8a\82µ
\82Ä
\82¢
\82é
\81D";
2273 newsym(mtmp->mx, mtmp->my);
2274 if (!canspotmon(mtmp))
2275 map_invisible(mtmp->mx, mtmp->my);
2282 struct permonst *pm = mtmp->data;
2283 int difficulty = monstr[(monsndx(pm))];
2285 if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
2286 || pm->mlet == S_GHOST || pm->mlet == S_KOP)
2288 /* Unlike other rnd_item functions, we only allow _weak_ monsters
2289 * to have this item; after all, the item will be used to strengthen
2290 * the monster and strong monsters won't use it at all...
2292 if (difficulty < 6 && !rn2(30))
2293 return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH;
2295 if (!rn2(40) && !nonliving(pm) && !is_vampshifter(mtmp))
2296 return AMULET_OF_LIFE_SAVING;
2302 return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER;
2304 if (mtmp->mpeaceful && !See_invisible)
2306 return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE;
2308 return POT_GAIN_LEVEL;
2315 searches_for_item(mon, obj)
2319 int typ = obj->otyp;
2321 if (is_animal(mon->data) || mindless(mon->data)
2322 || mon->data == &mons[PM_GHOST]) /* don't loot bones piles */
2325 if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY)
2326 return (boolean) (!mon->minvis && !mon->invis_blkd
2327 && !attacktype(mon->data, AT_GAZE));
2328 if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED)
2329 return (boolean) (mon->mspeed != MFAST);
2331 switch (obj->oclass) {
2335 if (typ == WAN_DIGGING)
2336 return (boolean) !is_floater(mon->data);
2337 if (typ == WAN_POLYMORPH)
2338 return (boolean) (monstr[monsndx(mon->data)] < 6);
2339 if (objects[typ].oc_dir == RAY || typ == WAN_STRIKING
2340 || typ == WAN_TELEPORTATION || typ == WAN_CREATE_MONSTER)
2344 if (typ == POT_HEALING || typ == POT_EXTRA_HEALING
2345 || typ == POT_FULL_HEALING || typ == POT_POLYMORPH
2346 || typ == POT_GAIN_LEVEL || typ == POT_PARALYSIS
2347 || typ == POT_SLEEPING || typ == POT_ACID || typ == POT_CONFUSION)
2349 if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE))
2353 if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER
2354 || typ == SCR_EARTH || typ == SCR_FIRE)
2358 if (typ == AMULET_OF_LIFE_SAVING)
2359 return (boolean) !(nonliving(mon->data) || is_vampshifter(mon));
2360 if (typ == AMULET_OF_REFLECTION)
2364 if (typ == PICK_AXE)
2365 return (boolean) needspick(mon->data);
2366 if (typ == UNICORN_HORN)
2367 return (boolean) (!obj->cursed && !is_unicorn(mon->data));
2368 if (typ == FROST_HORN || typ == FIRE_HORN)
2369 return (obj->spe > 0);
2373 return (boolean) (((mon->misc_worn_check & W_ARMG) != 0L
2374 && touch_petrifies(&mons[obj->corpsenm]))
2375 || (!resists_ston(mon)
2376 && cures_stoning(mon, obj, FALSE)));
2378 return (boolean) (mcould_eat_tin(mon)
2379 && (!resists_ston(mon)
2380 && cures_stoning(mon, obj, TRUE)));
2382 return (boolean) touch_petrifies(&mons[obj->corpsenm]);
2392 mon_reflects(mon, str)
2396 struct obj *orefl = which_armor(mon, W_ARMS);
2398 if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) {
2401 pline(str, s_suffix(mon_nam(mon)), "shield");
2403 pline(str, mon_nam(mon), "
\8f\82");
2404 makeknown(SHIELD_OF_REFLECTION);
2407 } else if (arti_reflects(MON_WEP(mon))) {
2408 /* due to wielded artifact weapon */
2411 pline(str, s_suffix(mon_nam(mon)), "weapon");
2413 pline(str, mon_nam(mon), "
\95\90\8aí");
2415 } else if ((orefl = which_armor(mon, W_AMUL))
2416 && orefl->otyp == AMULET_OF_REFLECTION) {
2419 pline(str, s_suffix(mon_nam(mon)), "amulet");
2421 pline(str, mon_nam(mon), "
\96\82\8f\9c\82¯");
2422 makeknown(AMULET_OF_REFLECTION);
2425 } else if ((orefl = which_armor(mon, W_ARM))
2426 && (orefl->otyp == SILVER_DRAGON_SCALES
2427 || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) {
2430 pline(str, s_suffix(mon_nam(mon)), "armor");
2432 pline(str, mon_nam(mon), "
\8aZ");
2434 } else if (mon->data == &mons[PM_SILVER_DRAGON]
2435 || mon->data == &mons[PM_CHROMATIC_DRAGON]) {
2436 /* Silver dragons only reflect when mature; babies do not */
2439 pline(str, s_suffix(mon_nam(mon)), "scales");
2441 pline(str, mon_nam(mon), "
\97Ø");
2449 const char *fmt, *str;
2451 /* Check from outermost to innermost objects */
2452 if (EReflecting & W_ARMS) {
2455 pline(fmt, str, "shield");
2457 pline(fmt, str, "
\8f\82");
2458 makeknown(SHIELD_OF_REFLECTION);
2461 } else if (EReflecting & W_WEP) {
2462 /* Due to wielded artifact weapon */
2465 pline(fmt, str, "weapon");
2467 pline(fmt, str, "
\95\90\8aí");
2469 } else if (EReflecting & W_AMUL) {
2472 pline(fmt, str, "medallion");
2474 pline(fmt, str, "
\83\81\83_
\83\8a\83I
\83\93");
2475 makeknown(AMULET_OF_REFLECTION);
2478 } else if (EReflecting & W_ARM) {
2481 pline(fmt, str, uskin ? "luster" : "armor");
2483 pline(fmt, str, uskin ? "
\82Â
\82â" : "
\8aZ");
2485 } else if (youmonst.data == &mons[PM_SILVER_DRAGON]) {
2488 pline(fmt, str, "scales");
2490 pline(fmt, str, "
\97Ø");
2496 /* TRUE if the monster ate something */
2498 munstone(mon, by_you)
2505 if (resists_ston(mon))
2507 if (mon->meating || !mon->mcanmove || mon->msleeping)
2509 mon->mstrategy &= ~STRAT_WAITFORU;
2511 tinok = mcould_eat_tin(mon);
2512 for (obj = mon->minvent; obj; obj = obj->nobj) {
2513 if (cures_stoning(mon, obj, tinok)) {
2514 mon_consume_unstone(mon, obj, by_you, TRUE);
2522 mon_consume_unstone(mon, obj, by_you, stoning)
2528 boolean vis = canseemon(mon), tinned = obj->otyp == TIN,
2529 food = obj->otyp == CORPSE || tinned,
2530 acid = obj->otyp == POT_ACID
2531 || (food && acidic(&mons[obj->corpsenm])),
2532 lizard = food && obj->corpsenm == PM_LIZARD;
2533 int nutrit = food ? dog_nutrition(mon, obj) : 0; /* also sets meating */
2535 /* give a "<mon> is slowing down" message and also remove
2536 intrinsic speed (comparable to similar effect on the hero) */
2538 mon_adjust_speed(mon, -3, (struct obj *) 0);
2541 long save_quan = obj->quan;
2545 pline("%s %s %s.", Monnam(mon),
2546 (obj->oclass == POTION_CLASS)
2548 : (obj->otyp == TIN) ? "opens and eats the contents of"
2550 distant_name(obj, doname));
2552 pline("%s
\82Í%s
\82ð%s
\81D", Monnam(mon),
2553 distant_name(obj, doname),
2554 (obj->oclass == POTION_CLASS)
2556 : (obj->otyp == TIN) ? "
\8aJ
\82¯
\82Ä
\92\86\90g
\82ð
\90H
\82×
\82½"
2559 obj->quan = save_quan;
2563 (obj->oclass == POTION_CLASS) ? "drinking" : "chewing");
2565 You_hear("%s
\82Æ
\82¢
\82¤
\89¹
\82ð
\95·
\82¢
\82½
\81D",
2566 (obj->otyp == POT_ACID) ? "
\83S
\83N
\83\93" : "
\83N
\83`
\83\83\83N
\83`
\83\83");
2570 /* obj is now gone */
2572 if (acid && !tinned && !resists_acid(mon)) {
2573 mon->mhp -= rnd(15);
2576 pline("%s has a very bad case of stomach acid.", Monnam(mon));
2578 pline("%s
\82Í
\88Ý
\8e_
\82Ì
\92²
\8eq
\82ª
\82Æ
\82Ä
\82à
\88«
\82¢
\81D", Monnam(mon));
2579 if (mon->mhp <= 0) {
2581 pline("%s dies!", Monnam(mon));
2583 pline("%s
\82Í
\8e\80\82ñ
\82¾
\81I", Monnam(mon));
2591 if (stoning && vis) {
2594 pline("What a pity - %s just ruined a future piece of art!",
2596 pline("
\82È
\82ñ
\82Ä
\82±
\82Æ
\82¾
\81I%s
\82Í
\8c|
\8fp
\8dì
\95i
\82É
\82È
\82ê
\82½
\82©
\82à
\82µ
\82ê
\82È
\82¢
\82Ì
\82É
\81I",
2600 pline("%s seems limber!", Monnam(mon));
2602 pline("%s
\82Í
\91Ì
\82ª
\8f_
\82ç
\82©
\82
\82È
\82Á
\82½
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81I", Monnam(mon));
2604 if (lizard && (mon->mconf || mon->mstun)) {
2607 if (vis && !is_bat(mon->data) && mon->data != &mons[PM_STALKER])
2609 pline("%s seems steadier now.", Monnam(mon));
2611 pline("%s
\82Í
\82æ
\82è
\8fä
\95v
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D", Monnam(mon));
2613 if (mon->mtame && !mon->isminion && nutrit > 0) {
2614 struct edog *edog = EDOG(mon);
2616 if (edog->hungrytime < monstermoves)
2617 edog->hungrytime = monstermoves;
2618 edog->hungrytime += nutrit;
2621 /* use up monster's next move */
2622 mon->movement -= NORMAL_SPEED;
2623 mon->mlstmv = monstermoves;
2626 /* decide whether obj can cure petrification; also used when picking up */
2628 cures_stoning(mon, obj, tinok)
2633 if (obj->otyp == POT_ACID)
2635 if (obj->otyp != CORPSE && (obj->otyp != TIN || !tinok))
2637 /* corpse, or tin that mon can open */
2638 return (boolean) (obj->corpsenm == PM_LIZARD
2639 || (acidic(&mons[obj->corpsenm])
2640 && (obj->corpsenm != PM_GREEN_SLIME
2641 || slimeproof(mon->data))));
2648 struct obj *obj, *mwep;
2651 /* monkeys who manage to steal tins can't open and eat them
2652 even if they happen to also have the appropriate tool */
2653 if (is_animal(mon->data))
2656 mwep = MON_WEP(mon);
2657 welded_wep = mwep && mwelded(mwep);
2658 /* this is different from the player; tin opener or dagger doesn't
2659 have to be wielded, and knife can be used instead of dagger */
2660 for (obj = mon->minvent; obj; obj = obj->nobj) {
2661 /* if stuck with a cursed weapon, don't check rest of inventory */
2662 if (welded_wep && obj != mwep)
2665 if (obj->otyp == TIN_OPENER
2666 || (obj->oclass == WEAPON_CLASS
2667 && (objects[obj->otyp].oc_skill == P_DAGGER
2668 || objects[obj->otyp].oc_skill == P_KNIFE)))
2674 /* TRUE if monster does something to avoid turning into green slime */
2676 munslime(mon, by_you)
2680 struct obj *obj, odummy;
2683 * muse_unslime() gives "mon starts turning green", "mon zaps
2684 * itself with a wand of fire", and "mon's slime burns away"
2685 * messages. Monsters who don't get any chance at that just have
2686 * (via our caller) newcham()'s "mon turns into slime" feedback.
2689 if (slimeproof(mon->data))
2691 if (mon->meating || !mon->mcanmove || mon->msleeping)
2693 mon->mstrategy &= ~STRAT_WAITFORU;
2695 /* if monster can breathe fire, do so upon self; a monster who deals
2696 fire damage by biting, clawing, gazing, and especially exploding
2697 isn't able to cure itself of green slime with its own attack
2698 [possible extension: monst capable of casting high level clerical
2699 spells could toss pillar of fire at self--probably too suicidal] */
2700 if (!mon->mcan && !mon->mspec_used
2701 && attacktype_fordmg(mon->data, AT_BREA, AD_FIRE)) {
2702 odummy = zeroobj; /* otyp == STRANGE_OBJECT */
2703 return muse_unslime(mon, &odummy, by_you);
2706 for (obj = mon->minvent; obj; obj = obj->nobj)
2707 if (cures_sliming(mon, obj))
2708 return muse_unslime(mon, obj, by_you);
2710 /* TODO: check for and move onto an adjacent fire trap */
2715 /* mon uses an item--selected by caller--to burn away incipient slime */
2717 muse_unslime(mon, obj, by_you)
2720 boolean by_you; /* true: if mon kills itself, hero gets credit/blame */
2722 struct obj *odummyp;
2723 int otyp = obj->otyp, dmg;
2724 boolean vis = canseemon(mon), res = TRUE;
2727 pline("%s starts turning %s.", Monnam(mon),
2728 green_mon(mon) ? "into ooze" : hcolor(NH_GREEN));
2729 /* -4 => sliming, causes quiet loss of enhanced speed */
2730 mon_adjust_speed(mon, -4, (struct obj *) 0);
2732 if (otyp == STRANGE_OBJECT) {
2733 /* monster is using fire breath on self */
2735 pline("%s breathes fire on %sself.", Monnam(mon), mhim(mon));
2737 mon->mspec_used = rn1(10, 5);
2738 /* -21 => monster's fire breath; 1 => # of damage dice */
2739 (void) zhitm(mon, by_you ? 21 : -21, 1, &odummyp);
2740 } else if (otyp == SCR_FIRE) {
2743 if (cansee(mon->mx, mon->my))
2744 pline("Oh, what a pretty fire!");
2745 if (vis && !objects[otyp].oc_name_known
2746 && !objects[otyp].oc_uname)
2748 m_useup(mon, obj); /* after docall() */
2749 vis = FALSE; /* skip makeknown() below */
2750 res = FALSE; /* failed to cure sliming */
2752 m_useup(mon, obj); /* before explode() */
2753 dmg = (2 * (rn1(3, 3) + 2 * bcsign(obj)) + 1) / 3;
2754 /* -11 => monster's fireball */
2755 explode(mon->mx, mon->my, -11, dmg, SCROLL_CLASS,
2756 /* by_you: override -11 for mon but not others */
2757 by_you ? -EXPL_FIERY : EXPL_FIERY);
2759 } else { /* wand/horn of fire w/ positive charge count */
2760 mzapmsg(mon, obj, TRUE);
2762 /* -1 => monster's wand of fire; 2 => # of damage dice */
2763 (void) zhitm(mon, by_you ? 1 : -1, 2, &odummyp);
2767 if (res && mon->mhp > 0)
2768 pline("%s slime is burned away!", s_suffix(Monnam(mon)));
2769 if (otyp != STRANGE_OBJECT)
2772 /* use up monster's next move */
2773 mon->movement -= NORMAL_SPEED;
2774 mon->mlstmv = monstermoves;
2778 /* decide whether obj can be used to cure green slime */
2780 cures_sliming(mon, obj)
2784 /* scroll of fire, non-empty wand or horn of fire */
2785 if (obj->otyp == SCR_FIRE)
2786 return (haseyes(mon->data) && mon->mcansee);
2787 /* hero doesn't need hands or even limbs to zap, so mon doesn't either */
2788 return ((obj->otyp == WAN_FIRE || obj->otyp == FIRE_HORN)
2792 /* TRUE if monster appears to be green; for active TEXTCOLOR, we go by
2793 the display color, otherwise we just pick things that seem plausibly
2794 green (which doesn't necessarily match the TEXTCOLOR categorization) */
2799 struct permonst *ptr = mon->data;
2804 if (iflags.use_color)
2805 return (ptr->mcolor == CLR_GREEN || ptr->mcolor == CLR_BRIGHT_GREEN);
2808 if (strstri(ptr->mname, "green"))
2810 switch (monsndx(ptr)) {
2811 case PM_FOREST_CENTAUR:
2812 case PM_GARTER_SNAKE:
2823 if (is_elf(ptr) && !is_prince(ptr) && !is_lord(ptr)
2824 && ptr != &mons[PM_GREY_ELF])