changeset 1692:92732b6fc196

Player::_48DCF6 cycle and unused var cleanup
author Grumpy7
date Sun, 22 Sep 2013 09:36:38 +0200
parents 1c880907575f
children 861ede68187a
files Player.cpp
diffstat 1 files changed, 56 insertions(+), 241 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Sun Sep 22 08:37:41 2013 +0200
+++ b/Player.cpp	Sun Sep 22 09:36:38 2013 +0200
@@ -2273,52 +2273,24 @@
   signed int v3; // edi@1
   signed int v4; // ebx@1
   int v6; // eax@2
-  int v7; // eax@5
   int v8; // eax@8
-  int v9; // ebx@8
   int v10; // eax@8
   int v11; // ebx@8
   signed int v12; // edx@9
   ItemGen *v13; // eax@9
   int v14; // edx@16
-  unsigned int v15; // edx@17
   int v16; // edx@26
-  unsigned int v17; // edx@27
   signed int v19; // edx@38
-  int *v20; // ecx@38
-  signed int v21; // eax@40
   int v22; // eax@49
   signed int v23; // ebx@49
-  unsigned int v24; // eax@60
-  int v25; // ecx@61
-  int v26; // ebx@74
   void *v27; // ecx@76
-  unsigned int v28; // ebx@78
-  signed int result; // eax@86
-  SoundID v30; // [sp-20h] [bp-C0h]@56
-  signed int v31; // [sp-1Ch] [bp-BCh]@56
-  unsigned int v32; // [sp-18h] [bp-B8h]@56
-  signed int v33; // [sp-14h] [bp-B4h]@56
-  signed int v34; // [sp-10h] [bp-B0h]@56
-  int v35; // [sp-Ch] [bp-ACh]@56
-  unsigned int v36; // [sp-8h] [bp-A8h]@51
-  unsigned int v37; // [sp-8h] [bp-A8h]@56
-  unsigned int v38; // [sp-8h] [bp-A8h]@57
-  unsigned int v39; // [sp-8h] [bp-A8h]@68
   enum CHARACTER_ATTRIBUTE_TYPE v40; // [sp-4h] [bp-A4h]@4
-  int v41; // [sp-4h] [bp-A4h]@51
-  int v42; // [sp-4h] [bp-A4h]@56
-  int v43; // [sp-4h] [bp-A4h]@57
-  signed int v44; // [sp-4h] [bp-A4h]@59
-  int v45; // [sp-4h] [bp-A4h]@68
   char v46[140]; // [sp+Ch] [bp-94h]@13
   unsigned int v47; // [sp+98h] [bp-8h]@1
-  int v48; // [sp+9Ch] [bp-4h]@1
-
-  v3 = 0;
+  ItemGen* v48; // [sp+9Ch] [bp-4h]@1
+
   v4 = 0;
   v47 = 0;
-  v48 = 0;
   switch ( a2 )
   {
     case 1:
@@ -2360,81 +2332,66 @@
       v11 = (GetParameterBonus(v10) + GetParameterBonus(v8)) / 2;
       break;
     case 17:
-      v12 = 0;
-      v13 = this->pInventoryItemList;
-      do
-      {
-        if ( (signed int)v13->uItemID > 0 && (signed int)v13->uItemID <= 134 && !v13->IsBroken())
+      for (int i = 0; i < 138; i++)
+      {
+        v13 = &this->pInventoryItemList[i];
+        if ( v13->uItemID > 0 && v13->uItemID <= 134 && !v13->IsBroken())
           v46[v4++] = v12;
-        ++v12;
-        ++v13;
-      }
-      while ( v12 < 138 );
+      }
       if ( !v4 )
         return 0;
-      v48 = (int)&this->pInventoryItemList[(unsigned __int8)v46[rand() % v4]];
-      v11 = 3 * (pItemsTable->pItems[*(int *)v48].uMaterial + pItemsTable->pItems[*(int *)v48].uDamageMod);
+      v48 = &this->pInventoryItemList[v46[rand() % v4]];
+      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod);
       break;
     case 18:
