1 /* NetHack 3.6 mon.c $NHDT-Date: 1522540516 2018/03/31 23:55:16 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.250 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Derek S. Ray, 2015. */
4 /* NetHack may be freely redistributed. See license for details. */
6 /* JNetHack Copyright */
7 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
8 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2019 */
9 /* JNetHack may be freely redistributed. See license for details. */
11 /* If you're using precompiled headers, you don't want this either */
20 STATIC_VAR boolean vamp_rise_msg, disintegested;
22 STATIC_DCL void FDECL(sanity_check_single_mon, (struct monst *, BOOLEAN_P,
24 STATIC_DCL boolean FDECL(restrap, (struct monst *));
25 STATIC_DCL long FDECL(mm_aggression, (struct monst *, struct monst *));
26 STATIC_DCL long FDECL(mm_displacement, (struct monst *, struct monst *));
27 STATIC_DCL int NDECL(pick_animal);
28 STATIC_DCL void FDECL(kill_eggs, (struct obj *));
29 STATIC_DCL int FDECL(pickvampshape, (struct monst *));
30 STATIC_DCL boolean FDECL(isspecmon, (struct monst *));
31 STATIC_DCL boolean FDECL(validspecmon, (struct monst *, int));
32 STATIC_DCL struct permonst *FDECL(accept_newcham_form, (int));
33 STATIC_DCL struct obj *FDECL(make_corpse, (struct monst *, unsigned));
34 STATIC_DCL void FDECL(m_detach, (struct monst *, struct permonst *));
35 STATIC_DCL void FDECL(lifesaved_monster, (struct monst *));
37 #define LEVEL_SPECIFIC_NOCORPSE(mdat) \
38 (Is_rogue_level(&u.uz) \
39 || (level.flags.graveyard && is_undead(mdat) && rn2(3)))
42 /* part of the original warning code which was replaced in 3.3.1 */
43 const char *warnings[] = {
45 "white", "pink", "red", "ruby", "purple", "black"
47 "
\94\92\82¢", "
\83s
\83\93\83N
\90F
\82Ì", "
\90Ô
\82¢", "
\83\8b\83r
\81[
\90F
\82Ì", "
\8e\87\82Ì", "
\8d\95\82¢"
53 sanity_check_single_mon(mtmp, chk_geno, msg)
58 if (DEADMONSTER(mtmp))
60 if (mtmp->data < &mons[LOW_PM] || mtmp->data >= &mons[NUMMONS]) {
61 impossible("illegal mon data %s; mnum=%d (%s)",
62 fmt_ptr((genericptr_t) mtmp->data), mtmp->mnum, msg);
64 int mndx = monsndx(mtmp->data);
66 if (mtmp->mnum != mndx) {
67 impossible("monster mnum=%d, monsndx=%d (%s)",
68 mtmp->mnum, mndx, msg);
71 if (chk_geno && (mvitals[mndx].mvflags & G_GENOD) != 0)
72 impossible("genocided %s in play (%s)", mons[mndx].mname, msg);
74 if (mtmp->isshk && !has_eshk(mtmp))
75 impossible("shk without eshk (%s)", msg);
76 if (mtmp->ispriest && !has_epri(mtmp))
77 impossible("priest without epri (%s)", msg);
78 if (mtmp->isgd && !has_egd(mtmp))
79 impossible("guard without egd (%s)", msg);
80 if (mtmp->isminion && !has_emin(mtmp))
81 impossible("minion without emin (%s)", msg);
82 /* guardian angel on astral level is tame but has emin rather than edog */
83 if (mtmp->mtame && !has_edog(mtmp) && !mtmp->isminion)
84 impossible("pet without edog (%s)", msg);
91 struct monst *mtmp, *m;
93 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
94 sanity_check_single_mon(mtmp, TRUE, "fmon");
95 if (DEADMONSTER(mtmp))
97 x = mtmp->mx, y = mtmp->my;
98 if (!isok(x, y) && !(mtmp->isgd && x == 0 && y == 0)) {
99 impossible("mon (%s) claims to be at <%d,%d>?",
100 fmt_ptr((genericptr_t) mtmp), x, y);
101 } else if (mtmp == u.usteed) {
102 /* steed is in fmon list but not on the map; its
103 <mx,my> coordinates should match hero's location */
104 if (x != u.ux || y != u.uy)
105 impossible("steed (%s) claims to be at <%d,%d>?",
106 fmt_ptr((genericptr_t) mtmp), x, y);
107 } else if (level.monsters[x][y] != mtmp) {
108 impossible("mon (%s) at <%d,%d> is not there!",
109 fmt_ptr((genericptr_t) mtmp), x, y);
110 } else if (mtmp->wormno) {
111 sanity_check_worm(mtmp);
115 for (x = 0; x < COLNO; x++)
116 for (y = 0; y < ROWNO; y++)
117 if ((mtmp = level.monsters[x][y]) != 0) {
118 for (m = fmon; m; m = m->nmon)
122 impossible("map mon (%s) at <%d,%d> not in fmon list!",
123 fmt_ptr((genericptr_t) mtmp), x, y);
124 else if (mtmp == u.usteed)
125 impossible("steed (%s) is on the map at <%d,%d>!",
126 fmt_ptr((genericptr_t) mtmp), x, y);
127 else if ((mtmp->mx != x || mtmp->my != y)
128 && mtmp->data != &mons[PM_LONG_WORM])
129 impossible("map mon (%s) at <%d,%d> is found at <%d,%d>?",
130 fmt_ptr((genericptr_t) mtmp),
131 mtmp->mx, mtmp->my, x, y);
134 for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) {
135 sanity_check_single_mon(mtmp, FALSE, "migr");
140 /* convert the monster index of an undead to its living counterpart */
142 undead_to_corpse(mndx)
146 case PM_KOBOLD_ZOMBIE:
147 case PM_KOBOLD_MUMMY:
150 case PM_DWARF_ZOMBIE:
154 case PM_GNOME_ZOMBIE:
167 case PM_VAMPIRE_LORD:
169 case PM_VAMPIRE_MAGE:
171 case PM_HUMAN_ZOMBIE:
175 case PM_GIANT_ZOMBIE:
179 case PM_ETTIN_ZOMBIE:
189 /* Convert the monster index of some monsters (such as quest guardians)
190 * to their generic species type.
192 * Return associated character class monster, rather than species
200 /* Quest guardians */
202 mndx = mode ? PM_ARCHEOLOGIST : PM_HUMAN;
205 mndx = mode ? PM_BARBARIAN : PM_HUMAN;
208 mndx = mode ? PM_CAVEMAN : PM_HUMAN;
211 mndx = mode ? PM_HEALER : PM_HUMAN;
214 mndx = mode ? PM_KNIGHT : PM_HUMAN;
217 mndx = mode ? PM_MONK : PM_HUMAN;
220 mndx = mode ? PM_PRIEST : PM_HUMAN;
223 mndx = mode ? PM_RANGER : PM_HUMAN;
226 mndx = mode ? PM_ROGUE : PM_HUMAN;
229 mndx = mode ? PM_SAMURAI : PM_HUMAN;
232 mndx = mode ? PM_TOURIST : PM_HUMAN;
235 mndx = mode ? PM_WIZARD : PM_HUMAN;
238 mndx = mode ? PM_VALKYRIE : PM_HUMAN;
241 if (mndx >= LOW_PM && mndx < NUMMONS) {
242 struct permonst *ptr = &mons[mndx];
246 else if (is_elf(ptr))
248 else if (is_dwarf(ptr))
250 else if (is_gnome(ptr))
252 else if (is_orc(ptr))
260 /* return monster index if chameleon, or NON_PM if not */
268 * As of 3.6.0 we just check M2_SHAPESHIFTER instead of having a
269 * big switch statement with hardcoded shapeshifter types here.
271 if (mndx >= LOW_PM && is_shapeshifter(&mons[mndx]))
276 /* for deciding whether corpse will carry along full monster data */
277 #define KEEPTRAITS(mon) \
278 ((mon)->isshk || (mon)->mtame || unique_corpstat((mon)->data) \
279 || is_reviver((mon)->data) \
280 /* normally quest leader will be unique, */ \
281 /* but he or she might have been polymorphed */ \
282 || (mon)->m_id == quest_status.leader_m_id \
283 /* special cancellation handling for these */ \
284 || (dmgtype((mon)->data, AD_SEDU) || dmgtype((mon)->data, AD_SSEX)))
286 /* Creates a monster corpse, a "special" corpse, or nothing if it doesn't
287 * leave corpses. Monsters which leave "special" corpses should have
288 * G_NOCORPSE set in order to prevent wishing for one, finding tins of one,
291 STATIC_OVL struct obj *
292 make_corpse(mtmp, corpseflags)
293 register struct monst *mtmp;
294 unsigned corpseflags;
296 register struct permonst *mdat = mtmp->data;
298 struct obj *obj = (struct obj *) 0;
299 struct obj *otmp = (struct obj *) 0;
300 int x = mtmp->mx, y = mtmp->my;
301 int mndx = monsndx(mdat);
302 unsigned corpstatflags = corpseflags;
303 boolean burythem = ((corpstatflags & CORPSTAT_BURIED) != 0);
307 case PM_SILVER_DRAGON:
309 case PM_SHIMMERING_DRAGON:
312 case PM_ORANGE_DRAGON:
313 case PM_WHITE_DRAGON:
314 case PM_BLACK_DRAGON:
316 case PM_GREEN_DRAGON:
317 case PM_YELLOW_DRAGON:
318 /* Make dragon scales. This assumes that the order of the
319 dragons is the same as the order of the scales. */
320 if (!rn2(mtmp->mrevived ? 20 : 3)) {
321 num = GRAY_DRAGON_SCALES + monsndx(mdat) - PM_GRAY_DRAGON;
322 obj = mksobj_at(num, x, y, FALSE, FALSE);
324 obj->cursed = obj->blessed = FALSE;
327 case PM_WHITE_UNICORN:
328 case PM_GRAY_UNICORN:
329 case PM_BLACK_UNICORN:
330 if (mtmp->mrevived && rn2(2)) {
333 pline("%s recently regrown horn crumbles to dust.",
334 s_suffix(Monnam(mtmp)));
336 pline("
\8dÅ
\8bß
\8dÄ
\90¶
\82µ
\82½%s
\82Ì
\8ap
\82Í
\95²
\81X
\82É
\82È
\82Á
\82½
\81D",
340 obj = mksobj_at(UNICORN_HORN, x, y, TRUE, FALSE);
341 if (obj && mtmp->mrevived)
342 obj->degraded_horn = 1;
346 (void) mksobj_at(WORM_TOOTH, x, y, TRUE, FALSE);
349 case PM_VAMPIRE_LORD:
350 /* include mtmp in the mkcorpstat() call */
351 num = undead_to_corpse(mndx);
352 corpstatflags |= CORPSTAT_INIT;
353 obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
354 obj->age -= 100; /* this is an *OLD* corpse */
356 case PM_KOBOLD_MUMMY:
364 case PM_KOBOLD_ZOMBIE:
365 case PM_DWARF_ZOMBIE:
366 case PM_GNOME_ZOMBIE:
369 case PM_HUMAN_ZOMBIE:
370 case PM_GIANT_ZOMBIE:
371 case PM_ETTIN_ZOMBIE:
372 num = undead_to_corpse(mndx);
373 corpstatflags |= CORPSTAT_INIT;
374 obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
375 obj->age -= 100; /* this is an *OLD* corpse */
380 obj = mksobj_at(IRON_CHAIN, x, y, TRUE, FALSE);
381 free_mname(mtmp); /* don't christen obj */
384 num = d(2, 4); /* very low chance of creating all glass gems */
386 obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE);
390 obj = mksobj_at(ROCK, x, y, FALSE, FALSE);
391 obj->quan = (long) (rn2(20) + 50);
392 obj->owt = weight(obj);
396 corpstatflags &= ~CORPSTAT_INIT;
398 mkcorpstat(STATUE, (struct monst *) 0, mdat, x, y, corpstatflags);
403 obj = mksobj_at(QUARTERSTAFF, x, y, TRUE, FALSE);
407 case PM_LEATHER_GOLEM:
410 obj = mksobj_at(LEATHER_ARMOR, x, y, TRUE, FALSE);
414 /* Good luck gives more coins */
415 obj = mkgold((long) (200 - rnl(101)), x, y);
421 obj = mksobj_at(SCR_BLANK_PAPER, x, y, TRUE, FALSE);
424 /* expired puddings will congeal into a large blob;
425 like dragons, relies on the order remaining consistent */
427 case PM_BROWN_PUDDING:
429 case PM_BLACK_PUDDING:
430 /* we have to do this here because most other places
431 expect there to be an object coming back; not this one */
432 obj = mksobj_at(GLOB_OF_BLACK_PUDDING - (PM_BLACK_PUDDING - mndx),
435 while (obj && (otmp = obj_nexto(obj)) != (struct obj *) 0) {
436 pudding_merge_message(obj, otmp);
437 obj = obj_meld(&obj, &otmp);
443 if (mvitals[mndx].mvflags & G_NOCORPSE) {
444 return (struct obj *) 0;
446 corpstatflags |= CORPSTAT_INIT;
447 /* preserve the unique traits of some creatures */
448 obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0,
449 mdat, x, y, corpstatflags);
453 (void) bury_an_obj(obj, &dealloc);
455 return dealloc ? (struct obj *) 0 : obj;
460 /* All special cases should precede the G_NOCORPSE check */
462 if (!obj) return NULL;
464 /* if polymorph or undead turning has killed this monster,
465 prevent the same attack beam from hitting its corpse */
466 if (context.bypasses)
470 obj = oname(obj, MNAME(mtmp));
472 /* Avoid "It was hidden under a green mold corpse!"
473 * during Blind combat. An unseen monster referred to as "it"
474 * could be killed and leave a corpse. If a hider then hid
475 * underneath it, you could be told the corpse type of a
476 * monster that you never knew was there without this.
477 * The code in hitmu() substitutes the word "something"
478 * if the corpses obj->dknown is 0.
480 if (Blind && !sensemon(mtmp))
488 /* check mtmp and water/lava for compatibility, 0 (survived), 1 (died) */
491 register struct monst *mtmp;
493 boolean inpool, inlava, infountain;
495 /* [what about ceiling clingers?] */
496 inpool = (is_pool(mtmp->mx, mtmp->my)
497 && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
498 inlava = (is_lava(mtmp->mx, mtmp->my)
499 && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
500 infountain = IS_FOUNTAIN(levl[mtmp->mx][mtmp->my].typ);
502 /* Flying and levitation keeps our steed out of the liquid */
503 /* (but not water-walking or swimming) */
504 if (mtmp == u.usteed && (Flying || Levitation))
507 /* Gremlin multiplying won't go on forever since the hit points
508 * keep going down, and when it gets to 1 hit point the clone
509 * function will fail.
511 if (mtmp->data == &mons[PM_GREMLIN] && (inpool || infountain) && rn2(3)) {
512 if (split_mon(mtmp, (struct monst *) 0))
513 dryup(mtmp->mx, mtmp->my, FALSE);
515 water_damage_chain(mtmp->minvent, FALSE);
517 } else if (mtmp->data == &mons[PM_IRON_GOLEM] && inpool && !rn2(5)) {
520 if (cansee(mtmp->mx, mtmp->my))
522 pline("%s rusts.", Monnam(mtmp));
524 pline("%s
\82Í
\8eK
\82Ñ
\82½
\81D", Monnam(mtmp));
526 if (mtmp->mhpmax > dam)
533 water_damage_chain(mtmp->minvent, FALSE);
539 * Lava effects much as water effects. Lava likers are able to
540 * protect their stuff. Fire resistant monsters can only protect
543 if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) {
544 if (!resists_fire(mtmp)) {
545 if (cansee(mtmp->mx, mtmp->my)) {
546 struct attack *dummy = &mtmp->data->mattk[0];
547 const char *how = on_fire(mtmp->data, dummy);
550 pline("%s %s.", Monnam(mtmp),
551 !strcmp(how, "boiling") ? "boils away"
552 : !strcmp(how, "melting") ? "melts away"
553 : "burns to a crisp");
554 #else /*mon.c:on_fire()
\82Ì
\95Ô
\82è
\92l*/
555 pline("%s
\82Í%s
\82½
\81D", Monnam(mtmp),
556 !strcmp(how, "
\95¦
\93«
\82µ
\82½") ? "
\95¦
\93«
\82µ"
557 : !strcmp(how, "
\97n
\82¯
\82½") ? "
\97n
\82¯
\82½"
558 : "
\94R
\82¦
\82Ä
\83p
\83\8a\83p
\83\8a\82É
\82È
\82Á");
565 if (cansee(mtmp->mx, mtmp->my))
567 pline("%s surrenders to the fire.", Monnam(mtmp));
569 pline("%s
\82Í
\89\8a\82É
\93Û
\82Ü
\82ê
\82½
\81D", Monnam(mtmp));
571 } else if (cansee(mtmp->mx, mtmp->my))
573 pline("%s burns slightly.", Monnam(mtmp));
575 pline("%s
\82Í
\82¿
\82å
\82Á
\82Æ
\8fÅ
\82°
\82½
\81D", Monnam(mtmp));
578 (void) fire_damage_chain(mtmp->minvent, FALSE, FALSE,
580 (void) rloc(mtmp, FALSE);
586 /* Most monsters drown in pools. flooreffects() will take care of
587 * water damage to dead monsters' inventory, but survivors need to
588 * be handled here. Swimmers are able to protect their stuff...
590 if (!is_clinger(mtmp->data) && !is_swimmer(mtmp->data)
591 && !amphibious(mtmp->data)) {
592 if (cansee(mtmp->mx, mtmp->my)) {
594 pline("%s drowns.", Monnam(mtmp));
596 pline("%s
\82Í
\93M
\82ê
\82½
\81D", Monnam(mtmp));
598 if (u.ustuck && u.uswallow && u.ustuck == mtmp) {
599 /* This can happen after a purple worm plucks you off a
600 flying steed while you are over water. */
602 pline("%s sinks as %s rushes in and flushes you out.",
603 Monnam(mtmp), hliquid("water"));
604 #else /*hliquid
\82Í
\95s
\8e©
\91R
\82É
\82È
\82é
\82Ì
\82Å
\82Æ
\82è
\82 \82¦
\82¸
\8eg
\82í
\82È
\82¢*/
605 pline("%s
\82Í
\90\85\97¬
\82É
\92¾
\82Ý
\81D
\82 \82È
\82½
\82ð
\93f
\82«
\8fo
\82µ
\82½
\81D",
611 water_damage_chain(mtmp->minvent, FALSE);
612 (void) rloc(mtmp, FALSE);
618 /* but eels have a difficult time outside */
619 if (mtmp->data->mlet == S_EEL && !Is_waterlevel(&u.uz)) {
620 /* as mhp gets lower, the rate of further loss slows down */
621 if (mtmp->mhp > 1 && rn2(mtmp->mhp) > rn2(8))
623 monflee(mtmp, 2, FALSE, FALSE);
633 int mmove = mon->data->mmove;
636 /* Note: MSLOW's `+ 1' prevents slowed speed 1 getting reduced to 0;
637 * MFAST's `+ 2' prevents hasted speed 1 from becoming a no-op;
638 * both adjustments have negligible effect on higher speeds.
640 if (mon->mspeed == MSLOW)
641 mmove = (2 * mmove + 1) / 3;
642 else if (mon->mspeed == MFAST)
643 mmove = (4 * mmove + 2) / 3;
645 if (mon == u.usteed && u.ugallop && context.mv) {
646 /* increase movement by a factor of 1.5; also increase variance of
647 movement speed (if it's naturally 24, we don't want it to always
649 mmove = ((rn2(2) ? 4 : 5) * mmove) / 3;
652 /* Randomly round the monster's speed to a multiple of NORMAL_SPEED. This
653 makes it impossible for the player to predict when they'll get a free
654 turn (thus preventing exploits like "melee kiting"), while retaining
655 guarantees about shopkeepers not being outsped by a normal-speed player,
656 normal-speed players being unable to open up a gap when fleeing a
657 normal-speed monster, etc.*/
658 mmove_adj = mmove % NORMAL_SPEED;
660 if (rn2(NORMAL_SPEED) < mmove_adj)
661 mmove += NORMAL_SPEED;
666 /* actions that happen once per ``turn'', regardless of each
667 individual monster's metabolism; some of these might need to
668 be reclassified to occur more in proportion with movement rate */
674 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
675 if (DEADMONSTER(mtmp))
678 /* must check non-moving monsters once/turn in case
679 * they managed to end up in liquid */
680 if (mtmp->data->mmove == 0) {
681 if (vision_full_recalc)
687 /* regenerate hit points */
688 mon_regen(mtmp, FALSE);
690 /* possibly polymorph shapechangers and lycanthropes */
691 if (mtmp->cham >= LOW_PM)
692 decide_to_shapeshift(mtmp, (canspotmon(mtmp)
693 || (u.uswallow && mtmp == u.ustuck))
697 /* gradually time out temporary problems */
698 if (mtmp->mblinded && !--mtmp->mblinded)
700 if (mtmp->mfrozen && !--mtmp->mfrozen)
702 if (mtmp->mfleetim && !--mtmp->mfleetim)
705 /* FIXME: mtmp->mlstmv ought to be updated here */
712 register struct monst *mtmp, *nmtmp;
713 register boolean somebody_can_move = FALSE;
716 * Some of you may remember the former assertion here that
717 * because of deaths and other actions, a simple one-pass
718 * algorithm wasn't possible for movemon. Deaths are no longer
719 * removed to the separate list fdmon; they are simply left in
720 * the chain with hit points <= 0, to be cleaned up at the end
723 * The only other actions which cause monsters to be removed from
724 * the chain are level migrations and losedogs(). I believe losedogs()
725 * is a cleanup routine not associated with monster movements, and
726 * monsters can only affect level migrations on themselves, not others
727 * (hence the fetching of nmon before moving the monster). Currently,
728 * monsters can jump into traps, read cursed scrolls of teleportation,
729 * and drink cursed potions of raise level to change levels. These are
730 * all reflexive at this point. Should one monster be able to level
731 * teleport another, this scheme would have problems.
734 for (mtmp = fmon; mtmp; mtmp = nmtmp) {
735 /* end monster movement early if hero is flagged to leave the level */
738 /* or if the program has lost contact with the user */
739 || program_state.done_hup
742 somebody_can_move = FALSE;
746 /* one dead monster needs to perform a move after death:
747 vault guard whose temporary corridor is still on the map */
748 if (mtmp->isgd && !mtmp->mx && mtmp->mhp <= 0)
749 (void) gd_move(mtmp);
750 if (DEADMONSTER(mtmp))
753 /* Find a monster that we have not treated yet. */
754 if (mtmp->movement < NORMAL_SPEED)
757 mtmp->movement -= NORMAL_SPEED;
758 if (mtmp->movement >= NORMAL_SPEED)
759 somebody_can_move = TRUE;
761 if (vision_full_recalc)
762 vision_recalc(0); /* vision! */
764 /* reset obj bypasses before next monster moves */
765 if (context.bypasses)
771 if (is_hider(mtmp->data)) {
772 /* unwatched mimics and piercers may hide again [MRS] */
775 if (mtmp->m_ap_type == M_AP_FURNITURE
776 || mtmp->m_ap_type == M_AP_OBJECT)
778 if (mtmp->mundetected)
780 } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected
781 && (mtmp->mflee || distu(mtmp->mx, mtmp->my) > 2)
782 && !canseemon(mtmp) && !rn2(4)) {
783 /* some eels end up stuck in isolated pools, where they
784 can't--or at least won't--move, so they never reach
785 their post-move chance to re-hide */
790 /* continue if the monster died fighting */
791 if (Conflict && !mtmp->iswiz && mtmp->mcansee) {
793 * Conflict does not take effect in the first round.
794 * Therefore, A monster when stepping into the area will
795 * get to swing at you.
797 * The call to fightm() must be _last_. The monster might
798 * have died if it returns 1.
800 if (couldsee(mtmp->mx, mtmp->my)
801 && (distu(mtmp->mx, mtmp->my) <= BOLT_LIM * BOLT_LIM)
803 continue; /* mon might have died */
805 if (dochugw(mtmp)) /* otherwise just move the monster */
809 if (any_light_source())
810 vision_full_recalc = 1; /* in case a mon moved with a light source */
811 /* reset obj bypasses after last monster has moved */
812 if (context.bypasses)
815 /* remove dead monsters; dead vault guard will be left at <0,0>
816 if temporary corridor out of vault hasn't been removed yet */
819 /* a monster may have levteleported player -dlc */
822 /* changed levels, so these monsters are dormant */
823 somebody_can_move = FALSE;
826 return somebody_can_move;
829 #define mstoning(obj) \
830 (ofood(obj) && (touch_petrifies(&mons[(obj)->corpsenm]) \
831 || (obj)->corpsenm == PM_MEDUSA))
834 * Maybe eat a metallic object (not just gold).
835 * Return value: 0 => nothing happened, 1 => monster ate something,
836 * 2 => monster died (it must have grown into a genocided form, but
837 * that can't happen at present because nothing which eats objects
838 * has young and old forms).
842 register struct monst *mtmp;
844 register struct obj *otmp;
845 struct permonst *ptr;
846 int poly, grow, heal, mstone;
848 /* If a pet, eating is handled separately, in dog.c */
852 /* Eats topmost metal object if it is there */
853 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp;
854 otmp = otmp->nexthere) {
855 /* Don't eat indigestible/choking/inappropriate objects */
856 if ((mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp))
857 || (otmp->otyp == AMULET_OF_STRANGULATION)
858 || (otmp->otyp == RIN_SLOW_DIGESTION))
860 if (is_metallic(otmp) && !obj_resists(otmp, 5, 95)
861 && touch_artifact(otmp, mtmp)) {
862 if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) {
863 if (canseemon(mtmp) && flags.verbose) {
865 pline("%s eats %s!", Monnam(mtmp),
866 distant_name(otmp, doname));
868 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
869 distant_name(otmp,doname));
872 /* The object's rustproofing is gone now */
873 otmp->oerodeproof = 0;
875 if (canseemon(mtmp) && flags.verbose) {
877 pline("%s spits %s out in disgust!", Monnam(mtmp),
878 distant_name(otmp, doname));
880 pline("%s
\82Í%s
\82ð
\83y
\83b
\82Æ
\93f
\82«
\8fo
\82µ
\82½
\81I", Monnam(mtmp),
881 distant_name(otmp,doname));
885 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
887 pline("%s eats %s!", Monnam(mtmp),
888 distant_name(otmp, doname));
890 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
891 distant_name(otmp,doname));
893 else if (flags.verbose)
895 You_hear("a crunching sound.");
897 You_hear("
\83o
\83\8a\83o
\83\8a\82Æ
\90H
\82×
\82é
\89¹
\82ð
\95·
\82¢
\82½
\81D");
898 mtmp->meating = otmp->owt / 2 + 1;
899 /* Heal up to the object's weight in hp */
900 if (mtmp->mhp < mtmp->mhpmax) {
901 mtmp->mhp += objects[otmp->otyp].oc_weight;
902 if (mtmp->mhp > mtmp->mhpmax)
903 mtmp->mhp = mtmp->mhpmax;
908 } else if (otmp == uchain) {
909 unpunish(); /* frees uchain */
911 poly = polyfodder(otmp);
912 grow = mlevelgain(otmp);
913 heal = mhealup(otmp);
914 mstone = mstoning(otmp);
918 if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
921 ptr = grow_up(mtmp, (struct monst *) 0);
923 if (poly_when_stoned(ptr)) {
926 } else if (!resists_ston(mtmp)) {
929 pline("%s turns to stone!", Monnam(mtmp));
931 pline("%s
\82Í
\90Î
\82É
\82È
\82Á
\82½
\81I", Monnam(mtmp));
933 ptr = (struct permonst *) 0;
936 mtmp->mhp = mtmp->mhpmax;
939 return 2; /* it died */
941 /* Left behind a pile? */
943 (void) mksobj_at(ROCK, mtmp->mx, mtmp->my, TRUE, FALSE);
944 newsym(mtmp->mx, mtmp->my);
952 /* monster eats a pile of objects */
954 meatobj(mtmp) /* for gelatinous cubes */
957 struct obj *otmp, *otmp2;
958 struct permonst *ptr, *original_ptr = mtmp->data;
959 int poly, grow, heal, eyes, count = 0, ecount = 0;
963 /* If a pet, eating is handled separately, in dog.c */
967 /* eat organic objects, including cloth and wood, if present;
968 engulf others, except huge rocks and metal attached to player
969 [despite comment at top, doesn't assume that eater is a g.cube] */
970 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
971 otmp2 = otmp->nexthere;
973 /* touch sensitive items */
974 if (otmp->otyp == CORPSE && is_rider(&mons[otmp->corpsenm])) {
975 /* Rider corpse isn't just inedible; can't engulf it either */
976 (void) revive_corpse(otmp);
978 /* untouchable (or inaccessible) items */
979 } else if ((otmp->otyp == CORPSE
980 && touch_petrifies(&mons[otmp->corpsenm])
981 && !resists_ston(mtmp))
982 /* don't engulf boulders and statues or ball&chain */
983 || otmp->oclass == ROCK_CLASS
984 || otmp == uball || otmp == uchain
985 /* normally mtmp won't have stepped onto scare monster
986 scroll, but if it does, don't eat or engulf that
987 (note: scrolls inside eaten containers will still
989 || otmp->otyp == SCR_SCARE_MONSTER) {
990 /* do nothing--neither eaten nor engulfed */
993 /* inedible items -- engulf these */
994 } else if (!is_organic(otmp) || obj_resists(otmp, 5, 95)
995 || !touch_artifact(otmp, mtmp)
996 /* redundant due to non-organic composition but
997 included for emphasis */
998 || (otmp->otyp == AMULET_OF_STRANGULATION
999 || otmp->otyp == RIN_SLOW_DIGESTION)
1000 /* cockatrice corpses handled above; this
1001 touch_petrifies() check catches eggs */
1002 || ((otmp->otyp == CORPSE || otmp->otyp == EGG
1004 && ((touch_petrifies(&mons[otmp->corpsenm])
1005 && !resists_ston(mtmp))
1006 || (otmp->corpsenm == PM_GREEN_SLIME
1007 && !slimeproof(mtmp->data))))) {
1012 Sprintf(buf, "%s engulfs %s.", Monnam(mtmp),
1013 distant_name(otmp, doname));
1015 Sprintf(buf, "%s
\82Í%s
\82ð
\88ù
\82Ý
\8d\9e\82ñ
\82¾
\81D", Monnam(mtmp),
1016 distant_name(otmp,doname));
1018 else if (ecount == 2)
1020 Sprintf(buf, "%s engulfs several objects.", Monnam(mtmp));
1022 Sprintf(buf, "%s
\82Í
\82¢
\82
\82Â
\82©
\82Ì
\95¨
\82ð
\88ù
\82Ý
\8d\9e\82ñ
\82¾
\81D", Monnam(mtmp));
1023 obj_extract_self(otmp);
1024 (void) mpickobj(mtmp, otmp); /* slurp */
1026 /* lastly, edible items; yum! */
1030 if (cansee(mtmp->mx, mtmp->my)) {
1033 pline("%s eats %s!", Monnam(mtmp),
1034 distant_name(otmp, doname));
1036 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
1037 distant_name(otmp, doname));
1039 /* give this one even if !verbose */
1040 if (otmp->oclass == SCROLL_CLASS
1041 && !strcmpi(OBJ_DESCR(objects[otmp->otyp]), "YUM YUM"))
1042 pline("Yum%c", otmp->blessed ? '!' : '.');
1046 You_hear("a slurping sound.");
1048 You_hear("
\82²
\82
\82ñ
\82Æ
\88ù
\82Ý
\8d\9e\82Þ
\89¹
\82ð
\95·
\82¢
\82½
\81D");
1050 /* Heal up to the object's weight in hp */
1051 if (mtmp->mhp < mtmp->mhpmax) {
1052 mtmp->mhp += objects[otmp->otyp].oc_weight;
1053 if (mtmp->mhp > mtmp->mhpmax)
1054 mtmp->mhp = mtmp->mhpmax;
1056 if (Has_contents(otmp)) {
1057 register struct obj *otmp3;
1059 /* contents of eaten containers become engulfed; this
1060 is arbitrary, but otherwise g.cubes are too powerful */
1061 while ((otmp3 = otmp->cobj) != 0) {
1062 obj_extract_self(otmp3);
1063 if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) {
1064 otmp3->age = monstermoves - otmp3->age;
1065 start_corpse_timeout(otmp3);
1067 (void) mpickobj(mtmp, otmp3);
1070 poly = polyfodder(otmp);
1071 grow = mlevelgain(otmp);
1072 heal = mhealup(otmp);
1073 eyes = (otmp->otyp == CARROT);
1074 delobj(otmp); /* munch */
1077 if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
1080 ptr = grow_up(mtmp, (struct monst *) 0);
1082 mtmp->mhp = mtmp->mhpmax;
1084 if ((eyes || heal) && !mtmp->mcansee)
1085 mcureblindness(mtmp, canseemon(mtmp));
1086 /* in case it polymorphed or died */
1087 if (ptr != original_ptr)
1088 return !ptr ? 2 : 1;
1091 /* Engulf & devour is instant, so don't set meating */
1093 newsym(mtmp->mx, mtmp->my);
1097 if (cansee(mtmp->mx, mtmp->my) && flags.verbose && buf[0])
1099 else if (flags.verbose)
1101 You_hear("%s slurping sound%s.",
1102 (ecount == 1) ? "a" : "several", plur(ecount));
1104 You_hear("
\83Y
\83\8b\83Y
\83\8b\82Æ
\82¢
\82¤
\89¹
\82ð
\95·
\82¢
\82½
\81D");
1107 return (count > 0 || ecount > 0) ? 1 : 0;
1112 register struct monst *mtmp;
1114 register struct obj *gold;
1119 if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) {
1121 mat_idx = objects[gold->otyp].oc_material;
1123 obj_extract_self(gold);
1124 add_to_minv(mtmp, gold);
1125 if (cansee(mtmp->mx, mtmp->my)) {
1126 if (flags.verbose && !mtmp->isgd)
1128 pline("%s picks up some %s.", Monnam(mtmp),
1129 mat_idx == GOLD ? "gold" : "money");
1131 pline("%s
\82Í
\82¨
\8bà
\82ð
\8fE
\82Á
\82½
\81D", Monnam(mtmp));
1133 newsym(mtmp->mx, mtmp->my);
1139 mpickstuff(mtmp, str)
1140 register struct monst *mtmp;
1141 register const char *str;
1143 register struct obj *otmp, *otmp2, *otmp3;
1146 /* prevent shopkeepers from leaving the door of their shop */
1147 if (mtmp->isshk && inhishop(mtmp))
1150 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
1151 otmp2 = otmp->nexthere;
1152 /* Nymphs take everything. Most monsters don't pick up corpses. */
1153 if (!str ? searches_for_item(mtmp, otmp)
1154 : !!(index(str, otmp->oclass))) {
1155 if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
1156 /* let a handful of corpse types thru to can_carry() */
1157 && !touch_petrifies(&mons[otmp->corpsenm])
1158 && otmp->corpsenm != PM_LIZARD
1159 && !acidic(&mons[otmp->corpsenm]))
1161 if (!touch_artifact(otmp, mtmp))
1163 carryamt = can_carry(mtmp, otmp);
1166 if (is_pool(mtmp->mx, mtmp->my))
1168 /* handle cases where the critter can only get some */
1170 if (carryamt != otmp->quan) {
1171 otmp3 = splitobj(otmp, carryamt);
1173 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
1175 pline("%s picks up %s.", Monnam(mtmp),
1176 (distu(mtmp->mx, mtmp->my) <= 5)
1178 : distant_name(otmp3, doname));
1180 pline("%s
\82Í%s
\82ð
\8fE
\82Á
\82½
\81D", Monnam(mtmp),
1181 (distu(mtmp->mx, mtmp->my) <= 5)
1183 : distant_name(otmp3, doname));
1185 obj_extract_self(otmp3); /* remove from floor */
1186 (void) mpickobj(mtmp, otmp3); /* may merge and free otmp3 */
1187 m_dowear(mtmp, FALSE);
1188 newsym(mtmp->mx, mtmp->my);
1189 return TRUE; /* pick only one object */
1202 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1203 if (obj->otyp != BOULDER || !throws_rocks(mtmp->data))
1204 curload += obj->owt;
1216 /* Base monster carrying capacity is equal to human maximum
1217 * carrying capacity, or half human maximum if not strong.
1218 * (for a polymorphed player, the value used would be the
1219 * non-polymorphed carrying capacity instead of max/half max).
1220 * This is then modified by the ratio between the monster weights
1221 * and human weights. Corpseless monsters are given a capacity
1222 * proportional to their size instead of weight.
1224 if (!mtmp->data->cwt)
1225 maxload = (MAX_CARR_CAP * (long) mtmp->data->msize) / MZ_HUMAN;
1226 else if (!strongmonst(mtmp->data)
1227 || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN)))
1228 maxload = (MAX_CARR_CAP * (long) mtmp->data->cwt) / WT_HUMAN;
1230 maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/
1232 if (!strongmonst(mtmp->data))
1238 return (int) maxload;
1241 /* for restricting monsters' object-pickup.
1243 * to support the new pet behavior, this now returns the max # of objects
1244 * that a given monster could pick up from a pile. frequently this will be
1245 * otmp->quan, but special cases for 'only one' now exist so.
1247 * this will probably cause very amusing behavior with pets and gold coins.
1249 * TODO: allow picking up 2-N objects from a pile of N based on weight.
1250 * Change from 'int' to 'long' to accomate big stacks of gold.
1251 * Right now we fake it by reporting a partial quantity, but the
1252 * likesgold handling m_move results in picking up the whole stack.
1255 can_carry(mtmp, otmp)
1259 int iquan, otyp = otmp->otyp, newload = otmp->owt;
1260 struct permonst *mdat = mtmp->data;
1264 return 0; /* can't carry anything */
1266 if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])
1267 && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp))
1269 if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm]))
1271 if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp)
1272 && (otyp != BELL_OF_OPENING || !is_covetous(mdat)))
1275 /* hostile monsters who like gold will pick up the whole stack;
1276 tame mosnters with hands will pick up the partial stack */
1277 iquan = (otmp->quan > (long) LARGEST_INT)
1278 ? 20000 + rn2(LARGEST_INT - 20000 + 1)
1281 /* monsters without hands can't pick up multiple objects at once
1282 * unless they have an engulfing attack
1284 * ...dragons, of course, can always carry gold pieces and gems somehow
1287 boolean glomper = FALSE;
1289 if (mtmp->data->mlet == S_DRAGON
1290 && (otmp->oclass == COIN_CLASS
1291 || otmp->oclass == GEM_CLASS))
1294 for (nattk = 0; nattk < NATTK; nattk++)
1295 if (mtmp->data->mattk[nattk].aatyp == AT_ENGL) {
1299 if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper)
1303 /* steeds don't pick up stuff (to avoid shop abuse) */
1304 if (mtmp == u.usteed)
1307 return iquan; /* no limit */
1308 if (mtmp->mpeaceful && !mtmp->mtame)
1310 /* otherwise players might find themselves obligated to violate
1311 * their alignment if the monster takes something they need
1314 /* special--boulder throwers carry unlimited amounts of boulders */
1315 if (throws_rocks(mdat) && otyp == BOULDER)
1318 /* nymphs deal in stolen merchandise, but not boulders or statues */
1319 if (mdat->mlet == S_NYMPH)
1320 return (otmp->oclass == ROCK_CLASS) ? 0 : iquan;
1322 if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp))
1328 /* return number of acceptable neighbour positions */
1330 mfndpos(mon, poss, info, flag)
1332 coord *poss; /* coord poss[9] */
1333 long *info; /* long info[9] */
1336 struct permonst *mdat = mon->data;
1337 register struct trap *ttmp;
1342 boolean wantpool, poolok, lavaok, nodiag;
1343 boolean rockok = FALSE, treeok = FALSE, thrudoor;
1345 boolean poisongas_ok, in_poisongas;
1347 int gas_glyph = cmap_to_glyph(S_poisoncloud);
1351 nowtyp = levl[x][y].typ;
1353 nodiag = NODIAG(mdat - mons);
1354 wantpool = mdat->mlet == S_EEL;
1355 poolok = (is_flyer(mdat) || is_clinger(mdat)
1356 || (is_swimmer(mdat) && !wantpool));
1357 lavaok = (is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat));
1358 thrudoor = ((flag & (ALLOW_WALL | BUSTDOOR)) != 0L);
1359 poisongas_ok = ((nonliving(mdat) || is_vampshifter(mon)
1360 || breathless(mdat)) || resists_poison(mon));
1361 in_poisongas = ((gas_reg = visible_region_at(x,y)) != 0
1362 && gas_reg->glyph == gas_glyph);
1364 if (flag & ALLOW_DIG) {
1367 /* need to be specific about what can currently be dug */
1368 if (!needspick(mdat)) {
1369 rockok = treeok = TRUE;
1370 } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed
1371 && mon->weapon_check == NO_WEAPON_WANTED) {
1372 rockok = is_pick(mw_tmp);
1373 treeok = is_axe(mw_tmp);
1375 rockok = (m_carrying(mon, PICK_AXE)
1376 || (m_carrying(mon, DWARVISH_MATTOCK)
1377 && !which_armor(mon, W_ARMS)));
1378 treeok = (m_carrying(mon, AXE) || (m_carrying(mon, BATTLE_AXE)
1379 && !which_armor(mon, W_ARMS)));
1381 if (rockok || treeok)
1385 nexttry: /* eels prefer the water, but if there is no water nearby,
1386 they will crawl over land */
1393 maxx = min(x + 1, COLNO - 1);
1394 maxy = min(y + 1, ROWNO - 1);
1395 for (nx = max(1, x - 1); nx <= maxx; nx++)
1396 for (ny = max(0, y - 1); ny <= maxy; ny++) {
1397 if (nx == x && ny == y)
1399 ntyp = levl[nx][ny].typ;
1401 && !((flag & ALLOW_WALL) && may_passwall(nx, ny))
1402 && !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx, ny)))
1404 /* KMH -- Added iron bars */
1405 if (ntyp == IRONBARS && !(flag & ALLOW_BARS))
1407 if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon))
1408 && (((levl[nx][ny].doormask & D_CLOSED) && !(flag & OPENDOOR))
1409 || ((levl[nx][ny].doormask & D_LOCKED)
1410 && !(flag & UNLOCKDOOR))) && !thrudoor)
1412 /* avoid poison gas? */
1413 if (!poisongas_ok && !in_poisongas
1414 && (gas_reg = visible_region_at(nx,ny)) != 0
1415 && gas_reg->glyph == gas_glyph)
1417 /* first diagonal checks (tight squeezes handled below) */
1418 if (nx != x && ny != y
1420 || (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN))
1421 || (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN))
1422 || ((IS_DOOR(nowtyp) || IS_DOOR(ntyp))
1423 && Is_rogue_level(&u.uz))
1424 /* mustn't pass between adjacent long worm segments,
1425 but can attack that way */
1426 || (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny)
1427 && !m_at(nx, ny) && (nx != u.ux || ny != u.uy))))
1429 if ((is_pool(nx, ny) == wantpool || poolok)
1430 && (lavaok || !is_lava(nx, ny))) {
1432 boolean monseeu = (mon->mcansee
1433 && (!Invis || perceives(mdat)));
1434 boolean checkobj = OBJ_AT(nx, ny);
1436 /* Displacement also displaces the Elbereth/scare monster,
1437 * as long as you are visible.
1439 if (Displaced && monseeu && mon->mux == nx && mon->muy == ny) {
1448 if (onscary(dispx, dispy, mon)) {
1449 if (!(flag & ALLOW_SSM))
1451 info[cnt] |= ALLOW_SSM;
1453 if ((nx == u.ux && ny == u.uy)
1454 || (nx == mon->mux && ny == mon->muy)) {
1455 if (nx == u.ux && ny == u.uy) {
1456 /* If it's right next to you, it found you,
1457 * displaced or no. We must set mux and muy
1458 * right now, so when we return we can tell
1459 * that the ALLOW_U means to attack _you_ and
1465 if (!(flag & ALLOW_U))
1467 info[cnt] |= ALLOW_U;
1469 if (MON_AT(nx, ny)) {
1470 struct monst *mtmp2 = m_at(nx, ny);
1471 long mmflag = flag | mm_aggression(mon, mtmp2);
1473 if (mmflag & ALLOW_M) {
1474 info[cnt] |= ALLOW_M;
1476 if (!(mmflag & ALLOW_TM))
1478 info[cnt] |= ALLOW_TM;
1481 mmflag = flag | mm_displacement(mon, mtmp2);
1482 if (!(mmflag & ALLOW_MDISP))
1484 info[cnt] |= ALLOW_MDISP;
1487 /* Note: ALLOW_SANCT only prevents movement, not
1488 attack, into a temple. */
1489 if (level.flags.has_temple && *in_rooms(nx, ny, TEMPLE)
1490 && !*in_rooms(x, y, TEMPLE)
1491 && in_your_sanctuary((struct monst *) 0, nx, ny)) {
1492 if (!(flag & ALLOW_SANCT))
1494 info[cnt] |= ALLOW_SANCT;
1497 if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
1498 if (flag & NOGARLIC)
1500 info[cnt] |= NOGARLIC;
1502 if (checkobj && sobj_at(BOULDER, nx, ny)) {
1503 if (!(flag & ALLOW_ROCK))
1505 info[cnt] |= ALLOW_ROCK;
1507 if (monseeu && onlineu(nx, ny)) {
1510 info[cnt] |= NOTONL;
1512 /* check for diagonal tight squeeze */
1513 if (nx != x && ny != y && bad_rock(mdat, x, ny)
1514 && bad_rock(mdat, nx, y) && cant_squeeze_thru(mon))
1516 /* The monster avoids a particular type of trap if it's
1517 * familiar with the trap type. Pets get ALLOW_TRAPS
1518 * and checking is done in dogmove.c. In either case,
1519 * "harmless" traps are neither avoided nor marked in info[].
1521 if ((ttmp = t_at(nx, ny)) != 0) {
1522 if (ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) {
1524 "A monster looked at a very strange trap of type %d.",
1528 if ((ttmp->ttyp != RUST_TRAP
1529 || mdat == &mons[PM_IRON_GOLEM])
1530 && ttmp->ttyp != STATUE_TRAP
1531 && ((ttmp->ttyp != PIT && ttmp->ttyp != SPIKED_PIT
1532 && ttmp->ttyp != TRAPDOOR && ttmp->ttyp != HOLE)
1533 || (!is_flyer(mdat) && !is_floater(mdat)
1534 && !is_clinger(mdat)) || Sokoban)
1535 && (ttmp->ttyp != SLP_GAS_TRAP || !resists_sleep(mon))
1536 && (ttmp->ttyp != BEAR_TRAP
1537 || (mdat->msize > MZ_SMALL && !amorphous(mdat)
1538 && !is_flyer(mdat) && !is_floater(mdat)
1539 && !is_whirly(mdat) && !unsolid(mdat)))
1540 && (ttmp->ttyp != FIRE_TRAP || !resists_fire(mon))
1541 && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat))
1542 && (ttmp->ttyp != WEB
1543 || (!amorphous(mdat) && !webmaker(mdat)
1544 && !is_whirly(mdat) && !unsolid(mdat)))
1545 && (ttmp->ttyp != ANTI_MAGIC || !resists_magm(mon))) {
1546 if (!(flag & ALLOW_TRAPS)) {
1547 if (mon->mtrapseen & (1L << (ttmp->ttyp - 1)))
1550 info[cnt] |= ALLOW_TRAPS;
1558 if (!cnt && wantpool && !is_pool(x, y)) {
1565 /* Monster against monster special attacks; for the specified monster
1566 combinations, this allows one monster to attack another adjacent one
1567 in the absence of Conflict. There is no provision for targetting
1568 other monsters; just hand to hand fighting when they happen to be
1569 next to each other. */
1571 mm_aggression(magr, mdef)
1572 struct monst *magr, /* monster that is currently deciding where to move */
1573 *mdef; /* another monster which is next to it */
1575 /* supposedly purple worms are attracted to shrieking because they
1576 like to eat shriekers, so attack the latter when feasible */
1577 if (magr->data == &mons[PM_PURPLE_WORM]
1578 && mdef->data == &mons[PM_SHRIEKER])
1579 return ALLOW_M | ALLOW_TM;
1580 /* Various other combinations such as dog vs cat, cat vs rat, and
1581 elf vs orc have been suggested. For the time being we don't
1586 /* Monster displacing another monster out of the way */
1588 mm_displacement(magr, mdef)
1589 struct monst *magr, /* monster that is currently deciding where to move */
1590 *mdef; /* another monster which is next to it */
1592 struct permonst *pa = magr->data, *pd = mdef->data;
1594 /* if attacker can't barge through, there's nothing to do;
1595 or if defender can barge through too, don't let attacker
1596 do so, otherwise they might just end up swapping places
1597 again when defender gets its chance to move */
1598 if ((pa->mflags3 & M3_DISPLACES) != 0 && (pd->mflags3 & M3_DISPLACES) == 0
1599 /* no displacing grid bugs diagonally */
1600 && !(magr->mx != mdef->mx && magr->my != mdef->my
1601 && NODIAG(monsndx(pd)))
1602 /* no displacing trapped monsters or multi-location longworms */
1603 && !mdef->mtrapped && (!mdef->wormno || !count_wsegs(mdef))
1604 /* riders can move anything; others, same size or smaller only */
1605 && (is_rider(pa) || pa->msize >= pd->msize))
1610 /* Is the square close enough for the monster to move or attack into? */
1616 int distance = dist2(mon->mx, mon->my, x, y);
1618 if (distance == 2 && NODIAG(mon->data - mons))
1620 return (boolean) (distance < 3);
1623 /* really free dead monsters */
1627 struct monst **mtmp, *freetmp;
1630 for (mtmp = &fmon; *mtmp;) {
1632 if (freetmp->mhp <= 0 && !freetmp->isgd) {
1633 *mtmp = freetmp->nmon;
1634 freetmp->nmon = NULL;
1635 dealloc_monst(freetmp);
1638 mtmp = &(freetmp->nmon);
1641 if (count != iflags.purge_monsters)
1642 impossible("dmonsfree: %d removed doesn't match %d pending",
1643 count, iflags.purge_monsters);
1644 iflags.purge_monsters = 0;
1647 /* called when monster is moved to larger structure */
1649 replmon(mtmp, mtmp2)
1650 struct monst *mtmp, *mtmp2;
1654 /* transfer the monster's inventory */
1655 for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
1656 if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
1657 impossible("replmon: minvent inconsistency");
1658 otmp->ocarry = mtmp2;
1662 /* remove the old monster from the map and from `fmon' list */
1663 relmon(mtmp, (struct monst **) 0);
1665 /* finish adding its replacement */
1666 if (mtmp != u.usteed) /* don't place steed onto the map */
1667 place_monster(mtmp2, mtmp2->mx, mtmp2->my);
1668 if (mtmp2->wormno) /* update level.monsters[wseg->wx][wseg->wy] */
1669 place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */
1670 if (emits_light(mtmp2->data)) {
1671 /* since this is so rare, we don't have any `mon_move_light_source' */
1672 new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
1673 LS_MONSTER, monst_to_any(mtmp2));
1674 /* here we rely on fact that `mtmp' hasn't actually been deleted */
1675 del_light_source(LS_MONSTER, monst_to_any(mtmp));
1679 if (u.ustuck == mtmp)
1681 if (u.usteed == mtmp)
1684 replshk(mtmp, mtmp2);
1686 /* discard the old monster */
1687 dealloc_monst(mtmp);
1690 /* release mon from the display and the map's monster list,
1691 maybe transfer it to one of the other monster lists */
1693 relmon(mon, monst_list)
1695 struct monst **monst_list; /* &migrating_mons or &mydogs or null */
1698 boolean unhide = (monst_list != 0);
1699 int mx = mon->mx, my = mon->my;
1702 panic("relmon: no fmon available.");
1705 /* can't remain hidden across level changes (exception: wizard
1706 clone can continue imitating some other monster form); also,
1707 might be imitating a boulder so need line-of-sight unblocking */
1708 mon->mundetected = 0;
1709 if (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)
1716 remove_monster(mx, my);
1721 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1722 if (mtmp->nmon == mon)
1726 mtmp->nmon = mon->nmon;
1728 panic("relmon: mon not in list.");
1733 /* insert into mydogs or migrating_mons */
1734 mon->nmon = *monst_list;
1737 /* orphan has no next monster */
1743 copy_mextra(mtmp2, mtmp1)
1744 struct monst *mtmp2, *mtmp1;
1746 if (!mtmp2 || !mtmp1 || !mtmp1->mextra)
1750 mtmp2->mextra = newmextra();
1752 new_mname(mtmp2, (int) strlen(MNAME(mtmp1)) + 1);
1753 Strcpy(MNAME(mtmp2), MNAME(mtmp1));
1758 *EGD(mtmp2) = *EGD(mtmp1);
1763 *EPRI(mtmp2) = *EPRI(mtmp1);
1768 *ESHK(mtmp2) = *ESHK(mtmp1);
1773 *EMIN(mtmp2) = *EMIN(mtmp1);
1778 *EDOG(mtmp2) = *EDOG(mtmp1);
1780 if (has_mcorpsenm(mtmp1))
1781 MCORPSENM(mtmp2) = MCORPSENM(mtmp1);
1788 struct mextra *x = m->mextra;
1792 free((genericptr_t) x->mname);
1794 free((genericptr_t) x->egd);
1796 free((genericptr_t) x->epri);
1798 free((genericptr_t) x->eshk);
1800 free((genericptr_t) x->emin);
1802 free((genericptr_t) x->edog);
1803 /* [no action needed for x->mcorpsenm] */
1805 free((genericptr_t) x);
1806 m->mextra = (struct mextra *) 0;
1815 panic("dealloc_monst with nmon");
1817 dealloc_mextra(mon);
1818 free((genericptr_t) mon);
1821 /* remove effects of mtmp from other data structures */
1823 m_detach(mtmp, mptr)
1825 struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
1827 if (mtmp == context.polearm.hitmon)
1828 context.polearm.hitmon = 0;
1830 m_unleash(mtmp, FALSE);
1831 /* to prevent an infinite relobj-flooreffects-hmon-killed loop */
1833 mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
1834 relobj(mtmp, 0, FALSE);
1835 remove_monster(mtmp->mx, mtmp->my);
1836 if (emits_light(mptr))
1837 del_light_source(LS_MONSTER, monst_to_any(mtmp));
1838 if (mtmp->m_ap_type)
1840 newsym(mtmp->mx, mtmp->my);
1842 fill_pit(mtmp->mx, mtmp->my);
1848 iflags.purge_monsters++;
1851 /* find the worn amulet of life saving which will save a monster */
1856 if (!nonliving(mon->data) || is_vampshifter(mon)) {
1857 struct obj *otmp = which_armor(mon, W_AMUL);
1859 if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING)
1862 return (struct obj *) 0;
1866 lifesaved_monster(mtmp)
1870 struct obj *lifesave = mlifesaver(mtmp);
1873 /* not canseemon; amulets are on the head, so you don't want
1874 * to show this for a long worm with only a tail visible.
1875 * Nor do you check invisibility, because glowing and
1876 * disintegrating amulets are always visible. */
1877 if (cansee(mtmp->mx, mtmp->my)) {
1879 pline("But wait...");
1881 pline("
\82¿
\82å
\82Á
\82Æ
\82Ü
\82Á
\82½
\81D
\81D
\81D");
1883 pline("%s medallion begins to glow!", s_suffix(Monnam(mtmp)));
1885 pline("%s
\82Ì
\96\82\8f\9c\82¯
\82ª
\8bP
\82«
\82Í
\82¶
\82ß
\82½
\81I", Monnam(mtmp));
1886 makeknown(AMULET_OF_LIFE_SAVING);
1887 /* amulet is visible, but monster might not be */
1888 if (canseemon(mtmp)) {
1889 if (attacktype(mtmp->data, AT_EXPL)
1890 || attacktype(mtmp->data, AT_BOOM))
1892 pline("%s reconstitutes!", Monnam(mtmp));
1894 pline("%s
\82Í
\8dÄ
\8d\
\90¬
\82³
\82ê
\82½
\81I", Monnam(mtmp));
1897 pline("%s looks much better!", Monnam(mtmp));
1899 pline("%s
\82Í
\82·
\82Á
\82©
\82è
\89ñ
\95\9c\82µ
\82½
\82æ
\82¤
\82¾
\81I", Monnam(mtmp));
1902 pline_The("medallion crumbles to dust!");
1904 pline("
\96\82\8f\9c\82¯
\82Í
\82±
\82È
\82²
\82È
\82É
\82
\82¾
\82¯
\82½
\81I");
1906 m_useup(mtmp, lifesave);
1908 surviver = !(mvitals[monsndx(mtmp->data)].mvflags & G_GENOD);
1911 if (mtmp->mtame && !mtmp->isminion) {
1912 wary_dog(mtmp, !surviver);
1914 if (mtmp->mhpmax <= 0)
1916 mtmp->mhp = mtmp->mhpmax;
1920 /* genocided monster can't be life-saved */
1921 if (cansee(mtmp->mx, mtmp->my))
1923 pline("Unfortunately, %s is still genocided...", mon_nam(mtmp));
1925 pline("
\8ec
\94O
\82È
\82ª
\82ç%s
\82Í
\8bs
\8eE
\82³
\82ê
\82Ä
\82¢
\82é
\81D
\81D
\81D", mon_nam(mtmp));
1932 register struct monst *mtmp;
1934 struct permonst *mptr;
1937 mtmp->mhp = 0; /* in case caller hasn't done this */
1938 lifesaved_monster(mtmp);
1942 if (is_vampshifter(mtmp)) {
1943 int mndx = mtmp->cham;
1944 int x = mtmp->mx, y = mtmp->my;
1946 /* this only happens if shapeshifted */
1947 if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
1948 && !(mvitals[mndx].mvflags & G_GENOD)) {
1950 boolean in_door = (amorphous(mtmp->data)
1951 && closed_door(mtmp->mx, mtmp->my)),
1953 /* alternate message phrasing for some monster types */
1954 spec_mon = (nonliving(mtmp->data)
1955 || noncorporeal(mtmp->data)
1956 || amorphous(mtmp->data)),
1958 spec_death = (disintegested /* disintegrated or digested */
1959 || noncorporeal(mtmp->data)
1960 || amorphous(mtmp->data));
1962 /* construct a format string before transformation;
1963 will be capitalized when used, expects one %s arg */
1965 Sprintf(buf, "%s suddenly %s and rises as %%s!",
1966 x_monnam(mtmp, ARTICLE_THE,
1967 spec_mon ? (char *) 0 : "seemingly dead",
1968 SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1969 | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1971 spec_death ? "reconstitutes" : "transforms");
1973 Sprintf(buf, "%s%s
\82Í
\93Ë
\91R%s
\81C%%s
\82Æ
\82µ
\82Ä
\91h
\82Á
\82½
\81I",
1974 spec_death ? "" : "
\8e\80\82ñ
\82¾
\82æ
\82¤
\82É
\8ev
\82í
\82ê
\82½",
1975 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
1976 SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1977 | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1979 spec_death ? "
\8dÄ
\8d\
\90¬
\82³
\82ê" : "
\95Ï
\89»
\82µ");
1983 if (mtmp->mhpmax <= 0)
1985 mtmp->mhp = mtmp->mhpmax;
1986 /* this can happen if previously a fog cloud */
1987 if (u.uswallow && (mtmp == u.ustuck))
1988 expels(mtmp, mtmp->data, FALSE);
1992 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
1993 rloc_to(mtmp, new_xy.x, new_xy.y);
1996 newcham(mtmp, &mons[mndx], FALSE, FALSE);
1997 if (mtmp->data == &mons[mndx])
1998 mtmp->cham = NON_PM;
2001 if (canspotmon(mtmp)) {
2002 /* was using a_monnam(mtmp) but that's weird if mtmp is named:
2003 "Dracula suddenly transforms and rises as Dracula" */
2004 pline(upstart(buf), an(mtmp->data->mname));
2005 vamp_rise_msg = TRUE;
2012 /* dead vault guard is actually kept at coordinate <0,0> until
2013 his temporary corridor to/from the vault has been removed;
2014 need to do this after life-saving and before m_detach() */
2015 if (mtmp->isgd && !grddead(mtmp))
2018 /* Player is thrown from his steed when it dies */
2019 if (mtmp == u.usteed)
2020 dismount_steed(DISMOUNT_GENERIC);
2022 mptr = mtmp->data; /* save this for m_detach() */
2023 /* restore chameleon, lycanthropes to true form at death */
2024 if (mtmp->cham >= LOW_PM) {
2025 set_mon_data(mtmp, &mons[mtmp->cham], -1);
2026 mtmp->cham = NON_PM;
2027 } else if (mtmp->data == &mons[PM_WEREJACKAL])
2028 set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL], -1);
2029 else if (mtmp->data == &mons[PM_WEREWOLF])
2030 set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF], -1);
2031 else if (mtmp->data == &mons[PM_WERERAT])
2032 set_mon_data(mtmp, &mons[PM_HUMAN_WERERAT], -1);
2035 * mvitals[].died does double duty as total number of dead monsters
2036 * and as experience factor for the player killing more monsters.
2037 * this means that a dragon dying by other means reduces the
2038 * experience the player gets for killing a dragon directly; this
2039 * is probably not too bad, since the player likely finagled the
2040 * first dead dragon via ring of conflict or pets, and extinguishing
2041 * based on only player kills probably opens more avenues of abuse
2042 * for rings of conflict and such.
2044 tmp = monsndx(mtmp->data);
2045 if (mvitals[tmp].died < 255)
2046 mvitals[tmp].died++;
2048 /* if it's a (possibly polymorphed) quest leader, mark him as dead */
2049 if (mtmp->m_id == quest_status.leader_m_id)
2050 quest_status.leader_is_dead = TRUE;
2052 /* if the mail daemon dies, no more mail delivery. -3. */
2053 if (tmp == PM_MAIL_DAEMON)
2054 mvitals[tmp].mvflags |= G_GENOD;
2057 if (mtmp->data->mlet == S_KOP) {
2058 /* Dead Kops may come back. */
2060 case 1: /* returns near the stairs */
2061 (void) makemon(mtmp->data, xdnstair, ydnstair, NO_MM_FLAGS);
2063 case 2: /* randomly */
2064 (void) makemon(mtmp->data, 0, 0, NO_MM_FLAGS);
2072 if (mtmp->data->msound == MS_NEMESIS)
2074 if (mtmp->data == &mons[PM_MEDUSA])
2075 u.uachieve.killed_medusa = 1;
2076 if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
2077 unmap_object(mtmp->mx, mtmp->my);
2078 m_detach(mtmp, mptr);
2081 /* TRUE if corpse might be dropped, magr may die if mon was swallowed */
2083 corpse_chance(mon, magr, was_swallowed)
2085 struct monst *magr; /* killer, if swallowed */
2086 boolean was_swallowed; /* digestion */
2088 struct permonst *mdat = mon->data;
2091 if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) {
2092 if (cansee(mon->mx, mon->my) && !was_swallowed)
2094 pline("%s body crumbles into dust.", s_suffix(Monnam(mon)));
2096 pline("%s
\82Ì
\91Ì
\82Í
\95²
\81X
\82É
\82È
\82Á
\82½
\81D", Monnam(mon));
2100 /* Gas spores always explode upon death */
2101 for (i = 0; i < NATTK; i++) {
2102 if (mdat->mattk[i].aatyp == AT_BOOM) {
2103 if (mdat->mattk[i].damn)
2104 tmp = d((int) mdat->mattk[i].damn, (int) mdat->mattk[i].damd);
2105 else if (mdat->mattk[i].damd)
2106 tmp = d((int) mdat->mlevel + 1, (int) mdat->mattk[i].damd);
2109 if (was_swallowed && magr) {
2110 if (magr == &youmonst) {
2112 There("is an explosion in your %s!", body_part(STOMACH));
2114 pline("%s
\82Ì
\92\86\82Å
\94\9a\94
\82ª
\8bN
\82«
\82½
\81I", body_part(STOMACH));
2116 Sprintf(killer.name, "%s explosion",
2117 s_suffix(mdat->mname));
2119 Sprintf(killer.name, "%s
\82Ì
\94\9a\94
\82Å", mdat->mname);
2121 losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN);
2124 You_hear("an explosion.");
2126 You_hear("
\94\9a\94
\89¹
\82ð
\95·
\82¢
\82½
\81D");
2130 if (magr->mhp < 1) { /* maybe lifesaved */
2131 if (canspotmon(magr))
2133 pline("%s rips open!", Monnam(magr));
2135 pline("%s
\82Í
\83r
\83\8a\82Á
\82Æ
\94j
\82ê
\82½
\81I", Monnam(magr));
2136 } else if (canseemon(magr))
2138 pline("%s seems to have indigestion.", Monnam(magr));
2140 pline("%s
\82Í
\8fÁ
\89»
\95s
\97Ç
\82Ì
\82æ
\82¤
\82¾
\81D", Monnam(magr));
2147 Sprintf(killer.name, "%s explosion", s_suffix(mdat->mname));
2149 Sprintf(killer.name, "%s
\82Ì
\94\9a\94
\82Å", mdat->mname);
2150 killer.format = KILLED_BY_AN;
2151 explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS);
2152 killer.name[0] = '\0';
2158 /* must duplicate this below check in xkilled() since it results in
2159 * creating no objects as well as no corpse
2161 if (LEVEL_SPECIFIC_NOCORPSE(mdat))
2164 if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned)
2165 || is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat) || mon->isshk)
2167 tmp = 2 + ((mdat->geno & G_FREQ) < 2) + verysmall(mdat);
2168 return (boolean) !rn2(tmp);
2171 /* drop (perhaps) a cadaver and remove monster */
2174 register struct monst *mdef;
2178 return; /* lifesaved */
2180 if (corpse_chance(mdef, (struct monst *) 0, FALSE)
2181 && (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my)))
2182 (void) make_corpse(mdef, CORPSTAT_NONE);
2185 /* monster disappears, not dies */
2190 mdef->mhp = 0; /* can skip some inventory bookkeeping */
2192 /* dead vault guard is actually kept at coordinate <0,0> until
2193 his temporary corridor to/from the vault has been removed */
2194 if (mdef->isgd && !grddead(mdef))
2196 /* hero is thrown from his steed when it disappears */
2197 if (mdef == u.usteed)
2198 dismount_steed(DISMOUNT_GENERIC);
2199 /* stuck to you? release */
2201 /* drop special items like the Amulet so that a dismissed Kop or nurse
2202 can't remove them from the game */
2203 mdrop_special_objs(mdef);
2204 /* release rest of monster's inventory--it is removed from game */
2205 discard_minvent(mdef);
2206 m_detach(mdef, mdef->data);
2209 /* drop a statue or rock and remove monster */
2214 struct obj *otmp, *obj, *oldminvent;
2215 xchar x = mdef->mx, y = mdef->my;
2216 boolean wasinside = FALSE;
2218 if (!vamp_stone(mdef)) /* vampshifter reverts to vampire */
2221 /* we have to make the statue before calling mondead, to be able to
2222 * put inventory in it, and we have to check for lifesaving before
2223 * making the statue....
2225 mdef->mhp = 0; /* in case caller hasn't done this */
2226 lifesaved_monster(mdef);
2230 mdef->mtrapped = 0; /* (see m_detach) */
2232 if ((int) mdef->data->msize > MZ_TINY
2233 || !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) {
2235 /* some objects may end up outside the statue */
2236 while ((obj = mdef->minvent) != 0) {
2237 obj_extract_self(obj);
2239 update_mon_intrinsics(mdef, obj, FALSE, TRUE);
2240 obj_no_longer_held(obj);
2241 if (obj->owornmask & W_WEP)
2242 setmnotwielded(mdef, obj);
2243 obj->owornmask = 0L;
2244 if (obj->otyp == BOULDER
2245 #if 0 /* monsters don't carry statues */
2246 || (obj->otyp == STATUE
2247 && mons[obj->corpsenm].msize >= mdef->data->msize)
2249 /* invocation tools resist even with 0% resistance */
2250 || obj_resists(obj, 0, 0)) {
2252 if (flooreffects(obj, x, y, "fall"))
2254 if (flooreffects(obj, x, y, "
\97\8e\82¿
\82é"))
2256 place_object(obj, x, y);
2259 end_burn(obj, TRUE);
2260 obj->nobj = oldminvent;
2264 /* defer statue creation until after inventory removal
2265 so that saved monster traits won't retain any stale
2266 item-conferred attributes */
2267 otmp = mkcorpstat(STATUE, mdef, mdef->data, x, y, CORPSTAT_NONE);
2268 if (has_mname(mdef))
2269 otmp = oname(otmp, MNAME(mdef));
2270 while ((obj = oldminvent) != 0) {
2271 oldminvent = obj->nobj;
2272 (void) add_to_container(otmp, obj);
2274 /* Archeologists should not break unique statues */
2275 if (mdef->data->geno & G_UNIQ)
2277 otmp->owt = weight(otmp);
2279 otmp = mksobj_at(ROCK, x, y, TRUE, FALSE);
2282 /* mondead() already does this, but we must do it before the newsym */
2283 if (glyph_is_invisible(levl[x][y].glyph))
2287 /* We don't currently trap the hero in the statue in this case but we
2289 if (u.uswallow && u.ustuck == mdef)
2293 if (is_animal(mdef->data))
2295 You("%s through an opening in the new %s.",
2296 locomotion(youmonst.data, "jump"), xname(otmp));
2298 You("
\90V
\82µ
\82
\82Å
\82«
\82½%s
\82©
\82ç%s
\81D",
2299 xname(otmp), jumpedthrough(youmonst.data, "
\94ò
\82Ñ
\8fo
\82½"));
2304 /* another monster has killed the monster mdef */
2306 monkilled(mdef, fltxt, how)
2311 boolean be_sad = FALSE; /* true if unseen pet is killed */
2313 if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my))
2316 pline("%s is %s%s%s!", Monnam(mdef),
2317 nonliving(mdef->data) ? "destroyed" : "killed",
2318 *fltxt ? " by the " : "", fltxt);
2322 pline("%s
\82Í%s
\82É
\82æ
\82Á
\82Ä%s
\81I", Monnam(mdef), fltxt,
2323 nonliving(mdef->data) ? "
\93|
\82³
\82ê
\82½" : "
\8eE
\82³
\82ê
\82½");
2325 pline("%s
\82Í%s
\81I", Monnam(mdef),
2326 nonliving(mdef->data) ? "
\93|
\82³
\82ê
\82½" : "
\8eE
\82³
\82ê
\82½");
2330 be_sad = (mdef->mtame != 0);
2332 /* no corpses if digested or disintegrated */
2333 disintegested = (how == AD_DGST || how == -AD_RBRE);
2339 if (be_sad && mdef->mhp <= 0)
2341 You("have a sad feeling for a moment, then it passes.");
2343 You("
\94ß
\82µ
\82¢
\8bC
\8e\9d\82É
\82¨
\82»
\82í
\82ê
\82½
\82ª
\81C
\82·
\82®
\82É
\89ß
\82¬
\82³
\82Á
\82½
\81D");
2350 if (u.ustuck == mtmp) {
2356 if (Punished && uchain->where != OBJ_FLOOR)
2358 vision_full_recalc = 1;
2360 /* prevent swallower (mtmp might have just poly'd into something
2361 without an engulf attack) from immediately re-engulfing */
2362 if (attacktype(mtmp->data, AT_ENGL) && !mtmp->mspec_used)
2363 mtmp->mspec_used = rnd(2);
2373 xkilled(mtmp, XKILL_GIVEMSG);
2376 /* the player has killed the monster mtmp */
2378 xkilled(mtmp, xkill_flags)
2380 int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */
2382 int tmp, mndx, x = mtmp->mx, y = mtmp->my;
2383 struct permonst *mdat;
2386 boolean wasinside = u.uswallow && (u.ustuck == mtmp),
2388 nomsg = (xkill_flags & XKILL_NOMSG) != 0,
2389 nocorpse = (xkill_flags & XKILL_NOCORPSE) != 0,
2390 noconduct = (xkill_flags & XKILL_NOCONDUCT) != 0;
2392 mtmp->mhp = 0; /* caller will usually have already done this */
2393 if (!noconduct) /* KMH, conduct */
2394 u.uconduct.killer++;
2398 boolean namedpet = has_mname(mtmp) && !Hallucination;
2401 nonliving(mtmp->data) ? "destroy" : "kill",
2402 !(wasinside || canspotmon(mtmp)) ? "it"
2403 : !mtmp->mtame ? mon_nam(mtmp)
2404 : x_monnam(mtmp, namedpet ? ARTICLE_NONE : ARTICLE_THE,
2405 "poor", namedpet ? SUPPRESS_SADDLE : 0, FALSE));
2407 You("%s%s
\82ð
\93|
\82µ
\82½
\81I",
2408 !(wasinside || canspotmon(mtmp)) ? "
\82»
\82ê"
2409 : mtmp->mtame ? "
\82©
\82í
\82¢
\82»
\82¤
\82È" : "",
2414 if (mtmp->mtrapped && (t = t_at(x, y)) != 0
2415 && (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
2416 if (sobj_at(BOULDER, x, y))
2417 nocorpse = TRUE; /* Prevent corpses/treasure being created
2418 "on top" of boulder that is about to fall in.
2419 This is out of order, but cannot be helped
2420 unless this whole routine is rearranged. */
2421 if (m_carrying(mtmp, BOULDER))
2425 /* your pet knows who just killed it...watch out */
2426 if (mtmp->mtame && !mtmp->isminion)
2427 EDOG(mtmp)->killed_by_u = 1;
2429 if (wasinside && thrownobj && thrownobj != uball) {
2430 /* thrown object has killed hero's engulfer; add it to mon's
2431 inventory now so that it will be placed with mon's other
2432 stuff prior to lookhere/autopickup when hero is expelled
2433 below (as a side-effect, this missile has immunity from
2434 being consumed [for this shot/throw only]) */
2435 mpickobj(mtmp, thrownobj);
2436 /* let throwing code know that missile has been disposed of */
2440 vamp_rise_msg = FALSE; /* might get set in mondead(); only checked below */
2441 disintegested = nocorpse; /* alternate vamp_rise message needed if true */
2442 /* dispose of monster and make cadaver */
2447 disintegested = FALSE; /* reset */
2449 if (mtmp->mhp > 0) { /* monster lifesaved */
2450 /* Cannot put the non-visible lifesaving message in
2451 * lifesaved_monster() since the message appears only when _you_
2452 * kill it (as opposed to visible lifesaving which always appears).
2455 if (!cansee(x, y) && !vamp_rise_msg)
2457 pline("Maybe not...");
2459 pline("
\82¢
\82â
\81C
\88á
\82¤
\82©
\82à
\81D
\81D
\81D");
2463 mdat = mtmp->data; /* note: mondead can change mtmp->data */
2464 mndx = monsndx(mdat);
2471 if (nocorpse || LEVEL_SPECIFIC_NOCORPSE(mdat))
2475 if (mdat == &mons[PM_MAIL_DAEMON]) {
2476 stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE));
2479 if (accessible(x, y) || is_pool(x, y)) {
2480 struct obj *cadaver;
2483 /* illogical but traditional "treasure drop" */
2484 if (!rn2(6) && !(mvitals[mndx].mvflags & G_NOCORPSE)
2485 /* no extra item from swallower or steed */
2486 && (x != u.ux || y != u.uy)
2487 /* no extra item from kops--too easy to abuse */
2488 && mdat->mlet != S_KOP
2489 /* no items from cloned monsters */
2490 && !mtmp->mcloned) {
2491 otmp = mkobj(RANDOM_CLASS, TRUE);
2492 /* don't create large objects from small monsters */
2494 if (mdat->msize < MZ_HUMAN && otyp != FIGURINE
2495 /* oc_big is also oc_bimanual and oc_bulky */
2496 && (otmp->owt > 30 || objects[otyp].oc_big)) {
2499 } else if (!flooreffects(otmp, x, y, nomsg ? "" : "fall")) {
2501 } else if (!flooreffects(otmp, x, y, nomsg ? "" : "
\97\8e\82¿
\82é")) {
2503 place_object(otmp, x, y);
2507 /* corpse--none if hero was inside the monster */
2508 if (!wasinside && corpse_chance(mtmp, (struct monst *) 0, FALSE)) {
2509 cadaver = make_corpse(mtmp, burycorpse ? CORPSTAT_BURIED
2511 if (burycorpse && cadaver && cansee(x, y) && !mtmp->minvis
2512 && cadaver->where == OBJ_BURIED && !nomsg) {
2514 pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp)));
2516 pline("%s
\82Ì
\8e\80\91Ì
\82Í
\96\84\82Ü
\82Á
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D", Monnam(mtmp));
2521 spoteffects(TRUE); /* poor man's expels() */
2522 /* monster is gone, corpse or other object might now be visible */
2526 /* punish bad behaviour */
2528 && (!always_hostile(mdat) && mtmp->malign <= 0)
2529 && (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD)
2530 && u.ualign.type != A_CHAOTIC) {
2531 HTelepat &= ~INTRINSIC;
2536 You("
\8eE
\90l
\8bS
\82¾
\81I");
2537 if (Blind && !Blind_telepat)
2538 see_monsters(); /* Can't sense monsters any more. */
2540 if ((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame)
2542 if (is_unicorn(mdat) && sgn(u.ualign.type) == sgn(mdat->maligntyp)) {
2545 You_feel("guilty...");
2547 You("
\8dß
\82ð
\8a´
\82¶
\82½
\81D
\81D
\81D");
2550 /* give experience points */
2551 tmp = experience(mtmp, (int) mvitals[mndx].died);
2552 more_experienced(tmp, 0);
2553 newexplevel(); /* will decide if you go up */
2555 /* adjust alignment points */
2556 if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */
2557 adjalign(-(u.ualign.record + (int) ALIGNLIM / 2));
2559 pline("That was %sa bad idea...",
2560 u.uevent.qcompleted ? "probably " : "");
2562 pline("%s
\82æ
\82
\82È
\82¢
\8ds
\88×
\82¾
\82Á
\82½
\81D
\81D
\81D",
2563 u.uevent.qcompleted ? "
\82½
\82Ô
\82ñ" : "");
2565 } else if (mdat->msound == MS_NEMESIS) { /* Real good! */
2566 adjalign((int) (ALIGNLIM / 4));
2567 } else if (mdat->msound == MS_GUARDIAN) { /* Bad */
2568 adjalign(-(int) (ALIGNLIM / 8));
2571 pline("That was probably a bad idea...");
2573 pline("
\82æ
\82
\82È
\82¢
\8ds
\88×
\82¾
\82Á
\82½
\81D
\81D
\81D");
2576 pline("Whoopsie-daisy!");
2578 pline("
\83V
\83\93\83W
\83}
\83b
\83^
\81[
\81I");
2579 } else if (mtmp->ispriest) {
2580 adjalign((p_coaligned(mtmp)) ? -2 : 2);
2581 /* cancel divine protection for killing your priest */
2582 if (p_coaligned(mtmp))
2584 if (mdat->maligntyp == A_NONE)
2585 adjalign((int) (ALIGNLIM / 4)); /* BIG bonus */
2586 } else if (mtmp->mtame) {
2587 adjalign(-15); /* bad!! */
2588 /* your god is mighty displeased... */
2591 You_hear("the rumble of distant thunder...");
2593 You_hear("
\89\93\82
\82Å
\97\8b\96Â
\82ð
\95·
\82¢
\82½
\81D
\81D
\81D");
2596 You_hear("the studio audience applaud!");
2598 pline("
\92®
\8fO
\82Ì
\8a\85\8dÑ
\82ð
\97\81\82Ñ
\82½
\81I");
2599 } else if (mtmp->mpeaceful)
2602 /* malign was already adjusted for u.ualign.type and randomization */
2603 adjalign(mtmp->malign);
2606 /* changes the monster into a stone monster of the same type
2607 this should only be called when poly_when_stoned() is true */
2612 if (mtmp->data->mlet == S_GOLEM) {
2613 /* it's a golem, and not a stone golem */
2614 if (canseemon(mtmp))
2616 pline("%s solidifies...", Monnam(mtmp));
2618 pline("%s
\82Í
\8bÃ
\8cÅ
\82µ
\82½
\81D
\81D
\81D", Monnam(mtmp));
2619 if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) {
2620 if (canseemon(mtmp))
2622 pline("Now it's %s.", an(mtmp->data->mname));
2624 pline("
\82È
\82ñ
\82Æ%s
\82É
\82È
\82Á
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D", mtmp->data->mname);
2626 if (canseemon(mtmp))
2628 pline("... and returns to normal.");
2630 pline("
\81D
\81D
\81D
\82»
\82µ
\82Ä
\95\81\92Ê
\82É
\96ß
\82Á
\82½
\81D");
2633 impossible("Can't polystone %s!", a_monnam(mtmp));
2640 if (is_vampshifter(mtmp)) {
2641 int mndx = mtmp->cham;
2642 int x = mtmp->mx, y = mtmp->my;
2644 /* this only happens if shapeshifted */
2645 if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
2646 && !(mvitals[mndx].mvflags & G_GENOD)) {
2648 boolean in_door = (amorphous(mtmp->data)
2649 && closed_door(mtmp->mx, mtmp->my));
2651 /* construct a format string before transformation */
2653 Sprintf(buf, "The lapidifying %s %s %s",
2654 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2655 (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2656 | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2657 amorphous(mtmp->data) ? "coalesces on the"
2658 : is_flyer(mtmp->data) ? "drops to the"
2662 Sprintf(buf, "
\90Î
\89»
\82µ
\82Â
\82Â
\82 \82é%s
\82ª%s%s",
2663 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2664 (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2665 | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2667 amorphous(mtmp->data) ? "
\82Ì
\8fã
\82Å
\97Z
\8d\87\82µ
\82½"
2668 : is_flyer(mtmp->data) ? "
\82É
\97\8e\82¿
\82½"
2669 : "
\82Ì
\8fã
\82Å
\90g
\82à
\82¾
\82¦
\82½");
2673 if (mtmp->mhpmax <= 0)
2675 mtmp->mhp = mtmp->mhpmax;
2676 /* this can happen if previously a fog cloud */
2677 if (u.uswallow && (mtmp == u.ustuck))
2678 expels(mtmp, mtmp->data, FALSE);
2682 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
2683 rloc_to(mtmp, new_xy.x, new_xy.y);
2686 if (canspotmon(mtmp)) {
2690 pline("%s
\81I", buf);
2691 display_nhwindow(WIN_MESSAGE, FALSE);
2693 newcham(mtmp, &mons[mndx], FALSE, FALSE);
2694 if (mtmp->data == &mons[mndx])
2695 mtmp->cham = NON_PM;
2698 if (canspotmon(mtmp)) {
2700 pline("%s rises from the %s with renewed agility!",
2701 Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2703 pline("%s
\82Í
\8b@
\95q
\82³
\82ð
\8eæ
\82è
\96ß
\82µ
\82Ä%s
\82©
\82ç
\95\9c\8a\88\82µ
\82½
\81I",
2704 Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2707 newsym(mtmp->mx, mtmp->my);
2708 return FALSE; /* didn't petrify */
2714 /* drop monster into "limbo" - that is, migrate to the current level */
2720 mdrop_special_objs(mtmp);
2721 migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_APPROX_XY, NULL);
2724 /* make monster mtmp next to you (if possible);
2725 might place monst on far side of a wall or boulder */
2731 boolean couldspot = canspotmon(mtmp);
2733 if (mtmp == u.usteed) {
2734 /* Keep your steed in sync with you instead */
2740 if (!enexto(&mm, u.ux, u.uy, mtmp->data)) {
2744 if (!isok(mm.x, mm.y))
2746 rloc_to(mtmp, mm.x, mm.y);
2747 if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) {
2748 mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */
2749 if (!couldspot && canspotmon(mtmp))
2751 pline("%s suddenly %s!", Amonnam(mtmp),
2752 !Blind ? "appears" : "arrives");
2754 pline("
\93Ë
\91R%s
\82ª
\8c»
\82ê
\82½
\81I", Amonnam(mtmp));
2760 /* like mnexto() but requires destination to be directly accessible */
2766 struct permonst *ptr = mtmp->data;
2767 boolean diagok = !NODIAG(ptr - mons);
2771 if (!enexto(&mm, u.ux, u.uy, ptr))
2773 if (couldsee(mm.x, mm.y)
2774 /* don't move grid bugs diagonally */
2775 && (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) {
2776 rloc_to(mtmp, mm.x, mm.y);
2779 } while (--tryct > 0);
2783 * Put monster near (or at) location if possible.
2785 * true if relocation was successful
2789 mnearto(mtmp, x, y, move_other)
2790 register struct monst *mtmp;
2792 boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */
2794 struct monst *othermon = (struct monst *) 0;
2798 if (mtmp->mx == x && mtmp->my == y)
2801 if (move_other && (othermon = m_at(x, y)) != 0) {
2802 if (othermon->wormno)
2803 remove_worm(othermon);
2805 remove_monster(x, y);
2810 if (!goodpos(newx, newy, mtmp, 0)) {
2811 /* Actually we have real problems if enexto ever fails.
2812 * Migrating_mons that need to be placed will cause
2813 * no end of trouble.
2815 if (!enexto(&mm, newx, newy, mtmp->data))
2817 if (!isok(mm.x,mm.y))
2822 rloc_to(mtmp, newx, newy);
2824 if (move_other && othermon) {
2825 xchar oldx = othermon->mx, oldy = othermon->my;
2827 othermon->mx = othermon->my = 0;
2828 (void) mnearto(othermon, x, y, FALSE);
2829 if (othermon->mx == 0 && othermon->my == 0) {
2831 othermon->mx = oldx;
2832 othermon->my = oldy;
2833 m_into_limbo(othermon);
2840 /* monster responds to player action; not the same as a passive attack;
2841 assumes reason for response has been tested, and response _must_ be made */
2846 if (mtmp->data->msound == MS_SHRIEK) {
2849 pline("%s shrieks.", Monnam(mtmp));
2851 pline("%s
\82Í
\8bà
\90Ø
\82è
\90º
\82ð
\82 \82°
\82½
\81D", Monnam(mtmp));
2856 (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
2858 (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS);
2862 if (mtmp->data == &mons[PM_MEDUSA]) {
2865 for (i = 0; i < NATTK; i++)
2866 if (mtmp->data->mattk[i].aatyp == AT_GAZE) {
2867 (void) gazemu(mtmp, &mtmp->data->mattk[i]);
2873 /* Called whenever the player attacks mtmp; also called in other situations
2874 where mtmp gets annoyed at the player. Handles mtmp getting annoyed at the
2875 attack and any ramifications that might have. Useful also in situations
2876 where mtmp was already hostile; it checks for situations where the player
2877 shouldn't be attacking and any ramifications /that/ might have. */
2879 setmangry(mtmp, via_attack)
2883 if (via_attack && sengr_at("Elbereth", u.ux, u.uy, TRUE)) {
2885 You_feel("like a hypocrite.");
2887 You_feel("
\8bU
\91P
\8eÒ
\82Ì
\82æ
\82¤
\82È
\8bC
\82ª
\82µ
\82½
\81D");
2888 /* AIS: Yes, I know alignment penalties and bonuses aren't balanced
2889 at the moment. This is about correct relative to other "small"
2890 penalties; it should be fairly large, as attacking while standing
2891 on an Elbereth means that you're requesting peace and then
2892 violating your own request. I know 5 isn't actually large, but
2893 it's intentionally larger than the 1s and 2s that are normally
2894 given for this sort of thing. */
2899 pline("The engraving beneath you fades.");
2901 pline("
\82 \82È
\82½
\82Ì
\91«
\8c³
\82Ì
\95¶
\8e\9a\82ª
\94\96\82ê
\82½
\81D");
2902 del_engr_at(u.ux, u.uy);
2905 /* AIS: Should this be in both places, or just in wakeup()? */
2906 mtmp->mstrategy &= ~STRAT_WAITMASK;
2907 if (!mtmp->mpeaceful)
2911 mtmp->mpeaceful = 0;
2912 if (mtmp->ispriest) {
2913 if (p_coaligned(mtmp))
2914 adjalign(-5); /* very bad */
2918 adjalign(-1); /* attacking peaceful monsters is bad */
2919 if (couldsee(mtmp->mx, mtmp->my)) {
2920 if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
2922 pline("%s gets angry!", Monnam(mtmp));
2924 pline("%s
\82Í
\93{
\82Á
\82½
\81I", Monnam(mtmp));
2925 else if (flags.verbose && !Deaf)
2929 /* attacking your own quest leader will anger his or her guardians */
2930 if (!context.mon_moving /* should always be the case here */
2931 && mtmp->data == &mons[quest_info(MS_LEADER)]) {
2933 struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
2936 /* guardians will sense this attack even if they can't see it */
2937 for (mon = fmon; mon; mon = mon->nmon) {
2938 if (DEADMONSTER(mon))
2940 if (mon->data == q_guardian && mon->mpeaceful) {
2946 if (got_mad && !Hallucination) {
2947 const char *who = q_guardian->mname;
2951 who = makeplural(who);
2952 pline_The("%s %s to be angry too...",
2953 who, vtense(who, "appear"));
2955 pline("%s
\82à
\93{
\82Á
\82½
\82æ
\82¤
\82¾
\81D
\81D
\81D", who);
2960 /* make other peaceful monsters react */
2961 if (!context.mon_moving) {
2962 static const char *const Exclam[] = {
2964 "Gasp!", "Uh-oh.", "Oh my!", "What?", "Why?",
2966 "
\82®
\82Í
\82Á
\81I", "
\82¤
\82í
\81D", "Oh my!", "
\82È
\82É
\82Á
\81H", "
\82È
\82ñ
\82¾
\81H",
2969 int mndx = monsndx(mtmp->data);
2971 for (mon = fmon; mon; mon = mon->nmon) {
2972 if (DEADMONSTER(mon))
2974 if (mon == mtmp) /* the mpeaceful test catches this since mtmp */
2975 continue; /* is no longer peaceful, but be explicit... */
2977 if (!mindless(mon->data) && mon->mpeaceful
2978 && couldsee(mon->mx, mon->my) && !mon->msleeping
2979 && mon->mcansee && m_canseeu(mon)) {
2980 boolean exclaimed = FALSE;
2982 if (humanoid(mon->data) || mon->isshk || mon->ispriest) {
2983 if (is_watch(mon->data)) {
2985 verbalize("Halt! You're under arrest!");
2987 verbalize("
\8e~
\82Ü
\82ê
\81I
\91ß
\95ß
\82·
\82é
\81I");
2988 (void) angry_guards(!!Deaf);
2991 verbalize("%s", Exclam[mon->m_id % SIZE(Exclam)]);
2994 /* shopkeepers and temple priests might gasp in
2995 surprise, but they won't become angry here */
2996 if (mon->isshk || mon->ispriest)
2999 if (mon->data->mlevel < rn2(10)) {
3000 monflee(mon, rn2(50) + 25, TRUE, !exclaimed);
3004 /* mustn't set mpeaceful to 0 as below;
3005 perhaps reduce tameness? */
3011 pline("%s gets angry!", Monnam(mon));
3013 pline("%s
\82Í
\93{
\82Á
\82½
\81I", Monnam(mon));
3016 } else if (mon->data->mlet == mtmp->data->mlet
3017 && big_little_match(mndx, monsndx(mon->data))
3024 monflee(mon, rn2(25) + 15, TRUE, !exclaimed);
3031 /* wake up a monster, possibly making it angry in the process */
3033 wakeup(mtmp, via_attack)
3034 register struct monst *mtmp;
3037 mtmp->msleeping = 0;
3038 if (mtmp->m_ap_type) {
3040 } else if (context.forcefight && !context.mon_moving
3041 && mtmp->mundetected) {
3042 mtmp->mundetected = 0;
3043 newsym(mtmp->mx, mtmp->my);
3045 finish_meating(mtmp);
3047 setmangry(mtmp, TRUE);
3050 /* Wake up nearby monsters without angering them. */
3054 register struct monst *mtmp;
3056 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3057 if (DEADMONSTER(mtmp))
3059 if (distu(mtmp->mx, mtmp->my) < u.ulevel * 20) {
3060 mtmp->msleeping = 0;
3061 if (!unique_corpstat(mtmp->data))
3062 mtmp->mstrategy &= ~STRAT_WAITMASK;
3064 if (!mtmp->isminion)
3065 EDOG(mtmp)->whistletime = moves;
3066 /* Clear mtrack. This is to fix up a pet who is
3067 stuck "fleeing" its master. */
3068 memset(mtmp->mtrack, 0, sizeof(mtmp->mtrack));
3074 /* Wake up monsters near some particular location. */
3076 wake_nearto(x, y, distance)
3077 register int x, y, distance;
3079 register struct monst *mtmp;
3081 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3082 if (DEADMONSTER(mtmp))
3084 if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
3085 mtmp->msleeping = 0;
3086 if (!unique_corpstat(mtmp->data))
3087 mtmp->mstrategy &= ~STRAT_WAITMASK;
3092 /* NOTE: we must check for mimicry before calling this routine */
3095 register struct monst *mtmp;
3097 boolean is_blocker_appear = (is_lightblocker_mappear(mtmp));
3099 if (has_mcorpsenm(mtmp))
3100 freemcorpsenm(mtmp);
3102 mtmp->m_ap_type = M_AP_NOTHING;
3103 mtmp->mappearance = 0;
3106 * Discovered mimics don't block light.
3108 if (is_blocker_appear
3109 && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
3110 unblock_point(mtmp->mx, mtmp->my);
3112 newsym(mtmp->mx, mtmp->my);
3115 /* force all chameleons to become normal */
3119 register struct monst *mtmp;
3122 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3123 if (DEADMONSTER(mtmp))
3125 mcham = (int) mtmp->cham;
3126 if (mcham >= LOW_PM) {
3127 (void) newcham(mtmp, &mons[mcham], FALSE, FALSE);
3128 mtmp->cham = NON_PM;
3130 if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
3132 if (mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) {
3134 /* we pretend that the mimic doesn't
3135 know that it has been unmasked */
3136 mtmp->msleeping = 1;
3141 /* Let the chameleons change again -dgk */
3145 register struct monst *mtmp;
3147 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3148 if (DEADMONSTER(mtmp))
3150 mtmp->cham = pm_to_cham(monsndx(mtmp->data));
3151 if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping
3152 && cansee(mtmp->mx, mtmp->my)) {
3153 set_mimic_sym(mtmp);
3154 newsym(mtmp->mx, mtmp->my);
3159 /* called when restoring a monster from a saved level; protection
3160 against shape-changing might be different now than it was at the
3161 time the level was saved. */
3168 if (Protection_from_shape_changers) {
3169 mcham = (int) mon->cham;
3170 if (mcham >= LOW_PM) {
3172 (void) newcham(mon, &mons[mcham], FALSE, FALSE);
3173 } else if (is_were(mon->data) && !is_human(mon->data)) {
3176 } else if (mon->cham == NON_PM) {
3177 mon->cham = pm_to_cham(monsndx(mon->data));
3181 /* unwatched hiders may hide again; if so, returns True */
3184 register struct monst *mtmp;
3188 if (mtmp->mcan || mtmp->m_ap_type || cansee(mtmp->mx, mtmp->my)
3189 || rn2(3) || mtmp == u.ustuck
3190 /* can't hide while trapped except in pits */
3191 || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
3192 && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))
3193 || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
3196 if (mtmp->data->mlet == S_MIMIC) {
3197 set_mimic_sym(mtmp);
3199 } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) {
3200 mtmp->mundetected = 1;
3207 /* monster/hero tries to hide under something at the current location */
3213 boolean undetected = FALSE, is_u = (mtmp == &youmonst);
3214 xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
3216 if (mtmp == u.ustuck) {
3217 ; /* can't hide if holding you or held by you */
3218 } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
3219 : (mtmp->mtrapped && (t = t_at(x, y)) != 0
3220 && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) {
3221 ; /* can't hide while stuck in a non-pit trap */
3222 } else if (mtmp->data->mlet == S_EEL) {
3223 undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
3224 } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
3225 struct obj *otmp = level.objects[x][y];
3227 /* most monsters won't hide under cockatrice corpse */
3228 if (otmp->nexthere || otmp->otyp != CORPSE
3229 || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp))
3230 || !touch_petrifies(&mons[otmp->corpsenm]))
3235 u.uundetected = undetected;
3237 mtmp->mundetected = undetected;
3241 /* called when returning to a previously visited level */
3246 boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL;
3248 if ((is_hider(mon->data) || hider_under)
3249 && !(mon->mundetected || mon->m_ap_type)) {
3250 xchar x = mon->mx, y = mon->my;
3251 char save_viz = viz_array[y][x];
3253 /* override vision, forcing hero to be unable to see monster's spot */
3254 viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE);
3255 if (is_hider(mon->data))
3256 (void) restrap(mon);
3257 /* try again if mimic missed its 1/3 chance to hide */
3258 if (mon->data->mlet == S_MIMIC && !mon->m_ap_type)
3259 (void) restrap(mon);
3261 (void) hideunder(mon);
3262 viz_array[y][x] = save_viz;
3266 static short *animal_list = 0; /* list of PM values for animal monsters */
3267 static int animal_list_count;
3270 mon_animal_list(construct)
3274 short animal_temp[SPECIAL_PM];
3277 /* if (animal_list) impossible("animal_list already exists"); */
3279 for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
3280 if (is_animal(&mons[i]))
3281 animal_temp[n++] = i;
3282 /* if (n == 0) animal_temp[n++] = NON_PM; */
3284 animal_list = (short *) alloc(n * sizeof *animal_list);
3285 (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp,
3286 n * sizeof *animal_list);
3287 animal_list_count = n;
3288 } else { /* release */
3290 free((genericptr_t) animal_list), animal_list = 0;
3291 animal_list_count = 0;
3301 mon_animal_list(TRUE);
3303 res = animal_list[rn2(animal_list_count)];
3304 /* rogue level should use monsters represented by uppercase letters
3305 only, but since chameleons aren't generated there (not uppercase!)
3306 we don't perform a lot of retries */
3307 if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet))
3308 res = animal_list[rn2(animal_list_count)];
3313 decide_to_shapeshift(mon, shiftflags)
3317 struct permonst *ptr = 0;
3319 unsigned was_female = mon->female;
3320 boolean msg = FALSE, dochng = FALSE;
3322 if ((shiftflags & SHIFT_MSG)
3323 || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon)))
3326 if (!is_vampshifter(mon)) {
3327 /* regular shapeshifter */
3331 /* The vampire has to be in good health (mhp) to maintain
3334 * If we're shifted and getting low on hp, maybe shift back, or
3335 * if we're a fog cloud at full hp, maybe pick a different shape.
3336 * If we're not already shifted and in good health, maybe shift.
3338 if (mon->data->mlet != S_VAMPIRE) {
3339 if ((mon->mhp <= (mon->mhpmax + 5) / 6) && rn2(4)
3340 && mon->cham >= LOW_PM) {
3341 ptr = &mons[mon->cham];
3343 } else if (mon->data == &mons[PM_FOG_CLOUD]
3344 && mon->mhp == mon->mhpmax && !rn2(4)
3346 || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM)) {
3347 /* if a fog cloud, maybe change to wolf or vampire bat;
3348 those are more likely to take damage--at least when
3349 tame--and then switch back to vampire; they'll also
3350 switch to fog cloud if they encounter a closed door */
3351 mndx = pickvampshape(mon);
3352 if (mndx >= LOW_PM) {
3354 dochng = (ptr != mon->data);
3358 if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6)
3360 || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM))
3361 dochng = TRUE; /* 'ptr' stays Null */
3365 if (newcham(mon, ptr, FALSE, msg) && is_vampshifter(mon)) {
3366 /* for vampshift, override the 10% chance for sex change */
3368 if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr))
3369 mon->female = was_female;
3378 int mndx = mon->cham, wolfchance = 10;
3379 /* avoid picking monsters with lowercase display symbols ('d' for wolf
3380 and 'v' for fog cloud) on rogue level*/
3381 boolean uppercase_only = Is_rogue_level(&u.uz);
3384 case PM_VLAD_THE_IMPALER:
3385 /* ensure Vlad can keep carrying the Candelabrum */
3386 if (mon_has_special(mon))
3387 break; /* leave mndx as is */
3390 case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */
3391 if (!rn2(wolfchance) && !uppercase_only) {
3396 case PM_VAMPIRE: /* any vampire can become fog or bat */
3397 mndx = (!rn2(4) && !uppercase_only) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
3403 /* nonshapechangers who warrant special polymorph handling */
3408 return (mon->isshk || mon->ispriest || mon->isgd
3409 || mon->m_id == quest_status.leader_m_id);
3412 /* restrict certain special monsters (shopkeepers, aligned priests,
3413 vault guards) to forms that allow them to behave sensibly (catching
3414 gold, speaking?) so that they don't need too much extra code */
3416 validspecmon(mon, mndx)
3421 return TRUE; /* caller wants random */
3423 if (!accept_newcham_form(mndx))
3424 return FALSE; /* geno'd or !polyok */
3426 if (isspecmon(mon)) {
3427 struct permonst *ptr = &mons[mndx];
3429 /* reject notake because object manipulation is expected
3430 and nohead because speech capability is expected */
3431 if (notake(ptr) || !has_head(ptr))
3433 /* [should we check ptr->msound here too?] */
3435 return TRUE; /* potential new form is ok */
3438 /* prevent wizard mode user from specifying invalid vampshifter shape */
3440 validvamp(mon, mndx_p, monclass)
3442 int *mndx_p, monclass;
3444 /* simplify caller's usage */
3445 if (!is_vampshifter(mon))
3446 return validspecmon(mon, *mndx_p);
3448 if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD
3449 || *mndx_p == PM_VLAD_THE_IMPALER) {
3450 /* player picked some type of vampire; use mon's self */
3451 *mndx_p = mon->cham;
3454 if (mon->cham == PM_VLAD_THE_IMPALER && mon_has_special(mon)) {
3455 /* Vlad with Candelabrum; override choice, then accept it */
3456 *mndx_p = PM_VLAD_THE_IMPALER;
3459 /* basic vampires can't become wolves; any can become fog or bat
3460 (we don't enforce upper-case only for rogue level here) */
3461 if (*mndx_p == PM_WOLF)
3462 return (boolean) (mon->cham != PM_VAMPIRE);
3463 if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT)
3466 /* if we get here, specific type was no good; try by class */
3469 *mndx_p = mon->cham;
3472 *mndx_p = PM_VAMPIRE_BAT;
3475 *mndx_p = PM_FOG_CLOUD;
3478 if (mon->cham != PM_VAMPIRE) {
3487 return (boolean) (*mndx_p != NON_PM);
3491 select_newcham_form(mon)
3494 int mndx = NON_PM, tryct;
3496 switch (mon->cham) {
3499 mndx = pick_nasty();
3501 case PM_DOPPELGANGER:
3503 mndx = pick_nasty();
3504 } else if (rn2(3)) { /* role monsters */
3505 mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
3506 } else if (!rn2(3)) { /* quest guardians */
3507 mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT);
3508 /* avoid own role's guardian */
3509 if (mndx == urole.guardnum)
3511 } else { /* general humanoids */
3514 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3515 if (humanoid(&mons[mndx]) && polyok(&mons[mndx]))
3517 } while (--tryct > 0);
3524 mndx = pick_animal();
3526 case PM_VLAD_THE_IMPALER:
3527 case PM_VAMPIRE_LORD:
3529 mndx = pickvampshape(mon);
3531 case NON_PM: /* ordinary */
3533 struct obj *m_armr = which_armor(mon, W_ARM);
3535 if (m_armr && Is_dragon_scales(m_armr))
3536 mndx = (int) (Dragon_scales_to_pm(m_armr) - mons);
3537 else if (m_armr && Is_dragon_mail(m_armr))
3538 mndx = (int) (Dragon_mail_to_pm(m_armr) - mons);
3543 /* for debugging: allow control of polymorphed monster */
3544 if (wizard && iflags.mon_polycontrol) {
3545 char pprompt[BUFSZ], buf[BUFSZ] = DUMMY;
3548 Sprintf(pprompt, "Change %s @ %s into what kind of monster?",
3550 coord_desc((int) mon->mx, (int) mon->my, buf,
3551 (iflags.getpos_coords != GPCOORDS_NONE)
3552 ? iflags.getpos_coords : GPCOORDS_MAP));
3556 getlin(pprompt, buf);
3558 /* for ESC, take form selected above (might be NON_PM) */
3561 /* for "*", use NON_PM to pick an arbitrary shape below */
3562 if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
3566 mndx = name_to_mon(buf);
3567 if (mndx == NON_PM) {
3568 /* didn't get a type, so check whether it's a class
3569 (single letter or text match with def_monsyms[]) */
3570 monclass = name_to_monclass(buf, &mndx);
3571 if (monclass && mndx == NON_PM)
3572 mndx = mkclass_poly(monclass);
3574 if (mndx >= LOW_PM) {
3575 /* got a specific type of monster; use it if we can */
3576 if (validvamp(mon, &mndx, monclass))
3578 /* can't; revert to random in case we exhaust tryct */
3582 pline("It can't become that.");
3583 } while (--tryct > 0);
3585 pline1(thats_enough_tries);
3586 if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass))
3587 mndx = pickvampshape(mon); /* don't resort to arbitrary */
3590 /* if no form was specified above, pick one at random now */
3591 if (mndx == NON_PM) {
3594 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3595 } while (--tryct > 0 && !validspecmon(mon, mndx)
3596 /* try harder to select uppercase monster on rogue level */
3597 && (tryct > 40 && Is_rogue_level(&u.uz)
3598 && !isupper((uchar) mons[mndx].mlet)));
3603 /* this used to be inline within newcham() but monpolycontrol needs it too */
3604 STATIC_OVL struct permonst *
3605 accept_newcham_form(mndx)
3608 struct permonst *mdat;
3613 if ((mvitals[mndx].mvflags & G_GENOD) != 0)
3615 if (is_placeholder(mdat))
3617 /* select_newcham_form() might deliberately pick a player
3618 character type (random selection never does) which
3619 polyok() rejects, so we need a special case here */
3620 if (is_mplayer(mdat))
3622 /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */
3623 return polyok(mdat) ? mdat : 0;
3627 mgender_from_permonst(mtmp, mdat)
3629 struct permonst *mdat;
3631 if (is_male(mdat)) {
3633 mtmp->female = FALSE;
3634 } else if (is_female(mdat)) {
3636 mtmp->female = TRUE;
3637 } else if (!is_neuter(mdat)) {
3639 mtmp->female = !mtmp->female;
3643 /* make a chameleon take on another shape, or a polymorph target
3644 (possibly self-inflicted) become a different monster;
3645 returns 1 if it actually changes form */
3647 newcham(mtmp, mdat, polyspot, msg)
3649 struct permonst *mdat;
3650 boolean polyspot; /* change is the result of wand or spell of polymorph */
3651 boolean msg; /* "The oldmon turns into a newmon!" */
3655 struct permonst *olddata = mtmp->data;
3656 char *p, oldname[BUFSZ], l_oldname[BUFSZ], newname[BUFSZ];
3658 /* Riders are immune to polymorph and green slime
3659 (but apparent Rider might actually be a doppelganger) */
3660 if (mtmp->cham == NON_PM) { /* not a shapechanger */
3661 if (is_rider(olddata))
3663 /* make Nazgul and erinyes immune too, to reduce chance of
3664 anomalous extinction feedback during final disclsoure */
3665 if (mbirth_limit(monsndx(olddata)) < MAXMONNO)
3670 /* like Monnam() but never mention saddle */
3671 Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3672 SUPPRESS_SADDLE, FALSE));
3673 oldname[0] = highc(oldname[0]);
3675 /* we need this one whether msg is true or not */
3676 Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3677 has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE));
3679 /* mdat = 0 -> caller wants a random monster shape */
3681 /* select_newcham_form() loops when resorting to random but
3682 it doesn't always pick that so we still retry here too */
3685 mndx = select_newcham_form(mtmp);
3686 mdat = accept_newcham_form(mndx);
3687 /* for the first several tries we require upper-case on
3688 the rogue level (after that, we take whatever we get) */
3689 if (tryct > 15 && Is_rogue_level(&u.uz)
3690 && mdat && !isupper((uchar) mdat->mlet))
3694 } while (--tryct > 0);
3697 } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
3698 return 0; /* passed in mdat is genocided */
3700 if (mdat == olddata)
3701 return 0; /* still the same monster */
3703 mgender_from_permonst(mtmp, mdat);
3704 /* Endgame mplayers start out as "Foo the Bar", but some of the
3705 * titles are inappropriate when polymorphed, particularly into
3706 * the opposite sex. Player characters don't use ranks when
3707 * polymorphed, so dropping rank for mplayers seems reasonable.
3709 if (In_endgame(&u.uz) && is_mplayer(olddata)
3710 && has_mname(mtmp) && (p = strstr(MNAME(mtmp), " the ")) != 0)
3713 if (mtmp->wormno) { /* throw tail away */
3715 place_monster(mtmp, mtmp->mx, mtmp->my);
3717 if (mtmp->m_ap_type && mdat->mlet != S_MIMIC)
3718 seemimic(mtmp); /* revert to normal monster */
3720 /* (this code used to try to adjust the monster's health based on
3721 a normal one of its type but there are too many special cases
3722 which need to handled in order to do that correctly, so just
3723 give the new form the same proportion of HP as its old one had) */
3726 /* set level and hit points */
3727 newmonhp(mtmp, monsndx(mdat));
3728 /* new hp: same fraction of max as before */
3730 mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd);
3732 /* sanity check (potential overflow) */
3733 if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax)
3734 mtmp->mhp = mtmp->mhpmax;
3735 /* unlikely but not impossible; a 1HD creature with 1HP that changes
3736 into a 0HD creature will require this statement */
3740 /* take on the new form... */
3741 set_mon_data(mtmp, mdat, 0);
3743 if (emits_light(olddata) != emits_light(mtmp->data)) {
3744 /* used to give light, now doesn't, or vice versa,
3745 or light's range has changed */
3746 if (emits_light(olddata))
3747 del_light_source(LS_MONSTER, monst_to_any(mtmp));
3748 if (emits_light(mtmp->data))
3749 new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
3750 LS_MONSTER, monst_to_any(mtmp));
3752 if (!mtmp->perminvis || pm_invisible(olddata))
3753 mtmp->perminvis = pm_invisible(mdat);
3754 mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
3755 if (mtmp->mundetected)
3756 (void) hideunder(mtmp);
3757 if (u.ustuck == mtmp) {
3759 if (!attacktype(mdat, AT_ENGL)) {
3760 /* Does mdat care? */
3761 if (!noncorporeal(mdat) && !amorphous(mdat)
3762 && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) {
3763 char msgtrail[BUFSZ];
3765 if (is_vampshifter(mtmp)) {
3767 Sprintf(msgtrail, " which was a shapeshifted %s",
3768 noname_monnam(mtmp, ARTICLE_NONE));
3770 Sprintf(msgtrail, "(
\8eÀ
\8dÛ
\82É
\82Í
\8c`
\82ð
\95Ï
\82¦
\82½%s)",
3771 noname_monnam(mtmp, ARTICLE_NONE));
3773 } else if (is_animal(mdat)) {
3775 Strcpy(msgtrail, "'s stomach");
3777 Strcpy(msgtrail, "
\82Ì
\88Ý");
3782 /* Do this even if msg is FALSE */
3785 (amorphous(olddata) || is_whirly(olddata))
3786 ? "emerge from" : "break out of",
3787 l_oldname, msgtrail);
3789 You("%s%s%s
\81I", l_oldname, msgtrail,
3790 (amorphous(olddata) || is_whirly(olddata))
3791 ? "
\82©
\82ç
\94ò
\82Ñ
\8fo
\82µ
\82½" : "
\82ð
\94j
\82è
\8fo
\82½"
3794 msg = FALSE; /* message has been given */
3795 mtmp->mhp = 1; /* almost dead */
3797 expels(mtmp, olddata, FALSE);
3799 /* update swallow glyphs for new monster */
3802 } else if (!sticks(mdat) && !sticks(youmonst.data))
3807 if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
3809 /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
3812 if (mdat == &mons[PM_LONG_WORM]
3813 && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
3815 /* we can now create worms with tails - 11/91 */
3816 initworm(mtmp, rn2(5));
3817 if (count_wsegs(mtmp))
3818 place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
3821 newsym(mtmp->mx, mtmp->my);
3824 Strcpy(newname, noname_monnam(mtmp, ARTICLE_A));
3825 /* oldname was capitalized above; newname will be lower case */
3827 if (!strcmpi(newname, "it")) { /* can't see or sense it now */
3829 if (!strcmpi(newname, "
\89½
\8eÒ
\82©")) { /* can't see or sense it now */
3832 if (!!strcmpi(oldname, "it")) /* could see or sense it before */
3834 if (!!strcmpi(oldname, "
\89½
\8eÒ
\82©")) /* could see or sense it before */
3836 pline("%s disappears!", oldname);
3837 (void) usmellmon(mdat);
3838 } else { /* can see or sense it now */
3840 if (!strcmpi(oldname, "it")) /* couldn't see or sense it before */
3842 if (!strcmpi(oldname, "
\89½
\8eÒ
\82©")) /* couldn't see or sense it before */
3844 pline("%s appears!", upstart(newname));
3847 pline("%s turns into %s!", oldname, newname);
3849 pline("%s
\82Í%s
\82É
\82È
\82Á
\82½
\81I", oldname, newname);
3853 /* when polymorph trap/wand/potion produces a vampire, turn in into
3854 a full-fledged vampshifter unless shape-changing is blocked */
3855 if (mtmp->cham == NON_PM && mdat->mlet == S_VAMPIRE
3856 && !Protection_from_shape_changers)
3857 mtmp->cham = pm_to_cham(monsndx(mdat));
3859 possibly_unwield(mtmp, polyspot); /* might lose use of weapon */
3860 mon_break_armor(mtmp, polyspot);
3861 if (!(mtmp->misc_worn_check & W_ARMG))
3863 mselftouch(mtmp, "No longer petrify-resistant, ",
3864 !context.mon_moving);
3866 mselftouch(mtmp, "
\90Î
\89»
\82Ö
\82Ì
\92ï
\8dR
\97Í
\82ª
\82È
\82
\82È
\82Á
\82Ä
\81C",
3867 !context.mon_moving);
3869 m_dowear(mtmp, FALSE);
3871 /* This ought to re-test can_carry() on each item in the inventory
3872 * rather than just checking ex-giants & boulders, but that'd be
3873 * pretty expensive to perform. If implemented, then perhaps
3874 * minvent should be sorted in order to drop heaviest items first.
3876 /* former giants can't continue carrying boulders */
3877 if (mtmp->minvent && !throws_rocks(mdat)) {
3878 register struct obj *otmp, *otmp2;
3880 for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
3882 if (otmp->otyp == BOULDER) {
3883 /* this keeps otmp from being polymorphed in the
3884 same zap that the monster that held it is polymorphed */
3887 obj_extract_self(otmp);
3888 /* probably ought to give some "drop" message here */
3889 if (flooreffects(otmp, mtmp->mx, mtmp->my, ""))
3891 place_object(otmp, mtmp->mx, mtmp->my);
3899 /* sometimes an egg will be special */
3900 #define BREEDER_EGG (!rn2(77))
3903 * Determine if the given monster number can be hatched from an egg.
3904 * Return the monster number to use as the egg's corpsenm. Return
3905 * NON_PM if the given monster can't be hatched.
3908 can_be_hatched(mnum)
3911 /* ranger quest nemesis has the oviparous bit set, making it
3912 be possible to wish for eggs of that unique monster; turn
3913 such into ordinary eggs rather than forbidding them outright */
3914 if (mnum == PM_SCORPIUS)
3917 mnum = little_to_big(mnum);
3919 * Queen bees lay killer bee eggs (usually), but killer bees don't
3920 * grow into queen bees. Ditto for [winged-]gargoyles.
3922 if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE
3923 || (lays_eggs(&mons[mnum])
3925 || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
3930 /* type of egg laid by #sit; usually matches parent */
3932 egg_type_from_parent(mnum, force_ordinary)
3933 int mnum; /* parent monster; caller must handle lays_eggs() check */
3934 boolean force_ordinary;
3936 if (force_ordinary || !BREEDER_EGG) {
3937 if (mnum == PM_QUEEN_BEE)
3938 mnum = PM_KILLER_BEE;
3939 else if (mnum == PM_WINGED_GARGOYLE)
3945 /* decide whether an egg of the indicated monster type is viable;
3946 also used to determine whether an egg or tin can be created... */
3948 dead_species(m_idx, egg)
3954 /* generic eggs are unhatchable and have corpsenm of NON_PM */
3958 * For monsters with both baby and adult forms, genociding either
3959 * form kills all eggs of that monster. Monsters with more than
3960 * two forms (small->large->giant mimics) are more or less ignored;
3961 * fortunately, none of them have eggs. Species extinction due to
3962 * overpopulation does not kill eggs.
3964 alt_idx = egg ? big_to_little(m_idx) : m_idx;
3965 return (boolean) ((mvitals[m_idx].mvflags & G_GENOD) != 0
3966 || (mvitals[alt_idx].mvflags & G_GENOD) != 0);
3969 /* kill off any eggs of genocided monsters */
3972 struct obj *obj_list;
3976 for (otmp = obj_list; otmp; otmp = otmp->nobj)
3977 if (otmp->otyp == EGG) {
3978 if (dead_species(otmp->corpsenm, TRUE)) {
3980 * It seems we could also just catch this when
3981 * it attempted to hatch, so we wouldn't have to
3982 * search all of the objlists.. or stop all
3983 * hatch timers based on a corpsenm.
3987 #if 0 /* not used */
3988 } else if (otmp->otyp == TIN) {
3989 if (dead_species(otmp->corpsenm, FALSE))
3990 otmp->corpsenm = NON_PM; /* empty tin */
3991 } else if (otmp->otyp == CORPSE) {
3992 if (dead_species(otmp->corpsenm, FALSE))
3993 ; /* not yet implemented... */
3995 } else if (Has_contents(otmp)) {
3996 kill_eggs(otmp->cobj);
4000 /* kill all members of genocided species */
4002 kill_genocided_monsters()
4004 struct monst *mtmp, *mtmp2;
4009 * Called during genocide, and again upon level change. The latter
4010 * catches up with any migrating monsters as they finally arrive at
4011 * their intended destinations, so possessions get deposited there.
4013 * Chameleon handling:
4014 * 1) if chameleons have been genocided, destroy them
4015 * regardless of current form;
4016 * 2) otherwise, force every chameleon which is imitating
4017 * any genocided species to take on a new form.
4019 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
4021 if (DEADMONSTER(mtmp))
4023 mndx = monsndx(mtmp->data);
4024 kill_cham = (mtmp->cham >= LOW_PM
4025 && (mvitals[mtmp->cham].mvflags & G_GENOD));
4026 if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) {
4027 if (mtmp->cham >= LOW_PM && !kill_cham)
4028 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
4033 kill_eggs(mtmp->minvent);
4038 kill_eggs(migrating_objs);
4039 kill_eggs(level.buriedobjlist);
4043 golemeffects(mon, damtype, dam)
4044 register struct monst *mon;
4047 int heal = 0, slow = 0;
4049 if (mon->data == &mons[PM_FLESH_GOLEM]) {
4050 if (damtype == AD_ELEC)
4051 heal = (dam + 5) / 6;
4052 else if (damtype == AD_FIRE || damtype == AD_COLD)
4054 } else if (mon->data == &mons[PM_IRON_GOLEM]) {
4055 if (damtype == AD_ELEC)
4057 else if (damtype == AD_FIRE)
4063 if (mon->mspeed != MSLOW)
4064 mon_adjust_speed(mon, -1, (struct obj *) 0);
4067 if (mon->mhp < mon->mhpmax) {
4069 if (mon->mhp > mon->mhpmax)
4070 mon->mhp = mon->mhpmax;
4071 if (cansee(mon->mx, mon->my))
4073 pline("%s seems healthier.", Monnam(mon));
4075 pline("%s
\82Í
\8c³
\8bC
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81D", Monnam(mon));
4081 angry_guards(silent)
4085 int ct = 0, nct = 0, sct = 0, slct = 0;
4087 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4088 if (DEADMONSTER(mtmp))
4090 if (is_watch(mtmp->data) && mtmp->mpeaceful) {
4092 if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
4093 if (distu(mtmp->mx, mtmp->my) == 2)
4098 if (mtmp->msleeping || mtmp->mfrozen) {
4100 mtmp->msleeping = mtmp->mfrozen = 0;
4102 mtmp->mpeaceful = 0;
4106 if (!silent) { /* do we want pline msgs? */
4109 pline_The("guard%s wake%s up!", slct > 1 ? "s" : "",
4110 slct == 1 ? "s" : "");
4112 pline("
\94Ô
\95º
\82Í
\96Ú
\82ð
\8ao
\82Ü
\82µ
\82½
\81I");
4117 pline_The("guard%s get%s angry!", nct == 1 ? "" : "s",
4118 nct == 1 ? "s" : "");
4120 pline("
\94Ô
\95º
\82Í
\93{
\82Á
\82½
\81I");
4124 You_see("%sangry guard%s approaching!",
4125 sct == 1 ? "an " : "", sct > 1 ? "s" : "");
4127 You("
\93{
\82Á
\82½
\94Ô
\95º
\82ª
\8bß
\8añ
\82Á
\82Ä
\82
\82é
\82Ì
\82ð
\8c©
\82½
\81I");
4131 You_hear("the shrill sound of a guard's whistle.");
4133 You_hear("
\94Ô
\95º
\82Ì
\93J
\82ª
\82¯
\82½
\82½
\82Ü
\82µ
\82
\96Â
\82é
\82Ì
\82ð
\95·
\82¢
\82½
\81D");
4145 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4146 if (DEADMONSTER(mtmp))
4148 if (is_watch(mtmp->data))
4149 mtmp->mpeaceful = 1;
4154 mimic_hit_msg(mtmp, otyp)
4158 short ap = mtmp->mappearance;
4160 switch (mtmp->m_ap_type) {
4162 case M_AP_FURNITURE:
4166 if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
4168 pline("%s seems a more vivid %s than before.",
4169 The(simple_typename(ap)),
4170 c_obj_colors[objects[ap].oc_color]);
4172 pline("%s
\82Í
\88È
\91O
\82æ
\82è
\82æ
\82è
\91N
\82â
\82©
\82È%s
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D",
4173 The(simple_typename(ap)),
4174 c_obj_colors[objects[ap].oc_color]);
4183 struct permonst *mdat;
4186 boolean nonspecific = FALSE;
4187 boolean msg_given = FALSE;
4190 if (!olfaction(youmonst.data))
4192 mndx = monsndx(mdat);
4197 You("notice a bovine smell.");
4199 You("
\8b\8d\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4205 case PM_NEANDERTHAL:
4207 You("smell body odor.");
4209 pline("
\91Ì
\8fL
\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4218 case PM_HORNED_DEVIL:
4225 case PM_HUMAN_WEREJACKAL:
4226 case PM_HUMAN_WERERAT:
4227 case PM_HUMAN_WEREWOLF:
4233 You("detect an odor reminiscent of an animal's den.");
4235 pline("
\93®
\95¨
\82Ì
\82Ë
\82®
\82ç
\82ð
\8ev
\82¢
\8fo
\82·
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4239 case PM_PURPLE_WORM:
4242 case PM_STEAM_VORTEX:
4244 You("smell steam.");
4246 pline("
\8fö
\8bC
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4249 case PM_GREEN_SLIME:
4251 pline("%s stinks.", Something);
4253 pline("
\88«
\8fL
\82ª
\82µ
\82½
\81D");
4256 case PM_VIOLET_FUNGUS:
4259 You("smell mushrooms.");
4261 pline("
\82«
\82Ì
\82±
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4264 /* These are here to avoid triggering the
4265 nonspecific treatment through the default case below*/
4266 case PM_WHITE_UNICORN:
4267 case PM_GRAY_UNICORN:
4268 case PM_BLACK_UNICORN:
4277 switch (mdat->mlet) {
4280 You("notice a dog smell.");
4282 You("
\8c¢
\82Ì
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4287 You("smell a dragon!");
4289 pline("
\83h
\83\89\83S
\83\93\82Ì
\82É
\82¨
\82¢
\82ª
\82·
\82é
\81I");
4294 pline("%s smells moldy.", Something);
4296 pline("
\89½
\82©
\91Û
\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82·
\82é
\81D");
4301 You("detect a%s odor reminiscent of a stable.",
4302 (mndx == PM_PONY) ? "n" : " strong");
4304 pline("
\94n
\8f¬
\89®
\82ð
\8ev
\82¢
\8fo
\82·
\82æ
\82¤
\82È%s
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D",
4305 (mndx == PM_PONY) ? "" : "
\8b
\82¢");
4311 You("smell rotting flesh.");
4313 pline("
\95\85\82Á
\82½
\93÷
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4320 pline("
\8b\9b\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4324 if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
4326 You("notice an attractive smell.");
4328 You("
\96£
\97Í
\93I
\82È
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4331 pline("A foul stench makes you feel a little nauseated.");
4333 pline("
\82Þ
\82©
\82Â
\82
\82æ
\82¤
\82È
\88«
\8fL
\82Å
\8f
\82µ
\8bC
\95ª
\82ª
\88«
\82
\82È
\82Á
\82½
\81D");
4340 return msg_given ? TRUE : FALSE;