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

@@ -288,7 +288,7 @@ saveDiskPrompt(start)
BPTR fileLock;
if (sysflags.asksavedisk) {
/* Don't prompt if you can find the save file */
if (fileLock = Lock(g.SAVEF, SHARED_LOCK)) {
if (fileLock = Lock(gs.SAVEF, SHARED_LOCK)) {
UnLock(fileLock);
#if defined(TTY_GRAPHICS)
if (windowprocs.win_init_nhwindows
@@ -303,7 +303,7 @@ saveDiskPrompt(start)
return 1;
}
pline("If save file is on a SAVE disk, put that disk in now.");
if (strlen(g.SAVEF) > QBUFSZ - 25 - 22)
if (strlen(gs.SAVEF) > QBUFSZ - 25 - 22)
panic("not enough buffer space for prompt");
/* THIS IS A HACK */
#if defined(TTY_GRAPHICS)
@@ -314,7 +314,7 @@ saveDiskPrompt(start)
#endif
#if defined(AMII_GRAPHICS)
if (windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows) {
getlind("File name ?", buf, g.SAVEF);
getlind("File name ?", buf, gs.SAVEF);
clear_nhwindow(WIN_BASE);
}
#endif
@@ -323,11 +323,11 @@ saveDiskPrompt(start)
return 0;
/* Strip any whitespace. Also, if nothing was entered except
* whitespace, do not change the value of g.SAVEF.
* whitespace, do not change the value of gs.SAVEF.
*/
for (bp = buf; *bp; bp++) {
if (!isspace(*bp)) {
strncpy(g.SAVEF, bp, PATHLEN);
strncpy(gs.SAVEF, bp, PATHLEN);
break;
}
}

View File

@@ -185,12 +185,12 @@ time_t when;
SetDrMd(rp, JAM1);
/* Put name on stone */
Sprintf(buf, "%s", g.plname);
Sprintf(buf, "%s", gp.plname);
buf[STONE_LINE_LEN] = 0;
tomb_text(buf);
/* Put $ on stone */
Sprintf(buf, "%ld Au", g.done_money);
Sprintf(buf, "%ld Au", gd.done_money);
buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */
tomb_text(buf);

View File

@@ -357,7 +357,7 @@ menu_item **retmip;
nw->Screen = HackScreen;
if (win == WIN_INVEN) {
sprintf(title, "%s the %s's Inventory", g.plname, g.pl_character);
sprintf(title, "%s the %s's Inventory", gp.plname, gp.pl_character);
nw->Title = title;
if (lastinvent.MaxX != 0) {
nw->LeftEdge = lastinvent.MinX;

View File

@@ -437,10 +437,10 @@ amii_askname()
amii_getlin("Who are you?", plnametmp);
} while (strlen(plnametmp) == 0);
strncpy(g.plname, plnametmp, PL_NSIZ - 1); /* Avoid overflowing plname[] */
g.plname[PL_NSIZ - 1] = 0;
strncpy(gp.plname, plnametmp, PL_NSIZ - 1); /* Avoid overflowing plname[] */
gp.plname[PL_NSIZ - 1] = 0;
if (*g.plname == '\33') {
if (*gp.plname == '\33') {
clearlocks();
exit_nhwindows(NULL);
nh_terminate(0);
@@ -474,9 +474,9 @@ amii_player_selection()
#if 0 /* Don't query the user ... instead give random character -jhsa */
#if 0 /* OBSOLETE */
if( *g.pl_character ){
g.pl_character[ 0 ] = toupper( g.pl_character[ 0 ] );
if( strchr( pl_classes, g.pl_character[ 0 ] ) )
if( *gp.pl_character ){
gp.pl_character[ 0 ] = toupper( gp.pl_character[ 0 ] );
if( strchr( pl_classes, gp.pl_character[ 0 ] ) )
return;
}
#endif
@@ -530,19 +530,19 @@ amii_player_selection()
case VANILLAKEY:
if( strchr( pl_classes, toupper( code ) ) )
{
g.pl_character[0] = toupper( code );
gp.pl_character[0] = toupper( code );
aredone = 1;
}
else if( code == ' ' || code == '\n' || code == '\r' )
{
flags.initrole = randrole(FALSE);
#if 0 /* OBSOLETE */
strcpy( g.pl_character, roles[ rnd( 11 ) ] );
strcpy( gp.pl_character, roles[ rnd( 11 ) ] );
#endif
aredone = 1;
amii_clear_nhwindow( WIN_BASE );
CloseShWindow( cwin );
RandomWindow( g.pl_character );
RandomWindow( gp.pl_character );
return;
}
else if( code == 'q' || code == 'Q' )
@@ -562,15 +562,15 @@ amii_player_selection()
case 1: /* Random Character */
flags.initrole = randrole(FALSE);
#if 0 /* OBSOLETE */
strcpy( g.pl_character, roles[ rnd( 11 ) ] );
strcpy( gp.pl_character, roles[ rnd( 11 ) ] );
#endif
amii_clear_nhwindow( WIN_BASE );
CloseShWindow( cwin );
RandomWindow( g.pl_character );
RandomWindow( gp.pl_character );
return;
default:
g.pl_character[0] = gd->GadgetID;
gp.pl_character[0] = gd->GadgetID;
break;
}
aredone = 1;

View File

@@ -81,8 +81,8 @@ const char *str;
while (isspace(*str))
str++;
strncpy(g.toplines, str, TBUFSZ);
g.toplines[TBUFSZ - 1] = 0;
strncpy(gt.toplines, str, TBUFSZ);
gt.toplines[TBUFSZ - 1] = 0;
/* For initial message to be visible, we need to explicitly position
* the
@@ -101,15 +101,15 @@ const char *str;
memcpy(cw->data, &cw->data[1],
(iflags.msg_history - 1) * sizeof(char *));
cw->data[iflags.msg_history - 1] =
(char *) alloc(strlen(g.toplines) + 5);
(char *) alloc(strlen(gt.toplines) + 5);
strcpy(cw->data[i = iflags.msg_history - 1] + SOFF
+ (scrollmsg != 0),
g.toplines);
gt.toplines);
} else {
/* Otherwise, allocate a new one and copy the line in */
cw->data[cw->maxrow] = (char *) alloc(strlen(g.toplines) + 5);
cw->data[cw->maxrow] = (char *) alloc(strlen(gt.toplines) + 5);
strcpy(cw->data[i = cw->maxrow++] + SOFF + (scrollmsg != 0),
g.toplines);
gt.toplines);
}
cw->data[i][SEL_ITEM] = 1;
cw->data[i][VATTR] = attr + 1;
@@ -182,7 +182,7 @@ const char *str;
/ w->RPort->TxHeight,
totalvis, totalvis);
}
i = strlen(g.toplines + SOFF);
i = strlen(gt.toplines + SOFF);
cw->maxcol = max(cw->maxcol, i);
cw->vwy = cw->maxrow;
break;
@@ -191,7 +191,7 @@ const char *str;
if (cw->data[cw->cury] == NULL)
panic("NULL pointer for status window");
ob = &cw->data[cw->cury][j = cw->curx];
if (g.context.botlx)
if (gc.context.botlx)
*ob = 0;
/* Display when beam at top to avoid flicker... */

View File

@@ -88,7 +88,7 @@ attempt_restore:
if (yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile();
else {
nh_compress(fqname(g.SAVEF, SAVEPREFIX, 0));
nh_compress(fqname(gs.SAVEF, SAVEPREFIX, 0));
}
}
}
@@ -132,14 +132,14 @@ whoami(void)
*/
char *s;
if (*g.plname)
if (*gp.plname)
return;
if (s = nh_getenv("USER")) {
(void) strncpy(g.plname, s, sizeof(g.plname) - 1);
(void) strncpy(gp.plname, s, sizeof(gp.plname) - 1);
return;
}
if (s = nh_getenv("LOGNAME")) {
(void) strncpy(g.plname, s, sizeof(g.plname) - 1);
(void) strncpy(gp.plname, s, sizeof(gp.plname) - 1);
return;
}
}
@@ -177,11 +177,11 @@ process_options(int argc, char **argv)
#endif
case 'u':
if (argv[0][2])
(void) strncpy(g.plname, argv[0] + 2, sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0] + 2, sizeof(gp.plname) - 1);
else if (argc > 1) {
argc--;
argv++;
(void) strncpy(g.plname, argv[0], sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0], sizeof(gp.plname) - 1);
} else
raw_print("Player name expected after -u");
break;
@@ -236,15 +236,15 @@ getlock(void)
{
int fd;
Sprintf(g.lock, "%d%s", getuid(), g.plname);
regularize(g.lock);
set_levelfile_name(g.lock, 0);
fd = creat(g.lock, FCMASK);
Sprintf(gl.lock, "%d%s", getuid(), gp.plname);
regularize(gl.lock);
set_levelfile_name(gl.lock, 0);
fd = creat(gl.lock, FCMASK);
if (fd == -1) {
error("cannot creat lock file.");
} else {
if (write(fd, (genericptr_t) &g.hackpid, sizeof(g.hackpid))
!= sizeof(g.hackpid)) {
if (write(fd, (genericptr_t) &gh.hackpid, sizeof(gh.hackpid))
!= sizeof(gh.hackpid)) {
error("cannot write lock");
}
if (close(fd) == -1) {

View File

@@ -228,7 +228,7 @@ macopen(const char *name, int flags, long fileType)
Handle name;
Str255 plnamep;
C2P(g.plname, plnamep);
C2P(gp.plname, plnamep);
name = (Handle)NewString(plnamep);
if (name)
replace_resource(name, 'STR ', PLAYER_NAME_RES_ID,

View File

@@ -43,12 +43,12 @@ main(void)
windowprocs = mac_procs;
InitMac();
g.hname = "Mac Hack";
gh.hname = "Mac Hack";
hackpid = getpid();
setrandom();
initoptions();
init_nhwindows(&argc, (char **) &g.hname);
init_nhwindows(&argc, (char **) &gh.hname);
/*
* It seems you really want to play.
@@ -102,7 +102,7 @@ attempt_restore:
if (yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile();
else {
nh_compress(fqname(g.SAVEF, SAVEPREFIX, 0));
nh_compress(fqname(gs.SAVEF, SAVEPREFIX, 0));
}
}
}
@@ -225,9 +225,9 @@ process_openfile(short src_vol, long src_dir, Str255 fName, OSType ftype)
Handle name = Get1Resource('STR ', PLAYER_NAME_RES_ID);
if (name) {
Str255 save_f_p;
P2C(*(StringHandle) name, g.plname);
P2C(*(StringHandle) name, gp.plname);
set_savefile_name(TRUE);
C2P(fqname(g.SAVEF, SAVEPREFIX, 0), save_f_p);
C2P(fqname(gs.SAVEF, SAVEPREFIX, 0), save_f_p);
force_hdelete(theDirs.dataRefNum, theDirs.dataDirID,
save_f_p);

View File

@@ -493,8 +493,8 @@ mac_askname()
SetPortDialogPort(askdialog);
/* Initialize the name text item */
ask_restring(g.plname, str);
if (g.plname[0]) {
ask_restring(gp.plname, str);
if (gp.plname[0]) {
GetDialogItem(askdialog, RSRC_ASK_NAME, &type, &handle, &rect);
SetDialogItemText(handle, str);
}
@@ -502,8 +502,8 @@ mac_askname()
{
Str32 pName;
pName [0] = 0;
if (g.plname && g.plname [0]) {
strcpy ((char *) pName, g.plname);
if (gp.plname && gp.plname [0]) {
strcpy ((char *) pName, gp.plname);
c2pstr ((char *) pName);
} else {
Handle h;
@@ -548,7 +548,7 @@ mac_askname()
if (flags.initrole >= 0)
currrole = flags.initrole;
/* Check for backward compatibility */
else if ((currrole = str2role(g.pl_character)) < 0)
else if ((currrole = str2role(gp.pl_character)) < 0)
currrole = randrole(FALSE);
/* Initialize the race popup menu */
@@ -735,8 +735,8 @@ mac_askname()
GetDialogItemText(handle, str);
if (str[0] > PL_NSIZ - 1)
str[0] = PL_NSIZ - 1;
BlockMove(&str[1], g.plname, str[0]);
g.plname[str[0]] = '\0';
BlockMove(&str[1], gp.plname, str[0]);
gp.plname[str[0]] = '\0';
/* Destroy the dialog */
for (i = RSRC_ASK_ROLE; i <= RSRC_ASK_MODE; i++) {
@@ -758,14 +758,14 @@ mac_askname()
break;
case 2: /* Debug */
wizard = 1;
strcpy(g.plname, WIZARD_NAME);
strcpy(gp.plname, WIZARD_NAME);
break;
default: /* Quit */
ExitToShell();
}
/* Process the role */
strcpy(g.pl_character, roles[currrole].name.m);
strcpy(gp.pl_character, roles[currrole].name.m);
flags.initrole = currrole;
/* Process the race */

View File

@@ -24,16 +24,16 @@ getlock(void)
int fd;
int pid = getpid(); /* Process ID */
Sprintf(g.lock, "%d%s", getuid(), g.plname);
set_levelfile_name(g.lock, 0);
Sprintf(gl.lock, "%d%s", getuid(), gp.plname);
set_levelfile_name(gl.lock, 0);
if ((fd = open(g.lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) {
raw_printf("Could not lock the game %s.", g.lock);
if ((fd = open(gl.lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) {
raw_printf("Could not lock the game %s.", gl.lock);
panic("Another game in progress?");
}
if (write(fd, (char *) &pid, sizeof(pid)) != sizeof(pid)) {
raw_printf("Could not lock the game %s.", g.lock);
raw_printf("Could not lock the game %s.", gl.lock);
panic("Disk locked?");
}
close(fd);

View File

@@ -581,10 +581,10 @@ SanePositions(void)
rmsg.top = rbase.bottom + 2;
rmsg.bottom = rmsg.top + height;
rmsg.left = rbase.left;
rmsg.right = rbase.right;
rmsgr.right = rbase.right;
RetrievePosition(kMessageWindow, &rmsg.top, &rmsg.left);
if (RetrieveSize(kMessageWindow, rmsg.top, rmsg.left, &height, &width)) {
rmsg.right = rmsg.left + width;
rmsgr.right = rmsg.left + width;
rmsg.bottom = rmsg.top + height;
}
SetWindowBounds(theWindows[NHW_MESSAGE].its_window, kWindowContentRgn,

View File

@@ -1,43 +0,0 @@
/* NetHack 3.7 nhlan.c $NHDT-Date: 1596498282 2020/08/03 23:44:42 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.11 $ */
/* Copyright (c) Michael Allison, 1997 */
/* NetHack may be freely redistributed. See license for details. */
/*
* Currently shared by the following ports:
* WIN32
*
* The code in here is used to take advantage of added features
* that might be available in a Local Area Network environment.
*
* Network Username of player
*/
#include "hack.h"
#include <ctype.h>
#ifdef LAN_FEATURES
void
init_lan_features(void)
{
lan_username();
}
/*
* The get_lan_username() call is a required call, since some of
* the other LAN features depend on a unique username being available.
*
*/
char *
lan_username(void)
{
char *lu;
lu = get_username(&g.lusername_size);
if (lu) {
Strcpy(g.lusername, lu);
return g.lusername;
} else
return (char *) 0;
}
#endif /*LAN_FEATURES*/
/*nhlan.c*/

View File

@@ -459,7 +459,7 @@ plselInitDialog(HWND hWnd)
TCHAR wbuf[BUFSZ];
/* set player name */
SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(g.plname, wbuf, sizeof(wbuf)));
SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(gp.plname, wbuf, sizeof(wbuf)));
/* check flags for consistency */
if (flags.initrole >= 0) {

View File

@@ -39,7 +39,7 @@ mswin_have_input()
return
#ifdef SAFERHANGUP
/* we always have input (ESC) if hangup was requested */
g.program_state.done_hup ||
gp.program_state.done_hup ||
#endif
(nhi_read_pos != nhi_write_pos);
}
@@ -69,7 +69,7 @@ mswin_input_pop()
#ifdef SAFERHANGUP
/* always return ESC when hangup was requested */
if (g.program_state.done_hup) {
if (gp.program_state.done_hup) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
@@ -98,7 +98,7 @@ mswin_input_peek()
#ifdef SAFERHANGUP
/* always return ESC when hangup was requested */
if (g.program_state.done_hup) {
if (gp.program_state.done_hup) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';

View File

@@ -826,7 +826,7 @@ mswin_layout_main_window(HWND changed_child)
/* show command window only if it exists and
the game is ready (plname is set) */
if (GetNHApp()->bCmdPad && cmd_size.cx > 0 && cmd_size.cy > 0
&& *g.plname) {
&& *gp.plname) {
MoveWindow(GetNHApp()->hCmdWnd, cmd_org.x, cmd_org.y, cmd_size.cx,
cmd_size.cy, TRUE);
ShowWindow(GetNHApp()->hCmdWnd, SW_SHOW);

View File

@@ -533,7 +533,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
if (!data->text.text) {
data->text.text = mswin_init_text_buffer(
g.program_state.gameover ? FALSE : GetNHApp()->bWrapText);
gp.program_state.gameover ? FALSE : GetNHApp()->bWrapText);
if (!data->text.text)
break;
}

View File

@@ -182,7 +182,7 @@ FormatStatusString(char *text, int format)
int hp, hpmax;
int cap = near_capacity();
Strcpy(text, g.plname);
Strcpy(text, gp.plname);
if ('a' <= text[0] && text[0] <= 'z')
text[0] += 'A' - 'a';
text[10] = 0;
@@ -237,7 +237,7 @@ FormatStatusString(char *text, int format)
hp = 0;
(void) describe_level(nb = eos(nb));
Sprintf(nb = eos(nb), "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d",
showsyms[COIN_CLASS + SYM_OFF_O], money_cnt(g.invent), hp, hpmax,
showsyms[COIN_CLASS + SYM_OFF_O], money_cnt(gi.invent), hp, hpmax,
u.uen, u.uenmax, u.uac);
if (Upolyd)
@@ -253,7 +253,7 @@ FormatStatusString(char *text, int format)
/* forth line */
if (flags.time)
Sprintf(nb = eos(nb), "T:%ld ", g.moves);
Sprintf(nb = eos(nb), "T:%ld ", gm.moves);
if (strcmp(hu_stat[u.uhs], " ")) {
Strcat(text, hu_stat[u.uhs]);

View File

@@ -39,7 +39,7 @@ mswin_init_text_window()
ZeroMemory(data, sizeof(NHTextWindow));
data->window_text = mswin_init_text_buffer(
g.program_state.gameover ? FALSE : GetNHApp()->bWrapText);
gp.program_state.gameover ? FALSE : GetNHApp()->bWrapText);
SetWindowLong(ret, GWL_USERDATA, (LONG) data);
return ret;
}

View File

@@ -646,7 +646,7 @@ mswin_askname(void)
{
logDebug("mswin_askname()\n");
if (mswin_getlin_window("who are you?", g.plname, PL_NSIZ) == IDCANCEL) {
if (mswin_getlin_window("who are you?", gp.plname, PL_NSIZ) == IDCANCEL) {
bail("bye-bye");
/* not reached */
}
@@ -1927,7 +1927,7 @@ NHSPhoneDialogSetup(HWND hDlg, UINT nToolBarId, BOOL is_edit,
rtDlg.bottom -= rtOK.bottom - rtOK.top;
ShowWindow(hOK, SW_HIDE);
SetWindowPos(hDlg, HWND_TOP, 0, 0, rtDlg.right - rtDlg.left,
SetWindowPos(hDlg, HWND_TOP, 0, 0, rtDlgr.right - rtDlg.left,
rtDlg.bottom - rtDlg.top,
SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER);
}

View File

@@ -167,11 +167,11 @@ eraseoldlocks()
*/
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(g.lock, i);
(void) unlink(fqname(g.lock, LEVELPREFIX, 0));
set_levelfile_name(gl.lock, i);
(void) unlink(fqname(gl.lock, LEVELPREFIX, 0));
}
set_levelfile_name(g.lock, 0);
if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
set_levelfile_name(gl.lock, 0);
if (unlink(fqname(gl.lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return (1); /* success! */
}
@@ -187,9 +187,9 @@ getlock()
int choice;
/* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf, "%s", fqname(g.lock, LEVELPREFIX, 0));
set_levelfile_name(g.lock, 0);
fq_lock = fqname(g.lock, LEVELPREFIX, 1);
Sprintf(tbuf, "%s", fqname(gl.lock, LEVELPREFIX, 0));
set_levelfile_name(gl.lock, 0);
fq_lock = fqname(gl.lock, LEVELPREFIX, 1);
f = CreateFile(NH_A2W(fq_lock, wbuf, BUFSZ), GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
@@ -226,8 +226,8 @@ gotlock:
if (fd == -1) {
error("cannot creat lock file (%s.)", fq_lock);
} else {
if (write(fd, (char *) &g.hackpid, sizeof(g.hackpid))
!= sizeof(g.hackpid)) {
if (write(fd, (char *) &gh.hackpid, sizeof(gh.hackpid))
!= sizeof(gh.hackpid)) {
error("cannot write lock (%s)", fq_lock);
}
if (close(fd) == -1) {