last? role/race/&c option values update

Keep track of how a role|race|gender|alignment option got its value
so that role:!Tourist in .nethackrc and role:!Priest in NETHACKOPTIONS
yield 'role:!Priest' rather than merging into 'role:!Priest !Tourist'.
It also doesn't write the value into new config file for #saveoptions
if that value comes from environment or command line (not applicable
since the command line arguments for role,&c don't go through options
handling).  Also, the old config file value takes precedence over
the current game's value file so that 'role:random' doesn't become
'role:Healer' or such in a new config after the random value gets
picked for play.

This only tracks the role, race, gender, and alignment options but the
concept could be extended to all options.  The data would need to be
saved and restored if values set interactively need to be retained in
restore sessions (doesn't apply to role,&c since those don't change
during play).
This commit is contained in:
PatR
2022-12-22 15:07:33 -08:00
parent 37f6eee147
commit 91e2ab13b2
7 changed files with 397 additions and 85 deletions

View File

@@ -1278,7 +1278,7 @@ struct instance_globals_o {
/* options.c */
/* options processing */
int opt_phase; /* builtin_opt, syscf_, rc_file_, environ_, play_opt */
boolean opt_initial;
boolean opt_from_file;
boolean opt_need_redraw; /* for doset() */

View File

@@ -1992,6 +1992,7 @@ extern void initoptions(void);
extern void initoptions_init(void);
extern void initoptions_finish(void);
extern boolean parseoptions(char *, boolean, boolean);
extern void freeroleoptvals(void);
extern char *get_option_value(const char *, boolean);
extern int doset_simple(void);
extern int doset(void);
@@ -2410,7 +2411,8 @@ extern int pick_align(int, int, int, int);
extern void rigid_role_checks(void);
extern boolean setrolefilter(const char *);
extern boolean gotrolefilter(void);
extern void clearrolefilter(void);
extern char *rolefilterstring(char *, int);
extern void clearrolefilter(int);
extern char *root_plselection_prompt(char *, int, int, int, int, int);
extern char *build_plselection_prompt(char *, int, int, int, int, int);
extern void plnamesuffix(void);

View File

@@ -115,16 +115,16 @@ static int optfn_##a(int, int, boolean, char *, char *);
No, Yes, No, No, NoAlias,
"your character's name (e.g., name:Merlin-W)")
NHOPTC(role, Advanced, PL_CSIZ, opt_in, set_gameview,
Yes, Yes, No, No, "character",
Yes, Yes, Yes, No, "character",
"your starting role (e.g., Barbarian, Valkyrie)")
NHOPTC(race, Advanced, PL_CSIZ, opt_in, set_gameview,
Yes, Yes, No, No, NoAlias,
Yes, Yes, Yes, No, NoAlias,
"your starting race (e.g., Human, Elf)")
NHOPTC(gender, Advanced, 8, opt_in, set_gameview,
Yes, Yes, No, No, NoAlias,
Yes, Yes, Yes, No, NoAlias,
"your starting gender (male or female)")
NHOPTC(alignment, Advanced, 8, opt_in, set_gameview,
Yes, Yes, No, No, "align",
Yes, Yes, Yes, No, "align",
"your starting alignment (lawful, neutral, or chaotic)")
/* end of special ordering; remainder of entries are in alphabetical order
*/