diff Player.cpp @ 1709:8251e59fd7c1

ITEM_ENCHANTED to ITEM_HARDENED, created helper functions to get params from itemtable for ItemGens
author Grumpy7
date Tue, 24 Sep 2013 07:29:55 +0200
parents f8414042db1f
children 0f6cd60ca987
line wrap: on
line diff
--- a/Player.cpp	Mon Sep 23 07:07:06 2013 +0200
+++ b/Player.cpp	Tue Sep 24 07:29:55 2013 +0200
@@ -507,15 +507,15 @@
     {
       for ( i = 0; i < enchant_count; ++i )
       {
-        if (!(pInventoryItemList[item_index_tabl[i]].uAttributes&ITEM_ENCHANTED))
-          pInventoryItemList[item_index_tabl[rand() % avalible_items]].uAttributes |= ITEM_ENCHANTED; 
+        if (!(pInventoryItemList[item_index_tabl[i]].uAttributes&ITEM_HARDENED))
+          pInventoryItemList[item_index_tabl[rand() % avalible_items]].uAttributes |= ITEM_HARDENED; 
       }
     }
     else
     {
       for ( i = 0; i < avalible_items; ++i )
       {
-          pInventoryItemList[item_index_tabl[i]].uAttributes |= ITEM_ENCHANTED;
+          pInventoryItemList[item_index_tabl[i]].uAttributes |= ITEM_HARDENED;
       }
     }
   }
@@ -1008,7 +1008,7 @@
   unsigned int slot_width; // [sp+14h] [bp+4h]@1
 
   item_in_slot = &this->pInventoryItemList[pInventoryMatrix[index]-1];  
-  item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[item_in_slot->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+  item_texture = pIcons_LOD->LoadTexturePtr(item_in_slot->GetIconName(), TEXTURE_16BIT_PALETTE);
   item_in_slot->Reset();
   slot_width = GetSizeInInventorySlots(item_texture->uTextureWidth);
   slot_height = GetSizeInInventorySlots(item_texture->uTextureHeight);
@@ -1041,7 +1041,7 @@
 
   merchantLevel = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
   idemId = pItem->uItemID;
-  equipType = pItemsTable->pItems[idemId].uEquipType;
+  equipType = pItem->GetItemEquipType();
   itemValue = pItem->GetValue();
 
   switch (building_type)
@@ -1160,10 +1160,10 @@
   unsigned __int16 v2; // ax@1
   int v5; // edi@7
 
-  ItemDesc* v7 = &pItemsTable->pItems[pItem->uItemID];
-  if (CheckHiredNPCSpeciality(Smith) && v7->uEquipType <= 2 ||
-      CheckHiredNPCSpeciality(Armorer) && v7->uEquipType >= 3 && v7->uEquipType <= 9 ||
-      CheckHiredNPCSpeciality(Alchemist) && v7->uEquipType >= 9 )
+  ITEM_EQUIP_TYPE equipType = pItem->GetItemEquipType();
+  if (CheckHiredNPCSpeciality(Smith) && equipType <= 2 ||
+      CheckHiredNPCSpeciality(Armorer) && equipType >= 3 && equipType <= 9 ||
+      CheckHiredNPCSpeciality(Alchemist) && equipType >= 9 )
     return true;
 
   v2 = GetActualSkillLevel(PLAYER_SKILL_REPAIR);
@@ -1172,7 +1172,7 @@
 
   int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5);
   v5 = multiplier * (v2 & 0x3F);
-  return v5 >= v7->uItemID_Rep_St;
+  return v5 >= pItemsTable->pItems[pItem->uItemID].uItemID_Rep_St;
 }
 
 //----- (004911F3) --------------------------------------------------------
@@ -1620,8 +1620,7 @@
       if ( this->HasItemEquipped(EQUIP_OFF_HAND) )
       {
         ItemGen *offHandItemGen = (ItemGen *)&this->pInventoryItemList[this->pEquipment.uShield - 1];
-        int itemId = offHandItemGen->uItemID;
-        if ( pItemsTable->pItems[itemId].uEquipType != EQUIP_SHIELD )
+        if ( offHandItemGen->GetItemEquipType() != EQUIP_SHIELD )
         {
           offHndWpnDmg = CalculateMeleeDmgToEnemyWithWeapon(offHandItemGen, uTargetActorID, false);
         }
@@ -1957,13 +1956,13 @@
 //----- (0048D62C) --------------------------------------------------------
 ITEM_EQUIP_TYPE Player::GetEquippedItemEquipType(ITEM_EQUIP_TYPE uEquipSlot)
 {
-  return pItemsTable->pItems[pInventoryItemList[pEquipment.pIndices[uEquipSlot] - 1].uItemID].uEquipType;
+  return pInventoryItemList[pEquipment.pIndices[uEquipSlot] - 1].GetItemEquipType();
 }
 
 //----- (0048D651) --------------------------------------------------------
 PLAYER_SKILL_TYPE Player::GetEquippedItemSkillType(ITEM_EQUIP_TYPE uEquipSlot)
 {
-  return (PLAYER_SKILL_TYPE)pItemsTable->pItems[pInventoryItemList[pEquipment.pIndices[uEquipSlot] - 1].uItemID].uSkillType;
+  return (PLAYER_SKILL_TYPE)pInventoryItemList[pEquipment.pIndices[uEquipSlot] - 1].GetPlayerSkillType();
 }
 
 //----- (0048D676) --------------------------------------------------------
@@ -1978,7 +1977,7 @@
 {
   auto i = pEquipment.pIndices[uEquipIndex];
   if (i)
-    return (~(pOwnItems[i - 1].uAttributes & ITEM_BROKEN)) != 0;
+    return !pOwnItems[i - 1].IsBroken();
   else 
     return false;
 }
@@ -2039,7 +2038,7 @@
     v7 = v6 & 0x3F;
     v8 = SkillToMastery(v6);
     itemvalue = itemToSteal->GetValue();
-    v10 = pItemsTable->pItems[itemToSteal->uItemID].uEquipType;
+    v10 = itemToSteal->GetItemEquipType();
     if ( v10 == EQUIP_OFF_HAND || v10 == EQUIP_MAIN_HAND || v10 == EQUIP_BOW )
       itemvalue *= 3;
     currMaxItemValue = StealingRandomBonuses[rand() % 5] + v7 * StealingMasteryBonuses[v8];
@@ -2125,7 +2124,7 @@
       {
         enchBonusSum += rand() % StealingEnchantmentBonusForSkill[stealingMastery] + 1;
       }
-      if ( pItemsTable->pItems[actroPtr->array_000234[3].uItemID].uEquipType != EQUIP_GOLD )
+      if ( actroPtr->array_000234[3].GetItemEquipType() != EQUIP_GOLD )
         return 2;
       enchTypePtr = &actroPtr->array_000234[3].uSpecEnchantmentType;
       if ( (int)enchBonusSum >= *enchTypePtr )
@@ -2156,7 +2155,7 @@
       int i;
       for (i = 0; i < 4; i++)
       {
-        if ( actroPtr->array_000234[i].uItemID != 0 && pItemsTable->pItems[actroPtr->array_000234[i].uItemID].uEquipType != EQUIP_GOLD )
+        if ( actroPtr->array_000234[i].uItemID != 0 && actroPtr->array_000234[i].GetItemEquipType() != EQUIP_GOLD )
           break;
       }
       if (i == 4)
@@ -2181,17 +2180,20 @@
           itemToSteal->Reset();
           carriedItemId = tempItem.uItemID;
         }
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
-        sprintf(
-          pTmpBuf2.data(),
-          pGlobalTXT_LocalizationStrings[304],   // Official                   //TODO: add a normal "%d stole %d" message
-          this->pName,
-          pItemsTable->pItems[carriedItemId].pUnidentifiedName);
-        ShowStatusBarString(pTmpBuf2.data(), 2u);
-        sub_421B2C_PlaceInInventory_or_DropPickedItem();
-        memcpy(&pParty->pPickedItem, &tempItem, sizeof(ItemGen));
-        pMouse->SetCursorBitmapFromItemID(carriedItemId);
-        return 2;
+        if (carriedItemId != 0)     // looks odd in current context, but avoids accessing zeroth element of pItemsTable->pItems
+        {
+          sub_421B2C_PlaceInInventory_or_DropPickedItem();
+          sprintf(
+            pTmpBuf2.data(),
+            pGlobalTXT_LocalizationStrings[304],   // Official                   //TODO: add a normal "%d stole %d" message
+            this->pName,
+            pItemsTable->pItems[carriedItemId].pUnidentifiedName);
+          ShowStatusBarString(pTmpBuf2.data(), 2u);
+          sub_421B2C_PlaceInInventory_or_DropPickedItem();
+          memcpy(&pParty->pPickedItem, &tempItem, sizeof(ItemGen));
+          pMouse->SetCursorBitmapFromItemID(carriedItemId);
+          return 2;
+        }
       }
     }
     sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[377], this->pName);   //%s failed to steal anything
