diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-21 12:52:08 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-21 12:52:08 +0000 |
commit | 8eb8602942d63661674d237d127c5f3ccfcf4ef4 (patch) | |
tree | 0d1e902e16c55f7742ead9a4c9f53506c373df48 /src/resources | |
parent | d70c0ba4264dee317d1a60f2fa4d81f123dde016 (diff) | |
download | mana-8eb8602942d63661674d237d127c5f3ccfcf4ef4.tar.gz mana-8eb8602942d63661674d237d127c5f3ccfcf4ef4.tar.bz2 mana-8eb8602942d63661674d237d127c5f3ccfcf4ef4.tar.xz mana-8eb8602942d63661674d237d127c5f3ccfcf4ef4.zip |
Now shops get item names from the xml database
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/itemmanager.cpp | 40 | ||||
-rw-r--r-- | src/resources/itemmanager.h | 1 |
2 files changed, 33 insertions, 8 deletions
diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 5ad4e66d..4bb6555b 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -36,7 +36,8 @@ #define xmlFree(x) ; #endif -ItemManager::ItemManager() +ItemManager::ItemManager() : + minId(10000), maxId(0) { // Check that file exists before trying to parse it std::fstream dbFile; @@ -62,6 +63,8 @@ ItemManager::ItemManager() xmlChar *prop; prop = xmlGetProp(node, BAD_CAST "id"); int id = atoi((const char*)prop); + if (id < minId) minId = id; + if (id > maxId) maxId = id; xmlFree(prop); prop = xmlGetProp(node, BAD_CAST "image"); int image = atoi((const char*)prop); @@ -115,35 +118,56 @@ ItemManager::~ItemManager() short ItemManager::getImage(int id) { - return db[id]->getImage(); + if (id >= minId && id <= maxId) + return db[id]->getImage(); + else + return 0; } short ItemManager::getArt(int id) { - return db[id]->getArt(); + if (id >= minId && id <= maxId) + return db[id]->getArt(); + else + return 0; } std::string ItemManager::getName(int id) { - return db[id]->getName(); + if (id >= minId && id <= maxId) + return db[id]->getName(); + else + return "Unknown"; } std::string ItemManager::getDescription(int id) { - return db[id]->getDescription(); + if (id >= minId && id <= maxId) + return db[id]->getDescription(); + else + return ""; } short ItemManager::getType(int id) { - return db[id]->getType(); + if (id >= minId && id <= maxId) + return db[id]->getType(); + else + return 0; } short ItemManager::getWeight(int id) { - return db[id]->getWeight(); + if (id >= minId && id <= maxId) + return db[id]->getWeight(); + else + return 0; } char ItemManager::getSlot(int id) { - return db[id]->getSlot(); + if (id >= minId && id <= maxId) + return db[id]->getSlot(); + else + return 0; } diff --git a/src/resources/itemmanager.h b/src/resources/itemmanager.h index 0db5893f..3f014ad6 100644 --- a/src/resources/itemmanager.h +++ b/src/resources/itemmanager.h @@ -63,6 +63,7 @@ class ItemManager protected: // Items database std::map <int, ItemInfo *> db; + int minId, maxId; }; |