]> granicus.if.org Git - nethack/commitdiff
Fold invisible glyph unmapping into single function
authorPasi Kallinen <paxed@alt.org>
Sat, 7 Oct 2017 13:24:49 +0000 (16:24 +0300)
committerPasi Kallinen <paxed@alt.org>
Sat, 7 Oct 2017 13:24:49 +0000 (16:24 +0300)
include/extern.h
src/apply.c
src/detect.c
src/display.c
src/dokick.c
src/explode.c
src/hack.c
src/zap.c

index de4003739e43fa0e56a2423b6a9abf4f001f06ac..54ec9440cf7e31a3c99ef5959cccbf956341a40b 100644 (file)
@@ -321,6 +321,7 @@ E void FDECL(map_background, (XCHAR_P, XCHAR_P, int));
 E void FDECL(map_trap, (struct trap *, int));
 E void FDECL(map_object, (struct obj *, int));
 E void FDECL(map_invisible, (XCHAR_P, XCHAR_P));
+E boolean FDECL(unmap_invisible, (int, int));
 E void FDECL(unmap_object, (int, int));
 E void FDECL(map_location, (int, int, int));
 E void FDECL(feel_newsym, (XCHAR_P, XCHAR_P));
index e19e86b71627ce8f6be0874377fc7b03309ef6f7..e5df1b904a0067ee62a43e61d74a7eb142423b67 100644 (file)
@@ -408,11 +408,8 @@ register struct obj *obj;
             map_invisible(rx, ry);
         return res;
     }
-    if (glyph_is_invisible(levl[rx][ry].glyph)) {
-        unmap_object(rx, ry);
-        newsym(rx, ry);
+    if (unmap_invisible(rx,ry))
         pline_The("invisible monster must have moved.");
-    }
 
     lev = &levl[rx][ry];
     switch (lev->typ) {
@@ -631,10 +628,7 @@ struct obj *obj;
 
     if (!(mtmp = m_at(cc.x, cc.y))) {
         There("is no creature there.");
-        if (glyph_is_invisible(levl[cc.x][cc.y].glyph)) {
-            unmap_object(cc.x, cc.y);
-            newsym(cc.x, cc.y);
-        }
+        (void) unmap_invisible(cc.x, cc.y);
         return 1;
     }
 
@@ -3030,11 +3024,7 @@ struct obj *obj;
         }
     } else {
         /* no monster here and no statue seen or remembered here */
-        if (glyph_is_invisible(glyph)) {
-            /* now you know that nothing is there... */
-            unmap_object(bhitpos.x, bhitpos.y);
-            newsym(bhitpos.x, bhitpos.y);
-        }
+        (void) unmap_invisible(bhitpos.x, bhitpos.y);
         You("miss; there is no one there to hit.");
     }
     u_wipe_engr(2); /* same as for melee or throwing */
index 2ba4a968fec792657c55bd905d0534bda9a345f1..1c5f3520311b5ea80d9e0b9b23456ebcac075f37 100644 (file)
@@ -1394,9 +1394,7 @@ genericptr_t num;
         }
         if (!canspotmon(mtmp) && !glyph_is_invisible(levl[zx][zy].glyph))
             map_invisible(zx, zy);
-    } else if (glyph_is_invisible(levl[zx][zy].glyph)) {
-        unmap_object(zx, zy);
-        newsym(zx, zy);
+    } else if (unmap_invisible(zx, zy)) {
         (*(int *) num)++;
     }
 }
@@ -1646,11 +1644,8 @@ register int aflag; /* intrinsic autosearch vs explicit searching */
                     /* see if an invisible monster has moved--if Blind,
                      * feel_location() already did it
                      */
-                    if (!aflag && !mtmp && !Blind
-                        && glyph_is_invisible(levl[x][y].glyph)) {
-                        unmap_object(x, y);
-                        newsym(x, y);
-                    }
+                    if (!aflag && !mtmp && !Blind)
+                        (void) unmap_invisible(x, y);
 
                     if ((trap = t_at(x, y)) && !trap->tseen && !rnl(8)) {
                         nomul(0);
index bede97c3c3de7b4011a6125a64263248f3d6f78d..a16b8909f8d7f30c25d40ede7fac6a5a19a9463d 100644 (file)
@@ -277,6 +277,19 @@ register xchar x, y;
     }
 }
 
+boolean
+unmap_invisible(x, y)
+int x, y;
+{
+    if (isok(x,y) && glyph_is_invisible(levl[x][y].glyph)) {
+        unmap_object(x, y);
+        newsym(x, y);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+
 /*
  * unmap_object()
  *
index a6a34898f58c43f8c7a3c914e93019afa432e2b4..7aa8e2baaf525d8acf29bd5e6989593736ba1ddb 100644 (file)
@@ -262,10 +262,7 @@ doit:
         } else {
             maybe_mnexto(mon);
             if (mon->mx != x || mon->my != y) {
-                if (glyph_is_invisible(levl[x][y].glyph)) {
-                    unmap_object(x, y);
-                    newsym(x, y);
-                }
+                (void) unmap_invisible(x, y);
                 pline("%s %s, %s evading your %skick.", Monnam(mon),
                       (!level.flags.noteleport && can_teleport(mon->data))
                           ? "teleports"
@@ -946,10 +943,7 @@ dokick()
         }
         return 1;
     }
-    if (glyph_is_invisible(levl[x][y].glyph)) {
-        unmap_object(x, y);
-        newsym(x, y);
-    }
+    (void) unmap_invisible(x, y);
     if (is_pool(x, y) ^ !!u.uinwater) {
         /* objects normally can't be removed from water by kicking */
         You("splash some %s around.", hliquid("water"));
index 643805dc40fb673c7fc1852d79432035aa31b73a..cc6477c4a9631a4530324948a463228000aa5c18 100644 (file)
@@ -219,11 +219,8 @@ int expltype;
             }
             if (mtmp && cansee(i + x - 1, j + y - 1) && !canspotmon(mtmp))
                 map_invisible(i + x - 1, j + y - 1);
-            else if (!mtmp && glyph_is_invisible(
-                                  levl[i + x - 1][j + y - 1].glyph)) {
-                unmap_object(i + x - 1, j + y - 1);
-                newsym(i + x - 1, j + y - 1);
-            }
+            else if (!mtmp)
+                (void) unmap_invisible(i + x - 1, j + y - 1);
             if (cansee(i + x - 1, j + y - 1))
                 visible = TRUE;
             if (explmask[i][j] == 1)
index 14e7258b46715d0ccb9c96935fa78dffc4813ffb..1aabddbdc2c187c1a7211ae8b8cbf369f60a735e 100644 (file)
@@ -1635,10 +1635,7 @@ domove()
         }
         return;
     }
-    if (glyph_is_invisible(levl[x][y].glyph)) {
-        unmap_object(x, y);
-        newsym(x, y);
-    }
+    (void) unmap_invisible(x, y);
     /* not attacking an animal, so we try to move */
     if ((u.dx || u.dy) && u.usteed && stucksteed(FALSE)) {
         nomul(0);
index 6d82ab48e1af96f362a6b38e039038e022ab1ed5..1a85709913b10e96abc212e1903387a61c582aa0 100644 (file)
--- a/src/zap.c
+++ b/src/zap.c
@@ -3958,10 +3958,8 @@ boolean say; /* Announce out of sight hit/miss events if true */
             /* reveal/unreveal invisible monsters before tmp_at() */
             if (mon && !canspotmon(mon))
                 map_invisible(sx, sy);
-            else if (!mon && glyph_is_invisible(levl[sx][sy].glyph)) {
-                unmap_object(sx, sy);
-                newsym(sx, sy);
-            }
+            else if (!mon)
+                (void) unmap_invisible(sx, sy);
             if (ZAP_POS(levl[sx][sy].typ)
                 || (isok(lsx, lsy) && cansee(lsx, lsy)))
                 tmp_at(sx, sy);