diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-08-30 14:24:07 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-08-30 14:24:07 +0300 |
commit | 87b9e5467d50ba243e4b0cb63f6be206ef107f7b (patch) | |
tree | 4b869ce85509c1c1ba7ac666c92588a3716b9e68 /src/inventory.cpp | |
parent | 625dac8d8c84e8952fb9bf3f80c8efed7b2b4fa0 (diff) | |
parent | 134e49cc8e442e582608411832363e15f68ea6eb (diff) | |
download | minetest-87b9e5467d50ba243e4b0cb63f6be206ef107f7b.tar.gz minetest-87b9e5467d50ba243e4b0cb63f6be206ef107f7b.tar.bz2 minetest-87b9e5467d50ba243e4b0cb63f6be206ef107f7b.zip |
Merge remote-tracking branch 'queatz/furnace-is-not-out-nor-can-rat-escape'
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 1ee63819d..62aedb536 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -549,7 +549,7 @@ InventoryItem * InventoryList::addItem(u32 i, InventoryItem *newitem) } } -bool InventoryList::itemFits(u32 i, InventoryItem *newitem) +bool InventoryList::itemFits(const u32 i, const InventoryItem *newitem) { // If it is an empty position, it's an easy job. const InventoryItem *to_item = getItem(i); @@ -558,11 +558,11 @@ bool InventoryList::itemFits(u32 i, InventoryItem *newitem) return true; } - // If not addable, return the item + // If not addable, fail if(newitem->addableTo(to_item) == false) return false; - // If the item fits fully in the slot, add counter and delete it + // If the item fits fully in the slot, pass if(newitem->getCount() <= to_item->freeSpace()) { return true; @@ -571,6 +571,24 @@ bool InventoryList::itemFits(u32 i, InventoryItem *newitem) return false; } +bool InventoryList::roomForItem(const InventoryItem *item) +{ + for(u32 i=0; i<m_items.size(); i++) + if(itemFits(i, item)) + return true; + return false; +} + +bool InventoryList::roomForCookedItem(const InventoryItem *item) +{ + const InventoryItem *cook = item->createCookResult(); + if(!cook) + return false; + bool room = roomForItem(cook); + delete cook; + return room; +} + InventoryItem * InventoryList::takeItem(u32 i, u32 count) { if(count == 0) |