diff options
author | Borja Lorente | 2016-07-16 19:57:36 +0200 |
---|---|---|
committer | Borja Lorente | 2016-08-14 18:55:17 +0200 |
commit | a06f291280e0897beed18e63e269938dfa45ccef (patch) | |
tree | fa589f2c5cdda38677f343c89429aa8cce71a903 /engines/macventure/world.cpp | |
parent | 734b453c86bb20b2cb52c4f695f8a770b97be459 (diff) | |
download | scummvm-rg350-a06f291280e0897beed18e63e269938dfa45ccef.tar.gz scummvm-rg350-a06f291280e0897beed18e63e269938dfa45ccef.tar.bz2 scummvm-rg350-a06f291280e0897beed18e63e269938dfa45ccef.zip |
MACVENTURE: Add basic game save/load feature
Diffstat (limited to 'engines/macventure/world.cpp')
-rw-r--r-- | engines/macventure/world.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index e247404eb6..cf13b78e48 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -9,7 +9,7 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _resourceManager = resMan; _engine = engine; - if (!loadStartGameFileName()) + if ((_startGameFileName = _engine->getStartGameFileName()) == "") error("Could not load initial game configuration"); Common::File saveGameFile; @@ -150,9 +150,11 @@ void World::updateObj(ObjID objID) { } void World::captureChildren(ObjID objID) { + warning("Capture children unimplemented!"); } void World::releaseChildren(ObjID objID) { + warning("Release children unimplemented!"); } Common::String World::getText(ObjID objID, ObjID source, ObjID target) { @@ -175,23 +177,8 @@ bool World::intersects(ObjID objID, Common::Rect rect) { return _engine->getObjBounds(objID).intersects(rect); } -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); - - return true; -} - void World::calculateObjectRelations() { + _relations.clear(); ObjID val, next; uint32 numObjs = _engine->getGlobalSettings().numObjects; const AttributeGroup &parents = *_saveGame->getGroup(0); @@ -228,6 +215,16 @@ void World::setParent(ObjID child, ObjID newParent) { _relations[oldNdx] = child; } +void World::loadGameFrom(Common::InSaveFile *file) { + if (_saveGame) delete _saveGame; + _saveGame = new SaveGame(_engine, file); + calculateObjectRelations(); +} + +void World::saveGameInto(Common::OutSaveFile *file) { + _saveGame->saveInto(file); +} + // SaveGame SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { _groups = Common::Array<AttributeGroup>(); @@ -263,14 +260,34 @@ void SaveGame::setGlobal(uint32 attrID, Attribute value) { _globals[attrID] = value; } -const Common::Array<uint16>& MacVenture::SaveGame::getGlobals() { +const Common::Array<uint16>& SaveGame::getGlobals() { return _globals; } -const Common::String & MacVenture::SaveGame::getText() { +const Common::String & SaveGame::getText() { return _text; } +void SaveGame::saveInto(Common::OutSaveFile *file) { + warning("Saving the game not yet tested!"); + // Save attibutes + Common::Array<AttributeGroup>::const_iterator itg; + for(itg = _groups.begin(); itg != _groups.end(); itg++) { + Common::Array<Attribute>::const_iterator ita; + for (ita = itg->begin(); ita != itg->end(); ita++) { + file->writeUint16BE((*ita)); + } + } + // Save globals + Common::Array<uint16>::const_iterator global; + for (global = _globals.begin(); global != _globals.end(); global++) { + file->writeUint16BE((*global)); + } + // Save text + _text = "Hello"; + file->write(_text.c_str(), _text.size()); +} + void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) { GlobalSettings settings = engine->getGlobalSettings(); for (int i = 0; i < settings.numGroups; ++i) { |