From 4b7aea0eac265f70654254c802b84c4e0e4d2d6d Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 7 Oct 2017 16:24:49 +0300 Subject: [PATCH] Fold invisible glyph unmapping into single function --- include/extern.h | 1 + src/apply.c | 16 +++------------- src/detect.c | 11 +++-------- src/display.c | 13 +++++++++++++ src/dokick.c | 10 ++-------- src/explode.c | 7 ++----- src/hack.c | 5 +---- src/zap.c | 6 ++---- 8 files changed, 27 insertions(+), 42 deletions(-) diff --git a/include/extern.h b/include/extern.h index de4003739..54ec9440c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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)); diff --git a/src/apply.c b/src/apply.c index e19e86b71..e5df1b904 100644 --- a/src/apply.c +++ b/src/apply.c @@ -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 */ diff --git a/src/detect.c b/src/detect.c index 2ba4a968f..1c5f35203 100644 --- a/src/detect.c +++ b/src/detect.c @@ -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); diff --git a/src/display.c b/src/display.c index bede97c3c..a16b8909f 100644 --- a/src/display.c +++ b/src/display.c @@ -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() * diff --git a/src/dokick.c b/src/dokick.c index a6a34898f..7aa8e2baa 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -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")); diff --git a/src/explode.c b/src/explode.c index 643805dc4..cc6477c4a 100644 --- a/src/explode.c +++ b/src/explode.c @@ -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) diff --git a/src/hack.c b/src/hack.c index 14e7258b4..1aabddbdc 100644 --- a/src/hack.c +++ b/src/hack.c @@ -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); diff --git a/src/zap.c b/src/zap.c index 6d82ab48e..1a8570991 100644 --- 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); -- 2.40.0