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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
|
/* 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/nuvie/nuvie.h"
#include "ultima/nuvie/metaengine.h"
#include "ultima/nuvie/core/events.h"
#include "ultima/nuvie/actors/actor.h"
#include "ultima/nuvie/core/nuvie_defs.h"
#include "ultima/nuvie/core/debugger.h"
#include "ultima/nuvie/conf/configuration.h"
#include "ultima/nuvie/misc/u6_misc.h"
#include "ultima/nuvie/files/nuvie_io_file.h"
#include "ultima/nuvie/screen/screen.h"
#include "ultima/nuvie/script/script.h"
#include "ultima/nuvie/core/game.h"
#include "ultima/nuvie/gui/gui.h"
#include "ultima/nuvie/gui/widgets/console.h"
#include "ultima/nuvie/sound/sound_manager.h"
#include "ultima/nuvie/gui/widgets/map_window.h"
#include "ultima/nuvie/save/save_game.h"
#include "ultima/nuvie/gui/widgets/msg_scroll.h"
#include "common/config-manager.h"
#include "common/translation.h"
#include "common/compression/unzip.h"
namespace Ultima {
namespace Nuvie {
NuvieEngine *g_engine;
NuvieEngine::NuvieEngine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
Ultima::Shared::UltimaEngine(syst, gameDesc), _config(nullptr), _savegame(nullptr),
_screen(nullptr), _script(nullptr), _game(nullptr), _soundManager(nullptr),
_events(nullptr) {
g_engine = this;
}
NuvieEngine::~NuvieEngine() {
delete _config;
delete _events;
delete _savegame;
delete _screen;
delete _script;
delete _game;
g_engine = nullptr;
}
bool NuvieEngine::isDataRequired(Common::Path &folder, int &majorVersion, int &minorVersion) {
folder = "ultima6";
majorVersion = 1;
minorVersion = 1;
return true;
}
bool NuvieEngine::initialize() {
uint8 gameType;
bool playEnding = false;
bool showVirtueMsg = false;
if (!Ultima::Shared::UltimaEngine::initialize())
return false;
// Get which game to play
switch (getGameId()) {
case GAME_ULTIMA6:
gameType = NUVIE_GAME_U6;
break;
case GAME_MARTIAN_DREAMS:
gameType = NUVIE_GAME_MD;
break;
case GAME_SAVAGE_EMPIRE:
gameType = NUVIE_GAME_SE;
break;
default:
error("Unknown game");
break;
}
// Find and load config file
initConfig();
// Setup events
Events *events = new Ultima::Nuvie::Events(this, _config);
_events = events;
// Setup savegame handler
_savegame = new SaveGame(_config);
// Setup debugger
setDebugger(new Debugger());
// Setup screen
_screen = new Screen(_config);
if (_screen->init() == false)
error("Error initializing screen!");
GUI *gui = new GUI(_config, _screen);
ConsoleInit(_config, _screen, gui, _screen->get_width(), _screen->get_height());
ConsoleAddInfo("ScummVM Nuvie");
ConsoleAddInfo("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
if (showVirtueMsg) {
ConsoleShow();
ConsoleAddInfo("");
ConsoleAddInfo("");
ConsoleAddInfo("\"The path to victory is marked with the laws of");
ConsoleAddInfo(" Virtue, not the commands of DOS.\"");
ConsoleAddInfo("");
ConsoleAddInfo(" -- Lord British");
return false;
}
// Setup various game related config variables.
assignGameConfigValues(gameType);
// Check for a valid path to the selected game.
if (checkGameDir(gameType) == false)
return false;
if (checkDataDir() == false)
return false;
_soundManager = new SoundManager(_mixer);
_soundManager->nuvieStartup(_config);
_game = new Game(_config, events, _screen, gui, gameType, _soundManager);
_script = new Script(_config, gui, _soundManager, gameType);
if (_script->init() == false)
return false;
if (playEnding) {
_script->play_cutscene("/ending.lua");
return false;
}
if (playIntro() == false) {
ConsoleDelete();
return false;
}
if (_game->loadGame(_script) == false) {
delete _game;
_game = nullptr;
return false;
}
ConsoleDelete();
return true;
}
Common::Error NuvieEngine::run() {
if (initialize()) {
if (_game)
_game->play();
}
return Common::kNoError;
}
void NuvieEngine::initConfig() {
_config = new Configuration();
_config->load(_gameDescription->gameId, isEnhanced());
}
void NuvieEngine::assignGameConfigValues(uint8 gameType) {
Std::string game_name, game_id;
_config->set("config/GameType", gameType);
switch (gameType) {
case NUVIE_GAME_U6 :
game_name.assign("ultima6");
game_id.assign("u6");
break;
case NUVIE_GAME_MD :
game_name.assign("martian");
game_id.assign("md");
break;
case NUVIE_GAME_SE :
game_name.assign("savage");
game_id.assign("se");
break;
}
_config->set("config/GameName", game_name);
_config->set("config/GameID", game_id);
return;
}
bool NuvieEngine::checkGameDir(uint8 gameType) {
Common::Path path;
config_get_path(_config, "", path);
ConsoleAddInfo("gamedir: \"%s\"", path.toString().c_str());
return true;
}
bool NuvieEngine::checkDataDir() {
Std::string path;
_config->value("config/datadir", path, "");
ConsoleAddInfo("datadir: \"%s\"", path.c_str());
return true;
}
void NuvieEngine::syncSoundSettings() {
Ultima::Shared::UltimaEngine::syncSoundSettings();
if (!_soundManager)
return;
_soundManager->syncSoundSettings();
}
bool NuvieEngine::canLoadGameStateCurrently(bool isAutosave) {
if (_game == nullptr || !_game->isLoaded())
return false;
// Note that to mimic what Nuvie originally did, any attempt to try and open
// the save dialog will result in active gumps being closed
Events *events = static_cast<Events *>(_events);
MapWindow *mapWindow = _game->get_map_window();
if (isAutosave) {
return events->get_mode() == MOVE_MODE;
} else {
events->close_gumps();
switch (events->get_mode()) {
case EQUIP_MODE:
events->cancelAction();
return false;
case MOVE_MODE:
mapWindow->set_looking(false);
mapWindow->set_walking(false);
return true;
default:
// Saving/loading only available in standard move mode in-game
return false;
}
}
}
bool NuvieEngine::canSaveGameStateCurrently(bool isAutosave) {
if (!canLoadGameStateCurrently(isAutosave))
return false;
// Further checks against saving
Events *events = static_cast<Events *>(_events);
MsgScroll *scroll = _game->get_scroll();
if (_game->is_armageddon()) {
if (!isAutosave)
scroll->message("Can't save. You killed everyone!\n\n");
return false;
} else if (events->using_control_cheat()) {
if (!isAutosave)
scroll->message(" Can't save while using control cheat\n\n");
return false;
}
return true;
}
Common::Error NuvieEngine::loadGameState(int slot) {
Common::String filename = getSaveStateName(slot);
if (slot == ORIGINAL_SAVE_SLOT) {
// For Nuvie, unless a savegame is already present for the slot,
// loading it loads in the original game savegame
Common::InSaveFile *saveFile = _saveFileMan->openForLoading(filename);
bool isPresent = saveFile != nullptr;
delete saveFile;
if (!isPresent) {
_savegame->load_original();
return Common::kNoError;
}
}
return _savegame->load(filename) ? Common::kNoError : Common::kReadingFailed;
}
Common::Error NuvieEngine::saveGameState(int slot, const Common::String &desc, bool isAutosave) {
Common::String filename = getSaveStateName(slot);
if (_savegame->save(filename, desc, isAutosave)) {
if (!isAutosave) {
// Store which savegame was most recently saved
ConfMan.setInt("latest_save", slot);
ConfMan.flushToDisk();
// Display that the game was saved
MsgScroll *scroll = Game::get_game()->get_scroll();
scroll->display_string("\nGame Saved\n\n");
scroll->display_prompt();
}
return Common::kNoError;
} else {
return Common::kReadingFailed;
}
}
bool NuvieEngine::journeyOnwards() {
// If savegame selected from ScummVM launcher, load it now
if (ConfMan.hasKey("save_slot")) {
int saveSlot = ConfMan.getInt("save_slot");
return loadGameState(saveSlot).getCode() == Common::kNoError;
}
// Check for new game needed
bool newsave = false;
_config->value("config/newgame", newsave, false);
if (newsave) {
return _savegame->load_new();
}
// Load the savegame from the last slot which was used for saving
if (ConfMan.hasKey("latest_save")) {
int saveSlot = ConfMan.getInt("latest_save");
return loadGameState(saveSlot).getCode() == Common::kNoError;
}
// Otherwise start a new game
return _savegame->load_new();
}
bool NuvieEngine::loadLatestSave() {
if (ConfMan.hasKey("latest_save")) {
int saveSlot = ConfMan.getInt("latest_save");
return loadGameState(saveSlot).getCode() == Common::kNoError;
}
return _savegame->load_new();
}
bool NuvieEngine::quickSave(int saveSlot, bool isLoad) {
if (saveSlot < 0 || saveSlot > 99)
return false;
Std::string text;
MsgScroll *scroll = _game->get_scroll();
if (isLoad) {
if (!canLoadGameStateCurrently(false))
return false;
text = Common::convertFromU32String(_("loading quick save %d"));
} else {
if (!canSaveGameStateCurrently(false))
return false;
text = Common::convertFromU32String(_("saving quick save %d"));
}
text = Std::string::format(text.c_str(), saveSlot);
scroll->display_string(text);
if (isLoad) {
if (loadGameState(saveSlot).getCode() == Common::kNoError) {
return true;
} else {
scroll->message("\nfailed!\n\n");
return false;
}
} else {
Common::String saveDesc = Common::String::format("Quicksave %03d", saveSlot);
return saveGameState(saveSlot, saveDesc, false).getCode() == Common::kNoError;
}
}
bool NuvieEngine::playIntro() {
if (ConfMan.hasKey("save_slot") && ConfMan.getInt("save_slot") >= 0)
// Loading a savegame from the launcher, so skip intro
return true;
bool skip_intro;
string key = config_get_game_key(_config);
key.append("/skip_intro");
_config->value(key, skip_intro, false);
if (skip_intro)
return true;
if (_script->play_cutscene("/intro.lua")) {
bool should_quit = false;
_config->value("config/quit", should_quit, false);
if (!should_quit) {
ConsoleHide();
return true;
}
}
return false;
}
} // End of namespace Nuvie
} // End of namespace Ultima
|