summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-06-14 09:27:43 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-06-14 09:27:43 +0000
commitd7904f7b7e25bbdd7205e5c18e06d184b2078732 (patch)
tree7f19693da61eb4a5944c220d3085530fd2e2a407 /src
parent24b1c618a11170e825598c5e22bf71f9238eae52 (diff)
downloadmana-client-d7904f7b7e25bbdd7205e5c18e06d184b2078732.tar.gz
mana-client-d7904f7b7e25bbdd7205e5c18e06d184b2078732.tar.bz2
mana-client-d7904f7b7e25bbdd7205e5c18e06d184b2078732.tar.xz
mana-client-d7904f7b7e25bbdd7205e5c18e06d184b2078732.zip
Added support for map properties, which minimap and background music
functionality can be based upon.
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp2
-rw-r--r--src/map.cpp22
-rw-r--r--src/map.h19
-rw-r--r--src/resources/mapreader.cpp17
4 files changed, 59 insertions, 1 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 973523ed..9c39b3aa 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -492,6 +492,8 @@ void Engine::draw()
std::stringstream debugStream;
debugStream << "[" << fps << " fps] " <<
(mouseX / 32 + camera_x) << ", " << (mouseY / 32 + camera_y);
+ debugStream << " [music: " << tiledMap->getProperty("music") << "]";
+ debugStream << " [minimap: " << tiledMap->getProperty("minimap") << "]";
debugInfo->setCaption(debugStream.str());
debugInfo->adjustSize();
}
diff --git a/src/map.cpp b/src/map.cpp
index 5f522dfb..24c9b5b4 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -177,6 +177,28 @@ int Map::getTileHeight()
return tileHeight;
}
+std::string Map::getProperty(const std::string &name)
+{
+ std::map<std::string,std::string>::iterator i = properties.find(name);
+
+ if (i != properties.end())
+ {
+ return (*i).second;
+ }
+
+ return "";
+}
+
+bool Map::hasProperty(const std::string &name)
+{
+ return (properties.find(name) != properties.end());
+}
+
+void Map::setProperty(const std::string &name, const std::string &value)
+{
+ properties[name] = value;
+}
+
std::list<PATH_NODE> Map::findPath(
int startX, int startY, int destX, int destY)
{
diff --git a/src/map.h b/src/map.h
index d3bf20b1..02bea4a2 100644
--- a/src/map.h
+++ b/src/map.h
@@ -159,11 +159,30 @@ class Map
std::list<PATH_NODE> findPath(
int startX, int startY, int destX, int destY);
+ /**
+ * Get a map property.
+ *
+ * @return the value of the given property or an empty string when it
+ * doesn't exist.
+ */
+ std::string getProperty(const std::string &name);
+
+ /**
+ * Returns whether a certain property is available.
+ */
+ bool hasProperty(const std::string &name);
+
+ /**
+ * Set a map property.
+ */
+ void setProperty(const std::string &name, const std::string &value);
+
private:
int width, height;
int tileWidth, tileHeight;
MetaTile *metaTiles;
Image **tiles;
+ std::map<std::string,std::string> properties;
// Pathfinding members
int onClosedList, onOpenList;
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index da7364a4..b62e6029 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -106,7 +106,22 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path)
for (node = node->xmlChildrenNode; node != NULL; node = node->next)
{
- if (xmlStrEqual(node->name, BAD_CAST "tileset"))
+ if (xmlStrEqual(node->name, BAD_CAST "property"))
+ {
+ // Example: <property name="name" value="value"/>
+
+ xmlChar *name = xmlGetProp(node, BAD_CAST "name");
+ xmlChar *value = xmlGetProp(node, BAD_CAST "value");
+
+ if (name && value)
+ {
+ map->setProperty((const char*)name, (const char*)value);
+ }
+
+ if (name) xmlFree(name);
+ if (value) xmlFree(value);
+ }
+ else if (xmlStrEqual(node->name, BAD_CAST "tileset"))
{
Tileset *tileset = readTileset(node, pathDir, map);
if (tileset) {