]> granicus.if.org Git - nethack/commitdiff
fix github issue #687 - logging of major events
authorPatR <rankin@nethack.org>
Tue, 1 Mar 2022 12:15:55 +0000 (04:15 -0800)
committerPatR <rankin@nethack.org>
Tue, 1 Mar 2022 12:15:55 +0000 (04:15 -0800)
Reported by k21971, the dumplog section labeled "major events" showed
all logged events rather than just the ones classified as major.
Filter out the non-major ones when writing dumplog.

At the moment only a couple of ones other than achievements are major.
Probably various other types should be too.

The #chronicle command still lists all logged events unless they're
flagged as 'spoiler'.  So far the mines' end luckstone is the only
one flagged that way.  Unfortunately a player with access to live
logging could still learn whether or not the gray stone that has just
been picked up on the last mines level is the target luckstone by
viewing the log from outside of the game.

The #chronicle command would be more useful if it gathered all the
categories of events present and put up a menu allowing the player to
choose which ones to view.  I haven't attempted to implement that.

Closes #687

doc/fixes3-7-0.txt
include/extern.h
include/global.h
src/allmain.c
src/cmd.c
src/do.c
src/end.c
src/insight.c

index 862456ef5f17252096cc4e719707c7e4cd407239..754291cfbbccf423515c6d273f4d3e0a0cf46427 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.806 $ $NHDT-Date: 1645298657 2022/02/19 19:24:17 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.835 $ $NHDT-Date: 1646136928 2022/03/01 12:15:28 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -1071,6 +1071,7 @@ counting "just picked up" items when deciding what pseudo-classes should be
        an uninitialized varaible
 changes to stair internals resulted in summoned Kops blockcading the stairs up
        rather than intended stairs down
+dumplog's list of "major events" showed all logged events, not just major ones
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index 9fb0597ba9125d814661fa3d9098d8b3820e932c..c576398466dbbd0c3dbf2432ebacc2940e226346 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 extern.h        $NHDT-Date: 1644524039 2022/02/10 20:13:59 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1046 $ */
+/* NetHack 3.7 extern.h        $NHDT-Date: 1646136928 2022/03/01 12:15:28 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1062 $ */
 /* Copyright (c) Steve Creps, 1988.                              */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -263,7 +263,6 @@ extern void rhack(char *);
 extern int doextlist(void);
 extern int extcmd_via_menu(void);
 extern int enter_explore_mode(void);
-extern int do_gamelog(void);
 extern boolean bind_key(uchar, const char *);
 extern void dokeylist(void);
 extern int xytod(schar, schar);
@@ -1039,6 +1038,8 @@ extern boolean remove_achievement(schar);
 extern int count_achievements(void);
 extern schar achieve_rank(int);
 extern boolean sokoban_in_play(void);
+extern int do_gamelog(void);
+extern void show_gamelog(int);
 extern int dovanquished(void);
 extern int doborn(void);
 extern void list_vanquished(char, boolean);
index 1aea2e939fe0d1c9fbf5e64bd16733c481e61275..39c7e13d240281d47c10d9c1ea4c245038c4c399 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 global.h        $NHDT-Date: 1642630918 2022/01/19 22:21:58 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.131 $ */
+/* NetHack 3.7 global.h        $NHDT-Date: 1646136933 2022/03/01 12:15:33 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.134 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Michael Allison, 2006. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -464,20 +464,22 @@ extern struct nomakedefs_s nomakedefs;
 #define unmeta(c) (0x7f & (c))
 
 /* Game log message type flags */
-#define LL_NONE       0x0000 /* No message is livelogged */
-#define LL_WISH       0x0001 /* Report stuff people type at the wish prompt */
-#define LL_ACHIEVE    0x0002 /* Achievements bitfield + invocation, planes */
-#define LL_UMONST     0x0004 /* Kill, Bribe or otherwise dispatch unique monsters */
-#define LL_DIVINEGIFT 0x0008 /* Sacrifice gifts, crowning */
-#define LL_LIFESAVE   0x0010 /* Use up amulet of lifesaving */
-#define LL_CONDUCT    0x0020 /* Break conduct - not reported early-game */
-#define LL_ARTIFACT   0x0040 /* Excalibur, Sting, Orcrist, plus sac gifts and artwishes */
-#define LL_GENOCIDE   0x0080 /* Logging of genocides */
-#define LL_KILLEDPET  0x0100 /* Killed a tame monster */
-#define LL_ALIGNMENT  0x0200 /* changed alignment temporarily or permanently */
-#define LL_DUMP_ASC   0x0400 /* Log URL for dumplog if ascended */
-#define LL_DUMP_ALL   0x0800 /* Log dumplog url for all games */
-#define LL_MINORAC    0x1000 /* Log 'minor' achievements - can be spammy */
-#define LL_DEBUG      0x8000 /* For debugging messages and other spam */
+#define LL_NONE       0x0000L /* No message is livelogged */
+#define LL_WISH       0x0001L /* Report stuff people type at the wish prompt */
+#define LL_ACHIEVE    0x0002L /* Achievements bitfield + invocation, planes */
+#define LL_UMONST     0x0004L /* defeated unique monster */
+#define LL_DIVINEGIFT 0x0008L /* Sacrifice gifts, crowning */
+#define LL_LIFESAVE   0x0010L /* Use up amulet of lifesaving */
+#define LL_CONDUCT    0x0020L /* Break conduct - not reported early-game */
+#define LL_ARTIFACT   0x0040L /* bestowed, found, or manifactured */
+#define LL_GENOCIDE   0x0080L /* Logging of genocides */
+#define LL_KILLEDPET  0x0100L /* Killed a tame monster */
+#define LL_ALIGNMENT  0x0200L /* changed alignment, temporary or permanent */
+#define LL_DUMP_ASC   0x0400L /* Log URL for dumplog if ascended */
+#define LL_DUMP_ALL   0x0800L /* Log dumplog url for all games */
+#define LL_MINORAC    0x1000L /* Log 'minor' achievements - can be spammy */
+#define LL_SPOILER    0x4000L /* reveals information so don't show in-game
+                               * via #chronicle unless in wizard mode */
+#define LL_DEBUG      0x8000L /* For debugging messages and other spam */
 
 #endif /* GLOBAL_H */
