changeset 1385:5644aecb5082

Player::AddItem and Player::AddItem2 fixed my bug
author Grumpy7
date Tue, 16 Jul 2013 23:35:40 +0200
parents b51332ab228f
children 72191abc8116
files Player.cpp
diffstat 1 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Tue Jul 16 20:51:29 2013 +0200
+++ b/Player.cpp	Tue Jul 16 23:35:40 2013 +0200
@@ -940,19 +940,22 @@
 int Player::AddItem(int index, unsigned int uItemID)
 {
   int xStartValue = 0;
+  int startOfInnerLoop = 0;
 
   if ( index == -1 )
   {
     for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++)
     {
-      for (int xcoord = xStartValue; xcoord < INVETORYSLOTSWIDTH; xcoord++)
-      {
-        if ( CanFitItem(xcoord, uItemID) )
+      int innerLoopPos = startOfInnerLoop;
+      for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++)
+      {
+        if ( CanFitItem(innerLoopPos, uItemID) )
         {
-          return CreateItemInInventory(xcoord, uItemID);
+          return CreateItemInInventory(innerLoopPos, uItemID);
         }
-      }
-      xStartValue += INVETORYSLOTSWIDTH;
+        innerLoopPos++;
+      }
+      startOfInnerLoop += INVETORYSLOTSWIDTH;
     }
     return 0;
   }
@@ -969,19 +972,22 @@
 {
   int xStartValue = 0;
   pItemsTable->SetSpecialBonus(Src);
+  int startOfInnerLoop = 0;
 
   if ( index == -1 )
   {
-    for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++)
-    {
-      for (int xcoord = xStartValue; xcoord < INVETORYSLOTSWIDTH; xcoord++)
-      {
-        if ( CanFitItem(xcoord, Src->uItemID) )
+    for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++)      //TODO: change pInventoryMatrix to 2 dimensional array.
+    {
+      int innerLoopPos = startOfInnerLoop;
+      for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++)
+      {
+        if ( CanFitItem(innerLoopPos, Src->uItemID) )
         {
-          return CreateItemInInventory2(xcoord, Src);
+          return CreateItemInInventory2(innerLoopPos, Src);
         }
-      }
-      xStartValue += INVETORYSLOTSWIDTH;
+        innerLoopPos++;
+      }
+      startOfInnerLoop += INVETORYSLOTSWIDTH;
     }
     return 0;
   }
@@ -1017,7 +1023,7 @@
 // 506128: using guessed type int areWeLoadingTexture;
 
 //----- (0049298B) --------------------------------------------------------
-void Player::PutItemArInventoryIndex( int uItemID, int itemListPos, int index )
+void Player::PutItemArInventoryIndex( int uItemID, int itemListPos, int index )   //originally accepted ItemGen* but needed only its uItemID
 {
   Texture *item_texture; // esi@1
   int *pInvPos; // esi@4