diff --git a/include/decl.h b/include/decl.h index c8ad733f2..0cac00374 100644 --- a/include/decl.h +++ b/include/decl.h @@ -529,11 +529,6 @@ struct entity { int ex, ey; }; -/* these probably ought to be generated by makedefs, like LAST_GEM */ -#define FIRST_GEM DILITHIUM_CRYSTAL -#define FIRST_AMULET AMULET_OF_ESP -#define LAST_AMULET AMULET_OF_YENDOR - struct valuable_data { long count; int typ; @@ -651,7 +646,7 @@ struct repo { /* repossession context */ #define NUM_ROLES (13) struct role_filter { - boolean roles[NUM_ROLES+1]; + boolean roles[NUM_ROLES + 1]; short mask; }; @@ -977,7 +972,8 @@ struct instance_globals_g { const char *gate_str; /* end.c */ - struct valuable_data gems[LAST_GEM + 1 - FIRST_GEM + 1]; /* +1 for glass */ + /* 1st +1: subtracting first from last, 2nd +1: one slot for all glass */ + struct valuable_data gems[LAST_REAL_GEM + 1 - FIRST_REAL_GEM + 1]; /* invent.c */ long glyph_reset_timestamp; diff --git a/include/objclass.h b/include/objclass.h index 2eccd95fc..be7ec92e2 100644 --- a/include/objclass.h +++ b/include/objclass.h @@ -171,9 +171,11 @@ enum objects_nums { }; enum misc_object_nums { - LAST_GEM = (JADE), - NUM_GLASS_GEMS = ((LUCKSTONE - JADE) - 1), - MAXSPELL = ((SPE_BOOK_OF_THE_DEAD - SCR_BLANK_PAPER) + 1) + NUM_GLASS_GEMS = (LAST_GLASS_GEM - FIRST_GLASS_GEM + 1), + /* 1st +1: last-first subtraction; 2nd +1: extra empty spl_book[] slot; + currently LAST_SPELL includes blank, novel, and DeadBook so this + overallocates when used to define spl_book[] array */ + MAXSPELL = (LAST_SPELL + 1 - FIRST_SPELL + 1), }; extern NEARDATA struct objclass objects[NUM_OBJECTS + 1]; diff --git a/include/objects.h b/include/objects.h index cc2a72bd6..14200c487 100644 --- a/include/objects.h +++ b/include/objects.h @@ -32,6 +32,7 @@ #define OBJ(name,desc) name, desc #define OBJECT(obj,bits,prp,sym,prob,dly,wt, \ cost,sdam,ldam,oc1,oc2,nut,color,sn) { obj } +#define MARKER(tag,sn) /*empty*/ #elif defined(OBJECTS_INIT) #define COLOR_FIELD(X) X, @@ -45,18 +46,21 @@ cost,sdam,ldam,oc1,oc2,nut,color,sn) \ { 0, 0, (char *) 0, bits, prp, sym, dly, COLOR_FIELD(color) prob, wt, \ cost, sdam, ldam, oc1, oc2, nut } +#define MARKER(tag,sn) /*empty*/ #elif defined(OBJECTS_ENUM) #define OBJ(name,desc) #define OBJECT(obj,bits,prp,sym,prob,dly,wt, \ cost,sdam,ldam,oc1,oc2,nut,color,sn) \ sn +#define MARKER(tag,sn) tag = sn, #elif defined(DUMP_ENUMS) #define OBJ(name,desc) #define OBJECT(obj,bits,prp,sym,prob,dly,wt, \ cost,sdam,ldam,oc1,oc2,nut,color,sn) \ { sn, #sn } +#define MARKER(tag,sn) { tag, #sn }, #else #error Unproductive inclusion of objects.h @@ -767,6 +771,7 @@ RING("protection from shape changers", "shiny", power, AMULET_CLASS, prob, 0, 20, 150, 0, 0, 0, 0, 20, HI_METAL, sn) AMULET("amulet of ESP", "circular", TELEPAT, 120, AMULET_OF_ESP), +MARKER(FIRST_AMULET, AMULET_OF_ESP) AMULET("amulet of life saving", "spherical", LIFESAVED, 75, AMULET_OF_LIFE_SAVING), AMULET("amulet of strangulation", "oval", STRANGLED, 115, @@ -804,6 +809,7 @@ OBJECT(OBJ("Amulet of Yendor", /* note: description == name */ BITS(0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, MITHRIL), 0, AMULET_CLASS, 0, 0, 20, 30000, 0, 0, 0, 0, 20, HI_METAL, AMULET_OF_YENDOR), +MARKER(LAST_AMULET, AMULET_OF_YENDOR) #undef AMULET /* tools ... */ @@ -1204,6 +1210,7 @@ SCROLL("blank paper", "unlabeled", 0, 28, 60, SCR_BLANK_PAPER), #define PAPER LEATHER /* override enum for use in SPELL() expansion */ SPELL("dig", "parchment", P_MATTER_SPELL, 20, 6, 5, 1, RAY, HI_LEATHER, SPE_DIG), +MARKER(FIRST_SPELL, SPE_DIG) /* magic missile ... finger of death must be in this order; see buzz() */ SPELL("magic missile", "vellum", P_ATTACK_SPELL, 45, 2, 2, 1, RAY, HI_LEATHER, SPE_MAGIC_MISSILE), @@ -1329,7 +1336,8 @@ SPELL("freeze sphere", "hardcover", #endif /* books with fixed descriptions */ -SPELL("blank paper", "plain", P_NONE, 18, 0, 0, 0, 0, HI_PAPER, SPE_BLANK_PAPER), +SPELL("blank paper", "plain", P_NONE, 18, 0, 0, 0, 0, HI_PAPER, + SPE_BLANK_PAPER), /* tribute book for 3.6 */ OBJECT(OBJ("novel", "paperback"), BITS(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, P_NONE, PAPER), @@ -1340,6 +1348,10 @@ OBJECT(OBJ("Book of the Dead", "papyrus"), BITS(0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, P_NONE, PAPER), 0, SPBOOK_CLASS, 0, 0, 20, 10000, 0, 0, 0, 7, 20, HI_PAPER, SPE_BOOK_OF_THE_DEAD), +/* LAST_SPELL is used to compute MAXSPELL and should probably be + SPE_BLANK_PAPER-1 since there's no need for spl_book[] slots for + blank, novel, and Book of the Dead */ +MARKER(LAST_SPELL, SPE_BOOK_OF_THE_DEAD) #undef SPELL /* wands ... */ @@ -1424,6 +1436,7 @@ COIN("gold piece", 1000, GOLD, 1, GOLD_PIECE), 0, GEM_CLASS, prob, 0, wt, gval, sdam, ldam, 0, 0, nutr, color, sn) GEM("dilithium crystal", "white", 2, 1, 4500, 15, 5, GEMSTONE, CLR_WHITE, DILITHIUM_CRYSTAL), +MARKER(FIRST_REAL_GEM, DILITHIUM_CRYSTAL) GEM("diamond", "white", 3, 1, 4000, 15, 10, GEMSTONE, CLR_WHITE, DIAMOND), GEM("ruby", "red", 4, 1, 3500, 15, 9, GEMSTONE, CLR_RED, @@ -1466,8 +1479,10 @@ GEM("agate", "orange", 12, 1, 200, 15, 6, GEMSTONE, CLR_ORANGE, AGATE), GEM("jade", "green", 10, 1, 300, 15, 6, GEMSTONE, CLR_GREEN, JADE), +MARKER(LAST_REAL_GEM, JADE) GEM("worthless piece of white glass", "white", 77, 1, 0, 6, 5, GLASS, CLR_WHITE, WORTHLESS_WHITE_GLASS), +MARKER(FIRST_GLASS_GEM, WORTHLESS_WHITE_GLASS) GEM("worthless piece of blue glass", "blue", 77, 1, 0, 6, 5, GLASS, CLR_BLUE, WORTHLESS_BLUE_GLASS), GEM("worthless piece of red glass", "red", @@ -1484,6 +1499,7 @@ GEM("worthless piece of green glass", "green", 77, 1, 0, 6, 5, GLASS, CLR_GREEN, WORTHLESS_GREEN_GLASS), GEM("worthless piece of violet glass", "violet", 77, 1, 0, 6, 5, GLASS, CLR_MAGENTA, WORTHLESS_VIOLET_GLASS), +MARKER(LAST_GLASS_GEM, WORTHLESS_VIOLET_GLASS) /* Placement note: there is a wishable subrange for * "gray stones" in the o_ranges[] array in objnam.c @@ -1548,6 +1564,7 @@ OBJECT(OBJ(NoDes, NoDes), #undef OBJ #undef OBJECT +#undef MARKER #undef HARDGEM #undef NoDes diff --git a/src/allmain.c b/src/allmain.c index e3d722003..72a898958 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -1055,9 +1055,16 @@ dump_enums(void) "monnums", "objects_nums" , "misc_object_nums" }; static const struct enum_dump omdump[] = { - { LAST_GEM, "LAST_GEM" }, - { NUM_GLASS_GEMS, "NUM_GLASS_GEMS" }, + { FIRST_AMULET, "FIRST_AMULET" }, + { LAST_AMULET, "LAST_AMULET" }, + { FIRST_SPELL, "FIRST_SPELL" }, + { LAST_SPELL, "LAST_SPELL" }, { MAXSPELL, "MAXSPELL" }, + { FIRST_REAL_GEM, "FIRST_REAL_GEM" }, + { LAST_REAL_GEM, "LAST_REAL_GEM" }, + { FIRST_GLASS_GEM, "FIRST_GLASS_GEM" }, + { LAST_GLASS_GEM, "LAST_GLASS_GEM" }, + { NUM_GLASS_GEMS, "NUM_GLASS_GEMS" }, }; static const struct enum_dump *const ed[NUM_ENUM_DUMPS] = { monsdump, objdump, omdump diff --git a/src/end.c b/src/end.c index 8f6b38678..7f61562f8 100644 --- a/src/end.c +++ b/src/end.c @@ -979,8 +979,9 @@ get_valuables(struct obj *list) /* inventory or container contents */ ga.amulets[i].typ = obj->otyp; } else ga.amulets[i].count += obj->quan; /* always adds one */ - } else if (obj->oclass == GEM_CLASS && obj->otyp < LUCKSTONE) { - i = min(obj->otyp, LAST_GEM + 1) - FIRST_GEM; + } else if (obj->oclass == GEM_CLASS && obj->otyp <= LAST_GLASS_GEM) { + /* last+1: combine all glass gems into one slot */ + i = min(obj->otyp, LAST_REAL_GEM + 1) - FIRST_REAL_GEM; if (!gg.gems[i].count) { gg.gems[i].count = obj->quan; gg.gems[i].typ = obj->otyp; @@ -1613,7 +1614,8 @@ really_done(int how) if (count == 0L) continue; - if (objects[typ].oc_class != GEM_CLASS || typ <= LAST_GEM) { + if (objects[typ].oc_class != GEM_CLASS + || typ <= LAST_REAL_GEM) { otmp = mksobj(typ, FALSE, FALSE); discover_object(otmp->otyp, TRUE, FALSE); otmp->known = 1; /* for fake amulets */ diff --git a/src/mon.c b/src/mon.c index 9ec08fdac..48d5d7d47 100644 --- a/src/mon.c +++ b/src/mon.c @@ -582,7 +582,7 @@ 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(NUM_GLASS_GEMS)), + obj = mksobj_at(FIRST_GLASS_GEM + rn2(NUM_GLASS_GEMS), x, y, TRUE, FALSE); free_mgivenname(mtmp); break; diff --git a/src/mthrowu.c b/src/mthrowu.c index 133b0014c..8bd26fb7f 100644 --- a/src/mthrowu.c +++ b/src/mthrowu.c @@ -501,12 +501,11 @@ ucatchgem( struct monst *mon) { /* won't catch rock or gray stone; catch (then drop) worthless glass */ - if (gem->otyp <= LAST_GEM + NUM_GLASS_GEMS - && is_unicorn(gy.youmonst.data)) { + if (gem->otyp <= LAST_GLASS_GEM && is_unicorn(gy.youmonst.data)) { char *gem_xname = xname(gem), *mon_s_name = s_suffix(mon_nam(mon)); - if (gem->otyp > LAST_GEM) { + if (gem->otyp >= FIRST_GLASS_GEM) { You("catch the %s.", gem_xname); You("are not interested in %s junk.", mon_s_name); makeknown(gem->otyp); diff --git a/src/o_init.c b/src/o_init.c index 502069cd5..1b88b80a3 100644 --- a/src/o_init.c +++ b/src/o_init.c @@ -56,14 +56,14 @@ setgemprobs(d_level* dlev) for (j = 0; j < 9 - lev / 3; j++) objects[first + j].oc_prob = 0; first += j; - if (first > LAST_GEM || objects[first].oc_class != GEM_CLASS + if (first > LAST_REAL_GEM || objects[first].oc_class != GEM_CLASS || OBJ_NAME(objects[first]) == (char *) 0) { raw_printf("Not enough gems? - first=%d j=%d LAST_GEM=%d", first, j, - LAST_GEM); + LAST_REAL_GEM); wait_synch(); } - for (j = first; j <= LAST_GEM; j++) - objects[j].oc_prob = (171 + j - first) / (LAST_GEM + 1 - first); + for (j = first; j <= LAST_REAL_GEM; j++) + objects[j].oc_prob = (171 + j - first) / (LAST_REAL_GEM + 1 - first); /* recompute GEM_CLASS total oc_prob - including rocks/stones */ for (j = gb.bases[GEM_CLASS]; j < gb.bases[GEM_CLASS + 1]; j++) diff --git a/src/objnam.c b/src/objnam.c index b857286d4..db089f7c4 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -73,19 +73,21 @@ struct Jitem { && typ != SAPPHIRE && typ != BLACK_OPAL && typ != EMERALD \ && typ != OPAL))) -static struct Jitem Japanese_items[] = { { SHORT_SWORD, "wakizashi" }, - { BROADSWORD, "ninja-to" }, - { FLAIL, "nunchaku" }, - { GLAIVE, "naginata" }, - { LOCK_PICK, "osaku" }, - { WOODEN_HARP, "koto" }, - { KNIFE, "shito" }, - { PLATE_MAIL, "tanko" }, - { HELMET, "kabuto" }, - { LEATHER_GLOVES, "yugake" }, - { FOOD_RATION, "gunyoki" }, - { POT_BOOZE, "sake" }, - { 0, "" } }; +static struct Jitem Japanese_items[] = { + { SHORT_SWORD, "wakizashi" }, + { BROADSWORD, "ninja-to" }, + { FLAIL, "nunchaku" }, + { GLAIVE, "naginata" }, + { LOCK_PICK, "osaku" }, + { WOODEN_HARP, "koto" }, + { KNIFE, "shito" }, + { PLATE_MAIL, "tanko" }, + { HELMET, "kabuto" }, + { LEATHER_GLOVES, "yugake" }, + { FOOD_RATION, "gunyoki" }, + { POT_BOOZE, "sake" }, + { 0, "" } +}; static const char *Japanese_item_name(int i); @@ -4264,7 +4266,7 @@ readobjnam_postparse2(struct _readobjnam_data *d) s += 9; if (!strcmpi(s, "glass")) { /* choose random color */ /* 9 different kinds */ - d->typ = LAST_GEM + rnd(NUM_GLASS_GEMS); + d->typ = FIRST_GLASS_GEM + rn2(NUM_GLASS_GEMS); if (objects[d->typ].oc_class == GEM_CLASS) return 2; /*goto typfnd;*/ else @@ -4292,7 +4294,7 @@ readobjnam_postparse3(struct _readobjnam_data *d) /* check real names of gems first */ if (!d->oclass && d->actualn) { - for (i = gb.bases[GEM_CLASS]; i <= LAST_GEM; i++) { + for (i = gb.bases[GEM_CLASS]; i <= LAST_REAL_GEM; i++) { register const char *zn; if ((zn = OBJ_NAME(objects[i])) != 0 && !strcmpi(d->actualn, zn)) { diff --git a/src/shk.c b/src/shk.c index 2f7606fb2..73d563d80 100644 --- a/src/shk.c +++ b/src/shk.c @@ -2201,32 +2201,32 @@ get_cost( (((int) ubirthday % obj->otyp) >= obj->otyp / 2); /* all gems are priced high - real or not */ - switch (obj->otyp - LAST_GEM) { - case 1: /* white */ + switch (obj->otyp - FIRST_GLASS_GEM) { + case 0: /* white */ i = pseudorand ? DIAMOND : OPAL; break; - case 2: /* blue */ + case 1: /* blue */ i = pseudorand ? SAPPHIRE : AQUAMARINE; break; - case 3: /* red */ + case 2: /* red */ i = pseudorand ? RUBY : JASPER; break; - case 4: /* yellowish brown */ + case 3: /* yellowish brown */ i = pseudorand ? AMBER : TOPAZ; break; - case 5: /* orange */ + case 4: /* orange */ i = pseudorand ? JACINTH : AGATE; break; - case 6: /* yellow */ + case 5: /* yellow */ i = pseudorand ? CITRINE : CHRYSOBERYL; break; - case 7: /* black */ + case 6: /* black */ i = pseudorand ? BLACK_OPAL : JET; break; - case 8: /* green */ + case 7: /* green */ i = pseudorand ? EMERALD : JADE; break; - case 9: /* violet */ + case 8: /* violet */ i = pseudorand ? AMETHYST : FLUORITE; break; default: @@ -2458,7 +2458,7 @@ set_cost(register struct obj* obj, register struct monst* shkp) /* different shop keepers give different prices */ if (objects[obj->otyp].oc_material == GEMSTONE || objects[obj->otyp].oc_material == GLASS) { - tmp = ((obj->otyp - FIRST_GEM) % (6 - shkp->m_id % 3)); + tmp = ((obj->otyp - FIRST_REAL_GEM) % (6 - shkp->m_id % 3)); tmp = (tmp + 3) * obj->quan; divisor = 1L; }