1 /* SCCS Id: @(#)makemon.c 3.4 2003/09/06 */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
13 STATIC_VAR NEARDATA struct monst zeromonst;
15 /* this assumes that a human quest leader or nemesis is an archetype
16 of the corresponding role; that isn't so for some roles (tourist
17 for instance) but is for the priests and monks we use it for... */
18 #define quest_mon_represents_role(mptr,role_pm) \
19 (mptr->mlet == S_HUMAN && Role_if(role_pm) && \
20 (mptr->msound == MS_LEADER || mptr->msound == MS_NEMESIS))
23 STATIC_DCL boolean FDECL(uncommon, (int));
24 STATIC_DCL int FDECL(align_shift, (struct permonst *));
26 STATIC_DCL boolean FDECL(wrong_elem_type, (struct permonst *));
27 STATIC_DCL void FDECL(m_initgrp,(struct monst *,int,int,int));
28 STATIC_DCL void FDECL(m_initthrow,(struct monst *,int,int));
29 STATIC_DCL void FDECL(m_initweap,(struct monst *));
31 STATIC_DCL void FDECL(m_initinv,(struct monst *));
34 extern const int monstr[];
36 #define m_initsgrp(mtmp, x, y) m_initgrp(mtmp, x, y, 3)
37 #define m_initlgrp(mtmp, x, y) m_initgrp(mtmp, x, y, 10)
38 #define toostrong(monindx, lev) (monstr[monindx] > lev)
39 #define tooweak(monindx, lev) (monstr[monindx] < lev)
43 is_home_elemental(ptr)
44 register struct permonst *ptr;
46 if (ptr->mlet == S_ELEMENTAL)
47 switch (monsndx(ptr)) {
48 case PM_AIR_ELEMENTAL: return Is_airlevel(&u.uz);
49 case PM_FIRE_ELEMENTAL: return Is_firelevel(&u.uz);
50 case PM_EARTH_ELEMENTAL: return Is_earthlevel(&u.uz);
51 case PM_WATER_ELEMENTAL: return Is_waterlevel(&u.uz);
57 * Return true if the given monster cannot exist on this elemental level.
61 register struct permonst *ptr;
63 if (ptr->mlet == S_ELEMENTAL) {
64 return((boolean)(!is_home_elemental(ptr)));
65 } else if (Is_earthlevel(&u.uz)) {
66 /* no restrictions? */
67 } else if (Is_waterlevel(&u.uz)) {
68 /* just monsters that can swim */
69 if(!is_swimmer(ptr)) return TRUE;
70 } else if (Is_firelevel(&u.uz)) {
71 if (!pm_resistance(ptr,MR_FIRE)) return TRUE;
72 } else if (Is_airlevel(&u.uz)) {
73 if(!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr)
74 && !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr))
81 m_initgrp(mtmp, x, y, n) /* make a group just like mtmp */
82 register struct monst *mtmp;
86 register int cnt = rnd(n);
88 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
89 /* There is an unresolved problem with several people finding that
90 * the game hangs eating CPU; if interrupted and restored, the level
91 * will be filled with monsters. Of those reports giving system type,
92 * there were two DG/UX and two HP-UX, all using gcc as the compiler.
93 * hcroft@hpopb1.cern.ch, using gcc 2.6.3 on HP-UX, says that the
94 * problem went away for him and another reporter-to-newsgroup
95 * after adding this debugging code. This has almost got to be a
96 * compiler bug, but until somebody tracks it down and gets it fixed,
97 * might as well go with the "but it went away when I tried to find
104 pline("init group call x=%d,y=%d,n=%d,cnt=%d.", x, y, n, cnt);
106 cntdiv = ((u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1);
108 /* Tuning: cut down on swarming at low character levels [mrs] */
109 cnt /= (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1;
110 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
111 if (cnt != (cnttmp/cntdiv)) {
112 pline("cnt=%d using %d, cnttmp=%d, cntdiv=%d", cnt,
113 (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1,
118 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
119 if (cnt < 0) cnt = 1;
120 if (cnt > 10) cnt = 10;
126 if (peace_minded(mtmp->data)) continue;
127 /* Don't create groups of peaceful monsters since they'll get
128 * in our way. If the monster has a percentage chance so some
129 * are peaceful and some are not, the result will just be a
132 if (enexto(&mm, mm.x, mm.y, mtmp->data)) {
133 mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS);
134 mon->mpeaceful = FALSE;
137 /* Undo the second peace_minded() check in makemon(); if the
138 * monster turned out to be peaceful the first time we
139 * didn't create it at all; we don't want a second check.
147 m_initthrow(mtmp,otyp,oquan)
151 register struct obj *otmp;
153 otmp = mksobj(otyp, TRUE, FALSE);
154 otmp->quan = (long) rn1(oquan, 3);
155 otmp->owt = weight(otmp);
156 if (otyp == ORCISH_ARROW) otmp->opoisoned = TRUE;
157 (void) mpickobj(mtmp, otmp);
165 register struct monst *mtmp;
167 register struct permonst *ptr = mtmp->data;
168 register int mm = monsndx(ptr);
172 if (Is_rogue_level(&u.uz)) return;
175 * first a few special cases:
177 * giants get a boulder to throw sometimes.
179 * kobolds get darts to throw
180 * centaurs get some sort of bow & arrows or bolts
181 * soldiers get all sorts of things.
182 * kops get clubs & cream pies.
186 if (rn2(2)) (void)mongets(mtmp, (mm != PM_ETTIN) ?
190 if(is_mercenary(ptr)) {
197 w1 = rn1(BEC_DE_CORBIN - PARTISAN + 1, PARTISAN);
198 w2 = rn2(2) ? DAGGER : KNIFE;
199 } else w1 = rn2(2) ? SPEAR : SHORT_SWORD;
202 w1 = rn2(2) ? FLAIL : MACE;
205 w1 = rn2(2) ? BROADSWORD : LONG_SWORD;
208 case PM_WATCH_CAPTAIN:
209 w1 = rn2(2) ? LONG_SWORD : SILVER_SABER;
212 if (!rn2(4)) w1 = DAGGER;
213 if (!rn2(7)) w2 = SPEAR;
216 if (w1) (void)mongets(mtmp, w1);
217 if (!w2 && w1 != DAGGER && !rn2(4)) w2 = KNIFE;
218 if (w2) (void)mongets(mtmp, w2);
219 } else if (is_elf(ptr)) {
222 rn2(2) ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK);
223 if (rn2(2)) (void)mongets(mtmp, ELVEN_LEATHER_HELM);
224 else if (!rn2(4)) (void)mongets(mtmp, ELVEN_BOOTS);
225 if (rn2(2)) (void)mongets(mtmp, ELVEN_DAGGER);
228 if (!rn2(4)) (void)mongets(mtmp, ELVEN_SHIELD);
229 if (rn2(3)) (void)mongets(mtmp, ELVEN_SHORT_SWORD);
230 (void)mongets(mtmp, ELVEN_BOW);
231 m_initthrow(mtmp, ELVEN_ARROW, 12);
234 (void)mongets(mtmp, ELVEN_BROADSWORD);
235 if (rn2(2)) (void)mongets(mtmp, ELVEN_SHIELD);
239 (void)mongets(mtmp, ELVEN_SPEAR);
240 (void)mongets(mtmp, ELVEN_SHIELD);
244 if (mm == PM_ELVENKING) {
245 if (rn2(3) || (in_mklev && Is_earthlevel(&u.uz)))
246 (void)mongets(mtmp, PICK_AXE);
247 if (!rn2(50)) (void)mongets(mtmp, CRYSTAL_BALL);
249 } else if (ptr->msound == MS_PRIEST ||
250 quest_mon_represents_role(ptr,PM_PRIEST)) {
251 otmp = mksobj(MACE, FALSE, FALSE);
254 if(!rn2(2)) curse(otmp);
255 (void) mpickobj(mtmp, otmp);
264 /* create minion stuff; can't use mongets */
265 otmp = mksobj(LONG_SWORD, FALSE, FALSE);
267 /* maybe make it special */
268 if (!rn2(20) || is_lord(ptr))
269 otmp = oname(otmp, artiname(
270 rn2(2) ? ART_DEMONBANE : ART_SUNSWORD));
272 otmp->oerodeproof = TRUE;
274 otmp->spe = max(otmp->spe, spe2);
275 (void) mpickobj(mtmp, otmp);
277 otmp = mksobj(!rn2(4) || is_lord(ptr) ?
278 SHIELD_OF_REFLECTION : LARGE_SHIELD,
280 otmp->cursed = FALSE;
281 otmp->oerodeproof = TRUE;
283 (void) mpickobj(mtmp, otmp);
288 if (mm == PM_HOBBIT) {
291 (void)mongets(mtmp, DAGGER);
294 (void)mongets(mtmp, ELVEN_DAGGER);
297 (void)mongets(mtmp, SLING);
300 if (!rn2(10)) (void)mongets(mtmp, ELVEN_MITHRIL_COAT);
301 if (!rn2(10)) (void)mongets(mtmp, DWARVISH_CLOAK);
302 } else if (is_dwarf(ptr)) {
303 if (rn2(7)) (void)mongets(mtmp, DWARVISH_CLOAK);
304 if (rn2(7)) (void)mongets(mtmp, IRON_SHOES);
306 (void)mongets(mtmp, DWARVISH_SHORT_SWORD);
307 /* note: you can't use a mattock with a shield */
308 if (rn2(2)) (void)mongets(mtmp, DWARVISH_MATTOCK);
310 (void)mongets(mtmp, AXE);
311 (void)mongets(mtmp, DWARVISH_ROUNDSHIELD);
313 (void)mongets(mtmp, DWARVISH_IRON_HELM);
315 (void)mongets(mtmp, DWARVISH_MITHRIL_COAT);
317 (void)mongets(mtmp, !rn2(3) ? PICK_AXE : DAGGER);
322 case S_KOP: /* create Keystone Kops with cream pies to
323 * throw. As suggested by KAA. [MRS]
325 if (!rn2(4)) m_initthrow(mtmp, CREAM_PIE, 2);
326 if (!rn2(3)) (void)mongets(mtmp,(rn2(2)) ? CLUB : RUBBER_HOSE);
330 if(rn2(2)) (void)mongets(mtmp, ORCISH_HELM);
331 switch (mm != PM_ORC_CAPTAIN ? mm :
332 rn2(2) ? PM_MORDOR_ORC : PM_URUK_HAI) {
334 if(!rn2(3)) (void)mongets(mtmp, SCIMITAR);
335 if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHIELD);
336 if(!rn2(3)) (void)mongets(mtmp, KNIFE);
337 if(!rn2(3)) (void)mongets(mtmp, ORCISH_CHAIN_MAIL);
340 if(!rn2(3)) (void)mongets(mtmp, ORCISH_CLOAK);
341 if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHORT_SWORD);
342 if(!rn2(3)) (void)mongets(mtmp, IRON_SHOES);
344 (void)mongets(mtmp, ORCISH_BOW);
345 m_initthrow(mtmp, ORCISH_ARROW, 12);
347 if(!rn2(3)) (void)mongets(mtmp, URUK_HAI_SHIELD);
350 if (mm != PM_ORC_SHAMAN && rn2(2))
351 (void)mongets(mtmp, (mm == PM_GOBLIN || rn2(2) == 0)
352 ? ORCISH_DAGGER : SCIMITAR);
356 if (!rn2(mm == PM_OGRE_KING ? 3 : mm == PM_OGRE_LORD ? 6 : 12))
357 (void) mongets(mtmp, BATTLE_AXE);
359 (void) mongets(mtmp, CLUB);
362 if (!rn2(2)) switch (rn2(4)) {
363 case 0: (void)mongets(mtmp, RANSEUR); break;
364 case 1: (void)mongets(mtmp, PARTISAN); break;
365 case 2: (void)mongets(mtmp, GLAIVE); break;
366 case 3: (void)mongets(mtmp, SPETUM); break;
370 if (!rn2(4)) m_initthrow(mtmp, DART, 12);
375 if(ptr == &mons[PM_FOREST_CENTAUR]) {
376 (void)mongets(mtmp, BOW);
377 m_initthrow(mtmp, ARROW, 12);
379 (void)mongets(mtmp, CROSSBOW);
380 m_initthrow(mtmp, CROSSBOW_BOLT, 12);
385 (void)mongets(mtmp, KNIFE);
386 (void)mongets(mtmp, LONG_SWORD);
389 if (!rn2(4)) (void)mongets(mtmp, LEATHER_ARMOR);
391 (void)mongets(mtmp, (rn2(3) ? KNIFE : SHORT_SWORD));
394 if (mm == PM_SALAMANDER)
395 (void)mongets(mtmp, (rn2(7) ? SPEAR : rn2(3) ?
396 TRIDENT : STILETTO));
401 (void)mongets(mtmp, BULLWHIP);
402 (void)mongets(mtmp, BROADSWORD);
405 (void)mongets(mtmp, WAN_DEATH); /* the Wand of Orcus */
407 case PM_HORNED_DEVIL:
408 (void)mongets(mtmp, rn2(4) ? TRIDENT : BULLWHIP);
411 (void)mongets(mtmp, WAN_STRIKING);
414 (void)mongets(mtmp, FLAIL);
417 /* prevent djinnis and mail daemons from leaving objects when
420 if (!is_demon(ptr)) break;
423 * Now the general case, Some chance of getting some type
424 * of weapon for "normal" monsters. Certain special types
425 * of monsters will get a bonus chance or different selections.
431 bias = is_lord(ptr) + is_prince(ptr) * 2 + extra_nasty(ptr);
432 switch(rnd(14 - (2 * bias))) {
434 if(strongmonst(ptr)) (void) mongets(mtmp, BATTLE_AXE);
435 else m_initthrow(mtmp, DART, 12);
439 (void) mongets(mtmp, TWO_HANDED_SWORD);
441 (void) mongets(mtmp, CROSSBOW);
442 m_initthrow(mtmp, CROSSBOW_BOLT, 12);
446 (void) mongets(mtmp, BOW);
447 m_initthrow(mtmp, ARROW, 12);
450 if(strongmonst(ptr)) (void) mongets(mtmp, LONG_SWORD);
451 else m_initthrow(mtmp, DAGGER, 3);
455 (void) mongets(mtmp, LUCERN_HAMMER);
456 else (void) mongets(mtmp, AKLYS);
464 if ((int) mtmp->m_lev > rn2(75))
465 (void) mongets(mtmp, rnd_offensive_item(mtmp));
473 * Makes up money for monster's inventory.
474 * This will change with silver & copper coins
477 mkmonmoney(mtmp, amount)
481 struct obj *gold = mksobj(GOLD_PIECE, FALSE, FALSE);
483 add_to_minv(mtmp, gold);
489 register struct monst *mtmp;
492 register struct obj *otmp;
493 register struct permonst *ptr = mtmp->data;
495 if (Is_rogue_level(&u.uz)) return;
498 * Soldiers get armour & rations - armour approximates their ac.
499 * Nymphs may get mirror or potion of object detection.
504 if(is_mercenary(ptr)) {
507 switch(monsndx(ptr)) {
508 case PM_GUARD: mac = -1; break;
509 case PM_SOLDIER: mac = 3; break;
510 case PM_SERGEANT: mac = 0; break;
511 case PM_LIEUTENANT: mac = -2; break;
512 case PM_CAPTAIN: mac = -3; break;
513 case PM_WATCHMAN: mac = 3; break;
514 case PM_WATCH_CAPTAIN: mac = -2; break;
515 default: impossible("odd mercenary %d?", monsndx(ptr));
520 if (mac < -1 && rn2(5))
521 mac += 7 + mongets(mtmp, (rn2(5)) ?
522 PLATE_MAIL : CRYSTAL_PLATE_MAIL);
523 else if (mac < 3 && rn2(5))
524 mac += 6 + mongets(mtmp, (rn2(3)) ?
525 SPLINT_MAIL : BANDED_MAIL);
527 mac += 3 + mongets(mtmp, (rn2(3)) ?
528 RING_MAIL : STUDDED_LEATHER_ARMOR);
530 mac += 2 + mongets(mtmp, LEATHER_ARMOR);
532 if (mac < 10 && rn2(3))
533 mac += 1 + mongets(mtmp, HELMET);
534 else if (mac < 10 && rn2(2))
535 mac += 1 + mongets(mtmp, DENTED_POT);
536 if (mac < 10 && rn2(3))
537 mac += 1 + mongets(mtmp, SMALL_SHIELD);
538 else if (mac < 10 && rn2(2))
539 mac += 2 + mongets(mtmp, LARGE_SHIELD);
540 if (mac < 10 && rn2(3))
541 mac += 1 + mongets(mtmp, LOW_BOOTS);
542 else if (mac < 10 && rn2(2))
543 mac += 2 + mongets(mtmp, HIGH_BOOTS);
544 if (mac < 10 && rn2(3))
545 mac += 1 + mongets(mtmp, LEATHER_GLOVES);
546 else if (mac < 10 && rn2(2))
547 mac += 1 + mongets(mtmp, LEATHER_CLOAK);
549 if(ptr != &mons[PM_GUARD] &&
550 ptr != &mons[PM_WATCHMAN] &&
551 ptr != &mons[PM_WATCH_CAPTAIN]) {
552 if (!rn2(3)) (void) mongets(mtmp, K_RATION);
553 if (!rn2(2)) (void) mongets(mtmp, C_RATION);
554 if (ptr != &mons[PM_SOLDIER] && !rn2(3))
555 (void) mongets(mtmp, BUGLE);
557 if (ptr == &mons[PM_WATCHMAN] && rn2(3))
558 (void) mongets(mtmp, TIN_WHISTLE);
559 } else if (ptr == &mons[PM_SHOPKEEPER]) {
560 (void) mongets(mtmp,SKELETON_KEY);
562 /* MAJOR fall through ... */
563 case 0: (void) mongets(mtmp, WAN_MAGIC_MISSILE);
564 case 1: (void) mongets(mtmp, POT_EXTRA_HEALING);
565 case 2: (void) mongets(mtmp, POT_HEALING);
566 case 3: (void) mongets(mtmp, WAN_STRIKING);
568 } else if (ptr->msound == MS_PRIEST ||
569 quest_mon_represents_role(ptr,PM_PRIEST)) {
570 (void) mongets(mtmp, rn2(7) ? ROBE :
571 rn2(3) ? CLOAK_OF_PROTECTION :
572 CLOAK_OF_MAGIC_RESISTANCE);
573 (void) mongets(mtmp, SMALL_SHIELD);
575 mtmp->mgold = (long)rn1(10,20);
577 mkmonmoney(mtmp,(long)rn1(10,20));
579 } else if (quest_mon_represents_role(ptr,PM_MONK)) {
580 (void) mongets(mtmp, rn2(11) ? ROBE :
581 CLOAK_OF_MAGIC_RESISTANCE);
585 if(!rn2(2)) (void) mongets(mtmp, MIRROR);
586 if(!rn2(2)) (void) mongets(mtmp, POT_OBJECT_DETECTION);
589 if (ptr == &mons[PM_MINOTAUR]) {
590 if (!rn2(3) || (in_mklev && Is_earthlevel(&u.uz)))
591 (void) mongets(mtmp, WAN_DIGGING);
592 } else if (is_giant(ptr)) {
593 for (cnt = rn2((int)(mtmp->m_lev / 2)); cnt; cnt--) {
594 otmp = mksobj(rnd_class(DILITHIUM_CRYSTAL,LUCKSTONE-1),
596 otmp->quan = (long) rn1(2, 3);
597 otmp->owt = weight(otmp);
598 (void) mpickobj(mtmp, otmp);
603 if (ptr == &mons[PM_NAZGUL]) {
604 otmp = mksobj(RIN_INVISIBILITY, FALSE, FALSE);
606 (void) mpickobj(mtmp, otmp);
610 if (ptr == &mons[PM_MASTER_LICH] && !rn2(13))
611 (void)mongets(mtmp, (rn2(7) ? ATHAME : WAN_NOTHING));
612 else if (ptr == &mons[PM_ARCH_LICH] && !rn2(3)) {
613 otmp = mksobj(rn2(3) ? ATHAME : QUARTERSTAFF,
614 TRUE, rn2(13) ? FALSE : TRUE);
615 if (otmp->spe < 2) otmp->spe = rnd(3);
616 if (!rn2(4)) otmp->oerodeproof = 1;
617 (void) mpickobj(mtmp, otmp);
621 if (rn2(7)) (void)mongets(mtmp, MUMMY_WRAPPING);
625 otmp = mksobj(LARGE_BOX, FALSE, FALSE);
626 otmp->spe = 1; /* flag for special box */
627 otmp->owt = weight(otmp);
628 (void) mpickobj(mtmp, otmp);
633 mtmp->mgold = (long) d(level_difficulty(), 30);
635 mkmonmoney(mtmp, (long) d(level_difficulty(), 30));
639 /* moved here from m_initweap() because these don't
640 have AT_WEAP so m_initweap() is not called for them */
641 if (ptr == &mons[PM_ICE_DEVIL] && !rn2(4)) {
642 (void)mongets(mtmp, SPEAR);
643 } else if (ptr == &mons[PM_ASMODEUS]) {
644 (void)mongets(mtmp, WAN_COLD);
645 (void)mongets(mtmp, WAN_FIRE);
652 /* ordinary soldiers rarely have access to magic (or gold :-) */
653 if (ptr == &mons[PM_SOLDIER] && rn2(13)) return;
655 if ((int) mtmp->m_lev > rn2(50))
656 (void) mongets(mtmp, rnd_defensive_item(mtmp));
657 if ((int) mtmp->m_lev > rn2(100))
658 (void) mongets(mtmp, rnd_misc_item(mtmp));
660 if (likes_gold(ptr) && !mtmp->mgold && !rn2(5))
662 (long) d(level_difficulty(), mtmp->minvent ? 5 : 10);
664 if (likes_gold(ptr) && !findgold(mtmp->minvent) && !rn2(5))
665 mkmonmoney(mtmp, (long) d(level_difficulty(), mtmp->minvent ? 5 : 10));
669 /* Note: for long worms, always call cutworm (cutworm calls clone_mon) */
673 xchar x, y; /* clone's preferred location or 0 (near mon) */
678 /* may be too weak or have been extinguished for population control */
679 if (mon->mhp <= 1 || (mvitals[monsndx(mon->data)].mvflags & G_EXTINCT))
680 return (struct monst *)0;
685 if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y))
686 return (struct monst *)0;
687 } else if (!isok(x, y)) {
688 return (struct monst *)0; /* paranoia */
692 if (MON_AT(mm.x, mm.y)) {
693 if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y))
694 return (struct monst *)0;
698 *m2 = *mon; /* copy condition of old monster */
701 m2->m_id = flags.ident++;
702 if (!m2->m_id) m2->m_id = flags.ident++; /* ident overflowed */
706 m2->minvent = (struct obj *) 0; /* objects don't clone */
707 m2->mleashed = FALSE;
711 /* Max HP the same, but current HP halved for both. The caller
712 * might want to override this by halving the max HP also.
713 * When current HP is odd, the original keeps the extra point.
715 m2->mhpmax = mon->mhpmax;
716 m2->mhp = mon->mhp / 2;
719 /* since shopkeepers and guards will only be cloned if they've been
720 * polymorphed away from their original forms, the clone doesn't have
721 * room for the extra information. we also don't want two shopkeepers
722 * around for the same shop.
724 if (mon->isshk) m2->isshk = FALSE;
725 if (mon->isgd) m2->isgd = FALSE;
726 if (mon->ispriest) m2->ispriest = FALSE;
728 place_monster(m2, m2->mx, m2->my);
729 if (emits_light(m2->data))
730 new_light_source(m2->mx, m2->my, emits_light(m2->data),
731 LS_MONSTER, (genericptr_t)m2);
733 m2->mnamelth = 0; /* or it won't get allocated */
734 m2 = christen_monst(m2, NAME(mon));
735 } else if (mon->isshk) {
736 m2 = christen_monst(m2, shkname(mon));
739 /* not all clones caused by player are tame or peaceful */
740 if (!flags.mon_moving) {
742 m2->mtame = rn2(max(2 + u.uluck, 2)) ? mon->mtame : 0;
743 else if (mon->mpeaceful)
744 m2->mpeaceful = rn2(max(2 + u.uluck, 2)) ? 1 : 0;
747 newsym(m2->mx,m2->my); /* display the new monster */
752 m3 = newmonst(sizeof(struct epri) + mon->mnamelth);
754 m3->mxlth = sizeof(struct epri);
755 if (m2->mnamelth) Strcpy(NAME(m3), NAME(m2));
756 *(EPRI(m3)) = *(EPRI(mon));
760 /* because m2 is a copy of mon it is tame but not init'ed.
761 * however, tamedog will not re-tame a tame dog, so m2
762 * must be made non-tame to get initialized properly.
765 if ((m3 = tamedog(m2, (struct obj *)0)) != 0) {
767 *(EDOG(m2)) = *(EDOG(mon));
777 * Propagate a species
779 * Once a certain number of monsters are created, don't create any more
780 * at random (i.e. make them extinct). The previous (3.2) behavior was
781 * to do this when a certain number had _died_, which didn't make
784 * Returns FALSE propagation unsuccessful
785 * TRUE propagation successful
788 propagate(mndx, tally, ghostly)
794 uchar lim = mbirth_limit(mndx);
795 boolean gone = (mvitals[mndx].mvflags & G_GONE); /* genocided or extinct */
797 result = (((int) mvitals[mndx].born < lim) && !gone) ? TRUE : FALSE;
799 /* if it's unique, don't ever make it again */
800 if (mons[mndx].geno & G_UNIQ) mvitals[mndx].mvflags |= G_EXTINCT;
802 if (mvitals[mndx].born < 255 && tally && (!ghostly || (ghostly && result)))
803 mvitals[mndx].born++;
804 if ((int) mvitals[mndx].born >= lim && !(mons[mndx].geno & G_NOGEN) &&
805 !(mvitals[mndx].mvflags & G_EXTINCT)) {
806 #if defined(DEBUG) && defined(WIZARD)
807 if (wizard) pline("Automatically extinguished %s.",
808 makeplural(mons[mndx].mname));
810 mvitals[mndx].mvflags |= G_EXTINCT;
811 reset_rndmonst(mndx);
817 * called with [x,y] = coordinates;
818 * [0,0] means anyplace
819 * [u.ux,u.uy] means: near player (if !in_mklev)
821 * In case we make a monster group, only return the one at [x,y].
824 makemon(ptr, x, y, mmflags)
825 register struct permonst *ptr;
827 register int mmflags;
829 register struct monst *mtmp;
830 int mndx, mcham, ct, mitem, xlth;
831 boolean anymon = (!ptr);
832 boolean byyou = (x == u.ux && y == u.uy);
833 boolean allow_minvent = ((mmflags & NO_MINVENT) == 0);
834 boolean countbirth = ((mmflags & MM_NOCOUNTBIRTH) == 0);
835 unsigned gpflags = (mmflags & MM_IGNOREWATER) ? MM_IGNOREWATER : 0;
837 /* if caller wants random location, do it here */
838 if(x == 0 && y == 0) {
839 int tryct = 0; /* careful with bigrooms */
840 struct monst fakemon;
842 fakemon.data = ptr; /* set up for goodpos */
846 } while(!goodpos(x, y, ptr ? &fakemon : (struct monst *)0, gpflags) ||
847 (!in_mklev && tryct++ < 50 && cansee(x, y)));
848 } else if (byyou && !in_mklev) {
851 if(enexto_core(&bypos, u.ux, u.uy, ptr, gpflags)) {
855 return((struct monst *)0);
858 /* Does monster already exist at the position? */
860 if ((mmflags & MM_ADJACENTOK) != 0) {
862 if(enexto_core(&bypos, x, y, ptr, gpflags)) {
866 return((struct monst *) 0);
868 return((struct monst *) 0);
873 /* if you are to make a specific monster and it has
874 already been genocided, return */
875 if (mvitals[mndx].mvflags & G_GENOD) return((struct monst *) 0);
876 #if defined(WIZARD) && defined(DEBUG)
877 if (wizard && (mvitals[mndx].mvflags & G_EXTINCT))
878 pline("Explicitly creating extinct monster %s.",
882 /* make a random (common) monster that can survive here.
883 * (the special levels ask for random monsters at specific
884 * positions, causing mass drowning on the medusa level,
887 int tryct = 0; /* maybe there are no good choices */
888 struct monst fakemon;
890 if(!(ptr = rndmonst())) {
892 pline("Warning: no monster.");
894 return((struct monst *) 0); /* no more monsters! */
896 fakemon.data = ptr; /* set up for goodpos */
897 } while(!goodpos(x, y, &fakemon, gpflags) && tryct++ < 50);
900 (void) propagate(mndx, countbirth, FALSE);
902 if (mmflags & MM_EDOG) xlth += sizeof(struct edog);
903 else if (mmflags & MM_EMIN) xlth += sizeof(struct emin);
904 mtmp = newmonst(xlth);
905 *mtmp = zeromonst; /* clear all entries in structure */
906 (void)memset((genericptr_t)mtmp->mextra, 0, xlth);
909 mtmp->m_id = flags.ident++;
910 if (!mtmp->m_id) mtmp->m_id = flags.ident++; /* ident overflowed */
911 set_mon_data(mtmp, ptr, 0);
912 if (mtmp->data->msound == MS_LEADER)
913 quest_status.leader_m_id = mtmp->m_id;
917 mtmp->m_lev = adj_lev(ptr);
919 mtmp->mhpmax = mtmp->mhp = golemhp(mndx);
920 } else if (is_rider(ptr)) {
921 /* We want low HP, but a high mlevel so they can attack well */
922 mtmp->mhpmax = mtmp->mhp = d(10,8);
923 } else if (ptr->mlevel > 49) {
924 /* "special" fixed hp monster
925 * the hit points are encoded in the mlevel in a somewhat strange
926 * way to fit in the 50..127 positive range of a signed character
927 * above the 1..49 that indicate "normal" monster levels */
928 mtmp->mhpmax = mtmp->mhp = 2*(ptr->mlevel - 6);
929 mtmp->m_lev = mtmp->mhp / 4; /* approximation */
930 } else if (ptr->mlet == S_DRAGON && mndx >= PM_GRAY_DRAGON) {
932 mtmp->mhpmax = mtmp->mhp = (int) (In_endgame(&u.uz) ?
933 (8 * mtmp->m_lev) : (4 * mtmp->m_lev + d((int)mtmp->m_lev, 4)));
934 } else if (!mtmp->m_lev) {
935 mtmp->mhpmax = mtmp->mhp = rnd(4);
937 mtmp->mhpmax = mtmp->mhp = d((int)mtmp->m_lev, 8);
938 if (is_home_elemental(ptr))
939 mtmp->mhpmax = (mtmp->mhp *= 3);
942 if (is_female(ptr)) mtmp->female = TRUE;
943 else if (is_male(ptr)) mtmp->female = FALSE;
944 else mtmp->female = rn2(2); /* ignored for neuters */
946 if (In_sokoban(&u.uz) && !mindless(ptr)) /* know about traps here */
947 mtmp->mtrapseen = (1L << (PIT - 1)) | (1L << (HOLE - 1));
948 if (ptr->msound == MS_LEADER) /* leader knows about portal */
949 mtmp->mtrapseen |= (1L << (MAGIC_PORTAL-1));
951 place_monster(mtmp, x, y);
952 mtmp->mcansee = mtmp->mcanmove = TRUE;
953 mtmp->mpeaceful = (mmflags & MM_ANGRY) ? FALSE : peace_minded(ptr);
963 (void) mkobj_at(0, x, y, TRUE);
964 if(hides_under(ptr) && OBJ_AT(x, y))
965 mtmp->mundetected = TRUE;
969 if (mndx == PM_STALKER || mndx == PM_BLACK_LIGHT) {
970 mtmp->perminvis = TRUE;
976 mtmp->mundetected = TRUE;
983 if (rn2(5) && !u.uhave.amulet) mtmp->msleeping = 1;
986 if (Race_if(PM_ELF)) mtmp->mpeaceful = FALSE;
989 if (is_unicorn(ptr) &&
990 sgn(u.ualign.type) == sgn(ptr->maligntyp))
991 mtmp->mpeaceful = TRUE;
994 if (Inhell && is_bat(ptr))
995 mon_adjust_speed(mtmp, 2, (struct obj *)0);
998 if ((ct = emits_light(mtmp->data)) > 0)
999 new_light_source(mtmp->mx, mtmp->my, ct,
1000 LS_MONSTER, (genericptr_t)mtmp);
1001 mitem = 0; /* extra inventory item for this monster */
1003 if ((mcham = pm_to_cham(mndx)) != CHAM_ORDINARY) {
1004 /* If you're protected with a ring, don't create
1005 * any shape-changing chameleons -dgk
1007 if (Protection_from_shape_changers)
1008 mtmp->cham = CHAM_ORDINARY;
1011 (void) newcham(mtmp, rndmonst(), FALSE, FALSE);
1013 } else if (mndx == PM_WIZARD_OF_YENDOR) {
1015 flags.no_of_wizards++;
1016 if (flags.no_of_wizards == 1 && Is_earthlevel(&u.uz))
1018 } else if (mndx == PM_DJINNI) {
1019 flags.djinni_count++;
1020 } else if (mndx == PM_GHOST) {
1021 flags.ghost_count++;
1022 if (!(mmflags & MM_NONAME))
1023 mtmp = christen_monst(mtmp, rndghostname());
1024 } else if (mndx == PM_VLAD_THE_IMPALER) {
1025 mitem = CANDELABRUM_OF_INVOCATION;
1026 } else if (mndx == PM_CROESUS) {
1027 mitem = TWO_HANDED_SWORD;
1028 } else if (ptr->msound == MS_NEMESIS) {
1029 mitem = BELL_OF_OPENING;
1030 } else if (mndx == PM_PESTILENCE) {
1031 mitem = POT_SICKNESS;
1033 if (mitem && allow_minvent) (void) mongets(mtmp, mitem);
1036 if(((is_ndemon(ptr)) ||
1037 (mndx == PM_WUMPUS) ||
1038 (mndx == PM_LONG_WORM) ||
1039 (mndx == PM_GIANT_EEL)) && !u.uhave.amulet && rn2(5))
1040 mtmp->msleeping = TRUE;
1043 newsym(mtmp->mx,mtmp->my);
1047 if(is_dprince(ptr) && ptr->msound == MS_BRIBE) {
1048 mtmp->mpeaceful = mtmp->minvis = mtmp->perminvis = 1;
1050 if (uwep && uwep->oartifact == ART_EXCALIBUR)
1051 mtmp->mpeaceful = mtmp->mtame = FALSE;
1054 if (mndx == PM_LONG_WORM && (mtmp->wormno = get_wormno()) != 0)
1056 /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
1059 if (mndx == PM_LONG_WORM &&
1060 (mtmp->wormno = get_wormno(), mtmp->wormno != 0))
1063 /* we can now create worms with tails - 11/91 */
1064 initworm(mtmp, rn2(5));
1065 if (count_wsegs(mtmp)) place_worm_tail_randomly(mtmp, x, y);
1067 set_malign(mtmp); /* having finished peaceful changes */
1069 if ((ptr->geno & G_SGROUP) && rn2(2)) {
1070 m_initsgrp(mtmp, mtmp->mx, mtmp->my);
1071 } else if (ptr->geno & G_LGROUP) {
1072 if(rn2(3)) m_initlgrp(mtmp, mtmp->mx, mtmp->my);
1073 else m_initsgrp(mtmp, mtmp->mx, mtmp->my);
1077 if (allow_minvent) {
1079 m_initweap(mtmp); /* equip with weapons / armor */
1080 m_initinv(mtmp); /* add on a few special items incl. more armor */
1081 m_dowear(mtmp, TRUE);
1083 /* no initial inventory is allowed */
1084 if (mtmp->minvent) discard_minvent(mtmp);
1085 mtmp->minvent = (struct obj *)0; /* caller expects this */
1087 if ((ptr->mflags3 & M3_WAITMASK) && !(mmflags & MM_NOWAIT)) {
1088 if (ptr->mflags3 & M3_WAITFORU)
1089 mtmp->mstrategy |= STRAT_WAITFORU;
1090 if (ptr->mflags3 & M3_CLOSE)
1091 mtmp->mstrategy |= STRAT_CLOSE;
1095 newsym(mtmp->mx,mtmp->my); /* make sure the mon shows up */
1104 /* assert(MAXMONNO < 255); */
1105 return (mndx == PM_NAZGUL ? 9 : mndx == PM_ERINYS ? 3 : MAXMONNO);
1108 /* used for wand/scroll/spell of create monster */
1109 /* returns TRUE iff you know monsters have been created */
1111 create_critters(cnt, mptr)
1113 struct permonst *mptr; /* usually null; used for confused reading */
1118 boolean known = FALSE;
1120 boolean ask = wizard;
1126 if (create_particular()) {
1130 else ask = FALSE; /* ESC will shut off prompting */
1134 /* if in water, try to encourage an aquatic monster
1135 by finding and then specifying another wet location */
1136 if (!mptr && u.uinwater && enexto(&c, x, y, &mons[PM_GIANT_EEL]))
1139 mon = makemon(mptr, x, y, NO_MM_FLAGS);
1140 if (mon && canspotmon(mon)) known = TRUE;
1152 if (mons[mndx].geno & (G_NOGEN | G_UNIQ)) return TRUE;
1153 if (mvitals[mndx].mvflags & G_GONE) return TRUE;
1155 return(mons[mndx].maligntyp > A_NEUTRAL);
1157 return((mons[mndx].geno & G_HELL) != 0);
1161 * shift the probability of a monster's generation by
1162 * comparing the dungeon alignment and monster alignment.
1163 * return an integer in the range of 0-5.
1167 register struct permonst *ptr;
1169 static NEARDATA long oldmoves = 0L; /* != 1, starting value of moves */
1170 static NEARDATA s_level *lev;
1171 register int alshift;
1173 if(oldmoves != moves) {
1174 lev = Is_special(&u.uz);
1177 switch((lev) ? lev->flags.align : dungeons[u.uz.dnum].flags.align) {
1178 default: /* just in case */
1179 case AM_NONE: alshift = 0;
1181 case AM_LAWFUL: alshift = (ptr->maligntyp+20)/(2*ALIGNWEIGHT);
1183 case AM_NEUTRAL: alshift = (20 - abs(ptr->maligntyp))/ALIGNWEIGHT;
1185 case AM_CHAOTIC: alshift = (-(ptr->maligntyp-20))/(2*ALIGNWEIGHT);
1191 static NEARDATA struct {
1193 char mchoices[SPECIAL_PM]; /* value range is 0..127 */
1194 } rndmonst_state = { -1, {0} };
1196 /* select a random monster type */
1200 register struct permonst *ptr;
1201 register int mndx, ct;
1203 if (u.uz.dnum == quest_dnum && rn2(7) && (ptr = qt_montype()) != 0)
1206 if (rndmonst_state.choice_count < 0) { /* need to recalculate */
1207 int zlevel, minmlev, maxmlev;
1209 #ifdef REINCARNATION
1213 rndmonst_state.choice_count = 0;
1214 /* look for first common monster */
1215 for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) {
1216 if (!uncommon(mndx)) break;
1217 rndmonst_state.mchoices[mndx] = 0;
1219 if (mndx == SPECIAL_PM) {
1220 /* evidently they've all been exterminated */
1222 pline("rndmonst: no common mons!");
1224 return (struct permonst *)0;
1225 } /* else `mndx' now ready for use below */
1226 zlevel = level_difficulty();
1227 /* determine the level of the weakest monster to make. */
1228 minmlev = zlevel / 6;
1229 /* determine the level of the strongest monster to make. */
1230 maxmlev = (zlevel + u.ulevel) / 2;
1231 #ifdef REINCARNATION
1232 upper = Is_rogue_level(&u.uz);
1234 elemlevel = In_endgame(&u.uz) && !Is_astralevel(&u.uz);
1237 * Find out how many monsters exist in the range we have selected.
1239 /* (`mndx' initialized above) */
1240 for ( ; mndx < SPECIAL_PM; mndx++) {
1242 rndmonst_state.mchoices[mndx] = 0;
1243 if (tooweak(mndx, minmlev) || toostrong(mndx, maxmlev))
1245 #ifdef REINCARNATION
1246 if (upper && !isupper(def_monsyms[(int)(ptr->mlet)])) continue;
1248 if (elemlevel && wrong_elem_type(ptr)) continue;
1249 if (uncommon(mndx)) continue;
1250 if (Inhell && (ptr->geno & G_NOHELL)) continue;
1251 ct = (int)(ptr->geno & G_FREQ) + align_shift(ptr);
1252 if (ct < 0 || ct > 127)
1253 panic("rndmonst: bad count [#%d: %d]", mndx, ct);
1254 rndmonst_state.choice_count += ct;
1255 rndmonst_state.mchoices[mndx] = (char)ct;
1258 * Possible modification: if choice_count is "too low",
1259 * expand minmlev..maxmlev range and try again.
1261 } /* choice_count+mchoices[] recalc */
1263 if (rndmonst_state.choice_count <= 0) {
1264 /* maybe no common mons left, or all are too weak or too strong */
1266 Norep("rndmonst: choice_count=%d", rndmonst_state.choice_count);
1268 return (struct permonst *)0;
1272 * Now, select a monster at random.
1274 ct = rnd(rndmonst_state.choice_count);
1275 for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++)
1276 if ((ct -= (int)rndmonst_state.mchoices[mndx]) <= 0) break;
1278 if (mndx == SPECIAL_PM || uncommon(mndx)) { /* shouldn't happen */
1279 impossible("rndmonst: bad `mndx' [#%d]", mndx);
1280 return (struct permonst *)0;
1285 /* called when you change level (experience or dungeon depth) or when
1286 monster species can no longer be created (genocide or extinction) */
1288 reset_rndmonst(mndx)
1289 int mndx; /* particular species that can no longer be created */
1291 /* cached selection info is out of date */
1292 if (mndx == NON_PM) {
1293 rndmonst_state.choice_count = -1; /* full recalc needed */
1294 } else if (mndx < SPECIAL_PM) {
1295 rndmonst_state.choice_count -= rndmonst_state.mchoices[mndx];
1296 rndmonst_state.mchoices[mndx] = 0;
1297 } /* note: safe to ignore extinction of unique monsters */
1303 /* The routine below is used to make one of the multiple types
1304 * of a given monster class. The second parameter specifies a
1305 * special casing bit mask to allow the normal genesis
1306 * masks to be deactivated. Returns 0 if no monsters
1307 * in that class can be made.
1315 register int first, last, num = 0;
1316 int maxmlev, mask = (G_NOGEN | G_UNIQ) & ~spc;
1318 maxmlev = level_difficulty() >> 1;
1319 if(class < 1 || class >= MAXMCLASSES) {
1320 impossible("mkclass called with bad class!");
1321 return((struct permonst *) 0);
1323 /* Assumption #1: monsters of a given class are contiguous in the
1326 for (first = LOW_PM; first < SPECIAL_PM; first++)
1327 if (mons[first].mlet == class) break;
1328 if (first == SPECIAL_PM) return (struct permonst *) 0;
1331 last < SPECIAL_PM && mons[last].mlet == class; last++)
1332 if (!(mvitals[last].mvflags & G_GONE) && !(mons[last].geno & mask)
1333 && !is_placeholder(&mons[last])) {
1335 if(num && toostrong(last, maxmlev) &&
1336 monstr[last] != monstr[last-1] && rn2(2)) break;
1337 num += mons[last].geno & G_FREQ;
1340 if(!num) return((struct permonst *) 0);
1342 /* Assumption #2: monsters of a given class are presented in ascending
1343 * order of strength.
1345 for(num = rnd(num); num > 0; first++)
1346 if (!(mvitals[first].mvflags & G_GONE) && !(mons[first].geno & mask)
1347 && !is_placeholder(&mons[first])) {
1348 /* skew towards lower value monsters at lower exp. levels */
1349 num -= mons[first].geno & G_FREQ;
1350 if (num && adj_lev(&mons[first]) > (u.ulevel*2)) {
1351 /* but not when multiple monsters are same level */
1352 if (mons[first].mlevel != mons[first+1].mlevel)
1356 first--; /* correct an off-by-one error */
1358 return(&mons[first]);
1362 adj_lev(ptr) /* adjust strength of monsters based on u.uz and u.ulevel */
1363 register struct permonst *ptr;
1367 if (ptr == &mons[PM_WIZARD_OF_YENDOR]) {
1368 /* does not depend on other strengths, but does get stronger
1369 * every time he is killed
1371 tmp = ptr->mlevel + mvitals[PM_WIZARD_OF_YENDOR].died;
1372 if (tmp > 49) tmp = 49;
1376 if((tmp = ptr->mlevel) > 49) return(50); /* "special" demons/devils */
1377 tmp2 = (level_difficulty() - tmp);
1378 if(tmp2 < 0) tmp--; /* if mlevel > u.uz decrement tmp */
1379 else tmp += (tmp2 / 5); /* else increment 1 per five diff */
1381 tmp2 = (u.ulevel - ptr->mlevel); /* adjust vs. the player */
1382 if(tmp2 > 0) tmp += (tmp2 / 4); /* level as well */
1384 tmp2 = (3 * ((int) ptr->mlevel))/ 2; /* crude upper limit */
1385 if (tmp2 > 49) tmp2 = 49; /* hard upper limit */
1386 return((tmp > tmp2) ? tmp2 : (tmp > 0 ? tmp : 0)); /* 0 lower limit */
1393 grow_up(mtmp, victim) /* `mtmp' might "grow up" into a bigger version */
1394 struct monst *mtmp, *victim;
1396 int oldtype, newtype, max_increase, cur_increase,
1397 lev_limit, hp_threshold;
1398 struct permonst *ptr = mtmp->data;
1400 /* monster died after killing enemy but before calling this function */
1401 /* currently possible if killing a gas spore */
1403 return ((struct permonst *)0);
1405 /* note: none of the monsters with special hit point calculations
1406 have both little and big forms */
1407 oldtype = monsndx(ptr);
1408 newtype = little_to_big(oldtype);
1409 if (newtype == PM_PRIEST && mtmp->female) newtype = PM_PRIESTESS;
1411 /* growth limits differ depending on method of advancement */
1412 if (victim) { /* killed a monster */
1414 * The HP threshold is the maximum number of hit points for the
1415 * current level; once exceeded, a level will be gained.
1416 * Possible bug: if somehow the hit points are already higher
1417 * than that, monster will gain a level without any increase in HP.
1419 hp_threshold = mtmp->m_lev * 8; /* normal limit */
1422 else if (is_golem(ptr)) /* strange creatures */
1423 hp_threshold = ((mtmp->mhpmax / 10) + 1) * 10 - 1;
1424 else if (is_home_elemental(ptr))
1426 lev_limit = 3 * (int)ptr->mlevel / 2; /* same as adj_lev() */
1427 /* If they can grow up, be sure the level is high enough for that */
1428 if (oldtype != newtype && mons[newtype].mlevel > lev_limit)
1429 lev_limit = (int)mons[newtype].mlevel;
1430 /* number of hit points to gain; unlike for the player, we put
1431 the limit at the bottom of the next level rather than the top */
1432 max_increase = rnd((int)victim->m_lev + 1);
1433 if (mtmp->mhpmax + max_increase > hp_threshold + 1)
1434 max_increase = max((hp_threshold + 1) - mtmp->mhpmax, 0);
1435 cur_increase = (max_increase > 1) ? rn2(max_increase) : 0;
1437 /* a gain level potion or wraith corpse; always go up a level
1438 unless already at maximum (49 is hard upper limit except
1439 for demon lords, who start at 50 and can't go any higher) */
1440 max_increase = cur_increase = rnd(8);
1441 hp_threshold = 0; /* smaller than `mhpmax + max_increase' */
1442 lev_limit = 50; /* recalc below */
1445 mtmp->mhpmax += max_increase;
1446 mtmp->mhp += cur_increase;
1447 if (mtmp->mhpmax <= hp_threshold)
1448 return ptr; /* doesn't gain a level */
1450 if (is_mplayer(ptr)) lev_limit = 30; /* same as player */
1451 else if (lev_limit < 5) lev_limit = 5; /* arbitrary */
1452 else if (lev_limit > 49) lev_limit = (ptr->mlevel > 49 ? 50 : 49);
1454 if ((int)++mtmp->m_lev >= mons[newtype].mlevel && newtype != oldtype) {
1455 ptr = &mons[newtype];
1456 if (mvitals[newtype].mvflags & G_GENOD) { /* allow G_EXTINCT */
1458 pline("As %s grows up into %s, %s %s!", mon_nam(mtmp),
1459 an(ptr->mname), mhe(mtmp),
1460 nonliving(ptr) ? "expires" : "dies");
1461 set_mon_data(mtmp, ptr, -1); /* keep mvitals[] accurate */
1463 return (struct permonst *)0;
1465 set_mon_data(mtmp, ptr, 1); /* preserve intrinsics */
1466 newsym(mtmp->mx, mtmp->my); /* color may change */
1467 lev_limit = (int)mtmp->m_lev; /* never undo increment */
1470 if ((int)mtmp->m_lev > lev_limit) {
1471 mtmp->m_lev--; /* undo increment */
1472 /* HP might have been allowed to grow when it shouldn't */
1473 if (mtmp->mhpmax == hp_threshold + 1) mtmp->mhpmax--;
1475 if (mtmp->mhpmax > 50*8) mtmp->mhpmax = 50*8; /* absolute limit */
1476 if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax;
1486 register struct monst *mtmp;
1489 register struct obj *otmp;
1492 if (!otyp) return 0;
1493 otmp = mksobj(otyp, TRUE, FALSE);
1495 if (mtmp->data->mlet == S_DEMON) {
1496 /* demons never get blessed objects */
1497 if (otmp->blessed) curse(otmp);
1498 } else if(is_lminion(mtmp)) {
1499 /* lawful minions don't get cursed, bad, or rusting objects */
1500 otmp->cursed = FALSE;
1501 if(otmp->spe < 0) otmp->spe = 0;
1502 otmp->oerodeproof = TRUE;
1503 } else if(is_mplayer(mtmp->data) && is_sword(otmp)) {
1504 otmp->spe = (3 + rn2(4));
1507 if(otmp->otyp == CANDELABRUM_OF_INVOCATION) {
1510 otmp->lamplit = FALSE;
1511 otmp->blessed = otmp->cursed = FALSE;
1512 } else if (otmp->otyp == BELL_OF_OPENING) {
1513 otmp->blessed = otmp->cursed = FALSE;
1514 } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) {
1515 otmp->blessed = FALSE;
1516 otmp->cursed = TRUE;
1519 /* leaders don't tolerate inferior quality battle gear */
1520 if (is_prince(mtmp->data)) {
1521 if (otmp->oclass == WEAPON_CLASS && otmp->spe < 1)
1523 else if (otmp->oclass == ARMOR_CLASS && otmp->spe < 0)
1528 (void) mpickobj(mtmp, otmp); /* might free otmp */
1541 case PM_STRAW_GOLEM: return 20;
1542 case PM_PAPER_GOLEM: return 20;
1543 case PM_ROPE_GOLEM: return 30;
1544 case PM_LEATHER_GOLEM: return 40;
1545 case PM_GOLD_GOLEM: return 40;
1546 case PM_WOOD_GOLEM: return 50;
1547 case PM_FLESH_GOLEM: return 40;
1548 case PM_CLAY_GOLEM: return 50;
1549 case PM_STONE_GOLEM: return 60;
1550 case PM_GLASS_GOLEM: return 60;
1551 case PM_IRON_GOLEM: return 80;
1560 * Alignment vs. yours determines monster's attitude to you.
1561 * ( some "animal" types are co-aligned, but also hungry )
1565 register struct permonst *ptr;
1567 aligntyp mal = ptr->maligntyp, ual = u.ualign.type;
1569 if (always_peaceful(ptr)) return TRUE;
1570 if (always_hostile(ptr)) return FALSE;
1571 if (ptr->msound == MS_LEADER || ptr->msound == MS_GUARDIAN)
1573 if (ptr->msound == MS_NEMESIS) return FALSE;
1575 if (race_peaceful(ptr)) return TRUE;
1576 if (race_hostile(ptr)) return FALSE;
1578 /* the monster is hostile if its alignment is different from the
1580 if (sgn(mal) != sgn(ual)) return FALSE;
1582 /* Negative monster hostile to player with Amulet. */
1583 if (mal < A_NEUTRAL && u.uhave.amulet) return FALSE;
1585 /* minions are hostile to players that have strayed at all */
1586 if (is_minion(ptr)) return((boolean)(u.ualign.record >= 0));
1588 /* Last case: a chance of a co-aligned monster being
1589 * hostile. This chance is greater if the player has strayed
1590 * (u.ualign.record negative) or the monster is not strongly aligned.
1592 return((boolean)(!!rn2(16 + (u.ualign.record < -15 ? -15 : u.ualign.record)) &&
1593 !!rn2(2 + abs(mal))));
1596 /* Set malign to have the proper effect on player alignment if monster is
1597 * killed. Negative numbers mean it's bad to kill this monster; positive
1598 * numbers mean it's good. Since there are more hostile monsters than
1599 * peaceful monsters, the penalty for killing a peaceful monster should be
1600 * greater than the bonus for killing a hostile monster to maintain balance.
1602 * it's bad to kill peaceful monsters, potentially worse to kill always-
1604 * it's never bad to kill a hostile monster, although it may not be good
1610 schar mal = mtmp->data->maligntyp;
1613 if (mtmp->ispriest || mtmp->isminion) {
1614 /* some monsters have individual alignments; check them */
1616 mal = EPRI(mtmp)->shralign;
1617 else if (mtmp->isminion)
1618 mal = EMIN(mtmp)->min_align;
1619 /* unless alignment is none, set mal to -5,0,5 */
1620 /* (see align.h for valid aligntyp values) */
1625 coaligned = (sgn(mal) == sgn(u.ualign.type));
1626 if (mtmp->data->msound == MS_LEADER) {
1628 } else if (mal == A_NONE) {
1629 if (mtmp->mpeaceful)
1632 mtmp->malign = 20; /* really hostile */
1633 } else if (always_peaceful(mtmp->data)) {
1634 int absmal = abs(mal);
1635 if (mtmp->mpeaceful)
1636 mtmp->malign = -3*max(5,absmal);
1638 mtmp->malign = 3*max(5,absmal); /* renegade */
1639 } else if (always_hostile(mtmp->data)) {
1640 int absmal = abs(mal);
1644 mtmp->malign = max(5,absmal);
1645 } else if (coaligned) {
1646 int absmal = abs(mal);
1647 if (mtmp->mpeaceful)
1648 mtmp->malign = -3*max(3,absmal);
1650 mtmp->malign = max(3,absmal);
1651 } else /* not coaligned and therefore hostile */
1652 mtmp->malign = abs(mal);
1658 static NEARDATA char syms[] = {
1659 MAXOCLASSES, MAXOCLASSES+1, RING_CLASS, WAND_CLASS, WEAPON_CLASS,
1660 FOOD_CLASS, COIN_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS,
1661 AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS,
1662 S_MIMIC_DEF, S_MIMIC_DEF, S_MIMIC_DEF,
1666 set_mimic_sym(mtmp) /* KAA, modified by ERS */
1667 register struct monst *mtmp;
1669 int typ, roomno, rt;
1670 unsigned appear, ap_type;
1676 mx = mtmp->mx; my = mtmp->my;
1677 typ = levl[mx][my].typ;
1678 /* only valid for INSIDE of room */
1679 roomno = levl[mx][my].roomno - ROOMOFFSET;
1681 rt = rooms[roomno].rtype;
1682 #ifdef SPECIALIZATION
1683 else if (IS_ROOM(typ))
1684 rt = OROOM, roomno = 0;
1686 else rt = 0; /* roomno < 0 case for GCC_WARN */
1688 if (OBJ_AT(mx, my)) {
1689 ap_type = M_AP_OBJECT;
1690 appear = level.objects[mx][my]->otyp;
1691 } else if (IS_DOOR(typ) || IS_WALL(typ) ||
1692 typ == SDOOR || typ == SCORR) {
1693 ap_type = M_AP_FURNITURE;
1695 * If there is a wall to the left that connects to this
1696 * location, then the mimic mimics a horizontal closed door.
1697 * This does not allow doors to be in corners of rooms.
1700 (levl[mx-1][my].typ == HWALL ||
1701 levl[mx-1][my].typ == TLCORNER ||
1702 levl[mx-1][my].typ == TRWALL ||
1703 levl[mx-1][my].typ == BLCORNER ||
1704 levl[mx-1][my].typ == TDWALL ||
1705 levl[mx-1][my].typ == CROSSWALL||
1706 levl[mx-1][my].typ == TUWALL ))
1711 if(!mtmp->minvis || See_invisible)
1712 block_point(mx,my); /* vision */
1713 } else if (level.flags.is_maze_lev && rn2(2)) {
1714 ap_type = M_AP_OBJECT;
1716 } else if (roomno < 0) {
1717 ap_type = M_AP_OBJECT;
1719 if(!mtmp->minvis || See_invisible)
1720 block_point(mx,my); /* vision */
1721 } else if (rt == ZOO || rt == VAULT) {
1722 ap_type = M_AP_OBJECT;
1723 appear = GOLD_PIECE;
1724 } else if (rt == DELPHI) {
1726 ap_type = M_AP_OBJECT;
1729 ap_type = M_AP_FURNITURE;
1730 appear = S_fountain;
1732 } else if (rt == TEMPLE) {
1733 ap_type = M_AP_FURNITURE;
1736 * We won't bother with beehives, morgues, barracks, throne rooms
1737 * since they shouldn't contain too many mimics anyway...
1739 } else if (rt >= SHOPBASE) {
1740 s_sym = get_shop_item(rt - SHOPBASE);
1742 ap_type = M_AP_OBJECT;
1745 if (s_sym == RANDOM_CLASS)
1746 s_sym = syms[rn2((int)sizeof(syms)-2) + 2];
1750 s_sym = syms[rn2((int)sizeof(syms))];
1752 if (s_sym >= MAXOCLASSES) {
1753 ap_type = M_AP_FURNITURE;
1754 appear = s_sym == MAXOCLASSES ? S_upstair : S_dnstair;
1755 } else if (s_sym == COIN_CLASS) {
1756 ap_type = M_AP_OBJECT;
1757 appear = GOLD_PIECE;
1759 ap_type = M_AP_OBJECT;
1760 if (s_sym == S_MIMIC_DEF) {
1761 appear = STRANGE_OBJECT;
1763 otmp = mkobj( (char) s_sym, FALSE );
1764 appear = otmp->otyp;
1765 /* make sure container contents are free'ed */
1766 obfree(otmp, (struct obj *) 0);
1770 mtmp->m_ap_type = ap_type;
1771 mtmp->mappearance = appear;
1774 /* release a monster from a bag of tricks */
1779 if (!bag || bag->otyp != BAG_OF_TRICKS) {
1780 impossible("bad bag o' tricks");
1781 } else if (bag->spe < 1) {
1782 pline(nothing_happens);
1784 boolean gotone = FALSE;
1787 consume_obj_charge(bag, TRUE);
1789 if (!rn2(23)) cnt += rn1(7, 1);
1791 if (makemon((struct permonst *)0, u.ux, u.uy, NO_MM_FLAGS))
1794 if (gotone) makeknown(BAG_OF_TRICKS);