diff options
author | Christopher Page | 2008-07-25 19:41:17 +0000 |
---|---|---|
committer | Christopher Page | 2008-07-25 19:41:17 +0000 |
commit | dac805c281d9dd37140644315bc968d7f312a265 (patch) | |
tree | 2b7961b7b2c08ef09de644f297188d903285d85c /engines | |
parent | 50a54103169487e2173727e2c5b8b25445a376f3 (diff) | |
download | scummvm-rg350-dac805c281d9dd37140644315bc968d7f312a265.tar.gz scummvm-rg350-dac805c281d9dd37140644315bc968d7f312a265.tar.bz2 scummvm-rg350-dac805c281d9dd37140644315bc968d7f312a265.zip |
Added -x and --list-saves support for LURE
svn-id: r33291
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lure/detection.cpp | 30 | ||||
-rw-r--r-- | engines/lure/game.cpp | 12 | ||||
-rw-r--r-- | engines/lure/lure.cpp | 65 | ||||
-rw-r--r-- | engines/lure/lure.h | 5 |
4 files changed, 90 insertions, 22 deletions
diff --git a/engines/lure/detection.cpp b/engines/lure/detection.cpp index 7dd1c77348..8ed2e62760 100644 --- a/engines/lure/detection.cpp +++ b/engines/lure/detection.cpp @@ -26,6 +26,7 @@ #include "base/plugins.h" #include "common/advancedDetector.h" +#include "common/savefile.h" #include "lure/lure.h" @@ -185,6 +186,7 @@ public: } virtual bool createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const; + virtual SaveStateList listSaves(const char *target) const; }; bool LureMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const { @@ -195,6 +197,34 @@ bool LureMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common return gd != 0; } +SaveStateList LureMetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringList filenames; + Common::String saveDesc; + Common::String pattern = target; + pattern += ".???"; + + filenames = saveFileMan->listSavefiles(pattern.c_str()); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + SaveStateList saveList; + for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + if (slotNum >= 0 && slotNum <= 999) { + Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); + if (in) { + saveDesc = Lure::getSaveName(in); + saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file)); + delete in; + } + } + } + + return saveList; +} + #if PLUGIN_ENABLED_DYNAMIC(LURE) REGISTER_PLUGIN_DYNAMIC(LURE, PLUGIN_TYPE_ENGINE, LureMetaEngine); #else diff --git a/engines/lure/game.cpp b/engines/lure/game.cpp index 195ad0fd66..479877f229 100644 --- a/engines/lure/game.cpp +++ b/engines/lure/game.cpp @@ -138,9 +138,17 @@ void Game::execute() { screen.empty(); screen.setPaletteEmpty(); + + bool _loadSavegame = false; + + if (engine.gameToLoad() != -1) + _loadSavegame = engine.loadGame(engine.gameToLoad()); + + if (!_loadSavegame) { + // Flag for starting game + setState(GS_RESTART); + } - // Flag for starting game - setState(GS_RESTART); bool initialRestart = true; while (!engine.quit()) { diff --git a/engines/lure/lure.cpp b/engines/lure/lure.cpp index 3cab41da71..335f3384a1 100644 --- a/engines/lure/lure.cpp +++ b/engines/lure/lure.cpp @@ -92,6 +92,7 @@ int LureEngine::init() { _room = new Room(); _fights = new FightsManager(); + _gameToLoad = -1; _initialised = true; return 0; } @@ -121,27 +122,34 @@ LureEngine &LureEngine::getReference() { } int LureEngine::go() { - - if (ConfMan.getBool("copy_protection")) { - CopyProtectionDialog *dialog = new CopyProtectionDialog(); - bool result = dialog->show(); - delete dialog; - if (quit()) - return _eventMan->shouldRTL(); - - if (!result) - error("Sorry - copy protection failed"); - } - Game *gameInstance = new Game(); + + // If requested, load a savegame instead of showing the intro + if (ConfMan.hasKey("save_slot")) { + _gameToLoad = ConfMan.getInt("save_slot"); + if (_gameToLoad < 0 || _gameToLoad > 999) + _gameToLoad = -1; + } + + if (_gameToLoad == -1) { + if (ConfMan.getBool("copy_protection")) { + CopyProtectionDialog *dialog = new CopyProtectionDialog(); + bool result = dialog->show(); + delete dialog; + if (quit()) + return _eventMan->shouldRTL(); + + if (!result) + error("Sorry - copy protection failed"); + } - if (ConfMan.getInt("boot_param") == 0) { - // Show the introduction - Sound.loadSection(Sound.isRoland() ? ROLAND_INTRO_SOUND_RESOURCE_ID : ADLIB_INTRO_SOUND_RESOURCE_ID); - - Introduction *intro = new Introduction(); - intro->show(); - delete intro; + if (ConfMan.getInt("boot_param") == 0) { + // Show the introduction + Sound.loadSection(Sound.isRoland() ? ROLAND_INTRO_SOUND_RESOURCE_ID : ADLIB_INTRO_SOUND_RESOURCE_ID); + Introduction *intro = new Introduction(); + intro->show(); + delete intro; + } } // Play the game @@ -278,4 +286,23 @@ Common::String *LureEngine::detectSave(int slotNumber) { return result; } +Common::String getSaveName(Common::InSaveFile *in) { + // Check for header + char saveName[MAX_DESC_SIZE]; + char buffer[5]; + in->read(&buffer[0], 5); + if (memcmp(&buffer[0], "lure", 5) == 0) { + // Check language version + in->readByte(); + in->readByte(); + char *p = saveName; + int decCtr = MAX_DESC_SIZE - 1; + while ((decCtr > 0) && ((*p++ = in->readByte()) != 0)) --decCtr; + *p = '\0'; + + } + + return Common::String(saveName); +} + } // End of namespace Lure diff --git a/engines/lure/lure.h b/engines/lure/lure.h index 940e04edc7..2c1a70329e 100644 --- a/engines/lure/lure.h +++ b/engines/lure/lure.h @@ -30,6 +30,7 @@ #include "common/rect.h" #include "sound/mixer.h" #include "common/file.h" +#include "common/savefile.h" #include "lure/disk.h" #include "lure/res.h" @@ -47,6 +48,7 @@ struct LureGameDescription; class LureEngine : public Engine { private: bool _initialised; + int _gameToLoad; uint8 _saveVersion; Disk *_disk; Resources *_resources; @@ -74,6 +76,7 @@ public: Disk &disk() { return *_disk; } + int gameToLoad() { return _gameToLoad; } bool loadGame(uint8 slotNumber); bool saveGame(uint8 slotNumber, Common::String &caption); Common::String *detectSave(int slotNumber); @@ -85,7 +88,7 @@ public: Common::Platform getPlatform() const; bool isEGA() const { return (getFeatures() & GF_EGA) != 0; } }; - + Common::String getSaveName(Common::InSaveFile *in); } // End of namespace Lure #endif |