srogue: add support for SAVEDIR
This commit is contained in:
parent
ce4b930551
commit
20d469d64f
5 changed files with 91 additions and 22 deletions
|
|
@ -37,6 +37,9 @@
|
|||
|
||||
#include "rogue.ext"
|
||||
|
||||
#define SCOREFILE "/usr/local/games/roguelike/srogue.scr"
|
||||
#define SAVEDIR "/usr/local/games/roguelike/sroguesave/"
|
||||
|
||||
struct termios terminal;
|
||||
|
||||
main(argc, argv, envp)
|
||||
|
|
@ -71,12 +74,17 @@ char **envp;
|
|||
playgid = getgid();
|
||||
|
||||
/* check for print-score option */
|
||||
#ifdef SCOREFILE
|
||||
strncpy(scorefile, SCOREFILE, LINLEN);
|
||||
scorefile[LINLEN - 1] = '\0';
|
||||
#else
|
||||
|
||||
strcpy(scorefile, homedir);
|
||||
|
||||
if (*scorefile)
|
||||
strcat(scorefile,"/");
|
||||
strcat(scorefile, "srogue.scr");
|
||||
#endif
|
||||
|
||||
if(argc >= 2 && strcmp(argv[1], "-s") == 0)
|
||||
{
|
||||
|
|
@ -105,6 +113,20 @@ char **envp;
|
|||
time(&now);
|
||||
lowtime = (int) now;
|
||||
|
||||
#ifdef SAVEDIR
|
||||
if (argc >= 3 && !strcmp(argv[1], "-n")) {
|
||||
strncpy(whoami, argv[2], LINLEN);
|
||||
whoami[LINLEN - 1] = '\0';
|
||||
use_savedir = TRUE;
|
||||
if (snprintf(file_name, LINLEN, "%s%d-%.10s.srsav", SAVEDIR,
|
||||
playuid, whoami) >= LINLEN) {
|
||||
/* Just in case it doesn't fit */
|
||||
strcpy(file_name, "srogue.save");
|
||||
use_savedir = FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* get home and options from environment */
|
||||
|
||||
if ((env = getenv("HOME")) != NULL)
|
||||
|
|
@ -120,13 +142,15 @@ char **envp;
|
|||
if ((strlen(home) > 0) && (home[strlen(home)-1] != '/'))
|
||||
strcat(home, "/");
|
||||
|
||||
strcpy(file_name, home);
|
||||
strcat(file_name, "srogue.sav");
|
||||
if (!use_savedir) {
|
||||
strcpy(file_name, home);
|
||||
strcat(file_name, "srogue.sav");
|
||||
}
|
||||
|
||||
if ((env = getenv("ROGUEOPTS")) != NULL)
|
||||
parse_opts(env);
|
||||
|
||||
if (env == NULL || whoami[0] == '\0')
|
||||
if (!use_savedir && (env == NULL || whoami[0] == '\0'))
|
||||
{
|
||||
if((pw = getpwuid(playuid)) == NULL)
|
||||
{
|
||||
|
|
@ -140,10 +164,20 @@ char **envp;
|
|||
if (env == NULL || fruit[0] == '\0')
|
||||
strcpy(fruit, "juicy-fruit");
|
||||
|
||||
if (argc == 2)
|
||||
if (use_savedir)
|
||||
{
|
||||
/* restore() won't return if the restore succeeded. If
|
||||
* file_name doesn't exist, it will return TRUE. In that
|
||||
* case, start a new game. */
|
||||
if (!restore(file_name, envp))
|
||||
exit(1);
|
||||
}
|
||||
else if (argc == 2)
|
||||
if(!restore(argv[1], envp)) /* NOTE: NEVER RETURNS */
|
||||
exit(1);
|
||||
|
||||
/* START NEW GAME */
|
||||
|
||||
dnum = (wizard && getenv("SEED") != NULL ?
|
||||
atoi(getenv("SEED")) : lowtime + getpid());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue