distinguish global variables that get written to savefile

The g? structs had a mix of variables that were written to
the savefile, and those that were not.

For better clarity and to distinguish those that end up in
the savefile, relocate some g? variables that get written
directly to the savefile into different structs.

This updates EDITLEVEL, although technically it probably
didn't need to, since savefile contents are not changing.

Details:

    gb.bases            -> svb.bases
    gb.bbubbles         -> svb.bbubbles
    gb.branches         -> svb.branches
    gc.context          -> svc.context
    gd.disco            -> svd.disco
    gd.dndest           -> svd.dndest
    gd.doors            -> svd.doors
    gd.doors_alloc      -> svd.doors_alloc
    gd.dungeon_topology -> svd.dungeon_topology
    gd.dungeons         -> svd.dungeons
    ge.exclusion_zones  -> sve.exclusion_zones
    gh.hackpid          -> svh.hackpid
    gi.inv_pos          -> svi.inv_pos
    gk.killer           -> svk.killer
    gl.lastseentyp      -> svl.lastseentyp
    gl.level            -> svl.level
    gl.level_info       -> svl.level_info
    gm.mapseenchn       -> svm.mapseenchn
    gm.moves            -> svm.moves
    gm.mvitals          -> svm.mvitals
    gn.n_dgns           -> svn.n_dgns
    gn.n_regions        -> svn.n_regions
    gn.nroom            -> svn.nroom
    go.oracle_cnt       -> svo.oracle_cnt
    gp.pl_character     -> svp.pl_character
    gp.pl_fruit         -> svp.pl_fruit
    gp.plname           -> svp.plname
    gp.program_state    -> svp.program_state
    gq.quest_status     -> svq.quest_status
    gr.rooms            -> svr.rooms
    gs.sp_levchn        -> svs.sp_levchn
    gs.spl_book         -> svs.spl_book
    gt.timer_id         -> svt.timer_id
    gt.tune             -> svt.tune
    gu.updest           -> svu.updest
    gx.xmax             -> svx.xmax
    gx.xmin             -> svx.xmin
    gy.ymax             -> svy.ymax
    gy.ymin             -> svy.ymin

Related note:
There are some pointer variables that are heads of chains that were not
moved from 'g?' to 'sv?', because they are not actually written to the
savefile directly, but the objects/monst/trap/lightsource/timer in the
chains they point to are. That can be changed, if desired.
Examples: gi.invent, gm.migrating_objs, gb.billobjs, gm.migrating_mons,
          gf.ftrap, gl.light_base, gt.timer_base
This commit is contained in:
nhmall
2024-07-13 14:57:50 -04:00
parent 0e4083153c
commit 6c0ae092c6
174 changed files with 3502 additions and 3305 deletions

View File

