unix check_panic_save
Inspired by self-recover, sort of. Enabled for unix by default; can be disabled by commenting out '#define CHECK_PANIC_SAVE' in unixconf.h. When starting the game, if there is no save file to restore and no lock/level files to recover, check whether a panic save file exists. If there is one, tell the player that it's there and that it might be viable, then ask whether to start a new game. It doesn't convert the panic save into a reconverable one (rename by nethack, then continue trying to restore) or tell the player how to make it viable (rename to remove ".e" by game admin), just whether it is present. If player opts to start a new game, the panic save is left alone and will trigger the "there's a panic save file" situation again once the new game finishes and player starts another.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.7 unixmain.c $NHDT-Date: 1708737183 2024/02/24 01:13:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.126 $ */
|
||||
/* NetHack 3.7 unixmain.c $NHDT-Date: 1711213891 2024/03/23 17:11:31 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.127 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/*-Copyright (c) Robert Patrick Rankin, 2011. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -305,6 +305,16 @@ main(int argc, char *argv[])
|
||||
goto attempt_restore;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CHECK_PANIC_SAVE
|
||||
/* no save file; check for a panic save; if the check finds one,
|
||||
ask the player whether to proceed with a new game; it will
|
||||
quit instead of returning if the answer isn't yes */
|
||||
if (check_panic_save())
|
||||
ask_about_panic_save();
|
||||
#endif
|
||||
|
||||
/* no save file; start a new game */
|
||||
newgame();
|
||||
wd_message();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.7 unixunix.c $NHDT-Date: 1687124609 2023/06/18 21:43:29 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.39 $ */
|
||||
/* NetHack 3.7 unixunix.c $NHDT-Date: 1711213894 2024/03/23 17:11:34 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.43 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/*-Copyright (c) Kenneth Lorber, Kensington, Maryland, 2015. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -182,14 +182,17 @@ getlock(void)
|
||||
unlock_file(HLOCK);
|
||||
if (iflags.window_inited) {
|
||||
#ifdef SELF_RECOVER
|
||||
c = yn_function("Old game in progress. Destroy [y], Recover [r], or Cancel [n]?", "ynr", 'n', FALSE);
|
||||
c = yn_function(
|
||||
"Old game in progress. Destroy [y], Recover [r], or Cancel [n]?",
|
||||
"ynr", 'n', FALSE);
|
||||
#else
|
||||
/* this is a candidate for paranoid_confirmation */
|
||||
c = y_n(destroy_old_game_prompt);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef SELF_RECOVER
|
||||
(void) raw_printf("\nThere is already a game in progress under your name. Do what?\n");
|
||||
(void) raw_printf(
|
||||
"\nThere is already a game in progress under your name. Do what?\n");
|
||||
(void) raw_printf("\n y - Destroy old game");
|
||||
(void) raw_printf("\n r - Try to recover it");
|
||||
(void) raw_printf("\n n - Cancel");
|
||||
@@ -241,17 +244,54 @@ getlock(void)
|
||||
unlock_file(HLOCK);
|
||||
if (fd == -1) {
|
||||
error("cannot creat lock file (%s).", fq_lock);
|
||||
/*NOTREACHED*/
|
||||
} else {
|
||||
if (write(fd, (genericptr_t) &gh.hackpid, sizeof gh.hackpid)
|
||||
!= sizeof gh.hackpid) {
|
||||
error("cannot write lock (%s)", fq_lock);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
if (close(fd) == -1) {
|
||||
error("cannot close lock (%s)", fq_lock);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* caller couldn't find a regular save file but did find a panic one */
|
||||
void
|
||||
ask_about_panic_save(void)
|
||||
{
|
||||
#ifdef CHECK_PANIC_SAVE
|
||||
static const char Instead_prompt[] = "Start a new game instead?";
|
||||
int c = '\0';
|
||||
|
||||
pline("There is no regular save file but there is a panic one.");
|
||||
pline("It might be recoverable with demi-divine intervention.");
|
||||
if (iflags.window_inited) {
|
||||
c = yn_function(Instead_prompt, "yn\033q", 'n', FALSE);
|
||||
} else {
|
||||
raw_printf("%s [yn] (n) ", Instead_prompt);
|
||||
(void) fflush(stdout);
|
||||
do {
|
||||
c = getchar();
|
||||
if (c == EOF || c == '\033' || c == '\0')
|
||||
break;
|
||||
c = lowc(c);
|
||||
} while (!strchr("ynq\n", c));
|
||||
}
|
||||
if (c != 'y') {
|
||||
/* caller successfully called getlock() and made <levelfile>.0 */
|
||||
delete_levelfile(0);
|
||||
unlock_file(HLOCK); /* just in case, release 'perm' */
|
||||
if (iflags.window_inited)
|
||||
exit_nhwindows((char *) 0);
|
||||
nh_terminate(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
return; /* proceed with new game */
|
||||
}
|
||||
|
||||
/* normalize file name - we don't like .'s, /'s, spaces */
|
||||
void
|
||||
regularize(char *s)
|
||||
|
||||
Reference in New Issue
Block a user