changeset 1383:0a4254e80036

Player::PutItemArInventoryIndex, Player::RemoveItemAtInventoryIndex cleanup, slightly simplified
author Grumpy7
date Tue, 16 Jul 2013 00:40:01 +0200
parents 132a6a0d5cef
children b51332ab228f
files Player.cpp Player.h
diffstat 2 files changed, 23 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Tue Jul 16 00:20:17 2013 +0200
+++ b/Player.cpp	Tue Jul 16 00:40:01 2013 +0200
@@ -895,25 +895,8 @@
   }
   else
   {
-    texturePtr = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-    widthInSlots = GetSizeInInventorySlots(texturePtr->uTextureWidth);
-    heightInSlots = GetSizeInInventorySlots(texturePtr->uTextureHeight);
-    if ( !areWeLoadingTexture )
-    {
-      texturePtr->Release();
-      pIcons_LOD->SyncLoadedFilesCount();
-    }
-    if (widthInSlots > 0)
-    {
-      v9 = &this->pInventoryIndices[uSlot];
-      for (unsigned int i = 0; i < heightInSlots; i++)
-      {
-        memset32(v9, -1 - uSlot, widthInSlots); //TODO: try to come up with a better solution. negative values are used when drawing the inventory - nothing is drawn
-        v9 += INVETORYSLOTSWIDTH;
-      }
-    }
+    PutItemArInventoryIndex(uItemID, freeSlot, uSlot);
     result = freeSlot + 1;
-    this->pInventoryIndices[uSlot] = freeSlot + 1;
     this->pInventoryItems[freeSlot].uItemID = uItemID;
   }
   return result;
@@ -1025,25 +1008,7 @@
   }
   else
   {
-    item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[Src->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-    slot_width = GetSizeInInventorySlots(item_texture->uTextureWidth);
-    slot_height = GetSizeInInventorySlots(item_texture->uTextureHeight);
-    if ( !areWeLoadingTexture )
-    {
-      item_texture->Release();
-      pIcons_LOD->SyncLoadedFilesCount();
-    }
-
-    if ( slot_width > 0 )
-    {
-      pInvPos = &pInventoryIndices[uSlot];
-      for (unsigned int i = 0; i < slot_height; i++)
-      {
-        memset32(pInvPos, -1 - uSlot, slot_width);
-        pInvPos += INVETORYSLOTSWIDTH;
-      }
-    }
-    pInventoryIndices[uSlot] = freeSlot + 1;
+    PutItemArInventoryIndex(Src->uItemID, freeSlot, uSlot);
     memcpy(&pInventoryItems[freeSlot], Src, sizeof(ItemGen));
     result = freeSlot + 1;
   }
@@ -1052,16 +1017,14 @@
 // 506128: using guessed type int areWeLoadingTexture;
 
 //----- (0049298B) --------------------------------------------------------
-int Player::PutItemArInventoryIndex( ItemGen *item, int item_id, int uSlot )
-    {
-  //Player *v4; // ebx@1
-  //unsigned int v5; // eax@1
+void Player::PutItemArInventoryIndex( int uItemID, int item_id, int uSlot )
+{
   Texture *item_texture; // esi@1
   int *pInvPos; // esi@4
   unsigned int slot_width; // [sp+Ch] [bp-4h]@1
   unsigned int slot_height; // [sp+18h] [bp+8h]@1
 
-  item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[item->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+  item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
   slot_width =  GetSizeInInventorySlots(item_texture->uTextureWidth);
   slot_height = GetSizeInInventorySlots(item_texture->uTextureHeight);
   if ( !areWeLoadingTexture )
@@ -1069,28 +1032,23 @@
     item_texture->Release();
     pIcons_LOD->SyncLoadedFilesCount();
   }
-  if ( (signed int)slot_height > 0 )
-  {
-    pInvPos = &pInventoryIndices[uSlot]; //14x9
-    do
-    {
-      if ( (signed int)slot_width > 0 )
-        memset32(pInvPos, -1 - uSlot, slot_width);
-      pInvPos +=14;
-      --slot_height;
-    }
-    while ( slot_height );
+  if ( slot_width > 0 )
+  {
+    pInvPos = &pInventoryIndices[uSlot];
+    for (unsigned int i = 0; i < slot_height; i++)
+    {
+      memset32(pInvPos, -1 - uSlot, slot_width);//TODO: try to come up with a better solution. negative values are used when drawing the inventory - nothing is drawn
+      pInvPos += INVETORYSLOTSWIDTH;
+    }
   }
   pInventoryIndices[uSlot] = item_id + 1;
-  return 1;
 }
 
 // 506128: using guessed type int areWeLoadingTexture;
 
 //----- (00492A36) --------------------------------------------------------
 void Player::RemoveItemAtInventoryIndex( unsigned int uSlot )
-    {
-
+{
   ItemGen *item_in_slot; // ecx@1
   Texture *item_texture; // esi@1
   unsigned int slot_height; // ebp@1
@@ -1107,19 +1065,15 @@
     item_texture->Release();
     pIcons_LOD->SyncLoadedFilesCount();
   }
-  if ( slot_height > 0 )
+  if ( slot_width > 0 )
   {
     pInvPos = &pInventoryIndices[uSlot];
-    do
-    {
-      if (slot_width > 0 )
-        memset32(pInvPos, 0, slot_width);
-      pInvPos += 14;
-      --slot_height;
-    }
-    while ( slot_height );
-  }
-  
+    for (unsigned int i = 0; i < slot_height; i++)
+    {
+      memset32(pInvPos, 0, slot_width);
+      pInvPos += INVETORYSLOTSWIDTH;
+    }
+  }
 }
 // 506128: using guessed type int areWeLoadingTexture;
 
@@ -9641,7 +9595,7 @@
             pX = v0->AddItem2(0xFFFFFFFFu, &pParty->pPickedItem);
             if ( !pX )
             {
-              v0->PutItemArInventoryIndex(&this_, v13 - 1, a4);
+              v0->PutItemArInventoryIndex(this_.uItemID, v13 - 1, a4);
               memcpy((void *)a2.y, &this_, sizeof(ItemGen));
               return;
             }
--- a/Player.h	Tue Jul 16 00:20:17 2013 +0200
+++ b/Player.h	Tue Jul 16 00:40:01 2013 +0200
@@ -547,7 +547,7 @@
   int AddItem(int uSlot, unsigned int uItemID);
   int AddItem2(int uSlot, ItemGen *Src);
   int CreateItemInInventory2(unsigned int uSlot, ItemGen *Src);
-  int PutItemArInventoryIndex(ItemGen *item, int item_id, int uSlot);
+  void PutItemArInventoryIndex(int uItemID, int item_id, int uSlot);
   void RemoveItemAtInventoryIndex(unsigned int uSlot);
   bool CanAct();
   bool CanSteal();