diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/iteminfo.cpp | 4 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 8 | ||||
-rw-r--r-- | src/resources/itemmanager.cpp | 18 | ||||
-rw-r--r-- | src/resources/itemmanager.h | 2 |
4 files changed, 23 insertions, 9 deletions
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index e23be049..69090dcb 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -30,6 +30,10 @@ ItemInfo::ItemInfo() : { } +ItemInfo::~ItemInfo() +{ +} + void ItemInfo::setImage(short image) { this->image = image; diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index f634025f..937911af 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -31,13 +31,14 @@ */ class ItemInfo { + friend class ItemManager; + public: /** * Constructor. */ ItemInfo(); - void setImage(short image); short getImage(); @@ -70,21 +71,18 @@ class ItemInfo char getSlot(); - protected: /** * Destructor. */ ~ItemInfo(); - + short image, art; std::string name; std::string description; std::string effect; short type, weight; char slot; - - }; #endif diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 7d9c5ef5..caa26f5b 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -42,12 +42,16 @@ ItemManager::ItemManager() xmlDocPtr doc = xmlParseMemory(data, size); free(data); - if (doc) { + if (doc) + { xmlNodePtr node = xmlDocGetRootElement(doc); - if (!node || !xmlStrEqual(node->name, BAD_CAST "items")) { + if (!node || !xmlStrEqual(node->name, BAD_CAST "items")) + { logger->error("items.xml is not a valid database file!"); - } else { + } + else + { for (node = node->xmlChildrenNode; node != NULL; node = node->next) { if (xmlStrEqual(node->name, BAD_CAST "item")) @@ -112,6 +116,14 @@ ItemManager::ItemManager() ItemManager::~ItemManager() { + std::map<int, ItemInfo*>::iterator i; + for (i = db.begin(); i != db.end(); i++) + { + delete (*i).second; + } + db.clear(); + + delete unknown; } ItemInfo *ItemManager::getItemInfo(int id) diff --git a/src/resources/itemmanager.h b/src/resources/itemmanager.h index be861c01..6d969923 100644 --- a/src/resources/itemmanager.h +++ b/src/resources/itemmanager.h @@ -48,7 +48,7 @@ class ItemManager protected: // Items database - std::map <int, ItemInfo *> db; + std::map<int, ItemInfo*> db; ItemInfo *unknown; }; |