changeset 1612:11f12a34b397

TampleDialog(cleaning continue)
author Ritor1
date Sun, 15 Sep 2013 00:41:34 +0600
parents 8e99b4a7176f
children aaefada3e1d8
files UI/UIHouses.cpp
diffstat 1 files changed, 273 insertions(+), 334 deletions(-) [+]
line wrap: on
line diff
--- a/UI/UIHouses.cpp	Sat Sep 14 10:28:23 2013 +0600
+++ b/UI/UIHouses.cpp	Sun Sep 15 00:41:34 2013 +0600
@@ -2815,37 +2815,25 @@
 
 //----- (004B705E) --------------------------------------------------------
 void TempleDialog()
-    {
-    GUIWindow *v0; // ebx@1
-    Player *v1; // esi@1
-    int v2; // edi@1
+{
+    int pPrice; // edi@1
     int result; // eax@4
-    GUIWindow *v4; // edi@6
-    void *v5; // eax@6
-    int v6; // eax@6
-    unsigned int v7; // eax@8
-    int v8; // ecx@8
     unsigned int v9; // eax@9
-    int v10; // eax@11
+    int pTextHeight; // eax@11
     int v11; // eax@12
     GUIWindow *v12; // ecx@16
     int v13; // edx@16
     GUIButton *v14; // eax@19
     GUIButton *v15; // edi@19
     int v16; // eax@19
-    const char *v17; // eax@21
-    int v18; // eax@21
     unsigned int v19; // ecx@21
     int v20; // eax@21
-    unsigned __int16 v21; // ax@21
-    unsigned __int16 v22; // ST14_2@27
-    int v23; // eax@27
+    unsigned __int16 pTextColor; // ax@21
     double v24; // st7@28
     unsigned int v25; // ebx@28
     DDM_DLV_Header *v26; // edi@29
     int v27; // eax@31
     int v28; // eax@32
-    //unsigned int v29; // ecx@34
     unsigned int v30; // edx@36
     unsigned int v31; // edx@38
     unsigned int v32; // edx@40
@@ -2857,343 +2845,294 @@
     int v38; // ecx@54
     GUIWindow *v39; // eax@56
     unsigned __int8 v40; // al@61
-    GUIButton *v41; // edi@64
-    int v42; // esi@66
-    GUIWindow *v43; // ecx@66
-    int v44; // edi@66
-    int v45; // eax@68
-    signed int v46; // edi@69
+    GUIButton *pButton; // edi@64
     int v47; // edi@71
-    GUIButton *v48; // eax@73
-    const char *v49; // edx@73
-    GUIButton *v50; // esi@73
-    int v51; // eax@73
     unsigned int v52; // ecx@73
-    unsigned __int16 v53; // ax@73
-    char a1[300]; // [sp+10h] [bp-1B4h]@64
-    GUIWindow v57; // [sp+13Ch] [bp-88h]@1
-    __int64 v58; // [sp+190h] [bp-34h]@1
-    __int64 v59; // [sp+198h] [bp-2Ch]@1
-    __int64 v60; // [sp+1A0h] [bp-24h]@1
-    GUIWindow *v61; // [sp+1ACh] [bp-18h]@6
+    GUIWindow tample_window; // [sp+13Ch] [bp-88h]@1
     unsigned int v62; // [sp+1B0h] [bp-14h]@8
-    unsigned __int8 v63; // [sp+1B7h] [bp-Dh]@64
+    unsigned __int8 index; // [sp+1B7h] [bp-Dh]@64
     int v64; // [sp+1B8h] [bp-Ch]@6
-    unsigned int v65; // [sp+1BCh] [bp-8h]@6
-    DDM_DLV_Header *v66; // [sp+1C0h] [bp-4h]@6
+    unsigned int pCurrentItem; // [sp+1BCh] [bp-8h]@6
+    int all_text_height; // [sp+1C0h] [bp-4h]@6
 
-    v0 = window_SpeakInHouse;
-    memcpy(&v57, window_SpeakInHouse, sizeof(v57));
-    v57.uFrameX = 483;
-    v57.uFrameWidth = 148;
-    v57.uFrameZ = 334;
-    HIDWORD(v58) = TargetColor(0xFFu, 0xFFu, 0xFFu);
-    HIDWORD(v59) = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-    v1 = pPlayers[uActiveCharacter];
-    //v2 = pPlayers[uActiveCharacter]->_4B807C(p2DEvents_minus1__20[13 * (unsigned int)v0->ptr_1C]);
-    v2 = pPlayers[uActiveCharacter]->GetTempleHealCostModifier(p2DEvents[v0->par1C - 1].fPriceMultiplier);
-    HIDWORD(v60) = v2;
-    if ( dialog_menu_id != HOUSE_DIALOGUE_MAIN )
+  memcpy(&tample_window, window_SpeakInHouse, sizeof(tample_window));
+  tample_window.uFrameX = 483;
+  tample_window.uFrameWidth = 148;
+  tample_window.uFrameZ = 334;
+  pPrice = pPlayers[uActiveCharacter]->GetTempleHealCostModifier(p2DEvents[window_SpeakInHouse->par1C - 1].fPriceMultiplier);
+  if ( dialog_menu_id == HOUSE_DIALOGUE_MAIN )
+  {
+    index = 1;
+    pButton = pDialogueWindow->GetControl(pDialogueWindow->pStartingPosActiveItem);
+    pButton->uHeight = 0;
+    pButton->uY = 0;
+    if ( pPlayers[uActiveCharacter]->IsPlayerHealableByTemple() )
     {
-      if ( dialog_menu_id != HOUSE_DIALOGUE_TEMPLE_HEAL )
+      sprintfex(pTmpBuf.data(), "%s %d %s", pGlobalTXT_LocalizationStrings[104], pPrice, pGlobalTXT_LocalizationStrings[97]);//"Лечить" "Золото"
+      pShopOptions[0] = pTmpBuf.data();
+      index = 0;
+    }
+    pShopOptions[1] = pGlobalTXT_LocalizationStrings[68];//"Пожертвовать"
+    pShopOptions[2] = pGlobalTXT_LocalizationStrings[160];//"Обучиться навыкам"
+    all_text_height = 0;
+    if ( index < pDialogueWindow->pNumPresenceButton )
+    {
+      uint i = index;
+      for ( uint j = index; j < pDialogueWindow->pNumPresenceButton; ++j )
+      {
+        all_text_height += pFontArrus->CalcTextHeight(pShopOptions[1 * i], &tample_window, 0, 0);
+        i++;
+      }
+    }
+    v64 = (174 - (signed int)all_text_height) / (pDialogueWindow->pNumPresenceButton - index);
+    if ( v64 > 32 )
+      v64 = 32;
+    v47 = (174 - v64 * (pDialogueWindow->pNumPresenceButton - index) - (signed int)all_text_height) / 2 - v64 / 2 + 138;
+    if ( index + pDialogueWindow->pStartingPosActiveItem < pDialogueWindow->pStartingPosActiveItem + pDialogueWindow->pNumPresenceButton )
+    {
+      uint i = index;
+      for ( pCurrentItem = index + pDialogueWindow->pStartingPosActiveItem;
+          (signed int)pCurrentItem < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem; ++pCurrentItem )
       {
-        if ( dialog_menu_id != HOUSE_DIALOGUE_TEMPLE_DONATE )
-        {
-          if ( dialog_menu_id == HOUSE_DIALOGUE_LEARN_SKILLS )
-          {
-            if ( HouseUI_CheckIfPlayerCanInteract() )
-            {
-              v4 = pDialogueWindow;
-              v61 = pDialogueWindow;
-              v5 = window_SpeakInHouse->ptr_1C;
-              v66 = 0;
-              //v65 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (signed int)v5] * 500.0);
-              v65 = (signed __int64)(p2DEvents[(signed int)v5 - 1].flt_24 * 500.0);
-              v6 = v1->GetMerchant();
-              v64 = (signed int)(v65 * (100 - v6)) / 100;
-              if ( v64 < (signed int)v65 / 3 )
-                v64 = (signed int)v65 / 3;
-              v7 = v4->pStartingPosActiveItem;
-              v8 = v7 + v4->pNumPresenceButton;
-              v65 = 0;
-              v62 = v7;
-              if ( (signed int)v7 >= v8 )
-                goto LABEL_78;
-              do
-              {
-                v9 = v4->GetControl(v62)->msg_param - 36;
-                if ( byte_4ED970_skill_learn_ability_by_class_table[v1->classType][v9] && !v1->pActiveSkills[v9] )
-                {
-                  v10 = pFontArrus->CalcTextHeight(pSkillNames[v9], &v57, 0, 0);
-                  v66 = (DDM_DLV_Header *)((char *)v66 + v10);
-                  ++v65;
-                }
-                v11 = v4->pStartingPosActiveItem;
-                ++v62;
-              }
-              while ( (signed int)v62 < v4->pNumPresenceButton + v11 );
-              if ( v65 )
-              {
-                sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[401], v64);
-                v57.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf.data(), 3u);
-                v64 = (149 - (signed int)v66) / (signed int)v65;
-                if ( v64 > 32 )
-                  v64 = 32;
-                v65 = (signed int)(149 - v65 * v64 - (int)v66) / 2 - v64 / 2 + 162;
-                v12 = v61;
-                result = v61->pStartingPosActiveItem;
-                v13 = result + v61->pNumPresenceButton;
-                v62 = v61->pStartingPosActiveItem;
-                if ( result < v13 )
-                {
-                  v66 = (DDM_DLV_Header *)2;
-                  while ( 1 )
-                  {
-                    v14 = v12->GetControl(v62);
-                    v15 = v14;
-                    v16 = v14->msg_param - 36;
-                    if ( !byte_4ED970_skill_learn_ability_by_class_table[v1->classType][v16] || v1->pActiveSkills[v16] )
-                    {
-                      v15->uW = 0;
-                      v15->uHeight = 0;
-                      v15->uY = 0;
-                    }
-                    else
-                    {
-                      v17 = pSkillNames[v16];
-                      v15->uY = v64 + v65;
-                      HIDWORD(v60) = (uint32)v17;
-                      v18 = pFontArrus->CalcTextHeight(v17, &v57, 0, 0);
-                      v19 = v15->uY;
-                      v15->uHeight = v18;
-                      v20 = v19 + v18 - 1;
-                      v15->uW = v20;
-                      v65 = v20;
-                      v21 = WORD2(v59);
-                      if ( (DDM_DLV_Header *)pDialogueWindow->pCurrentPosActiveItem != v66 )
-                        v21 = WORD2(v58);
-                      v57.DrawTitleText(pFontArrus, 0, v19, v21, (const char *)HIDWORD(v60), 3u);
-                    }
-                    result = (int)v61;
-                    ++v62;
-                    v66 = (DDM_DLV_Header *)((char *)v66 + 1);
-                    if ( (signed int)v62 >= v61->pNumPresenceButton + v61->pStartingPosActiveItem )
-                      break;
-                    v12 = v61;
-                  }
-                }
-              }
-              else
-              {
-LABEL_78:
-                sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[544], v1->pName, pClassNames[v1->classType]);
-                strcat(pTmpBuf.data(), "\n \n");
-                strcat(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[528]);
-                v22 = WORD2(v59);
-                v23 = pFontArrus->CalcTextHeight(pTmpBuf.data(), &v57, 0, 0);
-                v57.DrawTitleText(pFontArrus, 0, (174 - v23) / 2 + 138, v22, pTmpBuf.data(), 3u);
-              }
-            }
-          }
-          return;
-        }
-        // DONATION
-        //v24 = p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C];
-        v24 = p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].fPriceMultiplier;
-        v25 = 0;
-        if ( pParty->uNumGold >= (unsigned int)(signed __int64)v24 )
-        {
-                Party::TakeGold((signed __int64)v24);
-                v26 = &pOutdoor->ddm;
-                if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
-                    v26 = &pIndoor->dlv;
-                v27 = v26->uReputation;
-                v66 = v26;
-                if ( v27 > -5 )
-                    {
-                    v28 = v27 - 1;
-                    v26->uReputation = v28;
-                    if ( v28 < -5 )
-                        v26->uReputation = -5;
-                    }
-                if ( (unsigned __int8)byte_F8B1EF[uActiveCharacter] == pParty->uDaysPlayed % 7 )
-                    {
-                    if ( v26->uReputation <= -5 )
-                        {
-                        v30 = pParty->uDaysPlayed % 7 + 1;
-                        LOBYTE(v30) = v30 | 0x80;
-                        _42777D_CastSpell_UseWand_ShootArrow(SPELL_AIR_WIZARD_EYE, uActiveCharacter - 1, v30, 48, 0);
-                        }
-                    if ( v26->uReputation <= -10 )
-                        {
-                        v31 = pParty->uDaysPlayed % 7 + 1;
-                        LOBYTE(v31) = v31 | 0x80;
-                        _42777D_CastSpell_UseWand_ShootArrow(SPELL_SPIRIT_PRESERVATION, uActiveCharacter - 1, v31, 48, 0);
-                        v26 = v66;
-                        }
-                    if ( v26->uReputation <= -15 )
-                        {
-                        v32 = pParty->uDaysPlayed % 7 + 1;
-                        LOBYTE(v32) = v32 | 0x80;
-                        _42777D_CastSpell_UseWand_ShootArrow(SPELL_BODY_PROTECTION_FROM_MAGIC, uActiveCharacter - 1, v32, 48, 0);
-                        v26 = v66;
-                        }
-                    if ( v26->uReputation <= -20 )
-                        {
-                        v33 = pParty->uDaysPlayed % 7 + 1;
-                        LOBYTE(v33) = v33 | 0x80;
-                        _42777D_CastSpell_UseWand_ShootArrow(SPELL_LIGHT_HOUR_OF_POWER, uActiveCharacter - 1, v33, 48, 0);
-                        v26 = v66;
-                        }
-                    if ( v26->uReputation <= -25 )
-                        {
-                        v34 = pParty->uDaysPlayed % 7 + 1;
-                        LOBYTE(v34) = v34 | 0x80;
-                        _42777D_CastSpell_UseWand_ShootArrow(SPELL_LIGHT_DAY_OF_PROTECTION, uActiveCharacter - 1, v34, 48, 0);
-                        }
-                    }
-                ++byte_F8B1EF[uActiveCharacter];
-                v1->PlaySound(SPEECH_83, 0);
-                ShowStatusBarString(pGlobalTXT_LocalizationStrings[527], 2u); // "Thank You!"
-                pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
-                return;
-          }
-          ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
-          PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
-          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
-          return;
-        }
-        if ( !v1->IsPlayerHealableByTemple() )
-            return;
-        v25 = 0;
-        if ( pParty->uNumGold < v2 )
-        {
-          ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
-          PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
-          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
-          return;
-        }
-        Party::TakeGold(v2);
-        v35 = LODWORD(v1->pConditions[17]);
-        v59 = v1->pConditions[14];
-        v58 = v1->pConditions[15];
-        v60 = v1->pConditions[16];
-        v61 = (GUIWindow *)HIDWORD(v1->pConditions[17]);
-        memset(v1, 0, 0xA0u);
-        v1->sHealth = v1->GetMaxHealth();
-        v1->sMana = v1->GetMaxMana();
-        v36 = (signed int)window_SpeakInHouse->ptr_1C;
-        if ( v36 != 78 && (v36 <= 80 || v36 > 82) )
-            {
-            if ( (unsigned int)v61 | v35 )
-                {
-                v37 = LOBYTE(v1->uPrevFace);
-                v38 = v1->uPrevVoiceID;
-                v1->uCurrentFace = v37;
-                v1->uVoiceID = v38;
-                ReloadPlayerPortraits(uActiveCharacter - 1, (char)v37);
-                }
-            pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|0x2), -1, 0, -1, 0, 0, 0, 0);
-            v1->PlaySound(SPEECH_82, 0);
-            pOtherOverlayList->_4418B1(20, uActiveCharacter + 99, 0, 65536);
-            pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
-            return;
-            }
-        v39 = v61;
-        if ( (unsigned int)v61 | v35 )
-            {
-            LODWORD(v1->pConditions[17]) = v35;
-            }
-        else
-            {
-            if ( !v60 && !v58 && !v59 )
-            {
-              pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|0x2), -1, 0, -1, 0, 0, 0, 0);
-              v1->PlaySound(SPEECH_82, 0);
-              pOtherOverlayList->_4418B1(20, uActiveCharacter + 99, 0, 65536);
-              pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
-              return;
-            }
-            v1->uPrevFace = v1->uCurrentFace;
-            v1->uPrevVoiceID = v1->uVoiceID;
-            v1->SetCondition(0x11u, 1);
-            v1->uVoiceID = (v1->GetSexByVoice() != 0) + 23;
-            v40 = (v1->GetSexByVoice() != 0) + 23;
-            v1->uCurrentFace = v40;
-            ReloadPlayerPortraits(uActiveCharacter - 1, (char)v40);
-            LODWORD(v1->pConditions[17]) = LODWORD(pParty->uTimePlayed);
-            v39 = (GUIWindow *)HIDWORD(pParty->uTimePlayed);
-            }
-        HIDWORD(v1->pConditions[17]) = (int)v39;
+        pButton = pDialogueWindow->GetControl(pCurrentItem);
+        pButton->uY = v64 + v47;
+        pTextHeight = pFontArrus->CalcTextHeight(pShopOptions[1 * i], &tample_window, 0, 0);
+        v52 = pButton->uY;
+        pButton->uHeight = pTextHeight;
+        v47 = v52 + pTextHeight - 1;
+        pButton->uW = v47;
+        pTextColor = TargetColor(0xFFu, 0xFFu, 0x9Bu);
+        if ( pDialogueWindow->pCurrentPosActiveItem != index + 2 )
+          pTextColor = TargetColor(0xFFu, 0xFFu, 0xFFu);
+        tample_window.DrawTitleText(pFontArrus, 0, v52, pTextColor, pShopOptions[1 * i], 3);
+        i++;
+        index++;
+      }
+    }
+    return;
+  }
+  //-------------------------------------------------
+  if ( dialog_menu_id == HOUSE_DIALOGUE_TEMPLE_HEAL )
+  {
+    if ( !pPlayers[uActiveCharacter]->IsPlayerHealableByTemple() )
+      return;
+    v25 = 0;
+    if ( pParty->uNumGold < pPrice )
+    {
+      ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);
+      PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
+      return;
+    }
+    Party::TakeGold(pPrice);
+    v35 = LODWORD(pPlayers[uActiveCharacter]->pConditions[17]);
+    memset(pPlayers[uActiveCharacter], 0, 0xA0u);
+    pPlayers[uActiveCharacter]->sHealth = pPlayers[uActiveCharacter]->GetMaxHealth();
+    pPlayers[uActiveCharacter]->sMana = pPlayers[uActiveCharacter]->GetMaxMana();
+    v36 = (signed int)window_SpeakInHouse->ptr_1C;
+    if ( v36 != 78 && (v36 <= 80 || v36 > 82) )
+    {
+      if ( (unsigned int)pPlayers[uActiveCharacter]->pConditions[17] | v35 )
+      {
+        v37 = LOBYTE(pPlayers[uActiveCharacter]->uPrevFace);
+        v38 = pPlayers[uActiveCharacter]->uPrevVoiceID;
+        pPlayers[uActiveCharacter]->uCurrentFace = v37;
+        pPlayers[uActiveCharacter]->uVoiceID = v38;
+        ReloadPlayerPortraits(uActiveCharacter - 1, (char)v37);
+      }
+      pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|0x2), -1, 0, -1, 0, 0, 0, 0);
+      pPlayers[uActiveCharacter]->PlaySound(SPEECH_82, 0);
+      pOtherOverlayList->_4418B1(20, uActiveCharacter + 99, 0, 65536);
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
+      return;
+    }
+    if ( (unsigned int)pPlayers[uActiveCharacter]->pConditions[17] | v35 )
+    {
+      LODWORD(pPlayers[uActiveCharacter]->pConditions[17]) = v35;
+    }
+    else
+    {
+      if ( !pPlayers[uActiveCharacter]->pConditions[16]
+        && !pPlayers[uActiveCharacter]->pConditions[15] && !pPlayers[uActiveCharacter]->pConditions[14] )
+      {
         pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|0x2), -1, 0, -1, 0, 0, 0, 0);
