diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | gameserver.cbp | 16 | ||||
-rw-r--r-- | src/game-server/mapmanager.cpp | 13 | ||||
-rw-r--r-- | src/game-server/mapreader.cpp | 134 | ||||
-rw-r--r-- | src/game-server/mapreader.hpp | 3 | ||||
-rw-r--r-- | src/game-server/testing.cpp | 18 | ||||
-rw-r--r-- | src/utils/xml.hpp | 3 |
7 files changed, 154 insertions, 42 deletions
@@ -1,4 +1,11 @@ -2007-07-15 Bjørn Lindeijer <bjorn@lindeijer.nl> +2007-07-17 Eugenio Favalli <elvenprogrammer@gmail.com> + + * gameserver.cbp, src/game-server/mapmanager.cpp, + src/game-server/mapreader.cpp, src/game-server/mapreader.hpp, + src/game-server/testing.cpp, src/utils/xml.hpp: Implemented loading of + warp and spawn areas from map files. + +2007-07-15 Bjørn Lindeijer <bjorn@lindeijer.nl> * src/chat-server/chatchannelmanager.cpp, src/chat-server/chatchannelmanager.hpp, diff --git a/gameserver.cbp b/gameserver.cbp index 02b68325..d0c60c5b 100644 --- a/gameserver.cbp +++ b/gameserver.cbp @@ -176,6 +176,16 @@ <Option link="0"/> <Option target="default"/> </Unit> + <Unit filename="src\game-server\monstermanager.cpp"> + <Option compilerVar="CPP"/> + <Option target="default"/> + </Unit> + <Unit filename="src\game-server\monstermanager.hpp"> + <Option compilerVar=""/> + <Option compile="0"/> + <Option link="0"/> + <Option target="default"/> + </Unit> <Unit filename="src\game-server\movingobject.cpp"> <Option compilerVar="CPP"/> <Option target="default"/> @@ -276,12 +286,6 @@ <Option link="0"/> <Option target="default"/> </Unit> - <Unit filename="src\properties.h"> - <Option compilerVar=""/> - <Option compile="0"/> - <Option link="0"/> - <Option target="default"/> - </Unit> <Unit filename="src\resourcemanager.cpp"> <Option compilerVar="CPP"/> <Option target="default"/> 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; } } diff --git a/src/utils/xml.hpp b/src/utils/xml.hpp index ec384f5d..ace8d64d 100644 --- a/src/utils/xml.hpp +++ b/src/utils/xml.hpp @@ -40,4 +40,7 @@ namespace XML std::string getProperty(xmlNodePtr node, char const *name, std::string const &def); } +#define for_each_xml_child_node(var, parent) \ + for (xmlNodePtr var = parent->xmlChildrenNode; var; var = var->next) + #endif |