Fix Inventory::moveItemSomewhere()
authorsfan5 <sfan5@live.de>
Tue, 3 Sep 2019 14:36:46 +0000 (16:36 +0200)
committersfan5 <sfan5@live.de>
Tue, 3 Sep 2019 18:16:36 +0000 (20:16 +0200)
src/inventory.cpp

index 2a7c32a44dc2d53f99d0f957a79ddc781e8d2d26..26e6eaa73c46fa1be52abaf62023a7bb87a1b152 100644 (file)
@@ -717,27 +717,13 @@ void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count)
        if (item1.empty())
                return;
 
-       // Try to add the item to destination list
-       u32 dest_size = dest->getSize();
-       // 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;
-               }
-       }
+       ItemStack leftover;
+       leftover = dest->addItem(item1);
 
-       // Then try all the empty ones
-       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;
-               }
+       if (!leftover.empty()) {
+               // Add the remaining part back to the source item
+               addItem(i, leftover);
        }
-
-       // 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,