-        v1->PlaySound(SPEECH_82, 0);
+        pPlayers[uActiveCharacter]->PlaySound(SPEECH_82, 0);
         pOtherOverlayList->_4418B1(20, uActiveCharacter + 99, 0, 65536);
         pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
-        return; // void func
-        }
-    v63 = 1;
-    v41 = pDialogueWindow->GetControl(pDialogueWindow->pStartingPosActiveItem);
-    strcpy(a1, "");
-    v41->uHeight = 0;
-    v41->uY = 0;
-    if ( v1->IsPlayerHealableByTemple() )
+        return;
+      }
+      pPlayers[uActiveCharacter]->uPrevFace = pPlayers[uActiveCharacter]->uCurrentFace;
+      pPlayers[uActiveCharacter]->uPrevVoiceID = pPlayers[uActiveCharacter]->uVoiceID;
+      pPlayers[uActiveCharacter]->SetCondition(0x11u, 1);
+      pPlayers[uActiveCharacter]->uVoiceID = (pPlayers[uActiveCharacter]->GetSexByVoice() != 0) + 23;
+      v40 = (pPlayers[uActiveCharacter]->GetSexByVoice() != 0) + 23;
+      pPlayers[uActiveCharacter]->uCurrentFace = v40;
+      ReloadPlayerPortraits(uActiveCharacter - 1, (char)v40);
+      LODWORD(pPlayers[uActiveCharacter]->pConditions[17]) = LODWORD(pParty->uTimePlayed);
+      v39 = (GUIWindow *)HIDWORD(pParty->uTimePlayed);
+    }
+    HIDWORD(pPlayers[uActiveCharacter]->pConditions[17]) = (int)v39;
+    pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|0x2), -1, 0, -1, 0, 0, 0, 0);
+    pPlayers[uActiveCharacter]->PlaySound(SPEECH_82, 0);
+    pOtherOverlayList->_4418B1(20, uActiveCharacter + 99, 0, 65536);
+    pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
+    return;
+  }
+  //---------------------------------------------------
+  if ( dialog_menu_id == HOUSE_DIALOGUE_TEMPLE_DONATE )
+  {
+      v24 = p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].fPriceMultiplier;
+      v25 = 0;
+      if ( pParty->uNumGold >= (unsigned int)(signed __int64)v24 )
+      {
+        Party::TakeGold((signed __int64)v24);
+        v26 = &pOutdoor->ddm;
+        if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
+          v26 = &pIndoor->dlv;
+        v27 = v26->uReputation;
+        //v66 = v26;
+        if ( v27 > -5 )
         {
-        sprintf(a1, "%s %d %s", pGlobalTXT_LocalizationStrings[104], HIDWORD(v60), pGlobalTXT_LocalizationStrings[97]);
-        v63 = 0;
+          v28 = v27 - 1;
+          v26->uReputation = v28;
+          if ( v28 < -5 )
+            v26->uReputation = -5;
         }
-    strcpy(&a1[100], pGlobalTXT_LocalizationStrings[68]);
-    strcpy(&a1[200], pGlobalTXT_LocalizationStrings[160]);
-    v42 = v63;
-    v43 = pDialogueWindow;
-    v44 = v63;
-    v66 = 0;
-    if ( v63 < pDialogueWindow->pNumPresenceButton )
+        if ( (unsigned __int8)byte_F8B1EF[uActiveCharacter] == pParty->uDaysPlayed % 7 )
         {
-        v61 = (GUIWindow *)&a1[100 * v63];
-        do
-            {
-            v45 = pFontArrus->CalcTextHeight((const char *)v61, &v57, 0, 0);
-            v66 = (DDM_DLV_Header *)((char *)v66 + v45);
-            v43 = pDialogueWindow;
-            v61 = (GUIWindow *)((char *)v61 + 100);
-            ++v44;
-            }
-            while ( v44 < pDialogueWindow->pNumPresenceButton );
+          if ( v26->uReputation <= -5 )
+          {
+            v30 = pParty->uDaysPlayed % 7 + 1;
+            LOBYTE(v30) = v30 | 0x80;
+            _42777D_CastSpell_UseWand_ShootArrow(SPELL_AIR_WIZARD_EYE, uActiveCharacter - 1, v30, 48, 0);
+          }
+          if ( v26->uReputation <= -10 )
+          {
+            v31 = pParty->uDaysPlayed % 7 + 1;
+            LOBYTE(v31) = v31 | 0x80;
+            _42777D_CastSpell_UseWand_ShootArrow(SPELL_SPIRIT_PRESERVATION, uActiveCharacter - 1, v31, 48, 0);
+            //v26 = v66;
+          }
+          if ( v26->uReputation <= -15 )
+          {
+            v32 = pParty->uDaysPlayed % 7 + 1;
+            LOBYTE(v32) = v32 | 0x80;
+            _42777D_CastSpell_UseWand_ShootArrow(SPELL_BODY_PROTECTION_FROM_MAGIC, uActiveCharacter - 1, v32, 48, 0);
+            //v26 = v66;
+          }
+          if ( v26->uReputation <= -20 )
+          {
+            v33 = pParty->uDaysPlayed % 7 + 1;
+            LOBYTE(v33) = v33 | 0x80;
+            _42777D_CastSpell_UseWand_ShootArrow(SPELL_LIGHT_HOUR_OF_POWER, uActiveCharacter - 1, v33, 48, 0);
+            //v26 = v66;
+          }
+          if ( v26->uReputation <= -25 )
+          {
+            v34 = pParty->uDaysPlayed % 7 + 1;
+            LOBYTE(v34) = v34 | 0x80;
+            _42777D_CastSpell_UseWand_ShootArrow(SPELL_LIGHT_DAY_OF_PROTECTION, uActiveCharacter - 1, v34, 48, 0);
+          }
         }
-    v46 = v43->pNumPresenceButton - v42;
-    v64 = (174 - (signed int)v66) / v46;
-    if ( v64 > 32 )
-        v64 = 32;
-    v47 = (174 - v64 * v46 - (signed int)v66) / 2 - v64 / 2 + 138;
-    v65 = v42 + v43->pStartingPosActiveItem;
-    if ( v42 + v43->pStartingPosActiveItem < v43->pStartingPosActiveItem + v43->pNumPresenceButton )
+        ++byte_F8B1EF[uActiveCharacter];
+        pPlayers[uActiveCharacter]->PlaySound(SPEECH_83, 0);
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[527], 2); // "Thank You!"
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
+        return;
+      }
+      ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);
+      PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
+      return;
+  }
+  //------------------------------------------------
+  if ( dialog_menu_id == HOUSE_DIALOGUE_LEARN_SKILLS )
+  {
+    if ( HouseUI_CheckIfPlayerCanInteract() )
+    {
+      //v61 = pDialogueWindow;
+      all_text_height = 0;
+      pCurrentItem = (signed __int64)(p2DEvents[(signed int)window_SpeakInHouse->ptr_1C - 1].flt_24 * 500.0);
+      v64 = (signed int)(pCurrentItem * (100 - pPlayers[uActiveCharacter]->GetMerchant())) / 100;
+      if ( v64 < (signed int)pCurrentItem / 3 )
+        v64 = (signed int)pCurrentItem / 3;
+      pCurrentItem = 0;
+      //if ( (signed int)pDialogueWindow->pStartingPosActiveItem >= v8 )
+      //goto LABEL_78;
+      for ( v62 = pDialogueWindow->pStartingPosActiveItem; (signed int)v62 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem; ++v62 )
+      {
+        v9 = pDialogueWindow->GetControl(v62)->msg_param - 36;
+        if ( byte_4ED970_skill_learn_ability_by_class_table[pPlayers[uActiveCharacter]->classType][v9] && !pPlayers[uActiveCharacter]->pActiveSkills[v9] )
         {
-        v61 = (GUIWindow *)(v42 + 2);
-        v66 = (DDM_DLV_Header *)&a1[100 * v42];
-        do
+          all_text_height += pFontArrus->CalcTextHeight(pSkillNames[v9], &tample_window, 0, 0);
+          //v66 = (DDM_DLV_Header *)((char *)v66 + pTextHeight);
+          ++pCurrentItem;
+        }
+        v11 = pDialogueWindow->pStartingPosActiveItem;
+      }
+      if ( pCurrentItem )
+      {
+        sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[401], v64);
+        tample_window.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf.data(), 3);
+        v64 = (149 - (signed int)all_text_height) / (signed int)pCurrentItem;
+        if ( v64 > 32 )
+          v64 = 32;
+        pCurrentItem = (signed int)(149 - pCurrentItem * v64 - (int)all_text_height) / 2 - v64 / 2 + 162;
+        v12 = pDialogueWindow;
+        result = pDialogueWindow->pStartingPosActiveItem;
+        v13 = result + pDialogueWindow->pNumPresenceButton;
+        v62 = pDialogueWindow->pStartingPosActiveItem;
+        if ( result < v13 )
+        {
+          all_text_height = 2;
+          while ( 1 )
+          {
+            v14 = v12->GetControl(v62);
+            v15 = v14;
+            v16 = v14->msg_param - 36;
+            if ( !byte_4ED970_skill_learn_ability_by_class_table[pPlayers[uActiveCharacter]->classType][v16] || pPlayers[uActiveCharacter]->pActiveSkills[v16] )
             {
-            v48 = v43->GetControl(v65);
-            v49 = (const char *)v66;
-            v50 = v48;
-            v48->uY = v64 + v47;
-            v51 = pFontArrus->CalcTextHeight(v49, &v57, 0, 0);
-            v52 = v50->uY;
-            v50->uHeight = v51;
-            v47 = v52 + v51 - 1;
-            v50->uW = v47;
-            v53 = WORD2(v59);
-            if ( (GUIWindow *)pDialogueWindow->pCurrentPosActiveItem != v61 )
-                v53 = WORD2(v58);
-            v57.DrawTitleText(pFontArrus, 0, v52, v53, (const char *)v66, 3u);
-            v43 = pDialogueWindow;
-            v66 = (DDM_DLV_Header *)((char *)v66 + 100);
-            v61 = (GUIWindow *)((char *)v61 + 1);
-            ++v65;
+              v15->uW = 0;
+              v15->uHeight = 0;
+              v15->uY = 0;
+            }
+            else
+            {
+              v15->uY = v64 + pCurrentItem;
+              pTextHeight = pFontArrus->CalcTextHeight(pSkillNames[v16], &tample_window, 0, 0);
+              v19 = v15->uY;
+              v15->uHeight = pTextHeight;
+              v20 = v19 + pTextHeight - 1;
+              v15->uW = v20;
+              pCurrentItem = v20;
+              pTextColor = TargetColor(0xFFu, 0xFFu, 0x9Bu);
+              if ( pDialogueWindow->pCurrentPosActiveItem != all_text_height )
+                pTextColor = TargetColor(0xFFu, 0xFFu, 0xFFu);
+              tample_window.DrawTitleText(pFontArrus, 0, v19, pTextColor, pSkillNames[v16], 3);
             }
-            while ( (signed int)v65 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
+            result = (int)pDialogueWindow;
+            ++v62;
+            //v66 = (DDM_DLV_Header *)((char *)v66 + 1);
+	        all_text_height++;
+            if ( (signed int)v62 >= pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem )
+              break;
+            v12 = pDialogueWindow;
+          }
         }
-    return;
+      }
+      else
+      {
+LABEL_78:
+        sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[544], pPlayers[uActiveCharacter]->pName, pClassNames[pPlayers[uActiveCharacter]->classType]);
+        strcat(pTmpBuf.data(), "\n \n");
+        strcat(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[528]);
+        pTextHeight = pFontArrus->CalcTextHeight(pTmpBuf.data(), &tample_window, 0, 0);
+        tample_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, TargetColor(0xFFu, 0xFFu, 0x9Bu), pTmpBuf.data(), 3);
+      }
     }
+  }
+  return;
+}
 
 //----- (004B4710) --------------------------------------------------------
 void TrainingDialog()