Mercurial > mm7
diff Chest.cpp @ 528:b1598f110b07
Chest working
author | Gloval |
---|---|
date | Sun, 03 Mar 2013 13:36:41 +0400 |
parents | 214d9d47cf1f |
children | ec3546510fa1 |
line wrap: on
line diff
--- a/Chest.cpp Sun Mar 03 01:55:57 2013 +0400 +++ b/Chest.cpp Sun Mar 03 13:36:41 2013 +0400 @@ -29,9 +29,9 @@ Chest pChests[20]; -const int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42}; -const int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34}; -const int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; +const int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42}; +const int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34}; +const int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; const int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; @@ -271,7 +271,7 @@ signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1 int chest_offs_x; // [sp+1Ch] [bp-18h]@1 signed int chestWidthCells; // [sp+20h] [bp-14h]@1 - signed int cells_counter; // [sp+30h] [bp-4h]@1 + signed int item_counter; // [sp+30h] [bp-4h]@1 v16 = pRenderer->pActiveZBuffer; pRenderer->ClearZBuffer(0, 479); @@ -284,9 +284,9 @@ v5 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE); pRenderer->DrawTextureIndexed(8u, 8u, (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0)); - for (cells_counter = 0; cells_counter< chestWidthCells * chestHeghtCells; ++cells_counter) + for (item_counter = 0; item_counter< chestWidthCells * chestHeghtCells; ++item_counter) { - chest_item_index = pChests[uChestID].pInventoryIndices[cells_counter]; + chest_item_index = pChests[uChestID].pInventoryIndices[item_counter]; if ( chest_item_index > 0 ) { item_texture_id = pIcons_LOD->LoadTexture( @@ -302,11 +302,11 @@ v13 = v12 + 32; if ( itemPixelHeght < 14 ) itemPixelHeght = 14; - itemPixelPosX = chest_offs_x + (32 * cells_counter) % chestWidthCells + ((v13 - itemPixelWidth) >> 1); - itemPixelPosY = chest_offs_y + (32 * cells_counter) / chestHeghtCells + + itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((v13 - itemPixelWidth) >> 1); + itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) + ((((itemPixelHeght - 14) & 0xFFFFFFE0) - item_texture->uTextureHeight + 32) >> 1); pRenderer->DrawTextureTransparent( itemPixelPosX, itemPixelPosY, item_texture); - sub_40F92A(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, cells_counter + 1); + sub_40F92A(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1); } } pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, @@ -333,8 +333,6 @@ signed int v17; // [sp+10h] [bp-8h]@1 signed int chest_cell_width; // [sp+14h] [bp-4h]@1 - v17 = test_cell_position; - chest_cell_heght = pChestHeightsByType[pChests[uChestID].uChestBitmapID]; chest_cell_width = pChestWidthsByType[pChests[uChestID].uChestBitmapID]; item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE); @@ -364,12 +362,14 @@ _column = 0; if ( texture_cell_width > 0 ) { - while ( !pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]) + while ( pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]==0) { ++_column; if ( _column >= texture_cell_width ) break; } + if (pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]!=0) + return false; } _cell_rows += chest_cell_width; ++_row; @@ -516,83 +516,55 @@ // 506128: using guessed type int areWeLoadingTexture; //----- (0042013E) -------------------------------------------------------- -void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int uItemIdx, unsigned int uChestID ) +void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, unsigned int uChestID ) { - int v3; // esi@1 - unsigned int v4; // ebx@1 - int uItemID; // edi@1 - int v6; // edx@4 - unsigned int v7; // eax@5 - Texture *v8; // ecx@5 - signed int v9; // eax@5 - signed int v10; // edi@7 - unsigned int v11; // ebx@7 - int v12; // edi@9 - int v13; // edx@12 - void *v14; // edi@14 - int v15; // edi@14 - int i; // ecx@14 - unsigned int result; // eax@18 - __int16 v18; // [sp+Ch] [bp-10h]@1 - int v19; // [sp+10h] [bp-Ch]@11 - int v20; // [sp+14h] [bp-8h]@12 - unsigned int v21; // [sp+18h] [bp-4h]@1 + + int uItemID; // edi@1 + int v6; // edx@4 + unsigned int v7; // eax@5 + Texture *v8; // ecx@5 + signed int v9; // eax@5 + signed int v10; // edi@7 + unsigned int texture_cell_width; // ebx@7 + int textute_cell_height; // edi@9 + int chest_cell_row_pos; // edx@12 + int chest_cell_width; // [sp+10h] [bp-Ch]@11 - v3 = 5324 * uChestID; - v21 = put_cell_pos; - v4 = 5324 * uChestID + 36 * uItemIdx; - v18 = uItemIdx; - uItemID = pChests[ uChestID].igChestItems[uItemIdx].uItemID; - pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[uItemIdx]); - if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[uItemIdx].uNumCharges) - { - v6 = rand() % 21 + 10; - pChests[ uChestID].igChestItems[uItemIdx].uNumCharges = v6; - pChests[ uChestID].igChestItems[uItemIdx].uMaxCharges = v6; - } - v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); - v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0); - v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); - if ( v9 < 14 ) - v9 = 14; - v10 = v8->uTextureHeight; - v11 = ((v9 - 14) >> 5) + 1; - if ( v10 < 14 ) - v10 = 14; - v12 = ((v10 - 14) >> 5) + 1; - if ( !areWeLoadingTexture ) - { - v8->Release(); - pIcons_LOD->_40F9C5(); - } - v19 = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; - if ( v12 > 0 ) - { - v13 = 0; - v20 = v12; - do - { - if ( (signed int)v11 > 0 ) - { - v14 = &pChests[uChestID].pInventoryIndices[v21 + v13]; - LOWORD(v3) = -1 - v21; - v3 <<= 16; - LOWORD(v3) = -1 - v21; - memset32(v14, v3, v11 >> 1); - v15 = (int)((char *)v14 + 4 * (v11 >> 1)); - for ( i = v11 & 1; i; --i ) + uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID; + pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]); + if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges) { - *(short *)v15 = v3; - v15 += 2; + v6 = rand() % 21 + 10; + pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6; + pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6; } - } - v13 += v19; - --v20; + v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); + v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0); + v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); + if ( v9 < 14 ) + v9 = 14; + v10 = v8->uTextureHeight; + texture_cell_width = ((v9 - 14) >> 5) + 1; + if ( v10 < 14 ) + v10 = 14; + textute_cell_height = ((v10 - 14) >> 5) + 1; + if ( !areWeLoadingTexture ) + { + v8->Release(); + pIcons_LOD->_40F9C5(); + } + chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; + chest_cell_row_pos = 0; + for(int i=0; i<textute_cell_height; ++i) + { + for (int j=0; j<texture_cell_width; ++j) + { + pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1); + } + chest_cell_row_pos += chest_cell_width; + } + pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1; } - while ( v20 ); - } - pChests[uChestID].pInventoryIndices[v21] = v18 + 1; -} // 506128: using guessed type int areWeLoadingTexture; //----- (00420284) -------------------------------------------------------- @@ -603,13 +575,13 @@ int test_position; // ebx@11 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 int chest_item_id; // [sp+9Ch] [bp-10h]@10 - unsigned int cell_counter; // [sp+A4h] [bp-8h]@8 + unsigned int items_counter; // [sp+A4h] [bp-8h]@8 pRenderer->ClearZBuffer(0, 479); uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; memset(chest_cells_map, 0, 144); //fill cell map at random positions - for (cell_counter = 0; cell_counter<uChestArea; ++cell_counter) + for (items_counter = 0; items_counter<uChestArea; ++items_counter) { //get random position in chest do @@ -622,13 +594,13 @@ if ( random_chest_pos == uChestArea ) random_chest_pos = 0; } - chest_cells_map[random_chest_pos] = cell_counter; + chest_cells_map[random_chest_pos] = items_counter; } - cell_counter = 0; + items_counter = 0; - for (cell_counter = 0; cell_counter<uChestArea; ++cell_counter) + for (items_counter = 0; items_counter<uChestArea; ++items_counter) { - chest_item_id = pChests[uChestID].igChestItems[cell_counter].uItemID; + chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID; if ( chest_item_id ) { test_position = 0; @@ -640,13 +612,13 @@ } if(test_position<uChestArea) { - Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], cell_counter, uChestID); + Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID); if ( pChests[uChestID].uFlags & 4 ) - pChests[uChestID].igChestItems[cell_counter].SetIdentified(); + pChests[uChestID].igChestItems[items_counter].SetIdentified(); } } } - pChests[uChestID].uFlags = pChests[uChestID].uFlags & 0xFFFB | 2; + pChests[uChestID].SetInitialized(true); } // 420284: using guessed type char Dst[144];