]> granicus.if.org Git - nethack/commitdiff
overriding message suppression, revisited
authorPatR <rankin@nethack.org>
Wed, 20 Jan 2016 02:16:13 +0000 (18:16 -0800)
committerPatR <rankin@nethack.org>
Wed, 20 Jan 2016 02:16:13 +0000 (18:16 -0800)
This is more robust than the previous hack.  The issue of whether to
use it in other places is still unexplored.  Ultimately it's the user's
fault if overzealous message suppression hides something important.
[For an eerie game, try 'MSGTYPE=hide .'.]

include/decl.h
include/extern.h
include/flag.h
src/invent.c
src/options.c
src/pline.c

index 128413aaa2ca5c3bbb224b13dbee617cbbd47f24..52145808e6f45fd0e3419488c5ceea0781dffe7d 100644 (file)
@@ -406,6 +406,8 @@ struct plinemsg_type {
 #define MSGTYP_NOREP    1
 #define MSGTYP_NOSHOW   2
 #define MSGTYP_STOP     3
+/* bitmask for callers of hide_unhide_msgtypes() */
+#define MSGTYP_MASK_REP_SHOW ((1 << MSGTYP_NOREP) | (1 << MSGTYP_NOSHOW))
 
 E struct plinemsg_type *plinemsg_types;
 
index 661475c1b44bae54affb9952bb5940e00135ecd7..dd104cf70dcc89d5d369a6b7e0895da12f725ec3 100644 (file)
@@ -1641,8 +1641,8 @@ E int NDECL(dotogglepickup);
 E void NDECL(option_help);
 E void FDECL(next_opt, (winid, const char *));
 E int FDECL(fruitadd, (char *, struct fruit *));
-E int FDECL(choose_classes_menu,
-            (const char *, int, BOOLEAN_P, char *, char *));
+E int FDECL(choose_classes_menu, (const char *, int, BOOLEAN_P,
+                                  char *, char *));
 E void FDECL(add_menu_cmd_alias, (CHAR_P, CHAR_P));
 E char FDECL(map_menu_cmd, (CHAR_P));
 E void FDECL(assign_warnings, (uchar *));
@@ -1666,6 +1666,7 @@ E boolean FDECL(get_menu_coloring, (char *, int *, int *));
 E void NDECL(free_menu_coloring);
 E boolean FDECL(msgtype_parse_add, (char *));
 E int FDECL(msgtype_type, (const char *, BOOLEAN_P));
+E void FDECL(hide_unhide_msgtypes, (BOOLEAN_P, int));
 E void NDECL(msgtype_free);
 
 /* ### pager.c ### */
index 6482c7198e7a0acbfc127cded6f2baba891ae5ad..af3b59b655ce8e39221a5687ff339083f30a91a3 100644 (file)
@@ -363,13 +363,18 @@ extern NEARDATA struct sysflag sysflags;
 extern NEARDATA struct instance_flags iflags;
 
 /* last_msg values */
-#define PLNMSG_NOSHO_OVERRIDE    (-2)
-#define PLNMSG_NOREP_OVERRIDE    (-1)
 #define PLNMSG_UNKNOWN             0 /* arbitrary */
 #define PLNMSG_ONE_ITEM_HERE       1 /* "you see <single item> here" */
 #define PLNMSG_TOWER_OF_FLAME      2 /* scroll of fire */
 #define PLNMSG_CAUGHT_IN_EXPLOSION 3 /* explode() feedback */
 #define PLNMSG_OBJ_GLOWS           4 /* "the <obj> glows <color>" */
+    /* Usage:
+     *  pline("some message");
+     *    pline: vsprintf + putstr + iflags.last_msg = PLNMSG_UNKNOWN;
+     *  iflags.last_msg = PLNMSG_some_message;
+     * and subsequent code can adjust the next message if it is affected
+     * by some_message.  The next message will clear iflags.last_msg.
+     */
 
 /* runmode options */
 #define RUN_TPORT 0 /* don't update display until movement stops */
index dc740c4b14621ef2ab8f98baa4f4d37b3e3df1e0..f230c32c0cb08d630ade66595ba259357d81d152 100644 (file)
@@ -2830,8 +2830,16 @@ boolean picked_some;
 int
 dolook()
 {
-    iflags.last_msg = PLNMSG_NOREP_OVERRIDE;
-    return look_here(0, FALSE);
+    int res;
+
+    /* don't let
+       MSGTYPE={norep,noshow} "You see here"
+       interfere with feedback from the look-here command */
+    hide_unhide_msgtypes(TRUE, MSGTYP_MASK_REP_SHOW);
+    res = look_here(0, FALSE);
+    /* restore normal msgtype handling */
+    hide_unhide_msgtypes(FALSE, MSGTYP_MASK_REP_SHOW);
+    return res;
 }
 
 boolean
index 5eb02a7682dda850f081674f80cb309677b5c3a3..6c135d33004efd59e89caecbbeffb9388f21663f 100644 (file)
@@ -1500,6 +1500,8 @@ boolean norepeat; /* called from Norep(via pline) */
     struct plinemsg_type *tmp = plinemsg_types;
 
     while (tmp) {
+        /* we don't exclude entries with negative msgtype values
+           because then the msg might end up matching a later pattern */
         if (regex_match(msg, tmp->regex))
             return tmp->msgtype;
         tmp = tmp->next;
@@ -1507,6 +1509,26 @@ boolean norepeat; /* called from Norep(via pline) */
     return norepeat ? MSGTYP_NOREP : MSGTYP_NORMAL;
 }
 
+/* negate one or more types of messages so that their type handling will
+   be disabled or re-enabled; MSGTYPE_NORMAL (value 0) is not affected */
+void
+hide_unhide_msgtypes(hide, hide_mask)
+boolean hide;
+int hide_mask;
+{
+    struct plinemsg_type *tmp;
+    int mt;
+
+    /* negative msgtype value won't be recognized by pline, so does nothing */
+    for (tmp = plinemsg_types; tmp; tmp = tmp->next) {
+        mt = tmp->msgtype;
+        if (!hide)
+            mt = -mt; /* unhide: negate negative, yielding positive */
+        if (mt > 0 && ((1 << mt) & hide_mask))
+            tmp->msgtype = -tmp->msgtype;
+    }
+}
+
 int
 msgtype_count()
 {
index 86ac55a122fff359417e3ea1ce52f5987b3bfa22..141532cadf813fca36f5dcf80c224a6550bf80d2 100644 (file)
@@ -87,26 +87,9 @@ VA_DECL(const char *, line)
         return;
     }
 
-    /*
-     * Normally the sequence is
-     *  caller: pline("some message");
-     *   pline: vsprintf + putstr + iflags.last_msg = PLNMSG_UNKNOWN;
-     *  caller: iflags.last_msg = PLNMSG_some_message;
-     * and subsequent code can adjust the next message if it is
-     * affected by some_message.
-     *
-     * But some callers can use last_msg to control handling of next
-     * message
-     *  caller: iflags.last_msg = PLNMSG_NOREP_OVERRIDE;
-     *  caller: pline("another message");
-     * to force another_message to be delivered even if is a repeat
-     * and user's MSGTYPE settings have classified it as don't-repeat.
-     */
-
     msgtyp = msgtype_type(line, no_repeat);
-    if ((msgtyp == MSGTYP_NOSHOW && iflags.last_msg != PLNMSG_NOSHO_OVERRIDE)
-        || (msgtyp == MSGTYP_NOREP && iflags.last_msg != PLNMSG_NOREP_OVERRIDE
-            && !strcmp(line, prevmsg)))
+    if (msgtyp == MSGTYP_NOSHOW
+        || (msgtyp == MSGTYP_NOREP && !strcmp(line, prevmsg)))
         return;
     if (vision_full_recalc)
         vision_recalc(0);