diff Player.cpp @ 1534:d4bc1cb9d953

Player::GetSkillBonus put input value in case, removed labels (introduced a bit of code duplicity)
author Grumpy7
date Sat, 07 Sep 2013 02:42:54 +0200
parents a2e1174c428b
children a18076b22fb7
line wrap: on
line diff
--- a/Player.cpp	Fri Sep 06 03:36:08 2013 +0200
+++ b/Player.cpp	Sat Sep 07 02:42:54 2013 +0200
@@ -4803,6 +4803,7 @@
   return result;
 }
 
+
 //----- (0048FC00) --------------------------------------------------------
 int Player::GetSkillBonus(enum CHARACTER_ATTRIBUTE_TYPE a2)
 {
@@ -4872,7 +4873,7 @@
   int v66; // [sp+14h] [bp-18h]@104
   int v67; // [sp+18h] [bp-14h]@104
   int v68; // [sp+1Ch] [bp-10h]@69
-  PlayerEquipment *v69; // [sp+20h] [bp-Ch]@1
+  //PlayerEquipment *v69; // [sp+20h] [bp-Ch]@1
   int skill_bonus; // [sp+24h] [bp-8h]@1
   ITEM_EQUIP_TYPE v71; // [sp+28h] [bp-4h]@1
   int a1; // [sp+34h] [bp+8h]@21
@@ -4884,7 +4885,7 @@
 
   v2 = this;
   skill_bonus = 0;
-  v69 = 0;
+  //v69 = 0;
   multiplier =0;
   arm_bonus =0;
   v71 = (ITEM_EQUIP_TYPE)0;
@@ -4910,197 +4911,195 @@
     } 
     arm_bonus=(armmaster_skill&0x3F)*multiplier;
   }
