diff options
author | Paul Gilbert | 2018-02-26 18:24:24 -0500 |
---|---|---|
committer | Paul Gilbert | 2018-02-26 18:24:24 -0500 |
commit | 724c4e57add58362395ad6b6e79bcdaed1ff073b (patch) | |
tree | 4db154e5aa2f74c85ec18ecd9757308c616bc75b /engines | |
parent | c759dc764b227d3784996761eded672d5a685ca3 (diff) | |
download | scummvm-rg350-724c4e57add58362395ad6b6e79bcdaed1ff073b.tar.gz scummvm-rg350-724c4e57add58362395ad6b6e79bcdaed1ff073b.tar.bz2 scummvm-rg350-724c4e57add58362395ad6b6e79bcdaed1ff073b.zip |
XEEN: Defer creating new game state until needed
This fixes a bug with the startup menu where, after finishing the
game, starting a new one would simply re-show the prior game
Diffstat (limited to 'engines')
-rw-r--r-- | engines/xeen/saves.cpp | 69 | ||||
-rw-r--r-- | engines/xeen/saves.h | 5 | ||||
-rw-r--r-- | engines/xeen/worldofxeen/worldofxeen.cpp | 4 | ||||
-rw-r--r-- | engines/xeen/worldofxeen/worldofxeen_menu.cpp | 3 |
4 files changed, 49 insertions, 32 deletions
diff --git a/engines/xeen/saves.cpp b/engines/xeen/saves.cpp index 828d1ea829..a338aaffd3 100644 --- a/engines/xeen/saves.cpp +++ b/engines/xeen/saves.cpp @@ -38,37 +38,6 @@ SavesManager::SavesManager(const Common::String &targetName): _targetName(target _wonWorld(false), _wonDarkSide(false) { File::_xeenSave = nullptr; File::_darkSave = nullptr; - - if (g_vm->getGameID() != GType_Clouds) { - File::_darkSave = new SaveArchive(g_vm->_party); - File::_darkSave->reset(File::_darkCc); - } - if (g_vm->getGameID() != GType_DarkSide && g_vm->getGameID() != GType_Swords) { - File::_xeenSave = new SaveArchive(g_vm->_party); - File::_xeenSave->reset(File::_xeenCc); - } - - File::_currentSave = g_vm->getGameID() == GType_DarkSide || g_vm->getGameID() == GType_Swords ? - File::_darkSave : File::_xeenSave; - assert(File::_currentSave); - - // Set any final initial values - Party &party = *g_vm->_party; - party.resetBlacksmithWares(); - party._totalTime = 0; - - switch (g_vm->getGameID()) { - case GType_Swords: - party._year = 1050; - break; - case GType_DarkSide: - party._year = 850; - break; - default: - party._year = 610; - break; - } - party._day = 1; } SavesManager::~SavesManager() { @@ -237,6 +206,44 @@ Common::String SavesManager::generateSaveName(int slot) { return Common::String::format("%s.%03d", _targetName.c_str(), slot); } +void SavesManager::newGame() { + delete File::_xeenSave; + delete File::_darkSave; + File::_xeenSave = nullptr; + File::_darkSave = nullptr; + + if (g_vm->getGameID() != GType_Clouds) { + File::_darkSave = new SaveArchive(g_vm->_party); + File::_darkSave->reset(File::_darkCc); + } + if (g_vm->getGameID() != GType_DarkSide && g_vm->getGameID() != GType_Swords) { + File::_xeenSave = new SaveArchive(g_vm->_party); + File::_xeenSave->reset(File::_xeenCc); + } + + File::_currentSave = g_vm->getGameID() == GType_DarkSide || g_vm->getGameID() == GType_Swords ? + File::_darkSave : File::_xeenSave; + assert(File::_currentSave); + + // Set any final initial values + Party &party = *g_vm->_party; + party.resetBlacksmithWares(); + party._totalTime = 0; + + switch (g_vm->getGameID()) { + case GType_Swords: + party._year = 1050; + break; + case GType_DarkSide: + party._year = 850; + break; + default: + party._year = 610; + break; + } + party._day = 1; +} + bool SavesManager::loadGame() { if (!g_vm->canLoadGameStateCurrently()) return false; diff --git a/engines/xeen/saves.h b/engines/xeen/saves.h index 0150321a02..b18e04a822 100644 --- a/engines/xeen/saves.h +++ b/engines/xeen/saves.h @@ -83,6 +83,11 @@ public: Common::Error saveGameState(int slot, const Common::String &desc); /** + * Sets up a new game + */ + void newGame(); + + /** * Shows the load game dialog, and lets the user load a game * @returns True if a savegame was loaded */ diff --git a/engines/xeen/worldofxeen/worldofxeen.cpp b/engines/xeen/worldofxeen/worldofxeen.cpp index cb2c8c7ee3..54d3b482fc 100644 --- a/engines/xeen/worldofxeen/worldofxeen.cpp +++ b/engines/xeen/worldofxeen/worldofxeen.cpp @@ -45,8 +45,10 @@ void WorldOfXeenEngine::outerGameLoop() { while (!shouldQuit() && _pendingAction != WOX_QUIT) { // TODO: Remove this once proper startup menus are added for Clouds & Dark Side - if (g_vm->getGameID() != GType_WorldOfXeen) + if (g_vm->getGameID() != GType_WorldOfXeen) { + _saves->newGame(); _pendingAction = WOX_PLAY_GAME; + } WOXGameAction action = _pendingAction; _pendingAction = WOX_MENU; diff --git a/engines/xeen/worldofxeen/worldofxeen_menu.cpp b/engines/xeen/worldofxeen/worldofxeen_menu.cpp index ff2e9ac3e8..f43b00f027 100644 --- a/engines/xeen/worldofxeen/worldofxeen_menu.cpp +++ b/engines/xeen/worldofxeen/worldofxeen_menu.cpp @@ -109,7 +109,10 @@ void WorldOfXeenMenu::execute() { if (result == -1) break; + // Load a new game state and set the difficulty + _vm->_saves->newGame(); _vm->_party->_difficulty = (Difficulty)result; + WOX_VM._pendingAction = WOX_PLAY_GAME; closeWindow(); return; |