index 7e8839799a3c62f953f2cc17ec6195e750cf702d..c0fda578b10f7af1d6e81b63101059c8a93f6f63 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 allmain.c       $NHDT-Date: 1645223894 2022/02/18 22:38:14 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.177 $ */
+/* NetHack 3.7 allmain.c       $NHDT-Date: 1646136934 2022/03/01 12:15:34 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.178 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2012. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -761,8 +761,8 @@ welcome(boolean new_game) /* false => restoring an old game */
           Hello((struct monst *) 0), g.plname, buf);
 
     l_nhcore_call(new_game ? NHCORE_START_NEW_GAME : NHCORE_RESTORE_OLD_GAME);
-    if (new_game)
-        livelog_printf(LL_MINORAC, "%s the%s entered the dungeon",
+    if (new_game) /* guarantee that 'major' event category is never empty */
+        livelog_printf(LL_ACHIEVE, "%s the%s entered the dungeon",
                        g.plname, buf);
 }
 
index 2fb4134388106afcf31e8e3baca8b8afa20b8261..09c85b5f225d5f2b5f53724d4a8a378c98c9ad40 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 cmd.c   $NHDT-Date: 1644610344 2022/02/11 20:12:24 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.519 $ */
+/* NetHack 3.7 cmd.c   $NHDT-Date: 1646136938 2022/03/01 12:15:38 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.528 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2013. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -850,36 +850,6 @@ enter_explore_mode(void)
     return ECMD_OK;
 }
 
-int
-do_gamelog(void)
-{
-#ifdef CHRONICLE
-    struct gamelog_line *tmp = g.gamelog;
-    winid win;
-    char buf[BUFSZ];
-
-    if (!tmp) {
-        pline("No chronicled events.");
-        return ECMD_OK;
-    }
-
-    win = create_nhwindow(NHW_TEXT);
-    putstr(win, 0, "Major events:");
-    putstr(win, 0, "");
-    putstr(win, 0, " Turn");
-    while (tmp) {
-        Sprintf(buf, "%5li: %s", tmp->turn, tmp->text);
-        putstr(win, 0, buf);
-        tmp = tmp->next;
-    }
-    display_nhwindow(win, TRUE);
-    destroy_nhwindow(win);
-#else
-    pline("Chronicle was turned off during compile-time.");
-#endif /* !CHRONICLE */
-    return ECMD_OK;
-}
-
 /* #wizwish command - wish for something */
 static int
 wiz_wish(void) /* Unlimited wishes for debug mode by Paul Polderman */
