summaryrefslogtreecommitdiff
path: root/src/inventory.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-11-28 14:55:24 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-11-29 19:13:57 +0200
commite880cc40e98e7eedd7e8b51810cbc0348fff4a6f (patch)
tree6ffdb5565fe4e68e4d366d965350a4cbc9fe0b0e /src/inventory.cpp
parent7bb4b7911b4ae81b8577d34eb18231978e416d1d (diff)
downloadminetest-e880cc40e98e7eedd7e8b51810cbc0348fff4a6f.tar.gz
minetest-e880cc40e98e7eedd7e8b51810cbc0348fff4a6f.tar.bz2
minetest-e880cc40e98e7eedd7e8b51810cbc0348fff4a6f.zip
Fix stuff in inventory.{cpp,h}
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index f3b81090b..4e897d9ff 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -168,6 +168,13 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is, IGameDef *gamedef)
}
}
+InventoryItem* InventoryItem::deSerialize(const std::string &str,
+ IGameDef *gamedef)
+{
+ std::istringstream is(str, std::ios_base::binary);
+ return deSerialize(is, gamedef);
+}
+
std::string InventoryItem::getItemString() {
// Get item string
std::ostringstream os(std::ios_base::binary);
@@ -535,21 +542,22 @@ u32 InventoryList::getFreeSlots()
const InventoryItem * InventoryList::getItem(u32 i) const
{
- if(i > m_items.size() - 1)
+ if(i >= m_items.size())
return NULL;
return m_items[i];
}
InventoryItem * InventoryList::getItem(u32 i)
{
- if(i > m_items.size() - 1)
+ if(i >= m_items.size())
return NULL;
return m_items[i];
}
InventoryItem * InventoryList::changeItem(u32 i, InventoryItem *newitem)
{
- assert(i < m_items.size());
+ if(i >= m_items.size())
+ return newitem;
InventoryItem *olditem = m_items[i];
m_items[i] = newitem;
@@ -606,6 +614,8 @@ InventoryItem * InventoryList::addItem(u32 i, InventoryItem *newitem)
{
if(newitem == NULL)
return NULL;
+ if(i >= m_items.size())
+ return newitem;
//setDirty(true);
@@ -853,6 +863,16 @@ InventoryList * Inventory::getList(const std::string &name)
return m_lists[i];
}
+bool Inventory::deleteList(const std::string &name)
+{
+ s32 i = getListIndex(name);
+ if(i == -1)
+ return false;
+ delete m_lists[i];
+ m_lists.erase(i);
+ return true;
+}
+
const InventoryList * Inventory::getList(const std::string &name) const
{
s32 i = getListIndex(name);