diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-24 22:10:02 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-24 22:10:02 +0100 |
commit | d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3 (patch) | |
tree | 081556c8fa27ce16372b1657e469ccd8587dd4e5 /src/resources/itemdb.h | |
parent | f663f5bbb75b850ae22f451a22d112b6c62b2ad6 (diff) | |
download | mana-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.gz mana-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.bz2 mana-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.tar.xz mana-d055bee5e6b45737ab89b3f8c70c6d0db7a22eb3.zip |
Refactored the item loading in a more extensible and per protocol way.
This will greatly help into upgrading the need of
each protocol separately.
This is the first step to a new item and equipment system for manaserv.
A subclassing of the EquipmentWindow will be done in the next commit,
as requested by Thorbjorn.
Reviewed-by: Thorbjorn.
Diffstat (limited to 'src/resources/itemdb.h')
-rw-r--r-- | src/resources/itemdb.h | 152 |
1 files changed, 131 insertions, 21 deletions
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 9109898b..e80f2cd0 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -33,24 +33,59 @@ class ItemInfo; class SpriteDisplay; +// Used to make the compiler uderstand the iteminfo friendship. +namespace TmwAthena { class TaItemDB; }; +namespace ManaServ { class ManaServItemDB; }; + +/** + * Nano-description functions + */ +class ItemStat +{ + friend class ItemDB; + friend class TmwAthena::TaItemDB; + friend class ManaServ::ManaServItemDB; + + public: + ItemStat(const std::string &tag, + const std::string &format): + mTag(tag), mFormat(format) {} + + bool operator ==(std::string &name) const + { return mTag == name; } + + private: + std::string mTag; + std::string mFormat; +}; + +// Used to set nano-description +static std::list<ItemStat> extraStats; +void setStatsList(const std::list<ItemStat> &stats); + /** - * Item information database. + * Item information database generic definition. */ class ItemDB { public: - ItemDB() : mLoaded(false) { load(); } + ItemDB() : + mUnknown(0), + mLoaded(false) + {} + + ~ItemDB() + {} - ~ItemDB() { unload(); } /** * Loads the item data from <code>items.xml</code>. */ - void load(); + virtual void load() = 0; /** * Frees item data. */ - void unload(); + virtual void unload(); /** * Tells whether the item database is loaded. @@ -63,26 +98,42 @@ class ItemDB const ItemInfo &get(int id); const ItemInfo &get(const std::string &name); - class Stat - { - public: - Stat(const std::string &tag, - const std::string &format): - tag(tag), format(format) {} + protected: + /** + * Permits to load item definitions which are common + * for each protocols to avoid code duplication. + */ + void loadCommonRef(ItemInfo *itemInfo, xmlNodePtr node); - bool operator ==(std::string &name) const { return tag == name; } + /** + * Checks the items parameters consistency. + */ + virtual void checkItemInfo(ItemInfo* itemInfo); - private: - std::string tag; - std::string format; - friend class ItemDB; - }; + /** + * Register the item to mItemInfos and mNamedItemsInfos + */ + void addItem(ItemInfo *itemInfo); - void setStatsList(const std::list<Stat> &stats); + // Default unknown reference + ItemInfo *mUnknown; + + bool mLoaded; private: + /** + * Loads the sprite references contained in a <sprite> tag. + */ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); - void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); + + /** + * Loads the sound references contained in a <sound> tag. + */ + void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); + + /** + * Loads the floor item references contained in a <floor> tag. + */ void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node); // Items database @@ -91,10 +142,69 @@ class ItemDB ItemInfos mItemInfos; NamedItemInfos mNamedItemInfos; - ItemInfo *mUnknown; - bool mLoaded; }; +namespace TmwAthena { + +class TaItemInfo; + +/** + * Item information database TmwAthena specific class. + */ +class TaItemDB: public ItemDB +{ + public: + TaItemDB() : ItemDB() + { load(); } + + ~TaItemDB() + { unload(); } + + /** + * Loads the item data from <code>items.xml</code>. + */ + void load(); + + private: + /** + * Check items id specific hard limits and log errors found. + * TODO: Do it. + */ + void checkHairWeaponsRacesSpecialIds() + {} + + void checkItemInfo(ItemInfo* itemInfo); +}; + +}; // namespace TmwAthena + +namespace ManaServ { + +class ManaServItemInfo; + +/** + * Item information database TmwAthena specific class. + */ +class ManaServItemDB: public ItemDB +{ + public: + ManaServItemDB() : ItemDB() + { load(); } + + ~ManaServItemDB() + { unload(); } + + /** + * Loads the item data from <code>items.xml</code>. + */ + void load(); + + private: + void checkItemInfo(ItemInfo* itemInfo); +}; + +}; // namespace ManaServ + extern ItemDB *itemDb; #endif |