changeset 386:5632b38d421c

Merge
author Gloval
date Sat, 23 Feb 2013 01:50:50 +0400
parents b509ef97807a (diff) c31e87e41131 (current diff)
children 84f53d7fc96d
files
diffstat 3 files changed, 167 insertions(+), 243 deletions(-) [+]
line wrap: on
line diff
--- a/Items.cpp	Fri Feb 22 21:10:50 2013 +0000
+++ b/Items.cpp	Sat Feb 23 01:50:50 2013 +0400
@@ -26,159 +26,100 @@
 
 
 //----- (00439DF3) --------------------------------------------------------
-int ItemGen::_439DF3_get_additional_damage(int *a2, int *a3)
-{
-  int *v3; // edi@1
-  ItemGen *v4; // ebx@1
-  signed int v5; // esi@1
-  unsigned int v7; // ecx@5
-  signed int v8; // ebx@7
-  int v9; // edx@22
-  int v10; // eax@24
-  int v11; // edx@25
-  int v12; // ebx@28
-  int v13; // ebx@29
-  int v14; // ebx@30
-  int v15; // ebx@31
-  int v16; // ebx@32
-  signed int v17; // [sp-4h] [bp-10h]@24
+int ItemGen::_439DF3_get_additional_damage(int *damage_type, bool *draintargetHP)
+	{
+	*damage_type = 0;
+	if ( !uItemID )
+		return 0;
+	UpdateTempBonus(pParty->uTimePlayed);
+	if (uItemID == 501 )  //Iron Feather -sword
+		{
+		*damage_type = 1;
+		return rand() % 10 + 6;
+		}
+	if (uItemID == 507 ) //Ghoulsbane  -axe
+		{
+		*damage_type = 0;
+		return rand() % 16 + 3;
+		}
+	if ( uItemID == 510 ) //Ullyses  -bow
+		{
+		*damage_type = 2;
+		return rand() % 4 + 9;
+		}
+	if ( uItemID == 517 ) //Old Nick -dagger
+		{
+		*damage_type = 8;
+		return 8;
+		}
 
-  auto a1 = this;
-  v3 = a2;
-  v4 = a1;
-  v5 = 0;
-  *a2 = 0;
-  if ( !a1->uItemID )
-    return 0;
-  UpdateTempBonus(pParty->uTimePlayed);
-  if ( v4->uItemID == 501 )
-  {
-    *v3 = 1;
-    v10 = rand();
-    v17 = 10;
-    return v10 % v17 + 6;
-  }
-  if ( v4->uItemID == 507 )
-  {
-    *v3 = 0;
-    v11 = rand() % 16;
-    return v11 + 3;
-  }
-  v7 = 3;
-  if ( v4->uItemID == 510 )
-  {
-    *v3 = 2;
-    v9 = rand() % 4;
-    return v9 + 9;
-  }
-  if ( v4->uItemID == 517 )
-  {
-    v5 = 8;
-    *v3 = v5;
-    return v5;
-  }
-  v8 = v4->uSpecEnchantmentType;
-  if ( v8 > 46 )
-  {
-    v5 = 0;
-    *v3 = v5;
-    return v5;
-  }
-  if ( v8 == 46 )
-  {
-    *v3 = 0;
-    return rand() % 11 + 10;
-  }
-  if ( v8 > 11 )
-  {
-    v12 = v8 - 12;
-    if ( !v12 )
-    {
-      *v3 = 0;
-      return GetDiceResult(v7, 6u);
-    }
-    v13 = v12 - 1;
-    if ( !v13 )
-    {
-      *v3 = 8;
-      return 5;
-    }
-    v14 = v13 - 1;
-    if ( v14 )
-    {
-      v15 = v14 - 1;
-      if ( v15 )
-      {
-        v16 = v15 - 1;
-        if ( !v16 || v16 == 25 )
-        {
-          *v3 = 10;
-          *a3 = 1;
-          return v5;
-        }
-		v5 = 0;
-		*v3 = v5;
-		return v5;
-      }
-      *v3 = 2;
-      return 12;
-    }
-    v5 = 8;
-    *v3 = v5;
-    return v5;
-  }
-  if ( v8 == 11 )
-  {
-    *v3 = 0;
-    v7 = 2;
-    return GetDiceResult(v7, 6u);
-  }
-  if ( v8 == 4 )
-  {
-    *v3 = 2;
-    v11 = rand() % 2;
-    return v11 + 3;
-  }
-  if ( v8 == 5 )
-  {
-    *v3 = 2;
-    v10 = rand();
-    v17 = 3;
-    return v10 % v17 + 6;
-  }
-  if ( v8 == 6 )
-  {
-    *v3 = 2;
-    v9 = rand() % 4;
-    return v9 + 9;
-  }
-  if ( v8 == 7 )
-  {
-    *v3 = 1;
-    return rand() % 4 + 2;
-  }
-  if ( v8 == 8 )
-  {
-    *v3 = 1;
-    return rand() % 7 + 4;
-  }
-  if ( v8 == 9 )
-  {
-    *v3 = 1;
-    v10 = rand();
-    v17 = 10;
-    return v10 % v17 + 6;
-  }
-  if ( v8 != 10 )
-  {
-        v5 = 0;
-    *v3 = v5;
-    return v5;
-  }
-  *v3 = 0;
-  v7 = 1;
-  return GetDiceResult(v7, 6u);
-}
+	switch (uSpecEnchantmentType)
+		{
+	case 4:  //Adds 3-4 points of Cold damage.
+		*damage_type = 2;
+		return rand() % 2 + 3;
+		break;
+	case 5:  //Adds 6-8 points of Cold damage.
+		*damage_type = 2;
+		return rand() % 3 + 6;
+		break;
+	case 6: //Adds 9-12 points of Cold damage.
+		*damage_type = 2;
+		return rand() % 4 + 9;
+		break;
+	case 7: //Adds 2-5 points of Electrical damage.
+		*damage_type = 1;
+		return rand() % 4 + 2;
+		break;
+	case 8: //Adds 4-10 points of Electrical damage.
+		*damage_type = 1;
+		return rand() % 7 + 4;
+		break;
+	case 9: //Adds 6-15 points of Electrical damage.
+		*damage_type = 1;
+		return rand() % 10 + 6;
+		break;
+	case 10: //Adds 1-6 points of Fire damage.
+		*damage_type = 0;
+		return GetDiceResult(1, 6);
+		break;
+	case 11: //Adds 2-12 points of Fire damage.
+		*damage_type = 0;
+		return GetDiceResult(2, 6);
+		break;
+	case 12: //Adds 3-18 points of Fire damage.
+		*damage_type = 0;
+		return GetDiceResult(3, 6);
+		break;
+	case 13: //Adds 5 points of Body damage.
+		*damage_type = 8;
+		return 5;
+		break;
+	case 14: //Adds 8 points of Body damage.
+		*damage_type = 8;
+		return 8;
+		break;
+	case 15: //Adds 12 points of Body damage.
+		*damage_type = 8;
+		return 12;
+		break;
+	case 16: //Drain Hit Points from target.
+	case 41: //Drain Hit Points from target and Increased Weapon speed.
+		*damage_type = 10;
+		*draintargetHP = true;
+		return 0;
+		break;
+	case 46:  //Adds 10-20 points of Fire damage and +25 Might.
+		*damage_type = 0;
+		return rand() % 11 + 10;
+		break;
+	default:
+		*damage_type = 0;
+		return 0;
+
+		}
+
+	}
 
 
 //----- (00402F07) --------------------------------------------------------
