view UI/UIHouses.cpp @ 1396:e6908823897f

Research on #62
author Nomad
date Thu, 18 Jul 2013 17:29:20 +0200
parents 28f87f5234a1
children d4f57df4c299 468f434a8d8a
line wrap: on
line source

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "..\Texture.h"
#include "..\mm7_data.h"
#include "UIHouses.h"
#include "..\Party.h"
#include "..\texts.h"
#include "..\Events.h"
#include "..\Arcomage.h"
#include "..\LOD.h"
#include "..\Mouse.h"
#include "..\GUIWindow.h"
#include "..\GUIFont.h"
#include "..\Events2D.h"
#include "..\Overlays.h"
#include "..\Outdoor.h"
#include "..\AudioPlayer.h"
#include "..\VideoPlayer.h"
#include "..\Monsters.h"
#include "..\Viewport.h"
#include "..\Keyboard.h"
#include "..\IndoorCamera.h"
#include "..\MapInfo.h"
#include "..\Log.h"
#include "..\Game.h"

#include "..\stru159.h"
int uHouse_ExitPic; // weak

int dword_591080; // weak

int in_current_building_type; // 00F8B198
HOUSE_DIALOGUE_MENU dialog_menu_id; // 00F8B19C

#pragma pack(push, 1)
struct stru365_travel_info
{
  unsigned char uMapInfoID;
  unsigned char pSchedule[7];
  unsigned int uTravelTime;
  int arrival_x;
  int arrival_y;
  int arrival_z;
  int arrival_rot_y;
  unsigned int  uQuestBit;  // quest bit required to set for this travel option to be enabled; otherwise 0
};
#pragma pack(pop)
stru365_travel_info transport_schedule[35] =  // 004F09B0
{
  {MAP_STEADWICK,       {1, 0, 1, 0, 1, 0, 0},  2,  -18048,    4636,   833,  1536,  0},
  {MAP_PIERPONT,        {0, 1, 0, 1, 0, 1, 0},  2,   -2527,   -6773,  1153,   896,  0},
  {MAP_TATALIA,         {1, 0, 1, 0, 1, 0, 0},  2,    4730,  -10580,   320,  1024,  0},
  {MAP_HARMONDALE,      {0, 1, 0, 1, 0, 1, 0},  2,   -5692,   11137,     1,  1024,  0},
  {MAP_DEYJA,           {1, 0, 0, 1, 0, 0, 0},  3,    7227,  -16007,  2625,   640,  0},
  {MAP_BRAKADA_DESERT,  {0, 0, 1, 0, 0, 1, 0},  3,    8923,   17191,     1,   512,  0},
  {MAP_AVLEE,           {1, 0, 1, 0, 1, 0, 0},  3,   17059,   12331,   512,  1152,  0},
  {MAP_DEYJA,           {0, 1, 0, 0, 1, 0, 1},  2,    7227,  -16007,  2625,   640,  0},
  {MAP_HARMONDALE,      {0, 1, 0, 1, 0, 1, 0},  2,   -5692,   11137,     1,  1024,  0},
  {MAP_STEADWICK,       {1, 0, 1, 0, 1, 0, 0},  3,  -18048,    4636,   833,  1536,  0},
  {MAP_PIERPONT,        {0, 1, 0, 1, 0, 1, 0},  2,   -2527,   -6773,  1153,   896,  0},
  {MAP_STEADWICK,       {1, 0, 1, 0, 1, 0, 1},  3,  -18048,    4636,   833,  1536,  0},
  {MAP_HARMONDALE,      {0, 1, 0, 0, 0, 1, 0},  5,   -5692,   11137,     1,  1024,  0},
  {MAP_STEADWICK,       {0, 1, 0, 1, 0, 1, 0},  2,  -18048,    4636,   833,  1536,  0},
  {MAP_PIERPONT,        {0, 1, 0, 1, 0, 1, 0},  3,   -2527,  -16007,  1153,   896,  0},
  {MAP_DEYJA,           {0, 0, 1, 0, 0, 0, 1},  5,    7227,  -16007,  2625,   640,  0},
  {MAP_TATALIA,         {0, 1, 0, 1, 0, 1, 0},  2,   -2183,   -6941,    97,     0,  0},
  {MAP_AVLEE,           {1, 0, 0, 0, 1, 0, 0},  4,    7913,    9476,   193,     0,  0},
  {MAP_EVENMORN_ISLE,   {0, 0, 0, 0, 0, 0, 1},  7,   15616,    6390,   193,  1536,  PARTY_QUEST_EVENMORN_MAP_FOUND},
  {MAP_BRAKADA_DESERT,  {0, 0, 1, 0, 0, 0, 0},  6,   19171,  -19722,   193,  1024,  0},
  {MAP_AVLEE,           {0, 1, 0, 1, 0, 1, 0},  3,    7913,    9476,   193,     0,  0},
  {MAP_BRAKADA_DESERT,  {1, 0, 1, 0, 0, 0, 0},  6,   19171,  -19722,   193,  1024,  0},
  {MAP_TATALIA,         {1, 0, 1, 0, 1, 0, 0},  4,   -2183,   -6941,    97,     0,  0},
  {MAP_PIERPONT,        {0, 0, 0, 0, 0, 1, 0},  6,    -709,  -14087,   193,  1024,  0},
  {MAP_STEADWICK,       {0, 0, 0, 0, 0, 0, 1},  6,  -10471,   13497,   193,  1536,  0},
  {MAP_EVENMORN_ISLE,   {0, 1, 0, 1, 0, 0, 0},  1,   15616,    6390,   193,  1536,  PARTY_QUEST_EVENMORN_MAP_FOUND},
  {MAP_BRAKADA_DESERT,  {0, 1, 0, 1, 0, 0, 0},  1,   19171,  -19722,   193,  1024,  0},
  {MAP_STEADWICK,       {0, 1, 0, 1, 0, 1, 0},  2,  -10471,   13497,   193,  1536,  0},
  {MAP_BRAKADA_DESERT,  {1, 0, 1, 0, 0, 0, 0},  4,   19171,  -19722,   193,  1024,  0},
  {MAP_EVENMORN_ISLE,   {0, 0, 0, 0, 0, 0, 1},  5,   15616,    6390,   193,  1536,  PARTY_QUEST_EVENMORN_MAP_FOUND},
  {MAP_AVLEE,           {0, 0, 0, 0, 1, 0, 0},  5,    7913,    9476,   193,     0,  0},
  {MAP_STEADWICK,       {0, 1, 0, 0, 0, 1, 0},  4,  -10471,   13497,   193,  1536,  0},
  {MAP_PIERPONT,        {1, 0, 1, 0, 1, 0, 0},  3,    -709,  -14087,   193,  1024,  0},
  {MAP_TATALIA,         {0, 0, 0, 1, 0, 0, 0},  5,   -2183,   -6941,    97,     0,  0},
  {MAP_ARENA,           {0, 0, 0, 0, 0, 0, 1},  4,    3844,    2906,   193,  512,   0}
};

unsigned char transport_routes[20][4] =
{
  {  0,   1,   1,  34},  // HOUSE_STABLES_HARMONDALE
  {  2,   3,   4,   5},  // HOUSE_STABLES_STEADWICK
  {  6,   7,   8,   8},  // HOUSE_STABLES_56
  {  9,  10,  10,  10},  // HOUSE_STABLES_57
  { 11,  11,  12,  12},  // HOUSE_STABLES_58
  { 13,  13,  13,  13},  // HOUSE_STABLES_59
  { 14,  14,  15,  15},  // HOUSE_STABLES_60
  {255, 255, 255, 255},  // HOUSE_STABLES_61
  {255, 255, 255, 255},  // HOUSE_STABLES_62
  {255, 255, 255, 255},  // HOUSE_BOATS_63
  { 16,  17,  18,  19},  // HOUSE_BOATS_64
  { 18,  20,  21,  21},  // HOUSE_BOATS_65
  { 22,  23,  24,  25},  // HOUSE_BOATS_66
  { 22,  22,  23,  23},  // HOUSE_BOATS_67
  {255, 255, 255, 255},  // HOUSE_BOATS_68
  { 27,  28,  29,  30},  // HOUSE_BOATS_69
  { 31,  32,  33,  33},  // HOUSE_BOATS_70
  { 24,  24,  24,  24},  // HOUSE_BOATS_71
  {255, 255, 255, 255},  // HOUSE_BOATS_72
  {255, 255, 255, 255}   // HOUSE_BOATS_73
};





std::array<const stru159, 196> pAnimatedRooms = //0x4E5F70
{{
        {"",                            0x4, 0x1F4, 0, 0, 0},
        {"Human Armor01",               0x20, 0x2C0, 2, 58, 0},
        {"Necromancer Armor01",         0x20, 0x2D7, 2, 70, 0 },
        {"Dwarven Armor01",             0x20, 0x2EE, 2,  5, 0 },
        {"Wizard Armor",                0x20, 0x3BD, 2, 19, 0 },
        {"Warlock Armor",               0x20, 0x2D6, 2, 35, 0 },
        {"Elf Armor",                   0x20, 0x2BC, 2, 79, 0 },
        {"Human Alchemisht01",          0xE,  0x2BE, 4, 95, 0 },
        {"Necromancer Alchemist01",     0xE,  0x2D6, 4, 69, 0 },
        {"Dwarven Achemist01",          0xE,  0x387, 4,  4, 0 },
        {"Wizard Alchemist",            0xE,  0x232, 4, 25, 0 },
        {"Warlock Alchemist",           0xE,  0x2BE, 4, 42, 0 },
        {"Elf Alchemist",               0xE,  0x38A, 4, 84, 0 },
        {"Human Bank01",                0x6, 0x384, 22, 52, 0 },
        {"Necromancer Bank01",          0x6, 0x2D8, 22, 71, 0 },
        {"Dwarven Bank",                0x6, 0x2F3, 22,  6, 0 },
        {"Wizard Bank",                 0x6, 0x3BA, 22, 20, 0 },
        {"Warlock Bank",                0x6, 0x39F, 22, 36, 0 },
        {"Elf Bank",                    0x6, 0x2BC, 22, 71, 0 },
        {"Boat01",                      0xF,  0x4C, 28, 53, 3 },
        {"Boat01d",                     0xF,  0x4C, 28, 53, 3 },
        {"Human Magic Shop01",          0xA, 0x2C8,  3, 54, 0 },
        {"Necromancer Magic Shop01",    0xE, 0x2DC,  3, 66, 0 },
        {"Dwarven Magic Shop01",        0x2A, 0x2EF, 3, 91, 0 },
        {"Wizard Magic Shop",           0x1E, 0x2DF, 3, 15, 0 },
        {"Warlock Magic Shop",          0x7,  0x3B9, 3, 15, 0 },
        {"Elf Magic Shop",              0x24, 0x2CC, 3, 82, 0 },
        {"Human Stables01",             0x21, 0x31,  27, 48, 3 },
        {"Necromancer Stables",         0x21, 0x2DD, 27, 67, 3 },
        {"",                            0x21, 0x2F0, 27, 91, 3 },
        {"Wizard Stables",              0x21, 0x3BA, 27, 16, 3 },
        {"Warlock Stables",             0x21, 0x181, 27, 77, 3 },
        {"Elf Stables",                 0x21, 0x195, 27, 77, 3 },
        {"Human Tavern01",              0xD, 0x2C2,  21, 49, 0 },
        {"Necromancer Tavern01",        0xD, 0x3B0,  21, 57, 0 },
        {"Dwarven Tavern01",            0xD, 0x2FE,  21, 94, 0 },
        {"Wizard Tavern",               0xD, 0x3BB,  21, 17, 0 },
        {"Warlock Tavern",              0xD, 0x3A8,  21, 33, 0 },
        {"Elf Tavern",                  0xD, 0x2CD,  21, 78, 0 },
        {"Human Temple01",              0x24, 0x2DB, 23, 50, 3 },
        {"Necromancer Temple",          0x24, 0x2DF, 23, 60, 3 },
        {"Dwarven Temple01",            0x24, 0x2F1, 23, 86, 3 },
        {"Wizard Temple",               0x24, 0x2E0, 23, 10, 3 },
        {"Warlock Temple",              0x24, 0x3A4, 23, 27, 3 },
        {"Elf Temple",                  0x24, 0x2CE, 23, 72, 3 },
        {"Human Town Hall",             0x10, 0x39C, 17, 14, 0 },
        {"Necromancer Town Hall01",     0x10, 0x3A4, 17, 61, 0 },
        {"Dwarven Town Hall",           0x10, 0x2DB, 17, 88, 0 },
        {"Wizard Town Hall",            0x10, 0x3BD, 17, 11, 0 },
        {"Warlock Town Hall",           0x10, 0x2DB, 17, 28, 0 },
        {"Elf Town Hall",               0x10, 0x27A, 17, 73, 0 },
        {"Human Training Ground01",     0x18, 0x2C7, 30, 44, 0 },
        {"Necromancer Training Ground", 0x18, 0x3AD, 30, 62, 0 },
        {"Dwarven Training Ground",     0x18, 0x2F2, 30, 89, 0 },
        {"Wizard Training Ground",      0x18, 0x3A3, 30, 12, 0 },
        {"Warlock Training Ground",     0x18, 0x3A6, 30, 29, 0 },
        {"Elf Training Ground",         0x18, 0x19F, 30, 74, 0 },
        {"Human Weapon Smith01",        0x16, 0x2C1, 1, 45, 4 },
        {"Necromancer Weapon Smith01",  0x16, 0x2D9, 1, 63, 4 },
        {"Dwarven Weapon Smith01",      0x16, 0x2EE, 1, 82, 4 },
        {"Wizard Weapon Smith",         0x16, 0x2D5, 1, 13, 4 },
        {"Warlock Weapon Smith",        0x16, 0x2D7, 1, 23, 4 },
        {"Elf Weapon Smith",            0x16, 0x2CA, 1, 75, 4 },
        {"Air Guild",                   0x1D, 0xA4,   6, 1, 3 },
        {"Body Guild",                  0x19, 0x3BF, 11, 2, 0 },
        {"DarkGuild",                   0x19, 0x2D1, 13, 3, 0 },
        {"EarthGuild",                  0x19, 0x2CB, 8, 83, 0 },
        {"Fire Guild",                  0x1C, 0x2BF, 5, 56, 0 },
        {"Light Guild",                 0x1C, 0x2D5, 12, 46, 0 },
        {"Mind Guild",                  0x1C, 0xE5,  10, 40, 0 },
        {"Spirit Guild",                0x1C, 0x2D2,  9, 41, 0 },
        {"Water Guild",                 0x1B, 0x2D3,  7, 24, 0 },
        {"Lord And Judge Out01",        1, 0,        29, 39, 0 },
        {"Human Poor House 1",          8, 0,        29,  0, 0 },
        {"Human Poor House 2",          8, 0,        29,  0, 0 },
        {"Human Poor House 3",          8, 0,        29,  0, 0 },
        {"Human Medium House 1",        8, 0,        29,  0, 0 },
        {"Human Medium House 2",        8, 0,        29,  0, 0 },
        {"Human Medium House 3",        8, 0,        29,  0, 0 },
        {"Human Rich House 1",          8, 0,        29,  0, 0 },
        {"Human Rich House 2",          8, 0,        29,  0, 0 },
        {"Human Rich House 3",          8, 0,        29,  0, 0 },
        {"Elven Poor House 1",          8, 0,        29,  0, 0 },
        {"Elven Poor House 2",          8, 0,        29,  0, 0 },
        {"Elven Poor House 3",          8, 0,        29,  0, 0 },
        {"Elven Medium House 1",        8, 0,        29,  0, 0 },
        {"Elven Medium House 2",        8, 0,        29,  0, 0 },
        {"Elven Medium House 3",        8, 0,        29,  0, 0 },
        {"Elven Rich House 1",          8, 0,        29,  0, 0 },
        {"Elven Rich House 2",          8, 0,        29,  0, 0 },
        {"Elven Rich House 3",          8, 0,        29,  0, 0 },
        {"Dwarven Poor House 1",        8, 0,        29,  0, 0 },
        {"Dwarven Poor House 2",        8, 0,        29,  0, 0 },
        {"Dwarven Poor House 3",        8, 0,        29,  0, 0 },
        {"Dwarven Medium House 1",      8, 0,        29,  0, 0 },
        {"Dwarven Medium house 2",      8, 0,        29,  0, 0 },
        {"Dwarven Medium House 3",      8, 0,        29,  0, 0 },
        {"Dwarven Rich House 1",        8, 0,        29,  0, 0 },
        {"Dwarven Rich House 2",        8, 0,        29,  0, 0 },
        {"Dwarven Rich House 3",        8, 0,        29,  0, 0 },
        {"Wizard Poor House 1",         8, 0,        29,  0, 0 },
        {"Wizard Poor House 2",         8, 0,        29,  0, 0 },
        {"Wizard Poor House 3",         8, 0,        29,  0, 0 },
        {"Wizard Medium House 1",       8, 0,        29,  0, 0 },
        {"Wizard Medium House 2",       8, 0,        29,  0, 0 },
        {"Wizard Mdeium House 3",       8, 0,        29,  0, 0 },
        {"Wizard Rich House 1",         8, 0,        29,  0, 0 },
        {"Wizard Rich House 2",         8, 0,        29,  0, 0 },
        {"Wizard Rich House 3",         8, 0,        29,  0, 0 },
        {"Necromancer Poor House 1",    8, 0,        29,  0, 0 },
        {"Necromancer Poor House 2",    8, 0,        29,  0, 0 },
        {"Necromancer Poor House 3",    8, 0,        29,  0, 0 },
        {"Necromancer Medium House 1",  8, 0,        29,  0, 0 },
        {"Necromancer Medium House 2",  8, 0,        29,  0, 0 },
        {"Necromancer Mdeium House 3",  8, 0,        29,  0, 0 },
        {"Necromancer Rich House 1",    8, 0,        29,  0, 0 },
        {"Necromancer Rich House 2",    8, 0,        29,  0, 0 },
        {"Necromancer Rich House 3",    8, 0,        29,  0, 0 },
        {"Warlock Poor House 1",        8, 0,        29,  0, 0 },
        {"Warlock Poor House 2",        8, 0,        29,  0, 0 },
        {"Warlock Poor House 3",        8, 0,        29,  0, 0 },
        {"Warlock Medium House 1",      8, 0,        29,  0, 0 },
        {"Warlock Medium House 2",      8, 0,        29,  0, 0 },
        {"Warlock Mdeium House 3",      8, 0,        29,  0, 0 },
        {"Warlock Rich House 1",        8, 0,        29,  0, 0 },
        {"Warlock Rich House 2",        8, 0,        29,  0, 0 },
        {"Warlock Rich House 3",        8, 0,        29,  0, 0 },
        {"Out01 Temple of the Moon",    0x24, 0,     25,  0, 0 },
        {"Out01 Dragon Cave",           0x24, 0,     25,  0, 0 },
        {"Out02 Castle Harmondy",       0x24, 0,     25,  0, 0 },
        {"Out02 White Cliff Cave",      0x24, 0,     25,  0, 0 },
        {"Out03 Erathian Sewer",        0x24, 0,     25,  0, 0 },
        {"Out03 Fort Riverstride",      0x24, 0,     25,  0, 0 },
        {"Out03 Castle Gryphonheart",   0x24, 0,     25,  0, 0 },
        {"Out04 Elf Castle",            0x24, 0,     25,  0, 0 },
        {"Out04 Tularean Caves",        0x24, 0,     25,  0, 0 },
        {"Out04 Clanker's Laboratory",  0x24, 0,     25,  0, 0 },
        {"Out05 Hall of the Pit",       0x24, 0,     25,  0, 0 },
        {"Out05 Watchtower 6",          0x24, 0,     25,  0, 0 },
        {"Out06 School of Sorcery",     0x24, 0,     25,  0, 0 },
        {"Out06 Red Dwarf Mines",       0x24, 0,     25,  0, 0 },
        {"Out07 Castle Lambert",        0x24, 0,     25,  0, 0 },
        {"Out07 Walls of Mist",         0x24, 0,     25,  0, 0 },
        {"Out07 Temple of the Light",   0x24, 0,     25,  0, 0 },
        {"Out08 Evil Entrance",         0x24, 0,     25,  0, 0 },
        {"Out08 Breeding Zone",         0x24, 0,     25,  0, 0 },
        {"Out08 Temple of the Dark",    0x24, 0,     25,  0, 0 },
        {"Out09 Grand Temple of the Moon", 0x24, 0,     25,  0, 0 },
        {"Out09 Grand Tempple of the Sun", 0x24, 0,     25,  0, 0 },
        {"Out10 Thunderfist Mountain",  0x24, 0,     25,  0, 0 },
        {"Out10 The Maze",              0x24, 0,     25,  0, 0 },
        {"Out10 Connecting Tunnel Cave #1", 0x24, 0,     25,  0, 0 },
        {"",                            0x24, 0,     25,  0, 0 },
        {"",                            0x24, 0,     25,  0, 0 },
        {"Out11 Stone City",            0x24, 0,     25,  0, 0 },
        {"",                            0x24, 0,     25,  0, 0 },
        {"Out12 Colony Zod",            0x24, 0,     25,  0, 0 },
        {"Out12 Connecting Tunnel Cave #1", 0x24, 0,     25,  0, 0 },
        {"",                            0x24, 0,     25,  0, 0 },
        {"",                            0x24, 0,     25,  0, 0 },
        {"Out13 Mercenary Guild",       0x24, 0,     25,  0, 0 },
        {"Out13 Tidewater Caverns",     0x24, 0,     25,  0, 0 },
        {"Out13 Wine Cellar",           0x24, 0,     25,  0, 0 },
        {"Out14 Titan's Stronghold",    0x24, 0,     25,  0, 0 },
        {"Out14 Temple Of Baa",         0x24, 0,     25,  0, 0 },
        {"Out14 Hall under the Hill",   0x24, 0,     25,  0, 0 },
        {"Out15 The Linclon",           0x24, 0,     25,  0, 0 },
        {"Jail",                        0x24, 0, 31, 0, 0 },
        {"Harmondale Throne Room",      0x24, 0, 29, 0, 0 },
        {"Gryphonheart Throne Room",    0x24, 0, 20, 0, 0 },
        {"Elf Castle Throne Room",      0x24, 0, 20, 0, 0 },
        {"Wizard Castle Throne Room",   0x24, 0, 20, 0, 0 },
        {"Necromancer Casstle Trone Room", 0x24, 0, 20, 0, 0 },
        {"Master Thief",                0x24, 0, 29, 0, 0 },
        {"Dwarven King",                0x24, 0, 20, 0, 0 },
        {"Arms Master",                 0x24, 0, 29, 0, 0 },
        {"Warlock",                     0x24, 0, 29, 0, 0 },
        {"Lord Markam",                 0x24, 0, 20, 0, 0 },
        {"Arbiter Neutral Town",        0x24, 0, 29, 0, 0 },
        {"Arbiter Good Town",           0x24, 0, 29, 0, 0 },
        {"Arbiter Evil Town",           0x24, 0, 29, 0, 0 },
        {"Necromancer Throne Room Empty", 0x24, 0, 20, 0, 0 },
        {"",                            0x24, 0, 29, 0, 0 },
        {"",                            0x24, 0, 29, 0, 0 },
        {"",                            0x24, 0, 29, 0, 0 },
        {"",                            0x24, 0, 29, 0, 0 },
        {"Boat01",                      0xF, 0, 29, 53, 3 },
        {"",                            0x24, 0, 28, 0, 0 },
        {"",                            0x24, 0, 28, 0, 0 },
        {"",                            0x24, 0, 28, 0, 0 },
        {"",                            0x24, 0, 29, 0, 0 },
        {"Arbiter Room Neutral",        0x24, 0, 29, 0, 0 },
        {"Out02 Castle Harmondy Abandoned", 0x24, 0, 25, 0, 0 },
        {"Human Temple02",              0x24, 0x3AB, 23, 27, 0 },
        {"Player Castle Good",          0x24, 0, 25, 0, 0 },
        {"Player Castle Bad",           0x24, 0, 25, 0, 0}
}};


//----- (004B1784) --------------------------------------------------------
bool __cdecl HouseUI_CheckIfPlayerCanInteract()
{
  Player *pPlayer; // ebx@1
  bool result; // eax@2
  int v3; // eax@3
  GUIWindow v4; // [sp+4h] [bp-54h]@3

  pPlayer = pPlayers[uActiveCharacter];
  if ( pPlayer->CanAct() )
  {
    pDialogueWindow->pNumPresenceButton = dword_F8B1E0;
    result = 1;
  }
  else
  {
    pDialogueWindow->pNumPresenceButton = 0;
    memcpy(&v4, pPrimaryWindow, sizeof(v4));
    v4.uFrameX = 483;
    v4.uFrameWidth = 148;
    v4.uFrameZ = 334;
    sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[427], pPlayer->pName, pGlobalTXT_LocalizationStrings[562]);// 
                                                // "%s is in no condition to %s"
                                                // "do anything"
    v3 = pFontArrus->CalcTextHeight(pTmpBuf.data(), &v4, 0, 0);
    v4.DrawTitleText(pFontArrus, 0, (212 - v3) / 2 + 101, ui_house_player_cant_interact_color, pTmpBuf.data(), 3u);
    result = 0;
  }
  return result;
}

//----- (0044622E) --------------------------------------------------------
bool EnterHouse(enum HOUSE_ID uHouseID)
{
	//enum HOUSE_ID v1; // edi@1
	//int v2; // edi@5
	signed int uOpenTime; // eax@5
	signed int uCloseTime; // esi@5
	unsigned int v5; // esi@5
	int v6; // edx@5
	signed int am_pm_flag_open; // ecx@10
	signed int am_pm_flag_close; // eax@10
	int v9; // esi@10
	//unsigned int v10; // esi@16
	int v11; // ecx@17
	unsigned int v12; // kr00_4@25
	//Player *v13; // esi@25
	int v14; // eax@25
	//Player *v15; // esi@27
	//signed int v16; // eax@32
	unsigned int v17; // eax@37
	signed int v18; // edi@37
	signed int v19; // edi@41
	//unsigned int v20; // ecx@41
	//const char *v22; // [sp-4h] [bp-40h]@33
	char pContainer[40]; // [sp+Ch] [bp-30h]@32
	unsigned int v24; // [sp+34h] [bp-8h]@5
	//enum HOUSE_ID v25; // [sp+38h] [bp-4h]@1

	//v1 = uHouseID;
	//v25 = uHouseID;
	GameUI_Footer_TimedString[0] = 0;
	pFooterString[0] = 0;
	ShowStatusBarString("", 2u);
	if ( pMessageQueue_50CBD0->uNumMessages )
		pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
	viewparams->bRedrawGameUI = 1;
	uDialogueType = 0;
	pKeyActionMap->SetWindowInputStatus(3);
	pKeyActionMap->ResetKeys();
	if (uHouseID == HOUSE_600 || uHouseID == HOUSE_601)
		{
		GameOverMenu(0);
		return 0;
		}
	uOpenTime = p2DEvents[uHouseID - 1].uOpenTime;
	uCloseTime = p2DEvents[uHouseID - 1].uCloseTime;
	current_npc_text = 0;
	dword_F8B1E4 = 0;
	dword_F8B1F4 = 0;
	memset(byte_F8B1F0.data(), 0, 4);
	memset(player_levels.data(), 0, 16);
	pRenderer->ClearZBuffer(0, 479);

	if (((uCloseTime - 1 <= uOpenTime)&&((pParty->uCurrentHour <uOpenTime)&&(pParty->uCurrentHour >(uCloseTime - 1))))||
		((uCloseTime - 1 >  uOpenTime)&&((pParty->uCurrentHour < uOpenTime)||(pParty->uCurrentHour > (uCloseTime - 1))))) 

		{
		am_pm_flag_open = 0;
		am_pm_flag_close = 0;
		if (uOpenTime > 12 )
			{
			uOpenTime -= 12;
			am_pm_flag_open = 1;
			}
		if ( uCloseTime > 12 )
			{
			uCloseTime -= 12;
			am_pm_flag_close = 1;
			}
		sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[414], uOpenTime, aAMPMNames[am_pm_flag_open], 
			uCloseTime, aAMPMNames[am_pm_flag_close]); //"This place is open from %d%s to %d%s"
		ShowStatusBarString(pTmpBuf.data(), 2u);
		if ( uActiveCharacter )
			pPlayers[uActiveCharacter]->PlaySound(SPEECH_3, 0);
		return 0;
		}
	else
		{
		//v10 = uHouseID;
		if ( (signed int)uHouseID < 53 ) //entering shops and guilds
			{
			if ( !(pParty->field_3C._shop_ban_times[uHouseID])
				||  (pParty->field_3C._shop_ban_times[uHouseID] <= pParty->uTimePlayed) )
				{
				pParty->field_3C._shop_ban_times[uHouseID] = 0;
				}
			else
				{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[191], 2u);// "You've been banned from this shop!"
				return 0;
				}
			}
        pAudioPlayer->StopChannels(-1, -1);

		uCurrentHouse_Animation = p2DEvents[uHouseID - 1].uAnimationID;
		in_current_building_type = pAnimatedRooms[uCurrentHouse_Animation].uBuildingType;
		if ( in_current_building_type == BildingType_Throne_Room && pParty->uFine )   // going 2 jail
			{
			uCurrentHouse_Animation = (signed __int16)p2DEvents[186].uAnimationID;
			uHouseID = HOUSE_JAIL;
			pParty->uTimePlayed = pParty->uTimePlayed + 0x7620000;
			in_current_building_type = pAnimatedRooms[p2DEvents[HOUSE_LORD_AND_JUDGE_EMERALD_ISLE].uAnimationID].uBuildingType;
			++pParty->uNumPrisonTerms;
			pParty->uFine = 0;
			for (uint i = 0; i < 4; ++i)
				{
				pParty->pPlayers[i].uTimeToRecovery = 0;
				pParty->pPlayers[i].uNumDivineInterventionCastsThisDay = 0;
				pParty->pPlayers[i].SetVariable(VAR_Award, 87);
				}
			}
		++pIcons_LOD->uTexturePacksCount;
		if ( !pIcons_LOD->uNumPrevLoadedFiles )
			pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
		switch (pParty->alignment)
			{
		case PartyAlignment_Good:    sprintf(pContainer, "evt%02d-b", const_2()); break;
		case PartyAlignment_Neutral: sprintf(pContainer, "evt%02d", const_2()); break;
		case PartyAlignment_Evil:    sprintf(pContainer, "evt%02d-c", const_2()); break;
		default: assert(false);
			}

		v17 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
		pDialogueNPCCount = 0;
		pTexture_Dialogue_Background = &pIcons_LOD->pTextures[v17];
		uTextureID_right_panel_loop = uTextureID_right_panel;
		PrepareHouse(uHouseID);
		v18 = 1;
		uTextureID_right_panel_loop = uTextureID_right_panel;
		if ( uNumDialogueNPCPortraits == 1 )
			pDialogueNPCCount = 1;
		pVideoPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1u);  
		dword_5C35D4 = 1;
		if ( (signed int)uHouseID < 139 || (signed int)uHouseID > 172 )
        {
			if ( (signed int)uHouseID >= HOUSE_STABLES_HARMONDALE && (signed int)uHouseID <= 73 && !IsTravelAvailable(uHouseID - HOUSE_STABLES_HARMONDALE) )
            {
              return 1;
            }
        }
		else
		{ //guilds
			v19 = guild_mambership_flags[uHouseID - HOUSE_FIRE_GUILD_INITIATE_EMERALD_ISLE]; //guilds flags 
			//v20 = uHouseID;
			//if ( !((unsigned __int8)(0x80u >> v19 % 8) & pPlayers[uActiveCharacter]->_guilds_member_bits[v19 /8]) )
			if(_449B57_test_bit(pPlayers[uActiveCharacter]->_guilds_member_bits,v19))
            {
				PlayHouseSound(uHouseID, HouseSound_Greeting_2);
				return 1;
            }
		}
		PlayHouseSound(uHouseID, HouseSound_Greeting);
		dword_5C35D4 = 1;
		return 1;
		}
	}

//----- (0044606A) --------------------------------------------------------
void PrepareHouse(HOUSE_ID house)
{
  //unsigned int v1; // ebx@1
  //signed int v2; // esi@1
  //int uExitPic; // edi@1
  __int16 uExitMapID; // ax@2
  //int result; // eax@5
  //unsigned int *v6; // ecx@8
  int v7; // ebx@11
  //int v8; // esi@16
  //unsigned int v9; // eax@16
  //unsigned int v10; // eax@19
  //int v11; // ecx@19
  //char pContainer[36]; // [sp+Ch] [bp-54h]@16
  int v13; // [sp+30h] [bp-30h]@11
  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


  uAnimationID = p2DEvents[house - 1].uAnimationID;
  memset(npc_id_arr, 0, sizeof(npc_id_arr));
  uNumDialogueNPCPortraits = 0;
  uHouse_ExitPic = p2DEvents[house - 1].uExitPicID;
  if ( uHouse_ExitPic )
  {
    uExitMapID = p2DEvents[house - 1]._quest_related;
    if ( uExitMapID > 0 )
    {
	  if(_449B57_test_bit(pParty->_quest_bits,uExitMapID))
      {
        uHouse_ExitPic = 0;
      }
    }
  }

  dword_591080 = pAnimatedRooms[uAnimationID].house_npc_id;
  HouseNPCData[0]=0;
  uNumDialogueNPCPortraits = 0;
  if ( dword_591080 )
  {

    npc_id_arr[0] = dword_591080;
    uNumDialogueNPCPortraits = 1;
  }

  for (uint i = 1; i < pNPCStats->uNumNewNPCs; ++i)
  {
    if (pNPCStats->pNewNPCData[i].Location2D == house )
    {
      if (!(pNPCStats->pNewNPCData[i].uFlags & 0x80))
      {
        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;
      }
    }

  }

  for (uint i = 0; i < uNumDialogueNPCPortraits; ++i)
  {
   
    char icon_name[128];
    sprintfex(icon_name, "npc%03u", npc_id_arr[i]);
    pDialogueNPCPortraits[i] = pIcons_LOD->LoadTexturePtr(icon_name, TEXTURE_16BIT_PALETTE);
  }

  if (uHouse_ExitPic)
  {
    pDialogueNPCPortraits[uNumDialogueNPCPortraits] = pIcons_LOD->LoadTexturePtr(pHouse_ExitPictures[uHouse_ExitPic], TEXTURE_16BIT_PALETTE);
    ++uNumDialogueNPCPortraits;
    uHouse_ExitPic = p2DEvents[house - 1].uExitMapID;
  }
}
//----- (004B1E92) --------------------------------------------------------
void PlayHouseSound(unsigned int uHouseID, HouseSoundID sound)
{
    //if ( BYTE1(pAnimatedRooms[p2DEvents_minus1___02[26 * uHouseID]].field_C) )
    if ( pAnimatedRooms[p2DEvents[uHouseID].uAnimationID].uRoomSoundId )
        pAudioPlayer->PlaySound(
        //(SoundID)(a2 + 100 * (BYTE1(pAnimatedRooms[p2DEvents_minus1___02[26 * uHouseID]].field_C) + 300)),
        (SoundID)(sound + 100 * (pAnimatedRooms[p2DEvents[uHouseID].uAnimationID].uRoomSoundId + 300)),
        806, 0, -1, 0, 0, 0, 0);
}

//----- (004BCACC) --------------------------------------------------------
void __fastcall OnSelectShopDialogueOption(signed int uMessageParam)
{
  //unsigned int v1; // edi@1
  //signed int v2; // ebx@1
  //signed int v3; // ecx@2
  int v4; // eax@5
  signed int v5; // esi@5
  //Player *v6; // ecx@5
  //signed int v7; // edx@5
  GUIWindow *v8; // esi@10
  unsigned int v9; // eax@12
  int v10; // esi@31
  int v11; // edi@31
  int v12; // esi@32
  __int16 v13; // bp@32
  int v14; // edx@32
  GUIWindow *v15; // eax@32
  int v16; // eax@32
  int v17; // eax@33
  int v18; // eax@34
  int v19; // eax@35
  __int16 v20; // ax@37
  __int16 v21; // ax@76
  __int16 v22; // ax@107
  __int16 v23; // ax@132
  __int16 v24; // ax@163
  int v25; // esi@190
  __int16 v26; // ax@190
  char v27; // zf@190
  Player *v28; // edi@192
  int v29; // eax@204
  void *v30; // esi@208
  unsigned __int64 v31; // qax@208
  signed int v32; // edi@209
  int v33; // eax@210
  unsigned int v34; // eax@211
  //Player *v35; // edi@227
  signed int v36; // esi@227
  int v37; // ecx@227
  int v38; // esi@230
  int v39; // edx@235
  int v40; // edi@243
  unsigned __int64 v41; // qax@243
  //void *v42; // eax@244
  signed int v43; // edi@244
  int v44; // edx@244
  int v45; // eax@246
  unsigned int v46; // eax@247
  void *v47; // eax@250
  signed int v48; // edi@250
  int v49; // eax@252
  int v50; // eax@256
  unsigned int v51; // eax@257
  void *v52; // eax@260
  signed int v53; // edi@260
  int v54; // eax@262
  //signed int v55; // [sp+10h] [bp-10h]@1
  int v56; // [sp+14h] [bp-Ch]@31

  //v1 = 0;
  //v2 = a1;
  //v55 = a1;
  if ( !pDialogueWindow->pNumPresenceButton )
    return;
  pRenderer->ClearZBuffer(0, 479);
  //v3 = dword_F8B198;
  if ( dialog_menu_id != HOUSE_DIALOGUE_MAIN)
    v8 = window_SpeakInHouse;
  //else
  if (dialog_menu_id == HOUSE_DIALOGUE_MAIN)
  {
	  if ( in_current_building_type == BildingType_Training )
	  {
		if ( uMessageParam == HOUSE_DIALOGUE_TRAININGHALL_TRAIN )
		{
		  v4 = 0;
		  v5 = 0;
		  //v6 = pPlayers[uActiveCharacter];
		  //v7 = pPlayers[uActiveCharacter]->uLevel;
		  if ( pPlayers[uActiveCharacter]->uLevel > 0 )
		  {
			do
			  v4 += v5++ + 1;
			while ( v5 < pPlayers[uActiveCharacter]->uLevel );
		  }
		  if (pPlayers[uActiveCharacter]->uLevel < pMaxLevelPerTrainingHallType[(unsigned int)window_SpeakInHouse->ptr_1C - 89] &&
			  (signed __int64)pPlayers[uActiveCharacter]->uExperience < 1000 * v4)
			return;
		}
		pDialogueWindow->Release();
		pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x159u, WINDOW_MainMenu, 0, 0);
		pBtn_ExitCancel = pDialogueWindow->CreateButton(526, 445, 75, 33, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[74],// "End Conversation"
					                                    pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);
		pDialogueWindow->CreateButton(8, 8, 0x1C2, 0x140, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", nullptr);
//	LABEL_10:
		//v3 = dword_F8B198;
		v8 = window_SpeakInHouse;
	  }
	  //else
	  if ( in_current_building_type != BildingType_Training )
	  {
		  v8 = window_SpeakInHouse;
		  if ((in_current_building_type == BildingType_Stables || in_current_building_type == BildingType_Boats) &&
			  transport_schedule[transport_routes[(unsigned int)window_SpeakInHouse->ptr_1C - HOUSE_STABLES_HARMONDALE][uMessageParam - HOUSE_DIALOGUE_TRANSPORT_SCHEDULE_1]].pSchedule[pParty->uDaysPlayed % 7]
			|| in_current_building_type != BildingType_Temple || uMessageParam != BildingType_MindGuild )
		  {
		//LABEL_9:
			pDialogueWindow->Release();
			pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x159u, WINDOW_MainMenu, 0, 0);
			pBtn_ExitCancel = pDialogueWindow->CreateButton(526, 445, 75, 33, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[74],// "End Conversation"
						                                    pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);
			pDialogueWindow->CreateButton(8u, 8u, 0x1C2u, 0x140u, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", nullptr);
	//	LABEL_10:
			//v3 = dword_F8B198;
			v8 = window_SpeakInHouse;
		  }
		  else if (uActiveCharacter)
		  {
			if ( !pPlayers[uActiveCharacter]->IsPlayerHealableByTemple() )
			  return;
			v8 = window_SpeakInHouse;
		  }
	  }
	//LABEL_11:
	  dialog_menu_id = (HOUSE_DIALOGUE_MENU)uMessageParam;
	  if ( in_current_building_type < BildingType_19 )
	  {
		v9 = pIcons_LOD->LoadTexture(off_4F03B8[in_current_building_type], TEXTURE_16BIT_PALETTE);
		//v3 = dword_F8B198;
		ShopTexture = &pIcons_LOD->pTextures[v9];
	//LABEL_13:
		v8 = window_SpeakInHouse;
	  }
  }
  
  //NEW
  switch(in_current_building_type)
  {
    case BildingType_FireGuild:
    case BildingType_AirGuild:
    case BildingType_WaterGuild:
    case BildingType_EarthGuild:
    case BildingType_SpiritGuild:
    case BildingType_MindGuild:
    case BildingType_BodyGuild:
    case BildingType_LightGuild:
    case BildingType_DarkGuild:
    case BildingType_14:
    case BildingType_15:
    case BildingType_16:
    {
      if ( *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)v8->ptr_1C + 44472] >= (signed __int64)pParty->uTimePlayed &&
          *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)v8->ptr_1C + 44468] >= (signed __int64)pParty->uTimePlayed )
      {
        v32 = 0;
        do
        {
          //v33 = *(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 9 * (v32 + 12 * (unsigned int)v8->ptr_1C));
          v33 = pParty->SpellBooksInGuilds[v8->par1C-139][v32].uItemID;
          if ( v33 )
          {
            v34 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v33].pIconName, TEXTURE_16BIT_PALETTE);
            v8 = window_SpeakInHouse;
            ItemsInShopTexture[v32] = &pIcons_LOD->pTextures[v34];
          }
          ++v32;
        }
        while ( v32 < 12 );
      }
      else
      {
        SpellBookGenerator();
        v30 = window_SpeakInHouse->ptr_1C;
        v31 = pParty->uTimePlayed + (signed __int64)((double)(0xA8C000
                                   //* (signed int)p2DEvents_minus1[26 * (unsigned int)ptr_507BC0->ptr_1C])
                                  * (signed int)p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].field_1C) * 0.033333335);
        *(int *)&stru_AA1058[3].pSounds[8 * (int)v30 + 44468] = v31;
        *(int *)&stru_AA1058[3].pSounds[8 * (int)v30 + 44472] = HIDWORD(v31);
      }
      //return;
      break;
    }
    case BildingType_TownHall:
    {
      if ( uMessageParam == 99 )
      {
        v10 = (int)((char *)v8->ptr_1C - 102);
        v56 = v10;
        v11 = 8 * v10 + 11325428;
        if ( pParty->field_3C.field_0[2 * v10 + 1] >= (signed __int64)pParty->uTimePlayed
             && pParty->field_3C.field_0[2 * v10] >= (signed __int64)pParty->uTimePlayed )
        {
          v13 = 0;
        }
        else
        {
          v12 = v10;
          v13 = 0;
          pParty->field_75A[v12] = 0;
          *(_QWORD *)v11 = (signed __int64)((double)(309657600 * (pParty->uCurrentMonth + 12i64 * pParty->uCurrentYear - 14015)) * 0.033333335);
          v14 = rand() % 258;
          v15 = window_SpeakInHouse;
          pParty->field_750[v12] = v14 + 1;
          v16 = (int)((char *)v15->ptr_1C - 102);
          if ( v16 )
          {
            v17 = v16 - 1;
            if ( v17 )
            {
              v18 = v17 - 1;
              if ( v18 )
					{
						v19 = v18 - 1;
						if ( v19 )
						{
							if ( v19 == 1 )
							{
								while ( 1 )
								{
									v20 = pParty->field_750[v12];
									if ( (unsigned __int16)v20 < 0x73u || (unsigned __int16)v20 > 0x84u )
									{
										if ( ((unsigned __int16)v20 < 0xE8u || (unsigned __int16)v20 > 0xF9u)
										&& ((unsigned __int16)v20 < 0x85u || (unsigned __int16)v20 > 0x96u)
										&& ((unsigned __int16)v20 < 0x97u || (unsigned __int16)v20 > 0xBAu)
										&& ((unsigned __int16)v20 < 0xBEu || (unsigned __int16)v20 > 0xC0u)
										&& ((unsigned __int16)v20 < 0xC4u || (unsigned __int16)v20 > 0xC6u)
										&& ((unsigned __int16)v20 < 0x2Bu || (unsigned __int16)v20 > 0x2Du)
										&& ((unsigned __int16)v20 < 0x6Du || (unsigned __int16)v20 > 0x6Fu)
										&& ((unsigned __int16)v20 < 0x46u || (unsigned __int16)v20 > 0x48u)
										&& ((unsigned __int16)v20 < 0x100u || (unsigned __int16)v20 > 0x102u)
										&& ((unsigned __int16)v20 < 0xD9u || (unsigned __int16)v20 > 0xDBu)
										&& ((unsigned __int16)v20 < 0xC7u || (unsigned __int16)v20 > 0xC9u)
										&& ((unsigned __int16)v20 < 0xE5u || (unsigned __int16)v20 > 0xE7u)
										&& ((unsigned __int16)v20 < 0xDFu || (unsigned __int16)v20 > 0xE1u)
										&& ((unsigned __int16)v20 < 0x5Bu || (unsigned __int16)v20 > 0x5Du)
										&& ((unsigned __int16)v20 < 0x49u || (unsigned __int16)v20 > 0x4Bu)
										&& ((unsigned __int16)v20 < 0xFDu || (unsigned __int16)v20 > 0xFFu)
										&& ((unsigned __int16)v20 < 0x61u || (unsigned __int16)v20 > 0x63u)
										&& ((unsigned __int16)v20 < 0x10u || (unsigned __int16)v20 > 0x12u) )
											break;
									}
									pParty->field_750[v12] = rand() % 258 + 1;
								}
							}
						}
						else
						{
							while ( 1 )
							{
								v21 = pParty->field_750[v12];
								if ( (unsigned __int16)v21 < 0x73u || (unsigned __int16)v21 > 0x84u )
								{
								if ( ((unsigned __int16)v21 < 0xE8u || (unsigned __int16)v21 > 0xF9u)
									&& ((unsigned __int16)v21 < 0x85u || (unsigned __int16)v21 > 0x96u)
									&& ((unsigned __int16)v21 < 0x97u || (unsigned __int16)v21 > 0xBAu)
									&& ((unsigned __int16)v21 < 0xBEu || (unsigned __int16)v21 > 0xC0u)
									&& ((unsigned __int16)v21 < 0xC4u || (unsigned __int16)v21 > 0xC6u)
									&& ((unsigned __int16)v21 < 0x2Bu || (unsigned __int16)v21 > 0x2Du)
									&& ((unsigned __int16)v21 < 0x5Eu || (unsigned __int16)v21 > 0x60u)
									&& ((unsigned __int16)v21 < 0x43u || (unsigned __int16)v21 > 0x45u)
									&& ((unsigned __int16)v21 < 0x4Fu || (unsigned __int16)v21 > 0x51u)
									&& ((unsigned __int16)v21 < 0xC1u || (unsigned __int16)v21 > 0xC3u)
									&& ((unsigned __int16)v21 < 0x13u || (unsigned __int16)v21 > 0x15u)
									&& ((unsigned __int16)v21 < 0xFDu || (unsigned __int16)v21 > 0xFFu)
									&& ((unsigned __int16)v21 < 0x61u || (unsigned __int16)v21 > 0x63u)
									&& ((unsigned __int16)v21 < 0x6Au || (unsigned __int16)v21 > 0x6Cu) )
										break;
								}
								pParty->field_750[v12] = rand() % 258 + 1;
							}
						}
					}
					else
					{
						while ( 1 )
						{
							v22 = pParty->field_750[v12];
							if ( (unsigned __int16)v22 < 0x73u || (unsigned __int16)v22 > 0x84u )
							{
								if ( ((unsigned __int16)v22 < 0xE8u || (unsigned __int16)v22 > 0xF9u)
								&& ((unsigned __int16)v22 < 0x85u || (unsigned __int16)v22 > 0x96u)
								&& ((unsigned __int16)v22 < 0x97u || (unsigned __int16)v22 > 0xBAu)
								&& ((unsigned __int16)v22 < 0xBEu || (unsigned __int16)v22 > 0xC0u)
								&& ((unsigned __int16)v22 < 0xC4u || (unsigned __int16)v22 > 0xC6u)
								&& ((unsigned __int16)v22 < 0x2Bu || (unsigned __int16)v22 > 0x2Du)
								&& ((unsigned __int16)v22 < 0x31u || (unsigned __int16)v22 > 0x33u)
								&& ((unsigned __int16)v22 < 0x34u || (unsigned __int16)v22 > 0x36u)
								&& ((unsigned __int16)v22 < 0xFDu || (unsigned __int16)v22 > 0xFFu)
								&& ((unsigned __int16)v22 < 0x61u || (unsigned __int16)v22 > 0x63u)
								&& ((unsigned __int16)v22 < 0x1Cu || (unsigned __int16)v22 > 0x1Eu) )
								break;
							}
							pParty->field_750[v12] = rand() % 258 + 1;
						}
					}
				}
				else
				{
					while ( 1 )
					{
						v23 = pParty->field_750[v12];
						if ( (unsigned __int16)v23 < 0x73u || (unsigned __int16)v23 > 0x84u )
						{
						if ( ((unsigned __int16)v23 < 0xE8u || (unsigned __int16)v23 > 0xF9u)
							&& ((unsigned __int16)v23 < 0x85u || (unsigned __int16)v23 > 0x96u)
							&& ((unsigned __int16)v23 < 0x97u || (unsigned __int16)v23 > 0xBAu)
							&& ((unsigned __int16)v23 < 0xBEu || (unsigned __int16)v23 > 0xC0u)
							&& ((unsigned __int16)v23 < 0xC4u || (unsigned __int16)v23 > 0xC6u)
							&& ((unsigned __int16)v23 < 0x2Bu || (unsigned __int16)v23 > 0x2Du)
							&& ((unsigned __int16)v23 < 0x52u || (unsigned __int16)v23 > 0x54u)
							&& ((unsigned __int16)v23 < 4u || (unsigned __int16)v23 > 6u)
							&& ((unsigned __int16)v23 < 0x37u || (unsigned __int16)v23 > 0x39u)
							&& ((unsigned __int16)v23 < 0x3Au || (unsigned __int16)v23 > 0x3Cu)
							&& ((unsigned __int16)v23 < 0x3Du || (unsigned __int16)v23 > 0x3Fu)
							&& ((unsigned __int16)v23 < 0xFDu || (unsigned __int16)v23 > 0xFFu)
							&& ((unsigned __int16)v23 < 0x61u || (unsigned __int16)v23 > 0x63u)
							&& ((unsigned __int16)v23 < 0xCDu || (unsigned __int16)v23 > 0xCFu) )
								break;
						}
						pParty->field_750[v12] = rand() % 258 + 1;
					}
				}
			}
			else
			{
				while ( 1 )
				{
					v24 = pParty->field_750[v12];
					if ( (unsigned __int16)v24 < 0x73u || (unsigned __int16)v24 > 0x84u )
					{
						if ( ((unsigned __int16)v24 < 0xEBu || (unsigned __int16)v24 > 0xFCu)
						&& ((unsigned __int16)v24 < 0x85u || (unsigned __int16)v24 > 0x96u)
						&& ((unsigned __int16)v24 < 0x97u || (unsigned __int16)v24 > 0xBAu)
						&& ((unsigned __int16)v24 < 0xBEu || (unsigned __int16)v24 > 0xC0u)
						&& ((unsigned __int16)v24 < 0xC4u || (unsigned __int16)v24 > 0xC6u)
						&& ((unsigned __int16)v24 < 0x2Bu || (unsigned __int16)v24 > 0x2Du)
						&& ((unsigned __int16)v24 < 0xCDu || (unsigned __int16)v24 > 0xCFu)
						&& ((unsigned __int16)v24 < 0x5Eu || (unsigned __int16)v24 > 0x60u)
						&& ((unsigned __int16)v24 < 0xFDu || (unsigned __int16)v24 > 0xFFu)
						&& ((unsigned __int16)v24 < 0x6Du || (unsigned __int16)v24 > 0x6Fu)
						&& ((unsigned __int16)v24 < 0x61u || (unsigned __int16)v24 > 0x63u) )
							break;
					}
					pParty->field_750[v12] = rand() % 258 + 1;
				}
			}
			v10 = v56;
		}
		v25 = v10;
		v26 = pParty->field_750[v25];
		v27 = pParty->field_75A[v25] == v13;
		word_F8B1A0 = pParty->field_750[v25];
		if ( v27 )
		{
			//v1 = 0;
			v27 = v26 == v13;
			v29 = (int)pNPCTopics[351].pText;
			if ( v27 )
				v29 = (int)pNPCTopics[353].pText;
			dword_F8B1A4 = (char *)v29;
		}
		else
		{
			if ( v26 != v13 )
			{
				party_finds_gold(100 * pMonsterStats->pInfos[(unsigned __int16)v26].uLevel, 0);
				v28 = pParty->pPlayers;
				do
				{
					v28->SetVariable(VAR_Award, 86);
					++v28;
				}
				while ( (signed int)v28 < (signed int)pParty->pHirelings );
				pParty->uNumBountiesCollected += 100 * pMonsterStats->pInfos[pParty->field_750[v25]].uLevel;
				pParty->field_750[v25] = v13;
				pParty->field_75A[v25] = v13;
			}
			//v1 = 0;
			dword_F8B1A4 = pNPCTopics[352].pText;
		}
	}
	else if ( uMessageParam == HOUSE_DIALOGUE_TOWNHALL_100 )
	{
		pKeyActionMap->EnterText(1, 10, v8);
	}
	break;
	}
    case BildingType_Bank:
    {
      if ( dialog_menu_id >= 7 && dialog_menu_id <= 8 )
        pKeyActionMap->EnterText(1, 10, v8);
      return;
      break;
    }
    case BildingType_WeaponShop:
    case BildingType_ArmorShop:
    case BildingType_MagicShop:
    case BildingType_AlchemistShop:
    case BildingType_Tavern:
    case BildingType_Temple:
    case BildingType_Training:
    {
      break;
    }
    default:
    {
      return;
      break;
    }
  }

  /*
  if ( in_current_building_type > BildingType_Tavern )
  {
    if ( in_current_building_type == BildingType_Bank )
    {
      if ( dialog_menu_id >= 7 && dialog_menu_id <= 8 )
        pKeyActionMap->EnterText(1, 10, v8);
      return;
    }
    if ( in_current_building_type != BildingType_Temple && in_current_building_type != BildingType_Training )
      return;
  }
  //else
  if ( in_current_building_type < BildingType_Tavern )
  {
      if (in_current_building_type <= 0)
        return;
      if ( in_current_building_type > BildingType_AlchemistShop )
      {
        if ( in_current_building_type <= BildingType_16 )
        {
          if ( (signed __int64)__PAIR__(
                                 *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)v8->ptr_1C + 44472],
                                 *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)v8->ptr_1C + 44468]) >= (signed __int64)pParty->uTimePlayed )
          {
            v32 = 0;
            do
            {
              //v33 = *(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 9 * (v32 + 12 * (unsigned int)v8->ptr_1C));
				v33 = pParty->SpellBooksInGuilds[v8->par1C-139][v32].uItemID;
              if ( v33 )
              {
                v34 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v33].pIconName, TEXTURE_16BIT_PALETTE);
                v8 = window_SpeakInHouse;
                ItemsInShopTexture[v32] = &pIcons_LOD->pTextures[v34];
              }
              ++v32;
            }
            while ( v32 < 12 );
          }
          else
          {
            SpellBookGenerator();
            v30 = window_SpeakInHouse->ptr_1C;
            v31 = pParty->uTimePlayed
                + (signed __int64)((double)(0xA8C000
                                          //* (signed int)p2DEvents_minus1[26 * (unsigned int)ptr_507BC0->ptr_1C])
                                          * (signed int)p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].field_1C)
                                 * 0.033333335);
            *(int *)&stru_AA1058[3].pSounds[8 * (int)v30 + 44468] = v31;
            *(int *)&stru_AA1058[3].pSounds[8 * (int)v30 + 44472] = HIDWORD(v31);
          }
          return;
        }
        if ( in_current_building_type != BildingType_TownHall )
          return;
		if ( in_current_building_type == BildingType_TownHall )
		{
			if ( uMessageParam == 99 )
			{
			  v10 = (int)((char *)v8->ptr_1C - 102);
			  v56 = v10;
			  v11 = 8 * v10 + 11325428;
			  if ( (signed __int64)__PAIR__(pParty->field_3C.field_0[2 * v10 + 1], pParty->field_3C.field_0[2 * v10]) >= (signed __int64)pParty->uTimePlayed )
			  {
				v13 = 0;
			  }
			  else
			  {
				v12 = v10;
				v13 = 0;
				pParty->field_75A[v12] = 0;
				*(_QWORD *)v11 = (signed __int64)((double)(309657600 * (pParty->uCurrentMonth + 12i64 * pParty->uCurrentYear - 14015)) * 0.033333335);
				v14 = rand() % 258;
				v15 = window_SpeakInHouse;
				pParty->field_750[v12] = v14 + 1;
				v16 = (int)((char *)v15->ptr_1C - 102);
				if ( v16 )
				{
				  v17 = v16 - 1;
				  if ( v17 )
				  {
					v18 = v17 - 1;
					if ( v18 )
					{
					  v19 = v18 - 1;
					  if ( v19 )
					  {
						if ( v19 == 1 )
						{
						  while ( 1 )
						  {
							v20 = pParty->field_750[v12];
							if ( (unsigned __int16)v20 < 0x73u || (unsigned __int16)v20 > 0x84u )
							{
							  if ( ((unsigned __int16)v20 < 0xE8u || (unsigned __int16)v20 > 0xF9u)
								&& ((unsigned __int16)v20 < 0x85u || (unsigned __int16)v20 > 0x96u)
								&& ((unsigned __int16)v20 < 0x97u || (unsigned __int16)v20 > 0xBAu)
								&& ((unsigned __int16)v20 < 0xBEu || (unsigned __int16)v20 > 0xC0u)
								&& ((unsigned __int16)v20 < 0xC4u || (unsigned __int16)v20 > 0xC6u)
								&& ((unsigned __int16)v20 < 0x2Bu || (unsigned __int16)v20 > 0x2Du)
								&& ((unsigned __int16)v20 < 0x6Du || (unsigned __int16)v20 > 0x6Fu)
								&& ((unsigned __int16)v20 < 0x46u || (unsigned __int16)v20 > 0x48u)
								&& ((unsigned __int16)v20 < 0x100u || (unsigned __int16)v20 > 0x102u)
								&& ((unsigned __int16)v20 < 0xD9u || (unsigned __int16)v20 > 0xDBu)
								&& ((unsigned __int16)v20 < 0xC7u || (unsigned __int16)v20 > 0xC9u)
								&& ((unsigned __int16)v20 < 0xE5u || (unsigned __int16)v20 > 0xE7u)
								&& ((unsigned __int16)v20 < 0xDFu || (unsigned __int16)v20 > 0xE1u)
								&& ((unsigned __int16)v20 < 0x5Bu || (unsigned __int16)v20 > 0x5Du)
								&& ((unsigned __int16)v20 < 0x49u || (unsigned __int16)v20 > 0x4Bu)
								&& ((unsigned __int16)v20 < 0xFDu || (unsigned __int16)v20 > 0xFFu)
								&& ((unsigned __int16)v20 < 0x61u || (unsigned __int16)v20 > 0x63u)
								&& ((unsigned __int16)v20 < 0x10u || (unsigned __int16)v20 > 0x12u) )
								break;
							}
							pParty->field_750[v12] = rand() % 258 + 1;
						  }
						}
					  }
					  else
					  {
						while ( 1 )
						{
						  v21 = pParty->field_750[v12];
						  if ( (unsigned __int16)v21 < 0x73u || (unsigned __int16)v21 > 0x84u )
						  {
							if ( ((unsigned __int16)v21 < 0xE8u || (unsigned __int16)v21 > 0xF9u)
							  && ((unsigned __int16)v21 < 0x85u || (unsigned __int16)v21 > 0x96u)
							  && ((unsigned __int16)v21 < 0x97u || (unsigned __int16)v21 > 0xBAu)
							  && ((unsigned __int16)v21 < 0xBEu || (unsigned __int16)v21 > 0xC0u)
							  && ((unsigned __int16)v21 < 0xC4u || (unsigned __int16)v21 > 0xC6u)
							  && ((unsigned __int16)v21 < 0x2Bu || (unsigned __int16)v21 > 0x2Du)
							  && ((unsigned __int16)v21 < 0x5Eu || (unsigned __int16)v21 > 0x60u)
							  && ((unsigned __int16)v21 < 0x43u || (unsigned __int16)v21 > 0x45u)
							  && ((unsigned __int16)v21 < 0x4Fu || (unsigned __int16)v21 > 0x51u)
							  && ((unsigned __int16)v21 < 0xC1u || (unsigned __int16)v21 > 0xC3u)
							  && ((unsigned __int16)v21 < 0x13u || (unsigned __int16)v21 > 0x15u)
							  && ((unsigned __int16)v21 < 0xFDu || (unsigned __int16)v21 > 0xFFu)
							  && ((unsigned __int16)v21 < 0x61u || (unsigned __int16)v21 > 0x63u)
							  && ((unsigned __int16)v21 < 0x6Au || (unsigned __int16)v21 > 0x6Cu) )
							  break;
						  }
						  pParty->field_750[v12] = rand() % 258 + 1;
						}
					  }
					}
					else
					{
					  while ( 1 )
					  {
						v22 = pParty->field_750[v12];
						if ( (unsigned __int16)v22 < 0x73u || (unsigned __int16)v22 > 0x84u )
						{
						  if ( ((unsigned __int16)v22 < 0xE8u || (unsigned __int16)v22 > 0xF9u)
							&& ((unsigned __int16)v22 < 0x85u || (unsigned __int16)v22 > 0x96u)
							&& ((unsigned __int16)v22 < 0x97u || (unsigned __int16)v22 > 0xBAu)
							&& ((unsigned __int16)v22 < 0xBEu || (unsigned __int16)v22 > 0xC0u)
							&& ((unsigned __int16)v22 < 0xC4u || (unsigned __int16)v22 > 0xC6u)
							&& ((unsigned __int16)v22 < 0x2Bu || (unsigned __int16)v22 > 0x2Du)
							&& ((unsigned __int16)v22 < 0x31u || (unsigned __int16)v22 > 0x33u)
							&& ((unsigned __int16)v22 < 0x34u || (unsigned __int16)v22 > 0x36u)
							&& ((unsigned __int16)v22 < 0xFDu || (unsigned __int16)v22 > 0xFFu)
							&& ((unsigned __int16)v22 < 0x61u || (unsigned __int16)v22 > 0x63u)
							&& ((unsigned __int16)v22 < 0x1Cu || (unsigned __int16)v22 > 0x1Eu) )
							break;
						}
						pParty->field_750[v12] = rand() % 258 + 1;
					  }
					}
				  }
				  else
				  {
					while ( 1 )
					{
					  v23 = pParty->field_750[v12];
					  if ( (unsigned __int16)v23 < 0x73u || (unsigned __int16)v23 > 0x84u )
					  {
						if ( ((unsigned __int16)v23 < 0xE8u || (unsigned __int16)v23 > 0xF9u)
						  && ((unsigned __int16)v23 < 0x85u || (unsigned __int16)v23 > 0x96u)
						  && ((unsigned __int16)v23 < 0x97u || (unsigned __int16)v23 > 0xBAu)
						  && ((unsigned __int16)v23 < 0xBEu || (unsigned __int16)v23 > 0xC0u)
						  && ((unsigned __int16)v23 < 0xC4u || (unsigned __int16)v23 > 0xC6u)
						  && ((unsigned __int16)v23 < 0x2Bu || (unsigned __int16)v23 > 0x2Du)
						  && ((unsigned __int16)v23 < 0x52u || (unsigned __int16)v23 > 0x54u)
						  && ((unsigned __int16)v23 < 4u || (unsigned __int16)v23 > 6u)
						  && ((unsigned __int16)v23 < 0x37u || (unsigned __int16)v23 > 0x39u)
						  && ((unsigned __int16)v23 < 0x3Au || (unsigned __int16)v23 > 0x3Cu)
						  && ((unsigned __int16)v23 < 0x3Du || (unsigned __int16)v23 > 0x3Fu)
						  && ((unsigned __int16)v23 < 0xFDu || (unsigned __int16)v23 > 0xFFu)
						  && ((unsigned __int16)v23 < 0x61u || (unsigned __int16)v23 > 0x63u)
						  && ((unsigned __int16)v23 < 0xCDu || (unsigned __int16)v23 > 0xCFu) )
						  break;
					  }
					  pParty->field_750[v12] = rand() % 258 + 1;
					}
				  }
				}
				else
				{
				  while ( 1 )
				  {
					v24 = pParty->field_750[v12];
					if ( (unsigned __int16)v24 < 0x73u || (unsigned __int16)v24 > 0x84u )
					{
					  if ( ((unsigned __int16)v24 < 0xEBu || (unsigned __int16)v24 > 0xFCu)
						&& ((unsigned __int16)v24 < 0x85u || (unsigned __int16)v24 > 0x96u)
						&& ((unsigned __int16)v24 < 0x97u || (unsigned __int16)v24 > 0xBAu)
						&& ((unsigned __int16)v24 < 0xBEu || (unsigned __int16)v24 > 0xC0u)
						&& ((unsigned __int16)v24 < 0xC4u || (unsigned __int16)v24 > 0xC6u)
						&& ((unsigned __int16)v24 < 0x2Bu || (unsigned __int16)v24 > 0x2Du)
						&& ((unsigned __int16)v24 < 0xCDu || (unsigned __int16)v24 > 0xCFu)
						&& ((unsigned __int16)v24 < 0x5Eu || (unsigned __int16)v24 > 0x60u)
						&& ((unsigned __int16)v24 < 0xFDu || (unsigned __int16)v24 > 0xFFu)
						&& ((unsigned __int16)v24 < 0x6Du || (unsigned __int16)v24 > 0x6Fu)
						&& ((unsigned __int16)v24 < 0x61u || (unsigned __int16)v24 > 0x63u) )
						break;
					}
					pParty->field_750[v12] = rand() % 258 + 1;
				  }
				}
				v10 = v56;
			  }
			  v25 = v10;
			  v26 = pParty->field_750[v25];
			  v27 = pParty->field_75A[v25] == v13;
			  word_F8B1A0 = pParty->field_750[v25];
			  if ( v27 )
			  {
				//v1 = 0;
				v27 = v26 == v13;
				v29 = (int)pNPCTopics[351].pText;
				if ( v27 )
				  v29 = (int)pNPCTopics[353].pText;
				dword_F8B1A4 = (char *)v29;
			  }
			  else
			  {
				if ( v26 != v13 )
				{
				  party_finds_gold(100 * pMonsterStats->pInfos[(unsigned __int16)v26].uLevel, 0);
				  v28 = pParty->pPlayers;
				  do
				  {
					v28->SetVariable(VAR_Award, 86);
					++v28;
				  }
				  while ( (signed int)v28 < (signed int)pParty->pHirelings );
				  pParty->uNumBountiesCollected += 100 * pMonsterStats->pInfos[pParty->field_750[v25]].uLevel;
				  pParty->field_750[v25] = v13;
				  pParty->field_75A[v25] = v13;
				}
				//v1 = 0;
				dword_F8B1A4 = pNPCTopics[352].pText;
			  }
			}
			else if ( uMessageParam == 100 )
			{
			  pKeyActionMap->EnterText(1, 10, v8);
			}
		}
	  }
  }
  */
  

