changeset 1714:bafc79e65a4d

Item getter functions to reduce the number of ugly array accesses, fixing a bug with Player::setrecoverytime
author Grumpy7
date Wed, 25 Sep 2013 07:11:16 +0200
parents 0f6cd60ca987
children 8da2af197e11
files Player.cpp Player.h
diffstat 2 files changed, 179 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Tue Sep 24 07:32:24 2013 +0200
+++ b/Player.cpp	Wed Sep 25 07:11:16 2013 +0200
@@ -1608,7 +1608,7 @@
   {
     if ( HasItemEquipped(EQUIP_MAIN_HAND) )
     {
-      ItemGen *mainHandItemGen = &this->pInventoryItemList[this->pEquipment.uMainHand-1];
+      ItemGen *mainHandItemGen = this->GetMainHandItem();
       int itemId = mainHandItemGen->uItemID;
       bool addOneDice = false;
       if ( pItemsTable->pItems[itemId].uSkillType == PLAYER_SKILL_SPEAR && !this->pEquipment.uShield )
@@ -1695,8 +1695,8 @@
   int v6; // edi@4
   int v7; // edi@4
 
-  v2 = *(int *)&this->pInventoryItemList[this->pEquipment.uMainHand-1];
-  if ( v2 < ITEM_BLASTER || v2 > ITEM_LASER_RIFLE )
+  ItemGen* mainHandItem = GetMainHandItem();
+  if ( mainHandItem != nullptr && ( mainHandItem->uItemID < ITEM_BLASTER || mainHandItem->uItemID > ITEM_LASER_RIFLE ))
   {
     v4 = GetActualAccuracy();
     v5 = GetParameterBonus(v4);
@@ -1795,23 +1795,19 @@
 //----- (0048D2EA) --------------------------------------------------------
 char *Player::GetMeleeDamageString()
 {
-  signed int itemid; // eax@1
   int min_damage; // edi@3
   int max_damage; // eax@3
 
   static char player__getmeleedamagestring_static_buff[40]; // idb
 
-  if (pEquipment.uMainHand >= 0)
-  {
-    itemid = pOwnItems[this->pEquipment.uMainHand-1].uItemID;
-  }
-
-  if (pEquipment.uMainHand >= 0 && ( itemid >= 135 ) && ( itemid <= 159 ))
+  ItemGen* mainHandItem = GetMainHandItem();
+
+  if (mainHandItem != nullptr && ( mainHandItem->uItemID >= 135 ) && ( mainHandItem->uItemID <= 159 ))
   {
     strcpy(player__getmeleedamagestring_static_buff, pGlobalTXT_LocalizationStrings[595]); //"Wand"
     return player__getmeleedamagestring_static_buff;
   }
-  else if (pEquipment.uMainHand >= 0 && (itemid == ITEM_BLASTER || itemid == ITEM_LASER_RIFLE))
+  else if (mainHandItem != nullptr && (mainHandItem->uItemID == ITEM_BLASTER || mainHandItem->uItemID == ITEM_LASER_RIFLE))
   {
     min_damage = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MIN, true);
     max_damage = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MAX, true);
@@ -1835,23 +1831,19 @@
 //----- (0048D396) --------------------------------------------------------
 char *Player::GetRangedDamageString()
 {
-    signed int itemid; // eax@1
     int min_damage; // edi@3
     int max_damage; // eax@3
 
     static char player__getrangeddamagestring_static_buff[40]; // idb
 
-    if (pEquipment.uMainHand >= 0)
-    {
-      itemid = pOwnItems[this->pEquipment.uMainHand-1].uItemID;
-    }
-
-    if (pEquipment.uMainHand >= 0 && ( itemid >= 135 ) && ( itemid <= 159 ))
+    ItemGen* mainHandItem = GetMainHandItem();
+
+    if (mainHandItem != nullptr && ( mainHandItem->uItemID >= 135 ) && ( mainHandItem->uItemID <= 159 ))
     {
       strcpy(player__getrangeddamagestring_static_buff, pGlobalTXT_LocalizationStrings[595]); //"Wand"
       return player__getrangeddamagestring_static_buff;
     }
-    else if (pEquipment.uMainHand >= 0 && (itemid == ITEM_BLASTER || itemid == ITEM_LASER_RIFLE))
+    else if (mainHandItem != nullptr && (mainHandItem->uItemID == ITEM_BLASTER || mainHandItem->uItemID == ITEM_LASER_RIFLE))
     {
       min_damage = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MIN, true);
       max_damage = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MAX, true);
@@ -1933,11 +1925,12 @@
         break;
     }
   }
-  if (( dmg_type == DMGT_PHISYCAL ) && ( pEquipment.uArmor ))
-  {
-      if (!pOwnItems[pEquipment.uArmor - 1].IsBroken()) 
-      {
-        armor_skill = GetEquippedItemSkillType(EQUIP_ARMOUR);
+  ItemGen* equippedArmor = GetArmorItem();
+  if (( dmg_type == DMGT_PHISYCAL ) && ( equippedArmor != nullptr ))
+  {
+      if (!equippedArmor->IsBroken()) 
+      {
+        armor_skill = equippedArmor->GetPlayerSkillType();
         if ( armor_skill==PLAYER_SKILL_PLATE )
         {
           if ( SkillToMastery(pActiveSkills[PLAYER_SKILL_PLATE]) >= 3 )
@@ -1956,20 +1949,20 @@
 //----- (0048D62C) --------------------------------------------------------
 ITEM_EQUIP_TYPE Player::GetEquippedItemEquipType(ITEM_EQUIP_TYPE uEquipSlot)
 {
-  return pInventoryItemList[pEquipment.pIndices[uEquipSlot] - 1].GetItemEquipType();
+  return GetNthEquippedIndexItem(uEquipSlot)->GetItemEquipType();
 }
 
 //----- (0048D651) --------------------------------------------------------
 PLAYER_SKILL_TYPE Player::GetEquippedItemSkillType(ITEM_EQUIP_TYPE uEquipSlot)
 {
-  return (PLAYER_SKILL_TYPE)pInventoryItemList[pEquipment.pIndices[uEquipSlot] - 1].GetPlayerSkillType();
+  return (PLAYER_SKILL_TYPE)GetNthEquippedIndexItem(uEquipSlot)->GetPlayerSkillType();
 }
 
 //----- (0048D676) --------------------------------------------------------
 bool Player::IsUnarmed()
 {
   return !HasItemEquipped(EQUIP_MAIN_HAND) &&
-        (!HasItemEquipped(EQUIP_OFF_HAND) || GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD);
+        (!HasItemEquipped(EQUIP_OFF_HAND) || GetOffHandItem()->GetItemEquipType() == EQUIP_SHIELD);
 }
 
 //----- (0048D6AA) --------------------------------------------------------
@@ -1988,7 +1981,7 @@
   for (uint i = 0; i < 16; ++i)
   {
     if (HasItemEquipped((ITEM_EQUIP_TYPE)i) &&
-      pOwnItems[pEquipment.pIndices[i]-1].uSpecEnchantmentType == uEnchantment)
+      GetNthEquippedIndexItem(i)->uSpecEnchantmentType == uEnchantment)
       return true;
   }
   return false;
@@ -1997,7 +1990,7 @@
 //----- (0048D709) --------------------------------------------------------
 bool Player::WearsItem( int item_id, ITEM_EQUIP_TYPE equip_type )
 {
-  return ( HasItemEquipped(equip_type) && pInventoryItemList[pEquipment.pIndices[equip_type - 1]].uItemID == item_id );
+  return ( HasItemEquipped(equip_type) && GetNthEquippedIndexItem(equip_type)->uItemID == item_id );
 }
 
 bool Player::WearsItemAnyWhere(int item_id)
@@ -2230,7 +2223,6 @@
 int Player::ReceiveDamage( signed int amount, DAMAGE_TYPE dmg_type )
     {
   signed int recieved_dmg; // eax@1
-  unsigned int armor_indx; // eax@8
   bool broke_armor;
  
   SetAsleep(false);
@@ -2252,12 +2244,12 @@
     }
     if (broke_armor )
     {
-      armor_indx = pEquipment.uArmor;
-      if ( armor_indx )
-      {
-        if ( !(pOwnItems[armor_indx-1].uAttributes & ITEM_HARDENED))
+      ItemGen* equippedArmor = GetArmorItem();
+      if ( equippedArmor != nullptr )
+      {
+        if ( !(equippedArmor->uAttributes & ITEM_HARDENED))
         {
-          pOwnItems[armor_indx-1].SetBroken();
+          equippedArmor->SetBroken();
         }
       }
     }
@@ -2578,9 +2570,8 @@
   {
     if ( HasItemEquipped(EQUIP_BOW) )
     {
-      weapon = &pInventoryItemList[pEquipment.uBow - 1];
-      weapon_desc = &pItemsTable->pItems[weapon->uItemID];
-      weapon_recovery = base_recovery_times_per_weapon_type[weapon_desc->uSkillType];
+      weapon = GetBowItem();
+      weapon_recovery = base_recovery_times_per_weapon_type[weapon->GetPlayerSkillType()];
     }
   }
   else if ( IsUnarmed() == 1 && GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0)
@@ -2589,26 +2580,22 @@
   }
   else if ( HasItemEquipped(EQUIP_MAIN_HAND) )
   {
-    weapon = &pInventoryItemList[pEquipment.uMainHand - 1];
-    weapon_desc = &pItemsTable->pItems[weapon->uItemID];
-    if (weapon_desc->uEquipType == EQUIP_WAND)
+    weapon = GetMainHandItem();
+    if (weapon->GetItemEquipType() == EQUIP_WAND)
     {
       __debugbreak();  // looks like offset in player's inventory and wand_lut much like case in 0042ECB5
       __debugbreak();  // looks like wands were two-handed weapons once, or supposed to be. should not get here now
       weapon_recovery = pSpellDatas[wand_spell_ids[weapon->uItemID - ITEM_WAND_FIRE]].uExpertLevelRecovery;
     }
     else
-      weapon_recovery = base_recovery_times_per_weapon_type[weapon_desc->uSkillType];
+      weapon_recovery = base_recovery_times_per_weapon_type[weapon->GetPlayerSkillType()];
   }
   if (HasItemEquipped(EQUIP_OFF_HAND) && GetEquippedItemEquipType(EQUIP_OFF_HAND) != EQUIP_SHIELD) 
       // ADD: shield check because shield recovery is added later and can be accidentally doubled
   {
-    auto v12 = &pInventoryItemList[pEquipment.uShield - 1];
-    auto v12_desc = &pItemsTable->pItems[v12->uItemID];
-    if (base_recovery_times_per_weapon_type[v12_desc->uSkillType] > weapon_recovery)
-    {
-      weapon = &pInventoryItemList[pEquipment.uShield - 1];
-      weapon_desc = &pItemsTable->pItems[weapon->uItemID];
+    weapon = GetOffHandItem();
+    if (base_recovery_times_per_weapon_type[weapon->GetPlayerSkillType()] > weapon_recovery)
+    {
       weapon_recovery = base_recovery_times_per_weapon_type[weapon->GetPlayerSkillType()];
     }
   }
@@ -2616,7 +2603,7 @@
   uint armour_recovery = 0;
   if ( HasItemEquipped(EQUIP_ARMOUR) )
   {
-    auto armour_skill_type = pInventoryItemList[pEquipment.uArmor - 1].GetPlayerSkillType();
+    auto armour_skill_type = GetArmorItem()->GetPlayerSkillType();
     uint base_armour_recovery = base_recovery_times_per_weapon_type[armour_skill_type];
     float multiplier;
 
@@ -2644,8 +2631,7 @@
   uint shield_recovery = 0;
   if (HasItemEquipped(EQUIP_OFF_HAND) && GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD)
   {
-    auto shield = &pInventoryItemList[pEquipment.uShield - 1];
-    auto skill_type = shield->GetPlayerSkillType();
+    auto skill_type = GetOffHandItem()->GetPlayerSkillType();
 
     uint shield_base_recovery = base_recovery_times_per_weapon_type[skill_type];
     float multiplier = GetArmorRecoveryMultiplierFromSkillLevel(skill_type, 1.0f, 0, 0, 0);
@@ -2655,12 +2641,12 @@
   uint player_speed_recovery_reduction = GetParameterBonus(GetActualSpeed()),
        sword_axe_bow_recovery_reduction = 0;
   bool shooting_laser = false;
-  if (weapon_desc)
-  {
-    if (GetActualSkillLevel((PLAYER_SKILL_TYPE)weapon_desc->uSkillType) &&
-        (weapon_desc->uSkillType == PLAYER_SKILL_SWORD || weapon_desc->uSkillType == PLAYER_SKILL_AXE || weapon_desc->uSkillType == PLAYER_SKILL_BOW) )
-    {
-      if (SkillToMastery(pActiveSkills[weapon_desc->uSkillType]) >= 2 )  // Expert   Sword, Axe & Bow   reduce recovery
+  if (weapon != nullptr)
+  {
+    if (GetActualSkillLevel((PLAYER_SKILL_TYPE)weapon->GetPlayerSkillType()) &&
+        (weapon->GetPlayerSkillType() == PLAYER_SKILL_SWORD || weapon->GetPlayerSkillType() == PLAYER_SKILL_AXE || weapon->GetPlayerSkillType() == PLAYER_SKILL_BOW) )
+    {
+      if (SkillToMastery(pActiveSkills[weapon->GetPlayerSkillType()]) >= 2 )  // Expert   Sword, Axe & Bow   reduce recovery
         sword_axe_bow_recovery_reduction = pActiveSkills[weapon_desc->uSkillType] & 0x3F;
     }
     if (weapon_desc->uSkillType == PLAYER_SKILL_BLASTER)
@@ -2971,7 +2957,7 @@
   if (rec > uTimeToRecovery)
     uTimeToRecovery = rec;
 
-  if (pPlayers[uActiveCharacter] == this && !some_active_character)
+  if (uActiveCharacter != 0 && pPlayers[uActiveCharacter] == this && !some_active_character)
     uActiveCharacter = pParty->GetNextActiveCharacter();
 
   viewparams->bRedrawGameUI = true;
@@ -3012,21 +2998,18 @@
 //----- (0048EA46) --------------------------------------------------------
 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) )
     {
-      inv_indx = pEquipment.pIndices[i]  - 1;
       if (enchantmentId == 17)
       {
-        if ((pInventoryItemList[inv_indx].uSpecEnchantmentType == 17) || (pInventoryItemList[inv_indx].uItemID == 533)) //Elven Chainmail+Increases rate of Recovery
+        if ((GetNthEquippedIndexItem(i)->uSpecEnchantmentType == 17) || (GetNthEquippedIndexItem(i)->uItemID == 533)) //Elven Chainmail+Increases rate of Recovery
           return 50;
       }
       if (enchantmentId == 24) 
       {
-        if (pInventoryItemList[inv_indx].uSpecEnchantmentType == 24) //Increased Knockback.
+        if (GetNthEquippedIndexItem(i)->uSpecEnchantmentType == 24) //Increased Knockback.
           return 5;
       }
     }
@@ -3042,16 +3025,11 @@
   int v14; // ecx@58
   int v15; // eax@58
   int v17; // eax@62
-  int v20; // eax@69
   int v22; // eax@76
-  int v23; // edx@76
   int v25; // ecx@80
   int v26; // edi@80
-  int v31; // ebp@97
   int v32; // eax@98
-  unsigned int v33; // eax@100
   int v56; // eax@365
-  int v57; // ebx@368
   signed int v58; // [sp-4h] [bp-20h]@10
   int v61; // [sp+10h] [bp-Ch]@1
   int v62; // [sp+14h] [bp-8h]@1
@@ -3100,25 +3078,23 @@
     case CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS:
     case CHARACTER_ATTRIBUTE_RANGED_ATTACK:
       if ( HasItemEquipped(EQUIP_BOW) )
-        v5 = this->pOwnItems[this->pEquipment.uBow-1].GetDamageMod();
+        v5 = GetBowItem()->GetDamageMod();
       return v5;
       break;
 
     case CHARACTER_ATTRIBUTE_RANGED_DMG_MIN:
       if ( !HasItemEquipped(EQUIP_BOW) )
         return 0;
-      v57 = this->pOwnItems[this->pEquipment.uBow-1].uItemID;
-      v5 = pItemsTable->pItems[v57].uDamageMod;
-      v56 = pItemsTable->pItems[v57].uDamageDice;
+      v5 = GetBowItem()->GetDamageMod();
+      v56 = GetBowItem()->GetDamageDice();
       return v5 + v56;
       break;
 
     case CHARACTER_ATTRIBUTE_RANGED_DMG_MAX:
       if ( !HasItemEquipped(EQUIP_BOW) )
         return 0;
-      v20 = this->pOwnItems[this->pEquipment.uBow-1].uItemID;
-      v5 = pItemsTable->pItems[v20].uDamageDice * pItemsTable->pItems[v20].uDamageRoll;
-      v56 = pItemsTable->pItems[v20].uDamageMod;
+      v5 = GetBowItem()->GetDamageDice() * GetBowItem()->GetDamageRoll();
+      v56 = GetBowItem()->GetDamageMod();
       return v5 + v56;
 
     case CHARACTER_ATTRIBUTE_LEVEL: 
@@ -3139,17 +3115,17 @@
           v22 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
           if ( v22 >= 0 && v22 <= 2)
           {
-            v23 = this->pOwnItems[this->pEquipment.uMainHand - 1].uItemID;
-            v26 = pItemsTable->pItems[v23].uDamageRoll;
-            if ( this->pEquipment.uShield || pItemsTable->pItems[v23].uSkillType != 4 )
+            ItemGen* mainHandItem = GetMainHandItem();
+            v26 = mainHandItem->GetDamageRoll();
+            if ( GetOffHandItem() != nullptr || mainHandItem->GetPlayerSkillType() != 4 )
             {
-              v25 = pItemsTable->pItems[v23].uDamageDice;
+              v25 = mainHandItem->GetDamageDice();
             }
             else
             {
-              v25 = pItemsTable->pItems[v23].uDamageDice + 1;
+              v25 = mainHandItem->GetDamageDice() + 1;
             }
-            v5 = pItemsTable->pItems[v23].uDamageMod + v25 * v26;
+            v5 = mainHandItem->GetDamageMod() + v25 * v26;
           }
         }
         if ( getOnlyMainHandDmg || !this->HasItemEquipped(EQUIP_OFF_HAND) ||  (GetEquippedItemEquipType(EQUIP_OFF_HAND) < 0 || GetEquippedItemEquipType(EQUIP_OFF_HAND) > 2))
@@ -3158,9 +3134,9 @@
         }
         else
         {
-          v23 = this->pOwnItems[this->pEquipment.uShield - 1].uItemID;
-          v15 = pItemsTable->pItems[v23].uDamageMod;
-          v14 = pItemsTable->pItems[v23].uDamageDice * pItemsTable->pItems[v23].uDamageRoll;
+          ItemGen* offHandItem = GetOffHandItem();
+          v15 = offHandItem->GetDamageMod();
+          v14 = offHandItem->GetDamageDice() * offHandItem->GetDamageRoll();
           return v5 + v15 + v14;
         }
       }
@@ -3177,15 +3153,14 @@
         v17 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
         if ( v17 >= 0 && v17 <= 2)
         {
-          v5 = this->pOwnItems[this->pEquipment.uMainHand-1].GetDamageMod();
+          v5 = GetMainHandItem()->GetDamageMod();
         }
       }
       if ( getOnlyMainHandDmg || !this->HasItemEquipped(EQUIP_OFF_HAND) || (this->GetEquippedItemEquipType(EQUIP_OFF_HAND) < 0) || this->GetEquippedItemEquipType(EQUIP_OFF_HAND) > 2 )
         return v5;
       else
       {
-        v20 = this->pOwnItems[this->pEquipment.uShield - 1].uItemID;
-        v56 = pItemsTable->pItems[v20].uDamageMod;
+        v56 = GetOffHandItem()->GetDamageMod();
         return v5 + v56;
       }
       break;
@@ -3200,9 +3175,10 @@
         v9 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
         if ( v9 >= 0 && v9 <= 2)
         {
-          v5 = this->pOwnItems[this->pEquipment.uMainHand - 1].GetDamageDice() +
-            this->pOwnItems[this->pEquipment.uMainHand - 1].GetDamageMod();
-          if ( !this->pEquipment.uShield && this->pOwnItems[this->pEquipment.uMainHand - 1].GetPlayerSkillType() == 4)
+          ItemGen* mainHandItem = GetMainHandItem();
+          v5 = mainHandItem->GetDamageDice() +
+            mainHandItem->GetDamageMod();
+          if ( GetOffHandItem() == nullptr && mainHandItem->GetPlayerSkillType() == 4)
           {
             ++v5;
           }
@@ -3215,8 +3191,9 @@
       }
       else
       {
-        v14 = this->pOwnItems[this->pEquipment.uShield].GetDamageMod();
-        v15 = this->pOwnItems[this->pEquipment.uShield].GetDamageDice();
+        ItemGen* offHandItem = GetOffHandItem();
+        v14 = offHandItem->GetDamageMod();
+        v15 = offHandItem->GetDamageDice();
         return v5 + v15 + v14;
       }
       break;
@@ -3266,18 +3243,16 @@
       {
         if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) )
         {
-          v31 = this->pEquipment.pIndices[i] - 1;
-          currEquippedItem = &this->pInventoryItemList[v31];
+          currEquippedItem = GetNthEquippedIndexItem(i);
           if ( attr == CHARACTER_ATTRIBUTE_AC_BONUS )
           {
-            v32 = GetEquippedItemEquipType((ITEM_EQUIP_TYPE)i);
+            v32 = currEquippedItem->GetItemEquipType();
             if ( v32 >= 3 && v32 <= 11 )
             {
-              v33 = currEquippedItem->uItemID;
-              v5 += pItemsTable->pItems[v33].uDamageDice + pItemsTable->pItems[v33].uDamageMod;
+              v5 += currEquippedItem->GetDamageDice() + currEquippedItem->GetDamageMod();
             }
           }
-          if ( pItemsTable->IsMaterialNonCommon((ItemGen *)(currEquippedItem))
+          if ( pItemsTable->IsMaterialNonCommon(currEquippedItem)
             && !pItemsTable->IsMaterialSpecial(currEquippedItem) )
           {
             currEquippedItem->GetItemBonusArtifact(this, attr, &v62);
@@ -3649,10 +3624,10 @@
 
       for (int j = 0; j < 16; ++j) 
       {
-        if (pEquipment.pIndices[j] && (!pOwnItems[pEquipment.pIndices[j]].IsBroken()))
+        ItemGen* currItem = GetNthEquippedIndexItem(j);
+        if (currItem != nullptr && (!currItem->IsBroken()))
         {
-          int curr_item = pOwnItems[pEquipment.pIndices[j] - 1].uItemID;
-          PLAYER_SKILL_TYPE itemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[curr_item].uSkillType;
+          PLAYER_SKILL_TYPE itemSkillType = (PLAYER_SKILL_TYPE)currItem->GetPlayerSkillType();
           int currArmorSkillLevel = GetActualSkillLevel(itemSkillType);
           int multiplier = 0;
           switch (itemSkillType)
@@ -3710,10 +3685,10 @@
     {
       if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
       {
-        ItemDesc currItem = pItemsTable->pItems[this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID];
-        if ( currItem.uEquipType <= EQUIP_MAIN_HAND)
+        ItemGen* currItem = GetNthEquippedIndexItem(i);
+        if ( currItem->GetItemEquipType() <= EQUIP_MAIN_HAND)
         {
-          PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)currItem.uSkillType;
+          PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)currItem->GetPlayerSkillType();
           int currentItemSkillLevel = this->GetActualSkillLevel(currItemSkillType);
           if (currItemSkillType == PLAYER_SKILL_BLASTER)
           {
@@ -3741,7 +3716,7 @@
     {
       if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
       {
-        PLAYER_SKILL_TYPE currentItemSkillType = (PLAYER_SKILL_TYPE)this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].GetPlayerSkillType();
+        PLAYER_SKILL_TYPE currentItemSkillType = (PLAYER_SKILL_TYPE)GetNthEquippedIndexItem(i)->GetPlayerSkillType();
         int currentItemSkillLevel = this->GetActualSkillLevel(currentItemSkillType);
         if ( currentItemSkillType == PLAYER_SKILL_BOW )
         {
@@ -3773,7 +3748,7 @@
     {
       if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
       {
-        ItemGen* currItemPtr = &this->pInventoryItemList[this->pEquipment.pIndices[i] - 1];
+        ItemGen* currItemPtr = GetNthEquippedIndexItem(i);
         if ( currItemPtr->GetItemEquipType() == EQUIP_MAIN_HAND || currItemPtr->GetItemEquipType() == EQUIP_OFF_HAND )
         {
           PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)currItemPtr->GetPlayerSkillType();
@@ -5027,10 +5002,8 @@
   unsigned __int8 our_bit_value; // cl@25
   signed int v15; // ecx@28
   ItemGen *v16; // eax@28
-  char v17; // zf@31
   int v18; // edi@90
   DDM_DLV_Header *v19; // eax@122
-  char v20; // cl@124
   DDM_DLV_Header *v21; // eax@126
   unsigned int v22; // edi@129
   Player *v23; // esi@134
@@ -7301,7 +7274,7 @@
 //----- (0043EE77) --------------------------------------------------------
 bool Player::HasUnderwaterSuitEquipped() //the original function took the player number as a parameter. if it was 0, the whole party was checked. calls with the parameter 0 have been changed to calls to this for every player
 {
-  if (this->pEquipment.uArmor == 0 || this->pInventoryItemList[this->pEquipment.uArmor].uItemID != 604)
+  if (GetArmorItem() == nullptr || GetArmorItem()->uItemID != 604)
   {
     return false;
   }
@@ -7386,7 +7359,6 @@
 {
   Player *playerPtr; // ebx@3
   Actor *actorPtr; // esi@3
-  unsigned int v8; // eax@4
   int spellId; // eax@38
   signed int recvdMagicDmg; // eax@139
   int v72[4]; // [sp+30h] [bp-24h]@164
@@ -7401,13 +7373,13 @@
     healthBeforeRecvdDamage = playerPtr->sHealth;
     if ( PID_TYPE(uObjID) != 3 || !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) )
       return;
-    v8 = playerPtr->pEquipment.uArmor;
+    ItemGen* equippedArmor = playerPtr->GetArmorItem();
     SoundID soundToPlay;
-    if ( !v8
-      || playerPtr->pInventoryItemList[v8 - 1].IsBroken()
+    if ( !equippedArmor
+      || equippedArmor->IsBroken()
       || 
-      (playerPtr->pInventoryItemList[v8 - 1].GetPlayerSkillType() != PLAYER_SKILL_CHAIN 
-      && playerPtr->pInventoryItemList[v8 - 1].GetPlayerSkillType() != PLAYER_SKILL_PLATE 
+      (equippedArmor->GetPlayerSkillType() != PLAYER_SKILL_CHAIN 
+      && equippedArmor->GetPlayerSkillType() != PLAYER_SKILL_PLATE 
       )
       )
     {
@@ -7602,18 +7574,18 @@
         if ( playerPtr->HasEnchantedItemEquipped(69) )
           dmgToReceive >>= 1;
         if ( playerPtr->HasItemEquipped(EQUIP_ARMOUR)
-          && playerPtr->pInventoryItemList[playerPtr->pEquipment.uArmor-1].uItemID == ITEM_ARTIFACT_GOVERNORS_ARMOR )
+          && playerPtr->GetArmorItem()->uItemID == ITEM_ARTIFACT_GOVERNORS_ARMOR )
           dmgToReceive >>= 1;
         if ( playerPtr->HasItemEquipped(EQUIP_MAIN_HAND))
         {
-          int itemId = playerPtr->pInventoryItemList[playerPtr->pEquipment.uMainHand - 1].uItemID;
-          if ( itemId == ITEM_RELIC_KELEBRIM || itemId == ITEM_ARTIFACT_ELFBANE || (playerPtr->GetEquippedItemEquipType(EQUIP_MAIN_HAND) == EQUIP_SHIELD && SkillToMastery(playerPtr->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4))
+          ItemGen* mainHandItem = playerPtr->GetMainHandItem();
+          if ( mainHandItem->uItemID == ITEM_RELIC_KELEBRIM || mainHandItem->uItemID == ITEM_ARTIFACT_ELFBANE || (mainHandItem->GetItemEquipType() == EQUIP_SHIELD && SkillToMastery(playerPtr->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4))
             dmgToReceive >>= 1;
         }
         if ( playerPtr->HasItemEquipped(EQUIP_OFF_HAND))
         {
-          int itemId = playerPtr->pInventoryItemList[playerPtr->pEquipment.uShield - 1].uItemID;
-          if ( itemId == ITEM_RELIC_KELEBRIM || itemId == ITEM_ARTIFACT_ELFBANE || (playerPtr->GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD && SkillToMastery(playerPtr->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4))
+          ItemGen* offHandItem = playerPtr->GetOffHandItem();
+          if ( offHandItem->uItemID == ITEM_RELIC_KELEBRIM || offHandItem->uItemID == ITEM_ARTIFACT_ELFBANE || (offHandItem->GetItemEquipType() == EQUIP_SHIELD && SkillToMastery(playerPtr->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4))
             dmgToReceive >>= 1;
         }
       }
@@ -7978,3 +7950,76 @@
 {
   SetCondition(Condition_Dead, blockable);
 }
+
+ItemGen* Player::GetOffHandItem()
+{
+  return GetItem(&PlayerEquipment::uShield);
+}
+
+ItemGen* Player::GetMainHandItem()
+{
+  return GetItem(&PlayerEquipment::uMainHand);
+}
+
+ItemGen* Player::GetBowItem()
+{
+  return GetItem(&PlayerEquipment::uBow);
+}
+
+ItemGen* Player::GetArmorItem()
+{
+  return GetItem(&PlayerEquipment::uArmor);
+}
+
+ItemGen* Player::GetHelmItem()
+{
+  return GetItem(&PlayerEquipment::uHelm);
+}
+
+ItemGen* Player::GetBeltItem()
+{
+  return GetItem(&PlayerEquipment::uBelt);
+}
+
+ItemGen* Player::GetCloakItem()
+{
+  return GetItem(&PlayerEquipment::uCloak);
+}
+
+ItemGen* Player::GetGloveItem()
+{
+  return GetItem(&PlayerEquipment::uGlove);
+}
+
+ItemGen* Player::GetBootItem()
+{
+  return GetItem(&PlayerEquipment::uBoot);
+}
+
+ItemGen* Player::GetAmuletItem()
+{
+  return GetItem(&PlayerEquipment::uAmulet);
+}
+
+ItemGen* Player::GetNthRingItem(int ringNum)
+{
+  return GetNthEquippedIndexItem(ringNum + 10);
+}
+
+ItemGen* Player::GetNthEquippedIndexItem(int index)
+{
+  if (this->pEquipment.pIndices[index] == 0)
+  {
+    return nullptr;
+  }
+  return &this->pInventoryItemList[this->pEquipment.pIndices[index] - 1];
+}
+
+ItemGen* Player::GetItem(unsigned int PlayerEquipment::* itemPos)
+{
+  if (this->pEquipment.*itemPos == 0)
+  {
+    return nullptr;
+  }
+  return &this->pInventoryItemList[this->pEquipment.*itemPos - 1];
+}
\ No newline at end of file
--- a/Player.h	Tue Sep 24 07:32:24 2013 +0200
+++ b/Player.h	Wed Sep 25 07:11:16 2013 +0200
@@ -646,6 +646,20 @@
 
   inline bool IsMale() { return GetSexByVoice() == SEX_MALE;}
   inline bool IsFemale() { return !IsMale();}
+
+  ItemGen* GetMainHandItem();
+  ItemGen* GetOffHandItem();
+  ItemGen* GetBowItem();
+  ItemGen* GetArmorItem();
+  ItemGen* GetHelmItem();
+  ItemGen* GetBeltItem();
+  ItemGen* GetCloakItem();
+  ItemGen* GetGloveItem();
+  ItemGen* GetBootItem();
+  ItemGen* GetAmuletItem();
+  ItemGen* GetNthRingItem(int ringNum);
+  ItemGen* GetNthEquippedIndexItem(int index);
+  ItemGen* GetItem(unsigned int PlayerEquipment::* itemPos);
   __int64 pConditions[20];
   unsigned __int64 uExperience;
   char pName[16];