changeset 599:deb559e4fe47

Merge
author Gloval
date Wed, 06 Mar 2013 22:47:21 +0400
parents f8a4a2e0b4c9 (diff) c03428cb4119 (current diff)
children db4a23580e6c
files Party.cpp mm7_2.cpp mm7_data.h
diffstat 5 files changed, 161 insertions(+), 198 deletions(-) [+]
line wrap: on
line diff
--- a/Items.cpp	Wed Mar 06 17:04:54 2013 +0000
+++ b/Items.cpp	Wed Mar 06 22:47:21 2013 +0400
@@ -925,7 +925,7 @@
 	memset(&uChanceByTreasureLvlSumm, 0, 24);
 	for(i=0;i<6;++i)
 		{
-		for (j=0;j<800;++j)
+		for (j=1;j<item_counter;++j)
 			uChanceByTreasureLvlSumm[i]+=pItems[j].uChanceByTreasureLvl[i];
 		}
 
@@ -1723,7 +1723,10 @@
         if ( v18 > 0 )
             {
             do
-            v57 += pItems[out_item->uItemID++ + 1].uChanceByTreasureLvl[v6];
+                {      
+            v57 += pItems[out_item->uItemID + 1].uChanceByTreasureLvl[v6];
+            ++out_item->uItemID;
+                }
             while ( v57 < v18 );
             }
 
@@ -2019,204 +2022,162 @@
 
 
 //----- (00450218) --------------------------------------------------------
-void sub_450218_prolly_generate_chests_loot()
+void GenerateItemsInChest()
     {
-	unsigned int v0; // eax@1
-	Chest *v1; // ebx@1
-	MapInfo *v2; // esi@1
-	ItemGen *v3; // ebx@2
-	int v4; // ebp@4
-	int v5; // edi@4
-	int v6; // esi@4
-	int v7; // eax@4
-	signed int v8; // esi@4
-	int v9; // edx@4
-	int v10; // esi@8
-	int v11; // ebp@25
-	int v12; // esi@25
-	signed int v13; // ebp@27
-	ItemGen *v14; // edi@28
-	signed int v15; // edx@32
-	signed __int64 v16; // qtt@32
-	int v17; // esi@34
-	signed int v18; // [sp+10h] [bp-18h]@1
-	int v19; // [sp+14h] [bp-14h]@4
-	MapInfo *v20; // [sp+18h] [bp-10h]@1
-	Chest *v21; // [sp+1Ch] [bp-Ch]@1
-	int v22; // [sp+20h] [bp-8h]@26
-	signed int v23; // [sp+24h] [bp-4h]@2
+    unsigned int v0; // eax@1
+    Chest *v1; // ebx@1
+    MapInfo *v2; // esi@1
+    ItemGen *v3; // ebx@2
+    int v4; // ebp@4
+    int v5; // edi@4
+    int v6; // esi@4
+    int v7; // eax@4
+    signed int v8; // esi@4
+    int v9; // edx@4
+    int v10; // esi@8
+    int v11; // ebp@25
+    int v12; // esi@25
+    signed int v13; // ebp@27
+    ItemGen *v14; // edi@28
+    signed int v15; // edx@32
+    signed __int64 v16; // qtt@32
+    int v17; // esi@34
+    signed int v18; // [sp+10h] [bp-18h]@1
+    int v19; // [sp+14h] [bp-14h]@4
+    MapInfo *v20; // [sp+18h] [bp-10h]@1
+    Chest *v21; // [sp+1Ch] [bp-Ch]@1
+    int v22; // [sp+20h] [bp-8h]@26
+    signed int v23; // [sp+24h] [bp-4h]@2
 
-	v18 = rand() % 100;
-	v0 = pMapStats->GetMapInfo(pCurrentMapName);
-	v1 = pChests;
-	v2 = &pMapStats->pInfos[v0];
-	v21 = pChests;
-	v20 = &pMapStats->pInfos[v0];
-    for(int i=0; i<20;++i)
-		{
-		for(int j=0; j<140;++j)
-			{
-            v3 = &pChests[i].igChestItems[j];
-			if ( v3->uItemID < 0 )
-                {
-			v4 = rand() % 5 + 1;
-			v5 = (unsigned __int8)byte_4E8168[abs((int)v3->uItemID)-1][2*v2->Treasure_prob];//[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 2];
-			v6 = (unsigned __int8)byte_4E8168[abs((int)v3->uItemID)-1][2*v2->Treasure_prob+1];//[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 3];
-			v7 = rand();
-			v8 = v6 - v5 + 1;
-			v9 = v5 + v7 % v8;
-			v19 = v5 + v7 % v8;
-           /* switch (v9)
-                {
-            default:
-
-                }*/
-
+    v18 = rand() % 100;  //main random
+    v0 = pMapStats->GetMapInfo(pCurrentMapName);
+    //	v1 = pChests;
+    v2 = &pMapStats->pInfos[v0];
+    //v21 = pChests;
+    //v20 = &pMapStats->pInfos[v0];
+    for(int i=1; i<20;++i)
+        {
+        for(int j=0; j<140;++j)
+            {
 
-			if ( v9 < 7 )
-				{
-				if ( v18 < 20 )
-					{
-					v3->Reset();
-					goto LABEL_25;
-					}
-				if ( v18 < 60 )
-					{
-					v10 = 0;
-					v3->Reset();
-					if ( v19 == 1 )
-						{
-						v10 = rand() % 51 + 50;
-						}
-					else
-						{
-						if ( v19 != 2 )
-							{
-							if ( v19 == 3 )
-								{
-								v10 = rand() % 301 + 200;
-								}
-							else
-								{
-								if ( v19 != 4 )
-									{
-									if ( v19 == 5 )
-										{
-										v10 = rand() % 1001 + 1000;
-LABEL_15:
-										v3->uItemID = 199;
-										}
-									else
-										{
-										if ( v19 == 6 )
-											{
-											v10 = rand() % 3001 + 2000;
-											goto LABEL_15;
-											}
-										}
-LABEL_23:
-									v3->SetIdentified();
-									v3->uSpecEnchantmentType = v10;
-LABEL_25:
-									v11 = v4 - 1;
-									v12 = 0;
-									if ( v11 > 0 )
-										{
-										v22 = v11;
-										while ( 1 )
-											{
-											v13 = v12;
-											if ( v12 >= 140 )
-												goto LABEL_52;
-											v14 = &v21->igChestItems[v12];
-											while ( v14->uItemID )
-												{
-												++v13;
-												++v14;
-												if ( v13 >= 140 )
-													goto LABEL_52;
-												}
-											v16 = rand();
-											v15 = v16 % 100;
-											v18 = v16 % 100;
-											if ( v15 < 20 )
-												goto LABEL_52;
-											if ( v15 >= 60 )
-												{
-												pItemsTable->GenerateItem(v19, 0, v14);
-												goto LABEL_51;
-												}
-											v17 = 0;
-											v14->Reset();
-											if ( v19 == 1 )
-												{
-												v17 = rand() % 51 + 50;
-												goto LABEL_48;
-												}
-											if ( v19 == 2 )
-												{
-												v17 = rand() % 101 + 100;
-LABEL_48:
-												v14->uItemID = 197;
-												goto LABEL_49;
-												}
-											if ( v19 == 3 )
-												{
-												v17 = rand() % 301 + 200;
-												goto LABEL_44;
-												}
-											if ( v19 == 4 )
-												{
-												v17 = rand() % 501 + 500;
-LABEL_44:
-												v14->uItemID = 198;
-												goto LABEL_49;
-												}
-											if ( v19 == 5 )
-												break;
-											if ( v19 == 6 )
-												{
-												v17 = rand() % 3001 + 2000;
-LABEL_41:
-												v14->uItemID = 199;
-												}
-LABEL_49:
-											v14->uSpecEnchantmentType = v17;
-LABEL_51:
-											v12 = v13 + 1;
-LABEL_52:
-											--v22;
-											if ( !v22 )
-												goto LABEL_55;
-											}
-										v17 = rand() % 1001 + 1000;
-										goto LABEL_41;
-										}
-									goto LABEL_55;
-									}
-								v10 = rand() % 501 + 500;
-								}
-							v3->uItemID = 198;
-							goto LABEL_23;
-							}
-						v10 = rand() % 101 + 100;
-						}
-					v3->uItemID = 197;
-					goto LABEL_23;
-					}
-				pItemsTable->GenerateItem(v9, 0, v3);
-				goto LABEL_25;
-				}
-			v3->GenerateArtifact();
-            
-LABEL_55:
-			v2 = v20;
-LABEL_56: ;
+            v3 = &pChests[i].igChestItems[j];
+            if ( v3->uItemID < 0 )
+                {
+                v4 = rand() % 5; //additional items in chect
+                v5 = (unsigned __int8)byte_4E8168[abs((int)v3->uItemID)-1][2*v2->Treasure_prob];
+                v6 = (unsigned __int8)byte_4E8168[abs((int)v3->uItemID)-1][2*v2->Treasure_prob+1];
+                v8 = v6 - v5 + 1;
+                v9 = v5 + rand() % v8;  //treasure level 
+                if (v9<7)
+                    {
+                    if (v18<20)
+                        {
+                        v3->Reset();
+                        }
+                    else if (v18<60) //generate gold
+                        {
+                        v10=0;
+                        v3->Reset();
+                        switch (v9)
+                            {
+                        case 1: //small gold
+                            v10 = rand() % 51 + 50;
+                            v3->uItemID = 197;
+                            break;
+                        case 2://small gold
+                            v10 = rand() % 101 + 100;
+                            v3->uItemID = 197;
+                            break;
+                        case 3:  //medium
+                            v10 = rand() % 301 + 200;
+                            v3->uItemID = 198;
+                            break;
+                        case 4: //medium
+                            v10 = rand() % 501 + 500;
+                            v3->uItemID = 198;
+                            break;
+                        case 5: //big
+                            v10 = rand() % 1001 + 1000;
+                            v3->uItemID = 199;
+                            break;
+                        case 6: //big
+                            v10 = rand() % 3001 + 2000;
+                            v3->uItemID = 199;
+                            break;
+                            }
+                        v3->SetIdentified();
+                        v3->uSpecEnchantmentType = v10;
+                        }
+                    else
+                        {
+                        pItemsTable->GenerateItem(v9, 0, v3);
+                        }
+
+                    v12 = 0;
+                    //generate more items
+                    for (v11=0; v11<v4; ++v11)
+                        {
+
+                        if ( v12 >= 140 )
+                            break;
+                        while ( !(pChests[i].igChestItems[v12].uItemID==0) &&(v12<140))
+                            {
+                            ++v12;
+                            }
+                        v14=&pChests[i].igChestItems[v12];
+                        v18 = rand() % 100;
+                        if (v18<20)
+                            {
+                            v3->Reset();
+                            }
+                        else if (v18<60) //generate gold
+                            {
+                            v10=0;
+                            v3->Reset();
+                            switch (v9)
+                                {
+                            case 1: //small gold
+                                v10 = rand() % 51 + 50;
+                                v14->uItemID = 197;
+                                break;
+                            case 2://small gold
+                                v10 = rand() % 101 + 100;
+                                v14->uItemID = 197;
+                                break;
+                            case 3:  //medium
+                                v10 = rand() % 301 + 200;
+                                v14->uItemID = 198;
+                                break;
+                            case 4: //medium
+                                v10 = rand() % 501 + 500;
+                                v14->uItemID = 198;
+                                break;
+                            case 5: //big
+                                v10 = rand() % 1001 + 1000;
+                                v14->uItemID = 199;
+                                break;
+                            case 6: //big
+                                v10 = rand() % 3001 + 2000;
+                                v14->uItemID = 199;
+                                break;
+                                }
+                            v14->SetIdentified();
+                            v14->uSpecEnchantmentType = v10;
+                            }
+                        else
+                            {
+                            pItemsTable->GenerateItem(v9, 0, v14);
+                            }                       
+                        ++v12;
+                        }
+                    }
+                else
+                    v3->GenerateArtifact();
                 }
-			}			
-		}
-		
-	}
+            }			
+        }
+
+    }
 
 
 	