//LABEL_196:
  switch ( uMessageParam )
  {
    case HOUSE_DIALOGUE_LEARN_SKILLS:
    {
      pDialogueWindow->eWindowType = WINDOW_MainMenu;
      UI_CreateEndConversationButton();
      FillAviableSkillsToTeach(in_current_building_type);
      break;
    }
    case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_MAIN:
    {
      pDialogueWindow->eWindowType = WINDOW_MainMenu;
      UI_CreateEndConversationButton();
      sub_4B3A72(in_current_building_type);
      break;
    }
    case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_RULES:
    case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_VICTORY_CONDITIONS:
    {
      dialog_menu_id = (HOUSE_DIALOGUE_MENU)uMessageParam;
      break;
    }
    case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_RESULT:
    {
      /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
      {
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_PlayArcomage;
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v1;
        *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = v1;
        ++pMessageQueue_50CBD0->uNumMessages;
      }*/
      pMessageQueue_50CBD0->AddMessage(UIMSG_PlayArcomage, 0, 0);
      dialog_menu_id = HOUSE_DIALOGUE_TAVERN_ARCOMAGE_RESULT;
      break;
    }
    case HOUSE_DIALOGUE_SHOP_BUY_STANDARD:
    case HOUSE_DIALOGUE_SHOP_BUY_SPECIAL:
    {
      if ( pParty->field_3C.field_50[(unsigned int)v8->ptr_1C] < (signed __int64)pParty->uTimePlayed )
      {
        GenerateStandartShopItems();
        GenerateSpecialShopItems();
        pParty->field_3C.field_50[window_SpeakInHouse->par1C] = pParty->uTimePlayed + (signed __int64)((double)(11059200 * (signed int)p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].field_1C) * 0.033333335);
      }
      if ( uMessageParam == HOUSE_DIALOGUE_SHOP_BUY_STANDARD )
      {
        if ( uItemsAmountPerShopType[p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].uType] )
        {
          for ( v43 = 0; v43 < (unsigned __int8)uItemsAmountPerShopType[p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].uType]; ++v43 )
          {
            if ( pParty->StandartItemsInShops[(int)window_SpeakInHouse->ptr_1C][v43].uItemID )
            {
              v46 = pIcons_LOD->LoadTexture(pItemsTable->pItems[pParty->StandartItemsInShops[(int)window_SpeakInHouse->ptr_1C][v43].uItemID].pIconName, TEXTURE_16BIT_PALETTE);
              ItemsInShopTexture[v43] = &pIcons_LOD->pTextures[v46];
            }
          }
        }
        if ( in_current_building_type == BildingType_WeaponShop )
        {
          v48 = 0;
          if ( uItemsAmountPerShopType[p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].uType] )
          {
            do
            {
              if ( pParty->StandartItemsInShops[(int)window_SpeakInHouse->ptr_1C][v48].uItemID)
                word_F8B158[v48] = rand() % (300 - ItemsInShopTexture[v48]->uTextureHeight);
              ++v48;
              }
              while ( v48 < (unsigned __int8)uItemsAmountPerShopType[p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].uType] );
            }
          }
        }
        if ( uMessageParam == HOUSE_DIALOGUE_SHOP_BUY_SPECIAL )
        {
          if ( uItemsAmountPerShopType[p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].uType] )
          {
            for ( v43 = 0; v43 < (unsigned __int8)uItemsAmountPerShopType[p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].uType]; ++v43 )
            {
              if ( pParty->SpecialItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][(signed int)v43].uItemID )
              {
                v51 = pIcons_LOD->LoadTexture(pItemsTable->pItems[pParty->SpecialItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][(signed int)v43].uItemID].pIconName, TEXTURE_16BIT_PALETTE);
                ItemsInShopTexture[v43] = &pIcons_LOD->pTextures[v51];
              }
            }
          }
          if ( in_current_building_type == BildingType_WeaponShop )
          {
            v53 = 0;
            if ( uItemsAmountPerShopType[p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].uType] )
            {
              do
              {
                if (pParty->SpecialItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][v53].uItemID)
                  word_F8B158[v53] = rand() % (300 - ItemsInShopTexture[v53]->uTextureHeight);
                ++v53;
              }
              while ( v53 < (unsigned __int8)uItemsAmountPerShopType[p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].uType ] );
            }
          }
        }
        break;
    }
    case HOUSE_DIALOGUE_SHOP_SELL:
    case HOUSE_DIALOGUE_SHOP_IDENTIFY:
    case HOUSE_DIALOGUE_SHOP_REPAIR:
    {
      dialog_menu_id = (HOUSE_DIALOGUE_MENU)uMessageParam;
      sub_421B2C_PlaceInInventory_or_DropPickedItem();
      break;
    }
    case HOUSE_DIALOGUE_SHOP_DISPLAY_EQUIPMENT:
    {
      pDialogueWindow->eWindowType = WINDOW_MainMenu;
      UI_CreateEndConversationButton();
      sub_4B3AD4(in_current_building_type);
      break;
    }
    default:
    {
      if( uMessageParam >= HOUSE_DIALOGUE_36 && uMessageParam <= HOUSE_DIALOGUE_GUILD_LEARN_SKILL )
      {
        //v35 = pPlayers[uActiveCharacter];
        //v36 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (unsigned int)v8->ptr_1C] * 500.0);
        v36 = (signed __int64)(p2DEvents[(unsigned int)v8->ptr_1C - 1].flt_24 * 500.0);
        v37 = v36 * (100 - pPlayers[uActiveCharacter]->GetMerchant()) / 100;
        if ( v37 < v36 / 3 )
        v37 = v36 / 3;
        //if (false)
        if(byte_4ED970_skill_learn_ability_by_class_table[pPlayers[uActiveCharacter]->classType][uMessageParam-36])
        //if ( *(&byte_4ED94C[37 * v35->uClass] + v55) )
        {
          //v38 = (int)(&pPlayers[uActiveCharacter]->uIntelligence + uMessageParam);
          if ( !pPlayers[uActiveCharacter]->pActiveSkills[uMessageParam - 36] )
          {
            if ( pParty->uNumGold < v37 )
            {
              ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);
              if ( in_current_building_type == BildingType_Training || in_current_building_type == BildingType_Tavern )
                v39 = 4;
              else
                v39 = 2;
              PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, (HouseSoundID)v39);
            }
            else
            {
              Party::TakeGold(v37);
              dword_F8B1E4 = 1;
              pPlayers[uActiveCharacter]->pActiveSkills[uMessageParam - 36] = 1;
              pPlayers[uActiveCharacter]->PlaySound(SPEECH_78, 0);
            }
          }
        }
      }
      break;
    }
  }
  /*
  if ( uMessageParam != 95 && uMessageParam != 2 )
  {
    if ( uMessageParam == 3 )
    {
      dialog_menu_id = 3;
    }
    else
    {
      if ( uMessageParam == 4 )
      {
        dialog_menu_id = 4;
      }
      else
      {
        if ( uMessageParam != 5 )
        {
          if ( uMessageParam > 35 )
          {
            if ( uMessageParam <= 72 )
            {
              v35 = pPlayers[uActiveCharacter];
              //v36 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (unsigned int)v8->ptr_1C] * 500.0);
              v36 = (signed __int64)(p2DEvents[(unsigned int)v8->ptr_1C - 1].flt_24 * 500.0);
              v37 = v36 * (100 - pPlayers[uActiveCharacter]->GetMerchant()) / 100;
              if ( v37 < v36 / 3 )
                v37 = v36 / 3;
              
              __debugbreak();
              //pSkillAvailabilityPerClass[8 + v58->uClass][4 + v23]
              // or
              //byte_4ED970_skill_learn_ability_by_class_table[v58->uClass][v23 - 36]
              // or
              //byte_4ED970_skill_learn_ability_by_class_table[v58->uClass - 1][v23 + 1]

              if (false)
              //if ( *(&byte_4ED94C[37 * v35->uClass] + v55) )
              {
                v38 = (int)(&v35->uIntelligence + uMessageParam);
                if ( !*(short *)v38 )
                {
                  if ( pParty->uNumGold < v37 )
                  {
                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
                    if ( in_current_building_type == BildingType_Training || in_current_building_type == BildingType_Tavern )
                      v39 = 4;
                    else
                      v39 = 2;
                    PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, v39);
                  }
                  else
                  {
                    Party::TakeGold(v37);
                    dword_F8B1E4 = 1;
                    *(short *)v38 = 1;
                    v35->PlaySound(SPEECH_78, 0);
                  }
                }
              }
            }
            else
            {
              if ( uMessageParam == 94 )
              {
                pDialogueWindow->eWindowType = WINDOW_MainMenu;
                UI_CreateEndConversationButton();
                sub_4B3AD4(in_current_building_type);
              }
            }
          }
          return;
        }
        dialog_menu_id = 5;
      }
    }
    sub_421B2C_PlaceInInventory_or_DropPickedItem();
    return;
  }
  if ( pParty->field_3C.field_50[(unsigned int)v8->ptr_1C] < (signed __int64)pParty->uTimePlayed )
  {
    GenerateStandartShopItems();
    GenerateSpecialShopItems();
    v8 = window_SpeakInHouse;
    v40 = window_SpeakInHouse->par1C;
    //v3 = dword_F8B198;
    v41 = pParty->uTimePlayed
        //+ (signed __int64)((double)(11059200 * (signed int)p2DEvents_minus1[26 * (unsigned int)ptr_507BC0->ptr_1C])
        + (signed __int64)((double)(11059200 * (signed int)p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].field_1C)
                         * 0.033333335);
    pParty->field_3C.field_50[v40] = v41;
   
  }
  v42 = v8->ptr_1C;
  v43 = 0;
  //v44 = p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C];
  v44 = p2DEvents[(unsigned int)v8->ptr_1C - 1].uType;
  if ( uMessageParam == 2 )
  {
    if ( uItemsAmountPerShopType[v44] )
    {
      do
      {
        v45 = pParty->StandartItemsInShops[(int)v42][v43].uItemID;
        if ( v45 )
        {
          v46 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v45].pIconName, TEXTURE_16BIT_PALETTE);
          //v3 = dword_F8B198;
          v8 = window_SpeakInHouse;
          ItemsInShopTexture[v43] = &pIcons_LOD->pTextures[v46];
        }
        v42 = v8->ptr_1C;
        ++v43;
      }
      //while ( v43 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] );
      while ( v43 < (unsigned __int8)uItemsAmountPerShopType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] );
    }
    if ( in_current_building_type == BildingType_WeaponShop )
    {
      v47 = v8->ptr_1C;
      v48 = 0;
      //if ( _4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] )
      if ( uItemsAmountPerShopType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] )
      {
        do
        {
         // if ( pParty->field_777C[9 * (v48 + 12 * (int)v47)] )
		 if ( pParty->StandartItemsInShops[(int)v47][v48].uItemID);
          {
            v49 = rand();
            v8 = window_SpeakInHouse;
            word_F8B158[v48] = v49 % (300 - ItemsInShopTexture[v48]->uTextureHeight);
          }
          v47 = v8->ptr_1C;
          ++v48;
        }
        //while ( v48 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] );
        while ( v48 < (unsigned __int8)uItemsAmountPerShopType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] );
      }
    }
  }
  if ( uMessageParam == 95 )
  {
    if ( uItemsAmountPerShopType[v44] )
    {
      do
      {
        //v50 = pParty->field_C59C[9 * (v43 + 12 * (int)v42) + 724];
	  v50=pParty->SpecialItemsInShops[(unsigned int)v42][(signed int)v43].uItemID;
        if ( v50 )
        {
          v51 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v50].pIconName, TEXTURE_16BIT_PALETTE);
          //v3 = dword_F8B198;
          v8 = window_SpeakInHouse;
          ItemsInShopTexture[v43] = &pIcons_LOD->pTextures[v51];
        }
        v42 = v8->ptr_1C;
        ++v43;
      }
      //while ( v43 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] );
      while ( v43 < (unsigned __int8)uItemsAmountPerShopType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] );
    }
    if ( in_current_building_type == BildingType_WeaponShop )
    {
      v52 = v8->ptr_1C;
      v53 = 0;
      //if ( _4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] )
      if ( uItemsAmountPerShopType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] )
      {
        do
        {
         // if ( pParty->field_C59C[9 * (v53 + 12 * (int)v52) + 724] )
		if (pParty->SpecialItemsInShops[(unsigned int)v52][v53].uItemID)
          {
            v54 = rand();
            v8 = window_SpeakInHouse;
            word_F8B158[v53] = v54 % (300 - ItemsInShopTexture[v53]->uTextureHeight);
          }
          v52 = v8->ptr_1C;
          ++v53;
        }
        //while ( v53 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] );
        while ( v53 < (unsigned __int8)uItemsAmountPerShopType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType ] );
      }
    }
  }
*/
}
//----- (004B6943) --------------------------------------------------------
void __cdecl TravelByTransport()
{
  GUIWindow *v0; // ebx@1
  Player *v1; // esi@1
  signed int v2; // edi@1
  unsigned int v3; // eax@1
  signed int v4; // ebx@1
  stru365_travel_info *v5; // esi@7
  //int v6; // eax@9
  //int v7; // eax@9
  //int v8; // eax@12
  //int v9; // edi@12
  //int v10; // edx@12
  int v11; // ecx@12
  signed int v12; // esi@13
  signed int v13; // edi@14
  DWORD v14; // eax@26
  DWORD v15; // edi@26
  GUIWindow *v16; // ebx@36
  int v17; // esi@36
  int v18; // eax@36
  int v19; // ecx@36
  int v20; // esi@36
  int v21; // eax@36
  void *v22; // eax@39
  int v23; // esi@39
  GUIButton *v24; // ebx@39
  signed int v25; // eax@41
  //int v26; // esi@44
  //const char *v27; // eax@46
  char *v28; // eax@62
  int v29; // eax@62
  unsigned int v30; // ecx@62
  char *v31; // eax@63
  MapInfo v32; // [sp-3Ch] [bp-2CCh]@62
  /*int v33; // [sp-38h] [bp-2C8h]@62
  int v34; // [sp-34h] [bp-2C4h]@62
  int v35; // [sp-30h] [bp-2C0h]@62
  int v36; // [sp-2Ch] [bp-2BCh]@62
  int v37; // [sp-28h] [bp-2B8h]@62
  int v38; // [sp-24h] [bp-2B4h]@62
  int v39; // [sp-20h] [bp-2B0h]@62
  int v40; // [sp-1Ch] [bp-2ACh]@62
  int v41; // [sp-18h] [bp-2A8h]@62
  int v42; // [sp-14h] [bp-2A4h]@62
  char *v43; // [sp-10h] [bp-2A0h]@62
  char *v44; // [sp-Ch] [bp-29Ch]@62
  unsigned int v45; // [sp-8h] [bp-298h]@62
  char *v46; // [sp-4h] [bp-294h]@62
  const char *v47[5]; // [sp+0h] [bp-290h]@7*/
  char v48[5][100]; // [sp+14h] [bp-27Ch]@37
  //char v49[100]; // [sp+78h] [bp-218h]@68
  //char v50[100]; // [sp+DCh] [bp-1B4h]@68
  //char v51[100]; // [sp+140h] [bp-150h]@68
  //char Dest[100]; // [sp+1A4h] [bp-ECh]@36
  GUIWindow v53; // [sp+208h] [bp-88h]@1
  int v54; // [sp+25Ch] [bp-34h]@36
  int v55; // [sp+260h] [bp-30h]@36
  //unsigned int v56; // [sp+264h] [bp-2Ch]@1
  //int v57; // [sp+268h] [bp-28h]@1
  int v58; // [sp+26Ch] [bp-24h]@36
  //GUIWindow *v59; // [sp+270h] [bp-20h]@1
  unsigned int v60; // [sp+274h] [bp-1Ch]@36
  //Player *v61; // [sp+278h] [bp-18h]@1
  int v62; // [sp+27Ch] [bp-14h]@36
  int v63; // [sp+280h] [bp-10h]@14
  char *a1; // [sp+284h] [bp-Ch]@37
  unsigned int s1; // [sp+288h] [bp-8h]@1
  int v66; // [sp+28Ch] [bp-4h]@48

  v0 = window_SpeakInHouse;
  memcpy(&v53, window_SpeakInHouse, sizeof(v53));
  v2 = 255;
  //v61 = pPlayers[uActiveCharacter];
  v1 = pPlayers[uActiveCharacter];
  v53.uFrameX = 483;
  v53.uFrameWidth = 148;
  v53.uFrameZ = 334;
  auto color_default = TargetColor(255, 255, 255);
  auto color_selected = TargetColor(255, 255, 155);
  v3 = 52 * (unsigned int)v0->ptr_1C;
  //v59 = (GUIWindow *)((((p2DEvents_minus1___00[v3 / 2] != 27) - 1) & 0xFFFFFFE7) + 50);
  //v59 = (GUIWindow *)((((p2DEvents[(unsigned int)v0->ptr_1C - 1].uType != BildingType_Stables) - 1) & 0xFFFFFFE7) + 50);
  //v4 = (signed __int64)((double)(signed int)v59 * p2DEvents_minus1__20[v3 / 4]);

  v4 = p2DEvents[(unsigned int)v0->ptr_1C - 1].uType == BildingType_Stables ? 25 : 50;
  v4 *= p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier;

  s1 = v4 * (100 - v1->GetMerchant()) / 100;
  if ( (signed int)s1 < v4 / 3 )
    s1 = v4 / 3;
  if ( dialog_menu_id == HOUSE_DIALOGUE_MAIN)
  {
    if ( HouseUI_CheckIfPlayerCanInteract() )
    {
      v16 = pDialogueWindow;
      v58 = 255;
      v62 = 0;
      v17 = LOBYTE(pFontArrus->uFontHeight) - 3;
      //v59 = pDialogueWindow;
      v54 = v17;
      strcpy(v48[4], "");
      sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[405], s1); // Price: %lu gold
      v18 = pFontArrus->CalcTextHeight(pTmpBuf2.data(), &v53, 0, 0);
      v19 = v16->pNumPresenceButton;
      v20 = v18 + v17 + 146;
      v21 = v16->pStartingPosActiveItem;
      v63 = v20;
      v55 = v20;
      v60 = v21;
      if ( v21 >= v21 + v19 )
        goto LABEL_71;
      s1 = 2;
      a1 = (char *)v48;
      while ( 1 )
      {
        int v47 = v60;
        v22 = window_SpeakInHouse->ptr_1C;
        v23 = transport_routes[(unsigned int)v22 - HOUSE_STABLES_HARMONDALE][v62];
        //v23 = (unsigned __int8)*(&_4F0D38_TravelInfo[4 * (unsigned int)v22] + v62); // negindex. actual address is around + 0x36
        //v61 = (Player *)(unsigned __int8)*(&_4F0D38_TravelInfo[4 * (unsigned int)v22] + v62); // + 0x3F for sea travels, less for land
        v24 = v16->GetControl(v60);

        if (v23 != v58)
        {
          if (v23 >= 25)
            Log::Warning(L"Transport UI: scedule overflow");
          if (s1 >= 6)
            v25 = true;
          else
            v25 = transport_schedule[v23].pSchedule[pParty->uDaysPlayed % 7];
        }

        if (v23 != v58 && v25 && (!transport_schedule[v23].uQuestBit || _449B57_test_bit(pParty->_quest_bits, transport_schedule[v23].uQuestBit)) )
        {
            v58 = v23;
            if ( pDialogueWindow->pCurrentPosActiveItem == s1 )
              sprintf(a1, "\f%05d", color_selected);
            else
              sprintf(a1, "\f%05d", color_default);

          //v32.uRedbookTrackID = v27;
          v66 = transport_schedule[v23].uTravelTime;
          if ( (unsigned int)window_SpeakInHouse->ptr_1C >= HOUSE_BOATS_63 )
          {
            if ( CheckHiredNPCSpeciality(Sailor) )
              v66 -= 2;
            if ( CheckHiredNPCSpeciality(Navigator) )
              v66 -= 3;
            if ( CheckHiredNPCSpeciality(Pirate) )
              v66 -= 2;
          }
          else
          {
            if ( CheckHiredNPCSpeciality(Horseman) )
              v66 -= 2;
          }
          if ( CheckHiredNPCSpeciality(Explorer) )
            --v66;
          if ( v66 < 1 )
            v66 = 1;
          if ( v23 != v2 )
          {
            memcpy(&v32, &pMapStats->pInfos[transport_schedule[v23].uMapInfoID], 0x44u);
            sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[404], // Time - %d days, destination %s
                      v66, v32.pName);
            strcat(a1, pTmpBuf.data());
            v28 = a1;
            a1 += 100;
            ++v62;
            ++s1;
            strcat(v28, "\n \n");
            v24->uY = v63;
            v29 = pFontArrus->CalcTextHeight(pTmpBuf.data(), &v53, 0, 0);
            v30 = v24->uY;
            v24->uHeight = v29;
            v2 = 255;
            v24->uW = v30 + v29 - 1;
            v63 += v54 + v29;
          }
        }
        else
        {
          v31 = a1;
          ++v62;
          ++s1;
          a1 += 100;
          strcpy(v31, "");
          if ( v24 )
          {
            v24->uW = 0;
            v24->uHeight = 0;
            v24->uY = 0;
          }
        }
        ++v60;
        if ( (signed int)v60 >= v16->pNumPresenceButton + v16->pStartingPosActiveItem )
          break;
        //v16 = v59;
      }
      if ( v63 != v55 )
      {
        /*v47[1] = &Dest;
        v47[0] = &v51;
        v46 = &v50;
        v45 = (unsigned int)&v49;
        v44 = &v48;
        v43 = pTmpBuf2.data();*/
        sprintf(pTmpBuf.data(), "%s\n \n%s%s%s%s%s", pTmpBuf2.data(), v48[0], v48[1], v48[2], v48[3], v48[4]);
        v53.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf.data(), 3u);
      }
      else
      {
LABEL_71:
        v53.DrawTitleText(pFontArrus, 0, (174 - pFontArrus->CalcTextHeight(pGlobalTXT_LocalizationStrings[561], &v53, 0, 0)) / 2 + 138,
                          color_default, pGlobalTXT_LocalizationStrings[561], 3);
        pAudioPlayer->StopChannels(-1, -1);
      }
    }
  }
  else
  {
    if ( dialog_menu_id >= HOUSE_DIALOGUE_TRANSPORT_SCHEDULE_1 && dialog_menu_id <= HOUSE_DIALOGUE_TRANSPORT_SCHEDULE_4 )
    {
      if ( pParty->uNumGold < s1 )
      {
        ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
        PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_Greeting_2);
        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
        return;
      }

      Party::TakeGold(s1);

      v5 = &transport_schedule[transport_routes[(unsigned int)window_SpeakInHouse->ptr_1C - HOUSE_STABLES_HARMONDALE][dialog_menu_id - HOUSE_DIALOGUE_TRANSPORT_SCHEDULE_1]];
      if ( v5->pSchedule[pParty->uDaysPlayed % 7] )
      {
        if ( _stricmp(pCurrentMapName.data(), pMapStats->pInfos[v5->uMapInfoID].pFilename) )
        {
          SaveGame(1, 0);
          strcpy(pCurrentMapName.data(), pMapStats->pInfos[v5->uMapInfoID].pFilename);

          dword_6BE364_game_settings_1 |= 1u;
          _5B65B8_npcdata_hiword_house_or_other = 0;
          dword_5B65BC = 0;
          _5B65B4_npcdata_loword_house_or_other = v5->arrival_rot_y;
          v11 = *((int *)v5 + 3);
          uGameState = GAME_STATE_2;
          _5B65A8_npcdata_uflags_or_other = v11;
          _5B65AC_npcdata_fame_or_other = v5->arrival_y;
          _5B65B0_npcdata_rep_or_other = v5->arrival_z;
          dword_5B65C0 = v11 | v5->arrival_y | v5->arrival_z | v5->arrival_rot_y;
        }
        else
        {
          pIndoorCamera->sRotationY = 0;
          pParty->uFlags |= 2u;
          pParty->vPosition.x = v5->arrival_x;
          pParty->vPosition.y = v5->arrival_y;
          pParty->vPosition.z = v5->arrival_z;
          pParty->uFallStartY = pParty->vPosition.z;
          pParty->sRotationX = 0;
          pParty->sRotationY = v5->arrival_rot_y;
        }
        PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
        v12 = v5->uTravelTime;
        int _v47;
        if ( (signed int)window_SpeakInHouse->ptr_1C >= 63 )
        {
          v63 = SPEECH_SetSail;
          v13 = 2500;
          if ( CheckHiredNPCSpeciality(Sailor) )
            v12 -= 2;
          if ( CheckHiredNPCSpeciality(Navigator) )
            v12 -= 3;
          //_v47 = 45;
          if ( CheckHiredNPCSpeciality(Pirate) )
            v12 -= 2;
        }
        else
        {
          v63 = SPEECH_CarriageReady;
          v13 = 1500;
          //_v47 = 35;
          if ( CheckHiredNPCSpeciality(Horseman) )
            v12 -= 2;
        }
        if ( CheckHiredNPCSpeciality(Explorer) )
          --v12;
        if ( v12 < 1 )
          v12 = 1;
        RestAndHeal(1440 * v12);
        v1->PlaySound((PlayerSpeech)v63, 0);
        v14 = GetTickCount();
        v15 = v14 + v13;
        if ( v15 < v14 )
          v15 = v14;
        while ( GetTickCount() < v15 )
          sqrt(3.1415926);
        while ( sub_4BD8B5() )
          ;
        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
        return;
      }
      else
      {
        dialog_menu_id = HOUSE_DIALOGUE_MAIN;
        pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
      }
    }
  }
}
//----- (004B68EA) --------------------------------------------------------
bool __fastcall IsTravelAvailable(int a1)
{
  for (uint i = 0; i < 4; ++i)
  {
    uint route = transport_routes[a1][i];
    if (transport_schedule[route].pSchedule[pParty->uDaysPlayed % 7])
    {
      if (!transport_schedule[route].uQuestBit || _449B57_test_bit(pParty->_quest_bits, transport_schedule[route].uQuestBit))
        return true;
    }
  }
  return false;
}



//----- (004B7911) --------------------------------------------------------
void __cdecl TownHallDialog()
{
  GUIWindow *v0; // eax@4
  int v1; // eax@10
  int v2; // esi@10
  GUIFont *v3; // ST20_4@20
  int v4; // eax@20
  MonsterInfo *v5; // edi@21
  unsigned int v6; // ST20_4@21
  char *v7; // ST1C_4@21
  unsigned int v8; // eax@21
  int v9; // esi@21
  char *v10; // eax@23
  signed int v11; // ebx@24
  signed int i; // esi@26
  int v13; // eax@27
  GUIWindow *v14; // ecx@28
  __int64 v15; // qax@28
  signed int v16; // ebx@28
  int v17; // ebx@28
  unsigned __int8 v18; // sf@28
  char **v19; // edi@29
  GUIButton *v20; // eax@30
  GUIButton *v21; // esi@30
  int v22; // eax@30
  unsigned int v23; // ecx@30
  unsigned __int16 v24; // ax@30
  GUIWindow a1; // [sp+Ch] [bp-110h]@21
  GUIWindow w; // [sp+60h] [bp-BCh]@21
  GUIWindow _this; // [sp+B4h] [bp-68h]@1
  int v28; // [sp+108h] [bp-14h]@1
  int v29; // [sp+10Ch] [bp-10h]@28
  int v30; // [sp+110h] [bp-Ch]@1
  int v31; // [sp+114h] [bp-8h]@29
  GUIFont *pOutString; // [sp+118h] [bp-4h]@21

  memcpy(&_this, window_SpeakInHouse, sizeof(_this));
  _this.uFrameX = 483;
  _this.uFrameWidth = 148;
  _this.uFrameZ = 334;
  v28 = TargetColor(0xFFu, 0xFFu, 0xFFu);
  v30 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
  sprintf(pTmpBuf.data(), "%s: %d", pGlobalTXT_LocalizationStrings[605], pParty->uFine);
  _this.DrawTitleText(pFontArrus, 0, 0x104u, v30, pTmpBuf.data(), 3u);
  switch(dialog_menu_id)
  {
	case HOUSE_DIALOGUE_MAIN:
		{
		v11 = 1;
		pOutString = 0;
		pShopOptions[0] = pGlobalTXT_LocalizationStrings[604];
		if ( pParty->uFine )
		{
			pShopOptions[1] = pGlobalTXT_LocalizationStrings[603];
			v11 = 2;
		}
		for ( i = 0; i < v11; ++i )
		{
			v13 = pFontArrus->CalcTextHeight(pShopOptions[i], &_this, 0, 0);
			pOutString = (GUIFont *)((char *)pOutString + v13);
		}
		v29 = (100 - (signed int)pOutString) / v11;
		v14 = pDialogueWindow;
		v15 = 80 - v11 * (100 - (signed int)pOutString) / v11 - (signed int)pOutString;
		v16 = v15 - HIDWORD(v15);
		LODWORD(v15) = pDialogueWindow->pStartingPosActiveItem;
		HIDWORD(v15) = v15 + pDialogueWindow->pNumPresenceButton;
		v17 = (v16 >> 1) - v29 / 2 + 158;
		v18 = -pDialogueWindow->pNumPresenceButton < 0;
		pOutString = (GUIFont *)pDialogueWindow->pStartingPosActiveItem;
		if ( v18 ^ __OFSUB__((int)v15, HIDWORD(v15)) )
		{
			v31 = 2;
			v19 = pShopOptions.data();
			do
			{
				v20 = v14->GetControl((unsigned int)pOutString);
				v21 = v20;
				v20->uY = v29 + v17;
				v22 = pFontArrus->CalcTextHeight(*v19, &_this, 0, 0);
				v23 = v21->uY;
				v21->uHeight = v22;
				v17 = v23 + v22 - 1;
				v21->uW = v17;
				v24 = v30;
				if ( pDialogueWindow->pCurrentPosActiveItem != v31 )
					v24 = v28;
				_this.DrawTitleText(pFontArrus, 0, v23, v24, *v19, 3u);
				v14 = pDialogueWindow;
				++v31;
				++v19;
				pOutString = (GUIFont *)((char *)pOutString + 1);
			}
			while ( (signed int)pOutString < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
		}
		break;
		}

	case HOUSE_DIALOGUE_TOWNHALL_99:
		{
		v5 = &pMonsterStats->pInfos[word_F8B1A0];
		v6 = TargetColor(0xFFu, 0xFFu, 0xFFu);
		v7 = v5->pName;
		v8 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
		sprintf(pTmpBuf.data(), "\f%05d%s\f%05d", v8, v7, v6);
		sprintf(pTmpBuf2.data(), dword_F8B1A4, pTmpBuf.data(), 100 * v5->uLevel);
		current_npc_text = pTmpBuf2.data();
		memcpy(&a1, pDialogueWindow, sizeof(a1));
		w.uFrameWidth = 458;
		w.uFrameZ = 457;
		pOutString = pFontArrus;
		v9 = pFontArrus->CalcTextHeight(pTmpBuf2.data(), &w, 13, 0) + 7;
		if ( 352 - v9 < 8 )
		{
			pOutString = pFontCreate;
			v9 = pFontCreate->CalcTextHeight(current_npc_text, &w, 13, 0) + 7;
		}

		auto pTex = pIcons_LOD->GetTexture(uTextureID_Leather);
		pRenderer->_4A6A68(8u, 352 - v9, pTex, pTex->uTextureHeight - v9);
		pRenderer->DrawTextureIndexed(8u, 347 - v9, pTexture_591428);
		v10 = FitTextInAWindow(current_npc_text, pOutString, &w, 0xDu, 0);
		a1.DrawText(pOutString, 13, 354 - v9, 0, v10, 0, 0, 0);
		break;
		}
	case HOUSE_DIALOGUE_TOWNHALL_100:
		{
		v0 = window_SpeakInHouse;
		if ( window_SpeakInHouse->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
		{
			sprintfex(pTmpBuf.data(), "%s\n%s", pGlobalTXT_LocalizationStrings[606], pGlobalTXT_LocalizationStrings[112]); // "Pay"   "How Much?"
			_this.DrawTitleText(pFontArrus, 0, 0x92u, v30, pTmpBuf.data(), 3u);
			_this.DrawTitleText(pFontArrus, 0, 0xBAu, v28, (const char *)pKeyActionMap->pPressedKeysBuffer, 3);
			v3 = pFontArrus;
			v4 = pFontArrus->GetLineWidth((const char *)pKeyActionMap->pPressedKeysBuffer);
			_this.DrawFlashingInputCursor(v4 / 2 + 80, 185, v3);
			return;
		}
		if ( window_SpeakInHouse->receives_keyboard_input_2 == WINDOW_INPUT_CONFIRMED)
		{
			v1 = atoi((const char *)pKeyActionMap->pPressedKeysBuffer);
			v2 = v1;
			if ( v1 <= 0 )
			{
				pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
				return;
			}
			if ( v1 > pParty->uNumGold )
			{
				PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
				v2 = pParty->uNumGold;
			}
			if ( v2 > pParty->uFine )
				v2 = pParty->uFine;
			Party::TakeGold(v2);
			pParty->uFine -= v2;
			if ( pParty->uFine < 0 )
				pParty->uFine = 0;
			if ( uActiveCharacter )
				pPlayers[uActiveCharacter]->PlaySound(SPEECH_81, 0);
			v0 = window_SpeakInHouse;
		}
		if ( window_SpeakInHouse->receives_keyboard_input_2 == WINDOW_INPUT_CANCELLED)
		{
			v0->receives_keyboard_input_2 = WINDOW_INPUT_NONE;
			pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
		}
		break;
		}
	default:
		{
		break;
		}
  }
  return;
}

//----- (004B7D7E) --------------------------------------------------------
void __cdecl BankDialog()
{
  GUIWindow *v0; // eax@4
  //int v1; // ecx@5
  int v2; // eax@6
  unsigned int v3; // esi@6
  GUIFont *v4; // ST10_4@12
  int v5; // eax@12
  int v6; // eax@19
  unsigned int v7; // esi@19
  unsigned __int16 v8; // ax@27
  unsigned __int16 v9; // ax@29
  char *v10; // [sp-8h] [bp-70h]@11
  char *v11; // [sp-4h] [bp-6Ch]@11
  GUIWindow _this; // [sp+Ch] [bp-5Ch]@1
  __int16 v13[2]; // [sp+60h] [bp-8h]@1
  __int16 v14[2]; // [sp+64h] [bp-4h]@1

  memcpy(&_this, window_SpeakInHouse, sizeof(_this));
  _this.uFrameX = 483;
  _this.uFrameWidth = 148;
  _this.uFrameZ = 334;
  *(int *)v13 = TargetColor(0xFFu, 0xFFu, 0xFFu);
  *(int *)v14 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
  sprintf(pTmpBuf.data(), "%s: %d", pGlobalTXT_LocalizationStrings[25], pParty->uNumGoldInBank);
  _this.DrawTitleText(pFontArrus, 0, 0xDCu, v14[0], pTmpBuf.data(), 3u);
  switch(dialog_menu_id)
  {
	case HOUSE_DIALOGUE_MAIN:
		{
		v8 = v14[0];
		if ( pDialogueWindow->pCurrentPosActiveItem != 2 )
			v8 = v13[0];
		_this.DrawTitleText(pFontArrus, 0, 0x92u, v8, pGlobalTXT_LocalizationStrings[60], 3u);
		v9 = v14[0];
		if ( pDialogueWindow->pCurrentPosActiveItem != 3 )
			v9 = v13[0];
		_this.DrawTitleText(pFontArrus, 0, 0xB0u, v9, pGlobalTXT_LocalizationStrings[244], 3u);
		break;
		}
	case HOUSE_DIALOGUE_BANK_7:
		{
		v0 = window_SpeakInHouse;
		if ( window_SpeakInHouse->receives_keyboard_input_2 != WINDOW_INPUT_IN_PROGRESS)
		{
			if ( window_SpeakInHouse->receives_keyboard_input_2 == WINDOW_INPUT_CONFIRMED)
			{
				v6 = atoi((const char *)pKeyActionMap->pPressedKeysBuffer);
				v7 = v6;
				if ( !v6 )
				{
					pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
					return;
				}
				if ( v6 > pParty->uNumGold )
				{
					PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
					v7 = pParty->uNumGold;
				}
				if ( v7 )
				{
					Party::TakeGold(v7);
					pParty->uNumGoldInBank += v7;
					if ( uActiveCharacter )
						pPlayers[uActiveCharacter]->PlaySound(SPEECH_81, 0);
				}
				v0 = window_SpeakInHouse;
				v0->receives_keyboard_input_2 = WINDOW_INPUT_NONE;
				pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
				return;
			}
			if (window_SpeakInHouse->receives_keyboard_input_2 != WINDOW_INPUT_CANCELLED)
				return;
			v0->receives_keyboard_input_2 = WINDOW_INPUT_NONE;
			pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
			return;      
		}
		v11 = pGlobalTXT_LocalizationStrings[112];
		v10 = pGlobalTXT_LocalizationStrings[60];
		sprintf(pTmpBuf.data(), "%s\n%s", v10, v11);
		_this.DrawTitleText(pFontArrus, 0, 0x92u, v14[0], pTmpBuf.data(), 3u);
		_this.DrawTitleText(pFontArrus, 0, 0xBAu, v13[0], (const char *)pKeyActionMap->pPressedKeysBuffer, 3u);
		v4 = pFontArrus;
		v5 = pFontArrus->GetLineWidth((const char *)pKeyActionMap->pPressedKeysBuffer);
		_this.DrawFlashingInputCursor(v5 / 2 + 80, 185, v4);
		break;
		}

	case HOUSE_DIALOGUE_BANK_8:
		{
		v0 = window_SpeakInHouse;
		if ( window_SpeakInHouse->receives_keyboard_input_2 != WINDOW_INPUT_IN_PROGRESS)
		{
			if ( window_SpeakInHouse->receives_keyboard_input_2 == WINDOW_INPUT_CONFIRMED)
			{
				window_SpeakInHouse->receives_keyboard_input_2 = WINDOW_INPUT_NONE;
				v2 = atoi((const char *)pKeyActionMap->pPressedKeysBuffer);
				v3 = v2;
				if ( v2 )
				{
					if ( v2 > pParty->uNumGoldInBank )
					{
						PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
						v3 = pParty->uNumGoldInBank;
					}
					if ( v3 )
					{
						Party::SetGold(pParty->uNumGold + v3);
						pParty->uNumGoldInBank -= v3;
					}
				}
                v0->receives_keyboard_input_2 = WINDOW_INPUT_NONE;
				pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
				return;
			}
			if ( window_SpeakInHouse->receives_keyboard_input_2 != WINDOW_INPUT_CANCELLED)
				return;
			v0->receives_keyboard_input_2 = WINDOW_INPUT_NONE;
			pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
			return;  
		}
		v11 = pGlobalTXT_LocalizationStrings[112];
		v10 = pGlobalTXT_LocalizationStrings[244];
		sprintfex(pTmpBuf.data(), "%s\n%s", v10, v11);
		_this.DrawTitleText(pFontArrus, 0, 0x92u, v14[0], pTmpBuf.data(), 3u);
		_this.DrawTitleText(pFontArrus, 0, 0xBAu, v13[0], (const char *)pKeyActionMap->pPressedKeysBuffer, 3u);
		v4 = pFontArrus;
		v5 = pFontArrus->GetLineWidth((const char *)pKeyActionMap->pPressedKeysBuffer);
		_this.DrawFlashingInputCursor(v5 / 2 + 80, 185, v4);
		return;
		break;
		}

	default:
		{
		break;
		}
  }
}
// F8B19C: using guessed type int dword_F8B19C;

//----- (004B8285) --------------------------------------------------------
void __cdecl TavernDialog()
{
  int v0;
  int pItemNum;
  double v2; // st7@1
  signed int v3; // ebx@1
  int v4; // ecx@1
  int v5; // esi@3
  signed int v6; // edi@5
  int v7; // ecx@5
  int pNumString; // edi@16
  signed int v9; // esi@16
  unsigned int pNumActiveItem; // esi@18
  int v11; // eax@18
  unsigned int v12; // eax@19
  int v13; // eax@21
  int v14; // ecx@26
  //GUIButton *v15; // eax@28
  //GUIButton *v16; // esi@28
  int v17; // eax@28
  char *v18; // eax@30
  int v19; // eax@30
  unsigned int v20; // ecx@30
  int v21; // edx@30
  int v22; // eax@30
  unsigned __int16 v23; // ax@30
  int v24; // eax@34
  int v25; // eax@34
  char *v26; // esi@36
  int v27; // edi@46
  unsigned int pColorText; // eax@57
  signed int v31; // eax@59
  //GUIWindow *v33; // edi@64
  int v34; // eax@64
  int v35; // ecx@64
  int v36; // esi@64
  char v37; // sf@64
  GUIButton *pButton; // eax@65
  int v39; // edx@69
  int v40; // ecx@69
  int v41; // ecx@69
  int v42; // ecx@70
  unsigned int v43; // edx@70
  int v44; // edx@71
  int v45; // ecx@71
  int v46; // ecx@72
  int v47; // eax@74
  signed int v48; // edi@77
  signed int i; // esi@79
  int v50; // eax@80
  //GUIWindow *v51; // ecx@81
  _QWORD v52; // qax@81
  signed int v53; // edi@81
  int v54; // edi@81
  //GUIButton *v55; // esi@83
  const char **v56; // eax@83
  int v57; // eax@83
  unsigned int v58; // ecx@83
  //Player *v59; // edx@83
  unsigned __int16 v60; // ax@83
  int v61; // eax@99
  char *v63; // eax@99
  GUIFont *v64; // edx@99
  GUIFont *v65; // edi@100
  unsigned int v66; // [sp-10h] [bp-284h]@75
  unsigned __int16 v67; // [sp-Ch] [bp-280h]@75
  int v68; // [sp-Ch] [bp-280h]@99
  char *v69; // [sp-8h] [bp-27Ch]@75
  int v70; // [sp-8h] [bp-27Ch]@99
  unsigned int v71; // [sp-4h] [bp-278h]@75
  const char *v72; // [sp-4h] [bp-278h]@93
  unsigned int v73; // [sp-4h] [bp-278h]@99
  char pTopic1[100]; // [sp+Ch] [bp-268h]@55
  char pTopic4[100]; // [sp+70h] [bp-204h]@59
  char pTopic2[100]; // [sp+D4h] [bp-1A0h]@57
  char pTopic3[100]; // [sp+138h] [bp-13Ch]@59
  //GUIWindow v78; // [sp+19Ch] [bp-D8h]@99
  GUIWindow dialog_window; // [sp+1F0h] [bp-84h]@1
  char *Str[2]; // [sp+244h] [bp-30h]@30
  unsigned int pColorWhite; // [sp+24Ch] [bp-28h]@1
  unsigned __int8 pTopic3Height; // [sp+253h] [bp-21h]@59
  int v83; // [sp+254h] [bp-20h]@1
  int pColorYellow; // [sp+258h] [bp-1Ch]@1
  Player *pPlayer; // [sp+25Ch] [bp-18h]@1
  int all_text_height; // [sp+260h] [bp-14h]@18
  unsigned __int8 v87; // [sp+266h] [bp-Eh]@59
  unsigned __int8 pTopic2Height; // [sp+267h] [bp-Dh]@57
  int v89; // [sp+268h] [bp-Ch]@1
  unsigned int pTopic1Height; // [sp+26Fh] [bp-5h]@55
  int v91; // [sp+270h] [bp-4h]@3
  GUIFont *pOutString;
  unsigned __int8 pTopic4Height;
  int pTextHeight;

  pPlayer = pPlayers[uActiveCharacter];
  memcpy(&dialog_window, window_SpeakInHouse, sizeof(dialog_window));
  dialog_window.uFrameX = 483;
  dialog_window.uFrameWidth = 148;
  dialog_window.uFrameZ = 334;
  pColorWhite = TargetColor(0xFFu, 0xFFu, 0xFFu);
  pColorYellow = TargetColor(0xFFu, 0xFFu, 0x9Bu);
  v2 = p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].fPriceMultiplier;
  *(float *)&v83 = v2;
  *(float *)&v89 = v2 * v2;
  v3 = (signed __int64)(*(float *)&v89 * 0.1);
  pItemNum = v3 * (100 - pPlayer->GetMerchant()) / 100;
  if ( pItemNum < v3 / 3 )
    pItemNum = v3 / 3;
  v5 = 1;
  pOutString = (GUIFont *)pItemNum;
  if ( pItemNum <= 0 )
    pOutString = (GUIFont *)1;
  v6 = (signed __int64)(*(float *)&v89 * *(float *)&v83 * 0.0099999998);
  v7 = v6 * (100 - pPlayer->GetMerchant()) / 100;
  if ( v7 < v6 / 3 )
  v7 = v6 / 3;
  v83 = v7;
  if ( v7 <= 0 )
  {
    v7 = 1;
    v83 = 1;
  }

  switch(dialog_menu_id)
  {
    case HOUSE_DIALOGUE_MAIN:
    {
      if ( !HouseUI_CheckIfPlayerCanInteract() )
          return;

      sprintf(pTopic1, "\f%05d", pDialogueWindow->pCurrentPosActiveItem == 2 ? pColorYellow : pColorWhite);
      sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[178], pOutString); // Rent room for %d gold
      strcat(pTopic1, pTmpBuf2.data());
      pTopic1Height = pFontArrus->CalcTextHeight(pTopic1, &dialog_window, 0, 0);
      strcat(pTopic1, "\n \n");

      sprintf(pTopic2, "\f%05d", pDialogueWindow->pCurrentPosActiveItem == 3 ? pColorYellow : pColorWhite);
      sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[86], // Buy food for %d days for %d gold
        (unsigned int)p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].fPriceMultiplier, v83);
      strcat(pTopic2, pTmpBuf2.data());
      pTopic2Height = pFontArrus->CalcTextHeight(pTopic2, &dialog_window, 0, 0);
      strcat(pTopic2, "\n \n");

      sprintf(pTopic3, "\f%05d", pDialogueWindow->pCurrentPosActiveItem == 4 ? pColorYellow : pColorWhite);
      strcat(pTopic3, pGlobalTXT_LocalizationStrings[160]); // Learn Skills
      pTopic3Height = pFontArrus->CalcTextHeight(pTopic3, &dialog_window, 0, 0);
      strcat(pTopic3, "\n \n");
      pTopic4[0] = 0;
      if ( (signed int)window_SpeakInHouse->par1C >= 108 && (signed int)window_SpeakInHouse->par1C <= 120 )
      {
        sprintf(pTopic4, "\f%05d", pDialogueWindow->pCurrentPosActiveItem == 5 ? pColorYellow : pColorWhite);
        strcat(pTopic4, pGlobalTXT_LocalizationStrings[611]); // Play Arcomage
        pTopic4Height = pFontArrus->CalcTextHeight(pTopic4, &dialog_window, 0, 0);
      }
      pNumActiveItem = pDialogueWindow->pStartingPosActiveItem;
      v36 = LOBYTE(pFontArrus->uFontHeight) - 3;
      v37 = -pDialogueWindow->pNumPresenceButton < 0;
      if ( !(v37 ^ (pNumActiveItem < pNumActiveItem + pDialogueWindow->pNumPresenceButton)) )
      {
        do
        {
          pButton = pDialogueWindow->GetControl(pNumActiveItem);
          if ( pButton->msg_param == 15 )
          {
            v46 = pTopic1Height;
            pButton->uHeight = pTopic1Height;
            pButton->uY = 146;
            v41 = v46 + 145;
            pButton->uW = v41;
          }
          else if ( pButton->msg_param == 16 )
          {
            v44 = pTopic2Height;
            v45 = pTopic1Height + v36 + 146;
            pButton->uHeight = pTopic2Height;
            pButton->uY = v45;
            v41 = v45 + v44 - 1;
            pButton->uW = v41;
          }
          else if ( pButton->msg_param == 96 )
          {
            v42 = pTopic1Height + pTopic2Height + 2 * v36 + 146;
            v43 = pTopic3Height;
            pButton->uY = v42;
            pButton->uHeight = v43;
            v41 = v43 + v42 - 1;
            pButton->uW = v41;
          }
          else if ( pButton->msg_param == 101 )
          {
            v39 = pTopic1Height + 3 * v36 + pTopic4Height + pTopic2Height + 146;
            v40 = pTopic4Height;
            pButton->uHeight = pTopic4Height;
            pButton->uY = v39;
            v41 = v39 + v40 - 1;
            pButton->uW = v41;
          }
          pNumActiveItem++;
          if ( pNumActiveItem >= pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem )
          {
            sprintfex(pTmpBuf.data(), "%s%s%s%s", pTopic1, pTopic2, pTopic3, pTopic4);
            dialog_window.DrawTitleText(pFontArrus, 0, 146, 0, pTmpBuf.data(), 3);
          }
        }
        while ( pNumActiveItem < pDialogueWindow->pStartingPosActiveItem + pDialogueWindow->pNumPresenceButton );
      }
      break;
    }
    case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_RULES:
    {
      pOutString = pFontArrus;
      strcpy(pTmpBuf.data(), pNPCTopics[354].pText);
      dialog_window.uFrameWidth = game_viewport_width;
      dialog_window.uFrameZ = 452;
      pTextHeight = pFontArrus->CalcTextHeight(pTmpBuf.data(), &dialog_window, 12, 0) + 7;
      if ( 352 - pTextHeight < 8 )
      {
        pOutString = pFontCreate;
        pTextHeight = pFontCreate->CalcTextHeight(pTmpBuf.data(), &dialog_window, 12, 0) + 7;
      }
      auto pTex = pIcons_LOD->GetTexture(uTextureID_Leather);
      pRenderer->_4A6A68(8, 352 - pTextHeight, pTex, pTex->uTextureHeight - pTextHeight);
      pRenderer->DrawTextureIndexed(8, 347 - pTextHeight, pTexture_591428);
      v63 = FitTextInAWindow(pTmpBuf.data(), pOutString, &dialog_window, 0xCu, 0);
      window_SpeakInHouse->DrawText(pOutString, 12, 354 - pTextHeight, 0, v63, 0, 0, 0);
      break;
    }
    case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_VICTORY_CONDITIONS:
    {
      strcpy(pTmpBuf.data(), pNPCTopics[(uint)window_SpeakInHouse->ptr_1C + 247].pText);
      dialog_window.uFrameWidth = game_viewport_width;
      dialog_window.uFrameZ = 452;
      v61 = pFontArrus->CalcTextHeight(pTmpBuf.data(), &dialog_window, 12, 0);
      pTextHeight = v61 + 7;
      auto pTex = pIcons_LOD->GetTexture(uTextureID_Leather);
      pRenderer->_4A6A68(8, 352 - (v61 + 7), pTex, pTex->uTextureHeight - (v61 + 7));
      pRenderer->DrawTextureIndexed(8, 347 - pTextHeight, pTexture_591428);
      v63 = FitTextInAWindow(pTmpBuf.data(), pFontArrus, &dialog_window, 0xCu, 0);
      window_SpeakInHouse->DrawText(pFontArrus, 12, 354 - pTextHeight, 0, v63, 0, 0, 0);
      break;
    }
    case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_RESULT:
    {
      if ( pArcomageGame->bGameInProgress == 1 )
        return;
      if ( pArcomageGame->uGameResult )
      {
        if ( pArcomageGame->uGameResult == 1 )
          v72 = pGlobalTXT_LocalizationStrings[640];// You won!
        else
          v72 = pGlobalTXT_LocalizationStrings[641];// You lost!
      }
      else
      {
        v72 = pGlobalTXT_LocalizationStrings[639];// A tie!
      }
      strcpy(pTmpBuf.data(), v72);
      v66 = (174 - pFontArrus->CalcTextHeight(pTmpBuf.data(), &dialog_window, 0, 0)) / 2 + 138;
      dialog_window.DrawTitleText(pFontArrus, 0, v66, pColorYellow, pTmpBuf.data(), 3);
      break;
    }
    case HOUSE_DIALOGUE_TAVERN_REST:
    {
      if ( pParty->uNumGold >= (unsigned int)pOutString )
      {
        Party::TakeGold((unsigned int)pOutString);
        v27 = (int)window_SpeakInHouse->ptr_1C;//107
        PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
        dialog_menu_id = HOUSE_DIALOGUE_NULL;
        sub_4BD8B5();
        sub_4B1D27();
        pVideoPlayer->Unload();
        window_SpeakInHouse->Release();
        window_SpeakInHouse = 0;
        if ( pMessageQueue_50CBD0->uNumMessages )
          pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
        pMessageQueue_50CBD0->pMessages[0].eType = UIMSG_RentRoom;
        pMessageQueue_50CBD0->pMessages[0].param = v27;
        pMessageQueue_50CBD0->pMessages[0].field_8 = 1;
        ++pMessageQueue_50CBD0->uNumMessages;
        return;
      }
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);
      PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_Goodbye);
      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, v5, 0);
      break;
    }

    case HOUSE_DIALOGUE_LEARN_SKILLS:
    {
      if ( !HouseUI_CheckIfPlayerCanInteract() )
        return;
      v0 = 0;
      v9 = (signed __int64)(p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].flt_24 * 500.0);
      pItemNum = v9 * (100 - pPlayer->GetMerchant()) / 100;
      if ( pItemNum < v9 / 3 )
        pItemNum = v9 / 3;
      pNumActiveItem = pDialogueWindow->pStartingPosActiveItem;
      all_text_height = 0;
      if ( pNumActiveItem < pNumActiveItem + pDialogueWindow->pNumPresenceButton )
      {
        do
        {
          v12 = pDialogueWindow->GetControl(pNumActiveItem)->msg_param - 36;
          if ( byte_4ED970_skill_learn_ability_by_class_table[pPlayer->classType][v12] && !pPlayer->pActiveSkills[v12] )
          {
            all_text_height = pFontArrus->CalcTextHeight(pSkillNames[v12], &dialog_window, 0, 0);
            v0++;
          }
          ++pNumActiveItem;
        }
        while ( pNumActiveItem < pDialogueWindow->pStartingPosActiveItem + pDialogueWindow->pNumPresenceButton );
        if ( v0 )
        {
          sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[401], pItemNum);
          dialog_window.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf.data(), 3);
          v91 = (149 - all_text_height) / v0;
          if ( (149 - all_text_height) / v0 > 32 )
            v91 = 32;
          v14 = (149 - v0 * v91 - all_text_height) / 2 - v91 / 2 + 162;
          pNumActiveItem = pDialogueWindow->pStartingPosActiveItem;
          if ( pNumActiveItem < pNumActiveItem + pDialogueWindow->pNumPresenceButton )
          {
            pItemNum = 2;
            do
            {
              pButton = pDialogueWindow->GetControl(pItemNum);
              v17 = pButton->msg_param - 36;
              if ( !byte_4ED970_skill_learn_ability_by_class_table[pPlayer->classType][v17] || pPlayer->pActiveSkills[v17] )
              {
                pButton->uW = 0;
                pButton->uHeight = 0;
                pButton->uY = 0;
              }
              else
              {
                pButton->uY = v91 + v14;
                pTextHeight = pFontArrus->CalcTextHeight(pSkillNames[v17], &dialog_window, 0, 0);
                pButton->uHeight = pTextHeight;
                v14 = pTextHeight + pButton->uY - 1;
                pButton->uW = v14;
                pColorText = pColorYellow;
                if ( pDialogueWindow->pCurrentPosActiveItem != pItemNum )
                  pColorText = pColorWhite;
                dialog_window.DrawTitleText(pFontArrus, 0, pButton->uY, pColorText, pSkillNames[v17], 3);
              }
              pNumActiveItem = pDialogueWindow->pStartingPosActiveItem + pDialogueWindow->pNumPresenceButton;
              pItemNum++;
            }
            while ( pItemNum < pNumActiveItem );
          }
          return;
        }
      }
      sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[544], pPlayer->pName, pClassNames[pPlayer->classType]);
      strcat(pTmpBuf.data(), "\n \n");
      strcat(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[528]);
      pTextHeight = (174 - pFontArrus->CalcTextHeight(pTmpBuf.data(), &dialog_window, 0, 0)) / 2 + 138;
      dialog_window.DrawTitleText(pFontArrus, 0, pTextHeight, pColorYellow, pTmpBuf.data(), 3);
      return;
    }

    case HOUSE_DIALOGUE_TAVERN_BUY_FOOD:
    {
      *(_QWORD *)Str = pParty->uNumFoodRations;
      //if ( (double)pParty->uNumFoodRations >= p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C] )
      if ( (double)pParty->uNumFoodRations >= p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].fPriceMultiplier )
      {
        ShowStatusBarString(pGlobalTXT_LocalizationStrings[140], 2);
        if ( uActiveCharacter )
          pPlayers[uActiveCharacter]->PlaySound(SPEECH_67, 0);
        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, v5, 0);
        return;
      }
      if ( pParty->uNumGold >= v7 )
      {
        Party::TakeGold(v7);
        //pParty->uNumFoodRations = (signed __int64)p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C];
        pParty->uNumFoodRations = (signed __int64)p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].fPriceMultiplier;
        PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_Greeting_2);
        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
        return;
      }
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);  // "You don't have enough gold"
      PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_Goodbye);
      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, v5, 0);
      break;
    }

    case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_MAIN:
    {
      if ( HouseUI_CheckIfPlayerCanInteract() )
      {
        v48 = 2;
        pShopOptions[0] = pGlobalTXT_LocalizationStrings[620];
        pShopOptions[1] = pGlobalTXT_LocalizationStrings[622];
        pOutString = 0;
        if ( pParty->HasItem(0x28Bu) )
        {
          pShopOptions[2] = pGlobalTXT_LocalizationStrings[621];
          v48 = 3;
        }
        for ( i = 0; i < v48; ++i )
          all_text_height = pFontArrus->CalcTextHeight(pShopOptions[i], &dialog_window, 0, 0);
        all_text_height = (174 - all_text_height) / v48;
        pNumActiveItem = pDialogueWindow->pStartingPosActiveItem;
        v54 = (174 - v48 * (174 - all_text_height) / v48 - all_text_height) / 2 - (174 - all_text_height) / v48 / 2 + 138;
        v37 = -pDialogueWindow->pNumPresenceButton < 0;
        if ( pNumActiveItem < pNumActiveItem + pDialogueWindow->pNumPresenceButton )
        {
          pItemNum = 2;
          pNumString = 0;
          do
          {
            pButton = pDialogueWindow->GetControl(pItemNum);
            pButton->uY = all_text_height + v54;
            pTextHeight = pFontArrus->CalcTextHeight((const char *)pShopOptions[pNumString], &dialog_window, 0, 0);
            pButton->uHeight = pTextHeight;
            v54 = pButton->uY + pTextHeight - 1;
            pButton->uW = v54;
            pColorText = pColorYellow;
            if ( pDialogueWindow->pCurrentPosActiveItem != pItemNum )
              pColorText = pColorWhite;
            dialog_window.DrawTitleText(pFontArrus, 0, pButton->uY, pColorText, (const char *)pShopOptions[pNumString], 3);
            pItemNum++;
            ++pNumString;
            pNumActiveItem = pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem;
          }
          while ( pItemNum < pNumActiveItem );
        }
      }
      break;
    }
    default:
    {
      break;
    }
  }
}

