summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2006-02-24 20:15:19 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2006-02-24 20:15:19 +0000
commit1c4742e530271e10ae949cf7e85402bee867e298 (patch)
treef95927614c4f9a84a507c9425b882f945be6d09f /src
parent05a12d5568111fa13759026442ed358605bf9a28 (diff)
downloadmana-1c4742e530271e10ae949cf7e85402bee867e298.tar.gz
mana-1c4742e530271e10ae949cf7e85402bee867e298.tar.bz2
mana-1c4742e530271e10ae949cf7e85402bee867e298.tar.xz
mana-1c4742e530271e10ae949cf7e85402bee867e298.zip
Another bunch of cosmetic cleanups, ie mostly typedefs...
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp2
-rw-r--r--src/being.h8
-rw-r--r--src/configuration.cpp50
-rw-r--r--src/configuration.h11
-rw-r--r--src/engine.cpp15
-rw-r--r--src/gui/browserbox.cpp5
-rw-r--r--src/gui/browserbox.h10
-rw-r--r--src/gui/chat.cpp26
-rw-r--r--src/gui/chat.h6
-rw-r--r--src/gui/gccontainer.cpp2
-rw-r--r--src/gui/gccontainer.h4
-rw-r--r--src/gui/minimap.cpp2
-rw-r--r--src/gui/tabbedcontainer.cpp3
-rw-r--r--src/gui/tabbedcontainer.h6
-rw-r--r--src/map.cpp21
-rw-r--r--src/map.h6
-rw-r--r--src/net/network.cpp17
-rw-r--r--src/net/network.h4
-rw-r--r--src/properties.h19
-rw-r--r--src/resources/itemmanager.cpp239
-rw-r--r--src/resources/itemmanager.h4
21 files changed, 210 insertions, 250 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 253c2d24..880263af 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -80,7 +80,7 @@ void Being::clearPath()
mPath.clear();
}
-void Being::setPath(std::list<PATH_NODE> path)
+void Being::setPath(const Path &path)
{
mPath = path;
diff --git a/src/being.h b/src/being.h
index db6afbb8..6f8e578c 100644
--- a/src/being.h
+++ b/src/being.h
@@ -48,6 +48,8 @@ struct PATH_NODE
unsigned short x;
unsigned short y;
};
+typedef std::list<PATH_NODE> Path;
+typedef Path::iterator PathIterator;
class Being : public Sprite
{
@@ -291,7 +293,7 @@ class Being : public Sprite
* Sets the new path for this being.
*/
void
- setPath(std::list<PATH_NODE> path);
+ setPath(const Path &path);
/**
* Calculates the offset in the given directions.
@@ -304,9 +306,9 @@ class Being : public Sprite
Uint16 mWalkSpeed; /**< Walking speed */
Map *mMap; /**< Map on which this being resides */
std::string mName; /**< Name of character */
- Sprites::iterator mSpriteIterator;
+ SpriteIterator mSpriteIterator;
- std::list<PATH_NODE> mPath;
+ Path mPath;
std::string speech;
std::string damage;
Uint16 hairStyle, hairColor;
diff --git a/src/configuration.cpp b/src/configuration.cpp
index f961c084..aa63f46c 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -62,8 +62,7 @@ void Configuration::init(const std::string &filename)
xmlChar *value = xmlGetProp(node, BAD_CAST "value");
if (name && value) {
- options[std::string((const char*)name)] =
- std::string((const char*)value);
+ mOptions[(const char*)name] = (const char*)value;
}
if (name) xmlFree(name);
@@ -93,18 +92,16 @@ void Configuration::write()
xmlTextWriterStartDocument(writer, NULL, NULL, NULL);
xmlTextWriterStartElement(writer, BAD_CAST "configuration");
- std::map<std::string, std::string>::iterator iter;
-
- for (iter = options.begin(); iter != options.end(); iter++)
+ for (OptionIterator i = mOptions.begin(); i != mOptions.end(); i++)
{
logger->log("Configuration::write(%s, \"%s\")",
- iter->first.c_str(), iter->second.c_str());
+ i->first.c_str(), i->second.c_str());
xmlTextWriterStartElement(writer, BAD_CAST "option");
xmlTextWriterWriteAttribute(writer,
- BAD_CAST "name", BAD_CAST iter->first.c_str());
+ BAD_CAST "name", BAD_CAST i->first.c_str());
xmlTextWriterWriteAttribute(writer,
- BAD_CAST "value", BAD_CAST iter->second.c_str());
+ BAD_CAST "value", BAD_CAST i->second.c_str());
xmlTextWriterEndElement(writer);
}
@@ -115,19 +112,15 @@ void Configuration::write()
void Configuration::setValue(const std::string &key, std::string value)
{
- options[key] = value;
+ mOptions[key] = value;
// Notify listeners
- std::map<std::string, std::list<ConfigListener*> >::iterator list =
- listeners.find(key);
-
- if (list != listeners.end()) {
- std::list<ConfigListener*>::iterator listener = (*list).second.begin();
-
- while (listener != (*list).second.end())
+ ListenerMapIterator list = mListenerMap.find(key);
+ if (list != mListenerMap.end()) {
+ Listeners listeners = list->second;
+ for (ListenerIterator i = listeners.begin(); i != listeners.end(); i++)
{
- (*listener)->optionChanged(key);
- listener++;
+ (*i)->optionChanged(key);
}
}
}
@@ -141,33 +134,24 @@ void Configuration::setValue(const std::string &key, float value)
std::string Configuration::getValue(const std::string &key, std::string deflt)
{
- std::map<std::string, std::string>::iterator iter = options.find(key);
- return ((iter != options.end()) ? (*iter).second : deflt);
+ OptionIterator iter = mOptions.find(key);
+ return ((iter != mOptions.end()) ? iter->second : deflt);
}
float Configuration::getValue(const std::string &key, float deflt)
{
- std::map<std::string, std::string>::iterator iter = options.find(key);
- return (iter != options.end()) ? atof((*iter).second.c_str()) : deflt;
+ OptionIterator iter = mOptions.find(key);
+ return (iter != mOptions.end()) ? atof(iter->second.c_str()) : deflt;
}
void Configuration::addListener(
const std::string &key, ConfigListener *listener)
{
- listeners[key].push_front(listener);
+ mListenerMap[key].push_front(listener);
}
void Configuration::removeListener(
const std::string &key, ConfigListener *listener)
{
- std::list<ConfigListener*>::iterator i = listeners[key].begin();
-
- while (i != listeners[key].end())
- {
- if ((*i) == listener) {
- listeners[key].erase(i);
- return;
- }
- i++;
- }
+ mListenerMap[key].remove(listener);
}
diff --git a/src/configuration.h b/src/configuration.h
index d2f44dca..28246a02 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -94,8 +94,15 @@ class Configuration
void removeListener(const std::string &key, ConfigListener *listener);
private:
- std::map<std::string, std::string> options;
- std::map<std::string, std::list<ConfigListener*> > listeners;
+ typedef std::map<std::string, std::string> Options;
+ typedef Options::iterator OptionIterator;
+ Options mOptions;
+
+ typedef std::list<ConfigListener*> Listeners;
+ typedef Listeners::iterator ListenerIterator;
+ typedef std::map<std::string, Listeners> ListenerMap;
+ typedef ListenerMap::iterator ListenerMapIterator;
+ ListenerMap mListenerMap;
std::string mConfigPath; /**< Location of config file */
};
diff --git a/src/engine.cpp b/src/engine.cpp
index 879a6b21..76ed7ac9 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -167,7 +167,7 @@ void Engine::logic()
{
Beings *beings = beingManager->getAll();
// Update beings
- Beings::iterator beingIterator = beings->begin();
+ BeingIterator beingIterator = beings->begin();
while (beingIterator != beings->end())
{
Being *being = (*beingIterator);
@@ -232,21 +232,18 @@ void Engine::draw(Graphics *graphics)
int mouseTileX = mouseX / 32 + camera_x;
int mouseTileY = mouseY / 32 + camera_y;
- std::list<PATH_NODE> debugPath = mCurrentMap->findPath(
+ Path debugPath = mCurrentMap->findPath(
player_node->x, player_node->y,
mouseTileX, mouseTileY);
- while (!debugPath.empty())
+ for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++)
{
- PATH_NODE node = debugPath.front();
- debugPath.pop_front();
-
- int squareX = node.x * 32 - map_x + 12;
- int squareY = node.y * 32 - map_y + 12;
+ int squareX = i->x * 32 - map_x + 12;
+ int squareY = i->y * 32 - map_y + 12;
graphics->setColor(gcn::Color(255, 0, 0));
graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8));
- MetaTile *tile = mCurrentMap->getMetaTile(node.x, node.y);
+ MetaTile *tile = mCurrentMap->getMetaTile(i->x, i->y);
std::stringstream cost;
cost << tile->Gcost;
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index cbf7c1cc..8a636679 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -241,11 +241,10 @@ struct MouseOverLinkFunctor
void BrowserBox::mousePress(int mx, int my, int button)
{
- std::vector<BROWSER_LINK>::iterator i;
-
mouseOverLink.mX = mx;
mouseOverLink.mY = my;
- i = find_if(mLinks.begin(), mLinks.end(), mouseOverLink);
+
+ LinkIterator i = find_if(mLinks.begin(), mLinks.end(), mouseOverLink);
if (i != mLinks.end()) {
mLinkHandler->handleLink(i->link);
diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h
index 2897ee96..c6d8f117 100644
--- a/src/gui/browserbox.h
+++ b/src/gui/browserbox.h
@@ -143,8 +143,14 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener
};
private:
- std::vector<std::string> mTextRows;
- std::vector<BROWSER_LINK> mLinks;
+ typedef std::vector<std::string> TextRows;
+ typedef TextRows::iterator TextRowIterator;
+ TextRows mTextRows;
+
+ typedef std::vector<BROWSER_LINK> Links;
+ typedef Links::iterator LinkIterator;
+ Links mLinks;
+
LinkHandler *mLinkHandler;
unsigned int mMode;
unsigned int mHighMode;
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 29fbebfe..28259c77 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -75,7 +75,7 @@ ChatWindow::ChatWindow(const std::string &logfile, Network *network):
// Add key listener to chat input to be able to respond to up/down
chatInput->addKeyListener(this);
- curHist = history.end();
+ mCurHist = mHistory.end();
}
ChatWindow::~ChatWindow()
@@ -199,12 +199,12 @@ ChatWindow::action(const std::string& eventId)
if (message.length() > 0) {
// If message different from previous, put it in the history
- if (history.size() == 0 || message != history.back()) {
- history.push_back(message);
+ if (mHistory.size() == 0 || message != mHistory.back()) {
+ mHistory.push_back(message);
}
// Reset history iterator
- curHist = history.end();
+ mCurHist = mHistory.end();
// Send the message to the server
chatSend(player_node->getName().c_str(), message.c_str());
@@ -384,24 +384,24 @@ ChatWindow::const_msg(CHATSKILL act)
void
ChatWindow::keyPress(const gcn::Key &key)
{
- if (key.getValue() == key.DOWN && curHist != history.end())
+ if (key.getValue() == key.DOWN && mCurHist != mHistory.end())
{
// Move forward through the history
- std::list<std::string>::iterator prevHist = curHist++;
- if (curHist != history.end()) {
- chatInput->setText(*curHist);
+ HistoryIterator prevHist = mCurHist++;
+ if (mCurHist != mHistory.end()) {
+ chatInput->setText(*mCurHist);
chatInput->setCaretPosition(chatInput->getText().length());
}
else {
- curHist = prevHist;
+ mCurHist = prevHist;
}
}
- else if (key.getValue() == key.UP && curHist != history.begin() &&
- history.size() > 0)
+ else if (key.getValue() == key.UP && mCurHist != mHistory.begin() &&
+ mHistory.size() > 0)
{
// Move backward through the history
- curHist--;
- chatInput->setText(*curHist);
+ mCurHist--;
+ chatInput->setText(*mCurHist);
chatInput->setCaretPosition(chatInput->getText().length());
}
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 63b30db3..b460e4c0 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -218,8 +218,10 @@ class ChatWindow : public Window, public gcn::ActionListener,
BrowserBox *textOutput; /**< Text box for displaying chat history */
ScrollArea *scrollArea; /**< Scroll area around text output */
- std::list<std::string> history; /**< Command history */
- std::list<std::string>::iterator curHist; /**< History iterator */
+ typedef std::list<std::string> History;
+ typedef History::iterator HistoryIterator;
+ History mHistory; /**< Command history */
+ HistoryIterator mCurHist; /**< History iterator */
};
extern ChatWindow *chatWindow;
diff --git a/src/gui/gccontainer.cpp b/src/gui/gccontainer.cpp
index 32e78e48..3b574622 100644
--- a/src/gui/gccontainer.cpp
+++ b/src/gui/gccontainer.cpp
@@ -25,7 +25,7 @@
GCContainer::~GCContainer()
{
- std::list<gcn::Widget*>::iterator i = mDeathList.begin();
+ WidgetIterator i = mDeathList.begin();
while (i != mDeathList.end()) {
/* Take care _not_ to modify the list in our _announceDeath method */
diff --git a/src/gui/gccontainer.h b/src/gui/gccontainer.h
index 696aef0c..46ebfefa 100644
--- a/src/gui/gccontainer.h
+++ b/src/gui/gccontainer.h
@@ -37,7 +37,9 @@ class GCContainer : public gcn::Container
virtual void _announceDeath(gcn::Widget *w);
protected:
- std::list<gcn::Widget*> mDeathList;
+ typedef std::list<gcn::Widget*> Widgets;
+ typedef Widgets::iterator WidgetIterator;
+ Widgets mDeathList;
};
#endif
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index e19a8c62..d0c52b11 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -77,7 +77,7 @@ void Minimap::draw(gcn::Graphics *graphics)
}
Beings *beings = beingManager->getAll();
- Beings::iterator bi;
+ BeingIterator bi;
for (bi = beings->begin(); bi != beings->end(); bi++)
{
diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp
index 75977571..3d08b390 100644
--- a/src/gui/tabbedcontainer.cpp
+++ b/src/gui/tabbedcontainer.cpp
@@ -37,8 +37,7 @@ TabbedContainer::TabbedContainer():
TabbedContainer::~TabbedContainer()
{
- std::vector<gcn::Widget*>::iterator i = mTabs.begin();
- for (i = mTabs.begin(); i != mTabs.end(); i++) {
+ for (WidgetIterator i = mTabs.begin(); i != mTabs.end(); i++) {
remove(*i);
delete (*i);
}
diff --git a/src/gui/tabbedcontainer.h b/src/gui/tabbedcontainer.h
index 89c10c1c..24c8c425 100644
--- a/src/gui/tabbedcontainer.h
+++ b/src/gui/tabbedcontainer.h
@@ -48,8 +48,10 @@ class TabbedContainer : public gcn::Container, public gcn::ActionListener
void setOpaque(bool opaque);
private:
- std::vector<gcn::Widget*> mTabs; // The actual tabs at the top
- std::vector<gcn::Widget*> mContents; // The contents of the tabs
+ typedef std::vector<gcn::Widget*> Widgets;
+ typedef Widgets::iterator WidgetIterator;
+ Widgets mTabs; // The actual tabs at the top
+ Widgets mContents; // The contents of the tabs
Widget *mActiveContent;
};
diff --git a/src/map.cpp b/src/map.cpp
index d249426a..33e399d7 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -70,8 +70,7 @@ Map::~Map()
delete[] tiles;
// Clean up tilesets
- Tilesets::iterator i;
- for (i = tilesets.begin(); i != tilesets.end(); i++)
+ for (TilesetIterator i = tilesets.begin(); i != tilesets.end(); i++)
{
delete (*i);
}
@@ -109,7 +108,7 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
int endY = (graphics->getHeight() + scrollY + 31) / 32;
// If drawing the fringe layer, make sure sprites are sorted
- Sprites::iterator si;
+ SpriteIterator si;
if (layer == 1)
{
mSprites.sort(spriteCompare);
@@ -189,10 +188,9 @@ class ContainsGidFunctor
Tileset*
Map::getTilesetWithGid(int gid)
{
- Tilesets::iterator i;
-
containsGid.gid = gid;
- i = find_if(tilesets.begin(), tilesets.end(), containsGid);
+
+ TilesetIterator i = find_if(tilesets.begin(), tilesets.end(), containsGid);
return (i == tilesets.end()) ? NULL : *i;
}
@@ -225,8 +223,7 @@ Map::getWalk(int x, int y)
// Check for collision with a being
Beings *beings = beingManager->getAll();
- Beings::iterator i;
- for (i = beings->begin(); i != beings->end(); i++) {
+ for (BeingIterator i = beings->begin(); i != beings->end(); i++) {
// job 45 is a portal, they don't collide
if ((*i)->x == x && (*i)->y == y && (*i)->job != 45) {
return false;
@@ -266,7 +263,7 @@ Map::getMetaTile(int x, int y)
return &metaTiles[x + y * mWidth];
}
-Sprites::iterator
+SpriteIterator
Map::addSprite(Sprite *sprite)
{
mSprites.push_front(sprite);
@@ -274,16 +271,16 @@ Map::addSprite(Sprite *sprite)
}
void
-Map::removeSprite(Sprites::iterator iterator)
+Map::removeSprite(SpriteIterator iterator)
{
mSprites.erase(iterator);
}
-std::list<PATH_NODE>
+Path
Map::findPath(int startX, int startY, int destX, int destY)
{
// Path to be built up (empty by default)
- std::list<PATH_NODE> path;
+ Path path;
// Declare open list, a list with open tiles sorted on F cost
std::priority_queue<Location> openList;
diff --git a/src/map.h b/src/map.h
index 35e3d75f..309fefd0 100644
--- a/src/map.h
+++ b/src/map.h
@@ -37,7 +37,9 @@ class Sprite;
struct PATH_NODE;
typedef std::vector<Tileset*> Tilesets;
+typedef Tilesets::iterator TilesetIterator;
typedef std::list<Sprite*> Sprites;
+typedef Sprites::iterator SpriteIterator;
/**
* A meta tile stores additional information about a location on a tile map.
@@ -163,14 +165,14 @@ class Map : public Properties
/**
* Adds a sprite to the map.
*/
- Sprites::iterator
+ SpriteIterator
addSprite(Sprite *sprite);
/**
* Removes a sprite from the map.
*/
void
- removeSprite(Sprites::iterator iterator);
+ removeSprite(SpriteIterator iterator);
private:
/**
diff --git a/src/net/network.cpp b/src/net/network.cpp
index 9e6f6621..366d07d9 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -182,17 +182,9 @@ void Network::registerHandler(MessageHandler *handler)
void Network::unregisterHandler(MessageHandler *handler)
{
- const Uint16 *i = handler->handledMessages;
-
- while(*i)
+ for (const Uint16 *i = handler->handledMessages; *i; i++)
{
- std::map<Uint16, MessageHandler*>::iterator iter;
- iter = mMessageHandlers.find(*i);
- if (iter != mMessageHandlers.end())
- {
- mMessageHandlers.erase(iter);
- }
- i++;
+ mMessageHandlers.erase(*i);
}
handler->setNetwork(0);
@@ -200,7 +192,7 @@ void Network::unregisterHandler(MessageHandler *handler)
void Network::clearHandlers()
{
- std::map<Uint16, MessageHandler*>::iterator i;
+ MessageHandlerIterator i;
for (i = mMessageHandlers.begin(); i != mMessageHandlers.end(); i++)
{
i->second->setNetwork(0);
@@ -214,8 +206,7 @@ void Network::dispatchMessages()
{
MessageIn msg = getNextMessage();
- std::map<Uint16, MessageHandler*>::iterator iter;
- iter = mMessageHandlers.find(msg.getId());
+ MessageHandlerIterator iter = mMessageHandlers.find(msg.getId());
if (iter != mMessageHandlers.end())
iter->second->handleMessage(&msg);
diff --git a/src/net/network.h b/src/net/network.h
index 06abc445..f4637f73 100644
--- a/src/net/network.h
+++ b/src/net/network.h
@@ -89,7 +89,9 @@ class Network
SDL_Thread *mWorkerThread;
SDL_mutex *mMutex;
- std::map<Uint16, MessageHandler*> mMessageHandlers;
+ typedef std::map<Uint16, MessageHandler*> MessageHandlers;
+ typedef MessageHandlers::iterator MessageHandlerIterator;
+ MessageHandlers mMessageHandlers;
bool realConnect();
void receive();
diff --git a/src/properties.h b/src/properties.h
index ccf8cd00..92690cd3 100644
--- a/src/properties.h
+++ b/src/properties.h
@@ -46,17 +46,9 @@ class Properties
getProperty(const std::string &name)
{
const static std::string undefined = "";
- std::map<std::string, std::string>::const_iterator i =
- properties.find(name);
+ PropertyMap::const_iterator i = mProperties.find(name);
- if (i != properties.end())
- {
- return (*i).second;
- }
- else
- {
- return undefined;
- }
+ return (i != mProperties.end()) ? i->second : undefined;
}
/**
@@ -65,7 +57,7 @@ class Properties
bool
hasProperty(const std::string &name)
{
- return (properties.find(name) != properties.end());
+ return (mProperties.find(name) != mProperties.end());
}
/**
@@ -74,11 +66,12 @@ class Properties
void
setProperty(const std::string &name, const std::string &value)
{
- properties[name] = value;
+ mProperties[name] = value;
}
private:
- std::map<std::string, std::string> properties;
+ typedef std::map<std::string, std::string> PropertyMap;
+ PropertyMap mProperties;
};
#endif
diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp
index 59767e8e..994f11b9 100644
--- a/src/resources/itemmanager.cpp
+++ b/src/resources/itemmanager.cpp
@@ -29,8 +29,18 @@
#include "../log.h"
+#define READ_PROP(node, prop, name, target, cast) \
+ prop = xmlGetProp(node, BAD_CAST name); \
+ if (prop) { \
+ target = cast((const char*)prop); \
+ xmlFree(prop); \
+ }
+
ItemManager::ItemManager()
{
+ unknown = new ItemInfo();
+ unknown->setName("Unknown item");
+
ResourceManager *resman = ResourceManager::getInstance();
int size;
char *data = (char*)resman->loadFile("items.xml", size);
@@ -42,146 +52,114 @@ ItemManager::ItemManager()
xmlDocPtr doc = xmlParseMemory(data, size);
free(data);
- if (doc)
+ if (!doc)
{
- xmlNodePtr node = xmlDocGetRootElement(doc);
+ logger->error("Item Manager: Error while parsing item database (items.xml)!");
+ return;
+ }
- if (!node || !xmlStrEqual(node->name, BAD_CAST "items"))
+ xmlNodePtr node = xmlDocGetRootElement(doc);
+ if (!node || !xmlStrEqual(node->name, BAD_CAST "items"))
+ {
+ logger->error("Item Manager: items.xml is not a valid database file!");
+ return;
+ }
+
+ for (node = node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ int id = 0, image = 0, art = 0, type = 0, weight = 0, slot = 0;
+ std::string name = "", description = "", effect = "";
+
+ if (!xmlStrEqual(node->name, BAD_CAST "item")) {
+ continue;
+ }
+
+ xmlChar *prop = NULL;
+ READ_PROP(node, prop, "id", id, atoi);
+ READ_PROP(node, prop, "image", image, atoi);
+ READ_PROP(node, prop, "art", art, atoi);
+ READ_PROP(node, prop, "name", name, );
+ READ_PROP(node, prop, "description", description, );
+ READ_PROP(node, prop, "effect", effect, );
+ READ_PROP(node, prop, "type", type, atoi);
+ READ_PROP(node, prop, "weight", weight, atoi);
+ READ_PROP(node, prop, "slot", slot, atoi);
+
+ if (id && name != "")
+ {
+ ItemInfo *itemInfo = new ItemInfo();
+ itemInfo->setImage(image);
+ itemInfo->setArt(art);
+ itemInfo->setName(name);
+ itemInfo->setDescription(description);
+ itemInfo->setEffect(effect);
+ itemInfo->setType(type);
+ itemInfo->setWeight(weight);
+ itemInfo->setSlot(slot);
+ mItemInfos[id] = itemInfo;
+ }
+
+ if (id == 0)
{
- logger->error("Item Manager: items.xml is not a valid database file!");
+ logger->log("Item Manager: An item has no ID in items.xml!");
}
- else
+ if (name == "")
{
- for (node = node->xmlChildrenNode; node != NULL; node = node->next)
- {
- int id = 0, image = 0, art = 0, type = 0, weight = 0, slot = 0;
- std::string name = "", description = "", effect = "";
-
- if (xmlStrEqual(node->name, BAD_CAST "item"))
- {
- xmlChar *prop = NULL;
- // Item id
- prop = xmlGetProp(node, BAD_CAST "id");
- if (prop) id = atoi((const char*)prop);
- xmlFree(prop);
- // Image id
- prop = xmlGetProp(node, BAD_CAST "image");
- if (prop) image = atoi((const char*)prop);
- xmlFree(prop);
- // Art id
- prop = xmlGetProp(node, BAD_CAST "art");
- if (prop) art = atoi((const char*)prop);
- xmlFree(prop);
- // Name
- prop = xmlGetProp(node, BAD_CAST "name");
- if (prop) name = (const char*)prop;
- xmlFree(prop);
- // Description
- prop = xmlGetProp(node, BAD_CAST "description");
- if (prop) description = (const char*)prop;
- xmlFree(prop);
- // Effect
- prop = xmlGetProp(node, BAD_CAST "effect");
- if (prop) effect = (const char*)prop;
- xmlFree(prop);
- // Type id
- prop = xmlGetProp(node, BAD_CAST "type");
- if (prop) type = atoi((const char*)prop);
- xmlFree(prop);
- // Weight
- prop = xmlGetProp(node, BAD_CAST "weight");
- if (prop) weight = atoi((const char*)prop);
- xmlFree(prop);
- // Slot
- prop = xmlGetProp(node, BAD_CAST "slot");
- if (prop) slot = atoi((const char*)prop);
- xmlFree(prop);
-
- if (id && name != "")
- {
- ItemInfo *itemInfo = new ItemInfo();
- itemInfo->setImage(image);
- itemInfo->setArt(art);
- itemInfo->setName(name);
- itemInfo->setDescription(description);
- itemInfo->setEffect(effect);
- itemInfo->setType(type);
- itemInfo->setWeight(weight);
- itemInfo->setSlot(slot);
- db[id] = itemInfo;
- }
-
- if (id == 0)
- {
- logger->log("Item Manager: An item has no ID in items.xml!");
- }
- if (name == "")
- {
- logger->log("Item Manager: An item has no name in items.xml!");
- }
-
- if (image == 0)
- {
- logger->log("Item Manager: Missing image parameter for item: %i. %s",
- id, name.c_str());
- }
- if (art == 0)
- {
- logger->log("Item Manager: Missing art parameter for item: %i. %s",
- id, name.c_str());
- }
- if (description == "")
- {
- logger->log("Item Manager: Missing description parameter for item: %i. %s",
- id, name.c_str());
- }
- if (effect == "")
- {
- logger->log("Item Manager: Missing effect parameter for item: %i. %s",
- id, name.c_str());
- }
- if (type == 0)
- {
- logger->log("Item Manager: Missing type parameter for item: %i. %s",
- id, name.c_str());
- }
- if (weight == 0)
- {
- logger->log("Item Manager: Missing weight parameter for item: %i. %s",
- id, name.c_str());
- }
- if (slot == 0)
- {
- logger->log("Item Manager: Missing image parameter for item: %i. %s",
- id, name.c_str());
- }
-
- /*logger->log("Item: %i %i %i %s %s %i %i %i", id,
- getImage(id), getArt(id), getName(id).c_str(),
- getDescription(id).c_str(), getType(id), getWeight(id),
- getSlot(id));*/
- }
- }
+ logger->log("Item Manager: An item has no name in items.xml!");
}
- xmlFreeDoc(doc);
- }
- else {
- logger->error("Item Manager: Error while parsing item database (items.xml)!");
+ if (image == 0)
+ {
+ logger->log("Item Manager: Missing image parameter for item: %i. %s",
+ id, name.c_str());
+ }
+ if (art == 0)
+ {
+ logger->log("Item Manager: Missing art parameter for item: %i. %s",
+ id, name.c_str());
+ }
+ if (description == "")
+ {
+ logger->log("Item Manager: Missing description parameter for item: %i. %s",
+ id, name.c_str());
+ }
+ if (effect == "")
+ {
+ logger->log("Item Manager: Missing effect parameter for item: %i. %s",
+ id, name.c_str());
+ }
+ if (type == 0)
+ {
+ logger->log("Item Manager: Missing type parameter for item: %i. %s",
+ id, name.c_str());
+ }
+ if (weight == 0)
+ {
+ logger->log("Item Manager: Missing weight parameter for item: %i. %s",
+ id, name.c_str());
+ }
+ if (slot == 0)
+ {
+ logger->log("Item Manager: Missing image parameter for item: %i. %s",
+ id, name.c_str());
+ }
+
+ /*logger->log("Item: %i %i %i %s %s %i %i %i", id,
+ getImage(id), getArt(id), getName(id).c_str(),
+ getDescription(id).c_str(), getType(id), getWeight(id),
+ getSlot(id));*/
}
- unknown = new ItemInfo();
- unknown->setName("Unknown item");
+ xmlFreeDoc(doc);
}
ItemManager::~ItemManager()
{
- std::map<int, ItemInfo*>::iterator i;
- for (i = db.begin(); i != db.end(); i++)
+ for (ItemInfoIterator i = mItemInfos.begin(); i != mItemInfos.end(); i++)
{
- delete (*i).second;
+ delete i->second;
}
- db.clear();
+ mItemInfos.clear();
delete unknown;
}
@@ -189,12 +167,7 @@ ItemManager::~ItemManager()
ItemInfo*
ItemManager::getItemInfo(int id)
{
- if (db.find(id) != db.end())
- {
- return db[id];
- }
- else
- {
- return unknown;
- }
+ ItemInfoIterator i = mItemInfos.find(id);
+
+ return (i != mItemInfos.end()) ? i->second : unknown;
}
diff --git a/src/resources/itemmanager.h b/src/resources/itemmanager.h
index 6d969923..5a571de2 100644
--- a/src/resources/itemmanager.h
+++ b/src/resources/itemmanager.h
@@ -48,7 +48,9 @@ class ItemManager
protected:
// Items database
- std::map<int, ItemInfo*> db;
+ typedef std::map<int, ItemInfo*> ItemInfos;
+ typedef ItemInfos::iterator ItemInfoIterator;
+ ItemInfos mItemInfos;
ItemInfo *unknown;
};