/* core/inventory.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_INVENTORY_H__ #define __INCLUDED_CORE_INVENTORY_H__ #include "core/item.h" #include namespace core { /** * @brief an entity inventory */ class Inventory { public: /** * @brief type definition for items in the inventory */ typedef std::list Items; /** * @brief default constructor */ Inventory(const float capacity = 0); /** * @brief default destructor */ ~Inventory(); /* ---- inspectors ------------------------------------------------- */ /** * @brief items in the inventory */ inline Items &items() { return inventory_items; }; /** * @brief return the timestamp of the last client-side update * This is a client-side property */ inline const unsigned long timestamp() const { return inventory_timestamp; } /** * @brief return the timestamp of the last item erase * */ inline const unsigned long timestamp_erase() const { return inventory_timestamp_erase; } /** * @brief return the maximal inventory capacity, in cubic meters */ inline const float capacity() const { return inventory_capacity; } /** * @brief return the used inventory capacity, in cubic meters */ inline const float capacity_used() const { return inventory_capacity_used; } /** * @brief return the available inventory capacity, in cubic meters */ inline const float capacity_available() const { return inventory_capacity - inventory_capacity_used; } inline const bool dirty() const { return inventory_dirty; } /** * @brief returns the number of units of an item that can be stored in this inventory * @param credits number of player credits, limits the amount * @param price price of a single unit * @param volume volume of a single unit */ const long max_amount(const long credits, const long price, const float volume) const; /** * @brief search the inventory for a specific item type */ Item *find(const Info *info) const; /** * @brief search the inventory for a specific item id */ Item *find(const unsigned int id) const; /** * @brief search the inventory for a specific item */ Item *find(Item *item) const; /* ---- mutators --------------------------------------------------- */ /** * @brief add an item to the inventory */ void add(Item *item); /** * @brief erase an item from the inventory * This will call the Item's destructor */ void erase(Item *item); void erase(const unsigned int id); /** * @brief removes all items from the inventory and delete them */ void clear(); /** * @brief set the timestamp */ void set_timestamp(const unsigned long timestamp); /** * @brief mark the inventory as dirty */ void set_dirty(const bool dirty = true); /** * @brief set the maximal inventory capacity, in cubic meters */ void set_capacity(const float capacity); /// recalculate inventory capacity void recalculate(); /// serialize a server-to-client update on a stream void serialize_server_update(std::ostream & os) const; /// receive a server-to-client update from a stream void receive_server_update(std::istream &is); private: // items in the inventory Items inventory_items; // timestamp, last time the inventory was updated unsigned long inventory_timestamp; // timestamp, last time there was an item deleted from the inventory unsigned long inventory_timestamp_erase; // maximum inventory capacity, in cubic meters float inventory_capacity; // current capacity used, in cubic meters float inventory_capacity_used; bool inventory_dirty; }; } // namsepace core #endif // __INCLUDED_CORE_INVENTORY_H__