@@ -2255,7 +2257,7 @@
       armor_indx = pEquipment.uArmor;
       if ( armor_indx )
       {
-        if ( !(pOwnItems[armor_indx-1].uAttributes & ITEM_ENCHANTED))
+        if ( !(pOwnItems[armor_indx-1].uAttributes & ITEM_HARDENED))
         {
           pOwnItems[armor_indx-1].SetBroken();
         }
@@ -2334,7 +2336,7 @@
       if ( !v4 )
         return 0;
       v48 = &this->pInventoryItemList[v46[rand() % v4]];
-      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod);
+      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + v48->GetDamageMod());
       break;
     case SPECIAL_ATTACK_BREAK_ARMOR:
       for (int i = 0; i < 16; i++ )
@@ -2350,7 +2352,7 @@
       if ( !v4 )
         return 0;
       v48 = &this->pInventoryItemList[v46[rand() % v4]];
-      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod);
+      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + v48->GetDamageMod());
       break;
     case SPECIAL_ATTACK_BREAK_WEAPON:
       for (int i = 0; i < 16; i++ )
@@ -2367,7 +2369,7 @@
       if ( !v4 )
         return 0;
       v48 = &this->pInventoryItemList[v46[rand() % v4]];
-      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod);
+      v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + v48->GetDamageMod());
       break;
     case SPECIAL_ATTACK_STEAL:
       for ( int i = 0; i < 126; i++ )
@@ -2507,7 +2509,7 @@
       case SPECIAL_ATTACK_BREAK_ANY:
       case SPECIAL_ATTACK_BREAK_ARMOR:
       case SPECIAL_ATTACK_BREAK_WEAPON:
-        if ( !(v48->uAttributes & ITEM_ENCHANTED) )
+        if ( !(v48->uAttributes & ITEM_HARDENED) )
         {
           PlaySound(SPEECH_40, 0);
           v48->SetBroken();
@@ -2609,14 +2611,14 @@
     {
       weapon = &pInventoryItemList[pEquipment.uShield - 1];
       weapon_desc = &pItemsTable->pItems[weapon->uItemID];
-      weapon_recovery = base_recovery_times_per_weapon_type[pItemsTable->pItems[weapon->uItemID].uSkillType];
+      weapon_recovery = base_recovery_times_per_weapon_type[weapon->GetPlayerSkillType()];
     }
   }
 
   uint armour_recovery = 0;
   if ( HasItemEquipped(EQUIP_ARMOUR) )
   {
-    auto armour_skill_type = pItemsTable->pItems[pInventoryItemList[pEquipment.uArmor - 1].uItemID].uSkillType;
+    auto armour_skill_type = pInventoryItemList[pEquipment.uArmor - 1].GetPlayerSkillType();
     uint base_armour_recovery = base_recovery_times_per_weapon_type[armour_skill_type];
     float multiplier;
 
@@ -2645,7 +2647,7 @@
   if (HasItemEquipped(EQUIP_OFF_HAND) && GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD)
   {
     auto shield = &pInventoryItemList[pEquipment.uShield - 1];
-    auto skill_type = pItemsTable->pItems[shield->uItemID].uSkillType;
+    auto skill_type = shield->GetPlayerSkillType();
 
     uint shield_base_recovery = base_recovery_times_per_weapon_type[skill_type];
     float multiplier = GetArmorRecoveryMultiplierFromSkillLevel(skill_type, 1.0f, 0, 0, 0);
@@ -3100,7 +3102,7 @@
     case CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS:
     case CHARACTER_ATTRIBUTE_RANGED_ATTACK:
       if ( HasItemEquipped(EQUIP_BOW) )
-        v5 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uBow-1].uItemID].uDamageMod;
+        v5 = this->pOwnItems[this->pEquipment.uBow-1].GetDamageMod();
       return v5;
       break;
 
@@ -3177,7 +3179,7 @@
         v17 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
         if ( v17 >= 0 && v17 <= 2)
         {
-          v5 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand-1].uItemID].uDamageMod;
+          v5 = this->pOwnItems[this->pEquipment.uMainHand-1].GetDamageMod();
         }
       }
       if ( getOnlyMainHandDmg || !this->HasItemEquipped(EQUIP_OFF_HAND) || (this->GetEquippedItemEquipType(EQUIP_OFF_HAND) < 0) || this->GetEquippedItemEquipType(EQUIP_OFF_HAND) > 2 )
@@ -3200,9 +3202,9 @@
         v9 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
         if ( v9 >= 0 && v9 <= 2)
         {
-          v5 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand - 1].uItemID].uDamageDice +
-            pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand - 1].uItemID].uDamageMod;
-          if ( !this->pEquipment.uShield && pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand - 1].uItemID].uSkillType == 4)
+          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)
           {
             ++v5;
           }
@@ -3215,8 +3217,8 @@
       }
       else
       {
-        v14 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uShield].uItemID].uDamageMod;
-        v15 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uShield].uItemID].uDamageDice;
+        v14 = this->pOwnItems[this->pEquipment.uShield].GetDamageMod();
+        v15 = this->pOwnItems[this->pEquipment.uShield].GetDamageDice();
         return v5 + v15 + v14;
       }
       break;
