view Vis.cpp @ 127:9eac46182d8f

Слияние
author Ritor1
date Sun, 04 Nov 2012 09:37:39 +0600
parents 8b0c4d626477
children 918dca162239
line wrap: on
line source

#include "Vis.h"
#include "Outdoor.h"
#include "Game.h"
#include "Actor.h"
#include "IndoorCamera.h"
#include "Viewport.h"
#include "stru157.h"

#include "mm7_data.h"
//#include "MM7.h"


static Vis_stru1 Vis_static_sub_4C1944_stru_F8BDE8;



//----- (004C1026) --------------------------------------------------------
Vis_stru1_stru0 *Vis::_4C1026(BLVFace *a2, unsigned int a3, float a4)
{
  char *v4; // eax@4
  signed int v5; // ecx@4
  BLVFace *v6; // ecx@7
  unsigned int v7; // edi@7
  Vec3_short_ *v8; // eax@9
  char *v9; // edx@9
  signed int v10; // esi@10
  Vec3_int_ **v11; // edx@13
  char *v12; // eax@13
  double v13; // st7@14
  signed int v14; // ebx@14
  Vis *v15; // ebx@15
  Vis_stru1_stru0 *result; // eax@21
  Vis_stru1_stru0 *v17; // ecx@24
  RenderVertexSoft pRay[2]; // [sp+20h] [bp-70h]@17
  int v20; // [sp+84h] [bp-Ch]@10
  int v21; // [sp+88h] [bp-8h]@16
  int v22; // [sp+8Ch] [bp-4h]@16
  signed int v23; // [sp+98h] [bp+8h]@7

  auto ecx0 = this;

  static Vis_stru1 static_sub_4C1026_stru_F8FE00;
  static_sub_4C1026_stru_F8FE00.uNumPointers = 0;

  static bool _init_flag = false;
  static RenderVertexSoft static_sub_4C1026_array_F8F200[64];
  if (!_init_flag)
  {
    _init_flag = true;
    for (uint i = 0; i < 64; ++i)
      static_sub_4C1026_array_F8F200[i].flt_2C = 0.0f;
  }

  v6 = a2;
  v23 = 0;
  v7 = v6->uNumVertices;
  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
  {
    if ( (signed int)v7 > 0 )
    {
      v8 = pIndoor->pVertices;
      v9 = (char *)&static_sub_4C1026_array_F8F200[0].vWorldPosition.y;
      do
      {
        v10 = v23++;
        v20 = v8[v6->pVertexIDs[v10]].x;
        *((float *)v9 - 1) = (double)v20;
        v20 = v8[v6->pVertexIDs[v10]].y;
        *(float *)v9 = (double)v20;
        v9 += 48;
        v20 = v8[v6->pVertexIDs[v10]].z;
        *((float *)v9 - 11) = (double)v20;
      }
      while ( v23 < (signed int)v7 );
    }
  }
  else
  {
    if ( (signed int)v7 > 0 )
    {
      v11 = &pOutdoor->pBModels[a3 >> 9].pVertices.pVertices;
      v12 = (char *)&static_sub_4C1026_array_F8F200[0].vWorldPosition.y;
      do
      {
        *((float *)v12 - 1) = (double)(*v11)[v6->pVertexIDs[v23]].x;
        v13 = (double)(*v11)[v6->pVertexIDs[v23]].y;
        v14 = v23++;
        *(float *)v12 = v13;
        v12 += 48;
        *((float *)v12 - 11) = (double)(*v11)[v6->pVertexIDs[v14]].z;
      }
      while ( v23 < (signed int)v7 );
    }
  }
  pGame->pIndoorCameraD3D->ViewTransform(static_sub_4C1026_array_F8F200, v7);
  pGame->pIndoorCameraD3D->Project(static_sub_4C1026_array_F8F200, v7, 1);
  v15 = this;
  SortVectors_x(static_sub_4C1026_array_F8F200, 0, v7 - 1);
  if ( static_sub_4C1026_array_F8F200[0].vWorldViewPosition.x > (double)a4
    || (_4C1495(static_sub_4C1026_array_F8F200, v7, (float *)&v21, (float *)&v22),
        _4C12C3_FindSomeBillboard(static_sub_4C1026_array_F8F200, v7, *(float *)&v21, *(float *)&v22))
    || ((CastPickRay(pRay, *(float *)&v21, *(float *)&v22, a4), uCurrentlyLoadedLevelType != LEVEL_Indoor) ? PickOutdoor(a4, pRay, &static_sub_4C1026_stru_F8FE00, &a5, 1) : PickIndoor(a4, pRay, &static_sub_4C1026_stru_F8FE00, &a5),
        (static_sub_4C1026_stru_F8FE00.create_object_pointers(0),
         sort_object_pointers(
           static_sub_4C1026_stru_F8FE00.array_1804,
           0,
           static_sub_4C1026_stru_F8FE00.uNumPointers - 1),
         !static_sub_4C1026_stru_F8FE00.uNumPointers)
     || (result = static_sub_4C1026_stru_F8FE00.sub_4C2551(2, a3)) == 0
     || (signed int)static_sub_4C1026_stru_F8FE00.uNumPointers > 1
     && ((signed int)static_sub_4C1026_stru_F8FE00.uNumPointers <= 0 ? (v17 = 0) : (v17 = static_sub_4C1026_stru_F8FE00.array_1804[0]),
         result != v17)) )
    result = 0;
  return result;
}
// F91E08: using guessed type char static_sub_4C1026_byte_F91E08__init_flags;

//----- (004C12C3) --------------------------------------------------------
char Vis::_4C12C3_FindSomeBillboard(RenderVertexSoft *a1, int a2, float a3, float a4)
{
  signed int v5; // esi@1
  char *v6; // edi@2
  double v7; // st7@9
  int v8; // edx@9
  char *v9; // ecx@10
  char result; // al@24
  Vis *thisa; // [sp+10h] [bp-8h]@1
  float thisb; // [sp+10h] [bp-8h]@9
  signed int v13; // [sp+14h] [bp-4h]@1
  float a3a; // [sp+28h] [bp+10h]@9
  float a4a; // [sp+2Ch] [bp+14h]@9

  v13 = -1;
  v5 = 0;
  thisa = this;
  if ( (signed int)pRenderer->uNumBillboardsToDraw <= 0 )
    goto LABEL_28;
  v6 = (char *)&pRenderer->pBillboardRenderListD3D[0].uParentBillboardID;
  do
  {
    if ( IsPointInsideD3DBillboard((RenderBillboardD3D *)(v6 - 152), a3, a4)
      && (v13 == -1
       || (unsigned int)pBillboardRenderList[*(int *)v6].sZValue < pBillboardRenderList[pRenderer->pBillboardRenderListD3D[v13].uParentBillboardID].sZValue) )
      v13 = v5;
    ++v5;
    v6 += 156;
  }
  while ( v5 < (signed int)pRenderer->uNumBillboardsToDraw );
  if ( v13 == -1 )
    goto LABEL_28;
  v7 = 3.4028235e38;
  v8 = a2;
  a4a = 3.4028235e38;
  a3a = -3.4028235e38;
  thisb = -3.4028235e38;
  if ( a2 > 0 )
  {
    v9 = (char *)&a1->vWorldViewProjY;
    do
    {
      if ( *((float *)v9 - 1) < v7 )
        v7 = *((float *)v9 - 1);
      if ( *((float *)v9 - 1) > (double)a3a )
        a3a = *((float *)v9 - 1);
      if ( *(float *)v9 < (double)a4a )
        a4a = *(float *)v9;
      if ( *(float *)v9 > (double)thisb )
        thisb = *(float *)v9;
      v9 += 48;
      --v8;
    }
    while ( v8 );
  }
  if ( v7 < pRenderer->pBillboardRenderListD3D[v13].pQuards[0].pos.x
    || pRenderer->pBillboardRenderListD3D[v13].pQuards[0].pos.y > (double)a4a
    || pRenderer->pBillboardRenderListD3D[v13].pQuards[3].pos.x < (double)a3a
    || pRenderer->pBillboardRenderListD3D[v13].pQuards[1].pos.y < (double)thisb )
LABEL_28:
    result = 0;
  else
    result = 1;
  return result;
}

//----- (004C1417) --------------------------------------------------------
void Vis::GetPolygonCenter(RenderVertexD3D3 *pVertices, unsigned int uNumVertices, float *pCenterX, float *pCenterY)
{
  static RenderVertexD3D3 unk_F8EA00[64];

  memcpy(unk_F8EA00, pVertices, 32 * uNumVertices);

  SortVerticesByX(unk_F8EA00, 0, uNumVertices - 1);
  *pCenterX = (unk_F8EA00[uNumVertices - 1].pos.x - unk_F8EA00[0].pos.x) * 0.5 + unk_F8EA00[0].pos.x;

  SortVerticesByY(unk_F8EA00, 0, uNumVertices - 1);
  *pCenterY = (unk_F8EA00[uNumVertices - 1].pos.y - unk_F8EA00[0].pos.y) * 0.5 + unk_F8EA00[0].pos.y;
}

//----- (004C1495) --------------------------------------------------------
float *Vis::_4C1495(RenderVertexSoft *Src, int a2, float *a3, float *a4)
{
  char *v5; // eax@2
  signed int v6; // ecx@2
  float *result; // eax@5
  Vis *thisa; // [sp+0h] [bp-4h]@1

  thisa = this;

  static bool static_sub_4C1495_byte_F8E9F8__init_flags = false; // weak
  static RenderVertexSoft static_sub_4C1495_array_F8DDF8[64];
  if ( !static_sub_4C1495_byte_F8E9F8__init_flags )
  {
    static_sub_4C1495_byte_F8E9F8__init_flags = true;

    for (uint i = 0; i < 64; ++i)
      static_sub_4C1495_array_F8DDF8[i].flt_2C = 0.0f;
  }

  memcpy(static_sub_4C1495_array_F8DDF8, Src, 48 * a2);
  sort_objects_2(static_sub_4C1495_array_F8DDF8, 0, a2 - 1);
  *a3 = (*(float *)&Vis_static_sub_4C1944_stru_F8BDE8.array_1804[12 * a2 + 509]
       - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX)
      * 0.5
      + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX;
  sort_objects_3(static_sub_4C1495_array_F8DDF8, 0, a2 - 1);
  result = a4;
  *a4 = (*(float *)&Vis_static_sub_4C1944_stru_F8BDE8.array_1804[12 * a2 + 510]
       - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY)
      * 0.5
      + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY;
  return result;
}

