]> granicus.if.org Git - nethack/commitdiff
fix #H4246 - nasty() bugs
authorPatR <rankin@nethack.org>
Sat, 20 Feb 2016 02:15:45 +0000 (18:15 -0800)
committerPatR <rankin@nethack.org>
Sat, 20 Feb 2016 02:15:45 +0000 (18:15 -0800)
In theory nasty() could summon 200 critters at a time, although the
chance seems fairly remote.  But it was biased towards having lawfuls
summon more critters than others since there are fewer lawfuls in the
nasties[] list.  This puts a cap of 8 successful makemon() calls,
enough to completely surround the hero.  More than 8 monsters can be
generated, if any of the makemon() calls produces a group.  (I think
fire giants are the only thing in nasties[] that ever come in groups.)
It's still biased toward lawful summoners trying more times hoping to
produce a lawful creature and generating chaotic ones in the process.

The bug report also thought there was some problem between chaotic
and unaligned or with the Wizard, but unaligned is treated as if it
were chaotic (due to use of sgn() in the two or three places where
alignment type is manipulated) so that isn't an actual problem.

doc/fixes36.1
src/wizard.c

index fefa83ac66de80cd225f62108544408ca80ef7d6..8ffcdd9c3b8830a78ff49d8a1a3a58523185c658 100644 (file)
@@ -163,6 +163,8 @@ using 'R' on armor would bypass some restrictions imposed by 'T' (inner layer
 when examining hidden monsters (probing, persistent monster detection), tell
        how they're hidden (under an object, on the ceiling, etc)
 some quest text corrections
+use a much tighter upper bound when summoning nasties; old method could
+       theoretically create 200 critters at a time
 
 
 Platform- and/or Interface-Specific Fixes
index bb394349f7f513d2cb89c5ce897e06bc66009ede..d5237a6d9ef2a0d2b25e8327c0f44e0c60b71354 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 wizard.c        $NHDT-Date: 1446078768 2015/10/29 00:32:48 $  $NHDT-Branch: master $:$NHDT-Revision: 1.42 $ */
+/* NetHack 3.6 wizard.c        $NHDT-Date: 1455934524 2016/02/20 02:15:24 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.46 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -505,17 +505,19 @@ pick_nasty()
     return res;
 }
 
-/* create some nasty monsters, aligned or neutral with the caster */
-/* a null caster defaults to a chaotic caster (e.g. the wizard) */
+/* create some nasty monsters, aligned with the caster or neutral; chaotic
+   and unaligned are treated as equivalent; default caster is chaotic */
 int
 nasty(mcast)
 struct monst *mcast;
 {
     register struct monst *mtmp;
-    register int i, j, tmp;
+    register int i, j;
     int castalign = (mcast ? sgn(mcast->data->maligntyp) : -1);
     coord bypos;
-    int count, census;
+    int count, census, tmp;
+
+#define MAXNASTIES 8 /* more than this can be created if any come in groups */
 
     /* some candidates may be created in groups, so simple count
        of non-null makemon() return is inadequate */
@@ -526,8 +528,7 @@ struct monst *mcast;
     } else {
         count = 0;
         tmp = (u.ulevel > 3) ? u.ulevel / 3 : 1; /* just in case -- rph */
-        /* if we don't have a casting monster, the nasties appear around you
-         */
+        /* if we don't have a casting monster, nasties appear around you */
         bypos.x = u.ux;
         bypos.y = u.uy;
         for (i = rnd(tmp); i > 0; --i)
@@ -542,9 +543,8 @@ struct monst *mcast;
                 } while (mcast && attacktype(&mons[makeindex], AT_MAGC)
                          && monstr[makeindex] >= monstr[mcast->mnum]);
                 /* do this after picking the monster to place */
-                if (mcast
-                    && !enexto(&bypos, mcast->mux, mcast->muy,
-                               &mons[makeindex]))
+                if (mcast && !enexto(&bypos, mcast->mux, mcast->muy,
+                                     &mons[makeindex]))
                     continue;
                 if ((mtmp = makemon(&mons[makeindex], bypos.x, bypos.y,
                                     NO_MM_FLAGS)) != 0) {
@@ -554,8 +554,8 @@ struct monst *mcast;
                     mtmp = makemon((struct permonst *) 0, bypos.x, bypos.y,
                                    NO_MM_FLAGS);
                 if (mtmp) {
-                    count++;
-                    if (mtmp->data->maligntyp == 0
+                    if (++count >= MAXNASTIES
+                        || mtmp->data->maligntyp == 0
                         || sgn(mtmp->data->maligntyp) == castalign)
                         break;
                 }