diff options
author | strangerke | 2011-02-15 10:15:21 +0100 |
---|---|---|
committer | strangerke | 2011-02-15 10:15:21 +0100 |
commit | 402ac930fe440af42354bd0c635abb07a69cfc4a (patch) | |
tree | fd506786449c610648d9f1510aa99858c5795776 /engines/hugo/inventory.cpp | |
parent | f1030515d0875c2d306f0e97517f8dfac1375f6c (diff) | |
download | scummvm-rg350-402ac930fe440af42354bd0c635abb07a69cfc4a.tar.gz scummvm-rg350-402ac930fe440af42354bd0c635abb07a69cfc4a.tar.bz2 scummvm-rg350-402ac930fe440af42354bd0c635abb07a69cfc4a.zip |
HUGO: more refactoring and encapsulation
Diffstat (limited to 'engines/hugo/inventory.cpp')
-rw-r--r-- | engines/hugo/inventory.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/engines/hugo/inventory.cpp b/engines/hugo/inventory.cpp index 4bf107575e..a45df7e077 100644 --- a/engines/hugo/inventory.cpp +++ b/engines/hugo/inventory.cpp @@ -46,11 +46,30 @@ namespace Hugo { static const int kMaxDisp = (kXPix / kInvDx); // Max icons displayable -InventoryHandler::InventoryHandler(HugoEngine *vm) : _vm(vm) { +InventoryHandler::InventoryHandler(HugoEngine *vm) : _vm(vm), _invent(0) { _firstIconId = 0; _inventoryState = kInventoryOff; // Inventory icon bar state _inventoryHeight = 0; // Inventory icon bar pos _inventoryObjId = -1; // Inventory object selected (none) + _maxInvent = 0; +} + +/** + * Read _invent from Hugo.dat + */ +void InventoryHandler::loadInvent(Common::ReadStream &in) { + for (int varnt = 0; varnt < _vm->_numVariant; varnt++) { + int16 numElem = in.readUint16BE(); + if (varnt == _vm->_gameVariant) { + _maxInvent = numElem; + _invent = (int16 *)malloc(sizeof(int16) * numElem); + for (int i = 0; i < numElem; i++) + _invent[i] = in.readSint16BE(); + } else { + for (int i = 0; i < numElem; i++) + in.readSint16BE(); + } + } } /** @@ -78,7 +97,7 @@ void InventoryHandler::constructInventory(const int16 imageTotNumb, int displayN int16 displayed = 0; int16 carried = 0; for (int16 i = 0; (i < imageTotNumb) && (displayed < displayNumb); i++) { - if (_vm->_object->isCarried(_vm->_invent[i])) { + if (_vm->_object->isCarried(_invent[i])) { // Check still room to display and past first scroll index if (displayed < displayNumb && carried >= firstObjId) { // Compute source coordinates in dib_u @@ -107,8 +126,8 @@ int16 InventoryHandler::processInventory(const invact_t action, ...) { int16 imageNumb; // Total number of inventory items int displayNumb; // Total number displayed/carried // Compute total number and number displayed, i.e. number carried - for (imageNumb = 0, displayNumb = 0; imageNumb < _vm->_maxInvent && _vm->_invent[imageNumb] != -1; imageNumb++) { - if (_vm->_object->isCarried(_vm->_invent[imageNumb])) + for (imageNumb = 0, displayNumb = 0; imageNumb < _maxInvent && _invent[imageNumb] != -1; imageNumb++) { + if (_vm->_object->isCarried(_invent[imageNumb])) displayNumb++; } @@ -236,4 +255,18 @@ void InventoryHandler::runInventory() { } } + +/** + * Find index of dragged icon + */ +int16 InventoryHandler::findIconId(int16 objId) { + int16 iconId = 0; + for (; iconId < _maxInvent; iconId++) { + if (objId == _invent[iconId]) + break; + } + + return iconId; +} + } // End of namespace Hugo |