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

@@ -409,7 +409,7 @@ shkveg(void)
j = maxprob = 0;
ok[0] = 0; /* lint suppression */
for (i = g.bases[(int) oclass]; i < NUM_OBJECTS; ++i) {
for (i = gb.bases[(int) oclass]; i < NUM_OBJECTS; ++i) {
if (objects[i].oc_class != oclass)
break;
@@ -459,7 +459,7 @@ mkshobj_at(const struct shclass* shp, int sx, int sy, boolean mkspecl)
struct obj *novel = mksobj_at(SPE_NOVEL, sx, sy, FALSE, FALSE);
if (novel)
g.context.tribute.bookstock = TRUE;
gc.context.tribute.bookstock = TRUE;
return;
}
@@ -579,12 +579,12 @@ shkinit(const struct shclass* shp, struct mkroom* sroom)
/* place the shopkeeper in the given room */
sh = sroom->fdoor;
sx = g.doors[sh].x;
sy = g.doors[sh].y;
sx = gd.doors[sh].x;
sy = gd.doors[sh].y;
/* check that the shopkeeper placement is sane */
if (sroom->irregular) {
int rmno = (int) ((sroom - g.rooms) + ROOMOFFSET);
int rmno = (int) ((sroom - gr.rooms) + ROOMOFFSET);
if (isok(sx - 1, sy) && !levl[sx - 1][sy].edge
&& (int) levl[sx - 1][sy].roomno == rmno)
@@ -619,10 +619,10 @@ shkinit(const struct shclass* shp, struct mkroom* sroom)
impossible("Where is shopdoor?");
pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly, sroom->hx,
sroom->hy);
pline("doormax=%d doorct=%d fdoor=%d", g.doorindex, sroom->doorct,
pline("doormax=%d doorct=%d fdoor=%d", gd.doorindex, sroom->doorct,
sh);
while (j--) {
pline("door [%d,%d]", g.doors[sh].x, g.doors[sh].y);
pline("door [%d,%d]", gd.doors[sh].x, gd.doors[sh].y);
sh++;
}
display_nhwindow(WIN_MESSAGE, FALSE);
@@ -642,11 +642,11 @@ shkinit(const struct shclass* shp, struct mkroom* sroom)
set_malign(shk);
shk->msleeping = 0;
mon_learns_traps(shk, ALL_TRAPS); /* we know all the traps already */
eshkp->shoproom = (schar) ((sroom - g.rooms) + ROOMOFFSET);
eshkp->shoproom = (schar) ((sroom - gr.rooms) + ROOMOFFSET);
sroom->resident = shk;
eshkp->shoptype = sroom->rtype;
assign_level(&eshkp->shoplevel, &u.uz);
eshkp->shd = g.doors[sh];
eshkp->shd = gd.doors[sh];
eshkp->shk.x = sx;
eshkp->shk.y = sy;
eshkp->robbed = eshkp->credit = eshkp->debit = eshkp->loan = 0L;
@@ -668,12 +668,12 @@ stock_room_goodpos(struct mkroom* sroom, int rmno, int sh, int sx, int sy)
if (sroom->irregular) {
if (levl[sx][sy].edge
|| (int) levl[sx][sy].roomno != rmno
|| distmin(sx, sy, g.doors[sh].x, g.doors[sh].y) <= 1)
|| distmin(sx, sy, gd.doors[sh].x, gd.doors[sh].y) <= 1)
return FALSE;
} else if ((sx == sroom->lx && g.doors[sh].x == sx - 1)
|| (sx == sroom->hx && g.doors[sh].x == sx + 1)
|| (sy == sroom->ly && g.doors[sh].y == sy - 1)
|| (sy == sroom->hy && g.doors[sh].y == sy + 1))
} else if ((sx == sroom->lx && gd.doors[sh].x == sx - 1)
|| (sx == sroom->hx && gd.doors[sh].x == sx + 1)
|| (sy == sroom->ly && gd.doors[sh].y == sy - 1)
|| (sy == sroom->hy && gd.doors[sh].y == sy + 1))
return FALSE;
/* only generate items on solid floor squares */
@@ -697,7 +697,7 @@ stock_room(int shp_indx, register struct mkroom* sroom)
int sx, sy, sh;
int stockcount = 0, specialspot = 0;
char buf[BUFSZ];
int rmno = (int) ((sroom - g.rooms) + ROOMOFFSET);
int rmno = (int) ((sroom - gr.rooms) + ROOMOFFSET);
const struct shclass *shp = &shtypes[shp_indx];
/* first, try to place a shopkeeper in the room */
@@ -705,8 +705,8 @@ stock_room(int shp_indx, register struct mkroom* sroom)
return;
/* make sure no doorways without doors, and no trapped doors, in shops */
sx = g.doors[sroom->fdoor].x;
sy = g.doors[sroom->fdoor].y;
sx = gd.doors[sroom->fdoor].x;
sy = gd.doors[sroom->fdoor].y;
if (levl[sx][sy].doormask == D_NODOOR) {
levl[sx][sy].doormask = D_ISOPEN;
newsym(sx, sy);
@@ -733,7 +733,7 @@ stock_room(int shp_indx, register struct mkroom* sroom)
make_engr_at(m, n, buf, 0L, DUST);
}
if (g.context.tribute.enabled && !g.context.tribute.bookstock) {
if (gc.context.tribute.enabled && !gc.context.tribute.bookstock) {
/*
* Out of the number of spots where we're actually
* going to put stuff, randomly single out one in particular.
@@ -765,7 +765,7 @@ stock_room(int shp_indx, register struct mkroom* sroom)
mongone(mtmp);
}
g.level.flags.has_shop = TRUE;
gl.level.flags.has_shop = TRUE;
}
/* does shkp's shop stock this item type? */
@@ -838,7 +838,7 @@ shkname(struct monst* mtmp)
} else {
const char *shknm = ESHK(mtmp)->shknam;
if (Hallucination && !g.program_state.gameover) {
if (Hallucination && !gp.program_state.gameover) {
const char *const *nlp;
int num;