Revert "ZVISION: Remove ActionRestoreGame and loading of r.svr (restart slot)"

This reverts commit 9f642074ba8e17aa23b01bcee82b2293fe84f8f1, as it
broke the credits screen in ZGI.

This has been rewritten to use the common save code
This commit is contained in:
Filippos Karapetis 2015-01-10 22:03:15 +02:00
parent 899cf4813c
commit 21e9007d80
7 changed files with 48 additions and 14 deletions

View File

@ -130,12 +130,25 @@ void SaveManager::writeSaveGameHeader(Common::OutSaveFile *file, const Common::S
file->writeSint16LE(td.tm_min); file->writeSint16LE(td.tm_min);
} }
Common::Error SaveManager::loadGame(uint slot) { Common::Error SaveManager::loadGame(int slot) {
Common::SeekableReadStream *saveFile = getSlotFile(slot); Common::SeekableReadStream *saveFile = NULL;
if (saveFile == 0) {
return Common::kPathDoesNotExist; if (slot >= 0) {
saveFile = getSlotFile(slot);
} else {
Common::File *saveFile = _engine->getSearchManager()->openFile("r.svr");
if (!saveFile) {
saveFile = new Common::File;
if (!saveFile->open("r.svr")) {
delete saveFile;
return Common::kPathDoesNotExist;
}
}
} }
if (!saveFile)
return Common::kPathDoesNotExist;
// Read the header // Read the header
SaveGameHeader header; SaveGameHeader header;
if (!readSaveGameHeader(saveFile, header)) { if (!readSaveGameHeader(saveFile, header)) {

View File

@ -91,7 +91,7 @@ public:
* *
* @param slot The save slot to load. Must be [1, 20] * @param slot The save slot to load. Must be [1, 20]
*/ */
Common::Error loadGame(uint slot); Common::Error loadGame(int slot);
Common::SeekableReadStream *getSlotFile(uint slot); Common::SeekableReadStream *getSlotFile(uint slot);
bool readSaveGameHeader(Common::SeekableReadStream *in, SaveGameHeader &header); bool readSaveGameHeader(Common::SeekableReadStream *in, SaveGameHeader &header);

View File

@ -23,11 +23,12 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "video/video_decoder.h" #include "video/video_decoder.h"
#include "zvision/scripting/actions.h"
#include "zvision/zvision.h" #include "zvision/zvision.h"
#include "zvision/scripting/script_manager.h" #include "zvision/scripting/script_manager.h"
#include "zvision/graphics/render_manager.h" #include "zvision/graphics/render_manager.h"
#include "zvision/file/save_manager.h" #include "zvision/file/save_manager.h"
#include "zvision/scripting/actions.h"
#include "zvision/scripting/menu.h" #include "zvision/scripting/menu.h"
#include "zvision/scripting/effects/timer_effect.h" #include "zvision/scripting/effects/timer_effect.h"
#include "zvision/scripting/effects/music_effect.h" #include "zvision/scripting/effects/music_effect.h"
@ -797,6 +798,22 @@ bool ActionRandom::execute() {
return true; return true;
} }
//////////////////////////////////////////////////////////////////////////////
// ActionRestoreGame
//////////////////////////////////////////////////////////////////////////////
ActionRestoreGame::ActionRestoreGame(ZVision *engine, int32 slotkey, const Common::String &line) :
ResultAction(engine, slotkey) {
char buf[128];
sscanf(line.c_str(), "%s", buf);
_fileName = Common::String(buf);
}
bool ActionRestoreGame::execute() {
_engine->getSaveManager()->loadGame(-1);
return false;
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// ActionRotateTo // ActionRotateTo
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -340,6 +340,15 @@ private:
ValueSlot *_max; ValueSlot *_max;
}; };
class ActionRestoreGame : public ResultAction {
public:
ActionRestoreGame(ZVision *engine, int32 slotkey, const Common::String &line);
bool execute();
private:
Common::String _fileName;
};
class ActionRotateTo : public ResultAction { class ActionRotateTo : public ResultAction {
public: public:
ActionRotateTo(ZVision *engine, int32 slotkey, const Common::String &line); ActionRotateTo(ZVision *engine, int32 slotkey, const Common::String &line);

View File

@ -271,8 +271,8 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis
actionList.push_back(new ActionRegion(_engine, slot, args)); actionList.push_back(new ActionRegion(_engine, slot, args));
} else if (act.matchString("restore_game", true)) { } else if (act.matchString("restore_game", true)) {
// Only used by ZGI to load the restart game slot, r.svr. // Only used by ZGI to load the restart game slot, r.svr.
_engine->getScriptManager()->reset(); // Used by the credits screen.
_engine->getScriptManager()->changeLocation('g', 'a', 'r', 'y', 0); actionList.push_back(new ActionRestoreGame(_engine, slot, args));
} else if (act.matchString("rotate_to", true)) { } else if (act.matchString("rotate_to", true)) {
actionList.push_back(new ActionRotateTo(_engine, slot, args)); actionList.push_back(new ActionRotateTo(_engine, slot, args));
} else if (act.matchString("save_game", true)) { } else if (act.matchString("save_game", true)) {

View File

@ -686,7 +686,7 @@ void ScriptManager::serialize(Common::WriteStream *stream) {
stream->writeSint16LE(getStateValue(i)); stream->writeSint16LE(getStateValue(i));
} }
void ScriptManager::reset() { void ScriptManager::deserialize(Common::SeekableReadStream *stream) {
// Clear out the current table values // Clear out the current table values
_globalState.clear(); _globalState.clear();
_globalStateFlags.clear(); _globalStateFlags.clear();
@ -706,10 +706,6 @@ void ScriptManager::reset() {
_activeSideFx.clear(); _activeSideFx.clear();
_referenceTable.clear(); _referenceTable.clear();
}
void ScriptManager::deserialize(Common::SeekableReadStream *stream) {
reset();
if (stream->readUint32BE() != MKTAG('Z', 'N', 'S', 'G') || stream->readUint32LE() != 4) { if (stream->readUint32BE() != MKTAG('Z', 'N', 'S', 'G') || stream->readUint32LE() != 4) {
changeLocation('g', 'a', 'r', 'y', 0); changeLocation('g', 'a', 'r', 'y', 0);

View File

@ -248,7 +248,6 @@ public:
void serialize(Common::WriteStream *stream); void serialize(Common::WriteStream *stream);
void deserialize(Common::SeekableReadStream *stream); void deserialize(Common::SeekableReadStream *stream);
void reset();
Location getCurrentLocation() const; Location getCurrentLocation() const;
Location getLastLocation(); Location getLastLocation();