diff options
author | Paul Gilbert | 2014-03-19 00:15:25 -0400 |
---|---|---|
committer | Paul Gilbert | 2014-03-19 00:15:25 -0400 |
commit | 7b808b4464fb20ee37325ce5763504eb2c8e80a2 (patch) | |
tree | d9442af59fc0eb373541f0935c676f78c8b9e942 /engines/mads/inventory.cpp | |
parent | 53eac0d7c045c734e897df1c0246cab185af0463 (diff) | |
download | scummvm-rg350-7b808b4464fb20ee37325ce5763504eb2c8e80a2.tar.gz scummvm-rg350-7b808b4464fb20ee37325ce5763504eb2c8e80a2.tar.bz2 scummvm-rg350-7b808b4464fb20ee37325ce5763504eb2c8e80a2.zip |
MADS: Added inventory add/remove methods
Diffstat (limited to 'engines/mads/inventory.cpp')
-rw-r--r-- | engines/mads/inventory.cpp | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/engines/mads/inventory.cpp b/engines/mads/inventory.cpp index f1a2537d42..4f6ba48027 100644 --- a/engines/mads/inventory.cpp +++ b/engines/mads/inventory.cpp @@ -80,8 +80,16 @@ void InventoryObjects::setData(int objIndex, int id, const byte *p) { } } -void InventoryObjects::setRoom(int objectId, int roomNumber) { - warning("TODO: setObjectRoom"); +void InventoryObjects::setRoom(int objectId, int sceneNumber) { + InventoryObject &obj = (*this)[objectId]; + + if (obj._roomNumber == PLAYER_INVENTORY) + removeFromInventory(objectId, 1); + + if (sceneNumber == PLAYER_INVENTORY) + addToInventory(objectId); + else + obj._roomNumber = sceneNumber; } bool InventoryObjects::isInRoom(int objectId) const { @@ -92,4 +100,68 @@ bool InventoryObjects::isInInventory(int objectId) const { return (*this)[objectId]._roomNumber == PLAYER_INVENTORY; } +void InventoryObjects::addToInventory(int objectId) { + assert(_inventoryList.size() < 32); + UserInterface &userInterface = _vm->_game->_scene._userInterface; + + if (!isInInventory(objectId)) { + _inventoryList.push_back(objectId); + userInterface._selectedInvIndex = _inventoryList.size() - 1; + userInterface._inventoryTopIndex = CLIP(userInterface._inventoryTopIndex, + 0, (int)_inventoryList.size() - 1); + + if ((userInterface._inventoryTopIndex + 5) <= (size() - 1)) + userInterface._inventoryTopIndex = size() - 5; + userInterface._inventoryChanged = true; + + (*this)[objectId]._roomNumber = PLAYER_INVENTORY; + + if (_vm->_game->_v1 == 5 && !_vm->_game->_scene._screenObjects._v832EC) { + userInterface.categoryChanged(); + userInterface.selectObject(userInterface._selectedInvIndex); + } + } +} + +void InventoryObjects::removeFromInventory(int objectId, int newScene) { + Scene &scene = _vm->_game->_scene; + UserInterface &userInterface = scene._userInterface; + + // Scan the inventory list for the object + int invIndex = -1; + for (int idx = 0; idx < (int)_inventoryList.size() && invIndex == -1; ++idx) { + if (_inventoryList[idx] == objectId) + invIndex = idx; + } + + int selectedIndex = userInterface._selectedInvIndex; + bool noSelection = selectedIndex < 0; + + if (_vm->_game->_v1 == 5 && !scene._screenObjects._v832EC) + userInterface.selectObject(-1); + + // Remove the item from the inventory list + _inventoryList.remove_at(invIndex); + + if (invIndex > userInterface._inventoryTopIndex) { + userInterface._inventoryTopIndex = MAX(userInterface._inventoryTopIndex, 0); + } + + userInterface._inventoryChanged = true; + (*this)[objectId]._roomNumber = newScene; + + int newIndex = selectedIndex; + if (!noSelection) { + if (newIndex >= invIndex) + --newIndex; + if (newIndex < 0 && size() > 0) + newIndex = 0; + } + + if (_vm->_game->_v1 == 5 && !scene._screenObjects._v832EC) { + userInterface.categoryChanged(); + userInterface.selectObject(newIndex); + } +} + } // End of namespace MADS |