summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-13 21:23:33 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-13 21:59:10 +0200
commitbf32ca896ccf51385eb67812088ba5861ca2ede2 (patch)
tree02cc6a7f8de3ef48b6092668368f3b5ba8f35683
parent774e86e8d2f8d787fb3b3a865cd500f166153c96 (diff)
downloadplus-bf32ca896ccf51385eb67812088ba5861ca2ede2.tar.gz
plus-bf32ca896ccf51385eb67812088ba5861ca2ede2.tar.bz2
plus-bf32ca896ccf51385eb67812088ba5861ca2ede2.tar.xz
plus-bf32ca896ccf51385eb67812088ba5861ca2ede2.zip
Add ability to remap maps to different files.
-rw-r--r--manaplus.cbp2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp2
-rw-r--r--src/game.cpp10
-rw-r--r--src/gui/debugwindow.cpp2
-rw-r--r--src/gui/killstats.cpp4
-rw-r--r--src/localplayer.cpp6
-rw-r--r--src/map.cpp3
-rw-r--r--src/resources/mapdb.cpp88
-rw-r--r--src/resources/mapdb.h50
-rw-r--r--src/resources/mapreader.cpp30
-rw-r--r--src/resources/mapreader.h3
13 files changed, 179 insertions, 25 deletions
diff --git a/manaplus.cbp b/manaplus.cbp
index b25db4e17..8839b8765 100644
--- a/manaplus.cbp
+++ b/manaplus.cbp
@@ -586,6 +586,8 @@
<Unit filename="src\resources\itemdb.h" />
<Unit filename="src\resources\iteminfo.cpp" />
<Unit filename="src\resources\iteminfo.h" />
+ <Unit filename="src\resources\mapdb.cpp" />
+ <Unit filename="src\resources\mapdb.h" />
<Unit filename="src\resources\mapreader.cpp" />
<Unit filename="src\resources\mapreader.h" />
<Unit filename="src\resources\monsterdb.cpp" />
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4e12bcc21..4534457ba 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -409,6 +409,8 @@ SET(SRCS
resources/itemdb.h
resources/iteminfo.h
resources/iteminfo.cpp
+ resources/mapdb.cpp
+ resources/mapdb.h
resources/mapreader.cpp
resources/mapreader.h
resources/monsterdb.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 09533b114..a51cdd64a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -300,6 +300,8 @@ manaplus_SOURCES = gui/widgets/avatarlistbox.cpp \
resources/itemdb.h \
resources/iteminfo.h \
resources/iteminfo.cpp \
+ resources/mapdb.cpp \
+ resources/mapdb.h \
resources/mapreader.cpp \
resources/mapreader.h \
resources/monsterdb.cpp \
diff --git a/src/client.cpp b/src/client.cpp
index 5c183a17d..8b7eea4e9 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -80,6 +80,7 @@
#include "resources/emotedb.h"
#include "resources/image.h"
#include "resources/itemdb.h"
+#include "resources/mapdb.h"
#include "resources/monsterdb.h"
#include "resources/specialdb.h"
#include "resources/npcdb.h"
@@ -954,6 +955,7 @@ int Client::exec()
// Load XML databases
ColorDB::load();
+ MapDB::load();
ItemDB::load();
Being::load(); // Hairstyles
MonsterDB::load();
diff --git a/src/game.cpp b/src/game.cpp
index fe459f804..21758f66b 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -92,6 +92,7 @@
#include "net/playerhandler.h"
#include "resources/imagewriter.h"
+#include "resources/mapdb.h"
#include "resources/mapreader.h"
#include "resources/resourcemanager.h"
@@ -1386,12 +1387,15 @@ void Game::changeMap(const std::string &mapPath)
std::string fullMap = paths.getValue("maps", "maps/")
+ mMapName + ".tmx";
+ std::string realFullMap = paths.getValue("maps", "maps/")
+ + MapDB::getMapName(mMapName) + ".tmx";
+
ResourceManager *resman = ResourceManager::getInstance();
- if (!resman->exists(fullMap))
- fullMap += ".gz";
+ if (!resman->exists(realFullMap))
+ realFullMap += ".gz";
// Attempt to load the new map
- Map *newMap = MapReader::readMap(fullMap);
+ Map *newMap = MapReader::readMap(fullMap, realFullMap);
if (!newMap)
{
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index 7707c0935..1b436a617 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -184,7 +184,7 @@ void DebugWindow::logic()
mMinimapLabel->setCaption(strprintf("%s %s", _("Minimap:"),
map->getProperty("minimap").c_str()));
mMapLabel->setCaption(strprintf("%s %s", _("Map:"),
- map->getProperty("_filename").c_str()));
+ map->getProperty("_realfilename").c_str()));
if (mUpdateTime != cur_time)
diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp
index 8ce38c719..9bbbc8549 100644
--- a/src/gui/killstats.cpp
+++ b/src/gui/killstats.cpp
@@ -385,8 +385,8 @@ void KillStats::validateJacko()
Map *currentMap = Game::instance()->getCurrentMap();
if (currentMap)
{
- if (currentMap->getProperty("_filename") == "018-1"
- || currentMap->getProperty("_filename") == "maps/018-1.tmx")
+ if (currentMap->getProperty("_realfilename") == "018-1"
+ || currentMap->getProperty("_realfilename") == "maps/018-1.tmx")
{
if (player_node->getTileX() >= 167
&& player_node->getTileX() <= 175
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 3bd075f45..4cb944439 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -1712,7 +1712,7 @@ void LocalPlayer::moveToHome()
else
{
std::map<std::string, Vector>::iterator iter =
- mHomes.find(mMap->getProperty("_filename"));
+ mHomes.find(mMap->getProperty("_realfilename"));
if (iter != mHomes.end())
{
@@ -2882,7 +2882,7 @@ void LocalPlayer::setHome()
if (!specialLayer)
return;
- std::string key = mMap->getProperty("_filename");
+ std::string key = mMap->getProperty("_realfilename");
Vector pos = mHomes[key];
if (mAction == SIT)
@@ -3651,7 +3651,7 @@ void LocalPlayer::updateNavigateList()
if (mMap)
{
std::map<std::string, Vector>::iterator iter =
- mHomes.find(mMap->getProperty("_filename"));
+ mHomes.find(mMap->getProperty("_realfilename"));
if (iter != mHomes.end())
{
diff --git a/src/map.cpp b/src/map.cpp
index 855570eb8..c5cd1e3b5 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -1333,7 +1333,8 @@ void Map::saveExtraLayer()
std::string Map::getUserMapDirectory() const
{
- return Client::getServerConfigDirectory() + "/" + getProperty("_filename");
+ return Client::getServerConfigDirectory() + "/"
+ + getProperty("_realfilename");
}
void Map::addPortal(const std::string &name, int type,
diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp
new file mode 100644
index 000000000..37b127c02
--- /dev/null
+++ b/src/resources/mapdb.cpp
@@ -0,0 +1,88 @@
+/*
+ * Color database
+ * Copyright (C) 2008 Aethyra Development Team
+ * Copyright (C) 2011 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/mapdb.h"
+
+#include "configuration.h"
+#include "client.h"
+#include "log.h"
+
+#include "utils/xml.h"
+
+#include <libxml/tree.h>
+
+namespace
+{
+ bool mLoaded = false;
+ MapDB::Maps mMaps;
+}
+
+void MapDB::load()
+{
+ if (mLoaded)
+ unload();
+
+ XML::Document *doc = new XML::Document(
+ paths.getStringValue("maps") + "remap.xml");
+
+ xmlNodePtr root = doc->rootNode();
+ if (!root)
+ return;
+
+ for_each_xml_child_node(node, root)
+ {
+ if (xmlStrEqual(node->name, BAD_CAST "map"))
+ {
+ std::string name = XML::getProperty(node, "name", "");
+ if (name.empty())
+ continue;
+
+ std::string value = XML::getProperty(node, "value", "");
+ if (value.empty())
+ continue;
+
+ mMaps[name] = value;
+ }
+ }
+
+ delete doc;
+
+ mLoaded = true;
+}
+
+
+void MapDB::unload()
+{
+ logger->log1("Unloading map database...");
+
+ mMaps.clear();
+ mLoaded = false;
+}
+
+std::string MapDB::getMapName(std::string name)
+{
+ MapIterator it = mMaps.find(name);
+ logger->log("map: " + name);
+
+ if (it != mMaps.end())
+ return it->second;
+ return name;
+}
diff --git a/src/resources/mapdb.h b/src/resources/mapdb.h
new file mode 100644
index 000000000..2ba084297
--- /dev/null
+++ b/src/resources/mapdb.h
@@ -0,0 +1,50 @@
+/*
+ * Color database
+ * Copyright (C) 2008 Aethyra Development Team
+ * Copyright (C) 2011 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAPDB_H
+#define MAPDB_H
+
+#include <map>
+#include <string>
+
+/**
+ * Color information database.
+ */
+namespace MapDB
+{
+ /**
+ * Loads the map remap data from <code>maps\remap.xml</code>.
+ */
+ void load();
+
+ /**
+ * Clear the remap data
+ */
+ void unload();
+
+ std::string getMapName(std::string name);
+
+ // Maps DB
+ typedef std::map<std::string, std::string> Maps;
+ typedef Maps::iterator MapIterator;
+}
+
+#endif
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 5a635a8c2..d3cd22988 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -29,6 +29,7 @@
#include "resources/animation.h"
#include "resources/image.h"
+#include "resources/mapdb.h"
#include "resources/resourcemanager.h"
#include "utils/base64.h"
@@ -177,25 +178,26 @@ int inflateMemory(unsigned char *in, unsigned int inLength,
return outLength;
}
-Map *MapReader::readMap(const std::string &filename)
+Map *MapReader::readMap(const std::string &filename,
+ const std::string &realFilename)
{
- logger->log("Attempting to read map %s", filename.c_str());
+ logger->log("Attempting to read map %s", realFilename.c_str());
// Load the file through resource manager
ResourceManager *resman = ResourceManager::getInstance();
int fileSize;
- void *buffer = resman->loadFile(filename, fileSize);
+ void *buffer = resman->loadFile(realFilename, fileSize);
Map *map = NULL;
if (buffer == NULL)
{
- logger->log("Map file not found (%s)", filename.c_str());
+ logger->log("Map file not found (%s)", realFilename.c_str());
return NULL;
}
unsigned char *inflated;
unsigned int inflatedSize;
- if (filename.find(".gz", filename.length() - 3) != std::string::npos)
+ if (realFilename.find(".gz", realFilename.length() - 3) != std::string::npos)
{
// Inflate the gzipped map data
inflatedSize =
@@ -205,7 +207,7 @@ Map *MapReader::readMap(const std::string &filename)
if (inflated == NULL)
{
logger->log("Could not decompress map file (%s)",
- filename.c_str());
+ realFilename.c_str());
return NULL;
}
}
@@ -224,20 +226,20 @@ Map *MapReader::readMap(const std::string &filename)
if (node)
{
if (!xmlStrEqual(node->name, BAD_CAST "map"))
- {
- logger->log("Error: Not a map file (%s)!", filename.c_str());
- }
+ logger->log("Error: Not a map file (%s)!", realFilename.c_str());
else
- {
- map = readMap(node, filename);
- }
+ map = readMap(node, realFilename);
}
else
{
- logger->log("Error while parsing map file (%s)!", filename.c_str());
+ logger->log("Error while parsing map file (%s)!", realFilename.c_str());
}
- if (map) map->setProperty("_filename", filename);
+ if (map)
+ {
+ map->setProperty("_filename", realFilename);
+ map->setProperty("_realfilename", filename);
+ }
return map;
}
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 6995aaf8e..927b76173 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -46,7 +46,8 @@ class MapReader
/**
* Read an XML map from a file.
*/
- static Map *readMap(const std::string &filename);
+ static Map *readMap(const std::string &filename,
+ const std::string &realFilename);
/**
* Read an XML map from a parsed XML tree. The path is used to find the