comparison Chest.cpp @ 528:b1598f110b07

Chest working
author Gloval
date Sun, 03 Mar 2013 13:36:41 +0400
parents 214d9d47cf1f
children ec3546510fa1
comparison
equal deleted inserted replaced
526:214d9d47cf1f 528:b1598f110b07
27 size_t uNumChests; // idb 27 size_t uNumChests; // idb
28 struct ChestList *pChestList; 28 struct ChestList *pChestList;
29 Chest pChests[20]; 29 Chest pChests[20];
30 30
31 31
32 const int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42}; 32 const int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42};
33 const int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34}; 33 const int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34};
34 const int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; 34 const int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
35 const int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; 35 const int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
36 36
37 37
38 //----- (0042041E) -------------------------------------------------------- 38 //----- (0042041E) --------------------------------------------------------
39 bool Chest::Open( signed int uChestID ) 39 bool Chest::Open( signed int uChestID )
269 int v17; // [sp+10h] [bp-24h]@4 269 int v17; // [sp+10h] [bp-24h]@4
270 int chest_offs_y; // [sp+14h] [bp-20h]@1 270 int chest_offs_y; // [sp+14h] [bp-20h]@1
271 signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1 271 signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1
272 int chest_offs_x; // [sp+1Ch] [bp-18h]@1 272 int chest_offs_x; // [sp+1Ch] [bp-18h]@1
273 signed int chestWidthCells; // [sp+20h] [bp-14h]@1 273 signed int chestWidthCells; // [sp+20h] [bp-14h]@1
274 signed int cells_counter; // [sp+30h] [bp-4h]@1 274 signed int item_counter; // [sp+30h] [bp-4h]@1
275 275
276 v16 = pRenderer->pActiveZBuffer; 276 v16 = pRenderer->pActiveZBuffer;
277 pRenderer->ClearZBuffer(0, 479); 277 pRenderer->ClearZBuffer(0, 479);
278 chestBitmapId = pChests[uChestID].uChestBitmapID; 278 chestBitmapId = pChests[uChestID].uChestBitmapID;
279 chest_offs_x = pChestPixelOffsetX[chestBitmapId]; 279 chest_offs_x = pChestPixelOffsetX[chestBitmapId];
282 chestHeghtCells = pChestHeightsByType[chestBitmapId]; 282 chestHeghtCells = pChestHeightsByType[chestBitmapId];
283 sprintf(pTmpBuf, "chest%02d", pChestList->pChests[chestBitmapId].uTextureID); 283 sprintf(pTmpBuf, "chest%02d", pChestList->pChests[chestBitmapId].uTextureID);
284 v5 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE); 284 v5 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE);
285 pRenderer->DrawTextureIndexed(8u, 8u, (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0)); 285 pRenderer->DrawTextureIndexed(8u, 8u, (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0));
286 286
287 for (cells_counter = 0; cells_counter< chestWidthCells * chestHeghtCells; ++cells_counter) 287 for (item_counter = 0; item_counter< chestWidthCells * chestHeghtCells; ++item_counter)
288 { 288 {
289 chest_item_index = pChests[uChestID].pInventoryIndices[cells_counter]; 289 chest_item_index = pChests[uChestID].pInventoryIndices[item_counter];
290 if ( chest_item_index > 0 ) 290 if ( chest_item_index > 0 )
291 { 291 {
292 item_texture_id = pIcons_LOD->LoadTexture( 292 item_texture_id = pIcons_LOD->LoadTexture(
293 //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName, 293 //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName,
294 pItemsTable->pItems[pChests[uChestID].igChestItems[chest_item_index-1].uItemID].pIconName, TEXTURE_16BIT_PALETTE); 294 pItemsTable->pItems[pChests[uChestID].igChestItems[chest_item_index-1].uItemID].pIconName, TEXTURE_16BIT_PALETTE);
300 v12 = itemPixelWidth - 14; 300 v12 = itemPixelWidth - 14;
301 v12 = v12 & 0xFFFFFFE0; 301 v12 = v12 & 0xFFFFFFE0;
302 v13 = v12 + 32; 302 v13 = v12 + 32;
303 if ( itemPixelHeght < 14 ) 303 if ( itemPixelHeght < 14 )
304 itemPixelHeght = 14; 304 itemPixelHeght = 14;
305 itemPixelPosX = chest_offs_x + (32 * cells_counter) % chestWidthCells + ((v13 - itemPixelWidth) >> 1); 305 itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((v13 - itemPixelWidth) >> 1);
306 itemPixelPosY = chest_offs_y + (32 * cells_counter) / chestHeghtCells + 306 itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) +
307 ((((itemPixelHeght - 14) & 0xFFFFFFE0) - item_texture->uTextureHeight + 32) >> 1); 307 ((((itemPixelHeght - 14) & 0xFFFFFFE0) - item_texture->uTextureHeight + 32) >> 1);
308 pRenderer->DrawTextureTransparent( itemPixelPosX, itemPixelPosY, item_texture); 308 pRenderer->DrawTextureTransparent( itemPixelPosX, itemPixelPosY, item_texture);
309 sub_40F92A(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, cells_counter + 1); 309 sub_40F92A(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1);
310 } 310 }
311 } 311 }
312 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, 312 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY,
313 (Texture *)(uExitCancelTextureId != -1 ? (int)&pIcons_LOD->pTextures[uExitCancelTextureId] : 0)); 313 (Texture *)(uExitCancelTextureId != -1 ? (int)&pIcons_LOD->pTextures[uExitCancelTextureId] : 0));
314 } 314 }
330 int _column; // ecx@11 330 int _column; // ecx@11
331 char *v14; // eax@12 331 char *v14; // eax@12
332 int chest_cell_heght; // [sp+Ch] [bp-Ch]@1 332 int chest_cell_heght; // [sp+Ch] [bp-Ch]@1
333 signed int v17; // [sp+10h] [bp-8h]@1 333 signed int v17; // [sp+10h] [bp-8h]@1
334 signed int chest_cell_width; // [sp+14h] [bp-4h]@1 334 signed int chest_cell_width; // [sp+14h] [bp-4h]@1
335
336 v17 = test_cell_position;
337 335
338 chest_cell_heght = pChestHeightsByType[pChests[uChestID].uChestBitmapID]; 336 chest_cell_heght = pChestHeightsByType[pChests[uChestID].uChestBitmapID];
339 chest_cell_width = pChestWidthsByType[pChests[uChestID].uChestBitmapID]; 337 chest_cell_width = pChestWidthsByType[pChests[uChestID].uChestBitmapID];
340 item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE); 338 item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE);
341 item_texture = (Texture *)(item_texture_id != -1 ? (int)&pIcons_LOD->pTextures[item_texture_id] : 0); 339 item_texture = (Texture *)(item_texture_id != -1 ? (int)&pIcons_LOD->pTextures[item_texture_id] : 0);
362 while ( 1 ) 360 while ( 1 )
363 { 361 {
364 _column = 0; 362 _column = 0;
365 if ( texture_cell_width > 0 ) 363 if ( texture_cell_width > 0 )
366 { 364 {
367 while ( !pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]) 365 while ( pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]==0)
368 { 366 {
369 ++_column; 367 ++_column;
370 if ( _column >= texture_cell_width ) 368 if ( _column >= texture_cell_width )
371 break; 369 break;
372 } 370 }
371 if (pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]!=0)
372 return false;
373 } 373 }
374 _cell_rows += chest_cell_width; 374 _cell_rows += chest_cell_width;
375 ++_row; 375 ++_row;
376 if ( _row >= texture_cell_height ) 376 if ( _row >= texture_cell_height )
377 return true; 377 return true;
514 return result; 514 return result;
515 } 515 }
516 // 506128: using guessed type int areWeLoadingTexture; 516 // 506128: using guessed type int areWeLoadingTexture;
517 517
518 //----- (0042013E) -------------------------------------------------------- 518 //----- (0042013E) --------------------------------------------------------
519 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int uItemIdx, unsigned int uChestID ) 519 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, unsigned int uChestID )
520 { 520 {
521 int v3; // esi@1 521
522 unsigned int v4; // ebx@1 522 int uItemID; // edi@1
523 int uItemID; // edi@1 523 int v6; // edx@4
524 int v6; // edx@4 524 unsigned int v7; // eax@5
525 unsigned int v7; // eax@5 525 Texture *v8; // ecx@5
526 Texture *v8; // ecx@5 526 signed int v9; // eax@5
527 signed int v9; // eax@5 527 signed int v10; // edi@7
528 signed int v10; // edi@7 528 unsigned int texture_cell_width; // ebx@7
529 unsigned int v11; // ebx@7 529 int textute_cell_height; // edi@9
530 int v12; // edi@9 530 int chest_cell_row_pos; // edx@12
531 int v13; // edx@12 531 int chest_cell_width; // [sp+10h] [bp-Ch]@11
532 void *v14; // edi@14 532
533 int v15; // edi@14 533 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID;
534 int i; // ecx@14 534 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]);
535 unsigned int result; // eax@18 535 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges)
536 __int16 v18; // [sp+Ch] [bp-10h]@1
537 int v19; // [sp+10h] [bp-Ch]@11
538 int v20; // [sp+14h] [bp-8h]@12
539 unsigned int v21; // [sp+18h] [bp-4h]@1
540
541 v3 = 5324 * uChestID;
542 v21 = put_cell_pos;
543 v4 = 5324 * uChestID + 36 * uItemIdx;
544 v18 = uItemIdx;
545 uItemID = pChests[ uChestID].igChestItems[uItemIdx].uItemID;
546 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[uItemIdx]);
547 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[uItemIdx].uNumCharges)
548 {
549 v6 = rand() % 21 + 10;
550 pChests[ uChestID].igChestItems[uItemIdx].uNumCharges = v6;
551 pChests[ uChestID].igChestItems[uItemIdx].uMaxCharges = v6;
552 }
553 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
554 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0);
555 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
556 if ( v9 < 14 )
557 v9 = 14;
558 v10 = v8->uTextureHeight;
559 v11 = ((v9 - 14) >> 5) + 1;
560 if ( v10 < 14 )
561 v10 = 14;
562 v12 = ((v10 - 14) >> 5) + 1;
563 if ( !areWeLoadingTexture )
564 {
565 v8->Release();
566 pIcons_LOD->_40F9C5();
567 }
568 v19 = pChestWidthsByType[pChests[ uChestID].uChestBitmapID];
569 if ( v12 > 0 )
570 {
571 v13 = 0;
572 v20 = v12;
573 do
574 {
575 if ( (signed int)v11 > 0 )
576 {
577 v14 = &pChests[uChestID].pInventoryIndices[v21 + v13];
578 LOWORD(v3) = -1 - v21;
579 v3 <<= 16;
580 LOWORD(v3) = -1 - v21;
581 memset32(v14, v3, v11 >> 1);
582 v15 = (int)((char *)v14 + 4 * (v11 >> 1));
583 for ( i = v11 & 1; i; --i )
584 { 536 {
585 *(short *)v15 = v3; 537 v6 = rand() % 21 + 10;
586 v15 += 2; 538 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6;
587 } 539 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6;
588 } 540 }
589 v13 += v19; 541 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
590 --v20; 542 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0);
591 } 543 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
592 while ( v20 ); 544 if ( v9 < 14 )
593 } 545 v9 = 14;
594 pChests[uChestID].pInventoryIndices[v21] = v18 + 1; 546 v10 = v8->uTextureHeight;
595 } 547 texture_cell_width = ((v9 - 14) >> 5) + 1;
548 if ( v10 < 14 )
549 v10 = 14;
550 textute_cell_height = ((v10 - 14) >> 5) + 1;
551 if ( !areWeLoadingTexture )
552 {
553 v8->Release();
554 pIcons_LOD->_40F9C5();
555 }
556 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID];
557 chest_cell_row_pos = 0;
558 for(int i=0; i<textute_cell_height; ++i)
559 {
560 for (int j=0; j<texture_cell_width; ++j)
561 {
562 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1);
563 }
564 chest_cell_row_pos += chest_cell_width;
565 }
566 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1;
567 }
596 // 506128: using guessed type int areWeLoadingTexture; 568 // 506128: using guessed type int areWeLoadingTexture;
597 569
598 //----- (00420284) -------------------------------------------------------- 570 //----- (00420284) --------------------------------------------------------
599 void Chest::PlaceItems( unsigned int uChestID ) 571 void Chest::PlaceItems( unsigned int uChestID )
600 { 572 {
601 int uChestArea; // edi@1 573 int uChestArea; // edi@1
602 int random_chest_pos; // eax@2 574 int random_chest_pos; // eax@2
603 int test_position; // ebx@11 575 int test_position; // ebx@11
604 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 576 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1
605 int chest_item_id; // [sp+9Ch] [bp-10h]@10 577 int chest_item_id; // [sp+9Ch] [bp-10h]@10
606 unsigned int cell_counter; // [sp+A4h] [bp-8h]@8 578 unsigned int items_counter; // [sp+A4h] [bp-8h]@8
607 579
608 pRenderer->ClearZBuffer(0, 479); 580 pRenderer->ClearZBuffer(0, 479);
609 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; 581 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID];
610 memset(chest_cells_map, 0, 144); 582 memset(chest_cells_map, 0, 144);
611 //fill cell map at random positions 583 //fill cell map at random positions
612 for (cell_counter = 0; cell_counter<uChestArea; ++cell_counter) 584 for (items_counter = 0; items_counter<uChestArea; ++items_counter)
613 { 585 {
614 //get random position in chest 586 //get random position in chest
615 do 587 do
616 random_chest_pos = (unsigned __int8)rand(); 588 random_chest_pos = (unsigned __int8)rand();
617 while ( random_chest_pos >= uChestArea ); 589 while ( random_chest_pos >= uChestArea );
620 { 592 {
621 ++random_chest_pos; 593 ++random_chest_pos;
622 if ( random_chest_pos == uChestArea ) 594 if ( random_chest_pos == uChestArea )
623 random_chest_pos = 0; 595 random_chest_pos = 0;
624 } 596 }
625 chest_cells_map[random_chest_pos] = cell_counter; 597 chest_cells_map[random_chest_pos] = items_counter;
626 } 598 }
627 cell_counter = 0; 599 items_counter = 0;
628 600
629 for (cell_counter = 0; cell_counter<uChestArea; ++cell_counter) 601 for (items_counter = 0; items_counter<uChestArea; ++items_counter)
630 { 602 {
631 chest_item_id = pChests[uChestID].igChestItems[cell_counter].uItemID; 603 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID;
632 if ( chest_item_id ) 604 if ( chest_item_id )
633 { 605 {
634 test_position = 0; 606 test_position = 0;
635 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) 607 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) )
636 { 608 {
638 if ( test_position >= uChestArea ) 610 if ( test_position >= uChestArea )
639 break; 611 break;
640 } 612 }
641 if(test_position<uChestArea) 613 if(test_position<uChestArea)
642 { 614 {
643 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], cell_counter, uChestID); 615 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID);
644 if ( pChests[uChestID].uFlags & 4 ) 616 if ( pChests[uChestID].uFlags & 4 )
645 pChests[uChestID].igChestItems[cell_counter].SetIdentified(); 617 pChests[uChestID].igChestItems[items_counter].SetIdentified();
646 } 618 }
647 } 619 }
648 } 620 }
649 pChests[uChestID].uFlags = pChests[uChestID].uFlags & 0xFFFB | 2; 621 pChests[uChestID].SetInitialized(true);
650 } 622 }
651 // 420284: using guessed type char Dst[144]; 623 // 420284: using guessed type char Dst[144];
652 624
653 //----- (00458B03) -------------------------------------------------------- 625 //----- (00458B03) --------------------------------------------------------
654 void ChestList::ToFile() 626 void ChestList::ToFile()