/* 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::vector 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 server update * This is a client-side property and shoul not be used server-side */ inline const unsigned long timestamp() const { return inventory_timestamp; } /** * @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; /* ---- mutators --------------------------------------------------- */ /** * @brief add an item to the inventory */ void add(Item *item); /** * @brief remove an item from the inventory and delete it */ void remove(Item *item); /** * @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 when inventory was last updated unsigned long inventory_timestamp; // 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__