changeset 1410:38df78aba732

deleted stru220.h and stru220 (bezier terrain stuff) stru167 -> TrailParticle stru167warp -> TrailParticleGenerator
author Nomad
date Fri, 26 Jul 2013 22:19:29 +0200
parents c9e3b93ec570
children 2423bc2af692
files GUIWindow.cpp Indoor.cpp Indoor_stuff.h NPC.cpp Outdoor.cpp Outdoor_stuff.h ParticleEngine.cpp ParticleEngine.h Render.cpp SpriteObject.cpp UI/Books/UINotesBooks.cpp UI/UIGuilds.cpp UI/UIShops.cpp UI/UiGame.cpp _deleted.cpp mm7_2.cpp mm7_3.cpp mm7_4.cpp mm7_data.cpp mm7_data.h stru220.h
diffstat 21 files changed, 439 insertions(+), 496 deletions(-) [+]
line wrap: on
line diff
--- a/GUIWindow.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/GUIWindow.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -671,7 +671,7 @@
                   {
                   if ( v4 )
                       {
-                      v5 = BuilDialogueString(v4, uActiveCharacter - 1, 0, 0, 0, v3);
+                      v5 = BuildDialogueString(v4, uActiveCharacter - 1, 0, 0, 0, v3);
                       v6 = pAutonoteFont->CalcTextHeight(v5, &v26, 1, 0);
                       v7 = (v6 - 3) / (signed int)v26.uFrameHeight;
                       v8 = v7 + 1;
--- a/Indoor.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/Indoor.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -62,7 +62,6 @@
 
 stru320 stru_F8AD28; // idb
 stru337 stru_F81018;
-stru167_wrap array_5118E8;
 BspRenderer_PortalViewportData stru_F8A590;
 BspRenderer *pBspRenderer = new BspRenderer; // idb
 stru141 stru_721530;
@@ -412,7 +411,7 @@
   sub_440BED(&_this);
   pParty->uFlags &= ~2;
   pGame->DrawParticles();
-  array_5118E8._440F07();
+  trail_particle_generator.UpdateParticles();
 }
 
 //----- (004C0EF2) --------------------------------------------------------
--- a/Indoor_stuff.h	Fri Jul 26 21:16:51 2013 +0200
+++ b/Indoor_stuff.h	Fri Jul 26 22:19:29 2013 +0200
@@ -111,52 +111,6 @@
 
 
 
-/*  160 */
-#pragma pack(push, 1)
-struct stru167
-{
-  char field_0;
-  char field_1;
-  char field_2;
-  char field_3;
-  char field_4;
-  char field_5;
-  __int16 field_6_rnd_value;
-  __int16 field_8_rnd_value;
-  __int16 field_A_rnd_value;
-  __int16 field_C_time_left;
-  __int16 field_E_time_to_live;
-  char field_10;
-  char field_11;
-  char field_12;
-  char field_13;
-  __int16 bgr16;
-  char field_16;
-  char field_17;
-};
-#pragma pack(pop)
-
-
-
-/*  363 */
-#pragma pack(push, 1)
-struct stru167_wrap
-{
-  void _440F07();
-  int Push(__int16 a2, __int16 a3, __int16 a4, int a5, __int16 bgr);
-  void _440E91(__int16 x, int y, int z, int a5, __int16 bgr);
-
-  stru167 pElements[100];
-  int uNumElements;
-  int field_964;
-};
-#pragma pack(pop)
-extern stru167_wrap array_5118E8;
-
-
-
-
-
 
 
 
--- a/NPC.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/NPC.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -1312,7 +1312,7 @@
   {
     case 13:
       current_npc_text = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession].pJoinText;//(char *)*(&pNPCStats->field_13A64 + 5 * v2->uProfession);
-      current_npc_text = BuilDialogueString((char *)current_npc_text, uActiveCharacter - 1, 0, 0, 0, 0);
+      current_npc_text = BuildDialogueString((char *)current_npc_text, uActiveCharacter - 1, 0, 0, 0, 0);
       NPCHireableDialogPrepare();
       dialogue_show_profession_details = false;
       goto _return;
@@ -1391,7 +1391,7 @@
       else
         v17 = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].pBenefits;
       current_npc_text = v17;
-      v18 = BuilDialogueString(v17, uActiveCharacter - 1, 0, 0, 0, 0);
+      v18 = BuildDialogueString(v17, uActiveCharacter - 1, 0, 0, 0, 0);
       dialogue_show_profession_details = ~dialogue_show_profession_details;
       current_npc_text = v18;
     }
@@ -1511,7 +1511,7 @@
       dialogue_show_profession_details = false;
       uDialogueType = 13;
       current_npc_text = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].pJoinText;
-      current_npc_text = BuilDialogueString((char *)current_npc_text, uActiveCharacter - 1, 0, 0, 0, 0);
+      current_npc_text = BuildDialogueString((char *)current_npc_text, uActiveCharacter - 1, 0, 0, 0, 0);
       if ( uActiveCharacter )
         pPlayers[uActiveCharacter]->PlaySound(SPEECH_NotEnoughGold, 0);
       ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);
--- a/Outdoor.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/Outdoor.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -28,6 +28,7 @@
 #include "Time.h"
 #include "Viewport.h"
 #include "Events.h"
+#include "ParticleEngine.h"
 
 #include "mm7_data.h"
 #include "MM7.h"
@@ -195,7 +196,7 @@
 
   pGame->DrawParticles();
   pWeather->Draw();
-  array_5118E8._440F07();
+  trail_particle_generator.UpdateParticles();
 }
 
 //----- (00488E23) --------------------------------------------------------
@@ -782,7 +783,7 @@
     a3d = v22 * v19 - v21 * v18;
     v16 = a3d + 6.7553994e15;
     v3->v_18.z = LODWORD(v16);
-    v3->_486089_normalize_v_18();
+    v3->_normalize_v_18();
     a3e = -((double)v3->v_18.x * v4->vWorldViewPosition.x)
         - (double)v3->v_18.y * v4->vWorldViewPosition.y
         - (double)v3->v_18.z * v4->vWorldViewPosition.z;
--- a/Outdoor_stuff.h	Fri Jul 26 21:16:51 2013 +0200
+++ b/Outdoor_stuff.h	Fri Jul 26 22:19:29 2013 +0200
@@ -18,7 +18,7 @@
   int _479295();
   void DrawBorderTiles();
   //void _48276F_sr();
-  void _486089_normalize_v_18();
+  void _normalize_v_18();
   void _48607B(struct stru149 *a2);
 
   float field_0;
--- a/ParticleEngine.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/ParticleEngine.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -12,6 +12,47 @@
 #include "OutdoorCamera.h"
 #include "mm7_data.h"
 
+TrailParticleGenerator trail_particle_generator;
+
+
+//----- (00440DF5) --------------------------------------------------------
+void TrailParticleGenerator::AddParticle(int x, int y, int z, int bgr16)
+{
+  particles[num_particles].x = x;
+  particles[num_particles].y = y;
+  particles[num_particles].z = z;
+  particles[num_particles].time_to_live = rand() % 64 + 256;
+  particles[num_particles].time_left = particles[num_particles].time_to_live;
+  particles[num_particles].bgr16 = bgr16;
+
+  num_particles++;
+  assert(num_particles < 100);
+}
+
+//----- (00440E91) --------------------------------------------------------
+void TrailParticleGenerator::GenerateTrailParticles(int x, int y, int z, int bgr16)
+{
+  for (int i = 0; i < 5 + rand() % 6; ++i)
+    AddParticle(rand() % 33 + x - 16,
+                rand() % 33 + y - 16,
+                rand() % 33 + z, bgr16);
+}
+
+//----- (00440F07) --------------------------------------------------------
+void TrailParticleGenerator::UpdateParticles()
+{
+  for (uint i = 0; i < 100; ++i)
+  {
+    if (particles[i].time_left > 0)
+    {
+      particles[i].x += rand() % 5 + 4;
+      particles[i].y += rand() % 5 - 2;
+      particles[i].z += rand() % 5 - 2;
+      particles[i].time_left -= pEventTimer->uTimeElapsed;
+    }
+  }
+}
+
 //----- (0048AAC5) --------------------------------------------------------
 ParticleEngine::ParticleEngine()
 {
--- a/ParticleEngine.h	Fri Jul 26 21:16:51 2013 +0200
+++ b/ParticleEngine.h	Fri Jul 26 22:19:29 2013 +0200
@@ -127,4 +127,73 @@
   int uEndParticle;
   int uTimeElapsed;
 };
-#pragma pack(pop)
\ No newline at end of file
+#pragma pack(pop)
+
+
+
+
+
+
+
+
+
+
+
+/*  160 */
+#pragma pack(push, 1)
+struct TrailParticle // stru167
+{
+  inline TrailParticle()
+  {
+    x = 0;
+    y = 0;
+    z = 0;
+    time_left = 0;
+    time_to_live = 0;
+    bgr16 = 0;
+  }
+
+  char field_0;
+  char field_1;
+  char field_2;
+  char field_3;
+  char field_4;
+  char field_5;
+  __int16 x;
+  __int16 y;
+  __int16 z;
+  __int16 time_left;
+  __int16 time_to_live;
+  char field_10;
+  char field_11;
+  char field_12;
+  char field_13;
+  __int16 bgr16;
+  char field_16;
+  char field_17;
+};
+#pragma pack(pop)
+
+
+/*  363 */
+#pragma pack(push, 1)
+struct TrailParticleGenerator // stru167_wrap
+{
+  public:
+    inline TrailParticleGenerator()
+    {
+      num_particles = 0;
+    }
+
+    void GenerateTrailParticles(int x, int y, int z, int bgr16);
+    void UpdateParticles();
+
+  protected:
+    void AddParticle(int x, int y, int z, int bgr16);
+
+    TrailParticle particles[100];
+    int           num_particles;
+    int           field_964;
+};
+#pragma pack(pop)
+extern TrailParticleGenerator trail_particle_generator; // 005118E8
\ No newline at end of file
--- a/Render.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/Render.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -25,7 +25,6 @@
 #include "Time.h"
 #include "Game.h"
 #include "LightmapBuilder.h"
