changeset 1211:fd3bea473c0c

fix HouseNpcdata array addresiing
author Gloval
date Sun, 09 Jun 2013 16:36:24 +0400
parents decc0dd6e4ba
children 746f7ef994cb
files GUIWindow.cpp UIHouses.cpp mm7_2.cpp mm7_4.cpp mm7_data.cpp mm7_data.h stru159.h
diffstat 7 files changed, 43 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/GUIWindow.cpp	Sun Jun 09 13:20:34 2013 +0400
+++ b/GUIWindow.cpp	Sun Jun 09 16:36:24 2013 +0400
@@ -1036,11 +1036,11 @@
             pWindow.DrawTitleText(pFontCreate, 0x1E3u, 113, pColor2, pTitleText, 3);
             continue;
           }
-          pTitleText = HouseNPCData[v8 - (dword_591080 != 0)]->pName;
-          v9 = pNPCPortraits_x[6 + (uNumDialogueNPCPortraits - 1)][v8] + pDialogueNPCPortraits[v8]->uTextureHeight + 2;
+          pTitleText = HouseNPCData[v8 +1 - (dword_591080 != 0)]->pName;
+          v9 = pNPCPortraits_y[uNumDialogueNPCPortraits - 1][v8] + pDialogueNPCPortraits[v8]->uTextureHeight + 2;
         }
         v10 = v9;
-        pWindow.DrawTitleText(pFontCreate, 0x1E3u, v10, pColor2, pTitleText, 3);
+        pWindow.DrawTitleText(pFontCreate, 483, v10, pColor2, pTitleText, 3);
       }
     }
       if ( pDialogueNPCCount == uNumDialogueNPCPortraits && uHouse_ExitPic )
