changeset 136:1fbdefa82533

xrogue: initial support for the -n option. The scorefile location is also configurable now.
author John "Elwin" Edwards
date Wed, 22 Apr 2015 16:03:00 -0400
parents ce0cf824c192
children 443c8bd3e290
files xrogue/main.c xrogue/rogue.c xrogue/rogue.h xrogue/save.c
diffstat 4 files changed, 39 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/xrogue/main.c	Tue Apr 21 10:34:01 2015 -0400
+++ b/xrogue/main.c	Wed Apr 22 16:03:00 2015 -0400
@@ -26,6 +26,9 @@
 #include "network.h"
 #include "rogue.h"
 
+#define SCOREFILE "xrogue.scr"
+#define SAVEDIR "."
+
 main(argc, argv, envp)
 char **argv;
 char **envp;
@@ -46,12 +49,33 @@
     strcat(file_name, "xrogue.sav");
 
     /* Get default score file */
+#ifdef SCOREFILE
+    strncpy(score_file, SCOREFILE, LINELEN);
+    score_file[LINELEN-1] = '\0';
+#else
     strcpy(score_file, md_getroguedir());
 
     if (*score_file)
         strcat(score_file,"/");
 
     strcat(score_file, "xrogue.scr");
+#endif
+
+#ifdef SAVEDIR
+    /* Check for common save location */
+    if (argc >= 3 && strcmp(argv[1], "-n") == 0)
+    {
+        strncpy(whoami, argv[2], 79);
+        whoami[79] = '\0';
+        use_savedir = TRUE;
+        if (LINELEN <= snprintf(file_name, LINELEN, "%s/%d-%s.xrsav", SAVEDIR, 
+                     md_getuid(), whoami))
+        {
+            strcpy(file_name, "xrogue.sav");
+            use_savedir = FALSE;
+        }
+    }
+#endif
 
     if ((env = getenv("ROGUEOPTS")) != NULL)
         parse_opts(env);
@@ -121,6 +145,12 @@
         exit_game(0);
     }
 
+    if (use_savedir)
+    {
+        /* restore() will return TRUE if a new game should be started. */
+        if (!restore(file_name, envp))
+            exit_game(0);
+    }
     if (argc == 2)
         if (!restore(argv[1], envp)) /* Note: restore will never return */
             exit_game(0);
--- a/xrogue/rogue.c	Tue Apr 21 10:34:01 2015 -0400
+++ b/xrogue/rogue.c	Wed Apr 22 16:03:00 2015 -0400
@@ -99,6 +99,7 @@
 bool pool_teleport = FALSE;             /* just teleported from a pool */
 bool inwhgt = FALSE;                    /* true if from wghtchk() */
 bool after;                             /* True if we want after daemons */
+bool use_savedir = FALSE;               /* Use common save location? */
 bool waswizard;                         /* Was a wizard sometime */
 bool s_know[MAXSCROLLS];                /* Does he know what a scroll does */
 bool p_know[MAXPOTIONS];                /* Does he know what a potion does */
--- a/xrogue/rogue.h	Tue Apr 21 10:34:01 2015 -0400
+++ b/xrogue/rogue.h	Wed Apr 22 16:03:00 2015 -0400
@@ -1381,6 +1381,7 @@
 extern bool firstmove;                  /* First move after setting door_stop */
 extern bool waswizard;                  /* Was a wizard sometime */
 extern bool askme;                      /* Ask about unidentified things */
+extern bool use_savedir;                /* Use common save location */
 extern bool s_know[];                   /* Does he know what a scroll does */
 extern bool p_know[];                   /* Does he know what a potion does */
 extern bool r_know[];                   /* Does he know what a ring does */
--- a/xrogue/save.c	Tue Apr 21 10:34:01 2015 -0400
+++ b/xrogue/save.c	Wed Apr 22 16:03:00 2015 -0400
@@ -151,8 +151,13 @@
 
     if ((inf = open(file, O_RDONLY)) < 0)
     {
+        if (use_savedir && errno == ENOENT)
+        {
+            /* No game in progress, so one will be started. */
+            return TRUE;
+        }
         perror(file);
-        return(-1);
+        return FALSE;
     }
 
     fflush(stdout);
@@ -222,7 +227,7 @@
     playit();
 
     /*NOTREACHED*/
-	return(1);
+	return FALSE;
 }
 
 #define ENCWBSIZ        1024