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

@@ -1032,9 +1032,9 @@ NetHackQtPlayerSelector::NetHackQtPlayerSelector(NetHackQtKeyBuffer& ks) :
QButtonGroup* namebox = new QButtonGroup(1,Horizontal,"Name",this);
QLineEdit* name = new QLineEdit(namebox);
name->setMaxLength(sizeof(g.plname)-1);
if ( strncmp(g.plname,"player",6) && strncmp(g.plname,"games",5) )
name->setText(g.plname);
name->setMaxLength(sizeof(gp.plname)-1);
if ( strncmp(gp.plname,"player",6) && strncmp(gp.plname,"games",5) )
name->setText(gp.plname);
connect(name, SIGNAL(textChanged(const QString&)),
this, SLOT(selectName(const QString&)) );
name->setFocus();
@@ -1190,7 +1190,7 @@ NetHackQtPlayerSelector::NetHackQtPlayerSelector(NetHackQtKeyBuffer& ks) :
void NetHackQtPlayerSelector::selectName(const QString& n)
{
strncpy(g.plname,n.latin1(),sizeof(g.plname)-1);
strncpy(gp.plname,n.latin1(),sizeof(gp.plname)-1);
}
void NetHackQtPlayerSelector::selectRole()
@@ -2550,7 +2550,7 @@ void NetHackQtStatusWindow::updateStats()
encumber.setLabel(enc);
encumber.show();
}
Strcpy(buf, g.plname);
Strcpy(buf, gp.plname);
if ('a' <= buf[0] && buf[0] <= 'z') buf[0] += 'A'-'a';
Strcat(buf, " the ");
if (u.mtimedone) {
@@ -2579,7 +2579,7 @@ void NetHackQtStatusWindow::updateStats()
dlevel.setLabel(buf,(long)depth(&u.uz));
}
gold.setLabel("Au:", money_cnt(g.invent));
gold.setLabel("Au:", money_cnt(gi.invent));
if (u.mtimedone) {
// You're a monster!
@@ -2613,7 +2613,7 @@ void NetHackQtStatusWindow::updateStats()
align.setLabel("Lawful");
}
if (::flags.time) time.setLabel("Time:",(long)g.moves);
if (::flags.time) time.setLabel("Time:",(long)gm.moves);
else time.setLabel("");
#ifdef SCORE_ON_BOTL
if (::flags.showscore) {
@@ -3325,7 +3325,7 @@ static char** rip_line=0;
long year;
/* Put name on stone */
Sprintf(rip_line[NAME_LINE], "%s", g.plname);
Sprintf(rip_line[NAME_LINE], "%s", gp.plname);
/* Put $ on stone */
Sprintf(rip_line[GOLD_LINE], "%ld Au", done_money);
@@ -4052,7 +4052,7 @@ void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event)
void NetHackQtMainWindow::closeEvent(QCloseEvent* e)
{
if ( g.program_state.something_worth_saving ) {
if ( gp.program_state.something_worth_saving ) {
switch ( QMessageBox::information( this, "NetHack",
"This will end your NetHack session",
"&Save", "&Cancel", 0, 1 ) )
@@ -4644,7 +4644,7 @@ void NetHackQtBind::qt_askname()
NetHackQtSavedGameSelector sgsel((const char**)saved);
ch = sgsel.choose();
if ( ch >= 0 )
strcpy(g.plname,saved[ch]);
strcpy(gp.plname,saved[ch]);
}
free_saved_games(saved);
@@ -4864,7 +4864,7 @@ void NetHackQtBind::qt_update_inventory()
if (main)
main->updateInventory();
/* 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);
*/
}
@@ -4918,14 +4918,14 @@ int NetHackQtBind::qt_nhgetch()
//
while (keybuffer.Empty()
#ifdef SAFERHANGUP
&& !g.program_state.done_hup
&& !gp.program_state.done_hup
#endif
) {
qApp->enter_loop();
}
#ifdef SAFERHANGUP
if (g.program_state.done_hup && keybuffer.Empty()) return '\033';
if (gp.program_state.done_hup && keybuffer.Empty()) return '\033';
#endif
return keybuffer.GetAscii();
}
@@ -4939,13 +4939,13 @@ int NetHackQtBind::qt_nh_poskey(int *x, int *y, int *mod)
//
while (keybuffer.Empty() && clickbuffer.Empty()
#ifdef SAFERHANGUP
&& !g.program_state.done_hup
&& !gp.program_state.done_hup
#endif
) {
qApp->enter_loop();
}
#ifdef SAFERHANGUP
if (g.program_state.done_hup && keybuffer.Empty()) return '\033';
if (gp.program_state.done_hup && keybuffer.Empty()) return '\033';
#endif
if (!keybuffer.Empty()) {
return keybuffer.GetAscii();
@@ -5194,7 +5194,7 @@ bool NetHackQtBind::notify(QObject *receiver, QEvent *event)
bool result=QApplication::notify(receiver,event);
#ifdef SAFERHANGUP
if (g.program_state.done_hup) {
if (gp.program_state.done_hup) {
keybuffer.Put('\033');
qApp->exit_loop();
return TRUE;

View File

@@ -501,7 +501,7 @@ Gem_player_selection()
void
Gem_askname()
{
strncpy(g.plname, mar_ask_name(), PL_NSIZ);
strncpy(gp.plname, mar_ask_name(), PL_NSIZ);
}
void
@@ -1078,7 +1078,7 @@ time_t when;
}
/* Follows same algorithm as genl_outrip() */
/* Put name on stone */
Sprintf(rip_line[NAME_LINE], "%s", g.plname);
Sprintf(rip_line[NAME_LINE], "%s", gp.plname);
/* Put $ on stone */
Sprintf(rip_line[GOLD_LINE], "%ld Au", done_money);
/* Put together death description */

View File

@@ -1647,13 +1647,13 @@ const char *str;
}
message_line[mesg_hist - 1] = tmp;
}
strcpy(g.toplines, str);
strcpy(gt.toplines, str);
messages_pro_zug++;
msg_max++;
if ((int) strlen(g.toplines) >= msg_width) {
if ((int) strlen(gt.toplines) >= msg_width) {
int pos = msg_width;
tmp = g.toplines + msg_width;
tmp = gt.toplines + msg_width;
while (*tmp != ' ' && pos >= 0) {
tmp--;
pos--;
@@ -1661,12 +1661,12 @@ const char *str;
if (pos <= 0)
pos = msg_width; /* Mar -- Oops, what a word :-) */
message_age[msg_max] = TRUE;
strncpy(message_line[msg_max], g.toplines, pos);
strncpy(message_line[msg_max], gt.toplines, pos);
message_line[msg_max][pos] = 0;
rest = strcpy(buf, g.toplines + pos);
rest = strcpy(buf, gt.toplines + pos);
} else {
message_age[msg_max] = TRUE;
strncpy(message_line[msg_max], g.toplines, msg_width);
strncpy(message_line[msg_max], gt.toplines, msg_width);
rest = 0;
}

View File

@@ -354,7 +354,7 @@ gnome_askname()
/* Ask for a name and stuff the response into plname, a nethack global */
ret = ghack_ask_string_dialog("What is your name?", "gandalf",
"GnomeHack", g.plname);
"GnomeHack", gp.plname);
/* Quit if they want to quit... */
if (ret == -1) {
@@ -907,7 +907,7 @@ gnome_nhgetch()
g_askingQuestion = 1;
/* Process events until a key press event arrives. */
while (g_numKeys == 0) {
if (g.program_state.done_hup)
if (gp.program_state.done_hup)
return '\033';
gtk_main_iteration();
}
@@ -945,7 +945,7 @@ gnome_nh_poskey(int *x, int *y, int *mod)
g_askingQuestion = 0;
/* Process events until a key or map-click arrives. */
while (g_numKeys == 0 && g_numClicks == 0) {
if (g.program_state.done_hup)
if (gp.program_state.done_hup)
return '\033';
gtk_main_iteration();
}
@@ -1169,7 +1169,7 @@ gnome_outrip(winid wid, int how, time_t when)
long year;
/* Put name on stone */
Sprintf(buf, "%s\n", g.plname);
Sprintf(buf, "%s\n", gp.plname);
Strcat(ripString, buf);
/* Put $ on stone */

View File

@@ -440,7 +440,7 @@ ghack_status_window_update_stats()
long umoney;
/* First, fill in the player name and the dungeon level */
strcpy(buf, g.plname);
strcpy(buf, gp.plname);
if ('a' <= buf[0] && buf[0] <= 'z')
buf[0] += 'A' - 'a';
strcat(buf, " the ");
@@ -558,7 +558,7 @@ ghack_status_window_update_stats()
gtk_label_set(GTK_LABEL(chaLabel), buf);
/* Now do the non-pixmaped stats (gold and such) */
umoney = money_cnt(g.invent);
umoney = money_cnt(gi.invent);
sprintf(buf, "Au:%ld", umoney);
if (lastAu < umoney && firstTime == FALSE) {
/* Ok, this changed so add it to the highlighing list */
@@ -662,7 +662,7 @@ ghack_status_window_update_stats()
}
if (flags.time) {
sprintf(buf, "Time:%ld", g.moves);
sprintf(buf, "Time:%ld", gm.moves);
gtk_label_set(GTK_LABEL(timeLabel), buf);
} else
gtk_label_set(GTK_LABEL(timeLabel), "");