summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrzemysław Grzywacz <nexather@gmail.com>2013-05-03 15:16:34 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-05-03 15:28:41 +0200
commitf6f27a9ffaf72f9856240db1bb788a9efa3e86f0 (patch)
tree2be68e1fd640061f0bdd062e906e2521879fef31
parenteb9fdd6852fced4ca9125b93585b95eb319dce18 (diff)
downloadmanaserv-f6f27a9ffaf72f9856240db1bb788a9efa3e86f0.tar.gz
manaserv-f6f27a9ffaf72f9856240db1bb788a9efa3e86f0.tar.xz
manaserv-f6f27a9ffaf72f9856240db1bb788a9efa3e86f0.zip
Maps are now configured in settings.xml too
-rw-r--r--AUTHORS1
-rw-r--r--example/settings.xml1
-rw-r--r--src/game-server/main-game.cpp5
-rw-r--r--src/game-server/mapmanager.cpp121
-rw-r--r--src/game-server/mapmanager.h17
-rw-r--r--src/game-server/settingsmanager.cpp9
6 files changed, 84 insertions, 70 deletions
diff --git a/AUTHORS b/AUTHORS
index 4db5787..8ee2d8b 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -8,5 +8,6 @@ Guillaume Melquiond <guillaume.melquiond@gmail.com>
Huynh Ngoc Chau Tran aka kindjal <nthuynh at users dot sourceforge dot net>
jurkan <jurkan@gmx.de>
Philipp Sehmisch <tmw@crushnet.org>
+Przemysław Grzywacz <nexather@gmail.com>
seeseekey <seeseekey@googlemail.com>
Yohann Ferreira <Bertram@cegetel.net>
diff --git a/example/settings.xml b/example/settings.xml
index 5641d71..ebe7a71 100644
--- a/example/settings.xml
+++ b/example/settings.xml
@@ -1,4 +1,5 @@
<settings>
+ <include file="maps.xml" />
<include file="attributes.xml" />
<include file="skills.xml" />
<include file="specials.xml" />
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index e21b1dd..894af5f 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -128,11 +128,6 @@ static void initializeServer()
ResourceManager::initialize();
ScriptManager::initialize(); // Depends on ResourceManager
- if (MapManager::initialize(DEFAULT_MAPSDB_FILE) < 1)
- {
- LOG_FATAL("The Game Server can't find any valid/available maps.");
- exit(EXIT_MAP_FILE_NOT_FOUND);
- }
// load game settings files
settingsManager->initialize();
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index 50f79cd..f3e9fcf 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -22,10 +22,10 @@
#include "game-server/mapmanager.h"
#include "common/resourcemanager.h"
+#include "common/defines.h"
#include "game-server/map.h"
#include "game-server/mapcomposite.h"
#include "utils/logger.h"
-#include "utils/xml.h"
#include <cassert>
@@ -39,80 +39,87 @@ const MapManager::Maps &MapManager::getMaps()
return maps;
}
-int MapManager::initialize(const std::string &mapReferenceFile)
+void MapManager::initialize()
{
- // Indicates the number of maps loaded successfully
- int loadedMaps = 0;
- XML::Document doc(mapReferenceFile);
- xmlNodePtr rootNode = doc.rootNode();
+}
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "maps"))
+/**
+ * Destroys all maps.
+ */
+void MapManager::deinitialize()
+{
+ for (Maps::iterator i = maps.begin(), i_end = maps.end(); i != i_end; ++i)
{
- LOG_ERROR("Item Manager: Error while parsing map database ("
- << mapReferenceFile << ")!");
- return loadedMaps;
+ delete i->second;
}
+ maps.clear();
+}
- LOG_INFO("Loading map reference: " << mapReferenceFile);
- for_each_xml_child_node(node, rootNode)
- {
- if (!xmlStrEqual(node->name, BAD_CAST "map"))
- continue;
+/**
+ * Prepare map manager for a reload.
+ */
+void MapManager::reload()
+{
+ // TODO: this method needs proper map reloading
+ LOG_ERROR("MapManager::reload() not implemented yet");
+}
+
+/**
+ * Read a <map> node from settings
+ */
+void MapManager::readMapNode(xmlNodePtr node)
+{
+ int id = XML::getProperty(node, "id", 0);
+ std::string name = XML::getProperty(node, "name", std::string());
- int id = XML::getProperty(node, "id", 0);
- std::string name = XML::getProperty(node, "name", std::string());
- // Test id and map name
- if (id > 0 && !name.empty())
+ if (id <= 0)
+ {
+ LOG_WARN("Invalid map Id: " << id << " for map: "
+ << name << '.');
+ }
+ else if (name.empty())
+ {
+ LOG_WARN("Invalid unnamed map Id: " << id << '.');
+ }
+ else
+ {
+ // Testing if the file is actually in the maps folder
+ std::string file = std::string("maps/") + name + ".tmx";
+ bool mapFileExists = ResourceManager::exists(file);
+
+ // Try to fall back on fully compressed map
+ if (!mapFileExists)
{
- // Testing if the file is actually in the maps folder
- 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";
- mapFileExists = ResourceManager::exists(file);
- }
-
- if (mapFileExists)
- {
- maps[id] = new MapComposite(id, name);
- if (!maps[id]->readMap())
- LOG_FATAL("Failed to load map \"" << name << "\"!");
-
- ++loadedMaps;
- }
+ file += ".gz";
+ mapFileExists = ResourceManager::exists(file);
}
- else
+
+ if (mapFileExists)
{
- if (name.empty())
- {
- LOG_WARN("Invalid unnamed map Id: " << id << '.');
- }
- else
- {
- LOG_WARN("Invalid map Id: " << id << " for map: "
- << name << '.');
- }
+ maps[id] = new MapComposite(id, name);
+ if (!maps[id]->readMap())
+ LOG_FATAL("Failed to load map \"" << name << "\"!");
}
}
-
- if (loadedMaps > 0)
- LOG_INFO(loadedMaps << " valid map file references were loaded.");
-
- return loadedMaps;
}
-void MapManager::deinitialize()
+/**
+ * Check the status of recently loaded configuration.
+ */
+void MapManager::checkStatus()
{
- for (Maps::iterator i = maps.begin(), i_end = maps.end(); i != i_end; ++i)
+ int loadedMaps = maps.size();
+ if (loadedMaps > 0)
{
- delete i->second;
+ LOG_INFO(loadedMaps << " valid map file references were loaded.");
+ }
+ else
+ {
+ LOG_FATAL("The Game Server can't find any valid/available maps.");
+ exit(EXIT_MAP_FILE_NOT_FOUND);
}
- maps.clear();
}
MapComposite *MapManager::getMap(int mapId)
diff --git a/src/game-server/mapmanager.h b/src/game-server/mapmanager.h
index 12cbc34..b1b4759 100644
--- a/src/game-server/mapmanager.h
+++ b/src/game-server/mapmanager.h
@@ -25,23 +25,24 @@
#include <map>
#include <string>
+#include "utils/xml.h"
+
class MapComposite;
namespace MapManager
{
typedef std::map< int, MapComposite * > Maps;
- /**
- * Loads map reference file and prepares maps.
- * @return the number of maps loaded succesfully
- */
- int initialize(const std::string &mapReferenceFile);
+ void initialize();
- /**
- * Destroy loaded maps.
- */
void deinitialize();
+ void reload();
+
+ void readMapNode(xmlNodePtr node);
+
+ void checkStatus();
+
/**
* Returns the requested map.
*
diff --git a/src/game-server/settingsmanager.cpp b/src/game-server/settingsmanager.cpp
index 79aade1..b45ef93 100644
--- a/src/game-server/settingsmanager.cpp
+++ b/src/game-server/settingsmanager.cpp
@@ -25,6 +25,7 @@
#include "common/resourcemanager.h"
+#include "game-server/mapmanager.h"
#include "game-server/attributemanager.h"
#include "game-server/skillmanager.h"
#include "game-server/specialmanager.h"
@@ -41,6 +42,7 @@
void SettingsManager::initialize()
{
// initialize all managers in correct order
+ MapManager::initialize();
attributeManager->initialize();
skillManager->initialize();
specialManager->initialize();
@@ -61,6 +63,7 @@ void SettingsManager::initialize()
*/
void SettingsManager::reload()
{
+ MapManager::reload();
attributeManager->reload();
skillManager->reload();
specialManager->reload();
@@ -125,6 +128,11 @@ void SettingsManager::loadFile(const std::string &filename)
}
}
}
+ else if (xmlStrEqual(childNode->name, BAD_CAST "map"))
+ {
+ // map config
+ MapManager::readMapNode(childNode);
+ }
else if (xmlStrEqual(childNode->name, BAD_CAST "attribute"))
{
// attribute config
@@ -181,6 +189,7 @@ void SettingsManager::loadFile(const std::string &filename)
*/
void SettingsManager::checkStatus()
{
+ MapManager::checkStatus();
attributeManager->checkStatus();
skillManager->checkStatus();
specialManager->checkStatus();