- 
-  if ( a2 == CHARACTER_ATTRIBUTE_HEALTH )
-  {
-    base_value = pBaseHealthPerLevelByClass[classType];
-    attrib_modif = GetBodybuilding();
-    return base_value * attrib_modif;
-  }
-  if ( a2 == CHARACTER_ATTRIBUTE_MANA )
-  {
-    base_value = pBaseManaPerLevelByClass[classType];
-    attrib_modif = GetMeditation();
-    return base_value * attrib_modif;
-  }
-  if ( a2 == CHARACTER_ATTRIBUTE_AC_BONUS )
-  {
-    a1b = 0;
-    v71 = (ITEM_EQUIP_TYPE)0;
-
-    for (j=0; j<16; ++j) 
-    {
-      if (pEquipment.pIndices[j]&&(!pOwnItems[ pEquipment.pIndices[j]].Broken()))
-      {
-        int curr_item =pOwnItems[pEquipment.pIndices[j]].uItemID;
-        v44=pItemsTable->pItems[curr_item].uSkillType;
-        switch (v44)
+
+  switch(a2)
+  {
+  case CHARACTER_ATTRIBUTE_HEALTH:
+    {
+      base_value = pBaseHealthPerLevelByClass[classType];
+      attrib_modif = GetBodybuilding();
+      return base_value * attrib_modif;
+    }
+    break;
+  case CHARACTER_ATTRIBUTE_MANA:
+    {
+      base_value = pBaseManaPerLevelByClass[classType];
+      attrib_modif = GetMeditation();
+      return base_value * attrib_modif;
+    }
+    break;
+  case CHARACTER_ATTRIBUTE_AC_BONUS:
+    {
+      a1b = 0;
+      v71 = (ITEM_EQUIP_TYPE)0;
+
+      for (j=0; j<16; ++j) 
+      {
+        if (pEquipment.pIndices[j]&&(!pOwnItems[ pEquipment.pIndices[j]].Broken()))
         {
-        case PLAYER_SKILL_STAFF:
-
-          lvl_avl[0]=0;
-          lvl_avl[1]=1;
-          lvl_avl[2]=0;
-          lvl_avl[3]=0;
-          break;
-        case PLAYER_SKILL_SWORD:
-        case PLAYER_SKILL_SPEAR:
-          lvl_avl[0]=0;
-          lvl_avl[1]=0;
-          lvl_avl[2]=0;
-          lvl_avl[3]=1;
-          break;
-        case PLAYER_SKILL_SHIELD:
-          a1b = 1;
-          lvl_avl[0]=1;
-          lvl_avl[1]=0;
-          lvl_avl[2]=1;
-          lvl_avl[3]=0;
-          break;
-        case PLAYER_SKILL_LEATHER:
-          v71 = (ITEM_EQUIP_TYPE)1;
-          lvl_avl[0]=1;
-          lvl_avl[1]=0;
-          lvl_avl[2]=1;
-          lvl_avl[3]=0;
-
-          break;
-        case PLAYER_SKILL_CHAIN:
-          a1b = 1;
-          lvl_avl[0]=1;
-          lvl_avl[1]=0;
-          lvl_avl[2]=0;
-          lvl_avl[3]=0;
-          break;
-        case PLAYER_SKILL_PLATE:
-          a1b = 1; 
-          lvl_avl[0]=1;
-          lvl_avl[1]=0;
-          lvl_avl[2]=0;
-          lvl_avl[3]=0;
-          break;
-        default:
-          continue;
-        }
-
-        v50= GetActualSkillLevel((PLAYER_SKILL_TYPE)v44);
-        v51 = v50;
-        v52 = SkillToMastery(v50);
-        v53 = v51 & 0x3F;
-        for ( i = 0; i < (signed int)v52; ++i )
-        {
-          if ( lvl_avl[i] )
-            skill_bonus += v53;
+          int curr_item =pOwnItems[pEquipment.pIndices[j]].uItemID;
+          v44=pItemsTable->pItems[curr_item].uSkillType;
+          switch (v44)
+          {
+          case PLAYER_SKILL_STAFF:
+
+            lvl_avl[0]=0;
+            lvl_avl[1]=1;
+            lvl_avl[2]=0;
+            lvl_avl[3]=0;
+            break;
+          case PLAYER_SKILL_SWORD:
+          case PLAYER_SKILL_SPEAR:
+            lvl_avl[0]=0;
+            lvl_avl[1]=0;
+            lvl_avl[2]=0;
+            lvl_avl[3]=1;
+            break;
+          case PLAYER_SKILL_SHIELD:
+            a1b = 1;
+            lvl_avl[0]=1;
+            lvl_avl[1]=0;
+            lvl_avl[2]=1;
+            lvl_avl[3]=0;
+            break;
+          case PLAYER_SKILL_LEATHER:
+            v71 = (ITEM_EQUIP_TYPE)1;
+            lvl_avl[0]=1;
+            lvl_avl[1]=0;
+            lvl_avl[2]=1;
+            lvl_avl[3]=0;
+
+            break;
+          case PLAYER_SKILL_CHAIN:
+            a1b = 1;
+            lvl_avl[0]=1;
+            lvl_avl[1]=0;
+            lvl_avl[2]=0;
+            lvl_avl[3]=0;
+            break;
+          case PLAYER_SKILL_PLATE:
+            a1b = 1; 
+            lvl_avl[0]=1;
+            lvl_avl[1]=0;
+            lvl_avl[2]=0;
+            lvl_avl[3]=0;
+            break;
+          default:
+            continue;
+          }
+
+          v50= GetActualSkillLevel((PLAYER_SKILL_TYPE)v44);
+          v51 = v50;
+          v52 = SkillToMastery(v50);
+          v53 = v51 & 0x3F;
+          for ( i = 0; i < (signed int)v52; ++i )
+          {
+            if ( lvl_avl[i] )
+              skill_bonus += v53;
+          }
         }
       }
-    }
-
-    lvl_avl[0]=1;
-    lvl_avl[1]=1;
-    lvl_avl[2]=1;
-    lvl_avl[3]=0;
-
-    v55 = GetActualSkillLevel(PLAYER_SKILL_DODGE);
-    v56 = v55;
-    v57 = SkillToMastery(v55);
-    if ( !a1b && (!v71 || v57 == 4) )
-    {
-      v58 = v56 & 0x3F;
-      for ( j = 0; j < (signed int)v57; ++j )
-      {
-        if ( lvl_avl[j] )
-          skill_bonus += v58;
-      }
-    }
-    return skill_bonus;
-  }
-
-	if (a2 == CHARACTER_ATTRIBUTE_ATTACK)
-  {
-    if ( v2->IsUnarmed() == 1 )
-    {
-      v33 = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
-      v34 = v33;
-      if ( !v33 )
-        return skill_bonus;
-      if ( SkillToMastery(v33) >= 3 )
-        multiplier = 2;
-      else 
-        multiplier=1;
-      v30 = multiplier * (v34 & 0x3F);
-      return arm_bonus + v30;
-    }
-    v35 = (ITEM_EQUIP_TYPE)0;
-    v68 = 0;
-    for (i=0; i<16 ; ++i)
-    {
-      if ( v2->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
-      {
-        v37 = v2->pEquipment.pIndices[i]-1;
-        if ( pItemsTable->pItems[v37].uEquipType <= EQUIP_MAIN_HAND)
-          break;
-      }
-    }
-    if ( i >= 16 )
+
+      lvl_avl[0]=1;
+      lvl_avl[1]=1;
+      lvl_avl[2]=1;
+      lvl_avl[3]=0;
+
+      v55 = GetActualSkillLevel(PLAYER_SKILL_DODGE);
+      v56 = v55;
+      v57 = SkillToMastery(v55);
+      if ( !a1b && (!v71 || v57 == 4) )
+      {
+        v58 = v56 & 0x3F;
+        for ( j = 0; j < (signed int)v57; ++j )
+        {
+          if ( lvl_avl[j] )
+            skill_bonus += v58;
+        }
+      }
       return skill_bonus;
-
-    v38 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v37].uSkillType;
-    a1a = v2->GetActualSkillLevel(v38);
-    v39=  SkillToMastery(a1a);
-    v71 = (ITEM_EQUIP_TYPE)0;
-    switch (v38)
-    {
-    case PLAYER_SKILL_STAFF:
-      v71 = (ITEM_EQUIP_TYPE)1;
-      if ( v39 == 4 )
-      {
-        v40 = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
-        v41 = v40;
-
-        if ( v40 )
+    }
+    break;
+  case CHARACTER_ATTRIBUTE_ATTACK:
+    {
+      if ( v2->IsUnarmed() == 1 )
+      {
+        v33 = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
+        v34 = v33;
+        if ( !v33 )
+          return skill_bonus;
+        if ( SkillToMastery(v33) >= 3 )
+          multiplier = 2;
+        else 
+          multiplier=1;
+        v30 = multiplier * (v34 & 0x3F);
+        return arm_bonus + v30;
+      }
+      v35 = (ITEM_EQUIP_TYPE)0;
+      v68 = 0;
+      for (i=0; i<16 ; ++i)
+      {
+        if ( v2->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
         {
-          if ( SkillToMastery(v40) >= 3 )
-            multiplier = 2;
-          else 
-            multiplier=1;
-          v68 = multiplier * (v41 & 0x3F);
+          v37 = v2->pEquipment.pIndices[i]-1;
+          if ( pItemsTable->pItems[v37].uEquipType <= EQUIP_MAIN_HAND)
+            break;
         }
       }
-      break;
-    case PLAYER_SKILL_SWORD:
-    case PLAYER_SKILL_DAGGER:
-    case PLAYER_SKILL_AXE:
-    case PLAYER_SKILL_SPEAR:
-    case PLAYER_SKILL_MACE:
-      v71 = (ITEM_EQUIP_TYPE)1;
-      break;
-    case PLAYER_SKILL_BLASTER:
-
-      switch (v39)
-      {
-      case 0: multiplier=1; break;
-      case 1: multiplier=3; break;
-      case 3: multiplier=3; break;
-      case 4: multiplier=5; break;
-      }
-      v5 = multiplier;
-      return v5 * (a1a & 0x3F);
-      break;
-    }
-
-    v30 = v68 + v71 * (a1a & 0x3F);
-    return (int)((char *)v69 + v30);
-  }
-
-
-	if ( a2 != 9 )
-  {
-    if ( a2 <= CHARACTER_ATTRIBUTE_ATTACK )
-      return skill_bonus;
-    if ( a2 > CHARACTER_ATTRIBUTE_MELEE_DMG_MAX )
-    {
-      if ( a2 != CHARACTER_ATTRIBUTE_RANGED_ATTACK )
+      if ( i >= 16 )
         return skill_bonus;
+
+      v38 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v37].uSkillType;
+      a1a = v2->GetActualSkillLevel(v38);
+      v39=  SkillToMastery(a1a);
+      v71 = (ITEM_EQUIP_TYPE)0;
+      switch (v38)
+      {
+      case PLAYER_SKILL_STAFF:
+        v71 = (ITEM_EQUIP_TYPE)1;
+        if ( v39 == 4 )
+        {
+          v40 = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
+          v41 = v40;
+
+          if ( v40 )
+          {
+            if ( SkillToMastery(v40) >= 3 )
+              multiplier = 2;
+            else 
+              multiplier=1;
+            v68 = multiplier * (v41 & 0x3F);
+          }
+        }
+        break;
+      case PLAYER_SKILL_SWORD:
+      case PLAYER_SKILL_DAGGER:
+      case PLAYER_SKILL_AXE:
+      case PLAYER_SKILL_SPEAR:
+      case PLAYER_SKILL_MACE:
+        v71 = (ITEM_EQUIP_TYPE)1;
+        break;
+      case PLAYER_SKILL_BLASTER:
+
+        switch (v39)
+        {
+        case 0: multiplier=1; break;
+        case 1: multiplier=3; break;
+        case 3: multiplier=3; break;
+        case 4: multiplier=5; break;
+        }
+        v5 = multiplier;
+        return v5 * (a1a & 0x3F);
+        break;
+      }
+
+      v30 = v68 + v71 * (a1a & 0x3F);
+      return arm_bonus + v30;
+    }
+    break;
+
+  case CHARACTER_ATTRIBUTE_RANGED_ATTACK:
+    {
       v71 = (ITEM_EQUIP_TYPE)0;
       v9 = &v2->pEquipment;
       while ( 1 )
@@ -5127,116 +5126,134 @@
       if ( (signed int)SkillToMastery(a1) >= 4 )
       {
         v62 = 5;
-        goto LABEL_31;
+        v15 = v62;
+        v16 = v14;
+        return v15 * (v16 & 0x3F);
       }
       if ( (signed int)SkillToMastery(a1) >= 3 )
       {
         v62 = 3;
-        goto LABEL_31;
+        v15 = v62;
+        v16 = v14;
+        return v15 * (v16 & 0x3F);
       }
       if ( (signed int)SkillToMastery(a1) < 2 )
-        goto LABEL_32;
-      goto LABEL_30;
-    }
-    if ( v2->IsUnarmed() )
-    {
-      LOBYTE(v18) = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
-      v14 = v18;
-      if ( !v18 )
-        return skill_bonus;
-      v15 = 0;
-      v19 = SkillToMastery(v18);
-      if ( (signed int)v19 < 3 )
-      {
-        if ( (signed int)v19 >= 2 )
-          v15 = 1;
-LABEL_32:
+      {
+        v16 = v14;
+        return v15 * (v16 & 0x3F);
+      }
+      v62 = 2;
+      v15 = v62;
+      v16 = v14;
+      return v15 * (v16 & 0x3F);
+    }
+    break;
+
+  case CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS:
+    {
+      if ( v2->IsUnarmed() )
+      {
+        LOBYTE(v18) = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
+        v14 = v18;
+        if ( !v18 )
+          return skill_bonus;
+        v15 = 0;
+        v19 = SkillToMastery(v18);
+        if ( (signed int)v19 < 3 )
+        {
+          if ( (signed int)v19 >= 2 )
+            v15 = 1;
+          v16 = v14;
+          return v15 * (v16 & 0x3F);
+        }
+        v62 = 2;
+        v15 = v62;
         v16 = v14;
         return v15 * (v16 & 0x3F);
       }
-LABEL_30:
-      v62 = 2;
-LABEL_31:
-      v15 = v62;
-      goto LABEL_32;
-    }
-    v20 = (ITEM_EQUIP_TYPE)0;
-    while ( 1 )
-    {
-      if ( v2->HasItemEquipped(v20) )
-      {
-        v22 = this->pInventoryItemList[this->pEquipment.pIndices[v20]].uItemID;
-        if ( pItemsTable->pItems[v22].uEquipType <= 1u )
-          break;
-      }
-      v20 = (ITEM_EQUIP_TYPE)((int)v20 + 1);
-      if ( (signed int)v20 >= 16 )
-        return skill_bonus;
-    }
-    v71 = (ITEM_EQUIP_TYPE)0;
-    v23 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v22].uSkillType;
-    LOBYTE(v24) = v2->GetActualSkillLevel(v23);
-    v25 = v24;
-    v26 = SkillToMastery(v24);
-    if ( !v23 )
-    {
-      if ( (signed int)SkillToMastery(v25) >= 4 )
-      {
-        LOBYTE(v31) = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
-        LOBYTE(v25) = v31;
-        if ( v31 )
+      v20 = (ITEM_EQUIP_TYPE)0;
+      while ( 1 )
+      {
+        if ( v2->HasItemEquipped(v20) )
         {
-          v15 = 0;
-          v32 = SkillToMastery(v31);
-          if ( (signed int)v32 < 3 )
+          v22 = this->pInventoryItemList[this->pEquipment.pIndices[v20]].uItemID;
+          if ( pItemsTable->pItems[v22].uEquipType <= 1u )
+            break;
+        }
+        v20 = (ITEM_EQUIP_TYPE)((int)v20 + 1);
+        if ( (signed int)v20 >= 16 )
+          return skill_bonus;
+      }
+      v71 = (ITEM_EQUIP_TYPE)0;
+      v23 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v22].uSkillType;
+      LOBYTE(v24) = v2->GetActualSkillLevel(v23);
+      v25 = v24;
+      v26 = SkillToMastery(v24);
+      if ( v23 == PLAYER_SKILL_STAFF)
+      {
+        if ( (signed int)SkillToMastery(v25) >= 4 )
+        {
+          LOBYTE(v31) = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
+          LOBYTE(v25) = v31;
+          if ( v31 )
           {
-            if ( (signed int)v32 >= 2 )
-              v15 = 1;
+            v15 = 0;
+            v32 = SkillToMastery(v31);
+            if ( (signed int)v32 < 3 )
+            {
+              if ( (signed int)v32 >= 2 )
+                v15 = 1;
+            }
+            else
+            {
+              v15 = 2;
+            }
+            v16 = v25;
+            return v15 * (v16 & 0x3F);
           }
-          else
-          {
-            v15 = 2;
-          }
-          v16 = v25;
-          return v15 * (v16 & 0x3F);
+        }
+        v30 = v71 * (v25 & 0x3F);
+        return arm_bonus + v30;
+      }
+      if ( v23 == PLAYER_SKILL_DAGGER )
+      {
+        v29 = SkillToMastery(v25);
+        v28 = __OFSUB__(v29, 4);
+        v27 = ((v29 - 4) & 0x80000000u) != 0;
+      }
+      else
+      {
+        if ( v23 <= PLAYER_SKILL_DAGGER )
+        {
+          v30 = v71 * (v25 & 0x3F);
+          return arm_bonus + v30;
         }
-      }
-      goto LABEL_55;
-    }
-    if ( v23 == PLAYER_SKILL_DAGGER )
-    {
-      v29 = SkillToMastery(v25);
-      v28 = __OFSUB__(v29, 4);
-      v27 = ((v29 - 4) & 0x80000000u) != 0;
-    }
-    else
-    {
-      if ( v23 <= PLAYER_SKILL_DAGGER )
-        goto LABEL_55;
-      if ( v23 > PLAYER_SKILL_SPEAR )
-      {
-        if ( v23 == PLAYER_SKILL_MACE )
+        if ( v23 > PLAYER_SKILL_SPEAR )
         {
-          v28 = __OFSUB__(v26, 2);
-          v27 = v26 - 2 < 0;
-          goto LABEL_53;
+          if ( v23 == PLAYER_SKILL_MACE )
+          {
+            v28 = __OFSUB__(v26, 2);
+            v27 = v26 - 2 < 0;
+            if ( !(v27 ^ v28) )
+              v71 = (ITEM_EQUIP_TYPE)1;
+            v30 = v71 * (v25 & 0x3F);
+            return arm_bonus + v30;
+          }
+          v30 = v71 * (v25 & 0x3F);
+          return arm_bonus + v30;
         }
-LABEL_55:
-        v30 = v71 * (v25 & 0x3F);
-        return (int)((char *)v69 + v30);
-      }
-      v28 = __OFSUB__(v26, 3);
-      v27 = v26 - 3 < 0;
-    }
-LABEL_53:
-    if ( !(v27 ^ v28) )
-      v71 = (ITEM_EQUIP_TYPE)1;
-    goto LABEL_55;
+        v28 = __OFSUB__(v26, 3);
+        v27 = v26 - 3 < 0;
+      }
+      if ( !(v27 ^ v28) )
+        v71 = (ITEM_EQUIP_TYPE)1;
+      v30 = v71 * (v25 & 0x3F);
+      return arm_bonus + v30;
+    }
+  default:
+    return 0;
   }
     
-  
-  assert(false && "Unknown attribute!");
-  return 0;
 }
 
 //----- (00490109) --------------------------------------------------------