From e1efe05001712379dd6a74264db23e54c2ebbb51 Mon Sep 17 00:00:00 2001 From: "Leilani A." <168607226+kaleohanopahala@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:07:16 -0300 Subject: [PATCH] Update tile.cpp --- src/items/tile.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/items/tile.cpp b/src/items/tile.cpp index edd827db0e5..44f49c4fb7b 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -1876,11 +1876,25 @@ std::shared_ptr Tile::getUseItem(int32_t index) const { return ground; } - if (const auto &thing = getThing(index)) { - return thing->getItem(); + if (index >= 0 && index < static_cast(items->size())) { + if (const auto &thing = getThing(index)) { + if (auto thingItem = thing->getItem()) { + return thingItem; + } + } } - return nullptr; + if (auto topDownItem = getTopDownItem()) { + return topDownItem; + } + + for (auto it = items->rbegin(), end = items->rend(); it != end; ++it) { + if ((*it)->getDoor()) { + return (*it)->getItem(); + } + } + + return !items->empty() ? *items->begin() : nullptr; } std::shared_ptr Tile::getDoorItem() const {