summaryrefslogtreecommitdiff
path: root/src/resources/itemdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/itemdb.cpp')
-rw-r--r--src/resources/itemdb.cpp72
1 files changed, 59 insertions, 13 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 1678eda8..773febd7 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -20,10 +20,10 @@
*/
#include <cassert>
+
#include <libxml/tree.h>
#include "itemdb.h"
-
#include "iteminfo.h"
#include "resourcemanager.h"
@@ -36,6 +36,7 @@
namespace
{
ItemDB::ItemInfos mItemInfos;
+ ItemDB::NamedItemInfos mNamedItemInfos;
ItemInfo *mUnknown;
bool mLoaded = false;
}
@@ -49,20 +50,20 @@ void ItemDB::load()
if (mLoaded)
return;
- logger->log("Initializing item database...");
+ logger->log(_("Initializing item database..."));
mUnknown = new ItemInfo();
- mUnknown->setName("Unknown item");
+ mUnknown->setName(_("Unknown item"));
mUnknown->setImageName("");
mUnknown->setSprite("error.xml", GENDER_MALE);
mUnknown->setSprite("error.xml", GENDER_FEMALE);
- XML::Document doc("items.xml");
+ XML::Document doc(_("items.xml"));
xmlNodePtr rootNode = doc.rootNode();
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items"))
{
- logger->error("ItemDB: Error while loading items.xml!");
+ logger->error(_("ItemDB: Error while loading items.xml!"));
}
for_each_xml_child_node(node, rootNode)
@@ -74,12 +75,12 @@ void ItemDB::load()
if (id == 0)
{
- logger->log("ItemDB: Invalid or missing item ID in items.xml!");
+ logger->log(_("ItemDB: Invalid or missing item ID in items.xml!"));
continue;
}
else if (mItemInfos.find(id) != mItemInfos.end())
{
- logger->log("ItemDB: Redefinition of item ID %d", id);
+ logger->log(_("ItemDB: Redefinition of item ID %d"), id);
}
int type = XML::getProperty(node, "type", 0);
@@ -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,34 @@ void ItemDB::load()
}
mItemInfos[id] = itemInfo;
+ if (!name.empty())
+ {
+ NamedItemInfoIterator itr = mNamedItemInfos.find(name);
+ if (itr == mNamedItemInfos.end())
+ {
+ std::string temp = name;
+ while (temp[0] == ' ')
+ {
+ temp = temp.substr(1, temp.size());
+ }
+ while (temp[temp.size()] == ' ')
+ {
+ temp = temp.substr(0, temp.size() - 1);
+ }
+
+ for (unsigned int i = 0; i < temp.size(); i++)
+ {
+ temp[i] = (char) tolower(temp[i]);
+ }
+
+ mNamedItemInfos[temp] = itemInfo;
+ }
+ else
+ {
+ logger->log(_("ItemDB: Duplicate name of item found item %d"),
+ id);
+ }
+ }
}
#define CHECK_PARAM(param, error_value) \
@@ -126,9 +156,9 @@ void ItemDB::load()
CHECK_PARAM(name, "");
CHECK_PARAM(image, "");
CHECK_PARAM(description, "");
- CHECK_PARAM(effect, "");
+ // CHECK_PARAM(effect, "");
// CHECK_PARAM(type, 0);
- // CHECK_PARAM(weight, 0);
+ CHECK_PARAM(weight, 0);
// CHECK_PARAM(slot, 0);
#undef CHECK_PARAM
@@ -139,7 +169,7 @@ void ItemDB::load()
void ItemDB::unload()
{
- logger->log("Unloading item database...");
+ logger->log(_("Unloading item database..."));
delete mUnknown;
mUnknown = NULL;
@@ -157,7 +187,24 @@ const ItemInfo& ItemDB::get(int id)
if (i == mItemInfos.end())
{
- logger->log("ItemDB: Error, unknown item ID# %d", id);
+ logger->log(_("ItemDB: Error, unknown item ID# %d"), id);
+ return *mUnknown;
+ }
+ else
+ {
+ return *(i->second);
+ }
+}
+
+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
@@ -175,7 +222,6 @@ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node)
{
itemInfo->setSprite(filename, GENDER_MALE);
}
-
if (gender == "female" || gender == "unisex")
{
itemInfo->setSprite(filename, GENDER_FEMALE);
@@ -197,7 +243,7 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node)
}
else
{
- logger->log("ItemDB: Ignoring unknown sound event '%s'",
+ logger->log(_("ItemDB: Ignoring unknown sound event '%s'"),
event.c_str());
}
}