/* core/item.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CORE_ITEM_H__ #define __INCLUDED_CORE_ITEM_H__ #include "core/info.h" namespace core { /** * @brief an item in the inventory of an entity * The info record represents the type of the item */ class Item { public: /** * @brief item flags indicating special properties * Tradeable (reserved) * Unique indicates a unique item * Unrestricted can be sold everywhere (e.g. cargo) * Mountable indicate the item can be mounted in a slot * Mounted indicates the item is mounted in a slot * */ enum Flags {Tradeable = 1, Unique = 2, Unrestricted = 4, Mountable = 8, Mounted = 16}; Item(const Info *info); ~Item(); /* ---- inspectors --------------------------------------------- */ /** * @brief returns the item id * */ inline unsigned int id() const { return item_id; } /** * @brief associated amount */ inline long amount() const { return item_amount; } /** * @brief information record */ inline const Info *info() const { return item_info; } /** * @brief price */ inline const long price() const { return item_price; } /** * @brief server timestamp */ inline const unsigned long timestamp() const { return item_timestamp; } /** * @brief item flags */ inline const unsigned int flags() const { return item_flags; } /** * @brief returns true of a flag is set */ inline const bool has_flag(const Flags flag) const { return ((item_flags & (unsigned int) flag) == (unsigned int) flag); } /** * @brief returns true if the Unique flag is set */ inline const bool unique() const { return ((item_flags & (unsigned int) Unique) == (unsigned int) Unique); } /** * @brief returns true if the Unrestricted flag is set */ inline const bool unrestricted() const { return ((item_flags & (unsigned int) Unrestricted) == (unsigned int) Unrestricted); } /** * @brief return true if the dirty flag is set * */ inline const bool dirty() const { return item_dirty; } /* ---- mutators ----------------------------------------------- */ /** * @brief set item id * This should never be called from within the game module, * it is used by Inventory to keep track of unique items */ void set_id(const unsigned int id); /** * @brief set item info * This should never be called from within the game module, * it essentially changes the item type and is used by NetConnection * for inventory householding. */ void set_info(const Info *info); /** * @brief set associated amount */ void set_amount(const long amount); /** * @brief increase associated amount */ void inc_amount(const long amount); /** * @brief decrease associated amount */ void dec_amount(const long amount); /** * @brief set associated price */ void set_price(const long price); /** * @brief set all item flags */ void set_flags(const unsigned int flags); /** * @brief set item flag */ void set_flag(Flags flag); /** * @brief unset item flag */ void unset_flag(Flags flag); /** * @brief set the dirty flag * */ inline void set_dirty(const bool dirty = true) { item_dirty = dirty; } /* ---- serializers -------------------------------------------- */ void serialize_server_update(std::ostream & os) const; void receive_server_update(std::istream &is); private: void set_timestamp(const unsigned long timestamp); const Info *item_info; long item_price; long item_amount; unsigned long item_timestamp; unsigned int item_flags; bool item_dirty; unsigned int item_id; }; } // namespace core #endif // __INCLUDED_CORE_ITEM_H__