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

@@ -146,7 +146,7 @@ trapped_chest_at(int ttyp, coordxy x, coordxy y)
return TRUE;
/* in inventory, we need to find one which is actually trapped */
if (u_at(x, y)) {
for (otmp = g.invent; otmp; otmp = otmp->nobj)
for (otmp = gi.invent; otmp; otmp = otmp->nobj)
if (Is_box(otmp) && otmp->otrapped)
return TRUE;
if (u.usteed) { /* steed isn't on map so won't be found by m_at() */
@@ -255,13 +255,13 @@ check_map_spot(coordxy x, coordxy y, char oclass, unsigned material)
if (glyph_is_object(glyph)) {
/* there's some object shown here */
if (oclass == ALL_CLASSES) {
return !(g.level.objects[x][y] /* stale if nothing here */
return !(gl.level.objects[x][y] /* stale if nothing here */
|| ((mtmp = m_at(x, y)) != 0 && mtmp->minvent));
} else {
if (material
&& objects[glyph_to_obj(glyph)].oc_material == material) {
/* object shown here is of interest because material matches */
for (otmp = g.level.objects[x][y]; otmp; otmp = otmp->nexthere)
for (otmp = gl.level.objects[x][y]; otmp; otmp = otmp->nexthere)
if (o_material(otmp, GOLD))
return FALSE;
/* didn't find it; perhaps a monster is carrying it */
@@ -275,7 +275,7 @@ check_map_spot(coordxy x, coordxy y, char oclass, unsigned material)
}
if (oclass && objects[glyph_to_obj(glyph)].oc_class == oclass) {
/* obj shown here is of interest because its class matches */
for (otmp = g.level.objects[x][y]; otmp; otmp = otmp->nexthere)
for (otmp = gl.level.objects[x][y]; otmp; otmp = otmp->nexthere)
if (o_in(otmp, oclass))
return FALSE;
/* didn't find it; perhaps a monster is carrying it */
@@ -324,7 +324,7 @@ gold_detect(struct obj *sobj)
boolean stale, ugold = FALSE, steedgold = FALSE;
int ter_typ = TER_DETECT | TER_OBJ;
g.known = stale = clear_stale_map(COIN_CLASS,
gk.known = stale = clear_stale_map(COIN_CLASS,
(unsigned) (sobj->blessed ? GOLD : 0));
/* look for gold carried by monsters (might be in a container) */
@@ -335,7 +335,7 @@ gold_detect(struct obj *sobj)
if (mtmp == u.usteed) {
steedgold = TRUE;
} else {
g.known = TRUE;
gk.known = TRUE;
goto outgoldmap; /* skip further searching */
}
} else {
@@ -345,7 +345,7 @@ gold_detect(struct obj *sobj)
if (mtmp == u.usteed) {
steedgold = TRUE;
} else {
g.known = TRUE;
gk.known = TRUE;
goto outgoldmap; /* skip further searching */
}
}
@@ -355,25 +355,25 @@ gold_detect(struct obj *sobj)
/* look for gold objects */
for (obj = fobj; obj; obj = obj->nobj) {
if (sobj->blessed && o_material(obj, GOLD)) {
g.known = TRUE;
gk.known = TRUE;
if (obj->ox != u.ux || obj->oy != u.uy)
goto outgoldmap;
} else if (o_in(obj, COIN_CLASS)) {
g.known = TRUE;
gk.known = TRUE;
if (obj->ox != u.ux || obj->oy != u.uy)
goto outgoldmap;
}
}
if (!g.known) {
if (!gk.known) {
/* no gold found on floor or monster's inventory.
adjust message if you have gold in your inventory */
if (sobj) {
char buf[BUFSZ];
if (g.youmonst.data == &mons[PM_GOLD_GOLEM])
if (gy.youmonst.data == &mons[PM_GOLD_GOLEM])
Sprintf(buf, "You feel like a million %s!", currency(2L));
else if (money_cnt(g.invent) || hidden_gold(TRUE))
else if (money_cnt(gi.invent) || hidden_gold(TRUE))
Strcpy(buf,
"You feel worried about your future financial situation.");
else if (steedgold)
@@ -496,7 +496,7 @@ food_detect(struct obj *sobj)
}
if (!ct && !ctu) {
g.known = stale && !confused;
gk.known = stale && !confused;
if (stale) {
docrt();
You("sense a lack of %s nearby.", what);
@@ -524,7 +524,7 @@ food_detect(struct obj *sobj)
}
return !stale;
} else if (!ct) {
g.known = TRUE;
gk.known = TRUE;
You("%s %s nearby.", sobj ? "smell" : "sense", what);
if (sobj && sobj->blessed) {
if (!u.uedibility)
@@ -535,7 +535,7 @@ food_detect(struct obj *sobj)
struct obj *temp;
int ter_typ = TER_DETECT | TER_OBJ;
g.known = TRUE;
gk.known = TRUE;
cls();
(void) unconstrain_map();
for (obj = fobj; obj; obj = obj->nobj)
@@ -612,7 +612,7 @@ object_detect(struct obj *detector, /* object doing the detecting */
* We can exclude checking the buried obj chain for boulders below.
*/
sym = class ? def_oc_syms[class].sym : 0;
if (sym && sym == g.showsyms[SYM_BOULDER + SYM_OFF_X])
if (sym && sym == gs.showsyms[SYM_BOULDER + SYM_OFF_X])
boulder = ROCK_CLASS;
if (Hallucination || (Confusion && class == SCROLL_CLASS))
@@ -623,7 +623,7 @@ object_detect(struct obj *detector, /* object doing the detecting */
Strcat(stuff, " and/or large stones");
if (do_dknown)
for (obj = g.invent; obj; obj = obj->nobj)
for (obj = gi.invent; obj; obj = obj->nobj)
do_dknown_of(obj);
for (obj = fobj; obj; obj = obj->nobj) {
@@ -637,7 +637,7 @@ object_detect(struct obj *detector, /* object doing the detecting */
do_dknown_of(obj);
}
for (obj = g.level.buriedobjlist; obj; obj = obj->nobj) {
for (obj = gl.level.buriedobjlist; obj; obj = obj->nobj) {
if (!class || o_in(obj, class)) {
if (u_at(obj->ox, obj->oy))
ctu++;
@@ -685,7 +685,7 @@ object_detect(struct obj *detector, /* object doing the detecting */
/*
* Map all buried objects first.
*/
for (obj = g.level.buriedobjlist; obj; obj = obj->nobj)
for (obj = gl.level.buriedobjlist; obj; obj = obj->nobj)
if (!class || (otmp = o_in(obj, class)) != 0) {
if (class) {
if (otmp != obj) {
@@ -706,7 +706,7 @@ object_detect(struct obj *detector, /* object doing the detecting */
*/
for (x = 1; x < COLNO; x++)
for (y = 0; y < ROWNO; y++)
for (obj = g.level.objects[x][y]; obj; obj = obj->nexthere)
for (obj = gl.level.objects[x][y]; obj; obj = obj->nexthere)
if ((!class && !boulder) || (otmp = o_in(obj, class)) != 0
|| (otmp = o_in(obj, boulder)) != 0) {
if (class || boulder) {
@@ -933,20 +933,20 @@ display_trap_map(struct trap *ttmp, int cursed_src)
/* show chest traps first, so that subsequent floor trap display
will override if both types are present at the same location */
(void) detect_obj_traps(fobj, TRUE, cursed_src);
(void) detect_obj_traps(g.level.buriedobjlist, TRUE, cursed_src);
(void) detect_obj_traps(gl.level.buriedobjlist, TRUE, cursed_src);
for (mon = fmon; mon; mon = mon->nmon) {
if (DEADMONSTER(mon) || (mon->isgd && !mon->mx))
continue;
(void) detect_obj_traps(mon->minvent, TRUE, cursed_src);
}
(void) detect_obj_traps(g.invent, TRUE, cursed_src);
(void) detect_obj_traps(gi.invent, TRUE, cursed_src);
for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap)
for (ttmp = gf.ftrap; ttmp; ttmp = ttmp->ntrap)
sense_trap(ttmp, 0, 0, cursed_src);
dummytrap.ttyp = TRAPPED_DOOR;
for (door = 0; door < g.doorindex; door++) {
cc = g.doors[door];
for (door = 0; door < gd.doorindex; door++) {
cc = gd.doors[door];
if (levl[cc.x][cc.y].typ == SDOOR) /* see above */
continue;
if (levl[cc.x][cc.y].doormask & D_TRAPPED) {
@@ -988,7 +988,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
u.usteed->mx = u.ux, u.usteed->my = u.uy;
/* floor/ceiling traps */
for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap) {
for (ttmp = gf.ftrap; ttmp; ttmp = ttmp->ntrap) {
if (ttmp->tx != u.ux || ttmp->ty != u.uy) {
display_trap_map(ttmp, cursed_src);
return 0;
@@ -1003,7 +1003,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
} else
found = TRUE;
}
if ((tr = detect_obj_traps(g.level.buriedobjlist, FALSE, 0))
if ((tr = detect_obj_traps(gl.level.buriedobjlist, FALSE, 0))
!= OTRAP_NONE) {
if (tr & OTRAP_THERE) {
display_trap_map(ttmp, cursed_src);
@@ -1022,11 +1022,11 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
found = TRUE;
}
}
if (detect_obj_traps(g.invent, FALSE, 0) != OTRAP_NONE)
if (detect_obj_traps(gi.invent, FALSE, 0) != OTRAP_NONE)
found = TRUE;
/* door traps */
for (door = 0; door < g.doorindex; door++) {
cc = g.doors[door];
for (door = 0; door < gd.doorindex; door++) {
cc = gd.doors[door];
/* levl[][].doormask and .wall_info both overlay levl[][].flags;
the bit in doormask for D_TRAPPED is also a bit in wall_info;
secret doors use wall_info so can't be marked as trapped */
@@ -1183,7 +1183,7 @@ use_crystal_ball(struct obj **optr)
make_confused((HConfusion & TIMEOUT) + impair, FALSE);
break;
case 3:
if (!resists_blnd(&g.youmonst)) {
if (!resists_blnd(&gy.youmonst)) {
pline("%s your vision!", Tobjnam(obj, "damage"));
make_blinded((Blinded & TIMEOUT) + impair, FALSE);
if (!Blind)
@@ -1214,8 +1214,8 @@ use_crystal_ball(struct obj **optr)
if (Hallucination) {
nomul(-rnd(charged ? 4 : 2));
g.multi_reason = "gazing into a Magic 8-Ball (tm)";
g.nomovemsg = "";
gm.multi_reason = "gazing into a Magic 8-Ball (tm)";
gn.nomovemsg = "";
if (!charged) {
pline("All you see is funky %s haze.", hcolor((char *) 0));
@@ -1267,8 +1267,8 @@ use_crystal_ball(struct obj **optr)
You("peer into %s...", the(xname(obj)));
nomul(-rnd(charged ? 10 : 2));
g.multi_reason = "gazing into a crystal ball";
g.nomovemsg = "";
gm.multi_reason = "gazing into a crystal ball";
gn.nomovemsg = "";
if (!charged) {
pline_The("vision is unclear.");
@@ -1301,8 +1301,8 @@ use_crystal_ball(struct obj **optr)
ret = object_detect((struct obj *) 0, class);
} else if ((class = def_char_to_monclass(ch)) != MAXMCLASSES) {
ret = monster_detect((struct obj *) 0, class);
} else if (g.showsyms[SYM_BOULDER + SYM_OFF_X]
&& (ch == g.showsyms[SYM_BOULDER + SYM_OFF_X])) {
} else if (gs.showsyms[SYM_BOULDER + SYM_OFF_X]
&& (ch == gs.showsyms[SYM_BOULDER + SYM_OFF_X])) {
ret = object_detect((struct obj *) 0, ROCK_CLASS);
} else if (ch == '^') {
ret = trap_detect((struct obj *) 0);
@@ -1350,7 +1350,7 @@ show_map_spot(coordxy x, coordxy y)
* opposite to how normal vision behaves.
*/
oldglyph = glyph_at(x, y);
if (g.level.flags.hero_memory) {
if (gl.level.flags.hero_memory) {
magic_map_background(x, y, 0);
newsym(x, y); /* show it, if not blocked */
} else {
@@ -1361,7 +1361,7 @@ show_map_spot(coordxy x, coordxy y)
map_trap(t, 1);
} else if (glyph_is_trap(oldglyph) || glyph_is_object(oldglyph)) {
show_glyph(x, y, oldglyph);
if (g.level.flags.hero_memory)
if (gl.level.flags.hero_memory)
lev->glyph = oldglyph;
}
}
@@ -1378,7 +1378,7 @@ do_mapping(void)
for (zy = 0; zy < ROWNO; zy++)
show_map_spot(zx, zy);
if (!g.level.flags.hero_memory || unconstrained) {
if (!gl.level.flags.hero_memory || unconstrained) {
flush_screen(1); /* flush temp screen */
/* browse_map() instead of display_nhwindow(WIN_MAP, TRUE) */
browse_map(TER_DETECT | TER_MAP | TER_TRP | TER_OBJ,
@@ -1437,9 +1437,9 @@ do_vicinity_map(struct obj *sobj) /* scroll--actually fake spellbook--object */
*/
/* if hero is engulfed, show engulfer at <u.ux,u.uy> */
save_viz_uyux = g.viz_array[u.uy][u.ux];
save_viz_uyux = gv.viz_array[u.uy][u.ux];
if (u.uswallow)
g.viz_array[u.uy][u.ux] |= IN_SIGHT; /* <x,y> are reversed to [y][x] */
gv.viz_array[u.uy][u.ux] |= IN_SIGHT; /* <x,y> are reversed to [y][x] */
save_EDetect_mons = EDetect_monsters;
/* for skilled spell, getpos() scanning of the map will display all
monsters within range; otherwise, "unseen creature" will be shown */
@@ -1454,7 +1454,7 @@ do_vicinity_map(struct obj *sobj) /* scroll--actually fake spellbook--object */
if (OBJ_AT(zx, zy)) {
/* not vobj_at(); this is not vision-based access;
unlike object detection, we don't notice buried items */
otmp = g.level.objects[zx][zy];
otmp = gl.level.objects[zx][zy];
if (extended)
otmp->dknown = 1;
map_object(otmp, TRUE);
@@ -1471,7 +1471,7 @@ do_vicinity_map(struct obj *sobj) /* scroll--actually fake spellbook--object */
the map and we're not doing extended/blessed clairvoyance
(hence must be swallowed or underwater), show "unseen
creature" unless map already displayed a monster here */
if ((unconstrained || !g.level.flags.hero_memory)
if ((unconstrained || !gl.level.flags.hero_memory)
&& !extended && (zx != u.ux || zy != u.uy)
&& !glyph_is_monster(oldglyph))
map_invisible(zx, zy);
@@ -1494,7 +1494,7 @@ do_vicinity_map(struct obj *sobj) /* scroll--actually fake spellbook--object */
if (random_farsight && flags.quick_farsight)
mdetected = odetected = FALSE;
if (!g.level.flags.hero_memory || unconstrained
if (!gl.level.flags.hero_memory || unconstrained
|| mdetected || odetected) {
flush_screen(1); /* flush temp screen */
/* the getpos() prompt from browse_map() is only shown when
@@ -1508,7 +1508,7 @@ do_vicinity_map(struct obj *sobj) /* scroll--actually fake spellbook--object */
}
reconstrain_map();
EDetect_monsters = save_EDetect_mons;
g.viz_array[u.uy][u.ux] = save_viz_uyux;
gv.viz_array[u.uy][u.ux] = save_viz_uyux;
/* replace monsters with remembered,unseen monster, then run
see_monsters() to update visible ones and warned-of ones */
@@ -1621,7 +1621,7 @@ openone(coordxy zx, coordxy zy, genericptr_t num)
int *num_p = (int *) num;
if (OBJ_AT(zx, zy)) {
for (otmp = g.level.objects[zx][zy]; otmp; otmp = otmp->nexthere) {
for (otmp = gl.level.objects[zx][zy]; otmp; otmp = otmp->nexthere) {
if (Is_box(otmp) && otmp->olocked) {
otmp->olocked = 0;
(*num_p)++;
@@ -1664,7 +1664,7 @@ openone(coordxy zx, coordxy zy, genericptr_t num)
newsym(zx, zy);
(*num_p)++;
}
mon = u_at(zx, zy) ? &g.youmonst : m_at(zx, zy);
mon = u_at(zx, zy) ? &gy.youmonst : m_at(zx, zy);
if (openholdingtrap(mon, &dummy)
|| openfallingtrap(mon, TRUE, &dummy))
(*num_p)++;
@@ -1950,7 +1950,7 @@ dosearch(void)
{
if (cmd_safety_prevention("another search",
"You already found a monster.",
&g.already_found_flag))
&ga.already_found_flag))
return ECMD_OK;
return dosearch0(0) ? ECMD_TIME : ECMD_OK;
}
@@ -1992,7 +1992,7 @@ sokoban_detect(void)
}
/* Map the traps */
for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap) {
for (ttmp = gf.ftrap; ttmp; ttmp = ttmp->ntrap) {
ttmp->tseen = 1;
map_trap(ttmp, 1);
/* set sokoban_rules when there is at least one pit or hole */
@@ -2016,14 +2016,14 @@ reveal_terrain_getglyph(coordxy x, coordxy y, int full, unsigned swallowed,
/* for 'full', show the actual terrain for the entire level,
otherwise what the hero remembers for seen locations with
monsters, objects, and/or traps removed as caller dictates */
seenv = (full || g.level.flags.hero_memory)
seenv = (full || gl.level.flags.hero_memory)
? levl[x][y].seenv : cansee(x, y) ? SVALL : 0;
if (full) {
levl[x][y].seenv = SVALL;
glyph = back_to_glyph(x, y);
levl[x][y].seenv = seenv;
} else {
levl_glyph = g.level.flags.hero_memory
levl_glyph = gl.level.flags.hero_memory
? levl[x][y].glyph
: seenv ? back_to_glyph(x, y): default_glyph;
/* glyph_at() returns the displayed glyph, which might
@@ -2049,7 +2049,7 @@ reveal_terrain_getglyph(coordxy x, coordxy y, int full, unsigned swallowed,
|| glyph_is_invisible(glyph)) {
if (!seenv) {
glyph = default_glyph;
} else if (g.lastseentyp[x][y] == levl[x][y].typ) {
} else if (gl.lastseentyp[x][y] == levl[x][y].typ) {
glyph = back_to_glyph(x, y);
} else {
/* look for a mimic here posing as furniture;
@@ -2067,7 +2067,7 @@ reveal_terrain_getglyph(coordxy x, coordxy y, int full, unsigned swallowed,
but we've got no other choice) */
schar save_typ = levl[x][y].typ;
levl[x][y].typ = g.lastseentyp[x][y];
levl[x][y].typ = gl.lastseentyp[x][y];
glyph = back_to_glyph(x, y);
levl[x][y].typ = save_typ;
}
@@ -2089,7 +2089,7 @@ dump_map(void)
coordxy x, y;
int glyph, skippedrows, lastnonblank;
int subset = TER_MAP | TER_TRP | TER_OBJ | TER_MON;
int default_glyph = cmap_to_glyph(g.level.flags.arboreal ? S_tree
int default_glyph = cmap_to_glyph(gl.level.flags.arboreal ? S_tree
: S_stone);
char buf[COLBUFSZ];
boolean blankrow, toprow;
@@ -2161,7 +2161,7 @@ reveal_terrain(
if (unconstrain_map())
docrt();
default_glyph = cmap_to_glyph(g.level.flags.arboreal ? S_tree
default_glyph = cmap_to_glyph(gl.level.flags.arboreal ? S_tree
: S_stone);
for (x = 1; x < COLNO; x++)