changeset 1558:30db6d265ceb

Changed the new Assert macro definition slightly, Party::AddItem (for some reason in players.cpp) renamed to Party::AddItemToParty, cleaned up; some unused variables in previous functions removed
author Grumpy7
date Sat, 07 Sep 2013 23:06:13 +0200
parents 9c4cf5b07e98
children 1f3f01d39300
files CastSpellInfo.cpp ErrorHandling.h Indoor.cpp Party.h Player.cpp Viewport.cpp mm7_6.cpp
diffstat 7 files changed, 36 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/CastSpellInfo.cpp	Sat Sep 07 21:17:47 2013 +0200
+++ b/CastSpellInfo.cpp	Sat Sep 07 23:06:13 2013 +0200
@@ -2957,7 +2957,7 @@
 				{
 					sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[v450].pUnidentifiedName);
 					ShowStatusBarString(pTmpBuf2.data(), 2u);
-					if ( !pParty->AddItem(&pSpriteObjects[v445].stru_24) )
+					if ( !pParty->AddItemToParty(&pSpriteObjects[v445].stru_24) )
 						pParty->SetHoldingItem(&pSpriteObjects[v445].stru_24);
 				}
 				SpriteObject::OnInteraction(v445);
--- a/ErrorHandling.h	Sat Sep 07 21:17:47 2013 +0200
+++ b/ErrorHandling.h	Sat Sep 07 23:06:13 2013 +0200
@@ -1,9 +1,7 @@
 #pragma once
 
 #define Error(format, ...)             Error_impl_(__FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__)
-#define Assert(condition, format, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, format, __VA_ARGS__)
-#define Assert(condition)              Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, nullptr)
-
+#define Assert(condition, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition,  __VA_ARGS__)
 
 
 
@@ -33,7 +31,7 @@
 
 
 inline void Assert_impl_(const char *filename, const char *functionname, int line,
-                         bool condition, const char *condition_string, const char *format, ...)
+                         bool condition, const char *condition_string, const char *format = nullptr, ...)
 {
   if (condition)
     return;
--- a/Indoor.cpp	Sat Sep 07 21:17:47 2013 +0200
+++ b/Indoor.cpp	Sat Sep 07 23:06:13 2013 +0200
@@ -6053,7 +6053,7 @@
           _449B7E_toggle_bit(pParty->_quest_bits, 184, 1u);
         if ( v19->uItemID == 455 )
           _449B7E_toggle_bit(pParty->_quest_bits, 185, 1u);
-        if ( !pParty->AddItem(v19) )
+        if ( !pParty->AddItemToParty(v19) )
           pParty->SetHoldingItem(v19);
         v21 = v26;
       }
--- a/Party.h	Sat Sep 07 21:17:47 2013 +0200
+++ b/Party.h	Sat Sep 07 23:06:13 2013 +0200
@@ -186,7 +186,7 @@
   void SetHoldingItem(ItemGen *pItem);
   int GetNextActiveCharacter();
   bool _497FC5_check_party_perception_against_level();
-  bool AddItem(ItemGen *pItem);
+  bool AddItemToParty(ItemGen *pItem);
   void Yell();
   void CountHirelings();
   
--- a/Player.cpp	Sat Sep 07 21:17:47 2013 +0200
+++ b/Player.cpp	Sat Sep 07 23:06:13 2013 +0200
@@ -1095,7 +1095,7 @@
       price = this->GetPriceRepair(itemValue, multiplier);
       break;
     default:
-      Assert("(%u)", ShopMenuType);
+      Error("(%u)", ShopMenuType);
     break;
   }
   if ( merchantLevel )
@@ -1349,93 +1349,57 @@
 }
 
 //----- (0048C6F6) --------------------------------------------------------
-bool Party::AddItem(ItemGen *pItem)
+bool Party::AddItemToParty(ItemGen *pItem)
 {
   unsigned int v2; // eax@1
-  unsigned int v3; // ecx@4
-  signed int v4; // edx@4
   char *v5; // eax@8
-  //unsigned int v6; // eax@10
   Texture *v7; // ebx@10
   signed int v8; // esi@10
   Player *v9; // edi@11
   int v10; // eax@11
-  bool result; // eax@15
-  std::string v12; // [sp-18h] [bp-40h]@9
-
-
-  int v15[4] = {0, 1, 2, 3}; // [sp+Ch] [bp-1Ch]@3
-  //int v16; // [sp+10h] [bp-18h]@3
-  //int v17; // [sp+14h] [bp-14h]@3
-  //int v18; // [sp+18h] [bp-10h]@3
-  Player *v19; // [sp+1Ch] [bp-Ch]@9
-  Party *v20; // [sp+20h] [bp-8h]@1
   int v21; // [sp+24h] [bp-4h]@10
 
-  auto thos = this;
-
-  v20 = thos;
   v2 = pItem->uItemID;
   if ( !pItemsTable->pItems[v2].uItemID_Rep_St )
     pItem->SetIdentified();
-  ///v15 = 0;
-  //v16 = 1;
-  //v18 = 3;
-  //v17 = 2;
-  if ( uActiveCharacter )
-  {
-    v3 = uActiveCharacter - 1;
-    v4 = 0;
-    do
-    {
-      v15[v4++] = v3++;
-      if ( (signed int)v3 >= 4 )
-        v3 = 0;
-    }
-    while ( v4 < 4 );
-  }
+
   v5 = pItemsTable->pItems[v2].pIconName;
   if ( v5 )
   {
     v7 = pIcons_LOD->LoadTexturePtr(v5, TEXTURE_16BIT_PALETTE);
     v21 = areWeLoadingTexture;
     v8 = 0;
-    while ( 1 )
-    {
-      v9 = &v20->pPlayers[v15[v8]];
-      v19 = &v20->pPlayers[v15[v8]];
-      v10 = v19->AddItem(-1, pItem->uItemID);
+    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 )
-        break;
-      ++v8;
-      if ( v8 >= 4 )
       {
+        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();
         }
-        goto LABEL_15;
+        return true;
       }
     }
-    memcpy(&v9->pInventoryItemList[v10-1], pItem, 0x24u);
-    pItem->Reset();
-    pAudioPlayer->PlaySound(SOUND_GoldReceived, 0, 0, -1, 0, 0, 0, 0);
-    v19->PlaySound(SPEECH_60, 0);
     if ( !v21 )
     {
       v7->Release();
       pIcons_LOD->SyncLoadedFilesCount();
     }
-    result = 1;
+    return false;
   }
   else
   {
     MessageBoxW(nullptr, L"Invalid picture_name detected ::addItem()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Party.cpp:795", 0);
-LABEL_15:
-    result = 0;
-  }
-  return result;
+    return false;
+  }
 }
 // 506128: using guessed type int areWeLoadingTexture;
 
@@ -1573,31 +1537,26 @@
 //----- (0048CCF5) --------------------------------------------------------
 int Player::GetActualAttack(int a2)
 {
-  Player *v2; // esi@1
   int v3; // eax@1
   int v4; // edi@1
   int v5; // ebx@1
   int v6; // ebp@1
 
-  v2 = this;
   v3 = GetActualAccuracy();
   v4 = GetParameterBonus(v3);
   v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_ATTACK);
   v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_ATTACK, a2);
-  return v4 + v5 + v6 + GetMagicalBonus(CHARACTER_ATTRIBUTE_ATTACK) + v2->_some_attack_bonus;
+  return v4 + v5 + v6 + GetMagicalBonus(CHARACTER_ATTRIBUTE_ATTACK) + this->_some_attack_bonus;
 }
 
 //----- (0048CD45) --------------------------------------------------------
 int Player::GetMeleeDamageMinimal()
 {
-  Player *v1; // edi@1
   int v2; // eax@1
   int v3; // esi@1
   int v4; // esi@1
   int v5; // esi@1
-  int v6; // esi@1
   signed int result; // eax@1
-
  
   v2 = GetActualMight();
   v3 = GetParameterBonus(v2);
@@ -1612,7 +1571,6 @@
 //----- (0048CD90) --------------------------------------------------------
 int Player::GetMeleeDamageMaximal()
 {
-  Player *v1; // edi@1
   int v2; // eax@1
   int v3; // esi@1
   int v4; // esi@1
@@ -1620,12 +1578,11 @@
   int v6; // esi@1
   signed int result; // eax@1
 
-  v1 = this;
   v2 = GetActualMight();
   v3 = GetParameterBonus(v2);
   v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MAX, 0) + v3;
   v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v4;
-  v6 = v1->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v5;
+  v6 = this->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v5;
   result = 1;
   if ( v6 >= 1 )
     result = v6;
@@ -1731,7 +1688,6 @@
 //----- (0048D0B9) --------------------------------------------------------
 int Player::GetRangedAttack()
 {
-  Player *v1; // esi@1
   int v2; // eax@1
   int v3; // edi@3
   int v4; // eax@4
@@ -1739,7 +1695,6 @@
   int v6; // edi@4
   int v7; // edi@4
 
-  v1 = this;
   v2 = *(int *)&this->pInventoryItemList[this->pEquipment.uMainHand-1];
   if ( v2 < ITEM_BLASTER || v2 > ITEM_LASER_RIFLE )
   {
@@ -1747,7 +1702,7 @@
     v5 = GetParameterBonus(v4);
     v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK, 0) + v5;
     v7 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK) + v6;
-    v3 = v1->_ranged_atk_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK) + v7;
+    v3 = this->_ranged_atk_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK) + v7;
   }
   else
   {
@@ -1759,17 +1714,14 @@
 //----- (0048D124) --------------------------------------------------------
 int Player::GetRangedDamageMin()
 {
-  Player *v1; // esi@1
   int v2; // edi@1
   int v3; // edi@1
   int v4; // edi@1
-  unsigned __int16 v5; // ax@1
   int result; // eax@6
 
-  v1 = this;
   v2 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_MIN, 0);
   v3 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v2;
-  v4 = v1->_ranged_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v3;
+  v4 = this->_ranged_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v3;
   if ( v4 >= 1 )
     result = v4;
   else
@@ -1780,17 +1732,14 @@
 //----- (0048D191) --------------------------------------------------------
 int Player::GetRangedDamageMax()
 {
-  Player *v1; // esi@1
   int v2; // edi@1
   int v3; // edi@1
   int v4; // edi@1
-  unsigned __int16 v5; // ax@1
   int result; // eax@6
 
-  v1 = this;
   v2 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_MAX, 0);
   v3 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v2;
-  v4 = v1->_ranged_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v3;
+  v4 = this->_ranged_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v3;
   if ( v4 >= 1 )
     result = v4;
   else
@@ -1801,11 +1750,8 @@
 //----- (0048D1FE) --------------------------------------------------------
 int Player::CalculateRangedDamageTo( int a2 )
 {
-  bool result; // eax@1
   ItemGen *v4; // ebx@2
   unsigned int v5; // edi@2
-  int v7; // edx@4
-  char v8; // zf@4
   int v9; // esi@5
   int v10; // ebx@6
   signed int v15; // [sp+8h] [bp-Ch]@2
@@ -6863,7 +6809,7 @@
         this->sResMagicBonus = (unsigned __int8)var_value;
         break;
       default:
-          Assert("Unexpected var_type: %u", var_type);
+          Error("Unexpected var_type: %u", var_type);
           return;
         break;
     }
--- a/Viewport.cpp	Sat Sep 07 21:17:47 2013 +0200
+++ b/Viewport.cpp	Sat Sep 07 23:06:13 2013 +0200
@@ -300,7 +300,7 @@
           _449B7E_toggle_bit(pParty->_quest_bits, 184, 1);
         if ( pSpriteObjects[v21].stru_24.uItemID == 455 )
           _449B7E_toggle_bit(pParty->_quest_bits, 185, 1);
-        if ( !pParty->AddItem(&pSpriteObjects[v21].stru_24) )
+        if ( !pParty->AddItemToParty(&pSpriteObjects[v21].stru_24) )
           pParty->SetHoldingItem(&pSpriteObjects[v21].stru_24);
       }
       SpriteObject::OnInteraction(a2.y);
