diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-30 00:11:35 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-30 00:11:35 +0300 |
commit | 1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b (patch) | |
tree | de98074d774b203053c4215a49764837a3b007ed /src/inventory.cpp | |
parent | 598de45a1e77e5f10c69694f607941336163673f (diff) | |
download | mv-1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b.tar.gz mv-1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b.tar.bz2 mv-1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b.tar.xz mv-1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b.zip |
Allow add item by drag&drop into npc inventory to exact position.
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index eecaacd6c..c91a7411a 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -362,24 +362,42 @@ int Inventory::findIndexByTag(const int tag) const return -1; } -void Inventory::addVirtualItem(const Item *const item) +void Inventory::addVirtualItem(const Item *const item, + int index) { if (item && !PlayerInfo::isItemProtected(item->getId())) { if (findIndexByTag(item->getInvIndex()) != -1) return; - const int index = addItem(item->getId(), - item->getType(), - 1, - 1, - item->getColor(), - item->getIdentified(), - item->getDamaged(), - item->getFavorite(), - Equipm_false, - Equipped_false); - Item *const item2 = getItem(index); + if (index >= 0 && index < mSize && mItems[index] == nullptr) + { + setItem(index, + item->getId(), + item->getType(), + 1, + 1, + item->getColor(), + item->getIdentified(), + item->getDamaged(), + item->getFavorite(), + Equipm_false, + Equipped_false); + } + else + { + index = addItem(item->getId(), + item->getType(), + 1, + 1, + item->getColor(), + item->getIdentified(), + item->getDamaged(), + item->getFavorite(), + Equipm_false, + Equipped_false); + } + Item *const item2 = getItem(index); if (item2) item2->setTag(item->getInvIndex()); } |