From 22db98ea35a0d4098422d2c7d690931c4c3c2fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Ja=C5=82ocha?= Date: Sun, 13 Oct 2024 01:04:58 +0200 Subject: [PATCH] fix: limitsFloorView incorrect thing check when calculating visible floor (#920) --- src/client/mapview.cpp | 10 +++++----- src/client/tile.cpp | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index 3832ba5dd..2e5f29c1e 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -710,16 +710,16 @@ uint8_t MapView::calcFirstVisibleFloor(bool checkLimitsFloorsView) const firstFloor = std::max(m_posInfo.camera.z - g_gameConfig.getMapAwareUndergroundFloorRange(), g_gameConfig.getMapUndergroundFloorRange()); // loop in 3x3 tiles around the camera - for (int_fast32_t ix = -1; checkLimitsFloorsView && ix <= 1 && firstFloor < m_posInfo.camera.z; ++ix) { - for (int_fast32_t iy = -1; iy <= 1 && firstFloor < m_posInfo.camera.z; ++iy) { + for (int ix = -1; checkLimitsFloorsView && ix <= 1 && firstFloor < m_posInfo.camera.z; ++ix) { + for (int iy = -1; iy <= 1 && firstFloor < m_posInfo.camera.z; ++iy) { const auto& pos = m_posInfo.camera.translated(ix, iy); + const bool isLookPossible = g_map.isLookPossible(pos); // process tiles that we can look through, e.g. windows, doors - if ((ix == 0 && iy == 0) || ((std::abs(ix) != std::abs(iy)) && g_map.isLookPossible(pos))) { + if ((ix == 0 && iy == 0) || ((std::abs(ix) != std::abs(iy)) && isLookPossible)) { Position upperPos = pos; Position coveredPos = pos; - const bool isLookPossible = g_map.isLookPossible(pos); while (coveredPos.coveredUp() && upperPos.up() && upperPos.z >= firstFloor) { // check tiles physically above if (const TilePtr& tile = g_map.getTile(upperPos)) { @@ -754,7 +754,7 @@ uint8_t MapView::calcLastVisibleFloor() const { uint8_t z = g_gameConfig.getMapSeaFloor(); - // this could happens if the player is not known yet + // this could happen if the player is not known yet if (m_posInfo.camera.isValid()) { // view only underground floors when below sea level if (m_posInfo.camera.z > g_gameConfig.getMapSeaFloor()) diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 055ce9296..5030789f9 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -695,8 +695,18 @@ bool Tile::hasBlockingCreature() const bool Tile::limitsFloorsView(bool isFreeView) { // ground and walls limits the view - const auto& firstThing = getThing(0); - return firstThing && !firstThing->isDontHide() && (firstThing->isGround() || (isFreeView ? firstThing->isOnBottom() : firstThing->isOnBottom() && firstThing->blockProjectile())); + for (const auto& thing : m_things) { + // iterate until common item is encountered + if (thing->isCommon()) { + break; + } + + if (!thing->isDontHide() && (thing->isGround() || (isFreeView ? thing->isOnBottom() : thing->isOnBottom() && thing->blockProjectile()))) { + return true; + } + } + + return false; } bool Tile::checkForDetachableThing(const TileSelectType selectType)