From 29f818c314f86f9a842840c20d9634f0711507a6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Mar 2015 21:28:46 -0400 Subject: Added tool to map editor to set game starting position --- tools/mapedit/src/world.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tools/mapedit/src/world.cpp') diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index c30f76c..3145e4e 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp @@ -59,6 +59,17 @@ World::World(std::string filename) rootChildren.push_back(atoi((char*) key)); } xmlFree(key); + } else if (!xmlStrcmp(node->name, (const xmlChar*) "startpos")) + { + xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); + if (idKey == 0) throw MapLoadException(filename); + startingMap = atoi((char*) idKey); + xmlFree(idKey); + + xmlChar* posKey = xmlGetProp(node, (xmlChar*) "pos"); + if (posKey == 0) throw MapLoadException(filename); + sscanf((char*) posKey, "%d,%d", &startingPosition.first, &startingPosition.second); + xmlFree(posKey); } else if (!xmlStrcmp(node->name, (const xmlChar*) "map")) { xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); @@ -237,6 +248,22 @@ void World::save(std::string name, wxTreeCtrl* mapTree) if (rc < 0) throw MapWriteException(name); } + // + rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos"); + if (rc < 0) throw MapWriteException(name); + + // id= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "id", "%d", startingMap); + if (rc < 0) throw MapWriteException(name); + + // pos= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "pos", "%d,%d", startingPosition.first, startingPosition.second); + if (rc < 0) throw MapWriteException(name); + + // + rc = xmlTextWriterEndElement(writer); + if (rc < 0) throw MapWriteException(name); + for (auto mapPair : maps) { Map& map = *mapPair.second; @@ -379,3 +406,21 @@ bool World::getEmpty() const { return empty; } + +Map* World::getStartingMap() const +{ + return getMap(startingMap).get(); +} + +std::pair World::getStartingPosition() const +{ + return startingPosition; +} + +void World::setStart(Map* map, std::pair startPos) +{ + startingMap = map->getID(); + startingPosition = startPos; + + setDirty(true); +} -- cgit 1.4.1