diff --git a/xrogue/main.c b/xrogue/main.c index ecd8eb8..a404f05 100644 --- a/xrogue/main.c +++ b/xrogue/main.c @@ -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 @@ char **envp; 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 @@ char **envp; 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); diff --git a/xrogue/rogue.c b/xrogue/rogue.c index 41d8339..6667230 100644 --- a/xrogue/rogue.c +++ b/xrogue/rogue.c @@ -99,6 +99,7 @@ WINDOW *msgw; /* Used to display messages */ 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 */ diff --git a/xrogue/rogue.h b/xrogue/rogue.h index eabfa61..6881795 100644 --- a/xrogue/rogue.h +++ b/xrogue/rogue.h @@ -1381,6 +1381,7 @@ extern bool def_attr; /* True for default attributes */ 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 */ diff --git a/xrogue/save.c b/xrogue/save.c index dcfdee6..3e69434 100644 --- a/xrogue/save.c +++ b/xrogue/save.c @@ -151,8 +151,13 @@ char **envp; 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 @@ char **envp; playit(); /*NOTREACHED*/ - return(1); + return FALSE; } #define ENCWBSIZ 1024