summaryrefslogtreecommitdiff
path: root/src/inventory.cpp
diff options
context:
space:
mode:
authorJacobF <queatz@gmail.com>2011-08-25 19:27:50 -0400
committerJacobF <queatz@gmail.com>2011-08-25 19:27:50 -0400
commit134e49cc8e442e582608411832363e15f68ea6eb (patch)
tree3da141aefcfd33680f40b95f66ee99a31543c353 /src/inventory.cpp
parentefd8dabd913b2d1a0564378c30ae86c7a5081f06 (diff)
downloadminetest-134e49cc8e442e582608411832363e15f68ea6eb.tar.gz
minetest-134e49cc8e442e582608411832363e15f68ea6eb.tar.bz2
minetest-134e49cc8e442e582608411832363e15f68ea6eb.zip
Merged 2 branches because they relied on each other.
This one contains these changes from main c55: * Adds a function to check if there is room for a specific item * Using that, you can now pick up rats if you have a full inventory and a not full rat stack * Furnace would cook only 1 item if that item used the last available result slot, now it will continue * Furnace will say it's overloaded * Furnace won't wait until the next step to start on the next item - This caused small fuels to cook slower than meant to - Also caused furnaces to say they were out of fuel after finishing the last fuel item
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp24
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)