@@ -1842,15 +1842,12 @@
   if (eWindowType == WINDOW_HouseInterior)
   {
     pCurrentScreen = SCREEN_HOUSE;
-    pBtn_ExitCancel = pWindow->CreateButton(0x1D7u, 0x1BDu, 0xA9u, 0x23u, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[80],//Выйти из здания
+    pBtn_ExitCancel = pWindow->CreateButton(471, 445, 0xA9u, 0x23u, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[80],//Выйти из здания
                    pIcons_LOD->GetTexture(uExitCancelTextureId), 0);
-    v25 = uNumDialogueNPCPortraits;
-    v26 = 0;
-    if ( uNumDialogueNPCPortraits > 0 )
-    {
+  
       for ( v26 = 0; v26 < uNumDialogueNPCPortraits; ++v26 )
       {
-        if ( v26 + 1 == v25 && uHouse_ExitPic )
+        if ( v26 + 1 == uNumDialogueNPCPortraits && uHouse_ExitPic )
         {
           v30 = pMapStats->pInfos[uHouse_ExitPic].pName;
           v29 = (char*)pGlobalTXT_LocalizationStrings[LOCSTR_ENTER_S];
@@ -1858,21 +1855,19 @@
         else
         {
           if ( v26 || !dword_591080 )
-            v27 = HouseNPCData[v26 - (dword_591080 != 0)]->pName;
+            v27 = HouseNPCData[v26 +1 - (dword_591080 != 0)]->pName;
           else
-            //v27 = (char *)p2DEvents_minus1_::08[13 * a4];
             v27 = (char *)p2DEvents[pButton - 1].pProprieterName;
           v30 = v27;
           v29 = (char*)pGlobalTXT_LocalizationStrings[435];
         }
         sprintfex(byte_591180[v26].data(), v29, v30);
-        HouseNPCData[v26 + 7] = (NPCData *)pWindow->CreateButton(pNPCPortraits_x[uNumDialogueNPCPortraits - 1][v26],
+        dword_5913F4[v26] = pWindow->CreateButton(pNPCPortraits_x[uNumDialogueNPCPortraits - 1][v26],
                                                                  pNPCPortraits_y[uNumDialogueNPCPortraits - 1][v26],
                                              0x3Fu, 0x49u, 1, 0, UIMSG_ClickHouseNPCPortrait, v26, 0, byte_591180[v26].data(), 0, 0, 0);
-        v25 = uNumDialogueNPCPortraits;
       }
-    }
-    if ( v25 == 1 )
+  
+    if ( uNumDialogueNPCPortraits == 1 )
     {
       window_SpeakInHouse = &pWindowList[uNextFreeWindowID];
       _4B4224_UpdateNPCTopics(0);
--- a/UIHouses.cpp	Sun Jun 09 13:20:34 2013 +0400
+++ b/UIHouses.cpp	Sun Jun 09 16:36:24 2013 +0400
@@ -336,110 +336,71 @@
   //int v11; // ecx@19
   //char pContainer[36]; // [sp+Ch] [bp-54h]@16
   int v13; // [sp+30h] [bp-30h]@11
-  int Dst[6]; // [sp+34h] [bp-2Ch]@1
+  int npc_id_arr[6]; // [sp+34h] [bp-2Ch]@1
   //unsigned int v15; // [sp+4Ch] [bp-14h]@1
   int uAnimationID; // [sp+50h] [bp-10h]@1
   //unsigned int *v17; // [sp+54h] [bp-Ch]@3
   //unsigned int v18; // [sp+58h] [bp-8h]@1
   //int v19; // [sp+5Ch] [bp-4h]@7
 
-  //v15 = uHouseID;
-  //v1 = 52 * uHouseID;
-  //uAnimationID = p2DEvents_minus1___02[26 * uHouseID];
+
   uAnimationID = p2DEvents[house - 1].uAnimationID;
-  //v18 = 52 * uHouseID;
-  memset(Dst, 0, 0x18u);
-  //uExitPic = *(__int16 *)((char *)p2DEvents_minus1_::2C + v1);
-  //uExitPic = p2DEvents[uHouseID - 1].uExitPicID;
+  memset(npc_id_arr, 0, sizeof(npc_id_arr));
   uNumDialogueNPCPortraits = 0;
   uHouse_ExitPic = p2DEvents[house - 1].uExitPicID;
   if ( uHouse_ExitPic )
   {
-    //uExitMapID = *(__int16 *)((char *)p2DEvents_minus1_::30 + v1);
     uExitMapID = p2DEvents[house - 1]._quest_related;
     if ( uExitMapID > 0 )
     {
-      //v17 = (unsigned int *)(uExitMapID - 1);
 	  if(_449B57_test_bit(pParty->_quest_bits,uExitMapID))
-     // if ( !((unsigned __int8)(0x80u >> (uExitMapID - 1) % 8) & pParty->_quest_bits[(uExitMapID - 1) >> 3]) )
       {
-        //uExitPic = 0;
         uHouse_ExitPic = 0;
       }
     }
   }
 
-  dword_591080 = pAnimatedRooms[uAnimationID].field_8;
-  //result = dword_591080;
-
-  //v2 = 0;
+  dword_591080 = pAnimatedRooms[uAnimationID].house_npc_id;
+  HouseNPCData[0]=0;
   uNumDialogueNPCPortraits = 0;
   if ( dword_591080 )
   {
-    //v2 = 1;
-    Dst[0] = dword_591080;
+
+    npc_id_arr[0] = dword_591080;
     uNumDialogueNPCPortraits = 1;
   }
 
-  //v19 = 1;
-  for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
+  for (uint i = 1; i < pNPCStats->uNumNewNPCs; ++i)
   {
-    auto npc = pNPCStats->pNewNPCData + i;
-    //v6 = &pNPCStats->pNewNPCData[1].uFlags;
-    //v17 = &pNPCStats->pNewNPCData[1].uFlags;
-    //do
-    //{
-    if (npc->Location2D == house )
+    if (pNPCStats->pNewNPCData[i].Location2D == house )
     {
-      if (~npc->uFlags & 0x80)
-        //if ( !(*(char *)v6 & 0x80) )
+      if (!(pNPCStats->pNewNPCData[i].uFlags & 0x80))
       {
-        v7 = uNumDialogueNPCPortraits++ - (dword_591080 != 0) ? 1 : 0;
-        HouseNPCData[v7] = npc;
-        //v6 = v17;
-        //*(&v13 + v2) = *(v17 - 1);
-        Dst[uNumDialogueNPCPortraits - 1] = npc->uPortraitID;
-          //v1 = v18;
-        if ((npc->uFlags & 3) != 2)
-          ++npc->uFlags;
+        
+        HouseNPCData[uNumDialogueNPCPortraits+1- (dword_591080 != 0) ? 1 : 0] = &pNPCStats->pNewNPCData[i];     
+        npc_id_arr[uNumDialogueNPCPortraits] = pNPCStats->pNewNPCData[i].uPortraitID;
+         ++uNumDialogueNPCPortraits;
+        if ((pNPCStats->pNewNPCData[i].uFlags & 3) != 2)
+          ++pNPCStats->pNewNPCData[i].uFlags;
       }
     }
-      //++v19;
-      //v6 += 19;
-      //v17 = v6;
-    //}
-    //while ( v19 < (signed int)pNPCStats->uNumNewNPCs );
+
   }
-  //uNumDialogueNPCPortraits = v2;
 
-  //v19 = 0;
   for (uint i = 0; i < uNumDialogueNPCPortraits; ++i)
-  //if ( v2 > 0 )
   {
-    //do
-    //{
-      //v8 = v19;
+   
     char icon_name[128];
-    sprintfex(icon_name, "npc%03u", Dst[i]);
-    //v9 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
-    //++v19;
+    sprintfex(icon_name, "npc%03u", npc_id_arr[i]);
     pDialogueNPCPortraits[i] = pIcons_LOD->LoadTexturePtr(icon_name, TEXTURE_16BIT_PALETTE);
-    //result = v19;
-    //}
-    //while ( v19 < uNumDialogueNPCPortraits );
-    //uExitPic = uHouse_ExitPic;
   }
 
   if (uHouse_ExitPic)
   {
-    //v10 = pIcons_LOD->LoadTexture(pHouse_ExitPictures[uHouse_ExitPic], TEXTURE_16BIT_PALETTE);
-    //v11 = uNumDialogueNPCPortraits++;
-    pDialogueNPCPortraits[uNumDialogueNPCPortraits++] = pIcons_LOD->LoadTexturePtr(pHouse_ExitPictures[uHouse_ExitPic], TEXTURE_16BIT_PALETTE);
-    //result = *(__int16 *)((char *)p2DEvents_minus1_::2E + v1);
-    //result = p2DEvents[house - 1].uExitMapID;
+    pDialogueNPCPortraits[uNumDialogueNPCPortraits] = pIcons_LOD->LoadTexturePtr(pHouse_ExitPictures[uHouse_ExitPic], TEXTURE_16BIT_PALETTE);
+    ++uNumDialogueNPCPortraits;
     uHouse_ExitPic = p2DEvents[house - 1].uExitMapID;
   }
-  //return result;
 }
 
 
--- a/mm7_2.cpp	Sun Jun 09 13:20:34 2013 +0400
+++ b/mm7_2.cpp	Sun Jun 09 16:36:24 2013 +0400
@@ -879,7 +879,7 @@
         //v3 = byte_591180;
         do
         {
-          HouseNPCData[v2 + 7] = (NPCData *)window_SpeakInHouse->CreateButton(pNPCPortraits_x[v1 - 1][v2], pNPCPortraits_y[v1 - 1][v2],
+          dword_5913F4[v2] = window_SpeakInHouse->CreateButton(pNPCPortraits_x[v1 - 1][v2], pNPCPortraits_y[v1 - 1][v2],
                                               0x3Fu, 0x49u, 1, 0, UIMSG_ClickHouseNPCPortrait, v2, 0, byte_591180[v2].data(), 0, 0, 0);
           v1 = uNumDialogueNPCPortraits;
           ++v2;
--- a/mm7_4.cpp	Sun Jun 09 13:20:34 2013 +0400
+++ b/mm7_4.cpp	Sun Jun 09 16:36:24 2013 +0400
@@ -3373,7 +3373,7 @@
   if ( dword_5C35D4 )
   {
     //__debugbreak(); // fix  
-    npc = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) - 1)];
+    npc = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0))]; //- 1
   }
   else
     npc = GetNPCData(sDialogue_SpeakingActorNPC_ID);
