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

@@ -31,13 +31,13 @@ quest_info(int typ)
{
switch (typ) {
case 0:
return g.urole.questarti;
return gu.urole.questarti;
case MS_LEADER:
return g.urole.ldrnum;
return gu.urole.ldrnum;
case MS_NEMESIS:
return g.urole.neminum;
return gu.urole.neminum;
case MS_GUARDIAN:
return g.urole.guardnum;
return gu.urole.guardnum;
default:
impossible("quest_info(%d)", typ);
}
@@ -48,24 +48,24 @@ quest_info(int typ)
const char *
ldrname(void)
{
int i = g.urole.ldrnum;
int i = gu.urole.ldrnum;
Sprintf(g.nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ",
Sprintf(gn.nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ",
mons[i].pmnames[NEUTRAL]);
return g.nambuf;
return gn.nambuf;
}
/* return your intermediate target string */
static const char *
intermed(void)
{
return g.urole.intermed;
return gu.urole.intermed;
}
boolean
is_quest_artifact(struct obj *otmp)
{
return (boolean) (otmp->oartifact == g.urole.questarti);
return (boolean) (otmp->oartifact == gu.urole.questarti);
}
static struct obj *
@@ -91,7 +91,7 @@ find_quest_artifact(unsigned whichchains)
struct obj *qarti = 0;
if ((whichchains & (1 << OBJ_INVENT)) != 0)
qarti = find_qarti(g.invent);
qarti = find_qarti(gi.invent);
if (!qarti && (whichchains & (1 << OBJ_FLOOR)) != 0)
qarti = find_qarti(fobj);
if (!qarti && (whichchains & (1 << OBJ_MINVENT)) != 0)
@@ -103,17 +103,17 @@ find_quest_artifact(unsigned whichchains)
}
if (!qarti && (whichchains & (1 << OBJ_MIGRATING)) != 0) {
/* check migrating objects and minvent of migrating monsters */
for (mtmp = g.migrating_mons; mtmp; mtmp = mtmp->nmon) {
for (mtmp = gm.migrating_mons; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp))
continue;
if ((qarti = find_qarti(mtmp->minvent)) != 0)
break;
}
if (!qarti)
qarti = find_qarti(g.migrating_objs);
qarti = find_qarti(gm.migrating_objs);
}
if (!qarti && (whichchains & (1 << OBJ_BURIED)) != 0)
qarti = find_qarti(g.level.buriedobjlist);
qarti = find_qarti(gl.level.buriedobjlist);
return qarti;
}
@@ -122,17 +122,17 @@ find_quest_artifact(unsigned whichchains)
static const char *
neminame(void)
{
int i = g.urole.neminum;
int i = gu.urole.neminum;
Sprintf(g.nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ",
Sprintf(gn.nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ",
mons[i].pmnames[NEUTRAL]);
return g.nambuf;
return gn.nambuf;
}
static const char *
guardname(void) /* return your role leader's guard monster name */
{
int i = g.urole.guardnum;
int i = gu.urole.guardnum;
return mons[i].pmnames[NEUTRAL];
}
@@ -140,7 +140,7 @@ guardname(void) /* return your role leader's guard monster name */
static const char *
homebase(void) /* return your role leader's location */
{
return g.urole.homebase;
return gu.urole.homebase;
}
/* returns 1 if nemesis death message mentions noxious fumes, otherwise 0;
@@ -168,7 +168,7 @@ stinky_nemesis(struct monst *mon)
/* since nemdead() just gave the message for hero's nemesis even if 'mon'
is some other role's nemesis (feasible in wizard mode), base any gas
cloud on the text that was shown even if not appropriate for 'mon' */
(void) com_pager_core(g.urole.filecode, "killed_nemesis", FALSE, &mesg);
(void) com_pager_core(gu.urole.filecode, "killed_nemesis", FALSE, &mesg);
#endif
/* this is somewhat fragile; it assumes that when both (noxious or
@@ -210,24 +210,24 @@ qtext_pronoun(
* which genders[] doesn't handle; cvt_buf[] already contains name.
*/
if (who == 'o'
&& (strstri(g.cvt_buf, "Eyes ")
|| strcmpi(g.cvt_buf, makesingular(g.cvt_buf)))) {
&& (strstri(gc.cvt_buf, "Eyes ")
|| strcmpi(gc.cvt_buf, makesingular(gc.cvt_buf)))) {
pnoun = (lwhich == 'h') ? "they"
: (lwhich == 'i') ? "them"
: (lwhich == 'j') ? "their" : "?";
} else {
godgend = (who == 'd') ? g.quest_status.godgend
: (who == 'l') ? g.quest_status.ldrgend
: (who == 'n') ? g.quest_status.nemgend
godgend = (who == 'd') ? gq.quest_status.godgend
: (who == 'l') ? gq.quest_status.ldrgend
: (who == 'n') ? gq.quest_status.nemgend
: 2; /* default to neuter */
pnoun = (lwhich == 'h') ? genders[godgend].he
: (lwhich == 'i') ? genders[godgend].him
: (lwhich == 'j') ? genders[godgend].his : "?";
}
Strcpy(g.cvt_buf, pnoun);
Strcpy(gc.cvt_buf, pnoun);
/* capitalize for H,I,J */
if (lwhich != which)
g.cvt_buf[0] = highc(g.cvt_buf[0]);
gc.cvt_buf[0] = highc(gc.cvt_buf[0]);
return;
}
@@ -238,11 +238,11 @@ convert_arg(char c)
switch (c) {
case 'p':
str = g.plname;
str = gp.plname;
break;
case 'c':
str = (flags.female && g.urole.name.f) ? g.urole.name.f
: g.urole.name.m;
str = (flags.female && gu.urole.name.f) ? gu.urole.name.f
: gu.urole.name.m;
break;
case 'r':
str = rank_of(u.ulevel, Role_switch, flags.female);
@@ -264,7 +264,7 @@ convert_arg(char c)
break;
case 'O':
case 'o':
str = the(artiname(g.urole.questarti));
str = the(artiname(gu.urole.questarti));
if (c == 'O') {
/* shorten "the Foo of Bar" to "the Foo"
(buffer returned by the() is modifiable) */
@@ -311,7 +311,7 @@ convert_arg(char c)
str = Blind ? "sense" : "see";
break;
case 'Z':
str = g.dungeons[0].dname;
str = gd.dungeons[0].dname;
break;
case '%':
str = "%";
@@ -320,7 +320,7 @@ convert_arg(char c)
str = "";
break;
}
Strcpy(g.cvt_buf, str);
Strcpy(gc.cvt_buf, str);
}
static void
@@ -343,17 +343,17 @@ convert_line(char *in_line, char *out_line)
switch (*(++c)) {
/* insert "a"/"an" prefix */
case 'A':
Strcat(cc, An(g.cvt_buf));
Strcat(cc, An(gc.cvt_buf));
cc += strlen(cc);
continue; /* for */
case 'a':
Strcat(cc, an(g.cvt_buf));
Strcat(cc, an(gc.cvt_buf));
cc += strlen(cc);
continue; /* for */
/* capitalize */
case 'C':
g.cvt_buf[0] = highc(g.cvt_buf[0]);
gc.cvt_buf[0] = highc(gc.cvt_buf[0]);
break;
/* replace name with pronoun;
@@ -372,24 +372,24 @@ convert_line(char *in_line, char *out_line)
/* pluralize */
case 'P':
g.cvt_buf[0] = highc(g.cvt_buf[0]);
gc.cvt_buf[0] = highc(gc.cvt_buf[0]);
/*FALLTHRU*/
case 'p':
Strcpy(g.cvt_buf, makeplural(g.cvt_buf));
Strcpy(gc.cvt_buf, makeplural(gc.cvt_buf));
break;
/* append possessive suffix */
case 'S':
g.cvt_buf[0] = highc(g.cvt_buf[0]);
gc.cvt_buf[0] = highc(gc.cvt_buf[0]);
/*FALLTHRU*/
case 's':
Strcpy(g.cvt_buf, s_suffix(g.cvt_buf));
Strcpy(gc.cvt_buf, s_suffix(gc.cvt_buf));
break;
/* strip any "the" prefix */
case 't':
if (!strncmpi(g.cvt_buf, "the ", 4)) {
Strcat(cc, &g.cvt_buf[4]);
if (!strncmpi(gc.cvt_buf, "the ", 4)) {
Strcat(cc, &gc.cvt_buf[4]);
cc += strlen(cc);
continue; /* for */
}
@@ -399,8 +399,8 @@ convert_line(char *in_line, char *out_line)
--c; /* undo switch increment */
break;
}
Strcat(cc, g.cvt_buf);
cc += strlen(g.cvt_buf);
Strcat(cc, gc.cvt_buf);
cc += strlen(gc.cvt_buf);
break;
} /* else fall through */
@@ -455,7 +455,7 @@ static boolean
skip_pager(boolean common UNUSED)
{
/* WIZKIT: suppress plot feedback if starting with quest artifact */
if (g.program_state.wizkit_wishing)
if (gp.program_state.wizkit_wishing)
return TRUE;
return FALSE;
}
@@ -625,7 +625,7 @@ com_pager(const char *msgid)
void
qt_pager(const char *msgid)
{
if (!com_pager_core(g.urole.filecode, msgid, FALSE, (char **) 0))
if (!com_pager_core(gu.urole.filecode, msgid, FALSE, (char **) 0))
(void) com_pager_core("common", msgid, TRUE, (char **) 0);
}
@@ -635,15 +635,15 @@ qt_montype(void)
int qpm;
if (rn2(5)) {
qpm = g.urole.enemy1num;
if (qpm != NON_PM && rn2(5) && !(g.mvitals[qpm].mvflags & G_GENOD))
qpm = gu.urole.enemy1num;
if (qpm != NON_PM && rn2(5) && !(gm.mvitals[qpm].mvflags & G_GENOD))
return &mons[qpm];
return mkclass(g.urole.enemy1sym, 0);
return mkclass(gu.urole.enemy1sym, 0);
}
qpm = g.urole.enemy2num;
if (qpm != NON_PM && rn2(5) && !(g.mvitals[qpm].mvflags & G_GENOD))
qpm = gu.urole.enemy2num;
if (qpm != NON_PM && rn2(5) && !(gm.mvitals[qpm].mvflags & G_GENOD))
return &mons[qpm];
return mkclass(g.urole.enemy2sym, 0);
return mkclass(gu.urole.enemy2sym, 0);
}
/* special levels can include a custom arrival message; display it */
@@ -651,11 +651,11 @@ void
deliver_splev_message(void)
{
/* there's no provision for delivering via window instead of pline */
if (g.lev_message) {
deliver_by_pline(g.lev_message);
if (gl.lev_message) {
deliver_by_pline(gl.lev_message);
free((genericptr_t) g.lev_message);
g.lev_message = NULL;
free((genericptr_t) gl.lev_message);
gl.lev_message = NULL;
}
}