//----- (004B705E) --------------------------------------------------------
void TempleDialog()
    {
    GUIWindow *v0; // ebx@1
    Player *v1; // esi@1
    int v2; // 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 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
    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
    unsigned int v33; // edx@42
    unsigned int v34; // edx@44
    int v35; // edi@50
    signed int v36; // eax@50
    unsigned __int8 v37; // al@54
    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
    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
    unsigned int v62; // [sp+1B0h] [bp-14h]@8
    unsigned __int8 v63; // [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

    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 )
    {
      if ( dialog_menu_id != HOUSE_DIALOGUE_TEMPLE_HEAL )
      {
        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;
        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; // void func
        }
    v63 = 1;
    v41 = pDialogueWindow->GetControl(pDialogueWindow->pStartingPosActiveItem);
    strcpy(a1, "");
    v41->uHeight = 0;
    v41->uY = 0;
    if ( v1->IsPlayerHealableByTemple() )
        {
        sprintf(a1, "%s %d %s", pGlobalTXT_LocalizationStrings[104], HIDWORD(v60), pGlobalTXT_LocalizationStrings[97]);
        v63 = 0;
        }
    strcpy(&a1[100], pGlobalTXT_LocalizationStrings[68]);
    strcpy(&a1[200], pGlobalTXT_LocalizationStrings[160]);
    v42 = v63;
    v43 = pDialogueWindow;
    v44 = v63;
    v66 = 0;
    if ( v63 < pDialogueWindow->pNumPresenceButton )
        {
        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 );
        }
    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 )
        {
        v61 = (GUIWindow *)(v42 + 2);
        v66 = (DDM_DLV_Header *)&a1[100 * v42];
        do
            {
            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;
            }
            while ( (signed int)v65 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
        }
    return;
    }

