diff --git a/src/restore.c b/src/restore.c index c45ab97ea..39dc2def9 100644 --- a/src/restore.c +++ b/src/restore.c @@ -517,8 +517,10 @@ restgamestate(fd, stuckid, steedid) register int fd; unsigned int *stuckid, *steedid; /* STEED */ { - /* discover is actually flags.explore */ - boolean remember_discover = discover; + struct flag newgameflags; +#ifdef SYSFLAGS + struct sysflag newgamesysflags; +#endif struct obj *otmp, *tmp_bc; int uid; @@ -536,9 +538,24 @@ unsigned int *stuckid, *steedid; /* STEED */ if (context.warntype.speciesidx) context.warntype.species = &mons[context.warntype.speciesidx]; + /* we want to be able to revert to command line/environment/config + file option values instead of keeping old save file option values + if partial restore fails and we resort to starting a new game */ + newgameflags = flags; mread(fd, (genericptr_t) &flags, sizeof(struct flag)); - if (remember_discover) discover = remember_discover; + /* wizard and discover are actually flags.debug and flags.explore; + player might be overriding the save file values for them */ + if (newgameflags.explore) discover = TRUE; + if (newgameflags.debug) wizard = TRUE; + if (wizard) { +#ifdef WIZARD + discover = FALSE; +#else + discover = TRUE, wizard = FALSE; +#endif + } #ifdef SYSFLAGS + newgamesysflags = sysflags; mread(fd, (genericptr_t) &sysflags, sizeof(struct sysflag)); #endif @@ -560,6 +577,11 @@ unsigned int *stuckid, *steedid; /* STEED */ wiz1_level.dlevel = 0; u.uz.dnum = 0; u.uz.dlevel = 1; + /* revert to pre-restore option settings */ + flags = newgameflags; +#ifdef SYSFLAGS + sysflags = newgamesysflags; +#endif return(FALSE); } /* in case hangup save occurred in midst of level change */ diff --git a/sys/be/bemain.c b/sys/be/bemain.c index 5e9746574..bae1c1e3c 100644 --- a/sys/be/bemain.c +++ b/sys/be/bemain.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)bemain.c 3.5 2006/04/01 */ +/* SCCS Id: @(#)bemain.c 3.5 2007/02/15 */ /* Copyright (c) Dean Luick, 1996. */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,6 +11,8 @@ static void process_options(int argc, char **argv); static void chdirx(const char *dir); static void getlock(void); +static void NDECL(set_playmode); + #ifdef __begui__ #define MAIN nhmain int nhmain(int argc, char **argv); @@ -41,12 +43,7 @@ int MAIN(int argc, char **argv) u.uhp = 1; /* prevent RIP on early quits */ process_options(argc, argv); /* command line options */ - -#ifdef WIZARD - if (wizard) - Strcpy(plname, "wizard"); - else -#endif + set_playmode(); /* sets plname to "wizard" for wizard mode */ if(!*plname || !strncmp(plname, "player", 4) || !strncmp(plname, "games", 4)) askname(); @@ -57,7 +54,6 @@ int MAIN(int argc, char **argv) Sprintf(lock,"%d%s", getuid(), plname); getlock(); - dlb_init(); /* must be before newgame() */ /* @@ -80,12 +76,6 @@ int MAIN(int argc, char **argv) display_gamewindows(); if ((fd = restore_saved_game()) >= 0) { -#ifdef WIZARD - /* Since wizard is actually flags.debug, restoring might - * overwrite it. - */ - boolean remember_wiz_mode = wizard; -#endif #ifdef NEWS if(iflags.news) { display_file(NEWS, FALSE); @@ -96,12 +86,8 @@ int MAIN(int argc, char **argv) mark_synch(); /* flush output */ if (dorecover(fd)) { resuming = TRUE; /* not starting new game */ -#ifdef WIZARD - if (!wizard && remember_wiz_mode) wizard = TRUE; -#endif if (discover) You("are in non-scoring discovery mode."); - if (discover || wizard) { if(yn("Do you want to keep the save file?") == 'n') (void) delete_savefile(); @@ -165,12 +151,12 @@ static void process_options(int argc, char **argv) switch (argv[0][1]) { case 'D': #ifdef WIZARD - wizard = TRUE; + wizard = TRUE, discover = FALSE; break; #endif /* otherwise fall thru to discover */ case 'X': - discover = TRUE; + discover = TRUE, wizard = FALSE; break; #ifdef NEWS case 'n': @@ -251,6 +237,29 @@ void getlock(void) } } +/* validate wizard mode if player has requested access to it */ +static void +set_playmode() +{ + if (wizard) { +#ifdef WIZARD + /* other ports validate user name or character name here */ +#else + wizard = FALSE; +#endif + + if (!wizard) { + discover = TRUE; +#ifdef WIZARD + } else { + discover = FALSE; /* paranoia */ + Strcpy(plname, "wizard"); +#endif + } + } + /* don't need to do anything special for explore mode or normal play */ +} + #ifndef __begui__ /* * If we are not using the Be GUI, then just exit -- we don't need to @@ -262,3 +271,5 @@ void nethack_exit(int status) exit(status); } #endif /* !__begui__ */ + +/*bemain.c*/ diff --git a/sys/mac/macmain.c b/sys/mac/macmain.c index b3eca162b..051118d73 100644 --- a/sys/mac/macmain.c +++ b/sys/mac/macmain.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)macmain.c 3.5 2006/04/01 */ +/* SCCS Id: @(#)macmain.c 3.5 2007/02/15 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -24,6 +24,8 @@ #include #endif +static void NDECL(set_playmode); + static void finder_file_request(void); int main(void); @@ -78,12 +80,9 @@ main (void) display_gamewindows(); -#ifdef WIZARD - if (wizard) - Strcpy(plname, "wizard"); - else -#endif - if(!*plname || !strncmp(plname, "player", 4) || !strncmp(plname, "games", 4)) + set_playmode(); /* sets plname to "wizard" for wizard mode */ + if (!*plname || !strncmp(plname, "player", 4) || + !strncmp(plname, "games", 4)) askname(); plnamesuffix(); /* strip suffix from name; calls askname() */ /* again if suffix was whole name */ @@ -93,12 +92,6 @@ main (void) getlock (); if ((fd = restore_saved_game()) >= 0) { -#ifdef WIZARD - /* Since wizard is actually flags.debug, restoring might - * overwrite it. - */ - boolean remember_wiz_mode = wizard; -#endif #ifdef NEWS if(iflags.news) { display_file(NEWS, FALSE); @@ -110,9 +103,6 @@ main (void) game_active = 1; if (dorecover(fd)) { resuming = TRUE; /* not starting new game */ -#ifdef WIZARD - if(!wizard && remember_wiz_mode) wizard = TRUE; -#endif if (discover || wizard) { if(yn("Do you want to keep the save file?") == 'n') (void) delete_savefile(); @@ -280,4 +270,27 @@ finder_file_request(void) #endif /* 0 */ } +/* validate wizard mode if player has requested access to it */ +static void +set_playmode() +{ + if (wizard) { +#ifdef WIZARD + /* other ports validate user name or character name here */ +#else + wizard = FALSE; +#endif + + if (!wizard) { + discover = TRUE; +#ifdef WIZARD + } else { + discover = FALSE; /* paranoia */ + Strcpy(plname, "wizard"); +#endif + } + } + /* don't need to do anything special for explore mode or normal play */ +} + /*macmain.c*/ diff --git a/sys/share/pcmain.c b/sys/share/pcmain.c index 4f1f9537f..d970dab48 100644 --- a/sys/share/pcmain.c +++ b/sys/share/pcmain.c @@ -429,12 +429,6 @@ char *argv[]; #endif if ((fd = restore_saved_game()) >= 0) { -#ifdef WIZARD - /* Since wizard is actually flags.debug, restoring might - * overwrite it. - */ - boolean remember_wiz_mode = wizard; -#endif #ifndef NO_SIGNAL (void) signal(SIGINT, (SIG_RET_TYPE) done1); #endif @@ -449,12 +443,8 @@ char *argv[]; if (dorecover(fd)) { resuming = TRUE; /* not starting new game */ -#ifdef WIZARD - if (!wizard && remember_wiz_mode) wizard = TRUE; -#endif if (discover) You("are in non-scoring discovery mode."); - if (discover || wizard) { if(yn("Do you want to keep the save file?") == 'n') (void) delete_savefile(); diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index c94921a68..2ab066e39 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -234,12 +234,6 @@ char *argv[]; display_gamewindows(); if ((fd = restore_saved_game()) >= 0) { -#ifdef WIZARD - /* Since wizard is actually flags.debug, restoring might - * overwrite it. - */ - boolean remember_wiz_mode = wizard; -#endif const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1); (void) chmod(fq_save,0); /* disallow parallel restores */ @@ -254,9 +248,6 @@ char *argv[]; mark_synch(); /* flush output */ if (dorecover(fd)) { resuming = TRUE; /* not starting new game */ -#ifdef WIZARD - if (!wizard && remember_wiz_mode) wizard = TRUE; -#endif wd_message(); if (discover || wizard) { if(yn("Do you want to keep the save file?") == 'n') diff --git a/sys/vms/vmsmain.c b/sys/vms/vmsmain.c index 0c1f3f067..9af7b859f 100644 --- a/sys/vms/vmsmain.c +++ b/sys/vms/vmsmain.c @@ -174,12 +174,6 @@ char *argv[]; display_gamewindows(); if ((fd = restore_saved_game()) >= 0) { -#ifdef WIZARD - /* Since wizard is actually flags.debug, restoring might - * overwrite it. - */ - boolean remember_wiz_mode = wizard; -#endif const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1); (void) chmod(fq_save,0); /* disallow parallel restores */ @@ -194,9 +188,6 @@ char *argv[]; mark_synch(); /* flush output */ if (dorecover(fd)) { resuming = TRUE; /* not starting new game */ -#ifdef WIZARD - if (!wizard && remember_wiz_mode) wizard = TRUE; -#endif wd_message(); if (discover || wizard) { if (yn("Do you want to keep the save file?") == 'n')