summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2007-07-17 18:05:07 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2007-07-17 18:05:07 +0000
commit28010750064bdf3bc8aea36565d788d8a068ef2a (patch)
tree3b4cbe4889a041a634180af8f6474d3b6d3fb08f /src/game-server
parent2359f42b667f9f0ac182bb1dccd26bd5c034717a (diff)
downloadmanaserv-28010750064bdf3bc8aea36565d788d8a068ef2a.tar.gz
manaserv-28010750064bdf3bc8aea36565d788d8a068ef2a.tar.bz2
manaserv-28010750064bdf3bc8aea36565d788d8a068ef2a.tar.xz
manaserv-28010750064bdf3bc8aea36565d788d8a068ef2a.zip
Implemented loading of warp and spawn areas from map files.
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/mapmanager.cpp13
-rw-r--r--src/game-server/mapreader.cpp134
-rw-r--r--src/game-server/mapreader.hpp3
-rw-r--r--src/game-server/testing.cpp18
4 files changed, 133 insertions, 35 deletions
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index 58aace14..ab0d0fec 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -117,18 +117,13 @@ void MapManager::raiseActive(int mapId)
}
std::string const &file = composite->getName();
- Map *map = MapReader::readMap("maps/" + file);
- if (!map)
- {
- LOG_ERROR("Unable to load map \"" << file << "\" (id "
- << mapId << ")");
- return;
- }
+ MapReader::readMap("maps/" + file, composite);
- composite->setMap(map);
LOG_INFO("Activated map \"" << file << "\" (id " << mapId << ")");
- // will need to load extra map related resources here also
+ // Add some testing stuff
extern void testingMap(MapComposite *);
testingMap(composite);
}
+
+
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index db16cc3e..f7f98811 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -23,7 +23,12 @@
#include "resourcemanager.h"
#include "game-server/map.hpp"
+#include "game-server/mapcomposite.hpp"
+#include "game-server/mapmanager.hpp"
#include "game-server/mapreader.hpp"
+#include "game-server/monstermanager.hpp"
+#include "game-server/spawnarea.hpp"
+#include "game-server/trigger.hpp"
#include "utils/base64.h"
#include "utils/logger.h"
#include "utils/xml.hpp"
@@ -31,11 +36,11 @@
static std::vector< int > tilesetFirstGids;
-static Map* readMap(xmlNodePtr node, std::string const &path);
+static Map* readMap(xmlNodePtr node, std::string const &path, MapComposite *composite, std::vector<Thing *> &things);
static void readLayer(xmlNodePtr node, Map *map);
static void setTileWithGid(Map *map, int x, int y, int gid);
-Map *MapReader::readMap(const std::string &filename)
+void MapReader::readMap(const std::string &filename, MapComposite *composite)
{
// Load the file through resource manager.
ResourceManager *resman = ResourceManager::getInstance();
@@ -45,7 +50,7 @@ Map *MapReader::readMap(const std::string &filename)
if (buffer == NULL)
{
LOG_ERROR("Error: Map file not found (" << filename.c_str() << ")");
- return NULL;
+ return;
}
// Inflate the gzipped map data.
@@ -65,16 +70,18 @@ Map *MapReader::readMap(const std::string &filename)
if (!doc)
{
LOG_ERROR("Error while parsing map file (" << filename << ")!");
- return NULL;
+ return;
}
Map *map = NULL;
xmlNodePtr node = xmlDocGetRootElement(doc);
+ std::vector<Thing *> things;
+
// Parse the inflated map data.
if (node && xmlStrEqual(node->name, BAD_CAST "map"))
{
- map = ::readMap(node, filename);
+ map = ::readMap(node, filename, composite, things);
}
else
{
@@ -82,10 +89,20 @@ Map *MapReader::readMap(const std::string &filename)
}
xmlFreeDoc(doc);
- return map;
+
+ if (map != NULL)
+ {
+ composite->setMap(map);
+
+ for (std::vector< Thing * >::const_iterator i = things.begin(),
+ i_end = things.end(); i != i_end; ++i)
+ {
+ composite->insert(*i);
+ }
+ }
}
-static Map *readMap(xmlNodePtr node, std::string const &path)
+static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *composite, std::vector<Thing *> &things)
{
// Take the filename off the path
std::string pathDir = path.substr(0, path.rfind("/") + 1);
@@ -137,6 +154,109 @@ static Map *readMap(xmlNodePtr node, std::string const &path)
readLayer(node, map);
}
}
+ else if (xmlStrEqual(node->name, BAD_CAST "objectgroup"))
+ {
+ //readObjectGroup(node, map);
+ for_each_xml_child_node(objectNode, node)
+ {
+ if (!xmlStrEqual(objectNode->name, BAD_CAST "object"))
+ {
+ continue;
+ }
+
+ std::string objName = XML::getProperty(objectNode, "name", "");
+ std::string objType = XML::getProperty(objectNode, "type", "");
+ int objX = XML::getProperty(objectNode, "x", 0);
+ int objY = XML::getProperty(objectNode, "y", 0);
+ int objW = XML::getProperty(objectNode, "width", 0);
+ int objH = XML::getProperty(objectNode, "height", 0);
+ Rectangle rect = { objX, objY, objW, objH };
+
+
+ if (objType == "WARP")
+ {
+ for_each_xml_child_node(propertiesNode, objectNode)
+ {
+ if (!xmlStrEqual(propertiesNode->name, BAD_CAST "properties"))
+ {
+ continue;
+ }
+
+ int destMapId = -1;
+ int destX = -1;
+ int destY = -1;
+
+ for_each_xml_child_node(propertyNode, propertiesNode)
+ {
+ if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
+ {
+ std::string value = XML::getProperty(propertyNode, "name", std::string());
+ if (value == "DEST_MAP")
+ {
+ destMapId = atoi((const char *)propertyNode->xmlChildrenNode->content);
+ }
+ else if (value == "DEST_X")
+ {
+ destX = atoi((const char *)propertyNode->xmlChildrenNode->content);
+ }
+ else if (value == "DEST_Y")
+ {
+ destY = atoi((const char *)propertyNode->xmlChildrenNode->content);
+ }
+ }
+ }
+
+ if (destMapId != -1 && destX != -1 && destY != -1)
+ {
+ MapComposite *destMap = MapManager::getMap(destMapId);
+ if (destMap)
+ {
+ things.push_back(new TriggerArea(
+ composite, rect,
+ new WarpAction(destMap, destX, destY)));
+ }
+ }
+ else
+ {
+ LOG_WARN("Unrecognized warp format");
+ }
+ }
+ }
+ else if (objType == "SPAWN")
+ {
+ for_each_xml_child_node(propertiesNode, objectNode)
+ {
+ if (!xmlStrEqual(propertiesNode->name, BAD_CAST "properties"))
+ {
+ continue;
+ }
+
+ int monsterId = -1;
+
+ for_each_xml_child_node(propertyNode, propertiesNode)
+ {
+ if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
+ {
+ if (XML::getProperty(propertyNode, "name", std::string()) == "MONSTER_ID")
+ {
+ monsterId = atoi((const char *)propertyNode->xmlChildrenNode->content);
+ }
+ }
+ }
+
+ MonsterClass *monster = MonsterManager::getMonster(monsterId);
+ if (monster != NULL)
+ {
+ things.push_back(new SpawnArea(composite, monster, rect));
+ }
+ else
+ {
+ LOG_WARN("Unrecognized format for spawn area");
+ }
+ }
+ }
+ }
+ }
}
// Clean up tilesets
diff --git a/src/game-server/mapreader.hpp b/src/game-server/mapreader.hpp
index ed49b24d..473b59c6 100644
--- a/src/game-server/mapreader.hpp
+++ b/src/game-server/mapreader.hpp
@@ -27,6 +27,7 @@
#include <string>
class Map;
+class MapComposite;
/**
* Reader for XML map files (*.tmx)
@@ -37,7 +38,7 @@ class MapReader
/**
* Read an XML map from a file.
*/
- static Map *readMap(const std::string &filename);
+ static void readMap(const std::string &filename, MapComposite *composite);
};
#endif
diff --git a/src/game-server/testing.cpp b/src/game-server/testing.cpp
index 31f26d6a..01cb4e4f 100644
--- a/src/game-server/testing.cpp
+++ b/src/game-server/testing.cpp
@@ -27,31 +27,13 @@ static void dropItem(MapComposite *map, int x, int y, int type)
void testingMap(MapComposite *map)
{
- static Rectangle rectA = { 56 * 32, 12 * 32, 5 * 32, 32 };
- static WarpAction warpA(MapManager::getMap(3), 44 * 32 + 16, 80 * 32 + 16);
- static Rectangle rectB = { 42 * 32, 88 * 32, 5 * 32, 32 };
- static WarpAction warpB(MapManager::getMap(1), 58 * 32 + 16, 17 * 32 + 16);
-
switch (map->getID())
{
case 1:
{
- // Create maggot spawn area
- Rectangle maggotSpawnRect = { 720, 900, 320, 320 };
- GameState::insert(new SpawnArea(map, MonsterManager::getMonster(1002), maggotSpawnRect));
-
- // Portal to map 3
- GameState::insert(new TriggerArea(map, rectA, &warpA));
-
// Drop some items
dropItem(map, 58 * 32 + 16, 20 * 32 + 16, 508);
dropItem(map, 58 * 32 + 16, 21 * 32 + 16, 524);
} break;
-
- case 3:
- {
- // Portal to map 1
- GameState::insert(new TriggerArea(map, rectB, &warpB));
- } break;
}
}