changeset 67:3b4f8bd48e3b

25.01.13 (I did sky)
author Ritor1
date Fri, 25 Jan 2013 16:48:21 +0600
parents 653fdf29c654
children d7e3f844fc2e 6ef241d53522
files Indoor_stuff.h Outdoor.cpp Render.cpp Render.h mm7_3.cpp mm7_data.cpp mm7_data.h
diffstat 7 files changed, 722 insertions(+), 634 deletions(-) [+]
line wrap: on
line diff
--- a/Indoor_stuff.h	Wed Jan 23 17:29:00 2013 +0600
+++ b/Indoor_stuff.h	Fri Jan 25 16:48:21 2013 +0600
@@ -364,6 +364,7 @@
 
 /*  147 */
 #pragma pack(push, 1)
+
 struct stru154
 {
   //----- (0049B001) --------------------------------------------------------
--- a/Outdoor.cpp	Wed Jan 23 17:29:00 2013 +0600
+++ b/Outdoor.cpp	Fri Jan 25 16:48:21 2013 +0600
@@ -63,7 +63,7 @@
                                           * (signed __int64)pParty->field_18) >> 16);
   v3 = stru_5C6E00->SinCos(pParty->sRotationY - stru_5C6E00->uIntegerHalfPi);
   pIndoorCamera->field_4C = v1;
-  pIndoorCamera->pos.y = pParty->vPosition.y - ((unsigned __int64)(v3 * (signed __int64)pParty->field_18) >> 16);
+  pIndoorCamera->pos.y = pParty->vPosition.y - pParty->field_18 * (stru_5C6E00->SinCos(pIndoorCamera->sRotationY) / 2048.0);
   pIndoorCamera->pos.z = pParty->vPosition.z + pParty->sEyelevel;
   if ( v2 || pRenderer->pRenderD3D )
   {
@@ -196,39 +196,49 @@
 //----- (00488EB1) --------------------------------------------------------
 int OutdoorLocation::GetSomeOtherTileInfo(int sX, int sY)
 {
-  OutdoorLocation *v3; // esi@1
+  //OutdoorLocation *v3; // esi@1
   unsigned int v4; // edi@1
   unsigned int v5; // eax@1
   int result; // eax@5
 
-  v3 = this;
+/*  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;
+  return result;*/
+ v4 = WorldPosToGridCellZ(sY);
+ v5 = WorldPosToGridCellX(sX);
+ if ( v5 < 0 || v5 > 127 || v4 < 0 || v4 > 127 )
+   return 0;
+ return ActuallyGetSomeOtherTileInfo(v5, v4);
 }
 // 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)
+unsigned int OutdoorLocation::GetTileTexture(int sX, int sY)
 {
-  OutdoorLocation *v3; // esi@1
+  //OutdoorLocation *v3; // esi@1
   unsigned int v4; // edi@1
   unsigned int v5; // eax@1
-  unsigned int result; // eax@5
+//  unsigned int result; // eax@5
 
-  v3 = this;
+  /*v3 = this;
   v4 = WorldPosToGridCellZ(sZ);
   v5 = WorldPosToGridCellX(sX);
-  if ( (v5 & 0x80000000u) != 0 || (signed int)v5 > 127 || (v4 & 0x80000000u) != 0 || (signed int)v4 > 127 )
+  if ( v5< 0 || (signed int)v5 > 127 || v4 < 0 || (signed int)v4 > 127 )//if ( (v5 & 0x80000000u) != 0 || (signed int)v5 > 127 || (v4 & 0x80000000u) != 0 || (signed int)v4 > 127 )
     result = -1;
   else
     result = DoGetTileTexture(v5, v4);
-  return result;
+  return result;*/
+  v4 = WorldPosToGridCellZ(sY);
+  v5 = WorldPosToGridCellX(sX);
+  if ( v5 < 0 || v5 > 127 || v4 < 0 || v4 > 127 )
+    return -1;
+  return DoGetTileTexture(v5, v4);
 }
 // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
 // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
@@ -1686,7 +1696,7 @@
   memcpy(pLevelFilename, pSrc, 0x20);
   memcpy(pLocationFileName, pSrc + 0x20, 0x20);
   memcpy(pLocationFileDescription, pSrc + 0x40, 0x20);
-  memcpy(pSkyTextureName, pSrc + 0x60, 0x20);
+  memcpy(pSkyTextureName, pSrc + 3 * 32, 32);
   memcpy(pGroundTileset, pSrc + 0x80, 0x20);
   memcpy(pTileTypes, pSrc + 0xA0, 0x10);
   pSrc += 0xB0;
@@ -2389,18 +2399,13 @@
 }
 
 //----- (0047ED08) --------------------------------------------------------
-unsigned int OutdoorLocation::DoGetTileTexture(unsigned int uX, unsigned int uZ)
+unsigned int OutdoorLocation::DoGetTileTexture(unsigned int uX, unsigned int uY)
 {
   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);
+
+/*    v3 = *(&this->pTerrain.pTilemap[128 * uZ] + uX);
     if ( v3 < 198 )
     {
       if ( v3 >= 90 )
@@ -2412,7 +2417,20 @@
     }
     result = pTileTable->pTiles[v3].uBitmapID;
   }
-  return result;
+  return result;*/
+   if (uX > 127 || uY > 127)
+   return 0;
+
+ v3 = this->pTerrain.pTilemap[uY * 128 + uX];
+ if (v3 < 198)
+ {
+  if (v3 >= 90)
+    v3 = v3 + this->pTileTypes[(v3 - 90) / 18].uTileID - 36 * (v3 - 90) / 36 - 90;
+ }
+ else
+   v3 = v3 + this->pTileTypes[3].uTileID - 198;
+
+ return pTileTable->pTiles[v3].uBitmapID;
 }
 
 //----- (0047ED83) --------------------------------------------------------
@@ -2431,9 +2449,9 @@
 int OutdoorLocation::ActuallyGetSomeOtherTileInfo(unsigned int uX, unsigned int uY)
 {
   int v3; // esi@5
-  int result; // eax@7
+  //int result; // eax@7
 
-  if ( (uX & 0x80000000u) != 0 || (signed int)uX > 127 || (uY & 0x80000000u) != 0 || (signed int)uY > 127 )
+/*  if ( (uX & 0x80000000u) != 0 || (signed int)uX > 127 || (uY & 0x80000000u) != 0 || (signed int)uY > 127 )
   {
     result = 0;
   }
@@ -2444,7 +2462,16 @@
       v3 = v3 + this->pTileTypes[(v3 - 90) / 36].uTileID - 36 * (v3 - 90) / 36 - 90;
     result = pTileTable->pTiles[v3].uAttributes;
   }
-  return result;
+  return result;*/
+   if (uX > 127 || uY > 127)
+   return 0;
+ else
+ {
+  v3 = this->pTerrain.pTilemap[128 * uY + uX];
+  if ( v3 >= 90 )
+     v3 = v3 + this->pTileTypes[(v3 - 90) / 18].uTileID - 36 * (v3 - 90) / 36 - 90;
+  return pTileTable->pTiles[v3].uAttributes;
+ }
 }
 
 //----- (0047EE16) --------------------------------------------------------
--- a/Render.cpp	Wed Jan 23 17:29:00 2013 +0600
+++ b/Render.cpp	Fri Jan 25 16:48:21 2013 +0600
@@ -32,8 +32,7 @@
 
 struct IDirectDrawClipper *pDDrawClipper;
 struct Render *pRenderer; // idb
-
-
+struct RenderVertexD3D3  pVertices[50];
 int uNumDecorationsDrawnThisFrame; // weak
 RenderBillboard pBillboardRenderList[500];
 unsigned int uNumBillboardsToDraw;
@@ -925,7 +924,7 @@
   int v13; // eax@21
   int v14; // eax@31
   int v15; // edi@33
-  float v16; // eax@34
+  int v16; // eax@34
   int v17; // edx@34
   int v18; // ebx@34
   int v19; // eax@36
@@ -934,7 +933,7 @@
   char v22; // zf@44
   int v23; // ecx@47
   int v24; // edi@52
-  float v25; // eax@54
+  int v25; // eax@54
   int v26; // ecx@54
   int v27; // eax@56
   int v28; // edx@60
@@ -947,8 +946,8 @@
   int v35; // ecx@77
   int v36; // ecx@81
   int v37; // ecx@86
-  float v38; // eax@88
-  IndoorCameraD3D *v39; // ecx@88
+  int v38; // eax@88
+  int v39; // ecx@88
   int v40; // eax@90
   int v41; // edx@94
   int v42; // ecx@95
@@ -959,7 +958,7 @@
   int v47; // ecx@111
   int v48; // ecx@115
   int v49; // edi@120
-  float v50; // eax@122
+  int v50; // eax@122
   int v51; // ecx@122
   int v52; // eax@124
   int v53; // edx@128
@@ -972,8 +971,8 @@
   int v60; // ecx@147
   int v61; // ecx@150
   int v62; // ecx@155
-  float v63; // eax@157
-  IndoorCameraD3D *v64; // ecx@157
+  int v63; // eax@157
+  int v64; // ecx@157
   int v65; // eax@159
   int v66; // edx@163
   int v67; // ecx@164
@@ -985,7 +984,7 @@
   int v73; // ebx@180
   int v74; // eax@182
   int v75; // eax@184
-  IndoorCameraD3D *v76; // ecx@184
+  IndoorCameraD3D *pIndoorCameraD3D_3; // ecx@184
   int v77; // ecx@184
   int v79; // ebx@185
   int v127; // esi@185
@@ -998,9 +997,12 @@
   int v93; // ST08_4@204
   int v97; // ST08_4@204
   float result; // eax@212
-  char v102; // [sp+Ch] [bp-68h]@191
+  struct 
+  {
+  char v102[4]; // [sp+Ch] [bp-68h]@191
   __int16 v103; // [sp+10h] [bp-64h]@190
   __int16 v104; // [sp+12h] [bp-62h]@190
+  } v102;
   int pHeight; // [sp+1Ch] [bp-58h]@1
   int v106; // [sp+20h] [bp-54h]@3
   int v107; // [sp+24h] [bp-50h]@3
@@ -1009,7 +1011,7 @@
   int v110; // [sp+30h] [bp-44h]@9
   int v111; // [sp+34h] [bp-40h]@3
   int v112; // [sp+38h] [bp-3Ch]@6
-  IndoorCameraD3D *a1; // [sp+3Ch] [bp-38h]@9
+  IndoorCameraD3D *pIndoorCameraD3D_4; // [sp+3Ch] [bp-38h]@9
   int v114; // [sp+40h] [bp-34h]@9
   int v115; // [sp+44h] [bp-30h]@9
   int v116; // [sp+48h] [bp-2Ch]@9
@@ -1020,28 +1022,26 @@
   int i; // [sp+5Ch] [bp-18h]@1
   int v122; // [sp+60h] [bp-14h]@1
   int v123; // [sp+64h] [bp-10h]@1
-  float v124; // [sp+68h] [bp-Ch]@1
+  int v124; // [sp+68h] [bp-Ch]@1
   int v125; // [sp+6Ch] [bp-8h]@9
-  float v126; // [sp+70h] [bp-4h]@9
-
-  memset(&v102, 0, sizeof(v102));
+  int v126; // [sp+70h] [bp-4h]@9
+
   pHeight = pIndoorCamera->sRotationY / ((signed int)stru_5C6E00->uIntegerHalfPi / 2);
   v0 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerDoublePi - pIndoorCamera->sRotationY);
   v1 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + v0);
-  LODWORD(v124) = (signed int)((pIndoorCamera->uMapGridCellX << 16)
-                             + 3
-                             * stru_5C6E00->SinCos(
+  v124 = ((pIndoorCamera->uMapGridCellX << 16) + 3 * stru_5C6E00->SinCos(
                                  stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + v0))) >> 16;
-  v123 = (signed int)((pIndoorCamera->uMapGridCellZ << 16)
+  v123 = ((pIndoorCamera->uMapGridCellZ << 16)
                     + 3 * stru_5C6E00->SinCos(v1 - stru_5C6E00->uIntegerHalfPi)) >> 16;
-  v120 = pOutdoorCamera->outdoor_grid_band_3 + LODWORD(v124);
+  v120 = pOutdoorCamera->outdoor_grid_band_3 + v124;//+- range X
   v119 = pOutdoorCamera->outdoor_grid_band_3 + v123;
   v2 = pOutdoorCamera->uCameraFovInDegrees + 15;
-  i = LODWORD(v124) - pOutdoorCamera->outdoor_grid_band_3;
+  i = v124 - pOutdoorCamera->outdoor_grid_band_3;
   v122 = v123 - pOutdoorCamera->outdoor_grid_band_3;
-  if ( (signed int)(pOutdoorCamera->uCameraFovInDegrees + 15) > 90 )
+
+  if ( v2 > 90 )
     v2 = 90;
-  v3 = (signed int)(v2 << 11) / 720;
+  v3 = (v2 << 11) / 720;
   v4 = stru_5C6E00->uDoublePiMask & (v0 - v3);
   v5 = stru_5C6E00->uDoublePiMask & (v3 + v0);
   v106 = stru_5C6E00->SinCos(v4);
@@ -1049,124 +1049,127 @@
   v111 = stru_5C6E00->SinCos(v5);
   v6 = stru_5C6E00->SinCos(v5 - stru_5C6E00->uIntegerHalfPi);
   v7 = v4 & stru_5C6E00->uPiMask;
-  if ( (signed int)(v4 & stru_5C6E00->uPiMask) >= (signed int)stru_5C6E00->uIntegerHalfPi )
+
+  if ( (v4 & stru_5C6E00->uPiMask) >= stru_5C6E00->uIntegerHalfPi )
     v8 = -stru_5C6E00->pTanTable[stru_5C6E00->uIntegerPi - v7];
   else
     v8 = stru_5C6E00->pTanTable[v7];
   v112 = abs(v8);
   v9 = v5 & stru_5C6E00->uPiMask;
-  if ( (signed int)(v5 & stru_5C6E00->uPiMask) >= (signed int)stru_5C6E00->uIntegerHalfPi )
+  if ( (v5 & stru_5C6E00->uPiMask) >= stru_5C6E00->uIntegerHalfPi )
     v10 = -stru_5C6E00->pTanTable[stru_5C6E00->uIntegerPi - v9];
   else
     v10 = stru_5C6E00->pTanTable[v9];
   v108 = abs(v10);
-  v11 = LODWORD(v124);
+  v11 = v124;
   v12 = v123;
   v114 = 0;
   v115 = 0;
-  a1 = 0;
+  pIndoorCameraD3D_4 = 0;
   v125 = 0;
-  v110 = 2 * (v106 >= 0) - 1;
+  v110 = (v106 >= 0 ? 1: -1);//2 * (v106 >= 0) - 1;
   v126 = v124;
   v118 = v123;
-  v109 = 2 * (v107 >= 0) - 1;
-  v107 = 2 * (v111 >= 0) - 1;
+  v109 = (v107 >= 0 ? 1: -1);//2 * (v107 >= 0) - 1;
+  v107 = (v111 >= 0 ? 1: -1);//2 * (v111 >= 0) - 1;
   terrain_76E1C8[0] = 65535;
-  v116 = 1;
-  v106 = 2 * (v6 >= 0) - 1;
-  v117 = 1;
+  //v116 = 1;
+  v106 = (v6 >= 0 ? 1: -1);//2 * (v6 >= 0) - 1;
+  //v117 = 1;
   terrain_76E3C8[0] = 65535;
   terrain_76DDC8[0] = 65535;
   terrain_76DFC8[0] = 65535;
-  while ( 1 )
-  {
-    if ( v112 >= 65536 )
-    {
-      v111 = 4294967296i64 / v112;
+  for( v116=1; v116 < 128; v116++)
+  {
+    if ( v112 >= 0x10000 )
+    {
+      int v1, v2;
+      /*v111 = 4294967296i64 / v112;
       v114 += v111;
       if ( v114 >= 65536 )
       {
         v11 += v110;
         v114 = (unsigned __int16)v114;
       }
-      v12 += v109;
+      v12 += v109;*/
     }
     else
     {
       v11 += v110;
       v115 += v112;
-      if ( v115 >= 65536 )
+      if ( v112 + v115 >= 65536 )
       {
         v12 += v109;
         v115 = (unsigned __int16)v115;
       }
     }
-    if ( v116 > 128 || v11 < i || v11 > v120 || v12 < v122 || v12 > v119 )
+    if ( v11 < i || v11 > v120 || v12 < v122 || v12 > v119 )
       break;
-    v13 = v116++;
-    terrain_76E3C8[v13] = v11;
-    terrain_76E1C8[v13] = v12;
-  }
-  while ( 1 )
+    //v13 = v116++;
+    terrain_76E3C8[v116] = v11;
+    terrain_76E1C8[v116] = v12;
+  }
+
+  for( v117=1; v117 < 128; v117++ )
   {
     if ( v108 >= 65536 )
     {
       v111 = 4294967296i64 / v108;
-      a1 = (IndoorCameraD3D *)((char *)a1 + v111);
-      if ( (signed int)a1 >= 65536 )
-      {
-        LODWORD(v126) += v107;
-        a1 = (IndoorCameraD3D *)(unsigned __int16)a1;
+      v114 += v111;//
+      if ( v111 + v114 >= 65536 )
+      {
+        v126 += v107;
+        v114 = (unsigned __int16)v114;//
       }
       v118 += v106;
     }
     else
     {
       v125 += v108;
-      LODWORD(v126) += v107;
+      v126 += v107;
       if ( v125 >= 65536 )
       {
         v118 += v106;
         v125 = (unsigned __int16)v125;
       }
     }
-    if ( v117 >= 128 )
+    //if ( v117 >= 128 )
+      //break;
+    if ( v126 < i )
       break;
-    if ( SLODWORD(v126) < i )
-      break;
-    if ( SLODWORD(v126) > v120 )
+    if ( v126 > v120 )
       break;
     v14 = v118;
     if ( v118 < v122 )
       break;
     if ( v118 > v119 )
       break;
-    v15 = v117++;
-    terrain_76DFC8[v15] = LODWORD(v126);
-    terrain_76DDC8[v15] = v14;
-  }
-  LODWORD(v16) = 0;
-  LODWORD(v126) = 0;
+    terrain_76DFC8[v117] = v126;
+    terrain_76DDC8[v117] = v14;
+  }
+  v16 = 0;
+  v126 = 0;
   v17 = v117 - 1;
   v18 = v116 - 1;
   switch ( pHeight )
   {
     case 0:
     case 7:
+    {
       v116 = terrain_76DFC8[v17];
       if ( v120 > v116 )
       {
         v125 = v120;
-        memset32(terrain_76D9C8, v119 + 1, v120 - v116 + 1);
+        memset32(terrain_76D9C8, v119 + 1, 4 * (v120 - v116 + 1));
         v19 = v120;
         do
-          terrain_76DBC8[LODWORD(v126)++] = v19--;
+          terrain_76DBC8[v126++] = v19--;
         while ( v19 >= v116 );
         if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
         {
           do
-            v20 = terrain_76DDC8[v17-- + 127];
-          while ( v20 == terrain_76DDC8[v17 + 127] );
+            v20 = terrain_76DDC8[v17-- -1];
+          while ( v20 == terrain_76DDC8[v17 -1] );
         }
         v16 = v126;
         --v17;
@@ -1177,48 +1180,48 @@
       while ( 1 )
       {
         v125 = v21;
-        if ( v21 < SLODWORD(v124) )
+        if ( v21 < v124 )
           break;
-        terrain_76DBC8[LODWORD(v16)] = v21;
+        terrain_76DBC8[v16] = v21;
         v22 = terrain_76DDC8[v17] == 65535;
-        terrain_76D9C8[LODWORD(v16)] = terrain_76DDC8[v17] + 1;
+        terrain_76D9C8[v16] = terrain_76DDC8[v17] + 1;
         if ( v22 )
         {
-          terrain_76D9C8[LODWORD(v16)] = v123 + 1;
+          terrain_76D9C8[v16] = v123 + 1;
           break;
         }
         if ( !v17 )
           break;
-        if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
+        if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 - 1] )
         {
           do
-            v23 = terrain_76DDC8[v17-- + 127];
-          while ( v23 == terrain_76DDC8[v17 + 127] );
+            v23 = terrain_76DDC8[v17-- -1];
+          while ( v23 == terrain_76DDC8[v17 -1] );
         }
         --v17;
         v21 = v125 - 1;
-        ++LODWORD(v16);
-      }
-      LODWORD(v16) = 0;
+        ++v16;
+      }
+      v16 = 0;
       v24 = terrain_76E3C8[v18];
-      LODWORD(v126) = 0;
+      v126 = 0;
       if ( v120 > v24 )
       {
         v125 = v120;
-        memset32(terrain_76D5C8, v122, v120 - v24 + 1);
+        memset32(terrain_76D5C8, v122, 4 * (v120 - v24 + 1));
         do
         {
           v25 = v126;
           v26 = v125--;
-          ++LODWORD(v126);
-          terrain_76D7C8[LODWORD(v25)] = v26;
+          ++v126;
+          terrain_76D7C8[v25] = v26;
         }
         while ( v125 >= terrain_76E3C8[v18] );
-        if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 + 127] )
+        if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 -1] )
         {
           do
-            v27 = terrain_76E1C8[v18-- + 127];
-          while ( v27 == terrain_76E1C8[v18 + 127] );
+            v27 = terrain_76E1C8[v18-- -1];
+          while ( v27 == terrain_76E1C8[v18 -1] );
         }
         v16 = v126;
         --v18;
@@ -1226,48 +1229,51 @@
       if ( v18 < 0 )
         v18 = 0;
       v28 = terrain_76E3C8[v18];
-      while ( v28 >= SLODWORD(v124) )
+      while ( v28 >= v124 )
       {
         v29 = terrain_76E1C8[v18];
-        terrain_76D7C8[LODWORD(v16)] = v28;
-        terrain_76D5C8[LODWORD(v16)] = v29;
+        terrain_76D7C8[v16] = v28;
+        terrain_76D5C8[v16] = v29;
         if ( v29 == 65535 )
         {
           v31 = v123;
-          goto LABEL_172;
+          terrain_76D5C8[v16] = v31;
+          break;
         }
         if ( !v18 )
           break;
-        if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 + 127] )
+        if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 -1] )
         {
           do
-            v30 = terrain_76E1C8[v18-- + 127];
-          while ( v30 == terrain_76E1C8[v18 + 127] );
+            v30 = terrain_76E1C8[v18-- -1];
+          while ( v30 == terrain_76E1C8[v18 -1] );
         }
         --v18;
         --v28;
-        ++LODWORD(v16);
+        ++v16;
       }
       break;
+    }
     case 1:
     case 2:
+    {
       v116 = terrain_76DDC8[v17];
       if ( v122 < v116 )
       {
         v106 = v122;
-        memset32(terrain_76DBC8, v120 + 1, v116 - v122 + 1);
+        memset32(terrain_76DBC8, v120 + 1, 4 * (v116 - v122 + 1));
         v32 = v122;
         do
         {
-          v33 = LODWORD(v126)++;
+          v33 = v126++;
           terrain_76D9C8[v33] = v32++;
         }
         while ( v32 <= v116 );
-        if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 + 127] )
+        if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 -1] )
         {
           do
-            v34 = terrain_76DBC8[v17-- + 127];
-          while ( v34 == terrain_76DBC8[v17 + 127] );
+            v34 = terrain_76DBC8[v17-- -1];
+          while ( v34 == terrain_76DBC8[v17 -1] );
         }
         v16 = v126;
         --v17;
@@ -1279,47 +1285,47 @@
       while ( v35 <= v123 )
       {
         v22 = terrain_76DFC8[v17] == 65535;
-        terrain_76DBC8[LODWORD(v16)] = terrain_76DFC8[v17] + 1;
-        terrain_76D9C8[LODWORD(v16)] = v125;
+        terrain_76DBC8[v16] = terrain_76DFC8[v17] + 1;
+        terrain_76D9C8[v16] = v125;
         if ( v22 )
         {
-          terrain_76DBC8[LODWORD(v16)] = LODWORD(v124) + 1;
+          terrain_76DBC8[v16] = v124 + 1;
           break;
         }
         if ( !v17 )
           break;
-        if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 + 127] )
+        if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 -1] )
         {
           do
-            v36 = terrain_76DBC8[v17-- + 127];
-          while ( v36 == terrain_76DBC8[v17 + 127] );
+            v36 = terrain_76DBC8[v17-- -1];
+          while ( v36 == terrain_76DBC8[v17 -1] );
         }
         --v17;
         ++v125;
         v35 = v125;
-        ++LODWORD(v16);
-      }
-      LODWORD(v16) = 0;
-      LODWORD(v126) = 0;
+        ++v16;
+      }
+      v16 = 0;
+      v126 = 0;
       v37 = terrain_76E1C8[v18];
       if ( v122 < v37 )
       {
-        a1 = (IndoorCameraD3D *)v122;
-        memset32(terrain_76D7C8, i, v37 - v122 + 1);
+        v114 = v122;
+        memset32(terrain_76D7C8, i, 4 * (v37 - v122 + 1));
         do
         {
           v38 = v126;
-          v39 = a1;
-          ++LODWORD(v126);
-          a1 = (IndoorCameraD3D *)((char *)a1 + 1);
-          terrain_76D5C8[LODWORD(v38)] = (int)v39;
-        }
-        while ( (signed int)a1 <= terrain_76E1C8[v18] );
-        if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 + 127] )
+          v39 = v114;
+          ++v126;
+          ++v114;
+          terrain_76D5C8[v38] = v39;
+        }
+        while ( v114 <= terrain_76E1C8[v18] );
+        if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 -1] )
         {
           do
-            v40 = terrain_76DFC8[v18-- + 127];
-          while ( v40 == terrain_76DFC8[v18 + 127] );
+            v40 = terrain_76DFC8[v18-- -1];
+          while ( v40 == terrain_76DFC8[v18 -1] );
         }
         v16 = v126;
         --v18;
@@ -1330,42 +1336,44 @@
       while ( v41 <= v123 )
       {
         v42 = terrain_76E3C8[v18];
-        terrain_76D5C8[LODWORD(v16)] = v41;
-        terrain_76D7C8[LODWORD(v16)] = v42;
+        terrain_76D5C8[v16] = v41;
+        terrain_76D7C8[v16] = v42;
         if ( v42 == 65535 )
         {
-          v44 = LODWORD(v124);
-          goto LABEL_137;
+          terrain_76D7C8[v16] = v124;
+          break;
         }
         if ( !v18 )
           break;
-        if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 + 127] )
+        if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 -1] )
         {
           do
-            v43 = terrain_76DFC8[v18-- + 127];
-          while ( v43 == terrain_76DFC8[v18 + 127] );
+            v43 = terrain_76DFC8[v18-- -1];
+          while ( v43 == terrain_76DFC8[v18 -1] );
         }
         --v18;
         ++v41;
-        ++LODWORD(v16);
+        ++v16;
       }
       break;
+    }
     case 5:
     case 6:
+    {
       v116 = terrain_76DDC8[v17];
       if ( v119 > v116 )
       {
         v106 = v119;
-        memset32(terrain_76DBC8, i, v119 - v116 + 1);
+        memset32(terrain_76DBC8, i, 4 * (v119 - v116 + 1));
         v45 = v119;
         do
-          terrain_76D9C8[LODWORD(v126)++] = v45--;
+          terrain_76D9C8[v126++] = v45--;
         while ( v45 >= v116 );
-        if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 + 127] )
+        if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 -1] )
         {
           do
-            v46 = terrain_76DBC8[v17-- + 127];
-          while ( v46 == terrain_76DBC8[v17 + 127] );
+            v46 = terrain_76DBC8[v17-- -1];
+          while ( v46 == terrain_76DBC8[v17 -1] );
         }
         v16 = v126;
         --v17;
@@ -1377,46 +1385,46 @@
       while ( v47 >= v123 )
       {
         v22 = terrain_76DFC8[v17] == 65535;
-        terrain_76DBC8[LODWORD(v16)] = terrain_76DFC8[v17];
-        terrain_76D9C8[LODWORD(v16)] = v125;
+        terrain_76DBC8[v16] = terrain_76DFC8[v17];
+        terrain_76D9C8[v16] = v125;
         if ( v22 )
         {
-          terrain_76DBC8[LODWORD(v16)] = LODWORD(v124);
+          terrain_76DBC8[v16] = v124;
           break;
         }
         if ( !v17 )
           break;
-        if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 + 127] )
+        if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 -1] )
         {
           do
-            v48 = terrain_76DBC8[v17-- + 127];
-          while ( v48 == terrain_76DBC8[v17 + 127] );
+            v48 = terrain_76DBC8[v17-- -1];
+          while ( v48 == terrain_76DBC8[v17 -1] );
         }
         --v17;
         --v125;
         v47 = v125;
-        ++LODWORD(v16);
-      }
-      LODWORD(v16) = 0;
+        ++v16;
+      }
+      v16 = 0;
       v49 = terrain_76E1C8[v18];
-      LODWORD(v126) = 0;
+      v126 = 0;
       if ( v119 > v49 )
       {
         v125 = v119;
-        memset32(terrain_76D7C8, v120 + 1, v119 - v49 + 1);
+        memset32(terrain_76D7C8, v120 + 1, 4 * (v119 - v49 + 1));
         do
         {
           v50 = v126;
           v51 = v125--;
-          ++LODWORD(v126);
-          terrain_76D5C8[LODWORD(v50)] = v51;
+          ++v126;
+          terrain_76D5C8[v50] = v51;
         }
         while ( v125 >= terrain_76E1C8[v18] );
-        if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 + 127] )
+        if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 -1] )
         {
           do
-            v52 = terrain_76DFC8[v18-- + 127];
-          while ( v52 == terrain_76DFC8[v18 + 127] );
+            v52 = terrain_76DFC8[v18-- -1];
+          while ( v52 == terrain_76DFC8[v18 -1] );
         }
         v16 = v126;
         --v18;
@@ -1427,47 +1435,47 @@
       while ( v53 >= v123 )
       {
         v54 = terrain_76E3C8[v18];
-        terrain_76D5C8[LODWORD(v16)] = v53;
-        terrain_76D7C8[LODWORD(v16)] = v54 + 1;
+        terrain_76D5C8[v16] = v53;
+        terrain_76D7C8[v16] = v54 + 1;
         if ( v54 == 65535 )
         {
-          v44 = LODWORD(v124) + 1;
-LABEL_137:
-          terrain_76D7C8[LODWORD(v16)] = v44;
-          goto LABEL_173;
+          terrain_76D7C8[v16] = v124 + 1;
+          break;
         }
         if ( !v18 )
-          goto LABEL_173;
-        if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 + 127] )
+          break;
+        if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 -1] )
         {
           do
-            v55 = terrain_76DFC8[v18-- + 127];
-          while ( v55 == terrain_76DFC8[v18 + 127] );
+            v55 = terrain_76DFC8[v18-- -1];
+          while ( v55 == terrain_76DFC8[v18 -1] );
         }
         --v18;
         --v53;
-        ++LODWORD(v16);
+        ++v16;
       }
       break;
+    }
     case 3:
     case 4:
+    {
       v116 = terrain_76DFC8[v17];
       if ( i < v116 )
       {
         v106 = i;
-        memset32(terrain_76D9C8, v122, v116 - i + 1);
+        memset32(terrain_76D9C8, v122, 4 * (v116 - i + 1));
         v56 = i;
         do
         {
-          v57 = LODWORD(v126)++;
+          v57 = v126++;
           terrain_76DBC8[v57] = v56++;
         }
         while ( v56 <= v116 );
-        if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
+        if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 -1] )
         {
           do
-            v58 = terrain_76DDC8[v17-- + 127];
-          while ( v58 == terrain_76DDC8[v17 + 127] );
+            v58 = terrain_76DDC8[v17-- -1];
+          while ( v58 == terrain_76DDC8[v17 -1] );
         }
         v16 = v126;
         --v17;
@@ -1478,49 +1486,49 @@
       while ( 1 )
       {
         v125 = v59;
-        if ( v59 > SLODWORD(v124) )
+        if ( v59 > v124 )
           break;
-        terrain_76DBC8[LODWORD(v16)] = v59;
+        terrain_76DBC8[v16] = v59;
         v60 = terrain_76DDC8[v17];
-        terrain_76D9C8[LODWORD(v16)] = v60;
+        terrain_76D9C8[v16] = v60;
         if ( v60 == 65535 )
         {
-          terrain_76D9C8[LODWORD(v16)] = v123;
+          terrain_76D9C8[v16] = v123;
           break;
         }
         if ( !v17 )
           break;
-        if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
+        if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 -1] )
         {
           do
-            v61 = terrain_76DDC8[v17-- + 127];
-          while ( v61 == terrain_76DDC8[v17 + 127] );
+            v61 = terrain_76DDC8[v17-- -1];
+          while ( v61 == terrain_76DDC8[v17 -1] );
         }
         --v17;
         v59 = v125 + 1;
-        ++LODWORD(v16);
-      }
-      LODWORD(v16) = 0;
-      LODWORD(v126) = 0;
+        ++v16;
+      }
+      v16 = 0;
+      v126 = 0;
       v62 = terrain_76E3C8[v18];
       if ( i < v62 )
       {
-        a1 = (IndoorCameraD3D *)i;
-        memset32(terrain_76D5C8, v119 + 1, v62 - i + 1);
+        v114 = i;
+        memset32(terrain_76D5C8, v119 + 1, 4 * (v62 - i + 1));
         do
         {
           v63 = v126;
-          v64 = a1;
-          ++LODWORD(v126);
-          a1 = (IndoorCameraD3D *)((char *)a1 + 1);
-          terrain_76D7C8[LODWORD(v63)] = (int)v64;
-        }
-        while ( (signed int)a1 <= terrain_76E3C8[v18] );
-        if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 + 127] )
+          v64 = v114;
+          ++v126;
+          ++v114;
+          terrain_76D7C8[v63] = v64;
+        }
+        while ( v114 <= terrain_76E3C8[v18] );
+        if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 -1] )
         {
           do
-            v65 = terrain_76E1C8[v18-- + 127];
-          while ( v65 == terrain_76E1C8[v18 + 127] );
+            v65 = terrain_76E1C8[v18-- -1];
+          while ( v65 == terrain_76E1C8[v18 -1] );
         }
         v16 = v126;
         --v18;
@@ -1528,106 +1536,113 @@
       if ( v18 < 0 )
         v18 = 0;
       v66 = terrain_76E3C8[v18];
-      while ( v66 <= SLODWORD(v124) )
+      while ( v66 <= v124 )
       {
         v67 = terrain_76E1C8[v18];
-        terrain_76D7C8[LODWORD(v16)] = v66;
-        terrain_76D5C8[LODWORD(v16)] = v67 + 1;
+        terrain_76D7C8[v16] = v66;
+        terrain_76D5C8[v16] = v67 + 1;
         if ( v67 == 65535 )
         {
           v31 = v123 + 1;
-LABEL_172:
-          terrain_76D5C8[LODWORD(v16)] = v31;
-          goto LABEL_173;
+          terrain_76D5C8[v16] = v31;
+          break;
         }
         if ( !v18 )
-          goto LABEL_173;
-        if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 + 127] )
+          break;
+        if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 -1] )
         {
           do
-            v68 = terrain_76E1C8[v18-- + 127];
-          while ( v68 == terrain_76E1C8[v18 + 127] );
+            v68 = terrain_76E1C8[v18-- -1];
+          while ( v68 == terrain_76E1C8[v18 -1] );
         }
         --v18;
         ++v66;
-        ++LODWORD(v16);
+        ++v16;
       }
       break;
+    }
     default:
       break;
   }
-LABEL_173:
-  v69 = LODWORD(v16) - 1;
+  v69 = v16 - 1;
   ptr_801A08 = pVerticesSR_806210;
   ptr_801A04 = pVerticesSR_801A10;
-  LODWORD(v126) = v69;
+  v126 = v69;
   if ( pHeight && pHeight != 7 && pHeight != 3 && pHeight != 4 )
   {
     for ( i = v69; i >= 1; --i )
     {
-      v70 = i;
+      //v70 = i;
       v71 = terrain_76D7C8[i];
       v72 = terrain_76DBC8[i];
-      if ( v71 < v72 )
-      {
-        terrain_76DBC8[v70] = v71;
-        terrain_76D7C8[v70] = v72;
-      }
-      v73 = terrain_76DBC8[v70];
+      if ( v71 < v72 )//swap
+      {
+        terrain_76DBC8[i] = v71;
+        terrain_76D7C8[i] = v72;
+      }
+      v73 = terrain_76DBC8[i];
       v111 = 0;
       if ( v73 <= 0 )
         v73 = -v73;
-      v74 = terrain_76D7C8[v70];
+      v74 = terrain_76D7C8[i];
       if ( v74 <= 0 )
         v74 = -v74;
       v75 = v74 + 2;
-      v76 = pGame->pIndoorCameraD3D;
+      //pIndoorCameraD3D_3 = pGame->pIndoorCameraD3D;
       v107 = v75;
-      a1 = v76;
+      //pIndoorCameraD3D_4 = pIndoorCameraD3D_3;
       v77 = v73 - 2;
       if ( v73 - 2 < v75 )
       {
         v127 = 0;
-        v79 = (v73 - 66) << 9;
-        v116 = v77;
-        pHeight = v79;
+        //v79 = (v73 - 66) << 9;
+        //v116 = v77;
+        //pHeight = v79;
         v111 = v75 - v77;
-        do
+        for (int j = v77; j < v107; ++j)
         {// âûñîòà ÷åòûðåõ âåðøèí ÿ÷åéêè
-		  *(float *)&v106 = (double)pHeight;
+		  /* *(float *)&v106 = (double)pHeight;
           *(float *)((char *)&ptr_801A08->vWorldPosition.x + v127) = *(float *)&v106;//x
           pHeight = (64 - *(int *)((char *)terrain_76D9C8 + v70)) << 9;
           *(float *)((char *)&ptr_801A08->vWorldPosition.y + v127) = (double)pHeight;//y
           pHeight = pOutdoor->GetHeightOnTerrain(v112, *(int *)((char *)terrain_76D9C8 + v70));
-          *(float *)((char *)&ptr_801A08->vWorldPosition.z + v127) = (double)pHeight;//z
-          *(float *)((char *)&ptr_801A04->vWorldPosition.x + v127) = *(float *)&v106;//x
+          *(float *)((char *)&ptr_801A08->vWorldPosition.z + v127) = (double)pHeight;//z*/
+          ptr_801A08[v127].vWorldPosition.x = (v73 - 66 + v127) * 512;
+          ptr_801A08[v127].vWorldPosition.y = (64 - terrain_76D9C8[i]) * 512;
+          ptr_801A08[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( j, terrain_76D9C8[i]);
+
+          /* *(float *)((char *)&ptr_801A04->vWorldPosition.x + v127) = *(float *)&v106;//x
           pHeight = (63 - *(int *)((char *)terrain_76D9C8 + v70)) << 9;
           *(float *)((char *)&ptr_801A04->vWorldPosition.y + v127) = (double)pHeight;//y
           pHeight = pOutdoor->GetHeightOnTerrain(v112, *(int *)((char *)terrain_76D9C8 + v70) + 1);
-          *(float *)((char *)&ptr_801A04->vWorldPosition.z + v127) = (double)pHeight;//z
+          *(float *)((char *)&ptr_801A04->vWorldPosition.z + v127) = (double)pHeight;//z */
+          ptr_801A04[v127].vWorldPosition.x = (v73 - 66 + v127) * 512;
+          ptr_801A04[v127].vWorldPosition.y = (63 - terrain_76D9C8[i]) * 512;
+          ptr_801A04[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( j, terrain_76D9C8[i] + 1);
+
           if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
           {
-            a1->ViewTransform((RenderVertexSoft *)(char *)ptr_801A08 + v127, 1);
-            a1->ViewTransform((RenderVertexSoft *)(char *)ptr_801A04 + v127, 1);
-            a1->Project((RenderVertexSoft *)(char *)ptr_801A08 + v127, 1, 0);
-            a1->Project((RenderVertexSoft *)(char *)ptr_801A04 + v127, 1, 0);
+            pIndoorCameraD3D_4->ViewTransform(&ptr_801A08[v127], 1);
+            pIndoorCameraD3D_4->ViewTransform(&ptr_801A04[v127], 1);
+            pIndoorCameraD3D_4->Project(&ptr_801A08[v127], 1, 0);
+            pIndoorCameraD3D_4->Project(&ptr_801A04[v127], 1, 0);
           }
-          v79 += 512;
-          v127 += 48;
-          ++v116;
-          pHeight = v79;
+          //v79 += 512;
+          v127 ++;
+          //++v116;
+          //pHeight = v79;
 		}
-        while ( v116 < v107 );
-      }
-	  v103 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[v70]);
-      v104 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[v70]);
-	  //if ( pRenderer->pRenderD3D )//Ritor1: do comment to test
-        //Render::DrawTerrainD3D(v111, 0, (int)&v102);
-      //else
-        //Render::DrawTerrainSW(v111, 0, (int)&v102);
-    }
-  }
-  else
+        //while ( v116 < v107 );
+      }
+	  v102.v103 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[i]);
+      v102.v104 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[i]);
+	  if ( pRenderer->pRenderD3D )//Ritor1: do comment to test
+        Render::DrawTerrainD3D(v111, 1, (int)&v102);
+      else
+        Render::DrawTerrainSW(v111, 0, (int)&v102);
+    }
+  }
+/*  else
   {
     for ( i = v69; i >= 1; --i )
     {
@@ -1646,7 +1661,7 @@
       v90 = terrain_76D5C8[v86];
       if ( v90 <= 0 )
         v90 = -v90;
-      a1 = pGame->pIndoorCameraD3D;
+      pIndoorCameraD3D_4 = pGame->pIndoorCameraD3D;
       v107 = v90 + 2;
       if ( v89 - 2 < v90 + 2 )
       {
@@ -1672,10 +1687,10 @@
           *(float *)((char *)&ptr_801A04->vWorldPosition.z + v86) = (double)pHeight;
           if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
           {
-           a1->ViewTransform((RenderVertexSoft *)(char *)ptr_801A08 + v86, 1);
-           a1->ViewTransform((RenderVertexSoft *)(char *)ptr_801A04 + v86, 1);
-           a1->Project((RenderVertexSoft *)(char *)ptr_801A08 + v86, 1, 0);
-           a1->Project((RenderVertexSoft *)(char *)ptr_801A04 + v86, 1, 0);
+           pIndoorCameraD3D_4->ViewTransform((RenderVertexSoft *)(char *)ptr_801A08 + v86, 1);
+           pIndoorCameraD3D_4->ViewTransform((RenderVertexSoft *)(char *)ptr_801A04 + v86, 1);
+           pIndoorCameraD3D_4->Project((RenderVertexSoft *)(char *)ptr_801A08 + v86, 1, 0);
+           pIndoorCameraD3D_4->Project((RenderVertexSoft *)(char *)ptr_801A04 + v86, 1, 0);
           }
           v92 -= 512;
           v86 += 48;
@@ -1686,12 +1701,12 @@
       }
       v103 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[v86]);
 	  v104 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[v86]);
-	  //if ( pRenderer->pRenderD3D )
-        //Render::DrawTerrainD3D(v111, 1, (int)&v102);
-      //else
-        //Render::DrawTerrainSW(v111, 1, (int)&v102);
-    }
-  }
+	  if ( pRenderer->pRenderD3D )
+        Render::DrawTerrainD3D(v111, 1, (int)&v102);
+      else
+        Render::DrawTerrainSW(v111, 1, (int)&v102);
+    }
+  }*/
   result = v126;
   pOutdoorCamera->field_40 = v126;
   return result;
@@ -1702,7 +1717,7 @@
 
 
 //----- (0048034E) --------------------------------------------------------
-void Render::DrawTerrainD3D(int a1, int edx0, int a3)
+void Render::DrawTerrainD3D(int a1, int a2, int a3)
 {
   int v3; // esi@1
   int v4; // edi@1
@@ -1720,8 +1735,8 @@
   stru148 *v16; // ebx@12
   unsigned __int16 v17; // ax@12
   int v18; // eax@13
-  LightmapBuilder *v19; // ecx@13
-  stru220 *v20; // eax@13
+  int v19; // ecx@13
+  int v20; // eax@13
   int v21; // eax@13
   signed int v22; // eax@13
   Vec3_float_ *v23; // eax@15
@@ -1733,7 +1748,8 @@
   double v29; // st5@19
   double v30; // st5@19
   double v31; // st5@19
-  double v32; // st7@32
+  struct struct8 *v32; // esi@21
+  double v3a; // st7@32
   int v33; // edi@38
   unsigned int v34; // ecx@47
   char v35; // zf@47
@@ -1745,7 +1761,7 @@
   unsigned __int16 v41; // ax@62
   int v42; // eax@63
   LightmapBuilder *v43; // ecx@63
-  stru220 *v44; // eax@63
+  int v44; // eax@63
   int v45; // eax@63
   int v46; // eax@63
   signed int v47; // eax@63
@@ -1762,7 +1778,7 @@
   unsigned int v58; // eax@109
   stru148 *v59; // esi@112
   unsigned __int16 v60; // ax@112
-  stru220 *v61; // eax@113
+  int v61; // eax@113
   signed int v62; // eax@113
   Vec3_float_ *v63; // eax@114
   double v64; // st6@116
@@ -1775,10 +1791,10 @@
   RenderVertexSoft *v71; // esi@147
   unsigned int v72; // ecx@147
   unsigned int v73; // eax@150
-  float v74; // eax@154
+  int v74; // eax@154
   unsigned int v75; // eax@158
   unsigned int v76; // [sp-10h] [bp-E0h]@61
-  stru148 *v77; // [sp-Ch] [bp-DCh]@61
+  int v77; // [sp-Ch] [bp-DCh]@61
   IDirect3DTexture2 *v78; // [sp-8h] [bp-D8h]@61
   int v79; // [sp-4h] [bp-D4h]@61
   int v80; // [sp+0h] [bp-D0h]@59
@@ -1794,21 +1810,21 @@
   float v90; // [sp+84h] [bp-4Ch]@1
   float v91; // [sp+88h] [bp-48h]@1
   float v92; // [sp+8Ch] [bp-44h]@1
-  stru220 *v93; // [sp+90h] [bp-40h]@2
+  int v93; // [sp+90h] [bp-40h]@2
   int X; // [sp+94h] [bp-3Ch]@1
   float v95; // [sp+98h] [bp-38h]@21
   LightmapBuilder *v96; // [sp+9Ch] [bp-34h]@73
-  LightmapBuilder *_this; // [sp+A0h] [bp-30h]@6
+  int v97; // [sp+A0h] [bp-30h]@6
   int sX; // [sp+A4h] [bp-2Ch]@6
   unsigned int uNumVertices; // [sp+A8h] [bp-28h]@73
   int v100; // [sp+ACh] [bp-24h]@122
   int sY; // [sp+B0h] [bp-20h]@6
-  RenderVertexSoft *a2; // [sp+B4h] [bp-1Ch]@3
+  RenderVertexSoft *v102; // [sp+B4h] [bp-1Ch]@3
   unsigned int a5; // [sp+B8h] [bp-18h]@21
   RenderVertexSoft *v101; // [sp+BCh] [bp-14h]@6
   Vec3_float_ *v99; // [sp+C0h] [bp-10h]@17
   RenderVertexSoft *pVertices; // [sp+C4h] [bp-Ch]@6
-  RenderVertexSoft *a8; // [sp+C8h] [bp-8h]@6
+  RenderVertexSoft *pVertices2; // [sp+C8h] [bp-8h]@6
   char v108; // [sp+CFh] [bp-1h]@36
   float thisd; // [sp+D8h] [bp+8h]@6
   float thise; // [sp+D8h] [bp+8h]@6
@@ -1822,16 +1838,18 @@
   char this_3a; // [sp+DBh] [bp+Bh]@82
   char this_3b; // [sp+DBh] [bp+Bh]@131
 
+  static stru154 static_sub_0048034E_stru_154;
+  static stru154 stru_76D5A8;
   v3 = a1;
-  v82 = edx0;
+  v82 = a2;
   v83 = *(/*short **/_WORD *)(a3 + 4);
   X = abs(*(/*short **/_WORD *)(a3 + 6));
   v4 = 0;
   v88 = 0;
   v84 = v3 - 1;
-  v90 = (double)pOutdoor->vSunlight.x * 0.000015258789;
-  v91 = (double)pOutdoor->vSunlight.y * 0.000015258789;
-  v92 = (double)pOutdoor->vSunlight.z * 0.000015258789;
+  v90 = (float)pOutdoor->vSunlight.x / 65536,0;
+  v91 = (float)pOutdoor->vSunlight.y / 65536.0;
+  v92 = (float)pOutdoor->vSunlight.z / 65536.0;
   if ( v3 - 1 > 0 )
   {
     while ( 1 )
@@ -1839,8 +1857,8 @@
       v5 = abs(X);//v5 = 13108
       v6 = abs(v83);//v6 = 13108
       --X;
-      v93 = &stru_76E5C8[(v5 << 7) + v6];
-      if ( !v93->field_0 || ((v7 = 48 * v4, v8 = &pVerticesSR_806210[v4], a2 = v8, !v82) ? (v9 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7),
+      v93 = (int)&stru_76E5C8[(v5 << 7) + v6];
+      /*if ( !v93->field_0 || ((v7 = 48 * v4, v8 = &pVerticesSR_806210[v4], a2 = v8, !v82) ? (v9 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7),
                                                                        v10 = &pVerticesSR_806210[1] + v7) : (v9 = &pVerticesSR_806210[1] + v7, v10 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7)),
              ((a8 = v9,
                pVertices = &pVerticesSR_801A10[1] + v7,
@@ -1860,78 +1878,99 @@
                WorldPosToGridCellZ(sY),
                !byte_4D864C)
            || !(pGame->uFlags & 0x80))
-          && !sub_481EFA(v8, v9, v101, pVertices, 1)) )
+          && !sub_481EFA(v8, v9, v101, pVertices, 1)) )*/
+      if ( !&stru_76E5C8[(v5 << 7) + v6] )
         goto LABEL_162;
-      if ( v8->vWorldPosition.z != v9->vWorldPosition.z || v9->vWorldPosition.z != pVertices->vWorldPosition.z || pVertices->vWorldPosition.z != v101->vWorldPosition.z )
-        break;
-      v16 = &array_77EC08[pOutdoorCamera->numStru148s];
-      v17 = pOutdoor->GetTileTexture(sX, sY);
-      v16->uTileBitmapID = v17;
-      if ( v17 != -1 )
-      {
-        v18 = pOutdoor->GetSomeOtherTileInfo(sX, sY);
-        LOWORD(v18) = v18 | 0x8010;
-        v19 = _this;
-        *(int *)&v16->flags = v18;
-        v20 = v93;
-        v16->field_59 = 1;
-        v16->field_5D = (char)v19;
-        v16->field_34 = v20->distance;
-        v21 = v89;
-        v16->field_5C = v89;
-        v22 = pTerrainNormalIndices[2 * (signed int)((char *)v19 + 128 * v21) + 1];
-        if ( v22 < 0 || v22 > (signed int)(uNumTerrainNormals - 1) )
+      
+      v8 = &pVerticesSR_806210[v4];
+      pVertices2 = &pVerticesSR_801A10[v4 + 1];
+      v102 = v8;
+      if (!v82)
+      {
+       pVertices = &pVerticesSR_801A10[v4];
+       v101 = &pVerticesSR_806210[v4 + 1];
+      }
+      else
+      {
+       pVertices = &pVerticesSR_801A10[v4 + 1];
+       v101 = &pVerticesSR_806210[v4];
+      }
+
+      sX = floorf(v8->vWorldPosition.x + 0.5f);
+      sY = floorf(v8->vWorldPosition.z + 0.5f);
+
+      v89 = WorldPosToGridCellX(floorf((v101->vWorldPosition.x + v8->vWorldPosition.x) / 2 + 0.5f));
+      v97 = WorldPosToGridCellZ(floorf((pVertices->vWorldPosition.z + v8->vWorldPosition.z) / 2 + 0.5f));
+      WorldPosToGridCellX(sX);
+      WorldPosToGridCellZ(sY);
+
+      if ((!byte_4D864C || !(pGame->uFlags & 0x80)) && !sub_481EFA(v8, pVertices, v101, pVertices2, 1))
+        if ( v8->vWorldPosition.y != pVertices->vWorldPosition.y || pVertices->vWorldPosition.y != pVertices2->vWorldPosition.y || pVertices2->vWorldPosition.y != v101->vWorldPosition.y )
+          break;
+        v16 = &array_77EC08[pOutdoorCamera->numStru148s];
+        v16->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY);
+          if ( v16->uTileBitmapID != -1 )
+          {
+            v19 = v97;
+            v16->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(sX, sY);
+            v16->field_32 = 0;
+            v20 = v93;
+            v16->field_59 = 1;
+            v16->field_5D = (char)v19;
+            v16->field_34 = *(_WORD *)(v20 + 2);
+            v21 = v89;
+            v16->field_5C = v89;
+            v22 = pTerrainNormalIndices[2 * (v19 + 128 * v21) + 1];
+        if ( v22 < 0 || v22 > uNumTerrainNormals - 1 )
           v23 = 0;
         else
           v23 = &pTerrainNormals[v22];
-        v24 = v92 * v23->z;
-        v99 = v23;
-        thisf = 20.0 - (-v24 - v91 * v23->y - v90 * v23->x) * 20.0;
-        v25 = thisf + 6.7553994e15;
-        v27 = pOutdoorCamera->numStru148s > 1999;
-        v26 = pOutdoorCamera->numStru148s - 1999 < 0;
-        v16->field_58 = LOBYTE(v25);
-        if ( !(v26 ^ v27) )
+        v24 = v92 * v23->y;
+        //v99 = v23;
+        thisf = 20.0 - (-v24 - v91 * v23->z - v90 * v23->x) * 20.0;
+        //v25 = thisf + 6.7553994e15;
+        //v27 = pOutdoorCamera->numStru148s > 1999;
+        //v26 = pOutdoorCamera->numStru148s - 1999 < 0;
+        v16->field_58 = floorf(thisf + 0.5f);
+        if ( pOutdoorCamera->numStru148s >= 1999 )
           return;
         ++pOutdoorCamera->numStru148s;
-        if ( !sub_481FC9(v8, a8, v101, v16) )
+        if ( !sub_481FC9(v8, pVertices, v101, v16) )
           //goto LABEL_126;
           {
            --pOutdoorCamera->numStru148s;
            goto LABEL_162;
           }
-        v28 = 1.0 / (a2->vWorldViewPosition.x + 0.0000001);
-        memcpy(array_50AC10, a2, 0x30u);
+        v28 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097);
+        memcpy(&array_50AC10[0], v102, 0x30u);
         array_50AC10[0].flt_20 = v28;
         array_50AC10[0].u = 0.0;
         array_50AC10[0].v = 0.0;
-        v29 = a8->vWorldViewPosition.x + 0.0000001;
-        memcpy(&array_50AC10[1], a8, sizeof(array_50AC10[1]));
+        v29 = pVertices->vWorldViewPosition.x + 0.0000001000000011686097;
+        memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1]));
         array_50AC10[1].flt_20 = 1.0 / v29;
         array_50AC10[1].u = 0.0;
         array_50AC10[1].v = 1.0;
-        v30 = pVertices->vWorldViewPosition.x + 0.0000001;
-        memcpy(&array_50AC10[2], pVertices, sizeof(array_50AC10[2]));
+        v30 = pVertices2->vWorldViewPosition.x + 0.0000001000000011686097;
+        memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2]));
         array_50AC10[2].flt_20 = 1.0 / v30;
         array_50AC10[2].u = 1.0;
         array_50AC10[2].v = 1.0;
-        v31 = v101->vWorldViewPosition.x + 0.0000001;
+        v31 = v101->vWorldViewPosition.x + 0.0000001000000011686097;
         memcpy(&array_50AC10[3], v101, sizeof(array_50AC10[3]));
         array_50AC10[3].flt_20 = 1.0 / v31;
         array_50AC10[3].u = 1.0;
         array_50AC10[3].v = 0.0;
 
-        static stru154 static_sub_0048034E_stru_154;
-        /*static bool __init_flag3 = false;
-        if (!__init_flag3)
-        {
-          __init_flag3 = true;
-
-          stru154::stru154(&static_sub_0048034E_stru_154);
+        /*if ( !(byte_76D5C0 & 1) )
+        {
+          byte_76D5C0 |= 1u;
+          stru154(stru_76D5A8);
+          atexit(loc_481199);
         }*/
-
-        _this = pGame->pLightmapBuilder;
-        pGame->pLightmapBuilder->StackLights_TerrainFace(v99, &v95, array_50AC10, 4u, 1);
+        v32 = (struct8 *)array_50AC10;
+        v97 = (int)pGame->pLightmapBuilder;
+        pGame->pLightmapBuilder->StackLights_TerrainFace(v99, &v95, array_50AC10, 4, 1);
         pDecalBuilder->_49BE8A(v16, *(float *)&v99, (int)&v95, array_50AC10, 4u, 1);
         a5 = 4;
         if ( byte_4D864C && pGame->uFlags & 0x80 )
@@ -1942,74 +1981,73 @@
           thisa->ViewTransform(array_50AC10, a5);
           thisa->Project(array_50AC10, a5, 0);
         }
-        this_3 = a2->vWorldViewPosition.x < 8.0
-              || a8->vWorldViewPosition.x < 8.0
+        this_3 = v102->vWorldViewPosition.x < 8.0
+              || pVertices->vWorldViewPosition.x < 8.0
               || v101->vWorldViewPosition.x < 8.0
-              || pVertices->vWorldViewPosition.x < 8.0;
-        v32 = (double)pOutdoorCamera->shading_dist_mist;
-        v108 = v32 < a2->vWorldViewPosition.x
-            || v32 < a8->vWorldViewPosition.x
-            || v32 < v101->vWorldViewPosition.x
-            || v32 < pVertices->vWorldViewPosition.x;
-        LOBYTE(v33) = 0;
+              || pVertices2->vWorldViewPosition.x < 8.0;
+        v3a = (double)pOutdoorCamera->shading_dist_mist;
+        v108 = v3a < v102->vWorldViewPosition.x
+            || v3a < pVertices->vWorldViewPosition.x
+            || v3a < v101->vWorldViewPosition.x
+            || v3a < pVertices2->vWorldViewPosition.x;
+        v33 = 0;
         pGame->pLightmapBuilder->std__vector_000004_size = 0;
         if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
         {
           if ( this_3 )
-            LOBYTE(v33) = 3;
+            v33 = 3;
           else
             v33 = v108 != 0 ? 5 : 0;
           static_sub_0048034E_stru_154._49B0C9(v99, v95);
           if ( pDecalBuilder->uNumDecals > 0 )
-            pDecalBuilder->ApplyDecals(
-              31 - v16->field_58,
+            pDecalBuilder->ApplyDecals(31 - v16->field_58,
               4,
               &static_sub_0048034E_stru_154,
               a5,
               array_50AC10,
               0,
-              v33,
+              *(float *)&v33,
               -1);
         }
         if ( stru_F8AD28.uNumLightsApplied > 0 )
           pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33);
         v34 = a5;
-        v35 = byte_4D864C == 0;
+        //v35 = byte_4D864C == 0;
         v16->uNumVertices = a5;
-        if ( v35 || !(pGame->uFlags & 0x80) )
+        if ( !byte_4D864C || ~pGame->uFlags & 0x80 )
         {
           if ( this_3 )
           {
             v36 = sr_424CD7(v34);
-            goto LABEL_53;
+            v16->uNumVertices = v36;
+            OutdoorCamera::Project(v36);
           }
           if ( v108 )
           {
             v36 = sr_424EE0_MakeFanFromTriangle(v34);
-LABEL_53:
             v16->uNumVertices = v36;
             OutdoorCamera::Project(v36);
           }
         }
-        v37 = *(int *)&v16->flags;
-        if ( !(BYTE1(v37) & 1) )
-        {
-          if ( v37 & 2 && v16->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
+        //v37 = *(int *)&v16->flags;
+        if ( ~v16->flags & 1 )
+        {
+          if ( v16->flags & 2 && v16->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
           {
-            v80 = 0;
+            v80 = false;
             v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
           }
           else
           {
             v39 = v16->uTileBitmapID;
-            v80 = 1;
+            v80 = true;
           }
-          v79 = 0;
+          //v79 = 0;
           v78 = pBitmaps_LOD->pHardwareTextures[v39];
-          v77 = v16;
+          v77 = (int)v16;
           v76 = v16->uNumVertices;
 //LABEL_161:
-          pRenderer->DrawTerrainPolygon(v76, v77, v78, v79, v80);
+          pRenderer->DrawTerrainPolygon(v76, v16, v78, false, v80);
           goto LABEL_162;
         }
         v38 = v16;
@@ -2017,8 +2055,8 @@
         v38->_4811A3();
       }
 LABEL_162:
-      v4 = v88++ + 1;
-      if ( v88 >= v84 )
+      v4 = v88 + 1;
+      if ( ++v88 >= v84 )
         return;
     }
     v40 = &array_77EC08[pOutdoorCamera->numStru148s];
@@ -2033,44 +2071,44 @@
     v44 = v93;
     v40->field_59 = 1;
     v40->field_5D = (char)v43;
-    v40->field_34 = v44->distance;
+    v40->field_34 = *(_WORD *)(v44 + 2);
     v45 = v89;
     v40->field_5C = v89;
-    v46 = 2 * (int)((char *)v43 + 128 * v45);
-    v85 = v46 * 2;
-    v47 = pTerrainNormalIndices[v46 + 1];
+    v46 = 4 * ((char)v43 + (v45 << 7));
+    v85 = v46;
+    v47 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v46 + 2);//    v47 = pTerrainNormalIndices[v46 + 1];
     if ( v47 < 0 || v47 > (signed int)(uNumTerrainNormals - 1) )
       v48 = 0;
     else
       v48 = &pTerrainNormals[v47];
-    v49 = v92 * v48->z;
-    v99 = v48;
-    thisg = 20.0 - (-v49 - v91 * v48->y - v90 * v48->x) * 20.0;
-    v50 = thisg + 6.7553994e15;
+    v49 = v92 * v48->y;
+    //v99 = v48;
+    thisg = 20.0 - (-v49 - v91 * v48->z - v90 * v48->x) * 20.0;
+    v50 = thisg + 6.755399441055744e15;
     v40->field_58 = LOBYTE(v50);
-    if ( SLOBYTE(v50) < 0 )
+    if ( LOBYTE(v50) < 0 )
       v40->field_58 = 0;
     if ( pOutdoorCamera->numStru148s >= 1999 )
       return;
     ++pOutdoorCamera->numStru148s;
-    if ( !sub_481FC9(a8, pVertices, v8, v40) )
+    if ( !sub_481FC9(pVertices, pVertices2, v8, v40) )
       //goto LABEL_77;
       {
         --pOutdoorCamera->numStru148s;
         goto LABEL_112;
       }
-    v51 = 1.0 / (a2->vWorldViewPosition.x + 0.0000001);
-    memcpy(array_50AC10, a2, 0x30u);
+    v51 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097);
+    memcpy(&array_50AC10[0], v102, 0x30u);
     array_50AC10[0].flt_20 = v51;
     array_50AC10[0].u = 0.0;
     array_50AC10[0].v = 0.0;
-    v52 = a8->vWorldViewPosition.x + 0.0000001;
-    memcpy(&array_50AC10[1], a8, sizeof(array_50AC10[1]));
+    v52 = pVertices->vWorldViewPosition.x + 0.0000001000000011686097;
+    memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1]));
     array_50AC10[1].flt_20 = 1.0 / v52;
     array_50AC10[1].u = 0.0;
     array_50AC10[1].v = 1.0;
-    v53 = pVertices->vWorldViewPosition.x + 0.0000001;
-    memcpy(&array_50AC10[2], pVertices, sizeof(array_50AC10[2]));
+    v53 = pVertices2->vWorldViewPosition.x + 0.0000001000000011686097;
+    memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2]));
     array_50AC10[2].flt_20 = 1.0 / v53;
     array_50AC10[2].u = 1.0;
     array_50AC10[2].v = 1.0;
@@ -2083,10 +2121,15 @@
 
       stru154::stru154(&static_sub_0048034E_stru_76D590);
     }*/
-
+    /*if ( !(byte_76D5C0 & 2) )
+    {
+      byte_76D5C0 |= 2;
+      stru148(stru_76D590);
+      atexit(loc_48118F);
+    }*/
     v96 = pGame->pLightmapBuilder;
-    pGame->pLightmapBuilder->StackLights_TerrainFace(v99, (float *)&a4, array_50AC10, 3u, 0);
-    pDecalBuilder->_49BE8A(v40, *(float *)&v99, (int)&a4, array_50AC10, 3u, 0);
+    pGame->pLightmapBuilder->StackLights_TerrainFace(v99, (float *)&a4, array_50AC10, 3, 0);
+    pDecalBuilder->_49BE8A(v40, *(float *)&v99, (int)&a4, array_50AC10, 3, 0);
     uNumVertices = 3;
     if ( byte_4D864C && pGame->uFlags & 0x80 )
     {
@@ -2100,24 +2143,28 @@
       thisb->ViewTransform(array_50AC10, uNumVertices);
       thisb->Project(array_50AC10, uNumVertices, 0);
     }
-    this_3a = a2->vWorldViewPosition.x < 8.0 || a8->vWorldViewPosition.x < 8.0 || pVertices->vWorldViewPosition.x < 8.0;
+    this_3a = v102->vWorldViewPosition.x < 8.0 || pVertices->vWorldViewPosition.x < 8.0 || pVertices2->vWorldViewPosition.x < 8.0;
     v54 = (double)pOutdoorCamera->shading_dist_mist;
-    v108 = v54 < a2->vWorldViewPosition.x || v54 < a8->vWorldViewPosition.x || v54 < pVertices->vWorldViewPosition.x;
-    a8 = 0;
+    v108 = v54 < v102->vWorldViewPosition.x || v54 < pVertices->vWorldViewPosition.x || v54 < pVertices2->vWorldViewPosition.x;
+    pVertices = 0;
     v96->std__vector_000004_size = 0;
     if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
     {
-      a8 = (RenderVertexSoft *)(this_3a ? 3 : v108 != 0 ? 5 : 0);
+      if ( this_3a )
+        pVertices = (RenderVertexSoft *)3;
+      else
+        pVertices = (RenderVertexSoft *)(v108 != 0 ? 5 : 0);
+      //a8 = (RenderVertexSoft *)(this_3a ? 3 : v108 != 0 ? 5 : 0);
       static_sub_0048034E_stru_76D590._49B0C9(v99, *(float *)&a4);
       if ( pDecalBuilder->uNumDecals > 0 )
-        pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)a8, -1);
+        pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices, -1);
     }
     if ( stru_F8AD28.uNumLightsApplied > 0 )
-      v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)a8);
+      v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices);
     v55 = uNumVertices;
-    v35 = byte_4D864C == 0;
+    //v35 = byte_4D864C == 0;
     v40->uNumVertices = uNumVertices;
-    if ( v35 || !(pGame->uFlags & 0x80) )
+    if ( !byte_76D5C0 || !(pGame->uFlags & 0x80) )
     {
       if ( this_3a )
       {
@@ -2154,49 +2201,47 @@
     }
 LABEL_112:
     v59 = &array_77EC08[pOutdoorCamera->numStru148s];
-    a8 = (RenderVertexSoft *)&array_77EC08[pOutdoorCamera->numStru148s];
-    v60 = pOutdoor->GetTileTexture(sX, sY);
-    v59->uTileBitmapID = v60;
-    if ( v60 == -1 )
+    //a8 = (RenderVertexSoft *)&array_77EC08[pOutdoorCamera->numStru148s];
+    v59->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY);
+    if ( v59->uTileBitmapID  == -1 )
       goto LABEL_162;
     *(int *)&v59->flags = pOutdoor->GetSomeOtherTileInfo(sX, sY);
     v61 = v93;
     v59->field_59 = 1;
-    v59->field_34 = v61->distance;
+    v59->field_34 = *(_WORD *)(v61 + 2);
     v59->field_5C = v89;
-    v59->field_5D = (char)_this;
+    v59->field_5D = v97;
     v62 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v85);
     if ( v62 > (signed int)(uNumTerrainNormals - 1) )
       v63 = 0;
     else
       v63 = &pTerrainNormals[v62];
-    v64 = v92 * v63->z;
-    v99 = v63;
+    v64 = v92 * v63->y;
+    //v99 = v63;
     thish = 20.0 - (-v64 - v91 * v63->y - v90 * v63->x) * 20.0;
-    v65 = thish + 6.7553994e15;
-    v59->field_58 = LOBYTE(v65);
-    if ( SLOBYTE(v65) < 0 )
+    v59->field_58 = floorf(thish + 0.5f);
+    if ( v59->field_58 < 0 )
       v59->field_58 = 0;
     if ( pOutdoorCamera->numStru148s >= 1999 )
       return;
     ++pOutdoorCamera->numStru148s;
-    if ( !sub_481FC9(v101, a2, pVertices, v59) )
+    if ( !sub_481FC9(v101, v102, pVertices2, v59) )
     {
 //LABEL_126:
       --pOutdoorCamera->numStru148s;
       goto LABEL_162;
     }
-    v66 = 1.0 / (a2->vWorldViewPosition.x + 0.0000001);
-    memcpy(array_50AC10, a2, 0x30u);
+    v66 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097);
+    memcpy(&array_50AC10[0], v102, 0x30u);
     array_50AC10[0].flt_20 = v66;
     array_50AC10[0].u = 0.0;
     array_50AC10[0].v = 0.0;
-    v67 = pVertices->vWorldViewPosition.x + 0.0000001;
-    memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1]));
+    v67 = pVertices2->vWorldViewPosition.x + 0.0000001000000011686097;
+    memcpy(&array_50AC10[1], pVertices2, sizeof(array_50AC10[1]));
     array_50AC10[1].flt_20 = 1.0 / v67;
     array_50AC10[1].u = 1.0;
     array_50AC10[1].v = 1.0;
-    v68 = v101->vWorldViewPosition.x + 0.0000001;
+    v68 = v101->vWorldViewPosition.x + 0.0000001000000011686097;
     memcpy(&array_50AC10[2], v101, sizeof(array_50AC10[2]));
     array_50AC10[2].flt_20 = 1.0 / v68;
     array_50AC10[2].u = 1.0;
@@ -2227,17 +2272,17 @@
       thisc->ViewTransform(array_50AC10, v100);
       thisc->Project(array_50AC10, v100, 0);
     }
-    this_3b = a2->vWorldViewPosition.x < 8.0
-           || pVertices->vWorldViewPosition.x < 8.0
+    this_3b = v102->vWorldViewPosition.x < 8.0
+           || pVertices2->vWorldViewPosition.x < 8.0
            || v101->vWorldViewPosition.x < 8.0;
     v69 = (double)pOutdoorCamera->shading_dist_mist;
-    v108 = v69 < a2->vWorldViewPosition.x || v69 < pVertices->vWorldViewPosition.x || v69 < v101->vWorldViewPosition.x;
-    LOBYTE(v70) = 0;
+    v108 = v69 < v102->vWorldViewPosition.x || v69 < pVertices2->vWorldViewPosition.x || v69 < v101->vWorldViewPosition.x;
+    v70 = 0;
     v96->std__vector_000004_size = 0;
     if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
     {
       if ( this_3b )
-        LOBYTE(v70) = 3;
+        v70 = 3;
       else
         v70 = v108 != 0 ? 5 : 0;
       static_sub_0048034E_stru_76D578._49B0C9(v99, v87);
@@ -2246,11 +2291,11 @@
     }
     if ( stru_F8AD28.uNumLightsApplied > 0 )
       v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70);
-    v71 = a8;
+    v71 = (RenderVertexSoft *)v59;
     v72 = v100;
-    v35 = byte_4D864C == 0;
-    LODWORD(a8->vWorldViewPosition.z) = v100;
-    if ( !v35 && pGame->uFlags & 0x80 )
+    //v35 = byte_4D864C == 0;
+    v59->uNumVertices = v100;//???
+    if ( !byte_4D864C && pGame->uFlags & 0x80 )
       goto LABEL_154;
     if ( this_3b )
     {
@@ -2264,23 +2309,23 @@
         v74 = v71[1].vWorldPosition.x;
         if ( !(BYTE1(v74) & 1) )
         {
-          if ( LOBYTE(v74) & 2 && LOWORD(v71[1].vWorldViewProjY) == pRenderer->field_1036AC_bitmapid )
+          if ( v74 & 2 && LOWORD(v71[1].vWorldViewProjY) == pRenderer->field_1036AC_bitmapid )
           {
-            v80 = 0;
+            v80 = false;
             v75 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
           }
           else
           {
-            v75 = LOWORD(v71[1].vWorldViewProjY);
-            v80 = 1;
+            v75 = v71[1].vWorldViewProjY;
+            v80 = true;
           }
-          v79 = 0;
+          //v79 = 0;
           v78 = pBitmaps_LOD->pHardwareTextures[v75];
-          v77 = (stru148 *)v71;
-          v76 = LODWORD(v71->vWorldViewPosition.z);
+          v77 = (int)v71;
+          v76 = v71->vWorldViewPosition.z;
           //goto LABEL_161;
           {
-           pRenderer->DrawTerrainPolygon(v76, v77, v78, v79, v80);
+           pRenderer->DrawTerrainPolygon(v76, (stru148 *)v71, v78, v79, v80);
            goto LABEL_162;
           }
         }
@@ -2289,7 +2334,7 @@
       }
       v73 = sr_424EE0_MakeFanFromTriangle(v72);
     }
-    LODWORD(v71->vWorldViewPosition.z) = v73;
+    v71->vWorldViewPosition.z = v73;
     OutdoorCamera::Project(v73);
     goto LABEL_154;
   }
@@ -7370,71 +7415,91 @@
 // 4A26BC: could not find valid save-restore pair for esi
 // 4D864C: using guessed type char byte_4D864C;
 
-
 //----- (004A2DA3) --------------------------------------------------------
-void Render::DrawFan(unsigned int uNumVertices, stru148 *a3, IDirect3DTexture2 *a4)
-{
-  Render *v4; // ebx@1
-  char *v5; // esi@6
-  char *v6; // edi@6
-  double v7; // st7@7
-  float v8; // ST34_4@7
-  int v9; // eax@7
-  signed int v10; // eax@7
-  double v11; // st7@7
-  int v12; // eax@7
+void Render::DrawStrip(unsigned int uNumVertices, struct stru148 *a3, IDirect3DTexture2 *pTexture)
+{
+  int v4; // ebx@1
+  int v7; // eax@7
+  float v12; // ST3C_4@8
+ int i;
+
+  v4 = (int)this;
+ if (!this->uNumD3DSceneBegins)
+   return;
+
+ if (uNumVertices >= 3)
+ {
+  this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1);
+  if (this->bUsingSpecular)
+  {
+   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1);
+   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2);
+   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1);
+  }
+  
+  for (i = 0; i < uNumVertices; ++i)
+  {
+   pVertices[i].pos.x = array_50AC10[i].vWorldViewProjX;
+   pVertices[i].pos.y = array_50AC10[i].vWorldViewProjY;
+   pVertices[i].pos.z = 0.99989998;
+   pVertices[i].rhw = array_50AC10[i].flt_20;
+
+   pVertices[i].diffuse = GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, 1, 0);
+   v7 = 0;
+   if (this->bUsingSpecular)
+   {
+    v12 = array_50AC10[i].vWorldViewPosition.x;
+    v7 = sub_47C3D7_get_fog_related_stuff(0, 1, v12);
+   }
+   pVertices[i].specular = v7;
+   pVertices[i].texcoord.x = array_50AC10[i].u;
+   pVertices[i].texcoord.y = array_50AC10[i].v;
+  }
+  pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture);
+  pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, pVertices, uNumVertices, D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT);
+ }
+}
+//----- (004A2DA3) --------------------------------------------------------
+void Render::DrawFan(unsigned int uNumVertices, stru148 *a3, IDirect3DTexture2 *pTexture)
+{
+  int v4; // ebx@1
+  int v7; // eax@7
   float v13; // ST3C_4@8
-  unsigned int v14; // [sp+4Ch] [bp-4h]@6
-
-  v4 = this;
-  if ( this->uNumD3DSceneBegins && (signed int)uNumVertices >= 3 )
-  {
-    ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
-    if ( v4->bUsingSpecular )
-    {
-      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
-      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
-    }
-    if ( (signed int)uNumVertices > 0 )
-    {
-      v5 = (char *)&arary_77E5C8[0].pos.y;
-      v6 = (char *)&array_50AC10[0].vWorldViewProjY;
-      v14 = uNumVertices;
-      do
-      {
-        v7 = *((float *)v6 - 4);
-        *((int *)v5 - 1) = *((int *)v6 - 1);
-        v8 = v7;
-        *(int *)v5 = *(int *)v6;
-        v9 = *((int *)v6 + 1);
-        *((int *)v5 + 1) = 0x3F7FF972u;
-        *((int *)v5 + 2) = v9;
-        v10 = GetActorTintColor(31, 0, v8, 1, 0);
-        v11 = *((float *)v6 - 4);
-        *((int *)v5 + 3) = v10;
-        v12 = 0;
-        if ( v4->bUsingSpecular )
-        {
-          v13 = v11;
-          v12 = sub_47C3D7_get_fog_related_stuff(0, 1, v13);
-        }
-        *((int *)v5 + 4) = v12;
-        *((int *)v5 + 5) = *((int *)v6 + 2);
-        *((int *)v5 + 6) = *((int *)v6 + 3);
-        v6 += 48;
-        v5 += 32;
-        --v14;
-      }
-      while ( v14 );
-    }
-    ErrD3D(pRenderD3D->pDevice->SetTexture(0, a4));
-    ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-      D3DPT_TRIANGLEFAN,
-      D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-      arary_77E5C8,
-      uNumVertices,
-      24));
+  int i;
+
+  v4 = (int)this;
+  if ( !this->uNumD3DSceneBegins )
+    return;
+  if ( uNumVertices >= 3 )
+  {
+    this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1);
+    if ( this->bUsingSpecular )
+    {
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1);
+    }
+    for (i = 0; i < uNumVertices; ++i)
+    {
+      pVertices[i].pos.x = array_50AC10[i].vWorldViewProjX;
+      pVertices[i].pos.y = array_50AC10[i].vWorldViewProjY;
+      pVertices[i].pos.z = 0.99989998;
+      pVertices[i].rhw = array_50AC10[i].flt_20;
+
+      pVertices[i].diffuse = GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, 1, 0);
+      v7 = 0;
+      if (this->bUsingSpecular)
+      {
+        v13 = array_50AC10[i].vWorldViewPosition.x;
+        v7 = sub_47C3D7_get_fog_related_stuff(0, 1, v13);
+      }
+      pVertices[i].specular = v7;
+      pVertices[i].texcoord.x = array_50AC10[i].u;
+      pVertices[i].texcoord.y = array_50AC10[i].v;
+    }
+    pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture);
+    pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
+    pVertices, uNumVertices, D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT);
   }
 }
 
--- a/Render.h	Wed Jan 23 17:29:00 2013 +0600
+++ b/Render.h	Fri Jan 25 16:48:21 2013 +0600
@@ -244,7 +244,7 @@
   char field_78[208];
 };
 #pragma pack(pop)
-
+extern struct RenderVertexD3D3  pVertices[50];
 
 /*  182 */
 #pragma pack(push, 1)
@@ -309,6 +309,7 @@
   unsigned int GetActorTintColor(float a2, int a3, int a4, int a5, RenderBillboard *a6);
   void DrawPolygon(unsigned int uNumVertices, stru148 *a3, ODMFace *a4, IDirect3DTexture2 *pTexture);
   void DrawTerrainPolygon(unsigned int uNumVertices, stru148 *a4, IDirect3DTexture2 *a5, int a6, int a7);
+  void Render::DrawStrip(unsigned int uNumVertices, struct stru148 *a3, IDirect3DTexture2 *pTexture);
   void DrawFan(unsigned int uNumVertices, stru148 *a3, IDirect3DTexture2 *a4);
   void _4A2ED5(signed int a2, stru148 *a3, IDirect3DTexture2 *pHwTex);
   void DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, Texture *pTex, int uPackedID, unsigned int uColor, int a8);
@@ -447,7 +448,7 @@
 
 extern struct IDirectDrawClipper *pDDrawClipper;
 extern struct Render *pRenderer; // idb
-
+extern struct pUnkTerrain *Unks;
 
 
 
--- a/mm7_3.cpp	Wed Jan 23 17:29:00 2013 +0600
+++ b/mm7_3.cpp	Fri Jan 25 16:48:21 2013 +0600
@@ -7690,12 +7690,12 @@
 {
   int v0; // esi@2
   int v1; // eax@2
-  double v2; // st7@2
-  double v3; // st6@2
-  double v4; // st5@2
-  double v5; // st4@2
-  double v6; // st7@2
-  char *v7; // esi@3
+  //double v2; // st7@2
+  //double v3; // st6@2
+  //double v4; // st5@2
+  //double v5; // st4@2
+  //double v6; // st7@2
+  //char *v7; // esi@3
   int v8; // eax@4
   int v9; // eax@4
   int v10; // ebx@4
@@ -7707,91 +7707,75 @@
   int v16; // eax@12
   signed __int64 v17; // qtt@13
   signed int v18; // ecx@13
-  Texture *v19; // eax@15
-  double v20; // st6@15
-  double v21; // st7@15
-  double v22; // st6@15
-  unsigned __int8 v23; // sf@15
-  unsigned __int8 v24; // of@15
+  //Texture *v19; // eax@15
+  //double v20; // st6@15
+  //double v21; // st7@15
+  //double v22; // st6@15
+  //unsigned __int8 v23; // sf@15
+  //unsigned __int8 v24; // of@15
   stru148 _this; // [sp+14h] [bp-150h]@1
-  double v26; // [sp+120h] [bp-44h]@4
-  float v27; // [sp+128h] [bp-3Ch]@4
+  //double v26; // [sp+120h] [bp-44h]@4
+  //float v27; // [sp+128h] [bp-3Ch]@4
   float v28; // [sp+12Ch] [bp-38h]@2
   int v29; // [sp+130h] [bp-34h]@4
   int v30; // [sp+134h] [bp-30h]@1
-  int v31; // [sp+138h] [bp-2Ch]@2
+  //int v31; // [sp+138h] [bp-2Ch]@2
   int v32; // [sp+13Ch] [bp-28h]@6
   int v33; // [sp+140h] [bp-24h]@2
-  float v34; // [sp+144h] [bp-20h]@1
+  int v34; // [sp+144h] [bp-20h]@1
   int v35; // [sp+148h] [bp-1Ch]@4
-  double v36; // [sp+14Ch] [bp-18h]@2
+  int v36; // [sp+14Ch] [bp-18h]@2
   int v37; // [sp+154h] [bp-10h]@8
   int v38; // [sp+158h] [bp-Ch]@1
   int v39; // [sp+15Ch] [bp-8h]@4
   int v40; // [sp+160h] [bp-4h]@7
 
-  v30 = (signed __int64)((double)(pOutdoorCamera->int_fov_rad * pIndoorCamera->pos.z)
-                       / ((double)pOutdoorCamera->int_fov_rad + 8192.0)
-                       + (double)pViewport->uScreenCenterY);
-  v34 = cos((double)pIndoorCamera->sRotationX * 0.0030664064) * (double)pOutdoorCamera->shading_dist_mist;
-  v38 = (signed __int64)((double)pViewport->uScreenCenterY
-                       - (double)pOutdoorCamera->int_fov_rad
-                       / (v34 + 0.0000001)
-                       * (sin((double)pIndoorCamera->sRotationX * 0.0030664064)
-                        * (double)-pOutdoorCamera->shading_dist_mist
-                        - (double)pIndoorCamera->pos.z));
+  v30 = ((double)(pOutdoorCamera->int_fov_rad * pIndoorCamera->pos.z)
+        / ((double)pOutdoorCamera->int_fov_rad + 8192.0) + pViewport->uScreenCenterY);
+  v38 = pViewport->uScreenCenterY - 
+        pOutdoorCamera->int_fov_rad / (pOutdoorCamera->shading_dist_mist * cos(pIndoorCamera->sRotationX * 0.003066406352445483) + 0.0000001000000011686097) *
+        (pOutdoorCamera->shading_dist_mist * -sin(pIndoorCamera->sRotationX * 0.003066406352445483) - pIndoorCamera->pos.z);
   _this._48607B(&stru_8019C8);
   _this.ptr_38->_48694B();
-  _this.uTileBitmapID = LOWORD(pOutdoor->uSky_TextureID);
+  _this.uTileBitmapID = pOutdoor->uSky_TextureID;
   _this.pTexture = (Texture *)(SLOWORD(pOutdoor->uSky_TextureID) != -1 ? (int)&pBitmaps_LOD->pTextures[SLOWORD(pOutdoor->uSky_TextureID)] : 0);
-  if ( _this.pTexture )
-  {
-    v0 = pIndoorCamera->sRotationX;
-    _this.field_58 = 0;
-    _this.uNumVertices = 4;
-    _this.v_18.x = -stru_5C6E00->SinCos(pIndoorCamera->sRotationX - stru_5C6E00->uIntegerHalfPi + 16);
-    _this.v_18.y = 0;
-    v1 = stru_5C6E00->SinCos(v0 + 16);
-    v2 = (double)(signed int)pViewport->uViewportX;
-    _this.v_18.z = -v1;
-    array_50AC10[0].vWorldViewProjX = v2;
-    v3 = (double)(signed int)pViewport->uViewportY;
-    array_50AC10[0].vWorldViewProjY = v3;
-    array_50AC10[1].vWorldViewProjX = v2;
-    v4 = (double)v38;
-    _this.sTextureDeltaU = 224 * pMiscTimer->uTotalGameTimeElapsed;
-    _this.sTextureDeltaV = 224 * pMiscTimer->uTotalGameTimeElapsed;
-    v28 = v4;
-    array_50AC10[1].vWorldViewProjY = v4;
-    v5 = (double)(signed int)pViewport->uViewportZ;
-    array_50AC10[2].vWorldViewProjX = v5;
-    v38 = pViewport->uViewportZ - pViewport->uViewportX;
-    _this.field_24 = 0x2000000u;
-    array_50AC10[2].vWorldViewProjY = v4;
-    array_50AC10[3].vWorldViewProjX = v5;
-    array_50AC10[3].vWorldViewProjY = v3;
-    v36 = (double)(pViewport->uViewportZ - pViewport->uViewportX) * 0.5;
-    v6 = tan(0.6457717418670654);
-    v31 = 0;
-    v33 = 65536 / (signed int)(signed __int64)(v36 / v6 + 0.5);
-    if ( (signed int)_this.uNumVertices <= 0 )
-      goto LABEL_16;
-    v7 = (char *)&array_50AC10[0].vWorldViewProjY;
-    while ( 1 )
-    {
-      LODWORD(v27) = *(int *)v7;
-      v26 = v27 + 6.7553994e15;
-      v29 = LODWORD(v26);
-      v38 = _this.ptr_38->field_14;
-      v39 = (unsigned __int64)(v38 * (signed __int64)(v33 * (v30 - LODWORD(v26)))) >> 16;
-      v8 = v39 + _this.ptr_38->field_C;
-      v39 = v33 * (v30 - LODWORD(v26));
-      v35 = v8;
-      v38 = _this.ptr_38->field_20;
-      v39 = (unsigned __int64)(v38 * (signed __int64)(v33 * (v30 - LODWORD(v26)))) >> 16;
-      HIDWORD(v36) = v39 + _this.ptr_38->field_18;
-      v38 = _this.v_18.z;
-      v9 = (unsigned __int64)(_this.v_18.z * (signed __int64)(v33 * (v30 - LODWORD(v26)))) >> 16;
+  if (pOutdoor->uSky_TextureID == -1)
+    return;
+  _this.field_58 = 0;
+  _this.uNumVertices = 4;
+  _this.v_18.x = -stru_5C6E00->SinCos(pIndoorCamera->sRotationX - stru_5C6E00->uIntegerHalfPi + 16);
+  _this.v_18.y = 0;
+  _this.v_18.z = -stru_5C6E00->SinCos(pIndoorCamera->sRotationX + 16);
+  _this.field_24 = 0x2000000;
+
+  _this.sTextureDeltaU = 224 * pMiscTimer->uTotalGameTimeElapsed;
+  _this.sTextureDeltaV = 224 * pMiscTimer->uTotalGameTimeElapsed;
+
+  array_50AC10[0].vWorldViewProjX = pViewport->uViewportX;
+  array_50AC10[0].vWorldViewProjY = pViewport->uViewportY;
+
+  array_50AC10[1].vWorldViewProjX = pViewport->uViewportX;
+  array_50AC10[1].vWorldViewProjY = v38;
+
+  array_50AC10[2].vWorldViewProjX = pViewport->uViewportZ;
+  array_50AC10[2].vWorldViewProjY = pViewport->uViewportY;
+
+  array_50AC10[3].vWorldViewProjX = pViewport->uViewportZ;
+  array_50AC10[3].vWorldViewProjY = v38;
+
+  v36 = (double)(pViewport->uViewportZ - pViewport->uViewportX) * 0.5;
+  v33 = 65536 / (signed int)(v36 / tan(0.6457717418670654) + 0.5);
+
+  for (int i = 0; i < _this.uNumVertices; ++i)
+  {
+     v29 = floorf(array_50AC10[i].vWorldViewProjY + 0.5f);
+     v39 = (unsigned __int64)(_this.ptr_38->field_14 * v33 * (v30 - v29)) / 65536;
+     v8 = v39 + _this.ptr_38->field_C;
+
+     v39 = (unsigned __int64)(_this.ptr_38->field_20 * v33 * (v30 - v29)) / 65536;
+     v36 = v39 + _this.ptr_38->field_18;
+
+      v9 = (unsigned __int64)(_this.v_18.z * v33 * (v30 - v29)) / 65536;
       v10 = _this.v_18.x + v9;
       v39 = _this.v_18.x + v9;
       if ( _this.v_18.x + v9 > 0 )
@@ -7799,11 +7783,11 @@
         v10 = 0;
         v39 = 0;
       }
-      v11 = (signed __int64)*((float *)v7 - 1);
+      v11 = (signed __int64)array_50AC10[i].vWorldViewProjX;
       v38 = v10;
-      v12 = *(float *)v7 - 1.0;
+      v12 = array_50AC10[i].vWorldViewProjY - 1.0;
       v13 = v33 * (pViewport->uScreenCenterX - v11);
-      LODWORD(v34) = -_this.field_24;
+      v34 = -_this.field_24;
       v32 = (signed __int64)v12;
       v14 = v33 * (v30 - v32);
       while ( 1 )
@@ -7811,9 +7795,9 @@
         v40 = v14;
         if ( !v10 )
           goto LABEL_12;
-        v37 = abs(SLODWORD(v34) >> 14);
+        v37 = abs(v34 >> 14);
         v15 = abs(v10);
-        if ( v37 <= v15 || v32 <= (signed int)pViewport->uViewportY )
+        if ( v37 <= v15 || v32 <= pViewport->uViewportY )
         {
           if ( v39 <= 0 )
             break;
@@ -7827,57 +7811,49 @@
         v10 = _this.v_18.x + v16;
         v39 = _this.v_18.x + v16;
         v38 = _this.v_18.x + v16;
-      }
-      LODWORD(v17) = LODWORD(v34) << 16;
-      HIDWORD(v17) = SLODWORD(v34) >> 16;
-      v40 = v17 / v38;
+        break;
+      }
+      LODWORD(v17) = v34 << 16;
+      HIDWORD(v17) = v34 >> 16;
       v18 = v17 / v38;
       if ( v18 < 0 )
         v18 = pOutdoorCamera->shading_dist_mist;
-      v40 = v13;
-      v37 = _this.ptr_38->field_10;
-      v40 = v13;
-      v37 = v35 + ((unsigned __int64)(v37 * (signed __int64)v13) >> 16);
-      v35 = _this.ptr_38->field_1C;
-      HIDWORD(v36) += (unsigned __int64)(v35 * (signed __int64)v13) >> 16;
-      v35 = 224 * pMiscTimer->uTotalGameTimeElapsed
-          + ((signed int)((unsigned __int64)(v37 * (signed __int64)v18) >> 16) >> 3);
-      v40 = (unsigned __int64)(SHIDWORD(v36) * (signed __int64)v18) >> 16;
-      v19 = _this.pTexture;
-      HIDWORD(v36) = _this.pTexture->uTextureWidth;
-      v7 += 48;
-      v20 = (double)SHIDWORD(v36) * 65536.0;
-      HIDWORD(v36) = 224 * pMiscTimer->uTotalGameTimeElapsed + (v40 >> 3);
-      ++v31;
-      *((float *)v7 - 10) = (double)v35 / v20;
-      v21 = (double)SHIDWORD(v36);
-      HIDWORD(v36) = v19->uTextureHeight;
-      v22 = (double)SHIDWORD(v36);
-      HIDWORD(v36) = v18 >> 16;
-      v24 = _this.uNumVertices > v31;
-      v23 = ((v31 - _this.uNumVertices) & 0x80000000u) != 0;
-      *((float *)v7 - 9) = v21 / (v22 * 65536.0);
-      *((float *)v7 - 16) = (double)pOutdoorCamera->shading_dist_mist;
-      *((float *)v7 - 11) = 1.0 / (double)SHIDWORD(v36);
-      if ( !(v23 ^ v24) )
-      {
-LABEL_16:
-        pRenderer->DrawFan(
-          _this.uNumVertices,
-          &_this,
-          pBitmaps_LOD->pHardwareTextures[(signed __int16)_this.uTileBitmapID]);
-        array_50AC10[0].vWorldViewProjY = v28;
-        array_50AC10[1].vWorldViewProjY = array_50AC10[1].vWorldViewProjY + 30.0;
-        array_50AC10[2].vWorldViewProjY = array_50AC10[2].vWorldViewProjY + 30.0;
-        array_50AC10[3].vWorldViewProjY = v28;
-        pRenderer->DrawFan(
-          _this.uNumVertices,
-          &_this,
-          pBitmaps_LOD->pHardwareTextures[(signed __int16)_this.uTileBitmapID]);
+
+      v37 += ((unsigned __int64)(_this.ptr_38->field_10 * v13) >> 16);
+      v36 += ((unsigned __int64)(_this.ptr_38->field_1C * v13) >> 16);
+      v35 = 224 * pMiscTimer->uTotalGameTimeElapsed + (signed int)((unsigned __int64)(v37 * v18) >> 16) / 8;
+      v36 = 224 * pMiscTimer->uTotalGameTimeElapsed + (signed int)((unsigned __int64)(v36 * v18) >> 16) / 8;
+
+      array_50AC10[i].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist;
+      array_50AC10[i].flt_20 = 1.0 / (double)(v17 / 65536);
+      array_50AC10[i].u = (double)v35 / (65536.0 * pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID].uTextureWidth);
+      array_50AC10[i].v = (double)v36 / (65536.0 * pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID].uTextureWidth);
+    }
+
+     float t = (GetTickCount() % 96000) / 96000.0f;
+
+ array_50AC10[0].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist;
+ array_50AC10[0].flt_20 = 1;
+ array_50AC10[0].u = 0;
+ array_50AC10[0].v = 0 + t;
+
+ array_50AC10[1].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist;
+ array_50AC10[1].flt_20 = 1;
+ array_50AC10[1].u = 0;
+ array_50AC10[1].v = 1 + t;
+ 
+ array_50AC10[2].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist;
+ array_50AC10[2].flt_20 = 1;
+ array_50AC10[2].u = 1;
+ array_50AC10[2].v = 0 + t;
+
+ array_50AC10[3].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist;
+ array_50AC10[3].flt_20 = 1;
+ array_50AC10[3].u = 1;
+ array_50AC10[3].v = 1 + t;
+ pRenderer->DrawStrip(_this.uNumVertices, &_this,
+          pBitmaps_LOD->pHardwareTextures[_this.uTileBitmapID]);//problem
         return;
-      }
-    }
-  }
 }
 
 
@@ -9128,16 +9104,16 @@
 
 
 //----- (0047F44B) --------------------------------------------------------
-int __stdcall WorldPosToGridCellX(signed int a1)
-{
-  return (a1 >> 9) + 64;
+unsigned int __stdcall WorldPosToGridCellX(signed int sWorldPosX)
+{
+  return (sWorldPosX / 512) + 64;
 }
 // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
 
 //----- (0047F458) --------------------------------------------------------
-int __stdcall WorldPosToGridCellZ(signed int a1)
-{
-  return 64 - (a1 >> 9);
+unsigned int __stdcall WorldPosToGridCellZ(signed int sWorldPosZ)
+{
+  return 64 - (sWorldPosZ / 512);
 }
 
 //----- (0047F469) --------------------------------------------------------
--- a/mm7_data.cpp	Wed Jan 23 17:29:00 2013 +0600
+++ b/mm7_data.cpp	Fri Jan 25 16:48:21 2013 +0600
@@ -314,8 +314,6 @@
   }
 };
 
-
-
 #include "stru314.h"
 
 
@@ -1704,6 +1702,7 @@
 int dword_723E80_award_related[777]; // weak
 int dword_723E84[777]; // weak
 int dword_7241C8; // weak
+struct unk_F7B60C stru_73C834; // struct @ MM7.exe::0073C834
 struct NPCStats *pNPCStats = nullptr;
 char *aNPCProfessionNames[59];
 char *pAwardsTXT_Raw;
@@ -1716,10 +1715,10 @@
 char *pTransitionsTXT_Raw;
 char *pAutonoteTXT_Raw;
 char *pQuestsTXT_Raw;
-unsigned int uNumTerrainNormals;
-int pTerrainSomeOtherData[32768];
-unsigned __int16 pTerrainNormalIndices[32768];
-struct Vec3_float_ *pTerrainNormals;
+ unsigned int    uNumTerrainNormals;
+ struct Vec3_float_ *pTerrainNormals;
+ unsigned short  pTerrainNormalIndices[128 * 128 * 2];
+ unsigned int    pTerrainSomeOtherData[128 * 128 * 2];
 int dword_76D518_terrain_cell_world_pos_around_party_y; // weak
 int dword_76D51C_terrain_cell_world_pos_around_party_y; // weak
 int dword_76D520_terrain_cell_world_pos_around_party_y; // weak
@@ -1744,6 +1743,10 @@
 int dword_76D56C_terrain_cell_world_pos_around_party_x; // weak
 int dword_76D570_terrain_cell_world_pos_around_party_x; // weak
 int dword_76D574_terrain_cell_world_pos_around_party_x; // weak
+struct unk_F7B60C stru_76D578; // struct @ MM7.exe::0076D578
+struct unk_F7B60C stru_76D590; // struct @ MM7.exe::0076D590
+struct unk_F7B60C stru_76D5A8; // struct @ MM7.exe::0076D5A8
+char byte_76D5C0; // weak
 int terrain_76D5C8[128];
 int terrain_76D7C8[128];
 int terrain_76D9C8[128];
@@ -1752,6 +1755,7 @@
 int terrain_76DFC8[128];
 int terrain_76E1C8[128];
 int terrain_76E3C8[128];
+
 _UNKNOWN unk_801A00; // weak
 _UNKNOWN unk_801A0C; // weak
 char byte_80AA10; // weak
--- a/mm7_data.h	Wed Jan 23 17:29:00 2013 +0600
+++ b/mm7_data.h	Fri Jan 25 16:48:21 2013 +0600
@@ -1592,10 +1592,10 @@
 extern char *pTransitionsTXT_Raw;
 extern char *pAutonoteTXT_Raw;
 extern char *pQuestsTXT_Raw;
-extern unsigned int uNumTerrainNormals;
-extern int pTerrainSomeOtherData[32768];
-extern unsigned __int16 pTerrainNormalIndices[32768];
+extern unsigned int    uNumTerrainNormals;
 extern struct Vec3_float_ *pTerrainNormals;
+extern unsigned short  pTerrainNormalIndices[128 * 128 * 2];
+extern unsigned int    pTerrainSomeOtherData[128 * 128 * 2];
 extern int dword_76D518_terrain_cell_world_pos_around_party_y; // weak
 extern int dword_76D51C_terrain_cell_world_pos_around_party_y; // weak
 extern int dword_76D520_terrain_cell_world_pos_around_party_y; // weak
@@ -1620,6 +1620,10 @@
 extern int dword_76D56C_terrain_cell_world_pos_around_party_x; // weak
 extern int dword_76D570_terrain_cell_world_pos_around_party_x; // weak
 extern int dword_76D574_terrain_cell_world_pos_around_party_x; // weak
+extern char byte_76D5C0;
+extern struct unk_F7B60C stru_76D578;
+extern struct unk_F7B60C stru_76D590;
+extern struct unk_F7B60C stru_76D5A8;
 extern int terrain_76D5C8[128];
 extern int terrain_76D7C8[128];
 extern int terrain_76D9C8[128];
@@ -1628,6 +1632,16 @@
 extern int terrain_76DFC8[128];
 extern int terrain_76E1C8[128];
 extern int terrain_76E3C8[128];
+extern struct unk_F7B60C
+{
+ int   some_data_ptr;  // dword @ 000000
+ float flt_000004;
+ float flt_000008;
+ float flt_00000C;
+ float flt_000010;
+ char  byte_000014;
+ char  unk_000015[3];
+};
 extern _UNKNOWN unk_801A00; // weak
 extern _UNKNOWN unk_801A0C; // weak
 extern char byte_80AA10; // weak
@@ -2198,8 +2212,8 @@
 unsigned int __cdecl GetLevelFogColor();
 int __fastcall sub_47C3D7_get_fog_related_stuff(int a1, int a2, float a3);
 signed int __fastcall GetActorTintColor(int a1, int a2, float a3, int a4, struct RenderBillboard *a5);
-int __stdcall WorldPosToGridCellX(int); // weak
-int __stdcall WorldPosToGridCellZ(int); // weak
+unsigned int __stdcall WorldPosToGridCellX(int); // weak
+unsigned int __stdcall WorldPosToGridCellZ(int); // weak
 int __stdcall GridCellToWorldPosX(int); // weak
 int __stdcall GridCellToWorldPosZ(int); // weak
 void __fastcall sub_47F4D3(int band1, int band2, int band3);