msummon,nasty result counts (trunk only)

Reported in Dec'04 by <email deleted>, the
monster spell "summon nasties" could mistakenly give a message of "a
monster appears" instead of "monsters appear" when more that one monster
gets summoned.  Some of the candidate monsters for nasty() can produce a
group from makemon(), as can ones for msummon() which nasty() sometimes
calls in Gehennom.  Compare the number of monsters before and after the
creation attempt(s) instead of assuming makemon() creates one at a time.

     I don't know whether other routines face the same mis-count issue,
but I suspect there may be several.
This commit is contained in:
nethack.rankin
2007-04-16 03:58:30 +00:00
parent 2aa7cb189b
commit 2872c27e13
4 changed files with 34 additions and 4 deletions

View File

@@ -218,6 +218,7 @@ hero undergoing semi-controlled polymorph won't also undergo sex change
when doppelgangers taking on new shape don't specifically pick nasty monster
or role monster, bias the random form towards humanoid
salamanders can use green slime corpses to cure themselves of petrification
feedback about summoned monsters may use singular when it should use plural
Platform- and/or Interface-Specific Fixes

View File

@@ -1111,6 +1111,7 @@ E int FDECL(doseduce, (struct monst *));
E void FDECL(newemin, (struct monst *));
E void FDECL(free_emin, (struct monst *));
E int NDECL(monster_census);
E int FDECL(msummon, (struct monst *));
E void FDECL(summon_minion, (ALIGNTYP_P,BOOLEAN_P));
E int FDECL(demon_talk, (struct monst *));

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)minion.c 3.5 2006/12/04 */
/* SCCS Id: @(#)minion.c 3.5 2007/04/15 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -26,12 +26,26 @@ struct monst *mtmp;
mtmp->isminion = 0;
}
/* count the number of monsters on the level */
int
monster_census()
{
struct monst *mtmp;
int count = 0;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp)) continue;
++count;
}
return count;
}
int
msummon(mon) /* mon summons a monster */
struct monst *mon;
{
struct permonst *ptr;
int dtype = NON_PM, cnt = 0, result = 0;
int dtype = NON_PM, cnt = 0, result = 0, census;
aligntyp atyp;
struct monst *mtmp;
@@ -92,6 +106,10 @@ struct monst *mon;
if (dtype == NON_PM) return 0;
}
/* some candidates can generate a group of monsters, so simple
count of non-null makemon() result is not sufficient */
census = monster_census();
while (cnt > 0) {
mtmp = makemon(&mons[dtype], u.ux, u.uy, MM_EMIN);
if (mtmp) {
@@ -108,6 +126,10 @@ struct monst *mon;
}
cnt--;
}
/* how many monsters exist now compared to before? */
if (result) result = monster_census() - census;
return result;
}

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)wizard.c 3.5 2007/02/07 */
/* SCCS Id: @(#)wizard.c 3.5 2007/04/15 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -423,7 +423,11 @@ nasty(mcast)
register int i, j, tmp;
int castalign = (mcast ? sgn(mcast->data->maligntyp) : -1);
coord bypos;
int count;
int count, census;
/* some candidates may be created in groups, so simple count
of non-null makemon() return is inadequate */
census = monster_census();
if(!rn2(10) && Inhell) {
count = msummon((struct monst *) 0); /* summons like WoY */
@@ -463,6 +467,8 @@ nasty(mcast)
}
}
}
if (count) count = monster_census() - census;
return count;
}