HDB: Shift Save/Load functions to saveload.cpp
This commit is contained in:
parent
ac9f2d634b
commit
963043f3b2
4 changed files with 137 additions and 109 deletions
|
@ -244,7 +244,7 @@ bool HDBGame::startMap(const char *name) {
|
|||
//
|
||||
if (!scumm_strnicmp(name, "map", 3) && scumm_stricmp(name, "map30")) {
|
||||
_menu->fillSavegameSlots();
|
||||
saveSlot(0); // we ignore the slot parameter in everything else since we just keep saving...
|
||||
saveGameState(0); // we ignore the slot parameter in everything else since we just keep saving...
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -426,111 +426,6 @@ void HDBGame::setTargetXY(int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
bool HDBGame::saveSlot(int slot) {
|
||||
|
||||
// If no map is loaded, don't try to save
|
||||
if (!g_hdb->_map->isLoaded())
|
||||
return false;
|
||||
|
||||
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");
|
||||
|
||||
warning("STUB: Save MetaData");
|
||||
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 true;
|
||||
}
|
||||
|
||||
bool HDBGame::loadSlot(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 false;
|
||||
}
|
||||
|
||||
warning("STUB: Load MetaData");
|
||||
Graphics::skipThumbnail(*in);
|
||||
|
||||
// Actual Save Data
|
||||
loadGame(in);
|
||||
|
||||
delete in;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HDBGame::saveGame(Common::OutSaveFile *out) {
|
||||
|
||||
// Save Map Name
|
||||
out->write(_inMapName, 32);
|
||||
|
||||
// Save Map Object Data
|
||||
_map->save(out);
|
||||
|
||||
// Save Window Object Data
|
||||
_window->save(out);
|
||||
|
||||
// Save Gfx Object Data
|
||||
_gfx->save(out);
|
||||
|
||||
// Save Sound Object Data
|
||||
_sound->save(out);
|
||||
|
||||
// Save Game Object Data
|
||||
save(out);
|
||||
|
||||
// Save AI Object Data
|
||||
|
||||
_ai->save(out);
|
||||
}
|
||||
|
||||
void HDBGame::loadGame(Common::InSaveFile *in) {
|
||||
// Load Map Name
|
||||
in->read(_inMapName, 32);
|
||||
|
||||
g_hdb->_sound->stopMusic();
|
||||
_timeSeconds = 0;
|
||||
_timePlayed = 0;
|
||||
|
||||
// Load Map Object Data
|
||||
_map->loadSaveFile(in);
|
||||
|
||||
// Load Window Object Data
|
||||
_window->loadSaveFile(in);
|
||||
|
||||
// Load Gfx Object Data
|
||||
_gfx->loadSaveFile(in);
|
||||
|
||||
// Load Sound Object Data
|
||||
_sound->loadSaveFile(in);
|
||||
|
||||
// Load Game Object Data
|
||||
loadSaveFile(in);
|
||||
|
||||
// Load AI Object Data
|
||||
|
||||
_ai->loadSaveFile(in);
|
||||
|
||||
_gfx->turnOffFade();
|
||||
}
|
||||
|
||||
// PLAYER is trying to use this entity
|
||||
void HDBGame::useEntity(AIEntity *e) {
|
||||
warning("STUB: HDBGame::useEntity incomplete");
|
||||
|
@ -968,7 +863,7 @@ Common::Error HDBGame::run() {
|
|||
_sound->playSound(SND_VORTEX_SAVE);
|
||||
_ai->stopEntity(e);
|
||||
_menu->fillSavegameSlots();
|
||||
saveSlot(_saveInfo.slot);
|
||||
saveGameState(_saveInfo.slot);
|
||||
_saveInfo.active = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,8 +157,8 @@ public:
|
|||
_changeLevel = true;
|
||||
}
|
||||
|
||||
bool saveSlot(int slot);
|
||||
bool loadSlot(int slot);
|
||||
Common::Error saveGameState(int slot);
|
||||
Common::Error loadGameState(int slot);
|
||||
void saveGame(Common::OutSaveFile *out);
|
||||
void loadGame(Common::InSaveFile *in);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ MODULE_OBJS := \
|
|||
map.o \
|
||||
menu.o \
|
||||
sound.o \
|
||||
saveload.o \
|
||||
window.o
|
||||
|
||||
MODULE_DIRS += \
|
||||
|
|
132
engines/hdb/saveload.cpp
Normal file
132
engines/hdb/saveload.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
/* 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 {
|
||||
|
||||
Common::Error HDBGame::saveGameState(int slot) {
|
||||
|
||||
// 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");
|
||||
|
||||
warning("STUB: Save MetaData");
|
||||
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;
|
||||
}
|
||||
|
||||
warning("STUB: Load MetaData");
|
||||
Graphics::skipThumbnail(*in);
|
||||
|
||||
// Actual Save Data
|
||||
loadGame(in);
|
||||
|
||||
delete in;
|
||||
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
void HDBGame::saveGame(Common::OutSaveFile *out) {
|
||||
|
||||
// Save Map Name
|
||||
out->write(_inMapName, 32);
|
||||
|
||||
// Save Map Object Data
|
||||
_map->save(out);
|
||||
|
||||
// Save Window Object Data
|
||||
_window->save(out);
|
||||
|
||||
// Save Gfx Object Data
|
||||
_gfx->save(out);
|
||||
|
||||
// Save Sound Object Data
|
||||
_sound->save(out);
|
||||
|
||||
// Save Game Object Data
|
||||
save(out);
|
||||
|
||||
// Save AI Object Data
|
||||
|
||||
_ai->save(out);
|
||||
}
|
||||
|
||||
void HDBGame::loadGame(Common::InSaveFile *in) {
|
||||
// Load Map Name
|
||||
in->read(_inMapName, 32);
|
||||
|
||||
g_hdb->_sound->stopMusic();
|
||||
_timeSeconds = 0;
|
||||
_timePlayed = 0;
|
||||
|
||||
// Load Map Object Data
|
||||
_map->loadSaveFile(in);
|
||||
|
||||
// Load Window Object Data
|
||||
_window->loadSaveFile(in);
|
||||
|
||||
// Load Gfx Object Data
|
||||
_gfx->loadSaveFile(in);
|
||||
|
||||
// Load Sound Object Data
|
||||
_sound->loadSaveFile(in);
|
||||
|
||||
// Load Game Object Data
|
||||
loadSaveFile(in);
|
||||
|
||||
// Load AI Object Data
|
||||
|
||||
_ai->loadSaveFile(in);
|
||||
|
||||
_gfx->turnOffFade();
|
||||
}
|
||||
|
||||
} // End of Namespace
|
Loading…
Add table
Add a link
Reference in a new issue