1 /* NetHack 3.6 mon.c $NHDT-Date: 1449269918 2015/12/04 22:58:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.199 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016 */
8 /* JNetHack may be freely redistributed. See license for details. */
10 /* If you're using precompiled headers, you don't want this either */
19 STATIC_VAR boolean vamp_rise_msg;
21 STATIC_DCL void FDECL(sanity_check_single_mon, (struct monst *, const char *));
22 STATIC_DCL boolean FDECL(restrap, (struct monst *));
23 STATIC_DCL long FDECL(mm_aggression, (struct monst *, struct monst *));
24 STATIC_DCL long FDECL(mm_displacement, (struct monst *, struct monst *));
25 STATIC_DCL int NDECL(pick_animal);
26 STATIC_DCL void FDECL(kill_eggs, (struct obj *));
27 STATIC_DCL int FDECL(pickvampshape, (struct monst *));
28 STATIC_DCL boolean FDECL(isspecmon, (struct monst *));
29 STATIC_DCL boolean FDECL(validspecmon, (struct monst *, int));
30 STATIC_DCL boolean FDECL(validvamp, (struct monst *, int *, int));
31 STATIC_DCL struct permonst *FDECL(accept_newcham_form, (int));
32 STATIC_DCL struct obj *FDECL(make_corpse, (struct monst *, unsigned));
33 STATIC_DCL void FDECL(m_detach, (struct monst *, struct permonst *));
34 STATIC_DCL void FDECL(lifesaved_monster, (struct monst *));
36 #define LEVEL_SPECIFIC_NOCORPSE(mdat) \
37 (Is_rogue_level(&u.uz) \
38 || (level.flags.graveyard && is_undead(mdat) && rn2(3)))
41 /* part of the original warning code which was replaced in 3.3.1 */
42 const char *warnings[] = {
44 "white", "pink", "red", "ruby", "purple", "black"
46 "
\94\92\82¢", "
\83s
\83\93\83N
\90F
\82Ì", "
\90Ô
\82¢", "
\83\8b\83r
\81[
\90F
\82Ì", "
\8e\87\82Ì", "
\8d\95\82¢"
52 sanity_check_single_mon(mtmp, msg)
56 if (DEADMONSTER(mtmp))
58 if (mtmp->data < &mons[LOW_PM] || mtmp->data >= &mons[NUMMONS])
59 impossible("illegal mon data (%s)", msg);
66 struct monst *mtmp = fmon;
69 sanity_check_single_mon(mtmp, "fmon");
72 for (x = 0; x < COLNO; x++)
73 for (y = 0; y < ROWNO; y++)
74 if ((mtmp = m_at(x,y)) != 0)
75 sanity_check_single_mon(mtmp, "m_at");
77 mtmp = migrating_mons;
79 sanity_check_single_mon(mtmp, "migr");
85 /* convert the monster index of an undead to its living counterpart */
87 undead_to_corpse(mndx)
91 case PM_KOBOLD_ZOMBIE:
112 case PM_VAMPIRE_LORD:
114 case PM_VAMPIRE_MAGE:
116 case PM_HUMAN_ZOMBIE:
120 case PM_GIANT_ZOMBIE:
124 case PM_ETTIN_ZOMBIE:
134 /* Convert the monster index of some monsters (such as quest guardians)
135 * to their generic species type.
137 * Return associated character class monster, rather than species
145 /* Quest guardians */
147 mndx = mode ? PM_ARCHEOLOGIST : PM_HUMAN;
150 mndx = mode ? PM_BARBARIAN : PM_HUMAN;
153 mndx = mode ? PM_CAVEMAN : PM_HUMAN;
156 mndx = mode ? PM_HEALER : PM_HUMAN;
159 mndx = mode ? PM_KNIGHT : PM_HUMAN;
162 mndx = mode ? PM_MONK : PM_HUMAN;
165 mndx = mode ? PM_PRIEST : PM_HUMAN;
168 mndx = mode ? PM_RANGER : PM_HUMAN;
171 mndx = mode ? PM_ROGUE : PM_HUMAN;
174 mndx = mode ? PM_SAMURAI : PM_HUMAN;
177 mndx = mode ? PM_TOURIST : PM_HUMAN;
180 mndx = mode ? PM_WIZARD : PM_HUMAN;
183 mndx = mode ? PM_VALKYRIE : PM_HUMAN;
186 if (mndx >= LOW_PM && mndx < NUMMONS) {
187 struct permonst *ptr = &mons[mndx];
191 else if (is_elf(ptr))
193 else if (is_dwarf(ptr))
195 else if (is_gnome(ptr))
197 else if (is_orc(ptr))
205 /* return monster index if chameleon, or NON_PM if not */
213 * As of 3.6.0 we just check M2_SHAPESHIFTER instead of having a
214 * big switch statement with hardcoded shapeshifter types here.
216 if (mndx >= LOW_PM && is_shapeshifter(&mons[mndx]))
221 /* for deciding whether corpse will carry along full monster data */
222 #define KEEPTRAITS(mon) \
223 ((mon)->isshk || (mon)->mtame || unique_corpstat((mon)->data) \
224 || is_reviver((mon)->data) \
225 /* normally quest leader will be unique, */ \
226 /* but he or she might have been polymorphed */ \
227 || (mon)->m_id == quest_status.leader_m_id \
228 /* special cancellation handling for these */ \
229 || (dmgtype((mon)->data, AD_SEDU) || dmgtype((mon)->data, AD_SSEX)))
231 /* Creates a monster corpse, a "special" corpse, or nothing if it doesn't
232 * leave corpses. Monsters which leave "special" corpses should have
233 * G_NOCORPSE set in order to prevent wishing for one, finding tins of one,
236 STATIC_OVL struct obj *
237 make_corpse(mtmp, corpseflags)
238 register struct monst *mtmp;
239 unsigned corpseflags;
241 register struct permonst *mdat = mtmp->data;
243 struct obj *obj = (struct obj *) 0;
244 struct obj *otmp = (struct obj *) 0;
245 int x = mtmp->mx, y = mtmp->my;
246 int mndx = monsndx(mdat);
247 unsigned corpstatflags = corpseflags;
248 boolean burythem = ((corpstatflags & CORPSTAT_BURIED) != 0);
252 case PM_SILVER_DRAGON:
254 case PM_SHIMMERING_DRAGON:
257 case PM_ORANGE_DRAGON:
258 case PM_WHITE_DRAGON:
259 case PM_BLACK_DRAGON:
261 case PM_GREEN_DRAGON:
262 case PM_YELLOW_DRAGON:
263 /* Make dragon scales. This assumes that the order of the
264 dragons is the same as the order of the scales. */
265 if (!rn2(mtmp->mrevived ? 20 : 3)) {
266 num = GRAY_DRAGON_SCALES + monsndx(mdat) - PM_GRAY_DRAGON;
267 obj = mksobj_at(num, x, y, FALSE, FALSE);
269 obj->cursed = obj->blessed = FALSE;
272 case PM_WHITE_UNICORN:
273 case PM_GRAY_UNICORN:
274 case PM_BLACK_UNICORN:
275 if (mtmp->mrevived && rn2(2)) {
278 pline("%s recently regrown horn crumbles to dust.",
280 pline("
\8dÅ
\8bß
\8dÄ
\90¶
\82µ
\82½%s
\82Ì
\8ap
\82Í
\95²
\81X
\82É
\82È
\82Á
\82½
\81D",
281 s_suffix(Monnam(mtmp)));
283 obj = mksobj_at(UNICORN_HORN, x, y, TRUE, FALSE);
284 if (obj && mtmp->mrevived)
285 obj->degraded_horn = 1;
289 (void) mksobj_at(WORM_TOOTH, x, y, TRUE, FALSE);
292 case PM_VAMPIRE_LORD:
293 /* include mtmp in the mkcorpstat() call */
294 num = undead_to_corpse(mndx);
295 corpstatflags |= CORPSTAT_INIT;
296 obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
297 obj->age -= 100; /* this is an *OLD* corpse */
299 case PM_KOBOLD_MUMMY:
307 case PM_KOBOLD_ZOMBIE:
308 case PM_DWARF_ZOMBIE:
309 case PM_GNOME_ZOMBIE:
312 case PM_HUMAN_ZOMBIE:
313 case PM_GIANT_ZOMBIE:
314 case PM_ETTIN_ZOMBIE:
315 num = undead_to_corpse(mndx);
316 corpstatflags |= CORPSTAT_INIT;
317 obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
318 obj->age -= 100; /* this is an *OLD* corpse */
323 obj = mksobj_at(IRON_CHAIN, x, y, TRUE, FALSE);
324 free_mname(mtmp); /* don't christen obj */
327 num = d(2, 4); /* very low chance of creating all glass gems */
329 obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE);
333 obj = mksobj_at(ROCK, x, y, FALSE, FALSE);
334 obj->quan = (long) (rn2(20) + 50);
335 obj->owt = weight(obj);
339 corpstatflags &= ~CORPSTAT_INIT;
341 mkcorpstat(STATUE, (struct monst *) 0, mdat, x, y, corpstatflags);
346 obj = mksobj_at(QUARTERSTAFF, x, y, TRUE, FALSE);
350 case PM_LEATHER_GOLEM:
353 obj = mksobj_at(LEATHER_ARMOR, x, y, TRUE, FALSE);
357 /* Good luck gives more coins */
358 obj = mkgold((long) (200 - rnl(101)), x, y);
364 obj = mksobj_at(SCR_BLANK_PAPER, x, y, TRUE, FALSE);
367 /* expired puddings will congeal into a large blob;
368 like dragons, relies on the order remaining consistent */
370 case PM_BROWN_PUDDING:
372 case PM_BLACK_PUDDING:
373 /* we have to do this here because most other places
374 expect there to be an object coming back; not this one */
375 obj = mksobj_at(GLOB_OF_BLACK_PUDDING - (PM_BLACK_PUDDING - mndx),
378 while (obj && (otmp = obj_nexto(obj)) != (struct obj *) 0) {
379 pudding_merge_message(obj, otmp);
380 obj = obj_meld(&obj, &otmp);
387 if (mvitals[mndx].mvflags & G_NOCORPSE) {
388 return (struct obj *) 0;
390 corpstatflags |= CORPSTAT_INIT;
391 /* preserve the unique traits of some creatures */
392 obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0,
393 mdat, x, y, corpstatflags);
397 (void) bury_an_obj(obj, &dealloc);
399 return dealloc ? (struct obj *) 0 : obj;
404 /* All special cases should precede the G_NOCORPSE check */
406 if (!obj) return NULL;
408 /* if polymorph or undead turning has killed this monster,
409 prevent the same attack beam from hitting its corpse */
410 if (context.bypasses)
414 obj = oname(obj, MNAME(mtmp));
416 /* Avoid "It was hidden under a green mold corpse!"
417 * during Blind combat. An unseen monster referred to as "it"
418 * could be killed and leave a corpse. If a hider then hid
419 * underneath it, you could be told the corpse type of a
420 * monster that you never knew was there without this.
421 * The code in hitmu() substitutes the word "something"
422 * if the corpses obj->dknown is 0.
424 if (Blind && !sensemon(mtmp))
432 /* check mtmp and water/lava for compatibility, 0 (survived), 1 (died) */
435 register struct monst *mtmp;
437 boolean inpool, inlava, infountain;
439 /* [what about ceiling clingers?] */
440 inpool = (is_pool(mtmp->mx, mtmp->my)
441 && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
442 inlava = (is_lava(mtmp->mx, mtmp->my)
443 && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
444 infountain = IS_FOUNTAIN(levl[mtmp->mx][mtmp->my].typ);
446 /* Flying and levitation keeps our steed out of the liquid */
447 /* (but not water-walking or swimming) */
448 if (mtmp == u.usteed && (Flying || Levitation))
451 /* Gremlin multiplying won't go on forever since the hit points
452 * keep going down, and when it gets to 1 hit point the clone
453 * function will fail.
455 if (mtmp->data == &mons[PM_GREMLIN] && (inpool || infountain) && rn2(3)) {
456 if (split_mon(mtmp, (struct monst *) 0))
457 dryup(mtmp->mx, mtmp->my, FALSE);
459 water_damage_chain(mtmp->minvent, FALSE);
461 } else if (mtmp->data == &mons[PM_IRON_GOLEM] && inpool && !rn2(5)) {
464 if (cansee(mtmp->mx, mtmp->my))
466 pline("%s rusts.", Monnam(mtmp));
468 pline("%s
\82Í
\8eK
\82Ñ
\82½
\81D", Monnam(mtmp));
470 if (mtmp->mhpmax > dam)
477 water_damage_chain(mtmp->minvent, FALSE);
483 * Lava effects much as water effects. Lava likers are able to
484 * protect their stuff. Fire resistant monsters can only protect
487 if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) {
488 if (!resists_fire(mtmp)) {
489 if (cansee(mtmp->mx, mtmp->my))
491 pline("%s %s.", Monnam(mtmp),
492 mtmp->data == &mons[PM_WATER_ELEMENTAL]
494 : "burns to a crisp");
496 pline("%s
\82Í%s
\82½
\81D", Monnam(mtmp),
497 mtmp->data == &mons[PM_WATER_ELEMENTAL]
499 : "
\94R
\82¦
\82Ä
\83p
\83\8a\83p
\83\8a\82É
\82È
\82Á");
503 if (--mtmp->mhp < 1) {
504 if (cansee(mtmp->mx, mtmp->my))
506 pline("%s surrenders to the fire.", Monnam(mtmp));
508 pline("%s
\82Í
\89\8a\82É
\93Û
\82Ü
\82ê
\82½
\81D", Monnam(mtmp));
510 } else if (cansee(mtmp->mx, mtmp->my))
512 pline("%s burns slightly.", Monnam(mtmp));
514 pline("%s
\82Í
\82¿
\82å
\82Á
\82Æ
\8fÅ
\82°
\82½
\81D", Monnam(mtmp));
517 (void) fire_damage_chain(mtmp->minvent, FALSE, FALSE,
519 (void) rloc(mtmp, FALSE);
525 /* Most monsters drown in pools. flooreffects() will take care of
526 * water damage to dead monsters' inventory, but survivors need to
527 * be handled here. Swimmers are able to protect their stuff...
529 if (!is_clinger(mtmp->data) && !is_swimmer(mtmp->data)
530 && !amphibious(mtmp->data)) {
531 if (cansee(mtmp->mx, mtmp->my)) {
533 pline("%s drowns.", Monnam(mtmp));
535 pline("%s
\82Í
\93M
\82ê
\82½
\81D", Monnam(mtmp));
537 if (u.ustuck && u.uswallow && u.ustuck == mtmp) {
538 /* This can happen after a purple worm plucks you off a
539 flying steed while you are over water. */
541 pline("%s sinks as water rushes in and flushes you out.",
543 pline("%s
\82Í
\90\85\97¬
\82É
\92¾
\82Ý
\81D
\82 \82È
\82½
\82ð
\93f
\82«
\8fo
\82µ
\82½
\81D",
548 water_damage_chain(mtmp->minvent, FALSE);
549 (void) rloc(mtmp, FALSE);
555 /* but eels have a difficult time outside */
556 if (mtmp->data->mlet == S_EEL && !Is_waterlevel(&u.uz)) {
557 /* as mhp gets lower, the rate of further loss slows down */
558 if (mtmp->mhp > 1 && rn2(mtmp->mhp) > rn2(8))
560 monflee(mtmp, 2, FALSE, FALSE);
570 int mmove = mon->data->mmove;
572 /* Note: MSLOW's `+ 1' prevents slowed speed 1 getting reduced to 0;
573 * MFAST's `+ 2' prevents hasted speed 1 from becoming a no-op;
574 * both adjustments have negligible effect on higher speeds.
576 if (mon->mspeed == MSLOW)
577 mmove = (2 * mmove + 1) / 3;
578 else if (mon->mspeed == MFAST)
579 mmove = (4 * mmove + 2) / 3;
581 if (mon == u.usteed) {
582 if (u.ugallop && context.mv) {
583 /* average movement is 1.50 times normal */
584 mmove = ((rn2(2) ? 4 : 5) * mmove) / 3;
587 /* vary movement points allocated to slightly reduce predictability;
588 random increment (avg +2) exceeds random decrement (avg +1) by
589 a small amount; normal speed monsters will occasionally get an
590 extra move and slow ones won't be quite as slow */
591 mmove += rn2(5) - rn2(3); /* + 0..4 - 0..2, average net +1 */
599 /* actions that happen once per ``turn'', regardless of each
600 individual monster's metabolism; some of these might need to
601 be reclassified to occur more in proportion with movement rate */
607 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
608 if (DEADMONSTER(mtmp))
611 /* must check non-moving monsters once/turn in case
612 * they managed to end up in liquid */
613 if (mtmp->data->mmove == 0) {
614 if (vision_full_recalc)
620 /* regenerate hit points */
621 mon_regen(mtmp, FALSE);
623 /* possibly polymorph shapechangers and lycanthropes */
624 if (mtmp->cham >= LOW_PM) {
625 if (is_vampshifter(mtmp) || mtmp->data->mlet == S_VAMPIRE)
626 decide_to_shapeshift(mtmp, 0);
628 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
632 /* gradually time out temporary problems */
633 if (mtmp->mblinded && !--mtmp->mblinded)
635 if (mtmp->mfrozen && !--mtmp->mfrozen)
637 if (mtmp->mfleetim && !--mtmp->mfleetim)
640 /* FIXME: mtmp->mlstmv ought to be updated here */
647 register struct monst *mtmp, *nmtmp;
648 register boolean somebody_can_move = FALSE;
651 * Some of you may remember the former assertion here that
652 * because of deaths and other actions, a simple one-pass
653 * algorithm wasn't possible for movemon. Deaths are no longer
654 * removed to the separate list fdmon; they are simply left in
655 * the chain with hit points <= 0, to be cleaned up at the end
658 * The only other actions which cause monsters to be removed from
659 * the chain are level migrations and losedogs(). I believe losedogs()
660 * is a cleanup routine not associated with monster movements, and
661 * monsters can only affect level migrations on themselves, not others
662 * (hence the fetching of nmon before moving the monster). Currently,
663 * monsters can jump into traps, read cursed scrolls of teleportation,
664 * and drink cursed potions of raise level to change levels. These are
665 * all reflexive at this point. Should one monster be able to level
666 * teleport another, this scheme would have problems.
669 for (mtmp = fmon; mtmp; mtmp = nmtmp) {
670 /* end monster movement early if hero is flagged to leave the level */
673 /* or if the program has lost contact with the user */
674 || program_state.done_hup
677 somebody_can_move = FALSE;
681 /* one dead monster needs to perform a move after death:
682 vault guard whose temporary corridor is still on the map */
683 if (mtmp->isgd && !mtmp->mx && mtmp->mhp <= 0)
684 (void) gd_move(mtmp);
685 if (DEADMONSTER(mtmp))
688 /* Find a monster that we have not treated yet. */
689 if (mtmp->movement < NORMAL_SPEED)
692 mtmp->movement -= NORMAL_SPEED;
693 if (mtmp->movement >= NORMAL_SPEED)
694 somebody_can_move = TRUE;
696 if (vision_full_recalc)
697 vision_recalc(0); /* vision! */
699 /* reset obj bypasses before next monster moves */
700 if (context.bypasses)
706 if (is_hider(mtmp->data)) {
707 /* unwatched mimics and piercers may hide again [MRS] */
710 if (mtmp->m_ap_type == M_AP_FURNITURE
711 || mtmp->m_ap_type == M_AP_OBJECT)
713 if (mtmp->mundetected)
715 } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected
716 && (mtmp->mflee || distu(mtmp->mx, mtmp->my) > 2)
717 && !canseemon(mtmp) && !rn2(4)) {
718 /* some eels end up stuck in isolated pools, where they
719 can't--or at least won't--move, so they never reach
720 their post-move chance to re-hide */
725 /* continue if the monster died fighting */
726 if (Conflict && !mtmp->iswiz && mtmp->mcansee) {
728 * Conflict does not take effect in the first round.
729 * Therefore, A monster when stepping into the area will
730 * get to swing at you.
732 * The call to fightm() must be _last_. The monster might
733 * have died if it returns 1.
735 if (couldsee(mtmp->mx, mtmp->my)
736 && (distu(mtmp->mx, mtmp->my) <= BOLT_LIM * BOLT_LIM)
738 continue; /* mon might have died */
740 if (dochugw(mtmp)) /* otherwise just move the monster */
744 if (any_light_source())
745 vision_full_recalc = 1; /* in case a mon moved with a light source */
746 /* reset obj bypasses after last monster has moved */
747 if (context.bypasses)
750 /* remove dead monsters; dead vault guard will be left at <0,0>
751 if temporary corridor out of vault hasn't been removed yet */
754 /* a monster may have levteleported player -dlc */
757 /* changed levels, so these monsters are dormant */
758 somebody_can_move = FALSE;
761 return somebody_can_move;
764 #define mstoning(obj) \
765 (ofood(obj) && (touch_petrifies(&mons[(obj)->corpsenm]) \
766 || (obj)->corpsenm == PM_MEDUSA))
769 * Maybe eat a metallic object (not just gold).
770 * Return value: 0 => nothing happened, 1 => monster ate something,
771 * 2 => monster died (it must have grown into a genocided form, but
772 * that can't happen at present because nothing which eats objects
773 * has young and old forms).
777 register struct monst *mtmp;
779 register struct obj *otmp;
780 struct permonst *ptr;
781 int poly, grow, heal, mstone;
783 /* If a pet, eating is handled separately, in dog.c */
787 /* Eats topmost metal object if it is there */
788 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp;
789 otmp = otmp->nexthere) {
790 /* Don't eat indigestible/choking/inappropriate objects */
791 if ((mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp))
792 || (otmp->otyp == AMULET_OF_STRANGULATION)
793 || (otmp->otyp == RIN_SLOW_DIGESTION))
795 if (is_metallic(otmp) && !obj_resists(otmp, 5, 95)
796 && touch_artifact(otmp, mtmp)) {
797 if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) {
798 if (canseemon(mtmp) && flags.verbose) {
800 pline("%s eats %s!", Monnam(mtmp),
801 distant_name(otmp, doname));
803 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
804 distant_name(otmp,doname));
807 /* The object's rustproofing is gone now */
808 otmp->oerodeproof = 0;
810 if (canseemon(mtmp) && flags.verbose) {
812 pline("%s spits %s out in disgust!", Monnam(mtmp),
813 distant_name(otmp, doname));
815 pline("%s
\82Í%s
\82ð
\83y
\83b
\82Æ
\93f
\82«
\8fo
\82µ
\82½
\81I", Monnam(mtmp),
816 distant_name(otmp,doname));
820 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
822 pline("%s eats %s!", Monnam(mtmp),
823 distant_name(otmp, doname));
825 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
826 distant_name(otmp,doname));
828 else if (flags.verbose)
830 You_hear("a crunching sound.");
832 You_hear("
\83o
\83\8a\83o
\83\8a\82Æ
\90H
\82×
\82é
\89¹
\82ð
\95·
\82¢
\82½
\81D");
833 mtmp->meating = otmp->owt / 2 + 1;
834 /* Heal up to the object's weight in hp */
835 if (mtmp->mhp < mtmp->mhpmax) {
836 mtmp->mhp += objects[otmp->otyp].oc_weight;
837 if (mtmp->mhp > mtmp->mhpmax)
838 mtmp->mhp = mtmp->mhpmax;
843 } else if (otmp == uchain) {
844 unpunish(); /* frees uchain */
846 poly = polyfodder(otmp);
847 grow = mlevelgain(otmp);
848 heal = mhealup(otmp);
849 mstone = mstoning(otmp);
853 if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
856 ptr = grow_up(mtmp, (struct monst *) 0);
858 if (poly_when_stoned(ptr)) {
861 } else if (!resists_ston(mtmp)) {
864 pline("%s turns to stone!", Monnam(mtmp));
866 pline("%s
\82Í
\90Î
\82É
\82È
\82Á
\82½
\81I", Monnam(mtmp));
868 ptr = (struct permonst *) 0;
871 mtmp->mhp = mtmp->mhpmax;
874 return 2; /* it died */
876 /* Left behind a pile? */
878 (void) mksobj_at(ROCK, mtmp->mx, mtmp->my, TRUE, FALSE);
879 newsym(mtmp->mx, mtmp->my);
887 /* monster eats a pile of objects */
889 meatobj(mtmp) /* for gelatinous cubes */
892 register struct obj *otmp, *otmp2;
893 struct permonst *ptr, *original_ptr = mtmp->data;
894 int poly, grow, heal, count = 0, ecount = 0;
898 /* If a pet, eating is handled separately, in dog.c */
902 /* eat organic objects, including cloth and wood, if present;
903 engulf others, except huge rocks and metal attached to player
904 [despite comment at top, doesn't assume that eater is a g.cube] */
905 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
906 otmp2 = otmp->nexthere;
908 /* touch sensitive items */
909 if (otmp->otyp == CORPSE && is_rider(&mons[otmp->corpsenm])) {
910 /* Rider corpse isn't just inedible; can't engulf it either */
911 (void) revive_corpse(otmp);
913 /* untouchable (or inaccessible) items */
914 } else if ((otmp->otyp == CORPSE
915 && touch_petrifies(&mons[otmp->corpsenm])
916 && !resists_ston(mtmp))
917 /* don't engulf boulders and statues or ball&chain */
918 || otmp->oclass == ROCK_CLASS
919 || otmp == uball || otmp == uchain) {
920 /* do nothing--neither eaten nor engulfed */
923 /* inedible items -- engulf these */
924 } else if (!is_organic(otmp) || obj_resists(otmp, 5, 95)
925 || !touch_artifact(otmp, mtmp)
926 /* redundant due to non-organic composition but
927 included for emphasis */
928 || (otmp->otyp == AMULET_OF_STRANGULATION
929 || otmp->otyp == RIN_SLOW_DIGESTION)
930 /* cockatrice corpses handled above; this
931 touch_petrifies() check catches eggs */
932 || ((otmp->otyp == CORPSE || otmp->otyp == EGG)
933 && ((touch_petrifies(&mons[otmp->corpsenm])
934 && !resists_ston(mtmp))
935 || (otmp->corpsenm == PM_GREEN_SLIME
936 && !slimeproof(mtmp->data))))) {
941 Sprintf(buf, "%s engulfs %s.", Monnam(mtmp),
942 distant_name(otmp, doname));
944 Sprintf(buf, "%s
\82Í%s
\82ð
\88ù
\82Ý
\8d\9e\82ñ
\82¾
\81D", Monnam(mtmp),
945 distant_name(otmp,doname));
947 else if (ecount == 2)
949 Sprintf(buf, "%s engulfs several objects.", Monnam(mtmp));
951 Sprintf(buf, "%s
\82Í
\82¢
\82
\82Â
\82©
\82Ì
\95¨
\82ð
\88ù
\82Ý
\8d\9e\82ñ
\82¾
\81D", Monnam(mtmp));
952 obj_extract_self(otmp);
953 (void) mpickobj(mtmp, otmp); /* slurp */
955 /* lastly, edible items; yum! */
959 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
961 pline("%s eats %s!", Monnam(mtmp),
962 distant_name(otmp, doname));
964 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
965 distant_name(otmp, doname));
967 else if (flags.verbose)
969 You_hear("a slurping sound.");
971 You_hear("
\82²
\82
\82ñ
\82Æ
\88ù
\82Ý
\8d\9e\82Þ
\89¹
\82ð
\95·
\82¢
\82½
\81D");
972 /* Heal up to the object's weight in hp */
973 if (mtmp->mhp < mtmp->mhpmax) {
974 mtmp->mhp += objects[otmp->otyp].oc_weight;
975 if (mtmp->mhp > mtmp->mhpmax)
976 mtmp->mhp = mtmp->mhpmax;
978 if (Has_contents(otmp)) {
979 register struct obj *otmp3;
981 /* contents of eaten containers become engulfed; this
982 is arbitrary, but otherwise g.cubes are too powerful */
983 while ((otmp3 = otmp->cobj) != 0) {
984 obj_extract_self(otmp3);
985 if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) {
986 otmp3->age = monstermoves - otmp3->age;
987 start_corpse_timeout(otmp3);
989 (void) mpickobj(mtmp, otmp3);
992 poly = polyfodder(otmp);
993 grow = mlevelgain(otmp);
994 heal = mhealup(otmp);
995 delobj(otmp); /* munch */
998 if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
1001 ptr = grow_up(mtmp, (struct monst *) 0);
1003 mtmp->mhp = mtmp->mhpmax;
1005 /* in case it polymorphed or died */
1006 if (ptr != original_ptr)
1007 return !ptr ? 2 : 1;
1010 /* Engulf & devour is instant, so don't set meating */
1012 newsym(mtmp->mx, mtmp->my);
1016 if (cansee(mtmp->mx, mtmp->my) && flags.verbose && buf[0])
1018 else if (flags.verbose)
1020 You_hear("%s slurping sound%s.",
1021 (ecount == 1) ? "a" : "several", plur(ecount));
1023 You_hear("
\83Y
\83\8b\83Y
\83\8b\82Æ
\82¢
\82¤
\89¹
\82ð
\95·
\82¢
\82½
\81D");
1026 return (count > 0 || ecount > 0) ? 1 : 0;
1031 register struct monst *mtmp;
1033 register struct obj *gold;
1036 if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) {
1037 mat_idx = objects[gold->otyp].oc_material;
1038 obj_extract_self(gold);
1039 add_to_minv(mtmp, gold);
1040 if (cansee(mtmp->mx, mtmp->my)) {
1041 if (flags.verbose && !mtmp->isgd)
1043 pline("%s picks up some %s.", Monnam(mtmp),
1044 mat_idx == GOLD ? "gold" : "money");
1046 pline("%s
\82Í
\82¨
\8bà
\82ð
\8fE
\82Á
\82½
\81D", Monnam(mtmp));
1048 newsym(mtmp->mx, mtmp->my);
1054 mpickstuff(mtmp, str)
1055 register struct monst *mtmp;
1056 register const char *str;
1058 register struct obj *otmp, *otmp2, *otmp3;
1061 /* prevent shopkeepers from leaving the door of their shop */
1062 if (mtmp->isshk && inhishop(mtmp))
1065 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
1066 otmp2 = otmp->nexthere;
1067 /* Nymphs take everything. Most monsters don't pick up corpses. */
1068 if (!str ? searches_for_item(mtmp, otmp)
1069 : !!(index(str, otmp->oclass))) {
1070 if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
1071 /* let a handful of corpse types thru to can_carry() */
1072 && !touch_petrifies(&mons[otmp->corpsenm])
1073 && otmp->corpsenm != PM_LIZARD
1074 && !acidic(&mons[otmp->corpsenm]))
1076 if (!touch_artifact(otmp, mtmp))
1078 carryamt = can_carry(mtmp, otmp);
1081 if (is_pool(mtmp->mx, mtmp->my))
1083 /* handle cases where the critter can only get some */
1085 if (carryamt != otmp->quan) {
1086 otmp3 = splitobj(otmp, carryamt);
1088 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
1090 pline("%s picks up %s.", Monnam(mtmp),
1091 (distu(mtmp->mx, mtmp->my) <= 5)
1093 : distant_name(otmp3, doname));
1095 pline("%s
\82Í%s
\82ð
\8fE
\82Á
\82½
\81D", Monnam(mtmp),
1096 (distu(mtmp->mx, mtmp->my) <= 5)
1098 : distant_name(otmp3, doname));
1100 obj_extract_self(otmp3); /* remove from floor */
1101 (void) mpickobj(mtmp, otmp3); /* may merge and free otmp3 */
1102 m_dowear(mtmp, FALSE);
1103 newsym(mtmp->mx, mtmp->my);
1104 return TRUE; /* pick only one object */
1117 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1118 if (obj->otyp != BOULDER || !throws_rocks(mtmp->data))
1119 curload += obj->owt;
1131 /* Base monster carrying capacity is equal to human maximum
1132 * carrying capacity, or half human maximum if not strong.
1133 * (for a polymorphed player, the value used would be the
1134 * non-polymorphed carrying capacity instead of max/half max).
1135 * This is then modified by the ratio between the monster weights
1136 * and human weights. Corpseless monsters are given a capacity
1137 * proportional to their size instead of weight.
1139 if (!mtmp->data->cwt)
1140 maxload = (MAX_CARR_CAP * (long) mtmp->data->msize) / MZ_HUMAN;
1141 else if (!strongmonst(mtmp->data)
1142 || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN)))
1143 maxload = (MAX_CARR_CAP * (long) mtmp->data->cwt) / WT_HUMAN;
1145 maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/
1147 if (!strongmonst(mtmp->data))
1153 return (int) maxload;
1156 /* for restricting monsters' object-pickup.
1158 * to support the new pet behavior, this now returns the max # of objects
1159 * that a given monster could pick up from a pile. frequently this will be
1160 * otmp->quan, but special cases for 'only one' now exist so.
1162 * this will probably cause very amusing behavior with pets and gold coins.
1164 * TODO: allow picking up 2-N objects from a pile of N based on weight.
1165 * Change from 'int' to 'long' to accomate big stacks of gold.
1166 * Right now we fake it by reporting a partial quantity, but the
1167 * likesgold handling m_move results in picking up the whole stack.
1170 can_carry(mtmp, otmp)
1174 int iquan, otyp = otmp->otyp, newload = otmp->owt;
1175 struct permonst *mdat = mtmp->data;
1179 return 0; /* can't carry anything */
1181 if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])
1182 && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp))
1184 if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm]))
1186 if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp)
1187 && (otyp != BELL_OF_OPENING || !is_covetous(mdat)))
1190 /* hostile monsters who like gold will pick up the whole stack;
1191 tame mosnters with hands will pick up the partial stack */
1192 iquan = (otmp->quan > (long) LARGEST_INT)
1193 ? 20000 + rn2(LARGEST_INT - 20000 + 1)
1196 /* monsters without hands can't pick up multiple objects at once
1197 * unless they have an engulfing attack
1199 * ...dragons, of course, can always carry gold pieces and gems somehow
1202 boolean glomper = FALSE;
1204 if (mtmp->data->mlet == S_DRAGON
1205 && (otmp->oclass == COIN_CLASS
1206 || otmp->oclass == GEM_CLASS))
1209 for (nattk = 0; nattk < NATTK; nattk++)
1210 if (mtmp->data->mattk[nattk].aatyp == AT_ENGL) {
1214 if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper)
1218 /* steeds don't pick up stuff (to avoid shop abuse) */
1219 if (mtmp == u.usteed)
1222 return iquan; /* no limit */
1223 if (mtmp->mpeaceful && !mtmp->mtame)
1225 /* otherwise players might find themselves obligated to violate
1226 * their alignment if the monster takes something they need
1229 /* special--boulder throwers carry unlimited amounts of boulders */
1230 if (throws_rocks(mdat) && otyp == BOULDER)
1233 /* nymphs deal in stolen merchandise, but not boulders or statues */
1234 if (mdat->mlet == S_NYMPH)
1235 return (otmp->oclass == ROCK_CLASS) ? 0 : iquan;
1237 if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp))
1243 /* return number of acceptable neighbour positions */
1245 mfndpos(mon, poss, info, flag)
1247 coord *poss; /* coord poss[9] */
1248 long *info; /* long info[9] */
1251 struct permonst *mdat = mon->data;
1252 register struct trap *ttmp;
1257 boolean wantpool, poolok, lavaok, nodiag;
1258 boolean rockok = FALSE, treeok = FALSE, thrudoor;
1263 nowtyp = levl[x][y].typ;
1265 nodiag = NODIAG(mdat - mons);
1266 wantpool = mdat->mlet == S_EEL;
1267 poolok = (is_flyer(mdat) || is_clinger(mdat)
1268 || (is_swimmer(mdat) && !wantpool));
1269 lavaok = (is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat));
1270 thrudoor = ((flag & (ALLOW_WALL | BUSTDOOR)) != 0L);
1271 if (flag & ALLOW_DIG) {
1274 /* need to be specific about what can currently be dug */
1275 if (!needspick(mdat)) {
1276 rockok = treeok = TRUE;
1277 } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed
1278 && mon->weapon_check == NO_WEAPON_WANTED) {
1279 rockok = is_pick(mw_tmp);
1280 treeok = is_axe(mw_tmp);
1282 rockok = (m_carrying(mon, PICK_AXE)
1283 || (m_carrying(mon, DWARVISH_MATTOCK)
1284 && !which_armor(mon, W_ARMS)));
1285 treeok = (m_carrying(mon, AXE) || (m_carrying(mon, BATTLE_AXE)
1286 && !which_armor(mon, W_ARMS)));
1288 if (rockok || treeok)
1292 nexttry: /* eels prefer the water, but if there is no water nearby,
1293 they will crawl over land */
1300 maxx = min(x + 1, COLNO - 1);
1301 maxy = min(y + 1, ROWNO - 1);
1302 for (nx = max(1, x - 1); nx <= maxx; nx++)
1303 for (ny = max(0, y - 1); ny <= maxy; ny++) {
1304 if (nx == x && ny == y)
1306 ntyp = levl[nx][ny].typ;
1308 && !((flag & ALLOW_WALL) && may_passwall(nx, ny))
1309 && !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx, ny)))
1311 /* KMH -- Added iron bars */
1312 if (ntyp == IRONBARS && !(flag & ALLOW_BARS))
1314 if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon))
1315 && (((levl[nx][ny].doormask & D_CLOSED) && !(flag & OPENDOOR))
1316 || ((levl[nx][ny].doormask & D_LOCKED)
1317 && !(flag & UNLOCKDOOR))) && !thrudoor)
1319 /* first diagonal checks (tight squeezes handled below) */
1320 if (nx != x && ny != y
1322 || (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN))
1323 || (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN))
1324 || ((IS_DOOR(nowtyp) || IS_DOOR(ntyp))
1325 && Is_rogue_level(&u.uz))
1326 /* mustn't pass between adjacent long worm segments,
1327 but can attack that way */
1328 || (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny)
1329 && !m_at(nx, ny) && (nx != u.ux || ny != u.uy))))
1331 if ((is_pool(nx, ny) == wantpool || poolok)
1332 && (lavaok || !is_lava(nx, ny))) {
1334 boolean monseeu = (mon->mcansee
1335 && (!Invis || perceives(mdat)));
1336 boolean checkobj = OBJ_AT(nx, ny);
1338 /* Displacement also displaces the Elbereth/scare monster,
1339 * as long as you are visible.
1341 if (Displaced && monseeu && mon->mux == nx && mon->muy == ny) {
1350 if (onscary(dispx, dispy, mon)) {
1351 if (!(flag & ALLOW_SSM))
1353 info[cnt] |= ALLOW_SSM;
1355 if ((nx == u.ux && ny == u.uy)
1356 || (nx == mon->mux && ny == mon->muy)) {
1357 if (nx == u.ux && ny == u.uy) {
1358 /* If it's right next to you, it found you,
1359 * displaced or no. We must set mux and muy
1360 * right now, so when we return we can tell
1361 * that the ALLOW_U means to attack _you_ and
1367 if (!(flag & ALLOW_U))
1369 info[cnt] |= ALLOW_U;
1371 if (MON_AT(nx, ny)) {
1372 struct monst *mtmp2 = m_at(nx, ny);
1373 long mmflag = flag | mm_aggression(mon, mtmp2);
1375 if (mmflag & ALLOW_M) {
1376 info[cnt] |= ALLOW_M;
1378 if (!(mmflag & ALLOW_TM))
1380 info[cnt] |= ALLOW_TM;
1383 mmflag = flag | mm_displacement(mon, mtmp2);
1384 if (!(mmflag & ALLOW_MDISP))
1386 info[cnt] |= ALLOW_MDISP;
1389 /* Note: ALLOW_SANCT only prevents movement, not
1390 attack, into a temple. */
1391 if (level.flags.has_temple && *in_rooms(nx, ny, TEMPLE)
1392 && !*in_rooms(x, y, TEMPLE)
1393 && in_your_sanctuary((struct monst *) 0, nx, ny)) {
1394 if (!(flag & ALLOW_SANCT))
1396 info[cnt] |= ALLOW_SANCT;
1399 if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
1400 if (flag & NOGARLIC)
1402 info[cnt] |= NOGARLIC;
1404 if (checkobj && sobj_at(BOULDER, nx, ny)) {
1405 if (!(flag & ALLOW_ROCK))
1407 info[cnt] |= ALLOW_ROCK;
1409 if (monseeu && onlineu(nx, ny)) {
1412 info[cnt] |= NOTONL;
1414 /* check for diagonal tight squeeze */
1415 if (nx != x && ny != y && bad_rock(mdat, x, ny)
1416 && bad_rock(mdat, nx, y) && cant_squeeze_thru(mon))
1418 /* The monster avoids a particular type of trap if it's
1419 * familiar with the trap type. Pets get ALLOW_TRAPS
1420 * and checking is done in dogmove.c. In either case,
1421 * "harmless" traps are neither avoided nor marked in info[].
1423 if ((ttmp = t_at(nx, ny)) != 0) {
1424 if (ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) {
1426 "A monster looked at a very strange trap of type %d.",
1430 if ((ttmp->ttyp != RUST_TRAP
1431 || mdat == &mons[PM_IRON_GOLEM])
1432 && ttmp->ttyp != STATUE_TRAP
1433 && ((ttmp->ttyp != PIT && ttmp->ttyp != SPIKED_PIT
1434 && ttmp->ttyp != TRAPDOOR && ttmp->ttyp != HOLE)
1435 || (!is_flyer(mdat) && !is_floater(mdat)
1436 && !is_clinger(mdat)) || Sokoban)
1437 && (ttmp->ttyp != SLP_GAS_TRAP || !resists_sleep(mon))
1438 && (ttmp->ttyp != BEAR_TRAP
1439 || (mdat->msize > MZ_SMALL && !amorphous(mdat)
1440 && !is_flyer(mdat) && !is_floater(mdat)
1441 && !is_whirly(mdat) && !unsolid(mdat)))
1442 && (ttmp->ttyp != FIRE_TRAP || !resists_fire(mon))
1443 && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat))
1444 && (ttmp->ttyp != WEB
1445 || (!amorphous(mdat) && !webmaker(mdat)))
1446 && (ttmp->ttyp != ANTI_MAGIC || !resists_magm(mon))) {
1447 if (!(flag & ALLOW_TRAPS)) {
1448 if (mon->mtrapseen & (1L << (ttmp->ttyp - 1)))
1451 info[cnt] |= ALLOW_TRAPS;
1459 if (!cnt && wantpool && !is_pool(x, y)) {
1466 /* Monster against monster special attacks; for the specified monster
1467 combinations, this allows one monster to attack another adjacent one
1468 in the absence of Conflict. There is no provision for targetting
1469 other monsters; just hand to hand fighting when they happen to be
1470 next to each other. */
1472 mm_aggression(magr, mdef)
1473 struct monst *magr, /* monster that is currently deciding where to move */
1474 *mdef; /* another monster which is next to it */
1476 /* supposedly purple worms are attracted to shrieking because they
1477 like to eat shriekers, so attack the latter when feasible */
1478 if (magr->data == &mons[PM_PURPLE_WORM]
1479 && mdef->data == &mons[PM_SHRIEKER])
1480 return ALLOW_M | ALLOW_TM;
1481 /* Various other combinations such as dog vs cat, cat vs rat, and
1482 elf vs orc have been suggested. For the time being we don't
1487 /* Monster displacing another monster out of the way */
1489 mm_displacement(magr, mdef)
1490 struct monst *magr, /* monster that is currently deciding where to move */
1491 *mdef; /* another monster which is next to it */
1493 struct permonst *pa = magr->data, *pd = mdef->data;
1495 /* if attacker can't barge through, there's nothing to do;
1496 or if defender can barge through too, don't let attacker
1497 do so, otherwise they might just end up swapping places
1498 again when defender gets its chance to move */
1499 if ((pa->mflags3 & M3_DISPLACES) != 0 && (pd->mflags3 & M3_DISPLACES) == 0
1500 /* no displacing grid bugs diagonally */
1501 && !(magr->mx != mdef->mx && magr->my != mdef->my
1502 && NODIAG(monsndx(pd)))
1503 /* no displacing trapped monsters or multi-location longworms */
1504 && !mdef->mtrapped && (!mdef->wormno || !count_wsegs(mdef))
1505 /* riders can move anything; others, same size or smaller only */
1506 && (is_rider(pa) || pa->msize >= pd->msize))
1511 /* Is the square close enough for the monster to move or attack into? */
1517 int distance = dist2(mon->mx, mon->my, x, y);
1519 if (distance == 2 && NODIAG(mon->data - mons))
1521 return (boolean) (distance < 3);
1524 /* really free dead monsters */
1528 struct monst **mtmp, *freetmp;
1531 for (mtmp = &fmon; *mtmp;) {
1533 if (freetmp->mhp <= 0 && !freetmp->isgd) {
1534 *mtmp = freetmp->nmon;
1535 freetmp->nmon = NULL;
1536 dealloc_monst(freetmp);
1539 mtmp = &(freetmp->nmon);
1542 if (count != iflags.purge_monsters)
1543 impossible("dmonsfree: %d removed doesn't match %d pending",
1544 count, iflags.purge_monsters);
1545 iflags.purge_monsters = 0;
1548 /* called when monster is moved to larger structure */
1550 replmon(mtmp, mtmp2)
1551 struct monst *mtmp, *mtmp2;
1555 /* transfer the monster's inventory */
1556 for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
1557 if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
1558 impossible("replmon: minvent inconsistency");
1559 otmp->ocarry = mtmp2;
1563 /* remove the old monster from the map and from `fmon' list */
1564 relmon(mtmp, (struct monst **) 0);
1566 /* finish adding its replacement */
1567 if (mtmp != u.usteed) /* don't place steed onto the map */
1568 place_monster(mtmp2, mtmp2->mx, mtmp2->my);
1569 if (mtmp2->wormno) /* update level.monsters[wseg->wx][wseg->wy] */
1570 place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */
1571 if (emits_light(mtmp2->data)) {
1572 /* since this is so rare, we don't have any `mon_move_light_source' */
1573 new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
1574 LS_MONSTER, monst_to_any(mtmp2));
1575 /* here we rely on fact that `mtmp' hasn't actually been deleted */
1576 del_light_source(LS_MONSTER, monst_to_any(mtmp));
1580 if (u.ustuck == mtmp)
1582 if (u.usteed == mtmp)
1585 replshk(mtmp, mtmp2);
1587 /* discard the old monster */
1588 dealloc_monst(mtmp);
1591 /* release mon from the display and the map's monster list,
1592 maybe transfer it to one of the other monster lists */
1594 relmon(mon, monst_list)
1596 struct monst **monst_list; /* &migrating_mons or &mydogs or null */
1599 boolean unhide = (monst_list != 0);
1600 int mx = mon->mx, my = mon->my;
1603 panic("relmon: no fmon available.");
1606 /* can't remain hidden across level changes (exception: wizard
1607 clone can continue imitating some other monster form); also,
1608 might be imitating a boulder so need line-of-sight unblocking */
1609 mon->mundetected = 0;
1610 if (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)
1614 remove_monster(mx, my);
1619 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1620 if (mtmp->nmon == mon)
1624 mtmp->nmon = mon->nmon;
1626 panic("relmon: mon not in list.");
1631 /* insert into mydogs or migrating_mons */
1632 mon->nmon = *monst_list;
1635 /* orphan has no next monster */
1641 copy_mextra(mtmp2, mtmp1)
1642 struct monst *mtmp2, *mtmp1;
1644 if (!mtmp2 || !mtmp1 || !mtmp1->mextra)
1648 mtmp2->mextra = newmextra();
1650 new_mname(mtmp2, (int) strlen(MNAME(mtmp1)) + 1);
1651 Strcpy(MNAME(mtmp2), MNAME(mtmp1));
1656 (void) memcpy((genericptr_t) EGD(mtmp2), (genericptr_t) EGD(mtmp1),
1657 sizeof (struct egd));
1662 (void) memcpy((genericptr_t) EPRI(mtmp2), (genericptr_t) EPRI(mtmp1),
1663 sizeof (struct epri));
1668 (void) memcpy((genericptr_t) ESHK(mtmp2), (genericptr_t) ESHK(mtmp1),
1669 sizeof (struct eshk));
1674 (void) memcpy((genericptr_t) EMIN(mtmp2), (genericptr_t) EMIN(mtmp1),
1675 sizeof (struct emin));
1680 (void) memcpy((genericptr_t) EDOG(mtmp2), (genericptr_t) EDOG(mtmp1),
1681 sizeof (struct edog));
1683 if (has_mcorpsenm(mtmp1))
1684 MCORPSENM(mtmp2) = MCORPSENM(mtmp1);
1691 struct mextra *x = m->mextra;
1695 free((genericptr_t) x->mname);
1697 free((genericptr_t) x->egd);
1699 free((genericptr_t) x->epri);
1701 free((genericptr_t) x->eshk);
1703 free((genericptr_t) x->emin);
1705 free((genericptr_t) x->edog);
1706 /* [no action needed for x->mcorpsenm] */
1708 free((genericptr_t) x);
1709 m->mextra = (struct mextra *) 0;
1718 panic("dealloc_monst with nmon");
1720 dealloc_mextra(mon);
1721 free((genericptr_t) mon);
1724 /* remove effects of mtmp from other data structures */
1726 m_detach(mtmp, mptr)
1728 struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
1730 if (mtmp == context.polearm.hitmon)
1731 context.polearm.hitmon = 0;
1733 m_unleash(mtmp, FALSE);
1734 /* to prevent an infinite relobj-flooreffects-hmon-killed loop */
1736 mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
1737 relobj(mtmp, 0, FALSE);
1738 remove_monster(mtmp->mx, mtmp->my);
1739 if (emits_light(mptr))
1740 del_light_source(LS_MONSTER, monst_to_any(mtmp));
1741 newsym(mtmp->mx, mtmp->my);
1743 fill_pit(mtmp->mx, mtmp->my);
1749 iflags.purge_monsters++;
1752 /* find the worn amulet of life saving which will save a monster */
1757 if (!nonliving(mon->data) || is_vampshifter(mon)) {
1758 struct obj *otmp = which_armor(mon, W_AMUL);
1760 if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING)
1763 return (struct obj *) 0;
1767 lifesaved_monster(mtmp)
1771 struct obj *lifesave = mlifesaver(mtmp);
1774 /* not canseemon; amulets are on the head, so you don't want
1775 * to show this for a long worm with only a tail visible.
1776 * Nor do you check invisibility, because glowing and
1777 * disintegrating amulets are always visible. */
1778 if (cansee(mtmp->mx, mtmp->my)) {
1780 pline("But wait...");
1782 pline("
\82µ
\82©
\82µ
\81D
\81D
\81D");
1784 pline("%s medallion begins to glow!", s_suffix(Monnam(mtmp)));
1786 pline("%s
\82Ì
\83\81\83_
\83\8a\83I
\83\93\82ª
\8bP
\82«
\82Í
\82¶
\82ß
\82½
\81I", Monnam(mtmp));
1787 makeknown(AMULET_OF_LIFE_SAVING);
1788 /* amulet is visible, but monster might not be */
1789 if (canseemon(mtmp)) {
1790 if (attacktype(mtmp->data, AT_EXPL)
1791 || attacktype(mtmp->data, AT_BOOM))
1793 pline("%s reconstitutes!", Monnam(mtmp));
1795 pline("%s
\82Í
\8dÄ
\8d\
\90¬
\82³
\82ê
\82½
\81I", Monnam(mtmp));
1798 pline("%s looks much better!", Monnam(mtmp));
1800 pline("%s
\82Í
\82·
\82Á
\82©
\82è
\89ñ
\95\9c\82µ
\82½
\82æ
\82¤
\82¾
\81I", Monnam(mtmp));
1803 pline_The("medallion crumbles to dust!");
1805 pline_The("
\83\81\83_
\83\8a\83I
\83\93\82Í
\82±
\82È
\82²
\82È
\82É
\82
\82¾
\82¯
\82Ä
\82µ
\82Ü
\82Á
\82½
\81I");
1807 m_useup(mtmp, lifesave);
1809 surviver = !(mvitals[monsndx(mtmp->data)].mvflags & G_GENOD);
1812 if (mtmp->mtame && !mtmp->isminion) {
1813 wary_dog(mtmp, !surviver);
1815 if (mtmp->mhpmax <= 0)
1817 mtmp->mhp = mtmp->mhpmax;
1821 /* genocided monster can't be life-saved */
1822 if (cansee(mtmp->mx, mtmp->my))
1824 pline("Unfortunately, %s is still genocided...", mon_nam(mtmp));
1826 pline("
\8ec
\94O
\82È
\82ª
\82ç%s
\82Í
\8bs
\8eE
\82³
\82ê
\82Ä
\82¢
\82é
\81D
\81D
\81D", mon_nam(mtmp));
1833 register struct monst *mtmp;
1835 struct permonst *mptr;
1838 lifesaved_monster(mtmp);
1842 if (is_vampshifter(mtmp)) {
1843 int mndx = mtmp->cham;
1844 int x = mtmp->mx, y = mtmp->my;
1846 /* this only happens if shapeshifted */
1847 if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)) {
1849 boolean in_door = (amorphous(mtmp->data)
1850 && closed_door(mtmp->mx, mtmp->my)),
1851 /* alternate message phrasing for some monster types */
1852 spec_mon = (nonliving(mtmp->data)
1853 || noncorporeal(mtmp->data)
1854 || amorphous(mtmp->data));
1856 /* construct a format string before transformation */
1857 Sprintf(buf, "The %s%s suddenly %s and rises as %%s!",
1858 spec_mon ? "" : "seemingly dead ",
1859 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
1860 SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
1861 | SUPPRESS_INVISIBLE | SUPPRESS_IT,
1863 spec_mon ? "reconstitutes" : "transforms");
1866 if (mtmp->mhpmax <= 0)
1868 mtmp->mhp = mtmp->mhpmax;
1869 /* this can happen if previously a fog cloud */
1870 if (u.uswallow && (mtmp == u.ustuck))
1871 expels(mtmp, mtmp->data, FALSE);
1875 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
1876 rloc_to(mtmp, new_xy.x, new_xy.y);
1879 newcham(mtmp, &mons[mndx], FALSE, FALSE);
1880 if (mtmp->data == &mons[mndx])
1881 mtmp->cham = NON_PM;
1884 if (canspotmon(mtmp)) {
1885 pline(buf, a_monnam(mtmp));
1886 vamp_rise_msg = TRUE;
1893 /* dead vault guard is actually kept at coordinate <0,0> until
1894 his temporary corridor to/from the vault has been removed;
1895 need to do this after life-saving and before m_detach() */
1896 if (mtmp->isgd && !grddead(mtmp))
1899 /* Player is thrown from his steed when it dies */
1900 if (mtmp == u.usteed)
1901 dismount_steed(DISMOUNT_GENERIC);
1903 mptr = mtmp->data; /* save this for m_detach() */
1904 /* restore chameleon, lycanthropes to true form at death */
1905 if (mtmp->cham >= LOW_PM) {
1906 set_mon_data(mtmp, &mons[mtmp->cham], -1);
1907 mtmp->cham = NON_PM;
1908 } else if (mtmp->data == &mons[PM_WEREJACKAL])
1909 set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL], -1);
1910 else if (mtmp->data == &mons[PM_WEREWOLF])
1911 set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF], -1);
1912 else if (mtmp->data == &mons[PM_WERERAT])
1913 set_mon_data(mtmp, &mons[PM_HUMAN_WERERAT], -1);
1915 /* if MAXMONNO monsters of a given type have died, and it
1916 * can be done, extinguish that monster.
1918 * mvitals[].died does double duty as total number of dead monsters
1919 * and as experience factor for the player killing more monsters.
1920 * this means that a dragon dying by other means reduces the
1921 * experience the player gets for killing a dragon directly; this
1922 * is probably not too bad, since the player likely finagled the
1923 * first dead dragon via ring of conflict or pets, and extinguishing
1924 * based on only player kills probably opens more avenues of abuse
1925 * for rings of conflict and such.
1927 tmp = monsndx(mtmp->data);
1928 if (mvitals[tmp].died < 255)
1929 mvitals[tmp].died++;
1931 /* if it's a (possibly polymorphed) quest leader, mark him as dead */
1932 if (mtmp->m_id == quest_status.leader_m_id)
1933 quest_status.leader_is_dead = TRUE;
1935 /* if the mail daemon dies, no more mail delivery. -3. */
1936 if (tmp == PM_MAIL_DAEMON)
1937 mvitals[tmp].mvflags |= G_GENOD;
1940 if (mtmp->data->mlet == S_KOP) {
1941 /* Dead Kops may come back. */
1943 case 1: /* returns near the stairs */
1944 (void) makemon(mtmp->data, xdnstair, ydnstair, NO_MM_FLAGS);
1946 case 2: /* randomly */
1947 (void) makemon(mtmp->data, 0, 0, NO_MM_FLAGS);
1955 if (mtmp->data->msound == MS_NEMESIS)
1957 if (mtmp->data == &mons[PM_MEDUSA])
1958 u.uachieve.killed_medusa = 1;
1959 if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
1960 unmap_object(mtmp->mx, mtmp->my);
1961 m_detach(mtmp, mptr);
1964 /* TRUE if corpse might be dropped, magr may die if mon was swallowed */
1966 corpse_chance(mon, magr, was_swallowed)
1968 struct monst *magr; /* killer, if swallowed */
1969 boolean was_swallowed; /* digestion */
1971 struct permonst *mdat = mon->data;
1974 if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) {
1975 if (cansee(mon->mx, mon->my) && !was_swallowed)
1977 pline("%s body crumbles into dust.", s_suffix(Monnam(mon)));
1979 pline("%s
\82Ì
\91Ì
\82Í
\95²
\81X
\82É
\82È
\82Á
\82½
\81D", Monnam(mon));
1983 /* Gas spores always explode upon death */
1984 for (i = 0; i < NATTK; i++) {
1985 if (mdat->mattk[i].aatyp == AT_BOOM) {
1986 if (mdat->mattk[i].damn)
1987 tmp = d((int) mdat->mattk[i].damn, (int) mdat->mattk[i].damd);
1988 else if (mdat->mattk[i].damd)
1989 tmp = d((int) mdat->mlevel + 1, (int) mdat->mattk[i].damd);
1992 if (was_swallowed && magr) {
1993 if (magr == &youmonst) {
1995 There("is an explosion in your %s!", body_part(STOMACH));
1997 pline("%s
\82Ì
\92\86\82Å
\94\9a\94
\82ª
\8bN
\82«
\82½
\81I", body_part(STOMACH));
1999 Sprintf(killer.name, "%s explosion",
2000 s_suffix(mdat->mname));
2002 Sprintf(killer.name, "%s
\82Ì
\94\9a\94
\82Å", mdat->mname);
2004 losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN);
2007 You_hear("an explosion.");
2009 You_hear("
\94\9a\94
\89¹
\82ð
\95·
\82¢
\82½
\81D");
2013 if (magr->mhp < 1) { /* maybe lifesaved */
2014 if (canspotmon(magr))
2016 pline("%s rips open!", Monnam(magr));
2018 pline("%s
\82Í
\83r
\83\8a\82Á
\82Æ
\94j
\82ê
\82½
\81I", Monnam(magr));
2019 } else if (canseemon(magr))
2021 pline("%s seems to have indigestion.", Monnam(magr));
2023 pline("%s
\82Í
\8fÁ
\89»
\95s
\97Ç
\82Ì
\82æ
\82¤
\82¾
\81D", Monnam(magr));
2030 Sprintf(killer.name, "%s explosion", s_suffix(mdat->mname));
2032 Sprintf(killer.name, "%s
\82Ì
\94\9a\94
\82Å", mdat->mname);
2033 killer.format = KILLED_BY_AN;
2034 explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS);
2039 /* must duplicate this below check in xkilled() since it results in
2040 * creating no objects as well as no corpse
2042 if (LEVEL_SPECIFIC_NOCORPSE(mdat))
2045 if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned)
2046 || is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat))
2048 tmp = 2 + ((mdat->geno & G_FREQ) < 2) + verysmall(mdat);
2049 return (boolean) !rn2(tmp);
2052 /* drop (perhaps) a cadaver and remove monster */
2055 register struct monst *mdef;
2059 return; /* lifesaved */
2061 if (corpse_chance(mdef, (struct monst *) 0, FALSE)
2062 && (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my)))
2063 (void) make_corpse(mdef, CORPSTAT_NONE);
2066 /* monster disappears, not dies */
2071 mdef->mhp = 0; /* can skip some inventory bookkeeping */
2073 /* dead vault guard is actually kept at coordinate <0,0> until
2074 his temporary corridor to/from the vault has been removed */
2075 if (mdef->isgd && !grddead(mdef))
2077 /* hero is thrown from his steed when it disappears */
2078 if (mdef == u.usteed)
2079 dismount_steed(DISMOUNT_GENERIC);
2080 /* drop special items like the Amulet so that a dismissed Kop or nurse
2081 can't remove them from the game */
2082 mdrop_special_objs(mdef);
2083 /* release rest of monster's inventory--it is removed from game */
2084 discard_minvent(mdef);
2085 m_detach(mdef, mdef->data);
2088 /* drop a statue or rock and remove monster */
2093 struct obj *otmp, *obj, *oldminvent;
2094 xchar x = mdef->mx, y = mdef->my;
2095 boolean wasinside = FALSE;
2097 /* we have to make the statue before calling mondead, to be able to
2098 * put inventory in it, and we have to check for lifesaving before
2099 * making the statue....
2101 lifesaved_monster(mdef);
2105 mdef->mtrapped = 0; /* (see m_detach) */
2107 if ((int) mdef->data->msize > MZ_TINY
2108 || !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) {
2110 /* some objects may end up outside the statue */
2111 while ((obj = mdef->minvent) != 0) {
2112 obj_extract_self(obj);
2114 update_mon_intrinsics(mdef, obj, FALSE, TRUE);
2115 obj_no_longer_held(obj);
2116 if (obj->owornmask & W_WEP)
2117 setmnotwielded(mdef, obj);
2118 obj->owornmask = 0L;
2119 if (obj->otyp == BOULDER
2120 #if 0 /* monsters don't carry statues */
2121 || (obj->otyp == STATUE
2122 && mons[obj->corpsenm].msize >= mdef->data->msize)
2124 /* invocation tools resist even with 0% resistance */
2125 || obj_resists(obj, 0, 0)) {
2127 if (flooreffects(obj, x, y, "fall"))
2129 if (flooreffects(obj, x, y, "
\97\8e\82¿
\82é"))
2131 place_object(obj, x, y);
2134 end_burn(obj, TRUE);
2135 obj->nobj = oldminvent;
2139 /* defer statue creation until after inventory removal
2140 so that saved monster traits won't retain any stale
2141 item-conferred attributes */
2142 otmp = mkcorpstat(STATUE, mdef, mdef->data, x, y, CORPSTAT_NONE);
2143 if (has_mname(mdef))
2144 otmp = oname(otmp, MNAME(mdef));
2145 while ((obj = oldminvent) != 0) {
2146 oldminvent = obj->nobj;
2147 (void) add_to_container(otmp, obj);
2149 /* Archeologists should not break unique statues */
2150 if (mdef->data->geno & G_UNIQ)
2152 otmp->owt = weight(otmp);
2154 otmp = mksobj_at(ROCK, x, y, TRUE, FALSE);
2157 /* mondead() already does this, but we must do it before the newsym */
2158 if (glyph_is_invisible(levl[x][y].glyph))
2162 /* We don't currently trap the hero in the statue in this case but we
2164 if (u.uswallow && u.ustuck == mdef)
2168 if (is_animal(mdef->data))
2170 You("%s through an opening in the new %s.",
2171 locomotion(youmonst.data, "jump"), xname(otmp));
2173 You("
\90V
\82µ
\82
\82Å
\82«
\82½%s
\82©
\82ç%s
\81D",
2174 xname(otmp), jumpedthrough(youmonst.data, "
\94ò
\82Ñ
\8fo
\82½"));
2179 /* another monster has killed the monster mdef */
2181 monkilled(mdef, fltxt, how)
2186 boolean be_sad = FALSE; /* true if unseen pet is killed */
2188 if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my))
2191 pline("%s is %s%s%s!", Monnam(mdef),
2192 nonliving(mdef->data) ? "destroyed" : "killed",
2193 *fltxt ? " by the " : "", fltxt);
2197 pline("%s
\82Í%s
\82É
\82æ
\82Á
\82Ä%s
\81I", Monnam(mdef), fltxt,
2198 nonliving(mdef->data) ? "
\93|
\82³
\82ê
\82½" : "
\8eE
\82³
\82ê
\82½");
2200 pline("%s
\82Í%s
\81I", Monnam(mdef),
2201 nonliving(mdef->data) ? "
\93|
\82³
\82ê
\82½" : "
\8eE
\82³
\82ê
\82½");
2205 be_sad = (mdef->mtame != 0);
2207 /* no corpses if digested or disintegrated */
2208 if (how == AD_DGST || how == -AD_RBRE)
2213 if (be_sad && mdef->mhp <= 0)
2215 You("have a sad feeling for a moment, then it passes.");
2217 You("
\94ß
\82µ
\82¢
\8bC
\8e\9d\82É
\82¨
\82»
\82í
\82ê
\82½
\82ª
\81C
\82·
\82®
\82É
\89ß
\82¬
\82³
\82Á
\82½
\81D");
2224 if (u.ustuck == mtmp) {
2230 if (Punished && uchain->where != OBJ_FLOOR)
2232 vision_full_recalc = 1;
2246 /* the player has killed the monster mtmp */
2250 int dest; /* dest==1, normal; dest==0, don't print message; dest==2, don't
2251 drop corpse either; dest==3, message but no corpse */
2253 int tmp, mndx, x = mtmp->mx, y = mtmp->my;
2254 struct permonst *mdat;
2257 boolean wasinside = u.uswallow && (u.ustuck == mtmp);
2258 boolean burycorpse = FALSE;
2261 u.uconduct.killer++;
2265 const char *verb = nonliving(mtmp->data) ? "destroy" : "kill";
2268 if (!wasinside && !canspotmon(mtmp))
2270 You("%s it!", verb);
2272 You("
\89½
\8eÒ
\82©
\82ð
\93|
\82µ
\82½
\81I");
2279 (has_mname(mtmp)) ? ARTICLE_NONE : ARTICLE_THE,
2281 (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0,
2284 You("%s%s
\82ð
\93|
\82µ
\82½
\81I",
2285 mtmp->mtame ? "
\82©
\82í
\82¢
\82»
\82¤
\82È" : "",
2291 if (mtmp->mtrapped && (t = t_at(x, y)) != 0
2292 && (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
2293 if (sobj_at(BOULDER, x, y))
2295 * Prevent corpses/treasure being created "on top"
2296 * of the boulder that is about to fall in. This is
2297 * out of order, but cannot be helped unless this
2298 * whole routine is rearranged.
2300 if (m_carrying(mtmp, BOULDER))
2304 /* your pet knows who just killed it...watch out */
2305 if (mtmp->mtame && !mtmp->isminion)
2306 EDOG(mtmp)->killed_by_u = 1;
2308 if (wasinside && thrownobj && thrownobj != uball) {
2309 /* thrown object has killed hero's engulfer; add it to mon's
2310 inventory now so that it will be placed with mon's other
2311 stuff prior to lookhere/autopickup when hero is expelled
2312 below (as a side-effect, this missile has immunity from
2313 being consumed [for this shot/throw only]) */
2314 mpickobj(mtmp, thrownobj);
2315 /* let throwing code know that missile has been disposed of */
2319 vamp_rise_msg = FALSE; /* might get set in mondead() */
2320 /* dispose of monster and make cadaver */
2326 if (mtmp->mhp > 0) { /* monster lifesaved */
2327 /* Cannot put the non-visible lifesaving message in
2328 * lifesaved_monster() since the message appears only when you
2329 * kill it (as opposed to visible lifesaving which always
2333 if (!cansee(x, y) && !vamp_rise_msg)
2335 pline("Maybe not...");
2337 pline("
\82¢
\82â
\81C
\88á
\82¤
\82©
\82à
\81D
\81D
\81D");
2341 mdat = mtmp->data; /* note: mondead can change mtmp->data */
2342 mndx = monsndx(mdat);
2349 if ((dest & 2) || LEVEL_SPECIFIC_NOCORPSE(mdat))
2353 if (mdat == &mons[PM_MAIL_DAEMON]) {
2354 stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE));
2357 if (accessible(x, y) || is_pool(x, y)) {
2358 struct obj *cadaver;
2361 /* illogical but traditional "treasure drop" */
2362 if (!rn2(6) && !(mvitals[mndx].mvflags & G_NOCORPSE)
2363 /* no extra item from swallower or steed */
2364 && (x != u.ux || y != u.uy)
2365 /* no extra item from kops--too easy to abuse */
2366 && mdat->mlet != S_KOP
2367 /* no items from cloned monsters */
2368 && !mtmp->mcloned) {
2369 otmp = mkobj(RANDOM_CLASS, TRUE);
2370 /* don't create large objects from small monsters */
2372 if (mdat->msize < MZ_HUMAN && otyp != FIGURINE
2373 /* oc_big is also oc_bimanual and oc_bulky */
2374 && (otmp->owt > 30 || objects[otyp].oc_big)) {
2376 } else if (!flooreffects(otmp, x, y, (dest & 1) ? "fall" : "")) {
2377 place_object(otmp, x, y);
2381 /* corpse--none if hero was inside the monster */
2382 if (!wasinside && corpse_chance(mtmp, (struct monst *) 0, FALSE)) {
2383 cadaver = make_corpse(mtmp, burycorpse ? CORPSTAT_BURIED
2385 if (burycorpse && cadaver && cansee(x, y) && !mtmp->minvis
2386 && cadaver->where == OBJ_BURIED && (dest & 1)) {
2387 pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp)));
2392 spoteffects(TRUE); /* poor man's expels() */
2393 /* monster is gone, corpse or other object might now be visible */
2397 /* punish bad behaviour */
2398 if (is_human(mdat) && (!always_hostile(mdat) && mtmp->malign <= 0)
2399 && (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD)
2400 && u.ualign.type != A_CHAOTIC) {
2401 HTelepat &= ~INTRINSIC;
2406 You("
\8eE
\90l
\8bS
\82¾
\81I");
2407 if (Blind && !Blind_telepat)
2408 see_monsters(); /* Can't sense monsters any more. */
2410 if ((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame)
2412 if (is_unicorn(mdat) && sgn(u.ualign.type) == sgn(mdat->maligntyp)) {
2415 You_feel("guilty...");
2417 You("
\8dß
\82ð
\8a´
\82¶
\82½
\81D
\81D
\81D");
2420 /* give experience points */
2421 tmp = experience(mtmp, (int) mvitals[mndx].died);
2422 more_experienced(tmp, 0);
2423 newexplevel(); /* will decide if you go up */
2425 /* adjust alignment points */
2426 if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */
2427 adjalign(-(u.ualign.record + (int) ALIGNLIM / 2));
2429 pline("That was %sa bad idea...",
2430 u.uevent.qcompleted ? "probably " : "");
2432 pline("%s
\82æ
\82
\82È
\82¢
\8ds
\88×
\82¾
\82Á
\82½
\81D
\81D
\81D",
2433 u.uevent.qcompleted ? "
\82½
\82Ô
\82ñ" : "");
2435 } else if (mdat->msound == MS_NEMESIS) { /* Real good! */
2436 adjalign((int) (ALIGNLIM / 4));
2437 } else if (mdat->msound == MS_GUARDIAN) { /* Bad */
2438 adjalign(-(int) (ALIGNLIM / 8));
2441 pline("That was probably a bad idea...");
2443 pline("
\82æ
\82
\82È
\82¢
\8ds
\88×
\82¾
\82Á
\82½
\81D
\81D
\81D");
2446 pline("Whoopsie-daisy!");
2448 pline("
\83V
\83\93\83W
\83}
\83b
\83^
\81[
\81I");
2449 } else if (mtmp->ispriest) {
2450 adjalign((p_coaligned(mtmp)) ? -2 : 2);
2451 /* cancel divine protection for killing your priest */
2452 if (p_coaligned(mtmp))
2454 if (mdat->maligntyp == A_NONE)
2455 adjalign((int) (ALIGNLIM / 4)); /* BIG bonus */
2456 } else if (mtmp->mtame) {
2457 adjalign(-15); /* bad!! */
2458 /* your god is mighty displeased... */
2461 You_hear("the rumble of distant thunder...");
2463 You_hear("
\89\93\82
\82Å
\97\8b\96Â
\82ð
\95·
\82¢
\82½
\81D
\81D
\81D");
2466 You_hear("the studio audience applaud!");
2468 pline("
\92®
\8fO
\82Ì
\8a\85\8dÑ
\82ð
\97\81\82Ñ
\82½
\81I");
2469 } else if (mtmp->mpeaceful)
2472 /* malign was already adjusted for u.ualign.type and randomization */
2473 adjalign(mtmp->malign);
2476 /* changes the monster into a stone monster of the same type
2477 this should only be called when poly_when_stoned() is true */
2482 if (mtmp->data->mlet == S_GOLEM) {
2483 /* it's a golem, and not a stone golem */
2484 if (canseemon(mtmp))
2486 pline("%s solidifies...", Monnam(mtmp));
2488 pline("%s
\82Í
\8bÃ
\8cÅ
\82µ
\82½
\81D
\81D
\81D", Monnam(mtmp));
2489 if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) {
2490 if (canseemon(mtmp))
2492 pline("Now it's %s.", an(mtmp->data->mname));
2494 pline("
\82È
\82ñ
\82Æ%s
\82É
\82È
\82Á
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D", mtmp->data->mname);
2496 if (canseemon(mtmp))
2498 pline("... and returns to normal.");
2500 pline("
\81D
\81D
\81D
\82»
\82µ
\82Ä
\95\81\92Ê
\82É
\96ß
\82Á
\82½
\81D");
2503 impossible("Can't polystone %s!", a_monnam(mtmp));
2506 /* make monster mtmp next to you (if possible);
2507 might place monst on far side of a wall or boulder */
2513 boolean couldspot = canspotmon(mtmp);
2515 if (mtmp == u.usteed) {
2516 /* Keep your steed in sync with you instead */
2522 if (!enexto(&mm, u.ux, u.uy, mtmp->data))
2524 rloc_to(mtmp, mm.x, mm.y);
2525 if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) {
2526 mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */
2527 if (!couldspot && canspotmon(mtmp))
2528 pline("%s suddenly %s!", Amonnam(mtmp),
2529 !Blind ? "appears" : "arrives");
2534 /* like mnexto() but requires destination to be directly accessible */
2540 struct permonst *ptr = mtmp->data;
2541 boolean diagok = !NODIAG(ptr - mons);
2545 if (!enexto(&mm, u.ux, u.uy, ptr))
2547 if (couldsee(mm.x, mm.y)
2548 /* don't move grid bugs diagonally */
2549 && (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) {
2550 rloc_to(mtmp, mm.x, mm.y);
2553 } while (--tryct > 0);
2557 * Put monster near (or at) location if possible.
2559 * 1 - if a monster was moved from x, y to put mtmp at x, y.
2560 * 0 - in most cases.
2563 mnearto(mtmp, x, y, move_other)
2564 register struct monst *mtmp;
2566 boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */
2568 struct monst *othermon = (struct monst *) 0;
2572 if (mtmp->mx == x && mtmp->my == y)
2575 if (move_other && (othermon = m_at(x, y)) != 0) {
2576 if (othermon->wormno)
2577 remove_worm(othermon);
2579 remove_monster(x, y);
2584 if (!goodpos(newx, newy, mtmp, 0)) {
2585 /* Actually we have real problems if enexto ever fails.
2586 * Migrating_mons that need to be placed will cause
2587 * no end of trouble.
2589 if (!enexto(&mm, newx, newy, mtmp->data))
2594 rloc_to(mtmp, newx, newy);
2596 if (move_other && othermon) {
2597 xchar oldx = othermon->mx, oldy = othermon->my;
2599 othermon->mx = othermon->my = 0;
2600 (void) mnearto(othermon, x, y, FALSE);
2601 if (othermon->mx == 0 && othermon->my == 0) {
2602 /* reloc failed, dump monster into "limbo"
2603 (aka migrate to current level) */
2604 othermon->mx = oldx;
2605 othermon->my = oldy;
2606 mdrop_special_objs(othermon);
2607 migrate_to_level(othermon, ledger_no(&u.uz), MIGR_APPROX_XY, NULL);
2614 /* monster responds to player action; not the same as a passive attack;
2615 assumes reason for response has been tested, and response _must_ be made */
2620 if (mtmp->data->msound == MS_SHRIEK) {
2623 pline("%s shrieks.", Monnam(mtmp));
2625 pline("%s
\82Í
\8bà
\90Ø
\82è
\90º
\82ð
\82 \82°
\82½
\81D", Monnam(mtmp));
2630 (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
2632 (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS);
2636 if (mtmp->data == &mons[PM_MEDUSA]) {
2639 for (i = 0; i < NATTK; i++)
2640 if (mtmp->data->mattk[i].aatyp == AT_GAZE) {
2641 (void) gazemu(mtmp, &mtmp->data->mattk[i]);
2651 mtmp->mstrategy &= ~STRAT_WAITMASK;
2652 if (!mtmp->mpeaceful)
2656 mtmp->mpeaceful = 0;
2657 if (mtmp->ispriest) {
2658 if (p_coaligned(mtmp))
2659 adjalign(-5); /* very bad */
2663 adjalign(-1); /* attacking peaceful monsters is bad */
2664 if (couldsee(mtmp->mx, mtmp->my)) {
2665 if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
2667 pline("%s gets angry!", Monnam(mtmp));
2669 pline("%s
\82Í
\93{
\82Á
\82½
\81I", Monnam(mtmp));
2670 else if (flags.verbose && !Deaf)
2674 /* attacking your own quest leader will anger his or her guardians */
2675 if (!context.mon_moving /* should always be the case here */
2676 && mtmp->data == &mons[quest_info(MS_LEADER)]) {
2678 struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
2681 /* guardians will sense this attack even if they can't see it */
2682 for (mon = fmon; mon; mon = mon->nmon) {
2683 if (DEADMONSTER(mon))
2685 if (mon->data == q_guardian && mon->mpeaceful) {
2691 if (got_mad && !Hallucination)
2693 pline_The("%s appear%s to be angry too...",
2694 got_mad == 1 ? q_guardian->mname
2695 : makeplural(q_guardian->mname),
2696 got_mad == 1 ? "s" : "");
2698 pline("%s
\82à
\93{
\82Á
\82½
\81D
\81D
\81D", q_guardian->mname);
2703 /* wake up a monster, usually making it angry in the process */
2706 register struct monst *mtmp;
2708 mtmp->msleeping = 0;
2709 finish_meating(mtmp);
2711 if (mtmp->m_ap_type) {
2713 } else if (context.forcefight && !context.mon_moving
2714 && mtmp->mundetected) {
2715 mtmp->mundetected = 0;
2716 newsym(mtmp->mx, mtmp->my);
2720 /* Wake up nearby monsters without angering them. */
2724 register struct monst *mtmp;
2726 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
2727 if (DEADMONSTER(mtmp))
2729 if (distu(mtmp->mx, mtmp->my) < u.ulevel * 20) {
2730 mtmp->msleeping = 0;
2731 if (!unique_corpstat(mtmp->data))
2732 mtmp->mstrategy &= ~STRAT_WAITMASK;
2733 if (mtmp->mtame && !mtmp->isminion)
2734 EDOG(mtmp)->whistletime = moves;
2739 /* Wake up monsters near some particular location. */
2741 wake_nearto(x, y, distance)
2742 register int x, y, distance;
2744 register struct monst *mtmp;
2746 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
2747 if (DEADMONSTER(mtmp))
2749 if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
2750 mtmp->msleeping = 0;
2751 if (!unique_corpstat(mtmp->data))
2752 mtmp->mstrategy &= ~STRAT_WAITMASK;
2757 /* NOTE: we must check for mimicry before calling this routine */
2760 register struct monst *mtmp;
2762 boolean is_blocker_appear = (is_door_mappear(mtmp)
2763 || is_obj_mappear(mtmp, BOULDER));
2765 if (has_mcorpsenm(mtmp))
2766 freemcorpsenm(mtmp);
2768 mtmp->m_ap_type = M_AP_NOTHING;
2769 mtmp->mappearance = 0;
2772 * Discovered mimics don't block light.
2774 if (is_blocker_appear
2775 && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
2776 unblock_point(mtmp->mx, mtmp->my);
2778 newsym(mtmp->mx, mtmp->my);
2781 /* force all chameleons to become normal */
2785 register struct monst *mtmp;
2788 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
2789 if (DEADMONSTER(mtmp))
2791 mcham = (int) mtmp->cham;
2792 if (mcham >= LOW_PM) {
2793 (void) newcham(mtmp, &mons[mcham], FALSE, FALSE);
2794 mtmp->cham = NON_PM;
2796 if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
2798 if (mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) {
2800 /* we pretend that the mimic doesn't
2801 know that it has been unmasked */
2802 mtmp->msleeping = 1;
2807 /* Let the chameleons change again -dgk */
2811 register struct monst *mtmp;
2813 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
2814 if (DEADMONSTER(mtmp))
2816 mtmp->cham = pm_to_cham(monsndx(mtmp->data));
2817 if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping
2818 && cansee(mtmp->mx, mtmp->my)) {
2819 set_mimic_sym(mtmp);
2820 newsym(mtmp->mx, mtmp->my);
2825 /* called when restoring a monster from a saved level; protection
2826 against shape-changing might be different now than it was at the
2827 time the level was saved. */
2834 if (Protection_from_shape_changers) {
2835 mcham = (int) mon->cham;
2836 if (mcham >= LOW_PM) {
2838 (void) newcham(mon, &mons[mcham], FALSE, FALSE);
2839 } else if (is_were(mon->data) && !is_human(mon->data)) {
2842 } else if (mon->cham == NON_PM) {
2843 mon->cham = pm_to_cham(monsndx(mon->data));
2847 /* unwatched hiders may hide again; if so, returns True */
2850 register struct monst *mtmp;
2854 if (mtmp->mcan || mtmp->m_ap_type || cansee(mtmp->mx, mtmp->my)
2855 || rn2(3) || mtmp == u.ustuck
2856 /* can't hide while trapped except in pits */
2857 || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
2858 && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))
2859 || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
2862 if (mtmp->data->mlet == S_MIMIC) {
2863 set_mimic_sym(mtmp);
2865 } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) {
2866 mtmp->mundetected = 1;
2873 /* monster/hero tries to hide under something at the current location */
2879 boolean undetected = FALSE, is_u = (mtmp == &youmonst);
2880 xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
2882 if (mtmp == u.ustuck) {
2883 ; /* can't hide if holding you or held by you */
2884 } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
2885 : (mtmp->mtrapped && (t = t_at(x, y)) != 0
2886 && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) {
2887 ; /* can't hide while stuck in a non-pit trap */
2888 } else if (mtmp->data->mlet == S_EEL) {
2889 undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
2890 } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
2891 struct obj *otmp = level.objects[x][y];
2893 /* most monsters won't hide under cockatrice corpse */
2894 if (otmp->nexthere || otmp->otyp != CORPSE
2895 || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp))
2896 || !touch_petrifies(&mons[otmp->corpsenm]))
2901 u.uundetected = undetected;
2903 mtmp->mundetected = undetected;
2907 /* called when returning to a previously visited level */
2912 boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL;
2914 if ((is_hider(mon->data) || hider_under)
2915 && !(mon->mundetected || mon->m_ap_type)) {
2916 xchar x = mon->mx, y = mon->my;
2917 char save_viz = viz_array[y][x];
2919 /* override vision, forcing hero to be unable to see monster's spot */
2920 viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE);
2921 if (is_hider(mon->data))
2922 (void) restrap(mon);
2923 /* try again if mimic missed its 1/3 chance to hide */
2924 if (mon->data->mlet == S_MIMIC && !mon->m_ap_type)
2925 (void) restrap(mon);
2927 (void) hideunder(mon);
2928 viz_array[y][x] = save_viz;
2932 static short *animal_list = 0; /* list of PM values for animal monsters */
2933 static int animal_list_count;
2936 mon_animal_list(construct)
2940 short animal_temp[SPECIAL_PM];
2943 /* if (animal_list) impossible("animal_list already exists"); */
2945 for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
2946 if (is_animal(&mons[i]))
2947 animal_temp[n++] = i;
2948 /* if (n == 0) animal_temp[n++] = NON_PM; */
2950 animal_list = (short *) alloc(n * sizeof *animal_list);
2951 (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp,
2952 n * sizeof *animal_list);
2953 animal_list_count = n;
2954 } else { /* release */
2956 free((genericptr_t) animal_list), animal_list = 0;
2957 animal_list_count = 0;
2967 mon_animal_list(TRUE);
2969 res = animal_list[rn2(animal_list_count)];
2970 /* rogue level should use monsters represented by uppercase letters
2971 only, but since chameleons aren't generated there (not uppercase!)
2972 we don't perform a lot of retries */
2973 if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet))
2974 res = animal_list[rn2(animal_list_count)];
2979 decide_to_shapeshift(mon, shiftflags)
2983 struct permonst *ptr;
2984 unsigned was_female = mon->female;
2985 boolean msg = FALSE;
2987 if ((shiftflags & SHIFT_MSG)
2988 || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon)))
2991 if (is_vampshifter(mon)) {
2992 /* The vampire has to be in good health (mhp) to maintain
2995 * If we're shifted and getting low on hp, maybe shift back.
2996 * If we're not already shifted and in good health, maybe shift.
2998 if ((mon->mhp <= mon->mhpmax / 6) && rn2(4) && (mon->cham >= LOW_PM))
2999 (void) newcham(mon, &mons[mon->cham], FALSE, msg);
3000 } else if (mon->data->mlet == S_VAMPIRE && mon->cham == NON_PM && !rn2(6)
3001 && (mon->mhp > mon->mhpmax - ((mon->mhpmax / 10) + 1))) {
3002 (void) newcham(mon, (struct permonst *) 0, FALSE, msg);
3004 /* override the 10% chance for sex change */
3006 if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr))
3007 mon->female = was_female;
3014 int mndx = mon->cham;
3015 /* avoid picking monsters with lowercase display symbols ('d' for wolf
3016 and 'v' for fog cloud) on rogue level*/
3017 boolean uppercase_only = Is_rogue_level(&u.uz);
3020 case PM_VLAD_THE_IMPALER:
3021 /* ensure Vlad can keep carrying the Candelabrum */
3022 if (mon_has_special(mon))
3023 break; /* leave mndx as is */
3025 case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */
3026 if (!rn2(10) && !uppercase_only) {
3031 case PM_VAMPIRE: /* any vampire can become fog or bat */
3032 mndx = (!rn2(4) && !uppercase_only) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
3038 /* nonshapechangers who warrant special polymorph handling */
3043 return (mon->isshk || mon->ispriest || mon->isgd
3044 || mon->m_id == quest_status.leader_m_id);
3047 /* restrict certain special monsters (shopkeepers, aligned priests,
3048 vault guards) to forms that allow them to behave sensibly (catching
3049 gold, speaking?) so that they don't need too much extra code */
3051 validspecmon(mon, mndx)
3056 return TRUE; /* caller wants random */
3058 if (!accept_newcham_form(mndx))
3059 return FALSE; /* geno'd or !polyok */
3061 if (isspecmon(mon)) {
3062 struct permonst *ptr = &mons[mndx];
3064 /* reject notake because object manipulation is expected
3065 and nohead because speech capability is expected */
3066 if (notake(ptr) || !has_head(ptr))
3068 /* [should we check ptr->msound here too?] */
3070 return TRUE; /* potential new form is ok */
3073 /* prevent wizard mode user from specifying invalid vampshifter shape */
3075 validvamp(mon, mndx_p, monclass)
3077 int *mndx_p, monclass;
3079 /* simplify caller's usage */
3080 if (!is_vampshifter(mon))
3081 return validspecmon(mon, *mndx_p);
3083 if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD
3084 || *mndx_p == PM_VLAD_THE_IMPALER) {
3085 /* player picked some type of vampire; use mon's self */
3086 *mndx_p = mon->cham;
3089 if (mon->cham == PM_VLAD_THE_IMPALER && mon_has_special(mon)) {
3090 /* Vlad with Candelabrum; override choice, then accept it */
3091 *mndx_p = PM_VLAD_THE_IMPALER;
3094 /* basic vampires can't become wolves; any can become fog or bat
3095 (we don't enforce upper-case only for rogue level here) */
3096 if (*mndx_p == PM_WOLF)
3097 return (boolean) (mon->cham != PM_VAMPIRE);
3098 if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT)
3101 /* if we get here, specific type was no good; try by class */
3104 *mndx_p = mon->cham;
3107 *mndx_p = PM_VAMPIRE_BAT;
3110 *mndx_p = PM_FOG_CLOUD;
3113 if (mon->cham != PM_VAMPIRE) {
3122 return (boolean) (*mndx_p != NON_PM);
3126 select_newcham_form(mon)
3129 int mndx = NON_PM, tryct;
3131 switch (mon->cham) {
3134 mndx = pick_nasty();
3136 case PM_DOPPELGANGER:
3138 mndx = pick_nasty();
3139 } else if (rn2(3)) { /* role monsters */
3140 mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
3141 } else if (!rn2(3)) { /* quest guardians */
3142 mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT);
3143 /* avoid own role's guardian */
3144 if (mndx == urole.guardnum)
3146 } else { /* general humanoids */
3149 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3150 if (humanoid(&mons[mndx]) && polyok(&mons[mndx]))
3152 } while (--tryct > 0);
3159 mndx = pick_animal();
3161 case PM_VLAD_THE_IMPALER:
3162 case PM_VAMPIRE_LORD:
3164 mndx = pickvampshape(mon);
3166 case NON_PM: /* ordinary */
3168 struct obj *m_armr = which_armor(mon, W_ARM);
3170 if (m_armr && Is_dragon_scales(m_armr))
3171 mndx = (int) (Dragon_scales_to_pm(m_armr) - mons);
3172 else if (m_armr && Is_dragon_mail(m_armr))
3173 mndx = (int) (Dragon_mail_to_pm(m_armr) - mons);
3177 /* for debugging: allow control of polymorphed monster */
3178 if (wizard && iflags.mon_polycontrol) {
3179 char pprompt[BUFSZ], buf[BUFSZ];
3182 Sprintf(pprompt, "Change %s @ <%d,%d> into what kind of monster?",
3183 noit_mon_nam(mon), (int) mon->mx, (int) mon->my);
3187 getlin(pprompt, buf);
3189 /* for ESC, take form selected above (might be NON_PM) */
3192 /* for "*", use NON_PM to pick an arbitrary shape below */
3193 if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
3197 mndx = name_to_mon(buf);
3198 if (mndx == NON_PM) {
3199 /* didn't get a type, so check whether it's a class
3200 (single letter or text match with def_monsyms[]) */
3201 monclass = name_to_monclass(buf, &mndx);
3202 if (monclass && mndx == NON_PM)
3203 mndx = mkclass_poly(monclass);
3205 if (mndx >= LOW_PM) {
3206 /* got a specific type of monster; use it if we can */
3207 if (validvamp(mon, &mndx, monclass))
3209 /* can't; revert to random in case we exhaust tryct */
3213 pline("It can't become that.");
3214 } while (--tryct > 0);
3216 pline1(thats_enough_tries);
3217 if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass))
3218 mndx = pickvampshape(mon); /* don't resort to arbitrary */
3221 /* if no form was specified above, pick one at random now */
3222 if (mndx == NON_PM) {
3225 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3226 } while (--tryct > 0 && !validspecmon(mon, mndx)
3227 /* try harder to select uppercase monster on rogue level */
3228 && (tryct > 40 && Is_rogue_level(&u.uz)
3229 && !isupper((uchar) mons[mndx].mlet)));
3234 /* this used to be inline within newcham() but monpolycontrol needs it too */
3235 STATIC_OVL struct permonst *
3236 accept_newcham_form(mndx)
3239 struct permonst *mdat;
3244 if ((mvitals[mndx].mvflags & G_GENOD) != 0)
3246 if (is_placeholder(mdat))
3248 /* select_newcham_form() might deliberately pick a player
3249 character type (random selection never does) which
3250 polyok() rejects, so we need a special case here */
3251 if (is_mplayer(mdat))
3253 /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */
3254 return polyok(mdat) ? mdat : 0;
3258 mgender_from_permonst(mtmp, mdat)
3260 struct permonst *mdat;
3262 if (is_male(mdat)) {
3264 mtmp->female = FALSE;
3265 } else if (is_female(mdat)) {
3267 mtmp->female = TRUE;
3268 } else if (!is_neuter(mdat)) {
3270 mtmp->female = !mtmp->female;
3274 /* make a chameleon take on another shape, or a polymorph target
3275 (possibly self-inflicted) become a different monster;
3276 returns 1 if it actually changes form */
3278 newcham(mtmp, mdat, polyspot, msg)
3280 struct permonst *mdat;
3281 boolean polyspot; /* change is the result of wand or spell of polymorph */
3282 boolean msg; /* "The oldmon turns into a newmon!" */
3286 struct permonst *olddata = mtmp->data;
3287 char oldname[BUFSZ], newname[BUFSZ];
3289 /* Riders are immune to polymorph and green slime */
3290 if (is_rider(mtmp->data))
3294 /* like Monnam() but never mention saddle */
3295 Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3296 SUPPRESS_SADDLE, FALSE));
3297 oldname[0] = highc(oldname[0]);
3300 /* mdat = 0 -> caller wants a random monster shape */
3302 /* select_newcham_form() loops when resorting to random but
3303 it doesn't always pick that so we still retry here too */
3306 mndx = select_newcham_form(mtmp);
3307 mdat = accept_newcham_form(mndx);
3308 /* for the first several tries we require upper-case on
3309 the rogue level (after that, we take whatever we get) */
3310 if (tryct > 15 && Is_rogue_level(&u.uz)
3311 && mdat && !isupper((uchar) mdat->mlet))
3315 } while (--tryct > 0);
3318 } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
3319 return 0; /* passed in mdat is genocided */
3321 mgender_from_permonst(mtmp, mdat);
3323 if (In_endgame(&u.uz) && is_mplayer(olddata) && has_mname(mtmp)) {
3324 /* mplayers start out as "Foo the Bar", but some of the
3325 * titles are inappropriate when polymorphed, particularly
3326 * into the opposite sex. players don't use ranks when
3327 * polymorphed, so dropping the rank for mplayers seems
3330 char *p = index(MNAME(mtmp), ' ');
3336 if (mdat == mtmp->data)
3337 return 0; /* still the same monster */
3339 if (mtmp->wormno) { /* throw tail away */
3341 place_monster(mtmp, mtmp->mx, mtmp->my);
3343 if (mtmp->m_ap_type && mdat->mlet != S_MIMIC)
3344 seemimic(mtmp); /* revert to normal monster */
3346 /* (this code used to try to adjust the monster's health based on
3347 a normal one of its type but there are too many special cases
3348 which need to handled in order to do that correctly, so just
3349 give the new form the same proportion of HP as its old one had) */
3352 /* set level and hit points */
3353 newmonhp(mtmp, monsndx(mdat));
3354 /* new hp: same fraction of max as before */
3356 mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd);
3358 /* sanity check (potential overflow) */
3359 if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax)
3360 mtmp->mhp = mtmp->mhpmax;
3361 /* unlikely but not impossible; a 1HD creature with 1HP that changes
3362 into a 0HD creature will require this statement */
3366 /* take on the new form... */
3367 set_mon_data(mtmp, mdat, 0);
3369 if (emits_light(olddata) != emits_light(mtmp->data)) {
3370 /* used to give light, now doesn't, or vice versa,
3371 or light's range has changed */
3372 if (emits_light(olddata))
3373 del_light_source(LS_MONSTER, monst_to_any(mtmp));
3374 if (emits_light(mtmp->data))
3375 new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
3376 LS_MONSTER, monst_to_any(mtmp));
3378 if (!mtmp->perminvis || pm_invisible(olddata))
3379 mtmp->perminvis = pm_invisible(mdat);
3380 mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
3381 if (mtmp->mundetected)
3382 (void) hideunder(mtmp);
3383 if (u.ustuck == mtmp) {
3385 if (!attacktype(mdat, AT_ENGL)) {
3386 /* Does mdat care? */
3387 if (!noncorporeal(mdat) && !amorphous(mdat)
3388 && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) {
3390 You("break out of %s%s!", mon_nam(mtmp),
3391 (is_animal(mdat) ? "'s stomach" : ""));
3393 You("%s%s
\82ð
\94j
\82è
\8fo
\82½
\81I", mon_nam(mtmp),
3394 (is_animal(mdat) ? "
\82Ì
\88Ý
\91Ü" : ""));
3396 mtmp->mhp = 1; /* almost dead */
3398 expels(mtmp, olddata, FALSE);
3400 /* update swallow glyphs for new monster */
3403 } else if (!sticks(mdat) && !sticks(youmonst.data))
3408 if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
3410 /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
3413 if (mdat == &mons[PM_LONG_WORM]
3414 && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
3416 /* we can now create worms with tails - 11/91 */
3417 initworm(mtmp, rn2(5));
3418 if (count_wsegs(mtmp))
3419 place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
3422 newsym(mtmp->mx, mtmp->my);
3425 char *save_mname = 0;
3427 if (has_mname(mtmp)) {
3428 save_mname = MNAME(mtmp);
3429 MNAME(mtmp) = (char *) 0;
3432 Strcpy(newname, (mdat == &mons[PM_GREEN_SLIME])
3434 : x_monnam(mtmp, ARTICLE_A, (char *) 0,
3435 SUPPRESS_SADDLE, FALSE));
3437 Strcpy(newname, (mdat == &mons[PM_GREEN_SLIME])
3438 ? "
\83X
\83\89\83C
\83\80"
3439 : x_monnam(mtmp, ARTICLE_A, (char *) 0,
3440 SUPPRESS_SADDLE, FALSE));
3443 if (!strcmpi(oldname, "it") && !strcmpi(newname, "it"))
3445 if (!strcmpi(oldname, "
\89½
\8eÒ
\82©") && !strcmpi(newname, "
\89½
\8eÒ
\82©"))
3446 (void) usmellmon(mdat);
3449 pline("%s turns into %s!", oldname, newname);
3451 pline("%s
\82Í%s
\82É
\82È
\82Á
\82½
\81I", oldname, newname);
3453 MNAME(mtmp) = save_mname;
3456 possibly_unwield(mtmp, polyspot); /* might lose use of weapon */
3457 mon_break_armor(mtmp, polyspot);
3458 if (!(mtmp->misc_worn_check & W_ARMG))
3460 mselftouch(mtmp, "No longer petrify-resistant, ",
3461 !context.mon_moving);
3463 mselftouch(mtmp, "
\90Î
\89»
\82Ö
\82Ì
\92ï
\8dR
\97Í
\82ª
\82È
\82
\82È
\82Á
\82Ä
\81C",
3464 !context.mon_moving);
3466 m_dowear(mtmp, FALSE);
3468 /* This ought to re-test can_carry() on each item in the inventory
3469 * rather than just checking ex-giants & boulders, but that'd be
3470 * pretty expensive to perform. If implemented, then perhaps
3471 * minvent should be sorted in order to drop heaviest items first.
3473 /* former giants can't continue carrying boulders */
3474 if (mtmp->minvent && !throws_rocks(mdat)) {
3475 register struct obj *otmp, *otmp2;
3477 for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
3479 if (otmp->otyp == BOULDER) {
3480 /* this keeps otmp from being polymorphed in the
3481 same zap that the monster that held it is polymorphed */
3484 obj_extract_self(otmp);
3485 /* probably ought to give some "drop" message here */
3486 if (flooreffects(otmp, mtmp->mx, mtmp->my, ""))
3488 place_object(otmp, mtmp->mx, mtmp->my);
3496 /* sometimes an egg will be special */
3497 #define BREEDER_EGG (!rn2(77))
3500 * Determine if the given monster number can be hatched from an egg.
3501 * Return the monster number to use as the egg's corpsenm. Return
3502 * NON_PM if the given monster can't be hatched.
3505 can_be_hatched(mnum)
3508 /* ranger quest nemesis has the oviparous bit set, making it
3509 be possible to wish for eggs of that unique monster; turn
3510 such into ordinary eggs rather than forbidding them outright */
3511 if (mnum == PM_SCORPIUS)
3514 mnum = little_to_big(mnum);
3516 * Queen bees lay killer bee eggs (usually), but killer bees don't
3517 * grow into queen bees. Ditto for [winged-]gargoyles.
3519 if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE
3520 || (lays_eggs(&mons[mnum])
3522 || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
3527 /* type of egg laid by #sit; usually matches parent */
3529 egg_type_from_parent(mnum, force_ordinary)
3530 int mnum; /* parent monster; caller must handle lays_eggs() check */
3531 boolean force_ordinary;
3533 if (force_ordinary || !BREEDER_EGG) {
3534 if (mnum == PM_QUEEN_BEE)
3535 mnum = PM_KILLER_BEE;
3536 else if (mnum == PM_WINGED_GARGOYLE)
3542 /* decide whether an egg of the indicated monster type is viable;
3543 also used to determine whether an egg or tin can be created... */
3545 dead_species(m_idx, egg)
3551 /* generic eggs are unhatchable and have corpsenm of NON_PM */
3555 * For monsters with both baby and adult forms, genociding either
3556 * form kills all eggs of that monster. Monsters with more than
3557 * two forms (small->large->giant mimics) are more or less ignored;
3558 * fortunately, none of them have eggs. Species extinction due to
3559 * overpopulation does not kill eggs.
3561 alt_idx = egg ? big_to_little(m_idx) : m_idx;
3562 return (boolean) ((mvitals[m_idx].mvflags & G_GENOD) != 0
3563 || (mvitals[alt_idx].mvflags & G_GENOD) != 0);
3566 /* kill off any eggs of genocided monsters */
3569 struct obj *obj_list;
3573 for (otmp = obj_list; otmp; otmp = otmp->nobj)
3574 if (otmp->otyp == EGG) {
3575 if (dead_species(otmp->corpsenm, TRUE)) {
3577 * It seems we could also just catch this when
3578 * it attempted to hatch, so we wouldn't have to
3579 * search all of the objlists.. or stop all
3580 * hatch timers based on a corpsenm.
3584 #if 0 /* not used */
3585 } else if (otmp->otyp == TIN) {
3586 if (dead_species(otmp->corpsenm, FALSE))
3587 otmp->corpsenm = NON_PM; /* empty tin */
3588 } else if (otmp->otyp == CORPSE) {
3589 if (dead_species(otmp->corpsenm, FALSE))
3590 ; /* not yet implemented... */
3592 } else if (Has_contents(otmp)) {
3593 kill_eggs(otmp->cobj);
3597 /* kill all members of genocided species */
3599 kill_genocided_monsters()
3601 struct monst *mtmp, *mtmp2;
3606 * Called during genocide, and again upon level change. The latter
3607 * catches up with any migrating monsters as they finally arrive at
3608 * their intended destinations, so possessions get deposited there.
3610 * Chameleon handling:
3611 * 1) if chameleons have been genocided, destroy them
3612 * regardless of current form;
3613 * 2) otherwise, force every chameleon which is imitating
3614 * any genocided species to take on a new form.
3616 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
3618 if (DEADMONSTER(mtmp))
3620 mndx = monsndx(mtmp->data);
3621 kill_cham = (mtmp->cham >= LOW_PM
3622 && (mvitals[mtmp->cham].mvflags & G_GENOD));
3623 if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) {
3624 if (mtmp->cham >= LOW_PM && !kill_cham)
3625 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
3630 kill_eggs(mtmp->minvent);
3635 kill_eggs(migrating_objs);
3636 kill_eggs(level.buriedobjlist);
3640 golemeffects(mon, damtype, dam)
3641 register struct monst *mon;
3644 int heal = 0, slow = 0;
3646 if (mon->data == &mons[PM_FLESH_GOLEM]) {
3647 if (damtype == AD_ELEC)
3648 heal = (dam + 5) / 6;
3649 else if (damtype == AD_FIRE || damtype == AD_COLD)
3651 } else if (mon->data == &mons[PM_IRON_GOLEM]) {
3652 if (damtype == AD_ELEC)
3654 else if (damtype == AD_FIRE)
3660 if (mon->mspeed != MSLOW)
3661 mon_adjust_speed(mon, -1, (struct obj *) 0);
3664 if (mon->mhp < mon->mhpmax) {
3666 if (mon->mhp > mon->mhpmax)
3667 mon->mhp = mon->mhpmax;
3668 if (cansee(mon->mx, mon->my))
3670 pline("%s seems healthier.", Monnam(mon));
3672 pline("%s
\82Í
\8c³
\8bC
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81D", Monnam(mon));
3678 angry_guards(silent)
3682 int ct = 0, nct = 0, sct = 0, slct = 0;
3684 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3685 if (DEADMONSTER(mtmp))
3687 if (is_watch(mtmp->data) && mtmp->mpeaceful) {
3689 if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
3690 if (distu(mtmp->mx, mtmp->my) == 2)
3695 if (mtmp->msleeping || mtmp->mfrozen) {
3697 mtmp->msleeping = mtmp->mfrozen = 0;
3699 mtmp->mpeaceful = 0;
3703 if (!silent) { /* do we want pline msgs? */
3706 pline_The("guard%s wake%s up!", slct > 1 ? "s" : "",
3707 slct == 1 ? "s" : "");
3709 pline("
\94Ô
\95º
\82Í
\96Ú
\82ð
\8ao
\82Ü
\82µ
\82½
\81I");
3714 pline_The("guard%s get%s angry!", nct == 1 ? "" : "s",
3715 nct == 1 ? "s" : "");
3717 pline("
\94Ô
\95º
\82Í
\93{
\82Á
\82½
\81I");
3721 You_see("%sangry guard%s approaching!",
3722 sct == 1 ? "an " : "", sct > 1 ? "s" : "");
3724 You("
\93{
\82Á
\82½
\94Ô
\95º
\82ª
\8bß
\8añ
\82Á
\82Ä
\82
\82é
\82Ì
\82ð
\8c©
\82½
\81I");
3728 You_hear("the shrill sound of a guard's whistle.");
3730 You_hear("
\94Ô
\95º
\82Ì
\93J
\82ª
\82¯
\82½
\82½
\82Ü
\82µ
\82
\96Â
\82é
\82Ì
\82ð
\95·
\82¢
\82½
\81D");
3742 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3743 if (DEADMONSTER(mtmp))
3745 if (is_watch(mtmp->data))
3746 mtmp->mpeaceful = 1;
3751 mimic_hit_msg(mtmp, otyp)
3755 short ap = mtmp->mappearance;
3757 switch (mtmp->m_ap_type) {
3759 case M_AP_FURNITURE:
3763 if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
3765 pline("%s seems a more vivid %s than before.",
3766 The(simple_typename(ap)),
3767 c_obj_colors[objects[ap].oc_color]);
3769 pline("%s
\82Í
\88È
\91O
\82æ
\82è
\82æ
\82è
\91N
\82â
\82©
\82È%s
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D",
3770 The(simple_typename(ap)),
3771 c_obj_colors[objects[ap].oc_color]);
3780 struct permonst *mdat;
3783 boolean nonspecific = FALSE;
3784 boolean msg_given = FALSE;
3787 if (!olfaction(youmonst.data))
3789 mndx = monsndx(mdat);
3793 You("notice a bovine smell.");
3799 case PM_NEANDERTHAL:
3800 You("smell body odor.");
3809 case PM_HORNED_DEVIL:
3816 case PM_HUMAN_WEREJACKAL:
3817 case PM_HUMAN_WERERAT:
3818 case PM_HUMAN_WEREWOLF:
3823 You("detect an odor reminiscent of an animal's den.");
3827 case PM_PURPLE_WORM:
3830 case PM_STEAM_VORTEX:
3831 You("smell steam.");
3834 case PM_GREEN_SLIME:
3835 pline("%s stinks.", Something);
3838 case PM_VIOLET_FUNGUS:
3840 You("smell mushrooms.");
3843 /* These are here to avoid triggering the
3844 nonspecific treatment through the default case below*/
3845 case PM_WHITE_UNICORN:
3846 case PM_GRAY_UNICORN:
3847 case PM_BLACK_UNICORN:
3856 switch (mdat->mlet) {
3858 You("notice a dog smell.");
3862 You("smell a dragon!");
3866 pline("%s smells moldy.", Something);
3870 You("detect a%s odor reminiscent of a stable.",
3871 (mndx == PM_PONY) ? "n" : " strong");
3875 You("smell rotting flesh.");
3883 if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
3884 You("notice an attractive smell.");
3886 pline("A foul stench makes you feel a little nauseated.");
3893 return msg_given ? TRUE : FALSE;