]> granicus.if.org Git - nethack/commitdiff
Dehardcode number of glass gems
authorPasi Kallinen <paxed@alt.org>
Mon, 21 Jun 2021 07:06:46 +0000 (10:06 +0300)
committerPasi Kallinen <paxed@alt.org>
Mon, 21 Jun 2021 07:06:46 +0000 (10:06 +0300)
src/mon.c
src/mthrowu.c
src/objnam.c
util/makedefs.c

index 9cd1c28f303c8a8e0f8c29f595b14aa8f6b3fe1f..0b5d3da9117b4d01a2f7e0ee6e1bc56594c84449 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -572,7 +572,8 @@ make_corpse(struct monst *mtmp, unsigned int corpseflags)
     case PM_GLASS_GOLEM:
         num = d(2, 4); /* very low chance of creating all glass gems */
         while (num--)
-            obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE);
+            obj = mksobj_at((LAST_GEM + rnd(NUM_GLASS_GEMS)),
+                            x, y, TRUE, FALSE);
         free_mgivenname(mtmp);
         break;
     case PM_CLAY_GOLEM:
index 6142c10a7a62e36caa5e0931210911fb0f41720a..93f10406f5a0837b40542da01256cf16d19d667a 100644 (file)
@@ -556,7 +556,7 @@ m_throw(
                 nomul(0);
 
             if (singleobj->oclass == GEM_CLASS
-                && singleobj->otyp <= LAST_GEM + 9 /* 9 glass colors */
+                && singleobj->otyp <= LAST_GEM + NUM_GLASS_GEMS
                 && is_unicorn(g.youmonst.data)) {
                 if (singleobj->otyp > LAST_GEM) {
                     You("catch the %s.", xname(singleobj));
index 64a8933a07cd419d5244a636781048fd860c173e..790fc385d58265cf2f666a38b9eaffd405c4081b 100644 (file)
@@ -3956,7 +3956,7 @@ readobjnam_postparse2(struct _readobjnam_data *d)
             s += 9;
         if (!strcmpi(s, "glass")) { /* choose random color */
             /* 9 different kinds */
-            d->typ = LAST_GEM + rnd(9);
+            d->typ = LAST_GEM + rnd(NUM_GLASS_GEMS);
             if (objects[d->typ].oc_class == GEM_CLASS)
                 return 2; /*goto typfnd;*/
             else
index 73321749871088d403b504a3620a9abd0846659e..8afa8b14eb6b3afc7f19d90c5c13242affea27f3 100644 (file)
@@ -2018,6 +2018,8 @@ do_objs(void)
     int prefix = 0;
     char class = '\0';
     boolean sumerr = FALSE;
+    int n_glass_gems = 0;
+    int start_glass_gems = 0;
 
     filename[0] = '\0';
 #ifdef FILE_PREFIX
@@ -2091,6 +2093,14 @@ do_objs(void)
             if (objects[i].oc_material == GLASS) {
                 Fprintf(ofp, "/* #define\t%s\t%d */\n", objnam, i);
                 prefix = -1;
+                if (!n_glass_gems)
+                    start_glass_gems = i;
+                if (i != n_glass_gems + start_glass_gems) {
+                    Fprintf(stderr, "glass gems not sequential\n");
+                    (void) fflush(stderr);
+                    sumerr = TRUE;
+                }
+                n_glass_gems++;
                 break;
             }
             /*FALLTHRU*/
@@ -2112,15 +2122,20 @@ do_objs(void)
         prefix = 0;
 
         sum += objects[i].oc_prob;
+
+        if (sumerr)
+            break;
     }
 
     /* check last set of probabilities */
-    if (sum && sum != 1000) {
+    if (!sumerr && sum && sum != 1000) {
         Fprintf(stderr, "prob error for class %d (%d%%)", class, sum);
         (void) fflush(stderr);
         sumerr = TRUE;
     }
 
+    Fprintf(ofp, "\n");
+    Fprintf(ofp, "#define\tNUM_GLASS_GEMS\t%d\n", n_glass_gems);
     Fprintf(ofp, "#define\tLAST_GEM\t(JADE)\n");
     Fprintf(ofp, "#define\tMAXSPELL\t%d\n", nspell + 1);
     Fprintf(ofp, "#define\tNUM_OBJECTS\t%d\n", i);