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

@@ -33,7 +33,7 @@ noteleport_level(struct monst* mon)
return TRUE;
/* natural no-teleport level */
if (g.level.flags.noteleport)
if (gl.level.flags.noteleport)
return TRUE;
return FALSE;
@@ -97,7 +97,7 @@ goodpos(
* oh well.
*/
if (!allow_u) {
if (u_at(x, y) && mtmp != &g.youmonst
if (u_at(x, y) && mtmp != &gy.youmonst
&& (mtmp != u.ustuck || !u.uswallow)
&& (!u.usteed || mtmp != u.usteed))
return FALSE;
@@ -122,7 +122,7 @@ goodpos(
mdat = mtmp->data;
if (is_pool(x, y) && !ignorewater) {
/* [what about Breathless?] */
if (mtmp == &g.youmonst)
if (mtmp == &gy.youmonst)
return (Swimming || Amphibious
|| (!Is_waterlevel(&u.uz)
&& !is_waterwall(x, y)
@@ -141,11 +141,11 @@ goodpos(
that due the effect of the heat causing it to dry out */
if (mdat == &mons[PM_FLOATING_EYE])
return FALSE;
else if (mtmp == &g.youmonst)
else if (mtmp == &gy.youmonst)
return (Levitation || Flying
|| (Fire_resistance && Wwalking && uarmf
&& uarmf->oerodeproof)
|| (Upolyd && likes_lava(g.youmonst.data)));
|| (Upolyd && likes_lava(gy.youmonst.data)));
else
return (is_floater(mdat) || is_flyer(mdat)
|| likes_lava(mdat));
@@ -296,30 +296,30 @@ tele_jump_ok(coordxy x1, coordxy y1, coordxy x2, coordxy y2)
{
if (!isok(x2, y2))
return FALSE;
if (g.dndest.nlx > 0) {
if (gd.dndest.nlx > 0) {
/* if inside a restricted region, can't teleport outside */
if (within_bounded_area(x1, y1, g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy)
&& !within_bounded_area(x2, y2, g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy))
if (within_bounded_area(x1, y1, gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy)
&& !within_bounded_area(x2, y2, gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy))
return FALSE;
/* and if outside, can't teleport inside */
if (!within_bounded_area(x1, y1, g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy)
&& within_bounded_area(x2, y2, g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy))
if (!within_bounded_area(x1, y1, gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy)
&& within_bounded_area(x2, y2, gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy))
return FALSE;
}
if (g.updest.nlx > 0) { /* ditto */
if (within_bounded_area(x1, y1, g.updest.nlx, g.updest.nly,
g.updest.nhx, g.updest.nhy)
&& !within_bounded_area(x2, y2, g.updest.nlx, g.updest.nly,
g.updest.nhx, g.updest.nhy))
if (gu.updest.nlx > 0) { /* ditto */
if (within_bounded_area(x1, y1, gu.updest.nlx, gu.updest.nly,
gu.updest.nhx, gu.updest.nhy)
&& !within_bounded_area(x2, y2, gu.updest.nlx, gu.updest.nly,
gu.updest.nhx, gu.updest.nhy))
return FALSE;
if (!within_bounded_area(x1, y1, g.updest.nlx, g.updest.nly,
g.updest.nhx, g.updest.nhy)
&& within_bounded_area(x2, y2, g.updest.nlx, g.updest.nly,
g.updest.nhx, g.updest.nhy))
if (!within_bounded_area(x1, y1, gu.updest.nlx, gu.updest.nly,
gu.updest.nhx, gu.updest.nhy)
&& within_bounded_area(x2, y2, gu.updest.nlx, gu.updest.nly,
gu.updest.nhx, gu.updest.nhy))
return FALSE;
}
return TRUE;
@@ -344,7 +344,7 @@ teleok(coordxy x, coordxy y, boolean trapok)
if (!trapok)
return FALSE;
}
if (!goodpos(x, y, &g.youmonst, 0))
if (!goodpos(x, y, &gy.youmonst, 0))
return FALSE;
if (!tele_jump_ok(u.ux, u.uy, x, y))
return FALSE;
@@ -399,9 +399,9 @@ teleds(coordxy nux, coordxy nuy, int teleds_flags)
u.ux0 = u.ux;
u.uy0 = u.uy;
if (!hideunder(&g.youmonst) && g.youmonst.data->mlet == S_MIMIC) {
if (!hideunder(&gy.youmonst) && gy.youmonst.data->mlet == S_MIMIC) {
/* mimics stop being unnoticed */
g.youmonst.m_ap_type = M_AP_NOTHING;
gy.youmonst.m_ap_type = M_AP_NOTHING;
}
if (was_swallowed) {
@@ -445,7 +445,7 @@ teleds(coordxy nux, coordxy nuy, int teleds_flags)
*/
newsym(u.ux0, u.uy0);
see_monsters();
g.vision_full_recalc = 1;
gv.vision_full_recalc = 1;
nomul(0);
vision_recalc(0); /* vision before effects */
@@ -550,7 +550,7 @@ scrolltele(struct obj* scroll)
coord cc;
/* Disable teleportation in stronghold && Vlad's Tower */
if (noteleport_level(&g.youmonst) && !wizard) {
if (noteleport_level(&gy.youmonst) && !wizard) {
pline("A mysterious force prevents you from teleporting!");
if (scroll)
learnscroll(scroll); /* this is obviously a teleport scroll */
@@ -766,7 +766,7 @@ dotele(
int energy = 0;
if (!Teleportation || (u.ulevel < (Role_if(PM_WIZARD) ? 8 : 12)
&& !can_teleport(g.youmonst.data))) {
&& !can_teleport(gy.youmonst.data))) {
/* Try to use teleport away spell. */
int knownsp = known_spell(SPE_TELEPORT_AWAY);
@@ -831,7 +831,7 @@ dotele(
} else {
/* bypassing spelleffects(); apply energy cost directly */
u.uen -= energy;
g.context.botl = 1;
gc.context.botl = 1;
}
}
@@ -941,18 +941,18 @@ level_tele(void)
if (ynq("Go to Nowhere. Are you sure?") != 'y')
return;
You("%s in agony as your body begins to warp...",
is_silent(g.youmonst.data) ? "writhe" : "scream");
is_silent(gy.youmonst.data) ? "writhe" : "scream");
display_nhwindow(WIN_MESSAGE, FALSE);
You("cease to exist.");
if (g.invent)
if (gi.invent)
Your("possessions land on the %s with a thud.",
surface(u.ux, u.uy));
g.killer.format = NO_KILLER_PREFIX;
Strcpy(g.killer.name, "committed suicide");
gk.killer.format = NO_KILLER_PREFIX;
Strcpy(gk.killer.name, "committed suicide");
done(DIED);
pline("An energized cloud of dust begins to coalesce.");
Your("body rematerializes%s.",
g.invent ? ", and you gather up all your possessions" : "");
gi.invent ? ", and you gather up all your possessions" : "");
return;
}
@@ -972,7 +972,7 @@ level_tele(void)
* we let negative values requests fall into the "heaven" handling.
*/
if (In_quest(&u.uz) && newlev > 0)
newlev = newlev + g.dungeons[u.uz.dnum].depth_start - 1;
newlev = newlev + gd.dungeons[u.uz.dnum].depth_start - 1;
} else { /* involuntary level tele */
random_levtport:
newlev = random_teleport_level();
@@ -1002,24 +1002,24 @@ level_tele(void)
return;
}
g.killer.name[0] = 0; /* still alive, so far... */
gk.killer.name[0] = 0; /* still alive, so far... */
if (iflags.debug_fuzzer && newlev < 0)
goto random_levtport;
if (newlev < 0 && !force_dest) {
if (*u.ushops0) {
/* take unpaid inventory items off of shop bills */
g.in_mklev = TRUE; /* suppress map update */
gi.in_mklev = TRUE; /* suppress map update */
u_left_shop(u.ushops0, TRUE);
/* you're now effectively out of the shop */
*u.ushops0 = *u.ushops = '\0';
g.in_mklev = FALSE;
gi.in_mklev = FALSE;
}
if (newlev <= -10) {
You("arrive in heaven.");
verbalize("Thou art early, but we'll admit thee.");
g.killer.format = NO_KILLER_PREFIX;
Strcpy(g.killer.name, "went to heaven prematurely");
gk.killer.format = NO_KILLER_PREFIX;
Strcpy(gk.killer.name, "went to heaven prematurely");
} else if (newlev == -9) {
You_feel("deliriously happy.");
pline("(In fact, you're on Cloud 9!)");
@@ -1027,7 +1027,7 @@ level_tele(void)
} else
You("are now high above the clouds...");
if (g.killer.name[0]) {
if (gk.killer.name[0]) {
; /* arrival in heaven is pending */
} else if (Levitation) {
escape_by_flying = "float gently down to earth";
@@ -1036,14 +1036,14 @@ level_tele(void)
} else {
pline("Unfortunately, you don't know how to fly.");
You("plummet a few thousand feet to your death.");
Sprintf(g.killer.name,
Sprintf(gk.killer.name,
"teleported out of the dungeon and fell to %s death",
uhis());
g.killer.format = NO_KILLER_PREFIX;
gk.killer.format = NO_KILLER_PREFIX;
}
}
if (g.killer.name[0]) { /* the chosen destination was not survivable */
if (gk.killer.name[0]) { /* the chosen destination was not survivable */
d_level lsav;
/* set specific death location; this also suppresses bones */
@@ -1069,7 +1069,7 @@ level_tele(void)
/* wizard mode menu; no further validation needed */
;
} else if (u.uz.dnum == medusa_level.dnum
&& newlev >= g.dungeons[u.uz.dnum].depth_start
&& newlev >= gd.dungeons[u.uz.dnum].depth_start
+ dunlevs_in_dungeon(&u.uz)) {
find_hell(&newlevel);
} else {
@@ -1080,7 +1080,7 @@ level_tele(void)
d_level *qbranch = In_quest(&u.uz) ? &qstart_level
: In_mines(&u.uz) ? &mineend_level
: &sanctum_level;
int deepest = g.dungeons[qbranch->dnum].depth_start
int deepest = gd.dungeons[qbranch->dnum].depth_start
+ dunlevs_in_dungeon(qbranch) - 1;
/* if invocation did not yet occur, teleporting into
@@ -1113,7 +1113,7 @@ level_tele(void)
/* in case player just read a scroll and is about to be asked to
call it something, we can't defer until the end of the turn */
if (u.utotype && !g.context.mon_moving)
if (u.utotype && !gc.context.mon_moving)
deferred_goto();
}
@@ -1230,25 +1230,25 @@ rloc_pos_ok(
yy = mtmp->my;
if (!xx) {
/* no current location (migrating monster arrival) */
if (g.dndest.nlx && On_W_tower_level(&u.uz))
if (gd.dndest.nlx && On_W_tower_level(&u.uz))
return (((yy & 2) != 0)
/* inside xor not within */
^ !within_bounded_area(x, y, g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy));
if (g.updest.lx && (yy & 1) != 0) /* moving up */
return (within_bounded_area(x, y, g.updest.lx, g.updest.ly,
g.updest.hx, g.updest.hy)
&& (!g.updest.nlx
^ !within_bounded_area(x, y, gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy));
if (gu.updest.lx && (yy & 1) != 0) /* moving up */
return (within_bounded_area(x, y, gu.updest.lx, gu.updest.ly,
gu.updest.hx, gu.updest.hy)
&& (!gu.updest.nlx
|| !within_bounded_area(x, y,
g.updest.nlx, g.updest.nly,
g.updest.nhx, g.updest.nhy)));
if (g.dndest.lx && (yy & 1) == 0) /* moving down */
return (within_bounded_area(x, y, g.dndest.lx, g.dndest.ly,
g.dndest.hx, g.dndest.hy)
&& (!g.dndest.nlx
gu.updest.nlx, gu.updest.nly,
gu.updest.nhx, gu.updest.nhy)));
if (gd.dndest.lx && (yy & 1) == 0) /* moving down */
return (within_bounded_area(x, y, gd.dndest.lx, gd.dndest.ly,
gd.dndest.hx, gd.dndest.hy)
&& (!gd.dndest.nlx
|| !within_bounded_area(x, y,
g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy)));
gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy)));
} else {
/* [try to] prevent a shopkeeper or temple priest from being
sent out of his room (caller might resort to goodpos() if
@@ -1288,7 +1288,7 @@ rloc_to_core(
boolean preventmsg = (rlocflags & RLOC_NOMSG) != 0;
boolean vanishmsg = (rlocflags & RLOC_MSG) != 0;
boolean appearmsg = (mtmp->mstrategy & STRAT_APPEARMSG) != 0;
boolean domsg = !g.in_mklev && (vanishmsg || appearmsg) && !preventmsg;
boolean domsg = !gi.in_mklev && (vanishmsg || appearmsg) && !preventmsg;
boolean telemsg = FALSE;
if (x == mtmp->mx && y == mtmp->my && m_at(x, y) == mtmp)
@@ -1365,7 +1365,7 @@ rloc_to_core(
make_angry_shk(mtmp, oldx, oldy);
/* if hero is busy, maybe stop occupation */
if (g.occupation)
if (go.occupation)
(void) dochugw(mtmp, FALSE);
/* trapped monster teleported away */
@@ -1391,7 +1391,7 @@ rloc_to_flag(
static stairway *
stairway_find_forwiz(boolean isladder, boolean up)
{
stairway *stway = g.stairs;
stairway *stway = gs.stairs;
while (stway && !(stway->isladder == isladder
&& stway->up == up && stway->tolev.dnum == u.uz.dnum))
@@ -1624,7 +1624,7 @@ rloco(register struct obj* obj)
obj_extract_self(obj);
otx = obj->ox;
oty = obj->oy;
restricted_fall = (otx == 0 && g.dndest.lx);
restricted_fall = (otx == 0 && gd.dndest.lx);
do {
tx = rn1(COLNO - 3, 2);
ty = rn2(ROWNO);
@@ -1632,20 +1632,20 @@ rloco(register struct obj* obj)
break;
} while (!goodpos(tx, ty, (struct monst *) 0, 0)
|| (restricted_fall
&& (!within_bounded_area(tx, ty, g.dndest.lx, g.dndest.ly,
g.dndest.hx, g.dndest.hy)
|| (g.dndest.nlx
&& (!within_bounded_area(tx, ty, gd.dndest.lx, gd.dndest.ly,
gd.dndest.hx, gd.dndest.hy)
|| (gd.dndest.nlx
&& within_bounded_area(tx, ty,
g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy))))
gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy))))
/* on the Wizard Tower levels, objects inside should
stay inside and objects outside should stay outside */
|| (g.dndest.nlx && On_W_tower_level(&u.uz)
&& within_bounded_area(tx, ty, g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy)
|| (gd.dndest.nlx && On_W_tower_level(&u.uz)
&& within_bounded_area(tx, ty, gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy)
!= within_bounded_area(otx, oty,
g.dndest.nlx, g.dndest.nly,
g.dndest.nhx, g.dndest.nhy)));
gd.dndest.nlx, gd.dndest.nly,
gd.dndest.nhx, gd.dndest.nhy)));
if (flooreffects(obj, tx, ty, "fall")) {
/* update old location since flooreffects() couldn't;
@@ -1731,12 +1731,12 @@ random_teleport_level(void)
no one can randomly teleport past it */
if (dunlev_reached(&u.uz) < qlocate_depth)
bottom = qlocate_depth;
min_depth = g.dungeons[u.uz.dnum].depth_start;
max_depth = bottom + (g.dungeons[u.uz.dnum].depth_start - 1);
min_depth = gd.dungeons[u.uz.dnum].depth_start;
max_depth = bottom + (gd.dungeons[u.uz.dnum].depth_start - 1);
} else {
min_depth = 1;
max_depth = dunlevs_in_dungeon(&u.uz)
+ (g.dungeons[u.uz.dnum].depth_start - 1);
+ (gd.dungeons[u.uz.dnum].depth_start - 1);
/* can't reach Sanctum if the invocation hasn't been performed */
if (Inhell && !u.uevent.invoked)
max_depth -= 1;