1 /* NetHack 3.7 makemon.c $NHDT-Date: 1720128166 2024/07/04 21:22:46 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.249 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Robert Patrick Rankin, 2012. */
4 /* NetHack may be freely redistributed. See license for details. */
8 /* this assumes that a human quest leader or nemesis is an archetype
9 of the corresponding role; that isn't so for some roles (tourist
10 for instance) but is for the priests and monks we use it for... */
11 #define quest_mon_represents_role(mptr, role_pm) \
12 (mptr->mlet == S_HUMAN && Role_if(role_pm) \
13 && (mptr->msound == MS_LEADER || mptr->msound == MS_NEMESIS))
15 staticfn boolean
uncommon(int);
16 staticfn
int align_shift(struct permonst
*);
17 staticfn
int temperature_shift(struct permonst
*);
18 staticfn boolean
mk_gen_ok(int, unsigned, unsigned);
19 staticfn boolean
wrong_elem_type(struct permonst
*);
20 staticfn
void m_initgrp(struct monst
*, coordxy
, coordxy
, int, mmflags_nht
);
21 staticfn
void m_initthrow(struct monst
*, int, int);
22 staticfn
void m_initweap(struct monst
*);
23 staticfn
void m_initinv(struct monst
*);
24 staticfn boolean
makemon_rnd_goodpos(struct monst
*, mmflags_nht
, coord
*);
25 staticfn
void init_mextra(struct mextra
*);
27 #define m_initsgrp(mtmp, x, y, mmf) m_initgrp(mtmp, x, y, 3, mmf)
28 #define m_initlgrp(mtmp, x, y, mmf) m_initgrp(mtmp, x, y, 10, mmf)
31 is_home_elemental(struct permonst
*ptr
)
33 if (ptr
->mlet
== S_ELEMENTAL
) {
34 switch (monsndx(ptr
)) {
35 case PM_AIR_ELEMENTAL
:
36 return Is_airlevel(&u
.uz
);
37 case PM_FIRE_ELEMENTAL
:
38 return Is_firelevel(&u
.uz
);
39 case PM_EARTH_ELEMENTAL
:
40 return Is_earthlevel(&u
.uz
);
41 case PM_WATER_ELEMENTAL
:
42 return Is_waterlevel(&u
.uz
);
51 * Return true if the given monster cannot exist on this elemental level.
54 wrong_elem_type(struct permonst
*ptr
)
56 if (ptr
->mlet
== S_ELEMENTAL
) {
57 return (boolean
) !is_home_elemental(ptr
);
58 } else if (Is_earthlevel(&u
.uz
)) {
59 /* no restrictions? */
60 } else if (Is_waterlevel(&u
.uz
)) {
61 /* just monsters that can swim */
64 } else if (Is_firelevel(&u
.uz
)) {
65 if (!pm_resistance(ptr
, MR_FIRE
))
67 } else if (Is_airlevel(&u
.uz
)) {
68 if (!(is_flyer(ptr
) && ptr
->mlet
!= S_TRAPPER
) && !is_floater(ptr
)
69 && !amorphous(ptr
) && !noncorporeal(ptr
) && !is_whirly(ptr
))
75 /* make a group just like mtmp */
79 coordxy x
, coordxy y
, int n
,
85 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
86 /* There is an unresolved problem with several people finding that
87 * the game hangs eating CPU; if interrupted and restored, the level
88 * will be filled with monsters. Of those reports giving system type,
89 * there were two DG/UX and two HP-UX, all using gcc as the compiler.
90 * hcroft@hpopb1.cern.ch, using gcc 2.6.3 on HP-UX, says that the
91 * problem went away for him and another reporter-to-newsgroup
92 * after adding this debugging code. This has almost got to be a
93 * compiler bug, but until somebody tracks it down and gets it fixed,
94 * might as well go with the "but it went away when I tried to find
100 debugpline4("init group call <%d,%d>, n=%d, cnt=%d.", x
, y
, n
, cnt
);
101 cntdiv
= ((u
.ulevel
< 3) ? 4 : (u
.ulevel
< 5) ? 2 : 1);
103 /* Tuning: cut down on swarming at low character levels [mrs] */
104 cnt
/= (u
.ulevel
< 3) ? 4 : (u
.ulevel
< 5) ? 2 : 1;
105 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
106 if (cnt
!= (cnttmp
/ cntdiv
)) {
107 pline("cnt=%d using %d, cnttmp=%d, cntdiv=%d", cnt
,
108 (u
.ulevel
< 3) ? 4 : (u
.ulevel
< 5) ? 2 : 1, cnttmp
, cntdiv
);
113 #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
123 if (peace_minded(mtmp
->data
))
125 /* Don't create groups of peaceful monsters since they'll get
126 * in our way. If the monster has a percentage chance so some
127 * are peaceful and some are not, the result will just be a
130 if (enexto_gpflags(&mm
, mm
.x
, mm
.y
, mtmp
->data
, mmflags
)) {
131 mon
= makemon(mtmp
->data
, mm
.x
, mm
.y
, (mmflags
| MM_NOGRP
));
133 mon
->mpeaceful
= FALSE
;
136 /* Undo the second peace_minded() check in makemon(); if the
137 * monster turned out to be peaceful the first time we
138 * didn't create it at all; we don't want a second check.
146 m_initthrow(struct monst
*mtmp
, int otyp
, int oquan
)
150 otmp
= mksobj(otyp
, TRUE
, FALSE
);
151 otmp
->quan
= (long) rn1(oquan
, 3);
152 otmp
->owt
= weight(otmp
);
153 if (otyp
== ORCISH_ARROW
)
154 otmp
->opoisoned
= TRUE
;
155 (void) mpickobj(mtmp
, otmp
);
159 m_initweap(struct monst
*mtmp
)
161 struct permonst
*ptr
= mtmp
->data
;
162 int mm
= monsndx(ptr
);
166 if (Is_rogue_level(&u
.uz
))
169 * First a few special cases:
170 * giants get a boulder to throw sometimes
172 * kobolds get darts to throw
173 * centaurs get some sort of bow & arrows or bolts
174 * soldiers get all sorts of things
175 * kops get clubs & cream pies.
180 (void) mongets(mtmp
, (mm
!= PM_ETTIN
) ? BOULDER
: CLUB
);
181 if ((mm
!= PM_ETTIN
) && !rn2(5))
182 (void) mongets(mtmp
, rn2(2) ? TWO_HANDED_SWORD
: BATTLE_AXE
);
185 if (is_mercenary(ptr
)) {
191 /* lance and dwarvish mattock used to be in midst of
192 the polearms but use different skills from polearms
193 and aren't appropriates choices for human soldiers */
195 w1
= rn1(BEC_DE_CORBIN
- PARTISAN
+ 1, PARTISAN
);
196 } while (objects
[w1
].oc_skill
!= P_POLEARMS
);
197 w2
= rn2(2) ? DAGGER
: KNIFE
;
199 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
;
219 (void) mongets(mtmp
, w1
);
220 if (!w2
&& w1
!= DAGGER
&& !rn2(4))
223 (void) mongets(mtmp
, w2
);
224 } else if (is_elf(ptr
)) {
227 rn2(2) ? ELVEN_MITHRIL_COAT
: ELVEN_CLOAK
);
229 (void) mongets(mtmp
, ELVEN_LEATHER_HELM
);
231 (void) mongets(mtmp
, ELVEN_BOOTS
);
233 (void) mongets(mtmp
, ELVEN_DAGGER
);
237 (void) mongets(mtmp
, ELVEN_SHIELD
);
239 (void) mongets(mtmp
, ELVEN_SHORT_SWORD
);
240 (void) mongets(mtmp
, ELVEN_BOW
);
241 m_initthrow(mtmp
, ELVEN_ARROW
, 12);
244 (void) mongets(mtmp
, ELVEN_BROADSWORD
);
246 (void) mongets(mtmp
, ELVEN_SHIELD
);
250 (void) mongets(mtmp
, ELVEN_SPEAR
);
251 (void) mongets(mtmp
, ELVEN_SHIELD
);
255 if (mm
== PM_ELVEN_MONARCH
) {
256 if (rn2(3) || (gi
.in_mklev
&& Is_earthlevel(&u
.uz
)))
257 (void) mongets(mtmp
, PICK_AXE
);
259 (void) mongets(mtmp
, CRYSTAL_BALL
);
261 } else if (ptr
->msound
== MS_PRIEST
262 || quest_mon_represents_role(ptr
, PM_CLERIC
)) {
263 otmp
= mksobj(MACE
, FALSE
, FALSE
);
267 (void) mpickobj(mtmp
, otmp
);
268 } else if (mm
== PM_NINJA
) { /* extra quest villains */
269 (void) mongets(mtmp
, rn2(4) ? SHURIKEN
: DART
);
270 (void) mongets(mtmp
, rn2(4) ? SHORT_SWORD
: AXE
);
271 } else if (ptr
->msound
== MS_GUARDIAN
) {
272 /* quest "guardians" */
281 (void) mongets(mtmp
, rn2(3) ? DAGGER
: KNIFE
);
283 (void) mongets(mtmp
, rn2(3) ? LEATHER_JACKET
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
310 (void) mongets(mtmp
, BOW
);
311 m_initthrow(mtmp
, ARROW
, 12);
314 (void) mongets(mtmp
, CLUB
);
315 (void) mongets(mtmp
, rn2(3) ? DAGGER
: KNIFE
);
317 (void) mongets(mtmp
, LEATHER_GLOVES
);
318 (void) mongets(mtmp
, rn2(2) ? LEATHER_JACKET
: LEATHER_ARMOR
);
321 (void) mongets(mtmp
, CLUB
);
322 (void) mongets(mtmp
, LEATHER_ARMOR
);
330 /* create minion stuff; bypass mongets */
331 int typ
= rn2(3) ? LONG_SWORD
: MACE
;
332 const char *nam
= (typ
== LONG_SWORD
) ? "Sunsword" : "Demonbane";
334 otmp
= mksobj(typ
, FALSE
, FALSE
);
335 /* maybe promote weapon to an artifact */
336 if ((!rn2(20) || is_lord(ptr
))
337 && sgn(mtmp
->isminion
? EMIN(mtmp
)->min_align
338 : ptr
->maligntyp
) == A_LAWFUL
)
339 otmp
= oname(otmp
, nam
, ONAME_RANDOM
); /* randomly created */
340 /* enhance the weapon */
342 otmp
->oerodeproof
= TRUE
;
343 /* make long sword be +0 to +3, mace be +3 to +6 to compensate
344 for being significantly weaker against large opponents */
348 (void) mpickobj(mtmp
, otmp
);
350 otmp
= mksobj(!rn2(4) || is_lord(ptr
) ? SHIELD_OF_REFLECTION
353 /* uncurse(otmp); -- mksobj(,FALSE,) item is always uncursed */
354 otmp
->oerodeproof
= TRUE
;
356 (void) mpickobj(mtmp
, otmp
);
361 if (mm
== PM_HOBBIT
) {
364 (void) mongets(mtmp
, DAGGER
);
367 (void) mongets(mtmp
, ELVEN_DAGGER
);
370 (void) mongets(mtmp
, SLING
);
371 m_initthrow(mtmp
, !rn2(4) ? FLINT
: ROCK
, 6);
375 (void) mongets(mtmp
, ELVEN_MITHRIL_COAT
);
377 (void) mongets(mtmp
, DWARVISH_CLOAK
);
378 } else if (is_dwarf(ptr
)) {
380 (void) mongets(mtmp
, DWARVISH_CLOAK
);
382 (void) mongets(mtmp
, IRON_SHOES
);
384 (void) mongets(mtmp
, DWARVISH_SHORT_SWORD
);
385 /* note: you can't use a mattock with a shield */
387 (void) mongets(mtmp
, DWARVISH_MATTOCK
);
389 (void) mongets(mtmp
, rn2(2) ? AXE
: DWARVISH_SPEAR
);
390 (void) mongets(mtmp
, DWARVISH_ROUNDSHIELD
);
392 (void) mongets(mtmp
, DWARVISH_IRON_HELM
);
394 (void) mongets(mtmp
, DWARVISH_MITHRIL_COAT
);
396 (void) mongets(mtmp
, !rn2(3) ? PICK_AXE
: DAGGER
);
401 /* create Keystone Kops with cream pies to
402 throw. As suggested by KAA. [MRS] */
404 m_initthrow(mtmp
, CREAM_PIE
, 2);
406 (void) mongets(mtmp
, (rn2(2)) ? CLUB
: RUBBER_HOSE
);
410 (void) mongets(mtmp
, ORCISH_HELM
);
411 switch ((mm
!= PM_ORC_CAPTAIN
) ? mm
412 : rn2(2) ? PM_MORDOR_ORC
: PM_URUK_HAI
) {
415 (void) mongets(mtmp
, SCIMITAR
);
417 (void) mongets(mtmp
, ORCISH_SHIELD
);
419 (void) mongets(mtmp
, KNIFE
);
421 (void) mongets(mtmp
, ORCISH_CHAIN_MAIL
);
425 (void) mongets(mtmp
, ORCISH_CLOAK
);
427 (void) mongets(mtmp
, ORCISH_SHORT_SWORD
);
429 (void) mongets(mtmp
, IRON_SHOES
);
431 (void) mongets(mtmp
, ORCISH_BOW
);
432 m_initthrow(mtmp
, ORCISH_ARROW
, 12);
435 (void) mongets(mtmp
, URUK_HAI_SHIELD
);
438 if (mm
!= PM_ORC_SHAMAN
&& rn2(2))
439 (void) mongets(mtmp
, (mm
== PM_GOBLIN
|| rn2(2) == 0)
445 if (!rn2(mm
== PM_OGRE_TYRANT
? 3 : mm
== PM_OGRE_LEADER
? 6 : 12))
446 (void) mongets(mtmp
, BATTLE_AXE
);
448 (void) mongets(mtmp
, CLUB
);
454 (void) mongets(mtmp
, RANSEUR
);
457 (void) mongets(mtmp
, PARTISAN
);
460 (void) mongets(mtmp
, GLAIVE
);
463 (void) mongets(mtmp
, SPETUM
);
469 m_initthrow(mtmp
, DART
, 12);
474 if (ptr
== &mons
[PM_FOREST_CENTAUR
]) {
475 (void) mongets(mtmp
, BOW
);
476 m_initthrow(mtmp
, ARROW
, 12);
478 (void) mongets(mtmp
, CROSSBOW
);
479 m_initthrow(mtmp
, CROSSBOW_BOLT
, 12);
484 (void) mongets(mtmp
, KNIFE
);
485 (void) mongets(mtmp
, LONG_SWORD
);
489 (void) mongets(mtmp
, LEATHER_ARMOR
);
491 (void) mongets(mtmp
, (rn2(3) ? KNIFE
: SHORT_SWORD
));
494 if (mm
== PM_SALAMANDER
)
496 (rn2(7) ? SPEAR
: rn2(3) ? TRIDENT
: STILETTO
));
501 (void) mongets(mtmp
, BULLWHIP
);
502 (void) mongets(mtmp
, BROADSWORD
);
505 (void) mongets(mtmp
, WAN_DEATH
); /* the Wand of Orcus */
507 case PM_HORNED_DEVIL
:
508 (void) mongets(mtmp
, rn2(4) ? TRIDENT
: BULLWHIP
);
511 (void) mongets(mtmp
, WAN_STRIKING
);
514 (void) mongets(mtmp
, FLAIL
);
517 /* prevent djinn and mail daemons from leaving objects when
526 * Now the general case, some chance of getting some type
527 * of weapon for "normal" monsters. Certain special types
528 * of monsters will get a bonus chance or different selections.
530 bias
= is_lord(ptr
) + is_prince(ptr
) * 2 + extra_nasty(ptr
);
531 switch (rnd(14 - (2 * bias
))) {
533 if (strongmonst(ptr
))
534 (void) mongets(mtmp
, BATTLE_AXE
);
536 m_initthrow(mtmp
, DART
, 12);
539 if (strongmonst(ptr
))
540 (void) mongets(mtmp
, TWO_HANDED_SWORD
);
542 (void) mongets(mtmp
, CROSSBOW
);
543 m_initthrow(mtmp
, CROSSBOW_BOLT
, 12);
547 (void) mongets(mtmp
, BOW
);
548 m_initthrow(mtmp
, ARROW
, 12);
551 if (strongmonst(ptr
))
552 (void) mongets(mtmp
, LONG_SWORD
);
554 m_initthrow(mtmp
, DAGGER
, 3);
557 if (strongmonst(ptr
))
558 (void) mongets(mtmp
, LUCERN_HAMMER
);
560 (void) mongets(mtmp
, AKLYS
);
568 if ((int) mtmp
->m_lev
> rn2(75))
569 (void) mongets(mtmp
, rnd_offensive_item(mtmp
));
572 /* create a new stack of gold in monster's inventory */
574 mkmonmoney(struct monst
*mtmp
, long amount
)
576 /* mk_mplayer() passes rn2(1000) so the amount might be 0 */
578 struct obj
*gold
= mksobj(GOLD_PIECE
, FALSE
, FALSE
);
581 gold
->owt
= weight(gold
);
582 add_to_minv(mtmp
, gold
);
587 m_initinv(struct monst
*mtmp
)
591 struct permonst
*ptr
= mtmp
->data
;
593 if (Is_rogue_level(&u
.uz
))
596 * Soldiers get armour & rations - armour approximates their ac.
597 * Nymphs may get mirror or potion of object detection.
601 if (is_mercenary(ptr
)) {
604 switch (monsndx(ptr
)) {
623 case PM_WATCH_CAPTAIN
:
627 impossible("odd mercenary %d?", monsndx(ptr
));
632 #define add_ac(otmp) \
633 if (otmp) { mac += ARM_BONUS(otmp); } \
634 otmp = (struct obj *) 0;
636 /* round 1: give them body armor */
637 if (mac
< -1 && rn2(5))
638 otmp
= mongets(mtmp
, (rn2(5)) ? PLATE_MAIL
639 : CRYSTAL_PLATE_MAIL
);
640 else if (mac
< 3 && rn2(5))
641 otmp
= mongets(mtmp
, (rn2(3)) ? SPLINT_MAIL
: BANDED_MAIL
);
643 otmp
= mongets(mtmp
, (rn2(3)) ? RING_MAIL
644 : STUDDED_LEATHER_ARMOR
);
646 otmp
= mongets(mtmp
, LEATHER_ARMOR
);
649 /* round 2: helmets */
650 if (mac
< 10 && rn2(3))
651 otmp
= mongets(mtmp
, HELMET
);
652 else if (mac
< 10 && rn2(2))
653 otmp
= mongets(mtmp
, DENTED_POT
);
656 /* round 3: shields */
657 if (mac
< 10 && rn2(3))
658 otmp
= mongets(mtmp
, SMALL_SHIELD
);
659 else if (mac
< 10 && rn2(2))
660 otmp
= mongets(mtmp
, LARGE_SHIELD
);
664 if (mac
< 10 && rn2(3))
665 otmp
= mongets(mtmp
, LOW_BOOTS
);
666 else if (mac
< 10 && rn2(2))
667 otmp
= mongets(mtmp
, HIGH_BOOTS
);
670 /* round 5: gloves + cloak */
671 if (mac
< 10 && rn2(3))
672 otmp
= mongets(mtmp
, LEATHER_GLOVES
);
673 else if (mac
< 10 && rn2(2))
674 otmp
= mongets(mtmp
, LEATHER_CLOAK
);
675 add_ac(otmp
); /* not technically needed */
678 nhUse(mac
); /* suppress 'dead increment' from static analyzer */
680 if (ptr
== &mons
[PM_WATCH_CAPTAIN
]) {
681 ; /* better weapon rather than extra gear here */
682 } else if (ptr
== &mons
[PM_WATCHMAN
]) {
683 if (rn2(3)) /* most watchmen carry a whistle */
684 (void) mongets(mtmp
, TIN_WHISTLE
);
685 } else if (ptr
== &mons
[PM_GUARD
]) {
686 /* if hero teleports out of a vault while being confronted
687 by the vault's guard, there is a shrill whistling sound,
688 so guard evidently carries a cursed whistle */
689 otmp
= mksobj(TIN_WHISTLE
, TRUE
, FALSE
);
691 (void) mpickobj(mtmp
, otmp
);
692 } else { /* soldiers and their officers */
694 (void) mongets(mtmp
, K_RATION
);
696 (void) mongets(mtmp
, C_RATION
);
697 if (ptr
!= &mons
[PM_SOLDIER
] && !rn2(3))
698 (void) mongets(mtmp
, BUGLE
);
700 } else if (ptr
== &mons
[PM_SHOPKEEPER
]) {
701 (void) mongets(mtmp
, SKELETON_KEY
);
703 /* MAJOR fall through ... */
705 (void) mongets(mtmp
, WAN_MAGIC_MISSILE
);
709 (void) mongets(mtmp
, POT_EXTRA_HEALING
);
713 (void) mongets(mtmp
, POT_HEALING
);
717 (void) mongets(mtmp
, WAN_STRIKING
);
719 } else if (ptr
->msound
== MS_PRIEST
720 || quest_mon_represents_role(ptr
, PM_CLERIC
)) {
721 (void) mongets(mtmp
, rn2(7) ? ROBE
722 : rn2(3) ? CLOAK_OF_PROTECTION
723 : CLOAK_OF_MAGIC_RESISTANCE
);
724 (void) mongets(mtmp
, SMALL_SHIELD
);
725 mkmonmoney(mtmp
, (long) rn1(10, 20));
726 } else if (quest_mon_represents_role(ptr
, PM_MONK
)) {
727 (void) mongets(mtmp
, rn2(11) ? ROBE
: CLOAK_OF_MAGIC_RESISTANCE
);
732 (void) mongets(mtmp
, MIRROR
);
734 (void) mongets(mtmp
, POT_OBJECT_DETECTION
);
737 if (ptr
== &mons
[PM_MINOTAUR
]) {
738 if (!rn2(3) || (gi
.in_mklev
&& Is_earthlevel(&u
.uz
)))
739 (void) mongets(mtmp
, WAN_DIGGING
);
740 } else if (is_giant(ptr
)) {
741 for (cnt
= rn2((int) (mtmp
->m_lev
/ 2)); cnt
; cnt
--) {
742 otmp
= mksobj(rnd_class(DILITHIUM_CRYSTAL
, LUCKSTONE
- 1),
744 otmp
->quan
= (long) rn1(2, 3);
745 otmp
->owt
= weight(otmp
);
746 (void) mpickobj(mtmp
, otmp
);
751 if (ptr
== &mons
[PM_NAZGUL
]) {
752 otmp
= mksobj(RIN_INVISIBILITY
, FALSE
, FALSE
);
754 (void) mpickobj(mtmp
, otmp
);
758 if (ptr
== &mons
[PM_MASTER_LICH
] && !rn2(13))
759 (void) mongets(mtmp
, (rn2(7) ? ATHAME
: WAN_NOTHING
));
760 else if (ptr
== &mons
[PM_ARCH_LICH
] && !rn2(3)) {
761 otmp
= mksobj(rn2(3) ? ATHAME
: QUARTERSTAFF
, TRUE
,
762 rn2(13) ? FALSE
: TRUE
);
766 otmp
->oerodeproof
= 1;
767 (void) mpickobj(mtmp
, otmp
);
772 (void) mongets(mtmp
, MUMMY_WRAPPING
);
775 if (!rn2(20) && ptr
== &mons
[PM_QUANTUM_MECHANIC
]) {
776 struct obj
*catcorpse
;
778 otmp
= mksobj(LARGE_BOX
, FALSE
, FALSE
);
779 /* we used to just set the flag, which resulted in weight()
780 treating the box as being heavier by the weight of a cat;
781 now we include a cat corpse that won't rot; when opening or
782 disclosing the box's contents, the corpse might be revived,
783 otherwise it's given a rot timer; weight is now ordinary */
784 if ((catcorpse
= mksobj(CORPSE
, TRUE
, FALSE
)) != 0) {
785 otmp
->spe
= 1; /* flag for special SchroedingersBox */
786 set_corpsenm(catcorpse
, PM_HOUSECAT
);
787 (void) stop_timer(ROT_CORPSE
, obj_to_any(catcorpse
));
788 add_to_container(otmp
, catcorpse
);
789 otmp
->owt
= weight(otmp
);
791 (void) mpickobj(mtmp
, otmp
);
795 mkmonmoney(mtmp
, (long) d(level_difficulty(), 30));
798 /* moved here from m_initweap() because these don't
799 have AT_WEAP so m_initweap() is not called for them */
800 if (ptr
== &mons
[PM_ICE_DEVIL
] && !rn2(4)) {
801 (void) mongets(mtmp
, SPEAR
);
802 } else if (ptr
== &mons
[PM_ASMODEUS
]) {
803 (void) mongets(mtmp
, WAN_COLD
);
804 (void) mongets(mtmp
, WAN_FIRE
);
808 if (!rn2((In_mines(&u
.uz
) && gi
.in_mklev
) ? 20 : 60)) {
809 otmp
= mksobj(rn2(4) ? TALLOW_CANDLE
: WAX_CANDLE
, TRUE
, FALSE
);
811 otmp
->owt
= weight(otmp
);
812 if (!mpickobj(mtmp
, otmp
) && !levl
[mtmp
->mx
][mtmp
->my
].lit
)
813 begin_burn(otmp
, FALSE
);
820 /* ordinary soldiers rarely have access to magic (or gold :-) */
821 if (ptr
== &mons
[PM_SOLDIER
] && rn2(13))
824 if ((int) mtmp
->m_lev
> rn2(50))
825 (void) mongets(mtmp
, rnd_defensive_item(mtmp
));
826 if ((int) mtmp
->m_lev
> rn2(100))
827 (void) mongets(mtmp
, rnd_misc_item(mtmp
));
828 if (likes_gold(ptr
) && !findgold(mtmp
->minvent
) && !rn2(5))
830 (long) d(level_difficulty(), mtmp
->minvent
? 5 : 10));
833 /* Note: for long worms, always call cutworm (cutworm calls clone_mon) */
837 coordxy x
, coordxy y
) /* clone's preferred location or 0 (near mon) */
842 /* may be too weak or have been extinguished for population control */
844 || (svm
.mvitals
[monsndx(mon
->data
)].mvflags
& G_EXTINCT
) != 0)
845 return (struct monst
*) 0;
854 if (!isok(mm
.x
, mm
.y
)) { /* paranoia */
855 impossible("clone_mon trying to create a monster at <%d,%d>?",
857 return (struct monst
*) 0;
859 if (MON_AT(mm
.x
, mm
.y
)) { /* (always True for the x==0 case) */
860 if (!enexto(&mm
, mm
.x
, mm
.y
, mon
->data
) || MON_AT(mm
.x
, mm
.y
))
861 return (struct monst
*) 0;
865 *m2
= *mon
; /* copy condition of old monster */
866 m2
->mextra
= (struct mextra
*) 0;
869 m2
->m_id
= next_ident();
876 m2
->minvent
= (struct obj
*) 0; /* objects don't clone */
878 /* Max HP the same, but current HP halved for both. The caller
879 * might want to override this by halving the max HP also.
880 * When current HP is odd, the original keeps the extra point.
881 * We know original has more than 1 HP, so both end up with at least 1.
883 m2
->mhpmax
= mon
->mhpmax
;
884 m2
->mhp
= mon
->mhp
/ 2;
887 /* clone doesn't have mextra so mustn't retain special monster flags */
891 /* ms->isminion handled below */
893 /* clone shouldn't be reluctant to move on spots 'parent' just moved on */
896 place_monster(m2
, m2
->mx
, m2
->my
);
897 if (emits_light(m2
->data
))
898 new_light_source(m2
->mx
, m2
->my
, emits_light(m2
->data
), LS_MONSTER
,
900 /* if 'parent' is named, give the clone the same name */
901 if (has_mgivenname(mon
)) {
902 m2
= christen_monst(m2
, MGIVENNAME(mon
));
903 } else if (mon
->isshk
) {
904 m2
= christen_monst(m2
, shkname(mon
));
907 /* not all clones caused by player are tame or peaceful */
908 if (!svc
.context
.mon_moving
&& mon
->mpeaceful
) {
910 m2
->mtame
= rn2(max(2 + u
.uluck
, 2)) ? mon
->mtame
: 0;
911 else if (mon
->mpeaceful
)
912 m2
->mpeaceful
= rn2(max(2 + u
.uluck
, 2)) ? 1 : 0;
914 /* if guardian angel could be cloned (maybe after polymorph?),
915 m2 could be both isminion and mtame; isminion takes precedence */
920 assert(has_emin(m2
) && has_emin(mon
));
921 *EMIN(m2
) = *EMIN(mon
);
922 /* renegade when same alignment as hero but not peaceful or
923 when peaceful while being different alignment from hero */
924 atyp
= EMIN(m2
)->min_align
;
925 EMIN(m2
)->renegade
= (atyp
!= u
.ualign
.type
) ^ !m2
->mpeaceful
;
926 } else if (m2
->mtame
) {
927 /* Because m2 is a copy of mon it is tame but not init'ed.
928 However, tamedog() will not re-tame a tame dog, so m2
929 must be made non-tame to get initialized properly. */
931 if (tamedog(m2
, (struct obj
*) 0, FALSE
)) {
932 assert(has_edog(m2
) && has_edog(mon
));
933 *EDOG(m2
) = *EDOG(mon
);
935 /* [TODO? some (most? all?) edog fields probably should be
936 reinitialized rather that retain the 'parent's values] */
939 newsym(m2
->mx
, m2
->my
); /* display the new monster */
945 * Propagate a species
947 * Once a certain number of monsters are created, don't create any more
948 * at random (i.e. make them extinct). The previous (3.2) behavior was
949 * to do this when a certain number had _died_, which didn't make
952 * Returns FALSE propagation unsuccessful
953 * TRUE propagation successful
956 propagate(int mndx
, boolean tally
, boolean ghostly
)
958 boolean gone
, result
;
959 int lim
= mbirth_limit(mndx
);
961 gone
= (svm
.mvitals
[mndx
].mvflags
& G_GONE
) != 0; /* geno'd|extinct */
962 result
= ((int) svm
.mvitals
[mndx
].born
< lim
&& !gone
) ? TRUE
: FALSE
;
964 /* if it's unique, don't ever make it again */
965 if ((mons
[mndx
].geno
& G_UNIQ
) != 0 && mndx
!= PM_HIGH_CLERIC
)
966 svm
.mvitals
[mndx
].mvflags
|= G_EXTINCT
;
968 if (svm
.mvitals
[mndx
].born
< 255 && tally
&& (!ghostly
|| result
))
969 svm
.mvitals
[mndx
].born
++;
970 if ((int) svm
.mvitals
[mndx
].born
>= lim
971 && !(mons
[mndx
].geno
& G_NOGEN
)
972 && !(svm
.mvitals
[mndx
].mvflags
& G_EXTINCT
)) {
974 debugpline1("Automatically extinguished %s.",
975 makeplural(mons
[mndx
].pmnames
[NEUTRAL
]));
977 svm
.mvitals
[mndx
].mvflags
|= G_EXTINCT
;
982 /* amount of HP to lose from level drain (or gain from Stormbringer) */
984 monhp_per_lvl(struct monst
*mon
)
986 struct permonst
*ptr
= mon
->data
;
987 int hp
= rnd(8); /* default is d8 */
989 /* like newmonhp, but home elementals are ignored, riders use normal d8 */
991 /* draining usually won't be applicable for these critters */
992 hp
= golemhp(monsndx(ptr
)) / (int) ptr
->mlevel
;
993 } else if (ptr
->mlevel
> 49) {
994 /* arbitrary; such monsters won't be involved in draining anyway */
995 hp
= 4 + rnd(4); /* 5..8 */
996 } else if (ptr
->mlet
== S_DRAGON
&& monsndx(ptr
) >= PM_GRAY_DRAGON
) {
997 /* adult dragons; newmonhp() uses In_endgame(&u.uz) ? 8 : 4 + rnd(4)
999 hp
= 4 + rn2(5); /* 4..8 */
1000 } else if (!mon
->m_lev
) {
1001 /* level 0 monsters use 1d4 instead of Nd8 */
1007 /* set up a new monster's initial level and hit points;
1008 used by newcham() as well as by makemon() */
1010 newmonhp(struct monst
*mon
, int mndx
)
1012 struct permonst
*ptr
= &mons
[mndx
];
1015 mon
->m_lev
= adj_lev(ptr
);
1016 if (is_golem(ptr
)) {
1017 /* golems have a fixed amount of HP, varying by golem type */
1018 mon
->mhpmax
= mon
->mhp
= golemhp(mndx
);
1019 } else if (is_rider(ptr
)) {
1020 /* we want low HP, but a high mlevel so they can attack well */
1021 basehp
= 10; /* minimum is 1 per false (weaker) level */
1022 mon
->mhpmax
= mon
->mhp
= d(basehp
, 8);
1023 } else if (ptr
->mlevel
> 49) {
1024 /* "special" fixed hp monster
1025 * the hit points are encoded in the mlevel in a somewhat strange
1026 * way to fit in the 50..127 positive range of a signed character
1027 * above the 1..49 that indicate "normal" monster levels */
1028 mon
->mhpmax
= mon
->mhp
= 2 * (ptr
->mlevel
- 6);
1029 mon
->m_lev
= mon
->mhp
/ 4; /* approximation */
1030 } else if (ptr
->mlet
== S_DRAGON
&& mndx
>= PM_GRAY_DRAGON
) {
1031 /* adult dragons; N*(4+rnd(4)) before endgame, N*8 once there */
1032 basehp
= (int) mon
->m_lev
; /* not really applicable; isolates cast */
1033 mon
->mhpmax
= mon
->mhp
= In_endgame(&u
.uz
) ? (8 * basehp
)
1034 : (4 * basehp
+ d(basehp
, 4));
1035 } else if (!mon
->m_lev
) {
1036 basehp
= 1; /* minimum is 1, increased to 2 below */
1037 mon
->mhpmax
= mon
->mhp
= rnd(4);
1039 basehp
= (int) mon
->m_lev
; /* minimum possible is one per level */
1040 mon
->mhpmax
= mon
->mhp
= d(basehp
, 8);
1041 if (is_home_elemental(ptr
))
1042 mon
->mhpmax
= (mon
->mhp
*= 3); /* leave 'basehp' as-is */
1045 /* if d(X,8) rolled a 1 all X times, give a boost;
1046 most beneficial for level 0 and level 1 monsters, making mhpmax
1047 and starting mhp always be at least 2 */
1048 if (mon
->mhpmax
== basehp
) {
1050 mon
->mhp
= mon
->mhpmax
;
1054 static const struct mextra zeromextra
= DUMMY
;
1057 init_mextra(struct mextra
*mex
)
1060 mex
->mcorpsenm
= NON_PM
;
1066 struct mextra
*mextra
;
1068 mextra
= (struct mextra
*) alloc(sizeof (struct mextra
));
1069 init_mextra(mextra
);
1074 makemon_rnd_goodpos(
1076 mmflags_nht gpflags
,
1077 coord
*cc
) /* output */
1083 gpflags
|= GP_AVOID_MONPOS
;
1085 nx
= rn1(COLNO
- 3, 2);
1087 good
= (!gi
.in_mklev
&& cansee(nx
,ny
)) ? FALSE
1088 : goodpos(nx
, ny
, mon
, gpflags
);
1089 } while ((++tryct
< 50) && !good
);
1092 /* else go through all map positions, twice, first round
1093 ignoring positions in sight, and pick first good one.
1094 skip first round if we're in special level loader or blind */
1098 int bl
= (gi
.in_mklev
|| Blind
) ? 1 : 0;
1100 for ( ; bl
< 2; bl
++) {
1102 gpflags
&= ~GP_CHECKSCARY
; /* perhaps should be a 3rd pass */
1103 for (dx
= 0; dx
< COLNO
; dx
++)
1104 for (dy
= 0; dy
< ROWNO
; dy
++) {
1105 nx
= ((dx
+ xofs
) % (COLNO
- 1)) + 1;
1106 ny
= ((dy
+ yofs
) % (ROWNO
- 1)) + 1;
1107 if (bl
== 0 && cansee(nx
,ny
))
1109 if (goodpos(nx
, ny
, mon
, gpflags
))
1112 if (bl
== 0 && (!mon
|| mon
->data
->mmove
)) {
1113 stairway
*stway
= gs
.stairs
;
1114 /* all map positions are visible (or not good),
1115 try to pick something logical */
1117 if (stway
->tolev
.dnum
== u
.uz
.dnum
&& !rn2(2)) {
1122 stway
= stway
->next
;
1124 if (goodpos(nx
, ny
, mon
, gpflags
))
1138 * called with [x,y] = coordinates;
1139 * [0,0] means anyplace
1140 * [u.ux,u.uy] means: near player (if !gi.in_mklev)
1142 * In case we make a monster group, only return the one at [x,y].
1146 struct permonst
*ptr
,
1147 coordxy x
, coordxy y
,
1148 mmflags_nht mmflags
)
1151 struct monst fakemon
;
1153 int mndx
, mcham
, ct
, mitem
;
1154 boolean femaleok
, maleok
,
1157 allow_minvent
= ((mmflags
& NO_MINVENT
) == 0),
1158 countbirth
= ((mmflags
& MM_NOCOUNTBIRTH
) == 0),
1159 allowtail
= ((mmflags
& MM_NOTAIL
) == 0);
1160 mmflags_nht gpflags
= (((mmflags
& MM_IGNOREWATER
) ? MM_IGNOREWATER
: 0)
1161 | GP_CHECKSCARY
| GP_AVOID_MONPOS
);
1163 fakemon
= cg
.zeromonst
;
1166 if (iflags
.debug_mongen
|| (!svl
.level
.flags
.rndmongen
&& !ptr
))
1167 return (struct monst
*) 0;
1169 /* if caller wants random location, do it here */
1170 if (x
== 0 && y
== 0) {
1171 fakemon
.data
= ptr
; /* set up for goodpos */
1172 if (!makemon_rnd_goodpos(ptr
? &fakemon
: (struct monst
*) 0,
1174 return (struct monst
*) 0;
1177 } else if (byyou
&& !gi
.in_mklev
) {
1178 if (!enexto_core(&cc
, u
.ux
, u
.uy
, ptr
, gpflags
)
1179 && !enexto_core(&cc
, u
.ux
, u
.uy
, ptr
, gpflags
& ~GP_CHECKSCARY
))
1180 return (struct monst
*) 0;
1187 impossible("makemon trying to create a monster at <%d,%d>?", x
, y
);
1188 return (struct monst
*) 0;
1191 /* Does monster already exist at the position? */
1193 if (!(mmflags
& MM_ADJACENTOK
)
1194 || !enexto_core(&cc
, x
, y
, ptr
, gpflags
))
1195 return (struct monst
*) 0;
1201 mndx
= monsndx(ptr
);
1202 /* if you are to make a specific monster and it has
1203 already been genocided, return */
1204 if (svm
.mvitals
[mndx
].mvflags
& G_GENOD
)
1205 return (struct monst
*) 0;
1206 if (wizard
&& (svm
.mvitals
[mndx
].mvflags
& G_EXTINCT
)) {
1207 debugpline1("Explicitly creating extinct monster %s.",
1208 mons
[mndx
].pmnames
[NEUTRAL
]);
1211 /* make a random (common) monster that can survive here.
1212 * (the special levels ask for random monsters at specific
1213 * positions, causing mass drowning on the medusa level,
1216 int tryct
= 0; /* maybe there are no good choices */
1219 if (!(ptr
= rndmonst())) {
1220 debugpline0("Warning: no monster.");
1221 return (struct monst
*) 0; /* no more monsters! */
1223 fakemon
.data
= ptr
; /* set up for goodpos */
1224 } while (++tryct
<= 50
1225 /* in Sokoban, don't accept a giant on first try;
1226 after that, boulder carriers are fair game */
1227 && ((tryct
== 1 && throws_rocks(ptr
) && In_sokoban(&u
.uz
))
1228 || !goodpos(x
, y
, &fakemon
, gpflags
)));
1229 mndx
= monsndx(ptr
);
1231 (void) propagate(mndx
, countbirth
, FALSE
);
1233 *mtmp
= cg
.zeromonst
; /* clear all entries in structure */
1235 if (mmflags
& MM_EGD
)
1237 if (mmflags
& MM_EPRI
)
1239 if (mmflags
& MM_ESHK
)
1241 if (mmflags
& MM_EMIN
)
1243 if (mmflags
& MM_EDOG
)
1245 if (mmflags
& MM_ASLEEP
)
1246 mtmp
->msleeping
= 1;
1249 mtmp
->m_id
= next_ident();
1250 set_mon_data(mtmp
, ptr
); /* mtmp->data = ptr; */
1251 if (ptr
->msound
== MS_LEADER
&& quest_info(MS_LEADER
) == mndx
)
1252 svq
.quest_status
.leader_m_id
= mtmp
->m_id
;
1255 /* set up level and hit points */
1256 newmonhp(mtmp
, mndx
);
1258 femaleok
= (!is_male(ptr
) && !is_neuter(ptr
));
1259 maleok
= (!is_female(ptr
) && !is_neuter(ptr
));
1260 if (is_female(ptr
) || ((mmflags
& MM_FEMALE
) != 0 && femaleok
))
1262 else if (is_male(ptr
) || ((mmflags
& MM_MALE
) != 0 && maleok
))
1265 /* leader and nemesis gender is usually hardcoded in mons[],
1266 but for ones which can be random, it has already been chosen
1267 (in role_init(), for possible use by the quest pager code) */
1268 else if (ptr
->msound
== MS_LEADER
&& quest_info(MS_LEADER
) == mndx
)
1269 mtmp
->female
= svq
.quest_status
.ldrgend
;
1270 else if (ptr
->msound
== MS_NEMESIS
&& quest_info(MS_NEMESIS
) == mndx
)
1271 mtmp
->female
= svq
.quest_status
.nemgend
;
1273 /* female used to be set randomly here even for neuters on the
1274 grounds that it was ignored, but after corpses were changed to
1275 retain gender it matters because it affects stacking of corpses */
1277 mtmp
->female
= femaleok
? rn2(2) : 0;
1279 if (In_sokoban(&u
.uz
) && !mindless(ptr
)) { /* know about traps here */
1280 mon_learns_traps(mtmp
, PIT
);
1281 mon_learns_traps(mtmp
, HOLE
);
1283 if (Is_stronghold(&u
.uz
) && !mindless(ptr
)) /* know about trap doors */
1284 mon_learns_traps(mtmp
, TRAPDOOR
);
1285 /* quest leader and nemesis both know about all trap types */
1286 if (ptr
->msound
== MS_LEADER
|| ptr
->msound
== MS_NEMESIS
)
1287 mon_learns_traps(mtmp
, ALL_TRAPS
);
1289 place_monster(mtmp
, x
, y
);
1290 mtmp
->mcansee
= mtmp
->mcanmove
= TRUE
;
1291 mtmp
->seen_resistance
= M_SEEN_NOTHING
;
1292 mtmp
->mpeaceful
= (mmflags
& MM_ANGRY
) ? FALSE
: peace_minded(ptr
);
1293 if ((mmflags
& MM_MINVIS
) != 0) /* for ^G */
1294 mon_set_minvis(mtmp
); /* call after place_monster() */
1296 switch (ptr
->mlet
) {
1298 set_mimic_sym(mtmp
);
1304 (void) mkobj_at(RANDOM_CLASS
, x
, y
, TRUE
);
1305 (void) hideunder(mtmp
);
1310 if (mndx
== PM_STALKER
|| mndx
== PM_BLACK_LIGHT
) {
1311 mtmp
->perminvis
= TRUE
;
1312 mtmp
->minvis
= TRUE
;
1317 (void) hideunder(mtmp
);
1321 mtmp
->msleeping
= 1;
1325 if (rn2(5) && !u
.uhave
.amulet
)
1326 mtmp
->msleeping
= 1;
1329 if (Race_if(PM_ELF
))
1330 mtmp
->mpeaceful
= FALSE
;
1333 if (is_unicorn(ptr
) && sgn(u
.ualign
.type
) == sgn(ptr
->maligntyp
))
1334 mtmp
->mpeaceful
= TRUE
;
1337 if (Inhell
&& is_bat(ptr
))
1338 mon_adjust_speed(mtmp
, 2, (struct obj
*) 0);
1341 if ((ct
= emits_light(mtmp
->data
)) > 0)
1342 new_light_source(mtmp
->mx
, mtmp
->my
, ct
, LS_MONSTER
,
1343 monst_to_any(mtmp
));
1344 mitem
= STRANGE_OBJECT
; /* extra inventory item for this monster */
1346 if (mndx
== PM_VLAD_THE_IMPALER
)
1347 mitem
= CANDELABRUM_OF_INVOCATION
;
1348 mtmp
->cham
= NON_PM
; /* default is "not a shapechanger" */
1349 if (!Protection_from_shape_changers
1350 && (mcham
= pm_to_cham(mndx
)) != NON_PM
) {
1351 /* this is a shapechanger after all */
1353 /* Vlad stays in his normal shape so he can carry the Candelabrum */
1354 if (mndx
!= PM_VLAD_THE_IMPALER
1355 /* Note: shapechanger's initial form used to be chosen here
1356 with rndmonst(), yielding a monster which was appropriate
1357 to the level's difficulty but ignoring the changer's usual
1358 type selection, so was inappropriate for vampshifters.
1359 Let newcham() pick the shape. */
1360 && newcham(mtmp
, (struct permonst
*) 0, NO_NC_FLAGS
))
1361 allow_minvent
= FALSE
;
1362 } else if (mndx
== PM_WIZARD_OF_YENDOR
) {
1364 svc
.context
.no_of_wizards
++;
1365 if (svc
.context
.no_of_wizards
== 1 && Is_earthlevel(&u
.uz
))
1367 } else if (mndx
== PM_GHOST
&& !(mmflags
& MM_NONAME
)) {
1368 mtmp
= christen_monst(mtmp
, rndghostname());
1369 } else if (mndx
== PM_CROESUS
) {
1370 mitem
= TWO_HANDED_SWORD
;
1371 } else if (ptr
->msound
== MS_NEMESIS
) {
1372 mitem
= BELL_OF_OPENING
;
1373 } else if (mndx
== PM_PESTILENCE
) {
1374 mitem
= POT_SICKNESS
;
1376 if (mitem
!= STRANGE_OBJECT
&& allow_minvent
)
1377 (void) mongets(mtmp
, mitem
);
1380 if ((is_ndemon(ptr
) || mndx
== PM_WUMPUS
1381 || mndx
== PM_LONG_WORM
|| mndx
== PM_GIANT_EEL
)
1382 && !u
.uhave
.amulet
&& rn2(5))
1383 mtmp
->msleeping
= TRUE
;
1386 newsym(mtmp
->mx
, mtmp
->my
);
1390 if (is_dprince(ptr
) && ptr
->msound
== MS_BRIBE
) {
1391 mtmp
->mpeaceful
= mtmp
->minvis
= mtmp
->perminvis
= 1;
1393 if (u_wield_art(ART_EXCALIBUR
) || u_wield_art(ART_DEMONBANE
))
1394 mtmp
->mpeaceful
= mtmp
->mtame
= FALSE
;
1396 if (mndx
== PM_RAVEN
&& uwep
&& uwep
->otyp
== BEC_DE_CORBIN
)
1397 mtmp
->mpeaceful
= TRUE
;
1398 if (mndx
== PM_LONG_WORM
&& (mtmp
->wormno
= get_wormno()) != 0) {
1399 initworm(mtmp
, allowtail
? rn2(5) : 0);
1400 if (count_wsegs(mtmp
))
1401 place_worm_tail_randomly(mtmp
, x
, y
);
1403 /* it's possible to create an ordinary monster of some special
1404 types; make sure their extended data is initialized to
1405 something sensible if caller hasn't specified MM_EPRI|MM_EMIN
1406 (when they're specified, caller intends to handle this itself) */
1407 if ((mndx
== PM_ALIGNED_CLERIC
|| mndx
== PM_HIGH_CLERIC
)
1408 ? !(mmflags
& (MM_EPRI
| MM_EMIN
))
1409 : (mndx
== PM_ANGEL
&& !(mmflags
& MM_EMIN
) && !rn2(3))) {
1415 mtmp
->isminion
= 1; /* make priest be a roamer */
1416 eminp
->min_align
= rn2(3) - 1; /* no A_NONE */
1417 eminp
->renegade
= (boolean
) ((mmflags
& MM_ANGRY
) ? 1 : !rn2(3));
1418 mtmp
->mpeaceful
= (eminp
->min_align
== u
.ualign
.type
)
1422 set_malign(mtmp
); /* having finished peaceful changes */
1423 if (anymon
&& !(mmflags
& MM_NOGRP
)) {
1424 if ((ptr
->geno
& G_SGROUP
) && rn2(2)) {
1425 m_initsgrp(mtmp
, mtmp
->mx
, mtmp
->my
, mmflags
);
1426 } else if (ptr
->geno
& G_LGROUP
) {
1428 m_initlgrp(mtmp
, mtmp
->mx
, mtmp
->my
, mmflags
);
1430 m_initsgrp(mtmp
, mtmp
->mx
, mtmp
->my
, mmflags
);
1434 if (allow_minvent
) {
1436 m_initweap(mtmp
); /* equip with weapons / armor */
1437 m_initinv(mtmp
); /* add on a few special items incl. more armor */
1438 m_dowear(mtmp
, TRUE
);
1440 if (!rn2(100) && is_domestic(ptr
)
1441 && can_saddle(mtmp
) && !which_armor(mtmp
, W_SADDLE
)) {
1442 /* NULL obj arg means put_saddle_on_mon()
1443 * will create the saddle itself */
1444 put_saddle_on_mon((struct obj
*) 0, mtmp
);
1448 /* no initial inventory is allowed */
1450 discard_minvent(mtmp
, TRUE
);
1451 mtmp
->minvent
= (struct obj
*) 0; /* caller expects this */
1453 if (ptr
->mflags3
&& !(mmflags
& MM_NOWAIT
)) {
1454 if (ptr
->mflags3
& M3_WAITFORU
)
1455 mtmp
->mstrategy
|= STRAT_WAITFORU
;
1456 if (ptr
->mflags3
& M3_CLOSE
)
1457 mtmp
->mstrategy
|= STRAT_CLOSE
;
1458 if (ptr
->mflags3
& (M3_WAITMASK
| M3_COVETOUS
))
1459 mtmp
->mstrategy
|= STRAT_APPEARMSG
;
1462 if (allow_minvent
&& gm
.migrating_objs
)
1463 deliver_obj_to_mon(mtmp
, 1, DF_NONE
); /* in case of waiting items */
1466 newsym(mtmp
->mx
, mtmp
->my
); /* make sure the mon shows up */
1467 if (!(mmflags
& MM_NOMSG
)) {
1468 char mbuf
[BUFSZ
], *what
= 0;
1469 /* MM_NOEXCLAM is used for #wizgenesis (^G) */
1470 boolean exclaim
= !(mmflags
& MM_NOEXCLAM
);
1472 if ((canseemon(mtmp
) && (M_AP_TYPE(mtmp
) == M_AP_NOTHING
1473 || M_AP_TYPE(mtmp
) == M_AP_MONSTER
))
1474 || sensemon(mtmp
)) {
1475 what
= Amonnam(mtmp
);
1476 if (M_AP_TYPE(mtmp
) == M_AP_MONSTER
)
1478 } else if (canseemon(mtmp
)) {
1479 /* mimic masquerading as furniture or object and not sensed */
1480 mhidden_description(mtmp
, MHID_ARTICLE
| MHID_ALTMON
, mbuf
);
1481 what
= upstart(mbuf
);
1484 set_msg_xy(mtmp
->mx
, mtmp
->my
);
1485 Norep("%s%s appears%s%c", what
,
1486 exclaim
? " suddenly" : "",
1487 next2u(x
, y
) ? " next to you"
1488 : (distu(x
, y
) <= (BOLT_LIM
* BOLT_LIM
)) ? " close by"
1490 exclaim
? '!' : '.');
1493 /* if discernable and a threat, stop fiddling while Rome burns */
1495 (void) dochugw(mtmp
, FALSE
);
1497 /* TODO: unify with teleport appears msg */
1503 /* caller rejects makemon()'s result; always returns Null */
1507 mmflags_nht mmflags
)
1509 boolean countbirth
= ((mmflags
& MM_NOCOUNTBIRTH
) == 0);
1510 int mndx
= monsndx(mon
->data
);
1512 /* if count has reached the limit of 255, we don't know whether
1513 that just happened when creating this monster or the threshold
1514 had already been reached and further increments were suppressed;
1515 assume the latter */
1516 if (countbirth
&& svm
.mvitals
[mndx
].born
> 0
1517 && svm
.mvitals
[mndx
].born
< 255)
1518 svm
.mvitals
[mndx
].born
-= 1;
1519 if ((mon
->data
->geno
& G_UNIQ
) != 0)
1520 svm
.mvitals
[mndx
].mvflags
&= ~G_EXTINCT
;
1522 mon
->mhp
= 0; /* let discard_minvent() know that mon isn't being kept */
1523 /* uncreate any artifact that the monster was provided with; unlike
1524 mongone(), this doesn't protect special items like the Amulet
1525 by dropping them so caller should handle them when applicable */
1526 discard_minvent(mon
, TRUE
);
1529 return (struct monst
*) 0;
1533 mbirth_limit(int mndx
)
1535 /* There is an implicit limit of 4 for "high priest of <deity>",
1536 * but aligned priests can grow into high priests, thus they aren't
1537 * really limited to 4, so leave the default amount in place for them.
1540 /* assert(MAXMONNO < 255); */
1541 return (mndx
== PM_NAZGUL
? 9 : mndx
== PM_ERINYS
? 3 : MAXMONNO
);
1544 /* used for wand/scroll/spell of create monster */
1545 /* returns TRUE iff you know monsters have been created */
1549 struct permonst
*mptr
, /* usually null; used for confused reading */
1555 boolean known
= FALSE
;
1556 boolean ask
= (wizard
&& !neverask
);
1560 if (create_particular()) {
1564 ask
= FALSE
; /* ESC will shut off prompting */
1567 /* if in water, try to encourage an aquatic monster
1568 by finding and then specifying another wet location */
1569 if (!mptr
&& u
.uinwater
&& enexto(&c
, x
, y
, &mons
[PM_GIANT_EEL
]))
1572 if ((mon
= makemon(mptr
, x
, y
, NO_MM_FLAGS
)) == 0)
1573 continue; /* try again [should probably stop instead] */
1575 if ((canseemon(mon
) && (M_AP_TYPE(mon
) == M_AP_NOTHING
1576 || M_AP_TYPE(mon
) == M_AP_MONSTER
))
1586 if (mons
[mndx
].geno
& (G_NOGEN
| G_UNIQ
))
1588 if (svm
.mvitals
[mndx
].mvflags
& G_GONE
)
1591 return (boolean
) (mons
[mndx
].maligntyp
> A_NEUTRAL
);
1593 return (boolean
) ((mons
[mndx
].geno
& G_HELL
) != 0);
1597 * shift the probability of a monster's generation by
1598 * comparing the dungeon alignment and monster alignment.
1599 * return an integer in the range of 0-5.
1602 align_shift(struct permonst
*ptr
)
1604 static NEARDATA
long oldmoves
= 0L; /* != 1, starting value of moves */
1605 static NEARDATA s_level
*lev
;
1608 if (oldmoves
!= svm
.moves
) {
1609 lev
= Is_special(&u
.uz
);
1610 oldmoves
= svm
.moves
;
1612 switch ((lev
) ? lev
->flags
.align
: svd
.dungeons
[u
.uz
.dnum
].flags
.align
) {
1613 default: /* just in case */
1618 alshift
= (ptr
->maligntyp
+ 20) / (2 * ALIGNWEIGHT
);
1621 alshift
= (20 - abs(ptr
->maligntyp
)) / ALIGNWEIGHT
;
1624 alshift
= (-(ptr
->maligntyp
- 20)) / (2 * ALIGNWEIGHT
);
1630 /* return larger value if monster prefers the level temperature */
1632 temperature_shift(struct permonst
*ptr
)
1634 if (svl
.level
.flags
.temperature
1635 && pm_resistance(ptr
, (svl
.level
.flags
.temperature
> 0)
1636 ? MR_FIRE
: MR_COLD
))
1641 /* select a random monster type */
1645 return rndmonst_adj(0, 0);
1648 /* select a random monster type, with adjusted difficulty */
1650 rndmonst_adj(int minadj
, int maxadj
)
1652 struct permonst
*ptr
;
1654 int weight
, totalweight
, selected_mndx
, zlevel
, minmlev
, maxmlev
;
1655 boolean elemlevel
, upper
;
1657 if (u
.uz
.dnum
== quest_dnum
&& rn2(7) && (ptr
= qt_montype()) != 0)
1660 zlevel
= level_difficulty();
1661 minmlev
= monmin_difficulty(zlevel
) + minadj
;
1662 maxmlev
= monmax_difficulty(zlevel
) + maxadj
;
1663 upper
= Is_rogue_level(&u
.uz
); /* prefer uppercase only on rogue level */
1664 elemlevel
= In_endgame(&u
.uz
) && !Is_astralevel(&u
.uz
); /* elmntl plane */
1666 /* amount processed so far */
1668 selected_mndx
= NON_PM
;
1670 for (mndx
= LOW_PM
; mndx
< SPECIAL_PM
; ++mndx
) {
1673 if (montooweak(mndx
, minmlev
) || montoostrong(mndx
, maxmlev
))
1675 if (upper
&& !isupper(monsym(ptr
)))
1677 if (elemlevel
&& wrong_elem_type(ptr
))
1681 if (Inhell
&& (ptr
->geno
& G_NOHELL
))
1685 * Weighted reservoir sampling: select ptr with a
1686 * (ptr weight)/(total of all weights so far including ptr's)
1687 * probability. For example, if the previous total is 10, and
1688 * this is now looking at acid blobs with a frequency of 2, it
1689 * has a 2/12 chance of abandoning ptr's previous value in favor
1690 * of acid blobs, and 10/12 chance of keeping whatever it was.
1692 * This does not bias results towards either the earlier or the
1693 * later monsters: the smaller pool and better odds from being
1694 * earlier are exactly canceled out by having more monsters to
1695 * potentially steal its spot.
1697 weight
= (int) (ptr
->geno
& G_FREQ
) + align_shift(ptr
);
1698 weight
+= temperature_shift(ptr
);
1699 if (weight
< 0 || weight
> 127) {
1700 impossible("bad weight in rndmonst for mndx %d", mndx
);
1703 /* was unconditional, but if weight==0, rn2() < 0 will always fail;
1704 also need to avoid rn2(0) if totalweight is still 0 so far */
1706 totalweight
+= weight
; /* totalweight now guaranteed to be > 0 */
1707 if (rn2(totalweight
) < weight
)
1708 selected_mndx
= mndx
;
1712 * Possible modification: if totalweight is "too low" or nothing
1713 * viable was picked, expand minmlev..maxmlev range and try again.
1715 if (selected_mndx
== NON_PM
|| uncommon(selected_mndx
)) {
1716 /* maybe no common monsters left, or all are too weak or too strong */
1717 if (selected_mndx
!= NON_PM
)
1718 debugpline1("rndmonst returning Null [uncommon 'mndx'=#%d]",
1720 return (struct permonst
*) 0;
1722 return &mons
[selected_mndx
];
1725 /* decide whether it's ok to generate a candidate monster by mkclass() */
1727 mk_gen_ok(int mndx
, unsigned mvflagsmask
, unsigned genomask
)
1729 struct permonst
*ptr
= &mons
[mndx
];
1731 if (svm
.mvitals
[mndx
].mvflags
& mvflagsmask
)
1733 if (ptr
->geno
& genomask
)
1735 if (is_placeholder(ptr
))
1737 #ifdef MAIL_STRUCTURES
1738 /* special levels might ask for random demon type; reject this one */
1739 if (ptr
== &mons
[PM_MAIL_DAEMON
])
1745 /* Make one of the multiple types of a given monster class.
1746 The second parameter specifies a special casing bit mask
1747 to allow the normal genesis masks to be deactivated.
1748 Returns Null if no monsters in that class can be made. */
1750 mkclass(char class, int spc
)
1752 return mkclass_aligned(class, spc
, A_NONE
);
1755 /* mkclass() with alignment restrictions; used by ndemon() */
1757 mkclass_aligned(char class, int spc
, /* special mons[].geno handling */
1760 int first
, last
, num
= 0;
1761 int k
, nums
[SPECIAL_PM
+ 1]; /* +1: insurance for final return value */
1762 int maxmlev
, gehennom
= Inhell
!= 0;
1763 unsigned mv_mask
, gn_mask
;
1765 (void) memset((genericptr_t
) nums
, 0, sizeof nums
);
1766 maxmlev
= level_difficulty() >> 1;
1767 if (class < 1 || class >= MAXMCLASSES
) {
1768 impossible("mkclass called with bad class!");
1769 return (struct permonst
*) 0;
1771 /* Assumption #1: monsters of a given class are contiguous in the
1772 * mons[] array. Player monsters and quest denizens
1773 * are an exception; mkclass() won't pick them.
1774 * SPECIAL_PM is long worm tail and separates the
1775 * regular monsters from the exceptions.
1777 for (first
= LOW_PM
; first
< SPECIAL_PM
; first
++)
1778 if (mons
[first
].mlet
== class)
1780 if (first
== SPECIAL_PM
) {
1781 impossible("mkclass found no class %d monsters", class);
1782 return (struct permonst
*) 0;
1785 mv_mask
= G_GONE
; /* G_GENOD | G_EXTINCT */
1786 if ((spc
& G_IGNORE
) != 0) {
1787 mv_mask
= 0; /* mv_mask &= ~G_GONE; */
1788 /* G_IGNORE is not a mons[].geno mask so get rid of it now */
1792 /* Assumption #2: monsters of a given class are presented in ascending
1793 * order of strength.
1795 for (last
= first
; last
< SPECIAL_PM
&& mons
[last
].mlet
== class;
1797 if (atyp
!= A_NONE
&& sgn(mons
[last
].maligntyp
) != sgn(atyp
))
1799 /* traditionally mkclass() ignored hell-only and never-in-hell;
1800 now we usually honor those but not all the time, mostly so that
1801 the majority of major demons aren't constrained to Gehennom;
1802 arch- and master liches are always so constrained (for creation;
1803 lesser liches might grow up into them elsewhere) */
1804 gn_mask
= (G_NOGEN
| G_UNIQ
);
1805 if (rn2(9) || class == S_LICH
)
1806 gn_mask
|= (gehennom
? G_NOHELL
: G_HELL
);
1809 if (mk_gen_ok(last
, mv_mask
, gn_mask
)) {
1810 /* consider it; don't reject a toostrong() monster if we
1811 don't have anything yet (num==0) or if it is the same
1812 (or lower) difficulty as preceding candidate (non-zero
1813 'num' implies last > first so mons[last-1] is safe);
1814 sometimes accept it even if high difficulty */
1815 if (num
&& montoostrong(last
, maxmlev
)
1816 && mons
[last
].difficulty
> mons
[last
- 1].difficulty
1819 if ((k
= (mons
[last
].geno
& G_FREQ
)) > 0) {
1820 /* skew towards lower value monsters at lower exp. levels
1821 (this used to be done in the next loop, but that didn't
1822 work well when multiple species had the same level and
1823 were followed by one that was past the bias threshold;
1824 cited example was succubus and incubus, where the bias
1825 against picking the next demon resulted in incubus
1826 being picked nearly twice as often as succubus);
1827 we need the '+1' in case the entire set is too high
1828 level (really low svl.level hero) */
1829 nums
[last
] = k
+ 1 - (adj_lev(&mons
[last
]) > (u
.ulevel
* 2));
1835 return (struct permonst
*) 0;
1837 /* the hard work has already been done; 'num' should hit 0 before
1838 first reaches last (which is actually one past our last candidate) */
1839 for (num
= rnd(num
); first
< last
; first
++)
1840 if ((num
-= nums
[first
]) <= 0)
1843 return nums
[first
] ? &mons
[first
] : (struct permonst
*) 0;
1846 /* like mkclass(), but excludes difficulty considerations; used when
1847 player with polycontrol picks a class instead of a specific type;
1848 genocided types are avoided but extinct ones are acceptable; we don't
1849 check polyok() here--caller accepts some choices !polyok() would reject */
1851 mkclass_poly(int class)
1853 int first
, last
, num
= 0;
1856 for (first
= LOW_PM
; first
< SPECIAL_PM
; first
++)
1857 if (mons
[first
].mlet
== class)
1859 if (first
== SPECIAL_PM
)
1862 gmask
= (G_NOGEN
| G_UNIQ
);
1863 /* mkclass() does this on a per monster type basis, but doing that here
1864 would make the two loops inconsistent with each other for non L */
1865 if (rn2(9) || class == S_LICH
)
1866 gmask
|= (Inhell
? G_NOHELL
: G_HELL
);
1868 for (last
= first
; last
< SPECIAL_PM
&& mons
[last
].mlet
== class; last
++)
1869 if (mk_gen_ok(last
, G_GENOD
, gmask
))
1870 num
+= mons
[last
].geno
& G_FREQ
;
1874 for (num
= rnd(num
); num
> 0; first
++)
1875 if (mk_gen_ok(first
, G_GENOD
, gmask
))
1876 num
-= mons
[first
].geno
& G_FREQ
;
1877 first
--; /* correct an off-by-one error */
1882 /* adjust strength of monsters based on u.uz and u.ulevel */
1884 adj_lev(struct permonst
*ptr
)
1888 if (ptr
== &mons
[PM_WIZARD_OF_YENDOR
]) {
1889 /* does not depend on other strengths, but does get stronger
1890 * every time he is killed
1892 tmp
= ptr
->mlevel
+ svm
.mvitals
[PM_WIZARD_OF_YENDOR
].died
;
1898 if ((tmp
= ptr
->mlevel
) > 49)
1899 return 50; /* "special" demons/devils */
1900 tmp2
= (level_difficulty() - tmp
);
1902 tmp
--; /* if mlevel > u.uz decrement tmp */
1904 tmp
+= (tmp2
/ 5); /* else increment 1 per five diff */
1906 tmp2
= (u
.ulevel
- ptr
->mlevel
); /* adjust vs. the player */
1908 tmp
+= (tmp2
/ 4); /* level as well */
1910 tmp2
= (3 * ((int) ptr
->mlevel
)) / 2; /* crude upper limit */
1912 tmp2
= 49; /* hard upper limit */
1913 return ((tmp
> tmp2
) ? tmp2
: (tmp
> 0 ? tmp
: 0)); /* 0 lower limit */
1916 /* monster earned experience and will gain some hit points; it might also
1917 grow into a bigger monster (baby to adult, soldier to officer, etc) */
1919 grow_up(struct monst
*mtmp
, struct monst
*victim
)
1921 int oldtype
, newtype
, max_increase
, cur_increase
, lev_limit
, hp_threshold
;
1923 struct permonst
*ptr
= mtmp
->data
;
1925 /* monster died after killing enemy but before calling this function */
1926 /* currently possible if killing a gas spore */
1927 if (DEADMONSTER(mtmp
))
1928 return (struct permonst
*) 0;
1930 /* note: none of the monsters with special hit point calculations
1931 have both little and big forms (killer bee can't grow into queen
1932 bee by just killing things, so isn't in the little_to_big list) */
1933 oldtype
= monsndx(ptr
);
1934 newtype
= (oldtype
== PM_KILLER_BEE
&& !victim
) ? PM_QUEEN_BEE
1935 : little_to_big(oldtype
);
1937 /* gender-neutral PM_CLERIC now */
1938 if (newtype
== PM_PRIEST
&& mtmp
->female
)
1939 newtype
= PM_PRIESTESS
;
1942 /* growth limits differ depending on method of advancement */
1943 if (victim
) { /* killed a monster */
1945 * The HP threshold is the maximum number of hit points for the
1946 * current level; once exceeded, a level will be gained.
1947 * Possible bug: if somehow the hit points are already higher
1948 * than that, monster will gain a level without any increase in HP.
1950 hp_threshold
= mtmp
->m_lev
* 8; /* normal limit */
1953 else if (is_golem(ptr
)) /* strange creatures */
1954 hp_threshold
= ((mtmp
->mhpmax
/ 10) + 1) * 10 - 1;
1955 else if (is_home_elemental(ptr
))
1957 lev_limit
= 3 * (int) ptr
->mlevel
/ 2; /* same as adj_lev() */
1958 /* If they can grow up, be sure the level is high enough for that */
1959 if (oldtype
!= newtype
&& mons
[newtype
].mlevel
> lev_limit
)
1960 lev_limit
= (int) mons
[newtype
].mlevel
;
1961 /* number of hit points to gain; unlike for the player, we put
1962 the limit at the bottom of the next level rather than the top */
1963 max_increase
= rnd((int) victim
->m_lev
+ 1);
1964 if (mtmp
->mhpmax
+ max_increase
> hp_threshold
+ 1)
1965 max_increase
= max((hp_threshold
+ 1) - mtmp
->mhpmax
, 0);
1966 cur_increase
= (max_increase
> 1) ? rn2(max_increase
) : 0;
1968 /* a gain level potion or wraith corpse; always go up a level
1969 unless already at maximum (49 is hard upper limit except
1970 for demon lords, who start at 50 and can't go any higher) */
1971 max_increase
= cur_increase
= rnd(8);
1972 hp_threshold
= 0; /* smaller than `mhpmax + max_increase' */
1973 lev_limit
= 50; /* recalc below */
1976 mtmp
->mhpmax
+= max_increase
;
1977 mtmp
->mhp
+= cur_increase
;
1978 if (mtmp
->mhpmax
<= hp_threshold
)
1979 return ptr
; /* doesn't gain a level */
1981 if (is_mplayer(ptr
))
1982 lev_limit
= 30; /* same as player */
1983 else if (lev_limit
< 5)
1984 lev_limit
= 5; /* arbitrary */
1985 else if (lev_limit
> 49)
1986 lev_limit
= (ptr
->mlevel
> 49 ? 50 : 49);
1988 if ((int) ++mtmp
->m_lev
>= mons
[newtype
].mlevel
&& newtype
!= oldtype
) {
1989 ptr
= &mons
[newtype
];
1990 /* new form might force gender change */
1991 fem
= is_male(ptr
) ? 0 : is_female(ptr
) ? 1 : mtmp
->female
;
1993 if (svm
.mvitals
[newtype
].mvflags
& G_GENOD
) { /* allow G_EXTINCT */
1994 if (canspotmon(mtmp
))
1995 pline("As %s grows up into %s, %s %s!", mon_nam(mtmp
),
1996 an(pmname(ptr
, Mgender(mtmp
))), mhe(mtmp
),
1997 nonliving(ptr
) ? "expires" : "dies");
1998 set_mon_data(mtmp
, ptr
); /* keep svm.mvitals[] accurate */
2000 return (struct permonst
*) 0;
2001 } else if (canspotmon(mtmp
)) {
2005 * Temporary (?) hack to fix growing into opposite gender.
2007 Sprintf(buf
, "%s%s",
2008 /* deal with female gnome becoming a gnome lord */
2009 (mtmp
->female
&& !fem
) ? "male "
2010 /* or a male gnome becoming a gnome lady
2011 (can't happen with 3.6.0 mons[], but perhaps
2012 slightly less sexist if prepared for it...) */
2013 : (fem
&& !mtmp
->female
) ? "female " : "",
2015 pline_mon(mtmp
, "%s %s %s.", YMonnam(mtmp
),
2016 (fem
!= mtmp
->female
) ? "changes into"
2017 : humanoid(ptr
) ? "becomes"
2021 set_mon_data(mtmp
, ptr
);
2022 if (mtmp
->cham
== oldtype
&& is_shapeshifter(ptr
))
2023 mtmp
->cham
= newtype
; /* vampire growing into vampire lord */
2024 newsym(mtmp
->mx
, mtmp
->my
); /* color may change */
2025 lev_limit
= (int) mtmp
->m_lev
; /* never undo increment */
2027 mtmp
->female
= fem
; /* gender might be changing */
2028 /* if 'mtmp' is leashed, persistent inventory window needs updating */
2030 update_inventory(); /* x - leash (attached to a <mon>) */
2034 if ((int) mtmp
->m_lev
> lev_limit
) {
2035 mtmp
->m_lev
--; /* undo increment */
2036 /* HP might have been allowed to grow when it shouldn't */
2037 if (mtmp
->mhpmax
== hp_threshold
+ 1)
2040 if (mtmp
->mhpmax
> 50 * 8)
2041 mtmp
->mhpmax
= 50 * 8; /* absolute limit */
2042 if (mtmp
->mhp
> mtmp
->mhpmax
)
2043 mtmp
->mhp
= mtmp
->mhpmax
;
2049 mongets(struct monst
*mtmp
, int otyp
)
2054 return (struct obj
*) 0;
2055 otmp
= mksobj(otyp
, TRUE
, FALSE
);
2057 if (mtmp
->data
->mlet
== S_DEMON
) {
2058 /* demons never get blessed objects */
2061 } else if (is_lminion(mtmp
)) {
2062 /* lawful minions don't get cursed, bad, or rusting objects */
2063 otmp
->cursed
= FALSE
;
2066 otmp
->oerodeproof
= 1;
2067 otmp
->oeroded
= otmp
->oeroded2
= 0;
2068 } else if (is_mplayer(mtmp
->data
) && is_sword(otmp
)) {
2069 otmp
->spe
= (3 + rn2(4));
2072 if (otmp
->otyp
== CANDELABRUM_OF_INVOCATION
) {
2075 otmp
->lamplit
= FALSE
;
2076 otmp
->blessed
= otmp
->cursed
= FALSE
;
2077 } else if (otmp
->otyp
== BELL_OF_OPENING
) {
2078 otmp
->blessed
= otmp
->cursed
= FALSE
;
2079 } else if (otmp
->otyp
== SPE_BOOK_OF_THE_DEAD
) {
2080 otmp
->blessed
= FALSE
;
2081 otmp
->cursed
= TRUE
;
2084 /* leaders don't tolerate inferior quality battle gear */
2085 if (is_prince(mtmp
->data
)) {
2086 if (otmp
->oclass
== WEAPON_CLASS
&& otmp
->spe
< 1)
2088 else if (otmp
->oclass
== ARMOR_CLASS
&& otmp
->spe
< 0)
2092 if (mpickobj(mtmp
, otmp
)) {
2093 /* otmp was freed via merging with something else */
2094 otmp
= (struct obj
*) 0;
2104 case PM_STRAW_GOLEM
:
2106 case PM_PAPER_GOLEM
:
2110 case PM_LEATHER_GOLEM
:
2116 case PM_FLESH_GOLEM
:
2120 case PM_STONE_GOLEM
:
2122 case PM_GLASS_GOLEM
:
2132 * Alignment vs. yours determines monster's attitude to you.
2133 * (Some "animal" types are co-aligned, but also hungry.)
2136 peace_minded(struct permonst
*ptr
)
2138 aligntyp mal
= ptr
->maligntyp
, ual
= u
.ualign
.type
;
2140 if (always_peaceful(ptr
))
2142 if (always_hostile(ptr
))
2144 if (ptr
->msound
== MS_LEADER
|| ptr
->msound
== MS_GUARDIAN
)
2146 if (ptr
->msound
== MS_NEMESIS
)
2148 if (ptr
== &mons
[PM_ERINYS
])
2149 return !u
.ualign
.abuse
;
2151 if (race_peaceful(ptr
))
2153 if (race_hostile(ptr
))
2156 /* the monster is hostile if its alignment is different from the
2158 if (sgn(mal
) != sgn(ual
))
2161 /* Negative monster hostile to player with Amulet. */
2162 if (mal
< A_NEUTRAL
&& u
.uhave
.amulet
)
2165 /* minions are hostile to players that have strayed at all */
2167 return (boolean
) (u
.ualign
.record
>= 0);
2169 /* Last case: a chance of a co-aligned monster being
2170 * hostile. This chance is greater if the player has strayed
2171 * (u.ualign.record negative) or the monster is not strongly aligned.
2173 return (boolean
) (!!rn2(16 + (u
.ualign
.record
< -15 ? -15
2175 && !!rn2(2 + abs(mal
)));
2178 /* Set malign to have the proper effect on player alignment if monster is
2179 * killed. Negative numbers mean it's bad to kill this monster; positive
2180 * numbers mean it's good. Since there are more hostile monsters than
2181 * peaceful monsters, the penalty for killing a peaceful monster should be
2182 * greater than the bonus for killing a hostile monster to maintain balance.
2184 * it's bad to kill peaceful monsters, potentially worse to kill always-
2185 * peaceful monsters;
2186 * it's never bad to kill a hostile monster, although it may not be good.
2189 set_malign(struct monst
*mtmp
)
2191 schar mal
= mtmp
->data
->maligntyp
;
2194 if (mtmp
->ispriest
|| mtmp
->isminion
) {
2195 /* some monsters have individual alignments; check them */
2196 if (mtmp
->ispriest
&& EPRI(mtmp
))
2197 mal
= EPRI(mtmp
)->shralign
;
2198 else if (mtmp
->isminion
&& EMIN(mtmp
))
2199 mal
= EMIN(mtmp
)->min_align
;
2200 /* unless alignment is none, set mal to -5,0,5 */
2201 /* (see align.h for valid aligntyp values) */
2206 coaligned
= (sgn(mal
) == sgn(u
.ualign
.type
));
2207 if (mtmp
->data
->msound
== MS_LEADER
) {
2209 } else if (mal
== A_NONE
) {
2210 if (mtmp
->mpeaceful
)
2213 mtmp
->malign
= 20; /* really hostile */
2214 } else if (always_peaceful(mtmp
->data
)) {
2215 int absmal
= abs(mal
);
2216 if (mtmp
->mpeaceful
)
2217 mtmp
->malign
= -3 * max(5, absmal
);
2219 mtmp
->malign
= 3 * max(5, absmal
); /* renegade */
2220 } else if (always_hostile(mtmp
->data
)) {
2221 int absmal
= abs(mal
);
2225 mtmp
->malign
= max(5, absmal
);
2226 } else if (coaligned
) {
2227 int absmal
= abs(mal
);
2228 if (mtmp
->mpeaceful
)
2229 mtmp
->malign
= -3 * max(3, absmal
);
2231 mtmp
->malign
= max(3, absmal
);
2232 } else /* not coaligned and therefore hostile */
2233 mtmp
->malign
= abs(mal
);
2236 /* allocate a new mcorpsenm field for a monster; only need mextra itself */
2238 newmcorpsenm(struct monst
*mtmp
)
2241 mtmp
->mextra
= newmextra();
2242 MCORPSENM(mtmp
) = NON_PM
; /* not initialized yet */
2245 /* release monster's mcorpsenm field; basically a no-op */
2247 freemcorpsenm(struct monst
*mtmp
)
2249 if (has_mcorpsenm(mtmp
))
2250 MCORPSENM(mtmp
) = NON_PM
;
2253 static const NEARDATA
char syms
[] = {
2254 MAXOCLASSES
, MAXOCLASSES
, RING_CLASS
, WAND_CLASS
, WEAPON_CLASS
,
2255 FOOD_CLASS
, COIN_CLASS
, SCROLL_CLASS
, POTION_CLASS
, ARMOR_CLASS
,
2256 AMULET_CLASS
, TOOL_CLASS
, ROCK_CLASS
, GEM_CLASS
, SPBOOK_CLASS
,
2257 S_MIMIC_DEF
, S_MIMIC_DEF
,
2261 set_mimic_sym(struct monst
*mtmp
)
2263 int typ
, roomno
, rt
;
2264 unsigned appear
, ap_type
;
2269 if (!mtmp
|| Protection_from_shape_changers
)
2273 typ
= levl
[mx
][my
].typ
;
2274 /* only valid for INSIDE of room */
2275 roomno
= levl
[mx
][my
].roomno
- ROOMOFFSET
;
2277 rt
= svr
.rooms
[roomno
].rtype
;
2278 #ifdef SPECIALIZATION
2279 else if (IS_ROOM(typ
))
2280 rt
= OROOM
, roomno
= 0;
2283 rt
= 0; /* roomno < 0 case for GCC_WARN */
2285 if (OBJ_AT(mx
, my
)) {
2286 ap_type
= M_AP_OBJECT
;
2287 appear
= svl
.level
.objects
[mx
][my
]->otyp
;
2288 } else if (IS_DOOR(typ
) || IS_WALL(typ
) || typ
== SDOOR
|| typ
== SCORR
) {
2289 ap_type
= M_AP_FURNITURE
;
2291 * If there is a wall to the left that connects to this
2292 * location, then the mimic mimics a horizontal closed door.
2293 * This does not allow doors to be in corners of rooms.
2294 * Since rogue has no closed doors, mimic a wall there
2295 * (yes, mimics can end up on this level by various means).
2297 if (mx
!= 0 && (levl
[mx
- 1][my
].typ
== HWALL
2298 || levl
[mx
- 1][my
].typ
== TLCORNER
2299 || levl
[mx
- 1][my
].typ
== TRWALL
2300 || levl
[mx
- 1][my
].typ
== BLCORNER
2301 || levl
[mx
- 1][my
].typ
== TDWALL
2302 || levl
[mx
- 1][my
].typ
== CROSSWALL
2303 || levl
[mx
- 1][my
].typ
== TUWALL
))
2304 appear
= Is_rogue_level(&u
.uz
) ? S_hwall
: S_hcdoor
;
2306 appear
= Is_rogue_level(&u
.uz
) ? S_vwall
: S_vcdoor
;
2307 } else if (svl
.level
.flags
.is_maze_lev
2308 && !(In_mines(&u
.uz
) && in_town(u
.ux
, u
.uy
))
2309 && !In_sokoban(&u
.uz
) && rn2(2)) {
2310 ap_type
= M_AP_OBJECT
;
2312 } else if (roomno
< 0 && !t_at(mx
, my
)) {
2313 ap_type
= M_AP_OBJECT
;
2315 } else if (rt
== ZOO
|| rt
== VAULT
) {
2316 ap_type
= M_AP_OBJECT
;
2317 appear
= GOLD_PIECE
;
2318 } else if (rt
== DELPHI
) {
2320 ap_type
= M_AP_OBJECT
;
2323 ap_type
= M_AP_FURNITURE
;
2324 appear
= S_fountain
;
2326 } else if (rt
== TEMPLE
) {
2327 ap_type
= M_AP_FURNITURE
;
2331 * We won't bother with beehives, morgues, barracks, throne rooms
2332 * since they shouldn't contain too many mimics anyway...
2335 } else if (rt
>= SHOPBASE
) {
2336 if (rn2(10) >= depth(&u
.uz
)) {
2337 s_sym
= S_MIMIC_DEF
; /* -> STRANGE_OBJECT */
2340 s_sym
= get_shop_item(rt
- SHOPBASE
);
2342 ap_type
= M_AP_OBJECT
;
2344 } else if (rt
== FODDERSHOP
&& s_sym
> MAXOCLASSES
) {
2345 /* health food store usually generates pseudo-class
2346 VEGETARIAN_CLASS which is MAXOCLASSES+1; we don't bother
2347 trying to select among all possible vegetarian food items */
2348 ap_type
= M_AP_OBJECT
;
2349 appear
= rn2(2) ? LUMP_OF_ROYAL_JELLY
: SLIME_MOLD
;
2351 if (s_sym
== RANDOM_CLASS
|| s_sym
>= MAXOCLASSES
)
2352 s_sym
= syms
[rn2(SIZE(syms
) - 2) + 2];
2356 s_sym
= ROLL_FROM(syms
);
2358 if (s_sym
== MAXOCLASSES
) {
2359 static const int furnsyms
[] = {
2360 S_upstair
, S_upstair
, S_dnstair
, S_dnstair
,
2361 S_altar
, S_grave
, S_throne
, S_sink
2364 ap_type
= M_AP_FURNITURE
;
2365 appear
= ROLL_FROM(furnsyms
);
2367 ap_type
= M_AP_OBJECT
;
2368 if (s_sym
== S_MIMIC_DEF
) {
2369 appear
= STRANGE_OBJECT
;
2370 } else if (s_sym
== COIN_CLASS
) {
2371 appear
= GOLD_PIECE
;
2373 otmp
= mkobj((char) s_sym
, FALSE
);
2374 appear
= otmp
->otyp
;
2375 /* make sure container contents are free'ed */
2376 obfree(otmp
, (struct obj
*) 0);
2380 mtmp
->m_ap_type
= ap_type
;
2381 mtmp
->mappearance
= appear
;
2382 /* when appearing as an object based on a monster type, pick a shape */
2383 if (ap_type
== M_AP_OBJECT
2384 && (appear
== STATUE
|| appear
== FIGURINE
2385 || appear
== CORPSE
|| appear
== EGG
|| appear
== TIN
)) {
2386 int mndx
= rndmonnum(),
2387 nocorpse_ndx
= (svm
.mvitals
[mndx
].mvflags
& G_NOCORPSE
) != 0;
2389 if (appear
== CORPSE
&& nocorpse_ndx
)
2390 mndx
= rn1(PM_WIZARD
- PM_ARCHEOLOGIST
+ 1, PM_ARCHEOLOGIST
);
2391 else if ((appear
== EGG
&& !can_be_hatched(mndx
))
2392 || (appear
== TIN
&& nocorpse_ndx
))
2393 mndx
= NON_PM
; /* revert to generic egg or empty tin */
2396 MCORPSENM(mtmp
) = mndx
;
2397 } else if (ap_type
== M_AP_OBJECT
&& appear
== SLIME_MOLD
) {
2399 MCORPSENM(mtmp
) = svc
.context
.current_fruit
;
2400 /* if no objects of this fruit type have been created yet,
2401 context.current_fruit is available for re-use when the player
2402 assigns a new fruit name; override that--having a mimic as the
2403 current_fruit is equivalent to creating an instance of that
2404 fruit (no-op if a fruit of this type has actually been made) */
2405 flags
.made_fruit
= TRUE
;
2406 } else if (ap_type
== M_AP_FURNITURE
&& appear
== S_altar
) {
2407 int algn
= rn2(3) - 1; /* -1 (A_Cha) or 0 (A_Neu) or +1 (A_Law) */
2410 MCORPSENM(mtmp
) = (Inhell
&& rn2(3)) ? AM_NONE
: Align2amask(algn
);
2411 } else if (has_mcorpsenm(mtmp
)) {
2412 /* don't retain stale value from a previously mimicked shape */
2413 MCORPSENM(mtmp
) = NON_PM
;
2416 if (does_block(mx
, my
, &levl
[mx
][my
]))
2417 block_point(mx
, my
);
2420 /* release monster from bag of tricks; return number of monsters created */
2424 boolean tipping
, /* caller emptying entirely; affects shop handling */
2425 int *seencount
) /* secondary output */
2429 if (!bag
|| bag
->otyp
!= BAG_OF_TRICKS
) {
2430 impossible("bad bag o' tricks");
2431 } else if (bag
->spe
< 1) {
2432 /* if tipping known empty bag, give normal empty container message */
2433 pline1((tipping
&& bag
->cknown
) ? "It's empty." : nothing_happens
);
2434 /* now known to be empty if sufficiently discovered */
2435 if (bag
->dknown
&& objects
[bag
->otyp
].oc_name_known
) {
2437 update_inventory(); /* for perm_invent */
2441 int creatcnt
= 1, seecount
= 0;
2443 consume_obj_charge(bag
, !tipping
);
2448 mtmp
= makemon((struct permonst
*) 0, u
.ux
, u
.uy
, NO_MM_FLAGS
);
2451 if ((canseemon(mtmp
) && (M_AP_TYPE(mtmp
) == M_AP_NOTHING
2452 || M_AP_TYPE(mtmp
) == M_AP_MONSTER
))
2456 } while (--creatcnt
> 0);
2459 *seencount
+= seecount
;
2461 makeknown(BAG_OF_TRICKS
);
2462 update_inventory(); /* for perm_invent */
2464 } else if (!tipping
) {
2465 pline1(!moncount
? nothing_happens
: nothing_seems_to_happen
);
2471 /* create some or all remaining erinyes around the player */
2473 summon_furies(int limit
) /* number to create, or 0 to create until extinct */
2476 while (mk_gen_ok(PM_ERINYS
, G_GONE
, 0U) && (i
< limit
|| !limit
)) {
2477 makemon(&mons
[PM_ERINYS
], u
.ux
, u
.uy
, MM_ADJACENTOK
| MM_NOWAIT
);