role,race,&c options: environment vs config file

Due to the unorthodox values for role, race, gender, and alignment,
specifying a negated value or set of values in NETHACKOPTIONS wasn't
overriding a specific value set in the run-time config file.  The
command line should take priority, then environment, then config file,
lastly builtin defaults.

This could probably use some improvement.  It now treats role:!val
as if there was no val role and the entry was role:random rather than
previous role:none (affects prompting).

[I've just realized that role:!foo in environment will be combined
with role:!bar in config file rather than replacing it.  I'm not sure
how to deal with that.]
This commit is contained in:
PatR
2022-12-15 15:56:52 -08:00
parent df7e575500
commit dfa5bb5941
2 changed files with 14 additions and 0 deletions

View File

@@ -1070,6 +1070,8 @@ throwing recoil while levitating could send hero out of shop while carrying
a step other than back into the shop was treated as a robbery
if punished and iron ball was cursed and wielded--so welded to hand--falling
when doors would drop it instead of keeping it welded
if player's run-time config file had OPTIONS=role:Val and the environment had
NETHACKOPTIONS='role:!Val' the hero would be a Val instead of !Val
Fixes to 3.7.0-x Problems that Were Exposed Via git Repository

View File

@@ -7477,6 +7477,7 @@ parse_role_opts(
char *opts,
char **opp)
{
static char role_random[] = "random"; /* not 'const' but never modified */
char *op = *opp;
boolean ok = FALSE;
@@ -7535,6 +7536,8 @@ parse_role_opts(
complain_about_duplicate(optidx);
*opp = op;
ok = TRUE;
/* don't return yet; value might be a list which follows
this with something else, making it invalid */
}
if (sp) {
@@ -7544,6 +7547,15 @@ parse_role_opts(
op += strlen(op); /* break; */
}
}
if (!ok) {
/* '!ok' without config_error_add() implies a valid negation;
in case NETHACKOPTIONS=role:!Val overrides config file
OPTIONS=role:Val we need a positive result which will yield
someting other than ROLE_NONE from str2role(),str2race(),&c */
*opp = role_random;
ok = TRUE;
}
}
return ok;
}