diff options
Diffstat (limited to 'engines/sword2/sword2.cpp')
-rw-r--r-- | engines/sword2/sword2.cpp | 91 |
1 files changed, 67 insertions, 24 deletions
diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index 7331d1f761..dc884eaacb 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -33,6 +33,7 @@ #include "common/file.h" #include "common/fs.h" #include "common/events.h" +#include "common/savefile.h" #include "common/system.h" #include "engines/metaengine.h" @@ -79,13 +80,24 @@ public: return "Broken Sword Games (C) Revolution"; } + virtual bool hasFeature(MetaEngineFeature f) const; virtual GameList getSupportedGames() const; virtual GameDescriptor findGame(const char *gameid) const; - virtual GameList detectGames(const FSList &fslist) const; + virtual GameList detectGames(const Common::FSList &fslist) const; + virtual SaveStateList listSaves(const char *target) const; + virtual void removeSaveState(const char *target, int slot) const; virtual PluginError createInstance(OSystem *syst, Engine **engine) const; }; +bool Sword2MetaEngine::hasFeature(MetaEngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsListSaves) || + (f == kSupportsDirectLoad) || + (f == kSupportsDeleteSave); +} + GameList Sword2MetaEngine::getSupportedGames() const { const Sword2::GameSettings *g = Sword2::sword2_settings; GameList games; @@ -106,10 +118,10 @@ GameDescriptor Sword2MetaEngine::findGame(const char *gameid) const { return GameDescriptor(g->gameid, g->description); } -GameList Sword2MetaEngine::detectGames(const FSList &fslist) const { +GameList Sword2MetaEngine::detectGames(const Common::FSList &fslist) const { GameList detectedGames; const Sword2::GameSettings *g; - FSList::const_iterator file; + Common::FSList::const_iterator file; // TODO: It would be nice if we had code here which distinguishes // between the 'sword2' and 'sword2demo' targets. The current code @@ -139,8 +151,8 @@ GameList Sword2MetaEngine::detectGames(const FSList &fslist) const { const char *fileName = file->getName().c_str(); if (0 == scumm_stricmp("clusters", fileName)) { - FSList recList; - if (file->getChildren(recList, FilesystemNode::kListAll)) { + Common::FSList recList; + if (file->getChildren(recList, Common::FilesystemNode::kListAll)) { GameList recGames(detectGames(recList)); if (!recGames.empty()) { detectedGames.push_back(recGames); @@ -156,13 +168,52 @@ GameList Sword2MetaEngine::detectGames(const FSList &fslist) const { return detectedGames; } +SaveStateList Sword2MetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringList filenames; + char saveDesc[SAVE_DESCRIPTION_LEN]; + 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) { + in->readUint32LE(); + in->read(saveDesc, SAVE_DESCRIPTION_LEN); + saveList.push_back(SaveStateDescriptor(slotNum, Common::String(saveDesc), *file)); + delete in; + } + } + } + + return saveList; +} + +void Sword2MetaEngine::removeSaveState(const char *target, int slot) const { + char extension[6]; + snprintf(extension, sizeof(extension), ".%03d", slot); + + Common::String filename = target; + filename += extension; + + g_system->getSavefileManager()->removeSavefile(filename.c_str()); +} + PluginError Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) const { assert(syst); assert(engine); - FSList fslist; - FilesystemNode dir(ConfMan.get("path")); - if (!dir.getChildren(fslist, FilesystemNode::kListAll)) { + Common::FSList fslist; + Common::FilesystemNode dir(ConfMan.get("path")); + if (!dir.getChildren(fslist, Common::FilesystemNode::kListAll)) { return kInvalidPathError; } @@ -190,12 +241,12 @@ namespace Sword2 { Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) { // Add default file directories - Common::File::addDefaultDirectory(_gameDataPath + "CLUSTERS/"); - Common::File::addDefaultDirectory(_gameDataPath + "SWORD2/"); - Common::File::addDefaultDirectory(_gameDataPath + "VIDEO/"); - Common::File::addDefaultDirectory(_gameDataPath + "clusters/"); - Common::File::addDefaultDirectory(_gameDataPath + "sword2/"); - Common::File::addDefaultDirectory(_gameDataPath + "video/"); + Common::File::addDefaultDirectory(_gameDataDir.getChild("CLUSTERS")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("SWORD2")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("VIDEO")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("clusters")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("sword2")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("video")); if (0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2demo")) _features = GF_DEMO; @@ -229,7 +280,6 @@ Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) { _gameCycle = 0; _gameSpeed = 1; - _quit = false; syst->getEventManager()->registerRandomSource(_rnd, "sword2"); } @@ -371,7 +421,7 @@ int Sword2Engine::init() { // player will kill the music for us. Otherwise, the restore // will either have killed the music, or done a crossfade. - if (_quit) + if (quit()) return 0; if (result) @@ -443,7 +493,7 @@ int Sword2Engine::go() { // because we want the break to happen before updating the // screen again. - if (_quit) + if (quit()) break; // creates the debug text blocks @@ -463,10 +513,6 @@ int Sword2Engine::go() { return 0; } -void Sword2Engine::closeGame() { - _quit = true; -} - void Sword2Engine::restartGame() { ScreenInfo *screenInfo = _screen->getScreenInfo(); uint32 temp_demo_flag; @@ -610,9 +656,6 @@ void Sword2Engine::parseInputEvents() { _mouseEvent.buttons = RD_WHEELDOWN; } break; - case Common::EVENT_QUIT: - closeGame(); - break; default: break; } |