1 /* NetHack 3.6 makemon.c $NHDT-Date: 1450451931 2015/12/18 15:18:51 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.106 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
9 /* this assumes that a human quest leader or nemesis is an archetype
10 of the corresponding role; that isn't so for some roles (tourist
11 for instance) but is for the priests and monks we use it for... */
12 #define quest_mon_represents_role(mptr, role_pm) \
13 (mptr->mlet == S_HUMAN && Role_if(role_pm) \
14 && (mptr->msound == MS_LEADER || mptr->msound == MS_NEMESIS))
16 STATIC_DCL boolean
FDECL(uncommon
, (int));
17 STATIC_DCL
int FDECL(align_shift
, (struct permonst
*));
18 STATIC_DCL boolean
FDECL(mk_gen_ok
, (int, int, int));
19 STATIC_DCL boolean
FDECL(wrong_elem_type
, (struct permonst
*));
20 STATIC_DCL
void FDECL(m_initgrp
, (struct monst
*, int, int, int));
21 STATIC_DCL
void FDECL(m_initthrow
, (struct monst
*, int, int));
22 STATIC_DCL
void FDECL(m_initweap
, (struct monst
*));
23 STATIC_DCL
void FDECL(m_initinv
, (struct monst
*));
24 STATIC_DCL boolean
FDECL(makemon_rnd_goodpos
, (struct monst
*,
27 extern const int monstr
[];
29 #define m_initsgrp(mtmp, x, y) m_initgrp(mtmp, x, y, 3)
30 #define m_initlgrp(mtmp, x, y) m_initgrp(mtmp, x, y, 10)
31 #define toostrong(monindx, lev) (monstr[monindx] > lev)
32 #define tooweak(monindx, lev) (monstr[monindx] < lev)
35 is_home_elemental(ptr
)
38 if (ptr
->mlet
== S_ELEMENTAL
)
39 switch (monsndx(ptr
)) {
40 case PM_AIR_ELEMENTAL
:
41 return Is_airlevel(&u
.uz
);
42 case PM_FIRE_ELEMENTAL
:
43 return Is_firelevel(&u
.uz
);
44 case PM_EARTH_ELEMENTAL
:
45 return Is_earthlevel(&u
.uz
);
46 case PM_WATER_ELEMENTAL
:
47 return Is_waterlevel(&u
.uz
);
53 * Return true if the given monster cannot exist on this elemental level.
59 if (ptr
->mlet
== S_ELEMENTAL
) {
60 return (boolean
) !is_home_elemental(ptr
);
61 } else if (Is_earthlevel(&u
.uz
)) {
62 /* no restrictions? */
63 } else if (Is_waterlevel(&u
.uz
)) {
64 /* just monsters that can swim */
67 } else if (Is_firelevel(&u
.uz
)) {
68 if (!pm_resistance(ptr
, MR_FIRE
))
70 } else if (Is_airlevel(&u
.uz
)) {
71 if (!(is_flyer(ptr
) && ptr
->mlet
!= S_TRAPPER
) && !is_floater(ptr
)
72 && !amorphous(ptr
) && !noncorporeal(ptr
) && !is_whirly(ptr
))
78 /* make a group just like mtmp */
80 m_initgrp(mtmp
, x
, y
, n
)
81 register struct monst
*mtmp
;
85 register int cnt
= rnd(n
);
87 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
88 /* There is an unresolved problem with several people finding that
89 * the game hangs eating CPU; if interrupted and restored, the level
90 * will be filled with monsters. Of those reports giving system type,
91 * there were two DG/UX and two HP-UX, all using gcc as the compiler.
92 * hcroft@hpopb1.cern.ch, using gcc 2.6.3 on HP-UX, says that the
93 * problem went away for him and another reporter-to-newsgroup
94 * after adding this debugging code. This has almost got to be a
95 * compiler bug, but until somebody tracks it down and gets it fixed,
96 * might as well go with the "but it went away when I tried to find
102 debugpline4("init group call <%d,%d>, n=%d, cnt=%d.", x
, y
, n
, cnt
);
103 cntdiv
= ((u
.ulevel
< 3) ? 4 : (u
.ulevel
< 5) ? 2 : 1);
105 /* Tuning: cut down on swarming at low character levels [mrs] */
106 cnt
/= (u
.ulevel
< 3) ? 4 : (u
.ulevel
< 5) ? 2 : 1;
107 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
108 if (cnt
!= (cnttmp
/ cntdiv
)) {
109 pline("cnt=%d using %d, cnttmp=%d, cntdiv=%d", cnt
,
110 (u
.ulevel
< 3) ? 4 : (u
.ulevel
< 5) ? 2 : 1, cnttmp
, cntdiv
);
115 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
125 if (peace_minded(mtmp
->data
))
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
);
135 mon
->mpeaceful
= FALSE
;
138 /* Undo the second peace_minded() check in makemon(); if the
139 * monster turned out to be peaceful the first time we
140 * didn't create it at all; we don't want a second check.
149 m_initthrow(mtmp
, otyp
, oquan
)
153 register struct obj
*otmp
;
155 otmp
= mksobj(otyp
, TRUE
, FALSE
);
156 otmp
->quan
= (long) rn1(oquan
, 3);
157 otmp
->owt
= weight(otmp
);
158 if (otyp
== ORCISH_ARROW
)
159 otmp
->opoisoned
= TRUE
;
160 (void) mpickobj(mtmp
, otmp
);
165 register struct monst
*mtmp
;
167 register struct permonst
*ptr
= mtmp
->data
;
168 register int mm
= monsndx(ptr
);
170 int bias
, spe2
, w1
, w2
;
172 if (Is_rogue_level(&u
.uz
))
175 * First a few special cases:
176 * giants get a boulder to throw sometimes
178 * kobolds get darts to throw
179 * centaurs get some sort of bow & arrows or bolts
180 * soldiers get all sorts of things
181 * kops get clubs & cream pies.
186 (void) mongets(mtmp
, (mm
!= PM_ETTIN
) ? BOULDER
: CLUB
);
189 if (is_mercenary(ptr
)) {
195 w1
= rn1(BEC_DE_CORBIN
- PARTISAN
+ 1, PARTISAN
);
196 w2
= rn2(2) ? DAGGER
: KNIFE
;
198 w1
= rn2(2) ? SPEAR
: SHORT_SWORD
;
201 w1
= rn2(2) ? FLAIL
: MACE
;
204 w1
= rn2(2) ? BROADSWORD
: LONG_SWORD
;
207 case PM_WATCH_CAPTAIN
:
208 w1
= rn2(2) ? LONG_SWORD
: SILVER_SABER
;
218 (void) mongets(mtmp
, w1
);
219 if (!w2
&& w1
!= DAGGER
&& !rn2(4))
222 (void) mongets(mtmp
, w2
);
223 } else if (is_elf(ptr
)) {
226 rn2(2) ? ELVEN_MITHRIL_COAT
: ELVEN_CLOAK
);
228 (void) mongets(mtmp
, ELVEN_LEATHER_HELM
);
230 (void) mongets(mtmp
, ELVEN_BOOTS
);
232 (void) mongets(mtmp
, ELVEN_DAGGER
);
236 (void) mongets(mtmp
, ELVEN_SHIELD
);
238 (void) mongets(mtmp
, ELVEN_SHORT_SWORD
);
239 (void) mongets(mtmp
, ELVEN_BOW
);
240 m_initthrow(mtmp
, ELVEN_ARROW
, 12);
243 (void) mongets(mtmp
, ELVEN_BROADSWORD
);
245 (void) mongets(mtmp
, ELVEN_SHIELD
);
249 (void) mongets(mtmp
, ELVEN_SPEAR
);
250 (void) mongets(mtmp
, ELVEN_SHIELD
);
254 if (mm
== PM_ELVENKING
) {
255 if (rn2(3) || (in_mklev
&& Is_earthlevel(&u
.uz
)))
256 (void) mongets(mtmp
, PICK_AXE
);
258 (void) mongets(mtmp
, CRYSTAL_BALL
);
260 } else if (ptr
->msound
== MS_PRIEST
261 || quest_mon_represents_role(ptr
, PM_PRIEST
)) {
262 otmp
= mksobj(MACE
, FALSE
, FALSE
);
267 (void) mpickobj(mtmp
, otmp
);
269 } else if (mm
== PM_NINJA
) { /* extra quest villains */
270 (void) mongets(mtmp
, rn2(4) ? SHURIKEN
: DART
);
271 (void) mongets(mtmp
, rn2(4) ? SHORT_SWORD
: AXE
);
272 } else if (ptr
->msound
== MS_GUARDIAN
) {
273 /* quest "guardians" */
282 (void) mongets(mtmp
, rn2(3) ? DAGGER
: KNIFE
);
284 (void) mongets(mtmp
, rn2(3) ? LEATHER_JACKET
: LEATHER_CLOAK
);
286 (void) mongets(mtmp
, rn2(3) ? LOW_BOOTS
: HIGH_BOOTS
);
288 (void) mongets(mtmp
, POT_HEALING
);
294 (void) mongets(mtmp
, rn2(3) ? LONG_SWORD
: SHORT_SWORD
);
295 (void) mongets(mtmp
, rn2(3) ? CHAIN_MAIL
: LEATHER_ARMOR
);
297 (void) mongets(mtmp
, rn2(2) ? LOW_BOOTS
: HIGH_BOOTS
);
299 (void) mongets(mtmp
, LEATHER_CLOAK
);
301 (void) mongets(mtmp
, BOW
);
302 m_initthrow(mtmp
, ARROW
, 12);
306 (void) mongets(mtmp
, rn2(3) ? SHORT_SWORD
: DAGGER
);
308 (void) mongets(mtmp
, rn2(2) ? LEATHER_JACKET
: LEATHER_ARMOR
);
309 (void) mongets(mtmp
, BOW
);
310 m_initthrow(mtmp
, ARROW
, 12);
313 (void) mongets(mtmp
, CLUB
);
314 (void) mongets(mtmp
, rn2(3) ? DAGGER
: KNIFE
);
316 (void) mongets(mtmp
, LEATHER_GLOVES
);
317 (void) mongets(mtmp
, rn2(2) ? LEATHER_JACKET
: LEATHER_ARMOR
);
320 (void) mongets(mtmp
, CLUB
);
321 (void) mongets(mtmp
, LEATHER_ARMOR
);
329 /* create minion stuff; can't use mongets */
330 otmp
= mksobj(LONG_SWORD
, FALSE
, FALSE
);
332 /* maybe make it special */
333 if (!rn2(20) || is_lord(ptr
))
335 artiname(rn2(2) ? ART_DEMONBANE
: ART_SUNSWORD
));
337 otmp
->oerodeproof
= TRUE
;
339 otmp
->spe
= max(otmp
->spe
, spe2
);
340 (void) mpickobj(mtmp
, otmp
);
342 otmp
= mksobj(!rn2(4) || is_lord(ptr
) ? SHIELD_OF_REFLECTION
345 otmp
->cursed
= FALSE
;
346 otmp
->oerodeproof
= TRUE
;
348 (void) mpickobj(mtmp
, otmp
);
353 if (mm
== PM_HOBBIT
) {
356 (void) mongets(mtmp
, DAGGER
);
359 (void) mongets(mtmp
, ELVEN_DAGGER
);
362 (void) mongets(mtmp
, SLING
);
366 (void) mongets(mtmp
, ELVEN_MITHRIL_COAT
);
368 (void) mongets(mtmp
, DWARVISH_CLOAK
);
369 } else if (is_dwarf(ptr
)) {
371 (void) mongets(mtmp
, DWARVISH_CLOAK
);
373 (void) mongets(mtmp
, IRON_SHOES
);
375 (void) mongets(mtmp
, DWARVISH_SHORT_SWORD
);
376 /* note: you can't use a mattock with a shield */
378 (void) mongets(mtmp
, DWARVISH_MATTOCK
);
380 (void) mongets(mtmp
, rn2(2) ? AXE
: DWARVISH_SPEAR
);
381 (void) mongets(mtmp
, DWARVISH_ROUNDSHIELD
);
383 (void) mongets(mtmp
, DWARVISH_IRON_HELM
);
385 (void) mongets(mtmp
, DWARVISH_MITHRIL_COAT
);
387 (void) mongets(mtmp
, !rn2(3) ? PICK_AXE
: DAGGER
);
392 /* create Keystone Kops with cream pies to
393 throw. As suggested by KAA. [MRS] */
395 m_initthrow(mtmp
, CREAM_PIE
, 2);
397 (void) mongets(mtmp
, (rn2(2)) ? CLUB
: RUBBER_HOSE
);
401 (void) mongets(mtmp
, ORCISH_HELM
);
402 switch ((mm
!= PM_ORC_CAPTAIN
) ? mm
403 : rn2(2) ? PM_MORDOR_ORC
: PM_URUK_HAI
) {
406 (void) mongets(mtmp
, SCIMITAR
);
408 (void) mongets(mtmp
, ORCISH_SHIELD
);
410 (void) mongets(mtmp
, KNIFE
);
412 (void) mongets(mtmp
, ORCISH_CHAIN_MAIL
);
416 (void) mongets(mtmp
, ORCISH_CLOAK
);
418 (void) mongets(mtmp
, ORCISH_SHORT_SWORD
);
420 (void) mongets(mtmp
, IRON_SHOES
);
422 (void) mongets(mtmp
, ORCISH_BOW
);
423 m_initthrow(mtmp
, ORCISH_ARROW
, 12);
426 (void) mongets(mtmp
, URUK_HAI_SHIELD
);
429 if (mm
!= PM_ORC_SHAMAN
&& rn2(2))
430 (void) mongets(mtmp
, (mm
== PM_GOBLIN
|| rn2(2) == 0)
436 if (!rn2(mm
== PM_OGRE_KING
? 3 : mm
== PM_OGRE_LORD
? 6 : 12))
437 (void) mongets(mtmp
, BATTLE_AXE
);
439 (void) mongets(mtmp
, CLUB
);
445 (void) mongets(mtmp
, RANSEUR
);
448 (void) mongets(mtmp
, PARTISAN
);
451 (void) mongets(mtmp
, GLAIVE
);
454 (void) mongets(mtmp
, SPETUM
);
460 m_initthrow(mtmp
, DART
, 12);
465 if (ptr
== &mons
[PM_FOREST_CENTAUR
]) {
466 (void) mongets(mtmp
, BOW
);
467 m_initthrow(mtmp
, ARROW
, 12);
469 (void) mongets(mtmp
, CROSSBOW
);
470 m_initthrow(mtmp
, CROSSBOW_BOLT
, 12);
475 (void) mongets(mtmp
, KNIFE
);
476 (void) mongets(mtmp
, LONG_SWORD
);
480 (void) mongets(mtmp
, LEATHER_ARMOR
);
482 (void) mongets(mtmp
, (rn2(3) ? KNIFE
: SHORT_SWORD
));
485 if (mm
== PM_SALAMANDER
)
487 (rn2(7) ? SPEAR
: rn2(3) ? TRIDENT
: STILETTO
));
492 (void) mongets(mtmp
, BULLWHIP
);
493 (void) mongets(mtmp
, BROADSWORD
);
496 (void) mongets(mtmp
, WAN_DEATH
); /* the Wand of Orcus */
498 case PM_HORNED_DEVIL
:
499 (void) mongets(mtmp
, rn2(4) ? TRIDENT
: BULLWHIP
);
502 (void) mongets(mtmp
, WAN_STRIKING
);
505 (void) mongets(mtmp
, FLAIL
);
508 /* prevent djinn and mail daemons from leaving objects when
516 * Now the general case, some chance of getting some type
517 * of weapon for "normal" monsters. Certain special types
518 * of monsters will get a bonus chance or different selections.
520 bias
= is_lord(ptr
) + is_prince(ptr
) * 2 + extra_nasty(ptr
);
521 switch (rnd(14 - (2 * bias
))) {
523 if (strongmonst(ptr
))
524 (void) mongets(mtmp
, BATTLE_AXE
);
526 m_initthrow(mtmp
, DART
, 12);
529 if (strongmonst(ptr
))
530 (void) mongets(mtmp
, TWO_HANDED_SWORD
);
532 (void) mongets(mtmp
, CROSSBOW
);
533 m_initthrow(mtmp
, CROSSBOW_BOLT
, 12);
537 (void) mongets(mtmp
, BOW
);
538 m_initthrow(mtmp
, ARROW
, 12);
541 if (strongmonst(ptr
))
542 (void) mongets(mtmp
, LONG_SWORD
);
544 m_initthrow(mtmp
, DAGGER
, 3);
547 if (strongmonst(ptr
))
548 (void) mongets(mtmp
, LUCERN_HAMMER
);
550 (void) mongets(mtmp
, AKLYS
);
558 if ((int) mtmp
->m_lev
> rn2(75))
559 (void) mongets(mtmp
, rnd_offensive_item(mtmp
));
563 * Makes up money for monster's inventory.
564 * This will change with silver & copper coins
567 mkmonmoney(mtmp
, amount
)
571 struct obj
*gold
= mksobj(GOLD_PIECE
, FALSE
, FALSE
);
574 add_to_minv(mtmp
, gold
);
579 register struct monst
*mtmp
;
582 register struct obj
*otmp
;
583 register struct permonst
*ptr
= mtmp
->data
;
585 if (Is_rogue_level(&u
.uz
))
588 * Soldiers get armour & rations - armour approximates their ac.
589 * Nymphs may get mirror or potion of object detection.
593 if (is_mercenary(ptr
)) {
596 switch (monsndx(ptr
)) {
615 case PM_WATCH_CAPTAIN
:
619 impossible("odd mercenary %d?", monsndx(ptr
));
624 if (mac
< -1 && rn2(5))
625 mac
+= 7 + mongets(mtmp
, (rn2(5)) ? PLATE_MAIL
626 : CRYSTAL_PLATE_MAIL
);
627 else if (mac
< 3 && rn2(5))
629 6 + mongets(mtmp
, (rn2(3)) ? SPLINT_MAIL
: BANDED_MAIL
);
631 mac
+= 3 + mongets(mtmp
, (rn2(3)) ? RING_MAIL
632 : STUDDED_LEATHER_ARMOR
);
634 mac
+= 2 + mongets(mtmp
, LEATHER_ARMOR
);
636 if (mac
< 10 && rn2(3))
637 mac
+= 1 + mongets(mtmp
, HELMET
);
638 else if (mac
< 10 && rn2(2))
639 mac
+= 1 + mongets(mtmp
, DENTED_POT
);
640 if (mac
< 10 && rn2(3))
641 mac
+= 1 + mongets(mtmp
, SMALL_SHIELD
);
642 else if (mac
< 10 && rn2(2))
643 mac
+= 2 + mongets(mtmp
, LARGE_SHIELD
);
644 if (mac
< 10 && rn2(3))
645 mac
+= 1 + mongets(mtmp
, LOW_BOOTS
);
646 else if (mac
< 10 && rn2(2))
647 mac
+= 2 + mongets(mtmp
, HIGH_BOOTS
);
648 if (mac
< 10 && rn2(3))
649 mac
+= 1 + mongets(mtmp
, LEATHER_GLOVES
);
650 else if (mac
< 10 && rn2(2))
651 mac
+= 1 + mongets(mtmp
, LEATHER_CLOAK
);
653 nhUse(mac
); /* suppress 'dead increment' from static analyzer */
655 if (ptr
!= &mons
[PM_GUARD
] && ptr
!= &mons
[PM_WATCHMAN
]
656 && ptr
!= &mons
[PM_WATCH_CAPTAIN
]) {
658 (void) mongets(mtmp
, K_RATION
);
660 (void) mongets(mtmp
, C_RATION
);
661 if (ptr
!= &mons
[PM_SOLDIER
] && !rn2(3))
662 (void) mongets(mtmp
, BUGLE
);
663 } else if (ptr
== &mons
[PM_WATCHMAN
] && rn2(3))
664 (void) mongets(mtmp
, TIN_WHISTLE
);
665 } else if (ptr
== &mons
[PM_SHOPKEEPER
]) {
666 (void) mongets(mtmp
, SKELETON_KEY
);
668 /* MAJOR fall through ... */
670 (void) mongets(mtmp
, WAN_MAGIC_MISSILE
);
672 (void) mongets(mtmp
, POT_EXTRA_HEALING
);
674 (void) mongets(mtmp
, POT_HEALING
);
676 (void) mongets(mtmp
, WAN_STRIKING
);
678 } else if (ptr
->msound
== MS_PRIEST
679 || quest_mon_represents_role(ptr
, PM_PRIEST
)) {
680 (void) mongets(mtmp
, rn2(7) ? ROBE
681 : rn2(3) ? CLOAK_OF_PROTECTION
682 : CLOAK_OF_MAGIC_RESISTANCE
);
683 (void) mongets(mtmp
, SMALL_SHIELD
);
684 mkmonmoney(mtmp
, (long) rn1(10, 20));
685 } else if (quest_mon_represents_role(ptr
, PM_MONK
)) {
686 (void) mongets(mtmp
, rn2(11) ? ROBE
: CLOAK_OF_MAGIC_RESISTANCE
);
691 (void) mongets(mtmp
, MIRROR
);
693 (void) mongets(mtmp
, POT_OBJECT_DETECTION
);
696 if (ptr
== &mons
[PM_MINOTAUR
]) {
697 if (!rn2(3) || (in_mklev
&& Is_earthlevel(&u
.uz
)))
698 (void) mongets(mtmp
, WAN_DIGGING
);
699 } else if (is_giant(ptr
)) {
700 for (cnt
= rn2((int) (mtmp
->m_lev
/ 2)); cnt
; cnt
--) {
701 otmp
= mksobj(rnd_class(DILITHIUM_CRYSTAL
, LUCKSTONE
- 1),
703 otmp
->quan
= (long) rn1(2, 3);
704 otmp
->owt
= weight(otmp
);
705 (void) mpickobj(mtmp
, otmp
);
710 if (ptr
== &mons
[PM_NAZGUL
]) {
711 otmp
= mksobj(RIN_INVISIBILITY
, FALSE
, FALSE
);
713 (void) mpickobj(mtmp
, otmp
);
717 if (ptr
== &mons
[PM_MASTER_LICH
] && !rn2(13))
718 (void) mongets(mtmp
, (rn2(7) ? ATHAME
: WAN_NOTHING
));
719 else if (ptr
== &mons
[PM_ARCH_LICH
] && !rn2(3)) {
720 otmp
= mksobj(rn2(3) ? ATHAME
: QUARTERSTAFF
, TRUE
,
721 rn2(13) ? FALSE
: TRUE
);
725 otmp
->oerodeproof
= 1;
726 (void) mpickobj(mtmp
, otmp
);
731 (void) mongets(mtmp
, MUMMY_WRAPPING
);
735 otmp
= mksobj(LARGE_BOX
, FALSE
, FALSE
);
736 otmp
->spe
= 1; /* flag for special box */
737 otmp
->owt
= weight(otmp
);
738 (void) mpickobj(mtmp
, otmp
);
742 mkmonmoney(mtmp
, (long) d(level_difficulty(), 30));
745 /* moved here from m_initweap() because these don't
746 have AT_WEAP so m_initweap() is not called for them */
747 if (ptr
== &mons
[PM_ICE_DEVIL
] && !rn2(4)) {
748 (void) mongets(mtmp
, SPEAR
);
749 } else if (ptr
== &mons
[PM_ASMODEUS
]) {
750 (void) mongets(mtmp
, WAN_COLD
);
751 (void) mongets(mtmp
, WAN_FIRE
);
755 if (!rn2((In_mines(&u
.uz
) && in_mklev
) ? 20 : 60)) {
756 otmp
= mksobj(rn2(4) ? TALLOW_CANDLE
: WAX_CANDLE
, TRUE
, FALSE
);
758 otmp
->owt
= weight(otmp
);
759 if (!mpickobj(mtmp
, otmp
) && !levl
[mtmp
->mx
][mtmp
->my
].lit
)
760 begin_burn(otmp
, FALSE
);
767 /* ordinary soldiers rarely have access to magic (or gold :-) */
768 if (ptr
== &mons
[PM_SOLDIER
] && rn2(13))
771 if ((int) mtmp
->m_lev
> rn2(50))
772 (void) mongets(mtmp
, rnd_defensive_item(mtmp
));
773 if ((int) mtmp
->m_lev
> rn2(100))
774 (void) mongets(mtmp
, rnd_misc_item(mtmp
));
775 if (likes_gold(ptr
) && !findgold(mtmp
->minvent
) && !rn2(5))
777 (long) d(level_difficulty(), mtmp
->minvent
? 5 : 10));
780 /* Note: for long worms, always call cutworm (cutworm calls clone_mon) */
784 xchar x
, y
; /* clone's preferred location or 0 (near mon) */
789 /* may be too weak or have been extinguished for population control */
790 if (mon
->mhp
<= 1 || (mvitals
[monsndx(mon
->data
)].mvflags
& G_EXTINCT
))
791 return (struct monst
*) 0;
796 if (!enexto(&mm
, mm
.x
, mm
.y
, mon
->data
) || MON_AT(mm
.x
, mm
.y
))
797 return (struct monst
*) 0;
798 } else if (!isok(x
, y
)) {
799 return (struct monst
*) 0; /* paranoia */
803 if (MON_AT(mm
.x
, mm
.y
)) {
804 if (!enexto(&mm
, mm
.x
, mm
.y
, mon
->data
) || MON_AT(mm
.x
, mm
.y
))
805 return (struct monst
*) 0;
809 *m2
= *mon
; /* copy condition of old monster */
810 m2
->mextra
= (struct mextra
*) 0;
813 m2
->m_id
= context
.ident
++;
815 m2
->m_id
= context
.ident
++; /* ident overflowed */
820 m2
->minvent
= (struct obj
*) 0; /* objects don't clone */
821 m2
->mleashed
= FALSE
;
822 /* Max HP the same, but current HP halved for both. The caller
823 * might want to override this by halving the max HP also.
824 * When current HP is odd, the original keeps the extra point.
825 * We know original has more than 1 HP, so both end up with at least 1.
827 m2
->mhpmax
= mon
->mhpmax
;
828 m2
->mhp
= mon
->mhp
/ 2;
831 /* since shopkeepers and guards will only be cloned if they've been
832 * polymorphed away from their original forms, the clone doesn't have
833 * room for the extra information. we also don't want two shopkeepers
834 * around for the same shop.
841 m2
->ispriest
= FALSE
;
842 place_monster(m2
, m2
->mx
, m2
->my
);
843 if (emits_light(m2
->data
))
844 new_light_source(m2
->mx
, m2
->my
, emits_light(m2
->data
), LS_MONSTER
,
846 if (has_mname(mon
)) {
847 m2
= christen_monst(m2
, MNAME(mon
));
848 } else if (mon
->isshk
) {
849 m2
= christen_monst(m2
, shkname(mon
));
852 /* not all clones caused by player are tame or peaceful */
853 if (!context
.mon_moving
) {
855 m2
->mtame
= rn2(max(2 + u
.uluck
, 2)) ? mon
->mtame
: 0;
856 else if (mon
->mpeaceful
)
857 m2
->mpeaceful
= rn2(max(2 + u
.uluck
, 2)) ? 1 : 0;
860 newsym(m2
->mx
, m2
->my
); /* display the new monster */
865 *(EMIN(m2
)) = *(EMIN(mon
));
867 /* because m2 is a copy of mon it is tame but not init'ed.
868 * however, tamedog will not re-tame a tame dog, so m2
869 * must be made non-tame to get initialized properly.
872 if (tamedog(m2
, (struct obj
*) 0)) {
873 *(EDOG(m2
)) = *(EDOG(mon
));
883 * Propagate a species
885 * Once a certain number of monsters are created, don't create any more
886 * at random (i.e. make them extinct). The previous (3.2) behavior was
887 * to do this when a certain number had _died_, which didn't make
890 * Returns FALSE propagation unsuccessful
891 * TRUE propagation successful
894 propagate(mndx
, tally
, ghostly
)
900 uchar lim
= mbirth_limit(mndx
);
901 boolean gone
= (mvitals
[mndx
].mvflags
& G_GONE
) != 0; /* geno'd|extinct */
903 result
= (((int) mvitals
[mndx
].born
< lim
) && !gone
) ? TRUE
: FALSE
;
905 /* if it's unique, don't ever make it again */
906 if (mons
[mndx
].geno
& G_UNIQ
)
907 mvitals
[mndx
].mvflags
|= G_EXTINCT
;
909 if (mvitals
[mndx
].born
< 255 && tally
910 && (!ghostly
|| (ghostly
&& result
)))
911 mvitals
[mndx
].born
++;
912 if ((int) mvitals
[mndx
].born
>= lim
&& !(mons
[mndx
].geno
& G_NOGEN
)
913 && !(mvitals
[mndx
].mvflags
& G_EXTINCT
)) {
915 debugpline1("Automatically extinguished %s.",
916 makeplural(mons
[mndx
].mname
));
918 mvitals
[mndx
].mvflags
|= G_EXTINCT
;
919 reset_rndmonst(mndx
);
924 /* amount of HP to lose from level drain (or gain from Stormbringer) */
929 struct permonst
*ptr
= mon
->data
;
930 int hp
= rnd(8); /* default is d8 */
932 /* like newmonhp, but home elementals are ignored, riders use normal d8 */
934 /* draining usually won't be applicable for these critters */
935 hp
= golemhp(monsndx(ptr
)) / (int) ptr
->mlevel
;
936 } else if (ptr
->mlevel
> 49) {
937 /* arbitrary; such monsters won't be involved in draining anyway */
938 hp
= 4 + rnd(4); /* 5..8 */
939 } else if (ptr
->mlet
== S_DRAGON
&& monsndx(ptr
) >= PM_GRAY_DRAGON
) {
940 /* adult dragons; newmonhp() uses In_endgame(&u.uz) ? 8 : 4 + rnd(4)
942 hp
= 4 + rn2(5); /* 4..8 */
943 } else if (!mon
->m_lev
) {
944 /* level 0 monsters use 1d4 instead of Nd8 */
950 /* set up a new monster's initial level and hit points;
951 used by newcham() as well as by makemon() */
957 struct permonst
*ptr
= &mons
[mndx
];
959 mon
->m_lev
= adj_lev(ptr
);
961 mon
->mhpmax
= mon
->mhp
= golemhp(mndx
);
962 } else if (is_rider(ptr
)) {
963 /* we want low HP, but a high mlevel so they can attack well */
964 mon
->mhpmax
= mon
->mhp
= d(10, 8);
965 } else if (ptr
->mlevel
> 49) {
966 /* "special" fixed hp monster
967 * the hit points are encoded in the mlevel in a somewhat strange
968 * way to fit in the 50..127 positive range of a signed character
969 * above the 1..49 that indicate "normal" monster levels */
970 mon
->mhpmax
= mon
->mhp
= 2 * (ptr
->mlevel
- 6);
971 mon
->m_lev
= mon
->mhp
/ 4; /* approximation */
972 } else if (ptr
->mlet
== S_DRAGON
&& mndx
>= PM_GRAY_DRAGON
) {
974 mon
->mhpmax
= mon
->mhp
=
975 (int) (In_endgame(&u
.uz
)
977 : (4 * mon
->m_lev
+ d((int) mon
->m_lev
, 4)));
978 } else if (!mon
->m_lev
) {
979 mon
->mhpmax
= mon
->mhp
= rnd(4);
981 mon
->mhpmax
= mon
->mhp
= d((int) mon
->m_lev
, 8);
982 if (is_home_elemental(ptr
))
983 mon
->mhpmax
= (mon
->mhp
*= 3);
990 struct mextra
*mextra
;
992 mextra
= (struct mextra
*) alloc(sizeof(struct mextra
));
999 mextra
->mcorpsenm
= NON_PM
;
1004 makemon_rnd_goodpos(mon
, gpflags
, cc
)
1014 nx
= rn1(COLNO
- 3, 2);
1016 good
= (!in_mklev
&& cansee(nx
,ny
)) ? FALSE
1017 : goodpos(nx
, ny
, mon
, gpflags
);
1018 } while ((++tryct
< 50) && !good
);
1021 /* else go through all map positions, twice, first round
1022 ignoring positions in sight, and pick first good one.
1023 skip first round if we're in special level loader or blind */
1027 int bl
= (in_mklev
|| Blind
) ? 1 : 0;
1029 for ( ; bl
< 2; bl
++) {
1030 for (dx
= 0; dx
< COLNO
; dx
++)
1031 for (dy
= 0; dy
< ROWNO
; dy
++) {
1032 nx
= ((dx
+ xofs
) % (COLNO
- 1)) + 1;
1033 ny
= ((dy
+ yofs
) % (ROWNO
- 1)) + 1;
1034 if (bl
== 0 && cansee(nx
,ny
))
1036 if (goodpos(nx
, ny
, mon
, gpflags
))
1039 if (bl
== 0 && (!mon
|| mon
->data
->mmove
)) {
1040 /* all map positions are visible (or not good),
1041 try to pick something logical */
1042 if (dnstair
.sx
&& !rn2(2)) {
1045 } else if (upstair
.sx
&& !rn2(2)) {
1048 } else if (dnladder
.sx
&& !rn2(2)) {
1051 } else if (upladder
.sx
&& !rn2(2)) {
1055 if (goodpos(nx
, ny
, mon
, gpflags
))
1069 * called with [x,y] = coordinates;
1070 * [0,0] means anyplace
1071 * [u.ux,u.uy] means: near player (if !in_mklev)
1073 * In case we make a monster group, only return the one at [x,y].
1076 makemon(ptr
, x
, y
, mmflags
)
1077 register struct permonst
*ptr
;
1081 register struct monst
*mtmp
;
1082 int mndx
, mcham
, ct
, mitem
;
1083 boolean anymon
= (!ptr
);
1084 boolean byyou
= (x
== u
.ux
&& y
== u
.uy
);
1085 boolean allow_minvent
= ((mmflags
& NO_MINVENT
) == 0);
1086 boolean countbirth
= ((mmflags
& MM_NOCOUNTBIRTH
) == 0);
1087 unsigned gpflags
= (mmflags
& MM_IGNOREWATER
) ? MM_IGNOREWATER
: 0;
1089 /* if caller wants random location, do it here */
1090 if (x
== 0 && y
== 0) {
1092 struct monst fakemon
;
1094 cc
.x
= cc
.y
= 0; /* lint suppression */
1095 fakemon
.data
= ptr
; /* set up for goodpos */
1096 if (!makemon_rnd_goodpos(ptr
? &fakemon
: (struct monst
*)0,
1098 return (struct monst
*) 0;
1101 } else if (byyou
&& !in_mklev
) {
1104 if (enexto_core(&bypos
, u
.ux
, u
.uy
, ptr
, gpflags
)) {
1108 return (struct monst
*) 0;
1111 /* Does monster already exist at the position? */
1113 if ((mmflags
& MM_ADJACENTOK
) != 0) {
1115 if (enexto_core(&bypos
, x
, y
, ptr
, gpflags
)) {
1119 return (struct monst
*) 0;
1121 return (struct monst
*) 0;
1125 mndx
= monsndx(ptr
);
1126 /* if you are to make a specific monster and it has
1127 already been genocided, return */
1128 if (mvitals
[mndx
].mvflags
& G_GENOD
)
1129 return (struct monst
*) 0;
1130 if (wizard
&& (mvitals
[mndx
].mvflags
& G_EXTINCT
)) {
1131 debugpline1("Explicitly creating extinct monster %s.",
1135 /* make a random (common) monster that can survive here.
1136 * (the special levels ask for random monsters at specific
1137 * positions, causing mass drowning on the medusa level,
1140 int tryct
= 0; /* maybe there are no good choices */
1141 struct monst fakemon
;
1144 if (!(ptr
= rndmonst())) {
1145 debugpline0("Warning: no monster.");
1146 return (struct monst
*) 0; /* no more monsters! */
1148 fakemon
.data
= ptr
; /* set up for goodpos */
1149 } while (++tryct
<= 50
1150 /* in Sokoban, don't accept a giant on first try;
1151 after that, boulder carriers are fair game */
1152 && ((tryct
== 1 && throws_rocks(ptr
) && In_sokoban(&u
.uz
))
1153 || !goodpos(x
, y
, &fakemon
, gpflags
)));
1154 mndx
= monsndx(ptr
);
1156 (void) propagate(mndx
, countbirth
, FALSE
);
1158 *mtmp
= zeromonst
; /* clear all entries in structure */
1160 if (mmflags
& MM_EGD
)
1162 if (mmflags
& MM_EPRI
)
1164 if (mmflags
& MM_ESHK
)
1166 if (mmflags
& MM_EMIN
)
1168 if (mmflags
& MM_EDOG
)
1173 mtmp
->m_id
= context
.ident
++;
1175 mtmp
->m_id
= context
.ident
++; /* ident overflowed */
1176 set_mon_data(mtmp
, ptr
, 0);
1177 if (ptr
->msound
== MS_LEADER
&& quest_info(MS_LEADER
) == mndx
)
1178 quest_status
.leader_m_id
= mtmp
->m_id
;
1181 /* set up level and hit points */
1182 newmonhp(mtmp
, mndx
);
1185 mtmp
->female
= TRUE
;
1186 else if (is_male(ptr
))
1187 mtmp
->female
= FALSE
;
1188 /* leader and nemesis gender is usually hardcoded in mons[],
1189 but for ones which can be random, it has already been chosen
1190 (in role_init(), for possible use by the quest pager code) */
1191 else if (ptr
->msound
== MS_LEADER
&& quest_info(MS_LEADER
) == mndx
)
1192 mtmp
->female
= quest_status
.ldrgend
;
1193 else if (ptr
->msound
== MS_NEMESIS
&& quest_info(MS_NEMESIS
) == mndx
)
1194 mtmp
->female
= quest_status
.nemgend
;
1196 mtmp
->female
= rn2(2); /* ignored for neuters */
1198 if (In_sokoban(&u
.uz
) && !mindless(ptr
)) /* know about traps here */
1199 mtmp
->mtrapseen
= (1L << (PIT
- 1)) | (1L << (HOLE
- 1));
1200 /* quest leader and nemesis both know about all trap types */
1201 if (ptr
->msound
== MS_LEADER
|| ptr
->msound
== MS_NEMESIS
)
1202 mtmp
->mtrapseen
= ~0;
1204 place_monster(mtmp
, x
, y
);
1205 mtmp
->mcansee
= mtmp
->mcanmove
= TRUE
;
1206 mtmp
->mpeaceful
= (mmflags
& MM_ANGRY
) ? FALSE
: peace_minded(ptr
);
1208 switch (ptr
->mlet
) {
1210 set_mimic_sym(mtmp
);
1216 (void) mkobj_at(0, x
, y
, TRUE
);
1217 (void) hideunder(mtmp
);
1221 if (mndx
== PM_STALKER
|| mndx
== PM_BLACK_LIGHT
) {
1222 mtmp
->perminvis
= TRUE
;
1223 mtmp
->minvis
= TRUE
;
1227 (void) hideunder(mtmp
);
1230 mtmp
->msleeping
= 1;
1234 if (rn2(5) && !u
.uhave
.amulet
)
1235 mtmp
->msleeping
= 1;
1238 if (Race_if(PM_ELF
))
1239 mtmp
->mpeaceful
= FALSE
;
1242 if (is_unicorn(ptr
) && sgn(u
.ualign
.type
) == sgn(ptr
->maligntyp
))
1243 mtmp
->mpeaceful
= TRUE
;
1246 if (Inhell
&& is_bat(ptr
))
1247 mon_adjust_speed(mtmp
, 2, (struct obj
*) 0);
1250 if ((ct
= emits_light(mtmp
->data
)) > 0)
1251 new_light_source(mtmp
->mx
, mtmp
->my
, ct
, LS_MONSTER
,
1252 monst_to_any(mtmp
));
1253 mitem
= 0; /* extra inventory item for this monster */
1255 if (mndx
== PM_VLAD_THE_IMPALER
)
1256 mitem
= CANDELABRUM_OF_INVOCATION
;
1257 mtmp
->cham
= NON_PM
; /* default is "not a shapechanger" */
1258 if ((mcham
= pm_to_cham(mndx
)) != NON_PM
) {
1259 /* this is a shapechanger after all */
1260 if (Protection_from_shape_changers
1261 || mndx
== PM_VLAD_THE_IMPALER
) {
1262 ; /* stuck in its natural form (NON_PM) */
1265 /* Note: shapechanger's initial form used to be
1266 chosen here with rndmonst(), yielding a monster
1267 which was appropriate to the level's difficulty
1268 but ignored the changer's usual type selection
1269 so would be inappropriate for vampshifters.
1270 Let newcham() pick the shape. */
1271 if (newcham(mtmp
, (struct permonst
*) 0, FALSE
, FALSE
))
1272 allow_minvent
= FALSE
;
1274 } else if (mndx
== PM_WIZARD_OF_YENDOR
) {
1276 context
.no_of_wizards
++;
1277 if (context
.no_of_wizards
== 1 && Is_earthlevel(&u
.uz
))
1279 } else if (mndx
== PM_GHOST
&& !(mmflags
& MM_NONAME
)) {
1280 mtmp
= christen_monst(mtmp
, rndghostname());
1281 } else if (mndx
== PM_CROESUS
) {
1282 mitem
= TWO_HANDED_SWORD
;
1283 } else if (ptr
->msound
== MS_NEMESIS
) {
1284 mitem
= BELL_OF_OPENING
;
1285 } else if (mndx
== PM_PESTILENCE
) {
1286 mitem
= POT_SICKNESS
;
1288 if (mitem
&& allow_minvent
)
1289 (void) mongets(mtmp
, mitem
);
1292 if ((is_ndemon(ptr
) || mndx
== PM_WUMPUS
1293 || mndx
== PM_LONG_WORM
|| mndx
== PM_GIANT_EEL
)
1294 && !u
.uhave
.amulet
&& rn2(5))
1295 mtmp
->msleeping
= TRUE
;
1298 newsym(mtmp
->mx
, mtmp
->my
);
1302 if (is_dprince(ptr
) && ptr
->msound
== MS_BRIBE
) {
1303 mtmp
->mpeaceful
= mtmp
->minvis
= mtmp
->perminvis
= 1;
1305 if (uwep
&& uwep
->oartifact
== ART_EXCALIBUR
)
1306 mtmp
->mpeaceful
= mtmp
->mtame
= FALSE
;
1309 if (mndx
== PM_LONG_WORM
&& (mtmp
->wormno
= get_wormno()) != 0)
1311 /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
1313 if (mndx
== PM_LONG_WORM
1314 && (mtmp
->wormno
= get_wormno(), mtmp
->wormno
!= 0))
1317 /* we can now create worms with tails - 11/91 */
1318 initworm(mtmp
, rn2(5));
1319 if (count_wsegs(mtmp
))
1320 place_worm_tail_randomly(mtmp
, x
, y
);
1322 /* it's possible to create an ordinary monster of some special
1323 types; make sure their extended data is initialized to
1324 something sensible if caller hasn't specified MM_EPRI|MM_EMIN
1325 (when they're specified, caller intends to handle this itself) */
1326 if ((mndx
== PM_ALIGNED_PRIEST
|| mndx
== PM_HIGH_PRIEST
)
1327 ? !(mmflags
& (MM_EPRI
| MM_EMIN
))
1328 : (mndx
== PM_ANGEL
&& !(mmflags
& MM_EMIN
) && !rn2(3))) {
1333 mtmp
->isminion
= 1; /* make priest be a roamer */
1334 eminp
->min_align
= rn2(3) - 1; /* no A_NONE */
1335 eminp
->renegade
= (boolean
) ((mmflags
& MM_ANGRY
) ? 1 : !rn2(3));
1336 mtmp
->mpeaceful
= (eminp
->min_align
== u
.ualign
.type
)
1340 set_malign(mtmp
); /* having finished peaceful changes */
1342 if ((ptr
->geno
& G_SGROUP
) && rn2(2)) {
1343 m_initsgrp(mtmp
, mtmp
->mx
, mtmp
->my
);
1344 } else if (ptr
->geno
& G_LGROUP
) {
1346 m_initlgrp(mtmp
, mtmp
->mx
, mtmp
->my
);
1348 m_initsgrp(mtmp
, mtmp
->mx
, mtmp
->my
);
1352 if (allow_minvent
) {
1354 m_initweap(mtmp
); /* equip with weapons / armor */
1355 m_initinv(mtmp
); /* add on a few special items incl. more armor */
1356 m_dowear(mtmp
, TRUE
);
1358 if (!rn2(100) && is_domestic(ptr
)
1359 && can_saddle(mtmp
) && !which_armor(mtmp
, W_SADDLE
)) {
1360 struct obj
*otmp
= mksobj(SADDLE
, TRUE
, FALSE
);
1361 put_saddle_on_mon(otmp
, mtmp
);
1365 /* no initial inventory is allowed */
1367 discard_minvent(mtmp
);
1368 mtmp
->minvent
= (struct obj
*) 0; /* caller expects this */
1370 if (ptr
->mflags3
&& !(mmflags
& MM_NOWAIT
)) {
1371 if (ptr
->mflags3
& M3_WAITFORU
)
1372 mtmp
->mstrategy
|= STRAT_WAITFORU
;
1373 if (ptr
->mflags3
& M3_CLOSE
)
1374 mtmp
->mstrategy
|= STRAT_CLOSE
;
1375 if (ptr
->mflags3
& (M3_WAITMASK
| M3_COVETOUS
))
1376 mtmp
->mstrategy
|= STRAT_APPEARMSG
;
1380 newsym(mtmp
->mx
, mtmp
->my
); /* make sure the mon shows up */
1389 /* There is an implicit limit of 4 for "high priest of <deity>",
1390 * but aligned priests can grow into high priests, thus they aren't
1391 * really limited to 4, so leave the default amount in place for them.
1394 /* assert(MAXMONNO < 255); */
1395 return (mndx
== PM_NAZGUL
? 9 : mndx
== PM_ERINYS
? 3 : MAXMONNO
);
1398 /* used for wand/scroll/spell of create monster */
1399 /* returns TRUE iff you know monsters have been created */
1401 create_critters(cnt
, mptr
, neverask
)
1403 struct permonst
*mptr
; /* usually null; used for confused reading */
1409 boolean known
= FALSE
;
1410 boolean ask
= (wizard
&& !neverask
);
1414 if (create_particular()) {
1418 ask
= FALSE
; /* ESC will shut off prompting */
1421 /* if in water, try to encourage an aquatic monster
1422 by finding and then specifying another wet location */
1423 if (!mptr
&& u
.uinwater
&& enexto(&c
, x
, y
, &mons
[PM_GIANT_EEL
]))
1426 mon
= makemon(mptr
, x
, y
, NO_MM_FLAGS
);
1427 if (mon
&& canspotmon(mon
))
1437 if (mons
[mndx
].geno
& (G_NOGEN
| G_UNIQ
))
1439 if (mvitals
[mndx
].mvflags
& G_GONE
)
1442 return (boolean
) (mons
[mndx
].maligntyp
> A_NEUTRAL
);
1444 return (boolean
) ((mons
[mndx
].geno
& G_HELL
) != 0);
1448 * shift the probability of a monster's generation by
1449 * comparing the dungeon alignment and monster alignment.
1450 * return an integer in the range of 0-5.
1454 register struct permonst
*ptr
;
1456 static NEARDATA
long oldmoves
= 0L; /* != 1, starting value of moves */
1457 static NEARDATA s_level
*lev
;
1458 register int alshift
;
1460 if (oldmoves
!= moves
) {
1461 lev
= Is_special(&u
.uz
);
1464 switch ((lev
) ? lev
->flags
.align
: dungeons
[u
.uz
.dnum
].flags
.align
) {
1465 default: /* just in case */
1470 alshift
= (ptr
->maligntyp
+ 20) / (2 * ALIGNWEIGHT
);
1473 alshift
= (20 - abs(ptr
->maligntyp
)) / ALIGNWEIGHT
;
1476 alshift
= (-(ptr
->maligntyp
- 20)) / (2 * ALIGNWEIGHT
);
1482 static NEARDATA
struct {
1484 char mchoices
[SPECIAL_PM
]; /* value range is 0..127 */
1485 } rndmonst_state
= { -1, { 0 } };
1487 /* select a random monster type */
1491 register struct permonst
*ptr
;
1492 register int mndx
, ct
;
1494 if (u
.uz
.dnum
== quest_dnum
&& rn2(7) && (ptr
= qt_montype()) != 0)
1497 if (rndmonst_state
.choice_count
< 0) { /* need to recalculate */
1498 int zlevel
, minmlev
, maxmlev
;
1502 rndmonst_state
.choice_count
= 0;
1503 /* look for first common monster */
1504 for (mndx
= LOW_PM
; mndx
< SPECIAL_PM
; mndx
++) {
1505 if (!uncommon(mndx
))
1507 rndmonst_state
.mchoices
[mndx
] = 0;
1509 if (mndx
== SPECIAL_PM
) {
1510 /* evidently they've all been exterminated */
1511 debugpline0("rndmonst: no common mons!");
1512 return (struct permonst
*) 0;
1513 } /* else `mndx' now ready for use below */
1514 zlevel
= level_difficulty();
1515 /* determine the level of the weakest monster to make. */
1516 minmlev
= zlevel
/ 6;
1517 /* determine the level of the strongest monster to make. */
1518 maxmlev
= (zlevel
+ u
.ulevel
) / 2;
1519 upper
= Is_rogue_level(&u
.uz
);
1520 elemlevel
= In_endgame(&u
.uz
) && !Is_astralevel(&u
.uz
);
1523 * Find out how many monsters exist in the range we have selected.
1525 for ( ; mndx
< SPECIAL_PM
; mndx
++) { /* (`mndx' initialized above) */
1527 rndmonst_state
.mchoices
[mndx
] = 0;
1528 if (tooweak(mndx
, minmlev
) || toostrong(mndx
, maxmlev
))
1530 if (upper
&& !isupper((uchar
) def_monsyms
[(int) ptr
->mlet
].sym
))
1532 if (elemlevel
&& wrong_elem_type(ptr
))
1536 if (Inhell
&& (ptr
->geno
& G_NOHELL
))
1538 ct
= (int) (ptr
->geno
& G_FREQ
) + align_shift(ptr
);
1539 if (ct
< 0 || ct
> 127)
1540 panic("rndmonst: bad count [#%d: %d]", mndx
, ct
);
1541 rndmonst_state
.choice_count
+= ct
;
1542 rndmonst_state
.mchoices
[mndx
] = (char) ct
;
1545 * Possible modification: if choice_count is "too low",
1546 * expand minmlev..maxmlev range and try again.
1548 } /* choice_count+mchoices[] recalc */
1550 if (rndmonst_state
.choice_count
<= 0) {
1551 /* maybe no common mons left, or all are too weak or too strong */
1552 debugpline1("rndmonst: choice_count=%d", rndmonst_state
.choice_count
);
1553 return (struct permonst
*) 0;
1557 * Now, select a monster at random.
1559 ct
= rnd(rndmonst_state
.choice_count
);
1560 for (mndx
= LOW_PM
; mndx
< SPECIAL_PM
; mndx
++)
1561 if ((ct
-= (int) rndmonst_state
.mchoices
[mndx
]) <= 0)
1564 if (mndx
== SPECIAL_PM
|| uncommon(mndx
)) { /* shouldn't happen */
1565 impossible("rndmonst: bad `mndx' [#%d]", mndx
);
1566 return (struct permonst
*) 0;
1571 /* called when you change level (experience or dungeon depth) or when
1572 monster species can no longer be created (genocide or extinction) */
1574 reset_rndmonst(mndx
)
1575 int mndx
; /* particular species that can no longer be created */
1577 /* cached selection info is out of date */
1578 if (mndx
== NON_PM
) {
1579 rndmonst_state
.choice_count
= -1; /* full recalc needed */
1580 } else if (mndx
< SPECIAL_PM
) {
1581 rndmonst_state
.choice_count
-= rndmonst_state
.mchoices
[mndx
];
1582 rndmonst_state
.mchoices
[mndx
] = 0;
1583 } /* note: safe to ignore extinction of unique monsters */
1586 /* decide whether it's ok to generate a candidate monster by mkclass() */
1588 mk_gen_ok(mndx
, mvflagsmask
, genomask
)
1589 int mndx
, mvflagsmask
, genomask
;
1591 struct permonst
*ptr
= &mons
[mndx
];
1593 if (mvitals
[mndx
].mvflags
& mvflagsmask
)
1595 if (ptr
->geno
& genomask
)
1597 if (is_placeholder(ptr
))
1600 /* special levels might ask for random demon type; reject this one */
1601 if (ptr
== &mons
[PM_MAIL_DAEMON
])
1607 /* Make one of the multiple types of a given monster class.
1608 * The second parameter specifies a special casing bit mask
1609 * to allow the normal genesis masks to be deactivated.
1610 * Returns Null if no monsters in that class can be made.
1617 register int first
, last
, num
= 0;
1618 int maxmlev
, mask
= (G_NOGEN
| G_UNIQ
) & ~spc
;
1620 maxmlev
= level_difficulty() >> 1;
1621 if (class < 1 || class >= MAXMCLASSES
) {
1622 impossible("mkclass called with bad class!");
1623 return (struct permonst
*) 0;
1625 /* Assumption #1: monsters of a given class are contiguous in the
1628 for (first
= LOW_PM
; first
< SPECIAL_PM
; first
++)
1629 if (mons
[first
].mlet
== class)
1631 if (first
== SPECIAL_PM
)
1632 return (struct permonst
*) 0;
1634 for (last
= first
; last
< SPECIAL_PM
&& mons
[last
].mlet
== class; last
++)
1635 if (mk_gen_ok(last
, G_GONE
, mask
)) {
1637 if (num
&& toostrong(last
, maxmlev
)
1638 && monstr
[last
] != monstr
[last
- 1] && rn2(2))
1640 num
+= mons
[last
].geno
& G_FREQ
;
1643 return (struct permonst
*) 0;
1645 /* Assumption #2: monsters of a given class are presented in ascending
1646 * order of strength.
1648 for (num
= rnd(num
); num
> 0; first
++)
1649 if (mk_gen_ok(first
, G_GONE
, mask
)) {
1650 /* skew towards lower value monsters at lower exp. levels */
1651 num
-= mons
[first
].geno
& G_FREQ
;
1652 if (num
&& adj_lev(&mons
[first
]) > (u
.ulevel
* 2)) {
1653 /* but not when multiple monsters are same level */
1654 if (mons
[first
].mlevel
!= mons
[first
+ 1].mlevel
)
1658 first
--; /* correct an off-by-one error */
1660 return &mons
[first
];
1663 /* like mkclass(), but excludes difficulty considerations; used when
1664 player with polycontrol picks a class instead of a specific type;
1665 genocided types are avoided but extinct ones are acceptable; we don't
1666 check polyok() here--caller accepts some choices !polyok() would reject */
1671 register int first
, last
, num
= 0;
1673 for (first
= LOW_PM
; first
< SPECIAL_PM
; first
++)
1674 if (mons
[first
].mlet
== class)
1676 if (first
== SPECIAL_PM
)
1679 for (last
= first
; last
< SPECIAL_PM
&& mons
[last
].mlet
== class; last
++)
1680 if (mk_gen_ok(last
, G_GENOD
, (G_NOGEN
| G_UNIQ
)))
1681 num
+= mons
[last
].geno
& G_FREQ
;
1685 for (num
= rnd(num
); num
> 0; first
++)
1686 if (mk_gen_ok(first
, G_GENOD
, (G_NOGEN
| G_UNIQ
)))
1687 num
-= mons
[first
].geno
& G_FREQ
;
1688 first
--; /* correct an off-by-one error */
1693 /* adjust strength of monsters based on u.uz and u.ulevel */
1696 register struct permonst
*ptr
;
1700 if (ptr
== &mons
[PM_WIZARD_OF_YENDOR
]) {
1701 /* does not depend on other strengths, but does get stronger
1702 * every time he is killed
1704 tmp
= ptr
->mlevel
+ mvitals
[PM_WIZARD_OF_YENDOR
].died
;
1710 if ((tmp
= ptr
->mlevel
) > 49)
1711 return 50; /* "special" demons/devils */
1712 tmp2
= (level_difficulty() - tmp
);
1714 tmp
--; /* if mlevel > u.uz decrement tmp */
1716 tmp
+= (tmp2
/ 5); /* else increment 1 per five diff */
1718 tmp2
= (u
.ulevel
- ptr
->mlevel
); /* adjust vs. the player */
1720 tmp
+= (tmp2
/ 4); /* level as well */
1722 tmp2
= (3 * ((int) ptr
->mlevel
)) / 2; /* crude upper limit */
1724 tmp2
= 49; /* hard upper limit */
1725 return ((tmp
> tmp2
) ? tmp2
: (tmp
> 0 ? tmp
: 0)); /* 0 lower limit */
1728 /* monster earned experience and will gain some hit points; it might also
1729 grow into a bigger monster (baby to adult, soldier to officer, etc) */
1731 grow_up(mtmp
, victim
)
1732 struct monst
*mtmp
, *victim
;
1734 int oldtype
, newtype
, max_increase
, cur_increase
, lev_limit
, hp_threshold
;
1736 struct permonst
*ptr
= mtmp
->data
;
1738 /* monster died after killing enemy but before calling this function */
1739 /* currently possible if killing a gas spore */
1741 return (struct permonst
*) 0;
1743 /* note: none of the monsters with special hit point calculations
1744 have both little and big forms */
1745 oldtype
= monsndx(ptr
);
1746 newtype
= little_to_big(oldtype
);
1747 if (newtype
== PM_PRIEST
&& mtmp
->female
)
1748 newtype
= PM_PRIESTESS
;
1750 /* growth limits differ depending on method of advancement */
1751 if (victim
) { /* killed a monster */
1753 * The HP threshold is the maximum number of hit points for the
1754 * current level; once exceeded, a level will be gained.
1755 * Possible bug: if somehow the hit points are already higher
1756 * than that, monster will gain a level without any increase in HP.
1758 hp_threshold
= mtmp
->m_lev
* 8; /* normal limit */
1761 else if (is_golem(ptr
)) /* strange creatures */
1762 hp_threshold
= ((mtmp
->mhpmax
/ 10) + 1) * 10 - 1;
1763 else if (is_home_elemental(ptr
))
1765 lev_limit
= 3 * (int) ptr
->mlevel
/ 2; /* same as adj_lev() */
1766 /* If they can grow up, be sure the level is high enough for that */
1767 if (oldtype
!= newtype
&& mons
[newtype
].mlevel
> lev_limit
)
1768 lev_limit
= (int) mons
[newtype
].mlevel
;
1769 /* number of hit points to gain; unlike for the player, we put
1770 the limit at the bottom of the next level rather than the top */
1771 max_increase
= rnd((int) victim
->m_lev
+ 1);
1772 if (mtmp
->mhpmax
+ max_increase
> hp_threshold
+ 1)
1773 max_increase
= max((hp_threshold
+ 1) - mtmp
->mhpmax
, 0);
1774 cur_increase
= (max_increase
> 1) ? rn2(max_increase
) : 0;
1776 /* a gain level potion or wraith corpse; always go up a level
1777 unless already at maximum (49 is hard upper limit except
1778 for demon lords, who start at 50 and can't go any higher) */
1779 max_increase
= cur_increase
= rnd(8);
1780 hp_threshold
= 0; /* smaller than `mhpmax + max_increase' */
1781 lev_limit
= 50; /* recalc below */
1784 mtmp
->mhpmax
+= max_increase
;
1785 mtmp
->mhp
+= cur_increase
;
1786 if (mtmp
->mhpmax
<= hp_threshold
)
1787 return ptr
; /* doesn't gain a level */
1789 if (is_mplayer(ptr
))
1790 lev_limit
= 30; /* same as player */
1791 else if (lev_limit
< 5)
1792 lev_limit
= 5; /* arbitrary */
1793 else if (lev_limit
> 49)
1794 lev_limit
= (ptr
->mlevel
> 49 ? 50 : 49);
1796 if ((int) ++mtmp
->m_lev
>= mons
[newtype
].mlevel
&& newtype
!= oldtype
) {
1797 ptr
= &mons
[newtype
];
1798 /* new form might force gender change */
1799 fem
= is_male(ptr
) ? 0 : is_female(ptr
) ? 1 : mtmp
->female
;
1801 if (mvitals
[newtype
].mvflags
& G_GENOD
) { /* allow G_EXTINCT */
1802 if (canspotmon(mtmp
))
1803 pline("As %s grows up into %s, %s %s!", mon_nam(mtmp
),
1804 an(ptr
->mname
), mhe(mtmp
),
1805 nonliving(ptr
) ? "expires" : "dies");
1806 set_mon_data(mtmp
, ptr
, -1); /* keep mvitals[] accurate */
1808 return (struct permonst
*) 0;
1809 } else if (canspotmon(mtmp
)) {
1813 * Temporary (?) hack to fix growing into opposite gender.
1815 Sprintf(buf
, "%s%s",
1816 /* deal with female gnome becoming a gnome lord */
1817 (mtmp
->female
&& !fem
) ? "male "
1818 /* or a male gnome becoming a gnome lady
1819 (can't happen with 3.6.0 mons[], but perhaps
1820 slightly less sexist if prepared for it...) */
1821 : (fem
&& !mtmp
->female
) ? "female " : "",
1823 pline("%s %s %s.", Monnam(mtmp
),
1824 (fem
!= mtmp
->female
) ? "changes into"
1825 : humanoid(ptr
) ? "becomes"
1829 set_mon_data(mtmp
, ptr
, 1); /* preserve intrinsics */
1830 newsym(mtmp
->mx
, mtmp
->my
); /* color may change */
1831 lev_limit
= (int) mtmp
->m_lev
; /* never undo increment */
1833 mtmp
->female
= fem
; /* gender might be changing */
1837 if ((int) mtmp
->m_lev
> lev_limit
) {
1838 mtmp
->m_lev
--; /* undo increment */
1839 /* HP might have been allowed to grow when it shouldn't */
1840 if (mtmp
->mhpmax
== hp_threshold
+ 1)
1843 if (mtmp
->mhpmax
> 50 * 8)
1844 mtmp
->mhpmax
= 50 * 8; /* absolute limit */
1845 if (mtmp
->mhp
> mtmp
->mhpmax
)
1846 mtmp
->mhp
= mtmp
->mhpmax
;
1853 register struct monst
*mtmp
;
1856 register struct obj
*otmp
;
1861 otmp
= mksobj(otyp
, TRUE
, FALSE
);
1863 if (mtmp
->data
->mlet
== S_DEMON
) {
1864 /* demons never get blessed objects */
1867 } else if (is_lminion(mtmp
)) {
1868 /* lawful minions don't get cursed, bad, or rusting objects */
1869 otmp
->cursed
= FALSE
;
1872 otmp
->oerodeproof
= TRUE
;
1873 } else if (is_mplayer(mtmp
->data
) && is_sword(otmp
)) {
1874 otmp
->spe
= (3 + rn2(4));
1877 if (otmp
->otyp
== CANDELABRUM_OF_INVOCATION
) {
1880 otmp
->lamplit
= FALSE
;
1881 otmp
->blessed
= otmp
->cursed
= FALSE
;
1882 } else if (otmp
->otyp
== BELL_OF_OPENING
) {
1883 otmp
->blessed
= otmp
->cursed
= FALSE
;
1884 } else if (otmp
->otyp
== SPE_BOOK_OF_THE_DEAD
) {
1885 otmp
->blessed
= FALSE
;
1886 otmp
->cursed
= TRUE
;
1889 /* leaders don't tolerate inferior quality battle gear */
1890 if (is_prince(mtmp
->data
)) {
1891 if (otmp
->oclass
== WEAPON_CLASS
&& otmp
->spe
< 1)
1893 else if (otmp
->oclass
== ARMOR_CLASS
&& otmp
->spe
< 0)
1898 (void) mpickobj(mtmp
, otmp
); /* might free otmp */
1909 case PM_STRAW_GOLEM
:
1911 case PM_PAPER_GOLEM
:
1915 case PM_LEATHER_GOLEM
:
1921 case PM_FLESH_GOLEM
:
1925 case PM_STONE_GOLEM
:
1927 case PM_GLASS_GOLEM
:
1937 * Alignment vs. yours determines monster's attitude to you.
1938 * (Some "animal" types are co-aligned, but also hungry.)
1942 register struct permonst
*ptr
;
1944 aligntyp mal
= ptr
->maligntyp
, ual
= u
.ualign
.type
;
1946 if (always_peaceful(ptr
))
1948 if (always_hostile(ptr
))
1950 if (ptr
->msound
== MS_LEADER
|| ptr
->msound
== MS_GUARDIAN
)
1952 if (ptr
->msound
== MS_NEMESIS
)
1955 if (race_peaceful(ptr
))
1957 if (race_hostile(ptr
))
1960 /* the monster is hostile if its alignment is different from the
1962 if (sgn(mal
) != sgn(ual
))
1965 /* Negative monster hostile to player with Amulet. */
1966 if (mal
< A_NEUTRAL
&& u
.uhave
.amulet
)
1969 /* minions are hostile to players that have strayed at all */
1971 return (boolean
) (u
.ualign
.record
>= 0);
1973 /* Last case: a chance of a co-aligned monster being
1974 * hostile. This chance is greater if the player has strayed
1975 * (u.ualign.record negative) or the monster is not strongly aligned.
1977 return (boolean
) (!!rn2(16 + (u
.ualign
.record
< -15 ? -15
1979 && !!rn2(2 + abs(mal
)));
1982 /* Set malign to have the proper effect on player alignment if monster is
1983 * killed. Negative numbers mean it's bad to kill this monster; positive
1984 * numbers mean it's good. Since there are more hostile monsters than
1985 * peaceful monsters, the penalty for killing a peaceful monster should be
1986 * greater than the bonus for killing a hostile monster to maintain balance.
1988 * it's bad to kill peaceful monsters, potentially worse to kill always-
1989 * peaceful monsters;
1990 * it's never bad to kill a hostile monster, although it may not be good.
1996 schar mal
= mtmp
->data
->maligntyp
;
1999 if (mtmp
->ispriest
|| mtmp
->isminion
) {
2000 /* some monsters have individual alignments; check them */
2001 if (mtmp
->ispriest
&& EPRI(mtmp
))
2002 mal
= EPRI(mtmp
)->shralign
;
2003 else if (mtmp
->isminion
&& EMIN(mtmp
))
2004 mal
= EMIN(mtmp
)->min_align
;
2005 /* unless alignment is none, set mal to -5,0,5 */
2006 /* (see align.h for valid aligntyp values) */
2011 coaligned
= (sgn(mal
) == sgn(u
.ualign
.type
));
2012 if (mtmp
->data
->msound
== MS_LEADER
) {
2014 } else if (mal
== A_NONE
) {
2015 if (mtmp
->mpeaceful
)
2018 mtmp
->malign
= 20; /* really hostile */
2019 } else if (always_peaceful(mtmp
->data
)) {
2020 int absmal
= abs(mal
);
2021 if (mtmp
->mpeaceful
)
2022 mtmp
->malign
= -3 * max(5, absmal
);
2024 mtmp
->malign
= 3 * max(5, absmal
); /* renegade */
2025 } else if (always_hostile(mtmp
->data
)) {
2026 int absmal
= abs(mal
);
2030 mtmp
->malign
= max(5, absmal
);
2031 } else if (coaligned
) {
2032 int absmal
= abs(mal
);
2033 if (mtmp
->mpeaceful
)
2034 mtmp
->malign
= -3 * max(3, absmal
);
2036 mtmp
->malign
= max(3, absmal
);
2037 } else /* not coaligned and therefore hostile */
2038 mtmp
->malign
= abs(mal
);
2041 /* allocate a new mcorpsenm field for a monster; only need mextra itself */
2047 mtmp
->mextra
= newmextra();
2048 MCORPSENM(mtmp
) = NON_PM
; /* not initialized yet */
2051 /* release monster's mcorpsenm field; basically a no-op */
2056 if (has_mcorpsenm(mtmp
))
2057 MCORPSENM(mtmp
) = NON_PM
;
2060 static NEARDATA
char syms
[] = {
2061 MAXOCLASSES
, MAXOCLASSES
+ 1, RING_CLASS
, WAND_CLASS
, WEAPON_CLASS
,
2062 FOOD_CLASS
, COIN_CLASS
, SCROLL_CLASS
, POTION_CLASS
, ARMOR_CLASS
,
2063 AMULET_CLASS
, TOOL_CLASS
, ROCK_CLASS
, GEM_CLASS
, SPBOOK_CLASS
,
2064 S_MIMIC_DEF
, S_MIMIC_DEF
,
2069 register struct monst
*mtmp
;
2071 int typ
, roomno
, rt
;
2072 unsigned appear
, ap_type
;
2077 if (!mtmp
|| Protection_from_shape_changers
)
2081 typ
= levl
[mx
][my
].typ
;
2082 /* only valid for INSIDE of room */
2083 roomno
= levl
[mx
][my
].roomno
- ROOMOFFSET
;
2085 rt
= rooms
[roomno
].rtype
;
2086 #ifdef SPECIALIZATION
2087 else if (IS_ROOM(typ
))
2088 rt
= OROOM
, roomno
= 0;
2091 rt
= 0; /* roomno < 0 case for GCC_WARN */
2093 if (OBJ_AT(mx
, my
)) {
2094 ap_type
= M_AP_OBJECT
;
2095 appear
= level
.objects
[mx
][my
]->otyp
;
2096 } else if (IS_DOOR(typ
) || IS_WALL(typ
) || typ
== SDOOR
|| typ
== SCORR
) {
2097 ap_type
= M_AP_FURNITURE
;
2099 * If there is a wall to the left that connects to this
2100 * location, then the mimic mimics a horizontal closed door.
2101 * This does not allow doors to be in corners of rooms.
2102 * Since rogue has no closed doors, mimic a wall there
2103 * (yes, mimics can end up on this level by various means).
2105 if (mx
!= 0 && (levl
[mx
- 1][my
].typ
== HWALL
2106 || levl
[mx
- 1][my
].typ
== TLCORNER
2107 || levl
[mx
- 1][my
].typ
== TRWALL
2108 || levl
[mx
- 1][my
].typ
== BLCORNER
2109 || levl
[mx
- 1][my
].typ
== TDWALL
2110 || levl
[mx
- 1][my
].typ
== CROSSWALL
2111 || levl
[mx
- 1][my
].typ
== TUWALL
))
2112 appear
= Is_rogue_level(&u
.uz
) ? S_hwall
: S_hcdoor
;
2114 appear
= Is_rogue_level(&u
.uz
) ? S_vwall
: S_vcdoor
;
2115 if (!mtmp
->minvis
|| See_invisible
)
2116 block_point(mx
, my
); /* vision */
2117 } else if (level
.flags
.is_maze_lev
&& !In_sokoban(&u
.uz
) && rn2(2)) {
2118 ap_type
= M_AP_OBJECT
;
2120 } else if (roomno
< 0 && !t_at(mx
, my
)) {
2121 ap_type
= M_AP_OBJECT
;
2123 if (!mtmp
->minvis
|| See_invisible
)
2124 block_point(mx
, my
); /* vision */
2125 } else if (rt
== ZOO
|| rt
== VAULT
) {
2126 ap_type
= M_AP_OBJECT
;
2127 appear
= GOLD_PIECE
;
2128 } else if (rt
== DELPHI
) {
2130 ap_type
= M_AP_OBJECT
;
2133 ap_type
= M_AP_FURNITURE
;
2134 appear
= S_fountain
;
2136 } else if (rt
== TEMPLE
) {
2137 ap_type
= M_AP_FURNITURE
;
2140 * We won't bother with beehives, morgues, barracks, throne rooms
2141 * since they shouldn't contain too many mimics anyway...
2143 } else if (rt
>= SHOPBASE
) {
2144 s_sym
= get_shop_item(rt
- SHOPBASE
);
2146 ap_type
= M_AP_OBJECT
;
2149 if (s_sym
== RANDOM_CLASS
)
2150 s_sym
= syms
[rn2((int) sizeof(syms
) - 2) + 2];
2154 s_sym
= syms
[rn2((int) sizeof(syms
))];
2156 if (s_sym
== MAXOCLASSES
|| s_sym
== MAXOCLASSES
+ 1) {
2157 ap_type
= M_AP_FURNITURE
;
2158 appear
= (s_sym
== MAXOCLASSES
) ? S_upstair
: S_dnstair
;
2160 ap_type
= M_AP_OBJECT
;
2161 if (s_sym
== S_MIMIC_DEF
) {
2162 appear
= STRANGE_OBJECT
;
2163 } else if (s_sym
== COIN_CLASS
) {
2164 appear
= GOLD_PIECE
;
2166 otmp
= mkobj((char) s_sym
, FALSE
);
2167 appear
= otmp
->otyp
;
2168 /* make sure container contents are free'ed */
2169 obfree(otmp
, (struct obj
*) 0);
2173 mtmp
->m_ap_type
= ap_type
;
2174 mtmp
->mappearance
= appear
;
2175 if (ap_type
== M_AP_OBJECT
&& (appear
== STATUE
|| appear
== CORPSE
2176 || appear
== FIGURINE
|| appear
== EGG
)) {
2178 MCORPSENM(mtmp
) = rndmonnum();
2179 if (appear
== EGG
&& !can_be_hatched(MCORPSENM(mtmp
)))
2180 MCORPSENM(mtmp
) = NON_PM
; /* revert to generic egg */
2184 /* release monster from bag of tricks; return number of monsters created */
2186 bagotricks(bag
, tipping
, seencount
)
2188 boolean tipping
; /* caller emptying entire contents; affects shop handling */
2189 int *seencount
; /* secondary output */
2193 if (!bag
|| bag
->otyp
!= BAG_OF_TRICKS
) {
2194 impossible("bad bag o' tricks");
2195 } else if (bag
->spe
< 1) {
2196 /* if tipping known empty bag, give normal empty container message */
2197 pline1((tipping
&& bag
->cknown
) ? "It's empty." : nothing_happens
);
2198 /* now known to be empty if sufficiently discovered */
2199 if (bag
->dknown
&& objects
[bag
->otyp
].oc_name_known
)
2203 int creatcnt
= 1, seecount
= 0;
2205 consume_obj_charge(bag
, !tipping
);
2210 mtmp
= makemon((struct permonst
*) 0, u
.ux
, u
.uy
, NO_MM_FLAGS
);
2213 if (canspotmon(mtmp
))
2216 } while (--creatcnt
> 0);
2219 *seencount
+= seecount
;
2221 makeknown(BAG_OF_TRICKS
);
2222 } else if (!tipping
) {
2223 pline1(!moncount
? nothing_happens
: "Nothing seems to happen.");