Skip to content

Commit

Permalink
Fix Inventory::moveItemSomewhere()
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Sep 3, 2019
1 parent f3acdd3 commit 4582691
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/inventory.cpp
Expand Up @@ -717,27 +717,13 @@ void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count)
if (item1.empty()) if (item1.empty())
return; return;


// Try to add the item to destination list ItemStack leftover;
u32 dest_size = dest->getSize(); leftover = dest->addItem(item1);
// First try all the non-empty slots
for (u32 dest_i = 0; dest_i < dest_size; dest_i++) {
if (!m_items[dest_i].empty()) {
item1 = dest->addItem(dest_i, item1);
if (item1.empty()) return;
}
}


// Then try all the empty ones if (!leftover.empty()) {
for (u32 dest_i = 0; dest_i < dest_size; dest_i++) { // Add the remaining part back to the source item
if (m_items[dest_i].empty()) { addItem(i, leftover);
item1 = dest->addItem(dest_i, item1);
if (item1.empty()) return;
}
} }

// If we reach this, the item was not fully added
// Add the remaining part back to the source item
addItem(i, item1);
} }


u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i,
Expand Down

0 comments on commit 4582691

Please sign in to comment.