index 32b57f180769b1f2d57c824fb10f46aac6a0d517..d00a30f5072a83dfaf3ec8ea8d4a02a70d5abb18 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 do.c    $NHDT-Date: 1646084773 2022/02/28 21:46:13 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.294 $ */
+/* NetHack 3.7 do.c    $NHDT-Date: 1646136939 2022/03/01 12:15:39 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.295 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Derek S. Ray, 2015. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -1759,7 +1759,7 @@ goto_level(
         if (!In_quest(&u.uz0) && at_dgn_entrance("The Quest")
             && !(u.uevent.qcompleted || u.uevent.qexpelled
                  || g.quest_status.leader_is_dead)) {
-            /* [TODO: copy of same TODO below; if an anchievement for
+            /* [TODO: copy of same TODO below; if an achievement for
                receiving quest call from leader gets added, that should
                come after logging new level entry] */
             if (!u.uevent.qcalled) {
@@ -1775,7 +1775,7 @@ goto_level(
 
     /* this was originally done earlier; moved here to be logged after
        any achievement related to entering a dungeon branch
-       [TODO: if an anchievement for receiving quest call from leader
+       [TODO: if an achievement for receiving quest call from leader
        gets added, that should come after this rather than take place
        where the message is delivered above] */
     if (new)
index 1236134c81e0e329639837eff8a1bf19fc05afda..84c9b7d949ae0f9a64cd149b195de35d5af47dc1 100644 (file)
--- a/src/end.c
+++ b/src/end.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 end.c   $NHDT-Date: 1646084789 2022/02/28 21:46:29 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.238 $ */
+/* NetHack 3.7 end.c   $NHDT-Date: 1646136940 2022/03/01 12:15:40 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.239 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2012. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -793,7 +793,7 @@ dump_everything(
 
     dump_plines();
     putstr(0, 0, "");
-    (void) do_gamelog();
+    show_gamelog((how >= PANICKED) ? ENL_GAMEOVERALIVE : ENL_GAMEOVERDEAD);
     putstr(0, 0, "");
     putstr(0, 0, "Inventory:");
     (void) display_inventory((char *) 0, TRUE);
@@ -1393,7 +1393,7 @@ really_done(int how)
 
         /* it would be better to do this after killer.name fixups but
            that comes too late; end-of-game is classified as a "major
-           achievement" even if it happens to be ending in failure */
+           achievement" even if game happens to be ending in failure */
         formatkiller(pbuf, (unsigned) sizeof pbuf, how, TRUE);
         if (!*pbuf)
             Strcpy(pbuf, deaths[how]);
index abc3bfd7748ad1d82f8caa35e312fb88ccbebc6c..ad94d9eaf552877c433eb6de017f51cee66d970e 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 insight.c       $NHDT-Date: 1646084789 2022/02/28 21:46:29 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.52 $ */
+/* NetHack 3.7 insight.c       $NHDT-Date: 1646136941 2022/03/01 12:15:41 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.53 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -62,8 +62,10 @@ static struct ll_achieve_msg achieve_msg [] = {
     { LL_ACHIEVE, "entered the Planes" },
     { LL_ACHIEVE, "entered the Astral Plane" },
     { LL_ACHIEVE, "ascended" },
-    { LL_ACHIEVE, "acquired the Mines' End luckstone" },
-    { LL_ACHIEVE, "completed Sokoban" },
+    { LL_ACHIEVE | LL_SPOILER, "acquired the Mines' End luckstone" },
+    { LL_ACHIEVE, "completed Sokoban" }, /* actually, acquired the prize item
+                                          * which doesn't necessarily mean all
+                                          * four levels have been solved */
     { LL_ACHIEVE | LL_UMONST, "killed Medusa" },
      /* these two are not logged */
     { 0, "hero was always blond, no, blind" },
@@ -89,11 +91,12 @@ static struct ll_achieve_msg achieve_msg [] = {
     { LL_ACHIEVE, "" }, /* Xp 22 */
     { LL_ACHIEVE, "" }, /* Xp 26 */
     { LL_ACHIEVE, "" }, /* Xp 30 */
-    { LL_MINORAC, "learned castle drawbridge's tune" },
+    { LL_MINORAC, "learned castle drawbridge's tune" }, /* achievement #31 */
     { 0, "" } /* keep this one at the end */
 };
 
-
+/* macros to simplify output of enlightenment messages; also used by
+   conduct and achievements */
 #define enl_msg(prefix, present, past, suffix, ps) \
     enlght_line(prefix, final ? past : present, suffix, ps)
 #define you_are(attr, ps) enl_msg(You_, are, were, attr, ps)
@@ -2360,6 +2363,61 @@ sokoban_in_play(void)
     return FALSE;
 }
 
+#define majorevent(llmsg) (((llmsg)->flags & LL_ACHIEVE) != 0)
+#define spoilerevent(llmsg) (((llmsg)->flags & LL_SPOILER) != 0)
+
+/* #chronicle command */
+int
+do_gamelog(void)
+{
+#ifdef CHRONICLE
+    if (g.gamelog) {
+        show_gamelog(0);
+    } else {
+        pline("No chronicled events.");
+    }
+#else
+    pline("Chronicle was turned off during compile-time.");
+#endif /* !CHRONICLE */
+    return ECMD_OK;
+}
+
+/* #chronicle details */
+void
+show_gamelog(int final)
+{
+#ifdef CHRONICLE
+    struct gamelog_line *llmsg;
+    winid win;
+    char buf[BUFSZ];
+    int eventcnt = 0;
+
+    win = create_nhwindow(NHW_TEXT);
+    Sprintf(buf, "%s events:", final ? "Major" : "Logged");
+    putstr(win, 0, buf);
+    for (llmsg = g.gamelog; llmsg; llmsg = llmsg->next) {
+        if (final && !majorevent(llmsg))
+            continue;
+        if (!final && !wizard && spoilerevent(llmsg))
+            continue;
+        if (!eventcnt++)
+            putstr(win, 0, " Turn");
+        Sprintf(buf, "%5ld: %s", llmsg->turn, llmsg->text);
+        putstr(win, 0, buf);
+    }
+    /* since start of game is logged as a major event, 'eventcnt' should
+       never end up as 0; for 'final', end of game is a major event too */
+    if (!eventcnt)
+        putstr(win, 0, " none");
+
+    display_nhwindow(win, TRUE);
+    destroy_nhwindow(win);
+#else
+    nhUse(final);
+#endif /* !CHRONICLE */
+    return;
+}
+
 /*
  *      Vanquished monsters.
  */