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:
@@ -226,7 +226,7 @@ void NetHackQtBind::qt_askname()
|
||||
int ch = -1; // -1 => new game
|
||||
|
||||
have_asked = true;
|
||||
str_copy(default_plname, g.plname, PL_NSIZ);
|
||||
str_copy(default_plname, gp.plname, PL_NSIZ);
|
||||
|
||||
// We do it all here (plus qt_plsel.cpp and qt_svsel.cpp),
|
||||
// nothing in player_selection().
|
||||
@@ -241,9 +241,9 @@ void NetHackQtBind::qt_askname()
|
||||
NetHackQtSavedGameSelector sgsel((const char **) saved);
|
||||
ch = sgsel.choose();
|
||||
if (ch >= 0)
|
||||
str_copy(g.plname, saved[ch], SIZE(g.plname));
|
||||
str_copy(gp.plname, saved[ch], SIZE(gp.plname));
|
||||
// caller needs new lock name even if plname[] hasn't changed
|
||||
// because successful get_saved_games() clobbers g.SAVEF[]
|
||||
// because successful get_saved_games() clobbers gs.SAVEF[]
|
||||
::iflags.renameinprogress = TRUE;
|
||||
}
|
||||
free_saved_games(saved);
|
||||
@@ -271,10 +271,10 @@ void NetHackQtBind::qt_askname()
|
||||
break;
|
||||
}
|
||||
|
||||
if (!*g.plname)
|
||||
if (!*gp.plname)
|
||||
// in case Choose() returns with plname[] empty
|
||||
Strcpy(g.plname, default_plname);
|
||||
else if (strcmp(g.plname, default_plname) != 0)
|
||||
Strcpy(gp.plname, default_plname);
|
||||
else if (strcmp(gp.plname, default_plname) != 0)
|
||||
// caller needs to set new lock file name
|
||||
::iflags.renameinprogress = TRUE;
|
||||
return;
|
||||
@@ -487,7 +487,7 @@ void NetHackQtBind::qt_update_inventory(int arg UNUSED)
|
||||
main->updateInventory(); // update the paper doll inventory subset
|
||||
|
||||
/* doesn't work yet
|
||||
if (g.program_state.something_worth_saving && iflags.perm_invent)
|
||||
if (gp.program_state.something_worth_saving && iflags.perm_invent)
|
||||
display_inventory(NULL, false);
|
||||
*/
|
||||
}
|
||||
@@ -641,7 +641,7 @@ char NetHackQtBind::qt_more()
|
||||
// ^C comment in that routine] when the core triggers --More-- via
|
||||
// done2() -> really_done() -> display_nhwindow(WIN_MESSAGE, TRUE)
|
||||
// (get rid of this if the exec() loop issue gets properly fixed)
|
||||
if (::g.program_state.gameover)
|
||||
if (::gp.program_state.gameover)
|
||||
return ch; // bypass --More-- and just continue with program exit
|
||||
|
||||
NetHackQtMessageWindow *mesgwin = main ? main->GetMessageWindow() : NULL;
|
||||
|
||||
@@ -40,7 +40,7 @@ find_tool(int tooltyp)
|
||||
{
|
||||
struct obj *o;
|
||||
|
||||
for (o = g.invent; o; o = o->nobj) {
|
||||
for (o = gi.invent; o; o = o->nobj) {
|
||||
if ((tooltyp == LEASH && o->otyp == LEASH && o->leashmon)
|
||||
// OIL_LAMP is used for candles, lamps, lantern, candelabrum too
|
||||
|| (tooltyp == OIL_LAMP && o->lamplit))
|
||||
|
||||
@@ -1035,7 +1035,7 @@ void NetHackQtMainWindow::doQuit(bool)
|
||||
// in case someone wants to change that
|
||||
#ifdef MACOS
|
||||
QString info = nh_qsprintf("This will end your NetHack session.%s",
|
||||
!g.program_state.something_worth_saving ? ""
|
||||
!gp.program_state.something_worth_saving ? ""
|
||||
: "\n(Cancel quitting and use the Save command"
|
||||
"\nto save your current game.)");
|
||||
/* this is similar to closeEvent but the details are different;
|
||||
@@ -1053,7 +1053,7 @@ void NetHackQtMainWindow::doQuit(bool)
|
||||
break; // return to game
|
||||
case 1:
|
||||
// quit -- bypass the prompting preformed by done2()
|
||||
g.program_state.stopprint++;
|
||||
gp.program_state.stopprint++;
|
||||
::done(QUIT);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
@@ -1320,7 +1320,7 @@ void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event)
|
||||
event->key() >= Qt::Key_Left && event->key() <= Qt::Key_Down )
|
||||
return;
|
||||
|
||||
const char* d = g.Cmd.dirchars;
|
||||
const char* d = gc.Cmd.dirchars;
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Up:
|
||||
if ( dirkey == d[0] )
|
||||
@@ -1382,7 +1382,7 @@ void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event)
|
||||
void NetHackQtMainWindow::closeEvent(QCloseEvent *e UNUSED)
|
||||
{
|
||||
int ok = 0;
|
||||
if ( g.program_state.something_worth_saving ) {
|
||||
if ( gp.program_state.something_worth_saving ) {
|
||||
/* this used to offer "Save" and "Cancel"
|
||||
but cancel (ignoring the close attempt) won't work
|
||||
if user has clicked on the window's Close button */
|
||||
@@ -1397,7 +1397,7 @@ void NetHackQtMainWindow::closeEvent(QCloseEvent *e UNUSED)
|
||||
case 1:
|
||||
// quit -- bypass the prompting preformed by done2()
|
||||
ok = 1;
|
||||
g.program_state.stopprint++;
|
||||
gp.program_state.stopprint++;
|
||||
::done(QUIT);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
|
||||
@@ -1066,7 +1066,7 @@ void NetHackQtTextWindow::UseRIP(int how, time_t when)
|
||||
|
||||
/* Put name on stone */
|
||||
(void) snprintf(rip_line[NAME_LINE], STONE_LINE_LEN + 1,
|
||||
"%.*s", STONE_LINE_LEN, g.plname);
|
||||
"%.*s", STONE_LINE_LEN, gp.plname);
|
||||
|
||||
/* Put $ on stone;
|
||||
to keep things safe and relatively simple, impose an arbitrary
|
||||
@@ -1078,7 +1078,7 @@ void NetHackQtTextWindow::UseRIP(int how, time_t when)
|
||||
(simplest case: ~300K four times in a blessed bag of holding, so
|
||||
~1.2M; in addition to the hassle of getting such a thing set up,
|
||||
it would need many gold-rich bones levels or wizard mode wishing) */
|
||||
long cash = std::max(g.done_money, 0L);
|
||||
long cash = std::max(gd.done_money, 0L);
|
||||
/* force less that 10 digits to satisfy elaborate format checking;
|
||||
it's arbitrary but still way, way more than could ever be needed */
|
||||
if (cash < 0)
|
||||
|
||||
@@ -40,17 +40,17 @@ extern "C" {
|
||||
/* check whether plname[] is among the list of generic user names */
|
||||
static bool generic_plname()
|
||||
{
|
||||
if (*g.plname) {
|
||||
if (*gp.plname) {
|
||||
const char *sptr, *p;
|
||||
const char *genericusers = sysopt.genericusers;
|
||||
int ln = (int) strlen(g.plname);
|
||||
int ln = (int) strlen(gp.plname);
|
||||
|
||||
if (!genericusers || !*genericusers)
|
||||
genericusers = "player games";
|
||||
else if (!strcmp(genericusers, "*")) /* "*" => always ask for name */
|
||||
return true;
|
||||
|
||||
while ((sptr = strstri(genericusers, g.plname)) != NULL) {
|
||||
while ((sptr = strstri(genericusers, gp.plname)) != NULL) {
|
||||
/* check for full word: start of list or following a space */
|
||||
if ((sptr == genericusers || sptr[-1] == ' ')
|
||||
/* and also preceding a space or at end of list */
|
||||
@@ -263,8 +263,8 @@ NetHackQtPlayerSelector::NetHackQtPlayerSelector(
|
||||
|
||||
// if plname[] contains a generic user name, clear it
|
||||
if (generic_plname())
|
||||
*g.plname = '\0';
|
||||
name->setText(g.plname);
|
||||
*gp.plname = '\0';
|
||||
name->setText(gp.plname);
|
||||
connect(name, SIGNAL(textChanged(const QString&)),
|
||||
this, SLOT(selectName(const QString&)));
|
||||
name->setFocus();
|
||||
@@ -545,7 +545,7 @@ void NetHackQtPlayerSelector::Randomize()
|
||||
// if plname[] is empty, disable [Play], otherwise [Play] is the default
|
||||
void NetHackQtPlayerSelector::plnamePlayVsQuit()
|
||||
{
|
||||
if (*g.plname) {
|
||||
if (*gp.plname) {
|
||||
play_btn->setEnabled(true);
|
||||
play_btn->setDefault(true);
|
||||
//quit_btn->setDefault(false);
|
||||
@@ -564,7 +564,7 @@ void NetHackQtPlayerSelector::selectName(const QString& n)
|
||||
// (it would be better to set up a validator that rejects leading spaces)
|
||||
while (*name_str == ' ')
|
||||
++name_str;
|
||||
str_copy(g.plname, name_str, PL_NSIZ);
|
||||
str_copy(gp.plname, name_str, PL_NSIZ);
|
||||
// possibly enable or disable the [Play] button
|
||||
plnamePlayVsQuit();
|
||||
}
|
||||
|
||||
@@ -817,17 +817,17 @@ void NetHackQtStatusWindow::updateStats()
|
||||
buf = nh_capitalize_words(pmname(&mons[u.umonnum],
|
||||
::flags.female ? FEMALE : MALE));
|
||||
} else {
|
||||
buf = rank_of(u.ulevel, g.pl_character[0], ::flags.female);
|
||||
buf = rank_of(u.ulevel, gp.pl_character[0], ::flags.female);
|
||||
}
|
||||
QString buf2;
|
||||
char buf3[BUFSZ];
|
||||
buf2 = nh_qsprintf("%s the %s", upstart(strcpy(buf3, g.plname)),
|
||||
buf2 = nh_qsprintf("%s the %s", upstart(strcpy(buf3, gp.plname)),
|
||||
buf.toLatin1().constData());
|
||||
name.setLabel(buf2, NetHackQtLabelledIcon::NoNum, u.ulevel);
|
||||
|
||||
if (!describe_level(buf3, 0)) {
|
||||
Sprintf(buf3, "%s, level %d",
|
||||
g.dungeons[u.uz.dnum].dname, ::depth(&u.uz));
|
||||
gd.dungeons[u.uz.dnum].dname, ::depth(&u.uz));
|
||||
}
|
||||
dlevel.setLabel(buf3);
|
||||
|
||||
@@ -885,7 +885,7 @@ void NetHackQtStatusWindow::updateStats()
|
||||
ac.setLabel("AC:", (long) u.uac);
|
||||
// gold prefix used to be "Au:", tty uses "$:"; never too wide to fit;
|
||||
// practical limit due to carrying capacity limit is less than 300K
|
||||
long goldamt = money_cnt(g.invent);
|
||||
long goldamt = money_cnt(gi.invent);
|
||||
goldamt = std::max(goldamt, 0L); // sanity; core's botl() does likewise
|
||||
goldamt = std::min(goldamt, 99999999L); // ditto
|
||||
gold.setLabel("Gold:", goldamt);
|
||||
@@ -925,7 +925,7 @@ void NetHackQtStatusWindow::updateStats()
|
||||
if (::flags.time) {
|
||||
// hypothetically Time could grow to enough digits to have trouble
|
||||
// fitting, but it's not worth worrying about
|
||||
time.setLabel("Time:", (long) g.moves);
|
||||
time.setLabel("Time:", (long) gm.moves);
|
||||
} else {
|
||||
time.setLabel("");
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ char NetHackQtYnDialog::Exec()
|
||||
}
|
||||
if ( question.indexOf("what direction") >= 0 ) {
|
||||
// We replace this regardless, since sometimes you get choices.
|
||||
const char* d = g.Cmd.dirchars;
|
||||
const char* d = gc.Cmd.dirchars;
|
||||
enable=ch;
|
||||
ch="";
|
||||
ch.append(d[1]);
|
||||
@@ -220,7 +220,7 @@ char NetHackQtYnDialog::Exec()
|
||||
// for "ynaq" (where "all" is a choice) it's "stop"
|
||||
// and for end of game disclosure it really is "quit"
|
||||
if (question.left(10) == QString("Dump core?")
|
||||
|| (::g.program_state.gameover
|
||||
|| (::gp.program_state.gameover
|
||||
&& question.left(11) == QString("Do you want")))
|
||||
button_name = "Quit";
|
||||
else if (is_ynaq)
|
||||
|
||||
Reference in New Issue
Block a user