changeset 2247:529bf95fb0d7

Merge
author Grumpy7
date Wed, 26 Feb 2014 01:15:58 +0100
parents 0be4f17b7986 (current diff) 8817c398b792 (diff)
children 8c5855b842dc
files mm7_4.cpp
diffstat 23 files changed, 1315 insertions(+), 1625 deletions(-) [+]
line wrap: on
line diff
--- a/CastSpellInfo.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/CastSpellInfo.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -3327,7 +3327,7 @@
   //  || (result = pTurnEngine->field_4, pTurnEngine->field_4 != 1) && pTurnEngine->field_4 != 3 )
   if (pParty->bTurnBasedModeOn)
   {
-    if (pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3)
+    if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_MOVEMENT )
       return;
   }
 
--- a/DecalBuilder.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/DecalBuilder.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -236,7 +236,7 @@
       v29 = v21->radius;
       //v30 = (int)v21;
       //v31 = thisa;
-      if ( !this->_49B790_build_decal_geometry(v42, a3, (DecalBuilder_stru0 *)v21, (int)&a5a, SLODWORD(v29), v43, v33, &static_AE4F60, a5, a6, a8) )
+      if ( !this->_49B790_build_decal_geometry(v42, a3, (Bloodsplat *)v21, (int)&a5a, SLODWORD(v29), v43, v33, &static_AE4F60, a5, a6, a8) )
       {
       MessageBoxW(nullptr, L"Error: Failed to build decal geometry", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:114", 0);
       }
@@ -249,26 +249,26 @@
 }
 
 //----- (0049B790) --------------------------------------------------------
-char DecalBuilder::_49B790_build_decal_geometry(int a2, char a3, DecalBuilder_stru0 *a4, int a5, float a6, unsigned int uColorMultiplier, float a8, stru314 *a9, signed int a10, RenderVertexSoft *a11, char uClipFlags)
+char DecalBuilder::_49B790_build_decal_geometry(int a2, char a3, Bloodsplat *a4, int a5, float a6, unsigned int uColorMultiplier, float a8, stru314 *a9, signed int a10, RenderVertexSoft *a11, char uClipFlags)
 {
-  DecalBuilder *v12; // esi@1
+  //DecalBuilder *v12; // esi@1
   Decal *v13; // edi@2
   int *v14; // eax@2
-  double v15; // st7@4
-  double v16; // st7@4
-  int v17; // eax@4
-  stru314 *v18; // ebx@4
-  double v19; // st7@4
-  double v20; // st7@4
-  double v21; // st7@4
-  double v22; // st6@4
-  double v23; // st6@4
-  double v24; // st5@4
-  char *v25; // eax@4
-  signed int v26; // ecx@4
-  double v27; // st5@4
+  //double v15; // st7@4
+  //double v16; // st7@4
+  //int v17; // eax@4
+  //stru314 *v18; // ebx@4
+  //double v19; // st7@4
+  //double v20; // st7@4
+  //double v21; // st7@4
+  //double v22; // st6@4
+  //double v23; // st6@4
+  //double v24; // st5@4
+  //char *v25; // eax@4
+  //signed int v26; // ecx@4
+  //double v27; // st5@4
   double v28; // st7@5
-  double v29; // st7@6
+  //double v29; // st7@6
   char result; // al@6
   unsigned int *v31; // edi@7
   RenderVertexSoft *v32; // ebx@8
@@ -277,163 +277,150 @@
   const char *v35; // [sp-Ch] [bp-2Ch]@15
   int v36; // [sp-8h] [bp-28h]@15
   std::string v37; // [sp-4h] [bp-24h]@15
-  float v38; // [sp+8h] [bp-18h]@6
-  RenderVertexSoft *v39; // [sp+Ch] [bp-14h]@6
-  unsigned int v40; // [sp+10h] [bp-10h]@6
+  //float v38; // [sp+8h] [bp-18h]@6
+  //RenderVertexSoft *v39; // [sp+Ch] [bp-14h]@6
+  //unsigned int v40; // [sp+10h] [bp-10h]@6
 
-  int a6a;
-  RenderVertexSoft *a8a;
+  //int a6a;
+  //RenderVertexSoft *a8a;
   unsigned int a8b = 0;
 
-  v12 = this;
+  //v12 = this;
   if ( a6 == 0.0 )
     return 1;
   v13 = &this->std__vector_pDecals[this->field_308008];
   v14 = &this->std__vector_pDecals[this->field_308008].field_C1C;
-  this->std__vector_pDecals[this->field_308008].field_C18 = a4;
+  this->std__vector_pDecals[this->field_308008].field_C18 = (DecalBuilder_stru0 *)a4;
   *v14 = 0;
   if ( a3 & 2 )
     *v14 = 1;
-  v15 = a6 - a8;
-  this->field_30C028 = v15;
-  v16 = sqrt((a6 + a6 - v15) * v15);
-  v12->field_30C02C = v16;
-  v17 = a5;
-  v18 = a9;
-  v12->flt_30C030 = 1.0 - (a6 - v16) / a6;
-  v13->field_C08 = (signed __int64)((double)*(signed int *)v17 - a8 * v18->field_4.x);
-  v13->field_C0A = (signed __int64)((double)*(signed int *)(a5 + 4) - a8 * v18->field_4.y);
-  v19 = a6;
-  v13->field_C0C = (signed __int64)((double)*(signed int *)(a5 + 8) - a8 * v18->field_4.z);
-  v20 = v19 * v12->flt_30C030;
-  a8a = v13->pVertices;
-  v12->field_30C034 = v20;
-  v12->field_30C010 = v20 * v18->field_10.x;
-  v12->field_30C014 = v20 * v18->field_10.y;
-  v12->field_30C018 = v20 * v18->field_10.z;
-  v12->field_30C01C = v20 * v18->field_1C.x;
-  v12->field_30C020 = v20 * v18->field_1C.y;
-  v12->field_30C024 = v20 * v18->field_1C.z;
-  a6a = v13->field_C08;
-  v21 = (double)a6a;
-  v22 = v21 - v12->field_30C01C;
-  a6a = v13->field_C0A;
-  v13->pVertices[0].vWorldPosition.x = v22 + v12->field_30C010;
-  v23 = (double)a6a;
-  v24 = v23 - v12->field_30C020 + v12->field_30C014;
-  v25 = (char *)&v13->pVertices[0].vWorldPosition.y;
-  a6 = v13->field_C0C;
-  v26 = 4;
-  v13->pVertices[0].vWorldPosition.y = v24;
-  v27 = (double)a6a;
-  a6 = v27;
-  v13->pVertices[0].vWorldPosition.z = v27 - v12->field_30C024 + v12->field_30C018;
+  //v15 = a6 - a8;
+  this->field_30C028 = a6 - a8;
+  //v16 = sqrt((a6 + a6 - this->field_30C028) * this->field_30C028);
+  this->field_30C02C = sqrt((a6 + a6 - this->field_30C028) * this->field_30C028);
+  //v17 = a5;
+  //v18 = a9;
+  this->flt_30C030 = 1.0 - (a6 - this->field_30C02C) / a6;
+  v13->field_C08 = (signed __int64)((double)*(signed int *)a5 - a8 * a9->field_4.x);
+  v13->field_C0A = (signed __int64)((double)*(signed int *)(a5 + 4) - a8 * a9->field_4.y);
+  //v19 = a6;
+  v13->field_C0C = (signed __int64)((double)*(signed int *)(a5 + 8) - a8 * a9->field_4.z);
+  //v20 = a6 * this->flt_30C030;
+  //a8a = v13->pVertices;
+  this->field_30C034 = a6 * this->flt_30C030;
+  this->field_30C010 = this->field_30C034 * a9->field_10.x;
+  this->field_30C014 = this->field_30C034 * a9->field_10.y;
+  this->field_30C018 = this->field_30C034 * a9->field_10.z;
+  this->field_30C01C = this->field_30C034 * a9->field_1C.x;
+  this->field_30C020 = this->field_30C034 * a9->field_1C.y;
+  this->field_30C024 = this->field_30C034 * a9->field_1C.z;
+  //a6a = v13->field_C08;
+  //v21 = (double)v13->field_C08;
+  //v22 = (double)v13->field_C08 - this->field_30C01C;
+  //a6a = v13->field_C0A;
+  v13->pVertices[0].vWorldPosition.x = (double)v13->field_C08 - this->field_30C01C + this->field_30C010;
+  v13->pVertices[0].vWorldPosition.y = (double)v13->field_C0A - this->field_30C020 + this->field_30C014;
+  v13->pVertices[0].vWorldPosition.z = (double)v13->field_C0A - this->field_30C024 + this->field_30C018;
   v13->pVertices[0].u = 0.0;
   v13->pVertices[0].v = 0.0;
-  v13->pVertices[1].vWorldPosition.x = v21 - v12->field_30C01C - v12->field_30C010;
-  v13->pVertices[1].vWorldPosition.y = v23 - v12->field_30C020 - v12->field_30C014;
-  v13->pVertices[1].vWorldPosition.z = v27 - v12->field_30C024 - v12->field_30C018;
+
+  v13->pVertices[1].vWorldPosition.x = (double)v13->field_C08 - this->field_30C01C - this->field_30C010;
+  v13->pVertices[1].vWorldPosition.y = (double)v13->field_C0A - this->field_30C020 - this->field_30C014;
+  v13->pVertices[1].vWorldPosition.z = (double)v13->field_C0A - this->field_30C024 - this->field_30C018;
   v13->pVertices[1].u = 0.0;
   v13->pVertices[1].v = 1.0;
-  v13->pVertices[2].vWorldPosition.x = v21 + v12->field_30C01C - v12->field_30C010;
-  v13->pVertices[2].vWorldPosition.y = v23 + v12->field_30C020 - v12->field_30C014;
-  v13->pVertices[2].vWorldPosition.z = v27 + v12->field_30C024 - v12->field_30C018;
+
+  v13->pVertices[2].vWorldPosition.x = (double)v13->field_C08 + this->field_30C01C - this->field_30C010;
+  v13->pVertices[2].vWorldPosition.y = (double)v13->field_C0A + this->field_30C020 - this->field_30C014;
+  v13->pVertices[2].vWorldPosition.z = (double)v13->field_C0A + this->field_30C024 - this->field_30C018;
   v13->pVertices[2].u = 1.0;
   v13->pVertices[2].v = 1.0;
-  v13->pVertices[3].vWorldPosition.x = v21 + v12->field_30C01C + v12->field_30C010;
-  v13->pVertices[3].vWorldPosition.y = v23 + v12->field_30C020 + v12->field_30C014;
-  v13->pVertices[3].vWorldPosition.z = a6 + v12->field_30C024 + v12->field_30C018;
+
+  v13->pVertices[3].vWorldPosition.x = (double)v13->field_C08 + this->field_30C01C + this->field_30C010;
+  v13->pVertices[3].vWorldPosition.y = (double)v13->field_C0A + this->field_30C020 + this->field_30C014;
+  v13->pVertices[3].vWorldPosition.z = (double)v13->field_C0A + this->field_30C024 + this->field_30C018;
   v13->pVertices[3].u = 1.0;
   v13->pVertices[3].v = 0.0;
-  do
+
+  for ( uint i = 0; i < 4; ++i )
   {
-    v28 = v18->field_4.y * *(float *)v25
-        + *((float *)v25 - 1) * v18->field_4.x
-        + *((float *)v25 + 1) * v18->field_4.z
-        + v18->dist;
-    *((float *)v25 - 1) = *((float *)v25 - 1) - v28 * v18->field_4.x;
-    *(float *)v25 = *(float *)v25 - v28 * v18->field_4.y;
-    v25 += 48;
-    --v26;
-    *((float *)v25 - 11) = *((float *)v25 - 11) - v28 * v18->field_4.z;
+    v28 = a9->field_4.x * v13->pVertices[i].vWorldPosition.x
+        + a9->field_4.y * v13->pVertices[i].vWorldPosition.y
+        + a9->field_4.z * v13->pVertices[i].vWorldPosition.z
+        + a9->dist;
+    v13->pVertices[i].vWorldPosition.x = v13->pVertices[i].vWorldPosition.x - v28 * a9->field_4.x;
+    v13->pVertices[i].vWorldPosition.y = v13->pVertices[i].vWorldPosition.y - v28 * a9->field_4.y;
+    v13->pVertices[i].vWorldPosition.z = v13->pVertices[i].vWorldPosition.z - v28 * a9->field_4.z;
+    //v25 += 48;
   }
-  while ( v26 );
   v13->uColorMultiplier = uColorMultiplier;
   //v40 = (unsigned int *)&v13->uNumVertices;
-  v39 = v13->pVertices;
+  //v39 = v13->pVertices;
   v13->uNumVertices = 4;
   v13->field_C14 = a2;
-  v29 = v18->field_4.z;
+  //v29 = a9->field_4.z;
   //a6a = (unsigned int *)&v13->uNumVertices;
-  v38 = v29;
-  result = pGame->pStru9Instance->_4980B9(a11, a10, v18->field_4.x, v18->field_4.y, v38, v39, (unsigned int*)&v13->uNumVertices);
+  //v38 = a9->field_4.z;
+  result = pGame->pStru9Instance->_4980B9(a11, a10, a9->field_4.x, a9->field_4.y, a9->field_4.z, v13->pVertices, (unsigned int*)&v13->uNumVertices);
   if ( result )
   {
     //v31 = a6a;
     if ( !v13->uNumVertices )
       return 1;
-    v32 = a8a;
+    //v32 = a8a;
     //v40 = *a6a;
-    v39 = a8a;
-    pGame->pIndoorCameraD3D->ViewTransform(a8a, (unsigned int)v13->uNumVertices);
-    v40 = 0;
-    pGame->pIndoorCameraD3D->Project(v32, v13->uNumVertices, 0);
+    //v39 = a8a;
+    pGame->pIndoorCameraD3D->ViewTransform(v13->pVertices, (unsigned int)v13->uNumVertices);
+    //v40 = 0;
+    pGame->pIndoorCameraD3D->Project(v13->pVertices, v13->uNumVertices, 0);
     if ( !(uClipFlags & 1) )
     {
-      ++v12->field_308008;
+      ++this->field_308008;
       v34 = 1024;
-      if ( v12->field_308008 == 1024 )
-        v12->field_308008 = 0;
-      if ( (signed int)(v12->std__vector_pDecals_size + 1) <= 1024 )
-        v34 = v12->std__vector_pDecals_size + 1;
-      v12->std__vector_pDecals_size = v34;
+      if ( this->field_308008 == 1024 )
+        this->field_308008 = 0;
+      if ( (signed int)(this->std__vector_pDecals_size + 1) <= 1024 )
+        v34 = this->std__vector_pDecals_size + 1;
+      this->std__vector_pDecals_size = v34;
       return 1;
     }
     if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
     {
       if ( uClipFlags & 2 )
       {
-        v40 = (int)&a8;
-        v39 = v12->pVertices;
-      __debugbreak(); // warning C4700: uninitialized local variable 'v31' used
-        pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(v32, *v31, v12->pVertices, &a8b);
-        v40 = (int)v31;
-        v39 = v12->pVertices;
-        pGame->pIndoorCameraD3D->_437143(a8b, v32, v12->pVertices, v31);
+        //v40 = (int)&a8;
+        //v39 = this->pVertices;
+      //__debugbreak(); // warning C4700: uninitialized local variable 'v31' used
+        pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(v13->pVertices, v13->uNumVertices, this->pVertices, &a8b);
+        //v40 = (int)v31;
+        //v39 = this->pVertices;
+        pGame->pIndoorCameraD3D->_437143(a8b, v13->pVertices, this->pVertices, (unsigned int *)v13->uNumVertices);
       }
       else if ( uClipFlags & 4 )
       {
-        v40 = (int)&a8;
-        v39 = v12->pVertices;
-        pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(v32, *v31, v12->pVertices, &a8b);
-        v40 = (int)v31;
-        v39 = v12->pVertices;
-        pGame->pIndoorCameraD3D->_437143(a8b, v32, v12->pVertices, v31);
+        //v40 = (int)&a8;
+        //v39 = this->pVertices;
+        pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(v13->pVertices, v13->uNumVertices, this->pVertices, &a8b);
+        //v40 = (int)v31;
+        //v39 = this->pVertices;
+        pGame->pIndoorCameraD3D->_437143(a8b, v13->pVertices, this->pVertices, (unsigned int *)v13->uNumVertices);
       }
-	  else
-	  {
-        v39 = (RenderVertexSoft *)"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:258";
-        v35 = "Undefined clip flag specified";
-	    MessageBoxA(nullptr, v35, (const char *)v39, 0);
-	  }
+      else
+        MessageBoxA(nullptr, "Undefined clip flag specified", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:258", 0);
     }
     else
-    {
-      v39 = (RenderVertexSoft *)"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:263";
-      v35 = "Lightpoly builder native indoor clipping not implemented";
-	  MessageBoxA(nullptr, v35, (const char *)v39, 0);
-    }
+      MessageBoxA(nullptr, "Lightpoly builder native indoor clipping not implemented", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:263", 0);
     if ( a8b != 0 )
-	{
-      ++v12->field_308008;
+    {
+      ++this->field_308008;
       v34 = 1024;
-      if ( v12->field_308008 == 1024 )
-        v12->field_308008 = 0;
-      if ( (signed int)(v12->std__vector_pDecals_size + 1) <= 1024 )
-        v34 = v12->std__vector_pDecals_size + 1;
-      v12->std__vector_pDecals_size = v34;
+      if ( this->field_308008 == 1024 )
+        this->field_308008 = 0;
+      if ( (signed int)(this->std__vector_pDecals_size + 1) <= 1024 )
+        v34 = this->std__vector_pDecals_size + 1;
+      this->std__vector_pDecals_size = v34;
       return 1;
-	}
+    }
     result = 1;
   }
   return result;
--- a/DecalBuilder.h	Wed Feb 26 01:14:18 2014 +0100
+++ b/DecalBuilder.h	Wed Feb 26 01:15:58 2014 +0100
@@ -168,7 +168,7 @@
   void AddBloodsplat(float x, float y, float z, float r, float g, float b, float radius, int a8, int a9);
   void Reset(unsigned int bPreserveBloodsplats);
   char ApplyDecals(int light_level, char a3, struct stru154 *a4, int a5, struct RenderVertexSoft *a6, struct IndoorCameraD3D_Vec4 *a7, char a8, unsigned int uSectorID);
-  char _49B790_build_decal_geometry(int a2, char a3, DecalBuilder_stru0 *a4, int a5, float a6, unsigned int uColorMultiplier, float a8, struct stru314 *a9, signed int a10, struct RenderVertexSoft *a11, char uClipFlags);
+  char _49B790_build_decal_geometry(int a2, char a3, Bloodsplat *a4, int a5, float a6, unsigned int uColorMultiplier, float a8, struct stru314 *a9, signed int a10, struct RenderVertexSoft *a11, char uClipFlags);
   bool ApplyBloodsplatDecals_IndoorFace(unsigned int uFaceID);
   char ApplyDecals_OutdoorFace(ODMFace *pFace);
   bool _49BE8A(struct Polygon *a2, Vec3_float_ *a3, float *a4, struct RenderVertexSoft *a5, unsigned int uStripType, char a7);
--- a/Game.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Game.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -3428,7 +3428,7 @@
               Actor::StealFrom(uMessageParam);
             continue;
           }
-          if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3 )
+          if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_MOVEMENT )
             continue;
           if ( !(pTurnEngine->field_18 & TE_HAVE_PENDING_ACTIONS) )
           {
@@ -3447,7 +3447,7 @@
             _42ECB5_PlayerAttacksActor();
             continue;
           }
-          if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3 )
+          if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_MOVEMENT )
             continue;
           if ( !(pTurnEngine->field_18 & TE_HAVE_PENDING_ACTIONS) )
             _42ECB5_PlayerAttacksActor();
@@ -3710,7 +3710,7 @@
           continue;
         }
         case UIMSG_OpenSpellbookPage:
-          if ( pTurnEngine->turn_stage == 3 || !uActiveCharacter || uMessageParam == pPlayers[uActiveCharacter]->lastOpenedSpellbookPage )
+          if ( pTurnEngine->turn_stage == TE_MOVEMENT || !uActiveCharacter || uMessageParam == pPlayers[uActiveCharacter]->lastOpenedSpellbookPage )
             continue;
           OnCloseSpellBookPage();
           pPlayers[uActiveCharacter]->lastOpenedSpellbookPage = uMessageParam;
@@ -3719,7 +3719,7 @@
           continue;
         case UIMSG_SelectSpell:
         {
-          if (pTurnEngine->turn_stage == 3)
+          if (pTurnEngine->turn_stage == TE_MOVEMENT)
             continue;
           if (!uActiveCharacter)
             continue;
@@ -3757,17 +3757,17 @@
         continue;
 
         case UIMSG_CastSpellFromBook:
-          if ( pTurnEngine->turn_stage != 3 )
+          if ( pTurnEngine->turn_stage != TE_MOVEMENT )
             _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 0, 0, 0);
         continue;
 
         case UIMSG_SpellScrollUse:
 			__debugbreak();
-          if ( pTurnEngine->turn_stage != 3 )
+          if ( pTurnEngine->turn_stage != TE_MOVEMENT )
             _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 133, 1, 0);
           continue;
         case UIMSG_SpellBookWindow:
-          if ( pTurnEngine->turn_stage == 3 )
+          if ( pTurnEngine->turn_stage == TE_MOVEMENT )
             continue;
           if ( bUnderwater == true )
           {
--- a/Indoor.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Indoor.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -2819,7 +2819,7 @@
       }
       if ( pActors[actor_id].uAIState == Pursuing || pActors[actor_id].uAIState == Fleeing )
         v6 *= 2;
-      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 1 )
+      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == TE_WAIT )
         v6 = (signed __int64)((double)v6 * flt_6BE3AC_debug_recmod1_x_1_6);
       if ( v6 > 1000 )
         v6 = 1000;
@@ -2945,7 +2945,7 @@
               v37 = PID_ID(stru_721530.uFaceID);
               if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Actor)
               {
-                if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == 2 || pTurnEngine->turn_stage == 3) )
+                if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->turn_stage == TE_MOVEMENT) )
                 {
                   pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
                   pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
@@ -3093,7 +3093,7 @@
           }
           else
           {
-            if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == 2 || pTurnEngine->turn_stage == 3) )
+            if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->turn_stage == TE_MOVEMENT) )
               goto LABEL_123;
             if ( !pActors[actor_id].pMonsterInfo.uHostilityType || v56 != v22 )
             {
@@ -6256,7 +6256,7 @@
 
     stru_721530.uSectorID = uSectorID;
     v38 = 0;
-    if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == 3 )
+    if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT )
       v38 = 13312;
     if ( stru_721530._47050A(v38) )
       break;
--- a/IndoorCameraD3D.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/IndoorCameraD3D.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -23,86 +23,41 @@
 //----- (004361EF) --------------------------------------------------------
 IndoorCameraD3D::IndoorCameraD3D()
 {
-  IndoorCameraD3D *v1; // esi@1
-  //double v2; // st7@1
-  //double v3; // st6@1
-  //double v4; // st5@1
-  //double v5; // st7@1
-  //double v6; // st6@1
-  //double v7; // st5@1
-
-  v1 = this;
-  //IndoorCameraD3D_Vec3::IndoorCameraD3D_Vec3(&this->field_4);
-  //IndoorCameraD3D_Vec3::IndoorCameraD3D_Vec3(&v1->field_14);
-  //IndoorCameraD3D_Vec3::IndoorCameraD3D_Vec3(&v1->field_24);
-  /*_eh_vector_constructor_iterator_(v1->std__vector_000034_prolly_frustrum,
-    24,
-    6,
-    (void ( *)(void *))IndoorCameraD3D_Vec4::IndoorCameraD3D_Vec4,
-    (void ( *)(void *))IndoorCameraD3D_Vec4::dtor);*/
-  //v2 = 0;//(double)pBLVRenderParams->vPartyPos.z;
-  //v3 = 0;//(double)pBLVRenderParams->vPartyPos.y;
-  //v4 = 0;//(double)pBLVRenderParams->vPartyPos.x;
-  v1->field_108 = 0.0;
-  //v1->blv_party_x = 0;
-  //v1->blv_party_y = 0;
-  //v1->blv_party_z = 0;
-  //v5 = 0;//(double)pBLVRenderParams->vPartyPos.z;
-  //v6 = 0;//(double)pBLVRenderParams->vPartyPos.y;
-  //v7 = 300;//(double)(pBLVRenderParams->vPartyPos.x + 300);
-  v1->field_138 = 0.0;
-  //v1->blv_party_x_2 = 300;
-  //v1->blv_party_y_2 = 0;
-  //v1->blv_party_z_2 = 0;
-  v1->field_168 = 0.0;
-  v1->field_198 = 0.0;
-  v1->field_1C8 = 0.0;
-  v1->field_1F8 = 0.0;
-  v1->field_228 = 0.0;
-  v1->field_258 = 0.0;
-  v1->field_288 = 0.0;
-  v1->field_2B8 = 0.0;
-  v1->field_2E8 = 0.0;
-  v1->field_2BC = 0.0;
-  v1->field_2C0 = 0.0;
-  v1->field_2C4 = 0.0;
-  v1->field_318 = 0.0;
-  v1->field_2EC = 0.0;
-  v1->field_2F0 = 0.0;
-  v1->field_2F4 = 0.0;
-  v1->field_348 = 0.0;
-  v1->field_31C = 0.0;
-  v1->field_320 = 0.0;
-  v1->field_324 = 0.0;
-  v1->field_378 = 0.0;
-  v1->field_34C = 0.0;
-  v1->field_350 = 0.0;
-  v1->field_354 = 0.0;
+  this->field_108 = 0.0;
+  this->field_138 = 0.0;
+  this->field_168 = 0.0;
+  this->field_198 = 0.0;
+  this->field_1C8 = 0.0;
+  this->field_1F8 = 0.0;
+  this->field_228 = 0.0;
+  this->field_258 = 0.0;
+  this->field_288 = 0.0;
+  this->field_2B8 = 0.0;
+  this->field_2E8 = 0.0;
+  this->field_2BC = 0.0;
+  this->field_2C0 = 0.0;
+  this->field_2C4 = 0.0;
+  this->field_318 = 0.0;
+  this->field_2EC = 0.0;
+  this->field_2F0 = 0.0;
+  this->field_2F4 = 0.0;
+  this->field_348 = 0.0;
+  this->field_31C = 0.0;
+  this->field_320 = 0.0;
+  this->field_324 = 0.0;
+  this->field_378 = 0.0;
+  this->field_34C = 0.0;
+  this->field_350 = 0.0;
+  this->field_354 = 0.0;
   for (uint i = 0; i < 16384; ++i)
   {
     list_0037C[i].field_0 = 0;
     list_0037C[i].flt_30 = 0.0f;
   }
-
   list_0037C_size = 0;
   for (uint i = 0; i < 256; ++i)
     list_E0380[i].mm7__vector_000004_size = 0;
-  /*v10 = v1->list_E0380;
-  v12 = 256;
-  do
-  {
-    v10->mm7__vector_000004_size = 0;
-    //mm7__vector_constructor(
-    //  v10->mm7__vector_000004,
-    //  48,
-    //  64,
-    //  (int ( *)(int))IndoorCameraD3D_stru1::IndoorCameraD3D_stru1);
-    //++v10;
-    --v12;
-  }
-  while ( v12 );*/
   list_E0380_size = 0;
-  //v1->vdestructor_ptr = &stru8_pvdtor;
 }
 
 
@@ -786,37 +741,20 @@
 void IndoorCameraD3D::MatrixMultiply(Matrix3x3_float_ *a1, Matrix3x3_float_ *a2, Matrix3x3_float_ *out)
 {
   float *v4; // ecx@1
-  float *v5; // eax@1
-  signed int v6; // ebx@1
-  float *v7; // edx@2
-  float *v8; // ecx@2
-  signed int v9; // edi@2
   double v10; // st7@3
   double v11; // st6@3
 
   v4 = (float *)out;
-  v5 = &a1->_12;
-  v6 = 3;
-  do
+  for ( uint i = 0; i < 3; i++ )
   {
-    v7 = v4;
-    v8 = &a2->_21;
-    v9 = 3;
-    do
+    for ( uint j = 0; j < 3; j++ )
     {
-      v10 = v8[3] * v5[1] + *(v8 - 3) * *(v5 - 1);
-      v11 = *v8 * *v5;
-      ++v8;
-      *v7 = v10 + v11;
-      ++v7;
-      --v9;
+      v10 = a2->v[2][j] * a1->v[i][2] + a2->v[0][j] * a1->v[i][0];
+      v11 = a2->v[1][j] * a1->v[i][1];
+      *v4 = v10 + v11;
+      ++v4;
     }
-    while ( v9 );
-    v5 += 3;
-    --v6;
-    v4 = v7;
   }
-  while ( v6 );
 }
 
 //----- (004376E7) --------------------------------------------------------
@@ -946,56 +884,57 @@
 //----- (00437376) --------------------------------------------------------
 char IndoorCameraD3D::_437376(stru154 *thisa, RenderVertexSoft *a2, unsigned int *pOutNumVertices)
 {
-  unsigned int v4; // ebx@1
-  RenderVertexSoft *v5; // edx@2
+  //unsigned int v4; // ebx@1
+  //RenderVertexSoft *v5; // edx@2
   double v6; // st7@3
-  unsigned int v7; // edi@5
+  //unsigned int v7; // edi@5
   signed int v8; // esi@6
   int v9; // ebx@8
   int v10; // eax@8
-  int v11; // ecx@14
-  int v12; // eax@14
+  //int v11; // ecx@14
+  //int v12; // eax@14
   int v13; // eax@15
   signed int v14; // ebx@17
-  RenderVertexSoft *v15; // eax@18
+  //RenderVertexSoft *v15; // eax@18
   unsigned int *v16; // eax@20
   char result; // al@24
   RenderVertexSoft v18; // [sp+Ch] [bp-34h]@2
   int v19; // [sp+3Ch] [bp-4h]@8
   signed int thisb; // [sp+48h] [bp+8h]@6
-  char a2_3; // [sp+4Fh] [bp+Fh]@5
+  bool a2_3; // [sp+4Fh] [bp+Fh]@5
 
-  v4 = *pOutNumVertices;
+  //v4 = *pOutNumVertices;
+  //v5 = a2;
+  memcpy(&v18, a2, sizeof(v18));
+  a2_3 = false;
+  memcpy(&a2[*pOutNumVertices], a2, sizeof(a2[*pOutNumVertices]));
+  memcpy(&a2[*pOutNumVertices + 1], &a2[1], sizeof(a2[*pOutNumVertices + 1]));
+  //v7 = *pOutNumVertices;
+
   if ( (signed int)*pOutNumVertices <= 3
-    || ((v5 = a2,
-         memcpy(&v18, a2, sizeof(v18)),
-         (v18.vWorldPosition.z - (double)pGame->pIndoorCameraD3D->vPartyPos.z) * thisa->face_plane.vNormal.z
+    || (((v18.vWorldPosition.z - (double)pGame->pIndoorCameraD3D->vPartyPos.z) * thisa->face_plane.vNormal.z
        + (v18.vWorldPosition.y - (double)pGame->pIndoorCameraD3D->vPartyPos.y) * thisa->face_plane.vNormal.y
        + (v18.vWorldPosition.x - (double)pGame->pIndoorCameraD3D->vPartyPos.x) * thisa->face_plane.vNormal.x < 0.0) ? (v6 = 1.0) : (v6 = -1.0),
-        a2_3 = 0,
-        memcpy(&v5[v4], v5, sizeof(v5[v4])),
-        memcpy(&v5[*pOutNumVertices + 1], &v5[1], sizeof(v5[*pOutNumVertices + 1])),
-        v7 = *pOutNumVertices,
         (signed int)*pOutNumVertices <= 0) )
-    goto LABEL_28;
+    return 0;
   v8 = 1;
-  for ( thisb = 1; ; v8 = thisb )
+  for ( thisb = 1; thisb - 1 < (signed int)*pOutNumVertices; v8 = thisb )
   {
     v9 = v8 - 1;
     v10 = v8 + 1;
     v19 = v8 + 1;
-    if ( v8 - 1 >= (signed int)v7 )
-      v9 -= v7;
-    if ( v8 >= (signed int)v7 )
-      v8 -= v7;
-    if ( v19 >= (signed int)v7 )
-      v10 = v19 - v7;
-    v11 = (int)&v5[v10];
-    v12 = (int)&v5[v9];
-    if ( -0.009999999776482582 > ((v5[v8].vWorldViewProjX - *(float *)(v12 + 24))
-                                * (*(float *)(v11 + 28) - *(float *)(v12 + 28))
-                                - (v5[v8].vWorldViewProjY - *(float *)(v12 + 28))
-                                * (*(float *)(v11 + 24) - *(float *)(v12 + 24)))
+    if ( v8 - 1 >= (signed int)*pOutNumVertices )
+      v9 -= *pOutNumVertices;
+    if ( v8 >= (signed int)*pOutNumVertices )
+      v8 -= *pOutNumVertices;
+    if ( v19 >= (signed int)*pOutNumVertices )
+      v10 = v19 - *pOutNumVertices;
+    //v11 = (int)&a2[v10];
+    //v12 = (int)&a2[v9];
+    if ( -0.009999999776482582 > ((a2[v8].vWorldViewProjX - a2[v9].vWorldViewProjX)
+                                * (a2[v10].vWorldViewProjY - a2[v9].vWorldViewProjY)
+                                - (a2[v8].vWorldViewProjY - a2[v9].vWorldViewProjY)
+                                * (a2[v10].vWorldViewProjX - a2[v9].vWorldViewProjX))
                                * v6 )
     {
       thisb = v19;
@@ -1004,34 +943,25 @@
     else
     {
       v13 = thisb;
-      if ( thisb >= (signed int)v7 )
-        v13 = thisb - v7;
-      v14 = v13;
-      if ( v13 < (signed int)v7 )
+      if ( thisb >= (signed int)*pOutNumVertices )
+        v13 = thisb - *pOutNumVertices;
+      if ( v13 < (signed int)*pOutNumVertices )
       {
-        v15 = &v5[v13];
-        do
-        {
-          memcpy(v15, &v15[1], 0x30u);
-          ++v14;
-          ++v15;
-        }
-        while ( v14 < (signed int)*pOutNumVertices );
+        for ( v14 = v13; v14 < (signed int)*pOutNumVertices; ++v14 )
+          memcpy(&a2[v14], &a2[v14 + 1], sizeof(a2[v14]));
       }
       v16 = pOutNumVertices;
-      a2_3 = 1;
+      a2_3 = true;
       --*v16;
     }
-    v7 = *v16;
-    if ( thisb - 1 >= (signed int)*v16 )
-      break;
+    *pOutNumVertices = *v16;
+    //if ( thisb - 1 >= (signed int)*v16 )
+      //break;
   }
   if ( a2_3 )
-    result = 1;
+    return true;
   else
-LABEL_28:
-    result = 0;
-  return result;
+    return false;
 }
 
 //----- (00437285) --------------------------------------------------------
@@ -1162,42 +1092,22 @@
 // 50F1E0: using guessed type char static_sub_4371C3_byte_50F1E0_init_flags;
 
 //----- (00437143) --------------------------------------------------------
-int IndoorCameraD3D::_437143(unsigned int uNumInVertices, RenderVertexSoft *pOutVertices, RenderVertexSoft *pInVertices, unsigned int *pOutNumVertices)
+void IndoorCameraD3D::_437143(unsigned int uNumInVertices, RenderVertexSoft *pOutVertices, RenderVertexSoft *pInVertices, unsigned int *pOutNumVertices)
 {
-  unsigned int v5; // edi@1
-  char *pOutVertices_; // edx@2
-  char *v7; // eax@2
-  unsigned int v8; // ebx@2
   double v9; // st7@3
-  double v10; // st6@3
-  int result; // eax@5
-  unsigned int a2a; // [sp+10h] [bp+Ch]@2
 
-  v5 = uNumInVertices;
-  if ( (signed int)uNumInVertices > 0 )
+  uint i = 0;
+
+  for ( i; i < uNumInVertices; ++i )
   {
-    pOutVertices_ = (char *)&pOutVertices->vWorldViewProjY;
-    v7 = (char *)&pInVertices->_rhw;
-    v8 = (char *)pOutVertices - (char *)pInVertices;
-    a2a = uNumInVertices;
-    do
-    {
-      *(float *)v7 = 1.0 / (*((float *)v7 - 5) + 0.0000001);
-      memcpy(pOutVertices_ - 28, v7 - 32, 0x30u);
-      v9 = (double)pODMRenderParams->int_fov_rad * *(float *)&v7[v8];
-      v10 = (double)pViewport->uScreenCenterX - v9 * *((float *)v7 - 4);
-      v7 += 48;
-      *((float *)pOutVertices_ - 1) = v10;
-      *(float *)pOutVertices_ = (double)pViewport->uScreenCenterY - v9 * *((float *)v7 - 15);
-      pOutVertices_ += 48;
-      --a2a;
-    }
-    while ( a2a );
-    v5 = uNumInVertices;
+    pInVertices[i]._rhw = 1.0 / (pInVertices[i].vWorldViewPosition.x + 0.0000001);
+    memcpy(&pOutVertices[i], &pInVertices[i], sizeof(pOutVertices[i]));
+    v9 = (double)pODMRenderParams->int_fov_rad * pInVertices[i]._rhw;
+    pOutVertices[i].vWorldViewProjX = (double)pViewport->uScreenCenterX - v9 * pInVertices[i].vWorldViewPosition.y;
+    pOutVertices[i].vWorldViewProjY = (double)pViewport->uScreenCenterY - v9 * pInVertices[i].vWorldViewPosition.z;
   }
-  result = (int)pOutNumVertices;
-  *pOutNumVertices = v5;
-  return result;
+  *pOutNumVertices = i;
+  return;
 }
 
 //----- (00436F09) --------------------------------------------------------
--- a/IndoorCameraD3D.h	Wed Feb 26 01:14:18 2014 +0100
+++ b/IndoorCameraD3D.h	Wed Feb 26 01:15:58 2014 +0100
@@ -140,7 +140,7 @@
   void Project(struct RenderVertexSoft *pVertices, unsigned int uNumVertices, char a4);
   void _436CDC_mess_with_lightmap__clipflag_2(struct RenderVertexSoft *pInVertices, int uNumInVertices, struct RenderVertexSoft *pOutVertices, unsigned int *pOutNumVertices);
   void _436F09_mess_with_lightmap__clipflag_4(struct RenderVertexSoft *pInVertices, int uNumInVertices, struct RenderVertexSoft *pOutVertices, unsigned int *pOutNumVertices);
-  int _437143(unsigned int uNumInVertices, struct RenderVertexSoft *pOutVertices, struct RenderVertexSoft *pInVertices, unsigned int *pOutNumVertices);
+  void _437143(unsigned int uNumInVertices, struct RenderVertexSoft *pOutVertices, struct RenderVertexSoft *pInVertices, unsigned int *pOutNumVertices);
   bool _4371C3(struct RenderVertexSoft *pVertices, unsigned int *pOutNumVertices, int _unused);
   bool CalcPortalShape(struct RenderVertexSoft *a1, unsigned int *pOutNumVertices, struct RenderVertexSoft *pVertices, IndoorCameraD3D_Vec4 *a4, signed int uNumVertices, char a6, int _unused);
   char _437376(struct stru154 *thisa, struct RenderVertexSoft *a2, unsigned int *pOutNumVertices);
--- a/LightmapBuilder.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/LightmapBuilder.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -65,10 +65,7 @@
       memcpy(static_69B140 + i, a5 + i, sizeof(RenderVertexSoft));
 
     //__debugbreak();
-    if (pGame->pIndoorCameraD3D->_437376(
-           a3,
-           static_69B140,
-           &uNumVertices) == 1)
+    if (pGame->pIndoorCameraD3D->_437376(a3, static_69B140, &uNumVertices) == 1)
     {
       if ( !uNumVertices )
         return false;
@@ -81,11 +78,8 @@
   static_69B110.field_4.y = a3->face_plane.vNormal.y;
   static_69B110.field_4.z = a3->face_plane.vNormal.z;
   static_69B110.dist = a3->face_plane.dist;
-  if (!pGame->pIndoorCameraD3D->GetFacetOrientation(
-          a3->polygonType,
-          &static_69B110.field_4,
-          &static_69B110.field_10,
-          &static_69B110.field_1C))
+  if (!pGame->pIndoorCameraD3D->GetFacetOrientation(a3->polygonType, &static_69B110.field_4,
+          &static_69B110.field_10, &static_69B110.field_1C))
   {
     MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:119", 0);
     ExitProcess(0);
@@ -104,16 +98,8 @@
     if (!uColor)
       uColor = 0x00FFFFF;
 
-    if (!_45BE86_build_light_polygon(
-              &pos,
-              a2->_blv_lights_radii[i],
-              uColor,
-              a2->_blv_lights_light_dot_faces[i],
-              a2->_blv_lights_types[i],
-              &static_69B110,
-              uNumVertices,
-              a9,
-              uClipFlag) )
+    if (!_45BE86_build_light_polygon(&pos, a2->_blv_lights_radii[i], uColor, a2->_blv_lights_light_dot_faces[i],
+              a2->_blv_lights_types[i], &static_69B110, uNumVertices, a9, uClipFlag) )
     {
       MessageBoxW(nullptr, L"Error: Failed to build light polygon", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:138", 0);
     }
@@ -466,76 +452,62 @@
 //----- (0045C6D6) --------------------------------------------------------
 int LightmapBuilder::_45C6D6(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
 {
-  Lightmap *v4; // edi@1
-  signed int v5; // ebx@1
   signed int v6; // esi@1
-  RenderVertexSoft *v7; // ecx@2
-  char *v8; // edx@4
   double v9; // st7@6
   double v10; // st6@10
   double v11; // st5@14
   double v12; // st7@17
-  RenderVertexSoft *v13; // eax@21
   int v15; // [sp+Ch] [bp-8h]@1
   float v16; // [sp+10h] [bp-4h]@1
-  int pLightmapa; // [sp+24h] [bp+10h]@3
 
-  v4 = pLightmap;
-  v5 = 0;
   v6 = -1;
   v16 = 3.4028235e38;
   v15 = 0;
   if ( (signed int)pLightmap->uNumVertices > 0 )
   {
-    v7 = pLightmap->pVertices;
-    do
+    for ( uint i = 0; i < (signed int)pLightmap->uNumVertices; ++i )
     {
-      pLightmapa = 0;
       if ( a2 > 0 )
       {
-        v8 = (char *)&a3->vWorldPosition.z;
-        do
+        for ( uint j = 0; j < a2; ++j )
         {
-          if ( v7->vWorldPosition.x <= (double)*((float *)v8 - 2) )
-            v9 = *((float *)v8 - 2) - v7->vWorldPosition.x;
+          if ( pLightmap->pVertices[i].vWorldPosition.x <= (double)a3[j].vWorldPosition.x )
+            v9 = a3[j].vWorldPosition.x - pLightmap->pVertices[i].vWorldPosition.x;
           else
-            v9 = v7->vWorldPosition.x - *((float *)v8 - 2);
+            v9 = pLightmap->pVertices[i].vWorldPosition.x - a3[j].vWorldPosition.x;
           if ( v9 < 2.0 )
           {
-            v10 = v7->vWorldPosition.y <= (double)*((float *)v8 - 1) ? *((float *)v8 - 1) - v7->vWorldPosition.y : v7->vWorldPosition.y - *((float *)v8 - 1);
+            v10 = pLightmap->pVertices[i].vWorldPosition.y <= (double)a3[j].vWorldPosition.y
+                ? a3[j].vWorldPosition.y - pLightmap->pVertices[i].vWorldPosition.y
+                : pLightmap->pVertices[i].vWorldPosition.y - a3[j].vWorldPosition.y;
             if ( v10 < 2.0 )
             {
-              v11 = v7->vWorldPosition.z <= (double)*(float *)v8 ? *(float *)v8 - v7->vWorldPosition.z : v7->vWorldPosition.z - *(float *)v8;
+              v11 = pLightmap->pVertices[i].vWorldPosition.z <= (double)a3[j].vWorldPosition.z
+                  ? a3[j].vWorldPosition.z - pLightmap->pVertices[i].vWorldPosition.z
+                  : pLightmap->pVertices[i].vWorldPosition.z - a3[j].vWorldPosition.z;
               if ( v11 < 2.0 )
               {
                 v12 = v9 + v11 + v10;
                 if ( v12 < v16 )
                 {
                   v16 = v12;
-                  v6 = pLightmapa;
+                  v6 = j;
                 }
               }
             }
           }
-          ++pLightmapa;
-          v8 += 48;
         }
-        while ( pLightmapa < a2 );
         if ( v6 != -1 )
         {
-          v13 = &a3[v6];
           ++v15;
-          v7->vWorldPosition.x = v13->vWorldPosition.x;
-          v7->vWorldPosition.y = v13->vWorldPosition.y;
-          v7->vWorldPosition.z = v13->vWorldPosition.z;
+          pLightmap->pVertices[i].vWorldPosition.x = a3[v6].vWorldPosition.x;
+          pLightmap->pVertices[i].vWorldPosition.y = a3[v6].vWorldPosition.y;
+          pLightmap->pVertices[i].vWorldPosition.z = a3[v6].vWorldPosition.z;
         }
       }
       v6 = -1;
-      ++v5;
-      ++v7;
       v16 = 3.4028235e38;
     }
-    while ( v5 < (signed int)v4->uNumVertices );
   }
   return v15;
 }
--- a/Mouse.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Mouse.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -550,7 +550,7 @@
 
     if ( pParty->bTurnBasedModeOn == 1 )
     {
-      if ( pTurnEngine->turn_stage == 3 )
+      if ( pTurnEngine->turn_stage == TE_MOVEMENT )
         pTurnEngine->field_18 |= TE_FLAG_8;
     }
   }
--- a/Outdoor.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Outdoor.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -3948,7 +3948,7 @@
 
     stru_721530.uSectorID = 0;
     v36 = 0;
-    if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == 3 )
+    if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT )
       v36 = 13312;
     if ( stru_721530._47050A(v36) )
       break;
--- a/Overlays.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Overlays.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -95,56 +95,32 @@
 //----- (00441964) --------------------------------------------------------
 void OtherOverlayList::DrawTurnBasedIcon(int a2)
 {
-  unsigned int result; // eax@1
-  IconFrameTable *v3; // ecx@6
-  void *v4; // eax@12
+  IconFrame *frame; // eax@12
   unsigned int v5; // [sp-8h] [bp-Ch]@4
-  int v6; // [sp-4h] [bp-8h]@4
-  Texture *v7; // [sp-4h] [bp-8h]@14
 
   if ( pCurrentScreen != SCREEN_GAME || !pParty->bTurnBasedModeOn)
     return;
 
-  if ( pTurnEngine->turn_stage == 3 )
-  {
-    v6 = pEventTimer->uStartTime;
-    v5 = pIconIDs_Turn[5 - pTurnEngine->uActionPointsLeft / 26];
-  }
-  else
+  if ( pTurnEngine->turn_stage == TE_MOVEMENT )//âñå ïåðñû îòñòðåëÿëèñü(ñæàòûé êóëàê)
+    frame = pIconsFrameTable->GetFrame(pIconIDs_Turn[5 - pTurnEngine->uActionPointsLeft / 26], pEventTimer->uStartTime);
+  else  if ( pTurnEngine->turn_stage == TE_WAIT )
   {
-    if ( pTurnEngine->turn_stage == 1 )
-    {
-      v6 = dword_50C994;
-      v3 = pIconsFrameTable;
-      if ( dword_50C998_turnbased_icon_1A )
-        v5 = uIconID_TurnStart;
-      else
-        v5 = uIconID_TurnHour;
-      goto LABEL_12;
-    }
-    if ( pTurnEngine->turn_stage != 2 )
-    {
-      v4 = this;
-      goto LABEL_14;
-    }
-    v6 = pEventTimer->uStartTime;
-    v5 = uIconID_TurnStop;
+    if ( dword_50C998_turnbased_icon_1A )
+      v5 = uIconID_TurnStart;//àíèìàöèÿ ðóêè(çàïóñê ïîøàãîâîãî ðåæèìà)
+    else
+      v5 = uIconID_TurnHour; //ãðóïïà îæèäàåò(÷àñû)
+    frame = pIconsFrameTable->GetFrame(v5, dword_50C994);
   }
-  v3 = pIconsFrameTable;
-LABEL_12:
-  v4 = pIconsFrameTable->GetFrame(v5, v6);
-LABEL_14:
-  v7 = &pIcons_LOD->pTextures[*((short *)v4 + 15)];
+  else if ( pTurnEngine->turn_stage == TE_ATTACK )//ãðóïïà àòàêóåò(ëàäîíü)
+    frame = pIconsFrameTable->GetFrame(uIconID_TurnStop, pEventTimer->uStartTime);
   //if ( pRenderer->pRenderD3D )
-    pRenderer->DrawTextureIndexed(0x18Au, 0x120u, v7);
+    pRenderer->DrawTextureIndexed(394, 288, &pIcons_LOD->pTextures[frame->uTextureID]);
   /*else
     pRenderer->DrawTextureTransparent(0x18Au, 0x120u, v7);*/
-  result = dword_50C994;
   if ( dword_50C994 < dword_50C998_turnbased_icon_1A )
   {
-    result = pEventTimer->uTimeElapsed + dword_50C994;
-    dword_50C994 = result;
-    if ( (signed int)result >= dword_50C998_turnbased_icon_1A )
+    dword_50C994 += pEventTimer->uTimeElapsed;
+    if ( (signed int)dword_50C994 >= dword_50C998_turnbased_icon_1A )
       dword_50C998_turnbased_icon_1A = 0;
   }
 }
@@ -163,18 +139,16 @@
 //----- (00458DBC) --------------------------------------------------------
 void OverlayList::ToFile()
 {
-  OverlayList *v1; // esi@1
   FILE *v2; // eax@1
-  FILE *v3; // edi@1
+  //FILE *v3; // edi@1
 
-  v1 = this;
   v2 = fopen("data\\doverlay.bin", "wb");
-  v3 = v2;
+  //v3 = v2;
   if ( !v2 )
     Error("Unable to save doverlay.bin!");
-  fwrite(v1, 4u, 1u, v2);
-  fwrite(v1->pOverlays, 8u, v1->uNumOverlays, v3);
-  fclose(v3);
+  fwrite(this, 4, 1, v2);
+  fwrite(this->pOverlays, 8, this->uNumOverlays, v2);
+  fclose(v2);
 }
 
 //----- (00458E08) --------------------------------------------------------
@@ -197,31 +171,22 @@
 //----- (00458E4F) --------------------------------------------------------
 bool OverlayList::FromFileTxt(const char *Args)
 {
-  OverlayList *v2; // ebx@1
   __int32 v3; // edi@1
   FILE *v4; // eax@1
   unsigned int v5; // esi@3
-  const void *v6; // ST18_4@9
   void *v7; // eax@9
   FILE *v8; // ST0C_4@11
   char *i; // eax@11
-  unsigned __int16 v10; // ax@14
-  const char *v11; // ST1C_4@14
-  int v12; // eax@16
-  OverlayDesc *v13; // ecx@16
-  char v14; // zf@16
-  unsigned int v15; // eax@16
   char Buf; // [sp+10h] [bp-2F0h]@3
   FrameTableTxtLine v18; // [sp+204h] [bp-FCh]@4
   FrameTableTxtLine v19; // [sp+280h] [bp-80h]@4
   FILE *File; // [sp+2FCh] [bp-4h]@1
   unsigned int Argsa; // [sp+308h] [bp+8h]@3
 
-  v2 = this;
   free(this->pOverlays);
   v3 = 0;
-  v2->pOverlays = 0;
-  v2->uNumOverlays = 0;
+  this->pOverlays = 0;
+  this->uNumOverlays = 0;
   v4 = fopen(Args, "r");
   File = v4;
   if ( !v4 )
@@ -242,16 +207,15 @@
     v5 = Argsa;
     v3 = 0;
   }
-  v6 = v2->pOverlays;
-  v2->uNumOverlays = v5;
+  this->uNumOverlays = v5;
   v7 = malloc(8 * v5);
-  v2->pOverlays = (OverlayDesc *)v7;
+  this->pOverlays = (OverlayDesc *)v7;
   if ( v7 == (void *)v3 )
     Error("OverlayDescriptionList::load - Out of Memory!");
 
-  memset(v7, v3, 8 * v2->uNumOverlays);
+  memset(v7, v3, 8 * this->uNumOverlays);
   v8 = File;
-  v2->uNumOverlays = v3;
+  this->uNumOverlays = v3;
   fseek(v8, v3, v3);
   for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
   {
@@ -259,25 +223,17 @@
     memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19));
     if ( v19.uPropCount && *v19.pProperties[0] != 47 )
     {
-      v10 = atoi(v19.pProperties[0]);
-      v11 = v19.pProperties[1];
-      v2->pOverlays[v2->uNumOverlays].uOverlayID = v10;
-      if ( _stricmp(v11, "center") )
+      this->pOverlays[this->uNumOverlays].uOverlayID = atoi(v19.pProperties[0]);
+      if ( _stricmp(v19.pProperties[1], "center") )
       {
-        v12 = _stricmp(v19.pProperties[1], "transparent");
-        v13 = v2->pOverlays;
-        v14 = v12 == 0;
-        v15 = v2->uNumOverlays;
-        if ( v14 )
-          v13[v15].uOverlayType = 2;
+        if ( !_stricmp(v19.pProperties[1], "transparent") )
+          this->pOverlays[this->uNumOverlays].uOverlayType = 2;
         else
-          v13[v15].uOverlayType = 1;
+          this->pOverlays[this->uNumOverlays].uOverlayType = 1;
       }
       else
-      {
-        v2->pOverlays[v2->uNumOverlays].uOverlayType = 0;
-      }
-      v2->pOverlays[v2->uNumOverlays++].uSpriteFramesetID = pSpriteFrameTable->FastFindSprite(
+        this->pOverlays[this->uNumOverlays].uOverlayType = 0;
+      this->pOverlays[this->uNumOverlays++].uSpriteFramesetID = pSpriteFrameTable->FastFindSprite(
                                                               (char *)v19.pProperties[2]);
     }
   }
@@ -285,7 +241,6 @@
   return 1;
 }
 
-
 //----- (0045855F) --------------------------------------------------------
 void OtherOverlay::Reset()
 {
@@ -303,11 +258,12 @@
 //----- (004584B8) --------------------------------------------------------
 OtherOverlay::OtherOverlay()
 {
-  this->field_A = 0;
-  this->field_8 = 0;
+  this->field_0 = 0;
+  this->field_2 = 0;
+  this->field_4 = 0;
   this->field_6 = 0;
-  this->field_4 = 0;
-  this->field_2 = 0;
+  this->field_8 = 0;
+  this->field_A = 0;
   this->field_C = 0;
   this->field_E = 0;
   this->field_10 = 65536;
--- a/Party.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Party.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -159,7 +159,7 @@
   v12 = 0;
   if ( pParty->bTurnBasedModeOn == 1 )
   {
-    if ( pTurnEngine->turn_stage != 2 || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) != OBJECT_Player)
+    if ( pTurnEngine->turn_stage != TE_ATTACK || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) != OBJECT_Player)
       return 0;
     v2 = PID_ID(pTurnEngine->pQueue[0].uPackedID);
     return v2 + 1;
--- a/Player.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Player.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -4275,7 +4275,7 @@
   //thisb = this;
   playerAffected = &pParty->pPlayers[player_num-1];
   v73 = 1;
-  if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3) )
+  if ( pParty->bTurnBasedModeOn == true && (pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_MOVEMENT) )
       return;
   if ( pParty->pPickedItem.GetItemEquipType() == EQUIP_REAGENT )
   {
--- a/Render.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Render.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -3567,64 +3567,73 @@
   int v30; // ebx@60
   int v31; // edx@61
   int v32; // edi@61
-  __int64 v36; // [sp+14h] [bp-8h]@1
   signed int upper_bound; // [sp+18h] [bp-4h]@28
   unsigned int uXa; // [sp+24h] [bp+8h]@49
   int uYb; // [sp+28h] [bp+Ch]@47
-
-  v36 = 0i64;
+  bool left_border_x = false;
+  bool right_border_x = false;
+  bool left_border_z = false;
+  bool right_border_z = false;
+  bool upper_border_y = false;
+  bool bottom_border_y = false;
+  bool upper_border_w = false;
+  bool bottom_border_w = false;
+
   if ( uX < this->raster_clip_x )// x âûõîäèò çà ðàìêè ëåâîé ãðàíèöû
-    HIDWORD(v36) = 8; //left_border = true;
+    left_border_x = true;
   if ( uX > this->raster_clip_z )// x âûõîäèò çà ðàìêè ïðàâîé ãðàíèöû
-    HIDWORD(v36) |= 4;//right_border = true;
+    right_border_x = true;
 
   if ( uZ < this->raster_clip_x )// z âûõîäèò çà ðàìêè ëåâîé ãðàíèöû
-    LODWORD(v36) = 8;//
+    left_border_z = true;
   if ( uZ > this->raster_clip_z )// z âûõîäèò çà ðàìêè ïðàâîé ãðàíèöû
-    LODWORD(v36) |= 4;
+    right_border_z = true;
 
   if ( uY < this->raster_clip_y )// y âûõîäèò çà ðàìêè âåðõíåé ãðàíèöû
-    HIDWORD(v36) |= 2;//upper_border = true;
+    upper_border_y = true;
   if ( uY > this->raster_clip_w )// y âûõîäèò çà ðàìêè íèæíåé ãðàíèöû
-    HIDWORD(v36) |= 1;//bottom_border = true;
+    bottom_border_y = true;
 
   if ( uW < this->raster_clip_y )// w âûõîäèò çà ðàìêè âåðõíåé ãðàíèöû
-    LODWORD(v36) |= 2;
+    upper_border_w = true;
   if ( uW > this->raster_clip_w )// w âûõîäèò çà ðàìêè íèæíåé ãðàíèöû
-    LODWORD(v36) |= 1;
-
-  //LOBYTE(v12) = v36;
-  if ( (unsigned int)v36 & HIDWORD(v36) )
+    bottom_border_w = true;
+
+  if ( (left_border_x && left_border_z) || (right_border_x && right_border_z )
+    || (upper_border_y && upper_border_w) || (bottom_border_y && bottom_border_w))
     return;
 
-  if ( v36 ) //íå ïîëíîñòüþ â ðàìêàõ
-  {
-    if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 8 )//for left and right(ëåâàÿ è ïðàâàÿ)
-    {
-      if ( BYTE4(v36) & 8 )//left_border = true;
-      {
-        uY += ((uW - uY) * (this->raster_clip_x - uX)) / (uZ - uX);
+  if ( left_border_x || left_border_z || right_border_x || right_border_z
+    || upper_border_y || upper_border_w || bottom_border_y || bottom_border_w)
+  {
+    if ( left_border_x || left_border_z )//if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 8 )//for left (ëåâàÿ ãðàíèöà)
+    {
+      if ( left_border_x )//left_border = true; õ ìåíüøå ëåâîé ãðàíèöû
+      {
+        uY += (uW - uY) * ((this->raster_clip_x - uX) / (uZ - uX));//t = near_clip - v0.x / v1.x - v0.x  (ôîðìóëà ïîëó÷åíèÿ òî÷êè ïåðåñå÷åíèÿ îòðåçêà ñ ïëîñêîñòüþ)
         uX = this->raster_clip_x;
       }
-      else
+      else if ( left_border_z )//z ìåíüøå ëåâîé ãðàíèöû
       {
         uZ = this->raster_clip_x;
-        uW += ((uY - uW) * (this->raster_clip_x - uZ)) / (uX - uZ);
-      }
-    }
-    if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 4 )
-    {
-      if ( BYTE4(v36) & 4 ) //right_border = true
-      {
-        uY += ((uW - uY) * (this->raster_clip_z - uX)) / (uZ - uX);
+        uW += (uY - uW) * ((this->raster_clip_x - uZ) / (uX - uZ));
+      }
+    }
+
+    if ( right_border_x || right_border_z )//if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 4 )//for right (ïðàâàÿ ãðàíèöà)
+    {
+      if ( right_border_x ) //right_border = true; õ áîëüøå ïðàâîé ãðàíèöû
+      {
+        uY += (uY - uW) * ((this->raster_clip_z - uX) / (uZ - uX));
         uX = this->raster_clip_z;
       }
-      else
-      {
-        uW += ((uY - uW) * (this->raster_clip_z - uZ)) / (uX - uZ);
+      else if ( right_border_z )//z áîëüøå ïðàâîé ãðàíèöû
+      {
+        uW += (uW - uY) * ((this->raster_clip_z - uZ) / (uX - uZ));
         uZ = this->raster_clip_z;
       }
     }
+
     upper_bound = 0;
     if ( uY < this->raster_clip_y )
       upper_bound = 2;
@@ -3644,12 +3653,12 @@
       {
         if ( upper_bound & 2 )
         {
-          uX += ((uZ - uX) * (this->raster_clip_y - uY)) / (uW - uY);
+          uX += (uZ - uX) * ((this->raster_clip_y - uY) / (uW - uY));
           uY = this->raster_clip_y;
         }
         else
         {
-          uZ += (uX - uZ) * (this->raster_clip_y - uW) / (uY - uW);
+          uZ += (uX - uZ) * ((this->raster_clip_y - uW) / (uY - uW));
           uW = this->raster_clip_y;
         }
       }
@@ -3657,12 +3666,12 @@
       {
         if ( upper_bound & 1 )
         {
-          uX += ((uZ - uX) * (this->raster_clip_w - uY)) / (uW - uY);
+          uX += (uZ - uX) * ((this->raster_clip_w - uY) / (uW - uY));
           uY = this->raster_clip_w;
         }
         else
         {
-          uZ += ((uX - uZ) * (this->raster_clip_w - uW)) / (uY - uW);
+          uZ += (uX - uZ) * ((this->raster_clip_w - uW) / (uY - uW));
           uW = this->raster_clip_w;
         }
       }
@@ -3766,7 +3775,7 @@
 //----- (004A0E80) --------------------------------------------------------
 void Render::ClearZBuffer(int a2, int a3)
 {
-  memset32(this->pActiveZBuffer, -65536, 0x4B000u);
+  memset32(this->pActiveZBuffer, -65536, 0x4B000);
 }
 
 //----- (004A0E97) --------------------------------------------------------
--- a/TurnEngine.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/TurnEngine.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -21,1188 +21,1078 @@
 
 //----- (00404544) --------------------------------------------------------
 void stru262_TurnBased::SortTurnQueue()
-    {
-
-    int active_actors;
-    TurnBased_QueueElem *current_top; // eax@16
-    TurnBased_QueueElem *test_element; // ecx@18
-    TurnBased_QueueElem temp_elem;
-    int i,j;
-    unsigned int p_type;
-    unsigned int p_id;
-
-    active_actors = this->uActorQueueSize;
-    //set non active actors in queue initiative that not allow them to paticipate 
-    for( i=0; i<uActorQueueSize; ++i) 
-        {
-        p_type = PID_TYPE(pQueue[i].uPackedID);
-        p_id   = PID_ID(pQueue[i].uPackedID);
+{
+  int active_actors;
+  TurnBased_QueueElem *current_top; // eax@16
+  TurnBased_QueueElem *test_element; // ecx@18
+  TurnBased_QueueElem temp_elem;
+  int i,j;
+  unsigned int p_type;
+   unsigned int p_id;
 
-        if ( p_type == OBJECT_Actor )
-            {
-            pActors[p_id].uAttributes |= 0x80u;
-            if ( !pActors[p_id].CanAct() )
-                {
-                --active_actors;
-                pQueue[i].actor_initiative = 1001;
-                pActors[p_id].uAttributes &= ~0x80;
-                }
-            }
-        else if ( p_type == OBJECT_Player)
-            {
-            if ( !pParty->pPlayers[p_id].CanAct() )
-                {
-                --active_actors;
-                pQueue[i].actor_initiative = 1001;
-                }
-            }
-        }
-     //sort
-if (uActorQueueSize>0)
+  active_actors = this->uActorQueueSize;
+  //set non active actors in queue initiative that not allow them to paticipate 
+  for( i = 0; i < uActorQueueSize; ++i) 
+  {
+    p_type = PID_TYPE(pQueue[i].uPackedID);
+    p_id   = PID_ID(pQueue[i].uPackedID);
+
+    if ( p_type == OBJECT_Actor )
+    {
+      pActors[p_id].uAttributes |= 0x80;
+      if ( !pActors[p_id].CanAct() )
+      {
+        --active_actors;
+        pQueue[i].actor_initiative = 1001;
+        pActors[p_id].uAttributes &= ~0x80;
+      }
+    }
+    else if ( p_type == OBJECT_Player)
     {
-    for( i=0; i<uActorQueueSize-1; ++i) 
-        {
-       current_top=&pQueue[i];
-        for(j=i+1; j<uActorQueueSize;++j )
-            {  
-            test_element=&pQueue[j];           
-            if ( test_element->actor_initiative < current_top->actor_initiative  || // if less initiative -> top
-                   ((test_element->actor_initiative == current_top->actor_initiative) && 
-                       (
-                          ((PID_TYPE(test_element->uPackedID) == OBJECT_Player) && (PID_TYPE(current_top->uPackedID) == OBJECT_Actor)) || //player preferable
-                          ((PID_TYPE(test_element->uPackedID) == PID_TYPE(current_top->uPackedID)) && (PID_ID(test_element->uPackedID) < PID_ID(current_top->uPackedID)))  //less id preferable    
-                       ) 
-                   )
-                )
-                { //swap
-                memcpy(&temp_elem,current_top,sizeof(TurnBased_QueueElem));
-                memcpy(current_top,test_element, sizeof(TurnBased_QueueElem));
-                memcpy(test_element, &temp_elem, sizeof(TurnBased_QueueElem));
-                }
-            }
+      if ( !pParty->pPlayers[p_id].CanAct() )
+      {
+        --active_actors;
+        pQueue[i].actor_initiative = 1001;
+      }
+    }
+  }
+  //sort
+  if (uActorQueueSize > 0)
+  {
+    for( i = 0; i < uActorQueueSize-1; ++i) 
+    {
+      current_top=&pQueue[i];
+      for ( j = i+1; j < uActorQueueSize; ++j )
+      {
+        test_element=&pQueue[j];
+        if ( test_element->actor_initiative < current_top->actor_initiative  || // if less initiative -> top
+           ((test_element->actor_initiative == current_top->actor_initiative) && 
+           (((PID_TYPE(test_element->uPackedID) == OBJECT_Player) && (PID_TYPE(current_top->uPackedID) == OBJECT_Actor)) || //player preferable
+            ((PID_TYPE(test_element->uPackedID) == PID_TYPE(current_top->uPackedID)) && (PID_ID(test_element->uPackedID) < PID_ID(current_top->uPackedID))))))  //less id preferable
+        { //swap
+          memcpy(&temp_elem,current_top,sizeof(TurnBased_QueueElem));
+          memcpy(current_top,test_element, sizeof(TurnBased_QueueElem));
+          memcpy(test_element, &temp_elem, sizeof(TurnBased_QueueElem));
         }
+      }
     }
-    uActorQueueSize = active_actors;
-    if ( PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) //we have player at queue top
-        {
-        uActiveCharacter = PID_ID(pQueue[0].uPackedID)+1;
-        field_18 |= TE_PLAYER_TURN;
-        }
-    else
-        {
-        uActiveCharacter = 0;
-        field_18 &= ~TE_PLAYER_TURN;
-        }
-    for(i=0; i<uActorQueueSize; ++i)
-        {
-        if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) //set recovery times
-            pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 0.46875);
-        }
-
-
-    }
-
+  }
+  uActorQueueSize = active_actors;
+  if ( PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) //we have player at queue top
+  {
+    uActiveCharacter = PID_ID(pQueue[0].uPackedID)+1;
+    field_18 |= TE_PLAYER_TURN;
+  }
+  else
+  {
+    uActiveCharacter = 0;
+    field_18 &= ~TE_PLAYER_TURN;
+  }
+  for ( i = 0; i < uActorQueueSize; ++i)
+  {
+    if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) //set recovery times
+      pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 0.46875);
+  }
+}
 //----- (0040471C) --------------------------------------------------------
 void stru262_TurnBased::ApplyPlayerAction()
-    {
-    if ( pParty->bTurnBasedModeOn == 1 )
-        {
-        if ( pTurnEngine->turn_stage == 2 )
-            _406457(0);
-        }
-    }
+{
+  if ( pParty->bTurnBasedModeOn == 1 )
+  {
+    if ( pTurnEngine->turn_stage == TE_ATTACK )
+      _406457(0);
+  }
+}
 
 //----- (004059DB) --------------------------------------------------------
 void stru262_TurnBased::Start()
-    {
+{
+  int v17; // edx@22
+  AIDirection v30; // [sp+Ch] [bp-68h]@10
+  AIDirection v31; // [sp+28h] [bp-4Ch]@10
+  AIDirection a3; // [sp+44h] [bp-30h]@10
+  int activ_players[4];
+  int players_recovery_time[4];
+  int a_players_count;
+  int i,j;
+  int temp;
 
-    int v3; // esi@1
-    unsigned int actor_id; // esi@7
-    unsigned int v8; // edx@10
-    int v17; // edx@22
-    AIDirection v30; // [sp+Ch] [bp-68h]@10
-    AIDirection v31; // [sp+28h] [bp-4Ch]@10
-    AIDirection a3; // [sp+44h] [bp-30h]@10
-    Player *pPlayer; // [sp+6Ch] [bp-8h]@1
-    int v40b;
-    int activ_players[4];
-    int players_recovery_time[4];
-    int a_players_count;
-    int i,j;
-    int temp;
+  pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
+  pEventTimer->TrackGameTime();
+  pAudioPlayer->StopChannels(-1, -1);
+  pAudioPlayer->PlaySound(SOUND_207, 0, 0, -1, 0, 0, 0, 0);
+  //pPlayer = pParty->pPlayers.data();
+  dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength;
+  dword_50C994 = 0;
 
-    pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
-    pEventTimer->TrackGameTime();
-    pAudioPlayer->StopChannels(-1, -1);
-    pAudioPlayer->PlaySound(SOUND_207, 0, 0, -1, 0, 0, 0, 0);
-    pPlayer = pParty->pPlayers.data();
-    dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength;
-    dword_50C994 = 0;
+  this->turn_initiative = 100;
+  this->turns_count = 0;
+  this->ai_turn_timer = 64;
+  this->turn_stage = TE_WAIT;
+  this->uActorQueueSize = 0;
 
-    this->turn_initiative = 100;
-    this->turns_count = 0;
-    this->ai_turn_timer = 64;
-    this->turn_stage = 1;
-    this->uActorQueueSize = 0;
+  for ( uint pl_id = 0; pl_id < 4 ; ++pl_id )
+  {
+    if ( pParty->pPlayers[pl_id].CanAct() )
+    {
+      this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Player,pl_id);
+      this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE;
+      this->pQueue[this->uActorQueueSize].uActionLength = 0;
+      pParty->pTurnBasedPlayerRecoveryTimes[this->uActorQueueSize] = 0;
+      ++this->uActorQueueSize;
+    }
+  }
 
-    for ( v3 = 0; v3 < 4 ; ++v3 )
-        {
-        if ( pParty->pPlayers[v3].CanAct() )
-            {
-            this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Player,v3);
-            this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE;
-            this->pQueue[this->uActorQueueSize].uActionLength = 0;
-            pParty->pTurnBasedPlayerRecoveryTimes[this->uActorQueueSize] = 0;
-            ++this->uActorQueueSize;
-            }
-        }
+  for ( int i = 0; i < ai_arrays_size ; ++i )
+  {
+    if (ai_near_actors_ids[i] == 10)
+      continue;
+    if ( pActors[ai_near_actors_ids[i]].CanAct() )
+    {
+      if ( pActors[ai_near_actors_ids[i]].uAttributes & 0x8000 )
+      {
+        pActors[ai_near_actors_ids[i]].uAttributes |= 0x80;
+        Actor::GetDirectionInfo(PID(OBJECT_Actor,ai_near_actors_ids[i]), ai_near_actors_targets_pid[ai_near_actors_ids[i]], &v31, 0);
+        memcpy(&v30, &v31, sizeof(AIDirection));
+        Actor::AI_StandOrBored(ai_near_actors_ids[i], 4, 32, &v30);
+        this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[i]);
+        this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE;
+        this->pQueue[this->uActorQueueSize].uActionLength = 0;
+        ++this->uActorQueueSize;
+      }
+    }
+  }
 
-    for ( v3 = 0; v3 < ai_arrays_size ; ++v3 )
-        { 
-        actor_id = ai_near_actors_ids[v3];
-        if (actor_id == 10)
-            continue;
-        if ( pActors[actor_id].CanAct() )
-            {
-            if ( pActors[actor_id].uAttributes & 0x8000 )
-                {
-                v8 = ai_near_actors_targets_pid[actor_id];
-                pActors[actor_id].uAttributes |= 0x80;
-                Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v8, &v31, 0);
-                memcpy(&v30, &v31, sizeof(AIDirection));
-                Actor::AI_StandOrBored(actor_id, 4, 32, &v30);
-                this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Actor,actor_id);
-                this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE;
-                this->pQueue[this->uActorQueueSize].uActionLength = 0;
-                ++this->uActorQueueSize;
-                }
-            }
+  a_players_count = 0;
+  for ( int k = 0; k < this->uActorQueueSize; ++k )
+  {
+    //set initial initiative for turn actors
+    if ( PID_TYPE(this->pQueue[k].uPackedID) == OBJECT_Player )
+    {
+      if ( pPlayers[PID_ID(this->pQueue[k].uPackedID) + 1]->uTimeToRecovery != 0 )
+        this->pQueue[k].actor_initiative = (signed int)((double)pPlayers[PID_ID(this->pQueue[k].uPackedID) + 1]->uTimeToRecovery * 0.46875);
+      else
+      {
+        activ_players[a_players_count] = k;
+        ++a_players_count;
+      }
+    }
+    else if ( PID_TYPE(this->pQueue[k].uPackedID) == OBJECT_Actor )
+    {
+      v17 = rand() % 99;
+      if ( v17 < 33 )
+        this->pQueue[k].actor_initiative = 1;
+      else 
+        this->pQueue[k].actor_initiative= (v17 >= 66)? 5 : 3; 
+    }
+    else //fot non player and actor
+      this->pQueue[k].actor_initiative = 666;
+    this->pQueue[k].actor_initiative += 16;
+  }
+
+  if ( a_players_count > 0 )
+  {
+    for ( i = 0; i < a_players_count; ++i)
+      players_recovery_time[i] = pParty->pPlayers[PID_ID(this->pQueue[activ_players[i]].uPackedID)].GetAttackRecoveryTime(0);
+    //sort players by recovery time
+    for ( i = 0; i < a_players_count-1; ++i)
+    {
+      for ( j = i + 1; j < a_players_count; ++j )
+      {
+        if (players_recovery_time[j] < players_recovery_time[i]) //swap values
+        {
+          temp = players_recovery_time[i];
+          players_recovery_time[i] = players_recovery_time[j];
+          players_recovery_time[j] = temp;
+          temp = activ_players[i];
+          activ_players[i] = activ_players[j];
+          activ_players[j] = temp;
         }
-
-    a_players_count=0;
-    for ( v40b = 0; v40b < this->uActorQueueSize; ++v40b )
-        {
-        //set initial initiative for turn actors
-        if ( PID_TYPE(this->pQueue[v40b].uPackedID) == OBJECT_Player )
-            {
-            if ( pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery != 0 )
-                {
-                this->pQueue[v40b].actor_initiative = (signed int)((double)pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery * 0.46875);
-                }
-            else
-                {   
-                activ_players[a_players_count] = v40b;
-                ++a_players_count;
-                }
-            }
-        else if ( PID_TYPE(this->pQueue[v40b].uPackedID) == OBJECT_Actor )
-            {
-            v17 = rand() % 99;
-            if ( v17 < 33 )
-                this->pQueue[v40b].actor_initiative = 1;
-            else 
-                this->pQueue[v40b].actor_initiative= (v17 >= 66)? 5 : 3; 
-            }
-        else 
-            {  //fot non player and actor
-            this->pQueue[v40b].actor_initiative = 666;
-            }
-        this->pQueue[v40b].actor_initiative += 16;
-        }
-
-    if ( a_players_count > 0 )
-        {
-        for (i=0; i<a_players_count; ++i)
-            players_recovery_time[i] = pParty->pPlayers[PID_ID(this->pQueue[activ_players[i]].uPackedID)].GetAttackRecoveryTime(0);
-        //sort players by recovery time
-        for (i=0; i < a_players_count-1; ++i)
-            {  
-            for(j=i+1; j<a_players_count;++j )
-                {       
-                if (players_recovery_time[j] < players_recovery_time[i]) //swap values
-                    {
-                    temp = players_recovery_time[i];
-                    players_recovery_time[i] = players_recovery_time[j];
-                    players_recovery_time[j] = temp;
-
-                    temp = activ_players[i];
-                    activ_players[i] = activ_players[j];
-                    activ_players[j] = temp;
-                    }
-                }
-            }
-
-        for (i=0; i<a_players_count; ++i)
-            {
-            this->pQueue[activ_players[i]].actor_initiative = i+2;
-            }
-        }
-    this->SortTurnQueue();
+      }
     }
-
-
+    for ( i = 0; i < a_players_count; ++i)
+      this->pQueue[activ_players[i]].actor_initiative = i + 2;
+  }
+  this->SortTurnQueue();
+}
 
 //----- (00405CFF) --------------------------------------------------------
 void stru262_TurnBased::End(bool bPlaySound)
-    {
-   
-    ObjectType objType; // eax@13
-    int objID; // esi@13
-    int i; 
-
-    this->turn_stage = 0;
+{
+  ObjectType objType; // eax@13
+  int objID; // esi@13
+  int i; 
 
-    for( i=0; i<uActorQueueSize; ++i) 
-        { 
-        if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor )
-            pActors[PID_ID(pQueue[i].uPackedID)].uAttributes &= ~0x80;
-        }
+  this->turn_stage = TE_NONE;
+  for( i = 0; i < uActorQueueSize; ++i) 
+  {
+    if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor )
+      pActors[PID_ID(pQueue[i].uPackedID)].uAttributes &= ~0x80;
+  }
 
-    for( i=0; i<uNumSpriteObjects; ++i) 
-        {
-         if (pSpriteObjects[i].uAttributes & 4)
-             pSpriteObjects[i].uAttributes &= ~0x04;
-        }
+  for( i = 0; i < uNumSpriteObjects; ++i) 
+  {
+    if (pSpriteObjects[i].uAttributes & 4)
+      pSpriteObjects[i].uAttributes &= ~0x04;
+  }
 
-    for( i=0; i<uActorQueueSize; ++i) 
-        { 
-        objType = (ObjectType)PID_TYPE(pQueue[i].uPackedID);
-        objID = PID_ID(pQueue[i].uPackedID);
-        if ( objType == OBJECT_Player )
-            {
-            pPlayers[objID + 1]->uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333);
-            }
-        else if ( objType == OBJECT_Actor )
-            {
-             pActors[objID].pMonsterInfo.uRecoveryTime = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333);
-            }
-        }
-   
-    pAudioPlayer->StopChannels(-1, -1);
-    if ( bPlaySound != 0 )
-        pAudioPlayer->PlaySound(SOUND_206, 0, 0, -1, 0, 0, 0, 0);
-    pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
-    pEventTimer->StopGameTime();
-    dword_50C994 = 0;
-    dword_50C998_turnbased_icon_1A = 0;
-    }
+  for( i = 0; i < uActorQueueSize; ++i) 
+  {
+    objType = (ObjectType)PID_TYPE(pQueue[i].uPackedID);
+    objID = PID_ID(pQueue[i].uPackedID);
+    if ( objType == OBJECT_Player )
+      pPlayers[objID + 1]->uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333);
+    else if ( objType == OBJECT_Actor )
+      pActors[objID].pMonsterInfo.uRecoveryTime = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333);
+  }
+  pAudioPlayer->StopChannels(-1, -1);
+  if ( bPlaySound != 0 )
+    pAudioPlayer->PlaySound(SOUND_206, 0, 0, -1, 0, 0, 0, 0);
+  pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
+  pEventTimer->StopGameTime();
+  dword_50C994 = 0;
+  dword_50C998_turnbased_icon_1A = 0;
+}
 // 50C994: using guessed type int dword_50C994;
 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A;
 
 //----- (00405E14) --------------------------------------------------------
 void stru262_TurnBased::AITurnBasedAction()
+{
+  AIDirection v6; // esi@21
+  AIDirection a3; // [sp+4h] [bp-68h]@21
+  AIDirection v14; // [sp+20h] [bp-4Ch]@21
+  AIDirection v15; // [sp+3Ch] [bp-30h]@21
+  Actor *curr_actor; // [sp+58h] [bp-14h]@2
+  int target_pid; // [sp+5Ch] [bp-10h]@6
+  int shrinked;
+  int i, j;
+
+  for (i = 0; i < uNumActors; ++i )
+  {
+    curr_actor=&pActors[i];
+    shrinked=pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0;
+    for (j = 0; j < 22; ++j) //check expired spell Buffs
     {
-    AIDirection v6; // esi@21
-    int v7; // eax@21
-    AIDirection a3; // [sp+4h] [bp-68h]@21
-    AIDirection v14; // [sp+20h] [bp-4Ch]@21
-    AIDirection v15; // [sp+3Ch] [bp-30h]@21
-    Actor *curr_actor; // [sp+58h] [bp-14h]@2
-    int target_pid; // [sp+5Ch] [bp-10h]@6
-    int shrinked;
-    int i,j;
-
-    for (i =0; i<uNumActors; ++i )
+      if (j != 10)
+        pActors[i].pActorBuffs[j].IsBuffExpiredToTime(pParty->uTimePlayed);
+    }
+    if (shrinked && pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0) //buff 3 expired
+      pActors[i].uActorHeight = pMonsterList->pMonsters[pActors[i].pMonsterInfo.uID - 1].uMonsterHeight;
+    if (!(curr_actor->uAttributes & 0x80) && (!curr_actor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime) &&
+       (!curr_actor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime)) 
+    {
+      curr_actor->uCurrentActionTime += pMiscTimer->uTimeElapsed;
+      if (curr_actor->uCurrentActionTime>=curr_actor->uCurrentActionLength)
+      {
+        target_pid = ai_near_actors_targets_pid[i];
+        Actor::GetDirectionInfo(PID(OBJECT_Actor,i), target_pid, &v6, 0);
+        memcpy(&v15, &v6, sizeof(AIDirection));
+        memcpy(&v14, &v15, sizeof(AIDirection));
+        if ( curr_actor->uAIState == Dying )
         {
-        curr_actor=&pActors[i];
-        shrinked=pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0;
-        for (j =0; j<22; ++j) //check expired spell Buffs
-            {
-            if(j != 10)
-                pActors[i].pActorBuffs[j].IsBuffExpiredToTime(pParty->uTimePlayed);
-            }
-        if (shrinked && pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <=0) //buff 3 expired
-            {
-            pActors[i].uActorHeight = pMonsterList->pMonsters[pActors[i].pMonsterInfo.uID - 1].uMonsterHeight;
-            }
-        if(!(curr_actor->uAttributes&0x80)&&
-              (!curr_actor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime)&&
-              (!curr_actor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime)) 
-            {
-            curr_actor->uCurrentActionTime += pMiscTimer->uTimeElapsed;
-            if (curr_actor->uCurrentActionTime>=curr_actor->uCurrentActionLength)
-                {
-                target_pid = ai_near_actors_targets_pid[i];
-                Actor::GetDirectionInfo(PID(OBJECT_Actor,i), target_pid, &v6, 0);  
-                memcpy(&v15, &v6, sizeof(AIDirection));   
-                memcpy(&v14, &v15, sizeof(AIDirection));
-                v7 = curr_actor->uAIState;
-                if(v7==Dying)
-                    {
-                    curr_actor->uCurrentActionTime = 0;
-                    curr_actor->uCurrentActionLength = 0;
-                    curr_actor->uAIState = Dead;
-                    curr_actor->UpdateAnimation();
-                    }
-                else  if ( (v7 > AIState::Removed)&&(v7 < AIState::Disabled))
-                    {
-                     Actor::AI_StandOrBored(i, target_pid, 32, &v14);
-                    }
-                }
-            }
+          curr_actor->uCurrentActionTime = 0;
+          curr_actor->uCurrentActionLength = 0;
+          curr_actor->uAIState = Dead;
+          curr_actor->UpdateAnimation();
         }
-    
-    if ( turn_stage == 1 )
-        {
-        if ( ai_turn_timer == 64 )
-            ActorAISetMovementDecision();
-        else  if ( ai_turn_timer > 0 )
-            ActorAIDoAdditionalMove();
-        else
-            {
-             ActorAIStopMovement();
-             turn_initiative = 100;
-            }
-        ai_turn_timer -= pEventTimer->uTimeElapsed;
-        }
-    else if ( turn_stage == 2 )
-        {
-        if ( !(field_18 &TE_FLAG_1))
-            {
-            if ( turn_initiative == 100 )
-                {
-                StartTurn();
-                SetAIRecoveryTimes();
-                return;
-                }
-            if ( turn_initiative > 0 || pQueue[0].actor_initiative <= 0 )
-                {
-                _4065B0();
-                SetAIRecoveryTimes();
-                }
-            }
-        NextTurn();
-        }
-    else if ( turn_stage == 3 )
-        {
-        if ( (uActionPointsLeft > 0) && (!(field_18 & TE_FLAG_8)) )
-           ActorAIChooseNewTargets();
-        else
-            { 
-            field_18 &= ~TE_FLAG_8;
-            turn_stage = 1;
-            ai_turn_timer = 64; 
-            }
-        }
+        else  if ( (curr_actor->uAIState > AIState::Removed) && (curr_actor->uAIState < AIState::Disabled))
+          Actor::AI_StandOrBored(i, target_pid, 32, &v14);
+      }
+    }
+  }
+  if ( turn_stage == TE_WAIT )
+  {
+    if ( ai_turn_timer == 64 )
+      ActorAISetMovementDecision();
+    else  if ( ai_turn_timer > 0 )
+      ActorAIDoAdditionalMove();
+    else
+    {
+      ActorAIStopMovement();
+      turn_initiative = 100;
     }
+    ai_turn_timer -= pEventTimer->uTimeElapsed;
+  }
+  else if ( turn_stage == TE_ATTACK )
+  {
+    if ( !(field_18 &TE_FLAG_1))
+    {
+      if ( turn_initiative == 100 )
+      {
+        StartTurn();
+        SetAIRecoveryTimes();
+        return;
+      }
+      if ( turn_initiative > 0 || pQueue[0].actor_initiative <= 0 )
+      {
+        _4065B0();
+        SetAIRecoveryTimes();
+        return;
+      }
+    }
+    NextTurn();
+  }
+  else if ( turn_stage == TE_MOVEMENT )
+  {
+    if ( (uActionPointsLeft > 0) && (!(field_18 & TE_FLAG_8)) )
+      ActorAIChooseNewTargets();
+    else
+    {
+      field_18 &= ~TE_FLAG_8;
+      turn_stage = TE_WAIT;
+      ai_turn_timer = 64; 
+    }
+  }
+}
 
 
 //----- (00406051) --------------------------------------------------------
- void stru262_TurnBased::StartTurn()
-    {
-    int player_num, actor_num, i, j;
+void stru262_TurnBased::StartTurn()
+{
+  int player_num, actor_num, i, j;
 
-    pending_actions = 0;
-    //add player to queue if he can act
-    for(player_num=0; player_num<4; ++player_num) 
-        {
-        for(j=0; j<uActorQueueSize; ++j) 
-            {
-            if (PID_TYPE(pQueue[j].uPackedID)== OBJECT_Player)
-                {
-                if (pPlayers[PID_ID(pQueue[j].uPackedID) + 1]->CanAct() && (player_num != PID_ID(pQueue[j].uPackedID)) )
-                    break;
-                }
-            }
-         if (j==uActorQueueSize )
-             {
-             pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num);
-             pQueue[uActorQueueSize].actor_initiative = 100;
-             pQueue[uActorQueueSize].uActionLength = 0;
-             pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND;
-             ++uActorQueueSize;
-             }
-        }
-    //add new arrived actors
-    for(actor_num=0; actor_num<ai_arrays_size; ++actor_num) 
-        {
-        for(j=0; j<uActorQueueSize; ++j) 
-            {
-            if ((PID_TYPE(pQueue[j].uPackedID)== OBJECT_Actor)&&
-                 ai_near_actors_ids[actor_num] == PID_ID(pQueue[j].uPackedID))
-                    break;
-            }
-        if (j==uActorQueueSize )
-            {
-            pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]);
-            pQueue[uActorQueueSize].actor_initiative = 1;
-            pQueue[uActorQueueSize].uActionLength = 0;
-            pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND;
-            ++uActorQueueSize;
-            }
-        }
-
-    ++turns_count;
-    turn_initiative = 100;
-
-    for(i=0; i<uActorQueueSize; ++i) 
-        {
-        if (pQueue[i].actor_initiative == 0 )
-            pQueue[i].actor_initiative = 100;
-        }
-
-    StepTurnQueue();
-    for(i=0; i<uActorQueueSize; ++i) 
-        {
-        if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].actor_initiative > 0))
-            break;
-        AI_Action_(i);
-        }
+  pending_actions = 0;
+  //add player to queue if he can act
+  for ( player_num = 0; player_num < 4; ++player_num)
+  {
+    for ( j = 0; j < uActorQueueSize; ++j )
+    {
+      if (PID_TYPE(pQueue[j].uPackedID) == OBJECT_Player)
+      {
+        if (pPlayers[PID_ID(pQueue[j].uPackedID) + 1]->CanAct() && (player_num != PID_ID(pQueue[j].uPackedID)) )
+          break;
+      }
+    }
+    if ( j == uActorQueueSize )
+    {
+      pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num);
+      pQueue[uActorQueueSize].actor_initiative = 100;
+      pQueue[uActorQueueSize].uActionLength = 0;
+      pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND;
+      ++uActorQueueSize;
     }
+  }
+  //add new arrived actors
+  for ( actor_num = 0; actor_num < ai_arrays_size; ++actor_num )
+  {
+    for ( j = 0; j < uActorQueueSize; ++j )
+    {
+      if ((PID_TYPE(pQueue[j].uPackedID)== OBJECT_Actor)&&
+           ai_near_actors_ids[actor_num] == PID_ID(pQueue[j].uPackedID))
+        break;
+    }
+    if ( j == uActorQueueSize )
+    {
+      pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]);
+      pQueue[uActorQueueSize].actor_initiative = 1;
+      pQueue[uActorQueueSize].uActionLength = 0;
+      pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND;
+      ++uActorQueueSize;
+    }
+  }
+  ++turns_count;
+  turn_initiative = 100;
+  for ( i = 0; i < uActorQueueSize; ++i )
+  {
+    if (pQueue[i].actor_initiative == 0 )
+      pQueue[i].actor_initiative = 100;
+  }
+  StepTurnQueue();
+  for ( i = 0; i < uActorQueueSize; ++i )
+  {
+    if ((PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) || (pQueue[i].actor_initiative > 0))
+      break;
+    AI_Action_(i);
+  }
+}
 // 4F75D8: using guessed type int ai_arrays_size;
 
  //----- (004061CA) --------------------------------------------------------
  void stru262_TurnBased::NextTurn()
-     {
-     Actor *curr_actor; // eax@9
-     int ai_state; // ecx@9
-     int v13; // [sp+10h] [bp-4h]@7
-     int i;
-     int monster_ai_state;
-     int monster; // eax@5
+{
+  int v13; // [sp+10h] [bp-4h]@7
+  int monster_id; // eax@5
 
-     SortTurnQueue();
-     if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
-         uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
-     else
-         uActiveCharacter = 0;
-     viewparams->bRedrawGameUI = 1;
+  SortTurnQueue();
+  if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
+    uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
+  else
+    uActiveCharacter = 0;
+  viewparams->bRedrawGameUI = true;
 
-     if ( pending_actions )
-         {
-         pTurnEngine->field_18 |= TE_HAVE_PENDING_ACTIONS;
-         return;
-         }
-     pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
-     if ( pQueue[0].actor_initiative <= 0 )
-         return;
-
-     v13 = 0;
-     if (uActorQueueSize > 0 )
-         {   
+  if ( pending_actions )
+  {
+    pTurnEngine->field_18 |= TE_HAVE_PENDING_ACTIONS;
+    return;
+  }
+  pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
+  if ( pQueue[0].actor_initiative <= 0 )
+    return;
 
-         for (i=0; i<uActorQueueSize; ++i )
-             {
-             if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
-                 {
-                 curr_actor = &pActors[PID_ID(pQueue[i].uPackedID)];
-                 ai_state = curr_actor->uAIState;
-                 if ( (ai_state == AIState::Dying) || (ai_state == AIState::Stunned) || (ai_state == AIState::AttackingMelee) ||
-                     (ai_state == AIState::AttackingRanged1) || (ai_state == AIState::AttackingRanged2) || 
-                     (ai_state == AIState::AttackingRanged3) || (ai_state == AIState::AttackingRanged4) || (ai_state ==AIState::Summoned))
-                     {
-                     curr_actor->uCurrentActionTime += pEventTimer->uTimeElapsed;
-                     if ( curr_actor->uCurrentActionTime < curr_actor->uCurrentActionLength )
-                         {
-                         v13 = 1;
-                         }
-                     else if ( ai_state == AIState::Dying )// Dying
-                         {
-                         curr_actor->uAIState = AIState::Dead;
-                         curr_actor->uCurrentActionTime = 0;
-                         curr_actor->uCurrentActionLength = 0;
-                         curr_actor->UpdateAnimation();
-                         }
-                     else
-                         {
-                         if ( ai_state == AIState::Stunned ) //Stunned
-                             Actor::AI_StandOrBored(PID_ID(pQueue[i].uPackedID), ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)], 32, 0);
-                         }
-                     }
-                 }
-             }
-         if ( v13 != 0 )
-             {
-             field_18 |= TE_FLAG_1;
-             return;
-             }
-         }
+  v13 = 0;
+  if (uActorQueueSize > 0 )
+  {
+    for ( int i = 0; i < uActorQueueSize; ++i )
+    {
+      if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
+      {
+        monster_id = PID_ID(pQueue[i].uPackedID);
+        if ( (pActors[monster_id].uAIState == AIState::Dying) || (pActors[monster_id].uAIState == AIState::Stunned)
+          || (pActors[monster_id].uAIState == AIState::AttackingMelee) || (pActors[monster_id].uAIState == AIState::AttackingRanged1)
+          || (pActors[monster_id].uAIState == AIState::AttackingRanged2) || (pActors[monster_id].uAIState == AIState::AttackingRanged3)
+          || (pActors[monster_id].uAIState == AIState::AttackingRanged4) || (pActors[monster_id].uAIState ==AIState::Summoned))
+        {
+          pActors[monster_id].uCurrentActionTime += pEventTimer->uTimeElapsed;
+          if ( pActors[monster_id].uCurrentActionTime < pActors[monster_id].uCurrentActionLength )
+            v13 = 1;
+          else if ( pActors[monster_id].uAIState == AIState::Dying )// Dying
+          {
+            pActors[monster_id].uAIState = AIState::Dead;
+            pActors[monster_id].uCurrentActionTime = 0;
+            pActors[monster_id].uCurrentActionLength = 0;
+            pActors[monster_id].UpdateAnimation();
+          }
+          else
+          {
+            if ( pActors[monster_id].uAIState == AIState::Stunned ) //Stunned
+              Actor::AI_StandOrBored(monster_id, ai_near_actors_targets_pid[monster_id], 32, 0);
+          }
+        }
+      }
+    }
+    if ( v13 != 0 )
+    {
+      field_18 |= TE_FLAG_1;
+      return;
+    }
+  }
 
-     field_18 &= ~TE_FLAG_1;   
-     //set all actors to stay
-     for (i=0; i<uActorQueueSize; ++i )
-         {      
-         if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) 
-             {
-             monster=PID_ID(pQueue[i].uPackedID);
-             monster_ai_state=pActors[monster].uAIState;
-             if ((monster_ai_state != AIState::Dead) && 
-                 (monster_ai_state != AIState::Dying) &&
-                 (monster_ai_state != AIState::Removed) &&
-                 (monster_ai_state != AIState::Summoned) &&
-                 (monster_ai_state != AIState::Disabled))
-                 {
-                 pQueue[i].uActionLength = 0;
-                 Actor::AI_StandOrBored(monster, ai_near_actors_targets_pid[monster], 32, nullptr);
-                 }
-             }
-         }
-     // turn tick
-     turn_stage = 3;
-     pParty->uTimePlayed += 213i64;
-     _494035_timed_effects__water_walking_damage__etc();
-     uActionPointsLeft = 130;
-     }
+  field_18 &= ~TE_FLAG_1;
+  //set all actors to stay
+  for ( int i = 0; i < uActorQueueSize; ++i )
+  {
+    if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) 
+    {
+      monster_id = PID_ID(pQueue[i].uPackedID);
+      if ((pActors[monster_id].uAIState != AIState::Dead) && (pActors[monster_id].uAIState != AIState::Dying) &&
+          (pActors[monster_id].uAIState != AIState::Removed) && (pActors[monster_id].uAIState != AIState::Summoned) &&
+          (pActors[monster_id].uAIState != AIState::Disabled))
+      {
+        pQueue[i].uActionLength = 0;
+        Actor::AI_StandOrBored(monster_id, ai_near_actors_targets_pid[monster_id], 32, nullptr);
+      }
+    }
+  }
+  // turn tick
+  turn_stage = TE_MOVEMENT;
+  pParty->uTimePlayed += 213i64;
+  _494035_timed_effects__water_walking_damage__etc();
+  uActionPointsLeft = 130;
+}
 
- //----- (004063A1) --------------------------------------------------------
- bool stru262_TurnBased::StepTurnQueue()
- {
-     int v9; // dx@12 
-     int j;
+//----- (004063A1) --------------------------------------------------------
+bool stru262_TurnBased::StepTurnQueue()
+{
+  int v9; // dx@12 
+  int j;
 
-     SortTurnQueue();
-     viewparams->bRedrawGameUI = 1;
-     if ( pQueue[0].actor_initiative!=0 )
-         {
-         if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
-             {
-             do
-                 {
-                 for (j=0; j<uActorQueueSize; ++j )
-                     {      
-                     --pQueue[j].actor_initiative;
-                     }
-                 --turn_initiative;
-                 if (turn_initiative == 0)
-                     return true;
-                 }
-                 while (pQueue[0].actor_initiative != 0);
-             }
-         else
-             {
-             if ( pQueue[0].actor_initiative>0 )
-                 {            
-             v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState;
-             if (!(v9 == AIState::Dying || v9 == AIState::Dead || 
-                   v9 == AIState::Disabled || v9 == AIState::Removed))
-                 {
-                    do
-                     {
-                     for (j=0; j<uActorQueueSize; ++j )
-                         {      
-                         --pQueue[j].actor_initiative;
-                         if (pQueue[j].actor_initiative == 0)
-                             pQueue[j].uActionLength = 0;
-                         }
-                     --turn_initiative;
-                     if (turn_initiative == 0)
-                         return true;
-                     }
-                     while (pQueue[0].actor_initiative > 0); 
-                 }
-                 }
-             }
-         }
-     return false;
-     }
+  SortTurnQueue();
+  viewparams->bRedrawGameUI = 1;
+  if ( pQueue[0].actor_initiative != 0 )
+  {
+    if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
+    {
+      do
+      {
+        for (j = 0; j < uActorQueueSize; ++j )
+          --pQueue[j].actor_initiative;
+        --turn_initiative;
+        if (turn_initiative == 0)
+          return true;
+      }
+      while (pQueue[0].actor_initiative != 0);
+    }
+    else
+    {
+      if ( pQueue[0].actor_initiative > 0 )
+      {
+        v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState;
+        if (!(v9 == AIState::Dying || v9 == AIState::Dead || 
+              v9 == AIState::Disabled || v9 == AIState::Removed))
+        {
+          do
+          {
+            for ( j = 0; j < uActorQueueSize; ++j )
+            {
+              --pQueue[j].actor_initiative;
+              if (pQueue[j].actor_initiative == 0)
+                pQueue[j].uActionLength = 0;
+            }
+            --turn_initiative;
+            if (turn_initiative == 0)
+              return true;
+          }
+          while (pQueue[0].actor_initiative > 0); 
+        }
+      }
+    }
+  }
+  return false;
+}
 
 //----- (00406457) --------------------------------------------------------
 void stru262_TurnBased::_406457( int a2 )
-    {
-    signed int v4; // ecx@2
-    signed int v6; // eax@2
-    int i;
-    v6=0;
-    if (  PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player)
-        {
-        v4 = PID_ID(pQueue[a2].uPackedID);
-        if ( pParty->pTurnBasedPlayerRecoveryTimes[v4] )
-            pParty->pTurnBasedPlayerRecoveryTimes[v4] = 0;
-        else
-            v6 = pPlayers[v4 + 1]->GetAttackRecoveryTime(0);
-        if ( v6 < 30 )
-            v6 = 30;
-        }
+{
+  signed int v4; // ecx@2
+  signed int v6; // eax@2
+  int i;
+  v6 = 0;
+  if (  PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player)
+  {
+    v4 = PID_ID(pQueue[a2].uPackedID);
+    if ( pParty->pTurnBasedPlayerRecoveryTimes[v4] )
+      pParty->pTurnBasedPlayerRecoveryTimes[v4] = 0;
     else
-        {
-        v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime;
-        }
+      v6 = pPlayers[v4 + 1]->GetAttackRecoveryTime(0);
+    if ( v6 < 30 )
+      v6 = 30;
+  }
+  else
+    v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime;
 
-    pQueue[a2].actor_initiative = v6;
-    SortTurnQueue();
-    if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
-        uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
-    else
-        uActiveCharacter = 0;
-    viewparams->bRedrawGameUI = 1;
-
-    while ( (pQueue[0].actor_initiative > 0)&&(turn_initiative > 0) )
-        {
-        for (i=0; i<uActorQueueSize; ++i)
-            {
-            --pQueue[i].actor_initiative;
-            if (pQueue[i].actor_initiative==0)
-                pQueue[i].uActionLength=0;
-            }
-        --turn_initiative;
-        }
+  pQueue[a2].actor_initiative = v6;
+  SortTurnQueue();
+  if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
+    uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
+  else
+    uActiveCharacter = 0;
+  viewparams->bRedrawGameUI = 1;
+  while ( (pQueue[0].actor_initiative > 0) && (turn_initiative > 0) )
+  {
+    for ( i = 0; i < uActorQueueSize; ++i)
+    {
+      --pQueue[i].actor_initiative;
+      if (pQueue[i].actor_initiative == 0)
+        pQueue[i].uActionLength=0;
     }
+    --turn_initiative;
+  }
+}
 
 //----- (0040652A) --------------------------------------------------------
 void stru262_TurnBased::SetAIRecoveryTimes()
-    {
-    int i;
-    int monster_ai_state;
-    Actor *monster; // eax@5
+{
+  int i;
+  int monster_ai_state;
+  Actor *monster; // eax@5
 
-    for (i=0; i<uActorQueueSize; ++i )
-        {
-        if (pQueue[i].actor_initiative == 0)
-            {
-            if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) 
-                break;
-            monster=&pActors[PID_ID(pQueue[i].uPackedID)];
-            monster_ai_state=monster->uAIState;
-            if (monster_ai_state == AIState::Standing || 
-                monster_ai_state == AIState::Fleeing || 
-                monster_ai_state == AIState::Fidgeting)
-                {
-                pQueue[i].actor_initiative = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
-                if (monster->pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0)
-                    pQueue[i].actor_initiative*=2;
-                }
-            }
-        }
+  for ( i = 0; i < uActorQueueSize; ++i )
+  {
+    if (pQueue[i].actor_initiative == 0)
+    {
+      if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) 
+        break;
+      monster=&pActors[PID_ID(pQueue[i].uPackedID)];
+      monster_ai_state=monster->uAIState;
+      if (monster_ai_state == AIState::Standing || 
+          monster_ai_state == AIState::Fleeing || 
+          monster_ai_state == AIState::Fidgeting)
+      {
+        pQueue[i].actor_initiative = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
+        if (monster->pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0)
+          pQueue[i].actor_initiative*=2;
+      }
     }
+  }
+}
 
 //----- (004065B0) --------------------------------------------------------
 void stru262_TurnBased::_4065B0()
 {
-    int i;
+  int i;
 
-    SortTurnQueue();
-    if (pQueue[0].actor_initiative <= 0)
-        {  
-        for (i=0; i<uActorQueueSize; ++i )
-            {
-            if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)|| (pQueue[i].actor_initiative > 0) )
-                break;
-            if ((pQueue[i].uActionLength<=0) && (PID_TYPE(pQueue[i].uPackedID)==OBJECT_Actor))
-                AI_Action_(i);
-            }
-        }
+  SortTurnQueue();
+  if (pQueue[0].actor_initiative <= 0)
+  {
+    for ( i = 0; i < uActorQueueSize; ++i )
+    {
+      if ((PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)|| (pQueue[i].actor_initiative > 0) )
+        break;
+      if ((pQueue[i].uActionLength <= 0) && (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor))
+        AI_Action_(i);
+    }
+  }
+  else
+  {
+    StepTurnQueue();
+    if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) 
+      uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
     else
-        {
-        StepTurnQueue();
-        if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) 
-            uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
-        else
-            uActiveCharacter = 0;
-        viewparams->bRedrawGameUI = 1;
-        }
-
-    for (i=0; i<uActorQueueSize; ++i )
-        AIAttacks(i);
+      uActiveCharacter = 0;
+    viewparams->bRedrawGameUI = 1;
+  }
+  for ( i = 0; i < uActorQueueSize; ++i )
+    AIAttacks(i);
 }
 
 //----- (00406648) --------------------------------------------------------
 void stru262_TurnBased::AIAttacks( unsigned int queue_index )
 {
-    TurnBased_QueueElem *v1; // ecx@1
-    int v3; // eax@1
-    unsigned int v4; // ebx@2
-    Actor *v5; // esi@2
-    char v19; // al@24
-    AIDirection a3; // [sp+Ch] [bp-3Ch]@2
-    AIDirection a4; // [sp+28h] [bp-20h]@2
-    TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1
-    unsigned int a2a; // [sp+50h] [bp+8h]@2
+  //TurnBased_QueueElem *v1; // ecx@1
+  //int v3; // eax@1
+  unsigned int actor_id; // ebx@2
+  //Actor *v5; // esi@2
+  char v19; // al@24
+  AIDirection a3; // [sp+Ch] [bp-3Ch]@2
+  AIDirection a4; // [sp+28h] [bp-20h]@2
+  //TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1
+  //unsigned int a2a; // [sp+50h] [bp+8h]@2
 
-    v1 = &pQueue[queue_index];
-    v28 = v1;
-    v3 = v1->uPackedID;
-    if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor)
+  //v1 = &pQueue[queue_index];
+  //v28 = v1;
+  //v3 = pQueue[queue_index].uPackedID;
+  if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor)
+  {
+    actor_id = PID_ID(pQueue[queue_index].uPackedID);
+    //a2a = ai_near_actors_targets_pid[v4];
+    Actor::GetDirectionInfo(pQueue[queue_index].uPackedID, ai_near_actors_targets_pid[actor_id], &a3, 0);
+    memcpy(&a4, &a3, sizeof(a4));
+    //v5 = &pActors[v4];
+    //LOWORD(v3) = v5->uAIState;
+    if (( pActors[actor_id].uAIState != AIState::Dead ) && ( pActors[actor_id].uAIState != AIState::Disabled )
+      &&( pActors[actor_id].uAIState != AIState::Removed ))
+    {
+      pActors[actor_id].uCurrentActionTime += pEventTimer->uTimeElapsed;
+      if ( (signed int)pActors[actor_id].uCurrentActionTime >= pActors[actor_id].uCurrentActionLength )
+      {
+        switch (pActors[actor_id].uAIState)
         {
-        v4 = PID_ID(v3);
-        a2a = ai_near_actors_targets_pid[PID_ID(pQueue[queue_index].uPackedID)];
-        Actor::GetDirectionInfo(v1->uPackedID, ai_near_actors_targets_pid[PID_ID(v3)], &a3, 0);
-        memcpy(&a4, &a3, sizeof(a4));
-        v5 = &pActors[PID_ID(v3)];
-        LOWORD(v3) = v5->uAIState;
-        if (( (short)v3 != AIState::Dead )&& ( (short)v3 != AIState::Disabled )&&( (short)v3 != AIState::Removed ))  
-                    {
-                    v5->uCurrentActionTime += pEventTimer->uTimeElapsed;
-                    if ( (signed int)v5->uCurrentActionTime >= v5->uCurrentActionLength )
-                        {
-                         switch (v3)
-                         {
-                           case  AIState::AttackingMelee:
-                             v19 = pActors[v4].special_ability_use_check(v4);
-                             AttackerInfo.Add( v28->uPackedID,  5120,  v5->vPosition.x, v5->vPosition.y, v5->vPosition.z + ((signed int)v5->uActorHeight >> 1), v19,  1);
-                             Actor::AI_Stand(v4, a2a, 0, &a4);
-                             break;
-                           case AIState::AttackingRanged1:
-                             Actor::AI_RangedAttack(v4, &a4, v5->pMonsterInfo.uMissleAttack1Type, 0);
-                             Actor::AI_Stand(v4, a2a, 0,&a4);
-                             break;
-                           case AIState::Dying:
-                             v5->uCurrentActionTime = 0;
-                             v5->uCurrentActionLength = 0;
-                             v5->uAIState = Dead;
-                             pActors[v4].UpdateAnimation();
-                             break;
-                           case AIState::Stunned:
-                              Actor::AI_Stand(v4, a2a, 0,&a4);
-                              break;
-                           case AIState::AttackingRanged2:
-                             Actor::AI_RangedAttack(v4, &a4, v5->pMonsterInfo.uMissleAttack2Type, 1);
-                             Actor::AI_Stand(v4, a2a, 0,&a4);
-                             break;
-                           case AIState::AttackingRanged3:
-                             Actor::AI_SpellAttack(v4, &a4, v5->pMonsterInfo.uSpell1ID, 2, v5->pMonsterInfo.uSpellSkillAndMastery1);
-                             Actor::AI_Stand(v4, a2a, 0, &a4);
-                             break;
-                           case AIState::AttackingRanged4:
-                             Actor::AI_SpellAttack(v4, &a4, v5->pMonsterInfo.uSpell2ID, 3, v5->pMonsterInfo.uSpellSkillAndMastery2);
-                             Actor::AI_Stand(v4, a2a, 0, &a4);
-                             break;
-                           default:
-                             if ( !(rand() % 2) )
-                               Actor::AI_Bored(v4, a2a, &a4);
-                             else
-                               Actor::AI_Stand(v4, a2a, 64,&a4);
-                         }
-                    }
+          case  AIState::AttackingMelee:
+            v19 = pActors[actor_id].special_ability_use_check(actor_id);
+            AttackerInfo.Add( pQueue[queue_index].uPackedID,  5120,  pActors[actor_id].vPosition.x, pActors[actor_id].vPosition.y,
+                              pActors[actor_id].vPosition.z + ((signed int)pActors[actor_id].uActorHeight >> 1), v19,  1);
+            Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4);
+            break;
+          case AIState::AttackingRanged1:
+            Actor::AI_RangedAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uMissleAttack1Type, 0);
+            Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4);
+            break;
+          case AIState::Dying:
+            pActors[actor_id].uCurrentActionTime = 0;
+            pActors[actor_id].uCurrentActionLength = 0;
+            pActors[actor_id].uAIState = Dead;
+            pActors[actor_id].UpdateAnimation();
+            break;
+          case AIState::Stunned:
+            Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4);
+            break;
+          case AIState::AttackingRanged2:
+            Actor::AI_RangedAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uMissleAttack2Type, 1);
+            Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4);
+            break;
+          case AIState::AttackingRanged3:
+            Actor::AI_SpellAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uSpell1ID, 2, pActors[actor_id].pMonsterInfo.uSpellSkillAndMastery1);
+            Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4);
+            break;
+          case AIState::AttackingRanged4:
+            Actor::AI_SpellAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uSpell2ID, 3, pActors[actor_id].pMonsterInfo.uSpellSkillAndMastery2);
+            Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4);
+            break;
+          default:
+            if ( !(rand() % 2) )
+              Actor::AI_Bored(actor_id, ai_near_actors_targets_pid[actor_id], &a4);
+            else
+              Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 64,&a4);
         }
-
-        }
-        
+      }
     }
+  }
+}
 // 50FE08: using guessed type stru298 AttackerInfo;
 
 //----- (0040680F) --------------------------------------------------------
 void stru262_TurnBased::AI_Action_( int queue_index )
-    {
-    TurnBased_QueueElem *v2; // eax@1
-    unsigned int v3; // eax@1
-    unsigned int actor_id; // edi@2
-    Actor *v5; // ebx@2
-    AIDirection v7; // esi@10
-    int v8; // eax@10
-    int v9; // ecx@10
-    signed int v10; // eax@13
-    int v14; // eax@29
-    AIDirection a3; // [sp+Ch] [bp-44h]@10
-    AIDirection v18; // [sp+28h] [bp-28h]@10
-    int a2a; // [sp+44h] [bp-Ch]@2
-    int v20; // [sp+48h] [bp-8h]@10
-    TurnBased_QueueElem *v21; // [sp+4Ch] [bp-4h]@1
-    signed int v22; // [sp+58h] [bp+8h]@10
-
-    v2 = &pQueue[queue_index];
-    v21 = v2;
-    v2->uActionLength = 0;
-    v3 = v2->uPackedID;
-     if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor)
-        {
-   
-        actor_id = PID_ID(pQueue[queue_index].uPackedID);
-        a2a = v3;
-        v5 = &pActors[actor_id];
-        v3 = v5->uAIState;
-        if (!(v3 == AIState::Dying || v3 == AIState::Dead ||  v3 == AIState::Summoned ||
-            v3 == AIState::Disabled || v3 == AIState::Removed))
-            {
-                
-                Actor::_SelectTarget(actor_id, &ai_near_actors_targets_pid[actor_id], true);
-                v22 = ai_near_actors_targets_pid[actor_id];
-                if ( v5->pMonsterInfo.uHostilityType && !v22)
-                    v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
-                Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v22, &v7, 0);
-                v8 = v5->uActorRadius;
-                memcpy(&a3, &v7, sizeof(AIDirection));
-                memcpy(&v18, &a3, sizeof(AIDirection));
-                v9 = a3.uDistance - v8;
-                v20 = a3.uDistance - v8;
-                if ( v20 < 0 )
-                    {
-                    v9 = 0;
-                    v20 = 0;
-                    }
-
-                if (PID_TYPE(v22) == OBJECT_Actor)
-                    //v10 = (unsigned __int8)*(&byte_5C8D1A[89 * (pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID - 1) / 3] + (v5->pMonsterInfo.uID - 1) / 3);
-                    v10 = pFactionTable->relations[(pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID) / 3 + 1][(v5->pMonsterInfo.uID - 1) / 3 + 1];
-                else
-                    v10 = 4;
+{
+  unsigned int actor_id; // edi@2
+  AIDirection v7; // esi@10
+  int v9; // ecx@10
+  signed int v10; // eax@13
+  int v14; // eax@29
+  AIDirection a3; // [sp+Ch] [bp-44h]@10
+  AIDirection v18; // [sp+28h] [bp-28h]@10
+  signed int v22; // [sp+58h] [bp+8h]@10
 
-               switch (v10)
-                   {
-               case 1:
-                    if ( (double)(signed int)v20 < 307.2 )
-                        v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-                   break;
-               case 2:
-                   if ( v20 < 1024 )
-                       v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-                   break;
-               case 3:
-                   if ( v20 < 2560 )
-                       v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-                   break;
-               case 4:
-                   if ( v20 < 5120 )
-                       v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-                   break;
-                   }
-                
-                if ( v5->pMonsterInfo.uHostilityType == 4 && v22 && (signed int)v9 < 5120 )
-                    {
-                    v14 = v5->special_ability_use_check(actor_id);
-                    v21->AI_action_type = TE_AI_STAND;
-                    switch (v14)
-                        {
-                    case 1:
-                        if ( v5->pMonsterInfo.uMissleAttack2Type )
-                            {
-                            Actor::AI_MissileAttack2(actor_id, v22, &v18);
-                            v21->AI_action_type = TE_AI_RANGED_ATTACK;
-                            }   
-                        break;
-                    case 2:
-                        if(v5->pMonsterInfo.uSpell1ID)
-                            {
-                             Actor::AI_SpellAttack1(actor_id, v22, &v18);
-                            v21->AI_action_type = TE_AI_RANGED_ATTACK;
-                            }        
-                        break;
-                    case 3:
-                        if(v5->pMonsterInfo.uSpell2ID)
-                            {
-                            Actor::AI_SpellAttack2(actor_id, v22, &v18);
-                            v21->AI_action_type = TE_AI_RANGED_ATTACK;
-                            }
-                            
-                        break;
-                    default:
-                        if ( v5->pMonsterInfo.uMissleAttack1Type )
-                            {
-                            Actor::AI_MissileAttack1(actor_id, v22, &v18);
-                            v21->AI_action_type = TE_AI_RANGED_ATTACK;
-                            }
-                        }
-                     if (!v21->AI_action_type)
-                        if ( (double)v20 < 307.2)
-                            {
-                            Actor::AI_MeleeAttack(actor_id, v22, &v18);
-                            v21->AI_action_type = TE_AI_MELEE_ATTACK;
-                            }
-                        else
-                            {
-                            Actor::AI_Stand(actor_id, v22, 64, &v18);
-                            v21->AI_action_type = TE_AI_STAND;
-                            }             
+  pQueue[queue_index].uActionLength = 0;
+  if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor)
+  {
+    actor_id = PID_ID(pQueue[queue_index].uPackedID);
+    if (!(pActors[actor_id].uAIState == AIState::Dying || pActors[actor_id].uAIState == AIState::Dead || pActors[actor_id].uAIState == AIState::Summoned ||
+          pActors[actor_id].uAIState == AIState::Disabled || pActors[actor_id].uAIState == AIState::Removed))
+    {
+      Actor::_SelectTarget(actor_id, &ai_near_actors_targets_pid[actor_id], true);
+      v22 = ai_near_actors_targets_pid[actor_id];
+      if ( pActors[actor_id].pMonsterInfo.uHostilityType && !v22)
+        pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
+      Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v22, &v7, 0);
+      memcpy(&a3, &v7, sizeof(AIDirection));
+      memcpy(&v18, &a3, sizeof(AIDirection));
+      v9 = a3.uDistance - pActors[actor_id].uActorRadius;
+      if ( v9 < 0 )
+        v9 = 0;
+      if (PID_TYPE(v22) == OBJECT_Actor)
+        //v10 = (unsigned __int8)*(&byte_5C8D1A[89 * (pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID - 1) / 3] + (v5->pMonsterInfo.uID - 1) / 3);
+        v10 = pFactionTable->relations[(pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID) / 3 + 1][(pActors[actor_id].pMonsterInfo.uID - 1) / 3 + 1];
+      else
+        v10 = 4;
+      switch (v10)
+      {
+        case 1:
+          if ( (double)(signed int)v9 < 307.2 )
+            pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+          break;
+        case 2:
+          if ( v9 < 1024 )
+            pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+          break;
+        case 3:
+          if ( v9 < 2560 )
+            pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+          break;
+        case 4:
+          if ( v9 < 5120 )
+            pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+          break;
+      }
+      if ( pActors[actor_id].pMonsterInfo.uHostilityType == 4 && v22 && (signed int)v9 < 5120 )
+      {
+        v14 = pActors[actor_id].special_ability_use_check(actor_id);
+        pQueue[queue_index].AI_action_type = TE_AI_STAND;
+        switch (v14)
+        {
+          case 1:
+            if ( pActors[actor_id].pMonsterInfo.uMissleAttack2Type )
+            {
+              Actor::AI_MissileAttack2(actor_id, v22, &v18);
+              pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK;
             }
-                else
-                    {
-                    Actor::AI_Stand(actor_id, v22, 64, &v18);
-                    v21->AI_action_type = TE_AI_STAND;
-                    }
-               v21->uActionLength = v5->uCurrentActionLength;
+            break;
+          case 2:
+            if ( pActors[actor_id].pMonsterInfo.uSpell1ID )
+            {
+              Actor::AI_SpellAttack1(actor_id, v22, &v18);
+              pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK;
+            }
+            break;
+          case 3:
+            if (pActors[actor_id].pMonsterInfo.uSpell2ID)
+            {
+              Actor::AI_SpellAttack2(actor_id, v22, &v18);
+              pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK;
+            }
+            break;
+          default:
+            if ( pActors[actor_id].pMonsterInfo.uMissleAttack1Type )
+            {
+              Actor::AI_MissileAttack1(actor_id, v22, &v18);
+              pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK;
+            }
         }
-        }
+        //if (!pQueue[queue_index].AI_action_type)
+          if ( (double)v9 < 307.2)
+          {
+            Actor::AI_MeleeAttack(actor_id, v22, &v18);
+            pQueue[queue_index].AI_action_type = TE_AI_MELEE_ATTACK;
+            pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength;
+            return;
+          }
+          else
+          {
+            Actor::AI_Stand(actor_id, v22, 64, &v18);
+            pQueue[queue_index].AI_action_type = TE_AI_STAND;
+            pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength;
+            return;
+          }
+      }
+      else
+      {
+        Actor::AI_Stand(actor_id, v22, 64, &v18);
+        pQueue[queue_index].AI_action_type = TE_AI_STAND;
+      }
+      pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength;
     }
+  }
+}
 
 //----- (00406A63) --------------------------------------------------------
 void stru262_TurnBased::ActorAISetMovementDecision()
-    {
-  
-    AIDirection a3; // [sp+8h] [bp-44h]@5
-    AIDirection v7; // [sp+24h] [bp-28h]@5
-    unsigned int target_pid; // [sp+40h] [bp-Ch]@5
-    int i;
+{
+  AIDirection a3; // [sp+8h] [bp-44h]@5
+  AIDirection v7; // [sp+24h] [bp-28h]@5
+  unsigned int target_pid; // [sp+40h] [bp-Ch]@5
+  int i;
 
-    this->ai_turn_timer = 64;
-    dword_50C994 = 0;
-    uActiveCharacter = 0;
-    for (i=0; i<uActorQueueSize; ++i )
-        {
-        if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
-            {
-            target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
-            Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0);
-            if ( !ActorMove(i) )
-                Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
-            }
-        }   
+  this->ai_turn_timer = 64;
+  dword_50C994 = 0;
+  uActiveCharacter = 0;
+  for ( i = 0; i < uActorQueueSize; ++i )
+  {
+    if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
+    {
+      target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
+      Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0);
+      if ( !ActorMove(i) )
+        Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
     }
+  }
+}
 // 50C994: using guessed type int dword_50C994;
 
 //----- (00406AFE) --------------------------------------------------------
 void stru262_TurnBased::ActorAIStopMovement()
-    {
-    AIDirection a3; // [sp+4h] [bp-48h]@5
-    AIDirection v7; // [sp+20h] [bp-2Ch]@5
-    unsigned int target_pid; 
-    int i;
+{
+  AIDirection a3; // [sp+4h] [bp-48h]@5
+  AIDirection v7; // [sp+20h] [bp-2Ch]@5
+  unsigned int target_pid; 
+  int i;
 
-    for (i=0; i<uActorQueueSize; ++i )
-        {
-        if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
-            {
-            target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
-            Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0);
-            Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
-            pQueue[i].AI_action_type = TE_AI_STAND;
-            pQueue[i].uActionLength = 0;
-            }
-        }   
-    turn_stage = 2;
-    ai_turn_timer = 100;
-
+  for ( i = 0; i < uActorQueueSize; ++i )
+  {
+    if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
+    {
+      target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
+      Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0);
+      Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
+      pQueue[i].AI_action_type = TE_AI_STAND;
+      pQueue[i].uActionLength = 0;
     }
+  }
+  turn_stage = TE_ATTACK;
+  ai_turn_timer = 100;
+}
 
 //----- (00406B9F) --------------------------------------------------------
 void stru262_TurnBased::ActorAIDoAdditionalMove()
+{
+  AIDirection a3; // [sp+0h] [bp-50h]@15
+  AIDirection v9; // [sp+1Ch] [bp-34h]@15
+  unsigned int v13; // [sp+44h] [bp-Ch]@8
+  unsigned int monster_id;
+
+  for ( int i = 0; i < uActorQueueSize; ++i )
+  {
+    if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
     {
-    Actor *v6; // ebx@5
-    AIDirection a3; // [sp+0h] [bp-50h]@15
-    AIDirection v9; // [sp+1Ch] [bp-34h]@15
-    unsigned int v13; // [sp+44h] [bp-Ch]@8
-    int i;
-
-    for (i=0; i<uActorQueueSize; ++i )
+      monster_id = PID_ID(pQueue[i].uPackedID);
+      if ( !(pActors[monster_id].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0|| (pActors[monster_id].pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0) || 
+             pActors[monster_id].uAIState == AIState::Dead || pActors[monster_id].uAIState == AIState::Removed || pActors[monster_id].uAIState == AIState::Disabled) )
+      {
+        v13 = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
+        Actor::GetDirectionInfo(pQueue[i].uPackedID, v13, &v9, 0);
+        if ( pActors[monster_id].uAIState == AIState::Pursuing || pActors[monster_id].uAIState == AIState::Tethered ) 
         {
-        if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
+          if ( (double)(signed int)v9.uDistance < 307.2 )
+            Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
+        }
+        else
+        {
+          pActors[monster_id].uCurrentActionTime += pEventTimer->uTimeElapsed;
+          if ( pActors[monster_id].uCurrentActionTime > pActors[monster_id].uCurrentActionLength )
+          {
+            if ( pActors[monster_id].uAIState == AIState::Dying )
             {
-            v6 = &pActors[PID_ID(pQueue[i].uPackedID)];
-            if ( !(v6->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0|| (v6->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0) || 
-                    v6->uAIState == AIState::Dead || v6->uAIState == AIState::Removed || v6->uAIState == AIState::Disabled) )
-                {
-                v13 = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
-                Actor::GetDirectionInfo(pQueue[i].uPackedID, v13, &v9, 0);
-                if ( v6->uAIState == AIState::Pursuing || v6->uAIState == AIState::Tethered ) 
-                    {
-                    if ( (double)(signed int)v9.uDistance < 307.2 )
-                        Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
-                    }
-                else
-                    {           
-                    v6->uCurrentActionTime += pEventTimer->uTimeElapsed;
-                    if ( v6->uCurrentActionTime > v6->uCurrentActionLength )
-                        {
-                        if ( v6->uAIState == AIState::Dying )
-                            {
-                            v6->uCurrentActionTime = 0;
-                            v6->uCurrentActionLength = 0;
-                            v6->uAIState = AIState::Dead;
-                            v6->UpdateAnimation();
-                            }
-                        if ( !ActorMove(i) )
-                            Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
-                        }
-                    }
-                }
+              pActors[monster_id].uCurrentActionTime = 0;
+              pActors[monster_id].uCurrentActionLength = 0;
+              pActors[monster_id].uAIState = AIState::Dead;
+              pActors[monster_id].UpdateAnimation();
             }
+            if ( !ActorMove(i) )
+              Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
+          }
         }
+      }
     }
+  }
+}
 
 //----- (00406D10) --------------------------------------------------------
 bool stru262_TurnBased::ActorMove(signed int queue_position)
-    {
-    int v2; // ecx@1
-    //int v3; // ecx@2
-    Actor *actor; // ebx@2
-
-    AIDirection v9; // esi@10
-    int v10; // eax@10
-    int v11; // ecx@10
-    unsigned __int8 pHostileType; // al@12
-    AIDirection a3; // [sp+Ch] [bp-48h]@10
-    AIDirection pDir; // [sp+28h] [bp-2Ch]@10
-    int v28; // [sp+48h] [bp-Ch]@10
-    TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7
-    unsigned int uActorID; // [sp+50h] [bp-4h]@2
-    unsigned int a2a; // [sp+5Ch] [bp+8h]@7
-
-    // __debugbreak();//ñðàáàòûâàåò ïðè ïîøàãîâîì ðåæèìå ïîñëå ïÿòè øàãîâ
-    v2 = pQueue[queue_position].uPackedID;
-    if (PID_TYPE(v2) == OBJECT_Player)
-        return 0;
-    uActorID = PID_ID(v2);
-    //uActorID = v3;
-    actor = &pActors[uActorID];
-    //v5 = v4->uAIState;
-    if ( actor->uAIState == AIState::Dead || actor->uAIState ==  AIState::Dying || 
-         actor->uAIState == AIState::Removed|| actor->uAIState == AIState::Disabled || 
-         actor->uAIState == AIState::Summoned  )
-        return 1;
-    v29 = &pTurnEngine->pQueue[queue_position];
-    a2a = ai_near_actors_targets_pid[uActorID];
-    Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);
-    if ( actor->pMonsterInfo.uHostilityType && !ai_near_actors_targets_pid[uActorID] )
-        actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
-    Actor::GetDirectionInfo(pQueue[queue_position].uPackedID, ai_near_actors_targets_pid[uActorID], &v9, 0);
-    v10 = actor->uActorRadius;
-    memcpy(&a3, &v9, sizeof(AIDirection));
-    memcpy(&pDir, &a3, sizeof(AIDirection));
-    v11 = a3.uDistance - v10;
-    v28 = a3.uDistance - v10;
-    if ( v28 < 0 )
-        {
-        v11 = 0;
-        v28 = 0;
-        }
-    pHostileType = actor->pMonsterInfo.uHostilityType;
-   
-    switch (pHostileType)
-        {
-    case 1:
-        if ( (double)v28 < 307.2 )
-            actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-        break;
-    case 2:
-        if ( v28 < 1024 )
-            actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-        break;
-    case 3:
-        if ( v28 < 2560 )
-            actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-        break;
-        }
-
-    if ( actor->pActorBuffs[ACTOR_BUFF_AFRAID].uExpireTime > 0 )
-        {
-        if (v11 < 10240 )
-            {
-            Actor::AI_Flee(uActorID, a2a, 0, &pDir);
-            v29->AI_action_type = 4;
-            }
-        else
-            {
-             Actor::AI_RandomMove(uActorID, a2a, 1024, 0);
-             v29->AI_action_type = TE_AI_PURSUE;
-            }         
-    
-        v29->uActionLength = actor->uCurrentActionLength;
-        return 1;
-        }
+{
+  AIDirection v9; // esi@10
+  int v11; // ecx@10
+  unsigned __int8 pHostileType; // al@12
+  AIDirection a3; // [sp+Ch] [bp-48h]@10
+  AIDirection pDir; // [sp+28h] [bp-2Ch]@10
+  unsigned int uActorID; // [sp+50h] [bp-4h]@2
 
-    if ( actor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long )
-  {     
-    if ( !(actor->uAttributes & 0x020000) || actor->pMonsterInfo.uAIType == 1 )
+  if (PID_TYPE(pQueue[queue_position].uPackedID) == OBJECT_Player)
+    return 0;
+  uActorID = PID_ID(pQueue[queue_position].uPackedID);
+  if ( pActors[uActorID].uAIState == AIState::Dead || pActors[uActorID].uAIState ==  AIState::Dying || 
+       pActors[uActorID].uAIState == AIState::Removed|| pActors[uActorID].uAIState == AIState::Disabled || 
+       pActors[uActorID].uAIState == AIState::Summoned  )
+    return 1;
+  Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);
+  if ( pActors[uActorID].pMonsterInfo.uHostilityType && !ai_near_actors_targets_pid[uActorID] )
+    pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
+  Actor::GetDirectionInfo(pQueue[queue_position].uPackedID, ai_near_actors_targets_pid[uActorID], &v9, 0);
+  memcpy(&a3, &v9, sizeof(AIDirection));
+  memcpy(&pDir, &a3, sizeof(AIDirection));
+  v11 = a3.uDistance - pActors[uActorID].uActorRadius;
+  if ( v11 < 0 )
+    v11 = 0;
+  pHostileType = pActors[uActorID].pMonsterInfo.uHostilityType;
+  switch (pHostileType)
+  {
+    case 1:
+      if ( (double)v11 < 307.2 )
+        pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+      break;
+    case 2:
+      if ( v11 < 1024 )
+        pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+      break;
+    case 3:
+      if ( v11 < 2560 )
+        pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+      break;
+  }
+  if ( pActors[uActorID].pActorBuffs[ACTOR_BUFF_AFRAID].uExpireTime > 0 )
+  {
+    if (v11 < 10240 )
+    {
+      Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 0, &pDir);
+      pTurnEngine->pQueue[queue_position].AI_action_type = 4;
+    }
+    else
+    {
+      Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 1024, 0);
+      pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE;
+    }
+    pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
+    return true;
+  }
+  if ( pActors[uActorID].pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long )
+  {
+    if ( !(pActors[uActorID].uAttributes & 0x020000) || pActors[uActorID].pMonsterInfo.uAIType == 1 )
+    {
+      if ( pActors[uActorID].pMonsterInfo.uAIType == 1 )
+      {
+        if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
+          Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
+        else
+          Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
+        pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE;
+        pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
+        return true;
+      }
+      if ( pActors[uActorID].pMonsterInfo.uAIType == 2 )
+      {
+        if (((double)pActors[uActorID].pMonsterInfo.uHP * 0.2) > (double)pActors[uActorID].sCurrentHP && (v11 < 10240 ) )
         {
-        if ( actor->pMonsterInfo.uAIType == 1 )
-            {
-            if ( actor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
-                Actor::AI_Stand(uActorID, a2a, 32, 0);
-            else
-                Actor::AI_Flee(uActorID, a2a, 32, 0);
-            v29->AI_action_type = TE_AI_FLEE;
-            v29->uActionLength = actor->uCurrentActionLength;
-            return 1;
-            }
-        if ( actor->pMonsterInfo.uAIType == 2 )
-            {
-           
-            if (((double)actor->pMonsterInfo.uHP * 0.2) > (double)actor->sCurrentHP && (v11 < 10240 ) )
-                {
-                if ( actor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
-                    Actor::AI_Stand(uActorID, a2a, 32, 0);
-                else
-                     Actor::AI_Flee(uActorID, a2a, 32, 0);
-                v29->AI_action_type = TE_AI_FLEE;
-                v29->uActionLength = actor->uCurrentActionLength;
-                return 1;
-                }
-            }
-        if ( actor->pMonsterInfo.uAIType == 3 )
-            {
-
-            if ( ((double)actor->pMonsterInfo.uHP * 0.1) > (double)actor->sCurrentHP && (v11 < 10240 ))
-                {
-                if ( actor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
-                    Actor::AI_Stand(uActorID, a2a, 32, 0);
-                else
-                     Actor::AI_Flee(uActorID, a2a, 32, 0);
-                v29->AI_action_type = TE_AI_FLEE;
-                v29->uActionLength = actor->uCurrentActionLength;
-                return 1;
-                }
-
-            }
+          if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
+            Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
+          else
+            Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
+          pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE;
+          pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
+          return true;
+        }
+      }
+      if ( pActors[uActorID].pMonsterInfo.uAIType == 3 )
+      {
+        if ( ((double)pActors[uActorID].pMonsterInfo.uHP * 0.1) > (double)pActors[uActorID].sCurrentHP && (v11 < 10240 ))
+        {
+          if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
+            Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
+          else
+            Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
+          pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE;
+          pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
+          return true;
         }
-
-    if ( (double)(signed int)v28 < 307.2 )
-        return 0;
+      }
+    }
+    if ( (double)(signed int)v11 < 307.2 )
+      return 0;
     if ( (signed int)v11 < 5120 )
-        {
-        if ( actor->pMonsterInfo.uMissleAttack1Type && (signed int)v11 < 1024 )
-            Actor::AI_Pursue1(uActorID, a2a, uActorID, 32, &pDir);
-        else
-            Actor::AI_Pursue2(uActorID, a2a, 32, &pDir, 307);
-        v29->AI_action_type = TE_AI_PURSUE;
-        v29->uActionLength = actor->uCurrentActionLength;
-        return 1;
-        }
-        }
-    switch(actor->pMonsterInfo.uMovementType)
-        {
-        case MONSTER_MOVEMENT_TYPE_SHORT: 
-            Actor::AI_RandomMove(uActorID, a2a, 1024, 32);
-            break;
-        case MONSTER_MOVEMENT_TYPE_MEDIUM:
-             Actor::AI_RandomMove(uActorID, a2a, 2560, 32);
-             break;
-         case MONSTER_MOVEMENT_TYPE_LONG:
-             Actor::AI_RandomMove(uActorID, a2a, 5120, 32);
-             break;
-         case MONSTER_MOVEMENT_TYPE_FREE:
-             Actor::AI_RandomMove(uActorID, a2a, 10240, 32);
-             break;
-         case MONSTER_MOVEMENT_TYPE_STAIONARY:
-             Actor::AI_Stand(uActorID, a2a, 32, 0);
-              break;
-         default:
-             return 1;
-        }
-    v29->AI_action_type = TE_AI_PURSUE;
-    v29->uActionLength = actor->uCurrentActionLength;
-    return 1;
+    {
+      if ( pActors[uActorID].pMonsterInfo.uMissleAttack1Type && (signed int)v11 < 1024 )
+        Actor::AI_Pursue1(uActorID, ai_near_actors_targets_pid[uActorID], uActorID, 32, &pDir);
+      else
+        Actor::AI_Pursue2(uActorID, ai_near_actors_targets_pid[uActorID], 32, &pDir, 307);
+      pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE;
+      pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
+      return true;
     }
+  }
+  switch(pActors[uActorID].pMonsterInfo.uMovementType)
+  {
+    case MONSTER_MOVEMENT_TYPE_SHORT: 
+      Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 1024, 32);
+      break;
+    case MONSTER_MOVEMENT_TYPE_MEDIUM:
+      Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 2560, 32);
+      break;
+    case MONSTER_MOVEMENT_TYPE_LONG:
+      Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 5120, 32);
+      break;
+    case MONSTER_MOVEMENT_TYPE_FREE:
+      Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 10240, 32);
+      break;
+    case MONSTER_MOVEMENT_TYPE_STAIONARY:
+      Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
+      break;
+    default:
+      return true;
+  }
+  pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE;
+  pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
+  return true;
+}
 
     //----- (00406FA8) --------------------------------------------------------
 void stru262_TurnBased::ActorAIChooseNewTargets()
+{
+  Actor *curr_acror; // ebx@4
+  AIDirection a3; // [sp+Ch] [bp-6Ch]@8
+  AIDirection v9; // [sp+28h] [bp-50h]@8
+  AIDirection a4; // [sp+44h] [bp-34h]@8
+  unsigned int target_pid; // [sp+60h] [bp-18h]@1
+  int uActorID; // [sp+68h] [bp-10h]@4
+  int i;
+
+  for ( i = 0; i < uActorQueueSize; ++i )
+  {
+    if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
     {
-    Actor *curr_acror; // ebx@4
-    AIDirection a3; // [sp+Ch] [bp-6Ch]@8
-    AIDirection v9; // [sp+28h] [bp-50h]@8
-    AIDirection a4; // [sp+44h] [bp-34h]@8
-    unsigned int target_pid; // [sp+60h] [bp-18h]@1
-    int uActorID; // [sp+68h] [bp-10h]@4
-    int i;
-
-    for (i=0; i<uActorQueueSize; ++i )
+      uActorID=PID_ID(pQueue[i].uPackedID);
+      curr_acror = &pActors[uActorID];
+      if ( !( curr_acror->uAIState == AIState::Summoned|| curr_acror->uAIState == AIState::Dead ||
+              curr_acror->uAIState == AIState::Removed || curr_acror->uAIState == AIState::Disabled) )
+      {
+        target_pid = ai_near_actors_targets_pid[uActorID];
+        Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);
+        Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v9, 0);
+        memcpy(&a4, &v9, sizeof(AIDirection));
+        curr_acror->uCurrentActionTime += pEventTimer->uTimeElapsed;
+        if ( curr_acror->uCurrentActionTime > curr_acror->uCurrentActionLength )
         {
-        if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
-            {
-            uActorID=PID_ID(pQueue[i].uPackedID);
-            curr_acror = &pActors[uActorID];
-            if ( !( curr_acror->uAIState == AIState::Summoned|| curr_acror->uAIState == AIState::Dead ||
-                    curr_acror->uAIState == AIState::Removed || curr_acror->uAIState == AIState::Disabled) )
-                { 
-                target_pid = ai_near_actors_targets_pid[uActorID];      
-                Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);  
-                Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v9, 0);
-                memcpy(&a4, &v9, sizeof(AIDirection));     
-                curr_acror->uCurrentActionTime += pEventTimer->uTimeElapsed;
-                if ( curr_acror->uCurrentActionTime > curr_acror->uCurrentActionLength )
-                    {
-                    if ( curr_acror->uAIState == AIState::Dying )
-                        {
-                        curr_acror->uCurrentActionTime = 0;
-                        curr_acror->uCurrentActionLength = 0;
-                        curr_acror->uAIState = AIState::Dead;
-                        curr_acror->UpdateAnimation();
-                        break;
-                        }
-                    if ( rand() % 2 )
-                        Actor::AI_Stand(uActorID, target_pid, 64, &a4);
-                    else
-                        Actor::AI_Bored(uActorID, target_pid, &a4);
-                    }
-                }
-            }
+          if ( curr_acror->uAIState == AIState::Dying )
+          {
+            curr_acror->uCurrentActionTime = 0;
+            curr_acror->uCurrentActionLength = 0;
+            curr_acror->uAIState = AIState::Dead;
+            curr_acror->UpdateAnimation();
+            break;
+          }
+          if ( rand() % 2 )
+            Actor::AI_Stand(uActorID, target_pid, 64, &a4);
+          else
+            Actor::AI_Bored(uActorID, target_pid, &a4);
         }
+      }
     }
+  }
+}
 
--- a/TurnEngine.h	Wed Feb 26 01:14:18 2014 +0100
+++ b/TurnEngine.h	Wed Feb 26 01:15:58 2014 +0100
@@ -2,23 +2,29 @@
 
 
 enum TURN_ENGINE_FLAGS
-    {
-    TE_FLAG_1 =1,
-    TE_HAVE_PENDING_ACTIONS =2,
-    TE_PLAYER_TURN =4,
-    TE_FLAG_8 =8
-    };
+{
+  TE_FLAG_1               = 1,
+  TE_HAVE_PENDING_ACTIONS = 2,
+  TE_PLAYER_TURN          = 4,
+  TE_FLAG_8               = 8
+};
 
 enum TURN_ENGINE_AI_ACTION
-    {
-    TE_AI_STAND         =0,
-    TE_AI_RANGED_ATTACK =1,
-    TE_AI_PURSUE        =2,
-    TE_AI_MELEE_ATTACK  =3,
-    TE_AI_FLEE          =4
-    };
+{
+  TE_AI_STAND         = 0,
+  TE_AI_RANGED_ATTACK = 1,
+  TE_AI_PURSUE        = 2,
+  TE_AI_MELEE_ATTACK  = 3,
+  TE_AI_FLEE          = 4
+};
 
-
+enum TURN_ENGINE_TURN_STAGE
+{
+  TE_NONE             = 0,
+  TE_WAIT             = 1,
+  TE_ATTACK           = 2,
+  TE_MOVEMENT         = 3,
+};
 
 /*  299 */
 #pragma pack(push, 1)
--- a/UI/UiGame.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/UI/UiGame.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -1771,7 +1771,7 @@
   }
   if ( pParty->bTurnBasedModeOn == 1 )
   {
-    if ( pTurnEngine->turn_stage != 1 )
+    if ( pTurnEngine->turn_stage != TE_WAIT )
     {
       if (PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player)
       {
--- a/Viewport.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/Viewport.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -471,7 +471,7 @@
         pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, mon_id, 0);
         return;
       }
-      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3 )
+      if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT )
       {
         pTurnEngine->field_18 |= TE_FLAG_8;
         return;
@@ -480,7 +480,7 @@
     }
     else
     {
-      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3 )
+      if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT )
       {
         pParty->uFlags |= PARTY_FLAGS_1_FALLING;
         return;
--- a/mm7_3.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/mm7_3.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -705,7 +705,7 @@
       {
         v8 *= 2;
       }
-      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 1 )
+      if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_WAIT )
         v8 *= flt_6BE3AC_debug_recmod1_x_1_6;
       if ( v8 > 1000 )
         v8 = 1000;
@@ -854,7 +854,7 @@
       switch ( PID_TYPE(stru_721530.uFaceID) )
       {
         case OBJECT_Actor:
-          if ( pTurnEngine->turn_stage != 2 && pTurnEngine->turn_stage != 3 || pParty->bTurnBasedModeOn != 1 )
+          if ( pTurnEngine->turn_stage != TE_ATTACK && pTurnEngine->turn_stage != TE_MOVEMENT || pParty->bTurnBasedModeOn != TE_WAIT )
           {
 			//if(pParty->bTurnBasedModeOn == 1)
 				//v34 = 0;
--- a/mm7_4.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/mm7_4.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -2130,7 +2130,7 @@
 {
   const char *v2; // edi@1
 
-  __debugbreak();
+  //__debugbreak();
   uDialogueType = DIALOGUE_SKILL_TRAINER;
   current_npc_text = (char *)pNPCTopics[a4 + 168].pText;
   _4B254D_SkillMasteryTeacher(a4);  //might be needed because of contract_approved ?
@@ -2142,7 +2142,7 @@
   v2 = "";
   if ( contract_approved )
     v2 = pGlobalTXT_LocalizationStrings[535];
-  pDialogueWindow->CreateButton(0x1E0u, 0xA0u, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x4Fu, 0, v2, 0);
+  pDialogueWindow->CreateButton(480, 160, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x4Fu, 0, v2, 0);
   pDialogueWindow->_41D08F_set_keyboard_control_group(1, 1, 0, 2);
   dialog_menu_id = HOUSE_DIALOGUE_OTHER;
 }
--- a/mm7_5.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/mm7_5.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -556,9 +556,7 @@
       v6 = 0;
   }
   else
-  {
     v6 = 31;
-  }
   return v6;
 }
 
--- a/mm7_6.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/mm7_6.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -211,9 +211,7 @@
     result = a3;
   }
   else
-  {
     result = 0;
-  }
   return result;
 }
 
@@ -279,7 +277,6 @@
   }
 }
 
-
 //----- (0042EBDB) --------------------------------------------------------
 int stru193_math::Sin(int angle)
 {
@@ -289,46 +286,12 @@
 //----- (0042ECB5) --------------------------------------------------------
 void _42ECB5_PlayerAttacksActor()
 {
-  //unsigned int v0; // ebx@1
-  //Player *v1; // esi@1
-  //bool result; // eax@1
-  //int v3; // edi@2
-  //unsigned int v4; // eax@7
   char *v5; // eax@8
-  //int v6; // ecx@9
-  //signed int v7; // eax@16
-  //Actor *v8; // edi@20
   unsigned int v9; // ecx@21
-  //char *v10; // eax@26
   char *v11; // eax@26
   unsigned int v12; // eax@47
-  //char *v13; // eax@47
-  //char *v14; // eax@47
-  //unsigned int v15; // ebx@54
-  //int v16; // [sp-10h] [bp-4Ch]@24
-  //int v17; // [sp-10h] [bp-4Ch]@44
-  //unsigned int v18; // [sp-Ch] [bp-48h]@24
-  //unsigned int v19; // [sp-Ch] [bp-48h]@44
-  //__int16 v20; // [sp-8h] [bp-44h]@24
-  //__int16 v21; // [sp-8h] [bp-44h]@44
-  //int v22; // [sp-4h] [bp-40h]@24
-  //int v23; // [sp-4h] [bp-40h]@44
   SoundID v24; // [sp-4h] [bp-40h]@58
-  //Vec3_int_ a3; // [sp+Ch] [bp-30h]@19
-  //unsigned int a2; // [sp+18h] [bp-24h]@20
-  //unsigned int v27; // [sp+1Ch] [bp-20h]@1
-  //int v28; // [sp+20h] [bp-1Ch]@9
-  //unsigned int *v28b;
-  //int v29; // [sp+24h] [bp-18h]@16
-  //int v30; // [sp+28h] [bp-14h]@16
-  //int v31; // [sp+2Ch] [bp-10h]@4
-  //int v32; // [sp+30h] [bp-Ch]@7
-  //int v33; // [sp+34h] [bp-8h]@7
-  //int v34; // [sp+38h] [bp-4h]@17
 
-  //v0 = uActiveCharacter;
-  //v27 = 6972 * uActiveCharacter;
-  //v1 = &pParty->pPlayers[uActiveCharacter-1];
   //result = pParty->pPlayers[uActiveCharacter-1].CanAct();
   Player* player = &pParty->pPlayers[uActiveCharacter - 1];
   if (!player->CanAct())
@@ -638,7 +601,7 @@
   {
     char icon_name[32];
     sprintf(icon_name, "turn%u", i);
-    pIconIDs_Turn[i] = pIconsFrameTable->FindIcon("turn0");
+    pIconIDs_Turn[i] = pIconsFrameTable->FindIcon(icon_name);
     pIconsFrameTable->InitializeAnimation(pIconIDs_Turn[i]);
   }
 
@@ -914,7 +877,7 @@
               pPartyActionQueue->Add(partyAction);
               break;
             }
-            if (pTurnEngine->turn_stage != 1 && pTurnEngine->turn_stage != 2 && pTurnEngine->uActionPointsLeft > 0 )
+            if (pTurnEngine->turn_stage != TE_WAIT && pTurnEngine->turn_stage != TE_ATTACK && pTurnEngine->uActionPointsLeft > 0 )
             {
               pTurnEngine->uActionPointsLeft -= 26;
               if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)
@@ -937,7 +900,7 @@
               pPartyActionQueue->Add(partyAction);
               break;
             }
-            if ( pTurnEngine->turn_stage != 1 && pTurnEngine->turn_stage != 2 && pTurnEngine->uActionPointsLeft > 0 )
+            if ( pTurnEngine->turn_stage != TE_WAIT && pTurnEngine->turn_stage != TE_ATTACK && pTurnEngine->uActionPointsLeft > 0 )
             {
               pTurnEngine->uActionPointsLeft -= 26;
               if ( pParty->uFlags2 & 2 )
@@ -957,7 +920,7 @@
               pPartyActionQueue->Add(partyAction);
               break;
             }
-            if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 2 || pTurnEngine->uActionPointsLeft <= 0 )
+            if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 )
               break;
             pTurnEngine->uActionPointsLeft -= 26;
             partyAction = PARTY_StrafeLeft;
@@ -972,7 +935,7 @@
               pPartyActionQueue->Add(partyAction);
               break;
             }
-            if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 2 || pTurnEngine->uActionPointsLeft <= 0 )
+            if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 )
               break;
             pTurnEngine->uActionPointsLeft -= 26;
             partyAction = PARTY_StrafeRight;
@@ -985,7 +948,7 @@
             {
               if (pParty->bTurnBasedModeOn)
               {
-                if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 2 || pTurnEngine->uActionPointsLeft <= 0 )
+                if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 )
                   break;
                 pTurnEngine->uActionPointsLeft -= 26;
               }
@@ -1009,7 +972,7 @@
             {
               if (pParty->bTurnBasedModeOn)
               {
-                if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 2 || pTurnEngine->uActionPointsLeft <= 0 )
+                if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 )
                   break;
                 pTurnEngine->uActionPointsLeft -= 26;
               }
@@ -1042,7 +1005,7 @@
           case INPUT_Pass:
             if ( pCurrentScreen )
               break;
-            if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == 3)
+            if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == TE_MOVEMENT)
             {
               pTurnEngine->field_18 |= TE_FLAG_8;
               break;
@@ -1063,7 +1026,7 @@
             {
               if (pParty->bTurnBasedModeOn)
               {
-                if (pTurnEngine->turn_stage == 3 || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player)
+                if (pTurnEngine->turn_stage == TE_MOVEMENT || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player)
                 {
                   pParty->bTurnBasedModeOn = 0;
                   pTurnEngine->End(true);
@@ -1079,7 +1042,7 @@
           case INPUT_CastReady:
             if (pCurrentScreen != SCREEN_GAME)
               break;
-            if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == 3)
+            if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == TE_MOVEMENT)
             {
               pTurnEngine->field_18 |= TE_FLAG_8;
               break;
@@ -1105,7 +1068,7 @@
           case INPUT_Attack:
             if (pCurrentScreen != SCREEN_GAME)
               break;
-            if (pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3)
+            if (pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT)
             {
               pTurnEngine->field_18 |= TE_FLAG_8;
               break;
--- a/mm7_7.cpp	Wed Feb 26 01:14:18 2014 +0100
+++ b/mm7_7.cpp	Wed Feb 26 01:15:58 2014 +0100
@@ -37,7 +37,6 @@
 //----- (00423B4A) --------------------------------------------------------
 void  sub_423B4A()
 {
-	//__debugbreak();//Ritor1
   for ( uint i = 0; i < 50; i++ )
     array_507D30[i].flt_2C = 0.0;
 }