| 1 |
/* |
| 2 |
* The Mana World |
| 3 |
* Copyright (C) 2004 The Mana World Development Team |
| 4 |
* |
| 5 |
* This file is part of The Mana World. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "beingmanager.h" |
| 23 |
#include "engine.h" |
| 24 |
#include "flooritemmanager.h" |
| 25 |
#include "game.h" |
| 26 |
#include "localplayer.h" |
| 27 |
#include "log.h" |
| 28 |
#include "map.h" |
| 29 |
#include "particle.h" |
| 30 |
#include "sound.h" |
| 31 |
|
| 32 |
#include "gui/gui.h" |
| 33 |
#include "gui/minimap.h" |
| 34 |
#include "gui/okdialog.h" |
| 35 |
#include "gui/viewport.h" |
| 36 |
|
| 37 |
#include "net/gamehandler.h" |
| 38 |
#include "net/net.h" |
| 39 |
|
| 40 |
#include "resources/mapreader.h" |
| 41 |
#include "resources/monsterdb.h" |
| 42 |
#include "resources/resourcemanager.h" |
| 43 |
|
| 44 |
#include "utils/gettext.h" |
| 45 |
#include "utils/stringutils.h" |
| 46 |
|
| 47 |
#include <assert.h> |
| 48 |
|
| 49 |
Engine::Engine(): |
| 50 |
mCurrentMap(0) |
| 51 |
{ |
| 52 |
} |
| 53 |
|
| 54 |
Engine::~Engine() |
| 55 |
{ |
| 56 |
delete mCurrentMap; |
| 57 |
} |
| 58 |
|
| 59 |
bool Engine::changeMap(const std::string &mapPath) |
| 60 |
{ |
| 61 |
// Clean up floor items, beings and particles |
| 62 |
floorItemManager->clear(); |
| 63 |
beingManager->clear(); |
| 64 |
|
| 65 |
// Close the popup menu on map change so that invalid options can't be |
| 66 |
// executed. |
| 67 |
viewport->closePopupMenu(); |
| 68 |
|
| 69 |
// Unset the map of the player so that its particles are cleared before |
| 70 |
// being deleted in the next step |
| 71 |
if (player_node) |
| 72 |
player_node->setMap(0); |
| 73 |
|
| 74 |
particleEngine->clear(); |
| 75 |
|
| 76 |
mMapName = mapPath; |
| 77 |
|
| 78 |
// Store full map path in global var |
| 79 |
map_path = "maps/" + mapPath + ".tmx"; |
| 80 |
ResourceManager *resman = ResourceManager::getInstance(); |
| 81 |
if (!resman->exists(map_path)) |
| 82 |
map_path += ".gz"; |
| 83 |
|
| 84 |
// Attempt to load the new map |
| 85 |
Map *newMap = MapReader::readMap(map_path); |
| 86 |
|
| 87 |
if (!newMap) |
| 88 |
{ |
| 89 |
logger->log("Error while loading %s", map_path.c_str()); |
| 90 |
new OkDialog(_("Could Not Load Map"), |
| 91 |
strprintf(_("Error while loading %s"), map_path.c_str())); |
| 92 |
} |
| 93 |
|
| 94 |
// Notify the minimap and beingManager about the map change |
| 95 |
minimap->setMap(newMap); |
| 96 |
beingManager->setMap(newMap); |
| 97 |
particleEngine->setMap(newMap); |
| 98 |
viewport->setMap(newMap); |
| 99 |
|
| 100 |
delete mCurrentMap; |
| 101 |
mCurrentMap = newMap; |
| 102 |
|
| 103 |
Net::getGameHandler()->mapLoaded(mapPath); |
| 104 |
|
| 105 |
// Initialize map-based particle effects |
| 106 |
if (newMap) |
| 107 |
newMap->initializeParticleEffects(particleEngine); |
| 108 |
|
| 109 |
// Start playing new music file when necessary |
| 110 |
std::string oldMusic = mCurrentMap ? mCurrentMap->getMusicFile() : ""; |
| 111 |
std::string newMusic = newMap ? newMap->getMusicFile() : ""; |
| 112 |
if (newMusic != oldMusic) |
| 113 |
sound.playMusic(newMusic); |
| 114 |
|
| 115 |
return true; |
| 116 |
} |
| 117 |
|
| 118 |
void Engine::logic() |
| 119 |
{ |
| 120 |
beingManager->logic(); |
| 121 |
particleEngine->update(); |
| 122 |
gui->logic(); |
| 123 |
} |