From 1ed6a2668be5462694c81369cc5abb89e199e2dc Mon Sep 17 00:00:00 2001 From: Robert Špalek Date: Sun, 4 Oct 2009 09:13:15 +0000 Subject: Load inventory items properly after loading the game. This solution is quite hacky, but so is the rest of the code, before a future refactoring done one day. svn-id: r44588 --- engines/draci/game.cpp | 33 +++++++++++++++++++++++---------- engines/draci/game.h | 1 + engines/draci/saveload.cpp | 2 ++ 3 files changed, 26 insertions(+), 10 deletions(-) (limited to 'engines/draci') diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index 297214d8b2..1745a23e10 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -619,25 +619,30 @@ void Game::putItem(int itemID, int position) { if (itemID == kNoItem) return; - uint i = position; - if (position >= 0 && position < kInventoryLines * kInventoryColumns && - _inventory[position] == kNoItem) { + (_inventory[position] == kNoItem || _inventory[position] == itemID)) { _inventory[position] = itemID; } else { - for (i = 0; i < kInventorySlots; ++i) { - if (_inventory[i] == kNoItem) { - _inventory[i] = itemID; + for (position = 0; position < kInventorySlots; ++position) { + if (_inventory[position] == kNoItem) { + _inventory[position] = itemID; break; } } } - const int line = i / kInventoryColumns + 1; - const int column = i % kInventoryColumns + 1; + const int line = position / kInventoryColumns + 1; + const int column = position % kInventoryColumns + 1; - Animation *anim = _vm->_anims->getAnimation(kInventoryItemsID - itemID); + const int anim_id = kInventoryItemsID - itemID; + Animation *anim = _vm->_anims->getAnimation(anim_id); + if (!anim) { + anim = _vm->_anims->addItem(anim_id); + const BAFile *img = _vm->_itemImagesArchive->getFile(2 * itemID); + Sprite *sp = new Sprite(img->_data, img->_length, 0, 0, true); + anim->addFrame(sp); + } Drawable *frame = anim->getFrame(); const int x = kInventoryX + @@ -658,7 +663,7 @@ void Game::putItem(int itemID, int position) { // upon returning it to its slot but *not* in other modes because it should be // invisible then (along with the inventory) if (_loopStatus == kStatusInventory && _loopSubstatus == kSubstatusOrdinary) { - _vm->_anims->play(kInventoryItemsID - itemID); + _vm->_anims->play(anim_id); } } @@ -710,6 +715,14 @@ void Game::inventoryDraw() { } } +void Game::inventoryReload() { + // Make sure all items are loaded into memory (e.g., after loading a + // savegame) by re-putting them on the same spot in the inventory. + for (uint i = 0; i < kInventorySlots; ++i) { + putItem(_inventory[i], i); + } +} + void Game::dialogueMenu(int dialogueID) { int oldLines, hit; diff --git a/engines/draci/game.h b/engines/draci/game.h index 3687c3d2de..6a982c80fd 100644 --- a/engines/draci/game.h +++ b/engines/draci/game.h @@ -316,6 +316,7 @@ public: void inventoryInit(); void inventoryDraw(); void inventoryDone(); + void inventoryReload(); void dialogueMenu(int dialogueID); int dialogueDraw(); diff --git a/engines/draci/saveload.cpp b/engines/draci/saveload.cpp index 89516d2ba2..805e4f607c 100644 --- a/engines/draci/saveload.cpp +++ b/engines/draci/saveload.cpp @@ -149,6 +149,8 @@ Common::Error loadSavegameData(int saveGameIdx, DraciEngine *vm) { vm->_game->setRoomNum(oldRoomNum); vm->_game->setExitLoop(true); + vm->_game->inventoryReload(); + return Common::kNoError; } -- cgit v1.2.3