Refactor InitTileElement

Break loop when going to go outside of Tile
This commit is contained in:
Daniel Karandikar committed 2021-03-22 19:23:36 +00:00
1 parent 5ef750a879
commit d4efbdf531
1 file changed
+13 -11
+13 -11
View File
@@ -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: