From dfa5bb5941abf71e06ded76f4cc510a717012719 Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 15 Dec 2022 15:56:52 -0800 Subject: [PATCH] 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.] --- doc/fixes3-7-0.txt | 2 ++ src/options.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index b6375af04..f71d85287 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -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 diff --git a/src/options.c b/src/options.c index 036186b32..3f4c04dff 100644 --- a/src/options.c +++ b/src/options.c @@ -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; }