#include "common_irrlicht.h"
#include "debug.h"
#include "mapblockobject.h"
-// For g_materials
-#include "main.h"
+#include "main.h" // For g_materials
+#include "mapnode.h" // For content_t
#define QUANTITY_ITEM_MAX_COUNT 99
class ServerActiveObject;
class ServerEnvironment;
+class Player;
class InventoryItem
{
virtual std::string getText() { return ""; }
// Creates an object from the item, to be placed in the world.
virtual ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos);
+ // Gets amount of items that dropping one SAO will decrement
+ virtual u16 getDropCount() const { return getCount(); }
/*
Quantity methods
*/
// Shall return true if the item can be add()ed to the other
- virtual bool addableTo(InventoryItem *other)
+ virtual bool addableTo(const InventoryItem *other) const
{
return false;
}
- u16 getCount()
+ u16 getCount() const
{
return m_count;
}
m_count = count;
}
// This should return something else for stackable items
- virtual u16 freeSpace()
+ virtual u16 freeSpace() const
{
return 0;
}
/*
Other properties
*/
+
// Whether it can be cooked
- virtual bool isCookable(){return false;}
+ virtual bool isCookable() const {return false;}
// Time of cooking
virtual float getCookTime(){return 3.0;}
- // Result of cooking
- virtual InventoryItem *createCookResult(){return NULL;}
+ // Result of cooking (can randomize)
+ virtual InventoryItem *createCookResult() const {return NULL;}
+
+ // Eat, press, activate, whatever.
+ // Called when item is right-clicked when lying on ground.
+ // If returns true, item shall be deleted.
+ virtual bool use(ServerEnvironment *env,
+ Player *player){return false;}
protected:
u16 m_count;
class MaterialItem : public InventoryItem
{
public:
- MaterialItem(u8 content, u16 count):
+ MaterialItem(content_t content, u16 count):
InventoryItem(count)
{
m_content = content;
virtual void serialize(std::ostream &os)
{
//os.imbue(std::locale("C"));
- os<<getName();
+ os<<"MaterialItem2";
os<<" ";
os<<(unsigned int)m_content;
os<<" ";
return os.str();
}
- virtual bool addableTo(InventoryItem *other)
+ virtual bool addableTo(const InventoryItem *other) const
{
if(std::string(other->getName()) != "MaterialItem")
return false;
return false;
return true;
}
- u16 freeSpace()
+ u16 freeSpace() const
{
if(m_count > QUANTITY_ITEM_MAX_COUNT)
return 0;
/*
Other properties
*/
- bool isCookable();
- InventoryItem *createCookResult();
+ bool isCookable() const;
+ InventoryItem *createCookResult() const;
/*
Special methods
*/
- u8 getMaterial()
+ content_t getMaterial()
{
return m_content;
}
private:
- u8 m_content;
+ content_t m_content;
};
//TODO: Remove
}
ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos);
+ u16 getDropCount() const;
- virtual bool addableTo(InventoryItem *other)
+ virtual bool addableTo(const InventoryItem *other) const
{
if(std::string(other->getName()) != "CraftItem")
return false;
return false;
return true;
}
- u16 freeSpace()
+ u16 freeSpace() const
{
if(m_count > QUANTITY_ITEM_MAX_COUNT)
return 0;
return QUANTITY_ITEM_MAX_COUNT - m_count;
}
+
/*
Other properties
*/
- bool isCookable();
- InventoryItem *createCookResult();
+
+ bool isCookable() const;
+ InventoryItem *createCookResult() const;
+
+ bool use(ServerEnvironment *env, Player *player);
+
/*
Special methods
*/
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";
os<<basename<<"^[progressbar"<<value_f;
return g_texturesource->getTextureRaw(os.str());
-
- /*TextureSpec spec;
- spec.addTid(g_irrlicht->getTextureId(basename));
- spec.addTid(g_irrlicht->getTextureId(os.str()));
- return g_irrlicht->getTexture(spec);*/
}
#endif
std::string getText()
InventoryList(const InventoryList &other);
InventoryList & operator = (const InventoryList &other);
- std::string getName();
+ const std::string &getName() const;
u32 getSize();
// Count used slots
u32 getUsedSlots();
void setDirty(bool dirty=true){ m_dirty = dirty; }*/
// Get pointer to item
+ const InventoryItem * getItem(u32 i) const;
InventoryItem * getItem(u32 i);
// Returns old item (or NULL). Parameter can be NULL.
InventoryItem * changeItem(u32 i, InventoryItem *newitem);
InventoryList * addList(const std::string &name, u32 size);
InventoryList * getList(const std::string &name);
+ const InventoryList * getList(const std::string &name) const;
bool deleteList(const std::string &name);
// A shorthand for adding items.
// Returns NULL if the item was fully added, leftover otherwise.
private:
// -1 if not found
- s32 getListIndex(const std::string &name);
+ const s32 getListIndex(const std::string &name) const;
core::array<InventoryList*> m_lists;
};
{}
};
-class InventoryAction;
+struct InventoryAction;
class InventoryManager
{
{
}
- bool checkItem(InventoryItem *item);
+ bool checkItem(const InventoryItem *item) const;
};
/*
items: a pointer to an array of 9 pointers to items
specs: a pointer to an array of 9 ItemSpecs
*/
-bool checkItemCombination(InventoryItem **items, ItemSpec *specs);
+bool checkItemCombination(const InventoryItem * const*items, const ItemSpec *specs);
#endif