diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/engine.cpp | 28 | ||||
-rw-r--r-- | src/game.cpp | 23 |
3 files changed, 34 insertions, 18 deletions
@@ -30,6 +30,7 @@ contain the desert tiles that are twice and three times the height of a normal tile. One well in new_3-1 has been converted to use the new double tiles for testing purposes. + * src/game.cpp, src/engine.cpp: Fixed map switch crashing the client. 2005-10-06 Bjørn Lindeijer <bjorn@lindeijer.nl> diff --git a/src/engine.cpp b/src/engine.cpp index b7155ebb..dda6896c 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -190,12 +190,38 @@ Map *Engine::getCurrentMap() void Engine::changeMap(const std::string &mapPath) { + // Clean up floor items + empty_floor_items(); + + // Remove the local player, so it is not deleted + if (player_node != NULL) + { + beings.remove(player_node); + } + + // Delete all beings (except the local player) + std::list<Being*>::iterator i; + for (i = beings.begin(); i != beings.end(); i++) + { + delete (*i); + } + beings.clear(); + + // Attempt to load the new map Map *newMap = MapReader::readMap(mapPath); if (!newMap) { logger->error("Could not find map file"); } + // Re-add the local player node and transfer him to the newly loaded map + if (player_node != NULL) + { + beings.push_back(player_node); + player_node->setMap(newMap); + } + + // Start playing new music file when necessary std::string oldMusic = ""; if (mCurrentMap) { @@ -211,6 +237,8 @@ void Engine::changeMap(const std::string &mapPath) } mCurrentMap = newMap; + + // Notify the minimap about the map change minimap->setMap(mCurrentMap); } diff --git a/src/game.cpp b/src/game.cpp index d85149fe..e8692fd9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1472,35 +1472,22 @@ void do_parse() { // Set new map path map_path = "maps/" + msg.readString(16); - map_path= map_path.substr(0, map_path.rfind(".")) + ".tmx.gz"; + map_path = map_path.substr(0, map_path.rfind(".")) + + ".tmx.gz"; Uint16 x = msg.readShort(); Uint16 y = msg.readShort(); - logger->log("Warping to %s (%d, %d)", map_path.c_str(), x, y); + logger->log("Warping to %s (%d, %d)", + map_path.c_str(), x, y); + // Switch the actual map, deleting the previous one engine->changeMap(map_path); tiledMap = engine->getCurrentMap(); - empty_floor_items(); - - // Remove the player, so it is not deleted - beings.remove(player_node); - - // Delete all beings except the local player - std::list<Being *>::iterator i; - for (i = beings.begin(); i != beings.end(); i++) - { - delete (*i); - } - beings.clear(); - autoTarget = NULL; current_npc = 0; - // Re-add the local player node - beings.push_back(player_node); - player_node->action = Being::STAND; player_node->mFrame = 0; player_node->x = x; |