diff --git a/src/game.cpp b/src/game.cpp index 0344956df6..b70c3f76e6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1196,22 +1196,23 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, } } - Item* moveItem = nullptr; - - // remove the item + Item_ptr moveItem = item; int32_t itemIndex = fromCylinder->getThingIndex(item); - Item* updateItem = nullptr; - fromCylinder->removeThing(item, moveCount); + Item_ptr updateItem = nullptr; + //update item(s) if (item->isStackable()) { // lets find out how much we need to move uint32_t allowedCount = 0; - if (item->equals(toItem)) { - allowedCount = std::min(ITEM_STACK_SIZE - toItem->getItemCount(), moveCount); + // when item is moved onto another equal item + if (item->equals(toItem) && moveCount != MAX_ITEM_COUNT) { + allowedCount = std::min(static_cast(MAX_ITEM_COUNT) - toItem->getItemCount(), moveCount); if (allowedCount > 0) { + fromCylinder->removeThing(item, allowedCount); toCylinder->updateThing(toItem, toItem->getID(), toItem->getItemCount() + allowedCount); updateItem = toItem; + moveItem = nullptr; } } @@ -1222,27 +1223,21 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, moveItem = item->clone(); moveItem->setItemCount(newCount); - // source item may get deleted if move count is actually the whole source count, so let's release it if - // needed if (item->isRemoved()) { - ReleaseItem(item); + item->onRemoved(); } - } else { - // whole source item is moved - moveItem = item; } } - } else { - moveItem = item; } - // add item + //add item if (moveItem) { + fromCylinder->removeThing(item, moveCount); toCylinder->addThing(index, moveItem); } - if (itemIndex != -1 && !item->hasParent()) { - fromCylinder->postRemoveNotification(item, toCylinder, itemIndex); + if (itemIndex != -1) { + fromCylinder->postRemoveNotification(item, toCylinder, itemIndex, LINK_OWNER, actorPlayer); } if (moveItem) {