diff arogue5/main.c @ 64:a98834ce7e04

arogue5: add the savedir feature.
author elwin
date Fri, 10 Aug 2012 05:16:08 +0000
parents 0ed67132cf10
children c56f672244f4
line wrap: on
line diff
--- a/arogue5/main.c	Thu Aug 09 22:58:48 2012 +0000
+++ b/arogue5/main.c	Fri Aug 10 05:16:08 2012 +0000
@@ -57,10 +57,29 @@
 
     strncpy(home,md_gethomedir(),LINELEN);
 
+#ifdef SAVEDIR
+    if (argc >= 3 && !strcmp(argv[1], "-n")) {
+        use_savedir = TRUE;
+        strncpy(whoami, argv[2], LINELEN);
+        whoami[LINELEN - 1] = '\0';
+        if (snprintf(file_name, LINELEN, "%s%d-%.10s.ar5sav", SAVEDIR, 
+                     md_getuid(), whoami) >= LINELEN)
+        {
+            /* The name is too long */
+            use_savedir = FALSE;
+        }
+    }
+#endif
     /* Get default save file */
-    strcpy(file_name, home);
-    strcat(file_name, "arogue58.sav");
+    if (!use_savedir) {
+        strcpy(file_name, home);
+        strcat(file_name, "arogue58.sav");
+    }
 
+#ifdef SCOREFILE
+    strncpy(score_file, SCOREFILE, LINELEN);
+    score_file[LINELEN - 1] = '\0';
+#else
     /* Get default score file */
     strcpy(score_file, roguedir);
 
@@ -68,6 +87,7 @@
         strcat(score_file,"/");
 
     strcat(score_file, "arogue58.scr");
+#endif
 
     if ((env = getenv("ROGUEOPTS")) != NULL)
 	parse_opts(env);
@@ -139,7 +159,15 @@
 	exit(1);
     }
 #endif
-    if (argc == 2)
+    if (use_savedir)
+    {
+        /* Try to restore from file_name first. */
+        if (!restore(file_name, envp))
+            exit(1);
+        /* If restore() returns true, there is no such saved game.
+           So start a new one. */
+    }
+    else if (argc == 2)
 	if (!restore(argv[1], envp)) /* Note: restore will never return */
 	    exit(1);
     lowtime = (int) time(&now);