diff Player.cpp @ 1656:56847118d50c

DamagePlayerFromMonster continuing cleanup, part 2
author Grumpy7
date Wed, 18 Sep 2013 09:06:28 +0200
parents d25389b91029
children 51a74615d956
line wrap: on
line diff
--- a/Player.cpp	Wed Sep 18 06:32:15 2013 +0200
+++ b/Player.cpp	Wed Sep 18 09:06:28 2013 +0200
@@ -7509,7 +7509,7 @@
   int v41; // eax@77
   int v42; // eax@78
   Player *v43; // eax@81
-  Actor *v44; // esi@82
+  //Actor *actorPtr; // esi@82
   Player *v45; // edi@84
   unsigned __int16 v46; // ax@84
   int v47; // ebx@105
@@ -7521,7 +7521,7 @@
   int v53; // eax@128
   signed int v54; // eax@134
   unsigned __int16 v55; // cx@137
-  signed int v56; // eax@139
+  signed int recvdMagicDmg; // eax@139
   int v57; // eax@144
   float v58; // ST18_4@148
   double v59; // st7@148
@@ -7537,12 +7537,12 @@
   int v69; // ecx@170
   int v70; // eax@171
   enum SoundID v71; // [sp+20h] [bp-34h]@12
-  int v72; // [sp+30h] [bp-24h]@164
+  int v72[4]; // [sp+30h] [bp-24h]@164
   double v73; // [sp+40h] [bp-14h]@72
   signed int v74; // [sp+44h] [bp-10h]@1
-  unsigned int v75; // [sp+48h] [bp-Ch]@3
+  int healthBeforeRecvdDamage; // [sp+48h] [bp-Ch]@3
   unsigned int uActorID; // [sp+4Ch] [bp-8h]@1
-  int v77; // [sp+50h] [bp-4h]@26
+  int dmgToReceive; // [sp+50h] [bp-4h]@26
   signed int a4a; // [sp+60h] [bp+Ch]@162
   Player *a4b; // [sp+60h] [bp+Ch]@168
 
@@ -7554,7 +7554,7 @@
   {
     playerPtr = &pParty->pPlayers[a4];
     actorPtr = &pActors[v4];
-    v75 = playerPtr->sHealth;
+    healthBeforeRecvdDamage = playerPtr->sHealth;
     if ( v5 != 1 || !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) )
       return;
     v8 = playerPtr->pEquipment.uArmor;
@@ -7587,15 +7587,12 @@
       }
     }
     pAudioPlayer->PlaySound(v17, PID(OBJECT_Player,a4 + 80), 0, -1, 0, 0, 0, 0);
-    v18 = Actor::_43B3E0_CalcDamage(actorPtr, v74);
-    v19 = HIDWORD(actorPtr->pActorBuffs[3].uExpireTime) == 0;
-    v20 = SHIDWORD(actorPtr->pActorBuffs[3].uExpireTime) < 0;
-    v77 = v18;
-    if ( !v20 && (!(v20 | v19) || LODWORD(actorPtr->pActorBuffs[3].uExpireTime) > 0) )
+    dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, v74);
+    if ( actorPtr->pActorBuffs[3].uExpireTime > 0 )
     {
       v21 = actorPtr->pActorBuffs[3].uPower;
       if ( v21 )
-        v77 /= (signed int)v21;
+        dmgToReceive /= (signed int)v21;
     }
     switch (v74)
     {
@@ -7617,16 +7614,15 @@
     }
     if ( !(dword_6BE368_debug_settings_2 & 0x10) )
     {
-      v24 = playerPtr->ReceiveDamage(v77, (DAMAGE_TYPE)v22);
-      if ( SHIDWORD(playerPtr->pPlayerBuffs[10].uExpireTime) >= 0
-        && (SHIDWORD(playerPtr->pPlayerBuffs[10].uExpireTime) > 0 || LODWORD(playerPtr->pPlayerBuffs[10].uExpireTime)) )
+      v24 = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v22);
+      if ( playerPtr->pPlayerBuffs[10].uExpireTime > 0 )
       {
         v25 = actorPtr->uAIState;
         if ( v25 != Dying && v25 != Dead)
         {
           v26 = stru_50C198.CalcMagicalDamageToActor(actorPtr, v22, v24);
           actorPtr->sCurrentHP -= v26;
-          if ( v26 )
+          if ( v26 >= 0 )
           {
             if ( actorPtr->sCurrentHP >= 1 )
             {
@@ -7635,16 +7631,10 @@
             }
             else
             {
-              if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 )
+              if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pRenderer->pRenderD3D && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS)
               {
                 v27 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius;
-                if ( pRenderer->pRenderD3D )
-                {
-                  if ( pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
-                  {
-                    pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, v27, 0, 0);
-                  }
-                }
+                pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, v27, 0, 0);
               }
               Actor::Die(uActorID);
               Actor::ApplyFineForKillingPeasant(uActorID);
@@ -7662,25 +7652,20 @@
       if ( !(dword_6BE368_debug_settings_2 & 0x10)
         && actorPtr->pMonsterInfo.uSpecialAttack
         && rand() % 100 < actorPtr->pMonsterInfo.uLevel * actorPtr->pMonsterInfo.uSpecialAttackType )
+      {
         playerPtr->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, actorPtr);
+      }
     }
     if ( !pParty->bTurnBasedModeOn )
     {
       v35 = playerPtr->GetActualEndurance();
-      v36 = (double)(20 - playerPtr->GetParameterBonus(v35)) * flt_6BE3A4_debug_recmod1 * 2.133333333333333;
-      playerPtr->SetRecoveryTime((signed __int64)v36);
-    }
-    if ( v77 )
-    {
-      v73 = (double)(signed int)v75;
-      if ( (double)playerPtr->GetMaxHealth() * 0.25 < v73 )
-      {
-        if ( playerPtr->sHealth > 0 )
-        {
-          if ( (double)playerPtr->GetMaxHealth() * 0.25 >= (double)playerPtr->sHealth )
-            playerPtr->PlaySound(SPEECH_48, 0);
-        }
-      }
+      v36 = (20 - playerPtr->GetParameterBonus(v35)) * flt_6BE3A4_debug_recmod1 * 2.133333333333333;
+      playerPtr->SetRecoveryTime(v36);
+    }
+    int yellThreshold = playerPtr->GetMaxHealth() * 0.25;
+    if ( yellThreshold < playerPtr->sHealth && yellThreshold >= healthBeforeRecvdDamage && playerPtr->sHealth > 0 )
+    {
+      playerPtr->PlaySound(SPEECH_48, 0);
     }
     viewparams->bRedrawGameUI = 1;
     return;
@@ -7698,17 +7683,16 @@
     v42 = v41 - 1;
     if ( !v42 )
     {
-      v44 = &pActors[v39];
+      actorPtr = &pActors[v39];
       if ( a4 == -1 )
-        a4 = stru_50C198.which_player_would_attack(v44);
+        a4 = stru_50C198.which_player_would_attack(actorPtr);
       v45 = &pParty->pPlayers[a4];
-      v77 = Actor::_43B3E0_CalcDamage(v44, v74);
+      dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, v74);
       v46 = v37->uType;
       if ( v37->uType == 545 )
       {
-        LOBYTE(v51) = v45->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
-        v52 = v51;
-        if ( (signed int)SkillToMastery(v51) >= 4 && rand() % 100 < (v52 & 0x3F) )
+        v51 = v45->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
+        if ( SkillToMastery(v51) >= 4 && rand() % 100 < (v51 & 0x3F) )
         {
 		    sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[637], v45->pName);
           ShowStatusBarString(pTmpBuf.data(), 2u);
@@ -7730,125 +7714,111 @@
           && v46 != 540 )
           goto LABEL_115;
       }
-      if ( !stru_50C198.ActorHitOrMiss(v44, v45) )
+      if ( !stru_50C198.ActorHitOrMiss(actorPtr, v45) )
         return;
       if ( (signed __int64)v45->pPlayerBuffs[13].uExpireTime > 0 )
-        v77 >>= 1;
+        dmgToReceive >>= 1;
       if ( v45->HasEnchantedItemEquipped(36) )
-        v77 >>= 1;
+        dmgToReceive >>= 1;
       if ( v45->HasEnchantedItemEquipped(69) )
-        v77 >>= 1;
+        dmgToReceive >>= 1;
       if ( v45->HasItemEquipped(EQUIP_ARMOUR)
 		  && v45->pInventoryItemList[v45->pEquipment.uArmor-1].uItemID == ITEM_ARTIFACT_GOVERNORS_ARMOR )
-        v77 >>= 1;
+        dmgToReceive >>= 1;
       if ( v45->HasItemEquipped(EQUIP_MAIN_HAND))
       {
         v48 = v45->pInventoryItemList[v45->pEquipment.uMainHand - 1].uItemID;
         if ( v48 == ITEM_RELIC_KELEBRIM || v48 == ITEM_ARTIFACT_ELFBANE || (v45->GetEquippedItemEquipType(EQUIP_MAIN_HAND) == EQUIP_SHIELD && SkillToMastery(v45->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4))
-          v77 >>= 1;
+          dmgToReceive >>= 1;
       }
       if ( v45->HasItemEquipped(EQUIP_OFF_HAND))
       {
         v48 = v45->pInventoryItemList[v45->pEquipment.uShield - 1].uItemID;
         if ( v48 == ITEM_RELIC_KELEBRIM || v48 == ITEM_ARTIFACT_ELFBANE || (v45->GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD && SkillToMastery(v45->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4))
-          v77 >>= 1;
+          dmgToReceive >>= 1;
       }
   LABEL_115:
-      if ( (signed __int64)v44->pActorBuffs[3].uExpireTime > 0 )
-      {
-        v49 = v44->pActorBuffs[3].uPower;
-        if ( v49 )
-          v77 /= (signed int)v49;
-      }
-      if ( !v74 )
+      if ( actorPtr->pActorBuffs[3].uExpireTime > 0 )
       {
-        v50 = v44->pMonsterInfo.uAttack1Type;
-        goto LABEL_133;
+        v49 = actorPtr->pActorBuffs[3].uPower;
+        if ( v49 )
+          dmgToReceive /= (signed int)v49;
       }
-      if ( v74 == 1 )
-      {
-        v50 = v44->pMonsterInfo.uAttack2Type;
-        goto LABEL_133;
-      }
-      if ( v74 == 2 )
+      switch(v47)
       {
-        v53 = v44->pMonsterInfo.uSpell1ID;
+        case 0:
+          v50 = actorPtr->pMonsterInfo.uAttack1Type;
+          break;
+        case 1:
+          v50 = actorPtr->pMonsterInfo.uAttack2Type;
+          break;
+        case 2:
+          v53 = actorPtr->pMonsterInfo.uSpell1ID;
+          v50 = LOBYTE(pSpellStats->pInfos[v53].uSchool);
+          break;
+        case 3:
+          v53 = actorPtr->pMonsterInfo.uSpell2ID;
+          v50 = LOBYTE(pSpellStats->pInfos[v53].uSchool);
+          break;
+        case 4:
+          v50 = actorPtr->pMonsterInfo.field_3C_some_special_attack;
+          break;
+        case 5:
+          v50 = 4;
+          break;
       }
-      else
+      if ( !(dword_6BE368_debug_settings_2 & 0x10) )
       {
-        if ( v74 != 3 )
+        v54 = v45->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v50);
+        if ( v45->pPlayerBuffs[10].uExpireTime > 0 )
         {
-          if ( v74 == 4 )
-            v50 = v44->pMonsterInfo.field_3C_some_special_attack;
-          else
-            v50 = 4;
-  LABEL_133:
-          if ( !(dword_6BE368_debug_settings_2 & 0x10) )
+          v55 = actorPtr->uAIState;
+          if ( v55 != Dying && v55 != Dead)
           {
-            v54 = v45->ReceiveDamage(v77, (DAMAGE_TYPE)v50);
-            if ( SHIDWORD(v45->pPlayerBuffs[10].uExpireTime) >= 0 )
+            recvdMagicDmg = stru_50C198.CalcMagicalDamageToActor(actorPtr, v50, v54);
+            actorPtr->sCurrentHP -= recvdMagicDmg;
+            if ( recvdMagicDmg >= 0 )
             {
-              if ( SHIDWORD(v45->pPlayerBuffs[10].uExpireTime) > 0 || LODWORD(v45->pPlayerBuffs[10].uExpireTime) )
+              if ( actorPtr->sCurrentHP >= 1 )
               {
-                v55 = v44->uAIState;
-                if ( v55 != Dying && v55 != Dead)
+                Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0);
+                Actor::AggroSurroundingPeasants(uActorID, 1);
+              }
+              else
+              {
+                if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pRenderer->pRenderD3D && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
                 {
-                  v56 = stru_50C198.CalcMagicalDamageToActor(v44, v50, v54);
-                  v44->sCurrentHP -= v56;
-                  if ( v56 )
-                  {
-                    if ( v44->sCurrentHP >= 1 )
-                    {
-                      Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0);
-                      Actor::AggroSurroundingPeasants(uActorID, 1);
-                    }
-                    else
-                    {
-                      if ( pMonsterStats->pInfos[v44->pMonsterInfo.uID].bQuestMonster & 1 )
-                      {
-                        v57 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * v44->uActorRadius : v44->uActorRadius;
-                        if ( pRenderer->pRenderD3D )
-                        {
-                          if ( pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
-                          {
-                            pDecalBuilder->AddBloodsplat(v44->vPosition.x, v44->vPosition.y, v44->vPosition.z, 1.0, 0.0, 0.0, v57, 0, 0);
-                          }
-                        }
-                      }
-                      Actor::Die(uActorID);
-                      Actor::ApplyFineForKillingPeasant(uActorID);
-                      Actor::AggroSurroundingPeasants(uActorID, 1);
-                      if ( v44->pMonsterInfo.uExp )
-                        GivePartyExp(pMonsterStats->pInfos[v44->pMonsterInfo.uID].uExp);
-                      v64 = SPEECH_51;
-                      if ( rand() % 100 < 20 )
-                        v64 = ((signed int)v44->pMonsterInfo.uHP >= 100) + 1;
-                      v45->PlaySound((PlayerSpeech)v64, 0);
-                    }
-                  }
+                  v57 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius;
+                  pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, v57, 0, 0);
                 }
+                Actor::Die(uActorID);
+                Actor::ApplyFineForKillingPeasant(uActorID);
+                Actor::AggroSurroundingPeasants(uActorID, 1);
+                if ( actorPtr->pMonsterInfo.uExp )
+                  GivePartyExp(pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].uExp);
+                v64 = SPEECH_51;
+                if ( rand() % 100 < 20 )
+                  v64 = ((signed int)actorPtr->pMonsterInfo.uHP >= 100) + 1;
+                v45->PlaySound((PlayerSpeech)v64, 0);
               }
             }
           }
-          if ( !v74
-            && !(dword_6BE368_debug_settings_2 & 0x10)
-            && v44->pMonsterInfo.uSpecialAttack
-            && rand() % 100 < v44->pMonsterInfo.uLevel * v44->pMonsterInfo.uSpecialAttackType )
-            v45->_48DCF6(v44->pMonsterInfo.uSpecialAttack, v44);
-          if ( !pParty->bTurnBasedModeOn )
-          {
-            v65 = v45->GetActualEndurance();
-            v66 = (double)(20 - v45->GetParameterBonus(v65))
-                * flt_6BE3A4_debug_recmod1
-                * 2.133333333333333;
-            v45->SetRecoveryTime((signed __int64)v66);
-          }
-          return;
         }
-        v53 = v44->pMonsterInfo.uSpell2ID;
       }
-      v50 = LOBYTE(pSpellStats->pInfos[v53].uSchool);
-      goto LABEL_133;
+      if ( !v74
+        && !(dword_6BE368_debug_settings_2 & 0x10)
+        && actorPtr->pMonsterInfo.uSpecialAttack
+        && rand() % 100 < actorPtr->pMonsterInfo.uLevel * actorPtr->pMonsterInfo.uSpecialAttackType )
+        v45->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, actorPtr);
+      if ( !pParty->bTurnBasedModeOn )
+      {
+        v65 = v45->GetActualEndurance();
+        v66 = (double)(20 - v45->GetParameterBonus(v65))
+          * flt_6BE3A4_debug_recmod1
+          * 2.133333333333333;
+        v45->SetRecoveryTime((signed __int64)v66);
+      }
+      return;
     }
     if ( v42 != 1 )
       return;
@@ -7856,7 +7826,20 @@
     if ( a4 != -1 )
     {
       v43 = &pParty->pPlayers[a4];
-  LABEL_168:
+    }
+    else
+    {
+      v74 = 0;
+      for (int i = 1; i <= 4; i++)
+      {
+        v72[v74] = i;
+        v74++;
+      }
+      if ( v74 )
+      {
+        v43 = &pParty->pPlayers[v72[rand() % v74]];//&stru_AA1058[3].pSounds[6972 * *(&v72 + rand() % v74) + 40552];
+      }
+    }
       a4b = v43;
       if ( v38 != OBJECT_Player || v37->spell_id != SPELL_BOW_ARROW)
       {
@@ -7878,23 +7861,6 @@
       }
       return;
     }
-    v74 = 0;
-    a4a = 1;
-    do
-    {
-      if ( pPlayers[a4a]->CanAct() )
-      {
-        v67 = v74++;
-        *(&v72 + v67) = a4a;
-      }
-      ++a4a;
-    }
-    while ( a4a <= 4 );
-    if ( v74 )
-    {
-      v43 = &pParty->pPlayers[*(&v72+rand()%v74)-1];//&stru_AA1058[3].pSounds[6972 * *(&v72 + rand() % v74) + 40552];
-      goto LABEL_168;
-    }
   }
 }
 //----- (00421EA6) --------------------------------------------------------