@@ -659,7 +600,7 @@
 						pItems[item_counter].uSkillType = PLAYER_SKILL_CLUB;
 						break;
 						}
-					pItems[item_counter].uSkillType = PLAYER_SKILL_ANY;
+					pItems[item_counter].uSkillType = PLAYER_SKILL_MISC;
 					break;
 					}
 				case 6: //Mod1
@@ -1187,14 +1128,11 @@
 //----- (00456D17) --------------------------------------------------------
 void ItemsTable::SetSpecialBonus(ItemGen *pItem)
 {
-  ItemDesc *v2; // eax@1
-
-  v2 = &this->pItems[pItem->uItemID];
-  if ( v2->uMaterial == 3 )
+  if ( pItems[pItem->uItemID].uMaterial == MATERIAL_SPECIAL )
   {
-    pItem->uEncantmentType = v2->_bonus_type;
-    pItem->uSpecEnchantmentType = v2->_additional_value;
-    pItem->_bonus_strength = v2->_bonus_strength;
+    pItem->uEncantmentType = pItems[pItem->uItemID]._bonus_type;
+    pItem->uSpecEnchantmentType = pItems[pItem->uItemID]._additional_value;
+    pItem->_bonus_strength = pItems[pItem->uItemID]._bonus_strength;
   }
 }
 
