view Outdoor.cpp @ 5:ca90d9e499b3

.
author Серик@ПончиК
date Tue, 09 Oct 2012 20:00:01 +0600
parents 8b8875f5b359
children ac0fb48cd27a
line wrap: on
line source

#include "Outdoor.h"
#include "Party.h"
#include "LayingItem.h"
#include "LOD.h"
#include "Render.h"
#include "MapInfo.h"
#include "Allocator.h"
#include "Weather.h"
#include "PaletteManager.h"
#include "GUIProgressBar.h"
#include "AudioPlayer.h"
#include "IndoorCamera.h"
#include "DecorationList.h"
#include "TileFrameTable.h"
#include "Math.h"
#include "ObjectList.h"
#include "Game.h"
#include "Actor.h"
#include "Chest.h"
#include "stru123.h"
#include "Time.h"
#include "Viewport.h"
#include "Events.h"

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





OutdoorLocation *pOutdoor;
OutdoorCamera *pOutdoorCamera;


stru149 stru_8019C8;
stru148 array_77EC08[2000];
Surf stru_80C980;
Edge defaultEdge; // weak
Edge stru_80C9A4;
Edge stru_80C9D8;


//----- (0047A59E) --------------------------------------------------------
void OutdoorLocation::ExecDraw(unsigned int bRedraw)
{
  int v1; // edi@1
  unsigned int v2; // ebx@1
  int v3; // ST18_4@3
  int v4; // ST04_4@19
  int v5; // eax@19

  v1 = 0;
  v2 = bRedraw;
  if ( viewparams->field_54 )
    v1 = 2;
  pIndoorCamera->sRotationX = pParty->sRotationX;
  pIndoorCamera->sRotationY = pParty->sRotationY;
  pIndoorCamera->pos.x = pParty->vPosition.x
                      - ((unsigned __int64)(stru_5C6E00->SinCos(pParty->sRotationY)
                                          * (signed __int64)pParty->field_18) >> 16);
  v3 = stru_5C6E00->SinCos(pParty->sRotationY - stru_5C6E00->uIntegerHalfPi);
  pIndoorCamera->field_4C = v1;
  pIndoorCamera->pos.y = pParty->vPosition.z - ((unsigned __int64)(v3 * (signed __int64)pParty->field_18) >> 16);
  pIndoorCamera->pos.z = pParty->vPosition.y + pParty->sEyelevel;
  if ( v2 || pRenderer->pRenderD3D )
  {
    ResetStru148s();
    pOutdoorCamera->RotationToInts();
    sub_481ED9_MessWithOutdoorCamera();
  }
  pIndoorCamera->uMapGridCellX = WorldPosToGridCellX(pParty->vPosition.x);
  pIndoorCamera->uMapGridCellZ = WorldPosToGridCellZ(pParty->vPosition.z);
  if ( v2 )
  {
    Software_ResetNewEdges();
    sub_487DA9();
    ptr_80C97C_Surfs = pSurfs;
    ptr_80C978_Edges = pEdges;
  }
  if ( pParty->uCurrentMinute != pOutdoor->uLastSunlightUpdateMinute )
    pOutdoor->UpdateSunlightVectors();
  pOutdoor->UpdateFog();
  pGame->pIndoorCameraD3D->Reset_list_0037C();
  if ( !v2 )
  {
    if ( !pRenderer->pRenderD3D )
    {
      pRenderer->OnOutdoorRedrawSW();
      goto LABEL_16;
    }
    goto LABEL_14;
  }
  if ( pRenderer->pRenderD3D )
  {
LABEL_14:
    pRenderer->DrawSkyD3D();
    pRenderer->DrawBuildingsD3D();
    pRenderer->DrawBezierTerrain();
    goto LABEL_16;
  }
  pRenderer->DrawBuildingsSW();
  pRenderer->DrawBezierTerrain();
  sr_sub_486F92_MessWithEdgesAndSpans();
  pOutdoorCamera->_487355();
LABEL_16:
  uNumMobileLightsApplied = 0;
  uNumStationaryLightsApplied = 0;
  if ( !pRenderer->pRenderD3D )
  {
    pRenderer->ExecOutdoorDrawSW();
    pGame->pIndoorCameraD3D->_438240_draw_lits();
  }
  pGame->PushStationaryLights(-1);
  pGame->PushStru165s();
  if ( v2 )
  {
    v4 = WorldPosToGridCellZ(pParty->vPosition.z);
    v5 = WorldPosToGridCellX(pParty->vPosition.x);
    pOutdoor->_47EF60(v5, v4, 1);
  }
  pGame->uFlags2 &= 0xFFFFFFFEu;
  if ( pRenderer->pRenderD3D && pRenderer->bUsingSpecular )
    pGame->pLightmapBuilder->uFlags |= 1u;
  else
    pGame->pLightmapBuilder->uFlags &= 0xFFFFFFFEu;
  uNumDecorationsDrawnThisFrame = 0;
  _unused000 = 0;
  uNumSpritesDrawnThisFrame = 0;
  uNumBillboardsToDraw = 0;
  DrawActors();
  if ( !pOutdoorCamera->bDoNotRenderDecorations )
    pRenderer->DrawDecorations();
  pRenderer->DrawLayingItems_Shooting_Magic_ODM();
  pRenderer->TransformBillboardsAndSetPalettesODM();
  sub_485F53((Vec2_int_ *)unnamed_6BE060);
}



//----- (00441CFF) --------------------------------------------------------
void OutdoorLocation::Draw()
{
  unsigned int v0; // ecx@1

  v0 = 1;
  if ( !(pParty->uFlags & 2) && !(pGame->uFlags2 & 1) )
    v0 = 0;
  pOutdoor->ExecDraw(v0);
  pGame->DrawParticles();
  pWeather->Draw();
  array_5118E8._440F07();
}


//----- (00488E23) --------------------------------------------------------
double OutdoorLocation::GetFogDensityByTime()
{
  int v1; // eax@3
  double v2; // st7@3

  if ( pParty->uCurrentHour < 5 )
    goto LABEL_9;
  if ( pParty->uCurrentHour >= 6 )
  {
    if ( pParty->uCurrentHour < 0x14 )
    {
      pWeather->field_FA0 = 0;
      v2 = 0.0;
      return v2 * 0.016666668;
    }
    if ( pParty->uCurrentHour < 0x15 )
    {
      v1 = 0;
      v2 = (double)(pParty->uCurrentHour - 20) * 60.0 + (double)(signed int)pParty->uCurrentMinute;
      goto LABEL_4;
    }
LABEL_9:
    v2 = 60.0;
    pWeather->field_FA0 = 1;
    return v2 * 0.016666668;
  }
  v1 = 0;
  v2 = 60.0 - (double)(60 * pParty->uCurrentHour + pParty->uCurrentMinute - 300);
LABEL_4:
  pWeather->field_FA0 = v1;
  return v2 * 0.016666668;
}

//----- (00488EB1) --------------------------------------------------------
int OutdoorLocation::GetSomeOtherTileInfo(int sX, int sY)
{
  OutdoorLocation *v3; // esi@1
  unsigned int v4; // edi@1
  unsigned int v5; // eax@1
  int result; // eax@5

  v3 = this;
  v4 = WorldPosToGridCellZ(sY);
  v5 = WorldPosToGridCellX(sX);
  if ( (v5 & 0x80000000u) != 0 || (signed int)v5 > 127 || (v4 & 0x80000000u) != 0 || (signed int)v4 > 127 )
    result = 0;
  else
    result = ActuallyGetSomeOtherTileInfo(v5, v4);
  return result;
}
// 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
// 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);

//----- (00488EEF) --------------------------------------------------------
unsigned int OutdoorLocation::GetTileTexture(int sX, int sZ)
{
  OutdoorLocation *v3; // esi@1
  unsigned int v4; // edi@1
  unsigned int v5; // eax@1
  unsigned int result; // eax@5

  v3 = this;
  v4 = WorldPosToGridCellZ(sZ);
  v5 = WorldPosToGridCellX(sX);
  if ( (v5 & 0x80000000u) != 0 || (signed int)v5 > 127 || (v4 & 0x80000000u) != 0 || (signed int)v4 > 127 )
    result = -1;
  else
    result = DoGetTileTexture(v5, v4);
  return result;
}
// 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
// 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);

//----- (00488F2E) --------------------------------------------------------
int OutdoorLocation::GetHeightOnTerrain(int sX, int sZ)
{
  int result; // eax@5

  if ( sX < 0 || sX > 127 || sZ < 0 || sZ > 127 )
    result = 0;
  else
    result = DoGetHeightOnTerrain(sX, sZ);
  return result;
}

//----- (00488F5C) --------------------------------------------------------
bool OutdoorLocation::Initialize(const char *pFilename, int File, size_t uRespawnInterval, int thisa)
{
  OutdoorLocation *v5; // esi@1
  bool result; // eax@2

  v5 = this;
  if ( pFilename )
  {
    Release();
    pBitmaps_LOD->ReleaseAll2();
    pSprites_LOD->DeleteSomeOtherSprites();
    pSpriteFrameTable->ResetSomeSpriteFlags();
    pIcons_LOD->ReleaseAll2();
    sub_46080D();
    TryLoadLevelFromLOD();
    if ( !Load((char *)pFilename, (ODMFace *)File, uRespawnInterval, thisa) )
    {
      MessageBoxA(0, "Error!", "Couldn't Load Map!", 0);
      CreateDebugLocation();
    }
    day_attrib = v5->day_attrib;
    day_fogrange_1 = v5->day_fogrange_1;
    day_fogrange_2 = v5->day_fogrange_2;
    if ( Is_out15odm_underwater() )
      SetUnderwaterFog();
    _6BE134_odm_main_tile_group = v5->pTileTypes[0].uTileGroup;
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}
// 6BE030: using guessed type int day_attrib;
// 6BE040: using guessed type int day_fogrange_1;
// 6BE044: using guessed type int day_fogrange_2;
// 6BE134: using guessed type int _6BE134_odm_main_tile_group;

//----- (0048901B) --------------------------------------------------------
bool OutdoorLocation::Release2()
{
  Release();
  pOutdoorCamera->ReleaseSoftwareDrawBuffers();
  return true;
}

//----- (0048902E) --------------------------------------------------------
bool OutdoorLocation::GetTravelDestination(signed int sPartyX, signed int sPartyZ, char *pOut, signed int a5)
{
  OutdoorLocation *v5; // esi@1
  char *v6; // eax@3
  int v7; // eax@3
  int v8; // edx@3
  signed int v9; // esi@7
  int v10; // esi@23
  signed int v11; // eax@23
  int v12; // ST14_4@25
  signed int v14; // [sp-4h] [bp-84h]@6
  char Str; // [sp+8h] [bp-78h]@3
  int a5a; // [sp+94h] [bp+14h]@3

  auto Source = this;

  v5 = Source;
  if ( a5 < 10
    || strlen(Source->pLevelFilename) != 9
    || (strcpy(&Str, v5->pLevelFilename),
        _strlwr(&Str),
        v6 = strtok(&Str, "out"),
        v6[2] = 0,
        v7 = atoi(v6),
        v8 = v7,
        a5a = v7,
        v7 < 1)
    || v7 > 15 )
    return 0;
  if ( sPartyX < -22528 )
  {
    v14 = 4;
LABEL_7:
    v9 = v14;
    goto LABEL_14;
  }
  if ( sPartyX > 22528 )
  {
    v14 = 3;
    goto LABEL_7;
  }
  if ( sPartyZ < -22528 )
  {
    v14 = 2;
    goto LABEL_7;
  }
  if ( sPartyZ <= 22528 )
    return 0;
  v9 = 1;
LABEL_14:
  if ( v7 == 14 )
  {
    if ( v9 == 4 )
    {
      if ( sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(0) )
      {
        uDefaultTravelTime_ByFoot = 1;
        strcpy(pOut, "out15.odm");
        uLevel_StartingPointType = 3;
LABEL_18:
        LOWORD(pParty->uFlags) &= 0xFD7Bu;
        return 1;
      }
      v8 = a5a;
    }
  }
  else
  {
    if ( v7 == 15 && v9 == 3 )
    {
      uDefaultTravelTime_ByFoot = 1;
      strcpy(pOut, "out14.odm");
      uLevel_StartingPointType = 4;
      goto LABEL_18;
    }
  }
  v10 = v9 + 4 * v8;
  v11 = (unsigned __int8)aTiletableLoadU[v10 + 39];
  if ( v11 >= 1 && v11 <= 15 )
  {
    v12 = (unsigned __int8)aTiletableLoadU[v10 + 39];
    uDefaultTravelTime_ByFoot = (unsigned __int8)byte_4ECA93[v10];
    sprintfex(pOut, "out%02d.odm", v12);
    uLevel_StartingPointType = (unsigned __int8)byte_4ECACF[v10];
    return 1;
  }
  return 0;
}
// 6BD07C: using guessed type int uDefaultTravelTime_ByFoot;
// 6BE35C: using guessed type int uLevel_StartingPointType;

//----- (0048917E) --------------------------------------------------------
void OutdoorLocation::MessWithLUN()
{
  OutdoorLocation *v1; // esi@1
  unsigned int *v2; // ebp@1
  unsigned int v3; // eax@1
  unsigned __int16 v4; // ax@1
  signed int v5; // ebx@1

  v1 = this;
  v2 = this->pSpriteIDs_LUN;
  this->pSpriteIDs_LUN[0] = -1;
  this->pSpriteIDs_LUN[2] = pSpriteFrameTable->FastFindSprite("LUN1-4");
  v1->pSpriteIDs_LUN[4] = pSpriteFrameTable->FastFindSprite("LUN1-2");
  v1->pSpriteIDs_LUN[6] = pSpriteFrameTable->FastFindSprite("LUN3-4");
  v1->uSpriteID_LUNFULL = pSpriteFrameTable->FastFindSprite("LUNFULL");
  v1->uSpriteID_LUN3_4_cp = pSpriteFrameTable->FastFindSprite("LUN3-4");
  v1->uSpriteID_LUN1_2_cp = pSpriteFrameTable->FastFindSprite("LUN1-2");
  v3 = pSpriteFrameTable->FastFindSprite("LUN1-4");
  v1->field_D60 = -1;
  v1->uSpriteID_LUN1_4_cp = v3;
  v1->field_CF0 = 4;
  v1->field_CF8 = 4;
  v1->field_D00 = 4;
  LOWORD(v3) = *(short *)v2;
  v1->pSpriteIDs_LUN[1] = 0;
  v1->pSpriteIDs_LUN[3] = 0;
  v1->pSpriteIDs_LUN[5] = 0;
  v1->pSpriteIDs_LUN[7] = 0;
  v1->field_CE8 = 0;
  LOWORD(v1->field_D3C) = v3;
  v1->field_D40 = 0;
  v1->field_D44 = 0;
  v1->field_D48 = 0;
  v1->field_D4C = 131072;
  v1->field_D5C = 0;
  v1->field_D64 = 0;
  v4 = pSpriteFrameTable->FastFindSprite("LUN-SUN");
  v1->field_D28 = -1;
  v1->field_D08 = 0;
  v1->field_D0C = 0;
  v1->field_D10 = 0;
  v1->field_D24 = 0;
  v1->field_D2C = 0;
  v1->uSpriteID_LUN_SUN = v4;
  v1->field_D14 = -131072;
  v5 = 8;
  do
  {
    pSpriteFrameTable->InitializeSprite(*v2);
    v2 += 2;
    --v5;
  }
  while ( v5 );
  pSpriteFrameTable->InitializeSprite(v1->uSpriteID_LUN_SUN);
}

//----- (004892E6) --------------------------------------------------------
unsigned int OutdoorLocation::UpdateSunlightVectors()
{
  unsigned int result; // eax@1
  OutdoorLocation *v2; // esi@1
  unsigned int v3; // edi@3
  int v4; // ebx@3
  int v5; // eax@3
  int v6; // eax@3
  int v7; // ecx@3
  double v8; // st7@4

  result = pParty->uCurrentHour;
  v2 = this;
  if ( pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 0x15 )
  {
    v3 = pParty->uCurrentMinute + 60 * (pParty->uCurrentHour - 5);
    v4 = (signed int)(v3 * stru_5C6E00->uIntegerPi) / 960;
    v5 = stru_5C6E00->SinCos((signed int)(v3 * stru_5C6E00->uIntegerPi) / 960);
    v2->field_D1C = 0;
    v2->field_D18 = v5;
    v6 = stru_5C6E00->SinCos(v4 - stru_5C6E00->uIntegerHalfPi);
    v7 = v2->field_D18;
    v2->field_D20 = v6;
    v2->vSunlight.x = -v7;
    v2->vSunlight.y = -v2->field_D1C;
    v2->vSunlight.z = -v6;
    if ( (signed int)v3 >= 480 )
      v8 = (double)(signed int)(960 - v3);
    else
      v8 = (double)(signed int)v3;
    v2->field_CBC_terrain_triangles_shade_type = (signed __int64)(20.0 - v8 * 0.002083333333333333 * 20.0);
    result = pParty->uCurrentMinute;
    v2->uLastSunlightUpdateMinute = pParty->uCurrentMinute;
  }
  return result;
}

//----- (004893C1) --------------------------------------------------------
void OutdoorLocation::UpdateFog()
{
  fFogDensity = GetFogDensityByTime();
}

//----- (004893CF) --------------------------------------------------------
int OutdoorLocation::GetNumFoodRequiredToRestInCurrentPos(int x, signed int y, int z)
{
  OutdoorLocation *v4; // ebx@1
  signed int v5; // edi@4
  int v6; // eax@4
  int v7; // eax@4
  int v8; // eax@4
  int v9; // eax@5
  int v10; // eax@6
  int v11; // eax@7
  int v12; // eax@8
  int v15; // [sp+8h] [bp-8h]@2
  int v16; // [sp+Ch] [bp-4h]@2

  v4 = this;
  if ( pParty->uFlags & 8
    || (v15 = 0,
        v16 = 0,
        sub_46D49E_prolly_get_world_y_under_party(x, y, z, pParty->uDefaultPartyHeight, &v15, &v16, 0),
        v16)
    || v15 )
    return 2;
  v5 = WorldPosToGridCellX(pParty->vPosition.x);
  v6 = WorldPosToGridCellZ(pParty->vPosition.z);
  v7 = _47ED83(v5, v6 - 1);
  v8 = pTileTable->pTiles[_47ECC1(v7)].uTerrainType;
  if ( v8 )
  {
    v9 = v8 - 1;
    if ( !v9 )
      return 3;
    v10 = v9 - 1;
    if ( !v10 )
      return 5;
    v11 = v10 - 1;
    if ( !v11 || (v12 = v11 - 3) == 0 )
      return 4;
    if ( v12 == 1 )
      return 3;
    return 2;
  }
  return 1;
}
// 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
// 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);

//----- (00489487) --------------------------------------------------------
int OutdoorLocation::SetFog()
{
  int result; // eax@1
  int v2; // esi@1
  int v3; // edx@5
  unsigned __int8 *v4; // eax@5
  int v5; // ecx@5
  int v6; // esi@7
  unsigned __int8 v7; // al@9

  strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
  result = pMapStats->GetMapInfo(pCurrentMapName);
  v2 = result;
  if ( result < 1 || result == 7 || result == 8 || result > 15 )
    return result;
  day_attrib &= 0xFFFFFFFEu;
  v3 = rand() % 100;
  v4 = (unsigned __int8 *)&byte_4ECB0C[4 * v2];
  v5 = *v4;
  if ( v3 < v5 )
  {
    day_fogrange_1 = 4096;
    day_fogrange_2 = 8192;
LABEL_13:
    day_attrib |= 1u;
    goto LABEL_14;
  }
  v6 = v4[1];
  if ( v3 < v6 + v5 )
  {
    day_fogrange_2 = 4096;
LABEL_12:
    day_fogrange_1 = 0;
    goto LABEL_13;
  }
  v7 = v4[2];
  if ( v7 && v3 < v5 + v6 + v7 )
  {
    day_fogrange_2 = 2048;
    goto LABEL_12;
  }
LABEL_14:
  if ( Is_out15odm_underwater() )
    SetUnderwaterFog();
  pOutdoor->day_fogrange_1 = day_fogrange_1;
  pOutdoor->day_fogrange_2 = day_fogrange_2;
  result = day_attrib;
  pOutdoor->day_attrib = day_attrib;
  return result;
}
// 6BE030: using guessed type int day_attrib;
// 6BE040: using guessed type int day_fogrange_1;
// 6BE044: using guessed type int day_fogrange_2;

//----- (00482170) --------------------------------------------------------
bool ODMFace::IsBackfaceCulled(ODMFace *a1, RenderVertexSoft *a2, stru148 *a3)
{
  stru148 *v3; // edi@1
  RenderVertexSoft *v4; // esi@1
  unsigned int v5; // edx@1
  RenderVertexSoft *v6; // ecx@2
  double v7; // st7@5
  double v8; // st6@5
  double v9; // st5@5
  double v10; // st6@9
  double v11; // st5@9
  double v12; // st4@9
  bool result; // eax@16
  double v14; // ST2C_8@17
  double v15; // ST20_8@17
  double v16; // ST0C_8@17
  double v17; // ST0C_8@17
  float v18; // [sp+8h] [bp-38h]@5
  float v19; // [sp+10h] [bp-30h]@5
  float v20; // [sp+14h] [bp-2Ch]@5
  float v21; // [sp+18h] [bp-28h]@5
  float v22; // [sp+1Ch] [bp-24h]@5
  float v23; // [sp+24h] [bp-1Ch]@5
  float v24; // [sp+28h] [bp-18h]@5
  float v25; // [sp+30h] [bp-10h]@5
  float v26; // [sp+34h] [bp-Ch]@5
  float v27; // [sp+38h] [bp-8h]@5
  float v28; // [sp+3Ch] [bp-4h]@5
  float a3a; // [sp+48h] [bp+8h]@5
  float a3b; // [sp+48h] [bp+8h]@17
  float a3c; // [sp+48h] [bp+8h]@17
  float a3d; // [sp+48h] [bp+8h]@17
  float a3e; // [sp+48h] [bp+8h]@17

  v3 = a3;
  v4 = a2;
  v5 = a3->uNumVertices;
  if ( (signed int)v5 < 3 )
    goto LABEL_20;
  v6 = &v4[v5 - 1];
  if ( v4->vWorldPosition.z == v4[1].vWorldPosition.z && v4[1].vWorldPosition.z == v6->vWorldPosition.z )
    *(int *)&a3->flags |= 0x10u;
  v19 = v4[1].vWorldViewPosition.x - v4->vWorldViewPosition.x;
  v18 = v4[1].vWorldViewPosition.y - v4->vWorldViewPosition.y;
  v20 = v4[1].vWorldViewPosition.z - v4->vWorldViewPosition.z;
  v21 = v6->vWorldViewPosition.x - v4->vWorldViewPosition.x;
  v22 = v6->vWorldViewPosition.y - v4->vWorldViewPosition.y;
  v23 = v6->vWorldViewPosition.z - v4->vWorldViewPosition.z;
  v28 = v4[1].vWorldPosition.x - v4->vWorldPosition.x;
  v27 = v4[1].vWorldPosition.y - v4->vWorldPosition.y;
  a3a = v4[1].vWorldPosition.z - v4->vWorldPosition.z;
  v7 = v6->vWorldPosition.x - v4->vWorldPosition.x;
  v8 = v6->vWorldPosition.y - v4->vWorldPosition.y;
  v9 = v6->vWorldPosition.z - v4->vWorldPosition.z;
  v26 = v27 * v9 - v8 * a3a;
  v24 = v7 * a3a - v9 * v28;
  v25 = v8 * v28 - v7 * v27;
  if ( v26 == 0.0 && v24 == 0.0 && v25 == 0.0 )
  {
    while ( 1 )
    {
      --v5;
      if ( (signed int)v5 < 2 )
        break;
      v10 = v6->vWorldPosition.x - v4->vWorldPosition.x;
      v11 = v6->vWorldPosition.y - v4->vWorldPosition.y;
      v12 = v6->vWorldPosition.z - v4->vWorldPosition.z;
      v26 = v27 * v12 - v11 * a3a;
      v24 = v10 * a3a - v12 * v28;
      v25 = v11 * v28 - v10 * v27;
      if ( v26 != 0.0 )
        break;
      if ( v24 != 0.0 || v25 != 0.0 )
        break;
      --v6;
    }
    v21 = v6->vWorldViewPosition.x - v4->vWorldViewPosition.x;
    v22 = v6->vWorldViewPosition.y - v4->vWorldViewPosition.y;
    v23 = v6->vWorldViewPosition.z - v4->vWorldViewPosition.z;
  }
  if ( ((double)pIndoorCamera->pos.x - v4->vWorldPosition.x) * v26
     + ((double)pIndoorCamera->pos.z - v4->vWorldPosition.z) * v25
     + ((double)pIndoorCamera->pos.y - v4->vWorldPosition.y) * v24 > 0.0 )
  {
    a3b = v23 * v18 - v22 * v20;
    v14 = a3b + 6.7553994e15;
    v3->v_18.x = LODWORD(v14);
    a3c = v21 * v20 - v23 * v19;
    v15 = a3c + 6.7553994e15;
    v3->v_18.y = LODWORD(v15);
    a3d = v22 * v19 - v21 * v18;
    v16 = a3d + 6.7553994e15;
    v3->v_18.z = LODWORD(v16);
    v3->_486089_normalize_v_18();
    a3e = -((double)v3->v_18.x * v4->vWorldViewPosition.x)
        - (double)v3->v_18.y * v4->vWorldViewPosition.y
        - (double)v3->v_18.z * v4->vWorldViewPosition.z;
    v17 = a3e + 6.7553994e15;
    v3->field_24 = LODWORD(v17);
    result = 1;
  }
  else
  {
LABEL_20:
    result = 0;
  }
  return result;
}


//----- (0047C7A9) --------------------------------------------------------
void OutdoorLocationTerrain::_47C7A9()
{
  this->field_10 = 0;
  this->field_12 = 0;
  this->field_16 = 0;
  this->field_14 = 0;
  this->field_1C = 0;
  this->field_18 = 0;
}

//----- (0047C7C2) --------------------------------------------------------
void OutdoorLocationTerrain::Release()
{
  OutdoorLocationTerrain *v1; // esi@1
  void *v2; // ST00_4@1
  void *v3; // ST00_4@1
  void *v4; // ST00_4@1

  v1 = this;
  pAllocator->FreeChunk(this->pHeightmap);
  v2 = v1->pTilemap;
  v1->pHeightmap = 0;
  pAllocator->FreeChunk(v2);
  v3 = v1->pAttributemap;
  v1->pTilemap = 0;
  pAllocator->FreeChunk(v3);
  v4 = v1->ptr_C;
  v1->pAttributemap = 0;
  pAllocator->FreeChunk(v4);
  v1->ptr_C = 0;
  _47C7A9();
}

//----- (0047C80A) --------------------------------------------------------
int OutdoorLocationTerrain::_47C80A(int a2, int a3, int a4, int a5)
{
  OutdoorLocationTerrain *v5; // ebx@1
  double v6; // st7@1
  double v7; // st7@2
  double v8; // st7@2
  int result; // eax@3
  int v10; // eax@4
  int v11; // ecx@5
  int v12; // ecx@6
  int v13; // edi@7
  int v14; // edx@9
  int v15; // eax@15
  unsigned __int8 *v16; // ebx@15
  int v17; // eax@15
  int v18; // ecx@15
  int v19; // esi@15
  int v20; // edi@15
  int v21; // edx@15
  int v22; // ecx@15
  int v23; // ebx@15
  int v24; // ecx@15
  int v25; // ST28_4@15
  double v26; // st7@15
  double v27; // st6@15
  double v28; // st5@15
  double v29; // st7@15
  double v30; // st7@16
  double v31; // st7@17
  int v32; // eax@21
  double v33; // st7@21
  double v34; // st6@21
  double v35; // st5@21
  double v36; // st7@21
  double v37; // st7@22
  double v38; // st7@23
  int v39; // [sp+14h] [bp-34h]@8
  int v40; // [sp+18h] [bp-30h]@15
  int v41; // [sp+1Ch] [bp-2Ch]@15
  int v42; // [sp+20h] [bp-28h]@15
  OutdoorLocationTerrain *v43; // [sp+24h] [bp-24h]@1
  int v44; // [sp+28h] [bp-20h]@21
  float v45; // [sp+2Ch] [bp-1Ch]@1
  float v46; // [sp+30h] [bp-18h]@1
  float v47; // [sp+34h] [bp-14h]@1
  int v48; // [sp+38h] [bp-10h]@7
  int v49; // [sp+3Ch] [bp-Ch]@10
  int v50; // [sp+40h] [bp-8h]@9
  float v51; // [sp+44h] [bp-4h]@15
  float v52; // [sp+44h] [bp-4h]@21
  float v53; // [sp+50h] [bp+8h]@15
  float v54; // [sp+50h] [bp+8h]@21
  int v55; // [sp+54h] [bp+Ch]@15
  float v56; // [sp+54h] [bp+Ch]@15
  float v57; // [sp+54h] [bp+Ch]@21

  v46 = -64.0;
  v47 = -64.0;
  v5 = this;
  v45 = 64.0;
  v43 = this;
  v6 = sqrt(12288.0);
  if ( v6 != 0.0 )
  {
    v7 = 1.0 / v6;
    v45 = 64.0 * v7;
    v8 = v7 * -64.0;
    v46 = v8;
    v47 = v8;
  }
  result = a3;
  if ( a3 > a5 )
  {
    v10 = a5 ^ a3;
    a5 ^= a3 ^ a5;
    result = a5 ^ v10;
  }
  v11 = a2;
  if ( a2 > a4 )
  {
    v12 = a4 ^ a2;
    a4 ^= a2 ^ a4;
    v11 = a4 ^ v12;
  }
  v13 = result - 1;
  v48 = result - 1;
  if ( result - 1 <= a5 )
  {
    v39 = v11 - 1;
    do
    {
      v14 = v39;
      v50 = v39;
      if ( v39 <= a4 )
      {
        result = (v39 - 63) << 9;
        v49 = (v39 - 63) << 9;
        do
        {
          if ( v13 >= 0 && result >= -32256 && v13 <= 127 && result <= 32768 )
          {
            v15 = v5->field_10;
            v55 = v15;
            v16 = v5->pHeightmap;
            v17 = (int)(&v16[v13 * v15] + v14);
            v18 = -v13;
            v19 = (64 - v13) << 9;
            v20 = 32 * *(char *)v17;
            v21 = 32 * *(char *)(v17 + 1);
            v22 = (v18 + 63) << 9;
            v41 = v22;
            v23 = (int)(&v16[v55 * (v48 + 1)] + v50);
            v24 = v22 - v19;
            v40 = 32 * *(char *)v23;
            v42 = 32 * *(char *)(v23 + 1);
            v25 = v49 - 512 - v49;
            v26 = (double)-((v20 - v21) * v24);
            v51 = v26;
            v27 = (double)-(v25 * (v42 - v21));
            v53 = v27;
            v28 = (double)(v25 * v24);
            v56 = v28;
            v29 = sqrt(v28 * v28 + v27 * v27 + v26 * v26);
            if ( v29 != 0.0 )
            {
              v30 = 1.0 / v29;
              v51 = v51 * v30;
              v53 = v53 * v30;
              v56 = v30 * v56;
            }
            v31 = (v56 * v47 + v53 * v46 + v51 * v45) * 31.0;
            if ( v31 < 0.0 )
              v31 = 0.0;
            if ( v31 > 31.0 )
              v31 = 31.0;
            v44 = 2 * (v50 + v48 * v43->field_10);
            v5 = v43;
            *((char *)v43->ptr_C + v44 + 1) = (signed __int64)v31;
            v32 = v49 - (v49 - 512);
            v33 = (double)-((v42 - v40) * (v19 - v41));
            v52 = v33;
            v34 = (double)-(v32 * (v20 - v40));
            v54 = v34;
            v35 = (double)(v32 * (v19 - v41));
            v57 = v35;
            v36 = sqrt(v35 * v35 + v34 * v34 + v33 * v33);
            if ( v36 != 0.0 )
            {
              v37 = 1.0 / v36;
              v52 = v52 * v37;
              v54 = v54 * v37;
              v57 = v37 * v57;
            }
            v38 = (v57 * v47 + v54 * v46 + v52 * v45) * 31.0;
            if ( v38 < 0.0 )
              v38 = 0.0;
            if ( v38 > 31.0 )
              v38 = 31.0;
            v13 = v48;
            *((char *)v43->ptr_C + v44) = (signed __int64)v38;
            v14 = v50;
            result = v49;
          }
          ++v14;
          result += 512;
          v50 = v14;
          v49 = result;
        }
        while ( v14 <= a4 );
      }
      ++v13;
      v48 = v13;
    }
    while ( v13 <= a5 );
  }
  return result;
}

//----- (0047CB57) --------------------------------------------------------
int OutdoorLocationTerrain::_47CB57(int a1, int a2, int a3)
{
  signed int result; // eax@2
  unsigned __int16 *v5; // edx@3
  double v6; // st7@3
  char v7; // bl@3
  int v8; // eax@3
  int v9; // eax@4
  int v10; // eax@5
  double v11; // st6@7
  signed int v12; // edi@7
  int v13; // esi@9
  char *v14; // esi@10
  signed int v15; // ecx@10
  char v16[256]; // [sp+4h] [bp-124h]@9
  unsigned __int16 *v17; // [sp+104h] [bp-24h]@3
  unsigned int v18; // [sp+108h] [bp-20h]@3
  unsigned int v19; // [sp+10Ch] [bp-1Ch]@3
  unsigned int v20; // [sp+110h] [bp-18h]@3
  unsigned int v21; // [sp+114h] [bp-14h]@3
  float v22; // [sp+118h] [bp-10h]@3
  float v23; // [sp+11Ch] [bp-Ch]@3
  int i; // [sp+120h] [bp-8h]@3
  unsigned int v25; // [sp+124h] [bp-4h]@5
  signed int a2a; // [sp+134h] [bp+Ch]@3
  unsigned int a2b; // [sp+134h] [bp+Ch]@7
  float a3a; // [sp+138h] [bp+10h]@7
  int a3b; // [sp+138h] [bp+10h]@9

  if ( pRenderer->pRenderD3D )
  {
    result = 0;
  }
  else
  {
    v5 = PaletteManager::Get_Dark_or_Red_LUT(a2, 0, 1);
    v6 = 0.0;
    v7 = LOBYTE(pRenderer->uTargetBBits);
    v19 = pRenderer->uTargetRMask;
    v21 = pRenderer->uTargetGMask;
    v22 = 0.0;
    v20 = pRenderer->uTargetBMask;
    v8 = 0;
    v17 = v5;
    v23 = 0.0;
    v18 = pRenderer->uTargetBBits;
    a2a = 0;
    for ( i = 0; i < a3; ++i )
    {
      v9 = *(char *)(v8 + a1);
      if ( v9 )
      {
        v10 = v5[v9];
        v6 = v6 + (double)((signed int)(v19 & v10) >> (LOBYTE(pRenderer->uTargetBBits) + LOBYTE(pRenderer->uTargetGBits)));
        ++a2a;
        v25 = v20 & v10;
        v22 = (double)((signed int)(v21 & v10) >> SLOBYTE(pRenderer->uTargetBBits)) + v22;
        v23 = (double)(signed int)(v20 & v10) + v23;
      }
      v8 = i + 1;
    }
    v11 = 1.0 / (double)a2a;
    a3a = v11;
    v25 = (signed __int64)(a3a * v22);
    i = (signed __int64)(a3a * v23);
    v12 = 0;
    a2b = pRenderer->uTargetBBits + pRenderer->uTargetGBits;
    while ( 1 )
    {
      v13 = v17[v12];
      a3b = abs((__int64)(signed __int64)(v11 * v6) - ((signed int)(v19 & v17[v12]) >> a2b));
      BYTE3(a3b) = abs((signed)v25 - ((signed int)(v21 & v13) >> v7)) + a3b;
      v16[v12++] = abs((signed)i - (signed)(v20 & v13)) + BYTE3(a3b);
      if ( v12 >= 256 )
        break;
      v7 = v18;
    }
    result = 0;
    v14 = (char *)&pPaletteManager->field_D1600[42][23][116];
    v15 = 0;
    do
    {
      if ( (unsigned __int8)v16[v15] < (signed int)v14 )
      {
        v14 = (char *)(unsigned __int8)v16[v15];
        result = v15;
      }
      ++v15;
    }
    while ( v15 < 256 );
  }
  return result;
}
// 47CB57: using guessed type char var_124[256];

//----- (0047CCE2) --------------------------------------------------------
bool OutdoorLocationTerrain::ZeroLandscape()
{
  OutdoorLocationTerrain *v1; // esi@1

  v1 = this;
  memset(this->pHeightmap, 0, 0x4000u);
  memset(v1->pTilemap, 90, 0x4000u);
  memset(v1->pAttributemap, 0, 0x4000u);
  memset(v1->ptr_C, 0, 0x8000u);
  v1->field_12 = 128;
  v1->field_10 = 128;
  v1->field_16 = 7;
  v1->field_14 = 7;
  v1->field_1C = 127;
  v1->field_18 = 127;
  return 1;
}

//----- (0047CD44) --------------------------------------------------------
bool OutdoorLocationTerrain::Initialize()
{
  OutdoorLocationTerrain *v1; // esi@1
  void *v2; // eax@1
  bool result; // eax@2
  void *v4; // eax@3
  void *v5; // eax@4
  void *v6; // eax@5

  v1 = this;
  v2 = pAllocator->AllocNamedChunk(this->pHeightmap, 0x4000u, "HMAP");
  v1->pHeightmap = (unsigned __int8 *)v2;
  if ( v2
    && (v4 = pAllocator->AllocNamedChunk(v1->pTilemap, 0x4000u, "TMAP"),
        (v1->pTilemap = (unsigned __int8 *)v4) != 0)
    && (v5 = pAllocator->AllocNamedChunk(v1->pAttributemap, 0x4000u, "AMAP"),
        (v1->pAttributemap = (unsigned __int8 *)v5) != 0) )
  {
    v6 = pAllocator->AllocNamedChunk(v1->ptr_C, 0x8000u, "DMAP");
    v1->ptr_C = v6;
    result = v6 != 0;
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (0047CDE2) --------------------------------------------------------
void OutdoorLocation::CreateDebugLocation()
{
  OutdoorLocation *v1; // esi@1
  void *v2; // eax@1
  void *v3; // ST14_4@1
  void *v4; // eax@1
  void *v5; // ST14_4@1
  void *v6; // eax@1
  unsigned int v7; // eax@1
  char v8; // zf@1

  v1 = this;
  strcpy(this->pLevelFilename, "blank");
  strcpy(v1->pLocationFileName, "i6.odm");
  strcpy(v1->pLocationFileDescription, "MM6 Outdoor v1.00");
  v1->uNumBModels = 0;
  v1->pTileTypes[0].uTileGroup = 0;
  v1->pTileTypes[1].uTileGroup = 5;
  v1->pTileTypes[2].uTileGroup = 6;
  v1->pTileTypes[3].uTileGroup = 10;
  v1->_47F420();
  v1->_47F3EA();
  pAllocator->FreeChunk(v1->pBModels);
  pAllocator->FreeChunk(v1->pSpawnPoints);
  v1->pBModels = 0;
  v1->pSpawnPoints = 0;
  v1->pTerrain.Initialize();
  v1->pTerrain.ZeroLandscape();
  v1->pTerrain._47C80A(0, 0, 128, 128);
  pAllocator->FreeChunk(v1->ptr_D4);
  v1->ptr_D4 = 0;
  v2 = pAllocator->AllocNamedChunk(0, 0x8000u, "CMAP");
  v3 = v1->pOMAP;
  v1->ptr_D4 = v2;
  pAllocator->FreeChunk(v3);
  v1->pOMAP = 0;
  v4 = pAllocator->AllocNamedChunk(0, 0x10000u, "OMAP");
  v1->pOMAP = (unsigned int *)v4;
  memset(v4, 0, 0x10000u);
  v5 = v1->pFaceIDLIST;
  v1->field_DC = 0;
  pAllocator->FreeChunk(v5);
  v1->pFaceIDLIST = 0;
  v6 = pAllocator->AllocNamedChunk(0, 2u, "IDLIST");
  v1->pFaceIDLIST = (unsigned __int16 *)v6;
  *(short *)v6 = 0;
  strcpy(v1->pSkyTextureName, pDefaultSkyTexture);
  v1->uSky_TextureID = pBitmaps_LOD->LoadTexture(v1->pSkyTextureName);
  strcpy(v1->pGroundTileset, byte_6BE124_cfg_textures_DefaultGroundTexture);
  v7 = pBitmaps_LOD->LoadTexture(v1->pGroundTileset);
  v8 = v1->uSky_TextureID == -1;
  v1->uMainTile_BitmapID = v7;
  if ( v8 )
    Abortf("Invalid Sky Tex Handle");
  if ( v1->uMainTile_BitmapID == -1 )
    Abortf("Invalid Ground Tex Handle");
}



//----- (0047CF9C) --------------------------------------------------------
void OutdoorLocation::Release()
{
  OutdoorLocation *v1; // esi@1
  signed int v2; // edi@1
  int v3; // ebx@2
  void *v4; // ST24_4@4
  char *v5; // ebx@4
  void **v6; // esi@4

  v1 = this;
  strcpy(this->pLevelFilename, "blank");
  strcpy(v1->pLocationFileName, "default.odm");
  strcpy(v1->pLocationFileDescription, "MM6 Outdoor v1.00");
  strcpy(v1->pSkyTextureName, "sky043");
  strcpy(v1->pGroundTileset, "hm005");
  v2 = 0;
  if ( (signed int)v1->uNumBModels > 0 )
  {
    v3 = 0;
    do
    {
      ((BSPModel *)((char *)&v1->pBModels[v3] + 68))->Release();
      ++v2;
      ++v3;
    }
    while ( v2 < (signed int)v1->uNumBModels );
  }
  v1->uNumBModels = 0;
  v4 = v1->pBModels;
  v1->uNumSpawnPoints = 0;
  pAllocator->FreeChunk(v4);
  pAllocator->FreeChunk(v1->pSpawnPoints);
  v1->pBModels = 0;
  v1->pSpawnPoints = 0;
  v1->pTerrain.Release();
  pAllocator->FreeChunk(v1->ptr_D4);
  v1->ptr_D4 = 0;
  v5 = (char *)&v1->pOMAP;
  pAllocator->FreeChunk(v1->pOMAP);
  v6 = (void **)&v1->pFaceIDLIST;
  *(int *)v5 = 0;
  pAllocator->FreeChunk(*v6);
  *v6 = 0;
  pAllocator->FreeChunk(pTerrainNormals);
  pTerrainNormals = 0;
}

//----- (0047D0A6) --------------------------------------------------------
bool OutdoorLocation::Load(char *pFilename, ODMFace *File, size_t a4, int thisa)
{
  OutdoorLocation *v5; // esi@1
  bool result; // eax@9
  bool v7; // ebx@9
  size_t v8; // eax@10
  void *v9; // eax@10
  void *v10; // eax@10
  void *v11; // eax@10
  int v12; // ebx@11
  BSPModel *v13; // eax@12
  void *v14; // eax@12
  BSPModel *v15; // ecx@12
  void *v16; // eax@12
  BSPModel *v17; // ecx@12
  BSPModel *v18; // eax@12
  __int16 v19; // ax@15
  __int16 v20; // ax@16
  int v21; // ecx@16
  ODMFace *v22; // ebx@26
  LayingItem *v23; // ecx@27
  unsigned int v24; // eax@28
  unsigned __int8 v25; // zf@28
  unsigned __int8 v26; // sf@28
  ODMFace *v27; // eax@28
  const char *i; // edx@29
  unsigned __int16 v29; // ax@33
  unsigned __int16 v30; // ax@37
  int v31; // ecx@37
  int v32; // eax@38
  void *v33; // eax@38
  TileDesc *v34; // eax@43
  unsigned int v35; // eax@43
  unsigned int v36; // edi@43
  unsigned int v37; // edi@45
  size_t v38; // eax@50
  FILE *v39; // eax@50
  unsigned int v40; // edi@56
  void *v41; // eax@56
  void *v42; // ebx@56
  const void *v43; // ebx@59
  const void *v44; // ebx@59
  unsigned int v45; // eax@59
  BSPModel *v46; // eax@59
  unsigned int v47; // ecx@59
  int v48; // ebx@60
  BSPModel *v49; // eax@61
  BSPModel *v50; // eax@61
  BSPModel *v51; // eax@61
  BSPModel *v52; // eax@61
  BSPModel *v53; // eax@61
  BSPModel *v54; // ecx@61
  BSPModel *v55; // ecx@61
  BSPModel *v56; // ecx@61
  void *v57; // ST24_4@61
  BSPModel *v58; // ecx@61
  void *v59; // ST18_4@61
  BSPModel *v60; // eax@61
  __int16 v61; // ax@64
  unsigned __int16 v62; // ax@65
  ODMFace *v63; // ecx@65
  unsigned __int16 v64; // ax@80
  const char *v65; // ecx@80
  int v66; // eax@81
  void *v67; // eax@81
  int v68; // ecx@81
  void *v69; // eax@81
  unsigned int v70; // eax@81
  SpawnPointMM7 *v71; // eax@81
  unsigned int v72; // ecx@81
  size_t v73; // eax@81
  int v74; // edi@87
  void *v75; // edi@88
  unsigned int v76; // edx@94
  int v77; // ecx@94
  char *v78; // eax@95
  unsigned int v79; // edx@97
  unsigned int v80; // eax@99
  int v81; // eax@107
  void *v82; // edi@114
  size_t v83; // eax@120
  const void *v84; // edi@120
  const void *v85; // edi@120
  BSPModel *v86; // eax@124
  unsigned int v87; // eax@124
  BSPModel *v88; // eax@126
  BSPModel *v89; // eax@127
  ODMFace *v90; // eax@129
  const void *v91; // edi@138
  const void *v92; // edi@141
  const void *v93; // edi@141
  const void *v94; // edi@144
  const void *v95; // edi@144
  const char *v96; // edi@147
  unsigned int v97; // eax@147
  TileDesc *v98; // eax@147
  unsigned int v99; // eax@147
  int v100; // ecx@150
  unsigned int v101; // eax@157
  int v102; // edi@159
  void *v103; // [sp-14h] [bp-B94h]@55
  void *v104; // [sp-10h] [bp-B90h]@59
  size_t v105; // [sp-Ch] [bp-B8Ch]@59
  char *v106; // [sp-8h] [bp-B88h]@59
  int v107; // [sp-4h] [bp-B84h]@12
  int v108; // [sp+0h] [bp-B80h]@10
  char Src[968]; // [sp+10h] [bp-B70h]@110
  char Dst[968]; // [sp+3D8h] [bp-7A8h]@50
  char Str[256]; // [sp+7A0h] [bp-3E0h]@50
  char DstBuf; // [sp+8A0h] [bp-2E0h]@10
  __int32 Offset; // [sp+8A4h] [bp-2DCh]@10
  __int32 v114; // [sp+8B0h] [bp-2D0h]@10
  __int32 v115; // [sp+8BCh] [bp-2C4h]@10
  __int32 v116; // [sp+8C8h] [bp-2B8h]@10
  __int32 v117; // [sp+8D4h] [bp-2ACh]@10
  __int32 v118; // [sp+8E0h] [bp-2A0h]@10
  __int32 v119; // [sp+8ECh] [bp-294h]@10
  __int32 v120; // [sp+8F8h] [bp-288h]@10
  __int32 v121; // [sp+904h] [bp-27Ch]@10
  __int32 v122; // [sp+910h] [bp-270h]@10
  __int32 v123; // [sp+91Ch] [bp-264h]@10
  __int32 v124; // [sp+928h] [bp-258h]@26
  __int32 v125; // [sp+934h] [bp-24Ch]@35
  __int32 v126; // [sp+940h] [bp-240h]@38
  __int32 v127; // [sp+94Ch] [bp-234h]@38
  __int32 v128; // [sp+958h] [bp-228h]@38
  __int32 v129; // [sp+964h] [bp-21Ch]@38
  __int32 v130; // [sp+970h] [bp-210h]@38
  __int32 v131; // [sp+97Ch] [bp-204h]@38
  __int32 v132; // [sp+988h] [bp-1F8h]@38
  __int32 v133; // [sp+994h] [bp-1ECh]@38
  __int32 v134; // [sp+9A0h] [bp-1E0h]@38
  __int32 v135; // [sp+9ACh] [bp-1D4h]@38
  __int32 v136; // [sp+9D0h] [bp-1B0h]@10
  char FileName[8]; // [sp+A20h] [bp-160h]@8
  char v138; // [sp+A28h] [bp-158h]@12
  int v139; // [sp+B1Ch] [bp-64h]@10
  char pContainer[32]; // [sp+B20h] [bp-60h]@1
  int *v141; // [sp+B40h] [bp-40h]@50
  __int64 v142; // [sp+B44h] [bp-3Ch]@55
  size_t pSource; // [sp+B4Ch] [bp-34h]@56
  int v144; // [sp+B50h] [bp-30h]@61
  int v145; // [sp+B54h] [bp-2Ch]@68
  ODMHeader header; // [sp+B58h] [bp-28h]@50
  unsigned int pDestLen; // [sp+B68h] [bp-18h]@13
  FILE *ptr; // [sp+B6Ch] [bp-14h]@12
  void *v149; // [sp+B70h] [bp-10h]@19
  char *Str2; // [sp+B74h] [bp-Ch]@12
  int v151; // [sp+B78h] [bp-8h]@59
  void *uSourceLen; // [sp+B7Ch] [bp-4h]@59

  v5 = this;
  strcpy(pContainer, pFilename);
  if ( bUnderwater )
  {
    pPaletteManager->field_267AD3 = 0x10u;
    pPaletteManager->field_267AD4 = 0xC2u;
    pPaletteManager->field_267AD5 = 0x99u;
    pPaletteManager->field_267AD0 = 0x25u;
    pPaletteManager->field_267AD1 = 0x8Fu;
    pPaletteManager->field_267AD2 = 0x5Cu;
LABEL_7:
    pPaletteManager->RecalculateAll();
    goto LABEL_8;
  }
  pPaletteManager->field_267AD3 = 0;
  pPaletteManager->field_267AD4 = 0;
  pPaletteManager->field_267AD5 = 0;
  if ( pPaletteManager->field_267AD0 != 0x80u
    || pPaletteManager->field_267AD1 != 0x80u
    || pPaletteManager->field_267AD2 != 0x80u )
  {
    pPaletteManager->field_267AD0 = 0x80u;
    pPaletteManager->field_267AD1 = 0x80u;
    pPaletteManager->field_267AD2 = 0x80u;
    goto LABEL_7;
  }
LABEL_8:
  _6807E0_num_decorations_6807B8 = 0;
  sprintfex(FileName, "levels\\%s", pContainer);
  if ( GetFileAttributesA(FileName) != -1 )
  {
    result = (bool)fopen(FileName, "rb");
    v7 = result;
    File = (ODMFace *)result;
    if ( !result )
      return result;
    *(int *)thisa = 1;
    v8 = strlen(pContainer);
    v108 = 2;
    *((char *)&v139 + v8) = 0;
    viewparams->uTextureID_LocationMap = pIcons_LOD->LoadTexture(
                                          pContainer,
                                          (enum TEXTURE_TYPE)v108);
    fread(&DstBuf, 0x180u, 1u, (FILE *)v7);
    fseek((FILE *)v7, Offset, 0);
    fread(v5, 0xB0u, 1u, (FILE *)v7);
    v5->_47F420();
    v5->_47F3EA();
    strcpy(v5->pGroundTileset, "grastyl");
    fseek((FILE *)v7, v114, 0);
    fread(&v5->uNumBModels, 4u, 1u, (FILE *)v7);
    fseek((FILE *)v7, v115, 0);
    fread(&uNumLayingItems, 4u, 1u, (FILE *)v7);
    fseek((FILE *)v7, v116, 0);
    fread(&uNumLevelDecorations, 4u, 1u, (FILE *)v7);
    fseek((FILE *)v7, v117, 0);
    fread(&uNumActors, 4u, 1u, (FILE *)v7);
    fseek((FILE *)v7, v118, 0);
    fread(&uNumChests, 4u, 1u, (FILE *)v7);
    v5->pTerrain.Initialize();
    fseek((FILE *)v7, v119, 0);
    fread(v5->pTerrain.pHeightmap, 1u, 0x4000u, (FILE *)v7);
    fseek((FILE *)v7, v120, 0);
    fread(v5->pTerrain.pTilemap, 1u, 0x4000u, (FILE *)v7);
    fseek((FILE *)v7, v121, 0);
    fread(v5->pTerrain.pAttributemap, 1u, 0x4000u, (FILE *)v7);
    v5->pTerrain._47C80A(0, 0, 128, 128);
    pAllocator->FreeChunk(v5->ptr_D4);
    v5->ptr_D4 = 0;
    v9 = pAllocator->AllocNamedChunk(0, 0x8000u, "CMAP");
    v108 = (int)v5->pOMAP;
    v5->ptr_D4 = v9;
    pAllocator->FreeChunk((void *)v108);
    v5->pOMAP = 0;
    v10 = pAllocator->AllocNamedChunk(0, 0x10000u, "OMAP");
    v108 = 0;
    v5->pOMAP = (unsigned int *)v10;
    fseek((FILE *)v7, v136, v108);
    fread(&uNumTerrainNormals, 4u, 1u, (FILE *)v7);
    fread(pTerrainSomeOtherData, 1u, 0x20000u, (FILE *)v7);
    fread(pTerrainNormalIndices, 1u, 0x10000u, (FILE *)v7);
    pTerrainNormals = (Vec3_float_ *)pAllocator->AllocNamedChunk(
                                       pTerrainNormals,
                                       12 * uNumTerrainNormals,
                                       "TerNorm");
    fread(pTerrainNormals, 1u, 12 * uNumTerrainNormals, (FILE *)v7);
    v11 = pAllocator->AllocNamedChunk(v5->pBModels, 188 * v5->uNumBModels, "BDdata");
    v108 = 0;
    v5->pBModels = (BSPModel *)v11;
    fseek((FILE *)v7, v122, v108);
    fread(v5->pBModels, 0xBCu, v5->uNumBModels, (FILE *)v7);
    fseek((FILE *)v7, v123, 0);
    a4 = 0;
    if ( (signed int)v5->uNumBModels > 0 )
    {
      v12 = 0;
      while ( 1 )
      {
        v5->pBModels[v12].pVertices.pVertices = 0;
        v5->pBModels[v12].pFaces = 0;
        v5->pBModels[v12].pFacesOrdering = 0;
        v5->pBModels[v12].pNodes = 0;
        FileName[0] = 0;
        v108 = (int)&v5->pBModels[v12];
        sprintfex(FileName, "%s", v108);
        v13 = v5->pBModels;
        v138 = 0;
        v5->pBModels[v12].pVertices.pVertices = (Vec3_int_ *)pAllocator->AllocNamedChunk(
                                                               v13[v12].pVertices.pVertices,
                                                               12 * v13[v12].pVertices.uNumVertices,
                                                               FileName);
        v5->pBModels[v12].pFaces = (ODMFace *)pAllocator->AllocNamedChunk(
                                                v5->pBModels[v12].pFaces,
                                                308 * v5->pBModels[v12].uNumFaces,
                                                FileName);
        v5->pBModels[v12].pFacesOrdering = (unsigned __int16 *)pAllocator->AllocNamedChunk(
                                                                 v5->pBModels[v12].pFacesOrdering,
                                                                 2 * v5->pBModels[v12].uNumFaces,
                                                                 FileName);
        v14 = pAllocator->AllocNamedChunk(
                v5->pBModels[v12].pNodes,
                8 * v5->pBModels[v12].uNumNodes,
                FileName);
        v15 = v5->pBModels;
        v108 = (int)File;
        v15[v12].pNodes = (BSPNode *)v14;
        fread(v5->pBModels[v12].pVertices.pVertices, 0xCu, v5->pBModels[v12].pVertices.uNumVertices, (FILE *)v108);
        fread(v5->pBModels[v12].pFaces, 0x134u, v5->pBModels[v12].uNumFaces, (FILE *)File);
        fread(v5->pBModels[v12].pFacesOrdering, 2u, v5->pBModels[v12].uNumFaces, (FILE *)File);
        fread(v5->pBModels[v12].pNodes, 8u, v5->pBModels[v12].uNumNodes, (FILE *)File);
        v16 = malloc(10 * v5->pBModels[v12].uNumFaces);
        v107 = (int)File;
        v17 = v5->pBModels;
        ptr = (FILE *)v16;
        fread(v16, 0xAu, v17[v12].uNumFaces, (FILE *)File);
        v18 = v5->pBModels;
        Str2 = 0;
        if ( (signed int)v18[v12].uNumFaces > 0 )
          break;
LABEL_25:
        free(ptr);
        ++a4;
        ++v12;
        if ( (signed int)a4 >= (signed int)v5->uNumBModels )
          goto LABEL_26;
      }
      pDestLen = 0;
      pFilename = (char *)ptr;
      while ( 1 )
      {
        thisa = (int)((char *)v18[v12].pFaces + pDestLen);
        if ( !(*(char *)(thisa + 29) & 0x40) )
          break;
        v19 = pTextureFrameTable->FindTextureByName(pFilename);
        *(short *)(thisa + 272) = v19;
        if ( !v19 )
        {
          v20 = pBitmaps_LOD->LoadTexture(pFilename);
          v21 = thisa;
          *(char *)(v21 + 29) &= 0xBFu;
LABEL_19:
          *(short *)(v21 + 272) = v20;
          v149 = (void *)(v20 != -1 ? &pBitmaps_LOD->pTextures[v20] : 0);
          auto pTex = (Texture *)v149;
          if (pTex)
            pTex->palette = pPaletteManager->LoadPalette(pTex->palette);
          goto LABEL_20;
        }
        pTextureFrameTable->LoadAnimationSequenceAndPalettes(
          *(unsigned __int16 *)((char *)&v5->pBModels[v12].pFaces->uTextureID + pDestLen));
LABEL_20:
        if ( *(short *)(thisa + 292) )
        {
          if ( ((ODMFace *)thisa)->HasEventHint() )
            *(char *)(thisa + 30) |= 0x10u;
          else
            *(char *)(thisa + 30) &= 0xEFu;
        }
        ++Str2;
        v18 = v5->pBModels;
        pDestLen += 308;
        pFilename += 10;
        if ( (signed int)Str2 >= (signed int)v18[v12].uNumFaces )
          goto LABEL_25;
      }
      v20 = pBitmaps_LOD->LoadTexture(pFilename);
      v21 = thisa;
      goto LABEL_19;
    }
LABEL_26:
    v22 = File;
    fseek((FILE *)File, v124, 0);
    fread(pLayingItems, 0x70u, uNumLayingItems, (FILE *)v22);
    if ( (signed int)uNumLayingItems > 0 )
    {
      v23 = pLayingItems;
      a4 = uNumLayingItems;
      do
      {
        v24 = v23->stru_24.uItemID;
        thisa = 0;
        v27 = (ODMFace *)(48 * v24);
        v25 = pObjectList->uNumObjects == 0;
        v26 = (pObjectList->uNumObjects & 0x80000000u) != 0;
        LOWORD(v27) = *(short *)((char *)&v27->pFacePlane.vNormal.x + (int)((char *)&pItemsTable + 24));
        File = v27;
        v23->uItemType = (unsigned __int16)v27;
        if ( v26 | v25 )
        {
LABEL_33:
          v29 = 0;
        }
        else
        {
          for ( i = (const char *)&pObjectList->pObjects->uObjectID; (short)v27 != *(short *)i; i = pFilename )
          {
            ++thisa;
            pFilename = (char *)i + 56;
            if ( thisa >= (signed int)pObjectList->uNumObjects )
              goto LABEL_33;
            LOWORD(v27) = (short)File;
          }
          v29 = thisa;
        }
        v23->uObjectDescID = v29;
        ++v23;
        --a4;
      }
      while ( a4 );
    }
    fseek((FILE *)v22, v125, 0);
    fread(pLevelDecorations, 0x20u, uNumLevelDecorations, (FILE *)v22);
    a4 = 0;
    if ( (signed int)uNumLevelDecorations > 0 )
    {
      thisa = (int)pLevelDecorations;
      do
      {
        fread(FileName, 1u, 0x20u, (FILE *)v22);
        v30 = pDecorationList->GetDecorIdByName(FileName);
        v31 = thisa;
        ++a4;
        thisa += 32;
        *(short *)v31 = v30;
      }
      while ( (signed int)a4 < (signed int)uNumLevelDecorations );
    }
    fseek((FILE *)v22, v126, 0);
    fread(pActors, 0x344u, uNumActors, (FILE *)v22);
    fseek((FILE *)v22, v127, 0);
    fread(pChests, 0x14CCu, uNumChests, (FILE *)v22);
    fseek((FILE *)v22, v128, 0);
    fread(&v5->field_DC, 4u, 1u, (FILE *)v22);
    pAllocator->FreeChunk(v5->pFaceIDLIST);
    v32 = v5->field_DC;
    v5->pFaceIDLIST = 0;
    v33 = pAllocator->AllocNamedChunk(0, 2 * v32, "IDLIST");
    v108 = (int)v22;
    v5->pFaceIDLIST = (unsigned __int16 *)v33;
    fread(v33, 2u, v5->field_DC, (FILE *)v108);
    fseek((FILE *)v22, v129, 0);
    fread(v5->pOMAP, 4u, 0x4000u, (FILE *)v22);
    fseek((FILE *)v22, v130, 0);
    fread(&v5->uNumSpawnPoints, 4u, 1u, (FILE *)v22);
    v5->pSpawnPoints = (SpawnPointMM7 *)pAllocator->AllocNamedChunk(
                                          v5->pSpawnPoints,
                                          24 * v5->uNumSpawnPoints,
                                          "Spawn");
    fseek((FILE *)v22, v131, 0);
    fread(v5->pSpawnPoints, 0x18u, v5->uNumSpawnPoints, (FILE *)v22);
    fseek((FILE *)v22, v132, 0);
    fread(&v5->ddm, 0x28u, 1u, (FILE *)v22);
    fseek((FILE *)v22, v133, 0);
    fread(&stru_5E4C90, 1u, 0xC8u, (FILE *)v22);
    fseek((FILE *)v22, v134, 0);
    fread(&v5->uLastVisitDay, 1u, 0x38u, (FILE *)v22);
    fseek((FILE *)v22, v135, 0);
    fread(&v5->uLastVisitDay, 1u, 4u, (FILE *)v22);
    thisa = (int)v5->pTileTypes;
    pTileTable->InitializeTileset(4);
    pTileTable->InitializeTileset(v5->pTileTypes[0].uTileGroup);
    pTileTable->InitializeTileset(v5->pTileTypes[1].uTileGroup);
    pTileTable->InitializeTileset(v5->pTileTypes[2].uTileGroup);
    pTileTable->InitializeTileset(v5->pTileTypes[3].uTileGroup);
    if ( v5 != (OutdoorLocation *)-96 && v5->pSkyTextureName[0] )
    {
      v108 = 0;
      v107 = (int)v5->pSkyTextureName;
    }
    else
    {
      v108 = 0;
      v107 = (int)pDefaultSkyTexture;
    }
    v5->uSky_TextureID = pBitmaps_LOD->LoadTexture((const char *)v107, (enum TEXTURE_TYPE)v108);
    strcpy(v5->pGroundTileset, byte_6BE124_cfg_textures_DefaultGroundTexture);
    v34 = pTileTable->GetTileById(v5->pTileTypes[0].uTileID);
    v35 = pBitmaps_LOD->LoadTexture(v34->pTileName);
    v36 = v5->uSky_TextureID;
    v5->uMainTile_BitmapID = v35;
    if ( v36 != -1 )
      HIWORD(pBitmaps_LOD->pTextures[v36].palette) = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v36].palette);

    v37 = v5->uMainTile_BitmapID;
    if ( v37 != -1 )
      HIWORD(pBitmaps_LOD->pTextures[v37].palette) = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v37].palette);

    v5->_47F0E2();
    pGameLoadingUI_ProgressBar->Progress();
    fclose((FILE *)v22);
    goto LABEL_150;
  }
  if ( !pGames_LOD->DoesContainerExist(pContainer) )
    Abortf("Unable to find %s in Games.LOD", pContainer);
  strcpy(FileName, pContainer);
  strcpy(Str, pContainer);
  Dst[strlen(Str) + 964] = 0;
  viewparams->uTextureID_LocationMap = pIcons_LOD->LoadTexture(Str, TEXTURE_16BIT_PALETTE);
  v141 = &v139;
  v38 = strlen(pContainer);
  strcpy((char *)&v139 + v38, ".odm");
  v39 = pGames_LOD->FindContainer(pContainer, 1);
  header.uCompressedSize = 0;
  header.uDecompressedSize = 0;
  ptr = v39;
  header.uVersion = 91969;
  header.pMagic[0] = 'm';
  header.pMagic[1] = 'v';
  header.pMagic[2] = 'i';
  header.pMagic[3] = 'i';
  fread(&header, 0x10u, 1u, v39);
  if ( header.uVersion != 91969
    || header.pMagic[0] != 'm'
    || header.pMagic[1] != 'v'
    || header.pMagic[2] != 'i'
    || header.pMagic[3] != 'i' )
  {
          MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:507", 0);
  }
  v40 = header.uCompressedSize;
  pSource = header.uDecompressedSize;
  v41 = malloc(header.uDecompressedSize);
  v42 = v41;
  HIDWORD(v142) = (uint32)v41;
  if ( v40 < pSource )
  {
    pFilename = (char *)malloc(v40);
    fread((void *)pFilename, v40, 1u, ptr);
    zlib::MemUnzip(v42, &pSource, pFilename, v40);
    free((void *)pFilename);
  }
  else
  {
    fread(v41, pSource, 1u, ptr);
  }
  memcpy(v5, v42, 0xB0u);
  v43 = (char *)v42 + 176;
  v5->_47F420();
  v5->_47F3EA();
  strcpy(v5->pGroundTileset, "grastyl");
  pGameLoadingUI_ProgressBar->Progress();
  v5->pTerrain.Initialize();
  v108 = 16384;
  v107 = (int)v43;
  v106 = (char *)v5->pTerrain.pHeightmap;
  memcpy(v106, v43, 0x4000u);
  v43 = (char *)v43 + 16384;
  v105 = 16384;
  v104 = (void *)v43;
  v103 = v5->pTerrain.pTilemap;
  memcpy(v103, v43, 0x4000u);
  v43 = (char *)v43 + 16384;
  memcpy(v5->pTerrain.pAttributemap, v43, 0x4000u);
  v43 = (char *)v43 + 16384;
  v108 = (int)v5->ptr_D4;
  pAllocator->FreeChunk((void *)v108);
  v5->ptr_D4 = 0;
  v5->ptr_D4 = pAllocator->AllocNamedChunk(0, 0x8000u, "CMAP");
  v5->pTerrain._47C80A(0, 0, 128, 128);
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&uNumTerrainNormals, v43, 4u);
  v43 = (char *)v43 + 4;
  memcpy(pTerrainSomeOtherData, v43, 0x20000u);
  v43 = (char *)v43 + 131072;
  memcpy(pTerrainNormalIndices, v43, 0x10000u);
  v43 = (char *)v43 + 65536;
  pFilename = (char *)(12 * uNumTerrainNormals);
  pTerrainNormals = (Vec3_float_ *)pAllocator->AllocNamedChunk(
                                     pTerrainNormals,
                                     12 * uNumTerrainNormals,
                                     "TerNorm");
  memcpy(pTerrainNormals, v43, (size_t)pFilename);
  v44 = (char *)v43 + (int)pFilename;
  memcpy(&v5->uNumBModels, v44, 4u);
  v44 = (char *)v44 + 4;
  pGameLoadingUI_ProgressBar->Progress();
  v45 = v5->uNumBModels;
  v108 = (int)"BDdata";
  v107 = 188 * v45;
  v106 = (char *)v5->pBModels;
  v46 = (BSPModel *)pAllocator->AllocNamedChunk(v106, 188 * v45, "BDdata");
  v47 = v5->uNumBModels;
  v5->pBModels = v46;
  pFilename = (char *)(188 * v47);
  memcpy(v46, v44, 188 * v47);
  uSourceLen = (char *)v44 + (int)pFilename;
  pGameLoadingUI_ProgressBar->Progress();
  v151 = 0;
  if ( (signed int)v5->uNumBModels > 0 )
  {
    v48 = 0;
    while ( 1 )
    {
      v5->pBModels[v48].pVertices.pVertices = 0;
      v5->pBModels[v48].pFaces = 0;
      v5->pBModels[v48].pFacesOrdering = 0;
      v5->pBModels[v48].pNodes = 0;
      FileName[0] = 0;
      v108 = (int)&v5->pBModels[v48];
      sprintfex(FileName, "%s", v108);
      v49 = v5->pBModels;
      v138 = 0;
      v50 = &v49[v48];
      v108 = (int)FileName;
      v107 = 12 * v50->pVertices.uNumVertices;
      v106 = (char *)v50->pVertices.pVertices;
      v5->pBModels[v48].pVertices.pVertices = (Vec3_int_ *)pAllocator->AllocNamedChunk(v106, v107, FileName);
      v51 = &v5->pBModels[v48];
      v108 = (int)FileName;
      v107 = 308 * v51->uNumFaces;
      v106 = (char *)v51->pFaces;
      v5->pBModels[v48].pFaces = (ODMFace *)pAllocator->AllocNamedChunk(v106, v107, FileName);
      v52 = &v5->pBModels[v48];
      v108 = (int)FileName;
      v107 = 2 * v52->uNumFaces;
      v106 = (char *)v52->pFacesOrdering;
      v5->pBModels[v48].pFacesOrdering = (unsigned __int16 *)pAllocator->AllocNamedChunk(
                                                               v106,
                                                               v107,
                                                               FileName);
      v53 = &v5->pBModels[v48];
      v108 = (int)FileName;
      v107 = 8 * v53->uNumNodes;
      v106 = (char *)v53->pNodes;
      v5->pBModels[v48].pNodes = (BSPNode *)pAllocator->AllocNamedChunk(v106, v107, FileName);
      v54 = &v5->pBModels[v48];
      v108 = 12 * v54->pVertices.uNumVertices;
      pFilename = (char *)v108;
      v107 = (int)uSourceLen;
      v106 = (char *)v54->pVertices.pVertices;
      memcpy(v106, uSourceLen, v108);
      uSourceLen = (char *)uSourceLen + (int)pFilename;
      v55 = &v5->pBModels[v48];
      v105 = 308 * v55->uNumFaces;
      v104 = uSourceLen;
      v103 = v55->pFaces;
      pFilename = (char *)v105;
      memcpy(v103, uSourceLen, v105);
      v56 = &v5->pBModels[v48];
      uSourceLen = (char *)uSourceLen + (int)pFilename;
      v57 = v56->pFacesOrdering;
      pFilename = (char *)(2 * v56->uNumFaces);
      memcpy(v57, uSourceLen, (size_t)pFilename);
      v58 = &v5->pBModels[v48];
      uSourceLen = (char *)uSourceLen + (int)pFilename;
      v59 = v58->pNodes;
      pFilename = (char *)(8 * v58->uNumNodes);
      memcpy(v59, uSourceLen, (size_t)pFilename);
      uSourceLen = (char *)uSourceLen + (int)pFilename;
      ptr = (FILE *)malloc(10 * v5->pBModels[v48].uNumFaces);
      pFilename = (char *)(10 * v5->pBModels[v48].uNumFaces);
      memcpy(ptr, uSourceLen, (size_t)pFilename);
      v144 = 0;
      uSourceLen = (char *)uSourceLen + (int)pFilename;
      v60 = v5->pBModels;
      if ( (signed int)v60[v48].uNumFaces > 0 )
        break;
LABEL_74:
      free(ptr);
      ++v151;
      ++v48;
      if ( v151 >= (signed int)v5->uNumBModels )
        goto LABEL_75;
    }
    v149 = 0;
    Str2 = (char *)ptr;
    while ( 1 )
    {
      pFilename = (char *)v149 + (unsigned int)v60[v48].pFaces;
      if ( !(pFilename[29] & 0x40) )
        break;
      v61 = pTextureFrameTable->FindTextureByName(Str2);
      *((short *)pFilename + 136) = v61;
      if ( !v61 )
      {
        v62 = pBitmaps_LOD->LoadTexture(Str2);
        v63 = (ODMFace *)pFilename;
        BYTE1(v63->uFaceAttributes) &= 0xBFu;
LABEL_68:
        v63->uTextureID = v62;
        v145 = (signed __int16)v62 != -1 ? (int)&pBitmaps_LOD->pTextures[(signed __int16)v62] : 0;
        v108 = ((signed __int16)v62 != -1 ? LOWORD(pBitmaps_LOD->pTextures[(signed __int16)v62].palette) : 36);
        if ((signed __int16)v62 != -1)
          HIWORD(pBitmaps_LOD->pTextures[v62].palette) = pPaletteManager->LoadPalette(v108);
        goto LABEL_69;
      }
      v108 = *(unsigned __int16 *)((char *)&v5->pBModels[v48].pFaces->uTextureID + (unsigned int)v149);
      pTextureFrameTable->LoadAnimationSequenceAndPalettes(v108);
LABEL_69:
      if ( *((short *)pFilename + 146) )
      {
        if ( ((ODMFace *)pFilename)->HasEventHint() )
          pFilename[30] |= 0x10u;
        else
          pFilename[30] &= 0xEFu;
      }
      ++v144;
      v60 = v5->pBModels;
      v149 = (char *)v149 + 308;
      Str2 += 10;
      if ( v144 >= (signed int)v60[v48].uNumFaces )
        goto LABEL_74;
    }
    v62 = pBitmaps_LOD->LoadTexture(Str2);
    v63 = (ODMFace *)pFilename;
    goto LABEL_68;
  }
LABEL_75:
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&uNumLevelDecorations, uSourceLen, 4u);
  uSourceLen = (char *)uSourceLen + 4;
  if ( (uNumLevelDecorations & 0x80000000u) != 0 || (signed int)uNumLevelDecorations > 3000 )
  {
          MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:678", 0);
  }
  pGameLoadingUI_ProgressBar->Progress();
  pFilename = (char *)(32 * uNumLevelDecorations);
  memcpy(pLevelDecorations, uSourceLen, 32 * uNumLevelDecorations);
  v151 = 0;
  uSourceLen = (char *)uSourceLen + (int)pFilename;
  if ( (signed int)uNumLevelDecorations > 0 )
  {
    pFilename = (char *)pLevelDecorations;
    do
    {
      memcpy(FileName, uSourceLen, 0x20u);
      uSourceLen = (char *)uSourceLen + 32;
      v64 = pDecorationList->GetDecorIdByName(FileName);
      v65 = pFilename;
      ++v151;
      pFilename += 32;
      *(short *)v65 = v64;
    }
    while ( v151 < (signed int)uNumLevelDecorations );
  }
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&v5->field_DC, uSourceLen, 4u);
  uSourceLen = (char *)uSourceLen + 4;
  v108 = (int)v5->pFaceIDLIST;
  pAllocator->FreeChunk((void *)v108);
  v66 = v5->field_DC;
  v5->pFaceIDLIST = 0;
  v67 = pAllocator->AllocNamedChunk(0, 2 * v66, "IDLIST");
  v68 = v5->field_DC;
  v5->pFaceIDLIST = (unsigned __int16 *)v67;
  pFilename = (char *)(2 * v68);
  memcpy(v67, uSourceLen, 2 * v68);
  uSourceLen = (char *)uSourceLen + (int)pFilename;
  pGameLoadingUI_ProgressBar->Progress();
  v108 = (int)v5->pOMAP;
  pAllocator->FreeChunk((void *)v108);
  v5->pOMAP = 0;
  v69 = pAllocator->AllocNamedChunk(0, 0x10000u, "OMAP");
  v108 = 65536;
  v5->pOMAP = (unsigned int *)v69;
  memcpy(v69, uSourceLen, v108);
  uSourceLen = (char *)uSourceLen + 65536;
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&v5->uNumSpawnPoints, uSourceLen, 4u);
  uSourceLen = (char *)uSourceLen + 4;
  pGameLoadingUI_ProgressBar->Progress();
  v70 = v5->uNumSpawnPoints;
  v108 = (int)"Spawn";
  v107 = 24 * v70;
  v106 = (char *)v5->pSpawnPoints;
  v71 = (SpawnPointMM7 *)pAllocator->AllocNamedChunk(v106, 24 * v70, "Spawn");
  v72 = v5->uNumSpawnPoints;
  v5->pSpawnPoints = v71;
  memcpy(v71, uSourceLen, 24 * v72);
  pGameLoadingUI_ProgressBar->Progress();
  free((void *)HIDWORD(v142));
  v108 = (int)".ddm";
  v73 = strlen(pContainer);
  strcpy((char *)v141 + v73, (const char *)v108);
  v151 = (int)pNew_LOD->FindContainer(pContainer, 1);
  fread(&header, 0x10u, 1u, (FILE *)v151);
  Str2 = 0;
  if ( header.uVersion != 91969
    || header.pMagic[0] != 'm'
    || header.pMagic[1] != 'v'
    || header.pMagic[2] != 'i'
    || header.pMagic[3] != 'i' )
  {
          MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:746", 0);
    Str2 = (char *)1;
  }
  v74 = 0;
  pFilename = (char *)header.uCompressedSize;
  v149 = 0;
  pDestLen = header.uDecompressedSize;
  if ( !Str2 )
  {
    v75 = malloc(header.uDecompressedSize);
    v149 = v75;
    if ( (unsigned int)pFilename <= pDestLen )
    {
      if ( pFilename == (const char *)pDestLen )
      {
        fread(v75, pDestLen, 1u, (FILE *)v151);
      }
      else
      {
        uSourceLen = malloc((size_t)pFilename);
        fread(uSourceLen, (size_t)pFilename, 1u, (FILE *)v151);
        zlib::MemUnzip(v75, &pDestLen, uSourceLen, (unsigned int)pFilename);
        free(uSourceLen);
      }
    }
    else
    {
          MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:765", 0);
    }
    memcpy(&v5->ddm, v75, 0x28u);
    v74 = (int)((char *)v75 + 40);
  }
  v76 = v5->uNumBModels;
  v77 = 0;
  if ( (signed int)v76 > 0 )
  {
    v78 = (char *)&v5->pBModels->uNumFaces;
    do
    {
      v77 += *(int *)v78;
      v78 += 188;
      --v76;
    }
    while ( v76 );
  }
  v79 = v5->ddm.uNumFacesInBModels;
  if ( v79 )
  {
    if ( v5->ddm.uNumBModels )
    {
      v80 = v5->ddm.uNumDecorations;
      if ( v80 )
      {
        if ( v79 != v77 || v5->ddm.uNumBModels != v5->uNumBModels || v80 != uNumLevelDecorations )
          Str2 = (char *)1;
      }
    }
  }
  if ( BYTE1(dword_6BE364_game_settings_1) & 0x20 )
    a4 = 29030400;
  if ( Str2 )
  {
    memset(Dst, 0, 0x3C8u);
    memset(Src, 0, 0x3C8u);
    goto LABEL_112;
  }
  v81 = v5->ddm.uLastRepawnDay;
  if ( (unsigned int)((char *)File - v81) >= a4 || !v81 )
  {
    memcpy(Dst, (const void *)v74, 0x3C8u);
    memcpy(Src, (const void *)(v74 + 968), 0x3C8u);
LABEL_112:
    free(v149);
    v25 = Str2 == 0;
    v5->ddm.uLastRepawnDay = (int)File;
    if ( v25 )
      ++v5->ddm.uNumRespawns;
    v108 = 0;
    *(int *)thisa = 1;
    v151 = (int)pGames_LOD->FindContainer(pContainer, v108);
    fread(&header, 0x10u, 1u, (FILE *)v151);
    pFilename = (char *)header.uCompressedSize;
    pDestLen = header.uDecompressedSize;
    v82 = malloc(header.uDecompressedSize);
    v149 = v82;
    if ( (unsigned int)pFilename <= pDestLen )
    {
      if ( pFilename == (const char *)pDestLen )
      {
        fread(v82, pDestLen, 1u, (FILE *)v151);
      }
      else
      {
        uSourceLen = malloc((size_t)pFilename);
        fread(uSourceLen, (size_t)pFilename, 1u, (FILE *)v151);
        zlib::MemUnzip(v82, &pDestLen, uSourceLen, (unsigned int)pFilename);
        free(uSourceLen);
      }
    }
    else
    {
          MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:857", 0);
    }
    v74 = (int)((char *)v82 + 40);
    goto LABEL_120;
  }
  *(int *)thisa = 0;
LABEL_120:
  v108 = (int)".odm";
  v83 = strlen(pContainer);
  strcpy((char *)v141 + v83, (const char *)v108);
  memcpy(v5->array_528, (const void *)v74, 0x3C8u);
  v84 = (const void *)(v74 + 968);
  memcpy(v5->array_8F0, v84, 0x3C8u);
  v85 = (char *)v84 + 968;
  pGameLoadingUI_ProgressBar->Progress();
  if ( *(int *)thisa )
  {
    memcpy(v5->array_528, Dst, 0x3C8u);
    memcpy(v5->array_8F0, Src, 0x3C8u);
  }
  v25 = v5->uNumBModels == 0;
  v26 = (v5->uNumBModels & 0x80000000u) != 0;
  v151 = 0;
  if ( !(v26 | v25) )
  {
    a4 = 0;
    do
    {
      v86 = v5->pBModels;
      thisa = 0;
      v87 = (unsigned int)((char *)v86 + a4);
      if ( *(int *)(v87 + 76) > 0 )
      {
        File = 0;
        do
        {
          v106 = (char *)&File->uFaceAttributes + *(int *)(v87 + 84);
          memcpy(v106, v85, 4u);
          v88 = v5->pBModels;
          ++File;
          v85 = (char *)v85 + 4;
          ++thisa;
          v87 = (unsigned int)((char *)v88 + a4);
        }
        while ( thisa < *(int *)(v87 + 76) );
      }
      v89 = v5->pBModels;
      thisa = 0;
      if ( *(signed int *)((char *)&v89->uNumFaces + a4) > 0 )
      {
        pFilename = 0;
        do
        {
          v90 = (ODMFace *)&pFilename[*(unsigned int *)((char *)&v89->pFaces + a4)];
          File = v90;
          if ( v90->sCogTriggeredID )
          {
            if ( v90->HasEventHint() )
              BYTE2(File->uFaceAttributes) |= 0x10u;
            else
              BYTE2(File->uFaceAttributes) &= 0xEFu;
          }
          ++thisa;
          v89 = v5->pBModels;
          pFilename += 308;
        }
        while ( thisa < *(signed int *)((char *)&v89->uNumFaces + a4) );
      }
      ++v151;
      a4 += 188;
    }
    while ( v151 < (signed int)v5->uNumBModels );
  }
  pGameLoadingUI_ProgressBar->Progress();
  v151 = 0;
  if ( (signed int)uNumLevelDecorations > 0 )
  {
    thisa = (int)&pLevelDecorations[0].field_2;
    do
    {
      memcpy((void *)thisa, v85, 2u);
      thisa += 32;
      v85 = (char *)v85 + 2;
      ++v151;
    }
    while ( v151 < (signed int)uNumLevelDecorations );
  }
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&uNumActors, v85, 4u);
  v91 = (char *)v85 + 4;
  if ( (uNumActors & 0x80000000u) != 0 || (signed int)uNumActors > 500 )
  {
          MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:939", 0);
  }
  pGameLoadingUI_ProgressBar->Progress();
  pFilename = (char *)(836 * uNumActors);
  memcpy(pActors, v91, 836 * uNumActors);
  v92 = (char *)v91 + (int)pFilename;
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&uNumLayingItems, v92, 4u);
  v93 = (char *)v92 + 4;
  if ( (uNumLayingItems & 0x80000000u) != 0 || (signed int)uNumLayingItems > 1000 )
  {
          MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:954", 0);
  }
  pGameLoadingUI_ProgressBar->Progress();
  pFilename = (char *)(112 * uNumLayingItems);
  memcpy(pLayingItems, v93, 112 * uNumLayingItems);
  v94 = (char *)v93 + (int)pFilename;
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&uNumChests, v94, 4u);
  v95 = (char *)v94 + 4;
  if ( (uNumChests & 0x80000000u) != 0 || (signed int)uNumChests > 20 )
  {
          MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:968", 0);
  }
  pGameLoadingUI_ProgressBar->Progress();
  pFilename = (char *)(5324 * uNumChests);
  memcpy(pChests, v95, 5324 * uNumChests);
  v96 = (char *)v95 + (int)pFilename;
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&stru_5E4C90, v96, 0xC8u);
  pGameLoadingUI_ProgressBar->Progress();
  memcpy(&v5->uLastVisitDay, v96 + 200, 0x38u);
  free(v149);
  pTileTable->InitializeTileset(4);
  thisa = (int)v5->pTileTypes;
  v108 = v5->pTileTypes[0].uTileGroup;
  pTileTable->InitializeTileset(v108);
  v108 = v5->pTileTypes[1].uTileGroup;
  pTileTable->InitializeTileset(v108);
  v108 = v5->pTileTypes[2].uTileGroup;
  pTileTable->InitializeTileset(v108);
  v108 = v5->pTileTypes[3].uTileGroup;
  pTileTable->InitializeTileset(v108);
  strcpy(v5->pGroundTileset, byte_6BE124_cfg_textures_DefaultGroundTexture);
  v97 = v5->pTileTypes[0].uTileID;
  v108 = 0;
  v98 = pTileTable->GetTileById(v97);
  v99 = pBitmaps_LOD->LoadTexture(v98->pTileName, (enum TEXTURE_TYPE)v108);
  v5->uMainTile_BitmapID = v99;
  if ( v99 != -1 )
  {
    v108 = *(short *)(v99 != -1 ? &pBitmaps_LOD->pTextures[v99].palette : (int *)36);
    if (v99 != -1)
      HIWORD(pBitmaps_LOD->pTextures[v99].palette) = pPaletteManager->LoadPalette(v108);
  }
  v5->_47F0E2();
LABEL_150:
  v100 = HIDWORD(v5->uLastVisitDay);
  LODWORD(v142) = LODWORD(v5->uLastVisitDay);
  HIDWORD(v142) = v100;
  if ( v100 | (unsigned int)v142 )
  {
    v108 = 28;
    if ( (signed int)((signed int)(signed __int64)((double)v142 * 0.234375) / 60 / 60 / 0x18u) % 28 != pParty->uDaysPlayed )
    {
      if ( rand() % 100 >= 20 )
        v108 = dword_4EC268[rand() % dword_4EC2A8];
      else
        v108 = dword_4EC28C[rand() % dword_4EC2AC];
      sprintfex(v5->field_4F8, "plansky%d", v108);
    }
  }
  else
  {
    strcpy(v5->field_4F8, "plansky3");
  }
  v101 = pBitmaps_LOD->LoadTexture(v5->field_4F8);
  v5->uSky_TextureID = v101;
  if ( v101 != -1 )
  {
    v108 = *(short *)(v101 != -1 ? &pBitmaps_LOD->pTextures[v101].palette : (int *)36);
    if (v101 != -1)
      HIWORD(pBitmaps_LOD->pTextures[v101].palette) = pPaletteManager->LoadPalette(v108);
  }
  pPaletteManager->RecalculateAll();
  pSoundList->_4A9A67(53, 0);
  pSoundList->_4A9A67(92, 0);
  pSoundList->_4A9A67(57, 0);
  pSoundList->_4A9A67(96, 0);
  pSoundList->_4A9A67(64, 0);
  pSoundList->_4A9A67(103, 0);
  v102 = thisa;
  thisa = 3;
  do
  {
    if ( *(short *)v102 )
    {
      switch ( *(short *)v102 )
      {
        case 1:
          pSoundList->_4A9A67(58, 0);
          v108 = 0;
          v107 = 97;
          break;
        case 2:
          pSoundList->_4A9A67(52, 0);
          v108 = 0;
          v107 = 91;
          break;
        case 3:
          pSoundList->_4A9A67(51, 0);
          v108 = 0;
          v107 = 90;
          break;
        case 5:
          pSoundList->_4A9A67(62, 0);
          v108 = 0;
          v107 = 101;
          break;
        case 6:
          pSoundList->_4A9A67(49, 0);
          v108 = 0;
          v107 = 88;
          break;
        default:
          if ( *(short *)v102 != 7 )
            goto LABEL_175;
          pSoundList->_4A9A67(61, 0);
          v108 = 0;
          v107 = 100;
          break;
      }
    }
    else
    {
      pSoundList->_4A9A67(54, 0);
      v108 = 0;
      v107 = 93;
    }
    pSoundList->_4A9A67(v107, v108);
LABEL_175:
    v102 += 4;
    --thisa;
  }
  while ( thisa );
  return 1;
}
// 4EC268: using guessed type int dword_4EC268[];
// 4EC28C: using guessed type int dword_4EC28C[];
// 4EC2A8: using guessed type int dword_4EC2A8;
// 4EC2AC: using guessed type int dword_4EC2AC;
// 6807E0: using guessed type int _6807E0_num_decorations_6807B8;
// 6BE364: using guessed type int dword_6BE364_game_settings_1;
// 6BE3C4: using guessed type char bUnderwater;

//----- (0047ECC1) --------------------------------------------------------
int OutdoorLocation::_47ECC1(signed int a2)
{
  signed int result; // eax@2
  int v3; // eax@3

  if ( a2 >= 90 )
  {
    v3 = (a2 - 90) / 36;
    if ( v3 && v3 != 1 && v3 != 2 )
    {
      if ( v3 == 3 )
        result = this->pTileTypes[3].uTileID;
      else
        result = a2;
    }
    else
    {
      result = this->pTileTypes[v3].uTileID;
    }
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (0047ED08) --------------------------------------------------------
unsigned int OutdoorLocation::DoGetTileTexture(unsigned int uX, unsigned int uZ)
{
  int v3; // esi@5
  unsigned int result; // eax@9

  if ( (uX & 0x80000000u) != 0 || (signed int)uX > 127 || (uZ & 0x80000000u) != 0 || (signed int)uZ > 127 )
  {
    result = 0;
  }
  else
  {
    v3 = *(&this->pTerrain.pTilemap[128 * uZ] + uX);
    if ( v3 < 198 )
    {
      if ( v3 >= 90 )
        v3 = v3 + this->pTileTypes[(v3 - 90) / 36].uTileID - 36 * (v3 - 90) / 36 - 90;
    }
    else
    {
      v3 = v3 + this->pTileTypes[3].uTileID - 198;
    }
    result = pTileTable->pTiles[v3].uBitmapID;
  }
  return result;
}

//----- (0047ED83) --------------------------------------------------------
int OutdoorLocation::_47ED83(signed int a2, signed int a3)
{
  int result; // eax@5

  if ( a2 < 0 || a2 > 127 || a3 < 0 || a3 > 127 )
    result = 0;
  else
    result = *(&this->pTerrain.pTilemap[128 * a3] + a2);
  return result;
}

//----- (0047EDB3) --------------------------------------------------------
int OutdoorLocation::ActuallyGetSomeOtherTileInfo(unsigned int uX, unsigned int uY)
{
  int v3; // esi@5
  int result; // eax@7

  if ( (uX & 0x80000000u) != 0 || (signed int)uX > 127 || (uY & 0x80000000u) != 0 || (signed int)uY > 127 )
  {
    result = 0;
  }
  else
  {
    v3 = *(&this->pTerrain.pTilemap[128 * uY] + uX);
    if ( v3 >= 90 )
      v3 = v3 + this->pTileTypes[(v3 - 90) / 36].uTileID - 36 * (v3 - 90) / 36 - 90;
    result = pTileTable->pTiles[v3].uAttributes;
  }
  return result;
}

//----- (0047EE16) --------------------------------------------------------
int OutdoorLocation::DoGetHeightOnTerrain(unsigned int uX, unsigned int uZ)
{
  int result; // eax@5

  if ( (uX & 0x80000000u) != 0 || (signed int)uX > 127 || (uZ & 0x80000000u) != 0 || (signed int)uZ > 127 )
    result = 0;
  else
    result = 32 * *(&this->pTerrain.pHeightmap[128 * uZ] + uX);
  return result;
}

//----- (0047EE49) --------------------------------------------------------
int OutdoorLocation::_47EE49(signed int a2, signed int a3, int a4)
{
  signed int v4; // eax@5
  signed int v5; // eax@7
  int v6; // eax@8
  signed int v8; // eax@9
  int v9; // eax@12
  int v10; // eax@13
  int v11; // eax@14
  int v12; // eax@16
  int v13; // eax@17
  int v14; // eax@18
  int v15; // eax@19
  int v16; // eax@20
  int v17; // eax@21
  int v18; // eax@28
  int v19; // eax@29
  int v20; // eax@30

  if ( a2 < 0 || a2 > 127 || a3 < 0 || a3 > 127 )
    v4 = 0;
  else
    v4 = *(&this->pTerrain.pTilemap[128 * a3] + a2);
  v5 = _47ECC1(v4);
  if ( !v5 )
  {
    v6 = -(a4 != 0);
    LOBYTE(v6) = v6 & 0xD9;
    return v6 + 92;
  }
  v8 = pTileTable->pTiles[v5].uTerrainType;
  if ( v8 <= 6 )
  {
    if ( v8 == 6 )
    {
      v17 = -(a4 != 0);
      LOBYTE(v17) = v17 & 0xD9;
      return v17 + 88;
    }
    if ( v8 )
    {
      v9 = v8 - 1;
      if ( !v9 )
      {
        v15 = -(a4 != 0);
        LOBYTE(v15) = v15 & 0xD9;
        return v15 + 97;
      }
      v10 = v9 - 1;
      if ( !v10 )
      {
        v14 = -(a4 != 0);
        LOBYTE(v14) = v14 & 0xD9;
        return v14 + 91;
      }
      v11 = v10 - 1;
      if ( !v11 )
      {
        v13 = -(a4 != 0);
        LOBYTE(v13) = v13 & 0xD9;
        return v13 + 90;
      }
      if ( v11 == 2 )
      {
        v12 = -(a4 != 0);
        LOBYTE(v12) = v12 & 0xD9;
        return v12 + 101;
      }
LABEL_29:
      v19 = -(a4 != 0);
      LOBYTE(v19) = v19 & 0xD9;
      return v19 + 95;
    }
    goto LABEL_20;
  }
  if ( v8 != 7 )
  {
    if ( v8 != 8 )
    {
      if ( v8 > 9 && (v8 <= 17 || v8 > 21 && v8 <= 27) )
      {
        v18 = -(a4 != 0);
        LOBYTE(v18) = v18 & 0xD9;
        return v18 + 96;
      }
      goto LABEL_29;
    }
LABEL_20:
    v16 = -(a4 != 0);
    LOBYTE(v16) = v16 & 0xD9;
    return v16 + 93;
  }
  v20 = -(a4 != 0);
  LOBYTE(v20) = v20 & 0xD9;
  return v20 + 100;
}

//----- (0047EF60) --------------------------------------------------------
int OutdoorLocation::_47EF60(int a2, int a3, int a4)
{
  int v4; // ecx@1
  int v5; // edx@2
  int v6; // edi@2
  int v7; // esi@2
  int v8; // eax@4
  int v9; // ebx@4
  int v10; // eax@5
  int v11; // eax@7
  int v12; // esi@12
  char v13; // al@12
  int v15; // [sp+4h] [bp-14h]@7
  int v16; // [sp+8h] [bp-10h]@5
  int v17; // [sp+Ch] [bp-Ch]@2
  OutdoorLocation *v18; // [sp+10h] [bp-8h]@1
  int v19; // [sp+14h] [bp-4h]@2
  int i; // [sp+24h] [bp+Ch]@5

  v18 = this;
  v4 = a3 - 10;
  if ( a3 - 10 < a3 + 10 )
  {
    v5 = v4 - a3;
    v6 = 88 * (a3 - 30);
    v7 = a2;
    v19 = v4 - a3;
    v17 = a3 + 10 - v4;
    while ( 1 )
    {
      v8 = abs(v5);
      v9 = v7 - 10;
      if ( v7 - 10 < v7 + 10 )
      {
        v16 = v8 * v8;
        v10 = v9 - v7;
        for ( i = v9 - v7; ; v10 = i )
        {
          v11 = abs(v10);
          v15 = v11 * v11 + v16;
          if ( v15 <= 100 && v9 >= 20 && v9 <= 107 && v6 >= 0 && v6 <= 7656 )
          {
            v12 = (v6 + v9 - 20) >> 3;
            v13 = 1 << (8 - (v6 + v9 - 20) % 8 - 1);
            v18->array_8F0[v12] |= v13;
            if ( v15 <= 49 )
              v18->array_528[v12] |= v13;
            v7 = a2;
          }
          ++v9;
          ++i;
          if ( v9 >= v7 + 10 )
            break;
        }
      }
      v6 += 88;
      ++v19;
      --v17;
      if ( !v17 )
        break;
      v5 = v19;
    }
  }
  return 1;
}

//----- (0047F04C) --------------------------------------------------------
bool OutdoorLocation::_47F04C(signed int a2, signed int a3)
{
  bool result; // eax@5

  if ( a2 < 0 || a2 >= 88 || a3 < 0 || a3 >= 88 )
    result = 0;
  else
    result = (this->array_528[(a2 + 88 * a3) / 8] & (unsigned __int8)(1 << (7 - (a2 + 88 * a3) % 8))) != 0;
  return result;
}

//----- (0047F097) --------------------------------------------------------
bool OutdoorLocation::_47F097(signed int a2, signed int a3)
{
  bool result; // eax@5

  if ( a2 < 0 || a2 >= 88 || a3 < 0 || a3 >= 88 )
    result = 0;
  else
    result = (this->array_8F0[(a2 + 88 * a3) / 8] & (unsigned __int8)(1 << (7 - (a2 + 88 * a3) % 8))) != 0;
  return result;
}

//----- (0047F0E2) --------------------------------------------------------
bool OutdoorLocation::_47F0E2()
{
  signed int v1; // edi@1
  OutdoorLocation *v2; // ebx@1
  Texture *v3; // ebp@2

  v1 = 0;
  v2 = this;
  if ( (signed int)pBitmaps_LOD->uNumLoadedFiles > 0 )
  {
    v3 = pBitmaps_LOD->pTextures;
    do
    {
      if ( v1 != -1 ? (int)v3 : 0 )
        v3->uDecompressedSize = v2->pTerrain._47CB57((int)v3->pLevelOfDetail0,
                                                      HIWORD(v3->palette),
                                                      v3->uTextureWidth * v3->uTextureHeight);
      ++v1;
      ++v3;
    }
    while ( v1 < (signed int)pBitmaps_LOD->uNumLoadedFiles );
  }
  return 1;
}

//----- (0047F138) --------------------------------------------------------
int OutdoorLocation::PrepareDecorations()
{
  signed int v1; // ebx@1
  signed int v2; // edi@3
  LevelDecoration *v3; // esi@4
  __int16 v4; // ax@5
  int v5; // eax@7
  __int16 v6; // ax@14
  signed int v8; // [sp+Ch] [bp-4h]@1

  v1 = 0;
  v8 = 0;
  if ( !_strcmpi(pCurrentMapName, "out09.odm") )
    v8 = 1;
  v2 = 0;
  if ( (signed int)uNumLevelDecorations > 0 )
  {
    v3 = pLevelDecorations;
    do
    {
      pDecorationList->InitializeDecorationSprite(v3->uDecorationDescID);
      v4 = pDecorationList->pDecorations[v3->uDecorationDescID].uSoundID;
      if ( v4 && _6807E0_num_decorations_6807B8 < 9 )
      {
        pSoundList->_4A9A67(v4, 0);
        v5 = _6807E0_num_decorations_6807B8++;
        _6807B8_level_decorations_ids[v5] = v2;
      }
      if ( v8 && v3->uCog == 20 )
        LOBYTE(v3->field_2) |= 0x40u;
      if ( !v3->field_16_event_id )
      {
        if ( v3->IsInteractive() )
        {
          if ( v1 < 124 )
          {
            v6 = v1++ + 75;
            v3->field_1C = v6;
            if ( !stru_5E4C90.field_0[v1 + 74] )
              LOBYTE(v3->field_2) |= 0x20u;
          }
        }
      }
      ++v2;
      ++v3;
    }
    while ( v2 < (signed int)uNumLevelDecorations );
  }
  pGameLoadingUI_ProgressBar->Progress();
  return 1;
}
// 6807E0: using guessed type int _6807E0_num_decorations_6807B8;

//----- (0047F223) --------------------------------------------------------
int OutdoorLocation::_47F223_LooksLikeGenerateMonsterLoot()
{
  signed int v1; // ebx@1
  char *v2; // esi@2
  int v3; // eax@7
  OutdoorLocation *v5; // [sp+0h] [bp-4h]@1

  v5 = this;
  v1 = 0;
  if ( (signed int)uNumLayingItems > 0 )
  {
    v2 = (char *)&pLayingItems[0].uObjectDescID;
    do
    {
      if ( *(short *)v2 )
      {
        if ( !(v2[24] & 8) && !(pObjectList->pObjects[*(short *)v2].uFlags & 0x10) )
          *(int *)(v2 + 10) = GetTerrainHeightsAroundParty2(*(int *)(v2 + 2), *(int *)(v2 + 6), (int *)&v5, 0);
        v3 = *(int *)(v2 + 34);
        if ( v3 )
        {
          if ( v3 != 220 && pItemsTable->pItems[v3].uEquipType == 14 && !*(int *)(v2 + 38) )
            *(int *)(v2 + 38) = rand() % 15 + 5;
          pItemsTable->SetSpecialBonus((ItemGen *)(v2 + 34));
        }
      }
      ++v1;
      v2 += 112;
    }
    while ( v1 < (signed int)uNumLayingItems );
  }
  pGameLoadingUI_ProgressBar->Progress();
  return 1;
}

//----- (0047F2D3) --------------------------------------------------------
bool OutdoorLocation::InitalizeActors(int a1)
{
  int v2; // ebx@1
  char *v3; // esi@2
  int v4; // eax@3
  __int16 v5; // ax@11
  int v8; // [sp+348h] [bp-8h]@1
  int v9; // [sp+34Ch] [bp-4h]@1

  v2 = 0;
  v8 = 0;
  v9 = 0;
  if ( (signed int)uNumActors > 0 )
  {
    v3 = (char *)&pActors[0].uAttributes;
    while ( 1 )
    {
      v4 = *(int *)v3;
      if ( !(v4 & 0x100000) )
        break;
      if ( a1 == v2 )
        goto LABEL_8;
      if ( v8 != v2 )
        goto LABEL_9;
      *((short *)v3 + 70) = 19;
      *(int *)v3 = v4 | 0x10000;
      v8 = GetAlertStatus();
LABEL_17:
      ++v9;
      v3 += 836;
      if ( v9 >= (signed int)uNumActors )
        goto LABEL_18;
    }
    if ( v8 != 1 )
    {
LABEL_9:
      *((int *)v3 + 37) = v2;
      *((short *)v3 + 62) = v2;
      if ( v4 & 0x10000 )
        *((short *)v3 + 70) = 19;
      v5 = *((short *)v3 + 70);
      if ( v5 != 11 && v5 != 19 && (*((short *)v3 + 2) == (short)v2 || *((int *)v3 + 18) == v2) )
        *((short *)v3 + 70) = 5;
      *((short *)v3 + 56) = v2;
      *((short *)v3 + 57) = v2;
      *((short *)v3 + 58) = v2;
      ((Actor *)(v3 - 36))->UpdateAnimation();
      v3[25] = 0;
      ((Actor *)(v3 - 36))->PrepareSprites(0);
      v2 = 0;
      goto LABEL_17;
    }
LABEL_8:
    *((short *)v3 + 70) = 19;
    *(int *)v3 = v4 | 0x10000;
    goto LABEL_17;
  }
LABEL_18:
  pGameLoadingUI_ProgressBar->Progress();

  Actor thisa;
  thisa.pMonsterInfo.uID = 45;
  thisa.PrepareSprites(v2);
  return 1;
}

//----- (0047F3EA) --------------------------------------------------------
bool OutdoorLocation::_47F3EA()
{
  OutdoorLocationTileType *v1; // esi@1

  v1 = &this->pTileTypes[3];
  this->pTileTypes[3].uTileID = pTileTable->method_487ED6(this->pTileTypes[3].uTileGroup, 1);
  pTileTable->InitializeTileset(v1->uTileGroup);
  return 1;
}

//----- (0047F420) --------------------------------------------------------
bool OutdoorLocation::_47F420()
{
  char *v1; // esi@1
  signed int v2; // edi@1

  v1 = (char *)&this->pTileTypes[0].uTileID;
  v2 = 3;
  do
  {
    *(short *)v1 = pTileTable->method_487ED6(*((short *)v1 - 1), 1);
    v1 += 4;
    --v2;
  }
  while ( v2 );
  return 1;
}

//----- (0047B42C) --------------------------------------------------------
unsigned int OutdoorLocation::DrawActors()
{
  unsigned int result; // eax@1
  char *v1; // edi@2
  __int16 v2; // ax@3
  int v3; // esi@5
  float v4; // ST48_4@8
  double v5; // ST38_8@8
  float v6; // ST48_4@10
  double v7; // ST30_8@10
  unsigned int v8; // eax@11
  int v9; // edx@11
  __int16 v10; // dx@11
  unsigned int v11; // eax@13
  signed int v12; // eax@16
  __int16 v13; // cx@21
  SpriteFrame *v14; // eax@24
  SpriteFrame *v15; // ebx@25
  int *v16; // eax@25
  int v17; // eax@35
  int v18; // ST78_4@36
  int v19; // eax@36
  int v20; // ecx@38
  int v21; // eax@38
  int v22; // ecx@41
  int v23; // ST5C_4@43
  int v24; // esi@44
  signed __int64 v25; // qtt@45
  int v26; // ST54_4@45
  int v27; // ecx@45
  RenderBillboard *v28; // esi@45
  __int16 v29; // ax@46
  unsigned __int8 v30; // zf@46
  unsigned __int8 v31; // sf@46
  signed __int16 v32; // ax@49
  signed int v33; // ecx@50
  int v34; // ecx@54
  MonsterDesc *v35; // edx@54
  int v36; // ecx@54
  unsigned __int8 v37; // zf@54
  unsigned __int8 v38; // sf@54
  unsigned int v39; // [sp-8h] [bp-68h]@23
  unsigned int v40; // [sp-4h] [bp-64h]@23
  int v41; // [sp+24h] [bp-3Ch]@11
  int v42; // [sp+28h] [bp-38h]@38
  int v43; // [sp+28h] [bp-38h]@45
  int v44; // [sp+2Ch] [bp-34h]@36
  int v45; // [sp+2Ch] [bp-34h]@44
  int v46; // [sp+2Ch] [bp-34h]@45
  int v47; // [sp+30h] [bp-30h]@36
  int v48; // [sp+30h] [bp-30h]@41
  signed int v49; // [sp+34h] [bp-2Ch]@5
  int v50; // [sp+34h] [bp-2Ch]@36
  int v51; // [sp+34h] [bp-2Ch]@41
  int v52; // [sp+34h] [bp-2Ch]@50
  int v53; // [sp+38h] [bp-28h]@36
  int v54; // [sp+3Ch] [bp-24h]@2
  int y; // [sp+40h] [bp-20h]@5
  int x; // [sp+44h] [bp-1Ch]@5
  int v57; // [sp+48h] [bp-18h]@45
  int v58; // [sp+4Ch] [bp-14h]@45
  signed int v59; // [sp+50h] [bp-10h]@1
  int X; // [sp+54h] [bp-Ch]@36
  __int16 v61; // [sp+58h] [bp-8h]@5
  signed __int16 v62; // [sp+5Ch] [bp-4h]@25

  result = 0;
  v59 = 0;
  if ( (signed int)uNumActors > 0 )
  {
    v54 = 0;
    v1 = (char *)&pActors[0].vPosition.z;
    do
    {
      v2 = *((short *)v1 + 15);
      *(int *)(v1 - 110) &= 0xFFFFFFF7u;
      if ( v2 == 11 || v2 == 19 )
        goto LABEL_58;
      v3 = *(short *)v1;
      v49 = 0;
      x = *((short *)v1 - 2);
      y = *((short *)v1 - 1);
      v61 = *(short *)v1;
      if ( v2 == 17 )
      {
        if ( (v1[666] & 7) != 3 || pActors[*(int *)(v1 + 666) >> 3].pMonsterInfo.uSpecialAbilityDamageDiceSides != 1 )
        {
          v6 = (double)*((short *)v1 - 4) * 0.5;
          v7 = v6 + 6.7553994e15;
          v3 += LODWORD(v7);
          v61 = v3;
        }
        else
        {
          v49 = 1;
          pGame->pStru6Instance->_4A7F74(*((short *)v1 - 2), *((short *)v1 - 1), v3);
          v4 = (1.0 - (double)*(signed int *)(v1 + 38) / (double)*((short *)v1 + 7))
             * (double)(2 * (signed int)*((short *)v1 - 4));
          v5 = v4 + 6.7553994e15;
          v3 -= LODWORD(v5);
          v61 = v3;
          if ( v3 > *(short *)v1 )
          {
            v61 = *(short *)v1;
            v3 = *(short *)v1;
          }
        }
      }
      v8 = stru_5C6E00->Atan2(
             *((short *)v1 - 2) - pIndoorCamera->pos.x,
             *((short *)v1 - 1) - pIndoorCamera->pos.y);
      LOWORD(v9) = *((short *)v1 + 4);
      v41 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v9 - v8) >> 8) & 7;
      v10 = *((short *)v1 + 16);
      if ( pParty->bTurnBasedModeOn )
      {
        if ( v10 != 1 )
        {
LABEL_17:
          v12 = *(int *)(v1 + 38);
          goto LABEL_18;
        }
        v11 = pMiscTimer->uTotalGameTimeElapsed;
      }
      else
      {
        if ( v10 != 1 )
          goto LABEL_17;
        v11 = pEventTimer->uTotalGameTimeElapsed;
      }
      v12 = v54 + v11;
LABEL_18:
      if ( *(_QWORD *)(v1 + 146) > 0i64 || *(_QWORD *)(v1 + 162) > 0i64 )
        v12 = 0;
      v13 = *((short *)v1 + 15);
      if ( v13 == 17 && !v49 )
      {
        v40 = v12;
        v39 = uSpriteID_Spell11;
LABEL_24:
        v14 = pSpriteFrameTable->GetFrame(v39, v40);
        goto LABEL_25;
      }
      v40 = v12;
      v39 = *(short *)&v1[2 * v10 + 42];
      if ( v13 != 16 )
        goto LABEL_24;
      v14 = pSpriteFrameTable->GetFrameBy_x(v39, v12);
LABEL_25:
      v62 = 0;
      v15 = v14;
      v16 = (int *)v14->uFlags;
      if ( (unsigned __int8)v16 & 2 )
        v62 = 2;
      if ( (unsigned int)v16 & 0x40000 )
        v62 |= 0x40u;
      if ( (unsigned int)v16 & 0x20000 )
        LOBYTE(v62) = v62 | 0x80;
      if ( (256 << v41) & (unsigned int)v16 )
        v62 |= 4u;
      if ( v15->uGlowRadius )
      {
        LOBYTE(v16) = byte_4E94D3;
        pMobileLightsStack->AddLight(x, y, v3, 0, v15->uGlowRadius, 0xFFu, 0xFFu, 0xFFu, v16);
      }
      v17 = (x - pIndoorCamera->pos.x) << 16;
      if ( pIndoorCamera->sRotationX )
      {
        v18 = (y - pIndoorCamera->pos.y) << 16;
        v47 = ((unsigned __int64)(v17 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16)
            + ((unsigned __int64)(v18 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16);
        v50 = (unsigned __int64)(v17 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
        v53 = (unsigned __int64)(v18 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16;
        v44 = (v3 - pIndoorCamera->pos.z) << 16;
        v19 = ((unsigned __int64)(v44 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16)
            + ((unsigned __int64)(v47 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_cosine) >> 16);
        X = ((unsigned __int64)(v44 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16)
          + ((unsigned __int64)(v47 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_cosine) >> 16);
        if ( v19 < 262144 || v19 > pOutdoorCamera->shading_dist_mist << 16 )
          goto LABEL_58;
        v20 = v53 - v50;
        v42 = v53 - v50;
        v21 = ((unsigned __int64)(v44 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_cosine) >> 16)
            - ((unsigned __int64)(v47 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16);
      }
      else
      {
        v48 = (y - pIndoorCamera->pos.y) << 16;
        v51 = (unsigned __int64)(v17 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16;
        v22 = (unsigned __int64)(v48 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
        X = v22 + v51;
        if ( v22 + v51 < 262144 || v22 + v51 > pOutdoorCamera->shading_dist_mist << 16 )
          goto LABEL_58;
        v23 = (unsigned __int64)(((x - pIndoorCamera->pos.x) << 16)
                               * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
        v20 = ((unsigned __int64)(v48 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16) - v23;
        v42 = ((unsigned __int64)(v48 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16) - v23;
        v21 = (v3 - pIndoorCamera->pos.z) << 16;
      }
      v45 = v21;
      v24 = abs(v20);
      if ( abs(X) >= v24 )
      {
        LODWORD(v25) = 0;
        HIDWORD(v25) = SLOWORD(pOutdoorCamera->int_fov_rad);
        v58 = v25 / X;
        v26 = v25 / X;
        LODWORD(v25) = 0;
        HIDWORD(v25) = SLOWORD(pOutdoorCamera->int_fov_rad);
        v57 = v25 / X;
        v27 = pViewport->uScreenCenterX
            - ((signed int)(((unsigned __int64)(v26 * (signed __int64)v42) >> 16) + 32768) >> 16);
        v43 = pViewport->uScreenCenterX
            - ((signed int)(((unsigned __int64)(v26 * (signed __int64)v42) >> 16) + 32768) >> 16);
        v46 = pViewport->uScreenCenterY - ((signed int)(((unsigned __int64)(v25 / X * v45) >> 16) + 32768) >> 16);
        result = uNumBillboardsToDraw;
        v28 = &pBillboardRenderList[uNumBillboardsToDraw];
        if ( (signed int)uNumBillboardsToDraw >= 500 )
          return result;
        ++uNumBillboardsToDraw;
        ++uNumSpritesDrawnThisFrame;
        *(int *)(v1 - 110) |= 8u;
        v28->uHwSpriteID = v15->pHwSpriteIDs[v41];
        v29 = v15->uPaletteIndex;
        v28->uIndoorSectorID = 0;
        v28->uPalette = v29;
        v28->field_0 = (unsigned __int64)(v15->scale * (signed __int64)v58) >> 16;
        v30 = *(int *)(v1 + 118) == 0;
        v31 = *(int *)(v1 + 118) < 0;
        v28->field_4 = (unsigned __int64)(v15->scale * (signed __int64)v57) >> 16;
        if ( v31 || v31 | v30 && *(int *)(v1 + 114) <= 0u )
        {
          if ( *(_QWORD *)(v1 + 226) > 0i64 )
          {
            v52 = (unsigned __int64)(pGame->pStru6Instance->_4A806F((Actor *)(v1 - 146))
                                   * (signed __int64)v28->field_4) >> 16;
LABEL_53:
            LOWORD(v27) = v43;
            v28->field_4 = v52;
          }
        }
        else
        {
          v32 = *((short *)v1 + 61);
          if ( v32 )
          {
            v33 = *((short *)v1 + 61);
            v28->field_0 = (unsigned __int64)(65536 / (unsigned __int16)v32 * (signed __int64)v28->field_0) >> 16;
            v52 = (unsigned __int64)(65536 / v33 * (signed __int64)v28->field_4) >> 16;
            goto LABEL_53;
          }
        }
        v28->field_26 = v27;
        v28->field_20 = x;
        v28->field_28 = v46;
        v28->field_22 = y;
        v28->field_24 = v61;
        HIWORD(v34) = HIWORD(X);
        LOWORD(v34) = 0;
        v28->field_2A = 0;
        v28->sZValue = v34 + (8 * v59 | 3);
        v28->field_14 = v59;
        v35 = pMonsterList->pMonsters;
        v36 = *((short *)v1 - 25);
        v37 = *(int *)(v1 + 150) == 0;
        v38 = *(int *)(v1 + 150) < 0;
        v28->field_1E = v62 | 0x200;
        v28->pSpriteFrame = v15;
        v28->field_2C_prolly_tint = *((int *)&v35[v36] - 36);
        if ( !v38 && (!(v38 | v37) || *(int *)(v1 + 146)) )
          v28->field_1E = v62 | 0x200;
      }
LABEL_58:
      ++v59;
      v54 += 32;
      result = v59;
      v1 += 836;
    }
    while ( v59 < (signed int)uNumActors );
  }
  return result;
}
// 4E94D3: using guessed type char byte_4E94D3;
// 5187E4: using guessed type int uNumSpritesDrawnThisFrame;

//----- (0044C1E8) --------------------------------------------------------
bool ODMFace::HasEventHint()
{
  signed int v1; // eax@1
  Event *v2; // esi@2
  bool result; // eax@5
  signed int v4; // eax@6

  v1 = 0;
  if ( (signed int)(uLevelEVT_NumEvents - 1) <= 0 )
    goto LABEL_5;
  v2 = pLevelEVT_Events;
  while ( v2->uEventID != this->sCogTriggeredID )
  {
    ++v1;
    ++v2;
    if ( v1 >= (signed int)(uLevelEVT_NumEvents - 1) )
      goto LABEL_5;
  }
  v4 = v1;
  if ( pLevelEVT[pLevelEVT_Events[v4 + 1].uEventOffsetInEVT + 4] != 1
    || pLevelEVT[pLevelEVT_Events[v4].uEventOffsetInEVT + 4] != 4 )
LABEL_5:
    result = 0;
  else
    result = 1;
  return result;
}