2009-12-29 23:18:24 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2009-12-29 23:18:24 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2009-12-29 23:18:24 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-12-07 01:58:18 +00:00
|
|
|
#include "mohawk/cursors.h"
|
2009-12-29 23:18:24 +00:00
|
|
|
#include "mohawk/myst.h"
|
2010-12-26 15:10:33 +00:00
|
|
|
#include "mohawk/myst_state.h"
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2019-10-30 05:51:22 +01:00
|
|
|
#include "common/config-manager.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/debug.h"
|
2010-12-06 21:10:12 +00:00
|
|
|
#include "common/serializer.h"
|
2016-02-22 08:31:02 +01:00
|
|
|
#include "common/system.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/textconsole.h"
|
2009-12-29 23:18:24 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
|
2016-02-22 08:31:02 +01:00
|
|
|
#include "graphics/thumbnail.h"
|
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
namespace Mohawk {
|
|
|
|
|
2016-02-22 08:31:02 +01:00
|
|
|
MystSaveMetadata::MystSaveMetadata() {
|
|
|
|
saveDay = 0;
|
|
|
|
saveMonth = 0;
|
|
|
|
saveYear = 0;
|
|
|
|
saveHour = 0;
|
|
|
|
saveMinute = 0;
|
|
|
|
totalPlayTime = 0;
|
2018-04-28 06:58:12 -07:00
|
|
|
autoSave = false;
|
2016-02-22 08:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MystSaveMetadata::sync(Common::Serializer &s) {
|
2018-04-28 06:58:12 -07:00
|
|
|
static const Common::Serializer::Version kCurrentVersion = 2;
|
2016-02-22 08:31:02 +01:00
|
|
|
|
|
|
|
if (!s.syncVersion(kCurrentVersion)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
s.syncAsByte(saveDay);
|
|
|
|
s.syncAsByte(saveMonth);
|
|
|
|
s.syncAsUint16LE(saveYear);
|
|
|
|
s.syncAsByte(saveHour);
|
|
|
|
s.syncAsByte(saveMinute);
|
|
|
|
s.syncString(saveDescription);
|
|
|
|
s.syncAsUint32LE(totalPlayTime);
|
2018-04-28 06:58:12 -07:00
|
|
|
s.syncAsByte(autoSave, 2);
|
2016-02-22 08:31:02 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-19 18:23:45 +02:00
|
|
|
const int MystGameState::kAutoSaveSlot = 0;
|
|
|
|
|
2018-04-29 19:22:50 +02:00
|
|
|
MystGameState::MystGameState(MohawkEngine_Myst *vm, Common::SaveFileManager *saveFileMan) :
|
|
|
|
_vm(vm),
|
|
|
|
_saveFileMan(saveFileMan) {
|
|
|
|
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MystGameState::reset() {
|
2010-12-06 21:10:12 +00:00
|
|
|
// Most of the variables are zero at game start.
|
2010-12-26 14:31:03 +00:00
|
|
|
memset(&_globals, 0, sizeof(_globals));
|
|
|
|
memset(&_myst, 0, sizeof(_myst));
|
|
|
|
memset(&_channelwood, 0, sizeof(_channelwood));
|
|
|
|
memset(&_mechanical, 0, sizeof(_mechanical));
|
|
|
|
memset(&_selenitic, 0, sizeof(_selenitic));
|
|
|
|
memset(&_stoneship, 0, sizeof(_stoneship));
|
2011-01-09 15:31:08 +00:00
|
|
|
memset(&_mystReachableZipDests, 0, sizeof(_mystReachableZipDests));
|
|
|
|
memset(&_channelwoodReachableZipDests, 0, sizeof(_channelwoodReachableZipDests));
|
|
|
|
memset(&_mechReachableZipDests, 0, sizeof(_mechReachableZipDests));
|
|
|
|
memset(&_seleniticReachableZipDests, 0, sizeof(_seleniticReachableZipDests));
|
|
|
|
memset(&_stoneshipReachableZipDests, 0, sizeof(_stoneshipReachableZipDests));
|
2010-12-26 14:31:03 +00:00
|
|
|
|
|
|
|
// Unknown
|
|
|
|
_globals.u0 = 2;
|
2010-12-06 21:10:12 +00:00
|
|
|
// Current Age / Stack - Start in Myst
|
2018-04-25 16:03:21 -07:00
|
|
|
_globals.currentAge = kMystStart;
|
2018-04-26 14:27:59 -07:00
|
|
|
_globals.heldPage = kNoPage;
|
2010-12-26 14:31:03 +00:00
|
|
|
_globals.u1 = 1;
|
2018-04-26 14:27:59 -07:00
|
|
|
_globals.ending = kDniNotVisited;
|
2010-12-06 21:10:12 +00:00
|
|
|
|
|
|
|
// Library Bookcase Door - Default to Up
|
2010-12-26 14:31:03 +00:00
|
|
|
_myst.libraryBookcaseDoor = 1;
|
2010-12-06 21:10:12 +00:00
|
|
|
// Dock Imager Numeric Selection - Default to 67
|
2010-12-26 14:31:03 +00:00
|
|
|
_myst.imagerSelection = 67;
|
2010-12-06 21:10:12 +00:00
|
|
|
// Dock Imager Active - Default to Active
|
2010-12-26 14:31:03 +00:00
|
|
|
_myst.imagerActive = 1;
|
2010-12-06 21:10:12 +00:00
|
|
|
// Stellar Observatory Lights - Default to On
|
2010-12-26 14:31:03 +00:00
|
|
|
_myst.observatoryLights = 1;
|
2010-12-30 13:53:14 +00:00
|
|
|
// First day of month
|
|
|
|
_myst.observatoryDaySetting = 1;
|
2010-12-29 19:33:49 +00:00
|
|
|
// Stellar Observatory sliders
|
|
|
|
_myst.observatoryDaySlider = 90;
|
|
|
|
_myst.observatoryMonthSlider = 90;
|
|
|
|
_myst.observatoryYearSlider = 90;
|
|
|
|
_myst.observatoryTimeSlider = 90;
|
2010-12-06 21:10:12 +00:00
|
|
|
|
|
|
|
// Lighthouse Trapdoor State - Default to Locked
|
2010-12-26 14:31:03 +00:00
|
|
|
_stoneship.trapdoorState = 2;
|
2010-12-06 21:10:12 +00:00
|
|
|
// Lighthouse Chest Water State - Default to Full
|
2010-12-26 14:31:03 +00:00
|
|
|
_stoneship.chestWaterState = 1;
|
2009-12-29 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-26 14:31:03 +00:00
|
|
|
MystGameState::~MystGameState() {
|
2009-12-29 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
bool MystGameState::load(int slot) {
|
|
|
|
if (!loadState(slot)) {
|
2009-12-29 23:18:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
loadMetadata(slot);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2014-07-08 19:57:55 +02:00
|
|
|
// Set Channelwood elevator state to down, because we start on the lower level
|
|
|
|
_channelwood.elevatorState = 0;
|
|
|
|
|
2011-05-15 17:38:47 +02:00
|
|
|
// Switch us back to the intro stack, to the linking book
|
|
|
|
_vm->changeToStack(kIntroStack, 5, 0, 0);
|
|
|
|
|
2010-12-07 01:58:18 +00:00
|
|
|
// Set our default cursor
|
2016-07-24 14:14:50 +02:00
|
|
|
_vm->_cursor->showCursor();
|
2018-04-25 12:46:50 -04:00
|
|
|
if (_globals.heldPage == kNoPage)
|
2010-12-11 16:55:25 +00:00
|
|
|
_vm->setMainCursor(kDefaultMystCursor);
|
2018-04-25 12:46:50 -04:00
|
|
|
else if (_globals.heldPage < kRedLibraryPage) //A blue page is held
|
2010-12-07 01:58:18 +00:00
|
|
|
_vm->setMainCursor(kBluePageCursor);
|
2018-04-25 12:46:50 -04:00
|
|
|
else if (_globals.heldPage < kWhitePage) //A red page is held
|
2010-12-07 01:58:18 +00:00
|
|
|
_vm->setMainCursor(kRedPageCursor);
|
2018-04-25 12:46:50 -04:00
|
|
|
else
|
2010-12-07 01:58:18 +00:00
|
|
|
_vm->setMainCursor(kWhitePageCursor);
|
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
bool MystGameState::loadState(int slot) {
|
|
|
|
Common::String filename = buildSaveFilename(slot);
|
2016-02-22 08:31:02 +01:00
|
|
|
Common::InSaveFile *loadFile = _saveFileMan->openForLoading(filename);
|
|
|
|
if (!loadFile) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(kDebugSaveLoad, "Loading game from '%s'", filename.c_str());
|
|
|
|
|
|
|
|
// First, let's make sure we're using a saved game file from this version of Myst
|
|
|
|
// By checking length of file...
|
|
|
|
int32 size = loadFile->size();
|
|
|
|
if (size != 664 && size != 601) {
|
|
|
|
warning("Incompatible saved game version");
|
|
|
|
delete loadFile;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Serializer s(loadFile, nullptr);
|
|
|
|
syncGameState(s, size == 664);
|
|
|
|
delete loadFile;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
void MystGameState::loadMetadata(int slot) {
|
2016-02-22 08:31:02 +01:00
|
|
|
// Open the metadata file
|
2016-04-03 07:48:50 +02:00
|
|
|
Common::String filename = buildMetadataFilename(slot);
|
|
|
|
Common::InSaveFile *metadataFile = _vm->getSaveFileManager()->openForLoading(filename);
|
2016-02-22 08:31:02 +01:00
|
|
|
if (!metadataFile) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(kDebugSaveLoad, "Loading metadata from '%s'", filename.c_str());
|
|
|
|
|
|
|
|
Common::Serializer m(metadataFile, nullptr);
|
|
|
|
|
|
|
|
// Read the metadata file
|
|
|
|
if (_metadata.sync(m)) {
|
|
|
|
_vm->setTotalPlayTime(_metadata.totalPlayTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete metadataFile;
|
|
|
|
}
|
|
|
|
|
2018-04-29 19:22:50 +02:00
|
|
|
bool MystGameState::save(int slot, const Common::String &desc, const Graphics::Surface *thumbnail, bool autoSave) {
|
2016-04-03 07:48:50 +02:00
|
|
|
if (!saveState(slot)) {
|
2016-02-22 08:31:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-28 06:58:12 -07:00
|
|
|
updateMetadateForSaving(desc, autoSave);
|
2016-02-22 08:31:02 +01:00
|
|
|
|
2018-04-29 19:22:50 +02:00
|
|
|
return saveMetadata(slot, thumbnail);
|
2016-02-22 08:31:02 +01:00
|
|
|
}
|
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
bool MystGameState::saveState(int slot) {
|
2016-02-22 08:31:02 +01:00
|
|
|
// Make sure we have the right extension
|
2016-04-03 07:48:50 +02:00
|
|
|
Common::String filename = buildSaveFilename(slot);
|
2010-12-06 21:10:12 +00:00
|
|
|
Common::OutSaveFile *saveFile = _saveFileMan->openForSaving(filename);
|
2016-02-22 08:31:02 +01:00
|
|
|
if (!saveFile) {
|
2010-12-06 21:10:12 +00:00
|
|
|
return false;
|
2016-02-22 08:31:02 +01:00
|
|
|
}
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
debugC(kDebugSaveLoad, "Saving game to '%s'", filename.c_str());
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2016-02-06 11:27:51 +01:00
|
|
|
Common::Serializer s(nullptr, saveFile);
|
2010-12-07 18:33:58 +00:00
|
|
|
syncGameState(s, _vm->getFeatures() & GF_ME);
|
2010-12-06 21:10:12 +00:00
|
|
|
saveFile->finalize();
|
|
|
|
delete saveFile;
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
Common::String MystGameState::buildSaveFilename(int slot) {
|
|
|
|
return Common::String::format("myst-%03d.mys", slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String MystGameState::buildMetadataFilename(int slot) {
|
|
|
|
return Common::String::format("myst-%03d.mym", slot);
|
|
|
|
}
|
|
|
|
|
2018-04-28 06:58:12 -07:00
|
|
|
void MystGameState::updateMetadateForSaving(const Common::String &desc, bool autoSave) {
|
2016-02-22 08:31:02 +01:00
|
|
|
// Update save creation info
|
|
|
|
TimeDate t;
|
|
|
|
g_system->getTimeAndDate(t);
|
|
|
|
_metadata.saveYear = t.tm_year + 1900;
|
|
|
|
_metadata.saveMonth = t.tm_mon + 1;
|
|
|
|
_metadata.saveDay = t.tm_mday;
|
|
|
|
_metadata.saveHour = t.tm_hour;
|
|
|
|
_metadata.saveMinute = t.tm_min;
|
|
|
|
_metadata.saveDescription = desc;
|
|
|
|
_metadata.totalPlayTime = _vm->getTotalPlayTime();
|
2018-04-28 06:58:12 -07:00
|
|
|
_metadata.autoSave = autoSave;
|
2016-02-22 08:31:02 +01:00
|
|
|
}
|
|
|
|
|
2018-04-29 19:22:50 +02:00
|
|
|
bool MystGameState::saveMetadata(int slot, const Graphics::Surface *thumbnail) {
|
2016-02-22 08:31:02 +01:00
|
|
|
// Write the metadata to a separate file so that the save files
|
|
|
|
// are still compatible with the original engine
|
2016-04-03 07:48:50 +02:00
|
|
|
Common::String metadataFilename = buildMetadataFilename(slot);
|
2016-02-22 08:31:02 +01:00
|
|
|
Common::OutSaveFile *metadataFile = _saveFileMan->openForSaving(metadataFilename);
|
|
|
|
if (!metadataFile) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the metadata
|
|
|
|
Common::Serializer m(nullptr, metadataFile);
|
|
|
|
_metadata.sync(m);
|
|
|
|
|
|
|
|
// Append a thumbnail
|
2018-04-29 19:22:50 +02:00
|
|
|
if (thumbnail) {
|
|
|
|
Graphics::saveThumbnail(*metadataFile, *thumbnail);
|
|
|
|
} else {
|
|
|
|
Graphics::saveThumbnail(*metadataFile);
|
|
|
|
}
|
2016-02-22 08:31:02 +01:00
|
|
|
|
|
|
|
metadataFile->finalize();
|
|
|
|
delete metadataFile;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:09:43 +01:00
|
|
|
SaveStateDescriptor MystGameState::querySaveMetaInfos(int slot) {
|
|
|
|
SaveStateDescriptor desc;
|
|
|
|
desc.setWriteProtectedFlag(slot == kAutoSaveSlot);
|
2018-04-28 06:58:12 -07:00
|
|
|
|
2020-02-17 19:09:43 +01:00
|
|
|
// Open the save file
|
|
|
|
Common::String filename = buildSaveFilename(slot);
|
|
|
|
Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(filename);
|
|
|
|
if (!saveFile) {
|
|
|
|
return desc;
|
2018-04-28 06:58:12 -07:00
|
|
|
}
|
2020-02-17 19:09:43 +01:00
|
|
|
delete saveFile;
|
2018-04-28 06:58:12 -07:00
|
|
|
|
2020-02-17 19:09:43 +01:00
|
|
|
// There is a save in the slot
|
|
|
|
desc.setSaveSlot(slot);
|
2018-04-28 06:58:12 -07:00
|
|
|
|
2016-02-22 08:31:02 +01:00
|
|
|
// Open the metadata file
|
2020-02-17 19:09:43 +01:00
|
|
|
filename = buildMetadataFilename(slot);
|
2016-04-03 07:48:50 +02:00
|
|
|
Common::InSaveFile *metadataFile = g_system->getSavefileManager()->openForLoading(filename);
|
2016-02-22 08:31:02 +01:00
|
|
|
if (!metadataFile) {
|
2018-04-28 06:58:12 -07:00
|
|
|
return desc;
|
2016-02-22 08:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Serializer m(metadataFile, nullptr);
|
|
|
|
|
|
|
|
// Read the metadata file
|
|
|
|
Mohawk::MystSaveMetadata metadata;
|
|
|
|
if (!metadata.sync(m)) {
|
|
|
|
delete metadataFile;
|
2018-04-28 06:58:12 -07:00
|
|
|
return desc;
|
2016-02-22 08:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the save description
|
|
|
|
desc.setDescription(metadata.saveDescription);
|
|
|
|
desc.setSaveDate(metadata.saveYear, metadata.saveMonth, metadata.saveDay);
|
|
|
|
desc.setSaveTime(metadata.saveHour, metadata.saveMinute);
|
|
|
|
desc.setPlayTime(metadata.totalPlayTime);
|
2020-02-11 21:55:33 -08:00
|
|
|
desc.setAutosave(metadata.autoSave);
|
2018-05-21 18:24:47 -07:00
|
|
|
if (metadata.autoSave) // Allow non-saves to be deleted, but not autosaves
|
|
|
|
desc.setDeletableFlag(slot != kAutoSaveSlot);
|
2018-04-28 06:58:12 -07:00
|
|
|
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-06 00:06:38 +02:00
|
|
|
Graphics::Surface *thumbnail;
|
|
|
|
if (!Graphics::loadThumbnail(*metadataFile, thumbnail)) {
|
|
|
|
delete metadataFile;
|
2018-04-28 06:58:12 -07:00
|
|
|
return desc;
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-06 00:06:38 +02:00
|
|
|
}
|
|
|
|
desc.setThumbnail(thumbnail);
|
2016-02-22 08:31:02 +01:00
|
|
|
|
|
|
|
delete metadataFile;
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
Common::String MystGameState::querySaveDescription(int slot) {
|
2016-02-22 08:31:02 +01:00
|
|
|
// Open the metadata file
|
2016-04-03 07:48:50 +02:00
|
|
|
Common::String filename = buildMetadataFilename(slot);
|
|
|
|
Common::InSaveFile *metadataFile = g_system->getSavefileManager()->openForLoading(filename);
|
|
|
|
if (!metadataFile) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Serializer m(metadataFile, nullptr);
|
2016-02-22 08:31:02 +01:00
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
// Read the metadata file
|
|
|
|
Mohawk::MystSaveMetadata metadata;
|
|
|
|
if (!metadata.sync(m)) {
|
|
|
|
delete metadataFile;
|
|
|
|
return "";
|
2016-02-22 08:31:02 +01:00
|
|
|
}
|
2016-04-03 07:48:50 +02:00
|
|
|
|
|
|
|
delete metadataFile;
|
|
|
|
|
|
|
|
return metadata.saveDescription;
|
2016-02-22 08:31:02 +01:00
|
|
|
}
|
|
|
|
|
2010-12-26 14:31:03 +00:00
|
|
|
void MystGameState::syncGameState(Common::Serializer &s, bool isME) {
|
2010-12-06 21:10:12 +00:00
|
|
|
// Globals first
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_globals.u0);
|
|
|
|
s.syncAsUint16LE(_globals.currentAge);
|
|
|
|
s.syncAsUint16LE(_globals.heldPage);
|
|
|
|
s.syncAsUint16LE(_globals.u1);
|
|
|
|
s.syncAsUint16LE(_globals.transitions);
|
2011-01-09 10:14:40 +00:00
|
|
|
s.syncAsUint16LE(_globals.zipMode);
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_globals.redPagesInBook);
|
|
|
|
s.syncAsUint16LE(_globals.bluePagesInBook);
|
2010-12-06 21:10:12 +00:00
|
|
|
|
|
|
|
// Onto Myst
|
2010-12-07 18:33:58 +00:00
|
|
|
if (isME) {
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint32LE(_myst.cabinMarkerSwitch);
|
|
|
|
s.syncAsUint32LE(_myst.clockTowerMarkerSwitch);
|
|
|
|
s.syncAsUint32LE(_myst.dockMarkerSwitch);
|
|
|
|
s.syncAsUint32LE(_myst.poolMarkerSwitch);
|
|
|
|
s.syncAsUint32LE(_myst.gearsMarkerSwitch);
|
|
|
|
s.syncAsUint32LE(_myst.generatorMarkerSwitch);
|
|
|
|
s.syncAsUint32LE(_myst.observatoryMarkerSwitch);
|
|
|
|
s.syncAsUint32LE(_myst.rocketshipMarkerSwitch);
|
2010-12-04 09:26:44 +00:00
|
|
|
} else {
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsByte(_myst.cabinMarkerSwitch);
|
|
|
|
s.syncAsByte(_myst.clockTowerMarkerSwitch);
|
|
|
|
s.syncAsByte(_myst.dockMarkerSwitch);
|
|
|
|
s.syncAsByte(_myst.poolMarkerSwitch);
|
|
|
|
s.syncAsByte(_myst.gearsMarkerSwitch);
|
|
|
|
s.syncAsByte(_myst.generatorMarkerSwitch);
|
|
|
|
s.syncAsByte(_myst.observatoryMarkerSwitch);
|
|
|
|
s.syncAsByte(_myst.rocketshipMarkerSwitch);
|
2009-12-29 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_myst.greenBookOpenedBefore);
|
|
|
|
s.syncAsUint16LE(_myst.shipFloating);
|
|
|
|
s.syncAsUint16LE(_myst.cabinValvePosition);
|
|
|
|
s.syncAsUint16LE(_myst.clockTowerHourPosition);
|
|
|
|
s.syncAsUint16LE(_myst.clockTowerMinutePosition);
|
|
|
|
s.syncAsUint16LE(_myst.gearsOpen);
|
|
|
|
s.syncAsUint16LE(_myst.clockTowerBridgeOpen);
|
|
|
|
s.syncAsUint16LE(_myst.generatorBreakers);
|
|
|
|
s.syncAsUint16LE(_myst.generatorButtons);
|
|
|
|
s.syncAsUint16LE(_myst.generatorVoltage);
|
|
|
|
s.syncAsUint16LE(_myst.libraryBookcaseDoor);
|
|
|
|
s.syncAsUint16LE(_myst.imagerSelection);
|
|
|
|
s.syncAsUint16LE(_myst.imagerActive);
|
|
|
|
s.syncAsUint16LE(_myst.imagerWaterErased);
|
|
|
|
s.syncAsUint16LE(_myst.imagerMountainErased);
|
|
|
|
s.syncAsUint16LE(_myst.imagerAtrusErased);
|
|
|
|
s.syncAsUint16LE(_myst.imagerMarkerErased);
|
|
|
|
s.syncAsUint16LE(_myst.towerRotationAngle);
|
|
|
|
s.syncAsUint16LE(_myst.courtyardImageBoxes);
|
|
|
|
s.syncAsUint16LE(_myst.cabinPilotLightLit);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryDaySetting);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryLights);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryMonthSetting);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryTimeSetting);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryYearSetting);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryDayTarget);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryMonthTarget);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryTimeTarget);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryYearTarget);
|
|
|
|
s.syncAsUint16LE(_myst.cabinSafeCombination);
|
|
|
|
s.syncAsUint16LE(_myst.treePosition);
|
|
|
|
s.syncAsUint32LE(_myst.treeLastMoveTime);
|
2010-12-06 21:10:12 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_myst.rocketSliderPosition[i]);
|
2010-12-06 21:10:12 +00:00
|
|
|
|
2010-12-29 19:33:49 +00:00
|
|
|
s.syncAsUint16LE(_myst.observatoryDaySlider);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryMonthSlider);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryYearSlider);
|
|
|
|
s.syncAsUint16LE(_myst.observatoryTimeSlider);
|
2010-12-06 21:10:12 +00:00
|
|
|
|
|
|
|
// Channelwood
|
2010-12-07 18:33:58 +00:00
|
|
|
if (isME) {
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint32LE(_channelwood.waterPumpBridgeState);
|
|
|
|
s.syncAsUint32LE(_channelwood.elevatorState);
|
|
|
|
s.syncAsUint32LE(_channelwood.stairsLowerDoorState);
|
|
|
|
s.syncAsUint32LE(_channelwood.pipeState);
|
2010-12-06 21:10:12 +00:00
|
|
|
} else {
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsByte(_channelwood.waterPumpBridgeState);
|
|
|
|
s.syncAsByte(_channelwood.elevatorState);
|
|
|
|
s.syncAsByte(_channelwood.stairsLowerDoorState);
|
|
|
|
s.syncAsByte(_channelwood.pipeState);
|
2009-12-29 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_channelwood.waterValveStates);
|
|
|
|
s.syncAsUint16LE(_channelwood.holoprojectorSelection);
|
|
|
|
s.syncAsUint16LE(_channelwood.stairsUpperDoorState);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2011-02-13 12:15:37 +01:00
|
|
|
// Mechanical
|
|
|
|
|
2010-12-07 18:33:58 +00:00
|
|
|
if (isME)
|
2011-02-13 12:15:37 +01:00
|
|
|
s.syncAsUint32LE(_mechanical.achenarCrateOpened);
|
2010-12-06 21:10:12 +00:00
|
|
|
else
|
2011-02-13 12:15:37 +01:00
|
|
|
s.syncAsByte(_mechanical.achenarCrateOpened);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_mechanical.achenarPanelState);
|
|
|
|
s.syncAsUint16LE(_mechanical.sirrusPanelState);
|
|
|
|
s.syncAsUint16LE(_mechanical.staircaseState);
|
|
|
|
s.syncAsUint16LE(_mechanical.elevatorRotation);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_mechanical.codeShape[i]);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
// Selenitic
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-07 18:33:58 +00:00
|
|
|
if (isME) {
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint32LE(_selenitic.emitterEnabledWater);
|
|
|
|
s.syncAsUint32LE(_selenitic.emitterEnabledVolcano);
|
|
|
|
s.syncAsUint32LE(_selenitic.emitterEnabledClock);
|
|
|
|
s.syncAsUint32LE(_selenitic.emitterEnabledCrystal);
|
|
|
|
s.syncAsUint32LE(_selenitic.emitterEnabledWind);
|
|
|
|
s.syncAsUint32LE(_selenitic.soundReceiverOpened);
|
|
|
|
s.syncAsUint32LE(_selenitic.tunnelLightsSwitchedOn);
|
2009-12-29 23:18:24 +00:00
|
|
|
} else {
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsByte(_selenitic.emitterEnabledWater);
|
|
|
|
s.syncAsByte(_selenitic.emitterEnabledVolcano);
|
|
|
|
s.syncAsByte(_selenitic.emitterEnabledClock);
|
|
|
|
s.syncAsByte(_selenitic.emitterEnabledCrystal);
|
|
|
|
s.syncAsByte(_selenitic.emitterEnabledWind);
|
|
|
|
s.syncAsByte(_selenitic.soundReceiverOpened);
|
|
|
|
s.syncAsByte(_selenitic.tunnelLightsSwitchedOn);
|
2009-12-29 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_selenitic.soundReceiverCurrentSource);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
for (byte i = 0; i < 5; i++)
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_selenitic.soundReceiverPositions[i]);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
for (byte i = 0; i < 5; i++)
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_selenitic.soundLockSliderPositions[i]);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
// Stoneship
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-07 18:33:58 +00:00
|
|
|
if (isME) {
|
2011-01-27 21:13:34 +00:00
|
|
|
s.syncAsUint32LE(_stoneship.lightState);
|
2010-12-04 09:26:44 +00:00
|
|
|
} else {
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsByte(_stoneship.lightState);
|
2009-12-29 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2011-01-27 21:13:34 +00:00
|
|
|
s.syncAsUint16LE(_stoneship.sideDoorOpened);
|
2010-12-26 14:31:03 +00:00
|
|
|
s.syncAsUint16LE(_stoneship.pumpState);
|
|
|
|
s.syncAsUint16LE(_stoneship.trapdoorState);
|
|
|
|
s.syncAsUint16LE(_stoneship.chestWaterState);
|
|
|
|
s.syncAsUint16LE(_stoneship.chestValveState);
|
|
|
|
s.syncAsUint16LE(_stoneship.chestOpenState);
|
|
|
|
s.syncAsUint16LE(_stoneship.trapdoorKeyState);
|
2011-01-27 21:13:34 +00:00
|
|
|
s.syncAsUint32LE(_stoneship.generatorDuration);
|
|
|
|
s.syncAsUint16LE(_stoneship.generatorPowerAvailable);
|
|
|
|
s.syncAsUint32LE(_stoneship.generatorDepletionTime);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-06 21:10:12 +00:00
|
|
|
// D'ni
|
2011-01-09 10:14:40 +00:00
|
|
|
s.syncAsUint16LE(_globals.ending);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2011-01-09 16:13:31 +00:00
|
|
|
// Already visited zip destinations
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2011-01-09 10:14:40 +00:00
|
|
|
for (byte i = 0; i < 41; i++)
|
2011-01-09 15:31:08 +00:00
|
|
|
s.syncAsUint16LE(_mystReachableZipDests[i]);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2011-01-09 10:14:40 +00:00
|
|
|
for (byte i = 0; i < 41; i++)
|
2011-01-09 15:31:08 +00:00
|
|
|
s.syncAsUint16LE(_channelwoodReachableZipDests[i]);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2011-01-09 10:14:40 +00:00
|
|
|
for (byte i = 0; i < 41; i++)
|
2011-01-09 15:31:08 +00:00
|
|
|
s.syncAsUint16LE(_mechReachableZipDests[i]);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2011-01-09 10:14:40 +00:00
|
|
|
for (byte i = 0; i < 41; i++)
|
2011-01-09 15:31:08 +00:00
|
|
|
s.syncAsUint16LE(_seleniticReachableZipDests[i]);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2011-01-09 10:14:40 +00:00
|
|
|
for (byte i = 0; i < 41; i++)
|
2011-01-09 15:31:08 +00:00
|
|
|
s.syncAsUint16LE(_stoneshipReachableZipDests[i]);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-12-07 18:33:58 +00:00
|
|
|
if ((isME && s.bytesSynced() != 664) || (!isME && s.bytesSynced() != 601))
|
2010-12-06 21:10:12 +00:00
|
|
|
warning("Unexpected File Position 0x%03X At End of Save/Load", s.bytesSynced());
|
2009-12-29 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
void MystGameState::deleteSave(int slot) {
|
|
|
|
Common::String filename = buildSaveFilename(slot);
|
|
|
|
Common::String metadataFilename = buildMetadataFilename(slot);
|
|
|
|
|
|
|
|
debugC(kDebugSaveLoad, "Deleting save file \'%s\'", filename.c_str());
|
2016-02-22 08:31:02 +01:00
|
|
|
|
2016-04-03 07:48:50 +02:00
|
|
|
g_system->getSavefileManager()->removeSavefile(filename);
|
|
|
|
g_system->getSavefileManager()->removeSavefile(metadataFilename);
|
2009-12-29 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 20:22:29 +02:00
|
|
|
void MystGameState::addZipDest(MystStack stack, uint16 view) {
|
2016-02-06 11:27:51 +01:00
|
|
|
ZipDests *zipDests = nullptr;
|
2011-01-09 15:31:08 +00:00
|
|
|
|
2011-08-07 11:27:50 +02:00
|
|
|
// The demo has no zip dest storage
|
|
|
|
if (_vm->getFeatures() & GF_DEMO)
|
|
|
|
return;
|
|
|
|
|
2011-01-09 15:31:08 +00:00
|
|
|
// Select stack
|
|
|
|
switch (stack) {
|
|
|
|
case kChannelwoodStack:
|
|
|
|
zipDests = &_channelwoodReachableZipDests;
|
|
|
|
break;
|
|
|
|
case kMechanicalStack:
|
|
|
|
zipDests = &_mechReachableZipDests;
|
|
|
|
break;
|
|
|
|
case kMystStack:
|
|
|
|
zipDests = &_mystReachableZipDests;
|
|
|
|
break;
|
|
|
|
case kSeleniticStack:
|
|
|
|
zipDests = &_seleniticReachableZipDests;
|
|
|
|
break;
|
|
|
|
case kStoneshipStack:
|
|
|
|
zipDests = &_stoneshipReachableZipDests;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Stack does not have zip destination storage");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if not already in list
|
|
|
|
int16 firstEmpty = -1;
|
|
|
|
bool found = false;
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(*zipDests); i++) {
|
|
|
|
if (firstEmpty == -1 && (*zipDests)[i] == 0)
|
|
|
|
firstEmpty = i;
|
|
|
|
|
|
|
|
if ((*zipDests)[i] == view)
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add view to array
|
|
|
|
if (!found && firstEmpty >= 0)
|
|
|
|
(*zipDests)[firstEmpty] = view;
|
|
|
|
}
|
|
|
|
|
2018-05-28 20:22:29 +02:00
|
|
|
bool MystGameState::isReachableZipDest(MystStack stack, uint16 view) {
|
2011-01-09 15:31:08 +00:00
|
|
|
// Zip mode enabled
|
2020-03-22 15:19:56 +01:00
|
|
|
if (!ConfMan.getBool("zip_mode"))
|
2011-01-09 15:31:08 +00:00
|
|
|
return false;
|
|
|
|
|
2011-08-07 11:27:50 +02:00
|
|
|
// The demo has no zip dest storage
|
|
|
|
if (_vm->getFeatures() & GF_DEMO)
|
|
|
|
return false;
|
|
|
|
|
2011-01-09 15:31:08 +00:00
|
|
|
// Select stack
|
|
|
|
ZipDests *zipDests;
|
|
|
|
switch (stack) {
|
|
|
|
case kChannelwoodStack:
|
|
|
|
zipDests = &_channelwoodReachableZipDests;
|
|
|
|
break;
|
|
|
|
case kMechanicalStack:
|
|
|
|
zipDests = &_mechReachableZipDests;
|
|
|
|
break;
|
|
|
|
case kMystStack:
|
|
|
|
zipDests = &_mystReachableZipDests;
|
|
|
|
break;
|
|
|
|
case kSeleniticStack:
|
|
|
|
zipDests = &_seleniticReachableZipDests;
|
|
|
|
break;
|
|
|
|
case kStoneshipStack:
|
|
|
|
zipDests = &_stoneshipReachableZipDests;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Stack does not have zip destination storage");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if in list
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(*zipDests); i++) {
|
|
|
|
if ((*zipDests)[i] == view)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
} // End of namespace Mohawk
|