summaryrefslogtreecommitdiff
path: root/src/resources/mapreader.cpp
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 /src/resources/mapreader.cpp
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.
Diffstat (limited to 'src/resources/mapreader.cpp')
-rw-r--r--src/resources/mapreader.cpp30
1 files changed, 16 insertions, 14 deletions
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;
}