--- a/Items.h	Wed Mar 06 17:04:54 2013 +0000
+++ b/Items.h	Wed Mar 06 22:47:21 2013 +0400
@@ -289,6 +289,7 @@
 
 void GenerateStandartShopItems();
 void GenerateSpecialShopItems();
+void GenerateItemsInChest();
 
 extern const char uItemsAmountPerShopType[]; // weak
 extern ItemGen *ptr_50C9A4;
--- a/Party.cpp	Wed Mar 06 17:04:54 2013 +0000
+++ b/Party.cpp	Wed Mar 06 22:47:21 2013 +0400
@@ -745,6 +745,7 @@
   uFlags = 0;
   memset(_autonote_bits, 0, 12);
   memset(_quest_bits, 0, 64);
+  memset(pIsArtifactFound, 0, 29);
   _449B7E_toggle_bit(_quest_bits, 1, 1);
   _449B7E_toggle_bit(_quest_bits, 2, 1);
   _449B7E_toggle_bit(_quest_bits, 3, 1);
--- a/mm7_2.cpp	Wed Mar 06 17:04:54 2013 +0000
+++ b/mm7_2.cpp	Wed Mar 06 22:47:21 2013 +0400
@@ -11297,7 +11297,7 @@
   signed int v20; // [sp+18h] [bp-44h]@14
   int v21[16]; // [sp+1Ch] [bp-40h]@17
 
-  sub_450218_prolly_generate_chests_loot();
+  GenerateItemsInChest();
   //v0 = pGameLoadingUI_ProgressBar;
   pGameLoadingUI_ProgressBar->Progress();
   pParty->uFlags |= 2u;
--- a/mm7_data.h	Wed Mar 06 17:04:54 2013 +0000
+++ b/mm7_data.h	Wed Mar 06 22:47:21 2013 +0400
@@ -2053,7 +2053,7 @@
 // int __cdecl crt_deconstruct_44C42C();
 void SpawnEncounter(struct MapInfo *pMapInfo, struct SpawnPointMM7 *spawn, int a3, int a4, int a5);
 int __fastcall sub_44FA4C_spawn_light_elemental(int a1, int a2, int a3);
-void  sub_450218_prolly_generate_chests_loot();
+
 signed int __fastcall sub_450521_ProllyDropItemAt(int ecx0, signed int a2, int a3, int a4, int a5, unsigned __int16 a6);
 int __fastcall sub_45063B(struct MapInfo *a1, int a2);
 void RespawnGlobalDecorations();