From f84538aa8ceb43eb300c5805ac21a9b7cf5789b6 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 21 Jun 2021 10:06:46 +0300 Subject: [PATCH] Dehardcode number of glass gems --- src/mon.c | 3 ++- src/mthrowu.c | 2 +- src/objnam.c | 2 +- util/makedefs.c | 17 ++++++++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/mon.c b/src/mon.c index 9cd1c28f3..0b5d3da91 100644 --- 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: diff --git a/src/mthrowu.c b/src/mthrowu.c index 6142c10a7..93f10406f 100644 --- a/src/mthrowu.c +++ b/src/mthrowu.c @@ -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)); diff --git a/src/objnam.c b/src/objnam.c index 64a8933a0..790fc385d 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -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 diff --git a/util/makedefs.c b/util/makedefs.c index 733217498..8afa8b14e 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -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);