Mercurial > mm7
diff Player.cpp @ 1382:132a6a0d5cef
Player::AddItem2, Player::CreateItemInInventory2 cleanup
author | Grumpy7 |
---|---|
date | Tue, 16 Jul 2013 00:20:17 +0200 |
parents | 2e5c994f0833 |
children | 0a4254e80036 |
line wrap: on
line diff
--- a/Player.cpp Tue Jul 16 00:00:05 2013 +0200 +++ b/Player.cpp Tue Jul 16 00:20:17 2013 +0200 @@ -938,7 +938,7 @@ } //----- (00492745) -------------------------------------------------------- -int Player::WearItem(unsigned int uItemID) +void Player::WearItem( unsigned int uItemID ) { int item_body_anch; // edi@6 int item_indx; @@ -951,7 +951,6 @@ pEquipment.pIndices[item_body_anch] = item_indx + 1; pInventoryItems[item_indx].uBodyAnchor = item_body_anch + 1; } - return 0; } //----- (004927A8) -------------------------------------------------------- @@ -985,79 +984,42 @@ //----- (00492826) -------------------------------------------------------- int Player::AddItem2(int uSlot, ItemGen *Src) { - unsigned int v3; // ebx@1 - unsigned int v4; // esi@3 - signed int v5; // edi@3 - unsigned int v7; // [sp-8h] [bp-18h]@9 - ItemGen *v8; // [sp-4h] [bp-14h]@9 - Player *thisa; // [sp+Ch] [bp-4h]@1 - signed int uSlota; // [sp+18h] [bp+8h]@2 - - thisa = this; - v3 = Src->uItemID; + int xStartValue = 0; pItemsTable->SetSpecialBonus(Src); + if ( uSlot == -1 ) { - uSlota = 0; - while ( true ) - { - v4 = uSlota; - v5 = 0; - do - { - if ( CanFitItem(v4, v3) ) + for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++) + { + for (int xcoord = xStartValue; xcoord < INVETORYSLOTSWIDTH; xcoord++) + { + if ( CanFitItem(xcoord, Src->uItemID) ) { - v8 = Src; - v7 = v4; - return CreateItemInInventory2(v7, v8); + return CreateItemInInventory2(xcoord, Src); } - ++v5; - v4 += 14; - } - while ( v5 < 14 ); - ++uSlota; - if ( uSlota < 9 ) - continue; - break; + } + xStartValue += INVETORYSLOTSWIDTH; } return 0; } - if ( !CanFitItem(uSlot, v3) ) + if ( !CanFitItem(uSlot, Src->uItemID) ) return 0; - v8 = Src; - v7 = uSlot; - return CreateItemInInventory2(v7, v8); + return CreateItemInInventory2(uSlot, Src); } //----- (0049289C) -------------------------------------------------------- int Player::CreateItemInInventory2(unsigned int uSlot, ItemGen *Src) { - signed int v3; // ebx@1 - ItemGen *v4; // eax@1 + signed int freeSlot; // ebx@1 int result; // eax@6 - //unsigned int v6; // eax@7 Texture *item_texture; // esi@7 - unsigned int v8; // edx@9 int *pInvPos; // esi@10 unsigned int slot_width; // [sp+4h] [bp-Ch]@7 unsigned int slot_height; // [sp+8h] [bp-8h]@7 - Player *v12; // [sp+Ch] [bp-4h]@1 - - - v12 = this; - v3 = 0; - v4 = this->pInventoryItems; - while ( v4->uItemID ) - { - ++v3; - ++v4; - if ( v3 >= 126 ) - { - v3 = -1; - break; - } - } - if ( v3 == -1 ) + + + freeSlot = FindFreeInventorySlot(); + if ( freeSlot == -1 ) { result = 0; } @@ -1071,21 +1033,19 @@ item_texture->Release(); pIcons_LOD->SyncLoadedFilesCount(); } - if ( slot_height > 0 ) + + if ( slot_width > 0 ) { pInvPos = &pInventoryIndices[uSlot]; - do - { - if ( slot_width > 0 ) - memset32(pInvPos, -1 - uSlot, slot_width); - pInvPos +=14; - --slot_height; - } - while ( slot_height ); - } - pInventoryIndices[uSlot] = v3 + 1; - memcpy(&pInventoryItems[v3], Src, sizeof(ItemGen)); - result = v3 + 1; + for (unsigned int i = 0; i < slot_height; i++) + { + memset32(pInvPos, -1 - uSlot, slot_width); + pInvPos += INVETORYSLOTSWIDTH; + } + } + pInventoryIndices[uSlot] = freeSlot + 1; + memcpy(&pInventoryItems[freeSlot], Src, sizeof(ItemGen)); + result = freeSlot + 1; } return result; }