hero_seq followup

Make sure g.hero_seq has a sane value during restore before moveloop()
has a chance to update it.

Have curses use g.hero_seq for messages delivered via putmsghistory().
This commit is contained in:
PatR
2021-12-26 14:40:03 -08:00
parent 9daefde0c4
commit f72ad04266
2 changed files with 34 additions and 9 deletions
+6 -2
View File
@@ -670,8 +670,12 @@ restgamestate(NHFILE* nhfp, unsigned int* stuckid, unsigned int* steedid)
restlevchn(nhfp); restlevchn(nhfp);
if (nhfp->structlevel) { if (nhfp->structlevel) {
mread(nhfp->fd, (genericptr_t) &g.moves, sizeof g.moves); mread(nhfp->fd, (genericptr_t) &g.moves, sizeof g.moves);
mread(nhfp->fd, (genericptr_t) &g.quest_status, sizeof (struct q_score)); /* hero_seq isn't saved and restored because it can be recalculated */
mread(nhfp->fd, (genericptr_t) g.spl_book, (MAXSPELL + 1) * sizeof (struct spell)); g.hero_seq = g.moves << 3; /* normally handled in moveloop() */
mread(nhfp->fd, (genericptr_t) &g.quest_status,
sizeof (struct q_score));
mread(nhfp->fd, (genericptr_t) g.spl_book,
(MAXSPELL + 1) * sizeof (struct spell));
} }
restore_artifacts(nhfp); restore_artifacts(nhfp);
restore_oracles(nhfp); restore_oracles(nhfp);
+28 -7
View File
@@ -371,6 +371,17 @@ curses_prev_mesg(void)
nhprev_mesg *mesg; nhprev_mesg *mesg;
menu_item *selected = NULL; menu_item *selected = NULL;
boolean do_lifo = (iflags.prevmsg_window != 'f'); boolean do_lifo = (iflags.prevmsg_window != 'f');
#ifdef DEBUG
static int showturn = 0; /* 1: show hero_seq value in separators */
/*
* Set DEBUGFILES=MesgTurn in environment or sysconf to decorate
* separator line between blocks of messages with the turn they
* were issued.
*/
if (!showturn)
showturn = (wizard && explicitdebug("MesgTurn")) ? 1 : -1;
#endif
wid = curses_get_wid(NHW_MENU); wid = curses_get_wid(NHW_MENU);
curses_create_nhmenu(wid, 0UL); curses_create_nhmenu(wid, 0UL);
@@ -379,9 +390,18 @@ curses_prev_mesg(void)
for (count = 0; count < num_messages; ++count) { for (count = 0; count < num_messages; ++count) {
mesg = get_msg_line(do_lifo, count); mesg = get_msg_line(do_lifo, count);
if (mesg->turn != turn) { if (mesg->turn != turn) {
if (count > 0) /* skip separator for first line */ if (count > 0) { /* skip separator for first line */
char sepbuf[50];
Strcpy(sepbuf, "---");
#ifdef DEBUG
if (showturn == 1)
Sprintf(sepbuf, "- %ld+%ld",
(mesg->turn >> 3), (mesg->turn & 7L));
#endif
curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0, curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0,
A_NORMAL, "---", MENU_ITEMFLAGS_NONE); A_NORMAL, sepbuf, MENU_ITEMFLAGS_NONE);
}
turn = mesg->turn; turn = mesg->turn;
} }
curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0, curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0,
@@ -895,12 +915,10 @@ curses_getmsghistory(boolean init)
void void
curses_putmsghistory(const char *msg, boolean restoring_msghist) curses_putmsghistory(const char *msg, boolean restoring_msghist)
{ {
/* FIXME: these should be moved to struct instance_globals g */
static boolean initd = FALSE; static boolean initd = FALSE;
static int stash_count; static int stash_count;
static nhprev_mesg *stash_head = 0; static nhprev_mesg *stash_head = 0;
#ifdef DUMPLOG
/* extern unsigned g.saved_pline_index; */ /* pline.c */
#endif
if (restoring_msghist && !initd) { if (restoring_msghist && !initd) {
/* hide any messages we've gathered since starting current session /* hide any messages we've gathered since starting current session
@@ -918,8 +936,11 @@ curses_putmsghistory(const char *msg, boolean restoring_msghist)
if (msg) { if (msg) {
mesg_add_line(msg); mesg_add_line(msg);
/* treat all saved and restored messages as turn #1 */ /* treat all saved and restored messages as turn #1;
last_mesg->turn = 1L; 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;
#ifdef DUMPLOG #ifdef DUMPLOG
dumplogmsg(last_mesg->str); dumplogmsg(last_mesg->str);
#endif #endif