diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/itemdb.cpp | 40 | ||||
-rw-r--r-- | src/resources/itemdb.h | 4 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 11 |
3 files changed, 53 insertions, 2 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 33978192f..a590dcac1 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -42,6 +42,8 @@ namespace ItemDB::NamedItemInfos mNamedItemInfos; ItemInfo *mUnknown; bool mLoaded = false; + std::vector<std::string> mTagNames; + std::map<std::string, int> mTags; } // Forward declarations @@ -149,6 +151,7 @@ void ItemDB::load() if (mLoaded) unload(); + int tagNum = 0; logger->log1("Initializing item database..."); mUnknown = new ItemInfo; @@ -168,6 +171,17 @@ void ItemDB::load() return; } + mTags.clear(); + mTagNames.clear(); + mTagNames.push_back("All"); + mTagNames.push_back("Usable"); + mTagNames.push_back("Unusable"); + mTagNames.push_back("Equipment"); + mTags["All"] = tagNum ++; + mTags["Usable"] = tagNum ++; + mTags["Unusable"] = tagNum ++; + mTags["Equipment"] = tagNum ++; + for_each_xml_child_node(node, rootNode) { if (!xmlStrEqual(node->name, BAD_CAST "item")) @@ -210,6 +224,20 @@ void ItemDB::load() itemInfo->setName(name.empty() ? _("unnamed") : name); itemInfo->setDescription(description); itemInfo->setType(itemTypeFromString(typeStr)); + itemInfo->addTag(mTags["All"]); + switch (itemInfo->getType()) + { + case ITEM_USABLE: + itemInfo->addTag(mTags["Usable"]); + break; + case ITEM_UNUSABLE: + itemInfo->addTag(mTags["Unusable"]); + break; + default: + itemInfo->addTag(mTags["Equipment"]); + break; + } + itemInfo->setView(view); itemInfo->setWeight(weight); itemInfo->setAttackAction(attackAction); @@ -315,6 +343,16 @@ void ItemDB::load() mLoaded = true; } +const std::vector<std::string> &ItemDB::getTags() +{ + return mTagNames; +} + +int ItemDB::getTagId(std::string tagName) +{ + return mTags[tagName]; +} + void ItemDB::unload() { logger->log1("Unloading item database..."); @@ -325,6 +363,8 @@ void ItemDB::unload() delete_all(mItemInfos); mItemInfos.clear(); mNamedItemInfos.clear(); + mTags.clear(); + mTagNames.clear(); mLoaded = false; } diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 76e646c0f..19e36889e 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -23,6 +23,7 @@ #define ITEM_MANAGER_H #include <list> +#include <vector> #include <map> #include <string> @@ -49,6 +50,8 @@ namespace ItemDB */ void unload(); + const std::vector<std::string> &getTags(); + bool exists(int id); const ItemInfo &get(int id); @@ -60,6 +63,7 @@ namespace ItemDB const std::map<int, ItemInfo*> &getItemInfos(); + int getTagId(std::string tagName); struct Stat { Stat(const std::string &tag, diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index bb84193bb..19bba335d 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -207,6 +207,12 @@ class ItemInfo void setDrawPriority(int n) { mDrawPriority = n; } + std::map<int, int> getTags() + { return mTags; } + + void addTag(int tag) + { mTags[tag] = 1; } + protected: SpriteDisplay mDisplay; /**< Display info (like icon) */ std::string mName; @@ -233,10 +239,11 @@ class ItemInfo std::string mMissileParticle; /** Maps gender to sprite filenames. */ - std::map<int, std::string> mAnimationFiles; + std::map <int, std::string> mAnimationFiles; /** Stores the names of sounds to be played at certain event. */ - std::map< EquipmentSoundEvent, std::vector<std::string> > mSounds; + std::map < EquipmentSoundEvent, std::vector<std::string> > mSounds; + std::map <int,int> mTags; }; #endif |