UltraRogue: restrict changing name and save file.
When the -n option is in use, player name and save file location cannot be changed. The score file is also restricted.
This commit is contained in:
parent
7b42d453f0
commit
fc0b18d304
2 changed files with 103 additions and 3 deletions
|
|
@ -23,6 +23,8 @@
|
||||||
#define NUM_OPTS (sizeof optlist / sizeof (OPTION))
|
#define NUM_OPTS (sizeof optlist / sizeof (OPTION))
|
||||||
#define EQSTR(a, b, c) (strncmp(a, b, c) == 0)
|
#define EQSTR(a, b, c) (strncmp(a, b, c) == 0)
|
||||||
|
|
||||||
|
int get_restr(opt_arg *opt, WINDOW *win);
|
||||||
|
|
||||||
/* description of an option and what to do with it */
|
/* description of an option and what to do with it */
|
||||||
static OPTION optlist[] =
|
static OPTION optlist[] =
|
||||||
{
|
{
|
||||||
|
|
@ -30,10 +32,10 @@ static OPTION optlist[] =
|
||||||
{"inven","Style of inventories (inven): ", &inv_type, put_inv, get_inv},
|
{"inven","Style of inventories (inven): ", &inv_type, put_inv, get_inv},
|
||||||
{"askme","Ask me about unidentified things (askme): ",&askme,put_bool,get_bool},
|
{"askme","Ask me about unidentified things (askme): ",&askme,put_bool,get_bool},
|
||||||
{"doorstop","Stop running when adjacent (doorstop): ",&doorstop,put_bool,get_bool},
|
{"doorstop","Stop running when adjacent (doorstop): ",&doorstop,put_bool,get_bool},
|
||||||
{"name", "Name (name): ", &whoami, put_str, get_str},
|
{"name", "Name (name): ", &whoami, put_str, get_restr},
|
||||||
{"fruit", "Fruit (fruit): ", &fruit, put_str, get_str},
|
{"fruit", "Fruit (fruit): ", &fruit, put_str, get_str},
|
||||||
{"file", "Save file (file): ", &file_name, put_str, get_str},
|
{"file", "Save file (file): ", &file_name, put_str, get_restr},
|
||||||
{"score", "Score file (score): ", &score_file, put_str, get_str},
|
{"score", "Score file (score): ", &score_file, put_str, get_restr},
|
||||||
{"class", "Character class (class): ",&char_type, put_abil, get_abil}
|
{"class", "Character class (class): ",&char_type, put_abil, get_abil}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -311,6 +313,7 @@ parse_opts(char *str)
|
||||||
/* Look it up and deal with it */
|
/* Look it up and deal with it */
|
||||||
|
|
||||||
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
||||||
|
{
|
||||||
if (EQSTR(str, op->o_name, len))
|
if (EQSTR(str, op->o_name, len))
|
||||||
{
|
{
|
||||||
if (op->o_putfunc == put_bool)
|
if (op->o_putfunc == put_bool)
|
||||||
|
|
@ -334,6 +337,13 @@ parse_opts(char *str)
|
||||||
|
|
||||||
strncpy(start, str, sp - str);
|
strncpy(start, str, sp - str);
|
||||||
|
|
||||||
|
/* Some options can't be changed. */
|
||||||
|
if (use_savedir &&
|
||||||
|
(op->o_opt.str == whoami ||
|
||||||
|
op->o_opt.str == file_name ||
|
||||||
|
op->o_opt.str == score_file))
|
||||||
|
break;
|
||||||
|
|
||||||
/* Put the value into the option field */
|
/* Put the value into the option field */
|
||||||
|
|
||||||
if (op->o_putfunc != put_abil &&
|
if (op->o_putfunc != put_abil &&
|
||||||
|
|
@ -394,6 +404,7 @@ parse_opts(char *str)
|
||||||
*op->o_opt.iarg = FALSE;
|
*op->o_opt.iarg = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* skip to start of next option name */
|
/* skip to start of next option name */
|
||||||
|
|
||||||
|
|
@ -517,3 +528,56 @@ get_inv(opt_arg *opt, WINDOW *win)
|
||||||
|
|
||||||
return(NORM);
|
return(NORM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get_restr()
|
||||||
|
*
|
||||||
|
* Gets strings that cannot be changed when use_savedir is set.
|
||||||
|
* get_abil() can't be repurposed to do this without ugliness.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
get_restr(opt_arg *opt, WINDOW *win)
|
||||||
|
{
|
||||||
|
int oy, ox, ny, nx;
|
||||||
|
int keep_up;
|
||||||
|
|
||||||
|
keep_up = TRUE;
|
||||||
|
getyx(win, oy, ox);
|
||||||
|
put_str(opt, win);
|
||||||
|
|
||||||
|
if (!use_savedir)
|
||||||
|
return get_str(opt, win);
|
||||||
|
|
||||||
|
getyx(win, ny, nx);
|
||||||
|
while(keep_up)
|
||||||
|
{
|
||||||
|
wmove(win, oy, ox);
|
||||||
|
wrefresh(win);
|
||||||
|
|
||||||
|
switch(readcharw(win))
|
||||||
|
{
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
keep_up = FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\033':
|
||||||
|
case '\007':
|
||||||
|
return(QUIT);
|
||||||
|
|
||||||
|
case '-':
|
||||||
|
return(MINUS);
|
||||||
|
|
||||||
|
default:
|
||||||
|
mvwaddstr(win, ny, nx + 5, "(no change allowed)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wmove(win, ny, nx + 5);
|
||||||
|
wclrtoeol(win);
|
||||||
|
wmove(win, ny, nx);
|
||||||
|
waddch(win, '\n');
|
||||||
|
|
||||||
|
return(NORM);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "rogue.h"
|
#include "rogue.h"
|
||||||
|
|
||||||
|
int save_savedir_game(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
save_game(void)
|
save_game(void)
|
||||||
{
|
{
|
||||||
|
|
@ -32,6 +34,9 @@ save_game(void)
|
||||||
char buf[2 * LINELEN];
|
char buf[2 * LINELEN];
|
||||||
char oldfile[2*LINELEN];
|
char oldfile[2*LINELEN];
|
||||||
|
|
||||||
|
if (use_savedir)
|
||||||
|
return save_savedir_game();
|
||||||
|
|
||||||
/* get file name */
|
/* get file name */
|
||||||
|
|
||||||
strcpy(oldfile,file_name);
|
strcpy(oldfile,file_name);
|
||||||
|
|
@ -79,6 +84,37 @@ save_game(void)
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* save_savedir_game()
|
||||||
|
* Simplified save function for when system savefiles are used.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
save_savedir_game(void)
|
||||||
|
{
|
||||||
|
FILE *savef;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
mpos = 0;
|
||||||
|
msg("Save game? ");
|
||||||
|
c = readcharw(cw);
|
||||||
|
if (c == 'y' || c == 'Y')
|
||||||
|
{
|
||||||
|
if ((savef = fopen(file_name, "w")) == NULL)
|
||||||
|
{
|
||||||
|
msg(strerror(errno));
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
msg("");
|
||||||
|
save_file(savef);
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg("");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
restore(char *file)
|
restore(char *file)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue