aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBorja Lorente2016-06-17 20:45:43 +0200
committerBorja Lorente2016-08-14 18:28:08 +0200
commitd7d03baba9534e1d94e7642c685addedbb9e2238 (patch)
tree964db4eba70c667011778355d1f5e34b43a1327a
parent9c10b431ce3a59588571fbb77d8ae861f2de4c50 (diff)
downloadscummvm-rg350-d7d03baba9534e1d94e7642c685addedbb9e2238.tar.gz
scummvm-rg350-d7d03baba9534e1d94e7642c685addedbb9e2238.tar.bz2
scummvm-rg350-d7d03baba9534e1d94e7642c685addedbb9e2238.zip
MACVENTURE: Fix small bug in save reading
-rw-r--r--engines/macventure/world.cpp27
-rw-r--r--engines/macventure/world.h7
2 files changed, 30 insertions, 4 deletions
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<AttributeGroup>();
@@ -95,6 +111,11 @@ const Common::Array<AttributeGroup>& MacVenture::SaveGame::getGroups() {
return _groups;
}
+const AttributeGroup * SaveGame::getGroup(uint32 groupID) {
+ assert(groupID < _groups.size());
+ return &(_groups[groupID]);
+}
+
const Common::Array<uint16>& 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<uint16> AttributeGroup;
+typedef uint16 Attribute;
+typedef Common::Array<Attribute> AttributeGroup;
class TextAsset;
enum ObjectAttributeID {
@@ -65,6 +66,7 @@ public:
~SaveGame();
const Common::Array<AttributeGroup> &getGroups();
+ const AttributeGroup *getGroup(uint32 groupID);
const Common::Array<uint16> &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<ObjID> _relations; // Parent-child relations, stored in Williams Heap format
};
} // End of namespace MacVenture