From 4b6578603d1195f04be230870ab003ed0698d936 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 24 Aug 2019 20:31:56 -0700 Subject: [PATCH] XEEN: Fix incorrect Throne sprites in Northern Sphinx The Northern Sphinx used a list of object sprites that had an empty entry mid-list. This commit fixes the problem by allow such entries, but will only apply for new games --- engines/xeen/map.cpp | 25 +++++++++++++++++++------ engines/xeen/map.h | 5 +++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/engines/xeen/map.cpp b/engines/xeen/map.cpp index 9d384c7c8ff..f2a9395b281 100644 --- a/engines/xeen/map.cpp +++ b/engines/xeen/map.cpp @@ -383,12 +383,24 @@ void MonsterObjectData::synchronize(XeenSerializer &s, MonsterData &monsterData) _wallItems.clear(); } - for (uint i = 0; i < 16; ++i) { - b = (i >= _objectSprites.size()) ? 0xff : _objectSprites[i]._spriteId; - s.syncAsByte(b); - if (s.isLoading() && b != 0xff) - _objectSprites.push_back(SpriteResourceEntry(b)); + byte objSprites[16]; + int maxSprite = 0; + for (int i = 0; i < 16; ++i) { + objSprites[i] = (i >= (int)_objectSprites.size()) ? 0xff : _objectSprites[i]._spriteId; + s.syncAsByte(objSprites[i]); + if (s.isLoading() && objSprites[i] != 0xff) + maxSprite = i; } + + if (s.isLoading()) { + for (int i = 0; i <= maxSprite; ++i) { + if (objSprites[i] == 0xff) + _objectSprites.push_back(SpriteResourceEntry()); + else + _objectSprites.push_back(SpriteResourceEntry(objSprites[i])); + } + } + for (uint i = 0; i < 16; ++i) { b = (i >= _monsterSprites.size()) ? 0xff : _monsterSprites[i]._spriteId; s.syncAsByte(b); @@ -810,7 +822,8 @@ void Map::load(int mapId) { } // Read in the object sprites - _mobData._objectSprites[i]._sprites.load(filename); + if (!_mobData._objectSprites[i].isEmpty()) + _mobData._objectSprites[i]._sprites.load(filename); } // Load sprites for the monsters diff --git a/engines/xeen/map.h b/engines/xeen/map.h index 1c00e549c3d..cdd33760d74 100644 --- a/engines/xeen/map.h +++ b/engines/xeen/map.h @@ -319,6 +319,11 @@ public: SpriteResourceEntry() { _spriteId = -1; } SpriteResourceEntry(int spriteId): _spriteId(spriteId) { } + + /** + * Returns true if no sprite id is specified + */ + bool isEmpty() const { return _spriteId == -1; } }; private: XeenEngine *_vm;