From d4efbdf53170e6df0110d0ed211b0abf5336ec74 Mon Sep 17 00:00:00 2001 From: Daniel Karandikar Date: Mon, 22 Mar 2021 19:22:27 +0000 Subject: [PATCH] Refactor InitTileElement Break loop when going to go outside of Tile --- src/openrct2-ui/windows/Banner.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index a2225df03d..f0442ce136 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -93,19 +93,21 @@ private: void InitTileElement() { TileElement* tileElement = map_get_first_element_at(_banner->position.ToCoordsXY().ToTileCentre()); - if (tileElement == nullptr) + if (tileElement != nullptr) { - _tileElement = nullptr; - return; + while (1) + { + if ((tileElement->GetType() == TILE_ELEMENT_TYPE_BANNER) && (tileElement->AsBanner()->GetIndex() == number)) + { + _tileElement = tileElement; + return; + } + if (tileElement->IsLastForTile()) + break; + tileElement++; + } } - - while (1) - { - if ((tileElement->GetType() == TILE_ELEMENT_TYPE_BANNER) && (tileElement->AsBanner()->GetIndex() == number)) - break; - tileElement++; - } - _tileElement = tileElement; + _tileElement = nullptr; } public: