aboutsummaryrefslogtreecommitdiff
path: root/engines/bladerunner
diff options
context:
space:
mode:
Diffstat (limited to 'engines/bladerunner')
-rw-r--r--engines/bladerunner/bladerunner.cpp59
-rw-r--r--engines/bladerunner/bladerunner.h2
-rw-r--r--engines/bladerunner/script/script.cpp2
-rw-r--r--engines/bladerunner/ui/kia_section_save.cpp4
4 files changed, 60 insertions, 7 deletions
diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp
index d66836510c..bad251a333 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 10aaf37bff..7f7883a410 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 983d998a18..502344bf6f 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 b042dc8097..6bdcec964e 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;
}
}