--- a/mm7_6.cpp	Sat Sep 07 21:17:47 2013 +0200
+++ b/mm7_6.cpp	Sat Sep 07 23:06:13 2013 +0200
@@ -295,6 +295,7 @@
 		}
 	}
   }
+  pActor->uCarriedItemID = 1;
   if ( pActor->uCarriedItemID )
   {
     Dst.Reset();
@@ -318,12 +319,12 @@
     if ( pItemsTable->pItems[v5].uEquipType == 14 && v4 != 220 )
       Dst.uEnchantmentType = 2 * rand() % 4 + 2;
     pItemsTable->SetSpecialBonus(&Dst);
-    if ( !pParty->AddItem(&Dst) )
+    if ( !pParty->AddItemToParty(&Dst) )
       pParty->SetHoldingItem(&Dst);
     pActor->uCarriedItemID = 0;
     if ( pActor->array_000234[0].uItemID )
     {
-      if ( !pParty->AddItem(pActor->array_000234) )
+      if ( !pParty->AddItemToParty(pActor->array_000234) )
       {
         sub_421B2C_PlaceInInventory_or_DropPickedItem();
         pParty->SetHoldingItem(pActor->array_000234);
@@ -332,7 +333,7 @@
     }
     if ( pActor->array_000234[1].uItemID )
     {
-      if ( !pParty->AddItem(&pActor->array_000234[1]) )
+      if ( !pParty->AddItemToParty(&pActor->array_000234[1]) )
       {
         sub_421B2C_PlaceInInventory_or_DropPickedItem();
         pParty->SetHoldingItem(&pActor->array_000234[1]);
@@ -354,7 +355,7 @@
       else
         sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], v11);
       ShowStatusBarString(pTmpBuf2.data(), 2u);
-      if ( !pParty->AddItem(&Dst) )
+      if ( !pParty->AddItemToParty(&Dst) )
         pParty->SetHoldingItem(&Dst);
       v13 = 1;
     }
@@ -374,13 +375,13 @@
     sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], v10);
   ShowStatusBarString(pTmpBuf2.data(), 2u);
   v8 = pParty;
-  if ( !pParty->AddItem(&Dst) )
+  if ( !pParty->AddItemToParty(&Dst) )
     pParty->SetHoldingItem(&Dst);
   v13 = 1;
 LABEL_45:
   if ( pActor->array_000234[0].uItemID )
   {
-    if ( !v8->AddItem(pActor->array_000234) )
+    if ( !v8->AddItemToParty(pActor->array_000234) )
     {
       sub_421B2C_PlaceInInventory_or_DropPickedItem();
       v8->SetHoldingItem(pActor->array_000234);
@@ -390,7 +391,7 @@
   }
   if ( pActor->array_000234[1].uItemID )
   {
-    if ( !v8->AddItem(&pActor->array_000234[1]) )
+    if ( !v8->AddItemToParty(&pActor->array_000234[1]) )
     {
       sub_421B2C_PlaceInInventory_or_DropPickedItem();
       v8->SetHoldingItem(&pActor->array_000234[1]);