diff options
author | Johannes Schickel | 2008-11-09 13:00:40 +0000 |
---|---|---|
committer | Johannes Schickel | 2008-11-09 13:00:40 +0000 |
commit | 36de1204e343743b4c86d8b30113640b3e697c7c (patch) | |
tree | a72435f476a27abd0982c4796f1d04679091b51f /engines | |
parent | cb581c61b26269296e3e9f4837ae793e562a84db (diff) | |
download | scummvm-rg350-36de1204e343743b4c86d8b30113640b3e697c7c.tar.gz scummvm-rg350-36de1204e343743b4c86d8b30113640b3e697c7c.tar.bz2 scummvm-rg350-36de1204e343743b4c86d8b30113640b3e697c7c.zip |
- Implemented Engine::saveGameState for KYRA
- Changed internal save/load API to use slots instead of filename strings
- Changed internal save/load API to use Common::Error
svn-id: r34952
Diffstat (limited to 'engines')
-rw-r--r-- | engines/kyra/detection.cpp | 3 | ||||
-rw-r--r-- | engines/kyra/gui_hof.cpp | 15 | ||||
-rw-r--r-- | engines/kyra/gui_lok.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/gui_mr.cpp | 17 | ||||
-rw-r--r-- | engines/kyra/gui_v2.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/kyra_hof.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/kyra_hof.h | 4 | ||||
-rw-r--r-- | engines/kyra/kyra_lok.cpp | 10 | ||||
-rw-r--r-- | engines/kyra/kyra_lok.h | 5 | ||||
-rw-r--r-- | engines/kyra/kyra_mr.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/kyra_mr.h | 4 | ||||
-rw-r--r-- | engines/kyra/kyra_v1.h | 6 | ||||
-rw-r--r-- | engines/kyra/kyra_v2.cpp | 6 | ||||
-rw-r--r-- | engines/kyra/kyra_v2.h | 4 | ||||
-rw-r--r-- | engines/kyra/lol.h | 4 | ||||
-rw-r--r-- | engines/kyra/saveload.cpp | 12 | ||||
-rw-r--r-- | engines/kyra/saveload_hof.cpp | 37 | ||||
-rw-r--r-- | engines/kyra/saveload_lok.cpp | 41 | ||||
-rw-r--r-- | engines/kyra/saveload_mr.cpp | 37 | ||||
-rw-r--r-- | engines/kyra/script_mr.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/timer_mr.cpp | 2 |
21 files changed, 125 insertions, 98 deletions
diff --git a/engines/kyra/detection.cpp b/engines/kyra/detection.cpp index d584623702..59d7edf2fb 100644 --- a/engines/kyra/detection.cpp +++ b/engines/kyra/detection.cpp @@ -1083,7 +1083,8 @@ bool KyraMetaEngine::hasFeature(MetaEngineFeature f) const { bool Kyra::KyraEngine_v1::hasFeature(EngineFeature f) const { return (f == kSupportsRTL) || - (f == kSupportsLoadingDuringRuntime); + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); } bool KyraMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const { diff --git a/engines/kyra/gui_hof.cpp b/engines/kyra/gui_hof.cpp index 79db2b8b80..1b3413e724 100644 --- a/engines/kyra/gui_hof.cpp +++ b/engines/kyra/gui_hof.cpp @@ -785,8 +785,8 @@ int GUI_HoF::optionsButton(Button *button) { if (!_loadedSave && _reloadTemporarySave) { _vm->_unkSceneScreenFlag1 = true; - _vm->loadGame(_vm->getSavegameFilename(999)); - _vm->_saveFileMan->removeSavefile(_vm->getSavegameFilename(999)); + _vm->loadGameState(999); + //_vm->_saveFileMan->removeSavefile(_vm->getSavegameFilename(999)); _vm->_unkSceneScreenFlag1 = false; } @@ -1004,7 +1004,14 @@ int GUI_HoF::gameOptionsTalkie(Button *caller) { if (_vm->_lang != lang) { _reloadTemporarySave = true; - _vm->saveGame(_vm->getSavegameFilename(999), "Temporary Kyrandia 2 Savegame", 0); + + Graphics::Surface thumb; + createScreenThumbnail(thumb); + _vm->saveGameState(999, "Autosave", &thumb); + thumb.free(); + + _vm->_lastAutosave = _vm->_system->getMillis(); + _vm->loadCCodeBuffer("C_CODE.XXX"); if (_vm->_flags.isTalkie) _vm->loadOptionsBuffer("OPTIONS.XXX"); @@ -1188,7 +1195,7 @@ int GUI_HoF::loadMenu(Button *caller) { } else if (_vm->_gameToLoad >= 0) { restorePage1(_vm->_screenBuffer); restorePalette(); - _vm->loadGame(_vm->getSavegameFilename(_vm->_gameToLoad)); + _vm->loadGameState(_vm->_gameToLoad); if (_vm->_gameToLoad == 0) { _restartGame = true; for (int i = 0; i < 23; ++i) diff --git a/engines/kyra/gui_lok.cpp b/engines/kyra/gui_lok.cpp index e097a422f2..64d0c91d24 100644 --- a/engines/kyra/gui_lok.cpp +++ b/engines/kyra/gui_lok.cpp @@ -658,7 +658,7 @@ int GUI_LoK::loadGameMenu(Button *button) { } else { restorePalette(); if (_vm->_gameToLoad != -1) - _vm->loadGame(_vm->getSavegameFilename(_vm->_gameToLoad)); + _vm->loadGameState(_vm->_gameToLoad); _displayMenu = false; _menuRestoreScreen = false; } @@ -749,7 +749,7 @@ int GUI_LoK::saveGame(Button *button) { if (_vm->_gameToLoad > 0) { Graphics::Surface thumb; createScreenThumbnail(thumb); - _vm->saveGame(_vm->getSavegameFilename(_vm->_gameToLoad), _savegameName, &thumb); + _vm->saveGameState(_vm->_gameToLoad, _savegameName, &thumb); thumb.free(); } } diff --git a/engines/kyra/gui_mr.cpp b/engines/kyra/gui_mr.cpp index 9f6748cd9b..616c235266 100644 --- a/engines/kyra/gui_mr.cpp +++ b/engines/kyra/gui_mr.cpp @@ -1366,8 +1366,8 @@ int GUI_MR::optionsButton(Button *button) { if (!_loadedSave && _reloadTemporarySave) { _vm->_unkSceneScreenFlag1 = true; - _vm->loadGame(_vm->getSavegameFilename(999)); - _vm->_saveFileMan->removeSavefile(_vm->getSavegameFilename(999)); + _vm->loadGameState(999); + //_vm->_saveFileMan->removeSavefile(_vm->getSavegameFilename(999)); _vm->_unkSceneScreenFlag1 = false; } @@ -1408,7 +1408,7 @@ int GUI_MR::loadMenu(Button *caller) { restorePage1(_vm->_screenBuffer); restorePalette(); _vm->_menuDirectlyToLoad = false; - _vm->loadGame(_vm->getSavegameFilename(_vm->_gameToLoad)); + _vm->loadGameState(_vm->_gameToLoad); if (_vm->_gameToLoad == 0) { _restartGame = true; _vm->runStartupScript(1, 1); @@ -1425,7 +1425,7 @@ int GUI_MR::loadSecondChance(Button *button) { _vm->_gameToLoad = 999; restorePage1(_vm->_screenBuffer); - _vm->loadGame(_vm->getSavegameFilename(_vm->_gameToLoad)); + _vm->loadGameState(_vm->_gameToLoad); _displayMenu = false; _loadedSave = true; return 0; @@ -1458,7 +1458,14 @@ int GUI_MR::gameOptions(Button *caller) { if (_vm->_lang != lang) { _reloadTemporarySave = true; - _vm->saveGame(_vm->getSavegameFilename(999), "Temporary Kyrandia 3 Savegame", 0); + + Graphics::Surface thumb; + createScreenThumbnail(thumb); + _vm->saveGameState(999, "Autosave", &thumb); + thumb.free(); + + _vm->_lastAutosave = _vm->_system->getMillis(); + if (!_vm->loadLanguageFile("ITEMS.", _vm->_itemFile)) error("Couldn't load ITEMS"); if (!_vm->loadLanguageFile("SCORE.", _vm->_scoreFile)) diff --git a/engines/kyra/gui_v2.cpp b/engines/kyra/gui_v2.cpp index 9c5e86ad98..4859b813e7 100644 --- a/engines/kyra/gui_v2.cpp +++ b/engines/kyra/gui_v2.cpp @@ -622,7 +622,7 @@ int GUI_v2::saveMenu(Button *caller) { Graphics::Surface thumb; createScreenThumbnail(thumb); - _vm->saveGame(_vm->getSavegameFilename(_saveSlot), _saveDescription, &thumb); + _vm->saveGameState(_saveSlot, _saveDescription, &thumb); thumb.free(); _displayMenu = false; diff --git a/engines/kyra/kyra_hof.cpp b/engines/kyra/kyra_hof.cpp index bc5a59b7a9..9811448cde 100644 --- a/engines/kyra/kyra_hof.cpp +++ b/engines/kyra/kyra_hof.cpp @@ -437,9 +437,9 @@ void KyraEngine_HoF::startup() { if (_gameToLoad == -1) { snd_playWanderScoreViaMap(52, 1); enterNewScene(_mainCharacter.sceneId, _mainCharacter.facing, 0, 0, 1); - saveGame(getSavegameFilename(0), "New Game", 0); + saveGameState(0, "New Game", 0); } else { - loadGame(getSavegameFilename(_gameToLoad)); + loadGameState(_gameToLoad); } _screen->showMouse(); diff --git a/engines/kyra/kyra_hof.h b/engines/kyra/kyra_hof.h index 62039cb80a..1204179a05 100644 --- a/engines/kyra/kyra_hof.h +++ b/engines/kyra/kyra_hof.h @@ -907,8 +907,8 @@ protected: int _dbgPass; // save/load specific - void saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumbnail); - void loadGame(const char *fileName); + Common::Error saveGameState(int slot, const char *saveName, const Graphics::Surface *thumbnail); + Common::Error loadGameState(int slot); }; } // end of namespace Kyra diff --git a/engines/kyra/kyra_lok.cpp b/engines/kyra/kyra_lok.cpp index e995c74fd2..34be623369 100644 --- a/engines/kyra/kyra_lok.cpp +++ b/engines/kyra/kyra_lok.cpp @@ -391,10 +391,10 @@ void KyraEngine_LoK::startup() { _gui->buttonMenuCallback(0); _menuDirectlyToLoad = false; } else - saveGame(getSavegameFilename(0), "New game", 0); + saveGameState(0, "New game", 0); } else { _screen->setFont(Screen::FID_8_FNT); - loadGame(getSavegameFilename(_gameToLoad)); + loadGameState(_gameToLoad); _gameToLoad = -1; } } @@ -473,14 +473,14 @@ void KyraEngine_LoK::delay(uint32 amount, bool update, bool isMainLoop) { case Common::EVENT_KEYDOWN: if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' && (event.kbd.flags == Common::KBD_CTRL || event.kbd.flags == Common::KBD_ALT) && isMainLoop) { - const char *saveLoadSlot = getSavegameFilename(9 - (event.kbd.keycode - '0') + 990); + int saveLoadSlot = 9 - (event.kbd.keycode - '0') + 990; if (event.kbd.flags == Common::KBD_CTRL) - loadGame(saveLoadSlot); + loadGameState(saveLoadSlot); else { char savegameName[14]; sprintf(savegameName, "Quicksave %d", event.kbd.keycode - '0'); - saveGame(saveLoadSlot, savegameName, 0); + saveGameState(saveLoadSlot, savegameName, 0); } } else if (event.kbd.flags == Common::KBD_CTRL) { if (event.kbd.keycode == 'd') diff --git a/engines/kyra/kyra_lok.h b/engines/kyra/kyra_lok.h index c345dd4df8..d294e29fad 100644 --- a/engines/kyra/kyra_lok.h +++ b/engines/kyra/kyra_lok.h @@ -214,9 +214,8 @@ public: protected: int32 _speechPlayTime; - void saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumbnail); - void loadGame(const char *fileName); - + Common::Error saveGameState(int slot, const char *saveName, const Graphics::Surface *thumbnail); + Common::Error loadGameState(int slot); protected: // input void processInput(); diff --git a/engines/kyra/kyra_mr.cpp b/engines/kyra/kyra_mr.cpp index c461bfa494..877a6d4397 100644 --- a/engines/kyra/kyra_mr.cpp +++ b/engines/kyra/kyra_mr.cpp @@ -684,13 +684,13 @@ void KyraEngine_MR::startup() { assert(_invWsa); _invWsa->open("MOODOMTR.WSA", 1, 0); _invWsaFrame = 6; - saveGame(getSavegameFilename(0), "New Game", 0); + saveGameState(0, "New Game", 0); _soundDigital->beginFadeOut(_musicSoundChannel, 60); delayWithTicks(60); if (_gameToLoad == -1) enterNewScene(_mainCharacter.sceneId, _mainCharacter.facing, 0, 0, 1); else - loadGame(getSavegameFilename(_gameToLoad)); + loadGameState(_gameToLoad); if (_menuDirectlyToLoad) (*_mainButtonData[0].buttonCallback)(&_mainButtonData[0]); diff --git a/engines/kyra/kyra_mr.h b/engines/kyra/kyra_mr.h index 0bf5e663b4..73886b9d11 100644 --- a/engines/kyra/kyra_mr.h +++ b/engines/kyra/kyra_mr.h @@ -583,8 +583,8 @@ private: int albumClose(Button *caller); // save/load - void saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumbnail); - void loadGame(const char *fileName); + Common::Error saveGameState(int slot, const char *saveName, const Graphics::Surface *thumbnail); + Common::Error loadGameState(int slot); // opcodes int o3_getMalcolmShapes(EMCState *script); diff --git a/engines/kyra/kyra_v1.h b/engines/kyra/kyra_v1.h index 6711b1f19f..2d68dd2315 100644 --- a/engines/kyra/kyra_v1.h +++ b/engines/kyra/kyra_v1.h @@ -306,9 +306,9 @@ protected: static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *file, bool loadThumbnail, SaveHeader &header); - Common::Error loadGameState(int slot); - virtual void loadGame(const char *fileName) = 0; - virtual void saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumbnail) = 0; + virtual Common::Error loadGameState(int slot) = 0; + Common::Error saveGameState(int slot, const char *saveName) { return saveGameState(slot, saveName, 0); } + virtual Common::Error saveGameState(int slot, const char *saveName, const Graphics::Surface *thumbnail) = 0; Common::SeekableReadStream *openSaveForReading(const char *filename, SaveHeader &header); Common::WriteStream *openSaveForWriting(const char *filename, const char *saveName, const Graphics::Surface *thumbnail) const; diff --git a/engines/kyra/kyra_v2.cpp b/engines/kyra/kyra_v2.cpp index 1cdb659c6a..368c14e29d 100644 --- a/engines/kyra/kyra_v2.cpp +++ b/engines/kyra/kyra_v2.cpp @@ -182,16 +182,16 @@ int KyraEngine_v2::checkInput(Button *buttonList, bool mainLoop) { case Common::EVENT_KEYDOWN: if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' && (event.kbd.flags == Common::KBD_CTRL || event.kbd.flags == Common::KBD_ALT) && mainLoop) { - const char *saveLoadSlot = getSavegameFilename(9 - (event.kbd.keycode - '0') + 990); + int saveLoadSlot = 9 - (event.kbd.keycode - '0') + 990; if (event.kbd.flags == Common::KBD_CTRL) { - loadGame(saveLoadSlot); + loadGameState(saveLoadSlot); _eventList.clear(); breakLoop = true; } else { char savegameName[14]; sprintf(savegameName, "Quicksave %d", event.kbd.keycode - '0'); - saveGame(saveLoadSlot, savegameName, 0); + saveGameState(saveLoadSlot, savegameName, 0); } } else if (event.kbd.flags == Common::KBD_CTRL) { if (event.kbd.keycode == 'd') diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h index e7f9634fc6..e606bdfc15 100644 --- a/engines/kyra/kyra_v2.h +++ b/engines/kyra/kyra_v2.h @@ -417,10 +417,6 @@ protected: int o2_setTimerCountdown(EMCState *script); int o2_setVocHigh(EMCState *script); int o2_getVocHigh(EMCState *script); - - // save/load specific - virtual void saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumbnail) = 0; - virtual void loadGame(const char *fileName) = 0; }; } // end of namespace Kyra diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h index 3ece9b28a4..895f9cddaa 100644 --- a/engines/kyra/lol.h +++ b/engines/kyra/lol.h @@ -149,8 +149,8 @@ private: bool lineIsPassable(int, int) { return false; } // save - void loadGame(const char *fileName) {} - void saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumbnail) {} + Common::Error loadGameState(int slot) { return Common::kNoError; } + Common::Error saveGameState(int slot, const char *saveName, const Graphics::Surface *thumbnail) { return Common::kNoError; } }; } // end of namespace Kyra diff --git a/engines/kyra/saveload.cpp b/engines/kyra/saveload.cpp index 5f94c1321d..9fea2f0ea1 100644 --- a/engines/kyra/saveload.cpp +++ b/engines/kyra/saveload.cpp @@ -244,19 +244,9 @@ bool KyraEngine_v1::saveFileLoadable(int slot) { return false; } -Common::Error KyraEngine_v1::loadGameState(int slot) { - if (!_isSaveAllowed) - return Common::kUnknownError; // FIXME - - const char *filename = getSavegameFilename(slot); - loadGame(filename); - - return Common::kNoError; -} - void KyraEngine_v1::checkAutosave() { if (shouldPerformAutoSave(_lastAutosave)) { - saveGame(getSavegameFilename(999), "Autosave", 0); + saveGameState(999, "Autosave", 0); _lastAutosave = _system->getMillis(); } } diff --git a/engines/kyra/saveload_hof.cpp b/engines/kyra/saveload_hof.cpp index be7a74e1c3..d1407c1d91 100644 --- a/engines/kyra/saveload_hof.cpp +++ b/engines/kyra/saveload_hof.cpp @@ -35,14 +35,14 @@ namespace Kyra { -void KyraEngine_HoF::saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumb) { - debugC(9, kDebugLevelMain, "KyraEngine_LoK::saveGame('%s', '%s', %p)", fileName, saveName, (const void *)thumb); +Common::Error KyraEngine_HoF::saveGameState(int slot, const char *saveName, const Graphics::Surface *thumb) { + debugC(9, kDebugLevelMain, "KyraEngine_HoF::saveGame(%d, '%s', %p)", slot, saveName, (const void *)thumb); + + const char *fileName = getSavegameFilename(slot); Common::OutSaveFile *out = openSaveForWriting(fileName, saveName, thumb); - if (!out) { - warning("Can't open file '%s', game not loadable", fileName); - return; - } + if (!out) + return _saveFileMan->getError(); _timer->saveDataToFile(*out); @@ -118,23 +118,28 @@ void KyraEngine_HoF::saveGame(const char *fileName, const char *saveName, const out->finalize(); // check for errors - if (out->err()) + if (out->err()) { warning("Can't write file '%s'. (Disk full?)", fileName); - else + return Common::kUnknownError; + } else { debugC(1, kDebugLevelMain, "Saved game '%s.'", saveName); + } delete out; + return Common::kNoError; } -void KyraEngine_HoF::loadGame(const char *fileName) { - debugC(9, kDebugLevelMain, "KyraEngine_HoF::loadGame('%s')", fileName); +Common::Error KyraEngine_HoF::loadGameState(int slot) { + debugC(9, kDebugLevelMain, "KyraEngine_HoF::loadGame(%d)", slot); + + const char *fileName = getSavegameFilename(slot); SaveHeader header; Common::InSaveFile *saveFile = openSaveForReading(fileName, header); if (!saveFile) { showMessageFromCCode(0x35, 0x84, 0); snd_playSoundEffect(0x0D); - return; + return Common::kUnknownError; } if (header.originalSave) @@ -279,10 +284,12 @@ void KyraEngine_HoF::loadGame(const char *fileName) { _sceneExit3 = in.readUint16(); _sceneExit4 = in.readUint16(); - if (saveFile->err() || saveFile->eos()) - error("Load failed ('%s', '%s').", fileName, header.description.c_str()); - else + if (saveFile->err() || saveFile->eos()) { + warning("Load failed ('%s', '%s').", fileName, header.description.c_str()); + return Common::kUnknownError; + } else { debugC(1, kDebugLevelMain, "Loaded savegame '%s.'", header.description.c_str()); + } if (loadedZTable != _characterShapeFile) loadCharacterShapes(_characterShapeFile); @@ -325,6 +332,8 @@ void KyraEngine_HoF::loadGame(const char *fileName) { // We didn't explicitly set the walk speed, but it's saved as part of // the _timers array, so we need to re-sync it with _configWalkspeed. setWalkspeed(_configWalkspeed); + + return Common::kNoError; } } // end of namespace Kyra diff --git a/engines/kyra/saveload_lok.cpp b/engines/kyra/saveload_lok.cpp index 051b844703..8cad0eeb75 100644 --- a/engines/kyra/saveload_lok.cpp +++ b/engines/kyra/saveload_lok.cpp @@ -35,20 +35,21 @@ #include "kyra/timer.h" namespace Kyra { -void KyraEngine_LoK::loadGame(const char *fileName) { - debugC(9, kDebugLevelMain, "KyraEngine_LoK::loadGame('%s')", fileName); + +Common::Error KyraEngine_LoK::loadGameState(int slot) { + debugC(9, kDebugLevelMain, "KyraEngine_LoK::loadGame(%d)", slot); + + const char *fileName = getSavegameFilename(slot); SaveHeader header; Common::InSaveFile *in = openSaveForReading(fileName, header); - if (!in) { - warning("Can't open file '%s', game not loadable", fileName); - return; - } + if (!in) + return _saveFileMan->getError(); if (header.originalSave) { // no support for original savefile in Kyrandia 1 (yet) delete in; - return; + return Common::kUnknownError; } snd_playSoundEffect(0x0A); @@ -206,27 +207,32 @@ void KyraEngine_LoK::loadGame(const char *fileName) { _mousePressFlag = false; setMousePos(brandonX, brandonY); - if (in->err() || in->eos()) - error("Load failed ('%s', '%s').", fileName, header.description.c_str()); - else + if (in->err() || in->eos()) { + warning("Load failed ('%s', '%s').", fileName, header.description.c_str()); + return Common::kUnknownError; + } else { debugC(1, kDebugLevelMain, "Loaded savegame '%s.'", header.description.c_str()); + } // We didn't explicitly set the walk speed, but it's saved as part of // the _timers array, so we need to re-sync it with _configWalkspeed. setWalkspeed(_configWalkspeed); delete in; + return Common::kNoError; } -void KyraEngine_LoK::saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumb) { - debugC(9, kDebugLevelMain, "KyraEngine_LoK::saveGame('%s', '%s', %p)", fileName, saveName, (const void *)thumb); +Common::Error KyraEngine_LoK::saveGameState(int slot, const char *saveName, const Graphics::Surface *thumb) { + debugC(9, kDebugLevelMain, "KyraEngine_LoK::saveGame(%d, '%s', %p)", slot, saveName, (const void *)thumb); + + const char *fileName = getSavegameFilename(slot); if (shouldQuit()) - return; + return Common::kNoError; Common::OutSaveFile *out = openSaveForWriting(fileName, saveName, thumb); if (!out) - return; + return _saveFileMan->getError(); for (int i = 0; i < 11; i++) { out->writeUint16BE(_characterList[i].sceneId); @@ -289,12 +295,15 @@ void KyraEngine_LoK::saveGame(const char *fileName, const char *saveName, const out->finalize(); // check for errors - if (out->err()) + if (out->err()) { warning("Can't write file '%s'. (Disk full?)", fileName); - else + return Common::kUnknownError; + } else { debugC(1, kDebugLevelMain, "Saved game '%s.'", saveName); + } delete out; + return Common::kNoError; } } // end of namespace Kyra diff --git a/engines/kyra/saveload_mr.cpp b/engines/kyra/saveload_mr.cpp index 0db82863ab..f2f10d635a 100644 --- a/engines/kyra/saveload_mr.cpp +++ b/engines/kyra/saveload_mr.cpp @@ -32,14 +32,14 @@ namespace Kyra { -void KyraEngine_MR::saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumb) { - debugC(9, kDebugLevelMain, "KyraEngine_LoK::saveGame('%s', '%s', %p)", fileName, saveName, (const void *)thumb); +Common::Error KyraEngine_MR::saveGameState(int slot, const char *saveName, const Graphics::Surface *thumb) { + debugC(9, kDebugLevelMain, "KyraEngine_MR::saveGame(%d, '%s', %p)", slot, saveName, (const void *)thumb); + + const char *fileName = getSavegameFilename(slot); Common::OutSaveFile *out = openSaveForWriting(fileName, saveName, thumb); - if (!out) { - warning("Can't open file '%s', game not loadable", fileName); - return; - } + if (!out) + return _saveFileMan->getError(); _timer->saveDataToFile(*out); @@ -112,23 +112,28 @@ void KyraEngine_MR::saveGame(const char *fileName, const char *saveName, const G out->finalize(); // check for errors - if (out->err()) + if (out->err()) { warning("Can't write file '%s'. (Disk full?)", fileName); - else + return Common::kUnknownError; + } else { debugC(1, kDebugLevelMain, "Saved game '%s.'", saveName); + } delete out; + return Common::kNoError; } -void KyraEngine_MR::loadGame(const char *fileName) { - debugC(9, kDebugLevelMain, "KyraEngine_MR::loadGame('%s')", fileName); +Common::Error KyraEngine_MR::loadGameState(int slot) { + debugC(9, kDebugLevelMain, "KyraEngine_MR::loadGame(%d)", slot); + + const char *fileName = getSavegameFilename(slot); SaveHeader header; Common::InSaveFile *saveFile = openSaveForReading(fileName, header); if (!saveFile) { showMessageFromCCode(17, 0xB3, 0); snd_playSoundEffect(0x0D, 0xC8); - return; + return Common::kUnknownError; } if (header.originalSave) @@ -283,10 +288,12 @@ void KyraEngine_MR::loadGame(const char *fileName) { _sceneExit3 = in.readUint16(); _sceneExit4 = in.readUint16(); - if (saveFile->err() || saveFile->eos()) - error("Load failed ('%s', '%s').", fileName, header.description.c_str()); - else + if (saveFile->err() || saveFile->eos()) { + warning("Load failed ('%s', '%s').", fileName, header.description.c_str()); + return Common::kUnknownError; + } else { debugC(1, kDebugLevelMain, "Loaded savegame '%s.'", header.description.c_str()); + } _loadingState = true; updateCharacterAnim(0); @@ -321,6 +328,8 @@ void KyraEngine_MR::loadGame(const char *fileName) { // We didn't explicitly set the walk speed, but it's saved as part of // the _timers array, so we need to re-sync it with _configWalkspeed. setWalkspeed(_configWalkspeed); + + return Common::kNoError; } } // end of namespace Kyra diff --git a/engines/kyra/script_mr.cpp b/engines/kyra/script_mr.cpp index 3e709d45e5..3273d3b89f 100644 --- a/engines/kyra/script_mr.cpp +++ b/engines/kyra/script_mr.cpp @@ -293,7 +293,7 @@ int KyraEngine_MR::o3_updateScore(EMCState *script) { int KyraEngine_MR::o3_makeSecondChanceSave(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_MR::o3_makeSecondChanceSave(%p) ()", (const void *)script); - saveGame(getSavegameFilename(999), "Autosave", 0); + saveGameState(999, "Autosave", 0); return 0; } diff --git a/engines/kyra/timer_mr.cpp b/engines/kyra/timer_mr.cpp index dd749723ce..7e8d59ed01 100644 --- a/engines/kyra/timer_mr.cpp +++ b/engines/kyra/timer_mr.cpp @@ -65,7 +65,7 @@ void KyraEngine_MR::timerRunSceneScript7(int arg) { void KyraEngine_MR::timerFleaDeath(int arg) { debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_MR::timerFleaDeath(%d)", arg); _timer->setCountdown(4, 5400); - saveGame(getSavegameFilename(999), "Autosave", 0); + saveGameState(999, "Autosave", 0); _screen->hideMouse(); _timer->disable(4); runAnimationScript("FLEADTH1.EMC", 0, 0, 1, 1); |