// Convert old materials
if(material <= 0xff)
material = content_translate_from_19_to_internal(material);
- if(material > MAX_CONTENT)
+ if(material > 0xfff)
throw SerializationError("Too large material number");
// Convert old id to name
NameIdMapping legacy_nimap;
is>>material;
u16 materialcount;
is>>materialcount;
- if(material > MAX_CONTENT)
+ if(material > 0xfff)
throw SerializationError("Too large material number");
// Convert old id to name
NameIdMapping legacy_nimap;
return *this;
}
-bool InventoryList::operator == (const InventoryList &other)
+bool InventoryList::operator == (const InventoryList &other) const
{
if(m_size != other.m_size)
return false;
void Inventory::clear()
{
+ m_dirty = true;
for(u32 i=0; i<m_lists.size(); i++)
{
delete m_lists[i];
void Inventory::clearContents()
{
+ m_dirty = true;
for(u32 i=0; i<m_lists.size(); i++)
{
InventoryList *list = m_lists[i];
Inventory::Inventory(IItemDefManager *itemdef)
{
+ m_dirty = false;
m_itemdef = itemdef;
}
Inventory::Inventory(const Inventory &other)
{
*this = other;
+ m_dirty = false;
}
Inventory & Inventory::operator = (const Inventory &other)
// Gracefully handle self assignment
if(this != &other)
{
+ m_dirty = true;
clear();
m_itemdef = other.m_itemdef;
for(u32 i=0; i<other.m_lists.size(); i++)
return *this;
}
-bool Inventory::operator == (const Inventory &other)
+bool Inventory::operator == (const Inventory &other) const
{
if(m_lists.size() != other.m_lists.size())
return false;
for(u32 i=0; i<m_lists.size(); i++)
{
- if(m_lists[i] != other.m_lists[i])
+ if(*m_lists[i] != *other.m_lists[i])
return false;
}
return true;
}
else
{
- throw SerializationError("invalid inventory specifier");
+ throw SerializationError("invalid inventory specifier: " + name);
}
}
}
InventoryList * Inventory::addList(const std::string &name, u32 size)
{
+ m_dirty = true;
s32 i = getListIndex(name);
if(i != -1)
{
}
else
{
+ //don't create list with invalid name
+ if (name.find(" ") != std::string::npos) return NULL;
+
InventoryList *list = new InventoryList(name, size, m_itemdef);
m_lists.push_back(list);
return list;
s32 i = getListIndex(name);
if(i == -1)
return false;
+ m_dirty = true;
delete m_lists[i];
m_lists.erase(m_lists.begin() + i);
return true;