]> granicus.if.org Git - nethack/commitdiff
dumplog of map
authorPatR <rankin@nethack.org>
Sun, 21 May 2017 05:55:08 +0000 (22:55 -0700)
committerPatR <rankin@nethack.org>
Sun, 21 May 2017 05:55:08 +0000 (22:55 -0700)
When writing the known portion of the current level's map into
dumplog, discard any blank rows at the top (there will already be
one blank line separating it from the text that precedes) and keep
at most one blank row at the bottom (sometimes there won't be any).

include/extern.h
src/detect.c

index e8e15e701168000239bc61c4d806351433641f07..cabdb51b0459dc23df7e7cc383c18373c4cbe72a 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 extern.h        $NHDT-Date: 1494107197 2017/05/06 21:46:37 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.587 $ */
+/* NetHack 3.6 extern.h        $NHDT-Date: 1495346095 2017/05/21 05:54:55 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.588 $ */
 /* Copyright (c) Steve Creps, 1988.                              */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -270,7 +270,9 @@ E void NDECL(warnreveal);
 E int FDECL(dosearch0, (int));
 E int NDECL(dosearch);
 E void NDECL(sokoban_detect);
+#ifdef DUMPLOG
 E void NDECL(dump_map);
+#endif
 E void FDECL(reveal_terrain, (int, int));
 
 /* ### dig.c ### */
index def22469e25695c97949007b68f080f1a97a0c1f..86e3159bf29923ae71c024fd1b2fd5087e2ff145 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 detect.c        $NHDT-Date: 1491705573 2017/04/09 02:39:33 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.76 $ */
+/* NetHack 3.6 detect.c        $NHDT-Date: 1495346103 2017/05/21 05:55:03 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.77 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1799,15 +1799,28 @@ int default_glyph, which_subset;
     return glyph;
 }
 
+#ifdef DUMPLOG
 void
 dump_map()
 {
-    int x, y, glyph;
+    int x, y, glyph, skippedrows;
     int subset = TER_MAP | TER_TRP | TER_OBJ | TER_MON;
     int default_glyph = cmap_to_glyph(level.flags.arboreal ? S_tree : S_stone);
     char buf[BUFSZ];
+    boolean blankrow, toprow;
 
+    /*
+     * Squeeze out excess vertial space when dumping the map.
+     * If there are any blank map rows at the top, suppress them
+     * (our caller has already printed a separator).  If there is
+     * more than one blank map row at the bottom, keep just one.
+     * Any blank rows within the middle of the map are kept.
+     * Note: putstr() with winid==0 is for dumplog.
+     */
+    skippedrows = 0;
+    toprow = TRUE;
     for (y = 0; y < ROWNO; y++) {
+        blankrow = TRUE; /* assume blank until we discover otherwise */
         for (x = 1; x < COLNO; x++) {
             int ch, color;
             unsigned special;
@@ -1815,12 +1828,27 @@ dump_map()
             glyph = reveal_terrain_getglyph(x,y, FALSE, u.uswallow,
                                             default_glyph, subset);
             (void) mapglyph(glyph, &ch, &color, &special, x, y);
-            buf[x-1] = ch;
+            buf[x - 1] = ch;
+            if (ch != ' ')
+                blankrow = FALSE;
+        }
+        if (!blankrow) {
+            buf[x - 2] = '\0';
+            if (toprow) {
+                skippedrows = 0;
+                toprow = FALSE;
+            }
+            for (x = 0; x < skippedrows; x++)
+                putstr(0, 0, "");
+            putstr(0, 0, buf); /* map row #y */
+        } else {
+            ++skippedrows;
         }
-        buf[x-2] = '\0';
-        putstr(0,0, buf);
     }
+    if (skippedrows)
+        putstr(0, 0, "");
 }
+#endif /* DUMPLOG */
 
 /* idea from crawl; show known portion of map without any monsters,
    objects, or traps occluding the view of the underlying terrain */