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

@@ -150,14 +150,14 @@ mkshop(void)
}
gottype:
for (sroom = &g.rooms[0];; sroom++) {
for (sroom = &gr.rooms[0];; sroom++) {
/* return from this loop: cannot find any eligible room to be a shop
* continue: sroom is ineligible
* break: sroom is eligible
*/
if (sroom->hx < 0)
return;
if (sroom - g.rooms >= g.nroom) {
if (sroom - gr.rooms >= gn.nroom) {
impossible("rooms[] not closed by -1?");
return;
}
@@ -215,11 +215,11 @@ static struct mkroom *
pick_room(boolean strict)
{
register struct mkroom *sroom;
register int i = g.nroom;
register int i = gn.nroom;
for (sroom = &g.rooms[rn2(g.nroom)]; i--; sroom++) {
if (sroom == &g.rooms[g.nroom])
sroom = &g.rooms[0];
for (sroom = &gr.rooms[rn2(gn.nroom)]; i--; sroom++) {
if (sroom == &gr.rooms[gn.nroom])
sroom = &gr.rooms[0];
if (sroom->hx < 0)
return (struct mkroom *) 0;
if (sroom->rtype != OROOM)
@@ -274,7 +274,7 @@ fill_zoo(struct mkroom* sroom)
register int sx, sy, i;
int sh, goldlim = 0, type = sroom->rtype;
coordxy tx = 0, ty = 0;
int rmno = (int) ((sroom - g.rooms) + ROOMOFFSET);
int rmno = (int) ((sroom - gr.rooms) + ROOMOFFSET);
coord mm;
/* Note: This doesn't check needfill; it assumes the caller has already
@@ -282,7 +282,7 @@ fill_zoo(struct mkroom* sroom)
sh = sroom->fdoor;
switch (type) {
case COURT:
if (g.level.flags.is_maze_lev) {
if (gl.level.flags.is_maze_lev) {
for (tx = sroom->lx; tx <= sroom->hx; tx++)
for (ty = sroom->ly; ty <= sroom->hy; ty++)
if (IS_THRONE(levl[tx][ty].typ))
@@ -320,15 +320,15 @@ fill_zoo(struct mkroom* sroom)
if (sroom->irregular) {
if ((int) levl[sx][sy].roomno != rmno || levl[sx][sy].edge
|| (sroom->doorct
&& distmin(sx, sy, g.doors[sh].x, g.doors[sh].y) <= 1))
&& distmin(sx, sy, gd.doors[sh].x, gd.doors[sh].y) <= 1))
continue;
} else if (!SPACE_POS(levl[sx][sy].typ)
|| (sroom->doorct
&& ((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)
&& ((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
&& g.doors[sh].y == sy + 1))))
&& gd.doors[sh].y == sy + 1))))
continue;
/* don't place monster on explicitly placed throne */
if (type == COURT && IS_THRONE(levl[sx][sy].typ))
@@ -362,7 +362,7 @@ fill_zoo(struct mkroom* sroom)
case ZOO:
case LEPREHALL:
if (sroom->doorct) {
int distval = dist2(sx, sy, g.doors[sh].x, g.doors[sh].y);
int distval = dist2(sx, sy, gd.doors[sh].x, gd.doors[sh].y);
i = sq(distval);
} else
i = goldlim;
@@ -421,23 +421,23 @@ fill_zoo(struct mkroom* sroom)
add_to_container(chest, gold);
chest->owt = weight(chest);
chest->spe = 2; /* so it can be found later */
g.level.flags.has_court = 1;
gl.level.flags.has_court = 1;
break;
}
case BARRACKS:
g.level.flags.has_barracks = 1;
gl.level.flags.has_barracks = 1;
break;
case ZOO:
g.level.flags.has_zoo = 1;
gl.level.flags.has_zoo = 1;
break;
case MORGUE:
g.level.flags.has_morgue = 1;
gl.level.flags.has_morgue = 1;
break;
case SWAMP:
g.level.flags.has_swamp = 1;
gl.level.flags.has_swamp = 1;
break;
case BEEHIVE:
g.level.flags.has_beehive = 1;
gl.level.flags.has_beehive = 1;
break;
}
}
@@ -462,7 +462,7 @@ mkundead(
|| !revive(otmp, FALSE)))
(void) makemon(mdat, cc.x, cc.y, mm_flags);
}
g.level.flags.graveyard = TRUE; /* reduced chance for undead corpse */
gl.level.flags.graveyard = TRUE; /* reduced chance for undead corpse */
}
static struct permonst *
@@ -511,9 +511,9 @@ antholemon(void)
break;
}
/* try again if chosen type has been genocided or used up */
} while (++trycnt < 3 && (g.mvitals[mtyp].mvflags & G_GONE));
} while (++trycnt < 3 && (gm.mvitals[mtyp].mvflags & G_GONE));
return ((g.mvitals[mtyp].mvflags & G_GONE) ? (struct permonst *) 0
return ((gm.mvitals[mtyp].mvflags & G_GONE) ? (struct permonst *) 0
: &mons[mtyp]);
}
@@ -526,12 +526,12 @@ mkswamp(void) /* Michiel Huisjes & Fred de Wilde */
int rmno;
for (i = 0; i < 5; i++) { /* turn up to 5 rooms swampy */
sroom = &g.rooms[rn2(g.nroom)];
sroom = &gr.rooms[rn2(gn.nroom)];
if (sroom->hx < 0 || sroom->rtype != OROOM || has_upstairs(sroom)
|| has_dnstairs(sroom))
continue;
rmno = (int)(sroom - g.rooms) + ROOMOFFSET;
rmno = (int)(sroom - gr.rooms) + ROOMOFFSET;
/* satisfied; make a swamp */
sroom->rtype = SWAMP;
@@ -559,7 +559,7 @@ mkswamp(void) /* Michiel Huisjes & Fred de Wilde */
NO_MM_FLAGS);
}
}
g.level.flags.has_swamp = 1;
gl.level.flags.has_swamp = 1;
}
}
@@ -568,7 +568,7 @@ shrine_pos(int roomno)
{
static coord buf;
int delta;
struct mkroom *troom = &g.rooms[roomno - ROOMOFFSET];
struct mkroom *troom = &gr.rooms[roomno - ROOMOFFSET];
/* if width and height are odd, placement will be the exact center;
if either or both are even, center point is a hypothetical spot
@@ -600,13 +600,13 @@ mktemple(void)
* In temples, shrines are blessed altars
* located in the center of the room
*/
shrine_spot = shrine_pos((int) ((sroom - g.rooms) + ROOMOFFSET));
shrine_spot = shrine_pos((int) ((sroom - gr.rooms) + ROOMOFFSET));
lev = &levl[shrine_spot->x][shrine_spot->y];
lev->typ = ALTAR;
lev->altarmask = induced_align(80);
priestini(&u.uz, sroom, shrine_spot->x, shrine_spot->y, FALSE);
lev->altarmask |= AM_SHRINE;
g.level.flags.has_temple = 1;
gl.level.flags.has_temple = 1;
}
boolean
@@ -629,7 +629,7 @@ nexttodoor(int sx, int sy)
boolean
has_dnstairs(struct mkroom* sroom)
{
stairway *stway = g.stairs;
stairway *stway = gs.stairs;
while (stway) {
if (!stway->up && inside_room(sroom, stway->sx, stway->sy))
@@ -642,7 +642,7 @@ has_dnstairs(struct mkroom* sroom)
boolean
has_upstairs(struct mkroom* sroom)
{
stairway *stway = g.stairs;
stairway *stway = gs.stairs;
while (stway) {
if (stway->up && inside_room(sroom, stway->sx, stway->sy))
@@ -668,7 +668,7 @@ boolean
inside_room(struct mkroom* croom, coordxy x, coordxy y)
{
if (croom->irregular) {
int i = (int) ((croom - g.rooms) + ROOMOFFSET);
int i = (int) ((croom - gr.rooms) + ROOMOFFSET);
return (!levl[x][y].edge && (int) levl[x][y].roomno == i);
}
@@ -687,7 +687,7 @@ somexy(struct mkroom* croom,coord * c)
int i;
if (croom->irregular) {
i = (int) ((croom - g.rooms) + ROOMOFFSET);
i = (int) ((croom - gr.rooms) + ROOMOFFSET);
while (try_cnt++ < 100) {
c->x = somex(croom);
@@ -756,12 +756,12 @@ search_special(schar type)
{
register struct mkroom *croom;
for (croom = &g.rooms[0]; croom->hx >= 0; croom++)
for (croom = &gr.rooms[0]; croom->hx >= 0; croom++)
if ((type == ANY_TYPE && croom->rtype != OROOM)
|| (type == ANY_SHOP && croom->rtype >= SHOPBASE)
|| croom->rtype == type)
return croom;
for (croom = &g.subrooms[0]; croom->hx >= 0; croom++)
for (croom = &gs.subrooms[0]; croom->hx >= 0; croom++)
if ((type == ANY_TYPE && croom->rtype != OROOM)
|| (type == ANY_SHOP && croom->rtype >= SHOPBASE)
|| croom->rtype == type)
@@ -820,7 +820,7 @@ squadmon(void)
}
mndx = squadprob[rn2(SIZE(squadprob))].pm;
gotone:
if (!(g.mvitals[mndx].mvflags & G_GONE))
if (!(gm.mvitals[mndx].mvflags & G_GONE))
return &mons[mndx];
else
return (struct permonst *) 0;
@@ -838,7 +838,7 @@ save_room(NHFILE* nhfp, struct mkroom* r)
/*
* Well, I really should write only useful information instead
* of writing the whole structure. That is I should not write
* the g.subrooms pointers, but who cares ?
* the gs.subrooms pointers, but who cares ?
*/
if (nhfp->structlevel)
bwrite(nhfp->fd, (genericptr_t) r, sizeof (struct mkroom));
@@ -857,9 +857,9 @@ save_rooms(NHFILE* nhfp)
/* First, write the number of rooms */
if (nhfp->structlevel)
bwrite(nhfp->fd, (genericptr_t) &g.nroom, sizeof(g.nroom));
for (i = 0; i < g.nroom; i++)
save_room(nhfp, &g.rooms[i]);
bwrite(nhfp->fd, (genericptr_t) &gn.nroom, sizeof(gn.nroom));
for (i = 0; i < gn.nroom; i++)
save_room(nhfp, &gr.rooms[i]);
}
static void
@@ -871,9 +871,9 @@ rest_room(NHFILE* nhfp, struct mkroom* r)
mread(nhfp->fd, (genericptr_t) r, sizeof(struct mkroom));
for (i = 0; i < r->nsubrooms; i++) {
r->sbrooms[i] = &g.subrooms[g.nsubroom];
rest_room(nhfp, &g.subrooms[g.nsubroom]);
g.subrooms[g.nsubroom++].resident = (struct monst *) 0;
r->sbrooms[i] = &gs.subrooms[gn.nsubroom];
rest_room(nhfp, &gs.subrooms[gn.nsubroom]);
gs.subrooms[gn.nsubroom++].resident = (struct monst *) 0;
}
}
@@ -887,15 +887,15 @@ rest_rooms(NHFILE* nhfp)
short i;
if (nhfp->structlevel)
mread(nhfp->fd, (genericptr_t) &g.nroom, sizeof(g.nroom));
mread(nhfp->fd, (genericptr_t) &gn.nroom, sizeof(gn.nroom));
g.nsubroom = 0;
for (i = 0; i < g.nroom; i++) {
rest_room(nhfp, &g.rooms[i]);
g.rooms[i].resident = (struct monst *) 0;
gn.nsubroom = 0;
for (i = 0; i < gn.nroom; i++) {
rest_room(nhfp, &gr.rooms[i]);
gr.rooms[i].resident = (struct monst *) 0;
}
g.rooms[g.nroom].hx = -1; /* restore ending flags */
g.subrooms[g.nsubroom].hx = -1;
gr.rooms[gn.nroom].hx = -1; /* restore ending flags */
gs.subrooms[gn.nsubroom].hx = -1;
}
/* convert a display symbol for terrain into topology type;
@@ -1039,8 +1039,8 @@ static boolean
invalid_shop_shape(struct mkroom *sroom)
{
coordxy x, y;
coordxy doorx = g.doors[sroom->fdoor].x;
coordxy doory = g.doors[sroom->fdoor].y;
coordxy doorx = gd.doors[sroom->fdoor].x;
coordxy doory = gd.doors[sroom->fdoor].y;
coordxy insidex = 0, insidey = 0, insidect = 0;
/* First, identify squares inside the room and next to the door. */