changeset 1010:f73e1a219d38

player wear_item fix
author Gloval
date Sun, 19 May 2013 10:15:48 +0400
parents 446175a32a15
children f85a8305a57c
files Player.cpp
diffstat 1 files changed, 58 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Sat May 18 22:41:26 2013 +0400
+++ b/Player.cpp	Sun May 19 10:15:48 2013 +0400
@@ -112,6 +112,8 @@
 signed int player_stat_bonuses[30] = {30, 25, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, 0};
 
 
+unsigned char pEquipTypeToBodyAnchor[20] = {1, 1, 2, 3, 0, 4, 5, 6, 7, 8, 10, 9, 1, 0, 0, 0, 0, 0, 0, 0};
+
 
 unsigned short base_recovery_times_per_weapon_type[12] =
 {
@@ -1108,9 +1110,8 @@
   Player *v5; // ecx@21
   Player *v6; // ecx@22
   Player *v7; // ecx@29
-  Player *v8; // ecx@30
-  Player *v9; // ecx@37
-  Player *v10; // ecx@38
+  Player *v8; // ecx@29
+ 
   Player *v11; // ecx@45
   Player *v12; // ecx@46
   char *v13; // eax@49
@@ -1514,34 +1515,23 @@
 //----- (00492745) --------------------------------------------------------
 int Player::WearItem(unsigned int uItemID)
 {
-  signed int v2; // eax@1
-  ItemGen *v3; // edx@1
-  int v4; // edi@6
-  char *v5; // eax@6
-  char *v6; // esi@6
-
-  __debugbreak(); // sub is definetly broken
-
-  v2 = 0;
-  v3 = this->pInventoryItems;
-  while ( v3->uItemID )
-  {
-    ++v2;
-    ++v3;
-    if ( v2 >= 126 )
-    {
-      v2 = -1;
-      break;
-    }
-  }
-  if ( v2 != -1 )
-  {
-    v4 = v2 + 1;
-    v5 = (char *)this + 36 * v2;
-    v6 = &byte_4E8394[pItemsTable->pItems[uItemID].uEquipType + 4];
-    *(&this->pEquipment.uShield + (unsigned __int8)*v6) = v4;
-    *((int *)v5 + 133) = uItemID;
-    v5[556] = *v6 + 1;
+  int item_body_anch; // edi@6
+  int item_indx;
+  //find empty slot
+  for(item_indx=0;item_indx<126;++item_indx)
+      if (pInventoryItems[item_indx].uItemID==0)
+          break; 
+  if (item_indx==126) //not found
+      item_indx=-1;
+  
+  if ( item_indx != -1 )
+  {
+
+    pInventoryItems[item_indx].uItemID=uItemID;
+    item_body_anch=pEquipTypeToBodyAnchor[pItemsTable->pItems[uItemID].uEquipType];
+    pEquipment.pIndices[item_body_anch]=item_indx+1;
+    pInventoryItems[item_indx].uBodyAnchor=item_body_anch+1;
+
   }
   return 0;
 }
@@ -1969,7 +1959,7 @@
 //----- (0049107D) --------------------------------------------------------
 int Player::GetBodybuilding()
 {
-  char v1; // al@1
+  int v1; // al@1
   int v2; // ecx@1
   int v4; // eax@3
   signed int v6; // [sp-4h] [bp-4h]@2
@@ -1996,7 +1986,7 @@
 //----- (004910A8) --------------------------------------------------------
 int Player::GetMeditation()
 {
-  char v1; // al@1
+  int v1; // al@1
   int base_level; // ecx@1
   int v4; // eax@3
   signed int v6; // [sp-4h] [bp-4h]@2
@@ -2087,9 +2077,9 @@
       CheckHiredNPCSpeciality(Alchemist) && v7->uEquipType >= 9 )
     return true;
 
-  LOBYTE(v2) = GetActualSkillLevel(PLAYER_SKILL_REPAIR);
+  v2 = GetActualSkillLevel(PLAYER_SKILL_REPAIR);
   v3 = v2;
-  if ( HIBYTE(v2) & 1 )
+  if (v2 & 0x100 )
   {
     v10 = 5;
   }
@@ -2130,15 +2120,15 @@
 
   v1 = this;
   v2 = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
-  v3 = v1->pActiveSkills[22];
+  v3 = v1->pActiveSkills[PLAYER_SKILL_MERCHANT];
   v4 = v2 & 0x003F;
-  v5 = v1->pActiveSkills[22] & 0x3F;
+  v5 = v1->pActiveSkills[PLAYER_SKILL_MERCHANT] & 0x3F;
   if ( (signed int)SkillToMastery(v2) >= 4 )
     return 10000;
   v7 = GetPartyReputation();
   if ( !v4 )
     return -v7;
-  if ( HIBYTE(v3) & 1 )
+  if ( v3 & 0x100 )
   {
     v9 = 5;
   }
@@ -2167,13 +2157,13 @@
   signed int v8; // [sp-4h] [bp-10h]@4
 
   v1 = this;
-  v2 = (char)GetActualSkillLevel(PLAYER_SKILL_PERCEPTION);
-  v3 = v1->pActiveSkills[26];
+  v2 = GetActualSkillLevel(PLAYER_SKILL_PERCEPTION);
+  v3 = v1->pActiveSkills[PLAYER_SKILL_PERCEPTION];
   v4 = v2 & 0x3F;
-  v5 = v1->pActiveSkills[26] & 0x3F;
+  v5 = v1->pActiveSkills[PLAYER_SKILL_PERCEPTION] & 0x3F;
   if ( (signed int)SkillToMastery(v2) >= 4 )
     return 10000;
-  if ( HIBYTE(v3) & 1 )
+  if ( v3 & 0x100 )
   {
     v8 = 5;
   }
@@ -2202,7 +2192,7 @@
   signed int v8; // [sp-4h] [bp-14h]@6
 
   v1 = this;
-  LOBYTE(v2) = GetActualSkillLevel(PLAYER_SKILL_TRAP_DISARM);
+  v2 = GetActualSkillLevel(PLAYER_SKILL_TRAP_DISARM);
   v3 = v1->pActiveSkills[29];
   v4 = v2 & 0x3F;
   v5 = v1->pActiveSkills[29] & 0x3F;
@@ -2210,7 +2200,7 @@
     return 10000;
   if ( HasEnchantedItemEquipped(35) )
     v4 *= 2;
-  if ( HIBYTE(v3) & 1 )
+  if ( v3 & 0x100 )
   {
     v8 = 5;
   }
@@ -2238,12 +2228,12 @@
   signed int v7; // [sp-4h] [bp-Ch]@3
 
   v1 = this;
-  LOBYTE(v2) = GetActualSkillLevel(PLAYER_SKILL_LEARNING);
+  v2 = GetActualSkillLevel(PLAYER_SKILL_LEARNING);
   v3 = v1->pActiveSkills[36];
   v4 = v2 & 0x3F;
   if ( v2 )
   {
-    if ( HIBYTE(v3) & 1 )
+    if (v3 & 0x100 )
     {
       v7 = 5;
     }
@@ -2380,8 +2370,8 @@
   int v10; // eax@11
   bool result; // eax@15
   std::string v12; // [sp-18h] [bp-40h]@9
-  const char *v13; // [sp-8h] [bp-30h]@9
-  int v14; // [sp-4h] [bp-2Ch]@9
+
+
   int v15[4] = {0, 1, 2, 3}; // [sp+Ch] [bp-1Ch]@3
   //int v16; // [sp+10h] [bp-18h]@3
   //int v17; // [sp+14h] [bp-14h]@3
@@ -2596,8 +2586,6 @@
 //----- (0048CABC) --------------------------------------------------------
 int Player::GetActualEndurance()
 {
-  int v6; // ebp@5
-
   uint uActualAge = GetBaseAge() + sAgeModifier;
   uint uAgeingMultiplier = 100;
   for (uint i = 0; i < 4; ++i)
@@ -3436,10 +3424,8 @@
 //----- (0048D709) --------------------------------------------------------
 bool Player::WearsItem(int a1, signed int a2)
 {
-  int v3; // edx@2
-  Player *v4; // ecx@2
+
   int v6; // esi@5
-  int v7; // edx@6
 
   if ( a2 >= 16 )
   {
@@ -3674,24 +3660,21 @@
 //----- (0048DBB9) --------------------------------------------------------
 void Player::Heal(int amount)
 {
-  Player *v2; // esi@1
-  signed int v3; // eax@3
-
-  v2 = this;
-  if ( !this->pConditions[16] && !this->pConditions[14] )
-  {
-    v3 = GetMaxHealth();
-    if ( v2->pConditions[17] )
-      v3 /= 2;
-    v2->sHealth += amount;
-    if ( v2->sHealth > v3 )
-      v2->sHealth = v3;
-    if ( v2->pConditions[13] )
-    {
-      if ( v2->sHealth > 0 )
-      {
-        LODWORD(v2->pConditions[13]) = 0;
-        HIDWORD(v2->pConditions[13]) = 0;
+  signed int max_health; // eax@3
+
+  if ( !pConditions[Condition_Eradicated] && !pConditions[Condition_Dead] )
+  {
+    max_health = GetMaxHealth();
+    if ( pConditions[Condition_Zombie] )
+      max_health /= 2;
+    sHealth += amount;
+    if ( sHealth > max_health )
+        sHealth = max_health;
+    if ( pConditions[Condition_Unconcious] )
+    {
+      if ( sHealth > 0 )
+      {
+        pConditions[Condition_Unconcious] = 0i64;
       }
     }
   }
@@ -3710,7 +3693,7 @@
   //signed int typea; // [sp+14h] [bp+8h]@1
 
   v3 = this;
-  this->pConditions[2] = 0i64;
+  this->pConditions[Condition_Sleep] = 0i64;
   v4 = CalculateIncommingDamage(resistance, type);
   v3->sHealth -= v4;
   //typea = v4;
@@ -3720,7 +3703,7 @@
   if ( v5 < 1 )
   {
     if ( v3->sHealth + v3->uEndurance + GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE, 0) >= 1
-      || (signed __int64)v3->pPlayerBuffs[11].uExpireTime > 0 )
+      || (signed __int64)v3->pPlayerBuffs[PLAYER_BUFF_PRESERVATION].uExpireTime > 0 )
     {
       SetCondition(0xDu, 0);
     }
@@ -3769,7 +3752,6 @@
   unsigned int v15; // edx@17
   int v16; // edx@26
   unsigned int v17; // edx@27
-  Player *v18; // ecx@32
   signed int v19; // edx@38
   int *v20; // ecx@38
   signed int v21; // eax@40
@@ -4153,7 +4135,8 @@
     else
       weapon_recovery = base_recovery_times_per_weapon_type[weapon_desc->uSkillType];
   }
-  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
+  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 = &pInventoryItems[pEquipment.uShield - 1];
     auto v12_desc = &pItemsTable->pItems[v12->uItemID];