2019-07-09 12:57:44 +05:30
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hdb/hdb.h"
|
|
|
|
|
|
|
|
namespace HDB {
|
|
|
|
|
2019-07-09 11:38:52 +02:00
|
|
|
Common::Error HDBGame::saveGameState(int slot, const Common::String &desc) {
|
2019-07-09 12:57:44 +05:30
|
|
|
|
|
|
|
// If no map is loaded, don't try to save
|
|
|
|
if (!g_hdb->_map->isLoaded())
|
|
|
|
return Common::kCreatingFileFailed;
|
|
|
|
|
|
|
|
Common::OutSaveFile *out;
|
|
|
|
|
|
|
|
Common::String saveFileName = Common::String::format("%s.%03d", _targetName.c_str(), slot);
|
|
|
|
if (!(out = _saveFileMan->openForSaving(saveFileName)))
|
|
|
|
error("Unable to open save file");
|
|
|
|
|
|
|
|
Graphics::saveThumbnail(*out);
|
|
|
|
|
|
|
|
// Actual Save Data
|
|
|
|
saveGame(out);
|
|
|
|
_lua->save(out, _targetName.c_str(), slot);
|
|
|
|
|
|
|
|
out->finalize();
|
|
|
|
if (out->err())
|
|
|
|
warning("Can't write file '%s'. (Disk full?)", saveFileName.c_str());
|
|
|
|
|
|
|
|
delete out;
|
|
|
|
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error HDBGame::loadGameState(int slot) {
|
|
|
|
Common::InSaveFile *in;
|
|
|
|
|
|
|
|
Common::String saveFileName = Common::String::format("%s.%03d", _targetName.c_str(), slot);
|
|
|
|
if (!(in = _saveFileMan->openForLoading(saveFileName))) {
|
|
|
|
warning("missing savegame file %s", saveFileName.c_str());
|
|
|
|
if (g_hdb->_map->isLoaded())
|
|
|
|
g_hdb->setGameState(GAME_PLAY);
|
|
|
|
return Common::kReadingFailed;
|
|
|
|
}
|
|
|
|
|
2019-07-10 22:20:01 +02:00
|
|
|
_window->closeAll();
|
|
|
|
|
2019-07-09 12:57:44 +05:30
|
|
|
Graphics::skipThumbnail(*in);
|
|
|
|
|
|
|
|
// Actual Save Data
|
|
|
|
loadGame(in);
|
|
|
|
|
2019-07-09 14:42:04 +02:00
|
|
|
_lua->loadLua(_currentLuaName); // load the Lua code FIRST! (if no file, it's ok)
|
|
|
|
|
|
|
|
saveFileName = Common::String::format("%s.l.%03d", _targetName.c_str(), slot);
|
|
|
|
_lua->loadSaveFile(in, saveFileName.c_str());
|
|
|
|
|
2019-07-09 12:57:44 +05:30
|
|
|
delete in;
|
|
|
|
|
2019-07-10 22:20:01 +02:00
|
|
|
// center the player on the screen
|
|
|
|
int x, y;
|
|
|
|
_ai->getPlayerXY(&x, &y);
|
|
|
|
_map->centerMapXY(x + 16, y + 16);
|
|
|
|
|
|
|
|
if (!_ai->cinematicsActive())
|
|
|
|
_gfx->turnOffFade();
|
|
|
|
|
2019-07-09 12:57:44 +05:30
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HDBGame::saveGame(Common::OutSaveFile *out) {
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::saveGame: start at %u", out->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
|
2019-07-09 13:26:46 +05:30
|
|
|
// Save Map Name and Time
|
|
|
|
out->writeUint32LE(_timeSeconds + (_timePlayed / 1000));
|
2019-07-09 12:57:44 +05:30
|
|
|
out->write(_inMapName, 32);
|
|
|
|
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::saveGame: map at %u", out->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
// Save Map Object Data
|
|
|
|
_map->save(out);
|
|
|
|
|
|
|
|
// Save Window Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::saveGame: window at %u", out->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_window->save(out);
|
|
|
|
|
|
|
|
// Save Gfx Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::saveGame: gfx at %u", out->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_gfx->save(out);
|
|
|
|
|
|
|
|
// Save Sound Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::saveGame: sound at %u", out->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_sound->save(out);
|
|
|
|
|
|
|
|
// Save Game Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::saveGame: game object at %u", out->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
save(out);
|
|
|
|
|
|
|
|
// Save AI Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::saveGame: ai at %u", out->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_ai->save(out);
|
2019-07-09 21:15:40 +02:00
|
|
|
|
|
|
|
debug(1, "HDBGame::saveGame: end at %u", out->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void HDBGame::loadGame(Common::InSaveFile *in) {
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::loadGame: start at %u", in->pos());
|
|
|
|
|
2019-07-09 13:26:46 +05:30
|
|
|
// Load Map Name and Time
|
|
|
|
_timeSeconds = in->readUint32LE();;
|
|
|
|
_timePlayed = 0;
|
2019-07-09 12:57:44 +05:30
|
|
|
in->read(_inMapName, 32);
|
|
|
|
|
|
|
|
g_hdb->_sound->stopMusic();
|
|
|
|
|
|
|
|
// Load Map Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::loadGame: map at %u", in->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_map->loadSaveFile(in);
|
|
|
|
|
|
|
|
// Load Window Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::loadGame: window at %u", in->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_window->loadSaveFile(in);
|
|
|
|
|
|
|
|
// Load Gfx Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::loadGame: gfx at %u", in->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_gfx->loadSaveFile(in);
|
|
|
|
|
|
|
|
// Load Sound Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::loadGame: sound at %u", in->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_sound->loadSaveFile(in);
|
|
|
|
|
|
|
|
// Load Game Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::loadGame: game object at %u", in->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
loadSaveFile(in);
|
|
|
|
|
|
|
|
// Load AI Object Data
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::loadGame: ai at %u", in->pos());
|
2019-07-09 12:57:44 +05:30
|
|
|
_ai->loadSaveFile(in);
|
|
|
|
|
2019-07-09 21:15:40 +02:00
|
|
|
debug(1, "HDBGame::loadGame: end at %u", in->pos());
|
|
|
|
|
2019-07-09 12:57:44 +05:30
|
|
|
_gfx->turnOffFade();
|
|
|
|
}
|
|
|
|
|
2019-07-09 11:38:52 +02:00
|
|
|
} // End of Namespace
|