aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/zvision/core/save_manager.cpp40
-rw-r--r--engines/zvision/core/save_manager.h1
-rw-r--r--engines/zvision/detection.cpp83
-rw-r--r--engines/zvision/scripting/controls/save_control.cpp2
-rw-r--r--engines/zvision/scripting/script_manager.cpp23
-rw-r--r--engines/zvision/utility/clock.h3
-rw-r--r--engines/zvision/utility/utility.cpp15
-rw-r--r--engines/zvision/video/video.cpp2
-rw-r--r--engines/zvision/zvision.cpp9
-rw-r--r--engines/zvision/zvision.h8
10 files changed, 137 insertions, 49 deletions
diff --git a/engines/zvision/core/save_manager.cpp b/engines/zvision/core/save_manager.cpp
index 11d3dd391a..20bd39fde5 100644
--- a/engines/zvision/core/save_manager.cpp
+++ b/engines/zvision/core/save_manager.cpp
@@ -23,22 +23,60 @@
#include "common/scummsys.h"
#include "zvision/core/save_manager.h"
-
#include "zvision/zvision.h"
#include "zvision/scripting/script_manager.h"
#include "zvision/graphics/render_manager.h"
#include "common/system.h"
+#include "common/translation.h"
#include "graphics/surface.h"
#include "graphics/thumbnail.h"
#include "gui/message.h"
+#include "gui/saveload.h"
namespace ZVision {
const uint32 SaveManager::SAVEGAME_ID = MKTAG('Z', 'E', 'N', 'G');
+bool SaveManager::scummVMSaveLoadDialog(bool isSave) {
+ GUI::SaveLoadChooser *dialog;
+ Common::String desc;
+ int slot;
+
+ if (isSave) {
+ dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
+
+ slot = dialog->runModalWithCurrentTarget();
+ desc = dialog->getResultString();
+
+ if (desc.empty()) {
+ // create our own description for the saved game, the user didnt enter it
+ desc = dialog->createDefaultSaveDescription(slot);
+ }
+
+ if (desc.size() > 28)
+ desc = Common::String(desc.c_str(), 28);
+ } else {
+ dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
+ slot = dialog->runModalWithCurrentTarget();
+ }
+
+ delete dialog;
+
+ if (slot < 0)
+ return false;
+
+ if (isSave) {
+ saveGame(slot, desc);
+ return true;
+ } else {
+ Common::ErrorCode result = loadGame(slot).getCode();
+ return (result == Common::kNoError);
+ }
+}
+
void SaveManager::saveGame(uint slot, const Common::String &saveName) {
// The games only support 20 slots
//assert(slot <= 1 && slot <= 20);
diff --git a/engines/zvision/core/save_manager.h b/engines/zvision/core/save_manager.h
index 5cd61c7aa9..75841331e7 100644
--- a/engines/zvision/core/save_manager.h
+++ b/engines/zvision/core/save_manager.h
@@ -96,6 +96,7 @@ public:
void prepareSaveBuffer();
void flushSaveBuffer();
+ bool scummVMSaveLoadDialog(bool isSave);
private:
void writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName);
};
diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp
index 4d210abe86..ebf5bdcfdd 100644
--- a/engines/zvision/detection.cpp
+++ b/engines/zvision/detection.cpp
@@ -26,6 +26,8 @@
#include "zvision/zvision.h"
#include "zvision/detection.h"
+#include "zvision/core/save_manager.h"
+#include "zvision/scripting/script_manager.h"
#include "common/translation.h"
#include "common/savefile.h"
@@ -178,24 +180,40 @@ public:
};
bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const {
- return false;
- /*
+ return
(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail) ||
- (f == kSavesSupportCreationDate) ||
- (f == kSavesSupportPlayTime);
- */
+ (f == kSavesSupportCreationDate);
+ //(f == kSavesSupportPlayTime);
}
-/*bool ZVision::ZVision::hasFeature(EngineFeature f) const {
+bool ZVision::ZVision::hasFeature(EngineFeature f) const {
return
(f == kSupportsRTL) ||
(f == kSupportsLoadingDuringRuntime) ||
(f == kSupportsSavingDuringRuntime);
-}*/
+}
+
+Common::Error ZVision::ZVision::loadGameState(int slot) {
+ return _saveManager->loadGame(slot);
+}
+
+Common::Error ZVision::ZVision::saveGameState(int slot, const Common::String &desc) {
+ _saveManager->saveGame(slot, desc);
+ return Common::kNoError;
+}
+
+bool ZVision::ZVision::canLoadGameStateCurrently() {
+ return !_videoIsPlaying;
+}
+
+bool ZVision::ZVision::canSaveGameStateCurrently() {
+ Location currentLocation = _scriptManager->getCurrentLocation();
+ return !_videoIsPlaying && currentLocation.world != 'g' && !(currentLocation.room == 'j' || currentLocation.room == 'a');
+}
bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc;
@@ -213,8 +231,8 @@ const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String
}
SaveStateList ZVisionMetaEngine::listSaves(const char *target) const {
- //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
- /*ZVision::ZVision::SaveHeader header;
+ Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+ ZVision::SaveGameHeader header;
Common::String pattern = target;
pattern += ".???";
@@ -223,20 +241,25 @@ SaveStateList ZVisionMetaEngine::listSaves(const char *target) const {
Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/
SaveStateList saveList;
- /* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) {
+ // We only use readSaveGameHeader() here, which doesn't need an engine callback
+ ZVision::SaveManager *zvisionSaveMan = new ZVision::SaveManager(NULL);
+
+ for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 3);
if (slotNum >= 0 && slotNum <= 999) {
Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str());
if (in) {
- if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) {
- saveList.push_back(SaveStateDescriptor(slotNum, header.description));
+ if (zvisionSaveMan->readSaveGameHeader(in, header)) {
+ saveList.push_back(SaveStateDescriptor(slotNum, header.saveName));
}
delete in;
}
}
- }*/
+ }
+
+ delete zvisionSaveMan;
return saveList;
}
@@ -246,9 +269,8 @@ int ZVisionMetaEngine::getMaximumSaveSlot() const {
}
void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const {
- /*
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
- Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot);
+ Common::String filename = Common::String::format("%s.%03u", target, slot);
saveFileMan->removeSavefile(filename.c_str());
@@ -265,48 +287,47 @@ void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const {
// Rename every slot greater than the deleted slot,
if (slotNum > slot) {
saveFileMan->renameSavefile(file->c_str(), filename.c_str());
- filename = ZVision::ZVision::getSavegameFilename(target, ++slot);
+ filename = Common::String::format("%s.%03u", target, ++slot);
}
}
- */
}
SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
- /*
- Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot);
+ Common::String filename = Common::String::format("%s.%03u", target, slot);
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str());
if (in) {
- ZVision::ZVision::SaveHeader header;
- ZVision::ZVision::kReadSaveHeaderError error;
+ ZVision::SaveGameHeader header;
- error = ZVision::ZVision::readSaveHeader(in, true, header);
+ // We only use readSaveGameHeader() here, which doesn't need an engine callback
+ ZVision::SaveManager *zvisionSaveMan = new ZVision::SaveManager(NULL);
+ bool successfulRead = zvisionSaveMan->readSaveGameHeader(in, header);
+ delete zvisionSaveMan;
delete in;
- if (error == ZVision::ZVision::kRSHENoError) {
- SaveStateDescriptor desc(slot, header.description);
+ if (successfulRead) {
+ SaveStateDescriptor desc(slot, header.saveName);
desc.setThumbnail(header.thumbnail);
if (header.version > 0) {
- int day = (header.saveDate >> 24) & 0xFF;
- int month = (header.saveDate >> 16) & 0xFF;
- int year = header.saveDate & 0xFFFF;
+ int day = header.saveDay;
+ int month = header.saveMonth;
+ int year = header.saveYear;
desc.setSaveDate(year, month, day);
- int hour = (header.saveTime >> 16) & 0xFF;
- int minutes = (header.saveTime >> 8) & 0xFF;
+ int hour = header.saveHour;
+ int minutes = header.saveMinutes;
desc.setSaveTime(hour, minutes);
- desc.setPlayTime(header.playTime * 1000);
+ //desc.setPlayTime(header.playTime * 1000);
}
return desc;
}
}
- */
return SaveStateDescriptor();
}
diff --git a/engines/zvision/scripting/controls/save_control.cpp b/engines/zvision/scripting/controls/save_control.cpp
index ad01257e6b..d773b5fc6f 100644
--- a/engines/zvision/scripting/controls/save_control.cpp
+++ b/engines/zvision/scripting/controls/save_control.cpp
@@ -101,6 +101,8 @@ bool SaveControl::process(uint32 deltaTimeInMillis) {
toSave = false;
if (toSave) {
+ // FIXME: At this point, the screen shows the save control, so the save game thumbnails will always
+ // show the save control
_engine->getSaveManager()->saveGameBuffered(iter->saveId, inp->getText());
_engine->delayedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVED), 2000);
_engine->getScriptManager()->changeLocation(_engine->getScriptManager()->getLastMenuLocation());
diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp
index 7904817156..c532a2b15d 100644
--- a/engines/zvision/scripting/script_manager.cpp
+++ b/engines/zvision/scripting/script_manager.cpp
@@ -36,6 +36,7 @@
#include "common/hashmap.h"
#include "common/debug.h"
#include "common/stream.h"
+#include "common/config-manager.h"
namespace ZVision {
@@ -521,6 +522,28 @@ void ScriptManager::ChangeLocationReal() {
assert(_nextLocation.world != 0);
debug(1, "Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.offset);
+ if (_nextLocation.world == 'g' && _nextLocation.room == 'j' && !ConfMan.getBool("originalsaveload")) {
+ if ((_nextLocation.node == 's' || _nextLocation.node == 'r') && _nextLocation.view == 'e') {
+ // Hook up the ScummVM save/restore dialog
+ bool isSave = (_nextLocation.node == 's');
+ bool gameSavedOrLoaded = _engine->getSaveManager()->scummVMSaveLoadDialog(isSave);
+ if (!gameSavedOrLoaded || isSave) {
+ // Reload the current room
+ _nextLocation.world = _currentLocation.world;
+ _nextLocation.room = _currentLocation.room;
+ _nextLocation.node = _currentLocation.node;
+ _nextLocation.view = _currentLocation.view;
+ _nextLocation.offset = _currentLocation.offset;
+ _currentLocation.world = '0';
+ _currentLocation.room = '0';
+ _currentLocation.node = '0';
+ _currentLocation.view = '0';
+ _currentLocation.offset = 0;
+ } else
+ return;
+ }
+ }
+
_engine->setRenderDelay(2);
if (getStateValue(StateKey_World) != 'g' || getStateValue(StateKey_Room) != 'j') {
diff --git a/engines/zvision/utility/clock.h b/engines/zvision/utility/clock.h
index 9a50116a8c..cbf52be560 100644
--- a/engines/zvision/utility/clock.h
+++ b/engines/zvision/utility/clock.h
@@ -47,6 +47,7 @@ public:
* when the last update() was called.
*/
void update();
+
/**
* Get the delta time since the last frame. (The time between update() calls)
*
@@ -55,6 +56,7 @@ public:
uint32 getDeltaTime() const {
return _deltaTime;
}
+
/**
* Get the time from the program starting to the last update() call
*
@@ -69,6 +71,7 @@ public:
* Has no effect if the clock is already paused.
*/
void start();
+
/**
* Un-pause the clock.
* Has no effect if the clock is already un-paused.
diff --git a/engines/zvision/utility/utility.cpp b/engines/zvision/utility/utility.cpp
index 2388fe826e..e09545a90d 100644
--- a/engines/zvision/utility/utility.cpp
+++ b/engines/zvision/utility/utility.cpp
@@ -42,19 +42,4 @@ void trimCommentsAndWhiteSpace(Common::String *string) {
string->trim();
}
-void tryToDumpLine(const Common::String &key,
- Common::String &line,
- Common::HashMap<Common::String, byte> *count,
- Common::HashMap<Common::String, bool> *fileAlreadyUsed,
- Common::DumpFile &output) {
- const byte numberOfExamplesPerType = 8;
-
- if ((*count)[key] < numberOfExamplesPerType && !(*fileAlreadyUsed)[key]) {
- output.writeString(line);
- output.writeByte('\n');
- (*count)[key]++;
- (*fileAlreadyUsed)[key] = true;
- }
-}
-
} // End of namespace ZVision
diff --git a/engines/zvision/video/video.cpp b/engines/zvision/video/video.cpp
index 36b5f9b921..db6161bf0c 100644
--- a/engines/zvision/video/video.cpp
+++ b/engines/zvision/video/video.cpp
@@ -53,6 +53,7 @@ void ZVision::playVideo(Video::VideoDecoder &vid, const Common::Rect &destRect,
_clock.stop();
vid.start();
+ _videoIsPlaying = true;
// Only continue while the video is still playing
while (!shouldQuit() && !vid.endOfVideo() && vid.isPlaying()) {
@@ -99,6 +100,7 @@ void ZVision::playVideo(Video::VideoDecoder &vid, const Common::Rect &destRect,
_system->delayMillis(vid.getTimeToNextFrame() / 2);
}
+ _videoIsPlaying = false;
_clock.start();
if (scaled) {
diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index af9d26a350..8a44ccebea 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -96,7 +96,8 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc)
_audioId(0),
_rendDelay(2),
_kbdVelocity(0),
- _mouseVelocity(0) {
+ _mouseVelocity(0),
+ _videoIsPlaying(false) {
debug(1, "ZVision::ZVision");
@@ -205,6 +206,10 @@ void ZVision::initialize() {
Common::Error ZVision::run() {
initialize();
+ // Check if a saved game is to be loaded from the launcher
+ if (ConfMan.hasKey("save_slot"))
+ _saveManager->loadGame(ConfMan.getInt("save_slot"));
+
// Main loop
while (!shouldQuit()) {
_clock.update();
@@ -327,7 +332,7 @@ void ZVision::pauseEngineIntern(bool pause) {
}
Common::String ZVision::generateSaveFileName(uint slot) {
- return Common::String::format("%s.%02u", _targetName.c_str(), slot);
+ return Common::String::format("%s.%03u", _targetName.c_str(), slot);
}
Common::String ZVision::generateAutoSaveFileName() {
diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h
index ca6c8e10e4..5850bf66cd 100644
--- a/engines/zvision/zvision.h
+++ b/engines/zvision/zvision.h
@@ -124,6 +124,7 @@ private:
int16 _mouseVelocity;
int16 _kbdVelocity;
bool _halveDelay;
+ bool _videoIsPlaying;
uint8 _cheatBuff[KEYBUF_SIZE];
public:
@@ -198,6 +199,13 @@ public:
void checkBorders();
void showDebugMsg(const Common::String &msg, int16 delay = 3000);
+
+ // Engine features
+ bool hasFeature(EngineFeature f) const;
+ bool canLoadGameStateCurrently();
+ bool canSaveGameStateCurrently();
+ Common::Error loadGameState(int slot);
+ Common::Error saveGameState(int slot, const Common::String &desc);
private:
void initialize();
void initFonts();