changeset 1413:3881d2f94eb1

UseNPCSkill DIALOGUE_USE_NPC_ABILITY
author Nomad
date Sat, 27 Jul 2013 16:09:00 +0200
parents 182d58b2a34c
children 110eac219e5a
files AudioPlayer.h GUIWindow.h NPC.h Outdoor.cpp Render.cpp Render.h _deleted.cpp mm7_1.cpp mm7_2.cpp mm7_3.cpp mm7_4.cpp mm7_data.h
diffstat 12 files changed, 848 insertions(+), 850 deletions(-) [+]
line wrap: on
line diff
--- a/AudioPlayer.h	Sat Jul 27 14:28:14 2013 +0200
+++ b/AudioPlayer.h	Sat Jul 27 16:09:00 2013 +0200
@@ -102,13 +102,16 @@
   SOUND_Arcomage_131 = 0x83,
   SOUND_Arcomage_WallUpgrade = 0x84,
   SOUND_GoldReceived = 0xC8,
-  SOUND_206 =206,
-  SOUND_207 =207,
+  SOUND_203 = 203,
+  SOUND_206 = 206,
+  SOUND_207 = 207,
   SOUND_OpenChest = 208,
   SOUND_PlayerCantCastSpell = 0xD1,
   SOUND_Bell = 0xD9,
   SOUND_OpenBook = 230,
   SOUND_CloseBook = 231,
+  SOUND_11090 = 11090,
+  SOUND_12040 = 12040,
   SOUND_20001 = 0x4E21,
 };
 
--- a/GUIWindow.h	Sat Jul 27 14:28:14 2013 +0200
+++ b/GUIWindow.h	Sat Jul 27 16:09:00 2013 +0200
@@ -229,7 +229,7 @@
 
 enum DIALOGUE_TYPE
 {
-  DIALOGUE_9 = 9,
+  DIALOGUE_USE_NPC_ABILITY = 9,
   DIALOGUE_13 = 0xD,
   DIALOGUE_18 = 0x12,
   DIALOGUE_19 = 19,
--- a/NPC.h	Sat Jul 27 14:28:14 2013 +0200
+++ b/NPC.h	Sat Jul 27 16:09:00 2013 +0200
@@ -193,3 +193,5 @@
 
 bool PartyHasDragon();
 bool CheckHiredNPCSpeciality(unsigned int uProfession);
+
+int UseNPCSkill(NPCProf profession);
--- a/Outdoor.cpp	Sat Jul 27 14:28:14 2013 +0200
+++ b/Outdoor.cpp	Sat Jul 27 16:09:00 2013 +0200
@@ -3167,7 +3167,7 @@
     return true;
 }
 //----- (0046D49E) --------------------------------------------------------
-int __fastcall ODM_GetFloorLevel(int X, signed int Y, int Z, int __unused, int *pIsOnWater, int *a6, int bWaterWalk)
+int ODM_GetFloorLevel(int X, signed int Y, int Z, int __unused, int *pIsOnWater, int *bmodel_pid, int bWaterWalk)
 {
   BSPModel *pBModel; // esi@4
   ODMFace *pFace; // ecx@11
@@ -3284,12 +3284,12 @@
   }
   if ( v46 == 1 )
   {
-    *a6 = 0;
+    *bmodel_pid = 0;
     return odm_floor_level[0];
   }
   v27 = 0;
   if ( v46 <= 1 )
-    *a6 = 0;
+    *bmodel_pid = 0;
   else
   {
     //v29 = 1;
@@ -3319,9 +3319,9 @@
       }
     }
     if ( !v27 )
-      *a6 = 0;
+      *bmodel_pid = 0;
     else
-      *a6 = dword_721110[v27] | (dword_721160[v27] << 6);
+      *bmodel_pid = dword_721110[v27] | (dword_721160[v27] << 6);
   }
   if ( v27 )
   {
--- a/Render.cpp	Sat Jul 27 14:28:14 2013 +0200
+++ b/Render.cpp	Sat Jul 27 16:09:00 2013 +0200
@@ -50,22 +50,11 @@
 int uNumSpritesDrawnThisFrame; // weak
 
 RenderVertexSoft array_507D30[50];
-RenderVertexSoft array_508690[50];
-RenderVertexSoft array_508FF0[50];
-RenderVertexSoft array_509950[50];
-RenderVertexSoft array_50A2B0[50];
 RenderVertexSoft array_50AC10[50];
-
 RenderVertexSoft array_73D150[20];
 
 RenderVertexD3D3 d3d_vertex_buffer[50];
 
-RenderVertexSoft *ptr_801A04;
-RenderVertexSoft *ptr_801A08;
-
-RenderVertexSoft pVerticesSR_801A10[384];
-RenderVertexSoft pVerticesSR_806210[384];
-
 void SetBillboardBlendOptions(RenderBillboardD3D::OpacityType a1);
 
 /*  384 */
@@ -383,588 +372,6 @@
   }
 }
 
