Mercurial > mm7
changeset 2287:4e3236a4ea63
GenerateItemsInChest cleaned up a bit, unified the two switches
author | Grumpy7 |
---|---|
date | Sat, 15 Mar 2014 23:42:51 +0100 |
parents | 288e0b29a493 |
children | 406605240b0a |
files | Items.cpp |
diffstat | 1 files changed, 83 insertions(+), 132 deletions(-) [+] |
line wrap: on
line diff
--- a/Items.cpp Sat Mar 15 19:53:14 2014 +0100 +++ b/Items.cpp Sat Mar 15 23:42:51 2014 +0100 @@ -1862,149 +1862,100 @@ //----- (00450218) -------------------------------------------------------- void GenerateItemsInChest() { - unsigned int v0; // eax@1 - MapInfo *v2; // esi@1 - ItemGen *v3; // ebx@2 - int v4; // ebp@4 - int v5; // edi@4 - int v6; // esi@4 - signed int v8; // esi@4 - int v9; // edx@4 - int v10; // esi@8 + unsigned int mapType; // eax@1 + MapInfo *currMapInfo; // esi@1 + ItemGen *currItem; // ebx@2 + int additionaItemCount; // ebp@4 + int treasureLevelBot; // edi@4 + int treasureLevelTop; // esi@4 + signed int treasureLevelRange; // esi@4 + int resultTreasureLevel; // edx@4 + int goldAmount; // esi@8 int v11; // ebp@25 int v12; // esi@25 - ItemGen *v14; // edi@28 - signed int v18; // [sp+10h] [bp-18h]@1 + signed int whatToGenerateProb; // [sp+10h] [bp-18h]@1 - v18 = rand() % 100; //main random - v0 = pMapStats->GetMapInfo(pCurrentMapName); - // v1 = pChests; - v2 = &pMapStats->pInfos[v0]; - //v21 = pChests; - //v20 = &pMapStats->pInfos[v0]; + mapType = pMapStats->GetMapInfo(pCurrentMapName); + currMapInfo = &pMapStats->pInfos[mapType]; for(int i=1; i<20;++i) - { + { for(int j=0; j<140;++j) - { + { - v3 = &pChests[i].igChestItems[j]; - if ( v3->uItemID < 0 ) + currItem = &pChests[i].igChestItems[j]; + if ( currItem->uItemID < 0 ) + { + additionaItemCount = rand() % 5; //additional items in chect + treasureLevelBot = byte_4E8168[abs(currItem->uItemID)-1][2*currMapInfo->Treasure_prob]; + treasureLevelTop = byte_4E8168[abs(currItem->uItemID)-1][2*currMapInfo->Treasure_prob+1]; + treasureLevelRange = treasureLevelTop - treasureLevelBot + 1; + resultTreasureLevel = treasureLevelBot + rand() % treasureLevelRange; //treasure level + if (resultTreasureLevel<7) { - 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) + v11 = 0; + do + { + whatToGenerateProb = rand() % 100; + if (whatToGenerateProb<20) + { + currItem->Reset(); + } + else if (whatToGenerateProb<60) //generate gold { - 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; - } + goldAmount=0; + currItem->Reset(); + switch (resultTreasureLevel) + { + case 1: //small gold + goldAmount = rand() % 51 + 50; + currItem->uItemID = 197; + break; + case 2://small gold + goldAmount = rand() % 101 + 100; + currItem->uItemID = 197; + break; + case 3: //medium + goldAmount = rand() % 301 + 200; + currItem->uItemID = 198; + break; + case 4: //medium + goldAmount = rand() % 501 + 500; + currItem->uItemID = 198; + break; + case 5: //big + goldAmount = rand() % 1001 + 1000; + currItem->uItemID = 199; + break; + case 6: //big + goldAmount = rand() % 3001 + 2000; + currItem->uItemID = 199; + break; + } + currItem->SetIdentified(); + currItem->uSpecEnchantmentType = goldAmount; + } else - { - pItemsTable->GenerateItem(v9, 0, v3); - } - + { + pItemsTable->GenerateItem(resultTreasureLevel, 0, currItem); + } v12 = 0; - //generate more items - for (v11=0; v11<v4; ++v11) - { + while ( !(pChests[i].igChestItems[v12].uItemID==0) &&(v12<140)) + { + ++v12; + } + if (v12 >= 140) + break; + currItem=&pChests[i].igChestItems[v12]; + v11++; + } while (v11 < additionaItemCount + 1); // + 1 because it's the item at pChests[i].igChestItems[j] and the additional ones + } + else + currItem->GenerateArtifact(); + } + } + } - 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(); - } - } - } - - } +}