diff Party.cpp @ 1829:e4e27261d84e

sub_421B2C_PlaceInInventory_or_DropPickedItem to Party::sub_421B2C_PlaceInInventory_or_DropPickedItem
author Grumpy7
date Fri, 11 Oct 2013 07:29:14 +0200
parents 35c1e4ff6ba7
children f4f63f565a72
line wrap: on
line diff
--- a/Party.cpp	Fri Oct 11 07:04:19 2013 +0200
+++ b/Party.cpp	Fri Oct 11 07:29:14 2013 +0200
@@ -1008,101 +1008,140 @@
   pAudioPlayer->PlaySound(SOUND_GoldReceived, 0, 0, -1, 0, 0, 0, 0);
 }
 //----- (00421B2C) --------------------------------------------------------
-bool  sub_421B2C_PlaceInInventory_or_DropPickedItem()
+void Party::sub_421B2C_PlaceInInventory_or_DropPickedItem()
 {
   unsigned int v0; // eax@2
   Texture *v1; // ebx@2
   int v2; // eax@3
-  Player *v3; // esi@5
   int v4; // eax@6
   unsigned __int16 v5; // dx@11
   signed int v6; // eax@11
-  char *v7; // edi@12
   __int16 v8; // ax@16
   SpriteObject a1; // [sp+4h] [bp-78h]@11
   int v11; // [sp+74h] [bp-8h]@2
   int v12; // [sp+78h] [bp-4h]@5
 
   if ( !pParty->pPickedItem.uItemID )
-    return 1;
+    return;
   v0 = pIcons_LOD->LoadTexture(
          pParty->pPickedItem.GetIconName(),
          TEXTURE_16BIT_PALETTE);
   v1 = pIcons_LOD->GetTexture(v0);
   v11 = areWeLoadingTexture;
   if ( uActiveCharacter
-    && (v2 = pPlayers[uActiveCharacter]->AddItem(-1, pParty->pPickedItem.uItemID)) != 0 )
+    && (v2 = ::pPlayers[uActiveCharacter]->AddItem(-1, pParty->pPickedItem.uItemID)) != 0 )
   {
-    memcpy(&pPlayers[uActiveCharacter]->pInventoryItemList[v2-1], &pParty->pPickedItem, 0x24u);
-	pMouse->RemoveHoldingItem();
+    memcpy(&::pPlayers[uActiveCharacter]->pInventoryItemList[v2-1], &pParty->pPickedItem, 0x24u);
+	  pMouse->RemoveHoldingItem();
   }
   else
   {
-    v12 = 0;
-    v3 = pParty->pPlayers;
-	while ( v3 <= &pParty->pPlayers[3] )
+    for (v12 = 0; v12 < 4; v12++)
     {
-      v4 = v3->AddItem(-1, pParty->pPickedItem.uItemID);
+      v4 = pParty->pPlayers[v12].AddItem(-1, pParty->pPickedItem.uItemID);
       if ( v4 )
-	  {
-		memcpy(&pParty->pPlayers[v12].pInventoryItemList[v4 - 1], &pParty->pPickedItem, 0x24u);
-		pMouse->RemoveHoldingItem();
-		break;
-	  }
-	  ++v12;
-      ++v3;
+      {
+        memcpy(&pParty->pPlayers[v12].pInventoryItemList[v4 - 1], &pParty->pPickedItem, sizeof(ItemGen));
+        pMouse->RemoveHoldingItem();
+        break;
+      }
     }
     if ( v12 == 4 )
-	{
-		v5 = pItemsTable->pItems[pParty->pPickedItem.uItemID].uSpriteID;
-		v6 = 0;
-		a1.uType = pItemsTable->pItems[pParty->pPickedItem.uItemID].uSpriteID;
-		if ( (signed int)pObjectList->uNumObjects <= 0 )
-		{
-		  LOWORD(v6) = 0;
-		}
-		else
-		{
-		  v7 = (char *)&pObjectList->pObjects->uObjectID;
-		  while ( v5 != *(short *)v7 )
-		  {
-			++v6;
-			v7 += 56;
-			if ( v6 >= (signed int)pObjectList->uNumObjects )
-			{
-				LOWORD(v6) = 0;
-				break;
-			}
-		  }
-		}
-		a1.spell_caster_pid = OBJECT_Player;
-		a1.uObjectDescID = v6;
-		a1.vPosition.y = pParty->vPosition.y;
-		a1.vPosition.x = pParty->vPosition.x;
-		a1.vPosition.z = pParty->sEyelevel + pParty->vPosition.z;
-		a1.uSoundID = 0;
-		a1.uFacing = 0;
-		a1.uAttributes = 8;
-		v8 = pIndoor->GetSector(
-			   pParty->vPosition.x,
-			   pParty->vPosition.y,
-			   pParty->sEyelevel + pParty->vPosition.z);
-		a1.uSpriteFrameID = 0;
-		a1.uSectorID = v8;
-		memcpy(&a1.stru_24, &pParty->pPickedItem, sizeof(a1.stru_24));
-		a1.Create(pParty->sRotationY, 184, 200, 0);
-		pMouse->RemoveHoldingItem();
-	}
+    {
+      v5 = pItemsTable->pItems[pParty->pPickedItem.uItemID].uSpriteID;
+      v6 = 0;
+      a1.uType = pItemsTable->pItems[pParty->pPickedItem.uItemID].uSpriteID;
+      for ( uint i = 0; i < pObjectList->uNumObjects; i++ )
+      {
+        if ( v5 == pObjectList->pObjects[i].uObjectID )
+        {
+          v6 = i;
+          break;
+        }
+      }
+      a1.spell_caster_pid = OBJECT_Player;
+      a1.uObjectDescID = v6;
+      a1.vPosition.y = pParty->vPosition.y;
+      a1.vPosition.x = pParty->vPosition.x;
+      a1.vPosition.z = pParty->sEyelevel + pParty->vPosition.z;
+      a1.uSoundID = 0;
+      a1.uFacing = 0;
+      a1.uAttributes = 8;
+      v8 = pIndoor->GetSector(
+        pParty->vPosition.x,
+        pParty->vPosition.y,
+        pParty->sEyelevel + pParty->vPosition.z);
+      a1.uSpriteFrameID = 0;
+      a1.uSectorID = v8;
+      memcpy(&a1.stru_24, &pParty->pPickedItem, sizeof(a1.stru_24));
+      a1.Create(pParty->sRotationY, 184, 200, 0);
+      pMouse->RemoveHoldingItem();
+    }
   }
   if ( !v11 )
   {
     v1->Release();
     pIcons_LOD->SyncLoadedFilesCount();
   }