-//----- (0048034E) --------------------------------------------------------
-void Render::DrawTerrainD3D(int a1, int a2, int a3, int unk4)
-{
-  //int v3; // esi@1
-  int v4; // edi@1
-  int v5; // ebx@2
-  int v6; // eax@2
-  int v7; // eax@3
-  RenderVertexSoft *v8; // edi@3
-  RenderVertexSoft *v9; // ebx@4
-  RenderVertexSoft *v10; // ecx@4
-  float v11; // eax@6
-  double v12; // ST5C_8@6
-  double v13; // ST2C_8@6
-  int v14; // eax@6
-  double v15; // st7@6
-  struct Polygon *pTile; // ebx@12
-  unsigned __int16 v17; // ax@12
-  int v18; // eax@13
-  signed int v22; // eax@13
-  Vec3_float_ *norm; // eax@15
-  //double v24; // st6@17
-  double v25; // ST54_8@17
-  unsigned __int8 v26; // sf@17
-  unsigned __int8 v27; // of@17
-  double v28; // st5@19
-  double v29; // st5@19
-  double v30; // st5@19
-  double v31; // st5@19
-  struct struct8 *v32; // esi@21
-  double v3a; // st7@32
-  int v33; // edi@38
-  unsigned int v34; // ecx@47
-  char v35; // zf@47
-  unsigned int v36; // eax@50
-  int v37; // eax@54
-  //Polygon *v38; // ecx@55
-  unsigned int v39; // eax@59
-  struct Polygon *v40; // ebx@62
-  unsigned __int16 pTileBitmapsID; // ax@62
-  int v42; // eax@63
-  LightmapBuilder *v43; // ecx@63
-  int v44; // eax@63
-  int v45; // eax@63
-  int v46; // eax@63
-  signed int v47; // eax@63
-  Vec3_float_ *v48; // eax@65
-  double v49; // st6@67
-  double v50; // ST4C_8@67
-  double v51; // st5@71
-  double v52; // st5@71
-  double v53; // st5@71
-  double v54; // st7@84
-  unsigned int v55; // ecx@98
-  unsigned int v56; // eax@101
-  int v57; // eax@105
-  unsigned int v58; // eax@109
-  struct Polygon *v59; // esi@112
-  unsigned __int16 v60; // ax@112
-  int v61; // eax@113
-  signed int v62; // eax@113
-  Vec3_float_ *v63; // eax@114
-  double v64; // st6@116
-  double v65; // ST3C_8@116
-  double v66; // st5@120
-  double v67; // st5@120
-  double v68; // st5@120
-  double v69; // st7@133
-  int v70; // edi@138
-  struct Polygon *v71; // esi@147
-  unsigned int v72; // ecx@147
-  unsigned int v73; // eax@150
-  int v74; // eax@154
-  unsigned int v75; // eax@158
-  //unsigned int v76; // [sp-10h] [bp-E0h]@61
-  int v77; // [sp-Ch] [bp-DCh]@61
-  IDirect3DTexture2 *v78; // [sp-8h] [bp-D8h]@61
-  //int v79; // [sp-4h] [bp-D4h]@61
-  bool v80; // [sp+0h] [bp-D0h]@59
-  bool v81; // [sp+0h] [bp-D0h]@109
-  int v82; // [sp+54h] [bp-7Ch]@1
-  int v83; // [sp+60h] [bp-70h]@1
-  int v84; // [sp+6Ch] [bp-64h]@1
-  int v85; // [sp+70h] [bp-60h]@63
-  float a4; // [sp+74h] [bp-5Ch]@73
-  float v87; // [sp+78h] [bp-58h]@122
-  int v88; // [sp+7Ch] [bp-54h]@1
-  int v89; // [sp+80h] [bp-50h]@6
-  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
-  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 *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 *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
-  float thisf; // [sp+D8h] [bp+8h]@17
-  IndoorCameraD3D *thisa; // [sp+D8h] [bp+8h]@23
-  float thisg; // [sp+D8h] [bp+8h]@67
-  IndoorCameraD3D *thisb; // [sp+D8h] [bp+8h]@75
-  float thish; // [sp+D8h] [bp+8h]@116
-  IndoorCameraD3D *thisc; // [sp+D8h] [bp+8h]@124
-  char this_3; // [sp+DBh] [bp+Bh]@30
-  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 = a2;
-  v83 = a3;
-  X = abs(unk4);
-  v4 = 0;
-  v88 = 0;
-  v84 = a1 - 1;
-/*  if ( a1 - 1 > 0 )
-  {
-    while ( 1 )
-    {
-      v5 = abs(X);//v5 = 13108
-      v6 = abs(v83);//v6 = 13108
-      --X;
-      //__debugbreak(); // uncoment & refactor following large if
-      v93 = (int)&terrain_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,
-               v11 = v8->vWorldPosition.x,
-               v101 = v10,
-               v12 = v11 + 6.755399441055744e15,
-               sX = LODWORD(v12),
-               v13 = v8->vWorldPosition.y + 6.755399441055744e15,
-               sY = LODWORD(v13),
-               thisd = (v10->vWorldPosition.x + v8->vWorldPosition.x) * 0.5,
-               v14 = WorldPosToGridCellX(floorf(thisd + 0.5f)),//maybe current camera position X
-               v15 = v9->vWorldPosition.y + v8->vWorldPosition.y,
-               v89 = v14,
-               thise = v15 * 0.5,
-               _this = (LightmapBuilder *)WorldPosToGridCellZ(floorf(thisd + 0.5f)),//maybe current camera position Z
-               WorldPosToGridCellX(sX),
-               WorldPosToGridCellZ(sY),
-               !byte_4D864C)
-           || !(pGame->uFlags & 0x80))
-          && !_481EFA_clip_terrain_poly(v8, v9, v101, pVertices, 1)) )*/
-      /*if ( !&terrain_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];
-      }
-      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)) && !_481EFA_clip_terrain_poly(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;*/
-        pTile = &array_77EC08[pOutdoorCamera->uNumPolygons];
-        pTile->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY);
-        if ( pTile->uTileBitmapID != -1 )
-        {
-          pTile->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(sX, sY);
-          pTile->field_32 = 0;
-          pTile->field_59 = 1;
-          pTile->terrain_grid_x = (char)v97;
-          __debugbreak(); // warning C4700: uninitialized local variable 'v93' used
-          pTile->field_34 = *(_WORD *)(v93 + 2);
-          pTile->terrain_grid_z = v89;
-          v22 = pTerrainNormalIndices[2 * (v97 + 128 * v89) + 1];
-          if ( v22 < 0 || v22 > uNumTerrainNormals - 1 )
-            norm = 0;
-          else
-            norm = &pTerrainNormals[v22];
-          thisf = 20.0 - ( -(((float)pOutdoor->vSunlight.x / 65536.0) * norm->x) -
-                            (((float)pOutdoor->vSunlight.y / 65536.0) * norm->y) -
-                            (((float)pOutdoor->vSunlight.z / 65536.0) * norm->z)) * 20.0;
-          //v25 = thisf + 6.7553994e15;
-          //v27 = pOutdoorCamera->uNumPolygons > 1999;
-          //v26 = pOutdoorCamera->uNumPolygons - 1999 < 0;
-          pTile->dimming_level = floorf(thisf + 0.5f);
-          if ( pOutdoorCamera->uNumPolygons >= 1999 )
-            return;
-          ++pOutdoorCamera->uNumPolygons;
-          //if ( !_481FC9_terrain(v8, pVertices, v101, v16) )//Ritor1: It's temporary
-          //goto LABEL_126;
-          //{
-            //--pOutdoorCamera->uNumPolygons;
-            //goto LABEL_162;
-          //}
-          __debugbreak(); // warning C4700: uninitialized local variable 'v102' used
-          memcpy(&array_50AC10[0], v102, 0x30u);
-          array_50AC10[0]._rhw = 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]._rhw = 1.0 / (pVertices->vWorldViewPosition.x + 0.0000001000000011686097);
-          array_50AC10[1].u = 0.0;
-          array_50AC10[1].v = 1.0;
-          __debugbreak(); // warning C4700: uninitialized local variable 'pVertices2' used
-          memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2]));
-          array_50AC10[2]._rhw = 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]._rhw = 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(norm, &v95, array_50AC10, 4, 1);
-          pDecalBuilder->_49BE8A(pTile, norm, &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 )
-          {
-            if ( this_3 )
-              v33 = 3;
-            else
-              v33 = v108 != 0 ? 5 : 0;
-            static_sub_0048034E_stru_154.ClassifyPolygon(norm, v95);
-            if ( pDecalBuilder->uNumDecals > 0 )
-              pDecalBuilder->ApplyDecals(31 - pTile->dimming_level, 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;
-          pTile->uNumVertices = a5;
-          if ( !byte_4D864C || ~pGame->uFlags & 0x80 )
-          {
-            if ( this_3 )
-            {
-              v36 = sr_424CD7(v34);
-              pTile->uNumVertices = v36;
-              OutdoorCamera::Project(v36);
-            }
-            if ( v108 )
-            {
-              v36 = sr_424EE0_MakeFanFromTriangle(v34);
-              pTile->uNumVertices = v36;
-              OutdoorCamera::Project(v36);
-            }
-          }
-          //v37 = *(int *)&v16->flags;
-          if ( ~pTile->flags & 1 )
-          {
-            if ( pTile->flags & 2 && pTile->uTileBitmapID == pRenderer->hd_water_tile_id )
-            {
-              v80 = false;
-              v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame];
-            }
-            else
-            {
-              v39 = pTile->uTileBitmapID;
-              v80 = true;
-            }
-            //v79 = 0;
-            //v78 = pBitmaps_LOD->pHardwareTextures[v39];
-            pTile->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v39];// Ritor1: It's temporary
-            v77 = (int)pTile;
-            //v76 = v16->uNumVertices;
-//LABEL_161:
-            pRenderer->DrawTerrainPolygon(pTile->uNumVertices, pTile, pBitmaps_LOD->pHardwareTextures[v39], false, v80);
-            goto LABEL_162;
-          }
-LABEL_56:
-          pTile->DrawBorderTiles();
-        }
-LABEL_162:
-        v4 = v88 + 1;
-        if ( ++v88 >= v84 )
-          return;
-      }
-    /*  v40 = &array_77EC08[pOutdoorCamera->uNumPolygons];
-      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->terrain_grid_x = (char)v43;
-      v40->field_34 = *(_WORD *)(v44 + 2);
-      v45 = v89;
-      v40->terrain_grid_z = 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->dimming_level = LOBYTE(v50);
-      if ( LOBYTE(v50) < 0 )
-        v40->dimming_level = 0;
-      if ( pOutdoorCamera->uNumPolygons >= 1999 )
-        return;
-      ++pOutdoorCamera->uNumPolygons;
-      /*if ( !_481FC9_terrain(pVertices, pVertices2, v8, v40) ) // Ritor1: It's temporary
-        //goto LABEL_77;
-        {
-          --pOutdoorCamera->uNumPolygons;
-          goto LABEL_112;
-        }*/
-      /*memcpy(&array_50AC10[0], v102, 0x30u);
-      array_50AC10[0]._rhw = 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]._rhw = 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]._rhw = 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;
-        Polygon(stru_76D590);
-        atexit(loc_48118F);
-      }*/
-      /*v96 = pGame->pLightmapBuilder;
-      pGame->pLightmapBuilder->StackLights_TerrainFace(v48, (float *)&a4, array_50AC10, 3, 0);
-      pDecalBuilder->_49BE8A(v40, v48, &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->uNumPolygons;
-          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.ClassifyPolygon(v48, *(float *)&a4);
-        if ( pDecalBuilder->uNumDecals > 0 )
-          pDecalBuilder->ApplyDecals(31 - v40->dimming_level, 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->DrawBorderTiles();
-      }
-      else
-      {
-        if ( v57 & 2 && v40->uTileBitmapID == pRenderer->hd_water_tile_id )
-        {
-          v81 = false;
-          v58 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame];
-        }
-        else
-        {
-          v58 = v40->uTileBitmapID;
-          v81 = true;
-        }
-        pRenderer->DrawTerrainPolygon(v40->uNumVertices, v40, pBitmaps_LOD->pHardwareTextures[v58], 0, v81);
-      }
-LABEL_112:
-      v59 = &array_77EC08[pOutdoorCamera->uNumPolygons];
-      //a8 = (RenderVertexSoft *)&array_77EC08[pOutdoorCamera->uNumPolygons];
-      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->terrain_grid_z = v89;
-      v59->terrain_grid_x = 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->dimming_level = floorf(thish + 0.5f);
-      if ( v59->dimming_level < 0 )
-        v59->dimming_level = 0;
-      if ( pOutdoorCamera->uNumPolygons >= 1999 )
-        return;
-      ++pOutdoorCamera->uNumPolygons;
-      if ( !_481FC9_terrain(v101, v102, pVertices2, v59) )
-      {
-//LABEL_126:
-        --pOutdoorCamera->uNumPolygons;
-        goto LABEL_162;
-      }
-      memcpy(&array_50AC10[0], v102, 0x30u);
-      array_50AC10[0]._rhw = 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]._rhw = 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]._rhw = 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, v63, &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->uNumPolygons;
-          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.ClassifyPolygon(v63, v87);
-        if ( pDecalBuilder->uNumDecals > 0 )
-          pDecalBuilder->ApplyDecals(31 - v40->dimming_level, 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 )
-        {
-LABEL_154:
-          v74 = v71->flags;
-          if ( !(BYTE1(v74) & 1) )
-          {
-            if ( v74 & 2 && v71->uTileBitmapID == pRenderer->hd_water_tile_id )
-            {
-              v80 = false;
-              v75 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame];
-            }
-            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->uNumVertices, (Polygon *)v71, v78, 0, v80);
-            goto LABEL_162;
-          }
-          v38 = (Polygon *)v71;
-          goto LABEL_56;
-        }
-        v73 = sr_424EE0_MakeFanFromTriangle(v72);
-      }
-      v71->uNumVertices = v73;
-      OutdoorCamera::Project(v73);
-      goto LABEL_154;
-    }
-  }*/
 
 
 //----- (0047BACF) --------------------------------------------------------
--- a/Render.h	Sat Jul 27 14:28:14 2013 +0200
+++ b/Render.h	Sat Jul 27 16:09:00 2013 +0200
@@ -510,18 +510,7 @@
 
 
 extern RenderVertexSoft array_507D30[50];
-extern RenderVertexSoft array_508690[50];
-extern RenderVertexSoft array_508FF0[50];
-extern RenderVertexSoft array_509950[50];
-extern RenderVertexSoft array_50A2B0[50];
 extern RenderVertexSoft array_50AC10[50];
-
 extern RenderVertexSoft array_73D150[20];
 
-extern RenderVertexD3D3 d3d_vertex_buffer[50];
-
-extern RenderVertexSoft *ptr_801A04;
-extern RenderVertexSoft *ptr_801A08;
-
-extern RenderVertexSoft pVerticesSR_801A10[384];
-extern RenderVertexSoft pVerticesSR_806210[384];
\ No newline at end of file
+extern RenderVertexD3D3 d3d_vertex_buffer[50];
\ No newline at end of file
--- a/_deleted.cpp	Sat Jul 27 14:28:14 2013 +0200
+++ b/_deleted.cpp	Sat Jul 27 16:09:00 2013 +0200
@@ -726,7 +726,7 @@
     v27 = -10000.0;
     if ( (signed int)v1 > 0 )
     {
-      v4 = (char *)&array_508690[0].vWorldViewProjY;
+      v4 = (char *)&sr_508690[0].vWorldViewProjY;
       do
       {
         if ( *((float *)v4 - 1) < (double)v26 )
@@ -769,20 +769,20 @@
         *(&v19 + v10) = i;
       }
     }
-    v11 = &array_508690[v19];
-    v12 = &array_508690[v20];
-    v13 = &array_508690[v21];
+    v11 = &sr_508690[v19];
+    v12 = &sr_508690[v20];
+    v13 = &sr_508690[v21];
     if ( LODWORD(v29) != 3 )
     {
-      v11 = array_508690;
-      v13 = (RenderVertexSoft *)((char *)array_508690 + 16 * (3 * v1 - 3));
-      v12 = &array_508690[1];
-      v28 = array_508690[1].vWorldPosition.x - array_508690[0].vWorldPosition.x;
-      v27 = array_508690[1].vWorldPosition.y - array_508690[0].vWorldPosition.y;
-      v29 = array_508690[1].vWorldPosition.z - array_508690[0].vWorldPosition.z;
-      v26 = v13->vWorldPosition.x - array_508690[0].vWorldPosition.x;
-      v25 = v13->vWorldPosition.y - array_508690[0].vWorldPosition.y;
-      v24 = v13->vWorldPosition.z - array_508690[0].vWorldPosition.z;
+      v11 = sr_508690;
+      v13 = (RenderVertexSoft *)((char *)sr_508690 + 16 * (3 * v1 - 3));
+      v12 = &sr_508690[1];
+      v28 = sr_508690[1].vWorldPosition.x - sr_508690[0].vWorldPosition.x;
+      v27 = sr_508690[1].vWorldPosition.y - sr_508690[0].vWorldPosition.y;
+      v29 = sr_508690[1].vWorldPosition.z - sr_508690[0].vWorldPosition.z;
+      v26 = v13->vWorldPosition.x - sr_508690[0].vWorldPosition.x;
+      v25 = v13->vWorldPosition.y - sr_508690[0].vWorldPosition.y;
+      v24 = v13->vWorldPosition.z - sr_508690[0].vWorldPosition.z;
       if ( v24 * v27 - v25 * v29 == 0.0 )
       {
         if ( v26 * v29 - v24 * v28 == 0.0 )
@@ -793,12 +793,12 @@
             LODWORD(v26) = v14;
             if ( v14 >= 2 )
             {
-              v15 = &array_508690[v14];
+              v15 = &sr_508690[v14];
               do
               {
-                v16 = v15->vWorldPosition.x - array_508690[0].vWorldPosition.x;
-                v17 = v15->vWorldPosition.y - array_508690[0].vWorldPosition.y;
-                v18 = v15->vWorldPosition.z - array_508690[0].vWorldPosition.z;
+                v16 = v15->vWorldPosition.x - sr_508690[0].vWorldPosition.x;
+                v17 = v15->vWorldPosition.y - sr_508690[0].vWorldPosition.y;
+                v18 = v15->vWorldPosition.z - sr_508690[0].vWorldPosition.z;
                 v13 = v15;
                 if ( v27 * v18 - v17 * v29 != 0.0 )
                   break;
@@ -880,7 +880,7 @@
     v5 = 0;
     if ( (signed int)a3->uNumVertices > 0 )
     {
-      v6 = (char *)&array_508690[0].vWorldViewProjY;
+      v6 = (char *)&sr_508690[0].vWorldViewProjY;
       do
       {
         v7 = *((float *)v6 - 1) + 6.7553994e15;
@@ -1587,7 +1587,7 @@
           v39 = 0;
           if ( (signed int)v12->uNumVertices > 0 )
           {
-            v40 = (char *)&array_508690[0].vWorldViewProjY;
+            v40 = (char *)&sr_508690[0].vWorldViewProjY;
             do
             {
               LODWORD(v64) = *((int *)v40 - 1);
@@ -1615,7 +1615,7 @@
             v46 = 0;
             if ( (signed int)v12->uNumVertices > 0 )
             {
-              v47 = (char *)&array_508690[0].vWorldViewProjY;
+              v47 = (char *)&sr_508690[0].vWorldViewProjY;
               do
               {
                 LODWORD(v61) = *((int *)v47 - 1);
@@ -1646,7 +1646,7 @@
             v51 = 0;
             if ( (signed int)v12->uNumVertices > 0 )
             {
-              v52 = (char *)&array_508690[0].vWorldViewProjY;
+              v52 = (char *)&sr_508690[0].vWorldViewProjY;
               do
               {
                 LODWORD(v62) = *((int *)v52 - 1);
@@ -1663,7 +1663,7 @@
             }
           }
         }
-        sr_sub_486B4E_push_outdoor_edges(array_508690, dword_50B638.data(), dword_50B570.data(), v12);
+        sr_sub_486B4E_push_outdoor_edges(sr_508690, dword_50B638.data(), dword_50B570.data(), v12);
       }
 LABEL_72:
       ++v79;
@@ -4198,7 +4198,7 @@
         {
           sr_sub_4829B9((RenderVertexSoft *)HIDWORD(v101), v52, v104, v38, 0);
 LABEL_68:
-          sr_sub_481DB2(array_508690, v54, v38);
+          sr_sub_481DB2(sr_508690, v54, v38);
 LABEL_75:
           v17 = &array_77EC08[pOutdoorCamera->uNumPolygons];
           v57 = pOutdoor->GetTileTexture(v101, v100);
@@ -4301,7 +4301,7 @@
 LABEL_37:
           sr_sub_4829B9(v35, v34, v67, v68, v69);
 LABEL_38:
-          sr_sub_481DB2(array_508690, v33, v17);
+          sr_sub_481DB2(sr_508690, v33, v17);
           goto LABEL_105;
         }
         goto LABEL_74;
@@ -8051,7 +8051,7 @@
     return v117;
   v127 = a1;
   v1 = a1;
-  memcpy(array_508690, array_50AC10, 4 * ((unsigned int)(48 * a1) >> 2));
+  memcpy(sr_508690, array_50AC10, 4 * ((unsigned int)(48 * a1) >> 2));
   v2 = 0;
   do
   {
@@ -8350,12 +8350,12 @@
         v62 = SLODWORD(v61) <= (signed int)pViewport->uViewportBR_Y,
         v123 < 1) )
     goto LABEL_112;
-  v63 = (char *)&array_508690[0].vWorldViewProjX;
-  v131 = array_508690;
-  v120 = (char *)&array_508690[0].vWorldViewProjX;
-  v140 = (char *)&array_508690[0].vWorldViewProjY;
-  v126 = (char *)&array_508690[0].flt_2C;
-  v135 = (char *)&array_508690[0]._rhw;
+  v63 = (char *)&sr_508690[0].vWorldViewProjX;
+  v131 = sr_508690;
+  v120 = (char *)&sr_508690[0].vWorldViewProjX;
+  v140 = (char *)&sr_508690[0].vWorldViewProjY;
+  v126 = (char *)&sr_508690[0].flt_2C;
+  v135 = (char *)&sr_508690[0]._rhw;
   v64 = (char *)&array_508FF0[0].flt_2C;
   v113 = v123;
   while ( 2 )
@@ -8437,10 +8437,10 @@
   if ( v116 < 3 )
     goto LABEL_112;
   v80 = v116;
-  memcpy(&array_508690[v116], array_508690, sizeof(array_508690[v116]));
+  memcpy(&sr_508690[v116], sr_508690, sizeof(sr_508690[v116]));
   if ( v116 > 0 )
   {
-    v81 = (char *)&array_508690[0].vWorldViewProjX;
+    v81 = (char *)&sr_508690[0].vWorldViewProjX;
     v82 = v116;
     do
     {
@@ -8484,7 +8484,7 @@
   v90 = v116 - 3 < 0;
   if ( v116 > 3 )
   {
-    memcpy(&array_508690[v116 + 1], &array_508690[1], sizeof(array_508690[v116 + 1]));
+    memcpy(&sr_508690[v116 + 1], &sr_508690[1], sizeof(sr_508690[v116 + 1]));
     if ( v116 > 0 )
     {
       v105 = 1;
@@ -8500,10 +8500,10 @@
           v92 = v105 - v80;
         if ( v94 >= v80 )
           v95 = v94 - v80;
-        if ( (array_508690[v92].vWorldViewProjX - array_508690[v93].vWorldViewProjX)
-           * (array_508690[v95].vWorldViewProjY - array_508690[v93].vWorldViewProjY)
-           - (array_508690[v95].vWorldViewProjX - array_508690[v93].vWorldViewProjX)
-           * (array_508690[v92].vWorldViewProjY - array_508690[v93].vWorldViewProjY) < 0.0 )
+        if ( (sr_508690[v92].vWorldViewProjX - sr_508690[v93].vWorldViewProjX)
+           * (sr_508690[v95].vWorldViewProjY - sr_508690[v93].vWorldViewProjY)
+           - (sr_508690[v95].vWorldViewProjX - sr_508690[v93].vWorldViewProjX)
+           * (sr_508690[v92].vWorldViewProjY - sr_508690[v93].vWorldViewProjY) < 0.0 )
         {
           ++v105;
         }
@@ -8511,7 +8511,7 @@
         {
           v96 = v105;
           if ( v105 < v80 || (v96 = v105 - v80, v105 - v80 < v80) )
-            memcpy(&array_508690[v96], &array_508690[v96 + 1], 4 * ((unsigned int)(48 * v80 - 48 * v96) >> 2));
+            memcpy(&sr_508690[v96], &sr_508690[v96 + 1], 4 * ((unsigned int)(48 * v80 - 48 * v96) >> 2));
           --v80;
         }
       }
@@ -8528,7 +8528,589 @@
   return result;
 }
 
-
+//----- (0048034E) --------------------------------------------------------
+void Render::DrawTerrainD3D(int a1, int a2, int a3, int unk4)
+{
+  //int v3; // esi@1
+  int v4; // edi@1
+  int v5; // ebx@2
+  int v6; // eax@2
+  int v7; // eax@3
+  RenderVertexSoft *v8; // edi@3
+  RenderVertexSoft *v9; // ebx@4
+  RenderVertexSoft *v10; // ecx@4
+  float v11; // eax@6
+  double v12; // ST5C_8@6
+  double v13; // ST2C_8@6
+  int v14; // eax@6
+  double v15; // st7@6
+  struct Polygon *pTile; // ebx@12
+  unsigned __int16 v17; // ax@12
+  int v18; // eax@13
+  signed int v22; // eax@13
+  Vec3_float_ *norm; // eax@15
+  //double v24; // st6@17
+  double v25; // ST54_8@17
+  unsigned __int8 v26; // sf@17
+  unsigned __int8 v27; // of@17
+  double v28; // st5@19
+  double v29; // st5@19
+  double v30; // st5@19
+  double v31; // st5@19
+  struct struct8 *v32; // esi@21
+  double v3a; // st7@32
+  int v33; // edi@38
+  unsigned int v34; // ecx@47
+  char v35; // zf@47
+  unsigned int v36; // eax@50
+  int v37; // eax@54
+  //Polygon *v38; // ecx@55
+  unsigned int v39; // eax@59
+  struct Polygon *v40; // ebx@62
+  unsigned __int16 pTileBitmapsID; // ax@62
+  int v42; // eax@63
+  LightmapBuilder *v43; // ecx@63
+  int v44; // eax@63
+  int v45; // eax@63
+  int v46; // eax@63
+  signed int v47; // eax@63
+  Vec3_float_ *v48; // eax@65
+  double v49; // st6@67
+  double v50; // ST4C_8@67
+  double v51; // st5@71
+  double v52; // st5@71
+  double v53; // st5@71
+  double v54; // st7@84
+  unsigned int v55; // ecx@98
+  unsigned int v56; // eax@101
+  int v57; // eax@105
+  unsigned int v58; // eax@109
+  struct Polygon *v59; // esi@112
+  unsigned __int16 v60; // ax@112
+  int v61; // eax@113
+  signed int v62; // eax@113
+  Vec3_float_ *v63; // eax@114
+  double v64; // st6@116
+  double v65; // ST3C_8@116
+  double v66; // st5@120
+  double v67; // st5@120
+  double v68; // st5@120
+  double v69; // st7@133
+  int v70; // edi@138
+  struct Polygon *v71; // esi@147
+  unsigned int v72; // ecx@147
+  unsigned int v73; // eax@150
+  int v74; // eax@154
+  unsigned int v75; // eax@158
+  //unsigned int v76; // [sp-10h] [bp-E0h]@61
+  int v77; // [sp-Ch] [bp-DCh]@61
+  IDirect3DTexture2 *v78; // [sp-8h] [bp-D8h]@61
+  //int v79; // [sp-4h] [bp-D4h]@61
+  bool v80; // [sp+0h] [bp-D0h]@59
+  bool v81; // [sp+0h] [bp-D0h]@109
+  int v82; // [sp+54h] [bp-7Ch]@1
+  int v83; // [sp+60h] [bp-70h]@1
+  int v84; // [sp+6Ch] [bp-64h]@1
+  int v85; // [sp+70h] [bp-60h]@63
+  float a4; // [sp+74h] [bp-5Ch]@73
+  float v87; // [sp+78h] [bp-58h]@122
+  int v88; // [sp+7Ch] [bp-54h]@1
+  int v89; // [sp+80h] [bp-50h]@6
+  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
+  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 *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 *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
+  float thisf; // [sp+D8h] [bp+8h]@17
+  IndoorCameraD3D *thisa; // [sp+D8h] [bp+8h]@23
+  float thisg; // [sp+D8h] [bp+8h]@67
+  IndoorCameraD3D *thisb; // [sp+D8h] [bp+8h]@75
+  float thish; // [sp+D8h] [bp+8h]@116
+  IndoorCameraD3D *thisc; // [sp+D8h] [bp+8h]@124
+  char this_3; // [sp+DBh] [bp+Bh]@30
+  char this_3a; // [sp+DBh] [bp+Bh]@82
+  char this_3b; // [sp+DBh] [bp+Bh]@131
+
+  __debugbreak();
+  static stru154 static_sub_0048034E_stru_154;
+  static stru154 stru_76D5A8;
+  //v3 = a1;
+  v82 = a2;
+  v83 = a3;
+  X = abs(unk4);
+  v4 = 0;
+  v88 = 0;
+  v84 = a1 - 1;
+  if ( a1 - 1 > 0 )
+  {
+    while ( 1 )
+    {
+      v5 = abs(X);//v5 = 13108
+      v6 = abs(v83);//v6 = 13108
+      --X;
+      //__debugbreak(); // uncoment & refactor following large if
+      v93 = (int)&terrain_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,
+               v11 = v8->vWorldPosition.x,
+               v101 = v10,
+               v12 = v11 + 6.755399441055744e15,
+               sX = LODWORD(v12),
+               v13 = v8->vWorldPosition.y + 6.755399441055744e15,
+               sY = LODWORD(v13),
+               thisd = (v10->vWorldPosition.x + v8->vWorldPosition.x) * 0.5,
+               v14 = WorldPosToGridCellX(floorf(thisd + 0.5f)),//maybe current camera position X
+               v15 = v9->vWorldPosition.y + v8->vWorldPosition.y,
+               v89 = v14,
+               thise = v15 * 0.5,
+               _this = (LightmapBuilder *)WorldPosToGridCellZ(floorf(thisd + 0.5f)),//maybe current camera position Z
+               WorldPosToGridCellX(sX),
+               WorldPosToGridCellZ(sY),
+               !byte_4D864C)
+           || !(pGame->uFlags & 0x80))
+          && !_481EFA_clip_terrain_poly(v8, v9, v101, pVertices, 1)) )
+      if ( !&terrain_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];
+      }
+      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)) && !_481EFA_clip_terrain_poly(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;
+        pTile = &array_77EC08[pOutdoorCamera->uNumPolygons];
+        pTile->uTileBitmapID = pOutdoor->GetTileTexture(sX, sY);
+        if ( pTile->uTileBitmapID != -1 )
+        {
+          pTile->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(sX, sY);
+          pTile->field_32 = 0;
+          pTile->field_59 = 1;
+          pTile->terrain_grid_x = (char)v97;
+          __debugbreak(); // warning C4700: uninitialized local variable 'v93' used
+          pTile->field_34 = *(_WORD *)(v93 + 2);
+          pTile->terrain_grid_z = v89;
+          v22 = pTerrainNormalIndices[2 * (v97 + 128 * v89) + 1];
+          if ( v22 < 0 || v22 > uNumTerrainNormals - 1 )
+            norm = 0;
+          else
+            norm = &pTerrainNormals[v22];
+          thisf = 20.0 - ( -(((float)pOutdoor->vSunlight.x / 65536.0) * norm->x) -
+                            (((float)pOutdoor->vSunlight.y / 65536.0) * norm->y) -
+                            (((float)pOutdoor->vSunlight.z / 65536.0) * norm->z)) * 20.0;
+          //v25 = thisf + 6.7553994e15;
+          //v27 = pOutdoorCamera->uNumPolygons > 1999;
+          //v26 = pOutdoorCamera->uNumPolygons - 1999 < 0;
+          pTile->dimming_level = floorf(thisf + 0.5f);
+          if ( pOutdoorCamera->uNumPolygons >= 1999 )
+            return;
+          ++pOutdoorCamera->uNumPolygons;
+          //if ( !_481FC9_terrain(v8, pVertices, v101, v16) )//Ritor1: It's temporary
+          //goto LABEL_126;
+          //{
+            //--pOutdoorCamera->uNumPolygons;
+            //goto LABEL_162;
+          //}
+          __debugbreak(); // warning C4700: uninitialized local variable 'v102' used
+          memcpy(&array_50AC10[0], v102, 0x30u);
+          array_50AC10[0]._rhw = 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]._rhw = 1.0 / (pVertices->vWorldViewPosition.x + 0.0000001000000011686097);
+          array_50AC10[1].u = 0.0;
+          array_50AC10[1].v = 1.0;
+          __debugbreak(); // warning C4700: uninitialized local variable 'pVertices2' used
+          memcpy(&array_50AC10[2], pVertices2, sizeof(array_50AC10[2]));
+          array_50AC10[2]._rhw = 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]._rhw = 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(norm, &v95, array_50AC10, 4, 1);
+          pDecalBuilder->_49BE8A(pTile, norm, &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 )
+          {
+            if ( this_3 )
+              v33 = 3;
+            else
+              v33 = v108 != 0 ? 5 : 0;
+            static_sub_0048034E_stru_154.ClassifyPolygon(norm, v95);
+            if ( pDecalBuilder->uNumDecals > 0 )
+              pDecalBuilder->ApplyDecals(31 - pTile->dimming_level, 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;
+          pTile->uNumVertices = a5;
+          if ( !byte_4D864C || ~pGame->uFlags & 0x80 )
+          {
+            if ( this_3 )
+            {
+              v36 = sr_424CD7(v34);
+              pTile->uNumVertices = v36;
+              OutdoorCamera::Project(v36);
+            }
+            if ( v108 )
+            {
+              v36 = sr_424EE0_MakeFanFromTriangle(v34);
+              pTile->uNumVertices = v36;
+              OutdoorCamera::Project(v36);
+            }
+          }
+          //v37 = *(int *)&v16->flags;
+          if ( ~pTile->flags & 1 )
+          {
+            if ( pTile->flags & 2 && pTile->uTileBitmapID == pRenderer->hd_water_tile_id )
+            {
+              v80 = false;
+              v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame];
+            }
+            else
+            {
+              v39 = pTile->uTileBitmapID;
+              v80 = true;
+            }
+            //v79 = 0;
+            //v78 = pBitmaps_LOD->pHardwareTextures[v39];
+            pTile->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v39];// Ritor1: It's temporary
+            v77 = (int)pTile;
+            //v76 = v16->uNumVertices;
+//LABEL_161:
+            pRenderer->DrawTerrainPolygon(pTile->uNumVertices, pTile, pBitmaps_LOD->pHardwareTextures[v39], false, v80);
+            goto LABEL_162;
+          }
+LABEL_56:
+          pTile->DrawBorderTiles();
+        }
+LABEL_162:
+        v4 = v88 + 1;
+        if ( ++v88 >= v84 )
+          return;
+      }
+      v40 = &array_77EC08[pOutdoorCamera->uNumPolygons];
+      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->terrain_grid_x = (char)v43;
+      v40->field_34 = *(_WORD *)(v44 + 2);
+      v45 = v89;
+      v40->terrain_grid_z = 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->dimming_level = LOBYTE(v50);
+      if ( LOBYTE(v50) < 0 )
+        v40->dimming_level = 0;
+      if ( pOutdoorCamera->uNumPolygons >= 1999 )
+        return;
+      ++pOutdoorCamera->uNumPolygons;
+      if ( !_481FC9_terrain(pVertices, pVertices2, v8, v40) ) // Ritor1: It's temporary
+        //goto LABEL_77;
+        {
+          --pOutdoorCamera->uNumPolygons;
+          goto LABEL_112;
+        }
+      memcpy(&array_50AC10[0], v102, 0x30u);
+      array_50AC10[0]._rhw = 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]._rhw = 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]._rhw = 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;
+        Polygon(stru_76D590);
+        atexit(loc_48118F);
+      }
+      v96 = pGame->pLightmapBuilder;
+      pGame->pLightmapBuilder->StackLights_TerrainFace(v48, (float *)&a4, array_50AC10, 3, 0);
+      pDecalBuilder->_49BE8A(v40, v48, &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->uNumPolygons;
+          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.ClassifyPolygon(v48, *(float *)&a4);
+        if ( pDecalBuilder->uNumDecals > 0 )
+          pDecalBuilder->ApplyDecals(31 - v40->dimming_level, 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->DrawBorderTiles();
+      }
+      else
+      {
+        if ( v57 & 2 && v40->uTileBitmapID == pRenderer->hd_water_tile_id )
+        {
+          v81 = false;
+          v58 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame];
+        }
+        else
+        {
+          v58 = v40->uTileBitmapID;
+          v81 = true;
+        }
+        pRenderer->DrawTerrainPolygon(v40->uNumVertices, v40, pBitmaps_LOD->pHardwareTextures[v58], 0, v81);
+      }
+LABEL_112:
+      v59 = &array_77EC08[pOutdoorCamera->uNumPolygons];
+      //a8 = (RenderVertexSoft *)&array_77EC08[pOutdoorCamera->uNumPolygons];
+      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->terrain_grid_z = v89;
+      v59->terrain_grid_x = 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->dimming_level = floorf(thish + 0.5f);
+      if ( v59->dimming_level < 0 )
+        v59->dimming_level = 0;
+      if ( pOutdoorCamera->uNumPolygons >= 1999 )
+        return;
+      ++pOutdoorCamera->uNumPolygons;
+      if ( !_481FC9_terrain(v101, v102, pVertices2, v59) )
+      {
+//LABEL_126:
+        --pOutdoorCamera->uNumPolygons;
+        goto LABEL_162;
+      }
+      memcpy(&array_50AC10[0], v102, 0x30u);
+      array_50AC10[0]._rhw = 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]._rhw = 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]._rhw = 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, v63, &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->uNumPolygons;
+          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.ClassifyPolygon(v63, v87);
+        if ( pDecalBuilder->uNumDecals > 0 )
+          pDecalBuilder->ApplyDecals(31 - v40->dimming_level, 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 )
+        {
+LABEL_154:
+          v74 = v71->flags;
+          if ( !(BYTE1(v74) & 1) )
+          {
+            if ( v74 & 2 && v71->uTileBitmapID == pRenderer->hd_water_tile_id )
+            {
+              v80 = false;
+              v75 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame];
+            }
+            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->uNumVertices, (Polygon *)v71, v78, 0, v80);
+            goto LABEL_162;
+          }
+          v38 = (Polygon *)v71;
+          goto LABEL_56;
+        }
+        v73 = sr_424EE0_MakeFanFromTriangle(v72);
+      }
+      v71->uNumVertices = v73;
+      OutdoorCamera::Project(v73);
+      goto LABEL_154;
+    }
+  }
 //----- (00424579) --------------------------------------------------------
 int __fastcall sr_424579(int uFaceID, stru320 *a2)
 {
--- a/mm7_1.cpp	Sat Jul 27 14:28:14 2013 +0200
+++ b/mm7_1.cpp	Sat Jul 27 16:09:00 2013 +0200
@@ -434,70 +434,6 @@
 
 
 
-
-
-//----- (00423AEE) --------------------------------------------------------
-void __cdecl reset_some_strus_flt_2Cs()
-{
-  float *v0; // eax@1
-  signed int v1; // ecx@1
-  signed int v2; // edx@1
-  float *v3; // eax@3
-  signed int v4; // edx@3
-  float *v5; // eax@5
-  signed int v6; // edx@5
-  float *v7; // eax@7
-  signed int v8; // edx@7
-  float *v9; // eax@9
-
-  v0 = &array_50AC10[0].flt_2C;
-  v1 = 50;
-  v2 = 50;
-  do
-  {
-    *v0 = 0.0;
-    v0 += 12;
-    --v2;
-  }
-  while ( v2 );
-  v3 = &array_50A2B0[0].flt_2C;
-  v4 = 50;
-  do
-  {
-    *v3 = 0.0;
-    v3 += 12;
-    --v4;
-  }
-  while ( v4 );
-  v5 = &array_509950[0].flt_2C;
-  v6 = 50;
-  do
-  {
-    *v5 = 0.0;
-    v5 += 12;
-    --v6;
-  }
-  while ( v6 );
-  v7 = &array_508FF0[0].flt_2C;
-  v8 = 50;
-  do
-  {
-    *v7 = 0.0;
-    v7 += 12;
-    --v8;
-  }
-  while ( v8 );
-  v9 = &array_508690[0].flt_2C;
-  do
-  {
-    *v9 = 0.0;
-    v9 += 12;
-    --v1;
-  }
-  while ( v1 );
-}
-
-
 //----- (00424CD7) --------------------------------------------------------
 signed int __fastcall sr_424CD7(unsigned int uVertexID)
 {
@@ -527,6 +463,7 @@
   char *v24; // [sp+28h] [bp-8h]@4
   char *v25; // [sp+2Ch] [bp-4h]@4
 
+  __debugbreak();
   v1 = uVertexID;
   memcpy(&array_50AC10[uVertexID], array_50AC10, sizeof(array_50AC10[uVertexID]));
   v2 = 0;
--- a/mm7_2.cpp	Sat Jul 27 14:28:14 2013 +0200
+++ b/mm7_2.cpp	Sat Jul 27 16:09:00 2013 +0200
@@ -69,59 +69,167 @@
 #include "Lights.h"
 
 //----- (004BB756) --------------------------------------------------------
-signed int __fastcall sub_4BB756(signed int a1)
+int UseNPCSkill(NPCProf profession)
 {
-  unsigned int v1; // esi@8
-  unsigned int v3; // ecx@10
-  Player *v4; // esi@15
-  int v5; // ebx@16
-  int v6; // ST38_4@16
-  Player *v7; // esi@18
-  int v8; // ebx@19
-  int v9; // ST30_4@19
-  int v10; // ST44_4@19
-  int v11; // ST48_4@19
-  int v12; // ST4C_4@19
-  int v13; // ST50_4@19
-  int v14; // ST3C_4@19
-  int v15; // ST40_4@19
-  int v16; // ST34_4@19
-  int v17; // ST38_4@19
-  Player *v18; // esi@21
-  int v19; // eax@26
-  int v20; // eax@39
-  SoundID v21; // [sp-20h] [bp-54h]@25
-  signed int v22; // [sp-1Ch] [bp-50h]@25
-  unsigned int v23; // [sp-18h] [bp-4Ch]@25
-  signed int v24; // [sp-14h] [bp-48h]@25
-  signed int v25; // [sp-10h] [bp-44h]@25
-  int v26; // [sp-10h] [bp-44h]@32
-  int v27; // [sp-Ch] [bp-40h]@25
-  unsigned int v28; // [sp-Ch] [bp-40h]@32
-  unsigned int v29; // [sp-8h] [bp-3Ch]@25
-  __int16 v30; // [sp-8h] [bp-3Ch]@32
-  int v31; // [sp-4h] [bp-38h]@25
-  int v32; // [sp-4h] [bp-38h]@32
-
-  if ( a1 > 39 )
-  {
-    if ( a1 != 40 )
+  switch (profession)
+  {
+    case Healer:
+    {
+      for (int i = 0; i < 4; ++i)
+        pParty->pPlayers[i].sHealth = pParty->pPlayers[i].GetMaxHealth();
+    }
+    break;
+
+    case ExpertHealer:
+    {
+      for (int i = 0; i < 4; ++i)
+      {
+        auto player = &pParty->pPlayers[i];
+        player->sHealth = player->GetMaxHealth();
+
+        for (int j = 0; j < 14; ++j)
+          player->pConditions[i] = 0;
+        player->pConditions[18] = 0;
+      }
+    }
+    break;
+
+    case MasterHealer:
+    {
+      for (int i = 0; i < 4; ++i)
+      {
+        auto player = &pParty->pPlayers[i];
+        player->sHealth = player->GetMaxHealth();
+
+        auto v5 = LODWORD(player->pConditions[19]);//*((int *)v4 - 32);
+        auto v6 = HIDWORD(player->pConditions[19]);//*((int *)v4 - 31);
+        memset(player->pConditions, 0, 0xA0u);
+
+        __debugbreak();
+        *(int *)&player->pActiveSkills[8] = v5;
+        *(int *)&player->pActiveSkills[10] = v6;
+      }
+    }
+    break;
+
+    case Cook:
+    {
+      if (pParty->uNumFoodRations >= 13)
+        return 1;
+
+      Party::GiveFood(1);
+    }
+    break;
+
+    case Chef:
+    {
+      if (pParty->uNumFoodRations >= 13)
+        return 1;
+
+      if (pParty->uNumFoodRations == 13)
+        Party::GiveFood(1);
+      else
+        Party::GiveFood(2);
+    }
+    break;
+
+    case WindMaster:
     {
-      if ( a1 == 41 )
+      if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+      {
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[494], 2);
+        pAudioPlayer->PlaySound(SOUND_203, 0, 0, -1, 0, 0, 0, 0);
+      }
+      else
+      {
+        auto v19 = pOtherOverlayList->_4418B1(10008, 203, 0, 65536);
+        pParty->pPartyBuffs[PARTY_BUFF_FLY].Apply(pParty->uTimePlayed + 60 * (256 * 2), 3, 1, v19, 0);
+        pParty->pPartyBuffs[PARTY_BUFF_FLY].uFlags |= 1u;
+        pAudioPlayer->PlaySound(SOUND_11090, 0, 0, -1, 0, 0, 0, 0);
+      }
+    }
+    break;
+
+    case WaterMaster:
+    {
+      auto v20 = pOtherOverlayList->_4418B1(10005, 201, 0, 65536);
+      pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].Apply(pParty->uTimePlayed + 60 * (256 * (2 + 1)), 3, 0, v20, 0);
+      pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uFlags |= 1u;
+      pAudioPlayer->PlaySound(SOUND_12040, 0, 0, -1, 0, 0, 0, 0);
+    }
+    break;
+
+    case GateMaster:
+    {
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
+      dword_50C9DC = 195;
+      ptr_50C9E0 = GetNPCData(sDialogue_SpeakingActorNPC_ID);
+    }
+    break;
+
+    case Acolyte:      _42777D_CastSpell_UseWand_ShootArrow(46, 0, 133, 0, 0); break;
+    case Piper:        _42777D_CastSpell_UseWand_ShootArrow(51, 0, 133, 0, 0); break;
+    case FallenWizard: _42777D_CastSpell_UseWand_ShootArrow(86, 0, 133, 0, 0); break;
+      
+    case Teacher:
+    case Instructor:
+    case Armsmaster:
+    case Weaponsmaster:
+    case Apprentice:
+    case Mystic:
+    case Spellmaster:
+    case Trader:
+    case Merchant:
+    case Scout:
+    case Herbalist:
+    case Apothecary:
+    case Tinker:
+    case Locksmith:
+    case Fool:
+    case ChimneySweep:
+    case Porter:
+    case QuarterMaster:
+    case Factor:
+    case Banker:
+    case Horseman:
+    case Bard:
+    case Enchanter:
+    case Cartographer:
+    case Explorer:
+    case Pirate:
+    case Squire:
+    case Psychic:
+    case Gypsy:
+    case Diplomat:
+    case Duper:
+    case Burglar:
+    case Acolyte2:
+    case Initiate:
+    case Prelate:
+    case Monk:
+    case Sage:
+    case Hunter:
+      break;
+
+    default:
+      assert(false && "Invalid enum value");
+  }
+  return 0;
+
+
+  /*
+  if ( profession > 39 )
+  {
+    if ( profession != 40 )
+    {
+      if ( profession == 41 )
       {
         pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
-        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
-        {
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
-          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          ++pMessageQueue_50CBD0->uNumMessages;
-        }*/
         dword_50C9DC = 195;
         ptr_50C9E0 = GetNPCData(sDialogue_SpeakingActorNPC_ID);
         return 0;
       }
-      if ( a1 == 42 )
+      if ( profession == 42 )
       {
         v32 = 0;
         v30 = 0;
@@ -130,7 +238,7 @@
       }
       else
       {
-        if ( a1 == 43 )
+        if ( profession == 43 )
         {
           v32 = 0;
           v30 = 0;
@@ -139,7 +247,7 @@
         }
         else
         {
-          if ( a1 != 52 )
+          if ( profession != 52 )
             return 0;
           v32 = 0;
           v30 = 0;
@@ -165,7 +273,7 @@
     pAudioPlayer->PlaySound(v21, v22, v23, v24, v25, v27, v29, v31);
     return 0;
   }
-  if ( a1 == 39 )
+  if ( profession == 39 )
   {
     if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
     {
@@ -196,7 +304,7 @@
     pAudioPlayer->PlaySound(v21, v22, v23, v24, v25, v27, v29, v31);
     return 0;
   }
-  if ( a1 == 10 )
+  if ( profession == 10 )
   {
     v18 = pParty->pPlayers;
     do
@@ -207,21 +315,11 @@
     while ( (signed int)v18 < (signed int)pParty->pHirelings );
     return 0;
   }
-  if ( a1 == 11 )
+  if ( profession == 11 )
   {
     v7 = pParty->pPlayers;//(char *)&pParty->pPlayers[0].pConditions[15];
     do
     {
-      /*v8 = *((int *)v7 - 2);
-      v9 = *((int *)v7 - 1);
-      v10 = *(int *)v7;
-      v11 = *((int *)v7 + 1);
-      v12 = *((int *)v7 + 2);
-      v13 = *((int *)v7 + 3);
-      v14 = *((int *)v7 + 8);
-      v15 = *((int *)v7 + 9);
-      v16 = *((int *)v7 + 4);
-      v17 = *((int *)v7 + 5);*/
 	  v8 = LODWORD(v7->pConditions[14]);
 	  v9 = HIDWORD(v7->pConditions[14]);
 	  v10 = LODWORD(v7->pConditions[15]);
@@ -249,7 +347,7 @@
     while ( v7 <= pPlayers[3] );
     return 0;
   }
-  if ( a1 == 12 )
+  if ( profession == 12 )
   {
 	  v4 = pParty->pPlayers;//(char *)&pParty->pPlayers[0].pActiveSkills[8];
     do
@@ -265,7 +363,7 @@
     while ( v4 <= pPlayers[3] );
     return 0;
   }
-  if ( a1 == 33 )
+  if ( profession == 33 )
   {
     v1 = 14;
     if ( pParty->uNumFoodRations >= 0xE )
@@ -277,7 +375,7 @@
       pParty->uNumFoodRations = v1;
     return 0;
   }
-  if ( a1 == 34 )
+  if ( profession == 34 )
   {
     v1 = 14;
     if ( pParty->uNumFoodRations >= 0xE )
@@ -285,9 +383,8 @@
     v3 = 2;
     goto LABEL_13;
   }
-  return 0;
+  return 0;*/
 }
-// 50C9DC: using guessed type int dword_50C9DC;
 
 //----- (004BBA85) --------------------------------------------------------
 const char *sub_4BBA85_bounties()
--- a/mm7_3.cpp	Sat Jul 27 14:28:14 2013 +0200
+++ b/mm7_3.cpp	Sat Jul 27 16:09:00 2013 +0200
@@ -2207,8 +2207,8 @@
   int bFeatherFall; // [sp+28h] [bp-6Ch]@4
   int v105; // [sp+2Ch] [bp-68h]@24
   int bWaterWalk; // [sp+30h] [bp-64h]@1
-  bool v107; // [sp+34h] [bp-60h]@30
-  int v108; // [sp+38h] [bp-5Ch]@1
+  //bool v107; // [sp+34h] [bp-60h]@30
+  //int v108; // [sp+38h] [bp-5Ch]@1
   int v109; // [sp+3Ch] [bp-58h]@28
   int v110; // [sp+40h] [bp-54h]@180
   int v111; // [sp+44h] [bp-50h]@14
@@ -2230,7 +2230,7 @@
   BSPModel *v127; // [sp+84h] [bp-10h]@1
   int v128; // [sp+88h] [bp-Ch]@1
   int v129; // [sp+8Ch] [bp-8h]@92
-  int v130; // [sp+90h] [bp-4h]@14
+  //int v130; // [sp+90h] [bp-4h]@14
 
   v121 = pParty->uFallSpeed;
   pZ = pParty->vPosition.z;
@@ -2247,22 +2247,12 @@
   auto partyAtHighSlope = IsTerrainSlopeTooHigh(pParty->vPosition.x, pParty->vPosition.y);
   v114 = 0;
   v124 = 0;
-  v108 = 0;
   v102 = 0;
   v127 = 0;
   bWaterWalk = 0;
   if (!pParty->FeatherFallActive())
-      //SHIDWORD(pParty->pPartyBuffs[5].uExpireTime) < 0
-      //|| SHIDWORD(pParty->pPartyBuffs[5].uExpireTime) <= 0 && LODWORD(pParty->pPartyBuffs[5].uExpireTime) <= 0 )
   {
     bFeatherFall = 0;
-    /*v119 = &pPlayers[1];
-    while ( !(*v119)->WearsItem(536, 16) )
-    {
-      ++v119;
-      if ( (signed int)v119 > (signed int)&pPlayers[4] )
-        goto LABEL_9;
-    }*/
     for (int i = 0; i < 4; ++i)
       if (pParty->pPlayers[i].WearsItem(ITEM_ARTIFACT_LADYS_ESCORT, EQIUP_ANY))  // seems like flying boots
       {
@@ -2285,7 +2275,11 @@
 		pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster - 1].sMana <= 0 )
       bWaterWalk = 0;
   }
-  v3 = ODM_GetFloorLevel(pX, pY, pZ, pParty->uPartyHeight, &v130, &v108, bWaterWalk);
+  int bmodel_standing_on_pid;
+  int is_on_water = false;
+  v3 = ODM_GetFloorLevel(pX, pY, pZ, pParty->uPartyHeight, &is_on_water, &bmodel_standing_on_pid, bWaterWalk);
+  int is_not_on_bmodel = bmodel_standing_on_pid == 0;
+
   v111 = v3;
   if ( bFeatherFall )
     pParty->uFallStartY = v3;
@@ -2316,7 +2310,7 @@
   v109 = -1;
   if ( pParty->bFlying )
     v109 = sub_46D8E3(pX, pY, pZ + pParty->uPartyHeight, (int)&v102);
-  v107 = v108 == 0;
+  //v107 = bmodel_standing_on_pid == 0;
   v105 = v111 + 1;
   if ( pZ <= v111 + 1 )
   {
@@ -2334,20 +2328,18 @@
       pParty->walk_sound_timer -= pEventTimer->uTimeElapsed;
     else pParty->walk_sound_timer = 0;
   }
-  if (!bUnderwater
-    && SHIDWORD(pParty->pPartyBuffs[PARTY_BUFF_FLY].uExpireTime) <= 0
-    && (SHIDWORD(pParty->pPartyBuffs[PARTY_BUFF_FLY].uExpireTime) < 0 || LODWORD(pParty->pPartyBuffs[PARTY_BUFF_FLY].uExpireTime) <= 0) )
+  if (!bUnderwater && pParty->pPartyBuffs[PARTY_BUFF_FLY].uExpireTime <= 0)
     pParty->bFlying = false;
   if (!bJumping)
   {
-    if ( pParty->floor_face_pid != PID(OBJECT_BModel, v108) )
+    if ( pParty->floor_face_pid != PID(OBJECT_BModel, bmodel_standing_on_pid) )
     {
-      if (v108)
+      if (bmodel_standing_on_pid)
       {
-        if ( v108 >> 6 < pOutdoor->uNumBModels )
+        if ( (bmodel_standing_on_pid >> 6) < pOutdoor->uNumBModels )
         {
-          v7 = pOutdoor->pBModels[v108 >> 6].pFaces;
-          v6 = v108 & 0x3F;
+          v7 = pOutdoor->pBModels[bmodel_standing_on_pid >> 6].pFaces;
+          v6 = bmodel_standing_on_pid & 0x3F;
           /*if ( *(char *)(v7->pFacePlane.vNormal.x + 308 * v6 + 31) & 4 )
           {
             pParty->field_6F4_packedid = PID(OBJECT_BModel,v108);
@@ -2355,13 +2347,13 @@
           }*/
 		  if ( BYTE3(v7[v6].uAttributes) & 4 )
           {
-            pParty->floor_face_pid = PID(OBJECT_BModel, v108);
+            pParty->floor_face_pid = PID(OBJECT_BModel, bmodel_standing_on_pid);
             v103 = v7[v6].sCogTriggeredID;
           }
         }
       }
     }
-    pParty->floor_face_pid = PID(OBJECT_BModel, v108);
+    pParty->floor_face_pid = PID(OBJECT_BModel, bmodel_standing_on_pid);
   }
   _walk_speed = pParty->uWalkSpeed;
   _angle_y = pParty->sRotationY;
@@ -2547,7 +2539,7 @@
 
           v128 = v1;
         }
-        else if (partyAtHighSlope && !v108)
+        else if (partyAtHighSlope && !bmodel_standing_on_pid)
         {
           v2 += dx;
           v1 += dy;
@@ -2633,7 +2625,7 @@
       break;
 
       case PARTY_Jump:
-        if ( (!partyAtHighSlope || v108) && !bJumping && pParty->field_24 && !(pParty->uFlags & 4) && !(BYTE1(pParty->uFlags) & 2) )
+        if ( (!partyAtHighSlope || bmodel_standing_on_pid) && !bJumping && pParty->field_24 && !(pParty->uFlags & 4) && !(BYTE1(pParty->uFlags) & 2) )
         {
           v126 = pParty->field_24 << 6;
           bJumping = 1;
@@ -2677,7 +2669,7 @@
     }
 	else
 	{
-		if ( v130 && v121 )
+		if ( is_on_water && v121 )
 		  sub_42F960_create_object(pX, pY, v111);
 		v121 = 0;
 		pZ = v111;
@@ -2707,7 +2699,7 @@
   }
   else if (!bJumping)
   {
-    if ( !v108 )
+    if ( !bmodel_standing_on_pid )
 	{
 		// rolling down the hill
 		// how it's done: you get a little bit pushed in the air along terrain normal, getting in the air
@@ -2801,18 +2793,18 @@
       v40 = ((unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.z) >> 16) + pZ;
     }
     v122 = v40;
-    ODM_GetFloorLevel(_angle_x, _angle_y, v40, pParty->uPartyHeight, &v130, &v108, 0);
-    v129 = ODM_GetFloorLevel(_angle_x, pY, v40, pParty->uPartyHeight, &v130, &v97, 0);
-    auto v119 = ODM_GetFloorLevel(pX, _angle_y, v40, pParty->uPartyHeight, &v130, &v110, 0);
+    ODM_GetFloorLevel(_angle_x, _angle_y, v40, pParty->uPartyHeight, &is_on_water, &bmodel_standing_on_pid, 0);
+    v129 = ODM_GetFloorLevel(_angle_x, pY, v40, pParty->uPartyHeight, &is_on_water, &v97, 0);
+    auto v119 = ODM_GetFloorLevel(pX, _angle_y, v40, pParty->uPartyHeight, &is_on_water, &v110, 0);
     v127 = (BSPModel *)IsTerrainSlopeTooHigh(_angle_x, pY);
     v42 = IsTerrainSlopeTooHigh(pX, _angle_y);
-    v107 = 0;
+    is_not_on_bmodel = false;
     v118 = v42;
-    if ( !v97 && !v110 && !v108 )
-      v107 = 1;
+    if ( !v97 && !v110 && !bmodel_standing_on_pid )
+      is_not_on_bmodel = true;
     v43 = 1;
     v44 = 1;
-    if ( bUnderwater || !v107 )
+    if ( bUnderwater || !is_not_on_bmodel )
 	{
 		  pX = _angle_x;
 		  if ( v43 )
@@ -2834,7 +2826,7 @@
 		  pY = _angle_y;
 		else
 		{
-			v127 = (BSPModel *)ODM_GetFloorLevel(_angle_x, _angle_y, v40, pParty->uPartyHeight, &v130, &v108, 0);
+			v127 = (BSPModel *)ODM_GetFloorLevel(_angle_x, _angle_y, v40, pParty->uPartyHeight, &is_on_water, &bmodel_standing_on_pid, 0);
 			if ( IsTerrainSlopeTooHigh(_angle_x, _angle_y) && (signed int)v127 <= pZ )
 			{
 			  v43 = 1;
@@ -2846,7 +2838,7 @@
 	}
     if ( stru_721530.field_7C >= stru_721530.field_6C )
     {
-      if ( !v107 )
+      if ( !is_not_on_bmodel )
       {
         pX = stru_721530.normal2.x;
         pY = stru_721530.normal2.y;
@@ -2877,9 +2869,8 @@
     {
       v56 = integer_sqrt(v2 * v2 + v128 * v128);
       v118 = v56;
-      v57 = stru_5C6E00->Atan2(
-              _angle_x - pLevelDecorations[(signed int)stru_721530.uFaceID >> 3].vPosition.x,
-              _angle_y - pLevelDecorations[(signed int)stru_721530.uFaceID >> 3].vPosition.y);
+      v57 = stru_5C6E00->Atan2(_angle_x - pLevelDecorations[(signed int)stru_721530.uFaceID >> 3].vPosition.x,
+                               _angle_y - pLevelDecorations[(signed int)stru_721530.uFaceID >> 3].vPosition.y);
       v129 = v57;
       v58 = (BSPModel *)stru_5C6E00->Cos(v57);
       v127 = v58;
@@ -2920,7 +2911,7 @@
 				v2 = 0;
 				*(float *)&v128 = 0.0;
 			}
-			if ( pParty->floor_face_pid != v45 && BYTE3(v47->uAttributes) & 4 )
+			if ( pParty->floor_face_pid != v45 && (v47->uAttributes & FACE_PRESSURE_PLATE))
 			{
 				pParty->floor_face_pid = v45;
 				v103 = v47->sCogTriggeredID;
@@ -3035,7 +3026,7 @@
 	{
 		if ( v114 && (!bJumping || v101) )
 		{
-		  if ( !v107
+		  if ( !is_not_on_bmodel
 			&& !(BYTE1(pOutdoor->pBModels[pParty->floor_face_pid >> 9].pFaces[(pParty->floor_face_pid >> 3) & 0x3F].uAttributes) & 0x20) )
 		  {
             pAudioPlayer->PlaySound((SoundID)64, 804, 1, -1, 0, 0, 0, 0);
@@ -3052,7 +3043,7 @@
 		{
 			if ( v124 && (!bJumping || v101) )
 			{
-			  if ( v107
+			  if ( is_not_on_bmodel
 				|| BYTE1(pOutdoor->pBModels[pParty->floor_face_pid >> 9].pFaces[(pParty->floor_face_pid >> 3) & 0x3F].uAttributes) & 0x20 )
 			  {
 				v63 = WorldPosToGridCellZ(pParty->vPosition.y) - 1;
@@ -3079,14 +3070,14 @@
   v65 = WorldPosToGridCellZ(pParty->vPosition.y) - 1;
   v114 = WorldPosToGridCellX(pX);
   v66 = WorldPosToGridCellZ(pY) - 1;
-  v127 = (BSPModel *)(((unsigned int)~pOutdoor->ActuallyGetSomeOtherTileInfo(v126, v65) >> 1) & 1);
-  v122 = ((unsigned int)~pOutdoor->ActuallyGetSomeOtherTileInfo(v114, v65) >> 1) & 1;
+  v127 = (BSPModel *)((~(unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(v126, v65) >> 1) & 1);
+  v122 = (~(unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(v114, v65) >> 1) & 1;
   v67 = pOutdoor->ActuallyGetSomeOtherTileInfo(v126, v66);
   v68 = 0;
-  v69 = ((unsigned int)~v67 >> 1) & 1;
+  v69 = (~(unsigned int)v67 >> 1) & 1;
   if ( v114 == v126 && v66 == v65 && v122 && v69 )
     v68 = 1;
-  if ( !v107 )
+  if ( !is_not_on_bmodel )
     v68 = 1;
   if ( v68 )
   {
--- a/mm7_4.cpp	Sat Jul 27 14:28:14 2013 +0200
+++ b/mm7_4.cpp	Sat Jul 27 16:09:00 2013 +0200
@@ -530,15 +530,8 @@
 //----- (00487DA9) --------------------------------------------------------
 void __cdecl sub_487DA9()
 {
-  char *v0; // eax@1
-
-  v0 = &array_77EC08[0].field_108;
-  do
-  {
-    *v0 = 0;
-    v0 += 268;
-  }
-  while ( (signed int)v0 < (signed int)&pVerticesSR_801A10[4] );
+  for (int i = 0; i < 20000; ++i)
+    array_77EC08[i].field_108 = 0;
 }
 
 //----- (00487DBE) --------------------------------------------------------
@@ -585,9 +578,9 @@
     v = v_replace;
   HSV2RGB(&r, &g, &b, h, s, v);
 
-  return (((uint)floorf(r * 255.0f + 0.5f) & 0xFF) << 16) |
-         (((uint)floorf(g * 255.0f + 0.5f) & 0xFF) << 8) |
-         ((uint)floorf(b * 255.0f + 0.5f) & 0xFF);
+  return (((uint)round(r * 255.0f) & 0xFF) << 16) |
+         (((uint)round(g * 255.0f) & 0xFF) << 8) |
+         (((uint)round(b * 255.0f) & 0xFF));
 }
 
 //----- (0048B561) --------------------------------------------------------
@@ -3735,19 +3728,17 @@
 		ArenaFight();
 		return;
 	}
-	else if(newDialogueType == DIALOGUE_9)
+	else if(newDialogueType == DIALOGUE_USE_NPC_ABILITY)
 	{
-		if ( !sub_4BB756(speakingNPC->uProfession) )
+		if (UseNPCSkill((NPCProf)speakingNPC->uProfession) == 0)
 		{
-			if ( speakingNPC->uProfession != 41 )
+			if ( speakingNPC->uProfession != GateMaster )
 				speakingNPC->bHasUsedTheAbility = 1;
 
 			pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
 		}
 		else
-		{
-			ShowStatusBarString(pGlobalTXT_LocalizationStrings[140], 2u); //"Your packs are already full!"
-		}
+			ShowStatusBarString(pGlobalTXT_LocalizationStrings[140], 2); //"Your packs are already full!"
 	}
 	else if(newDialogueType == DIALOGUE_13)
 	{
--- a/mm7_data.h	Sat Jul 27 14:28:14 2013 +0200
+++ b/mm7_data.h	Sat Jul 27 16:09:00 2013 +0200
@@ -1343,7 +1343,7 @@
 bool __fastcall _46BFFA_check_object_intercept(unsigned int uLayingItemID, signed int a2);
 void __cdecl check_event_triggers();
 int BLV_GetFloorLevel(int x, int y, int z, unsigned int uSectorID, unsigned int *pFaceID);
-int __fastcall ODM_GetFloorLevel(int X, signed int Y, int Z, int, int *pOnWater, int *a6, int bWaterWalk);
+int ODM_GetFloorLevel(int X, signed int Y, int Z, int, int *pOnWater, int *bmodel_pid, int bWaterWalk);
 int __fastcall sub_46D8E3(int a1, signed int a2, int a3, int a4);
 void ODM_GetTerrainNormalAt(int pos_x, int pos_z, Vec3_int_ *out);
 unsigned int __fastcall sub_46DEF2(signed int a2, unsigned int uLayingItemID);
@@ -1452,7 +1452,6 @@
 void __fastcall DrawTextAtStatusBar(const char *Str, int a5);
 int __fastcall sub_4B46F8(int a1);
 
-signed int __fastcall sub_4BB756(signed int a1);
 const char *sub_4BBA85_bounties();
 void __cdecl sub_4BBCDD();
 void __fastcall _4BBF61_summon_actor(int a1, __int16 x, int y, int z); // idb