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

@@ -158,7 +158,7 @@ stuck_in_wall(void)
if (!isok(x, y)
|| (IS_ROCK(levl[x][y].typ)
&& (levl[x][y].typ != SDOOR && levl[x][y].typ != SCORR))
|| (blocked_boulder(i, j) && !throws_rocks(g.youmonst.data)))
|| (blocked_boulder(i, j) && !throws_rocks(gy.youmonst.data)))
++count;
}
}
@@ -214,13 +214,13 @@ in_trouble(void)
|| stuck_ring(uleft, RIN_LEVITATION)
|| stuck_ring(uright, RIN_LEVITATION))
return TROUBLE_CURSED_LEVITATION;
if (nohands(g.youmonst.data) || !freehand()) {
if (nohands(gy.youmonst.data) || !freehand()) {
/* for bag/box access [cf use_container()]...
make sure it's a case that we know how to handle;
otherwise "fix all troubles" would get stuck in a loop */
if (welded(uwep))
return TROUBLE_UNUSEABLE_HANDS;
if (Upolyd && nohands(g.youmonst.data)
if (Upolyd && nohands(gy.youmonst.data)
&& (!Unchanging || ((otmp = unchanger()) != 0 && otmp->cursed)))
return TROUBLE_UNUSEABLE_HANDS;
}
@@ -243,7 +243,7 @@ in_trouble(void)
return TROUBLE_SADDLE;
}
if (Blinded > 1 && haseyes(g.youmonst.data)
if (Blinded > 1 && haseyes(gy.youmonst.data)
&& (!u.uswallow
|| !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)))
return TROUBLE_BLIND;
@@ -276,7 +276,7 @@ worst_cursed_item(void)
/* if strained or worse, check for loadstone first */
if (near_capacity() >= HVY_ENCUMBER) {
for (otmp = g.invent; otmp; otmp = otmp->nobj)
for (otmp = gi.invent; otmp; otmp = otmp->nobj)
if (Cursed_obj(otmp, LOADSTONE))
return otmp;
}
@@ -320,7 +320,7 @@ worst_cursed_item(void)
otmp = uswapwep;
/* all worn items ought to be handled by now */
} else {
for (otmp = g.invent; otmp; otmp = otmp->nobj) {
for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
if (!otmp->cursed)
continue;
if (otmp->otyp == LOADSTONE || confers_luck(otmp))
@@ -377,7 +377,7 @@ fix_worst_trouble(int trouble)
}
You("can breathe again.");
Strangled = 0;
g.context.botl = 1;
gc.context.botl = 1;
break;
case TROUBLE_LAVA:
You("are back on solid ground.");
@@ -391,7 +391,7 @@ fix_worst_trouble(int trouble)
case TROUBLE_HUNGRY:
Your("%s feels content.", body_part(STOMACH));
init_uhunger();
g.context.botl = 1;
gc.context.botl = 1;
break;
case TROUBLE_SICK:
You_feel("better.");
@@ -419,14 +419,14 @@ fix_worst_trouble(int trouble)
if (u.uhpmax > u.uhppeak)
u.uhppeak = u.uhpmax;
u.uhp = u.uhpmax;
g.context.botl = 1;
gc.context.botl = 1;
break;
case TROUBLE_COLLAPSING:
/* override Fixed_abil; uncurse that if feasible */
You_feel("%sstronger.",
(AMAX(A_STR) - ABASE(A_STR) > 6) ? "much " : "");
ABASE(A_STR) = AMAX(A_STR);
g.context.botl = 1;
gc.context.botl = 1;
if (Fixed_abil) {
if ((otmp = stuck_ring(uleft, RIN_SUSTAIN_ABILITY)) != 0) {
if (otmp == uleft)
@@ -477,7 +477,7 @@ fix_worst_trouble(int trouble)
fix_curse_trouble(otmp, what);
break;
}
if (Upolyd && nohands(g.youmonst.data)) {
if (Upolyd && nohands(gy.youmonst.data)) {
if (!Unchanging) {
Your("shape becomes uncertain.");
rehumanize(); /* "You return to {normal} form." */
@@ -487,7 +487,7 @@ fix_worst_trouble(int trouble)
break;
}
}
if (nohands(g.youmonst.data) || !freehand())
if (nohands(gy.youmonst.data) || !freehand())
impossible("fix_worst_trouble: couldn't cure hands.");
break;
case TROUBLE_CURSED_BLINDFOLD:
@@ -530,7 +530,7 @@ fix_worst_trouble(int trouble)
for (i = 0; i < A_MAX; i++) {
if (ABASE(i) < AMAX(i)) {
ABASE(i) = AMAX(i);
g.context.botl = 1;
gc.context.botl = 1;
}
}
(void) encumber_msg();
@@ -542,7 +542,7 @@ fix_worst_trouble(int trouble)
msgbuf[0] = '\0';
if (Blinded) {
if (eyecount(g.youmonst.data) != 1)
if (eyecount(gy.youmonst.data) != 1)
eyes = makeplural(eyes);
Sprintf(msgbuf, "Your %s %s better", eyes, vtense(eyes, "feel"));
u.ucreamed = 0;
@@ -672,8 +672,8 @@ fry_by_god(aligntyp resp_god, boolean via_disintegration)
{
You("%s!", !via_disintegration ? "fry to a crisp"
: "disintegrate into a pile of dust");
g.killer.format = KILLED_BY;
Sprintf(g.killer.name, "the wrath of %s", align_gname(resp_god));
gk.killer.format = KILLED_BY;
Sprintf(gk.killer.name, "the wrath of %s", align_gname(resp_god));
done(DIED);
}
@@ -712,7 +712,7 @@ angrygods(aligntyp resp_god)
(ugod_is_angry() && resp_god == u.ualign.type)
? "hast strayed from the path"
: "art arrogant",
g.youmonst.data->mlet == S_HUMAN ? "mortal" : "creature");
gy.youmonst.data->mlet == S_HUMAN ? "mortal" : "creature");
verbalize("Thou must relearn thy lessons!");
(void) adjattrib(A_WIS, -1, FALSE);
losexp((char *) 0);
@@ -739,7 +739,7 @@ angrygods(aligntyp resp_god)
: "call upon");
/* [why isn't this using verbalize()?] */
pline("\"Then die, %s!\"",
(g.youmonst.data->mlet == S_HUMAN) ? "mortal" : "creature");
(gy.youmonst.data->mlet == S_HUMAN) ? "mortal" : "creature");
summon_minion(resp_god, FALSE);
break;
@@ -988,7 +988,7 @@ give_spell(void)
|| carrying(MAGIC_MARKER))
break;
}
otmp->otyp = rnd_class(g.bases[SPBOOK_CLASS], SPE_BLANK_PAPER);
otmp->otyp = rnd_class(gb.bases[SPBOOK_CLASS], SPE_BLANK_PAPER);
}
/*
* 25% chance of learning the spell directly instead of
@@ -1049,7 +1049,7 @@ pleased(aligntyp g_align)
: Hallucination ? "full" : "satisfied");
/* not your deity */
if (on_altar() && g.p_aligntyp != u.ualign.type) {
if (on_altar() && gp.p_aligntyp != u.ualign.type) {
adjalign(-1);
return;
} else if (u.ualign.record < 2 && trouble <= 0)
@@ -1071,7 +1071,7 @@ pleased(aligntyp g_align)
*/
if (!trouble && u.ualign.record >= DEVOUT) {
/* if hero was in trouble, but got better, no special favor */
if (g.p_trouble == 0)
if (gp.p_trouble == 0)
pat_on_head = 1;
} else {
int action, prayer_luck;
@@ -1185,7 +1185,7 @@ pleased(aligntyp g_align)
if (!u.uevent.uopened_dbridge && !u.uevent.gehennom_entered) {
if (u.uevent.uheard_tune < 1) {
godvoice(g_align, (char *) 0);
verbalize("Hark, %s!", (g.youmonst.data->mlet == S_HUMAN)
verbalize("Hark, %s!", (gy.youmonst.data->mlet == S_HUMAN)
? "mortal"
: "creature");
verbalize(
@@ -1194,7 +1194,7 @@ pleased(aligntyp g_align)
break;
} else if (u.uevent.uheard_tune < 2) {
You_hear("a divine music...");
pline("It sounds like: \"%s\".", g.tune);
pline("It sounds like: \"%s\".", gt.tune);
u.uevent.uheard_tune++;
record_achievement(ACH_TUNE);
break;
@@ -1221,7 +1221,7 @@ pleased(aligntyp g_align)
u.mh = u.mhmax;
if (ABASE(A_STR) < AMAX(A_STR)) {
ABASE(A_STR) = AMAX(A_STR);
g.context.botl = 1; /* before potential message */
gc.context.botl = 1; /* before potential message */
(void) encumber_msg();
}
if (u.uhunger < 900)
@@ -1236,7 +1236,7 @@ pleased(aligntyp g_align)
rather than issuing a pat-on-head */
u.ucreamed = 0;
make_blinded(0L, TRUE);
g.context.botl = 1;
gc.context.botl = 1;
break;
case 4: {
register struct obj *otmp;
@@ -1246,7 +1246,7 @@ pleased(aligntyp g_align)
You_feel("the power of %s.", u_gname());
else
You("are surrounded by %s aura.", an(hcolor(NH_LIGHT_BLUE)));
for (otmp = g.invent; otmp; otmp = otmp->nobj) {
for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
if (otmp->cursed
&& (otmp != uarmh /* [see worst_cursed_item()] */
|| uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT)) {
@@ -1323,8 +1323,8 @@ pleased(aligntyp g_align)
of nutrition will be required. The increase gets throttled if
it ever reaches 32K so that configurations using 16-bit ints are
still viable. */
if (g.moves > 100000L) {
long incr = (g.moves - 100000L) / 100L,
if (gm.moves > 100000L) {
long incr = (gm.moves - 100000L) / 100L,
largest_ublesscnt_incr = (long) (LARGEST_INT - u.ublesscnt);
if (incr > largest_ublesscnt_incr)
@@ -1345,7 +1345,7 @@ water_prayer(boolean bless_water)
register long changed = 0;
boolean other = FALSE, bc_known = !(Blind || Hallucination);
for (otmp = g.level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
for (otmp = gl.level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
/* turn water into (un)holy water */
if (otmp->otyp == POT_WATER
&& (bless_water ? !otmp->blessed : !otmp->cursed)) {
@@ -1516,7 +1516,7 @@ dosacrifice(void)
return ECMD_TIME;
if (otmp->corpsenm == PM_ACID_BLOB
|| (g.moves <= peek_at_iced_corpse_age(otmp) + 50)) {
|| (gm.moves <= peek_at_iced_corpse_age(otmp) + 50)) {
value = mons[otmp->corpsenm].difficulty + 1;
if (otmp->oeaten)
value = eaten_stat(value, otmp);
@@ -1525,7 +1525,7 @@ dosacrifice(void)
/* same race or former pet results apply even if the corpse is
too old (value==0) */
if (your_race(ptr)) {
if (is_demon(g.youmonst.data)) {
if (is_demon(gy.youmonst.data)) {
You("find the idea very satisfying.");
exercise(A_WIS, TRUE);
} else if (u.ualign.type != A_CHAOTIC) {
@@ -1539,7 +1539,7 @@ dosacrifice(void)
return ECMD_TIME;
} else if (altaralign != A_CHAOTIC && altaralign != A_NONE) {
/* curse the lawful/neutral altar */
pline_The("altar is stained with %s blood.", g.urace.adj);
pline_The("altar is stained with %s blood.", gu.urace.adj);
levl[u.ux][u.uy].altarmask = AM_CHAOTIC;
newsym(u.ux, u.uy); /* in case Invisible to self */
angry_priest();
@@ -1579,8 +1579,8 @@ dosacrifice(void)
dmon->mpeaceful = TRUE;
You("are terrified, and unable to move.");
nomul(-3);
g.multi_reason = "being terrified of a demon";
g.nomovemsg = 0;
gm.multi_reason = "being terrified of a demon";
gn.nomovemsg = 0;
} else
pline_The("%s.", demonless_msg);
}
@@ -1679,8 +1679,8 @@ dosacrifice(void)
pline("%s shrugs and retains dominion over %s,", Moloch,
u_gname());
pline("then mercilessly snuffs out your life.");
Sprintf(g.killer.name, "%s indifference", s_suffix(Moloch));
g.killer.format = KILLED_BY;
Sprintf(gk.killer.name, "%s indifference", s_suffix(Moloch));
gk.killer.format = KILLED_BY;
done(DIED);
/* life-saved (or declined to die in wizard/explore mode) */
pline("%s snarls and tries again...", Moloch);
@@ -1948,51 +1948,51 @@ can_pray(boolean praying) /* false means no messages should be given */
{
int alignment;
g.p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type;
g.p_trouble = in_trouble();
gp.p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type;
gp.p_trouble = in_trouble();
if (is_demon(g.youmonst.data) /* ok if chaotic or none (Moloch) */
&& (g.p_aligntyp == A_LAWFUL || g.p_aligntyp != A_NEUTRAL)) {
if (is_demon(gy.youmonst.data) /* ok if chaotic or none (Moloch) */
&& (gp.p_aligntyp == A_LAWFUL || gp.p_aligntyp != A_NEUTRAL)) {
if (praying)
pline_The("very idea of praying to a %s god is repugnant to you.",
g.p_aligntyp ? "lawful" : "neutral");
gp.p_aligntyp ? "lawful" : "neutral");
return FALSE;
}
if (praying)
You("begin praying to %s.", align_gname(g.p_aligntyp));
You("begin praying to %s.", align_gname(gp.p_aligntyp));
if (u.ualign.type && u.ualign.type == -g.p_aligntyp)
if (u.ualign.type && u.ualign.type == -gp.p_aligntyp)
alignment = -u.ualign.record; /* Opposite alignment altar */
else if (u.ualign.type != g.p_aligntyp)
else if (u.ualign.type != gp.p_aligntyp)
alignment = u.ualign.record / 2; /* Different alignment altar */
else
alignment = u.ualign.record;
if (g.p_aligntyp == A_NONE) /* praying to Moloch */
g.p_type = -2;
else if ((g.p_trouble > 0) ? (u.ublesscnt > 200) /* big trouble */
: (g.p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulties */
if (gp.p_aligntyp == A_NONE) /* praying to Moloch */
gp.p_type = -2;
else if ((gp.p_trouble > 0) ? (u.ublesscnt > 200) /* big trouble */
: (gp.p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulties */
: (u.ublesscnt > 0)) /* not in trouble */
g.p_type = 0; /* too soon... */
gp.p_type = 0; /* too soon... */
else if ((int) Luck < 0 || u.ugangr || alignment < 0)
g.p_type = 1; /* too naughty... */
gp.p_type = 1; /* too naughty... */
else /* alignment >= 0 */ {
if (on_altar() && u.ualign.type != g.p_aligntyp)
g.p_type = 2;
if (on_altar() && u.ualign.type != gp.p_aligntyp)
gp.p_type = 2;
else
g.p_type = 3;
gp.p_type = 3;
}
if (is_undead(g.youmonst.data) && !Inhell
&& (g.p_aligntyp == A_LAWFUL
|| (g.p_aligntyp == A_NEUTRAL && !rn2(10))))
g.p_type = -1;
if (is_undead(gy.youmonst.data) && !Inhell
&& (gp.p_aligntyp == A_LAWFUL
|| (gp.p_aligntyp == A_NEUTRAL && !rn2(10))))
gp.p_type = -1;
/* Note: when !praying, the random factor for neutrals makes the
return value a non-deterministic approximation for enlightenment.
This case should be uncommon enough to live with... */
return !praying ? (boolean) (g.p_type == 3 && !Inhell) : TRUE;
return !praying ? (boolean) (gp.p_type == 3 && !Inhell) : TRUE;
}
/* return TRUE if praying revived a pet corpse */
@@ -2001,7 +2001,7 @@ pray_revive(void)
{
struct obj *otmp;
for (otmp = g.level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere)
for (otmp = gl.level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere)
if (otmp->otyp == CORPSE && has_omonst(otmp)
&& OMONST(otmp)->mtame && !OMONST(otmp)->isminion)
break;
@@ -2037,7 +2037,7 @@ dopray(void)
if (!can_pray(TRUE))
return ECMD_OK;
if (wizard && g.p_type >= 0) {
if (wizard && gp.p_type >= 0) {
static const char forcesuccess[] = "Force the gods to be pleased?";
/* if we asked "are you sure?" above we suppressed the response
@@ -2051,16 +2051,16 @@ dopray(void)
if (u.ualign.record <= 0)
u.ualign.record = 1;
u.ugangr = 0;
if (g.p_type < 2)
g.p_type = 3;
if (gp.p_type < 2)
gp.p_type = 3;
}
}
nomul(-3);
g.multi_reason = "praying";
g.nomovemsg = "You finish your prayer.";
g.afternmv = prayer_done;
gm.multi_reason = "praying";
gn.nomovemsg = "You finish your prayer.";
ga.afternmv = prayer_done;
if (g.p_type == 3 && !Inhell) {
if (gp.p_type == 3 && !Inhell) {
/* if you've been true to your god you can't die while you pray */
if (!Blind)
You("are surrounded by a shimmering light.");
@@ -2073,10 +2073,10 @@ dopray(void)
static int
prayer_done(void) /* M. Stephenson (1.0.3b) */
{
aligntyp alignment = g.p_aligntyp;
aligntyp alignment = gp.p_aligntyp;
u.uinvulnerable = FALSE;
if (g.p_type == -2) {
if (gp.p_type == -2) {
/* praying at an unaligned altar, not necessarily in Gehennom */
You("%s diabolical laughter all around you...",
!Deaf ? "hear" : "intuit");
@@ -2088,7 +2088,7 @@ prayer_done(void) /* M. Stephenson (1.0.3b) */
pline("Nothing else happens."); /* not actually true... */
return 1;
} /* else use regular Inhell result below */
} else if (g.p_type == -1) {
} else if (gp.p_type == -1) {
/* praying while poly'd into an undead creature while non-chaotic */
godvoice(alignment,
(alignment == A_LAWFUL)
@@ -2111,17 +2111,17 @@ prayer_done(void) /* M. Stephenson (1.0.3b) */
return 0;
}
if (g.p_type == 0) {
if (gp.p_type == 0) {
if (on_altar() && u.ualign.type != alignment)
(void) water_prayer(FALSE);
u.ublesscnt += rnz(250);
change_luck(-3);
gods_upset(u.ualign.type);
} else if (g.p_type == 1) {
} else if (gp.p_type == 1) {
if (on_altar() && u.ualign.type != alignment)
(void) water_prayer(FALSE);
angrygods(u.ualign.type); /* naughty */
} else if (g.p_type == 2) {
} else if (gp.p_type == 2) {
if (water_prayer(FALSE)) {
/* attempted water prayer on a non-coaligned altar */
u.ublesscnt += rnz(250);
@@ -2162,7 +2162,7 @@ doturn(void)
Gname = halu_gname(u.ualign.type);
/* [What about needing free hands (does #turn involve any gesturing)?] */
if (!can_chant(&g.youmonst)) {
if (!can_chant(&gy.youmonst)) {
/* "evilness": "demons and undead" is too verbose and too precise */
You("are %s upon %s to turn aside evilness.",
Strangled ? "not able to call" : "incapable of calling", Gname);
@@ -2172,8 +2172,8 @@ doturn(void)
return (u.uconduct.gnostic == 1) ? ECMD_TIME : ECMD_OK;
}
if ((u.ualign.type != A_CHAOTIC
&& (is_demon(g.youmonst.data)
|| is_undead(g.youmonst.data) || is_vampshifter(&g.youmonst)))
&& (is_demon(gy.youmonst.data)
|| is_undead(gy.youmonst.data) || is_vampshifter(&gy.youmonst)))
|| u.ugangr > 6) { /* "Die, mortal!" */
pline("For some reason, %s seems to ignore you.", Gname);
aggravate();
@@ -2271,8 +2271,8 @@ doturn(void)
* the brief paralysis?]
*/
nomul(-(5 - ((u.ulevel - 1) / 6))); /* -5 .. -1 */
g.multi_reason = "trying to turn the monsters";
g.nomovemsg = You_can_move_again;
gm.multi_reason = "trying to turn the monsters";
gn.nomovemsg = You_can_move_again;
return ECMD_TIME;
}
@@ -2326,13 +2326,13 @@ align_gname(aligntyp alignment)
gnam = Moloch;
break;
case A_LAWFUL:
gnam = g.urole.lgod;
gnam = gu.urole.lgod;
break;
case A_NEUTRAL:
gnam = g.urole.ngod;
gnam = gu.urole.ngod;
break;
case A_CHAOTIC:
gnam = g.urole.cgod;
gnam = gu.urole.cgod;
break;
default:
impossible("unknown alignment.");
@@ -2421,13 +2421,13 @@ align_gtitle(aligntyp alignment)
switch (alignment) {
case A_LAWFUL:
gnam = g.urole.lgod;
gnam = gu.urole.lgod;
break;
case A_NEUTRAL:
gnam = g.urole.ngod;
gnam = gu.urole.ngod;
break;
case A_CHAOTIC:
gnam = g.urole.cgod;
gnam = gu.urole.cgod;
break;
default:
gnam = 0;
@@ -2469,7 +2469,7 @@ blocked_boulder(int dx, int dy)
int nx, ny;
long count = 0L;
for (otmp = g.level.objects[u.ux + dx][u.uy + dy]; otmp;
for (otmp = gl.level.objects[u.ux + dx][u.uy + dy]; otmp;
otmp = otmp->nexthere) {
if (otmp->otyp == BOULDER)
count += otmp->quan;