]> granicus.if.org Git - nethack/commitdiff
paranoid_confirmation [expanded user patch] (trunk only; 1 of 2)
authornethack.rankin <nethack.rankin>
Sat, 5 Mar 2011 10:08:38 +0000 (10:08 +0000)
committernethack.rankin <nethack.rankin>
Sat, 5 Mar 2011 10:08:38 +0000 (10:08 +0000)
[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"<return> 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 <the
  peaceful monster>?" 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 <the
  peaceful monster?".  Can also be supplied as paranoid_confirm:hit.

paranoid_confirm:pray - supersedes the existing prayconfirm boolean.
  That option is still accepted and honored duing config file processing,
  but option viewing/changing with 'O' only handles the new variant.
  This does not control "yes" vs 'y', but rather whether there's a prompt
  first or prayer simply starts.  When used, the prompt itself is the
  same yn one already being asked with prayconfirm.  Presumably config
  file support for prayconfirm will go away in some future version.
  Unlike the other paranoid settings, this one defaults to 'on' in order
  to match the 3.3.0 through 3.4.3 behavior controlled by prayconfirm,
  whose default was on (but maybe should have been off...).

paranoid_confirm:Remove - as above, causes the 'R' and 'T' commands to
  use a "what do you want to remove?" or "what do you want to takeoff?"
  inventory selection prompt even when only one accessory or piece of
  armor is worn.  Player can pick the inventory letter and remove/takeoff
  the item, use ? or * to see what the candidate item is, or cancel with
  ESC.  Can be supplied as paranoid_confirm:takeoff or "remove takeoff",
  but like with "quit explore", a single flag controls the behavior of
  both 'R' and 'T'.

Option file processing accepts two other settings, paranoid_confirm:none
and paranoid_confirm:all, but those are not available (nor needed) when
using the 'O' command.  "none" is useful because it's the value shown to
the player by 'O' when none of the paranoia flags are set, and it's a
way to turn off paranoid_confirm:pray without turning on any of the other
choices.  "all" probably isn't very useful but was trivial to tack on.

     This is an example of the menu that 'O' puts up after picking option
paranoid_confirmation from the main list.  I've shifted everything left
to reduce whitespace here; it appears on the right side of the screen for
tty menuing.

  Actions requiring extra confirmation:

  q - yes vs y to quit or to enter explore mode
  d - yes vs y to die (explore mode or debug mode)
  a - yes vs y to attack a peaceful monster
  p + y to pray (supersedes old "prayconfirm" option)
  R - always pick from inventory for Remove and Takeoff
  (end)

Currently set paranoia features are marked as preselected and can be
toggled off along with toggling any others on as desired.  I've just
realized that this menu relies on showing entries marked via preselection
rather than explicitly annotating each one as [on] or [off]; that seemed
perfectly natural during testing so I think I'll leave it this way, at
least for the time being.

include/flag.h
src/options.c

index 8e217aa4161836dc889ea981e46ce1a7ffbc520a..3de395b3b728ff11e7d8795612e375b8c4f6a51b 100644 (file)
@@ -1,5 +1,4 @@
 /* NetHack 3.5 flag.h  $Date$  $Revision$ */
-/*     SCCS Id: @(#)flag.h     3.5     2009/01/04      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -53,12 +52,17 @@ struct flag {
        boolean  tombstone;     /* print tombstone */
        boolean  toptenwin;     /* ending list in window instead of stdout */
        boolean  verbose;       /* max battle info */
-       boolean  prayconfirm;   /* confirm before praying */
        int      end_top, end_around;   /* describe desired score list */
        unsigned moonphase;
        unsigned long suppress_alert;
 #define NEW_MOON       0
 #define FULL_MOON      4
+       int      paranoia_bits; /* alternate confirmation prompting */
+#define PARANOID_QUIT  0x01
+#define PARANOID_DIE   0x02
+#define PARANOID_HIT   0x04
+#define PARANOID_PRAY  0x08
+#define PARANOID_REMOVE        0x10
        int      pickup_burden;         /* maximum burden before prompt */
        int      pile_limit; /* controls feedback when walking over objects */
        char     inv_order[MAXOCLASSES];
@@ -337,6 +341,20 @@ extern NEARDATA struct instance_flags iflags;
 #define RUN_STEP       2       /* update display every single step */
 #define RUN_CRAWL      3       /* walk w/ extra delay after each update */
 
+/* paranoid confirmation prompting */
+/* quit: yes vs y for "Really quit?" and "Enter explore mode?" */
+#define ParanoidQuit   ((flags.paranoia_bits & PARANOID_QUIT) != 0)
+/* die: yes vs y for "Die?" (dying in explore mode or wizard mode) */
+#define ParanoidDie    ((flags.paranoia_bits & PARANOID_DIE) != 0)
+/* hit: yes vs y for "Really attack <the peaceful monster>?" */
+#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 */
 
index c6cbcf175bf5325475ff1d52575f085780722f13..b4b197d43915afd8ccaf806166728ab14c434520 100644 (file)
@@ -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, &paranoia_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" :