-#include "stru220.h"
 #include "ObjectList.h"
 #include "SpriteObject.h"
 #include "DecorationList.h"
@@ -517,7 +516,7 @@
       v6 = abs(v83);//v6 = 13108
       --X;
       //__debugbreak(); // uncoment & refactor following large if
-      v93 = (int)&stru_76E5C8[(v5 << 7) + v6];
+      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,
@@ -538,8 +537,8 @@
                WorldPosToGridCellZ(sY),
                !byte_4D864C)
            || !(pGame->uFlags & 0x80))
-          && !sub_481EFA(v8, v9, v101, pVertices, 1)) )*/
-      /*if ( !&stru_76E5C8[(v5 << 7) + v6] )
+          && !_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];
@@ -560,7 +559,7 @@
       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 ((!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;*/
@@ -590,7 +589,7 @@
           if ( pOutdoorCamera->uNumPolygons >= 1999 )
             return;
           ++pOutdoorCamera->uNumPolygons;
-          //if ( !sub_481FC9(v8, pVertices, v101, v16) )//Ritor1: It's temporary
+          //if ( !_481FC9_terrain(v8, pVertices, v101, v16) )//Ritor1: It's temporary
           //goto LABEL_126;
           //{
             //--pOutdoorCamera->uNumPolygons;
@@ -731,7 +730,7 @@
       if ( pOutdoorCamera->uNumPolygons >= 1999 )
         return;
       ++pOutdoorCamera->uNumPolygons;
-      /*if ( !sub_481FC9(pVertices, pVertices2, v8, v40) ) // Ritor1: It's temporary
+      /*if ( !_481FC9_terrain(pVertices, pVertices2, v8, v40) ) // Ritor1: It's temporary
         //goto LABEL_77;
         {
           --pOutdoorCamera->uNumPolygons;
@@ -860,7 +859,7 @@
       if ( pOutdoorCamera->uNumPolygons >= 1999 )
         return;
       ++pOutdoorCamera->uNumPolygons;
-      if ( !sub_481FC9(v101, v102, pVertices2, v59) )
+      if ( !_481FC9_terrain(v101, v102, pVertices2, v59) )
       {
 //LABEL_126:
         --pOutdoorCamera->uNumPolygons;
@@ -1015,11 +1014,12 @@
     billboard.uFlags = pBillboard->field_1E;
     if (pBillboard->uHwSpriteID != -1)
     {
-      if (pRenderer->pRenderD3D)
+      if (!pRenderer->pRenderD3D) __debugbreak(); // no sw rendering
+      //if (pRenderer->pRenderD3D)
         pRenderer->TransformBillboard(&billboard,
                                       &pSprites_LOD->pHardwareSprites[pBillboard->uHwSpriteID],
                                       pBillboard->dimming_level, pBillboard);
-      else
+      /*else
       {
           assert(false);
 
@@ -1027,7 +1027,7 @@
           if ( *(v1 - 10) & 2 )
             v9 = PaletteManager::Get_Dark_or_Red_LUT(*((short *)v1 - 7), 0, 1);
           else
-            v9 = GetBillboardPalette((RenderBillboard *)(v1 - 40), *((short *)v1 - 7), pBillboard->sZValue, *((short *)v1 + 1));
+            v9 = sr_GetBillboardPalette((RenderBillboard *)(v1 - 40), *((short *)v1 - 7), pBillboard->sZValue, *((short *)v1 + 1));
           v10 = (*(v1 - 9) & 1) == 0;
           billboard.pPalette = v9;
           if ( !v10 )
@@ -1042,7 +1042,7 @@
           v13 = *((short *)v1 - 8);
           if ( v13 >= 0 )
             pSprites_LOD->pSpriteHeaders[v13].DrawSprite_sw(&billboard, 1);
-      }
+      }*/
     }
   }
 }
--- a/SpriteObject.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/SpriteObject.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -1093,9 +1093,6 @@
         (item->uSoundID & 8 || pObjectList->pObjects[item->uType].uFlags & 0x10))
       SpriteObject::OnInteraction(i);
   }
-
-  for (uint i = 0; i < 100; ++i)
-    array_5118E8.pElements[i].field_C_time_left = 0;
 }
 //----- (0046BEF1) --------------------------------------------------------
 void SpriteObject::_46BEF1_apply_spells_aoe()
--- a/UI/Books/UINotesBooks.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/UI/Books/UINotesBooks.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -637,7 +637,7 @@
   num_achieved_awards = 0;
   //v7 = *pStorylineText->StoreLine[v6].pText;//*(&pStorylineText->field_0 + 3 * v6);
   v7 = (int)pStorylineText->StoreLine[v6].pText;//*(&pStorylineText->field_0 + 3 * v6);
-  v8 = BuilDialogueString(
+  v8 = BuildDialogueString(
          pStorylineText->StoreLine[v6].pText,
          uActiveCharacter - 1,
          0,
--- a/UI/UIGuilds.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/UI/UIGuilds.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -183,7 +183,7 @@
         v16 = (int)window_SpeakInHouse->ptr_1C;
         uPlayerID = uActiveCharacter - 1;
         v17 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction( (ItemGen *)&pParty->pPlayers[1].uExpressionTimeLength + v13 + 12 * (int)v14, BildingType_MagicShop, v16,  2);
-        v18 = BuilDialogueString((char *)pMerchantsBuyPhrases[v17], uPlayerID, v15, (char *)v14, 2, 0);     
+        v18 = BuildDialogueString((char *)pMerchantsBuyPhrases[v17], uPlayerID, v15, (char *)v14, 2, 0);     
         v19 = pFontArrus->CalcTextHeight(v18, &working_window, 0, 0);
         working_window.DrawTitleText(pFontArrus, 0, (174 - v19) / 2 + 138,  pColorWhite, v18, 3);
         return;
--- a/UI/UIShops.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/UI/UIShops.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -234,13 +234,13 @@
             if ( !v56 || !Str )
             {
               v64 = pPlayer->SelectPhrasesTransaction(pItemInShop, BildingType_WeaponShop, v61, 2);
-              v7 = BuilDialogueString((char *)pMerchantsBuyPhrases[v64], uActiveCharacter - 1, pItemInShop, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+              v7 = BuildDialogueString((char *)pMerchantsBuyPhrases[v64], uActiveCharacter - 1, pItemInShop, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
               pTextHeight = pFontArrus->CalcTextHeight(v7, &dialog_window, 0, 0);
               dialog_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, pColorWhite, v7, 3);
             }
             else
             {
-              v7 = BuilDialogueString(pGlobalTXT_LocalizationStrings[181], uActiveCharacter - 1, pItemInShop, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+              v7 = BuildDialogueString(pGlobalTXT_LocalizationStrings[181], uActiveCharacter - 1, pItemInShop, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
               pTextHeight = pFontArrus->CalcTextHeight(v7, &dialog_window, 0, 0);
               dialog_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, pColorWhite, v7, 3);
             }
@@ -268,7 +268,7 @@
         return;
       v79 = (ItemGen *)&pPlayer->pInventoryItemList[pNumActiveItem - 1];
       v13 = pPlayer->SelectPhrasesTransaction(v79, BildingType_WeaponShop, (int)window_SpeakInHouse->ptr_1C, 3);
-      v7 = BuilDialogueString((char *)pMerchantsSellPhrases[v13], uActiveCharacter - 1, v79, (char *)window_SpeakInHouse->ptr_1C, 3, 0);
+      v7 = BuildDialogueString((char *)pMerchantsSellPhrases[v13], uActiveCharacter - 1, v79, (char *)window_SpeakInHouse->ptr_1C, 3, 0);
       pTextHeight = pFontArrus->CalcTextHeight(v7, &dialog_window, 0, 0);
       dialog_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, pColorWhite, v7, 3);
       break;
@@ -289,13 +289,13 @@
       if (!v4->Identified())
       {
         v10 = pPlayer->SelectPhrasesTransaction(v4, BildingType_WeaponShop, (int)window_SpeakInHouse->ptr_1C, 4);
-        v7 = BuilDialogueString((char *)pMerchantsIdentifyPhrases[v10], uActiveCharacter - 1, v4, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
+        v7 = BuildDialogueString((char *)pMerchantsIdentifyPhrases[v10], uActiveCharacter - 1, v4, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
         pTextHeight = pFontArrus->CalcTextHeight(v7, &dialog_window, 0, 0);
         dialog_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, pColorWhite, v7, 3);
       }
       else
       {
-        v7 = BuilDialogueString("%24", uActiveCharacter - 1, v4, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
+        v7 = BuildDialogueString("%24", uActiveCharacter - 1, v4, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
         pTextHeight = pFontArrus->CalcTextHeight(v7, &dialog_window, 0, 0);
         dialog_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, pColorWhite, v7, 3);
       }
@@ -316,7 +316,7 @@
             return;
       v4 = (ItemGen *)&pPlayer->pInventoryItemList[pNumActiveItem - 1];
       v10 = pPlayer->SelectPhrasesTransaction(v4, BildingType_ArmorShop, (int)window_SpeakInHouse->ptr_1C, 5);
-      v7 = BuilDialogueString((char *)pMerchantsRepairPhrases[v10], uActiveCharacter - 1, v4, (char *)window_SpeakInHouse->ptr_1C, 5, 0);
+      v7 = BuildDialogueString((char *)pMerchantsRepairPhrases[v10], uActiveCharacter - 1, v4, (char *)window_SpeakInHouse->ptr_1C, 5, 0);
       pTextHeight = (174 - pFontArrus->CalcTextHeight(v7, &dialog_window, 0, 0)) / 2 + 138;
       dialog_window.DrawTitleText(pFontArrus, 0, pTextHeight, pColorWhite, v7, 3);
       return;
@@ -425,13 +425,13 @@
             if ( !v56 || !Str )
             {
               v64 = pPlayer->SelectPhrasesTransaction(pItemInShop, BildingType_WeaponShop, v61, 2);
-              v7 = BuilDialogueString((char *)pMerchantsBuyPhrases[v64], uActiveCharacter - 1, pItemInShop, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+              v7 = BuildDialogueString((char *)pMerchantsBuyPhrases[v64], uActiveCharacter - 1, pItemInShop, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
               pTextHeight = pFontArrus->CalcTextHeight(v7, &dialog_window, 0, 0);
               dialog_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, pColorWhite, v7, 3);
             }
             else
             {
-              v7 = BuilDialogueString(pGlobalTXT_LocalizationStrings[181], uActiveCharacter - 1, pItemInShop, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+              v7 = BuildDialogueString(pGlobalTXT_LocalizationStrings[181], uActiveCharacter - 1, pItemInShop, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
               pTextHeight = pFontArrus->CalcTextHeight(v7, &dialog_window, 0, 0);
               dialog_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, pColorWhite, v7, 3);
             }
@@ -764,7 +764,7 @@
           v15 = (char *)pMerchantsBuyPhrases[pPlayers[uActiveCharacter]->SelectPhrasesTransaction(selected_item, BildingType_ArmorShop, window_SpeakInHouse->par1C, 2)];
         else
           v15 = pGlobalTXT_LocalizationStrings[181]; //"Steal %24"
-        v36 = BuilDialogueString(v15, uActiveCharacter - 1, selected_item, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+        v36 = BuildDialogueString(v15, uActiveCharacter - 1, selected_item, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
         v115 = (174 - pFontArrus->CalcTextHeight(v36, &dialog_window, 0, 0)) / 2 + 138;
         dialog_window.DrawTitleText(pFontArrus, 0, v115, pWhiteColor, v36, 3);
         return;
@@ -836,7 +836,7 @@
           v15 = (char *)pMerchantsBuyPhrases[pPlayers[uActiveCharacter]->SelectPhrasesTransaction(selected_item, BildingType_ArmorShop, window_SpeakInHouse->par1C, 2)];
         else
           v15 = pGlobalTXT_LocalizationStrings[181]; //"Steal %24"
-        v36 = BuilDialogueString(v15, uActiveCharacter - 1, selected_item, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+        v36 = BuildDialogueString(v15, uActiveCharacter - 1, selected_item, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
         v115 = (174 - pFontArrus->CalcTextHeight(v36, &dialog_window, 0, 0)) / 2 + 138;
         dialog_window.DrawTitleText(pFontArrus, 0, v115, pWhiteColor, v36, 3);
         return;
@@ -897,7 +897,7 @@
       v116 = (ItemGen *)&pPlayers[uActiveCharacter]->pInventoryItemList[v10 - 1];
       v13 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(v116, BildingType_ArmorShop, window_SpeakInHouse->par1C, 3);
       v15 = (char *)pMerchantsSellPhrases[pPlayers[uActiveCharacter]->SelectPhrasesTransaction(v116, BildingType_ArmorShop, window_SpeakInHouse->par1C, 3)];
-      v36 = BuilDialogueString(v15, uActiveCharacter - 1, v116, (char *) window_SpeakInHouse->par1C, 3, 0);
+      v36 = BuildDialogueString(v15, uActiveCharacter - 1, v116, (char *) window_SpeakInHouse->par1C, 3, 0);
       v115 = (174 - pFontArrus->CalcTextHeight(v36, &dialog_window, 0, 0)) / 2 + 138;
       dialog_window.DrawTitleText(pFontArrus, 0, v115, pWhiteColor, v36, 3);
       return;
@@ -927,7 +927,7 @@
                 v8 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(v3, BildingType_ArmorShop, (int)window_SpeakInHouse->ptr_1C, 4);
                 v5 = (char *)pMerchantsIdentifyPhrases[v8];
               }
-              v6 = BuilDialogueString(v5, uActiveCharacter - 1, v3, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
+              v6 = BuildDialogueString(v5, uActiveCharacter - 1, v3, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
               v115 = (174 - pFontArrus->CalcTextHeight(v6, &dialog_window, 0, 0)) / 2 + 138;
               dialog_window.DrawTitleText(pFontArrus, 0, v115, pWhiteColor, v6, 3);
               return;
@@ -955,7 +955,7 @@
       v116 = &pPlayers[uActiveCharacter]->pInventoryItemList[v33 - 1];
       v35 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(&pPlayers[uActiveCharacter]->pInventoryItemList[v32 - 1], BildingType_ArmorShop, window_SpeakInHouse->par1C, 5);
       v15 = (char *)pMerchantsRepairPhrases[v35];
-      v36 = BuilDialogueString(v15, uActiveCharacter - 1, v116, (char *)window_SpeakInHouse->ptr_1C, 5, 0);
+      v36 = BuildDialogueString(v15, uActiveCharacter - 1, v116, (char *)window_SpeakInHouse->ptr_1C, 5, 0);
       v115 = (174 - pFontArrus->CalcTextHeight(v36, &dialog_window, 0, 0)) / 2 + 138;
       dialog_window.DrawTitleText(pFontArrus, 0, v115, pWhiteColor, v36, 3);
       return;
@@ -982,7 +982,7 @@
           v97 = uActiveCharacter - 1;
       __debugbreak(); // warning C4700: uninitialized local variable 'v98' used
           v99 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(&pParty->SpecialItemsInShops[window_SpeakInHouse->par1C][v95-1], BildingType_ArmorShop,	window_SpeakInHouse->par1C,	2);
-          v100 = BuilDialogueString((char *)pMerchantsBuyPhrases[v99], uActiveCharacter - 1, v98, (char *)window_SpeakInHouse->par1C, 2, 0);
+          v100 = BuildDialogueString((char *)pMerchantsBuyPhrases[v99], uActiveCharacter - 1, v98, (char *)window_SpeakInHouse->par1C, 2, 0);
           v103 = pFontArrus->CalcTextHeight(v100, &dialog_window, 0, 0);
           dialog_window.DrawTitleText(pFontArrus, 0, (174 - v103) / 2 + 138, pWhiteColor, v100, 3);
         }
@@ -1371,7 +1371,7 @@
           {
             v38 = pGlobalTXT_LocalizationStrings[181];
           }
-          v21 = BuilDialogueString(v38, uActiveCharacter - 1, v70, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+          v21 = BuildDialogueString(v38, uActiveCharacter - 1, v70, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
           v40 = pFontArrus->CalcTextHeight(v21, &dialog_window, 0, 0);
           dialog_window.DrawTitleText(pFontArrus, 0, (174 - v40) / 2 + 138, pColorWhite, v21, 3);
           return ;
@@ -1392,7 +1392,7 @@
           return;
       v87 = (ItemGen *)&pPlayer->pInventoryItemList[pNumActiveItem - 1];
       v45 = pPlayer->SelectPhrasesTransaction(v87, BildingType_AlchemistShop, (int)window_SpeakInHouse->ptr_1C, 3);
-      v21 = BuilDialogueString((char *)pMerchantsSellPhrases[v45], uActiveCharacter - 1, v87, (char *)window_SpeakInHouse->ptr_1C, 3, 0);
+      v21 = BuildDialogueString((char *)pMerchantsSellPhrases[v45], uActiveCharacter - 1, v87, (char *)window_SpeakInHouse->ptr_1C, 3, 0);
       pTextHeight = pFontArrus->CalcTextHeight(v21, &dialog_window, 0, 0);
       dialog_window.DrawTitleText(pFontArrus, 0, (174 - pTextHeight) / 2 + 138, pColorWhite, v21, 3);
       return; 
@@ -1418,7 +1418,7 @@
       {
         v38 = "%24";
       }
-      v21 = BuilDialogueString(v38, uActiveCharacter - 1, v37, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
+      v21 = BuildDialogueString(v38, uActiveCharacter - 1, v37, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
       v40 = pFontArrus->CalcTextHeight(v21, &dialog_window, 0, 0);
       dialog_window.DrawTitleText(pFontArrus, 0, (174 - v40) / 2 + 138, pColorWhite, v21, 3);
       return;
@@ -1574,7 +1574,7 @@
           {
             v38 = pGlobalTXT_LocalizationStrings[181];
           }
-          v21 = BuilDialogueString(v38, uActiveCharacter - 1, v70, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+          v21 = BuildDialogueString(v38, uActiveCharacter - 1, v70, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
           v40 = pFontArrus->CalcTextHeight(v21, &dialog_window, 0, 0);
           dialog_window.DrawTitleText(pFontArrus, 0, (174 - v40) / 2 + 138, pColorWhite, v21, 3);
           return;
@@ -1950,7 +1950,7 @@
           v75 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(item, BildingType_MagicShop, (int)window_SpeakInHouse->ptr_1C, 2);
           v10 = (char *)pMerchantsBuyPhrases[v75];
         }
-        v30 = BuilDialogueString(v10, uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+        v30 = BuildDialogueString(v10, uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
         v6 = (174 - pFontArrus->CalcTextHeight(v30, &dialog_window, v3, v3)) / 2 + 138;
         dialog_window.DrawTitleText(pFontArrus, v3, v6, pWhiteColor, v30, 3);
         return;
@@ -2081,7 +2081,7 @@
           v75 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(item, BildingType_MagicShop, (int)window_SpeakInHouse->ptr_1C, 2);
           v10 = (char *)pMerchantsBuyPhrases[v75];
         }
-        v30 = BuilDialogueString(v10, uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
+        v30 = BuildDialogueString(v10, uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 2, 0);
         v6 = (174 - pFontArrus->CalcTextHeight(v30, &dialog_window, v3, v3)) / 2 + 138;
         dialog_window.DrawTitleText(pFontArrus, v3, v6, pWhiteColor, v30, 3);
         return;
@@ -2143,7 +2143,7 @@
       return;
     item = &pPlayers[uActiveCharacter]->pInventoryItemList[result - 1];
     v13 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(item, BildingType_MagicShop, (int)window_SpeakInHouse->ptr_1C, 3);
-    v30 = BuilDialogueString((char *)pMerchantsSellPhrases[v13], uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 3, 0);
+    v30 = BuildDialogueString((char *)pMerchantsSellPhrases[v13], uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 3, 0);
     v6 = (174 - pFontArrus->CalcTextHeight(v30, &dialog_window, v3, v3)) / 2 + 138;
     dialog_window.DrawTitleText(pFontArrus, v3, v6, pWhiteColor, v30, 3);
     return;
@@ -2169,13 +2169,13 @@
             item = &pPlayers[uActiveCharacter]->pInventoryItemList[result-1];
             if ( item->uAttributes & 1 )
             {
-              v5 = BuilDialogueString("%24", uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
+              v5 = BuildDialogueString("%24", uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
               v6 = (212 - pFontArrus->CalcTextHeight(v5, &dialog_window, 0, 0)) / 2 + 101;
               dialog_window.DrawTitleText(pFontArrus, 0, v6, pWhiteColor, v5, 3); 
               return;
             }
             v8 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(item, BildingType_MagicShop, (int)window_SpeakInHouse->ptr_1C, 4);
-            v30 = BuilDialogueString((char *)pMerchantsIdentifyPhrases[v8], uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
+            v30 = BuildDialogueString((char *)pMerchantsIdentifyPhrases[v8], uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 4, 0);
             v6 = (174 - pFontArrus->CalcTextHeight(v30, &dialog_window, 0, 0)) / 2 + 138;
             dialog_window.DrawTitleText(pFontArrus, 0, v6, pWhiteColor, v30, 3);
             return;
@@ -2202,7 +2202,7 @@
       return;
     item = &pPlayers[uActiveCharacter]->pInventoryItemList[result - 1];
     v29 = pPlayers[uActiveCharacter]->SelectPhrasesTransaction(&pPlayers[uActiveCharacter]->pInventoryItemList[result - 1], BildingType_MagicShop, (int)window_SpeakInHouse->ptr_1C, 5);
-    v30 = BuilDialogueString((char *)pMerchantsRepairPhrases[v29], uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 5, 0);
+    v30 = BuildDialogueString((char *)pMerchantsRepairPhrases[v29], uActiveCharacter - 1, item, (char *)window_SpeakInHouse->ptr_1C, 5, 0);
     v6 = (174 - pFontArrus->CalcTextHeight(v30, &dialog_window, v3, v3)) / 2 + 138;
     dialog_window.DrawTitleText(pFontArrus, v3, v6, pWhiteColor, v30, 3);
     return;
--- a/UI/UiGame.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/UI/UiGame.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -287,7 +287,7 @@
         a1.DrawTitleText(pFontArrus, 0, 0xCu, v13, v11, 3u);
         a1.uFrameWidth -= 24;
         a1.uFrameZ = a1.uFrameX + a1.uFrameWidth - 1;
-        v14 = BuilDialogueString((char *)lpsz, uActiveCharacter - 1, 0, 0, 0, 0);
+        v14 = BuildDialogueString((char *)lpsz, uActiveCharacter - 1, 0, 0, 0, 0);
         a1.DrawText(pFontArrus, 100, 36, 0, v14, 0, 0, 0);
       }
     }
@@ -481,7 +481,7 @@
   switch (uDialogueType)
   {
     case DIALOGUE_13:
-      pInString = BuilDialogueString(pNPCStats->pProfessions[pNPC->uProfession - 1].pJoinText, uActiveCharacter - 1, 0, 0, 0, 0);
+      pInString = BuildDialogueString(pNPCStats->pProfessions[pNPC->uProfession - 1].pJoinText, uActiveCharacter - 1, 0, 0, 0, 0);
     break;
 
     case DIALOGUE_PROFESSION_DETAILS:
@@ -489,11 +489,11 @@
       auto prof = pNPCStats->pProfessions + pNPC->uProfession - 1;
 
       if (dialogue_show_profession_details)
-        pInString = BuilDialogueString(prof->pBenefits, uActiveCharacter - 1, 0, 0, 0, 0);
+        pInString = BuildDialogueString(prof->pBenefits, uActiveCharacter - 1, 0, 0, 0, 0);
       else if (pNPC->Hired())
-        pInString = BuilDialogueString(prof->pDismissText, uActiveCharacter - 1, 0, 0, 0, 0);
+        pInString = BuildDialogueString(prof->pDismissText, uActiveCharacter - 1, 0, 0, 0, 0);
       else
-        pInString = BuilDialogueString(prof->pJoinText, uActiveCharacter - 1, 0, 0, 0, 0);
+        pInString = BuildDialogueString(prof->pJoinText, uActiveCharacter - 1, 0, 0, 0, 0);
     }
     break;
 
@@ -535,9 +535,9 @@
         auto prof = pNPCStats->pProfessions + pNPC->uProfession - 1;
 
         if (pNPC->Hired())
-          pInString = BuilDialogueString(prof->pDismissText, uActiveCharacter - 1, 0, 0, 0, 0);
+          pInString = BuildDialogueString(prof->pDismissText, uActiveCharacter - 1, 0, 0, 0, 0);
         else
-          pInString = BuilDialogueString(prof->pJoinText, uActiveCharacter - 1, 0, 0, 0, 0);
+          pInString = BuildDialogueString(prof->pJoinText, uActiveCharacter - 1, 0, 0, 0, 0);
       }
     break;
   }
--- a/_deleted.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/_deleted.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -1677,6 +1677,104 @@
   return result;
 }
 
+//----- (0047BC6F) --------------------------------------------------------
+unsigned __int16 *__fastcall sr_GetBillboardPalette(RenderBillboard *a1, int a2, signed int a3, int a4)
+{
+  int v4; // ebx@1
+  int v6; // edx@4
+  int v7; // ecx@5
+  signed int v8; // eax@6
+  signed __int64 v9; // qtt@11
+  signed int v10; // eax@12
+  int v11; // esi@17
+  signed __int64 v12; // qtt@19
+  double v13; // ST10_8@19
+  int v14; // edi@25
+  signed int v15; // edx@26
+  signed __int64 v16; // qtt@29
+  signed int v17; // eax@30
+  int v18; // [sp+10h] [bp-8h]@1
+  float a3a; // [sp+20h] [bp+8h]@19
+
+  v4 = a2;
+  v18 = a2;
+  if ( pParty->armageddon_timer )
+    return PaletteManager::Get(a2);
+  if ( !pWeather->bNight )
+  {
+    if (day_attrib & DAY_ATTRIB_FOG)
+    {
+      v14 = day_fogrange_1 << 16;
+      if ( a3 >= day_fogrange_1 << 16 )
+      {
+        if ( a3 <= day_fogrange_2 << 16 )
+        {
+          LODWORD(v16) = (a3 - v14) << 16;
+          HIDWORD(v16) = (a3 - v14) >> 16;
+          v15 = (unsigned __int64)(27 * v16 / ((day_fogrange_2 - day_fogrange_1) << 16)) >> 16;
+        }
+        else
+        {
+          v15 = 27;
+        }
+      }
+      else
+      {
+        v15 = 0;
+      }
+      v17 = _43F55F_get_billboard_light_level(a1, v15);
+      if ( v17 > 27 )
+        v17 = 27;
+      if ( !a3 )
+        v17 = 27;
+      v7 = v18;
+      v6 = v17;
+      return (unsigned __int16 *)PaletteManager::Get_Mist_or_Red_LUT(v7, v6, 1);
+    }
+    v11 = a4;
+    if ( a4 < 0 )
+      v11 = 0;
+    LODWORD(v12) = a3 << 16;
+    HIDWORD(v12) = a3 >> 16;
+    a3a = (double)(signed int)(((unsigned __int64)(11 * v12 / (pOutdoorCamera->shading_dist_shade << 16)) >> 16) + 20)
+        * pOutdoor->fFogDensity;
+    v13 = a3a + 6.7553994e15;
+    v10 = _43F55F_get_billboard_light_level(a1, LODWORD(v13) + v11);
+    if ( v10 > 27 )
+      v10 = 27;
+    if ( v10 < a4 )
+      v10 = a4;
+    if ( v10 > pOutdoor->max_terrain_dimming_level )
+      v10 = pOutdoor->max_terrain_dimming_level;
+    return PaletteManager::Get_Dark_or_Red_LUT(v4, v10, 1);
+  }
+  v6 = 0;
+  if (pWeather->bNight)
+  {
+    v8 = 67108864;
+    if ( (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_TORCHLIGHT].uExpireTime > 0 )
+      v8 = pParty->pPartyBuffs[PARTY_BUFF_TORCHLIGHT].uPower << 26;
+    if ( a3 <= v8 )
+    {
+      if ( a3 > 0 )
+      {
+        LODWORD(v9) = a3 << 16;
+        HIDWORD(v9) = a3 >> 16;
+        v6 = (unsigned __int64)(27 * v9 / v8) >> 16;
+      }
+    }
+    else
+    {
+      v6 = 27;
+    }
+    v10 = _43F55F_get_billboard_light_level(a1, v6);
+    if ( v10 > 27 || !a3 )
+      v10 = 27;
+    return PaletteManager::Get_Dark_or_Red_LUT(v4, v10, 1);
+  }
+  v7 = 0;
+  return (unsigned __int16 *)PaletteManager::Get_Mist_or_Red_LUT(v7, v6, 1);
+}
 //----- (00487389) --------------------------------------------------------
 void Render::ExecOutdoorDrawSW()
 {
@@ -3649,6 +3747,87 @@
   return result;
 }
 
+//----- (0047F4D3) --------------------------------------------------------
+void __fastcall _47F4D3_initialize_terrain_bezier_stuff(int band1, int band2, int band3)
+{
+  int v3; // edi@1
+  //stru220 *v4; // esi@1
+  double v5; // ST2C_8@3
+  double v6; // st7@3
+  //double v7; // [sp+18h] [bp-28h]@3
+  //double v8; // [sp+20h] [bp-20h]@2
+  int v9; // [sp+34h] [bp-Ch]@1
+  int v10; // [sp+38h] [bp-8h]@1
+  //signed int band3a; // [sp+48h] [bp+8h]@2
+
+  v9 = band2 * 512;
+  pOutdoorCamera->outdoor_grid_band_3 = band3;
+  v10 = band1 * 512;
+  v3 = band3 * 512;
+  pOutdoorCamera->uPickDepth = band3 * 512;
+  //v4 = terrain_76E5C8;                             // v4:  0 -> 65536
+  for (uint i = 0; i < 16384; ++i)
+  //do
+  {
+    auto v4 = terrain_76E5C8[i];
+    //band3a = 256;
+    //v8 = (double)(signed int)((char *)v4 + 256 - (int)terrain_76E5C8);
+    for (uint j = 0; j < 128; ++j)                  // band3a: 0 -> 128
+    {
+      v5 = pow(j * 512 + 256, 2.0);
+      v6 = pow(i * 4 + 256, 2.0);
+      //*((float *)&v5 + 1) = sqrt(v6 + v5);
+      int v7 = floorf(sqrtf(v5 + v6) + 0.5f);//*((float *)&v5 + 1) + 6.7553994e15;
+      if (v7 >= v10)
+      {
+        if (v7 >= v9)
+          v4.field_0 = ((v7 >= v3) - 1) & 2;
+        else
+          v4.field_0 = 2;
+      }
+      else
+      {
+        v4.field_0 = 1;
+      }
+      //band3a += 512;
+      v4.distance = v7;
+      //++v4;
+    }
+    //while ( band3a < 65792 );
+  }
+  //while ( (signed int)v4 < (signed int)arary_77E5C8 );
+}
+
+//----- (00481EFA) --------------------------------------------------------
+bool __fastcall _481EFA_clip_terrain_poly(RenderVertexSoft *a1, RenderVertexSoft *a2, RenderVertexSoft *a3, RenderVertexSoft *a4, int a5)
+{
+  RenderVertexSoft *v5; // esi@1
+  RenderVertexSoft *v6; // edx@1
+  bool v7; // edi@2
+  bool v8; // ecx@5
+  bool v9; // esi@8
+  bool v10; // eax@11
+  double v11; // st7@14
+  signed int v12; // esi@15
+  signed int v13; // edx@18
+  signed int v14; // ecx@21
+  signed int v15; // eax@24
+  RenderVertexSoft *v17; // [sp+Ch] [bp-8h]@1
+
+  v5 = a2;
+  v6 = a1;
+  v17 = v5;
+  v7 = a1->vWorldViewPosition.x < 8.0;
+  v8 = v5->vWorldViewPosition.x < 8.0;
+  v9 = a3->vWorldViewPosition.x < 8.0;
+  v10 = a4->vWorldViewPosition.x < 8.0;
+  return !(v8 & v9 & v10 & v7)
+      && ((v11 = (double)pOutdoorCamera->shading_dist_mist, v11 > v6->vWorldViewPosition.x) ? (v12 = 0) : (v12 = 1),
+          v11 > v17->vWorldViewPosition.x ? (v13 = 0) : (v13 = 1),
+          v11 > a3->vWorldViewPosition.x ? (v14 = 0) : (v14 = 1),
+          v11 > a4->vWorldViewPosition.x ? (v15 = 0) : (v15 = 1),
+          !(v13 & v14 & v15 & v12));
+}
 //----- (00481212) --------------------------------------------------------
 void Render::DrawTerrainSW(int a1, int a2, int a3, int a4)
 {
@@ -3779,7 +3958,7 @@
       v7 = abs(X);
       v8 = abs(v86);
       --X;
-      v92 = &stru_76E5C8[(v7 << 7) + v8];
+      v92 = &terrain_76E5C8[(v7 << 7) + v8];
       if ( !v92->field_0
         || ((v9 = v6, v10 = &pVerticesSR_806210[v6], v104 = v10, !v85) ? (v11 = &pVerticesSR_801A10[v9],
                                                                           v12 = &pVerticesSR_806210[v9 + 1]) : (v11 = &pVerticesSR_806210[v9 + 1], v12 = &pVerticesSR_801A10[v9]),
@@ -3807,7 +3986,7 @@
               WorldPosToGridCellZ(v100),
               !byte_4D864C)
           || !(pGame->uFlags & 0x80))
-         && !sub_481EFA(v10, v11, v102, v103, 1)) )
+         && !_481EFA_clip_terrain_poly(v10, v11, v102, v103, 1)) )
         goto LABEL_105;
       if ( v10->vWorldPosition.z != v11->vWorldPosition.z
         || v11->vWorldPosition.z != v103->vWorldPosition.z
@@ -3851,7 +4030,7 @@
         if ( pOutdoorCamera->uNumPolygons >= 1999 )
           return;
         ++pOutdoorCamera->uNumPolygons;
-        if ( !sub_481FC9(v10, (RenderVertexSoft *)HIDWORD(v101), v102, v17) )
+        if ( !_481FC9_terrain(v10, (RenderVertexSoft *)HIDWORD(v101), v102, v17) )
           goto LABEL_104;
         v26 = 1.0 / (v104->vWorldViewPosition.x + 0.0000001);
         memcpy(array_50AC10, v104, 0x30u);
@@ -3972,7 +4151,7 @@
     if ( pOutdoorCamera->uNumPolygons >= 1999 )
       return;
     ++pOutdoorCamera->uNumPolygons;
-    if ( !sub_481FC9((RenderVertexSoft *)HIDWORD(v101), v103, v104, v38) )
+    if ( !_481FC9_terrain((RenderVertexSoft *)HIDWORD(v101), v103, v104, v38) )
       goto LABEL_74;
     v48 = 1.0 / (v104->vWorldViewPosition.x + 0.0000001);
     memcpy(array_50AC10, v104, 0x30u);
@@ -4062,7 +4241,7 @@
           if ( pOutdoorCamera->uNumPolygons >= 1999 )
             return;
           ++pOutdoorCamera->uNumPolygons;
-          if ( !sub_481FC9(v102, v104, v103, v17) )
+          if ( !_481FC9_terrain(v102, v104, v103, v17) )
           {
 LABEL_104:
             --pOutdoorCamera->uNumPolygons;
@@ -4147,12 +4326,43 @@
   }
 }
 
+//----- (00481FC9) --------------------------------------------------------
+int __fastcall _481FC9_terrain(RenderVertexSoft *a1, RenderVertexSoft *a2, RenderVertexSoft *a3, struct Polygon *a4)//Rotate camera
+{
+  float arg_0, arg_4, var_4, var_8, var_c, var_10, var_14;
+
+  if (a1->vWorldPosition.y == a2->vWorldPosition.y && a2->vWorldPosition.y == a3->vWorldPosition.y)
+    a4->flags |= 0x10;
+  var_c = a1->vWorldViewPosition.x - a2->vWorldViewPosition.x;
+  var_14 = a1->vWorldViewPosition.y - a2->vWorldViewPosition.y;
+  arg_0 = a1->vWorldViewPosition.z - a2->vWorldViewPosition.z;
+  var_10 = a3->vWorldViewPosition.x - a2->vWorldViewPosition.x;
+  var_8 = a3->vWorldViewPosition.y - a2->vWorldViewPosition.y;
+  var_4 = a3->vWorldViewPosition.z - a2->vWorldViewPosition.z;
+  arg_4 = a3->vWorldPosition.y - a2->vWorldPosition.y;
+  if (((a3->vWorldPosition.y - a2->vWorldPosition.y) * (a1->vWorldPosition.x - a2->vWorldPosition.x) - (a3->vWorldPosition.x - a2->vWorldPosition.x) * (a1->vWorldPosition.y - a2->vWorldPosition.y)) * (pIndoorCamera->pos.y - a2->vWorldPosition.z) +
+      ((a3->vWorldPosition.z - a2->vWorldPosition.z) * (a1->vWorldPosition.y - a2->vWorldPosition.y) - (a3->vWorldPosition.y - a2->vWorldPosition.y) * (a1->vWorldPosition.z - a2->vWorldPosition.z)) * (pIndoorCamera->pos.x - a2->vWorldPosition.x) +
+      ((a3->vWorldPosition.x - a2->vWorldPosition.x) * (a1->vWorldPosition.z - a2->vWorldPosition.z) - (a3->vWorldPosition.z - a2->vWorldPosition.z) * (a1->vWorldPosition.x - a2->vWorldPosition.x)) * (pIndoorCamera->pos.z - a2->vWorldPosition.y) < 0)
+  {
+   arg_4 = var_4 * var_14 - var_8 * arg_0;
+   a4->v_18.x = floorf(arg_4 + 0.5f);
+   arg_4 = var_10 * arg_0 - var_4 * var_c;
+   a4->v_18.y = floorf(arg_4 + 0.5f);
+   arg_4 = var_8 * var_c - var_10 * var_14;
+   a4->v_18.z = floorf(arg_4 + 0.5f);
+   a4->_normalize_v_18();
+   arg_4 = -(a4->v_18.x * a2->vWorldViewPosition.x) - a4->v_18.y * a2->vWorldViewPosition.y - a4->v_18.z * a2->vWorldViewPosition.z;
+   a4->field_24 = floorf(arg_4 + 0.5f);
+   return true;
+  }
+  else
+    return false;
+}
 //----- (00438250) --------------------------------------------------------
 void IndoorCameraD3D::sr_Reset_list_0037C()
 {
   this->list_0037C_size = 0;
 }
-
 //----- (00438240) --------------------------------------------------------
 void IndoorCameraD3D::sr_438240_draw_lits()
 {
--- a/mm7_2.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/mm7_2.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -5367,7 +5367,7 @@
   assert(sizeof(IndoorCamera) == 0x50);
   assert(sizeof(Bloodsplat) == 0x28);
   assert(sizeof(BloodsplatContainer) == 0xA0C);
-  assert(sizeof(stru167) == 0x18);
+  assert(sizeof(TrailParticle) == 0x18);
   assert(sizeof(EventIndex) == 0xC);
   assert(sizeof(_2devent) == 0x34);
   assert(sizeof(stru176) == 0x20);
@@ -5775,7 +5775,7 @@
       outdoor_grid_band_2 = 15;
       outdoor_grid_band_3 = 20;
       pOutdoorCamera->shading_dist_mist = 8192;
-      pOutdoorCamera->bNoSky = 0;
+      pOutdoorCamera->bNoSky = false;
       LOBYTE(viewparams->field_20) = 0;
     }
     mipmapping_terrain_mm1 = 1024;
@@ -5789,7 +5789,11 @@
     mipmapping_building_mm3 = 4096;
     pOutdoorCamera->shading_dist_shademist = 4096;
     pOutdoorCamera->outdoor_no_wavy_water = 0;
-    sub_47F4D3(outdoor_grid_band_1, outdoor_grid_band_2, outdoor_grid_band_3);
+    //_47F4D3_initialize_terrain_bezier_stuff(outdoor_grid_band_1, outdoor_grid_band_2, outdoor_grid_band_3);
+    {
+      pOutdoorCamera->outdoor_grid_band_3 = outdoor_grid_band_3;
+      pOutdoorCamera->uPickDepth = outdoor_grid_band_3 * 512;
+    }
   }
   else
   {
@@ -7227,8 +7231,8 @@
     v2->uSpriteFrameID = 0;
     v147 = v38;
     stru_50FE08.Add(v38, 512, v40, v39, v37, 0, 0);
-    if ( HIBYTE(v3->uFlags) & 1 )
-      array_5118E8._440E91(v2->vPosition.x, v2->vPosition.y, v2->vPosition.z, 0, v3->uParticleTrailColor);
+    if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
+      trail_particle_generator.GenerateTrailParticles(v2->vPosition.x, v2->vPosition.y, v2->vPosition.z, v3->uParticleTrailColor);
     v133 = 0;
     v131 = 0;
     v130 = 0;
@@ -7285,12 +7289,11 @@
         v2->vVelocity.z = v32;
         v149 = v102;
         stru_50FE08.Add(v102, 512, v104, v103, v101, v100, v32);
-        if ( HIBYTE(v3->uFlags) & 1 )
-          array_5118E8._440E91(
+        if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
+          trail_particle_generator.GenerateTrailParticles(
             v2->vPosition.x,
             v2->vPosition.y,
             v2->vPosition.z,
-            v32,
             v3->uParticleTrailColor);
         v105 = v2->uSoundID;
         if ( v105 == (short)v32 )
--- a/mm7_3.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/mm7_3.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -42,7 +42,6 @@
 #include "Time.h"
 #include "IconFrameTable.h"
 #include "TurnEngine.h"
-#include "stru220.h"
 #include "Events2D.h"
 #include "stru176.h"
 #include "stru298.h"
@@ -5611,8 +5610,8 @@
   //int v5; // eax@8
   //SpawnPointMM7 *v6; // edx@14
   size_t v7; // eax@19
-  char *v8; // eax@19
-  char *v9; // eax@21
+  //char *v8; // eax@19
+  //char *v9; // eax@21
   char Source[120]; // [sp+Ch] [bp-84h]@19
   const char *pFilename; // [sp+84h] [bp-Ch]@1
   //unsigned int v12; // [sp+88h] [bp-8h]@12
@@ -5621,7 +5620,7 @@
   pFilename = pLevelFilename;
   thisa->AllocSoftwareDrawBuffers();
   pOutdoorCamera->_485F64();
-  pWeather->bRenderSnow = 0;
+  pWeather->bRenderSnow = false;
   pRenderer->ClearZBuffer(0, 479);
   thisa = (OutdoorCamera *)1;
   GetAlertStatus();
@@ -5691,22 +5690,16 @@
   pOutdoor->UpdateSunlightVectors();
   pOutdoorCamera->int_fov_rad = (signed __int64)pIndoorCamera->flt_1C_fov;
   pOutdoorCamera->int_fov_rad_inv = (signed __int64)pIndoorCamera->flt_20_inv_1C;
-  v8 = (char *)&array_77EC08[0].ptr_38;
-  do
-  {
-    *(int *)v8 = (int)&stru_8019C8;
-    v8 += 268;
-  }
-  while ( (signed int)v8 < (signed int)&unk_801A00 );
-  v9 = (char *)&array_77EC08[0].prolly_tail;
-  do
-  {
-    *((int *)v9 - 1) = 0;
-    *(int *)v9 = 0;
-    *((int *)v9 - 5) = 0;
-    v9 += 268;
-  }
-  while ( (signed int)v9 < (signed int)&unk_801A0C );
+
+  for (int i = 0; i < 20000; ++i)
+  {
+    array_77EC08[i].ptr_38 = &stru_8019C8;
+    
+    array_77EC08[i].prolly_head = nullptr;
+    array_77EC08[i].prolly_tail = nullptr;
+    array_77EC08[i].ptr_48 = nullptr;
+  }
+
   MM7Initialization();
 }
 
@@ -5748,139 +5741,33 @@
   return v1;
 }
 
-//----- (0047BC6F) --------------------------------------------------------
-unsigned __int16 *__fastcall GetBillboardPalette(RenderBillboard *a1, int a2, signed int a3, int a4)
-{
-  int v4; // ebx@1
-  int v6; // edx@4
-  int v7; // ecx@5
-  signed int v8; // eax@6
-  signed __int64 v9; // qtt@11
-  signed int v10; // eax@12
-  int v11; // esi@17
-  signed __int64 v12; // qtt@19
-  double v13; // ST10_8@19
-  int v14; // edi@25
-  signed int v15; // edx@26
-  signed __int64 v16; // qtt@29
-  signed int v17; // eax@30
-  int v18; // [sp+10h] [bp-8h]@1
-  float a3a; // [sp+20h] [bp+8h]@19
-
-  v4 = a2;
-  v18 = a2;
-  if ( pParty->armageddon_timer )
-    return PaletteManager::Get(a2);
-  if ( !pWeather->bNight )
-  {
-    if (day_attrib & DAY_ATTRIB_FOG)
-    {
-      v14 = day_fogrange_1 << 16;
-      if ( a3 >= day_fogrange_1 << 16 )
-      {
-        if ( a3 <= day_fogrange_2 << 16 )
-        {
-          LODWORD(v16) = (a3 - v14) << 16;
-          HIDWORD(v16) = (a3 - v14) >> 16;
-          v15 = (unsigned __int64)(27 * v16 / ((day_fogrange_2 - day_fogrange_1) << 16)) >> 16;
-        }
-        else
-        {
-          v15 = 27;
-        }
-      }
-      else
-      {
-        v15 = 0;
-      }
-      v17 = _43F55F_get_billboard_light_level(a1, v15);
-      if ( v17 > 27 )
-        v17 = 27;
-      if ( !a3 )
-        v17 = 27;
-      v7 = v18;
-      v6 = v17;
-      return (unsigned __int16 *)PaletteManager::Get_Mist_or_Red_LUT(v7, v6, 1);
-    }
-    v11 = a4;
-    if ( a4 < 0 )
-      v11 = 0;
-    LODWORD(v12) = a3 << 16;
-    HIDWORD(v12) = a3 >> 16;
-    a3a = (double)(signed int)(((unsigned __int64)(11 * v12 / (pOutdoorCamera->shading_dist_shade << 16)) >> 16) + 20)
-        * pOutdoor->fFogDensity;
-    v13 = a3a + 6.7553994e15;
-    v10 = _43F55F_get_billboard_light_level(a1, LODWORD(v13) + v11);
-    if ( v10 > 27 )
-      v10 = 27;
-    if ( v10 < a4 )
-      v10 = a4;
-    if ( v10 > pOutdoor->max_terrain_dimming_level )
-      v10 = pOutdoor->max_terrain_dimming_level;
-    return PaletteManager::Get_Dark_or_Red_LUT(v4, v10, 1);
-  }
-  v6 = 0;
-  if (pWeather->bNight)
-  {
-    v8 = 67108864;
-    if ( (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_TORCHLIGHT].uExpireTime > 0 )
-      v8 = pParty->pPartyBuffs[PARTY_BUFF_TORCHLIGHT].uPower << 26;
-    if ( a3 <= v8 )
-    {
-      if ( a3 > 0 )
-      {
-        LODWORD(v9) = a3 << 16;
-        HIDWORD(v9) = a3 >> 16;
-        v6 = (unsigned __int64)(27 * v9 / v8) >> 16;
-      }
-    }
-    else
-    {
-      v6 = 27;
-    }
-    v10 = _43F55F_get_billboard_light_level(a1, v6);
-    if ( v10 > 27 || !a3 )
-      v10 = 27;
-    return PaletteManager::Get_Dark_or_Red_LUT(v4, v10, 1);
-  }
-  v7 = 0;
-  return (unsigned __int16 *)PaletteManager::Get_Mist_or_Red_LUT(v7, v6, 1);
-}
 
 //----- (0047C370) --------------------------------------------------------
-unsigned int __cdecl GetLevelFogColor()
+unsigned int GetLevelFogColor()
 {
-  unsigned int result; // eax@2
   signed __int64 v1; // qax@5
   int v2; // eax@6
 
-  if ( bUnderwater )
-  {
-    result = 0xFF258F5C;
-  }
-  else
-  {
-    if (day_attrib & DAY_ATTRIB_FOG)
-    {
+  if (bUnderwater)
+    return 0xFF258F5C;
+
+  if (day_attrib & DAY_ATTRIB_FOG)
+  {
       if ( pWeather->bNight ) // night-time fog
       {
-        __debugbreak(); // decompilation can be inaccurate, please  send savegame to Nomad
+        __debugbreak(); // decompilation can be inaccurate, please send savegame to Nomad
         v2 = -(pWeather->bNight != 1);
-        result = (v2 & 0xE0E0E1) - 0xE0E0E1;
+        return (v2 & 0xE0E0E1) - 0xE0E0E1;
       }
       else
       {
         v1 = (signed __int64)((1.0 - pOutdoor->fFogDensity) * 200.0 + pOutdoor->fFogDensity * 31.0);
-        result = v1 | (((unsigned int)v1 | (((unsigned int)v1 | 0xFFFFFF00) << 8)) << 8);
+        return v1 | (((unsigned int)v1 | (((unsigned int)v1 | 0xFFFFFF00) << 8)) << 8);
       }
-    }
-    else
-      return 0;
-  }
-  return result;
+  }
+
+  return 0;
 }
-// 6BE030: using guessed type int day_attrib;
-// 6BE3C4: using guessed type char bUnderwater;
 
 //----- (0047C3D7) --------------------------------------------------------
 int __fastcall sub_47C3D7_get_fog_related_stuff(int a1, int a2, float a3)
@@ -6112,56 +5999,6 @@
   return (64 - a1) << 9;
 }
 
-//----- (0047F4D3) --------------------------------------------------------
-void __fastcall sub_47F4D3(int band1, int band2, int band3)
-{
-  int v3; // edi@1
-  //stru220 *v4; // esi@1
-  double v5; // ST2C_8@3
-  double v6; // st7@3
-  //double v7; // [sp+18h] [bp-28h]@3
-  //double v8; // [sp+20h] [bp-20h]@2
-  int v9; // [sp+34h] [bp-Ch]@1
-  int v10; // [sp+38h] [bp-8h]@1
-  //signed int band3a; // [sp+48h] [bp+8h]@2
-
-  v9 = band2 * 512;
-  pOutdoorCamera->outdoor_grid_band_3 = band3;
-  v10 = band1 * 512;
-  v3 = band3 * 512;
-  pOutdoorCamera->uPickDepth = band3 * 512;
-  //v4 = stru_76E5C8;                             // v4:  0 -> 65536
-  for (uint i = 0; i < 16384; ++i)
-  //do
-  {
-    auto v4 = stru_76E5C8[i];
-    //band3a = 256;
-    //v8 = (double)(signed int)((char *)v4 + 256 - (int)stru_76E5C8);
-    for (uint j = 0; j < 128; ++j)                  // band3a: 0 -> 128
-    {
-      v5 = pow(j * 512 + 256, 2.0);
-      v6 = pow(i * 4 + 256, 2.0);
-      //*((float *)&v5 + 1) = sqrt(v6 + v5);
-      int v7 = floorf(sqrtf(v5 + v6) + 0.5f);//*((float *)&v5 + 1) + 6.7553994e15;
-      if (v7 >= v10)
-      {
-        if (v7 >= v9)
-          v4.field_0 = ((v7 >= v3) - 1) & 2;
-        else
-          v4.field_0 = 2;
-      }
-      else
-      {
-        v4.field_0 = 1;
-      }
-      //band3a += 512;
-      v4.distance = v7;
-      //++v4;
-    }
-    //while ( band3a < 65792 );
-  }
-  //while ( (signed int)v4 < (signed int)arary_77E5C8 );
-}
 
 //----- (004811A3) --------------------------------------------------------
 void Polygon::DrawBorderTiles()
@@ -6178,24 +6015,15 @@
 
 
 //----- (00481EB7) --------------------------------------------------------
-void __cdecl ResetPolygons()
+void ResetPolygons()
 {
-  int v0; // ecx@1
-  char *v1; // eax@2
-
-  v0 = pOutdoorCamera->uNumPolygons;
-  if ( pOutdoorCamera->uNumPolygons > 0 )
-  {
-    v1 = (char *)&array_77EC08[0].prolly_tail;
-    do
-    {
-      *((int *)v1 - 1) = 0;
-      *(int *)v1 = 0;
-      *((int *)v1 - 5) = 0;
-      v1 += 268;
-      --v0;
-    }
-    while ( v0 );
+  for (auto i = 0; i < pOutdoorCamera->uNumPolygons; ++i)
+  {
+    array_77EC08[i].prolly_head = nullptr;
+    array_77EC08[i].prolly_tail = nullptr;
+
+    array_77EC08[i].flags = 0;
+    array_77EC08[i].field_32 = 0;
   }
 }
 
@@ -6211,70 +6039,6 @@
   pOutdoorCamera->field_44 = 0;
 }
 
-//----- (00481EFA) --------------------------------------------------------
-bool __fastcall sub_481EFA(RenderVertexSoft *a1, RenderVertexSoft *a2, RenderVertexSoft *a3, RenderVertexSoft *a4, int a5)
-{
-  RenderVertexSoft *v5; // esi@1
-  RenderVertexSoft *v6; // edx@1
-  bool v7; // edi@2
-  bool v8; // ecx@5
-  bool v9; // esi@8
-  bool v10; // eax@11
-  double v11; // st7@14
-  signed int v12; // esi@15
-  signed int v13; // edx@18
-  signed int v14; // ecx@21
-  signed int v15; // eax@24
-  RenderVertexSoft *v17; // [sp+Ch] [bp-8h]@1
-
-  v5 = a2;
-  v6 = a1;
-  v17 = v5;
-  v7 = a1->vWorldViewPosition.x < 8.0;
-  v8 = v5->vWorldViewPosition.x < 8.0;
-  v9 = a3->vWorldViewPosition.x < 8.0;
-  v10 = a4->vWorldViewPosition.x < 8.0;
-  return !(v8 & v9 & v10 & v7)
-      && ((v11 = (double)pOutdoorCamera->shading_dist_mist, v11 > v6->vWorldViewPosition.x) ? (v12 = 0) : (v12 = 1),
-          v11 > v17->vWorldViewPosition.x ? (v13 = 0) : (v13 = 1),
-          v11 > a3->vWorldViewPosition.x ? (v14 = 0) : (v14 = 1),
-          v11 > a4->vWorldViewPosition.x ? (v15 = 0) : (v15 = 1),
-          !(v13 & v14 & v15 & v12));
-}
-
-//----- (00481FC9) --------------------------------------------------------
-int __fastcall sub_481FC9(RenderVertexSoft *a1, RenderVertexSoft *a2, RenderVertexSoft *a3, struct Polygon *a4)//Rotate camera
-{
-  float arg_0, arg_4, var_4, var_8, var_c, var_10, var_14;
-
-  if (a1->vWorldPosition.y == a2->vWorldPosition.y && a2->vWorldPosition.y == a3->vWorldPosition.y)
-    a4->flags |= 0x10;
-  var_c = a1->vWorldViewPosition.x - a2->vWorldViewPosition.x;
-  var_14 = a1->vWorldViewPosition.y - a2->vWorldViewPosition.y;
-  arg_0 = a1->vWorldViewPosition.z - a2->vWorldViewPosition.z;
-  var_10 = a3->vWorldViewPosition.x - a2->vWorldViewPosition.x;
-  var_8 = a3->vWorldViewPosition.y - a2->vWorldViewPosition.y;
-  var_4 = a3->vWorldViewPosition.z - a2->vWorldViewPosition.z;
-  arg_4 = a3->vWorldPosition.y - a2->vWorldPosition.y;
-  if (((a3->vWorldPosition.y - a2->vWorldPosition.y) * (a1->vWorldPosition.x - a2->vWorldPosition.x) - (a3->vWorldPosition.x - a2->vWorldPosition.x) * (a1->vWorldPosition.y - a2->vWorldPosition.y)) * (pIndoorCamera->pos.y - a2->vWorldPosition.z) +
-      ((a3->vWorldPosition.z - a2->vWorldPosition.z) * (a1->vWorldPosition.y - a2->vWorldPosition.y) - (a3->vWorldPosition.y - a2->vWorldPosition.y) * (a1->vWorldPosition.z - a2->vWorldPosition.z)) * (pIndoorCamera->pos.x - a2->vWorldPosition.x) +
-      ((a3->vWorldPosition.x - a2->vWorldPosition.x) * (a1->vWorldPosition.z - a2->vWorldPosition.z) - (a3->vWorldPosition.z - a2->vWorldPosition.z) * (a1->vWorldPosition.x - a2->vWorldPosition.x)) * (pIndoorCamera->pos.z - a2->vWorldPosition.y) < 0)
-  {
-   arg_4 = var_4 * var_14 - var_8 * arg_0;
-   a4->v_18.x = floorf(arg_4 + 0.5f);
-   arg_4 = var_10 * arg_0 - var_4 * var_c;
-   a4->v_18.y = floorf(arg_4 + 0.5f);
-   arg_4 = var_8 * var_c - var_10 * var_14;
-   a4->v_18.z = floorf(arg_4 + 0.5f);
-   a4->_486089_normalize_v_18();
-   arg_4 = -(a4->v_18.x * a2->vWorldViewPosition.x) - a4->v_18.y * a2->vWorldViewPosition.y - a4->v_18.z * a2->vWorldViewPosition.z;
-   a4->field_24 = floorf(arg_4 + 0.5f);
-   return true;
-  }
-  else
-    return false;
-}
-
 //----- (004823F4) --------------------------------------------------------
 bool IsTerrainSlopeTooHigh(int pos_x, int pos_z)
 {
@@ -6469,50 +6233,28 @@
 }
 
 //----- (00486089) --------------------------------------------------------
-void Polygon::_486089_normalize_v_18()
+void Polygon::_normalize_v_18()
 {
-  //Polygon *v1; // esi@1
   double v2; // st7@1
   double v3; // st6@1
-  float v4; // ST18_4@2
   double v5; // st5@1
-  float v6; // ST14_4@2
-  double v7; // st7@1
-  float v8; // ST24_4@2
-  float v9; // ST20_4@2
-  double v10; // ST0C_8@2
-  float v11; // ST18_4@2
-  double v12; // ST0C_8@2
-  float v13; // ST14_4@2
-  double v14; // ST0C_8@2
-  float v15; // [sp+20h] [bp-8h]@1
 
   //v1 = this;
   v2 = (double)this->v_18.x;
-  v15 = v2;
   v3 = (double)this->v_18.y;
   v5 = (double)this->v_18.z;
-  v7 = sqrt(v5 * v5 + v3 * v3 + v2 * v2);
-  if ( v7 == 0.0 )
-  {
-    this->v_18.x = 0;
-    this->v_18.y = 0;
-    this->v_18.z = 65536;
+  float len = sqrt(v5 * v5 + v3 * v3 + v2 * v2);
+  if (fabsf(len) < 1e-6f)
+  {
+    v_18.x = 0;
+    v_18.y = 0;
+    v_18.z = 65536;
   }
   else
   {
-    v8 = 1.0 / v7;
-    v9 = v8 * v15 * 65536.0;
-    v10 = v9 + 6.7553994e15;
-    this->v_18.x = LODWORD(v10);
-    v4 = v3;
-    v11 = v8 * v4 * 65536.0;
-    v12 = v11 + 6.7553994e15;
-    this->v_18.y = LODWORD(v12);
-    v6 = v5;
-    v13 = v8 * v6 * 65536.0;
-    v14 = v13 + 6.7553994e15;
-    this->v_18.z = LODWORD(v14);
+    v_18.x = round(v2 / len * 65536.0);
+    v_18.y = round(v3 / len * 65536.0);
+    v_18.y = round(v5 / len * 65536.0);
   }
 }
 
@@ -6651,58 +6393,6 @@
   return result;
 }
 
-
-//----- (00440DF5) --------------------------------------------------------
-int stru167_wrap::Push(__int16 a2, __int16 a3, __int16 a4, int a5, __int16 bgr)
-{
-  int result; // eax@1
-
-  pElements[uNumElements].field_6_rnd_value = a2;
-  pElements[uNumElements].field_8_rnd_value = a3;
-  pElements[uNumElements].field_A_rnd_value = a4;
-  pElements[uNumElements].field_C_time_left = rand() % 64 + 256;
-  pElements[uNumElements].field_E_time_to_live = pElements[uNumElements].field_C_time_left;
-  result = 3 * uNumElements;
-  pElements[uNumElements++].bgr16 = bgr;
-  if (uNumElements >= 100 )
-    uNumElements = 0;
-   return result;
-}
-
-//----- (00440E91) --------------------------------------------------------
-void stru167_wrap::_440E91(__int16 x, int y, int z, int a5, __int16 bgr)
-{
-  stru167_wrap *v6; // edi@1
-  int i; // esi@1
-  int v8; // ST08_4@2
-  int v9; // ST04_4@2
-  int v10; // eax@2
-
-  v6 = this;
-  for ( i = 0; i < rand() % 6 + 5; ++i )
-  {
-    v8 = z + rand() % 33;
-    v9 = rand() % 33 + y - 16;
-    v10 = rand();
-    Push(v10 % 33 + x - 16, v9, v8, a5, bgr);
-  }
-}
-
-//----- (00440F07) --------------------------------------------------------
-void stru167_wrap::_440F07()
-{
-  for (uint i = 0; i < 100; ++i)
-  {
-    if (pElements[i].field_C_time_left > 0)
-    {
-      pElements[i].field_A_rnd_value += rand() % 5 + 4;
-      pElements[i].field_6_rnd_value += rand() % 5 - 2;
-      pElements[i].field_8_rnd_value += rand() % 5 - 2;
-      pElements[i].field_C_time_left -= (short)pEventTimer->uTimeElapsed;
-    }
-  }
-}
-
 //----- (0044100D) --------------------------------------------------------
 bool sub_44100D()
 {
--- a/mm7_4.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/mm7_4.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -1902,7 +1902,7 @@
 }
 
 //----- (00495461) --------------------------------------------------------
-char *BuilDialogueString(char *lpsz, unsigned __int8 uPlayerID, ItemGen *a3, char *a4, int a5, __int64 *a6)
+char *BuildDialogueString(char *lpsz, unsigned __int8 uPlayerID, ItemGen *a3, char *a4, int a5, __int64 *a6)
 {
   unsigned __int8 v6; // bl@1
   Player *pPlayer; // ebx@3
--- a/mm7_data.cpp	Fri Jul 26 21:16:51 2013 +0200
+++ b/mm7_data.cpp	Fri Jul 26 22:19:29 2013 +0200
@@ -231,9 +231,6 @@
   0x00000031, 0x00000031, 0x0000002D, 0x00000041
 }};
 
-#include "stru220.h"
-std::array<stru220, 16384> stru_76E5C8;
-
 #include "stru176.h"
 stru176 array_5B5928_timers[100];
 
--- a/mm7_data.h	Fri Jul 26 21:16:51 2013 +0200
+++ b/mm7_data.h	Fri Jul 26 22:19:29 2013 +0200
@@ -1376,21 +1376,17 @@
 void __cdecl loc_47907F(); // idb
 bool __fastcall IsBModelVisible(unsigned int uModelID, int *unused);
 void __thiscall ODM_LoadAndInitialize(const char *pLevelFilename, struct OutdoorCamera *thisa);
-unsigned __int16 *__fastcall GetBillboardPalette(struct RenderBillboard *a1, int a2, signed int a3, int a4);
-unsigned int __cdecl GetLevelFogColor();
+unsigned int GetLevelFogColor();
 int __fastcall sub_47C3D7_get_fog_related_stuff(int a1, int a2, float a3);
 signed int __fastcall GetActorTintColor(int max_dim, int min_dim, float distance, int a4, struct RenderBillboard *a5);
 unsigned int __stdcall WorldPosToGridCellX(int); // weak
 unsigned int __stdcall WorldPosToGridCellZ(int); // weak
 int __stdcall GridCellToWorldPosX(int); // weak
 int __stdcall GridCellToWorldPosZ(int); // weak
-void __fastcall sub_47F4D3(int band1, int band2, int band3);
 void __cdecl loc_48118F(); // idb
 void __cdecl loc_481199(); // idb
-void __cdecl ResetPolygons();
+void ResetPolygons();
 void __cdecl sub_481ED9_MessWithOutdoorCamera();
-bool __fastcall sub_481EFA(RenderVertexSoft *a1, RenderVertexSoft *a2, RenderVertexSoft *a3, RenderVertexSoft *a4, int a5);
-signed int __fastcall sub_481FC9(RenderVertexSoft *_ECX, RenderVertexSoft *a2, RenderVertexSoft *a3, struct Polygon *a4);
 bool IsTerrainSlopeTooHigh(int pos_x, int pos_y);
 int __fastcall GetTerrainHeightsAroundParty2(int a1, int a2, int *a3, int a4);
 signed int __cdecl const_1_0();
@@ -1413,7 +1409,7 @@
 unsigned int __fastcall _494820_training_time(unsigned int a1);
 char *__fastcall sub_495366(unsigned __int8 a1, unsigned __int8 a2);
 char *GetReputationString(signed int a1);
-char *BuilDialogueString(char *lpsz, unsigned __int8 uPlayerID, struct ItemGen *a3, char *a4, int a5, __int64 *a6);
+char *BuildDialogueString(char *lpsz, unsigned __int8 uPlayerID, struct ItemGen *a3, char *a4, int a5, __int64 *a6);
 void PlayerCreationUI_Draw();
 void PlayerCreationUI_Initialize();
 void DeleteCCharFont();
--- a/stru220.h	Fri Jul 26 21:16:51 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-#pragma once
-
-
-
-/*  210 */
-#pragma pack(push, 1)
-struct stru220
-{
-  __int16 field_0;//char field_0;
-  //char field_1;
-  __int16 distance;
-};
-#pragma pack(pop)
-extern std::array<stru220, 16384> stru_76E5C8;
\ No newline at end of file