//----- (004C1542) --------------------------------------------------------
void Vis::PickBillboards(float fPickDepth, float fX, float fY, Vis_stru1 *a4, stru157 *a2)
{
  int v6; // ST1C_4@6
  Vis_stru1_stru0 *v7; // edi@6
  Vis *thisa; // [sp+20h] [bp-Ch]@1
  void **v9; // [sp+24h] [bp-8h]@2
  unsigned int uD3DBillboardIdx; // [sp+28h] [bp-4h]@1

  uD3DBillboardIdx = 0;
  thisa = this;
  if ( (signed int)pRenderer->uNumBillboardsToDraw > 0 )
  {
    v9 = (void **)&pRenderer->pBillboardRenderListD3D[0].uParentBillboardID;
    do
    {
      if ( is_part_of_selection((BLVFace *)uD3DBillboardIdx, a2)
        && IsPointInsideD3DBillboard((RenderBillboardD3D *)(v9 - 38), fX, fY) )
      {
        if ( DoesRayIntersectBillboard(fPickDepth, uD3DBillboardIdx) )
        {
          v6 = pBillboardRenderList[(int)*v9].sZValue;
          v7 = &a4->array_0004[a4->uNumPointers];
          v7->pObjectInfo = *v9;
          v7 = (Vis_stru1_stru0 *)((char *)v7 + 4);
          v7->pObjectInfo = (void *)v6;
          v7->sZValue = 1;
          ++a4->uNumPointers;
        }
      }
      ++uD3DBillboardIdx;
      v9 += 39;
    }
    while ( (signed int)uD3DBillboardIdx < (signed int)pRenderer->uNumBillboardsToDraw );
  }
}

//----- (004C1607) --------------------------------------------------------
bool Vis::IsPointInsideD3DBillboard(RenderBillboardD3D *a1, float x, float y)
{
  RenderBillboardD3D *result; // eax@1
  double v5; // st7@2
  float v6; // ecx@2
  float v7; // ST00_4@3
  __int16 v8; // fps@6
  double v9; // st6@6
  char v10; // c0@6
  char v11; // c2@6
  char v12; // c3@6
  __int16 v13; // fps@7
  double v14; // st6@7
  unsigned __int8 v15; // c0@7
  char v16; // c2@7
  unsigned __int8 v17; // c3@7
  __int16 v18; // fps@8
  double v19; // st6@8
  char v20; // c0@8
  char v21; // c2@8
  char v22; // c3@8
  __int16 v23; // fps@9
  double v24; // st6@9
  unsigned __int8 v25; // c0@9
  char v26; // c2@9
  unsigned __int8 v27; // c3@9
  float v28; // [sp+4h] [bp-8h]@2
  float v29; // [sp+8h] [bp-4h]@2
  float a1a; // [sp+14h] [bp+8h]@2

  result = a1;
  if ( a1->uParentBillboardID == -1 )
    goto LABEL_14;
  v5 = a1->pQuards[0].pos.x;
  a1a = a1->pQuards[3].pos.x;
  v6 = result->pQuards[0].pos.y;
  result = (RenderBillboardD3D *)LODWORD(result->pQuards[1].pos.y);
  v29 = v6;
  LODWORD(v28) = (int)result;
  if ( v5 > a1a )
  {
    v7 = v5;
    HIWORD(result) = HIWORD(v7);
    v5 = a1a;
    a1a = v7;
  }
  if ( v6 > (double)v28 )
  {
    result = (RenderBillboardD3D *)LODWORD(v28);
    v28 = v6;
    LODWORD(v29) = (int)result;
  }
  v9 = x + 1.0;
  //UNDEF(v8);
  v10 = v9 < v5;
  v11 = 0;
  v12 = v9 == v5;
  BYTE1(result) = HIBYTE(v8);
  if ( v9 >= v5
    && (v14 = x - 1.0, /*UNDEF(v13),*/ v15 = v14 < a1a, v16 = 0, v17 = v14 == a1a, BYTE1(result) = HIBYTE(v13), v15 | v17)
    && (v19 = y + 1.0, /*UNDEF(v18),*/ v20 = v19 < v29, v21 = 0, v22 = v19 == v29, BYTE1(result) = HIBYTE(v18), v19 >= v29)
    && (v24 = y - 1.0, /*UNDEF(v23),*/ v25 = v24 < v28, v26 = 0, v27 = v24 == v28, BYTE1(result) = HIBYTE(v23), v25 | v27) )
    LOBYTE(result) = 1;
  else
LABEL_14:
    LOBYTE(result) = 0;
  return (bool)result;
}

//----- (004C16B4) --------------------------------------------------------
void Vis::PickIndoor(float fDepth, RenderVertexSoft *pRay, Vis_stru1 *a4, stru157 *a5)
{
  int v5; // eax@1
  signed int v6; // edi@2
  signed int v7; // esi@4
  int v8; // ecx@7
  int v9; // eax@7
  unsigned int *pNumPointers; // eax@7
  unsigned int v11; // ecx@7
  Vis_stru1_stru0 *v12; // edi@7
  RenderVertexSoft a1; // [sp+Ch] [bp-44h]@1
  BLVFace *v14; // [sp+3Ch] [bp-14h]@7
  void *v15; // [sp+40h] [bp-10h]@7
  int v16; // [sp+44h] [bp-Ch]@7
  int v17; // [sp+48h] [bp-8h]@1
  Vis *thisa; // [sp+4Ch] [bp-4h]@1

  v5 = 0;
  thisa = this;
  v17 = 0;
  for ( a1.flt_2C = 0.0; v17 < (signed int)pStru170->uNumFaceIDs; ++v17 )
  {
    v6 = pStru170->pFaceIDs[2 * v5];
    if ( v6 >= 0 )
    {
      if ( v6 < (signed int)pIndoor->uNumFaces )
      {
        v7 = v6;
        if ( is_part_of_selection(&pIndoor->pFaces[v6], a5) )
        {
          if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[v7]) )
          {
            if ( Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &a1, &pIndoor->pFaces[v7], 0xFFFFFFFFu) )
            {
              pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u);
              v9 = _48B561_mess_with_scaling_along_z(/*v8, */a1.vWorldViewPosition.x);
              LOWORD(v9) = 0;
              v15 = (void *)((8 * v6 | 6) + v9);
              pNumPointers = &a4->uNumPointers;
              v16 = 2;
              v11 = a4->uNumPointers;
              v14 = &pIndoor->pFaces[v7];
              v12 = &a4->array_0004[v11];
              v12->pObjectInfo = &pIndoor->pFaces[v7];
              v12 = (Vis_stru1_stru0 *)((char *)v12 + 4);
              v12->pObjectInfo = v15;
              v12->sZValue = v16;
              ++*pNumPointers;
            }
          }
        }
      }
    }
    v5 = v17 + 1;
  }
}

//----- (004C17CF) --------------------------------------------------------
void Vis::PickOutdoor(float fDepth, RenderVertexSoft *pRay, Vis_stru1 *a4, stru157 *a5, char a6)
{
  int v6; // esi@1
  unsigned int v7; // ecx@1
  BSPModel *v8; // ebx@3
  bool v9; // eax@3
  int v10; // eax@8
  ODMFace *v11; // esi@10
  int v12; // ecx@12
  int v13; // eax@12
  unsigned int *pNumPointers; // eax@12
  Vis_stru1_stru0 *v15; // edi@12
  BLVFace thisa; // [sp+10h] [bp-B8h]@1
  RenderVertexSoft a1; // [sp+70h] [bp-58h]@1
  void *v18; // [sp+A0h] [bp-28h]@12
  void *v19; // [sp+A4h] [bp-24h]@12
  int v20; // [sp+A8h] [bp-20h]@12
  int v21; // [sp+ACh] [bp-1Ch]@8
  Vis *v22; // [sp+B0h] [bp-18h]@1
  int v23; // [sp+B4h] [bp-14h]@9
  int v24; // [sp+B8h] [bp-10h]@1
  unsigned int v25; // [sp+BCh] [bp-Ch]@2
  unsigned int v26; // [sp+C0h] [bp-8h]@1
  int v27; // [sp+C4h] [bp-4h]@8

  v22 = this;
  v6 = 0;
  v7 = 0;
  v24 = 0;
  v26 = 0;
  a1.flt_2C = 0.0;
  if (!pOutdoor)
    return;
  if ( (signed int)pOutdoor->uNumBModels > 0 )
  {
    v25 = 0;
    do
    {
      v8 = &pOutdoor->pBModels[v25 / 0xBC];
      v9 = IsBModelVisible(v7, &v24);
      if ( a6 )
      {
        if ( v9 && v24 != v6 )
        {
LABEL_8:
          v10 = v8->uNumFaces;
          v27 = v6;
          v21 = v10;
          if ( v10 > v6 )
          {
            v23 = v6;
            do
            {
              v11 = (ODMFace *)((char *)v8->pFaces + v23);
              if ( is_part_of_selection((BLVFace *)((char *)v8->pFaces + v23), a5) )
              {
                thisa.FromODM(v11);
                if ( Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &a1, &thisa, v26) )
                {
                  pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u);
                  v18 = v11;
                  v13 = _48B561_mess_with_scaling_along_z(/*v12, */a1.vWorldViewPosition.x);
                  LOWORD(v13) = 0;
                  v20 = 2;
                  v19 = (void *)((8 * (v27 | (v26 << 6)) | 6) + v13);
                  pNumPointers = &a4->uNumPointers;
                  v15 = &a4->array_0004[a4->uNumPointers];
                  v15->pObjectInfo = v18;
                  v15 = (Vis_stru1_stru0 *)((char *)v15 + 4);
                  v15->pObjectInfo = v19;
                  v15->sZValue = v20;
                  ++*pNumPointers;
                }
              }
              ++v27;
              v23 += 308;
            }
            while ( v27 < v21 );
            v6 = 0;
          }
          goto LABEL_15;
        }
      }
      else
      {
        if ( v9 )
          goto LABEL_8;
      }
LABEL_15:
      v25 += 188;
      v7 = v26++ + 1;
    }
    while ( (signed int)v26 < (signed int)pOutdoor->uNumBModels );
  }
}

