]> granicus.if.org Git - nethack/commitdiff
msummon,nasty result counts (trunk only)
authornethack.rankin <nethack.rankin>
Mon, 16 Apr 2007 03:58:30 +0000 (03:58 +0000)
committernethack.rankin <nethack.rankin>
Mon, 16 Apr 2007 03:58:30 +0000 (03:58 +0000)
     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.

doc/fixes35.0
include/extern.h
src/minion.c
src/wizard.c

index 0c6e08b628a4d86b3690658b5d174186f2e8e6c3..171122087f7b401538863705e1335d9e6a1ac16b 100644 (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
index 557784c8f5e0bfcdeeb970ba08159028b03059f1..2f595fb994f2f769402ddc39555392d36f9c58c3 100644 (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 *));
index c48c4eb4871e26030a6b302e037437a8228d8b1c..c56f8d3b1c481b9ed88be5f67142e1c9d7b8d6c6 100644 (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;
 }
 
index 71136e2cb7695acc44efd354f538258c36f0f3d4..94ebeacf8d68996be1f31e3abb6593160b82ece2 100644 (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;
 }