view mm7_4.cpp @ 471:c43f156a95c9

ArmorShopDialog crash fixed. All shops show its items
author Gloval
date Mon, 25 Feb 2013 23:33:15 +0400
parents fcdaa804074f
children 7f1b00901cf7
line wrap: on
line source

#include <io.h>
#include <direct.h>
#include <assert.h>

#include "MM7.h"

#include "MapInfo.h"
#include "Game.h"
#include "GUIWindow.h"
#include "GUIButton.h"
#include "GUIFont.h"
#include "Party.h"
#include "AudioPlayer.h"
#include "Outdoor.h"
#include "IndoorCamera.h"
#include "Overlays.h"
#include "Monsters.h"
#include "Arcomage.h"
#include "LOD.h"
#include "Actor.h"
#include "Allocator.h"
#include "Events.h"
#include "Viewport.h"
#include "FrameTableInc.h"
#include "Math.h"
#include "LayingItem.h"
#include "ObjectList.h"
#include "Chest.h"
#include "PaletteManager.h"
#include "DecorationList.h"
#include "SaveLoad.h"
#include "stru123.h"
#include "stru287.h"
#include "Time.h"
#include "IconFrameTable.h"
#include "GUIProgressBar.h"
#include "Bink_Smacker.h"
#include "TileFrameTable.h"
#include "PlayerFrameTable.h"
#include "Awards.h"
#include "Autonotes.h"
#include "stru160.h"
#include "stru279.h"
#include "TurnEngine.h"
#include "FactionTable.h"
#include "StorylineTextTable.h"
#include "Random.h"
#include "stru277.h"
#include "stru298.h"
#include "stru12.h"
#include "stru351.h"
#include "Events2D.h"
#include "stru159.h"
#include "texts.h"
#include "Log.h"

#include "mm7_data.h"















//----- (0046CC4B) --------------------------------------------------------
void __cdecl _46CC4B_check_event_triggers()
{
  int v0; // eax@1
  LevelDecoration *v1; // esi@2
  signed int v2; // edi@2
  int v3; // ebx@2
  int v4; // eax@3
  int v5; // ebx@3
  unsigned int v6; // ecx@3
  unsigned int v7; // edx@6
  unsigned int v8; // edx@8
  Actor *v9; // edi@13
  int v10; // ebx@14
  int v11; // eax@14
  int v12; // ebx@14
  unsigned int v13; // ecx@14
  int v14; // edx@15
  unsigned int v15; // edx@17
  unsigned int v16; // edx@19
  char *v17; // edi@25
  int v18; // ebx@26
  int v19; // eax@26
  int v20; // ebx@26
  unsigned int v21; // ecx@26
  int v22; // edx@27
  unsigned int v23; // edx@29
  unsigned int v24; // edx@31
  int v25; // [sp+0h] [bp-24h]@3
  int v26; // [sp+0h] [bp-24h]@14
  int v27; // [sp+0h] [bp-24h]@26
  int v28; // [sp+4h] [bp-20h]@3
  int v29; // [sp+4h] [bp-20h]@14
  int v30; // [sp+4h] [bp-20h]@26
  signed int v31; // [sp+8h] [bp-1Ch]@2
  int v32; // [sp+Ch] [bp-18h]@2
  int v33; // [sp+10h] [bp-14h]@2
  int i; // [sp+14h] [bp-10h]@1
  int v35; // [sp+18h] [bp-Ch]@2
  int v36; // [sp+1Ch] [bp-8h]@3
  signed int v37; // [sp+1Ch] [bp-8h]@12
  signed int v38; // [sp+20h] [bp-4h]@24

  v0 = 0;
  for ( i = 0; i < _6836C8_num_decorations_6807E8; ++i )
  {
    v1 = &pLevelDecorations[_6807E8_level_decorations_ids[v0]];
    v2 = v1->field_18;
    v3 = v1->vPosition.y;
    v33 = v1->vPosition.x;
    v32 = v1->vPosition.y;
    v35 = v1->vPosition.z;
    v31 = v1->field_18;
    if ( v1->field_2 & 1 )
    {
      v36 = abs(v1->vPosition.x - pParty->vPosition.x);
      v25 = abs(v3 - pParty->vPosition.y);
      v28 = abs(v35 - pParty->vPosition.z);
      v4 = v36;
      v5 = v25;
      v6 = v28;
      if ( v36 < v25 )
      {
        v4 = v25;
        v5 = v36;
      }
      if ( v4 < v28 )
      {
        v7 = v4;
        v4 = v28;
        v6 = v7;
      }
      if ( v5 < (signed int)v6 )
      {
        v8 = v6;
        v6 = v5;
        v5 = v8;
      }
      if ( (signed int)(((unsigned int)(11 * v5) >> 5) + (v6 >> 2) + v4) < v2 )
        EventProcessor(v1->field_16_event_id, 8 * i | 5, 1);
    }
    if ( v1->field_2 & 2 )
    {
      v37 = 0;
      if ( (signed int)uNumActors > 0 )
      {
        v9 = pActors;//[0].vPosition.y;
        do
        {
		  v10 = abs(v33 - v9->vPosition.x);
          v29 = abs(v32 - v9->vPosition.y);
          v26 = abs(v35 - v9->vPosition.z);
          v11 = v10;
          v12 = v29;
          v13 = v26;
          if ( v11 < v29 )
          {
            v14 = v11;
            v11 = v29;
            v12 = v14;
          }
          if ( v11 < v26 )
          {
            v15 = v11;
            v11 = v26;
            v13 = v15;
          }
          if ( v12 < (signed int)v13 )
          {
            v16 = v13;
            v13 = v12;
            v12 = v16;
          }
          if ( (signed int)(((unsigned int)(11 * v12) >> 5) + (v13 >> 2) + v11) < v31 )
            EventProcessor(v1->field_16_event_id, 0, 1);
          ++v37;
          ++v9;
        }
        while ( v37 < (signed int)uNumActors );
      }
    }
    if ( v1->field_2 & 4 )
    {
      v38 = 0;
      if ( (signed int)uNumLayingItems > 0 )
      {
        v17 = (char *)&pLayingItems[0].vPosition.y;
        do
        {
          v18 = abs(v33 - *((int *)v17 - 1));
          v30 = abs(v32 - *(int *)v17);
          v27 = abs(v35 - *((int *)v17 + 1));
          v19 = v18;
          v20 = v30;
          v21 = v27;
          if ( v19 < v30 )
          {
            v22 = v19;
            v19 = v30;
            v20 = v22;
          }
          if ( v19 < v27 )
          {
            v23 = v19;
            v19 = v27;
            v21 = v23;
          }
          if ( v20 < (signed int)v21 )
          {
            v24 = v21;
            v21 = v20;
            v20 = v24;
          }
          if ( (signed int)(((unsigned int)(11 * v20) >> 5) + (v21 >> 2) + v19) < v31 )
            EventProcessor(v1->field_16_event_id, 0, 1);
          ++v38;
          v17 += 112;
        }
        while ( v38 < (signed int)uNumLayingItems );
      }
    }
    v0 = i + 1;
  }
}
// 6836C8: using guessed type int 6836C8_num_decorations_6807E8;

//----- (0046CEC3) --------------------------------------------------------
int _46CEC3_get_floor_level(int x, int y, int z, unsigned int uSectorID, unsigned int *pFaceID)
{
  //BLVSector *v5; // edi@1
  //int v6; // ecx@1
  //Vec3_short_ *v7; // edx@1
  //BLVFace *v8; // esi@2
  //int v9; // eax@8
  //int v10; // edi@8
  //int v11; // eax@10
  int v12; // ecx@10
  int v13; // ecx@13
  signed int v14; // ebx@14
  int v15; // eax@16
  int v16; // edx@19
  int v17; // ST18_4@19
  signed int v18; // edx@19
  signed __int64 v19; // qtt@19
  PolygonType v20; // al@25
  int v21; // eax@27
  int v22; // ecx@29
  //BLVFace *v23; // eax@33
  //int v24; // esi@39
  //int v25; // edi@39
  //int v26; // esi@41
  int v27; // ecx@43
  signed int v28; // eax@45
  int v29; // ebx@47
  int v30; // edx@49
  int v31; // ST10_4@49
  signed int v32; // edx@49
  signed __int64 v33; // qtt@49
  signed int v34; // eax@54
  signed int v35; // esi@56
  int result; // eax@57
  int v37; // edi@61
  int v38; // edx@62
  //int v39; // [sp+Ch] [bp-34h]@1
  //int v40; // [sp+10h] [bp-30h]@2
  int v41; // [sp+14h] [bp-2Ch]@12
  //unsigned __int16 *v42; // [sp+18h] [bp-28h]@1
  //BLVSector *v43; // [sp+1Ch] [bp-24h]@1
  int v44; // [sp+20h] [bp-20h]@10
  int v45; // [sp+24h] [bp-1Ch]@10
  //signed int v46; // [sp+24h] [bp-1Ch]@38
  bool v47; // [sp+24h] [bp-1Ch]@43
  bool v48; // [sp+28h] [bp-18h]@10
  bool v49; // [sp+28h] [bp-18h]@41
  bool v50; // [sp+2Ch] [bp-14h]@12
  int v51; // [sp+2Ch] [bp-14h]@41
  //signed int v52; // [sp+30h] [bp-10h]@7
  signed int v53; // [sp+30h] [bp-10h]@10
  signed int v54; // [sp+30h] [bp-10h]@41
  signed int v55; // [sp+34h] [bp-Ch]@1
  //signed int v56; // [sp+38h] [bp-8h]@1
  //signed int v57; // [sp+3Ch] [bp-4h]@1
  //int uSectorIDa; // [sp+4Ch] [bp+Ch]@1
  //signed int uSectorIDb; // [sp+4Ch] [bp+Ch]@32

  LOG_DECOMPILATION_WARNING();

  //auto a1 = x;
  //auto a2 = y;
  //auto a3 = z;

  //v5 = &pIndoor->pSectors[uSectorID];
  auto pSector = &pIndoor->pSectors[uSectorID];
  //v57 = y;
  //v56 = x;
  //v6 = 0;
  v55 = 0;
  //v43 = v5;
  //v42 = v5->pFloors;
  //v7 = pIndoor->pVertices;
  //v39 = v5->uNumFloors;
  //for ( uSectorIDa = 0; uSectorIDa < v39; ++uSectorIDa )
  for (uint i = 0; i < pSector->uNumFloors; ++i)
  {
    //v40 = (int)&v42[v6];
    //v8 = &pIndoor->pFaces[pSector->pFloors[i]];
    auto pFloor = &pIndoor->pFaces[pSector->pFloors[i]];
    if (pFloor->Clickable())
      continue;

    if (x <= pFloor->pBounding.x2 && x >= pFloor->pBounding.x1 &&
        y <= pFloor->pBounding.y2 && y >= pFloor->pBounding.y1)
    {
      //v52 = 0;
      for (uint j = 0; j < pFloor->uNumVertices; ++j)
      {
          //v9 = v52;
          //v10 = 2 * v52;
        word_721460[2 * j] =     pFloor->pXInterceptDisplacements[j] + pIndoor->pVertices[pFloor->pVertexIDs[j]].x;
        word_721460[2 * j + 1] = pFloor->pXInterceptDisplacements[j] + pIndoor->pVertices[pFloor->pVertexIDs[j + 1]].x;
        word_721390[2 * j] =     pFloor->pYInterceptDisplacements[j] + pIndoor->pVertices[pFloor->pVertexIDs[j]].y;
        word_721390[2 * j + 1] = pFloor->pYInterceptDisplacements[j] + pIndoor->pVertices[pFloor->pVertexIDs[j + 1]].y;
        //}
        //while ( v52 < v8->uNumVertices );
        //v5 = v43;
      }
      v44 = 2 * pFloor->uNumVertices;
      //v11 = 2 * pFloor->uNumVertices;
      word_721460[2 * pFloor->uNumVertices] = word_721460[0];
      word_721390[2 * pFloor->uNumVertices] = word_721390[0];

      v48 = word_721390[0] >= y;
      v12 = 0;
      v53 = 0;
      v45 = 0;
      if ( pFloor->uNumVertices > 0 )
      {
        do
        {
          if ( v53 >= 2 )
            break;
          v41 = word_721390[v12 + 1];
          v50 = word_721390[v12 + 1] >= y;
          if ( v48 == v50 )
          {
            v13 = v45;
          }
          else
          {
            v13 = v45;
            if ( word_721460[v45 + 1] >= x )
              v14 = 0;
            else
              v14 = 2;
            v15 = v14 | word_721460[v45] < x;
            if ( v15 != 3 )
            {
              if ( !v15
                || (v16 = word_721390[v45],
                    v17 = v41 - v16,
                    v18 = y - v16,
                    LODWORD(v19) = v18 << 16,
                    HIDWORD(v19) = v18 >> 16,
                    //v7 = pIndoor->pVertices,
                    (signed int)(((unsigned __int64)(((signed int)word_721460[v45 + 1] - (signed int)word_721460[v45])
                                                   * v19
                                                   / v17) >> 16)
                               + word_721460[v45]) >= x) )
                ++v53;
            }
          }
          v12 = v13 + 1;
          v48 = v50;
          v45 = v12;
        }
        while ( v12 < v44 );

        if ( v53 == 1 )
        {
          if ( v55 >= 50 )
            break;
          v20 = pFloor->uPolygonType;
          if ( v20 == 3 || v20 == 5 )
          {
            v21 = pIndoor->pVertices[*pFloor->pVertexIDs].z;
          }
          else
          {
            //v7 = pIndoor->pVertices;
            v21 = ((unsigned __int64)(pFloor->zCalc1 * (signed __int64)x) >> 16)
                + ((unsigned __int64)(pFloor->zCalc2 * (signed __int64)y) >> 16)
                + HIWORD(pFloor->zCalc3);
          }
          v22 = v55++;
          dword_7212C8[v22] = v21;
          dword_721200[v22] = pSector->pFloors[i];
        }
      }
    }
    //v6 = uSectorIDa + 1;
  }

  if ( pSector->field_0 & 8 )
  {
    for (uint i = 0; i < pSector->uNumPortals; ++i)
    {
      //v23 = &pIndoor->pFaces[v5->pPortals[uSectorIDb]];
      auto portal = &pIndoor->pFaces[pSector->pPortals[i]];
      if (portal->uPolygonType != POLYGON_Floor)
        continue;

      if (x <= portal->pBounding.x2 &&
          x >= portal->pBounding.x1 &&
          y <= portal->pBounding.y2 &&
          y >= portal->pBounding.y1 )
      {
        //v46 = 0;
        for (uint j = 0; j < portal->uNumVertices; ++j)
        {
            //v24 = v46;
            //v25 = 2 * v46;
          word_721460[2 * j] =     portal->pXInterceptDisplacements[j] + pIndoor->pVertices[portal->pVertexIDs[j]].x;
          word_721460[2 * j + 1] = portal->pXInterceptDisplacements[j + 1] + pIndoor->pVertices[portal->pVertexIDs[j + 1]].x;
          word_721390[2 * j] =     portal->pYInterceptDisplacements[j] + pIndoor->pVertices[portal->pVertexIDs[j]].y;
          word_721390[2 * j + 1] = portal->pYInterceptDisplacements[j + 1] + pIndoor->pVertices[portal->pVertexIDs[j + 1]].y;
          //}
          //while ( v46 < v23->uNumVertices );
          //v5 = v43;
        }

        //v26 = 2 * v23->uNumVertices;
        word_721460[2 * portal->uNumVertices] = word_721460[0];
        word_721390[2 * portal->uNumVertices] = word_721390[0];
        v54 = 0;
        v51 = 0;
        v49 = word_721390[0] >= y;
        if ( portal->uNumVertices > 0 )
        {
          do
          {
            if ( v54 >= 2 )
              break;
            v27 = v51;
            v47 = word_721390[v51 + 1] >= y;
            if ( v49 != v47 )
            {
              if ( word_721460[v27 + 1] >= x )
                v28 = 0;
              else
                v28 = 2;
              v29 = v28 | word_721460[v27] < x;
              if ( v29 != 3 )
              {
                if ( !v29
                  || (v30 = word_721390[v27],
                      v31 = word_721390[v51 + 1] - v30,
                      v32 = y - v30,
                      LODWORD(v33) = v32 << 16,
                      HIDWORD(v33) = v32 >> 16,
                      //v7 = pIndoor->pVertices,
                      (signed int)(((unsigned __int64)(((signed int)word_721460[v27 + 1] - (signed int)word_721460[v27])
                                                     * v33
                                                     / v31) >> 16)
                                 + word_721460[v27]) >= x) )
                  ++v54;
              }
            }
            ++v51;
            v49 = v47;
          }
          while ( v51 < 2 * portal->uNumVertices );

          if ( v54 == 1 )
          {
            if ( v55 >= 50 )
              break;
            v34 = v55++;
            dword_7212C8[v34] = -29000;
            dword_721200[v34] = pSector->pPortals[i];
          }
        }
      }
    }
  }

  v35 = 1;
  if ( v55 == 1 )
  {
    *pFaceID = dword_721200[0];
    return dword_7212C8[0];
  }
  if ( !v55 )
    return -30000;
  *pFaceID = dword_721200[0];
  result = dword_7212C8[0];
  if ( v55 > 1 )
  {
    v37 = z + 5;
    while ( 1 )
    {
      v38 = dword_7212C8[v35];
      if ( result <= v37 )
        break;
      if ( v38 < result )
        goto LABEL_67;
LABEL_68:
      ++v35;
      if ( v35 >= v55 )
        return result;
    }
    if ( v38 <= result || v38 > v37 )
      goto LABEL_68;
LABEL_67:
    result = dword_7212C8[v35];
    *pFaceID = dword_721200[v35];
    goto LABEL_68;
  }
  return result;
}

//----- (0046D49E) --------------------------------------------------------
int __fastcall sub_46D49E_prolly_get_world_y_under_party(int a1, signed int a2, int a3, int a4, int *a5, int *a6, int a7)
{
  signed int v7; // edi@1
  int v8; // ebx@1
  int v9; // eax@1
  BSPModel *v10; // esi@4
  ODMFace *v11; // ecx@11
  unsigned __int8 v12; // al@11
  char *v13; // eax@19
  int v14; // edx@20
  int v15; // eax@22
  int v16; // edx@22
  int v17; // edi@24
  signed int v18; // edx@26
  int v19; // eax@28
  int v20; // edx@30
  int v21; // ST1C_4@30
  signed int v22; // edx@30
  signed __int64 v23; // qtt@30
  int v24; // eax@36
  signed int v25; // ecx@38
  int result; // eax@42
  signed int v27; // ecx@43
  int v28; // edi@44
  signed int v29; // edx@44
  int v30; // esi@45
  int v31; // eax@45
  ODMFace *v32; // eax@57
  int v33; // ecx@59
  int v34; // [sp+Ch] [bp-34h]@8
  int v35; // [sp+10h] [bp-30h]@22
  int v36; // [sp+14h] [bp-2Ch]@24
  int v37; // [sp+18h] [bp-28h]@22
  int v38; // [sp+1Ch] [bp-24h]@2
  int v39; // [sp+20h] [bp-20h]@9
  int v40; // [sp+24h] [bp-1Ch]@1
  signed int v41; // [sp+28h] [bp-18h]@1
  int v42; // [sp+2Ch] [bp-14h]@8
  bool v43; // [sp+30h] [bp-10h]@22
  bool v44; // [sp+34h] [bp-Ch]@24
  signed int v45; // [sp+38h] [bp-8h]@1
  signed int v46; // [sp+3Ch] [bp-4h]@1
  signed int v47; // [sp+58h] [bp+18h]@18
  signed int v48; // [sp+58h] [bp+18h]@22
  signed int v49; // [sp+58h] [bp+18h]@43

  v7 = a2;
  v8 = a1;
  v45 = a2;
  v40 = a1;
  v46 = 1;
  v9 = GetTerrainHeightsAroundParty2(a1, a2, a5, a7);
  dword_721160[0] = -1;
  dword_721110[0] = -1;
  dword_7211B0[0] = v9;
  v41 = 0;
  if ( (signed int)pOutdoor->uNumBModels <= 0 )
    goto LABEL_63;
  v38 = 0;
  while ( 1 )
  {
    v10 = &pOutdoor->pBModels[v38];
    if ( v8 <= pOutdoor->pBModels[v38].sMaxX )
    {
      if ( v8 >= v10->sMinX )
      {
        if ( v7 <= v10->sMaxY )
        {
          if ( v7 >= v10->sMinY )
          {
            v42 = 0;
            v34 = v10->uNumFaces;
            if ( (signed int)v10->uNumFaces > 0 )
            {
              v39 = 0;
              while ( 1 )
              {
                v11 = &v10->pFaces[v39];
                v12 = v11->uPolygonType;
                if ( (v12 == 3 || v12 == 4)
                  && !(v11->uAttributes & 0x20000000)
                  && v8 <= v11->pBoundingBox.x2
                  && v8 >= v11->pBoundingBox.x1
                  && v7 <= v11->pBoundingBox.y2
                  && v7 >= v11->pBoundingBox.y1 )
                {
                  v47 = 0;
                  if ( v11->uNumVertices )
                  {
                    v13 = (char *)v11->pXInterceptDisplacements;
                    do
                    {
                      v14 = 2 * v47;
                      word_721040[2 * v47] = *(short *)v13 + LOWORD(v10->pVertices.pVertices[*((short *)v13 - 60)].x);
                      word_720F70[2 * v47] = *((short *)v13 + 20)
                                           + LOWORD(v10->pVertices.pVertices[*((short *)v13 - 60)].y);
                      word_721040[2 * v47++ + 1] = *(short *)v13
                                                 + LOWORD(v10->pVertices.pVertices[*((short *)v13 - 59)].x);
                      word_720F70[v14 + 1] = *((short *)v13 + 20)
                                           + LOWORD(v10->pVertices.pVertices[*((short *)v13 - 59)].y);
                      v13 += 2;
                    }
                    while ( v47 < v11->uNumVertices );
                    v8 = v40;
                  }
                  v15 = 2 * v11->uNumVertices;
                  word_721040[2 * v11->uNumVertices] = word_721040[0];
                  word_720F70[v15] = word_720F70[0];
                  v35 = v15;
                  v16 = 0;
                  v43 = word_720F70[0] >= v45;
                  v48 = 0;
                  v37 = 0;
                  if ( v15 > 0 )
                  {
                    do
                    {
                      if ( v48 >= 2 )
                        break;
                      v17 = v16;
                      v8 = v40;
                      v36 = word_720F70[v16 + 1];
                      v44 = word_720F70[v16 + 1] >= v45;
                      if ( v43 != v44 )
                      {
                        v18 = word_721040[v17 + 1] >= v40 ? 0 : 2;
                        v19 = v18 | word_721040[v17] < v40;
                        if ( v19 != 3 )
                        {
                          if ( !v19
                            || (v20 = word_720F70[v17],
                                v21 = v36 - v20,
                                v22 = v45 - v20,
                                LODWORD(v23) = v22 << 16,
                                HIDWORD(v23) = v22 >> 16,
                                (signed int)(((unsigned __int64)(((signed int)word_721040[v17 + 1]
                                                                - (signed int)word_721040[v17])
                                                               * v23
                                                               / v21) >> 16)
                                           + word_721040[v17]) >= v40) )
                            ++v48;
                        }
                      }
                      v16 = v37 + 1;
                      v43 = v44;
                      ++v37;
                    }
                    while ( v37 < v35 );
                    if ( v48 == 1 )
                    {
                      if ( v46 >= 20 )
                        break;
                      if ( v11->uPolygonType == 3 )
                        v24 = v10->pVertices.pVertices[v11->pVertexIDs[0]].z;
                      else
                        v24 = ((unsigned __int64)(v11->zCalc1 * (signed __int64)v8) >> 16)
                            + ((unsigned __int64)(v11->zCalc2 * (signed __int64)v45) >> 16)
                            + HIWORD(v11->zCalc3);
                      v25 = v46++;
                      dword_7211B0[v25] = v24;
                      dword_721160[v25] = v41;
                      dword_721110[v25] = v42;
                    }
                  }
                }
                ++v42;
                ++v39;
                if ( v42 >= v34 )
                  break;
                v7 = v45;
              }
            }
          }
        }
      }
    }
    ++v41;
    ++v38;
    if ( v41 >= (signed int)pOutdoor->uNumBModels )
      break;
    v7 = v45;
  }
  if ( v46 == 1 )
  {
LABEL_63:
    *a6 = 0;
    return dword_7211B0[0];
  }
  v27 = 0;
  v49 = 1;
  if ( v46 <= 1 )
  {
LABEL_55:
    *a6 = 0;
    goto LABEL_56;
  }
  v28 = 0;
  v29 = 1;
  do
  {
    v30 = dword_7211B0[v29];
    v31 = *(int *)((char *)dword_7211B0 + v28);
    if ( v30 == v31 )
      goto LABEL_51;
    if ( v31 > a3 + 5 )
    {
      if ( v30 >= v31 )
        goto LABEL_52;
LABEL_51:
      v27 = v49;
      v28 = v29 * 4;
      goto LABEL_52;
    }
    if ( v30 > v31 && v30 <= a3 + 5 )
      goto LABEL_51;
LABEL_52:
    ++v49;
    ++v29;
  }
  while ( v49 < v46 );
  if ( !v27 )
    goto LABEL_55;
  *a6 = dword_721110[v27] | (dword_721160[v27] << 6);
LABEL_56:
  if ( v27 )
  {
    v32 = &pOutdoor->pBModels[dword_721160[v27]].pFaces[dword_721110[v27]];
    *a5 = 0;
    if ( v32->uAttributes & 0x10 )
      *a5 = 1;
  }
  v33 = dword_7211B0[v27];
  result = dword_7211B0[0];
  if ( v33 >= dword_7211B0[0] )
    result = v33;
  return result;
}

//----- (0046D8E3) --------------------------------------------------------
int __fastcall sub_46D8E3(int a1, signed int a2, int a3, int a4)
{
  int v4; // ebx@1
  unsigned int v5; // ecx@1
  BSPModel *v6; // edi@3
  ODMFace *v7; // esi@10
  unsigned __int8 v8; // al@10
  unsigned __int16 *v9; // eax@18
  int v10; // edx@19
  int v11; // ecx@21
  int v12; // ecx@23
  signed int v13; // eax@25
  int v14; // edx@27
  int v15; // edx@29
  int v16; // ST18_4@29
  signed int v17; // edx@29
  signed __int64 v18; // qtt@29
  int v19; // eax@35
  signed int v20; // ecx@37
  signed int v22; // ebx@42
  unsigned int v23; // esi@43
  int v24; // edx@44
  int v25; // eax@44
  int v26; // [sp+Ch] [bp-38h]@7
  int v27; // [sp+10h] [bp-34h]@21
  int v28; // [sp+18h] [bp-2Ch]@21
  int v29; // [sp+1Ch] [bp-28h]@2
  unsigned int v30; // [sp+20h] [bp-24h]@8
  signed int v31; // [sp+24h] [bp-20h]@1
  signed int v32; // [sp+28h] [bp-1Ch]@1
  int v33; // [sp+2Ch] [bp-18h]@7
  bool v34; // [sp+30h] [bp-14h]@21
  bool v35; // [sp+34h] [bp-10h]@23
  signed int v36; // [sp+38h] [bp-Ch]@17
  signed int v37; // [sp+38h] [bp-Ch]@21
  signed int v38; // [sp+38h] [bp-Ch]@42
  signed int v39; // [sp+3Ch] [bp-8h]@1
  signed int v40; // [sp+40h] [bp-4h]@1

  dword_720ED0[0] = -1;
  dword_720E80[0] = -1;
  v4 = a1;
  v5 = 0;
  v40 = a2;
  v31 = v4;
  v39 = 1;
  dword_720F20[0] = 10000;
  v32 = 0;
  if ( (signed int)pOutdoor->uNumBModels > 0 )
  {
    v29 = 0;
    do
    {
      v6 = &pOutdoor->pBModels[v29];
      if ( v4 <= pOutdoor->pBModels[v29].sMaxX )
      {
        if ( v4 >= v6->sMinX )
        {
          if ( v40 <= v6->sMaxY )
          {
            if ( v40 >= v6->sMinY )
            {
              v33 = v5;
              v26 = v6->uNumFaces;
              if ( (signed int)v6->uNumFaces > (signed int)v5 )
              {
                v30 = v5;
                while ( 1 )
                {
                  v7 = (ODMFace *)((char *)v6->pFaces + v30);
                  v8 = v7->uPolygonType;
                  if ( (v8 == 5 || v8 == 6)
                    && !(BYTE3(v7->uAttributes) & 0x20)
                    && v4 <= v7->pBoundingBox.x2
                    && v4 >= v7->pBoundingBox.x1
                    && v40 <= v7->pBoundingBox.y2
                    && v40 >= v7->pBoundingBox.y1 )
                  {
                    v36 = v5;
                    if ( v7->uNumVertices )
                    {
                      v9 = v7->pXInterceptDisplacements;
                      do
                      {
                        v10 = 2 * v36;
                        word_720DB0_xs[2 * v36] = *v9 + LOWORD(v6->pVertices.pVertices[*(v9 - 60)].x);
                        word_720CE0_ys[2 * v36] = v9[20] + LOWORD(v6->pVertices.pVertices[*(v9 - 60)].y);
                        word_720DB0_xs[2 * v36++ + 1] = *v9 + LOWORD(v6->pVertices.pVertices[*(v9 - 59)].x);
                        word_720CE0_ys[v10 + 1] = v9[20] + LOWORD(v6->pVertices.pVertices[*(v9 - 59)].y);
                        ++v9;
                      }
                      while ( v36 < v7->uNumVertices );
                      v4 = v31;
                    }
                    v27 = 2 * v7->uNumVertices;
                    word_720DB0_xs[2 * v7->uNumVertices] = word_720DB0_xs[0];
                    word_720CE0_ys[v27] = word_720CE0_ys[0];
                    v11 = 0;
                    v34 = word_720CE0_ys[0] >= v40;
                    v37 = 0;
                    v28 = 0;
                    if ( v27 > 0 )
                    {
                      do
                      {
                        if ( v37 >= 2 )
                          break;
                        v12 = v11;
                        v4 = v31;
                        v35 = word_720CE0_ys[v12 + 1] >= v40;
                        if ( v34 != v35 )
                        {
                          v13 = word_720DB0_xs[v12 + 1] >= v31 ? 0 : 2;
                          v14 = v13 | word_720DB0_xs[v12] < v31;
                          if ( v14 != 3 )
                          {
                            if ( !v14
                              || (v15 = word_720CE0_ys[v12],
                                  v16 = word_720CE0_ys[v12 + 1] - v15,
                                  v17 = v40 - v15,
                                  LODWORD(v18) = v17 << 16,
                                  HIDWORD(v18) = v17 >> 16,
                                  (signed int)(((unsigned __int64)(((signed int)word_720DB0_xs[v12 + 1]
                                                                  - (signed int)word_720DB0_xs[v12])
                                                                 * v18
                                                                 / v16) >> 16)
                                             + word_720DB0_xs[v12]) >= v31) )
                              ++v37;
                          }
                        }
                        v11 = v28 + 1;
                        v34 = v35;
                        ++v28;
                      }
                      while ( v28 < v27 );
                      if ( v37 == 1 )
                      {
                        if ( v39 >= 20 )
                          break;
                        if ( v7->uPolygonType == 5 )
                          v19 = v6->pVertices.pVertices[v7->pVertexIDs[0]].z;
                        else
                          v19 = ((unsigned __int64)(v7->zCalc1 * (signed __int64)v4) >> 16)
                              + ((unsigned __int64)(v7->zCalc2 * (signed __int64)v40) >> 16)
                              + HIWORD(v7->zCalc3);
                        v20 = v39++;
                        dword_720F20[v20] = v19;
                        dword_720ED0[v20] = v32;
                        dword_720E80[v20] = v33;
                      }
                    }
                  }
                  ++v33;
                  v30 += 308;
                  if ( v33 >= v26 )
                    break;
                  v5 = 0;
                }
              }
            }
          }
        }
      }
      ++v32;
      ++v29;
      v5 = 0;
    }
    while ( v32 < (signed int)pOutdoor->uNumBModels );
    if ( !v39 )
    {
      *(int *)a4 = 0;
      return dword_720F20[0];
    }
  }
  v22 = 0;
  v38 = v5;
  if ( v39 <= (signed int)v5 )
    goto LABEL_54;
  v23 = 0;
  do
  {
    v24 = dword_720F20[v5 / 4];
    v25 = *(int *)((char *)dword_720F20 + v23);
    if ( v24 == v25 )
      goto LABEL_50;
    if ( v25 > a3 + 15 )
    {
      if ( v24 >= v25 )
        goto LABEL_51;
LABEL_50:
      v22 = v38;
      v23 = v5;
      goto LABEL_51;
    }
    if ( v24 > v25 && v24 <= a3 + 15 )
      goto LABEL_50;
LABEL_51:
    ++v38;
    v5 += 4;
  }
  while ( v38 < v39 );
  if ( v22 )
  {
    *(int *)a4 = dword_720E80[v22] | (dword_720ED0[v22] << 6);
    return dword_720F20[v22];
  }
LABEL_54:
  *(int *)a4 = 0;
  return dword_720F20[v22];
}


//not sure if right- or left-handed coordinate space assumed, so this could be normal of inverse normal
// for a right-handed system, that would be an inverse normal
//----- (0046DCC8) --------------------------------------------------------
void ODM_GetTerrainNormalAt(int pos_x, int pos_z, Vec3_int_ *out)
{
  auto grid_x = WorldPosToGridCellX(pos_x);
  auto grid_z = WorldPosToGridCellZ(pos_z) - 1;

  auto grid_pos_x1 = GridCellToWorldPosX(grid_x);
  auto grid_pos_x2 = GridCellToWorldPosX(grid_x + 1);
  auto grid_pos_z1 = GridCellToWorldPosZ(grid_z);
  auto grid_pos_z2 = GridCellToWorldPosZ(grid_z + 1);

  auto x1z1_y = pOutdoor->DoGetHeightOnTerrain(grid_x, grid_z);
  auto x2z1_y = pOutdoor->DoGetHeightOnTerrain(grid_x + 1, grid_z);
  auto x2z2_y = pOutdoor->DoGetHeightOnTerrain(grid_x + 1, grid_z + 1);
  auto x1z2_y = pOutdoor->DoGetHeightOnTerrain(grid_x, grid_z + 1);

  float side1_dx, side1_dy, side1_dz,
        side2_dx, side2_dy, side2_dz;

  auto dx = abs(pos_x - grid_pos_x1),
       dz = abs(grid_pos_z1 - pos_z);
  if (dz >= dx)
  {
    side1_dy = (double)(x1z1_y - x1z2_y);
    side2_dy = (double)(x2z2_y - x1z2_y);
    side2_dx = (double)(grid_pos_x2 - grid_pos_x1);
    side1_dx = (double)(grid_pos_x1 - grid_pos_x1);
    side2_dz = (double)(grid_pos_z2 - grid_pos_z2);  // bug?  z2 - z2
    side1_dz = (double)(grid_pos_z2 - grid_pos_z2);  //       z1 - z2
    Log::Warning(L"%S %S %u\n", __FILE__, __FUNCTION__, __LINE__);
    /*       |\
       side1 |  \
             |____\
             side 2      */
  }
  else
  {
    side1_dy = (double)(x2z2_y - x2z1_y);
    side2_dy = (double)(x1z1_y - x2z1_y);
    side2_dx = (double)(grid_pos_x1 - grid_pos_x2);
    side1_dx = (double)(grid_pos_x2 - grid_pos_x2);
    side2_dz = (double)(grid_pos_z1 - grid_pos_z1);
    side1_dz = (double)(grid_pos_z2 - grid_pos_z1);

    /*   side 2
         _____
         \    |
           \  | side 1
             \|       */
  }
  
  float nx = side1_dy * side2_dz - side1_dz * side2_dy;
  float ny = side1_dx * side2_dy - side1_dy * side2_dx;
  float nz = side1_dz * side2_dx - side1_dx * side2_dz;

  float mag = sqrt(nx * nx + ny * ny + nz * nz);
  if (fabsf(mag) < 1e-6f)
  {
    out->y = 0;
    out->x = 0;
    out->z = 65536;
  }
  else
  {
    float invmag = 1.0 / mag;
    out->x = invmag * nx * 65536.0;
    out->y = invmag * ny * 65536.0;
    out->z = invmag * nz * 65536.0;
  }
}


//----- (0046DEF2) --------------------------------------------------------
unsigned int __fastcall sub_46DEF2(signed int a2, unsigned int uLayingItemID)
{
  unsigned int result; // eax@1

  result = uLayingItemID;
  if ( pObjectList->pObjects[pLayingItems[uLayingItemID].uObjectDescID].uFlags & 0x10 )
    result = _46BFFA_check_object_intercept(uLayingItemID, a2);
  return result;
}

//----- (0046DF1A) --------------------------------------------------------
signed int __fastcall _46DF1A_collide_against_actor(int a1, int a2)
{
  Actor *v2; // edi@1
  unsigned __int16 v3; // ax@1
  int v4; // esi@6
  int v5; // ecx@8
  int v6; // eax@10
  int v7; // edx@12
  int v8; // ecx@14
  int v9; // eax@14
  int v10; // ebx@14
  int v11; // esi@14
  int v12; // ebx@15
  int v13; // ebx@17
  unsigned int v14; // eax@20
  signed int result; // eax@21
  int v16; // [sp+Ch] [bp-10h]@1
  int v17; // [sp+10h] [bp-Ch]@14
  int v18; // [sp+14h] [bp-8h]@14
  int v19; // [sp+18h] [bp-4h]@14

  v16 = a1;
  v2 = &pActors[a1];
  v3 = v2->uAIState;
  if ( v3 == 11 || v3 == 4 || v3 == 19 || v3 == 5 || v3 == 17 )
    goto LABEL_25;
  v4 = v2->uActorRadius;
  if ( a2 )
    v4 = a2;
  v5 = v2->vPosition.x;
  if ( stru_721530.sMaxX > v5 + v4
    || stru_721530.sMinX < v5 - v4
    || (v6 = v2->vPosition.y, stru_721530.sMaxY > v6 + v4)
    || stru_721530.sMinY < v6 - v4
    || (v7 = v2->vPosition.z, stru_721530.sMaxZ > v7 + v2->uActorHeight)
    || stru_721530.sMinZ < v7
    || (v8 = v5 - stru_721530.normal.x,
        v9 = v6 - stru_721530.normal.y,
        v10 = stru_721530.prolly_normal_d + v4,
        v17 = stru_721530.prolly_normal_d + v4,
        v11 = (v8 * stru_721530.field_58.y - v9 * stru_721530.field_58.x) >> 16,
        v18 = v8,
        v19 = v9,
        abs((v8 * stru_721530.field_58.y - v9 * stru_721530.field_58.x) >> 16) > v10)
    || (v12 = (v18 * stru_721530.field_58.x + v19 * stru_721530.field_58.y) >> 16, v12 <= 0)
    || (signed int)(((unsigned __int64)(stru_721530.field_58.z * (signed __int64)v12) >> 16) + stru_721530.normal.z) < v2->vPosition.z )
  {
LABEL_25:
    result = 0;
  }
  else
  {
    v13 = v12 - integer_sqrt(v17 * v17 - v11 * v11);
    if ( v13 < 0 )
      v13 = 0;
    if ( v13 < stru_721530.field_7C )
    {
      stru_721530.field_7C = v13;
      v14 = 8 * v16;
      LOBYTE(v14) = 8 * v16 | 3;
      stru_721530.uFaceID = v14;
    }
    result = 1;
  }
  return result;
}
// 46DF1A: using guessed type int __fastcall 46DF1A_collide_against_actor(int, int);

//----- (0046E0B2) --------------------------------------------------------
void __cdecl _46E0B2_collide_against_decorations()
{
  BLVSector *v0; // ebp@1
  LevelDecoration *v1; // edi@2
  DecorationDesc *v2; // esi@3
  int v3; // edx@4
  int v4; // eax@4
  int v5; // ecx@6
  int v6; // ebx@8
  int v7; // esi@8
  int v8; // ebx@10
  int v9; // esi@11
  int v10; // edi@12
  int v11; // eax@12
  int v12; // esi@14
  unsigned int v13; // eax@17
  signed int i; // [sp+4h] [bp-14h]@1
  int v15; // [sp+8h] [bp-10h]@10
  int v16; // [sp+Ch] [bp-Ch]@10
  int v17; // [sp+10h] [bp-8h]@10
  int v18; // [sp+14h] [bp-4h]@8

  v0 = &pIndoor->pSectors[stru_721530.uSectorID];
  for ( i = 0; i < v0->uNumDecorations; ++i )
  {
    v1 = &pLevelDecorations[v0->pDecorationIDs[i]];
    if ( !(v1->field_2 & 0x20) )
    {
      v2 = &pDecorationList->pDecorations[v1->uDecorationDescID];
      if (!v2->CanMoveThrough())
      {
        v3 = v2->uRadius;
        v4 = v1->vPosition.x;
        if ( stru_721530.sMaxX <= v4 + v3 )
        {
          if ( stru_721530.sMinX >= v4 - v3 )
          {
            v5 = v1->vPosition.y;
            if ( stru_721530.sMaxY <= v5 + v3 )
            {
              if ( stru_721530.sMinY >= v5 - v3 )
              {
                v6 = v2->uDecorationHeight;
                v7 = v1->vPosition.z;
                v18 = v6;
                if ( stru_721530.sMaxZ <= v7 + v6 )
                {
                  if ( stru_721530.sMinZ >= v7 )
                  {
                    v16 = v4 - stru_721530.normal.x;
                    v15 = v5 - stru_721530.normal.y;
                    v8 = stru_721530.prolly_normal_d + v3;
                    v17 = ((v4 - stru_721530.normal.x) * stru_721530.field_58.y
                         - (v5 - stru_721530.normal.y) * stru_721530.field_58.x) >> 16;
                    if ( abs(v17) <= stru_721530.prolly_normal_d + v3 )
                    {
                      v9 = (v16 * stru_721530.field_58.x + v15 * stru_721530.field_58.y) >> 16;
                      if ( v9 > 0 )
                      {
                        v10 = v1->vPosition.z;
                        v11 = stru_721530.normal.z
                            + ((unsigned __int64)(stru_721530.field_58.z * (signed __int64)v9) >> 16);
                        if ( v11 >= v10 )
                        {
                          if ( v11 <= v18 + v10 )
                          {
                            v12 = v9 - integer_sqrt(v8 * v8 - v17 * v17);
                            if ( v12 < 0 )
                              v12 = 0;
                            if ( v12 < stru_721530.field_7C )
                            {
                              stru_721530.field_7C = v12;
                              v13 = 8 * v0->pDecorationIDs[i];
                              LOBYTE(v13) = v13 | 5;
                              stru_721530.uFaceID = v13;
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

//----- (0046E26D) --------------------------------------------------------
void __fastcall _46E26D_collide_against_sprites(signed int a1, signed int a2)
{
  int v2; // edx@5
  unsigned __int16 *v3; // eax@5
  unsigned __int16 v4; // ax@6
  LevelDecoration *v5; // edi@7
  DecorationDesc *v6; // esi@8
  int v7; // edx@9
  int v8; // eax@9
  int v9; // ecx@11
  int v10; // ebx@13
  int v11; // esi@13
  int v12; // ebp@15
  int v13; // ebx@15
  int v14; // esi@16
  int v15; // edi@17
  int v16; // eax@17
  int v17; // esi@19
  char v18; // zf@23
  int v19; // [sp+0h] [bp-10h]@15
  unsigned __int16 *v20; // [sp+4h] [bp-Ch]@5
  int v21; // [sp+8h] [bp-8h]@15
  int v22; // [sp+Ch] [bp-4h]@13

  if ( a1 >= 0 )
  {
    if ( a1 <= 127 )
    {
      if ( a2 >= 0 )
      {
        if ( a2 <= 127 )
        {
          v2 = a1 + (a2 << 7);
          v3 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]];
          v20 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]];
          if ( v3 )
          {
            do
            {
              v4 = *v3;
              if ( (v4 & 7) == OBJECT_Decoration)
              {
                v5 = &pLevelDecorations[(signed __int16)v4 >> 3];
                if ( !(v5->field_2 & 0x20) )
                {
                  v6 = &pDecorationList->pDecorations[v5->uDecorationDescID];
                  if (!v6->CanMoveThrough())
                  {
                    v7 = v6->uRadius;
                    v8 = v5->vPosition.x;
                    if ( stru_721530.sMaxX <= v8 + v7 )
                    {
                      if ( stru_721530.sMinX >= v8 - v7 )
                      {
                        v9 = v5->vPosition.y;
                        if ( stru_721530.sMaxY <= v9 + v7 )
                        {
                          if ( stru_721530.sMinY >= v9 - v7 )
                          {
                            v10 = v6->uDecorationHeight;
                            v11 = v5->vPosition.z;
                            v22 = v10;
                            if ( stru_721530.sMaxZ <= v11 + v10 )
                            {
                              if ( stru_721530.sMinZ >= v11 )
                              {
                                v12 = v8 - stru_721530.normal.x;
                                v19 = v9 - stru_721530.normal.y;
                                v13 = stru_721530.prolly_normal_d + v7;
                                v21 = ((v8 - stru_721530.normal.x) * stru_721530.field_58.y
                                     - (v9 - stru_721530.normal.y) * stru_721530.field_58.x) >> 16;
                                if ( abs(v21) <= stru_721530.prolly_normal_d + v7 )
                                {
                                  v14 = (v12 * stru_721530.field_58.x + v19 * stru_721530.field_58.y) >> 16;
                                  if ( v14 > 0 )
                                  {
                                    v15 = v5->vPosition.z;
                                    v16 = stru_721530.normal.z
                                        + ((unsigned __int64)(stru_721530.field_58.z * (signed __int64)v14) >> 16);
                                    if ( v16 >= v15 )
                                    {
                                      if ( v16 <= v22 + v15 )
                                      {
                                        v17 = v14 - integer_sqrt(v13 * v13 - v21 * v21);
                                        if ( v17 < 0 )
                                          v17 = 0;
                                        if ( v17 < stru_721530.field_7C )
                                        {
                                          stru_721530.field_7C = v17;
                                          stru_721530.uFaceID = (signed __int16)*v20;
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
              v3 = v20 + 1;
              v18 = *v20 == 0;
              ++v20;
            }
            while ( !v18 );
          }
        }
      }
    }
  }
}

//----- (00486F92) --------------------------------------------------------
void __cdecl sr_sub_486F92_MessWithEdgesAndSpans()
{
  Span *v0; // ebx@1
  int v1; // eax@2
  Edge *v2; // ecx@3
  Edge *v3; // edx@3
  Edge *v4; // esi@6
  Edge *v5; // eax@7
  Edge *v6; // ecx@8
  Surf *v7; // esi@11
  double v8; // st7@13
  Surf *v9; // edi@13
  double v10; // st6@13
  double v11; // st7@14
  signed __int64 v12; // qax@14
  stru148 *v13; // eax@15
  Span *v14; // ecx@17
  double v15; // st7@28
  signed __int64 v16; // qax@28
  stru148 *v17; // eax@29
  Span *v18; // ecx@31
  Edge *i; // eax@40
  Edge *v20; // ecx@43
  Edge *v21; // esi@44
  double v22; // st7@45
  Edge *v23; // edx@48
  unsigned int v24; // [sp+10h] [bp-10h]@2
  float v25; // [sp+14h] [bp-Ch]@3
  Edge *v26; // [sp+18h] [bp-8h]@8
  unsigned int v27; // [sp+1Ch] [bp-4h]@1

  v0 = pSpans;
  stru_80C9D8.pSurf = &stru_80C980;
  stru_80C9D8.field_0 = (double)(signed int)pViewport->uViewportX;
  stru_80C9A4.pSurf = &stru_80C980;
  stru_80C980.pPrev = &stru_80C980;
  stru_80C980.pNext = &stru_80C980;
  stru_80C9A4.field_0 = (double)(signed int)pViewport->uViewportZ;
  stru_80C980.field_8 = 0.0;
  stru_80C980.field_4 = 0.0;
  stru_80C9D8.pNext = &stru_80C9A4;
  stru_80C9D8.pPrev = 0;
  stru_80C9D8.field_8 = 1;
  stru_80C9A4.pNext = 0;
  stru_80C9A4.pPrev = &stru_80C9D8;
  stru_80C9A4.field_8 = 0;
  LODWORD(stru_80C980.field_0) = 0xC97423F0u;
  v27 = pViewport->uViewportY;
  if ( (signed int)pViewport->uViewportY > (signed int)pViewport->uViewportW )
  {
LABEL_51:
    v0->field_8 = -1;
  }
  else
  {
    v1 = 52 * pViewport->uViewportY;
    v24 = 52 * pViewport->uViewportY;
    while ( 1 )
    {
      v2 = *(Edge **)((char *)&pNewEdges->pNext + v1);
      v3 = &stru_80C9D8;
      v25 = (double)(signed int)v27;
      if ( v2 != &defaultEdge )
      {
        do
        {
          while ( 1 )
          {
            v4 = v3->pNext;
            if ( v2->field_0 <= (double)v4->field_0 )
              break;
            v3 = v3->pNext;
          }
          v5 = v2->pNext;
          v2->pNext = v4;
          v2->pPrev = v3;
          v3->pNext->pPrev = v2;
          v3->pNext = v2;
          v3 = v2;
          v2 = v5;
        }
        while ( v5 != &defaultEdge );
      }
      v6 = stru_80C9D8.pNext;
      stru_80C980.field_20 = 0;
      stru_80C980.field_22 = 1;
      v26 = stru_80C9D8.pNext;
      if ( stru_80C9D8.pNext )
      {
        while ( 1 )
        {
          v7 = v6->pSurf;
          if ( v6->field_8 )
          {
            ++v7->field_22;
            if ( v7->field_22 == 1 )
            {
              v8 = v6->field_0 + 2.0;
              v9 = stru_80C980.pNext;
              v10 = (v8 - v7->field_C) * v7->field_4 + (v25 - v7->field_10) * v7->field_8 + v7->field_0;
              if ( v10 <= (v8 - stru_80C980.pNext->field_C) * stru_80C980.pNext->field_4
                        + (v25 - stru_80C980.pNext->field_10) * stru_80C980.pNext->field_8
                        + stru_80C980.pNext->field_0 )
              {
                do
                  v9 = v9->pNext;
                while ( v10 <= (v8 - v9->field_C) * v9->field_4 + (v25 - v9->field_10) * v9->field_8 + v9->field_0 );
                v7->pNext = v9;
                v7->pPrev = v9->pPrev;
                v9->pPrev->pNext = v7;
                v9->pPrev = v7;
              }
              else
              {
                v11 = v6->field_0 + 0.5;
                v12 = (signed __int64)(v11 - (double)stru_80C980.pNext->field_20);
                v0->field_C = v12;
                if ( (signed __int16)v12 > 0 )
                {
                  v0->field_A = v27;
                  v0->field_8 = v9->field_20;
                  v13 = v9->pParent;
                  v0->pParent = v13;
                  if ( v13 )
                  {
                    if ( v13->prolly_head )
                    {
                      v14 = v13->prolly_tail;
                      if ( !v14 )
                        return;
                      v14->pNext = v0;
                    }
                    else
                    {
                      v13->prolly_head = v0;
                    }
                    v13->prolly_tail = v0;
                  }
                  if ( (signed int)pOutdoorCamera->uNumSpans >= 12499 )
                    return;
                  ++v0;
                  ++pOutdoorCamera->uNumSpans;
                }
                v6 = v26;
                v7->field_20 = (signed __int64)v11;
                v7->pNext = v9;
                v9->pPrev = v7;
                stru_80C980.pNext = v7;
                v7->pPrev = &stru_80C980;
              }
            }
          }
          else
          {
            --v7->field_22;
            if ( !v7->field_22 )
            {
              if ( stru_80C980.pNext == v7 )
              {
                v15 = v6->field_0 + 0.5;
                v16 = (signed __int64)(v15 - (double)v7->field_20);
                v0->field_C = v16;
                if ( (signed __int16)v16 > 0 )
                {
                  v0->field_A = v27;
                  v0->field_8 = v7->field_20;
                  v17 = v7->pParent;
                  v0->pParent = v17;
                  if ( v17 )
                  {
                    if ( v17->prolly_head )
                    {
                      v18 = v17->prolly_tail;
                      if ( !v18 )
                        return;
                      v18->pNext = v0;
                    }
                    else
                    {
                      v17->prolly_head = v0;
                    }
                    v17->prolly_tail = v0;
                  }
                  if ( (signed int)pOutdoorCamera->uNumSpans >= 12499 )
                    return;
                  ++v0;
                  ++pOutdoorCamera->uNumSpans;
                }
                v7->pNext->field_20 = (signed __int64)v15;
                v6 = v26;
              }
              v7->pNext->pPrev = v7->pPrev;
              v7->pPrev->pNext = v7->pNext;
            }
          }
          v26 = v6->pNext;
          if ( !v26 )
            break;
          v6 = v6->pNext;
        }
      }
      for ( i = ptr_80CA10[v27]; i; i = i->ptr_18 )
      {
        i->pPrev->pNext = i->pNext;
        i->pNext->pPrev = i->pPrev;
      }
      v20 = stru_80C9D8.pNext;
      if ( stru_80C9D8.pNext != &stru_80C9A4 )
        break;
LABEL_50:
      ++v27;
      v1 = v24 + 52;
      v24 += 52;
      if ( (signed int)v27 > (signed int)pViewport->uViewportW )
        goto LABEL_51;
    }
    while ( 1 )
    {
      v21 = v20->pNext;
      if ( !v21 )
        break;
      v22 = v20->field_4 + v20->field_0;
      v20->field_0 = v22;
      if ( v22 < stru_80C9D8.field_0 )
        v20->field_0 = stru_80C9D8.field_0 + 0.0000001;
      while ( 1 )
      {
        v23 = v20->pPrev;
        if ( v20->field_0 >= (double)v23->field_0 )
          break;
        v23->pNext = v20->pNext;
        v20->pNext->pPrev = v23;
        v23->pPrev->pNext = v20;
        v20->pPrev = v23->pPrev;
        v20->pNext = v23;
        v23->pPrev = v20;
      }
      v20 = v21;
      if ( v21 == &stru_80C9A4 )
        goto LABEL_50;
    }
  }
}
// 4EC3EC: using guessed type Edge defaultEdge;



//----- (00487355) --------------------------------------------------------
bool OutdoorCamera::_487355()
{
  int v0; // esi@1
  stru148 *v1; // edi@2
  bool result; // eax@3

  v0 = 0;
  if ( pOutdoorCamera->numStru148s > 0 )
  {
    v1 = array_77EC08;
    do
    {
      result = pGame->pLightmapBuilder->_45D3C7(v1);
      ++v0;
      ++v1;
    }
    while ( v0 < pOutdoorCamera->numStru148s );
  }
  return result;
}



//----- (00487DA9) --------------------------------------------------------
void __cdecl sub_487DA9()
{
  char *v0; // eax@1

  v0 = &array_77EC08[0].field_108;
  do
  {
    *v0 = 0;
    v0 += 268;
  }
  while ( (signed int)v0 < (signed int)&pVerticesSR_801A10[4] );
}

//----- (00487DBE) --------------------------------------------------------
void Software_ResetNewEdges()
{
  int v0; // ecx@1
  Edge **v1; // eax@1
  signed int v2; // eax@3

  v0 = 0;
  v1 = ptr_80CA10;
  do
  {
    ++v0;
    *((int *)&pNewEdges[v0] - 9) = (int)&defaultEdge;
    *v1 = 0;
    ++v1;
  }
  while ( (signed int)v1 < (signed int)&unk_80D190 );
  v2 = 2000;
  do
  {
    pSurfs->field_22 = 0;
    --v2;
  }
  while ( v2 );
}
// 4EC3EC: using guessed type Edge defaultEdge;




//----- (00487E1D) --------------------------------------------------------
TileTable::~TileTable()
{
  if ( this->pTiles )
  {
    pAllocator->FreeChunk(this->pTiles);
    pTiles = nullptr;
  }
  uNumTiles = 0;
}

//----- (00487E3B) --------------------------------------------------------
TileDesc *TileTable::GetTileById(unsigned int uTileID)
{
  /*TileDesc *result; // eax@3

  if ( (uTileID & 0x80000000u) != 0 || (signed int)uTileID > (signed int)(this->uNumTiles - 1) )
    result = this->pTiles;
  else
    result = &this->pTiles[uTileID];
  return result;*/

 if (uTileID < 0 || uTileID > this->uNumTiles - 1)
   return this->pTiles;
 else
   return &this->pTiles[uTileID];
}

//----- (00487E58) --------------------------------------------------------
void TileTable::InitializeTileset(int uTerrainType)
{
  TileTable *v2; // edi@1
  int v3; // ebx@1
  TileDesc *v4; // eax@2
  signed int i; // [sp+8h] [bp-4h]@1

  v2 = this;
  v3 = 0;
  for ( i = 0; i < (signed int)v2->uNumTiles; ++v3 )
  {
    v4 = &v2->pTiles[v3];
    if ( uTerrainType == v4->uTerrainType && v4->pTileName[0] )
    {
      v2->pTiles[v3].uBitmapID = pBitmaps_LOD->LoadTexture(v4->pTileName);
      if ( v2->pTiles[v3].uBitmapID != -1 )
        pBitmaps_LOD->pTextures[v2->pTiles[v3].uBitmapID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v2->pTiles[v3].uBitmapID].palette_id1);
    }
    ++i;
  }
}

//----- (00487ED6) --------------------------------------------------------
int TileTable::method_487ED6(signed int a1, int a2)
{
  int v3; // esi@1
  TileTable *v4; // edi@1
  int v5; // edx@3
  int v6; // edx@11
  unsigned int v8; // [sp-4h] [bp-10h]@4

  v3 = 0;
  v4 = this;
  if ( a1 > 8 )
  {
    v8 = 0;
    return v4->GetTileId(a1, v8);
  }
  if ( a2 || (v5 = rand() % 50, v5 < 20) )
  {
    v8 = 0;
    return v4->GetTileId(a1, v8);
  }
  if ( v5 < 30 )
  {
    v8 = 1;
    return v4->GetTileId(a1, v8);
  }
  if ( v5 < 40 )
  {
    v8 = 2;
    return v4->GetTileId(a1, v8);
  }
  if ( v5 < 48 )
  {
    v8 = 3;
    return v4->GetTileId(a1, v8);
  }
  v6 = rand() % 8;
  if ( !v6 )
  {
    v8 = 4;
    return v4->GetTileId(a1, v8);
  }
  if ( v6 == 1 )
  {
    v8 = 5;
    return v4->GetTileId(a1, v8);
  }
  if ( v6 == 2 )
  {
    v8 = 6;
    return v4->GetTileId(a1, v8);
  }
  if ( v6 == 3 )
  {
    v8 = 7;
    return v4->GetTileId(a1, v8);
  }
  if ( v6 == 4 )
  {
    v8 = 8;
    return v4->GetTileId(a1, v8);
  }
  if ( v6 == 5 )
  {
    v8 = 9;
    return v4->GetTileId(a1, v8);
  }
  if ( v6 == 6 )
  {
    v8 = 10;
    return v4->GetTileId(a1, v8);
  }
  if ( v6 == 7 )
  {
    v8 = 11;
    return v4->GetTileId(a1, v8);
  }
  return v3;
}

//----- (00487F84) --------------------------------------------------------
unsigned int TileTable::GetTileId(unsigned int uTerrainType, unsigned int uSection)
{
  unsigned int v3; // edx@1
  unsigned int result; // eax@1
  unsigned __int16 *v5; // ecx@2

  v3 = this->uNumTiles;
  result = 0;
  if ( (signed int)this->uNumTiles <= 0 )
  {
LABEL_6:
    result = 0;
  }
  else
  {
    v5 = &this->pTiles->uSection;
    while ( (signed __int16)*(v5 - 1) != uTerrainType || (signed __int16)*v5 != uSection )
    {
      ++result;
      v5 += 13;
      if ( (signed int)result >= (signed int)v3 )
        goto LABEL_6;
    }
  }
  return result;
}

//----- (00487FB4) --------------------------------------------------------
void TileTable::ToFile()
{
  TileTable *v1; // esi@1
  FILE *v2; // eax@1
  FILE *v3; // edi@1

  auto Str = this;

  v1 = Str;
  v2 = fopen("data\\dtile.bin", "wb");
  v3 = v2;
  if ( !v2 )
    Abortf("Unable to save dtile.bin!");
  fwrite(v1, 4u, 1u, v2);
  fwrite(v1->pTiles, 0x1Au, v1->uNumTiles, v3);
  fclose(v3);
}

//----- (00488000) --------------------------------------------------------
void TileTable::FromFile(void *pSerialized)
{
  uNumTiles = *(int *)pSerialized;
  pTiles = (TileDesc *)pAllocator->AllocNamedChunk(pTiles, 26 * uNumTiles, "Tile Descrip");
  memcpy(pTiles, (char *)pSerialized + 4, 26 * uNumTiles);
}

//----- (00488047) --------------------------------------------------------
int TileTable::FromFileTxt(const char *pFilename)
{
  TileTable *v2; // ebp@1
  FILE *v3; // eax@1
  unsigned int v4; // ebx@3
  void *v5; // eax@9
  unsigned __int16 v6; // ax@14
  const char *v7; // ST14_4@14
  unsigned __int16 v8; // ax@14
  const char *v9; // esi@14
  int v10; // eax@17
  int v11; // eax@20
  int v12; // eax@22
  int v13; // eax@24
  int v14; // eax@26
  int v15; // eax@28
  int v16; // eax@30
  int v17; // eax@32
  int v18; // eax@34
  int v19; // eax@36
  int v20; // eax@38
  int v21; // eax@40
  int v22; // eax@42
  int v23; // eax@44
  int v24; // eax@46
  int v25; // eax@48
  int v26; // eax@50
  int v27; // eax@52
  int v28; // eax@54
  int v29; // eax@56
  int v30; // eax@58
  int v31; // eax@60
  int v32; // eax@62
  int v33; // eax@64
  int v34; // eax@66
  const char *v35; // esi@67
  int v36; // eax@70
  int v37; // eax@73
  int v38; // eax@75
  int v39; // eax@77
  int v40; // eax@79
  int v41; // eax@81
  int v42; // eax@83
  int v43; // eax@85
  int v44; // eax@87
  int v45; // eax@89
  int v46; // eax@91
  int v47; // eax@93
  int v48; // eax@108
  int v49; // eax@110
  int v50; // eax@112
  int v51; // eax@114
  int v52; // eax@116
  int v53; // eax@118
  int v54; // eax@120
  int v55; // eax@122
  int v56; // eax@124
  int v57; // eax@126
  int v58; // eax@128
  int v59; // eax@130
  int v60; // eax@132
  int v61; // eax@134
  int v62; // eax@136
  int v63; // eax@138
  int v64; // eax@140
  int v65; // eax@142
  int v66; // eax@144
  int v67; // eax@146
  int v68; // eax@148
  int v69; // eax@150
  int v70; // eax@151
  int j; // edi@152
  const char *v72; // esi@153
  int v73; // eax@154
  int v74; // eax@156
  int v75; // eax@160
  int v76; // eax@162
  int v77; // eax@164
  int v78; // eax@166
  int v79; // eax@168
  int v80; // eax@170
  FILE *i; // [sp-10h] [bp-304h]@3
  FILE *File; // [sp+4h] [bp-2F0h]@1
  FrameTableTxtLine v84; // [sp+8h] [bp-2ECh]@4
  FrameTableTxtLine v85; // [sp+84h] [bp-270h]@4
  char Buf; // [sp+100h] [bp-1F4h]@4

  v2 = this;
  v3 = fopen(pFilename, "r");
  File = v3;
  if ( !v3 )
    Abortf("TileTable::load - Unable to open file: %s.");
  v4 = 0;
  for ( i = v3; fgets(&Buf, 490, i); i = File )
  {
    *strchr(&Buf, 10) = 0;
    memcpy(&v84, texture_frame_table_txt_parser(&Buf, &v85), sizeof(v84));
    if ( v84.field_0 && *v84.pProperties[0] != 47 )
      ++v4;
  }
  v2->uNumTiles = v4;
  v5 = pAllocator->AllocNamedChunk(v2->pTiles, 26 * v4, "Tile Descrip");
  v2->pTiles = (TileDesc *)v5;
  if ( !v5 )
    Abortf("TileTable::Load - Out of Memory!");
  memset(v5, 0, 26 * v2->uNumTiles);
  v2->uNumTiles = 0;
  fseek(File, 0, 0);
  if ( fgets(&Buf, 490, File) )
  {
    while ( 1 )
    {
      *strchr(&Buf, 10) = 0;
      memcpy(&v84, texture_frame_table_txt_parser(&Buf, &v85), sizeof(v84));
      if ( v84.field_0 )
      {
        if ( *v84.pProperties[0] != 47 )
          break;
      }
LABEL_173:
      if ( !fgets(&Buf, 490, File) )
        goto LABEL_174;
    }
    strcpy(v2->pTiles[v2->uNumTiles].pTileName, v84.pProperties[0]);
    v6 = atoi(v84.pProperties[1]);
    v7 = v84.pProperties[2];
    v2->pTiles[v2->uNumTiles].uTileID = v6;
    v8 = atoi(v7);
    v9 = v84.pProperties[3];
    v2->pTiles[v2->uNumTiles].uBitmapID = v8;
    v2->pTiles[v2->uNumTiles].uTerrainType = 0;
    if ( _strcmpi(v9, "TTtype_NULL") )
    {
      if ( _strcmpi(v9, "TTtype_Start") )
      {
        if ( _strcmpi(v9, "TTtype_Grass") )
        {
          if ( _strcmpi(v9, "TTtype_Cracked") )
          {
            if ( _strcmpi(v9, "TTtype_Snow") )
            {
              if ( _strcmpi(v9, "TTtype_Sand") )
              {
                if ( _strcmpi(v9, "TTtype_Volcano") )
                {
                  if ( _strcmpi(v9, "TTtype_Dirt") )
                  {
                    if ( _strcmpi(v9, "TTtype_Water") )
                    {
                      if ( _strcmpi(v9, "TTtype_Tropical") )
                      {
                        if ( _strcmpi(v9, "TTtype_Swamp") )
                        {
                          if ( _strcmpi(v9, "TTtype_City") )
                          {
                            if ( _strcmpi(v9, "TTtype_RoadGrassCobble") )
                            {
                              if ( _strcmpi(v9, "TTtype_RoadGrassDirt") )
                              {
                                if ( _strcmpi(v9, "TTtype_RoadCrackedCobble") )
                                {
                                  if ( _strcmpi(v9, "TTtype_RoadCrackedDirt") )
                                  {
                                    if ( _strcmpi(v9, "TTtype_RoadSandCobble") )
                                    {
                                      if ( _strcmpi(v9, "TTtype_RoadSandDirt") )
                                      {
                                        if ( _strcmpi(v9, "TTtype_RoadVolcanoCobble") )
                                        {
                                          if ( _strcmpi(v9, "TTtype_RoadVolcanoDirt") )
                                          {
                                            if ( _strcmpi(v9, "TTtype_RoadSwampCobble") )
                                            {
                                              if ( _strcmpi(v9, "TTtype_RoadSwampDirt") )
                                              {
                                                if ( _strcmpi(v9, "TTtype_RoadTropicalCobble") )
                                                {
                                                  if ( _strcmpi(v9, "TTtype_RoadTropicalDirt") )
                                                  {
                                                    if ( _strcmpi(v9, "TTtype_RoadSnowCobble") )
                                                    {
                                                      if ( _strcmpi(v9, "TTtype_RoadSnowDirt") )
                                                      {
                                                        if ( !_strcmpi(v9, "TTtype_RoadCityStone") )
                                                        {
                                                          v34 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                                          *(char *)v34 |= 0x1Cu;
                                                        }
                                                      }
                                                      else
                                                      {
                                                        v33 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                                        *(char *)v33 |= 0xDu;
                                                      }
                                                    }
                                                    else
                                                    {
                                                      v32 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                                      *(char *)v32 |= 0xCu;
                                                    }
                                                  }
                                                  else
                                                  {
                                                    v31 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                                    *(char *)v31 |= 0x1Bu;
                                                  }
                                                }
                                                else
                                                {
                                                  v30 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                                  *(char *)v30 |= 0x1Au;
                                                }
                                              }
                                              else
                                              {
                                                v29 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                                *(char *)v29 |= 0x19u;
                                              }
                                            }
                                            else
                                            {
                                              v28 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                              *(char *)v28 |= 0x18u;
                                            }
                                          }
                                          else
                                          {
                                            v27 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                            *(char *)v27 |= 0x11u;
                                          }
                                        }
                                        else
                                        {
                                          v26 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                          *(char *)v26 |= 0x10u;
                                        }
                                      }
                                      else
                                      {
                                        v25 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                        *(char *)v25 |= 0xFu;
                                      }
                                    }
                                    else
                                    {
                                      v24 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                      *(char *)v24 |= 0xEu;
                                    }
                                  }
                                  else
                                  {
                                    v23 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                    *(char *)v23 |= 0x17u;
                                  }
                                }
                                else
                                {
                                  v22 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                  *(char *)v22 |= 0x16u;
                                }
                              }
                              else
                              {
                                v21 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                                *(char *)v21 |= 0xBu;
                              }
                            }
                            else
                            {
                              v20 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                              *(char *)v20 |= 0xAu;
                            }
                          }
                          else
                          {
                            v19 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                            *(char *)v19 |= 9u;
                          }
                        }
                        else
                        {
                          v18 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                          *(char *)v18 |= 7u;
                        }
                      }
                      else
                      {
                        v17 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                        *(char *)v17 |= 8u;
                      }
                    }
                    else
                    {
                      v16 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                      *(char *)v16 |= 5u;
                    }
                  }
                  else
                  {
                    v15 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                    *(char *)v15 |= 4u;
                  }
                }
                else
                {
                  v14 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                  *(char *)v14 |= 3u;
                }
              }
              else
              {
                v13 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
                *(char *)v13 |= 2u;
              }
            }
            else
            {
              v12 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
              *(char *)v12 |= 1u;
            }
          }
          else
          {
            v11 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
            *(char *)v11 |= 6u;
          }
        }
      }
      else
      {
        v10 = (int)&v2->pTiles[v2->uNumTiles].uSection;
        *(char *)v10 |= 0xFEu;
      }
    }
    else
    {
      LOBYTE(v2->pTiles[v2->uNumTiles].uTerrainType) = -1;
    }
    v35 = v84.pProperties[4];
    v2->pTiles[v2->uNumTiles].uSection = 0;
    v2->pTiles[v2->uNumTiles].uAttributes = 0;
    if ( !_strcmpi(v35, "TTsect_NULL") )
    {
      LOBYTE(v2->pTiles[v2->uNumTiles].uSection) = -1;
LABEL_152:
      for ( j = 5; j < v84.field_0; ++j )
      {
        v72 = v84.pProperties[j];
        if ( _strcmpi(v84.pProperties[j], "TTattr_Burn") )
        {
          if ( _strcmpi(v72, "TTattr_Water") )
          {
            if ( _strcmpi(v72, "TTattr_Water2") )
            {
              if ( _strcmpi(v72, "TTattr_Block") )
              {
                if ( _strcmpi(v72, "TTattr_Repulse") )
                {
                  if ( _strcmpi(v72, "TTattr_Flat") )
                  {
                    if ( _strcmpi(v72, "TTattr_Wave") )
                    {
                      if ( _strcmpi(v72, "TTattr_NoDraw") )
                      {
                        if ( !_strcmpi(v72, "TTattr_Transition") )
                        {
                          v80 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
                          *(short *)v80 |= 0x200u;
                        }
                      }
                      else
                      {
                        v79 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
                        *(char *)v79 |= 0x40u;
                      }
                    }
                    else
                    {
                      v78 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
                      *(char *)v78 |= 0x20u;
                    }
                  }
                  else
                  {
                    v77 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
                    *(char *)v77 |= 0x10u;
                  }
                }
                else
                {
                  v76 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
                  *(char *)v76 |= 8u;
                }
              }
              else
              {
                v75 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
                *(char *)v75 |= 4u;
              }
            }
            else
            {
              HIBYTE(v2->pTiles[v2->uNumTiles].uAttributes) |= 1u;
            }
          }
          else
          {
            v74 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
            *(char *)v74 |= 2u;
          }
        }
        else
        {
          v73 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
          *(char *)v73 |= 1u;
        }
      }
      ++v2->uNumTiles;
      goto LABEL_173;
    }
    if ( !_strcmpi(v35, "TTsect_Start") )
    {
      v36 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v36 |= 0xFEu;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Base1") )
      goto LABEL_152;
    if ( !_strcmpi(v35, "TTsect_Base2") )
    {
      v37 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v37 |= 1u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Base3") )
    {
      v38 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v38 |= 2u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Base4") )
    {
      v39 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v39 |= 3u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Special1") )
    {
      v40 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v40 |= 4u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Special2") )
    {
      v41 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v41 |= 5u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Special3") )
    {
      v42 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v42 |= 6u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Special4") )
    {
      v43 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v43 |= 7u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Special5") )
    {
      v44 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v44 |= 8u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Special6") )
    {
      v45 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v45 |= 9u;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Special7") )
    {
      v46 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v46 |= 0xAu;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_Special8") )
    {
      v47 = (int)&v2->pTiles[v2->uNumTiles].uSection;
      *(char *)v47 |= 0xBu;
      goto LABEL_152;
    }
    if ( !_strcmpi(v35, "TTsect_NE1") )
      goto LABEL_130;
    if ( !_strcmpi(v35, "TTsect_NW1") )
      goto LABEL_134;
    if ( !_strcmpi(v35, "TTsect_SE1") )
      goto LABEL_130;
    if ( !_strcmpi(v35, "TTsect_SW1") )
      goto LABEL_134;
    if ( !_strcmpi(v35, "TTsect_E1") )
      goto LABEL_138;
    if ( !_strcmpi(v35, "TTsect_W1") )
      goto LABEL_140;
    if ( !_strcmpi(v35, "TTsect_N1") )
      goto LABEL_142;
    if ( !_strcmpi(v35, "TTsect_S1") )
      goto LABEL_144;
    if ( !_strcmpi(v35, "TTsect_XNE1") )
      goto LABEL_146;
    if ( _strcmpi(v35, "TTsect_XNW1") )
    {
      if ( !_strcmpi(v35, "TTsect_XSE1") )
        goto LABEL_146;
      if ( _strcmpi(v35, "TTsect_XSW1") )
      {
        if ( !_strcmpi(v35, "TTsect_CROS") )
        {
LABEL_151:
          v70 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
          *(short *)v70 |= 0x200u;
          goto LABEL_152;
        }
        if ( !_strcmpi(v35, "TTsect_NS") )
        {
          v48 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v48 |= 1u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_EW") )
        {
          v49 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v49 |= 2u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_N_E") )
        {
          v50 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v50 |= 3u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_N_W") )
        {
          v51 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v51 |= 4u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_S_E") )
        {
          v52 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v52 |= 5u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_S_W") )
        {
          v53 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v53 |= 6u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_NS_E") )
        {
          v54 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v54 |= 7u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_NS_W") )
        {
          v55 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v55 |= 8u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_EW_N") )
        {
          v56 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v56 |= 9u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_EW_S") )
        {
          v57 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v57 |= 0xAu;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_NCAP") )
        {
          v58 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v58 |= 0xBu;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_ECAP") )
        {
LABEL_130:
          v59 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v59 |= 0xCu;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_SCAP") )
        {
          v60 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v60 |= 0xDu;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_WCAP") )
        {
LABEL_134:
          v61 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v61 |= 0xEu;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_DN") )
        {
          v62 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v62 |= 0xFu;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_DS") )
        {
LABEL_138:
          v63 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v63 |= 0x10u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_DW") )
        {
LABEL_140:
          v64 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v64 |= 0x11u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_DE") )
        {
LABEL_142:
          v65 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v65 |= 0x12u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_DSW") )
        {
LABEL_144:
          v66 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v66 |= 0x13u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_DNE") )
        {
LABEL_146:
          v67 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v67 |= 0x14u;
          goto LABEL_151;
        }
        if ( !_strcmpi(v35, "TTsect_DSE") )
        {
          v68 = (int)&v2->pTiles[v2->uNumTiles].uSection;
          *(char *)v68 |= 0x15u;
          goto LABEL_151;
        }
        if ( _strcmpi(v35, "TTsect_DNW") )
          goto LABEL_152;
      }
    }
    v69 = (int)&v2->pTiles[v2->uNumTiles].uSection;
    *(char *)v69 |= 0x16u;
    goto LABEL_151;
  }
LABEL_174:
  fclose(File);
  return 1;
}



//----- (0048958E) --------------------------------------------------------
stru12_MemoryBlock::stru12_MemoryBlock(int a2)
{
  stru12_MemoryBlock *v2; // esi@1
  void *v3; // eax@1
  void *v4; // ecx@1
  stru12_MemoryBlock *result; // eax@1

  v2 = this;
  v3 = operator new(8 * a2 + 16);
  v2->pBlockBase = v3;
  v4 = (char *)v3 + (-(signed int)v3 & 7);
  result = v2;
  v2->pAlignedBlock = v4;
}

//----- (004895B7) --------------------------------------------------------
stru12::stru12(stru11 *pStru11)
{
  stru12 *v2; // esi@1

  v2 = this;
  this->field_44 = 0x41000000u;
  this->field_4C = 0x46000000u;
  //this->vdestructor_ptr = stru12::_4898E6;
  this->field_48 = 0;
  this->field_50 = 0;
  this->field_54 = 0x33D6BF95u;
  this->field_58 = 0;
  
  for (int i = 0; i < 12; ++i)
    v2->pMemBlocks[i] = new stru12_MemoryBlock(640);
  /*
  v3 = (stru12_MemoryBlock *)operator new(8u);
  if ( v3 )
    v4 = AllocAlignedMem(v3, 640);
  else
    v4 = 0;
  v2->pMemBlocks[0] = v4;
  /*v5 = (stru12_MemoryBlock *)operator new(8u);
  if ( v5 )
    v6 = AllocAlignedMem(v5, 640);
  else
    v6 = 0;
  v2->pMemBlocks[1] = v6;
  v7 = (stru12_MemoryBlock *)operator new(8u);
  if ( v7 )
    v8 = AllocAlignedMem(v7, 640);
  else
    v8 = 0;
  v2->pMemBlocks[2] = v8;
  v9 = (stru12_MemoryBlock *)operator new(8u);
  if ( v9 )
    v10 = AllocAlignedMem(v9, 640);
  else
    v10 = 0;
  v2->pMemBlocks[3] = v10;
  v11 = (stru12_MemoryBlock *)operator new(8u);
  if ( v11 )
    v12 = AllocAlignedMem(v11, 640);
  else
    v12 = 0;
  v2->pMemBlocks[4] = v12;
  v13 = (stru12_MemoryBlock *)operator new(8u);
  if ( v13 )
    v14 = AllocAlignedMem(v13, 640);
  else
    v14 = 0;
  v2->pMemBlocks[5] = v14;
  v15 = (stru12_MemoryBlock *)operator new(8u);
  if ( v15 )
    v16 = AllocAlignedMem(v15, 640);
  else
    v16 = 0;
  v2->pMemBlocks[6] = v16;
  v17 = (stru12_MemoryBlock *)operator new(8u);
  if ( v17 )
    v18 = AllocAlignedMem(v17, 640);
  else
    v18 = 0;
  v2->pMemBlocks[7] = v18;
  v19 = (stru12_MemoryBlock *)operator new(8u);
  if ( v19 )
    v20 = AllocAlignedMem(v19, 640);
  else
    v20 = 0;
  v2->pMemBlocks[8] = v20;
  v21 = (stru12_MemoryBlock *)operator new(8u);
  if ( v21 )
    v22 = AllocAlignedMem(v21, 640);
  else
    v22 = 0;
  v2->pMemBlocks[9] = v22;
  v23 = (stru12_MemoryBlock *)operator new(8u);
  if ( v23 )
    v24 = AllocAlignedMem(v23, 640);
  else
    v24 = 0;
  v2->pMemBlocks[10] = v24;
  v25 = (stru12_MemoryBlock *)operator new(8u);
  if ( v25 )
    v26 = AllocAlignedMem(v25, 640);
  else
    v26 = 0;
  v2->field_8C = 0;
  v2->pMemBlocks[11] = v26;*/
}

//----- (00489810) --------------------------------------------------------
stru12::~stru12()
{
  for (int i = 0; i < 12; ++i)
    delete pMemBlocks[i];
  /*if ( v2 )
    stru12_MemoryBlock::dtor(v2, 1);
  v3 = v1->pMemBlocks[1];
  if ( v3 )
    stru12_MemoryBlock::dtor(v3, 1);
  v4 = v1->pMemBlocks[2];
  if ( v4 )
    stru12_MemoryBlock::dtor(v4, 1);
  v5 = v1->pMemBlocks[3];
  if ( v5 )
    stru12_MemoryBlock::dtor(v5, 1);
  v6 = v1->pMemBlocks[4];
  if ( v6 )
    stru12_MemoryBlock::dtor(v6, 1);
  v7 = v1->pMemBlocks[5];
  if ( v7 )
    stru12_MemoryBlock::dtor(v7, 1);
  v8 = v1->pMemBlocks[6];
  if ( v8 )
    stru12_MemoryBlock::dtor(v8, 1);
  v9 = v1->pMemBlocks[7];
  if ( v9 )
    stru12_MemoryBlock::dtor(v9, 1);
  v10 = v1->pMemBlocks[8];
  if ( v10 )
    stru12_MemoryBlock::dtor(v10, 1);
  v11 = v1->pMemBlocks[9];
  if ( v11 )
    stru12_MemoryBlock::dtor(v11, 1);
  v12 = v1->pMemBlocks[10];
  if ( v12 )
    stru12_MemoryBlock::dtor(v12, 1);
  v13 = v1->pMemBlocks[11];
  if ( v13 )
    stru12_MemoryBlock::dtor(v13, 1);*/
}

//----- (004898BF) --------------------------------------------------------
stru12_MemoryBlock::~stru12_MemoryBlock()
{
  stru12_MemoryBlock *v2; // esi@1
  void *v3; // ST00_4@1

  v2 = this;
  v3 = this->pBlockBase;
  this->pAlignedBlock = 0;
  free(v3);
  v2->pBlockBase = 0;
  /*if ( a2 & 1 )
    free(v2);*/
}

//----- (004898E6) --------------------------------------------------------
void stru12::_4898E6()
{
  void *v1; // eax@1
  void *v2; // edx@1
  char *v3; // edi@2
  double v4; // st7@2
  char *v5; // ebx@2
  double v6; // st6@3
  double v7; // st5@3
  double v8; // st4@3
  int v9; // esi@3
  double v10; // st3@3
  float v11; // ST34_4@5
  double v12; // st6@10
  double v13; // ST0C_8@10
  char *v14; // [sp+14h] [bp-44h]@2
  char *v15; // [sp+18h] [bp-40h]@2
  char *v16; // [sp+1Ch] [bp-3Ch]@2
  char *v17; // [sp+20h] [bp-38h]@2
  char *v18; // [sp+24h] [bp-34h]@2
  float v19; // [sp+30h] [bp-28h]@3
  float v20; // [sp+38h] [bp-20h]@3
  char *v21; // [sp+3Ch] [bp-1Ch]@2
  int v22; // [sp+40h] [bp-18h]@1
  char *v23; // [sp+44h] [bp-14h]@2
  char *v24; // [sp+48h] [bp-10h]@2
  int v25; // [sp+4Ch] [bp-Ch]@2
  float v26; // [sp+50h] [bp-8h]@3
  float v27; // [sp+54h] [bp-4h]@3

  v22 = 0;
  v1 = this->pMemBlocks[1]->pAlignedBlock;
  v2 = this->pMemBlocks[6]->pAlignedBlock;
  if ( this->field_8C > 0 )
  {
    v24 = (char *)((char *)pMemBlocks[0]->pAlignedBlock - v1);
    v23 = (char *)((char *)pMemBlocks[2]->pAlignedBlock - v1);
    v18 = (char *)((char *)pMemBlocks[7]->pAlignedBlock - v2);
    v17 = (char *)((char *)pMemBlocks[8]->pAlignedBlock - v2);
    v25 = (int)v1 - (int)v2;
    v16 = (char *)((char *)pMemBlocks[9]->pAlignedBlock - v2);
    v3 = (char *)((char *)pMemBlocks[4]->pAlignedBlock - v2);
    v15 = (char *)((char *)pMemBlocks[10]->pAlignedBlock - v2);
    v4 = 1.0;
    v5 = (char *)((char *)pMemBlocks[5]->pAlignedBlock - v2);
    v21 = (char *)((char *)pMemBlocks[3]->pAlignedBlock - v2);
    v14 = (char *)((char *)pMemBlocks[11]->pAlignedBlock - v2);
    do
    {
      v26 = *(float *)&v24[(int)((char *)v2 + v25)] - (double)pIndoorCamera->pos.x;
      v27 = *(float *)((char *)v2 + v25) - (double)pIndoorCamera->pos.y;
      v6 = *(float *)&v23[(int)((char *)v2 + v25)] - (double)pIndoorCamera->pos.z;
      v7 = pIndoorCamera->fRotationYCosine;
      v8 = pIndoorCamera->fRotationYSine;
      v20 = pIndoorCamera->fRotationXCosine;
      v19 = pIndoorCamera->fRotationXSine;
      v9 = (int)((char *)v2 + (int)v21);
      v10 = v27 * pIndoorCamera->fRotationYSine + pIndoorCamera->fRotationYCosine * v26;
      if ( pIndoorCamera->sRotationX )
      {
        v11 = v10;
        *(float *)v9 = v11 * pIndoorCamera->fRotationXCosine + pIndoorCamera->fRotationXSine * v6;
        *(float *)((char *)v2 + (int)v3) = v7 * v27 - v8 * v26;
        *(float *)((char *)v2 + (int)v5) = v20 * v6 - v11 * v19;
      }
      else
      {
        *(float *)v9 = v10;
        *(float *)((char *)v2 + (int)v3) = v7 * v27 - v8 * v26;
        *(float *)((char *)v2 + (int)v5) = v6;
      }
      if ( *(float *)v9 >= 8.0 )
      {
        if ( (double)pOutdoorCamera->shading_dist_mist >= *(float *)v9 )
        {
          *(int *)v2 = 0;
          v12 = v4 / (*(float *)v9 + 0.0000001) * (double)pOutdoorCamera->int_fov_rad;
          *(float *)((char *)v2 + (int)v18) = (double)pViewport->uScreenCenterX
                                               - v12 * *(float *)((char *)v2 + (int)v3);
          *(float *)((char *)v2 + (int)v17) = (double)pViewport->uScreenCenterY
                                               - v12 * *(float *)((char *)v2 + (int)v5);
          *(float *)((char *)v2 + (int)v16) = v4
                                               - v4 / (*(float *)v9 * 1000.0 / (double)pOutdoorCamera->shading_dist_mist);
          *(float *)((char *)v2 + (int)v15) = v4 / (*(float *)v9 + 0.0000001);
          v13 = *(float *)v9 + 6.7553994e15;
          v4 = 1.0;
          *(int *)((char *)v2 + (int)v14) = LODWORD(v13);
        }
        else
        {
          *(int *)v2 = 2;
        }
      }
      else
      {
        *(int *)v2 = 1;
      }
      ++v22;
      v2 = (char *)v2 + 4;
    }
    while ( v22 < this->field_8C );
  }
  this->field_8C = 0;
}





//----- (0048A959) --------------------------------------------------------
unsigned int ReplaceHSV(unsigned int uColor, float h_replace, float s_replace, float v_replace)
{
  float r = ((uColor & 0x00FF0000) >> 16) / 255.0f,
        g = ((uColor & 0x0000FF00) >> 8) / 255.0f,
        b = (uColor & 0x000000FF) / 255.0f;

  float h, s, v;
  RGB2HSV(&h, &s, r, g, b, &v);

  if ( h_replace != -1.0 )
    h = h_replace;
  if ( s_replace != -1.0 )
    s = s_replace;
  if ( v_replace != -1.0 )
    v = v_replace;
  HSV2RGB(&r, &g, &b, h, s, v);

  return (((uint)floorf(r * 255.0f + 0.5f) & 0xFF) << 16) |
         (((uint)floorf(g * 255.0f + 0.5f) & 0xFF) << 8) |
         ((uint)floorf(b * 255.0f + 0.5f) & 0xFF);
}


//----- (0048B561) --------------------------------------------------------
int _48B561_mess_with_scaling_along_z(/*int a1, */float a2)
{
  //v2 = a2 - 0.5;
  //v3 = v2 + 6.7553994e15;
  int v4 = floorf(a2 - 0.5f + 0.5f);
  //v7 = (a2 - (double)SLODWORD(v3)) * 65536.0;
  //v5 = v7 + 6.7553994e15;
  //return LODWORD(v5) | (v4 << 16);
  int v5 = floorf((a2 - v4) * 65536.0f + 0.5f);
  return v5 | (v4 << 16);
}




//----- (004908DE) --------------------------------------------------------
signed int __cdecl PlayerCreation_Chose4Skills()
{
  Player *v0; // esi@1
  signed int v1; // edx@2
  unsigned short *v2; // eax@2
  signed int v3; // ecx@2

  v0 = pParty->pPlayers;//[0].pActiveSkills;
  while ( 1 )
  {
    v1 = 0;
	v2 = v0->pActiveSkills;
    v3 = 37;
    do
    {
      if ( *v2 )
        ++v1;
      ++v2;
      --v3;
    }
    while ( v3 );
    if ( v1 < 4 )
      break;
    ++v0;
	if ( v0 > &pParty->pPlayers[3] )
      return 1;
  }
  return 0;
}




//----- (00491CB5) --------------------------------------------------------
void __cdecl LoadPlayerPortraintsAndVoices()
{
  //Texture **v0; // ebx@1
  //int v1; // eax@2
  //int v2; // edi@3
  char *v3; // esi@5
  char *v4; // [sp+10h] [bp-4h]@1

  pIcons_LOD->pFacesLock = pIcons_LOD->uNumLoadedFiles;

  for (uint i = 0; i < 4; ++i)
    for (uint j = 0; j < 56; ++j)
    {
      sprintf(pTmpBuf, "%s%02d", pPlayerPortraitsNames[pParty->pPlayers[i].uFace], j + 1);
      pTextures_PlayerFaces[i][j] = pIcons_LOD->LoadTexturePtr(pTmpBuf, TEXTURE_16BIT_PALETTE);
    }

  pTexture_PlayerFaceEradicated = pIcons_LOD->LoadTexturePtr("ERADCATE", TEXTURE_16BIT_PALETTE);
  pTexture_PlayerFaceDead = pIcons_LOD->LoadTexturePtr("DEAD", TEXTURE_16BIT_PALETTE);
  pTexture_PlayerFaceMask = pIcons_LOD->LoadTexturePtr("FACEMASK", TEXTURE_16BIT_PALETTE);
  
  if (SoundSetAction[24][0])
    for (uint i = 0; i < 4; ++i)
    {
      pSoundList->LoadSound(2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4998, 0);
      pSoundList->LoadSound(2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4999, 0);
    }
}

//----- (00491DE7) --------------------------------------------------------
int __fastcall ReloadPlayerPortraits(int a1, int a2)
{
  int result; // eax@1
  const char **v3; // ebp@1
  Texture **v4; // ebx@1
  int v5; // esi@2

  result = 0;
  v3 = &pPlayerPortraitsNames[a2];
  v4 = pTextures_PlayerFaces[a1];
  do
  {
    v5 = result + 1;
    sprintf(pTmpBuf, "%s%02d", *v3, result + 1);
    pIcons_LOD->ReloadTexture(*v4, pTmpBuf, 2);
    result = v5;
    ++v4;
  }
  while ( v5 < 56 );
  return result;
}


//----- (00491E3A) --------------------------------------------------------
void __cdecl sub_491E3A()
{
  Player *v0; // ebx@1
  signed int v1; // esi@3
  char *v2; // eax@4
  unsigned int v3; // eax@7
  unsigned int v4; // edx@8
  char *v5; // ecx@9
  int v6; // edi@17
  Texture *v7; // ebx@18
  struct IDirect3DTexture2 **v8; // eax@19
  struct IDirect3DTexture2 *v9; // eax@20
  struct IDirectDrawSurface **v10; // eax@22
  struct IDirectDrawSurface *v11; // eax@23
  int v12; // eax@26

  v0 = pParty->pPlayers;
  do
  {
    if (SoundSetAction[24][0])
    {
      v1 = 0;
      if ( (signed int)pSoundList->uNumSounds <= 0 )
      {
LABEL_7:
        v3 = 0;
      }
      else
      {
        v2 = (char *)&pSoundList->pSounds->uSoundID;
        while ( *(int *)v2 != 2 * (SoundSetAction[24][0] + 50 * v0->uVoiceID) + 4998 )
        {
          ++v1;
          v2 += 120;
          if ( v1 >= (signed int)pSoundList->uNumSounds )
            goto LABEL_7;
        }
        v3 = v1;
      }
      pSoundList->_4A9DCD(v3, 1);
      v4 = 0;
      if ( (signed int)pSoundList->uNumSounds <= 0 )
      {
LABEL_12:
        v4 = 0;
      }
      else
      {
        v5 = (char *)&pSoundList->pSounds->uSoundID;
        while ( *(int *)v5 != 2 * (SoundSetAction[24][0] + 50 * v0->uVoiceID) + 4999 )
        {
          ++v4;
          v5 += 120;
          if ( (signed int)v4 >= (signed int)pSoundList->uNumSounds )
            goto LABEL_12;
        }
      }
      pSoundList->_4A9DCD(v4, 1);
    }
    ++v0;
  }
  while ( (signed int)v0 < (signed int)pParty->pHirelings );
  v6 = pIcons_LOD->uNumLoadedFiles - 1;
  if ( v6 >= pIcons_LOD->pFacesLock )
  {
    v7 = &pIcons_LOD->pTextures[v6];
    do
    {
      v7->Release();
      v8 = pIcons_LOD->pHardwareTextures;
      if ( v8 )
      {
        v9 = v8[v6];
        if ( v9 )
        {
          v9->Release();
          pIcons_LOD->pHardwareTextures[v6] = 0;
        }
      }
      v10 = pIcons_LOD->pHardwareSurfaces;
      if ( v10 )
      {
        v11 = v10[v6];
        if ( v11 )
        {
          v11->Release();
          pIcons_LOD->pHardwareSurfaces[v6] = 0;
        }
      }
      --v6;
      --v7;
    }
    while ( v6 >= pIcons_LOD->pFacesLock );
  }
  v12 = pIcons_LOD->pFacesLock;
  pIcons_LOD->pFacesLock = 0;
  pIcons_LOD->uNumLoadedFiles = v12;
}
// 4ED498: using guessed type char byte_4ED498;

//----- (00491F87) --------------------------------------------------------
void __cdecl DrawHiredNPCs()
{
  int v6; // eax@15
  char v7; // al@17
  unsigned int v8; // eax@18
  int v9; // esi@18
  int v10; // eax@18
  unsigned int v11; // eax@19
  unsigned int v12; // esi@19
  unsigned int v13; // eax@23
  IconFrame *v14; // eax@24
  unsigned int v15; // eax@26
  char pContainer[20]; // [sp+Ch] [bp-30h]@18
  unsigned int v17; // [sp+20h] [bp-1Ch]@19
  signed int uFrameID; // [sp+24h] [bp-18h]@19
  int i; // [sp+28h] [bp-14h]@15
  unsigned int v20; // [sp+2Ch] [bp-10h]@20
  unsigned int v21; // [sp+30h] [bp-Ch]@19
  int v22; // [sp+34h] [bp-8h]@2
  unsigned __int8 v23; // [sp+3Bh] [bp-1h]@2

  if ( bNoNPCHiring != 1 )
  {
    v23 = 0;
    v22 = 0;
    /*for (uint i = 0; i < 2; ++i)
    { 
      if (pParty->pHirelings[i].pName)
        pTmpBuf[v22++] = i;
    }*/
    if (pParty->pHirelings[0].pName)
      pTmpBuf[v22++] = 0;
    if (pParty->pHirelings[1].pName)
      pTmpBuf[v22++] = 1;

    for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
    {
      if (pNPCStats->pNewNPCData[i].uFlags == 128)
      {
        if (!pParty->pHirelings[0].pName || strcmp(pNPCStats->pNewNPCData[i].pName, pParty->pHirelings[0].pName))
        {
          if (!pParty->pHirelings[1].pName || strcmp(pNPCStats->pNewNPCData[i].pName, pParty->pHirelings[1].pName))
            pTmpBuf[v22++] = i + 2;
        }
      }
    }

    v6 = (unsigned __int8)pParty->field_709;
    for ( i = (unsigned __int8)pParty->field_709; i < v22; v6 = i++ + 1 )
    {
      if ( v23 >= 2 )
        break;
      v7 = pTmpBuf[v6];
      if ( (unsigned __int8)v7 >= 2 )
      {
        sprintf(pContainer, "NPC%03d", pNPCStats->pNPCData[(unsigned __int8)v7 + 499].uPortraitID);
        v15 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
        pRenderer->DrawTextureIndexed(pHiredNPCsIconsOffsetsX[v23], pHiredNPCsIconsOffsetsY[v23], (Texture *)(v15 != -1 ? &pIcons_LOD->pTextures[v15] : 0));
      }
      else
      {
        sprintf(pContainer, "NPC%03d", pParty->pHirelings[(unsigned __int8)v7].uPortraitID);
        v8 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
        v9 = v23;
        pRenderer->DrawTextureIndexed(pHiredNPCsIconsOffsetsX[v9], pHiredNPCsIconsOffsetsY[v9], (Texture *)(v8 != -1 ? &pIcons_LOD->pTextures[v8] : 0));
        v10 = (unsigned __int8)pTmpBuf[i];
        if ( pParty->pHirelings[v10].evt_A == 1 )
        {
          uFrameID = pParty->pHirelings[v10].evt_B;
          v11 = pHiredNPCsIconsOffsetsX[v9];
          v12 = pHiredNPCsIconsOffsetsY[v9];
          v17 = v11;
          v21 = 0;
          if ( (signed int)pIconsFrameTable->uNumIcons <= 0 )
          {
LABEL_23:
            v13 = 0;
          }
          else
          {
            v20 = 0;
            while ( _strcmpi("spell96", pIconsFrameTable->pIcons[v20 / 0x20].pAnimationName) )
            {
              ++v21;
              v20 += 32;
              if ( (signed int)v21 >= (signed int)pIconsFrameTable->uNumIcons )
                goto LABEL_23;
            }
            v13 = v21;
          }
          v14 = pIconsFrameTable->GetFrame(v13, uFrameID);
          pRenderer->DrawTextureTransparent(v17, v12, &pIcons_LOD->pTextures[v14->uTextureID]);
        }
      }
      ++v23;
    }
  }
}
// 6BE3C5: using guessed type char bNoNPCHiring;



//----- (004921C1) --------------------------------------------------------
void GameUI_DrawPortraits(unsigned int _this)
{
  Texture *pFace; // eax@10
  unsigned int v7; // eax@17
  PlayerFrame *pFrame; // eax@21
  unsigned int v9; // eax@27
  bool v10; // eax@33
  bool v11; // edi@40
  bool v12; // edx@43
  bool v13; // ecx@46
  int v16; // eax@57
  int v19; // eax@62
  Texture *pPortrait; // [sp-4h] [bp-1Ch]@27
  unsigned int v22; // [sp+14h] [bp-4h]@1

  v22 = _this;
  if ( qword_A750D8 )
  {
    qword_A750D8 -= (signed int)pMiscTimer->uTimeElapsed;
    if ( qword_A750D8 <= 0 )
    {
      if ( pPlayers[word_A750E2]->CanAct() )
        pPlayers[word_A750E2]->PlaySound((PlayerSpeech)word_A750E0, 0);
      qword_A750D8 = 0i64;
    }
  }

  for (uint i = 0; i < 4; ++i)
  {
    auto pPlayer = pParty->pPlayers + i;

    if (pPlayer->Eradicated())
    {
      pFace = pTexture_PlayerFaceEradicated;
      pPortrait = pFace;
      v9 = pPlayerPortraitsXCoords_For_PlayerBuffAnimsDrawing[i];
      if ( pParty->pPartyBuffs[11].uExpireTime )
        pRenderer->_4A6E7E(v9, 0x183u, pPortrait);
      else
        pRenderer->DrawTextureTransparent(v9 + 1, 0x184u, pPortrait);
      auto _v1 = 0;
      v10 = pPlayer->pPlayerBuffs[14].uExpireTime > 0;
      if (pPlayer->pPlayerBuffs[1].uExpireTime > 0)
        _v1 = 1;
      v11 = pPlayer->pPlayerBuffs[8].uExpireTime > 0;
      v12 = pPlayer->pPlayerBuffs[7].uExpireTime > 0;
      v13 = pPlayer->pPlayerBuffs[13].uExpireTime > 0;
      if ( v13 | v12 | v11 | _v1 | v10 )
        sub_441A4E(i);
      continue;
    }
    if (pPlayer->Dead())
    {
      pFace = pTexture_PlayerFaceDead;
      pPortrait = pFace;
      v9 = pPlayerPortraitsXCoords_For_PlayerBuffAnimsDrawing[i];
      if ( pParty->pPartyBuffs[11].uExpireTime )
        pRenderer->_4A6E7E(v9, 0x183u, pPortrait);
      else
        pRenderer->DrawTextureTransparent(v9 + 1, 0x184u, pPortrait);
      auto _v1 = 0;
      v10 = pPlayer->pPlayerBuffs[14].uExpireTime > 0;
      if (pPlayer->pPlayerBuffs[1].uExpireTime > 0)
        _v1 = 1;
      v11 = pPlayer->pPlayerBuffs[8].uExpireTime > 0;
      v12 = pPlayer->pPlayerBuffs[7].uExpireTime > 0;
      v13 = pPlayer->pPlayerBuffs[13].uExpireTime > 0;
      if ( v13 | v12 | v11 | _v1 | v10 )
        sub_441A4E(i);
      continue;
    }
      v7 = 0;
      for (uint j = 0; j < pPlayerFrameTable->uNumFrames; ++j)
        if (pPlayerFrameTable->pFrames[j].expression == pPlayer->expression)
        {
          v7 = j;
          break;
        }
    if ( v7 == 0 )
      v7 = 1;
    if (pPlayer->expression == CHARACTER_EXPRESSION_21)
      pFrame = pPlayerFrameTable->GetFrameBy_y(&pPlayer->field_1AA8, &pPlayer->field_1AA4, pMiscTimer->uTimeElapsed);
    else
      pFrame = pPlayerFrameTable->GetFrameBy_x(v7, pPlayer->uExpressionTimePassed);
    if (pPlayer->field_1AA2 != pFrame->uTextureID - 1 || v22 )
    {
      pPlayer->field_1AA2 = pFrame->uTextureID - 1;
      pFace = (Texture *)pTextures_PlayerFaces[i][pPlayer->field_1AA2];//pFace = (Texture *)pTextures_PlayerFaces[i][pFrame->uTextureID];
      pPortrait = pFace;
      v9 = pPlayerPortraitsXCoords_For_PlayerBuffAnimsDrawing[i];
      if ( pParty->pPartyBuffs[11].uExpireTime )
        pRenderer->_4A6E7E(v9, 0x183u, pPortrait);
      else
        pRenderer->DrawTextureTransparent(v9 + 1, 0x184u, pPortrait);
      auto _v1 = 0;
      v10 = pPlayer->pPlayerBuffs[14].uExpireTime > 0;
      if (pPlayer->pPlayerBuffs[1].uExpireTime > 0)
        _v1 = 1;
      v11 = pPlayer->pPlayerBuffs[8].uExpireTime > 0;
      v12 = pPlayer->pPlayerBuffs[7].uExpireTime > 0;
      v13 = pPlayer->pPlayerBuffs[13].uExpireTime > 0;
      if ( v13 | v12 | v11 | _v1 | v10 )
        sub_441A4E(i);
      continue;
    }
  }
  if ( pParty->bTurnBasedModeOn == 1 )
  {
    if ( pTurnEngine->field_4 != 1 )
    {
      if ( (pTurnEngine->pQueue[0].uPackedID & 7) == OBJECT_Player)
      {
        //v14 = 0;
        if ( pTurnEngine->uActorQueueSize > 0 )
        {
          //v15 = (char *)pTurnEngine->pQueue;
          for (uint i = 0; i < pTurnEngine->uActorQueueSize; ++i)
          {
            auto pElem = pTurnEngine->pQueue + i;

            if ( (pElem->uPackedID & 7) != OBJECT_Player)
              break;
            v16 = dword_5079D0;
            if ( pParty->uFlags & 0x10 )
            {
              v16 = dword_5079CC;
            }
            else
            {
              if ( pParty->uFlags & 0x20 )
                v16 = dword_5079C8;
            }
            pRenderer->DrawTextureTransparent(pPlayerPortraitsXCoords_For_PlayerBuffAnimsDrawing[pElem->uPackedID >> 3] - 4,
              0x181u, (Texture *)(v16 != -1 ? &pIcons_LOD->pTextures[v16] : 0));
          }
        }
      }
    }
  }
  else
  {
    for (uint i = 0; i < 4; ++i)
    {
      auto pPlayer = pParty->pPlayers + i;
      if (pPlayer->CanAct() && !pPlayer->uTimeToRecovery)
      {
        v19 = dword_5079D0;
        if ( pParty->uFlags & 0x10 )
        {
          v19 = dword_5079CC;
        }
        else
        {
          if ( pParty->uFlags & 0x20 )
            v19 = dword_5079C8;
        }
        pRenderer->DrawTextureTransparent(pPlayerPortraitsXCoords_For_PlayerBuffAnimsDrawing[i] - 4,
          0x181u, (Texture *)(v19 != -1 ? &pIcons_LOD->pTextures[v19] : 0));
      }
    }
  }
}


//----- (0049387A) --------------------------------------------------------
int CycleCharacter(unsigned int _this)
{
  signed int result; // eax@1
  signed int v2; // ecx@2
  signed int v3; // ecx@8

  result = uActiveCharacter;
  if ( _this )
  {
    v2 = 0;
    while ( 1 )
    {
      --result;
      if ( result < 1 )
        result = 4;
      if ( !pPlayers[result]->uTimeToRecovery )
        break;
      ++v2;
      if ( v2 >= 4 )
        return uActiveCharacter;
    }
  }
  else
  {
    v3 = 0;
    while ( 1 )
    {
      ++result;
      if ( result > 4 )
        result = 1;
      if ( !pPlayers[result]->uTimeToRecovery )
        break;
      ++v3;
      if ( v3 >= 4 )
        return uActiveCharacter;
    }
  }
  return result;
}

//----- (004938D1) --------------------------------------------------------
void __fastcall Rest(unsigned int uHoursToSleep)
{
  unsigned int v1; // esi@1
  double v2; // st7@3
  Player **v3; // esi@3

  v1 = uHoursToSleep;
  if ( uHoursToSleep > 240 )
    InitializeActors();
  v2 = (double)(7680 * v1) * 0.033333335;
  pParty->uTimePlayed += (signed __int64)v2;
  v3 = &pPlayers[1];
  do
  {
    (*v3)->Recover((signed __int64)v2);
    ++v3;
  }
  while ( (signed int)v3 <= (signed int)&pPlayers[4] );
  _494035_timed_effects__water_walking_damage__etc();
}

//----- (00493938) --------------------------------------------------------
int __cdecl _493938_regenerate()
{
  int v0; // edi@1
  signed __int64 v1; // qax@1
  int v2; // ecx@1
  int result; // eax@1
  int v4; // eax@2
  int v5; // edi@5
  int *v6; // ecx@5
  char v7; // sf@5
  int *v8; // ecx@10
  int v9; // edi@15
  signed int v10; // eax@15
  __int16 *v11; // edx@16
  int v12; // eax@20
  int v13; // ebx@20
  unsigned int *v14; // esi@21
  unsigned int v15; // ecx@21
  unsigned int v16; // eax@21
  int v17; // edx@21
  int v18; // eax@21
  signed int v19; // eax@21
  signed int v20; // ebx@25
  Player *v21; // esi@25
  ITEM_EQUIP_TYPE v22; // edi@30
  //int v23; // edx@31
  signed int v24; // ecx@32
  signed int v25; // eax@33
  int v26; // eax@35
  int v27; // eax@36
  int v28; // eax@37
  int v29; // eax@40
  int v30; // eax@41
  signed int v31; // ecx@53
  char *v32; // eax@53
  char *v33; // edi@82
  int v34; // ecx@88
  int v35; // eax@88
  char *v36; // edi@99
  int v37; // edi@104
  int v38; // edi@106
  int v39; // edi@111
  int v40; // ecx@113
  char v41[400]; // [sp+4h] [bp-22Ch]@20
  LayingItem a1; // [sp+194h] [bp-9Ch]@15
  Vec3_int_ a3; // [sp+204h] [bp-2Ch]@15
  int v44; // [sp+210h] [bp-20h]@22
  int v45; // [sp+214h] [bp-1Ch]@25
  int v46; // [sp+218h] [bp-18h]@25
  int v47; // [sp+21Ch] [bp-14h]@25
  int v48; // [sp+220h] [bp-10h]@25
  int v49; // [sp+224h] [bp-Ch]@24
  int v50; // [sp+228h] [bp-8h]@25
  int v51; // [sp+22Ch] [bp-4h]@2

  v0 = (signed int)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
  v1 = (signed __int64)((double)pParty->uLastRegenerationTime * 0.234375);
  v2 = (signed int)v1 / 60;
  result = (signed int)v1 / 60 + 5;
  if ( v0 >= result )
  {
    v51 = 0;
    v4 = (v0 - v2) / 5;
    if (pParty->FlyActive())
    {
      if ( pParty->bFlying )
      {
        if ( !(pParty->pPartyBuffs[7].uFlags & 1) )
        {
          v5 = v4 * pParty->pPartyBuffs[7].uPower;
          __debugbreak();
		  v6 = (int *)&pParty->pPlayers[pParty->pPartyBuffs[7].uCaster].pConditions[0];//&stru_AA1058[4].pSounds[6972 * pParty->pPartyBuffs[7].uCaster + 2000];
          v7 = *v6 < v5;
          *v6 -= v5;
          if ( v7 )
          {
            *v6 = 0;
            pParty->uFlags &= 0xFFFFFFBFu;
            pParty->bFlying = 0;
            v51 = 1;
          }
        }
      }
    }
    if (pParty->WaterWalkActive())
    {
      if (pParty->uFlags & 0x80 )
      {
        if ( !(pParty->pPartyBuffs[18].uFlags & 1) )
        {
          __debugbreak();
          v8 = (int *)&pParty->pPlayers[pParty->pPartyBuffs[18].uCaster].pConditions[0];//&stru_AA1058[4].pSounds[6972 * pParty->pPartyBuffs[18].uCaster + 2000];
          v7 = *v8 < v4;
          *v8 -= v4;
          if ( v7 )
          {
            *v8 = 0;
            LOBYTE(pParty->uFlags) &= 0x7Fu;
            v51 = 1;
          }
        }
      }
    }
    if (pParty->ImmolationActive())
    {
      //LayingItem::LayingItem(&a1);
      v9 = 0;
      a3.z = 0;
      a3.y = 0;
      a3.x = 0;
      a1.stru_24.Reset();
      a1.field_4C = pParty->pPartyBuffs[10].uPower;
      a1.field_50 = pParty->ImmolationSkillLevel();
      v10 = 0;
      a1.uItemType = 1070;
      a1.field_48 = 8;
      if ( (signed int)pObjectList->uNumObjects <= 0 )
      {
LABEL_19:
        LOWORD(v10) = 0;
      }
      else
      {
        v11 = &pObjectList->pObjects->uObjectID;
        while ( stru_4E3ACC[8].uItemType != *v11 )
        {
          ++v10;
          v11 += 28;
          if ( v10 >= (signed int)pObjectList->uNumObjects )
            goto LABEL_19;
        }
      }
      a1.uObjectDescID = v10;
      a1.field_60_distance_related_prolly_lod = 0;
      v12 = 8 * pParty->pPartyBuffs[10].uCaster;
      LOBYTE(v12) = v12 | OBJECT_Player;
      a1.uAttributes = 0;
      a1.uSectorID = 0;
      a1.uSpriteFrameID = 0;
      a1.field_58_pid = v12;
      a1.uFacing = 0;
      a1.uSoundID = 0;
      v13 = sub_46A89E((int)v41, 100, 307);
      if ( v13 > 0 )
      {
        do
        {
          v14 = (unsigned int *)&v41[4 * v9];
          v15 = *v14;
          v16 = *v14;
          a1.vPosition.x = pActors[v16].vPosition.x;
          v17 = pActors[v16].vPosition.y;
          a1.vPosition.z = pActors[v16].vPosition.z;
          v18 = 8 * v15;
          LOBYTE(v18) = 8 * v15 | 3;
          a1.vPosition.y = v17;
          a1.field_5C = v18;
          v19 = a1.Create(0, 0, 0, 0);
          DamageMonsterFromParty(8 * v19 | 2, *v14, &a3);
          ++v9;
        }
        while ( v9 < v13 );
      }
    }
    v44 = 0;
    if (PartyHasDragon())
      v44 = 1;
    v49 = 0;
LABEL_25:
    v20 = 0;
    v21 = &pParty->pPlayers[v49];
    v50 = 0;
    v47 = 0;
    v45 = 0;
    v48 = 0;
    v46 = 0;
    if ( v44 && v21->classType == PLAYER_CLASS_WARLOCK )
      v50 = 1;
    if ( v21->classType == PLAYER_CLASS_LICH )
      v48 = 1;
    v22 = (ITEM_EQUIP_TYPE)0;
    while ( 1 )
    {
      if ( v21->HasItemEquipped(v22) )
      {
        //v23 = v21->pEquipment.pIndices;
        auto _idx = v21->pEquipment.pIndices[v22];
        v24 = v21->pInventoryItems[_idx].uItemID;
        if ( v24 > 134 )
        {
          if ( v24 == 529 )
            goto LABEL_43;
          if ( v24 == 535 )
            goto LABEL_44;
          if ( v24 == 515 )
          {
            v47 = 1;
          }
          else
          {
            if ( v24 == 532 )
              goto LABEL_50;
          }
        }
        else
        {
          v25 = v21->pInventoryItems[_idx].uSpecEnchantmentType;
          if ( v25 <= 50 )
          {
            if ( v25 != 50 )
            {
              v26 = v25 - 37;
              if ( v26 )
              {
                v27 = v26 - 1;
                if ( !v27 )
                  goto LABEL_50;
                v28 = v27 - 6;
                if ( v28 )
                {
                  if ( v28 != 3 )
                    goto LABEL_51;
LABEL_50:
                  v50 = 1;
                  goto LABEL_51;
                }
              }
            }
LABEL_44:
            v20 = 1;
            goto LABEL_51;
          }
          v29 = v25 - 54;
          if ( !v29 )
            goto LABEL_44;
          v30 = v29 - 1;
          if ( !v30 )
            goto LABEL_50;
          if ( v30 == 11 )
          {
LABEL_43:
            v20 = 1;
            v50 = 1;
            goto LABEL_51;
          }
        }
      }
LABEL_51:
      v22 = (ITEM_EQUIP_TYPE)((int)v22 + 1);
      if ( (signed int)v22 >= 16 )
      {
        if ( v48 )
        {
          v31 = 0;
          v32 = (char *)v21->pInventoryItems;
          while ( *(int *)v32 != 601 || (unsigned __int8)v32[26] != v49 + 1 )
          {
            ++v31;
            v32 += 36;
            if ( v31 >= 138 )
              goto LABEL_59;
          }
          v48 = 0;
          v45 = 1;
        }
LABEL_59:
        if ( v21->pConditions[17] )
          v46 = 1;
        if ( v20 && !v21->pConditions[14] && !v21->pConditions[16] )
        {
          ++v21->sHealth;
          if ( v21->sHealth > v21->GetMaxHealth() )
            v21->sHealth = v21->GetMaxHealth();
          if ( v21->pConditions[13] && v21->sHealth > 0 )
          {
            LODWORD(v21->pConditions[13]) = 0;
            HIDWORD(v21->pConditions[13]) = 0;
          }
          v51 = 1;
        }
        if ( SHIDWORD(v21->pPlayerBuffs[12].uExpireTime) >= 0
          && (SHIDWORD(v21->pPlayerBuffs[12].uExpireTime) > 0 || LODWORD(v21->pPlayerBuffs[12].uExpireTime))
          && !v21->pConditions[14]
          && !v21->pConditions[16] )
        {
          v21->sHealth += 5 * v21->pPlayerBuffs[12].uPower;
          if ( v21->sHealth > v21->GetMaxHealth() )
            v21->sHealth = v21->GetMaxHealth();
          if ( v21->pConditions[13] && v21->sHealth > 0 )
          {
            LODWORD(v21->pConditions[13]) = 0;
            HIDWORD(v21->pConditions[13]) = 0;
          }
          v51 = 1;
        }
        if ( v50 )
        {
          v33 = (char *)&v21->sMana;
          ++*(int *)v33;
          if ( v21->sMana > v21->GetMaxMana() )
            *(int *)v33 = v21->GetMaxMana();
          v51 = 1;
        }
        if ( v47 && !v21->pConditions[14] && !v21->pConditions[16] )
        {
          v34 = LODWORD(v21->pConditions[13]);
          --v21->sHealth;
          v35 = v21->sHealth;
          if ( !(HIDWORD(v21->pConditions[13]) | v34) && v35 < 0 )
            v21->pConditions[13] = pParty->uTimePlayed;
          if ( v35 < 1 )
          {
            if ( v21->sHealth + v21->uEndurance + v21->GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE, 0) >= 1
              || (signed __int64)v21->pPlayerBuffs[11].uExpireTime > 0 )
            {
              v21->pConditions[13] = pParty->uTimePlayed;
            }
            else
            {
              if ( !v21->pConditions[14] )
                v21->pConditions[14] = pParty->uTimePlayed;
            }
          }
          v51 = 1;
        }
        if ( v45 )
        {
          v36 = (char *)&v21->sMana;
          ++*(int *)v36;
          if ( v21->sMana > v21->GetMaxMana() )
            *(int *)v36 = v21->GetMaxMana();
        }
        if ( v48 && !v21->pConditions[14] && !v21->pConditions[16] )
        {
          v37 = v21->sHealth;
          if ( v37 > v21->GetMaxHealth() / 2 )
            v21->sHealth = v37 - 2;
          v38 = v21->sMana;
          if ( v38 > v21->GetMaxMana() / 2 )
            v21->sMana = v38 - 2;
        }
        if ( v46 && !v21->pConditions[14] && !v21->pConditions[16] )
        {
          v39 = v21->sHealth;
          if ( v39 > v21->GetMaxHealth() / 2 )
            v21->sHealth = v39 - 1;
          v40 = v21->sMana;
          if ( v40 > 0 )
            v21->sMana = v40 - 1;
        }
        ++v49;
        if ( v49 >= 4 )
        {
          result = HIDWORD(pParty->uTimePlayed);
          pParty->uLastRegenerationTime = pParty->uTimePlayed;
          if ( !viewparams->bRedrawGameUI )
          {
            result = v51;
            viewparams->bRedrawGameUI = v51;
          }
          return result;
        }
        goto LABEL_25;
      }
    }
  }
  return result;
}



//----- (00493F79) --------------------------------------------------------
void sub_493F79(stru351_summoned_item *_this, __int64 a2)
{
  signed __int64 v2; // ST2C_8@1
  signed __int64 v3; // qax@1
  //signed __int64 v4; // ST1C_8@1
  unsigned __int64 v5; // qax@1
  unsigned int v6; // ebx@1

  v2 = (signed __int64)((double)a2 * 0.234375);
  v3 = v2 / 60 / 60;
  //v4 = v3;
  v5 = (unsigned int)v3 / 0x18;
  v6 = (unsigned int)(v5 / 7) >> 2;
  _this->field_0_expire_second = v2 % 60;
  _this->field_4_expire_minute = v2 / 60 % 60;
  _this->field_8_expire_hour = v3 % 24;
  _this->field_10_expire_week = v5 / 7 & 3;
  _this->field_C_expire_day = (unsigned int)v5 % 0x1C;
  _this->field_14_exprie_month = v6 % 0xC;
  _this->field_18_expire_year = v6 / 0xC + game_starting_year;
}





//----- (00494035) --------------------------------------------------------
void __cdecl _494035_timed_effects__water_walking_damage__etc()
{
  signed __int64 v0; // qax@1
  signed __int64 v1; // ST30_8@1
  signed __int64 v2; // ST38_8@1
  unsigned __int64 v3; // qax@1
  unsigned int v4; // edi@1
  //signed int v5; // eax@4
  //char *v6; // ecx@5
  //Player *v7; // esi@8
  //char *v8; // ecx@12
  Player *pPlayer; // esi@15
  //void *v10; // esi@25
  unsigned int v11; // ecx@27
  signed int v12; // edi@29
  Player *v13; // ecx@30
  Player *v14; // esi@35
  double v15; // st7@35
  Player **v16; // esi@43
  Player *v17; // edi@44
  double v18; // st7@44
  float v19; // ST28_4@48
  double v20; // ST38_8@48
  Player *v21; // esi@51
  signed int v22; // edi@53
  int v23; // eax@59
  int v24; // ecx@60
  int v25; // eax@63
  int v26; // ecx@64
  int v27; // eax@67
  int v28; // ecx@68
  int v29; // eax@71
  int v30; // ecx@72
  int v31; // eax@75
  int v32; // ecx@76
  int v33; // eax@79
  int v34; // ecx@80
  int v35; // eax@83
  int v36; // ecx@84
  int v37; // eax@87
  int v38; // ecx@88
  int v39; // eax@91
  int v40; // ecx@92
  int v41; // eax@95
  int v42; // ecx@96
  bool v43; // ebx@102
  //SpellBuff *v44; // edi@104
  //signed int v45; // ebp@104
  bool v46; // edi@111
  //SpellBuff *v47; // esi@113
  //Player **v48; // esi@119
  //signed int v49; // edi@121
  //char *v50; // esi@122
  signed int v51; // edx@128
  signed int v52; // ecx@130
  int v53; // eax@131
  Player *v54; // eax@141
  unsigned int v55; // [sp-8h] [bp-38h]@18
  unsigned int v56; // [sp-8h] [bp-38h]@55
  int v57; // [sp-4h] [bp-34h]@18
  int v58; // [sp-4h] [bp-34h]@33
  int v59; // [sp-4h] [bp-34h]@55
  unsigned int v60; // [sp+10h] [bp-20h]@1
  unsigned int v61; // [sp+14h] [bp-1Ch]@1
  Player **v62; // [sp+14h] [bp-1Ch]@50
  unsigned int a2; // [sp+18h] [bp-18h]@1
  signed int a2a; // [sp+18h] [bp-18h]@47
  signed int v65; // [sp+1Ch] [bp-14h]@47

  a2 = pParty->uCurrentHour;
  v61 = pParty->uDaysPlayed;
  v60 = pEventTimer->uTimeElapsed;
  pParty->uTimePlayed += (signed int)pEventTimer->uTimeElapsed;
  v0 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
  v1 = v0;
  v0 /= 60i64;
  v2 = v0;
  v3 = (unsigned int)v0 / 24;
  v4 = (unsigned int)(v3 / 7) >> 2;
  pParty->uCurrentTimeSecond = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) % 60;
  pParty->uCurrentMinute = v1 % 60;
  pParty->uCurrentMonthWeek = v3 / 7 & 3;
  pParty->uCurrentHour = v2 % 24;
  pParty->uDaysPlayed = (unsigned int)v3 % 28;
  pParty->uCurrentMonth = v4 % 12;
  pParty->uCurrentYear = v4 / 0xC + game_starting_year;
  if ( pParty->uCurrentHour >= 3 && ((signed int)a2 < 3 || (unsigned int)v3 % 28 > v61) )
  {
    pParty->pHirelings[0].bHasUsedTheAbility = false;
    pParty->pHirelings[1].bHasUsedTheAbility = false;

    for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
      pNPCStats->pNewNPCData[i].bHasUsedTheAbility = false;

    ++pParty->field_764;
    if ( pParty->field_764 > 1u )
    {
      for (uint i = 0; i < 4; ++i)
        pParty->pPlayers[i].SetCondition(1, 0);

      if ( pParty->uNumFoodRations )
      {
        Party::TakeFood(1u);
      }
      else
      {
        for (uint i = 0; i < 4; ++i)
          pParty->pPlayers[i].sHealth = pParty->pPlayers[i].sHealth / ((unsigned __int8)pParty->field_764 + 1) + 1;
      }
      if ( pParty->field_764 > 3u )
      {
        pPlayer = pParty->pPlayers;
        do
        {
          pPlayer->Zero();
          if ( !(pPlayer->pConditions[15] | pPlayer->pConditions[16] | pPlayer->pConditions[14]) )
          {
            if ( rand() % 100 < 5 * (unsigned __int8)pParty->field_764 )
            {
              v57 = 0;
              v55 = 14;
LABEL_21:
              pPlayer->SetCondition(v55, v57);
              goto LABEL_22;
            }
            if ( rand() % 100 < 10 * (unsigned __int8)pParty->field_764 )
            {
              v57 = 0;
              v55 = 5;
              goto LABEL_21;
            }
          }
LABEL_22:
          ++pPlayer;
        }
        while ( (signed int)pPlayer < (signed int)pParty->pHirelings );
      }
    }
    if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
      pOutdoor->SetFog();

    for (uint i = 0; i < 4; ++i)
      pParty->pPlayers[i].uNumDivineInterventionCastsThisDay = 0;
  }
  v11 = LODWORD(pParty->uTimePlayed);
  if ( pParty->uFlags & 4 && pParty->field_6FC < (signed __int64)pParty->uTimePlayed )
  {
    v12 = 1;
    pParty->field_6FC = LODWORD(pParty->uTimePlayed) + 128;
    viewparams->bRedrawGameUI = 1;
    while ( 1 )
    {
      if ( pPlayers[v12]->WearsItem(516, 3)
        || pPlayers[v12]->HasEnchantedItemEquipped(71)
        || pPlayers[v12]->pPlayerBuffs[23].uExpireTime > 0 )
      {
        v58 = 0;
      }
      else
      {
        v58 = 0;
        if ( !sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(v12) )
        {
          v14 = pPlayers[v12];
          v15 = (double)pPlayers[v12]->GetMaxHealth() * 0.1;
          v14->ReceiveDamage((signed __int64)v15, 0);
          if ( pParty->uFlags & 4 )
          {
            strcpy(GameUI_StatusBar_TimedString, pGlobalTXT_LocalizationStrings[660]);
            GameUI_StatusBar_TimedStringTimeLeft = 128;
          }
          goto LABEL_39;
        }
        v13 = pPlayers[v12];
      }
      v13->PlayEmotion(CHARACTER_EXPRESSION_37, v58);
LABEL_39:
      ++v12;
      if ( v12 > 4 )
      {
        v11 = LODWORD(pParty->uTimePlayed);
        break;
      }
    }
  }
  if ( pParty->uFlags & 0x200 && pParty->field_6FC < (signed __int64)__PAIR__(HIDWORD(pParty->uTimePlayed), v11) )
  {
    viewparams->bRedrawGameUI = 1;
    pParty->field_6FC = v11 + 128;
    v16 = &pPlayers[1];
    do
    {
      v17 = *v16;
      v18 = (double)(*v16)->GetMaxHealth() * 0.1;
      v17->ReceiveDamage((signed __int64)v18, 0);
      if ( pParty->uFlags & 0x200 )
      {
        strcpy(GameUI_StatusBar_TimedString, pGlobalTXT_LocalizationStrings[661]);
        GameUI_StatusBar_TimedStringTimeLeft = 128;
      }
      ++v16;
    }
    while ( (signed int)v16 <= (signed int)&pPlayers[4] );
  }
  _493938_regenerate();
  v65 = 4;
  a2a = v60;
  if ( pParty->uFlags2 & 2 )
  {
    v19 = (double)(signed int)v60 * 0.5;
    v20 = v19 + 6.7553994e15;
    a2a = LODWORD(v20);
    if ( SLODWORD(v20) <= 0 )
      a2a = 1;
  }
  v62 = &pPlayers[1];
  do
  {
    v21 = *v62;
    if ( (*v62)->uTimeToRecovery )
      v21->Recover(a2a);
    v22 = v21->sHealth;
    if ( v21->GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE, 0) + v22 + v21->uEndurance >= 1
      || (signed __int64)v21->pPlayerBuffs[11].uExpireTime > 0 )
    {
      if ( v22 >= 1 )
        goto LABEL_59;
      v59 = 0;
      v56 = 13;
    }
    else
    {
      v59 = 0;
      v56 = 14;
    }
    v21->SetCondition(v56, v59);
LABEL_59:
    v23 = (int)&v21->field_E0;
    if ( v21->field_E0 )
    {
      v24 = *(int *)v23 - v60;
      if ( v24 > 0 )
      {
        *(int *)v23 = v24;
      }
      else
      {
        *(int *)v23 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v25 = (int)&v21->field_E4;
    if ( v21->field_E4 )
    {
      v26 = *(int *)v25 - v60;
      if ( v26 > 0 )
      {
        *(int *)v25 = v26;
      }
      else
      {
        *(int *)v25 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v27 = (int)&v21->field_E8;
    if ( v21->field_E8 )
    {
      v28 = *(int *)v27 - v60;
      if ( v28 > 0 )
      {
        *(int *)v27 = v28;
      }
      else
      {
        *(int *)v27 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v29 = (int)&v21->field_EC;
    if ( v21->field_EC )
    {
      v30 = *(int *)v29 - v60;
      if ( v30 > 0 )
      {
        *(int *)v29 = v30;
      }
      else
      {
        *(int *)v29 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v31 = (int)&v21->field_F0;
    if ( v21->field_F0 )
    {
      v32 = *(int *)v31 - v60;
      if ( v32 > 0 )
      {
        *(int *)v31 = v32;
      }
      else
      {
        *(int *)v31 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v33 = (int)&v21->field_F4;
    if ( v21->field_F4 )
    {
      v34 = *(int *)v33 - v60;
      if ( v34 > 0 )
      {
        *(int *)v33 = v34;
      }
      else
      {
        *(int *)v33 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v35 = (int)&v21->field_F8;
    if ( v21->field_F8 )
    {
      v36 = *(int *)v35 - v60;
      if ( v36 > 0 )
      {
        *(int *)v35 = v36;
      }
      else
      {
        *(int *)v35 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v37 = (int)&v21->field_FC;
    if ( v21->field_FC )
    {
      v38 = *(int *)v37 - v60;
      if ( v38 > 0 )
      {
        *(int *)v37 = v38;
      }
      else
      {
        *(int *)v37 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v39 = (int)&v21->field_100;
    if ( v21->field_100 )
    {
      v40 = *(int *)v39 - v60;
      if ( v40 > 0 )
      {
        *(int *)v39 = v40;
      }
      else
      {
        *(int *)v39 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    v41 = (int)&v21->field_104;
    if ( v21->field_104 )
    {
      v42 = *(int *)v41 - v60;
      if ( v42 > 0 )
      {
        *(int *)v41 = v42;
      }
      else
      {
        *(int *)v41 = 0;
        viewparams->bRedrawGameUI = 1;
      }
    }
    if ( v21->pConditions[2] | v21->pConditions[12] | v21->pConditions[13] | v21->pConditions[14] | v21->pConditions[15] | v21->pConditions[16] )
      --v65;
    v43 = (signed __int64)v21->pPlayerBuffs[7].uExpireTime > 0;

    for (uint k = 0; k < 24; ++k)
      v21->pPlayerBuffs[k]._4585CA(pParty->uTimePlayed);

    if ( v43 && (signed __int64)v21->pPlayerBuffs[7].uExpireTime <= 0 )
      v21->SetCondition(1u, 0);
    ++v62;
  }
  while ( (signed int)v62 <= (signed int)&pPlayers[4] );
  v46 = (signed __int64)pParty->pPartyBuffs[8].uExpireTime > 0;

  for (uint i = 0; i < 20; ++i)
  {
    if (pParty->pPartyBuffs[i]._4585CA(pParty->uTimePlayed) == 1)
      viewparams->bRedrawGameUI = 1;
  }

  if ( v46 && (signed __int64)pParty->pPartyBuffs[8].uExpireTime <= 0 )
  {
    for (uint i = 0; i < 4; ++i)
      pParty->pPlayers[i].SetCondition(1, 0);
  }

  for (uint i = 0; i < 2; ++i)
  {
    auto pBuf = &pParty->pPartyBuffs[dword_4EE07C[i]];
    if (pBuf->uExpireTime == 0)
      continue;

    if ( !(pBuf->uFlags & 1) )
    {
      if (!pPlayers[pBuf->uCaster]->CanAct())
      {
        pBuf->Reset();
        if (dword_4EE07C[i] == 7 )
          pParty->bFlying = false;
      }
    }
  }

  v51 = v65;
  if ( v65 )
    goto LABEL_135;
  if ( pCurrentScreen != SCREEN_REST )
  {
    v52 = (signed int)&pPlayers[1];
    while ( 1 )
    {
      v53 = *(int *)v52;
      if ( *(_QWORD *)(*(int *)v52 + 16) )
        break;
      v52 += 4;
      if ( v52 > (signed int)&pPlayers[4] )
        goto LABEL_135;
    }
    *(int *)(v53 + 16) = 0;
    *(int *)(v53 + 20) = 0;
    v51 = 1;
LABEL_135:
    if ( pCurrentScreen != SCREEN_REST
      && (!v51 || dword_5C35C0) )
      uGameState = 8;
  }
  if ( uActiveCharacter )
  {
    if ( pCurrentScreen != SCREEN_REST )
    {
      v54 = pPlayers[uActiveCharacter];
      if ( v54->pConditions[2]
        || v54->pConditions[12]
        || v54->pConditions[13]
        || v54->pConditions[14]
        || v54->pConditions[15]
        || v54->pConditions[16] )
      {
        viewparams->bRedrawGameUI = 1;
        uActiveCharacter = pParty->GetNextActiveCharacter();
      }
    }
  }
}

//----- (00494820) --------------------------------------------------------
unsigned int __fastcall sub_494820(unsigned int a1)
{
  signed int v1; // eax@1

  v1 = 5;
  if ( a1 % 0x18 >= 5 )
    v1 = 29;
  return v1 - a1 % 0x18;
}

//----- (00494836) --------------------------------------------------------
int stru339_spell_sound::_494836(int uSoundID, int a6)
{
  int v3; // esi@1
  int result; // eax@1
  stru339_spell_sound *v5; // ebx@1
  int *v6; // edi@2
  unsigned int v7; // eax@3
  int v8; // [sp+Ch] [bp-8h]@3
  int v9; // [sp+10h] [bp-4h]@2
  int a2a; // [sp+1Ch] [bp+8h]@1

  v3 = 0;
  result = word_4EE088_sound_ids[uSoundID];
  v5 = this;
  a2a = word_4EE088_sound_ids[uSoundID];
  if ( result )
  {
    v9 = 0;
    v6 = this->pSoundsOffsets;
    do
    {
      v7 = a2a++;
      result = pSoundList->LoadSound(v7, (char *)v5 + v3, 44744 - v3, &v8, a6);
      if ( !result )
        break;
      a6 += 4;
      result = v8 + 256;
      *v6 = v3;
      v3 += result;
      ++v9;
      *(v6 - 2) = result;
      ++v6;
    }
    while ( v9 < 2 );
  }
  return result;
}
// 4EE088: using guessed type __int16 word_4EE088_sound_ids[];



//----- (00494AED) --------------------------------------------------------
unsigned int PlayerFrameTable::GetFrameIdByExpression(CHARACTER_EXPRESSION_ID expression)
{
  unsigned int _uNumFrames; // edx@1
  unsigned int result; // eax@1
  PlayerFrame *v4; // ecx@2

  _uNumFrames = this->uNumFrames;
  result = 0;
  if ( (signed int)this->uNumFrames <= 0 )
  {
LABEL_5:
    result = 0;
  }
  else
  {
    v4 = this->pFrames;
    while ( v4->expression != expression )
    {
      ++result;
      ++v4;
      if ( (signed int)result >= (signed int)_uNumFrames )
        goto LABEL_5;
    }
  }
  return result;
}

//----- (00494B10) --------------------------------------------------------
PlayerFrame *PlayerFrameTable::GetFrameBy_x(unsigned int uFramesetID, unsigned int uFrameID)
{
  unsigned int v3; // esi@1
  PlayerFrame *v4; // edi@1
  PlayerFrame *v5; // ecx@1
  __int16 v6; // dx@2
  int v7; // edx@3
  char *i; // eax@3
  int v9; // ecx@5
  PlayerFrame *result; // eax@6

  v3 = uFramesetID;
  v4 = this->pFrames;
  v5 = &v4[uFramesetID];
  if ( v5->uFlags & 1 && (v6 = v5->uAnimLength) != 0 )
  {
    v7 = ((signed int)uFrameID >> 3) % (unsigned __int16)v6;
    for ( i = (char *)&v5->uAnimTime; ; i += 10 )
    {
      v9 = *(short *)i;
      if ( v7 <= v9 )
        break;
      v7 -= v9;
      ++v3;
    }
    result = &v4[v3];
  }
  else
  {
    result = &v4[uFramesetID];
  }
  return result;
}

//----- (00494B5E) --------------------------------------------------------
PlayerFrame *PlayerFrameTable::GetFrameBy_y(int *a2, int *a3, int a4)
{
  PlayerFrameTable *v4; // edi@1
  int v5; // esi@1
  int v6; // eax@2

  v4 = this;
  v5 = a4 + *a3;
  if ( v5 < 8 * this->pFrames[*a2].uAnimTime )
  {
    *a3 = v5;
  }
  else
  {
    v6 = rand() % 4 + 21;
    *a2 = v6;
    *a3 = 8 * v5 % v4->pFrames[v6].uAnimTime;
  }
  return &v4->pFrames[*a2];
}

//----- (00494BC3) --------------------------------------------------------
void PlayerFrameTable::ToFile()
{
  PlayerFrameTable *v1; // esi@1
  FILE *v2; // eax@1
  FILE *v3; // edi@1

  auto Str = this;

  v1 = Str;
  v2 = fopen("data\\dpft.bin", "wb");
  v3 = v2;
  if ( !v2 )
    Abortf("Unable to save dpft.bin!");
  fwrite(v1, 4u, 1u, v2);
  fwrite(v1->pFrames, 0xAu, v1->uNumFrames, v3);
  fclose(v3);
}

//----- (00494C0F) --------------------------------------------------------
void PlayerFrameTable::FromFile(void *pSerialized)
{
  uNumFrames = *(int *)pSerialized;
  pFrames = (PlayerFrame *)pAllocator->AllocNamedChunk(pFrames, 10 * uNumFrames, "P Frames");
  memcpy(pFrames, (char *)pSerialized + 4, 10 * uNumFrames);
}

//----- (00494C5A) --------------------------------------------------------
int PlayerFrameTable::FromFileTxt(const char *Args)
{
  PlayerFrameTable *v2; // ebx@1
  FILE *v3; // eax@1
  int v4; // esi@3
  void *v5; // eax@10
  FILE *v6; // ST0C_4@12
  char *i; // eax@12
  __int16 v8; // ax@15
  const char *v9; // ST10_4@15
  unsigned __int16 v10; // ax@15
  const char *v11; // ST0C_4@15
  int j; // esi@15
  int v13; // eax@17
  int v14; // edx@22
  int v15; // ecx@23
  int v16; // eax@24
  signed int k; // eax@27
  PlayerFrame *v18; // edx@28
  int v19; // esi@28
  int l; // ecx@29
  char Buf; // [sp+Ch] [bp-2F8h]@3
  FrameTableTxtLine v23; // [sp+200h] [bp-104h]@4
  FrameTableTxtLine v24; // [sp+27Ch] [bp-88h]@4
  int v25; // [sp+2F8h] [bp-Ch]@3
  int v26; // [sp+2FCh] [bp-8h]@3
  FILE *File; // [sp+300h] [bp-4h]@1
  int Argsa; // [sp+30Ch] [bp+8h]@28

  v2 = this;
  //TileTable::dtor((TileTable *)this);
  v3 = fopen(Args, "r");
  File = v3;
  if ( !v3 )
    Abortf("PlayerFrameTable::load - Unable to open file: %s.", Args);
  v4 = 0;
  v25 = 0;
  v26 = 1;
  if ( fgets(&Buf, 490, v3) )
  {
    do
    {
      *strchr(&Buf, 10) = 0;
      memcpy(&v24, texture_frame_table_txt_parser(&Buf, &v23), sizeof(v24));
      if ( v24.field_0 && *v24.pProperties[0] != 47 )
      {
        if ( v24.field_0 < 3 )
          Abortf("PlayerFrameTable::load, too few arguments, %s line %i.", Args, v26);
        ++v25;
      }
      ++v26;
    }
    while ( fgets(&Buf, 490, File) );
    v4 = v25;
  }
  v2->uNumFrames = v4;
  v5 = pAllocator->AllocNamedChunk(v2->pFrames, 10 * v4, "P Frames");
  v2->pFrames = (PlayerFrame *)v5;
  if ( !v5 )
    Abortf("PlayerFrameTable::load - Out of Memory!");
  v6 = File;
  v2->uNumFrames = 0;
  fseek(v6, 0, 0);
  for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
  {
    *strchr(&Buf, 10) = 0;
    memcpy(&v24, texture_frame_table_txt_parser(&Buf, &v23), sizeof(v24));
    if ( v24.field_0 && *v24.pProperties[0] != 47 )
    {
      v8 = atoi(v24.pProperties[0]);
      v9 = v24.pProperties[1];
      v2->pFrames[v2->uNumFrames].expression = (CHARACTER_EXPRESSION_ID)v8;
      v10 = atoi(v9);
      v11 = v24.pProperties[2];
      v2->pFrames[v2->uNumFrames].uTextureID = v10;
      v2->pFrames[v2->uNumFrames].uAnimTime = atoi(v11);
      v2->pFrames[v2->uNumFrames].uAnimLength = 0;
      v2->pFrames[v2->uNumFrames].uFlags = 0;
      for ( j = 3; j < v24.field_0; ++j )
      {
        if ( !_strcmpi(v24.pProperties[j], "New") )
        {
          v13 = (int)&v2->pFrames[v2->uNumFrames].uFlags;
          *(char *)v13 |= 4u;
        }
      }
      ++v2->uNumFrames;
    }
  }
  fclose(File);
  v14 = 0;
  if ( (signed int)(v2->uNumFrames - 1) > 0 )
  {
    v15 = 0;
    do
    {
      v16 = (int)&v2->pFrames[v15];
      if ( !(*(char *)(v16 + 18) & 4) )
        *(char *)(v16 + 8) |= 1u;
      ++v14;
      ++v15;
    }
    while ( v14 < (signed int)(v2->uNumFrames - 1) );
  }
  for ( k = 0; k < (signed int)v2->uNumFrames; *(short *)(Argsa + 6) = v19 )
  {
    v18 = v2->pFrames;
    Argsa = (int)&v18[k];
    v19 = *(short *)(Argsa + 4);
    if ( *(char *)(Argsa + 8) & 1 )
    {
      ++k;
      for ( l = (int)&v18[k]; *(char *)(l + 8) & 1; l += 10 )
      {
        v19 += *(short *)(l + 4);
        ++k;
      }
      LOWORD(v19) = v18[k].uAnimTime + v19;
    }
    ++k;
  }
  return 1;
}

//----- (00494F3A) --------------------------------------------------------
unsigned int IconFrameTable::FindIcon(const char *pIconName)
{
  IconFrameTable *v2; // esi@1
  int v3; // ebx@1
  unsigned int uID; // edi@1
  unsigned int result; // eax@4

  v2 = this;
  v3 = 0;
  uID = 0;
  if ( (signed int)this->uNumIcons <= 0 )
  {
LABEL_4:
    result = 0;
  }
  else
  {
    while ( _strcmpi(pIconName, v2->pIcons[v3].pAnimationName) )
    {
      ++uID;
      ++v3;
      if ( (signed int)uID >= (signed int)v2->uNumIcons )
        goto LABEL_4;
    }
    result = uID;
  }
  return result;
}

//----- (00494F70) --------------------------------------------------------
IconFrame *IconFrameTable::GetFrame(unsigned int uIconID, unsigned int uFrameID)
{
  IconFrame *v3; // edi@1
  IconFrame *v4; // ecx@1
  __int16 v5; // dx@2
  int v6; // edx@3
  unsigned int v7; // eax@3
  char *i; // ecx@3
  int v9; // esi@5
  IconFrame *result; // eax@6

  v3 = this->pIcons;
  v4 = &v3[uIconID];
  if ( v4->uFlags & 1 && (v5 = v4->uAnimLength) != 0 )
  {
    v6 = ((signed int)uFrameID >> 3) % (unsigned __int16)v5;
    v7 = uIconID;
    for ( i = (char *)&v4->uAnimTime; ; i += 32 )
    {
      v9 = *(short *)i;
      if ( v6 <= v9 )
        break;
      v6 -= v9;
      ++v7;
    }
    result = &v3[v7];
  }
  else
  {
    result = &v3[uIconID];
  }
  return result;
}

//----- (00494FBF) --------------------------------------------------------
void IconFrameTable::InitializeAnimation(unsigned int uIconID)
{
  IconFrameTable *v2; // esi@1
  unsigned int v3; // edi@3
  const char *i; // eax@3
  IconFrame *v5; // eax@5

  v2 = this;
  if ( (signed int)uIconID <= (signed int)this->uNumIcons && (uIconID & 0x80000000u) == 0 )
  {
    v3 = uIconID;
    for ( i = this->pIcons[uIconID].pTextureName; ; i = v5[v3].pTextureName )
    {
      v2->pIcons[v3].uTextureID = pIcons_LOD->LoadTexture(i, TEXTURE_16BIT_PALETTE);
      v5 = v2->pIcons;
      if ( !(v5[v3].uFlags & 1) )
        break;
      ++v3;
    }
  }
}

//----- (0049500A) --------------------------------------------------------
void IconFrameTable::ToFile()
{
  IconFrameTable *v1; // esi@1
  FILE *v2; // eax@1
  FILE *v3; // edi@1

  auto Str = this;

  v1 = Str;
  v2 = fopen("data\\dift.bin", "wb");
  v3 = v2;
  if ( !v2 )
    Abortf("Unable to save dift.bin!");
  fwrite(v1, 4u, 1u, v2);
  fwrite(v1->pIcons, 0x20u, v1->uNumIcons, v3);
  fclose(v3);
}

//----- (00495056) --------------------------------------------------------
void IconFrameTable::FromFile(void *pSerialized)
{
  uNumIcons = *(int *)pSerialized;
  pIcons = (IconFrame *)pAllocator->AllocNamedChunk(pIcons, 32 * uNumIcons, "I Frames");
  memcpy(pIcons, (char *)pSerialized + 4, 32 * uNumIcons);
}

//----- (0049509D) --------------------------------------------------------
int IconFrameTable::FromFileTxt(const char *Args)
{
  IconFrameTable *v2; // ebx@1
  FILE *v3; // eax@1
  int v4; // esi@3
  void *v5; // eax@10
  FILE *v6; // ST0C_4@12
  char *i; // eax@12
  const char *v8; // ST00_4@15
  int v9; // eax@16
  int v10; // edx@20
  int v11; // ecx@21
  int v12; // eax@22
  signed int j; // edx@25
  IconFrame *v14; // ecx@26
  int v15; // esi@26
  int k; // eax@27
  signed int result; // eax@11
  char Buf; // [sp+Ch] [bp-2F8h]@3
  FrameTableTxtLine v19; // [sp+200h] [bp-104h]@4
  FrameTableTxtLine v20; // [sp+27Ch] [bp-88h]@4
  int v21; // [sp+2F8h] [bp-Ch]@3
  int v22; // [sp+2FCh] [bp-8h]@3
  FILE *File; // [sp+300h] [bp-4h]@1
  int Argsa; // [sp+30Ch] [bp+8h]@26

  v2 = this;
  //TileTable::dtor((TileTable *)this);
  v3 = fopen(Args, "r");
  File = v3;
  if ( !v3 )
    Abortf("IconFrameTable::load - Unable to open file: %s.", Args);
  v4 = 0;
  v21 = 0;
  v22 = 1;
  if ( fgets(&Buf, 490, v3) )
  {
    do
    {
      *strchr(&Buf, 10) = 0;
      memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20));
      if ( v20.field_0 && *v20.pProperties[0] != 47 )
      {
        if ( v20.field_0 < 3 )
          Abortf("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22);
        ++v21;
      }
      ++v22;
    }
    while ( fgets(&Buf, 490, File) );
    v4 = v21;
  }
  v2->uNumIcons = v4;
  v5 = pAllocator->AllocNamedChunk(v2->pIcons, 32 * v4, "I Frames");
  v2->pIcons = (IconFrame *)v5;
  if ( v5 )
  {
    v6 = File;
    v2->uNumIcons = 0;
    fseek(v6, 0, 0);
    for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
    {
      *strchr(&Buf, 10) = 0;
      memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20));
      if ( v20.field_0 && *v20.pProperties[0] != 47 )
      {
        strcpy(v2->pIcons[v2->uNumIcons].pAnimationName, v20.pProperties[0]);
        strcpy(v2->pIcons[v2->uNumIcons].pTextureName, v20.pProperties[1]);
        v8 = v20.pProperties[2];
        v2->pIcons[v2->uNumIcons].uFlags = 0;
        if ( !_strcmpi(v8, "new") )
        {
          v9 = (int)&v2->pIcons[v2->uNumIcons].uFlags;
          *(char *)v9 |= 4u;
        }
        v2->pIcons[v2->uNumIcons].uAnimTime = atoi(v20.pProperties[3]);
        v2->pIcons[v2->uNumIcons].uAnimLength = 0;
        v2->pIcons[v2->uNumIcons++].uTextureID = 0;
      }
    }
    fclose(File);
    v10 = 0;
    if ( (signed int)(v2->uNumIcons - 1) > 0 )
    {
      v11 = 0;
      do
      {
        v12 = (int)&v2->pIcons[v11];
        if ( !(*(char *)(v12 + 60) & 4) )
          *(char *)(v12 + 28) |= 1u;
        ++v10;
        ++v11;
      }
      while ( v10 < (signed int)(v2->uNumIcons - 1) );
    }
    for ( j = 0; j < (signed int)v2->uNumIcons; *(short *)(Argsa + 26) = v15 )
    {
      v14 = v2->pIcons;
      Argsa = (int)&v14[j];
      v15 = *(short *)(Argsa + 24);
      if ( *(char *)(Argsa + 28) & 1 )
      {
        ++j;
        for ( k = (int)&v14[j]; *(char *)(k + 28) & 1; k += 32 )
        {
          v15 += *(short *)(k + 24);
          ++j;
        }
        LOWORD(v15) = v14[j].uAnimTime + v15;
      }
      ++j;
    }
    result = 1;
  }
  else
  {
    fclose(File);
    result = 0;
  }
  return result;
}



//----- (00495366) --------------------------------------------------------
char *__fastcall sub_495366(unsigned __int8 a1, unsigned __int8 a2)
{
  int v2; // edi@1
  int v3; // edx@2
  int v4; // esi@3
  int v5; // ebx@5
  signed int v7; // [sp+Ch] [bp-14h]@1
  signed int v8; // [sp+10h] [bp-10h]@1
  int **v9; // [sp+14h] [bp-Ch]@4
  signed int v10; // [sp+18h] [bp-8h]@3
  unsigned __int8 v11; // [sp+1Ch] [bp-4h]@1

  v2 = a1;
  v11 = a2;
  v8 = 0;
  v7 = 0;
  if ( dword_AE336C == a1 )
  {
    v3 = dword_AE3370;
  }
  else
  {
    v4 = a2;
    dword_AE336C = a1;
    v10 = 0;
    if ( (signed int)pNPCStats->uNumNPCNames[v4] <= 0 )
      goto LABEL_17;
    v9 = (int **)((char *)pNPCStats->pNPCNames + v4 * 4);
    do
    {
      v5 = tolower(*(char *)*v9);
      if ( v5 == tolower(v2) )
      {
        if ( v8 )
          v7 = v10;
        else
          v8 = v10;
      }
      ++v10;
      v9 += 2;
    }
    while ( v10 < (signed int)pNPCStats->uNumNPCNames[v4] );
    if ( v8 && v8 != v7 )
      v3 = v8 + rand() % (v7 - v8);
    else
LABEL_17:
      v3 = rand() % (signed int)pNPCStats->uNumNPCNames[v4];
  }
  dword_AE3370 = v3;
  return pNPCStats->pNPCNames[0][v11 + 2 * v3];
}
// AE336C: using guessed type int dword_AE336C;
// AE3370: using guessed type int dword_AE3370;

//----- (00495430) --------------------------------------------------------
char *__fastcall GetReputationString(signed int a1)
{
  char *result; // eax@2

  if ( a1 < 25 )
  {
    if ( a1 < 6 )
    {
      if ( a1 < -5 )
      {
        result = pGlobalTXT_LocalizationStrings[402];
        if ( a1 < -24 )
          result = pGlobalTXT_LocalizationStrings[434];
      }
      else
      {
        result = pGlobalTXT_LocalizationStrings[399];
      }
    }
    else
    {
      result = pGlobalTXT_LocalizationStrings[392];
    }
  }
  else
  {
    result = pGlobalTXT_LocalizationStrings[379];
  }
  return result;
}

//----- (00495461) --------------------------------------------------------
char *BuilDialogueString(char *lpsz, unsigned __int8 uPlayerID, ItemGen *a3, char *a4, int a5, __int64 *a6)
{
  unsigned __int8 v6; // bl@1
  Player *pPlayer; // ebx@3
  //NPCData *v9; // eax@4
  //size_t v10; // eax@6
  char *v11; // esi@7
  //int v12; // edx@7
  //ItemGen *v13; // edi@7
  //char v14; // cl@8
  //char *v15; // ecx@10
  //int v16; // edx@10
  int v17; // eax@10
  signed __int64 v18; // qax@18
  unsigned int v19; // edi@32
  unsigned __int8 *v20; // ebx@32
  int v21; // ecx@34
  __int16 v22; // ax@34
  int v23; // edx@39
  int v24; // eax@39
  int v25; // eax@45
  float *v26; // esi@68
  float v27; // ST18_4@68
  signed int v28; // eax@68
  int v29; // eax@68
  float v30; // ST18_4@72
  signed int v31; // eax@72
  float v32; // ST18_4@74
  signed int v33; // eax@74
  double v34; // st7@75
  float v35; // ST18_4@76
  signed int v36; // eax@76
  float *v37; // esi@78
  float v38; // ST18_4@78
  int v39; // eax@78
  float v40; // ST18_4@82
  int v41; // eax@82
  float v42; // ST18_4@83
  int v43; // eax@83
  float v44; // ST18_4@85
  int v45; // eax@85
  const char *v46; // eax@86
  unsigned int v47; // eax@87
  float v48; // ST18_4@97
  __int64 v49; // ST14_8@107
  int v50; // eax@107
  int v51; // eax@108
  Player *v52; // eax@109
  int v53; // [sp-4h] [bp-13Ch]@107
  int v54; // [sp+0h] [bp-138h]@107
  __int16 v55[56]; // [sp+10h] [bp-128h]@34
  stru351_summoned_item v56; // [sp+80h] [bp-B8h]@107
  stru351_summoned_item v57; // [sp+9Ch] [bp-9Ch]@115
  char a1[100]; // [sp+B8h] [bp-80h]@3
  unsigned int v59; // [sp+11Ch] [bp-1Ch]@3
  //size_t v60; // [sp+120h] [bp-18h]@3
  //Player *v61; // [sp+124h] [bp-14h]@3
  //char *Str; // [sp+128h] [bp-10h]@1
  int v63; // [sp+12Ch] [bp-Ch]@32
  //int v64; // [sp+130h] [bp-8h]@6
  //NPCData *v65; // [sp+134h] [bp-4h]@6
  //int packed;



  v6 = uPlayerID;
  //Str = lpsz;
  if ( IsBadStringPtrA(lpsz, 1u) )
    return "Invalid String Passed";

  a1[0] = 0;
  pPlayer = &pParty->pPlayers[v6];
  v59 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(255, 255, 155);
  //v61 = pPlayer;
  memset(pTmpBuf2, 0, sizeof(pTmpBuf2));

  NPCData *npc = nullptr;
  if ( dword_5C35D4 )
  {
    //__debugbreak(); // fix  
    npc = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) - 1)];
  }
  else
    npc = GetNPCData(uDialogue_SpeakingActorNPC_ID);
  //v65 = v9;
  //v10 = 0;
  //v64 = 0;

  //int i = 0;
  //if ( (signed int)v60 > 0 )
  v11 = a4;

  auto len = strlen(lpsz);
  for (int i = 0, dst = 0; i < len; ++i)
  {
    //v12 = v64;
    //v13 = a3;
    //while ( 1 )
    //{
    char c = lpsz[i];
    if (c != '%')
      pTmpBuf2[dst++] = c;
    else
    {
        //v15 = &lpsz[v12 + 1];
        //v16 = (unsigned __int8)lpsz[v12 + 2];
        //packed = 10 * (int)lpsz[v12 + 1] + lpsz[v12 + 2];
        //v17 = packed - 528;// 10 * '0' + '0'
      v17 = 10 * (int)(lpsz[i + 1] - '0') + lpsz[i + 2] - '0';

      switch ( v17 )
      {
        case 1:
          v11 = npc->pName;
        goto _continue_strcat;
          case 2:
            v11 = pPlayer->pName;
            goto _continue_strcat;
          case 3:
          case 4:
            v11 = a1;
            goto _continue_strcat;
          case 5:
            v18 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60 / 60 % 24;
            v11 = pGlobalTXT_LocalizationStrings[397];// "evening"
            if ( SHIDWORD(v18) <= 0 && SHIDWORD(v18) >= 0 && (unsigned int)v18 >= 5 && SHIDWORD(v18) <= 0 )
            {
              if ( SHIDWORD(v18) >= 0 && (unsigned int)v18 >= 0xB )
              {
                if ( v18 < 20 )
                  v11 = pGlobalTXT_LocalizationStrings[396];// "day"
              }
              else
              {
                v11 = pGlobalTXT_LocalizationStrings[395];// "morning"
              }
            }
            goto _continue_strcat;
          case 6:
            if ( pPlayer->uSex )
              v11 = pGlobalTXT_LocalizationStrings[387];// "lady"
            else
              v11 = pGlobalTXT_LocalizationStrings[385];// "sir"
            goto _continue_strcat;
          case 7:
            if ( pPlayer->uSex )
              v11 = pGlobalTXT_LocalizationStrings[389];// "Lady"
            else
              v11 = pGlobalTXT_LocalizationStrings[386];// "Sir"
            goto _continue_strcat;
          case 8:
            v19 = 0;
            v63 = 0;
            v20 = (unsigned __int8 *)pPlayer->field_152;
            do
            {
              if ( (unsigned __int16)_449B57_test_bit(v20, word_4EE150[v19]) )
              {
                v21 = v63;
                v22 = word_4EE150[v19];
                ++v63;
                v55[v21] = v22;
              }
              ++v19;
            }
            while ( v19 < 28 );
            if ( v63 )
            {
              v23 = rand() % v63;
              v24 = dword_A74CDC;
              if ( dword_A74CDC == -1 )
              {
                v24 = v23;
                dword_A74CDC = v23;
              }
              v11 = (char *)pAwards[v55[v24]-1].pText;//(char *)dword_723E80_award_related[2 * v55[v24]];
            }
            else
            {
              v11 = (char *)pNPCTopics[55].pText;
            }
            //pPlayer = v61;
            //v13 = a3;
            goto _continue_strcat;
          case 9:
            if ( npc->uSex )
              v11 = pGlobalTXT_LocalizationStrings[384];// "her"
            else
              v11 = pGlobalTXT_LocalizationStrings[383];// "his"
            goto _continue_strcat;
          case 10:
            if ( pPlayer->uSex )
              v11 = pGlobalTXT_LocalizationStrings[389];// "Lady"
            else
              v11 = pGlobalTXT_LocalizationStrings[388];// "Lord"
            goto _continue_strcat;
          case 11:
            v25 = GetPartyReputation();
            goto LABEL_46;
          case 12:
            v25 = npc->rep;
LABEL_46:
            if ( v25 >= 25 )
            {
              v11 = pGlobalTXT_LocalizationStrings[379];
            }
            else
            {
              if ( v25 < 6 )
              {
                if ( v25 >= -5 )
                {
                  v11 = pGlobalTXT_LocalizationStrings[399];
                }
                else
                {
                  if ( v25 < -24 )
                    v11 = pGlobalTXT_LocalizationStrings[434];
                  else
                    v11 = pGlobalTXT_LocalizationStrings[402];
                }
              }
              else
              {
                v11 = pGlobalTXT_LocalizationStrings[392];
              }
            }
            goto _continue_strcat;
          case 13:
            v11 = sub_495366(pPlayer->pName[0], pPlayer->uSex);
            goto _continue_strcat;
          case 14:
            {
              if ( npc->uSex )
                v11 = pGlobalTXT_LocalizationStrings[391];// "sister"
              else
                v11 = pGlobalTXT_LocalizationStrings[390];// "brother"
              goto _continue_strcat;
            }

          case 15:
          {
            v11 = pGlobalTXT_LocalizationStrings[393];// "daughter"
_continue_strcat:
            strcat(pTmpBuf2, v11);
            dst = strlen(pTmpBuf2);
            //v64 += 2;
            i += 2;
          }
          break;

          case 16:
          {
            if ( npc->uSex )
              v11 = pGlobalTXT_LocalizationStrings[391];// "sister"
            else
              v11 = pGlobalTXT_LocalizationStrings[390];// "brother"
            goto _continue_strcat;
          }
          case 17:
          {
            auto pay_percentage = pNPCStats->pProfessions[npc->uProfession - 1].uHirePrice / 100;
            if (!pay_percentage)
              pay_percentage = 1;

            sprintf(a1, "%lu", pay_percentage);
            v11 = a1;
            goto _continue_strcat;
          }

          case 18:
          case 19:
          case 20:
          case 21:
          case 22:
          case 26:
_continue_strncpy:
            strncpy(a1, lpsz + i + 1, 2);
          v51 = atoi(a1);
          sprintf(a1, "%lu", v51);
          v11 = a1;
          goto _continue_strcat;

          case 23:
          {
            v47 = pMapStats->GetMapInfo(pCurrentMapName);
            if ( v47 )
              v11 = pMapStats->pInfos[v47].pName;
            else
              v11 = pGlobalTXT_LocalizationStrings[394];// "Unknown"
            goto _continue_strcat;
          }
          case 24:
          {
            v46 = a3->GetDisplayName();
            sprintf(a1, format_4E2D80, v59, v46);
            v11 = a1;
            goto _continue_strcat;
          }


          case 25:
          {
            v37 = &p2DEvents[(signed int)a4 - 1].fPriceMultiplier;
            v38 = *v37;
            v39 = a3->GetValue();
            v29 = pPlayer->_4B8233(v39, v38);
          switch ( a5 )
          {
            case 3:
              v44 = *v37;
              v45 = a3->GetValue();
              v29 = pPlayer->_4B8213(v45, v44);
              break;
            case 4:
              v29 = pPlayer->_4B824B(*v37);
              break;
            case 5:
              v42 = *v37;
              v43 = a3->GetValue();
              v29 = pPlayer->_4B8265(v43, v42);
              break;
            case 6:
              v40 = *v37;
              v41 = a3->GetValue();
              v29 = pPlayer->_4B8213(v41, v40) / 2;
              break;
            }
            goto _continue_sprintf;
          }

          case 27:
          {
                    v26 = &p2DEvents[(signed int)a4 - 1].fPriceMultiplier;
        v27 = *v26;
        v28 = a3->GetValue();
        v29 = pPlayer->_4B8142(v28, v27);
        if ( a5 == 3 )
        {
          v35 = *v26;
          v36 = a3->GetValue();
          v29 = pPlayer->_4B8102(v36, v35);
          if (a3->Broken())
            v29 = 1;
          goto _continue_sprintf;
        }
        if ( a5 != 4 )
        {
          if ( a5 == 5 )
          {
            v32 = *v26;
            v33 = a3->GetValue();
            v29 = pPlayer->_4B81C3(v33, v32);
          }
          else
          {
            if ( a5 == 6 )
            {
              v30 = *v26;
              v31 = a3->GetValue();
              v29 = pPlayer->_4B8102(v31, v30) / 2;
              if (a3->Broken())
                v29 = 1;
              if (!v29)
                v29 = 1;
              goto _continue_sprintf;
            }
          }
_continue_sprintf:
          sprintf(a1, "%lu", v29);
          v11 = a1;
          goto _continue_strcat;
        }
        v34 = *v26;

      v48 = v34;
      v29 = pPlayer->_4B8179(v48);
      goto _continue_sprintf;
          }

          case 28:
          {
            //v11 = (char *)p2DEvents_minus1__10[13 * (signed int)a4];
            v11 = (char *)p2DEvents[(signed int)a4 - 1].pProprieterTitle;
            goto _continue_strcat;
          }

          case 29:
          {
            //v34 = p2DEvents_minus1__20[13 * (signed int)a4];
            v34 = p2DEvents[(signed int)a4 - 1].fPriceMultiplier;
            v48 = v34;
            v29 = pPlayer->_4B8179(v48);
            goto _continue_sprintf;
          }

          case 30:
          {
                if ( !a6 )
      goto _continue_strcat;
    sub_493F79(&v57, *a6);
    v54 = v57.field_18_expire_year;
    v53 = v57.field_C_expire_day + 1;
    v50 = v57.field_14_exprie_month;
    sprintf(a1, pGlobalTXT_LocalizationStrings[378], aMonthNames[v50], v53, v54);
    v11 = a1;
    goto _continue_strcat;
          }

          case 31:
          case 32:
          case 33:
          case 34:
            v52 = &pParty->pPlayers[v17 - 31];
            v11 = v52->pName;
            goto _continue_strcat;

          default:
            if ( v17 <= 50 || v17 > 70 )
              goto _continue_strncpy;
            if ( v17 - 51 >= 20 )
              goto _continue_strcat;
            HIDWORD(v49) = pParty->field_3C.field_440[2 * v17 + 1];
            LODWORD(v49) = pParty->field_3C.field_440[2 * v17];
            sub_493F79(&v56, v49);
            v54 = v56.field_18_expire_year;
            v53 = v56.field_C_expire_day + 1;
            v50 = v56.field_14_exprie_month;
            sprintf(a1, pGlobalTXT_LocalizationStrings[378], aMonthNames[v50], v53, v54);
            v11 = a1;
            goto _continue_strcat;
        }
      }
  }
  return pTmpBuf2;
}

//----- (00495B39) --------------------------------------------------------
void __cdecl PlayerCreationUI_Draw()
{
  const char *uTitleText; // ST10_4@3
  int pTextCenter; // eax@3
  IconFrame *v3; // eax@3
  int v4; // ecx@7
  GUIButton *uPosActiveItem; // edi@12
  int v6; // esi@14
  int uNumLet; // eax@14
  char v8; // al@17
  int v9; // ecx@17
  char v10; // sf@17
  int v11; // ecx@19
  void *v12; // eax@20
  int v13; // ecx@21
  int v14; // ecx@22
  char *v15; // ST14_4@24
  size_t v16; // eax@28
  int v17; // eax@33
  //enum CHARACTER_RACE uNumRace; // eax@35
  int v19; // eax@36
  int v20; // eax@37
  int uNumMight; // eax@44
  unsigned int v24; // eax@44
  int v25; // eax@44
  unsigned int v26; // eax@44
  int v27; // eax@44
  unsigned int v28; // eax@44
  int v29; // eax@44
  unsigned int v30; // eax@44
  int v31; // eax@44
  unsigned int v32; // eax@44
  int v33; // eax@44
  unsigned int v34; // eax@44
  int v35; // eax@44
  unsigned int v36; // eax@44
  enum PLAYER_SKILL_TYPE v37; // eax@44
  enum PLAYER_SKILL_TYPE v39; // eax@44
  enum PLAYER_SKILL_TYPE v41; // eax@44
  const char *v42; // edx@44
  char *v43; // ST1C_4@44
  int v45; // eax@44
  enum PLAYER_SKILL_TYPE v46; // eax@46
  const char *v47; // edx@46
  char *v48; // ST1C_4@46
  int v50; // eax@46
  int v51; // eax@49
  char *v52; // edi@52
  char v53; // al@52
  PLAYER_CLASS_TYPE uClassType; // edi@53
  int v55; // ST0C_4@53
  int v57; // eax@53
  int v61; // ecx@55
  int v64; // ST08_4@57
  int v66; // ecx@57
  int v71; // eax@59
  int v75; // eax@61
  int v80; // eax@63
  int v85; // eax@65
  int v89; // eax@67
  int v94; // eax@69
  enum PLAYER_SKILL_TYPE pSkillId; // edi@72
  size_t pLenText; // eax@72
  signed int v104; // ecx@72
  int pColorText; // ecx@79
  unsigned int v107; // ST0C_4@81
  int pTextY; // ST08_4@81
  int v111; // ST0C_4@82
  signed int v113; // edi@82
  int v114; // ST0C_4@82
  const char *uRaceName; // [sp+0h] [bp-170h]@39
  char pText[200]; // [sp+10h] [bp-160h]@14
  GUIWindow pWindow; // [sp+D8h] [bp-98h]@83
  int v119; // [sp+12Ch] [bp-44h]@18
  size_t v120; // [sp+130h] [bp-40h]@25
  int uY; // [sp+134h] [bp-3Ch]@18
  int v122; // [sp+138h] [bp-38h]@18
  int v123; // [sp+13Ch] [bp-34h]@11
  void *v124; // [sp+140h] [bp-30h]@18
  int uColor1; // [sp+144h] [bp-2Ch]@1
  int v126; // [sp+148h] [bp-28h]@25
  int uColorGreen; // [sp+14Ch] [bp-24h]@1
  int v128; // [sp+150h] [bp-20h]@14
  int v129; // [sp+154h] [bp-1Ch]@18
  int uColorTeal; // [sp+158h] [bp-18h]@1
  int uColorWhite; // [sp+15Ch] [bp-14h]@1
  int uX; // [sp+160h] [bp-10h]@18
  unsigned int v133; // [sp+164h] [bp-Ch]@25
  int pOrder; // [sp+168h] [bp-8h]@14
  //char *Str; // [sp+16Ch] [bp-4h]@18
  //Player *pPlayer;
  const char *pSkillName;

  uColor1 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xD1, 0xBB, 0x61);
  uColorTeal = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0, 0xF7, 0xF7);
  uColorGreen = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0, 0xFF, 0);
  uColorWhite = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFF, 0xFF, 0xFF);
  pRenderer->BeginScene();
  pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
  uPlayerCreationUI_SkySliderPos = (GetTickCount() % 12800) / 20;
  pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos, 2, pTexture_MAKESKY);
  pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos - 640, 2, pTexture_MAKESKY);
  //if (uPlayerCreationUI_SkySliderPos > 640)
    //uPlayerCreationUI_SkySliderPos = 0;
  pRenderer->DrawTextureTransparent(0, 0, pTexture_MAKETOP);
  uTitleText = pGlobalTXT_LocalizationStrings[51];
  uPlayerCreationUI_SelectedCharacter = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem) / 7;
  pTextCenter = pFontCChar->AlignText_Center(640, pGlobalTXT_LocalizationStrings[51]);
  pGUIWindow_CurrentMenu->DrawText(pFontCChar, pTextCenter + 1, 0, 0, uTitleText, 0, 0, 0);
  pRenderer->DrawTextureTransparent(17, 35, pPlayerPortraits[pParty->pPlayers[0].uFace]);
  pRenderer->DrawTextureTransparent(176, 35, pPlayerPortraits[pParty->pPlayers[1].uFace]);
  pRenderer->DrawTextureTransparent(335, 35, pPlayerPortraits[pParty->pPlayers[2].uFace]);
  pRenderer->DrawTextureTransparent(494, 35, pPlayerPortraits[pParty->pPlayers[3].uFace]);
  v3 = pIconsFrameTable->GetFrame(uIconID_CharacterFrame, pEventTimer->uStartTime);
  if ( uPlayerCreationUI_SelectedCharacter )
  {
    switch ( uPlayerCreationUI_SelectedCharacter )
    {
      case 1:
        v4 = 171;
        break;
      case 2:
        v4 = 329;
        break;
      case 3:
        v4 = 488;
        break;
      default:
        v4 = v123;
        break;
    }
  }
  else
  {
    v4 = 12;
  }

  pRenderer->DrawTextureTransparent(v4, 29, &pIcons_LOD->pTextures[v3->uTextureID]);
  uPosActiveItem = pGUIWindow_CurrentMenu->GetControl(pGUIWindow_CurrentMenu->pCurrentPosActiveItem);
  uPlayerCreationUI_ArrowAnim = 19 - (GetTickCount() % 500) / 25;
  pRenderer->DrawTextureTransparent(uPosActiveItem->uZ - 4, uPosActiveItem->uY, pTextures_arrowl[uPlayerCreationUI_ArrowAnim]);
  pRenderer->DrawTextureTransparent(uPosActiveItem->uX - 12, uPosActiveItem->uY, pTextures_arrowr[uPlayerCreationUI_ArrowAnim]);
  //if (uPlayerCreationUI_ArrowAnim < 0)
  //  uPlayerCreationUI_ArrowAnim = 18;
  v6 = pFontCreate->uFontHeight - 2;
  v128 = pFontCreate->uFontHeight - 2;
  memset(pText, 0, 200);
  strcpy(pText, pGlobalTXT_LocalizationStrings[205]);// "Skills"
  uNumLet = strlen(pText) - 1;
  pOrder = uNumLet;
  if ( uNumLet >= 0 )
  {
    while ( 1 )
    {
      v8 = toupper((unsigned __int8)pText[uNumLet]);
      v9 = pOrder;
      v10 = pOrder-- - 1 < 0;
      pText[v9] = v8;
      if ( v10 )
        break;
      uNumLet = pOrder;
    }
  }
  pOrder = 18;
  v124 = 0;
  uX = 32;
  uY = 3 * v6 + 169;
  v122 = 5 * v6 + 169;
  v123 = 3 * v6 + 311;
  v129 = 493;
  //pPlayer = pParty->pPlayers;
  v119 = 6 * v6 + 169;
  //do

  //for ( pPlayer = pParty->pPlayers; (signed int)pPlayer->pName < (signed int)&pParty->pPickedItem.uNumCharges; pPlayer++)
  for (int i = 0; i < 4; ++i)
  {
    auto player = pParty->pPlayers + i;

    //Str = pPlayer->pName;
	pGUIWindow_CurrentMenu->DrawText(pFontCreate, pOrder + 73, 100, 0, pClassNames[player->classType], 0, 0, 0);
    pRenderer->DrawTextureTransparent(pOrder + 77, 50, pTexture_IC_KNIGHT[player->classType / 4]);
    v11 = pGUIWindow_CurrentMenu->field_40;
    if ( v11 && (v12 = pGUIWindow_CurrentMenu->ptr_1C, v12 == v124) )
    {
      v13 = v11 - 1;
      if ( v13 )
      {
        v14 = v13 - 1;
        if ( v14 )
        {
          if ( v14 == 1 )
          {
            pGUIWindow_CurrentMenu->field_40 = 0;
            pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, pOrder, 124, 0, player->pName, 130, 0);
            SetCurrentMenuID(MENU_NAMEPANELESC);
          }
        }
        else
        {
          pGUIWindow_CurrentMenu->field_40 = 0;
          v120 = strlen((const char *)pKeyActionMap->pPressedKeysBuffer);
          v126 = 0;
          v133 = 0;
          if ( strlen((const char *)pKeyActionMap->pPressedKeysBuffer) )//edit name
          {
            do
            {
              if ( pKeyActionMap->pPressedKeysBuffer[v133] == ' ' )
                ++v126;
              ++v133;
              v16 = strlen((const char *)pKeyActionMap->pPressedKeysBuffer);
            }
            while ( v133 < v16 );
          }
          if ( v120 && v126 != v120 )
            strcpy(player->pName, (const char *)pKeyActionMap->pPressedKeysBuffer);
          pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, pOrder, 0x7C, 0, player->pName, 130, 0);
          *(short *)&player->field_1988[27] = 1; //
        }
      }
      else
      {
        v17 = pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, 159 * (int)v12 + 18, 0x7Cu, 0, (const char *)pKeyActionMap->pPressedKeysBuffer, 120, 1);
        pGUIWindow_CurrentMenu->DrawFlashingInputCursor(159 * (unsigned int)pGUIWindow_CurrentMenu->ptr_1C + v17 + 20, 124, pFontCreate);
      }
    }
    else
    {
      pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, pOrder, 0x7C, 0, player->pName, 130, 0);
    }
    switch (player->GetRace())
    {
      case 0:  uRaceName = pGlobalTXT_LocalizationStrings[99]; break; // "Human"       
      case 1:  uRaceName = pGlobalTXT_LocalizationStrings[103]; break; // "Dwarf"
      case 2:  uRaceName = pGlobalTXT_LocalizationStrings[106]; break; // "Goblin"
	  case 3:  uRaceName = pGlobalTXT_LocalizationStrings[101]; break; // "Elf"   
    }; 
	strcpy(pTmpBuf, uRaceName);
    pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, pOrder + 72, v128 + 12, 0, pTmpBuf, 130, 0);
    pTextCenter = pFontCreate->AlignText_Center(0x96, pText);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + uX - 24, 291, uColor1, pText, 0, 0, 0);
    uNumMight = player->GetActualMight();
    sprintf(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[144], v129, uNumMight);// "Might"
    LOWORD(v24) = player->GetStatColor(0);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, 169, v24, pTmpBuf, 0, 0, 0);
    v25 = player->GetActualIntelligence();
    sprintf(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[116], v129, v25);// "Intellect"
    LOWORD(v26) = player->GetStatColor(1);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, v128 + 169, v26, pTmpBuf, 0, 0, 0);
    v27 = player->GetActualWillpower();
    sprintf(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[163], v129, v27);// "Personality"
    LOWORD(v28) = player->GetStatColor(2);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, 2 * v128 + 169, v28, pTmpBuf, 0, 0, 0);
    v29 = player->GetActualEndurance();
    sprintf(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[75], v129, v29);// "Endurance"
    LOWORD(v30) = player->GetStatColor(3);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, uY, v30, pTmpBuf, 0, 0, 0);
    v31 = player->GetActualAccuracy();
    sprintf(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[1], v129, v31);// "Accuracy"
    LOWORD(v32) = player->GetStatColor(4);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, 4 * v128 + 169, v32, pTmpBuf, 0, 0, 0);
    v33 = player->GetActualSpeed();
    sprintf(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[211], v129, v33);// "Speed"
    LOWORD(v34) = player->GetStatColor(5);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, v122, v34, pTmpBuf, 0, 0, 0);
    v35 = player->GetActualLuck();
    sprintf(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[136], v129, v35);// "Luck"
    LOWORD(v36) = player->GetStatColor(6);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, v119, v36, pTmpBuf, 0, 0, 0);
    v37 = player->GetSkillIdxByOrder(0);
    pTextCenter = pFontCreate->AlignText_Center(0x96u, pSkillNames[v37]);
    sprintf(pTmpBuf, "\t%03u%s", pTextCenter, pSkillNames[v37]);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX - 24, 311, uColorWhite, pTmpBuf, 0, 0, 0);
    v39 = player->GetSkillIdxByOrder(1);
    pTextCenter = pFontCreate->AlignText_Center(0x96u, pSkillNames[v39]);
    sprintf(pTmpBuf, "\t%03u%s", pTextCenter, pSkillNames[v39]);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX - 24, v128 + 311, uColorWhite, pTmpBuf, 0, 0, 0);
    v41 = player->GetSkillIdxByOrder(2);
    pTextCenter = pFontCreate->AlignText_Center(150u, pSkillNames[v41]);
    sprintf(pTmpBuf, "\t%03u%s", pTextCenter, pSkillNames[v41]);
    v45 = uColorGreen;
    if ( (signed int)v41 >= 37 )
      v45 = uColorTeal;
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX - 24, 2 * v128 + 311, v45, pTmpBuf, 0, 0, 0);
    v46 = player->GetSkillIdxByOrder(3);
    pTextCenter = pFontCreate->AlignText_Center(150u, pSkillNames[v46]);
    sprintf(pTmpBuf, "\t%03u%s", pTextCenter, pSkillNames[v46]);
    v50 = uColorGreen;
    if ( (signed int)v46 >= 37 )
      v50 = uColorTeal;
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX - 24, v123, v50, pTmpBuf, 0, 0, 0);
    //pPlayer++;
    v124 = (char *)v124 + 1;
    pOrder += 159;
    v129 -= 158;
    uX += 158;
  }

  //while ( (signed int)pPlayer->pName < (signed int)&pParty->pPickedItem.uNumCharges );
  strcpy(pText, pGlobalTXT_LocalizationStrings[41]);// "Class"
  v51 = strlen(pText) - 1;
  pOrder = v51;
  if ( v51 >= 0 )
  {
    while ( 1 )
    {
      v52 = &pText[v51];
      v53 = toupper((unsigned __int8)pText[v51]);
      v10 = pOrder-- - 1 < 0;
      *v52 = v53;
      if ( v10 )
        break;
      v51 = pOrder;
    }
  }
  uClassType = pParty->pPlayers[uPlayerCreationUI_SelectedCharacter].classType;
  pTextCenter = pFontCreate->AlignText_Center(193u, pText);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 324, 395, uColor1, pText, 0, 0, 0);
  v57 = uColorTeal;
  if ( uClassType )
    v57 = uColorWhite;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[0]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 323, 417, v57, pClassNames[0], 0, 0, 0);
  v61 = uColorTeal;
  if ( uClassType != PLAYER_CLASS_PALADIN )
    v61 = uColorWhite;
  uColorGreen = v128 + 417;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[12]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 323, v128 + 417, v61, pClassNames[12], 0, 0, 0);
  v66 = uColorTeal;
  if ( uClassType != PLAYER_CLASS_DRUID )
    v66 = uColorWhite;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[20]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 323, 2 * v128 + 417, v66, pClassNames[20], 0, 0, 0);
  v71 = uColorTeal;
  if ( uClassType != PLAYER_CLASS_CLERIC )
    v71 = uColorWhite;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[24]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 388, 417, v71, pClassNames[24], 0, 0, 0);
  v75 = uColorTeal;
  if ( uClassType != PLAYER_CLASS_DRUID)
    v75 = uColorWhite;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[28]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 388, uColorGreen, v75, pClassNames[28], 0, 0, 0);
  v80 = uColorTeal;
  if ( uClassType != PLAYER_CLASS_SORCERER )
    v80 = uColorWhite;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[32]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 388, 2 * v128 + 417, v80, pClassNames[32], 0, 0, 0);
  v85 = uColorTeal;
  if ( uClassType != PLAYER_CLASS_ARCHER )
    v85 = uColorWhite;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[16]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 453, 417, v85, pClassNames[16], 0, 0, 0);
  v89 = uColorTeal;
  if ( uClassType != PLAYER_CLASS_MONK )
    v89 = uColorWhite;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[8]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 453, uColorGreen, v89, pClassNames[8], 0, 0, 0);
  v94 = uColorTeal;
  if ( uClassType != PLAYER_CLASS_THEIF )
    v94 = uColorWhite;
  pTextCenter = pFontCreate->AlignText_Center(65, pClassNames[4]);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 453, 2 * v128 + 417, v94, pClassNames[4], 0, 0, 0);
  pTextCenter = pFontCreate->AlignText_Center(0xECu, pGlobalTXT_LocalizationStrings[20]); // "Available Skills"
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 37, 395, uColor1, pGlobalTXT_LocalizationStrings[20], 0, 0, 0);
  //pOrder = 0;
  //do
  for (pOrder = 0; pOrder < 9; ++pOrder)
  {
    pSkillId = pParty->pPlayers[uPlayerCreationUI_SelectedCharacter].GetSkillIdxByOrder(pOrder + 4);
    strcpy(pText, pSkillNames[pSkillId]);
    pLenText = strlen(pText);
    v104 = 0;
    if ( (signed int)pLenText > 0 )
    {
	  if ( pText[v104] == 32 )
	  {
		pText[v104] = 0;
	  }
	  else
	  {
		while ( pText[v104] != 32 )
		//for (v104 = 0; v104 < (signed int)pLenText || pText[v104] != 32; ++v104)
		{
		  ++v104;
		  if ( v104 >= (signed int)pLenText )
		   break;
		}
	  }
    }
    uColorGreen = -5;
    if ( (signed int)v124 > 2 )
      uColorGreen = 0;
    pColorText = uColorTeal;
    if ( !pParty->pPlayers[uPlayerCreationUI_SelectedCharacter].pActiveSkills[pSkillId] )
      pColorText = uColorWhite;
	pTextCenter = pFontCreate->AlignText_Center(100, pText);
    pGUIWindow_CurrentMenu->DrawText(pFontCreate, 100 * (pOrder / 3) + pTextCenter + uColorGreen + 17, v128 * (pOrder % 3) + 417, pColorText, pText, 0, 0, 0);
    //++pOrder;
  }
  //while ( pOrder < 9 );
  pTextCenter = pFontCreate->AlignText_Center(0x5C, pGlobalTXT_LocalizationStrings[30]);// "Bonus"
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 533, 394, uColor1, pGlobalTXT_LocalizationStrings[30], 0, 0, 0);
  v113 = PlayerCreation_ComputeAttributeBonus();
  sprintf(pTmpBuf, "%d", v113);
  pTextCenter = pFontCreate->AlignText_Center(84, pTmpBuf);
  pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 530, 410, uColorWhite, pTmpBuf, 0, 0, 0);
  if ( GameUI_StatusBar_TimedStringTimeLeft > GetTickCount() )
  {
    pWindow.Hint = pGlobalTXT_LocalizationStrings[412];// "Create Party cannot be completed unless you have assigned all characters 2 extra skills and have spent all of your bonus points."
    if ( v113 < 0 )
      pWindow.Hint = pGlobalTXT_LocalizationStrings[413];// "You can't spend more than 50 points."
    pWindow.uFrameWidth = 300;
    pWindow.uFrameHeight = 100;
    pWindow.uFrameX = 170;
    pWindow.uFrameY = 140;
    pWindow.uFrameZ = 469;
    pWindow.uFrameW = 239;
    pWindow.DrawMessageBox(0);
  }
  pRenderer->EndScene();
}

//----- (0049695A) --------------------------------------------------------
void __cdecl PlayerCreationUI_Initialize()
{
  unsigned int v0; // ebx@5
  unsigned int v1; // eax@6
  int v2; // ecx@6
  unsigned int v3; // eax@8
  signed int v4; // ecx@8
  signed int uControlParam; // [sp+10h] [bp-Ch]@7
  unsigned int uControlParama; // [sp+10h] [bp-Ch]@9
  unsigned int uControlParamb; // [sp+10h] [bp-Ch]@11
  unsigned int uControlParamc; // [sp+10h] [bp-Ch]@13
  signed int uControlParamd; // [sp+10h] [bp-Ch]@15
  signed int uX; // [sp+14h] [bp-8h]@5
  unsigned int uXa; // [sp+14h] [bp-8h]@9
  unsigned int uXb; // [sp+14h] [bp-8h]@11
  unsigned int uXc; // [sp+14h] [bp-8h]@13
  signed int uXd; // [sp+14h] [bp-8h]@16

  if ( pMessageQueue_50CBD0->uNumMessages )
    pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
  pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
  ++pIcons_LOD->uTexturePacksCount;
  if ( !pIcons_LOD->uNumPrevLoadedFiles )
    pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
  pCurrentScreen = SCREEN_PARTY_CREATION;
  uPlayerCreationUI_ArrowAnim = 0;
  uPlayerCreationUI_SkySliderPos = 0;
  uPlayerCreationUI_SelectedCharacter = 0;
  v0 = LOBYTE(pFontCreate->uFontHeight) - 2;
  pTexture_IC_KNIGHT[0] = pIcons_LOD->LoadTexturePtr("IC_KNIGHT", TEXTURE_16BIT_PALETTE);
  pTexture_IC_KNIGHT[1] = pIcons_LOD->LoadTexturePtr("IC_THIEF", TEXTURE_16BIT_PALETTE);
  pTexture_IC_KNIGHT[2] = pIcons_LOD->LoadTexturePtr("IC_MONK", TEXTURE_16BIT_PALETTE);
  pTexture_IC_KNIGHT[3] = pIcons_LOD->LoadTexturePtr("IC_PALAD", TEXTURE_16BIT_PALETTE);
  pTexture_IC_KNIGHT[4] = pIcons_LOD->LoadTexturePtr("IC_ARCH", TEXTURE_16BIT_PALETTE);
  pTexture_IC_KNIGHT[5] = pIcons_LOD->LoadTexturePtr("IC_RANGER", TEXTURE_16BIT_PALETTE);
  pTexture_IC_KNIGHT[6] = pIcons_LOD->LoadTexturePtr("IC_CLER", TEXTURE_16BIT_PALETTE);
  pTexture_IC_KNIGHT[7] = pIcons_LOD->LoadTexturePtr("IC_DRUID", TEXTURE_16BIT_PALETTE);
  pTexture_IC_KNIGHT[8] = pIcons_LOD->LoadTexturePtr("IC_SORC", TEXTURE_16BIT_PALETTE);
  pTexture_MAKETOP = pIcons_LOD->LoadTexturePtr("MAKETOP", TEXTURE_16BIT_PALETTE);
  pTexture_MAKESKY = pIcons_LOD->LoadTexturePtr("MAKESKY", TEXTURE_16BIT_PALETTE);
  for(uX=0;uX < 22;++uX ) // load PlayerPortraits texture
  {
    sprintf(pTmpBuf, "%s01", pPlayerPortraitsNames[uX]);
    v1 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE);
    pPlayerPortraits[uX] = &pIcons_LOD->pTextures[v1];

  }
  pTexture_PlayerFaceMask = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("FACEMASK", TEXTURE_16BIT_PALETTE)];
  pTexture_buttminu  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("buttminu", TEXTURE_16BIT_PALETTE)];
  pTexture_buttplus  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("buttplus", TEXTURE_16BIT_PALETTE)];
  pTexture_pressrigh = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("presrigh", TEXTURE_16BIT_PALETTE)];
  pTexture_presleft  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("presleft", TEXTURE_16BIT_PALETTE)];
  uControlParam = 1;
  do
  {
    sprintf(pTmpBuf, "arrowl%d", uControlParam);
    pTextures_arrowl[uControlParam] = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE)];
    sprintf(pTmpBuf, "arrowr%d", uControlParam);
    v3 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE);
    v4 = uControlParam++;
    pTextures_arrowr[v4] = &pIcons_LOD->pTextures[v3];
  }
  while ( uControlParam < 20 );
  pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
  uControlParama = 0;
  uXa = 8;
  do
  {
    pGUIWindow_CurrentMenu->CreateButton(uXa, 120u, 145u, 25u, 1, 0, 0x3Cu, uControlParama, 0, "", 0);
    uXa += 158;
    ++uControlParama;
  }
  while ( (signed int)uXa < 640 );
  pCreationUI_BtnPressLeft[0] = pGUIWindow_CurrentMenu->CreateButton(10, 32, 11, 13, 1, 0, 0xABu, 0, 0, "", pTexture_presleft, 0);
  pCreationUI_BtnPressLeft[1] = pGUIWindow_CurrentMenu->CreateButton(169, 32, 11, 13, 1, 0, 0xABu, 1, 0, "", pTexture_presleft, 0);
  pCreationUI_BtnPressLeft[2] = pGUIWindow_CurrentMenu->CreateButton(327, 32, 11, 13, 1, 0, 0xABu, 2, 0, "", pTexture_presleft, 0);
  pCreationUI_BtnPressLeft[3] = pGUIWindow_CurrentMenu->CreateButton(486, 32, 11, 13, 1, 0, 0xABu, 3, 0, "", pTexture_presleft, 0);
  pCreationUI_BtnPressRight[0] = pGUIWindow_CurrentMenu->CreateButton(74, 32, 11, 13, 1, 0, 0xACu, 0, 0, "", pTexture_pressrigh, 0);
  pCreationUI_BtnPressRight[1] = pGUIWindow_CurrentMenu->CreateButton(233, 32, 11, 13, 1, 0, 0xACu, 1, 0, "", pTexture_pressrigh, 0);
  pCreationUI_BtnPressRight[2] = pGUIWindow_CurrentMenu->CreateButton(391, 32, 11, 13, 1, 0, 0xACu, 2, 0, "", pTexture_pressrigh, 0);
  pCreationUI_BtnPressRight[3] = pGUIWindow_CurrentMenu->CreateButton(549, 32, 11, 13, 1, 0, 0xACu, 3, 0, "", pTexture_pressrigh, 0);
  pCreationUI_BtnPressLeft2[0] = pGUIWindow_CurrentMenu->CreateButton(10, 103, 11, 13, 1, 0, 0x90u, 0, 0, "", pTexture_presleft, 0);
  pCreationUI_BtnPressLeft2[1] = pGUIWindow_CurrentMenu->CreateButton(169, 103, 11, 13, 1, 0, 0x90u, 1, 0, "", pTexture_presleft, 0);
  pCreationUI_BtnPressLeft2[2] = pGUIWindow_CurrentMenu->CreateButton(327, 103, 11, 13, 1, 0, 0x90u, 2, 0, "", pTexture_presleft, 0);
  pCreationUI_BtnPressLeft2[3] = pGUIWindow_CurrentMenu->CreateButton(486, 103, 11, 13, 1, 0, 0x90u, 3, 0, "", pTexture_presleft, 0);
  pCreationUI_BtnPressRight2[0] = pGUIWindow_CurrentMenu->CreateButton(74, 103, 11, 13, 1, 0, 0x91u, 0, 0, "", pTexture_pressrigh, 0);
  pCreationUI_BtnPressRight2[1] = pGUIWindow_CurrentMenu->CreateButton(233, 103, 11, 13, 1, 0, 0x91u, 1, 0, "", pTexture_pressrigh, 0);
  pCreationUI_BtnPressRight2[2] = pGUIWindow_CurrentMenu->CreateButton(391, 103, 11, 13, 1, 0, 0x91u, 2, 0, "", pTexture_pressrigh, 0);
  pCreationUI_BtnPressRight2[3] = pGUIWindow_CurrentMenu->CreateButton(549, 103, 11, 13, 1, 0, 0x91u, 3, 0, "", pTexture_pressrigh, 0);
  uControlParamb = 0;
  uXb = 8;
  do
  {
    pGUIWindow_CurrentMenu->CreateButton(uXb, 308, 150, v0, 1, 0, 0x48u, uControlParamb, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXb, v0 + 308, 150, v0, 1, 0, 0x49u, uControlParamb, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXb, 2 * v0 + 308, 150u, v0, 1, 0, 0x4Au, uControlParamb, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXb, 3 * v0 + 308, 150u, v0, 1, 0, 0x4Bu, uControlParamb, 0, "", 0);
    uXb += 158;
    ++uControlParamb;
  }
  while ( (signed int)uXb < 640 );
  pGUIWindow_CurrentMenu->CreateButton(5u, 21u, 0x99u, 0x16Du, 1, 0, 0x76u, 0, 0x31u, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(163u, 21u, 0x99u, 0x16Du, 1, 0, 0x76u, 1u, 0x32u, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(321u, 21u, 0x99u, 0x16Du, 1, 0, 0x76u, 2u, 0x33u, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(479u, 21u, 0x99u, 0x16Du, 1, 0, 0x76u, 3u, 0x34u, "", 0);
  uXc = 23;
  uControlParamc = 2;
  do
  {
    pGUIWindow_CurrentMenu->CreateButton(uXc, 169, 120, 20, 1, 0, 0, uControlParamc - 2, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXc, v0 + 169, 120, 20, 1, 0, 0, uControlParamc - 1, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXc, 2 * v0 + 169, 120, 20, 1, 0, 0, uControlParamc, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXc, 3 * v0 + 169, 120, 20, 1, 0, 0, uControlParamc + 1, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXc, 4 * v0 + 169, 120, 20, 1, 0, 0, uControlParamc + 2, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXc, 5 * v0 + 169, 120, 20, 1, 0, 0, uControlParamc + 3, 0, "", 0);
    pGUIWindow_CurrentMenu->CreateButton(uXc, 6 * v0 + 169, 120, 20, 1, 0, 0, uControlParamc + 4, 0, "", 0);
    uControlParamc += 7;
    uXc += 158;
  }
  while ( (signed int)uControlParamc < 30 );
  pGUIWindow_CurrentMenu->_41D08F(28, 0, 7, 40);
  pGUIWindow_CurrentMenu->CreateButton(323, 417, 65, v0, 1, 0, 0x41, 0, 0, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(323, v0 + 417, 65, v0, 1, 0, 0x41, 0xC, 0, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(323, 2 * v0 + 417, 65, v0, 1, 0, 0x41, 0x14, 0, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(388, 417, 65, v0, 1, 0, 0x41, 0x18, 0, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(388, v0 + 417, 65, v0, 1, 0, 0x41, 0x1C, 0, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(388, 2 * v0 + 417, 65, v0, 1, 0, 0x41, 0x20, 0, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(453, 417, 65, v0, 1, 0, 0x41, 0x10, 0, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(453, v0 + 417, 65, v0, 1, 0, 0x41, 8, 0, "", 0);
  pGUIWindow_CurrentMenu->CreateButton(453, 2 * v0 + 417, 65, v0, 1, 0, 0x41, 4, 0, "", 0);
  uControlParamd = 0;
  do
  {
    uXd = -5;
    if ( uControlParamd <= 3 )
      uXd = 0;
    pGUIWindow_CurrentMenu->CreateButton(100 * (uControlParamd / 3) + uXd + 17, v0 * (uControlParamd % 3) + 417, 100, v0, 1, 0, 0x40,
      uControlParamd, 0, "", 0);
    ++uControlParamd;
  }
  while ( uControlParamd < 9 );
  pPlayerCreationUI_BtnOK = pGUIWindow_CurrentMenu->CreateButton(580, 431, 51, 39, 1, 0, 0x42, 0, 0xD, "",
                              (Texture *)(uTextureID_BUTTMAKE != -1 ? &pIcons_LOD->pTextures[uTextureID_BUTTMAKE] : 0), 0);
  pPlayerCreationUI_BtnReset = pGUIWindow_CurrentMenu->CreateButton(527, 431, 51, 39, 1, 0, 0x43, 0, 0x43, "",
                                 (Texture *)(uTextureID_BUTTMAKE2 != -1 ? &pIcons_LOD->pTextures[uTextureID_BUTTMAKE2] : 0), 0);
  pPlayerCreationUI_BtnMinus = pGUIWindow_CurrentMenu->CreateButton(523, 393, 20, 35, 1, 0, 0x3F, 0, 0x2D, "", pTexture_buttminu, 0);
  pPlayerCreationUI_BtnPlus = pGUIWindow_CurrentMenu->CreateButton(613, 393, 20, 35, 1, 0, 0x3E, 1, 0x2B, "", pTexture_buttplus, 0);
  pFontCChar = LoadFont("cchar.fnt", "FONTPAL", NULL);
}
// 4E28F8: using guessed type int pCurrentScreen;

//----- (0049750E) --------------------------------------------------------
void __cdecl DeleteCCharFont()
{
  pAllocator->FreeChunk(pFontCChar);
  pFontCChar = 0;
}
//----- (00497526) --------------------------------------------------------
bool __cdecl PlayerCreationUI_Loop()
{
  //RGBTexture *pTexture; // ebx@1
  UINT v1; // esi@1
  unsigned int v2; // ecx@3
  LONG uMouseX; // edi@6
  LONG uMouseY; // eax@6
  GUIButton *pControlsHead; // edx@6
  //unsigned int pNumMessage; // ecx@7
  int pControlParam; // esi@12
  signed int v8; // edi@30
  int v9; // edx@31
  char *v10; // ebx@37
  Player *v11; // esi@38
  //signed int uSpellBookPageCount; // ecx@40
  int v13; // eax@40
  //signed int uSkillIdx; // eax@45
  int v15; // eax@70
  signed int v16; // ecx@70
  //unsigned int v18; // [sp-4h] [bp-84h]@48
  ItemGen item; // [sp+Ch] [bp-74h]@37
  char v20[32]; // [sp+30h] [bp-50h]@29
  //char v21; // [sp+31h] [bp-4Fh]@29
  //__int16 v22; // [sp+4Dh] [bp-33h]@29
  char v23; // [sp+4Fh] [bp-31h]@29
  MSG Msg; // [sp+50h] [bp-30h]@17
  POINT v25; // [sp+6Ch] [bp-14h]@6
  bool v26; // [sp+74h] [bp-Ch]@1
  //POINT v24; // [sp+78h] [bp-8h]@6
  //Player *pPlayer;

  //pTexture = &pTexture_PCX;
  v1 = 0;
  v26 = 0;
  pTexture_PCX.Release();
  pTexture_PCX.Load("makeme.pcx", 0);
  if (pAsyncMouse)
    pAsyncMouse->Resume();
  v2 = 6;
  pGUIWindow_CurrentMenu->field_40 = 0;
//LABEL_27:
  SetCurrentMenuID((MENU_STATE)v2);
  while ( GetCurrentMenuID() == MENU_CREATEPARTY )
  {
    if ( pAsyncMouse != (void *)v1 )
      pAsyncMouse->_46B736_consume_click_lists(1);
    uMouseX = pMouse->GetCursorPos(&v25)->x;
    uMouseY = pMouse->GetCursorPos(&v25)->y;
    pControlsHead = pGUIWindow_CurrentMenu->pControlsHead;

    //does nothing actually
    /*if ( pControlsHead != (GUIButton *)v1 )
    {
      pNumMessage = pMessageQueue_50CBD0->uNumMessages;
      do
      {
        if ( uMouseX >= (signed int)pControlsHead->uX && uMouseX <= (signed int)pControlsHead->uZ 
            && uMouseY >= (signed int)pControlsHead->uY && uMouseY <= (signed int)pControlsHead->uW )//mouse movement
        {
          pControlParam = pControlsHead->uControlParam;
          pMessageQueue_50CBD0->AddMessage((UIMessageType)pControlsHead->field_1C, pControlParam, 0);
          v1 = 0;
        }
        pControlsHead = pControlsHead->pNext;
      }
      while ( pControlsHead != (GUIButton *)v1 );
    }*/

    while ( PeekMessageA(&Msg, (HWND)v1, v1, v1, PM_REMOVE) )
    {
      if ( Msg.message == WM_QUIT )
        Game_DeinitializeAndTerminate(0);
      TranslateMessage(&Msg);
      DispatchMessageA(&Msg);
    }
    if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
    {
      WaitMessage();
    }
    else
    {
      PlayerCreationUI_Draw();
      GUI_MainMenuMessageProc();
      pRenderer->BeginScene();
      GUI_UpdateWindows();
      pRenderer->EndScene();
      pRenderer->Present();
      if ( uGameState == 1 )
      {
        v26 = 1;
        v2 = 0;
        //goto LABEL_27;
        SetCurrentMenuID((MENU_STATE)v2);
        continue;
      }
      if ( uGameState == 6 )
      {
        uGameState = v1;
        v2 = 1;
        //goto LABEL_27;
        SetCurrentMenuID((MENU_STATE)v2);
        continue;
      }
    }
  }
  pTexture_PCX.Release();
  pGUIWindow_CurrentMenu->Release();
  pIcons_LOD->_4114F2();

  memset(v20, 0, 32);
  do
  {
    v8 = 0;
    do
    {
      v9 = rand() % 32;
      if ( !v20[v9] )
        break;
      ++v8;
    }
    while ( v8 < 10 );
    if ( v8 == 10 )
    {
      v9 = 0;
      if ( v20[0] )
      {
        do
          ++v9;
        while ( v20[v9] );
      }
    }
    pParty->field_854[v1++] = v9;
    v20[v9] = 1;
  }
  while ( (signed int)v1 < 32 );
  //v10 = (char *)&pParty->pPlayers[0].sResMagicBase;
  
  item.Reset();
  //for ( pPlayer = &pParty->pPlayers[0];  pPlayer < &pParty->pPlayers[4]; pPlayer++)
  for (uint i = 0; i < 4; ++i)
  {
    auto player = &pParty->pPlayers[i];
    //v11 = pPlayer;
    if (player->classType == PLAYER_CLASS_KNIGHT)
      player->sResMagicBase = 10;
    //*((short *)v10 + 400) = 0;
    player->pPlayerBuffs[22].uExpireTime = 0;
    for (uint j = 0; j < 9; j++)
    {
      if (player->pActiveSkills[PLAYER_SKILL_FIRE + j])
      {
        player->lastOpenedSpellbookPage = j;
        break;
      }
    }
    pItemsTable->GenerateItem(2, 40, &item);
    player->AddItem2(-1, &item);
    //uSkillIdx = 0;
    //v24.y = 0;

    player->sHealth = player->GetMaxHealth();
    player->sMana = player->GetMaxMana();
    for (uint j = 0; j < 37; ++j)
    {
      if (!player->pActiveSkills[j])
        continue;

      switch (j)
      {
        case PLAYER_SKILL_STAFF:   player->AddItem(-1, 61); break;
        case PLAYER_SKILL_SWORD:   player->AddItem(-1, 1); break;
        case PLAYER_SKILL_DAGGER:  player->AddItem(-1, 15); break;
        case PLAYER_SKILL_AXE:     player->AddItem(-1, 23); break;
        case PLAYER_SKILL_SPEAR:   player->AddItem(-1, 31); break;
        case PLAYER_SKILL_BOW:     player->AddItem(-1, 47); break;
        case PLAYER_SKILL_MACE:    player->AddItem(-1, 50); break;
        case PLAYER_SKILL_BLASTER: assert(false); break;
        case PLAYER_SKILL_SHIELD:  player->AddItem(-1, 84); break;
        case PLAYER_SKILL_LEATHER: player->AddItem(-1, 66); break;
        case PLAYER_SKILL_CHAIN:   player->AddItem(-1, 71); break;
        case PLAYER_SKILL_PLATE:   player->AddItem(-1, 76); break;
        case PLAYER_SKILL_FIRE:
          player->AddItem(-1, 0x191);
          player->spellbook.pFireSpellbook.bIsSpellAvailable[0] = true;
        break;
        case PLAYER_SKILL_AIR:
          player->AddItem(-1, 0x19C);
          player->spellbook.pAirSpellbook.bIsSpellAvailable[0] = true;
        break;
        case PLAYER_SKILL_WATER:
          player->AddItem(-1, 0x1A7);
		  player->spellbook.pWaterSpellbook.bIsSpellAvailable[0] = true;
        break;
        case PLAYER_SKILL_EARTH:
          player->AddItem(-1, 0x1B2);
		  player->spellbook.pEarthSpellbook.bIsSpellAvailable[0] = true;
        break;
        case PLAYER_SKILL_SPIRIT:
          player->AddItem(-1, 0x1BD);
		  player->spellbook.pSpiritSpellbook.bIsSpellAvailable[0] = true;
        break;
        case PLAYER_SKILL_MIND:
          player->AddItem(-1, 0x1C8);
		  player->spellbook.pMindSpellbook.bIsSpellAvailable[0] = true;
        break;
        case PLAYER_SKILL_BODY:
          player->AddItem(-1, 0x1D3);
		  player->spellbook.pBodySpellbook.bIsSpellAvailable[0] = true;
        break;
        case PLAYER_SKILL_LIGHT:
        case PLAYER_SKILL_DARK:
        case PLAYER_SKILL_DIPLOMACY:
          assert(false);
        break;
        case PLAYER_SKILL_ITEM_ID:
        case PLAYER_SKILL_REPAIR:
        case PLAYER_SKILL_MEDITATION:
        case PLAYER_SKILL_PERCEPTION:
        case PLAYER_SKILL_TRAP_DISARM:
        case PLAYER_SKILL_LEARNING:
          player->AddItem(-1, 0xDC);
		  player->AddItem(-1, 5 * (rand() % 3 + 40));
        break;
        case PLAYER_SKILL_DODGE:   player->AddItem(-1, 115); break;
        case PLAYER_SKILL_UNARMED: player->AddItem(-1, 110); break;
        default:
          break;
      }

      for (uint k = 0; k < 138; k++)
      {
        if (&player->pInventoryItems[k])
          player->pInventoryItems[k].SetIdentified();
      }
    }
  }

  pAudioPlayer->StopChannels(-1, -1);
  if (pAsyncMouse)
    pAsyncMouse->Suspend();
  return v26;
}

//----- (004979D2) --------------------------------------------------------
MENU_STATE __cdecl CreditsMenu__Loop()
{
  char *v0; // eax@5
  char *v1; // edi@5
  FILE *pFile; // eax@5
  unsigned int pSize; // esi@7
  GUIFont *pFont; // edx@9
  GUIFont *pFont2; // ecx@9
  __int16 pHeight; // ax@9
  void *v7; // eax@9
  unsigned int pNumPixels; // ST2C_4@9
  unsigned int teal; // eax@9
  unsigned int v10; // ST2C_4@19
  MSG Msg; // [sp+84h] [bp-B8h]@10
  int v17; // [sp+A0h] [bp-9Ch]@9
  int pX; // [sp+A4h] [bp-98h]@9
  unsigned int pY; // [sp+A8h] [bp-94h]@9
  int v20; // [sp+ACh] [bp-90h]@9
  int a4; // [sp+B0h] [bp-8Ch]@9
  int pColor2; // [sp+F8h] [bp-44h]@9
  int pColor1; // [sp+FCh] [bp-40h]@9
  int a5; // [sp+128h] [bp-14h]@1
  char *pString; // [sp+12Ch] [bp-10h]@9
  char *ptr; // [sp+130h] [bp-Ch]@5
  GUIFont *pFontQuick; // [sp+134h] [bp-8h]@1
  GUIFont *pFontCChar; // [sp+138h] [bp-4h]@1
  RGBTexture pTexture; // [sp+54h] [bp-E8h]@1
  RGBTexture pTexture2; // [sp+100h] [bp-3Ch]@1
  Texture pTexture3; // [sp+Ch] [bp-130h]@5
  
  a5 = 0;
  pFontQuick = LoadFont("quick.fnt", "FONTPAL", NULL);
  pFontCChar = LoadFont("cchar.fnt", "FONTPAL", NULL);
  if ( pMessageQueue_50CBD0->uNumMessages )
    pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
  ++pIcons_LOD->uTexturePacksCount;
  if ( !pIcons_LOD->uNumPrevLoadedFiles )
    pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
  dword_A74C88 = 0;
  pAudioPlayer->PlayMusicTrack(MUSIC_Credits);
  pTexture.Load("mm6title.pcx", 0);
  v0 = (char *)pEvents_LOD->LoadRaw("credits.txt", 0);
  v1 = v0;
  ptr = v0;
  pFile = pEvents_LOD->FindContainer("credits.txt", 0);
  if ( !pFile )
    Abortf(pGlobalTXT_LocalizationStrings[63]); // "Might and Magic VII is having trouble loading files. 
                                                // Please re-install to fix this problem. Note: Re-installing will not destroy your save games."
  fread(&pTexture3, 1, 0x30, pFile);
  pSize = pTexture3.uDecompressedSize;
  if ( !pTexture3.uDecompressedSize )
    pSize = pTexture3.uTextureSize;
  memset(&pTexture3, 0, 0x48);
  pFont = pFontCChar;
  pFont2 = pFontQuick;
  v1[pSize] = 0;
  v20 = 250;
  a4 = 440;
  pX = 389;
  pY = 19;
  pTexture2.uWidth = 250;
  pHeight = pFont2->GetStringHeight2(pFont, v1, (int)&pX, 0, 1);
  pTexture2.uHeight = pHeight + 2 * a4;
  pTexture2.uNumPixels = (signed __int16)pTexture2.uWidth * (signed __int16)pTexture2.uHeight;
  v7 = pAllocator->AllocNamedChunk(pTexture2.pPixels, 2 * pTexture2.uNumPixels, "scrollermap");
  pNumPixels = pTexture2.uNumPixels;
  pTexture2.pPixels = (unsigned __int16 *)v7;
  teal = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0, 0xFFu, 0xFFu);
  fill_pixels_fast(teal, pTexture2.pPixels, pNumPixels);
  pTexture2.field_20 = 0;
  pTexture2.field_22 = 0;
  pColor1 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0x70u, 0x8Fu, 0xFEu);
  pColor2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xECu, 0xE6u, 0x9Cu);
  pString = (char *)operator new(2 * pSize);
  strncpy(pString, ptr, pSize);
  pString[pSize]=0;
  pFontQuick->_44D2FD_prolly_draw_credits_entry(pFontCChar, 0, a4, (signed __int16)pTexture2.uWidth, (signed __int16)pTexture2.uHeight, pColor1, 
	  pColor2, pString, pTexture2.pPixels, (signed __int16)pTexture2.uWidth);
  free(pString);
  pWindow_MainMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, (int)ptr);
  pWindow_MainMenu->CreateButton(0, 0, 0, 0, 1, 0, 0x71u, 0, 0x1Bu, "", 0);
  pCurrentScreen = SCREEN_CREATORS;
  SetCurrentMenuID(MENU_CREDITSPROC);
  do
  {
    while ( PeekMessageA(&Msg, 0, 0, 0, 1) )
    {
      if ( Msg.message == 18 )
        Game_DeinitializeAndTerminate(0);
      TranslateMessage(&Msg);
      DispatchMessageA(&Msg);
    }
    if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
    {
      WaitMessage();
    }
    else
    {
      if (pAsyncMouse)
        pAsyncMouse->_46B736_consume_click_lists(1);
      pRenderer->BeginScene();
      pRenderer->DrawTextureRGB(0, 0, &pTexture);
      pRenderer->Clip(pX, pY, pX + v20, pY + a4);
      pRenderer->_4A5D33(pX, pY, 0, a5, &pTexture2);
      pRenderer->ResetClip();
      pRenderer->EndScene();
      ++a5;
      if ( a5 >= (signed __int16)pTexture2.uHeight )
        SetCurrentMenuID(MENU_MAIN);
      pRenderer->Present();
      pCurrentScreen = SCREEN_GAME;//Ritor1: temporarily, must be corrected GUI_MainMenuMessageProc()
      GUI_MainMenuMessageProc();
    }
  }
  while ( GetCurrentMenuID() == MENU_CREDITSPROC );
  pAudioPlayer->_4AA258(1);
  pAllocator->FreeChunk(ptr);
  pAllocator->FreeChunk(pFontQuick);
  pAllocator->FreeChunk(pFontCChar);
  pWindow_MainMenu->Release();
  pIcons_LOD->_4114F2();
  pTexture.Release();
  pTexture2.Release();
  return MENU_MAIN;     // return MENU_Main
}

//----- (0049B04D) --------------------------------------------------------
int stru154::_49B04D(ODMFace *a2, BSPVertexBuffer *a3)
{
  stru154 *v3; // edi@1
  signed int v4; // eax@1
  signed int result; // eax@9
  signed int v6; // [sp-8h] [bp-18h]@8
  Vec3_float_ v; // [sp+4h] [bp-Ch]@1

  v.x = 0.0;
  v3 = this;
  v.y = 0.0;
  v.z = 0.0;
  _49B13D(a2, a3, &v, (float *)&a3);
  v4 = 2;
  if ( a2->pFacePlane.vNormal.z )
  {
    if ( !a2->pFacePlane.vNormal.x && !a2->pFacePlane.vNormal.y )
      v4 = 1;
  }
  else
  {
    v4 = 0;
  }
  if ( v4 )
  {
    if ( v4 == 1 )
      v6 = 3;
    else
      v6 = 4;
    result = v6;
  }
  else
  {
    result = 1;
  }
  v3->face_plane.vNormal.x = v.x;
  v3->face_plane.vNormal.y = v.y;
  v3->face_plane.vNormal.z = v.z;
  v3->face_plane.dist = *(float *)&a3;
  v3->polygonType = (PolygonType)result;
  return result;
}

//----- (0049B0C9) --------------------------------------------------------
int stru154::_49B0C9(Vec3_float_ *pNormal, float dist)
{
  signed int v3; // esi@1
  signed int result; // eax@9
  double v5; // st7@12
  double v6; // st6@12
  double v7; // st5@12
  signed int v8; // [sp+0h] [bp-4h]@8

  v3 = 2;
  if ( pNormal->z == 0.0 )
  {
    v3 = 0;
  }
  else
  {
    if ( pNormal->x == 0.0 && pNormal->y == 0.0 )
      v3 = 1;
  }
  if ( v3 )
  {
    if ( v3 == 1 )
      v8 = 3;
    else
      v8 = 4;
    result = v8;
  }
  else
  {
    result = 1;
  }
  v5 = pNormal->z;
  v6 = pNormal->y;
  v7 = pNormal->x;
  this->polygonType = (PolygonType)result;
  this->face_plane.vNormal.x = v7;
  this->face_plane.dist = dist;
  this->face_plane.vNormal.y = v6;
  this->face_plane.vNormal.z = v5;
  return result;
}

//----- (0049B13D) --------------------------------------------------------
int stru154::_49B13D(ODMFace *pFace, BSPVertexBuffer *pVertices, Vec3_float_ *a3, float *a4)
{
  ODMFace *v5; // ebx@1
  int v6; // eax@1
  unsigned __int16 *v7; // ebx@2
  Vec3_int_ *v8; // eax@3
  Vec3_int_ *v9; // ecx@3
  double v10; // st7@3
  int v11; // ecx@3
  Vec3_int_ *v12; // ecx@3
  double v13; // st7@3
  double v14; // st6@3
  double v15; // st5@3
  int v16; // ecx@3
  Vec3_int_ *v17; // eax@3
  double v18; // st5@3
  Vec3_float_ *v19; // eax@3
  int result; // eax@8
  float v21; // ecx@10
  double v22; // st7@10
  double v23; // st6@10
  Vec3_float_ v2; // [sp+4h] [bp-64h]@3
  float v25; // [sp+18h] [bp-50h]@3
  float v26; // [sp+1Ch] [bp-4Ch]@3
  float v27; // [sp+20h] [bp-48h]@3
  float v28; // [sp+24h] [bp-44h]@3
  float v29; // [sp+2Ch] [bp-3Ch]@3
  float v30; // [sp+30h] [bp-38h]@3
  float v31; // [sp+34h] [bp-34h]@3
  float v32; // [sp+38h] [bp-30h]@3
  float v33; // [sp+3Ch] [bp-2Ch]@3
  Vec3_float_ v1; // [sp+40h] [bp-28h]@1
  float v35; // [sp+4Ch] [bp-1Ch]@3
  float v36; // [sp+50h] [bp-18h]@3
  float v37; // [sp+54h] [bp-14h]@3
  Vec3_float_ v38; // [sp+58h] [bp-10h]@3
  int v39; // [sp+64h] [bp-4h]@1

  v39 = 0;
  v1.x = 0.0;
  v5 = pFace;
  v6 = pFace->uNumVertices;
  v1.y = 0.0;
  v1.z = 0.0;
  if ( v6 - 1 <= 0 )
  {
LABEL_8:
    a3->x = (double)(v5->pFacePlane.vNormal.x & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.x >> 16);
    a3->y = (double)(v5->pFacePlane.vNormal.y & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.y >> 16);
    a3->z = (double)(v5->pFacePlane.vNormal.z & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.z >> 16);
    result = (int)a4;
    *a4 = (double)(v5->pFacePlane.dist & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.dist >> 16);
  }
  else
  {
    v7 = &pFace->pVertexIDs[1];
    while ( 1 )
    {
      v8 = pVertices->pVertices;
      v9 = &v8[*(v7 - 1)];
      v35 = (double)v9->x;
      v36 = (double)v9->y;
      v10 = (double)v9->z;
      v11 = *v7;
      v37 = v10;
      v12 = &v8[v11];
      v13 = (double)v12->x;
      v14 = (double)v12->y;
      v15 = (double)v12->z;
      v16 = v7[1];
      v25 = v15;
      v17 = &v8[v16];
      v18 = (double)v17->x;
      v29 = (double)v17->y;
      v30 = (double)v17->z;
      v31 = v13 - v35;
      v32 = v14 - v36;
      v33 = v25 - v37;
      v1.x = v31;
      v26 = v18 - v13;
      v1.y = v32;
      v27 = v29 - v14;
      v1.z = v33;
      v28 = v30 - v25;
      v19 = Vec3_float_::Cross(&v1, &v2, v26, v27, v28);
      v38.x = v19->x;
      v38.y = v19->y;
      v38.z = v19->z;
      if ( v38.x != 0.0 )
        break;
      if ( v38.y != 0.0 || v38.z != 0.0 )
        break;
      ++v39;
      ++v7;
      if ( v39 >= pFace->uNumVertices - 1 )
      {
        v5 = pFace;
        goto LABEL_8;
      }
    }
    v38.Normalize();
    v21 = v38.y;
    a3->x = v38.x;
    v22 = v37 * v38.z;
    v23 = v36 * v38.y;
    a3->y = v21;
    a3->z = v38.z;
    result = (int)a4;
    *a4 = -(v22 + v23 + v35 * v38.x);
  }
  return result;
}





//----- (0049D700) --------------------------------------------------------
unsigned int __fastcall GetMaxMipLevels(unsigned int uDim)
{
  unsigned int v1; // eax@1
  int v2; // ecx@1
  unsigned int v3; // eax@1

  v1 = uDim;
  v2 = 0;
  v3 = v1 - 1;
  while ( v3 & 1 )
  {
    v3 >>= 1;
    ++v2;
  }
  return v3 == 0 ? v2 : 0;
}










//----- (004A19D8) --------------------------------------------------------
int __fastcall sub_4A19D8(unsigned int a1, unsigned int a2)
{
  signed __int64 v2; // ST10_8@1
  double v3; // st7@1
  float v4; // ST24_4@1
  double v5; // ST10_8@1
  int v6; // ST1C_4@1
  float v7; // ST24_4@1
  double v8; // ST10_8@1
  unsigned __int8 v9; // ST20_1@1
  float v10; // ST24_4@1
  double v11; // ST10_8@1
  float v12; // ST24_4@1
  double v13; // ST08_8@1

  v2 = a1 >> 24;
  v3 = (double)v2 * 0.0039215689;
  LODWORD(v2) = a2 >> 24;
  v4 = v3 * (double)v2 * 0.0039215689 * 255.0;
  v5 = v4 + 6.7553994e15;
  v6 = LODWORD(v5);
  v7 = (double)((a1 >> 16) & 0xFFi64) * 0.0039215689 * (double)((a2 >> 16) & 0xFF) * 0.0039215689 * 255.0;
  v8 = v7 + 6.7553994e15;
  v9 = LOBYTE(v8);
  v10 = (double)((unsigned __int16)a1 >> 8) * 0.0039215689 * (double)((unsigned __int16)a2 >> 8) * 0.0039215689 * 255.0;
  v11 = v10 + 6.7553994e15;
  v12 = (double)(a1 & 0xFFi64) * 0.0039215689 * (double)(unsigned __int8)a2 * 0.0039215689 * 255.0;
  v13 = v12 + 6.7553994e15;
  return LOBYTE(v13) | ((LOBYTE(v11) | (((v6 << 8) | v9) << 8)) << 8);
}



//----- (004A46E6) --------------------------------------------------------
int __fastcall sr_4A46E6_draw_particle_segment(unsigned int x, signed int y, signed int _z, int a4, unsigned int lightColor)
{
  int v5; // eax@1
  int z; // eax@1
  unsigned int v7; // eax@9
  unsigned int v8; // ecx@9
  int v9; // eax@9
  unsigned int v10; // eax@10
  int *v11; // esi@10
  int *v12; // edi@10
  int v13; // ecx@10
  int v14; // edx@10
  unsigned int v15; // eax@22
  int *v16; // esi@22
  int *v17; // edi@22
  int v18; // ecx@22
  int v19; // edx@22
  unsigned __int16 *pTarget; // [sp+Ch] [bp-8h]@9
  int *pTargetZ; // [sp+10h] [bp-4h]@9
  unsigned int v22; // [sp+1Ch] [bp+8h]@9
  signed int v23; // [sp+20h] [bp+Ch]@1

  v5 = a4;
  v23 = _z >> 16;
  z = x + v5;
  if ( z >= (signed int)pViewport->uViewportX
    && (signed int)x <= (signed int)pViewport->uViewportZ
    && y >= (signed int)pViewport->uViewportY
    && y <= (signed int)pViewport->uViewportW )
  {
    if ( (signed int)x < (signed int)pViewport->uViewportX )
      x = pViewport->uViewportX;
    if ( z > (signed int)pViewport->uViewportZ )
      z = pViewport->uViewportZ;
    pTarget = &pRenderer->pTargetSurface[x + y * pRenderer->uTargetSurfacePitch];
    v22 = z - x;
    pTargetZ = &pRenderer->pActiveZBuffer[x + 640 * y];
    v7 = lightColor >> 3;
    v8 = lightColor & 0xF0;
    v9 = v7 & 0x1E0000;
    if ( pRenderer->uTargetGBits == 5 )
    {
      v10 = (v8 | (((unsigned __int16)(lightColor & 0xF000) | (unsigned int)v9) >> 3)) >> 4;
      v11 = (int *)pTarget;
      v12 = pTargetZ;
      v13 = v22;
      v14 = (v10 << 16) | v10;
      z = (unsigned __int8)pTarget & 2;
      if ( (unsigned __int8)pTarget & 2 )
      {
        z = (unsigned int)*pTargetZ >> 16;
        if ( z > v23 )
        {
          z = v14 + ((*pTarget & 0x7BDEu) >> 1);
          *pTarget = z;
        }
        v13 = v22 - 1;
        v11 = (int *)(pTarget + 1);
        v12 = pTargetZ + 1;
      }
      while ( v13 != 1 )
      {
        if ( v13 < 1 )
          return z;
        z = (unsigned int)*v12 >> 16;
        if ( z <= v23 )
        {
          v13 -= 2;
          ++v11;
          v12 += 2;
        }
        else
        {
          v12 += 2;
          z = v14 + ((*v11 & 0x7BDE7BDEu) >> 1);
          v13 -= 2;
          *v11 = z;
          ++v11;
        }
      }
      z = (unsigned int)*v12 >> 16;
      if ( z > v23 )
      {
        z = v14 + ((*(short *)v11 & 0x7BDEu) >> 1);
        *(short *)v11 = z;
      }
    }
    else
    {
      v15 = (v8 | (((unsigned __int16)(lightColor & 0xF800) | (unsigned int)v9) >> 2)) >> 4;
      v16 = (int *)pTarget;
      v17 = pTargetZ;
      v18 = v22;
      v19 = (v15 << 16) | v15;
      z = (unsigned __int8)pTarget & 2;
      if ( (unsigned __int8)pTarget & 2 )
      {
        z = (unsigned int)*pTargetZ >> 16;
        if ( z > v23 )
        {
          z = v19 + ((*pTarget & 0xF7DEu) >> 1);
          *pTarget = z;
        }
        v18 = v22 - 1;
        v16 = (int *)(pTarget + 1);
        v17 = pTargetZ + 1;
      }
      while ( v18 != 1 )
      {
        if ( v18 < 1 )
          return z;
        z = (unsigned int)*v17 >> 16;
        if ( z <= v23 )
        {
          v18 -= 2;
          ++v16;
          v17 += 2;
        }
        else
        {
          v17 += 2;
          z = v19 + ((*v16 & 0xF7DEF7DEu) >> 1);
          v18 -= 2;
          *v16 = z;
          ++v16;
        }
      }
      z = (unsigned int)*v17 >> 16;
      if ( z > v23 )
      {
        z = v19 + ((*(short *)v16 & 0xF7DEu) >> 1);
        *(short *)v16 = z;
      }
    }
  }
  return z;
}


//----- (004A57E9) --------------------------------------------------------
void __cdecl Present_ColorKey()
{
  HRESULT v0; // eax@3
  HRESULT v1; // eax@3
  HRESULT v2; // eax@3
  HRESULT v3; // eax@3
  HRESULT v4; // eax@3
  RECT a2; // [sp+4h] [bp-14h]@3
  //CheckHRESULT_stru0 this; // [sp+14h] [bp-4h]@3

  if ( !pRenderer->uNumSceneBegins )
  {
    if ( pRenderer->field_40110 )
    {
      a2.bottom = pViewport->uViewportY;
      a2.left = 0;
      a2.top = 0;
      a2.right = 640;
      ErrD3D(pRenderer->pBackBuffer4->BltFast(0, 0, pRenderer->pColorKeySurface4, &a2, 16u));
      a2.right = 640;
      a2.left = 0;
      a2.top = pViewport->uViewportW + 1;
      a2.bottom = 480;
      ErrD3D(pRenderer->pBackBuffer4->BltFast(
             0,
             pViewport->uViewportW + 1,
             pRenderer->pColorKeySurface4,
             &a2,
             16u));
      a2.right = pViewport->uViewportX;
      a2.bottom = pViewport->uViewportW + 1;
      a2.left = 0;
      a2.top = pViewport->uViewportY;
      ErrD3D(pRenderer->pBackBuffer4->BltFast(
             0,
             pViewport->uViewportY,
             pRenderer->pColorKeySurface4,
             &a2,
             16u));
      a2.left = pViewport->uViewportZ;
      a2.top = pViewport->uViewportY;
      a2.right = 640;
      a2.bottom = pViewport->uViewportW + 1;
      ErrD3D(pRenderer->pBackBuffer4->BltFast(
             pViewport->uViewportZ,
             pViewport->uViewportY,
             pRenderer->pColorKeySurface4,
             &a2,
             16u));
      a2.right = pViewport->uViewportZ;
      a2.bottom = pViewport->uViewportW + 1;
      a2.left = pViewport->uViewportX;
      a2.top = pViewport->uViewportY;
      ErrD3D(pRenderer->pBackBuffer4->BltFast(
             pViewport->uViewportX,
             pViewport->uViewportY,
             pRenderer->pColorKeySurface4,
             &a2,
             17u));
    }
  }
}

//----- (004A597D) --------------------------------------------------------
void Present_NoColorKey()
{
  //unsigned __int16 *v0; // eax@4
  unsigned __int16 *v1; // esi@4
  void *v2; // edi@4
  //signed int v4; // ebx@4
  //signed int v5; // ebx@6
  //void *v6; // edi@7
  //const void *v7; // esi@7
  signed int v8; // ebx@8
  int v9; // eax@10
  unsigned int v10; // esi@10
  unsigned __int32 v11; // edi@10
  //int v12; // ecx@10
  unsigned int v13; // ebx@10
  int v14; // eax@11
  int v15; // eax@13
  int v16; // eax@14
  int v17; // eax@16
  HRESULT v18; // eax@22
  DDSURFACEDESC2 Dst; // [sp+Ch] [bp-98h]@3
  int v20; // [sp+88h] [bp-1Ch]@10
  int v21; // [sp+8Ch] [bp-18h]@10
  __int32 v22; // [sp+90h] [bp-14h]@10
  //unsigned __int32 v23; // [sp+94h] [bp-10h]@10
  unsigned int v24; // [sp+98h] [bp-Ch]@4
  //unsigned int _this; // [sp+9Ch] [bp-8h]@10
  //LPVOID v26; // [sp+A0h] [bp-4h]@4

  if ( !pRenderer->uNumSceneBegins )
  {
    if ( pRenderer->field_40110 )
    {
      memset(&Dst, 0, 0x7Cu);
      Dst.dwSize = 124;
      if ( pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, &Dst, DDLOCK_WAIT) )
      {
        //v26 = Dst.lpSurface;
        pRenderer->pCurrentlyLockedSurfaceDataPtr = (unsigned __int16 *)Dst.lpSurface;
        v24 = pRenderer->uTargetGMask | pRenderer->uTargetBMask |
              ((pRenderer->uTargetGMask | pRenderer->uTargetBMask) << 16);
        pRenderer->pCurrentlyLockedSoftSurface = pRenderer->pTargetSurface;
        pRenderer->uCurrentlyLockedSurfacePitch = Dst.lPitch;
        v1 = pRenderer->pTargetSurface;
        v2 = Dst.lpSurface;


        /*for (uint y = 0; y < 480; ++y)
        {
          auto pDst = (unsigned short *)((char *)Dst.lpSurface + y * Dst.lPitch);
          for (uint x = 0; x < 640; ++x)
            pDst[x] = pRenderer->uTargetRMask | pRenderer->uTargetBMask;
        }*/
        
        auto pSrc = pRenderer->pTargetSurface;
        auto pDst = (__int16 *)Dst.lpSurface;

        for (uint y = 0; y < 8; ++y)
          memcpy(pDst + y * Dst.lPitch / 2,

		  pSrc + y * 640, 640 * sizeof(__int16));

        for (uint y = 8; y < 352; ++y)
        {
          memcpy(pDst + y * Dst.lPitch / 2,
                 pSrc + y * 640, 8 * sizeof(__int16));
          memcpy(pDst + 8 + 460/*462*/ + y * Dst.lPitch / 2,
                 pSrc + 8 + 460/*462*/ + y * 640, 174/*172*/ * sizeof(__int16));
        }

        for (uint y = 352; y < 480; ++y)
          memcpy(pDst + y * Dst.lPitch / 2,
                 pSrc + y * 640, 640 * sizeof(__int16));


        auto pSrc_x1y1 = pSrc + 640 * pViewport->uViewportY + pViewport->uViewportX;
        //_this = (unsigned int)&pSrc[2 * (((signed int)pViewport->uViewportX >> 1) + 320 * pViewport->uViewportY)];
        auto pDst_x1y1 = pDst + Dst.lPitch * pViewport->uViewportY + pViewport->uViewportX;
        //v23 = (unsigned __int32)((char *)v26 + 4 * (((signed int)pViewport->uViewportX >> 1) + (Dst.lPitch >> 2) * pViewport->uViewportY));
        v9 = ((signed int)pViewport->uViewportX >> 1) - ((signed int)pViewport->uViewportZ >> 1);
        //v20 = ((signed int)pViewport->uViewportZ >> 1) - ((signed int)pViewport->uViewportX >> 1);
        v22 = 4 * ((Dst.lPitch / 4) + v9);
        v21 = 4 * v9 + 1280;

        //auto uNumLines = pViewport->uViewportW - pViewport->uViewportY + 1;
        //v26 = (LPVOID)(pViewport->uViewportW - pViewport->uViewportY + 1);
        v10 = (int)pSrc_x1y1;
        v11 = (int)pDst_x1y1;
        auto uHalfWidth = v20 = (pViewport->uViewportZ - pViewport->uViewportX) / 2;
        v13 = v24;

        for (uint y = pViewport->uViewportY; y < pViewport->uViewportW + 1; ++y)
        {
          //memcpy(pDst + pViewport->uViewportX + y * Dst.lPitch / 2,
          //       pSrc + pViewport->uViewportX + y * 640, (pViewport->uViewportZ - pViewport->uViewportX) * sizeof(__int16));
          for (uint x = pViewport->uViewportX; x < pViewport->uViewportZ; ++x)
          {
            if (pSrc[y * 640 + x] != (pRenderer->uTargetGMask | pRenderer->uTargetBMask))
              pDst[y * Dst.lPitch / 2 + x] = pSrc[y * 640 + x];
          }
        }

              ErrD3D(pRenderer->pBackBuffer4->Unlock(0));

       /* while ( 1 )
        {
          while ( 1 )
          {
            v14 = *(int *)v10;
            v10 += 4;
            if ( v14 == v13 )
              break;
            if ( (short)v14 == (short)v13 )
            {
              *(int *)v11 = *(int *)v11 & 0xFFFF | v14 & 0xFFFF0000;
              v11 += 4;
              --uHalfWidth;
              if ( !uHalfWidth )
                goto LABEL_21;
            }
            else
            {
              v15 = __ROL__(v14, 16);
              if ( (short)v15 == (short)v13 )
              {
                v17 = __ROR__(v15, 16);
                *(int *)v11 = *(int *)v11 & 0xFFFF0000 | (unsigned __int16)v17;
                v11 += 4;
                --uHalfWidth;
                if ( !uHalfWidth )
                  goto LABEL_21;
              }
              else
              {
                v16 = __ROR__(v15, 16);
                *(int *)v11 = v16;
                v11 += 4;
                --uHalfWidth;
                if ( !uHalfWidth )
                  goto LABEL_21;
              }
            }
          }
          v11 += 4;
          --uHalfWidth;
          if ( !uHalfWidth )
          {
LABEL_21:
            v10 += v21;
            v11 += v22;
            uHalfWidth = v20;
            if ( !--uNumLines )
            {
              ErrD3D(pRenderer->pBackBuffer4->Unlock(0));
              return;
            }
          }
        }*/
      }
    }
  }
}



//----- (004A7063) --------------------------------------------------------
int __thiscall sub_4A7063(unsigned int uDiffuse, float a2)
{
  float v2; // ST1C_4@1
  double v3; // ST14_8@1
  signed int v4; // ebx@1
  float v5; // ST1C_4@1
  double v6; // ST14_8@1
  signed int v7; // edi@1
  double v8; // ST0C_8@1
  signed int v9; // esi@1
  signed int v10; // ecx@1
  double v12; // [sp+8h] [bp-18h]@1
  unsigned __int64 v13; // [sp+18h] [bp-8h]@1

  v2 = (double)(uDiffuse >> 24) * a2;
  v3 = v2 + 6.7553994e15;
  v4 = LODWORD(v3);
  v5 = (double)((uDiffuse >> 16) & 0xFF) * a2;
  v6 = v5 + 6.7553994e15;
  v7 = LODWORD(v6);
  *((float *)&v6 + 1) = (double)((unsigned __int16)uDiffuse >> 8) * a2;
  v8 = *((float *)&v6 + 1) + 6.7553994e15;
  v13 = __PAIR__(LODWORD(v6), LODWORD(v8));
  v9 = LODWORD(v8);
  *((float *)&v6 + 1) = (double)(unsigned __int8)uDiffuse * a2;
  v12 = *((float *)&v6 + 1) + 6.7553994e15;
  v10 = LODWORD(v12);
  if ( v4 > 255 )
    v4 = 255;
  if ( v4 < 0 )
    v4 = 0;
  if ( SHIDWORD(v13) > 255 )
    v7 = 255;
  if ( v7 < 0 )
    v7 = 0;
  if ( (signed int)v13 > 255 )
    v9 = 255;
  if ( v9 < 0 )
    v9 = 0;
  if ( SLODWORD(v12) > 255 )
    v10 = 255;
  if ( v10 < 0 )
    v10 = 0;
  return v10 | ((v9 | ((v7 | (v4 << 8)) << 8)) << 8);
}





//----- (004AC1C9) --------------------------------------------------------
int __thiscall sub_4AC1C9(unsigned int _this, Vec4_int_ *a2)
{
  unsigned int v2; // esi@1
  __int16 v3; // di@1
  signed int v4; // ebx@1
  int v5; // ecx@3
  Vec4_int_ *v6; // eax@10
  Vec4_int_ *v7; // esi@14
  int result; // eax@16
  char *v9; // esi@16
  Vec4_int_ a1; // [sp+Ch] [bp-34h]@10
  Vec4_int_ v11; // [sp+1Ch] [bp-24h]@14
  Vec4_int_ Dst; // [sp+2Ch] [bp-14h]@1
  int v13; // [sp+3Ch] [bp-4h]@1

  v2 = _this;
  v3 = sub_4382BC(_this);
  v13 = sub_4383ED();
  v4 = 0;
  memset(&Dst, 0, 0x10u);
  if ( v3 < 0 )
    goto LABEL_19;
  if ( (signed int)v2 > 0 )
  {
    if ( (signed int)v2 > 150 )
    {
      v5 = (int)a2;
    }
    else
    {
      v5 = 4000 * v2;
      v4 = 1;
    }
  }
  else
  {
    v5 = 4000 * dword_4F031C[(unsigned __int16)v3];
  }
  if ( v13 & 0x10 && !v4 )
  {
    if ( v2 )
      v6 = sub_4AC4FD_get_cpu_clocks_rdtsc(v5, &a1);
    else
      v6 = sub_4AC33A_get_cpu_clocks_QPC(v5, &a1);
    goto LABEL_14;
  }
  if ( (unsigned __int16)v3 < 3u )
  {
LABEL_19:
    v7 = &Dst;
    goto LABEL_16;
  }
  v6 = sub_4AC277(v5, &a1);
LABEL_14:
  v11.x = v6->x;
  v11.y = v6->y;
  v11.z = v6->z;
  v11.w = v6->w;
  v7 = &v11;
LABEL_16:
  result = (int)a2;
  a2->x = v7->x;
  v9 = (char *)&v7->y;
  a2->y = *(int *)v9;
  v9 += 4;
  a2->z = *(int *)v9;
  a2->w = *((int *)v9 + 1);
  return result;
}
// 4F031C: using guessed type int dword_4F031C[];

//----- (004AC277) --------------------------------------------------------
Vec4_int_ *__thiscall sub_4AC277(unsigned int _this, Vec4_int_ *a2)
{
  __debugbreak();
  return 0;
  /*signed int v2; // esi@1
  signed __int16 v4; // bx@3
  int v10; // esi@8
  int v11; // eax@10
  Vec4_int_ *result; // eax@13
  Vec4_int_ Dst; // [sp+8h] [bp-30h]@1
  LARGE_INTEGER Frequency; // [sp+18h] [bp-20h]@1
  LARGE_INTEGER PerformanceCount; // [sp+20h] [bp-18h]@3
  LARGE_INTEGER v16; // [sp+28h] [bp-10h]@5
  int v17; // [sp+30h] [bp-8h]@1
  int v18; // [sp+34h] [bp-4h]@2

  v17 = _this;
  v2 = -1;
  memset(&Dst, 0, 0x10u);
  if ( QueryPerformanceFrequency(&Frequency) )
  {
    v18 = 10;
    do
    {
      QueryPerformanceCounter(&PerformanceCount);
      _EAX = -2147483648;
      v4 = 4000;
      do
      {
        __asm { bsf     ecx, eax }
        --v4;
      }
      while ( v4 );
      QueryPerformanceCounter(&v16);
      if ( (signed int)v16.s.LowPart - (signed int)PerformanceCount.s.LowPart < (unsigned int)v2 )
        v2 = v16.s.LowPart - PerformanceCount.s.LowPart;
      --v18;
    }
    while ( v18 );
    v10 = 100000 * v2 / (Frequency.s.LowPart / 0xA);
    if ( v10 % Frequency.s.LowPart > Frequency.s.LowPart >> 1 )
      ++v10;
    v11 = v17 / (unsigned int)v10;
    Dst.z = v17 / (unsigned int)v10;
    if ( v17 % (unsigned int)v10 > (unsigned int)v10 >> 1 )
      ++v11;
    Dst.x = v17;
    Dst.y = v10;
    Dst.w = v11;
  }
  result = a2;
  a2->x = Dst.x;
  a2->y = Dst.y;
  a2->z = Dst.z;
  a2->w = Dst.w;
  return result;*/
}

//----- (004AC33A) --------------------------------------------------------
Vec4_int_ *__thiscall sub_4AC33A_get_cpu_clocks_QPC(int _this, Vec4_int_ *a1)
{
  __debugbreak();
  return 0;
  /*int v2; // esi@1
  int v3; // ebx@1
  unsigned __int64 v4; // qax@4
  unsigned __int64 v5; // qax@7
  DWORD v6; // edi@7
  DWORD v7; // eax@7
  unsigned int v8; // ecx@10
  unsigned __int64 v9; // qax@10
  unsigned int v10; // edi@10
  int v11; // eax@14
  unsigned int v12; // ecx@19
  Vec4_int_ *result; // eax@24
  int Dst; // [sp+Ch] [bp-4Ch]@1
  int v15; // [sp+10h] [bp-48h]@23
  int v16; // [sp+14h] [bp-44h]@21
  int v17; // [sp+18h] [bp-40h]@21
  LARGE_INTEGER Frequency; // [sp+1Ch] [bp-3Ch]@1
  LARGE_INTEGER PerformanceCount; // [sp+24h] [bp-34h]@2
  LARGE_INTEGER v20; // [sp+2Ch] [bp-2Ch]@2
  int v21; // [sp+34h] [bp-24h]@2
  int v22; // [sp+38h] [bp-20h]@2
  int v23; // [sp+3Ch] [bp-1Ch]@4
  int v24; // [sp+40h] [bp-18h]@7
  int nPriority; // [sp+44h] [bp-14h]@2
  unsigned int v26; // [sp+48h] [bp-10h]@1
  unsigned int v27; // [sp+4Ch] [bp-Ch]@1
  HANDLE hThread; // [sp+50h] [bp-8h]@1
  int v29; // [sp+54h] [bp-4h]@1

  v2 = 0;
  v3 = 0;
  v29 = 0;
  v27 = 0;
  v26 = 0;
  hThread = GetCurrentThread();
  memset(&Dst, 0, 0x10u);
  if ( QueryPerformanceFrequency(&Frequency) )
  {
    do
    {
      ++v29;
      v22 = v2;
      v21 = v3;
      QueryPerformanceCounter(&PerformanceCount);
      v20 = PerformanceCount;
      nPriority = GetThreadPriority(hThread);
      if ( nPriority != 2147483647 )
        SetThreadPriority(hThread, 15);
      while ( v20.s.LowPart - PerformanceCount.s.LowPart < 0x32 )
      {
        QueryPerformanceCounter(&v20);
        v4 = __rdtsc();
        v23 = v4;
      }
      PerformanceCount = v20;
      do
      {
        QueryPerformanceCounter(&v20);
        v5 = __rdtsc();
        v24 = v5;
        v6 = v20.s.LowPart;
        v7 = PerformanceCount.s.LowPart;
      }
      while ( v20.s.LowPart - PerformanceCount.s.LowPart < 0x3E8 );
      if ( nPriority != 2147483647 )
      {
        SetThreadPriority(hThread, nPriority);
        v7 = PerformanceCount.s.LowPart;
        v6 = v20.s.LowPart;
      }
      v8 = v24 - v23;
      v27 += v24 - v23;
      v9 = (100000 * v6 - 100000 * v7) / (Frequency.s.LowPart / 0xA);
      v10 = v9;
      v26 += v9;
      if ( v9 % Frequency.s.LowPart > Frequency.s.LowPart >> 1 )
        v10 = v9 + 1;
      v3 = v8 / v10;
      if ( v8 % v10 > v10 >> 1 )
        v3 = v8 / v10 + 1;
      v2 = v21;
      v11 = v3 + v22 + v21;
    }
    while ( v29 < 3
         || v29 < 20
         && ((unsigned int)(3 * v3 - v11) > 3 || (unsigned int)(3 * v21 - v11) > 3 || (unsigned int)(3 * v22 - v11) > 3) );
    v12 = 10 * v27 / v26;
    if ( 100 * v27 / v26 - 10 * v12 >= 6 )
      ++v12;
    v16 = v27 / v26;
    v17 = v27 / v26;
    if ( v12 - 10 * v27 / v26 >= 6 )
      v17 = v27 / v26 + 1;
    v15 = v26;
    Dst = v27;
  }
  result = a1;
  a1->x = Dst;
  a1->y = v15;
  a1->z = v16;
  a1->w = v17;
  return result;*/
}

//----- (004AC4FD) --------------------------------------------------------
Vec4_int_ *__thiscall sub_4AC4FD_get_cpu_clocks_rdtsc(int _this, Vec4_int_ *a1)
{
  __debugbreak();
  return 0;
  /*int v2; // eax@1
  int v3; // eax@4
  bool v4; // eax@5
  unsigned __int64 v5; // kr00_8@8
  int v6; // edi@9
  int v7; // eax@9
  bool v8; // eax@10
  unsigned __int64 v9; // kr08_8@13
  unsigned int v10; // eax@15
  Vec4_int_ *result; // eax@17
  int Dst; // [sp+Ch] [bp-2Ch]@1
  int v13; // [sp+10h] [bp-28h]@17
  int v14; // [sp+14h] [bp-24h]@15
  int v15; // [sp+18h] [bp-20h]@17
  unsigned int v16; // [sp+1Ch] [bp-1Ch]@8
  unsigned int v17; // [sp+20h] [bp-18h]@8
  unsigned int v18; // [sp+24h] [bp-14h]@13
  int nPriority; // [sp+28h] [bp-10h]@1
  __int64 v20; // [sp+2Ch] [bp-Ch]@1
  int v21; // [sp+34h] [bp-4h]@3

  HIDWORD(v20) = GetCurrentThread();
  memset(&Dst, 0, 0x10u);
  v2 = GetThreadPriority(HIDWORD(v20));
  nPriority = v2;
  if ( v2 != 0x7FFFFFFF )
    SetThreadPriority(HIDWORD(v20), v2 + 1);
  __outbyte(0x70u, 0);
  v21 = __inbyte(0x71u);
  do
  {
    __outbyte(0x70u, 0);
    LODWORD(v20) = __inbyte(0x71u);
    v3 = v20 - v21;
    if ( (signed int)v20 >= v21 )
      v4 = v3 > 0;
    else
      v4 = v3 + 10;
  }
  while ( !v4 );
  v5 = __rdtsc();
  v16 = HIDWORD(v5);
  v17 = v5;
  do
  {
    __outbyte(0x70u, 0);
    v21 = __inbyte(0x71u);
    v6 = v21;
    v7 = v21 - v20;
    if ( v21 >= (signed int)v20 )
      v8 = v7 > 0;
    else
      v8 = v7 + 10;
  }
  while ( !v8 );
  v9 = __rdtsc();
  v18 = HIDWORD(v9);
  v21 = v9;
  if ( nPriority != 0x7FFFFFFF )
    SetThreadPriority(HIDWORD(v20), nPriority);
  nPriority = v21;
  *(__int64 *)((char *)&v20 + 4) = __PAIR__(v18, v21) - __PAIR__(v16, v17);
  Dst = HIDWORD(v20);
  v10 = HIDWORD(v20) / 0xF4240;
  v14 = HIDWORD(v20) / 0xF4240;
  if ( HIDWORD(v20) / 0x186A0 - 10 * HIDWORD(v20) / 0xF4240 >= 6 )
    ++v10;
  v15 = v10;
  result = a1;
  v13 = 1000000 * v6 - 1000000 * v20;
  a1->x = Dst;
  a1->y = v13;
  a1->z = v14;
  a1->w = v15;
  return result;*/
}



//----- (004AD504) --------------------------------------------------------
int __fastcall sub_4AD504(unsigned int uFaceID)
{
  int result; // eax@1
  unsigned int v2; // ebx@1
  BLVFace *v3; // esi@3
  Texture *v4; // edi@6
  int v5; // eax@7
  int v6; // edx@7
  int v7; // ecx@7
  int v8; // ebx@8
  int v9; // eax@8
  int v10; // ebx@8
  unsigned int v11; // ebx@9
  int v12; // esi@10
  int v13; // eax@13
  unsigned __int16 *v14; // eax@13
  unsigned int v15; // eax@14
  unsigned __int16 *v16; // ebx@14
  int v17; // eax@15
  int v18; // ebx@15
  int v19; // esi@15
  int v20; // ecx@15
  int v21; // eax@15
  stru193_math *v22; // ebx@15
  int v23; // eax@15
  char *v24; // esi@16
  int v25; // eax@18
  int v26; // eax@18
  int v27; // eax@20
  signed int v28; // esi@20
  signed int v29; // edx@20
  signed int v30; // esi@20
  signed int v31; // edi@20
  int v32; // esi@20
  int v33; // eax@26
  int *v34; // esi@27
  unsigned __int16 *v35; // edi@27
  unsigned int v36; // edx@27
  int v37; // ebx@27
  char v38; // cl@27
  char v39; // ch@27
  int v40; // ebx@29
  int v41; // edx@29
  unsigned int v42; // ebx@30
  int v43; // edx@30
  int v44; // eax@33
  int *v45; // esi@34
  unsigned __int16 *v46; // edi@34
  unsigned int v47; // edx@34
  int v48; // ebx@34
  char v49; // cl@34
  char v50; // ch@34
  int v51; // ebx@36
  int v52; // edx@36
  unsigned __int16 v53; // bx@37
  int v54; // edx@37
  int v55; // eax@40
  int v56; // eax@41
  int *v57; // esi@42
  unsigned __int16 *v58; // edi@42
  unsigned int v59; // edx@42
  int v60; // ebx@42
  char v61; // cl@42
  char v62; // ch@42
  unsigned int v63; // ebx@44
  int v64; // edx@44
  unsigned int v65; // ebx@44
  int v66; // edx@44
  unsigned int v67; // ebx@45
  int v68; // edx@45
  int v69; // ebx@45
  int v70; // edx@45
  int v71; // eax@48
  int *v72; // esi@49
  unsigned __int16 *v73; // edi@49
  unsigned int v74; // edx@49
  int v75; // ebx@49
  char v76; // cl@49
  char v77; // ch@49
  unsigned int v78; // ebx@51
  int v79; // edx@51
  unsigned int v80; // ebx@51
  int v81; // edx@51
  unsigned int v82; // ebx@52
  int v83; // edx@52
  int v84; // ebx@52
  int v85; // edx@52
  unsigned __int8 *v86; // [sp+Ch] [bp-98h]@9
  unsigned __int8 *v87; // [sp+10h] [bp-94h]@9
  unsigned __int8 *v88; // [sp+14h] [bp-90h]@9
  unsigned __int8 *v89; // [sp+18h] [bp-8Ch]@9
  int v90; // [sp+1Ch] [bp-88h]@20
  BLVFace *v91; // [sp+20h] [bp-84h]@3
  int v92; // [sp+24h] [bp-80h]@7
  int i; // [sp+28h] [bp-7Ch]@7
  unsigned __int16 *v94; // [sp+2Ch] [bp-78h]@9
  unsigned int v95; // [sp+30h] [bp-74h]@1
  Texture *v96; // [sp+34h] [bp-70h]@6
  int v97; // [sp+38h] [bp-6Ch]@15
  unsigned int v98; // [sp+3Ch] [bp-68h]@9
  int v99; // [sp+40h] [bp-64h]@9
  int v100; // [sp+44h] [bp-60h]@24
  int v101; // [sp+48h] [bp-5Ch]@10
  int v102; // [sp+4Ch] [bp-58h]@20
  int v103; // [sp+50h] [bp-54h]@20
  int v104; // [sp+54h] [bp-50h]@9
  unsigned __int8 *v105; // [sp+58h] [bp-4Ch]@20
  int v106; // [sp+5Ch] [bp-48h]@24
  int v107; // [sp+60h] [bp-44h]@20
  int v108; // [sp+64h] [bp-40h]@20
  int v109; // [sp+68h] [bp-3Ch]@20
  int v110; // [sp+6Ch] [bp-38h]@15
  int v111; // [sp+70h] [bp-34h]@20
  int a1; // [sp+74h] [bp-30h]@12
  int a2; // [sp+78h] [bp-2Ch]@9
  int *v114; // [sp+7Ch] [bp-28h]@16
  int v115; // [sp+80h] [bp-24h]@18
  int v116; // [sp+84h] [bp-20h]@7
  unsigned int v117; // [sp+88h] [bp-1Ch]@15
  unsigned int v118; // [sp+8Ch] [bp-18h]@24
  int *v119; // [sp+90h] [bp-14h]@13
  int v120; // [sp+94h] [bp-10h]@15
  unsigned int v121; // [sp+98h] [bp-Ch]@15
  unsigned __int16 *v122; // [sp+9Ch] [bp-8h]@15
  unsigned int v123; // [sp+A0h] [bp-4h]@13

  result = pRenderer->uTargetSurfacePitch;
  v2 = uFaceID;
  v95 = pRenderer->uTargetSurfacePitch;
  if ( (uFaceID & 0x80000000u) == 0 )
  {
    if ( (signed int)uFaceID < (signed int)pIndoor->uNumFaces )
    {
      v3 = &pIndoor->pFaces[uFaceID];
      v91 = &pIndoor->pFaces[uFaceID];
      if ( !pRenderer->pRenderD3D )
      {
        result = sub_423B5D(uFaceID);
        if ( result )
        {
          result = sub_424829(result, &stru_F8A590, pBLVRenderParams->field_7C, v2);
          if ( result )
          {
            result = (int)v3->GetTexture();
            v4 = (Texture *)result;
            v96 = (Texture *)result;
            if ( result )
            {
              v5 = *(short *)(result + 38);
              LOBYTE(v3->uAttributes) |= 0x80u;
              v92 = v5;
              sub_4AE5F1(v2);
              ++pBLVRenderParams->field_84;
              v6 = stru_F8AD28.pDeltaUV[0];
              v116 = stru_F8AD28.pDeltaUV[1];
              v7 = 0;
              for ( i = bUseLoResSprites; v7 < stru_F8AD28.uNumLightsApplied; *(int *)v9 = v10 )
              {
                v8 = v116;
                stru_F8AD28._blv_lights_xs[v7] += v6;
                v9 = 4 * v7 + 16297672;
                v10 = v8 - stru_F8AD28._blv_lights_ys[v7++];
              }
              v94 = sr_sub_47C24C_get_palette(v3, v92, 0, 1);
              result = stru_F8A590._viewport_space_y;
              a2 = stru_F8A590._viewport_space_y;
              v11 = stru_F8A590._viewport_space_y * pRenderer->uTargetSurfacePitch;
              v99 = 640 * stru_F8A590._viewport_space_y;
              v86 = v4->pLevelOfDetail0;
              v87 = v4->pLevelOfDetail1;
              v88 = v4->pLevelOfDetail2;
              v89 = v4->pLevelOfDetail3;
              v98 = stru_F8A590._viewport_space_y * pRenderer->uTargetSurfacePitch;
              v104 = 2 * pBLVRenderParams->field_0_timer_;
              if ( stru_F8A590._viewport_space_y <= stru_F8A590._viewport_space_w )
              {
                v12 = 2 * stru_F8A590._viewport_space_y;
                v101 = 2 * stru_F8A590._viewport_space_y;
                while ( 1 )
                {
                  a1 = *(__int16 *)((char *)stru_F8A590.array_18 + v12);
                  sub_4AE313(a1, result, &stru_F81018.field_0);
                  if ( LOBYTE(viewparams->field_20) )
                  {
                    v15 = v95 * (v12 - pBLVRenderParams->uViewportY);
                    v119 = &pBLVRenderParams->pTargetZBuffer[2
                                                          * (*(__int16 *)((char *)stru_F8A590.array_18 + v12)
                                                           + 320 * (v12 - pBLVRenderParams->uViewportY))
                                                          - pBLVRenderParams->uViewportX];
                    v16 = &pBLVRenderParams->pRenderTarget[v15
                                                        + 2 * *(__int16 *)((char *)stru_F8A590.array_18 + v12)
                                                        - pBLVRenderParams->uViewportX];
                    v14 = &pBLVRenderParams->pRenderTarget[v15
                                                        + 2 * *(__int16 *)((char *)stru_F8A590.array_3D8 + v12)
                                                        - pBLVRenderParams->uViewportX];
                    v123 = (unsigned int)v16;
                  }
                  else
                  {
                    v13 = *(__int16 *)((char *)stru_F8A590.array_18 + v12);
                    v119 = &pBLVRenderParams->pTargetZBuffer[v13 + v99];
                    v123 = (unsigned int)&pBLVRenderParams->pRenderTarget[v13 + v11];
                    v14 = &pBLVRenderParams->pRenderTarget[v11 + *(__int16 *)((char *)stru_F8A590.array_3D8 + v12)];
                  }
                  v117 = (unsigned int)v14;
                  HIWORD(v17) = HIWORD(stru_F81018.field_0.field_0);
                  v18 = stru_F81018.field_0.field_10;
                  LOWORD(v17) = 0;
                  v97 = stru_F8AD28.field_0 | v17;
                  v110 = sub_4AE491(SHIWORD(stru_F81018.field_0.field_4), SHIWORD(stru_F81018.field_0.field_8));
                  v19 = stru_F81018.field_0.field_4 >> i;
                  v20 = 11 - v18;
                  v116 = stru_F81018.field_0.field_8 >> i;
                  v21 = stru_F81018.field_0.field_8 >> i >> (11 - v18);
                  v22 = stru_5C6E00;
                  v122 = (unsigned __int16 *)v20;
                  v121 = (stru_F81018.field_0.field_4 >> i) + 4 * stru_5C6E00->Cos(v104 + v21);
                  v23 = stru_5C6E00->Sin(v104 + (v19 >> (char)v122));
                  v120 = v116 + 4 * v23;
                  if ( v123 < v117 )
                  {
                    v24 = (char *)&stru_F81018.field_34.field_8;
                    v114 = &stru_F81018.field_34.field_8;
                    a1 += 16;
                    while ( 1 )
                    {
                      sub_4AE313(a1, a2, (stru337_stru0 *)(v24 - 8));
                      v25 = *((int *)v24 - 2);
                      LOWORD(v25) = 0;
                      v115 = v97;
                      v26 = stru_F8AD28.field_0 | v25;
                      if ( v97 <= (unsigned int)v26 )
                        v115 = v26;
                      v97 = v26;
                      v27 = *((int *)v24 - 11);
                      v28 = *((int *)v24 - 1);
                      v105 = (&v86)[4 * v27];
                      v111 = v27 + 16;
                      v29 = v4->uWidthMinus1;
                      v109 = v27 + v27 + 16 - v4->uWidthLn2;
                      v107 = v29 >> v27;
                      v30 = v28 >> i;
                      v102 = v4->uHeightMinus1 >> v27 << (v27 + 16);
                      v31 = *v114 >> i;
                      v122 = (unsigned __int16 *)(11 - v27);
                      v116 = v30 + 4 * stru_5C6E00->Cos(v104 + (v31 >> (11 - v27)));
                      v90 = v31 + 4 * stru_5C6E00->Sin(v104 + (v30 >> (char)v122));
                      v108 = (signed int)(v116 - v121) >> 4;
                      v103 = (v90 - v120) >> 4;
                      v32 = v123 + 32;
                      if ( LOBYTE(viewparams->field_20) )
                        v32 = v123 + 64;
                      if ( v32 > v117 )
                        v32 = v117;
                      v118 = v32;
                      v100 = sub_4AE491(*((short *)v114 - 1), *((short *)v114 + 1));
                      v106 = (signed int)(v32 - v123) >> 1;
                      if ( v110 >> 16 == v100 >> 16 )
                      {
                        v122 = sr_sub_47C24C_get_palette(v91, v92, v110 >> 16, 1);
                        if ( LOBYTE(viewparams->field_20) )
                        {
                          v44 = v123;
                          if ( v123 < v118 )
                          {
                            v45 = v119;
                            v46 = v122;
                            v47 = v121;
                            v48 = v120;
                            v49 = v111;
                            v50 = v109;
                            if ( v106 & 2 )
                            {
                              *v119 = v115;
                              v45 -= 2;
                              v44 = v123 + 4;
                              goto LABEL_37;
                            }
                            do
                            {
                              v44 += 8;
                              v51 = *(&v105[v107 & (v47 >> v49)] + ((v102 & (unsigned int)v48) >> v50));
                              v52 = v115;
                              LOWORD(v51) = v46[v51];
                              *v45 = v115;
                              v45[1] = v52;
                              v45[640] = v52;
                              v45[641] = v52;
                              *(short *)(v44 - 8) = v51;
                              *(short *)(v44 - 6) = v51;
                              *(short *)(v44 + 1272) = v51;
                              *(short *)(v44 + 1274) = v51;
                              v45[2] = v52;
                              v45[3] = v52;
                              v45[642] = v52;
                              v45[643] = v52;
                              v121 += v108;
                              v120 += v103;
                              v47 = v121;
                              v48 = v120;
LABEL_37:
                              v45 += 4;
                              v53 = v46[*(&v105[v107 & (v47 >> v49)] + ((v102 & (unsigned int)v48) >> v50))];
                              v54 = v108;
                              *(short *)(v44 - 4) = v53;
                              *(short *)(v44 - 2) = v53;
                              *(short *)(v44 + 1276) = v53;
                              *(short *)(v44 + 1278) = v53;
                              v121 += v54;
                              v120 += v103;
                              v47 = v121;
                              v48 = v120;
                            }
                            while ( v44 < v118 );
                            v123 = v44;
                            v119 = v45;
                          }
                        }
                        else
                        {
                          v33 = v123;
                          if ( v123 < v118 )
                          {
                            v34 = v119;
                            v35 = v122;
                            v36 = v121;
                            v37 = v120;
                            v38 = v111;
                            v39 = v109;
                            if ( v106 & 1 )
                            {
                              *v119 = v115;
                              --v34;
                              v33 = v123 + 2;
                              goto LABEL_30;
                            }
                            do
                            {
                              v33 += 4;
                              v40 = *(&v105[v107 & (v36 >> v38)] + ((v102 & (unsigned int)v37) >> v39));
                              v41 = v115;
                              LOWORD(v40) = v35[v40];
                              *v34 = v115;
                              *(short *)(v33 - 4) = v40;
                              v34[1] = v41;
                              v121 += v108;
                              v120 += v103;
                              v36 = v121;
                              v37 = v120;
LABEL_30:
                              v42 = (unsigned int)(&v105[v107 & (v36 >> v38)] + ((v102 & (unsigned int)v37) >> v39));
                              v34 += 2;
                              v43 = v108;
                              *(short *)(v33 - 2) = v35[*(char *)v42];
                              v121 += v43;
                              v120 += v103;
                              v36 = v121;
                              v37 = v120;
                            }
                            while ( v33 < v118 );
                            v123 = v33;
                            v119 = v34;
                          }
                        }
                      }
                      else
                      {
                        v55 = v110 - ((v100 - v110) >> 4);
                        v110 = (v100 - v110) >> 4;
                        v122 = (unsigned __int16 *)v55;
                        if ( LOBYTE(viewparams->field_20) )
                        {
                          v71 = v123;
                          if ( v123 < v118 )
                          {
                            v72 = v119;
                            v73 = v94;
                            v74 = v121;
                            v75 = v120;
                            v76 = v111;
                            v77 = v109;
                            if ( v106 & 2 )
                            {
                              *v119 = v115;
                              v72 += 2;
                              v71 = v123 + 4;
                              goto LABEL_52;
                            }
                            do
                            {
                              v78 = (v107 & (v74 >> v76)) + ((v102 & (unsigned int)v75) >> v77);
                              v79 = (int)((char *)v122 + v110);
                              v71 += 8;
                              v122 = (unsigned __int16 *)v79;
                              v80 = ((v79 & 0xFFFF0000u) >> 8) + v105[v78];
                              v81 = v115;
                              LOWORD(v80) = v73[v80];
                              *v72 = v115;
                              v72[1] = v81;
                              v72[640] = v81;
                              v72[641] = v81;
                              *(short *)(v71 - 8) = v80;
                              *(short *)(v71 - 6) = v80;
                              *(short *)(v71 + 1272) = v80;
                              *(short *)(v71 + 1274) = v80;
                              v72[2] = v81;
                              v72[3] = v81;
                              v72[642] = v81;
                              v72[643] = v81;
                              v121 += v108;
                              v120 += v103;
                              v74 = v121;
                              v75 = v120;
                              v72 += 4;
LABEL_52:
                              v82 = (v107 & (v74 >> v76)) + ((v102 & (unsigned int)v75) >> v77);
                              v83 = (int)((char *)v122 + v110);
                              v84 = v105[v82];
                              v122 = (unsigned __int16 *)v83;
                              LOWORD(v84) = v73[((v83 & 0xFFFF0000u) >> 8) + v84];
                              v85 = v108;
                              *(short *)(v71 - 4) = v84;
                              *(short *)(v71 - 2) = v84;
                              *(short *)(v71 + 1276) = v84;
                              *(short *)(v71 + 1278) = v84;
                              v121 += v85;
                              v120 += v103;
                              v74 = v121;
                              v75 = v120;
                            }
                            while ( v71 < v118 );
                            v123 = v71;
                            v119 = v72;
                          }
                        }
                        else
                        {
                          v56 = v123;
                          if ( v123 < v118 )
                          {
                            v57 = v119;
                            v58 = v94;
                            v59 = v121;
                            v60 = v120;
                            v61 = v111;
                            v62 = v109;
                            if ( v106 & 1 )
                            {
                              *v119 = v115;
                              ++v57;
                              v56 = v123 + 2;
                              goto LABEL_45;
                            }
                            do
                            {
                              v63 = (v107 & (v59 >> v61)) + ((v102 & (unsigned int)v60) >> v62);
                              v64 = (int)((char *)v122 + v110);
                              v56 += 4;
                              v122 = (unsigned __int16 *)v64;
                              v65 = ((v64 & 0xFFFF0000u) >> 8) + v105[v63];
                              v66 = v115;
                              LOWORD(v65) = v58[v65];
                              *v57 = v115;
                              *(short *)(v56 - 4) = v65;
                              v57[1] = v66;
                              v121 += v108;
                              v120 += v103;
                              v59 = v121;
                              v60 = v120;
                              v57 += 2;
LABEL_45:
                              v67 = (v107 & (v59 >> v61)) + ((v102 & (unsigned int)v60) >> v62);
                              v68 = (int)((char *)v122 + v110);
                              v69 = v105[v67];
                              v122 = (unsigned __int16 *)v68;
                              LOWORD(v69) = v58[((v68 & 0xFFFF0000u) >> 8) + v69];
                              v70 = v108;
                              *(short *)(v56 - 2) = v69;
                              v121 += v70;
                              v120 += v103;
                              v59 = v121;
                              v60 = v120;
                            }
                            while ( v56 < v118 );
                            v123 = v56;
                            v119 = v57;
                          }
                        }
                      }
                      v114 += 13;
                      v110 = v100;
                      a1 += 16;
                      v4 = v96;
                      v121 = v116;
                      v120 = v90;
                      if ( v123 >= v117 )
                        break;
                      v24 = (char *)v114;
                      v22 = stru_5C6E00;
                    }
                  }
                  ++a2;
                  v98 += v95;
                  result = a2;
                  v101 += 2;
                  v99 += 640;
                  if ( a2 > stru_F8A590._viewport_space_w )
                    break;
                  v12 = v101;
                  result = a2;
                  v11 = v98;
                }
              }
            }
          }
        }
      }
    }
  }
  return result;
}
// 4AE491: using guessed type int __fastcall sub_4AE491(int, int);

//----- (004ADD1D) --------------------------------------------------------
void __fastcall sub_4ADD1D(int uFaceID)
{
  int v1; // edi@1
  BLVFace *v2; // esi@3
  signed int v3; // ebx@4
  Texture *v4; // edi@9
  signed int v5; // eax@9
  char *v6; // edi@12
  signed int v7; // eax@15
  unsigned int v8; // eax@16
  __int16 v9; // cx@19
  unsigned __int8 *v10; // eax@19
  unsigned __int16 *v11; // eax@19
  int v12; // edi@19
  int v13; // ebx@20
  stru352 *v14; // esi@20
  DWORD v15; // eax@22
  signed int v16; // ecx@22
  signed int v17; // ST68_4@22
  int v18; // eax@22
  int v19; // ecx@22
  unsigned int v20; // esi@23
  int v21; // edi@23
  int v22; // eax@23
  int *v23; // ebx@24
  int v24; // edx@24
  int v25; // ebx@25
  unsigned __int16 v26; // cx@25
  int v27; // edx@26
  unsigned __int16 v28; // cx@26
  unsigned __int8 v29; // sf@27
  unsigned __int8 v30; // of@27
  unsigned int v31; // esi@29
  int v32; // edi@29
  unsigned __int16 *v33; // eax@29
  int *v34; // ebx@30
  int v35; // edx@30
  int v36; // ebx@31
  unsigned __int16 v37; // cx@31
  int v38; // edx@32
  unsigned __int16 v39; // cx@32
  Texture *v40; // [sp-10h] [bp-6Ch]@16
  int v41; // [sp-Ch] [bp-68h]@15
  unsigned int v42; // [sp+10h] [bp-4Ch]@1
  signed int v43; // [sp+14h] [bp-48h]@12
  signed int v44; // [sp+14h] [bp-48h]@22
  int v45; // [sp+1Ch] [bp-40h]@22
  int v46; // [sp+20h] [bp-3Ch]@22
  int v47; // [sp+24h] [bp-38h]@19
  char v48; // [sp+28h] [bp-34h]@19
  int v49; // [sp+2Ch] [bp-30h]@19
  unsigned __int8 *v50; // [sp+30h] [bp-2Ch]@19
  unsigned __int16 *v51; // [sp+34h] [bp-28h]@19
  int v52; // [sp+38h] [bp-24h]@22
  int v53; // [sp+3Ch] [bp-20h]@22
  signed int v54; // [sp+40h] [bp-1Ch]@12
  int v55; // [sp+40h] [bp-1Ch]@20
  int v56; // [sp+44h] [bp-18h]@20
  stru352 *i; // [sp+48h] [bp-14h]@20
  unsigned __int16 *v58; // [sp+4Ch] [bp-10h]@23
  int v59; // [sp+50h] [bp-Ch]@4
  int v60; // [sp+50h] [bp-Ch]@19
  int v61; // [sp+54h] [bp-8h]@22
  int *v62; // [sp+58h] [bp-4h]@23
  int *v63; // [sp+58h] [bp-4h]@29

  v1 = uFaceID;
  v42 = pRenderer->uTargetSurfacePitch;
  if ( uFaceID >= 0 && uFaceID < (signed int)pIndoor->uNumFaces )
  {
    v2 = &pIndoor->pFaces[uFaceID];
    if ( pRenderer->pRenderD3D )
    {
      v3 = sub_424579(uFaceID, &stru_F8AD28);
      v59 = v3;
    }
    else
    {
      v59 = sub_423B5D(uFaceID);
      v3 = v59;
    }
    if ( v3 && (pRenderer->pRenderD3D || sub_424829(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1)) )
    {
      v4 = v2->GetTexture();
      v5 = 0;
      if ( v4 )
      {
        if ( pRenderer->pRenderD3D )
        {
          if ( v3 > 0 )
          {
            v54 = v3;
            v43 = v3;
            v6 = (char *)&array_507D30[0].v;
            do
            {
              *((float *)v6 - 1) = (double)((GetTickCount() >> 5) - pBLVRenderParams->vPartyPos.x) + *((float *)v6 - 1);
              *(float *)v6 = (double)(pBLVRenderParams->vPartyPos.y + (GetTickCount() >> 5)) + *(float *)v6;
              v6 += 48;
              --v54;
            }
            while ( v54 );
            v3 = v59;
            v5 = v43;
          }
          v7 = v5;
          v41 = stru_F8AD28.field_0;
          array_507D30[v7].u = array_507D30[v7].u * 0.25;
          array_507D30[v7].v = array_507D30[v7].v * 0.25;
          if ( BYTE1(v2->uAttributes) & 0x40 )
          {
            v40 = v2->GetTexture();
            v8 = pTextureFrameTable->GetFrameTexture(v2->uBitmapID, pBLVRenderParams->field_0_timer_);
          }
          else
          {
            v40 = v2->GetTexture();
            v8 = v2->uBitmapID;
          }
          pRenderer->DrawIndoorPolygon(v3, v2, pBitmaps_LOD->pHardwareTextures[v8], v40, v41, -1, 0);
        }
        else
        {
          v49 = v4->uWidthMinus1;
          v47 = v4->uHeightMinus1 << 16;
          v9 = 16 - v4->uWidthLn2;
          v10 = v4->pLevelOfDetail0;
          LOBYTE(v2->uAttributes) |= 0x80u;
          v48 = v9;
          v50 = v10;
          sub_4AF412();
          ++pBLVRenderParams->uNumFacesRenderedThisFrame;
          v11 = sr_sub_47C24C_get_palette(v2, v4->palette_id2, 0, 1);
          v12 = stru_F8A590._viewport_space_y;
          v51 = v11;
          v60 = stru_F8A590._viewport_space_y;
          if ( stru_F8A590._viewport_space_y <= stru_F8A590._viewport_space_w )
          {
            v13 = 2 * stru_F8A590._viewport_space_y;
            v14 = &stru_F83B80[stru_F8A590._viewport_space_y];
            v55 = 2 * stru_F8A590._viewport_space_y;
            v56 = 640 * stru_F8A590._viewport_space_y;
            for ( i = &stru_F83B80[stru_F8A590._viewport_space_y]; ; v14 = i )
            {
              sub_4AE1E7(v12, *(__int16 *)((char *)stru_F8A590.array_18 + v13), v12);
              v14->field_0 += (GetTickCount() << 11) - (pBLVRenderParams->vPartyPos.x << 16);
              v15 = GetTickCount();
              v16 = v14->field_0;
              v14->field_4 += (32 * pBLVRenderParams->vPartyPos.y + v15) << 11;
              v45 = v14->field_4 >> 3;
              v44 = v16 >> 3;
              v17 = (signed int)((unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)v14->field_28) >> 16) >> 3;
              v52 = (unsigned __int64)(v17 * (signed __int64)-pBLVRenderParams->sSineY) >> 16;
              v53 = (unsigned __int64)(v17 * (signed __int64)pBLVRenderParams->sCosineY) >> 16;
              v18 = v14->field_28;
              v19 = *(__int16 *)((char *)stru_F8A590.array_18 + v13);
              LOWORD(v18) = 0;
              v46 = stru_F8AD28.field_0 | v18;
              v61 = *(__int16 *)((char *)stru_F8A590.array_3D8 + v13) - v19;
              if ( LOBYTE(viewparams->field_20) )
              {
                v63 = &pBLVRenderParams->pTargetZBuffer[2 * (v19 + 320 * (v13 - pBLVRenderParams->uViewportY))
                                                     - pBLVRenderParams->uViewportX];
                v31 = v44;
                v32 = v45;
                v33 = &pBLVRenderParams->pRenderTarget[v42 * (v13 - pBLVRenderParams->uViewportY)
                                                    + 2 * v19
                                                    - pBLVRenderParams->uViewportX];
                if ( v61 & 1 )
                {
                  --v61;
                  v33 = &pBLVRenderParams->pRenderTarget[v42 * (v13 - pBLVRenderParams->uViewportY)
                                                      + 2 * v19
                                                      - pBLVRenderParams->uViewportX
                                                      - 2];
                  v34 = &pBLVRenderParams->pTargetZBuffer[2 * (v19 + 320 * (v13 - pBLVRenderParams->uViewportY))
                                                       - pBLVRenderParams->uViewportX];
                  v35 = v46;
                  v63 += 2;
                  goto LABEL_32;
                }
                while ( 1 )
                {
                  v30 = __OFSUB__(v61, 2);
                  v29 = v61 - 2 < 0;
                  v61 -= 2;
                  if ( v29 ^ v30 )
                    break;
                  v36 = *(&v50[v49 & (v31 >> 16)] + ((v47 & (unsigned int)v32) >> v48));
                  v31 += v52;
                  v37 = v51[v36];
                  v32 += v53;
                  v34 = v63;
                  v35 = v46;
                  *v33 = v37;
                  v33[1] = v37;
                  v33[640] = v37;
                  v33[641] = v37;
                  v63 += 4;
                  v34[2] = v46;
                  v34[3] = v46;
                  v34[642] = v46;
                  v34[643] = v46;
LABEL_32:
                  *v34 = v35;
                  v34[1] = v35;
                  v34[640] = v35;
                  v34[641] = v35;
                  v38 = v49 & (v31 >> 16);
                  v33 += 4;
                  v31 += v52;
                  v39 = v51[*(&v50[v38] + ((v47 & (unsigned int)v32) >> v48))];
                  v32 += v53;
                  *(v33 - 2) = v39;
                  *(v33 - 1) = v39;
                  v33[638] = v39;
                  v33[639] = v39;
                }
              }
              else
              {
                v58 = &pBLVRenderParams->pRenderTarget[v19 + v12 * pRenderer->uTargetSurfacePitch];
                v62 = &pBLVRenderParams->pTargetZBuffer[v56 + v19];
                v20 = v44;
                v21 = v45;
                v22 = (int)v58;
                if ( v61 & 1 )
                {
                  --v61;
                  v22 = (int)(v58 - 1);
                  v23 = &pBLVRenderParams->pTargetZBuffer[v56 + v19];
                  v24 = v46;
                  ++v62;
                  goto LABEL_26;
                }
                while ( 1 )
                {
                  v30 = __OFSUB__(v61, 2);
                  v29 = v61 - 2 < 0;
                  v61 -= 2;
                  if ( v29 ^ v30 )
                    break;
                  v25 = *(&v50[v49 & (v20 >> 16)] + ((v47 & (unsigned int)v21) >> v48));
                  v20 += v52;
                  v26 = v51[v25];
                  v21 += v53;
                  v23 = v62;
                  v24 = v46;
                  *(short *)v22 = v26;
                  v62 += 2;
                  v23[1] = v46;
LABEL_26:
                  *v23 = v24;
                  v27 = v49 & (v20 >> 16);
                  v22 += 4;
                  v20 += v52;
                  v28 = v51[*(&v50[v27] + ((v47 & (unsigned int)v21) >> v48))];
                  v21 += v53;
                  *(short *)(v22 - 2) = v28;
                }
              }
              ++v60;
              ++i;
              v56 += 640;
              v55 += 2;
              if ( v60 > stru_F8A590._viewport_space_w )
                break;
              v13 = v55;
              v12 = v60;
            }
          }
        }
      }
    }
  }
}

//----- (004AE1E7) --------------------------------------------------------
int __fastcall sub_4AE1E7(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  signed __int64 v6; // qtt@3
  int v7; // esi@3
  int v8; // eax@5
  int result; // eax@5
  int v10; // edx@5
  int v11; // [sp+Ch] [bp-8h]@1
  int v12; // [sp+1Ch] [bp+8h]@2

  v3 = pBLVRenderParams->uViewportCenterY - a3;
  v4 = pBLVRenderParams->uViewportCenterX - a2;
  v11 = a1;
  v5 = (pBLVRenderParams->uViewportCenterY - a3) * stru_F8AD28.vec_80.y
     + stru_F8AD28.field_7C
     + (pBLVRenderParams->uViewportCenterX - a2) * stru_F8AD28.vec_80.x;
  if ( v5 && (v12 = abs(stru_F8AD28.vec_80.z) >> 14, v12 <= abs(v5)) )
  {
    LODWORD(v6) = stru_F8AD28.vec_80.z << 16;
    HIDWORD(v6) = stru_F8AD28.vec_80.z >> 16;
    v7 = v6 / (v3 * stru_F8AD28.vec_80.y + stru_F8AD28.field_7C + v4 * stru_F8AD28.vec_80.x);
  }
  else
  {
    v7 = 1073741824;
  }
  v8 = stru_F8AD28.vec_9C.z;
  stru_F83B80[v11].field_0 = ((unsigned __int64)((v3 * stru_F8AD28.vec_8C.z
                                                + stru_F8AD28.vec_8C.x
                                                + v4 * stru_F8AD28.vec_8C.y)
                                               * (signed __int64)v7) >> 16)
                           + stru_F8AD28.field_98;
  result = (unsigned __int64)((v3 * v8 + stru_F8AD28.vec_9C.x + v4 * stru_F8AD28.vec_9C.y) * (signed __int64)v7) >> 16;
  v10 = result + stru_F8AD28.field_A8;
  stru_F83B80[v11].field_28 = v7;
  stru_F83B80[v11].field_4 = v10;
  return result;
}

//----- (004AE313) --------------------------------------------------------
int __fastcall sub_4AE313(int viewport_space_x, int viewport_space_y, stru337_stru0 *p)
{
  int _dy; // ebx@1
  int _dx; // edi@1
  int v5; // ecx@1
  int v6; // esi@1
  int v7; // ST18_4@2
  signed __int64 v8; // qtt@3
  unsigned int v9; // ecx@3
  int result; // eax@8
  int v11; // [sp+Ch] [bp-8h]@1

  _dy = pBLVRenderParams->uViewportCenterY - viewport_space_y;
  _dx = pBLVRenderParams->uViewportCenterX - viewport_space_x;
  ++pBLVRenderParams->field_88;
  v5 = (pBLVRenderParams->uViewportCenterY - viewport_space_y) * stru_F8AD28.vec_80.y + stru_F8AD28.field_7C;
  v6 = v5 + _dx * stru_F8AD28.vec_80.x;
  v11 = v5 + _dx * stru_F8AD28.vec_80.x;
  if ( v5 + _dx * stru_F8AD28.vec_80.x && (v7 = abs(stru_F8AD28.vec_80.z) >> 14, v7 <= abs(v6)) )
  {
    LODWORD(v8) = stru_F8AD28.vec_80.z << 16;
    HIDWORD(v8) = stru_F8AD28.vec_80.z >> 16;
    v9 = v8 / v11;
  }
  else
  {
    v9 = 0x40000000u;
  }
  if ( (signed int)v9 >= stru_F8AD28.field_34 )
    p->field_0 = v9;
  else
    p->field_0 = stru_F8AD28.field_34;
  p->field_4 = ((unsigned __int64)((_dy * stru_F8AD28.vec_8C.z + stru_F8AD28.vec_8C.x + _dx * stru_F8AD28.vec_8C.y)
                                 * (signed __int64)(signed int)v9) >> 16)
             + stru_F8AD28.field_98
             + (stru_F8AD28.pDeltaUV[0] << 16);
  p->field_8 = ((unsigned __int64)((_dy * stru_F8AD28.vec_9C.z + stru_F8AD28.vec_9C.x + _dx * stru_F8AD28.vec_9C.y)
                                 * (signed __int64)(signed int)v9) >> 16)
             + stru_F8AD28.field_A8
             + (stru_F8AD28.pDeltaUV[1] << 16);
  result = abs((__int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)(signed int)v9) >> 16);
  if ( result < 369620 || bUseLoResSprites )
  {
    if ( result < 184810 )
      p->field_10 = result > 92405;
    else
      p->field_10 = 2;
  }
  else
  {
    p->field_10 = 3;
  }
  return result;
}

//----- (004AE491) --------------------------------------------------------
int __fastcall sub_4AE491(signed int a1, signed int a2)
{
  signed int v2; // eax@1
  signed int v3; // edi@1
  int v4; // ecx@1
  int v5; // esi@2
  int v6; // eax@2
  int v7; // ebx@2
  unsigned int v8; // ecx@2
  int v9; // edx@5
  int v10; // edx@7
  unsigned int v11; // eax@8
  int v13; // [sp+4h] [bp-18h]@2
  int v14; // [sp+8h] [bp-14h]@2
  signed int v15; // [sp+Ch] [bp-10h]@1
  int v16; // [sp+14h] [bp-8h]@1
  int v17; // [sp+18h] [bp-4h]@1

  v2 = a1 >> SLOBYTE(stru_F8AD28.field_38);
  v3 = a2 >> SLOBYTE(stru_F8AD28.field_38);
  v17 = stru_F8AD28.uCurrentAmbientLightLevel;
  v4 = 0;
  v15 = v2;
  v16 = 0;
  if ( stru_F8AD28.uNumLightsApplied > 0 )
  {
    do
    {
      v5 = v16;
      v13 = abs(v2 - stru_F8AD28._blv_lights_xs[v16]);
      v14 = abs(v3 - stru_F8AD28._blv_lights_ys[v16]);
      v6 = stru_F8AD28._blv_lights_light_dot_faces[v16];
      v7 = v13;
      v8 = v14;
      if ( v6 < v13 )
      {
        v6 = v13;
        v7 = stru_F8AD28._blv_lights_light_dot_faces[v16];
      }
      if ( v6 < v14 )
      {
        v9 = v6;
        v6 = v14;
        v8 = v9;
      }
      if ( v7 < (signed int)v8 )
      {
        v10 = v8;
        v8 = v7;
        v7 = v10;
      }
      v11 = ((unsigned int)(11 * v7) >> 5) + (v8 >> 2) + v6;
      if ( (signed int)v11 < stru_F8AD28._blv_lights_radii[v5] )
        v17 += 30 * (v11 * stru_F8AD28._blv_lights_inv_radii[v5] - 65536);
      ++v16;
      v2 = v15;
    }
    while ( v16 < stru_F8AD28.uNumLightsApplied );
    v4 = 0;
  }
  if ( stru_F8AD28.field_3E4 != v4 )
    v17 -= stru_F8AD28.field_3E8 * (v2 - stru_F8AD28.field_3F0) + stru_F8AD28.field_3EC * (v3 - stru_F8AD28.field_3F4);
  if ( v17 >= v4 )
  {
    if ( v17 > 2031616 )
      v17 = 2031616;
  }
  else
  {
    v17 = v4;
  }
  ++pBLVRenderParams->field_8C;
  return v17;
}
// 4AE491: using guessed type int __fastcall sub_4AE491(int, int);




//----- (004AE5F1) --------------------------------------------------------
void __fastcall sub_4AE5F1(unsigned int uFaceID)
{
  BLVFace *v1; // esi@1
  BLVFaceExtra *v2; // ebx@1
  int v3; // eax@1
  int v4; // edi@1
  Texture *v5; // edi@1
  int v6; // eax@1
  unsigned int v7; // eax@1
  unsigned int v8; // ecx@1
  unsigned int v9; // eax@1
  unsigned int v10; // ecx@5
  int v11; // edi@10
  int v12; // ecx@10
  int v13; // eax@10
  int v14; // edx@10
  int v15; // ebx@12
  double v16; // st7@16
  int v17; // eax@16
  char *v18; // ebx@17
  int v19; // ecx@19
  int v20; // eax@19
  int v21; // edx@21
  int v22; // eax@23
  int v23; // ST04_4@26
  int v24; // edi@26
  double v25; // st6@26
  int v26; // eax@26
  double v27; // st6@26
  int v28; // ecx@26
  char v29; // al@26
  int v30; // edx@28
  int v31; // ecx@28
  BLVLightMM7 *v32; // ecx@32
  int v33; // edi@33
  int v34; // edx@33
  int v35; // eax@33
  int v36; // edi@35
  int v37; // edx@37
  int v38; // ebx@39
  int v39; // edi@42
  int v40; // eax@42
  char *v41; // ebx@45
  signed int v42; // ecx@47
  int v43; // edi@47
  int v44; // eax@49
  int v45; // edx@51
  int v46; // eax@53
  int v47; // ST04_4@55
  int v48; // edi@55
  double v49; // st6@55
  int v50; // eax@55
  double v51; // st6@55
  int v52; // eax@55
  int v53; // ecx@57
  int v54; // ecx@58
  int v55; // ecx@59
  int v56; // edx@62
  int v57; // ecx@62
  int v58; // eax@63
  int v59; // edx@64
  int v60; // ecx@67
  int v61; // edx@67
  int v62; // eax@68
  int v63; // edx@69
  signed int v64; // ecx@72
  double v65; // st7@75
  Vec3_int_ v66; // [sp+Ch] [bp-34h]@9
  Vec3_int_ v67; // [sp+18h] [bp-28h]@9
  BLVFaceExtra *v68; // [sp+24h] [bp-1Ch]@1
  int v69; // [sp+28h] [bp-18h]@10
  int v70; // [sp+2Ch] [bp-14h]@10
  int X; // [sp+30h] [bp-10h]@10
  int v72; // [sp+34h] [bp-Ch]@10
  int v73; // [sp+38h] [bp-8h]@10
  int v74; // [sp+3Ch] [bp-4h]@10

  v1 = &pIndoor->pFaces[uFaceID];
  v2 = &pIndoor->pFaceExtras[v1->uFaceExtraID];
  v3 = v1->uBitmapID;
  v4 = v1->uBitmapID;
  v68 = v2;
  v5 = (Texture *)(v4 != -1 ? (int)&pBitmaps_LOD->pTextures[v3] : 0);
  v6 = 8 * uFaceID;
  LOBYTE(v6) = 8 * uFaceID | 6;
  stru_F8AD28.field_0 = v6;
  stru_F8AD28.plane_4.vNormal.x = v1->pFacePlane_old.vNormal.x;
  stru_F8AD28.plane_4.vNormal.y = v1->pFacePlane_old.vNormal.y;
  stru_F8AD28.plane_4.vNormal.z = v1->pFacePlane_old.vNormal.z;
  stru_F8AD28.plane_4.dist = v1->pFacePlane_old.dist;
  stru_F8AD28.pDeltaUV[0] = v2->sTextureDeltaU;
  stru_F8AD28.pDeltaUV[1] = v2->sTextureDeltaV;
  v7 = GetTickCount();
  v8 = v1->uAttributes;
  v9 = v7 >> 3;
  if ( v8 & 4 )
  {
    stru_F8AD28.pDeltaUV[1] -= v9 & v5->uHeightMinus1;
  }
  else
  {
    if ( v8 & 0x20 )
      stru_F8AD28.pDeltaUV[1] += v9 & v5->uHeightMinus1;
  }
  v10 = v1->uAttributes;
  if ( BYTE1(v10) & 8 )
  {
    stru_F8AD28.pDeltaUV[0] -= v9 & v5->uWidthMinus1;
  }
  else
  {
    if ( v10 & 0x40 )
      stru_F8AD28.pDeltaUV[0] += v9 & v5->uWidthMinus1;
  }
  v1->_get_normals(&v67, &v66);
  stru_F8AD28.vec_14.x = v67.x;
  stru_F8AD28.vec_14.y = v67.y;
  stru_F8AD28.vec_14.z = v67.z;
  stru_F8AD28.vec_20.x = v66.x;
  stru_F8AD28.vec_20.y = v66.y;
  stru_F8AD28.vec_20.z = v66.z;
  stru_F8AD28.uDefaultAmbientLightLevel = v2->field_22;
  if ( pBLVRenderParams->sPartyRotX )
  {
    v74 = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
    v74 = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16) - v74;
    X = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
    stru_F8AD28.rotated_normal.x = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16) - X;
    stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
                                                     * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                                 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
                                                     * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.rotated_normal.z = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
                                 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
                                                     * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
    v70 = (unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
    v74 = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16) - v70;
    v70 = (unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
    stru_F8AD28.vec_60.y = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16) - v70;
    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.field_6C = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
    v70 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
    v74 = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16) - v70;
    X = (unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16;
    v72 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16;
    v70 = (unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
    stru_F8AD28.vec_70.x = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16) - v70;
    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.vec_70.z = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
    v74 = pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.y
        - pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.x;
    v11 = -(pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.y
          + pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.x);
    v73 = -65536 * pBLVRenderParams->vPartyPos.z;
    v70 = (unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
    v12 = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16) - v70;
    v69 = (unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
    v13 = pBLVRenderParams->vPartyPos.y;
    v70 = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
        + ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
    v14 = pBLVRenderParams->vPartyPos.x;
  }
  else
  {
    v70 = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
    stru_F8AD28.rotated_normal.x = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
                                                     * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
                                 - v70;
    stru_F8AD28.rotated_normal.z = stru_F8AD28.plane_4.vNormal.z;
    stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
                                                     * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                                 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
                                                     * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    v70 = (unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
    stru_F8AD28.vec_60.y = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
                         - v70;
    stru_F8AD28.field_6C = stru_F8AD28.vec_14.z;
    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    v70 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
    stru_F8AD28.vec_70.x = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
                         - v70;
    v69 = (unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16;
    v14 = pBLVRenderParams->vPartyPos.x;
    stru_F8AD28.vec_70.z = stru_F8AD28.vec_20.z;
    v13 = pBLVRenderParams->vPartyPos.y;
    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    v12 = pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.y
        - pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.x;
    v11 = -(pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.y
          + pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.x);
    v70 = -65536 * pBLVRenderParams->vPartyPos.z;
  }
  stru_F8AD28.field_7C = stru_F8AD28.rotated_normal.x;
  stru_F8AD28.vec_60.x = stru_F8AD28.plane_4.vNormal.z * pBLVRenderParams->vPartyPos.z
                       + stru_F8AD28.plane_4.dist
                       + stru_F8AD28.plane_4.vNormal.y * v13
                       + stru_F8AD28.plane_4.vNormal.x * v14;
  stru_F8AD28.vec_80.x = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44)
                                          * (signed __int64)stru_F8AD28.rotated_normal.y) >> 16;
  stru_F8AD28.vec_80.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44)
                                          * (signed __int64)stru_F8AD28.rotated_normal.z) >> 16;
  stru_F8AD28.vec_80.z = -stru_F8AD28.vec_60.x;
  stru_F8AD28.vec_8C.x = stru_F8AD28.vec_60.y;
  stru_F8AD28.vec_8C.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_60.z) >> 16;
  stru_F8AD28.vec_8C.z = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.field_6C) >> 16;
  X = (unsigned __int64)(stru_F8AD28.vec_60.y * (signed __int64)v12) >> 16;
  v15 = v70;
  v70 = (unsigned __int64)(stru_F8AD28.field_6C * (signed __int64)v70) >> 16;
  stru_F8AD28.vec_9C.x = stru_F8AD28.vec_70.x;
  stru_F8AD28.field_98 = -(X + ((unsigned __int64)(stru_F8AD28.vec_60.z * (signed __int64)v11) >> 16) + v70);
  stru_F8AD28.vec_9C.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_70.y) >> 16;
  stru_F8AD28.vec_9C.z = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_70.z) >> 16;
  X = (unsigned __int64)(stru_F8AD28.vec_70.x * (signed __int64)v12) >> 16;
  v69 = (unsigned __int64)(stru_F8AD28.vec_70.y * (signed __int64)v11) >> 16;
  v70 = (unsigned __int64)(stru_F8AD28.vec_70.z * (signed __int64)v15) >> 16;
  stru_F8AD28.field_38 = 0;
  stru_F8AD28.field_A8 = -(X
                         + ((unsigned __int64)(stru_F8AD28.vec_70.y * (signed __int64)v11) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_70.z * (signed __int64)v15) >> 16));
  if ( *(int *)&v68->field_4 || *(int *)&v68->field_8 )
  {
    stru_F8AD28.field_3E4 = 1;
    stru_F8AD28.field_3E8 = *(int *)&v68->field_4;
    stru_F8AD28.field_3EC = *(int *)&v68->field_8;
    stru_F8AD28.field_3F0 = v68->field_1E;
    stru_F8AD28.field_3F4 = v68->field_20;
  }
  else
  {
    stru_F8AD28.field_3E4 = 0;
  }
  v16 = 0.0039215689;
  v17 = 116 * v1->uSectorID;
  v69 = v17;
  v74 = 0;
  v73 = 0;
  stru_F8AD28.uCurrentAmbientLightLevel = (stru_F8AD28.uDefaultAmbientLightLevel + *(__int16 *)((char *)&pIndoor->pSectors->uMinAmbientLightLevel + v17)) << 16;
  v70 = pMobileLightsStack->uNumLightsActive;
  if ( pMobileLightsStack->uNumLightsActive > 0 )
  {
    v18 = (char *)&pMobileLightsStack->pLights[0].vPosition.y;
    do
    {
      if ( v74 >= 20 )
        break;
      v19 = *((short *)v18 + 2);
      v20 = *((short *)v18 - 1);
      if ( v20 > v1->pBounding.x1 - v19 )
      {
        if ( v20 < v19 + v1->pBounding.x2 )
        {
          v21 = *(short *)v18;
          if ( v21 > v1->pBounding.y1 - v19 )
          {
            if ( v21 < v19 + v1->pBounding.y2 )
            {
              v22 = *((short *)v18 + 1);
              if ( v22 > v1->pBounding.z1 - v19 )
              {
                if ( v22 < v19 + v1->pBounding.z2 )
                {
                  X = (v1->pFacePlane_old.dist
                     + *((short *)v18 + 1) * v1->pFacePlane_old.vNormal.z
                     + v21 * v1->pFacePlane_old.vNormal.y
                     + *((short *)v18 - 1) * v1->pFacePlane_old.vNormal.x) >> 16;
                  if ( X <= v19 )
                  {
                    v23 = X;
                    v24 = v74;
                    stru_F8AD28._blv_lights_radii[v74] = v19;
                    stru_F8AD28._blv_lights_inv_radii[v24] = 65536 / v19;
                    *(int *)((char *)&stru_F8AD28.field_240 + v24 * 4) = *((short *)v18 + 5) << 16;
                    stru_F8AD28._blv_lights_xs[v24] = *((short *)v18 - 1);
                    stru_F8AD28._blv_lights_ys[v24] = *(short *)v18;
                    stru_F8AD28._blv_lights_zs[v24] = *((short *)v18 + 1);
                    v68 = (BLVFaceExtra *)(unsigned __int8)v18[6];
                    v25 = (double)(signed int)v68 * v16;
                    v68 = (BLVFaceExtra *)(unsigned __int8)v18[7];
                    v26 = (unsigned __int8)v18[8];
                    *(float *)(v24 * 4 + 16297992) = v25;
                    v27 = (double)(signed int)v68;
                    v68 = (BLVFaceExtra *)v26;
                    *(float *)(v24 * 4 + 16298072) = v27 * v16;
                    *(float *)(v24 * 4 + 16298152) = (double)(signed int)v68 * v16;
                    v16 = 0.0039215689;
                    stru_F8AD28._blv_lights_light_dot_faces[v24] = abs(v23);
                    v28 = v74;
                    v29 = v18[9];
                    ++v74;
                    stru_F8AD28._blv_lights_types[v28] = v29;
                  }
                }
              }
            }
          }
        }
      }
      ++v73;
      v18 += 18;
      v17 = v69;
    }
    while ( v73 < v70 );
  }
  v30 = 0;
  v73 = 0;
  v31 = *(__int16 *)((char *)&pIndoor->pSectors->uNumLights + v17);
  v70 = *(__int16 *)((char *)&pIndoor->pSectors->uNumLights + v17);
  if ( v31 > 0 )
  {
    while ( v74 < 20 )
    {
      v32 = &pIndoor->pLights[*(&(*(BLVLightMM7 **)((char *)&pIndoor->pSectors->pLights + v17))->vPosition.x + v30)];
      if ( !(v32->uAtributes & 8) )
      {
        v33 = v1->pBounding.x1;
        v34 = v32->vPosition.x;
        X = v32->uBrightness;
        v35 = v32->uRadius;
        v68 = (BLVFaceExtra *)v32->uRadius;
        if ( v34 > v33 - v35 )
        {
          if ( v34 < v35 + v1->pBounding.x2 )
          {
            v36 = v32->vPosition.y;
            if ( v36 > v1->pBounding.y1 - v35 )
            {
              if ( v36 < v35 + v1->pBounding.y2 )
              {
                v37 = v32->vPosition.z;
                if ( v37 > v1->pBounding.z1 - v35 )
                {
                  if ( v37 < v35 + v1->pBounding.z2 )
                  {
                    v38 = (v1->pFacePlane_old.dist
                         + v32->vPosition.x * v1->pFacePlane_old.vNormal.x
                         + v37 * v1->pFacePlane_old.vNormal.z
                         + v36 * v1->pFacePlane_old.vNormal.y) >> 16;
                    if ( v38 >= 0 )
                    {
                      if ( v38 <= v35 && v35 )
                      {
                        v39 = v74;
                        stru_F8AD28._blv_lights_radii[v74] = v35;
                        stru_F8AD28._blv_lights_inv_radii[v39] = 65536 / (signed int)v68;
                        *(int *)((char *)&stru_F8AD28.field_240 + v39 * 4) = X << 16;
                        stru_F8AD28._blv_lights_xs[v39] = v32->vPosition.x;
                        stru_F8AD28._blv_lights_ys[v39] = v32->vPosition.y;
                        stru_F8AD28._blv_lights_zs[v39] = v32->vPosition.z;
                        v68 = (BLVFaceExtra *)v32->uRed;
                        stru_F8AD28._blv_lights_rs[v39] = (double)(signed int)v68 * v16;
                        v68 = (BLVFaceExtra *)v32->uGreen;
                        stru_F8AD28._blv_lights_gs[v39] = (double)(signed int)v68 * v16;
                        v68 = (BLVFaceExtra *)v32->uBlue;
                        stru_F8AD28._blv_lights_bs[v39] = (double)(signed int)v68 * v16;
                        v16 = 0.0039215689;
                        stru_F8AD28._blv_lights_light_dot_faces[v39] = abs(v38);
                        v40 = v74++;
                        stru_F8AD28._blv_lights_types[v40] = 1;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      v30 = v73++ + 1;
      if ( v73 >= v70 )
        break;
      v17 = v69;
    }
  }
  v73 = 0;
  if ( pStationaryLightsStack->uNumLightsActive > 0 )
  {
    v41 = (char *)&pStationaryLightsStack->pLights[0].vPosition.y;
    do
    {
      if ( v74 >= 20 )
        break;
      v42 = *((short *)v41 + 2);
      v43 = *((short *)v41 - 1);
      if ( v43 > v1->pBounding.x1 - v42 )
      {
        if ( v43 < v42 + v1->pBounding.x2 )
        {
          v44 = *(short *)v41;
          if ( v44 > v1->pBounding.y1 - v42 )
          {
            if ( v44 < v42 + v1->pBounding.y2 )
            {
              v45 = *((short *)v41 + 1);
              if ( v45 > v1->pBounding.z1 - v42 )
              {
                if ( v45 < v42 + v1->pBounding.z2 )
                {
                  v46 = (v1->pFacePlane_old.dist
                       + *(short *)v41 * v1->pFacePlane_old.vNormal.y
                       + v43 * v1->pFacePlane_old.vNormal.x
                       + v45 * v1->pFacePlane_old.vNormal.z) >> 16;
                  v69 = v46;
                  if ( v46 >= 0 )
                  {
                    if ( v46 <= v42 )
                    {
                      v47 = v69;
                      v48 = v74;
                      stru_F8AD28._blv_lights_radii[v74] = v42;
                      stru_F8AD28._blv_lights_inv_radii[v48] = 65536 / v42;
                      stru_F8AD28._blv_lights_xs[v48] = *((short *)v41 - 1);
                      stru_F8AD28._blv_lights_ys[v48] = *(short *)v41;
                      stru_F8AD28._blv_lights_zs[v48] = *((short *)v41 + 1);
                      v68 = (BLVFaceExtra *)(unsigned __int8)v41[6];
                      v49 = (double)(signed int)v68 * v16;
                      v68 = (BLVFaceExtra *)(unsigned __int8)v41[7];
                      v50 = (unsigned __int8)v41[8];
                      stru_F8AD28._blv_lights_rs[v48] = v49;
                      v51 = (double)(signed int)v68;
                      v68 = (BLVFaceExtra *)v50;
                      stru_F8AD28._blv_lights_gs[v48] = v51 * v16;
                      stru_F8AD28._blv_lights_bs[v48] = (double)(signed int)v68 * v16;
                      v16 = 0.0039215689;
                      stru_F8AD28._blv_lights_light_dot_faces[v48] = abs(v47);
                      v52 = v74++;
                      stru_F8AD28._blv_lights_types[v52] = 1;
                    }
                  }
                }
              }
            }
          }
        }
      }
      ++v73;
      v41 += 12;
    }
    while ( v73 < pStationaryLightsStack->uNumLightsActive );
  }
  stru_F8AD28.uNumLightsApplied = v74;
  v53 = v1->pBounding.x2;
  if ( pBLVRenderParams->vPartyPos.x <= v53 )
  {
    v55 = v1->pBounding.x1;
    if ( pBLVRenderParams->vPartyPos.x >= v55 )
      v54 = 0;
    else
      v54 = v55 - pBLVRenderParams->vPartyPos.x;
  }
  else
  {
    v54 = pBLVRenderParams->vPartyPos.x - v53;
  }
  v56 = v1->pBounding.y2;
  v57 = v54 * v54;
  if ( pBLVRenderParams->vPartyPos.y <= v56 )
  {
    v59 = v1->pBounding.y1;
    if ( pBLVRenderParams->vPartyPos.y >= v59 )
      v58 = 0;
    else
      v58 = v59 - pBLVRenderParams->vPartyPos.y;
  }
  else
  {
    v58 = pBLVRenderParams->vPartyPos.y - v56;
  }
  v60 = v58 * v58 + v57;
  v61 = v1->pBounding.z2;
  if ( pBLVRenderParams->vPartyPos.z <= v61 )
  {
    v63 = v1->pBounding.z1;
    if ( pBLVRenderParams->vPartyPos.z >= v63 )
      v62 = 0;
    else
      v62 = v63 - pBLVRenderParams->vPartyPos.z;
  }
  else
  {
    v62 = pBLVRenderParams->vPartyPos.z - v61;
  }
  v64 = v62 * v62 + v60;
  if ( v64 )
    stru_F8AD28.field_34 = integer_sqrt(v64) << 16;
  else
    stru_F8AD28.field_34 = 0;
  v68 = (BLVFaceExtra *)abs(stru_F8AD28.rotated_normal.y);
  v65 = (double)(signed int)v68;
  if ( v65 >= 655.36 )
  {
    if ( v65 >= 26214.4 )
    {
      if ( v65 >= 45875.2 )
      {
        stru_F8AD28.field_44 = 8;
        stru_F8AD28.field_48 = 3;
      }
      else
      {
        stru_F8AD28.field_44 = 16;
        stru_F8AD28.field_48 = 4;
      }
    }
    else
    {
      stru_F8AD28.field_44 = 32;
      stru_F8AD28.field_48 = 5;
    }
  }
  else
  {
    stru_F8AD28.field_44 = 64;
    stru_F8AD28.field_48 = 6;
  }
}
// 519AB4: using guessed type int uNumStationaryLightsApplied;

//----- (004AF412) --------------------------------------------------------
int __cdecl sub_4AF412()
{
  int v0; // ST20_4@2
  int v1; // ST20_4@2
  int v2; // ST20_4@2
  int v3; // esi@2
  int v4; // ST20_4@2
  int v5; // ecx@2
  int v6; // ebx@2
  int v7; // edi@2
  int v8; // edx@2
  int v9; // eax@2
  int result; // eax@4

  stru_F8AD28.plane_4.vNormal.z = -65536;
  stru_F8AD28.vec_20.y = -65536;
  stru_F8AD28.plane_4.vNormal.x = 0;
  stru_F8AD28.plane_4.vNormal.y = 0;
  stru_F8AD28.plane_4.dist = (pBLVRenderParams->vPartyPos.z + 800) << 16;
  stru_F8AD28.vec_14.x = 65536;
  stru_F8AD28.vec_14.y = 0;
  stru_F8AD28.vec_14.z = 0;
  stru_F8AD28.vec_20.x = 0;
  stru_F8AD28.vec_20.z = 0;
  stru_F8AD28.uDefaultAmbientLightLevel = 0;
  if ( pBLVRenderParams->sPartyRotX )
  {
    v0 = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
       - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
    stru_F8AD28.rotated_normal.x = ((unsigned __int64)(v0 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
                                 - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
                                                     * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
    stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
                                                     * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                                 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
                                                     * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.rotated_normal.z = ((unsigned __int64)(v0 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
                                 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
                                                     * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
    v1 = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
       - ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
    stru_F8AD28.vec_60.y = ((unsigned __int64)(v1 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
                         - ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.field_6C = ((unsigned __int64)(v1 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
    v2 = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
       - ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
    stru_F8AD28.vec_70.x = ((unsigned __int64)(v2 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
                         - ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.vec_70.z = ((unsigned __int64)(v2 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
    v3 = -(pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.y
         + pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.x);
    v4 = pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.y
       - pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.x;
    v5 = ((unsigned __int64)(v4 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
       - ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
    v6 = pBLVRenderParams->vPartyPos.z;
    v7 = ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
       + ((unsigned __int64)(v4 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
    v8 = pBLVRenderParams->vPartyPos.y;
    v9 = pBLVRenderParams->vPartyPos.x;
  }
  else
  {
    stru_F8AD28.rotated_normal.x = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
                                                     * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
                                 - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
                                                     * (signed __int64)pBLVRenderParams->sSineY) >> 16);
    stru_F8AD28.rotated_normal.z = stru_F8AD28.plane_4.vNormal.z;
    stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
                                                     * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                                 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
                                                     * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.vec_60.y = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
                         - ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
    stru_F8AD28.field_6C = stru_F8AD28.vec_14.z;
    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.vec_70.x = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
                         - ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
    v8 = pBLVRenderParams->vPartyPos.y;
    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
    stru_F8AD28.vec_70.z = stru_F8AD28.vec_20.z;
    v9 = pBLVRenderParams->vPartyPos.x;
    v5 = pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.y
       - pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.x;
    v6 = pBLVRenderParams->vPartyPos.z;
    v3 = -(pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.y
         + pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.x);
    v7 = -65536 * pBLVRenderParams->vPartyPos.z;
  }
  stru_F8AD28.field_7C = stru_F8AD28.rotated_normal.x;
  stru_F8AD28.vec_60.x = stru_F8AD28.plane_4.vNormal.y * v8
                       + stru_F8AD28.plane_4.dist
                       + stru_F8AD28.plane_4.vNormal.x * v9
                       + stru_F8AD28.plane_4.vNormal.z * v6;
  stru_F8AD28.vec_80.x = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44)
                                          * (signed __int64)stru_F8AD28.rotated_normal.y) >> 16;
  stru_F8AD28.vec_80.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44)
                                          * (signed __int64)stru_F8AD28.rotated_normal.z) >> 16;
  stru_F8AD28.vec_80.z = -stru_F8AD28.vec_60.x;
  stru_F8AD28.vec_8C.x = stru_F8AD28.vec_60.y;
  stru_F8AD28.vec_8C.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_60.z) >> 16;
  stru_F8AD28.vec_8C.z = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.field_6C) >> 16;
  stru_F8AD28.vec_9C.x = stru_F8AD28.vec_70.x;
  stru_F8AD28.field_98 = -(((unsigned __int64)(stru_F8AD28.vec_60.y * (signed __int64)v5) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_60.z * (signed __int64)v3) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.field_6C * (signed __int64)v7) >> 16));
  stru_F8AD28.vec_9C.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_70.y) >> 16;
  stru_F8AD28.vec_9C.z = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_70.z) >> 16;
  result = 0;
  stru_F8AD28.field_A8 = -(((unsigned __int64)(stru_F8AD28.vec_70.x * (signed __int64)v5) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_70.y * (signed __int64)v3) >> 16)
                         + ((unsigned __int64)(stru_F8AD28.vec_70.z * (signed __int64)v7) >> 16));
  stru_F8AD28.field_38 = 0;
  stru_F8AD28.field_3E4 = 0;
  stru_F8AD28.uCurrentAmbientLightLevel = 0;
  stru_F8AD28.uNumLightsApplied = 0;
  stru_F8AD28.field_34 = 0;
  return result;
}






//----- (004B1447) --------------------------------------------------------
Player *__fastcall sub_4B1447_party_fine(int a1, int a2, int a3)
{
  signed int v3; // esi@1
  char v4; // sf@8
  int v5; // eax@8
  unsigned __int64 v6; // qax@12
  DDM_DLV_Header *v7; // eax@14
  Player **v8; // edi@18
  Player *result; // eax@19
  char *v10; // esi@20

  v3 = 0;
  if ( a2 )
  {
    if ( a2 != 1 )
    {
      if ( a2 == 2 )
        v3 = 2;
      goto LABEL_13;
    }
    v3 = 2;
  }
  else
  {
    v3 = 1;
  }
  if ( pParty->uFine < 4000000 )
  {
    v4 = a3 + pParty->uFine < 0;
    v5 = a3 + pParty->uFine;
    pParty->uFine += a3;
    if ( v4 )
    {
      v5 = 0;
      pParty->uFine = 0;
    }
    if ( v5 > 4000000 )
      pParty->uFine = 4000000;
  }
  v6 = pParty->uTimePlayed + 368640;
  pParty->field_3C._shop_ban_times[2 * a1] = LODWORD(pParty->uTimePlayed) + 368640;
  pParty->field_3C._shop_ban_times[2 * a1 + 1] = HIDWORD(v6);
LABEL_13:
  pParty->InTheShopFlags[a1] = 1;
  if ( v3 )
  {
    v7 = &pOutdoor->ddm;
    if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
      v7 = &pIndoor->dlv;
    v7->uReputation += v3;
    if ( v7->uReputation > 10000 )
      v7->uReputation = 10000;
  }
  v8 = &pPlayers[1];
  do
  {
    result = *v8;
    if ( pParty->uFine )
    {
      v10 = result->field_152;
      result = (Player *)_449B57_test_bit((unsigned __int8 *)result->field_152, 1);
      if ( !(short)result )
        result = (Player *)_449B7E_toggle_bit((unsigned char *)v10, 1, 1u);
    }
    ++v8;
  }
  while ( (signed int)v8 <= (signed int)&pPlayers[4] );
  return result;
}

//----- (004B1523) --------------------------------------------------------
char *__thiscall sub_4B1523(int *_this)
{
  int v1; // esi@1
  int v2; // edx@1
  unsigned int v3; // eax@2
  int v4; // eax@4
  LONG v5; // ecx@4
  int v6; // eax@10
  char *v7; // ST44_4@12
  unsigned __int16 v8; // ax@12
  GUIWindow a1; // [sp+Ch] [bp-68h]@4
  unsigned int v11; // [sp+60h] [bp-14h]@1
  POINT a2; // [sp+64h] [bp-10h]@1
  int v13; // [sp+6Ch] [bp-8h]@4
  int v14; // [sp+70h] [bp-4h]@4

  v1 = *_this - 399;
  v2 = (*_this - 400) % 11 + 1;
  v11 = 4 * (*_this - 400) / 11;
  sprintf(pTmpBuf, "%s%03d", spellbook_texture_filename_suffices[v11 / 4], v2);
  if ( pMouse->GetCursorPos(&a2)->y <= 320 )
    v3 = pMouse->GetCursorPos(&a2)->y + 30;
  else
    v3 = 30;
  a1.Hint = 0;
  a1.uFrameY = v3;
  a1.uFrameWidth = 328;
  a1.uFrameHeight = 68;
  a1.uFrameX = 90;
  a1.uFrameZ = 417;
  a1.uFrameW = v3 + 67;
  a2.y = pFontSmallnum->GetLineWidth(pGlobalTXT_LocalizationStrings[431]);
  v14 = pFontSmallnum->GetLineWidth(pGlobalTXT_LocalizationStrings[433]);
  v13 = pFontSmallnum->GetLineWidth(pGlobalTXT_LocalizationStrings[432]);
  v4 = pFontSmallnum->GetLineWidth(pGlobalTXT_LocalizationStrings[96]);
  v5 = a2.y;
  if ( v14 > a2.y )
    v5 = v14;
  if ( v13 > v5 )
    v5 = v13;
  if ( v4 > v5 )
    v5 = v4;
  sprintf(pTmpBuf2, "%s\n\n%s\t%03d:\t%03d%s\t000\n%s\t%03d:\t%03d%s\t000\n%s\t%03d:\t%03d%s\t000\n%s\t%03d:\t%03d%s",
    pSpellStats->pInfos[v1].pDescription, pGlobalTXT_LocalizationStrings[431],        // "Normal"
    v5 + 3, v5 + 10, pSpellStats->pInfos[v1].pBasicSkillDesc, pGlobalTXT_LocalizationStrings[433],        // "Expert"
    v5 + 3, v5 + 10, pSpellStats->pInfos[v1].pExpertSkillDesc, pGlobalTXT_LocalizationStrings[432],        // "Master"
    v5 + 3, v5 + 10, pSpellStats->pInfos[v1].pMasterSkillDesc, pGlobalTXT_LocalizationStrings[96],         // "Grand"
    v5 + 3, v5 + 10, pSpellStats->pInfos[v1].pGrandmasterSkillDesc);
  v6 = pFontSmallnum->CalcTextHeight(pTmpBuf2, &a1, 0, 0);
  a1.uFrameHeight += v6;
  if ( (signed int)a1.uFrameHeight < 150 )
    a1.uFrameHeight = 150;
  a1.uFrameWidth = 460;
  a1.DrawMessageBox(0);
  a1.uFrameWidth -= 12;
  a1.uFrameHeight -= 12;
  v7 = pSpellStats->pInfos[v1].pName;
  a1.uFrameZ = a1.uFrameX + a1.uFrameWidth - 1;
  a1.uFrameW = a1.uFrameHeight + a1.uFrameY - 1;
  v8 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
  a1.DrawTitleText(pFontArrus, 0x78u, 0xCu, v8, v7, 3u);
  a1.DrawText(pFontSmallnum, 120, 44, 0, pTmpBuf2, 0, 0, 0);
  a1.uFrameZ = a1.uFrameX + 107;
  a1.uFrameWidth = 108;
  a1.DrawTitleText(pFontComic, 0xCu, 0x4Bu, 0, pSkillNames[v11 / 4 + 12], 3u);
  sprintf(pTmpBuf, "%s\n%d", pGlobalTXT_LocalizationStrings[522], *(&pSpellDatas[0].uNormalLevelMana + 10 * v1));
  return a1.DrawTitleText(pFontComic, 0xCu, a1.uFrameHeight - LOBYTE(pFontComic->uFontHeight) - 16, 0, pTmpBuf, 3);
}


//----- (004B1784) --------------------------------------------------------
bool __cdecl sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win()
{
  Player *pPlayer; // ebx@1
  bool result; // eax@2
  unsigned __int16 v2; // ST0C_2@3
  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;
    sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[427], pPlayer->pName, pGlobalTXT_LocalizationStrings[562]);// 
                                                // "%s is in no condition to %s"
                                                // "do anything"
    v2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
    v3 = pFontArrus->CalcTextHeight(pTmpBuf, &v4, 0, 0);
    v4.DrawTitleText(pFontArrus, 0, (212 - v3) / 2 + 101, v2, pTmpBuf, 3u);
    result = 0;
  }
  return result;
}
// F8B1E0: using guessed type int dword_F8B1E0;


//view  item details  in shop?
//----- (004B1A2D) --------------------------------------------------------
void __cdecl sub_4B1A2D()
{
  //Player *v0; // edi@1
  POINT *v1; // esi@5
  unsigned int v2; // eax@5
  int v3; // ecx@5
  POINT *v4; // esi@12
  int v5; // eax@12
  unsigned int v6; // eax@13
  ItemGen *v7; // ecx@13
  signed int v8; // esi@17
  unsigned int v9; // eax@19
  char v10; // [sp+8h] [bp-44h]@12
  char v11; // [sp+10h] [bp-3Ch]@12
  char v12; // [sp+18h] [bp-34h]@18
  char v13; // [sp+20h] [bp-2Ch]@17
  char v14; // [sp+28h] [bp-24h]@17
  char v15; // [sp+30h] [bp-1Ch]@17
  char v16; // [sp+38h] [bp-14h]@5
  POINT a2; // [sp+40h] [bp-Ch]@5
  int v18; // [sp+48h] [bp-4h]@5

  //v0 = pPlayers[uActiveCharacter];
  if ( dword_F8B198 <= 0 )
    return;
  if ( dword_F8B198 <= 4 )
  {
    if ( dword_F8B19C != 2 )
    {
      if ( dword_F8B19C <= 2 )
        return;
      if ( dword_F8B19C <= 5 || dword_F8B19C == 94 )
      {
        v8 = pMouse->GetCursorPos((POINT *)&v15)->x - 14;
        v18 = (v8 >> 5) + 14 * ((pMouse->GetCursorPos((POINT *)&v14)->y - 17) >> 5);
        if ( pMouse->GetCursorPos((POINT *)&v13)->x <= 13
          || pMouse->GetCursorPos((POINT *)&v12)->x >= 462
          || (v9 = pPlayers[uActiveCharacter]->GetItemIDAtInventoryIndex(&v18)) == 0 )
          return;
        v7 = (ItemGen *)&pPlayers[uActiveCharacter]->pInventoryItems[v9-1];
LABEL_15:
        GameUI_DrawItemInfo(v7);
        return;
      }
      if ( dword_F8B19C != 95 )
        return;
    }
    v4 = pMouse->GetCursorPos((POINT *)&v11);
    v5 = pRenderer->pActiveZBuffer[v4->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v10)->y]] & 0xFFFF;
    v18 = v5;
    if ( !v5 )
      return;
    v6 = 9 * (v5 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C);
    v7 = (ItemGen *)((char *)&pParty->pPickedItem + 4 * v6 + 4);
    if ( dword_F8B19C != 2 )
   //   v7 = (ItemGen *)&pParty->field_C59C[v6 + 715];
		v7 =&pParty->SpecialItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][v5];
    goto LABEL_15;
  }
  if ( dword_F8B198 <= 16 && dword_F8B19C == 18 )
  {
    v1 = pMouse->GetCursorPos(&a2);
    v2 = v1->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v16)->y];
    v3 = pRenderer->pActiveZBuffer[v2] & 0xFFFF;
    v18 = pRenderer->pActiveZBuffer[v2] & 0xFFFF;
    if ( v18 )
      sub_4B1523((int *)&pParty->pPlayers[1].uExpressionTimeLength + 9 * (v3 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C));
  }
}
// F8B198: using guessed type int dword_F8B198;
// F8B19C: using guessed type int dword_F8B19C;

//----- (004B1BDB) --------------------------------------------------------
void __stdcall RestAndHeal(__int64 uNumMinutes)
{
  signed __int64 v1; // ST2C_8@1
  signed __int64 v2; // qax@1
  signed __int64 v3; // ST1C_8@1
  unsigned __int64 v4; // qax@1
  unsigned int v5; // ebx@1
  Player *v6; // ebx@1

  pParty->pHirelings[0].bHasUsedTheAbility = 0;
  pParty->pHirelings[1].bHasUsedTheAbility = 0;
  pParty->uTimePlayed += (signed __int64)((double)(7680 * uNumMinutes) * 0.033333335);
  v1 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375);
  v2 = v1 / 60 / 60;
  v3 = v2;
  v4 = (unsigned int)v2 / 0x18;
  v5 = (unsigned int)(v4 / 7) >> 2;
  pParty->uCurrentTimeSecond = v1 % 60;
  pParty->uCurrentMinute = v1 / 60 % 60;
  pParty->uCurrentHour = v3 % 24;
  pParty->uCurrentMonthWeek = v4 / 7 & 3;
  pParty->uDaysPlayed = (unsigned int)v4 % 0x1C;
  pParty->uCurrentMonth = v5 % 0xC;
  pParty->uCurrentYear = v5 / 0xC + game_starting_year;
  pParty->RestAndHeal();
  dword_507B94 = 1;
  v6 = pParty->pPlayers;//[0].uNumDivineInterventionCastsThisDay;
  do
  {
	v6->uTimeToRecovery = 0;
	memset(&v6->uTimeToRecovery, 0, 4u);
    ++v6;
  }
  while ( v6 <= &pParty->pPlayers[3] );
  pParty->UpdatePlayersAndHirelingsEmotions();
}
// 507B94: using guessed type int dword_507B94;

//----- (004B1D27) --------------------------------------------------------
void __cdecl sub_4B1D27()
{
  int v0; // edx@2
  unsigned int v1; // ecx@7
  signed int v2; // edi@10
  int v3; // esi@10
  __int16 v4; // ax@15
  signed int v5; // edi@20
  int v6; // esi@20
  int v7[4]; // [sp+Ch] [bp-10h]@12

  if ( dword_F8B198 > 0 )
  {
    v0 = 3;
    if ( dword_F8B198 > 3 )
    {
      if ( dword_F8B198 == 22 )
      {
        if ( !dword_F8B1E4 )
          return;
      }
      else
      {
        if ( dword_F8B198 != 23 )
          return;
      }
      v1 = (unsigned int)window_SpeakInHouse->ptr_1C;
LABEL_28:
      HousePlaySomeSound(v1, v0);
      return;
    }
    v1 = (unsigned int)window_SpeakInHouse->ptr_1C;
    if ( (signed __int64)__PAIR__(pParty->field_3C._shop_ban_times[2 * v1 + 1], pParty->field_3C._shop_ban_times[2 * v1]) <= (signed __int64)pParty->uTimePlayed )
    {
      if ( pParty->uNumGold <= 0x2710 )
      {
        if ( !dword_F8B1E4 )
          return;
        v0 = 4;
        goto LABEL_28;
      }
      HousePlaySomeSound(v1, dword_F8B1E4 + 3);
      if ( !dword_F8B1E4 && !qword_A750D8 )
      {
        v5 = 0;
        v6 = 1;
        do
        {
          if ( pPlayers[v6]->CanAct() )
            v7[v5++] = v6;
          ++v6;
        }
        while ( v6 <= 4 );
        if ( v5 )
        {
          qword_A750D8 = 256i64;
          word_A750E0 = 80;
          v4 = LOWORD(v7[rand() % v5]);
          goto LABEL_16;
        }
      }
    }
    else
    {
      if ( !qword_A750D8 )
      {
        v2 = 0;
        v3 = 1;
        do
        {
          if ( pPlayers[v3]->CanAct() )
            v7[v2++] = v3;
          ++v3;
        }
        while ( v3 <= 4 );
        if ( v2 )
        {
          qword_A750D8 = 256i64;
          word_A750E0 = 80;
          v4 = LOWORD(v7[rand() % v2]);
LABEL_16:
          word_A750E2 = v4;
          return;
        }
      }
    }
  }
}

//----- (004B1E92) --------------------------------------------------------
void __fastcall HousePlaySomeSound(unsigned int uHouseID, int a2)
{
  //if ( BYTE1(pAnimatedRooms[p2DEvents_minus1___02[26 * uHouseID]].field_C) )
  if ( BYTE1(pAnimatedRooms[p2DEvents[uHouseID - 1].uAnimationID].field_C) )
    pAudioPlayer->PlaySound(
      //(SoundID)(a2 + 100 * (BYTE1(pAnimatedRooms[p2DEvents_minus1___02[26 * uHouseID]].field_C) + 300)),
      (SoundID)(a2 + 100 * (BYTE1(pAnimatedRooms[p2DEvents[uHouseID - 1].uAnimationID].field_C) + 300)),
      806,
      0,
      -1,
      0,
      0,
      0,
      0);
}

//----- (004B1ECE) --------------------------------------------------------
void __cdecl sub_4B1ECE()
{
  __int16 *v0; // edi@1
  int v1; // ebx@3
  Player *v2; // esi@3
  int v3; // eax@4
  signed int v4; // eax@9
  int v5; // ebx@11
  Player *v6; // esi@13
  ItemGen *v7; // eax@14
  signed int v8; // edi@14
  ItemGen *v9; // [sp+Ch] [bp-Ch]@11
  signed int v10; // [sp+10h] [bp-8h]@13
  int v11; // [sp+14h] [bp-4h]@1
  Player *v12; // [sp+14h] [bp-4h]@11

  dword_F8B1A8 = 0;
  v11 = 0;
  uDialogueType = 84;
  ptr_F8B1E8 = (char *)pNPCTopics[667].pText;
  v0 = _4F0882_evt_VAR_PlayerItemInHands_vals;
  while ( 1 )
  {
    if ( (unsigned __int16)_449B57_test_bit(pParty->_award_bits, *v0) )
    {
      v1 = 0;
      v2 = pParty->pPlayers;
      do
      {
        LOBYTE(v3) = v2->CompareVariable(VAR_PlayerItemInHands, *(v0+1));
        if ( v3 )
          break;
        ++v2;
        ++v1;
      }
      while ( (signed int)v2 < (signed int)pParty->pHirelings );
      if ( v1 == 4 )
        break;
    }
    ++v11;
    v0 += 2;
    if ( v0 > &_4F0882_evt_VAR_PlayerItemInHands_vals[53] )
	  break;
  }
  if ( v0 <= &_4F0882_evt_VAR_PlayerItemInHands_vals[53] )
  {
	  ptr_F8B1E8 = (char *)pNPCTopics[666].pText;
	  v4 = _4F0882_evt_VAR_PlayerItemInHands_vals[2 * v11];
	  dword_F8B1A8 = _4F0882_evt_VAR_PlayerItemInHands_vals[2 * v11];
	  pParty->pPlayers[0].AddVariable(VAR_PlayerItemInHands, v4);
  }
  if ( dword_F8B1A8 == 601 )
  {
    v5 = 0;
    v12 = pParty->pPlayers;//[0].uClass;
    v9 = 0;
    while ( 1 )
    {
      if ( v12->classType == PLAYER_CLASS_LICH )
      {
        v10 = 0;
        v6 = pParty->pPlayers;//[0].pInventoryItems[0].field_1A;
        do
        {
		  v7 = v6->pInventoryItems;
          v8 = 138;
          do
          {
			if ( v7->uItemID == 601 )
            {
			  if ( !v7->uHolderPlayer )
				  v9 = v7;
			  if ( v7->uHolderPlayer == v5 )
                v10 = 1;
            }
            ++v7;
            --v8;
          }
          while ( v8 );
          ++v6;
        }
		while ( v6 <= &pParty->pPlayers[3] );
        if ( !v10 )
          break;
      }
      ++v12;
      ++v5;
	  if ( v12 > &pParty->pPlayers[3] )
        return;
    }
    if ( v9 )
	  v9->uHolderPlayer = v5;
  }
}
// 4F08EC: using guessed type int dword_4F08EC[];
// 722B3C: using guessed type int dword_722B3C;
// 722B44: using guessed type int dword_722B44;
// F8B1A8: using guessed type int dword_F8B1A8;

//----- (004B2001) --------------------------------------------------------
void __fastcall ClickNPCTopic(signed int uMessageParam)
{
  //signed int v1; // eax@1
  NPCData *pCurrentNPCInfo; // ebp@1
  int pEventNumber; // ecx@8
  Player *v4; // esi@20
  //int v5; // eax@28
  //int v6; // eax@31
  //int v7; // eax@34
  //int v8; // eax@37
  //int v9; // eax@40
  //unsigned int v10; // eax@43
  char *v12; // eax@53
  char *v13; // eax@56
  char *v14; // eax@57
  char *v15; // eax@58
  //unsigned int v16; // ebp@62
  char *v17; // ecx@63
  char *v18; // eax@65
  const char *v19; // ecx@68
  //unsigned int v20; // eax@69
  signed int pPrice; // ecx@70
  char *v22; // [sp-Ch] [bp-18h]@73
  //int v23; // [sp-8h] [bp-14h]@49
  char *v24; // [sp-8h] [bp-14h]@73
  //int v25; // [sp-4h] [bp-10h]@49

  uDialogueType = uMessageParam + 1;
  pCurrentNPCInfo = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) - 1)];
  if ( uMessageParam <= 24 )
  {
  switch ( uMessageParam )
  {
    case 13:
      ptr_F8B1E8 = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession].pJoinText;//(char *)*(&pNPCStats->field_13A64 + 5 * v2->uProfession);
      ptr_F8B1E8 = BuilDialogueString((char *)ptr_F8B1E8, uActiveCharacter - 1, 0, 0, 0, 0);
      sub_4B40E6();
      dialogue_show_profession_details = false;
      goto _return;
    case 19:
      pEventNumber = pCurrentNPCInfo->evt_A;
      break;
    case 20:
      pEventNumber = pCurrentNPCInfo->evt_B;
      break;
    case 21:
      pEventNumber = pCurrentNPCInfo->evt_C;
      break;
    case 22:
      pEventNumber = pCurrentNPCInfo->evt_D;
      break;
    case 23:
      pEventNumber = pCurrentNPCInfo->evt_E;
      break;
    case 24:
      pEventNumber = pCurrentNPCInfo->evt_F;
      break;
    default:
      goto _return;
  }
  /*switch ( pEventNumber )
  {
    case 139:
      sub_4B1ECE();
      goto _return;
    case 311:
      sub_4BBA85_bounties();
    goto _return;
  }*/
  if ( pEventNumber < 200 || pEventNumber > 310 )
    {
      if ( pEventNumber < 400 || pEventNumber > 410 )
      {
        if ( pEventNumber == 139 )
        {
          sub_4B1ECE();
        }
        else
        {
          if ( pEventNumber == 311 )
          {
            sub_4BBA85_bounties();
          }
          else
          {
            ptr_F8B1E8 = 0;
            GlobalEventInfo = 1;
            EventProcessor(pEventNumber, 0, 1);
            GlobalEventInfo = 0;
          }
        }
      }
      else
      {
        dword_F8B1D8 = uMessageParam;
        DrawJoinGuildWindow(pEventNumber - 400);
      }
    }
    else
    {
      sub_4B3FE5(pEventNumber);
    }
    goto _return;
  }
  if ( uMessageParam != 76 )
  {
    if ( uMessageParam == 77 )
    {
      //v16 = pCurrentNPCInfo->uProfession;
      if (dialogue_show_profession_details)
        v17 = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].pJoinText;
      else
        v17 = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].pBenefits;
      ptr_F8B1E8 = v17;
      v18 = BuilDialogueString(v17, uActiveCharacter - 1, 0, 0, 0, 0);
      dialogue_show_profession_details = ~dialogue_show_profession_details;
      ptr_F8B1E8 = v18;
    }
    else
    {
      if ( uMessageParam == 79 )
      {
        if ( dword_F8B1A8 )
        {
          Party::TakeGold(gold_transaction_amount);
          if ( uActiveCharacter )
          {
            v12 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_something_todo_with_awards];
            *(short *)v12 &= 0x3Fu;
            switch ( dword_F8B1B0 )
            {
              case 2:
                v15 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_something_todo_with_awards];
                *v15 |= 0x40u;
                break;
              case 3:
                v14 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_something_todo_with_awards];
                *v14 |= 0x80u;
                break;
              case 4:
                v13 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_something_todo_with_awards];
                v13[1] |= 1u;
                break;
            }
            pPlayers[uActiveCharacter]->PlaySound(SPEECH_85, 0);
          }
          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
          {
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
            ++pMessageQueue_50CBD0->uNumMessages;
          }*/
        }
      }
      else
      {
        if ( uMessageParam == 82 && dword_F8B1A8 )
        {
          Party::TakeGold(gold_transaction_amount);
          v4 = pParty->pPlayers;
          do
          {
            v4->SetVariable(VAR_Award, dword_F8B1AC_something_todo_with_awards);
            ++v4;
          }
          while ( (signed int)v4 < (signed int)pParty->pHirelings );
          switch ( dword_F8B1D8 )
          {
            case 19:
              pEventNumber = pCurrentNPCInfo->evt_A;
              if ( pEventNumber >= 400 && pEventNumber <= 416 )
                pCurrentNPCInfo->evt_A = 0;
              break;
            case 20:
              pEventNumber = pCurrentNPCInfo->evt_B;
              if ( pEventNumber >= 400 && pEventNumber <= 416 )
                pCurrentNPCInfo->evt_B = 0;
              break;
            case 21:
              pEventNumber = pCurrentNPCInfo->evt_C;
              if ( pEventNumber >= 400 && pEventNumber <= 416 )
                pCurrentNPCInfo->evt_C = 0;
              break;
            case 22:
              pEventNumber = pCurrentNPCInfo->evt_D;
              if ( pEventNumber >= 400 && pEventNumber <= 416 )
                pCurrentNPCInfo->evt_D = 0;
              break;
            case 23:
              pEventNumber = pCurrentNPCInfo->evt_E;
              if ( pEventNumber >= 400 && pEventNumber <= 416 )
                pCurrentNPCInfo->evt_E = 0;
              break;
            case 24:
              pEventNumber = pCurrentNPCInfo->evt_F;
              if ( pEventNumber >= 400 && pEventNumber <= 416)
                pCurrentNPCInfo->evt_F = 0;
              break;
          }
          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
          {
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
            ++pMessageQueue_50CBD0->uNumMessages;
          }*/
          //v11 = uActiveCharacter;
          if ( uActiveCharacter )
          {
            pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)SPEECH_86, 0);
            goto _return;
          }
        }
      }
    }
    goto _return;
  }
  if ( pParty->pHirelings[0].pName && pParty->pHirelings[1].pName )
  {
    ShowStatusBarString(pGlobalTXT_LocalizationStrings[533], 2);// ""I cannot join you, you're party is full""
    goto _return;
  }
  if ( pCurrentNPCInfo->uProfession != 51 )
  {
    pPrice = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].uHirePrice;
    if ( pParty->uNumGold < pPrice )
    {
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);
      dialogue_show_profession_details = false;
      uDialogueType = 13;
      ptr_F8B1E8 = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].pJoinText;
      ptr_F8B1E8 = BuilDialogueString((char *)ptr_F8B1E8, uActiveCharacter - 1, 0, 0, 0, 0);
      if ( uActiveCharacter )
        pPlayers[uActiveCharacter]->PlaySound(SPEECH_NotEnoughGold, 0);
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);
      goto _return;
    }
    Party::TakeGold(pPrice);
  }
  //LOBYTE(v2->uFlags) |= 0x80u;
  pCurrentNPCInfo->uFlags = 128;
  pParty->field_709 = 0;
  sub_44A56A();
  if ( pParty->pHirelings[0].pName )
  {
    memcpy(&pParty->pHirelings[1], pCurrentNPCInfo, sizeof(pParty->pHirelings[1]));
    v24 = pCurrentNPCInfo->pName;
    v22 = pParty->pHireling2Name;
  }
  else
  {
    memcpy(pParty->pHirelings, pCurrentNPCInfo, 0x4Cu);
    v24 = pCurrentNPCInfo->pName;
    v22 = pParty->pHireling1Name;
  }
  strcpy(v22, v24);
  pParty->field_709 = 0;
  sub_44A56A();
  PrepareHouse((HOUSE_TYPE)(int)window_SpeakInHouse->ptr_1C);
  dword_F8B19C = 1;

  pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
  /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
  {
    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
    *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
    ++pMessageQueue_50CBD0->uNumMessages;
  }*/
  if ( uActiveCharacter )
    pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)61, 0);
_return:
  pVideoPlayer->_4BF5B2();//HouseVideo
}


//----- (004B254D) --------------------------------------------------------
char *__thiscall _4B254D_SkillMasteryTeacher(int _this)
{
  Player *v1; // esi@1
  int v2; // edx@1
  int v3; // ecx@1
  int v4; // edi@1
  int v5; // eax@7
  int v6; // eax@7
  int v7; // ebx@7
  int v8; // ebx@8
  signed int v9; // esi@8
  int v10; // eax@8
  char *v11; // ecx@8
  int v12; // edi@9
  char *v13; // edx@9
  signed int v14; // edi@10
  unsigned int v16; // eax@29
  int v17; // eax@36
  char v18; // cl@46
  __int16 v19; // dx@56
  int v20; // eax@60
  char *v21; // [sp-Ch] [bp-38h]@82
  const char *v22; // [sp-8h] [bp-34h]@21
  unsigned int v23; // [sp-8h] [bp-34h]@38
  char *v24; // [sp-8h] [bp-34h]@82
  char *v25; // [sp-4h] [bp-30h]@14
  int v26; // [sp-4h] [bp-30h]@38
  int v27; // [sp-4h] [bp-30h]@82
  char v28[4]; // [sp+Ch] [bp-20h]@9
  int v29; // [sp+10h] [bp-1Ch]@13
  int v30; // [sp+14h] [bp-18h]@15
  int v31; // [sp+18h] [bp-14h]@16
  unsigned __int16 a1[2]; // [sp+1Ch] [bp-10h]@7
  int v33; // [sp+20h] [bp-Ch]@7
  int v34; // [sp+24h] [bp-8h]@7
  char *v35; // [sp+28h] [bp-4h]@1

  v1 = pPlayers[uActiveCharacter];
  dword_F8B1A8 = 0;
  v2 = (_this - 200) % 3;
  v3 = (_this - 200) / 3;
  v4 = v2;
  v35 = (char *)pNPCTopics[127].pText;
  dword_F8B1AC_something_todo_with_awards = v3;
  if ( v2 )
  {
    if ( v2 == 1 )
    {
      gold_transaction_amount = 5000;
      dword_F8B1B0 = 3;
    }
    else
    {
      if ( v2 == 2 )
      {
        gold_transaction_amount = 8000;
        dword_F8B1B0 = 4;
      }
    }
  }
  else
  {
    gold_transaction_amount = 2000;
    dword_F8B1B0 = 2;
  }
  v5 = v1->classType;
  v33 = v5;
  v6 = byte_4ED970_skill_learn_ability_by_class_table[v5][v3];
  *(int *)a1 = v1->pActiveSkills[v3];
  v7 = a1[0] & 0x3F;
  v34 = v2 + 2;
  if ( v6 < v2 + 2 )
  {
    v8 = v33;
    v9 = 0;
    v10 = v33 - v33 % 4;
    v11 = &byte_4ED970_skill_learn_ability_by_class_table[v33 - v33 % 4][v3];
    do
    {
      v12 = (unsigned __int8)*v11;
      v13 = &v28[4 * v9];
      *(int *)v13 = 0;
      if ( v12 < v34 )
      {
        v14 = 1;
      }
      else
      {
        v14 = 1;
        *(int *)v13 = 1;
      }
      ++v9;
      v11 += 37;
    }
    while ( v9 < 4 );
    if ( v29 == v14 )
    {
      v25 = pClassNames[v10 + 1];
    }
    else
    {
      if ( v30 == v14 )
      {
        if ( v31 == v14 )
        {
          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[634], pClassNames[v10 + 2], pClassNames[v10 + 3]);
          return pTmpBuf;
        }
        v25 = pClassNames[v10 + 2];
      }
      else
      {
        if ( v31 != v14 )
        {
          v25 = pClassNames[v8];
          v22 = pGlobalTXT_LocalizationStrings[632];
          goto LABEL_23;
        }
        v25 = pClassNames[v10 + 3];
      }
    }
    v22 = pGlobalTXT_LocalizationStrings[633];
LABEL_23:
    sprintf(pTmpBuf, v22, v25);
    return pTmpBuf;
  }
  if ( !v1->CanAct() )
    return (char *)pNPCTopics[122].pText;
  if ( !v7 )
    return (char *)pNPCTopics[131].pText;
  v16 = SkillToMastery(a1[0]);
  if ( (signed int)v16 > v4 + 1 )
    return (char *)pNPCTopics[v4 + 128].pText;
  if ( v34 != 2 )
  {
    if ( v34 == 3 )
    {
      if ( (signed int)v16 >= 2 && v7 >= 7 )
      {
        v17 = dword_F8B1AC_something_todo_with_awards;
        switch ( dword_F8B1AC_something_todo_with_awards )
        {
          default:
            goto LABEL_41;
          case 12:
          case 13:
          case 14:
          case 15:
          case 16:
          case 17:
          case 18:
            gold_transaction_amount = 4000;
            goto LABEL_42;
          case 19:
            v19 = 114;
            goto LABEL_57;
          case 20:
            v19 = 110;
LABEL_57:
            if ( !(unsigned __int16)_449B57_test_bit(pParty->_award_bits, v19) )
              return v35;
            goto LABEL_40;
          case 22:
            v20 = v1->GetBaseWillpower();
            goto LABEL_61;
          case 24:
            gold_transaction_amount = 2500;
            v20 = v1->GetBaseEndurance();
            goto LABEL_61;
          case 36:
            v20 = v1->GetBaseIntelligence();
LABEL_61:
            if ( v20 < 50 )
              return v35;
            goto LABEL_40;
          case 21:
          case 23:
          case 25:
          case 26:
          case 29:
          case 32:
          case 34:
          case 35:
            gold_transaction_amount = 2500;
            goto LABEL_42;
          case 8:
          case 9:
          case 10:
          case 11:
            gold_transaction_amount = 3000;
            goto LABEL_42;
          case 7:
            goto LABEL_67;
        }
        goto LABEL_67;
      }
    }
    else
    {
      if ( v34 != 4 )
      {
LABEL_40:
        v17 = dword_F8B1AC_something_todo_with_awards;
        goto LABEL_41;
      }
      if ( (signed int)v16 >= 3 && v7 >= 10 )
      {
        v17 = dword_F8B1AC_something_todo_with_awards;
        switch ( dword_F8B1AC_something_todo_with_awards )
        {
          case 19:
            if ( v1->_49327B(0x22u, 1) == 1 )
              goto LABEL_40;
            v26 = 1;
            v23 = 26;
            goto LABEL_39;
          default:
            goto LABEL_41;
          case 20:
            if ( v1->_49327B(0x23u, 1) == 1 )
              goto LABEL_40;
            v26 = 1;
            v23 = 27;
LABEL_39:
            if ( v1->_49327B(v23, v26) == 1 )
              goto LABEL_40;
            return v35;
          case 30:
            v18 = LOBYTE(v1->pActiveSkills[31]);
            goto LABEL_47;
          case 31:
            v18 = LOBYTE(v1->pActiveSkills[30]);
LABEL_47:
            if ( (v18 & 0x3Fu) < 0xA )
              return v35;
            goto LABEL_41;
          case 21:
          case 23:
          case 24:
          case 25:
          case 26:
          case 29:
          case 32:
          case 34:
          case 35:
            gold_transaction_amount = 6000;
            goto LABEL_42;
          case 8:
          case 9:
          case 10:
          case 11:
            gold_transaction_amount = 7000;
            goto LABEL_42;
          case 7:
            break;
        }
LABEL_67:
        gold_transaction_amount = 0;
        goto LABEL_41;
      }
    }
    return v35;
  }
  if ( v7 < 4 )
    return v35;
  v17 = dword_F8B1AC_something_todo_with_awards;
  if ( dword_F8B1AC_something_todo_with_awards > 27 )
  {
    if ( dword_F8B1AC_something_todo_with_awards != 29
      && dword_F8B1AC_something_todo_with_awards != 32
      && (dword_F8B1AC_something_todo_with_awards <= 33 || dword_F8B1AC_something_todo_with_awards > 35) )
    {
LABEL_41:
      if ( !gold_transaction_amount )
        goto LABEL_79;
      goto LABEL_42;
    }
LABEL_87:
    gold_transaction_amount = 500;
    goto LABEL_41;
  }
  if ( dword_F8B1AC_something_todo_with_awards >= 23 )
    goto LABEL_87;
  if ( dword_F8B1AC_something_todo_with_awards == 7 )
  {
    gold_transaction_amount = 0;
    goto LABEL_79;
  }
  if ( dword_F8B1AC_something_todo_with_awards <= 7 )
    goto LABEL_41;
  if ( dword_F8B1AC_something_todo_with_awards > 18 )
  {
    if ( dword_F8B1AC_something_todo_with_awards != 21 )
      goto LABEL_41;
    goto LABEL_87;
  }
  gold_transaction_amount = 1000;
LABEL_42:
  if ( gold_transaction_amount > pParty->uNumGold )
    return (char *)pNPCTopics[124].pText;
LABEL_79:
  dword_F8B1A8 = 1;
  if ( v34 == 2 )
  {
    v27 = gold_transaction_amount;
    v24 = pSkillNames[v17];
    v21 = pGlobalTXT_LocalizationStrings[433];
    goto LABEL_90;
  }
  if ( v34 == 3 )
  {
    v27 = gold_transaction_amount;
    v24 = pSkillNames[v17];
    v21 = pGlobalTXT_LocalizationStrings[432];
    goto LABEL_90;
  }
  if ( v34 == 4 )
  {
    v27 = gold_transaction_amount;
    v24 = pSkillNames[v17];
    v21 = pGlobalTXT_LocalizationStrings[225];
LABEL_90:
    sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[534], v21, v24, v27);
  }
  return pTmpBuf2;
}



//----- (004B29F2) --------------------------------------------------------
const char *__fastcall ContractSelectText(int pEventNumber)
{
  dword_F8B1A8 = 0;
  dword_F8B1AC_something_todo_with_awards = pEventNumber + 50;
  gold_transaction_amount = dword_4F08EC[pEventNumber];
  if ( pPlayers[uActiveCharacter]->CanAct() )
  {
    if ( (unsigned __int16)_449B57_test_bit((unsigned __int8 *)pPlayers[uActiveCharacter]->field_152, dword_F8B1AC_something_todo_with_awards) )
    {
      return pNPCTopics[123].pText;
    }
    else
    {
      if ( gold_transaction_amount <= pParty->uNumGold )
      {
        dword_F8B1A8 = 1;
        return pNPCTopics[pEventNumber + 110].pText;
      }
      else
      {
        return pNPCTopics[124].pText;
      }
    }
  }
  else
  {
    return pNPCTopics[122].pText;
  }
}


//----- (004B2A74) --------------------------------------------------------
char __cdecl 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 )
    {
      sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[411], v0);
      v2 = pTmpBuf;
    }
    v3 = v2;
    v4 = pFontCreate->CalcTextHeight(v2, &a1, 0, 0);
    LOBYTE(i) = (unsigned int)a1.DrawTitleText(pFontCreate, 0, (212 - v4) / 2 + 101, 0, v3, 3u);
    return i;
  }
  a1.uFrameWidth -= 10;
  a1.uFrameZ -= 10;
  v58 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) - 1)];
  v6 = v58;
  v55 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
  v7 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0x15u, 0x99u, 0xE9u);
  v8 = v6->uProfession;
  if ( v8 )
    sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[429], v6->pName, aNPCProfessionNames[v8]);
  else
    strcpy(pTmpBuf, v6->pName);
  a1.DrawTitleText(pFontCreate, 0x1E3u, 0x71u, v7, pTmpBuf, 3u);
  if ( !dword_591080 )
  {
    if ( !uDialogueType )
    {
      v9 = v6->greet;
      if ( v9 )
      {
        v10 = v6->uFlags;
        a1.uFrameWidth = 460;
        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(
          8u,
          352 - (v11 + 7),
          (Texture *)(uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0),
          (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - (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->uControlParam;
      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 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
          v31 = *(int *)v29;
          v32 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
          sprintf(pTmpBuf, &byte_4F0F98, v32, v31, v30);
          sprintf(pTmpBuf2, dword_F8B1A4, pTmpBuf, 100 * (unsigned __int8)v29[8]);
          ptr_F8B1E8 = pTmpBuf2;
          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->uControlParam = 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->uControlParam = 0;
              v15 = "";
            }
            if ( uDialogueType != 84 )
              goto LABEL_49;
            sprintf(pTmpBuf, format_4E2D80, v55, pItemsTable->pItems[dword_F8B1A8].pUnidentifiedName);
            sprintf(pTmpBuf2, ptr_F8B1E8, pTmpBuf);
            ptr_F8B1E8 = pTmpBuf2;
            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 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
  v35 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(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 ( ptr_F8B1E8 )
  {
    w.uFrameWidth = 458;
    w.uFrameZ = 457;
    v47 = pFontArrus;
    v48 = pFontArrus->CalcTextHeight(ptr_F8B1E8, &w, 13, 0) + 7;
    if ( 352 - v48 < 8 )
    {
      v47 = pFontCreate;
      v48 = pFontCreate->CalcTextHeight(ptr_F8B1E8, &w, 13, 0) + 7;
    }
    pRenderer->_4A6A68(
      8u,
      352 - v48,
      (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
      (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v48);
    pRenderer->DrawTextureIndexed(8u, 347 - v48, pTexture_591428);
    v49 = FitTextInAWindow(ptr_F8B1E8, v47, &w, 0xDu, 0);
    LOBYTE(i) = a1.DrawText(v47, 13, 354 - v48, 0, v49, 0, 0, 0);
  }
  return i;
}





//----- (004B36CC) --------------------------------------------------------
GUIButton *__fastcall sub_4B36CC(int a1, unsigned int a2)
{
  return pDialogueWindow->CreateButton(
           0x1E0u,
           30 * a1 + 146,
           0x8Cu,
           0x1Eu,
           1,
           0,
           0x195u,
           a2,
           0,
           "",
           0);
}



//----- (004B3A72) --------------------------------------------------------
int __thiscall sub_4B3A72(int a1)
{
  int v1; // esi@1
  int result; // eax@4

  v1 = 0;
  if ( a1 == 21 )
  {
    sub_4B36CC(0, 0x66u);
    v1 = 2;
    sub_4B36CC(1, 0x67u);
    if ( pParty->HasItem(0x28Bu) )
    {
      v1 = 3;
      sub_4B36CC(2, 0x68u);
    }
  }
  pDialogueWindow->_41D08F(v1, 1, 0, 2);
  result = pDialogueWindow->pNumPresenceButton;
  dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
  return result;
}
// F8B1E0: using guessed type int dword_F8B1E0;

//----- (004B3AD4) --------------------------------------------------------
int __fastcall sub_4B3AD4(signed int a1)
{
  int result; // eax@7
  int v2; // [sp-10h] [bp-10h]@4
  int v3; // [sp-Ch] [bp-Ch]@4
  int v4; // [sp-8h] [bp-8h]@4
  int v5; // [sp-4h] [bp-4h]@4

  if ( a1 > 0 )
  {
    if ( a1 <= 3 )
    {
      sub_4B36CC(0, 3u);
      sub_4B36CC(1, 4u);
      sub_4B36CC(2, 5u);
      v5 = 2;
      v4 = 0;
      v3 = 1;
      v2 = 3;
      goto LABEL_6;
    }
    if ( a1 == 4 )
    {
      sub_4B36CC(0, 3u);
      sub_4B36CC(1, 4u);
      v5 = 2;
      v4 = 0;
      v3 = 1;
      v2 = 2;
LABEL_6:
      pDialogueWindow->_41D08F(v2, v3, v4, v5);
      goto LABEL_7;
    }
  }
LABEL_7:
  result = pDialogueWindow->pNumPresenceButton;
  dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
  return result;
}
// F8B1E0: using guessed type int dword_F8B1E0;

//----- (004B3B42) --------------------------------------------------------
int __fastcall sub_4B3B42(signed int a1)
{
  int v1; // ecx@18
  int v2; // ecx@19
  int v3; // ecx@20
  signed int v4; // esi@22
  signed int v5; // eax@22
  unsigned int v6; // edx@24
  int v7; // ecx@24
  int result; // eax@43
  int v9; // [sp-10h] [bp-14h]@28
  int v10; // [sp-Ch] [bp-10h]@28
  int v11; // [sp-8h] [bp-Ch]@28
  unsigned int v12; // [sp-4h] [bp-8h]@4
  unsigned int v13; // [sp-4h] [bp-8h]@5
  unsigned int v14; // [sp-4h] [bp-8h]@9
  unsigned int v15; // [sp-4h] [bp-8h]@10
  unsigned int v16; // [sp-4h] [bp-8h]@14
  int v17; // [sp-4h] [bp-8h]@28

  if ( a1 > 13 )
  {
    if ( a1 > 22 )
    {
      if ( a1 == 23 )
      {
        sub_4B36CC(0, 0xAu);
        sub_4B36CC(1, 0xBu);
        v14 = 96;
LABEL_41:
        sub_4B36CC(2, v14);
        v17 = 2;
        v11 = 0;
        v10 = 1;
        v9 = 3;
        goto LABEL_42;
      }
      if ( a1 <= 26 )
        goto LABEL_43;
      if ( a1 > 28 )
      {
        if ( a1 != 30 )
          goto LABEL_43;
        sub_4B36CC(0, 0x11u);
        v16 = 96;
        goto LABEL_37;
      }
      sub_4B36CC(0, 0x69u);
      sub_4B36CC(1, 0x6Au);
      sub_4B36CC(2, 0x6Bu);
      v12 = 108;
    }
    else
    {
      if ( a1 == 22 )
      {
        sub_4B36CC(0, 7u);
        v16 = 8;
        goto LABEL_37;
      }
      v1 = a1 - 14;
      if ( !v1 )
      {
        sub_4B36CC(0, 0x12u);
        sub_4B36CC(1, 0x30u);
        sub_4B36CC(2, 0x31u);
        sub_4B36CC(3, 0x32u);
        sub_4B36CC(4, 0x33u);
        v17 = 2;
        v11 = 0;
        v10 = 1;
        v9 = 5;
        goto LABEL_42;
      }
      v2 = v1 - 1;
      if ( v2 )
      {
        v3 = v2 - 2;
        if ( v3 )
        {
          if ( v3 != 4 )
            goto LABEL_43;
          sub_4B36CC(0, 0xFu);
          sub_4B36CC(1, 0x10u);
          v4 = 3;
          sub_4B36CC(2, 0x60u);
          v5 = (signed int)window_SpeakInHouse->ptr_1C;
          if ( v5 < 108 || v5 > 120 )
            goto LABEL_28;
          v4 = 4;
          v6 = 101;
          v7 = 3;
        }
        else
        {
          v4 = 1;
          sub_4B36CC(0, 0x63u);
          if ( !pParty->uFine )
          {
LABEL_28:
            v17 = 2;
            v11 = 0;
            v10 = 1;
            v9 = v4;
LABEL_42:
            pDialogueWindow->_41D08F(v9, v10, v11, v17);
            goto LABEL_43;
          }
          v4 = 2;
          v7 = 1;
          v6 = 100;
        }
        sub_4B36CC(v7, v6);
        goto LABEL_28;
      }
      sub_4B36CC(0, 0x12u);
      sub_4B36CC(1, 0x34u);
      sub_4B36CC(2, 0x35u);
      v12 = 54;
    }
LABEL_39:
    sub_4B36CC(3, v12);
    v17 = 2;
    v11 = 0;
    v10 = 1;
    v9 = 4;
    goto LABEL_42;
  }
  if ( a1 == 13 )
  {
    sub_4B36CC(0, 0x12u);
    v16 = 56;
LABEL_37:
    sub_4B36CC(1, v16);
    v17 = 2;
    v11 = 0;
    v10 = 1;
    v9 = 2;
    goto LABEL_42;
  }
  switch ( a1 )
  {
    case 1:
    case 2:
    case 3:
    case 4:
      sub_4B36CC(0, 2u);
      sub_4B36CC(1, 0x5Fu);
      sub_4B36CC(2, 0x5Eu);
      v12 = 96;
      goto LABEL_39;
    case 5:
      sub_4B36CC(0, 0x12u);
      v13 = 48;
      goto LABEL_9;
    case 6:
      sub_4B36CC(0, 0x12u);
      v13 = 49;
      goto LABEL_9;
    case 7:
      sub_4B36CC(0, 0x12u);
      v13 = 50;
      goto LABEL_9;
    case 8:
      sub_4B36CC(0, 0x12u);
      v13 = 51;
LABEL_9:
      sub_4B36CC(1, v13);
      v14 = 72;
      goto LABEL_41;
    case 9:
      sub_4B36CC(0, 0x12u);
      v15 = 52;
      goto LABEL_13;
    case 10:
      sub_4B36CC(0, 0x12u);
      v15 = 53;
      goto LABEL_13;
    case 11:
      sub_4B36CC(0, 0x12u);
      v15 = 54;
LABEL_13:
      sub_4B36CC(1, v15);
      v14 = 61;
      goto LABEL_41;
    case 12:
      sub_4B36CC(0, 0x12u);
      v16 = 55;
      goto LABEL_37;
    default:
      break;
  }
LABEL_43:
  result = pDialogueWindow->pNumPresenceButton;
  dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
  return result;
}
// F8B1E0: using guessed type int dword_F8B1E0;

//----- (004B3E1E) --------------------------------------------------------
void __cdecl sub_4B3E1E()
{
  NPCData *v0; // ST40_4@1
  signed int v1; // edi@1
  //GUIWindow *v2; // ecx@1

  __debugbreak();
  v0 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
  v1 = 0;
  pDialogueWindow->eWindowType = WINDOW_MainMenu;
  pDialogueWindow->Release();
  pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_Dialogue, 1, 0);
  if ( pNPCStats->pProfessions[v0->uProfession].pBenefits)//*(&pNPCStats->field_13A5C + 5 * v0->uProfession) )
  {
    pDialogueWindow->CreateButton(480, 160, 140, 28, 1, 0, 136, 77, 0, pGlobalTXT_LocalizationStrings[407], 0);
    v1 = 1;
  }
  pDialogueWindow->CreateButton(480, 30 * v1 + 160, 140, 30, 1, 0, 136, 76, 0, pGlobalTXT_LocalizationStrings[406], 0);//Íàíÿòü
  pDialogueWindow->_41D08F(v1 + 1, 1, 0, 1);
}

//----- (004B3EF0) --------------------------------------------------------
void __fastcall DrawJoinGuildWindow(int pEventNumber)
{
  uDialogueType = 81;//enum JoinGuildDialog
  ptr_F8B1E8 = (char *)pNPCTopics[pEventNumber + 99].pText;
  ContractSelectText(pEventNumber);
  pDialogueWindow->Release();
  pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x15E, WINDOW_MainMenu, pEventNumber, 0);
  pBtn_ExitCancel = pDialogueWindow->CreateButton(0x1D7, 0x1BD, 0xA9, 0x23, 1, 0, 0x71, 0, 0, pGlobalTXT_LocalizationStrings[34],
                 (Texture *)(uTextureID_506438 != -1 ? &pIcons_LOD->pTextures[uTextureID_506438] : 0), 0);
  pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, 0x51u, 0, 0, "", 0);
  pDialogueWindow->CreateButton(0x1E0u, 0xA0u, 0x8Cu, 0x1Eu, 1, 0, 0xAFu, 0x52u, 0, pGlobalTXT_LocalizationStrings[122], 0);
  pDialogueWindow->_41D08F(1, 1, 0, 2);
  dword_F8B19C = -1;
}
// F8B19C: using guessed type int dword_F8B19C;

//----- (004B3FE5) --------------------------------------------------------
void __fastcall sub_4B3FE5(int a4)
{
  int v1; // edi@1
  char *v2; // edi@1

  v1 = a4;
  uDialogueType = 78;
  ptr_F8B1E8 = (char *)pNPCTopics[a4 + 168].pText;
  _4B254D_SkillMasteryTeacher(a4);
  pDialogueWindow->Release();
  pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x15Eu, WINDOW_MainMenu, v1, 0);
  v2 = "";
  pBtn_ExitCancel = pDialogueWindow->CreateButton(
                 0x1D7u,
                 0x1BDu,
                 0xA9u,
                 0x23u,
                 1,
                 0,
                 0x71u,
                 0,
                 0,
                 pGlobalTXT_LocalizationStrings[34],
                 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
                 0);
  pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, 0x51u, 0, 0, "", 0);
  if ( dword_F8B1A8 )
    v2 = pGlobalTXT_LocalizationStrings[535];
  pDialogueWindow->CreateButton(0x1E0u, 0xA0u, 0x8Cu, 0x1Eu, 1, 0, 0xAFu, 0x4Fu, 0, v2, 0);
  pDialogueWindow->_41D08F(1, 1, 0, 2);
  dword_F8B19C = -1;
}
// F8B19C: using guessed type int dword_F8B19C;
// F8B1A8: using guessed type int dword_F8B1A8;

//----- (004B40E6) --------------------------------------------------------
void __cdecl sub_4B40E6()
{
  signed int v0; // ebx@1
  NPCData *v1; // edi@1

  v0 = 0;
  v1 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) - 1)];
  pDialogueWindow->Release();
  pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x15Eu, WINDOW_MainMenu, 0, 0);
  pBtn_ExitCancel = pDialogueWindow->CreateButton(
                 0x1D7u,
                 0x1BDu,
                 0xA9u,
                 0x23u,
                 1,
                 0,
                 0x71u,
                 0,
                 0,
                 pGlobalTXT_LocalizationStrings[34],
                 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
                 0);
  pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, 0x51u, 0, 0, "", 0);
  if ( pNPCStats->pProfessions[v1->uProfession].pBenefits)//*(&pNPCStats->field_13A5C + 5 * v1->uProfession) )
  {
    pDialogueWindow->CreateButton(
      0x1E0u,
      0xA0u,
      0x8Cu,
      0x1Eu,
      1,
      0,
      0xAFu,
      0x4Du,
      0,
      pGlobalTXT_LocalizationStrings[407],
      0);
    v0 = 1;
  }
  pDialogueWindow->CreateButton(
    0x1E0u,
    30 * v0 + 160,
    0x8Cu,
    0x1Eu,
    1,
    0,
    0xAFu,
    0x4Cu,
    0,
    pGlobalTXT_LocalizationStrings[406],
    0);
  pDialogueWindow->_41D08F(v0 + 1, 1, 0, 2);
  dword_F8B19C = -1;
}


//----- (004B4224) --------------------------------------------------------
void _4B4224_UpdateNPCTopics( int _this )
	{
  int num_menu_buttons; // ebx@1
  int i; // ebp@5
 // signed int v4; // ebp@9
  int v6; // eax@16
  int v8; // eax@21
  int v10; // eax@26
  int v12; // eax@31
  int v14; // eax@36
  int v16; // eax@41
  NPCData *v17; // [sp+10h] [bp-4h]@4

  num_menu_buttons = 0;
  pDialogueNPCCount = (_this + 1);
  if ( _this + 1 == uNumDialogueNPCPortraits && uHouse_ExitPic )
  {
    pDialogueWindow->Release();
    pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
    sprintf(sHouseName, pGlobalTXT_LocalizationStrings[LOCSTR_ENTER_S], pMapStats->pInfos[uHouse_ExitPic].pName);
    pBtn_ExitCancel = pDialogueWindow->CreateButton( 566, 445, 75, 33, 1, 0, 0x71u, 0, 0x4Eu,
                   pGlobalTXT_LocalizationStrings[34],// "Cancel"
                   (Texture *)(uTextureID_BUTTDESC2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTDESC2] : 0),0);
    pBtn_YES = pDialogueWindow->CreateButton( 486u, 445u,  75u, 33u, 1, 0,  0xBFu,  1u,  0x59u,
                   sHouseName,
                   (Texture *)(uTextureID_BUTTYES2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTYES2] : 0), 0);
    pDialogueWindow->CreateButton( pNPCPortraits_x[0][0], pNPCPortraits_y[0][0], 63u, 73u, 1, 0,  0xBFu, 1u, 0x20u,  sHouseName, 0);
    pDialogueWindow->CreateButton(8u, 8u, 460u, 344u, 1, 0, 0xBFu, 1u, 0x59u, sHouseName, 0);
  }
  else
  {
    v17 = HouseNPCData[_this + 1 - ((dword_591080 != 0) + 1)];
    if ( dword_F8B19C == -1 )
    {
      pDialogueWindow->Release();
    }
    else
    {
      for ( i = 0; i < uNumDialogueNPCPortraits; ++i )
        GUIButton::_41D0D8((GUIButton *)HouseNPCData[i + 7]);
    }
    pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x159u, WINDOW_MainMenu, 0, 0);
    pBtn_ExitCancel = pDialogueWindow->CreateButton(  471u,  445u,  169u, 35u,  1,   0, 0x71u,  0,  0,
                   pGlobalTXT_LocalizationStrings[74],// "End Conversation"
                   (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),   0);
    pDialogueWindow->CreateButton(8u, 8u, 0x1C2u, 0x140u, 1, 0, 0x51u, 0, 0, "", 0);
    if ( pDialogueNPCCount == 1 && dword_591080 )
    {
      sub_4B3B42(dword_F8B198);
    }
    else
    {
      if ( v17->joins )
      {
        num_menu_buttons = 1;
        pDialogueWindow->CreateButton(480u, 160u, 140u, 30u, 1, 0, 0xAFu, 0xDu, 0, "", 0);
      }
      if ( v17->evt_A)
      {
        if ( num_menu_buttons < 4 )
        {
          v6 = NPC_EventProcessor(v17->evt_A);
          if ( v6 == 1 || v6 == 2 )
            pDialogueWindow->CreateButton(  480u, 30 * num_menu_buttons++ + 160,  140u, 30u, 1, 0, 0xAFu, 0x13u,  0, "",  0);
        }
      }
      if ( v17->evt_B )
      {
        if ( num_menu_buttons < 4 )
        {
          v8 = NPC_EventProcessor(v17->evt_B);
          if ( v8 == 1 || v8 == 2 )
            pDialogueWindow->CreateButton( 480u,  30 * num_menu_buttons++ + 160,  140u, 30u,  1, 0,  0xAFu,  0x14u,  0, "",  0);
        }
      }
      if ( v17->evt_C )
      {
        if ( num_menu_buttons < 4 )
        {
          v10 = NPC_EventProcessor(v17->evt_C);
          if ( v10 == 1 || v10 == 2 )
            pDialogueWindow->CreateButton(  480u,  30 * num_menu_buttons++ + 160,  140u, 30u,  1,  0, 0xAFu, 0x15u, 0, "",  0);
        }
      }
 
      if ( v17->evt_D )
      {
        if ( num_menu_buttons < 4 )
        {
          v12 = NPC_EventProcessor(v17->evt_D);
          if ( v12 == 1 || v12 == 2 )
            pDialogueWindow->CreateButton( 0x1E0u, 30 * num_menu_buttons++ + 160,  0x8Cu, 0x1Eu, 1, 0, 0xAFu, 0x16u,  0, "",  0);
        }
      }
      if ( v17->evt_E )
      {
        if ( num_menu_buttons < 4 )
        {
          v14 = NPC_EventProcessor(v17->evt_E);
          if ( v14 == 1 || v14 == 2 )
            pDialogueWindow->CreateButton( 0x1E0u, 30 * num_menu_buttons++ + 160,  0x8Cu,  0x1Eu,  1,  0,  0xAFu, 0x17u,  0, "",  0);
        }
      }
      if ( v17->evt_F )
      {
        if ( num_menu_buttons < 4 )
        {
          v16 = NPC_EventProcessor(v17->evt_F);
          if ( v16 == 1 || v16 == 2 )
            pDialogueWindow->CreateButton( 0x1E0u, 30 * num_menu_buttons++ + 160,  0x8Cu,  0x1Eu, 1, 0, 0xAFu, 0x18u, 0, "",  0);
        }
      }
      pDialogueWindow->_41D08F(num_menu_buttons, 1, 0, 2);
      dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
    }
    dword_F8B19C = 1;
  }
 
}



//----- (004B46A5) --------------------------------------------------------
char __fastcall DrawTextAtStatusBar(const char *sText, int font_color)
{
  int v4; // eax@1
  pRenderer->DrawTextureRGB(0, 352, pTexture_StatusBar);
  v4 = pFontLucida->AlignText_Center(450, sText);
  return pPrimaryWindow->DrawText(pFontLucida, v4 + 11, 357, font_color, sText, 0, 0, 0);
}

//----- (004B46F8) --------------------------------------------------------
int __fastcall sub_4B46F8(int a1)
{
  int v1; // eax@1
  int i; // edx@1

  v1 = 0;
  for ( i = 0; i < a1; ++i )
    v1 += i + 1;
  return 1000 * v1;
}

//----- (004B4710) --------------------------------------------------------
int __cdecl TrainingDialog()
{
  Player *v0; // ebx@1
  int color2; // eax@1
  unsigned int v2; // ecx@1
  int v3; // eax@1
  signed int v4; // edx@1
  int 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 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
  color2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
  v2 = v0->uLevel;
  v71 = color2;
  v3 = 0;
  v4 = 0;
  for ( i = v2; v4 < (signed int)v2; ++v4 )
    v3 += v4 + 1;
  v5 = 1000 * v3;
  v6 = HIDWORD(v0->uExperience);
  v7 = window_SpeakInHouse->ptr_1C;
  v68 = (unsigned __int16)word_4F0866[(signed int)v7];
  v66 = 1000 * v3;
  if ( (signed __int64)__PAIR__(v6, LODWORD(v0->uExperience)) >= v66 )
  {
    v8 = v0->classType % 4 + 1;
    if ( v8 == 4 )
      v8 = 3;
    v9 = (double)(signed int)i;
    i = 0;
    v69 = v8;
    //v10 = (signed __int64)(v9 * p2DEvents_minus1__20[13 * (signed int)v7] * (double)v8);
    v10 = (signed __int64)(v9 * p2DEvents[(signed int)v7 - 1].fPriceMultiplier * (double)v8);
    v11 = v10 * (100 - v0->GetMerchant()) / 100;
    if ( v11 < v10 / 3 )
      v11 = v10 / 3;
    i = v11;
  }
  result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
  if ( result )
  {
    if ( dword_F8B19C != 1 )
    {
      if ( dword_F8B19C != 17 )
      {
        result = dword_F8B19C - 96;
        if ( dword_F8B19C == 96 )
        {
          result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
          if ( result )
          {
            i = 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 - v0->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)->uControlParam - 36;
              if ( byte_4ED970_skill_learn_ability_by_class_table[v0->classType][v17] && !v0->pActiveSkills[v17] )
              {
                v18 = pFontArrus->CalcTextHeight(pSkillNames[v17], &v65, 0, 0);
                i += v18;
                ++v72;
              }
              ++v15;
            }
            while ( (signed int)v15 < v13->pNumPresenceButton + v13->pStartingPosActiveItem );
            if ( v72 )
            {
              sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v73);// "Skill Cost: %lu"
              v65.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
              v73 = (signed int)(149 - i) / v72;
              if ( v73 > 32 )
                v73 = 32;
              result = v13->pStartingPosActiveItem;
              v19 = (signed int)(149 - v72 * v73 - i) / 2 - v73 / 2 + 162;
              i = result;
              v68 = v19;
              if ( result < result + v13->pNumPresenceButton )
              {
                v72 = 2;
                do
                {
                  v20 = v13->GetControl(i);
                  v21 = v20;
                  v22 = v20->uControlParam - 36;
                  if ( !byte_4ED970_skill_learn_ability_by_class_table[v0->classType][v22] || v0->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 = v71;
                    if ( pDialogueWindow->pCurrentPosActiveItem != v72 )
                      v27 = white;
                    v65.DrawTitleText(pFontArrus, 0, v25, v27, (char *)HIDWORD(v66), 3u);
                  }
                  v28 = v13->pStartingPosActiveItem;
                  ++i;
                  result = v13->pNumPresenceButton + v28;
                  ++v72;
                }
                while ( (signed int)i < result );
              }
            }
            else
            {
LABEL_76:
              sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[544], v0->pName, pClassNames[v0->classType]);// 
                                                // "Seek knowledge elsewhere %s the %s"
              strcat(pTmpBuf, "\n \n");
              strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);// "I can offer you nothing further."
              v29 = v71;
              v30 = pFontArrus->CalcTextHeight(pTmpBuf, &v65, 0, 0);
              result = (int)v65.DrawTitleText(pFontArrus, 0, (174 - v30) / 2 + 138, v29, pTmpBuf, 3u);
            }
          }
        }
        return result;
      }
      if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
      {
        v31 = pNPCTopics[122].pText;
        v32 = v71;
        v33 = pFontArrus->CalcTextHeight(pNPCTopics[122].pText, &v65, 0, 0);
        v65.DrawTitleText(pFontArrus, 0, (212 - v33) / 2 + 101, v32, v31, 3u);
        result = (int)pDialogueWindow;
        pDialogueWindow->pNumPresenceButton = 0;
        return result;
      }
      v34 = v0->uLevel;
      if ( v34 < v68 )
      {
        if ( (signed __int64)v0->uExperience >= v66 )
        {
          if ( pParty->uNumGold >= i )
          {
            Party::TakeGold(i);
            HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, 2);
            ++v0->uLevel;
            v0->uSkillPoints += v0->uLevel / 10 + 5;
            v0->sHealth = v0->GetMaxHealth();
            v0->sMana = v0->GetMaxMana();
            v37 = 0;
            v38 = byte_F8B148;
            do
            {
              if ( *(int *)v38 > v37 )
                v37 = *(int *)v38;
              v38 += 4;
            }
            while ( (signed int)v38 < (signed int)word_F8B158 );
            v39 = &dword_F8B144 + uActiveCharacter;
            ++*v39;
            if ( *v39 > v37 )
            {
              v40 = sub_494820(pParty->uCurrentHour);
              v41 = window_SpeakInHouse->ptr_1C;
              v42 = 60 * (v40 + 4) - pParty->uCurrentMinute;
              if ( v41 == (void *)94 || v41 == (void *)95 )
                v42 += 720;
              RestAndHeal((signed int)(v42 + 10080));
              if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
                pOutdoor->SetFog();
            }
            v0->PlaySound(SPEECH_87, 0);
            sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[430], v0->pName, v0->uLevel, v0->uLevel / 10 + 5);// 
                                                // "%s is now Level %lu and has earned %lu Skill Points!"
            ShowStatusBarString(pTmpBuf, 2u);
            goto LABEL_56;
          }
          ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);// "You don't have enough gold"
          v63 = 4;
LABEL_55:
          HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, v63);
LABEL_56:
          /*result = pMessageQueue_50CBD0->uNumMessages;
          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
          {
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
            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 1; // void function actually
        }
        sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[538], v5 - LODWORD(v0->uExperience), v34 + 1);// 
                                                // "You need %d more experience to train to level %d"
        v35 = 0;
        v62 = 3;
        v60 = pTmpBuf;
        v58 = v71;
        v36 = (212 - pFontArrus->CalcTextHeight(pTmpBuf, &v65, 0, 0)) / 2 + 88;
      }
      else
      {
        sprintf(pTmpBuf, "%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;
        v58 = v71;
        v36 = (212 - pFontArrus->CalcTextHeight(pTmpBuf, &v65, 0, 0)) / 2 + 101;
      }
      v65.DrawTitleText(pFontArrus, v35, v36, v58, v60, v62);
      v63 = 3;
      goto LABEL_55;
    }
    result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
    if ( result )
    {
      v43 = pDialogueWindow;
      v72 = 0;
      pShopOptions[0] = pTmpBuf;
      pShopOptions[1] = pGlobalTXT_LocalizationStrings[160];// "Learn Skills"
      v44 = pDialogueWindow->pNumPresenceButton;
      v73 = pDialogueWindow->pStartingPosActiveItem;
      if ( v73 < v73 + v44 )
      {
        v45 = pShopOptions;
        do
        {
          if ( v43->GetControl(v73)->uControlParam == 17 )
          {
            v46 = v0->uLevel;
            if ( v46 < v68 )
            {
              if ( (signed __int64)v0->uExperience < v66 )
              {
                v64 = (char *)(v46 + 1);
                v61 = (char *)(v5 - LODWORD(v0->uExperience));
                v59 = pGlobalTXT_LocalizationStrings[538];// "You need %d more experience to train to level %d"
              }
              else
              {
                v64 = (char *)i;
                v61 = (char *)(v46 + 1);
                v59 = pGlobalTXT_LocalizationStrings[537];// "Train to level %d for %d gold"
              }
            }
            else
            {
              v64 = pGlobalTXT_LocalizationStrings[529];// ""Sorry, but we are unable to train you.""
              v61 = pGlobalTXT_LocalizationStrings[536];// ""With your skills, you should be working here as a teacher.""
              v59 = "%s\n \n%s";
            }
            sprintf(*v45, v59, v61, v64);
          }
          v47 = pFontArrus->CalcTextHeight(*v45, &v65, 0, 0);
          v43 = pDialogueWindow;
          v72 += v47;
          ++v45;
          ++v73;
        }
        while ( v73 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
      }
      HIDWORD(v66) = (174 - v72) / 2;
      result = v43->pStartingPosActiveItem;
      v48 = result + v43->pNumPresenceButton;
      v49 = (2 * (87 - (174 - v72) / 2) - v72) / 2 - (174 - v72) / 2 / 2 + 138;
      v50 = -v43->pNumPresenceButton < 0;
      v73 = v43->pStartingPosActiveItem;
      if ( v50 ^ __OFSUB__(result, v48) )
      {
        i = 2;
        v51 = pShopOptions;
        do
        {
          v52 = v43->GetControl(v73);
          v53 = v52;
          v52->uY = HIDWORD(v66) + v49;
          v54 = pFontArrus->CalcTextHeight(*v51, &v65, 0, 0);
          v55 = v53->uY;
          v53->uHeight = v54;
          v56 = v54 + v55 - 1;
          v53->uW = v56;
          v49 = v56;
          v57 = v71;
          if ( pDialogueWindow->pCurrentPosActiveItem != i )
            v57 = white;
          v65.DrawTitleText(pFontArrus, 0, v55, v57, *v51, 3u);
          v43 = pDialogueWindow;
          ++i;
          ++v51;
          ++v73;
          result = pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem;
        }
        while ( v73 < result );
      }
    }
  }
  return result;
}









//----- (004B4FCF) --------------------------------------------------------
int __cdecl MagicShopDialog()
{
  Player *v0; // ebx@1
  int result; // eax@6
  signed int v2; // esi@8
  unsigned int v3; // ebx@10
  char *v4; // eax@11
  char *v5; // eax@12
  unsigned int v6; // eax@12
  int v7; // ST08_4@14
  int v8; // eax@14
  unsigned __int8 v9; // dl@14
  char *v10; // ecx@14
  signed int v11; // esi@16
  int v12; // ST08_4@19
  int v13; // eax@19
  int v14; // edi@21
  char **v15; // esi@21
  int v16; // eax@22
  GUIWindow *v17; // ecx@23
  int v18; // edx@23
  int v19; // edi@23
  unsigned __int8 v20; // sf@23
  GUIButton *v21; // esi@25
  const char **v22; // eax@25
  int v23; // eax@25
  unsigned int v24; // ecx@25
  const char **v25; // edx@25
  unsigned __int16 v26; // ax@25
  signed int v27; // esi@30
  int v28; // ST08_4@34
  int v29; // eax@34
  char *v30; // edx@35
  GUIWindow *v31; // edi@40
  void *v32; // eax@40
  signed int v33; // esi@40
  unsigned int v34; // esi@42
  int v35; // eax@42
  unsigned int v36; // eax@43
  int v37; // eax@45
  int v38; // ecx@50
  GUIButton *v39; // eax@52
  GUIButton *v40; // esi@52
  int v41; // eax@52
  char *v42; // eax@54
  int v43; // eax@54
  unsigned int v44; // ecx@54
  int v45; // edx@54
  int v46; // eax@54
  unsigned __int16 v47; // ax@54
  int v48; // eax@58
  signed int v49; // esi@62
  Texture *v50; // ecx@64
  unsigned int v51; // edi@64
  unsigned int v52; // esi@66
  int v53; // edx@70
  Texture *v54; // ecx@76
  unsigned int v55; // edi@76
  unsigned int v56; // esi@76
  int v57; // edx@80
  Texture *v58; // ecx@86
  unsigned int v59; // edi@86
  unsigned int v60; // esi@88
  int v61; // edx@92
  Texture *v62; // ecx@98
  unsigned int v63; // edi@98
  unsigned int v64; // esi@100
  int v65; // edx@104
  signed int v66; // ecx@109
  SHORT v67; // di@117
  bool v68; // eax@117
  const char *v69; // ecx@119
  POINT *v70; // esi@124
  int v71; // ecx@125
  int v72; // eax@125
  int v73; // ecx@125
  ItemGen *v74; // esi@125
  int v75; // eax@130
  int v76; // esi@131
  char **v77; // edi@131
  int v78; // eax@132
  GUIWindow *v79; // ecx@133
  int v80; // edx@133
  int v81; // edi@133
  GUIButton *v82; // esi@135
  const char **v83; // eax@135
  int v84; // eax@135
  unsigned int v85; // ecx@135
  int v86; // edx@135
  unsigned __int16 v87; // ax@135
  GUIWindow *v88; // [sp-18h] [bp-110h]@35
  int v89; // [sp-14h] [bp-10Ch]@35
  ItemGen *v90; // [sp-10h] [bp-108h]@14
  int v91; // [sp-10h] [bp-108h]@35
  unsigned __int16 v92; // [sp-Ch] [bp-104h]@12
  void *v93; // [sp-Ch] [bp-104h]@14
  int v94; // [sp-8h] [bp-100h]@11
  char *v95; // [sp-8h] [bp-100h]@12
  __int64 *v96; // [sp-4h] [bp-FCh]@11
  unsigned int v97; // [sp-4h] [bp-FCh]@12
  POINT v98; // [sp+Ch] [bp-ECh]@8
  POINT v99; // [sp+14h] [bp-E4h]@16
  POINT v100; // [sp+1Ch] [bp-DCh]@124
  POINT v101; // [sp+24h] [bp-D4h]@17
  POINT v102; // [sp+2Ch] [bp-CCh]@124
  POINT v103; // [sp+34h] [bp-C4h]@9
  POINT v104; // [sp+3Ch] [bp-BCh]@31
  POINT v105; // [sp+44h] [bp-B4h]@16
  POINT v106; // [sp+4Ch] [bp-ACh]@30
  POINT v107; // [sp+54h] [bp-A4h]@16
  POINT v108; // [sp+5Ch] [bp-9Ch]@30
  POINT a2; // [sp+64h] [bp-94h]@8
  POINT v110; // [sp+6Ch] [bp-8Ch]@30
  POINT v111; // [sp+74h] [bp-84h]@8
  GUIWindow v112; // [sp+7Ch] [bp-7Ch]@1
  char *Str; // [sp+D0h] [bp-28h]@54
  int v114; // [sp+D4h] [bp-24h]@23
  unsigned int color2; // [sp+D8h] [bp-20h]@1
  unsigned int white; // [sp+DCh] [bp-1Ch]@1
  __int32 v117; // [sp+E0h] [bp-18h]@8
  int v118; // [sp+E4h] [bp-14h]@40
  const char **v119; // [sp+E8h] [bp-10h]@24
  Player *_this; // [sp+ECh] [bp-Ch]@1
  unsigned __int8 uPlayerID; // [sp+F3h] [bp-5h]@14
  int v122; // [sp+F4h] [bp-4h]@23

  v0 = pPlayers[uActiveCharacter];
  _this = pPlayers[uActiveCharacter];
  memcpy(&v112, window_SpeakInHouse, sizeof(v112));
  v112.uFrameX = 483;
  v112.uFrameWidth = 148;
  v112.uFrameZ = 334;
  white = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
  color2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
  if ( dword_F8B19C > 5 )
  {
    if ( dword_F8B19C == 94 )
    {
      draw_leather();
      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
      pShopOptions[0] = pGlobalTXT_LocalizationStrings[200];// "Sell"
      pShopOptions[1] = pGlobalTXT_LocalizationStrings[113];// "Identify"
      pShopOptions[2] = pGlobalTXT_LocalizationStrings[179];// "Repair"
      v76 = 0;
      v77 = pShopOptions;
      do
      {
        v78 = pFontArrus->CalcTextHeight(*v77, &v112, 0, 0);
        ++v77;
        v76 += v78;
      }
      while ( (signed int)v77 < (signed int)&pShopOptions[3] );
      v79 = pDialogueWindow;
      _this = (Player *)((174 - v76) / 3);
      result = pDialogueWindow->pStartingPosActiveItem;
      v80 = result + pDialogueWindow->pNumPresenceButton;
      v81 = (3 * (58 - (signed int)_this) - v76) / 2 - (174 - v76) / 3 / 2 + 138;
      v20 = -pDialogueWindow->pNumPresenceButton < 0;
      v118 = pDialogueWindow->pStartingPosActiveItem;
      if ( v20 ^ __OFSUB__(result, v80) )
      {
        v122 = 2;
        v119 = (const char **)pShopOptions;
        do
        {
          v82 = v79->GetControl(v118);
          v83 = v119;
          v82->uY = (unsigned int)((char *)_this + v81);
          v84 = pFontArrus->CalcTextHeight(*v83, &v112, 0, 0);
          v85 = v82->uY;
          v86 = v122;
          v82->uHeight = v84;
          v81 = v84 + v85 - 1;
          v82->uW = v81;
          v87 = color2;
          if ( pDialogueWindow->pCurrentPosActiveItem != v86 )
            v87 = white;
          v112.DrawTitleText(pFontArrus, 0, v85, v87, *v119, 3u);
          v79 = pDialogueWindow;
          ++v122;
          ++v119;
          ++v118;
          result = pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem;
        }
        while ( v118 < result );
      }
      return result;
    }
    if ( dword_F8B19C != 95 )
    {
      result = dword_F8B19C - 96;
      if ( dword_F8B19C == 96 )
      {
        result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
        if ( result )
        {
          v31 = pDialogueWindow;
          v3 = 0;
          v32 = window_SpeakInHouse->ptr_1C;
          v118 = 0;
            //v33 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (signed int)v32] * 500.0);
            v33 = (signed __int64)(p2DEvents[(signed int)v32 - 1].flt_24 * 500.0);
          v119 = (const char **)(v33 * (100 - _this->GetMerchant()) / 100);
          if ( (signed int)v119 < v33 / 3 )
            v119 = (const char **)(v33 / 3);
          v34 = v31->pStartingPosActiveItem;
          v35 = v34 + v31->pNumPresenceButton;
          v122 = 0;
          if ( (signed int)v34 >= v35 )
            goto LABEL_140;
          do
          {
            v36 = v31->GetControl(v34)->uControlParam - 36;
            if ( byte_4ED970_skill_learn_ability_by_class_table[_this->classType][v36] && !_this->pActiveSkills[v36] )
            {
              v37 = pFontArrus->CalcTextHeight(pSkillNames[v36], &v112, 0, 0);
              v118 += v37;
              ++v122;
            }
            ++v34;
          }
          while ( (signed int)v34 < v31->pNumPresenceButton + v31->pStartingPosActiveItem );
          if ( !v122 )
          {
LABEL_140:
            sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[544], _this->pName, pClassNames[_this->classType]);// 
                                                // "Seek knowledge elsewhere %s the %s"
            strcat(pTmpBuf, "\n \n");
            strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);// "I can offer you nothing further."
            v30 = pTmpBuf;
            v97 = 3;
            v95 = pTmpBuf;
            v92 = color2;
            v91 = 0;
            v89 = 0;
            v88 = &v112;
            goto LABEL_61;
          }
          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v119);// "Skill Cost: %lu"
          v112.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
          v119 = (const char **)((149 - v118) / v122);
          if ( (149 - v118) / v122 > 32 )
            v119 = (const char **)32;
          result = v31->pStartingPosActiveItem;
          v38 = (149 - v122 * (signed int)v119 - v118) / 2 - (signed int)v119 / 2 + 162;
          v118 = result;
          v114 = v38;
          if ( result < result + v31->pNumPresenceButton )
          {
            v122 = 2;
            do
            {
              v39 = v31->GetControl(v118);
              v40 = v39;
              v41 = v39->uControlParam - 36;
              if ( !byte_4ED970_skill_learn_ability_by_class_table[_this->classType][v41] || _this->pActiveSkills[v41] )
              {
                v40->uW = 0;
                v40->uHeight = 0;
                v40->uY = 0;
              }
              else
              {
                v42 = pSkillNames[v41];
                v40->uY = (unsigned int)((char *)v119 + v114);
                Str = v42;
                v43 = pFontArrus->CalcTextHeight(v42, &v112, 0, 0);
                v44 = v40->uY;
                v45 = v122;
                v40->uHeight = v43;
                v46 = v44 + v43 - 1;
                v40->uW = v46;
                v114 = v46;
                v47 = color2;
                if ( pDialogueWindow->pCurrentPosActiveItem != v45 )
                  v47 = white;
                v112.DrawTitleText(pFontArrus, 0, v44, v47, Str, 3u);
              }
              v48 = v31->pStartingPosActiveItem;
              ++v118;
              result = v31->pNumPresenceButton + v48;
              ++v122;
            }
            while ( v118 < result );
          }
        }
      }
      return result;
    }
  }
  else
  {
    if ( dword_F8B19C == 5 )
    {
      draw_leather();
      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
      DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[198], 0);// "Select the Item to Repair"
      result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
      if ( !result
        || (v27 = pMouse->GetCursorPos(&v110)->x - 14,
            v117 = (v27 >> 5) + 14 * ((pMouse->GetCursorPos(&v108)->y - 17) >> 5),
            result = (int)pMouse->GetCursorPos(&v106),
            *(int *)result <= 13)
        || (result = (int)pMouse->GetCursorPos(&v104), *(int *)result >= 462)
        || (result = v0->GetItemIDAtInventoryIndex((int *)&v117), v3 = 0, !result)
        || (result *= 9, !(_this->field_1F5[4 * result + 15] & 2)) )
        return result;
      v96 = 0;
      v94 = 5;
      v93 = window_SpeakInHouse->ptr_1C;
      v90 = (ItemGen *)&_this->spellbook.pDarkSpellbook.bIsSpellAvailable[4 * result + 5];
      v28 = (int)window_SpeakInHouse->ptr_1C;
      uPlayerID = uActiveCharacter - 1;
      v29 = _this->_490EEE((ItemGen *)&_this->spellbook.pDarkSpellbook.bIsSpellAvailable[4 * result + 5], 3, v28, 5);
      v9 = uPlayerID;
      v10 = (char *)pMerchantsRepairPhrases[v29];
      goto LABEL_35;
    }
    if ( dword_F8B19C == 1 )
    {
      result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
      if ( result )
      {
        pShopOptions[0] = pGlobalTXT_LocalizationStrings[134];// "Buy Standard"
        pShopOptions[1] = pGlobalTXT_LocalizationStrings[152];// "Buy Special"
        pShopOptions[2] = pGlobalTXT_LocalizationStrings[159];// "Display Inventory"
        v14 = 0;
        pShopOptions[3] = pGlobalTXT_LocalizationStrings[160];// "Learn Skills"
        v15 = pShopOptions;
        do
        {
          v16 = pFontArrus->CalcTextHeight(*v15, &v112, 0, 0);
          ++v15;
          v14 += v16;
        }
        while ( (signed int)v15 < (signed int)&unk_F8B1C8 );
        v17 = pDialogueWindow;
        v114 = (174 - v14) / 4;
        result = pDialogueWindow->pStartingPosActiveItem;
        v18 = result + pDialogueWindow->pNumPresenceButton;
        v19 = (174 - 4 * (174 - v14) / 4 - v14) / 2 - (174 - v14) / 4 / 2 + 138;
        v20 = -pDialogueWindow->pNumPresenceButton < 0;
        v122 = pDialogueWindow->pStartingPosActiveItem;
        if ( v20 ^ __OFSUB__(result, v18) )
        {
          v119 = (const char **)2;
          _this = (Player *)pShopOptions;
          do
          {
            v21 = v17->GetControl(v122);
            v22 = (const char **)_this;
            v21->uY = v114 + v19;
            v23 = pFontArrus->CalcTextHeight(*v22, &v112, 0, 0);
            v24 = v21->uY;
            v25 = v119;
            v21->uHeight = v23;
            v19 = v24 + v23 - 1;
            v21->uW = v19;
            v26 = color2;
            if ( (const char **)pDialogueWindow->pCurrentPosActiveItem != v25 )
              v26 = white;
            v112.DrawTitleText(pFontArrus, 0, v24, v26, (const char *)LODWORD(_this->pConditions[0]), 3u);
            v17 = pDialogueWindow;
            v119 = (const char **)((char *)v119 + 1);
            _this = (Player *)((char *)_this + 4);
            ++v122;
            result = pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem;
          }
          while ( v122 < result );
        }
      }
      return result;
    }
    if ( dword_F8B19C != 2 )
    {
      if ( dword_F8B19C != 3 )
      {
        result = dword_F8B19C - 4;
        if ( dword_F8B19C == 4 )
        {
          draw_leather();
          CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
          DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[197], 0);// "Select the Item to Identify"
          result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
          if ( result )
          {
            v2 = pMouse->GetCursorPos(&a2)->x - 14;
            v117 = (v2 >> 5) + 14 * ((pMouse->GetCursorPos(&v98)->y - 17) >> 5);
            result = (int)pMouse->GetCursorPos(&v111);
            if ( *(int *)result > 13 )
            {
              result = (int)pMouse->GetCursorPos(&v103);
              if ( *(int *)result < 462 )
              {
                result = v0->GetItemIDAtInventoryIndex((int *)&v117);
                v3 = 0;
                if ( result )
                {
                  v96 = 0;
                  v94 = 4;
                  v4 = (char *)&_this->pInventoryItems[result-1];
                  if ( v4[20] & 1 )
                  {
                    v5 = BuilDialogueString("%24", uActiveCharacter - 1, (ItemGen *)v4, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
                    v97 = 3;
                    v95 = v5;
                    v92 = white;
                    v6 = (212 - pFontArrus->CalcTextHeight(v5, &v112, 0, 0)) / 2 + 101;
                    return (int)v112.DrawTitleText(pFontArrus, v3, v6, v92, v95, v97);
                  }
                  v93 = window_SpeakInHouse->ptr_1C;
                  v90 = (ItemGen *)v4;
                  v7 = (int)window_SpeakInHouse->ptr_1C;
                  uPlayerID = uActiveCharacter - 1;
                  v8 = ((Player *)_this)->_490EEE((ItemGen *)v4, 3, v7, 4);
                  v9 = uPlayerID;
                  v10 = (char *)pMerchantsIdentifyPhrases[v8];
                  goto LABEL_35;
                }
              }
            }
          }
        }
        return result;
      }
      draw_leather();
      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
      DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[199], 0);// "Select the Item to Sell"
      result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
      if ( !result
        || (v11 = pMouse->GetCursorPos(&v107)->x - 14,
            v117 = (v11 >> 5) + 14 * ((pMouse->GetCursorPos(&v99)->y - 17) >> 5),
            result = (int)pMouse->GetCursorPos(&v105),
            *(int *)result <= 13)
        || (result = (int)pMouse->GetCursorPos(&v101), *(int *)result >= 462)
        || (result = v0->GetItemIDAtInventoryIndex((int *)&v117), v3 = 0, !result) )
        return result;
      v96 = 0;
      v94 = 3;
      v93 = window_SpeakInHouse->ptr_1C;
      v90 = (ItemGen *)&_this->pInventoryItems[result-1];
      v12 = (int)window_SpeakInHouse->ptr_1C;
      uPlayerID = uActiveCharacter - 1;
      v13 = _this->_490EEE(v90, 3, v12, 3);
      v9 = uPlayerID;
      v10 = (char *)pMerchantsSellPhrases[v13];
LABEL_35:
      v30 = BuilDialogueString(v10, v9, v90, (char *)v93, v94, v96);
      v97 = 3;
      v95 = v30;
      v92 = white;
      v91 = v3;
      v89 = v3;
      v88 = &v112;
LABEL_61:
      v6 = (174 - pFontArrus->CalcTextHeight(v30, v88, v89, v91)) / 2 + 138;
      return (int)v112.DrawTitleText(pFontArrus, v3, v6, v92, v95, v97);
    }
  }
  pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
  v3 = 0;
  v49 = 0;
  v122 = 0;
  if ( dword_F8B19C == 2 )
  {
    do
    {
     // if ( pParty->field_777C[9 * (v49 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C)] )
	 if ( pParty->StandartItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][v49].uItemID);
      {
        v50 = ItemsInShopTexture[v49];
        v51 = 152 - v50->uTextureHeight;
        if ( (signed int)v51 < 1 )
          v51 = 0;
        v52 = 75 * v49 - v50->uTextureWidth / 2 + 40;
        if ( v122 )
        {
          if ( v122 == 5 )
          {
            v53 = ItemsInShopTexture[5]->uTextureWidth;
            if ( (signed int)v52 > 457 - v53 )
              v52 = 457 - v53;
          }
        }
        else
        {
          if ( (signed int)v52 < 18 )
            v52 = 18;
        }
        pRenderer->DrawTextureTransparent(v52, v51, v50);
        sub_40F92A(&pRenderer->pActiveZBuffer[v52 + 640 * v51], ItemsInShopTexture[v122], v122 + 1);
        v49 = v122;
      }
      ++v49;
      v122 = v49;
    }
    while ( v49 < 6 );
    v122 = 0;
    do
    {
      //if ( pParty->field_777C[9 * (v122 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C) + 54] )
	if ( pParty->StandartItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][v122+1].uItemID);
      {
        v54 = ItemsInShopTexture[v122 + 6];
        v55 = 306 - v54->uTextureHeight;
        v56 = 75 * v122 - v54->uTextureWidth / 2 + 40;
        if ( v122 )
        {
          if ( v122 == 5 )
          {
            v57 = ItemsInShopTexture[11]->uTextureWidth;
            if ( (signed int)v56 > 457 - v57 )
              v56 = 457 - v57;
          }
        }
        else
        {
          if ( (signed int)v56 < 18 )
            v56 = 18;
        }
        pRenderer->DrawTextureTransparent(v56, v55, v54);
        sub_40F92A(&pRenderer->pActiveZBuffer[v56 + 640 * v55], ItemsInShopTexture[v122 + 6], v122 + 7);
      }
      ++v122;
    }
    while ( v122 < 6 );
  }
  else
  {
    do
    {
     // if ( pParty->field_C59C[9 * (v49 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C) + 724] )
	if (pParty->SpecialItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][v49].uItemID)
      {
        v58 = ItemsInShopTexture[v49];
        v59 = 152 - v58->uTextureHeight;
        if ( (signed int)v59 < 1 )
          v59 = 0;
        v60 = 75 * v49 - v58->uTextureWidth / 2 + 40;
        if ( v122 )
        {
          if ( v122 == 5 )
          {
            v61 = ItemsInShopTexture[5]->uTextureWidth;
            if ( (signed int)v60 > 457 - v61 )
              v60 = 457 - v61;
          }
        }
        else
        {
          if ( (signed int)v60 < 18 )
            v60 = 18;
        }
        pRenderer->DrawTextureTransparent(v60, v59, v58);
        sub_40F92A(&pRenderer->pActiveZBuffer[v60 + 640 * v59], ItemsInShopTexture[v122], v122 + 1);
        v49 = v122;
      }
      ++v49;
      v122 = v49;
    }
    while ( v49 < 6 );
    v122 = 0;
    do
    {
      //if ( pParty->Spell_Item[(unsigned int)window_SpeakInHouse->ptr_1C][v49] + 778] )  //weak
		if (pParty->SpecialItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][v49].uAttributes)
      {
        v62 = ItemsInShopTexture[v122 + 6];
        v63 = 306 - v62->uTextureHeight;
        if ( (signed int)v63 < 1 )
          v63 = 0;
        v64 = 75 * v122 - v62->uTextureWidth / 2 + 40;
        if ( v122 )
        {
          if ( v122 == 5 )
          {
            v65 = ItemsInShopTexture[11]->uTextureWidth;
            if ( (signed int)v64 > 457 - v65 )
              v64 = 457 - v65;
          }
        }
        else
        {
          if ( (signed int)v64 < 18 )
            v64 = 18;
        }
        pRenderer->DrawTextureTransparent(v64, v63, v62);
        sub_40F92A(&pRenderer->pActiveZBuffer[v64 + 640 * v63], ItemsInShopTexture[v122 + 6], v122 + 7);
      }
      ++v122;
    }
    while ( v122 < 6 );
  }
  result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
  if ( result )
  {
    v66 = 0;
    v117 = 0;
    if ( dword_F8B19C == 2 )
    {
      do
      {
        if ( pParty->StandartItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][v66].uItemID); //9 * (v66 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C)] )
          ++v117;
        ++v66;
      }
      while ( v66 < 12 );
    }
    else
    {
      do
      {
        //if ( pParty->field_C59C[9 * (v66 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C) + 724] )
	  if (pParty->SpecialItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][v66].uItemID)
          ++v117;
        ++v66;
      }
      while ( v66 < 12 );
    }
    v67 = GetAsyncKeyState(VK_CONTROL);
    v68 = _this->CanSteal();
    Str = (char *)v68;
    if ( v67 && v68 )
    {
      v69 = pGlobalTXT_LocalizationStrings[185];// "Steal item"
    }
    else
    {
      v69 = pGlobalTXT_LocalizationStrings[195];// "Select the Item to Buy"
      if ( dword_F8B19C != 2 )
        v69 = pGlobalTXT_LocalizationStrings[196];// "Select the Special Item to Buy"
    }
    DrawTextAtStatusBar(v69, 0);
    if ( !v117 )
		{
      v112.DrawCurrentTime( pParty->field_3C.field_50[(unsigned int)window_SpeakInHouse->ptr_1C] - pParty->uTimePlayed);
	  return 0;
		}
    v70 = pMouse->GetCursorPos(&v102);
    result = v70->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v100)->y];
    if ( pRenderer->pActiveZBuffer[result] & 0xFFFF )
    {
      v71 = (pRenderer->pActiveZBuffer[result] & 0xFFFF) - 1;
      v117 = v71;
      v72 = (int)window_SpeakInHouse->ptr_1C;
     // v73 = 9 * (v71 + 12 * v72);
      v74 = (ItemGen *)&pParty->StandartItemsInShops[v72][v71];
      if ( dword_F8B19C != 2 )
       // v74 = (ItemGen *)&pParty->field_C59C[v73 + 724];
	      v74 =&pParty->SpecialItemsInShops[v72][v71];
      if ( v67 && Str )
      {
        v10 = pGlobalTXT_LocalizationStrings[181];// "Steal %24"
        v96 = 0;
        v94 = 2;
        v93 = window_SpeakInHouse->ptr_1C;
        v90 = v74;
        v9 = uActiveCharacter - 1;
      }
      else
      {
        v96 = 0;
        v94 = 2;
        v93 = window_SpeakInHouse->ptr_1C;
        v90 = v74;
        uPlayerID = uActiveCharacter - 1;
        v75 = _this->_490EEE(v74, 3, v72, 2);
        v9 = uPlayerID;
        v10 = (char *)pMerchantsBuyPhrases[v75];
      }
      goto LABEL_35;
    }
  }
  return result;
}

//----- (004BC49B) --------------------------------------------------------
void OnSelectDialogueOption(DIALOGUE_TYPE newDialogueType)
{
  //unsigned int v1; // esi@1
  NPCData *v2; // ebp@1
  //unsigned int v3; // eax@1
  int v4; // ecx@10
  signed int v5; // edi@14
  char *v6; // esi@15
  const char *v7; // ecx@22
  signed int v8; // edi@37
  //unsigned int v9; // eax@56
  unsigned int v10; // ecx@57
  void *v11; // [sp-Ch] [bp-1Ch]@46
  int v12; // [sp-8h] [bp-18h]@46
  char *v13; // [sp-8h] [bp-18h]@60
  size_t v14; // [sp-4h] [bp-14h]@46
  const char *v15; // [sp-4h] [bp-14h]@60

  //v1 = _this;
  v2 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
  //v3 = v1;
  uDialogueType = newDialogueType;
  if ( !v2->uFlags )
  {
    v2->uFlags = 1;
    //v3 = uDialogueType;
  }
  if ( (signed int)newDialogueType > 22 )
  {
    if ( newDialogueType == DIALOGUE_23 )
    {
      v4 = v2->evt_E;
      goto LABEL_74;
    }
    if (newDialogueType == DIALOGUE_24)
    {
      v4 = v2->evt_F;
      goto LABEL_74;
    }
    if (newDialogueType != DIALOGUE_76)
    {
      if (newDialogueType == DIALOGUE_PROFESSION_DETAILS)
      {
        dialogue_show_profession_details = ~dialogue_show_profession_details;
      }
      else
      {
        if ( (signed int)newDialogueType > 84 && (signed int)newDialogueType <= 88 )
        {
          ArenaFight();
          return;
        }
      }
      goto LABEL_87;
    }
    if (v2->Hired())
    {
      v8 = 0;
      if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
      {
        v6 = (char *)pNPCStats->pNewNPCData;
        while ( !(v6[8] & 0x80) || strcmp(v2->pName, *(const char **)v6) )
        {
          ++v8;
          v6 += 76;
          if ( v8 >= (signed int)pNPCStats->uNumNewNPCs )
            goto LABEL_44;
        }
        goto LABEL_43;
      }
LABEL_44:
      if ( !pParty->pHirelings[0].pName || _strcmpi(pParty->pHirelings[0].pName, v2->pName) )
      {
        if ( !pParty->pHirelings[1].pName || _strcmpi(pParty->pHirelings[1].pName, v2->pName) )
        {
LABEL_51:
          pParty->field_709 = 0;
          sub_44A56A();
          dword_591084 = 0;
          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
          {
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
            ++pMessageQueue_50CBD0->uNumMessages;
          }*/
          goto LABEL_89;
        }
        v14 = 76;
        v12 = 0;
        v11 = &pParty->pHirelings[1];
      }
      else
      {
        v14 = 76;
        v12 = 0;
        v11 = pParty->pHirelings;
      }
      memset(v11, v12, v14);
      goto LABEL_51;
    }
    if ( pParty->pHirelings[0].pName && pParty->pHirelings[1].pName )
    {
      v7 = pGlobalTXT_LocalizationStrings[533]; // ""I cannot join you, you're party is full""
LABEL_64:
      ShowStatusBarString(v7, 2u);
      goto LABEL_87;
    }
    //v9 = v2->uProfession;
    if ( v2->uProfession != 51 )
    {
      v10 = pNPCStats->pProfessions[v2->uProfession - 1].uHirePrice;
      if ( pParty->uNumGold < v10 )
      {
        ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);// "You don't have enough gold"
        dialogue_show_profession_details = false;
        uDialogueType = 13;
        if ( uActiveCharacter )
          pPlayers[uActiveCharacter]->PlaySound(SPEECH_NotEnoughGold, 0);
        v7 = pGlobalTXT_LocalizationStrings[155];
        goto LABEL_64;
      }
      Party::TakeGold(v10);
    }
    LOBYTE(v2->uFlags) |= 0x80u;
    if ( pParty->pHirelings[0].pName )
    {
      memcpy(&pParty->pHirelings[1], v2, sizeof(pParty->pHirelings[1]));
      v15 = v2->pName;
      v13 = pParty->pHireling2Name;
    }
    else
    {
      memcpy(pParty->pHirelings, v2, 0x4Cu);
      v15 = v2->pName;
      v13 = pParty->pHireling1Name;
    }
    strcpy(v13, v15);
    pParty->field_709 = 0;
    sub_44A56A();

    pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
    {
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
      *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
      ++pMessageQueue_50CBD0->uNumMessages;
    }*/
    if ( (uDialogue_SpeakingActorNPC_ID & 0x80000000u) == 0 )
      pDialogue_SpeakingActor->uAIState = Removed;
    if ( uActiveCharacter )
      pPlayers[uActiveCharacter]->PlaySound(SPEECH_61, 0);
    goto LABEL_87;
  }
  if (newDialogueType == DIALOGUE_22)
  {
    v4 = v2->evt_D;
    goto LABEL_74;
  }
  if (newDialogueType == DIALOGUE_9)
  {
    if ( !sub_4BB756(v2->uProfession) )
    {
      if ( v2->uProfession != 41 )
        v2->bHasUsedTheAbility = 1;
      /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
      {
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
        *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
        ++pMessageQueue_50CBD0->uNumMessages;
      }*/
      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
      goto LABEL_87;
    }
    v7 = pGlobalTXT_LocalizationStrings[140];
    goto LABEL_64;
  }
  if (newDialogueType == DIALOGUE_13)
  {
    if (!v2->Hired())
    {
      sub_4B3E1E();
      dialogue_show_profession_details = false;
      goto LABEL_87;
    }
    v5 = 0;
    if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
    {
      v6 = (char *)pNPCStats->pNewNPCData;
      while ( !(v6[8] & 0x80) || strcmp(v2->pName, *(const char **)v6) )
      {
        ++v5;
        v6 += 76;
        if ( v5 >= (signed int)pNPCStats->uNumNewNPCs )
          goto LABEL_44;
      }
LABEL_43:
      v6[8] &= 0x7Fu;
      goto LABEL_44;
    }
    goto LABEL_44;
  }
  if (newDialogueType == DIALOGUE_19)
  {
    v4 = v2->evt_A;
    goto LABEL_74;
  }
  if (newDialogueType == DIALOGUE_20)
  {
    v4 = v2->evt_B;
    goto LABEL_74;
  }
  if (newDialogueType == DIALOGUE_21)
  {
    v4 = v2->evt_C;
LABEL_74:
    if ( v4 < 200 || v4 > 310 )
    {
      if ( v4 < 400 || v4 > 410 )
      {
        switch ( v4 )
        {
          case 139:
            sub_4B1ECE();
            break;
          case 311:
            sub_4BBA85_bounties();
            break;
          case 399:
            sub_4BBCDD();
            break;
          default:
            GlobalEventInfo = 1;
            ptr_F8B1E8 = 0;
            EventProcessor(v4, 0, 1);
            GlobalEventInfo = 0;
            break;
        }
      }
      else
      {
        dword_F8B1D8 = newDialogueType;
        DrawJoinGuildWindow(v4 - 400);
      }
    }
    else
    {
      sub_4B3FE5(v4);
    }
  }
LABEL_87:
  if ( !dword_7241C8 )
    pGame->Draw();
LABEL_89:
  dword_7241C8 = 0;
}



//----- (004BDAAF) --------------------------------------------------------
bool __fastcall sub_4BDAAF(ItemGen *a1, int _2da_idx)
{
  int v2; // edx@1
  unsigned int v3; // esi@1
  unsigned int v4; // eax@1
  signed int v5; // edi@1
  int v6; // edx@8
  int v7; // edx@9
  int v8; // edx@10
  unsigned __int8 v9; // zf@16
  char v10; // sf@16
  unsigned __int8 v11; // of@16

  auto a2 = _2da_idx;
  //v2 = p2DEvents_minus1___00[26 * a2];
  v2 = p2DEvents[a2 - 1].uType;
  v3 = a1->uItemID;
  v4 = a1->uItemID;
  v5 = pItemsTable->pItems[v4].uEquipType;
  if ( (v2 != 4 || (signed int)v3 < 740 || (signed int)v3 > 771)
    && ((signed int)v3 >= 600 || (signed int)v3 >= 529 && (signed int)v3 <= 599) || a1->Stolen())
    return 0;
  v6 = v2 - 1;
  if ( !v6 )
  {
    v11 = __OFSUB__(v5, 2);
    v9 = v5 == 2;
    v10 = v5 - 2 < 0;
    goto LABEL_23;
  }
  v7 = v6 - 1;
  if ( v7 )
  {
    v8 = v7 - 1;
    if ( !v8 )
    {
      if ( pItemsTable->pItems[v4].uSkillType != 38 )
        return v5 == 16;
      return 1;
    }
    if ( v8 != 1 || v5 < 13 )
      return 0;
    if ( v5 <= 14 )
      return 1;
    if ( v5 != 17 || (signed int)v3 < 740 )
      return 0;
    v11 = __OFSUB__(v3, 771);
    v9 = v3 == 771;
    v10 = ((v3 - 771) & 0x80000000u) != 0;
LABEL_23:
    if ( !((unsigned __int8)(v10 ^ v11) | v9) )
      return 0;
    return 1;
  }
  if ( v5 >= 3 )
  {
    v11 = __OFSUB__(v5, 9);
    v9 = v5 == 9;
    v10 = v5 - 9 < 0;
    goto LABEL_23;
  }
  return 0;
}



//----- (004B5D7C) --------------------------------------------------------
int __cdecl GuildDialog()
{
  GUIWindow *v0; // ebx@1
  Player *v1; // edi@1
  signed int v2; // ebx@1
  int v3; // edi@6
  int result; // eax@11
  unsigned int v5; // ebx@13
  int v6; // esi@13
  signed int v7; // esi@17
  int v8; // esi@22
  signed int v9; // ecx@22
  char *v10; // eax@22
  const char *v11; // ecx@26
  POINT *v12; // esi@30
  int v13; // ecx@30
  void *v14; // ST1C_4@31
  ItemGen *v15; // ST18_4@31
  int v16; // ST10_4@31
  int v17; // eax@31
  char *v18; // edx@31
  int v19; // eax@32
  GUIWindow *v20; // edi@35
  int v21; // esi@35
  int v22; // eax@35
  unsigned int v23; // eax@36
  int v24; // eax@39
  int v25; // eax@40
  int v26; // ecx@47
  GUIButton *v27; // eax@49
  GUIButton *v28; // esi@49
  unsigned int v29; // eax@49
  char *v30; // eax@52
  int v31; // eax@55
  unsigned int v32; // ecx@55
  int v33; // eax@55
  unsigned __int16 v34; // ax@55
  int v35; // eax@58
  const char *v36; // ST20_4@61
  unsigned __int16 v37; // ST1C_2@61
  int v38; // eax@61
  GUIWindow *v39; // [sp-18h] [bp-304h]@31
  int v40; // [sp-14h] [bp-300h]@31
  int v41; // [sp-10h] [bp-2FCh]@31
  unsigned __int16 v42; // [sp-Ch] [bp-2F8h]@31
  char *v43; // [sp-8h] [bp-2F4h]@31
  unsigned int v44; // [sp-4h] [bp-2F0h]@31
  char Dest[100]; // [sp+Ch] [bp-2E0h]@3
  char v46[100]; // [sp+70h] [bp-27Ch]@3
  char v47[100]; // [sp+D4h] [bp-218h]@3
  char v48[100]; // [sp+138h] [bp-1B4h]@3
  char v49[100]; // [sp+19Ch] [bp-150h]@3
  POINT v50; // [sp+264h] [bp-88h]@30
  POINT v51; // [sp+26Ch] [bp-80h]@30
  GUIWindow v52; // [sp+274h] [bp-78h]@1
  signed int v53; // [sp+27Ch] [bp-70h]@1
  signed int v54; // [sp+284h] [bp-68h]@1
  int v55; // [sp+2C8h] [bp-24h]@47
  int v56; // [sp+2CCh] [bp-20h]@1
  int v57; // [sp+2D0h] [bp-1Ch]@1
  Player *v58; // [sp+2D4h] [bp-18h]@1
  unsigned __int8 uPlayerID; // [sp+2DBh] [bp-11h]@31
  char *Str; // [sp+2DCh] [bp-10h]@35
  int v61; // [sp+2E0h] [bp-Ch]@35
  unsigned int v62; // [sp+2E4h] [bp-8h]@13
  int v63; // [sp+2E8h] [bp-4h]@1

  v0 = window_SpeakInHouse;
  memcpy(&v52, window_SpeakInHouse, sizeof(v52));
  v58 = pPlayers[uActiveCharacter];
  v1 = v58;
  v52.uFrameX = 483;
  v53 = 148;
  v54 = 334;
  v56 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
  v57 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
  //v2 = (signed __int64)(p2DEvents_minus1__20[13 * (unsigned int)v0->ptr_1C] * 500.0);
  v2 = (signed __int64)(p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier * 500.0);
  v63 = v2 * (100 - v1->GetMerchant()) / 100;
  if ( v63 < v2 / 3 )
    v63 = v2 / 3;
  strcpy(Dest, "");
  strcpy(v46, "");
  strcpy(v47, "");
  strcpy(v48, "");
  strcpy(v49, "");
  if ( dword_F8B19C != 1 )
  {
    if ( dword_F8B19C != 18 )
    {
      if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
      {
        v3 = (int)(&v1->uIntelligence + dword_F8B19C);
        if ( *(short *)v3 )
        {
          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[403], pClassNames[dword_F8B19C + 20]);
          ShowStatusBarString(pTmpBuf, 2u);
          pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
        }
        else
        {
          if ( pParty->uNumGold < v63 )
          {
            ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
            HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, 2);
          }
          else
          {
            Party::TakeGold(v63);
            *(short *)v3 = 1;
          }
        }
      }
      /*result = pMessageQueue_50CBD0->uNumMessages;
      if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
      {
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
        result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
        *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
        ++pMessageQueue_50CBD0->uNumMessages;
      }*/
      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
      return 1; // void function actually
    }
    pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
    v5 = 0;
    v6 = 0;
    v62 = 0;
    v63 = 32;
    do
    {
      if ( *(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 9 * (v6 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C)) )
      {
        pRenderer->DrawTextureTransparent(v63, 0x5Au, ItemsInShopTexture[v6]);
        ZBuffer_DoFill((int *)((char *)pRenderer->pActiveZBuffer + v62 + 230528), ItemsInShopTexture[v6], v6 + 1);
        v1 = v58;
      }
      v63 += 70;
      v62 += 280;
      ++v6;
    }
    while ( v63 < 452 );
    v62 = 1680;
    v7 = 6;
    v63 = 32;
    do
    {
      if ( *(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 9 * (v7 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C)) )
      {
        pRenderer->DrawTextureTransparent(v63, 0xFAu, ItemsInShopTexture[v7]);
        ZBuffer_DoFill((int *)((char *)pRenderer->pActiveZBuffer + v62 + 638448), ItemsInShopTexture[v7], v7 + 1);
        v1 = v58;
      }
      v63 += 70;
      v62 += 280;
      ++v7;
    }
    while ( v63 < 452 );
    result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
    if ( result )
    {
      v8 = 0;
      v9 = 12;
      v10 = (char *)(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 108 * (unsigned int)window_SpeakInHouse->ptr_1C);
      do
      {
        if ( *(int *)v10 )
          ++v8;
        v10 += 36;
        --v9;
      }
      while ( v9 );
      GetAsyncKeyState(17);
      v11 = pGlobalTXT_LocalizationStrings[195];
      if ( dword_F8B19C != 2 )
        v11 = pGlobalTXT_LocalizationStrings[196];
      DrawTextAtStatusBar(v11, 0);
      if ( !v8 )
		  {
        v52.DrawCurrentTime(
                      __PAIR__(
                        *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)window_SpeakInHouse->ptr_1C + 44472],
                        *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)window_SpeakInHouse->ptr_1C + 44468])
                    - pParty->uTimePlayed);
		return 0;
		  }
      v12 = pMouse->GetCursorPos(&v51);
      result = v12->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v50)->y];
      v13 = pRenderer->pActiveZBuffer[result] & 0xFFFF;
      if ( pRenderer->pActiveZBuffer[result] & 0xFFFF )
      {
        v14 = window_SpeakInHouse->ptr_1C;
        v15 = (ItemGen *)(&pParty->pPlayers[1].uExpressionTimeLength + 18 * (v13 + 12 * (int)v14));
        v16 = (int)window_SpeakInHouse->ptr_1C;
        uPlayerID = uActiveCharacter - 1;
        v17 = v1->_490EEE(
                (ItemGen *)&pParty->pPlayers[1].uExpressionTimeLength + v13 + 12 * (int)v14,
                3,
                v16,
                2);
        v18 = BuilDialogueString((char *)pMerchantsBuyPhrases[v17], uPlayerID, v15, (char *)v14, 2, 0);
        v44 = 3;
        v43 = v18;
        v42 = v56;
        v41 = 0;
        v40 = 0;
        v39 = &v52;
LABEL_32:
        v19 = pFontArrus->CalcTextHeight(v18, v39, v40, v41);
        return (int)v52.DrawTitleText(pFontArrus, v5, (174 - v19) / 2 + 138, v42, v43, v44);
      }
    }
    return result;
  }
  if ( !(unsigned __int16)_449B57_test_bit(
                            (unsigned __int8 *)v1->field_152,
                            word_4F0704[2 * (unsigned int)window_SpeakInHouse->ptr_1C]) )
  {
    v36 = pNPCTopics[121].pText;
    v37 = v57;
    v38 = pFontArrus->CalcTextHeight(pNPCTopics[121].pText, &v52, 0, 0);
    v52.DrawTitleText(pFontArrus, 0, (212 - v38) / 2 + 101, v37, v36, 3u);
    result = (int)pDialogueWindow;
    pDialogueWindow->pNumPresenceButton = 0;
    return result;
  }
  result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
  if ( !result )
    return result;
  v20 = pDialogueWindow;
  v5 = 0;
  v62 = 0;
  Str = 0;
  v21 = pDialogueWindow->pStartingPosActiveItem;
  v22 = v21 + pDialogueWindow->pNumPresenceButton;
  v61 = 0;
  if ( v21 >= v22 )
    goto LABEL_64;
  do
  {
    v23 = v20->GetControl(v21)->uControlParam;
    if ( v23 == 18 )
    {
      v25 = pFontArrus->CalcTextHeight(pGlobalTXT_LocalizationStrings[400], &v52, 0, 0);
      v62 += v25;
      ++v61;
    }
    else
    {
      __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 ( *(&byte_4ED94C[37 * v58->uClass] + v23) && !*(&v58->uIntelligence + v23) )
      {
        v24 = pFontArrus->CalcTextHeight(pClassNames[v23 + 20], &v52, 0, 0);
        v62 += v24;
        ++v61;
        ++Str;
      }
    }
    ++v21;
  }
  while ( v21 < v20->pNumPresenceButton + v20->pStartingPosActiveItem );
  if ( !v61 )
  {
LABEL_64:
    sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[544], v58->pName, pClassNames[v58->classType]);
    strcat(pTmpBuf, "\n \n");
    strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
    v18 = pTmpBuf;
    v44 = 3;
    v43 = pTmpBuf;
    v42 = v57;
    v41 = 0;
    v40 = 0;
    v39 = &v52;
    goto LABEL_32;
  }
  if ( Str )
  {
    sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v63);
    v52.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
  }
  v63 = (signed int)(149 - v62) / v61;
  if ( v63 > 32 )
    v63 = 32;
  result = v20->pStartingPosActiveItem;
  v26 = (signed int)(149 - v61 * v63 - v62) / 2 - v63 / 2 + 162;
  v62 = result;
  v55 = v26;
  if ( result < result + v20->pNumPresenceButton )
  {
    v61 = 2;
    while ( 1 )
    {
      v27 = v20->GetControl(v62);
      v28 = v27;
      v29 = v27->uControlParam;
      if ( v29 == 18 )
        break;

      __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 ( *(&byte_4ED94C[37 * v58->uClass] + v29) && !*(&v58->uIntelligence + v29) )
      {
        v30 = pClassNames[v29 + 20];
LABEL_55:
        Str = v30;
        v28->uY = v63 + v55;
        v31 = pFontArrus->CalcTextHeight(v30, &v52, 0, 0);
        v32 = v28->uY;
        v28->uHeight = v31;
        v33 = v32 + v31 - 1;
        v28->uW = v33;
        v55 = v33;
        v34 = v57;
        if ( pDialogueWindow->pCurrentPosActiveItem != v61 )
          v34 = v56;
        v52.DrawTitleText(pFontArrus, 0, v32, v34, Str, 3u);
        goto LABEL_58;
      }
      v28->uW = 0;
      v28->uHeight = 0;
      v28->uY = 0;
LABEL_58:
      v35 = v20->pStartingPosActiveItem;
      ++v62;
      result = v20->pNumPresenceButton + v35;
      ++v61;
      if ( (signed int)v62 >= result )
        return result;
    }
    v30 = pGlobalTXT_LocalizationStrings[400];
    goto LABEL_55;
  }
  return result;
}



//----- (004B705E) --------------------------------------------------------
int __cdecl TampleDialog()
{
  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) = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
  HIDWORD(v59) = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
  v1 = pPlayers[uActiveCharacter];
  //v2 = pPlayers[uActiveCharacter]->_4B807C(p2DEvents_minus1__20[13 * (unsigned int)v0->ptr_1C]);
  v2 = pPlayers[uActiveCharacter]->_4B807C(p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier);
  HIDWORD(v60) = v2;
  if ( dword_F8B19C != 1 )
  {
    if ( dword_F8B19C != 10 )
    {
      if ( dword_F8B19C != 11 )
      {
        result = dword_F8B19C - 96;
        if ( dword_F8B19C == 96 )
        {
          result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
          if ( result )
          {
            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)->uControlParam - 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, pGlobalTXT_LocalizationStrings[401], v64);
              v57.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 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->uControlParam - 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, pGlobalTXT_LocalizationStrings[544], v1->pName, pClassNames[v1->classType]);
              strcat(pTmpBuf, "\n \n");
              strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
              v22 = WORD2(v59);
              v23 = pFontArrus->CalcTextHeight(pTmpBuf, &v57, 0, 0);
              result = (int)v57.DrawTitleText(pFontArrus, 0, (174 - v23) / 2 + 138, v22, pTmpBuf, 3u);
            }
          }
        }
        return result;
      }
      //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;
        }
        v29 = uActiveCharacter;
        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(12, uActiveCharacter - 1, v30, 48, 0);
            v29 = uActiveCharacter;
          }
          if ( v26->uReputation <= -10 )
          {
            v31 = pParty->uDaysPlayed % 7 + 1;
            LOBYTE(v31) = v31 | 0x80;
            _42777D_CastSpell_UseWand_ShootArrow(50, v29 - 1, v31, 48, 0);
            v29 = uActiveCharacter;
            v26 = v66;
          }
          if ( v26->uReputation <= -15 )
          {
            v32 = pParty->uDaysPlayed % 7 + 1;
            LOBYTE(v32) = v32 | 0x80;
            _42777D_CastSpell_UseWand_ShootArrow(75, v29 - 1, v32, 48, 0);
            v29 = uActiveCharacter;
            v26 = v66;
          }
          if ( v26->uReputation <= -20 )
          {
            v33 = pParty->uDaysPlayed % 7 + 1;
            LOBYTE(v33) = v33 | 0x80;
            _42777D_CastSpell_UseWand_ShootArrow(86, v29 - 1, v33, 48, 0);
            v29 = uActiveCharacter;
            v26 = v66;
          }
          if ( v26->uReputation <= -25 )
          {
            v34 = pParty->uDaysPlayed % 7 + 1;
            LOBYTE(v34) = v34 | 0x80;
            _42777D_CastSpell_UseWand_ShootArrow(85, v29 - 1, v34, 48, 0);
            v29 = uActiveCharacter;
          }
        }
        ++byte_F8B1EF[v29];
        v1->PlaySound(SPEECH_83, 0);
        ShowStatusBarString(pGlobalTXT_LocalizationStrings[527], 2u);
        goto LABEL_46;
      }
      goto LABEL_55;
    }
    result = v1->_4B6FF9();
    if ( !result )
      return result;
    v25 = 0;
    if ( pParty->uNumGold < v2 )
    {
LABEL_55:
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
      HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, 2);
      goto LABEL_46;
    }
    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->field_1928);
        v38 = v1->field_1924;
        v1->uFace = v37;
        v1->uVoiceID = v38;
        ReloadPlayerPortraits(uActiveCharacter - 1, (char)v37);
      }
      goto LABEL_63;
    }
    v39 = v61;
    if ( (unsigned int)v61 | v35 )
    {
      LODWORD(v1->pConditions[17]) = v35;
    }
    else
    {
      if ( !v60 && !v58 && !v59 )
        goto LABEL_63;
      v1->field_1928 = v1->uFace;
      v1->field_1924 = v1->uVoiceID;
      v1->SetCondition(0x11u, 1);
      v1->uVoiceID = (v1->GetSexByVoice() != 0) + 23;
      v40 = (v1->GetSexByVoice() != 0) + 23;
      v1->uFace = v40;
      ReloadPlayerPortraits(uActiveCharacter - 1, (char)v40);
      LODWORD(v1->pConditions[17]) = LODWORD(pParty->uTimePlayed);
      v39 = (GUIWindow *)HIDWORD(pParty->uTimePlayed);
    }
    HIDWORD(v1->pConditions[17]) = (int)v39;
LABEL_63:
    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);
LABEL_46:
    /*result = pMessageQueue_50CBD0->uNumMessages;
    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
    {
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
      result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
      *(&pMessageQueue_50CBD0->uNumMessages + result) = v25;
      ++pMessageQueue_50CBD0->uNumMessages;
    }*/
    pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
    return result; // void func
  }
  v63 = 1;
  v41 = pDialogueWindow->GetControl(pDialogueWindow->pStartingPosActiveItem);
  strcpy(a1, "");
  v41->uHeight = 0;
  v41->uY = 0;
  if ( v1->_4B6FF9() )
  {
    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;
  result = v43->pStartingPosActiveItem;
  v47 = (174 - v64 * v46 - (signed int)v66) / 2 - v64 / 2 + 138;
  v65 = v42 + result;
  if ( v42 + result < result + 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;
      result = pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem;
    }
    while ( (signed int)v65 < result );
  }
  return result;
}



//----- (004B6478) --------------------------------------------------------
int __cdecl 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 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
  v31 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(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 ( dword_F8B19C != 1 )
  {
    if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
    {
      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]

      if (false
      //if ( !*(&byte_4ED94C[37 * v1->uClass / 3] + dword_F8B19C)
        || (v6 = (int)(&v1->uIntelligence + dword_F8B19C), *(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;
        }
        HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, v27);
      }
    }
    else
    {
      v5 = 0;
    }
    /*result = pMessageQueue_50CBD0->uNumMessages;
    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
    {
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
      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 result; // void func
  }
  if ( !(unsigned __int16)_449B57_test_bit(
                            (unsigned __int8 *)v1->field_152,
                            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);
    result = (int)pDialogueWindow;
    pDialogueWindow->pNumPresenceButton = 0;
    return result;
  }
  result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
  if ( !result )
    return result;
  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)->uControlParam - 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, pGlobalTXT_LocalizationStrings[544], v1->pName, pClassNames[v1->classType]);
    strcat(pTmpBuf, "\n \n");
    strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
    v22 = v31;
    v23 = pFontArrus->CalcTextHeight(pTmpBuf, &v28, 0, 0);
    return (int)v28.DrawTitleText(pFontArrus, 0, (174 - v23) / 2 + 138, v22, pTmpBuf, 3u);
  }
  sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v32);
  v28.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
  v32 = (149 - v33) / v34;
  if ( (149 - v33) / v34 > 32 )
    v32 = 32;
  result = v8->pStartingPosActiveItem;
  v35 = result;
  v34 = (149 - v34 * v32 - v33) / 2 - v32 / 2 + 162;
  if ( result < result + v8->pNumPresenceButton )
  {
    v33 = 2;
    do
    {
      v14 = v8->GetControl(v35);
      v15 = v14->uControlParam - 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;
      result = v29->pNumPresenceButton + v29->pStartingPosActiveItem;
    }
    while ( v35 < result );
  }
  return result;
}



//----- (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
  char *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
  Player *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
  char 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; // [sp+14h] [bp-27Ch]@37
  char v49; // [sp+78h] [bp-218h]@68
  char v50; // [sp+DCh] [bp-1B4h]@68
  char v51; // [sp+140h] [bp-150h]@68
  char Dest; // [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
  __int16 v57[2]; // [sp+268h] [bp-28h]@1
  Player *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 = v61;
  v53.uFrameX = 483;
  v53.uFrameWidth = 148;
  v53.uFrameZ = 334;
  *(int *)v57 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
  v56 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
  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 != 27) - 1) & 0xFFFFFFE7) + 50);
  //v4 = (signed __int64)((double)(signed int)v59 * p2DEvents_minus1__20[v3 / 4]);
  v4 = (signed __int64)((double)(signed int)v59 * p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier);
  s1 = v4 * (100 - v1->GetMerchant()) / 100;
  if ( (signed int)s1 < v4 / 3 )
    s1 = v4 / 3;
  if ( dword_F8B19C == 1 )
  {
    if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
    {
      v16 = pDialogueWindow;
      v58 = (Player *)-1;
      v62 = 0;
      v17 = LOBYTE(pFontArrus->uFontHeight) - 3;
      v59 = pDialogueWindow;
      v54 = v17;
      strcpy(&Dest, "");
      sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[405], s1);
      v18 = pFontArrus->CalcTextHeight(pTmpBuf2, &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 = &v48;
      while ( 1 )
      {
        v47[1] = (const char *)v60;
        v22 = window_SpeakInHouse->ptr_1C;
        v23 = (Player *)(unsigned __int8)*(&_4F0D38_TravelInfo[4 * (signed int)v22] + v62);
        v61 = (Player *)(unsigned __int8)*(&_4F0D38_TravelInfo[4 * (signed int)v22] + v62);
        v24 = v16->GetControl(v60);
        if ( v23 != v58
          && ((signed int)s1 >= 6 ? (v25 = 1) : (v25 = (unsigned __int8)*(&byte_4F09B1[32 * (int)v23]
                                                                        + pParty->uDaysPlayed % 7)),
              v25
           && ((v26 = 8 * (int)v23, !dword_4F09CC[v26])
            || (unsigned __int16)_449B57_test_bit(pParty->_award_bits, LOWORD(dword_4F09CC[v26])))) )
        {
          v58 = v61;
          v27 = (const char *)v56;
          if ( pDialogueWindow->pCurrentPosActiveItem != s1 )
            v27 = *(const char **)v57;
          v47[1] = v27;
          sprintf(a1, format_4E2DC8, v27);
          v66 = (unsigned __int8)byte_4F09B8[v26 * 4];
          if ( (signed int)window_SpeakInHouse->ptr_1C >= 63 )
          {
            if ( CheckHiredNPCSpeciality(8u) )
              v66 -= 2;
            if ( CheckHiredNPCSpeciality(9u) )
              v66 -= 3;
            v47[1] = (const char *)45;
          }
          else
          {
            v47[1] = (const char *)35;
          }
          if ( CheckHiredNPCSpeciality((unsigned int)v47[1]) )
            v66 -= 2;
          if ( CheckHiredNPCSpeciality(0x2Cu) )
            --v66;
          if ( v66 < 1 )
            v66 = 1;
          if ( v61 != (Player *)v2 )
          {
            memcpy(&v32, (char *)&pMapStats + 68 * (unsigned __int8)byte_4F09B0[v26 * 4], 0x44u);
            sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[404],
              v66,
              *(int *)&v32,
              v33,
              v34,
              v35,
              v36,
              v37,
              v38,
              v39,
              v40,
              v41,
              v42,
              v43,
              v44,
              v45,
              v46,
              *(_QWORD *)v47);
            strcat(a1, pTmpBuf);
            v28 = a1;
            a1 += 100;
            ++v62;
            ++s1;
            strcat(v28, "\n \n");
            v24->uY = v63;
            v29 = pFontArrus->CalcTextHeight(pTmpBuf, &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 >= v59->pNumPresenceButton + v59->pStartingPosActiveItem )
          break;
        v16 = v59;
      }
      if ( v63 != v55 )
      {
        v47[1] = &Dest;
        v47[0] = &v51;
        v46 = &v50;
        v45 = (unsigned int)&v49;
        v44 = &v48;
        v43 = pTmpBuf2;
        sprintf(pTmpBuf, "%s\n \n%s%s%s%s%s", pTmpBuf2, &v48, &v49, &v50, &v51, &Dest);
        v53.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
      }
      else
      {
LABEL_71:
        v47[1] = (const char *)3;
        v47[0] = pGlobalTXT_LocalizationStrings[561];
        v46 = *(char **)v57;
        v45 = (174 - pFontArrus->CalcTextHeight(pGlobalTXT_LocalizationStrings[561], &v53, 0, 0)) / 2 + 138;
        v53.DrawTitleText(pFontArrus, 0, v45, (unsigned __int16)v46, v47[0], (unsigned int)v47[1]);
        pAudioPlayer->StopChannels(-1, -1);
      }
    }
  }
  else
  {
    if ( dword_F8B19C > 104 && dword_F8B19C <= 108 )
    {
      if ( pParty->uNumGold < s1 )
      {
        ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
        HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, 3);
        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
          return;
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
        goto LABEL_33;*/
        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
      }
      Party::TakeGold(s1);
      v47[1] = (const char *)7;
      v5 = &byte_4F09B0[32 * (unsigned __int8)*(&byte_4F0CCF[4 * (unsigned int)window_SpeakInHouse->ptr_1C] + dword_F8B19C)];
      if ( v5[pParty->uDaysPlayed % 7 + 1] )
      {
        if ( _strcmpi(pCurrentMapName, pMapStats->pInfos[(unsigned __int8)*v5].pFilename) )
        {
          SaveGame(1, 0);
          strcpy(pCurrentMapName, pMapStats->pInfos[(unsigned __int8)*v5].pFilename);
          v8 = *((int *)v5 + 6);
          v9 = *((int *)v5 + 5);
          v10 = *((int *)v5 + 4);
          dword_6BE364_game_settings_1 |= 1u;
          _5B65B8_npcdata_hiword_house_or_other = 0;
          dword_5B65BC = 0;
          _5B65B4_npcdata_loword_house_or_other = v8;
          v11 = *((int *)v5 + 3);
          uGameState = 2;
          _5B65A8_npcdata_uflags_or_other = v11;
          _5B65AC_npcdata_fame_or_other = v10;
          _5B65B0_npcdata_rep_or_other = v9;
          dword_5B65C0 = v11 | v10 | v9 | v8;
        }
        else
        {
          v6 = *((int *)v5 + 3);
          pParty->sRotationX = 0;
          pParty->vPosition.x = v6;
          v7 = *((int *)v5 + 4);
          pIndoorCamera->sRotationY = 0;
          pParty->uFlags |= 2u;
          pParty->vPosition.y = v7;
          pParty->vPosition.z = *((int *)v5 + 5);
          pParty->uFallStartY = pParty->vPosition.z;
          pParty->sRotationY = *((int *)v5 + 6);
        }
        HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, 2);
        v12 = (unsigned __int8)v5[8];
        if ( (signed int)window_SpeakInHouse->ptr_1C >= 63 )
        {
          v63 = SPEECH_72;
          v13 = 2500;
          if ( CheckHiredNPCSpeciality(8u) )
            v12 -= 2;
          if ( CheckHiredNPCSpeciality(9u) )
            v12 -= 3;
          v47[1] = (const char *)45;
        }
        else
        {
          v63 = SPEECH_71;
          v13 = 1500;
          v47[1] = (const char *)35;
        }
        if ( CheckHiredNPCSpeciality((unsigned int)v47[1]) )
          v12 -= 2;
        if ( CheckHiredNPCSpeciality(0x2Cu) )
          --v12;
        if ( v12 < 1 )
          v12 = 1;
        RestAndHeal(1440 * v12);
        v61->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);
        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
        {
          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
LABEL_33:
          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
          ++pMessageQueue_50CBD0->uNumMessages;
          return;
        }*/
      }
      else
      {
        dword_F8B19C = 1;
        pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
      }
    }
  }
}





//----- (00405CFF) --------------------------------------------------------
void stru262_TurnBased::End(bool bPlaySound)
{
  stru262_TurnBased *v2; // edi@1
  int v3; // ebx@1
  int v4; // esi@1
  unsigned __int8 v5; // zf@1
  unsigned __int8 v6; // sf@1
  TurnBased_QueueElem *v7; // ecx@2
  unsigned __int16 *pAttributes; // ecx@7
  size_t v9; // edx@7
  unsigned __int16 v10; // ax@8
  TurnBased_QueueElem *v11; // ebx@12
  ObjectType objType; // eax@13
  int objID; // esi@13
  int v14; // [sp+Ch] [bp-4h]@11

  v2 = this;
  v3 = 0;
  v4 = 0;
  v5 = this->uActorQueueSize == 0;
  v6 = this->uActorQueueSize < 0;
  this->field_4 = 0;
  if ( !(v6 | v5) )
  {
    v7 = this->pQueue;
    do
    {
      if ( (v7->uPackedID & 7) == OBJECT_Actor )
        LOBYTE(pActors[v7->uPackedID >> 3].uAttributes) &= 0x7Fu;
      ++v4;
      ++v7;
    }
    while ( v4 < v2->uActorQueueSize );
  }
  if ( (signed int)uNumLayingItems > 0 )
  {
    pAttributes = &pLayingItems[0].uAttributes;
    v9 = uNumLayingItems;
    do
    {
      v10 = *pAttributes;
      if ( *pAttributes & 4 )
      {
        LOBYTE(v10) = v10 & 0xFB;
        *pAttributes = v10;
      }
      pAttributes += 56;
      --v9;
    }
    while ( v9 );
  }
  v14 = 0;
  if ( v2->uActorQueueSize > 0 )
  {
    v11 = v2->pQueue;
    do
    {
      objType = (ObjectType)(v11->uPackedID & 7);
      objID = v11->uPackedID >> 3;
      if ( objType == OBJECT_Player )
      {
        pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)v11->field_4 * 2.133333333333333);
      }
      else
      {
        if ( objType == OBJECT_Actor )
          pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)v11->field_4 * 2.133333333333333);
      }
      ++v14;
      ++v11;
    }
    while ( v14 < v2->uActorQueueSize );
    v3 = 0;
  }
  pAudioPlayer->StopChannels(-1, -1);
  if ( bPlaySound != v3 )
    pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|SOUND_EnteringAHouse), v3, v3, -1, v3, v3, v3, v3);
  pTurnEngine->field_18 &= 0xFFFFFFFDu;
  pEventTimer->StopGameTime();
  dword_50C994 = v3;
  dword_50C998_turnbased_icon_1A = v3;
}
// 50C994: using guessed type int dword_50C994;
// 50C998: using guessed type int dword_50C998_turnbased_icon_1A;

//----- (00405E14) --------------------------------------------------------
void stru262_TurnBased::_405E14()
{
  stru262_TurnBased *v1; // esi@1
  int v2; // ecx@1
  SpellBuff *v3; // edi@2
  Actor *v4; // ebx@3
  signed int v5; // edx@20
  AIDirection *v6; // esi@21
  int v7; // eax@21
  int v8; // eax@21
  int v9; // eax@22
  int v10; // eax@23
  int v11; // eax@37
  int v12; // eax@44
  AIDirection a3; // [sp+4h] [bp-68h]@21
  AIDirection v14; // [sp+20h] [bp-4Ch]@21
  AIDirection v15; // [sp+3Ch] [bp-30h]@21
  Actor *v16; // [sp+58h] [bp-14h]@2
  int v17; // [sp+5Ch] [bp-10h]@6
  stru262_TurnBased *v18; // [sp+60h] [bp-Ch]@1
  int v19; // [sp+64h] [bp-8h]@8
  unsigned int v20; // [sp+68h] [bp-4h]@1

  v1 = this;
  v2 = 0;
  v18 = v1;
  v20 = 0;
  if ( (signed int)uNumActors > 0 )
  {
    //v3 = pActors;//[0].pActorBuffs;
    v16 = pActors;//[0].pActorBuffs;
	v3 = v16->pActorBuffs;
    do
    {
      v4 = v16;
	  if ( SHIDWORD(v3[3].uExpireTime) < v2 || SHIDWORD(v3[3].uExpireTime) <= v2 && LODWORD(v3[3].uExpireTime) <= v2 )
        v17 = v2;
      else
        v17 = 1;
      v19 = v2;
      do
      {
        if ( v19 != 10 )
        {
          v3->_4585CA(pParty->uTimePlayed);
          v2 = 0;
        }
        ++v19;
        ++v3;
      }
      while ( v19 < 22 );
      if ( v17 != v2
        && SHIDWORD(v4->pActorBuffs[3].uExpireTime) <= v2
        && (SHIDWORD(v4->pActorBuffs[3].uExpireTime) < v2 || LODWORD(v4->pActorBuffs[3].uExpireTime) <= v2) )
        v4->uActorHeight = pMonsterList->pMonsters[v4->pMonsterInfo.uID - 1].uMonsterHeight;
      if ( !(v4->uAttributes & 0x80) )
      {
        if ( !v4->pActorBuffs[5].uExpireTime )
        {
          if ( !v4->pActorBuffs[6].uExpireTime )
          {
            v5 = v4->uCurrentActionLength;
            v4->uCurrentActionTime += pMiscTimer->uTimeElapsed;
            if ( (signed int)v4->uCurrentActionTime >= v5 )
            {
              v17 = ai_near_actors_targets_pid[v20];
              v6 = Actor::GetDirectionInfo(8 * v20 | OBJECT_Actor, v17, &a3, v2);
              v7 = v4->uAIState;
              memcpy(&v15, v6, sizeof(v15));
              v8 = v7 - 4;
              memcpy(&v14, &v15, sizeof(v14));
              if ( v8 )
              {
                v9 = v8 - 1;
                if ( v9 )
                {
                  v10 = v9 - 6;
                  if ( v10 )
                  {
                    if ( v10 != 8 )
                      Actor::AI_StandOrBored(v20, v17, 32, &v14);
                  }
                }
              }
              else
              {
                v4->uCurrentActionTime = 0;
                v4->uCurrentActionLength = 0;
                v4->uAIState = Dead;
                v4->UpdateAnimation();
              }
              v1 = v18;
              v2 = 0;
            }
          }
        }
      }
      ++v20;
	  v3 = v16[1].pActorBuffs;
      ++v16;
    }
    while ( (signed int)v20 < (signed int)uNumActors );
  }
  if ( v1->field_4 == 1 )
  {
    v12 = v1->field_8;
    if ( v12 == 64 )
    {
      v1->_406A63();
    }
    else
    {
      if ( v12 > v2 )
      {
        v1->_406B9F();
      }
      else
      {
        v1->_406AFE();
        v1->field_10 = 100;
      }
    }
    v1->field_8 -= pEventTimer->uTimeElapsed;
    return;
  }
  if ( v1->field_4 == 2 )
  {
    if ( !(v1->field_18 & 1) )
    {
      v11 = v1->field_10;
      if ( v11 == 100 )
      {
        v1->StartTurn();
LABEL_39:
        v1->_40652A();
        return;
      }
      if ( v11 > v2 || v1->pQueue[0].field_4 <= v2 )
      {
        v1->_4065B0();
        goto LABEL_39;
      }
    }
    v1->NextTurn();
    return;
  }
  if ( v1->field_4 == 3 )
  {
    if ( v1->uActionPointsLeft <= v2 || v1->field_18 & 8 )
    {
      v1->field_18 &= 0xFFFFFFF7u;
      v1->field_4 = 1;
      v1->field_8 = 64;
    }
    else
    {
      v1->_406FA8();
    }
  }
}




//----- (0043FDED) --------------------------------------------------------
void PrepareActorRenderList_BLV()
{
  RenderBillboard *v0; // esi@0
  unsigned __int16 v3; // ax@3
  unsigned int v4; // eax@5
  unsigned __int16 v5; // cx@5
  int v6; // esi@5
  unsigned int v7; // eax@7
  int v8; // eax@10
  SpriteFrame *v9; // eax@16
  SpriteFrame *v10; // ebx@18
  //int *v11; // eax@18
  int v12; // ecx@28
  //IndoorCameraD3D **v14; // eax@36
  double v15; // st7@36
  float v16; // eax@36
  //double v17; // ST30_8@36
  signed __int64 v18; // qtt@36
  int v19; // ST5C_4@36
  signed __int64 v20; // qtt@37
  int v21; // ST5C_4@37
  signed __int16 v22; // cx@39
  int v23; // ST50_4@40
  signed int v24; // ecx@40
  int v25; // edx@44
  __int16 v26; // ax@44
  //MonsterDesc *v27; // edx@44
  //int v28; // ecx@44
  unsigned __int8 v29; // zf@44
  unsigned __int8 v30; // sf@44
  unsigned int v31; // [sp-8h] [bp-5Ch]@15
  int v32; // [sp+1Ch] [bp-38h]@5
  int a3; // [sp+20h] [bp-34h]@5
  int a2; // [sp+24h] [bp-30h]@5
  int a1a; // [sp+28h] [bp-2Ch]@5
  __int16 a5; // [sp+2Ch] [bp-28h]@5
  int a5a; // [sp+2Ch] [bp-28h]@36
  int a5b; // [sp+2Ch] [bp-28h]@40
  __int16 v41; // [sp+3Ch] [bp-18h]@18
  int a6; // [sp+40h] [bp-14h]@34
  int v43; // [sp+44h] [bp-10h]@34
  int z; // [sp+48h] [bp-Ch]@32
  signed int y; // [sp+4Ch] [bp-8h]@32
  int x; // [sp+50h] [bp-4h]@32

  for (uint i = 0; i < uNumActors; ++i)
  {
    auto p = pActors + i;

    if (p->uAIState == Removed ||
        p->uAIState == Disabled)
      continue;

    a5 = p->uSectorID;
    a2 = p->vPosition.y;
    a1a = p->vPosition.x;
    a3 = p->vPosition.z;
    v4 = stru_5C6E00->Atan2(a1a - pBLVRenderParams->vPartyPos.x, a2 - pBLVRenderParams->vPartyPos.y);
    LOWORD(v0) = p->uYawAngle;
    v5 = p->uCurrentActionAnimation;
    v6 = ((signed int)((char *)v0 + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v4 + stru_5C6E00->uIntegerPi) >> 8) & 7;
    v32 = v6;
    if ( pParty->bTurnBasedModeOn )
    {
      if ( v5 == 1 )
      {
        v7 = pMiscTimer->uTotalGameTimeElapsed;
        goto LABEL_10;
      }
    }
    else
    {
      if ( v5 == 1 )
      {
        v7 = pBLVRenderParams->field_0_timer_;
LABEL_10:
        v8 = i * 32 + v7;
        goto LABEL_12;
      }
    }
    v8 = p->uCurrentActionTime;
LABEL_12:
    if (p->pActorBuffs[5].uExpireTime > 0i64 || p->pActorBuffs[6].uExpireTime > 0i64 )
      v8 = 0;
    v31 = p->pSpriteIDs[v5];
    if (p->uAIState == Resurrected)
      v9 = pSpriteFrameTable->GetFrameBy_x(v31, v8);
    else
      v9 = pSpriteFrameTable->GetFrame(v31, v8);
    v41 = 0;
    v10 = v9;
    //v11 = (int *)v9->uFlags;
    if (v9->uFlags & 2)
      v41 = 2;
    if (v9->uFlags & 0x40000)
      v41 |= 0x40u;
    if (v9->uFlags & 0x20000)
      LOBYTE(v41) = v41 | 0x80;
    v0 = (RenderBillboard *)(256 << v6);
    if ( (unsigned int)v0 & v9->uFlags)
      v41 |= 4u;
    if ( v10->uGlowRadius )
    {
      //LOBYTE(v11) = byte_4E94D3;
      pMobileLightsStack->AddLight(
        a1a,
        a2,
        a3,
        a5,
        v10->uGlowRadius,
        0xFFu,
        0xFFu,
        0xFFu,
        byte_4E94D3);
    }
    v12 = 0;
    if ( pBspRenderer->uNumVisibleNotEmptySectors <= 0 )
      continue;
    while (pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v12] != p->uSectorID)
    {
      ++v12;
      if ( v12 >= pBspRenderer->uNumVisibleNotEmptySectors )
        goto _continue;
    }
    if ( !pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible(a1a, a2, a3, &x, &y, &z, 1)
      || (v0 = (RenderBillboard *)abs(x), (signed int)v0 < abs(y)) )
      continue;
    pGame->pIndoorCameraD3D->Project(x, y, z, &v43, &a6);

    v0 = &pBillboardRenderList[uNumBillboardsToDraw];
    if (uNumBillboardsToDraw >= 500)
      break;
    ++uNumBillboardsToDraw;
    ++uNumSpritesDrawnThisFrame;
    p->uAttributes |= 8u;
    v29 = pRenderer->pRenderD3D == 0;
    v0->uHwSpriteID = v10->pHwSpriteIDs[v32];
    v0->uPalette = v10->uPaletteIndex;
    v0->uIndoorSectorID = a5;
    if ( v29 )
    {
      LODWORD(v20) = pBLVRenderParams->field_40 << 16;
      HIDWORD(v20) = pBLVRenderParams->field_40 >> 16;
      v21 = v20 / x;
      v0->_screenspace_x_scaler_packedfloat = (unsigned __int64)(v10->scale * v20 / x) >> 16;
      a5a = (unsigned __int64)(v10->scale * (signed __int64)v21) >> 16;
    }
    else
    {
      //v14 = &pGame->pIndoorCameraD3D;
      v0->fov_x = pGame->pIndoorCameraD3D->fov_x;
      v15 = pGame->pIndoorCameraD3D->fov_y;
      v16 = v0->fov_x;
      v0->fov_y = v15;
      //v17 = v16 + 6.7553994e15;
      LODWORD(v18) = 0;
      HIDWORD(v18) = floorf(v16 + 0.5f);
      v19 = v18 / x;
      v0->_screenspace_x_scaler_packedfloat = (unsigned __int64)(v10->scale * v18 / x) >> 16;
      a5a = (unsigned __int64)(v10->scale * (signed __int64)v19) >> 16;
    }
    v0->_screenspace_y_scaler_packedfloat = a5a;
    if ( (signed __int64)p->pActorBuffs[3].uExpireTime <= 0 )
    {
      if ( (signed __int64)p->pActorBuffs[10].uExpireTime > 0 )
      {
        a5b = (unsigned __int64)(pGame->pStru6Instance->_4A806F(p) * (signed __int64)v0->_screenspace_y_scaler_packedfloat) >> 16;
        goto LABEL_43;
      }
    }
    else
    {
      v22 = p->pActorBuffs[3].uPower;
      if ( v22 )
      {
        v23 = (unsigned __int64)(65536 / (unsigned __int16)v22 * (signed __int64)v0->_screenspace_x_scaler_packedfloat) >> 16;
        v24 = p->pActorBuffs[3].uPower;
        v0->_screenspace_x_scaler_packedfloat = v23;
        a5b = (unsigned __int64)(65536 / v24 * (signed __int64)v0->_screenspace_y_scaler_packedfloat) >> 16;
LABEL_43:
        v0->_screenspace_y_scaler_packedfloat = a5b;
        goto LABEL_44;
      }
    }
LABEL_44:
    HIWORD(v25) = HIWORD(x);
    v0->world_x = a1a;
    v0->world_y = a2;
    v0->world_z = a3;
    v0->uScreenSpaceX = v43;
    v0->uScreenSpaceY = a6;
    LOWORD(v25) = 0;
    LOBYTE(v26) = v41;

    //v0->sZValue = v25 + (8 * i | OBJECT_Actor);
    v0->actual_z = HIWORD(x);
    v0->object_pid = v8 * i | OBJECT_Actor;

    v29 = HIDWORD(p->pActorBuffs[5].uExpireTime) == 0;
    v30 = HIDWORD(p->pActorBuffs[5].uExpireTime) < 0;
    v0->field_1E = v41;
    v0->pSpriteFrame = v10;
    v0->uTintColor = pMonsterList->pMonsters[p->pMonsterInfo.uID - 1].uTintColor;
    if ( !v30 && (!(v30 | v29) || LODWORD(p->pActorBuffs[5].uExpireTime)) )
    {
      HIBYTE(v26) = HIBYTE(v41) | 1;
      v0->field_1E = v26;
    }
    
_continue:
    ;
  }
}





//----- (00444732) --------------------------------------------------------
char *GetEventHintString(unsigned int uEventID)
{
  signed int event_index; // edx@1
  int event_pos; // esi@4
  char *result; // eax@6
  unsigned int str_index; // eax@9
  int i; // esi@11
 _evt_raw*  test_evt;
 _evt_raw*  last_evt;

  event_index = 0;
  if ( uLevelEVT_NumEvents <= 0 )
    return NULL;
 
    //v2 = (char *)&pLevelEVT_Index[0].uEventOffsetInEVT;
    while ( 1 )
    {
      if ( pLevelEVT_Index[event_index].uEventID == uEventID )
      {
		test_evt=(_evt_raw*)&pLevelEVT[pLevelEVT_Index[event_index].uEventOffsetInEVT];
		last_evt=test_evt;
        event_pos = pLevelEVT_Index[event_index+1].uEventOffsetInEVT;
        if ( test_evt->_e_type == EVENT_MouseOver )
          break;
      }
      ++event_index;
      if ( event_index >= uLevelEVT_NumEvents )
       return NULL;
    }
	test_evt=(_evt_raw*)&pLevelEVT[event_pos];
    if ( test_evt->_e_type== EVENT_SpeakInHouse )
    {
      str_index = EVT_DWORD(test_evt->v5);
      result = (char *)p2DEvents[str_index - 1].pName;
    }
    else
    {
      for ( i = event_index+1; pLevelEVT_Index[i].uEventID  == uEventID; ++i )
      {
        event_pos = pLevelEVT_Index[i].uEventOffsetInEVT;
		test_evt=(_evt_raw*)&pLevelEVT[event_pos];
        if ( test_evt->_e_type == EVENT_SpeakInHouse )
        {
          str_index = EVT_DWORD(test_evt->v5);
          if ( str_index < 600 )
            return (char *)p2DEvents[str_index - 1].pName;
        }
      }
      result = &pLevelStr[pLevelStrOffsets[EVT_BYTE(last_evt->v5)]];
    }
 
  return result;
}




//----- (00444839) --------------------------------------------------------
unsigned int __fastcall sub_444839_move_map(unsigned int a1, int a2, int x, int y, int z, int directiony, int directionx, int a8, const char *pLocationName)
{
  unsigned int v9; // ebx@1
  int v10; // edi@1
  //signed int v11; // eax@1
  unsigned int v12; // eax@6
  const char *v13; // ST0C_4@6
  unsigned int v14; // eax@8
  const char *v15; // eax@14
  unsigned int v16; // eax@16
  unsigned int result; // eax@26
  const char *v18; // [sp-8h] [bp-40h]@9
  //const char *v19; // [sp-4h] [bp-3Ch]@2
  char *v20; // [sp-4h] [bp-3Ch]@9
  const char *v21; // [sp-4h] [bp-3Ch]@11
  char pContainer[40]; // [sp+Ch] [bp-2Ch]@1
  unsigned int v23; // [sp+34h] [bp-4h]@1

  v9 = a1;
  v10 = a2;
  v23 = IndoorLocation::GetLocationIndex(pLocationName);
  dword_59117C_teleportx = x;
  dword_591178_teleporty = y;
  dword_591174_teleportz = z;
  dword_591170_teleport_directiony = directiony;
  dword_59116C_teleport_directionx = directionx;
  dword_591168_teleport_speedz = a8;
  dword_591164_teleport_map_name = (char *)pLocationName;
  uCurrentHouse_Animation = v9;
  pEventTimer->Pause();
  pAudioPlayer->StopChannels(-1, -1);

  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);
  }
  /*v11 = const_2();
  sprintf(pContainer, "evt%02d", v11);
  if ( pParty->uAlignment )
  {
    if ( pParty->uAlignment != 2 )
      goto LABEL_6;
    v19 = "-c";
  }
  else
  {
    v19 = "-b";
  }
  strcat(pContainer, v19);*/

//LABEL_6:
  v12 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
  v13 = pHouse_ExitPictures[v10];
  pTexture_Dialogue_Background = &pIcons_LOD->pTextures[v12];
  pTexture_outside = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(v13, TEXTURE_16BIT_PALETTE)];
  if ( v9 )
  {
    if ( !v23 )
      //pVideoPlayer->_4BF28F(pAnimatedRooms[p2DEvents_minus1___02[26 * v9]].field_0, 1u);
      pVideoPlayer->_4BF28F(pAnimatedRooms[p2DEvents[v9 - 1].uAnimationID].field_0, 1u);
  }
  else
  {
    if ( !v23 )
    {
      v14 = pMapStats->GetMapInfo(pCurrentMapName);
      if ( v14 )
      {
        v20 = pMapStats->pInfos[v14].pName;
        v18 = pGlobalTXT_LocalizationStrings[410];
LABEL_10:
        sprintf(sHouseName, v18, v20);
        goto LABEL_20;
      }
      v21 = pGlobalTXT_LocalizationStrings[79];
      goto LABEL_19;
    }
  }
  v15 = pLocationName;
  if ( *pLocationName == 48 )
    v15 = pCurrentMapName;
  v16 = pMapStats->GetMapInfo(v15);
  if ( v16 )
  {
    v20 = pMapStats->pInfos[v16].pName;
    v18 = pGlobalTXT_LocalizationStrings[411];
    goto LABEL_10;
  }
  v21 = pGlobalTXT_LocalizationStrings[73];
LABEL_19:
  strcpy(sHouseName, v21);
LABEL_20:
  pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, (enum WindowType)26, 0, (int)sHouseName);
  //if ( BYTE1(pAnimatedRooms[p2DEvents_minus1___02[26 * v9]].field_C) )
  if ( BYTE1(pAnimatedRooms[p2DEvents[v9 - 1].uAnimationID].field_C) )
    HousePlaySomeSound(v9, 1);
  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor && uActiveCharacter && pParty->uFlags & 0x30 )
    pPlayers[uActiveCharacter]->PlaySound(SPEECH_47, 0);
  result = v23;
  if ( v23 )
    uCurrentHouse_Animation = v23;
  return result;
}

//----- (0044606A) --------------------------------------------------------
void PrepareHouse(HOUSE_TYPE 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 Dst[6]; // [sp+34h] [bp-2Ch]@1
  //unsigned int v15; // [sp+4Ch] [bp-14h]@1
  int uAnimationID; // [sp+50h] [bp-10h]@1
  //unsigned int *v17; // [sp+54h] [bp-Ch]@3
  //unsigned int v18; // [sp+58h] [bp-8h]@1
  //int v19; // [sp+5Ch] [bp-4h]@7

  //v15 = uHouseID;
  //v1 = 52 * uHouseID;
  //uAnimationID = p2DEvents_minus1___02[26 * uHouseID];
  uAnimationID = p2DEvents[house - 1].uAnimationID;
  //v18 = 52 * uHouseID;
  memset(Dst, 0, 0x18u);
  //uExitPic = *(__int16 *)((char *)p2DEvents_minus1_::2C + v1);
  //uExitPic = p2DEvents[uHouseID - 1].uExitPicID;
  uNumDialogueNPCPortraits = 0;
  uHouse_ExitPic = p2DEvents[house - 1].uExitPicID;
  if ( uHouse_ExitPic )
  {
    //uExitMapID = *(__int16 *)((char *)p2DEvents_minus1_::30 + v1);
    uExitMapID = p2DEvents[house - 1]._quest_related;
    if ( uExitMapID > 0 )
    {
      //v17 = (unsigned int *)(uExitMapID - 1);
      if ( !((unsigned __int8)(0x80u >> (uExitMapID - 1) % 8) & pParty->_award_bits[(uExitMapID - 1) >> 3]) )
      {
        //uExitPic = 0;
        uHouse_ExitPic = 0;
      }
    }
  }

  dword_591080 = pAnimatedRooms[uAnimationID].field_8;
  //result = dword_591080;

  //v2 = 0;
  uNumDialogueNPCPortraits = 0;
  if ( dword_591080 )
  {
    //v2 = 1;
    Dst[0] = dword_591080;
    uNumDialogueNPCPortraits = 1;
  }

  //v19 = 1;
  for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
  {
    auto npc = pNPCStats->pNewNPCData + i;
    //v6 = &pNPCStats->pNewNPCData[1].uFlags;
    //v17 = &pNPCStats->pNewNPCData[1].uFlags;
    //do
    //{
    if (npc->Location2D == house )
    {
      if (~npc->uFlags & 0x80)
        //if ( !(*(char *)v6 & 0x80) )
      {
        v7 = uNumDialogueNPCPortraits++ - dword_591080 ? 1 : 0;
        HouseNPCData[v7] = npc;
        //v6 = v17;
        //*(&v13 + v2) = *(v17 - 1);
        Dst[uNumDialogueNPCPortraits - 1] = npc->uPortraitID;
          //v1 = v18;
        if ((npc->uFlags & 3) != 2)
          ++npc->uFlags;
      }
    }
      //++v19;
      //v6 += 19;
      //v17 = v6;
    //}
    //while ( v19 < (signed int)pNPCStats->uNumNewNPCs );
  }
  //uNumDialogueNPCPortraits = v2;

  //v19 = 0;
  for (uint i = 0; i < uNumDialogueNPCPortraits; ++i)
  //if ( v2 > 0 )
  {
    //do
    //{
      //v8 = v19;
    char icon_name[128];
    sprintfex(icon_name, "npc%03u", Dst[i]);
    //v9 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
    //++v19;
    pDialogueNPCPortraits[i] = pIcons_LOD->LoadTexturePtr(icon_name, TEXTURE_16BIT_PALETTE);
    //result = v19;
    //}
    //while ( v19 < uNumDialogueNPCPortraits );
    //uExitPic = uHouse_ExitPic;
  }

  if (uHouse_ExitPic)
  {
    //v10 = pIcons_LOD->LoadTexture(pHouse_ExitPictures[uHouse_ExitPic], TEXTURE_16BIT_PALETTE);
    //v11 = uNumDialogueNPCPortraits++;
    pDialogueNPCPortraits[uNumDialogueNPCPortraits++] = pIcons_LOD->LoadTexturePtr(pHouse_ExitPictures[uHouse_ExitPic], TEXTURE_16BIT_PALETTE);
    //result = *(__int16 *)((char *)p2DEvents_minus1_::2E + v1);
    //result = p2DEvents[house - 1].uExitMapID;
    uHouse_ExitPic = p2DEvents[house - 1].uExitMapID;
  }
  //return result;
}



//----- (0044622E) --------------------------------------------------------
bool __fastcall EnterHouse(HOUSE_TYPE uHouseID)
{
  //enum HOUSE_TYPE v1; // edi@1
  //int v2; // edi@5
  unsigned int uOpenTime; // eax@5
  int uCloseTime; // esi@5
  unsigned int v5; // esi@5
  int v6; // edx@5
  signed int v7; // ecx@10
  signed int v8; // 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_TYPE v25; // [sp+38h] [bp-4h]@1

  //v1 = uHouseID;
  //v25 = uHouseID;
  GameUI_StatusBar_TimedString[0] = 0;
  pStatusBarString[0] = 0;
  ShowStatusBarString("", 2u);
  if ( pMessageQueue_50CBD0->uNumMessages )
    pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
  viewparams->bRedrawGameUI = 1;
  uDialogueType = 0;
  pKeyActionMap->_459ED1(3);
  pKeyActionMap->ResetKeys();
  if (uHouseID == HOUSE_600 || uHouseID == HOUSE_601)
  {
    GameOverMenu(0);
    return 0;
  }
  //v2 = 26 * v1;
  //uOpenTime = p2DEvents_minus1_::uOpenTime[v2];
  uOpenTime = p2DEvents[uHouseID - 1].uOpenTime;
  //uCloseTime = p2DEvents_minus1_::uCloseTime[v2];
  uCloseTime = p2DEvents[uHouseID - 1].uCloseTime;
  ptr_F8B1E8 = 0;
  v24 = uOpenTime;
  v5 = uCloseTime - 1;
  dword_F8B1E4 = 0;
  dword_F8B1F4 = 0;
  memset(byte_F8B1F0, 0, 4u);
  memset(byte_F8B148, 0, 0x10u);
  pRenderer->ClearZBuffer(0, 479);
  v6 = v24;
  if ( (signed int)v5 <= (signed int)v24 )
  {
    if ( pParty->uCurrentHour >= v24 )
      goto LABEL_16;
  }
  else
  {
    if ( pParty->uCurrentHour < v24 )
    {
LABEL_10:
      v7 = 0;
      v8 = 0;
      v9 = v5 + 1;
      if ( (signed int)v24 > 12 )
      {
        v6 = v24 - 12;
        v7 = 1;
      }
      if ( v9 > 12 )
      {
        v9 -= 12;
        v8 = 1;
      }
      sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[414], v6, aAMPMNames[v7], v9, aAMPMNames[v8]);
      ShowStatusBarString(pTmpBuf, 2u);
      if ( uActiveCharacter )
        pPlayers[uActiveCharacter]->PlaySound(SPEECH_3, 0);
      return 0;
    }
  }
  if ( pParty->uCurrentHour > v5 )
    goto LABEL_10;
LABEL_16:
  //v10 = uHouseID;
  if ( (signed int)uHouseID >= 53 )
    goto LABEL_21;
  v11 = pParty->field_3C._shop_ban_times[2 * uHouseID + 1];
  if ( !(v11 | pParty->field_3C._shop_ban_times[2 * uHouseID])
    || (signed __int64)__PAIR__(v11, pParty->field_3C._shop_ban_times[2 * uHouseID]) <= (signed __int64)pParty->uTimePlayed )
  {
    pParty->field_3C._shop_ban_times[2 * uHouseID] = 0;
    pParty->field_3C._shop_ban_times[2 * uHouseID + 1] = 0;
LABEL_21:
    if ( !start_event_seq_number )
      pAudioPlayer->StopChannels(-1, -1);
    //uCurrentHouse_Animation = p2DEvents_minus1___02[v2];
    uCurrentHouse_Animation = p2DEvents[uHouseID - 1].uAnimationID;
    dword_F8B198 = LOBYTE(pAnimatedRooms[uCurrentHouse_Animation].field_C);
    if ( dword_F8B198 == 20 && pParty->uFine )   // going 2 jail
    {
      uCurrentHouse_Animation = (signed __int16)p2DEvents[186].uAnimationID;
      //v25 = HOUSE_187;
      uHouseID = HOUSE_JAIL;
      v12 = LODWORD(pParty->uTimePlayed);
      LODWORD(pParty->uTimePlayed) += 0x7620000u;
      v14 = LOBYTE(pAnimatedRooms[(signed __int16)p2DEvents[HOUSE_186].uAnimationID].field_C);
      pParty->uTimePlayed = __PAIR__(HIDWORD(pParty->uTimePlayed), v12) + 0x7620000;
      dword_F8B198 = v14;
      //v13 = pParty->pPlayers;//[0].uNumDivineInterventionCastsThisDay;
      //do
      ++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);
		//v13->uTimeToRecovery = 0;
		//memset(&v13->uTimeToRecovery, 0, 4u);
        //++v13;
      }
      //while ( v13 <= &pParty->pPlayers[3] );
      /*v15 = pParty->pPlayers;
      do
      {
        ++v15;
      }
      while ( v15 <= &pParty->pPlayers[3] );*/
      //v10 = v25;
    }
    ++pIcons_LOD->uTexturePacksCount;
    if ( !pIcons_LOD->uNumPrevLoadedFiles )
      pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;

    /*v16 = const_2();
    sprintf(pContainer, "evt%02d", v16);
    if ( pParty->uAlignment )
    {
      if ( pParty->uAlignment != 2 )
        goto LABEL_37;
      v22 = "-c";
    }
    else
    {
      v22 = "-b";
    }
    strcat(pContainer, v22);*/
//LABEL_37:
    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_507B04 = uTextureID_right_panel;
    PrepareHouse(uHouseID);
    v18 = 1;
    uTextureID_507B04 = uTextureID_right_panel;
    if ( uNumDialogueNPCPortraits == 1 )
      pDialogueNPCCount = 1;
    pVideoPlayer->_4BF28F(pAnimatedRooms[uCurrentHouse_Animation].field_0, 1u);
    if ( (signed int)uHouseID < 139 || (signed int)uHouseID > 172 )
    {
      if ( (signed int)uHouseID >= 54 && (signed int)uHouseID <= 73 && !sub_4B68EA(uHouseID - 54) )
        goto LABEL_49;
      //v20 = uHouseID;
    }
    else
    {
      v19 = word_4F0704[2 * uHouseID] - 1;
      //v20 = uHouseID;
      if ( !((unsigned __int8)(0x80u >> v19 % 8) & pPlayers[uActiveCharacter]->field_152[v19 >> 3]) )
      {
        HousePlaySomeSound(uHouseID, 3);
        v18 = 1;
LABEL_49:
        dword_5C35D4 = v18;
        return v18;
      }
      v18 = 1;
    }
    HousePlaySomeSound(uHouseID, v18);
    goto LABEL_49;
  }
  ShowStatusBarString(pGlobalTXT_LocalizationStrings[191], 2u);// "You've been banned from this shop!"
  return 0;
}