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:
@@ -49,20 +49,20 @@ roguecorr(coordxy x, coordxy y, int dir)
|
||||
register coordxy fromx, fromy, tox, toy;
|
||||
|
||||
if (dir == XL_DOWN) {
|
||||
g.r[x][y].doortable &= ~XL_DOWN;
|
||||
if (!g.r[x][y].real) {
|
||||
fromx = g.r[x][y].rlx;
|
||||
fromy = g.r[x][y].rly;
|
||||
gr.r[x][y].doortable &= ~XL_DOWN;
|
||||
if (!gr.r[x][y].real) {
|
||||
fromx = gr.r[x][y].rlx;
|
||||
fromy = gr.r[x][y].rly;
|
||||
fromx += 1 + 26 * x;
|
||||
fromy += 7 * y;
|
||||
} else {
|
||||
fromx = g.r[x][y].rlx + rn2(g.r[x][y].dx);
|
||||
fromy = g.r[x][y].rly + g.r[x][y].dy;
|
||||
fromx = gr.r[x][y].rlx + rn2(gr.r[x][y].dx);
|
||||
fromy = gr.r[x][y].rly + gr.r[x][y].dy;
|
||||
fromx += 1 + 26 * x;
|
||||
fromy += 7 * y;
|
||||
if (!IS_WALL(levl[fromx][fromy].typ))
|
||||
impossible("down: no wall at %d,%d?", fromx, fromy);
|
||||
dodoor(fromx, fromy, &g.rooms[g.r[x][y].nroom]);
|
||||
dodoor(fromx, fromy, &gr.rooms[gr.r[x][y].nroom]);
|
||||
levl[fromx][fromy].doormask = D_NODOOR;
|
||||
fromy++;
|
||||
}
|
||||
@@ -71,40 +71,40 @@ roguecorr(coordxy x, coordxy y, int dir)
|
||||
return;
|
||||
}
|
||||
y++;
|
||||
g.r[x][y].doortable &= ~XL_UP;
|
||||
if (!g.r[x][y].real) {
|
||||
tox = g.r[x][y].rlx;
|
||||
toy = g.r[x][y].rly;
|
||||
gr.r[x][y].doortable &= ~XL_UP;
|
||||
if (!gr.r[x][y].real) {
|
||||
tox = gr.r[x][y].rlx;
|
||||
toy = gr.r[x][y].rly;
|
||||
tox += 1 + 26 * x;
|
||||
toy += 7 * y;
|
||||
} else {
|
||||
tox = g.r[x][y].rlx + rn2(g.r[x][y].dx);
|
||||
toy = g.r[x][y].rly - 1;
|
||||
tox = gr.r[x][y].rlx + rn2(gr.r[x][y].dx);
|
||||
toy = gr.r[x][y].rly - 1;
|
||||
tox += 1 + 26 * x;
|
||||
toy += 7 * y;
|
||||
if (!IS_WALL(levl[tox][toy].typ))
|
||||
impossible("up: no wall at %d,%d?", tox, toy);
|
||||
dodoor(tox, toy, &g.rooms[g.r[x][y].nroom]);
|
||||
dodoor(tox, toy, &gr.rooms[gr.r[x][y].nroom]);
|
||||
levl[tox][toy].doormask = D_NODOOR;
|
||||
toy--;
|
||||
}
|
||||
roguejoin(fromx, fromy, tox, toy, FALSE);
|
||||
return;
|
||||
} else if (dir == XL_RIGHT) {
|
||||
g.r[x][y].doortable &= ~XL_RIGHT;
|
||||
if (!g.r[x][y].real) {
|
||||
fromx = g.r[x][y].rlx;
|
||||
fromy = g.r[x][y].rly;
|
||||
gr.r[x][y].doortable &= ~XL_RIGHT;
|
||||
if (!gr.r[x][y].real) {
|
||||
fromx = gr.r[x][y].rlx;
|
||||
fromy = gr.r[x][y].rly;
|
||||
fromx += 1 + 26 * x;
|
||||
fromy += 7 * y;
|
||||
} else {
|
||||
fromx = g.r[x][y].rlx + g.r[x][y].dx;
|
||||
fromy = g.r[x][y].rly + rn2(g.r[x][y].dy);
|
||||
fromx = gr.r[x][y].rlx + gr.r[x][y].dx;
|
||||
fromy = gr.r[x][y].rly + rn2(gr.r[x][y].dy);
|
||||
fromx += 1 + 26 * x;
|
||||
fromy += 7 * y;
|
||||
if (!IS_WALL(levl[fromx][fromy].typ))
|
||||
impossible("down: no wall at %d,%d?", fromx, fromy);
|
||||
dodoor(fromx, fromy, &g.rooms[g.r[x][y].nroom]);
|
||||
dodoor(fromx, fromy, &gr.rooms[gr.r[x][y].nroom]);
|
||||
levl[fromx][fromy].doormask = D_NODOOR;
|
||||
fromx++;
|
||||
}
|
||||
@@ -113,20 +113,20 @@ roguecorr(coordxy x, coordxy y, int dir)
|
||||
return;
|
||||
}
|
||||
x++;
|
||||
g.r[x][y].doortable &= ~XL_LEFT;
|
||||
if (!g.r[x][y].real) {
|
||||
tox = g.r[x][y].rlx;
|
||||
toy = g.r[x][y].rly;
|
||||
gr.r[x][y].doortable &= ~XL_LEFT;
|
||||
if (!gr.r[x][y].real) {
|
||||
tox = gr.r[x][y].rlx;
|
||||
toy = gr.r[x][y].rly;
|
||||
tox += 1 + 26 * x;
|
||||
toy += 7 * y;
|
||||
} else {
|
||||
tox = g.r[x][y].rlx - 1;
|
||||
toy = g.r[x][y].rly + rn2(g.r[x][y].dy);
|
||||
tox = gr.r[x][y].rlx - 1;
|
||||
toy = gr.r[x][y].rly + rn2(gr.r[x][y].dy);
|
||||
tox += 1 + 26 * x;
|
||||
toy += 7 * y;
|
||||
if (!IS_WALL(levl[tox][toy].typ))
|
||||
impossible("left: no wall at %d,%d?", tox, toy);
|
||||
dodoor(tox, toy, &g.rooms[g.r[x][y].nroom]);
|
||||
dodoor(tox, toy, &gr.rooms[gr.r[x][y].nroom]);
|
||||
levl[tox][toy].doormask = D_NODOOR;
|
||||
tox--;
|
||||
}
|
||||
@@ -146,18 +146,18 @@ miniwalk(coordxy x, coordxy y)
|
||||
|
||||
while (1) {
|
||||
q = 0;
|
||||
#define doorhere (g.r[x][y].doortable)
|
||||
#define doorhere (gr.r[x][y].doortable)
|
||||
if (x > 0 && (!(doorhere & XL_LEFT))
|
||||
&& (!g.r[x - 1][y].doortable || !rn2(10)))
|
||||
&& (!gr.r[x - 1][y].doortable || !rn2(10)))
|
||||
dirs[q++] = 0;
|
||||
if (x < 2 && (!(doorhere & XL_RIGHT))
|
||||
&& (!g.r[x + 1][y].doortable || !rn2(10)))
|
||||
&& (!gr.r[x + 1][y].doortable || !rn2(10)))
|
||||
dirs[q++] = 1;
|
||||
if (y > 0 && (!(doorhere & XL_UP))
|
||||
&& (!g.r[x][y - 1].doortable || !rn2(10)))
|
||||
&& (!gr.r[x][y - 1].doortable || !rn2(10)))
|
||||
dirs[q++] = 2;
|
||||
if (y < 2 && (!(doorhere & XL_DOWN))
|
||||
&& (!g.r[x][y + 1].doortable || !rn2(10)))
|
||||
&& (!gr.r[x][y + 1].doortable || !rn2(10)))
|
||||
dirs[q++] = 3;
|
||||
/* Rogue levels aren't just 3 by 3 mazes; they have some extra
|
||||
* connections, thus that 1/10 chance
|
||||
@@ -212,15 +212,15 @@ makeroguerooms(void)
|
||||
* Room height may be 2-4 (2-5 on last row), length 2-23 (not
|
||||
* counting walls).
|
||||
*/
|
||||
#define here g.r[x][y]
|
||||
#define here gr.r[x][y]
|
||||
|
||||
g.nroom = 0;
|
||||
gn.nroom = 0;
|
||||
for (y = 0; y < 3; y++)
|
||||
for (x = 0; x < 3; x++) {
|
||||
/* Note: we want to insure at least 1 room. So, if the
|
||||
* first 8 are all dummies, force the last to be a room.
|
||||
*/
|
||||
if (!rn2(5) && (g.nroom || (x < 2 && y < 2))) {
|
||||
if (!rn2(5) && (gn.nroom || (x < 2 && y < 2))) {
|
||||
/* Arbitrary: dummy rooms may only go where real
|
||||
* ones do.
|
||||
*/
|
||||
@@ -235,19 +235,19 @@ makeroguerooms(void)
|
||||
/* boundaries of room floor */
|
||||
here.rlx = rnd(23 - here.dx + 1);
|
||||
here.rly = rnd(((y == 2) ? 5 : 4) - here.dy + 1);
|
||||
g.nroom++;
|
||||
gn.nroom++;
|
||||
}
|
||||
here.doortable = 0;
|
||||
}
|
||||
miniwalk(rn2(3), rn2(3));
|
||||
g.nroom = 0;
|
||||
gn.nroom = 0;
|
||||
for (y = 0; y < 3; y++)
|
||||
for (x = 0; x < 3; x++) {
|
||||
if (here.real) { /* Make a room */
|
||||
coordxy lowx, lowy, hix, hiy;
|
||||
|
||||
g.r[x][y].nroom = g.nroom;
|
||||
g.smeq[g.nroom] = g.nroom;
|
||||
gr.r[x][y].nroom = gn.nroom;
|
||||
gs.smeq[gn.nroom] = gn.nroom;
|
||||
|
||||
lowx = 1 + 26 * x + here.rlx;
|
||||
lowy = 7 * y + here.rly;
|
||||
@@ -295,9 +295,9 @@ makerogueghost(void)
|
||||
struct mkroom *croom;
|
||||
coordxy x, y;
|
||||
|
||||
if (!g.nroom)
|
||||
if (!gn.nroom)
|
||||
return; /* Should never happen */
|
||||
croom = &g.rooms[rn2(g.nroom)];
|
||||
croom = &gr.rooms[rn2(gn.nroom)];
|
||||
x = somex(croom);
|
||||
y = somey(croom);
|
||||
if (!(ghost = makemon(&mons[PM_GHOST], x, y, NO_MM_FLAGS)))
|
||||
|
||||
Reference in New Issue
Block a user