Permalink
Browse files

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.
  • Loading branch information...
peterkohaut committed Feb 10, 2019
1 parent 1384afd commit eb5f4548819052bc6d33fce2e291b3ca864fbf06
@@ -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());
}
@@ -286,7 +286,7 @@ class BladeRunnerEngine : public Engine {
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);

@@ -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) {
@@ -366,15 +366,17 @@ 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;
}
}

if (slot == -1) {
slot = _saveList.size();
slot = maxSlot + 1;
}
}

0 comments on commit eb5f454

Please sign in to comment.