changeset 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 5ea627a263dd 211dfe2d8db1
files CastSpellInfo.cpp Party.cpp Party.h Player.cpp UI/UIHouses.cpp mm7_6.cpp mm7_data.h
diffstat 7 files changed, 112 insertions(+), 127 deletions(-) [+]
line wrap: on
line diff
--- a/CastSpellInfo.cpp	Fri Oct 11 07:04:19 2013 +0200
+++ b/CastSpellInfo.cpp	Fri Oct 11 07:29:14 2013 +0200
@@ -4347,7 +4347,7 @@
         pGUIWindow_Settings->CreateButton(165, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 1, 50, "", 0);
         pGUIWindow_Settings->CreateButton(280, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 2, 51, "", 0);
         pGUIWindow_Settings->CreateButton(390, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 3, 52, "", 0);
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
+        pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
       }
       if ( a5 & 8 )
@@ -4357,7 +4357,7 @@
 
         pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
         pGUIWindow_Settings->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Shoot_Monster, 0, 0, "", 0);
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
+        pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
       }
       if ( a5 & 0x40 )
@@ -4367,7 +4367,7 @@
 
         pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
         pGUIWindow_Settings->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Telekinesis, 0, 0, "", 0);
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
+        pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
       }
       if ( (char)a5 < 0 )
@@ -4380,7 +4380,7 @@
         pGUIWindow_Settings = pCastSpellInfo[result].GetCastSpellInInventoryWindow();
         _50C9A0_IsEnchantingInProgress = 1;
         some_active_character = uActiveCharacter;
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
+        pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
       }
       if ( HIBYTE(a5) & 1 )
@@ -4393,7 +4393,7 @@
         pGUIWindow_Settings->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 2, 0x33u, "", 0);
         pGUIWindow_Settings->CreateButton(0x186u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 3, 0x34u, "", 0);
         pGUIWindow_Settings->CreateButton(8, 8, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Monster_Improvement, 0, 0, "", NULL);
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
+        pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
       }
       if ( HIBYTE(a5) & 2 && !pGUIWindow_Settings )
       {
--- 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);
--- a/Party.h	Fri Oct 11 07:04:19 2013 +0200
+++ b/Party.h	Fri Oct 11 07:29:14 2013 +0200
@@ -191,6 +191,7 @@
 
 
   void PartyFindsGold(unsigned int uNumGold, int _1_dont_share_with_followers___2_the_same_but_without_a_message__else_normal);
+  void sub_421B2C_PlaceInInventory_or_DropPickedItem();
 
   static void SetGold(unsigned int uNumGold);
   static void TakeGold(unsigned int uNumGold);
--- a/Player.cpp	Fri Oct 11 07:04:19 2013 +0200
+++ b/Player.cpp	Fri Oct 11 07:29:14 2013 +0200
@@ -1347,60 +1347,6 @@
   lastOpenedSpellbookPage = 0;
 }
 
-//----- (0048C6F6) --------------------------------------------------------
-bool Party::AddItemToParty(ItemGen *pItem)      //TODO move to party.cpp
-{
-  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;
 
 //----- (0048C855) --------------------------------------------------------
 int Player::GetBaseStrength()
@@ -2174,14 +2120,14 @@
         }
         if (carriedItemId != 0)     // looks odd in current context, but avoids accessing zeroth element of pItemsTable->pItems
         {
-          sub_421B2C_PlaceInInventory_or_DropPickedItem();
+          pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
           sprintf(
             pTmpBuf2.data(),
             pGlobalTXT_LocalizationStrings[304],   // Official                   //TODO: add a normal "%d stole %d" message
             this->pName,
             pItemsTable->pItems[carriedItemId].pUnidentifiedName);
           ShowStatusBarString(pTmpBuf2.data(), 2u);
-          sub_421B2C_PlaceInInventory_or_DropPickedItem();
+          pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
           memcpy(&pParty->pPickedItem, &tempItem, sizeof(ItemGen));
           pMouse->SetCursorBitmapFromItemID(carriedItemId);
           return 2;
--- a/UI/UIHouses.cpp	Fri Oct 11 07:04:19 2013 +0200
+++ b/UI/UIHouses.cpp	Fri Oct 11 07:29:14 2013 +0200
@@ -1349,7 +1349,7 @@
     case HOUSE_DIALOGUE_SHOP_REPAIR:
     {
       dialog_menu_id = (HOUSE_DIALOGUE_MENU)uMessageParam;
-      sub_421B2C_PlaceInInventory_or_DropPickedItem();
+      pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
       break;
     }
     case HOUSE_DIALOGUE_SHOP_DISPLAY_EQUIPMENT:
--- a/mm7_6.cpp	Fri Oct 11 07:04:19 2013 +0200
+++ b/mm7_6.cpp	Fri Oct 11 07:29:14 2013 +0200
@@ -59,7 +59,7 @@
   int v13; // [sp+30h] [bp-8h]@1
   int v14; // [sp+34h] [bp-4h]@1
 
-  sub_421B2C_PlaceInInventory_or_DropPickedItem();
+  pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
   Dst.Reset();
   v2 = 0;
   v3 = ((unsigned int)&array_77EC08[1975].pEdgeList1[1] & pActor->uAttributes) == 0;
@@ -125,7 +125,7 @@
     {
       if ( !pParty->AddItemToParty(pActor->array_000234) )
       {
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
+        pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         pParty->SetHoldingItem(pActor->array_000234);
       }
       pActor->array_000234[0].Reset();
@@ -134,7 +134,7 @@
     {
       if ( !pParty->AddItemToParty(&pActor->array_000234[1]) )
       {
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
+        pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         pParty->SetHoldingItem(&pActor->array_000234[1]);
       }
       pActor->array_000234[1].Reset();
@@ -182,7 +182,7 @@
   {
     if ( !v8->AddItemToParty(pActor->array_000234) )
     {
-      sub_421B2C_PlaceInInventory_or_DropPickedItem();
+      pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
       v8->SetHoldingItem(pActor->array_000234);
       v13 = 1;
     }
@@ -192,7 +192,7 @@
   {
     if ( !v8->AddItemToParty(&pActor->array_000234[1]) )
     {
-      sub_421B2C_PlaceInInventory_or_DropPickedItem();
+      pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
       v8->SetHoldingItem(&pActor->array_000234[1]);
       v13 = 1;
     }
--- a/mm7_data.h	Fri Oct 11 07:04:19 2013 +0200
+++ b/mm7_data.h	Fri Oct 11 07:29:14 2013 +0200
@@ -1085,7 +1085,6 @@
 void ChestUI_WritePointedObjectStatusString();
 void OnChestLeftClick();
 void GameUI_WritePointedObjectStatusString();
-bool sub_421B2C_PlaceInInventory_or_DropPickedItem();
 void __fastcall GameUI_OnPlayerPortraitLeftClick(unsigned int uPlayerID); // idb
 void OnGameViewportClick();
 bool PauseGameDrawing();