summaryrefslogtreecommitdiff
path: root/src/resources/itemdb.cpp
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2009-01-14 14:11:35 +0000
committerDavid Athay <ko2fan@gmail.com>2009-01-14 14:11:35 +0000
commit451b5887beae88c1f3c139a35d23e5521e896e7d (patch)
treee1d5f5058311a1121d1eb2c122eb3d1eb5cee372 /src/resources/itemdb.cpp
parentac3d5127cb7f3e3a4f5fa7a3ceb6f7c8de6808be (diff)
downloadmana-client-451b5887beae88c1f3c139a35d23e5521e896e7d.tar.gz
mana-client-451b5887beae88c1f3c139a35d23e5521e896e7d.tar.bz2
mana-client-451b5887beae88c1f3c139a35d23e5521e896e7d.tar.xz
mana-client-451b5887beae88c1f3c139a35d23e5521e896e7d.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.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 04828d1b..5dfcfb87 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -37,6 +37,7 @@
namespace
{
ItemDB::ItemInfos mItemInfos;
+ ItemDB::NamedItemInfos mNamedItemInfos;
ItemInfo *mUnknown;
bool mLoaded = false;
}
@@ -136,6 +137,7 @@ void ItemDB::load()
int attackRange = XML::getProperty(node, "attack-range", 0);
ItemInfo *itemInfo = new ItemInfo;
+ itemInfo->setId(id);
itemInfo->setImageName(image);
itemInfo->setName(name.empty() ? "Unnamed" : name);
itemInfo->setDescription(description);
@@ -169,6 +171,18 @@ 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) \
if (param == error_value) \
@@ -217,6 +231,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");