//----- (004B4710) --------------------------------------------------------
void TrainingDialog()
{
  //Player *v0; // ebx@1
  int color2; // eax@1
  //unsigned int v2; // ecx@1
  //int v3; // eax@1
  //signed int v4; // edx@1
  unsigned __int64 v5; // edi@3
  //unsigned int v6; // esi@3
  //void *v7; // ecx@3
  int v8; // edx@4
  double v9; // st7@6
  signed int v10; // esi@6
  int v11; // ecx@6
  //int result; // eax@9
  GUIWindow *v13; // edi@14
  signed int v14; // esi@14
  unsigned int v15; // esi@16
  int v16; // eax@16
  unsigned int v17; // eax@17
  int v18; // eax@19
  int v19; // ecx@24
  GUIButton *v20; // eax@26
  GUIButton *v21; // esi@26
  int v22; // eax@26
  const char *v23; // eax@28
  int v24; // eax@28
  unsigned int v25; // ecx@28
  int v26; // eax@28
  unsigned __int16 v27; // ax@28
  //int v28; // eax@32
  unsigned __int16 v29; // ST14_2@34
  int v30; // eax@34
  //const char *v31; // ST18_4@36
  //unsigned __int16 v32; // ST14_2@36
  int v33; // eax@36
  int v34; // eax@37
  unsigned int v35; // edi@38
  unsigned int v36; // eax@38
  //int v37; // ecx@41
  //char *v38; // eax@41
  //int *v39; // eax@45
  unsigned int v40; // eax@46
  //void *v41; // ecx@46
  unsigned int v42; // eax@46
  GUIWindow *v43; // ecx@59
  int v44; // edx@59
  char **v45; // esi@60
  //int v46; // eax@62
  int v47; // eax@68
  //int v48; // edx@69
  int v49; // ebx@69
  //unsigned __int8 v50; // sf@69
  char **v51; // edi@70
  GUIButton *v52; // eax@71
  GUIButton *v53; // esi@71
  int v54; // eax@71
  unsigned int v55; // ecx@71
  int v56; // eax@71
  unsigned __int16 v57; // ax@71
  unsigned __int16 v58; // [sp-Ch] [bp-90h]@38
  //const char *v59; // [sp-Ch] [bp-90h]@63
  char *v60; // [sp-8h] [bp-8Ch]@38
  //char *v61; // [sp-8h] [bp-8Ch]@63
  unsigned int v62; // [sp-4h] [bp-88h]@38
  int v63; // [sp-4h] [bp-88h]@52
  //char *v64; // [sp-4h] [bp-88h]@63
  GUIWindow v65; // [sp+Ch] [bp-78h]@1
  //__int64 v66; // [sp+60h] [bp-24h]@3
  unsigned int white; // [sp+68h] [bp-1Ch]@1
  int v68; // [sp+6Ch] [bp-18h]@3
  int v69; // [sp+70h] [bp-14h]@6
  //unsigned int i; // [sp+74h] [bp-10h]@1
  //int v71; // [sp+78h] [bp-Ch]@1
  int v72; // [sp+7Ch] [bp-8h]@16
  int v73; // [sp+80h] [bp-4h]@14

  //v0 = pPlayers[uActiveCharacter];
  memcpy(&v65, window_SpeakInHouse, sizeof(v65));
  v65.uFrameX = 483;
  v65.uFrameWidth = 148;
  v65.uFrameZ = 334;
  white = TargetColor(255, 255, 255);
  color2 = TargetColor(0xE1u, 0xCDu, 0x23u);
  //v71 = color2;
  //v2 = v0->uLevel;
  //v3 = 0;
  //v4 = 0;
  //for ( i = v2; v4 < (signed int)v2; ++v4 )
  //  v3 += v4 + 1;
  //v5 = 1000 * v3;
  v5 = 1000ui64 * pPlayers[uActiveCharacter]->uLevel * (pPlayers[uActiveCharacter]->uLevel + 1) / 2;  // E n = n(n + 1) / 2
  //v6 = HIDWORD(v0->uExperience);
  //v7 = window_SpeakInHouse->ptr_1C;
  v68 = pMaxLevelPerTrainingHallType[(unsigned int)window_SpeakInHouse->ptr_1C - HOUSE_TRAINING_HALL_EMERALD_ISLE];
  //v66 = 1000 * v3;
  if (pPlayers[uActiveCharacter]->uExperience >= v5)
  {
    v8 = pPlayers[uActiveCharacter]->classType % 4 + 1;
    if ( v8 == 4 )
      v8 = 3;
    v9 = (double)pPlayers[uActiveCharacter]->uLevel;
    //i = 0;
    v69 = v8;
    //v10 = (signed __int64)(v9 * p2DEvents_minus1__20[13 * (signed int)v7] * (double)v8);
    v10 = (signed __int64)(v9 * p2DEvents[(signed int)window_SpeakInHouse->ptr_1C - 1].fPriceMultiplier * (double)v8);
    v11 = v10 * (100 - pPlayers[uActiveCharacter]->GetMerchant()) / 100;
    if ( v11 < v10 / 3 )
      v11 = v10 / 3;
    //i = v11;
  }

  if (HouseUI_CheckIfPlayerCanInteract())
  {
    if ( dialog_menu_id != HOUSE_DIALOGUE_MAIN )
    {
      if ( dialog_menu_id != HOUSE_DIALOGUE_TRAININGHALL_TRAIN )
      {
        if ( dialog_menu_id == HOUSE_DIALOGUE_LEARN_SKILLS )
        {
          if (HouseUI_CheckIfPlayerCanInteract())
          {
            //i = 0;
            int _v0 = 0;
            v13 = pDialogueWindow;
            //v14 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (unsigned int)ptr_507BC0->ptr_1C] * 500.0);
            v14 = (signed __int64)(p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1].flt_24 * 500.0);
            v73 = v14 * (100 - pPlayers[uActiveCharacter]->GetMerchant()) / 100;
            if ( v73 < v14 / 3 )
              v73 = v14 / 3;
            v15 = v13->pStartingPosActiveItem;
            v16 = v13->pNumPresenceButton;
            v72 = 0;
            if ( (signed int)v15 >= (signed int)(v15 + v16) )
              goto LABEL_76;
            do
            {
              v17 = v13->GetControl(v15)->msg_param - 36;
              if ( byte_4ED970_skill_learn_ability_by_class_table[pPlayers[uActiveCharacter]->classType][v17] && !pPlayers[uActiveCharacter]->pActiveSkills[v17] )
              {
                v18 = pFontArrus->CalcTextHeight(pSkillNames[v17], &v65, 0, 0);
                _v0 += v18;
                ++v72;
              }
              ++v15;
            }
            while ( (signed int)v15 < v13->pNumPresenceButton + v13->pStartingPosActiveItem );
            if ( v72 )
            {
              sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[401], v73);// "Skill Cost: %lu"
              v65.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf.data(), 3u);
              v73 = (signed int)(149 - _v0) / v72;
              if ( v73 > 32 )
                v73 = 32;
              //result = v13->pStartingPosActiveItem;
              v19 = (signed int)(149 - v72 * v73 - _v0) / 2 - v73 / 2 + 162;
              int _v1 = v13->pStartingPosActiveItem;
              v68 = v19;
              if (v13->pStartingPosActiveItem < v13->pStartingPosActiveItem + v13->pNumPresenceButton )
              {
                v72 = 2;
                do
                {
                  v20 = v13->GetControl(_v1);
                  v21 = v20;
                  v22 = v20->msg_param - 36;
                  if ( !byte_4ED970_skill_learn_ability_by_class_table[pPlayers[uActiveCharacter]->classType][v22] || pPlayers[uActiveCharacter]->pActiveSkills[v22] )
                  {
                    v21->uW = 0;
                    v21->uHeight = 0;
                    v21->uY = 0;
                  }
                  else
                  {
                    v23 = pSkillNames[v22];
                    v21->uY = v73 + v68;
                    //HIDWORD(v66) = (int)v23;
                    v24 = pFontArrus->CalcTextHeight(v23, &v65, 0, 0);
                    v25 = v21->uY;
                    v21->uHeight = v24;
                    v26 = v25 + v24 - 1;
                    v21->uW = v26;
                    v68 = v26;
                    v27 = color2;
                    if ( pDialogueWindow->pCurrentPosActiveItem != v72 )
                      v27 = white;
                    v65.DrawTitleText(pFontArrus, 0, v25, v27, v23, 3u);
                  }
                  ++_v1;
                  ++v72;
                }
                while ( (signed int)_v1 < v13->pStartingPosActiveItem + v13->pNumPresenceButton );
              }
            }
            else
            {
LABEL_76:
              sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[544], pPlayers[uActiveCharacter]->pName, pClassNames[pPlayers[uActiveCharacter]->classType]);// 
                                                // "Seek knowledge elsewhere %s the %s"
              strcat(pTmpBuf.data(), "\n \n");
              strcat(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[528]);// "I can offer you nothing further."
              v29 = color2;
              v30 = pFontArrus->CalcTextHeight(pTmpBuf.data(), &v65, 0, 0);
              v65.DrawTitleText(pFontArrus, 0, (174 - v30) / 2 + 138, v29, pTmpBuf.data(), 3u);
            }
          }
        }
        return;
      }
      if ( !HouseUI_CheckIfPlayerCanInteract() )
      {
        //v31 = pNPCTopics[122].pText;
        //v32 = color2;
        v33 = pFontArrus->CalcTextHeight(pNPCTopics[122].pText, &v65, 0, 0);
        v65.DrawTitleText(pFontArrus, 0, (212 - v33) / 2 + 101, color2, pNPCTopics[122].pText, 3);
        pDialogueWindow->pNumPresenceButton = 0;
        return;
      }
      v34 = pPlayers[uActiveCharacter]->uLevel;
      if ( v34 < v68 )
      {
        if ( (signed __int64)pPlayers[uActiveCharacter]->uExperience >= v5 )
        {
          if ( pParty->uNumGold >= v11)
          {
            Party::TakeGold(v11);
            PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, HouseSound_NotEnoughMoney_TrainingSuccessful);
            ++pPlayers[uActiveCharacter]->uLevel;
            pPlayers[uActiveCharacter]->uSkillPoints += pPlayers[uActiveCharacter]->uLevel / 10 + 5;
            pPlayers[uActiveCharacter]->sHealth = pPlayers[uActiveCharacter]->GetMaxHealth();
            pPlayers[uActiveCharacter]->sMana = pPlayers[uActiveCharacter]->GetMaxMana();

            uint max_level_in_party = player_levels[0];
            for (uint _it = 1; _it < 4; ++_it)
            {
              if (player_levels[_it] > max_level_in_party)
                max_level_in_party = player_levels[_it];
            }

            ++player_levels[uActiveCharacter - 1];
            if (player_levels[uActiveCharacter - 1] > max_level_in_party) // if we reach new maximum party level
                                                                          // feature is broken thou, since this array is always zeroed in EnterHouse
            {
              v40 = _494820_training_time(pParty->uCurrentHour);
              //v41 = window_SpeakInHouse->ptr_1C;
              v42 = 60 * (v40 + 4) - pParty->uCurrentMinute;
              if ((unsigned int)window_SpeakInHouse->ptr_1C == HOUSE_TRAINING_HALL_94 ||
                  (unsigned int)window_SpeakInHouse->ptr_1C == HOUSE_TRAINING_HALL_95)
                v42 += 720;
              RestAndHeal((signed int)(v42 + 10080));
              if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
                pOutdoor->SetFog();
            }
            pPlayers[uActiveCharacter]->PlaySound(SPEECH_87, 0);
            sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[430], pPlayers[uActiveCharacter]->pName, pPlayers[uActiveCharacter]->uLevel, pPlayers[uActiveCharacter]->uLevel / 10 + 5);// 
                                                // "%s is now Level %lu and has earned %lu Skill Points!"
            ShowStatusBarString(pTmpBuf.data(), 2);
            pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
            return;
          }
          ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);// "You don't have enough gold"
          v63 = 4;
LABEL_55:
          PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, (HouseSoundID)v63);
//LABEL_56:
          /*result = pMessageQueue_50CBD0->uNumMessages;
          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
          {
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
            result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
            *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
            ++pMessageQueue_50CBD0->uNumMessages;
          }
          return result;*/
          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
          return;
        }
        sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[538], (unsigned int)(v5 - pPlayers[uActiveCharacter]->uExperience), v34 + 1);// 
                                                // "You need %d more experience to train to level %d"
        v35 = 0;
        v62 = 3;
        v60 = pTmpBuf.data();
        v58 = color2;
        v36 = (212 - pFontArrus->CalcTextHeight(pTmpBuf.data(), &v65, 0, 0)) / 2 + 88;
      }
      else
      {
        sprintf(pTmpBuf.data(), "%s\n \n%s", pGlobalTXT_LocalizationStrings[536], pGlobalTXT_LocalizationStrings[529]);// 
                                                // ""With your skills, you should be working here as a teacher.""
                                                // ""Sorry, but we are unable to train you.""
        v35 = 0;
        v62 = 3;
        v60 = pTmpBuf.data();
        v58 = color2;
        v36 = (212 - pFontArrus->CalcTextHeight(pTmpBuf.data(), &v65, 0, 0)) / 2 + 101;
      }
      v65.DrawTitleText(pFontArrus, v35, v36, v58, v60, v62);
      v63 = 3;
      goto LABEL_55;
    }

    if (HouseUI_CheckIfPlayerCanInteract())
    {
      v43 = pDialogueWindow;
      v72 = 0;
      pShopOptions[0] = pTmpBuf.data();
      pShopOptions[1] = pGlobalTXT_LocalizationStrings[160];// "Learn Skills"
      v44 = pDialogueWindow->pNumPresenceButton;
      v73 = pDialogueWindow->pStartingPosActiveItem;
      if ( v73 < v73 + v44 )
      {
        v45 = pShopOptions.data();
        do
        {
          if ( v43->GetControl(v73)->msg_param == HOUSE_DIALOGUE_TRAININGHALL_TRAIN )
          {
            //v46 = pPlayers[uActiveCharacter]->uLevel;
            if (pPlayers[uActiveCharacter]->uLevel >= v68)
              sprintfex(*v45, "%s\n \n%s",
                        pGlobalTXT_LocalizationStrings[536], pGlobalTXT_LocalizationStrings[529]); //"With your skills, you should be working here as a teacher."    "Sorry, but we are unable to train you."
            else
            {
              if (pPlayers[uActiveCharacter]->uExperience < v5)
                sprintfex(*v45, pGlobalTXT_LocalizationStrings[538],  // "You need %d more experience to train to level %d"
                          (uint)(v5 - pPlayers[uActiveCharacter]->uExperience), pPlayers[uActiveCharacter]->uLevel + 1);
              else
                sprintfex(*v45, pGlobalTXT_LocalizationStrings[537],  // "Train to level %d for %d gold"
                          pPlayers[uActiveCharacter]->uLevel + 1, v11);
            }
          }
          v47 = pFontArrus->CalcTextHeight(*v45, &v65, 0, 0);
          v43 = pDialogueWindow;
          v72 += v47;
          ++v45;
          ++v73;
        }
        while ( v73 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
      }

      v49 = (2 * (87 - (174 - v72) / 2) - v72) / 2 - (174 - v72) / 2 / 2 + 138;
      v73 = v43->pStartingPosActiveItem;
      if (v43->pStartingPosActiveItem < v43->pStartingPosActiveItem + v43->pNumPresenceButton)
      {
        int _v3 = 2;
        v51 = pShopOptions.data();
        do
        {
          v52 = v43->GetControl(v73);
          v53 = v52;
          v52->uY = (174 - v72) / 2 + v49;
          v54 = pFontArrus->CalcTextHeight(*v51, &v65, 0, 0);
          v55 = v53->uY;
          v53->uHeight = v54;
          v56 = v54 + v55 - 1;
          v53->uW = v56;
          v49 = v56;
          v57 = color2;
          if ( pDialogueWindow->pCurrentPosActiveItem != _v3 )
            v57 = white;
          v65.DrawTitleText(pFontArrus, 0, v55, v57, *v51, 3u);
          v43 = pDialogueWindow;
          ++_v3;
          ++v51;
          ++v73;
        }
        while ( v73 < pDialogueWindow->pStartingPosActiveItem + pDialogueWindow->pNumPresenceButton);
      }
    }
  }
}

