]> granicus.if.org Git - nethack/commitdiff
mons[0]
authorPatR <rankin@nethack.org>
Sun, 16 Jul 2017 22:28:44 +0000 (15:28 -0700)
committerPatR <rankin@nethack.org>
Sun, 16 Jul 2017 22:28:44 +0000 (15:28 -0700)
Alex mentioned that loops over mons[] were starting at [0], which
should be [LOW_PM] instead.  I only found two, and the mvitals[] one
was benign.  The special level one might have been too, depending
upon spec_lev's thoroughness--I didn't attempt to check.

Once upon a time there was a possibility of moving 'playermon' from
a separate variable to mons[0], so LOW_PM became the index of the
first valid monster.  Instead, 'playermon' went away altogether.
LOW_PM (and NON_PM) could go away too, but I don't see how reverting
to hardcoded 0 and -1 would be an improvement.  We have enough
problems as it is with "giant ant" turning up in unexpected places
because someone used 0 instead of NON_PM to mean "none of the above".

src/allmain.c
src/sp_lev.c

index 2b006bf634e25b538419a289e6889b911d4395ee..fa9e03ac69a0963714bc23e57a0ae2163e96188b 100644 (file)
@@ -578,7 +578,7 @@ newgame()
     context.tribute.enabled = TRUE;   /* turn on 3.6 tributes    */
     context.tribute.tributesz = sizeof(struct tribute_info);
 
-    for (i = 0; i < NUMMONS; i++)
+    for (i = LOW_PM; i < NUMMONS; i++)
         mvitals[i].mvflags = mons[i].geno & G_NOCORPSE;
 
     init_objects(); /* must be before u_init() */
index 179d45fa3d8368709414b0451bbf483ae6173016..9ef1dcf46637f43b256fe6e78faebb6f0df23479 100644 (file)
@@ -3050,6 +3050,7 @@ struct sp_coder *coder;
     while ((nparams++ < (SP_O_V_END + 1)) && (OV_typ(varparam) == SPOVAR_INT)
            && (OV_i(varparam) >= 0) && (OV_i(varparam) < SP_O_V_END)) {
         struct opvar *parm;
+
         OV_pop(parm);
         switch (OV_i(varparam)) {
         case SP_O_V_NAME:
@@ -3061,11 +3062,12 @@ struct sp_coder *coder;
                 char monclass = SP_MONST_CLASS(OV_i(parm));
                 int monid = SP_MONST_PM(OV_i(parm));
 
-                if (monid >= 0 && monid < NUMMONS) {
+                if (monid >= LOW_PM && monid < NUMMONS) {
                     tmpobj.corpsenm = monid;
                     break; /* we're done! */
                 } else {
                     struct permonst *pm = (struct permonst *) 0;
+
                     if (def_char_to_monclass(monclass) != MAXMCLASSES) {
                         pm = mkclass(def_char_to_monclass(monclass), G_NOGEN);
                     } else {