rogue4: add -n option and system savedir
This commit is contained in:
parent
9f62c197cc
commit
18a08fce7e
6 changed files with 53 additions and 8 deletions
|
|
@ -26,13 +26,14 @@ CFILES= vers.c extern.c armor.c chase.c command.c daemon.c daemons.c \
|
||||||
MISC= Makefile LICENSE.TXT rogue.6 rogue.me
|
MISC= Makefile LICENSE.TXT rogue.6 rogue.me
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS= -O3
|
CFLAGS= -O3 -DSAVEDIR=\"/usr/local/games/roguelike/rogue4save/\"
|
||||||
CRLIB = -lcurses
|
CRLIB = -lcurses
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
TAR = tar
|
TAR = tar
|
||||||
|
|
||||||
SCOREFILE=
|
SCOREFILE=
|
||||||
SF=-DSCOREFILE=\"rogue52.scr\" -DLOCKFILE=\"rogue52.lck\"
|
SF=-DSCOREFILE=\"/usr/local/games/roguelike/rogue4.scr\" \
|
||||||
|
-DLOCKFILE=\"/usr/local/games/roguelike/rogue4.lck\"
|
||||||
NAMELIST=
|
NAMELIST=
|
||||||
NL=
|
NL=
|
||||||
#MACHDEP= -DMAXLOAD=40 -DLOADAV -DCHECKTIME=4
|
#MACHDEP= -DMAXLOAD=40 -DLOADAV -DCHECKTIME=4
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ bool running = FALSE; /* True if player is running */
|
||||||
bool save_msg = TRUE; /* Remember last msg */
|
bool save_msg = TRUE; /* Remember last msg */
|
||||||
bool slow_invent = FALSE; /* Inventory one line at a time */
|
bool slow_invent = FALSE; /* Inventory one line at a time */
|
||||||
bool terse = FALSE; /* True if we should be short */
|
bool terse = FALSE; /* True if we should be short */
|
||||||
|
bool use_savedir = FALSE; /* True if using system savefile area */
|
||||||
#ifdef WIZARD
|
#ifdef WIZARD
|
||||||
bool wizard = FALSE; /* True if allows wizard commands */
|
bool wizard = FALSE; /* True if allows wizard commands */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
extern bool after, amulet, askme, door_stop, fight_flush,
|
extern bool after, amulet, askme, door_stop, fight_flush,
|
||||||
firstmove, in_shell, jump, noscore, p_know[], passgo,
|
firstmove, in_shell, jump, noscore, p_know[], passgo,
|
||||||
playing, r_know[], running, s_know[], save_msg,
|
playing, r_know[], running, s_know[], save_msg,
|
||||||
slow_invent, terse, wizard, ws_know[];
|
slow_invent, terse, use_savedir, wizard, ws_know[];
|
||||||
|
|
||||||
|
|
||||||
extern const char *p_colors[], *r_stones[], *w_names[],
|
extern const char *p_colors[], *r_stones[], *w_names[],
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,9 @@ open_score()
|
||||||
#else
|
#else
|
||||||
fd = -1;
|
fd = -1;
|
||||||
#endif
|
#endif
|
||||||
|
if (!use_savedir)
|
||||||
md_normaluser();
|
md_normaluser();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -71,16 +71,36 @@ char **envp;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SAVEDIR
|
||||||
|
if (argc >= 3 && !strcmp(argv[1], "-n"))
|
||||||
|
{
|
||||||
|
strncpy(whoami, argv[2], MAXSTR - 1);
|
||||||
|
whoami[MAXSTR - 1] = '\0'; /* insurance */
|
||||||
|
use_savedir = TRUE;
|
||||||
|
/* look for savefile at SAVEDIR/UIDplayername.r4sav */
|
||||||
|
if (snprintf(file_name, MAXSTR, "%s%d%.10s.r4sav", SAVEDIR, md_getuid(),
|
||||||
|
whoami) >= MAXSTR)
|
||||||
|
{
|
||||||
|
/* Name is too long- this shouldn't happen */
|
||||||
|
strcpy(file_name, "rogue4.save");
|
||||||
|
use_savedir = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get home and options from environment
|
* get home and options from environment
|
||||||
*/
|
*/
|
||||||
strncpy(home, md_gethomedir(), PATH_MAX);
|
strncpy(home, md_gethomedir(), PATH_MAX);
|
||||||
|
if (!use_savedir)
|
||||||
|
{
|
||||||
strcpy(file_name, home);
|
strcpy(file_name, home);
|
||||||
strcat(file_name, "rogue52.sav");
|
strcat(file_name, "/rogue4.save");
|
||||||
|
}
|
||||||
|
|
||||||
if ((env = getenv("ROGUEOPTS")) != NULL)
|
if ((env = getenv("ROGUEOPTS")) != NULL)
|
||||||
parse_opts(env);
|
parse_opts(env);
|
||||||
if (env == NULL || whoami[0] == '\0')
|
if (!use_savedir && (env == NULL || whoami[0] == '\0'))
|
||||||
strucpy(whoami, md_getusername(md_getuid()), strlen(md_getusername(md_getuid())));
|
strucpy(whoami, md_getusername(md_getuid()), strlen(md_getusername(md_getuid())));
|
||||||
if (env == NULL || fruit[0] == '\0')
|
if (env == NULL || fruit[0] == '\0')
|
||||||
strcpy(fruit, "slime-mold");
|
strcpy(fruit, "slime-mold");
|
||||||
|
|
@ -96,12 +116,27 @@ char **envp;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
init_check(); /* check for legal startup */
|
init_check(); /* check for legal startup */
|
||||||
if (argc == 2)
|
|
||||||
|
if (use_savedir)
|
||||||
|
{
|
||||||
|
/* Try to restore from file_name which we just set up. */
|
||||||
|
if (!restore(file_name, envp))
|
||||||
|
exit(1);
|
||||||
|
/* If restore() returns true, the system savefile doesn't exist.
|
||||||
|
So we'll start a new game. */
|
||||||
|
}
|
||||||
|
else if (argc == 2)
|
||||||
|
{
|
||||||
if (!restore(argv[1], envp)) /* Note: restore will never return */
|
if (!restore(argv[1], envp)) /* Note: restore will never return */
|
||||||
{
|
{
|
||||||
endwin();
|
endwin();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!use_savedir)
|
||||||
|
md_normaluser();
|
||||||
|
|
||||||
lowtime = (int) time(NULL);
|
lowtime = (int) time(NULL);
|
||||||
|
|
||||||
#ifdef WIZARD
|
#ifdef WIZARD
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,12 @@ char **envp;
|
||||||
|
|
||||||
if ((inf = open(file, 0)) < 0)
|
if ((inf = open(file, 0)) < 0)
|
||||||
{
|
{
|
||||||
|
if (use_savedir && errno == ENOENT)
|
||||||
|
{
|
||||||
|
/* We're using a system savefile which doesn't exist.
|
||||||
|
This isn't a fatal error, it means start a new game. */
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
perror(file);
|
perror(file);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue