diff options
author | David Athay <ko2fan@gmail.com> | 2009-01-14 14:11:35 +0000 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-01-20 11:04:37 -0700 |
commit | de068425200d5254181c6806ebeb4a72d68895ec (patch) | |
tree | 7ec17c0bbd7a2654dbad678cd129575ca74f8dcd /src/resources/itemdb.cpp | |
parent | 088ccc74d9b8695c906eaabae8e4019ebf55c83c (diff) | |
download | mana-de068425200d5254181c6806ebeb4a72d68895ec.tar.gz mana-de068425200d5254181c6806ebeb4a72d68895ec.tar.bz2 mana-de068425200d5254181c6806ebeb4a72d68895ec.tar.xz mana-de068425200d5254181c6806ebeb4a72d68895ec.zip |
Added linking to item's just using [Item Name] in chat
Diffstat (limited to 'src/resources/itemdb.cpp')
-rw-r--r-- | src/resources/itemdb.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 7091abed..53e7530b 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -36,6 +36,7 @@ namespace { ItemDB::ItemInfos mItemInfos; + ItemDB::NamedItemInfos mNamedItemInfos; ItemInfo *mUnknown; bool mLoaded = false; } @@ -95,6 +96,7 @@ void ItemDB::load() if (id) { ItemInfo *itemInfo = new ItemInfo; + itemInfo->setId(id); itemInfo->setImageName(image); itemInfo->setName(name.empty() ? _("Unnamed") : name); itemInfo->setDescription(description); @@ -117,6 +119,19 @@ void ItemDB::load() } mItemInfos[id] = itemInfo; + if (!name.empty()) + { + NamedItemInfoIterator itr = mNamedItemInfos.find(name); + if (itr == mNamedItemInfos.end()) + { + mNamedItemInfos[name] = itemInfo; + } + else + { + logger->log(_("ItemDB: Duplicate name of item found item %d"), + id); + } + } } #define CHECK_PARAM(param, error_value) \ @@ -166,6 +181,23 @@ const ItemInfo& ItemDB::get(int id) } } +const ItemInfo& ItemDB::get(const std::string &name) +{ + assert(mLoaded && !name.empty()); + + NamedItemInfoIterator i = mNamedItemInfos.find(name); + + if (i == mNamedItemInfos.end()) + { + logger->log("ItemDB: Error, unknown item name %s", name.c_str()); + return *mUnknown; + } + else + { + return *(i->second); + } +} + void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) { std::string gender = XML::getProperty(node, "gender", "unisex"); |