-  return 1;
+  return;
 }
 
 
+//----- (0048C6F6) --------------------------------------------------------
+bool Party::AddItemToParty(ItemGen *pItem) 
+{
+  unsigned int v2; // eax@1
+  char *v5; // eax@8
+  Texture *v7; // ebx@10
+  signed int v8; // esi@10
+  Player *v9; // edi@11
+  int v10; // eax@11
+  int v21; // [sp+24h] [bp-4h]@10
+
+  v2 = pItem->uItemID;
+  if ( !pItemsTable->pItems[v2].uItemID_Rep_St )
+    pItem->SetIdentified();
+
+  v5 = pItemsTable->pItems[v2].pIconName;
+  if ( v5 )
+  {
+    v7 = pIcons_LOD->LoadTexturePtr(v5, TEXTURE_16BIT_PALETTE);
+    v21 = areWeLoadingTexture;
+    v8 = 0;
+    int startId = uActiveCharacter >= 0 ? uActiveCharacter - 1 : 0;
+    for (int i = 0; i < 4; i++)
+    {
+      v9 = &pPlayers[(startId + i) % 4];  //start with current active player, then cycle right if item won't fit
+      v10 = v9->AddItem(-1, pItem->uItemID);
+      if ( v10 )
+      {
+        memcpy(&v9->pInventoryItemList[v10-1], pItem, 0x24u);
+        pItem->Reset();
+        pAudioPlayer->PlaySound(SOUND_GoldReceived, 0, 0, -1, 0, 0, 0, 0);
+        v9->PlaySound(SPEECH_60, 0);
+        if ( !v21 )
+        {
+          v7->Release();
+          pIcons_LOD->SyncLoadedFilesCount();
+        }
+        return true;
+      }
+    }
+    if ( !v21 )
+    {
+      v7->Release();
+      pIcons_LOD->SyncLoadedFilesCount();
+    }
+    return false;
+  }
+  else
+  {
+    MessageBoxW(nullptr, L"Invalid picture_name detected ::addItem()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Party.cpp:795", 0);
+    return false;
+  }
+}
+// 506128: using guessed type int areWeLoadingTexture;
+
 bool Party::IsPartyEvil()
 {
   return _449B57_test_bit(_quest_bits, 100);