diff mm7_5.cpp @ 521:663c4f618f56

Awards tab corrrection
author Gloval
date Sat, 02 Mar 2013 01:42:05 +0400
parents cb0ad52d6a26
children 5196a51cc9ec
line wrap: on
line diff
--- a/mm7_5.cpp	Fri Mar 01 23:43:21 2013 +0400
+++ b/mm7_5.cpp	Sat Mar 02 01:42:05 2013 +0400
@@ -3174,7 +3174,7 @@
           pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 102;
           GUIWindow::Create(pCharacterScreen_AwardsBtn->uX, pCharacterScreen_AwardsBtn->uY, 0, 0, (WindowType)(WINDOW_HouseInterior|0x42),
             (int)pCharacterScreen_AwardsBtn, 0);
-          sub_419100();
+          FillAwardsData();
           continue;
         case UIMSG_AutonotesBook:
           switch ( uMessageParam )
@@ -13602,7 +13602,7 @@
     v0 = pViewport->uViewportX + 398;
   }
   pRenderer->DrawTextureTransparent(v0, v11, v13);
-  if ( dword_506544 || dword_506528 + dword_506520 >= dword_506524 )
+  if ( dword_506544 || dword_506528 + awards_count >= awards_count2 )
   {
     v14 = pTex_tab_an_7a__zoot_off;
     v12 = pViewport->uViewportY + 38;
@@ -13617,7 +13617,7 @@
   pRenderer->DrawTextureTransparent(v1, v12, v14);
   if ( !byte_5C6D50[dword_506528] )
   {
-    v2 = pStru179.field_0[dword_506528];
+    v2 = achievedAwardsIndex[dword_506528];
     a1.uFrameWidth = 460;
     a1.uFrameX = 8;
     a1.uFrameY = 8;
@@ -13636,12 +13636,12 @@
   a1.uFrameZ = 407;
   a1.uFrameHeight = v4 * 264 / v4;
   a1.uFrameW = a1.uFrameHeight + 69;
-  if ( dword_506544 && dword_506528 + dword_506520 < dword_506524 )
+  if ( dword_506544 && dword_506528 + awards_count < awards_count2 )
   {
     pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
     v5 = dword_50651C++;
-    dword_506528 += dword_506520;
-    byte_506130[v5] = dword_506520;
+    dword_506528 += awards_count;
+    byte_506130[v5] = awards_count;
   }
   if ( dword_506548 && dword_50651C )
   {
@@ -13649,15 +13649,15 @@
     --dword_50651C;
     dword_506528 -= (unsigned __int8)byte_506130[dword_50651C];
   }
-  if ( !dword_506520 || dword_506528 < 1 )
+  if ( !awards_count || dword_506528 < 1 )
   {
     dword_506528 = 0;
     dword_50651C = 0;
   }
   dword_506544 = 0;
-  v6 = pStru179.field_0[dword_506528];
+  v6 = achievedAwardsIndex[dword_506528];
   dword_506548 = 0;
-  dword_506520 = 0;
+  awards_count = 0;
   //v7 = *pStorylineText->StoreLine[v6].pText;//*(&pStorylineText->field_0 + 3 * v6);
   v7 = (int)pStorylineText->StoreLine[v6].pText;//*(&pStorylineText->field_0 + 3 * v6);
   v8 = BuilDialogueString(
@@ -13671,7 +13671,7 @@
   {
     v9 = pAutonoteFont->_44C6C2(v8, &a1, 1u, (unsigned __int8)byte_5C6D50[dword_506528]);
     LOBYTE(v8) = a1.DrawText(pAutonoteFont, 1, 0, 0, (const char *)v9, 0, a1.uFrameY + a1.uFrameHeight, 0);
-    ++dword_506520;
+    ++awards_count;
   }
   return (char)v8;
 }
@@ -13708,7 +13708,7 @@
     v0 = pViewport->uViewportX + 398;
   }
   pRenderer->DrawTextureTransparent(v0, v8, v10);
-  if ( dword_506544 || dword_506528 + dword_506520 >= dword_506524 )
+  if ( dword_506544 || dword_506528 + awards_count >= awards_count2 )
   {
     v11 = pTex_tab_an_7a__zoot_off;
     v9 = pViewport->uViewportY + 38;
@@ -13734,12 +13734,12 @@
   a1.uFrameHeight = 264;
   a1.uFrameZ = 407;
   a1.uFrameW = 333;
-  if ( dword_506544 && dword_506528 + dword_506520 < dword_506524 )
+  if ( dword_506544 && dword_506528 + awards_count < awards_count2 )
   {
     pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
     v2 = dword_50651C++;
-    dword_506528 += dword_506520;
-    byte_506130[v2] = dword_506520;
+    dword_506528 += awards_count;
+    byte_506130[v2] = awards_count;
   }
   if ( dword_506548 && dword_50651C )
   {
@@ -13747,7 +13747,7 @@
     --dword_50651C;
     dword_506528 -= (unsigned __int8)byte_506130[dword_50651C];
   }
-  if ( !dword_506520 || (v3 = dword_506528, dword_506528 < 1) )
+  if ( !awards_count || (v3 = dword_506528, dword_506528 < 1) )
   {
     v3 = 0;
     dword_50651C = 0;
@@ -13755,11 +13755,11 @@
   }
   dword_506544 = 0;
   dword_506548 = 0;
-  dword_506520 = 0;
-  while ( v3 < dword_506524 )
-  {
-    v4 = pStru179.field_0[v3];
-    ++dword_506520;
+  awards_count = 0;
+  while ( v3 < awards_count2 )
+  {
+    v4 = achievedAwardsIndex[v3];
+    ++awards_count;
     v5 = pQuestTable[v4-1];//(&dword_722F10)[4 * v4];
     a1.DrawText(pAutonoteFont, 1, 0, 0, pQuestTable[v4-1], 0, 0, 0);//(&dword_722F10)[4 * v4], 0, 0, 0);
     v6 = pAutonoteFont->CalcTextHeight(v5, &a1, 1, 0);
@@ -13826,7 +13826,7 @@
     v0 = pViewport->uViewportX + 398;
   }
   pRenderer->DrawTextureTransparent(v0, v17, v24);
-  if ( dword_506544 || dword_506528 + dword_506520 >= dword_506524 )
+  if ( dword_506544 || dword_506528 + awards_count >= awards_count2 )
   {
     v25 = pTex_tab_an_7a__zoot_off;
     v18 = pViewport->uViewportY + 38;
@@ -14000,10 +14000,10 @@
   a1.uFrameW = 333;
   if ( v31 )
   {
-    dword_506524 = 0;
+    awards_count2 = 0;
     dword_506528 = 0;
     dword_50651C = 0;
-    dword_506520 = 0;
+    awards_count = 0;
     v8 = 0;
     do
     {
@@ -14016,25 +14016,25 @@
         {
           if ( (unsigned __int16)_449B57_test_bit(pParty->_autonote_bits, v8) && v32 )
           {
-            v9 = dword_506520++;
-            pStru179.field_0[v9] = (signed __int16)v8;
+            v9 = awards_count++;
+            achievedAwardsIndex[v9] = (signed __int16)v8;
           }
         }
       }
       ++v8;
     }
     while ( v8 < 196 );
-    dword_506524 = dword_506520;
+    awards_count2 = awards_count;
   }
   else
   {
     if ( dword_506544 )
     {
-      v10 = dword_506520 + dword_506528;
-      if ( dword_506520 + dword_506528 < dword_506524 )
+      v10 = awards_count + dword_506528;
+      if ( awards_count + dword_506528 < awards_count2 )
       {
         v11 = dword_50651C++;
-        byte_506130[v11] = dword_506520;
+        byte_506130[v11] = awards_count;
         dword_506528 = v10;
         pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
       }
@@ -14045,7 +14045,7 @@
       dword_506528 -= (unsigned __int8)byte_506130[dword_50651C];
       pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
     }
-    if ( !dword_506520 || dword_506528 < 1 )
+    if ( !awards_count || dword_506528 < 1 )
     {
       dword_506528 = 0;
       dword_50651C = 0;
@@ -14055,16 +14055,16 @@
   dword_50652C = 0;
   dword_506544 = 0;
   dword_506548 = 0;
-  dword_506520 = 0;
+  awards_count = 0;
   dword_506530 = 0;
   dword_506534 = 0;
   dword_506538 = 0;
   dword_50653C = 0;
   dword_506540 = 0;
-  while ( v12 < dword_506524 )
-  {
-    v13 = pStru179.field_0[v12];
-    ++dword_506520;
+  while ( v12 < awards_count2 )
+  {
+    v13 = achievedAwardsIndex[v12];
+    ++awards_count;
     //v14 = (&dword_723718_autonote_related)[8 * v13];
 	v14 = pAutonoteTxt[v13-1].pText;
     //a1.DrawText(pAutonoteFont, 1, 0, 0, (&dword_723718_autonote_related)[8 * v13], 0, 0, 0);
@@ -17657,88 +17657,45 @@
 }
 
 //----- (00419100) --------------------------------------------------------
-int __cdecl sub_419100()
-{
-  Player *pPlayer; // esi@1
-  int v1; // ebx@1
-  unsigned __int8 *v2; // esi@1
-  int v3; // eax@4
-  int result; // eax@6
-  int v5; // esi@6
-  unsigned __int8 v6; // zf@6
-  unsigned __int8 v7; // sf@6
-  int v8; // edx@7
-  int v9; // ecx@7
-  unsigned __int8 v10; // of@7
-  stru179 *v11; // edi@9
-  int v12; // edx@11
-  char *v13; // [sp+Ch] [bp-8h]@2
-  signed int v14; // [sp+Ch] [bp-8h]@9
-  int i; // [sp+10h] [bp-4h]@10
-
-  pPlayer = pPlayers[uActiveCharacter];
-  memset(&pStru179, 0, 0xFA0u);
-  memset(pTmpBuf2, 0, 0x7D0u);
-  v1 = 0;
-  dword_506544 = 0;
-  dword_506548 = 0;
-  dword_506520 = 0;
-  dword_50651C = 0;
-  dword_506528 = 0;
-  v2 = (unsigned __int8 *)pPlayer->_guilds_member_bits;
-  do
-  {
-    v13 = (char *)pAwards[v1].pText;//dword_723E80_award_related[2 * v1];
-    if ( (unsigned __int16)_449B57_test_bit(v2, v1) && v13 )
-    {
-      v3 = dword_506520++;
-      pStru179.field_0[v3] = v1;
-    }
-    ++v1;
-  }
-  while ( v1 < 105 );
-  result = dword_506520;
-  v5 = 0;
-  v6 = dword_506520 == 0;
-  v7 = dword_506520 < 0;
-  dword_506524 = dword_506520;
-  dword_506520 = 0;
-  if ( !(v7 | v6) )
-  {
-    do
-    {
-      v8 = rand() % 16;
-      result = dword_506524;
-      v9 = dword_506524 + v5++;
-      v10 = v5 > dword_506524;//__OFSUB__(v5, dword_506524);
-      v7 = v5 - dword_506524 < 0;
-      pStru179.field_0[v9] = v8;
-    }
-    while ( v7 ^ v10 );
-    if ( result > 0 )
-    {
-      v14 = 1;
-      v11 = &pStru179;
-      do
-      {
-        for ( i = v14; i < result; ++i )
-        {
-          v12 = pStru179.field_0[i];
-          //if ( dword_723E84[2 * v12] < dword_723E84[2 * v11->field_0[0]] )
-		  if(pAwards[v12-1].uSort < pAwards[v11->field_0[0]].uSort)
-          {
-            pStru179.field_0[i] = v11->field_0[0];
-            v11->field_0[0] = v12;
-          }
-        }
-        ++v14;
-        v11 = (stru179 *)((char *)v11 + 4);
-      }
-      while ( v14 - 1 < result );
-    }
-  }
-  return result;
-}
+void FillAwardsData()
+    {
+    Player *pPlayer; // esi@1
+
+    pPlayer = pPlayers[uActiveCharacter];
+    memset(&achievedAwardsIndex, 0, 4000);
+    memset(pTmpBuf2, 0, 0x7D0u);
+    dword_506544 = 0;
+    dword_506548 = 0;
+    awards_count = 0;
+    dword_50651C = 0;
+    dword_506528 = 0;
+    for(int i=0; i<105; ++i)
+        {
+        if ( _449B57_test_bit((unsigned char*)&pPlayer->_guilds_member_bits, i) && pAwards[i].pText )
+            achievedAwardsIndex[awards_count++] = i;
+        }
+    awards_count2 = awards_count;
+    awards_count = 0;
+    //sort awards index 
+    if ( awards_count2>0 )
+        {
+        for(int i=0; i<awards_count2; ++i)
+            achievedAwardsIndex[awards_count2 + i] = rand() % 16;
+
+        for(int i=1; i<awards_count2-1; ++i)
+            {
+            for (int j = i; j < awards_count2-1; ++j )
+                {
+                int tmp=achievedAwardsIndex[j];
+                if(pAwards[j].uSort < pAwards[i].uSort)
+                    {
+                    achievedAwardsIndex[j] = achievedAwardsIndex[i];
+                    achievedAwardsIndex[i] = tmp;
+                    }
+                }
+            }
+        }
+    }
 
 
 //----- (00419220) --------------------------------------------------------