changeset 1597:33a82b36c3e8

Player::GetActualResistance cleaned up, some minor changes in Player::Recover, _48EA46_calc_special_bonus_by_items renamed to GetSpecialItemBonus
author Grumpy7
date Tue, 10 Sep 2013 04:08:15 +0200
parents 061f0e5a284d
children 11bb463837b1
files Player.cpp Player.h
diffstat 2 files changed, 58 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Tue Sep 10 03:25:28 2013 +0200
+++ b/Player.cpp	Tue Sep 10 04:08:15 2013 +0200
@@ -2939,9 +2939,7 @@
 int Player::GetBaseResistance(enum CHARACTER_ATTRIBUTE_TYPE a2)
 {
   int v7; // esi@20
-
   int racialBonus = 0;
-
   __int16* resStat;
 
   switch (a2)
@@ -2985,88 +2983,55 @@
 //----- (0048E7D0) --------------------------------------------------------
 int Player::GetActualResistance(enum CHARACTER_ATTRIBUTE_TYPE a2)
 {
-  signed int v2; // edi@1
-  Player *v3; // esi@1
-  enum CHARACTER_RACE v4; // ebx@1
-  char v6; // zf@18
-  int v7; // ebx@28
-  int result; // eax@28
-  signed int v9; // [sp+10h] [bp-8h]@1
-  signed int v10; // [sp+14h] [bp-4h]@1
-
-  v2 = 0;
-  v3 = this;
-  v10 = 0;
-  v9 = 0;
-  v4 = GetRace();
+  signed int v10 = 0; // [sp+14h] [bp-4h]@1
+  __int16* resStat;
+  int result;
+  int baseRes;
+
+  int leatherArmorSkillLevel = GetActualSkillLevel(PLAYER_SKILL_LEATHER);
   if ( CheckHiredNPCSpeciality(Enchanter) )
     v10 = 20;
   if ( (a2 == CHARACTER_ATTRIBUTE_RESIST_FIRE
      || a2 == CHARACTER_ATTRIBUTE_RESIST_AIR
      || a2 == CHARACTER_ATTRIBUTE_RESIST_WATER
      || a2 == CHARACTER_ATTRIBUTE_RESIST_EARTH)
-    && SkillToMastery(v3->pActiveSkills[9]) == 4
+    && SkillToMastery(leatherArmorSkillLevel) == 4
     && HasItemEquipped(EQUIP_ARMOUR)
     && GetEquippedItemSkillType(EQUIP_ARMOUR) == PLAYER_SKILL_LEATHER )
-    v10 += v3->pActiveSkills[9] & 0x3F;
-  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_FIRE )
-    goto LABEL_25;
-  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_AIR )
-  {
-    v2 = 1;
-LABEL_25:
-    v6 = v4 == 2;
-LABEL_26:
-    if ( v6 )
-      v9 = 5;
-    goto LABEL_28;
-  }
-  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_WATER )
-  {
-    v6 = v4 == 3;
-    v2 = 2;
-    goto LABEL_26;
-  }
-  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_EARTH )
-  {
-    v2 = 3;
-    if ( v4 == 3 )
-      v10 += 5;
-  }
-  else
-  {
-    if ( a2 != CHARACTER_ATTRIBUTE_RESIST_MIND )
-    {
-      if ( a2 != CHARACTER_ATTRIBUTE_RESIST_BODY && a2 != 33 )
-        goto LABEL_28;
-      v2 = 8;
-      v6 = v4 == 0;
-      goto LABEL_26;
-    }
-    v2 = 7;
-    if ( v4 == 1 )
-      v9 = 10;
-  }
-LABEL_28:
-  v7 = GetItemsBonus(a2);
-  result = v10 + GetMagicalBonus(a2) + v7 + v9 + *(&v3->sResFireBonus + v2) + *(&v3->sResFireBase + v2);
-  if ( v3->classType == PLAYER_CLASS_LICH )
-  {
-    if ( result > 200 )
-      result = 200;
-  }
+    v10 += leatherArmorSkillLevel & 0x3F;
+  switch (a2)
+  {
+  case CHARACTER_ATTRIBUTE_RESIST_FIRE:
+    resStat = &sResFireBonus;
+    break;
+  case CHARACTER_ATTRIBUTE_RESIST_AIR:
+    resStat = &sResAirBonus;
+    break;
+  case  CHARACTER_ATTRIBUTE_RESIST_WATER:
+    resStat = &sResWaterBonus;
+    break;
+  case CHARACTER_ATTRIBUTE_RESIST_EARTH:
+    resStat = &sResEarthBonus;
+    break;
+  case CHARACTER_ATTRIBUTE_RESIST_MIND:
+    resStat = &sResMindBonus;
+    break;
+  case CHARACTER_ATTRIBUTE_RESIST_BODY:
+  case CHARACTER_ATTRIBUTE_RESIST_SPIRIT:
+    resStat = &sResBodyBonus;
+    break;
+  }
+  baseRes = GetBaseResistance(a2);
+  result = v10 + GetMagicalBonus(a2) + baseRes + *(resStat);
   return result;
 }
 
 //----- (0048E8F5) --------------------------------------------------------
 bool Player::Recover(int dt)
 {
-  //Player *v2; // esi@1
-  signed __int64 v3; // qax@1
-  //bool result; // eax@4
-
-  //v2 = this;
-  v3 = (signed __int64)((double)(dt * _48EA46_calc_special_bonus_by_items(17)) * 0.01 + (double)dt);
+  int v3; // qax@1
+
+  v3 = (int)(dt * GetSpecialItemBonus(17) * 0.01 + dt);
 
   Log::Warning(L"Recover(dt = %u/%u - %u", dt, (uint)v3, (uint)uTimeToRecovery);
 
@@ -3119,39 +3084,40 @@
 
 //----- (0048EA1B) --------------------------------------------------------
 int Player::GetParameterBonus( int player_parameter )
-    {
+{
   int i; // eax@1
   i = 0;
   while (param_to_bonus_table[i])
-      { 
-      if (player_parameter >= param_to_bonus_table[i])
-          break;
-      ++i;    
-      }   
+  { 
+    if (player_parameter >= param_to_bonus_table[i])
+      break;
+    ++i;    
+  }   
   return parameter_to_bonus_value[i];
 }
 
 //----- (0048EA46) --------------------------------------------------------
-int Player::_48EA46_calc_special_bonus_by_items(int a2)
+int Player::GetSpecialItemBonus( int enchantmentId )
 {
   int inv_indx; // eax@3
 
-  for (int i=EQUIP_OFF_HAND; i<EQUIP_BOOK; ++i )
-      {
-      if ( !HasItemEquipped((ITEM_EQUIP_TYPE)i) )
-          continue;
+  for (int i = EQUIP_OFF_HAND; i < EQUIP_BOOK; ++i )
+  {
+    if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) )
+    {
       inv_indx = pEquipment.pIndices[i]  - 1;
-      if (a2==17)
-          {
-          if ((pInventoryItemList[inv_indx].uSpecEnchantmentType==17)||(pInventoryItemList[inv_indx].uItemID==533)) //Elven Chainmail+Increases rate of Recovery
-              return 50;
-          }
-      if (a2==24)
-          {
-          if (pInventoryItemList[inv_indx].uSpecEnchantmentType==24) //Increased Knockback.
-              return 5;
-          }
+      if (enchantmentId == 17)
+      {
+        if ((pInventoryItemList[inv_indx].uSpecEnchantmentType==17) || (pInventoryItemList[inv_indx].uItemID == 533)) //Elven Chainmail+Increases rate of Recovery
+          return 50;
       }
+      if (enchantmentId == 24)     //XXX: never actually used on mm7
+      {
+        if (pInventoryItemList[inv_indx].uSpecEnchantmentType == 24) //Increased Knockback.
+          return 5;
+      }
+    }
+  }
   return 0;
 }
 
--- a/Player.h	Tue Sep 10 03:25:28 2013 +0200
+++ b/Player.h	Tue Sep 10 04:08:15 2013 +0200
@@ -518,7 +518,7 @@
   void RandomizeName();
   unsigned int GetMajorConditionIdx();
   int GetParameterBonus(int player_parameter);
-  int _48EA46_calc_special_bonus_by_items(int a2);
+  int GetSpecialItemBonus(int enchantmentId);
   int GetItemsBonus(enum CHARACTER_ATTRIBUTE_TYPE attr, bool a3 = false);
   int GetMagicalBonus(enum CHARACTER_ATTRIBUTE_TYPE a2);
   int GetActualSkillLevel(PLAYER_SKILL_TYPE uSkillType);