@@ -3741,7 +3743,7 @@
     {
       if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
       {
-        PLAYER_SKILL_TYPE currentItemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID].uSkillType;
+        PLAYER_SKILL_TYPE currentItemSkillType = (PLAYER_SKILL_TYPE)this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].GetPlayerSkillType();
         int currentItemSkillLevel = this->GetActualSkillLevel(currentItemSkillType);
         if ( currentItemSkillType == PLAYER_SKILL_BOW )
         {
@@ -3773,10 +3775,10 @@
     {
       if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
       {
-        int currItemId = this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID;
-        if ( pItemsTable->pItems[currItemId].uEquipType == EQUIP_MAIN_HAND || pItemsTable->pItems[currItemId].uEquipType == EQUIP_OFF_HAND )
+        ItemGen* currItemPtr = &this->pInventoryItemList[this->pEquipment.pIndices[i] - 1];
+        if ( currItemPtr->GetItemEquipType() == EQUIP_MAIN_HAND || currItemPtr->GetItemEquipType() == EQUIP_OFF_HAND )
         {
-          PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[currItemId].uSkillType;
+          PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)currItemPtr->GetPlayerSkillType();
           int currItemSkillLevel = this->GetActualSkillLevel(currItemSkillType);
           int baseSkillBonus;
           int multiplier;
@@ -4378,7 +4380,7 @@
   v73 = 1;
   if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3) )
       return;
-  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_REAGENT )
+  if ( pParty->pPickedItem.GetItemEquipType() == EQUIP_REAGENT )
   {
     if ( pParty->pPickedItem.uItemID == 160 )
     { 
@@ -4428,7 +4430,7 @@
     return;
   }
 
-  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_POTION )
+  if ( pParty->pPickedItem.GetItemEquipType() == EQUIP_POTION )
   {
       switch ( pParty->pPickedItem.uItemID )
       {
@@ -4724,7 +4726,7 @@
   }
 
 
-  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_SPELL_SCROLL )
+  if ( pParty->pPickedItem.GetItemEquipType() == EQUIP_SPELL_SCROLL )
   {
     if ( pCurrentScreen == SCREEN_CASTING )
         return;
@@ -4768,7 +4770,7 @@
     return;
   }
 
-  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_BOOK )
+  if ( pParty->pPickedItem.GetItemEquipType() == EQUIP_BOOK )
   {  
       v15 = pParty->pPickedItem.uItemID - 400;
       v72 = playerAffected->spellbook.bHaveSpell[pParty->pPickedItem.uItemID-400];//(char *)&v3->pConditions[0] + pParty->pPickedItem.uItemID + 2;
@@ -4840,7 +4842,7 @@
       return;
   }
 
-  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_MESSAGE_SCROLL )
+  if ( pParty->pPickedItem.GetItemEquipType() == EQUIP_MESSAGE_SCROLL )
   {
       if ( playerAffected->CanAct() )
       {
@@ -6238,7 +6240,7 @@
                 pParty->pIsArtifactFound[val-500] = 1;
               if ( val >= ITEM_WAND_FIRE && val <= ITEM_WAND_INCENERATION )
               {
-                item.uNumCharges = rand() % 6 + pItemsTable->pItems[item.uItemID].uDamageMod + 1;
+                item.uNumCharges = rand() % 6 + item.GetDamageMod() + 1;
                 item.uMaxCharges = LOBYTE(item.uNumCharges);
               }
               pParty->SetHoldingItem(&item);
@@ -7406,8 +7408,8 @@
     if ( !v8
       || playerPtr->pInventoryItemList[v8 - 1].IsBroken()
       || 
-      (pItemsTable->pItems[playerPtr->pInventoryItemList[v8 - 1].uItemID].uSkillType != PLAYER_SKILL_CHAIN 
-      && pItemsTable->pItems[playerPtr->pInventoryItemList[v8 - 1].uItemID].uSkillType != PLAYER_SKILL_PLATE 
+      (playerPtr->pInventoryItemList[v8 - 1].GetPlayerSkillType() != PLAYER_SKILL_CHAIN 
+      && playerPtr->pInventoryItemList[v8 - 1].GetPlayerSkillType() != PLAYER_SKILL_PLATE 
       )
       )
     {
@@ -7792,7 +7794,7 @@
             }
             v9 = tmpItem.uItemID;
             memcpy(&pParty->pPickedItem, &tmpItem, sizeof(ItemGen));
-            pMouse->SetCursorBitmap(pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName);
+            pMouse->SetCursorBitmap(pParty->pPickedItem.GetIconName());
             return;
           }
           else