//----- (004C1930) --------------------------------------------------------
//bool Vis::j_DoesRayIntersectBillboard(float fDepth, unsigned int uD3DBillboardIdx)
//{return DoesRayIntersectBillboard(fDepth, uD3DBillboardIdx);}

//----- (004C1944) --------------------------------------------------------
int Vis::_4C1944(int a2, unsigned int a3, int a4, int a5, int a6)
{
  float v6; // ST00_4@3
  int result; // eax@4
  stru157 v8; // [sp+18h] [bp-20h]@3
  __int64 v9; // [sp+2Ch] [bp-Ch]@3
  Vis *v14; // [sp+34h] [bp-4h]@1

  v14 = this;

  static Vis_stru1 Vis_static_sub_4C1944_stru_F8BDE8;

  v8.field_4 = a2;
  v8.field_8 = a6;
  v8.field_C = a5;
  v8.field_10 = a4;
  v9 = a3;
  Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers = 0;
  v6 = (double)a3;
  v8.field_0 = 1;
  _4C06F8(v6, &Vis_static_sub_4C1944_stru_F8BDE8, &v8);
  Vis_static_sub_4C1944_stru_F8BDE8.create_object_pointers(1u);
  sort_object_pointers(
    Vis_static_sub_4C1944_stru_F8BDE8.array_1804,
    0,
    Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers - 1);
  if ( (signed int)Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers <= 0 )
    result = -1;
  else
    result = Vis_static_sub_4C1944_stru_F8BDE8.array_1804[0]->sZValue;
  return result;
}
// F8DDF0: using guessed type char Vis_static_sub_4C1944_byte_F8DDF0_init;

//----- (004C1A02) --------------------------------------------------------
void Vis::_4C1A02()
{
  RenderVertexSoft v1; // [sp+8h] [bp-C0h]@1
  RenderVertexSoft v2; // [sp+38h] [bp-90h]@1
  RenderVertexSoft v3; // [sp+68h] [bp-60h]@1
  RenderVertexSoft v4; // [sp+98h] [bp-30h]@1

  v4.flt_2C = 0.0;
  v4.vWorldPosition.x = 0.0;
  v4.vWorldPosition.y = 65536.0;
  v4.vWorldPosition.z = 0.0;
  v3.flt_2C = 0.0;
  v3.vWorldPosition.x = 65536.0;
  v3.vWorldPosition.y = 0.0;
  v3.vWorldPosition.z = 0.0;
  memcpy(&v1, &v3, sizeof(v1));
  v3.flt_2C = 0.0;
  v3.vWorldPosition.x = 0.0;
  v3.vWorldPosition.y = 65536.0;
  v3.vWorldPosition.z = 0.0;
  memcpy(&v2, &v4, sizeof(v2));
  v4.flt_2C = 0.0;
  v4.vWorldPosition.x = 65536.0;
  v4.vWorldPosition.y = 0.0;
  v4.vWorldPosition.z = 0.0;
  memcpy(&this->stru_200C, &v1, 0x60u);
  memcpy(&v1, &v4, sizeof(v1));
  memcpy(&v2, &v3, sizeof(v2));
  memcpy(&this->stru_206C, &v1, 0x60u);
}

//----- (004C1ABA) --------------------------------------------------------
bool Vis::SortVectors_x(RenderVertexSoft *a2, int a3, int a4)
{
  bool result; // eax@1
  RenderVertexSoft *v5; // edx@2
  int v6; // ebx@2
  int i; // ecx@2
  int v8; // esi@3
  int v9; // esi@5
  RenderVertexSoft *v10; // eax@8
  RenderVertexSoft v11; // [sp+4h] [bp-6Ch]@8
  RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2
  int v13; // [sp+64h] [bp-Ch]@7
  Vis *thisa; // [sp+68h] [bp-8h]@1
  RenderVertexSoft *v15; // [sp+6Ch] [bp-4h]@2

  result = a4;
  thisa = this;
  if ( a4 > a3 )
  {
    v5 = a2;
    v15 = &a2[a4];
    v6 = a3 - 1;
    memcpy(&v12, &a2[a4], sizeof(v12));
    for ( i = a4; ; i = v13 )
    {
      v8 = (int)&v5[v6].vWorldViewPosition;
      do
      {
        v8 += 48;
        ++v6;
      }
      while ( *(float *)v8 < (double)v12.vWorldViewPosition.x );
      v9 = (int)&v5[i].vWorldViewPosition;
      do
      {
        v9 -= 48;
        --i;
      }
      while ( *(float *)v9 > (double)v12.vWorldViewPosition.x );
      v13 = i;
      if ( v6 >= i )
        break;
      v10 = &v5[i];
      memcpy(&v11, &a2[v6], sizeof(v11));
      v5 = a2;
      memcpy(&a2[v6], v10, sizeof(a2[v6]));
      memcpy(v10, &v11, 0x30u);
    }
    memcpy(&v11, &v5[v6], sizeof(v11));
    memcpy(&v5[v6], v15, sizeof(v5[v6]));
    memcpy(v15, &v11, 0x30u);
    SortVectors_x(v5, a3, v6 - 1);
    SortVectors_x(a2, v6 + 1, a4);
  }
  return true;
}

//----- (004C1BAA) --------------------------------------------------------
int Vis::get_object_zbuf_val(Vis_stru1_stru0 *a2)
{
  unsigned int v2; // eax@1
  int result; // eax@3
  std::string v4; // [sp-18h] [bp-1Ch]@4
  const char *v5; // [sp-8h] [bp-Ch]@4
  int v6; // [sp-4h] [bp-8h]@4
  Vis *v7; // [sp+0h] [bp-4h]@1

  v7 = this;
  v2 = a2->uObjectType;
  if ( (signed int)v2 <= 0 || (signed int)v2 > 2 )
  {
    MessageBoxW(nullptr, L"Undefined type requested for: CVis::get_object_zbuf_val()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1037", 0);
    result = -1;
  }
  else
  {
    result = a2->sZValue;
  }
  return result;
}

//----- (004C1BF1) --------------------------------------------------------
int Vis::get_picked_object_zbuf_val()
{
  int result; // eax@2

  if ( (signed int)this->stru1.uNumPointers <= 0 )
    result = -1;
  else
    result = get_object_zbuf_val(this->stru1.array_1804[0]);
  return result;
}

//----- (004C1C0C) --------------------------------------------------------
bool Vis::Intersect_Ray_Face(RenderVertexSoft *pRayStart, RenderVertexSoft *pRayEnd, float *pDepth, RenderVertexSoft *a4, BLVFace *a5, unsigned int a6)
{
  BLVFace *v7; // ebx@1
  bool result; // eax@1
  double v9; // st7@3
  __int16 v10; // fps@3
  char v11; // c0@3
  char v12; // c2@3
  char v13; // c3@3
  __int16 v14; // fps@5
  char v15; // c0@5
  char v16; // c2@5
  char v17; // c3@5
  double v18; // st5@6
  __int16 v19; // fps@6
  char v20; // c0@6
  char v21; // c2@6
  char v22; // c3@6
  unsigned __int8 v23; // c0@6
  char v24; // c2@6
  unsigned __int8 v25; // c3@6
  char v26; // zf@6
  double v27; // st6@10
  __int16 v28; // fps@10
  unsigned __int8 v29; // c0@10
  char v30; // c2@10
  unsigned __int8 v31; // c3@10
  double v32; // st7@11
  Vec2_short_ v33; // ST1E_4@11
  Vec3_short_ v34; // ST04_6@11
  float a5a; // [sp+30h] [bp+18h]@10
  float a5b; // [sp+30h] [bp+18h]@13

  v7 = a5;
  result = a5->uAttributes;
  if ( result & 1
    || BYTE1(result) & 0x20
    || (v9 = pRayEnd->vWorldPosition.z * a5->pFacePlane.vNormal.z
           + a5->pFacePlane.vNormal.y * pRayEnd->vWorldPosition.y
           + pRayEnd->vWorldPosition.x * a5->pFacePlane.vNormal.x,
        //UNDEF(v10),
        v11 = v9 < 0.0,
        v12 = 0,
        v13 = v9 == 0.0,
        BYTE1(result) = HIBYTE(v10),
        v9 == 0.0)
    || (/*UNDEF(v14),*/ v15 = v9 < 0.0, v16 = 0, v17 = v9 == 0.0, BYTE1(result) = HIBYTE(v14), v9 > 0.0) )// ray's away (>) from face surface or parallel (==)
    goto LABEL_12;
  v18 = -(a5->pFacePlane.vNormal.y * pRayStart->vWorldPosition.y// ray-plane intersection
        + pRayStart->vWorldPosition.x * a5->pFacePlane.vNormal.x
        + pRayStart->vWorldPosition.z * a5->pFacePlane.vNormal.z
        + a5->pFacePlane.dist);
  //UNDEF(v19);
  v20 = v9 < 0.0;
  v21 = 0;
  v22 = v9 == 0.0;
  BYTE1(result) = HIBYTE(v19);
  v23 = v18 < 0.0;
  v24 = 0;
  v25 = v18 == 0.0;
  v26 = (BYTE1(result) & 0x41) == 0;
  BYTE1(result) = HIBYTE(v19);
  if ( v26 )
  {
    if ( v18 < 0.0 )
      goto LABEL_12;
  }
  else
  {
    if ( !(v23 | v25) )
    {
LABEL_12:
      LOBYTE(result) = 0;
      return result;
    }
  }
  a5a = v18;
  v27 = a5a / v9;
  HIWORD(result) = HIWORD(pDepth);
  //UNDEF(v28);
  v29 = v27 < *pDepth;
  v30 = 0;
  v31 = v27 == *pDepth;
  BYTE1(result) = HIBYTE(v28);
  if ( !(v29 | v31)
    || (a4->vWorldPosition.x = v27 * pRayEnd->vWorldPosition.x + pRayStart->vWorldPosition.x,
        a4->vWorldPosition.y = v27 * pRayEnd->vWorldPosition.y + pRayStart->vWorldPosition.y,
        v32 = v27 * pRayEnd->vWorldPosition.z + pRayStart->vWorldPosition.z,
        a4->vWorldPosition.z = v32,
        v33.x = (signed __int64)a4->vWorldPosition.x,
        v33.y = (signed __int64)a4->vWorldPosition.y,
        *(int *)&v34.x = v33.x,
        v34.z = (signed __int64)v32,
        result = _4C1D2B(v7, v34, a6),
        *(float *)&result == 0.0) )
    goto LABEL_12;
  *(float *)&result = v27;
  a5b = v27;
  *(int *)pDepth = LODWORD(a5b);
  LOBYTE(result) = 1;
  return result;
}

//----- (004C1D2B) --------------------------------------------------------
int Vis::_4C1D2B(BLVFace *pFace, Vec3_short_ a2, unsigned int uModelID)
{
  BLVFace *v4; // esi@1
  int v5; // esi@10
  bool v6; // edi@10
  int v7; // ecx@12
  signed int v8; // edx@12
  signed int v9; // eax@13
  signed int v10; // ebx@14
  int v11; // edi@16
  signed int v12; // ST28_4@18
  signed __int64 v13; // qtt@18
  signed int result; // eax@21
  int v15; // [sp+10h] [bp-Ch]@10
  signed int v16; // [sp+18h] [bp-4h]@10

  v4 = pFace;
  if ( a2.z < pFace->pBounding.z1
    || a2.z > pFace->pBounding.z2
    || a2.x < pFace->pBounding.x1
    || a2.x > pFace->pBounding.x2
    || a2.y < pFace->pBounding.y1
    || a2.y > pFace->pBounding.y2
    || (uModelID != -1 ? _4C2186_BLV_IntersectBModel(
                           (int *)&pFace,
                           (int *)&uModelID,
                           &word_F8BC48_displaced_face_intersect_plane_coords_a,
                           &word_F8BD18_displaced_face_intersect_plane_coords_b,
                           &a2,
                           pFace,
                           uModelID) : _4C1EE5_BLV_IntersectBModel_2(
                                         (int *)&pFace,
                                         (int *)&uModelID,
                                         &word_F8BC48_displaced_face_intersect_plane_coords_a,
                                         &word_F8BD18_displaced_face_intersect_plane_coords_b,
                                         &a2,
                                         pFace),
        v5 = 2 * v4->uNumVertices,
        v16 = 0,
        *(&word_F8BC48_displaced_face_intersect_plane_coords_a + v5) = word_F8BC48_displaced_face_intersect_plane_coords_a,
        *(&word_F8BD18_displaced_face_intersect_plane_coords_b + v5) = word_F8BD18_displaced_face_intersect_plane_coords_b,
        v15 = 0,
        v6 = word_F8BD18_displaced_face_intersect_plane_coords_b >= (signed int)uModelID,
        v5 <= 0) )
    goto LABEL_25;
  do
  {
    if ( v16 >= 2 )
      break;
    v7 = 2 * v15;
    v8 = *(&word_F8BD18_displaced_face_intersect_plane_coords_b + v15 + 1);
    if ( v6 ^ v8 >= (signed int)uModelID )
    {
      v9 = *(__int16 *)((char *)&word_F8BC48_displaced_face_intersect_plane_coords_a + v7 + 2);
      if ( v9 >= (signed int)pFace )
        v10 = 0;
      else
        v10 = 2;
      v11 = v10 | *(__int16 *)((char *)&word_F8BC48_displaced_face_intersect_plane_coords_a + v7) < (signed int)pFace;
      if ( v11 != 3 )
      {
        if ( !v11
          || (v12 = v9 - *(__int16 *)((char *)&word_F8BC48_displaced_face_intersect_plane_coords_a + v7),
              LODWORD(v13) = v12 << 16,
              HIDWORD(v13) = v12 >> 16,
              *(__int16 *)((char *)&word_F8BC48_displaced_face_intersect_plane_coords_a + v7)
            + ((signed int)(((unsigned __int64)(v13
                                              / (v8
                                               - *(__int16 *)((char *)&word_F8BD18_displaced_face_intersect_plane_coords_b
                                                            + v7))
                                              * (signed int)((uModelID
                                                            - *(__int16 *)((char *)&word_F8BD18_displaced_face_intersect_plane_coords_b
                                                                         + v7)) << 16)) >> 16)
                          + 32768) >> 16) >= (signed int)pFace) )
          ++v16;
      }
    }
    ++v15;
    v6 = v8 >= (signed int)uModelID;
  }
  while ( v15 < v5 );
  result = 1;
  if ( v16 != 1 )
LABEL_25:
    result = 0;
  return result;
}

//----- (004C1EE5) --------------------------------------------------------
bool Vis::_4C1EE5_BLV_IntersectBModel_2(int *a1, int *a2, __int16 *a3, __int16 *a4, Vec3_short_ *a5, BLVFace *pFace)
{
  bool result; // eax@1
  unsigned int v8; // ecx@1
  Vec3_short_ *v9; // ecx@2
  __int16 *v10; // edx@3
  signed int v11; // ecx@4
  char v12; // zf@6
  Vec3_short_ *v13; // ecx@6
  int v14; // edx@7
  __int16 *v15; // edx@8
  signed int v16; // ecx@9
  int v17; // edx@11
  __int16 *v18; // edx@12
  signed int v19; // ecx@13
  signed int a5a; // [sp+24h] [bp+18h]@2
  signed int a5b; // [sp+24h] [bp+18h]@7
  signed int a5c; // [sp+24h] [bp+18h]@11

  result = (bool)pFace;
  v8 = pFace->uAttributes;
  if ( BYTE1(v8) & 1 )
  {
    v9 = a5;
    a5a = 0;
    *a1 = v9->x;
    *a2 = v9->y;
    if ( pFace->uNumVertices )
    {
      v10 = a4 + 1;
      do
      {
        v11 = a5a;
        a3[2 * a5a] = pFace->pXInterceptDisplacements[a5a] + pIndoor->pVertices[pFace->pVertexIDs[a5a]].x;
        *(v10 - 1) = pFace->pYInterceptDisplacements[v11] + pIndoor->pVertices[pFace->pVertexIDs[v11]].y;
        *(__int16 *)((char *)v10 + (int)a3 - (int)a4) = pFace->pXInterceptDisplacements[v11 + 1]
                                                            + pIndoor->pVertices[pFace->pVertexIDs[v11 + 1]].x;
        ++a5a;
        *v10 = pFace->pYInterceptDisplacements[v11 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v11 + 1]].y;
        v10 += 2;
      }
      while ( a5a < pFace->uNumVertices );
    }
  }
  else
  {
    v12 = (BYTE1(v8) & 2) == 0;
    v13 = a5;
    if ( v12 )
    {
      v17 = a5->y;
      a5c = 0;
      *a1 = v17;
      *a2 = v13->z;
      if ( pFace->uNumVertices )
      {
        v18 = a4 + 1;
        do
        {
          v19 = a5c;
          a3[2 * a5c] = pFace->pYInterceptDisplacements[a5c] + pIndoor->pVertices[pFace->pVertexIDs[a5c]].y;
          *(v18 - 1) = pFace->pZInterceptDisplacements[v19] + pIndoor->pVertices[pFace->pVertexIDs[v19]].z;
          *(__int16 *)((char *)v18 + (int)(char *)a3 - (char *)a4) = pFace->pYInterceptDisplacements[v19 + 1]
                                                              + pIndoor->pVertices[pFace->pVertexIDs[v19 + 1]].y;
          ++a5c;
          *v18 = pFace->pZInterceptDisplacements[v19 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v19 + 1]].z;
          v18 += 2;
        }
        while ( a5c < pFace->uNumVertices );
      }
    }
    else
    {
      v14 = a5->x;
      a5b = 0;
      *a1 = v14;
      *a2 = v13->z;
      if ( pFace->uNumVertices )
      {
        v15 = a4 + 1;
        do
        {
          v16 = a5b;
          a3[2 * a5b] = pFace->pXInterceptDisplacements[a5b] + pIndoor->pVertices[pFace->pVertexIDs[a5b]].x;
          *(v15 - 1) = pFace->pZInterceptDisplacements[v16] + pIndoor->pVertices[pFace->pVertexIDs[v16]].z;
          *(__int16 *)((char *)v15 + (int)a3 - (int)a4) = pFace->pXInterceptDisplacements[v16 + 1]
                                                              + pIndoor->pVertices[pFace->pVertexIDs[v16 + 1]].x;
          ++a5b;
          *v15 = pFace->pZInterceptDisplacements[v16 + 1] + pIndoor->pVertices[pFace->pVertexIDs[v16 + 1]].z;
          v15 += 2;
        }
        while ( a5b < pFace->uNumVertices );
      }
    }
  }
  LOBYTE(result) = 1;
  return result;
}

//----- (004C2186) --------------------------------------------------------
bool Vis::_4C2186_BLV_IntersectBModel(int *a1, int *a2, __int16 *a3, __int16 *a4, Vec3_short_ *a5, BLVFace *a6, unsigned int uModelID)
{
  bool result; // eax@1
  int *v9; // esi@1
  unsigned int v10; // ecx@1
  unsigned int v11; // edx@3
  signed int v12; // ecx@4
  __int16 v13; // si@4
  __int16 *v14; // ecx@4
  unsigned int v15; // edx@8
  signed int v16; // ecx@9
  __int16 v17; // si@9
  __int16 *v18; // ecx@9
  unsigned int v19; // edx@12
  signed int v20; // ecx@13
  __int16 v21; // si@13
  __int16 *v22; // ecx@13
  signed int a1a; // [sp+14h] [bp+8h]@1
  __int16 *a5a; // [sp+24h] [bp+18h]@3
  __int16 *a5b; // [sp+24h] [bp+18h]@8
  __int16 *a5c; // [sp+24h] [bp+18h]@12

  result = (bool)a6;
  v9 = a1;
  v10 = a6->uAttributes;
  a1a = 0;
  if ( BYTE1(v10) & 1 )
  {
    *v9 = a5->x;
    *a2 = a5->y;
    if ( a6->uNumVertices )
    {
      v11 = 188 * uModelID + 72;
      a5a = a4 + 1;
      do
      {
        v12 = a1a;
        a3[2 * a1a] = a6->pXInterceptDisplacements[a1a]
                    + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[a1a]);
        *(a5a - 1) = a6->pYInterceptDisplacements[v12]
                   + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[v12] + 4);
        *(__int16 *)((char *)a5a + (int)(char *)a3 - (char *)a4) = a6->pXInterceptDisplacements[v12 + 1]
                                                            + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11]
                                                                       + 12 * a6->pVertexIDs[v12 + 1]);
        v13 = a6->pYInterceptDisplacements[v12 + 1]
            + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[v12 + 1] + 4);
        v14 = a5a;
        ++a1a;
        a5a += 2;
        *v14 = v13;
      }
      while ( a1a < a6->uNumVertices );
    }
  }
  else
  {
    if ( BYTE1(v10) & 2 )
    {
      *v9 = a5->x;
      *a2 = a5->z;
      if ( a6->uNumVertices )
      {
        v15 = 188 * uModelID + 72;
        a5b = a4 + 1;
        do
        {
          v16 = a1a;
          a3[2 * a1a] = a6->pXInterceptDisplacements[a1a]
                      + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[a1a]);
          *(a5b - 1) = a6->pZInterceptDisplacements[v16]
                     + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[v16] + 8);
          *(__int16 *)((char *)a5b + (int)a3 - (int)a4) = a6->pXInterceptDisplacements[v16 + 1]
                                                              + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15]
                                                                         + 12 * a6->pVertexIDs[v16 + 1]);
          v17 = a6->pZInterceptDisplacements[v16 + 1]
              + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[v16 + 1] + 8);
          v18 = a5b;
          ++a1a;
          a5b += 2;
          *v18 = v17;
        }
        while ( a1a < a6->uNumVertices );
      }
    }
    else
    {
      *v9 = a5->y;
      *a2 = a5->z;
      if ( a6->uNumVertices )
      {
        v19 = 188 * uModelID + 72;
        a5c = a4 + 1;
        do
        {
          v20 = a1a;
          a3[2 * a1a] = a6->pYInterceptDisplacements[a1a]
                      + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[a1a] + 4);
          *(a5c - 1) = a6->pZInterceptDisplacements[v20]
                     + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[v20] + 8);
          *(__int16 *)((char *)a5c + (int)(char *)a3 - (char *)a4) = a6->pYInterceptDisplacements[v20 + 1]
                                                              + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19]
                                                                         + 12 * a6->pVertexIDs[v20 + 1]
                                                                         + 4);
          v21 = a6->pZInterceptDisplacements[v20 + 1]
              + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[v20 + 1] + 8);
          v22 = a5c;
          ++a1a;
          a5c += 2;
          *v22 = v21;
        }
        while ( a1a < a6->uNumVertices );
      }
    }
  }
  LOBYTE(result) = 1;
  return result;
}

//----- (004C248E) --------------------------------------------------------
void Vis::CastPickRay(RenderVertexSoft *pRay, float fMouseX, float fMouseY, float fPickDepth)
{
  int v5; // ebx@1
  int v6; // edi@1
  int v7; // esi@1
  Vec3_int_ v8; // ST08_12@1
  int v9; // ST04_4@1
  int v10; // eax@1
  RenderVertexSoft v11[2]; // [sp+2Ch] [bp-74h]@1
  int v12; // [sp+8Ch] [bp-14h]@1
  int v13; // [sp+90h] [bp-10h]@1
  int outz; // [sp+94h] [bp-Ch]@1
  int outy; // [sp+98h] [bp-8h]@1
  int v16; // [sp+9Ch] [bp-4h]@1

  v5 = pIndoorCamera->pos.y;
  v6 = pIndoorCamera->pos.x;
  v13 = pIndoorCamera->pos.x;
  v12 = pIndoorCamera->pos.y;
  v16 = pIndoorCamera->pos.z;
  v7 = pIndoorCamera->sRotationY + UnprojectX((signed __int64)fMouseX);
  v8.z = v16;
  v8.x = v6;
  v8.y = v5;
  v9 = pIndoorCamera->sRotationX + UnprojectY((signed __int64)fMouseY);
  v10 = _48B561_mess_with_scaling_along_z(/*(int)&fMouseX, */fPickDepth);
  Vec3_int_::Rotate(v10, v7, v9, v8, (int *)&fMouseX, &outy, &outz);
  v11[0].flt_2C = 0.0;
  v11[0].vWorldPosition.x = (double)SLODWORD(fMouseX);
  v11[0].vWorldPosition.y = (double)outy;
  v11[0].vWorldPosition.z = (double)outz;
  v11[1].flt_2C = 0.0;
  v11[1].vWorldPosition.x = (double)v13;
  v11[1].vWorldPosition.y = (double)v12;
  v11[1].vWorldPosition.z = (double)v16;
  memcpy(pRay, &v11[1], 0x30u);
  memcpy(&pRay[1], v11, sizeof(pRay[1]));
}

//----- (004C2551) --------------------------------------------------------
Vis_stru1_stru0 *Vis_stru1::sub_4C2551(int a2, int a3)
{
  unsigned int v3; // esi@1
  signed int v4; // edx@1
  char *v5; // eax@2
  Vis_stru1_stru0 *result; // eax@6

  v3 = this->uNumPointers;
  v4 = 0;
  if ( (signed int)v3 <= 0 )
  {
LABEL_6:
    result = 0;
  }
  else
  {
    v5 = (char *)&this->array_0004[0].sZValue;
    while ( *((int *)v5 + 1) != a2 || (*(int *)v5 & 0xFFFF) != a3 )
    {
      ++v4;
      v5 += 12;
      if ( v4 >= (signed int)v3 )
        goto LABEL_6;
    }
    result = &this->array_0004[v4];
  }
  return result;
}

//----- (004C2591) --------------------------------------------------------
Vis_stru1_stru0 **Vis_stru1::create_object_pointers(unsigned int flag)
{
  Vis_stru1_stru0 **result; // eax@1
  signed int v3; // esi@2
  Vis_stru1_stru0 *v4; // edx@3
  unsigned __int8 v5; // zf@7
  unsigned __int8 v6; // sf@7
  Vis_stru1_stru0 **v7; // ebx@8
  Vis_stru1_stru0 *v8; // esi@8
  signed int v9; // edi@9
  Vis_stru1_stru0 **v10; // edx@10
  std::string v11; // [sp-18h] [bp-28h]@19
  const char *v12; // [sp-8h] [bp-18h]@19
  int v13; // [sp-4h] [bp-14h]@19
  char v14; // [sp+Ch] [bp-4h]@19

  result = 0;
  if ( flag )
  {
    if ( flag == 1 )
    {
      v5 = this->uNumPointers == 0;
      v6 = (this->uNumPointers & 0x80000000u) != 0;
      BYTE3(flag) = 1;
      if ( !(v6 | v5) )
      {
        v7 = this->array_1804;
        v8 = this->array_0004;
        do
        {
          v9 = 0;
          if ( (signed int)result > 0 )
          {
            v10 = this->array_1804;
            while ( *v10 != v8 )
            {
              ++v9;
              ++v10;
              if ( v9 >= (signed int)result )
                goto LABEL_15;
            }
            BYTE3(flag) = 0;
          }
LABEL_15:
          if ( BYTE3(flag) )
            *v7 = v8;
          result = (Vis_stru1_stru0 **)((char *)result + 1);
          ++v7;
          ++v8;
        }
        while ( (signed int)result < (signed int)this->uNumPointers );
      }
    }
    else
    {
      MessageBoxW(nullptr, L"Unknown pointer creation flag passed to ::create_object_pointers()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1358", 0);
    }
  }
  else
  {
    v3 = 0;
    if ( (signed int)this->uNumPointers > 0 )
    {
      result = this->array_1804;
      v4 = this->array_0004;
      do
      {
        *result = v4;
        ++v3;
        ++result;
        ++v4;
      }
      while ( v3 < (signed int)this->uNumPointers );
    }
  }
  return result;
}

//----- (004C264A) --------------------------------------------------------
void Vis::sort_object_pointers(Vis_stru1_stru0 **pPointers, int left, int right)
{
  int v4; // edx@1
  int v5; // ebx@1
  int v6; // esi@2
  signed int i; // ecx@2
  int v8; // eax@3
  int v9; // ebx@4
  int v10; // ebx@6
  Vis_stru1_stru0 *v11; // eax@7
  Vis *thisa; // [sp+4h] [bp-4h]@1
  Vis_stru1_stru0 *a3a; // [sp+14h] [bp+Ch]@2

  v4 = left;
  v5 = right;
  thisa = this;
  if ( right > left )
  {
    do
    {
      v6 = v4 - 1;
      a3a = pPointers[v5];
      for ( i = v5; ; pPointers[i] = v11 )
      {
        v8 = a3a->sZValue;
        LOWORD(v8) = 0;
        do
        {
          ++v6;
          v9 = pPointers[v6]->sZValue;
          LOWORD(v9) = 0;
        }
        while ( v9 < (unsigned int)v8 );
        do
        {
          if ( i < 1 )
            break;
          --i;
          v10 = pPointers[i]->sZValue;
          LOWORD(v10) = 0;
        }
        while ( v10 > (unsigned int)v8 );
        v11 = pPointers[v6];
        if ( v6 >= i )
          break;
        pPointers[v6] = pPointers[i];
      }
      v5 = right;
      pPointers[v6] = pPointers[right];
      pPointers[right] = v11;
      sort_object_pointers(pPointers, v4, v6 - 1);
      v4 = v6 + 1;
    }
    while ( right > v6 + 1 );
  }
}

//----- (004C26D0) --------------------------------------------------------
bool Vis::SortVerticesByX(RenderVertexD3D3 *a2, unsigned int uStart, unsigned int uEnd)
{
  bool result; // eax@1
  RenderVertexD3D3 *v5; // edx@2
  RenderVertexD3D3 *v6; // esi@2
  void *v7; // edi@2
  unsigned int v8; // ebx@2
  RenderVertexD3D3 *v9; // ecx@3
  RenderVertexD3D3 *v10; // ecx@5
  RenderVertexD3D3 *v11; // eax@8
  RenderVertexD3D3 v12; // [sp+4h] [bp-4Ch]@8
  RenderVertexD3D3 v13; // [sp+24h] [bp-2Ch]@2
  Vis *thisa; // [sp+44h] [bp-Ch]@1
  RenderVertexD3D3 *v15; // [sp+48h] [bp-8h]@2
  unsigned int v16; // [sp+4Ch] [bp-4h]@2

  result = uEnd;
  thisa = this;
  if ( (signed int)uEnd > (signed int)uStart )
  {
    v5 = a2;
    v6 = &a2[uEnd];
    v7 = &v13;
    v15 = &a2[uEnd];
    v8 = uStart - 1;
    v16 = uEnd;
    while ( 1 )
    {
      memcpy(v7, v6, 0x20u);
      v9 = &v5[v8];
      do
      {
        ++v9;
        ++v8;
      }
      while ( v9->pos.x < (double)v13.pos.x );
      v10 = &v5[v16];
      do
      {
        --v10;
        --v16;
      }
      while ( v10->pos.x > (double)v13.pos.x );
      if ( (signed int)v8 >= (signed int)v16 )
        break;
      v11 = &v5[v16];
      memcpy(&v12, &a2[v8], sizeof(v12));
      v5 = a2;
      memcpy(&a2[v8], v11, sizeof(a2[v8]));
      v6 = &v12;
      v7 = v11;
    }
    memcpy(&v12, &v5[v8], sizeof(v12));
    memcpy(&v5[v8], v15, sizeof(v5[v8]));
    memcpy(v15, &v12, 0x20u);
    SortVerticesByX(v5, uStart, v8 - 1);
    SortVerticesByX(a2, v8 + 1, uEnd);
  }
  return true;
}

//----- (004C27AD) --------------------------------------------------------
bool Vis::SortVerticesByY(RenderVertexD3D3 *a2, unsigned int uStart, unsigned int uEnd)
{
  bool result; // eax@1
  RenderVertexD3D3 *v5; // edx@2
  RenderVertexD3D3 *v6; // esi@2
  RenderVertexD3D3 v7; // qdi@2
  unsigned int v8; // ebx@2
  int v9; // ecx@3
  int v10; // ecx@5
  float v11; // eax@8
  RenderVertexD3D3 v12; // [sp+4h] [bp-4Ch]@8
  char v13; // [sp+24h] [bp-2Ch]@2
  float v14; // [sp+28h] [bp-28h]@4
  Vis *thisa; // [sp+44h] [bp-Ch]@1
  RenderVertexD3D3 *v16; // [sp+48h] [bp-8h]@2
  unsigned int v17; // [sp+4Ch] [bp-4h]@2

  result = uEnd;
  thisa = this;
  if ( (signed int)uEnd > (signed int)uStart )
  {
    v5 = a2;
    v6 = &a2[uEnd];
    LODWORD(v7.pos.x) = (int)&v13;
    v16 = &a2[uEnd];
    v8 = uStart - 1;
    v17 = uEnd;
    while ( 1 )
    {
      memcpy(*(void **)&v7.pos.x, v6, 0x20u);
      v9 = (int)&v5[v8].pos.y;
      do
      {
        v9 += 32;
        ++v8;
      }
      while ( *(float *)v9 < (double)v14 );
      v10 = (int)&v5[v17].pos.y;
      do
      {
        v10 -= 32;
        --v17;
      }
      while ( *(float *)v10 > (double)v14 );
      if ( (signed int)v8 >= (signed int)v17 )
        break;
      LODWORD(v11) = (int)&v5[v17];
      memcpy(&v12, &a2[v8], sizeof(v12));
      v5 = a2;
      memcpy(&a2[v8], *(void **)&v11, sizeof(a2[v8]));
      v6 = &v12;
      v7.pos.x = v11;
    }
    memcpy(&v12, &v5[v8], sizeof(v12));
    memcpy(&v5[v8], v16, sizeof(v5[v8]));
    memcpy(v16, &v12, 0x20u);
    SortVerticesByY(v5, uStart, v8 - 1);
    SortVerticesByY(a2, v8 + 1, uEnd);
  }
  return true;
}

//----- (004C288E) --------------------------------------------------------
bool Vis::sort_objects_2(RenderVertexSoft *pArray, int sLeft, int sRight)
{
  bool result; // eax@1
  RenderVertexSoft *v5; // edx@2
  int v6; // ebx@2
  int i; // ecx@2
  int v8; // esi@3
  int v9; // esi@5
  RenderVertexSoft *v10; // eax@8
  RenderVertexSoft v11; // [sp+4h] [bp-6Ch]@8
  RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2
  float v13; // [sp+4Ch] [bp-24h]@4
  int v14; // [sp+64h] [bp-Ch]@7
  Vis *thisa; // [sp+68h] [bp-8h]@1
  RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2

  __debugbreak();

  result = sRight;
  thisa = this;
  if ( sRight > sLeft )
  {
    v5 = pArray;
    v16 = &pArray[sRight];
    v6 = sLeft - 1;
    memcpy(&v12, &pArray[sRight], sizeof(v12));
    for ( i = sRight; ; i = v14 )
    {
      v8 = (int)&v5[v6].vWorldViewProjX;
      do
      {
        v8 += 48;
        ++v6;
      }
      while ( *(float *)v8 < (double)v13 );
      v9 = (int)&v5[i].vWorldViewProjX;
      do
      {
        v9 -= 48;
        --i;
      }
      while ( *(float *)v9 > (double)v13 );
      v14 = i;
      if ( v6 >= i )
        break;
      v10 = &v5[i];
      memcpy(&v11, &pArray[v6], sizeof(v11));
      v5 = pArray;
      memcpy(&pArray[v6], v10, sizeof(pArray[v6]));
      memcpy(v10, &v11, 0x30u);
    }
    memcpy(&v11, &v5[v6], sizeof(v11));
    memcpy(&v5[v6], v16, sizeof(v5[v6]));
    memcpy(v16, &v11, 0x30u);
    sort_objects_2(v5, sLeft, v6 - 1);
    sort_objects_2(pArray, v6 + 1, sRight);
  }
  return true;
}

//----- (004C297E) --------------------------------------------------------
bool Vis::sort_objects_3(RenderVertexSoft *pArray, int sLeft, int sRight)
{
  bool result; // eax@1
  RenderVertexSoft *v5; // edx@2
  int v6; // ebx@2
  int i; // ecx@2
  int v8; // esi@3
  int v9; // esi@5
  RenderVertexSoft *v10; // eax@8
  char v11; // [sp+4h] [bp-6Ch]@8
  RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2
  float v13; // [sp+50h] [bp-20h]@4
  int v14; // [sp+64h] [bp-Ch]@7
  Vis *thisa; // [sp+68h] [bp-8h]@1
  RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2

  result = sRight;
  thisa = this;
  if ( sRight > sLeft )
  {
    v5 = pArray;
    v16 = &pArray[sRight];
    v6 = sLeft - 1;
    memcpy(&v12, &pArray[sRight], sizeof(v12));
    for ( i = sRight; ; i = v14 )
    {
      v8 = (int)&v5[v6].vWorldViewProjY;
      do
      {
        v8 += 48;
        ++v6;
      }
      while ( *(float *)v8 < (double)v13 );
      v9 = (int)&v5[i].vWorldViewProjY;
      do
      {
        v9 -= 48;
        --i;
      }
      while ( *(float *)v9 > (double)v13 );
      v14 = i;
      if ( v6 >= i )
        break;
      v10 = &v5[i];
      memcpy(&v11, &pArray[v6], 0x30u);
      v5 = pArray;
      memcpy(&pArray[v6], v10, sizeof(pArray[v6]));
      memcpy(v10, &v11, 0x30u);
    }
    memcpy(&v11, &v5[v6], 0x30u);
    memcpy(&v5[v6], v16, sizeof(v5[v6]));
    memcpy(v16, &v11, 0x30u);
    sort_objects_3(v5, sLeft, v6 - 1);
    sort_objects_3(pArray, v6 + 1, sRight);
  }
  return true;
}


//----- (004C04AF) --------------------------------------------------------
Vis::Vis()
{
  Vis *v1; // ebx@1
  Vis *result; // eax@1
  RenderVertexSoft v3; // [sp+Ch] [bp-60h]@1
  RenderVertexSoft v4; // [sp+3Ch] [bp-30h]@1

  v1 = this;
  v3.flt_2C = 0.0;
  v3.vWorldPosition.x = 0.0;
  v3.vWorldPosition.y = 65536.0;
  v3.vWorldPosition.z = 0.0;
  v4.flt_2C = 0.0;
  v4.vWorldPosition.x = 65536.0;
  v4.vWorldPosition.y = 0.0;
  v4.vWorldPosition.z = 0.0;
  memcpy(&v1->stru_200C, &v4, sizeof(v1->stru_200C));
  v4.flt_2C = 0.0;
  v4.vWorldPosition.x = 0.0;
  v4.vWorldPosition.y = 65536.0;
  v4.vWorldPosition.z = 0.0;
  memcpy(&v1->stru_203C, &v3, sizeof(v1->stru_203C));
  v3.flt_2C = 0.0;
  v3.vWorldPosition.x = 65536.0;
  v3.vWorldPosition.y = 0.0;
  v3.vWorldPosition.z = 0.0;
  memcpy(&v1->stru_206C, &v3, sizeof(v1->stru_206C));
  result = v1;
  memcpy(&v1->stru_209C, &v4, sizeof(v1->stru_209C));
  v1->field_20CC = 512;
}

//----- (004C055C) --------------------------------------------------------
Vis_stru1::Vis_stru1()
{
  for (uint i = 0; i < 512; ++i)
  {
    array_0004[i].pObjectInfo = 0;
    array_0004[i].sZValue = -1;
    array_0004[i].uObjectType = 0;
  }
  uNumPointers = 0;
}




//----- (004C05CC) --------------------------------------------------------
bool Vis::_4C05CC(Vis_stru1 *a2, stru157 *a3, stru157 *a4)
{
  Vis_stru1 *v4; // esi@1
  Vis *v5; // ebx@1
  char *v6; // edi@3
  float v7; // ST00_4@3
  bool result; // eax@6
  float v9; // [sp+4h] [bp-14h]@3

  v4 = a2;
  v5 = this;
  if ( !a2 )
    v4 = &this->stru1;
  v4->uNumPointers = 0;
  v6 = (char *)&this->field_20CC;
  v7 = (double)this->field_20CC;
  _4C06F8(v7, v4, a3);
  v9 = (double)*(signed int *)v6;
  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
    _4C0D32_BLV(v9, v4, a4);
  else
    _4C0DEA_ODM(v9, v4, a4);
  v4->create_object_pointers(1u);
  sort_object_pointers(v4->array_1804, 0, v4->uNumPointers - 1);
  return true;
}

//----- (004C0646) --------------------------------------------------------
bool Vis::PickMouse(float fDepth, float fMouseX, float fMouseY, stru157 *a5, stru157 *a6)
{
  RenderVertexSoft pMouseRay[2]; // [sp+1Ch] [bp-60h]@1

  stru1.uNumPointers = 0;
  CastPickRay(pMouseRay, fMouseX, fMouseY, fDepth);
  PickBillboards(fDepth, fMouseX, fMouseY, &stru1, a5);
  if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
    PickIndoor(fDepth, pMouseRay, &stru1, a6);
  else
    PickOutdoor(fDepth, pMouseRay, &stru1, a6, 0);
  stru1.create_object_pointers(0);
  sort_object_pointers(stru1.array_1804, 0, stru1.uNumPointers - 1);
  return true;
}

//----- (004C06F8) --------------------------------------------------------
void Vis::_4C06F8(float arg0, Vis_stru1 *a3, stru157 *a2)
{
  int v4; // ST18_4@5
  Vis_stru1_stru0 *v5; // edi@5
  void **v7; // [sp+24h] [bp-8h]@2
  unsigned int uD3DBillboardIdx; // [sp+28h] [bp-4h]@1

  uD3DBillboardIdx = 0;
  auto ecx0 = this;
  if ( (signed int)pRenderer->uNumBillboardsToDraw > 0 )
  {
    v7 = (void **)&pRenderer->pBillboardRenderListD3D[0].uParentBillboardID;
    do
    {
      if ( is_part_of_selection((BLVFace *)uD3DBillboardIdx, a2) )
      {
        if ( DoesRayIntersectBillboard(arg0, uD3DBillboardIdx) )
        {
          v4 = pBillboardRenderList[(int)*v7].sZValue;
          v5 = &a3->array_0004[a3->uNumPointers];
          v5->pObjectInfo = *v7;
          v5 = (Vis_stru1_stru0 *)((char *)v5 + 4);
          v5->pObjectInfo = (void *)v4;
          v5->sZValue = 1;
          ++a3->uNumPointers;
        }
      }
      ++uD3DBillboardIdx;
      v7 += 39;
    }
    while ( (signed int)uD3DBillboardIdx < (signed int)pRenderer->uNumBillboardsToDraw );
  }
}

//----- (004C0791) --------------------------------------------------------
bool Vis::is_part_of_selection(BLVFace *uD3DBillboardIdx_or_pBLVFace_or_pODMFace, stru157 *a2)
{
  stru157 *v3; // esi@1
  int result; // eax@1
  int v5; // edx@2
  int v6; // ecx@2
  char v7; // zf@3
  int v8; // esi@5
  std::string *v9; // ecx@7
  Actor *v10; // edi@18
  char v11; // zf@26
  const char *v12; // [sp-20h] [bp-2Ch]@7
  int v13; // [sp-1Ch] [bp-28h]@7
  std::string v14; // [sp-18h] [bp-24h]@7
  const char *v15; // [sp-8h] [bp-14h]@7
  int v16; // [sp-4h] [bp-10h]@7

  v3 = a2;
  result = a2->field_0;
  if ( a2->field_0 != 1 )
  {
    if ( result != 2
      || (uCurrentlyLoadedLevelType != LEVEL_Indoor ? (v11 = LOWORD(uD3DBillboardIdx_or_pBLVFace_or_pODMFace[3].pFacePlane.vNormal.y) == 0,
                                            result = uD3DBillboardIdx_or_pBLVFace_or_pODMFace->pFacePlane_old.dist) : (v11 = pIndoor->pFaceExtras[uD3DBillboardIdx_or_pBLVFace_or_pODMFace->uFaceExtraID].uEventID == 0, result = uD3DBillboardIdx_or_pBLVFace_or_pODMFace->uAttributes),
          a2->field_4 != 1) )
      goto LABEL_16;
    if ( v11 || result & a2->field_C )
      goto LABEL_33;
    v7 = (result & a2->field_8) == 0;
    goto LABEL_32;
  }
  v5 = a2->field_10;
  result = (pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].sZValue & 0xFFFF) >> 3;
  v6 = pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].sZValue & 7;
  if ( v5 & 2 )
  {
    v7 = v6 == a2->field_4;
    goto LABEL_32;
  }
  if ( v5 & 4 )
  {
    v8 = a2->field_4;
    if ( v6 != v8 )
      goto LABEL_16;
    if ( v8 != 5 )
    {
      v15 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:207";
      v12 = "Unsupported \"exclusion if no event\" type in CVis::is_part_of_selection";
LABEL_15:
          MessageBoxA(nullptr, v12, v15, 0);
      return true;
    }
    result *= 32;
    if ( *(__int16 *)((char *)&pLevelDecorations[0].uCog + result)
      || *(__int16 *)((char *)&pLevelDecorations[0].field_16_event_id + result) )
      goto LABEL_16;
    result = pLevelDecorations[result / sizeof(LevelDecoration)].IsInteractive();
    goto LABEL_11;
  }
  if ( v6 == a2->field_4 )
  {
    if ( v6 != 3 )
    {
      v15 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:245";
      v12 = "Default case reached in VIS";
      goto LABEL_15;
    }
    v10 = &pActors[result];
    result = 1 << LOBYTE(v10->uAIState);
    if ( result & a2->field_C
      || !(result & a2->field_8)
      || v5 & 8 && (result = MonsterStats::BelongsToSupertype(v10->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD)) == 0 )
      goto LABEL_33;
    if ( !(v3->field_10 & 1) )
      goto LABEL_16;
    result = v10->GetActorsRelation(nullptr);
LABEL_11:
    v7 = result == 0;
LABEL_32:
    if ( v7 )
      goto LABEL_33;
LABEL_16:
    return true;
  }
LABEL_33:
  LOBYTE(result) = 0;
  return result;
}

//----- (004C091D) --------------------------------------------------------
bool Vis::DoesRayIntersectBillboard(float fDepth, unsigned int uD3DBillboardIdx)
{
  unsigned int v3; // esi@3
  bool result; // eax@3
  int v5; // ecx@4
  double v6; // st7@4
  __int16 v7; // fps@4
  double v8; // st7@4
  unsigned __int8 v9; // c0@4
  char v10; // c2@4
  unsigned __int8 v11; // c3@4
  Vis_stru1_stru0 *v12; // eax@10
  __int16 v13; // fps@16
  double v14; // st7@16
  char v15; // c0@16
  char v16; // c2@16
  char v17; // c3@16
  double v18; // st7@18
  double v19; // st6@18
  double v20; // st4@18
  float v21; // ST0C_4@22
  float v22; // ST08_4@22
  signed int v23; // eax@27
  double v24; // st7@32
  double v25; // st6@32
  float v26; // eax@32
  double v27; // st7@36
  double v28; // st6@36
  __int16 v29; // fps@36
  char v30; // c0@36
  char v31; // c2@36
  char v32; // c3@36
  double v33; // st6@37
  __int16 v34; // fps@37
  char v35; // c0@37
  char v36; // c2@37
  char v37; // c3@37
  __int16 v38; // fps@38
  double v39; // st6@38
  unsigned __int8 v40; // c0@38
  char v41; // c2@38
  unsigned __int8 v42; // c3@38
  __int16 v43; // fps@39
  double v44; // st6@39
  char v45; // c0@39
  char v46; // c2@39
  char v47; // c3@39
  Vis *v48; // esi@40
  float v49; // ST08_4@40
  Vis_stru1_stru0 *v50; // eax@45
  RenderVertexSoft pRay[2]; // [sp+20h] [bp-DCh]@5
  RenderVertexSoft a3[2]; // [sp+80h] [bp-7Ch]@22
  float v53; // [sp+E0h] [bp-1Ch]@33
  float v54; // [sp+E4h] [bp-18h]@32
  float fBillboardCenterX; // [sp+E8h] [bp-14h]@5
  float fBillboardCenterY; // [sp+ECh] [bp-10h]@5
  unsigned int v57; // [sp+F0h] [bp-Ch]@5
  float v58; // [sp+F4h] [bp-8h]@17
  Vis *thisa; // [sp+F8h] [bp-4h]@1
  signed int a3a; // [sp+108h] [bp+Ch]@17
  float a3b; // [sp+108h] [bp+Ch]@32

  thisa = this;

  static Vis_stru1 Vis_static_stru_F91E10;

  Vis_static_stru_F91E10.uNumPointers = 0;
  v3 = uD3DBillboardIdx;
  result = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].uParentBillboardID;
  if ( result != -1
    && (v5 = pBillboardRenderList[result].sZValue,
        v6 = (double)(unsigned __int16)pBillboardRenderList[result].sZValue,
        result = v5 >> 16,
        v8 = v6 * 0.000015259022 + (double)(v5 >> 16),
        //UNDEF(v7),
        v9 = v8 < fDepth,
        v10 = 0,
        v11 = v8 == fDepth,
        BYTE1(result) = HIBYTE(v7),
        v9 | v11) )
  {
    LOWORD(v5) = 0;
    v57 = v5;
    GetPolygonCenter(
      pRenderer->pBillboardRenderListD3D[v3].pQuards,
      4u,
      &fBillboardCenterX,
      &fBillboardCenterY);
    CastPickRay(pRay, fBillboardCenterX, fBillboardCenterY, fDepth);
    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
      PickIndoor(fDepth, pRay, &Vis_static_stru_F91E10, &a5);
    else
      PickOutdoor(fDepth, pRay, &Vis_static_stru_F91E10, &a5, 0);
    Vis_static_stru_F91E10.create_object_pointers(0);
    sort_object_pointers(Vis_static_stru_F91E10.array_1804, 0, Vis_static_stru_F91E10.uNumPointers - 1);
    HIWORD(result) = HIWORD(Vis_static_stru_F91E10.uNumPointers);
    if ( Vis_static_stru_F91E10.uNumPointers
      && ((signed int)Vis_static_stru_F91E10.uNumPointers <= 0 ? (v12 = 0) : (v12 = Vis_static_stru_F91E10.array_1804[0]),
          result = v12->sZValue,
          LOWORD(result) = 0,
          result <= v57)
      || (double)(signed int)pViewport->uScreenX > fBillboardCenterX
      || (double)(signed int)pViewport->uScreenZ < fBillboardCenterX
      || (double)(signed int)pViewport->uScreenY > fBillboardCenterY
      || (v14 = (double)(signed int)pViewport->uScreenW,
          //UNDEF(v13),
          v15 = v14 < fBillboardCenterY,
          v16 = 0,
          v17 = v14 == fBillboardCenterY,
          BYTE1(result) = HIBYTE(v13),
          v14 < fBillboardCenterY) )
    {
      a3a = 0;
      result = (bool)&pRenderer->pBillboardRenderListD3D[v3].pQuards[0].pos.y;

      __debugbreak();
      {
      LODWORD(v58) = (int)((char *)&pRenderer + v3 * 156 + 1062620);// pBillboardRenderListD3D+0x0C
      }

      while ( 1 )
      {
        v18 = *(float *)(result - 4);
        v19 = *(float *)result;
        v20 = *(float *)(result - 4);
        Vis_static_stru_F91E10.uNumPointers = 0;
        if ( v20 >= (double)(signed int)pViewport->uScreenX )
        {
          if ( v18 <= (double)(signed int)pViewport->uScreenZ
            && v19 >= (double)(signed int)pViewport->uScreenY
            && v19 <= (double)(signed int)pViewport->uScreenW )
          {
            v21 = v19;
            v22 = v18;
            CastPickRay(a3, v22, v21, fDepth);
            if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
              PickIndoor(fDepth, a3, &Vis_static_stru_F91E10, &a5);
            else
              PickOutdoor(fDepth, a3, &Vis_static_stru_F91E10, &a5, 0);
            Vis_static_stru_F91E10.create_object_pointers(0);
            sort_object_pointers(
              Vis_static_stru_F91E10.array_1804,
              0,
              Vis_static_stru_F91E10.uNumPointers - 1);
            result = Vis_static_stru_F91E10.uNumPointers;
            if ( !Vis_static_stru_F91E10.uNumPointers )
              break;
            v23 = (signed int)(Vis_static_stru_F91E10.uNumPointers <= 0 ? 0 : Vis_static_stru_F91E10.array_1804[0]);
            result = *(int *)(v23 + 4);
            LOWORD(result) = 0;
            if ( result > v57 )
              break;
          }
        }
        ++a3a;
        result = LODWORD(v58) + 32;
        LODWORD(v58) += 32;
        if ( a3a >= 4 )
        {
          if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
            goto LABEL_49;
          v24 = pRenderer->pBillboardRenderListD3D[v3].pQuards[0].pos.x;
          v25 = pRenderer->pBillboardRenderListD3D[v3].pQuards[3].pos.x;
          v26 = pRenderer->pBillboardRenderListD3D[v3].pQuards[0].pos.y;
          v54 = pRenderer->pBillboardRenderListD3D[v3].pQuards[3].pos.x;
          v58 = v26;
          result = LODWORD(pRenderer->pBillboardRenderListD3D[v3].pQuards[1].pos.y);
          a3b = pRenderer->pBillboardRenderListD3D[v3].pQuards[1].pos.y;
          if ( v24 > v25 )
          {
            v53 = v24;
            v24 = v54;
            v25 = v53;
          }
          if ( v58 > (double)a3b )
            a3b = v58;
          if ( (Vis_static_stru_F91E10.uNumPointers = 0,
                v27 = (v25 - v24) * 0.5,
                v28 = (double)(signed int)pViewport->uScreenX,
                //UNDEF(v29),
                v30 = v27 < v28,
                v31 = 0,
                v32 = v27 == v28,
                BYTE1(result) = HIBYTE(v29),
                v27 < v28)
            || (v33 = (double)(signed int)pViewport->uScreenZ,
                //UNDEF(v34),
                v35 = v27 < v33,
                v36 = 0,
                v37 = v27 == v33,
                BYTE1(result) = HIBYTE(v34),
                v27 > v33)
            || (v39 = (double)(signed int)pViewport->uScreenY,
                //UNDEF(v38),
                v40 = v39 < a3b,
                v41 = 0,
                v42 = v39 == a3b,
                BYTE1(result) = HIBYTE(v38),
                !(v40 | v42))
            || (v44 = (double)(signed int)pViewport->uScreenW,
                //UNDEF(v43),
                v45 = v44 < a3b,
                v46 = 0,
                v47 = v44 == a3b,
                BYTE1(result) = HIBYTE(v43),
                v44 < a3b)
            || ((v48 = thisa, v49 = v27, CastPickRay(a3, v49, a3b, fDepth), uCurrentlyLoadedLevelType != LEVEL_Indoor) ? PickOutdoor(fDepth, a3, &Vis_static_stru_F91E10, &a5, 0) : PickIndoor(fDepth, a3, &Vis_static_stru_F91E10, &a5),
                (Vis_static_stru_F91E10.create_object_pointers(0),
                 sort_object_pointers(
                   Vis_static_stru_F91E10.array_1804,
                   0,
                   Vis_static_stru_F91E10.uNumPointers - 1),
                 (result = Vis_static_stru_F91E10.uNumPointers) != 0)
             && ((signed int)Vis_static_stru_F91E10.uNumPointers <= 0 ? (v50 = 0) : (v50 = Vis_static_stru_F91E10.array_1804[0]),
                 result = v50->sZValue,
                 LOWORD(result) = 0,
                 result <= v57)) )
            goto LABEL_49;
          break;
        }
      }
    }
    LOBYTE(result) = 1;
  }
  else
  {
LABEL_49:
    return false;
  }
  return result;
}
// F93E18: using guessed type char static_byte_F93E18_init;

//----- (004C0D32) --------------------------------------------------------
int Vis::_4C0D32_BLV(float a1, Vis_stru1 *arg4, stru157 *a2)
{
  int result; // eax@1
  signed int v5; // esi@2
  BLVFace *v6; // edi@4
  unsigned int v7; // eax@6
  Vis_stru1_stru0 *v8; // eax@6
  int v9; // ST18_4@7
  unsigned int v10; // ST1C_4@7
  unsigned int v11; // ecx@7
  signed int i; // [sp+18h] [bp-8h]@1
  Vis *thisa; // [sp+1Ch] [bp-4h]@1

  result = 0;
  thisa = this;
  for ( i = 0; i < (signed int)pStru170->uNumFaceIDs; ++i )
  {
    v5 = pStru170->pFaceIDs[2 * result];
    if ( v5 >= 0 )
    {
      if ( v5 < (signed int)pIndoor->uNumFaces )
      {
        v6 = &pIndoor->pFaces[v5];
        if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[v5]) )
        {
          if ( is_part_of_selection(v6, a2) )
          {
            v7 = 8 * v5;
            LOBYTE(v7) = 8 * v5 | 6;
            v8 = _4C1026(v6, v7, a1);
            if ( v8 )
            {
              v9 = v8->sZValue;
              v10 = v8->uObjectType;
              v11 = 3 * arg4->uNumPointers;
              arg4->array_0004[arg4->uNumPointers].pObjectInfo = v8->pObjectInfo;
              arg4->array_0004[4 * v11 / 0xC].sZValue = v9;
              arg4->array_0004[4 * v11 / 0xC].uObjectType = v10;
              ++arg4->uNumPointers;
            }
          }
        }
      }
    }
    result = i + 1;
  }
  return result;
}

//----- (004C0DEA) --------------------------------------------------------
void Vis::_4C0DEA_ODM(float arg0, Vis_stru1 *a3, stru157 *a2)
{
  int v4; // esi@1
  BSPModel *v5; // ebx@3
  unsigned __int8 v6; // zf@5
  char v7; // sf@5
  unsigned __int8 v8; // of@5
  ODMFace *v9; // esi@7
  unsigned int v10; // eax@8
  Vis_stru1_stru0 *v11; // eax@8
  unsigned int v12; // ecx@9
  BLVFace f; // [sp+10h] [bp-84h]@1
  void *v14; // [sp+70h] [bp-24h]@9
  int v15; // [sp+74h] [bp-20h]@9
  unsigned int v16; // [sp+78h] [bp-1Ch]@9
  int v17; // [sp+7Ch] [bp-18h]@1
  Vis *v18; // [sp+80h] [bp-14h]@1
  int v19; // [sp+84h] [bp-10h]@6
  unsigned int v20; // [sp+88h] [bp-Ch]@2
  int v21; // [sp+8Ch] [bp-8h]@5
  int a1; // [sp+90h] [bp-4h]@1

  auto ecx0 = this;
  v18 = ecx0;
  v4 = 0;
  v17 = 0;
  a1 = 0;
  if ( (signed int)pOutdoor->uNumBModels > 0 )
  {
    v20 = 0;
    do
    {
      v5 = &pOutdoor->pBModels[v20 / 0xBC];
      if ( IsBModelVisible(a1, &v17) )
      {
        if ( v17 != v4 )
        {
          v8 = __OFSUB__(v5->uNumFaces, v4);
          v6 = v5->uNumFaces == v4;
          v7 = ((v5->uNumFaces - v4) & 0x80000000u) != 0;
          v21 = v4;
          if ( !((unsigned __int8)(v7 ^ v8) | v6) )
          {
            v19 = v4;
            do
            {
              v9 = (ODMFace *)((char *)v5->pFaces + v19);
              if ( is_part_of_selection((BLVFace *)((char *)v5->pFaces + v19), a2) )
              {
                f.FromODM(v9);
                v10 = 8 * (v21 | (a1 << 6));
                LOBYTE(v10) = v10 | 6;
                v11 = _4C1026(&f, v10, arg0);
                if ( v11 )
                {
                  v14 = v11->pObjectInfo;
                  v15 = v11->sZValue;
                  v12 = a3->uNumPointers;
                  v16 = v11->uObjectType;
                  v12 *= 3;
                  *((int *)&a3->array_0004[0].pObjectInfo + v12) = (int)v14;
                  *(&a3->array_0004[0].sZValue + v12) = v15;
                  *(&a3->array_0004[0].uObjectType + v12) = v16;
                  ++a3->uNumPointers;
                }
              }
              ++v21;
              v19 += 308;
            }
            while ( v21 < (signed int)v5->uNumFaces );
            v4 = 0;
          }
        }
      }
      ++a1;
      v20 += 188;
    }
    while ( a1 < (signed int)pOutdoor->uNumBModels );
  }
}