aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2011-01-21 13:28:35 +0000
committerSven Hesse2011-01-21 13:28:35 +0000
commit8b3f2955a458ea9c677491a4e41f9fc95c806b8d (patch)
tree9af49b2310a1858ed3c6ea90de613b2ee82e0da4
parent398c95a331c408cad596e1d0e7aca2653495bea9 (diff)
downloadscummvm-rg350-8b3f2955a458ea9c677491a4e41f9fc95c806b8d.tar.gz
scummvm-rg350-8b3f2955a458ea9c677491a4e41f9fc95c806b8d.tar.bz2
scummvm-rg350-8b3f2955a458ea9c677491a4e41f9fc95c806b8d.zip
GOB: Make the Cemetary/Lab screen work correctly
Saving there still won't work though svn-id: r55374
-rw-r--r--engines/gob/inter_v5.cpp17
-rw-r--r--engines/gob/save/savehandler.cpp4
-rw-r--r--engines/gob/save/savehandler.h3
-rw-r--r--engines/gob/save/saveload.cpp24
-rw-r--r--engines/gob/save/saveload.h22
-rw-r--r--engines/gob/save/saveload_v6.cpp70
6 files changed, 138 insertions, 2 deletions
diff --git a/engines/gob/inter_v5.cpp b/engines/gob/inter_v5.cpp
index 32e659feed..a22392be55 100644
--- a/engines/gob/inter_v5.cpp
+++ b/engines/gob/inter_v5.cpp
@@ -26,12 +26,15 @@
#include "common/endian.h"
#include "common/file.h"
+#include "gui/message.h"
+
#include "gob/gob.h"
#include "gob/inter.h"
#include "gob/global.h"
#include "gob/game.h"
#include "gob/script.h"
#include "gob/draw.h"
+#include "gob/save/saveload.h"
namespace Gob {
@@ -95,8 +98,20 @@ void Inter_v5::setupOpcodesGob() {
void Inter_v5::o5_deleteFile() {
_vm->_game->_script->evalExpr(0);
+ char *file = _vm->_game->_script->getResultStr();
+
+ debugC(2, kDebugFileIO, "Delete file \"%s\"", file);
+
+ SaveLoad::SaveMode mode = _vm->_saveLoad->getSaveMode(file);
+ if (mode == SaveLoad::kSaveModeSave) {
+
+ if (!_vm->_saveLoad->deleteFile(file)) {
+ GUI::MessageDialog dialog("Failed to save game state to file.");
+ dialog.runModal();
+ }
- warning("deleteFile: \"%s\"", _vm->_game->_script->getResultStr());
+ } else if (mode == SaveLoad::kSaveModeNone)
+ warning("Attempted to delete file \"%s\"", file);
}
void Inter_v5::o5_initScreen() {
diff --git a/engines/gob/save/savehandler.cpp b/engines/gob/save/savehandler.cpp
index d447b0dbd6..8a20665140 100644
--- a/engines/gob/save/savehandler.cpp
+++ b/engines/gob/save/savehandler.cpp
@@ -212,6 +212,10 @@ uint32 SaveHandler::getVarSize(GobEngine *vm) {
return vm->_inter->_variables->getSize();
}
+bool SaveHandler::deleteFile() {
+ return true;
+}
+
TempSpriteHandler::TempSpriteHandler(GobEngine *vm) : SaveHandler(vm) {
_sprite = 0;
diff --git a/engines/gob/save/savehandler.h b/engines/gob/save/savehandler.h
index 723215cf08..c6370947e2 100644
--- a/engines/gob/save/savehandler.h
+++ b/engines/gob/save/savehandler.h
@@ -121,6 +121,9 @@ public:
/** Saves (parts of) the file. */
virtual bool save(int16 dataVar, int32 size, int32 offset) = 0;
+ /** Deletes the file. */
+ virtual bool deleteFile();
+
static uint32 getVarSize(GobEngine *vm);
protected:
diff --git a/engines/gob/save/saveload.cpp b/engines/gob/save/saveload.cpp
index 81239f07dc..3508e58f16 100644
--- a/engines/gob/save/saveload.cpp
+++ b/engines/gob/save/saveload.cpp
@@ -117,6 +117,30 @@ bool SaveLoad::save(const char *fileName, int16 dataVar, int32 size, int32 offse
return true;
}
+bool SaveLoad::deleteFile(const char *fileName) {
+ debugC(3, kDebugSaveLoad, "Requested deletion save file \"%s\"", fileName);
+
+ SaveHandler *handler = getHandler(fileName);
+
+ if (!handler) {
+ warning("No save handler for \"%s\"", fileName);
+ return false;
+ }
+
+ if (!handler->deleteFile()) {
+ const char *desc = getDescription(fileName);
+
+ if (!desc)
+ desc = "Unknown";
+
+ warning("Could not delete %s (\"%s\")", desc, fileName);
+ return false;
+ }
+
+ debugC(3, kDebugSaveLoad, "Successfully deleted file");
+ return true;
+}
+
SaveLoad::SaveMode SaveLoad::getSaveMode(const char *fileName) const {
return kSaveModeNone;
}
diff --git a/engines/gob/save/saveload.h b/engines/gob/save/saveload.h
index 89beafd9fc..af1c323723 100644
--- a/engines/gob/save/saveload.h
+++ b/engines/gob/save/saveload.h
@@ -64,6 +64,9 @@ public:
/** Saves size bytes from the variables starting with data dataVar at offset. */
bool save(const char *fileName, int16 dataVar, int32 size, int32 offset);
+ /** Deletes the file. */
+ bool deleteFile(const char *fileName);
+
protected:
GobEngine *_vm;
@@ -653,10 +656,29 @@ protected:
File _file;
};
+ /** Handles the temporary saves. */
+ class TempHandler : public SaveHandler {
+ public:
+ TempHandler(GobEngine *vm);
+ ~TempHandler();
+
+ int32 getSize();
+ bool load(int16 dataVar, int32 size, int32 offset);
+ bool save(int16 dataVar, int32 size, int32 offset);
+ bool deleteFile();
+
+ private:
+ bool _empty;
+
+ uint32 _size;
+ byte *_data;
+ };
+
static SaveFile _saveFiles[];
GameHandler *_gameHandler;
AutoHandler *_autoHandler;
+ TempHandler *_tmpHandler[2];
SaveHandler *getHandler(const char *fileName) const;
const char *getDescription(const char *fileName) const;
diff --git a/engines/gob/save/saveload_v6.cpp b/engines/gob/save/saveload_v6.cpp
index 8961b050f2..9a439fbf4c 100644
--- a/engines/gob/save/saveload_v6.cpp
+++ b/engines/gob/save/saveload_v6.cpp
@@ -37,7 +37,9 @@ SaveLoad_v6::SaveFile SaveLoad_v6::_saveFiles[] = {
{ "no_cd.txt", kSaveModeExists, 0, 0},
{ "vide.inf", kSaveModeIgnore, 0, 0},
{"fenetre.txt", kSaveModeIgnore, 0, 0},
- { "music.txt", kSaveModeIgnore, 0, 0}
+ { "music.txt", kSaveModeIgnore, 0, 0},
+ { "cata2.inf", kSaveModeSave, 0, "temp save"},
+ { "cata3.inf", kSaveModeSave, 0, "temp save"}
};
@@ -374,17 +376,83 @@ bool SaveLoad_v6::AutoHandler::save(int16 dataVar, int32 size, int32 offset) {
}
+SaveLoad_v6::TempHandler::TempHandler(GobEngine *vm) : SaveHandler(vm),
+ _empty(true), _size(0), _data(0) {
+}
+
+SaveLoad_v6::TempHandler::~TempHandler() {
+ delete[] _data;
+}
+
+int32 SaveLoad_v6::TempHandler::getSize() {
+ if (_empty)
+ return -1;
+
+ return _size + 2900;
+}
+
+bool SaveLoad_v6::TempHandler::load(int16 dataVar, int32 size, int32 offset) {
+ if (_empty || (_size == 0) || !_data)
+ return false;
+
+ if ((size != 0) || (offset != 2900)) {
+ warning("Invalid temp loading procedure (%d, %d, %d)", dataVar, size, offset);
+ return false;
+ }
+
+ _vm->_inter->_variables->copyFrom(0, _data, _size);
+
+ return true;
+}
+
+bool SaveLoad_v6::TempHandler::save(int16 dataVar, int32 size, int32 offset) {
+ if ((size != 0) || (offset != 2900)) {
+ warning("Invalid temp saving procedure (%d, %d, %d)", dataVar, size, offset);
+ return false;
+ }
+
+ delete[] _data;
+
+ _size = SaveHandler::getVarSize(_vm);
+ _data = new byte[_size];
+
+ _vm->_inter->_variables->copyTo(0, _data, _size);
+
+ _empty = false;
+
+ return true;
+}
+
+bool SaveLoad_v6::TempHandler::deleteFile() {
+ delete[] _data;
+
+ _empty = true;
+ _size = 0;
+ _data = 0;
+
+ return true;
+}
+
+
SaveLoad_v6::SaveLoad_v6(GobEngine *vm, const char *targetName) :
SaveLoad(vm) {
_gameHandler = new GameHandler(vm, targetName);
_autoHandler = new AutoHandler(vm, targetName);
+ _tmpHandler[0] = new TempHandler(vm);
+ _tmpHandler[1] = new TempHandler(vm);
+
_saveFiles[0].handler = _gameHandler;
_saveFiles[1].handler = _autoHandler;
+
+ _saveFiles[7].handler = _tmpHandler[0];
+ _saveFiles[8].handler = _tmpHandler[1];
}
SaveLoad_v6::~SaveLoad_v6() {
+ delete _tmpHandler[0];
+ delete _tmpHandler[1];
delete _autoHandler;
delete _gameHandler;
}