changeset 86:ec84db4c8f9d

4.01.13
author Ritor1
date Mon, 04 Feb 2013 09:17:35 +0600
parents 3f2d5c80e162
children 170259c8c71f
files IndoorCameraD3D.cpp LightmapBuilder.cpp Outdoor.cpp Render.cpp Render.h mm7_3.cpp mm7_4.cpp
diffstat 7 files changed, 860 insertions(+), 528 deletions(-) [+]
line wrap: on
line diff
--- a/IndoorCameraD3D.cpp	Tue Jan 29 10:03:07 2013 +0600
+++ b/IndoorCameraD3D.cpp	Mon Feb 04 09:17:35 2013 +0600
@@ -1701,7 +1701,7 @@
   float *v5; // ecx@2
 
   v3 = uStripType;
-  result = 3.4028235e38;
+  result = 3.402823466385289e38;
   if ( (signed int)uStripType > 0 )
   {
     v5 = &pVertices->vWorldPosition.z;
--- a/LightmapBuilder.cpp	Tue Jan 29 10:03:07 2013 +0600
+++ b/LightmapBuilder.cpp	Mon Feb 04 09:17:35 2013 +0600
@@ -1024,9 +1024,9 @@
 // 4E94D2: using guessed type char _4E94D2_light_type;
 
 //----- (0045D036) --------------------------------------------------------
-bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, bool bLightBackfaces)
+bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *a2, RenderVertexSoft *a3, unsigned int uStripType, bool bLightBackfaces)
 {
-  int v6; // esi@1
+  /*int v6; // esi@1
   //LightmapBuilder *v7; // edi@1
   MobileLight *v8; // ebx@2
   int v9; // esi@5
@@ -1067,7 +1067,32 @@
   }
 
   stru_F8AD28.uNumLightsApplied = a7;
+  return true;*/
+//	bool __stdcall sub_45D036(struct Vec3<float> *pNormal, int a2, struct RenderVertex *a3, int a4, signed int X)
+//{
+  float v6; // ebx@2
+  unsigned int v10; // [sp+Ch] [bp-4h]@1
+ int i;
+
+  v10 = 0;
+  stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->field_CBC_terrain_triangles_shade_type;
+  for (i = 0; i < pMobileLightsStack->uNumLightsActive; ++i)
+  {
+      if ( v10 >= 20 )
+        break;
+      StackLight_TerrainFace((StationaryLight *)&pMobileLightsStack->pLights[i], pNormal, a2, a3, uStripType, bLightBackfaces, &v10);
+  }
+
+  for (i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i)
+  {
+      if ( v10 >= 20 )
+        break;
+      StackLight_TerrainFace(&pStationaryLightsStack->pLights[i], pNormal, a2, a3, uStripType, bLightBackfaces, &v10);
+  }
+
+  stru_F8AD28.uNumLightsApplied = v10;
   return true;
+
 }
 // 519AB4: using guessed type int uNumStationaryLightsApplied;
 
@@ -1136,8 +1161,8 @@
   result = pLight->uRadius;
   v63 = pLight->uRadius;
   if ( result <= 0 )
-    goto LABEL_27;
-  v10 = uStripType;
+    return 0;
+  //v10 = uStripType;
   v11 = a1;
   if ( uStripType == 4 )
   {
@@ -1168,22 +1193,21 @@
 LABEL_5:
   v64 = v13;
 LABEL_11:
-  v60 = v10;
+  //v60 = v10;
   v59 = (const char *)v11;
-  v14 = pGame->pIndoorCameraD3D->GetPolygonMinZ(v11, v10);
-  v60 = v10;
-  minz = v14;
-  maxz = pGame->pIndoorCameraD3D->GetPolygonMaxZ(v11, v10);
+  v60 = uStripType;
+  minz = pGame->pIndoorCameraD3D->GetPolygonMinZ(v11, uStripType);
+  maxz = pGame->pIndoorCameraD3D->GetPolygonMaxZ(v11, uStripType);
   result = v8->vPosition.x;
   *((float *)&v61 + 1) = maxz;
   v16 = (double)result;
   *(float *)&X = (double)v63;
   v17 = *(float *)&pLight - *(float *)&X;
   //UNDEF(v18);
-  v19 = v16 < v17;
+  //v19 = v16 < v17;
   v20 = 0;
-  v21 = v16 == v17;
-//  BYTE1(result) = HIBYTE(v18);
+  //v21 = v16 == v17;
+/*  BYTE1(result) = HIBYTE(v18);
   if ( v16 <= v17
     || (v22 = *(float *)&X + *(float *)&uStripType,
         //UNDEF(v23),
@@ -1238,25 +1262,22 @@
         result = LODWORD(v61),
         X = LODWORD(v61),
         v52 = v63,
-        SLODWORD(v61) > v63) )
-  {
-LABEL_27:
-    LOBYTE(result) = 0;
-    return result;
-  }
+        SLODWORD(v61) > v63) )*/
+  if (0)
+    return 0;
   v53 = pSlot;
   v60 = X;
   stru_F8AD28._blv_lights_radii[*pSlot] = v63;
-  stru_F8AD28._blv_lights_inv_radii[*v53] = 65536 / v52;
+  stru_F8AD28._blv_lights_inv_radii[*v53] = 65536 / v63;
   stru_F8AD28._blv_lights_xs[*v53] = v8->vPosition.x;
   stru_F8AD28._blv_lights_ys[*v53] = v8->vPosition.y;
   stru_F8AD28._blv_lights_zs[*v53] = v8->vPosition.z;
   a3 = (float *)v8->uLightColorR;
-  stru_F8AD28._blv_lights_rs[*v53] = (double)(signed int)a3 * 0.0039215689;
+  stru_F8AD28._blv_lights_rs[*v53] = (double)(signed int)a3 * 0.003921568859368563;
   a3 = (float *)v8->uLightColorG;
-  stru_F8AD28._blv_lights_gs[*v53] = (double)(signed int)a3 * 0.0039215689;
+  stru_F8AD28._blv_lights_gs[*v53] = (double)(signed int)a3 * 0.003921568859368563;
   a3 = (float *)v8->uLightColorB;
-  stru_F8AD28._blv_lights_bs[*v53] = (double)(signed int)a3 * 0.0039215689;
+  stru_F8AD28._blv_lights_bs[*v53] = (double)(signed int)a3 * 0.003921568859368563;
   v54 = abs(v60);
   v55 = pRenderer->bUsingSpecular;
   stru_F8AD28._blv_lights_light_dot_faces[*v53] = v54;
@@ -1272,16 +1293,15 @@
     if ( stru_F8AD28._blv_lights_types[*v53] & 4 )
     {
       *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result)
-                                                              * 0.33000001;
+                                                              * 0.3300000131130219;
       *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result)
-                                                              * 0.33000001;
+                                                              * 0.3300000131130219;
       *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result)
-                                                              * 0.33000001;
+                                                              * 0.3300000131130219;
     }
   }
   ++*v53;
-  LOBYTE(result) = 1;
-  return result;
+  return 1;
 }
 // 4E94D2: using guessed type char _4E94D2_light_type;
 
--- a/Outdoor.cpp	Tue Jan 29 10:03:07 2013 +0600
+++ b/Outdoor.cpp	Mon Feb 04 09:17:35 2013 +0600
@@ -58,9 +58,7 @@
     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);
+  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.y - pParty->field_18 * ((stru_5C6E00->SinCos(pParty->sRotationY)) >> 16);
@@ -92,7 +90,7 @@
       goto LABEL_16;
     }
     //goto LABEL_14;
-	pRenderer->DrawSkyD3D();
+    pRenderer->DrawSkyD3D();
     pRenderer->DrawBuildingsD3D();
     pRenderer->DrawBezierTerrain();
     goto LABEL_16;
@@ -219,7 +217,7 @@
 // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
 
 //----- (00488EEF) --------------------------------------------------------
-unsigned int OutdoorLocation::GetTileTexture(int sX, int sY)
+unsigned int OutdoorLocation::GetTileTexture(int sX, int sZ)
 {
   //OutdoorLocation *v3; // esi@1
   unsigned int v4; // edi@1
@@ -234,7 +232,7 @@
   else
     result = DoGetTileTexture(v5, v4);
   return result;*/
-  v4 = WorldPosToGridCellZ(sY);
+  v4 = WorldPosToGridCellZ(sZ);
   v5 = WorldPosToGridCellX(sX);
   if ( v5 < 0 || v5 > 127 || v4 < 0 || v4 > 127 )
     return -1;
@@ -2399,9 +2397,9 @@
 }
 
 //----- (0047ED08) --------------------------------------------------------
-unsigned int OutdoorLocation::DoGetTileTexture(unsigned int uX, unsigned int uY)
+unsigned int OutdoorLocation::DoGetTileTexture(unsigned int uX, unsigned int uZ)
 {
-  int v3; // esi@5
+  int uTileID; // esi@5
   unsigned int result; // eax@9
 
 
@@ -2418,19 +2416,19 @@
     result = pTileTable->pTiles[v3].uBitmapID;
   }
   return result;*/
-   if (uX > 127 || uY > 127)
+   if (uX > 127 || uZ > 127)
    return 0;
 
- v3 = this->pTerrain.pTilemap[uY * 128 + uX];
- if (v3 < 198)
+ uTileID = this->pTerrain.pTilemap[uZ * 128 + uX];
+ if (uTileID < 198)
  {
-  if (v3 >= 90)
-    v3 = v3 + this->pTileTypes[(v3 - 90) / 18].uTileID - 36 * (v3 - 90) / 36 - 90;
+  if (uTileID >= 90)
+    uTileID = uTileID + this->pTileTypes[(uTileID - 90) / 18].uTileID - 36 * (uTileID - 90) / 36 - 90;
  }
  else
-   v3 = v3 + this->pTileTypes[3].uTileID - 198;
+   uTileID = uTileID + this->pTileTypes[3].uTileID - 198;
 
- return pTileTable->pTiles[v3].uBitmapID;
+ return pTileTable->pTiles[uTileID].uBitmapID;
 }
 
 //----- (0047ED83) --------------------------------------------------------
--- a/Render.cpp	Tue Jan 29 10:03:07 2013 +0600
+++ b/Render.cpp	Mon Feb 04 09:17:35 2013 +0600
@@ -908,8 +908,8 @@
  //__debugbreak();Ritor1: it's temporarily
   //return 0;
   
-  unsigned int v0; // ebx@1
-  unsigned int v1; // edi@1
+  unsigned int pDirectionIndicator1; // ebx@1
+  unsigned int pDirectionIndicator2; // edi@1
   unsigned int v2; // eax@1
   int v3; // eax@3
   int v4; // edi@3
@@ -981,11 +981,11 @@
   int v70; // edi@178
   int v71; // eax@178
   int v72; // ecx@178
-  int v73; // ebx@180
+  int x; // ebx@180
   int v74; // eax@182
   int v75; // eax@184
   IndoorCameraD3D *pIndoorCameraD3D_3; // ecx@184
-  int v77; // ecx@184
+  int uStartZ; // ecx@184
   int v79; // ebx@185
   int v127; // esi@185
   int v86; // edi@196
@@ -1005,7 +1005,7 @@
   } v102;
   int v105; // [sp+1Ch] [bp-58h]@1
   int v106; // [sp+20h] [bp-54h]@3
-  int v107; // [sp+24h] [bp-50h]@3
+  int uEndZ; // [sp+24h] [bp-50h]@3
   int v108; // [sp+28h] [bp-4Ch]@9
   int v109; // [sp+2Ch] [bp-48h]@9
   int v110; // [sp+30h] [bp-44h]@9
@@ -1027,12 +1027,10 @@
   int v126; // [sp+70h] [bp-4h]@9
 
   v105 = 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);
-  v124 = ((pIndoorCamera->uMapGridCellX << 16) + 3 * stru_5C6E00->SinCos(
-                                 stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + v0))) >> 16;
-  v123 = ((pIndoorCamera->uMapGridCellZ << 16)
-                    + 3 * stru_5C6E00->SinCos(v1 - stru_5C6E00->uIntegerHalfPi)) >> 16;
+  pDirectionIndicator1 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerDoublePi - pIndoorCamera->sRotationY);//1536
+  pDirectionIndicator2 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + pDirectionIndicator1);//512
+  v124 = ((pIndoorCamera->uMapGridCellX << 16) + 3 * stru_5C6E00->SinCos(stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + pDirectionIndicator1))) >> 16;
+  v123 = ((pIndoorCamera->uMapGridCellZ << 16) + 3 * stru_5C6E00->SinCos(pDirectionIndicator2 - stru_5C6E00->uIntegerHalfPi)) >> 16;
   v120 = pOutdoorCamera->outdoor_grid_band_3 + v124;//+- range X
   v119 = pOutdoorCamera->outdoor_grid_band_3 + v123;
   v2 = pOutdoorCamera->uCameraFovInDegrees + 15;
@@ -1042,10 +1040,10 @@
   if ( v2 > 90 )
     v2 = 90;
   v3 = (v2 << 11) / 720;
-  v4 = stru_5C6E00->uDoublePiMask & (v0 - v3);
-  v5 = stru_5C6E00->uDoublePiMask & (v3 + v0);
+  v4 = stru_5C6E00->uDoublePiMask & (pDirectionIndicator1 - v3);
+  v5 = stru_5C6E00->uDoublePiMask & (v3 + pDirectionIndicator1);
   v106 = stru_5C6E00->SinCos(v4);
-  v107 = stru_5C6E00->SinCos(v4 - stru_5C6E00->uIntegerHalfPi);
+  uEndZ = stru_5C6E00->SinCos(v4 - stru_5C6E00->uIntegerHalfPi);
   v111 = stru_5C6E00->SinCos(v5);
   v6 = stru_5C6E00->SinCos(v5 - stru_5C6E00->uIntegerHalfPi);
   v7 = v4 & stru_5C6E00->uPiMask;
@@ -1070,8 +1068,8 @@
   v110 = (v106 >= 0 ? 1: -1);//2 * (v106 >= 0) - 1;
   v126 = v124;
   v118 = v123;
-  v109 = (v107 >= 0 ? 1: -1);//2 * (v107 >= 0) - 1;
-  v107 = (v111 >= 0 ? 1: -1);//2 * (v111 >= 0) - 1;
+  v109 = (uEndZ >= 0 ? 1: -1);//2 * (v107 >= 0) - 1;
+  uEndZ = (v111 >= 0 ? 1: -1);//2 * (v111 >= 0) - 1;
   terrain_76E1C8[0] = 65535;
   //v116 = 1;
   v106 = (v6 >= 0 ? 1: -1);//2 * (v6 >= 0) - 1;
@@ -1118,7 +1116,7 @@
       v114 += v111;//
       if ( v111 + v114 >= 65536 )
       {
-        v126 += v107;
+        v126 += uEndZ;
         v114 = (unsigned __int16)v114;//
       }
       v118 += v106;
@@ -1126,7 +1124,7 @@
     else
     {
       v125 += v108;
-      v126 += v107;
+      v126 += uEndZ;
       if ( v125 >= 65536 )
       {
         v118 += v106;
@@ -1573,52 +1571,41 @@
     for ( i = v69; i >= 1; --i )
     {
       //v70 = i;
-      v71 = terrain_76D7C8[i];
-      v72 = terrain_76DBC8[i];
+      v71 = terrain_76D7C8[i];//88
+      v72 = terrain_76DBC8[i];//0
       if ( v71 < v72 )//swap
       {
         terrain_76DBC8[i] = v71;
         terrain_76D7C8[i] = v72;
       }
-      v73 = terrain_76DBC8[i];
+      x = terrain_76DBC8[i];//0
       v111 = 0;
-      if ( v73 <= 0 )
-        v73 = -v73;
+      if ( x <= 0 )
+        x = -x;
       v74 = terrain_76D7C8[i];
       if ( v74 <= 0 )
         v74 = -v74;
       v75 = v74 + 2;
       //pIndoorCameraD3D_3 = pGame->pIndoorCameraD3D;
-      v107 = v75;
+      uEndZ = v75;
       //pIndoorCameraD3D_4 = pIndoorCameraD3D_3;
-      v77 = v73 - 2;
-      if ( v73 - 2 < v75 )
+      uStartZ = x - 2;
+      if ( x - 2 < v75 )
       {
         v127 = 0;
         //v79 = (v73 - 66) << 9;
         //v116 = v77;
         //pHeight = v79;
-        v111 = v75 - v77;
-        for (int j = v77; j < v107; ++j)
-        {// âûñîòà ÷åòûðåõ âåðøèí ÿ÷åéêè
-		  /* *(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*/
-          ptr_801A08[v127].vWorldPosition.x = (v73 - 66 + v127) * 512;
+        v111 = v75 - uStartZ;
+        for (int z = uStartZ; z < uEndZ; ++z)
+        {
+          ptr_801A08[v127].vWorldPosition.x = (-64 + x) * 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 */
-          ptr_801A04[v127].vWorldPosition.x = (v73 - 66 + v127) * 512;
+          ptr_801A08[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( z, terrain_76D9C8[i]);
+
+          ptr_801A04[v127].vWorldPosition.x = (-64 + x) * 512;
           ptr_801A04[v127].vWorldPosition.y = (63 - terrain_76D9C8[i]) * 512;
-          ptr_801A04[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( j, terrain_76D9C8[i] + 1);
+          ptr_801A04[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( z, terrain_76D9C8[i] + 1);
 
           if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
           {
@@ -1637,7 +1624,7 @@
 	  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);
+        Render::RenderTerrainD3D();//Render::DrawTerrainD3D(v111, 0, (int)&v102);
       else
         Render::DrawTerrainSW(v111, 0, (int)&v102);
     }
@@ -1714,7 +1701,253 @@
 // 47FFC4: inconsistent fpu stack
 // 4D864C: using guessed type char byte_4D864C;
 
-
+void Render::RenderTerrainD3D() // New function
+{
+  char result; // al@3
+  //int v1; // eax@3
+  //int v2; // ebx@4
+  //struct ODMFace *v4; // esi@6
+  int v6; // ecx@8
+  //int v7; // ecx@8
+ struct stru148 *v8; // ebx@8
+  //char v11; // zf@8
+ struct stru148 *v16;
+  unsigned int v18; // edi@22
+  //int v20; // edi@34
+  //int v28; // eax@50
+  //int v29; // ecx@55
+  //int v30; // eax@57
+  int v31; // eax@57
+  int v35; // edi@63
+  int v37; // eax@73
+  int v39; // eax@80
+  char v40; // [sp-18h] [bp-70h]@2
+  int v41; // [sp-14h] [bp-6Ch]@2
+  int v42; // [sp-10h] [bp-68h]@2
+  int v43; // [sp-Ch] [bp-64h]@2
+  const char *v44; // [sp-8h] [bp-60h]@2
+  int v45; // [sp-4h] [bp-5Ch]@2
+  //float v48; // [sp+14h] [bp-44h]@8
+  //void *v52; // [sp+24h] [bp-34h]@3
+  bool v54; // [sp+2Ch] [bp-2Ch]@10
+  int v55; // [sp+30h] [bp-28h]@34
+  int v56;
+  int v57; // [sp+38h] [bp-20h]@36
+  int v58; // [sp+3Ch] [bp-1Ch]@8
+  int v63; // [sp+50h] [bp-8h]@3
+  int v64; // [sp+57h] [bp-1h]@2
+  int v62;
+
+  v63 = 0;
+
+  // basic optimizations
+ unsigned int uStartX, uEndX,
+              uStartZ, uEndZ;
+ if (pIndoorCamera->sRotationY >= 0 && pIndoorCamera->sRotationY <= 1024)
+ {
+  /*      CAMERA
+       ï/2     512
+            ^
+       \    |    /
+         \  |  /
+   ï  _____\|/______ +  0
+ 1024       |        x  0
+            |
+           - y
+       3ï/2   1536
+  */
+  uStartX = 0, uEndX = 128;
+  uStartZ = 0, uEndZ = 64 + 16;
+ }
+ else if (pIndoorCamera->sRotationY >= 512 && pIndoorCamera->sRotationY <= 1536)
+ {
+  /*         ï/2     512
+                 + y
+             \    |     
+               \  |   
+CAMERA   ï  _____\| ______ +  0
+       1024      /|        x  0
+               /  |
+             /   - y
+             3ï/2   1536
+  */
+  uStartX = 0, uEndX = 64 + 16;
+  uStartZ = 0, uEndZ = 128;
+ }
+ else if (pIndoorCamera->sRotationY >= 1536 || pIndoorCamera->sRotationY <= 512)
+ {
+  /*         ï/2     512
+                 + y
+                  |    /  
+                  |  /  
+         ï  _____ |/______ +  0     CAMERA
+       1024       |\       x  0
+                  |  \
+                 - y   \
+             3ï/2   1536
+  */
+  uStartX = 64 - 16, uEndX = 128;
+  uStartZ = 0, uEndZ = 128;
+ }
+ else
+ {
+  uStartX = 0, uEndX = 128;
+  uStartZ = 64 - 16, uEndZ = 128;
+ }
+
+// uStartX = 0, uEndX = 128;
+// uStartZ = 0, uEndZ = 128;
+
+
+ static RenderVertexSoft pTerrainVertices[128 * 128];
+ for (unsigned int z = uStartZ; z < uEndZ; ++z)
+   for (unsigned int x = uStartX; x < uEndX; ++x)
+   {
+    pTerrainVertices[z * 128 + x].vWorldPosition.x = (-64 + (signed)x) * 512;
+    pTerrainVertices[z * 128 + x].vWorldPosition.y = (64 - (signed)z) * 512;
+    pTerrainVertices[z * 128 + x].vWorldPosition.z = 32 * pOutdoor->pTerrain.pHeightmap[z * 128 + x];
+
+    struct IndoorCameraD3D *pIndoorCameraD3D = pGame->pIndoorCameraD3D;
+    pIndoorCameraD3D->ViewTransform(&pTerrainVertices[z * 128 + x], 1);
+    pIndoorCameraD3D->Project(&pTerrainVertices[z * 128 + x], 1, 0);
+   }
+
+
+
+ for (unsigned int z = uStartZ; z < uEndZ - 1; ++z)
+   for (unsigned int x = uStartX; x < uEndX - 1; ++x)
+   {
+    v8 = &array_77EC08[pOutdoorCamera->numStru148s];
+    v8->flags = 0;
+    v8->field_32 = 0;
+
+    //unsigned int uTileID = pOutdoor->pTerrain.pTilemap[z * 128 + x];
+    //struct TileDesc *pTile = pOutdoor->pTerrain->pTileTable->GetTileById(uTileID);
+    v8->uTileBitmapID = pOutdoor->DoGetTileTexture(x, z);
+    /*if (uTileID == 1 ||   //dirttyl BitmapID 88
+        uTileID == 2 ||   //dirt1 BitmapID 126
+        uTileID == 3 ||   //dirttyl BitmapID 88
+        uTileID == 4 ||   //dirt2 BitmapID 127
+        uTileID == 11 ||  //dirttyl BitmapID 127
+
+        uTileID == 90 ||  //grastyl BitmapID 110
+        uTileID == 92 ||  //grastyl BitmapID 110
+
+        uTileID == 102 || //grdrtNE BitmapID 128
+        uTileID == 104 || //grdrtNW BitmapID 130
+        uTileID == 105 || //grdrtSW BitmapID 131
+        uTileID == 106 || //grdrtE BitmapID 132
+        uTileID == 107 || //grdrtW BitmapID 133
+        uTileID == 108 || //grdrtN BitmapID 134
+        uTileID == 109 || //grdrtS BitmapID 135
+        uTileID == 110 || //grdrtXNE BitmapID 136
+        uTileID == 112 || //grdrtXNW BitmapID 138
+        uTileID == 113 || //grdrtXSW BitmapID 139
+
+        uTileID == 126 || uTileID == 127 || uTileID == 128 || uTileID == 129 ||
+        uTileID == 130 || //wtrtyl BitmapID 89
+        uTileID == 131 || //wtrtyl BitmapID 89
+        uTileID == 132 || //wtrtyl BitmapID 89
+        uTileID == 133 || //wtrtyl BitmapID 89
+        uTileID == 134 || //wtrtyl BitmapID 89
+        uTileID == 135 || //wtrtyl BitmapID 89
+        uTileID == 136 || //wtrtyl BitmapID 89
+        uTileID == 137 || //wtrtyl BitmapID 89
+
+        uTileID == 139 || //wtrdrSE BitmapID 141
+        uTileID == 141 || //wrtdrSW BitmapID 143
+        uTileID == 142 || //wrtdrE BitmapID 144
+        uTileID == 143 || //wrtdrW BitmapID 145
+        uTileID == 145 || //wtrdrS BitmapID 147
+        uTileID == 147 || //wtrdrXSE BitmapID 149
+        uTileID == 149 ) //wtrdrXSW BitmapID 151
+      continue;*/
+
+    /*if (uTileID == 199 || //dirttyl BitmapID 0
+        uTileID == 200 || //dirttyl BitmapID 0
+        uTileID == 201 || //dirttyl BitmapID 0
+        uTileID == 202 || //dirttyl BitmapID 0
+        uTileID == 203 || //dirttyl BitmapID 0
+        uTileID == 204 || //dirttyl BitmapID 0
+        uTileID == 212 || //dirttyl BitmapID 0
+        uTileID == 217) //dirttyl BitmapID 0
+     continue;*/
+
+    v6 = v8->uTileBitmapID;
+    v8->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v6];
+
+    if (v8->uTileBitmapID == 0xFFFF)
+      continue;
+
+    v8->sTextureDeltaU = 0;
+    v8->sTextureDeltaV = 0;
+
+
+/* world coordinates, z -> height
+            32767
+             +y
+
+ -32768 -x        +x 32767
+
+             -y
+           -32768
+*/
+
+    memcpy(array_73D150 + 0, &pTerrainVertices[z * 128 + x], sizeof(RenderVertexSoft));
+    array_73D150[0].u = 0;
+    array_73D150[0].v = 0;
+
+    memcpy(array_73D150 + 1, &pTerrainVertices[z * 128 + x + 1], sizeof(RenderVertexSoft));
+    array_73D150[1].u = 1;
+    array_73D150[1].v = 0;
+
+    memcpy(array_73D150 + 2, &pTerrainVertices[(z + 1) * 128 + x + 1], sizeof(RenderVertexSoft));
+    array_73D150[2].u = 1;
+    array_73D150[2].v = 1;
+
+    memcpy(array_73D150 + 3, &pTerrainVertices[(z + 1) * 128 + x], sizeof(RenderVertexSoft));
+    array_73D150[3].u = 0;
+    array_73D150[3].v = 1;
+
+
+      v55 = 0;
+      v54 = false;
+      v58 = 0;
+
+      if (v58 == 4) // if all y == first y;  primitive in xz plane 
+        v8->field_32 |= 0x0001;
+
+      v8->pODMFace = nullptr;
+      v8->uNumVertices = 4;
+      v8->field_59 = 5;
+
+      v8->field_58 = 0;
+
+      ++pOutdoorCamera->numStru148s;
+      ++pOutdoorCamera->field_44;
+
+
+
+        v8->uBModelID = 0;
+        v8->uBModelFaceID = 0;
+        v31 = (8 * (0 | (0 << 6)));
+        v8->field_50 = v31 | 6;
+
+        for (unsigned int k = 0; k < 4; ++k)
+        {
+         memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft));
+         array_50AC10[k].flt_20 = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097);
+        }
+
+
+        pRenderer->DrawTerrainPolygon(v8, pBitmaps_LOD->pHardwareTextures[v6]);
+
+      --pOutdoorCamera->numStru148s;
+      --pOutdoorCamera->field_44;
+
+    }
+
+  }
 
 //----- (0048034E) --------------------------------------------------------
 void Render::DrawTerrainD3D(int a1, int a2, int a3)
@@ -1758,7 +1991,7 @@
   stru148 *v38; // ecx@55
   unsigned int v39; // eax@59
   stru148 *v40; // ebx@62
-  unsigned __int16 v41; // ax@62
+  unsigned __int16 pTileBitmapsID; // ax@62
   int v42; // eax@63
   LightmapBuilder *v43; // ecx@63
   int v44; // eax@63
@@ -1788,7 +2021,7 @@
   double v68; // st5@120
   double v69; // st7@133
   int v70; // edi@138
-  RenderVertexSoft *v71; // esi@147
+  stru148 *v71; // esi@147
   unsigned int v72; // ecx@147
   unsigned int v73; // eax@150
   int v74; // eax@154
@@ -1881,464 +2114,432 @@
           && !sub_481EFA(v8, v9, v101, pVertices, 1)) )*/
       if ( !&stru_76E5C8[(v5 << 7) + v6] )
         goto LABEL_162;
-      
       v8 = &pVerticesSR_806210[v4];
       pVertices2 = &pVerticesSR_801A10[v4 + 1];
       v102 = v8;
       if (!v82)
       {
-       pVertices = &pVerticesSR_801A10[v4];
-       v101 = &pVerticesSR_806210[v4 + 1];
+        pVertices = &pVerticesSR_801A10[v4];
+        v101 = &pVerticesSR_806210[v4 + 1];
       }
       else
       {
-       pVertices = &pVerticesSR_801A10[v4 + 1];
-       v101 = &pVerticesSR_806210[v4];
-      }
-
+        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 )
+        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->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, pVertices, v101, v16) )
+        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->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, pVertices, v101, v16) )
           //goto LABEL_126;
           {
-           --pOutdoorCamera->numStru148s;
-           goto LABEL_162;
-          }
-        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 = 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 = 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.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;
-
-        /*if ( !(byte_76D5C0 & 1) )
-        {
-          byte_76D5C0 |= 1u;
-          stru154(stru_76D5A8);
-          atexit(loc_481199);
-        }*/
-        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 )
-        {
-          thisa = pGame->pIndoorCameraD3D;
-          if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 )
+            --pOutdoorCamera->numStru148s;
             goto LABEL_162;
-          thisa->ViewTransform(array_50AC10, a5);
-          thisa->Project(array_50AC10, a5, 0);
-        }
-        this_3 = v102->vWorldViewPosition.x < 8.0
-              || pVertices->vWorldViewPosition.x < 8.0
-              || v101->vWorldViewPosition.x < 8.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 )
-            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,
-              4,
-              &static_sub_0048034E_stru_154,
-              a5,
-              array_50AC10,
-              0,
-              *(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;
-        v16->uNumVertices = a5;
-        if ( !byte_4D864C || ~pGame->uFlags & 0x80 )
-        {
-          if ( this_3 )
+          }
+          memcpy(&array_50AC10[0], v102, 0x30u);
+          array_50AC10[0].flt_20 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097);
+          array_50AC10[0].u = 0.0;
+          array_50AC10[0].v = 0.0;
+          memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1]));
+          array_50AC10[1].flt_20 = 1.0 / (pVertices->vWorldViewPosition.x + 0.0000001000000011686097);
+          array_50AC10[1].u = 0.0;
+          array_50AC10[1].v = 1.0;
+          memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2]));
+          array_50AC10[2].flt_20 = 1.0 / (pVertices2->vWorldViewPosition.x + 0.0000001000000011686097);
+          array_50AC10[2].u = 1.0;
+          array_50AC10[2].v = 1.0;
+          memcpy(&array_50AC10[3], v101, sizeof(array_50AC10[3]));
+          array_50AC10[3].flt_20 = 1.0 / (v101->vWorldViewPosition.x + 0.0000001000000011686097);
+          array_50AC10[3].u = 1.0;
+          array_50AC10[3].v = 0.0;
+          /*if ( !(byte_76D5C0 & 1) )
+          {
+            byte_76D5C0 |= 1u;
+            stru154(stru_76D5A8);
+            atexit(loc_481199);
+          }*/
+          v32 = (struct8 *)array_50AC10;
+          v97 = (int)pGame->pLightmapBuilder;
+          pGame->pLightmapBuilder->StackLights_TerrainFace(v23, &v95, array_50AC10, 4, 1);
+          pDecalBuilder->_49BE8A(v16, *(float *)&v23, (int)&v95, array_50AC10, 4, 1);
+          a5 = 4;
+          if ( byte_4D864C && pGame->uFlags & 0x80 )
+          {
+            thisa = pGame->pIndoorCameraD3D;
+            if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 )
+              goto LABEL_162;
+            thisa->ViewTransform(array_50AC10, a5);
+            thisa->Project(array_50AC10, a5, 0);
+          }
+          this_3 = v102->vWorldViewPosition.x < 8.0 || pVertices->vWorldViewPosition.x < 8.0
+              || v101->vWorldViewPosition.x < 8.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 )
           {
-            v36 = sr_424CD7(v34);
-            v16->uNumVertices = v36;
-            OutdoorCamera::Project(v36);
+            if ( this_3 )
+              v33 = 3;
+            else
+              v33 = v108 != 0 ? 5 : 0;
+            static_sub_0048034E_stru_154._49B0C9(v23, v95);
+            if ( pDecalBuilder->uNumDecals > 0 )
+              pDecalBuilder->ApplyDecals(31 - v16->field_58, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1);
           }
-          if ( v108 )
-          {
-            v36 = sr_424EE0_MakeFanFromTriangle(v34);
-            v16->uNumVertices = v36;
-            OutdoorCamera::Project(v36);
-          }
-        }
-        //v37 = *(int *)&v16->flags;
-        if ( ~v16->flags & 1 )
-        {
-          if ( v16->flags & 2 && v16->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
+          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;
+          v16->uNumVertices = a5;
+          if ( !byte_4D864C || ~pGame->uFlags & 0x80 )
           {
-            v80 = false;
-            v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
-          }
-          else
-          {
-            v39 = v16->uTileBitmapID;
-            v80 = true;
+            if ( this_3 )
+            {
+              v36 = sr_424CD7(v34);
+              v16->uNumVertices = v36;
+              OutdoorCamera::Project(v36);
+            }
+            if ( v108 )
+            {
+              v36 = sr_424EE0_MakeFanFromTriangle(v34);
+              v16->uNumVertices = v36;
+              OutdoorCamera::Project(v36);
+            }
           }
-          //v79 = 0;
-          v78 = pBitmaps_LOD->pHardwareTextures[v39];
-          v77 = (int)v16;
-          v76 = v16->uNumVertices;
+          //v37 = *(int *)&v16->flags;
+          if ( ~v16->flags & 1 )
+          {
+            if ( v16->flags & 2 && v16->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
+            {
+              v80 = false;
+              v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
+            }
+            else
+            {
+              v39 = v16->uTileBitmapID;
+              v80 = true;
+            }
+            //v79 = 0;
+            //v78 = pBitmaps_LOD->pHardwareTextures[v39];
+            v16->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v39];// Ritor1: It's temporary
+            v77 = (int)v16;
+            //v76 = v16->uNumVertices;
 //LABEL_161:
-          pRenderer->DrawTerrainPolygon(v76, v16, v78, false, v80);
-          goto LABEL_162;
-        }
-        v38 = v16;
+            pRenderer->DrawTerrainPolygon(v16, pBitmaps_LOD->pHardwareTextures[v39]);//pRenderer->DrawTerrainPolygon(v16->uNumVertices, v16, pBitmaps_LOD->pHardwareTextures[v39], false, v80);
+            goto LABEL_162;
+          }
+          v38 = v16;
 LABEL_56:
-        v38->_4811A3();
-      }
+          v38->_4811A3();
+        }
 LABEL_162:
-      v4 = v88 + 1;
-      if ( ++v88 >= v84 )
+        v4 = v88 + 1;
+        if ( ++v88 >= v84 )
+          return;
+      }
+      v40 = &array_77EC08[pOutdoorCamera->numStru148s];
+      v40->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY);
+      if ( v40->uTileBitmapID == -1 )
+        goto LABEL_162;
+      v42 = pOutdoor->GetSomeOtherTileInfo(sX, sY);
+      BYTE1(v42) |= 0x80u;
+      v43 = pGame->pLightmapBuilder;
+      *(int *)&v40->flags = v42;
+      v44 = v93;
+      v40->field_59 = 1;
+      v40->field_5D = (char)v43;
+      v40->field_34 = *(_WORD *)(v44 + 2);
+      v45 = v89;
+      v40->field_5C = v89;
+      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->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 ( LOBYTE(v50) < 0 )
+        v40->field_58 = 0;
+      if ( pOutdoorCamera->numStru148s >= 1999 )
         return;
-    }
-    v40 = &array_77EC08[pOutdoorCamera->numStru148s];
-    v41 = pOutdoor->GetTileTexture(sX, sY);
-    v40->uTileBitmapID = v41;
-    if ( v41 == -1 )
-      goto LABEL_162;
-    v42 = pOutdoor->GetSomeOtherTileInfo(sX, sY);
-    BYTE1(v42) |= 0x80u;
-    v43 = pGame->pLightmapBuilder;
-    *(int *)&v40->flags = v42;
-    v44 = v93;
-    v40->field_59 = 1;
-    v40->field_5D = (char)v43;
-    v40->field_34 = *(_WORD *)(v44 + 2);
-    v45 = v89;
-    v40->field_5C = v89;
-    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->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 ( LOBYTE(v50) < 0 )
-      v40->field_58 = 0;
-    if ( pOutdoorCamera->numStru148s >= 1999 )
-      return;
-    ++pOutdoorCamera->numStru148s;
-    if ( !sub_481FC9(pVertices, pVertices2, v8, v40) )
-      //goto LABEL_77;
-      {
+      ++pOutdoorCamera->numStru148s;
+      /*if ( !sub_481FC9(pVertices, pVertices2, v8, v40) ) // Ritor1: It's temporary
+        //goto LABEL_77;
+        {
+          --pOutdoorCamera->numStru148s;
+          goto LABEL_112;
+        }*/
+      memcpy(&array_50AC10[0], v102, 0x30u);
+      array_50AC10[0].flt_20 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097);
+      array_50AC10[0].u = 0.0;
+      array_50AC10[0].v = 0.0;
+      memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1]));
+      array_50AC10[1].flt_20 = 1.0 / pVertices->vWorldViewPosition.x + 0.0000001000000011686097;
+      array_50AC10[1].u = 0.0;
+      array_50AC10[1].v = 1.0;
+      memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2]));
+      array_50AC10[2].flt_20 = 1.0 / pVertices2->vWorldViewPosition.x + 0.0000001000000011686097;
+      array_50AC10[2].u = 1.0;
+      array_50AC10[2].v = 1.0;
+      static stru154 static_sub_0048034E_stru_76D590;
+      /*static bool __init_flag2 = false;
+      if (!__init_flag2)
+      {
+        __init_flag2 = true;
+        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(v48, (float *)&a4, array_50AC10, 3, 0);
+      pDecalBuilder->_49BE8A(v40, *(float *)&v48, (int)&a4, array_50AC10, 3, 0);
+      uNumVertices = 3;
+      if ( byte_4D864C && pGame->uFlags & 0x80 )
+      {
+        thisb = pGame->pIndoorCameraD3D;
+        if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &uNumVertices, 0) == 1 && !uNumVertices )
+        {
+//LABEL_77:
+          --pOutdoorCamera->numStru148s;
+          goto LABEL_112;
+        }
+        thisb->ViewTransform(array_50AC10, uNumVertices);
+        thisb->Project(array_50AC10, uNumVertices, 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 < 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 )
+      {
+        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(v48, *(float *)&a4);
+        if ( pDecalBuilder->uNumDecals > 0 )
+          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)pVertices);
+      v55 = uNumVertices;
+      //v35 = byte_4D864C == 0;
+      v40->uNumVertices = uNumVertices;
+      if ( !byte_76D5C0 || !(pGame->uFlags & 0x80) )
+      {
+        if ( this_3a )
+        {
+          v56 = sr_424CD7(v55);
+        }
+        else
+        {
+          if ( !v108 )
+            goto LABEL_105;
+          v56 = sr_424EE0_MakeFanFromTriangle(v55);
+        }
+        v40->uNumVertices = v56;
+        OutdoorCamera::Project(v56);
+      }
+LABEL_105:
+      v57 = *(int *)&v40->flags;
+      if ( BYTE1(v57) & 1 )
+      {
+        v40->_4811A3();
+      }
+      else
+      {
+        if ( v57 & 2 && v40->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
+        {
+          v81 = 0;
+          v58 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
+        }
+        else
+        {
+          v58 = v40->uTileBitmapID;
+          v81 = 1;
+        }
+        pRenderer->DrawTerrainPolygon(v40, pBitmaps_LOD->pHardwareTextures[v58]);
+      }
+LABEL_112:
+      v59 = &array_77EC08[pOutdoorCamera->numStru148s];
+      //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 = *(_WORD *)(v61 + 2);
+      v59->field_5C = v89;
+      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->y;
+      //v99 = v63;
+      thish = 20.0 - (-v64 - v91 * v63->y - v90 * v63->x) * 20.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, v102, pVertices2, v59) )
+      {
+//LABEL_126:
         --pOutdoorCamera->numStru148s;
-        goto LABEL_112;
-      }
-    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 = 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 = 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;
-
-    static stru154 static_sub_0048034E_stru_76D590;
-    /*static bool __init_flag2 = false;
-    if (!__init_flag2)
-    {
-      __init_flag2 = true;
-
-      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, 3, 0);
-    pDecalBuilder->_49BE8A(v40, *(float *)&v99, (int)&a4, array_50AC10, 3, 0);
-    uNumVertices = 3;
-    if ( byte_4D864C && pGame->uFlags & 0x80 )
-    {
-      thisb = pGame->pIndoorCameraD3D;
-      if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &uNumVertices, 0) == 1 && !uNumVertices )
-      {
-//LABEL_77:
-        --pOutdoorCamera->numStru148s;
-        goto LABEL_112;
-      }
-      thisb->ViewTransform(array_50AC10, uNumVertices);
-      thisb->Project(array_50AC10, uNumVertices, 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 < 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 )
-    {
-      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)pVertices, -1);
-    }
-    if ( stru_F8AD28.uNumLightsApplied > 0 )
-      v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices);
-    v55 = uNumVertices;
-    //v35 = byte_4D864C == 0;
-    v40->uNumVertices = uNumVertices;
-    if ( !byte_76D5C0 || !(pGame->uFlags & 0x80) )
-    {
-      if ( this_3a )
-      {
-        v56 = sr_424CD7(v55);
+        goto LABEL_162;
+      }
+      memcpy(&array_50AC10[0], v102, 0x30u);
+      array_50AC10[0].flt_20 = 1.0 / (v102->vWorldViewPosition.x + 0.0000001000000011686097);
+      array_50AC10[0].u = 0.0;
+      array_50AC10[0].v = 0.0;
+      memcpy(&array_50AC10[1], pVertices2, sizeof(array_50AC10[1]));
+      array_50AC10[1].flt_20 = 1.0 / pVertices2->vWorldViewPosition.x + 0.0000001000000011686097;
+      array_50AC10[1].u = 1.0;
+      array_50AC10[1].v = 1.0;
+      memcpy(&array_50AC10[2], v101, sizeof(array_50AC10[2]));
+      array_50AC10[2].flt_20 = 1.0 / v101->vWorldViewPosition.x + 0.0000001000000011686097;
+      array_50AC10[2].u = 1.0;
+      array_50AC10[2].v = 0.0;
+      static stru154 static_sub_0048034E_stru_76D578;
+      /*static bool __init_flag1 = false;
+      if (!__init_flag1)
+      {
+        __init_flag1 = true;
+        stru154::stru154(&static_sub_0048034E_stru_76D578);
+      }*/
+      v96 = pGame->pLightmapBuilder;
+      pGame->pLightmapBuilder->StackLights_TerrainFace(v63, &v87, array_50AC10, 3, 1);
+      pDecalBuilder->_49BE8A(v40, *(float *)&v63, (int)&v87, array_50AC10, 3, 1);
+      v100 = 3;
+      if ( byte_4D864C && pGame->uFlags & 0x80 )
+      {
+        thisc = pGame->pIndoorCameraD3D;
+        if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, (unsigned int *)&v100, 0) == 1 && !v100 )
+          //goto LABEL_126;
+        {
+          --pOutdoorCamera->numStru148s;
+          goto LABEL_162;
+        }
+        thisc->ViewTransform(array_50AC10, v100);
+        thisc->Project(array_50AC10, v100, 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 < 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 )
+          v70 = 3;
+        else
+          v70 = v108 != 0 ? 5 : 0;
+        static_sub_0048034E_stru_76D578._49B0C9(v63, v87);
+        if ( pDecalBuilder->uNumDecals > 0 )
+          pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70, -1);
+      }
+      if ( stru_F8AD28.uNumLightsApplied > 0 )
+        v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70);
+      v71 = v59;
+      v72 = v100;
+      //v35 = byte_4D864C == 0;
+      v59->uNumVertices = v100;//???
+      if ( !byte_4D864C && pGame->uFlags & 0x80 )
+        goto LABEL_154;
+      if ( this_3b )
+      {
+        v73 = sr_424CD7(v72);
       }
       else
       {
         if ( !v108 )
-          goto LABEL_105;
-        v56 = sr_424EE0_MakeFanFromTriangle(v55);
-      }
-      v40->uNumVertices = v56;
-      OutdoorCamera::Project(v56);
-    }
-LABEL_105:
-    v57 = *(int *)&v40->flags;
-    if ( BYTE1(v57) & 1 )
-    {
-      v40->_4811A3();
-    }
-    else
-    {
-      if ( v57 & 2 && v40->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
-      {
-        v81 = 0;
-        v58 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
-      }
-      else
-      {
-        v58 = v40->uTileBitmapID;
-        v81 = 1;
-      }
-      pRenderer->DrawTerrainPolygon(v40->uNumVertices, v40, pBitmaps_LOD->pHardwareTextures[v58], 0, v81);
-    }
-LABEL_112:
-    v59 = &array_77EC08[pOutdoorCamera->numStru148s];
-    //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 = *(_WORD *)(v61 + 2);
-    v59->field_5C = v89;
-    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->y;
-    //v99 = v63;
-    thish = 20.0 - (-v64 - v91 * v63->y - v90 * v63->x) * 20.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, v102, pVertices2, v59) )
-    {
-//LABEL_126:
-      --pOutdoorCamera->numStru148s;
-      goto LABEL_162;
-    }
-    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 = 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.0000001000000011686097;
-    memcpy(&array_50AC10[2], v101, sizeof(array_50AC10[2]));
-    array_50AC10[2].flt_20 = 1.0 / v68;
-    array_50AC10[2].u = 1.0;
-    array_50AC10[2].v = 0.0;
-
-    static stru154 static_sub_0048034E_stru_76D578;
-    /*static bool __init_flag1 = false;
-    if (!__init_flag1)
-    {
-      __init_flag1 = true;
-
-      stru154::stru154(&static_sub_0048034E_stru_76D578);
-    }*/
-
-    v96 = pGame->pLightmapBuilder;
-    pGame->pLightmapBuilder->StackLights_TerrainFace(v99, &v87, array_50AC10, 3u, 1);
-    pDecalBuilder->_49BE8A(v40, *(float *)&v99, (int)&v87, array_50AC10, 3u, 1);
-    v100 = 3;
-    if ( byte_4D864C && pGame->uFlags & 0x80 )
-    {
-      thisc = pGame->pIndoorCameraD3D;
-      if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, (unsigned int *)&v100, 0) == 1 && !v100 )
-        //goto LABEL_126;
-        {
-         --pOutdoorCamera->numStru148s;
-         goto LABEL_162;
-        }
-      thisc->ViewTransform(array_50AC10, v100);
-      thisc->Project(array_50AC10, v100, 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 < 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 )
-        v70 = 3;
-      else
-        v70 = v108 != 0 ? 5 : 0;
-      static_sub_0048034E_stru_76D578._49B0C9(v99, v87);
-      if ( pDecalBuilder->uNumDecals > 0 )
-        pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70, -1);
-    }
-    if ( stru_F8AD28.uNumLightsApplied > 0 )
-      v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70);
-    v71 = (RenderVertexSoft *)v59;
-    v72 = v100;
-    //v35 = byte_4D864C == 0;
-    v59->uNumVertices = v100;//???
-    if ( !byte_4D864C && pGame->uFlags & 0x80 )
+        {
+LABEL_154:
+          v74 = v71->flags;
+          if ( !(BYTE1(v74) & 1) )
+          {
+            if ( v74 & 2 && v71->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
+            {
+              v80 = false;
+              v75 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
+            }
+            else
+            {
+              v75 = v71->uTileBitmapID;
+              v80 = true;
+            }
+            //v79 = 0;
+            //v78 = pBitmaps_LOD->pHardwareTextures[v75];
+            v71->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v75];// Ritor1: It's temporary
+            //v77 = (int)v71;
+            //v76 = v71->uNumVertices;
+            //goto LABEL_161;
+            pRenderer->DrawTerrainPolygon(v71, pBitmaps_LOD->pHardwareTextures[v75]);//pRenderer->DrawTerrainPolygon(v76, (stru148 *)v71, v78, v79, v80);
+            goto LABEL_162;
+          }
+          v38 = (stru148 *)v71;
+          goto LABEL_56;
+        }
+        v73 = sr_424EE0_MakeFanFromTriangle(v72);
+      }
+      v71->uNumVertices = v73;
+      OutdoorCamera::Project(v73);
       goto LABEL_154;
-    if ( this_3b )
-    {
-      v73 = sr_424CD7(v72);
-    }
-    else
-    {
-      if ( !v108 )
-      {
-LABEL_154:
-        v74 = v71[1].vWorldPosition.x;
-        if ( !(BYTE1(v74) & 1) )
-        {
-          if ( v74 & 2 && LOWORD(v71[1].vWorldViewProjY) == pRenderer->field_1036AC_bitmapid )
-          {
-            v80 = false;
-            v75 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
-          }
-          else
-          {
-            v75 = v71[1].vWorldViewProjY;
-            v80 = true;
-          }
-          //v79 = 0;
-          v78 = pBitmaps_LOD->pHardwareTextures[v75];
-          v77 = (int)v71;
-          v76 = v71->vWorldViewPosition.z;
-          //goto LABEL_161;
-          {
-           pRenderer->DrawTerrainPolygon(v76, (stru148 *)v71, v78, v79, v80);
-           goto LABEL_162;
-          }
-        }
-        v38 = (stru148 *)v71;
-        goto LABEL_56;
-      }
-      v73 = sr_424EE0_MakeFanFromTriangle(v72);
-    }
-    v71->vWorldViewPosition.z = v73;
-    OutdoorCamera::Project(v73);
-    goto LABEL_154;
-  }
-}
+    }
+  }
 // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
 // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
 // 4D864C: using guessed type char byte_4D864C;
@@ -7126,7 +7327,119 @@
   return ::GetActorTintColor(a3, a4, a2, a5, a6);
 }
 
-
+void Render::DrawTerrainPolygon(stru148 *a3, IDirect3DTexture2 *pTexture)//new function
+{
+  int v5; // ebx@1
+  int v6; // edi@1
+  int v8; // eax@7
+  float v9; // eax@12
+  float *v10; // esi@12
+  float v11; // ecx@14
+  double v12; // st7@14
+  double v13; // st7@14
+  double v14; // st7@14
+  signed int v15; // eax@14
+  int v16; // eax@15
+  float v17; // ST48_4@15
+  char v18; // zf@17
+  int v19; // eax@18
+  int v20; // eax@18
+  int v21; // edx@20
+  signed int v22; // ecx@20
+  int v23; // eax@20
+  const char *v24; // ST4C_4@20
+  unsigned int v25; // ST50_4@20
+  int v26; // ST54_4@20
+  int v27; // eax@20
+  _UNKNOWN *v28; // eax@21
+  int v29; // ecx@23
+  int v30; // eax@23
+  int v31; // eax@23
+  int v32; // eax@24
+  int v33; // eax@25
+  int v34; // eax@25
+  int v35; // eax@25
+  int v36; // eax@25
+  signed int v37; // ecx@26
+  int v38; // eax@26
+  _UNKNOWN *v39; // eax@27
+  int v40; // edx@28
+  int v41; // eax@29
+  int v42; // eax@29
+  int v43; // eax@29
+  int v44; // eax@29
+  unsigned int v46; // eax@29
+  int v47; // eax@30
+  int v48; // eax@30
+  int v49; // eax@30
+  double v52; // st6@35
+  const char *v55; // [sp+4Ch] [bp-1Ch]@20
+  int v57; // [sp+5Ch] [bp-Ch]@3
+  signed int v59; // [sp+60h] [bp-8h]@12
+  int v61; // [sp+64h] [bp-4h]@4
+ int i;
+
+  v6 = (int)this;
+  v5 = 0;
+ if (!this->uNumD3DSceneBegins)
+   return;
+
+
+
+ 
+     this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1);
+     this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
+     if (this->bUsingSpecular)
+     {
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1);
+     }
+
+     pVertices[0].pos.x = array_50AC10[0].vWorldViewProjX;
+     pVertices[0].pos.y = array_50AC10[0].vWorldViewProjY;
+     pVertices[0].pos.z = 1.0 - 1.0 / (1000 * array_50AC10[0].vWorldViewPosition.x / (double)pOutdoorCamera->shading_dist_mist);
+     pVertices[0].rhw = 1.0 / (array_50AC10[0].vWorldViewPosition.x + 0.0000001000000011686097);
+     pVertices[0].diffuse = GetActorTintColor(a3->field_58, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
+     pVertices[0].specular = 0;
+     pVertices[0].texcoord.x = array_50AC10[0].u;
+     pVertices[0].texcoord.y = array_50AC10[0].v;
+ 
+     pVertices[1].pos.x = array_50AC10[3].vWorldViewProjX;
+     pVertices[1].pos.y = array_50AC10[3].vWorldViewProjY;
+     pVertices[1].pos.z = 1.0 - 1.0 / (1000 * array_50AC10[3].vWorldViewPosition.x / (double)pOutdoorCamera->shading_dist_mist);
+     pVertices[1].rhw = 1.0 / (array_50AC10[3].vWorldViewPosition.x + 0.0000001000000011686097);
+     pVertices[1].diffuse = GetActorTintColor(a3->field_58, 0, array_50AC10[3].vWorldViewPosition.x, 0, 0);
+     pVertices[1].specular = 0;
+     pVertices[1].texcoord.x = array_50AC10[3].u;
+     pVertices[1].texcoord.y = array_50AC10[3].v;
+
+     pVertices[2].pos.x = array_50AC10[1].vWorldViewProjX;
+     pVertices[2].pos.y = array_50AC10[1].vWorldViewProjY;
+     pVertices[2].pos.z = 1.0 - 1.0 / (1000 * array_50AC10[1].vWorldViewPosition.x / (double)pOutdoorCamera->shading_dist_mist);
+     pVertices[2].rhw = 1.0 / (array_50AC10[1].vWorldViewPosition.x + 0.0000001000000011686097);
+     pVertices[2].diffuse = GetActorTintColor(a3->field_58, 0, array_50AC10[1].vWorldViewPosition.x, 0, 0);
+     pVertices[2].specular = 0;
+     pVertices[2].texcoord.x = array_50AC10[1].u;
+     pVertices[2].texcoord.y = array_50AC10[1].v;
+
+     memcpy(pVertices + 3, pVertices + 2, sizeof(RenderVertexD3D3));
+     memcpy(pVertices + 4, pVertices + 1, sizeof(RenderVertexD3D3));
+
+     pVertices[5].pos.x = array_50AC10[2].vWorldViewProjX;
+     pVertices[5].pos.y = array_50AC10[2].vWorldViewProjY;
+     pVertices[5].pos.z = 1.0 - 1.0 / (1000 * array_50AC10[2].vWorldViewPosition.x / (double)pOutdoorCamera->shading_dist_mist);
+     pVertices[5].rhw = 1.0 / (array_50AC10[2].vWorldViewPosition.x + 0.0000001000000011686097);
+     pVertices[5].diffuse = GetActorTintColor(a3->field_58, 0, array_50AC10[2].vWorldViewPosition.x, 0, 0);
+     pVertices[5].specular = 0;
+     pVertices[5].texcoord.x = array_50AC10[2].u;
+     pVertices[5].texcoord.y = array_50AC10[2].v;
+
+
+     this->pRenderD3D->pDevice->SetTexture(0, pTexture);
+     this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, pVertices, 6, D3DDP_DONOTLIGHT);
+
+}
 //----- (004A26BC) --------------------------------------------------------
 void Render::DrawTerrainPolygon(unsigned int uNumVertices, stru148 *a4, IDirect3DTexture2 *a5, int a6, int a7)
 {
@@ -7276,13 +7589,9 @@
             v51 = a7;
           }
         }
-        ErrD3D(pRenderD3D->pDevice->SetTexture(0, a5));
-        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-          D3DPT_TRIANGLEFAN,
-          D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-          arary_77E5C8,
-          uNumVertices,
-          16));
+        this->pRenderD3D->pDevice->SetTexture(0, a5);
+        this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
+          arary_77E5C8, uNumVertices, 16);
         if ( a6 )
         {
           ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
--- a/Render.h	Tue Jan 29 10:03:07 2013 +0600
+++ b/Render.h	Mon Feb 04 09:17:35 2013 +0600
@@ -308,6 +308,7 @@
   void DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
   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(stru148 *a3, 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);
@@ -352,6 +353,7 @@
   void DrawLayingItems_Shooting_Magic_ODM();
   void TransformBillboardsAndSetPalettesODM();
   float DrawBezierTerrain();
+  void RenderTerrainD3D();
   void DrawTerrainD3D(int a1, int edx0, int a3);
   void DrawTerrainSW(int a1, int a2, int a3);
   __int16 ExecOutdoorDrawSW();
--- a/mm7_3.cpp	Tue Jan 29 10:03:07 2013 +0600
+++ b/mm7_3.cpp	Mon Feb 04 09:17:35 2013 +0600
@@ -9191,9 +9191,7 @@
     0, 0);
 
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1));
-  pRenderer->DrawTerrainPolygon(uNumVertices, this,
-    pBitmaps_LOD->pHardwareTextures[uTileBitmapID],
-    1, 1);
+  pRenderer->DrawTerrainPolygon(uNumVertices, this, pBitmaps_LOD->pHardwareTextures[uTileBitmapID], 1, 1);
 }
 
 
--- a/mm7_4.cpp	Tue Jan 29 10:03:07 2013 +0600
+++ b/mm7_4.cpp	Mon Feb 04 09:17:35 2013 +0600
@@ -1709,13 +1709,18 @@
 //----- (00487E3B) --------------------------------------------------------
 TileDesc *TileTable::GetTileById(unsigned int uTileID)
 {
-  TileDesc *result; // eax@3
+  /*TileDesc *result; // eax@3
 
   if ( (uTileID & 0x80000000u) != 0 || (signed int)uTileID > (signed int)(this->uNumTiles - 1) )
     result = this->pTiles;
   else
     result = &this->pTiles[uTileID];
-  return result;
+  return result;*/
+
+ if (uTileID < 0 || uTileID > this->uNumTiles - 1)
+   return this->pTiles;
+ else
+   return &this->pTiles[uTileID];
 }
 
 //----- (00487E58) --------------------------------------------------------