-      v14 = 0;
-      do
+      for (int i = 0; i < 16; i++ )
       {
         if ( HasItemEquipped((ITEM_EQUIP_TYPE)v14) )
         {
-          if ( v14 == EQUIP_ARMOUR )
-            v46[v4++] = LOBYTE(this->pEquipment.uArmor) - 1;
-          if ( (!v14 || v14 == 1) && GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v14) == 4 )
-            v46[v4++] = *((char *)&this->pEquipment.uShield + 4 * v14) - 1;
+          if ( i == EQUIP_ARMOUR )
+            v46[v4++] = this->pEquipment.uArmor - 1;
+          if ( (i == EQUIP_OFF_HAND || i == EQUIP_MAIN_HAND) && GetEquippedItemEquipType((ITEM_EQUIP_TYPE)i) == EQUIP_SHIELD )
+            v46[v4++] = this->pEquipment.pIndices[i] - 1;
         }
-        v14++;
-      }
-      while ( v14 < 16 );
+      }
       if ( !v4 )
         return 0;
-      v48 = (int)&this->pInventoryItemList[(unsigned __int8)v46[rand() % v4]];
-      v11 = 3 * (pItemsTable->pItems[*(int *)v48].uMaterial + pItemsTable->pItems[*(int *)v48].uDamageMod);
+      v48 = &this->pInventoryItemList[v46[rand() % v4]];
+      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod);
       break;
     case 19:
-      v16 = 0;
-      do
+      for (int i = 0; i < 16; i++ )
       {
         if ( HasItemEquipped((ITEM_EQUIP_TYPE)v16) )
         {
-          if ( v16 == 2 )
+          if ( v16 == EQUIP_BOW )
             v46[v4++] = LOBYTE(this->pEquipment.uBow) - 1;
-          if ( (!v16 || v16 == 1)
-            && (!GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v16) || GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v16) == 1) )
-            v46[v4++] = *((char *)&this->pEquipment.uShield + 4 * v16) - 1;
+          if ( (v16 == EQUIP_OFF_HAND || v16 == EQUIP_MAIN_HAND)
+            && (GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v16) == EQUIP_OFF_HAND || GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v16) == EQUIP_MAIN_HAND) )
+            v46[v4++] = this->pEquipment.pIndices[v16] - 1;
         }
-        v16++;
-      }
-      while ( v16 < 16 );
+      }
       if ( !v4 )
         return 0;
-      v48 = (int)&this->pInventoryItemList[(unsigned __int8)v46[rand() % v4]];
-      v11 = 3 * (pItemsTable->pItems[*(int *)v48].uMaterial + pItemsTable->pItems[*(int *)v48].uDamageMod);
+      v48 = &this->pInventoryItemList[v46[rand() % v4]];
+      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod);
       break;
     case 20:
-      v19 = 0;
-      v20 = this->pInventoryMatrix;
-      do
-      {
-        if ( *v20 > 0 )
+      for ( int i = 0; i < 126; i++ )
+      {
+        int ItemPosInList = this->pInventoryMatrix[i];
+        if (ItemPosInList > 0)
         {
-          v21 = *(int *)&this->pInventoryItemList[*v20-1];
-          if ( v21 > 0 )
+          ItemGen* v21 = &this->pInventoryItemList[ItemPosInList - 1];
+          if ( v21->uItemID > 0 && v21->uItemID <= 134 )
           {
-            if ( v21 <= 134 )
               v46[v4++] = v19;
           }
         }
-        ++v19;
-        ++v20;
-      }
-      while ( v19 < 126 );
+      }
       if ( !v4 )
         return 0;
-      v47 = (unsigned __int8)v46[rand() % v4];
+      v47 = v46[rand() % v4];
       v6 = GetActualAccuracy();
       v11 = GetParameterBonus(v6);
       break;
