summaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-09 12:07:25 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-09 12:07:25 +0000
commit6f706879515b4e37a78994aaae6b0e36d00b5f32 (patch)
tree33785b722f71a1496fc88e4a619dedbc7f716ea8 /src/engine.cpp
parent8bde9095c5840b8d62ebafe11beaed98877d6ac2 (diff)
downloadMana-6f706879515b4e37a78994aaae6b0e36d00b5f32.tar.gz
Mana-6f706879515b4e37a78994aaae6b0e36d00b5f32.tar.bz2
Mana-6f706879515b4e37a78994aaae6b0e36d00b5f32.tar.xz
Mana-6f706879515b4e37a78994aaae6b0e36d00b5f32.zip
Fixed map switch to crash the client.
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp28
1 files changed, 28 insertions, 0 deletions
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);
}