2014-10-06 14:50:05 +02: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on Labyrinth of Time code with assistance of
|
|
|
|
*
|
|
|
|
* Copyright (c) 1993 Terra Nova Development
|
|
|
|
* Copyright (c) 2004 The Wyrmkeep Entertainment Co.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
#include "graphics/thumbnail.h"
|
|
|
|
|
2014-12-25 19:13:52 +01:00
|
|
|
#include "lab/lab.h"
|
2015-12-08 20:53:44 +01:00
|
|
|
#include "lab/savegame.h"
|
2014-10-06 14:50:05 +02:00
|
|
|
|
|
|
|
namespace Lab {
|
2015-02-19 15:41:15 +02:00
|
|
|
#define SAVEGAME_ID MKTAG('L', 'O', 'T', 'S')
|
|
|
|
#define SAVEGAME_VERSION 1
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
void writeSaveGameHeader(Common::OutSaveFile *out, const Common::String &saveName) {
|
|
|
|
out->writeUint32BE(SAVEGAME_ID);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Write version
|
|
|
|
out->writeByte(SAVEGAME_VERSION);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Write savegame name
|
|
|
|
out->writeString(saveName);
|
|
|
|
out->writeByte(0);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Save the game thumbnail
|
|
|
|
Graphics::saveThumbnail(*out);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Creation date/time
|
|
|
|
TimeDate curTime;
|
|
|
|
g_system->getTimeAndDate(curTime);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
|
|
|
|
uint16 saveTime = ((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF);
|
|
|
|
uint32 playTime = g_engine->getTotalPlayTime() / 1000;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
out->writeUint32BE(saveDate);
|
|
|
|
out->writeUint16BE(saveTime);
|
|
|
|
out->writeUint32BE(playTime);
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header) {
|
|
|
|
uint32 id = in->readUint32BE();
|
2015-12-03 11:01:50 +01:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Check if it's a valid ScummVM savegame
|
|
|
|
if (id != SAVEGAME_ID)
|
|
|
|
return false;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Read in the version
|
2015-12-03 01:06:04 +01:00
|
|
|
header._version = in->readByte();
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Check that the save version isn't newer than this binary
|
2015-12-03 01:06:04 +01:00
|
|
|
if (header._version > SAVEGAME_VERSION)
|
2015-02-19 15:41:15 +02:00
|
|
|
return false;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Read in the save name
|
|
|
|
Common::String saveName;
|
|
|
|
char ch;
|
|
|
|
while ((ch = (char)in->readByte()) != '\0')
|
|
|
|
saveName += ch;
|
2015-12-03 01:06:04 +01:00
|
|
|
header._descr.setDescription(saveName);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Get the thumbnail
|
2015-12-03 01:06:04 +01:00
|
|
|
header._descr.setThumbnail(Graphics::loadThumbnail(*in));
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
uint32 saveDate = in->readUint32BE();
|
|
|
|
uint16 saveTime = in->readUint16BE();
|
|
|
|
uint32 playTime = in->readUint32BE();
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
int day = (saveDate >> 24) & 0xFF;
|
|
|
|
int month = (saveDate >> 16) & 0xFF;
|
|
|
|
int year = saveDate & 0xFFFF;
|
2015-12-03 01:06:04 +01:00
|
|
|
header._descr.setSaveDate(year, month, day);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
int hour = (saveTime >> 8) & 0xFF;
|
|
|
|
int minutes = saveTime & 0xFF;
|
2015-12-03 01:06:04 +01:00
|
|
|
header._descr.setSaveTime(hour, minutes);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-03 01:06:04 +01:00
|
|
|
header._descr.setPlayTime(playTime * 1000);
|
2015-02-19 15:41:15 +02:00
|
|
|
g_engine->setTotalPlayTime(playTime * 1000);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Writes the game out to disk.
|
|
|
|
*/
|
2015-11-30 01:42:12 +01:00
|
|
|
bool saveGame(uint16 Direction, uint16 Quarters, int slot, Common::String desc) {
|
2015-02-19 15:41:15 +02:00
|
|
|
uint16 i, j;
|
|
|
|
Common::String fileName = g_lab->generateSaveFileName(slot);
|
|
|
|
Common::SaveFileManager *saveFileManager = g_system->getSavefileManager();
|
|
|
|
Common::OutSaveFile *file = saveFileManager->openForSaving(fileName);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
if (!file)
|
|
|
|
return false;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Load scene pic
|
2015-12-06 21:53:57 +01:00
|
|
|
CloseDataPtr cPtr = nullptr;
|
2015-12-07 23:58:18 +01:00
|
|
|
g_lab->_graphics->readPict(g_lab->getPictName(&cPtr), true);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
writeSaveGameHeader(file, desc);
|
2015-11-30 01:42:12 +01:00
|
|
|
file->writeUint16LE(g_lab->_roomNum);
|
2015-02-19 15:41:15 +02:00
|
|
|
file->writeUint16LE(Direction);
|
|
|
|
file->writeUint16LE(Quarters);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Conditions
|
|
|
|
for (i = 0; i < g_lab->_conditions->_lastElement / (8 * 2); i++)
|
|
|
|
file->writeUint16LE(g_lab->_conditions->_array[i]);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Rooms found
|
|
|
|
for (i = 0; i < g_lab->_roomsFound->_lastElement / (8 * 2); i++)
|
|
|
|
file->writeUint16LE(g_lab->_roomsFound->_array[i]);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Combination lock and tile stuff
|
|
|
|
for (i = 0; i < 6; i++)
|
2015-12-06 18:16:26 +01:00
|
|
|
file->writeByte(g_lab->_combination[i]);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Tiles
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
for (j = 0; j < 4; j++)
|
2015-12-06 18:16:26 +01:00
|
|
|
file->writeUint16LE(g_lab->_curTile[i][j]);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
// Breadcrumbs
|
2015-11-30 07:13:09 +01:00
|
|
|
for (i = 0; i < sizeof(g_lab->_breadCrumbs); i++) {
|
|
|
|
file->writeUint16LE(g_lab->_breadCrumbs[i]._roomNum);
|
|
|
|
file->writeUint16LE(g_lab->_breadCrumbs[i]._direction);
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
file->flush();
|
|
|
|
file->finalize();
|
|
|
|
delete file;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Reads the game from disk.
|
|
|
|
*/
|
2015-11-30 01:42:12 +01:00
|
|
|
bool loadGame(uint16 *Direction, uint16 *Quarters, int slot) {
|
2015-02-19 15:41:15 +02:00
|
|
|
uint16 i, j;
|
|
|
|
Common::String fileName = g_lab->generateSaveFileName(slot);
|
|
|
|
Common::SaveFileManager *saveFileManager = g_system->getSavefileManager();
|
|
|
|
Common::InSaveFile *file = saveFileManager->openForLoading(fileName);
|
2015-12-03 11:01:50 +01:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
if (!file)
|
2014-10-06 14:50:05 +02:00
|
|
|
return false;
|
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
SaveGameHeader header;
|
|
|
|
readSaveGameHeader(file, header);
|
2015-11-30 01:42:12 +01:00
|
|
|
g_lab->_roomNum = file->readUint16LE();
|
2015-02-19 15:41:15 +02:00
|
|
|
*Direction = file->readUint16LE();
|
|
|
|
*Quarters = file->readUint16LE();
|
|
|
|
|
|
|
|
// Conditions
|
|
|
|
for (i = 0; i < g_lab->_conditions->_lastElement / (8 * 2); i++)
|
|
|
|
g_lab->_conditions->_array[i] = file->readUint16LE();
|
|
|
|
|
|
|
|
// Rooms found
|
|
|
|
for (i = 0; i < g_lab->_roomsFound->_lastElement / (8 * 2); i++)
|
|
|
|
g_lab->_roomsFound->_array[i] = file->readUint16LE();
|
|
|
|
|
|
|
|
// Combination lock and tile stuff
|
|
|
|
for (i = 0; i < 6; i++)
|
2015-12-06 18:16:26 +01:00
|
|
|
g_lab->_combination[i] = file->readByte();
|
2015-02-19 15:41:15 +02:00
|
|
|
|
|
|
|
// Tiles
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
for (j = 0; j < 4; j++)
|
2015-12-06 18:16:26 +01:00
|
|
|
g_lab->_curTile[i][j] = file->readUint16LE();
|
2015-02-19 15:41:15 +02:00
|
|
|
|
|
|
|
// Breadcrumbs
|
2015-02-19 19:03:45 +02:00
|
|
|
for (i = 0; i < 128; i++) {
|
2015-11-30 07:13:09 +01:00
|
|
|
g_lab->_breadCrumbs[i]._roomNum = file->readUint16LE();
|
|
|
|
g_lab->_breadCrumbs[i]._direction = file->readUint16LE();
|
2015-02-19 15:41:15 +02:00
|
|
|
}
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-11-30 07:13:09 +01:00
|
|
|
g_lab->_droppingCrumbs = (g_lab->_breadCrumbs[0]._roomNum != 0);
|
|
|
|
g_lab->_followingCrumbs = false;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 19:03:45 +02:00
|
|
|
for (i = 0; i < 128; i++) {
|
2015-11-30 07:13:09 +01:00
|
|
|
if (g_lab->_breadCrumbs[i]._roomNum == 0)
|
2015-02-19 15:41:15 +02:00
|
|
|
break;
|
2015-11-30 07:13:09 +01:00
|
|
|
g_lab->_numCrumbs = i;
|
2015-02-19 15:41:15 +02:00
|
|
|
}
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
delete file;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-19 15:41:15 +02:00
|
|
|
|
2014-10-06 14:50:05 +02:00
|
|
|
} // End of namespace Lab
|