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

@@ -223,18 +223,18 @@ mkobj(int oclass, boolean artif)
}
if (oclass == SPBOOK_no_NOVEL) {
i = rnd_class(g.bases[SPBOOK_CLASS], SPE_BLANK_PAPER);
i = rnd_class(gb.bases[SPBOOK_CLASS], SPE_BLANK_PAPER);
oclass = SPBOOK_CLASS; /* for sanity check below */
} else {
prob = rnd(g.oclass_prob_totals[oclass]);
i = g.bases[oclass];
prob = rnd(go.oclass_prob_totals[oclass]);
i = gb.bases[oclass];
while ((prob -= objects[i].oc_prob) > 0)
++i;
}
if (objects[i].oc_class != oclass || !OBJ_NAME(objects[i])) {
impossible("probtype error, oclass=%d i=%d", (int) oclass, i);
i = g.bases[oclass];
i = gb.bases[oclass];
}
return mksobj(i, TRUE, artif);
@@ -261,7 +261,7 @@ mkbox_cnts(struct obj *box)
case SACK:
case OILSKIN_SACK:
/* initial inventory: sack starts out empty */
if (g.moves <= 1 && !g.in_mklev) {
if (gm.moves <= 1 && !gi.in_mklev) {
n = 0;
break;
}
@@ -411,8 +411,8 @@ splitobj(struct obj *obj, long num)
otmp->lua_ref_cnt = 0;
otmp->pickup_prev = 0;
g.context.objsplit.parent_oid = obj->o_id;
g.context.objsplit.child_oid = otmp->o_id;
gc.context.objsplit.parent_oid = obj->o_id;
gc.context.objsplit.child_oid = otmp->o_id;
obj->nobj = otmp;
/* Only set nexthere when on the floor; nexthere is also used
as a back pointer to the container object when contained.
@@ -442,7 +442,7 @@ splitobj(struct obj *obj, long num)
unsigned
next_ident(void)
{
unsigned res = g.context.ident;
unsigned res = gc.context.ident;
/* +rnd(2): originally just +1; changed to rnd() to avoid potential
exploit of player using #adjust to split an object stack in a manner
@@ -452,14 +452,14 @@ next_ident(void)
next object to be created was knowable and player could make a wish
under controlled circumstances for an item that is affected by the
low bits of its obj->o_id [particularly helm of opposite alignment] */
g.context.ident += rnd(2); /* ready for next new object or monster */
gc.context.ident += rnd(2); /* ready for next new object or monster */
/* if ident has wrapped to 0, force it to be non-zero; if/when it
ever wraps past 0 (unlikely, but possible on a configuration which
uses 16-bit 'int'), just live with that and hope no o_id conflicts
between objects or m_id conflicts between monsters arise */
if (!g.context.ident)
g.context.ident = rnd(2);
if (!gc.context.ident)
gc.context.ident = rnd(2);
return res;
}
@@ -470,7 +470,7 @@ static unsigned
nextoid(struct obj *oldobj, struct obj *newobj)
{
int olddif, newdif, trylimit = 256; /* limit of 4 suffices at present */
unsigned oid = g.context.ident - 1; /* loop increment will reverse -1 */
unsigned oid = gc.context.ident - 1; /* loop increment will reverse -1 */
olddif = oid_price_adjustment(oldobj, oldobj->o_id);
do {
@@ -479,7 +479,7 @@ nextoid(struct obj *oldobj, struct obj *newobj)
++oid;
newdif = oid_price_adjustment(newobj, oid);
} while (newdif != olddif && --trylimit >= 0);
g.context.ident = oid; /* update 'last ident used' */
gc.context.ident = oid; /* update 'last ident used' */
(void) next_ident(); /* increment context.ident for next use */
return oid; /* caller will use this ident */
}
@@ -509,7 +509,7 @@ unsplitobj(struct obj *obj)
default:
return (struct obj *) 0;
case OBJ_INVENT:
list = g.invent;
list = gi.invent;
break;
case OBJ_MINVENT:
list = obj->ocarry->minvent;
@@ -520,17 +520,17 @@ unsplitobj(struct obj *obj)
}
/* first try the expected case; obj is split from another stack */
if (obj->o_id == g.context.objsplit.child_oid) {
if (obj->o_id == gc.context.objsplit.child_oid) {
/* parent probably precedes child and will require list traversal */
ochild = obj;
target_oid = g.context.objsplit.parent_oid;
target_oid = gc.context.objsplit.parent_oid;
if (obj->nobj && obj->nobj->o_id == target_oid)
oparent = obj->nobj;
} else if (obj->o_id == g.context.objsplit.parent_oid) {
} else if (obj->o_id == gc.context.objsplit.parent_oid) {
/* alternate scenario: another stack was split from obj;
child probably follows parent and will be found here */
oparent = obj;
target_oid = g.context.objsplit.child_oid;
target_oid = gc.context.objsplit.child_oid;
if (obj->nobj && obj->nobj->o_id == target_oid)
ochild = obj->nobj;
}
@@ -559,7 +559,7 @@ unsplitobj(struct obj *obj)
void
clear_splitobjs(void)
{
g.context.objsplit.parent_oid = g.context.objsplit.child_oid = 0;
gc.context.objsplit.parent_oid = gc.context.objsplit.child_oid = 0;
}
/*
@@ -582,7 +582,7 @@ replace_object(struct obj *obj, struct obj *otmp)
case OBJ_INVENT:
otmp->nobj = obj->nobj;
obj->nobj = otmp;
extract_nobj(obj, &g.invent);
extract_nobj(obj, &gi.invent);
break;
case OBJ_CONTAINED:
otmp->nobj = obj->nobj;
@@ -604,7 +604,7 @@ replace_object(struct obj *obj, struct obj *otmp)
obj->nobj = otmp;
obj->nexthere = otmp;
extract_nobj(obj, &fobj);
extract_nexthere(obj, &g.level.objects[obj->ox][obj->oy]);
extract_nexthere(obj, &gl.level.objects[obj->ox][obj->oy]);
break;
default:
panic("replace_object: obj position");
@@ -799,7 +799,7 @@ mksobj(int otyp, boolean init, boolean artif)
otmp = newobj();
*otmp = cg.zeroobj;
otmp->age = g.moves;
otmp->age = gm.moves;
otmp->o_id = next_ident();
otmp->quan = 1L;
otmp->oclass = let;
@@ -836,11 +836,11 @@ mksobj(int otyp, boolean init, boolean artif)
tryct = 50;
do
otmp->corpsenm = undead_to_corpse(rndmonnum());
while ((g.mvitals[otmp->corpsenm].mvflags & G_NOCORPSE)
while ((gm.mvitals[otmp->corpsenm].mvflags & G_NOCORPSE)
&& (--tryct > 0));
if (tryct == 0) {
/* perhaps rndmonnum() only wants to make G_NOCORPSE
monsters on this g.level; create an adventurer's
monsters on this gl.level; create an adventurer's
corpse instead, then */
otmp->corpsenm = PM_HUMAN;
}
@@ -866,7 +866,7 @@ mksobj(int otyp, boolean init, boolean artif)
for (tryct = 200; tryct > 0; --tryct) {
mndx = undead_to_corpse(rndmonnum());
if (mons[mndx].cnutrit
&& !(g.mvitals[mndx].mvflags & G_NOCORPSE)) {
&& !(gm.mvitals[mndx].mvflags & G_NOCORPSE)) {
otmp->corpsenm = mndx;
set_tin_variety(otmp, RANDOM_TIN);
break;
@@ -875,7 +875,7 @@ mksobj(int otyp, boolean init, boolean artif)
blessorcurse(otmp, 10);
break;
case SLIME_MOLD:
otmp->spe = g.context.current_fruit;
otmp->spe = gc.context.current_fruit;
flags.made_fruit = TRUE;
break;
case KELP_FROND:
@@ -993,7 +993,7 @@ mksobj(int otyp, boolean init, boolean artif)
break;
case AMULET_CLASS:
if (otmp->otyp == AMULET_OF_YENDOR)
g.context.made_amulet = TRUE;
gc.context.made_amulet = TRUE;
if (rn2(10) && (otmp->otyp == AMULET_OF_STRANGULATION
|| otmp->otyp == AMULET_OF_CHANGE
|| otmp->otyp == AMULET_OF_RESTFUL_SLEEP)) {
@@ -1033,7 +1033,7 @@ mksobj(int otyp, boolean init, boolean artif)
otmp = mk_artifact(otmp, (aligntyp) A_NONE);
/* simulate lacquered armor for samurai */
if (Role_if(PM_SAMURAI) && otmp->otyp == SPLINT_MAIL
&& (g.moves <= 1 || In_quest(&u.uz))) {
&& (gm.moves <= 1 || In_quest(&u.uz))) {
#ifdef UNIXPC
/* optimizer bitfield bug */
otmp->oerodeproof = 1;
@@ -1104,8 +1104,8 @@ mksobj(int otyp, boolean init, boolean artif)
case CORPSE:
if (otmp->corpsenm == NON_PM) {
otmp->corpsenm = undead_to_corpse(rndmonnum());
if (g.mvitals[otmp->corpsenm].mvflags & (G_NOCORPSE | G_GONE))
otmp->corpsenm = g.urole.mnum;
if (gm.mvitals[otmp->corpsenm].mvflags & (G_NOCORPSE | G_GONE))
otmp->corpsenm = gu.urole.mnum;
}
/*FALLTHRU*/
case STATUE:
@@ -1263,8 +1263,8 @@ start_corpse_timeout(struct obj *body)
return;
action = ROT_CORPSE; /* default action: rot away */
rot_adjust = g.in_mklev ? 25 : 10; /* give some variation */
age = g.moves - body->age;
rot_adjust = gi.in_mklev ? 25 : 10; /* give some variation */
age = gm.moves - body->age;
if (age > ROT_AGE)
when = rot_adjust;
else
@@ -1281,7 +1281,7 @@ start_corpse_timeout(struct obj *body)
when = age;
break;
}
} else if (g.zombify && zombie_form(&mons[body->corpsenm]) != NON_PM
} else if (gz.zombify && zombie_form(&mons[body->corpsenm]) != NON_PM
&& !body->norevive) {
action = ZOMBIFY_MON;
when = rn1(15, 5); /* 5..19 */
@@ -1383,9 +1383,9 @@ shrink_glob(
/*
* If shrinkage occurred while we were on another level, catch up now.
*/
if (expire_time < g.moves && globloc != BURIED_UNDER_ICE) {
if (expire_time < gm.moves && globloc != BURIED_UNDER_ICE) {
/* number of units of weight to remove */
long delta = (g.moves - expire_time + 24L) / 25L,
long delta = (gm.moves - expire_time + 24L) / 25L,
/* leftover amount to use for new timer */
moddelta = 25L - (delta % 25L);
@@ -1424,7 +1424,7 @@ shrink_glob(
*/
if (eating_glob(obj)
|| globloc == BURIED_UNDER_ICE
|| (globloc == SET_ON_ICE && (g.moves % 3L) == 1L)) {
|| (globloc == SET_ON_ICE && (gm.moves % 3L) == 1L)) {
/* schedule next shrink attempt; for the being eaten case, the
glob and its timer might be deleted before this kicks in */
start_glob_timeout(obj, 0L);
@@ -1487,7 +1487,7 @@ shrink_glob(
change because only a fraction of glob's weight is counted;
however, always say the bag is lighter for the 'gone' case */
if (gone || (shrink && topcontnr->owt != old_top_owt)
|| near_capacity() != g.oldcap)
|| near_capacity() != go.oldcap)
pline("%s %s%s lighter.", Yname2(topcontnr),
/* containers also always have quantity 1 */
(topcontnr->owt != old_top_owt) ? "becomes" : "seems",
@@ -1726,7 +1726,7 @@ set_bknown(
{
if (obj->bknown != onoff) {
obj->bknown = onoff;
if (obj->where == OBJ_INVENT && g.moves > 1L)
if (obj->where == OBJ_INVENT && gm.moves > 1L)
update_inventory();
}
}
@@ -1887,7 +1887,7 @@ mkcorpstat(
}
/* record gender and 'historic statue' in overloaded enchantment field */
otmp->spe = (corpstatflags & CORPSTAT_SPE_VAL);
otmp->norevive = g.mkcorpstat_norevive; /* via envrmt rather than flags */
otmp->norevive = gm.mkcorpstat_norevive; /* via envrmt rather than flags */
/* when 'mtmp' is non-null save the monster's details with the
corpse or statue; it will also force the 'ptr' override below */
@@ -1910,7 +1910,7 @@ mkcorpstat(
otmp->corpsenm = monsndx(ptr);
otmp->owt = weight(otmp);
if (otmp->otyp == CORPSE && (g.zombify || special_corpse(old_corpsenm)
if (otmp->otyp == CORPSE && (gz.zombify || special_corpse(old_corpsenm)
|| special_corpse(otmp->corpsenm))) {
obj_stop_timers(otmp);
start_corpse_timeout(otmp);
@@ -2119,7 +2119,7 @@ place_object(struct obj *otmp, coordxy x, coordxy y)
panic("place_object: obj \"%s\" [%d] not free",
safe_typename(otmp->otyp), otmp->where);
otmp2 = g.level.objects[x][y];
otmp2 = gl.level.objects[x][y];
obj_no_longer_held(otmp);
if (otmp->otyp == BOULDER) {
@@ -2142,7 +2142,7 @@ place_object(struct obj *otmp, coordxy x, coordxy y)
} else {
/* put on top of current pile */
otmp->nexthere = otmp2;
g.level.objects[x][y] = otmp;
gl.level.objects[x][y] = otmp;
}
/* set the new object's location */
@@ -2167,12 +2167,12 @@ obj_ice_effects(coordxy x, coordxy y, boolean do_buried)
{
struct obj *otmp;
for (otmp = g.level.objects[x][y]; otmp; otmp = otmp->nexthere) {
for (otmp = gl.level.objects[x][y]; otmp; otmp = otmp->nexthere) {
if (otmp->timed)
obj_timer_checks(otmp, x, y, 0);
}
if (do_buried) {
for (otmp = g.level.buriedobjlist; otmp; otmp = otmp->nobj) {
for (otmp = gl.level.buriedobjlist; otmp; otmp = otmp->nobj) {
if (otmp->ox == x && otmp->oy == y) {
if (otmp->timed)
obj_timer_checks(otmp, x, y, 0);
@@ -2195,12 +2195,12 @@ peek_at_iced_corpse_age(struct obj *otmp)
if (otmp->otyp == CORPSE && otmp->on_ice) {
/* Adjust the age; must be same as obj_timer_checks() for off ice*/
age = g.moves - otmp->age;
age = gm.moves - otmp->age;
retval += age * (ROT_ICE_ADJUSTMENT - 1) / ROT_ICE_ADJUSTMENT;
debugpline3(
"The %s age has ice modifications: otmp->age = %ld, returning %ld.",
s_suffix(doname(otmp)), otmp->age, retval);
debugpline1("Effective age of corpse: %ld.", g.moves - retval);
debugpline1("Effective age of corpse: %ld.", gm.moves - retval);
}
return retval;
}
@@ -2239,8 +2239,8 @@ obj_timer_checks(
later calculations behave as if it had been on ice during
that time (longwinded way of saying this is the inverse
of removing it from the ice and of peeking at its age). */
age = g.moves - otmp->age;
otmp->age = g.moves - (age * ROT_ICE_ADJUSTMENT);
age = gm.moves - otmp->age;
otmp->age = gm.moves - (age * ROT_ICE_ADJUSTMENT);
}
/* Check for corpses coming off ice */
@@ -2261,7 +2261,7 @@ obj_timer_checks(
tleft /= ROT_ICE_ADJUSTMENT;
restart_timer = TRUE;
/* Adjust the age */
age = g.moves - otmp->age;
age = gm.moves - otmp->age;
otmp->age += age * (ROT_ICE_ADJUSTMENT - 1) / ROT_ICE_ADJUSTMENT;
}
}
@@ -2281,7 +2281,7 @@ remove_object(struct obj *otmp)
if (otmp->where != OBJ_FLOOR)
panic("remove_object: obj not on floor");
extract_nexthere(otmp, &g.level.objects[x][y]);
extract_nexthere(otmp, &gl.level.objects[x][y]);
extract_nobj(otmp, &fobj);
/* update vision iff this was the only boulder at its spot */
if (otmp->otyp == BOULDER && !sobj_at(BOULDER, x, y))
@@ -2318,7 +2318,7 @@ discard_minvent(struct monst *mtmp, boolean uncreate_artifacts)
* OBJ_MINVENT monster's invent chain
* OBJ_MIGRATING migrating chain
* OBJ_BURIED level.buriedobjs chain
* OBJ_ONBILL on g.billobjs chain
* OBJ_ONBILL on gb.billobjs chain
* OBJ_LUAFREE obj is dealloc'd from core, but still used by lua
*/
void
@@ -2344,13 +2344,13 @@ obj_extract_self(struct obj *obj)
obj->ocarry = (struct monst *) 0; /* clear stale back-link */
break;
case OBJ_MIGRATING:
extract_nobj(obj, &g.migrating_objs);
extract_nobj(obj, &gm.migrating_objs);
break;
case OBJ_BURIED:
extract_nobj(obj, &g.level.buriedobjlist);
extract_nobj(obj, &gl.level.buriedobjlist);
break;
case OBJ_ONBILL:
extract_nobj(obj, &g.billobjs);
extract_nobj(obj, &gb.billobjs);
break;
default:
panic("obj_extract_self");
@@ -2468,10 +2468,10 @@ add_to_migration(struct obj *obj)
maybe_reset_pick(obj);
obj->where = OBJ_MIGRATING;
obj->nobj = g.migrating_objs;
obj->nobj = gm.migrating_objs;
obj->omigr_from_dnum = u.uz.dnum;
obj->omigr_from_dlevel = u.uz.dlevel;
g.migrating_objs = obj;
gm.migrating_objs = obj;
}
void
@@ -2481,8 +2481,8 @@ add_to_buried(struct obj *obj)
panic("add_to_buried: obj not free");
obj->where = OBJ_BURIED;
obj->nobj = g.level.buriedobjlist;
g.level.buriedobjlist = obj;
obj->nobj = gl.level.buriedobjlist;
gl.level.buriedobjlist = obj;
}
/* Recalculate the weight of this container and all of _its_ containers. */
@@ -2529,10 +2529,10 @@ dealloc_obj(struct obj *obj)
obj->lamplit = 0;
}
if (obj == g.thrownobj)
g.thrownobj = 0;
if (obj == g.kickedobj)
g.kickedobj = 0;
if (obj == gt.thrownobj)
gt.thrownobj = 0;
if (obj == gk.kickedobj)
gk.kickedobj = 0;
if (obj->oextra)
dealloc_oextra(obj);
@@ -2658,7 +2658,7 @@ obj_sanity_check(void)
for (y = 0; y < ROWNO; y++) {
char at_fmt[BUFSZ];
otop = g.level.objects[x][y];
otop = gl.level.objects[x][y];
prevo = 0;
for (obj = otop; obj; prevo = obj, obj = prevo->nexthere) {
/* <ox,oy> should match <x,y>; <0,*> should always be empty */
@@ -2690,32 +2690,32 @@ obj_sanity_check(void)
}
}
objlist_sanity(g.invent, OBJ_INVENT, "invent sanity");
objlist_sanity(g.migrating_objs, OBJ_MIGRATING, "migrating sanity");
objlist_sanity(g.level.buriedobjlist, OBJ_BURIED, "buried sanity");
objlist_sanity(g.billobjs, OBJ_ONBILL, "bill sanity");
objlist_sanity(gi.invent, OBJ_INVENT, "invent sanity");
objlist_sanity(gm.migrating_objs, OBJ_MIGRATING, "migrating sanity");
objlist_sanity(gl.level.buriedobjlist, OBJ_BURIED, "buried sanity");
objlist_sanity(gb.billobjs, OBJ_ONBILL, "bill sanity");
mon_obj_sanity(fmon, "minvent sanity");
mon_obj_sanity(g.migrating_mons, "migrating minvent sanity");
mon_obj_sanity(gm.migrating_mons, "migrating minvent sanity");
/* monsters temporarily in transit;
they should have arrived with hero by the time we get called */
if (g.mydogs) {
impossible("g.mydogs sanity [not empty]");
mon_obj_sanity(g.mydogs, "mydogs minvent sanity");
if (gm.mydogs) {
impossible("gm.mydogs sanity [not empty]");
mon_obj_sanity(gm.mydogs, "mydogs minvent sanity");
}
/* objects temporarily freed from invent/floor lists;
they should have arrived somewhere by the time we get called */
if (g.thrownobj)
insane_object(g.thrownobj, ofmt3, "g.thrownobj sanity",
if (gt.thrownobj)
insane_object(gt.thrownobj, ofmt3, "gt.thrownobj sanity",
(struct monst *) 0);
if (g.kickedobj)
insane_object(g.kickedobj, ofmt3, "g.kickedobj sanity",
if (gk.kickedobj)
insane_object(gk.kickedobj, ofmt3, "gk.kickedobj sanity",
(struct monst *) 0);
/* g.current_wand isn't removed from invent while in use, but should
/* gc.current_wand isn't removed from invent while in use, but should
be Null between moves when we're called */
if (g.current_wand)
insane_object(g.current_wand, ofmt3, "g.current_wand sanity",
if (gc.current_wand)
insane_object(gc.current_wand, ofmt3, "gc.current_wand sanity",
(struct monst *) 0);
}
@@ -2981,7 +2981,7 @@ init_dummyobj(struct obj *obj, short otyp, long oquan)
obj->next_boulder = 0; /* overloads corpsenm, avoid NON_PM */
/* but suppressing fruit details leads to "bad fruit #0" */
if (obj->otyp == SLIME_MOLD)
obj->spe = g.context.current_fruit;
obj->spe = gc.context.current_fruit;
}
return obj;
}
@@ -3340,11 +3340,11 @@ obj_absorb(struct obj **obj1, struct obj **obj2)
o2wt = otmp2->oeaten ? otmp2->oeaten : otmp2->owt;
/* averaging the relative ages is less likely to overflow
than averaging the absolute ages directly */
agetmp = (((g.moves - otmp1->age) * o1wt
+ (g.moves - otmp2->age) * o2wt)
agetmp = (((gm.moves - otmp1->age) * o1wt
+ (gm.moves - otmp2->age) * o2wt)
/ (o1wt + o2wt));
/* convert relative age back to absolute age */
otmp1->age = g.moves - agetmp;
otmp1->age = gm.moves - agetmp;
otmp1->owt += o2wt;
if (otmp1->oeaten || otmp2->oeaten)
otmp1->oeaten = o1wt + o2wt;