@@ -632,7 +632,7 @@ create_levelfile(int lev, char errbuf[])
#endif /* MICRO || WIN32 */
if (nhfp->fd >= 0)
gl.level_info[lev].flags |= LFILE_EXISTS;
svl.level_info[lev].flags |= LFILE_EXISTS;
else if (errbuf) /* failure explanation */
Sprintf(errbuf,
"Cannot create file \"%s\" for level %d (errno %d).",
@@ -690,10 +690,10 @@ delete_levelfile(int lev)
* Level 0 might be created by port specific code that doesn't
* call create_levfile(), so always assume that it exists.
*/
if (lev == 0 || (gl.level_info[lev].flags & LFILE_EXISTS)) {
if (lev == 0 || (svl.level_info[lev].flags & LFILE_EXISTS)) {
set_levelfile_name(gl.lock, lev);
(void) unlink(fqname(gl.lock, LEVELPREFIX, 0));
gl.level_info[lev].flags &= ~LFILE_EXISTS;
svl.level_info[lev].flags &= ~LFILE_EXISTS;
}
}
@@ -703,7 +703,7 @@ clearlocks(void)
int x;
#ifdef HANGUPHANDLING
if (gp.program_state.preserve_locks)
if (svp.program_state.preserve_locks)
return;
#endif
#ifndef NO_SIGNAL
@@ -713,7 +713,7 @@ clearlocks(void)
#endif
#endif /* NO_SIGNAL */
/* can't access maxledgerno() before dungeons are created -dlc */
for (x = (gn.n_dgns ? maxledgerno() : 0); x >= 0; x--)
for (x = (svn.n_dgns ? maxledgerno() : 0); x >= 0; x--)
delete_levelfile(x); /* not all levels need be present */
}
@@ -782,7 +782,7 @@ set_bonesfile_name(char *file, d_level *lev)
dptr = eos(file);
/* when this naming scheme was adopted, 'filecode' was one letter;
3.3.0 turned it into a three letter string for quest levels */
Sprintf(dptr, "%c%s", gd.dungeons[lev->dnum].boneid,
Sprintf(dptr, "%c%s", svd.dungeons[lev->dnum].boneid,
In_quest(lev) ? gu.urole.filecode : "0");
if ((sptr = Is_special(lev)) != 0)
Sprintf(eos(dptr), ".%c", sptr->boneid);
@@ -944,7 +944,7 @@ compress_bonesfile(void)
/* ---------- BEGIN SAVE FILE HANDLING ----------- */
/* set savefile name in OS-dependent manner from pre-existing gp.plname,
/* set savefile name in OS-dependent manner from pre-existing svp.plname,
* avoiding troublesome characters */
void
set_savefile_name(boolean regularize_it)
@@ -958,7 +958,7 @@ set_savefile_name(boolean regularize_it)
#endif
#ifdef VMS
Sprintf(gs.SAVEF, "[.save]%d%s", getuid(), gp.plname);
Sprintf(gs.SAVEF, "[.save]%d%s", getuid(), svp.plname);
regoffset = 7;
indicator_spot = 1;
postappend = ";1";
@@ -970,9 +970,9 @@ set_savefile_name(boolean regularize_it)
const char *legal = okchars;
++legal; /* skip '*' wildcard character */
(void) fname_encode(legal, '%', gp.plname, tmp, sizeof tmp);
(void) fname_encode(legal, '%', svp.plname, tmp, sizeof tmp);
} else {
Sprintf(tmp, "%s", gp.plname);
Sprintf(tmp, "%s", svp.plname);
}
if (strlen(tmp) < (SAVESIZE - 1))
Strcpy(gs.SAVEF, tmp);
@@ -982,7 +982,7 @@ set_savefile_name(boolean regularize_it)
regularize_it = FALSE;
#endif
#ifdef UNIX
Sprintf(gs.SAVEF, "save/%d%s", (int) getuid(), gp.plname);
Sprintf(gs.SAVEF, "save/%d%s", (int) getuid(), svp.plname);
regoffset = 5;
indicator_spot = 2;
#endif
@@ -990,7 +990,7 @@ set_savefile_name(boolean regularize_it)
if (strlen(gs.SAVEP) < (SAVESIZE - 1))
Strcpy(gs.SAVEF, gs.SAVEP);
if (strlen(gs.SAVEF) < (SAVESIZE - 1))
(void) strncat(gs.SAVEF, gp.plname, (SAVESIZE - strlen(gs.SAVEF)));
(void) strncat(gs.SAVEF, svp.plname, (SAVESIZE - strlen(gs.SAVEF)));
#endif
#if defined(MICRO) && !defined(VMS) && !defined(WIN32) && !defined(MSDOS)
if (strlen(gs.SAVEP) < (SAVESIZE - 1))
@@ -1003,11 +1003,11 @@ set_savefile_name(boolean regularize_it)
{
int i = strlen(gs.SAVEP);
#ifdef AMIGA
/* gp.plname has to share space with gs.SAVEP and ".sav" */
(void) strncat(gs.SAVEF, gp.plname,
/* svp.plname has to share space with gs.SAVEP and ".sav" */
(void) strncat(gs.SAVEF, svp.plname,
FILENAME - i - strlen(SAVE_EXTENSION));
#else
(void) strncat(gs.SAVEF, gp.plname, 8);
(void) strncat(gs.SAVEF, svp.plname, 8);
#endif
regoffset = i;
}
@@ -1101,7 +1101,7 @@ create_savefile(void)
nhfp->fieldlevel = FALSE;
nhfp->ftype = NHF_SAVEFILE;
nhfp->mode = WRITING;
if (gp.program_state.in_self_recover || do_historical) {
if (svp.program_state.in_self_recover || do_historical) {
do_historical = TRUE; /* force it */
nhfp->structlevel = TRUE;
nhfp->fieldlevel = FALSE;
@@ -1155,7 +1155,7 @@ open_savefile(void)
nhfp->fieldlevel = FALSE;
nhfp->ftype = NHF_SAVEFILE;
nhfp->mode = READING;
if (gp.program_state.in_self_recover || do_historical) {
if (svp.program_state.in_self_recover || do_historical) {
do_historical = TRUE; /* force it */
nhfp->structlevel = TRUE;
nhfp->fieldlevel = FALSE;
@@ -1337,7 +1337,7 @@ get_saved_games(void)
char **files = 0;
int i, count_failures = 0;
Strcpy(gp.plname, "*");
Strcpy(svp.plname, "*");
set_savefile_name(FALSE);
#if defined(ZLIB_COMP)
Strcat(gs.SAVEF, COMPRESS_EXTENSION);
@@ -1372,7 +1372,7 @@ get_saved_games(void)
if (r) {
/* rename file if it is not named as expected */
Strcpy(gp.plname, r);
Strcpy(svp.plname, r);
set_savefile_name(TRUE);
fq_new_save = fqname(gs.SAVEF, SAVEPREFIX, 0);
fq_old_save = fqname(files[i], SAVEPREFIX, 1);
@@ -1434,7 +1434,7 @@ get_saved_games(void)
}
#endif
#ifdef VMS
Strcpy(gp.plname, "*");
Strcpy(svp.plname, "*");
set_savefile_name(FALSE);
j = vms_get_saved_games(gs.SAVEF, &result);
#endif /* VMS */
@@ -1875,7 +1875,7 @@ static struct flock sflock; /* for unlocking, same as above */
#endif
#if defined(HANGUPHANDLING)
#define HUP if (!gp.program_state.done_hup)
#define HUP if (!svp.program_state.done_hup)
#else
#define HUP
#endif
@@ -2728,7 +2728,7 @@ cnf_line_TROUBLEDIR(char *bufp)
staticfn boolean
cnf_line_NAME(char *bufp)
{
(void) strncpy(gp.plname, bufp, PL_NSIZ - 1);
(void) strncpy(svp.plname, bufp, PL_NSIZ - 1);
return TRUE;
}
@@ -3447,7 +3447,7 @@ config_error_init(boolean from_file, const char *sourcename, boolean secure)
tmp->next = config_error_data;
config_error_data = tmp;
gp.program_state.config_error_ready = TRUE;
svp.program_state.config_error_ready = TRUE;
}
staticfn boolean
@@ -3513,7 +3513,7 @@ config_erradd(const char *buf)
punct = c_eos((char *) buf) - 1; /* eos(buf)-1 is valid */
punct = strchr(".!?", *punct) ? "" : ".";
if (!gp.program_state.config_error_ready) {
if (!svp.program_state.config_error_ready) {
/* either very early, where pline() will use raw_print(), or
player gave bad value when prompted by interactive 'O' command */
pline("%s%s%s", !iflags.window_inited ? "config_error_add: " : "",
@@ -3575,7 +3575,7 @@ config_error_done(void)
}
config_error_data = tmp->next;
free(tmp);
gp.program_state.config_error_ready = (config_error_data != 0);
svp.program_state.config_error_ready = (config_error_data != 0);
return n;
}
@@ -3978,14 +3978,14 @@ read_wizkit(void)
if (!wizard || !(fp = fopen_wizkit_file()))
return;
gp.program_state.wizkit_wishing = 1;
svp.program_state.wizkit_wishing = 1;
config_error_init(TRUE, "WIZKIT", FALSE);
parse_conf_file(fp, proc_wizkit_line);
(void) fclose(fp);
config_error_done();
gp.program_state.wizkit_wishing = 0;
svp.program_state.wizkit_wishing = 0;
return;
}
@@ -4195,13 +4195,13 @@ paniclog(
#ifdef PANICLOG
FILE *lfile;
if (!gp.program_state.in_paniclog) {
gp.program_state.in_paniclog = 1;
if (!svp.program_state.in_paniclog) {
svp.program_state.in_paniclog = 1;
lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX);
if (lfile) {
#ifdef PANICLOG_FMT2
(void) fprintf(lfile, "%ld %s: %s %s\n",
ubirthday, (gp.plname[0] ? gp.plname : "(none)"),
ubirthday, (svp.plname[0] ? svp.plname : "(none)"),
type, reason);
#else
char buf[BUFSZ];
@@ -4216,7 +4216,7 @@ paniclog(
#endif /* !PANICLOG_FMT2 */
(void) fclose(lfile);
}
gp.program_state.in_paniclog = 0;
svp.program_state.in_paniclog = 0;
}
#endif /* PANICLOG */
return;
@@ -4323,9 +4323,9 @@ recover_savefile(void)
/*
* Set a flag for the savefile routines to know the
* circumstances and act accordingly:
* gp.program_state.in_self_recover
* svp.program_state.in_self_recover
*/
gp.program_state.in_self_recover = TRUE;
svp.program_state.in_self_recover = TRUE;
set_savefile_name(TRUE);
snhfp = create_savefile();
if (!snhfp) {
@@ -4433,11 +4433,11 @@ recover_savefile(void)
close_nhfile(gnhfp);
close_nhfile(snhfp);
close_nhfile(lnhfp);
gp.program_state.in_self_recover = FALSE;
svp.program_state.in_self_recover = FALSE;
delete_savefile();
return FALSE;
}
/* we don't clear gp.program_state.in_self_recover here, we
/* we don't clear svp.program_state.in_self_recover here, we
leave it as a flag to reload the structlevel savefile
in the caller. The caller should then clear it. */
return TRUE;
@@ -4789,7 +4789,7 @@ reveal_paths(void)
#define TITLESCOPE 2
#define PASSAGESCOPE 3
#define MAXPASSAGES SIZE(gc.context.novel.pasg) /* 20 */
#define MAXPASSAGES SIZE(svc.context.novel.pasg) /* 20 */
staticfn int choose_passage(int, unsigned);
@@ -4807,32 +4807,32 @@ choose_passage(int passagecnt, /* total of available passages */
/* if a different book or we've used up all the passages already,
reset in order to have all 'passagecnt' passages available */
if (oid != gc.context.novel.id || gc.context.novel.count == 0) {
if (oid != svc.context.novel.id || svc.context.novel.count == 0) {
int i, range = passagecnt, limit = MAXPASSAGES;
gc.context.novel.id = oid;
svc.context.novel.id = oid;
if (range <= limit) {
/* collect all of the N indices */
gc.context.novel.count = passagecnt;
svc.context.novel.count = passagecnt;
for (idx = 0; idx < MAXPASSAGES; idx++)
gc.context.novel.pasg[idx] = (xint16) ((idx < passagecnt)
svc.context.novel.pasg[idx] = (xint16) ((idx < passagecnt)
? idx + 1 : 0);
} else {
/* collect MAXPASSAGES of the N indices */
gc.context.novel.count = MAXPASSAGES;
svc.context.novel.count = MAXPASSAGES;
for (idx = i = 0; i < passagecnt; ++i, --range)
if (range > 0 && rn2(range) < limit) {
gc.context.novel.pasg[idx++] = (xint16) (i + 1);
svc.context.novel.pasg[idx++] = (xint16) (i + 1);
--limit;
}
}
}
idx = rn2(gc.context.novel.count);
res = (int) gc.context.novel.pasg[idx];
idx = rn2(svc.context.novel.count);
res = (int) svc.context.novel.pasg[idx];
/* move the last slot's passage index into the slot just used
and reduce the number of passages available */
gc.context.novel.pasg[idx] = gc.context.novel.pasg[--gc.context.novel.count];
svc.context.novel.pasg[idx] = svc.context.novel.pasg[--svc.context.novel.count];
return res;
}
@@ -5061,10 +5061,10 @@ livelog_add(long ll_type, const char *str)
"gender=%s" LLOG_SEP "align=%s" LLOG_SEP
"turns=%ld" LLOG_SEP "starttime=%ld" LLOG_SEP
"curtime=%ld" LLOG_SEP "message=%s" LLOG_EOL,
(ll_type & sysopt.livelog), gp.plname,
(ll_type & sysopt.livelog), svp.plname,
gu.urole.filecode, gu.urace.filecode,
genders[gindx].filecode, aligns[aindx].filecode,
gm.moves, timet_to_seconds(ubirthday),
svm.moves, timet_to_seconds(ubirthday),
timet_to_seconds(now), str);
(void) fclose(livelogfile);
unlock_file(LIVELOGFILE);