Planeshift

psinventorycache.h

Go to the documentation of this file.
00001 
00019 #ifndef PS_INVENTORY_CACHE
00020 #define PS_INVENTORY_CACHE
00021 
00022 #include "util/pscache.h"
00023 
00027 class psInventoryCache : public psCache
00028 {
00029 public:
00030     psInventoryCache();
00031     ~psInventoryCache();
00032 
00033     struct CachedItemDescription
00034     {
00035         int slot;
00036         int containerID;
00037         csString name;
00038         csString meshName;
00039         csString materialName;
00040         float weight;
00041         float size;
00042         int stackCount;
00043         csString iconImage;
00044         int purifyStatus;
00045 
00046         static int CompareSlot(CachedItemDescription* const &first, CachedItemDescription* const &second);
00047     };
00048 
00057     bool GetInventory (void);
00058 
00074     bool SetInventoryItem(int slot,
00075                           int containerID,
00076                           csString name,
00077                           csString meshName,
00078                           csString materialName,
00079                           float weight,
00080                           float size,
00081                           int stackCount,
00082                           csString iconImage,
00083                           int purifyStatus);
00084 
00092     bool EmptyInventoryItem(int slot, int container);
00093 
00097     void EmptyInventory(void);
00098 
00106     bool MoveItem(int from_containerID, int from_slot,
00107                   int to_containerID, int to_slot, int stackCount);
00108 
00114     CachedItemDescription* GetInventoryItem(int slot);
00115 
00118     inline uint32 GetInventoryVersion() const
00119     {
00120         return version;
00121     }
00122 
00125     inline void SetInventoryVersion(uint32 ver)
00126     {
00127         version = ver;
00128     }
00129 
00130 
00134     csHash<CachedItemDescription*>::GlobalIterator GetHashIterator()
00135     {
00136         return itemhash.GetIterator();
00137     }
00138 
00142     csArray<CachedItemDescription*>::Iterator GetSortedIterator()
00143     {
00144         return itemBySlot.GetIterator();
00145     }
00146 
00147 private:
00148 
00149     csHash<CachedItemDescription*> itemhash;  // all cached items in equip, bulk or containers
00150 
00151     csArray<CachedItemDescription*> itemBySlot; // all cached items sorted by slot number
00152 
00153     // CachedItemDescription bulkItems[INVENTORY_BULK_COUNT];    /// cached bulk items
00154     // CachedItemDescription equipItems[INVENTORY_EQUIP_COUNT];  /// cached equip items
00155 
00156     uint32 version; // Current cache version (PS#2691)
00157 };
00158 
00159 #endif
00160