MCPcopy Index your code
hub / github.com/NetHack/NetHack / nasty

Function nasty

src/wizard.c:590–711  ·  view source on GitHub ↗

create some nasty monsters, aligned with the caster or neutral; chaotic and unaligned are treated as equivalent; if summoner is Null, this is for late-game harassment (after the Wizard has been killed at least once or the invocation ritual has been performed), in which case we treat 'summoner' as neutral, since that will produce the greatest number of creatures on average (in 3.6.0

Source from the content-addressed store, hash-verified

588 creatures on average (in 3.6.0 and earlier, Null was treated as chaotic);
589 returns the number of monsters created */
590int
591nasty(struct monst *summoner)
592{
593 struct monst *mtmp;
594 coord bypos;
595 int i, j, count, census, tmp, makeindex,
596 s_cls, m_cls, difcap, trylimit, castalign;
597 /* when a monster casts the "summon nasties" spell, it gives feedback;
598 when random post-Wizard harassment casts that, we give feedback */
599 unsigned mmflags = summoner ? MM_NOMSG : NO_MM_FLAGS;
600
601#define MAXNASTIES 10 /* more than this can be created */
602
603 /* some candidates may be created in groups, so simple count
604 of non-null makemon() return is inadequate */
605 census = monster_census(FALSE);
606
607 if (!rn2(10) && Inhell) {
608 /* this might summon a demon prince or lord */
609 count = msummon((struct monst *) 0); /* summons like WoY */
610 } else {
611 count = 0;
612 s_cls = summoner ? summoner->data->mlet : 0;
613 difcap = summoner ? summoner->data->difficulty : 0; /* spellcasters */
614 castalign = summoner ? sgn(summoner->data->maligntyp) : 0;
615 tmp = (u.ulevel > 3) ? u.ulevel / 3 : 1;
616 /* if we don't have a casting monster, nasties appear around hero,
617 otherwise they'll appear around spot summoner thinks she's at */
618 bypos.x = u.ux;
619 bypos.y = u.uy;
620 for (i = rnd(tmp); i > 0 && count < MAXNASTIES; --i) {
621 /* Of the 44 nasties[], 10 are lawful, 14 are chaotic,
622 * and 20 are neutral. [These numbers are up date for
623 * 5.0.0; the ones in the next paragraph are not....]
624 *
625 * Neutral caster, used for late-game harassment,
626 * has 18/42 chance to stop the inner loop on each
627 * critter, 24/42 chance for another iteration.
628 * Lawful caster has 28/42 chance to stop unless the
629 * summoner is an angel or demon, in which case the
630 * chance is 26/42.
631 * Chaotic or unaligned caster has 32/42 chance to
632 * stop, so will summon fewer creatures on average.
633 *
634 * The outer loop potentially gives chaotic/unaligned
635 * a chance to even things up since others will hit
636 * MAXNASTIES sooner, but its number of iterations is
637 * randomized so it won't always do so.
638 */
639 for (j = 0; j < 20; j++) {
640 /* Don't create more spellcasters of the monster's level or
641 * higher--avoids chain summoners filling up the level.
642 */
643 trylimit = 10 + 1; /* 10 tries */
644 do {
645 if (!--trylimit)
646 goto nextj; /* break this loop, continue outer one */
647 makeindex = pick_nasty(difcap);

Callers 2

mcast_summon_monsFunction · 0.85
interveneFunction · 0.85

Calls 11

monster_censusFunction · 0.85
rn2Function · 0.85
msummonFunction · 0.85
sgnFunction · 0.85
rndFunction · 0.85
pick_nastyFunction · 0.85
attacktypeFunction · 0.85
enextoFunction · 0.85
makemonFunction · 0.85
set_malignFunction · 0.85
unmakemonFunction · 0.85

Tested by

no test coverage detected