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-2018 */
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;
1117 if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) {
1118 mat_idx = objects[gold->otyp].oc_material;
1119 obj_extract_self(gold);
1120 add_to_minv(mtmp, gold);
1121 if (cansee(mtmp->mx, mtmp->my)) {
1122 if (flags.verbose && !mtmp->isgd)
1124 pline("%s picks up some %s.", Monnam(mtmp),
1125 mat_idx == GOLD ? "gold" : "money");
1127 pline("%s
\82Í
\82¨
\8bà
\82ð
\8fE
\82Á
\82½
\81D", Monnam(mtmp));
1129 newsym(mtmp->mx, mtmp->my);
1135 mpickstuff(mtmp, str)
1136 register struct monst *mtmp;
1137 register const char *str;
1139 register struct obj *otmp, *otmp2, *otmp3;
1142 /* prevent shopkeepers from leaving the door of their shop */
1143 if (mtmp->isshk && inhishop(mtmp))
1146 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
1147 otmp2 = otmp->nexthere;
1148 /* Nymphs take everything. Most monsters don't pick up corpses. */
1149 if (!str ? searches_for_item(mtmp, otmp)
1150 : !!(index(str, otmp->oclass))) {
1151 if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
1152 /* let a handful of corpse types thru to can_carry() */
1153 && !touch_petrifies(&mons[otmp->corpsenm])
1154 && otmp->corpsenm != PM_LIZARD
1155 && !acidic(&mons[otmp->corpsenm]))
1157 if (!touch_artifact(otmp, mtmp))
1159 carryamt = can_carry(mtmp, otmp);
1162 if (is_pool(mtmp->mx, mtmp->my))
1164 /* handle cases where the critter can only get some */
1166 if (carryamt != otmp->quan) {
1167 otmp3 = splitobj(otmp, carryamt);
1169 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
1171 pline("%s picks up %s.", Monnam(mtmp),
1172 (distu(mtmp->mx, mtmp->my) <= 5)
1174 : distant_name(otmp3, doname));
1176 pline("%s
\82Í%s
\82ð
\8fE
\82Á
\82½
\81D", Monnam(mtmp),
1177 (distu(mtmp->mx, mtmp->my) <= 5)
1179 : distant_name(otmp3, doname));
1181 obj_extract_self(otmp3); /* remove from floor */
1182 (void) mpickobj(mtmp, otmp3); /* may merge and free otmp3 */
1183 m_dowear(mtmp, FALSE);
1184 newsym(mtmp->mx, mtmp->my);
1185 return TRUE; /* pick only one object */
1198 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1199 if (obj->otyp != BOULDER || !throws_rocks(mtmp->data))
1200 curload += obj->owt;
1212 /* Base monster carrying capacity is equal to human maximum
1213 * carrying capacity, or half human maximum if not strong.
1214 * (for a polymorphed player, the value used would be the
1215 * non-polymorphed carrying capacity instead of max/half max).
1216 * This is then modified by the ratio between the monster weights
1217 * and human weights. Corpseless monsters are given a capacity
1218 * proportional to their size instead of weight.
1220 if (!mtmp->data->cwt)
1221 maxload = (MAX_CARR_CAP * (long) mtmp->data->msize) / MZ_HUMAN;
1222 else if (!strongmonst(mtmp->data)
1223 || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN)))
1224 maxload = (MAX_CARR_CAP * (long) mtmp->data->cwt) / WT_HUMAN;
1226 maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/
1228 if (!strongmonst(mtmp->data))
1234 return (int) maxload;
1237 /* for restricting monsters' object-pickup.
1239 * to support the new pet behavior, this now returns the max # of objects
1240 * that a given monster could pick up from a pile. frequently this will be
1241 * otmp->quan, but special cases for 'only one' now exist so.
1243 * this will probably cause very amusing behavior with pets and gold coins.
1245 * TODO: allow picking up 2-N objects from a pile of N based on weight.
1246 * Change from 'int' to 'long' to accomate big stacks of gold.
1247 * Right now we fake it by reporting a partial quantity, but the
1248 * likesgold handling m_move results in picking up the whole stack.
1251 can_carry(mtmp, otmp)
1255 int iquan, otyp = otmp->otyp, newload = otmp->owt;
1256 struct permonst *mdat = mtmp->data;
1260 return 0; /* can't carry anything */
1262 if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])
1263 && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp))
1265 if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm]))
1267 if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp)
1268 && (otyp != BELL_OF_OPENING || !is_covetous(mdat)))
1271 /* hostile monsters who like gold will pick up the whole stack;
1272 tame mosnters with hands will pick up the partial stack */
1273 iquan = (otmp->quan > (long) LARGEST_INT)
1274 ? 20000 + rn2(LARGEST_INT - 20000 + 1)
1277 /* monsters without hands can't pick up multiple objects at once
1278 * unless they have an engulfing attack
1280 * ...dragons, of course, can always carry gold pieces and gems somehow
1283 boolean glomper = FALSE;
1285 if (mtmp->data->mlet == S_DRAGON
1286 && (otmp->oclass == COIN_CLASS
1287 || otmp->oclass == GEM_CLASS))
1290 for (nattk = 0; nattk < NATTK; nattk++)
1291 if (mtmp->data->mattk[nattk].aatyp == AT_ENGL) {
1295 if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper)
1299 /* steeds don't pick up stuff (to avoid shop abuse) */
1300 if (mtmp == u.usteed)
1303 return iquan; /* no limit */
1304 if (mtmp->mpeaceful && !mtmp->mtame)
1306 /* otherwise players might find themselves obligated to violate
1307 * their alignment if the monster takes something they need
1310 /* special--boulder throwers carry unlimited amounts of boulders */
1311 if (throws_rocks(mdat) && otyp == BOULDER)
1314 /* nymphs deal in stolen merchandise, but not boulders or statues */
1315 if (mdat->mlet == S_NYMPH)
1316 return (otmp->oclass == ROCK_CLASS) ? 0 : iquan;
1318 if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp))
1324 /* return number of acceptable neighbour positions */
1326 mfndpos(mon, poss, info, flag)
1328 coord *poss; /* coord poss[9] */
1329 long *info; /* long info[9] */
1332 struct permonst *mdat = mon->data;
1333 register struct trap *ttmp;
1338 boolean wantpool, poolok, lavaok, nodiag;
1339 boolean rockok = FALSE, treeok = FALSE, thrudoor;
1341 boolean poisongas_ok, in_poisongas;
1343 int gas_glyph = cmap_to_glyph(S_poisoncloud);
1347 nowtyp = levl[x][y].typ;
1349 nodiag = NODIAG(mdat - mons);
1350 wantpool = mdat->mlet == S_EEL;
1351 poolok = (is_flyer(mdat) || is_clinger(mdat)
1352 || (is_swimmer(mdat) && !wantpool));
1353 lavaok = (is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat));
1354 thrudoor = ((flag & (ALLOW_WALL | BUSTDOOR)) != 0L);
1355 poisongas_ok = ((nonliving(mdat) || is_vampshifter(mon)
1356 || breathless(mdat)) || resists_poison(mon));
1357 in_poisongas = ((gas_reg = visible_region_at(x,y)) != 0
1358 && gas_reg->glyph == gas_glyph);
1360 if (flag & ALLOW_DIG) {
1363 /* need to be specific about what can currently be dug */
1364 if (!needspick(mdat)) {
1365 rockok = treeok = TRUE;
1366 } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed
1367 && mon->weapon_check == NO_WEAPON_WANTED) {
1368 rockok = is_pick(mw_tmp);
1369 treeok = is_axe(mw_tmp);
1371 rockok = (m_carrying(mon, PICK_AXE)
1372 || (m_carrying(mon, DWARVISH_MATTOCK)
1373 && !which_armor(mon, W_ARMS)));
1374 treeok = (m_carrying(mon, AXE) || (m_carrying(mon, BATTLE_AXE)
1375 && !which_armor(mon, W_ARMS)));
1377 if (rockok || treeok)
1381 nexttry: /* eels prefer the water, but if there is no water nearby,
1382 they will crawl over land */
1389 maxx = min(x + 1, COLNO - 1);
1390 maxy = min(y + 1, ROWNO - 1);
1391 for (nx = max(1, x - 1); nx <= maxx; nx++)
1392 for (ny = max(0, y - 1); ny <= maxy; ny++) {
1393 if (nx == x && ny == y)
1395 ntyp = levl[nx][ny].typ;
1397 && !((flag & ALLOW_WALL) && may_passwall(nx, ny))
1398 && !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx, ny)))
1400 /* KMH -- Added iron bars */
1401 if (ntyp == IRONBARS && !(flag & ALLOW_BARS))
1403 if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon))
1404 && (((levl[nx][ny].doormask & D_CLOSED) && !(flag & OPENDOOR))
1405 || ((levl[nx][ny].doormask & D_LOCKED)
1406 && !(flag & UNLOCKDOOR))) && !thrudoor)
1408 /* avoid poison gas? */
1409 if (!poisongas_ok && !in_poisongas
1410 && (gas_reg = visible_region_at(nx,ny)) != 0
1411 && gas_reg->glyph == gas_glyph)
1413 /* first diagonal checks (tight squeezes handled below) */
1414 if (nx != x && ny != y
1416 || (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN))
1417 || (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN))
1418 || ((IS_DOOR(nowtyp) || IS_DOOR(ntyp))
1419 && Is_rogue_level(&u.uz))
1420 /* mustn't pass between adjacent long worm segments,
1421 but can attack that way */
1422 || (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny)
1423 && !m_at(nx, ny) && (nx != u.ux || ny != u.uy))))
1425 if ((is_pool(nx, ny) == wantpool || poolok)
1426 && (lavaok || !is_lava(nx, ny))) {
1428 boolean monseeu = (mon->mcansee
1429 && (!Invis || perceives(mdat)));
1430 boolean checkobj = OBJ_AT(nx, ny);
1432 /* Displacement also displaces the Elbereth/scare monster,
1433 * as long as you are visible.
1435 if (Displaced && monseeu && mon->mux == nx && mon->muy == ny) {
1444 if (onscary(dispx, dispy, mon)) {
1445 if (!(flag & ALLOW_SSM))
1447 info[cnt] |= ALLOW_SSM;
1449 if ((nx == u.ux && ny == u.uy)
1450 || (nx == mon->mux && ny == mon->muy)) {
1451 if (nx == u.ux && ny == u.uy) {
1452 /* If it's right next to you, it found you,
1453 * displaced or no. We must set mux and muy
1454 * right now, so when we return we can tell
1455 * that the ALLOW_U means to attack _you_ and
1461 if (!(flag & ALLOW_U))
1463 info[cnt] |= ALLOW_U;
1465 if (MON_AT(nx, ny)) {
1466 struct monst *mtmp2 = m_at(nx, ny);
1467 long mmflag = flag | mm_aggression(mon, mtmp2);
1469 if (mmflag & ALLOW_M) {
1470 info[cnt] |= ALLOW_M;
1472 if (!(mmflag & ALLOW_TM))
1474 info[cnt] |= ALLOW_TM;
1477 mmflag = flag | mm_displacement(mon, mtmp2);
1478 if (!(mmflag & ALLOW_MDISP))
1480 info[cnt] |= ALLOW_MDISP;
1483 /* Note: ALLOW_SANCT only prevents movement, not
1484 attack, into a temple. */
1485 if (level.flags.has_temple && *in_rooms(nx, ny, TEMPLE)
1486 && !*in_rooms(x, y, TEMPLE)
1487 && in_your_sanctuary((struct monst *) 0, nx, ny)) {
1488 if (!(flag & ALLOW_SANCT))
1490 info[cnt] |= ALLOW_SANCT;
1493 if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
1494 if (flag & NOGARLIC)
1496 info[cnt] |= NOGARLIC;
1498 if (checkobj && sobj_at(BOULDER, nx, ny)) {
1499 if (!(flag & ALLOW_ROCK))
1501 info[cnt] |= ALLOW_ROCK;
1503 if (monseeu && onlineu(nx, ny)) {
1506 info[cnt] |= NOTONL;
1508 /* check for diagonal tight squeeze */
1509 if (nx != x && ny != y && bad_rock(mdat, x, ny)
1510 && bad_rock(mdat, nx, y) && cant_squeeze_thru(mon))
1512 /* The monster avoids a particular type of trap if it's
1513 * familiar with the trap type. Pets get ALLOW_TRAPS
1514 * and checking is done in dogmove.c. In either case,
1515 * "harmless" traps are neither avoided nor marked in info[].
1517 if ((ttmp = t_at(nx, ny)) != 0) {
1518 if (ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) {
1520 "A monster looked at a very strange trap of type %d.",
1524 if ((ttmp->ttyp != RUST_TRAP
1525 || mdat == &mons[PM_IRON_GOLEM])
1526 && ttmp->ttyp != STATUE_TRAP
1527 && ((ttmp->ttyp != PIT && ttmp->ttyp != SPIKED_PIT
1528 && ttmp->ttyp != TRAPDOOR && ttmp->ttyp != HOLE)
1529 || (!is_flyer(mdat) && !is_floater(mdat)
1530 && !is_clinger(mdat)) || Sokoban)
1531 && (ttmp->ttyp != SLP_GAS_TRAP || !resists_sleep(mon))
1532 && (ttmp->ttyp != BEAR_TRAP
1533 || (mdat->msize > MZ_SMALL && !amorphous(mdat)
1534 && !is_flyer(mdat) && !is_floater(mdat)
1535 && !is_whirly(mdat) && !unsolid(mdat)))
1536 && (ttmp->ttyp != FIRE_TRAP || !resists_fire(mon))
1537 && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat))
1538 && (ttmp->ttyp != WEB
1539 || (!amorphous(mdat) && !webmaker(mdat)
1540 && !is_whirly(mdat) && !unsolid(mdat)))
1541 && (ttmp->ttyp != ANTI_MAGIC || !resists_magm(mon))) {
1542 if (!(flag & ALLOW_TRAPS)) {
1543 if (mon->mtrapseen & (1L << (ttmp->ttyp - 1)))
1546 info[cnt] |= ALLOW_TRAPS;
1554 if (!cnt && wantpool && !is_pool(x, y)) {
1561 /* Monster against monster special attacks; for the specified monster
1562 combinations, this allows one monster to attack another adjacent one
1563 in the absence of Conflict. There is no provision for targetting
1564 other monsters; just hand to hand fighting when they happen to be
1565 next to each other. */
1567 mm_aggression(magr, mdef)
1568 struct monst *magr, /* monster that is currently deciding where to move */
1569 *mdef; /* another monster which is next to it */
1571 /* supposedly purple worms are attracted to shrieking because they
1572 like to eat shriekers, so attack the latter when feasible */
1573 if (magr->data == &mons[PM_PURPLE_WORM]
1574 && mdef->data == &mons[PM_SHRIEKER])
1575 return ALLOW_M | ALLOW_TM;
1576 /* Various other combinations such as dog vs cat, cat vs rat, and
1577 elf vs orc have been suggested. For the time being we don't
1582 /* Monster displacing another monster out of the way */
1584 mm_displacement(magr, mdef)
1585 struct monst *magr, /* monster that is currently deciding where to move */
1586 *mdef; /* another monster which is next to it */
1588 struct permonst *pa = magr->data, *pd = mdef->data;
1590 /* if attacker can't barge through, there's nothing to do;
1591 or if defender can barge through too, don't let attacker
1592 do so, otherwise they might just end up swapping places
1593 again when defender gets its chance to move */
1594 if ((pa->mflags3 & M3_DISPLACES) != 0 && (pd->mflags3 & M3_DISPLACES) == 0
1595 /* no displacing grid bugs diagonally */
1596 && !(magr->mx != mdef->mx && magr->my != mdef->my
1597 && NODIAG(monsndx(pd)))
1598 /* no displacing trapped monsters or multi-location longworms */
1599 && !mdef->mtrapped && (!mdef->wormno || !count_wsegs(mdef))
1600 /* riders can move anything; others, same size or smaller only */
1601 && (is_rider(pa) || pa->msize >= pd->msize))
1606 /* Is the square close enough for the monster to move or attack into? */
1612 int distance = dist2(mon->mx, mon->my, x, y);
1614 if (distance == 2 && NODIAG(mon->data - mons))
1616 return (boolean) (distance < 3);
1619 /* really free dead monsters */
1623 struct monst **mtmp, *freetmp;
1626 for (mtmp = &fmon; *mtmp;) {
1628 if (freetmp->mhp <= 0 && !freetmp->isgd) {
1629 *mtmp = freetmp->nmon;
1630 freetmp->nmon = NULL;
1631 dealloc_monst(freetmp);
1634 mtmp = &(freetmp->nmon);
1637 if (count != iflags.purge_monsters)
1638 impossible("dmonsfree: %d removed doesn't match %d pending",
1639 count, iflags.purge_monsters);
1640 iflags.purge_monsters = 0;
1643 /* called when monster is moved to larger structure */
1645 replmon(mtmp, mtmp2)
1646 struct monst *mtmp, *mtmp2;
1650 /* transfer the monster's inventory */
1651 for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
1652 if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
1653 impossible("replmon: minvent inconsistency");
1654 otmp->ocarry = mtmp2;
1658 /* remove the old monster from the map and from `fmon' list */
1659 relmon(mtmp, (struct monst **) 0);
1661 /* finish adding its replacement */
1662 if (mtmp != u.usteed) /* don't place steed onto the map */
1663 place_monster(mtmp2, mtmp2->mx, mtmp2->my);
1664 if (mtmp2->wormno) /* update level.monsters[wseg->wx][wseg->wy] */
1665 place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */
1666 if (emits_light(mtmp2->data)) {
1667 /* since this is so rare, we don't have any `mon_move_light_source' */
1668 new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
1669 LS_MONSTER, monst_to_any(mtmp2));
1670 /* here we rely on fact that `mtmp' hasn't actually been deleted */
1671 del_light_source(LS_MONSTER, monst_to_any(mtmp));
1675 if (u.ustuck == mtmp)
1677 if (u.usteed == mtmp)
1680 replshk(mtmp, mtmp2);
1682 /* discard the old monster */
1683 dealloc_monst(mtmp);
1686 /* release mon from the display and the map's monster list,
1687 maybe transfer it to one of the other monster lists */
1689 relmon(mon, monst_list)
1691 struct monst **monst_list; /* &migrating_mons or &mydogs or null */
1694 boolean unhide = (monst_list != 0);
1695 int mx = mon->mx, my = mon->my;
1698 panic("relmon: no fmon available.");
1701 /* can't remain hidden across level changes (exception: wizard
1702 clone can continue imitating some other monster form); also,
1703 might be imitating a boulder so need line-of-sight unblocking */
1704 mon->mundetected = 0;
1705 if (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)
1712 remove_monster(mx, my);
1717 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1718 if (mtmp->nmon == mon)
1722 mtmp->nmon = mon->nmon;
1724 panic("relmon: mon not in list.");
1729 /* insert into mydogs or migrating_mons */
1730 mon->nmon = *monst_list;
1733 /* orphan has no next monster */
1739 copy_mextra(mtmp2, mtmp1)
1740 struct monst *mtmp2, *mtmp1;
1742 if (!mtmp2 || !mtmp1 || !mtmp1->mextra)
1746 mtmp2->mextra = newmextra();
1748 new_mname(mtmp2, (int) strlen(MNAME(mtmp1)) + 1);
1749 Strcpy(MNAME(mtmp2), MNAME(mtmp1));
1754 *EGD(mtmp2) = *EGD(mtmp1);
1759 *EPRI(mtmp2) = *EPRI(mtmp1);
1764 *ESHK(mtmp2) = *ESHK(mtmp1);
1769 *EMIN(mtmp2) = *EMIN(mtmp1);
1774 *EDOG(mtmp2) = *EDOG(mtmp1);
1776 if (has_mcorpsenm(mtmp1))
1777 MCORPSENM(mtmp2) = MCORPSENM(mtmp1);
1784 struct mextra *x = m->mextra;
1788 free((genericptr_t) x->mname);
1790 free((genericptr_t) x->egd);
1792 free((genericptr_t) x->epri);
1794 free((genericptr_t) x->eshk);
1796 free((genericptr_t) x->emin);
1798 free((genericptr_t) x->edog);
1799 /* [no action needed for x->mcorpsenm] */
1801 free((genericptr_t) x);
1802 m->mextra = (struct mextra *) 0;
1811 panic("dealloc_monst with nmon");
1813 dealloc_mextra(mon);
1814 free((genericptr_t) mon);
1817 /* remove effects of mtmp from other data structures */
1819 m_detach(mtmp, mptr)
1821 struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
1823 if (mtmp == context.polearm.hitmon)
1824 context.polearm.hitmon = 0;
1826 m_unleash(mtmp, FALSE);
1827 /* to prevent an infinite relobj-flooreffects-hmon-killed loop */
1829 mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
1830 relobj(mtmp, 0, FALSE);
1831 remove_monster(mtmp->mx, mtmp->my);
1832 if (emits_light(mptr))
1833 del_light_source(LS_MONSTER, monst_to_any(mtmp));
1834 if (mtmp->m_ap_type)
1836 newsym(mtmp->mx, mtmp->my);
1838 fill_pit(mtmp->mx, mtmp->my);
1844 iflags.purge_monsters++;
1847 /* find the worn amulet of life saving which will save a monster */
1852 if (!nonliving(mon->data) || is_vampshifter(mon)) {
1853 struct obj *otmp = which_armor(mon, W_AMUL);
1855 if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING)
1858 return (struct obj *) 0;
1862 lifesaved_monster(mtmp)
1866 struct obj *lifesave = mlifesaver(mtmp);
1869 /* not canseemon; amulets are on the head, so you don't want
1870 * to show this for a long worm with only a tail visible.
1871 * Nor do you check invisibility, because glowing and
1872 * disintegrating amulets are always visible. */
1873 if (cansee(mtmp->mx, mtmp->my)) {
1875 pline("But wait...");
1877 pline("
\82¿
\82å
\82Á
\82Æ
\82Ü
\82Á
\82½
\81D
\81D
\81D");
1879 pline("%s medallion begins to glow!", s_suffix(Monnam(mtmp)));
1881 pline("%s
\82Ì
\96\82\8f\9c\82¯
\82ª
\8bP
\82«
\82Í
\82¶
\82ß
\82½
\81I", Monnam(mtmp));
1882 makeknown(AMULET_OF_LIFE_SAVING);
1883 /* amulet is visible, but monster might not be */
1884 if (canseemon(mtmp)) {
1885 if (attacktype(mtmp->data, AT_EXPL)
1886 || attacktype(mtmp->data, AT_BOOM))
1888 pline("%s reconstitutes!", Monnam(mtmp));
1890 pline("%s
\82Í
\8dÄ
\8d\
\90¬
\82³
\82ê
\82½
\81I", Monnam(mtmp));
1893 pline("%s looks much better!", Monnam(mtmp));
1895 pline("%s
\82Í
\82·
\82Á
\82©
\82è
\89ñ
\95\9c\82µ
\82½
\82æ
\82¤
\82¾
\81I", Monnam(mtmp));
1898 pline_The("medallion crumbles to dust!");
1900 pline("
\96\82\8f\9c\82¯
\82Í
\82±
\82È
\82²
\82È
\82É
\82
\82¾
\82¯
\82½
\81I");
1902 m_useup(mtmp, lifesave);
1904 surviver = !(mvitals[monsndx(mtmp->data)].mvflags & G_GENOD);
1907 if (mtmp->mtame && !mtmp->isminion) {
1908 wary_dog(mtmp, !surviver);
1910 if (mtmp->mhpmax <= 0)
1912 mtmp->mhp = mtmp->mhpmax;
1916 /* genocided monster can't be life-saved */
1917 if (cansee(mtmp->mx, mtmp->my))
1919 pline("Unfortunately, %s is still genocided...", mon_nam(mtmp));
1921 pline("
\8ec
\94O
\82È
\82ª
\82ç%s
\82Í
\8bs
\8eE
\82³
\82ê
\82Ä
\82¢
\82é
\81D
\81D
\81D", mon_nam(mtmp));
1928 register struct monst *mtmp;
1930 struct permonst *mptr;
1933 mtmp->mhp = 0; /* in case caller hasn't done this */
1934 lifesaved_monster(mtmp);
1938 if (is_vampshifter(mtmp)) {
1939 int mndx = mtmp->cham;
1940 int x = mtmp->mx, y = mtmp->my;
1942 /* this only happens if shapeshifted */
1943 if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
1944 && !(mvitals[mndx].mvflags & G_GENOD)) {
1946 boolean in_door = (amorphous(mtmp->data)
1947 && closed_door(mtmp->mx, mtmp->my)),
1948 /* alternate message phrasing for some monster types */
1949 spec_mon = (nonliving(mtmp->data)
1950 || noncorporeal(mtmp->data)
1951 || amorphous(mtmp->data)),
1952 spec_death = (disintegested /* disintegrated or digested */
1953 || noncorporeal(mtmp->data)
1954 || amorphous(mtmp->data));
1956 /* construct a format string before transformation;
1957 will be capitalized when used, expects one %s arg */
1959 Sprintf(buf, "%s suddenly %s and rises as %%s!",
1960 x_monnam(mtmp, ARTICLE_THE,
1961 spec_mon ? (char *) 0 : "seemingly dead",
1962 SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1963 | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1965 spec_death ? "reconstitutes" : "transforms");
1967 Sprintf(buf, "%s%s
\82Í
\93Ë
\91R%s
\81C%%s
\82Æ
\82µ
\82Ä
\91h
\82Á
\82½
\81I",
1968 spec_death ? "" : "
\8e\80\82ñ
\82¾
\82æ
\82¤
\82É
\8ev
\82í
\82ê
\82½",
1969 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
1970 SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1971 | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1973 spec_death ? "
\8dÄ
\8d\
\90¬
\82³
\82ê" : "
\95Ï
\89»
\82µ");
1977 if (mtmp->mhpmax <= 0)
1979 mtmp->mhp = mtmp->mhpmax;
1980 /* this can happen if previously a fog cloud */
1981 if (u.uswallow && (mtmp == u.ustuck))
1982 expels(mtmp, mtmp->data, FALSE);
1986 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
1987 rloc_to(mtmp, new_xy.x, new_xy.y);
1990 newcham(mtmp, &mons[mndx], FALSE, FALSE);
1991 if (mtmp->data == &mons[mndx])
1992 mtmp->cham = NON_PM;
1995 if (canspotmon(mtmp)) {
1996 /* was using a_monnam(mtmp) but that's weird if mtmp is named:
1997 "Dracula suddenly transforms and rises as Dracula" */
1998 pline(upstart(buf), an(mtmp->data->mname));
1999 vamp_rise_msg = TRUE;
2006 /* dead vault guard is actually kept at coordinate <0,0> until
2007 his temporary corridor to/from the vault has been removed;
2008 need to do this after life-saving and before m_detach() */
2009 if (mtmp->isgd && !grddead(mtmp))
2012 /* Player is thrown from his steed when it dies */
2013 if (mtmp == u.usteed)
2014 dismount_steed(DISMOUNT_GENERIC);
2016 mptr = mtmp->data; /* save this for m_detach() */
2017 /* restore chameleon, lycanthropes to true form at death */
2018 if (mtmp->cham >= LOW_PM) {
2019 set_mon_data(mtmp, &mons[mtmp->cham], -1);
2020 mtmp->cham = NON_PM;
2021 } else if (mtmp->data == &mons[PM_WEREJACKAL])
2022 set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL], -1);
2023 else if (mtmp->data == &mons[PM_WEREWOLF])
2024 set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF], -1);
2025 else if (mtmp->data == &mons[PM_WERERAT])
2026 set_mon_data(mtmp, &mons[PM_HUMAN_WERERAT], -1);
2029 * mvitals[].died does double duty as total number of dead monsters
2030 * and as experience factor for the player killing more monsters.
2031 * this means that a dragon dying by other means reduces the
2032 * experience the player gets for killing a dragon directly; this
2033 * is probably not too bad, since the player likely finagled the
2034 * first dead dragon via ring of conflict or pets, and extinguishing
2035 * based on only player kills probably opens more avenues of abuse
2036 * for rings of conflict and such.
2038 tmp = monsndx(mtmp->data);
2039 if (mvitals[tmp].died < 255)
2040 mvitals[tmp].died++;
2042 /* if it's a (possibly polymorphed) quest leader, mark him as dead */
2043 if (mtmp->m_id == quest_status.leader_m_id)
2044 quest_status.leader_is_dead = TRUE;
2046 /* if the mail daemon dies, no more mail delivery. -3. */
2047 if (tmp == PM_MAIL_DAEMON)
2048 mvitals[tmp].mvflags |= G_GENOD;
2051 if (mtmp->data->mlet == S_KOP) {
2052 /* Dead Kops may come back. */
2054 case 1: /* returns near the stairs */
2055 (void) makemon(mtmp->data, xdnstair, ydnstair, NO_MM_FLAGS);
2057 case 2: /* randomly */
2058 (void) makemon(mtmp->data, 0, 0, NO_MM_FLAGS);
2066 if (mtmp->data->msound == MS_NEMESIS)
2068 if (mtmp->data == &mons[PM_MEDUSA])
2069 u.uachieve.killed_medusa = 1;
2070 if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
2071 unmap_object(mtmp->mx, mtmp->my);
2072 m_detach(mtmp, mptr);
2075 /* TRUE if corpse might be dropped, magr may die if mon was swallowed */
2077 corpse_chance(mon, magr, was_swallowed)
2079 struct monst *magr; /* killer, if swallowed */
2080 boolean was_swallowed; /* digestion */
2082 struct permonst *mdat = mon->data;
2085 if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) {
2086 if (cansee(mon->mx, mon->my) && !was_swallowed)
2088 pline("%s body crumbles into dust.", s_suffix(Monnam(mon)));
2090 pline("%s
\82Ì
\91Ì
\82Í
\95²
\81X
\82É
\82È
\82Á
\82½
\81D", Monnam(mon));
2094 /* Gas spores always explode upon death */
2095 for (i = 0; i < NATTK; i++) {
2096 if (mdat->mattk[i].aatyp == AT_BOOM) {
2097 if (mdat->mattk[i].damn)
2098 tmp = d((int) mdat->mattk[i].damn, (int) mdat->mattk[i].damd);
2099 else if (mdat->mattk[i].damd)
2100 tmp = d((int) mdat->mlevel + 1, (int) mdat->mattk[i].damd);
2103 if (was_swallowed && magr) {
2104 if (magr == &youmonst) {
2106 There("is an explosion in your %s!", body_part(STOMACH));
2108 pline("%s
\82Ì
\92\86\82Å
\94\9a\94
\82ª
\8bN
\82«
\82½
\81I", body_part(STOMACH));
2110 Sprintf(killer.name, "%s explosion",
2111 s_suffix(mdat->mname));
2113 Sprintf(killer.name, "%s
\82Ì
\94\9a\94
\82Å", mdat->mname);
2115 losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN);
2118 You_hear("an explosion.");
2120 You_hear("
\94\9a\94
\89¹
\82ð
\95·
\82¢
\82½
\81D");
2124 if (magr->mhp < 1) { /* maybe lifesaved */
2125 if (canspotmon(magr))
2127 pline("%s rips open!", Monnam(magr));
2129 pline("%s
\82Í
\83r
\83\8a\82Á
\82Æ
\94j
\82ê
\82½
\81I", Monnam(magr));
2130 } else if (canseemon(magr))
2132 pline("%s seems to have indigestion.", Monnam(magr));
2134 pline("%s
\82Í
\8fÁ
\89»
\95s
\97Ç
\82Ì
\82æ
\82¤
\82¾
\81D", Monnam(magr));
2141 Sprintf(killer.name, "%s explosion", s_suffix(mdat->mname));
2143 Sprintf(killer.name, "%s
\82Ì
\94\9a\94
\82Å", mdat->mname);
2144 killer.format = KILLED_BY_AN;
2145 explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS);
2146 killer.name[0] = '\0';
2152 /* must duplicate this below check in xkilled() since it results in
2153 * creating no objects as well as no corpse
2155 if (LEVEL_SPECIFIC_NOCORPSE(mdat))
2158 if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned)
2159 || is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat) || mon->isshk)
2161 tmp = 2 + ((mdat->geno & G_FREQ) < 2) + verysmall(mdat);
2162 return (boolean) !rn2(tmp);
2165 /* drop (perhaps) a cadaver and remove monster */
2168 register struct monst *mdef;
2172 return; /* lifesaved */
2174 if (corpse_chance(mdef, (struct monst *) 0, FALSE)
2175 && (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my)))
2176 (void) make_corpse(mdef, CORPSTAT_NONE);
2179 /* monster disappears, not dies */
2184 mdef->mhp = 0; /* can skip some inventory bookkeeping */
2186 /* dead vault guard is actually kept at coordinate <0,0> until
2187 his temporary corridor to/from the vault has been removed */
2188 if (mdef->isgd && !grddead(mdef))
2190 /* hero is thrown from his steed when it disappears */
2191 if (mdef == u.usteed)
2192 dismount_steed(DISMOUNT_GENERIC);
2193 /* stuck to you? release */
2195 /* drop special items like the Amulet so that a dismissed Kop or nurse
2196 can't remove them from the game */
2197 mdrop_special_objs(mdef);
2198 /* release rest of monster's inventory--it is removed from game */
2199 discard_minvent(mdef);
2200 m_detach(mdef, mdef->data);
2203 /* drop a statue or rock and remove monster */
2208 struct obj *otmp, *obj, *oldminvent;
2209 xchar x = mdef->mx, y = mdef->my;
2210 boolean wasinside = FALSE;
2212 if (!vamp_stone(mdef)) /* vampshifter reverts to vampire */
2215 /* we have to make the statue before calling mondead, to be able to
2216 * put inventory in it, and we have to check for lifesaving before
2217 * making the statue....
2219 mdef->mhp = 0; /* in case caller hasn't done this */
2220 lifesaved_monster(mdef);
2224 mdef->mtrapped = 0; /* (see m_detach) */
2226 if ((int) mdef->data->msize > MZ_TINY
2227 || !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) {
2229 /* some objects may end up outside the statue */
2230 while ((obj = mdef->minvent) != 0) {
2231 obj_extract_self(obj);
2233 update_mon_intrinsics(mdef, obj, FALSE, TRUE);
2234 obj_no_longer_held(obj);
2235 if (obj->owornmask & W_WEP)
2236 setmnotwielded(mdef, obj);
2237 obj->owornmask = 0L;
2238 if (obj->otyp == BOULDER
2239 #if 0 /* monsters don't carry statues */
2240 || (obj->otyp == STATUE
2241 && mons[obj->corpsenm].msize >= mdef->data->msize)
2243 /* invocation tools resist even with 0% resistance */
2244 || obj_resists(obj, 0, 0)) {
2246 if (flooreffects(obj, x, y, "fall"))
2248 if (flooreffects(obj, x, y, "
\97\8e\82¿
\82é"))
2250 place_object(obj, x, y);
2253 end_burn(obj, TRUE);
2254 obj->nobj = oldminvent;
2258 /* defer statue creation until after inventory removal
2259 so that saved monster traits won't retain any stale
2260 item-conferred attributes */
2261 otmp = mkcorpstat(STATUE, mdef, mdef->data, x, y, CORPSTAT_NONE);
2262 if (has_mname(mdef))
2263 otmp = oname(otmp, MNAME(mdef));
2264 while ((obj = oldminvent) != 0) {
2265 oldminvent = obj->nobj;
2266 (void) add_to_container(otmp, obj);
2268 /* Archeologists should not break unique statues */
2269 if (mdef->data->geno & G_UNIQ)
2271 otmp->owt = weight(otmp);
2273 otmp = mksobj_at(ROCK, x, y, TRUE, FALSE);
2276 /* mondead() already does this, but we must do it before the newsym */
2277 if (glyph_is_invisible(levl[x][y].glyph))
2281 /* We don't currently trap the hero in the statue in this case but we
2283 if (u.uswallow && u.ustuck == mdef)
2287 if (is_animal(mdef->data))
2289 You("%s through an opening in the new %s.",
2290 locomotion(youmonst.data, "jump"), xname(otmp));
2292 You("
\90V
\82µ
\82
\82Å
\82«
\82½%s
\82©
\82ç%s
\81D",
2293 xname(otmp), jumpedthrough(youmonst.data, "
\94ò
\82Ñ
\8fo
\82½"));
2298 /* another monster has killed the monster mdef */
2300 monkilled(mdef, fltxt, how)
2305 boolean be_sad = FALSE; /* true if unseen pet is killed */
2307 if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my))
2310 pline("%s is %s%s%s!", Monnam(mdef),
2311 nonliving(mdef->data) ? "destroyed" : "killed",
2312 *fltxt ? " by the " : "", fltxt);
2316 pline("%s
\82Í%s
\82É
\82æ
\82Á
\82Ä%s
\81I", Monnam(mdef), fltxt,
2317 nonliving(mdef->data) ? "
\93|
\82³
\82ê
\82½" : "
\8eE
\82³
\82ê
\82½");
2319 pline("%s
\82Í%s
\81I", Monnam(mdef),
2320 nonliving(mdef->data) ? "
\93|
\82³
\82ê
\82½" : "
\8eE
\82³
\82ê
\82½");
2324 be_sad = (mdef->mtame != 0);
2326 /* no corpses if digested or disintegrated */
2327 disintegested = (how == AD_DGST || how == -AD_RBRE);
2333 if (be_sad && mdef->mhp <= 0)
2335 You("have a sad feeling for a moment, then it passes.");
2337 You("
\94ß
\82µ
\82¢
\8bC
\8e\9d\82É
\82¨
\82»
\82í
\82ê
\82½
\82ª
\81C
\82·
\82®
\82É
\89ß
\82¬
\82³
\82Á
\82½
\81D");
2344 if (u.ustuck == mtmp) {
2350 if (Punished && uchain->where != OBJ_FLOOR)
2352 vision_full_recalc = 1;
2354 /* prevent swallower (mtmp might have just poly'd into something
2355 without an engulf attack) from immediately re-engulfing */
2356 if (attacktype(mtmp->data, AT_ENGL) && !mtmp->mspec_used)
2357 mtmp->mspec_used = rnd(2);
2367 xkilled(mtmp, XKILL_GIVEMSG);
2370 /* the player has killed the monster mtmp */
2372 xkilled(mtmp, xkill_flags)
2374 int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */
2376 int tmp, mndx, x = mtmp->mx, y = mtmp->my;
2377 struct permonst *mdat;
2380 boolean wasinside = u.uswallow && (u.ustuck == mtmp),
2382 nomsg = (xkill_flags & XKILL_NOMSG) != 0,
2383 nocorpse = (xkill_flags & XKILL_NOCORPSE) != 0,
2384 noconduct = (xkill_flags & XKILL_NOCONDUCT) != 0;
2386 mtmp->mhp = 0; /* caller will usually have already done this */
2387 if (!noconduct) /* KMH, conduct */
2388 u.uconduct.killer++;
2391 boolean namedpet = has_mname(mtmp) && !Hallucination;
2395 nonliving(mtmp->data) ? "destroy" : "kill",
2396 !(wasinside || canspotmon(mtmp)) ? "it"
2397 : !mtmp->mtame ? mon_nam(mtmp)
2398 : x_monnam(mtmp, namedpet ? ARTICLE_NONE : ARTICLE_THE,
2399 "poor", namedpet ? SUPPRESS_SADDLE : 0, FALSE));
2401 You("%s%s
\82ð
\93|
\82µ
\82½
\81I",
2402 !(wasinside || canspotmon(mtmp)) ? "
\82»
\82ê"
2403 : mtmp->mtame ? "
\82©
\82í
\82¢
\82»
\82¤
\82È" : "",
2408 if (mtmp->mtrapped && (t = t_at(x, y)) != 0
2409 && (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
2410 if (sobj_at(BOULDER, x, y))
2411 nocorpse = TRUE; /* Prevent corpses/treasure being created
2412 "on top" of boulder that is about to fall in.
2413 This is out of order, but cannot be helped
2414 unless this whole routine is rearranged. */
2415 if (m_carrying(mtmp, BOULDER))
2419 /* your pet knows who just killed it...watch out */
2420 if (mtmp->mtame && !mtmp->isminion)
2421 EDOG(mtmp)->killed_by_u = 1;
2423 if (wasinside && thrownobj && thrownobj != uball) {
2424 /* thrown object has killed hero's engulfer; add it to mon's
2425 inventory now so that it will be placed with mon's other
2426 stuff prior to lookhere/autopickup when hero is expelled
2427 below (as a side-effect, this missile has immunity from
2428 being consumed [for this shot/throw only]) */
2429 mpickobj(mtmp, thrownobj);
2430 /* let throwing code know that missile has been disposed of */
2434 vamp_rise_msg = FALSE; /* might get set in mondead(); only checked below */
2435 disintegested = nocorpse; /* alternate vamp_rise message needed if true */
2436 /* dispose of monster and make cadaver */
2441 disintegested = FALSE; /* reset */
2443 if (mtmp->mhp > 0) { /* monster lifesaved */
2444 /* Cannot put the non-visible lifesaving message in
2445 * lifesaved_monster() since the message appears only when _you_
2446 * kill it (as opposed to visible lifesaving which always appears).
2449 if (!cansee(x, y) && !vamp_rise_msg)
2451 pline("Maybe not...");
2453 pline("
\82¢
\82â
\81C
\88á
\82¤
\82©
\82à
\81D
\81D
\81D");
2457 mdat = mtmp->data; /* note: mondead can change mtmp->data */
2458 mndx = monsndx(mdat);
2465 if (nocorpse || LEVEL_SPECIFIC_NOCORPSE(mdat))
2469 if (mdat == &mons[PM_MAIL_DAEMON]) {
2470 stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE));
2473 if (accessible(x, y) || is_pool(x, y)) {
2474 struct obj *cadaver;
2477 /* illogical but traditional "treasure drop" */
2478 if (!rn2(6) && !(mvitals[mndx].mvflags & G_NOCORPSE)
2479 /* no extra item from swallower or steed */
2480 && (x != u.ux || y != u.uy)
2481 /* no extra item from kops--too easy to abuse */
2482 && mdat->mlet != S_KOP
2483 /* no items from cloned monsters */
2484 && !mtmp->mcloned) {
2485 otmp = mkobj(RANDOM_CLASS, TRUE);
2486 /* don't create large objects from small monsters */
2488 if (mdat->msize < MZ_HUMAN && otyp != FIGURINE
2489 /* oc_big is also oc_bimanual and oc_bulky */
2490 && (otmp->owt > 30 || objects[otyp].oc_big)) {
2493 } else if (!flooreffects(otmp, x, y, nomsg ? "" : "fall")) {
2495 } else if (!flooreffects(otmp, x, y, nomsg ? "" : "
\97\8e\82¿
\82é")) {
2497 place_object(otmp, x, y);
2501 /* corpse--none if hero was inside the monster */
2502 if (!wasinside && corpse_chance(mtmp, (struct monst *) 0, FALSE)) {
2503 cadaver = make_corpse(mtmp, burycorpse ? CORPSTAT_BURIED
2505 if (burycorpse && cadaver && cansee(x, y) && !mtmp->minvis
2506 && cadaver->where == OBJ_BURIED && !nomsg) {
2508 pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp)));
2510 pline("%s
\82Ì
\8e\80\91Ì
\82Í
\96\84\82Ü
\82Á
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D", Monnam(mtmp));
2515 spoteffects(TRUE); /* poor man's expels() */
2516 /* monster is gone, corpse or other object might now be visible */
2520 /* punish bad behaviour */
2522 && (!always_hostile(mdat) && mtmp->malign <= 0)
2523 && (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD)
2524 && u.ualign.type != A_CHAOTIC) {
2525 HTelepat &= ~INTRINSIC;
2530 You("
\8eE
\90l
\8bS
\82¾
\81I");
2531 if (Blind && !Blind_telepat)
2532 see_monsters(); /* Can't sense monsters any more. */
2534 if ((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame)
2536 if (is_unicorn(mdat) && sgn(u.ualign.type) == sgn(mdat->maligntyp)) {
2539 You_feel("guilty...");
2541 You("
\8dß
\82ð
\8a´
\82¶
\82½
\81D
\81D
\81D");
2544 /* give experience points */
2545 tmp = experience(mtmp, (int) mvitals[mndx].died);
2546 more_experienced(tmp, 0);
2547 newexplevel(); /* will decide if you go up */
2549 /* adjust alignment points */
2550 if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */
2551 adjalign(-(u.ualign.record + (int) ALIGNLIM / 2));
2553 pline("That was %sa bad idea...",
2554 u.uevent.qcompleted ? "probably " : "");
2556 pline("%s
\82æ
\82
\82È
\82¢
\8ds
\88×
\82¾
\82Á
\82½
\81D
\81D
\81D",
2557 u.uevent.qcompleted ? "
\82½
\82Ô
\82ñ" : "");
2559 } else if (mdat->msound == MS_NEMESIS) { /* Real good! */
2560 adjalign((int) (ALIGNLIM / 4));
2561 } else if (mdat->msound == MS_GUARDIAN) { /* Bad */
2562 adjalign(-(int) (ALIGNLIM / 8));
2565 pline("That was probably a bad idea...");
2567 pline("
\82æ
\82
\82È
\82¢
\8ds
\88×
\82¾
\82Á
\82½
\81D
\81D
\81D");
2570 pline("Whoopsie-daisy!");
2572 pline("
\83V
\83\93\83W
\83}
\83b
\83^
\81[
\81I");
2573 } else if (mtmp->ispriest) {
2574 adjalign((p_coaligned(mtmp)) ? -2 : 2);
2575 /* cancel divine protection for killing your priest */
2576 if (p_coaligned(mtmp))
2578 if (mdat->maligntyp == A_NONE)
2579 adjalign((int) (ALIGNLIM / 4)); /* BIG bonus */
2580 } else if (mtmp->mtame) {
2581 adjalign(-15); /* bad!! */
2582 /* your god is mighty displeased... */
2585 You_hear("the rumble of distant thunder...");
2587 You_hear("
\89\93\82
\82Å
\97\8b\96Â
\82ð
\95·
\82¢
\82½
\81D
\81D
\81D");
2590 You_hear("the studio audience applaud!");
2592 pline("
\92®
\8fO
\82Ì
\8a\85\8dÑ
\82ð
\97\81\82Ñ
\82½
\81I");
2593 } else if (mtmp->mpeaceful)
2596 /* malign was already adjusted for u.ualign.type and randomization */
2597 adjalign(mtmp->malign);
2600 /* changes the monster into a stone monster of the same type
2601 this should only be called when poly_when_stoned() is true */
2606 if (mtmp->data->mlet == S_GOLEM) {
2607 /* it's a golem, and not a stone golem */
2608 if (canseemon(mtmp))
2610 pline("%s solidifies...", Monnam(mtmp));
2612 pline("%s
\82Í
\8bÃ
\8cÅ
\82µ
\82½
\81D
\81D
\81D", Monnam(mtmp));
2613 if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) {
2614 if (canseemon(mtmp))
2616 pline("Now it's %s.", an(mtmp->data->mname));
2618 pline("
\82È
\82ñ
\82Æ%s
\82É
\82È
\82Á
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D", mtmp->data->mname);
2620 if (canseemon(mtmp))
2622 pline("... and returns to normal.");
2624 pline("
\81D
\81D
\81D
\82»
\82µ
\82Ä
\95\81\92Ê
\82É
\96ß
\82Á
\82½
\81D");
2627 impossible("Can't polystone %s!", a_monnam(mtmp));
2634 if (is_vampshifter(mtmp)) {
2635 int mndx = mtmp->cham;
2636 int x = mtmp->mx, y = mtmp->my;
2638 /* this only happens if shapeshifted */
2639 if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
2640 && !(mvitals[mndx].mvflags & G_GENOD)) {
2642 boolean in_door = (amorphous(mtmp->data)
2643 && closed_door(mtmp->mx, mtmp->my));
2645 /* construct a format string before transformation */
2647 Sprintf(buf, "The lapidifying %s %s %s",
2648 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2649 (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2650 | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2651 amorphous(mtmp->data) ? "coalesces on the"
2652 : is_flyer(mtmp->data) ? "drops to the"
2656 Sprintf(buf, "
\90Î
\89»
\82µ
\82Â
\82Â
\82 \82é%s
\82ª%s%s",
2657 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2658 (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2659 | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2661 amorphous(mtmp->data) ? "
\82Ì
\8fã
\82Å
\97Z
\8d\87\82µ
\82½"
2662 : is_flyer(mtmp->data) ? "
\82É
\97\8e\82¿
\82½"
2663 : "
\82Ì
\8fã
\82Å
\90g
\82à
\82¾
\82¦
\82½");
2667 if (mtmp->mhpmax <= 0)
2669 mtmp->mhp = mtmp->mhpmax;
2670 /* this can happen if previously a fog cloud */
2671 if (u.uswallow && (mtmp == u.ustuck))
2672 expels(mtmp, mtmp->data, FALSE);
2676 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
2677 rloc_to(mtmp, new_xy.x, new_xy.y);
2680 if (canspotmon(mtmp)) {
2684 pline("%s
\81I", buf);
2685 display_nhwindow(WIN_MESSAGE, FALSE);
2687 newcham(mtmp, &mons[mndx], FALSE, FALSE);
2688 if (mtmp->data == &mons[mndx])
2689 mtmp->cham = NON_PM;
2692 if (canspotmon(mtmp)) {
2694 pline("%s rises from the %s with renewed agility!",
2695 Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2697 pline("%s
\82Í
\8b@
\95q
\82³
\82ð
\8eæ
\82è
\96ß
\82µ
\82Ä%s
\82©
\82ç
\95\9c\8a\88\82µ
\82½
\81I",
2698 Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2701 newsym(mtmp->mx, mtmp->my);
2702 return FALSE; /* didn't petrify */
2708 /* drop monster into "limbo" - that is, migrate to the current level */
2714 mdrop_special_objs(mtmp);
2715 migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_APPROX_XY, NULL);
2718 /* make monster mtmp next to you (if possible);
2719 might place monst on far side of a wall or boulder */
2725 boolean couldspot = canspotmon(mtmp);
2727 if (mtmp == u.usteed) {
2728 /* Keep your steed in sync with you instead */
2734 if (!enexto(&mm, u.ux, u.uy, mtmp->data)) {
2738 if (!isok(mm.x, mm.y))
2740 rloc_to(mtmp, mm.x, mm.y);
2741 if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) {
2742 mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */
2743 if (!couldspot && canspotmon(mtmp))
2745 pline("%s suddenly %s!", Amonnam(mtmp),
2746 !Blind ? "appears" : "arrives");
2748 pline("
\93Ë
\91R%s
\82ª
\8c»
\82ê
\82½
\81I", Amonnam(mtmp));
2754 /* like mnexto() but requires destination to be directly accessible */
2760 struct permonst *ptr = mtmp->data;
2761 boolean diagok = !NODIAG(ptr - mons);
2765 if (!enexto(&mm, u.ux, u.uy, ptr))
2767 if (couldsee(mm.x, mm.y)
2768 /* don't move grid bugs diagonally */
2769 && (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) {
2770 rloc_to(mtmp, mm.x, mm.y);
2773 } while (--tryct > 0);
2777 * Put monster near (or at) location if possible.
2779 * true if relocation was successful
2783 mnearto(mtmp, x, y, move_other)
2784 register struct monst *mtmp;
2786 boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */
2788 struct monst *othermon = (struct monst *) 0;
2792 if (mtmp->mx == x && mtmp->my == y)
2795 if (move_other && (othermon = m_at(x, y)) != 0) {
2796 if (othermon->wormno)
2797 remove_worm(othermon);
2799 remove_monster(x, y);
2804 if (!goodpos(newx, newy, mtmp, 0)) {
2805 /* Actually we have real problems if enexto ever fails.
2806 * Migrating_mons that need to be placed will cause
2807 * no end of trouble.
2809 if (!enexto(&mm, newx, newy, mtmp->data))
2811 if (!isok(mm.x,mm.y))
2816 rloc_to(mtmp, newx, newy);
2818 if (move_other && othermon) {
2819 xchar oldx = othermon->mx, oldy = othermon->my;
2821 othermon->mx = othermon->my = 0;
2822 (void) mnearto(othermon, x, y, FALSE);
2823 if (othermon->mx == 0 && othermon->my == 0) {
2825 othermon->mx = oldx;
2826 othermon->my = oldy;
2827 m_into_limbo(othermon);
2834 /* monster responds to player action; not the same as a passive attack;
2835 assumes reason for response has been tested, and response _must_ be made */
2840 if (mtmp->data->msound == MS_SHRIEK) {
2843 pline("%s shrieks.", Monnam(mtmp));
2845 pline("%s
\82Í
\8bà
\90Ø
\82è
\90º
\82ð
\82 \82°
\82½
\81D", Monnam(mtmp));
2850 (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
2852 (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS);
2856 if (mtmp->data == &mons[PM_MEDUSA]) {
2859 for (i = 0; i < NATTK; i++)
2860 if (mtmp->data->mattk[i].aatyp == AT_GAZE) {
2861 (void) gazemu(mtmp, &mtmp->data->mattk[i]);
2867 /* Called whenever the player attacks mtmp; also called in other situations
2868 where mtmp gets annoyed at the player. Handles mtmp getting annoyed at the
2869 attack and any ramifications that might have. Useful also in situations
2870 where mtmp was already hostile; it checks for situations where the player
2871 shouldn't be attacking and any ramifications /that/ might have. */
2873 setmangry(mtmp, via_attack)
2877 if (via_attack && sengr_at("Elbereth", u.ux, u.uy, TRUE)) {
2879 You_feel("like a hypocrite.");
2881 You_feel("
\8bU
\91P
\8eÒ
\82Ì
\82æ
\82¤
\82È
\8bC
\82ª
\82µ
\82½
\81D");
2882 /* AIS: Yes, I know alignment penalties and bonuses aren't balanced
2883 at the moment. This is about correct relative to other "small"
2884 penalties; it should be fairly large, as attacking while standing
2885 on an Elbereth means that you're requesting peace and then
2886 violating your own request. I know 5 isn't actually large, but
2887 it's intentionally larger than the 1s and 2s that are normally
2888 given for this sort of thing. */
2893 pline("The engraving beneath you fades.");
2895 pline("
\82 \82È
\82½
\82Ì
\91«
\8c³
\82Ì
\95¶
\8e\9a\82ª
\94\96\82ê
\82½
\81D");
2896 del_engr_at(u.ux, u.uy);
2899 /* AIS: Should this be in both places, or just in wakeup()? */
2900 mtmp->mstrategy &= ~STRAT_WAITMASK;
2901 if (!mtmp->mpeaceful)
2905 mtmp->mpeaceful = 0;
2906 if (mtmp->ispriest) {
2907 if (p_coaligned(mtmp))
2908 adjalign(-5); /* very bad */
2912 adjalign(-1); /* attacking peaceful monsters is bad */
2913 if (couldsee(mtmp->mx, mtmp->my)) {
2914 if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
2916 pline("%s gets angry!", Monnam(mtmp));
2918 pline("%s
\82Í
\93{
\82Á
\82½
\81I", Monnam(mtmp));
2919 else if (flags.verbose && !Deaf)
2923 /* attacking your own quest leader will anger his or her guardians */
2924 if (!context.mon_moving /* should always be the case here */
2925 && mtmp->data == &mons[quest_info(MS_LEADER)]) {
2927 struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
2930 /* guardians will sense this attack even if they can't see it */
2931 for (mon = fmon; mon; mon = mon->nmon) {
2932 if (DEADMONSTER(mon))
2934 if (mon->data == q_guardian && mon->mpeaceful) {
2940 if (got_mad && !Hallucination) {
2941 const char *who = q_guardian->mname;
2945 who = makeplural(who);
2946 pline_The("%s %s to be angry too...",
2947 who, vtense(who, "appear"));
2949 pline("%s
\82à
\93{
\82Á
\82½
\82æ
\82¤
\82¾
\81D
\81D
\81D", who);
2954 /* make other peaceful monsters react */
2955 if (!context.mon_moving) {
2956 static const char *const Exclam[] = {
2958 "Gasp!", "Uh-oh.", "Oh my!", "What?", "Why?",
2960 "
\82®
\82Í
\82Á
\81I", "
\82¤
\82í
\81D", "Oh my!", "
\82È
\82É
\82Á
\81H", "
\82È
\82ñ
\82¾
\81H",
2963 int mndx = monsndx(mtmp->data);
2965 for (mon = fmon; mon; mon = mon->nmon) {
2966 if (DEADMONSTER(mon))
2968 if (mon == mtmp) /* the mpeaceful test catches this since mtmp */
2969 continue; /* is no longer peaceful, but be explicit... */
2971 if (!mindless(mon->data) && mon->mpeaceful
2972 && couldsee(mon->mx, mon->my) && !mon->msleeping
2973 && mon->mcansee && m_canseeu(mon)) {
2974 boolean exclaimed = FALSE;
2976 if (humanoid(mon->data) || mon->isshk || mon->ispriest) {
2977 if (is_watch(mon->data)) {
2979 verbalize("Halt! You're under arrest!");
2981 verbalize("
\8e~
\82Ü
\82ê
\81I
\91ß
\95ß
\82·
\82é
\81I");
2982 (void) angry_guards(!!Deaf);
2985 verbalize("%s", Exclam[mon->m_id % SIZE(Exclam)]);
2988 /* shopkeepers and temple priests might gasp in
2989 surprise, but they won't become angry here */
2990 if (mon->isshk || mon->ispriest)
2993 if (mon->data->mlevel < rn2(10)) {
2994 monflee(mon, rn2(50) + 25, TRUE, !exclaimed);
2998 /* mustn't set mpeaceful to 0 as below;
2999 perhaps reduce tameness? */
3005 pline("%s gets angry!", Monnam(mon));
3007 pline("%s
\82Í
\93{
\82Á
\82½
\81I", Monnam(mon));
3010 } else if (mon->data->mlet == mtmp->data->mlet
3011 && big_little_match(mndx, monsndx(mon->data))
3018 monflee(mon, rn2(25) + 15, TRUE, !exclaimed);
3025 /* wake up a monster, possibly making it angry in the process */
3027 wakeup(mtmp, via_attack)
3028 register struct monst *mtmp;
3031 mtmp->msleeping = 0;
3032 if (mtmp->m_ap_type) {
3034 } else if (context.forcefight && !context.mon_moving
3035 && mtmp->mundetected) {
3036 mtmp->mundetected = 0;
3037 newsym(mtmp->mx, mtmp->my);
3039 finish_meating(mtmp);
3041 setmangry(mtmp, TRUE);
3044 /* Wake up nearby monsters without angering them. */
3048 register struct monst *mtmp;
3050 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3051 if (DEADMONSTER(mtmp))
3053 if (distu(mtmp->mx, mtmp->my) < u.ulevel * 20) {
3054 mtmp->msleeping = 0;
3055 if (!unique_corpstat(mtmp->data))
3056 mtmp->mstrategy &= ~STRAT_WAITMASK;
3058 if (!mtmp->isminion)
3059 EDOG(mtmp)->whistletime = moves;
3060 /* Clear mtrack. This is to fix up a pet who is
3061 stuck "fleeing" its master. */
3062 memset(mtmp->mtrack, 0, sizeof(mtmp->mtrack));
3068 /* Wake up monsters near some particular location. */
3070 wake_nearto(x, y, distance)
3071 register int x, y, distance;
3073 register struct monst *mtmp;
3075 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3076 if (DEADMONSTER(mtmp))
3078 if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
3079 mtmp->msleeping = 0;
3080 if (!unique_corpstat(mtmp->data))
3081 mtmp->mstrategy &= ~STRAT_WAITMASK;
3086 /* NOTE: we must check for mimicry before calling this routine */
3089 register struct monst *mtmp;
3091 boolean is_blocker_appear = (is_lightblocker_mappear(mtmp));
3093 if (has_mcorpsenm(mtmp))
3094 freemcorpsenm(mtmp);
3096 mtmp->m_ap_type = M_AP_NOTHING;
3097 mtmp->mappearance = 0;
3100 * Discovered mimics don't block light.
3102 if (is_blocker_appear
3103 && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
3104 unblock_point(mtmp->mx, mtmp->my);
3106 newsym(mtmp->mx, mtmp->my);
3109 /* force all chameleons to become normal */
3113 register struct monst *mtmp;
3116 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3117 if (DEADMONSTER(mtmp))
3119 mcham = (int) mtmp->cham;
3120 if (mcham >= LOW_PM) {
3121 (void) newcham(mtmp, &mons[mcham], FALSE, FALSE);
3122 mtmp->cham = NON_PM;
3124 if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
3126 if (mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) {
3128 /* we pretend that the mimic doesn't
3129 know that it has been unmasked */
3130 mtmp->msleeping = 1;
3135 /* Let the chameleons change again -dgk */
3139 register struct monst *mtmp;
3141 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3142 if (DEADMONSTER(mtmp))
3144 mtmp->cham = pm_to_cham(monsndx(mtmp->data));
3145 if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping
3146 && cansee(mtmp->mx, mtmp->my)) {
3147 set_mimic_sym(mtmp);
3148 newsym(mtmp->mx, mtmp->my);
3153 /* called when restoring a monster from a saved level; protection
3154 against shape-changing might be different now than it was at the
3155 time the level was saved. */
3162 if (Protection_from_shape_changers) {
3163 mcham = (int) mon->cham;
3164 if (mcham >= LOW_PM) {
3166 (void) newcham(mon, &mons[mcham], FALSE, FALSE);
3167 } else if (is_were(mon->data) && !is_human(mon->data)) {
3170 } else if (mon->cham == NON_PM) {
3171 mon->cham = pm_to_cham(monsndx(mon->data));
3175 /* unwatched hiders may hide again; if so, returns True */
3178 register struct monst *mtmp;
3182 if (mtmp->mcan || mtmp->m_ap_type || cansee(mtmp->mx, mtmp->my)
3183 || rn2(3) || mtmp == u.ustuck
3184 /* can't hide while trapped except in pits */
3185 || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
3186 && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))
3187 || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
3190 if (mtmp->data->mlet == S_MIMIC) {
3191 set_mimic_sym(mtmp);
3193 } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) {
3194 mtmp->mundetected = 1;
3201 /* monster/hero tries to hide under something at the current location */
3207 boolean undetected = FALSE, is_u = (mtmp == &youmonst);
3208 xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
3210 if (mtmp == u.ustuck) {
3211 ; /* can't hide if holding you or held by you */
3212 } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
3213 : (mtmp->mtrapped && (t = t_at(x, y)) != 0
3214 && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) {
3215 ; /* can't hide while stuck in a non-pit trap */
3216 } else if (mtmp->data->mlet == S_EEL) {
3217 undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
3218 } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
3219 struct obj *otmp = level.objects[x][y];
3221 /* most monsters won't hide under cockatrice corpse */
3222 if (otmp->nexthere || otmp->otyp != CORPSE
3223 || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp))
3224 || !touch_petrifies(&mons[otmp->corpsenm]))
3229 u.uundetected = undetected;
3231 mtmp->mundetected = undetected;
3235 /* called when returning to a previously visited level */
3240 boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL;
3242 if ((is_hider(mon->data) || hider_under)
3243 && !(mon->mundetected || mon->m_ap_type)) {
3244 xchar x = mon->mx, y = mon->my;
3245 char save_viz = viz_array[y][x];
3247 /* override vision, forcing hero to be unable to see monster's spot */
3248 viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE);
3249 if (is_hider(mon->data))
3250 (void) restrap(mon);
3251 /* try again if mimic missed its 1/3 chance to hide */
3252 if (mon->data->mlet == S_MIMIC && !mon->m_ap_type)
3253 (void) restrap(mon);
3255 (void) hideunder(mon);
3256 viz_array[y][x] = save_viz;
3260 static short *animal_list = 0; /* list of PM values for animal monsters */
3261 static int animal_list_count;
3264 mon_animal_list(construct)
3268 short animal_temp[SPECIAL_PM];
3271 /* if (animal_list) impossible("animal_list already exists"); */
3273 for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
3274 if (is_animal(&mons[i]))
3275 animal_temp[n++] = i;
3276 /* if (n == 0) animal_temp[n++] = NON_PM; */
3278 animal_list = (short *) alloc(n * sizeof *animal_list);
3279 (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp,
3280 n * sizeof *animal_list);
3281 animal_list_count = n;
3282 } else { /* release */
3284 free((genericptr_t) animal_list), animal_list = 0;
3285 animal_list_count = 0;
3295 mon_animal_list(TRUE);
3297 res = animal_list[rn2(animal_list_count)];
3298 /* rogue level should use monsters represented by uppercase letters
3299 only, but since chameleons aren't generated there (not uppercase!)
3300 we don't perform a lot of retries */
3301 if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet))
3302 res = animal_list[rn2(animal_list_count)];
3307 decide_to_shapeshift(mon, shiftflags)
3311 struct permonst *ptr = 0;
3313 unsigned was_female = mon->female;
3314 boolean msg = FALSE, dochng = FALSE;
3316 if ((shiftflags & SHIFT_MSG)
3317 || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon)))
3320 if (!is_vampshifter(mon)) {
3321 /* regular shapeshifter */
3325 /* The vampire has to be in good health (mhp) to maintain
3328 * If we're shifted and getting low on hp, maybe shift back, or
3329 * if we're a fog cloud at full hp, maybe pick a different shape.
3330 * If we're not already shifted and in good health, maybe shift.
3332 if (mon->data->mlet != S_VAMPIRE) {
3333 if ((mon->mhp <= (mon->mhpmax + 5) / 6) && rn2(4)
3334 && mon->cham >= LOW_PM) {
3335 ptr = &mons[mon->cham];
3337 } else if (mon->data == &mons[PM_FOG_CLOUD]
3338 && mon->mhp == mon->mhpmax && !rn2(4)
3340 || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM)) {
3341 /* if a fog cloud, maybe change to wolf or vampire bat;
3342 those are more likely to take damage--at least when
3343 tame--and then switch back to vampire; they'll also
3344 switch to fog cloud if they encounter a closed door */
3345 mndx = pickvampshape(mon);
3346 if (mndx >= LOW_PM) {
3348 dochng = (ptr != mon->data);
3352 if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6)
3354 || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM))
3355 dochng = TRUE; /* 'ptr' stays Null */
3359 if (newcham(mon, ptr, FALSE, msg) && is_vampshifter(mon)) {
3360 /* for vampshift, override the 10% chance for sex change */
3362 if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr))
3363 mon->female = was_female;
3372 int mndx = mon->cham, wolfchance = 10;
3373 /* avoid picking monsters with lowercase display symbols ('d' for wolf
3374 and 'v' for fog cloud) on rogue level*/
3375 boolean uppercase_only = Is_rogue_level(&u.uz);
3378 case PM_VLAD_THE_IMPALER:
3379 /* ensure Vlad can keep carrying the Candelabrum */
3380 if (mon_has_special(mon))
3381 break; /* leave mndx as is */
3384 case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */
3385 if (!rn2(wolfchance) && !uppercase_only) {
3390 case PM_VAMPIRE: /* any vampire can become fog or bat */
3391 mndx = (!rn2(4) && !uppercase_only) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
3397 /* nonshapechangers who warrant special polymorph handling */
3402 return (mon->isshk || mon->ispriest || mon->isgd
3403 || mon->m_id == quest_status.leader_m_id);
3406 /* restrict certain special monsters (shopkeepers, aligned priests,
3407 vault guards) to forms that allow them to behave sensibly (catching
3408 gold, speaking?) so that they don't need too much extra code */
3410 validspecmon(mon, mndx)
3415 return TRUE; /* caller wants random */
3417 if (!accept_newcham_form(mndx))
3418 return FALSE; /* geno'd or !polyok */
3420 if (isspecmon(mon)) {
3421 struct permonst *ptr = &mons[mndx];
3423 /* reject notake because object manipulation is expected
3424 and nohead because speech capability is expected */
3425 if (notake(ptr) || !has_head(ptr))
3427 /* [should we check ptr->msound here too?] */
3429 return TRUE; /* potential new form is ok */
3432 /* prevent wizard mode user from specifying invalid vampshifter shape */
3434 validvamp(mon, mndx_p, monclass)
3436 int *mndx_p, monclass;
3438 /* simplify caller's usage */
3439 if (!is_vampshifter(mon))
3440 return validspecmon(mon, *mndx_p);
3442 if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD
3443 || *mndx_p == PM_VLAD_THE_IMPALER) {
3444 /* player picked some type of vampire; use mon's self */
3445 *mndx_p = mon->cham;
3448 if (mon->cham == PM_VLAD_THE_IMPALER && mon_has_special(mon)) {
3449 /* Vlad with Candelabrum; override choice, then accept it */
3450 *mndx_p = PM_VLAD_THE_IMPALER;
3453 /* basic vampires can't become wolves; any can become fog or bat
3454 (we don't enforce upper-case only for rogue level here) */
3455 if (*mndx_p == PM_WOLF)
3456 return (boolean) (mon->cham != PM_VAMPIRE);
3457 if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT)
3460 /* if we get here, specific type was no good; try by class */
3463 *mndx_p = mon->cham;
3466 *mndx_p = PM_VAMPIRE_BAT;
3469 *mndx_p = PM_FOG_CLOUD;
3472 if (mon->cham != PM_VAMPIRE) {
3481 return (boolean) (*mndx_p != NON_PM);
3485 select_newcham_form(mon)
3488 int mndx = NON_PM, tryct;
3490 switch (mon->cham) {
3493 mndx = pick_nasty();
3495 case PM_DOPPELGANGER:
3497 mndx = pick_nasty();
3498 } else if (rn2(3)) { /* role monsters */
3499 mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
3500 } else if (!rn2(3)) { /* quest guardians */
3501 mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT);
3502 /* avoid own role's guardian */
3503 if (mndx == urole.guardnum)
3505 } else { /* general humanoids */
3508 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3509 if (humanoid(&mons[mndx]) && polyok(&mons[mndx]))
3511 } while (--tryct > 0);
3518 mndx = pick_animal();
3520 case PM_VLAD_THE_IMPALER:
3521 case PM_VAMPIRE_LORD:
3523 mndx = pickvampshape(mon);
3525 case NON_PM: /* ordinary */
3527 struct obj *m_armr = which_armor(mon, W_ARM);
3529 if (m_armr && Is_dragon_scales(m_armr))
3530 mndx = (int) (Dragon_scales_to_pm(m_armr) - mons);
3531 else if (m_armr && Is_dragon_mail(m_armr))
3532 mndx = (int) (Dragon_mail_to_pm(m_armr) - mons);
3537 /* for debugging: allow control of polymorphed monster */
3538 if (wizard && iflags.mon_polycontrol) {
3539 char pprompt[BUFSZ], buf[BUFSZ] = DUMMY;
3542 Sprintf(pprompt, "Change %s @ %s into what kind of monster?",
3544 coord_desc((int) mon->mx, (int) mon->my, buf,
3545 (iflags.getpos_coords != GPCOORDS_NONE)
3546 ? iflags.getpos_coords : GPCOORDS_MAP));
3550 getlin(pprompt, buf);
3552 /* for ESC, take form selected above (might be NON_PM) */
3555 /* for "*", use NON_PM to pick an arbitrary shape below */
3556 if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
3560 mndx = name_to_mon(buf);
3561 if (mndx == NON_PM) {
3562 /* didn't get a type, so check whether it's a class
3563 (single letter or text match with def_monsyms[]) */
3564 monclass = name_to_monclass(buf, &mndx);
3565 if (monclass && mndx == NON_PM)
3566 mndx = mkclass_poly(monclass);
3568 if (mndx >= LOW_PM) {
3569 /* got a specific type of monster; use it if we can */
3570 if (validvamp(mon, &mndx, monclass))
3572 /* can't; revert to random in case we exhaust tryct */
3576 pline("It can't become that.");
3577 } while (--tryct > 0);
3579 pline1(thats_enough_tries);
3580 if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass))
3581 mndx = pickvampshape(mon); /* don't resort to arbitrary */
3584 /* if no form was specified above, pick one at random now */
3585 if (mndx == NON_PM) {
3588 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3589 } while (--tryct > 0 && !validspecmon(mon, mndx)
3590 /* try harder to select uppercase monster on rogue level */
3591 && (tryct > 40 && Is_rogue_level(&u.uz)
3592 && !isupper((uchar) mons[mndx].mlet)));
3597 /* this used to be inline within newcham() but monpolycontrol needs it too */
3598 STATIC_OVL struct permonst *
3599 accept_newcham_form(mndx)
3602 struct permonst *mdat;
3607 if ((mvitals[mndx].mvflags & G_GENOD) != 0)
3609 if (is_placeholder(mdat))
3611 /* select_newcham_form() might deliberately pick a player
3612 character type (random selection never does) which
3613 polyok() rejects, so we need a special case here */
3614 if (is_mplayer(mdat))
3616 /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */
3617 return polyok(mdat) ? mdat : 0;
3621 mgender_from_permonst(mtmp, mdat)
3623 struct permonst *mdat;
3625 if (is_male(mdat)) {
3627 mtmp->female = FALSE;
3628 } else if (is_female(mdat)) {
3630 mtmp->female = TRUE;
3631 } else if (!is_neuter(mdat)) {
3633 mtmp->female = !mtmp->female;
3637 /* make a chameleon take on another shape, or a polymorph target
3638 (possibly self-inflicted) become a different monster;
3639 returns 1 if it actually changes form */
3641 newcham(mtmp, mdat, polyspot, msg)
3643 struct permonst *mdat;
3644 boolean polyspot; /* change is the result of wand or spell of polymorph */
3645 boolean msg; /* "The oldmon turns into a newmon!" */
3649 struct permonst *olddata = mtmp->data;
3650 char *p, oldname[BUFSZ], l_oldname[BUFSZ], newname[BUFSZ];
3652 /* Riders are immune to polymorph and green slime
3653 (but apparent Rider might actually be a doppelganger) */
3654 if (mtmp->cham == NON_PM) { /* not a shapechanger */
3655 if (is_rider(olddata))
3657 /* make Nazgul and erinyes immune too, to reduce chance of
3658 anomalous extinction feedback during final disclsoure */
3659 if (mbirth_limit(monsndx(olddata)) < MAXMONNO)
3664 /* like Monnam() but never mention saddle */
3665 Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3666 SUPPRESS_SADDLE, FALSE));
3667 oldname[0] = highc(oldname[0]);
3669 /* we need this one whether msg is true or not */
3670 Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3671 has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE));
3673 /* mdat = 0 -> caller wants a random monster shape */
3675 /* select_newcham_form() loops when resorting to random but
3676 it doesn't always pick that so we still retry here too */
3679 mndx = select_newcham_form(mtmp);
3680 mdat = accept_newcham_form(mndx);
3681 /* for the first several tries we require upper-case on
3682 the rogue level (after that, we take whatever we get) */
3683 if (tryct > 15 && Is_rogue_level(&u.uz)
3684 && mdat && !isupper((uchar) mdat->mlet))
3688 } while (--tryct > 0);
3691 } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
3692 return 0; /* passed in mdat is genocided */
3694 if (mdat == olddata)
3695 return 0; /* still the same monster */
3697 mgender_from_permonst(mtmp, mdat);
3698 /* Endgame mplayers start out as "Foo the Bar", but some of the
3699 * titles are inappropriate when polymorphed, particularly into
3700 * the opposite sex. Player characters don't use ranks when
3701 * polymorphed, so dropping rank for mplayers seems reasonable.
3703 if (In_endgame(&u.uz) && is_mplayer(olddata)
3704 && has_mname(mtmp) && (p = strstr(MNAME(mtmp), " the ")) != 0)
3707 if (mtmp->wormno) { /* throw tail away */
3709 place_monster(mtmp, mtmp->mx, mtmp->my);
3711 if (mtmp->m_ap_type && mdat->mlet != S_MIMIC)
3712 seemimic(mtmp); /* revert to normal monster */
3714 /* (this code used to try to adjust the monster's health based on
3715 a normal one of its type but there are too many special cases
3716 which need to handled in order to do that correctly, so just
3717 give the new form the same proportion of HP as its old one had) */
3720 /* set level and hit points */
3721 newmonhp(mtmp, monsndx(mdat));
3722 /* new hp: same fraction of max as before */
3724 mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd);
3726 /* sanity check (potential overflow) */
3727 if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax)
3728 mtmp->mhp = mtmp->mhpmax;
3729 /* unlikely but not impossible; a 1HD creature with 1HP that changes
3730 into a 0HD creature will require this statement */
3734 /* take on the new form... */
3735 set_mon_data(mtmp, mdat, 0);
3737 if (emits_light(olddata) != emits_light(mtmp->data)) {
3738 /* used to give light, now doesn't, or vice versa,
3739 or light's range has changed */
3740 if (emits_light(olddata))
3741 del_light_source(LS_MONSTER, monst_to_any(mtmp));
3742 if (emits_light(mtmp->data))
3743 new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
3744 LS_MONSTER, monst_to_any(mtmp));
3746 if (!mtmp->perminvis || pm_invisible(olddata))
3747 mtmp->perminvis = pm_invisible(mdat);
3748 mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
3749 if (mtmp->mundetected)
3750 (void) hideunder(mtmp);
3751 if (u.ustuck == mtmp) {
3753 if (!attacktype(mdat, AT_ENGL)) {
3754 /* Does mdat care? */
3755 if (!noncorporeal(mdat) && !amorphous(mdat)
3756 && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) {
3757 char msgtrail[BUFSZ];
3759 if (is_vampshifter(mtmp)) {
3761 Sprintf(msgtrail, " which was a shapeshifted %s",
3762 noname_monnam(mtmp, ARTICLE_NONE));
3764 Sprintf(msgtrail, "(
\8eÀ
\8dÛ
\82É
\82Í
\8c`
\82ð
\95Ï
\82¦
\82½%s)",
3765 noname_monnam(mtmp, ARTICLE_NONE));
3767 } else if (is_animal(mdat)) {
3769 Strcpy(msgtrail, "'s stomach");
3771 Strcpy(msgtrail, "
\82Ì
\88Ý");
3776 /* Do this even if msg is FALSE */
3779 (amorphous(olddata) || is_whirly(olddata))
3780 ? "emerge from" : "break out of",
3781 l_oldname, msgtrail);
3783 You("%s%s%s
\81I", l_oldname, msgtrail,
3784 (amorphous(olddata) || is_whirly(olddata))
3785 ? "
\82©
\82ç
\94ò
\82Ñ
\8fo
\82µ
\82½" : "
\82ð
\94j
\82è
\8fo
\82½"
3788 msg = FALSE; /* message has been given */
3789 mtmp->mhp = 1; /* almost dead */
3791 expels(mtmp, olddata, FALSE);
3793 /* update swallow glyphs for new monster */
3796 } else if (!sticks(mdat) && !sticks(youmonst.data))
3801 if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
3803 /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
3806 if (mdat == &mons[PM_LONG_WORM]
3807 && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
3809 /* we can now create worms with tails - 11/91 */
3810 initworm(mtmp, rn2(5));
3811 if (count_wsegs(mtmp))
3812 place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
3815 newsym(mtmp->mx, mtmp->my);
3818 Strcpy(newname, noname_monnam(mtmp, ARTICLE_A));
3819 /* oldname was capitalized above; newname will be lower case */
3821 if (!strcmpi(newname, "it")) { /* can't see or sense it now */
3823 if (!strcmpi(newname, "
\89½
\8eÒ
\82©")) { /* can't see or sense it now */
3826 if (!!strcmpi(oldname, "it")) /* could see or sense it before */
3828 if (!!strcmpi(oldname, "
\89½
\8eÒ
\82©")) /* could see or sense it before */
3830 pline("%s disappears!", oldname);
3831 (void) usmellmon(mdat);
3832 } else { /* can see or sense it now */
3834 if (!strcmpi(oldname, "it")) /* couldn't see or sense it before */
3836 if (!strcmpi(oldname, "
\89½
\8eÒ
\82©")) /* couldn't see or sense it before */
3838 pline("%s appears!", upstart(newname));
3841 pline("%s turns into %s!", oldname, newname);
3843 pline("%s
\82Í%s
\82É
\82È
\82Á
\82½
\81I", oldname, newname);
3847 /* when polymorph trap/wand/potion produces a vampire, turn in into
3848 a full-fledged vampshifter unless shape-changing is blocked */
3849 if (mtmp->cham == NON_PM && mdat->mlet == S_VAMPIRE
3850 && !Protection_from_shape_changers)
3851 mtmp->cham = pm_to_cham(monsndx(mdat));
3853 possibly_unwield(mtmp, polyspot); /* might lose use of weapon */
3854 mon_break_armor(mtmp, polyspot);
3855 if (!(mtmp->misc_worn_check & W_ARMG))
3857 mselftouch(mtmp, "No longer petrify-resistant, ",
3858 !context.mon_moving);
3860 mselftouch(mtmp, "
\90Î
\89»
\82Ö
\82Ì
\92ï
\8dR
\97Í
\82ª
\82È
\82
\82È
\82Á
\82Ä
\81C",
3861 !context.mon_moving);
3863 m_dowear(mtmp, FALSE);
3865 /* This ought to re-test can_carry() on each item in the inventory
3866 * rather than just checking ex-giants & boulders, but that'd be
3867 * pretty expensive to perform. If implemented, then perhaps
3868 * minvent should be sorted in order to drop heaviest items first.
3870 /* former giants can't continue carrying boulders */
3871 if (mtmp->minvent && !throws_rocks(mdat)) {
3872 register struct obj *otmp, *otmp2;
3874 for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
3876 if (otmp->otyp == BOULDER) {
3877 /* this keeps otmp from being polymorphed in the
3878 same zap that the monster that held it is polymorphed */
3881 obj_extract_self(otmp);
3882 /* probably ought to give some "drop" message here */
3883 if (flooreffects(otmp, mtmp->mx, mtmp->my, ""))
3885 place_object(otmp, mtmp->mx, mtmp->my);
3893 /* sometimes an egg will be special */
3894 #define BREEDER_EGG (!rn2(77))
3897 * Determine if the given monster number can be hatched from an egg.
3898 * Return the monster number to use as the egg's corpsenm. Return
3899 * NON_PM if the given monster can't be hatched.
3902 can_be_hatched(mnum)
3905 /* ranger quest nemesis has the oviparous bit set, making it
3906 be possible to wish for eggs of that unique monster; turn
3907 such into ordinary eggs rather than forbidding them outright */
3908 if (mnum == PM_SCORPIUS)
3911 mnum = little_to_big(mnum);
3913 * Queen bees lay killer bee eggs (usually), but killer bees don't
3914 * grow into queen bees. Ditto for [winged-]gargoyles.
3916 if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE
3917 || (lays_eggs(&mons[mnum])
3919 || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
3924 /* type of egg laid by #sit; usually matches parent */
3926 egg_type_from_parent(mnum, force_ordinary)
3927 int mnum; /* parent monster; caller must handle lays_eggs() check */
3928 boolean force_ordinary;
3930 if (force_ordinary || !BREEDER_EGG) {
3931 if (mnum == PM_QUEEN_BEE)
3932 mnum = PM_KILLER_BEE;
3933 else if (mnum == PM_WINGED_GARGOYLE)
3939 /* decide whether an egg of the indicated monster type is viable;
3940 also used to determine whether an egg or tin can be created... */
3942 dead_species(m_idx, egg)
3948 /* generic eggs are unhatchable and have corpsenm of NON_PM */
3952 * For monsters with both baby and adult forms, genociding either
3953 * form kills all eggs of that monster. Monsters with more than
3954 * two forms (small->large->giant mimics) are more or less ignored;
3955 * fortunately, none of them have eggs. Species extinction due to
3956 * overpopulation does not kill eggs.
3958 alt_idx = egg ? big_to_little(m_idx) : m_idx;
3959 return (boolean) ((mvitals[m_idx].mvflags & G_GENOD) != 0
3960 || (mvitals[alt_idx].mvflags & G_GENOD) != 0);
3963 /* kill off any eggs of genocided monsters */
3966 struct obj *obj_list;
3970 for (otmp = obj_list; otmp; otmp = otmp->nobj)
3971 if (otmp->otyp == EGG) {
3972 if (dead_species(otmp->corpsenm, TRUE)) {
3974 * It seems we could also just catch this when
3975 * it attempted to hatch, so we wouldn't have to
3976 * search all of the objlists.. or stop all
3977 * hatch timers based on a corpsenm.
3981 #if 0 /* not used */
3982 } else if (otmp->otyp == TIN) {
3983 if (dead_species(otmp->corpsenm, FALSE))
3984 otmp->corpsenm = NON_PM; /* empty tin */
3985 } else if (otmp->otyp == CORPSE) {
3986 if (dead_species(otmp->corpsenm, FALSE))
3987 ; /* not yet implemented... */
3989 } else if (Has_contents(otmp)) {
3990 kill_eggs(otmp->cobj);
3994 /* kill all members of genocided species */
3996 kill_genocided_monsters()
3998 struct monst *mtmp, *mtmp2;
4003 * Called during genocide, and again upon level change. The latter
4004 * catches up with any migrating monsters as they finally arrive at
4005 * their intended destinations, so possessions get deposited there.
4007 * Chameleon handling:
4008 * 1) if chameleons have been genocided, destroy them
4009 * regardless of current form;
4010 * 2) otherwise, force every chameleon which is imitating
4011 * any genocided species to take on a new form.
4013 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
4015 if (DEADMONSTER(mtmp))
4017 mndx = monsndx(mtmp->data);
4018 kill_cham = (mtmp->cham >= LOW_PM
4019 && (mvitals[mtmp->cham].mvflags & G_GENOD));
4020 if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) {
4021 if (mtmp->cham >= LOW_PM && !kill_cham)
4022 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
4027 kill_eggs(mtmp->minvent);
4032 kill_eggs(migrating_objs);
4033 kill_eggs(level.buriedobjlist);
4037 golemeffects(mon, damtype, dam)
4038 register struct monst *mon;
4041 int heal = 0, slow = 0;
4043 if (mon->data == &mons[PM_FLESH_GOLEM]) {
4044 if (damtype == AD_ELEC)
4045 heal = (dam + 5) / 6;
4046 else if (damtype == AD_FIRE || damtype == AD_COLD)
4048 } else if (mon->data == &mons[PM_IRON_GOLEM]) {
4049 if (damtype == AD_ELEC)
4051 else if (damtype == AD_FIRE)
4057 if (mon->mspeed != MSLOW)
4058 mon_adjust_speed(mon, -1, (struct obj *) 0);
4061 if (mon->mhp < mon->mhpmax) {
4063 if (mon->mhp > mon->mhpmax)
4064 mon->mhp = mon->mhpmax;
4065 if (cansee(mon->mx, mon->my))
4067 pline("%s seems healthier.", Monnam(mon));
4069 pline("%s
\82Í
\8c³
\8bC
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81D", Monnam(mon));
4075 angry_guards(silent)
4079 int ct = 0, nct = 0, sct = 0, slct = 0;
4081 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4082 if (DEADMONSTER(mtmp))
4084 if (is_watch(mtmp->data) && mtmp->mpeaceful) {
4086 if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
4087 if (distu(mtmp->mx, mtmp->my) == 2)
4092 if (mtmp->msleeping || mtmp->mfrozen) {
4094 mtmp->msleeping = mtmp->mfrozen = 0;
4096 mtmp->mpeaceful = 0;
4100 if (!silent) { /* do we want pline msgs? */
4103 pline_The("guard%s wake%s up!", slct > 1 ? "s" : "",
4104 slct == 1 ? "s" : "");
4106 pline("
\94Ô
\95º
\82Í
\96Ú
\82ð
\8ao
\82Ü
\82µ
\82½
\81I");
4111 pline_The("guard%s get%s angry!", nct == 1 ? "" : "s",
4112 nct == 1 ? "s" : "");
4114 pline("
\94Ô
\95º
\82Í
\93{
\82Á
\82½
\81I");
4118 You_see("%sangry guard%s approaching!",
4119 sct == 1 ? "an " : "", sct > 1 ? "s" : "");
4121 You("
\93{
\82Á
\82½
\94Ô
\95º
\82ª
\8bß
\8añ
\82Á
\82Ä
\82
\82é
\82Ì
\82ð
\8c©
\82½
\81I");
4125 You_hear("the shrill sound of a guard's whistle.");
4127 You_hear("
\94Ô
\95º
\82Ì
\93J
\82ª
\82¯
\82½
\82½
\82Ü
\82µ
\82
\96Â
\82é
\82Ì
\82ð
\95·
\82¢
\82½
\81D");
4139 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4140 if (DEADMONSTER(mtmp))
4142 if (is_watch(mtmp->data))
4143 mtmp->mpeaceful = 1;
4148 mimic_hit_msg(mtmp, otyp)
4152 short ap = mtmp->mappearance;
4154 switch (mtmp->m_ap_type) {
4156 case M_AP_FURNITURE:
4160 if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
4162 pline("%s seems a more vivid %s than before.",
4163 The(simple_typename(ap)),
4164 c_obj_colors[objects[ap].oc_color]);
4166 pline("%s
\82Í
\88È
\91O
\82æ
\82è
\82æ
\82è
\91N
\82â
\82©
\82È%s
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D",
4167 The(simple_typename(ap)),
4168 c_obj_colors[objects[ap].oc_color]);
4177 struct permonst *mdat;
4180 boolean nonspecific = FALSE;
4181 boolean msg_given = FALSE;
4184 if (!olfaction(youmonst.data))
4186 mndx = monsndx(mdat);
4191 You("notice a bovine smell.");
4193 You("
\8b\8d\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4199 case PM_NEANDERTHAL:
4201 You("smell body odor.");
4203 pline("
\91Ì
\8fL
\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4212 case PM_HORNED_DEVIL:
4219 case PM_HUMAN_WEREJACKAL:
4220 case PM_HUMAN_WERERAT:
4221 case PM_HUMAN_WEREWOLF:
4227 You("detect an odor reminiscent of an animal's den.");
4229 pline("
\93®
\95¨
\82Ì
\82Ë
\82®
\82ç
\82ð
\8ev
\82¢
\8fo
\82·
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4233 case PM_PURPLE_WORM:
4236 case PM_STEAM_VORTEX:
4238 You("smell steam.");
4240 pline("
\8fö
\8bC
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4243 case PM_GREEN_SLIME:
4245 pline("%s stinks.", Something);
4247 pline("
\88«
\8fL
\82ª
\82µ
\82½
\81D");
4250 case PM_VIOLET_FUNGUS:
4253 You("smell mushrooms.");
4255 pline("
\82«
\82Ì
\82±
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4258 /* These are here to avoid triggering the
4259 nonspecific treatment through the default case below*/
4260 case PM_WHITE_UNICORN:
4261 case PM_GRAY_UNICORN:
4262 case PM_BLACK_UNICORN:
4271 switch (mdat->mlet) {
4274 You("notice a dog smell.");
4276 You("
\8c¢
\82Ì
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4281 You("smell a dragon!");
4283 pline("
\83h
\83\89\83S
\83\93\82Ì
\82É
\82¨
\82¢
\82ª
\82·
\82é
\81I");
4288 pline("%s smells moldy.", Something);
4290 pline("
\89½
\82©
\91Û
\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82·
\82é
\81D");
4295 You("detect a%s odor reminiscent of a stable.",
4296 (mndx == PM_PONY) ? "n" : " strong");
4298 pline("
\94n
\8f¬
\89®
\82ð
\8ev
\82¢
\8fo
\82·
\82æ
\82¤
\82È%s
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D",
4299 (mndx == PM_PONY) ? "" : "
\8b
\82¢");
4305 You("smell rotting flesh.");
4307 pline("
\95\85\82Á
\82½
\93÷
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4314 pline("
\8b\9b\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4318 if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
4320 You("notice an attractive smell.");
4322 You("
\96£
\97Í
\93I
\82È
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4325 pline("A foul stench makes you feel a little nauseated.");
4327 pline("
\82Þ
\82©
\82Â
\82
\82æ
\82¤
\82È
\88«
\8fL
\82Å
\8f
\82µ
\8bC
\95ª
\82ª
\88«
\82
\82È
\82Á
\82½
\81D");
4334 return msg_given ? TRUE : FALSE;