@@ -6467,7 +6467,7 @@
   //int v25; // [sp-4h] [bp-10h]@49
 
   uDialogueType = uMessageParam + 1;
-  pCurrentNPCInfo = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) - 1)];
+  pCurrentNPCInfo = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) )];//- 1
   if ( uMessageParam <= 24 )
   {
   switch ( uMessageParam )
@@ -7209,7 +7209,7 @@
   }
   a1.uFrameWidth -= 10;
   a1.uFrameZ -= 10;
-  v58 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) - 1)];
+  v58 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) )];//- 1
   v6 = v58;
   v55 = TargetColor(0xE1u, 0xCDu, 0x23u);
   v7 = TargetColor(0x15u, 0x99u, 0xE9u);
@@ -7763,7 +7763,7 @@
   NPCData *v1; // edi@1
 
   v0 = 0;
-  v1 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) - 1)];
+  v1 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) )];//- 1
   pDialogueWindow->Release();
   pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x15Eu, WINDOW_MainMenu, 0, 0);
   pBtn_ExitCancel = pDialogueWindow->CreateButton( 0x1D7u, 0x1BDu,  0xA9u,   0x23u,  1,  0,  UIMSG_Escape,  0,   0,
@@ -7811,7 +7811,7 @@
   }
   else
   {
-    v17 = HouseNPCData[_this + 1 - ((dword_591080 != 0) + 1)];
+    v17 = HouseNPCData[_this + 1 - ((dword_591080 != 0) )];//+ 1
     if ( dialog_menu_id == HOUSE_DIALOGUE_OTHER )
     {
       pDialogueWindow->Release();
@@ -7819,7 +7819,7 @@
     else
     {
       for ( i = 0; i < uNumDialogueNPCPortraits; ++i )
-        ((GUIButton *)HouseNPCData[i + 7])->Release();
+        dword_5913F4[i]->Release();
     }
     pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x159u, WINDOW_MainMenu, 0, 0);
     pBtn_ExitCancel = pDialogueWindow->CreateButton(  471u,  445u,  169u, 35u,  1,   0, UIMSG_Escape,  0,  0,
--- a/mm7_data.cpp	Sun Jun 09 13:20:34 2013 +0400
+++ b/mm7_data.cpp	Sun Jun 09 16:36:24 2013 +0400
@@ -1116,8 +1116,8 @@
 int dword_591178_teleporty; // weak
 int dword_59117C_teleportx; // weak
 std::array<std::array<char, 100>, 6> byte_591180; // idb
-std::array<struct NPCData *, 60> HouseNPCData;//array_5913D8 this array size temporarily increased to 60 from 6 to work aroud house overflow
-
+std::array<struct NPCData *, 7> HouseNPCData;//0 zero element holds standart house npc
+GUIButton* dword_5913F4[6];
 struct Texture *pTexture_591428;
 struct Texture *pTexture_outside; // idb
 struct Texture *pTexture_Dialogue_Background;
--- a/mm7_data.h	Sun Jun 09 13:20:34 2013 +0400
+++ b/mm7_data.h	Sun Jun 09 16:36:24 2013 +0400
@@ -755,8 +755,8 @@
 extern int dword_591178_teleporty; // weak
 extern int dword_59117C_teleportx; // weak
 extern std::array<std::array<char, 100>, 6> byte_591180; // idb
-extern std::array<struct NPCData *, 60> HouseNPCData; //this array size temporarily increased to 60 from 6 to work aroud house overflow
-
+extern std::array<struct NPCData *, 7> HouseNPCData; //0this array size temporarily increased to 60 from 6 to work aroud house overflow
+extern GUIButton* dword_5913F4[6];
 extern struct Texture *pTexture_591428;
 extern struct Texture *pTexture_outside; // idb
 extern struct Texture *pTexture_Dialogue_Background;
--- a/stru159.h	Sun Jun 09 13:20:34 2013 +0400
+++ b/stru159.h	Sun Jun 09 16:36:24 2013 +0400
@@ -8,7 +8,7 @@
 {
   char *video_name;
   int field_4;
-  int field_8;
+  int house_npc_id;
   unsigned __int8 uBuildingType;
   unsigned __int8 uRoomSoundId;
   unsigned __int16 padding_e;