split g into multiple structures

The consolidation of global variables from scattered source
files into decl.c and declared in decl.h was begun in 3.7.0.
Their placement in common files was done for centralized
initialization and potential re-initialization during a
"play again" scenario.

It wasn't really necessary for all of them to be housed in a
single huge structure to meet the "play again" requirement,
and the single huge structure has been a little unwieldy when
it comes to maintenance.

Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.

To make things easy for the developer, each variable is placed
into the struct corresponding to the starting letter of the variable.
That way, no lookup is required in order to know which struct houses
a particular variable, it is a simple match to the starting letter
for all the centralized global variables.

A global variable named 'amulets', would be found in ga.
    ga.amulets
     ^ ^
A global varable named 'move', would be found in gm.
    gm.moves
     ^ ^
A global variable named 'val_for_n_or_more' would be found in gv.
    gv.val_for_n_or_more
     ^ ^
A global variable named 'youmonst' would be found in gy.
    gy.youmonst
     ^ ^
This commit is contained in:
nhmall
2022-11-29 21:53:21 -05:00
parent e64ed2859d
commit 02a48aa8cf
193 changed files with 10764 additions and 10148 deletions

View File

@@ -287,7 +287,7 @@ obj_is_pname(struct obj* obj)
{
if (!obj->oartifact || !has_oname(obj))
return FALSE;
if (!g.program_state.gameover && !iflags.override_ID) {
if (!gp.program_state.gameover && !iflags.override_ID) {
if (not_fully_identified(obj))
return FALSE;
}
@@ -337,9 +337,9 @@ distant_name(
value; but the Eyes of the Overworld override blindness and
would let characters wearing them get obj->dknown set for
distant items, so the external flag was added */
++g.distantname;
++gd.distantname;
str = (*func)(obj);
--g.distantname;
--gd.distantname;
}
return str;
}
@@ -351,12 +351,12 @@ fruitname(
boolean juice) /* whether or not to append " juice" to the name */
{
char *buf = nextobuf();
const char *fruit_nam = strstri(g.pl_fruit, " of ");
const char *fruit_nam = strstri(gp.pl_fruit, " of ");
if (fruit_nam)
fruit_nam += 4; /* skip past " of " */
else
fruit_nam = g.pl_fruit; /* use it as is */
fruit_nam = gp.pl_fruit; /* use it as is */
Sprintf(buf, "%s%s", makesingular(fruit_nam), juice ? " juice" : "");
return buf;
@@ -368,7 +368,7 @@ fruit_from_indx(int indx)
{
struct fruit *f;
for (f = g.ffruit; f; f = f->nextf)
for (f = gf.ffruit; f; f = f->nextf)
if (f->fid == indx)
break;
return f;
@@ -391,7 +391,7 @@ fruit_from_name(
if (highest_fid)
*highest_fid = 0;
/* first try for an exact match */
for (f = g.ffruit; f; f = f->nextf)
for (f = gf.ffruit; f; f = f->nextf)
if (!strcmp(f->fname, fname))
return f;
else if (highest_fid && f->fid > *highest_fid)
@@ -402,7 +402,7 @@ fruit_from_name(
matches, not the first */
if (!exact) {
tentativef = 0;
for (f = g.ffruit; f; f = f->nextf) {
for (f = gf.ffruit; f; f = f->nextf) {
k = Strlen(f->fname);
if (!strncmp(f->fname, fname, k)
&& (!fname[k] || fname[k] == ' ')
@@ -415,7 +415,7 @@ fruit_from_name(
for exact match, that's trivial, but for prefix, it's hard */
if (!f) {
altfname = makesingular(fname);
for (f = g.ffruit; f; f = f->nextf) {
for (f = gf.ffruit; f; f = f->nextf) {
if (!strcmp(f->fname, altfname))
break;
}
@@ -426,7 +426,7 @@ fruit_from_name(
unsigned fname_k = Strlen(fname); /* length of assumed plural fname */
tentativef = 0;
for (f = g.ffruit; f; f = f->nextf) {
for (f = gf.ffruit; f; f = f->nextf) {
k = Strlen(f->fname);
/* reload fnamebuf[] each iteration in case it gets modified;
there's no need to recalculate fname_k */
@@ -463,7 +463,7 @@ reorder_fruit(boolean forward)
for (i = 0; i < k; ++i)
allfr[i] = (struct fruit *) 0;
for (f = g.ffruit; f; f = f->nextf) {
for (f = gf.ffruit; f; f = f->nextf) {
/* without sanity checking, this would reduce to 'allfr[f->fid]=f' */
j = f->fid;
if (j < 1 || j >= k) {
@@ -475,7 +475,7 @@ reorder_fruit(boolean forward)
}
allfr[j] = f;
}
g.ffruit = 0; /* reset linked list; we're rebuilding it from scratch */
gf.ffruit = 0; /* reset linked list; we're rebuilding it from scratch */
/* slot [0] will always be empty; must start 'i' at 1 to avoid
[k - i] being out of bounds during first iteration */
for (i = 1; i < k; ++i) {
@@ -483,8 +483,8 @@ reorder_fruit(boolean forward)
for backward ordering, go from low to high */
j = forward ? (k - i) : i;
if (allfr[j]) {
allfr[j]->nextf = g.ffruit;
g.ffruit = allfr[j];
allfr[j]->nextf = gf.ffruit;
gf.ffruit = allfr[j];
}
}
}
@@ -528,7 +528,7 @@ xname_flags(
*/
if (!nn && ocl->oc_uses_known && ocl->oc_unique)
obj->known = 0;
if (!Blind && !g.distantname)
if (!Blind && !gd.distantname)
obj->dknown = 1;
if (Role_if(PM_CLERIC))
obj->bknown = 1; /* avoid set_bknown() to bypass update_inventory() */
@@ -845,7 +845,7 @@ xname_flags(
}
/* maybe give some extra information which isn't shown during play */
if (g.program_state.gameover) {
if (gp.program_state.gameover) {
const char *lbl;
char tmpbuf[BUFSZ];
@@ -949,10 +949,10 @@ mshot_xname(struct obj* obj)
char tmpbuf[BUFSZ];
char *onm = xname(obj);
if (g.m_shot.n > 1 && g.m_shot.o == obj->otyp) {
if (gm.m_shot.n > 1 && gm.m_shot.o == obj->otyp) {
/* "the Nth arrow"; value will eventually be passed to an() or
The(), both of which correctly handle this "the " prefix */
Sprintf(tmpbuf, "the %d%s ", g.m_shot.i, ordin(g.m_shot.i));
Sprintf(tmpbuf, "the %d%s ", gm.m_shot.i, ordin(gm.m_shot.i));
onm = strprepend(onm, tmpbuf);
}
return onm;
@@ -1324,7 +1324,7 @@ doname_base(
Strcat(prefix, "stale ");
#endif
if (omndx >= LOW_PM
&& (known || (g.mvitals[omndx].mvflags & MV_KNOWS_EGG))) {
&& (known || (gm.mvitals[omndx].mvflags & MV_KNOWS_EGG))) {
Strcat(prefix, mons[omndx].pmnames[NEUTRAL]);
Strcat(prefix, " ");
if (obj->spe == 1)
@@ -1354,7 +1354,7 @@ doname_base(
: "unspecified gender");
}
if ((obj->owornmask & W_WEP) && !g.mrg_to_wielded) {
if ((obj->owornmask & W_WEP) && !gm.mrg_to_wielded) {
boolean twoweap_primary = (obj == uwep && u.twoweap),
tethered = (obj->otyp == AKLYS);
@@ -1383,11 +1383,11 @@ doname_base(
(twoweap_primary && !tethered) ? "wielded" : "weapon",
twoweap_primary ? "right " : "", hand_s);
if (!Blind) {
if (g.warn_obj_cnt && obj == uwep
if (gw.warn_obj_cnt && obj == uwep
&& (EWarn_of_mon & W_WEP) != 0L)
/* we know bp[] ends with ')'; overwrite that */
Sprintf(eos(bp) - 1, ", %s %s)",
glow_verb(g.warn_obj_cnt, TRUE),
glow_verb(gw.warn_obj_cnt, TRUE),
glow_color(obj->oartifact));
else if (obj->lamplit && artifact_light(obj))
/* as above, overwrite known closing paren */
@@ -1438,7 +1438,7 @@ doname_base(
bill might not be available yet while restore is in progress
(objects won't normally be formatted during that time, but if
'perm_invent' is enabled then they might be [not any more...]) */
if (iflags.suppress_price || g.program_state.restoring) {
if (iflags.suppress_price || gp.program_state.restoring) {
; /* don't attempt to obtain any shop pricing, even if 'with_price' */
} else if (is_unpaid(obj)) { /* in inventory or in container in invent */
long quotedprice = unpaid_cost(obj, TRUE);
@@ -3110,7 +3110,7 @@ rnd_otyp_by_wpnskill(schar skill)
int i, n = 0;
short otyp = STRANGE_OBJECT;
for (i = g.bases[WEAPON_CLASS];
for (i = gb.bases[WEAPON_CLASS];
i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++)
if (objects[i].oc_skill == skill) {
n++;
@@ -3118,7 +3118,7 @@ rnd_otyp_by_wpnskill(schar skill)
}
if (n > 0) {
n = rn2(n);
for (i = g.bases[WEAPON_CLASS];
for (i = gb.bases[WEAPON_CLASS];
i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++)
if (objects[i].oc_skill == skill)
if (--n < 0)
@@ -3150,8 +3150,8 @@ rnd_otyp_by_namedesc(
(void) memset((genericptr_t) validobjs, 0, sizeof validobjs);
if (oclass) {
lo = g.bases[(uchar) oclass];
hi = g.bases[(uchar) oclass + 1] - 1;
lo = gb.bases[(uchar) oclass];
hi = gb.bases[(uchar) oclass + 1] - 1;
} else {
lo = STRANGE_OBJECT + 1;
hi = NUM_OBJECTS - 1;
@@ -3248,7 +3248,7 @@ wizterrainwish(struct _readobjnam_data *d)
p = eos(bp);
if (!BSTRCMPI(bp, p - 8, "fountain")) {
lev->typ = FOUNTAIN;
g.level.flags.nfountains++;
gl.level.flags.nfountains++;
lev->looted = d->looted ? F_LOOTED : 0; /* overlays 'flags' */
lev->blessedftn = !strncmpi(bp, "magic ", 6);
pline("A %sfountain.", lev->blessedftn ? "magic " : "");
@@ -3260,7 +3260,7 @@ wizterrainwish(struct _readobjnam_data *d)
madeterrain = TRUE;
} else if (!BSTRCMPI(bp, p - 4, "sink")) {
lev->typ = SINK;
g.level.flags.nsinks++;
gl.level.flags.nsinks++;
lev->looted = d->looted ? (S_LPUDDING | S_LDWASHER | S_LRING) : 0;
pline("A sink.");
madeterrain = TRUE;
@@ -3283,7 +3283,7 @@ wizterrainwish(struct _readobjnam_data *d)
EHalluc_resistance = save_prop;
pline("%s.", An(new_water));
/* Must manually make kelp! */
water_damage_chain(g.level.objects[x][y], TRUE);
water_damage_chain(gl.level.objects[x][y], TRUE);
madeterrain = TRUE;
/* also matches "molten lava" */
@@ -3487,9 +3487,9 @@ wizterrainwish(struct _readobjnam_data *d)
increment above gets canceled out by the decrement here;
otherwise if fountain or sink was replaced, there's one less */
if (IS_FOUNTAIN(oldtyp))
g.level.flags.nfountains--;
gl.level.flags.nfountains--;
else if (IS_SINK(oldtyp))
g.level.flags.nsinks--;
gl.level.flags.nsinks--;
/* horizontal is overlaid by fountain->blessedftn, grave->disturbed */
if (IS_FOUNTAIN(oldtyp) || IS_GRAVE(oldtyp)
|| IS_WALL(oldtyp) || oldtyp == IRONBARS
@@ -3548,7 +3548,7 @@ readobjnam_init(char *bp, struct _readobjnam_data *d)
d->bp = d->origbp = bp;
d->p = (char *) 0;
d->name = (const char *) 0;
d->ftype = g.context.current_fruit;
d->ftype = gc.context.current_fruit;
(void) memset(d->globbuf, '\0', sizeof d->globbuf);
(void) memset(d->fruitbuf, '\0', sizeof d->fruitbuf);
}
@@ -4129,7 +4129,7 @@ readobjnam_postparse1(struct _readobjnam_data *d)
d->otmp = mksobj(GOLD_PIECE, FALSE, FALSE);
d->otmp->quan = (long) d->cnt;
d->otmp->owt = weight(d->otmp);
g.context.botl = 1;
gc.context.botl = 1;
return 3; /*return otmp;*/
}
@@ -4304,7 +4304,7 @@ readobjnam_postparse3(struct _readobjnam_data *d)
/* check real names of gems first */
if (!d->oclass && d->actualn) {
for (i = g.bases[GEM_CLASS]; i <= LAST_GEM; i++) {
for (i = gb.bases[GEM_CLASS]; i <= LAST_GEM; i++) {
register const char *zn;
if ((zn = OBJ_NAME(objects[i])) != 0 && !strcmpi(d->actualn, zn)) {
@@ -4412,7 +4412,7 @@ readobjnam_postparse3(struct _readobjnam_data *d)
fp += l;
}
for (f = g.ffruit; f; f = f->nextf) {
for (f = gf.ffruit; f; f = f->nextf) {
/* match type: 0=none, 1=exact, 2=singular, 3=plural */
int ftyp = 0;
@@ -4532,7 +4532,7 @@ readobjnam(char *bp, struct obj *no_wish)
* Disallow such topology tweaks for WIZKIT startup wishes.
*/
wiztrap:
if (wizard && !g.program_state.wizkit_wishing && !d.oclass) {
if (wizard && !gp.program_state.wizkit_wishing && !d.oclass) {
/* [inline code moved to separate routine to unclutter readobjnam] */
if ((d.otmp = wizterrainwish(&d)) != 0)
return d.otmp;
@@ -4620,7 +4620,7 @@ readobjnam(char *bp, struct obj *no_wish)
if (rn1cnt > 6 - d.gsize)
rn1cnt = 6 - d.gsize;
if (d.cnt > rn1cnt
&& (!wizard || g.program_state.wizkit_wishing
&& (!wizard || gp.program_state.wizkit_wishing
|| yn("Override glob weight limit?") != 'y'))
d.cnt = rn1cnt;
d.otmp->owt *= (unsigned) d.cnt;
@@ -4754,7 +4754,7 @@ readobjnam(char *bp, struct obj *no_wish)
corpses and tins, switch to their corresponding human form;
for figurines, override the can't-be-human restriction instead */
if (d.typ != FIGURINE && is_were(&mons[d.mntmp])
&& (g.mvitals[d.mntmp].mvflags & G_NOCORPSE) != 0
&& (gm.mvitals[d.mntmp].mvflags & G_NOCORPSE) != 0
&& (humanwere = counter_were(d.mntmp)) != NON_PM)
d.mntmp = humanwere;
@@ -4763,14 +4763,14 @@ readobjnam(char *bp, struct obj *no_wish)
if (dead_species(d.mntmp, FALSE)) {
d.otmp->corpsenm = NON_PM; /* it's empty */
} else if ((!(mons[d.mntmp].geno & G_UNIQ) || wizard)
&& !(g.mvitals[d.mntmp].mvflags & G_NOCORPSE)
&& !(gm.mvitals[d.mntmp].mvflags & G_NOCORPSE)
&& mons[d.mntmp].cnutrit != 0) {
d.otmp->corpsenm = d.mntmp;
}
break;
case CORPSE:
if ((!(mons[d.mntmp].geno & G_UNIQ) || wizard)
&& !(g.mvitals[d.mntmp].mvflags & G_NOCORPSE)) {
&& !(gm.mvitals[d.mntmp].mvflags & G_NOCORPSE)) {
if (mons[d.mntmp].msound == MS_GUARDIAN)
d.mntmp = genus(d.mntmp, 1);
set_corpsenm(d.otmp, d.mntmp);