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:
@@ -220,7 +220,7 @@ curses_character_input_dialog(
|
||||
re-activate them now that input is being requested */
|
||||
curses_got_input();
|
||||
|
||||
if (g.invent || (g.moves > 1)) {
|
||||
if (gi.invent || (gm.moves > 1)) {
|
||||
curses_get_window_size(MAP_WIN, &map_height, &map_width);
|
||||
} else {
|
||||
map_height = term_rows;
|
||||
@@ -775,7 +775,7 @@ curses_display_nhmenu(
|
||||
menu_determine_pages(current_menu);
|
||||
|
||||
/* Display pre and post-game menus centered */
|
||||
if ((g.moves <= 1 && !g.invent) || g.program_state.gameover) {
|
||||
if ((gm.moves <= 1 && !gi.invent) || gp.program_state.gameover) {
|
||||
win = curses_create_window(current_menu->width,
|
||||
current_menu->height, CENTER);
|
||||
} else { /* Display during-game menus on the right out of the way */
|
||||
@@ -1018,7 +1018,7 @@ menu_win_size(nhmenu *menu)
|
||||
int maxheaderwidth = menu->prompt ? (int) strlen(menu->prompt) : 0;
|
||||
nhmenu_item *menu_item_ptr;
|
||||
|
||||
if (g.program_state.gameover) {
|
||||
if (gp.program_state.gameover) {
|
||||
/* for final inventory disclosure, use full width */
|
||||
maxwidth = term_cols - 2; /* +2: borders assumed */
|
||||
} else {
|
||||
|
||||
@@ -742,9 +742,9 @@ curses_init_options(void)
|
||||
set_option_mod_status("eight_bit_tty", set_in_config);
|
||||
|
||||
/* If we don't have a symset defined, load the curses symset by default */
|
||||
if (!g.symset[PRIMARYSET].explicitly)
|
||||
if (!gs.symset[PRIMARYSET].explicitly)
|
||||
load_symset("curses", PRIMARYSET);
|
||||
if (!g.symset[ROGUESET].explicitly)
|
||||
if (!gs.symset[ROGUESET].explicitly)
|
||||
load_symset("default", ROGUESET);
|
||||
|
||||
#ifdef PDCURSES
|
||||
|
||||
@@ -297,9 +297,9 @@ curses_askname(void)
|
||||
}
|
||||
#endif /* SELECTSAVED */
|
||||
|
||||
curses_line_input_dialog("Who are you?", g.plname, PL_NSIZ);
|
||||
(void) mungspaces(g.plname);
|
||||
if (!g.plname[0] || g.plname[0] == '\033')
|
||||
curses_line_input_dialog("Who are you?", gp.plname, PL_NSIZ);
|
||||
(void) mungspaces(gp.plname);
|
||||
if (!gp.plname[0] || gp.plname[0] == '\033')
|
||||
goto bail;
|
||||
|
||||
iflags.renameallowed = TRUE; /* tty uses this, we don't [yet?] */
|
||||
@@ -701,7 +701,7 @@ curses_update_inventory(int arg)
|
||||
}
|
||||
|
||||
/* skip inventory updating during character initialization */
|
||||
if (!g.program_state.in_moveloop && !g.program_state.gameover)
|
||||
if (!gp.program_state.in_moveloop && !gp.program_state.gameover)
|
||||
return;
|
||||
|
||||
if (!arg) {
|
||||
|
||||
@@ -77,7 +77,7 @@ curses_message_win_puts(const char *message, boolean recursed)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (curs_mesg_suppress_seq == g.hero_seq) {
|
||||
if (curs_mesg_suppress_seq == gh.hero_seq) {
|
||||
return; /* user has typed ESC to avoid seeing remaining messages. */
|
||||
}
|
||||
|
||||
@@ -89,19 +89,19 @@ curses_message_win_puts(const char *message, boolean recursed)
|
||||
my = border_space;
|
||||
|
||||
if (strcmp(message, "#") == 0) { /* Extended command or Count: */
|
||||
if ((strcmp(g.toplines, "#") != 0)
|
||||
if ((strcmp(gt.toplines, "#") != 0)
|
||||
/* Bottom of message window */
|
||||
&& (my >= (height - 1 + border_space)) && (height != 1)) {
|
||||
scroll_window(MESSAGE_WIN);
|
||||
mx = width;
|
||||
my--;
|
||||
Strcpy(g.toplines, message);
|
||||
Strcpy(gt.toplines, message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!recursed) {
|
||||
strcpy(g.toplines, message);
|
||||
strcpy(gt.toplines, message);
|
||||
mesg_add_line(message);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ curses_message_win_puts(const char *message, boolean recursed)
|
||||
this turn unless an urgent message is being delivered */
|
||||
if (curses_more() == '\033'
|
||||
&& !curs_mesg_no_suppress) {
|
||||
curs_mesg_suppress_seq = g.hero_seq;
|
||||
curs_mesg_suppress_seq = gh.hero_seq;
|
||||
return;
|
||||
}
|
||||
/* turn_lines reset to 0 by more()->block()->got_input() */
|
||||
@@ -321,7 +321,7 @@ curses_last_messages(void)
|
||||
if (mesg && mesg->str && *mesg->str)
|
||||
curses_message_win_puts(mesg->str, TRUE);
|
||||
}
|
||||
curses_message_win_puts(g.toplines, TRUE);
|
||||
curses_message_win_puts(gt.toplines, TRUE);
|
||||
--last_messages;
|
||||
|
||||
if (border)
|
||||
@@ -681,7 +681,7 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
|
||||
case '\n':
|
||||
(void) strncpy(answer, p_answer, buffer);
|
||||
answer[buffer - 1] = '\0';
|
||||
Strcpy(g.toplines, tmpbuf);
|
||||
Strcpy(gt.toplines, tmpbuf);
|
||||
mesg_add_line(tmpbuf);
|
||||
#if 1
|
||||
/* position at end of current line so next message will be
|
||||
@@ -818,7 +818,7 @@ mesg_add_line(const char *mline)
|
||||
current_mesg->str = dupstr(mline);
|
||||
}
|
||||
}
|
||||
current_mesg->turn = g.hero_seq;
|
||||
current_mesg->turn = gh.hero_seq;
|
||||
|
||||
if (num_messages == 0) {
|
||||
/* very first message; set up head */
|
||||
@@ -934,7 +934,7 @@ curses_putmsghistory(const char *msg, boolean restoring_msghist)
|
||||
initd = TRUE;
|
||||
#ifdef DUMPLOG
|
||||
/* this suffices; there's no need to scrub g.saved_pline[] pointers */
|
||||
g.saved_pline_index = 0;
|
||||
gs.saved_pline_index = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -944,7 +944,7 @@ curses_putmsghistory(const char *msg, boolean restoring_msghist)
|
||||
however, we aren't only called when restoring history;
|
||||
core uses putmsghistory() for other stuff during play
|
||||
and those messages should have a normal turn value */
|
||||
last_mesg->turn = restoring_msghist ? (1L << 3) : g.hero_seq;
|
||||
last_mesg->turn = restoring_msghist ? (1L << 3) : gh.hero_seq;
|
||||
#ifdef DUMPLOG
|
||||
dumplogmsg(last_mesg->str);
|
||||
#endif
|
||||
|
||||
@@ -925,7 +925,7 @@ curses_convert_keys(int key)
|
||||
if (iflags.num_pad) {
|
||||
ret = '7';
|
||||
} else {
|
||||
ret = !g.Cmd.swap_yz ? 'y' : 'z';
|
||||
ret = !gc.Cmd.swap_yz ? 'y' : 'z';
|
||||
}
|
||||
break;
|
||||
#ifdef KEY_A3
|
||||
|
||||
@@ -147,7 +147,7 @@ curses_status_update(int fldidx, genericptr_t ptr, int chg UNUSED, int percent,
|
||||
|
||||
if (fldidx != BL_FLUSH) {
|
||||
if (fldidx < 0 || fldidx >= MAXBLSTATS) {
|
||||
g.context.botlx = g.context.botl = FALSE; /* avoid another bot() */
|
||||
gc.context.botlx = gc.context.botl = FALSE; /* avoid another bot() */
|
||||
panic("curses_status_update(%d)", fldidx);
|
||||
}
|
||||
changed_fields |= (1 << fldidx);
|
||||
@@ -1848,7 +1848,7 @@ draw_horizontal(int x, int y, int hp, int hpmax)
|
||||
wmove(win, y, x);
|
||||
|
||||
get_playerrank(rank);
|
||||
sprintf(buf, "%s the %s", g.plname, rank);
|
||||
sprintf(buf, "%s the %s", gp.plname, rank);
|
||||
|
||||
/* Use the title as HP bar (similar to hitpointbar) */
|
||||
draw_bar(TRUE, hp, hpmax, buf);
|
||||
@@ -1878,7 +1878,7 @@ draw_horizontal(int x, int y, int hp, int hpmax)
|
||||
|
||||
wprintw(win, "%s", buf);
|
||||
|
||||
print_statdiff("$", &prevau, money_cnt(g.invent), STAT_GOLD);
|
||||
print_statdiff("$", &prevau, money_cnt(gi.invent), STAT_GOLD);
|
||||
|
||||
/* HP/Pw use special coloring rules */
|
||||
attr_t hpattr, pwattr;
|
||||
@@ -1916,7 +1916,7 @@ draw_horizontal(int x, int y, int hp, int hpmax)
|
||||
print_statdiff(" Exp:", &prevlevel, u.ulevel, STAT_OTHER);
|
||||
|
||||
if (flags.time)
|
||||
print_statdiff(" T:", &prevtime, g.moves, STAT_TIME);
|
||||
print_statdiff(" T:", &prevtime, gm.moves, STAT_TIME);
|
||||
|
||||
curses_add_statuses(win, FALSE, FALSE, NULL, NULL);
|
||||
}
|
||||
@@ -1933,9 +1933,9 @@ draw_horizontal_new(int x, int y, int hp, int hpmax)
|
||||
|
||||
get_playerrank(rank);
|
||||
char race[BUFSZ];
|
||||
Strcpy(race, g.urace.adj);
|
||||
Strcpy(race, gu.urace.adj);
|
||||
race[0] = highc(race[0]);
|
||||
wprintw(win, "%s the %s %s%s%s", g.plname,
|
||||
wprintw(win, "%s the %s %s%s%s", gp.plname,
|
||||
(u.ualign.type == A_CHAOTIC ? "Chaotic" :
|
||||
u.ualign.type == A_NEUTRAL ? "Neutral" : "Lawful"),
|
||||
Upolyd ? "" : race, Upolyd ? "" : " ",
|
||||
@@ -1989,7 +1989,7 @@ draw_horizontal_new(int x, int y, int hp, int hpmax)
|
||||
wprintw(win, "Pw:");
|
||||
draw_bar(FALSE, u.uen, u.uenmax, NULL);
|
||||
|
||||
print_statdiff(" $", &prevau, money_cnt(g.invent), STAT_GOLD);
|
||||
print_statdiff(" $", &prevau, money_cnt(gi.invent), STAT_GOLD);
|
||||
|
||||
#ifdef SCORE_ON_BOTL
|
||||
if (flags.showscore)
|
||||
@@ -1997,7 +1997,7 @@ draw_horizontal_new(int x, int y, int hp, int hpmax)
|
||||
#endif /* SCORE_ON_BOTL */
|
||||
|
||||
if (flags.time)
|
||||
print_statdiff(" T:", &prevtime, g.moves, STAT_TIME);
|
||||
print_statdiff(" T:", &prevtime, gm.moves, STAT_TIME);
|
||||
|
||||
curses_add_statuses(win, TRUE, FALSE, &x, &y);
|
||||
|
||||
@@ -2054,7 +2054,7 @@ draw_vertical(int x, int y, int hp, int hpmax)
|
||||
|
||||
get_playerrank(rank);
|
||||
int ranklen = strlen(rank);
|
||||
int namelen = strlen(g.plname);
|
||||
int namelen = strlen(gp.plname);
|
||||
int maxlen = 19;
|
||||
#ifdef STATUS_COLORS
|
||||
if (!iflags.hitpointbar)
|
||||
@@ -2071,7 +2071,7 @@ draw_vertical(int x, int y, int hp, int hpmax)
|
||||
while ((ranklen + namelen) > maxlen)
|
||||
ranklen--; /* Still doesn't fit, strip rank */
|
||||
}
|
||||
sprintf(buf, "%-*s the %-*s", namelen, g.plname, ranklen, rank);
|
||||
sprintf(buf, "%-*s the %-*s", namelen, gp.plname, ranklen, rank);
|
||||
draw_bar(TRUE, hp, hpmax, buf);
|
||||
wmove(win, y++, x);
|
||||
wprintw(win, "%s", dungeons[u.uz.dnum].dname);
|
||||
@@ -2105,7 +2105,7 @@ draw_vertical(int x, int y, int hp, int hpmax)
|
||||
wprintw(win, "%d", depth(&u.uz));
|
||||
wmove(win, y++, x);
|
||||
|
||||
print_statdiff("Gold: ", &prevau, money_cnt(g.invent), STAT_GOLD);
|
||||
print_statdiff("Gold: ", &prevau, money_cnt(gi.invent), STAT_GOLD);
|
||||
wmove(win, y++, x);
|
||||
|
||||
/* HP/Pw use special coloring rules */
|
||||
@@ -2150,7 +2150,7 @@ draw_vertical(int x, int y, int hp, int hpmax)
|
||||
wmove(win, y++, x);
|
||||
|
||||
if (flags.time) {
|
||||
print_statdiff("Time: ", &prevtime, g.moves, STAT_TIME);
|
||||
print_statdiff("Time: ", &prevtime, gm.moves, STAT_TIME);
|
||||
wmove(win, y++, x);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ curses_create_window(int width, int height, orient orientation)
|
||||
|
||||
if ((orientation == UP) || (orientation == DOWN) ||
|
||||
(orientation == LEFT) || (orientation == RIGHT)) {
|
||||
if (g.invent || (g.moves > 1)) {
|
||||
if (gi.invent || (gm.moves > 1)) {
|
||||
map_border = curses_window_has_border(MAP_WIN);
|
||||
curses_get_window_xy(MAP_WIN, &mapx, &mapy);
|
||||
curses_get_window_size(MAP_WIN, &maph, &mapw);
|
||||
@@ -97,7 +97,7 @@ curses_create_window(int width, int height, orient orientation)
|
||||
starty = (term_rows / 2) - (height / 2);
|
||||
break;
|
||||
case UP:
|
||||
if (g.invent || (g.moves > 1)) {
|
||||
if (gi.invent || (gm.moves > 1)) {
|
||||
startx = (mapw / 2) - (width / 2) + mapx + mapb_offset;
|
||||
} else {
|
||||
startx = 0;
|
||||
@@ -106,7 +106,7 @@ curses_create_window(int width, int height, orient orientation)
|
||||
starty = mapy + mapb_offset;
|
||||
break;
|
||||
case DOWN:
|
||||
if (g.invent || (g.moves > 1)) {
|
||||
if (gi.invent || (gm.moves > 1)) {
|
||||
startx = (mapw / 2) - (width / 2) + mapx + mapb_offset;
|
||||
} else {
|
||||
startx = 0;
|
||||
@@ -122,7 +122,7 @@ curses_create_window(int width, int height, orient orientation)
|
||||
starty = term_rows - height;
|
||||
break;
|
||||
case RIGHT:
|
||||
if (g.invent || (g.moves > 1)) {
|
||||
if (gi.invent || (gm.moves > 1)) {
|
||||
startx = (mapw + mapx + (mapb_offset * 2)) - width;
|
||||
} else {
|
||||
startx = term_cols - width;
|
||||
@@ -174,7 +174,7 @@ curses_refresh_nethack_windows(void)
|
||||
map_window = curses_get_nhwin(MAP_WIN);
|
||||
inv_window = curses_get_nhwin(INV_WIN);
|
||||
|
||||
if ((g.moves <= 1) && !g.invent) {
|
||||
if ((gm.moves <= 1) && !gi.invent) {
|
||||
/* Main windows not yet displayed; refresh base window instead */
|
||||
touchwin(stdscr);
|
||||
refresh();
|
||||
|
||||
Reference in New Issue
Block a user