]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/inventory.cpp
Place project name and gettext use in config
[dragonfireclient.git] / src / inventory.cpp
index f9b9107a0e0d860ed2ecb4a17e571c112731abf2..fec51a759e581617db89f43eef9bb494ef82f949 100644 (file)
@@ -27,6 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "debug.h"
 #include <sstream>
 #include "main.h"
+#include "serverobject.h"
+#include "content_mapnode.h"
+#include "content_inventory.h"
+#include "content_sao.h"
 
 /*
        InventoryItem
@@ -90,60 +94,83 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
        }
 }
 
+ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f pos)
+{
+       /*
+               Create an ItemSAO
+       */
+       // Get item string
+       std::ostringstream os(std::ios_base::binary);
+       serialize(os);
+       // Create object
+       ServerActiveObject *obj = new ItemSAO(env, 0, pos, os.str());
+       return obj;
+}
+
 /*
        MaterialItem
 */
 
 bool MaterialItem::isCookable()
 {
-       if(m_content == CONTENT_TREE)
-       {
-               return true;
-       }
-       else if(m_content == CONTENT_COBBLE)
-       {
-               return true;
-       }
-       return false;
+       return item_material_is_cookable(m_content);
 }
 
 InventoryItem *MaterialItem::createCookResult()
 {
-       if(m_content == CONTENT_TREE)
-       {
-               return new CraftItem("lump_of_coal", 1);
-       }
-       else if(m_content == CONTENT_COBBLE)
-       {
-               return new MaterialItem(CONTENT_STONE, 1);
-       }
-       return NULL;
+       return item_material_create_cook_result(m_content);
 }
 
 /*
        CraftItem
 */
 
+#ifndef SERVER
+video::ITexture * CraftItem::getImage()
+{
+       if(g_texturesource == NULL)
+               return NULL;
+       
+       std::string name = item_craft_get_image_name(m_subname);
+
+       // Get such a texture
+       return g_texturesource->getTextureRaw(name);
+}
+#endif
+
+ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, u16 id, v3f pos)
+{
+       // Special cases
+       ServerActiveObject *obj = item_craft_create_object(m_subname, env, id, pos);
+       if(obj)
+               return obj;
+       // Default
+       return InventoryItem::createSAO(env, id, pos);
+}
+
+u16 CraftItem::getDropCount()
+{
+       // Special cases
+       s16 dc = item_craft_get_drop_count(m_subname);
+       if(dc != -1)
+               return dc;
+       // Default
+       return InventoryItem::getDropCount();
+}
+
 bool CraftItem::isCookable()
 {
-       if(m_subname == "lump_of_iron")
-       {
-               return true;
-       }
-       return false;
+       return item_craft_is_cookable(m_subname);
 }
 
 InventoryItem *CraftItem::createCookResult()
 {
-       if(m_subname == "lump_of_iron")
-       {
-               return new CraftItem("steel_ingot", 1);
-       }
-       return NULL;
+       return item_craft_create_cook_result(m_subname);
 }
 
 /*
-       MapBlockObjectItem
+       MapBlockObjectItem DEPRECATED
+       TODO: Remove
 */
 #ifndef SERVER
 video::ITexture * MapBlockObjectItem::getImage()
@@ -221,6 +248,7 @@ InventoryList::InventoryList(std::string name, u32 size)
        m_name = name;
        m_size = size;
        clearItems();
+       //m_dirty = false;
 }
 
 InventoryList::~InventoryList()
@@ -246,6 +274,8 @@ void InventoryList::clearItems()
        {
                m_items.push_back(NULL);
        }
+
+       //setDirty(true);
 }
 
 void InventoryList::serialize(std::ostream &os)
@@ -339,6 +369,7 @@ InventoryList & InventoryList::operator = (const InventoryList &other)
                        m_items[i] = item->clone();
                }
        }
+       //setDirty(true);
 
        return *this;
 }
@@ -383,6 +414,7 @@ InventoryItem * InventoryList::changeItem(u32 i, InventoryItem *newitem)
 
        InventoryItem *olditem = m_items[i];
        m_items[i] = newitem;
+       //setDirty(true);
        return olditem;
 }
 
@@ -436,8 +468,10 @@ InventoryItem * InventoryList::addItem(u32 i, InventoryItem *newitem)
        if(newitem == NULL)
                return NULL;
        
+       //setDirty(true);
+       
        // If it is an empty position, it's an easy job.
-       InventoryItem *to_item = m_items[i];
+       InventoryItem *to_item = getItem(i);
        if(to_item == NULL)
        {
                m_items[i] = newitem;
@@ -469,7 +503,7 @@ InventoryItem * InventoryList::addItem(u32 i, InventoryItem *newitem)
 bool InventoryList::itemFits(u32 i, InventoryItem *newitem)
 {
        // If it is an empty position, it's an easy job.
-       InventoryItem *to_item = m_items[i];
+       InventoryItem *to_item = getItem(i);
        if(to_item == NULL)
        {
                return true;
@@ -492,8 +526,10 @@ InventoryItem * InventoryList::takeItem(u32 i, u32 count)
 {
        if(count == 0)
                return NULL;
+       
+       //setDirty(true);
 
-       InventoryItem *item = m_items[i];
+       InventoryItem *item = getItem(i);
        // If it is an empty position, return NULL
        if(item == NULL)
                return NULL;