Skip to content

Commit

Permalink
Update tile.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleohanopahala authored Jan 10, 2025
1 parent 3ac0bab commit e1efe05
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/items/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,11 +1876,25 @@ std::shared_ptr<Item> Tile::getUseItem(int32_t index) const {
return ground;
}

if (const auto &thing = getThing(index)) {
return thing->getItem();
if (index >= 0 && index < static_cast<int32_t>(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<Item> Tile::getDoorItem() const {
Expand Down

0 comments on commit e1efe05

Please sign in to comment.