From 0346e68debc73c20be1220177bab4da8716ae402 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 25 Jul 2012 16:52:00 +0300 Subject: Add special return value -1 to inventry callbacks --- src/inventorymanager.cpp | 56 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'src/inventorymanager.cpp') diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp index 02b887ac2..06978fbb9 100644 --- a/src/inventorymanager.cpp +++ b/src/inventorymanager.cpp @@ -280,19 +280,24 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame L, from_inv.p, from_list, from_i, src_item, player); } } + + int old_count = count; /* Modify count according to collected data */ - int new_count = try_take_count; - if(new_count > src_can_take_count) - new_count = src_can_take_count; - if(new_count > dst_can_put_count) - new_count = dst_can_put_count; + count = try_take_count; + if(src_can_take_count != -1 && count > src_can_take_count) + count = src_can_take_count; + if(dst_can_put_count != -1 && count > dst_can_put_count) + count = dst_can_put_count; + /* Limit according to source item count */ + if(count > list_from->getItem(from_i).count) + count = list_from->getItem(from_i).count; /* If no items will be moved, don't go further */ - if(new_count == 0) + if(count == 0) { - infostream<<"IMoveAction::apply(): move was completely disallowed: " - <<" count="<deleteItem(from_i); + list_from->addItem(from_i, from_stack_was); + } + // If destination is infinite, reset it's stack and take count from source + if(dst_can_put_count == -1){ + list_to->deleteItem(to_i); + list_to->addItem(to_i, to_stack_was); + list_from->takeItem(from_i, count); + } + + infostream<<"IMoveAction::apply(): moved" <<" count="<takeItem(from_i, actually_dropped_count); - // Take item from source list - ItemStack item2 = list_from->takeItem(from_i, actually_dropped_count); + if(item2.count != actually_dropped_count) + errorstream<<"Could not take dropped count of items"<setInventoryModified(from_inv); + mgr->setInventoryModified(from_inv); + } } infostream<<"IDropAction::apply(): dropped " -- cgit v1.2.3