1 /* NetHack 3.6 mon.c $NHDT-Date: 1556139724 2019/04/24 21:02:04 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.284 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Derek S. Ray, 2015. */
4 /* NetHack may be freely redistributed. See license for details. */
6 /* JNetHack Copyright */
7 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
8 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2019 */
9 /* JNetHack may be freely redistributed. See license for details. */
11 /* If you're using precompiled headers, you don't want this either */
20 STATIC_VAR boolean vamp_rise_msg, disintegested;
22 STATIC_DCL void FDECL(sanity_check_single_mon, (struct monst *, BOOLEAN_P,
24 STATIC_DCL boolean FDECL(restrap, (struct monst *));
25 STATIC_DCL long FDECL(mm_aggression, (struct monst *, struct monst *));
26 STATIC_DCL long FDECL(mm_displacement, (struct monst *, struct monst *));
27 STATIC_DCL int NDECL(pick_animal);
28 STATIC_DCL void FDECL(kill_eggs, (struct obj *));
29 STATIC_DCL int FDECL(pickvampshape, (struct monst *));
30 STATIC_DCL boolean FDECL(isspecmon, (struct monst *));
31 STATIC_DCL boolean FDECL(validspecmon, (struct monst *, int));
32 STATIC_DCL struct permonst *FDECL(accept_newcham_form, (int));
33 STATIC_DCL struct obj *FDECL(make_corpse, (struct monst *, unsigned));
34 STATIC_DCL void FDECL(m_detach, (struct monst *, struct permonst *));
35 STATIC_DCL void FDECL(lifesaved_monster, (struct monst *));
37 /* note: duplicated in dog.c */
38 #define LEVEL_SPECIFIC_NOCORPSE(mdat) \
39 (Is_rogue_level(&u.uz) \
40 || (level.flags.graveyard && is_undead(mdat) && rn2(3)))
43 /* part of the original warning code which was replaced in 3.3.1 */
44 const char *warnings[] = {
46 "white", "pink", "red", "ruby", "purple", "black"
48 "
\94\92\82¢", "
\83s
\83\93\83N
\90F
\82Ì", "
\90Ô
\82¢", "
\83\8b\83r
\81[
\90F
\82Ì", "
\8e\87\82Ì", "
\8d\95\82¢"
54 sanity_check_single_mon(mtmp, chk_geno, msg)
59 if (mtmp->data < &mons[LOW_PM] || mtmp->data >= &mons[NUMMONS]) {
60 impossible("illegal mon data %s; mnum=%d (%s)",
61 fmt_ptr((genericptr_t) mtmp->data), mtmp->mnum, msg);
63 int mndx = monsndx(mtmp->data);
65 if (mtmp->mnum != mndx) {
66 impossible("monster mnum=%d, monsndx=%d (%s)",
67 mtmp->mnum, mndx, msg);
70 if (DEADMONSTER(mtmp)) {
72 /* bad if not fmons list or if not vault guard */
73 if (strcmp(msg, "fmon") || !mtmp->isgd)
74 impossible("dead monster on %s; %s at <%d,%d>",
75 msg, mons[mndx].mname, mtmp->mx, mtmp->my);
79 if (chk_geno && (mvitals[mndx].mvflags & G_GENOD) != 0)
80 impossible("genocided %s in play (%s)", mons[mndx].mname, msg);
82 if (mtmp->isshk && !has_eshk(mtmp))
83 impossible("shk without eshk (%s)", msg);
84 if (mtmp->ispriest && !has_epri(mtmp))
85 impossible("priest without epri (%s)", msg);
86 if (mtmp->isgd && !has_egd(mtmp))
87 impossible("guard without egd (%s)", msg);
88 if (mtmp->isminion && !has_emin(mtmp))
89 impossible("minion without emin (%s)", msg);
90 /* guardian angel on astral level is tame but has emin rather than edog */
91 if (mtmp->mtame && !has_edog(mtmp) && !mtmp->isminion)
92 impossible("pet without edog (%s)", msg);
99 struct monst *mtmp, *m;
101 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
102 /* dead monsters should still have sane data */
103 sanity_check_single_mon(mtmp, TRUE, "fmon");
104 if (DEADMONSTER(mtmp) && !mtmp->isgd)
107 x = mtmp->mx, y = mtmp->my;
108 if (!isok(x, y) && !(mtmp->isgd && x == 0 && y == 0)) {
109 impossible("mon (%s) claims to be at <%d,%d>?",
110 fmt_ptr((genericptr_t) mtmp), x, y);
111 } else if (mtmp == u.usteed) {
112 /* steed is in fmon list but not on the map; its
113 <mx,my> coordinates should match hero's location */
114 if (x != u.ux || y != u.uy)
115 impossible("steed (%s) claims to be at <%d,%d>?",
116 fmt_ptr((genericptr_t) mtmp), x, y);
117 } else if (level.monsters[x][y] != mtmp) {
118 impossible("mon (%s) at <%d,%d> is not there!",
119 fmt_ptr((genericptr_t) mtmp), x, y);
120 } else if (mtmp->wormno) {
121 sanity_check_worm(mtmp);
125 for (x = 1; x < COLNO; x++)
126 for (y = 0; y < ROWNO; y++)
127 if ((mtmp = level.monsters[x][y]) != 0) {
128 for (m = fmon; m; m = m->nmon)
132 impossible("map mon (%s) at <%d,%d> not in fmon list!",
133 fmt_ptr((genericptr_t) mtmp), x, y);
134 else if (mtmp == u.usteed)
135 impossible("steed (%s) is on the map at <%d,%d>!",
136 fmt_ptr((genericptr_t) mtmp), x, y);
137 else if ((mtmp->mx != x || mtmp->my != y)
138 && mtmp->data != &mons[PM_LONG_WORM])
139 impossible("map mon (%s) at <%d,%d> is found at <%d,%d>?",
140 fmt_ptr((genericptr_t) mtmp),
141 mtmp->mx, mtmp->my, x, y);
144 for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) {
145 sanity_check_single_mon(mtmp, FALSE, "migr");
150 /* convert the monster index of an undead to its living counterpart */
152 undead_to_corpse(mndx)
156 case PM_KOBOLD_ZOMBIE:
157 case PM_KOBOLD_MUMMY:
160 case PM_DWARF_ZOMBIE:
164 case PM_GNOME_ZOMBIE:
177 case PM_VAMPIRE_LORD:
179 case PM_VAMPIRE_MAGE:
181 case PM_HUMAN_ZOMBIE:
185 case PM_GIANT_ZOMBIE:
189 case PM_ETTIN_ZOMBIE:
199 /* Convert the monster index of some monsters (such as quest guardians)
200 * to their generic species type.
202 * Return associated character class monster, rather than species
210 /* Quest guardians */
212 mndx = mode ? PM_ARCHEOLOGIST : PM_HUMAN;
215 mndx = mode ? PM_BARBARIAN : PM_HUMAN;
218 mndx = mode ? PM_CAVEMAN : PM_HUMAN;
221 mndx = mode ? PM_HEALER : PM_HUMAN;
224 mndx = mode ? PM_KNIGHT : PM_HUMAN;
227 mndx = mode ? PM_MONK : PM_HUMAN;
230 mndx = mode ? PM_PRIEST : PM_HUMAN;
233 mndx = mode ? PM_RANGER : PM_HUMAN;
236 mndx = mode ? PM_ROGUE : PM_HUMAN;
239 mndx = mode ? PM_SAMURAI : PM_HUMAN;
242 mndx = mode ? PM_TOURIST : PM_HUMAN;
245 mndx = mode ? PM_WIZARD : PM_HUMAN;
248 mndx = mode ? PM_VALKYRIE : PM_HUMAN;
251 if (mndx >= LOW_PM && mndx < NUMMONS) {
252 struct permonst *ptr = &mons[mndx];
256 else if (is_elf(ptr))
258 else if (is_dwarf(ptr))
260 else if (is_gnome(ptr))
262 else if (is_orc(ptr))
270 /* return monster index if chameleon, or NON_PM if not */
278 * As of 3.6.0 we just check M2_SHAPESHIFTER instead of having a
279 * big switch statement with hardcoded shapeshifter types here.
281 if (mndx >= LOW_PM && is_shapeshifter(&mons[mndx]))
286 /* for deciding whether corpse will carry along full monster data */
287 #define KEEPTRAITS(mon) \
288 ((mon)->isshk || (mon)->mtame || unique_corpstat((mon)->data) \
289 || is_reviver((mon)->data) \
290 /* normally quest leader will be unique, */ \
291 /* but he or she might have been polymorphed */ \
292 || (mon)->m_id == quest_status.leader_m_id \
293 /* special cancellation handling for these */ \
294 || (dmgtype((mon)->data, AD_SEDU) || dmgtype((mon)->data, AD_SSEX)))
296 /* Creates a monster corpse, a "special" corpse, or nothing if it doesn't
297 * leave corpses. Monsters which leave "special" corpses should have
298 * G_NOCORPSE set in order to prevent wishing for one, finding tins of one,
301 STATIC_OVL struct obj *
302 make_corpse(mtmp, corpseflags)
303 register struct monst *mtmp;
304 unsigned corpseflags;
306 register struct permonst *mdat = mtmp->data;
308 struct obj *obj = (struct obj *) 0;
309 struct obj *otmp = (struct obj *) 0;
310 int x = mtmp->mx, y = mtmp->my;
311 int mndx = monsndx(mdat);
312 unsigned corpstatflags = corpseflags;
313 boolean burythem = ((corpstatflags & CORPSTAT_BURIED) != 0);
317 case PM_SILVER_DRAGON:
319 case PM_SHIMMERING_DRAGON:
322 case PM_ORANGE_DRAGON:
323 case PM_WHITE_DRAGON:
324 case PM_BLACK_DRAGON:
326 case PM_GREEN_DRAGON:
327 case PM_YELLOW_DRAGON:
328 /* Make dragon scales. This assumes that the order of the
329 dragons is the same as the order of the scales. */
330 if (!rn2(mtmp->mrevived ? 20 : 3)) {
331 num = GRAY_DRAGON_SCALES + monsndx(mdat) - PM_GRAY_DRAGON;
332 obj = mksobj_at(num, x, y, FALSE, FALSE);
334 obj->cursed = obj->blessed = FALSE;
337 case PM_WHITE_UNICORN:
338 case PM_GRAY_UNICORN:
339 case PM_BLACK_UNICORN:
340 if (mtmp->mrevived && rn2(2)) {
343 pline("%s recently regrown horn crumbles to dust.",
344 s_suffix(Monnam(mtmp)));
346 pline("
\8dÅ
\8bß
\8dÄ
\90¶
\82µ
\82½%s
\82Ì
\8ap
\82Í
\95²
\81X
\82É
\82È
\82Á
\82½
\81D",
350 obj = mksobj_at(UNICORN_HORN, x, y, TRUE, FALSE);
351 if (obj && mtmp->mrevived)
352 obj->degraded_horn = 1;
356 (void) mksobj_at(WORM_TOOTH, x, y, TRUE, FALSE);
359 case PM_VAMPIRE_LORD:
360 /* include mtmp in the mkcorpstat() call */
361 num = undead_to_corpse(mndx);
362 corpstatflags |= CORPSTAT_INIT;
363 obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
364 obj->age -= 100; /* this is an *OLD* corpse */
366 case PM_KOBOLD_MUMMY:
374 case PM_KOBOLD_ZOMBIE:
375 case PM_DWARF_ZOMBIE:
376 case PM_GNOME_ZOMBIE:
379 case PM_HUMAN_ZOMBIE:
380 case PM_GIANT_ZOMBIE:
381 case PM_ETTIN_ZOMBIE:
382 num = undead_to_corpse(mndx);
383 corpstatflags |= CORPSTAT_INIT;
384 obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
385 obj->age -= 100; /* this is an *OLD* corpse */
390 obj = mksobj_at(IRON_CHAIN, x, y, TRUE, FALSE);
391 free_mname(mtmp); /* don't christen obj */
394 num = d(2, 4); /* very low chance of creating all glass gems */
396 obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE);
400 obj = mksobj_at(ROCK, x, y, FALSE, FALSE);
401 obj->quan = (long) (rn2(20) + 50);
402 obj->owt = weight(obj);
406 corpstatflags &= ~CORPSTAT_INIT;
408 mkcorpstat(STATUE, (struct monst *) 0, mdat, x, y, corpstatflags);
413 obj = mksobj_at(QUARTERSTAFF, x, y, TRUE, FALSE);
417 case PM_LEATHER_GOLEM:
420 obj = mksobj_at(LEATHER_ARMOR, x, y, TRUE, FALSE);
424 /* Good luck gives more coins */
425 obj = mkgold((long) (200 - rnl(101)), x, y);
431 obj = mksobj_at(SCR_BLANK_PAPER, x, y, TRUE, FALSE);
434 /* expired puddings will congeal into a large blob;
435 like dragons, relies on the order remaining consistent */
437 case PM_BROWN_PUDDING:
439 case PM_BLACK_PUDDING:
440 /* we have to do this here because most other places
441 expect there to be an object coming back; not this one */
442 obj = mksobj_at(GLOB_OF_BLACK_PUDDING - (PM_BLACK_PUDDING - mndx),
445 while (obj && (otmp = obj_nexto(obj)) != (struct obj *) 0) {
446 pudding_merge_message(obj, otmp);
447 obj = obj_meld(&obj, &otmp);
453 if (mvitals[mndx].mvflags & G_NOCORPSE) {
454 return (struct obj *) 0;
456 corpstatflags |= CORPSTAT_INIT;
457 /* preserve the unique traits of some creatures */
458 obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0,
459 mdat, x, y, corpstatflags);
463 (void) bury_an_obj(obj, &dealloc);
465 return dealloc ? (struct obj *) 0 : obj;
470 /* All special cases should precede the G_NOCORPSE check */
473 return (struct obj *) 0;
475 /* if polymorph or undead turning has killed this monster,
476 prevent the same attack beam from hitting its corpse */
477 if (context.bypasses)
481 obj = oname(obj, MNAME(mtmp));
483 /* Avoid "It was hidden under a green mold corpse!"
484 * during Blind combat. An unseen monster referred to as "it"
485 * could be killed and leave a corpse. If a hider then hid
486 * underneath it, you could be told the corpse type of a
487 * monster that you never knew was there without this.
488 * The code in hitmu() substitutes the word "something"
489 * if the corpse's obj->dknown is 0.
491 if (Blind && !sensemon(mtmp))
499 /* check mtmp and water/lava for compatibility, 0 (survived), 1 (died) */
502 register struct monst *mtmp;
504 boolean inpool, inlava, infountain;
506 /* [what about ceiling clingers?] */
507 inpool = (is_pool(mtmp->mx, mtmp->my)
508 && (!(is_flyer(mtmp->data) || is_floater(mtmp->data))
509 /* there's no "above the surface" on the plane of water */
510 || Is_waterlevel(&u.uz)));
511 inlava = (is_lava(mtmp->mx, mtmp->my)
512 && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
513 infountain = IS_FOUNTAIN(levl[mtmp->mx][mtmp->my].typ);
515 /* Flying and levitation keeps our steed out of the liquid
516 (but not water-walking or swimming; note: if hero is in a
517 water location on the Plane of Water, flight and levitating
518 are blocked so this (Flying || Levitation) test fails there
519 and steed will be subject to water effects, as intended) */
520 if (mtmp == u.usteed && (Flying || Levitation))
523 /* Gremlin multiplying won't go on forever since the hit points
524 * keep going down, and when it gets to 1 hit point the clone
525 * function will fail.
527 if (mtmp->data == &mons[PM_GREMLIN] && (inpool || infountain) && rn2(3)) {
528 if (split_mon(mtmp, (struct monst *) 0))
529 dryup(mtmp->mx, mtmp->my, FALSE);
531 water_damage_chain(mtmp->minvent, FALSE);
533 } else if (mtmp->data == &mons[PM_IRON_GOLEM] && inpool && !rn2(5)) {
536 if (cansee(mtmp->mx, mtmp->my))
538 pline("%s rusts.", Monnam(mtmp));
540 pline("%s
\82Í
\8eK
\82Ñ
\82½
\81D", Monnam(mtmp));
542 if (mtmp->mhpmax > dam)
544 if (DEADMONSTER(mtmp)) {
546 if (DEADMONSTER(mtmp))
549 water_damage_chain(mtmp->minvent, FALSE);
555 * Lava effects much as water effects. Lava likers are able to
556 * protect their stuff. Fire resistant monsters can only protect
559 if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) {
560 /* not fair...? hero doesn't automatically teleport away
561 from lava, just from water */
562 if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) {
563 if (rloc(mtmp, TRUE))
566 if (!resists_fire(mtmp)) {
567 if (cansee(mtmp->mx, mtmp->my)) {
568 struct attack *dummy = &mtmp->data->mattk[0];
569 const char *how = on_fire(mtmp->data, dummy);
572 pline("%s %s.", Monnam(mtmp),
573 !strcmp(how, "boiling") ? "boils away"
574 : !strcmp(how, "melting") ? "melts away"
575 : "burns to a crisp");
576 #else /*mon.c:on_fire()
\82Ì
\95Ô
\82è
\92l*/
577 pline("%s
\82Í%s
\82½
\81D", Monnam(mtmp),
578 !strcmp(how, "
\95¦
\93«
\82µ
\82½") ? "
\95¦
\93«
\82µ"
579 : !strcmp(how, "
\97n
\82¯
\82½") ? "
\97n
\82¯
\82½"
580 : "
\94R
\82¦
\82Ä
\83p
\83\8a\83p
\83\8a\82É
\82È
\82Á");
583 /* unlike fire -> melt ice -> pool, there's no way for the
584 hero to create lava beneath a monster, so the !mon_moving
585 case is not expected to happen (and we haven't made a
586 player-against-monster variation of the message above) */
587 if (context.mon_moving)
590 xkilled(mtmp, XKILL_NOMSG);
593 if (DEADMONSTER(mtmp)) {
594 if (cansee(mtmp->mx, mtmp->my))
596 pline("%s surrenders to the fire.", Monnam(mtmp));
598 pline("%s
\82Í
\89\8a\82É
\93Û
\82Ü
\82ê
\82½
\81D", Monnam(mtmp));
600 } else if (cansee(mtmp->mx, mtmp->my))
602 pline("%s burns slightly.", Monnam(mtmp));
604 pline("%s
\82Í
\82¿
\82å
\82Á
\82Æ
\8fÅ
\82°
\82½
\81D", Monnam(mtmp));
606 if (!DEADMONSTER(mtmp)) {
607 (void) fire_damage_chain(mtmp->minvent, FALSE, FALSE,
609 (void) rloc(mtmp, FALSE);
615 /* Most monsters drown in pools. flooreffects() will take care of
616 * water damage to dead monsters' inventory, but survivors need to
617 * be handled here. Swimmers are able to protect their stuff...
619 if (!is_clinger(mtmp->data) && !is_swimmer(mtmp->data)
620 && !amphibious(mtmp->data)) {
621 /* like hero with teleport intrinsic or spell, teleport away
623 if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) {
624 if (rloc(mtmp, TRUE))
627 if (cansee(mtmp->mx, mtmp->my)) {
628 if (context.mon_moving)
630 pline("%s drowns.", Monnam(mtmp));
632 pline("%s
\82Í
\93M
\82ê
\82½
\81D", Monnam(mtmp));
634 /* hero used fire to melt ice that monster was on */
635 You("drown %s.", mon_nam(mtmp));
637 if (u.ustuck && u.uswallow && u.ustuck == mtmp) {
638 /* This can happen after a purple worm plucks you off a
639 flying steed while you are over water. */
641 pline("%s sinks as %s rushes in and flushes you out.",
642 Monnam(mtmp), hliquid("water"));
643 #else /*hliquid
\82Í
\95s
\8e©
\91R
\82É
\82È
\82é
\82Ì
\82Å
\82Æ
\82è
\82 \82¦
\82¸
\8eg
\82í
\82È
\82¢*/
644 pline("%s
\82Í
\90\85\97¬
\82É
\92¾
\82Ý
\81D
\82 \82È
\82½
\82ð
\93f
\82«
\8fo
\82µ
\82½
\81D",
648 if (context.mon_moving)
651 xkilled(mtmp, XKILL_NOMSG);
652 if (!DEADMONSTER(mtmp)) {
653 water_damage_chain(mtmp->minvent, FALSE);
654 (void) rloc(mtmp, FALSE);
660 /* but eels have a difficult time outside */
661 if (mtmp->data->mlet == S_EEL && !Is_waterlevel(&u.uz)) {
662 /* as mhp gets lower, the rate of further loss slows down */
663 if (mtmp->mhp > 1 && rn2(mtmp->mhp) > rn2(8))
665 monflee(mtmp, 2, FALSE, FALSE);
675 int mmove = mon->data->mmove;
678 /* Note: MSLOW's `+ 1' prevents slowed speed 1 getting reduced to 0;
679 * MFAST's `+ 2' prevents hasted speed 1 from becoming a no-op;
680 * both adjustments have negligible effect on higher speeds.
682 if (mon->mspeed == MSLOW)
683 mmove = (2 * mmove + 1) / 3;
684 else if (mon->mspeed == MFAST)
685 mmove = (4 * mmove + 2) / 3;
687 if (mon == u.usteed && u.ugallop && context.mv) {
688 /* increase movement by a factor of 1.5; also increase variance of
689 movement speed (if it's naturally 24, we don't want it to always
691 mmove = ((rn2(2) ? 4 : 5) * mmove) / 3;
694 /* Randomly round the monster's speed to a multiple of NORMAL_SPEED.
695 This makes it impossible for the player to predict when they'll get
696 a free turn (thus preventing exploits like "melee kiting"), while
697 retaining guarantees about shopkeepers not being outsped by a
698 normal-speed player, normal-speed players being unable to open up
699 a gap when fleeing a normal-speed monster, etc. */
700 mmove_adj = mmove % NORMAL_SPEED;
702 if (rn2(NORMAL_SPEED) < mmove_adj)
703 mmove += NORMAL_SPEED;
708 /* actions that happen once per ``turn'', regardless of each
709 individual monster's metabolism; some of these might need to
710 be reclassified to occur more in proportion with movement rate */
716 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
717 if (DEADMONSTER(mtmp))
720 /* must check non-moving monsters once/turn in case they managed
721 to end up in water or lava; note: when not in liquid they regen,
722 shape-shift, timeout temporary maladies just like other monsters */
723 if (mtmp->data->mmove == 0) {
724 if (vision_full_recalc)
730 /* regenerate hit points */
731 mon_regen(mtmp, FALSE);
733 /* possibly polymorph shapechangers and lycanthropes */
734 if (mtmp->cham >= LOW_PM)
735 decide_to_shapeshift(mtmp, (canspotmon(mtmp)
736 || (u.uswallow && mtmp == u.ustuck))
740 /* gradually time out temporary problems */
741 if (mtmp->mblinded && !--mtmp->mblinded)
743 if (mtmp->mfrozen && !--mtmp->mfrozen)
745 if (mtmp->mfleetim && !--mtmp->mfleetim)
748 /* FIXME: mtmp->mlstmv ought to be updated here */
755 register struct monst *mtmp, *nmtmp;
756 register boolean somebody_can_move = FALSE;
759 * Some of you may remember the former assertion here that
760 * because of deaths and other actions, a simple one-pass
761 * algorithm wasn't possible for movemon. Deaths are no longer
762 * removed to the separate list fdmon; they are simply left in
763 * the chain with hit points <= 0, to be cleaned up at the end
766 * The only other actions which cause monsters to be removed from
767 * the chain are level migrations and losedogs(). I believe losedogs()
768 * is a cleanup routine not associated with monster movements, and
769 * monsters can only affect level migrations on themselves, not others
770 * (hence the fetching of nmon before moving the monster). Currently,
771 * monsters can jump into traps, read cursed scrolls of teleportation,
772 * and drink cursed potions of raise level to change levels. These are
773 * all reflexive at this point. Should one monster be able to level
774 * teleport another, this scheme would have problems.
777 for (mtmp = fmon; mtmp; mtmp = nmtmp) {
778 /* end monster movement early if hero is flagged to leave the level */
781 /* or if the program has lost contact with the user */
782 || program_state.done_hup
785 somebody_can_move = FALSE;
789 /* one dead monster needs to perform a move after death: vault
790 guard whose temporary corridor is still on the map; live
791 guards who have led the hero back to civilization get moved
792 off the map too; gd_move() decides whether the temporary
793 corridor can be removed and guard discarded (via clearing
794 mon->isgd flag so that dmonsfree() will get rid of mon) */
795 if (mtmp->isgd && !mtmp->mx) {
796 /* parked at <0,0>; eventually isgd should get set to false */
797 if (monstermoves > mtmp->mlstmv) {
798 (void) gd_move(mtmp);
799 mtmp->mlstmv = monstermoves;
803 if (DEADMONSTER(mtmp))
806 /* Find a monster that we have not treated yet. */
807 if (mtmp->movement < NORMAL_SPEED)
810 mtmp->movement -= NORMAL_SPEED;
811 if (mtmp->movement >= NORMAL_SPEED)
812 somebody_can_move = TRUE;
814 if (vision_full_recalc)
815 vision_recalc(0); /* vision! */
817 /* reset obj bypasses before next monster moves */
818 if (context.bypasses)
824 /* after losing equipment, try to put on replacement */
825 if (mtmp->misc_worn_check & I_SPECIAL) {
828 mtmp->misc_worn_check &= ~I_SPECIAL;
829 oldworn = mtmp->misc_worn_check;
830 m_dowear(mtmp, FALSE);
831 if (mtmp->misc_worn_check != oldworn || !mtmp->mcanmove)
835 if (is_hider(mtmp->data)) {
836 /* unwatched mimics and piercers may hide again [MRS] */
839 if (M_AP_TYPE(mtmp) == M_AP_FURNITURE
840 || M_AP_TYPE(mtmp) == M_AP_OBJECT)
842 if (mtmp->mundetected)
844 } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected
845 && (mtmp->mflee || distu(mtmp->mx, mtmp->my) > 2)
846 && !canseemon(mtmp) && !rn2(4)) {
847 /* some eels end up stuck in isolated pools, where they
848 can't--or at least won't--move, so they never reach
849 their post-move chance to re-hide */
854 /* continue if the monster died fighting */
855 if (Conflict && !mtmp->iswiz && mtmp->mcansee) {
857 * Conflict does not take effect in the first round.
858 * Therefore, A monster when stepping into the area will
859 * get to swing at you.
861 * The call to fightm() must be _last_. The monster might
862 * have died if it returns 1.
864 if (couldsee(mtmp->mx, mtmp->my)
865 && (distu(mtmp->mx, mtmp->my) <= BOLT_LIM * BOLT_LIM)
867 continue; /* mon might have died */
869 if (dochugw(mtmp)) /* otherwise just move the monster */
873 if (any_light_source())
874 vision_full_recalc = 1; /* in case a mon moved with a light source */
875 /* reset obj bypasses after last monster has moved */
876 if (context.bypasses)
879 /* remove dead monsters; dead vault guard will be left at <0,0>
880 if temporary corridor out of vault hasn't been removed yet */
883 /* a monster may have levteleported player -dlc */
886 /* changed levels, so these monsters are dormant */
887 somebody_can_move = FALSE;
890 return somebody_can_move;
893 #define mstoning(obj) \
894 (ofood(obj) && (touch_petrifies(&mons[(obj)->corpsenm]) \
895 || (obj)->corpsenm == PM_MEDUSA))
898 * Maybe eat a metallic object (not just gold).
899 * Return value: 0 => nothing happened, 1 => monster ate something,
900 * 2 => monster died (it must have grown into a genocided form, but
901 * that can't happen at present because nothing which eats objects
902 * has young and old forms).
906 register struct monst *mtmp;
908 register struct obj *otmp;
909 struct permonst *ptr;
910 int poly, grow, heal, mstone;
912 /* If a pet, eating is handled separately, in dog.c */
916 /* Eats topmost metal object if it is there */
917 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp;
918 otmp = otmp->nexthere) {
919 /* Don't eat indigestible/choking/inappropriate objects */
920 if ((mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp))
921 || (otmp->otyp == AMULET_OF_STRANGULATION)
922 || (otmp->otyp == RIN_SLOW_DIGESTION))
924 if (is_metallic(otmp) && !obj_resists(otmp, 5, 95)
925 && touch_artifact(otmp, mtmp)) {
926 if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) {
927 if (canseemon(mtmp) && flags.verbose) {
929 pline("%s eats %s!", Monnam(mtmp),
930 distant_name(otmp, doname));
932 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
933 distant_name(otmp,doname));
936 /* The object's rustproofing is gone now */
937 otmp->oerodeproof = 0;
939 if (canseemon(mtmp) && flags.verbose) {
941 pline("%s spits %s out in disgust!", Monnam(mtmp),
942 distant_name(otmp, doname));
944 pline("%s
\82Í%s
\82ð
\83y
\83b
\82Æ
\93f
\82«
\8fo
\82µ
\82½
\81I", Monnam(mtmp),
945 distant_name(otmp,doname));
949 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
951 pline("%s eats %s!", Monnam(mtmp),
952 distant_name(otmp, doname));
954 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
955 distant_name(otmp,doname));
957 else if (flags.verbose)
959 You_hear("a crunching sound.");
961 You_hear("
\83o
\83\8a\83o
\83\8a\82Æ
\90H
\82×
\82é
\89¹
\82ð
\95·
\82¢
\82½
\81D");
962 mtmp->meating = otmp->owt / 2 + 1;
963 /* Heal up to the object's weight in hp */
964 if (mtmp->mhp < mtmp->mhpmax) {
965 mtmp->mhp += objects[otmp->otyp].oc_weight;
966 if (mtmp->mhp > mtmp->mhpmax)
967 mtmp->mhp = mtmp->mhpmax;
972 } else if (otmp == uchain) {
973 unpunish(); /* frees uchain */
975 poly = polyfodder(otmp);
976 grow = mlevelgain(otmp);
977 heal = mhealup(otmp);
978 mstone = mstoning(otmp);
982 if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
985 ptr = grow_up(mtmp, (struct monst *) 0);
987 if (poly_when_stoned(ptr)) {
990 } else if (!resists_ston(mtmp)) {
993 pline("%s turns to stone!", Monnam(mtmp));
995 pline("%s
\82Í
\90Î
\82É
\82È
\82Á
\82½
\81I", Monnam(mtmp));
997 ptr = (struct permonst *) 0;
1000 mtmp->mhp = mtmp->mhpmax;
1003 return 2; /* it died */
1005 /* Left behind a pile? */
1007 (void) mksobj_at(ROCK, mtmp->mx, mtmp->my, TRUE, FALSE);
1008 newsym(mtmp->mx, mtmp->my);
1016 /* monster eats a pile of objects */
1018 meatobj(mtmp) /* for gelatinous cubes */
1021 struct obj *otmp, *otmp2;
1022 struct permonst *ptr, *original_ptr = mtmp->data;
1023 int poly, grow, heal, eyes, count = 0, ecount = 0;
1027 /* If a pet, eating is handled separately, in dog.c */
1031 /* eat organic objects, including cloth and wood, if present;
1032 engulf others, except huge rocks and metal attached to player
1033 [despite comment at top, doesn't assume that eater is a g.cube] */
1034 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
1035 otmp2 = otmp->nexthere;
1037 /* touch sensitive items */
1038 if (otmp->otyp == CORPSE && is_rider(&mons[otmp->corpsenm])) {
1039 /* Rider corpse isn't just inedible; can't engulf it either */
1040 (void) revive_corpse(otmp);
1042 /* untouchable (or inaccessible) items */
1043 } else if ((otmp->otyp == CORPSE
1044 && touch_petrifies(&mons[otmp->corpsenm])
1045 && !resists_ston(mtmp))
1046 /* don't engulf boulders and statues or ball&chain */
1047 || otmp->oclass == ROCK_CLASS
1048 || otmp == uball || otmp == uchain
1049 /* normally mtmp won't have stepped onto scare monster
1050 scroll, but if it does, don't eat or engulf that
1051 (note: scrolls inside eaten containers will still
1053 || otmp->otyp == SCR_SCARE_MONSTER) {
1054 /* do nothing--neither eaten nor engulfed */
1057 /* inedible items -- engulf these */
1058 } else if (!is_organic(otmp) || obj_resists(otmp, 5, 95)
1059 || !touch_artifact(otmp, mtmp)
1060 /* redundant due to non-organic composition but
1061 included for emphasis */
1062 || (otmp->otyp == AMULET_OF_STRANGULATION
1063 || otmp->otyp == RIN_SLOW_DIGESTION)
1064 /* cockatrice corpses handled above; this
1065 touch_petrifies() check catches eggs */
1066 || ((otmp->otyp == CORPSE || otmp->otyp == EGG
1068 && ((touch_petrifies(&mons[otmp->corpsenm])
1069 && !resists_ston(mtmp))
1070 || (otmp->corpsenm == PM_GREEN_SLIME
1071 && !slimeproof(mtmp->data))))) {
1076 Sprintf(buf, "%s engulfs %s.", Monnam(mtmp),
1077 distant_name(otmp, doname));
1079 Sprintf(buf, "%s
\82Í%s
\82ð
\88ù
\82Ý
\8d\9e\82ñ
\82¾
\81D", Monnam(mtmp),
1080 distant_name(otmp,doname));
1082 else if (ecount == 2)
1084 Sprintf(buf, "%s engulfs several objects.", Monnam(mtmp));
1086 Sprintf(buf, "%s
\82Í
\82¢
\82
\82Â
\82©
\82Ì
\95¨
\82ð
\88ù
\82Ý
\8d\9e\82ñ
\82¾
\81D", Monnam(mtmp));
1087 obj_extract_self(otmp);
1088 (void) mpickobj(mtmp, otmp); /* slurp */
1090 /* lastly, edible items; yum! */
1094 if (cansee(mtmp->mx, mtmp->my)) {
1097 pline("%s eats %s!", Monnam(mtmp),
1098 distant_name(otmp, doname));
1100 pline("%s
\82Í%s
\82ð
\90H
\82×
\82Ä
\82¢
\82é
\81I", Monnam(mtmp),
1101 distant_name(otmp, doname));
1103 /* give this one even if !verbose */
1104 if (otmp->oclass == SCROLL_CLASS
1105 && !strcmpi(OBJ_DESCR(objects[otmp->otyp]), "YUM YUM"))
1106 pline("Yum%c", otmp->blessed ? '!' : '.');
1110 You_hear("a slurping sound.");
1112 You_hear("
\82²
\82
\82ñ
\82Æ
\88ù
\82Ý
\8d\9e\82Þ
\89¹
\82ð
\95·
\82¢
\82½
\81D");
1114 /* Heal up to the object's weight in hp */
1115 if (mtmp->mhp < mtmp->mhpmax) {
1116 mtmp->mhp += objects[otmp->otyp].oc_weight;
1117 if (mtmp->mhp > mtmp->mhpmax)
1118 mtmp->mhp = mtmp->mhpmax;
1120 if (Has_contents(otmp)) {
1121 register struct obj *otmp3;
1123 /* contents of eaten containers become engulfed; this
1124 is arbitrary, but otherwise g.cubes are too powerful */
1125 while ((otmp3 = otmp->cobj) != 0) {
1126 obj_extract_self(otmp3);
1127 if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) {
1128 otmp3->age = monstermoves - otmp3->age;
1129 start_corpse_timeout(otmp3);
1131 (void) mpickobj(mtmp, otmp3);
1134 poly = polyfodder(otmp);
1135 grow = mlevelgain(otmp);
1136 heal = mhealup(otmp);
1137 eyes = (otmp->otyp == CARROT);
1138 delobj(otmp); /* munch */
1141 if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
1144 ptr = grow_up(mtmp, (struct monst *) 0);
1146 mtmp->mhp = mtmp->mhpmax;
1148 if ((eyes || heal) && !mtmp->mcansee)
1149 mcureblindness(mtmp, canseemon(mtmp));
1150 /* in case it polymorphed or died */
1151 if (ptr != original_ptr)
1152 return !ptr ? 2 : 1;
1155 /* Engulf & devour is instant, so don't set meating */
1157 newsym(mtmp->mx, mtmp->my);
1161 if (cansee(mtmp->mx, mtmp->my) && flags.verbose && buf[0])
1163 else if (flags.verbose)
1165 You_hear("%s slurping sound%s.",
1166 (ecount == 1) ? "a" : "several", plur(ecount));
1168 You_hear("
\83Y
\83\8b\83Y
\83\8b\82Æ
\82¢
\82¤
\89¹
\82ð
\95·
\82¢
\82½
\81D");
1171 return (count > 0 || ecount > 0) ? 1 : 0;
1176 register struct monst *mtmp;
1178 register struct obj *gold;
1183 if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) {
1185 mat_idx = objects[gold->otyp].oc_material;
1187 obj_extract_self(gold);
1188 add_to_minv(mtmp, gold);
1189 if (cansee(mtmp->mx, mtmp->my)) {
1190 if (flags.verbose && !mtmp->isgd)
1192 pline("%s picks up some %s.", Monnam(mtmp),
1193 mat_idx == GOLD ? "gold" : "money");
1195 pline("%s
\82Í
\82¨
\8bà
\82ð
\8fE
\82Á
\82½
\81D", Monnam(mtmp));
1197 newsym(mtmp->mx, mtmp->my);
1203 mpickstuff(mtmp, str)
1204 register struct monst *mtmp;
1205 register const char *str;
1207 register struct obj *otmp, *otmp2, *otmp3;
1210 /* prevent shopkeepers from leaving the door of their shop */
1211 if (mtmp->isshk && inhishop(mtmp))
1214 for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
1215 otmp2 = otmp->nexthere;
1216 /* Nymphs take everything. Most monsters don't pick up corpses. */
1217 if (!str ? searches_for_item(mtmp, otmp)
1218 : !!(index(str, otmp->oclass))) {
1219 if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
1220 /* let a handful of corpse types thru to can_carry() */
1221 && !touch_petrifies(&mons[otmp->corpsenm])
1222 && otmp->corpsenm != PM_LIZARD
1223 && !acidic(&mons[otmp->corpsenm]))
1225 if (!touch_artifact(otmp, mtmp))
1227 carryamt = can_carry(mtmp, otmp);
1230 if (is_pool(mtmp->mx, mtmp->my))
1232 /* handle cases where the critter can only get some */
1234 if (carryamt != otmp->quan) {
1235 otmp3 = splitobj(otmp, carryamt);
1237 if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
1239 pline("%s picks up %s.", Monnam(mtmp),
1240 (distu(mtmp->mx, mtmp->my) <= 5)
1242 : distant_name(otmp3, doname));
1244 pline("%s
\82Í%s
\82ð
\8fE
\82Á
\82½
\81D", Monnam(mtmp),
1245 (distu(mtmp->mx, mtmp->my) <= 5)
1247 : distant_name(otmp3, doname));
1249 obj_extract_self(otmp3); /* remove from floor */
1250 (void) mpickobj(mtmp, otmp3); /* may merge and free otmp3 */
1251 m_dowear(mtmp, FALSE);
1252 newsym(mtmp->mx, mtmp->my);
1253 return TRUE; /* pick only one object */
1266 for (obj = mtmp->minvent; obj; obj = obj->nobj) {
1267 if (obj->otyp != BOULDER || !throws_rocks(mtmp->data))
1268 curload += obj->owt;
1280 /* Base monster carrying capacity is equal to human maximum
1281 * carrying capacity, or half human maximum if not strong.
1282 * (for a polymorphed player, the value used would be the
1283 * non-polymorphed carrying capacity instead of max/half max).
1284 * This is then modified by the ratio between the monster weights
1285 * and human weights. Corpseless monsters are given a capacity
1286 * proportional to their size instead of weight.
1288 if (!mtmp->data->cwt)
1289 maxload = (MAX_CARR_CAP * (long) mtmp->data->msize) / MZ_HUMAN;
1290 else if (!strongmonst(mtmp->data)
1291 || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN)))
1292 maxload = (MAX_CARR_CAP * (long) mtmp->data->cwt) / WT_HUMAN;
1294 maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/
1296 if (!strongmonst(mtmp->data))
1302 return (int) maxload;
1305 /* for restricting monsters' object-pickup.
1307 * to support the new pet behavior, this now returns the max # of objects
1308 * that a given monster could pick up from a pile. frequently this will be
1309 * otmp->quan, but special cases for 'only one' now exist so.
1311 * this will probably cause very amusing behavior with pets and gold coins.
1313 * TODO: allow picking up 2-N objects from a pile of N based on weight.
1314 * Change from 'int' to 'long' to accomate big stacks of gold.
1315 * Right now we fake it by reporting a partial quantity, but the
1316 * likesgold handling m_move results in picking up the whole stack.
1319 can_carry(mtmp, otmp)
1323 int iquan, otyp = otmp->otyp, newload = otmp->owt;
1324 struct permonst *mdat = mtmp->data;
1328 return 0; /* can't carry anything */
1330 if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])
1331 && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp))
1333 if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm]))
1335 if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp)
1336 && (otyp != BELL_OF_OPENING || !is_covetous(mdat)))
1339 /* hostile monsters who like gold will pick up the whole stack;
1340 tame mosnters with hands will pick up the partial stack */
1341 iquan = (otmp->quan > (long) LARGEST_INT)
1342 ? 20000 + rn2(LARGEST_INT - 20000 + 1)
1345 /* monsters without hands can't pick up multiple objects at once
1346 * unless they have an engulfing attack
1348 * ...dragons, of course, can always carry gold pieces and gems somehow
1351 boolean glomper = FALSE;
1353 if (mtmp->data->mlet == S_DRAGON
1354 && (otmp->oclass == COIN_CLASS
1355 || otmp->oclass == GEM_CLASS))
1358 for (nattk = 0; nattk < NATTK; nattk++)
1359 if (mtmp->data->mattk[nattk].aatyp == AT_ENGL) {
1363 if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper)
1367 /* steeds don't pick up stuff (to avoid shop abuse) */
1368 if (mtmp == u.usteed)
1371 return iquan; /* no limit */
1372 if (mtmp->mpeaceful && !mtmp->mtame)
1374 /* otherwise players might find themselves obligated to violate
1375 * their alignment if the monster takes something they need
1378 /* special--boulder throwers carry unlimited amounts of boulders */
1379 if (throws_rocks(mdat) && otyp == BOULDER)
1382 /* nymphs deal in stolen merchandise, but not boulders or statues */
1383 if (mdat->mlet == S_NYMPH)
1384 return (otmp->oclass == ROCK_CLASS) ? 0 : iquan;
1386 if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp))
1392 /* return number of acceptable neighbour positions */
1394 mfndpos(mon, poss, info, flag)
1396 coord *poss; /* coord poss[9] */
1397 long *info; /* long info[9] */
1400 struct permonst *mdat = mon->data;
1401 register struct trap *ttmp;
1406 boolean wantpool, poolok, lavaok, nodiag;
1407 boolean rockok = FALSE, treeok = FALSE, thrudoor;
1409 boolean poisongas_ok, in_poisongas;
1411 int gas_glyph = cmap_to_glyph(S_poisoncloud);
1415 nowtyp = levl[x][y].typ;
1417 nodiag = NODIAG(mdat - mons);
1418 wantpool = mdat->mlet == S_EEL;
1419 poolok = (is_flyer(mdat) || is_clinger(mdat)
1420 || (is_swimmer(mdat) && !wantpool));
1421 lavaok = (is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat));
1422 thrudoor = ((flag & (ALLOW_WALL | BUSTDOOR)) != 0L);
1423 poisongas_ok = ((nonliving(mdat) || is_vampshifter(mon)
1424 || breathless(mdat)) || resists_poison(mon));
1425 in_poisongas = ((gas_reg = visible_region_at(x,y)) != 0
1426 && gas_reg->glyph == gas_glyph);
1428 if (flag & ALLOW_DIG) {
1431 /* need to be specific about what can currently be dug */
1432 if (!needspick(mdat)) {
1433 rockok = treeok = TRUE;
1434 } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed
1435 && mon->weapon_check == NO_WEAPON_WANTED) {
1436 rockok = is_pick(mw_tmp);
1437 treeok = is_axe(mw_tmp);
1439 rockok = (m_carrying(mon, PICK_AXE)
1440 || (m_carrying(mon, DWARVISH_MATTOCK)
1441 && !which_armor(mon, W_ARMS)));
1442 treeok = (m_carrying(mon, AXE) || (m_carrying(mon, BATTLE_AXE)
1443 && !which_armor(mon, W_ARMS)));
1445 if (rockok || treeok)
1449 nexttry: /* eels prefer the water, but if there is no water nearby,
1450 they will crawl over land */
1457 maxx = min(x + 1, COLNO - 1);
1458 maxy = min(y + 1, ROWNO - 1);
1459 for (nx = max(1, x - 1); nx <= maxx; nx++)
1460 for (ny = max(0, y - 1); ny <= maxy; ny++) {
1461 if (nx == x && ny == y)
1463 ntyp = levl[nx][ny].typ;
1465 && !((flag & ALLOW_WALL) && may_passwall(nx, ny))
1466 && !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx, ny)))
1468 /* KMH -- Added iron bars */
1469 if (ntyp == IRONBARS
1470 && (!(flag & ALLOW_BARS)
1471 || ((levl[nx][ny].wall_info & W_NONDIGGABLE)
1472 && (dmgtype(mdat, AD_RUST)
1473 || dmgtype(mdat, AD_CORR)))))
1475 if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon))
1476 && (((levl[nx][ny].doormask & D_CLOSED) && !(flag & OPENDOOR))
1477 || ((levl[nx][ny].doormask & D_LOCKED)
1478 && !(flag & UNLOCKDOOR))) && !thrudoor)
1480 /* avoid poison gas? */
1481 if (!poisongas_ok && !in_poisongas
1482 && (gas_reg = visible_region_at(nx,ny)) != 0
1483 && gas_reg->glyph == gas_glyph)
1485 /* first diagonal checks (tight squeezes handled below) */
1486 if (nx != x && ny != y
1488 || (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN))
1489 || (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN))
1490 || ((IS_DOOR(nowtyp) || IS_DOOR(ntyp))
1491 && Is_rogue_level(&u.uz))
1492 /* mustn't pass between adjacent long worm segments,
1493 but can attack that way */
1494 || (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny)
1495 && !m_at(nx, ny) && (nx != u.ux || ny != u.uy))))
1497 if ((is_pool(nx, ny) == wantpool || poolok)
1498 && (lavaok || !is_lava(nx, ny))) {
1500 boolean monseeu = (mon->mcansee
1501 && (!Invis || perceives(mdat)));
1502 boolean checkobj = OBJ_AT(nx, ny);
1504 /* Displacement also displaces the Elbereth/scare monster,
1505 * as long as you are visible.
1507 if (Displaced && monseeu && mon->mux == nx && mon->muy == ny) {
1516 if (onscary(dispx, dispy, mon)) {
1517 if (!(flag & ALLOW_SSM))
1519 info[cnt] |= ALLOW_SSM;
1521 if ((nx == u.ux && ny == u.uy)
1522 || (nx == mon->mux && ny == mon->muy)) {
1523 if (nx == u.ux && ny == u.uy) {
1524 /* If it's right next to you, it found you,
1525 * displaced or no. We must set mux and muy
1526 * right now, so when we return we can tell
1527 * that the ALLOW_U means to attack _you_ and
1533 if (!(flag & ALLOW_U))
1535 info[cnt] |= ALLOW_U;
1537 if (MON_AT(nx, ny)) {
1538 struct monst *mtmp2 = m_at(nx, ny);
1539 long mmflag = flag | mm_aggression(mon, mtmp2);
1541 if (mmflag & ALLOW_M) {
1542 info[cnt] |= ALLOW_M;
1544 if (!(mmflag & ALLOW_TM))
1546 info[cnt] |= ALLOW_TM;
1549 mmflag = flag | mm_displacement(mon, mtmp2);
1550 if (!(mmflag & ALLOW_MDISP))
1552 info[cnt] |= ALLOW_MDISP;
1555 /* Note: ALLOW_SANCT only prevents movement, not
1556 attack, into a temple. */
1557 if (level.flags.has_temple && *in_rooms(nx, ny, TEMPLE)
1558 && !*in_rooms(x, y, TEMPLE)
1559 && in_your_sanctuary((struct monst *) 0, nx, ny)) {
1560 if (!(flag & ALLOW_SANCT))
1562 info[cnt] |= ALLOW_SANCT;
1565 if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
1566 if (flag & NOGARLIC)
1568 info[cnt] |= NOGARLIC;
1570 if (checkobj && sobj_at(BOULDER, nx, ny)) {
1571 if (!(flag & ALLOW_ROCK))
1573 info[cnt] |= ALLOW_ROCK;
1575 if (monseeu && onlineu(nx, ny)) {
1578 info[cnt] |= NOTONL;
1580 /* check for diagonal tight squeeze */
1581 if (nx != x && ny != y && bad_rock(mdat, x, ny)
1582 && bad_rock(mdat, nx, y) && cant_squeeze_thru(mon))
1584 /* The monster avoids a particular type of trap if it's
1585 * familiar with the trap type. Pets get ALLOW_TRAPS
1586 * and checking is done in dogmove.c. In either case,
1587 * "harmless" traps are neither avoided nor marked in info[].
1589 if ((ttmp = t_at(nx, ny)) != 0) {
1590 if (ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) {
1592 "A monster looked at a very strange trap of type %d.",
1596 if ((ttmp->ttyp != RUST_TRAP
1597 || mdat == &mons[PM_IRON_GOLEM])
1598 && ttmp->ttyp != STATUE_TRAP
1599 && ttmp->ttyp != VIBRATING_SQUARE
1600 && ((!is_pit(ttmp->ttyp) && !is_hole(ttmp->ttyp))
1601 || (!is_flyer(mdat) && !is_floater(mdat)
1602 && !is_clinger(mdat)) || Sokoban)
1603 && (ttmp->ttyp != SLP_GAS_TRAP || !resists_sleep(mon))
1604 && (ttmp->ttyp != BEAR_TRAP
1605 || (mdat->msize > MZ_SMALL && !amorphous(mdat)
1606 && !is_flyer(mdat) && !is_floater(mdat)
1607 && !is_whirly(mdat) && !unsolid(mdat)))
1608 && (ttmp->ttyp != FIRE_TRAP || !resists_fire(mon))
1609 && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat))
1610 && (ttmp->ttyp != WEB
1611 || (!amorphous(mdat) && !webmaker(mdat)
1612 && !is_whirly(mdat) && !unsolid(mdat)))
1613 && (ttmp->ttyp != ANTI_MAGIC || !resists_magm(mon))) {
1614 if (!(flag & ALLOW_TRAPS)) {
1615 if (mon->mtrapseen & (1L << (ttmp->ttyp - 1)))
1618 info[cnt] |= ALLOW_TRAPS;
1626 if (!cnt && wantpool && !is_pool(x, y)) {
1633 /* Monster against monster special attacks; for the specified monster
1634 combinations, this allows one monster to attack another adjacent one
1635 in the absence of Conflict. There is no provision for targetting
1636 other monsters; just hand to hand fighting when they happen to be
1637 next to each other. */
1639 mm_aggression(magr, mdef)
1640 struct monst *magr, /* monster that is currently deciding where to move */
1641 *mdef; /* another monster which is next to it */
1643 /* supposedly purple worms are attracted to shrieking because they
1644 like to eat shriekers, so attack the latter when feasible */
1645 if (magr->data == &mons[PM_PURPLE_WORM]
1646 && mdef->data == &mons[PM_SHRIEKER])
1647 return ALLOW_M | ALLOW_TM;
1648 /* Various other combinations such as dog vs cat, cat vs rat, and
1649 elf vs orc have been suggested. For the time being we don't
1654 /* Monster displacing another monster out of the way */
1656 mm_displacement(magr, mdef)
1657 struct monst *magr, /* monster that is currently deciding where to move */
1658 *mdef; /* another monster which is next to it */
1660 struct permonst *pa = magr->data, *pd = mdef->data;
1662 /* if attacker can't barge through, there's nothing to do;
1663 or if defender can barge through too, don't let attacker
1664 do so, otherwise they might just end up swapping places
1665 again when defender gets its chance to move */
1666 if ((pa->mflags3 & M3_DISPLACES) != 0 && (pd->mflags3 & M3_DISPLACES) == 0
1667 /* no displacing grid bugs diagonally */
1668 && !(magr->mx != mdef->mx && magr->my != mdef->my
1669 && NODIAG(monsndx(pd)))
1670 /* no displacing trapped monsters or multi-location longworms */
1671 && !mdef->mtrapped && (!mdef->wormno || !count_wsegs(mdef))
1672 /* riders can move anything; others, same size or smaller only */
1673 && (is_rider(pa) || pa->msize >= pd->msize))
1678 /* Is the square close enough for the monster to move or attack into? */
1684 int distance = dist2(mon->mx, mon->my, x, y);
1686 if (distance == 2 && NODIAG(mon->data - mons))
1688 return (boolean) (distance < 3);
1691 /* really free dead monsters */
1695 struct monst **mtmp, *freetmp;
1698 for (mtmp = &fmon; *mtmp;) {
1700 if (DEADMONSTER(freetmp) && !freetmp->isgd) {
1701 *mtmp = freetmp->nmon;
1702 freetmp->nmon = NULL;
1703 dealloc_monst(freetmp);
1706 mtmp = &(freetmp->nmon);
1709 if (count != iflags.purge_monsters)
1710 impossible("dmonsfree: %d removed doesn't match %d pending",
1711 count, iflags.purge_monsters);
1712 iflags.purge_monsters = 0;
1715 /* called when monster is moved to larger structure */
1717 replmon(mtmp, mtmp2)
1718 struct monst *mtmp, *mtmp2;
1722 /* transfer the monster's inventory */
1723 for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
1724 if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
1725 impossible("replmon: minvent inconsistency");
1726 otmp->ocarry = mtmp2;
1730 /* remove the old monster from the map and from `fmon' list */
1731 relmon(mtmp, (struct monst **) 0);
1733 /* finish adding its replacement */
1734 if (mtmp != u.usteed) /* don't place steed onto the map */
1735 place_monster(mtmp2, mtmp2->mx, mtmp2->my);
1736 if (mtmp2->wormno) /* update level.monsters[wseg->wx][wseg->wy] */
1737 place_wsegs(mtmp2, NULL); /* locations to mtmp2 not mtmp. */
1738 if (emits_light(mtmp2->data)) {
1739 /* since this is so rare, we don't have any `mon_move_light_source' */
1740 new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
1741 LS_MONSTER, monst_to_any(mtmp2));
1742 /* here we rely on fact that `mtmp' hasn't actually been deleted */
1743 del_light_source(LS_MONSTER, monst_to_any(mtmp));
1747 if (u.ustuck == mtmp)
1749 if (u.usteed == mtmp)
1752 replshk(mtmp, mtmp2);
1754 /* discard the old monster */
1755 dealloc_monst(mtmp);
1758 /* release mon from the display and the map's monster list,
1759 maybe transfer it to one of the other monster lists */
1761 relmon(mon, monst_list)
1763 struct monst **monst_list; /* &migrating_mons or &mydogs or null */
1766 int mx = mon->mx, my = mon->my;
1767 boolean on_map = (m_at(mx, my) == mon),
1768 unhide = (monst_list != 0);
1771 panic("relmon: no fmon available.");
1774 /* can't remain hidden across level changes (exception: wizard
1775 clone can continue imitating some other monster form); also,
1776 might be imitating a boulder so need line-of-sight unblocking */
1777 mon->mundetected = 0;
1778 if (M_AP_TYPE(mon) && M_AP_TYPE(mon) != M_AP_MONSTER)
1787 remove_monster(mx, my);
1793 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1794 if (mtmp->nmon == mon)
1798 mtmp->nmon = mon->nmon;
1800 panic("relmon: mon not in list.");
1806 /* insert into mydogs or migrating_mons */
1807 mon->nmon = *monst_list;
1810 /* orphan has no next monster */
1816 copy_mextra(mtmp2, mtmp1)
1817 struct monst *mtmp2, *mtmp1;
1819 if (!mtmp2 || !mtmp1 || !mtmp1->mextra)
1823 mtmp2->mextra = newmextra();
1825 new_mname(mtmp2, (int) strlen(MNAME(mtmp1)) + 1);
1826 Strcpy(MNAME(mtmp2), MNAME(mtmp1));
1831 *EGD(mtmp2) = *EGD(mtmp1);
1836 *EPRI(mtmp2) = *EPRI(mtmp1);
1841 *ESHK(mtmp2) = *ESHK(mtmp1);
1846 *EMIN(mtmp2) = *EMIN(mtmp1);
1851 *EDOG(mtmp2) = *EDOG(mtmp1);
1853 if (has_mcorpsenm(mtmp1))
1854 MCORPSENM(mtmp2) = MCORPSENM(mtmp1);
1861 struct mextra *x = m->mextra;
1865 free((genericptr_t) x->mname);
1867 free((genericptr_t) x->egd);
1869 free((genericptr_t) x->epri);
1871 free((genericptr_t) x->eshk);
1873 free((genericptr_t) x->emin);
1875 free((genericptr_t) x->edog);
1876 /* [no action needed for x->mcorpsenm] */
1878 free((genericptr_t) x);
1879 m->mextra = (struct mextra *) 0;
1888 panic("dealloc_monst with nmon");
1890 dealloc_mextra(mon);
1891 free((genericptr_t) mon);
1894 /* remove effects of mtmp from other data structures */
1896 m_detach(mtmp, mptr)
1898 struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
1900 boolean onmap = (mtmp->mx > 0);
1902 if (mtmp == context.polearm.hitmon)
1903 context.polearm.hitmon = 0;
1905 m_unleash(mtmp, FALSE);
1906 /* to prevent an infinite relobj-flooreffects-hmon-killed loop */
1908 mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
1909 relobj(mtmp, 0, FALSE);
1910 if (onmap || mtmp == level.monsters[0][0]) {
1914 remove_monster(mtmp->mx, mtmp->my);
1916 if (emits_light(mptr))
1917 del_light_source(LS_MONSTER, monst_to_any(mtmp));
1918 if (M_AP_TYPE(mtmp))
1921 newsym(mtmp->mx, mtmp->my);
1924 fill_pit(mtmp->mx, mtmp->my);
1930 iflags.purge_monsters++;
1933 /* find the worn amulet of life saving which will save a monster */
1938 if (!nonliving(mon->data) || is_vampshifter(mon)) {
1939 struct obj *otmp = which_armor(mon, W_AMUL);
1941 if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING)
1944 return (struct obj *) 0;
1948 lifesaved_monster(mtmp)
1952 struct obj *lifesave = mlifesaver(mtmp);
1955 /* not canseemon; amulets are on the head, so you don't want
1956 * to show this for a long worm with only a tail visible.
1957 * Nor do you check invisibility, because glowing and
1958 * disintegrating amulets are always visible. */
1959 if (cansee(mtmp->mx, mtmp->my)) {
1961 pline("But wait...");
1963 pline("
\82¿
\82å
\82Á
\82Æ
\82Ü
\82Á
\82½
\81D
\81D
\81D");
1965 pline("%s medallion begins to glow!", s_suffix(Monnam(mtmp)));
1967 pline("%s
\82Ì
\96\82\8f\9c\82¯
\82ª
\8bP
\82«
\82Í
\82¶
\82ß
\82½
\81I", Monnam(mtmp));
1968 makeknown(AMULET_OF_LIFE_SAVING);
1969 /* amulet is visible, but monster might not be */
1970 if (canseemon(mtmp)) {
1971 if (attacktype(mtmp->data, AT_EXPL)
1972 || attacktype(mtmp->data, AT_BOOM))
1974 pline("%s reconstitutes!", Monnam(mtmp));
1976 pline("%s
\82Í
\8dÄ
\8d\
\90¬
\82³
\82ê
\82½
\81I", Monnam(mtmp));
1979 pline("%s looks much better!", Monnam(mtmp));
1981 pline("%s
\82Í
\82·
\82Á
\82©
\82è
\89ñ
\95\9c\82µ
\82½
\82æ
\82¤
\82¾
\81I", Monnam(mtmp));
1984 pline_The("medallion crumbles to dust!");
1986 pline("
\96\82\8f\9c\82¯
\82Í
\82±
\82È
\82²
\82È
\82É
\82
\82¾
\82¯
\82½
\81I");
1988 m_useup(mtmp, lifesave);
1989 /* equip replacement amulet, if any, on next move */
1990 mtmp->misc_worn_check |= I_SPECIAL;
1992 surviver = !(mvitals[monsndx(mtmp->data)].mvflags & G_GENOD);
1995 if (mtmp->mtame && !mtmp->isminion) {
1996 wary_dog(mtmp, !surviver);
1998 if (mtmp->mhpmax <= 0)
2000 mtmp->mhp = mtmp->mhpmax;
2003 /* genocided monster can't be life-saved */
2004 if (cansee(mtmp->mx, mtmp->my))
2006 pline("Unfortunately, %s is still genocided...",
2008 pline("
\8ec
\94O
\82È
\82ª
\82ç%s
\82Í
\8bs
\8eE
\82³
\82ê
\82Ä
\82¢
\82é
\81D
\81D
\81D",
2017 register struct monst *mtmp;
2019 struct permonst *mptr;
2022 mtmp->mhp = 0; /* in case caller hasn't done this */
2023 lifesaved_monster(mtmp);
2024 if (!DEADMONSTER(mtmp))
2027 if (is_vampshifter(mtmp)) {
2028 int mndx = mtmp->cham;
2029 int x = mtmp->mx, y = mtmp->my;
2031 /* this only happens if shapeshifted */
2032 if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
2033 && !(mvitals[mndx].mvflags & G_GENOD)) {
2035 boolean in_door = (amorphous(mtmp->data)
2036 && closed_door(mtmp->mx, mtmp->my)),
2038 /* alternate message phrasing for some monster types */
2039 spec_mon = (nonliving(mtmp->data)
2040 || noncorporeal(mtmp->data)
2041 || amorphous(mtmp->data)),
2043 spec_death = (disintegested /* disintegrated or digested */
2044 || noncorporeal(mtmp->data)
2045 || amorphous(mtmp->data));
2047 /* construct a format string before transformation;
2048 will be capitalized when used, expects one %s arg */
2050 Sprintf(buf, "%s suddenly %s and rises as %%s!",
2051 x_monnam(mtmp, ARTICLE_THE,
2052 spec_mon ? (char *) 0 : "seemingly dead",
2053 (SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2054 spec_death ? "reconstitutes" : "transforms");
2056 Sprintf(buf, "%s%s
\82Í
\93Ë
\91R%s
\81C%%s
\82Æ
\82µ
\82Ä
\91h
\82Á
\82½
\81I",
2057 spec_death ? "" : "
\8e\80\82ñ
\82¾
\82æ
\82¤
\82É
\8ev
\82í
\82ê
\82½",
2058 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2059 SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2060 | SUPPRESS_INVISIBLE | SUPPRESS_IT,
2062 spec_death ? "
\8dÄ
\8d\
\90¬
\82³
\82ê" : "
\95Ï
\89»
\82µ");
2066 if (mtmp->mhpmax <= 0)
2068 mtmp->mhp = mtmp->mhpmax;
2069 /* mtmp==u.ustuck can happen if previously a fog cloud
2070 or poly'd hero is hugging a vampire bat */
2071 if (mtmp == u.ustuck) {
2073 expels(mtmp, mtmp->data, FALSE);
2080 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
2081 rloc_to(mtmp, new_xy.x, new_xy.y);
2084 newcham(mtmp, &mons[mndx], FALSE, FALSE);
2085 if (mtmp->data == &mons[mndx])
2086 mtmp->cham = NON_PM;
2089 if (canspotmon(mtmp)) {
2090 /* 3.6.0 used a_monnam(mtmp); that was weird if mtmp was
2091 named: "Dracula suddenly transforms and rises as Dracula";
2092 3.6.1 used mtmp->data->mname; that ignored hallucination */
2094 x_monnam(mtmp, ARTICLE_A, (char *) 0,
2095 (SUPPRESS_NAME | SUPPRESS_IT
2096 | SUPPRESS_INVISIBLE), FALSE));
2097 vamp_rise_msg = TRUE;
2104 /* dead vault guard is actually kept at coordinate <0,0> until
2105 his temporary corridor to/from the vault has been removed;
2106 need to do this after life-saving and before m_detach() */
2107 if (mtmp->isgd && !grddead(mtmp))
2110 /* Player is thrown from his steed when it dies */
2111 if (mtmp == u.usteed)
2112 dismount_steed(DISMOUNT_GENERIC);
2114 mptr = mtmp->data; /* save this for m_detach() */
2115 /* restore chameleon, lycanthropes to true form at death */
2116 if (mtmp->cham >= LOW_PM) {
2117 set_mon_data(mtmp, &mons[mtmp->cham]);
2118 mtmp->cham = NON_PM;
2119 } else if (mtmp->data == &mons[PM_WEREJACKAL])
2120 set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL]);
2121 else if (mtmp->data == &mons[PM_WEREWOLF])
2122 set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF]);
2123 else if (mtmp->data == &mons[PM_WERERAT])
2124 set_mon_data(mtmp, &mons[PM_HUMAN_WERERAT]);
2127 * mvitals[].died does double duty as total number of dead monsters
2128 * and as experience factor for the player killing more monsters.
2129 * this means that a dragon dying by other means reduces the
2130 * experience the player gets for killing a dragon directly; this
2131 * is probably not too bad, since the player likely finagled the
2132 * first dead dragon via ring of conflict or pets, and extinguishing
2133 * based on only player kills probably opens more avenues of abuse
2134 * for rings of conflict and such.
2136 tmp = monsndx(mtmp->data);
2137 if (mvitals[tmp].died < 255)
2138 mvitals[tmp].died++;
2140 /* if it's a (possibly polymorphed) quest leader, mark him as dead */
2141 if (mtmp->m_id == quest_status.leader_m_id)
2142 quest_status.leader_is_dead = TRUE;
2144 /* if the mail daemon dies, no more mail delivery. -3. */
2145 if (tmp == PM_MAIL_DAEMON)
2146 mvitals[tmp].mvflags |= G_GENOD;
2149 if (mtmp->data->mlet == S_KOP) {
2150 /* Dead Kops may come back. */
2152 case 1: /* returns near the stairs */
2153 (void) makemon(mtmp->data, xdnstair, ydnstair, NO_MM_FLAGS);
2155 case 2: /* randomly */
2156 (void) makemon(mtmp->data, 0, 0, NO_MM_FLAGS);
2164 if (mtmp->data->msound == MS_NEMESIS)
2166 if (mtmp->data == &mons[PM_MEDUSA])
2167 u.uachieve.killed_medusa = 1;
2168 if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
2169 unmap_object(mtmp->mx, mtmp->my);
2170 m_detach(mtmp, mptr);
2173 /* TRUE if corpse might be dropped, magr may die if mon was swallowed */
2175 corpse_chance(mon, magr, was_swallowed)
2177 struct monst *magr; /* killer, if swallowed */
2178 boolean was_swallowed; /* digestion */
2180 struct permonst *mdat = mon->data;
2183 if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) {
2184 if (cansee(mon->mx, mon->my) && !was_swallowed)
2186 pline("%s body crumbles into dust.", s_suffix(Monnam(mon)));
2188 pline("%s
\82Ì
\91Ì
\82Í
\95²
\81X
\82É
\82È
\82Á
\82½
\81D", Monnam(mon));
2192 /* Gas spores always explode upon death */
2193 for (i = 0; i < NATTK; i++) {
2194 if (mdat->mattk[i].aatyp == AT_BOOM) {
2195 if (mdat->mattk[i].damn)
2196 tmp = d((int) mdat->mattk[i].damn, (int) mdat->mattk[i].damd);
2197 else if (mdat->mattk[i].damd)
2198 tmp = d((int) mdat->mlevel + 1, (int) mdat->mattk[i].damd);
2201 if (was_swallowed && magr) {
2202 if (magr == &youmonst) {
2204 There("is an explosion in your %s!", body_part(STOMACH));
2206 pline("%s
\82Ì
\92\86\82Å
\94\9a\94
\82ª
\8bN
\82«
\82½
\81I", body_part(STOMACH));
2208 Sprintf(killer.name, "%s explosion",
2209 s_suffix(mdat->mname));
2211 Sprintf(killer.name, "%s
\82Ì
\94\9a\94
\82Å", mdat->mname);
2213 losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN);
2216 You_hear("an explosion.");
2218 You_hear("
\94\9a\94
\89¹
\82ð
\95·
\82¢
\82½
\81D");
2220 if (DEADMONSTER(magr))
2222 if (DEADMONSTER(magr)) { /* maybe lifesaved */
2223 if (canspotmon(magr))
2225 pline("%s rips open!", Monnam(magr));
2227 pline("%s
\82Í
\83r
\83\8a\82Á
\82Æ
\94j
\82ê
\82½
\81I", Monnam(magr));
2228 } else if (canseemon(magr))
2230 pline("%s seems to have indigestion.", Monnam(magr));
2232 pline("%s
\82Í
\8fÁ
\89»
\95s
\97Ç
\82Ì
\82æ
\82¤
\82¾
\81D", Monnam(magr));
2239 Sprintf(killer.name, "%s explosion", s_suffix(mdat->mname));
2241 Sprintf(killer.name, "%s
\82Ì
\94\9a\94
\82Å", mdat->mname);
2242 killer.format = KILLED_BY_AN;
2243 explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS);
2244 killer.name[0] = '\0';
2250 /* must duplicate this below check in xkilled() since it results in
2251 * creating no objects as well as no corpse
2253 if (LEVEL_SPECIFIC_NOCORPSE(mdat))
2256 if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned)
2257 || is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat) || mon->isshk)
2259 tmp = 2 + ((mdat->geno & G_FREQ) < 2) + verysmall(mdat);
2260 return (boolean) !rn2(tmp);
2263 /* drop (perhaps) a cadaver and remove monster */
2266 register struct monst *mdef;
2269 if (!DEADMONSTER(mdef))
2270 return; /* lifesaved */
2272 if (corpse_chance(mdef, (struct monst *) 0, FALSE)
2273 && (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my)))
2274 (void) make_corpse(mdef, CORPSTAT_NONE);
2277 /* monster disappears, not dies */
2282 mdef->mhp = 0; /* can skip some inventory bookkeeping */
2284 /* dead vault guard is actually kept at coordinate <0,0> until
2285 his temporary corridor to/from the vault has been removed */
2286 if (mdef->isgd && !grddead(mdef))
2288 /* hero is thrown from his steed when it disappears */
2289 if (mdef == u.usteed)
2290 dismount_steed(DISMOUNT_GENERIC);
2291 /* stuck to you? release */
2293 /* drop special items like the Amulet so that a dismissed Kop or nurse
2294 can't remove them from the game */
2295 mdrop_special_objs(mdef);
2296 /* release rest of monster's inventory--it is removed from game */
2297 discard_minvent(mdef);
2298 m_detach(mdef, mdef->data);
2301 /* drop a statue or rock and remove monster */
2306 struct obj *otmp, *obj, *oldminvent;
2307 xchar x = mdef->mx, y = mdef->my;
2308 boolean wasinside = FALSE;
2310 if (!vamp_stone(mdef)) /* vampshifter reverts to vampire */
2313 /* we have to make the statue before calling mondead, to be able to
2314 * put inventory in it, and we have to check for lifesaving before
2315 * making the statue....
2317 mdef->mhp = 0; /* in case caller hasn't done this */
2318 lifesaved_monster(mdef);
2319 if (!DEADMONSTER(mdef))
2322 mdef->mtrapped = 0; /* (see m_detach) */
2324 if ((int) mdef->data->msize > MZ_TINY
2325 || !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) {
2327 /* some objects may end up outside the statue */
2328 while ((obj = mdef->minvent) != 0) {
2329 obj_extract_self(obj);
2331 update_mon_intrinsics(mdef, obj, FALSE, TRUE);
2332 obj_no_longer_held(obj);
2333 if (obj->owornmask & W_WEP)
2334 setmnotwielded(mdef, obj);
2335 obj->owornmask = 0L;
2336 if (obj->otyp == BOULDER
2337 #if 0 /* monsters don't carry statues */
2338 || (obj->otyp == STATUE
2339 && mons[obj->corpsenm].msize >= mdef->data->msize)
2341 /* invocation tools resist even with 0% resistance */
2342 || obj_resists(obj, 0, 0)) {
2344 if (flooreffects(obj, x, y, "fall"))
2346 if (flooreffects(obj, x, y, "
\97\8e\82¿
\82é"))
2348 place_object(obj, x, y);
2351 end_burn(obj, TRUE);
2352 obj->nobj = oldminvent;
2356 /* defer statue creation until after inventory removal
2357 so that saved monster traits won't retain any stale
2358 item-conferred attributes */
2359 otmp = mkcorpstat(STATUE, mdef, mdef->data, x, y, CORPSTAT_NONE);
2360 if (has_mname(mdef))
2361 otmp = oname(otmp, MNAME(mdef));
2362 while ((obj = oldminvent) != 0) {
2363 oldminvent = obj->nobj;
2364 obj->nobj = 0; /* avoid merged-> obfree-> dealloc_obj-> panic */
2365 (void) add_to_container(otmp, obj);
2367 /* Archeologists should not break unique statues */
2368 if (mdef->data->geno & G_UNIQ)
2370 otmp->owt = weight(otmp);
2372 otmp = mksobj_at(ROCK, x, y, TRUE, FALSE);
2375 /* mondead() already does this, but we must do it before the newsym */
2376 if (glyph_is_invisible(levl[x][y].glyph))
2380 /* We don't currently trap the hero in the statue in this case but we
2382 if (u.uswallow && u.ustuck == mdef)
2386 if (is_animal(mdef->data))
2388 You("%s through an opening in the new %s.",
2389 locomotion(youmonst.data, "jump"), xname(otmp));
2391 You("
\90V
\82µ
\82
\82Å
\82«
\82½%s
\82©
\82ç%s
\81D",
2392 xname(otmp), jumpedthrough(youmonst.data, "
\94ò
\82Ñ
\8fo
\82½"));
2397 /* another monster has killed the monster mdef */
2399 monkilled(mdef, fltxt, how)
2404 boolean be_sad = FALSE; /* true if unseen pet is killed */
2406 if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my))
2409 pline("%s is %s%s%s!", Monnam(mdef),
2410 nonliving(mdef->data) ? "destroyed" : "killed",
2411 *fltxt ? " by the " : "", fltxt);
2415 pline("%s
\82Í%s
\82É
\82æ
\82Á
\82Ä%s
\81I", Monnam(mdef), fltxt,
2416 nonliving(mdef->data) ? "
\93|
\82³
\82ê
\82½" : "
\8eE
\82³
\82ê
\82½");
2418 pline("%s
\82Í%s
\81I", Monnam(mdef),
2419 nonliving(mdef->data) ? "
\93|
\82³
\82ê
\82½" : "
\8eE
\82³
\82ê
\82½");
2423 be_sad = (mdef->mtame != 0);
2425 /* no corpses if digested or disintegrated */
2426 disintegested = (how == AD_DGST || how == -AD_RBRE);
2432 if (be_sad && DEADMONSTER(mdef))
2434 You("have a sad feeling for a moment, then it passes.");
2436 You("
\94ß
\82µ
\82¢
\8bC
\8e\9d\82É
\82¨
\82»
\82í
\82ê
\82½
\82ª
\81C
\82·
\82®
\82É
\89ß
\82¬
\82³
\82Á
\82½
\81D");
2443 if (u.ustuck == mtmp) {
2449 if (Punished && uchain->where != OBJ_FLOOR)
2451 vision_full_recalc = 1;
2453 /* prevent swallower (mtmp might have just poly'd into something
2454 without an engulf attack) from immediately re-engulfing */
2455 if (attacktype(mtmp->data, AT_ENGL) && !mtmp->mspec_used)
2456 mtmp->mspec_used = rnd(2);
2466 xkilled(mtmp, XKILL_GIVEMSG);
2469 /* the player has killed the monster mtmp */
2471 xkilled(mtmp, xkill_flags)
2473 int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */
2475 int tmp, mndx, x = mtmp->mx, y = mtmp->my;
2476 struct permonst *mdat;
2479 boolean wasinside = u.uswallow && (u.ustuck == mtmp),
2481 nomsg = (xkill_flags & XKILL_NOMSG) != 0,
2482 nocorpse = (xkill_flags & XKILL_NOCORPSE) != 0,
2483 noconduct = (xkill_flags & XKILL_NOCONDUCT) != 0;
2485 mtmp->mhp = 0; /* caller will usually have already done this */
2486 if (!noconduct) /* KMH, conduct */
2487 u.uconduct.killer++;
2491 boolean namedpet = has_mname(mtmp) && !Hallucination;
2494 nonliving(mtmp->data) ? "destroy" : "kill",
2495 !(wasinside || canspotmon(mtmp)) ? "it"
2496 : !mtmp->mtame ? mon_nam(mtmp)
2497 : x_monnam(mtmp, namedpet ? ARTICLE_NONE : ARTICLE_THE,
2498 "poor", namedpet ? SUPPRESS_SADDLE : 0, FALSE));
2500 You("%s%s
\82ð
\93|
\82µ
\82½
\81I",
2501 !(wasinside || canspotmon(mtmp)) ? "
\82»
\82ê"
2502 : mtmp->mtame ? "
\82©
\82í
\82¢
\82»
\82¤
\82È" : "",
2507 if (mtmp->mtrapped && (t = t_at(x, y)) != 0
2508 && is_pit(t->ttyp)) {
2509 if (sobj_at(BOULDER, x, y))
2510 nocorpse = TRUE; /* Prevent corpses/treasure being created
2511 "on top" of boulder that is about to fall in.
2512 This is out of order, but cannot be helped
2513 unless this whole routine is rearranged. */
2514 if (m_carrying(mtmp, BOULDER))
2518 /* your pet knows who just killed it...watch out */
2519 if (mtmp->mtame && !mtmp->isminion)
2520 EDOG(mtmp)->killed_by_u = 1;
2522 if (wasinside && thrownobj && thrownobj != uball) {
2523 /* thrown object has killed hero's engulfer; add it to mon's
2524 inventory now so that it will be placed with mon's other
2525 stuff prior to lookhere/autopickup when hero is expelled
2526 below (as a side-effect, this missile has immunity from
2527 being consumed [for this shot/throw only]) */
2528 mpickobj(mtmp, thrownobj);
2529 /* let throwing code know that missile has been disposed of */
2533 vamp_rise_msg = FALSE; /* might get set in mondead(); only checked below */
2534 disintegested = nocorpse; /* alternate vamp_rise message needed if true */
2535 /* dispose of monster and make cadaver */
2540 disintegested = FALSE; /* reset */
2542 if (!DEADMONSTER(mtmp)) { /* monster lifesaved */
2543 /* Cannot put the non-visible lifesaving message in
2544 * lifesaved_monster() since the message appears only when _you_
2545 * kill it (as opposed to visible lifesaving which always appears).
2548 if (!cansee(x, y) && !vamp_rise_msg)
2550 pline("Maybe not...");
2552 pline("
\82¢
\82â
\81C
\88á
\82¤
\82©
\82à
\81D
\81D
\81D");
2556 mdat = mtmp->data; /* note: mondead can change mtmp->data */
2557 mndx = monsndx(mdat);
2564 if (nocorpse || LEVEL_SPECIFIC_NOCORPSE(mdat))
2568 if (mdat == &mons[PM_MAIL_DAEMON]) {
2569 stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE));
2572 if (accessible(x, y) || is_pool(x, y)) {
2573 struct obj *cadaver;
2576 /* illogical but traditional "treasure drop" */
2577 if (!rn2(6) && !(mvitals[mndx].mvflags & G_NOCORPSE)
2578 /* no extra item from swallower or steed */
2579 && (x != u.ux || y != u.uy)
2580 /* no extra item from kops--too easy to abuse */
2581 && mdat->mlet != S_KOP
2582 /* no items from cloned monsters */
2583 && !mtmp->mcloned) {
2584 otmp = mkobj(RANDOM_CLASS, TRUE);
2585 /* don't create large objects from small monsters */
2587 if (mdat->msize < MZ_HUMAN && otyp != FIGURINE
2588 /* oc_big is also oc_bimanual and oc_bulky */
2589 && (otmp->owt > 30 || objects[otyp].oc_big)) {
2592 } else if (!flooreffects(otmp, x, y, nomsg ? "" : "fall")) {
2594 } else if (!flooreffects(otmp, x, y, nomsg ? "" : "
\97\8e\82¿
\82é")) {
2596 place_object(otmp, x, y);
2600 /* corpse--none if hero was inside the monster */
2601 if (!wasinside && corpse_chance(mtmp, (struct monst *) 0, FALSE)) {
2602 cadaver = make_corpse(mtmp, burycorpse ? CORPSTAT_BURIED
2604 if (burycorpse && cadaver && cansee(x, y) && !mtmp->minvis
2605 && cadaver->where == OBJ_BURIED && !nomsg) {
2607 pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp)));
2609 pline("%s
\82Ì
\8e\80\91Ì
\82Í
\96\84\82Ü
\82Á
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D", Monnam(mtmp));
2614 spoteffects(TRUE); /* poor man's expels() */
2615 /* monster is gone, corpse or other object might now be visible */
2619 /* punish bad behaviour */
2621 && (!always_hostile(mdat) && mtmp->malign <= 0)
2622 && (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD)
2623 && u.ualign.type != A_CHAOTIC) {
2624 HTelepat &= ~INTRINSIC;
2629 You("
\8eE
\90l
\8bS
\82¾
\81I");
2630 if (Blind && !Blind_telepat)
2631 see_monsters(); /* Can't sense monsters any more. */
2633 if ((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame)
2635 if (is_unicorn(mdat) && sgn(u.ualign.type) == sgn(mdat->maligntyp)) {
2638 You_feel("guilty...");
2640 You("
\8dß
\82ð
\8a´
\82¶
\82½
\81D
\81D
\81D");
2643 /* give experience points */
2644 tmp = experience(mtmp, (int) mvitals[mndx].died);
2645 more_experienced(tmp, 0);
2646 newexplevel(); /* will decide if you go up */
2648 /* adjust alignment points */
2649 if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */
2650 adjalign(-(u.ualign.record + (int) ALIGNLIM / 2));
2652 pline("That was %sa bad idea...",
2653 u.uevent.qcompleted ? "probably " : "");
2655 pline("%s
\82æ
\82
\82È
\82¢
\8ds
\88×
\82¾
\82Á
\82½
\81D
\81D
\81D",
2656 u.uevent.qcompleted ? "
\82½
\82Ô
\82ñ" : "");
2658 } else if (mdat->msound == MS_NEMESIS) { /* Real good! */
2659 adjalign((int) (ALIGNLIM / 4));
2660 } else if (mdat->msound == MS_GUARDIAN) { /* Bad */
2661 adjalign(-(int) (ALIGNLIM / 8));
2664 pline("That was probably a bad idea...");
2666 pline("
\82æ
\82
\82È
\82¢
\8ds
\88×
\82¾
\82Á
\82½
\81D
\81D
\81D");
2669 pline("Whoopsie-daisy!");
2671 pline("
\83V
\83\93\83W
\83}
\83b
\83^
\81[
\81I");
2672 } else if (mtmp->ispriest) {
2673 adjalign((p_coaligned(mtmp)) ? -2 : 2);
2674 /* cancel divine protection for killing your priest */
2675 if (p_coaligned(mtmp))
2677 if (mdat->maligntyp == A_NONE)
2678 adjalign((int) (ALIGNLIM / 4)); /* BIG bonus */
2679 } else if (mtmp->mtame) {
2680 adjalign(-15); /* bad!! */
2681 /* your god is mighty displeased... */
2684 You_hear("the rumble of distant thunder...");
2686 You_hear("
\89\93\82
\82Å
\97\8b\96Â
\82ð
\95·
\82¢
\82½
\81D
\81D
\81D");
2689 You_hear("the studio audience applaud!");
2691 pline("
\92®
\8fO
\82Ì
\8a\85\8dÑ
\82ð
\97\81\82Ñ
\82½
\81I");
2692 } else if (mtmp->mpeaceful)
2695 /* malign was already adjusted for u.ualign.type and randomization */
2696 adjalign(mtmp->malign);
2699 /* changes the monster into a stone monster of the same type
2700 this should only be called when poly_when_stoned() is true */
2705 if (mtmp->data->mlet == S_GOLEM) {
2706 /* it's a golem, and not a stone golem */
2707 if (canseemon(mtmp))
2709 pline("%s solidifies...", Monnam(mtmp));
2711 pline("%s
\82Í
\8bÃ
\8cÅ
\82µ
\82½
\81D
\81D
\81D", Monnam(mtmp));
2712 if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) {
2713 if (canseemon(mtmp))
2715 pline("Now it's %s.", an(mtmp->data->mname));
2717 pline("
\82È
\82ñ
\82Æ%s
\82É
\82È
\82Á
\82Ä
\82µ
\82Ü
\82Á
\82½
\81D", mtmp->data->mname);
2719 if (canseemon(mtmp))
2721 pline("... and returns to normal.");
2723 pline("
\81D
\81D
\81D
\82»
\82µ
\82Ä
\95\81\92Ê
\82É
\96ß
\82Á
\82½
\81D");
2726 impossible("Can't polystone %s!", a_monnam(mtmp));
2733 if (is_vampshifter(mtmp)) {
2734 int mndx = mtmp->cham;
2735 int x = mtmp->mx, y = mtmp->my;
2737 /* this only happens if shapeshifted */
2738 if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
2739 && !(mvitals[mndx].mvflags & G_GENOD)) {
2741 boolean in_door = (amorphous(mtmp->data)
2742 && closed_door(mtmp->mx, mtmp->my));
2744 /* construct a format string before transformation */
2746 Sprintf(buf, "The lapidifying %s %s %s",
2747 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2748 (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2749 | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2750 amorphous(mtmp->data) ? "coalesces on the"
2751 : is_flyer(mtmp->data) ? "drops to the"
2755 Sprintf(buf, "
\90Î
\89»
\82µ
\82Â
\82Â
\82 \82é%s
\82ª%s%s",
2756 x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
2757 (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
2758 | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
2760 amorphous(mtmp->data) ? "
\82Ì
\8fã
\82Å
\97Z
\8d\87\82µ
\82½"
2761 : is_flyer(mtmp->data) ? "
\82É
\97\8e\82¿
\82½"
2762 : "
\82Ì
\8fã
\82Å
\90g
\82à
\82¾
\82¦
\82½");
2766 if (mtmp->mhpmax <= 0)
2768 mtmp->mhp = mtmp->mhpmax;
2769 /* this can happen if previously a fog cloud */
2770 if (u.uswallow && (mtmp == u.ustuck))
2771 expels(mtmp, mtmp->data, FALSE);
2775 if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
2776 rloc_to(mtmp, new_xy.x, new_xy.y);
2779 if (canspotmon(mtmp)) {
2783 pline("%s
\81I", buf);
2784 display_nhwindow(WIN_MESSAGE, FALSE);
2786 newcham(mtmp, &mons[mndx], FALSE, FALSE);
2787 if (mtmp->data == &mons[mndx])
2788 mtmp->cham = NON_PM;
2791 if (canspotmon(mtmp)) {
2793 pline("%s rises from the %s with renewed agility!",
2794 Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2796 pline("%s
\82Í
\8b@
\95q
\82³
\82ð
\8eæ
\82è
\96ß
\82µ
\82Ä%s
\82©
\82ç
\95\9c\8a\88\82µ
\82½
\81I",
2797 Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
2800 newsym(mtmp->mx, mtmp->my);
2801 return FALSE; /* didn't petrify */
2807 /* drop monster into "limbo" - that is, migrate to the current level */
2813 mdrop_special_objs(mtmp);
2814 migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_APPROX_XY, (coord *) 0);
2817 /* make monster mtmp next to you (if possible);
2818 might place monst on far side of a wall or boulder */
2824 boolean couldspot = canspotmon(mtmp);
2826 if (mtmp == u.usteed) {
2827 /* Keep your steed in sync with you instead */
2833 if (!enexto(&mm, u.ux, u.uy, mtmp->data)) {
2837 if (!isok(mm.x, mm.y))
2839 rloc_to(mtmp, mm.x, mm.y);
2840 if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) {
2841 mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */
2842 if (!couldspot && canspotmon(mtmp))
2844 pline("%s suddenly %s!", Amonnam(mtmp),
2845 !Blind ? "appears" : "arrives");
2847 pline("
\93Ë
\91R%s
\82ª
\8c»
\82ê
\82½
\81I", Amonnam(mtmp));
2853 /* like mnexto() but requires destination to be directly accessible */
2859 struct permonst *ptr = mtmp->data;
2860 boolean diagok = !NODIAG(ptr - mons);
2864 if (!enexto(&mm, u.ux, u.uy, ptr))
2866 if (couldsee(mm.x, mm.y)
2867 /* don't move grid bugs diagonally */
2868 && (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) {
2869 rloc_to(mtmp, mm.x, mm.y);
2872 } while (--tryct > 0);
2876 * Put monster near (or at) location if possible.
2878 * 2 if another monster was moved out of this one's way;
2879 * 1 if relocation was successful (without moving another one);
2881 * Note: if already at the target spot, result is 1 rather than 0.
2883 * Might be called recursively if 'move_other' is True; if so, that argument
2884 * will be False on the nested call so there won't be any further recursion.
2887 mnearto(mtmp, x, y, move_other)
2888 register struct monst *mtmp;
2890 boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */
2892 struct monst *othermon = (struct monst *) 0;
2897 if (mtmp->mx == x && mtmp->my == y && m_at(x, y) == mtmp)
2900 if (move_other && (othermon = m_at(x, y)) != 0) {
2901 if (othermon->wormno)
2902 remove_worm(othermon);
2904 remove_monster(x, y);
2906 othermon->mx = othermon->my = 0; /* 'othermon' is not on the map */
2911 if (!goodpos(newx, newy, mtmp, 0)) {
2912 /* Actually we have real problems if enexto ever fails.
2913 * Migrating_mons that need to be placed will cause
2914 * no end of trouble.
2916 if (!enexto(&mm, newx, newy, mtmp->data))
2918 if (!isok(mm.x, mm.y))
2923 rloc_to(mtmp, newx, newy);
2925 if (move_other && othermon) {
2926 res = 2; /* moving another monster out of the way */
2927 if (!mnearto(othermon, x, y, FALSE)) /* no 'move_other' this time */
2928 m_into_limbo(othermon);
2934 /* monster responds to player action; not the same as a passive attack;
2935 assumes reason for response has been tested, and response _must_ be made */
2940 if (mtmp->data->msound == MS_SHRIEK) {
2943 pline("%s shrieks.", Monnam(mtmp));
2945 pline("%s
\82Í
\8bà
\90Ø
\82è
\90º
\82ð
\82 \82°
\82½
\81D", Monnam(mtmp));
2950 (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
2952 (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS);
2956 if (mtmp->data == &mons[PM_MEDUSA]) {
2959 for (i = 0; i < NATTK; i++)
2960 if (mtmp->data->mattk[i].aatyp == AT_GAZE) {
2961 (void) gazemu(mtmp, &mtmp->data->mattk[i]);
2967 /* Called whenever the player attacks mtmp; also called in other situations
2968 where mtmp gets annoyed at the player. Handles mtmp getting annoyed at the
2969 attack and any ramifications that might have. Useful also in situations
2970 where mtmp was already hostile; it checks for situations where the player
2971 shouldn't be attacking and any ramifications /that/ might have. */
2973 setmangry(mtmp, via_attack)
2977 if (via_attack && sengr_at("Elbereth", u.ux, u.uy, TRUE)
2978 /* only hypocritical if monster is vulnerable to Elbereth (or
2979 peaceful--not vulnerable but attacking it is hypocritical) */
2980 && (onscary(u.ux, u.uy, mtmp) || mtmp->mpeaceful)) {
2982 You_feel("like a hypocrite.");
2984 You_feel("
\8bU
\91P
\8eÒ
\82Ì
\82æ
\82¤
\82È
\8bC
\82ª
\82µ
\82½
\81D");
2985 /* AIS: Yes, I know alignment penalties and bonuses aren't balanced
2986 at the moment. This is about correct relative to other "small"
2987 penalties; it should be fairly large, as attacking while standing
2988 on an Elbereth means that you're requesting peace and then
2989 violating your own request. I know 5 isn't actually large, but
2990 it's intentionally larger than the 1s and 2s that are normally
2991 given for this sort of thing. */
2992 /* reduce to 3 (average) when alignment is already very low */
2993 adjalign((u.ualign.record > 5) ? -5 : -rnd(5));
2997 pline("The engraving beneath you fades.");
2999 pline("
\82 \82È
\82½
\82Ì
\91«
\8c³
\82Ì
\95¶
\8e\9a\82ª
\94\96\82ê
\82½
\81D");
3000 del_engr_at(u.ux, u.uy);
3003 /* AIS: Should this be in both places, or just in wakeup()? */
3004 mtmp->mstrategy &= ~STRAT_WAITMASK;
3005 if (!mtmp->mpeaceful)
3009 mtmp->mpeaceful = 0;
3010 if (mtmp->ispriest) {
3011 if (p_coaligned(mtmp))
3012 adjalign(-5); /* very bad */
3016 adjalign(-1); /* attacking peaceful monsters is bad */
3017 if (couldsee(mtmp->mx, mtmp->my)) {
3018 if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
3020 pline("%s gets angry!", Monnam(mtmp));
3022 pline("%s
\82Í
\93{
\82Á
\82½
\81I", Monnam(mtmp));
3023 else if (flags.verbose && !Deaf)
3027 /* attacking your own quest leader will anger his or her guardians */
3028 if (!context.mon_moving /* should always be the case here */
3029 && mtmp->data == &mons[quest_info(MS_LEADER)]) {
3031 struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
3034 /* guardians will sense this attack even if they can't see it */
3035 for (mon = fmon; mon; mon = mon->nmon) {
3036 if (DEADMONSTER(mon))
3038 if (mon->data == q_guardian && mon->mpeaceful) {
3044 if (got_mad && !Hallucination) {
3045 const char *who = q_guardian->mname;
3049 who = makeplural(who);
3050 pline_The("%s %s to be angry too...",
3051 who, vtense(who, "appear"));
3053 pline("%s
\82à
\93{
\82Á
\82½
\82æ
\82¤
\82¾
\81D
\81D
\81D", who);
3058 /* make other peaceful monsters react */
3059 if (!context.mon_moving) {
3060 static const char *const Exclam[] = {
3062 "Gasp!", "Uh-oh.", "Oh my!", "What?", "Why?",
3064 "
\82®
\82Í
\82Á
\81I", "
\82¤
\82í
\81D", "Oh my!", "
\82È
\82É
\82Á
\81H", "
\82È
\82ñ
\82¾
\81H",
3067 int mndx = monsndx(mtmp->data);
3069 for (mon = fmon; mon; mon = mon->nmon) {
3070 if (DEADMONSTER(mon))
3072 if (mon == mtmp) /* the mpeaceful test catches this since mtmp */
3073 continue; /* is no longer peaceful, but be explicit... */
3075 if (!mindless(mon->data) && mon->mpeaceful
3076 && couldsee(mon->mx, mon->my) && !mon->msleeping
3077 && mon->mcansee && m_canseeu(mon)) {
3078 boolean exclaimed = FALSE;
3080 if (humanoid(mon->data) || mon->isshk || mon->ispriest) {
3081 if (is_watch(mon->data)) {
3083 verbalize("Halt! You're under arrest!");
3085 verbalize("
\8e~
\82Ü
\82ê
\81I
\91ß
\95ß
\82·
\82é
\81I");
3086 (void) angry_guards(!!Deaf);
3089 verbalize("%s", Exclam[mon->m_id % SIZE(Exclam)]);
3092 /* shopkeepers and temple priests might gasp in
3093 surprise, but they won't become angry here */
3094 if (mon->isshk || mon->ispriest)
3097 if (mon->data->mlevel < rn2(10)) {
3098 monflee(mon, rn2(50) + 25, TRUE, !exclaimed);
3102 /* mustn't set mpeaceful to 0 as below;
3103 perhaps reduce tameness? */
3109 pline("%s gets angry!", Monnam(mon));
3111 pline("%s
\82Í
\93{
\82Á
\82½
\81I", Monnam(mon));
3114 } else if (mon->data->mlet == mtmp->data->mlet
3115 && big_little_match(mndx, monsndx(mon->data))
3122 monflee(mon, rn2(25) + 15, TRUE, !exclaimed);
3129 /* wake up a monster, possibly making it angry in the process */
3131 wakeup(mtmp, via_attack)
3132 register struct monst *mtmp;
3135 mtmp->msleeping = 0;
3136 if (M_AP_TYPE(mtmp)) {
3138 } else if (context.forcefight && !context.mon_moving
3139 && mtmp->mundetected) {
3140 mtmp->mundetected = 0;
3141 newsym(mtmp->mx, mtmp->my);
3143 finish_meating(mtmp);
3145 setmangry(mtmp, TRUE);
3148 /* Wake up nearby monsters without angering them. */
3152 wake_nearto(u.ux, u.uy, u.ulevel * 20);
3155 /* Wake up monsters near some particular location. */
3157 wake_nearto(x, y, distance)
3162 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3163 if (DEADMONSTER(mtmp))
3165 if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
3166 /* sleep for N turns uses mtmp->mfrozen, but so does paralysis
3167 so we leave mfrozen monsters alone */
3168 mtmp->msleeping = 0; /* wake indeterminate sleep */
3169 if (!(mtmp->data->geno & G_UNIQ))
3170 mtmp->mstrategy &= ~STRAT_WAITMASK; /* wake 'meditation' */
3171 if (context.mon_moving)
3174 if (!mtmp->isminion)
3175 EDOG(mtmp)->whistletime = moves;
3176 /* Clear mtrack. This is to fix up a pet who is
3177 stuck "fleeing" its master. */
3178 memset(mtmp->mtrack, 0, sizeof mtmp->mtrack);
3184 /* NOTE: we must check for mimicry before calling this routine */
3187 register struct monst *mtmp;
3189 boolean is_blocker_appear = (is_lightblocker_mappear(mtmp));
3191 if (has_mcorpsenm(mtmp))
3192 freemcorpsenm(mtmp);
3194 mtmp->m_ap_type = M_AP_NOTHING;
3195 mtmp->mappearance = 0;
3198 * Discovered mimics don't block light.
3200 if (is_blocker_appear
3201 && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
3202 unblock_point(mtmp->mx, mtmp->my);
3204 newsym(mtmp->mx, mtmp->my);
3207 /* force all chameleons to become normal */
3211 register struct monst *mtmp;
3214 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3215 if (DEADMONSTER(mtmp))
3217 mcham = (int) mtmp->cham;
3218 if (mcham >= LOW_PM) {
3219 (void) newcham(mtmp, &mons[mcham], FALSE, FALSE);
3220 mtmp->cham = NON_PM;
3222 if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
3224 if (M_AP_TYPE(mtmp) && cansee(mtmp->mx, mtmp->my)) {
3226 /* we pretend that the mimic doesn't
3227 know that it has been unmasked */
3228 mtmp->msleeping = 1;
3233 /* Let the chameleons change again -dgk */
3237 register struct monst *mtmp;
3239 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
3240 if (DEADMONSTER(mtmp))
3243 mtmp->cham = pm_to_cham(monsndx(mtmp->data));
3244 if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping
3245 && cansee(mtmp->mx, mtmp->my)) {
3246 set_mimic_sym(mtmp);
3247 newsym(mtmp->mx, mtmp->my);
3252 /* called when restoring a monster from a saved level; protection
3253 against shape-changing might be different now than it was at the
3254 time the level was saved. */
3261 if (Protection_from_shape_changers) {
3262 mcham = (int) mon->cham;
3263 if (mcham >= LOW_PM) {
3265 (void) newcham(mon, &mons[mcham], FALSE, FALSE);
3266 } else if (is_were(mon->data) && !is_human(mon->data)) {
3269 } else if (mon->cham == NON_PM) {
3270 mon->cham = pm_to_cham(monsndx(mon->data));
3274 /* unwatched hiders may hide again; if so, returns True */
3277 register struct monst *mtmp;
3281 if (mtmp->mcan || M_AP_TYPE(mtmp) || cansee(mtmp->mx, mtmp->my)
3282 || rn2(3) || mtmp == u.ustuck
3283 /* can't hide while trapped except in pits */
3284 || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
3285 && !is_pit(t->ttyp))
3286 || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
3289 if (mtmp->data->mlet == S_MIMIC) {
3290 set_mimic_sym(mtmp);
3292 } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) {
3293 mtmp->mundetected = 1;
3300 /* monster/hero tries to hide under something at the current location */
3306 boolean undetected = FALSE, is_u = (mtmp == &youmonst);
3307 xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
3309 if (mtmp == u.ustuck) {
3310 ; /* can't hide if holding you or held by you */
3311 } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
3312 : (mtmp->mtrapped && (t = t_at(x, y)) != 0
3313 && !is_pit(t->ttyp))) {
3314 ; /* can't hide while stuck in a non-pit trap */
3315 } else if (mtmp->data->mlet == S_EEL) {
3316 undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
3317 } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
3318 struct obj *otmp = level.objects[x][y];
3320 /* most monsters won't hide under cockatrice corpse */
3321 if (otmp->nexthere || otmp->otyp != CORPSE
3322 || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp))
3323 || !touch_petrifies(&mons[otmp->corpsenm]))
3328 u.uundetected = undetected;
3330 mtmp->mundetected = undetected;
3334 /* called when returning to a previously visited level */
3339 boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL;
3341 if ((is_hider(mon->data) || hider_under)
3342 && !(mon->mundetected || M_AP_TYPE(mon))) {
3343 xchar x = mon->mx, y = mon->my;
3344 char save_viz = viz_array[y][x];
3346 /* override vision, forcing hero to be unable to see monster's spot */
3347 viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE);
3348 if (is_hider(mon->data))
3349 (void) restrap(mon);
3350 /* try again if mimic missed its 1/3 chance to hide */
3351 if (mon->data->mlet == S_MIMIC && !M_AP_TYPE(mon))
3352 (void) restrap(mon);
3354 (void) hideunder(mon);
3355 viz_array[y][x] = save_viz;
3359 static short *animal_list = 0; /* list of PM values for animal monsters */
3360 static int animal_list_count;
3363 mon_animal_list(construct)
3367 short animal_temp[SPECIAL_PM];
3370 /* if (animal_list) impossible("animal_list already exists"); */
3372 for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
3373 if (is_animal(&mons[i]))
3374 animal_temp[n++] = i;
3375 /* if (n == 0) animal_temp[n++] = NON_PM; */
3377 animal_list = (short *) alloc(n * sizeof *animal_list);
3378 (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp,
3379 n * sizeof *animal_list);
3380 animal_list_count = n;
3381 } else { /* release */
3383 free((genericptr_t) animal_list), animal_list = 0;
3384 animal_list_count = 0;
3394 mon_animal_list(TRUE);
3396 res = animal_list[rn2(animal_list_count)];
3397 /* rogue level should use monsters represented by uppercase letters
3398 only, but since chameleons aren't generated there (not uppercase!)
3399 we don't perform a lot of retries */
3400 if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet))
3401 res = animal_list[rn2(animal_list_count)];
3406 decide_to_shapeshift(mon, shiftflags)
3410 struct permonst *ptr = 0;
3412 unsigned was_female = mon->female;
3413 boolean msg = FALSE, dochng = FALSE;
3415 if ((shiftflags & SHIFT_MSG)
3416 || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon)))
3419 if (!is_vampshifter(mon)) {
3420 /* regular shapeshifter */
3424 /* The vampire has to be in good health (mhp) to maintain
3427 * If we're shifted and getting low on hp, maybe shift back, or
3428 * if we're a fog cloud at full hp, maybe pick a different shape.
3429 * If we're not already shifted and in good health, maybe shift.
3431 if (mon->data->mlet != S_VAMPIRE) {
3432 if ((mon->mhp <= (mon->mhpmax + 5) / 6) && rn2(4)
3433 && mon->cham >= LOW_PM) {
3434 ptr = &mons[mon->cham];
3436 } else if (mon->data == &mons[PM_FOG_CLOUD]
3437 && mon->mhp == mon->mhpmax && !rn2(4)
3439 || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM)) {
3440 /* if a fog cloud, maybe change to wolf or vampire bat;
3441 those are more likely to take damage--at least when
3442 tame--and then switch back to vampire; they'll also
3443 switch to fog cloud if they encounter a closed door */
3444 mndx = pickvampshape(mon);
3445 if (mndx >= LOW_PM) {
3447 dochng = (ptr != mon->data);
3451 if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6)
3453 || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM))
3454 dochng = TRUE; /* 'ptr' stays Null */
3458 if (newcham(mon, ptr, FALSE, msg) && is_vampshifter(mon)) {
3459 /* for vampshift, override the 10% chance for sex change */
3461 if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr))
3462 mon->female = was_female;
3471 int mndx = mon->cham, wolfchance = 10;
3472 /* avoid picking monsters with lowercase display symbols ('d' for wolf
3473 and 'v' for fog cloud) on rogue level*/
3474 boolean uppercase_only = Is_rogue_level(&u.uz);
3477 case PM_VLAD_THE_IMPALER:
3478 /* ensure Vlad can keep carrying the Candelabrum */
3479 if (mon_has_special(mon))
3480 break; /* leave mndx as is */
3483 case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */
3484 if (!rn2(wolfchance) && !uppercase_only) {
3489 case PM_VAMPIRE: /* any vampire can become fog or bat */
3490 mndx = (!rn2(4) && !uppercase_only) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
3496 /* nonshapechangers who warrant special polymorph handling */
3501 return (mon->isshk || mon->ispriest || mon->isgd
3502 || mon->m_id == quest_status.leader_m_id);
3505 /* restrict certain special monsters (shopkeepers, aligned priests,
3506 vault guards) to forms that allow them to behave sensibly (catching
3507 gold, speaking?) so that they don't need too much extra code */
3509 validspecmon(mon, mndx)
3514 return TRUE; /* caller wants random */
3516 if (!accept_newcham_form(mndx))
3517 return FALSE; /* geno'd or !polyok */
3519 if (isspecmon(mon)) {
3520 struct permonst *ptr = &mons[mndx];
3522 /* reject notake because object manipulation is expected
3523 and nohead because speech capability is expected */
3524 if (notake(ptr) || !has_head(ptr))
3526 /* [should we check ptr->msound here too?] */
3528 return TRUE; /* potential new form is ok */
3531 /* prevent wizard mode user from specifying invalid vampshifter shape */
3533 validvamp(mon, mndx_p, monclass)
3535 int *mndx_p, monclass;
3537 /* simplify caller's usage */
3538 if (!is_vampshifter(mon))
3539 return validspecmon(mon, *mndx_p);
3541 if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD
3542 || *mndx_p == PM_VLAD_THE_IMPALER) {
3543 /* player picked some type of vampire; use mon's self */
3544 *mndx_p = mon->cham;
3547 if (mon->cham == PM_VLAD_THE_IMPALER && mon_has_special(mon)) {
3548 /* Vlad with Candelabrum; override choice, then accept it */
3549 *mndx_p = PM_VLAD_THE_IMPALER;
3552 /* basic vampires can't become wolves; any can become fog or bat
3553 (we don't enforce upper-case only for rogue level here) */
3554 if (*mndx_p == PM_WOLF)
3555 return (boolean) (mon->cham != PM_VAMPIRE);
3556 if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT)
3559 /* if we get here, specific type was no good; try by class */
3562 *mndx_p = mon->cham;
3565 *mndx_p = PM_VAMPIRE_BAT;
3568 *mndx_p = PM_FOG_CLOUD;
3571 if (mon->cham != PM_VAMPIRE) {
3580 return (boolean) (*mndx_p != NON_PM);
3584 select_newcham_form(mon)
3587 int mndx = NON_PM, tryct;
3589 switch (mon->cham) {
3592 mndx = pick_nasty();
3594 case PM_DOPPELGANGER:
3596 mndx = pick_nasty();
3597 } else if (rn2(3)) { /* role monsters */
3598 mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
3599 } else if (!rn2(3)) { /* quest guardians */
3600 mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT);
3601 /* avoid own role's guardian */
3602 if (mndx == urole.guardnum)
3604 } else { /* general humanoids */
3607 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3608 if (humanoid(&mons[mndx]) && polyok(&mons[mndx]))
3610 } while (--tryct > 0);
3617 mndx = pick_animal();
3619 case PM_VLAD_THE_IMPALER:
3620 case PM_VAMPIRE_LORD:
3622 mndx = pickvampshape(mon);
3624 case NON_PM: /* ordinary */
3626 struct obj *m_armr = which_armor(mon, W_ARM);
3628 if (m_armr && Is_dragon_scales(m_armr))
3629 mndx = (int) (Dragon_scales_to_pm(m_armr) - mons);
3630 else if (m_armr && Is_dragon_mail(m_armr))
3631 mndx = (int) (Dragon_mail_to_pm(m_armr) - mons);
3636 /* for debugging: allow control of polymorphed monster */
3637 if (wizard && iflags.mon_polycontrol) {
3638 char pprompt[BUFSZ], buf[BUFSZ] = DUMMY;
3641 Sprintf(pprompt, "Change %s @ %s into what kind of monster?",
3643 coord_desc((int) mon->mx, (int) mon->my, buf,
3644 (iflags.getpos_coords != GPCOORDS_NONE)
3645 ? iflags.getpos_coords : GPCOORDS_MAP));
3649 getlin(pprompt, buf);
3651 /* for ESC, take form selected above (might be NON_PM) */
3654 /* for "*", use NON_PM to pick an arbitrary shape below */
3655 if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
3659 mndx = name_to_mon(buf);
3660 if (mndx == NON_PM) {
3661 /* didn't get a type, so check whether it's a class
3662 (single letter or text match with def_monsyms[]) */
3663 monclass = name_to_monclass(buf, &mndx);
3664 if (monclass && mndx == NON_PM)
3665 mndx = mkclass_poly(monclass);
3667 if (mndx >= LOW_PM) {
3668 /* got a specific type of monster; use it if we can */
3669 if (validvamp(mon, &mndx, monclass))
3671 /* can't; revert to random in case we exhaust tryct */
3675 pline("It can't become that.");
3676 } while (--tryct > 0);
3678 pline1(thats_enough_tries);
3679 if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass))
3680 mndx = pickvampshape(mon); /* don't resort to arbitrary */
3683 /* if no form was specified above, pick one at random now */
3684 if (mndx == NON_PM) {
3687 mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
3688 } while (--tryct > 0 && !validspecmon(mon, mndx)
3689 /* try harder to select uppercase monster on rogue level */
3690 && (tryct > 40 && Is_rogue_level(&u.uz)
3691 && !isupper((uchar) mons[mndx].mlet)));
3696 /* this used to be inline within newcham() but monpolycontrol needs it too */
3697 STATIC_OVL struct permonst *
3698 accept_newcham_form(mndx)
3701 struct permonst *mdat;
3706 if ((mvitals[mndx].mvflags & G_GENOD) != 0)
3708 if (is_placeholder(mdat))
3710 /* select_newcham_form() might deliberately pick a player
3711 character type (random selection never does) which
3712 polyok() rejects, so we need a special case here */
3713 if (is_mplayer(mdat))
3715 /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */
3716 return polyok(mdat) ? mdat : 0;
3720 mgender_from_permonst(mtmp, mdat)
3722 struct permonst *mdat;
3724 if (is_male(mdat)) {
3726 mtmp->female = FALSE;
3727 } else if (is_female(mdat)) {
3729 mtmp->female = TRUE;
3730 } else if (!is_neuter(mdat)) {
3732 mtmp->female = !mtmp->female;
3736 /* make a chameleon take on another shape, or a polymorph target
3737 (possibly self-inflicted) become a different monster;
3738 returns 1 if it actually changes form */
3740 newcham(mtmp, mdat, polyspot, msg)
3742 struct permonst *mdat;
3743 boolean polyspot; /* change is the result of wand or spell of polymorph */
3744 boolean msg; /* "The oldmon turns into a newmon!" */
3748 struct permonst *olddata = mtmp->data;
3749 char *p, oldname[BUFSZ], l_oldname[BUFSZ], newname[BUFSZ];
3751 /* Riders are immune to polymorph and green slime
3752 (but apparent Rider might actually be a doppelganger) */
3753 if (mtmp->cham == NON_PM) { /* not a shapechanger */
3754 if (is_rider(olddata))
3756 /* make Nazgul and erinyes immune too, to reduce chance of
3757 anomalous extinction feedback during final disclsoure */
3758 if (mbirth_limit(monsndx(olddata)) < MAXMONNO)
3760 /* cancelled shapechangers become uncancelled prior
3761 to being given a new shape */
3762 if (mtmp->mcan && !Protection_from_shape_changers) {
3763 mtmp->cham = pm_to_cham(monsndx(mtmp->data));
3764 if (mtmp->cham != NON_PM)
3770 /* like Monnam() but never mention saddle */
3771 Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3772 SUPPRESS_SADDLE, FALSE));
3773 oldname[0] = highc(oldname[0]);
3775 /* we need this one whether msg is true or not */
3776 Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
3777 has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE));
3779 /* mdat = 0 -> caller wants a random monster shape */
3781 /* select_newcham_form() loops when resorting to random but
3782 it doesn't always pick that so we still retry here too */
3785 mndx = select_newcham_form(mtmp);
3786 mdat = accept_newcham_form(mndx);
3787 /* for the first several tries we require upper-case on
3788 the rogue level (after that, we take whatever we get) */
3789 if (tryct > 15 && Is_rogue_level(&u.uz)
3790 && mdat && !isupper((uchar) mdat->mlet))
3794 } while (--tryct > 0);
3797 } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
3798 return 0; /* passed in mdat is genocided */
3800 if (mdat == olddata)
3801 return 0; /* still the same monster */
3803 mgender_from_permonst(mtmp, mdat);
3804 /* Endgame mplayers start out as "Foo the Bar", but some of the
3805 * titles are inappropriate when polymorphed, particularly into
3806 * the opposite sex. Player characters don't use ranks when
3807 * polymorphed, so dropping rank for mplayers seems reasonable.
3809 if (In_endgame(&u.uz) && is_mplayer(olddata)
3810 && has_mname(mtmp) && (p = strstr(MNAME(mtmp), " the ")) != 0)
3813 if (mtmp->wormno) { /* throw tail away */
3815 place_monster(mtmp, mtmp->mx, mtmp->my);
3817 if (M_AP_TYPE(mtmp) && mdat->mlet != S_MIMIC)
3818 seemimic(mtmp); /* revert to normal monster */
3820 /* (this code used to try to adjust the monster's health based on
3821 a normal one of its type but there are too many special cases
3822 which need to handled in order to do that correctly, so just
3823 give the new form the same proportion of HP as its old one had) */
3826 /* set level and hit points */
3827 newmonhp(mtmp, monsndx(mdat));
3828 /* new hp: same fraction of max as before */
3830 mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd);
3832 /* sanity check (potential overflow) */
3833 if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax)
3834 mtmp->mhp = mtmp->mhpmax;
3835 /* unlikely but not impossible; a 1HD creature with 1HP that changes
3836 into a 0HD creature will require this statement */
3840 /* take on the new form... */
3841 set_mon_data(mtmp, mdat);
3843 if (emits_light(olddata) != emits_light(mtmp->data)) {
3844 /* used to give light, now doesn't, or vice versa,
3845 or light's range has changed */
3846 if (emits_light(olddata))
3847 del_light_source(LS_MONSTER, monst_to_any(mtmp));
3848 if (emits_light(mtmp->data))
3849 new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
3850 LS_MONSTER, monst_to_any(mtmp));
3852 if (!mtmp->perminvis || pm_invisible(olddata))
3853 mtmp->perminvis = pm_invisible(mdat);
3854 mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
3855 if (mtmp->mundetected)
3856 (void) hideunder(mtmp);
3857 if (u.ustuck == mtmp) {
3859 if (!attacktype(mdat, AT_ENGL)) {
3860 /* Does mdat care? */
3861 if (!noncorporeal(mdat) && !amorphous(mdat)
3862 && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) {
3863 char msgtrail[BUFSZ];
3865 if (is_vampshifter(mtmp)) {
3867 Sprintf(msgtrail, " which was a shapeshifted %s",
3868 noname_monnam(mtmp, ARTICLE_NONE));
3870 Sprintf(msgtrail, "(
\8eÀ
\8dÛ
\82É
\82Í
\8c`
\82ð
\95Ï
\82¦
\82½%s)",
3871 noname_monnam(mtmp, ARTICLE_NONE));
3873 } else if (is_animal(mdat)) {
3875 Strcpy(msgtrail, "'s stomach");
3877 Strcpy(msgtrail, "
\82Ì
\88Ý");
3882 /* Do this even if msg is FALSE */
3885 (amorphous(olddata) || is_whirly(olddata))
3886 ? "emerge from" : "break out of",
3887 l_oldname, msgtrail);
3889 You("%s%s%s
\81I", l_oldname, msgtrail,
3890 (amorphous(olddata) || is_whirly(olddata))
3891 ? "
\82©
\82ç
\94ò
\82Ñ
\8fo
\82µ
\82½" : "
\82ð
\94j
\82è
\8fo
\82½"
3894 msg = FALSE; /* message has been given */
3895 mtmp->mhp = 1; /* almost dead */
3897 expels(mtmp, olddata, FALSE);
3899 /* update swallow glyphs for new monster */
3902 } else if (!sticks(mdat) && !sticks(youmonst.data))
3907 if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
3909 /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
3912 if (mdat == &mons[PM_LONG_WORM]
3913 && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
3915 /* we can now create worms with tails - 11/91 */
3916 initworm(mtmp, rn2(5));
3917 place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
3920 newsym(mtmp->mx, mtmp->my);
3923 Strcpy(newname, noname_monnam(mtmp, ARTICLE_A));
3924 /* oldname was capitalized above; newname will be lower case */
3926 if (!strcmpi(newname, "it")) { /* can't see or sense it now */
3928 if (!strcmpi(newname, "
\89½
\8eÒ
\82©")) { /* can't see or sense it now */
3931 if (!!strcmpi(oldname, "it")) /* could see or sense it before */
3933 if (!!strcmpi(oldname, "
\89½
\8eÒ
\82©")) /* could see or sense it before */
3935 pline("%s disappears!", oldname);
3936 (void) usmellmon(mdat);
3937 } else { /* can see or sense it now */
3939 if (!strcmpi(oldname, "it")) /* couldn't see or sense it before */
3941 if (!strcmpi(oldname, "
\89½
\8eÒ
\82©")) /* couldn't see or sense it before */
3943 pline("%s appears!", upstart(newname));
3946 pline("%s turns into %s!", oldname, newname);
3948 pline("%s
\82Í%s
\82É
\82È
\82Á
\82½
\81I", oldname, newname);
3952 /* when polymorph trap/wand/potion produces a vampire, turn in into
3953 a full-fledged vampshifter unless shape-changing is blocked */
3954 if (mtmp->cham == NON_PM && mdat->mlet == S_VAMPIRE
3955 && !Protection_from_shape_changers)
3956 mtmp->cham = pm_to_cham(monsndx(mdat));
3958 possibly_unwield(mtmp, polyspot); /* might lose use of weapon */
3959 mon_break_armor(mtmp, polyspot);
3960 if (!(mtmp->misc_worn_check & W_ARMG))
3962 mselftouch(mtmp, "No longer petrify-resistant, ",
3963 !context.mon_moving);
3965 mselftouch(mtmp, "
\90Î
\89»
\82Ö
\82Ì
\92ï
\8dR
\97Í
\82ª
\82È
\82
\82È
\82Á
\82Ä
\81C",
3966 !context.mon_moving);
3968 m_dowear(mtmp, FALSE);
3970 /* This ought to re-test can_carry() on each item in the inventory
3971 * rather than just checking ex-giants & boulders, but that'd be
3972 * pretty expensive to perform. If implemented, then perhaps
3973 * minvent should be sorted in order to drop heaviest items first.
3975 /* former giants can't continue carrying boulders */
3976 if (mtmp->minvent && !throws_rocks(mdat)) {
3977 register struct obj *otmp, *otmp2;
3979 for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
3981 if (otmp->otyp == BOULDER) {
3982 /* this keeps otmp from being polymorphed in the
3983 same zap that the monster that held it is polymorphed */
3986 obj_extract_self(otmp);
3987 /* probably ought to give some "drop" message here */
3988 if (flooreffects(otmp, mtmp->mx, mtmp->my, ""))
3990 place_object(otmp, mtmp->mx, mtmp->my);
3998 /* sometimes an egg will be special */
3999 #define BREEDER_EGG (!rn2(77))
4002 * Determine if the given monster number can be hatched from an egg.
4003 * Return the monster number to use as the egg's corpsenm. Return
4004 * NON_PM if the given monster can't be hatched.
4007 can_be_hatched(mnum)
4010 /* ranger quest nemesis has the oviparous bit set, making it
4011 be possible to wish for eggs of that unique monster; turn
4012 such into ordinary eggs rather than forbidding them outright */
4013 if (mnum == PM_SCORPIUS)
4016 mnum = little_to_big(mnum);
4018 * Queen bees lay killer bee eggs (usually), but killer bees don't
4019 * grow into queen bees. Ditto for [winged-]gargoyles.
4021 if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE
4022 || (lays_eggs(&mons[mnum])
4024 || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
4029 /* type of egg laid by #sit; usually matches parent */
4031 egg_type_from_parent(mnum, force_ordinary)
4032 int mnum; /* parent monster; caller must handle lays_eggs() check */
4033 boolean force_ordinary;
4035 if (force_ordinary || !BREEDER_EGG) {
4036 if (mnum == PM_QUEEN_BEE)
4037 mnum = PM_KILLER_BEE;
4038 else if (mnum == PM_WINGED_GARGOYLE)
4044 /* decide whether an egg of the indicated monster type is viable;
4045 also used to determine whether an egg or tin can be created... */
4047 dead_species(m_idx, egg)
4053 /* generic eggs are unhatchable and have corpsenm of NON_PM */
4057 * For monsters with both baby and adult forms, genociding either
4058 * form kills all eggs of that monster. Monsters with more than
4059 * two forms (small->large->giant mimics) are more or less ignored;
4060 * fortunately, none of them have eggs. Species extinction due to
4061 * overpopulation does not kill eggs.
4063 alt_idx = egg ? big_to_little(m_idx) : m_idx;
4064 return (boolean) ((mvitals[m_idx].mvflags & G_GENOD) != 0
4065 || (mvitals[alt_idx].mvflags & G_GENOD) != 0);
4068 /* kill off any eggs of genocided monsters */
4071 struct obj *obj_list;
4075 for (otmp = obj_list; otmp; otmp = otmp->nobj)
4076 if (otmp->otyp == EGG) {
4077 if (dead_species(otmp->corpsenm, TRUE)) {
4079 * It seems we could also just catch this when
4080 * it attempted to hatch, so we wouldn't have to
4081 * search all of the objlists.. or stop all
4082 * hatch timers based on a corpsenm.
4086 #if 0 /* not used */
4087 } else if (otmp->otyp == TIN) {
4088 if (dead_species(otmp->corpsenm, FALSE))
4089 otmp->corpsenm = NON_PM; /* empty tin */
4090 } else if (otmp->otyp == CORPSE) {
4091 if (dead_species(otmp->corpsenm, FALSE))
4092 ; /* not yet implemented... */
4094 } else if (Has_contents(otmp)) {
4095 kill_eggs(otmp->cobj);
4099 /* kill all members of genocided species */
4101 kill_genocided_monsters()
4103 struct monst *mtmp, *mtmp2;
4108 * Called during genocide, and again upon level change. The latter
4109 * catches up with any migrating monsters as they finally arrive at
4110 * their intended destinations, so possessions get deposited there.
4112 * Chameleon handling:
4113 * 1) if chameleons have been genocided, destroy them
4114 * regardless of current form;
4115 * 2) otherwise, force every chameleon which is imitating
4116 * any genocided species to take on a new form.
4118 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
4120 if (DEADMONSTER(mtmp))
4122 mndx = monsndx(mtmp->data);
4123 kill_cham = (mtmp->cham >= LOW_PM
4124 && (mvitals[mtmp->cham].mvflags & G_GENOD));
4125 if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) {
4126 if (mtmp->cham >= LOW_PM && !kill_cham)
4127 (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
4132 kill_eggs(mtmp->minvent);
4137 kill_eggs(migrating_objs);
4138 kill_eggs(level.buriedobjlist);
4142 golemeffects(mon, damtype, dam)
4143 register struct monst *mon;
4146 int heal = 0, slow = 0;
4148 if (mon->data == &mons[PM_FLESH_GOLEM]) {
4149 if (damtype == AD_ELEC)
4150 heal = (dam + 5) / 6;
4151 else if (damtype == AD_FIRE || damtype == AD_COLD)
4153 } else if (mon->data == &mons[PM_IRON_GOLEM]) {
4154 if (damtype == AD_ELEC)
4156 else if (damtype == AD_FIRE)
4162 if (mon->mspeed != MSLOW)
4163 mon_adjust_speed(mon, -1, (struct obj *) 0);
4166 if (mon->mhp < mon->mhpmax) {
4168 if (mon->mhp > mon->mhpmax)
4169 mon->mhp = mon->mhpmax;
4170 if (cansee(mon->mx, mon->my))
4172 pline("%s seems healthier.", Monnam(mon));
4174 pline("%s
\82Í
\8c³
\8bC
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81D", Monnam(mon));
4180 angry_guards(silent)
4184 int ct = 0, nct = 0, sct = 0, slct = 0;
4186 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4187 if (DEADMONSTER(mtmp))
4189 if (is_watch(mtmp->data) && mtmp->mpeaceful) {
4191 if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
4192 if (distu(mtmp->mx, mtmp->my) == 2)
4197 if (mtmp->msleeping || mtmp->mfrozen) {
4199 mtmp->msleeping = mtmp->mfrozen = 0;
4201 mtmp->mpeaceful = 0;
4205 if (!silent) { /* do we want pline msgs? */
4208 pline_The("guard%s wake%s up!", slct > 1 ? "s" : "",
4209 slct == 1 ? "s" : "");
4211 pline("
\94Ô
\95º
\82Í
\96Ú
\82ð
\8ao
\82Ü
\82µ
\82½
\81I");
4216 pline_The("guard%s get%s angry!", nct == 1 ? "" : "s",
4217 nct == 1 ? "s" : "");
4219 pline("
\94Ô
\95º
\82Í
\93{
\82Á
\82½
\81I");
4223 You_see("%sangry guard%s approaching!",
4224 sct == 1 ? "an " : "", sct > 1 ? "s" : "");
4226 You("
\93{
\82Á
\82½
\94Ô
\95º
\82ª
\8bß
\8añ
\82Á
\82Ä
\82
\82é
\82Ì
\82ð
\8c©
\82½
\81I");
4230 You_hear("the shrill sound of a guard's whistle.");
4232 You_hear("
\94Ô
\95º
\82Ì
\93J
\82ª
\82¯
\82½
\82½
\82Ü
\82µ
\82
\96Â
\82é
\82Ì
\82ð
\95·
\82¢
\82½
\81D");
4244 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
4245 if (DEADMONSTER(mtmp))
4247 if (is_watch(mtmp->data))
4248 mtmp->mpeaceful = 1;
4253 mimic_hit_msg(mtmp, otyp)
4257 short ap = mtmp->mappearance;
4259 switch (M_AP_TYPE(mtmp)) {
4261 case M_AP_FURNITURE:
4265 if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
4267 pline("%s seems a more vivid %s than before.",
4268 The(simple_typename(ap)),
4269 c_obj_colors[objects[ap].oc_color]);
4271 pline("%s
\82Í
\88È
\91O
\82æ
\82è
\82æ
\82è
\91N
\82â
\82©
\82È%s
\82É
\82È
\82Á
\82½
\82æ
\82¤
\82¾
\81D",
4272 The(simple_typename(ap)),
4273 c_obj_colors[objects[ap].oc_color]);
4282 struct permonst *mdat;
4285 boolean nonspecific = FALSE;
4286 boolean msg_given = FALSE;
4289 if (!olfaction(youmonst.data))
4291 mndx = monsndx(mdat);
4296 You("notice a bovine smell.");
4298 You("
\8b\8d\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4304 case PM_NEANDERTHAL:
4306 You("smell body odor.");
4308 pline("
\91Ì
\8fL
\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4317 case PM_HORNED_DEVIL:
4324 case PM_HUMAN_WEREJACKAL:
4325 case PM_HUMAN_WERERAT:
4326 case PM_HUMAN_WEREWOLF:
4332 You("detect an odor reminiscent of an animal's den.");
4334 pline("
\93®
\95¨
\82Ì
\82Ë
\82®
\82ç
\82ð
\8ev
\82¢
\8fo
\82·
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4338 case PM_PURPLE_WORM:
4341 case PM_STEAM_VORTEX:
4343 You("smell steam.");
4345 pline("
\8fö
\8bC
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4348 case PM_GREEN_SLIME:
4350 pline("%s stinks.", Something);
4352 pline("
\88«
\8fL
\82ª
\82µ
\82½
\81D");
4355 case PM_VIOLET_FUNGUS:
4358 You("smell mushrooms.");
4360 pline("
\82«
\82Ì
\82±
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4363 /* These are here to avoid triggering the
4364 nonspecific treatment through the default case below*/
4365 case PM_WHITE_UNICORN:
4366 case PM_GRAY_UNICORN:
4367 case PM_BLACK_UNICORN:
4376 switch (mdat->mlet) {
4379 You("notice a dog smell.");
4381 You("
\8c¢
\82Ì
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4386 You("smell a dragon!");
4388 pline("
\83h
\83\89\83S
\83\93\82Ì
\82É
\82¨
\82¢
\82ª
\82·
\82é
\81I");
4393 pline("%s smells moldy.", Something);
4395 pline("
\89½
\82©
\91Û
\82Ì
\82æ
\82¤
\82È
\82É
\82¨
\82¢
\82ª
\82·
\82é
\81D");
4400 You("detect a%s odor reminiscent of a stable.",
4401 (mndx == PM_PONY) ? "n" : " strong");
4403 pline("
\94n
\8f¬
\89®
\82ð
\8ev
\82¢
\8fo
\82·
\82æ
\82¤
\82È%s
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D",
4404 (mndx == PM_PONY) ? "" : "
\8b
\82¢");
4410 You("smell rotting flesh.");
4412 pline("
\95\85\82Á
\82½
\93÷
\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4419 pline("
\8b\9b\82Ì
\82É
\82¨
\82¢
\82ª
\82µ
\82½
\81D");
4423 if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
4425 You("notice an attractive smell.");
4427 You("
\96£
\97Í
\93I
\82È
\82É
\82¨
\82¢
\82É
\8bC
\95t
\82¢
\82½
\81D");
4430 pline("A foul stench makes you feel a little nauseated.");
4432 pline("
\82Þ
\82©
\82Â
\82
\82æ
\82¤
\82È
\88«
\8fL
\82Å
\8f
\82µ
\8bC
\95ª
\82ª
\88«
\82
\82È
\82Á
\82½
\81D");
4439 return msg_given ? TRUE : FALSE;