diff options
-rw-r--r-- | engines/sword1/control.cpp | 3 | ||||
-rw-r--r-- | engines/sword1/control.h | 1 | ||||
-rw-r--r-- | engines/sword1/sword1.cpp | 16 |
3 files changed, 15 insertions, 5 deletions
diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp index 3a26f4dd33..d0808d3ece 100644 --- a/engines/sword1/control.cpp +++ b/engines/sword1/control.cpp @@ -703,7 +703,7 @@ void Control::handleSaveKey(Common::KeyState kbd) { bool Control::saveToFile(void) { if ((_selectedSavegame == 255) || !strlen((char*)_saveNames[_selectedSavegame])) return false; // no saveslot selected or no name entered - saveGameToFile(_selectedSavegame); + saveGameToFile(_numSaves); writeSavegameDescriptions(); return true; } @@ -741,6 +741,7 @@ void Control::readSavegameDescriptions(void) { curFileNum++; } while ((ch != 255) && (!inf->eos())); _saveFiles = curFileNum; + _numSaves = _saveFiles; } delete inf; } diff --git a/engines/sword1/control.h b/engines/sword1/control.h index 7d9af2f199..926db757b9 100644 --- a/engines/sword1/control.h +++ b/engines/sword1/control.h @@ -98,6 +98,7 @@ private: void deselectSaveslots(void); uint8 *_restoreBuf; uint8 _saveFiles; + uint8 _numSaves; uint8 _saveScrollPos; uint8 _selectedSavegame; uint8 _saveNames[64][32]; diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp index de346a42dc..1a7ae87f66 100644 --- a/engines/sword1/sword1.cpp +++ b/engines/sword1/sword1.cpp @@ -199,12 +199,20 @@ PluginError SwordMetaEngine::createInstance(OSystem *syst, Engine **engine) cons SaveStateList SwordMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveStateList saveList; + + Common::String pattern = "SAVEGAME.???"; + Common::StringList filenames = saveFileMan->listSavefiles(pattern.c_str()); + sort(filenames.begin(), filenames.end()); + Common::StringList::const_iterator file = filenames.begin(); + Common::InSaveFile *in = saveFileMan->openForLoading("SAVEGAME.INF"); if (in) { uint8 stop; char saveDesc[32]; - int slotNum = 0; do { + // Obtain the last digit of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 1); + uint pos = 0; do { stop = in->readByte(); @@ -218,8 +226,8 @@ SaveStateList SwordMetaEngine::listSaves(const char *target) const { } } while ((stop != 10) && (stop != 255) && (!in->eos())); if (saveDesc[0] != 0) { - saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, "SAVEGAME.INF")); - slotNum++; + saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file)); + file++; } } while ((stop != 255) && (!in->eos())); } @@ -688,7 +696,7 @@ int SwordEngine::go() { int saveSlot = ConfMan.getInt("save_slot"); // Savegames are numbered starting from 1 in the dialog window, // but their filenames are numbered starting from 0. - if (saveSlot > 0 && _control->restoreGameFromFile(saveSlot - 1)) { + if (saveSlot >= 0 && _control->savegamesExist() &&_control->restoreGameFromFile(saveSlot)) { _control->doRestore(); } else if (_control->savegamesExist()) { _systemVars.controlPanelMode = CP_NEWGAME; |