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

@@ -1307,14 +1307,71 @@ gotrolefilter(void)
return FALSE;
}
void
clearrolefilter(void)
/* create a string like " !Bar !Kni" or " !chaotic" that can be
put back into an RC file by #saveoptions */
char *
rolefilterstring(char *outbuf, int which)
{
int i;
for (i = 0; i < SIZE(roles); ++i)
gr.rfilter.roles[i] = FALSE;
gr.rfilter.mask = 0;
outbuf[0] = outbuf[1] = '\0';
switch (which) {
case RS_ROLE:
for (i = 0; i < SIZE(roles); ++i) {
if (gr.rfilter.roles[i])
Sprintf(eos(outbuf), " !%.3s", roles[i].name.m);
}
break;
case RS_RACE:
for (i = 0; i < SIZE(races); ++i) {
if ((gr.rfilter.mask & races[i].selfmask) != 0)
Sprintf(eos(outbuf), " !%s", races[i].noun);
}
break;
case RS_GENDER:
for (i = 0; i < SIZE(genders); ++i) {
if ((gr.rfilter.mask & genders[i].allow) != 0)
Sprintf(eos(outbuf), " !%s", genders[i].adj);
}
break;
case RS_ALGNMNT:
for (i = 0; i < SIZE(aligns); ++i) {
if ((gr.rfilter.mask & aligns[i].allow) != 0)
Sprintf(eos(outbuf), " !%s", aligns[i].adj);
}
break;
default:
impossible("rolefilterstring: bad role aspect (%d)", which);
Strcpy(outbuf, " ?");
break;
}
/* constructed with a leading space; drop it */
return &outbuf[1];
}
void
clearrolefilter(int which)
{
int i;
switch (which) {
case RS_filter:
gr.rfilter.mask = 0; /* clear race, gender, and alignment filters */
/*FALLTHRU*/
case RS_ROLE:
for (i = 0; i < SIZE(roles); ++i)
gr.rfilter.roles[i] = FALSE;
break;
case RS_RACE:
gr.rfilter.mask &= ~ROLE_RACEMASK;
break;
case RS_GENDER:
gr.rfilter.mask &= ~ROLE_GENDMASK;
break;
case RS_ALGNMNT:
gr.rfilter.mask &= ~ROLE_ALIGNMASK;
break;
}
}
static char *
@@ -2690,7 +2747,7 @@ reset_role_filtering(void)
n = select_menu(win, PICK_ANY, &selected);
if (n >= 0) { /* n==0: clear current filters and don't set new ones */
clearrolefilter();
clearrolefilter(RS_filter);
for (i = 0; i < n; i++)
setrolefilter(selected[i].item.a_string);