summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/itemmanager.cpp64
-rw-r--r--src/game-server/main-game.cpp4
-rw-r--r--src/game-server/mapmanager.cpp75
-rw-r--r--src/game-server/mapmanager.hpp7
-rw-r--r--src/game-server/mapreader.cpp6
-rw-r--r--src/game-server/monstermanager.cpp35
-rw-r--r--src/game-server/monstermanager.hpp2
-rw-r--r--src/game-server/statusmanager.cpp28
-rw-r--r--src/game-server/statusmanager.hpp2
9 files changed, 72 insertions, 151 deletions
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index e7069636..c1750443 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -45,39 +45,25 @@ void ItemManager::initialize(const std::string &file)
void ItemManager::reload()
{
- int size;
- char *data = ResourceManager::loadFile(itemReferenceFile, size);
-
std::string absPathFile = ResourceManager::resolve(itemReferenceFile);
-
- if (!data) {
+ if (absPathFile.empty()) {
LOG_ERROR("Item Manager: Could not find " << itemReferenceFile << "!");
- free(data);
return;
}
- xmlDocPtr doc = xmlParseMemory(data, size);
- free(data);
+ XML::Document doc(absPathFile, false);
+ xmlNodePtr rootNode = doc.rootNode();
- if (!doc)
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items"))
{
LOG_ERROR("Item Manager: Error while parsing item database ("
<< absPathFile << ")!");
return;
}
- xmlNodePtr node = xmlDocGetRootElement(doc);
- if (!node || !xmlStrEqual(node->name, BAD_CAST "items"))
- {
- LOG_ERROR("Item Manager: " << absPathFile
- << " is not a valid database file!");
- xmlFreeDoc(doc);
- return;
- }
-
LOG_INFO("Loading item reference: " << absPathFile);
unsigned nbItems = 0;
- for (node = node->xmlChildrenNode; node != NULL; node = node->next)
+ for_each_xml_child_node(node, rootNode)
{
// Try to load the version of the item database. The version is defined
// as subversion tag embedded as XML attribute. So every modification
@@ -109,8 +95,9 @@ void ItemManager::reload()
if (itemType == ITEM_UNKNOWN)
{
- LOG_WARN(itemReferenceFile<<": Unknown item type \""<<sItemType
- <<"\" for item #"<<id<<" - treating it as \"generic\"");
+ LOG_WARN(itemReferenceFile << ": Unknown item type \"" << sItemType
+ << "\" for item #" << id <<
+ " - treating it as \"generic\"");
itemType = ITEM_UNUSABLE;
}
@@ -146,27 +133,28 @@ void ItemManager::reload()
std::string strWeaponType = XML::getProperty(node, "weapon-type", "");
if (strWeaponType == "")
{
- LOG_WARN(itemReferenceFile<<": Unknown weapon type \""
- <<"\" for item #"<<id<<" - treating it as generic item");
+ LOG_WARN(itemReferenceFile << ": Unknown weapon type \""
+ << "\" for item #" << id <<
+ " - treating it as generic item");
} else {
weaponType = SkillManager::getIdFromString(strWeaponType);
}
modifiers.setValue(MOD_WEAPON_TYPE, weaponType);
- modifiers.setValue(MOD_WEAPON_RANGE, XML::getProperty(node, "range", 0));
- modifiers.setValue(MOD_ELEMENT_TYPE, XML::getProperty(node, "element", 0));
+ modifiers.setValue(MOD_WEAPON_RANGE, XML::getProperty(node, "range", 0));
+ modifiers.setValue(MOD_ELEMENT_TYPE, XML::getProperty(node, "element", 0));
}
- modifiers.setValue(MOD_LIFETIME, XML::getProperty(node, "lifetime", 0) * 10);
+ modifiers.setValue(MOD_LIFETIME, XML::getProperty(node, "lifetime", 0) * 10);
//TODO: add child nodes for these modifiers (additive and factor)
- modifiers.setAttributeValue(BASE_ATTR_PHY_ATK_MIN, XML::getProperty(node, "attack-min", 0));
- modifiers.setAttributeValue(BASE_ATTR_PHY_ATK_DELTA, XML::getProperty(node, "attack-delta", 0));
- modifiers.setAttributeValue(BASE_ATTR_HP, XML::getProperty(node, "hp", 0));
- modifiers.setAttributeValue(BASE_ATTR_PHY_RES, XML::getProperty(node, "defense", 0));
- modifiers.setAttributeValue(CHAR_ATTR_STRENGTH, XML::getProperty(node, "strength", 0));
- modifiers.setAttributeValue(CHAR_ATTR_AGILITY, XML::getProperty(node, "agility", 0));
- modifiers.setAttributeValue(CHAR_ATTR_DEXTERITY, XML::getProperty(node, "dexterity", 0));
- modifiers.setAttributeValue(CHAR_ATTR_VITALITY, XML::getProperty(node, "vitality", 0));
- modifiers.setAttributeValue(CHAR_ATTR_INTELLIGENCE, XML::getProperty(node, "intelligence", 0));
- modifiers.setAttributeValue(CHAR_ATTR_WILLPOWER, XML::getProperty(node, "willpower", 0));
+ modifiers.setAttributeValue(BASE_ATTR_PHY_ATK_MIN, XML::getProperty(node, "attack-min", 0));
+ modifiers.setAttributeValue(BASE_ATTR_PHY_ATK_DELTA, XML::getProperty(node, "attack-delta", 0));
+ modifiers.setAttributeValue(BASE_ATTR_HP, XML::getProperty(node, "hp", 0));
+ modifiers.setAttributeValue(BASE_ATTR_PHY_RES, XML::getProperty(node, "defense", 0));
+ modifiers.setAttributeValue(CHAR_ATTR_STRENGTH, XML::getProperty(node, "strength", 0));
+ modifiers.setAttributeValue(CHAR_ATTR_AGILITY, XML::getProperty(node, "agility", 0));
+ modifiers.setAttributeValue(CHAR_ATTR_DEXTERITY, XML::getProperty(node, "dexterity", 0));
+ modifiers.setAttributeValue(CHAR_ATTR_VITALITY, XML::getProperty(node, "vitality", 0));
+ modifiers.setAttributeValue(CHAR_ATTR_INTELLIGENCE, XML::getProperty(node, "intelligence", 0));
+ modifiers.setAttributeValue(CHAR_ATTR_WILLPOWER, XML::getProperty(node, "willpower", 0));
if (maxPerSlot == 0)
{
@@ -220,9 +208,7 @@ void ItemManager::reload()
}
LOG_INFO("Loaded " << nbItems << " items from "
- << itemReferenceFile << ".");
-
- xmlFreeDoc(doc);
+ << absPathFile << ".");
}
void ItemManager::deinitialize()
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index fd850534..d551035b 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -176,8 +176,8 @@ void initialize()
ResourceManager::initialize();
if (MapManager::initialize(DEFAULT_MAPSDB_FILE) < 1)
{
- LOG_FATAL("The Game Server can't find any valid/available maps.");
- exit(2);
+ LOG_FATAL("The Game Server can't find any valid/available maps.");
+ exit(2);
}
SkillManager::initialize(DEFAULT_SKILLSDB_FILE);
ItemManager::initialize(DEFAULT_ITEMSDB_FILE);
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index f2f6b396..bee43585 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -39,81 +39,61 @@ const MapManager::Maps &MapManager::getMaps()
return maps;
}
-unsigned int MapManager::initialize(const std::string &mapReferenceFile)
+int MapManager::initialize(const std::string &mapReferenceFile)
{
// Indicates the number of maps loaded successfully
- unsigned int loadedMaps = 0;
-
- int size;
- char *data = ResourceManager::loadFile(mapReferenceFile, size);
+ int loadedMaps = 0;
std::string absPathFile = ResourceManager::resolve(mapReferenceFile);
-
- if (!data) {
+ if (absPathFile.empty()) {
LOG_ERROR("Map Manager: Could not find " << mapReferenceFile << "!");
- free(data);
return loadedMaps;
}
- xmlDocPtr doc = xmlParseMemory(data, size);
- free(data);
+ XML::Document doc(absPathFile, false);
+ xmlNodePtr rootNode = doc.rootNode();
- if (!doc)
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "maps"))
{
- LOG_ERROR("Map Manager: Error while parsing map database ("
+ LOG_ERROR("Item Manager: Error while parsing map database ("
<< absPathFile << ")!");
return loadedMaps;
}
- xmlNodePtr node = xmlDocGetRootElement(doc);
- if (!node || !xmlStrEqual(node->name, BAD_CAST "maps"))
- {
- LOG_ERROR("Map Manager: " << absPathFile
- << " is not a valid database file!");
- xmlFreeDoc(doc);
- return loadedMaps;
- }
-
LOG_INFO("Loading map reference: " << absPathFile);
- for (node = node->xmlChildrenNode; node != NULL; node = node->next)
+ for_each_xml_child_node(node, rootNode)
{
- if (!xmlStrEqual(node->name, BAD_CAST "map")) {
+ if (!xmlStrEqual(node->name, BAD_CAST "map"))
continue;
- }
int id = XML::getProperty(node, "id", 0);
std::string name = XML::getProperty(node, "name", std::string());
- std::string file = "maps/";
- bool mapFileExists = false;
+
// Test id and map name
if (id != 0 && !name.empty())
{
// Testing if the file is actually in the maps folder
- file += name + ".tmx";
- if (!ResourceManager::exists(file))
+ std::string file = std::string("maps/") + name + ".tmx";
+ bool mapFileExists = ResourceManager::exists(file);
+
+ // Try to fall back on fully compressed map
+ if (!mapFileExists)
{
file += ".gz";
- if (ResourceManager::exists(file))
- {
- mapFileExists = true;
- }
- }
- else
- {
- mapFileExists = true;
+ mapFileExists = ResourceManager::exists(file);
}
if (mapFileExists)
{
maps[id] = new MapComposite(id, name);
- loadedMaps++;
+ ++loadedMaps;
}
}
}
- xmlFreeDoc(doc);
if (loadedMaps > 0)
- LOG_INFO(loadedMaps << " valid map file references were loaded.");
+ LOG_INFO(loadedMaps << " valid map file references were loaded.");
+
return loadedMaps;
}
@@ -128,19 +108,17 @@ void MapManager::deinitialize()
MapComposite *MapManager::getMap(int mapId)
{
- Maps::iterator i = maps.find(mapId);
+ Maps::const_iterator i = maps.find(mapId);
return (i != maps.end()) ? i->second : NULL;
}
MapComposite *MapManager::getMap(const std::string &mapName)
{
- Maps::iterator i;
- for (i = maps.begin(); i != maps.end(); ++i)
- {
- if (i->second->getName() == mapName)
- return i->second;
- }
- return NULL;
+ for (Maps::const_iterator i = maps.begin(); i != maps.end(); ++i)
+ if (i->second->getName() == mapName)
+ return i->second;
+
+ return NULL;
}
bool MapManager::raiseActive(int mapId)
@@ -170,6 +148,3 @@ bool MapManager::raiseActive(int mapId)
return false;
}
}
-
-
-
diff --git a/src/game-server/mapmanager.hpp b/src/game-server/mapmanager.hpp
index e28dfb91..d21bd419 100644
--- a/src/game-server/mapmanager.hpp
+++ b/src/game-server/mapmanager.hpp
@@ -32,8 +32,9 @@ namespace MapManager
/**
* Loads map reference file and prepares maps.
+ * @return the number of maps loaded succesfully
*/
- unsigned int initialize(const std::string &mapReferenceFile);
+ int initialize(const std::string &mapReferenceFile);
/**
* Destroy loaded maps.
@@ -48,7 +49,7 @@ namespace MapManager
MapComposite *getMap(int mapId);
/**
- * Returns the requested map
+ * Returns the requested map
*/
MapComposite *getMap(const std::string &mapName);
@@ -64,4 +65,4 @@ namespace MapManager
bool raiseActive(int mapId);
}
-#endif
+#endif // MAPMANAGER_H
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 3e1065d2..00587ae1 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -540,15 +540,11 @@ void MapReader::setTileWithGid(Map *map, int x, int y, int gid)
i_end = ::tilesetFirstGids.end(); i != i_end; ++i)
{
if (gid < *i)
- {
break;
- }
+
set = *i;
}
if (gid!=set)
- {
map->blockTile(x, y, Map::BLOCKTYPE_WALL);
- }
-
}
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index f73a1bec..45772c65 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -62,45 +62,28 @@ void MonsterManager::initialize(const std::string &file)
void MonsterManager::reload()
{
- int size;
- char *data = ResourceManager::loadFile(monsterReferenceFile, size);
-
std::string absPathFile = ResourceManager::resolve(monsterReferenceFile);
-
- if (!data) {
- LOG_ERROR("Monster Manager: Could not find "
- << monsterReferenceFile << "!");
- free(data);
+ if (absPathFile.empty()) {
+ LOG_ERROR("Monster Manager: Could not find " << monsterReferenceFile << "!");
return;
}
- xmlDocPtr doc = xmlParseMemory(data, size);
- free(data);
+ XML::Document doc(absPathFile, false);
+ xmlNodePtr rootNode = doc.rootNode();
- if (!doc)
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters"))
{
LOG_ERROR("Monster Manager: Error while parsing monster database ("
<< absPathFile << ")!");
return;
}
- xmlNodePtr node = xmlDocGetRootElement(doc);
- if (!node || !xmlStrEqual(node->name, BAD_CAST "monsters"))
- {
- LOG_ERROR("Monster Manager: " << absPathFile
- << " is not a valid database file!");
- xmlFreeDoc(doc);
- return;
- }
-
LOG_INFO("Loading monster reference: " << absPathFile);
int nbMonsters = 0;
- for (node = node->xmlChildrenNode; node != NULL; node = node->next)
+ for_each_xml_child_node(node, rootNode)
{
if (!xmlStrEqual(node->name, BAD_CAST "monster"))
- {
continue;
- }
int id = XML::getProperty(node, "id", -1);
std::string name = XML::getProperty(node, "name", "unnamed");
@@ -108,8 +91,8 @@ void MonsterManager::reload()
if (id == -1)
{
LOG_WARN("Monster Manager: There is a monster ("
- << name << ") without ID in "
- << monsterReferenceFile << "! It has been ignored.");
+ << name << ") without ID in "
+ << monsterReferenceFile << "! It has been ignored.");
continue;
}
@@ -288,8 +271,6 @@ void MonsterManager::reload()
LOG_INFO("Loaded " << nbMonsters << " monsters from "
<< monsterReferenceFile << '.');
-
- xmlFreeDoc(doc);
}
void MonsterManager::deinitialize()
diff --git a/src/game-server/monstermanager.hpp b/src/game-server/monstermanager.hpp
index fb80fc05..18377bc5 100644
--- a/src/game-server/monstermanager.hpp
+++ b/src/game-server/monstermanager.hpp
@@ -48,4 +48,4 @@ namespace MonsterManager
MonsterClass *getMonster(int id);
}
-#endif
+#endif // MONSTERMANAGER_HPP
diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp
index 2ca5a8a3..0e64df6b 100644
--- a/src/game-server/statusmanager.cpp
+++ b/src/game-server/statusmanager.cpp
@@ -42,43 +42,27 @@ void StatusManager::initialize(const std::string &file)
void StatusManager::reload()
{
- int size;
- char *data = ResourceManager::loadFile(statusReferenceFile, size);
-
std::string absPathFile = ResourceManager::resolve(statusReferenceFile);
-
- if (!data) {
+ if (absPathFile.empty()) {
LOG_ERROR("Status Manager: Could not find " << statusReferenceFile << "!");
- free(data);
return;
}
- xmlDocPtr doc = xmlParseMemory(data, size);
- free(data);
+ XML::Document doc(absPathFile, false);
+ xmlNodePtr rootNode = doc.rootNode();
- if (!doc)
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "status-effects"))
{
LOG_ERROR("Status Manager: Error while parsing status database ("
<< absPathFile << ")!");
return;
}
- xmlNodePtr node = xmlDocGetRootElement(doc);
- if (!node || !xmlStrEqual(node->name, BAD_CAST "status-effects"))
- {
- LOG_ERROR("Status Manager: " << absPathFile
- << " is not a valid database file!");
- xmlFreeDoc(doc);
- return;
- }
-
LOG_INFO("Loading status reference: " << absPathFile);
- for (node = node->xmlChildrenNode; node != NULL; node = node->next)
+ for_each_xml_child_node(node, rootNode)
{
if (!xmlStrEqual(node->name, BAD_CAST "status-effect"))
- {
continue;
- }
int id = XML::getProperty(node, "id", 0);
if (id == 0)
@@ -120,8 +104,6 @@ void StatusManager::reload()
}
statusEffects[id] = statusEffect;
}
-
- xmlFreeDoc(doc);
}
void StatusManager::deinitialize()
diff --git a/src/game-server/statusmanager.hpp b/src/game-server/statusmanager.hpp
index 4533a5b0..fc09adb5 100644
--- a/src/game-server/statusmanager.hpp
+++ b/src/game-server/statusmanager.hpp
@@ -48,4 +48,4 @@ namespace StatusManager
StatusEffect *getStatus(int statusId);
}
-#endif
+#endif // STATUSMANAGER_H