Mercurial > hg > early-roguelike
diff rogue3/options.c @ 2:e676d52b5d09
Prevent changing name or save file when using system savedir
author | edwarj4 |
---|---|
date | Wed, 14 Oct 2009 11:21:33 +0000 |
parents | 527e2150eaf0 |
children | e52a8a7ad4c5 |
line wrap: on
line diff
--- a/rogue3/options.c Wed Oct 14 01:32:13 2009 +0000 +++ b/rogue3/options.c Wed Oct 14 11:21:33 2009 +0000 @@ -34,6 +34,8 @@ typedef struct optstruct OPTION; +int allowchange(OPTION *opt); /* doesn't need to be externally visible */ + OPTION optlist[] = { {"terse", "Terse output: ", (int *) &terse, put_bool, get_bool }, @@ -69,9 +71,12 @@ */ for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) { - waddstr(hw, op->o_prompt); - (*op->o_putfunc)(op->o_opt); - waddch(hw, '\n'); + if (allowchange(op)) + { + waddstr(hw, op->o_prompt); + (*op->o_putfunc)(op->o_opt); + waddch(hw, '\n'); + } } /* * Set values @@ -79,11 +84,21 @@ wmove(hw, 0, 0); for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) { + if (!allowchange(op)) + continue; waddstr(hw, op->o_prompt); if ((retval = (*op->o_getfunc)(op->o_opt, hw))) + { if (retval == QUIT) break; - else if (op > optlist) { /* MINUS */ +#if 0 +/* Support for MINUS has been removed because making it work with + * hidden unchangable options without underflowing optlist will + * require a complete rewrite. And it should also be rewritten + * so option() doesn't count on get_str() to put the cursor in the + * right place, because that makes it a pain to understand. + */ + else if (op > optlist) { /* retval == MINUS */ wmove(hw, (int)(op - optlist) - 1, 0); op -= 2; } @@ -93,6 +108,10 @@ wmove(hw, 0, 0); op--; } +#else + break; +#endif + } } /* * Switch back to original screen @@ -285,6 +304,11 @@ * Look it up and deal with it */ for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) + { + /* If using system savefiles, changing your name or the + save file is not allowed. */ + if (!allowchange(op)) + continue; if (EQSTR(str, op->o_name, len)) { if (op->o_putfunc == put_bool) /* if option is a boolean */ @@ -324,6 +348,7 @@ *(int *)op->o_opt = FALSE; break; } + } /* * skip to start of next option name @@ -351,3 +376,15 @@ } *s1 = '\0'; } + +/* Tells whether the user is allowed to change the option. */ +int allowchange(OPTION *opt) +{ + if (!use_savedir) + return 1; + if (!strcmp(opt->o_name, "name")) + return 0; + if (!strcmp(opt->o_name, "file")) + return 0; + return 1; +}