@@ -1207,10 +1145,9 @@
 //----- (00456D5E) --------------------------------------------------------
 bool ItemsTable::IsMaterialNonCommon(ItemGen *pItem)
 {
-  unsigned __int8 v2; // al@1
-
-  v2 = this->pItems[pItem->uItemID].uMaterial;
-  return v2 == MATERIAL_SPECIAL || v2 == MATERIAL_RELIC || v2 == MATERIAL_ARTEFACT;
+  return pItems[pItem->uItemID].uMaterial == MATERIAL_SPECIAL ||
+	      pItems[pItem->uItemID].uMaterial == MATERIAL_RELIC || 
+		  pItems[pItem->uItemID].uMaterial == MATERIAL_ARTEFACT;
 }
 
 
@@ -1486,7 +1423,7 @@
 
 
 //----- (00456620) --------------------------------------------------------
-void ItemsTable::GenerateItem(int treasure_level, int a3, ItemGen *out_item)
+void ItemsTable::GenerateItem(int treasure_level, unsigned int uTreasureType, ItemGen *out_item)
 {
   
 ItemGen *v4; // esi@1
@@ -1557,23 +1494,23 @@
 
   v4 = out_item;
   v6 = treasure_level - 1;
-  //v54 = treasure_level - 1;
-  if ( a3 )
+  v54 = treasure_level - 1;
+  if ( uTreasureType ) //generate known treasure type
   {
     ITEM_EQUIP_TYPE   requested_equip;
     PLAYER_SKILL_TYPE requested_skill = PLAYER_SKILL_INVALID;
-    switch (a3)
+    switch (uTreasureType)
      {
       case 20: requested_equip = EQUIP_ONE_OR_TWO_HANDS; break;
       case 21: requested_equip = EQUIP_ARMOUR; break;
-      case 22: requested_skill = (PLAYER_SKILL_TYPE)38; __debugbreak();/*check this skill*/ break;
+      case 22: requested_skill = PLAYER_SKILL_MISC; break;
       case 23: requested_skill = PLAYER_SKILL_SWORD; break;
       case 24: requested_skill = PLAYER_SKILL_DAGGER; break;
       case 25: requested_skill = PLAYER_SKILL_AXE; break;
       case 26: requested_skill = PLAYER_SKILL_SPEAR; break;
       case 27: requested_skill = PLAYER_SKILL_BOW; break;
       case 28: requested_skill = PLAYER_SKILL_MACE; break;
-      case 29: requested_skill = (PLAYER_SKILL_TYPE)37; __debugbreak();/*check this skill*/break;
+      case 29: requested_skill = PLAYER_SKILL_CLUB; break;
       case 30: requested_skill = PLAYER_SKILL_STAFF; break;
       case 31: requested_skill = PLAYER_SKILL_LEATHER; break;
       case 32: requested_skill = PLAYER_SKILL_CHAIN; break;
@@ -1593,14 +1530,14 @@
       case 46: requested_equip = EQUIP_GEM; break;
       default:
         __debugbreak(); // check this condition
-        requested_equip = (ITEM_EQUIP_TYPE)(a3 - 1);
+        requested_equip = (ITEM_EQUIP_TYPE)(uTreasureType - 1);
       break;
     }
     memset(Dst, 0, sizeof(Dst));
     v52 = 0;
     v7 = Dst;
     //a2a = 1;
-    if (requested_skill == PLAYER_SKILL_INVALID)
+    if (requested_skill == PLAYER_SKILL_INVALID)  // no skill for this item needed
     {
       for (uint i = 1; i < 500; ++i)
       {
@@ -1611,7 +1548,7 @@
         }
       }
     }
-    else
+    else  //have needed skill
     {
       for (uint i = 1; i < 500; ++i)
       {
@@ -1627,11 +1564,11 @@
     if ( v52 )
       v10 = rand() % v52;
 
-    v4->uItemID = *Dst;
-    if (!v4->uItemID)
-      v4->uItemID = 1;
+    out_item->uItemID = *Dst;
+    if (!out_item->uItemID)
+      out_item->uItemID = 1;
 
-    v11 = pItems[v4->uItemID].uChanceByTreasureLvl[v6];
+    v11 = pItems[out_item->uItemID].uChanceByTreasureLvl[v6];
     if ( v11 < v10 )
     {
       v12 = (uint *)Dst;
@@ -1639,23 +1576,18 @@
       {
         ++v12;
         v13 = *v12;
-        v4->uItemID = *v12;
+        out_item->uItemID = *v12;
         v11 += pItems[v13].uChanceByTreasureLvl[v6];
       }
       while ( v11 < v10 );
     }
-    if (pItems[v4->uItemID].uEquipType == EQUIP_POTION && v4->uItemID != ITEM_POTION_BOTTLE )
-    {
-      v4->uEncantmentType = 0;
-      v14 = 2;
-      do
-      {
-        v4->uEncantmentType += rand() % 4 + 1;
-        v15 = v4->uEncantmentType;
-        --v14;
-      }
-      while ( v14 );
-      v4->uEncantmentType = v15 * treasure_level;
+	
+    if (pItems[out_item->uItemID].uEquipType == EQUIP_POTION && out_item->uItemID != ITEM_POTION_BOTTLE )
+    {// if it potion set potion spec
+      out_item->uEncantmentType = 0;
+     for (int i=0; i<2; ++i)
+        out_item->uEncantmentType += rand() % 4 + 1;
+      out_item->uEncantmentType = out_item->uEncantmentType * treasure_level; 
     }
   }
   else
@@ -1666,40 +1598,38 @@
       v56 += pParty->field_7BA[v16++];
     while ( v16 < 29 );
     v17 = rand() % 29;
+
     if ( v6 == 5 && rand() % 100 < 5 && !pParty->field_7BA[v17] && v56 < 13 )
     {
       pParty->field_7BA[v17] = 1;
-      v4->uAttributes = 0;
-      v4->uItemID = v17 + 500;
-      SetSpecialBonus(v4);
+      out_item->uAttributes = 0;
+      out_item->uItemID = v17 + 500;
+      SetSpecialBonus(out_item);
       return;
     }
+
     v57 = 0;
     v18 = rand() % v5->uChanceByTreasureLvlSumm[v54];// v5->field_11684[v54];
-    v4->uItemID = 0;
+    out_item->uItemID = 0;
     if ( v18 > 0 )
     {
       do
-        v57 += pItems[v4->uItemID++ + 1].uChanceByTreasureLvl[v6];
+        v57 += pItems[out_item->uItemID++ + 1].uChanceByTreasureLvl[v6];
       while ( v57 < v18 );
     }
+
     if ( !v18 )
-      v4->uItemID = 1;
-    if ( !v4->uItemID )
-      v4->uItemID = 1;
-    if (pItems[v4->uItemID].uEquipType == EQUIP_POTION && v4->uItemID != ITEM_POTION_BOTTLE)
-    {
-      v4->uEncantmentType = 0;
-      v19 = 2;
-      do
-      {
-        v4->uEncantmentType += rand() % 4 + 1;
-        v15 = v4->uEncantmentType;
-        --v19;
-      }
-      while ( v19 );
-      v4->uEncantmentType = v15 * treasure_level;
-    }
+      out_item->uItemID = 1;
+    if ( !out_item->uItemID )
+      out_item->uItemID = 1;
+	if (pItems[out_item->uItemID].uEquipType == EQUIP_POTION && out_item->uItemID != ITEM_POTION_BOTTLE )
+		{// if it potion set potion spec
+		out_item->uEncantmentType = 0;
+		for (int i=0; i<2; ++i)
+			out_item->uEncantmentType += rand() % 4 + 1;
+		out_item->uEncantmentType = out_item->uEncantmentType * treasure_level; 
+		}
+	out_item->uEncantmentType = out_item->uEncantmentType * treasure_level; 
   }
   if ( v4->uItemID == ITEM_SPELLBOOK_LIGHT_DIVINE_INTERVENTION
     && !(unsigned __int16)_449B57_test_bit(pParty->_award_bits, 239) )
@@ -1708,12 +1638,12 @@
     v4->uAttributes = 0;
   else
     v4->uAttributes = 1;
-  if ( pItems[v4->uItemID].uEquipType != EQUIP_POTION )
+  if ( pItems[out_item->uItemID].uEquipType != EQUIP_POTION )
   {
-    v4->uSpecEnchantmentType = 0;
-    v4->uEncantmentType = 0;
+    out_item->uSpecEnchantmentType = 0;
+    out_item->uEncantmentType = 0;
   }
-  v20 = pItems[v4->uItemID].uEquipType;
+  v20 = pItems[out_item->uItemID].uEquipType;
   if ( v20 <= EQUIP_BOW )
   {
     v37 = v5->uBonusChanceWpSpecial[v54];
@@ -1730,22 +1660,21 @@
       if ( v20 == EQUIP_WAND )
       {
         v21 = rand() % 6 + pItemsTable->pItems[v4->uItemID].uDamageMod + 1;
-        v4->uNumCharges = v21;
-        v4->uMaxCharges = v21;
+        out_item->uNumCharges = v21;
+        out_item->uMaxCharges = v21;
       }
       return;
     }
     v22 = (int)&uBonusChanceStandart[v6];
     if ( !*(unsigned int *)v22 )
       return;
-    v23 = rand();
     v24 = *(unsigned int *)v22;
-    v25 = v23 % 100;
-    if ( !uBonusChanceSpecial[v6] && !(v23 % 100 < v24))
+    v25 = rand() % 100;
+    if ( !uBonusChanceSpecial[v6] && !(v25 < v24))
         return;
-    if ( v25 < v24 || v23 % 100 < v24)
+    if ( v25 < v24 || v25 < v24)
     {
-      v26 = rand() % 10;//v5->field_116D8[v5->pItems[v4->uItemID].uEquipType];
+      v26 = rand() % v5->uBonusChanceWpSpecial[v5->pItems[v4->uItemID].uEquipType + 3];
       v27 = v4->uItemID;
       v4->uEncantmentType = 0;
       for ( i = pEnchantments[0].to_item[pItems[v27].uEquipType + 1];
@@ -1889,32 +1818,27 @@
   signed int uNumArtifactsNotFound; // esi@1
   int v3; // eax@1
   bool result; // eax@6
-  int v5[32]; // [sp+8h] [bp-A0h]@3
+  int artifacts_list[32]; // [sp+8h] [bp-A0h]@3
   char Dst[32]; // [sp+88h] [bp-20h]@1
 
   auto a2 = this;
   v1 = a2;
-  memset(Dst, 0, 0x20u);
+  memset(artifacts_list, 0,sizeof(artifacts_list));
   uNumArtifactsNotFound = 0;
-  v3 = 500;
-  do
-  {
-    if ( !pParty->field_3C.pIsArtifactFound[v3] )
-      v5[uNumArtifactsNotFound++] = v3;
-    ++v3;
-  }
-  while ( v3 < 529 );
-  v1->Reset();
+
+  for (int i=500;i<529;++i)
+     if ( !pParty->field_3C.pIsArtifactFound[i] )
+        artifacts_list[uNumArtifactsNotFound++] = i;
+
+  Reset();
   if ( uNumArtifactsNotFound )
   {
-    v1->uItemID = v5[rand() % uNumArtifactsNotFound];
-    pItemsTable->SetSpecialBonus(v1);
-    result = 1;
+    uItemID = artifacts_list[rand() % uNumArtifactsNotFound];
+    pItemsTable->SetSpecialBonus(this);
+    return true;
   }
   else
-  {
-    result = 0;
-  }
-  return result;
+    return false;
+
 }
 // 4505CC: using guessed type int var_A0[32];
\ No newline at end of file
--- a/Items.h	Fri Feb 22 21:10:50 2013 +0000
+++ b/Items.h	Sat Feb 23 01:50:50 2013 +0400
@@ -118,7 +118,7 @@
   const char *GetIdentifiedName();
   void UpdateTempBonus(__int64 uTimePlayed);
   void Reset();
-  int _439DF3_get_additional_damage(int *a2, int *a3);
+  int _439DF3_get_additional_damage(int *a2, bool *vampiyr);
 
 
 
@@ -234,7 +234,7 @@
   void Initialize();
   void LoadPotions();
   void LoadPotionNotes();
-  void GenerateItem(int treasure_level, int a3, ItemGen *pItem);
+  void GenerateItem(int treasure_level, unsigned int uTreasureType, ItemGen *pItem);
   void SetSpecialBonus(ItemGen *pItem);
   bool IsMaterialSpecial(ItemGen *pItem);
   bool IsMaterialNonCommon(ItemGen *pItem);
--- a/Player.h	Fri Feb 22 21:10:50 2013 +0000
+++ b/Player.h	Sat Feb 23 01:50:50 2013 +0400
@@ -216,7 +216,7 @@
   PLAYER_SKILL_ALCHEMY = 35,
   PLAYER_SKILL_LEARNING = 36,
   PLAYER_SKILL_CLUB = 37,
-  PLAYER_SKILL_ANY = 38,
+  PLAYER_SKILL_MISC = 38,
   PLAYER_SKILL_INVALID = -1
 };