@@ -2450,228 +2407,115 @@
   }
   else
   {
+    for ( v3 = 0; v3 < 4; v3++ )
+    {
+      if ( this == pPlayers[v3 + 1] )
+        break;
+    }
+
     switch ( a2 )
     {
       case 1:
-        SetCondition(0, 1);
+        SetCondition(Condition_Cursed, 1);
         pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 2:
-        SetCondition(1, 1);
+        SetCondition(Condition_Weak, 1);
         pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 3:
-        SetCondition(2, 1);
+        SetCondition(Condition_Sleep, 1);
         pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 23:
-        SetCondition(3, 1);
+        SetCondition(Condition_Fear, 1);
         pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 4:
-        SetCondition(4, 1);
+        SetCondition(Condition_Drunk, 1);
         pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 5:
-        SetCondition(5, 1);
+        SetCondition(Condition_Insane, 1);
         pAudioPlayer->PlaySound((SoundID)224, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 6:
-        SetCondition(6, 1);
+        SetCondition(Condition_Poison1, 1);
         pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 7:
-        SetCondition(8, 1);
+        SetCondition(Condition_Poison2, 1);
         pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 8:
-        SetCondition(10, 1);
+        SetCondition(Condition_Poison3, 1);
         pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 9:
-        SetCondition(11, 1);
+        SetCondition(Condition_Disease3, 1);
         pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 12:
-        SetCondition(12, 1);
+        SetCondition(Condition_Paralyzed, 1);
         pAudioPlayer->PlaySound((SoundID)224, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 15:
-        SetCondition(15, 1);
+        SetCondition(Condition_Pertified, 1);
         pAudioPlayer->PlaySound((SoundID)225, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 13:
-        SetCondition(13, 1);
+        SetCondition(Condition_Unconcious, 1);
         pAudioPlayer->PlaySound((SoundID)224, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 14:
-        SetCondition(14, 1);
+        SetCondition(Condition_Dead, 1);
         pAudioPlayer->PlaySound((SoundID)225, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 16:
-        SetCondition(16, 1);
+        SetCondition(Condition_Eradicated, 1);
         pAudioPlayer->PlaySound((SoundID)225, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case 17:
       case 18:
       case 19:
-        if ( *(char *)(v48 + 21) & 2 )
+        if ( v48->uAttributes & ITEM_ENCHANTED )
         {
-          do
-          {
-            if ( this == pPlayers[v3 + 1] )
-              break;
-            ++v3;
-          }
-          while ( v3 < 4 );
           pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
           return 1;
         }
         PlaySound(SPEECH_40, 0);
-        *(int *)(v48 + 20) |= 2u;
+        v48->SetBroken();
         pAudioPlayer->PlaySound((SoundID)47, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
@@ -2683,13 +2527,6 @@
           v27 = &pActor->array_000234[1];
           if ( pActor->array_000234[1].uItemID )
           {
-            do
-            {
-              if ( this == pPlayers[v3 + 1] )
-                break;
-              ++v3;
-            }
-            while ( v3 < 4 );
             pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
             return 1;
           }
@@ -2697,13 +2534,6 @@
         memcpy(v27, &this->pInventoryItemList[this->pInventoryMatrix[v47]-1], 0x24u);
         RemoveItemAtInventoryIndex(v47);
         pAudioPlayer->PlaySound((SoundID)47, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
@@ -2711,13 +2541,6 @@
         PlaySound(SPEECH_42, 0);
         ++this->sAgeModifier;
         pAudioPlayer->PlaySound((SoundID)226, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
@@ -2725,13 +2548,6 @@
         PlaySound(SPEECH_41, 0);
         this->sMana = 0;
         pAudioPlayer->PlaySound((SoundID)226, 0, 0, -1, 0, 0, 0, 0);
-        do
-        {
-          if ( this == pPlayers[v3 + 1] )
-            break;
-          ++v3;
-        }
-        while ( v3 < 4 );
         pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
@@ -2739,7 +2555,6 @@
         return 0;
     }
   }
-  return result;
 }
 
 // 48DCF6: using guessed type char var_94[140];