BLADERUNNER: Added auto save feature

Also fixed a bug in KIA save screen, where not selecting a save slot can
lead to overwriting other save game.
This commit is contained in:
Peter Kohaut 2019-02-10 18:08:54 +01:00
parent 1384afd0f6
commit eb5f454881
4 changed files with 60 additions and 7 deletions

View file

@ -109,7 +109,7 @@ BladeRunnerEngine::BladeRunnerEngine(OSystem *syst, const ADGameDescription *des
_playerDead = false;
_speechSkipped = false;
_gameOver = false;
_gameAutoSave = 0;
_gameAutoSave = -1;
_gameIsLoading = false;
_sceneIsLoading = false;
@ -309,7 +309,7 @@ Common::Error BladeRunnerEngine::run() {
_mouse->disable();
if (_gameOver) {
// autoSaveGame(4, 1); // TODO
autoSaveGame(4, true);
_endCredits->show();
}
}
@ -836,7 +836,10 @@ void BladeRunnerEngine::gameTick() {
_settings->openNewScene();
}
// TODO: Autosave
if (_gameAutoSave >= 0) {
autoSaveGame(_gameAutoSave, false);
_gameAutoSave = -1;
}
//probably not needed, this version of tick is just loading data from buffer
//_audioMixer->tick();
@ -1933,6 +1936,56 @@ void BladeRunnerEngine::newGame(int difficulty) {
_settings->setStartingGame();
}
void BladeRunnerEngine::autoSaveGame(int textId, bool endgame) {
TextResource textAutoSave(this);
if (!textAutoSave.open("AUTOSAVE")) {
return;
}
SaveStateList saveList = BladeRunner::SaveFileManager::list(getTargetName());
// Find first available save slot
int slot = -1;
int maxSlot = -1;
for (int i = 0; i < (int)saveList.size(); ++i) {
maxSlot = MAX(maxSlot, saveList[i].getSaveSlot());
if (saveList[i].getSaveSlot() != i) {
slot = i;
break;
}
}
if (slot == -1) {
slot = maxSlot + 1;
}
Common::OutSaveFile *saveFile = BladeRunner::SaveFileManager::openForSaving(getTargetName(), slot);
if (saveFile == nullptr || saveFile->err()) {
delete saveFile;
}
BladeRunner::SaveFileHeader header;
if (endgame) {
header._name = "END_GAME_STATE";
} else {
header._name = textAutoSave.getText(textId);
}
BladeRunner::SaveFileManager::writeHeader(*saveFile, header);
Graphics::Surface thumbnail = generateThumbnail();
_time->pause();
saveGame(*saveFile, thumbnail);
_time->resume();
saveFile->finalize();
thumbnail.free();
delete saveFile;
}
void BladeRunnerEngine::ISez(const Common::String &str) {
debug("\t%s", str.c_str());
}

View file

@ -286,7 +286,7 @@ public:
bool saveGame(Common::WriteStream &stream, const Graphics::Surface &thumbnail);
bool loadGame(Common::SeekableReadStream &stream);
void newGame(int difficulty);
void autoSaveGame();
void autoSaveGame(int textId, bool endgame);
void ISez(const Common::String &str);

View file

@ -1546,8 +1546,6 @@ bool ScriptBase::Game_Over() {
void ScriptBase::Autosave_Game(int textId) {
debugC(kDebugScript, "Autosave_Game(%d)", textId);
_vm->_gameAutoSave = textId;
// TODO
warning("Autosave not yet implemented");
}
void ScriptBase::I_Sez(const char *str) {

View file

@ -366,7 +366,9 @@ void KIASectionSave::save() {
slot = _saveList[_selectedLineId].getSaveSlot();
} else {
// Find first available save slot
int maxSlot = -1;
for (int i = 0; i < (int)_saveList.size(); ++i) {
maxSlot = MAX(maxSlot, _saveList[i].getSaveSlot());
if (_saveList[i].getSaveSlot() != i) {
slot = i;
break;
@ -374,7 +376,7 @@ void KIASectionSave::save() {
}
if (slot == -1) {
slot = _saveList.size();
slot = maxSlot + 1;
}
}