summaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp44
1 files changed, 17 insertions, 27 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 43d4d0e5..3be152bd 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -82,7 +82,6 @@ Engine::Engine(Network *network):
{
std::stringstream filename;
filename << "graphics/sprites/weapon" << i << ".png";
- printf("hairstyle: %s\n", filename.str().c_str());
Spriteset *tmp = ResourceManager::getInstance()->createSpriteset(
filename.str(), 64, 64);
if (!tmp) {
@@ -117,53 +116,44 @@ Engine::~Engine()
delete itemDb;
}
-void Engine::changeMap(std::string mapPath)
+void Engine::changeMap(const std::string &mapPath)
{
- // Clean up floor items
+ // Clear floor items and beings
floorItemManager->clear();
-
beingManager->clear();
- // Generate full map path
- mapPath = "maps/" + mapPath;
- mapPath = mapPath.substr(0, mapPath.rfind(".")) + ".tmx.gz";
+ std::string oldMusic;
+ // Remove old map
+ if (mCurrentMap) {
+ oldMusic = mCurrentMap->getProperty("music");
+ delete mCurrentMap;
+ }
- // Store in global var
- map_path = mapPath;
+ // Generate full map path
+ map_path = "maps/" + mapPath.substr(0, mapPath.rfind(".")) + ".tmx.gz";
// Attempt to load the new map
- Map *newMap = MapReader::readMap(mapPath);
-
- if (!newMap) {
+ if (!(mCurrentMap = MapReader::readMap(map_path))) {
logger->error("Could not find map file");
}
// Notify the minimap and beingManager about the map change
Image *mapImage = NULL;
- if (newMap->hasProperty("minimap")) {
+ if (mCurrentMap->hasProperty("minimap")) {
ResourceManager *resman = ResourceManager::getInstance();
- mapImage = resman->getImage(newMap->getProperty("minimap"));
+ mapImage = resman->getImage(mCurrentMap->getProperty("minimap"));
}
minimap->setMapImage(mapImage);
- beingManager->setMap(newMap);
+ beingManager->setMap(mCurrentMap);
- // Start playing new music file when necessary
- std::string oldMusic = "";
-
- if (mCurrentMap) {
- oldMusic = mCurrentMap->getProperty("music");
- delete mCurrentMap;
- }
-
- std::string newMusic = newMap->getProperty("music");
+ // Change the music, if necessary
+ std::string newMusic = mCurrentMap->getProperty("music");
if (newMusic != oldMusic) {
- newMusic = std::string(TMW_DATADIR) + "data/music/" + newMusic;
+ newMusic = std::string(TMW_DATADIR "data/music/") + newMusic;
sound.playMusic(newMusic.c_str(), -1);
}
- mCurrentMap = newMap;
-
// Send "map loaded"
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_MAP_LOADED);