From 9cd7e8b886c2c72d659cd3439ae4f004126393de Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 3 May 2014 13:47:04 -0400 Subject: MADS: Maintain inventory ordering in savegames --- engines/mads/inventory.cpp | 29 ++++++++++++++++++++--------- engines/mads/inventory.h | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/engines/mads/inventory.cpp b/engines/mads/inventory.cpp index a6459c764b..fecb1b34eb 100644 --- a/engines/mads/inventory.cpp +++ b/engines/mads/inventory.cpp @@ -47,10 +47,22 @@ void InventoryObject::synchronize(Common::Serializer &s) { void InventoryObjects::load() { File f("*OBJECTS.DAT"); + int count = f.readUint16LE(); Common::Serializer s(&f, nullptr); // Load the objects data - synchronize(s); + reserve(count); + for (int i = 0; i < count; ++i) { + InventoryObject obj; + obj.synchronize(s); + push_back(obj); + + // If it's for the player's inventory, add the index to the inventory list + if (obj._roomNumber == PLAYER_INVENTORY) { + _inventoryList.push_back(i); + assert(_inventoryList.size() <= 32); + } + } } void InventoryObjects::synchronize(Common::Serializer &s) { @@ -61,23 +73,22 @@ void InventoryObjects::synchronize(Common::Serializer &s) { // Store the data for each object in the inventory lsit for (int idx = 0; idx < count; ++idx) (*this)[idx].synchronize(s); + + // Synchronize the player's inventory + _inventoryList.synchronize(s); } else { clear(); - _inventoryList.clear(); - reserve(count); // Read in each object + reserve(count); for (int i = 0; i < count; ++i) { InventoryObject obj; obj.synchronize(s); push_back(obj); - - // If it's for the player's inventory, add the index to the inventory list - if (obj._roomNumber == PLAYER_INVENTORY) { - _inventoryList.push_back(i); - assert(_inventoryList.size() <= 32); - } } + + // Synchronize the player's inventory + _inventoryList.synchronize(s); } } diff --git a/engines/mads/inventory.h b/engines/mads/inventory.h index 5e3ecd6a69..f3c63f8c4b 100644 --- a/engines/mads/inventory.h +++ b/engines/mads/inventory.h @@ -60,7 +60,7 @@ private: MADSEngine *_vm; public: - Common::Array _inventoryList; + SynchronizedList _inventoryList; /** * Constructor -- cgit v1.2.3