From: nethack.rankin Date: Sat, 5 Mar 2011 10:08:38 +0000 (+0000) Subject: paranoid_confirmation [expanded user patch] (trunk only; 1 of 2) X-Git-Tag: MOVE2GIT~255 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa6098bfd49ef3528cb9c6ef6a9b10978e0aed26;p=nethack paranoid_confirmation [expanded user patch] (trunk only; 1 of 2) [Long writeup committed with flag.h and options.c only.] This is a reworking of a user contributed patch available in Pasi Kallinen's NetHack Patch Database at http://bilious.homelinux.org under the name "Paranoid_Quit". It was created by David Damerell and extended by several others, and I haven't attempted to preserve attribution. Their patch added three new boolean run-time options (this one doesn't; details below): paranoid_quit: if true, change the "really quit?" prompt to require an answer of yes rather than just y to quit, presumeably for players who type faster than they read and think (been there, done that...). It also applies to the "do you want to enter explore mode?" prompt. The changed prompt shows yes and no rather than yn as possible answers. After having used it a few times, I find it easily noticeable that "yes" is expected instead of just single keystroke 'y', and if you mess up somehow you can just reissue the #quit or X command with no harm done. (And the default setting is off; the game still issues the original yn prompt.) paranoid_hit: if true, make a similar change for the "really attack ?" prompt. Definitely helpful if you bump into a monster while in the midst of using 'y' to move diagonally upper left. Note that this just changes the expected/required answer to an existing prompt; it doesn't change interaction between the hero and monsters. paranoid_remove: if true, the 'R' and 'T' commands will prompt the player to select an appropriate item from inventory even when there's only one applicable item (instead of simply removing or taking off that only item). Helpful if you think you've got more than one thing on and intend to take off something other than the last one (which might be a ring of levitation keeping you from dropping into lava or a blindfold and you're trying to play the whole game blinded). Their patch also made two other changes which weren't controllable via options: when dipping, after picking what to dip, mention it in the second prompt for what to dip into; and require yes instead of y at the wizard mode "save bones?" prompt. We've had the enhanced dipping prompt for a while, and "unknown" installed a fix-up (which wasn't needed with their version) for it recently. I've left our bones prompt alone, the original yn query. Anyone who saves bones by accident can remove them, if not externally they by using wizard mode to revisit the same dungeon depth, load the bones, and unlink them. ##### That's a summary of the contributed patch. Now for the implemented one.... Instead of separate booleans, this adds a single compound option called "paranoid_confirmation" that takes a string argument of space separated words: "quit die attack pray Remove". And it puts the actual yes vs y querying into a new routine instead of duplicating it at each affected prompting location. paranoid_confirm:quit - as above, if true then require yes instead of y to answer the "really quit?" and "do you want to enter explore mode?" prompts. Can also be supplied as paranoid_confirm:explore or even "quit explore" but that's just redundant; it's a single flag which controls prompting for both game-ending or game-altering commands. paranoid_confirm:die - applicable only for explore and wizard modes but visible/settable during option viewing/changing in normal play. If true then require yes instead of y at the "die?" prompt. This wasn't part of their original patch, but should have been since the effect of accidental y is just as drastic as unintentionally quitting. paranoid_confirm:attack - as above, yes vs y for "really attack ?" */ +#define ParanoidHit ((flags.paranoia_bits & PARANOID_HIT) != 0) +/* pray: ask "Really pray?" (accepts y answer, doesn't require yes), + taking over for the old prayconfirm boolean option */ +#define ParanoidPray ((flags.paranoia_bits & PARANOID_PRAY) != 0) +/* remove: remove ('R') and takeoff ('T') commands prompt for an inventory + item even when only one accessory or piece of armor is currently worn */ +#define ParanoidRemove ((flags.paranoia_bits & PARANOID_REMOVE) != 0) + /* command parsing, mainly dealing with number_pad handling; not saved and restored */ diff --git a/src/options.c b/src/options.c index c6cbcf175..b4b197d43 100644 --- a/src/options.c +++ b/src/options.c @@ -145,7 +145,6 @@ static struct Bool_Opt {"perm_invent", &flags.perm_invent, FALSE, SET_IN_GAME}, {"pickup_thrown", &flags.pickup_thrown, TRUE, SET_IN_GAME}, {"popup_dialog", &iflags.wc_popup_dialog, FALSE, SET_IN_GAME}, /*WC*/ - {"prayconfirm", &flags.prayconfirm, TRUE, SET_IN_GAME}, {"preload_tiles", &iflags.wc_preload_tiles, TRUE, DISP_IN_GAME}, /*WC*/ {"pushweapon", &flags.pushweapon, FALSE, SET_IN_GAME}, #if defined(MICRO) && !defined(AMIGA) @@ -317,6 +316,8 @@ static struct Comp_Opt 15, SET_IN_FILE }, # endif #endif + { "paranoid_confirmation", "extra prompting in certain situations", + 28, SET_IN_GAME }, { "pettype", "your preferred initial pet type", 4, DISP_IN_GAME }, { "pickup_burden", "maximum burden picked up before prompt", 20, SET_IN_GAME }, @@ -550,7 +551,8 @@ const char *ev; /* Split initoptions into 2 parts for SYSCF but don't break anything not * using SYSCF. */ void -initoptions(){ +initoptions() +{ initoptions_init(); initoptions_finish(); } @@ -600,6 +602,7 @@ initoptions_init() flags.end_own = FALSE; flags.end_top = 3; flags.end_around = 2; + flags.paranoia_bits = PARANOID_PRAY; /* old prayconfirm=TRUE */ flags.pile_limit = PILE_LIMIT_DFLT; /* 5 */ flags.runmode = RUN_LEAP; iflags.msg_history = 20; @@ -678,8 +681,10 @@ initoptions_init() objects[SLIME_MOLD].oc_name_idx = SLIME_MOLD; nmcpy(pl_fruit, OBJ_NAME(objects[SLIME_MOLD]), PL_FSIZ); } + void -initoptions_finish(){ +initoptions_finish() +{ #ifndef MAC char *opts = getenv("NETHACKOPTIONS"); if (!opts) opts = getenv("HACKOPTIONS"); @@ -1052,6 +1057,37 @@ int iscompound; /* 0 == boolean option, 1 == compound */ return; } +/* paranoia[] - used by parseoptions() and special_handling() */ +STATIC_VAR const struct paranoia_opts { + int flagmask; /* which paranoid option */ + const char *argname; /* primary name */ + int argMinLen; /* minimum number of letters to match */ + const char *synonym; /* alternate name (optional) */ + int synMinLen; + const char *explain; /* for interactive menu */ +} paranoia[] = { + /* there are two initial-letter conflicts: "a"ttack vs "a"ll, "attack" + takes precedence and "all" isn't present in the interactive menu; + and "d"ie vs "d"eath, synonyms for each other so doesn't matter */ + { PARANOID_QUIT, "quit", 1, "explore", 1, + "yes vs y to quit or to enter explore mode" }, + { PARANOID_DIE, "die", 1, "death", 2, +#ifdef WIZARD + "yes vs y to die (explore mode or debug mode)" }, +#else + "yes vs y to die (explore mode only)" }, +#endif + { PARANOID_HIT, "attack", 1, "hit", 1, + "yes vs y to attack a peaceful monster" }, + { PARANOID_PRAY, "pray", 1, 0, 0, + "y to pray (supersedes old \"prayconfirm\" option)" }, + { PARANOID_REMOVE, "Remove", 1, "Takeoff", 1, + "always pick from inventory for Remove and Takeoff" }, + /* for config file parsing; interactive menu skips these */ + { 0, "none", 4, 0, 0, 0 }, /* require full word match */ + { ~0, "all", 3, 0, 0, 0 }, /* ditto */ +}; + void parseoptions(opts, tinitial, tfrom_file) register char *opts; @@ -1759,6 +1795,68 @@ goodfruit: return; } + /* user can change required response for some prompts (quit, die, hit), + or add an extra prompt (pray, Remove) that isn't ordinarily there */ + fullname = "paranoid_confirmation"; + if (match_optname(opts, fullname, 8, TRUE)) { + /* at present we don't complain about duplicates for this + option, but we do throw away the old settings whenever + we process a new one [clearing old flags is essential + for handling default paranoid_confirm:pray sanely] */ + flags.paranoia_bits = 0; /* clear all */ + if (negated) { + flags.paranoia_bits = 0; /* [now redundant...] */ + } else if ((op = string_for_opt(opts, TRUE)) != 0) { + char *pp, buf[BUFSZ]; + + op = mungspaces(strcpy(buf, op)); + for (;;) { + /* We're looking to parse + "paranoid_confirm:whichone wheretwo whothree" + and "paranoid_confirm:" prefix has already + been stripped off by the time we get here */ + pp = index(op, ' '); + if (pp) *pp = '\0'; + /* we aren't matching option names but match_optname + does what we want once we've broken the space + delimited aggregate into separate tokens */ + for (i = 0; i < SIZE(paranoia); ++i) { + if (match_optname(op, paranoia[i].argname, + paranoia[i].argMinLen, FALSE) || + (paranoia[i].synonym && + match_optname(op, paranoia[i].synonym, + paranoia[i].synMinLen, FALSE))) { + if (paranoia[i].flagmask) + flags.paranoia_bits |= paranoia[i].flagmask; + else /* 0 == "none", so clear all */ + flags.paranoia_bits = 0; + break; + } + } + if (i == SIZE(paranoia)) { + /* didn't match anything, so arg is bad; + any flags already set will stay set */ + badoption(opts); + break; + } + /* move on to next token */ + if (pp) op = pp + 1; + else break; /* no next token */ + } /* for(;;) */ + } + return; + } + + /* accept deprecated boolean; superseded by paranoid_confirm:pray */ + fullname = "prayconfirm"; + if (match_optname(opts, fullname, 4, FALSE)) { + if (negated) + flags.paranoia_bits &= ~PARANOID_PRAY; + else + flags.paranoia_bits |= PARANOID_PRAY; + return; + } + /* maximum burden picked up before prompt (Warren Cheung) */ fullname = "pickup_burden"; if (match_optname(opts, fullname, 8, TRUE)) { @@ -2910,6 +3008,34 @@ boolean setinitial,setfromfile; free((genericptr_t)style_pick); } destroy_nhwindow(tmpwin); + } else if (!strcmp("paranoid_confirmation", optname)) { + menu_item *paranoia_picks = (menu_item *)0; + + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + for (i = 0; paranoia[i].flagmask != 0; ++i) { + any.a_int = paranoia[i].flagmask; + add_menu(tmpwin, NO_GLYPH, &any, *paranoia[i].argname, 0, + ATR_NONE, paranoia[i].explain, + (flags.paranoia_bits & paranoia[i].flagmask) ? + MENU_SELECTED : MENU_UNSELECTED); + } + end_menu(tmpwin, "Actions requiring extra confirmation:"); + i = select_menu(tmpwin, PICK_ANY, ¶noia_picks); + if (i >= 0) { + /* player didn't cancel; we reset all the paranoia options + here even if there were no items picked, since user + could have toggled off preselected ones to end up with 0 */ + flags.paranoia_bits = 0; + if (i > 0) { + /* at least one item set, either preselected or newly picked */ + while (--i >= 0) + flags.paranoia_bits |= paranoia_picks[i].item.a_int; + free((genericptr_t)paranoia_picks); + } + } + destroy_nhwindow(tmpwin); } else if (!strcmp("pickup_burden", optname)) { const char *burden_name, *burden_letters = "ubsntl"; menu_item *burden_pick = (menu_item *)0; @@ -3602,7 +3728,17 @@ char *buf; else if (!strcmp(optname, "palette")) Sprintf(buf, "%s", get_color_string()); #endif - else if (!strcmp(optname, "pettype")) + else if (!strcmp(optname, "paranoid_confirmation")) { + char tmpbuf[QBUFSZ]; + + tmpbuf[0] = '\0'; + if (ParanoidQuit) Strcat(tmpbuf, " quit"); + if (ParanoidDie) Strcat(tmpbuf, " die"); + if (ParanoidHit) Strcat(tmpbuf, " attack"); + if (ParanoidPray) Strcat(tmpbuf, " pray"); + if (ParanoidRemove) Strcat(tmpbuf, " Remove"); + Strcpy(buf, tmpbuf[0] ? &tmpbuf[1] : "none"); + } else if (!strcmp(optname, "pettype")) Sprintf(buf, "%s", (preferred_pet == 'c') ? "cat" : (preferred_pet == 'd') ? "dog" : (preferred_pet == 'h') ? "horse" :