Added -x and --list-saves support for LURE

svn-id: r33291
This commit is contained in:
Christopher Page 2008-07-25 19:41:17 +00:00
parent 50a5410316
commit dac805c281
4 changed files with 89 additions and 21 deletions

View File

@ -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

View File

@ -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()) {

View File

@ -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 (ConfMan.getInt("boot_param") == 0) {
// Show the introduction
Sound.loadSection(Sound.isRoland() ? ROLAND_INTRO_SOUND_RESOURCE_ID : ADLIB_INTRO_SOUND_RESOURCE_ID);
if (!result)
error("Sorry - copy protection failed");
}
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

View File

@ -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