1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima4/ultima4.h"
#include "ultima/ultima4/controllers/intro_controller.h"
#include "ultima/ultima4/conversation/conversation.h"
#include "ultima/ultima4/conversation/dialogueloader.h"
#include "ultima/ultima4/core/config.h"
#include "ultima/ultima4/core/debugger.h"
#include "ultima/ultima4/core/settings.h"
#include "ultima/ultima4/core/utils.h"
#include "ultima/ultima4/events/event_handler.h"
#include "ultima/ultima4/filesys/savegame.h"
#include "ultima/ultima4/game/armor.h"
#include "ultima/ultima4/game/codex.h"
#include "ultima/ultima4/game/context.h"
#include "ultima/ultima4/game/death.h"
#include "ultima/ultima4/game/game.h"
#include "ultima/ultima4/game/item.h"
#include "ultima/ultima4/game/moongate.h"
#include "ultima/ultima4/game/person.h"
#include "ultima/ultima4/game/weapon.h"
#include "ultima/ultima4/gfx/screen.h"
#include "ultima/ultima4/gfx/imagemgr.h"
#include "ultima/ultima4/map/maploader.h"
#include "ultima/ultima4/map/shrine.h"
#include "ultima/ultima4/map/tilemap.h"
#include "ultima/ultima4/map/tileset.h"
#include "ultima/ultima4/sound/music.h"
#include "ultima/ultima4/sound/sound.h"
#include "common/debug.h"
#include "common/system.h"
namespace Ultima {
namespace Ultima4 {
Ultima4Engine *g_ultima;
Ultima4Engine::Ultima4Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
Shared::UltimaEngine(syst, gameDesc), _saveSlotToLoad(-1), _armors(nullptr),
_codex(nullptr), _config(nullptr), _context(nullptr), _death(nullptr),
_dialogueLoaders(nullptr), _game(nullptr), _items(nullptr), _music(nullptr),
_mapLoaders(nullptr), _moongates(nullptr),
_responseParts(nullptr), _saveGame(nullptr), _screen(nullptr), _shrines(nullptr),
_soundManager(nullptr), _spells(nullptr), _tileMaps(nullptr), _tileRules(nullptr),
_tileSets(nullptr), _weapons(nullptr) {
g_ultima = this;
g_armors = nullptr;
g_codex = nullptr;
g_context = nullptr;
g_death = nullptr;
g_game = nullptr;
g_items = nullptr;
g_mapLoaders = nullptr;
g_moongates = nullptr;
g_music = nullptr;
g_responseParts = nullptr;
g_screen = nullptr;
g_shrines = nullptr;
g_sound = nullptr;
g_spells = nullptr;
g_tileMaps = nullptr;
g_tileRules = nullptr;
g_tileSets = nullptr;
g_weapons = nullptr;
}
Ultima4Engine::~Ultima4Engine() {
delete _armors;
delete _codex;
delete _config;
delete _context;
delete _death;
delete _dialogueLoaders;
delete _game;
delete _items;
delete _mapLoaders;
delete _moongates;
delete _music;
delete _responseParts;
delete _saveGame;
delete _screen;
delete _shrines;
delete _soundManager;
delete _spells;
delete _tileMaps;
delete _tileRules;
delete _tileSets;
delete _weapons;
ImageMgr::destroy();
//delete g_music;
}
bool Ultima4Engine::initialize() {
if (!Shared::UltimaEngine::initialize())
return false;
// Initialize the sub-systems
_config = new Config();
_armors = new Armors();
_codex = new Codex();
_context = new Context();
_death = new Death();
_dialogueLoaders = new DialogueLoaders();
_items = new Items();
_mapLoaders = new MapLoaders();
_moongates = new Moongates();
_music = new Music(_mixer);
_soundManager = new SoundManager(_mixer);
_responseParts = new ResponseParts();
_screen = new Screen();
_screen->init();
_shrines = new Shrines();
_spells = new Spells();
_tileRules = new TileRules();
_tileSets = new TileSets();
_tileMaps = new TileMaps();
_game = new GameController();
_saveGame = new SaveGame();
_weapons = new Weapons();
setDebugger(new Debugger());
creatureMgr->getInstance();
_saveSlotToLoad = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
return true;
}
void Ultima4Engine::startup() {
bool skipInfo = _saveSlotToLoad != -1;
if (!skipInfo) {
// do the intro
g_intro = new IntroController();
g_intro->init();
g_intro->preloadMap();
eventHandler->pushController(g_intro);
eventHandler->run();
eventHandler->popController();
g_intro->deleteIntro();
}
}
Common::Error Ultima4Engine::run() {
if (initialize()) {
startup();
if (!shouldQuit()) {
g_game->init();
if (_saveSlotToLoad != -1) {
if (loadGameState(_saveSlotToLoad).getCode() != Common::kNoError)
error("Error loading save");
} else {
_saveGame->newGame();
}
eventHandler->setControllerDone(false);
eventHandler->pushController(g_game);
eventHandler->run();
eventHandler->popController();
}
}
return Common::kNoError;
}
bool Ultima4Engine::isDataRequired(Common::Path &folder, int &majorVersion, int &minorVersion) {
folder = "ultima4";
majorVersion = 1;
minorVersion = 0;
return true;
}
void Ultima4Engine::setToJourneyOnwards() {
_saveSlotToLoad = ConfMan.hasKey("last_save") ? ConfMan.getInt("last_save") : -1;
assert(_saveSlotToLoad);
}
bool Ultima4Engine::canLoadGameStateCurrently(bool isAutosave) {
return g_game != nullptr && g_context != nullptr && eventHandler->getController() == g_game;
}
bool Ultima4Engine::canSaveGameStateCurrently(bool isAutosave) {
return g_game != nullptr && g_context != nullptr && eventHandler->getController() == g_game
&& (g_context->_location->_context & CTX_CAN_SAVE_GAME);
}
Common::Error Ultima4Engine::saveGameState(int slot, const Common::String &desc, bool isAutosave) {
Common::Error result = Shared::UltimaEngine::saveGameState(slot, desc, isAutosave);
if (!isAutosave && result.getCode() == Common::kNoError) {
ConfMan.setInt("last_save", slot);
ConfMan.flushToDisk();
}
return result;
}
Common::Error Ultima4Engine::loadGameStream(Common::SeekableReadStream *stream) {
g_ultima->_saveGame->load(stream);
g_screen->screenUpdate(&g_game->_mapArea, true, false);
return Common::kNoError;
}
Common::Error Ultima4Engine::saveGameStream(Common::WriteStream *stream, bool isAutosave) {
g_ultima->_saveGame->save(stream);
return Common::kNoError;
}
void Ultima4Engine::quitGame() {
UltimaEngine::quitGame();
// Do an event poll to all the quit message to be processed
Common::Event e;
(void)g_system->getEventManager()->pollEvent(e);
}
} // End of namespace Ultima4
} // End of namespace Ultima
|