[Scummvm-git-logs] scummvm master -> eb5f4548819052bc6d33fce2e291b3ca864fbf06
peterkohaut
peterkohaut at users.noreply.github.com
Sun Feb 10 18:11:15 CET 2019
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
eb5f454881 BLADERUNNER: Added auto save feature
Commit: eb5f4548819052bc6d33fce2e291b3ca864fbf06
https://github.com/scummvm/scummvm/commit/eb5f4548819052bc6d33fce2e291b3ca864fbf06
Author: Peter Kohaut (peter.kohaut at gmail.com)
Date: 2019-02-10T18:10:25+01:00
Commit Message:
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.
Changed paths:
engines/bladerunner/bladerunner.cpp
engines/bladerunner/bladerunner.h
engines/bladerunner/script/script.cpp
engines/bladerunner/ui/kia_section_save.cpp
diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp
index d668365..bad251a 100644
--- a/engines/bladerunner/bladerunner.cpp
+++ b/engines/bladerunner/bladerunner.cpp
@@ -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());
}
diff --git a/engines/bladerunner/bladerunner.h b/engines/bladerunner/bladerunner.h
index 10aaf37..7f7883a 100644
--- a/engines/bladerunner/bladerunner.h
+++ b/engines/bladerunner/bladerunner.h
@@ -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);
diff --git a/engines/bladerunner/script/script.cpp b/engines/bladerunner/script/script.cpp
index 983d998..502344b 100644
--- a/engines/bladerunner/script/script.cpp
+++ b/engines/bladerunner/script/script.cpp
@@ -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) {
diff --git a/engines/bladerunner/ui/kia_section_save.cpp b/engines/bladerunner/ui/kia_section_save.cpp
index b042dc8..6bdcec9 100644
--- a/engines/bladerunner/ui/kia_section_save.cpp
+++ b/engines/bladerunner/ui/kia_section_save.cpp
@@ -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;
}
}
More information about the Scummvm-git-logs
mailing list