]> granicus.if.org Git - nethack/commitdiff
more wizard/explore mode control (trunk only)
authornethack.rankin <nethack.rankin>
Fri, 16 Feb 2007 02:35:30 +0000 (02:35 +0000)
committernethack.rankin <nethack.rankin>
Fri, 16 Feb 2007 02:35:30 +0000 (02:35 +0000)
     Wizard mode or explore mode can be forced on (via -D or -X on the
command line, or now via OPTIONS=playmode:debug|explore) when restoring
a saved game; explore mode handling was confined to restgamestate(), but
wizard mode handling was replicated in every main().  Treat `wizard' the
same as `discover'.  Also, prevent a new game started when restore fails
from using the old game's option settings if partial restore attempt got
far enough to load the flags struct.  And update bemain.c and macmain.c
to catch up with the others modified by the playmode patch.

src/restore.c
sys/be/bemain.c
sys/mac/macmain.c
sys/share/pcmain.c
sys/unix/unixmain.c
sys/vms/vmsmain.c

index c45ab97ea502f7ad71efaed5a5b28e225baf8e04..39dc2def9ce806096c76991efba661cc45de1a31 100644 (file)
@@ -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 */
index 5e974657446d67de1e7f524a49cac432b145845e..bae1c1e3c30d73cc4e85c2a6ccbb22354e67b664 100644 (file)
@@ -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*/
index b3eca162b815594edd9cab55a8418d62cd399d4b..051118d73a8543b226c4c19c9f5d9f777870f696 100644 (file)
@@ -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 <fcntl.h>
 #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*/
index 4f1f9537fa45c8dee7f9ee0244fc2ba01519aa71..d970dab487c4da5ae5cb2896135d8a583deadec4 100644 (file)
@@ -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();
index c94921a6817261105731901bf822e91c88c97ce7..2ab066e3964b445e61c3c89fe3d962c0abd7f0b1 100644 (file)
@@ -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')
index 0c1f3f067f084488801c916ff892db50071b3a39..9af7b859fdf3f64b9e26a965a5bf2b87e1658751 100644 (file)
@@ -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')