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:
74
src/steal.c
74
src/steal.c
@@ -78,7 +78,7 @@ stealgold(register struct monst* mtmp)
|
||||
fgold = fgold->nexthere;
|
||||
|
||||
/* Do you have real gold? */
|
||||
ygold = findgold(g.invent);
|
||||
ygold = findgold(gi.invent);
|
||||
|
||||
if (fgold && (!ygold || fgold->quan > ygold->quan || !rn2(5))) {
|
||||
obj_extract_self(fgold);
|
||||
@@ -89,7 +89,7 @@ stealgold(register struct monst* mtmp)
|
||||
whose = s_suffix(y_monnam(who));
|
||||
what = makeplural(mbodypart(who, FOOT));
|
||||
} else {
|
||||
who = &g.youmonst;
|
||||
who = &gy.youmonst;
|
||||
whose = "your";
|
||||
what = makeplural(body_part(FOOT));
|
||||
}
|
||||
@@ -109,7 +109,7 @@ stealgold(register struct monst* mtmp)
|
||||
} else if (ygold) {
|
||||
const int gold_price = objects[GOLD_PIECE].oc_cost;
|
||||
|
||||
tmp = (somegold(money_cnt(g.invent)) + gold_price - 1) / gold_price;
|
||||
tmp = (somegold(money_cnt(gi.invent)) + gold_price - 1) / gold_price;
|
||||
tmp = min(tmp, ygold->quan);
|
||||
if (tmp < ygold->quan)
|
||||
ygold = splitobj(ygold, tmp);
|
||||
@@ -121,7 +121,7 @@ stealgold(register struct monst* mtmp)
|
||||
if (!tele_restrict(mtmp))
|
||||
(void) rloc(mtmp, RLOC_MSG);
|
||||
monflee(mtmp, 0, FALSE, FALSE);
|
||||
g.context.botl = 1;
|
||||
gc.context.botl = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,14 +130,14 @@ void
|
||||
thiefdead(void)
|
||||
{
|
||||
/* hero is busy taking off an item of armor which takes multiple turns */
|
||||
g.stealmid = 0;
|
||||
if (g.afternmv == stealarm) {
|
||||
g.afternmv = unstolenarm;
|
||||
g.nomovemsg = (char *) 0;
|
||||
gs.stealmid = 0;
|
||||
if (ga.afternmv == stealarm) {
|
||||
ga.afternmv = unstolenarm;
|
||||
gn.nomovemsg = (char *) 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* called via (*g.afternmv)() when hero finishes taking off armor that
|
||||
/* called via (*ga.afternmv)() when hero finishes taking off armor that
|
||||
was slated to be stolen but the thief died in the interim */
|
||||
static int
|
||||
unstolenarm(void)
|
||||
@@ -146,10 +146,10 @@ unstolenarm(void)
|
||||
|
||||
/* find the object before clearing stealoid; it has already become
|
||||
not-worn and is still in hero's inventory */
|
||||
for (obj = g.invent; obj; obj = obj->nobj)
|
||||
if (obj->o_id == g.stealoid)
|
||||
for (obj = gi.invent; obj; obj = obj->nobj)
|
||||
if (obj->o_id == gs.stealoid)
|
||||
break;
|
||||
g.stealoid = 0;
|
||||
gs.stealoid = 0;
|
||||
if (obj) {
|
||||
You("finish taking off your %s.", equipname(obj));
|
||||
}
|
||||
@@ -162,13 +162,13 @@ stealarm(void)
|
||||
register struct monst *mtmp;
|
||||
register struct obj *otmp;
|
||||
|
||||
if (!g.stealoid || !g.stealmid)
|
||||
if (!gs.stealoid || !gs.stealmid)
|
||||
goto botm;
|
||||
|
||||
for (otmp = g.invent; otmp; otmp = otmp->nobj) {
|
||||
if (otmp->o_id == g.stealoid) {
|
||||
for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
|
||||
if (otmp->o_id == gs.stealoid) {
|
||||
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
|
||||
if (mtmp->m_id == g.stealmid) {
|
||||
if (mtmp->m_id == gs.stealmid) {
|
||||
if (DEADMONSTER(mtmp))
|
||||
impossible("stealarm(): dead monster stealing");
|
||||
if (!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */
|
||||
@@ -190,7 +190,7 @@ stealarm(void)
|
||||
}
|
||||
}
|
||||
botm:
|
||||
g.stealoid = g.stealmid = 0; /* in case only one has been reset so far */
|
||||
gs.stealoid = gs.stealmid = 0; /* in case only one has been reset so far */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ steal(struct monst* mtmp, char* objnambuf)
|
||||
/* food being eaten might already be used up but will not have
|
||||
been removed from inventory yet; we don't want to steal that,
|
||||
so this will cause it to be removed now */
|
||||
if (g.occupation)
|
||||
if (go.occupation)
|
||||
(void) maybe_finished_meal(FALSE);
|
||||
|
||||
icnt = inv_cnt(FALSE); /* don't include gold */
|
||||
@@ -306,14 +306,14 @@ steal(struct monst* mtmp, char* objnambuf)
|
||||
|
||||
retry:
|
||||
tmp = 0;
|
||||
for (otmp = g.invent; otmp; otmp = otmp->nobj)
|
||||
for (otmp = gi.invent; otmp; otmp = otmp->nobj)
|
||||
if ((!uarm || otmp != uarmc) && otmp != uskin
|
||||
&& otmp->oclass != COIN_CLASS)
|
||||
tmp += (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
|
||||
if (!tmp)
|
||||
goto nothing_to_steal;
|
||||
tmp = rn2(tmp);
|
||||
for (otmp = g.invent; otmp; otmp = otmp->nobj)
|
||||
for (otmp = gi.invent; otmp; otmp = otmp->nobj)
|
||||
if ((!uarm || otmp != uarmc) && otmp != uskin
|
||||
&& otmp->oclass != COIN_CLASS) {
|
||||
tmp -= (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
|
||||
@@ -340,7 +340,7 @@ steal(struct monst* mtmp, char* objnambuf)
|
||||
otmp = uarm;
|
||||
|
||||
gotobj:
|
||||
if (otmp->o_id == g.stealoid)
|
||||
if (otmp->o_id == gs.stealoid)
|
||||
return 0;
|
||||
|
||||
if (otmp->otyp == BOULDER && !throws_rocks(mtmp->data)) {
|
||||
@@ -422,7 +422,7 @@ steal(struct monst* mtmp, char* objnambuf)
|
||||
/* can't charm you without first waking you */
|
||||
if (Unaware)
|
||||
unmul((char *) 0);
|
||||
slowly = (armordelay >= 1 || g.multi < 0);
|
||||
slowly = (armordelay >= 1 || gm.multi < 0);
|
||||
if (flags.female)
|
||||
urgent_pline("%s charms you. You gladly %s your %s.",
|
||||
!seen ? "She" : Monnam(mtmp),
|
||||
@@ -442,14 +442,14 @@ steal(struct monst* mtmp, char* objnambuf)
|
||||
named++;
|
||||
/* the following is to set multi for later on */
|
||||
nomul(-armordelay);
|
||||
g.multi_reason = "taking off clothes";
|
||||
g.nomovemsg = 0;
|
||||
gm.multi_reason = "taking off clothes";
|
||||
gn.nomovemsg = 0;
|
||||
remove_worn_item(otmp, TRUE);
|
||||
otmp->cursed = curssv;
|
||||
if (g.multi < 0) {
|
||||
g.stealoid = otmp->o_id;
|
||||
g.stealmid = mtmp->m_id;
|
||||
g.afternmv = stealarm;
|
||||
if (gm.multi < 0) {
|
||||
gs.stealoid = otmp->o_id;
|
||||
gs.stealmid = mtmp->m_id;
|
||||
ga.afternmv = stealarm;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -484,7 +484,7 @@ steal(struct monst* mtmp, char* objnambuf)
|
||||
minstapetrify(mtmp, TRUE);
|
||||
return -1;
|
||||
}
|
||||
return (g.multi < 0) ? 0 : 1;
|
||||
return (gm.multi < 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
/* Returns 1 if otmp is free'd, 0 otherwise. */
|
||||
@@ -506,10 +506,10 @@ mpickobj(struct monst *mtmp, struct obj *otmp)
|
||||
}
|
||||
/* if monster is acquiring a thrown or kicked object, the throwing
|
||||
or kicking code shouldn't continue to track and place it */
|
||||
if (otmp == g.thrownobj)
|
||||
g.thrownobj = 0;
|
||||
else if (otmp == g.kickedobj)
|
||||
g.kickedobj = 0;
|
||||
if (otmp == gt.thrownobj)
|
||||
gt.thrownobj = 0;
|
||||
else if (otmp == gk.kickedobj)
|
||||
gk.kickedobj = 0;
|
||||
/* don't want hidden light source inside the monster; assumes that
|
||||
engulfers won't have external inventories; whirly monsters cause
|
||||
the light to be extinguished rather than letting it shine thru */
|
||||
@@ -552,12 +552,12 @@ stealamulet(struct monst* mtmp)
|
||||
/* target every quest artifact, not just current role's;
|
||||
if hero has more than one, choose randomly so that player
|
||||
can't use inventory ordering to influence the theft */
|
||||
for (n = 0, obj = g.invent; obj; obj = obj->nobj)
|
||||
for (n = 0, obj = gi.invent; obj; obj = obj->nobj)
|
||||
if (any_quest_artifact(obj))
|
||||
++n, otmp = obj;
|
||||
if (n > 1) {
|
||||
n = rnd(n);
|
||||
for (otmp = g.invent; otmp; otmp = otmp->nobj)
|
||||
for (otmp = gi.invent; otmp; otmp = otmp->nobj)
|
||||
if (any_quest_artifact(otmp) && !--n)
|
||||
break;
|
||||
}
|
||||
@@ -578,12 +578,12 @@ stealamulet(struct monst* mtmp)
|
||||
return; /* you have nothing of special interest */
|
||||
|
||||
/* If we get here, real and fake have been set up. */
|
||||
for (n = 0, obj = g.invent; obj; obj = obj->nobj)
|
||||
for (n = 0, obj = gi.invent; obj; obj = obj->nobj)
|
||||
if (obj->otyp == real || (obj->otyp == fake && !mtmp->iswiz))
|
||||
++n, otmp = obj;
|
||||
if (n > 1) {
|
||||
n = rnd(n);
|
||||
for (otmp = g.invent; otmp; otmp = otmp->nobj)
|
||||
for (otmp = gi.invent; otmp; otmp = otmp->nobj)
|
||||
if ((otmp->otyp == real
|
||||
|| (otmp->otyp == fake && !mtmp->iswiz)) && !--n)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user