diff options
author | Borja Lorente | 2016-06-13 20:29:08 +0200 |
---|---|---|
committer | Borja Lorente | 2016-08-14 18:24:58 +0200 |
commit | 5719ea30760c85113b4536f7b70295422e95ae9e (patch) | |
tree | f024e7403989255ea35522e35587e020de3fd34a /engines/macventure/world.cpp | |
parent | 9564866ec360dbab39973a5b982b748f6c060637 (diff) | |
download | scummvm-rg350-5719ea30760c85113b4536f7b70295422e95ae9e.tar.gz scummvm-rg350-5719ea30760c85113b4536f7b70295422e95ae9e.tar.bz2 scummvm-rg350-5719ea30760c85113b4536f7b70295422e95ae9e.zip |
MACVENTURE: Add save game loading
Diffstat (limited to 'engines/macventure/world.cpp')
-rw-r--r-- | engines/macventure/world.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp new file mode 100644 index 0000000000..223541d152 --- /dev/null +++ b/engines/macventure/world.cpp @@ -0,0 +1,98 @@ +#include "macventure/world.h" + +#include "common/file.h" + +namespace MacVenture { + +World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { + _resourceManager = resMan; + _engine = engine; + + if (!loadStartGameFileName()) + error("Could not load initial game configuration"); + + Common::File saveGameFile; + if (!saveGameFile.open(_startGameFileName)) + error("Could not load initial game configuration"); + + Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); + + _saveGame = new SaveGame(_engine, saveGameRes); + + delete saveGameRes; + saveGameFile.close(); +} + + +World::~World() { + + if (_saveGame) + delete _saveGame; +} + +bool World::loadStartGameFileName() { + Common::SeekableReadStream *res; + + res = _resourceManager->getResource(MKTAG('S', 'T', 'R', ' '), kStartGameFilenameID); + if (!res) + return false; + + byte length = res->readByte(); + char *fileName = new char[length + 1]; + res->read(fileName, length); + fileName[length] = '\0'; + _startGameFileName = Common::String(fileName, length); + _startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".TXT"); + + return true; +} + +// SaveGame +SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { + _groups = Common::Array<AttributeGroup>(); + loadGroups(engine, res); + _globals = Common::Array<uint16>(); + loadGlobals(engine, res); + _text = Common::String(); + loadText(engine, res); +} + +SaveGame::~SaveGame() { +} + +const Common::Array<AttributeGroup>& MacVenture::SaveGame::getGroups() { + return _groups; +} + +const Common::Array<uint16>& MacVenture::SaveGame::getGlobals() { + return _globals; +} + +const Common::String & MacVenture::SaveGame::getText() { + return _text; +} + +void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) { + GlobalSettings settings = engine->getGlobalSettings(); + for (int i = 0; i < settings.numGroups; ++i) { + AttributeGroup g; + for (int j = 0; j < settings.numObjects; ++j) + g.push_back(res->readUint16BE()); + + _groups.push_back(g); + } +} + +void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream * res) { + GlobalSettings settings = engine->getGlobalSettings(); + for (int i = 0; i < settings.numGlobals; ++i) { + _globals.push_back(res->readUint16BE()); + } +} + +void SaveGame::loadText(MacVentureEngine *engine, Common::SeekableReadStream * res) { + _text = "Placeholder Console Text"; +} + + +} // End of namespace MacVenture |