//----- (004B6478) --------------------------------------------------------
void sub_4B6478()
    {
  GUIWindow *v0; // ebx@1
  Player *v1; // edi@1
  unsigned int v2; // eax@1
  signed int v3; // esi@1
  int v4; // ebx@1
  unsigned int v5; // esi@5
  int v6; // edi@6
  int result; // eax@13
  GUIWindow *v8; // ebx@17
  int v9; // eax@17
  int v10; // ecx@17
  unsigned int v11; // ecx@18
  int v12; // eax@20
  int v13; // eax@21
  GUIButton *v14; // esi@27
  int v15; // ecx@27
  unsigned int v16; // eax@28
  const char *v17; // ebx@29
  int v18; // eax@29
  unsigned int v19; // ecx@29
  int v20; // eax@29
  unsigned __int16 v21; // ax@29
  unsigned __int16 v22; // ST14_2@36
  int v23; // eax@36
  const char *v24; // ST18_4@37
  unsigned __int16 v25; // ST14_2@37
  int v26; // eax@37
  int v27; // [sp-4h] [bp-80h]@8
  GUIWindow v28; // [sp+Ch] [bp-70h]@1
  GUIWindow *v29; // [sp+60h] [bp-1Ch]@17
  unsigned int v30; // [sp+64h] [bp-18h]@1
  int v31; // [sp+68h] [bp-14h]@1
  int v32; // [sp+6Ch] [bp-10h]@1
  int v33; // [sp+70h] [bp-Ch]@17
  int v34; // [sp+74h] [bp-8h]@17
  int v35; // [sp+78h] [bp-4h]@17

  v0 = window_SpeakInHouse;
  memcpy(&v28, window_SpeakInHouse, sizeof(v28));
  v1 = pPlayers[uActiveCharacter];
  v28.uFrameX = 483;
  v28.uFrameWidth = 148;
  v28.uFrameZ = 334;
  v30 = TargetColor(0xFFu, 0xFFu, 0xFFu);
  v31 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
  v2 = 52 * (unsigned int)v0->ptr_1C;
  //v32 = (unsigned __int8)(((p2DEvents_minus1___00[v2 / 2] != 18) - 1) & 0x96) + 100;
  v32 = (unsigned __int8)(((p2DEvents[(unsigned int)v0->ptr_1C - 1].uType != 18) - 1) & 0x96) + 100;
  //v3 = (signed __int64)((double)v32 * p2DEvents_minus1__20[v2 / 4]);
  v3 = (signed __int64)((double)v32 * p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier);
  v4 = v3 * (100 - v1->GetMerchant()) / 100;
  v32 = v4;
  if ( v4 < v3 / 3 )
  {
    v4 = v3 / 3;
    v32 = v3 / 3;
  }
  if ( dialog_menu_id != HOUSE_DIALOGUE_MAIN)
  {
    if ( HouseUI_CheckIfPlayerCanInteract() )
    {
      v5 = 0;

      __debugbreak();
      //pSkillAvailabilityPerClass[8 + v58->uClass][4 + v23]
      // or
      //byte_4ED970_skill_learn_ability_by_class_table[v58->uClass][v23 - 36]
      // or
      //byte_4ED970_skill_learn_ability_by_class_table[v58->uClass - 1][v23 + 1]
      __debugbreak(); // whacky condition - fix
      if (false
      //if ( !*(&byte_4ED94C[37 * v1->uClass / 3] + dword_F8B19C)
        || (v6 = (int)(&v1->uIntelligence + dialog_menu_id), *(short *)v6) )
      {
        pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
      }
      else
      {
        if ( pParty->uNumGold < v4 )
        {
          ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
          v27 = 4;
        }
        else
        {
          Party::TakeGold(v4);
          *(short *)v6 = 1;
          v27 = 2;
        }
        PlayHouseSound((unsigned int)window_SpeakInHouse->ptr_1C, (HouseSoundID)v27);
      }
    }
    else
    {
      v5 = 0;
    }
    /*result = pMessageQueue_50CBD0->uNumMessages;
    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
    {
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
      result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
      *(&pMessageQueue_50CBD0->uNumMessages + result) = v5;
      ++pMessageQueue_50CBD0->uNumMessages;
    }*/
    pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v5);
    return; // void func
  }
  if ( !(unsigned __int16)_449B57_test_bit((unsigned __int8 *)v1->_guilds_member_bits, word_4F0754[2 * (unsigned int)window_SpeakInHouse->ptr_1C]) )
  {
    v24 = pNPCTopics[171].pText;
    v25 = v31;
    v26 = pFontArrus->CalcTextHeight(pNPCTopics[171].pText, &v28, 0, 0);
    v28.DrawTitleText(pFontArrus, 0, (212 - v26) / 2 + 101, v25, v24, 3u);
    pDialogueWindow->pNumPresenceButton = 0;
    return ;
  }

  if ( !HouseUI_CheckIfPlayerCanInteract() )
    return;
  v8 = pDialogueWindow;
  v33 = 0;
  v34 = 0;
  v29 = pDialogueWindow;
  v9 = pDialogueWindow->pStartingPosActiveItem;
  v10 = v9 + pDialogueWindow->pNumPresenceButton;
  v35 = pDialogueWindow->pStartingPosActiveItem;
  if ( v9 >= v10 )
    goto LABEL_40;
  do
  {
    v11 = v8->GetControl(v35)->msg_param - 36;
    if ( byte_4ED970_skill_learn_ability_by_class_table[v1->classType / 3][v11] && !v1->pActiveSkills[v11] )
    {
      v12 = pFontArrus->CalcTextHeight(pSkillNames[v11], &v28, 0, 0);
      v33 += v12;
      ++v34;
    }
    v13 = v8->pStartingPosActiveItem;
    ++v35;
  }
  while ( v35 < v8->pNumPresenceButton + v13 );
  if ( !v34 )
  {
LABEL_40:
    sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[544], v1->pName, pClassNames[v1->classType]);
    strcat(pTmpBuf.data(), "\n \n");
    strcat(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[528]);
    v22 = v31;
    v23 = pFontArrus->CalcTextHeight(pTmpBuf.data(), &v28, 0, 0);
    v28.DrawTitleText(pFontArrus, 0, (174 - v23) / 2 + 138, v22, pTmpBuf.data(), 3u);
    return; 
  }
  sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[401], v32);
  v28.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf.data(), 3u);
  v32 = (149 - v33) / v34;
  if ( (149 - v33) / v34 > 32 )
    v32 = 32;

  v35 = v8->pStartingPosActiveItem;
  v34 = (149 - v34 * v32 - v33) / 2 - v32 / 2 + 162;
  if ( v8->pStartingPosActiveItem < v8->pStartingPosActiveItem+ v8->pNumPresenceButton )
  {
    v33 = 2;
    do
    {
      v14 = v8->GetControl(v35);
      v15 = v14->msg_param - 36;
      if ( byte_4ED970_skill_learn_ability_by_class_table[v1->classType / 3][v15] )
      {
        v16 = 0;
        if ( !v1->pActiveSkills[v15] )
        {
          v17 = pSkillNames[v15];
          v14->uY = v32 + v34;
          v18 = pFontArrus->CalcTextHeight(v17, &v28, 0, 0);
          v19 = v14->uY;
          v14->uHeight = v18;
          v20 = v19 + v18 - 1;
          v14->uW = v20;
          v34 = v20;
          v21 = v31;
          if ( pDialogueWindow->pCurrentPosActiveItem != v33 )
            v21 = v30;
          v28.DrawTitleText(pFontArrus, 0, v19, v21, v17, 3u);
          goto LABEL_34;
        }
      }
      else
      {
        v16 = 0;
      }
      v14->uW = v16;
      v14->uHeight = v16;
      v14->uY = v16;
LABEL_34:
      v8 = v29;
      ++v35;
      ++v33;
    }
    while ( v35 <v29->pNumPresenceButton + v29->pStartingPosActiveItem );
  }
  return;
}

//----- (004B2A74) --------------------------------------------------------
void SimpleHouseAndBoatsDialog()
{
  char *v0; // esi@3
  char *v1; // ST1C_4@3
  char *v2; // eax@3
  const char *v3; // ST1C_4@5
  int v4; // eax@5
  unsigned int i; // eax@5
  NPCData *v6; // esi@6
  unsigned __int16 v7; // bx@6
  unsigned int v8; // eax@6
  int v9; // eax@11
  unsigned int v10; // ecx@12
  int v11; // eax@12
  int v12; // esi@12
  char *v13; // eax@12
  GUIWindow *v14; // ebx@13
  char *v15; // esi@14
  GUIButton *v16; // eax@15
  unsigned int v17; // ecx@15
  int v18; // ecx@17
  int v19; // ecx@18
  int v20; // ecx@19
  int v21; // ecx@20
  int v22; // ecx@21
  unsigned int v23; // ecx@23
  int v24; // ecx@35
  int v25; // ecx@36
  int v26; // ecx@37
  int v27; // ecx@38
  int v28; // ecx@39
  char *v29; // esi@42
  unsigned int v30; // ST20_4@42
  int v31; // ST1C_4@42
  unsigned int v32; // eax@42
  char *v33; // eax@43
  int v34; // esi@51
  int v35; // eax@51
  unsigned int v36; // edi@51
  GUIButton *v37; // eax@52
  int v38; // eax@52
  signed int v39; // ecx@54
  int v40; // edi@57
  GUIButton *v41; // eax@60
  GUIButton *v42; // esi@60
  const char *v43; // ebx@60
  int v44; // eax@60
  unsigned int v45; // ecx@60
  unsigned __int16 v46; // ax@60
  GUIFont *v47; // ebx@64
  int v48; // esi@64
  char *v49; // eax@66
  GUIWindow w; // [sp+Ch] [bp-110h]@64
  GUIWindow v52; // [sp+60h] [bp-BCh]@13
  GUIWindow a1; // [sp+B4h] [bp-68h]@1
  unsigned int v54; // [sp+108h] [bp-14h]@14
  int v55; // [sp+10Ch] [bp-10h]@6
  int v56; // [sp+110h] [bp-Ch]@13
  char *pInString; // [sp+114h] [bp-8h]@12
  NPCData *v58; // [sp+118h] [bp-4h]@6

  memcpy(&a1, pDialogueWindow, sizeof(a1));
  if ( pDialogueNPCCount == uNumDialogueNPCPortraits && uHouse_ExitPic )
  {
    v0 = pMapStats->pInfos[uHouse_ExitPic].pName;
    v1 = pMapStats->pInfos[uHouse_ExitPic].pName;
    a1.uFrameX = 493;
    a1.uFrameWidth = 126;
    a1.uFrameZ = 366;
    a1.DrawTitleText(pFontCreate, 0, 2u, 0, v1, 3u);
    a1.uFrameX = 483;
    a1.uFrameWidth = 148;
    a1.uFrameZ = 334;
    v2 = pTransitionStrings[uHouse_ExitPic];
    if ( !v2 )
    {
      sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[411], v0);
      v2 = pTmpBuf.data();
    }
    v3 = v2;
    v4 = pFontCreate->CalcTextHeight(v2, &a1, 0, 0);
    a1.DrawTitleText(pFontCreate, 0, (212 - v4) / 2 + 101, 0, v3, 3u);
    return;
  }
  a1.uFrameWidth -= 10;
  a1.uFrameZ -= 10;
  v58 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) )];//- 1
  v6 = v58;
  v55 = TargetColor(0xE1u, 0xCDu, 0x23u);
  v7 = TargetColor(0x15u, 0x99u, 0xE9u);
  v8 = v6->uProfession;
  if ( v8 )
    sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[429], v6->pName, aNPCProfessionNames[v8]);
  else
    strcpy(pTmpBuf.data(), v6->pName);
  a1.DrawTitleText(pFontCreate, 0x1E3u, 0x71u, v7, pTmpBuf.data(), 3u);
  if ( !dword_591080 )
  {
    if ( !uDialogueType )
    {
      v9 = v6->greet;
      if ( v9 )
      {
        v10 = v6->uFlags;
        a1.uFrameWidth = game_viewport_width;
        a1.uFrameZ = 452;
        pInString = (char *)*(&pNPCStats->field_17884 + ((v10 & 3) == 2) + 2 * v9);
        v11 = pFontArrus->CalcTextHeight(pInString, &a1, 13, 0);
        v12 = v11 + 7;
        pRenderer->_4A6A68(8, 352 - (v11 + 7),
          pIcons_LOD->GetTexture(uTextureID_Leather),
          pIcons_LOD->GetTexture(uTextureID_Leather)->uTextureHeight - (v11 + 7));
        pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
        v13 = FitTextInAWindow(pInString, pFontArrus, &a1, 0xDu, 0);
        pDialogueWindow->DrawText(pFontArrus, 13, 354 - v12, 0, v13, 0, 0, 0);
      }
    }
  }
  v14 = pDialogueWindow;
  memcpy(&v52, pDialogueWindow, sizeof(v52));
  v52.uFrameX = 483;
  v52.uFrameWidth = 148;
  v52.uFrameZ = 334;
  v56 = v52.pStartingPosActiveItem;
  if ( v52.pStartingPosActiveItem < v52.pStartingPosActiveItem + v52.pNumPresenceButton )
  {
    v15 = "";//(char *)v54;
    while ( 1 )
    {
      v16 = v52.GetControl(v56);
      v17 = v16->msg_param;
      pInString = (char *)v16;
      if ( (signed int)v17 > 24 )
      {
        v24 = v17 - 76;
        if ( !v24 )
        {
          v15 = pGlobalTXT_LocalizationStrings[406];
          goto LABEL_49;
        }
        v25 = v24 - 1;
        if ( !v25 )
        {
          v15 = pGlobalTXT_LocalizationStrings[407];
          goto LABEL_49;
        }
        v26 = v25 - 2;
        if ( !v26 )
        {
          v33 = _4B254D_SkillMasteryTeacher((int)v52.ptr_1C);
LABEL_44:
          v15 = v33;
LABEL_45:
          v16 = (GUIButton *)pInString;
          goto LABEL_49;
        }
        v27 = v26 - 3;
        if ( !v27 )
        {
          v33 = (char *)ContractSelectText((int)v52.ptr_1C);
          goto LABEL_44;
        }
        v28 = v27 - 1;
        if ( !v28 )
        {
          v29 = (char *)&pMonsterStats + 88 * word_F8B1A0;
          v30 = TargetColor(0xFFu, 0xFFu, 0xFFu);
          v31 = *(int *)v29;
          v32 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
          sprintfex(pTmpBuf.data(), "\f%05d%s\f%05d", v32, v31, v30);
          sprintfex(pTmpBuf2.data(), dword_F8B1A4, pTmpBuf.data(), 100 * (unsigned __int8)v29[8]);
          current_npc_text = pTmpBuf2.data();
          v15 = "";
          goto LABEL_45;
        }
        if ( v28 != 10 )
          goto LABEL_41;
      }
      else
      {
        if ( v17 == 24 )
        {
          v23 = v58->evt_F;
LABEL_33:
          v15 = (char *)pNPCTopics[v23-1].pTopic;//(&dword_721660)[8 * v23];
          if ( !v15 )
          {
            v16->msg_param = 0;
            v15 = "";
          }
          goto LABEL_49;
        }
        v18 = v17 - 13;
        if ( v18 )
        {
          v19 = v18 - 6;
          if ( !v19 )
          {
            v23 = v58->evt_A;
            goto LABEL_33;
          }
          v20 = v19 - 1;
          if ( !v20 )
          {
            v15 = (char *)pNPCTopics[v58->evt_B-1].pTopic;//(&dword_721660)[8 * v58->evtb];
            if ( !v15 )
            {
              v16->msg_param = 0;
              v15 = "";
            }
            if ( uDialogueType != 84 )
              goto LABEL_49;
            sprintf(pTmpBuf.data(), format_4E2D80, v55, pItemsTable->pItems[contract_approved].pUnidentifiedName);
            sprintf(pTmpBuf2.data(), current_npc_text, pTmpBuf.data());
            current_npc_text = pTmpBuf2.data();
            goto LABEL_45;
          }
          v21 = v20 - 1;
          if ( !v21 )
          {
            v23 = v58->evt_C;
            goto LABEL_33;
          }
          v22 = v21 - 1;
          if ( !v22 )
          {
            v23 = v58->evt_D;
            goto LABEL_33;
          }
          if ( v22 == 1 )
          {
            v23 = v58->evt_E;
            goto LABEL_33;
          }
LABEL_41:
          v15 = "";
          goto LABEL_49;
        }
        v15 = pGlobalTXT_LocalizationStrings[122];
      }
LABEL_49:
      strcpy(v16->pButtonName, v15);
      ++v56;
      if ( v56 >= v52.pStartingPosActiveItem + v52.pNumPresenceButton )
      {
        v14 = pDialogueWindow;
        break;
      }
    }
  }
  v34 = 0;
  v54 = TargetColor(0xFFu, 0xFFu, 0xFFu);
  v35 = TargetColor(0xE1u, 0xCDu, 0x23u);
  v36 = v14->pStartingPosActiveItem;
  v55 = v35;
  for ( i = v36 + v14->pNumPresenceButton; (signed int)v36 < (signed int)i; i = pDialogueWindow->pNumPresenceButton
                                                                    + pDialogueWindow->pStartingPosActiveItem )
  {
    v37 = v14->GetControl(v36);
    v38 = pFontArrus->CalcTextHeight(v37->pButtonName, &v52, 0, 0);
    v14 = pDialogueWindow;
    v34 += v38;
    ++v36;
  }
  v39 = v14->pNumPresenceButton;
  if ( v39 )
  {
    v58 = (NPCData *)((174 - v34) / v39);
    if ( (signed int)v58 > 32 )
      v58 = (NPCData *)32;
    pInString = (char *)2;
    v40 = (174 - (signed int)v58 * v39 - v34) / 2 - (signed int)v58 / 2 + 138;
    v56 = v14->pStartingPosActiveItem;
    i = v56;
    if ( (signed int)i < (signed int)(i + v39) )
    {
      while ( 1 )
      {
        v41 = v14->GetControl(i);
        v42 = v41;
        v43 = v41->pButtonName;
        v41->uY = (unsigned int)((char *)v58 + v40);
        v44 = pFontArrus->CalcTextHeight(v41->pButtonName, &v52, 0, 0);
        v45 = v42->uY;
        v42->uHeight = v44;
        v40 = v45 + v44 - 1;
        v42->uW = v40;
        v46 = v55;
        if ( (char *)pDialogueWindow->pCurrentPosActiveItem != pInString )
          v46 = v54;
        v52.DrawTitleText(pFontArrus, 0, v45, v46, v43, 3u);
        v14 = pDialogueWindow;
        ++pInString;
        ++v56;
        i = pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem;
        if ( v56 >= (signed int)i )
          break;
        i = v56;
      }
    }
  }
  if ( current_npc_text )
  {
    w.uFrameWidth = 458;
    w.uFrameZ = 457;
    v47 = pFontArrus;
    v48 = pFontArrus->CalcTextHeight(current_npc_text, &w, 13, 0) + 7;
    if ( 352 - v48 < 8 )
    {
      v47 = pFontCreate;
      v48 = pFontCreate->CalcTextHeight(current_npc_text, &w, 13, 0) + 7;
    }
    pRenderer->_4A6A68(8, 352 - v48,
      pIcons_LOD->GetTexture(uTextureID_Leather),
      pIcons_LOD->GetTexture(uTextureID_Leather)->uTextureHeight - v48);
    pRenderer->DrawTextureIndexed(8u, 347 - v48, pTexture_591428);
    v49 = FitTextInAWindow(current_npc_text, v47, &w, 0xDu, 0);
    a1.DrawText(v47, 13, 354 - v48, 0, v49, 0, 0, 0);
  }
}
//----- (004B4F4F) --------------------------------------------------------
void JailDialog()
{
  const char *v0; // esi@1
  const char *v1; // ST10_4@1
  unsigned __int16 v2; // ST0C_2@1
  int v3; // eax@1
  GUIWindow v5; // [sp+8h] [bp-54h]@1

  memcpy(&v5, window_SpeakInHouse, sizeof(v5));
  v0 = pGlobalTXT_LocalizationStrings[672];
  v1 = pGlobalTXT_LocalizationStrings[672];
  v5.uFrameX = 483;
  v5.uFrameWidth = 148;
  v5.uFrameZ = 334;
  v2 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
  v3 = pFontArrus->CalcTextHeight(v0, &v5, 0, 0);
  v5.DrawTitleText(pFontArrus, 0, (310 - v3) / 2 + 18, v2, v1, 3u);
}