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]);
89 if (potion_descr && !strcmp(potion_descr, "milky")) {
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]))
98 mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS);
106 "As %s opens the bottle, an enormous %s emerges!",
108 Hallucination ? rndmonnam(NULL)
109 : (const char *) "ghost");
112 "%s
\82ª
\95r
\82ð
\8aJ
\82¯
\82é
\82Æ
\81C
\8b\90\91å
\82È%s
\82ª
\8fo
\82Ä
\82«
\82½
\81I",
114 Hallucination ? rndmonnam(NULL)
115 : (const char *)"
\97H
\97ì");
118 pline("%s is frightened to death, and unable to move.",
120 pline("%s
\82Í
\82Ü
\82Á
\82³
\82¨
\82É
\82È
\82Á
\82Ä
\8bÁ
\82«
\81C
\93®
\82¯
\82È
\82
\82È
\82Á
\82½
\81D",
123 paralyze_monst(mon, 3);
129 if (potion_descr && !strcmp(potion_descr, "smoky")
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]))
138 mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS);
145 pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp));
147 pline("
\89\8c\82Ì
\92\86\82©
\82ç
\81C%s
\82ª
\8c»
\82í
\82ê
\82½
\81I", a_monnam(mtmp));
149 pline("%s speaks.", vis ? Monnam(mtmp) : Something);
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.... */
156 verbalize("You freed me!");
158 verbalize("
\89ð
\95ú
\82µ
\82Ä
\82
\82ê
\82½
\82Ì
\82Í
\82¨
\91O
\82©
\81I");
163 verbalize("It is about time.");
165 verbalize("
\82³
\82ç
\82Î
\82¾
\81I");
168 pline("%s vanishes.", Monnam(mtmp));
170 pline("%s
\82Í
\8fÁ
\82¦
\82½
\81D", Monnam(mtmp));
177 if (obj->oclass == WAND_CLASS && obj->cursed
178 && !rn2(WAND_BACKFIRE_CHANCE)) {
179 int dam = d(obj->spe + 2, 6);
184 pline("%s zaps %s, which suddenly explodes!", Monnam(mon),
187 pline("%s
\82Í%s
\82ð
\82Ó
\82è
\82©
\82´
\82µ
\82½
\81C
\82»
\82ê
\82Í
\93Ë
\91R
\94\9a\94
\82µ
\82½
\81I", Monnam(mon),
192 You_hear("a zap and an explosion in the distance.");
194 You_hear("
\89\93\95û
\82Ì
\8fñ
\82Ì
\89¹
\82Æ
\94\9a\94
\89¹
\82ð
\95·
\82¢
\82½
\81D");
197 if (mon->mhp <= dam) {
198 monkilled(mon, "", AD_RBRE);
202 m.has_defense = m.has_offense = m.has_misc = 0;
203 /* Only one needed to be set to 0 but the others are harmless */
209 mzapmsg(mtmp, otmp, self)
214 if (!canseemon(mtmp)) {
217 You_hear("a %s zap.", (distu(mtmp->mx, mtmp->my)
218 <= (BOLT_LIM + 1) * (BOLT_LIM + 1))
222 You_hear("%s
\82
\82Å
\8fñ
\82Ì
\89¹
\82ð
\95·
\82¢
\82½
\81D", (distu(mtmp->mx, mtmp->my)
223 <= (BOLT_LIM + 1) * (BOLT_LIM + 1))
229 pline("%s zaps %sself with %s!", Monnam(mtmp), mhim(mtmp),
232 pline("%s
\82Í
\8e©
\95ª
\8e©
\90g
\82É%s
\82ð
\82Ó
\82è
\82©
\82´
\82µ
\82½
\81I", Monnam(mtmp),
237 pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp)));
239 pline("%s
\82Í%s
\82ð
\82Ó
\82è
\82©
\82´
\82µ
\82½
\81I", Monnam(mtmp), an(xname(otmp)));
249 boolean vismon = canseemon(mtmp);
255 return; /* no feedback */
257 otmp->dknown = 1; /* seeing or hearing it read reveals its label */
258 /* shouldn't be able to hear curse/bless status of unseen scrolls;
259 for priest characters, bknown will always be set during naming */
260 savebknown = otmp->bknown;
261 saverole = Role_switch;
264 if (Role_if(PM_PRIEST))
267 Strcpy(onambuf, singular(otmp, doname));
268 Role_switch = saverole;
269 otmp->bknown = savebknown;
273 pline("%s reads %s!", Monnam(mtmp), onambuf);
275 pline("%s
\82Í%s
\82ð
\93Ç
\82ñ
\82¾
\81I", Monnam(mtmp), onambuf);
278 You_hear("%s reading %s.",
279 x_monnam(mtmp, ARTICLE_A, (char *) 0,
280 (SUPPRESS_IT | SUPPRESS_INVISIBLE | SUPPRESS_SADDLE),
284 You_hear("%s
\82ª%s
\82ð
\93Ç
\82ñ
\82Å
\82¢
\82é
\90º
\82ð
\95·
\82¢
\82½
\81D",
285 x_monnam(mtmp, ARTICLE_A, (char *)0,
286 (SUPPRESS_IT|SUPPRESS_INVISIBLE|SUPPRESS_SADDLE),
293 pline("Being confused, %s mispronounces the magic words...",
295 pline("
\8d¬
\97\90\82µ
\82Ä
\82¢
\82é
\82Ì
\82Å
\81C%s
\82Í
\8eô
\95¶
\82ð
\8aÔ
\88á
\82Á
\82Ä
\8f¥
\82¦
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D
\81D
\81D",
296 vismon ? mon_nam(mtmp) : mhe(mtmp));
300 mquaffmsg(mtmp, otmp)
304 if (canseemon(mtmp)) {
307 pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname));
309 pline("%s
\82Í%s
\82ð
\88ù
\82ñ
\82¾
\81I", Monnam(mtmp), singular(otmp, doname));
312 You_hear("a chugging sound.");
314 You_hear("
\83S
\83N
\83b
\81I
\82Æ
\82¢
\82¤
\89¹
\82ð
\95·
\82¢
\82½
\81D");
317 /* Defines for various types of stuff. The order in which monsters prefer
318 * to use them is determined by the order of the code logic, not the
319 * numerical order in which they are defined.
321 #define MUSE_SCR_TELEPORTATION 1
322 #define MUSE_WAN_TELEPORTATION_SELF 2
323 #define MUSE_POT_HEALING 3
324 #define MUSE_POT_EXTRA_HEALING 4
325 #define MUSE_WAN_DIGGING 5
326 #define MUSE_TRAPDOOR 6
327 #define MUSE_TELEPORT_TRAP 7
328 #define MUSE_UPSTAIRS 8
329 #define MUSE_DOWNSTAIRS 9
330 #define MUSE_WAN_CREATE_MONSTER 10
331 #define MUSE_SCR_CREATE_MONSTER 11
332 #define MUSE_UP_LADDER 12
333 #define MUSE_DN_LADDER 13
334 #define MUSE_SSTAIRS 14
335 #define MUSE_WAN_TELEPORTATION 15
336 #define MUSE_BUGLE 16
337 #define MUSE_UNICORN_HORN 17
338 #define MUSE_POT_FULL_HEALING 18
339 #define MUSE_LIZARD_CORPSE 19
341 #define MUSE_INNATE_TPT 9999
342 * We cannot use this. Since monsters get unlimited teleportation, if they
343 * were allowed to teleport at will you could never catch them. Instead,
344 * assume they only teleport at random times, despite the inconsistency
345 * that if you polymorph into one you teleport at will.
348 /* Select a defensive item/action for a monster. Returns TRUE iff one is
354 register struct obj *obj = 0;
356 int x = mtmp->mx, y = mtmp->my;
357 boolean stuck = (mtmp == u.ustuck);
358 boolean immobile = (mtmp->data->mmove == 0);
361 if (is_animal(mtmp->data) || mindless(mtmp->data))
363 if (dist2(x, y, mtmp->mux, mtmp->muy) > 25)
365 if (u.uswallow && stuck)
368 m.defensive = (struct obj *) 0;
371 /* since unicorn horns don't get used up, the monster would look
372 * silly trying to use the same cursed horn round after round
374 if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) {
375 if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) {
376 for (obj = mtmp->minvent; obj; obj = obj->nobj)
377 if (obj->otyp == UNICORN_HORN && !obj->cursed)
380 if (obj || is_unicorn(mtmp->data)) {
382 m.has_defense = MUSE_UNICORN_HORN;
387 if (mtmp->mconf || mtmp->mstun) {
388 struct obj *liztin = 0;
390 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
391 if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) {
393 m.has_defense = MUSE_LIZARD_CORPSE;
395 } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) {
399 /* confused or stunned monster might not be able to open tin */
400 if (liztin && mcould_eat_tin(mtmp) && rn2(3)) {
401 m.defensive = liztin;
402 /* tin and corpse ultimately end up being handled the same */
403 m.has_defense = MUSE_LIZARD_CORPSE;
408 /* It so happens there are two unrelated cases when we might want to
409 * check specifically for healing alone. The first is when the monster
410 * is blind (healing cures blindness). The second is when the monster
411 * is peaceful; then we don't want to flee the player, and by
412 * coincidence healing is all there is that doesn't involve fleeing.
413 * These would be hard to combine because of the control flow.
414 * Pestilence won't use healing even when blind.
416 if (!mtmp->mcansee && !nohands(mtmp->data)
417 && mtmp->data != &mons[PM_PESTILENCE]) {
418 if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
420 m.has_defense = MUSE_POT_FULL_HEALING;
423 if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
425 m.has_defense = MUSE_POT_EXTRA_HEALING;
428 if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
430 m.has_defense = MUSE_POT_HEALING;
435 fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3;
436 if (mtmp->mhp >= mtmp->mhpmax
437 || (mtmp->mhp >= 10 && mtmp->mhp * fraction >= mtmp->mhpmax))
440 if (mtmp->mpeaceful) {
441 if (!nohands(mtmp->data)) {
442 if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
444 m.has_defense = MUSE_POT_FULL_HEALING;
447 if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
449 m.has_defense = MUSE_POT_EXTRA_HEALING;
452 if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
454 m.has_defense = MUSE_POT_HEALING;
461 if (stuck || immobile) {
462 ; /* fleeing by stairs or traps is not possible */
463 } else if (levl[x][y].typ == STAIRS) {
464 if (x == xdnstair && y == ydnstair) {
465 if (!is_floater(mtmp->data))
466 m.has_defense = MUSE_DOWNSTAIRS;
467 } else if (x == xupstair && y == yupstair) {
468 /* don't let monster leave the dungeon with the Amulet */
469 if (ledger_no(&u.uz) != 1)
470 m.has_defense = MUSE_UPSTAIRS;
471 } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) {
472 if (sstairs.up || !is_floater(mtmp->data))
473 m.has_defense = MUSE_SSTAIRS;
475 } else if (levl[x][y].typ == LADDER) {
476 if (x == xupladder && y == yupladder) {
477 m.has_defense = MUSE_UP_LADDER;
478 } else if (x == xdnladder && y == ydnladder) {
479 if (!is_floater(mtmp->data))
480 m.has_defense = MUSE_DN_LADDER;
481 } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) {
482 if (sstairs.up || !is_floater(mtmp->data))
483 m.has_defense = MUSE_SSTAIRS;
486 /* Note: trap doors take precedence over teleport traps. */
487 int xx, yy, i, locs[10][2];
488 boolean ignore_boulders = (verysmall(mtmp->data)
489 || throws_rocks(mtmp->data)
490 || passes_walls(mtmp->data)),
491 diag_ok = !NODIAG(monsndx(mtmp->data));
493 for (i = 0; i < 10; ++i) /* 10: 9 spots plus sentinel */
494 locs[i][0] = locs[i][1] = 0;
495 /* collect viable spots; monster's <mx,my> comes first */
496 locs[0][0] = x, locs[0][1] = y;
498 for (xx = x - 1; xx <= x + 1; xx++)
499 for (yy = y - 1; yy <= y + 1; yy++)
500 if (isok(xx, yy) && (xx != x || yy != y)) {
501 locs[i][0] = xx, locs[i][1] = yy;
504 /* look for a suitable trap among the viable spots */
505 for (i = 0; i < 10; ++i) {
506 xx = locs[i][0], yy = locs[i][1];
508 break; /* we've run out of spots */
509 /* skip if it's hero's location
510 or a diagonal spot and monster can't move diagonally
511 or some other monster is there */
512 if ((xx == u.ux && yy == u.uy)
513 || (xx != x && yy != y && !diag_ok)
514 || (level.monsters[xx][yy] && !(xx == x && yy == y)))
516 /* skip if there's no trap or can't/won't move onto trap */
517 if ((t = t_at(xx, yy)) == 0
518 || (!ignore_boulders && sobj_at(BOULDER, xx, yy))
519 || onscary(xx, yy, mtmp))
521 /* use trap if it's the correct type */
522 if ((t->ttyp == TRAPDOOR || t->ttyp == HOLE)
523 && !is_floater(mtmp->data)
524 && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
525 && Can_fall_thru(&u.uz)) {
528 m.has_defense = MUSE_TRAPDOOR;
529 break; /* no need to look at any other spots */
530 } else if (t->ttyp == TELEP_TRAP) {
533 m.has_defense = MUSE_TELEPORT_TRAP;
538 if (nohands(mtmp->data)) /* can't use objects */
541 if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE)) != 0) {
545 /* Distance is arbitrary. What we really want to do is
546 * have the soldier play the bugle when it sees or
547 * remembers soldiers nearby...
549 for (xx = x - 3; xx <= x + 3; xx++) {
550 for (yy = y - 3; yy <= y + 3; yy++) {
551 if (!isok(xx, yy) || (xx == x && yy == y))
553 if ((mon = m_at(xx, yy)) != 0 && is_mercenary(mon->data)
554 && mon->data != &mons[PM_GUARD]
555 && (mon->msleeping || !mon->mcanmove)) {
557 m.has_defense = MUSE_BUGLE;
558 goto toot; /* double break */
566 /* use immediate physical escape prior to attempting magic */
567 if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */
570 /* kludge to cut down on trap destruction (particularly portals) */
572 if (t && (t->ttyp == PIT || t->ttyp == SPIKED_PIT || t->ttyp == WEB
573 || t->ttyp == BEAR_TRAP))
574 t = 0; /* ok for monster to dig here */
576 #define nomore(x) if (m.has_defense == x) continue;
577 /* selection could be improved by collecting all possibilities
578 into an array and then picking one at random */
579 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
580 /* don't always use the same selection pattern */
581 if (m.has_defense && !rn2(3))
584 /* nomore(MUSE_WAN_DIGGING); */
585 if (m.has_defense == MUSE_WAN_DIGGING)
587 if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t
588 && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
589 && !is_floater(mtmp->data)
590 /* monsters digging in Sokoban can ruin things */
592 /* digging wouldn't be effective; assume they know that */
593 && !(levl[x][y].wall_info & W_NONDIGGABLE)
594 && !(Is_botlevel(&u.uz) || In_endgame(&u.uz))
595 && !(is_ice(x, y) || is_pool(x, y) || is_lava(x, y))
596 && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER]
597 && In_V_tower(&u.uz))) {
599 m.has_defense = MUSE_WAN_DIGGING;
601 nomore(MUSE_WAN_TELEPORTATION_SELF);
602 nomore(MUSE_WAN_TELEPORTATION);
603 if (obj->otyp == WAN_TELEPORTATION && obj->spe > 0) {
604 /* use the TELEP_TRAP bit to determine if they know
605 * about noteleport on this level or not. Avoids
606 * ineffective re-use of teleportation. This does
607 * mean if the monster leaves the level, they'll know
608 * about teleport traps.
610 if (!level.flags.noteleport
611 || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) {
613 m.has_defense = (mon_has_amulet(mtmp))
614 ? MUSE_WAN_TELEPORTATION
615 : MUSE_WAN_TELEPORTATION_SELF;
618 nomore(MUSE_SCR_TELEPORTATION);
619 if (obj->otyp == SCR_TELEPORTATION && mtmp->mcansee
620 && haseyes(mtmp->data)
621 && (!obj->cursed || (!(mtmp->isshk && inhishop(mtmp))
622 && !mtmp->isgd && !mtmp->ispriest))) {
623 /* see WAN_TELEPORTATION case above */
624 if (!level.flags.noteleport
625 || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) {
627 m.has_defense = MUSE_SCR_TELEPORTATION;
631 if (mtmp->data != &mons[PM_PESTILENCE]) {
632 nomore(MUSE_POT_FULL_HEALING);
633 if (obj->otyp == POT_FULL_HEALING) {
635 m.has_defense = MUSE_POT_FULL_HEALING;
637 nomore(MUSE_POT_EXTRA_HEALING);
638 if (obj->otyp == POT_EXTRA_HEALING) {
640 m.has_defense = MUSE_POT_EXTRA_HEALING;
642 nomore(MUSE_WAN_CREATE_MONSTER);
643 if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
645 m.has_defense = MUSE_WAN_CREATE_MONSTER;
647 nomore(MUSE_POT_HEALING);
648 if (obj->otyp == POT_HEALING) {
650 m.has_defense = MUSE_POT_HEALING;
652 } else { /* Pestilence */
653 nomore(MUSE_POT_FULL_HEALING);
654 if (obj->otyp == POT_SICKNESS) {
656 m.has_defense = MUSE_POT_FULL_HEALING;
658 nomore(MUSE_WAN_CREATE_MONSTER);
659 if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
661 m.has_defense = MUSE_WAN_CREATE_MONSTER;
664 nomore(MUSE_SCR_CREATE_MONSTER);
665 if (obj->otyp == SCR_CREATE_MONSTER) {
667 m.has_defense = MUSE_SCR_CREATE_MONSTER;
671 return (boolean) !!m.has_defense;
675 /* Perform a defensive action for a monster. Must be called immediately
676 * after find_defensive(). Return values are 0: did something, 1: died,
677 * 2: did something and can't attack again (i.e. teleported).
683 int i, fleetim, how = 0;
684 struct obj *otmp = m.defensive;
685 boolean vis, vismon, oseen;
687 const char *mcsa = "%s can see again.";
689 const char *mcsa = "%s
\82Í
\82Ü
\82½
\8c©
\82¦
\82é
\82æ
\82¤
\82É
\82È
\82Á
\82½
\81D";
691 if ((i = precheck(mtmp, otmp)) != 0)
693 vis = cansee(mtmp->mx, mtmp->my);
694 vismon = canseemon(mtmp);
695 oseen = otmp && vismon;
697 /* when using defensive choice to run away, we want monster to avoid
698 rushing right straight back; don't override if already scared */
699 fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0;
701 if (fleetim && !m->iswiz) { \
702 monflee(m, fleetim, FALSE, FALSE); \
705 switch (m.has_defense) {
706 case MUSE_UNICORN_HORN:
710 pline("%s uses a unicorn horn!", Monnam(mtmp));
712 pline("%s
\82Í
\83\86\83j
\83R
\81[
\83\93\82Ì
\8ap
\82ð
\8eg
\82Á
\82½
\81I", Monnam(mtmp));
715 pline_The("tip of %s's horn glows!", mon_nam(mtmp));
717 pline("%s
\82Ì
\8ap
\82Ì
\90æ
\92[
\82ª
\8bP
\82¢
\82½
\81I", mon_nam(mtmp));
719 if (!mtmp->mcansee) {
723 pline(mcsa, Monnam(mtmp));
724 } else if (mtmp->mconf || mtmp->mstun) {
725 mtmp->mconf = mtmp->mstun = 0;
728 pline("%s seems steadier now.", Monnam(mtmp));
730 pline("%s
\82Í
\95½
\90Ã
\82ð
\82Æ
\82è
\82à
\82Ç
\82µ
\82½
\81D", Monnam(mtmp));
732 impossible("No need for unicorn horn?");
737 pline("%s plays %s!", Monnam(mtmp), doname(otmp));
739 pline("%s
\82Í%s
\82ð
\90\81\82¢
\82½
\81I", Monnam(mtmp), doname(otmp));
742 You_hear("a bugle playing reveille!");
744 You_hear("
\8bN
\8f°
\83\89\83b
\83p
\82Ì
\89¹
\82ð
\95·
\82¢
\82½
\81I");
745 awaken_soldiers(mtmp);
747 case MUSE_WAN_TELEPORTATION_SELF:
748 if ((mtmp->isshk && inhishop(mtmp)) || mtmp->isgd || mtmp->ispriest)
751 mzapmsg(mtmp, otmp, TRUE);
753 how = WAN_TELEPORTATION;
755 if (tele_restrict(mtmp)) { /* mysterious force... */
756 if (vismon && how) /* mentions 'teleport' */
758 /* monster learns that teleportation isn't useful here */
759 if (level.flags.noteleport)
760 mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1));
763 if ((mon_has_amulet(mtmp) || On_W_tower_level(&u.uz)) && !rn2(3)) {
766 pline("%s seems disoriented for a moment.", Monnam(mtmp));
768 pline("%s
\82Í
\88ê
\8fu
\95û
\8cü
\8a´
\8ao
\82ð
\8e¸
\82Á
\82½
\81D", Monnam(mtmp));
773 (void) rloc(mtmp, TRUE);
775 case MUSE_WAN_TELEPORTATION:
777 mzapmsg(mtmp, otmp, FALSE);
780 mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp);
781 /* monster learns that teleportation isn't useful here */
782 if (level.flags.noteleport)
783 mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1));
786 case MUSE_SCR_TELEPORTATION: {
787 int obj_is_cursed = otmp->cursed;
789 if (mtmp->isshk || mtmp->isgd || mtmp->ispriest)
792 mreadmsg(mtmp, otmp);
793 m_useup(mtmp, otmp); /* otmp might be free'ed */
794 how = SCR_TELEPORTATION;
795 if (obj_is_cursed || mtmp->mconf) {
799 if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) {
802 pline("%s seems very disoriented for a moment.",
804 pline("%s
\82Í
\88ê
\8fu
\95û
\8cü
\8a´
\8ao
\82ð
\8e¸
\82Á
\82½
\81D",
808 nlev = random_teleport_level();
809 if (nlev == depth(&u.uz)) {
812 pline("%s shudders for a moment.", Monnam(mtmp));
814 pline("%s
\82Í
\88ê
\8fu
\90k
\82¦
\82½
\81D", Monnam(mtmp));
817 get_level(&flev, nlev);
818 migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM,
821 makeknown(SCR_TELEPORTATION);
826 case MUSE_WAN_DIGGING: {
830 mzapmsg(mtmp, otmp, FALSE);
833 makeknown(WAN_DIGGING);
834 if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ)
835 || IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ)
836 || (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0)
837 || (sstairs.sx && sstairs.sx == mtmp->mx
838 && sstairs.sy == mtmp->my)) {
840 pline_The("digging ray is ineffective.");
842 pline("
\8c@
\8dí
\8cõ
\90ü
\82Í
\8cø
\89Ê
\82ª
\82È
\82¢
\81D");
845 if (!Can_dig_down(&u.uz) && !levl[mtmp->mx][mtmp->my].candig) {
848 pline_The("%s here is too hard to dig in.",
850 pline("
\82±
\82±
\82Ì%s
\82Í
\8cÅ
\82
\82Ä
\8c@
\82ê
\82È
\82¢
\81D",
851 surface(mtmp->mx, mtmp->my));
854 ttmp = maketrap(mtmp->mx, mtmp->my, HOLE);
860 pline("%s has made a hole in the %s.", Monnam(mtmp),
861 surface(mtmp->mx, mtmp->my));
863 pline("%s
\82Í%s
\82É
\8c\8a\82ð
\8aJ
\82¯
\82½
\81D", Monnam(mtmp),
864 surface(mtmp->mx, mtmp->my));
867 pline("%s %s through...", Monnam(mtmp),
868 is_flyer(mtmp->data) ? "dives" : "falls");
870 pline("%s
\82Í
\92Ê
\82è
\94²
\82¯
\82Ä%s
\81D
\81D
\81D", Monnam(mtmp),
871 is_flyer(mtmp->data) ? "
\94ò
\82Ñ
\82±
\82ñ
\82¾" : "
\97\8e\82¿
\82½");
875 You_hear("%s crash through the %s.", something,
876 surface(mtmp->mx, mtmp->my));
878 You_hear("
\89½
\82©
\82ª%s
\82ð
\92Ê
\82è
\94²
\82¯
\82Ä
\97\8e\82¿
\82é
\89¹
\82ð
\95·
\82¢
\82½
\81D
\81D
\81D",
879 surface(mtmp->mx, mtmp->my));
881 /* we made sure that there is a level for mtmp to go to */
882 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
886 case MUSE_WAN_CREATE_MONSTER: {
888 /* pm: 0 => random, eel => aquatic, croc => amphibious */
889 struct permonst *pm =
890 !is_pool(mtmp->mx, mtmp->my)
892 : &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
895 if (!enexto(&cc, mtmp->mx, mtmp->my, pm))
897 mzapmsg(mtmp, otmp, FALSE);
899 mon = makemon((struct permonst *) 0, cc.x, cc.y, NO_MM_FLAGS);
900 if (mon && canspotmon(mon) && oseen)
901 makeknown(WAN_CREATE_MONSTER);
904 case MUSE_SCR_CREATE_MONSTER: {
906 struct permonst *pm = 0, *fish = 0;
909 boolean known = FALSE;
913 if (mtmp->mconf || otmp->cursed)
916 pm = fish = &mons[PM_ACID_BLOB];
917 else if (is_pool(mtmp->mx, mtmp->my))
918 fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
919 mreadmsg(mtmp, otmp);
921 /* `fish' potentially gives bias towards water locations;
922 `pm' is what to actually create (0 => random) */
923 if (!enexto(&cc, mtmp->mx, mtmp->my, fish))
925 mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS);
926 if (mon && canspotmon(mon))
929 /* The only case where we don't use oseen. For wands, you
930 * have to be able to see the monster zap the wand to know
931 * what type it is. For teleport scrolls, you have to see
932 * the monster to know it teleported.
935 makeknown(SCR_CREATE_MONSTER);
936 else if (!objects[SCR_CREATE_MONSTER].oc_name_known
937 && !objects[SCR_CREATE_MONSTER].oc_uname)
943 /* trap doors on "bottom" levels of dungeons are rock-drop
944 * trap doors, not holes in the floor. We check here for
947 if (Is_botlevel(&u.uz))
951 struct trap *t = t_at(trapx, trapy);
954 pline("%s %s into a %s!", Monnam(mtmp),
955 makeplural(locomotion(mtmp->data, "jump")),
956 t->ttyp == TRAPDOOR ? "trap door" : "hole");
958 pline("%s
\82Í%s
\82É%s
\93ü
\82Á
\82½
\81I", Monnam(mtmp),
959 t->ttyp == TRAPDOOR ? "
\97\8e\82µ
\94à" : "
\8c\8a",
960 jconj(locomotion(mtmp->data, "
\94ò
\82Ô"), "
\82Ä"));
962 if (levl[trapx][trapy].typ == SCORR) {
963 levl[trapx][trapy].typ = CORR;
964 unblock_point(trapx, trapy);
966 seetrap(t_at(trapx, trapy));
969 /* don't use rloc_to() because worm tails must "move" */
970 remove_monster(mtmp->mx, mtmp->my);
971 newsym(mtmp->mx, mtmp->my); /* update old location */
972 place_monster(mtmp, trapx, trapy);
975 newsym(trapx, trapy);
977 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
981 /* Monsters without amulets escape the dungeon and are
982 * gone for good when they leave up the up stairs.
983 * Monsters with amulets would reach the endlevel,
984 * which we cannot allow since that would leave the
987 if (ledger_no(&u.uz) == 1) {
988 if (mon_has_special(mtmp))
992 pline("%s escapes the dungeon!", Monnam(mtmp));
994 pline("%s
\82Í
\96À
\8b{
\82©
\82ç
\93¦
\91\96\82µ
\82½
\81I", Monnam(mtmp));
999 if (Inhell && mon_has_amulet(mtmp) && !rn2(4)
1000 && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) {
1004 "As %s climbs the stairs, a mysterious force momentarily surrounds %s...",
1005 mon_nam(mtmp), mhim(mtmp));
1008 "%s
\82ª
\8aK
\92i
\82ð
\82Ì
\82Ú
\82ë
\82¤
\82Æ
\82·
\82é
\82Æ
\8aï
\96
\82È
\97Í
\82ª%s
\82ð
\82Â
\82Â
\82ñ
\82¾
\81D
\81D
\81D",
1009 mon_nam(mtmp), mhim(mtmp));
1011 /* simpler than for the player; this will usually be
1012 the Wizard and he'll immediately go right to the
1013 upstairs, so there's not much point in having any
1014 chance for a random position on the current level */
1015 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
1020 pline("%s escapes upstairs!", Monnam(mtmp));
1022 pline("%s
\82Í
\8aK
\92i
\82ð
\82Ì
\82Ú
\82Á
\82Ä
\93¦
\82°
\82½
\81I", Monnam(mtmp));
1023 migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_STAIRS_DOWN,
1027 case MUSE_DOWNSTAIRS:
1031 pline("%s escapes downstairs!", Monnam(mtmp));
1033 pline("%s
\82Í
\8aK
\92i
\82ð
\8d~
\82è
\82Ä
\93¦
\82°
\82½
\81I", Monnam(mtmp));
1034 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_STAIRS_UP,
1037 case MUSE_UP_LADDER:
1041 pline("%s escapes up the ladder!", Monnam(mtmp));
1043 pline("%s
\82Í
\82Í
\82µ
\82²
\82ð
\82Ì
\82Ú
\82Á
\82Ä
\93¦
\82°
\82½
\81I", Monnam(mtmp));
1044 migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_LADDER_DOWN,
1047 case MUSE_DN_LADDER:
1051 pline("%s escapes down the ladder!", Monnam(mtmp));
1053 pline("%s
\82Í
\82Í
\82µ
\82²
\82ð
\8d~
\82è
\82Ä
\93¦
\82°
\82½
\81I", Monnam(mtmp));
1054 migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_LADDER_UP,
1061 pline("%s escapes %sstairs!", Monnam(mtmp),
1062 sstairs.up ? "up" : "down");
1064 pline("%s
\82Í
\8aK
\92i
\82ð%s
\93¦
\82°
\82½
\81I", Monnam(mtmp),
1065 sstairs.up ? "
\82Ì
\82Ú
\82Á
\82Ä" : "
\8d~
\82è
\82Ä");
1067 /* going from the Valley to Castle (Stronghold) has no sstairs
1068 to target, but having sstairs.<sx,sy> == <0,0> will work the
1069 same as specifying MIGR_RANDOM when mon_arrive() eventually
1070 places the monster, so we can use MIGR_SSTAIRS unconditionally */
1071 migrate_to_level(mtmp, ledger_no(&sstairs.tolev), MIGR_SSTAIRS,
1074 case MUSE_TELEPORT_TRAP:
1078 pline("%s %s onto a teleport trap!", Monnam(mtmp),
1079 makeplural(locomotion(mtmp->data, "jump")));
1081 pline("%s
\82Í
\8fu
\8aÔ
\88Ú
\93®
\82Ìã©
\82É
\94ò
\82Ñ
\8d\9e\82ñ
\82¾
\81I", Monnam(mtmp));
1083 seetrap(t_at(trapx, trapy));
1085 /* don't use rloc_to() because worm tails must "move" */
1086 remove_monster(mtmp->mx, mtmp->my);
1087 newsym(mtmp->mx, mtmp->my); /* update old location */
1088 place_monster(mtmp, trapx, trapy);
1091 newsym(trapx, trapy);
1094 case MUSE_POT_HEALING:
1095 mquaffmsg(mtmp, otmp);
1096 i = d(6 + 2 * bcsign(otmp), 4);
1098 if (mtmp->mhp > mtmp->mhpmax)
1099 mtmp->mhp = ++mtmp->mhpmax;
1100 if (!otmp->cursed && !mtmp->mcansee) {
1104 pline(mcsa, Monnam(mtmp));
1108 pline("%s looks better.", Monnam(mtmp));
1110 pline("%s
\82Í
\8bC
\95ª
\82ª
\82æ
\82
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D", Monnam(mtmp));
1112 makeknown(POT_HEALING);
1113 m_useup(mtmp, otmp);
1115 case MUSE_POT_EXTRA_HEALING:
1116 mquaffmsg(mtmp, otmp);
1117 i = d(6 + 2 * bcsign(otmp), 8);
1119 if (mtmp->mhp > mtmp->mhpmax)
1120 mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2));
1121 if (!mtmp->mcansee) {
1125 pline(mcsa, Monnam(mtmp));
1129 pline("%s looks much better.", Monnam(mtmp));
1131 pline("%s
\82Í
\82Æ
\82Ä
\82à
\8bC
\95ª
\82ª
\82æ
\82
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D", Monnam(mtmp));
1133 makeknown(POT_EXTRA_HEALING);
1134 m_useup(mtmp, otmp);
1136 case MUSE_POT_FULL_HEALING:
1137 mquaffmsg(mtmp, otmp);
1138 if (otmp->otyp == POT_SICKNESS)
1139 unbless(otmp); /* Pestilence */
1140 mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4));
1141 if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) {
1145 pline(mcsa, Monnam(mtmp));
1149 pline("%s looks completely healed.", Monnam(mtmp));
1151 pline("%s
\82Í
\8a®
\91S
\82É
\89ñ
\95\9c\82µ
\82½
\82æ
\82¤
\82¾
\81D", Monnam(mtmp));
1153 makeknown(otmp->otyp);
1154 m_useup(mtmp, otmp);
1156 case MUSE_LIZARD_CORPSE:
1157 /* not actually called for its unstoning effect */
1158 mon_consume_unstone(mtmp, otmp, FALSE, FALSE);
1161 return 0; /* i.e. an exploded wand */
1163 impossible("%s wanted to perform action %d?", Monnam(mtmp),
1172 rnd_defensive_item(mtmp)
1175 struct permonst *pm = mtmp->data;
1176 int difficulty = monstr[(monsndx(pm))];
1179 if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
1180 || pm->mlet == S_GHOST || pm->mlet == S_KOP)
1183 switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + (difficulty > 8))) {
1186 if (level.flags.noteleport && ++trycnt < 2)
1189 return WAN_TELEPORTATION;
1193 return SCR_TELEPORTATION;
1197 return WAN_CREATE_MONSTER;
1200 return SCR_CREATE_MONSTER;
1204 return POT_EXTRA_HEALING;
1206 return (mtmp->data != &mons[PM_PESTILENCE]) ? POT_FULL_HEALING
1209 if (is_floater(pm) || mtmp->isshk || mtmp->isgd || mtmp->ispriest)
1218 #define MUSE_WAN_DEATH 1
1219 #define MUSE_WAN_SLEEP 2
1220 #define MUSE_WAN_FIRE 3
1221 #define MUSE_WAN_COLD 4
1222 #define MUSE_WAN_LIGHTNING 5
1223 #define MUSE_WAN_MAGIC_MISSILE 6
1224 #define MUSE_WAN_STRIKING 7
1225 #define MUSE_SCR_FIRE 8
1226 #define MUSE_POT_PARALYSIS 9
1227 #define MUSE_POT_BLINDNESS 10
1228 #define MUSE_POT_CONFUSION 11
1229 #define MUSE_FROST_HORN 12
1230 #define MUSE_FIRE_HORN 13
1231 #define MUSE_POT_ACID 14
1232 /*#define MUSE_WAN_TELEPORTATION 15*/
1233 #define MUSE_POT_SLEEPING 16
1234 #define MUSE_SCR_EARTH 17
1236 /* Select an offensive item/action for a monster. Returns TRUE iff one is
1240 find_offensive(mtmp)
1243 register struct obj *obj;
1244 boolean reflection_skip = (Reflecting && rn2(2));
1245 struct obj *helmet = which_armor(mtmp, W_ARMH);
1247 m.offensive = (struct obj *) 0;
1249 if (mtmp->mpeaceful || is_animal(mtmp->data) || mindless(mtmp->data)
1250 || nohands(mtmp->data))
1254 if (in_your_sanctuary(mtmp, 0, 0))
1256 if (dmgtype(mtmp->data, AD_HEAL)
1257 && !uwep && !uarmu && !uarm && !uarmh
1258 && !uarms && !uarmg && !uarmc && !uarmf)
1260 /* all offensive items require orthogonal or diagonal targetting */
1261 if (!lined_up(mtmp))
1264 #define nomore(x) if (m.has_offense == x) continue;
1265 /* this picks the last viable item rather than prioritizing choices */
1266 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1267 if (!reflection_skip) {
1268 nomore(MUSE_WAN_DEATH);
1269 if (obj->otyp == WAN_DEATH && obj->spe > 0) {
1271 m.has_offense = MUSE_WAN_DEATH;
1273 nomore(MUSE_WAN_SLEEP);
1274 if (obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) {
1276 m.has_offense = MUSE_WAN_SLEEP;
1278 nomore(MUSE_WAN_FIRE);
1279 if (obj->otyp == WAN_FIRE && obj->spe > 0) {
1281 m.has_offense = MUSE_WAN_FIRE;
1283 nomore(MUSE_FIRE_HORN);
1284 if (obj->otyp == FIRE_HORN && obj->spe > 0) {
1286 m.has_offense = MUSE_FIRE_HORN;
1288 nomore(MUSE_WAN_COLD);
1289 if (obj->otyp == WAN_COLD && obj->spe > 0) {
1291 m.has_offense = MUSE_WAN_COLD;
1293 nomore(MUSE_FROST_HORN);
1294 if (obj->otyp == FROST_HORN && obj->spe > 0) {
1296 m.has_offense = MUSE_FROST_HORN;
1298 nomore(MUSE_WAN_LIGHTNING);
1299 if (obj->otyp == WAN_LIGHTNING && obj->spe > 0) {
1301 m.has_offense = MUSE_WAN_LIGHTNING;
1303 nomore(MUSE_WAN_MAGIC_MISSILE);
1304 if (obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) {
1306 m.has_offense = MUSE_WAN_MAGIC_MISSILE;
1309 nomore(MUSE_WAN_STRIKING);
1310 if (obj->otyp == WAN_STRIKING && obj->spe > 0) {
1312 m.has_offense = MUSE_WAN_STRIKING;
1314 nomore(MUSE_POT_PARALYSIS);
1315 if (obj->otyp == POT_PARALYSIS && multi >= 0) {
1317 m.has_offense = MUSE_POT_PARALYSIS;
1319 nomore(MUSE_POT_BLINDNESS);
1320 if (obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) {
1322 m.has_offense = MUSE_POT_BLINDNESS;
1324 nomore(MUSE_POT_CONFUSION);
1325 if (obj->otyp == POT_CONFUSION) {
1327 m.has_offense = MUSE_POT_CONFUSION;
1329 nomore(MUSE_POT_SLEEPING);
1330 if (obj->otyp == POT_SLEEPING) {
1332 m.has_offense = MUSE_POT_SLEEPING;
1334 nomore(MUSE_POT_ACID);
1335 if (obj->otyp == POT_ACID) {
1337 m.has_offense = MUSE_POT_ACID;
1339 /* we can safely put this scroll here since the locations that
1340 * are in a 1 square radius are a subset of the locations that
1341 * are in wand or throwing range (in other words, always lined_up())
1343 nomore(MUSE_SCR_EARTH);
1344 if (obj->otyp == SCR_EARTH
1345 && ((helmet && is_metallic(helmet)) || mtmp->mconf
1346 || amorphous(mtmp->data) || passes_walls(mtmp->data)
1347 || noncorporeal(mtmp->data) || unsolid(mtmp->data)
1349 && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2
1350 && mtmp->mcansee && haseyes(mtmp->data)
1351 && !Is_rogue_level(&u.uz)
1352 && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
1354 m.has_offense = MUSE_SCR_EARTH;
1357 nomore(MUSE_SCR_FIRE);
1358 if (obj->otyp == SCR_FIRE && resists_fire(mtmp)
1359 && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2
1360 && mtmp->mcansee && haseyes(mtmp->data)) {
1362 m.has_offense = MUSE_SCR_FIRE;
1366 return (boolean) !!m.has_offense;
1373 register struct monst *mtmp;
1374 register struct obj *otmp;
1378 boolean reveal_invis = FALSE;
1379 if (mtmp != &youmonst) {
1380 mtmp->msleeping = 0;
1381 if (mtmp->m_ap_type)
1384 switch (otmp->otyp) {
1386 reveal_invis = TRUE;
1387 if (mtmp == &youmonst) {
1389 makeknown(WAN_STRIKING);
1391 shieldeff(u.ux, u.uy);
1395 pline("
\83{
\83C
\83\93\81I");
1396 } else if (rnd(20) < 10 + u.uac) {
1398 pline_The("wand hits you!");
1400 pline("
\8fñ
\82Í
\82 \82È
\82½
\82É
\96½
\92\86\82µ
\82½
\81I");
1402 if (Half_spell_damage)
1403 tmp = (tmp + 1) / 2;
1405 losehp(tmp, "wand", KILLED_BY_AN);
1407 losehp(tmp, "
\8fÕ
\8c\82\82Ì
\8fñ
\82É
\82æ
\82Á
\82Ä", KILLED_BY_AN);
1410 pline_The("wand misses you.");
1412 pline("
\8fñ
\82Í
\82Í
\82¸
\82ê
\82½
\81D");
1415 } else if (resists_magm(mtmp)) {
1416 shieldeff(mtmp->mx, mtmp->my);
1420 pline("
\83{
\83C
\83\93\81I");
1421 } else if (rnd(20) < 10 + find_mac(mtmp)) {
1424 hit("wand", mtmp, exclam(tmp));
1426 hit("
\8fñ", mtmp, exclam(tmp));
1427 (void) resist(mtmp, otmp->oclass, tmp, TELL);
1428 if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
1429 makeknown(WAN_STRIKING);
1435 if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
1436 makeknown(WAN_STRIKING);
1439 case WAN_TELEPORTATION:
1440 if (mtmp == &youmonst) {
1442 makeknown(WAN_TELEPORTATION);
1445 /* for consistency with zap.c, don't identify */
1446 if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) {
1447 if (cansee(mtmp->mx, mtmp->my))
1449 pline("%s resists the magic!", Monnam(mtmp));
1451 pline("%s
\82Í
\96\82\96@
\82ð
\96h
\82¢
\82¾
\81I", Monnam(mtmp));
1452 } else if (!tele_restrict(mtmp))
1453 (void) rloc(mtmp, TRUE);
1456 case WAN_CANCELLATION:
1457 case SPE_CANCELLATION:
1458 (void) cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE);
1462 if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y)
1463 && !canspotmon(mtmp))
1464 map_invisible(bhitpos.x, bhitpos.y);
1469 /* A modified bhit() for monsters. Based on bhit() in zap.c. Unlike
1470 * buzz(), bhit() doesn't take into account the possibility of a monster
1471 * zapping you, so we need a special function for it. (Unless someone wants
1472 * to merge the two functions...)
1475 mbhit(mon, range, fhitm, fhito, obj)
1476 struct monst *mon; /* monster shooting the wand */
1477 register int range; /* direction and range */
1478 int FDECL((*fhitm), (MONST_P, OBJ_P));
1479 int FDECL((*fhito), (OBJ_P, OBJ_P)); /* fns called when mon/obj hit */
1480 struct obj *obj; /* 2nd arg to fhitm/fhito */
1482 register struct monst *mtmp;
1483 register struct obj *otmp;
1487 bhitpos.x = mon->mx;
1488 bhitpos.y = mon->my;
1489 ddx = sgn(mon->mux - mon->mx);
1490 ddy = sgn(mon->muy - mon->my);
1492 while (range-- > 0) {
1505 if (find_drawbridge(&x, &y))
1506 switch (obj->otyp) {
1508 destroy_drawbridge(x, y);
1510 if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
1511 (*fhitm)(&youmonst, obj);
1513 } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
1514 if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp))
1515 map_invisible(bhitpos.x, bhitpos.y);
1516 (*fhitm)(mtmp, obj);
1519 /* modified by GAN to hit all objects */
1521 int hitanything = 0;
1522 register struct obj *next_obj;
1524 for (otmp = level.objects[bhitpos.x][bhitpos.y]; otmp;
1526 /* Fix for polymorph bug, Tim Wright */
1527 next_obj = otmp->nexthere;
1528 hitanything += (*fhito)(otmp, obj);
1533 typ = levl[bhitpos.x][bhitpos.y].typ;
1534 if (IS_DOOR(typ) || typ == SDOOR) {
1535 switch (obj->otyp) {
1536 /* note: monsters don't use opening or locking magic
1537 at present, but keep these as placeholders */
1541 if (doorlock(obj, bhitpos.x, bhitpos.y)) {
1543 makeknown(obj->otyp);
1544 /* if a shop door gets broken, add it to
1545 the shk's fix list (no cost to player) */
1546 if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
1547 && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE))
1548 add_damage(bhitpos.x, bhitpos.y, 0L);
1554 || (IS_DOOR(typ) && (levl[bhitpos.x][bhitpos.y].doormask
1555 & (D_LOCKED | D_CLOSED)))) {
1563 /* Perform an offensive action for a monster. Must be called immediately
1564 * after find_offensive(). Return values are same as use_defensive().
1571 struct obj *otmp = m.offensive;
1574 /* offensive potions are not drunk, they're thrown */
1575 if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0)
1577 oseen = otmp && canseemon(mtmp);
1579 switch (m.has_offense) {
1580 case MUSE_WAN_DEATH:
1581 case MUSE_WAN_SLEEP:
1584 case MUSE_WAN_LIGHTNING:
1585 case MUSE_WAN_MAGIC_MISSILE:
1586 mzapmsg(mtmp, otmp, FALSE);
1589 makeknown(otmp->otyp);
1591 buzz((int) (-30 - (otmp->otyp - WAN_MAGIC_MISSILE)),
1592 (otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, mtmp->mx, mtmp->my,
1593 sgn(mtmp->mux - mtmp->mx), sgn(mtmp->muy - mtmp->my));
1595 return (mtmp->mhp <= 0) ? 1 : 2;
1596 case MUSE_FIRE_HORN:
1597 case MUSE_FROST_HORN:
1599 makeknown(otmp->otyp);
1601 pline("%s plays a %s!", Monnam(mtmp), xname(otmp));
1603 pline("%s
\82Í%s
\82ð
\90\81\82¢
\82½
\81I", Monnam(mtmp), xname(otmp));
1606 You_hear("a horn being played.");
1608 You_hear("
\83z
\83\8b\83\93\82Ì
\89¹
\82ð
\95·
\82¢
\82½
\81D");
1611 buzz(-30 - ((otmp->otyp == FROST_HORN) ? AD_COLD - 1 : AD_FIRE - 1),
1612 rn1(6, 6), mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx),
1613 sgn(mtmp->muy - mtmp->my));
1615 return (mtmp->mhp <= 0) ? 1 : 2;
1616 case MUSE_WAN_TELEPORTATION:
1617 case MUSE_WAN_STRIKING:
1619 mzapmsg(mtmp, otmp, FALSE);
1622 mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp);
1625 case MUSE_SCR_EARTH: {
1626 /* TODO: handle steeds */
1628 /* don't use monster fields after killing it */
1629 boolean confused = (mtmp->mconf ? TRUE : FALSE);
1630 int mmx = mtmp->mx, mmy = mtmp->my;
1631 boolean is_cursed = otmp->cursed;
1633 mreadmsg(mtmp, otmp);
1634 /* Identify the scroll */
1635 if (canspotmon(mtmp)) {
1637 pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my),
1638 otmp->blessed ? "around" : "above", mon_nam(mtmp));
1640 pline("%s
\82Ì%s
\82Ì%s
\82©
\82ç
\83S
\83\8d\83S
\83\8d\82Æ
\89¹
\82ª
\95·
\82±
\82¦
\82Ä
\82«
\82½
\81D",
1642 otmp->blessed ? "
\82Ü
\82í
\82è" : "
\90^
\8fã",
1643 ceiling(mtmp->mx, mtmp->my));
1646 makeknown(otmp->otyp);
1647 } else if (cansee(mtmp->mx, mtmp->my)) {
1649 pline_The("%s rumbles in the middle of nowhere!",
1651 pline_The("
\82Ç
\82±
\82©
\82Ì%s
\82©
\82ç
\83S
\83\8d\83S
\83\8d\82Æ
\89¹
\82ª
\95·
\82±
\82¦
\82Ä
\82«
\82½
\81D",
1652 ceiling(mtmp->mx, mtmp->my));
1654 map_invisible(mtmp->mx, mtmp->my);
1656 makeknown(otmp->otyp);
1659 /* Loop through the surrounding squares */
1660 for (x = mmx - 1; x <= mmx + 1; x++) {
1661 for (y = mmy - 1; y <= mmy + 1; y++) {
1662 /* Is this a suitable spot? */
1663 if (isok(x, y) && !closed_door(x, y)
1664 && !IS_ROCK(levl[x][y].typ) && !IS_AIR(levl[x][y].typ)
1665 && (((x == mmx) && (y == mmy)) ? !otmp->blessed
1667 && (x != u.ux || y != u.uy)) {
1668 (void) drop_boulder_on_monster(x, y, confused, FALSE);
1672 m_useup(mtmp, otmp);
1673 /* Attack the player */
1674 if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !is_cursed) {
1675 drop_boulder_on_player(confused, !is_cursed, FALSE, TRUE);
1678 return (mtmp->mhp <= 0) ? 1 : 2;
1681 case MUSE_SCR_FIRE: {
1682 boolean vis = cansee(mtmp->mx, mtmp->my);
1684 mreadmsg(mtmp, otmp);
1688 pline("Oh, what a pretty fire!");
1690 pline("
\82í
\82\9f\81C
\82«
\82ê
\82¢
\82È
\89\8a\82¾
\81I");
1692 struct monst *mtmp2;
1697 pline_The("scroll erupts in a tower of flame!");
1699 pline("
\8aª
\95¨
\82©
\82ç
\89Î
\92\8c\82ª
\97§
\82¿
\8f¸
\82Á
\82½
\81I");
1700 shieldeff(mtmp->mx, mtmp->my);
1702 pline("%s is uninjured.", Monnam(mtmp));
1704 pline("%s
\82Í
\8f\9d\82Â
\82©
\82È
\82©
\82Á
\82½
\81D", Monnam(mtmp));
1705 (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
1706 (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
1707 (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
1708 num = (2 * (rn1(3, 3) + 2 * bcsign(otmp)) + 1) / 3;
1709 if (Fire_resistance)
1711 You("are not harmed.");
1713 You("
\8f\9d\82Â
\82©
\82È
\82©
\82Á
\82½
\81D");
1715 if (Half_spell_damage)
1716 num = (num + 1) / 2;
1719 losehp(num, "scroll of fire", KILLED_BY_AN);
1721 losehp(num, "
\89\8a\82Ì
\8aª
\95¨
\82Å", KILLED_BY_AN);
1722 for (mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) {
1723 if (DEADMONSTER(mtmp2)) continue;
1724 if (mtmp == mtmp2) continue;
1725 if (dist2(mtmp2->mx, mtmp2->my, mtmp->mx, mtmp->my) < 3) {
1726 if (resists_fire(mtmp2)) continue;
1728 if (resists_cold(mtmp2))
1729 mtmp2->mhp -= 3 * num;
1730 if (mtmp2->mhp < 1) {
1740 case MUSE_POT_PARALYSIS:
1741 case MUSE_POT_BLINDNESS:
1742 case MUSE_POT_CONFUSION:
1743 case MUSE_POT_SLEEPING:
1745 /* Note: this setting of dknown doesn't suffice. A monster
1746 * which is out of sight might throw and it hits something _in_
1747 * sight, a problem not existing with wands because wand rays
1748 * are not objects. Also set dknown in mthrowu.c.
1750 if (cansee(mtmp->mx, mtmp->my)) {
1753 pline("%s hurls %s!", Monnam(mtmp), singular(otmp, doname));
1755 pline("%s
\82Í%s
\82ð
\8b
\82
\93\8a\82°
\82Â
\82¯
\82½
\81I", Monnam(mtmp), singular(otmp, doname));
1757 m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx),
1758 sgn(mtmp->muy - mtmp->my),
1759 distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp);
1762 return 0; /* i.e. an exploded wand */
1764 impossible("%s wanted to perform action %d?", Monnam(mtmp),
1772 rnd_offensive_item(mtmp)
1775 struct permonst *pm = mtmp->data;
1776 int difficulty = monstr[(monsndx(pm))];
1778 if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
1779 || pm->mlet == S_GHOST || pm->mlet == S_KOP)
1781 if (difficulty > 7 && !rn2(35))
1783 switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) {
1785 struct obj *helmet = which_armor(mtmp, W_ARMH);
1787 if ((helmet && is_metallic(helmet)) || amorphous(pm)
1788 || passes_walls(pm) || noncorporeal(pm) || unsolid(pm))
1790 } /* fall through */
1792 return WAN_STRIKING;
1796 return POT_CONFUSION;
1798 return POT_BLINDNESS;
1800 return POT_SLEEPING;
1802 return POT_PARALYSIS;
1805 return WAN_MAGIC_MISSILE;
1813 return WAN_LIGHTNING;
1819 #define MUSE_POT_GAIN_LEVEL 1
1820 #define MUSE_WAN_MAKE_INVISIBLE 2
1821 #define MUSE_POT_INVISIBILITY 3
1822 #define MUSE_POLY_TRAP 4
1823 #define MUSE_WAN_POLYMORPH 5
1824 #define MUSE_POT_SPEED 6
1825 #define MUSE_WAN_SPEED_MONSTER 7
1826 #define MUSE_BULLWHIP 8
1827 #define MUSE_POT_POLYMORPH 9
1833 register struct obj *obj;
1834 struct permonst *mdat = mtmp->data;
1835 int x = mtmp->mx, y = mtmp->my;
1837 int xx, yy, pmidx = NON_PM;
1838 boolean immobile = (mdat->mmove == 0);
1839 boolean stuck = (mtmp == u.ustuck);
1841 m.misc = (struct obj *) 0;
1843 if (is_animal(mdat) || mindless(mdat))
1845 if (u.uswallow && stuck)
1848 /* We arbitrarily limit to times when a player is nearby for the
1849 * same reason as Junior Pac-Man doesn't have energizers eaten until
1850 * you can see them...
1852 if (dist2(x, y, mtmp->mux, mtmp->muy) > 36)
1855 if (!stuck && !immobile && (mtmp->cham == NON_PM)
1856 && monstr[(pmidx = monsndx(mdat))] < 6) {
1857 boolean ignore_boulders = (verysmall(mdat) || throws_rocks(mdat)
1858 || passes_walls(mdat)),
1859 diag_ok = !NODIAG(pmidx);
1861 for (xx = x - 1; xx <= x + 1; xx++)
1862 for (yy = y - 1; yy <= y + 1; yy++)
1863 if (isok(xx, yy) && (xx != u.ux || yy != u.uy)
1864 && (diag_ok || xx == x || yy == y)
1865 && ((xx == x && yy == y) || !level.monsters[xx][yy]))
1866 if ((t = t_at(xx, yy)) != 0
1867 && (ignore_boulders || !sobj_at(BOULDER, xx, yy))
1868 && !onscary(xx, yy, mtmp)) {
1869 /* use trap if it's the correct type */
1870 if (t->ttyp == POLY_TRAP) {
1873 m.has_misc = MUSE_POLY_TRAP;
1881 #define nomore(x) if (m.has_misc == x) continue
1883 * [bug?] Choice of item is not prioritized; the last viable one
1884 * in the monster's inventory will be chosen.
1885 * 'nomore()' is nearly worthless because it only screens checking
1886 * of duplicates when there is no alternate type in between them.
1888 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1889 /* Monsters shouldn't recognize cursed items; this kludge is
1890 necessary to prevent serious problems though... */
1891 if (obj->otyp == POT_GAIN_LEVEL
1893 || (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) {
1895 m.has_misc = MUSE_POT_GAIN_LEVEL;
1897 nomore(MUSE_BULLWHIP);
1898 if (obj->otyp == BULLWHIP && !mtmp->mpeaceful
1899 /* the random test prevents whip-wielding
1900 monster from attempting disarm every turn */
1901 && uwep && !rn2(5) && obj == MON_WEP(mtmp)
1902 /* hero's location must be known and adjacent */
1903 && mtmp->mux == u.ux && mtmp->muy == u.uy
1904 && distu(mtmp->mx, mtmp->my) <= 2
1905 /* don't bother if it can't work (this doesn't
1906 prevent cursed weapons from being targetted) */
1907 && (canletgo(uwep, "")
1908 || (u.twoweap && canletgo(uswapwep, "")))) {
1910 m.has_misc = MUSE_BULLWHIP;
1912 /* Note: peaceful/tame monsters won't make themselves
1913 * invisible unless you can see them. Not really right, but...
1915 nomore(MUSE_WAN_MAKE_INVISIBLE);
1916 if (obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && !mtmp->minvis
1917 && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible)
1918 && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
1920 m.has_misc = MUSE_WAN_MAKE_INVISIBLE;
1922 nomore(MUSE_POT_INVISIBILITY);
1923 if (obj->otyp == POT_INVISIBILITY && !mtmp->minvis
1924 && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible)
1925 && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
1927 m.has_misc = MUSE_POT_INVISIBILITY;
1929 nomore(MUSE_WAN_SPEED_MONSTER);
1930 if (obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0
1931 && mtmp->mspeed != MFAST && !mtmp->isgd) {
1933 m.has_misc = MUSE_WAN_SPEED_MONSTER;
1935 nomore(MUSE_POT_SPEED);
1936 if (obj->otyp == POT_SPEED && mtmp->mspeed != MFAST && !mtmp->isgd) {
1938 m.has_misc = MUSE_POT_SPEED;
1940 nomore(MUSE_WAN_POLYMORPH);
1941 if (obj->otyp == WAN_POLYMORPH && obj->spe > 0
1942 && (mtmp->cham == NON_PM) && monstr[monsndx(mdat)] < 6) {
1944 m.has_misc = MUSE_WAN_POLYMORPH;
1946 nomore(MUSE_POT_POLYMORPH);
1947 if (obj->otyp == POT_POLYMORPH && (mtmp->cham == NON_PM)
1948 && monstr[monsndx(mdat)] < 6) {
1950 m.has_misc = MUSE_POT_POLYMORPH;
1953 return (boolean) !!m.has_misc;
1957 /* type of monster to polymorph into; defaults to one suitable for the
1958 current level rather than the totally arbitrary choice of newcham() */
1959 static struct permonst *
1960 muse_newcham_mon(mon)
1965 if ((m_armr = which_armor(mon, W_ARM)) != 0) {
1966 if (Is_dragon_scales(m_armr))
1967 return Dragon_scales_to_pm(m_armr);
1968 else if (Is_dragon_mail(m_armr))
1969 return Dragon_mail_to_pm(m_armr);
1979 struct obj *otmp = m.misc;
1980 boolean vis, vismon, oseen;
1983 if ((i = precheck(mtmp, otmp)) != 0)
1985 vis = cansee(mtmp->mx, mtmp->my);
1986 vismon = canseemon(mtmp);
1987 oseen = otmp && vismon;
1989 switch (m.has_misc) {
1990 case MUSE_POT_GAIN_LEVEL:
1991 mquaffmsg(mtmp, otmp);
1993 if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) {
1994 register int tolev = depth(&u.uz) - 1;
1997 get_level(&tolevel, tolev);
1998 /* insurance against future changes... */
1999 if (on_level(&tolevel, &u.uz))
2003 pline("%s rises up, through the %s!", Monnam(mtmp),
2004 ceiling(mtmp->mx, mtmp->my));
2006 pline("%s
\82Í%s
\82ð
\93Ë
\82«
\94²
\82¯
\82½
\81I", Monnam(mtmp),
2007 ceiling(mtmp->mx, mtmp->my));
2009 if (!objects[POT_GAIN_LEVEL].oc_name_known
2010 && !objects[POT_GAIN_LEVEL].oc_uname)
2013 m_useup(mtmp, otmp);
2014 migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM,
2021 pline("%s looks uneasy.", Monnam(mtmp));
2023 pline("%s
\82Í
\95s
\88À
\82°
\82É
\8c©
\82¦
\82é
\81D", Monnam(mtmp));
2024 if (!objects[POT_GAIN_LEVEL].oc_name_known
2025 && !objects[POT_GAIN_LEVEL].oc_uname)
2028 m_useup(mtmp, otmp);
2034 pline("%s seems more experienced.", Monnam(mtmp));
2036 pline("%s
\82Í
\8co
\8c±
\82ð
\90Ï
\82ñ
\82¾
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81D", Monnam(mtmp));
2038 makeknown(POT_GAIN_LEVEL);
2039 m_useup(mtmp, otmp);
2040 if (!grow_up(mtmp, (struct monst *) 0))
2042 /* grew into genocided monster */
2044 case MUSE_WAN_MAKE_INVISIBLE:
2045 case MUSE_POT_INVISIBILITY:
2046 if (otmp->otyp == WAN_MAKE_INVISIBLE) {
2047 mzapmsg(mtmp, otmp, TRUE);
2050 mquaffmsg(mtmp, otmp);
2051 /* format monster's name before altering its visibility */
2052 Strcpy(nambuf, mon_nam(mtmp));
2053 mon_set_minvis(mtmp);
2054 if (vismon && mtmp->minvis) { /* was seen, now invisible */
2055 if (canspotmon(mtmp))
2057 pline("%s body takes on a %s transparency.",
2058 upstart(s_suffix(nambuf)),
2059 Hallucination ? "normal" : "strange");
2061 pline("%s%s
\82Ì
\91Ì
\82Í
\93§
\89ß
\90«
\82ð
\82à
\82Á
\82½
\81D",
2062 Hallucination ? "
\82 \82½
\82è
\82Ü
\82¦
\82È
\82±
\82Æ
\82¾
\82ª" : "
\8aï
\96
\82È
\82±
\82Æ
\82É",
2067 pline("Suddenly you cannot see %s.", nambuf);
2069 pline("%s
\82Í
\93Ë
\91R
\8c©
\82¦
\82È
\82
\82È
\82Á
\82½
\81D", nambuf);
2071 makeknown(otmp->otyp);
2073 if (otmp->otyp == POT_INVISIBILITY) {
2075 you_aggravate(mtmp);
2076 m_useup(mtmp, otmp);
2079 case MUSE_WAN_SPEED_MONSTER:
2080 mzapmsg(mtmp, otmp, TRUE);
2082 mon_adjust_speed(mtmp, 1, otmp);
2084 case MUSE_POT_SPEED:
2085 mquaffmsg(mtmp, otmp);
2086 /* note difference in potion effect due to substantially
2087 different methods of maintaining speed ratings:
2088 player's character becomes "very fast" temporarily;
2089 monster becomes "one stage faster" permanently */
2090 mon_adjust_speed(mtmp, 1, otmp);
2091 m_useup(mtmp, otmp);
2093 case MUSE_WAN_POLYMORPH:
2094 mzapmsg(mtmp, otmp, TRUE);
2096 (void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE);
2098 makeknown(WAN_POLYMORPH);
2100 case MUSE_POT_POLYMORPH:
2101 mquaffmsg(mtmp, otmp);
2104 pline("%s suddenly mutates!", Monnam(mtmp));
2106 pline("%s
\82Í
\93Ë
\91R
\95Ï
\89»
\82µ
\82½
\81I", Monnam(mtmp));
2107 (void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE);
2109 makeknown(POT_POLYMORPH);
2110 m_useup(mtmp, otmp);
2112 case MUSE_POLY_TRAP:
2115 pline("%s deliberately %s onto a polymorph trap!", Monnam(mtmp),
2116 makeplural(locomotion(mtmp->data, "jump")));
2118 pline("%s
\82Í
\82í
\82´
\82Æ
\95Ï
\89»
\82Ìã©
\82É
\94ò
\82Ñ
\82±
\82ñ
\82¾
\81I", Monnam(mtmp));
2121 seetrap(t_at(trapx, trapy));
2123 /* don't use rloc() due to worms */
2124 remove_monster(mtmp->mx, mtmp->my);
2125 newsym(mtmp->mx, mtmp->my);
2126 place_monster(mtmp, trapx, trapy);
2129 newsym(trapx, trapy);
2131 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
2134 /* attempt to disarm hero */
2137 const char *The_whip = vismon ? "The bullwhip" : "A whip";
2139 const char *The_whip = vismon ? "
\95Ú" : "
\95Ú";
2140 int where_to = rn2(4);
2141 struct obj *obj = uwep;
2143 char the_weapon[BUFSZ];
2145 if (!obj || !canletgo(obj, "")
2146 || (u.twoweap && canletgo(uswapwep, "") && rn2(2)))
2149 break; /* shouldn't happen after find_misc() */
2151 Strcpy(the_weapon, the(xname(obj)));
2152 hand = body_part(HAND);
2154 hand = makeplural(hand);
2158 pline("%s flicks a bullwhip towards your %s!", Monnam(mtmp),
2161 pline("%s
\82Í
\82 \82È
\82½
\82Ì%s
\82É
\8cü
\82©
\82Á
\82Ä
\95Ú
\82ð
\91Å
\82Á
\82½
\81I", Monnam(mtmp),
2164 if (obj->otyp == HEAVY_IRON_BALL) {
2166 pline("%s fails to wrap around %s.", The_whip, the_weapon);
2168 pline("%s
\82Í%s
\82É
\82Í
\82©
\82ç
\82Ý
\82Â
\82©
\82È
\82©
\82Á
\82½
\81D", The_whip, the_weapon);
2172 pline("%s wraps around %s you're wielding!", The_whip,
2175 pline("%s
\82Í
\82 \82È
\82½
\82Ì
\91\95\94õ
\82µ
\82Ä
\82¢
\82é%s
\82É
\82©
\82ç
\82Ý
\82Â
\82¢
\82½
\81I", The_whip,
2180 pline("%s welded to your %s%c",
2181 !is_plural(obj) ? "It is" : "They are", hand,
2182 !obj->bknown ? '!' : '.');
2184 pline("
\82µ
\82©
\82µ
\81C
\82»
\82ê
\82Í
\82Ü
\82¾
\82 \82È
\82½
\82Ì%s
\82Ì
\92\86\82É
\82 \82é%s",
2186 !obj->bknown ? "
\81I" : "
\81D");
2188 /* obj->bknown = 1; */ /* welded() takes care of this */
2193 pline_The("whip slips free."); /* not `The_whip' */
2195 pline("
\95Ú
\82Í
\82Ù
\82Ç
\82¯
\82½
\81D"); /* not `The_whip' */
2198 } else if (where_to == 3 && mon_hates_silver(mtmp)
2199 && objects[obj->otyp].oc_material == SILVER) {
2200 /* this monster won't want to catch a silver
2201 weapon; drop it at hero's feet instead */
2204 remove_worn_item(obj, FALSE);
2207 case 1: /* onto floor beneath mon */
2209 pline("%s yanks %s from your %s!", Monnam(mtmp), the_weapon,
2212 pline("%s
\82Í%s
\82ð
\82 \82È
\82½
\82Ì%s
\82©
\82ç
\82®
\82¢
\82Æ
\82Ð
\82Á
\82Ï
\82Á
\82½
\81I", Monnam(mtmp), the_weapon,
2215 place_object(obj, mtmp->mx, mtmp->my);
2217 case 2: /* onto floor beneath you */
2219 pline("%s yanks %s to the %s!", Monnam(mtmp), the_weapon,
2220 surface(u.ux, u.uy));
2222 pline("%s
\82Í%s
\82ð%s
\82É
\88ø
\82«
\97\8e\82µ
\82½
\81I", Monnam(mtmp), the_weapon,
2223 surface(u.ux, u.uy));
2227 case 3: /* into mon's inventory */
2229 pline("%s snatches %s!", Monnam(mtmp), the_weapon);
2231 pline("%s
\82Í%s
\82ð
\92D
\82Á
\82½
\81I", Monnam(mtmp), the_weapon);
2232 (void) mpickobj(mtmp, obj);
2239 return 0; /* i.e. an exploded wand */
2241 impossible("%s wanted to perform action %d?", Monnam(mtmp),
2253 pline("For some reason, %s presence is known to you.",
2255 pline("
\82È
\82º
\82©
\81C
\82 \82È
\82½
\82Í%s
\82Ì
\91¶
\8dÝ
\82É
\8bC
\82ª
\82Â
\82¢
\82½
\81D",
2256 s_suffix(noit_mon_nam(mtmp)));
2259 cliparound(mtmp->mx, mtmp->my);
2261 show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp));
2264 You_feel("aggravated at %s.", noit_mon_nam(mtmp));
2266 You("%s
\82É
\95 \82ª
\82½
\82Á
\82½
\81D", mon_nam(mtmp));
2267 display_nhwindow(WIN_MAP, TRUE);
2269 if (unconscious()) {
2272 nomovemsg = "Aggravated, you are jolted into full consciousness.";
2274 nomovemsg = "
\95 \82ª
\82½
\82Á
\82Ä
\82¢
\82Ä
\81C
\83s
\83\8a\83s
\83\8a\82µ
\82Ä
\82¢
\82é
\81D";
2276 newsym(mtmp->mx, mtmp->my);
2277 if (!canspotmon(mtmp))
2278 map_invisible(mtmp->mx, mtmp->my);
2285 struct permonst *pm = mtmp->data;
2286 int difficulty = monstr[(monsndx(pm))];
2288 if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
2289 || pm->mlet == S_GHOST || pm->mlet == S_KOP)
2291 /* Unlike other rnd_item functions, we only allow _weak_ monsters
2292 * to have this item; after all, the item will be used to strengthen
2293 * the monster and strong monsters won't use it at all...
2295 if (difficulty < 6 && !rn2(30))
2296 return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH;
2298 if (!rn2(40) && !nonliving(pm) && !is_vampshifter(mtmp))
2299 return AMULET_OF_LIFE_SAVING;
2305 return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER;
2307 if (mtmp->mpeaceful && !See_invisible)
2309 return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE;
2311 return POT_GAIN_LEVEL;
2318 searches_for_item(mon, obj)
2322 int typ = obj->otyp;
2324 if (is_animal(mon->data) || mindless(mon->data)
2325 || mon->data == &mons[PM_GHOST]) /* don't loot bones piles */
2328 if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY)
2329 return (boolean) (!mon->minvis && !mon->invis_blkd
2330 && !attacktype(mon->data, AT_GAZE));
2331 if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED)
2332 return (boolean) (mon->mspeed != MFAST);
2334 switch (obj->oclass) {
2338 if (typ == WAN_DIGGING)
2339 return (boolean) !is_floater(mon->data);
2340 if (typ == WAN_POLYMORPH)
2341 return (boolean) (monstr[monsndx(mon->data)] < 6);
2342 if (objects[typ].oc_dir == RAY || typ == WAN_STRIKING
2343 || typ == WAN_TELEPORTATION || typ == WAN_CREATE_MONSTER)
2347 if (typ == POT_HEALING || typ == POT_EXTRA_HEALING
2348 || typ == POT_FULL_HEALING || typ == POT_POLYMORPH
2349 || typ == POT_GAIN_LEVEL || typ == POT_PARALYSIS
2350 || typ == POT_SLEEPING || typ == POT_ACID || typ == POT_CONFUSION)
2352 if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE))
2356 if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER
2357 || typ == SCR_EARTH || typ == SCR_FIRE)
2361 if (typ == AMULET_OF_LIFE_SAVING)
2362 return (boolean) !(nonliving(mon->data) || is_vampshifter(mon));
2363 if (typ == AMULET_OF_REFLECTION)
2367 if (typ == PICK_AXE)
2368 return (boolean) needspick(mon->data);
2369 if (typ == UNICORN_HORN)
2370 return (boolean) (!obj->cursed && !is_unicorn(mon->data));
2371 if (typ == FROST_HORN || typ == FIRE_HORN)
2372 return (obj->spe > 0);
2376 return (boolean) (((mon->misc_worn_check & W_ARMG) != 0L
2377 && touch_petrifies(&mons[obj->corpsenm]))
2378 || (!resists_ston(mon)
2379 && cures_stoning(mon, obj, FALSE)));
2381 return (boolean) (mcould_eat_tin(mon)
2382 && (!resists_ston(mon)
2383 && cures_stoning(mon, obj, TRUE)));
2385 return (boolean) touch_petrifies(&mons[obj->corpsenm]);
2395 mon_reflects(mon, str)
2399 struct obj *orefl = which_armor(mon, W_ARMS);
2401 if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) {
2404 pline(str, s_suffix(mon_nam(mon)), "shield");
2406 pline(str, mon_nam(mon), "
\8f\82");
2407 makeknown(SHIELD_OF_REFLECTION);
2410 } else if (arti_reflects(MON_WEP(mon))) {
2411 /* due to wielded artifact weapon */
2414 pline(str, s_suffix(mon_nam(mon)), "weapon");
2416 pline(str, mon_nam(mon), "
\95\90\8aí");
2418 } else if ((orefl = which_armor(mon, W_AMUL))
2419 && orefl->otyp == AMULET_OF_REFLECTION) {
2422 pline(str, s_suffix(mon_nam(mon)), "amulet");
2424 pline(str, mon_nam(mon), "
\96\82\8f\9c\82¯");
2425 makeknown(AMULET_OF_REFLECTION);
2428 } else if ((orefl = which_armor(mon, W_ARM))
2429 && (orefl->otyp == SILVER_DRAGON_SCALES
2430 || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) {
2433 pline(str, s_suffix(mon_nam(mon)), "armor");
2435 pline(str, mon_nam(mon), "
\8aZ");
2437 } else if (mon->data == &mons[PM_SILVER_DRAGON]
2438 || mon->data == &mons[PM_CHROMATIC_DRAGON]) {
2439 /* Silver dragons only reflect when mature; babies do not */
2442 pline(str, s_suffix(mon_nam(mon)), "scales");
2444 pline(str, mon_nam(mon), "
\97Ø");
2452 const char *fmt, *str;
2454 /* Check from outermost to innermost objects */
2455 if (EReflecting & W_ARMS) {
2458 pline(fmt, str, "shield");
2460 pline(fmt, str, "
\8f\82");
2461 makeknown(SHIELD_OF_REFLECTION);
2464 } else if (EReflecting & W_WEP) {
2465 /* Due to wielded artifact weapon */
2468 pline(fmt, str, "weapon");
2470 pline(fmt, str, "
\95\90\8aí");
2472 } else if (EReflecting & W_AMUL) {
2475 pline(fmt, str, "medallion");
2477 pline(fmt, str, "
\83\81\83_
\83\8a\83I
\83\93");
2478 makeknown(AMULET_OF_REFLECTION);
2481 } else if (EReflecting & W_ARM) {
2484 pline(fmt, str, uskin ? "luster" : "armor");
2486 pline(fmt, str, uskin ? "
\82Â
\82â" : "
\8aZ");
2488 } else if (youmonst.data == &mons[PM_SILVER_DRAGON]) {
2491 pline(fmt, str, "scales");
2493 pline(fmt, str, "
\97Ø");
2499 /* TRUE if the monster ate something */
2501 munstone(mon, by_you)
2508 if (resists_ston(mon))
2510 if (mon->meating || !mon->mcanmove || mon->msleeping)
2512 mon->mstrategy &= ~STRAT_WAITFORU;
2514 tinok = mcould_eat_tin(mon);
2515 for (obj = mon->minvent; obj; obj = obj->nobj) {
2516 if (cures_stoning(mon, obj, tinok)) {
2517 mon_consume_unstone(mon, obj, by_you, TRUE);
2525 mon_consume_unstone(mon, obj, by_you, stoning)
2531 boolean vis = canseemon(mon), tinned = obj->otyp == TIN,
2532 food = obj->otyp == CORPSE || tinned,
2533 acid = obj->otyp == POT_ACID
2534 || (food && acidic(&mons[obj->corpsenm])),
2535 lizard = food && obj->corpsenm == PM_LIZARD;
2536 int nutrit = food ? dog_nutrition(mon, obj) : 0; /* also sets meating */
2538 /* give a "<mon> is slowing down" message and also remove
2539 intrinsic speed (comparable to similar effect on the hero) */
2541 mon_adjust_speed(mon, -3, (struct obj *) 0);
2544 long save_quan = obj->quan;
2548 pline("%s %s %s.", Monnam(mon),
2549 (obj->oclass == POTION_CLASS)
2551 : (obj->otyp == TIN) ? "opens and eats the contents of"
2553 distant_name(obj, doname));
2555 pline("%s
\82Í%s
\82ð%s
\81D", Monnam(mon),
2556 distant_name(obj, doname),
2557 (obj->oclass == POTION_CLASS)
2559 : (obj->otyp == TIN) ? "
\8aJ
\82¯
\82Ä
\92\86\90g
\82ð
\90H
\82×
\82½"
2562 obj->quan = save_quan;
2566 (obj->oclass == POTION_CLASS) ? "drinking" : "chewing");
2568 You_hear("%s
\82Æ
\82¢
\82¤
\89¹
\82ð
\95·
\82¢
\82½
\81D",
2569 (obj->otyp == POT_ACID) ? "
\83S
\83N
\83\93" : "
\83N
\83`
\83\83\83N
\83`
\83\83");
2573 /* obj is now gone */
2575 if (acid && !tinned && !resists_acid(mon)) {
2576 mon->mhp -= rnd(15);
2579 pline("%s has a very bad case of stomach acid.", Monnam(mon));
2581 pline("%s
\82Í
\88Ý
\8e_
\82Ì
\92²
\8eq
\82ª
\82Æ
\82Ä
\82à
\88«
\82¢
\81D", Monnam(mon));
2582 if (mon->mhp <= 0) {
2584 pline("%s dies!", Monnam(mon));
2586 pline("%s
\82Í
\8e\80\82ñ
\82¾
\81I", Monnam(mon));
2594 if (stoning && vis) {
2597 pline("What a pity - %s just ruined a future piece of art!",
2599 pline("
\82È
\82ñ
\82Ä
\82±
\82Æ
\82¾
\81I%s
\82Í
\8c|
\8fp
\8dì
\95i
\82É
\82È
\82ê
\82½
\82©
\82à
\82µ
\82ê
\82È
\82¢
\82Ì
\82É
\81I",
2603 pline("%s seems limber!", Monnam(mon));
2605 pline("%s
\82Í
\91Ì
\82ª
\8f_
\82ç
\82©
\82
\82È
\82Á
\82½
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81I", Monnam(mon));
2607 if (lizard && (mon->mconf || mon->mstun)) {
2610 if (vis && !is_bat(mon->data) && mon->data != &mons[PM_STALKER])
2612 pline("%s seems steadier now.", Monnam(mon));
2614 pline("%s
\82Í
\82æ
\82è
\8fä
\95v
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D", Monnam(mon));
2616 if (mon->mtame && !mon->isminion && nutrit > 0) {
2617 struct edog *edog = EDOG(mon);
2619 if (edog->hungrytime < monstermoves)
2620 edog->hungrytime = monstermoves;
2621 edog->hungrytime += nutrit;
2624 /* use up monster's next move */
2625 mon->movement -= NORMAL_SPEED;
2626 mon->mlstmv = monstermoves;
2629 /* decide whether obj can cure petrification; also used when picking up */
2631 cures_stoning(mon, obj, tinok)
2636 if (obj->otyp == POT_ACID)
2638 if (obj->otyp != CORPSE && (obj->otyp != TIN || !tinok))
2640 /* corpse, or tin that mon can open */
2641 return (boolean) (obj->corpsenm == PM_LIZARD
2642 || (acidic(&mons[obj->corpsenm])
2643 && (obj->corpsenm != PM_GREEN_SLIME
2644 || slimeproof(mon->data))));
2651 struct obj *obj, *mwep;
2654 /* monkeys who manage to steal tins can't open and eat them
2655 even if they happen to also have the appropriate tool */
2656 if (is_animal(mon->data))
2659 mwep = MON_WEP(mon);
2660 welded_wep = mwep && mwelded(mwep);
2661 /* this is different from the player; tin opener or dagger doesn't
2662 have to be wielded, and knife can be used instead of dagger */
2663 for (obj = mon->minvent; obj; obj = obj->nobj) {
2664 /* if stuck with a cursed weapon, don't check rest of inventory */
2665 if (welded_wep && obj != mwep)
2668 if (obj->otyp == TIN_OPENER
2669 || (obj->oclass == WEAPON_CLASS
2670 && (objects[obj->otyp].oc_skill == P_DAGGER
2671 || objects[obj->otyp].oc_skill == P_KNIFE)))
2677 /* TRUE if monster does something to avoid turning into green slime */
2679 munslime(mon, by_you)
2683 struct obj *obj, odummy;
2686 * muse_unslime() gives "mon starts turning green", "mon zaps
2687 * itself with a wand of fire", and "mon's slime burns away"
2688 * messages. Monsters who don't get any chance at that just have
2689 * (via our caller) newcham()'s "mon turns into slime" feedback.
2692 if (slimeproof(mon->data))
2694 if (mon->meating || !mon->mcanmove || mon->msleeping)
2696 mon->mstrategy &= ~STRAT_WAITFORU;
2698 /* if monster can breathe fire, do so upon self; a monster who deals
2699 fire damage by biting, clawing, gazing, and especially exploding
2700 isn't able to cure itself of green slime with its own attack
2701 [possible extension: monst capable of casting high level clerical
2702 spells could toss pillar of fire at self--probably too suicidal] */
2703 if (!mon->mcan && !mon->mspec_used
2704 && attacktype_fordmg(mon->data, AT_BREA, AD_FIRE)) {
2705 odummy = zeroobj; /* otyp == STRANGE_OBJECT */
2706 return muse_unslime(mon, &odummy, by_you);
2709 for (obj = mon->minvent; obj; obj = obj->nobj)
2710 if (cures_sliming(mon, obj))
2711 return muse_unslime(mon, obj, by_you);
2713 /* TODO: check for and move onto an adjacent fire trap */
2718 /* mon uses an item--selected by caller--to burn away incipient slime */
2720 muse_unslime(mon, obj, by_you)
2723 boolean by_you; /* true: if mon kills itself, hero gets credit/blame */
2725 struct obj *odummyp;
2726 int otyp = obj->otyp, dmg;
2727 boolean vis = canseemon(mon), res = TRUE;
2730 pline("%s starts turning %s.", Monnam(mon),
2731 green_mon(mon) ? "into ooze" : hcolor(NH_GREEN));
2732 /* -4 => sliming, causes quiet loss of enhanced speed */
2733 mon_adjust_speed(mon, -4, (struct obj *) 0);
2735 if (otyp == STRANGE_OBJECT) {
2736 /* monster is using fire breath on self */
2738 pline("%s breathes fire on %sself.", Monnam(mon), mhim(mon));
2740 mon->mspec_used = rn1(10, 5);
2741 /* -21 => monster's fire breath; 1 => # of damage dice */
2742 (void) zhitm(mon, by_you ? 21 : -21, 1, &odummyp);
2743 } else if (otyp == SCR_FIRE) {
2746 if (cansee(mon->mx, mon->my))
2747 pline("Oh, what a pretty fire!");
2748 if (vis && !objects[otyp].oc_name_known
2749 && !objects[otyp].oc_uname)
2751 m_useup(mon, obj); /* after docall() */
2752 vis = FALSE; /* skip makeknown() below */
2753 res = FALSE; /* failed to cure sliming */
2755 m_useup(mon, obj); /* before explode() */
2756 dmg = (2 * (rn1(3, 3) + 2 * bcsign(obj)) + 1) / 3;
2757 /* -11 => monster's fireball */
2758 explode(mon->mx, mon->my, -11, dmg, SCROLL_CLASS,
2759 /* by_you: override -11 for mon but not others */
2760 by_you ? -EXPL_FIERY : EXPL_FIERY);
2762 } else { /* wand/horn of fire w/ positive charge count */
2763 mzapmsg(mon, obj, TRUE);
2765 /* -1 => monster's wand of fire; 2 => # of damage dice */
2766 (void) zhitm(mon, by_you ? 1 : -1, 2, &odummyp);
2770 if (res && mon->mhp > 0)
2771 pline("%s slime is burned away!", s_suffix(Monnam(mon)));
2772 if (otyp != STRANGE_OBJECT)
2775 /* use up monster's next move */
2776 mon->movement -= NORMAL_SPEED;
2777 mon->mlstmv = monstermoves;
2781 /* decide whether obj can be used to cure green slime */
2783 cures_sliming(mon, obj)
2787 /* scroll of fire, non-empty wand or horn of fire */
2788 if (obj->otyp == SCR_FIRE)
2789 return (haseyes(mon->data) && mon->mcansee);
2790 /* hero doesn't need hands or even limbs to zap, so mon doesn't either */
2791 return ((obj->otyp == WAN_FIRE || obj->otyp == FIRE_HORN)
2795 /* TRUE if monster appears to be green; for active TEXTCOLOR, we go by
2796 the display color, otherwise we just pick things that seem plausibly
2797 green (which doesn't necessarily match the TEXTCOLOR categorization) */
2802 struct permonst *ptr = mon->data;
2807 if (iflags.use_color)
2808 return (ptr->mcolor == CLR_GREEN || ptr->mcolor == CLR_BRIGHT_GREEN);
2811 if (strstri(ptr->mname, "green"))
2813 switch (monsndx(ptr)) {
2814 case PM_FOREST_CENTAUR:
2815 case PM_GARTER_SNAKE:
2826 if (is_elf(ptr) && !is_prince(ptr) && !is_lord(ptr)
2827 && ptr != &mons[PM_GREY_ELF])