From d7d03baba9534e1d94e7642c685addedbb9e2238 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 20:45:43 +0200 Subject: MACVENTURE: Fix small bug in save reading --- engines/macventure/world.cpp | 27 ++++++++++++++++++++++++--- engines/macventure/world.h | 7 ++++++- 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index d919a1a639..abb0c55c04 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -15,11 +15,13 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { if (!saveGameFile.open(_startGameFileName)) error("Could not load initial game configuration"); + debug("Loading save game state from %s", _startGameFileName.c_str()); Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); _saveGame = new SaveGame(_engine, saveGameRes); _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); - //_gameText = new Container(_engine->getFilePath(kTextPathID).c_str()); + calculateObjectRelations(); + _gameText = new Container("Shadowgate II/Shadow Text"); ObjID tid = (ObjID)1; @@ -73,11 +75,25 @@ bool World::loadStartGameFileName() { res->read(fileName, length); fileName[length] = '\0'; _startGameFileName = Common::String(fileName, length); - _startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".bin"); return true; } +void World::calculateObjectRelations() { + ObjID val, next; + uint32 numObjs = _engine->getGlobalSettings().numObjects; + const AttributeGroup &parents = *_saveGame->getGroup(0); + for (uint i = 0; i < numObjs * 2; i++) { + _relations.push_back(0); + } + for (uint i = numObjs - 1; i > 0; i--) { + val = parents[i]; + next = _relations[val * 2]; + if (next) { _relations[i * 2 + 1] = next; } + _relations[val * 2] = i; + } +} + // SaveGame SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { _groups = Common::Array(); @@ -95,6 +111,11 @@ const Common::Array& MacVenture::SaveGame::getGroups() { return _groups; } +const AttributeGroup * SaveGame::getGroup(uint32 groupID) { + assert(groupID < _groups.size()); + return &(_groups[groupID]); +} + const Common::Array& MacVenture::SaveGame::getGlobals() { return _globals; } @@ -107,7 +128,7 @@ void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * GlobalSettings settings = engine->getGlobalSettings(); for (int i = 0; i < settings.numGroups; ++i) { AttributeGroup g; - for (int j = 0; j < settings.numObjects; ++j) + for (int j = 0; j < settings.numObjects; ++j) g.push_back(res->readUint16BE()); _groups.push_back(g); diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 6931996100..fe93ef1395 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -30,7 +30,8 @@ namespace MacVenture { typedef uint32 ObjID; -typedef Common::Array AttributeGroup; +typedef uint16 Attribute; +typedef Common::Array AttributeGroup; class TextAsset; enum ObjectAttributeID { @@ -65,6 +66,7 @@ public: ~SaveGame(); const Common::Array &getGroups(); + const AttributeGroup *getGroup(uint32 groupID); const Common::Array &getGlobals(); const Common::String &getText(); @@ -89,6 +91,7 @@ public: private: bool loadStartGameFileName(); + void calculateObjectRelations(); private: MacVentureEngine *_engine; @@ -99,6 +102,8 @@ private: SaveGame *_saveGame; Container *_objectConstants; Container *_gameText; + + Common::Array _relations; // Parent-child relations, stored in Williams Heap format }; } // End of namespace MacVenture -- cgit v1.2.3