arogue5: add the savedir feature.
This commit is contained in:
parent
14fad3b319
commit
38a8534eb5
5 changed files with 40 additions and 4 deletions
|
|
@ -25,7 +25,8 @@
|
||||||
/*
|
/*
|
||||||
* where scorefile should live
|
* where scorefile should live
|
||||||
*/
|
*/
|
||||||
#define SCOREFILE "/bnr/contrib/lib/rogue/scorefile"
|
#define SCOREFILE "/var/local/games/roguelike/arogue5.scr"
|
||||||
|
#define SAVEDIR "/var/local/games/roguelike/arogue5save/"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables for checking to make sure the system isn't too loaded
|
* Variables for checking to make sure the system isn't too loaded
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,29 @@ char **envp;
|
||||||
|
|
||||||
strncpy(home,md_gethomedir(),LINELEN);
|
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 */
|
/* Get default save file */
|
||||||
|
if (!use_savedir) {
|
||||||
strcpy(file_name, home);
|
strcpy(file_name, home);
|
||||||
strcat(file_name, "arogue58.sav");
|
strcat(file_name, "arogue58.sav");
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SCOREFILE
|
||||||
|
strncpy(score_file, SCOREFILE, LINELEN);
|
||||||
|
score_file[LINELEN - 1] = '\0';
|
||||||
|
#else
|
||||||
/* Get default score file */
|
/* Get default score file */
|
||||||
strcpy(score_file, roguedir);
|
strcpy(score_file, roguedir);
|
||||||
|
|
||||||
|
|
@ -68,6 +87,7 @@ char **envp;
|
||||||
strcat(score_file,"/");
|
strcat(score_file,"/");
|
||||||
|
|
||||||
strcat(score_file, "arogue58.scr");
|
strcat(score_file, "arogue58.scr");
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((env = getenv("ROGUEOPTS")) != NULL)
|
if ((env = getenv("ROGUEOPTS")) != NULL)
|
||||||
parse_opts(env);
|
parse_opts(env);
|
||||||
|
|
@ -139,7 +159,15 @@ char **envp;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#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 */
|
if (!restore(argv[1], envp)) /* Note: restore will never return */
|
||||||
exit(1);
|
exit(1);
|
||||||
lowtime = (int) time(&now);
|
lowtime = (int) time(&now);
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ bool firstmove = FALSE;
|
||||||
bool askme = FALSE;
|
bool askme = FALSE;
|
||||||
bool in_shell = FALSE;
|
bool in_shell = FALSE;
|
||||||
bool daytime = TRUE;
|
bool daytime = TRUE;
|
||||||
|
bool use_savedir = FALSE;
|
||||||
coord delta; /* Change indicated to get_dir() */
|
coord delta; /* Change indicated to get_dir() */
|
||||||
LEVTYPE levtype; /* type of level i'm on */
|
LEVTYPE levtype; /* type of level i'm on */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1096,6 +1096,7 @@ extern bool ws_know[]; /* Does he know what a stick does */
|
||||||
extern bool m_know[]; /* Does he know what a MM does */
|
extern bool m_know[]; /* Does he know what a MM does */
|
||||||
extern bool in_shell; /* True if executing a shell */
|
extern bool in_shell; /* True if executing a shell */
|
||||||
extern bool daytime; /* Indicates whether it is daytime */
|
extern bool daytime; /* Indicates whether it is daytime */
|
||||||
|
extern bool use_savedir; /* True if using systemwide save area */
|
||||||
extern coord oldpos; /* Position before last look() call */
|
extern coord oldpos; /* Position before last look() call */
|
||||||
extern coord delta; /* Change indicated to get_dir() */
|
extern coord delta; /* Change indicated to get_dir() */
|
||||||
extern coord grid[]; /* used for random pos generation */
|
extern coord grid[]; /* used for random pos generation */
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,11 @@ char **envp;
|
||||||
|
|
||||||
if ((inf = open(file, O_RDONLY)) < 0)
|
if ((inf = open(file, O_RDONLY)) < 0)
|
||||||
{
|
{
|
||||||
|
if (use_savedir && errno == ENOENT)
|
||||||
|
{
|
||||||
|
/* No such game in SAVEDIR */
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
perror(file);
|
perror(file);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue