+/*
+ An item that is used as a mid-product when crafting.
+ Subnames:
+ - Stick
+*/
+class CraftItem : public InventoryItem
+{
+public:
+ CraftItem(std::string subname, u16 count):
+ InventoryItem(count)
+ {
+ m_subname = subname;
+ }
+ /*
+ Implementation interface
+ */
+ virtual const char* getName() const
+ {
+ return "CraftItem";
+ }
+ virtual void serialize(std::ostream &os)
+ {
+ os<<getName();
+ os<<" ";
+ os<<m_subname;
+ os<<" ";
+ os<<m_count;
+ }
+ virtual InventoryItem* clone()
+ {
+ return new CraftItem(m_subname, m_count);
+ }
+#ifndef SERVER
+ video::ITexture * getImage();
+#endif
+ std::string getText()
+ {
+ std::ostringstream os;
+ os<<m_count;
+ return os.str();
+ }
+
+ ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos);
+ u16 getDropCount();
+
+ virtual bool addableTo(InventoryItem *other)
+ {
+ if(std::string(other->getName()) != "CraftItem")
+ return false;
+ CraftItem *m = (CraftItem*)other;
+ if(m->m_subname != m_subname)
+ return false;
+ return true;
+ }
+ u16 freeSpace()
+ {
+ if(m_count > QUANTITY_ITEM_MAX_COUNT)
+ return 0;
+ return QUANTITY_ITEM_MAX_COUNT - m_count;
+ }
+ /*
+ Other properties
+ */
+ bool isCookable();
+ InventoryItem *createCookResult();
+ /*
+ Special methods
+ */
+ std::string getSubName()
+ {
+ return m_subname;
+ }
+private:
+ std::string m_subname;
+};
+
+class ToolItem : public InventoryItem
+{
+public:
+ ToolItem(std::string toolname, u16 wear):
+ InventoryItem(1)
+ {
+ m_toolname = toolname;
+ m_wear = wear;
+ }
+ /*
+ Implementation interface
+ */
+ virtual const char* getName() const
+ {
+ return "ToolItem";
+ }
+ virtual void serialize(std::ostream &os)
+ {
+ os<<getName();
+ os<<" ";
+ os<<m_toolname;
+ os<<" ";
+ os<<m_wear;
+ }
+ virtual InventoryItem* clone()
+ {
+ return new ToolItem(m_toolname, m_wear);
+ }
+#ifndef SERVER
+ video::ITexture * getImage()
+ {
+ if(g_texturesource == NULL)
+ return NULL;
+
+ std::string basename;
+ if(m_toolname == "WPick")
+ basename = "tool_woodpick.png";
+ else if(m_toolname == "STPick")
+ basename = "tool_stonepick.png";
+ else if(m_toolname == "SteelPick")
+ basename = "tool_steelpick.png";
+ else if(m_toolname == "MesePick")
+ basename = "tool_mesepick.png";
+ else if(m_toolname == "WShovel")
+ basename = "tool_woodshovel.png";
+ else if(m_toolname == "STShovel")
+ basename = "tool_stoneshovel.png";
+ else if(m_toolname == "SteelShovel")
+ basename = "tool_steelshovel.png";
+ else if(m_toolname == "WAxe")
+ basename = "tool_woodaxe.png";
+ else if(m_toolname == "STAxe")
+ basename = "tool_stoneaxe.png";
+ else if(m_toolname == "SteelAxe")
+ basename = "tool_steelaxe.png";
+ else if(m_toolname == "WSword")
+ basename = "tool_woodsword.png";
+ else if(m_toolname == "STSword")
+ basename = "tool_stonesword.png";
+ else if(m_toolname == "SteelSword")
+ basename = "tool_steelsword.png";
+ else
+ basename = "cloud.png";
+
+ /*
+ Calculate a progress value with sane amount of
+ maximum states
+ */
+ u32 maxprogress = 30;
+ u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
+
+ float value_f = (float)toolprogress / (float)maxprogress;
+ std::ostringstream os;
+ os<<basename<<"^[progressbar"<<value_f;
+
+ return g_texturesource->getTextureRaw(os.str());
+ }
+#endif
+ std::string getText()
+ {
+ return "";
+
+ /*std::ostringstream os;
+ u16 f = 4;
+ u16 d = 65535/f;
+ u16 i;
+ for(i=0; i<(65535-m_wear)/d; i++)
+ os<<'X';
+ for(; i<f; i++)
+ os<<'-';
+ return os.str();*/
+
+ /*std::ostringstream os;
+ os<<m_toolname;
+ os<<" ";
+ os<<(m_wear/655);
+ return os.str();*/
+ }
+ /*
+ Special methods
+ */
+ std::string getToolName()
+ {
+ return m_toolname;
+ }
+ u16 getWear()
+ {
+ return m_wear;
+ }
+ // Returns true if weared out
+ bool addWear(u16 add)
+ {
+ if(m_wear >= 65535 - add)
+ {
+ m_wear = 65535;
+ return true;
+ }
+ else
+ {
+ m_wear += add;
+ return false;
+ }
+ }
+private:
+ std::string m_toolname;
+ u16 m_wear;
+};
+