changeset 2225:080fd5a5433d

Merge
author Grumpy7
date Wed, 19 Feb 2014 22:30:39 +0100
parents c2eeeb991a87 (current diff) 17bc3a1eb037 (diff)
children 5944810e88e2 10c909eb6766
files CastSpellInfo.cpp Game.cpp Indoor.cpp Player.cpp UI/UiGame.cpp
diffstat 47 files changed, 3351 insertions(+), 4374 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Actor.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -2041,7 +2041,7 @@
   v7 = stru_5C6E00->Atan2(actor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x, actor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
   v9 = stru_5C6E00->uIntegerPi + actor->uYawAngle + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v7;
 
-  if ( BYTE1(v9) & 7 )      // turned away - just stand
+  if ( v9 & 0x700 )      // turned away - just stand
     Actor::AI_Stand(uActorID, uObjID, actor->uCurrentActionLength, a4);
   else                      // facing player - play bored anim
   {
@@ -2932,9 +2932,7 @@
 	if ( uCurrentlyLoadedLevelType != LEVEL_Indoor && pParty->armageddon_timer > 0 )
 	{
 		if ( pParty->armageddon_timer > 417 )
-		{
 			pParty->armageddon_timer = 0;
-		}
 		else
 		{
 			pParty->sRotationY = (stru_5C6E00->uIntegerDoublePi - 1) & (pParty->sRotationY + rand() % 16 - 8);
@@ -2960,9 +2958,7 @@
 						if ( sDmg )
 						{
 							if ( pActor->sCurrentHP >= 0 )
-							{
 								Actor::AI_Stun(i, 4, 0);
-							}
 							else
 							{
 								Actor::Die(i);
@@ -2990,7 +2986,6 @@
 		return;
 	}
 	
-	
 	for (uint i = 0; i < uNumActors; ++i)
 	{
 		pActor = &pActors[i];
@@ -3061,17 +3056,13 @@
 			radiusMultiplier = 1.0;
 		v22 = pActor->uAIState;
 		if ( v22 == Dying || v22 == Dead || v22 == Removed || v22 == Disabled || v22 == Summoned)
-		{
 			continue;
-		}
 		if ( !pActor->sCurrentHP )
 			Actor::Die(actor_id);
 		for(int i=0;i<22;i++)
 		{
 			if ( i != 10 )
-			{
 				pActor->pActorBuffs[i].IsBuffExpiredToTime(pParty->uTimePlayed);
-			}
 		}
 		if ( pActor->pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime < 0 )
 			pActor->uActorHeight = pMonsterList->pMonsters[pActor->pMonsterInfo.uID - 1].uMonsterHeight;
@@ -3110,21 +3101,11 @@
 			&&  !pActor->pMonsterInfo.uMissleAttack1Type || uAIState != Stunned )
 		{
 			if ( (signed int)pActor->uCurrentActionTime < pActor->uCurrentActionLength )
-			{
 				continue;
-			}
 			else if ( pActor->uAIState == AttackingMelee )
 			{
 				v35 = pActor->special_ability_use_check(actor_id);
-				AttackerInfo.Add(
-					a1,
-					5120,
-					pActor->vPosition.x,
-					pActor->vPosition.y,
-					pActor->vPosition.z + ((signed int)pActor->uActorHeight >> 1),
-					v35,
-					1
-				);
+				AttackerInfo.Add(a1, 5120, pActor->vPosition.x, pActor->vPosition.y, pActor->vPosition.z + ((signed int)pActor->uActorHeight >> 1), v35, 1 );
 			}
 			else if ( pActor->uAIState == AttackingRanged1 )
 			{
@@ -3159,22 +3140,14 @@
         v37 =pFactionTable->relations[(pActor->pMonsterInfo.uID-1) / 3 + 1][(pActors[PID_ID(target_pid)].pMonsterInfo.uID - 1) / 3 + 1];
 			}
 			else
-			{
 				v37 = 4;
-			}
-			v38=0;
+			v38 = 0;
 			if ( v37 == 2 )
-			{
 				v38 = 1024;
-			}
 			else if ( v37 == 3 )
-			{
 				v38 = 2560;
-			}
 			else if ( v37 == 4 )
-			{
 				v38 = 5120;
-			}
 			if ( v37 >= 1 && v37 <= 4 && v36 < v38  || v37 == 1 )
 				pActor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
 		}
@@ -3182,9 +3155,7 @@
 		if (pActor->pActorBuffs[ACTOR_BUFF_AFRAID].uExpireTime > 0)
 		{
 			if ( (signed int)v36 >= 10240 )
-			{
 				Actor::AI_RandomMove(actor_id, target_pid, 1024, 0);
-			}
 			else
 			{
 				//peasents after attacked
@@ -3196,13 +3167,10 @@
 
 		if ( pActor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long && target_pid )
 		{
-
 			if ( pActor->pMonsterInfo.uAIType == 1 )
 			{
 				if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
-				{
 					Actor::AI_Stand(actor_id, target_pid, (uint)(pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333),	pDir);
-				}
 				else
 				{
 					Actor::AI_Flee(actor_id, target_pid, 0, pDir);
@@ -3242,23 +3210,15 @@
 					if ( pActor->pMonsterInfo.uMissleAttack1Type )
 					{
 						if ( (signed int)pActor->pMonsterInfo.uRecoveryTime <= 0 )
-						{
 							Actor::AI_MissileAttack1(actor_id, target_pid, pDir);
-						}
 						else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
-						{
 							Actor::AI_Stand(actor_id, target_pid, v47, pDir);
-						}
 						else
 						{
 							if ( radiusMultiplier * 307.2 > (double)v81 )
-							{
 								Actor::AI_Stand(actor_id, target_pid, v47, pDir);
-							}
 							else
-							{
 								Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, pDir);
-							}
 						}
 					}
 					else
@@ -3266,14 +3226,9 @@
             if ( (double)v81 >= radiusMultiplier * 307.2 )
             {
               if (pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY)
-              {
                 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
-              }
-              else if ( v81 >= 1024 )
-              {
-				        //monsters
+              else if ( v81 >= 1024 )//monsters
                 Actor::AI_Pursue3(actor_id, target_pid, 0, pDir);
-              }
               else
               {
                 v70 = (signed int)(radiusMultiplier * 307.2);
@@ -3311,26 +3266,18 @@
 								Actor::AI_SpellAttack2(actor_id, target_pid, pDir);
 						}
 						else if ( radiusMultiplier * 307.2 > (double)v81 || pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
-						{
 							Actor::AI_Stand(actor_id, target_pid, v47, pDir);
-						}
 						else
-						{
 							Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, pDir);
-						}
 					}
 					else
           {
             if ( (double)v81 >= radiusMultiplier * 307.2 ) 
             {
               if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
-              {
                 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
-              }
               else if ( v81 >= 1024 )
-              {
                 Actor::AI_Pursue3(actor_id, target_pid, 256, pDir);
-              }
               else
               {
                 v70 = (signed int)(radiusMultiplier * 307.2);
@@ -3354,21 +3301,13 @@
 		if ( pActor->pMonsterInfo.uHostilityType != MonsterInfo::Hostility_Long || !target_pid || v81 >= 5120 || v45 != 1 )
 		{
 			if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_SHORT )
-			{
 				Actor::AI_RandomMove(actor_id, 4, 1024, 0);
-			}
 			else if ( pActor->pMonsterInfo.uMovementType == 1 )
-			{
 				Actor::AI_RandomMove(actor_id, 4, 2560, 0);
-			}
 			else if ( pActor->pMonsterInfo.uMovementType == 2 )
-			{
 				Actor::AI_RandomMove(actor_id, 4, 5120, 0);
-			}
 			else if ( pActor->pMonsterInfo.uMovementType == 4 )
-			{
 				Actor::AI_RandomMove(actor_id, 4, 10240, 0);
-			}
 			else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
 			{
 				Actor::GetDirectionInfo(a1, 4u, &v72, 0);
@@ -3378,30 +3317,22 @@
 		}
 		else if ( !pActor->pMonsterInfo.uMissleAttack2Type )
 		{
-			if ( (double)v81 >= radiusMultiplier * 307.2 )
-			{
+		if ( (double)v81 >= radiusMultiplier * 307.2 )
+		{
         if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
-        {
           Actor::AI_Stand(actor_id, target_pid, v47, pDir);
-        }
-				else if ( v81 >= 1024 )
-				{
-					Actor::AI_Pursue3(actor_id, target_pid, 256, pDir);
-				}
-				else
-				{
-					v70 = (int)(radiusMultiplier * 307.2);
-					Actor::AI_Pursue2(actor_id, target_pid, 0, pDir, v70);
-				}
-			}
+		else if ( v81 >= 1024 )
+			Actor::AI_Pursue3(actor_id, target_pid, 256, pDir);
+		else
+		{
+			v70 = (int)(radiusMultiplier * 307.2);
+			Actor::AI_Pursue2(actor_id, target_pid, 0, pDir, v70);
+		}
+		}
 			else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 )
-			{
 				Actor::AI_Stand(actor_id, target_pid, v47, pDir);
-			}
 			else
-			{
 				Actor::AI_MeleeAttack(actor_id, target_pid, pDir);
-			}
 		}
 		else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 )
 		{
@@ -3411,9 +3342,7 @@
 				Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, pDir);
 		}
 		else
-		{
 			Actor::AI_MissileAttack2(actor_id, target_pid, pDir);
-		}		
 	}
 }
 //----- (0044665D) --------------------------------------------------------
@@ -3583,10 +3512,10 @@
     if (!v8 || v7)
       if (!v6 || v5)
         if (actor->IsPeasant())
-          BYTE2(actor->uAttributes) &= 0xF7u;
+          actor->uAttributes &= 0xF70000;
 
-    BYTE2(actor->uAttributes) &= 0x7Fu;
-    if (BYTE2(actor->uAttributes) & 0x40)
+    actor->uAttributes &= 0x7F0000;
+    if (actor->uAttributes & 0x400000)
         Actor::_4031C1_update_job_never_gets_called(i, pParty->uCurrentHour, 1);
   }
 }
@@ -3689,18 +3618,12 @@
       std::sort(distances.begin(), distances.end());
       v61 = ((unsigned int)(11 * distances[1]) >> 5) + (distances[0] >> 2) + distances[2];
 
-      if ( v61 >= 5120 && !(BYTE1(pMonster->uAttributes) & 4) )
-      {
+      if ( v61 >= 5120 && !(pMonster->uAttributes & 0x400) )
         return;
-      }
       else if ( v61 >= 2560 )
-      {
         v61 = 2;
-      }
       else
-      {
         v61 = 1;
-      }
     }
 
     switch (projectileSprite->spell_id)
@@ -4119,7 +4042,7 @@
       {
         if ( pActors[i].uAIState != Dying && pActors[i].uAIState != Removed
           && pActors[i].uAIState != Disabled && pActors[i].uAIState != Summoned
-          && (BYTE2(pActors[i].uAttributes) & 8 || pActors[i].GetActorsRelation(0) ) )
+          && (pActors[i].uAttributes & 0x80000 || pActors[i].GetActorsRelation(0) ) )
           return true;
       }
     }
--- a/Arcomage.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Arcomage.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -250,47 +250,44 @@
 
 //----- (0040DFFE) --------------------------------------------------------
 int stru272_stru0::Free()
-    {
-
-    if ( this->signature == SIG_trpg )
-        {
-        this->signature = SIG_xxxx;
-        free(this);
-        return 0;
-        }
-    else
-        return 2;
-
-    }
+{
+  if ( this->signature == SIG_trpg )
+  {
+    this->signature = SIG_xxxx;
+    free(this);
+    return 0;
+  }
+  else
+    return 2;
+}
 
 //----- (0040E01A) --------------------------------------------------------
 int stru272_stru0::StartFill( stru272_stru2* a2 )
-    {
-    stru272_stru0* a1 = this;
-    if ( a1->signature == SIG_trpg )
-        {
-        a1->field_4 = a2->field_20;
-        a1->field_C = a2->effect_area.left << 16;
-        a1->field_10 = a2->effect_area.top << 16;
-        a1->field_14 = a2->effect_area.right << 16;
-        a1->field_18 = a2->effect_area.bottom << 16;
-        a1->field_1C = a2->field_10;
-        a1->field_20 = a2->field_14;
-        a1->field_24 = a2->field_18;
-        a1->field_28 = (float)(a2->field_1Cf * 65536.0);
-        a1->field_2C = a2->field_24f;
-        a1->field_34 = (int)(a2->field_28f * 65536.0);
-        a1->field_38 = (int)(a2->field_2Cf * 65536.0);
-        a1->field_3C = a2->field_30;
-        a1->field_40 = a2->field_34;
-        a1->field_54 = a2->sparks_array;
-        a1->field_59 = 1;
-
-        return 0;
-        }
-    else
-       return 2;
-    }
+{
+  //stru272_stru0* a1 = this;
+  if ( this->signature == SIG_trpg )
+  {
+    this->field_4 = a2->field_20;
+    this->field_C = a2->effect_area.left << 16;
+    this->field_10 = a2->effect_area.top << 16;
+    this->field_14 = a2->effect_area.right << 16;
+    this->field_18 = a2->effect_area.bottom << 16;
+    this->field_1C = a2->field_10;
+    this->field_20 = a2->field_14;
+    this->field_24 = a2->field_18;
+    this->field_28 = (float)(a2->field_1Cf * 65536.0);
+    this->field_2C = a2->field_24f;
+    this->field_34 = (int)(a2->field_28f * 65536.0);
+    this->field_38 = (int)(a2->field_2Cf * 65536.0);
+    this->field_3C = a2->field_30;
+    this->field_40 = a2->field_34;
+    this->field_54 = a2->sparks_array;
+    this->field_59 = 1;
+    return 0;
+  }
+  else
+    return 2;
+}
 
 //----- (0040E0F5) --------------------------------------------------------
 int stru272_stru0::Clear(char a2, char a3)
@@ -317,118 +314,117 @@
 
 //----- (0040E133) --------------------------------------------------------
 int stru272_stru0::DrawEffect()
+{
+//    stru272_stru0 *v1; // edi@1
+  int v3; // ST18_4@3
+  double v4; // st7@3
+  double v5; // st6@4
+  char v6; // bl@8
+  stru272_stru1 *v7; // esi@8
+  int v8; // ecx@10
+  signed int v9; // eax@10
+  int v10; // ecx@10
+  signed int v11; // eax@10
+  int v12; // ebx@12
+  int v13; // ST1C_4@12
+  int v14; // ebx@12
+  int v15; // ST1C_4@12
+  signed int v16; // edx@12
+  int v17; // ebx@12
+  int v18; // ST1C_4@12
+  signed int v19; // edx@12
+  int v20; // [sp+8h] [bp-10h]@8
+  int v21; // [sp+Ch] [bp-Ch]@8
+  float v22; // [sp+14h] [bp-4h]@3
+
+  if ( this->signature != SIG_trpg )
+    return 2;
+  v3 = this->position_in_sparks_arr;
+  v22 = this->field_30;
+  v4 = v3;
+  if ( v3 > 0 )
+  {
+    v5 = v22 + this->field_2C;
+    v22 = v5;
+    if ( v5 > v4 )
+      v22 = v4;
+  }
+  if ( v22 >= 1.0 || this->field_58 )
+  {
+    v6 = 0;
+    v7 = this->field_54;
+    v20 = this->field_28;
+
+    for ( v21 = this->field_4; v21; v21-- )
     {
-
-    stru272_stru0 *v1; // edi@1
-    int v3; // ST18_4@3
-    double v4; // st7@3
-    double v5; // st6@4
-    char v6; // bl@8
-    stru272_stru1 *v7; // esi@8
-    int v8; // ecx@10
-    signed int v9; // eax@10
-    int v10; // ecx@10
-    signed int v11; // eax@10
-    int v12; // ebx@12
-    int v13; // ST1C_4@12
-    int v14; // ebx@12
-    int v15; // ST1C_4@12
-    signed int v16; // edx@12
-    int v17; // ebx@12
-    int v18; // ST1C_4@12
-    signed int v19; // edx@12
-    int v20; // [sp+8h] [bp-10h]@8
-    int v21; // [sp+Ch] [bp-Ch]@8
-    float v22; // [sp+14h] [bp-4h]@3
-
-    v1 = this;
-    if ( this->signature != SIG_trpg )
-        return 2;
-    v3 = this->position_in_sparks_arr;
-    v22 = this->field_30;
-    v4 = v3;
-    if ( v3 > 0 )
-        {
-        v5 = v22 + this->field_2C;
-        v22 = v5;
-        if ( v5 > v4 )
-            v22 = v4;
-        }
-    if ( v22 >= 1.0 || this->field_58 )
-        {
-        v6 = 0;
-        v7 = this->field_54;
-        v20 = this->field_28;
-        v21 = this->field_4;
-        while ( v7->have_spark <= 0 )
-            {
-            if ( v22 >= 1.0 )
-                {
-                v12 = v1->field_40;
-                v13 = v1->field_3C;
-                v7->have_spark = rand_interval(v13,v12);
-                v7->field_14 = (rand() % 17 - 8) << 16;
-                v7->field_18 = (rand() % 17 - 8) << 16;
-
-                v14 = v1->field_14 - 1;
-                v15 = v1->field_C;
-                v16 = rand_interval(v15,v14);
-                v7->field_C = v16;
-                v7->spark_position.x = v16 >> 16;
-
-                v17 = v1->field_18 - 1;
-                v18 = v1->field_10;
-                v19 = rand_interval(v17, v18);
-                v7->field_10 = v19;
-                v7->spark_position.y = v19 >> 16;
-                --v1->position_in_sparks_arr;
-                v22 = v22 - 1.0;
-                goto LABEL_13;
-                }
-LABEL_14:
-            ++v7;
-            --v21;
-            if ( !v21 )
-                {
-                v1->field_58 = v6;
-                v1->field_30 = v22;
-                return 0;
-                }
-            }
-        v8 = v7->field_14;
-        --v7->have_spark;
-        v9 = v8 + v7->field_C;
-
-        v10 = v20 + v7->field_18;
-        v7->field_C = v9;
-        v7->spark_position.x = v9 >> 16;
-
-        v11 = v10 + v7->field_10;
-        v7->field_18 = v10;
-        v7->field_10 = v11;
-        v7->spark_position.y = v11 >> 16;
-LABEL_13:
+		if ( v7->have_spark > 0  )
+		{
+    v8 = v7->field_14;
+    --v7->have_spark;
+    v9 = v8 + v7->field_C;
+    v10 = v20 + v7->field_18;
+    v7->field_C = v9;
+    v7->spark_position.x = v9 >> 16;
+    v11 = v10 + v7->field_10;
+    v7->field_18 = v10;
+    v7->field_10 = v11;
+    v7->spark_position.y = v11 >> 16;
+    v6 = 1;
+    //goto LABEL_14;
+		}
+		else
+		{
+      if ( v22 >= 1.0 )
+      {
+        v12 = this->field_40;
+        v13 = this->field_3C;
+        v7->have_spark = rand_interval(v13,v12);
+        v7->field_14 = (rand() % 17 - 8) << 16;
+        v7->field_18 = (rand() % 17 - 8) << 16;
+        v14 = this->field_14 - 1;
+        v15 = this->field_C;
+        v16 = rand_interval(v15,v14);
+        v7->field_C = v16;
+        v7->spark_position.x = v16 >> 16;
+        v17 = this->field_18 - 1;
+        v18 = this->field_10;
+        v19 = rand_interval(v17, v18);
+        v7->field_10 = v19;
+        v7->spark_position.y = v19 >> 16;
+        --this->position_in_sparks_arr;
+        v22 = v22 - 1.0;
         v6 = 1;
-        goto LABEL_14;
-        }
-    return 0;
+      }
+		}
+//LABEL_14:
+      ++v7;
+      //--v21;
+      //if ( !v21 )
+      //{
+        //this->field_58 = v6;
+        //this->field_30 = v22;
+        //return 0;
+      //}
     }
+    this->field_58 = v6;
+    this->field_30 = v22;
+  }
+  return 0;
+}
 
 //----- (0040E2A7) --------------------------------------------------------
 int stru272_stru0::_40E2A7()
-    {
-
-    if (signature == SIG_trpg )
-        {
-        if ( position_in_sparks_arr <= 0 )
-            return field_58 != 0 ? 2 : 0;
-        else
-            return 1;
-        }
+{
+  if (signature == SIG_trpg )
+  {
+    if ( position_in_sparks_arr <= 0 )
+      return field_58 != 0 ? 2 : 0;
     else
-        return 3;
-    }
-
+      return 1;
+  }
+  else
+    return 3;
+}
 
 //----- (0040DFAF) --------------------------------------------------------
 void ArcomageGame::OnMouseClick(char right_left, bool bDown)
@@ -446,7 +442,6 @@
   pArcomageGame->mouse_y = y;
 }
 
-
 //----- (0040DF47) --------------------------------------------------------
 void DoBlt_Copy(unsigned __int16 *pPixels)
 {
@@ -460,8 +455,8 @@
 
   pSrcRect.left   = 0;
   pSrcRect.top    = 0;
-  pSrcRect.right  = 640;
-  pSrcRect.bottom = 480;
+  pSrcRect.right  = window->GetWidth();
+  pSrcRect.bottom = window->GetHeight();
 
   pRenderer->BeginScene();
   pArcomageGame->pBlit_Copy_pixels = pPixels;
@@ -472,7 +467,7 @@
 
 //----- (0040DDC9) --------------------------------------------------------
 void ArcomageGame::PlaySound( unsigned int event_id )
-    {
+{
   SoundID play_sound_id; // eax@10
 
   switch ( event_id )
@@ -546,7 +541,7 @@
       break;
   default:
       return;
-      }
+  }
   pAudioPlayer->PlaySound(play_sound_id, 0, 0, -1, 0, 0, 0, 0);
 }
 
@@ -555,10 +550,6 @@
 {
   void *v2; // ebp@1
   BOOL v3; // eax@1
-  //int v4; // edx@6
-  //int v5; // edx@6
-  //int v6; // eax@6
-  //int v7; // edx@7
 
   v2 = a2;
   pArcomageGame->field_0 = 0;
@@ -606,7 +597,6 @@
   return pArcomageGame->stru1.field_0 != 0;
 }
 
-
 //----- (0040D7D5) --------------------------------------------------------
 void am_BeginScene(unsigned __int16 *pPcxPixels, int a2, int a3)
 {
@@ -617,156 +607,153 @@
 //----- (0040D7EC) --------------------------------------------------------
 void Render::am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode)
 {
-
-unsigned __int16 *pSrc; // eax@2
-//unsigned __int16 *dest_surf_pos; // edi@3
-int uSrcTotalWidth; // ecx@4
-unsigned int v10; // esi@9
-int v21; // [sp+Ch] [bp-18h]@8
-unsigned __int16 *src_surf_pos; // [sp+10h] [bp-14h]@9
-__int32 src_width; // [sp+14h] [bp-10h]@3
-__int32 src_height; // [sp+18h] [bp-Ch]@3
-int uSrcPitch; // [sp+1Ch] [bp-8h]@5
-
-
-if ( !uNumSceneBegins )
+  unsigned __int16 *pSrc; // eax@2
+  int uSrcTotalWidth; // ecx@4
+  unsigned int v10; // esi@9
+  int v21; // [sp+Ch] [bp-18h]@8
+  unsigned __int16 *src_surf_pos; // [sp+10h] [bp-14h]@9
+  __int32 src_width; // [sp+14h] [bp-10h]@3
+  __int32 src_height; // [sp+18h] [bp-Ch]@3
+  int uSrcPitch; // [sp+1Ch] [bp-8h]@5
+
+  if ( !uNumSceneBegins )
     return;
-if ( !pArcomageGame->pBlit_Copy_pixels )
+  if ( !pArcomageGame->pBlit_Copy_pixels )
     return;
 
-//dest_surf_pos = &pRenderer->pTargetSurface[pTargetPoint->x + pTargetPoint->y * pRenderer->uTargetSurfacePitch];
-src_width = pSrcRect->right - pSrcRect->left;
-src_height = pSrcRect->bottom - pSrcRect->top;
-
-if ( pArcomageGame->pBlit_Copy_pixels == pArcomageGame->pBackgroundPixels )
+  //dest_surf_pos = &pRenderer->pTargetSurface[pTargetPoint->x + pTargetPoint->y * pRenderer->uTargetSurfacePitch];
+  src_width = pSrcRect->right - pSrcRect->left;
+  src_height = pSrcRect->bottom - pSrcRect->top;
+
+  if ( pArcomageGame->pBlit_Copy_pixels == pArcomageGame->pBackgroundPixels )
     uSrcTotalWidth = pArcomageGame->pGameBackground.uWidth;
-else if ( pArcomageGame->pBlit_Copy_pixels == pArcomageGame->pSpritesPixels )
+  else if ( pArcomageGame->pBlit_Copy_pixels == pArcomageGame->pSpritesPixels )
     uSrcTotalWidth = pArcomageGame->pSprites.uWidth;
 
-//v20 = 157;
-//v19 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\am_nw.cpp";
-//v21 = &v18;
-//std__string_char_40E2C8(&v18, "Problem in Blit_Chroma", &a3a);
-//466D09_xcpt_string(&v21, v18, v19, v20);
-//pSrc = pArcomageGame.pBlit_Copy_pixels;
-//LABEL_9:
-pSrc = pArcomageGame->pBlit_Copy_pixels;
-uSrcPitch = uSrcTotalWidth;
-
-src_surf_pos = &pSrc[pSrcRect->left + uSrcPitch * pSrcRect->top];
-v10 = 0xFFu >> (8 - (unsigned __int8)uTargetBBits);
-v21 = (uTargetGBits != 6 ? 0x31EF : 0x7BEF);
-
-
-if ( blend_mode == 2 )
+  //v20 = 157;
+  //v19 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\am_nw.cpp";
+  //v21 = &v18;
+  //std__string_char_40E2C8(&v18, "Problem in Blit_Chroma", &a3a);
+  //466D09_xcpt_string(&v21, v18, v19, v20);
+  //pSrc = pArcomageGame.pBlit_Copy_pixels;
+  //LABEL_9:
+  pSrc = pArcomageGame->pBlit_Copy_pixels;
+  uSrcPitch = uSrcTotalWidth;
+  src_surf_pos = &pSrc[pSrcRect->left + uSrcPitch * pSrcRect->top];
+  v10 = 0x1F;//0xFF >> (8 - (unsigned __int8)uTargetBBits);
+  v21 = (uTargetGBits != 6 ? 0x31EF : 0x7BEF);
+  if ( blend_mode == 2 )
+  {
+    uSrcPitch =  (uSrcPitch - src_width);
+    for ( int i = 0; i < src_height; ++i )
     {
-        uSrcPitch =  (uSrcPitch - src_width);
-        for (int i=0; i< src_height; ++i)
-            {
-            for (int j=0; j< src_width; ++j)
-                {
-                if ( *src_surf_pos != v10 )
-                  WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, *src_surf_pos);
-                    //*dest_surf_pos = *src_surf_pos;
-                //++dest_surf_pos;
-                ++src_surf_pos;
-                }
-            src_surf_pos+=uSrcPitch;
-            //dest_surf_pos += pRenderer->uTargetSurfacePitch - src_width;
-            }
+      for ( int j = 0; j < src_width; ++j )
+      {
+        if ( *src_surf_pos != v10 )
+        {
+          if ( pTargetPoint->x + j >= 0 && pTargetPoint->x + j <= window->GetWidth() - 1 
+            && pTargetPoint->y + i >= 0 && pTargetPoint->y + i <= window->GetHeight() - 1)
+            WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, *src_surf_pos);
+        }
+        ++src_surf_pos;
+      }
+      src_surf_pos += uSrcPitch;
     }
-else 
+  }
+  else 
+  {
+    uSrcPitch = (uSrcPitch - src_width);
+    for ( int i = 0; i < src_height; ++i )
     {
-    uSrcPitch = (uSrcPitch - src_width);
-    for (int i=0; i< src_height; ++i)
+      for ( int j = 0; j < src_width; ++j )
+      {
+        if ( *src_surf_pos != v10 )
         {
-        for (int j=0; j< src_width; ++j)
-            {
-            if ( *src_surf_pos != v10 )
-              WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, (v21 & (ReadPixel16(pTargetPoint->x + j, pTargetPoint->y + i) >> 1)) + (v21 & (*src_surf_pos >> 1)));
-                //*dest_surf_pos = (v21 & (*dest_surf_pos >> 1)) + (v21 & (*src_surf_pos >> 1));
-            //++dest_surf_pos;
-            ++src_surf_pos;
-            }
-        src_surf_pos+=uSrcPitch;
-        //dest_surf_pos += pRenderer->uTargetSurfacePitch - src_width;
+          if ( pTargetPoint->x + j >= 0 && pTargetPoint->x + j <= window->GetWidth() - 1
+            && pTargetPoint->y + i >= 0 && pTargetPoint->y + i <= window->GetHeight() - 1)
+          //WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, (v21 & (ReadPixel16(pTargetPoint->x + j, pTargetPoint->y + i) >> 1)) + (v21 & (*src_surf_pos >> 1)));
+            WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, (0x7BEF & (*src_surf_pos / 2)));
         }
+        ++src_surf_pos;
+      }
+      src_surf_pos+=uSrcPitch;
     }
-
+  }
 }
 
 //----- (0040D9B1) --------------------------------------------------------
 void Render::am_Blt_Copy( RECT *pSrcRect, POINT *pTargetPoint, int blend_mode )
-    {
-
-    unsigned __int16 *pSrc; // eax@2
-    //unsigned __int16 *dest_surf_pos; // edi@3
-    int uSrcTotalWidth; // ecx@4
-    int v21; // [sp+Ch] [bp-18h]@8
-    unsigned __int16 *src_surf_pos; // [sp+10h] [bp-14h]@9
-    __int32 src_width; // [sp+14h] [bp-10h]@3
-    __int32 src_height; // [sp+18h] [bp-Ch]@3
-    int uSrcPitch; // [sp+1Ch] [bp-8h]@5
-
-    if ( !uNumSceneBegins )
-        return;
-    if ( !pArcomageGame->pBlit_Copy_pixels )
-        return;
+{
+  unsigned __int16 *pSrc; // eax@2
+  int uSrcTotalWidth; // ecx@4
+  int v21; // [sp+Ch] [bp-18h]@8
+  unsigned __int16 *src_surf_pos; // [sp+10h] [bp-14h]@9
+  __int32 src_width; // [sp+14h] [bp-10h]@3
+  __int32 src_height; // [sp+18h] [bp-Ch]@3
+  int uSrcPitch; // [sp+1Ch] [bp-8h]@5
+
+  if ( !uNumSceneBegins )
+    return;
+  if ( !pArcomageGame->pBlit_Copy_pixels )
+    return;
 
     //dest_surf_pos = &pRenderer->pTargetSurface[pTargetPoint->x + pTargetPoint->y * pRenderer->uTargetSurfacePitch];
-    src_width = pSrcRect->right - pSrcRect->left;
-    src_height = pSrcRect->bottom - pSrcRect->top;
-
-    if ( pArcomageGame->pBlit_Copy_pixels == pArcomageGame->pBackgroundPixels )
-        uSrcTotalWidth = pArcomageGame->pGameBackground.uWidth;
-    else if ( pArcomageGame->pBlit_Copy_pixels == pArcomageGame->pSpritesPixels )
-        uSrcTotalWidth = pArcomageGame->pSprites.uWidth;
-
-    //v20 = 157;
-    //v19 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\am_nw.cpp";
-    //v21 = &v18;
-    //std__string_char_40E2C8(&v18, "Problem in Blit_Chroma", &a3a);
-    //466D09_xcpt_string(&v21, v18, v19, v20);
-    //pSrc = pArcomageGame.pBlit_Copy_pixels;
-    //LABEL_9:
-    pSrc = pArcomageGame->pBlit_Copy_pixels;
-    uSrcPitch = uSrcTotalWidth;
-
-    src_surf_pos = &pSrc[pSrcRect->left + uSrcPitch * pSrcRect->top];
-    v21 = (uTargetGBits != 6 ? 0x31EF : 0x7BEF);
-
-    if ( blend_mode == 2 )
+  src_width = pSrcRect->right - pSrcRect->left;
+  src_height = pSrcRect->bottom - pSrcRect->top;
+  if ( pArcomageGame->pBlit_Copy_pixels == pArcomageGame->pBackgroundPixels )
+    uSrcTotalWidth = pArcomageGame->pGameBackground.uWidth;
+  else if ( pArcomageGame->pBlit_Copy_pixels == pArcomageGame->pSpritesPixels )
+    uSrcTotalWidth = pArcomageGame->pSprites.uWidth;
+
+  //v20 = 157;
+  //v19 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\am_nw.cpp";
+  //v21 = &v18;
+  //std__string_char_40E2C8(&v18, "Problem in Blit_Chroma", &a3a);
+  //466D09_xcpt_string(&v21, v18, v19, v20);
+  //pSrc = pArcomageGame.pBlit_Copy_pixels;
+  //LABEL_9:
+  pSrc = pArcomageGame->pBlit_Copy_pixels;
+  uSrcPitch = uSrcTotalWidth;
+  src_surf_pos = &pSrc[pSrcRect->left + uSrcPitch * pSrcRect->top];
+  v21 = (uTargetGBits != 6 ? 0x31EF : 0x7BEF);
+
+  if ( blend_mode == 2 )
+  {
+    uSrcPitch =  (uSrcPitch - src_width);
+    for ( int i = 0; i < src_height; ++i )
+    {
+      for ( int j = 0; j < src_width; ++j )
+      { 
+        if ( *src_surf_pos != v21 )
         {
-        uSrcPitch =  (uSrcPitch - src_width);
-        for (int i=0; i< src_height; ++i)
-            {
-            for (int j=0; j< src_width; ++j)
-                { 
-                  WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, *src_surf_pos);
-                //*dest_surf_pos = *src_surf_pos;
-                //++dest_surf_pos;
-                ++src_surf_pos;
-                }
-            src_surf_pos+=uSrcPitch;
-            //dest_surf_pos += pRenderer->uTargetSurfacePitch - src_width;
-            }
+          if ( pTargetPoint->x + j >= 0 && pTargetPoint->x + j <= window->GetWidth() - 1 
+            && pTargetPoint->y + i >= 0 && pTargetPoint->y + i <= window->GetHeight() - 1)
+            WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, *src_surf_pos);
         }
-    else 
+        ++src_surf_pos;
+      }
+      src_surf_pos += uSrcPitch;
+    }
+  }
+  else 
+  {
+    uSrcPitch =  (uSrcPitch - src_width);
+    for ( int i = 0; i < src_height; ++i )
+    {
+      for ( int j = 0; j < src_width; ++j )
+      {
+        if ( *src_surf_pos != v21 )
         {
-        uSrcPitch =  (uSrcPitch - src_width);
-        for (int i=0; i< src_height; ++i)
-            {
-            for (int j=0; j< src_width; ++j)
-                {
-                 //*dest_surf_pos = (v21 & (*dest_surf_pos >> 1)) + (v21 & (*src_surf_pos >> 1));
-                //++dest_surf_pos;
-                  WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, (v21 & (ReadPixel16(pTargetPoint->x + j, pTargetPoint->y + i) >> 1)) + (v21 & (*src_surf_pos >> 1)));
-                ++src_surf_pos;
-                }
-            src_surf_pos+=uSrcPitch;
-            //dest_surf_pos += pRenderer->uTargetSurfacePitch - src_width;
-            }
+          if ( pTargetPoint->x + j >= 0 && pTargetPoint->x + j <= window->GetWidth() - 1
+            && pTargetPoint->y + i >= 0 && pTargetPoint->y + i <= window->GetHeight() - 1)
+          //WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, (v21 & (ReadPixel16(pTargetPoint->x + j, pTargetPoint->y + i) / 2)) + (v21 & (*src_surf_pos / 2)));
+            WritePixel16(pTargetPoint->x + j, pTargetPoint->y + i, (0x7BEF & (*src_surf_pos / 2)));
         }
+        ++src_surf_pos;
+      }
+      src_surf_pos += uSrcPitch;
+    }
+  }
 }
 
 //----- (0040DB10) --------------------------------------------------------
@@ -793,8 +780,8 @@
 }
 
 int CalculateCardPower(ArcomagePlayer* player, ArcomagePlayer* enemy, ArcomageCard* pCard, int mastery)
-    {
-    enum V_INDX{
+{
+  enum V_INDX{
         P_TOWER_M10,
         P_WALL_M10,
         E_TOWER,
@@ -820,7 +807,6 @@
     int card_power= 0;
     int element_power;
 
-   
     if ( pCard->to_player_tower  == 99 || pCard->to_pl_enm_tower  == 99|| 
             pCard->to_player_tower2 == 99 || pCard->to_pl_enm_tower2 == 99 )
         element_power = enemy->tower_height - player->tower_height; 
@@ -963,281 +949,121 @@
 
     if ( enemy->tower_height <= pCard->to_enemy_tower2 + pCard->to_enemy_tower )
         card_power += 9999;
-  
+
     if (pCard->to_enemy_tower2    + pCard->to_enemy_tower + 
         pCard->to_enemy_wall      + pCard->to_enemy_wall2 + 
         pCard->to_enemy_buildings + pCard->to_enemy_buildings2 >= enemy->wall_height + enemy->tower_height) 
         card_power += 9999;
 
-    if ( (pCard->to_player_tower2 + pCard->to_pl_enm_tower2 + 
-          pCard->to_player_tower  + pCard->to_pl_enm_tower  + player->tower_height) >= max_tower_height )
-        card_power += 9999;
-
-    return card_power;
-    }
-
+  if ( (pCard->to_player_tower2 + pCard->to_pl_enm_tower2 + pCard->to_player_tower  + pCard->to_pl_enm_tower  + player->tower_height)
+         >= max_tower_height )
+    card_power += 9999;
+
+  return card_power;
+}
 
 //----- (00408BB4) --------------------------------------------------------
 bool OpponentsAITurn(int player_num)
 {
-    char result; // al@3
-    signed int v2; // ebx@8
-    int v3; // esi@8
-    int all_player_cards_count; // eax@9
-    int random_card_slot; // edi@9
-    int v6; // eax@11
-    signed int v7; // eax@11
-    int v8; // ebx@5
-    int v9; // eax@5
-    int v10; // ecx@18
-    int v11; // eax@20
-    ArcomageCard *v12; // ecx@20
-    char v13; // dl@20
-    char v14; // dl@24
-    int v15; // edx@25
-    int v16; // edx@27
-    char v17; // dl@31
-    int v18; // edx@32
-    char v19; // dl@35
-    char v20; // dl@39
-    int v21; // edx@40
-    char v22; // dl@45
-    int v23; // edx@46
-    char v24; // dl@52
-    int v25; // edx@53
-    char v26; // dl@58
-    int v27; // edx@59
-    char v28; // dl@64
-    int v29; // edx@65
-    char v30; // dl@70
-    int v31; // edx@71
-    char v32; // dl@76
-    int v33; // edx@77
-    char v34; // dl@82
-    int v35; // edx@83
-    char v36; // dl@86
-    char v37; // dl@90
-    int v38; // edi@93
-    char v39; // dl@93
-    int v40; // esi@93
-    char v41; // bl@94
-    char v42; // dl@98
-    char v43; // dl@102
-    char v44; // dl@106
-    char v45; // dl@110
-    char v46; // dl@114
-    ArcomagePlayer *v47; // ebx@115
-    ArcomagePlayer *v48; // edx@115
-    int v49; // esi@123
-    int v50; // edx@123
-    int v51; // edx@126
-    int v52; // esi@129
-    int v53; // edi@137
-    int j; // esi@137
-    am_2 *v55; // eax@139
-    int v56; // ecx@141
-    int v57; // edx@141
-    int v58; // ebx@141
-    int v59; // eax@144
-    int v60; // esi@145
-    int v61; // ebx@4
-    int v62; // eax@4
-    int v63; // ecx@167
-    int v64; // eax@169
-    ArcomageCard *pCard; // ecx@169
-    char v66; // dl@169
-    char v67; // dl@173
-    int v68; // edx@174
-    int v69; // edx@176
-    char v70; // dl@180
-    char v71; // dl@183
-    char v72; // dl@187
-    int v73; // edx@188
-    char v74; // dl@193
-    char v75; // dl@199
-    int v76; // edx@200
-    char v77; // dl@205
-    int v78; // edx@206
-    char v79; // dl@211
-    int v80; // edx@212
-    char v81; // dl@217
-    int v82; // edx@218
-    char v83; // dl@223
-    int v84; // edx@224
-    char v85; // dl@229
-    int v86; // edx@230
-    char v87; // dl@233
-    int v88; // edx@234
-    char v89; // dl@237
-    int v90; // edx@238
-    int v91; // esi@240
-    char v92; // dl@240
-    int v93; // esi@240
-    char v94; // bl@241
-    int v95; // edx@243
-    int v96; // edi@244
-    char v97; // dl@245
-    int v98; // edx@246
-    char v99; // dl@249
-    int v100; // edx@250
-    char v101; // dl@253
-    int v102; // edx@254
-    char v103; // dl@257
-    int v104; // edx@258
-    char v105; // dl@261
-    ArcomagePlayer *v106; // ebx@262
-    ArcomagePlayer *v107; // edx@262
-    int v108; // esi@270
-    int v109; // edx@270
-    int v110; // edx@273
-    int v111; // esi@276
-    int v112; // edi@284
-   // int j; // esi@284
-    am_2 *v114; // eax@286
-    int v115; // ecx@288
-    int v116; // edx@288
-    int v117; // ebx@288
-    int v118; // eax@291
-    int v119; // esi@292
-    int v120; // [sp-28h] [bp-28h]@129
-    int v121; // [sp-28h] [bp-28h]@276
-    int k; // [sp-24h] [bp-24h]@18
-    int i; // [sp-24h] [bp-24h]@167
-    int v124; // [sp-20h] [bp-20h]@5
-    int v125; // [sp-20h] [bp-20h]@4
-    int v126; // [sp-1Ch] [bp-1Ch]@17
-    int v127; // [sp-1Ch] [bp-1Ch]@139
-    int v128; // [sp-1Ch] [bp-1Ch]@166
-    int v129; // [sp-1Ch] [bp-1Ch]@286
-    int v130; // [sp-18h] [bp-18h]@5
-    int cards_count; // [sp-18h] [bp-18h]@4
-    int v132; // [sp-14h] [bp-14h]@0
-    int v133; // [sp-14h] [bp-14h]@93
-    int v134; // [sp-14h] [bp-14h]@129
-    int v135; // [sp-14h] [bp-14h]@240
-    int v136; // [sp-14h] [bp-14h]@276
-    ArcomagePlayer *enemy; // [sp-10h] [bp-10h]@5
-    ArcomagePlayer *enemy1; // [sp-10h] [bp-10h]@4
-    ArcomagePlayer *player; // [sp-Ch] [bp-Ch]@5
-    ArcomagePlayer *player1; // [sp-Ch] [bp-Ch]@4
-    char v141; // [sp-8h] [bp-8h]@35
-    char v142; // [sp-8h] [bp-8h]@183
-    char v143; // [sp-5h] [bp-5h]@20
-    char v144; // [sp-5h] [bp-5h]@169
-
-     byte_4FAA00 = 1;
-    if ( opponent_mastery == 0)
+  int all_player_cards_count; // eax@9
+  int random_card_slot; // edi@9
+  ArcomageCard *v12; // ecx@20
+  int v56; // ecx@141
+  int v57; // edx@141
+  int v64; // eax@169
+  ArcomageCard *pCard; // ecx@169
+  char v66; // dl@169
+  char v67; // dl@173
+  int v68; // edx@174
+  int v132; // [sp-14h] [bp-14h]@0
+  ArcomagePlayer *enemy; // [sp-10h] [bp-10h]@5
+  ArcomagePlayer *player; // [sp-Ch] [bp-Ch]@5
+
+  byte_4FAA00 = 1;
+  if ( opponent_mastery == 0)
+  {
+    if ( need_to_discard_card == 0 )  //am_byte_4FAA77
+    {
+      for(int i = 0; i < 10; ++i )
+      {
+        all_player_cards_count = GetPlayerHandCardCount(player_num);
+        random_card_slot = rand_interval(0, all_player_cards_count - 1);
+        if ( CanCardBePlayed(player_num, random_card_slot) )
+          return PlayCard(player_num, random_card_slot);
+      }
+    }
+    all_player_cards_count = GetPlayerHandCardCount(player_num);
+    random_card_slot= rand_interval(0, all_player_cards_count - 1);
+    return DiscardCard(player_num, random_card_slot);
+  }
+  else if (( opponent_mastery == 1 )|| ( opponent_mastery == 2 ))
+  {
+    player = &am_Players[player_num];
+    enemy = &am_Players[(player_num + 1) % 2];
+    all_player_cards_count = GetPlayerHandCardCount(player_num);
+    for(int i = 0; i < 10 ; ++i )
+    {
+      if ( i >= all_player_cards_count )
+      {
+        cards_power[i].slot_index = -1;
+        cards_power[i].card_power = -9999;
+      }
+      else
+      {
+        cards_power[i].slot_index = i;
+        cards_power[i].card_power = 0;
+      }
+    }
+    for(int i = 0; i < all_player_cards_count ; ++i )
+    {
+      v12 = &pCards[am_Players[player_num].cards_at_hand[cards_power[i].slot_index]];
+      cards_power[i].card_power = CalculateCardPower(player, enemy, v12, opponent_mastery-1);
+    }
+
+    for (int j = all_player_cards_count - 1; j >= 0; --j )
+    {
+      for (int m = 0; m < j; ++m )
+      {
+        if ( cards_power[m].card_power < cards_power[m + 1].card_power )
         {
-        if ( need_to_discard_card==0 )  //am_byte_4FAA77
-            {
-           for(int i = 0; i<10 ; ++i )
-                {
-                all_player_cards_count = GetPlayerHandCardCount(player_num);
-                random_card_slot = rand_interval(0, all_player_cards_count - 1);
-                if ( CanCardBePlayed(player_num, random_card_slot) )
-                    return PlayCard(player_num, random_card_slot);
-                 }
-            }
-            all_player_cards_count = GetPlayerHandCardCount(player_num);
-            random_card_slot= rand_interval(0, all_player_cards_count - 1);
-            return DiscardCard(player_num, random_card_slot);
+          v56 = cards_power[m].slot_index;
+          v57 = cards_power[m].card_power;
+          cards_power[m].slot_index = cards_power[m + 1].slot_index;
+          cards_power[m].card_power = cards_power[m + 1].card_power;
+          cards_power[m + 1].slot_index = cards_power[m].slot_index;
+          cards_power[m + 1].card_power = cards_power[m].card_power;
         }
-    else if (( opponent_mastery == 1 )|| ( opponent_mastery == 2 ))
-        {
-        player = &am_Players[player_num];
-        enemy = &am_Players[(player_num + 1) % 2];
-        all_player_cards_count = GetPlayerHandCardCount(player_num);
-        for(int i = 0; i<10 ; ++i )
-            {
-            if ( i >= all_player_cards_count )
-                {
-                cards_power[i].slot_index = -1;
-                cards_power[i].card_power = -9999;
-                }
-            else
-                {
-                cards_power[i].slot_index = i;
-                cards_power[i].card_power = 0;
-                }
-            }
-        for(int i = 0; i< all_player_cards_count ; ++i )
-            {   
-               v12 = &pCards[am_Players[player_num].cards_at_hand[cards_power[i].slot_index]];          
-               cards_power[i].card_power = CalculateCardPower(player, enemy, v12, opponent_mastery-1);
-            }
-
-            for (int j = all_player_cards_count - 1; j >= 0; --j )
-                {
-                    for (int m=0; m<j; ++m )
-                        {
-                        if ( cards_power[m].card_power < cards_power[m+1].card_power )
-                            {
-                            v56 = cards_power[m].slot_index;
-                            v57 = cards_power[m].card_power;
-                            cards_power[m].slot_index = cards_power[m+1].slot_index;
-                            cards_power[m].card_power = cards_power[m+1].card_power;
-                            cards_power[m+1].slot_index = v56;
-                            cards_power[m+1].card_power = v57;
-                            }
-                        }
-                }                           
-            v59 = all_player_cards_count - 1;
-            if ( need_to_discard_card )
-                {
-                if ( all_player_cards_count - 1 >= 0 )
-                    {
-                    while ( !pCards[am_Players[player_num].cards_at_hand[cards_power[v59].slot_index]].can_be_discarded )
-                        {
-                        --v59;
-                        if ( v59 < 0 )
-                            return DiscardCard(player_num, v132);
-                        }
-                    v132 = cards_power[v59].slot_index;
-                    }
-                }
-            else
-                {
-                v60 = 0;
-                if ( all_player_cards_count - 1 >= 0 )
-                    {
-                    while ( !pCards[am_Players[player_num].cards_at_hand[cards_power[v59].slot_index]].can_be_discarded )
-                        {
-                        --v59;
-                        if ( v59 < 0 )
-                            goto LABEL_150;
-                        }
-                    v132 = cards_power[v59].slot_index;
-                    }
-LABEL_150:
-                if ( (all_player_cards_count - 1)> 0 )
-                    {
-                    while ( !CanCardBePlayed(player_num, cards_power[v60].slot_index) || cards_power[v60].card_power < 0 )
-                        {
-                        ++v60;
-                        if ( v60 >= all_player_cards_count - 1 )
-                            return DiscardCard(player_num, v132);
-                        }
-                    return PlayCard(player_num, cards_power[v60].slot_index);
-                    }
-                }
-            return DiscardCard(player_num, v132);
-        }
-   
-
+      }
+    }
+    if ( need_to_discard_card )
+    {
+      for ( int i = all_player_cards_count - 1; i; --i )
+      {
+        if ( pCards[am_Players[player_num].cards_at_hand[cards_power[i].slot_index]].can_be_discarded )
+          v132 = cards_power[i].slot_index;
+      }
+    }
+    else
+    {
+      for ( int i = all_player_cards_count - 1; i; --i )
+      {
+        if ( pCards[am_Players[player_num].cards_at_hand[cards_power[i].slot_index]].can_be_discarded )
+          v132 = cards_power[i].slot_index;
+      }
+      for ( int i = 0; i < all_player_cards_count - 1; ++i )
+      {
+        if ( CanCardBePlayed(player_num, cards_power[i].slot_index) && cards_power[i].card_power )
+          return PlayCard(player_num, cards_power[i].slot_index);
+      }
+    }
+    return DiscardCard(player_num, v132);
+  }
   return true;//result != 0;
 }
 
-
-
 //----- (00409E6A) --------------------------------------------------------
 void ArcomageGame::Loop()
 {
-  int v0; // edx@2
-  int v1; // ecx@14
-  signed int v2; // eax@15
-  stru272 *v3; // esi@17
-  __int16 *v4; // esi@23
-
   while ( !pArcomageGame->GameOver )
   {
     pArcomageGame->field_F6 = 1;
@@ -1267,15 +1093,11 @@
   }
   GameResultsApply();
   if ( am_gameover )
-  {
      dword_4FAA70 = 0;
-  }
   else
-  {
     dword_4FAA70 = -1;
-  }
-
-  for(int i=0; i<10; ++i)
+
+  for( int i = 0; i < 10; ++i )
   {
       array_4FABD0[i].field_40->Clear(1, 1);
       array_4FABD0[i].field_40->Free();
@@ -1287,13 +1109,10 @@
   viewparams->bRedrawGameUI = true;
   if ( pVideoPlayer->AnyMovieLoaded() )
     pVideoPlayer->_4BF5B2();
-  for(int i=0; i<12; ++i)
+  for( int i = 0; i < 12; ++i )
     pSoundList->UnloadSound(am_sounds[i], 1);
 }
 
-
-
-
 //----- (00409FE9) --------------------------------------------------------
 void SetStartGameData()
 {
@@ -1304,7 +1123,7 @@
 
   current_player_num = am_default_starting_player;
   SetStartConditions();
-  for(i=0; i<2; ++i )
+  for( i = 0; i < 2; ++i )
   {
     if ( i )
     {
@@ -1328,7 +1147,7 @@
     am_Players[i].resource_gems   = start_gems_amount;
     am_Players[i].resource_beasts = start_beasts_amount;
 
-    for (j=0; j<10; ++j )
+    for ( j = 0; j < 10; ++j )
     {
       am_Players[i].cards_at_hand[j] = -1;
       if ( am_byte_4E185D )
@@ -1344,12 +1163,12 @@
     }  
   }
   strcpy(deckMaster.name, "Master Deck");
-  for (i=0, card_dispenser_counter=-2, card_id_counter=0; i<DECK_SIZE; ++i, ++card_dispenser_counter)
-      {
-      deckMaster.cardsInUse[i] = 0;
-      deckMaster.cards_IDs[i] =card_id_counter;
-      switch ( card_dispenser_counter )
-          {
+  for ( i = 0, card_dispenser_counter = -2, card_id_counter = 0; i < DECK_SIZE; ++i, ++card_dispenser_counter)
+  {
+    deckMaster.cardsInUse[i] = 0;
+    deckMaster.cards_IDs[i] = card_id_counter;
+    switch ( card_dispenser_counter )
+    {
       case 0:
       case 2:
       case 6:
@@ -1371,13 +1190,12 @@
       case 81:
       case 84:
       case 89:
-          break;
+        break;
       default:
-          ++card_id_counter;
-          }
-      }
-
-   FillPlayerDeck();
+        ++card_id_counter;
+    }
+  }
+  FillPlayerDeck();
 }
 
 //----- (0040A198) --------------------------------------------------------
@@ -1392,25 +1210,25 @@
   memset(deckMaster.cardsInUse, 0,DECK_SIZE );
   memset(card_taken_flags, 0, DECK_SIZE);
 
-  for (i=0; i<2; ++i)
+  for ( i = 0; i < 2; ++i )
   {
-    for (j=0; j<10; ++j)
+    for ( j = 0; j < 10; ++j )
     {
       if ( am_Players[i].cards_at_hand[j] > -1 )
       {
         for (m = 0; m<DECK_SIZE; ++m)
-            {
-            if (deckMaster.cards_IDs[m] == am_Players[i].cards_at_hand[j] && deckMaster.cardsInUse[m] == 0)
-                {
-                    deckMaster.cardsInUse[m] = 1;
-                    break;
-                }
-            }
+        {
+          if (deckMaster.cards_IDs[m] == am_Players[i].cards_at_hand[j] && deckMaster.cardsInUse[m] == 0)
+          {
+            deckMaster.cardsInUse[m] = 1;
+            break;
+          }
+        }
       }
     }
   }
 
-  for (i=0; i<DECK_SIZE; ++i)
+  for ( i = 0; i < DECK_SIZE; ++i )
   {
     do
       rand_deck_pos = rand() % DECK_SIZE;
@@ -1429,20 +1247,19 @@
 
 //----- (0040A255) --------------------------------------------------------
 void InitalHandsFill()
-    {
+{
   for (int i = 0; i < minimum_cards_at_hand; ++i )
   {
-      GetNextCardFromDeck(0);
-      GetNextCardFromDeck(1);
+    GetNextCardFromDeck(0);
+    GetNextCardFromDeck(1);
   }
   pArcomageGame->field_F6 = 1;
-
 }
 // 4E1874: using guessed type int dword_4E1874;
 
 //----- (0040A283) --------------------------------------------------------
 void GetNextCardFromDeck( int player_num )
-    {
+{
   signed int deck_index; // eax@1
   int new_card_id; // edi@1
   signed int card_slot_indx; // eax@7
@@ -1456,16 +1273,16 @@
       deck_index = deck_walk_index;
     }
     if ( !playDeck.cardsInUse[deck_index] )
-        {
-        new_card_id = playDeck.cards_IDs[deck_index];
-        ++deck_index;
-        deck_walk_index = deck_index;
-        break;
-        }
+    {
+      new_card_id = playDeck.cards_IDs[deck_index];
+      ++deck_index;
+      deck_walk_index = deck_index;
+      break;
+    }
     ++deck_index;
     deck_walk_index = deck_index;
   }
-  
+
   ArcomageGame::PlaySound(21);
   card_slot_indx = GetEmptyCardSlotIndex(player_num);
   if ( card_slot_indx != -1 )
@@ -1477,23 +1294,17 @@
     pArcomageGame->field_F6 = 1;
     byte_4FAA2D = 1;
   }
-
 }
 
-
 //----- (0040A324) --------------------------------------------------------
 int GetEmptyCardSlotIndex( int player_num )
-    {
-  int i; 
-  for (i=0; i<10; ++i )
-      {
-       if (am_Players[player_num].cards_at_hand[i]==-1)
-           break;
-      }
-  if ( i >= 10 )
-      return -1;
-  else
-     return i;  
+{
+  for ( int i = 0; i < 10; ++i )
+  {
+    if (am_Players[player_num].cards_at_hand[i] == -1)
+      return i;
+  }
+  return -1;
 }
 
 //----- (0040A346) --------------------------------------------------------
@@ -1510,7 +1321,6 @@
 {
   char player_name[64]; // [sp+4h] [bp-64h]@4
  // RECT v6; // [sp+44h] [bp-24h]@6
- 
   ArcomageGame_stru1 v10; // [sp+54h] [bp-14h]@7
   POINT v11; // [sp+60h] [bp-8h]@4
 
@@ -1529,7 +1339,7 @@
    //   v11.x = 0;
    //   v11.y = 0;
       strcpy(player_name, "The Next Player is: ");//"След"
-     // v0 = 0;
+      // v0 = 0;
       v11.y = 200;
       v11.x = 320; // - 12 * v0 / 2;
       am_DrawText(-1, player_name, &v11);
@@ -1538,11 +1348,11 @@
       if ( current_player_num >= 2  )
         current_player_num = 0;
       strcpy(player_name, am_Players[current_player_num].pPlayerName);
-     // v4 = 0;
+      // v4 = 0;
       v11.y = 260;
       v11.x = 320;// - 12 * v4 / 2;
       am_DrawText(-1, player_name, &v11);
-     /* v6.left = 0;
+      /* v6.left = 0;
       v6.right = 640;
       v6.top = 0;
       v6.bottom = 480;*/
@@ -1550,24 +1360,24 @@
       pRenderer->Present();
       //nullsub_1();
       while ( 1 )
-      {  
-          while ( !ArcomageGame::MsgLoop(20, &v10) )
-            ;
-          if ( v10.field_0 == 1 )
-              {
-              if ( v10.field_4 )
-                  break;
-              //nullsub_1();
-              continue;
-              }
-           if (( v10.field_0 > 4 )&& ( v10.field_0 <= 8 )) 
-               break;
-           if ( v10.field_0 == 10 )
-               {
-               pArcomageGame->field_F4 = 1;
-               byte_4FAA74 = 1;
-               break;
-               }
+      {
+        while ( !ArcomageGame::MsgLoop(20, &v10) )
+          ;
+        if ( v10.field_0 == 1 )
+        {
+          if ( v10.field_4 )
+            break;
+          //nullsub_1();
+          continue;
+        }
+        if (( v10.field_0 > 4 ) && ( v10.field_0 <= 8 ))
+          break;
+        if ( v10.field_0 == 10 )
+        {
+          pArcomageGame->field_F4 = 1;
+          byte_4FAA74 = 1;
+          break;
+        }
       }
       /*  v11.x = 0;
       v11.y = 0;
@@ -1581,14 +1391,13 @@
   }
 }
 
-
 //----- (0040A514) --------------------------------------------------------
 bool IsGameOver()
 {
   bool result; // eax@1
 
   result = false;
-  for(int i=0; i<2; ++i)
+  for( int i = 0; i < 2; ++i )
   {
     if ( am_Players[i].tower_height <= 0 )
        result  = true;
@@ -1603,10 +1412,9 @@
   return am_gameover = result;
 }
 
-
 //----- (0040A560) --------------------------------------------------------
 char PlayerTurn( int player_num )
-    {
+{
   int v1; // ebp@0
   unsigned __int64 v2; // qax@3
   unsigned __int64 v3; // kr00_8@3
@@ -1633,16 +1441,14 @@
     byte_4FAA2D = 1;
   do
   {
-   
-      do
-      {
-        v3 = pEventTimer->Time() - pArcomageGame->event_timer_time;
-      }
-      while (v3 < 6);
-    
+    do
+    {
+      v3 = pEventTimer->Time() - pArcomageGame->event_timer_time;
+    }
+    while (v3 < 6);
     pArcomageGame->event_timer_time = (unsigned int)pEventTimer->Time();
     if ( pArcomageGame->field_F4 )
-      break_loop = 1;
+      break_loop = true;
     ArcomageGame::MsgLoop(0, &a2);
     switch ( a2.field_0 )
     {
@@ -1700,9 +1506,7 @@
             byte_4FAA00 = 0;
           }
           else
-          {
             break_loop = true;
-          }
           byte_4FAA2E = 0;
           animation_stage = 20;
         }
@@ -1807,9 +1611,9 @@
       pTargetXY.x = 0;
       pTargetXY.y = 0;
       pSrcXYZW.left = 0;
-      pSrcXYZW.right = 640;
+      pSrcXYZW.right = window->GetWidth();
       pSrcXYZW.top = 0;
-      pSrcXYZW.bottom = 480;
+      pSrcXYZW.bottom = window->GetHeight();
       am_BeginScene(pArcomageGame->pBackgroundPixels, -1, 1);
       pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
       am_EndScene();
@@ -1831,20 +1635,20 @@
   am_EndScene();
 
   am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-  DrawCards();
-  DrawPlayersTowers();
-  DrawPlayersWall();
-  DrawPlayersText();
+  DrawCards();//рисуем карты
+  DrawPlayersTowers();//рисуем башню
+  DrawPlayersWall();//рисуем стену
+  DrawPlayersText();//рисуем текст
   am_EndScene();
 
   am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
   DrawCardAnimation(animation_stage);
 
-  for( int i=0; i<10; ++i)
-      {
-      if (array_4FABD0[i].have_effect)
-          array_4FABD0[i].field_40->DrawEffect();
-      }
+  for( int i = 0; i < 10; ++i )
+  {
+    if (array_4FABD0[i].have_effect)
+      array_4FABD0[i].field_40->DrawEffect();
+  }
   current_card_slot_index = DrawCardsRectangles(current_player_num);
   DrawSparks();
   am_EndScene();
@@ -1852,37 +1656,35 @@
 
 //----- (0040AA4E) --------------------------------------------------------
 void DrawSparks()
-    {
+{
   int rgb_pixel_color; // [sp-4h] [bp-2Ch]@4
   unsigned int pixel_color;
 
-  for (int i=0; i<10; ++i)
+  for ( int i = 0; i < 10; ++i )
+  {
+    if(array_4FABD0[i].have_effect && (array_4FABD0[i].field_40->_40E2A7()==2))
+    {
+      rgb_pixel_color = 0x0000FF00;
+      if ( !array_4FABD0[i].effect_sign )
+        rgb_pixel_color =  0x000000FF;
+      pixel_color = R8G8B8_to_TargetFormat(rgb_pixel_color);
+      for( int j = 0; j < 150; ++j )
       {
-        if(array_4FABD0[i].have_effect && (array_4FABD0[i].field_40->_40E2A7()==2))
-            {
-            rgb_pixel_color = 0x0000FF00;
-            if ( !array_4FABD0[i].effect_sign )
-                rgb_pixel_color =  0x000000FF;
-
-             pixel_color = R8G8B8_to_TargetFormat(rgb_pixel_color);
-             for(int j=0; j<150; ++j )
-                 {
-                 if (array_4FABD0[i].effect_sparks[j].have_spark > 0)
-                     {
-                      if (j%2)
-                          DrawPixel(&array_4FABD0[i].effect_sparks[j].spark_position, pixel_color);
-                      else
-                          DrawSquare(&array_4FABD0[i].effect_sparks[j].spark_position, pixel_color);
-                     }
-                 }
-            }
+        if (array_4FABD0[i].effect_sparks[j].have_spark > 0)
+        {
+          if ( j%2 )
+            DrawPixel(&array_4FABD0[i].effect_sparks[j].spark_position, pixel_color);
+          else
+            DrawSquare(&array_4FABD0[i].effect_sparks[j].spark_position, pixel_color);
+        }
       }
-
+    }
+  }
 }
 
 //----- (0040AB0A) --------------------------------------------------------
 void DrawRectanglesForText()
-{ 
+{
   RECT pSrcRect; // [sp+Ch] [bp-18h]@1
   POINT pTargetXY; // [sp+1Ch] [bp-8h]@1
 
@@ -1942,8 +1744,7 @@
 
 //----- (0040AC5F) --------------------------------------------------------
 void DrawPlayersText()
-    {
- 
+{
   int res_value; // ecx@18
   char text_buff[32]; // [sp+Ch] [bp-28h]@2
   POINT text_position; // [sp+2Ch] [bp-8h]@2
@@ -2076,7 +1877,7 @@
 
 //----- (0040B102) --------------------------------------------------------
 void DrawPlayerLevels( int a1, char *text, POINT *pXY )
-    {
+{
   char *v3; // esi@1
   unsigned char test_char; // bl@2
   int v7; // eax@3
@@ -2108,557 +1909,518 @@
 
 //----- (0040B17E) --------------------------------------------------------
 void DrawBricksCount( int a1, char* text, POINT *pXY )
+{
+  char *v3; // esi@1
+  unsigned char test_char; // bl@2
+  int v7; // eax@3
+  RECT pSrcRect;
+  POINT pTargetPoint;
+
+  v3 = text;
+  am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
+  pTargetPoint.x = pXY->x;
+  pTargetPoint.y = pXY->y;
+  do
+  {
+    test_char = *v3;
+    ++v3;
+    if ( test_char )
     {
-
-    char *v3; // esi@1
-    unsigned char test_char; // bl@2
-    int v7; // eax@3
-    RECT pSrcRect;
-    POINT pTargetPoint;
-
-    v3 = text;
-    am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-    pTargetPoint.x = pXY->x;
-    pTargetPoint.y = pXY->y;
-    do
-        {
-        test_char = *v3;
-        ++v3;
-        if ( test_char )
-            {
-            v7 = 13 * test_char;
-            pSrcRect.left = v7 - 370;
-            pSrcRect.right = v7 - 357;
-            pSrcRect.top = 128;
-            pSrcRect.bottom = 138;
-            pRenderer->am_Blt_Copy(&pSrcRect, &pTargetPoint, 2);
-            pTargetPoint.x += 13;
-            }
-        }
-        while ( test_char!= 0 );
-        am_EndScene();
-
+      v7 = 13 * test_char;
+      pSrcRect.left = v7 - 370;
+      pSrcRect.right = v7 - 357;
+      pSrcRect.top = 128;
+      pSrcRect.bottom = 138;
+      pRenderer->am_Blt_Copy(&pSrcRect, &pTargetPoint, 2);
+      pTargetPoint.x += 13;
+    }
+  }
+  while ( test_char!= 0 );
+  am_EndScene();
 }
 
 //----- (0040B1F3) --------------------------------------------------------
 void DrawGemsCount( int a1, char* text, POINT* pXY )
+{
+  char *v3; // esi@1
+  unsigned char test_char; // bl@2
+  int v7; // eax@3
+  RECT pSrcRect;
+  POINT pTargetPoint;
+
+  v3 = text;
+  am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
+  pTargetPoint.x = pXY->x;
+  pTargetPoint.y = pXY->y;
+  do
+  {
+    test_char = *v3;
+    ++v3;
+    if ( test_char )
     {
-
-    char *v3; // esi@1
-    unsigned char test_char; // bl@2
-    int v7; // eax@3
-    RECT pSrcRect;
-    POINT pTargetPoint;
-
-    v3 = text;
-    am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-    pTargetPoint.x = pXY->x;
-    pTargetPoint.y = pXY->y;
-    do
-        {
-        test_char = *v3;
-        ++v3;
-        if ( test_char )
-            {
-            v7 = 13 * test_char;
-            pSrcRect.left = v7 - 370;
-            pSrcRect.right = v7 - 357;
-            pSrcRect.top = 138;
-            pSrcRect.bottom = 148;
-            pRenderer->am_Blt_Copy(&pSrcRect, &pTargetPoint, 2);
-            pTargetPoint.x += 13;
-            }
-        }
-        while ( test_char!= 0 );
-        am_EndScene();
-  
+      v7 = 13 * test_char;
+      pSrcRect.left = v7 - 370;
+      pSrcRect.right = v7 - 357;
+      pSrcRect.top = 138;
+      pSrcRect.bottom = 148;
+      pRenderer->am_Blt_Copy(&pSrcRect, &pTargetPoint, 2);
+      pTargetPoint.x += 13;
+    }
+  }
+  while ( test_char!= 0 );
+  am_EndScene();
 }
 
 //----- (0040B268) --------------------------------------------------------
 void DrawBeastsCount( int a1, char *text, POINT *pXY )
+{
+  char *v3; // esi@1
+  unsigned char test_char; // bl@2
+  int v7; // eax@3
+  RECT pSrcRect;
+  POINT pTargetPoint;
+
+  v3 = text;
+  am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
+  pTargetPoint.x = pXY->x;
+  pTargetPoint.y = pXY->y;
+  do
+  {
+    test_char = *v3;
+    ++v3;
+    if ( test_char )
     {
-
-    char *v3; // esi@1
-    unsigned char test_char; // bl@2
-    int v7; // eax@3
-    RECT pSrcRect;
-    POINT pTargetPoint;
-
-    v3 = text;
-    am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-    pTargetPoint.x = pXY->x;
-    pTargetPoint.y = pXY->y;
-    do
-        {
-        test_char = *v3;
-        ++v3;
-        if ( test_char )
-            {
-            v7 = 13 * test_char;
-            pSrcRect.left = v7 - 370;
-            pSrcRect.right = v7 - 357;
-            pSrcRect.top = 148;
-            pSrcRect.bottom = 158;
-            pRenderer->am_Blt_Copy(&pSrcRect, &pTargetPoint, 2);
-            pTargetPoint.x += 13;
-            }
-        }
-        while ( test_char!= 0 );
-        am_EndScene();
-
+      v7 = 13 * test_char;
+      pSrcRect.left = v7 - 370;
+      pSrcRect.right = v7 - 357;
+      pSrcRect.top = 148;
+      pSrcRect.bottom = 158;
+      pRenderer->am_Blt_Copy(&pSrcRect, &pTargetPoint, 2);
+      pTargetPoint.x += 13;
+    }
+  }
+  while ( test_char!= 0 );
+  am_EndScene();
 }
 
 //----- (0040B2DD) --------------------------------------------------------
 void DrawPlayersTowers()
-    {
-int tower_height; // eax@1
-int tower_top; // esi@3
-RECT pSrcXYZW; // [sp+0h] [bp-18h]@3
-POINT pTargetXY; // [sp+10h] [bp-8h]@3
-
-tower_height= am_Players[0].tower_height;
-if ( am_Players[0].tower_height > max_tower_height )
-      tower_height = max_tower_height;
-pSrcXYZW.top = 0;
-pSrcXYZW.left = 892;
-pSrcXYZW.right = 937;
-tower_top = 200 * tower_height / max_tower_height;
-pSrcXYZW.bottom = tower_top;
-pTargetXY.x = 102;
-pTargetXY.y = 297 - tower_top;
-pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
-
-pSrcXYZW.top = 0;
-pSrcXYZW.left = 384;
-pSrcXYZW.right = 452;
-pSrcXYZW.bottom = 94;
-pTargetXY.y = 203 - tower_top;
-pTargetXY.x = 91;
-pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
-
-
-tower_height = am_Players[1].tower_height;
-if (am_Players[1].tower_height  > max_tower_height )
+{
+  int tower_height; // eax@1
+  int tower_top; // esi@3
+  RECT pSrcXYZW; // [sp+0h] [bp-18h]@3
+  POINT pTargetXY; // [sp+10h] [bp-8h]@3
+
+  tower_height= am_Players[0].tower_height;
+  if ( am_Players[0].tower_height > max_tower_height )
     tower_height = max_tower_height;
-tower_top = 200 * tower_height / max_tower_height;
-pSrcXYZW.top    = 0;
-pSrcXYZW.left   = 892;
-pSrcXYZW.right  = 937;
-pSrcXYZW.bottom = tower_top;
-
-pTargetXY.x = 494;
-pTargetXY.y = 297 - tower_top;
-pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
-//draw tower up cone
-pSrcXYZW.left   = 384;
-pSrcXYZW.right  = 452;
-pSrcXYZW.top    =  94;
-pSrcXYZW.bottom = 188;
-
-pTargetXY.x = 483;
-pTargetXY.y = 203 - tower_top;
-pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
- 
+  pSrcXYZW.top = 0;
+  pSrcXYZW.left = 892;
+  pSrcXYZW.right = 937;
+  tower_top = 200 * tower_height / max_tower_height;
+  pSrcXYZW.bottom = tower_top;
+  pTargetXY.x = 102;
+  pTargetXY.y = 297 - tower_top;
+  pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);//стена башни
+
+  pSrcXYZW.top = 0;
+  pSrcXYZW.left = 384;
+  pSrcXYZW.right = 452;
+  pSrcXYZW.bottom = 94;
+  pTargetXY.y = 203 - tower_top;
+  pTargetXY.x = 91;
+  pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);//верхушка башни
+
+  tower_height = am_Players[1].tower_height;
+  if (am_Players[1].tower_height  > max_tower_height )
+    tower_height = max_tower_height;
+  tower_top = 200 * tower_height / max_tower_height;
+  pSrcXYZW.top    = 0;
+  pSrcXYZW.left   = 892;
+  pSrcXYZW.right  = 937;
+  pSrcXYZW.bottom = tower_top;
+
+  pTargetXY.x = 494;
+  pTargetXY.y = 297 - tower_top;
+  pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
+  //draw tower up cone
+  pSrcXYZW.left   = 384;
+  pSrcXYZW.right  = 452;
+  pSrcXYZW.top    =  94;
+  pSrcXYZW.bottom = 188;
+
+  pTargetXY.x = 483;
+  pTargetXY.y = 203 - tower_top;
+  pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
 }
 // 4E1884: using guessed type int dword_4E1884;
 
 //----- (0040B400) --------------------------------------------------------
 void DrawPlayersWall()
-    {
-int v0; // eax@1
-int v1; // eax@4
-LONG v2; // ecx@4
-int v3; // eax@5
-int v4; // eax@8
-LONG v5; // esi@8
-RECT pSrcXYZW; // [sp+4h] [bp-18h]@4
-POINT pTargetXY; // [sp+14h] [bp-8h]@4
-
-v0 = am_Players[0].wall_height;
-
-if ( am_Players[0].wall_height > 100 )
+{
+  int v0; // eax@1
+  int v1; // eax@4
+  LONG v2; // ecx@4
+  int v3; // eax@5
+  int v4; // eax@8
+  LONG v5; // esi@8
+  RECT pSrcXYZW; // [sp+4h] [bp-18h]@4
+  POINT pTargetXY; // [sp+14h] [bp-8h]@4
+
+  v0 = am_Players[0].wall_height;
+
+  if ( am_Players[0].wall_height > 100 )
     v0 = 100;
 
-if ( am_Players[0].wall_height > 0 )
-       {
-
-pSrcXYZW.top = 0;
-pSrcXYZW.left = 843;
-v1 = 200 * v0 / 100;
-pSrcXYZW.right = 867;
-pSrcXYZW.bottom = v1;
-pTargetXY.x = 177;
-pTargetXY.y = 297 - v1;
-pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
- }
-
-v3 = am_Players[1].wall_height;
-if ( am_Players[1].wall_height > 100 )
- v3 = 100;
-
-    
-    if ( am_Players[1].wall_height > 0 )
-        {
- 
-pSrcXYZW.top = 0;
-pSrcXYZW.left = 843;
-v4 = 200 * v3 / 100;
-pSrcXYZW.right = 867;
-pSrcXYZW.bottom = v4;
-pTargetXY.x = 439;
-pTargetXY.y =  297 - v4;
-pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
-        }
+  if ( am_Players[0].wall_height > 0 )
+  {
+    pSrcXYZW.top = 0;
+    pSrcXYZW.left = 843;
+    v1 = 200 * v0 / 100;
+    pSrcXYZW.right = 867;
+    pSrcXYZW.bottom = v1;
+    pTargetXY.x = 177;
+    pTargetXY.y = 297 - v1;
+    pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
+  }
+  v3 = am_Players[1].wall_height;
+  if ( am_Players[1].wall_height > 100 )
+    v3 = 100;
+  if ( am_Players[1].wall_height > 0 )
+  {
+    pSrcXYZW.top = 0;
+    pSrcXYZW.left = 843;
+    v4 = 200 * v3 / 100;
+    pSrcXYZW.right = 867;
+    pSrcXYZW.bottom = v4;
+    pTargetXY.x = 439;
+    pTargetXY.y =  297 - v4;
+    pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
+  }
 }
 
 //----- (0040B4B9) --------------------------------------------------------
 void DrawCards()
-    {
-
-int v0; // esi@1
-char v1; // bl@1
-int v2; // edi@1
-int v3; // edx@2
-int v4; // eax@3
-int v5; // ecx@3
-int v6; // eax@3
-unsigned int v7; // ecx@4
-int v8; // eax@16
-int v9; // ecx@16
-int v10; // eax@16
-signed int v11; // edi@18
-signed int v12; // esi@20
-int v13; // ecx@20
-int v14; // eax@23
-signed int v15; // eax@25
-int v16; // ecx@25
-POINT *v17; // esi@26
-signed int v18; // eax@29
-AcromageCardOnTable *v19; // ecx@29
-int v20; // ecx@31
-int v21; // [sp-4h] [bp-2Ch]@8
-RECT pSrcXYZW; // [sp+Ch] [bp-1Ch]@8
-POINT pTargetXY; // [sp+1Ch] [bp-Ch]@1
-int v24; // [sp+24h] [bp-4h]@1
-
-v0 = GetPlayerHandCardCount(current_player_num);
-v2 = 0;
-pTargetXY.y = 327;
-v24 = (640 - 96 * v0) / (v0 + 1);
-pTargetXY.x = (640 - 96 * v0) / (v0 + 1);
-while ( v2 < v0 )
+{
+  int v0; // esi@1
+  char v1; // bl@1
+  int v2; // edi@1
+  //int v3; // edx@2
+  int v4; // eax@3
+  int v5; // ecx@3
+  int v6; // eax@3
+  unsigned int v7; // ecx@4
+  int v8; // eax@16
+  int v9; // ecx@16
+  int v10; // eax@16
+  signed int v11; // edi@18
+  signed int v12; // esi@20
+  int v13; // ecx@20
+  int v14; // eax@23
+  signed int v15; // eax@25
+  int v16; // ecx@25
+  POINT *v17; // esi@26
+  signed int v18; // eax@29
+  AcromageCardOnTable *v19; // ecx@29
+  int v20; // ecx@31
+  int v21; // [sp-4h] [bp-2Ch]@8
+  RECT pSrcXYZW; // [sp+Ch] [bp-1Ch]@8
+  POINT pTargetXY; // [sp+1Ch] [bp-Ch]@1
+  int v24; // [sp+24h] [bp-4h]@1
+
+  v0 = GetPlayerHandCardCount(current_player_num);
+  pTargetXY.y = 327;
+  v24 = (window->GetWidth() - 96 * v0) / (v0 + 1);
+  pTargetXY.x = (window->GetWidth() - 96 * v0) / (v0 + 1);
+  for ( v2 = 0; v2 < v0; ++v2 )
+  {
+    //v3 = current_player_num;
+    if ( am_byte_4E185D)
     {
-    v3 = current_player_num;
-    if ( am_byte_4E185D)
-        {
-
-        pTargetXY.x += am_Players[current_player_num].card_shift[v2].x ;
-        pTargetXY.y += am_Players[current_player_num].card_shift[v2].y;
-        }
+      pTargetXY.x += am_Players[current_player_num].card_shift[v2].x;
+      pTargetXY.y += am_Players[current_player_num].card_shift[v2].y;
+    }
     v7 = am_Players[current_player_num].cards_at_hand[v2];
-    if ( v7 == -1 )
-        {
-        ++v0;
-        goto LABEL_15;
-        }
+    if ( am_Players[current_player_num].cards_at_hand[v2] == -1 )
+    {
+      ++v0;
+      goto LABEL_15;
+    }
     if ( v2 != amuint_4FAA4C )
-        {
-        if ( am_Players[current_player_num].IsHisTurn == 0 && byte_505881 == 0 )
-            {
-            pSrcXYZW.left = 192;
-            pSrcXYZW.right = 288;
-            pSrcXYZW.top = 0;
-            pSrcXYZW.bottom = 128;
-            pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
-            goto LABEL_13;
-            }
-        pArcomageGame->GetCardRect(v7, &pSrcXYZW);
-        if ( !CanCardBePlayed(current_player_num, v2) )
-            {
-            pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 0);
-            goto LABEL_13;
-            }
-        pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
-
-        }
-LABEL_13:
-    v3 = current_player_num;
+    {
+      if ( am_Players[current_player_num].IsHisTurn == 0 && byte_505881 == 0 )
+      {
+        pSrcXYZW.left = 192;
+        pSrcXYZW.right = 288;
+        pSrcXYZW.top = 0;
+        pSrcXYZW.bottom = 128;
+        pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);//рисуется оборотные стороны карт противника
+        pTargetXY.x += v24 + 96;
+        goto LABEL_15;
+      }
+      pArcomageGame->GetCardRect(v7, &pSrcXYZW);
+      if ( !CanCardBePlayed(current_player_num, v2) )
+      {
+        pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 0);//рисуются неактивные карты
+        pTargetXY.x += v24 + 96;
+        goto LABEL_15;
+      }
+      pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);//рисуются активные карты
+    }
     pTargetXY.x += v24 + 96;
 LABEL_15:
     if ( am_byte_4E185D )
-        {
-        pTargetXY.x -= am_Players[current_player_num].card_shift[v2].x ;
-        pTargetXY.y -= am_Players[current_player_num].card_shift[v2].y ;
-        }
-    ++v2;
+    {
+      pTargetXY.x -= am_Players[current_player_num].card_shift[v2].x;
+      pTargetXY.y -= am_Players[current_player_num].card_shift[v2].y;
     }
-
-for (v11=0; v11<10; ++v11)
-    {
+  }
+
+  for ( v11 = 0; v11 < 10; ++v11 )
+  {
     if ( am_byte_4FAA76 == 0 )
-        {
-        if ( shown_cards[v11].uCardId != -1 )
-            {
-            pArcomageGame->GetCardRect(shown_cards[v11].uCardId, &pSrcXYZW);
-            pRenderer->am_Blt_Copy(&pSrcXYZW, &shown_cards[v11].field_18_point, 0);
-            }
-        if ( shown_cards[v11].field_4 != 0 )
-            {
-            pTargetXY.x = shown_cards[v11].field_18_point.x + 12;
-            pTargetXY.y = shown_cards[v11].field_18_point.y + 40;
-            pSrcXYZW.left   = 843;
-            pSrcXYZW.right  = 916;
-            pSrcXYZW.top    = 200;
-            pSrcXYZW.bottom = 216;
-            pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
-            }
-        }
+    {
+      if ( shown_cards[v11].uCardId != -1 )
+      {
+        pArcomageGame->GetCardRect(shown_cards[v11].uCardId, &pSrcXYZW);
+        pRenderer->am_Blt_Copy(&pSrcXYZW, &shown_cards[v11].field_18_point, 0);
+      }
+      if ( shown_cards[v11].field_4 != 0 )
+      {
+        pTargetXY.x = shown_cards[v11].field_18_point.x + 12;
+        pTargetXY.y = shown_cards[v11].field_18_point.y + 40;
+        pSrcXYZW.left   = 843;
+        pSrcXYZW.right  = 916;
+        pSrcXYZW.top    = 200;
+        pSrcXYZW.bottom = 216;
+        pRenderer->am_Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
+      }
+    }
     else if ( amuint_4FAA34 <= 0 )
-        {
-        if ( v11 == 9 )
-            {
-            am_byte_4FAA76 = 0;
-            am_byte_4FAA75 = 0;
-            amuint_4FAA34 = 5;
-            }
-        if ( shown_cards[v11].uCardId != -1 )
-            amuint_4FABC4 = shown_cards[v11].uCardId;
-        shown_cards[v11].uCardId = -1;
-        shown_cards[v11].field_18_point.x = shown_cards[v11].field_8.x;
-        shown_cards[v11].field_18_point.y = shown_cards[v11].field_8.y;
-        shown_cards[v11].field_4 = 0;
-        }
+    {
+      if ( v11 == 9 )
+      {
+        am_byte_4FAA76 = 0;
+        am_byte_4FAA75 = 0;
+        amuint_4FAA34 = 5;
+      }
+      if ( shown_cards[v11].uCardId != -1 )
+        amuint_4FABC4 = shown_cards[v11].uCardId;
+      shown_cards[v11].uCardId = -1;
+      shown_cards[v11].field_18_point.x = shown_cards[v11].field_8.x;
+      shown_cards[v11].field_18_point.y = shown_cards[v11].field_8.y;
+      shown_cards[v11].field_4 = 0;
+    }
     else
-        {
-        if ( shown_cards[v11].uCardId != -1 )
-            {
-            shown_cards[v11].field_18_point.x += shown_cards[v11].field_10_xplus;
-            shown_cards[v11].field_18_point.y += shown_cards[v11].field_14_y_plus;
-            pArcomageGame->GetCardRect(shown_cards[v11].uCardId, &pSrcXYZW);
-            pRenderer->am_Blt_Copy(&pSrcXYZW, &shown_cards[v11].field_18_point, 0);
-            }
-        }
+    {
+      if ( shown_cards[v11].uCardId != -1 )
+      {
+        shown_cards[v11].field_18_point.x += shown_cards[v11].field_10_xplus;
+        shown_cards[v11].field_18_point.y += shown_cards[v11].field_14_y_plus;
+        pArcomageGame->GetCardRect(shown_cards[v11].uCardId, &pSrcXYZW);
+        pRenderer->am_Blt_Copy(&pSrcXYZW, &shown_cards[v11].field_18_point, 0);
+      }
     }
-    if ( am_byte_4FAA76 != 0 )
-        --amuint_4FAA34;
-
-    pSrcXYZW.left   = 192;
-    pSrcXYZW.right  = 288;
-    pSrcXYZW.top    = 0;
-    pSrcXYZW.bottom = 128;
-    pTargetXY.x     = 120;
-    pTargetXY.y     = 18;
-    pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 0);
-
+  }
+  if ( am_byte_4FAA76 != 0 )
+    --amuint_4FAA34;
+  pSrcXYZW.left   = 192;
+  pSrcXYZW.right  = 288;
+  pSrcXYZW.top    = 0;
+  pSrcXYZW.bottom = 128;
+  pTargetXY.x     = 120;
+  pTargetXY.y     = 18;
+  pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 0);
 }
 
-
 //----- (0040B76F) --------------------------------------------------------
 void DrawCardAnimation( int animation_stage )
+{
+  int v1; // eax@3
+  int v2; // eax@3
+  int v3; // esi@4
+  int v4; // eax@4
+  POINT *v5; // edx@6
+  RECT *v6; // ecx@6
+  int v8; // eax@15
+  AcromageCardOnTable *v9; // ecx@15
+  int v10; // ecx@19
+  int v11; // eax@20
+  int v12; // ecx@20
+  int v13; // eax@20
+  unsigned int v14; // ecx@21
+  double v15; // st7@22
+  POINT *v16; // edx@23
+  int v17; // eax@32
+  char v18; // zf@37
+  int v19; // eax@41
+  int v20; // eax@46
+  int v21; // ecx@46
+  int v22; // eax@46
+  int v23; // [sp-4h] [bp-2Ch]@28
+  RECT pSrcXYZW; // [sp+Ch] [bp-1Ch]@6
+  POINT pTargetXY; // [sp+1Ch] [bp-Ch]@20
+  int v26; // [sp+24h] [bp-4h]@1
+
+  v26 = animation_stage;
+  if ( amuint_4FAA4C != -1 )
+  {
+    if ( amuint_4FAA38 >= 9 )
     {
-
-int v1; // eax@3
-int v2; // eax@3
-int v3; // esi@4
-int v4; // eax@4
-POINT *v5; // edx@6
-RECT *v6; // ecx@6
-
-int v8; // eax@15
-AcromageCardOnTable *v9; // ecx@15
-int v10; // ecx@19
-int v11; // eax@20
-int v12; // ecx@20
-int v13; // eax@20
-unsigned int v14; // ecx@21
-double v15; // st7@22
-POINT *v16; // edx@23
-int v17; // eax@32
-char v18; // zf@37
-int v19; // eax@41
-int v20; // eax@46
-int v21; // ecx@46
-int v22; // eax@46
-int v23; // [sp-4h] [bp-2Ch]@28
-RECT pSrcXYZW; // [sp+Ch] [bp-1Ch]@6
-POINT pTargetXY; // [sp+1Ch] [bp-Ch]@20
-int v26; // [sp+24h] [bp-4h]@1
-
-v26 = animation_stage;
-if ( amuint_4FAA4C != -1 )
+      am_uint_4FAA44_blt_xy.y = 18;
+      am_uint_4FAA44_blt_xy.x = 120;
+      v1 = GetPlayerHandCardCount(current_player_num);
+      v2 = (window->GetWidth() - 96 * v1) / v1 + 96;
+      if ( am_byte_4E185D )
+      {
+        // v3 = 188 * current_player_num + 8 * amuint_4FAA4C;
+        // amuint_4FAA3C_blt_xy.x = (amuint_4FAA4C * v2 + *(am_Players[0].arr_6C[0] + v3) - 120) / 10;
+        amuint_4FAA3C_blt_xy.x=(amuint_4FAA4C * v2 + am_Players[current_player_num].card_shift[amuint_4FAA4C].x-120)/10;
+        v4 = (am_Players[current_player_num].card_shift[amuint_4FAA4C].y+309) /10;//(*(&am_Players[0].arr_6C[0][1] + v3) + 309) / 10;
+      }
+      else
+      {
+        amuint_4FAA3C_blt_xy.x = (amuint_4FAA4C * v2 - 120) / 10;
+        v4 = 30;
+      }
+      am_uint_4FAA44_blt_xy.y += v4;
+      am_uint_4FAA44_blt_xy.x += amuint_4FAA3C_blt_xy.x;
+      amuint_4FAA3C_blt_xy.y = v4;
+      pSrcXYZW.left = 192;
+      pSrcXYZW.top = 0;
+      pSrcXYZW.right = 288;
+      pSrcXYZW.bottom = 128;
+      pRenderer->am_Blt_Copy(&pSrcXYZW, &am_uint_4FAA44_blt_xy, 2);
+    }
+    else
     {
-    if ( amuint_4FAA38 >= 9 )
+      pSrcXYZW.left  = 192;
+      pSrcXYZW.top    = 0;
+      pSrcXYZW.right  = 288;
+      pSrcXYZW.bottom = 128;
+      am_uint_4FAA44_blt_xy.x += amuint_4FAA3C_blt_xy.x;
+      am_uint_4FAA44_blt_xy.y += amuint_4FAA3C_blt_xy.y;
+      pRenderer->am_Blt_Copy(&pSrcXYZW, &am_uint_4FAA44_blt_xy, 2);
+      if ( !amuint_4FAA38 )
+       amuint_4FAA4C = -1;
+    }
+  }
+  if ( uCardID != -1 )
+  {
+    if ( v26 <= 10 )
+    {
+      if ( v26 == 10 )
+      {
+        pArcomageGame->GetCardRect(uCardID, &pSrcXYZW);
+        //  v8 = 0;
+        for ( v8 = 0; v8 < 10; ++v8 )
         {
-        am_uint_4FAA44_blt_xy.y = 18;
-        am_uint_4FAA44_blt_xy.x = 120;
-        v1 = GetPlayerHandCardCount(current_player_num);
-        v2 = (640 - 96 * v1) / v1 + 96;
-        if ( am_byte_4E185D )
-            {
-           // v3 = 188 * current_player_num + 8 * amuint_4FAA4C;
-           // amuint_4FAA3C_blt_xy.x = (amuint_4FAA4C * v2 + *(am_Players[0].arr_6C[0] + v3) - 120) / 10;
-            amuint_4FAA3C_blt_xy.x=(amuint_4FAA4C * v2 + am_Players[current_player_num].card_shift[amuint_4FAA4C].x-120)/10;
-            v4 = (am_Players[current_player_num].card_shift[amuint_4FAA4C].y+309) /10;//(*(&am_Players[0].arr_6C[0][1] + v3) + 309) / 10;
-            }
-        else
-            {
-            amuint_4FAA3C_blt_xy.x = (amuint_4FAA4C * v2 - 120) / 10;
-            v4 = 30;
-            }
-        am_uint_4FAA44_blt_xy.y += v4;
-        am_uint_4FAA44_blt_xy.x += amuint_4FAA3C_blt_xy.x;
-        
-        amuint_4FAA3C_blt_xy.y = v4;
-        
-        pSrcXYZW.left = 192;
-        pSrcXYZW.top = 0;
-        pSrcXYZW.right = 288;
-        pSrcXYZW.bottom = 128;
-        pRenderer->am_Blt_Copy(&pSrcXYZW, &am_uint_4FAA44_blt_xy, 2);
+          if (shown_cards[v8].uCardId==-1)
+          {
+            shown_cards[v8].uCardId = uCardID;
+            shown_cards[v8].field_4 = 1;
+            break;
+          }
         }
-    else
+        /* v9 = shown_cards;
+        while ( v9->uCardId != -1 )
         {
-
-    
-    pSrcXYZW.left  = 192;
-    pSrcXYZW.top    = 0;
-    pSrcXYZW.right  = 288;
-    pSrcXYZW.bottom = 128;
-    am_uint_4FAA44_blt_xy.x += amuint_4FAA3C_blt_xy.x;
-    am_uint_4FAA44_blt_xy.y += amuint_4FAA3C_blt_xy.y;
-    pRenderer->am_Blt_Copy(&pSrcXYZW, &am_uint_4FAA44_blt_xy, 2);
-    if ( !amuint_4FAA38 )
-        {
-        
-    amuint_4FAA4C = -1;
+          ++v9;
+          ++v8;
+          if ( v9 >= &dword_4FABB8 )
+          goto LABEL_20;
         }
-        }
+        v10 = v8;
+        shown_cards[v10].uCardId = uCardID;
+        shown_cards[v10].field_4 = 1;*/
+//LABEL_20:
+        pTargetXY.x = shown_cards[v8].field_8.x;
+        pTargetXY.y = shown_cards[v8].field_8.y;
+        pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 0);
+        uCardID = -1;
+      }
     }
-LABEL_11:
-
-if ( uCardID != -1 )
+    else
+    {
+      pArcomageGame->GetCardRect(uCardID, &pSrcXYZW);
+      amuint_4FAA5C_blt_xy.x += amuint_4FAA54_blt_xy.x;
+      amuint_4FAA5C_blt_xy.y += amuint_4FAA54_blt_xy.y;
+      pRenderer->am_Blt_Copy(&pSrcXYZW, &amuint_4FAA5C_blt_xy, 0);
+    }
+  }
+  if ( played_card_id != -1 )
+  {
+    v15 = v26;
+    if ( v15 > 15.0 )
+    {
+      pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
+      amuint_4FAA5C_blt_xy.x += amuint_4FAA54_blt_xy.x;
+      amuint_4FAA5C_blt_xy.y += amuint_4FAA54_blt_xy.y;
+      pRenderer->am_Blt_Copy(&pSrcXYZW, &amuint_4FAA5C_blt_xy, 2);
+      return;
+    }
+    if ( v15 == 15.0 )
     {
-    if ( v26 <= 10 )
-        {
-        if ( v26 == 10 )
-            {
-            pArcomageGame->GetCardRect(uCardID, &pSrcXYZW);
-          //  v8 = 0;
-            for (v8=0; v8<10; ++v8)
-                {
-                if (shown_cards[v8].uCardId==-1)
-                    {
-                    shown_cards[v8].uCardId = uCardID;
-                    shown_cards[v8].field_4 = 1;
-                    break;
-                    }
-                }
-            /* v9 = shown_cards;
-            while ( v9->uCardId != -1 )
-            {
-            ++v9;
-            ++v8;
-            if ( v9 >= &dword_4FABB8 )
-            goto LABEL_20;
-            }
-
-            v10 = v8;
-            shown_cards[v10].uCardId = uCardID;
-            shown_cards[v10].field_4 = 1;*/
-//LABEL_20:
-            pTargetXY.x = shown_cards[v8].field_8.x;
-            pTargetXY.y = shown_cards[v8].field_8.y;
-            pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 0);
-            uCardID = -1;
-            }
-        }
+      ApplyCardToPlayer(current_player_num, played_card_id);
+      pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
+      pTargetXY.x = 272;
+      pTargetXY.y = 173;
+      pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
+      return;
+    }
+    if ( v15 == 5.0 )
+    {
+      amuint_4FAA5C_blt_xy.x = 272;
+      amuint_4FAA5C_blt_xy.y = 173;
+      for ( v17 = 0; v17 < 10; ++v17 )
+      {
+        if (shown_cards[v17].uCardId == -1)
+          break;
+      }
+      amuint_4FAA54_blt_xy.x = (shown_cards[v17].field_8.x - 272) / 5;
+      amuint_4FAA54_blt_xy.y = (shown_cards[v17].field_8.y - 173) / 5;
+      pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
+      pTargetXY.x = 272;
+      pTargetXY.y = 173;
+      pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
+      return;
+    }
+    if ( v15 >= 5.0 )
+      v18 = v26 == 0;
     else
-        {
-        pArcomageGame->GetCardRect(uCardID, &pSrcXYZW);
+    {
+      v18 = v26 == 0;
+      if ( v26 > 0 )
+      {
+        pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
         amuint_4FAA5C_blt_xy.x += amuint_4FAA54_blt_xy.x;
         amuint_4FAA5C_blt_xy.y += amuint_4FAA54_blt_xy.y;
         pRenderer->am_Blt_Copy(&pSrcXYZW, &amuint_4FAA5C_blt_xy, 0);
-        }
+        return;
+      }
     }
-
-if ( played_card_id != -1 )
+    if ( !v18 )
     {
-    v15 = v26;
-    if ( v15 > 15.0 )
-        {
-        pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
-        amuint_4FAA5C_blt_xy.x += amuint_4FAA54_blt_xy.x;
-        amuint_4FAA5C_blt_xy.y += amuint_4FAA54_blt_xy.y;
-        pRenderer->am_Blt_Copy(&pSrcXYZW, &amuint_4FAA5C_blt_xy, 2);
-        return;
-        }
-    if ( v15 == 15.0 )
-        {
-        ApplyCardToPlayer(current_player_num, played_card_id);
-        pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
-        pTargetXY.x = 272;
-        pTargetXY.y = 173;
-        pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
-        return;
-        }
-    if ( v15 == 5.0 )
-        {
-        amuint_4FAA5C_blt_xy.x = 272;
-        amuint_4FAA5C_blt_xy.y = 173;
-        for (v17=0; v17<10; ++v17)
-            {
-            if (shown_cards[v17].uCardId==-1)
-                break;
-            }
-        
-            amuint_4FAA54_blt_xy.x = (shown_cards[v17].field_8.x - 272) / 5;
-            amuint_4FAA54_blt_xy.y = (shown_cards[v17].field_8.y - 173) / 5;
-            pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
-            pTargetXY.x = 272;
-            pTargetXY.y = 173;
-            pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
-            return;
-        }
-    if ( v15 >= 5.0 )
-        {
-        v18 = v26 == 0;
-        }
-    else
-        {
-        v18 = v26 == 0;
-        if ( v26 > 0 )
-            {
-            pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
-            amuint_4FAA5C_blt_xy.x += amuint_4FAA54_blt_xy.x;
-            amuint_4FAA5C_blt_xy.y += amuint_4FAA54_blt_xy.y;
-            pRenderer->am_Blt_Copy(&pSrcXYZW, &amuint_4FAA5C_blt_xy, 0);
-            return;
-            }
-        }
-    if ( !v18 )
-        {
-
-        pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
-        pTargetXY.x = 272;
-        pTargetXY.y = 173;
-        pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
-        return;
-        }
-
+      pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
+      pTargetXY.x = 272;
+      pTargetXY.y = 173;
+      pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
+      return;
+    }
     pArcomageGame->GetCardRect(played_card_id, &pSrcXYZW);
-    for (v19=0; v19<10; ++v19)
-        {
-        if (shown_cards[v19].uCardId==-1)
-            {
-            shown_cards[v19].uCardId = played_card_id;
-            break;
-            }       
-        }
-        pTargetXY.x = shown_cards[v19].field_8.x;
+    for ( v19 = 0; v19 < 10; ++v19 )
+    {
+      if (shown_cards[v19].uCardId == -1)
+      {
+        shown_cards[v19].uCardId = played_card_id;
+        break;
+      }
+    }
+    pTargetXY.x = shown_cards[v19].field_8.x;
     pTargetXY.y = shown_cards[v19].field_8.y;
     pRenderer->am_Blt_Copy(&pSrcXYZW, &pTargetXY, 0);
     played_card_id = -1;
-    }
+  }
 }
 
 //----- (0040BB12) --------------------------------------------------------
@@ -2677,157 +2439,86 @@
 
 //----- (0040BB49) --------------------------------------------------------
 int GetPlayerHandCardCount( int player_num )
-    {
+{
   int card_count; // eax@1
 
   card_count = 0;
   for(int i=0; i<10; ++i)
-      {
-      if (am_Players[player_num].cards_at_hand[i]!=-1)
-            ++card_count;
-      }
+  {
+    if (am_Players[player_num].cards_at_hand[i]!=-1)
+      ++card_count;
+  }
   return card_count;
-  
 }
 
 //----- (0040BB67) --------------------------------------------------------
 signed int DrawCardsRectangles( int player_num )
 {
-//int v1; // esi@1
-signed int result; // eax@1
-int v3; // ebx@1
-char v4; // zf@1
-int v5; // eax@3
-int v6; // eax@4
-int v7; // ecx@6
-char *v8; // eax@6
-int v9; // eax@10
-int v10; // ecx@10
-int v11; // eax@10
-char v12; // ch@2@11
-int v13; // ST00_4@12
-unsigned __int16 v14; // ax@12
-int v15; // eax@13
-int v16; // ecx@13
-int v17; // eax@13
-char v18; // al@16
-char v19; // ch@2@16
-int v20; // ST00_4@19
-unsigned __int16 v21; // ax@19
-RECT pXYZW; // [sp+Ch] [bp-3Ch]@3
-stru273 v26; // [sp+1Ch] [bp-2Ch]@2
-int v25; // [sp+2Ch] [bp-1Ch]@3
-__int32 var18; // [sp+30h] [bp-18h]@3
-int i; // [sp+34h] [bp-14h]@4
-int v28; // [sp+38h] [bp-10h]@1
-int hand_index; // [sp+3Ch] [bp-Ch]@3
-int v30; // [sp+40h] [bp-8h]@1
-char v31; // [sp+44h] [bp-4h]@12
-char v32; // [sp+45h] [bp-3h]@12
-char v33; // [sp+46h] [bp-2h]@12
-
-__debugbreak(); // need do fix rectangle not fit to card
-
-v30 = 0;
-result = -1;
-//v3 = 188 * a1;
-
-//v4 = LOBYTE(am_Players[a1].field_20) == 0;
-v28 = -1;
-if ( am_Players[player_num].IsHisTurn )
+  int v5; // eax@3
+  int i; // ecx@6
+  int color; // ST00_4@19
+  RECT pXYZW; // [sp+Ch] [bp-3Ch]@3
+  stru273 v26; // [sp+1Ch] [bp-2Ch]@2
+  __int32 var18; // [sp+30h] [bp-18h]@3
+  int hand_index; // [sp+3Ch] [bp-Ch]@3
+
+//__debugbreak(); // need do fix rectangle not fit to card
+
+  if ( am_Players[player_num].IsHisTurn )
+  {
+    if ( v26._40DD2F() )
     {
-    if ( v26._40DD2F() )
+      v5 = GetPlayerHandCardCount(player_num);
+      pXYZW.top = 327;
+      pXYZW.bottom = 455;
+      pXYZW.left = (window->GetWidth() - 96 * v5) / (v5 + 1);
+      var18 = pXYZW.left + 96;
+      pXYZW.right = pXYZW.left + 96;
+      for( hand_index = 0; hand_index < v5; hand_index++)
+      {
+        //for ( i = 0; i < 10; ++i )
+        //{
+        if (am_Players[player_num].cards_at_hand[hand_index] != -1 )
         {
-        v5 = GetPlayerHandCardCount(player_num);
-        hand_index = 0;
-        v25 = v5;
-        pXYZW.top = 327;
-        pXYZW.bottom = 455;
-        pXYZW.left = (640 - 96 * v5) / (v5 + 1);
-        var18 = pXYZW.left + 96;
-        pXYZW.right = pXYZW.left + 96;
-        if ( v5 > 0 )
-            {
-           // v6 = 47 * v1;
-           // for ( i = player_num; ; v6 = i )
-            for(;;)
-                {
-                v7 = v30;
-              //  v8 = &am_Players[0].cards_at_hand[v30 + v6];
-
-                for (v7=0; v7<10; ++v7)
-                    {
-                    if (am_Players[player_num].cards_at_hand[v7]!= -1 )
-                        break;
-                    }
-                //if ( *v8 )
-                //    {
-                //    do
-                //        {
-                //        //v8 += 4;
-                //        ++v7;
-                //        }
-                //        while ( *v8 == -1 );
-                        v30 = v7;
-                  //  }
-                if ( am_byte_4E185D )
-                    {
-                 //   v9 = v3 + 8 * v7;
-                    v10 = am_Players[player_num].card_shift[v7].x;//*(am_player[0].arr_6C[0] + v9);
-                    v11 = am_Players[player_num].card_shift[v7].y;//*(&am_player[0].arr_6C[0][1] + v9);
-                    pXYZW.left += v10;
-                    pXYZW.right += v10;
-                    pXYZW.top += v11;
-                    pXYZW.bottom += v11;
-                    }
-                if (v26.Inside(&pXYZW) )
-                    break;
-           
-                v13=0;
-                v14 = R8G8B8_to_TargetFormat(v13);
-                DrawRect(&pXYZW, v14, 0);
-                pXYZW.left += var18;
-                pXYZW.right += var18;
-                if ( am_byte_4E185D )
-                    {
-                    v16 = am_Players[player_num].card_shift[v30].x;//*(am_player[0].arr_6C[0] + v15);
-                    v17 = am_Players[player_num].card_shift[v30].y;//*(&am_player[0].arr_6C[0][1] + v15);
-                    pXYZW.left -= v16;
-                    pXYZW.right -= v16;
-                    pXYZW.top -= v17;
-                    pXYZW.bottom -= v17;
-                    }
-                ++v30;
-                ++hand_index;
-                if ( hand_index >= v25 )
-                    return v28;
-                }
-            v28 = hand_index;
-            v18 = CanCardBePlayed(player_num, hand_index);
-            if ( v18 )
-                {
-                 v20=0x00FFFFFF;
-                }
+            //break;
+        //}
+          if ( am_byte_4E185D )
+          {
+            pXYZW.left += am_Players[player_num].card_shift[hand_index].x;
+            pXYZW.right += am_Players[player_num].card_shift[hand_index].x;
+            pXYZW.top += am_Players[player_num].card_shift[hand_index].y;
+            pXYZW.bottom += am_Players[player_num].card_shift[hand_index].y;
+          }
+          if ( v26.Inside(&pXYZW) )
+          {
+            if ( CanCardBePlayed(player_num, hand_index) )
+              color = 0x00FFFFFF;//белый цвет
             else
-                {
-                v20=0x000000FF;
-                }
-           
-            v21 = R8G8B8_to_TargetFormat(v20);
-            DrawRect(&pXYZW, v21, 0);
-            }
+              color = 0x000000FF;//красный цвет
+            DrawRect(&pXYZW, R8G8B8_to_TargetFormat(color), 0);
+            return hand_index;
+          }
+          DrawRect(&pXYZW, R8G8B8_to_TargetFormat(0), 0);//рамка чёрного цвета
+          if ( am_byte_4E185D )
+          {
+            pXYZW.left -= am_Players[player_num].card_shift[hand_index].x;
+            pXYZW.right -= am_Players[player_num].card_shift[hand_index].x;
+            pXYZW.top -= am_Players[player_num].card_shift[hand_index].y;
+            pXYZW.bottom -= am_Players[player_num].card_shift[hand_index].y;
+          }
+          pXYZW.left += var18;
+          pXYZW.right += var18;
         }
-    result = v28;
+      }
     }
-return result;
-
-
+  }
+  return -1;
 }
 // 4E185D: using guessed type char am_byte_4E185D;
 
 //----- (0040BCFB) --------------------------------------------------------
 bool DiscardCard( int player_num, signed int card_slot_index )
-    {
+{
   int v2; // esi@2
   signed int v3; // edi@2
   char *v4; // eax@2
@@ -2848,7 +2539,7 @@
     return false;
   v2 = 0;
 
-  for(i=0; i<10; ++i)
+  for( i = 0; i < 10; ++i )
   {
     if ( am_Players[player_num].cards_at_hand[i] != -1 )
     {
@@ -2862,18 +2553,18 @@
   {
     ArcomageGame::PlaySound(22);
     v8 = GetPlayerHandCardCount(current_player_num);
-    v10=am_Players[player_num].card_shift[i].x + (640 - 96 * v8) / (v8 + 1);
+    v10 = am_Players[player_num].card_shift[i].x + (window->GetWidth() - 96 * v8) / (v8 + 1);
     amuint_4FAA5C_blt_xy.x = v10;
     amuint_4FAA5C_blt_xy.y = am_Players[player_num].card_shift[i].y + 327;//v11;
     v12 = 0;
 
     if ( !am_byte_4FAA75 )
     {
-      for (v12=0; v12<10; ++v12)
-          {
-           if (shown_cards[v12].uCardId== -1)
-               break;
-          }
+      for ( v12 = 0; v12 < 10; ++v12 )
+      {
+        if (shown_cards[v12].uCardId == -1)
+          break;
+      }
     }
     pArcomageGame->field_F6 = 1;
     amuint_4FAA54_blt_xy.x = (shown_cards[v12].field_8.x - v10) / 10;
@@ -2887,7 +2578,6 @@
     return false;
 }
 
-
 //----- (0040BE0E) --------------------------------------------------------
 bool PlayCard( int player_num, int card_slot_num )
 {
@@ -2926,7 +2616,7 @@
     cards_at_hand = GetPlayerHandCardCount(current_player_num);
     pArcomageGame->field_F6 = 1;
     v12 =  am_Players[player_num].card_shift[card_index].x + 
-         (640 - 96 * cards_at_hand) / (cards_at_hand + 1)+ 
+         (window->GetWidth() - 96 * cards_at_hand) / (cards_at_hand + 1)+ 
          96 * card_index ;
         
   //  v13 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v10) + 327;
@@ -2974,9 +2664,6 @@
   return result;
 }
 
-
-
-
 //----- (0040BF77) --------------------------------------------------------
 void ApplyCardToPlayer( int player_num, unsigned int uCardID )
     {
@@ -3093,109 +2780,81 @@
         enemy_num = (player_num + 1) % 2;
         enemy = &am_Players[enemy_num];
         switch ( pCard->compare_param )
-            {
+        {
         case 2:
-            v5 = player->quarry_level;
-            v7 = __OFSUB__(v5, enemy->quarry_level);
-            v6 = v5 - enemy->quarry_level < 0;
-            v18 = v6 ^ v7;
-            goto LABEL_25;
+            if ( player->quarry_level < enemy->quarry_level )//если рудники < рудника врага
+                goto LABEL_26;
+            goto LABEL_231;
         case 3:
-            v8 = player->magic_level;
-            v7 = __OFSUB__(v8, enemy->magic_level);
-            v6 = v8 - enemy->magic_level < 0;
-            v18 = v6 ^ v7;
-            goto LABEL_25;
+            if ( player->magic_level < enemy->magic_level )
+                goto LABEL_26;
+            goto LABEL_231;
         case 4:
-            v9 = player->zoo_level;
-            v7 = __OFSUB__(v9, enemy->zoo_level);
-            v6 = v9 - enemy->zoo_level < 0;
-            v18 = v6 ^ v7;
-            goto LABEL_25;
+            if ( player->zoo_level < enemy->zoo_level )//если зверинец < зверинца врага
+                goto LABEL_26;
+            goto LABEL_231;
         case 5:
-            v10 = player->quarry_level == enemy->quarry_level;
-            v18 = v10;
-            goto LABEL_25;
+            if ( player->quarry_level == enemy->quarry_level )
+                goto LABEL_26;
+            goto LABEL_231;
         case 6:
-            v10 = player->magic_level == enemy->magic_level;
-            v18 = v10;
-            goto LABEL_25;
+            if ( player->magic_level == enemy->magic_level )
+                goto LABEL_26;
+            goto LABEL_231;
         case 7:
-            v10 = player->zoo_level == enemy->zoo_level;
-            v18 = v10;
-            goto LABEL_25;
+            if ( player->zoo_level == enemy->zoo_level )
+                goto LABEL_26;
+            goto LABEL_231;
         case 8:
-            v11 = player->quarry_level;
-            v14 = __OFSUB__(v11, enemy->quarry_level);
-            v12 = v11 == enemy->quarry_level;
-            v13 = v11 - enemy->quarry_level < 0;
-            v18 = !((v13 ^ v14) | v12);
-            goto LABEL_25;
+            if ( player->quarry_level < enemy->quarry_level )
+                goto LABEL_26;
+            goto LABEL_231;
         case 9:
-            v15 = player->magic_level;
-            v14 = __OFSUB__(v15, enemy->magic_level);
-            v12 = v15 == enemy->magic_level;
-            v13 = v15 - enemy->magic_level < 0;
-            v18 = !((v13 ^ v14) | v12);
-            goto LABEL_25;
+            if ( player->magic_level < enemy->magic_level )
+                goto LABEL_26;
+            goto LABEL_231;
         case 10:
-            v16 = player->zoo_level;
-            v14 = __OFSUB__(v16, enemy->zoo_level);
-            v12 = v16 == enemy->zoo_level;
-            v13 = v16 - enemy->zoo_level < 0;
-            v18 = !((v13 ^ v14) | v12);
-            goto LABEL_25;
+            if ( player->zoo_level < enemy->zoo_level )
+                goto LABEL_26;
+            goto LABEL_231;
         case 11:
-            v10 = player->wall_height == 0;
-            v18 = v10;
-            goto LABEL_25;
+            if ( !player->wall_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 12:
-            v17 = player->wall_height == 0;
-            v18 = !v17;
-            goto LABEL_25;
+            if ( player->wall_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 13:
-            v10 = enemy->wall_height == 0;
-            v18 = v10;
-            goto LABEL_25;
+            if ( !enemy->wall_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 14:
-            v17 = enemy->wall_height == 0;
-            v18 = !v17;
-            goto LABEL_25;
+            if ( enemy->wall_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 15:
-            v19 = player->wall_height;
-            v7 = __OFSUB__(v19, enemy->wall_height);
-            v6 = v19 - enemy->wall_height < 0;
-            v18 = v6 ^ v7;
-            goto LABEL_25;
+            if ( player->wall_height < enemy->wall_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 16:
-            v20 = player->tower_height;
-            v7 = __OFSUB__(v20, enemy->tower_height);
-            v6 = v20 - enemy->tower_height < 0;
-            v18 = v6 ^ v7;
-            goto LABEL_25;
+            if ( player->tower_height < enemy->tower_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 17:
-            v10 = player->wall_height == enemy->wall_height;
-            v18 = v10;
-            goto LABEL_25;
+            if ( player->wall_height == enemy->wall_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 18:
-            v10 = player->tower_height == enemy->tower_height;
-            v18 = v10;
-            goto LABEL_25;
+            if ( player->tower_height == enemy->tower_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 19:
-            v21 = player->wall_height;
-            v14 = __OFSUB__(v21, enemy->wall_height);
-            v12 = v21 == enemy->wall_height;
-            v13 = v21 - enemy->wall_height < 0;
-            v18 = !((v13 ^ v14) | v12);
-            goto LABEL_25;
+            if ( player->wall_height < enemy->wall_height )
+                goto LABEL_26;
+            goto LABEL_231;
         case 20:
-            v22 = player->tower_height;
-            v14 = __OFSUB__(v22, enemy->tower_height);
-            v12 = v22 == enemy->tower_height;
-            v13 = v22 - enemy->tower_height < 0;
-            v18 = !((v13 ^ v14) | v12);
-LABEL_25:
-            if ( v18 )
+            if ( player->tower_height < enemy->tower_height )
                 goto LABEL_26;
             goto LABEL_231;
         default:
@@ -3205,18 +2864,17 @@
             dword_4FAA68 = v23 + (pCard->field_30 == 1);
             dword_4FAA64 = v23;
             if ( v23 > 0 )
-                {
-                do
-                    {
-                    GetNextCardFromDeck(player_num);
-                    ++v24;
-                    }
-                    while ( v24 < pCard->draw_extra_card_count );
-                }
+            {
+              do
+              {
+                GetNextCardFromDeck(player_num);
+                ++v24;
+              }
+              while ( v24 < pCard->draw_extra_card_count );
+            }
 
             need_to_discard_card = GetPlayerHandCardCount(player_num) > minimum_cards_at_hand;
 
-
             APPLY_TO_PLAYER(player, enemy, quarry_level,    pCard->to_player_quarry_lvl, quarry_p);
             APPLY_TO_PLAYER(player, enemy, magic_level,     pCard->to_player_magic_lvl,  magic_p);
             APPLY_TO_PLAYER(player, enemy, zoo_level,       pCard->to_player_zoo_lvl,    zoo_p);
@@ -3607,51 +3265,45 @@
                 }
             }
 #undef APPLY_TO_BOTH
-#undef APPLY_TO_ENEMY        
+#undef APPLY_TO_ENEMY
 #undef APPLY_TO_PLAYER
 
 }
 
-
-
-
 //----- (0040D2B4) --------------------------------------------------------
 int am_40D2B4( POINT* startXY, int effect_value )
-    {
+{
   int v2; // ebp@1
   POINT *v3; // edi@1
   int result; // eax@3
   int v6;
   stru272_stru0 *v8; // ecx@12
   signed int v11; // [sp+10h] [bp-8h]@1
- 
 
   v11 = 0;
   v2 = effect_value;
 
-  while ( array_4FABD0[v11].have_effect )
-      {
-      result = array_4FABD0[v11].field_40->_40E2A7();
-      if ( !result )
-          {
-          array_4FABD0[v11].have_effect = 0;
-          --v11;
-          }
-      ++v11;
-      if ( v11 >= 10 )
-          return result;
-      }
+  while ( array_4FABD0[v11].have_effect )//Ritor1: needed refactoring
+  {
+    result = array_4FABD0[v11].field_40->_40E2A7();
+    if ( !result )
+    {
+      array_4FABD0[v11].have_effect = 0;
+      --v11;
+    }
+    ++v11;
+    if ( v11 >= 10 )
+      return result;
+  }
   v6 = v11;
   array_4FABD0[v11].have_effect = 1;
   if ( effect_value <= 0 )
-      {
-      array_4FABD0[v6].effect_sign = 0;
-      effect_value = -effect_value;
-      }
+  {
+    array_4FABD0[v6].effect_sign = 0;
+    effect_value = -effect_value;
+  }
   else
-      {
-      array_4FABD0[v6].effect_sign = 1;
-      }
+    array_4FABD0[v6].effect_sign = 1;
   array_4FABD0[v6].field_4.effect_area.left = startXY->x - 20;
   array_4FABD0[v6].field_4.effect_area.right = startXY->x + 20;
   array_4FABD0[v6].field_4.effect_area.top = startXY->y - 20;
@@ -3683,42 +3335,36 @@
   v8->field_4C = 0;
   v8->field_48 = 0;
   v8->field_50 = 0;
-  for (int i=0; i<v8->field_4; ++i)
-      v8->field_54[i].have_spark=0;
+  for (int i = 0; i < v8->field_4; ++i)
+    v8->field_54[i].have_spark = 0;
   return 0;
 }
 
-
 //----- (0040D402) --------------------------------------------------------
 int ApplyDamageToBuildings( int player_num, int damage )
-    {
+{
   ArcomagePlayer *v2; // ecx@1
   int v3; // esi@1
   int result; // eax@3
 
-
   v3 = am_Players[player_num].wall_height;
-  if ( v3 <= 0 )
-  {
+  //if ( v3 <= 0 )
     result = 0;
-  }
-  else
-  {
+  //else
+  //{
     if ( v3 >= -damage )
     {
       result = damage;
       am_Players[player_num].wall_height += damage;
-
     }
     else
-        {      
-    damage += v3;
-    result = -v3;
-    am_Players[player_num].wall_height = 0;
-    am_Players[player_num].tower_height += damage;
-        }
-  }
-
+    {
+      damage += v3;
+      result = -v3;
+      am_Players[player_num].wall_height = 0;
+      am_Players[player_num].tower_height += damage;
+    }
+  //}
   if ( am_Players[player_num].tower_height < 0 )
     am_Players[player_num].tower_height = 0;
   return result;
@@ -3727,228 +3373,190 @@
 
 //----- (0040D444) --------------------------------------------------------
 void GameResultsApply()
-    {
-  int v0; // esi@1
-  int v1; // edi@1
-  int v2; // eax@1
-  int v3; // eax@23
-  int v4; // edx@25
-  int v5; // ecx@28
-  int v6; // eax@28
-  GUIWindow *v7; // ecx@50
-  signed int v8; // eax@50
-  char v9; // eax@52
-  signed int v10; // eax@54
-  char *v11; // esi@59
-  char *v12; // esi@65
-  signed int v14; // [sp-4h] [bp-58h]@46
+{
+  int winner; // esi@1
+  int victory_type; // edi@1
+  int pl_resource; // edx@25
+  int en_resource; // eax@28
+  unsigned int tavern_num; // eax@54
   char pText[64]; // [sp+Ch] [bp-48h]@1
   POINT xy; // [sp+4Ch] [bp-8h]@1
 
-  v0 = -1;
-  v1 = -1;
+  winner = -1;
+  victory_type = -1;
   //nullsub_1();
-  xy.x = 0;
-  xy.y = 0;
-  strcpy(pText, "The Winner is: ");//"Победи"
- // v2 = 0;
+  /*strcpy(pText, "The Winner is: ");//"Победил: " Ritor1: архаизм
   xy.y = 160;
   xy.x = 320; //- 12 * v2 / 2;
-//  am_DrawText(-1, pText, xy);
-  if ( am_Players[0].tower_height < max_tower_height )
+  am_DrawText(-1, pText, &xy);*/
+
+  //проверка построена ли башня
+  if ( am_Players[0].tower_height < max_tower_height && am_Players[1].tower_height >= max_tower_height )//наша башня не построена, а у врага построена
   {
-    if ( am_Players[1].tower_height < max_tower_height )
-      goto LABEL_10;
-    v0 = 2;
+    winner = 2;//победил игрок 2(враг)
+    victory_type = 0;
   }
-  else
+  else if ( am_Players[0].tower_height >= max_tower_height && am_Players[1].tower_height < max_tower_height )//наша башня построена, а у врага нет
   {
-    if ( am_Players[1].tower_height < max_tower_height )
+    winner = 1;//победил игрок 1(мы)
+    victory_type = 0;
+  }
+  else if ( am_Players[0].tower_height >= max_tower_height && am_Players[1].tower_height >= max_tower_height )//и у нас, и у врага построена
+  {
+    if ( am_Players[0].tower_height == am_Players[1].tower_height )//наши башни равны
     {
-      v0 = 1;
+      winner = 0;//никто не победил
+      victory_type = 4;//ничья
     }
-    else
+    else//наши башни не равны
     {
-      if ( am_Players[0].tower_height == am_Players[1].tower_height )
-      {
-        v0 = 0;
-        v1 = 4;
-        goto LABEL_10;
-      }
-      v0 = (am_Players[0].tower_height <= am_Players[1].tower_height) + 1;
+      winner = (am_Players[0].tower_height <= am_Players[1].tower_height) + 1;//победил тот, у кого выше
+      victory_type = 0;
     }
   }
-  v1 = 0;
-LABEL_10:
-  if ( am_Players[0].tower_height <= 0 )
+
+  //проверка разрушена ли башня
+  if ( am_Players[0].tower_height <= 0 && am_Players[1].tower_height > 0 )//наша башня разрушена, а у врага нет
   {
-    if ( am_Players[1].tower_height > 0 )
+    winner = 2;// победил игрок 2(враг)
+    victory_type = 2;//победил разрушив башню врага
+  }
+  else if ( am_Players[0].tower_height > 0 && am_Players[1].tower_height <= 0 )//у врага башня разрушена, а у нас нет
+  {
+    winner = 1;//победил игрок 1(мы)
+    victory_type = 2;//победил разрушив башню врага
+  }
+  else if ( am_Players[0].tower_height <= 0 && am_Players[1].tower_height <= 0  )//наша башня разрушена, и у врага разрушена
+  {
+    if ( am_Players[0].tower_height == am_Players[1].tower_height )//если башни равны
     {
-      v0 = 2;
-    }
-    else
-    {
-      if ( am_Players[0].tower_height == am_Players[1].tower_height )
+      if ( am_Players[0].wall_height == am_Players[1].wall_height )//если стены равны
       {
-LABEL_20:
-        if ( am_Players[0].wall_height == am_Players[1].wall_height )
-        {
-          v0 = 0;
-          v1 = 4;
-        }
-        else
-        {
-          v0 = (am_Players[0].wall_height <= am_Players[1].wall_height) + 1;
-          v1 = 1;
-        }
-        goto LABEL_23;
+        winner = 0;
+        victory_type = 4;
       }
-      v0 = (am_Players[0].tower_height <= am_Players[1].tower_height) + 1;
+      else//если стены не равны
+      {
+        winner = (am_Players[0].wall_height <= am_Players[1].wall_height) + 1;//победил тот, у кого стена выше
+        victory_type = 1;//победа когда больше стена при ничье
+      }
     }
-    goto LABEL_17;
-  }
-  if ( am_Players[1].tower_height <= 0 )
-  {
-    v0 = 1;
-LABEL_17:
-    v1 = 2;
-  }
-  if ( !v0 && v1 == 4 )
-    goto LABEL_20;
-LABEL_23:
-  v3 = am_Players[0].resource_bricks;
-  if ( am_Players[0].resource_bricks <= am_Players[0].resource_gems )
-  {
-    v3 = am_Players[0].resource_beasts;
-    v4 = am_Players[0].resource_gems;
-    if ( am_Players[0].resource_gems > am_Players[0].resource_beasts )
-      goto LABEL_28;
-  }
-  else
-  {
-    if ( am_Players[0].resource_bricks <= am_Players[0].resource_beasts )
+    else//башни не равны
     {
-      v4 = am_Players[0].resource_beasts;
-      goto LABEL_28;
+      winner = (am_Players[0].tower_height <= am_Players[1].tower_height) + 1;// побеждает тот у кого башня больше
+      victory_type = 2;//победил разрушив башню врага
     }
   }
-  v4 = v3;
-LABEL_28:
-  v5 = am_Players[1].resource_bricks;
-  v6 = am_Players[1].resource_gems;
-  if ( am_Players[1].resource_bricks <= am_Players[1].resource_gems )
+
+  //проверка набраны ли ресурсы
+  //проверка какого ресурса больше всего у игрока 1(нас)
+  pl_resource = am_Players[0].resource_bricks;//кирпичей больше чем др. ресурсов
+  if ( am_Players[0].resource_gems > am_Players[0].resource_bricks
+    && am_Players[0].resource_gems > am_Players[0].resource_beasts )//драг.камней больше всего
+    pl_resource = am_Players[0].resource_gems;
+  else if ( am_Players[0].resource_beasts > am_Players[0].resource_gems
+          && am_Players[0].resource_beasts > am_Players[0].resource_bricks )//зверей больше всего
+    pl_resource = am_Players[0].resource_beasts;
+
+  //проверка какого ресурса больше у игрока 2(врага)
+  en_resource = am_Players[1].resource_bricks;//кирпичей больше чем др. ресурсов
+  if ( am_Players[1].resource_gems > am_Players[1].resource_bricks
+    && am_Players[1].resource_gems > am_Players[1].resource_beasts )//драг.камней больше всего
+    en_resource = am_Players[1].resource_gems;
+  else if ( am_Players[1].resource_beasts > am_Players[1].resource_gems
+          && am_Players[1].resource_beasts > am_Players[1].resource_bricks )//зверей больше всего
+    en_resource = am_Players[1].resource_beasts;
+
+  //сравнение ресурсов игроков
+  if ( winner == -1 && victory_type == -1 )//нет победителя по башням
   {
-    v5 = am_Players[1].resource_beasts;
-    if ( am_Players[1].resource_gems > am_Players[1].resource_beasts )
-      goto LABEL_33;
-    goto LABEL_32;
-  }
-  v6 = am_Players[1].resource_beasts;
-  if ( am_Players[1].resource_bricks > am_Players[1].resource_beasts )
-LABEL_32:
-    v6 = v5;
-LABEL_33:
-  if ( v0 == -1 )
-  {
-    if ( v1 != -1 )
-      goto LABEL_49;
-    if ( v4 < max_resources_amount )
+    if ( pl_resource < max_resources_amount && en_resource >= max_resources_amount )//враг набрал нужное количество
+    {
+      winner = 2;// враг победил
+      victory_type = 3;//победа собрав нужное количество ресурсов
+    }
+    else if ( pl_resource >= max_resources_amount && en_resource < max_resources_amount )//мы набрали нужное количество
     {
-      if ( v6 < max_resources_amount )
-        goto LABEL_49;
-      v0 = 2;
+      winner = 1;// мы победили
+      victory_type = 3;//победа собрав нужное количество ресурсов
     }
-    else
+    else if ( pl_resource >= max_resources_amount && en_resource >= max_resources_amount )//и у нас и у врага нужное количество ресурсов
     {
-      if ( v6 < max_resources_amount )
+      if ( pl_resource == en_resource )// ресурсы равны
       {
-        v0 = 1;
+        winner = 0;//ресурсы равны
+        victory_type = 4; //ничья
       }
       else
       {
-        if ( v4 == v6 )
-          goto LABEL_46;
-        v0 = (v4 <= v6) + 1;
+        winner = (pl_resource <= en_resource) + 1;//ресурсы не равны, побеждает тот у кого больше
+        victory_type = 3;//победа собрав нужное количество ресурсов
       }
     }
-    v1 = 3;
   }
-  if ( !v0 && v1 == 4 )
+  else if ( winner == 0 && victory_type == 4 )// при ничье по башням и стене
   {
-    if ( v4 != v6 )
+    if ( pl_resource != en_resource )//ресурсы не равны
     {
-      v14 = 5;
-      v0 = (v4 <= v6) + 1;
-      goto LABEL_48;
+      winner = (pl_resource <= en_resource) + 1;//победил тот у кого больше
+      victory_type = 5;//победа когда при ничье большее количество ресурсов
     }
-LABEL_46:
-    v0 = 0;
-    v14 = 4;
-LABEL_48:
-    v1 = v14;
+    else //ресурсы равны
+    {
+      winner = 0;//нет победителя
+      victory_type = 4; //ничья
+    }
   }
-LABEL_49:
-  pArcomageGame->field_B0 = v1;
-  pArcomageGame->uGameResult = v0;
-  if ( v0 == 1 )
+
+  //подведение итогов
+  pArcomageGame->Victory_type = victory_type;
+  pArcomageGame->uGameWinner = winner;
+  if ( winner == 1 )//победитель игрок 1(мы)
   {
-
-    v8 = (signed int)window_SpeakInHouse->par1C;
-    if (( v8 >= 108 )&&( v8 <= 120 ))
+    if (( window_SpeakInHouse->par1C >= 108 ) && ( window_SpeakInHouse->par1C <= 120 ))//таверны
     {
-        if ( !pParty->pArcomageWins[v8-108] )
-        {
-          pParty->pArcomageWins[v8-108] = 1;
-          signed int _a = (signed int)(p2DEvents[ window_SpeakInHouse->par1C - 1].fPriceMultiplier * 100.0);
-          pParty->PartyFindsGold(_a, 0);
-        }
-      
-    }
-    v10 = 108;
-    do
-    {
-      if ( !pParty->pArcomageWins[v10-108] )
-        break;
-      ++v10;
+      if ( !pParty->pArcomageWins[window_SpeakInHouse->par1C - 108] )
+      {
+        pParty->pArcomageWins[window_SpeakInHouse->par1C - 108] = 1;
+        pParty->PartyFindsGold(p2DEvents[ window_SpeakInHouse->par1C - 1].fPriceMultiplier * 100.0, 0);//вознаграждение
+      }
     }
-    while ( v10 <= 120 );
-
-    if ( v10 == 121 )
-      _449B7E_toggle_bit(pParty->_quest_bits, 238, 1u);
-
-   
-    for (int i=0; i<4; ++i  )
+    //проверка выполнен ли квест по аркомагу
+    tavern_num = 0;
+    for ( uint i = 108; i <= 120; ++i )
     {
-      v11 = (char *)&pParty->pPlayers[i]._achieved_awards_bits;
-      if ( !(unsigned __int16)_449B57_test_bit((unsigned __int8 *)v11, 1) )
-        _449B7E_toggle_bit((unsigned char *)v11, PLAYER_GUILD_BITS__ARCOMAGE_WIN, 1);
-      
+      if ( !pParty->pArcomageWins[i - 108] )
+        break;
+      tavern_num++;
     }
-   
+    if ( tavern_num == 13 )
+      _449B7E_toggle_bit(pParty->_quest_bits, 238, 1);// 238 - Won all Arcomage games
+
+    for ( int i = 0; i < 4; ++i )//внесение записи в Заслуги
+    {
+      if ( !_449B57_test_bit(pParty->pPlayers[i]._achieved_awards_bits, 1) )
+        _449B7E_toggle_bit(pParty->pPlayers[i]._achieved_awards_bits, PLAYER_GUILD_BITS__ARCOMAGE_WIN, 1);
+    }
     ++pParty->uNumArcomageWins;
-    if ( pParty->uNumArcomageWins > 1000000 )
+    if ( pParty->uNumArcomageWins > 1000000 )//ограничение количества побед
       pParty->uNumArcomageWins = 1000000;
   }
-  else
+  else//проигрыш
   {
-  for (int i=0; i<4; ++i  )
-      {
-      v12 = (char *)&pParty->pPlayers[i]._achieved_awards_bits;
-      if ( !(unsigned __int16)_449B57_test_bit((unsigned __int8 *)v12, 1) )
-        _449B7E_toggle_bit((unsigned char *)v12, PLAYER_GUILD_BITS__ARCOMAGE_LOSE, 1);
+    for ( int i = 0; i < 4; ++i )//внесение записи в Заслуги
+    {
+      if ( !_449B57_test_bit(pParty->pPlayers[i]._achieved_awards_bits, 1) )
+        _449B7E_toggle_bit(pParty->pPlayers[i]._achieved_awards_bits, PLAYER_GUILD_BITS__ARCOMAGE_LOSE, 1);
     }
-   
     ++pParty->uNumArcomageLoses;
-    if ( pParty->uNumArcomageLoses > 1000000 )
+    if ( pParty->uNumArcomageLoses > 1000000 )//ограничение количества проигрышей
       pParty->uNumArcomageLoses = 1000000;
   }
 }
 
-
-
 //----- (00409C8B) --------------------------------------------------------
 void PrepareArcomage()
-    {
+{
   signed __int64 v1; // qax@4
   int v2; // esi@4
   int v3; // esi@5
@@ -3963,27 +3571,27 @@
   am_byte_4FAA76 = 0;
   am_byte_4FAA75 = 0;
 
-  for (int i=0; i<10; ++i)
-      {
-      v2 = (i+1) % 4;
-      v3 = (i+1) / 4;
-      shown_cards[i].uCardId = -1;
-      shown_cards[i].field_4 = 0;
-      shown_cards[i].field_8.x = 100 * v2 + 120;
-      shown_cards[i].field_8.y = 138 * v3 + 18;
-      shown_cards[i].field_10_xplus = -100 * v2 / 5;
-      shown_cards[i].field_14_y_plus = -138 * v3 / 5;
-      shown_cards[i].field_18_point.x = shown_cards[i].field_8.x;
-      shown_cards[i].field_18_point.y = shown_cards[i].field_8.y;
-      }
+  for (int i = 0; i < 10; ++i)
+  {
+    v2 = (i+1) % 4;
+    v3 = (i+1) / 4;
+    shown_cards[i].uCardId = -1;
+    shown_cards[i].field_4 = 0;
+    shown_cards[i].field_8.x = 100 * v2 + 120;
+    shown_cards[i].field_8.y = 138 * v3 + 18;
+    shown_cards[i].field_10_xplus = -100 * v2 / 5;
+    shown_cards[i].field_14_y_plus = -138 * v3 / 5;
+    shown_cards[i].field_18_point.x = shown_cards[i].field_8.x;
+    shown_cards[i].field_18_point.y = shown_cards[i].field_8.y;
+  }
 
   pXY.x = 0;
   pXY.y = 0;
   ArcomageGame::LoadBackground();
   pXYZW.left = 0;
-  pXYZW.right = 640;
+  pXYZW.right = window->GetWidth();
   pXYZW.top = 0;
-  pXYZW.bottom = 480;
+  pXYZW.bottom = window->GetHeight();
   am_BeginScene(pArcomageGame->pBackgroundPixels, -1, 1);
   pRenderer->am_Blt_Copy(&pXYZW, &pXY, 2);
   am_EndScene();
@@ -3992,10 +3600,10 @@
   pRenderer->Present();
 
   v4 = 120;
-  for (int i=0; i<12; ++i)
+  for ( int i = 0; i < 12; ++i )
     am_sounds[i] = pSoundList->LoadSound(v4++, 0);
 
-  for (int i=0; i<10; ++i)
+  for (int i = 0; i < 10; ++i)
      array_4FABD0[i].field_40 = stru272_stru0::New();
   
   current_card_slot_index = -1;
@@ -4014,7 +3622,6 @@
   pArcomageGame->pfntArrus = pFontArrus;
 }
 
-
 //----- (0040D711) --------------------------------------------------------
 ArcomageGame::ArcomageGame()
 {
@@ -4025,12 +3632,11 @@
   field_F9 = 0;
 }
 
-
 //----- (00409BE8) --------------------------------------------------------
 void SetStartConditions()
 {
   const ArcomageStartConditions *st_cond; // eax@1
-    
+
   st_cond = &start_conditions[window_SpeakInHouse->par1C - 108];
   start_tower_height = st_cond->tower_height;
   start_wall_height  = st_cond->wall_height;
@@ -4049,92 +3655,83 @@
   start_bricks_amount = st_cond->bricks_amount;
   start_gems_amount   = st_cond->gems_amount;
   start_beasts_amount = st_cond->beasts_amount;
-  
 }
 
-
 //----- (0040D75D) --------------------------------------------------------
 void am_DrawText( int a1, const char *pText, POINT *pXY )
-    {
-    pPrimaryWindow->DrawText( pFontComic, pXY->x, pXY->y - ((pFontComic->uFontHeight - 3) >> 1) + 3, 0, pText, 0, 0, 0);
-    }
-
+{
+  pPrimaryWindow->DrawText( pFontComic, pXY->x, pXY->y - ((pFontComic->uFontHeight - 3) / 2) + 3, 0, pText, 0, 0, 0);
+}
 
 //----- (0040DB27) --------------------------------------------------------
 void DrawRect( RECT *pXYZW, unsigned __int16 uColor, char bSolidFill )
-    {
-    RECT *v3; // esi@1
-
-    v3 = pXYZW;
-    pRenderer->BeginScene();
-    pRenderer->SetRasterClipRect(0, 0, 639u, 479u);
-    if ( bSolidFill )
-        {
-        for ( int i = v3->top; i <= v3->bottom;  ++i )
-            pRenderer->RasterLine2D(v3->left, i, v3->right, i, uColor);
-        }
-    else
-        {
-        pRenderer->RasterLine2D(v3->left, v3->top, v3->right, v3->top, uColor);
-        pRenderer->RasterLine2D(v3->right, v3->top, v3->right, v3->bottom, uColor);
-        pRenderer->RasterLine2D(v3->right, v3->bottom, v3->left, v3->bottom, uColor);
-        pRenderer->RasterLine2D(v3->left, v3->bottom, v3->left, v3->top, uColor);
-        }
-    pRenderer->EndScene();
-    }
+{
+  pRenderer->BeginScene();
+  pRenderer->SetRasterClipRect(0, 0, window->GetWidth() - 1, window->GetHeight() - 1);
+  if ( bSolidFill )
+  {
+    for ( int i = pXYZW->top; i <= pXYZW->bottom;  ++i )
+      pRenderer->RasterLine2D(pXYZW->left, i, pXYZW->right, i, uColor);
+  }
+  else
+  {
+    pRenderer->RasterLine2D(pXYZW->left, pXYZW->top, pXYZW->right, pXYZW->top, uColor);
+    pRenderer->RasterLine2D(pXYZW->right, pXYZW->top, pXYZW->right, pXYZW->bottom, uColor);
+    pRenderer->RasterLine2D(pXYZW->right, pXYZW->bottom, pXYZW->left, pXYZW->bottom, uColor);
+    pRenderer->RasterLine2D(pXYZW->left, pXYZW->bottom, pXYZW->left, pXYZW->top, uColor);
+  }
+  pRenderer->EndScene();
+}
 
 void DrawSquare( POINT *pTargetXY, unsigned __int16 uColor )
 {
-    pRenderer->BeginScene();
-    //if ( uNumSceneBegins )
+  pRenderer->BeginScene();
+  //if ( uNumSceneBegins )
+  {
+    if ( pTargetXY->x >= 0 && pTargetXY->x <= window->GetWidth() - 1
+      && pTargetXY->y >= 0 && pTargetXY->y <= window->GetHeight() - 1)
     {
       pRenderer->WritePixel16(pTargetXY->x,     pTargetXY->y, uColor);
       pRenderer->WritePixel16(pTargetXY->x + 1, pTargetXY->y, uColor);
       pRenderer->WritePixel16(pTargetXY->x,     pTargetXY->y + 1, uColor);
       pRenderer->WritePixel16(pTargetXY->x + 1, pTargetXY->y + 1, uColor);
-        /*int xVal = pTargetXY->x;
-        int yVal = pTargetXY->y;
-        if ( xVal >= 0 && xVal <= 639 && yVal >= 0 && yVal <= 479)
-            {
-            pRenderer->pTargetSurface[xVal + pRenderer->uTargetSurfacePitch * yVal] = uColor;
-            pRenderer->pTargetSurface[xVal+1 + pRenderer->uTargetSurfacePitch * yVal] = uColor;
-            pRenderer->pTargetSurface[xVal + pRenderer->uTargetSurfacePitch * (yVal+1)] = uColor;
-            pRenderer->pTargetSurface[xVal+1 + pRenderer->uTargetSurfacePitch * (yVal+1)] = uColor;
-            }*/
-        pRenderer->EndScene();
-        }
+    }
+    pRenderer->EndScene();
+  }
 }
 
 //----- (0040DBD3) --------------------------------------------------------
 void DrawPixel( POINT *pTargetXY, unsigned __int16 uColor )
 {
-    pRenderer->BeginScene();
-    //if ( pRenderer->uNumSceneBegins )
-        {
-          pRenderer->WritePixel16(pTargetXY->x, pTargetXY->y, uColor);
-        /*int xVal = pTargetXY->x;
-        int yVal = pTargetXY->y;
-        if ( xVal >= 0 && xVal <= 639 && yVal >= 0 && yVal <= 479)
-            {
-            pRenderer->pTargetSurface[xVal + pRenderer->uTargetSurfacePitch * yVal] = uColor;
-            }*/
-        pRenderer->EndScene();
-        }
+  pRenderer->BeginScene();
+  //if ( pRenderer->uNumSceneBegins )
+  {
+    if ( pTargetXY->x >= 0 && pTargetXY->x <= window->GetWidth() - 1
+      && pTargetXY->y >= 0 && pTargetXY->y <= window->GetHeight() - 1)
+    {
+      pRenderer->WritePixel16(pTargetXY->x, pTargetXY->y, uColor);
+    /*int xVal = pTargetXY->x;
+    int yVal = pTargetXY->y;
+    if ( xVal >= 0 && xVal <= 639 && yVal >= 0 && yVal <= 479)
+    {
+      pRenderer->pTargetSurface[xVal + pRenderer->uTargetSurfacePitch * yVal] = uColor;
+    }*/
+    }
+    pRenderer->EndScene();
+  }
 }
 
-
 //----- (0040DDB1) --------------------------------------------------------
 int rand_interval( int min, int max )
-    {
-    return min + rand() % (max - min + 1);
-    }
-
+{
+  return min + rand() % (max - min + 1);
+}
 
 //----- (0040DEC8) --------------------------------------------------------
 void __fastcall am_IntToString(int val, char *pOut)
-    {
-    sprintfex(pOut, "%d", val);
-    }
+{
+  sprintfex(pOut, "%d", val);
+}
 
 void set_stru1_field_8_InArcomage(int inValue)
 {
--- a/Arcomage.h	Wed Feb 19 22:26:10 2014 +0100
+++ b/Arcomage.h	Wed Feb 19 22:30:39 2014 +0100
@@ -169,8 +169,8 @@
   RGBTexture pGameBackground;
   RGBTexture pSprites;
   int event_timer_time;
-  int uGameResult;
-  int field_B0;
+  int uGameWinner;
+  int Victory_type;
   char pPlayer1Name[32];
   char pPlayer2Name[32];
   char field_F4;
--- a/Build/Visual Studio 2010/World of Might and Magic.vcxproj	Wed Feb 19 22:26:10 2014 +0100
+++ b/Build/Visual Studio 2010/World of Might and Magic.vcxproj	Wed Feb 19 22:30:39 2014 +0100
@@ -402,6 +402,7 @@
     <ClInclude Include="..\..\MapInfo.h" />
     <ClInclude Include="..\..\MM7.h" />
     <ClInclude Include="..\..\mm7_data.h" />
+    <ClInclude Include="..\..\mm7_unsorted_subs.h" />
     <ClInclude Include="..\..\Monsters.h" />
     <ClInclude Include="..\..\Mouse.h" />
     <ClInclude Include="..\..\NewUI\Core\UIControl.h" />
--- a/Build/Visual Studio 2010/World of Might and Magic.vcxproj.filters	Wed Feb 19 22:26:10 2014 +0100
+++ b/Build/Visual Studio 2010/World of Might and Magic.vcxproj.filters	Wed Feb 19 22:30:39 2014 +0100
@@ -501,6 +501,7 @@
     <ClInclude Include="..\..\lib\OpenAL\xram.h">
       <Filter>lib\OpenAL</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\mm7_unsorted_subs.h" />
   </ItemGroup>
   <ItemGroup>
     <Filter Include="lib">
--- a/CastSpellInfo.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/CastSpellInfo.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -3543,7 +3543,7 @@
       {
         if ( pGUIWindow_Settings )
           return;
-        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_Settings = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
         pGUIWindow_Settings->CreateButton(52, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 0, 49, "", 0);
         pGUIWindow_Settings->CreateButton(165, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 1, 50, "", 0);
         pGUIWindow_Settings->CreateButton(280, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 2, 51, "", 0);
@@ -3556,7 +3556,7 @@
         if ( pGUIWindow_Settings )
           return;
 
-        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_Settings = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
         pGUIWindow_Settings->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Shoot_Monster, 0, 0, "", 0);
         pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
@@ -3566,7 +3566,7 @@
         if ( pGUIWindow_Settings )
           return;
 
-        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_Settings = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
         pGUIWindow_Settings->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Telekinesis, 0, 0, "", 0);
         pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
@@ -3588,7 +3588,7 @@
       {
         if ( pGUIWindow_Settings )
           return;
-        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_Settings = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
         pGUIWindow_Settings->CreateButton(0x34u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 0, 0x31u, "", 0);
         pGUIWindow_Settings->CreateButton(0xA5u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 1, 0x32u, "", 0);
         pGUIWindow_Settings->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 2, 0x33u, "", 0);
@@ -3598,7 +3598,7 @@
       }
       if ( HIBYTE(a5) & 2 && !pGUIWindow_Settings )
       {
-        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_Settings = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
         pBtn_NPCLeft = pGUIWindow_Settings->CreateButton(469, 178,
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCLeft)->uTextureWidth,
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCLeft)->uTextureHeight,
--- a/Chest.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Chest.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -183,7 +183,7 @@
       pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0);
   }
   OpenedTelekinesis = false;
-  pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Chest, uChestID, 0);
+  pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Chest, uChestID, 0);
   pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169,  35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit
                     pChestWindow->CreateButton(  7,   8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0);
   pCurrentScreen = SCREEN_CHEST;
--- a/DecalBuilder.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/DecalBuilder.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -614,7 +614,7 @@
 			if ( v14 <= v10->radius )
 			{
 				v15 = a2->flags;
-				if ( v15 & 2 || BYTE1(v15) & 1 )
+				if ( a2->flags & 2 || a2->flags & 0x100 )
 				{
 					v16 = v10->field_1C;
 					if ( !(v16 & 1) )
--- a/Events.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Events.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -710,7 +710,7 @@
                   if ( EnterHouse(HOUSE_DARK_GUILD_PIT) )
                   {
                     pAudioPlayer->StopChannels(-1, -1);
-                    window_SpeakInHouse = GUIWindow::Create(0, 0, 640, 480, WINDOW_HouseInterior, 170, 0);
+                    window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_HouseInterior, 170, 0);
                     window_SpeakInHouse->CreateButton( 61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1',  "", 0);
                     window_SpeakInHouse->CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2',  "", 0);
                     window_SpeakInHouse->CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3',  "", 0);
@@ -809,7 +809,7 @@
             if ( EnterHouse(HOUSE_BODY_GUILD_ERATHIA) )
               {
               pAudioPlayer->PlaySound((SoundID)0, 0, 0, -1, 0, 0, 0, 0);
-              window_SpeakInHouse = GUIWindow::Create(0, 0, 640, 480, WINDOW_HouseInterior, 165, 0);
+              window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_HouseInterior, 165, 0);
               v48 = window_SpeakInHouse->pControlsHead;
               if ( v48 )
                 {
@@ -1481,7 +1481,7 @@
           v104 = 187;
           if ( uCurrentHouse_Animation != 167 )
             v104 = EVT_DWORD(_evt->v5);
-          window_SpeakInHouse = GUIWindow::Create(0, 0, 640, 480, WINDOW_HouseInterior, v104, 0);
+          window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_HouseInterior, v104, 0);
           window_SpeakInHouse->CreateButton( 61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1,  '1', "", 0);
           window_SpeakInHouse->CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2,  '2', "", 0);
           window_SpeakInHouse->CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3,  '3', "", 0);
--- a/GUIButton.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/GUIButton.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -4,7 +4,7 @@
 #include "mm7_data.h"
 #include "LOD.h"
 #include "Texts.h"
-
+#include "OSWindow.h"
 
 
 
@@ -248,7 +248,7 @@
 void UI_CreateEndConversationButton()
 {
   pDialogueWindow->Release();
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 345, WINDOW_MainMenu, 0, 0);
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), 345, WINDOW_MainMenu, 0, 0);
   pBtn_ExitCancel = pDialogueWindow->CreateButton( 471, 445,  169, 35, 1, 0, UIMSG_Escape,  0,  0,
                  pGlobalTXT_LocalizationStrings[74],  //"End Conversation"
                  pIcons_LOD->GetTexture(uExitCancelTextureId), 0);
--- a/GUIWindow.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/GUIWindow.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -186,7 +186,7 @@
 		return result;
 	  }
 	}
-	if ( !v4->uFrameX && !v4->uFrameY && (v4->uFrameWidth == 640 && v4->uFrameHeight == 480) )
+	if ( !v4->uFrameX && !v4->uFrameY && (v4->uFrameWidth == window->GetWidth() && v4->uFrameHeight == window->GetWidth()) )
 	  break;
   }
   return 0;
@@ -680,8 +680,8 @@
   else
   {
     v4 = 0;
-    v5 = 640;
-    v22 = 480;
+    v5 = window->GetWidth();
+    v22 = window->GetHeight();
   }
   v6 = this->uFrameX;
   if ( (signed int)this->uFrameX >= v4 )
@@ -1146,7 +1146,7 @@
     v13 = (signed int)(v8 - pFont->GetLineWidth(Stra)) >> 1;
     if ( v13 < 0 )
       v13 = 0;
-    pFont->DrawTextLine(uDefaultColor, v11 + v13, v12, Stra, 640);
+    pFont->DrawTextLine(uDefaultColor, v11 + v13, v12, Stra, window->GetWidth());
     v12 += pFont->uFontHeight - uLineSpacing;
     Stra = strtok(0, "\n");
   }
@@ -1520,7 +1520,7 @@
 
 //----- (00459C2B) --------------------------------------------------------
 void GUIWindow::DrawFlashingInputCursor( signed int uX, int uY, struct GUIFont *a2 )
-    {
+{
   if ( GetTickCount() % 1000 > 500 )
     DrawText(a2, uX, uY, 0, "_", 0, 0, 0);
 }
@@ -1760,17 +1760,17 @@
     }
     if (eWindowType == WINDOW_Scroll)
     {
-      pWindow->CreateButton(0x3Du, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 1u, '1', "", 0);
-      pWindow->CreateButton(0xB1u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 2u, '2', "", 0);
-      pWindow->CreateButton(0x124u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 3u, '3', "", 0);
-      pWindow->CreateButton(0x197u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 4u, '4', "", 0);
+      pWindow->CreateButton(61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
+      pWindow->CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
+      pWindow->CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
+      pWindow->CreateButton(407, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
       pWindow->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_CycleCharacters, 0, '\t', "", 0);
       return pWindow;
     }
     if (eWindowType == WINDOW_CastSpell_InInventory)
     {
       pMouse->SetCursorBitmap("MICON2");
-      pBtn_ExitCancel = pWindow->CreateButton(0x188u, 0x13Eu, 0x4Bu, 0x21u, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[34],//Отмена
+      pBtn_ExitCancel = pWindow->CreateButton(392, 318, 75, 33, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[34],//Отмена
                      pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);
       ShowStatusBarString(pGlobalTXT_LocalizationStrings[39], 2);//Выбрать цель
       ++pIcons_LOD->uTexturePacksCount;
@@ -1789,7 +1789,7 @@
   current_npc_text = (char *)pNPCTopics[pEventCode + 99].pText;
   ContractSelectText(pEventCode);
   pDialogueWindow->Release();
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x15E, WINDOW_MainMenu, pEventCode, 0);
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), 350, WINDOW_MainMenu, pEventCode, 0);
   pBtn_ExitCancel = pDialogueWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape,                    0, 0, pGlobalTXT_LocalizationStrings[34], pIcons_LOD->GetTexture(uExitCancelTextureId), 0); // Cancel
                     pDialogueWindow->CreateButton(  0,   0,   0,  0, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0);
                     pDialogueWindow->CreateButton(480, 160, 140, 30, 1, 0, UIMSG_ClickNPCTopic,             0x52u, 0, pGlobalTXT_LocalizationStrings[122], 0);
@@ -2029,9 +2029,9 @@
         if ( pWindow->Hint != (char *)1 )
           pAudioPlayer->PlaySound((SoundID)75, 0, 0, -1, 0, 0, 0, 0);
         pButton = (GUIButton *)pWindow->ptr_1C;
-        if ( pButton->uX >= 0 && pButton->uX <= 640 )
+        if ( pButton->uX >= 0 && pButton->uX <= window->GetWidth() )
         {
-          if ( pButton->uY >= 0 && pButton->uY <= 480 )
+          if ( pButton->uY >= 0 && pButton->uY <= window->GetHeight() )
           {
             pRenderer->DrawTextureIndexed(pWindow->uFrameX, pWindow->uFrameY, pButton->pTextures[0]);
             viewparams->bRedrawGameUI = 1;
@@ -2264,7 +2264,7 @@
 {
   pEventTimer->Pause();
   modal_window_prev_screen = pCurrentScreen;
-  pModalWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_ModalWindow, OnRelease_message, pStrHint);
+  pModalWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_ModalWindow, OnRelease_message, pStrHint);
   pCurrentScreen = SCREEN_MODAL_WINDOW;
 }
 
@@ -2352,7 +2352,7 @@
     if ( mscroll_id <= 782 )
     {
       uTextureID_720980 = pIcons_LOD->LoadTexture("leather", TEXTURE_16BIT_PALETTE);
-      pGUIWindow_ScrollWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_Scroll, v1 - 700, 0);
+      pGUIWindow_ScrollWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Scroll, v1 - 700, 0);
     }
   }
 }
--- a/Game.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Game.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -154,9 +154,7 @@
   v4 = viewparams->bRedrawGameUI;
   GameUI_Footer();
   if (!viewparams->bRedrawGameUI)
-  {
     GameUI_DrawRightPanelItems();
-  }
   else
   {
     GameUI_DrawRightPanelFrames();
@@ -185,7 +183,7 @@
   GameUI_DrawPortraits(v4);
   GameUI_DrawLifeManaBars();
   GameUI_DrawCharacterSelectionFrame();
-  if ( sub_44100D() )
+  if ( _44100D_should_alter_right_panel() )
     GameUI_DrawRightPanel();
   if ( !pVideoPlayer->AnyMovieLoaded() )
   {
@@ -258,9 +256,9 @@
   _unused_5B5924_is_travel_ui_drawn = false;
   if (v4)
     pMouse->bRedraw = true;
-  pMouse->_469EA4();
+  pMouse->ReadCursorWithItem();
   pMouse->DrawCursor();
-  pMouse->_469E1C();
+  pMouse->Activate();
   pRenderer->EndScene();
   pRenderer->Present();
   pParty->uFlags &= ~2;
@@ -526,14 +524,8 @@
 {
   for (uint i = 0; i < uNumBloodsplats; ++i)
   {
-    pBloodsplatContainer->AddBloodsplat(
-        pBloodsplats[i].x,
-        pBloodsplats[i].y,
-        pBloodsplats[i].z,
-        pBloodsplats[i].radius,
-        pBloodsplats[i].r,
-        pBloodsplats[i].g,
-        pBloodsplats[i].b);
+    pBloodsplatContainer->AddBloodsplat(pBloodsplats[i].x, pBloodsplats[i].y, pBloodsplats[i].z,
+        pBloodsplats[i].radius, pBloodsplats[i].r, pBloodsplats[i].g, pBloodsplats[i].b);
    }
 }
 
@@ -546,15 +538,8 @@
   for( int i=0; i<uNumStationaryLights; ++i ) 
       {
        pLight=&pStationaryLights[i];
-       pStationaryLightsStack->AddLight(
-           pLight->vPosition.x, 
-           pLight->vPosition.y,
-           pLight->vPosition.z,
-           pLight->flt_18,
-           pLight->vRGBColor.x,
-           pLight->vRGBColor.y,
-           pLight->vRGBColor.z,
-           _4E94D0_light_type);
+       pStationaryLightsStack->AddLight(pLight->vPosition.x, pLight->vPosition.y, pLight->vPosition.z,
+           pLight->flt_18, pLight->vRGBColor.x, pLight->vRGBColor.y, pLight->vRGBColor.z, _4E94D0_light_type);
       }
 }
 // 4E94D0: using guessed type char _4E94D0_light_type;
@@ -584,11 +569,8 @@
 //----- (0044F07B) --------------------------------------------------------
 bool Game::_44F07B()
 {
-  if (!pKeyboardInstance->IsKeyBeingHeld(VK_SHIFT) &&
-      !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) &&
-      !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) ||
-
-      (pKeyboardInstance->WasKeyPressed(VK_F11) == 0 &&
+  if (!pKeyboardInstance->IsKeyBeingHeld(VK_SHIFT) && !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) &&
+      !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) || (pKeyboardInstance->WasKeyPressed(VK_F11) == 0 &&
        pKeyboardInstance->WasKeyPressed(VK_F11)))
     return true;
   return false;
@@ -601,21 +583,21 @@
   //double v2; // st7@2
   float depth; // ST00_4@9
   //bool result; // eax@9
-  unsigned int v5; // eax@14
+  //unsigned int v5; // eax@14
   __int64 v6; // kr00_8@21
-  unsigned int y; // [sp+4h] [bp-24h]@2
-  unsigned int x; // [sp+8h] [bp-20h]@2
+  //unsigned int y; // [sp+4h] [bp-24h]@2
+  //unsigned int x; // [sp+8h] [bp-20h]@2
   Vis_SelectionFilter *v10; // [sp+10h] [bp-18h]@2
   Vis_SelectionFilter *v11; // [sp+14h] [bp-14h]@2
-  POINT a2; // [sp+20h] [bp-8h]@1
+  POINT cursor; // [sp+20h] [bp-8h]@1
 
   //v1 = this;
   ++qword_5C6DF0;
   pParticleEngine->UpdateParticles();
-  pMouseInstance->GetCursorPos(&a2);
+  pMouseInstance->GetCursorPos(&cursor);
 
-  x = a2.y;
-  y = a2.x;
+  //x = cursor.y;
+  //y = cursor.x;
   if ( sub_4637E0_is_there_popup_onscreen() )
   {
     v11 = &vis_face_filter;
@@ -638,7 +620,7 @@
   }
   //depth = v2;
 
-  PickMouse(depth, y, x, false, v10, v11);
+  PickMouse(depth, cursor.x, cursor.y, false, v10, v11);
   pLightmapBuilder->std__vector_000004_size = 0;
   pLightmapBuilder->std__vector_183808_size = 0;
   pDecalBuilder->std__vector_pDecals_size = 0;
@@ -649,10 +631,7 @@
     if ( uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
       pStru10Instance->bDoNotDrawPortalFrustum = false;
     if ( /*pRenderer->pRenderD3D &&*/ uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-    {
-      v5 = GetLevelFogColor();
-      pRenderer->uFogColor = v5 & 0xFFFFFF;
-    }
+      pRenderer->uFogColor = GetLevelFogColor() & 0xFFFFFF;
     if (uFlags & 0x0400)
       uFlags2 |= 0x01;
     /*if ( !pRenderer->pRenderD3D && uCurrentlyLoadedLevelType == LEVEL_Outdoor && pMobileLightsStack->uNumLightsActive )
@@ -665,7 +644,7 @@
       uFlags2 |= v6;
     if (uNumStationaryLights_in_pStationaryLightsStack != pStationaryLightsStack->uNumLightsActive )
     {
-      uFlags2 |= 1u;
+      uFlags2 |= 1;
       uNumStationaryLights_in_pStationaryLightsStack = pStationaryLightsStack->uNumLightsActive;
     }
     _44E904();
@@ -767,9 +746,7 @@
       v6 = floorf(a3b + 0.5f);
     }
     else
-    {
       v6 = 0;
-    }
     if ( a4 >= v6 )
     {
       a4a = (1.0 - fSaturation) * a2a;
@@ -783,19 +760,13 @@
         result = floorf(a4b + 0.5f);
       }
       else
-      {
         result = 0;
-      }
     }
     else
-    {
       result = a4;
-    }
   }
   else
-  {
     result = -1;
-  }
   return result;
 }
 
@@ -846,9 +817,7 @@
       v6 = floorf(v13 + 0.5f);
     }
     else
-    {
       v6 = 0;
-    }
     if ( a4 >= v6 )
     {
       v14 = (1.0 - fSaturation) * v11;
@@ -861,19 +830,13 @@
         result = floorf(v15 + 0.5f);
       }
       else
-      {
         result = 0;
-      }
     }
     else
-    {
       result = a4;
-    }
   }
   else
-  {
     result = -1;
-  }
   return result;
 }
 
@@ -1008,9 +971,7 @@
       v7 = 0.0;
   }
   else
-  {
     v7 = 1.0;
-  }
   //if ( pRenderer->pRenderD3D )
     fSaturation = v7;
   //else
@@ -1526,7 +1487,7 @@
           pIcons_LOD->RemoveTexturesPackFromTextureList();
           pGUIWindow_CurrentMenu->Release();
           pCurrentScreen = SCREEN_OPTIONS;
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_8, 0, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_8, 0, 0);
           continue;
         case UIMSG_ArrowUp:
           --pSaveListPosition;
@@ -1618,7 +1579,7 @@
           options_menu_skin.uTextureID_ShowDamage     = pIcons_LOD->LoadTexture("option02", TEXTURE_16BIT_PALETTE);
           options_menu_skin.uTextureID_WalkSound      = pIcons_LOD->LoadTexture("option01", TEXTURE_16BIT_PALETTE);
 
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Options, 0, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Options, 0, 0);
           pGUIWindow_CurrentMenu->CreateButton(22, 270,
                                                pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[2])->uTextureWidth,
                                                pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[2])->uTextureHeight,
@@ -1677,7 +1638,7 @@
           uTextureID_Optkb[2] = pIcons_LOD->LoadTexture("resume1", TEXTURE_16BIT_PALETTE);
           uTextureID_Optkb[3] = pIcons_LOD->LoadTexture("optkb_1", TEXTURE_16BIT_PALETTE);
           uTextureID_Optkb[4] = pIcons_LOD->LoadTexture("optkb_2", TEXTURE_16BIT_PALETTE);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_KeyMappingOptions, 0, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_KeyMappingOptions, 0, 0);
           pGUIWindow_CurrentMenu->CreateButton(0xF1u, 0x12Eu, 0xD6u, 0x28u, 1, 0, UIMSG_Escape, 0, 0, "", 0);
           pGUIWindow_CurrentMenu->CreateButton(19u, 0x12Eu, 0x6Cu, 0x14u, 1, 0, UIMSG_SelectKeyPage1, 0, 0, "", 0);
           pGUIWindow_CurrentMenu->CreateButton(127u, 0x12Eu, 0x6Cu, 0x14u, 1, 0, UIMSG_SelectKeyPage2, 0, 0, "", 0);
@@ -1778,7 +1739,7 @@
           not_available_bloodsplats_texture_id = pIcons_LOD->LoadTexture("opvdG-bs", TEXTURE_16BIT_PALETTE);
           not_available_us_colored_lights_texture_id = pIcons_LOD->LoadTexture("opvdG-cl", TEXTURE_16BIT_PALETTE);
           not_available_tinting_texture_id = pIcons_LOD->LoadTexture("opvdG-tn", TEXTURE_16BIT_PALETTE);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_VideoOptions, 0, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_VideoOptions, 0, 0);
           pGUIWindow_CurrentMenu->CreateButton(0xF1u, 0x12Eu, 0xD6u, 0x28u, 1, 0, UIMSG_Escape, 0, 0, "", 0);
           //if ( pRenderer->pRenderD3D )
           {
@@ -1992,7 +1953,7 @@
             pGUIWindow_CurrentMenu->Release();
           pEventTimer->Pause();
           pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640u, 480u, WINDOW_Book, uMessage, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
           pBooksWindow = GUIWindow::Create(493u, 355u, 0, 0, WINDOW_BooksWindow, (int)pBtn_Quests, 0);
           bFlashQuestBook = 0;
           continue;
@@ -2003,7 +1964,7 @@
             pGUIWindow_CurrentMenu->Release();
           pEventTimer->Pause();
           pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640u, 480u, WINDOW_Book, uMessage, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
           pBooksWindow = GUIWindow::Create(527u, 353u, 0, 0, WINDOW_BooksWindow, (int)pBtn_Autonotes, 0);
           bFlashAutonotesBook = 0;
           continue;
@@ -2016,7 +1977,7 @@
           viewparams->sViewCenterX = pParty->vPosition.x;
           viewparams->sViewCenterY = pParty->vPosition.y;
           pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Book, uMessage, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
           pBooksWindow = GUIWindow::Create(546, 353, 0, 0, WINDOW_BooksWindow, (int)pBtn_Maps, 0);
           continue;
         case UIMSG_OpenCalendar:
@@ -2026,7 +1987,7 @@
             pGUIWindow_CurrentMenu->Release();
           pEventTimer->Pause();
           pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Book, uMessage, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
           pBooksWindow = GUIWindow::Create(570, 354, 0, 0, WINDOW_BooksWindow, (int)pBtn_Calendar, 0);
           continue;
         case UIMSG_OpenHistoryBook:
@@ -2036,7 +1997,7 @@
             pGUIWindow_CurrentMenu->Release();
           pEventTimer->Pause();
           pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Book, uMessage, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
           pBooksWindow = GUIWindow::Create(0x258u, 0x169u, 0, 0, WINDOW_BooksWindow, (int)pBtn_History, 0);
           bFlashHistoryBook = 0;
           continue;
@@ -2083,9 +2044,7 @@
                   if ( pGUIWindow_Settings )
                   {
                     if ( pCurrentScreen == SCREEN_CHARACTERS )
-                    {
                       pMouse->SetCursorBitmap("MICON2");
-                    }
                     else
                     {
                       pGUIWindow_Settings->Release();
@@ -2136,18 +2095,16 @@
                       }
                       if ( pGUIWindow_Settings )
                       {
-                       if ( pCurrentScreen == SCREEN_CHARACTERS )
-                       {
-                        pMouse->SetCursorBitmap("MICON2");
-                       }
-                       else
-                       {
-                         pGUIWindow_Settings->Release();
-                         pGUIWindow_Settings = 0;
-                         pMouse->SetCursorBitmap("MICON1");
-                         GameUI_Footer_TimeLeft = 0;
-                         _50C9A0_IsEnchantingInProgress = 0;
-                         back_to_game();
+                        if ( pCurrentScreen == SCREEN_CHARACTERS )
+                          pMouse->SetCursorBitmap("MICON2");
+                        else
+                        {
+                          pGUIWindow_Settings->Release();
+                          pGUIWindow_Settings = 0;
+                          pMouse->SetCursorBitmap("MICON1");
+                          GameUI_Footer_TimeLeft = 0;
+                          _50C9A0_IsEnchantingInProgress = 0;
+                          back_to_game();
                         }
                        }
                        if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
@@ -2169,17 +2126,15 @@
                       if ( pGUIWindow_Settings )
                       {
                         if ( pCurrentScreen == SCREEN_CHARACTERS )
-                        {
-                         pMouse->SetCursorBitmap("MICON2");
-                        }
+                          pMouse->SetCursorBitmap("MICON2");
                         else
                         {
-                         pGUIWindow_Settings->Release();
-                         pGUIWindow_Settings = 0;
-                         pMouse->SetCursorBitmap("MICON1");
-                         GameUI_Footer_TimeLeft = 0;
-                         _50C9A0_IsEnchantingInProgress = 0;
-                         back_to_game();
+                          pGUIWindow_Settings->Release();
+                          pGUIWindow_Settings = 0;
+                          pMouse->SetCursorBitmap("MICON1");
+                          GameUI_Footer_TimeLeft = 0;
+                          _50C9A0_IsEnchantingInProgress = 0;
+                          back_to_game();
                         }
                       }
                       if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
@@ -2290,8 +2245,7 @@
 
                           memset(&uTextureID_Optkb, 0, 0x14u);
                           pIcons_LOD->SyncLoadedFilesCount();
-                          uAction = 0;
-                          do
+                          for ( uAction = 0; uAction < 28; ++uAction )
                           {
                             v33 = pKeyActionMap->GetActionVKey((enum InputAction)uAction);
                             if ( v33 != pPrevVirtualCidesMapping[uAction] )
@@ -2313,9 +2267,7 @@
                             else
                               pKeyToggleType = TOGGLE_Continuously;
                             pKeyActionMap->SetKeyMapping(uAction, pPrevVirtualCidesMapping[uAction], pKeyToggleType);
-                            ++uAction;
                           }
-                          while ( uAction < 28 );
                           pKeyActionMap->StoreMappings();
                           stru_506E40.Release();
                           break;
@@ -2347,9 +2299,7 @@
                       if ( pGUIWindow_Settings )
                       {
                         if ( pCurrentScreen == SCREEN_CHARACTERS )
-                        {
                           pMouse->SetCursorBitmap("MICON2");
-                        }
                         else
                         {
                           pGUIWindow_Settings->Release();
@@ -2358,7 +2308,7 @@
                           GameUI_Footer_TimeLeft = 0;
                           _50C9A0_IsEnchantingInProgress = 0;
                           back_to_game();
-                         }
+                        }
                       }
                       if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
                         uActiveCharacter = pParty->GetNextActiveCharacter();
@@ -2397,9 +2347,7 @@
                       if ( pGUIWindow_Settings )
                       {
                         if ( pCurrentScreen == SCREEN_CHARACTERS )
-                        {
                           pMouse->SetCursorBitmap("MICON2");
-                        }
                         else
                         {
                           pGUIWindow_Settings->Release();
@@ -2481,9 +2429,7 @@
                       if ( pGUIWindow_Settings )
                       {
                         if ( pCurrentScreen == SCREEN_CHARACTERS )
-                        {
                           pMouse->SetCursorBitmap("MICON2");
-                        }
                         else
                         {
                           pGUIWindow_Settings->Release();
@@ -2509,9 +2455,7 @@
                       if ( pGUIWindow_Settings )
                       {
                         if ( pCurrentScreen == SCREEN_CHARACTERS )
-                        {
                           pMouse->SetCursorBitmap("MICON2");
-                        }
                         else
                         {
                           pGUIWindow_Settings->Release();
@@ -2537,9 +2481,7 @@
                   if ( pGUIWindow_Settings )
                   {
                     if ( pCurrentScreen == SCREEN_CHARACTERS )
-                    {
                       pMouse->SetCursorBitmap("MICON2");
-                    }
                     else
                     {
                       pGUIWindow_Settings->Release();
@@ -2569,9 +2511,7 @@
               if ( pGUIWindow_Settings )
               {
                 if ( pCurrentScreen == SCREEN_CHARACTERS )
-                {
                   pMouse->SetCursorBitmap("MICON2");
-                }
                 else
                 {
                   pGUIWindow_Settings->Release();
@@ -2606,7 +2546,7 @@
               if ( !pIcons_LOD->uNumPrevLoadedFiles )
                 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
 
-              pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_OptionsButtons, 0, 0);
+              pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_OptionsButtons, 0, 0);
               uTextureID_Options = pIcons_LOD->LoadTexture("options", TEXTURE_16BIT_PALETTE);
               uTextureID_New1 = pIcons_LOD->LoadTexture("new1", TEXTURE_16BIT_PALETTE);
               uTextureID_Load1 = pIcons_LOD->LoadTexture("load1", TEXTURE_16BIT_PALETTE);
@@ -3024,12 +2964,12 @@
 
         case UIMSG_OnCastTownPortal:
           pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Book, WINDOW_TownPortal, (char *)uMessageParam);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, WINDOW_TownPortal, (char *)uMessageParam);
         continue;
 
         case UIMSG_OnCastLloydsBeacon:
           pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Book, WINDOW_LloydsBeacon, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, WINDOW_LloydsBeacon, 0);
         continue;
 
         case UIMSG_LloydsBeacon_FlippingBtn:
@@ -3473,7 +3413,7 @@
 			__debugbreak();
           if ( !uActiveCharacter || pCurrentScreen )
             continue;
-          ptr_507BC8 = GUIWindow::Create(0, 0, 640, 480, WINDOW_68, uMessageParam, 0);
+          ptr_507BC8 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_68, uMessageParam, 0);
           pCurrentScreen = SCREEN_19;
           pEventTimer->Pause();
           continue;
@@ -3845,7 +3785,7 @@
                 GUIWindow::Create(476, 450, 0, 0, WINDOW_PressedButton2, (int)pBtn_CastSpell, 0);
                 pCurrentScreen = SCREEN_SPELL_BOOK;
                 pEventTimer->Pause();
-                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_SpellBook, 0, 0);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SpellBook, 0, 0);
                 pAudioPlayer->PlaySound((SoundID)48, 0, 0, -1, 0, 0, 0, 0);
                 viewparams->field_48 = 1;
                 continue;
@@ -3857,7 +3797,7 @@
                 GUIWindow::Create(476, 450, 0, 0, WINDOW_PressedButton2, (int)pBtn_CastSpell, 0);
                 pCurrentScreen = SCREEN_SPELL_BOOK;
                 pEventTimer->Pause();
-                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_SpellBook, 0, 0);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SpellBook, 0, 0);
                 pAudioPlayer->PlaySound((SoundID)48, 0, 0, -1, 0, 0, 0, 0);
                 viewparams->field_48 = 1;
                 continue;
@@ -3878,7 +3818,7 @@
           pEventTimer->Pause();
           pAudioPlayer->StopChannels(-1, -1);
           pCurrentScreen = SCREEN_QUICK_REFERENCE;
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_QuickReference, 5, 0);
+          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_QuickReference, 5, 0);
           papredoll_dbrds[2] = pIcons_LOD->LoadTexture("BUTTEXI1", TEXTURE_16BIT_PALETTE);
           pBtn_ExitCancel = pGUIWindow_CurrentMenu->CreateButton(0x187u, 0x13Cu, 0x4Bu, 0x21u, 1, 0, UIMSG_Escape, 0, 0,
                          pGlobalTXT_LocalizationStrings[79],// "Exit"
--- a/Indoor.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Indoor.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -280,8 +280,8 @@
   this->fov_rad_fixpoint = fixpoint_from_int(_calc_fov(uViewportWidth, 65), 0);
   this->fov_rad_inv_fixpoint = 0x100000000i64 / this->fov_rad_fixpoint;
   this->pRenderTarget = pRenderer->pTargetSurface;
-  this->uTargetWidth = 640;
-  this->uTargetHeight = 480;
+  this->uTargetWidth = window->GetWidth();
+  this->uTargetHeight = window->GetHeight();
   this->pTargetZBuffer = pRenderer->pActiveZBuffer;
   this->field_8C = 0;
   this->field_84 = 0;
@@ -411,12 +411,12 @@
   _this.pTargetZ = pRenderer->pActiveZBuffer;*/
 
   //sub_440BED(&_this); -- inlined
-  {
+  //{
     PrepareDrawLists_BLV();
     if (pBLVRenderParams->uPartySectorID)
       IndoorLocation::ExecDraw(true/*pRenderer->pRenderD3D != 0*/);
     pRenderer->DrawBillboardList_BLV();
-  }
+  //}
 
   pParty->uFlags &= ~2;
   pGame->DrawParticles();
@@ -509,7 +509,7 @@
     return;
   
   ++pBLVRenderParams->uNumFacesRenderedThisFrame;
-  pFace->uAttributes |= 0x80u;
+  pFace->uAttributes |= 0x80;
 
   if (!pFace->GetTexture())
     return;
@@ -601,18 +601,14 @@
   stru_F8AD28.pDeltaUV[1] = pIndoor->pFaceExtras[pIndoor->pFaces[uFaceID].uFaceExtraID].sTextureDeltaV;
   result = GetTickCount() >> 3;
   if ( pIndoor->pFaces[uFaceID].uAttributes & 4 )
-  {
     stru_F8AD28.pDeltaUV[1] -= result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uHeightMinus1;
-  }
   else
   {
     if ( pIndoor->pFaces[uFaceID].uAttributes & 0x20 )
       stru_F8AD28.pDeltaUV[1] += result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uHeightMinus1;
   }
-  if ( BYTE1(pIndoor->pFaces[uFaceID].uAttributes) & 8 )
-  {
+  if ( pIndoor->pFaces[uFaceID].uAttributes & 0x800 )
     stru_F8AD28.pDeltaUV[0] -= result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uWidthMinus1;
-  }
   else
   {
     if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_DONT_CACHE_TEXTURE )
@@ -791,7 +787,6 @@
   }
 }
 
-
 //----- (004AE5BA) --------------------------------------------------------
 Texture *BLVFace::GetTexture()
 {
@@ -808,46 +803,46 @@
 //----- (00498B15) --------------------------------------------------------
 void IndoorLocation::Release()
 {
-  IndoorLocation *v1; // esi@1
-  char *v2; // ebp@1
-  void *v3; // ST00_4@1
-
-  v1 = this;
-  v2 = (char *)&this->ptr_0002B4_doors_ddata;
+  //IndoorLocation *v1; // esi@1
+  //char *v2; // ebp@1
+  //void *v3; // ST00_4@1
+
+  //v1 = this;
+  //v2 = (char *)&this->ptr_0002B4_doors_ddata;
   free(this->ptr_0002B4_doors_ddata);
-  *(int *)v2 = 0;
-  free(v1->ptr_0002B0_sector_rdata);
-  v1->ptr_0002B0_sector_rdata = 0;
-  free(v1->ptr_0002B8_sector_lrdata);
-  v1->ptr_0002B8_sector_lrdata = 0;
-  free(v1->pLFaces);
-  v1->pLFaces = 0;
-  free(v1->pSpawnPoints);
-  v3 = v1->pVertices;
-  v1->pSpawnPoints = 0;
-  v1->uNumSectors = 0;
-  v1->uNumFaces = 0;
-  v1->uNumVertices = 0;
-  v1->uNumNodes = 0;
-  v1->uNumDoors = 0;
-  v1->uNumLights = 0;
-  free(v3);
-  free(v1->pFaces);
-  free(v1->pFaceExtras);
-  free(v1->pSectors);
-  free(v1->pLights);
-  free(v1->pDoors);
-  free(v1->pNodes);
-  free(v1->pMapOutlines);
-  v1->pVertices = 0;
-  v1->pFaces = 0;
-  v1->pFaceExtras = 0;
-  v1->pSectors = 0;
-  v1->pLights = 0;
-  v1->pDoors = 0;
-  v1->pNodes = 0;
-  v1->pMapOutlines = 0;
-  v1->bLoaded = 0;
+  this->ptr_0002B4_doors_ddata = 0;
+  free(this->ptr_0002B0_sector_rdata);
+  this->ptr_0002B0_sector_rdata = 0;
+  free(this->ptr_0002B8_sector_lrdata);
+  this->ptr_0002B8_sector_lrdata = 0;
+  free(this->pLFaces);
+  this->pLFaces = 0;
+  free(this->pSpawnPoints);
+  //v3 = this->pVertices;
+  this->pSpawnPoints = 0;
+  this->uNumSectors = 0;
+  this->uNumFaces = 0;
+  this->uNumVertices = 0;
+  this->uNumNodes = 0;
+  this->uNumDoors = 0;
+  this->uNumLights = 0;
+  free(this->pVertices);
+  free(this->pFaces);
+  free(this->pFaceExtras);
+  free(this->pSectors);
+  free(this->pLights);
+  free(this->pDoors);
+  free(this->pNodes);
+  free(this->pMapOutlines);
+  this->pVertices = 0;
+  this->pFaces = 0;
+  this->pFaceExtras = 0;
+  this->pSectors = 0;
+  this->pLights = 0;
+  this->pDoors = 0;
+  this->pNodes = 0;
+  this->pMapOutlines = 0;
+  this->bLoaded = 0;
 }
 
 //----- (00498C45) --------------------------------------------------------
@@ -879,8 +874,6 @@
   }
 }
 
-
-
 //----- (00444810) --------------------------------------------------------
 unsigned int IndoorLocation::GetLocationIndex(const char *Str1)
 {
@@ -893,8 +886,6 @@
   return 0;
 }
 
-
-
 //----- (004488F7) --------------------------------------------------------
 void IndoorLocation::ToggleLight(signed int sLightID, unsigned int bToggle)
 {
@@ -908,7 +899,6 @@
   }
 }
 
-
 //----- (00498E0A) --------------------------------------------------------
 bool IndoorLocation::Load(char *pFilename, int a3, size_t _i, char *pDest)
 {
@@ -2490,13 +2480,13 @@
     goto LABEL_12;
   }
 LABEL_12:
-  if ( BYTE2(this->uAttributes) & 0x80 )
+  if ( this->uAttributes & 0x800000 )
   {
     a2->x = -a2->x;
     a2->y = -a2->y;
     a2->z = -a2->z;
   }
-  if ( BYTE3(this->uAttributes) & 1 )
+  if ( this->uAttributes & 0x1000000 )
   {
     a3->x = -a3->x;
     a3->y = -a3->y;
@@ -3482,13 +3472,9 @@
           if ( v55 >= 50 )
             break;
           if ( pFloor->uPolygonType == POLYGON_Floor || pFloor->uPolygonType == POLYGON_Ceiling )
-          {
             v21 = pIndoor->pVertices[pFloor->pVertexIDs[0]].z;
-          }
           else
-          {
             v21 = fixpoint_mul(pFloor->zCalc1, x) + fixpoint_mul(pFloor->zCalc2, y) + (short)(pFloor->zCalc3 >> 16);
-          }
           blv_floor_level[v55] = v21;
           blv_floor_id[v55] = pSector->pFloors[i];
           v55++;
@@ -3496,7 +3482,6 @@
     }
   }
 
-
   if ( pSector->field_0 & 8 )
   {
     for (uint i = 0; i < pSector->uNumPortals; ++i)
@@ -3561,6 +3546,8 @@
   if ( v55 == 1 )
   {
     *pFaceID = blv_floor_id[0];
+	if ( blv_floor_level[0] <= -29000 )
+		__debugbreak();
     return blv_floor_level[0];
   }
   if ( !v55 )
@@ -3595,12 +3582,16 @@
         if ( v38 > result && v38 <= z + 5 )
         {
           result = blv_floor_level[i];
+	if ( blv_floor_level[i] <= -29000 )
+		__debugbreak();
           *pFaceID = blv_floor_id[i];
         }
       }
       else if ( v38 < result )
       {
         result = blv_floor_level[i];
+	if ( blv_floor_level[i] <= -29000 )
+		__debugbreak();
         *pFaceID = blv_floor_id[i];
       }
   }
@@ -3610,7 +3601,7 @@
 //----- (004016FA) --------------------------------------------------------
 int  MakeActorAIList_BLV()
 {
-  Actor *v0; // esi@2
+  //Actor *v0; // esi@2
   int v1; // eax@4
   int v2; // ebx@4
   unsigned int v3; // ecx@4
@@ -3649,10 +3640,10 @@
   int v37; // [sp+Ch] [bp-18h]@1
   int v38; // [sp+10h] [bp-14h]@4
   int v39; // [sp+14h] [bp-10h]@4
-  int v40; // [sp+18h] [bp-Ch]@10
+  //int v40; // [sp+18h] [bp-Ch]@10
   int v41; // [sp+18h] [bp-Ch]@29
   int i; // [sp+18h] [bp-Ch]@31
-  signed int v43; // [sp+1Ch] [bp-8h]@1
+  //signed int v43; // [sp+1Ch] [bp-8h]@1
   signed int v44; // [sp+1Ch] [bp-8h]@25
   int v45; // [sp+20h] [bp-4h]@1
 
@@ -3660,201 +3651,152 @@
   pParty->uFlags &= 0xFFFFFFCFu;
   v37 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
   v45 = 0;
-  v43 = 0;
-  if ( (signed int)uNumActors > 0 )
+  for ( uint i = 0; i < (signed int)uNumActors; ++i )
   {
-    v0 = pActors.data();//[0].uAttributes;
-    do
+    pActors[i].uAttributes &= 0xFB00;
+    if ( !pActors[i].CanAct() )
+    {
+      pActors[i].uAttributes &= 0xBF00;
+      continue;
+    }
+    v39 = abs(pParty->vPosition.z - pActors[i].vPosition.z);
+    v38 = abs(pParty->vPosition.y - pActors[i].vPosition.y);
+    v1 = abs(pParty->vPosition.x - pActors[i].vPosition.x);
+    v2 = v38;
+    v3 = v39;
+    if ( v1 < v38 )
     {
-      BYTE1(v0->uAttributes) &= 0xFBu;
-      if ( ! v0->CanAct() )
-        goto LABEL_60;
-	  v39 = abs(pParty->vPosition.z - v0->vPosition.z);
-	  v38 = abs(pParty->vPosition.y - v0->vPosition.y);
-	  v1 = abs(pParty->vPosition.x - v0->vPosition.x);
-      v2 = v38;
-      v3 = v39;
-      if ( v1 < v38 )
+      v4 = v1;
+      v1 = v38;
+      v2 = v4;
+    }
+    if ( v1 < v39 )
+    {
+      v5 = v1;
+      v1 = v39;
+      v3 = v5;
+    }
+    if ( v2 < (signed int)v3 )
+    {
+      v6 = v3;
+      v3 = v2;
+      v2 = v6;
+    }
+    v7 = ((unsigned int)(11 * v2) >> 5) + (v3 >> 2) + v1;
+    v9 = v7 - pActors[i].uActorRadius;
+    if ( v9 < 0 )
+      v9 = 0;
+    if ( v9 < 10240 )
+    {
+      pActors[i].uAttributes &= 0xFEFFFFFF;
+      if ( pActors[i].uAttributes & 0x80000 || pActors[i].GetActorsRelation(0) )
       {
-        v4 = v1;
-        v1 = v38;
-        v2 = v4;
-      }
-      if ( v1 < v39 )
-      {
-        v5 = v1;
-        v1 = v39;
-        v3 = v5;
-      }
-      if ( v2 < (signed int)v3 )
-      {
-        v6 = v3;
-        v3 = v2;
-        v2 = v6;
+        pActors[i].uAttributes |= 0x1000000;
+        if ( !(pParty->uFlags & 0x10) && (double)v9 < 307.2 )
+          pParty->uFlags |= 0x10;
+        if ( !(pParty->uFlags & 0x20) && v9 < 5120 )
+          pParty->uFlags |= 0x20;
       }
-      v7 = ((unsigned int)(11 * v2) >> 5) + (v3 >> 2) + v1;
-      v8 = v0->uActorRadius;
-      v9 = v7 - v8;
-      v40 = v7 - v8;
-      if ( v40 < 0 )
-      {
-        v9 = 0;
-        v40 = 0;
-      }
-      if ( v9 < 10240 )
-      {
-        v10 = v0->uAttributes & 0xFEFFFFFF;
-        v0->uAttributes = v10;
-        if ( v10 & 0x80000 || v0->GetActorsRelation(0) )
-        {
-          v11 = (pParty->uFlags & 0x10) == 0;
-          v0->uAttributes = v10 | 0x1000000;
-          if ( v11 && (double)v40 < 307.2 )
-            pParty->uFlags |= 0x10u;
-          if ( !(pParty->uFlags & 0x20) && v9 < 5120 )
-            pParty->uFlags |= 0x20u;
-        }
-        v12 = v45++;
-        ai_near_actors_distances[v12] = v9;
-        ai_near_actors_ids[v12] = v43;
-      }
-      else
-      {
-LABEL_60:
-        BYTE1(v0->uAttributes) &= 0xBFu;
-      }
-      ++v43;
-      ++v0;
+      v12 = v45++;
+      ai_near_actors_distances[v12] = v9;
+      ai_near_actors_ids[v12] = i;
     }
-    while ( v43 < (signed int)uNumActors );
+    else
+      pActors[i].uAttributes &= 0xBF00;
   }
   v13 = 0;
   if ( v45 > 0 )
   {
-    v14 = 1;
-    v44 = 1;
-    do
+    for ( uint i = 1; i < v45; i++ )
     {
-      while ( 1 )
+      for ( uint j = 1; j < v45; ++j )
       {
-        v41 = v14;
-        if ( v14 >= v45 )
-          break;
         v15 = ai_near_actors_distances[v13];
-        if ( v15 > ai_near_actors_distances[v14] )
+        if ( ai_near_actors_distances[v13] > ai_near_actors_distances[j] )
         {
-          v16 = &ai_near_actors_ids[v14];
           v17 = ai_near_actors_ids[v13];
-          ai_near_actors_ids[v13] = *v16;
-          *v16 = v17;
-          v14 = v41;
-          ai_near_actors_distances[v13] = ai_near_actors_distances[v41];
-          ai_near_actors_distances[v41] = v15;
+          ai_near_actors_ids[v13] = ai_near_actors_ids[j];
+          ai_near_actors_ids[j] = v17;
+          ai_near_actors_distances[v13] = ai_near_actors_distances[j];
+          ai_near_actors_distances[j] = v15;
         }
-        ++v14;
       }
       ++v13;
-      v14 = v44 + 1;
-      v44 = v14;
     }
-    while ( v14 - 1 < v45 );
   }
   v18 = 0;
   v19 = 0;
-  for ( i = 0; v18 < v45; i = v18 )
+  for ( i = 0; i < v45; i++ )
   {
-    v20 = &pActors[ai_near_actors_ids[v18]];
-    if ( v20->uAttributes & 0x8000
-      || (v21 = sub_4070EF_prolly_detect_player(PID(OBJECT_Actor,ai_near_actors_ids[v18]), 4u), v18 = i, v21) )
+    if ( pActors[ai_near_actors_ids[i]].uAttributes & 0x8000
+      || sub_4070EF_prolly_detect_player(PID(OBJECT_Actor,ai_near_actors_ids[i]), 4) )
     {
-      v22 = ai_near_actors_ids[v18];
-      v20->uAttributes |= 0x8000u;
-      ai_array_4F6638_actor_ids[v19] = v22;
-      ai_array_4F5E68[v19++] = ai_near_actors_distances[v18];
+      pActors[ai_near_actors_ids[i]].uAttributes |= 0x8000;
+      ai_array_4F6638_actor_ids[v19] = ai_near_actors_ids[i];
+      ai_array_4F5E68[v19++] = ai_near_actors_distances[i];
       if ( v19 >= 30 )
         break;
     }
-    ++v18;
   }
-  v23 = 0;
   ai_arrays_size = v19;
   if ( (signed int)uNumActors > 0 )
   {
-    v24 = pActors.data();//[0].uAttributes;
-    do
+    for ( uint i = 0; i < (signed int)uNumActors; ++i )
     {
-      if ( v24->CanAct() && v24->uSectorID == v37 )
+      if ( pActors[i].CanAct() && pActors[i].uSectorID == v37 )
       {
         v25 = 0;
         if ( v19 <= 0 )
         {
-LABEL_43:
-          v26 = ai_arrays_size;
-          BYTE1(v24->uAttributes) |= 0x40u;
-          ++ai_arrays_size;
-          ai_array_4F6638_actor_ids[v26] = v23;
+          pActors[i].uAttributes |= 0x4000;
+          ai_array_4F6638_actor_ids[ai_arrays_size++] = i;
         }
         else
         {
-          while ( ai_array_4F6638_actor_ids[v25] != v23 )
+          while ( ai_array_4F6638_actor_ids[v25] != i )
           {
             ++v25;
             if ( v25 >= v19 )
-              goto LABEL_43;
+            {
+              pActors[i].uAttributes |= 0x4000;
+              ai_array_4F6638_actor_ids[ai_arrays_size++] = i;
+			  break;
+            }
           }
         }
       }
-      ++v23;
-      ++v24;
     }
-    while ( v23 < (signed int)uNumActors );
   }
   v27 = ai_arrays_size;
   for ( j = 0; j < v45; ++j )
   {
-    v29 = ai_near_actors_ids[j];
-    if ( pActors[v29].uAttributes & 0xC000 && pActors[v29].CanAct() )
+    //v29 = ai_near_actors_ids[j];
+    if ( pActors[ai_near_actors_ids[j]].uAttributes & 0xC000 && pActors[ai_near_actors_ids[j]].CanAct() )
     {
       v30 = 0;
       if ( v27 <= 0 )
-      {
-LABEL_51:
-        v31 = ai_arrays_size;
-        v32 = ai_near_actors_ids[j];
-        ++ai_arrays_size;
-        ai_array_4F6638_actor_ids[v31] = v32;
-      }
+        ai_array_4F6638_actor_ids[ai_arrays_size++] = ai_near_actors_ids[j];
       else
       {
         while ( ai_array_4F6638_actor_ids[v30] != ai_near_actors_ids[j] )
         {
           ++v30;
           if ( v30 >= v27 )
-            goto LABEL_51;
+		  {
+            ai_array_4F6638_actor_ids[ai_arrays_size++] = ai_near_actors_ids[j];
+			break;
+		  }
         }
       }
     }
   }
-  v33 = ai_arrays_size;
   if ( ai_arrays_size > 30 )
-  {
-    v33 = 30;
     ai_arrays_size = 30;
-  }
-  memcpy(ai_near_actors_ids.data(), ai_array_4F6638_actor_ids.data(), 4 * v33);
+  memcpy(ai_near_actors_ids.data(), ai_array_4F6638_actor_ids.data(), 4 * ai_arrays_size);
   memcpy(ai_near_actors_distances.data(), ai_array_4F5E68.data(), 4 * ai_arrays_size);
-  v34 = (unsigned int)ai_arrays_size;
-  if ( ai_arrays_size > 0 )
-  {
-    do
-    {
-      v35 = (char *)&pActors[ai_near_actors_ids[HIDWORD(v34)]].uAttributes;
-      v35[1] |= 4u;
-      ++HIDWORD(v34);
-    }
-    while ( SHIDWORD(v34) < (signed int)v34 );
-  }
-  return v34;
+  for ( uint i = 0; i < ai_arrays_size; i++ )
+    pActors[ai_near_actors_ids[i]].uAttributes |= 0x400;
+  return ai_arrays_size;
 }
 //----- (0043FDED) --------------------------------------------------------
 void PrepareActorRenderList_BLV()
@@ -4343,11 +4285,11 @@
   _viewport_space_y = y;
   _viewport_space_w = w;
 
-  for (uint i = 0; i < 480; ++i)
+  for (uint i = 0; i < window->GetHeight(); ++i)
   {
     if ( i < y || i > w )
     {
-      viewport_left_side[i] = 640;
+      viewport_left_side[i] = window->GetWidth();
       viewport_right_side[i] = -1;
     }
     else
@@ -4487,8 +4429,8 @@
   int v35; // eax@39
   int v36; // ebx@39
   int v37; // edx@41
-  char *v38; // edi@51
-  ODMFace *v39; // esi@54
+  //char *v38; // edi@51
+  ODMFace *odm_face; // esi@54
   int v40; // ebx@60
   int v41; // eax@61
   signed int v42; // edi@61
@@ -4509,9 +4451,9 @@
   int v57; // eax@81
   int v58; // esi@81
   int v59; // eax@90
-  BLVSector *v60; // edx@90
+  //BLVSector *v60; // edx@90
   int v61; // ecx@90
-  BLVFace *v62; // esi@91
+  BLVFace *face; // esi@91
   int v63; // ST34_4@98
   int v64; // ST30_4@98
   int v65; // eax@98
@@ -4539,7 +4481,7 @@
   int v87; // ecx@128
   BLVSector *v88; // eax@128
   int v89; // ecx@128
-  BLVFace *v90; // esi@129
+  //BLVFace *v90; // esi@129
   int v91; // ebx@136
   int v92; // eax@137
   signed int v93; // edi@137
@@ -4552,8 +4494,8 @@
   int v101; // [sp-8h] [bp-84h]@126
   int v102; // [sp-4h] [bp-80h]@88
   int v103; // [sp-4h] [bp-80h]@126
-  int v104; // [sp+Ch] [bp-70h]@13
-  int v105; // [sp+Ch] [bp-70h]@48
+  //int v104; // [sp+Ch] [bp-70h]@13
+  //int v105; // [sp+Ch] [bp-70h]@48
   int v106; // [sp+10h] [bp-6Ch]@18
   int v107; // [sp+10h] [bp-6Ch]@98
   int v108; // [sp+10h] [bp-6Ch]@104
@@ -4605,11 +4547,11 @@
   int sDeptha; // [sp+58h] [bp-24h]@52
   int sDepthb; // [sp+58h] [bp-24h]@90
   char *a5; // [sp+5Ch] [bp-20h]@16
-  char *a5a; // [sp+5Ch] [bp-20h]@51
+  //char *a5a; // [sp+5Ch] [bp-20h]@51
   signed int a5b; // [sp+5Ch] [bp-20h]@83
   signed int a5c; // [sp+5Ch] [bp-20h]@121
-  signed int v160; // [sp+60h] [bp-1Ch]@12
-  signed int v161; // [sp+60h] [bp-1Ch]@47
+  //signed int v160; // [sp+60h] [bp-1Ch]@12
+  //signed int v161; // [sp+60h] [bp-1Ch]@47
   int v162; // [sp+60h] [bp-1Ch]@128
   int v163; // [sp+64h] [bp-18h]@2
   int outx; // [sp+68h] [bp-14h]@2
@@ -4630,7 +4572,7 @@
   int v_4c; // [sp+8Ch] [bp+10h]@141
   int v_8; // [sp+90h] [bp+14h]@53
 
-  //__debugbreak();
+  //__debugbreak();срабатывает при стрельбе огненным шаром
 
   v4 = stru_5C6E00->Atan2(v.x - x, v.y - z);
   v114 = 0;
@@ -4638,8 +4580,8 @@
   v97.x = x;
   v97.y = z;
   v113 = 0;
-  a4_8 = v4;
-  if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor)
+  a4_8 = stru_5C6E00->Atan2(v.x - x, v.y - z);
+  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
   {
     Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v97, &pOut.x, &pOut.y, &outz);
     v45.z = v.z;
@@ -4662,9 +4604,7 @@
     v151 = v53;
     v119 = pOut.x;
     if ( pOut.x < outx )
-    {
       v123 = outx;
-    }
     else
     {
       v119 = outx;
@@ -4674,9 +4614,7 @@
     v56 = outy;
     v127 = pOut.y;
     if ( pOut.y < outy )
-    {
       v131 = outy;
-    }
     else
     {
       v127 = outy;
@@ -4686,79 +4624,69 @@
     v58 = outz;
     v135 = outz;
     if ( outz < v163 )
-    {
       v139 = v163;
-    }
     else
     {
       v135 = v163;
       v139 = outz;
     }
-    a5b = 0;
-    while ( !v114 )
+    
+    //while ( !v114 )
+    for ( a5b = 0; a5b < 2; a5b++ )
     {
       if ( a5b )
       {
-        v102 = v58;
-        v100 = v55;
-        v98 = v54;
+        v102 = outz;
+        v100 = pOut.y;
+        v98 = pOut.x;
       }
       else
       {
-        v102 = v57;
-        v100 = v56;
-        v98 = v51;
+        v102 = v163;
+        v100 = outy;
+        v98 = outx;
       }
       v59 = pIndoor->GetSector(v98, v100, v102);
-      v60 = pIndoor->pSectors;
-      v61 = 116 * v59;
-      sDepthb = 0;
-      for ( i = 116 * v59;
-            sDepthb < *(__int16 *)((char *)&pIndoor->pSectors->uNumWalls + v61)
-                    + 2 * *(__int16 *)((char *)&pIndoor->pSectors->uNumFloors + v61);
-            ++sDepthb )
+      //v60 = pIndoor->pSectors;
+      //v61 = 116 * v59;
+      //i = 116 * v59;
+      //for (sDepthb = 0; *(__int16 *)((char *)&pIndoor->pSectors->uNumWalls + v61)
+                    //+ 2 * *(__int16 *)((char *)&pIndoor->pSectors->uNumFloors + v61); ++sDepthb)
+      for ( sDepthb = 0; sDepthb < pIndoor->pSectors[v59].uNumFaces; ++sDepthb )
       {
-        v62 = &pIndoor->pFaces[(*(unsigned __int16 **)((char *)&v60->pWalls + v61))[sDepthb]];
-        if ( v62->Portal()
-          || v119 > v62->pBounding.x2
-          || v123 < v62->pBounding.x1
-          || v127 > v62->pBounding.y2
-          || v131 < v62->pBounding.y1
-          || v135 > v62->pBounding.z2
-          || v139 < v62->pBounding.z1
-          || (v63 = (unsigned __int64)(v143 * (signed __int64)v62->pFacePlane_old.vNormal.x) >> 16,
-              v64 = (unsigned __int64)(v151 * (signed __int64)v62->pFacePlane_old.vNormal.z) >> 16,
-              v65 = (unsigned __int64)(v147 * (signed __int64)v62->pFacePlane_old.vNormal.y) >> 16,
-              v20 = v63 + v64 + v65 == 0,
-              v66 = v63 + v64 + v65,
-              v107 = v63 + v64 + v65,
-              v20) )
-          goto LABEL_107;
-        v67 = outz * v62->pFacePlane_old.vNormal.z;
-        v68 = -(v62->pFacePlane_old.dist
-              + v67
-              + pOut.y * v62->pFacePlane_old.vNormal.y
-              + pOut.x * v62->pFacePlane_old.vNormal.x);
+        face = &pIndoor->pFaces[pIndoor->pSectors[v59].pFaceIDs[sDepthb]];// face = &pIndoor->pFaces[*(__int16 *)((char *)&pIndoor->pSectors->pWalls + v61)[sDepthb]]
+        v63 = fixpoint_mul(v143, face->pFacePlane_old.vNormal.x);
+        v64 = fixpoint_mul(v151, face->pFacePlane_old.vNormal.z);
+        v65 = fixpoint_mul(v147, face->pFacePlane_old.vNormal.y);
+        v20 = v63 + v64 + v65;
+        v66 = v63 + v64 + v65;
+        v107 = v63 + v64 + v65;
+        if ( face->Portal()
+          || v119 > face->pBounding.x2 || v123 < face->pBounding.x1
+          || v127 > face->pBounding.y2 || v131 < face->pBounding.y1
+          || v135 > face->pBounding.z2 || v139 < face->pBounding.z1
+          || !v20 )
+          continue;
+        v68 = -(face->pFacePlane_old.dist + pOut.x * face->pFacePlane_old.vNormal.x
+                                          + pOut.y * face->pFacePlane_old.vNormal.y
+                                          + outz * face->pFacePlane_old.vNormal.z);
         if ( v66 <= 0 )
         {
-          if ( v62->pFacePlane_old.dist
-             + v67
-             + pOut.y * v62->pFacePlane_old.vNormal.y
-             + pOut.x * v62->pFacePlane_old.vNormal.x < 0 )
-            goto LABEL_107;
+          if ( face->pFacePlane_old.dist + pOut.x * face->pFacePlane_old.vNormal.x
+                                         + pOut.y * face->pFacePlane_old.vNormal.y
+                                         + outz * face->pFacePlane_old.vNormal.z < 0 )
+            continue;
         }
         else
         {
-          if ( v62->pFacePlane_old.dist
-             + v67
-             + pOut.y * v62->pFacePlane_old.vNormal.y
-             + pOut.x * v62->pFacePlane_old.vNormal.x > 0 )
-            goto LABEL_107;
+          if ( face->pFacePlane_old.dist + pOut.x * face->pFacePlane_old.vNormal.x
+                                         + pOut.y * face->pFacePlane_old.vNormal.y
+                                         + outz * face->pFacePlane_old.vNormal.z > 0 )
+            continue;
         }
-        v69 = abs(-(v62->pFacePlane_old.dist
-                  + v67
-                  + pOut.y * v62->pFacePlane_old.vNormal.y
-                  + pOut.x * v62->pFacePlane_old.vNormal.x)) >> 14;
+        v69 = abs(-(face->pFacePlane_old.dist + pOut.x * face->pFacePlane_old.vNormal.x
+                                              + pOut.y * face->pFacePlane_old.vNormal.y
+                                              + outz * face->pFacePlane_old.vNormal.z )) >> 14;
         if ( v69 <= abs(v66) )
         {
           //LODWORD(v70) = v68 << 16;
@@ -4768,30 +4696,17 @@
           v108 = fixpoint_div(v68, v107);
           if ( v108 >= 0 )
           {
-            if ( sub_4075DB(
-                   pOut.x + ((signed int)(fixpoint_mul(v108, v143) + 32768) >> 16),
-                   pOut.y + ((signed int)(fixpoint_mul(v108, v147) + 32768) >> 16),
-                   outz + ((signed int)(fixpoint_mul(v108, v151) + 32768) >> 16),
-                   v62) )
+            if ( sub_4075DB(pOut.x + ((signed int)(fixpoint_mul(v108, v143) + 0x8000) >> 16),
+                            pOut.y + ((signed int)(fixpoint_mul(v108, v147) + 0x8000) >> 16),
+                              outz + ((signed int)(fixpoint_mul(v108, v151) + 0x8000) >> 16),
+                            face) )
             {
               v114 = 1;
               break;
             }
           }
         }
-        v61 = i;
-LABEL_107:
-        v60 = pIndoor->pSectors;
       }
-      ++a5b;
-      if ( a5b >= 2 )
-        break;
-      v57 = v163;
-      v56 = outy;
-      v51 = outx;
-      v58 = outz;
-      v55 = pOut.y;
-      v54 = pOut.x;
     }
     v72.z = y;
     v72.x = x;
@@ -4817,9 +4732,7 @@
     v152 = v81;
     v120 = pOut.x;
     if ( pOut.x < outx )
-    {
       v124 = outx;
-    }
     else
     {
       v120 = outx;
@@ -4829,9 +4742,7 @@
     v84 = outy;
     v128 = pOut.y;
     if ( pOut.y < outy )
-    {
       v132 = outy;
-    }
     else
     {
       v128 = outy;
@@ -4841,93 +4752,74 @@
     v86 = outz;
     v136 = outz;
     if ( outz < v163 )
-    {
       v140 = v163;
-    }
     else
     {
       v136 = v163;
       v140 = outz;
     }
-    a5c = 0;
-    while ( 1 )
+    //while ( 1 )
+    for ( a5c = 0; a5c < 2; a5c++ )
     {
       if ( v113 )
         return !v114 || !v113;
       if ( a5c )
       {
-        v103 = v86;
-        v101 = v83;
-        v99 = v82;
+        v103 = outz;
+        v101 = pOut.y;
+        v99 = pOut.x;
       }
       else
       {
-        v103 = v85;
-        v101 = v84;
-        v99 = v79;
+        v103 = v163;
+        v101 = outy;
+        v99 = outx;
       }
       v87 = pIndoor->GetSector(v99, v101, v103);
-      v88 = pIndoor->pSectors;
-      v89 = 116 * v87;
-      v162 = 0;
-      v112 = v89;
-      if ( *(__int16 *)((char *)&pIndoor->pSectors->uNumWalls + v89)
-         + 2 * *(__int16 *)((char *)&pIndoor->pSectors->uNumFloors + v89) > 0 )
-        break;
-LABEL_148:
-      ++a5c;
-      if ( a5c >= 2 )
-        return !v114 || !v113;
-      v85 = v163;
-      v84 = outy;
-      v79 = outx;
-      v86 = outz;
-      v83 = pOut.y;
-      v82 = pOut.x;
-    }
-    while ( 1 )
+      //v88 = pIndoor->pSectors;
+      //v89 = 116 * v87;
+      
+      //v112 = v89;
+      //if ( *(__int16 *)((char *)&pIndoor->pSectors->uNumWalls + v89)
+         //+ 2 * *(__int16 *)((char *)&pIndoor->pSectors->uNumFloors + v89) > 0 )
+   //{
+    //while ( 1 )
+    for ( v162 = 0; v162 < pIndoor->pSectors[v87].uNumFaces; v162++)
     {
-      v90 = &pIndoor->pFaces[(*(unsigned __int16 **)((char *)&v88->pWalls + v89))[v162]];
-      if ( v90->Portal()
-        || v120 > v90->pBounding.x2
-        || v124 < v90->pBounding.x1
-        || v128 > v90->pBounding.y2
-        || v132 < v90->pBounding.y1
-        || v136 > v90->pBounding.z2
-        || v140 < v90->pBounding.z1
-        || (yb = fixpoint_mul(v144, v90->pFacePlane_old.vNormal.x),
-            v_4b = fixpoint_mul(v148, v90->pFacePlane_old.vNormal.y),
-            vf = fixpoint_mul(v152, v90->pFacePlane_old.vNormal.z),
-            v20 = yb + vf + v_4b == 0,
-            v91 = yb + vf + v_4b,
-            vc = yb + vf + v_4b,
-            v20) )
-        goto LABEL_145;
-      v92 = outz * v90->pFacePlane_old.vNormal.z;
-      v93 = -(v90->pFacePlane_old.dist
-            + v92
-            + pOut.y * v90->pFacePlane_old.vNormal.y
-            + pOut.x * v90->pFacePlane_old.vNormal.x);
+      face = &pIndoor->pFaces[pIndoor->pSectors[v87].pFaceIDs[v162]];
+      yb = fixpoint_mul(v144, face->pFacePlane_old.vNormal.x);
+      v_4b = fixpoint_mul(v148, face->pFacePlane_old.vNormal.y);
+      vf = fixpoint_mul(v152, face->pFacePlane_old.vNormal.z);
+      v20 = yb + vf + v_4b;
+      v91 = yb + vf + v_4b;
+      vc = yb + vf + v_4b;
+      if ( face->Portal()
+        || v120 > face->pBounding.x2 || v124 < face->pBounding.x1
+        || v128 > face->pBounding.y2 || v132 < face->pBounding.y1
+        || v136 > face->pBounding.z2 || v140 < face->pBounding.z1
+        || !v20 )
+        continue;
+      //v92 = outz * face->pFacePlane_old.vNormal.z;
+      v93 = -(face->pFacePlane_old.dist + pOut.x * face->pFacePlane_old.vNormal.x
+                                        + pOut.y * face->pFacePlane_old.vNormal.y
+                                        + outz * face->pFacePlane_old.vNormal.z);
       if ( v91 <= 0 )
       {
-        if ( v90->pFacePlane_old.dist
-           + v92
-           + pOut.y * v90->pFacePlane_old.vNormal.y
-           + pOut.x * v90->pFacePlane_old.vNormal.x < 0 )
-          goto LABEL_145;
+        if ( face->pFacePlane_old.dist + pOut.x * face->pFacePlane_old.vNormal.x
+                                       + pOut.y * face->pFacePlane_old.vNormal.y
+                                       + outz * face->pFacePlane_old.vNormal.z < 0 )
+          continue;
       }
       else
       {
-        if ( v90->pFacePlane_old.dist
-           + v92
-           + pOut.y * v90->pFacePlane_old.vNormal.y
-           + pOut.x * v90->pFacePlane_old.vNormal.x > 0 )
-          goto LABEL_145;
+        if ( face->pFacePlane_old.dist + pOut.x * face->pFacePlane_old.vNormal.x
+                                       + pOut.y * face->pFacePlane_old.vNormal.y
+                                       + outz * face->pFacePlane_old.vNormal.z > 0 )
+          continue;
       }
-      v_4c = abs(-(v90->pFacePlane_old.dist
-                 + v92
-                 + pOut.y * v90->pFacePlane_old.vNormal.y
-                 + pOut.x * v90->pFacePlane_old.vNormal.x)) >> 14;
+      v_4c = abs(-(face->pFacePlane_old.dist + pOut.x * face->pFacePlane_old.vNormal.x
+                                             + pOut.y * face->pFacePlane_old.vNormal.y
+                                             + outz * face->pFacePlane_old.vNormal.z)) >> 14;
       if ( v_4c <= abs(v91) )
       {
         //LODWORD(v94) = v93 << 16;
@@ -4937,288 +4829,235 @@
         vd = fixpoint_div(v93, vc);
         if ( vd >= 0 )
         {
-          if ( sub_4075DB(
-                 pOut.x + ((signed int)(fixpoint_mul(vd, v144) + 32768) >> 16),
-                 pOut.y + ((signed int)(fixpoint_mul(vd, v148) + 32768) >> 16),
-                 outz + ((signed int)(fixpoint_mul(vd, v152) + 32768) >> 16),
-                 v90) )
+          if ( sub_4075DB(pOut.x + ((signed int)(fixpoint_mul(vd, v144) + 0x8000) >> 16),
+                          pOut.y + ((signed int)(fixpoint_mul(vd, v148) + 0x8000) >> 16),
+                            outz + ((signed int)(fixpoint_mul(vd, v152) + 0x8000) >> 16),
+                          face) )
           {
             v113 = 1;
-            goto LABEL_148;
+            break;
           }
         }
       }
-      v89 = v112;
-LABEL_145:
-      v88 = pIndoor->pSectors;
-      ++v162;
-      if ( v162 >= *(__int16 *)((char *)&pIndoor->pSectors->uNumWalls + v89)
-                 + 2 * *(__int16 *)((char *)&pIndoor->pSectors->uNumFloors + v89) )
-        goto LABEL_148;
+      }
     }
   }
-  Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v97, &pOut.x, &pOut.y, &outz);
-  v5.z = v.z;
-  v5.x = v.x;
-  v5.y = v.y;
-  Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v5, &outx, &outy, &v163);
-  v6 = outy - pOut.y;
-  v7 = v163 - outz;
-  v8 = outx - pOut.x;
-  v9 = integer_sqrt(v8 * v8 + v6 * v6 + v7 * v7);
-  v10 = 65536;
-  if ( v9 )
-    v10 = 65536 / v9;
-  v125 = v8 * v10;
-  v11 = v10;
-  v12 = v7 * v10;
-  v13 = pOut.x;
-  v117 = v12;
-  v121 = v6 * v11;
-  v149 = pOut.x;
-  if ( pOut.x < outx )
-  {
-    v145 = outx;
-  }
-  else
+  else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
   {
-    v149 = outx;
-    v145 = pOut.x;
-  }
-  v14 = outy;
-  v141 = pOut.y;
-  if ( pOut.y < outy )
-  {
-    v137 = outy;
-  }
-  else
-  {
-    v141 = outy;
-    v137 = pOut.y;
-  }
-  v133 = outz;
-  if ( outz < v163 )
-  {
-    v129 = v163;
-  }
-  else
-  {
-    v133 = v163;
-    v129 = outz;
-  }
-  v160 = 0;
-  if ( (signed int)pOutdoor->uNumBModels > 0 )
-  {
-    v104 = 0;
-    while ( 1 )
+    Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v97, &pOut.x, &pOut.y, &outz);
+    v5.z = v.z;
+    v5.x = v.x;
+    v5.y = v.y;
+    Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v5, &outx, &outy, &v163);
+    v6 = outy - pOut.y;
+    v7 = v163 - outz;
+    v8 = outx - pOut.x;
+    v9 = integer_sqrt(v8 * v8 + v6 * v6 + v7 * v7);
+    v10 = 65536;
+    if ( v9 )
+      v10 = 65536 / v9;
+    v125 = v8 * v10;
+    v11 = v10;
+    v12 = v7 * v10;
+    v13 = pOut.x;
+    v117 = v12;
+    v121 = v6 * v11;
+    v149 = pOut.x;
+    if ( pOut.x < outx )
+      v145 = outx;
+    else
     {
-      v15 = (char *)&pOutdoor->pBModels[v104].pVertices;
-      a5 = (char *)&pOutdoor->pBModels[v104].pVertices;
-      if ( sub_4088E9(v13, pOut.y, outx, v14, pOutdoor->pBModels[v104].vPosition.x, pOutdoor->pBModels[v104].vPosition.y) <= pOutdoor->pBModels[v104].sBoundingRadius + 128 )
+      v149 = outx;
+      v145 = pOut.x;
+    }
+    v14 = outy;
+    v141 = pOut.y;
+    if ( pOut.y < outy )
+      v137 = outy;
+    else
+    {
+      v141 = outy;
+      v137 = pOut.y;
+    }
+    v133 = outz;
+    if ( outz < v163 )
+      v129 = v163;
+    else
+    {
+      v133 = v163;
+      v129 = outz;
+    }
+    for ( uint model_id = 0; model_id < pOutdoor->uNumBModels; model_id++)
+    {
+      if ( sub_4088E9(pOut.x, pOut.y, outx, outy, pOutdoor->pBModels[model_id].vPosition.x, pOutdoor->pBModels[model_id].vPosition.y)
+           <= pOutdoor->pBModels[model_id].sBoundingRadius + 128 )
       {
-        sDepth = 0;
-        if ( *((int *)v15 + 2) > 0 )
-          break;
-      }
-LABEL_36:
-      ++v160;
-      ++v104;
-      if ( v160 >= (signed int)pOutdoor->uNumBModels )
-        goto LABEL_37;
-      v14 = outy;
-      v13 = pOut.x;
-    }
-    v106 = 0;
-    while ( 1 )
-    {
-      v16 = (ODMFace *)(v106 + *((int *)a5 + 4));
-      if ( v149 > v16->pBoundingBox.x2
-        || v145 < v16->pBoundingBox.x1
-        || v141 > v16->pBoundingBox.y2
-        || v137 < v16->pBoundingBox.y1
-        || v133 > v16->pBoundingBox.z2
-        || v129 < v16->pBoundingBox.z1
-        || (v17 = fixpoint_mul(v125, v16->pFacePlane.vNormal.x),
-            v18 = fixpoint_mul(v121, v16->pFacePlane.vNormal.y),
-            v19 = fixpoint_mul(v117, v16->pFacePlane.vNormal.z),
-            v20 = v17 + v18 + v19 == 0,
-            v21 = v17 + v18 + v19,
-            v109 = v17 + v18 + v19,
-            v20) )
-        goto LABEL_33;
-      v22 = pOut.y * v16->pFacePlane.vNormal.y;
-      v23 = -(v16->pFacePlane.dist + v22 + outz * v16->pFacePlane.vNormal.z + pOut.x * v16->pFacePlane.vNormal.x);
-      if ( v21 <= 0 )
-      {
-        if ( v16->pFacePlane.dist + v22 + outz * v16->pFacePlane.vNormal.z + pOut.x * v16->pFacePlane.vNormal.x < 0 )
-          goto LABEL_33;
-      }
-      else
-      {
-        if ( v16->pFacePlane.dist + v22 + outz * v16->pFacePlane.vNormal.z + pOut.x * v16->pFacePlane.vNormal.x > 0 )
-          goto LABEL_33;
-      }
-      v24 = abs(-(v16->pFacePlane.dist + v22 + outz * v16->pFacePlane.vNormal.z + pOut.x * v16->pFacePlane.vNormal.x)) >> 14;
-      if ( v24 <= abs(v21) )
-      {
-        //LODWORD(v25) = v23 << 16;
-        //HIDWORD(v25) = v23 >> 16;
-        //v26 = v25 / v109;
-        //v110 = v25 / v109;
-        v110 = fixpoint_div(v23, v109);
-        if ( v110 >= 0 )
+        for ( uint face_id = 0; face_id < pOutdoor->pBModels[model_id].uNumFaces; ++face_id )
         {
-          if ( sub_4077F1(
-                 pOut.x + ((signed int)(fixpoint_mul(v110, v125) + 32768) >> 16),
-                 pOut.y + ((signed int)(fixpoint_mul(v110, v121) + 32768) >> 16),
-                 outz + ((signed int)(fixpoint_mul(v110, v117) + 32768) >> 16),
-                 v16,
-                 (BSPVertexBuffer *)a5) )
+          odm_face = &pOutdoor->pBModels[model_id].pFaces[face_id];
+          v17 = fixpoint_mul(v125, odm_face->pFacePlane.vNormal.x);
+          v18 = fixpoint_mul(v121, odm_face->pFacePlane.vNormal.y);
+          v19 = fixpoint_mul(v117, odm_face->pFacePlane.vNormal.z);
+          v20 = v17 + v18 + v19;
+          v21 = v17 + v18 + v19;
+          v109 = v17 + v18 + v19;
+          if ( v149 > odm_face->pBoundingBox.x2 || v145 < odm_face->pBoundingBox.x1
+            || v141 > odm_face->pBoundingBox.y2 || v137 < odm_face->pBoundingBox.y1
+            || v133 > odm_face->pBoundingBox.z2 || v129 < odm_face->pBoundingBox.z1
+            || !v20 )
+            continue;
+          v23 = -(odm_face->pFacePlane.dist + pOut.x * odm_face->pFacePlane.vNormal.x
+                                            + pOut.y * odm_face->pFacePlane.vNormal.y
+                                            + outz * odm_face->pFacePlane.vNormal.z);
+          if ( v21 <= 0 )
+          {
+            if ( odm_face->pFacePlane.dist + pOut.x * odm_face->pFacePlane.vNormal.x
+                                           + pOut.y * odm_face->pFacePlane.vNormal.y 
+                                           + outz * odm_face->pFacePlane.vNormal.z < 0 )
+              continue;
+          }
+          else
           {
-            v114 = 1;
-            goto LABEL_36;
+            if ( odm_face->pFacePlane.dist + pOut.x * odm_face->pFacePlane.vNormal.x
+                                           + pOut.y * odm_face->pFacePlane.vNormal.y
+                                           + outz * odm_face->pFacePlane.vNormal.z > 0 )
+              continue;
+          }
+          v24 = abs(-(odm_face->pFacePlane.dist + pOut.x * odm_face->pFacePlane.vNormal.x
+                                                + pOut.y * odm_face->pFacePlane.vNormal.y 
+                                                + outz * odm_face->pFacePlane.vNormal.z)) >> 14;
+          if ( v24 <= abs(v21) )
+          {
+            //LODWORD(v25) = v23 << 16;
+            //HIDWORD(v25) = v23 >> 16;
+            //v26 = v25 / v109;
+            //v110 = v25 / v109;
+            v110 = fixpoint_div(v23, v109);
+            if ( v110 >= 0 )
+            {
+              if ( sub_4077F1(pOut.x + ((signed int)(fixpoint_mul(v110, v125) + 0x8000) >> 16),
+                              pOut.y + ((signed int)(fixpoint_mul(v110, v121) + 0x8000) >> 16),
+                                outz + ((signed int)(fixpoint_mul(v110, v117) + 0x8000) >> 16),
+                              odm_face,
+                              &pOutdoor->pBModels[model_id].pVertices) )
+              {
+                v114 = 1;
+                break;
+              }
+            }
           }
         }
       }
-LABEL_33:
-      ++sDepth;
-      v106 += 308;
-      if ( sDepth >= *((int *)a5 + 2) )
-        goto LABEL_36;
+    }
+    v27.z = y;
+    v27.x = x;
+    v27.y = z;
+    Vec3_int_::Rotate(32, a4_8 - stru_5C6E00->uIntegerHalfPi, 0, v27, &pOut.x, &pOut.y, &outz);
+    v28.z = v.z;
+    v28.x = v.x;
+    v28.y = v.y;
+    Vec3_int_::Rotate(32, a4_8 - stru_5C6E00->uIntegerHalfPi, 0, v28, &outx, &outy, &v163);
+    v29 = outy - pOut.y;
+    v30 = v163 - outz;
+    v31 = outx - pOut.x;
+    v32 = integer_sqrt(v31 * v31 + v29 * v29 + v30 * v30);
+    v33 = 65536;
+    if ( v32 )
+      v33 = 65536 / v32;
+    v126 = v31 * v33;
+    v34 = v33;
+    v35 = v30 * v33;
+    v36 = pOut.x;
+    v118 = v35;
+    v122 = v29 * v34;
+    v150 = pOut.x;
+    if ( pOut.x < outx )
+      v146 = outx;
+    else
+    {
+      v150 = outx;
+      v146 = pOut.x;
+    }
+    v37 = outy;
+    v142 = pOut.y;
+    if ( pOut.y < outy )
+      v138 = outy;
+    else
+    {
+      v142 = outy;
+      v138 = pOut.y;
+    }
+    v134 = outz;
+    if ( outz < v163 )
+      v130 = v163;
+    else
+    {
+      v134 = v163;
+      v130 = outz;
     }
-  }
-LABEL_37:
-  v27.z = y;
-  v27.x = x;
-  v27.y = z;
-  Vec3_int_::Rotate(32, a4_8 - stru_5C6E00->uIntegerHalfPi, 0, v27, &pOut.x, &pOut.y, &outz);
-  v28.z = v.z;
-  v28.x = v.x;
-  v28.y = v.y;
-  Vec3_int_::Rotate(32, a4_8 - stru_5C6E00->uIntegerHalfPi, 0, v28, &outx, &outy, &v163);
-  v29 = outy - pOut.y;
-  v30 = v163 - outz;
-  v31 = outx - pOut.x;
-  v32 = integer_sqrt(v31 * v31 + v29 * v29 + v30 * v30);
-  v33 = 65536;
-  if ( v32 )
-    v33 = 65536 / v32;
-  v126 = v31 * v33;
-  v34 = v33;
-  v35 = v30 * v33;
-  v36 = pOut.x;
-  v118 = v35;
-  v122 = v29 * v34;
-  v150 = pOut.x;
-  if ( pOut.x < outx )
-  {
-    v146 = outx;
-  }
-  else
-  {
-    v150 = outx;
-    v146 = pOut.x;
-  }
-  v37 = outy;
-  v142 = pOut.y;
-  if ( pOut.y < outy )
-  {
-    v138 = outy;
-  }
-  else
-  {
-    v142 = outy;
-    v138 = pOut.y;
-  }
-  v134 = outz;
-  if ( outz < v163 )
-  {
-    v130 = v163;
-  }
-  else
-  {
-    v134 = v163;
-    v130 = outz;
-  }
-  v161 = 0;
-  if ( (signed int)pOutdoor->uNumBModels > 0 )
-  {
-    v105 = 0;
-    while ( 1 )
+
+    for ( uint model_id = 0; model_id < (signed int)pOutdoor->uNumBModels; ++model_id )
     {
-      v38 = (char *)&pOutdoor->pBModels[v105].pVertices;
-      a5a = (char *)&pOutdoor->pBModels[v105].pVertices;
-      if ( sub_4088E9(v36, pOut.y, outx, v37, pOutdoor->pBModels[v105].vPosition.x, pOutdoor->pBModels[v105].vPosition.y) <= pOutdoor->pBModels[v105].sBoundingRadius + 128 )
+      if ( sub_4088E9(pOut.x, pOut.y, outx, outy, pOutdoor->pBModels[model_id].vPosition.x, pOutdoor->pBModels[model_id].vPosition.y)
+           <= pOutdoor->pBModels[model_id].sBoundingRadius + 128 )
       {
-        sDeptha = 0;
-        if ( *((int *)v38 + 2) > 0 )
-          break;
-      }
-LABEL_71:
-      ++v161;
-      ++v105;
-      if ( v161 >= (signed int)pOutdoor->uNumBModels )
-        return !v114 || !v113;
-      v37 = outy;
-      v36 = pOut.x;
-    }
-    v_8 = 0;
-    while ( 1 )
-    {
-      v39 = (ODMFace *)(v_8 + *((int *)a5a + 4));
-      if ( v150 > v39->pBoundingBox.x2
-        || v146 < v39->pBoundingBox.x1
-        || v142 > v39->pBoundingBox.y2
-        || v138 < v39->pBoundingBox.y1
-        || v134 > v39->pBoundingBox.z2
-        || v130 < v39->pBoundingBox.z1
-        || (ya = fixpoint_mul(v126, v39->pFacePlane.vNormal.x),
-            ve = fixpoint_mul(v122, v39->pFacePlane.vNormal.y),
-            v_4 = fixpoint_mul(v118, v39->pFacePlane.vNormal.z),
-            v20 = ya + ve + v_4 == 0,
-            v40 = ya + ve + v_4,
-            va = ya + ve + v_4,
-            v20) )
-        goto LABEL_68;
-      v41 = pOut.y * v39->pFacePlane.vNormal.y;
-      v42 = -(v39->pFacePlane.dist + v41 + outz * v39->pFacePlane.vNormal.z + pOut.x * v39->pFacePlane.vNormal.x);
-      if ( v40 <= 0 )
-      {
-        if ( v39->pFacePlane.dist + v41 + outz * v39->pFacePlane.vNormal.z + pOut.x * v39->pFacePlane.vNormal.x < 0 )
-          goto LABEL_68;
-      }
-      else
-      {
-        if ( v39->pFacePlane.dist + v41 + outz * v39->pFacePlane.vNormal.z + pOut.x * v39->pFacePlane.vNormal.x > 0 )
-          goto LABEL_68;
-      }
-      v_4a = abs(-(v39->pFacePlane.dist + v41 + outz * v39->pFacePlane.vNormal.z + pOut.x * v39->pFacePlane.vNormal.x)) >> 14;
-      if ( v_4a <= abs(v40) )
-      {
-        //LODWORD(v43) = v42 << 16;
-        //HIDWORD(v43) = v42 >> 16;
-        //vb = v43 / va;
-        vb = fixpoint_div(v42, va);
-        if ( vb >= 0 )
+        for ( uint face_id = 0; face_id < pOutdoor->pBModels[model_id].uNumFaces; ++face_id )
         {
-          if ( sub_4077F1(
-                 pOut.x + ((signed int)(fixpoint_mul(vb, v126) + 32768) >> 16),
-                 pOut.y + ((signed int)(fixpoint_mul(vb, v122) + 32768) >> 16),
-                 outz + ((signed int)(fixpoint_mul(vb, v118) + 32768) >> 16),
-                 v39,
-                 (BSPVertexBuffer *)a5a) )
+          odm_face = &pOutdoor->pBModels[model_id].pFaces[face_id];
+          ya = fixpoint_mul(v126, odm_face->pFacePlane.vNormal.x);
+          ve = fixpoint_mul(v122, odm_face->pFacePlane.vNormal.y);
+          v_4 = fixpoint_mul(v118, odm_face->pFacePlane.vNormal.z);
+          v20 = ya + ve + v_4;
+          v40 = ya + ve + v_4;
+          va = ya + ve + v_4;
+          if ( v150 > odm_face->pBoundingBox.x2 || v146 < odm_face->pBoundingBox.x1
+            || v142 > odm_face->pBoundingBox.y2 || v138 < odm_face->pBoundingBox.y1
+            || v134 > odm_face->pBoundingBox.z2 || v130 < odm_face->pBoundingBox.z1
+            || !v20 )
+            continue;
+          v42 = -(odm_face->pFacePlane.dist + pOut.x * odm_face->pFacePlane.vNormal.x
+                                            + pOut.y * odm_face->pFacePlane.vNormal.y
+                                            + outz * odm_face->pFacePlane.vNormal.z);
+          if ( v40 <= 0 )
+          {
+            if ( odm_face->pFacePlane.dist + pOut.x * odm_face->pFacePlane.vNormal.x
+                                           + pOut.y * odm_face->pFacePlane.vNormal.y 
+                                           + outz * odm_face->pFacePlane.vNormal.z  < 0 )
+              continue;
+          }
+          else
           {
-            v113 = 1;
-            goto LABEL_71;
+            if ( odm_face->pFacePlane.dist + pOut.x * odm_face->pFacePlane.vNormal.x
+                                           + pOut.y * odm_face->pFacePlane.vNormal.y 
+                                           + outz * odm_face->pFacePlane.vNormal.z  > 0 )
+              continue;
+          }
+          v_4a = abs(-(odm_face->pFacePlane.dist + pOut.x * odm_face->pFacePlane.vNormal.x
+                                                 + pOut.y * odm_face->pFacePlane.vNormal.y 
+                                                 + outz * odm_face->pFacePlane.vNormal.z )) >> 14;
+          if ( v_4a <= abs(v40) )
+          {
+            //LODWORD(v43) = v42 << 16;
+            //HIDWORD(v43) = v42 >> 16;
+            //vb = v43 / va;
+            vb = fixpoint_div(v42, va);
+            if ( vb >= 0 )
+            {
+              if ( sub_4077F1(pOut.x + ((signed int)(fixpoint_mul(vb, v126) + 0x8000) >> 16),
+                              pOut.y + ((signed int)(fixpoint_mul(vb, v122) + 0x8000) >> 16),
+                                outz + ((signed int)(fixpoint_mul(vb, v118) + 0x8000) >> 16),
+                              odm_face,
+                              &pOutdoor->pBModels[model_id].pVertices) )
+              {
+                v113 = 1;
+                break;
+               }
+            }
           }
         }
       }
-LABEL_68:
-      ++sDeptha;
-      v_8 += 308;
-      if ( sDeptha >= *((int *)a5a + 2) )
-        goto LABEL_71;
     }
+
   }
   return !v114 || !v113;
 }
@@ -5230,120 +5069,74 @@
   uNumVisibleNotEmptySectors = 0;
   for (uint i = 0; i < num_nodes; ++i)
   {
-      if (!uNumVisibleNotEmptySectors)
-      {
-        pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
-        continue;
-      }
-      
-      v6 = 0;
-        while (pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6] != nodes[i].uSectorID )
-        {
-          ++v6;
-          if ( v6 >= uNumVisibleNotEmptySectors)
-          {
-            pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
-          }
-        }
-
+    //if (!uNumVisibleNotEmptySectors)
+    //{
+      //pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
+      //continue;
+    //}
+    //v6 = 0;
+    //while (pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6] != nodes[i].uSectorID )
+    for ( uint j = 0; j < uNumVisibleNotEmptySectors; j++ )
+    {
+      //++v6;
+      if ( pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[j] == nodes[i].uSectorID)
+        break;
+    }
+    pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
   }
 }
 //----- (0046A334) --------------------------------------------------------
 char __fastcall DoInteractionWithTopmostZObject(int a1, int a2)
 {
-  int v2; // edx@1
-  BLVFace *v4; // eax@9
-  unsigned int v5; // ecx@9
-  unsigned __int16 v6; // ax@11
-  //ODMFace *v7; // eax@16
-  LevelDecoration *v8; // esi@19
-  __int16 v9; // ax@19
-  int v10; // eax@22
-  int v11; // ecx@22
-  int v12; // edi@23
-  Actor *v13; // esi@23
-  unsigned __int16 v14; // ax@23
-  unsigned __int16 v15; // ax@33
-  const char *v16; // eax@34
   int v17; // edi@36
-  int v18; // eax@36
-  ItemGen *v19; // esi@39
-  unsigned int v20; // eax@39
-  int v21; // ecx@40
-  std::string v22; // [sp-18h] [bp-2Ch]@5
-  const char *v23; // [sp-8h] [bp-1Ch]@5
-  int v24; // [sp-4h] [bp-18h]@5
-  char v25; // [sp+8h] [bp-Ch]@5
-  int v26; // [sp+Ch] [bp-8h]@1
-  int a3; // [sp+13h] [bp-1h]@5
-
-  v26 = a2;
-  v2 = a1;
+
+  v17 = PID_ID(a1);
   switch ( PID_TYPE(a1) )
   {
     case OBJECT_Item: // take the item
-      v17 = PID_ID(a1);
-      v26 = PID_ID(a1);
-      v18 = PID_ID(a1);
-      if ( pObjectList->pObjects[pSpriteObjects[v18].uObjectDescID].uFlags & 0x10
-        || v17 >= 1000
-        || !pSpriteObjects[v18].uObjectDescID )
+      if ( pObjectList->pObjects[pSpriteObjects[v17].uObjectDescID].uFlags & 0x10 || v17 >= 1000 || !pSpriteObjects[v17].uObjectDescID )
         return 1;
-      v19 = &pSpriteObjects[v18].stru_24;
-      v20 = pSpriteObjects[v18].stru_24.uItemID;
-      if ( pItemsTable->pItems[v20].uEquipType == EQUIP_GOLD)
+      if ( pItemsTable->pItems[pSpriteObjects[v17].stru_24.uItemID].uEquipType == EQUIP_GOLD)
       {
-        pParty->PartyFindsGold(v19->uSpecEnchantmentType, 0);
+        pParty->PartyFindsGold(pSpriteObjects[v17].stru_24.uSpecEnchantmentType, 0);
         viewparams->bRedrawGameUI = 1;
-        v21 = v17;
       }
       else
       {
         if ( pParty->pPickedItem.uItemID )
           return 1;
-        v24 = (int)pItemsTable->pItems[v20].pUnidentifiedName;
-        sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], v24);
-        ShowStatusBarString(pTmpBuf2.data(), 2u);
-        if ( v19->uItemID == 506 )
-          _449B7E_toggle_bit(pParty->_quest_bits, 184, 1u);
-        if ( v19->uItemID == 455 )
-          _449B7E_toggle_bit(pParty->_quest_bits, 185, 1u);
-        if ( !pParty->AddItemToParty(v19) )
-          pParty->SetHoldingItem(v19);
-        v21 = v26;
+        sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[pSpriteObjects[v17].stru_24.uItemID].pUnidentifiedName);//You found an item (%s)!
+        ShowStatusBarString(pTmpBuf2.data(), 2);
+        if ( pSpriteObjects[v17].stru_24.uItemID == 506 )//artefact
+          _449B7E_toggle_bit(pParty->_quest_bits, 184, 1);
+        if ( pSpriteObjects[v17].stru_24.uItemID == 455 )
+          _449B7E_toggle_bit(pParty->_quest_bits, 185, 1);
+        if ( !pParty->AddItemToParty(&pSpriteObjects[v17].stru_24) )
+          pParty->SetHoldingItem(&pSpriteObjects[v17].stru_24);
       }
-      SpriteObject::OnInteraction(v21);
+      SpriteObject::OnInteraction(v17);
       break;
 
     case OBJECT_Actor:
-      v12 = PID_ID(a1);
-      v13 = &pActors[PID_ID(a1)];
-      v14 = v13->uAIState;
-      if ( v14 == 4 || v14 == 17 )
+      if ( pActors[v17].uAIState == Dying || pActors[v17].uAIState == Summoned )
         return 1;
-      if ( v14 == 5 )
-      {
-        pActors[PID_ID(a1)].LootActor();
-      }
+      if ( pActors[v17].uAIState == Dead )
+        pActors[v17].LootActor();
       else
       {
-        if ( !v13->GetActorsRelation(0) && !(BYTE2(v13->uAttributes) & 8) && v13->CanAct() )
+        if ( !pActors[v17].GetActorsRelation(0) && !(pActors[v17].uAttributes & 0x80000) && pActors[v17].CanAct() )
         {
-          Actor::AI_FaceObject(v12, 4u, 0, 0);
-          if ( v13->sNPC_ID )
-          {
-            pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v12, 0);
-          }
+          Actor::AI_FaceObject(v17, 4, 0, 0);
+          if ( pActors[v17].sNPC_ID )
+            pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v17, 0);
           else
           {
-            v15 = pNPCStats->pGroups_copy[v13->uGroup];
-            if ( v15 )
+            if ( pNPCStats->pGroups_copy[pActors[v17].uGroup] )
             {
-              v16 = pNPCStats->pCatchPhrases[v15];
-              if ( v16 )
+              if ( pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[v17].uGroup]] )
               {
-                pParty->uFlags |= 2u;
-                strcpy(byte_5B0938.data(), v16);
+                pParty->uFlags |= 2;
+                strcpy(byte_5B0938.data(), pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[v17].uGroup]]);
                 sub_4451A8_press_any_key(0, 0, 0);
               }
             }
@@ -5353,22 +5146,17 @@
       break;
 
     case OBJECT_Decoration:
-      v8 = &pLevelDecorations[PID_ID(a1)];
-      v9 = v8->uEventID;
-      if ( v9 )
+      if ( pLevelDecorations[v17].uEventID )
       {
-        EventProcessor(v9, a1, 1);
-        v8->uFlags |= LEVEL_DECORATION_VISIBLE_ON_MAP;
+        EventProcessor(pLevelDecorations[v17].uEventID, a1, 1);
+        pLevelDecorations[v17].uFlags |= LEVEL_DECORATION_VISIBLE_ON_MAP;
       }
       else
       {
-        if ( !pLevelDecorations[PID_ID(a1)].IsInteractive() )
+        if ( !pLevelDecorations[v17].IsInteractive() )
           return 1;
-        v10 = v8->_idx_in_stru123;
-        v24 = 1;
-        v11 = stru_5E4C90_MapPersistVars._decor_events[v10 - 75] + 380;
-        activeLevelDecoration = v8;
-        EventProcessor(v11, 0, 1);
+        activeLevelDecoration = &pLevelDecorations[v17];
+        EventProcessor(stru_5E4C90_MapPersistVars._decor_events[pLevelDecorations[v17]._idx_in_stru123 - 75] + 380, 0, 1);
         activeLevelDecoration = NULL;
       }
       break;
@@ -5381,27 +5169,25 @@
       if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
       {
         int bmodel_id = a1 >> 9,
-            face_id = PID_ID(a1) & 0x3F;
+            face_id = v17 & 0x3F;
         if (bmodel_id >= pOutdoor->uNumBModels)
           return 1;
-        ODMFace* face = &pOutdoor->pBModels[bmodel_id].pFaces[face_id];
-        if (face->uAttributes & 0x100000 || face->sCogTriggeredID == 0 )
+        if (pOutdoor->pBModels[bmodel_id].pFaces[face_id].uAttributes & FACE_UNKNOW 
+         || pOutdoor->pBModels[bmodel_id].pFaces[face_id].sCogTriggeredID == 0 )
           return 1;
-        EventProcessor((signed __int16)face->sCogTriggeredID, v2, 1);
+        EventProcessor((signed __int16)pOutdoor->pBModels[bmodel_id].pFaces[face_id].sCogTriggeredID, a1, 1);
       }
       else
       {
-        v4 = &pIndoor->pFaces[PID_ID(a1)];
-        v5 = v4->uAttributes;
-        if ( !(v5 & 0x2000000) )
+        if ( !(pIndoor->pFaces[v17].uAttributes & FACE_CLICKABLE) )
         {
           ShowNothingHereStatus();
           return 1;
         }
-        if ( v5 & 0x100000 || (v6 = pIndoor->pFaceExtras[v4->uFaceExtraID].uEventID) == 0 )
+        if ( pIndoor->pFaces[v17].uAttributes & FACE_UNKNOW || !pIndoor->pFaceExtras[pIndoor->pFaces[v17].uFaceExtraID].uEventID )
           return 1;
         if ( pCurrentScreen != SCREEN_BRANCHLESS_NPC_DIALOG )
-          EventProcessor((signed __int16)v6, v2, 1);
+          EventProcessor((signed __int16)pIndoor->pFaceExtras[pIndoor->pFaces[v17].uFaceExtraID].uEventID, a1, 1);
       }
       return 0;
       break;
@@ -6196,7 +5982,7 @@
   int v80; // [sp+34h] [bp-2Ch]@1
   int v82; // [sp+3Ch] [bp-24h]@47
   int _view_angle; // [sp+40h] [bp-20h]@47
-  bool bJumping; // [sp+44h] [bp-1Ch]@1
+  bool hovering; // [sp+44h] [bp-1Ch]@1
   int new_party_y; // [sp+48h] [bp-18h]@1
   int new_party_x; // [sp+4Ch] [bp-14h]@1
   int party_z; // [sp+50h] [bp-10h]@1
@@ -6212,12 +5998,12 @@
   uSectorID = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
   party_running_flag = false;
   party_walking_flag = false;
-  bJumping = false;
+  hovering = false;
 
   uFaceID = -1;
-  int floor_level = collide_against_floor(new_party_x, new_party_y, party_z + 40, &uSectorID, &uFaceID);
-
-  if ( pParty->bFlying )
+  int floor_level = collide_against_floor(new_party_x, new_party_y, party_z + 40, &uSectorID, &uFaceID);//получить высоту пола
+
+  if ( pParty->bFlying )//отключить полёт
   {
     pParty->bFlying = false;
     if (pParty->FlyActive())
@@ -6258,8 +6044,8 @@
     }
   }
 
-  uint fall_start;
-  if (!pParty->FeatherFallActive())
+  int fall_start;
+  if (!pParty->FeatherFallActive())// не активно падение пера
   {
     bFeatherFall = false;
     if (!pParty->pPlayers[0].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT) &&  // grants feather fall
@@ -6270,7 +6056,7 @@
       fall_start = pParty->uFallStartY;
     }
   }
-  else
+  else// активно падение пера
   {
     fall_start = floor_level;
     bFeatherFall = true;
@@ -6278,7 +6064,7 @@
   }
 
 
-  if (fall_start - party_z > 512 && !bFeatherFall && party_z <= floor_level + 1)
+  if (fall_start - party_z > 512 && !bFeatherFall && party_z <= floor_level + 1)//повреждение от падения с высоты
   {
     assert(~pParty->uFlags & PARTY_FLAGS_1_LANDING); // why land in indoor?
     if (pParty->uFlags & PARTY_FLAGS_1_LANDING)
@@ -6295,40 +6081,39 @@
   }
 
   if ( party_z > floor_level + 1 )
-    bJumping = true;
-
-  bool jumping_up = false;
+    hovering = true;
+
+  bool not_high_fall = false;
 
   if ( party_z - floor_level <= 32 )
   {
     pParty->uFallStartY = party_z;
-    jumping_up = true;
+    not_high_fall = true;
   }
 
-  if (bWalkSound && pParty->walk_sound_timer)
+  if (bWalkSound && pParty->walk_sound_timer)//таймеры для звуков передвижения
   {
     if (pParty->walk_sound_timer > pEventTimer->uTimeElapsed)
       pParty->walk_sound_timer -= pEventTimer->uTimeElapsed;
     else pParty->walk_sound_timer = 0;
   }
 
-
-  if (party_z <= floor_level + 1)
+  if (party_z <= floor_level + 1)// группа ниже уровня пола
   {
     party_z = floor_level + 1;
     pParty->uFallStartY = floor_level + 1;
 
-    if (!bJumping && pParty->floor_face_pid != uFaceID)
+    if (!hovering && pParty->floor_face_pid != uFaceID)// не парящие и 
     {
       if (pIndoor->pFaces[uFaceID].uAttributes & FACE_PRESSURE_PLATE)
         uFaceEvent = pIndoor->pFaceExtras[pIndoor->pFaces[uFaceID].uFaceExtraID].uEventID;
     }
   }
-  if (!bJumping)
+  if (!hovering)
     pParty->floor_face_pid = uFaceID;
 
   bool on_water = false;
-  if ( pIndoor->pFaces[uFaceID].Fluid())
+  if ( pIndoor->pFaces[uFaceID].Fluid())// на воде
     on_water = true;
 
   //v81 = pParty->uWalkSpeed;
@@ -6387,7 +6172,7 @@
         v1 -= fixpoint_mul(stru_5C6E00->Sin(angle), pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier);
         party_walking_flag = true;
         break;
-      case PARTY_RunForward:
+      case PARTY_RunForward://Бег вперёд
         v2 += fixpoint_mul(stru_5C6E00->Cos(angle), 2 * pParty->uWalkSpeed * fWalkSpeedMultiplier);
         v1 += fixpoint_mul(stru_5C6E00->Sin(angle), 2 * pParty->uWalkSpeed * fWalkSpeedMultiplier);
         party_running_flag = true;
@@ -6419,9 +6204,9 @@
         _view_angle = 0;
         break;
       case PARTY_Jump:
-        if ( (!bJumping || party_z <= floor_level + 6 && pParty->uFallSpeed <= 0) && pParty->field_24 )
+        if ( (!hovering || party_z <= floor_level + 6 && pParty->uFallSpeed <= 0) && pParty->field_24 )
         {
-          bJumping = true;
+          hovering = true;
           pParty->uFallSpeed = (signed __int64)((double)(pParty->field_24 << 6) * 1.5 + (double)pParty->uFallSpeed);
         }
         break;
@@ -6431,17 +6216,16 @@
   }
   pParty->sRotationY = angle;
   pParty->sRotationX = _view_angle;
-  if ( bJumping )
+  if ( hovering )//парящие
   {
-    pParty->uFallSpeed += -2 * pEventTimer->uTimeElapsed * GetGravityStrength();
-    if ( bJumping && pParty->uFallSpeed <= 0 )
+    pParty->uFallSpeed += -2 * pEventTimer->uTimeElapsed * GetGravityStrength();// расчёт скорости падения
+    if ( hovering && pParty->uFallSpeed <= 0 )
     {
       if ( pParty->uFallSpeed < -500 && !pParty->bFlying )
       {
         for ( uint pl = 1; pl <= 4; pl++ )
         {
-          if ( !pPlayers[pl]->HasEnchantedItemEquipped(72)
-            && !pPlayers[pl]->WearsItem(ITEM_ARTIFACT_HERMES_SANDALS, EQUIP_BOOTS) ) //was 8 
+          if ( !pPlayers[pl]->HasEnchantedItemEquipped(72) && !pPlayers[pl]->WearsItem(ITEM_ARTIFACT_HERMES_SANDALS, EQUIP_BOOTS) ) //was 8 
              pPlayers[pl]->PlayEmotion(CHARACTER_EXPRESSION_SCARED, 0);
         }
       }
@@ -6449,9 +6233,9 @@
     else
       pParty->uFallStartY = party_z;
   }
-  else
+  else// не парящие
   {
-    if ( pIndoor->pFaces[uFaceID].pFacePlane_old.vNormal.z < 32768 )
+    if ( pIndoor->pFaces[uFaceID].pFacePlane_old.vNormal.z < 0x8000 )
     {
       pParty->uFallSpeed -= pEventTimer->uTimeElapsed * GetGravityStrength();
       pParty->uFallStartY = party_z;
@@ -6499,10 +6283,10 @@
     for ( uint j = 0; j < 100; ++j )
     {
       _46E44E_collide_against_faces_and_portals(1);
-      _46E0B2_collide_against_decorations();
+      _46E0B2_collide_against_decorations();//столкновения с декором
       for ( v80 = 0; v80 < (signed int)uNumActors; ++v80 )
-        Actor::_46DF1A_collide_against_actor(v80, 0);
-      if ( _46F04E_collide_against_portals() )
+        Actor::_46DF1A_collide_against_actor(v80, 0);//столкновения с монстрами
+      if ( _46F04E_collide_against_portals() )//столкновения с порталами
         break;
     }
     if ( stru_721530.field_7C >= stru_721530.field_6C )
@@ -6520,7 +6304,7 @@
     v42 = collide_against_floor(v39, uSectorID, v40 + 40, &stru_721530.uSectorID, &uFaceID);
     if ( v42 == -30000 || v42 - new_party_z > 128 )
       return;
-    if ( stru_721530.field_7C >= stru_721530.field_6C )
+    if ( stru_721530.field_7C >= stru_721530.field_6C )//???
     {
       new_party_x = stru_721530.normal2.x;
       new_party_y = stru_721530.normal2.y;
@@ -6532,24 +6316,23 @@
     uSectorID = stru_721530.uSectorID;
     stru_721530.field_70 += stru_721530.field_7C;
     unsigned long long v87 = new_party_z + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z);
-    if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Actor)
+    if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Actor)//при столкновении с монстром
     {
-      if ( SHIDWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime) >= 0
-        && (SHIDWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime) > 0 || LODWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime)) )
+      if ( pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime > 0 )
         pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
       viewparams->bRedrawGameUI = true;
     }
-    else if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Decoration)
+    else if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Decoration)//при столкновении с декорацией
     {
       v54 = stru_5C6E00->Atan2(new_party_x - pLevelDecorations[stru_721530.uFaceID >> 3].vPosition.x,
               new_party_y - pLevelDecorations[stru_721530.uFaceID >> 3].vPosition.y);
       v2 = fixpoint_mul(stru_5C6E00->Cos(v54), integer_sqrt(v2 * v2 + v1 * v1));
       v1 = fixpoint_mul(stru_5C6E00->Sin(v54), integer_sqrt(v2 * v2 + v1 * v1));
     }
-    else if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_BModel)
+    else if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_BModel)//при столкновении с bmodel
     {
       pFace = &pIndoor->pFaces[(signed int)stru_721530.uFaceID >> 3];
-      if ( pFace->uPolygonType == POLYGON_Floor )
+      if ( pFace->uPolygonType == POLYGON_Floor )// если bmodel - пол
       {
         if ( pParty->uFallSpeed < 0 )
           pParty->uFallSpeed = 0;
@@ -6564,10 +6347,10 @@
         if ( pParty->floor_face_pid != PID_ID(stru_721530.uFaceID) && pFace->Pressure_Plate() )
           uFaceEvent = pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID;
       }
-      else
+      else// если не пол
       {
         v46 = pParty->uFallSpeed * pFace->pFacePlane_old.vNormal.z;
-        if ( pFace->uPolygonType != POLYGON_InBetweenFloorAndWall )
+        if ( pFace->uPolygonType != POLYGON_InBetweenFloorAndWall )//полез на холм
         {
           v80 = abs(v1 * pFace->pFacePlane_old.vNormal.y + v46 + v2 * pFace->pFacePlane_old.vNormal.x) >> 16;
           if ((stru_721530.speed >> 3) > v80 )
@@ -6617,13 +6400,13 @@
   }
 
   //  //Воспроизведение звуков ходьбы/бега-------------------------
-  uint pX_ = pParty->vPosition.x - new_party_x;
-  uint pY_ = pParty->vPosition.y - new_party_y;
-  uint pZ_ = pParty->vPosition.z - new_party_z;
+  uint pX_ = abs(pParty->vPosition.x - new_party_x);
+  uint pY_ = abs(pParty->vPosition.y - new_party_y);
+  uint pZ_ = abs(pParty->vPosition.z - new_party_z);
   if ( bWalkSound && pParty->walk_sound_timer <= 0 )
   {
     pAudioPlayer->_4AA258(804);//stop sound
-    if ( party_running_flag && (!bJumping || jumping_up) ) //для бега
+    if ( party_running_flag && (!hovering || not_high_fall) ) //Бег и (не прыжок или не высокое падение )
     {
       if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) >= 16 )
       {
@@ -6633,10 +6416,10 @@
           pAudioPlayer->PlaySound((SoundID)50, 804, 1, -1, 0, 0, 0, 0);
         else
           pAudioPlayer->PlaySound(SOUND_RunAlong3DModel, 804, 1, -1, 0, 0, 0, 0);
-        pParty->walk_sound_timer = 64;
+        pParty->walk_sound_timer = 96;//64
       }
     }
-    else if ( party_walking_flag && (!bJumping || jumping_up) )//для ходьбы
+    else if ( party_walking_flag && (!hovering || not_high_fall) )//Ходьба и (не прыжок или не высокое падение)
     {
       if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) >= 8 )
       {
@@ -6646,14 +6429,14 @@
           pAudioPlayer->PlaySound((SoundID)89, 804, 1, -1, 0, 0, 0, 0);
         else
           pAudioPlayer->PlaySound(SOUND_WalkAlong3DModel, 804, 1, -1, 0, 0, 0, 0);
-        pParty->walk_sound_timer = 64;
+        pParty->walk_sound_timer = 144;//64
       }
     }
   }
   if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) < 8 )//отключить  звук ходьбы при остановке
     pAudioPlayer->_4AA258(804);
   //-------------------------------------------------------------
-  if ( !bJumping || jumping_up )
+  if ( !hovering || !not_high_fall )
     pParty->uFlags &= ~PARTY_FLAGS_1_FALLING;
   else
     pParty->uFlags |= PARTY_FLAGS_1_FALLING;
@@ -6662,7 +6445,7 @@
   pParty->vPosition.z = new_party_z;
   pParty->vPosition.y = new_party_y;
   //pParty->uFallSpeed = v89;
-  if ( !bJumping && pIndoor->pFaces[uFaceID].uAttributes & FACE_UNKNOW5 )
+  if ( !hovering && pIndoor->pFaces[uFaceID].uAttributes & FACE_UNKNOW5 )
     pParty->uFlags |= 0x200;
   if (uFaceEvent)
     EventProcessor(uFaceEvent, 0, 1);
--- a/IndoorCameraD3D.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/IndoorCameraD3D.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -166,12 +166,9 @@
          - (unsigned __int64)(to_y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y);
     //}
     a3a = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-    a2b = (unsigned __int64)(to_z * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-    //v10 = pOutX;
-    *pOutX = ((unsigned __int64)(v14 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16) - a2b;
+    *pOutX = fixpoint_mul(v14, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(to_z, pGame->pIndoorCameraD3D->int_sine_x);
     *pOutZ = v9;
-    *pOutY = ((unsigned __int64)(v14 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16)
-           + ((unsigned __int64)(a3a * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16);
+    *pOutY = fixpoint_mul(v14, pGame->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(a3a, pGame->pIndoorCameraD3D->int_cosine_x);
   }
   else
   {
--- a/LOD.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/LOD.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -512,7 +512,7 @@
   int v75; // [sp+48h] [bp-14h]@4
   int v76; // [sp+48h] [bp-14h]@22
   int v77; // [sp+48h] [bp-14h]@59
-  LODSprite *v78; // [sp+4Ch] [bp-10h]@1
+  //LODSprite *v78; // [sp+4Ch] [bp-10h]@1
   int v79; // [sp+50h] [bp-Ch]@4
   int v80; // [sp+50h] [bp-Ch]@21
   int v81; // [sp+50h] [bp-Ch]@62
@@ -526,7 +526,7 @@
   int v89; // [sp+68h] [bp+Ch]@56
 
   v3 = a2;
-  v78 = this;
+  //v78 = this;
   result = a2->_screenspace_x_scaler_packedfloat;
   v58 = a2->_screenspace_x_scaler_packedfloat;
   if ( result <= 0 )
@@ -547,14 +547,14 @@
   auto pTarget = (unsigned __int16 *)v3->pTarget;
   v57 = v3->sZValue;
   v61 = v3->pPalette;
-  v9 = (v6 * this->uWidth + 32768) >> 16;
+  v9 = (v6 * this->uWidth + 0x8000) >> 16;
   v72 = v3->uScreenSpaceY;
-  result = (v5 * v7 + 32768) >> 16;
+  result = (v5 * v7 + 0x8000) >> 16;
   v10 = (int *)(v72 - result + 1);
   v11 = v3->uScreenSpaceX - (v9 >> 1) + 1;
   v65 = v72 - result + 1;
   v59 = v11 + v9 - 1;
-  if ( BYTE1(v3->uFlags) & 8 )
+  if ( v3->uFlags & 0x800 )
   {
     v10 = (int *)((char *)v10 + (v49 >> 1));
     v72 += v49 >> 1;
@@ -607,7 +607,7 @@
     while ( 1 )
     {
       v35 = v71 >> 16;
-      v36 = LOWORD(v78->pSpriteLines[v35].dword_0);
+      v36 = LOWORD(this->pSpriteLines[v35].dword_0);
       if ( v36 == -1 )
       {
         v34 -= v69;
@@ -615,23 +615,20 @@
         goto LABEL_84;
       }
       v37 = v9 - ((unsigned __int64)(v36 * (signed __int64)v58) >> 16);
-      v67 = v87 * ((unsigned __int64)(LOWORD(v78->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16);
+      v67 = v87 * ((unsigned __int64)(LOWORD(this->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16);
       v38 = v9 - v60;
       v77 = v9 - v60;
-      if ( v9 - v60 <= (signed int)(v9
-                                  - ((unsigned __int64)(HIWORD(v78->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16))
+      if ( v9 - v60 <= (signed int)(v9 - ((unsigned __int64)(HIWORD(this->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16))
         || v68 >= v37 )
       {
         v89 -= v69;
         v34 = v89;
 LABEL_84:
-        v86 -= 640;
+        v86 -= window->GetWidth();
         goto LABEL_85;
       }
       if ( v38 < v37 )
-      {
         v81 = (v87 >> 1) + v87 * (v37 - v38);
-      }
       else
       {
         v77 = v37;
@@ -640,15 +637,15 @@
         v89 += v39 + v60;
         v86 += v60 + v39;
       }
-      v40 = ((HIWORD(v78->pSpriteLines[v35].dword_0) + 1) << 16) - v81 - v67;
+      v40 = ((HIWORD(this->pSpriteLines[v35].dword_0) + 1) << 16) - v81 - v67;
       LODWORD(v41) = v40 << 16;
       HIDWORD(v41) = v40 >> 16;
-      v42 = v77 - (((signed int)((unsigned __int64)(v41 / v48) - 32768) >> 16) + 1);
+      v42 = v77 - (((signed int)((unsigned __int64)(v41 / v48) - 0x8000) >> 16) + 1);
       if ( v68 >= v42 )
         v42 = v68;
       v43 = &pTarget[v89];
       v74 = &v43[v42 - v77 + 1];
-      v44 = &v78->pSpriteLines[v35];
+      v44 = &this->pSpriteLines[v35];
       v64 = v44->ptr_4;
       if ( !v57 )
       {
@@ -661,7 +658,7 @@
         }
         while ( v43 >= v74 )
         {
-          v46 = (v83 - ((signed int)LOWORD(v78->pSpriteLines[v35].dword_0) << 16)) >> 16;
+          v46 = (v83 - ((signed int)LOWORD(this->pSpriteLines[v35].dword_0) << 16)) >> 16;
           if ( *((char *)v64 + v46) )
             *v43 = v61[*((char *)v64 + v46)];
           v83 += v87;
@@ -679,7 +676,7 @@
 LABEL_81:
       v89 += v9 - v77 - v60 - v69;
       v34 = v89;
-      v86 = v86 + v9 - v77 - v60 - 640;
+      v86 = v86 + v9 - v77 - v60 - window->GetWidth();
 LABEL_85:
       result = v52;
       v71 += v52;
@@ -687,7 +684,7 @@
       if ( !v51 )
         return result;
     }
-    v45 = (v82 - ((signed int)LOWORD(v78->pSpriteLines[v35].dword_0) << 16)) >> 16;
+    v45 = (v82 - ((signed int)LOWORD(this->pSpriteLines[v35].dword_0) << 16)) >> 16;
     v56 = *((char *)v64 + v45);
     if ( *((char *)v64 + v45) && v57 <= (unsigned int)*pTargetZ )
     {
@@ -709,12 +706,12 @@
     v50 = result - (int)v16 + 1;
     while ( 1 )
     {
-      v20 = &v78->pSpriteLines[v71 >> 16];
+      v20 = &this->pSpriteLines[v71 >> 16];
       v80 = v71 >> 16;
       if ( LOWORD(v20->dword_0) != -1 )
         break;
       v18 -= v69;
-      v85 = v19 - 640;
+      v85 = v19 - window->GetWidth();
       v88 = v18;
 LABEL_54:
       result = v52;
@@ -732,7 +729,7 @@
     if ( v68 >= (v58 * v54 + 32768) >> 16 || v22 <= v21 )
     {
       v88 -= v69;
-      v85 -= 640;
+      v85 -= window->GetWidth();
       goto LABEL_51;
     }
     if ( v68 > v21 )
@@ -741,7 +738,7 @@
     }
     else
     {
-      v76 = (v58 * LOWORD(v20->dword_0) + 32768) >> 16;
+      v76 = (v58 * LOWORD(v20->dword_0) + 0x8000) >> 16;
       v23 = v21 - v68;
       v88 += v23;
       v24 = v87 >> 1;
@@ -754,7 +751,7 @@
       v22 = v26;
     v27 = &pTarget[v88];
     v73 = &v27[v22 - v76 - 1];
-    v28 = &v78->pSpriteLines[v80];
+    v28 = &this->pSpriteLines[v80];
     v63 = v28->ptr_4;
     if ( v57 )
     {
@@ -778,7 +775,7 @@
         }
       }
       v30 = v29 >> 16;
-      if ( v30 > HIWORD(v78->pSpriteLines[v80].dword_0) - (signed int)LOWORD(v78->pSpriteLines[v80].dword_0)
+      if ( v30 > HIWORD(this->pSpriteLines[v80].dword_0) - (signed int)LOWORD(this->pSpriteLines[v80].dword_0)
         || (v31 = *((char *)v63 + v30)) == 0
         || v57 > (unsigned int)*pTargetZ )
         goto LABEL_50;
@@ -801,14 +798,14 @@
         ++v27;
       }
       v33 = v32 >> 16;
-      if ( v33 > HIWORD(v78->pSpriteLines[v80].dword_0) - (signed int)LOWORD(v78->pSpriteLines[v80].dword_0)
+      if ( v33 > HIWORD(this->pSpriteLines[v80].dword_0) - (signed int)LOWORD(this->pSpriteLines[v80].dword_0)
         || (v31 = *((char *)v63 + v33)) == 0 )
         goto LABEL_50;
     }
     *v27 = v61[v31];
 LABEL_50:
     v88 += v68 - v76 - v69;
-    v85 = v85 + v68 - v76 - 640;
+    v85 = v85 + v68 - v76 - window->GetWidth();
 LABEL_51:
     v18 = v88;
     goto LABEL_54;
@@ -1374,7 +1371,7 @@
 
 
 //----- (004621A7) --------------------------------------------------------
-bool LODWriteableFile::_4621A7()
+bool LODWriteableFile::_4621A7()//закрыть и загрузить записываемый ф-л(при сохранении)
 {
   CloseWriteFile();
   return LoadFile(pLODName, 0);
@@ -1383,72 +1380,70 @@
 //----- (00461FD4) ---LODFile_sub_461FD4---text:004632EA  --------------------------------------------------
 int LODWriteableFile::FixDirectoryOffsets()
 {
-    int total_size; // edi@1
-    int temp_offset; // ecx@5
-    FILE *tmp_file; // eax@9
-    size_t write_size; // edi@12
-    int result;
-    char Filename[256]; // [sp+Ch] [bp-228h]@9
-    char NewFilename[256]; // [sp+10Ch] [bp-128h]@15
-    int i;
+  int total_size; // edi@1
+  int temp_offset; // ecx@5
+  FILE *tmp_file; // eax@9
+  size_t write_size; // edi@12
+  int result;
+  char Filename[256]; // [sp+Ch] [bp-228h]@9
+  char NewFilename[256]; // [sp+10Ch] [bp-128h]@15
+  int i;
 
-    total_size = 0;
-    for (i=0;i<uNumSubDirs;i++)
-         total_size+=pSubIndices[i].uDataSize;
-    //fix offsets
-     temp_offset = sizeof(LOD::Directory) * uNumSubDirs;
-     for (i=0;i<uNumSubDirs;i++)
-            {
-            pSubIndices[i].uOfsetFromSubindicesStart=temp_offset;
-            temp_offset+=pSubIndices[i].uDataSize;
-         }
-    strcpy(Filename, "lod.tmp");
-    tmp_file = fopen(Filename, "wb+");
+  total_size = 0;
+  for ( i = 0; i < uNumSubDirs; i++ )
+    total_size += pSubIndices[i].uDataSize;
+  //fix offsets
+  temp_offset = sizeof(LOD::Directory) * uNumSubDirs;
+  for ( i = 0; i < uNumSubDirs; i++ )
+  {
+    pSubIndices[i].uOfsetFromSubindicesStart=temp_offset;
+    temp_offset+=pSubIndices[i].uDataSize;
+  }
+  strcpy(Filename, "lod.tmp");
+  tmp_file = fopen(Filename, "wb+");
 
-    if ( tmp_file )
-    {
-        fwrite((const void *)&header, sizeof(LOD::FileHeader), 1, tmp_file);
+  if ( tmp_file )
+  {
+    fwrite((const void *)&header, sizeof(LOD::FileHeader), 1, tmp_file);
 
-        LOD::Directory Lindx;
-        strcpy(Lindx.pFilename, "chapter");
-        Lindx.uOfsetFromSubindicesStart=uOffsetToSubIndex; //10h 16
-        Lindx.uDataSize=sizeof(LOD::Directory) * uNumSubDirs + total_size;		   //14h 20
-        Lindx.dword_000018=0;		   //18h 24 
-        Lindx.uNumSubIndices=uNumSubDirs;		   //1ch 28
-        Lindx.word_00001E=0;		   // 1Eh 30
-        fwrite(&Lindx, sizeof(LOD::Directory), 1, tmp_file);
-        fwrite(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, tmp_file);
-        fseek(pOutputFileHandle, 0, 0);
-        if ( total_size > 0 )
-            {
-            do
-                {
-                write_size = uIOBufferSize;
-                if ( total_size <= (signed int)uIOBufferSize )
-                    write_size =total_size;
-                fread(pIOBuffer, 1,  write_size,  pOutputFileHandle);
-                fwrite(pIOBuffer, 1,  write_size, tmp_file);
-                total_size -=  write_size;
-                }
-                while ( total_size > 0 );
-            }
-        strcpy(NewFilename, (const char *)&pLODName);
-        fclose(tmp_file);
-        fclose(pOutputFileHandle);
-        CloseWriteFile();
-        remove("lodapp.tmp");
-        remove(NewFilename);
-        rename(Filename, NewFilename);
-        CloseWriteFile();
-        LoadFile( (const char *)&pLODName, 0);
-        result = 0;
-        }
-    else
-        {
-        result = 5;
-        }
-    return result;
+    LOD::Directory Lindx;
+    strcpy(Lindx.pFilename, "chapter");
+    Lindx.uOfsetFromSubindicesStart = uOffsetToSubIndex; //10h 16
+    Lindx.uDataSize = sizeof(LOD::Directory) * uNumSubDirs + total_size;		   //14h 20
+    Lindx.dword_000018 = 0;		   //18h 24 
+    Lindx.uNumSubIndices = uNumSubDirs;		   //1ch 28
+    Lindx.word_00001E = 0;		   // 1Eh 30
+    fwrite(&Lindx, sizeof(LOD::Directory), 1, tmp_file);
+    fwrite(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, tmp_file);
+    fseek(pOutputFileHandle, 0, 0);
+    if ( total_size > 0 )
+    {
+      do
+      {
+        write_size = uIOBufferSize;
+        if ( total_size <= (signed int)uIOBufferSize )
+          write_size =total_size;
+        fread(pIOBuffer, 1,  write_size,  pOutputFileHandle);
+        fwrite(pIOBuffer, 1,  write_size, tmp_file);
+        total_size -=  write_size;
+      }
+      while ( total_size > 0 );
     }
+    strcpy(NewFilename, (const char *)&pLODName);
+    fclose(tmp_file);
+    fclose(pOutputFileHandle);
+    CloseWriteFile();
+    remove("lodapp.tmp");
+    remove(NewFilename);
+    rename(Filename, NewFilename);
+    CloseWriteFile();
+    LoadFile( (const char *)&pLODName, 0);
+    result = 0;
+  }
+  else
+    result = 5;
+  return result;
+}
 
 //----- (00461F71) --------------------------------------------------------
 bool LOD::File::AppendDirectory(LOD::Directory *pDir, const void *pData)
@@ -1491,6 +1486,8 @@
     fclose(pFile);
     pFile = 0;
   }
+  //else 
+    //__debugbreak();
 }
 // 6A0CA8: using guessed type int 6A0CA8_lod_unused;
 
@@ -1641,25 +1638,18 @@
     to_copy_size -= read_size;
   }
   //replace	  old file by new with added  data
-  strcpy(NewFilename, pLODName);
+  strcpy(NewFilename, (const char *)&pLODName);
   fclose(tmp_file);
-  bool test_file_opened1 = isFileOpened;
-  CloseWriteFile(); //isFileOpened == false, current file
-  bool test_file_opened2 = isFileOpened;
+  fclose(pFile);
+  CloseWriteFile();
   remove(NewFilename);
-  bool test_file_opened3 = isFileOpened;
   rename(Filename, NewFilename);
-  bool test_file_opened4 = isFileOpened;
   CloseWriteFile();
-  bool test_file_opened5 = isFileOpened;
   //reload new
-  LoadFile(pLODName, 0);//isFileOpened == true, next file
-  if (isFileOpened == false)
-		__debugbreak();
+  LoadFile((const char *)&pLODName, 0);//isFileOpened == true, next file
   return 0;
 }
 
-
 //----- (00461A43) --------------------------------------------------------
 bool LODWriteableFile::LoadFile(const char *pFilename, bool bWriting)
 {
@@ -2583,8 +2573,8 @@
     return -1;
   v8 = pOutTex;
   fread(pOutTex, 1, 0x30, pFile);
-  strcpy(v8->pName, pContainer);
-  if (/*pRenderer->pRenderD3D &&*/ v8->pBits & 2)
+  strcpy(pOutTex->pName, pContainer);
+  if (/*pRenderer->pRenderD3D &&*/ pOutTex->pBits & 2)
   {
     if (!pHardwareSurfaces || !pHardwareTextures)
     {
@@ -2600,15 +2590,13 @@
     if (_strnicmp(pContainer, "wtrdr", 5))//*v4 != 'w' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'd' || v4[4] != 'r' )
     {
       if (_strnicmp(pContainer, "WtrTyl", 6))//if ( *v4 != 'W' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'T' || v4[4] != 'y' || v4[5] != 'l' )
-      {
         v14 = uNumLoadedFiles;
-      }
       else
       {
         pRenderer->hd_water_tile_id = uNumLoadedFiles;
         v14 = uNumLoadedFiles;
       }
-      v13 = pRenderer->LoadTexture(pContainer, v8->palette_id1, (IDirectDrawSurface4 **)&pHardwareSurfaces[v14], &pHardwareTextures[v14]);
+      v13 = pRenderer->LoadTexture(pContainer, pOutTex->palette_id1, (IDirectDrawSurface4 **)&pHardwareSurfaces[v14], &pHardwareTextures[v14]);
     }
     else
     {
@@ -2617,30 +2605,30 @@
       eTextureType = v12;
       *(char *)v12 = 104;
       strcpy((char *)(v12 + 1), pContainer);
-      v13 = pRenderer->LoadTexture((const char *)eTextureType, v8->palette_id1,
+      v13 = pRenderer->LoadTexture((const char *)eTextureType, pOutTex->palette_id1,
               (IDirectDrawSurface4 **)&pHardwareSurfaces[uNumLoadedFiles], &pHardwareTextures[uNumLoadedFiles]);
       free((void *)eTextureType);
     }
     return v13;
   }
-  v15 = v8->uTextureSize;
-  v16 = &v8->uDecompressedSize;
-  pOutTex = (Texture *)v8->uTextureSize;
+  //v15 = v8->uTextureSize;
+  //v16 = &v8->uDecompressedSize;
+  //pOutTex = (Texture *)v8->uTextureSize;
   if ( !v8->uDecompressedSize || dword_011BA4 )
   {
-    v32 = malloc(v15);
+    v32 = malloc(v8->uTextureSize);
     v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v32;
-    fread(v32, 1, (size_t)pOutTex, pFile);
+    fread(v32, 1, (size_t)v8->uTextureSize, pFile);
   }
   else
   {
-    v17 = malloc(v8->uDecompressedSize);
-    v18 = v8->uTextureSize;
-    pContainer = (const char *)v17;
-    v19 = malloc(v18);
-    fread(v19, 1u, (size_t)pOutTex, pFile);
+    //v17 = malloc(v8->uDecompressedSize);
+    //v18 = v8->uTextureSize;
+    pContainer = (const char *)malloc(v8->uDecompressedSize);
+    v19 = malloc(v8->uTextureSize);
+    fread(v19, 1, (size_t)v8->uTextureSize, pFile);
     zlib::MemUnzip((void *)pContainer, &v8->uDecompressedSize, v19, v8->uTextureSize);
-    v8->uTextureSize = *v16;
+    v8->uTextureSize = v8->uDecompressedSize;
     free(v19);
     if ( /*bUseLoResSprites*/false && v8->pBits & 2 )
     {
@@ -2655,24 +2643,24 @@
       v8->uTextureWidth = (signed __int16)v8->uTextureWidth / 2;
       //v24 = v8->uTextureWidth;
       v8->uTextureHeight = (signed __int16)v8->uTextureHeight / 2;
-      v25 = v8->uTextureHeight;
+      //v25 = v8->uTextureHeight;
       --v8->uWidthLn2;
       --v8->uHeightLn2;
       v8->uWidthMinus1 = v8->uTextureWidth - 1;
-      v26 = v25 - 1;
-      v27 = (signed __int16)v8->uTextureWidth * (signed __int16)v25;
-      v28 = pOutTex;
-      v8->uHeightMinus1 = v26;
-      v8->uSizeOfMaxLevelOfDetail = v27;
-      v8->uTextureSize = (unsigned int)v28;
+      //v26 = v25 - 1;
+      //v27 = (signed __int16)v8->uTextureWidth * (signed __int16)v25;
+      //v28 = pOutTex;
+      v8->uHeightMinus1 = v8->uTextureHeight - 1;
+      v8->uSizeOfMaxLevelOfDetail = (signed __int16)v8->uTextureWidth * (signed __int16)v8->uTextureHeight;
+      v8->uTextureSize = (unsigned int)pOutTex;
     }
     else
     {
-      v29 = *v16;
-      v30 = malloc(v29);
-      v31 = v8->uDecompressedSize;
+      //v29 = v8->uDecompressedSize;
+      v30 = malloc(v8->uDecompressedSize);
+      //v31 = v8->uDecompressedSize;
       v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v30;
-      memcpy(v30, pContainer, v31);
+      memcpy(v30, pContainer, v8->uDecompressedSize);
     }
     free((void *)pContainer);
   }
@@ -2682,7 +2670,7 @@
   {
     v33 = malloc(0x300);
     v8->pPalette24 = (unsigned __int8 *)v33;
-    fread(v33, 1u, 0x300u, pFile);
+    fread(v33, 1, 0x300u, pFile);
   }
   else
   {
@@ -2690,20 +2678,17 @@
     if ( eTextureType == TEXTURE_16BIT_PALETTE )
     {
       v8->pPalette16 = (unsigned __int16 *)malloc(0x200);
-      v38 = 0;
-      do
+      for ( v38 = 0; v38 < 256; ++v38 )
       {
-        fread((char *)&eTextureType + 3, 1u, 1u, pFile);
-        fread((char *)&pContainer + 3, 1u, 1u, pFile);
-        v39 = fread((char *)&pOutTex + 3, 1u, 1u, pFile);
+        fread((char *)&eTextureType + 3, 1, 1, pFile);
+        fread((char *)&pContainer + 3, 1, 1, pFile);
+        v39 = fread((char *)&pOutTex + 3, 1, 1, pFile);
         LOWORD(v39) = (unsigned __int8)(BYTE3(eTextureType) >> (8 - LOBYTE(uTextureRedBits)));
         v8->pPalette16[v38] = v39 << (LOBYTE(uTextureBlueBits) + LOBYTE(uTextureGreenBits));
         LOWORD(v40) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(uTextureGreenBits)));
         v8->pPalette16[v38] += v40 << uTextureBlueBits;
         v8->pPalette16[v38] += (unsigned __int8)(BYTE3(pOutTex) >> (8 - LOBYTE(uTextureBlueBits)));
-        ++v38;
       }
-      while ( v38 < 256 );
       goto LABEL_36;
     }
   }
@@ -2725,24 +2710,17 @@
     v8->pLevelOfDetail1 = 0;
   }
   v8->pLevelOfDetail3 = v37;
-  v41 = 1;
-  while ( 1 << v41 != v8->uTextureWidth )
+  for ( v41 = 1; v41 < 15; ++v41 )
   {
-    ++v41;
-    if ( v41 >= 15 )
-      goto LABEL_48;
+    if ( 1 << v41 == v8->uTextureWidth )
+      v8->uWidthLn2 = v41;
   }
-  v8->uWidthLn2 = v41;
-LABEL_48:
-  v42 = 1;
-  while ( 1 << v42 != v8->uTextureHeight )
+  for ( v42 = 1; v42 < 15; ++v42 )
   {
-    ++v42;
-    if ( v42 >= 15 )
-      goto LABEL_53;
+    if ( 1 << v42 == v8->uTextureHeight )
+      v8->uHeightLn2 = v42;
   }
-  v8->uHeightLn2 = v42;
-LABEL_53:
+
   switch ( v8->uWidthLn2 )
   {
     case 2:
--- a/Mouse.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Mouse.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -52,23 +52,25 @@
 //----- (00469903) --------------------------------------------------------
 void Mouse::SetCursorBitmap(const char *pName)
 {
+  DDSURFACEDESC2 Dst;
+
   if ( !this->bInitialized || !pName )
     return;
-  if ( _stricmp("MICON2", pName) )
-    pGame->uFlags2 &= 0xFFFFFFEFu;
+  if ( _stricmp("MICON2", pName) )//если кусор не мишень
+    pGame->uFlags2 &= 0xFFFFFFEF;
   else
-    pGame->uFlags2 |= 0x10u;
+    pGame->uFlags2 |= 0x10;
   if ( _stricmp(this->pCurrentCursorName, pName) )
     strcpy(this->pCurrentCursorName, pName);
   ClearCursor();
-  if ( _strnicmp(pName, "MICON1", 5) )
+  if ( _strnicmp(pName, "MICON1", 5) )//for click to item / если курсор с вещью
   {
     this->uCursorTextureID = pIcons_LOD->LoadTexture(pName, TEXTURE_16BIT_PALETTE);
     this->uCursorTextureID_2 = pIcons_LOD->LoadTexture(pName, TEXTURE_16BIT_PALETTE);
     this->AllocCursorSystemMem();
     this->field_C = 0;
-    this->bRedraw = 1;
-    this->bActive = 1;
+    this->bRedraw = true;
+    this->bActive = true;
     if ( !areWeLoadingTexture )
     {
       if (uCursorTextureID != -1)
@@ -86,12 +88,10 @@
 //----- (00469AE4) --------------------------------------------------------
 LONG Mouse::_469AE4()
 {
-  Mouse *v1; // esi@1
   LONG v2; // ecx@2
   LONG result; // eax@2
   struct tagPOINT Point; // [sp+Ch] [bp-8h]@2
 
-  v1 = this;
   this->field_8 = 1;
   /*if (pAsyncMouse)
   {
@@ -107,8 +107,8 @@
     result = Point.y;
     v2 = Point.x;
   //}
-  v1->uMouseClickX = v2;
-  v1->uMouseClickY = result;
+  this->uMouseClickX = v2;
+  this->uMouseClickY = result;
   if ( true/*pRenderer->bWindowMode*/)
     goto LABEL_16;
   //if (pAsyncMouse)
@@ -117,35 +117,29 @@
     v2 = 0;
   if ( result < 0 )
     result = 0;
-  if ( v2 > 639 )
-    v2 = 639;
-  if ( result > 479 )
+  if ( v2 > window->GetWidth() - 1 )
+    v2 = window->GetWidth() - 1;
+  if ( result > window->GetHeight() - 1 )
   {
-    result = 479;
+    result = window->GetHeight() - 1;
 LABEL_16:
     //if (pAsyncMouse)
     //  goto LABEL_24;
-    if (true/*pRenderer->bWindowMode*/ && (v2 < 0 || result < 0 || v2 > 639 || result > 479) )
+    if (true/*pRenderer->bWindowMode*/ && (v2 < 0 || result < 0 || v2 > window->GetWidth() -1 || result > window->GetHeight() - 1) )
       goto LABEL_23;
   }
-  if ( v1->field_C )
+  if ( this->field_C )
 LABEL_23:
-    v1->bActive = 0;
+    this->bActive = false;
 LABEL_24:
-  v1->field_8 = 0;
+  this->field_8 = 0;
   return result;
 }
 
 //----- (00469BA3) --------------------------------------------------------
 void Mouse::ClearCursor()
 {
-  //Mouse *v1; // esi@1
-  //void *v2; // eax@1
-  //void **v3; // esi@5
-
-  //v1 = this;
-  //v2 = this->pCursorBitmap_sysmem;
-  this->bActive = 0;
+  this->bActive = false;
   if ( this->pCursorBitmap_sysmem )
   {
     free(this->pCursorBitmap_sysmem);
@@ -156,7 +150,6 @@
     free(this->pCursorBitmap2_sysmem);
     this->pCursorBitmap2_sysmem = 0;
   }
-  //v3 = &this->ptr_90;
   if ( this->ptr_90 )
     free(this->ptr_90);
   this->ptr_90 = 0;
@@ -165,7 +158,7 @@
 //----- (00469BE6) --------------------------------------------------------
 void Mouse::AllocCursorSystemMem()
 {
-  bActive = 0;
+  bActive = false;
   if (!pCursorBitmap_sysmem)
     pCursorBitmap_sysmem = (unsigned __int16 *)DoAllocCursorMem();
   if (!pCursorBitmap2_sysmem)
@@ -193,6 +186,12 @@
   this->window = window;
   this->bActive = false;
   this->bInitialized = true;
+
+  //this->field_8 = 0;//Ritor1: result incorrect uMouseClickX, this->uMouseClickY in _469AE4()
+  this->uCursorBitmapPitch = 0;//Ritor1: it's include
+  for ( uint i = 0; i < 13; i++ )
+    this->field_5C[i] = 0;
+
   this->pCursorBitmapPos.x = 0;
   this->pCursorBitmapPos.y = 0;
   this->uMouseClickX = 0;
@@ -228,7 +227,7 @@
   if ( this->bInitialized )
   {
     if ( !this->field_8 && this->bActive && !this->field_C )
-      pMouse->_469AE4();
+      pMouse->_469AE4();//Ritor1: странная, непонятная функция
     this->field_F4 = 1;
     if ( this->field_C )
     {
@@ -238,7 +237,7 @@
 
     //if ( pRenderer->bWindowMode )
     {
-      if ( this->uMouseClickX < 0 || this->uMouseClickY < 0 || this->uMouseClickX > 639 || this->uMouseClickY > 479 )
+      if ( this->uMouseClickX < 0 || this->uMouseClickY < 0 || this->uMouseClickX > window->GetWidth() - 1 || this->uMouseClickY > window->GetHeight() - 1 )
       {
         this->field_F4 = 0;
         return;
@@ -256,18 +255,18 @@
         this->uMouseClickY = 479;
     }*/
     this->pCursorBitmapRect.x = this->uMouseClickX;
-    this->pCursorBitmapRect.w = this->uMouseClickY + this->field_5C[0];
+    this->pCursorBitmapRect.w = this->uMouseClickY + this->field_5C[0]; //Ritor1: Maybe this->field_5C[0] - cursor width
     this->pCursorBitmapRect.y = this->uMouseClickY;
-    this->pCursorBitmapRect.z = this->uMouseClickX + this->uCursorBitmapPitch;
+    this->pCursorBitmapRect.z = this->uMouseClickX + this->uCursorBitmapPitch; //Ritor1: Maybe this->uCursorBitmapPitch - cursor height
     if ( this->uMouseClickX < 0 )
       this->pCursorBitmapRect.x = 0;
     if ( this->uMouseClickY < 0 )
       this->pCursorBitmapRect.y = 0;
-    if ( this->pCursorBitmapRect.z > 640 )
-      this->pCursorBitmapRect.z = 640;
-    if ( this->pCursorBitmapRect.w > 480 )
-      this->pCursorBitmapRect.w = 480;
-    this->bActive = 0;
+    if ( this->pCursorBitmapRect.z > window->GetWidth() )
+      this->pCursorBitmapRect.z = window->GetWidth();
+    if ( this->pCursorBitmapRect.w > window->GetHeight() )
+      this->pCursorBitmapRect.w = window->GetHeight();
+    this->bActive = false;
     this->uCursorBitmapWidth = this->pCursorBitmapRect.z - this->pCursorBitmapRect.x;
     this->uCursorBitmapHeight = this->pCursorBitmapRect.w - this->pCursorBitmapRect.y;
     if ( this->bRedraw )
@@ -284,7 +283,7 @@
 }
 
 //----- (00469E1C) --------------------------------------------------------
-void Mouse::_469E1C()
+void Mouse::Activate()
 {
   bActive = true;
 }
@@ -300,107 +299,75 @@
 }
 
 //----- (00469E3B) --------------------------------------------------------
-void Mouse::DrawCursorToTarget()
+void Mouse::DrawCursorToTarget()//??? DrawCursorWithItem
 {
   if (!pCursorBitmap3_sysmembits_16bit)
     return;
-
+  //пишем на экран курсор с вещью
   ushort* pSrc = pCursorBitmap3_sysmembits_16bit;
-  for (uint y = field_44; y < field_4C; ++y)
-    for (uint x = field_40; x < field_48; ++x)
+  for (uint y = uCursorWithItemY; y < uCursorWithItemZ; ++y)
+    for (uint x = uCursorWithItemX; x < uCursorWithItemW; ++x)
       //pRenderer->pTargetSurface[y * pRenderer->uTargetSurfacePitch + x] = *pSrc++;
         pRenderer->WritePixel16(x, y, *pSrc++);
 }
 
 //----- (00469EA4) --------------------------------------------------------
-void Mouse::_469EA4()
+void Mouse::ReadCursorWithItem()
 {
-  //Mouse *v1; // esi@1
   unsigned int pTextureID; // eax@2
   Texture *pTexture; // edi@2
-  unsigned int v4; // ecx@3
-  unsigned int v5; // eax@3
-  unsigned int v6; // ebx@5
-  int v7; // ecx@15
   int v8; // ecx@25
   int v9; // ebx@26
   unsigned int v10; // eax@26
   int v11; // edx@27
-  //unsigned __int16 *v12; // edx@29
-  //unsigned __int16 *v13; // ebx@29
-  unsigned int a2; // [sp+Ch] [bp-1Ch]@5
-  unsigned int v15; // [sp+10h] [bp-18h]@5
-  //unsigned int v16; // [sp+14h] [bp-14h]@25
-  //unsigned __int16 *v17; // [sp+18h] [bp-10h]@25
-  //int v18; // [sp+1Ch] [bp-Ch]@27
-  int v19; // [sp+20h] [bp-8h]@15
+  int pTextureHeight; // [sp+20h] [bp-8h]@15
   unsigned __int16 *v20; // [sp+20h] [bp-8h]@28
   int pTextureWidth; // [sp+24h] [bp-4h]@12
   unsigned __int16 *v22; // [sp+24h] [bp-4h]@25
 
-  //v1 = this;
   if ( pParty->pPickedItem.uItemID )
   {
     pTextureID = pIcons_LOD->LoadTexture(pParty->pPickedItem.GetIconName(), TEXTURE_16BIT_PALETTE);
     pTexture = (Texture *)(pTextureID != -1 ? (int)&pIcons_LOD->pTextures[pTextureID] : 0);
 
-      v4 = pMouse->uMouseClickX;
-      v5 = pMouse->uMouseClickY;
-
-    v6 = v5;
-    a2 = v4;
-    v15 = v5;
-    if ( (signed int)v4 <= 639 && (signed int)v5 <= 479 )
+    if ( (signed int)pMouse->uMouseClickX <= window->GetWidth() - 1 && (signed int)pMouse->uMouseClickY <= window->GetHeight() - 1 )
     {
-      if ( (v4 & 0x80000000u) != 0 )
+      /*if ( (v4 & 0x80000000u) != 0 )
         a2 = 0;
       if ( (v5 & 0x80000000u) != 0 )
       {
-        v6 = 0;
+        //v6 = 0;
         v15 = 0;
-      }
-      if ( (signed int)(pTexture->uTextureWidth + a2) <= 640 )
+      }	*/
+      if ( (signed int)(pTexture->uTextureWidth + pMouse->uMouseClickX) <= window->GetWidth() )
         pTextureWidth = pTexture->uTextureWidth;
       else
-        pTextureWidth = 640 - a2;
-      if ( (signed int)(pTexture->uTextureHeight + v6) <= 480 )
-      {
-        v19 = pTexture->uTextureHeight;
-        v7 = pTexture->uTextureHeight;
-      }
+        pTextureWidth = window->GetWidth() - pMouse->uMouseClickX;
+      if ( (signed int)(pTexture->uTextureHeight + pMouse->uMouseClickY) <= window->GetHeight() )
+        pTextureHeight = pTexture->uTextureHeight;
       else
-      {
-        v7 = 480 - v6;
-        v19 = 480 - v6;
-      }
+        pTextureHeight = window->GetHeight() - pMouse->uMouseClickY;
       if ( !this->pCursorBitmap3_sysmembits_16bit
-        || a2 != this->field_40
-        || v6 != this->field_44
-        || a2 + pTextureWidth != this->field_48
-        || v6 + v7 != this->field_4C )
+        || pMouse->uMouseClickX != this->uCursorWithItemX
+        || pMouse->uMouseClickY != this->uCursorWithItemY
+        || pMouse->uMouseClickX + pTextureWidth != this->uCursorWithItemW
+        || pMouse->uMouseClickY + pTextureHeight != this->uCursorWithItemZ )
       {
         if ( this->pCursorBitmap3_sysmembits_16bit )
           free(this->pCursorBitmap3_sysmembits_16bit);
         this->pCursorBitmap3_sysmembits_16bit = (unsigned __int16 *)malloc(2 * pTexture->uTextureHeight * pTexture->uTextureWidth);
-        this->field_40 = a2;
-        this->field_48 = a2 + pTextureWidth;
-        this->field_44 = v6;
-        this->field_4C = v6 + v19;
+        this->uCursorWithItemX = pMouse->uMouseClickX;
+        this->uCursorWithItemW = pMouse->uMouseClickX + pTextureWidth;
+        this->uCursorWithItemY = pMouse->uMouseClickY;
+        this->uCursorWithItemZ = pMouse->uMouseClickY + pTextureHeight;
       }
-      v8 = this->field_44;
       v22 = this->pCursorBitmap3_sysmembits_16bit;
-      //v17 = pRenderer->pTargetSurface;
-      //v16 = pRenderer->uTargetSurfacePitch;
-      
-        v10 = pRenderer->uTargetSurfacePitch * v8;
-          v11 = this->field_40;
-      for (int y = this->field_44; y < this->field_4C; ++y)
+
+      for (int y = this->uCursorWithItemY; y < this->uCursorWithItemZ; ++y)
       {
-            //v20 = &v17[v10 + v11];
-        for (int x = this->field_40; x < this->field_48; ++x)
+        for (int x = this->uCursorWithItemX; x < this->uCursorWithItemW; ++x)
         {
-              //++v18;
-              *v22++ = pRenderer->ReadPixel16(x, y);
+          *v22++ = pRenderer->ReadPixel16(x, y);
         }
       }
       /*if ( v8 < this->field_4C )
@@ -430,13 +397,12 @@
         v6 = v15;
       }*/
 
-      v6 = v15;
       if (pParty->pPickedItem.IsBroken())
-        pRenderer->DrawTransparentRedShade(a2, v6, pTexture);
+        pRenderer->DrawTransparentRedShade(pMouse->uMouseClickX, pMouse->uMouseClickY, pTexture);
       else if (!pParty->pPickedItem.IsIdentified())
-        pRenderer->DrawTransparentGreenShade(a2, v6, pTexture);
+        pRenderer->DrawTransparentGreenShade(pMouse->uMouseClickX, pMouse->uMouseClickY, pTexture);
       else
-        pRenderer->DrawTextureTransparent(a2, v6, pTexture);
+        pRenderer->DrawTextureTransparent(pMouse->uMouseClickX, pMouse->uMouseClickY, pTexture);
     }
   }
   else
@@ -450,9 +416,9 @@
 }
 
 //----- (0046A080) --------------------------------------------------------
-void Mouse::Activate(int bActive)
+void Mouse::ChangeActivation(int a1)
 {
-  bActive = bActive;
+  this->bActive = a1;
 }
 
 //----- (0046A08A) --------------------------------------------------------
@@ -818,9 +784,7 @@
         break;
       }
       default:
-      {
         break;
-      }
     }
   }
-}
\ No newline at end of file
+}
--- a/Mouse.h	Wed Feb 19 22:26:10 2014 +0100
+++ b/Mouse.h	Wed Feb 19 22:30:39 2014 +0100
@@ -73,11 +73,11 @@
   void SetActive(bool active);
   void Deactivate();
   void DrawCursor();
-  void _469E1C();
+  void Activate();
   void _469E24();
   void DrawCursorToTarget();
-  void _469EA4();
-  void Activate(int bActive);
+  void ReadCursorWithItem();
+  void ChangeActivation(int a1);
   void SetMouseClick(int x, int y);
 
 
@@ -98,10 +98,10 @@
   int field_34;
   unsigned __int8 *pCursorBitmap2_sysmem;
   unsigned __int16 *pCursorBitmap3_sysmembits_16bit;
-  int field_40;
-  int field_44;
-  int field_48;
-  int field_4C;
+  int uCursorWithItemX;
+  int uCursorWithItemY;
+  int uCursorWithItemW;
+  int uCursorWithItemZ;
   int field_50;
   int field_54;
   int uCursorBitmapPitch;
--- a/NPC.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/NPC.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -1591,15 +1591,15 @@
   v0 = 0;
   v1 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) )];//- 1
   pDialogueWindow->Release();
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x15Eu, WINDOW_MainMenu, 0, 0);
-  pBtn_ExitCancel = pDialogueWindow->CreateButton( 0x1D7u, 0x1BDu,  0xA9u,   0x23u,  1,  0,  UIMSG_Escape,  0,   0,
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), 350, WINDOW_MainMenu, 0, 0);
+  pBtn_ExitCancel = pDialogueWindow->CreateButton( 471, 0x1BDu,  0xA9u,   0x23u,  1,  0,  UIMSG_Escape,  0,   0,
                  pGlobalTXT_LocalizationStrings[34], //"Cancel"
                  pIcons_LOD->GetTexture(uExitCancelTextureId),
                  0);
   pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0);
   if ( pNPCStats->pProfessions[v1->uProfession].pBenefits)//*(&pNPCStats->field_13A5C + 5 * v1->uProfession) )
   {
-    pDialogueWindow->CreateButton( 0x1E0u,  0xA0u,  0x8Cu,  0x1Eu,   1,  0,  UIMSG_ClickNPCTopic,  0x4Du,   0,
+    pDialogueWindow->CreateButton( 480,  0xA0u,  0x8Cu,  0x1Eu,   1,  0,  UIMSG_ClickNPCTopic,  0x4Du,   0,
       pGlobalTXT_LocalizationStrings[407], 0);//"More Information"   
     v0 = 1;
   }
@@ -1628,7 +1628,7 @@
   if ( _this + 1 == uNumDialogueNPCPortraits && uHouse_ExitPic )
   {
     pDialogueWindow->Release();
-    pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
+    pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
     sprintfex(sHouseName.data(), pGlobalTXT_LocalizationStrings[LOCSTR_ENTER_S], pMapStats->pInfos[uHouse_ExitPic].pName);
     pBtn_ExitCancel = pDialogueWindow->CreateButton(566, 445, 75, 33, 1, 0, UIMSG_Escape, 0, 'N', pGlobalTXT_LocalizationStrings[34], pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);// "Cancel"
     pBtn_YES        = pDialogueWindow->CreateButton(486, 445, 75, 33, 1, 0, UIMSG_BF,     1, 'Y', sHouseName.data(), pIcons_LOD->GetTexture(uTextureID_BUTTYES2), 0);
@@ -1647,7 +1647,7 @@
       for ( i = 0; i < uNumDialogueNPCPortraits; ++i )
         HouseNPCPortraitsButtonsList[i]->Release();
     }
-    pDialogueWindow = GUIWindow::Create(0, 0, 640, 345, WINDOW_MainMenu, 0, 0);
+    pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), 345, WINDOW_MainMenu, 0, 0);
     pBtn_ExitCancel = pDialogueWindow->CreateButton(  471,  445,  169, 35,  1,   0, UIMSG_Escape,  0,  0,
                    pGlobalTXT_LocalizationStrings[74],// "End Conversation"
                    pIcons_LOD->GetTexture(uExitCancelTextureId),   0);
--- a/OSWindow.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/OSWindow.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -18,6 +18,7 @@
 #include "Bink_Smacker.h"
 #include "ErrorHandling.h"
 #include "Log.h"
+#include "LOD.h"
 
 
 bool OSWindow::OnMouseLeftClick(int x, int y)
@@ -255,8 +256,8 @@
       {
         pArcomageGame->GameOver = 1;
         pArcomageGame->field_F4 = 1;
-        pArcomageGame->uGameResult = 2;
-        pArcomageGame->field_B0 = -2;
+        pArcomageGame->uGameWinner = 2;
+        pArcomageGame->Victory_type = -2;
         return false;
       }
       if ( wparam != 114 )
@@ -473,13 +474,23 @@
   GetCursorPos(&cursor_pos);
 
   if (!strcmp(cursor_name, "MICON1") )
-    SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(GetModuleHandleW(nullptr), IDC_ARROW));
+    //SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(GetModuleHandleW(nullptr), IDC_ARROW));
+    SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(NULL, IDC_ARROW));
   else if (!strcmp(cursor_name, "MICON2") )
-    SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(GetModuleHandleW(nullptr), L"Target"));
+  {
+    //HCURSOR hCurs1; // дескриптор курсора 
+ 
+    // Создаем курсор в виде мишени. 
+ 
+    //pMouse->uCursorTextureID = pIcons_LOD->LoadTexture(cursor_name, TEXTURE_16BIT_PALETTE);//есть альфа маска
+    //hCurs1 = LoadCursor(NULL, L"Target");//неверно, наверно нужно загрузить/создать курсор
+    SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(NULL, IDC_CROSS));
+
+  }
   else if (!strcmp(cursor_name, "MICON3") )
-    SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(GetModuleHandleW(nullptr), IDC_WAIT));
+    SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(NULL, IDC_WAIT));
 
-  //ClientToScreen(api_handle, &cursor_pos);
+  //ClientToScreen(api_handle, &cursor_pos); //кидает курсор в другую часть экрана
   SetCursorPos(cursor_pos.x, cursor_pos.y);
 }
 
--- a/Outdoor.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Outdoor.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -33,6 +33,7 @@
 #include "BSPModel.h"
 #include "GUIWindow.h"
 #include "Level/Decoration.h"
+#include "OurMath.h"
 
 MapStartPoint uLevel_StartingPointType; // weak
 
@@ -2971,8 +2972,8 @@
                   v24 = pBModel->pVertices.pVertices[pFace->pVertexIDs[0]].z;
                 else
                 {
-                  int a = ((signed __int64)(pFace->zCalc1 * (signed __int64)X) >> 16);
-                  int b = ((signed __int64)(pFace->zCalc2 * (signed __int64)Y) >> 16);
+                  int a = fixpoint_mul(pFace->zCalc1, X);
+                  int b = fixpoint_mul(pFace->zCalc2, Y);
                   int c = ((signed __int64)pFace->zCalc3 >> 16);
                   v24 = a + b + c;
                 }
@@ -3405,7 +3406,7 @@
   int v96; // [sp-4h] [bp-98h]@246
   int v97; // [sp+Ch] [bp-88h]@180
   Vec3_int_ v98;
-  bool high_fall_flag; // [sp+1Ch] [bp-78h]@33
+  bool not_high_fall; // [sp+1Ch] [bp-78h]@33
   int v102; // [sp+20h] [bp-74h]@1
   int trigger_id; // [sp+24h] [bp-70h]@1
   bool bFeatherFall; // [sp+28h] [bp-6Ch]@4
@@ -3487,9 +3488,7 @@
   if ( floor_level - pZ > 512 && !bFeatherFall && pZ <= v111 + 1 )//падение на 3D Model
   {
     if (pParty->uFlags & PARTY_FLAGS_1_LANDING)
-    {
       pParty->uFlags &= ~PARTY_FLAGS_1_LANDING;
-    }
     else for (int i = 0; i < 4; ++i)     // receive falling damage
     {
       if ( !pParty->pPlayers[i].HasEnchantedItemEquipped(72) && !pParty->pPlayers[i].WearsItem(ITEM_ARTIFACT_HERMES_SANDALS, EQUIP_BOOTS) )
@@ -3514,7 +3513,7 @@
   }
   else
     hovering = true;
-  high_fall_flag = pZ - v111 <= 32;
+  not_high_fall = pZ - v111 <= 32;
 
   if ( bWalkSound && pParty->walk_sound_timer)//timer update
   {
@@ -4154,15 +4153,15 @@
   }
 
   //Воспроизведение звуков ходьбы/бега------------------------
-  v122 = abs(pParty->vPosition.x - pX);
+  uint pX_ = abs(pParty->vPosition.x - pX);
   uint pY_ = abs(pParty->vPosition.y - pY);
-  v62 = abs(pParty->vPosition.z - pZ);
+  uint pZ_ = abs(pParty->vPosition.z - pZ);
   if ( bWalkSound && pParty->walk_sound_timer <= 0 )
   {
     pAudioPlayer->_4AA258(804);//stop sound
-    if ( party_running_flag && (!hovering || high_fall_flag) )
+    if ( party_running_flag && (!hovering || not_high_fall) )
     {
-      if ( integer_sqrt(v122 * v122 + pY_ * pY_ + v62 * v62) >= 16 )
+      if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) >= 16 )
       {
         if ( !is_not_on_bmodel && pOutdoor->pBModels[pParty->floor_face_pid >> 9].pFaces[(pParty->floor_face_pid >> 3) & 0x3F].Visible() )
           pAudioPlayer->PlaySound(SOUND_RunAlong3DModel, 804, 1, -1, 0, 0, 0, 0);//бег на 3D Modelи
@@ -4174,9 +4173,9 @@
         pParty->walk_sound_timer = 96;//таймер для бега
       }
     }
-    else if( party_walking_flag && (!hovering || high_fall_flag) )
+    else if( party_walking_flag && (!hovering || not_high_fall) )
     {
-      if ( integer_sqrt(v122 * v122 + pY_ * pY_ + v62 * v62) >= 8 )
+      if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) >= 8 )
       {
         if ( !is_not_on_bmodel && pOutdoor->pBModels[pParty->floor_face_pid >> 9].pFaces[(pParty->floor_face_pid >> 3) & 0x3F].Visible() )
           pAudioPlayer->PlaySound(SOUND_WalkAlong3DModel, 804, 1, -1, 0, 0, 0, 0);// хождение на 3D Modelи
@@ -4189,10 +4188,10 @@
       }
     }
   }
-  if ( integer_sqrt(v122 * v122 + pY_ * pY_ + v62 * v62) < 8 )//отключить  звук ходьбы при остановке
+  if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) < 8 )//отключить  звук ходьбы при остановке
     pAudioPlayer->_4AA258(804);
 //------------------------------------------------------------------------
-  if ( !hovering || !high_fall_flag )
+  if ( !hovering || !not_high_fall )//  или не высокое падение
     pParty->uFlags &= ~PARTY_FLAGS_1_FALLING;
   else
     pParty->uFlags |= PARTY_FLAGS_1_FALLING;
@@ -4267,12 +4266,12 @@
   }
 //-----------------------------------------------------------------
   //v76 = pParty->bFlying;
-  if ( pParty->bFlying || !high_fall_flag || bWaterWalk || !v122_a )
+  if ( pParty->bFlying || !not_high_fall || bWaterWalk || !v122_a )// полёт или высокое падение или хождение по воде или 
     v77 = 1;
   else
     v77 = v122 != 0;
   bool party_drowning_flag = false;
-  if ( !pParty->bFlying && high_fall_flag && !bWaterWalk ) //не полёт, высокое падение, не хождение по воде
+  if ( !pParty->bFlying && not_high_fall && !bWaterWalk ) //не полёт и не высокое падение и не хождение по воде
   {
     if ( v122_a )
       v78 = v69 != 0;
@@ -4451,8 +4450,7 @@
             if ( pOutdoor->pBModels[i].pFaces[j].uPolygonType == POLYGON_Ceiling )
               v19 = pOutdoor->pBModels[i].pVertices.pVertices[pOutdoor->pBModels[i].pFaces[j].pVertexIDs[0]].z;
             else
-              v19 = ((unsigned __int64)(pOutdoor->pBModels[i].pFaces[j].zCalc1 * (signed __int64)Party_X) >> 16)
-                  + ((unsigned __int64)(pOutdoor->pBModels[i].pFaces[j].zCalc2 * (signed __int64)Party_Y) >> 16)
+              v19 = fixpoint_mul(pOutdoor->pBModels[i].pFaces[j].zCalc1, Party_X) + fixpoint_mul(pOutdoor->pBModels[i].pFaces[j].zCalc2, Party_Y)
                   + HIWORD(pOutdoor->pBModels[i].pFaces[j].zCalc3);
             v20 = v39++;
             ceiling_height_level[v20] = v19;
--- a/ParticleEngine.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/ParticleEngine.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -454,174 +454,101 @@
 //----- (0048B5B3) --------------------------------------------------------
 bool ParticleEngine::ViewProject_TrueIfStillVisible_ODM(unsigned int uID)
 {
-  //ParticleEngine *v2; // ST18_4@1
   int v3; // ebx@1
   int v4; // edi@1
   int v5; // ecx@1
-  Particle *v6; // esi@1
-  //double v7; // ST14_8@2
-  //double v8; // ST34_8@4
-  //double v9; // ST3C_8@4
-  //int v10; // ST50_4@4
   int v11; // ST44_4@4
-  //double v12; // ST48_8@4
   signed __int64 v13; // qtt@4
-  //int v14; // eax@4
-  //int v15; // ST28_4@4
   int v16; // edi@6
   int v17; // eax@6
-  //double v18; // ST2C_8@8
-  //double v19; // ST34_8@8
-  //int v20; // ST50_4@8
-  //double v21; // ST34_8@8
   signed __int64 v22; // qtt@8
-  //int v23; // eax@8
-  //int v24; // ST28_4@8
-  //int v25; // edx@8
   int v26; // edx@9
-  //int v27; // eax@9
   int v28; // ebx@12
   signed __int64 v29; // qtt@13
-  //int v30; // eax@13
-  //int v31; // ST1C_4@13
-  //double v32; // st7@13
-  signed int v33; // eax@13
-  //int v34; // ecx@13
-  //float v35; // ST04_4@13
-  int v36; // eax@13
-  int v37; // esi@15
-  //double v39; // [sp+10h] [bp-40h]@2
   int v40; // [sp+14h] [bp-3Ch]@12
-  //int v41; // [sp+1Ch] [bp-34h]@2
-  //double v42; // [sp+20h] [bp-30h]@2
-  //int v43; // [sp+24h] [bp-2Ch]@5
   int v44; // [sp+2Ch] [bp-24h]@1
   int v45; // [sp+40h] [bp-10h]@5
   int X_4; // [sp+48h] [bp-8h]@5
-  //int v47; // [sp+4Ch] [bp-4h]@5
-  //int v48; // [sp+4Ch] [bp-4h]@9
-  //int uIDc; // [sp+58h] [bp+8h]@4
-  //int uIDd; // [sp+58h] [bp+8h]@4
-  //int uIDe; // [sp+58h] [bp+8h]@5
-  //int uIDa; // [sp+58h] [bp+8h]@5
-  //int uIDf; // [sp+58h] [bp+8h]@8
-  //int uIDb; // [sp+58h] [bp+8h]@9
 
   v3 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX);
   v44 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
   v4 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
   v5 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
 
-  v6 = &pParticles[uID];
-  if (v6->type == ParticleType_Invalid)
+  if (pParticles[uID].type == ParticleType_Invalid)
     return false;
 
-    //v7 = v6->x + 6.7553994e15;
-    //v41 = LODWORD(v7);
-    //v39 = v6->y + 6.7553994e15;
-    //v42 = v6->z + 6.7553994e15;
-    if ( v3 )
+  if ( v3 )
+  {
+    if (pParticles[uID].type & ParticleType_Line)
     {
-      if (v6->type & ParticleType_Line)
-      {
-        //v8 = v6->_x + 6.7553994e15;
-        //uIDc = (LODWORD(v8) - pIndoorCamera->pos.x) << 16;
-        //v9 = v6->_y + 6.7553994e15;
-        //v10 = (LODWORD(v9) - pIndoorCamera->pos.y) << 16;
-        v11 = fixpoint_sub_unknown(v6->x - pGame->pIndoorCameraD3D->vPartyPos.x, v4) + fixpoint_sub_unknown(v6->y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
-        //HIDWORD(v8) = fixpoint_sub_unknown(v6->x - pIndoorCamera->pos.x, v5);
-        //v12 = v6->_z + 6.7553994e15;
-        //uIDd = (LODWORD(v12) - pIndoorCamera->pos.z) << 16;
-        long long _hidword_v12 = fixpoint_mul(v11, v3) + fixpoint_sub_unknown(v6->z - pGame->pIndoorCameraD3D->vPartyPos.z, v44);
-        LODWORD(v13) = 0;
-        HIDWORD(v13) = SLOWORD(pODMRenderParams->int_fov_rad);
-        //v14 = v13 / _hidword_v12;
-        v6->_screenspace_scale = v13 / _hidword_v12;
-        //v15 = v6->_screenspace_scale;
-        v6->uScreenSpaceX = pViewport->uScreenCenterX
-                          - ((signed int)((unsigned __int64)(v6->_screenspace_scale
-                                                           * (signed __int64)(fixpoint_sub_unknown(v6->y - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
-                                                                                        - fixpoint_sub_unknown(v6->x - pGame->pIndoorCameraD3D->vPartyPos.x, v5))) >> 16) >> 16);
-        v6->uScreenSpaceY = pViewport->uScreenCenterY
-                          - ((signed int)((unsigned __int64)(v6->_screenspace_scale
-                                                           * (signed __int64)(fixpoint_sub_unknown(v6->z - pGame->pIndoorCameraD3D->vPartyPos.z, v3)
-                                                                                        - ((unsigned __int64)(v11 * (signed __int64)v44) >> 16))) >> 16) >> 16);
-        v6->sZValue = _hidword_v12;
-      }
-      //uIDe = (v41 - pIndoorCamera->pos.x) << 16;
-      //v47 = (LODWORD(v39) - pIndoorCamera->pos.y) << 16;
-      v45 = fixpoint_sub_unknown(v6->x - pGame->pIndoorCameraD3D->vPartyPos.x, v4) + fixpoint_sub_unknown(v6->y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
-      //HIDWORD(v42) = fixpoint_sub_unknown(v6->x - pIndoorCamera->pos.x, v5);
-      //uIDa = (LODWORD(v42) - pIndoorCamera->pos.z) << 16;
-      X_4 = fixpoint_sub_unknown(v6->z - pGame->pIndoorCameraD3D->vPartyPos.z, v44) + fixpoint_mul(v45, v3);
-      if ( X_4 < 0x40000 )
-        return 0;
-      v16 = fixpoint_sub_unknown(v6->y - pGame->pIndoorCameraD3D->vPartyPos.y, v4) - fixpoint_sub_unknown(v6->x - pGame->pIndoorCameraD3D->vPartyPos.x, v5);
-      v17 = fixpoint_sub_unknown(v6->z - pGame->pIndoorCameraD3D->vPartyPos.z, v3) - fixpoint_mul(v45, v44);
+      v11 = fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v4)
+          + fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
+      long long _hidword_v12 = fixpoint_mul(v11, v3) + fixpoint_sub_unknown(pParticles[uID].z - pGame->pIndoorCameraD3D->vPartyPos.z, v44);
+      LODWORD(v13) = 0;
+      HIDWORD(v13) = SLOWORD(pODMRenderParams->int_fov_rad);
+      pParticles[uID]._screenspace_scale = v13 / _hidword_v12;
+      pParticles[uID].uScreenSpaceX = pViewport->uScreenCenterX
+                                    - ((signed int)fixpoint_mul(pParticles[uID]._screenspace_scale, (fixpoint_sub_unknown(pParticles[uID].y
+                                    - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
+                                    - fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v5))) >> 16);
+      pParticles[uID].uScreenSpaceY = pViewport->uScreenCenterY
+                                    - ((signed int)fixpoint_mul(pParticles[uID]._screenspace_scale, (fixpoint_sub_unknown(pParticles[uID].z
+                                    - pGame->pIndoorCameraD3D->vPartyPos.z, v3)
+                                    - fixpoint_mul(v11, v44))) >> 16);
+      pParticles[uID].sZValue = _hidword_v12;
     }
-    else
+    v45 = fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v4) + fixpoint_sub_unknown(pParticles[uID].y
+                                                 - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
+    X_4 = fixpoint_sub_unknown(pParticles[uID].z - pGame->pIndoorCameraD3D->vPartyPos.z, v44) + fixpoint_mul(v45, v3);
+    if ( X_4 < 0x40000 )
+      return 0;
+    v16 = fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
+        - fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v5);
+    v17 = fixpoint_sub_unknown(pParticles[uID].z - pGame->pIndoorCameraD3D->vPartyPos.z, v3) - fixpoint_mul(v45, v44);
+  }
+  else
+  {
+    if (pParticles[uID].type & ParticleType_Line)
     {
-      if (v6->type & ParticleType_Line)
-      {
-        //v18 = v6->_x + 6.7553994e15;
-        //uIDf = (LODWORD(v18) - pIndoorCamera->pos.x) << 16;
-        //v19 = v6->_y + 6.7553994e15;
-        //v20 = (LODWORD(v19) - pIndoorCamera->pos.y) << 16;
-        //v21 = v6->_z + 6.7553994e15;
-        LODWORD(v22) = 0;
-        HIDWORD(v22) = SLOWORD(pODMRenderParams->int_fov_rad);
-        long long _var_123 = fixpoint_sub_unknown(v6->x - pGame->pIndoorCameraD3D->vPartyPos.x, v4) + fixpoint_sub_unknown(v6->y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
-        //v23 = v22 / _var_123;
-        v6->_screenspace_scale = v22 / _var_123;
-        //v24 = v6->_screenspace_scale;
-        v6->uScreenSpaceX = pViewport->uScreenCenterX
-                          - ((signed int)((unsigned __int64)(v6->_screenspace_scale
-                                                           * (signed __int64)(fixpoint_sub_unknown(v6->y - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
-                                                                                        - fixpoint_sub_unknown(v6->x - pGame->pIndoorCameraD3D->vPartyPos.x, v5))) >> 16) >> 16);
-        v6->uScreenSpaceY = pViewport->uScreenCenterY - (fixpoint_sub_unknown(v6->z, v6->_screenspace_scale) >> 16);
-        v6->sZValue = _var_123;
-      }
-      //uIDb = (v41 - pIndoorCamera->pos.x) << 16;
-      //v48 = (LODWORD(v39) - pIndoorCamera->pos.y) << 16;
-      v26 = fixpoint_sub_unknown(v6->y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
-      //v27 = v26 + ((unsigned __int64)(uIDb * (signed __int64)v4) >> 16);
-      X_4 = v26 + fixpoint_sub_unknown(v6->x - pGame->pIndoorCameraD3D->vPartyPos.x, v4);
-      if ( X_4 < 0x40000 || X_4 > (pODMRenderParams->uPickDepth - 1000) << 16 )
-        return 0;
-      v17 = v6->z;
-      v16 = fixpoint_sub_unknown(v6->y - pGame->pIndoorCameraD3D->vPartyPos.y, v4) - fixpoint_sub_unknown(v6->x - pGame->pIndoorCameraD3D->vPartyPos.x, v5);
+      LODWORD(v22) = 0;
+      HIDWORD(v22) = SLOWORD(pODMRenderParams->int_fov_rad);
+      long long _var_123 = fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v4)
+                         + fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
+      pParticles[uID]._screenspace_scale = v22 / _var_123;
+      pParticles[uID].uScreenSpaceX = pViewport->uScreenCenterX
+                        - ((signed int)fixpoint_mul(pParticles[uID]._screenspace_scale, (fixpoint_sub_unknown(pParticles[uID].y
+                        - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
+                        - fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v5))) >> 16);
+      pParticles[uID].uScreenSpaceY = pViewport->uScreenCenterY - (fixpoint_sub_unknown(pParticles[uID].z, pParticles[uID]._screenspace_scale) >> 16);
+      pParticles[uID].sZValue = _var_123;
     }
-    v40 = v17;
-    v28 = abs(v16);
-    if ( abs(X_4) >= v28 )
-    {
-      LODWORD(v29) = 0;
-      HIDWORD(v29) = SLOWORD(pODMRenderParams->int_fov_rad);
-      //v30 = v29 / X_4;
-      v6->_screenspace_scale = v29 / X_4;
-      //v31 = v6->_screenspace_scale;
-      v6->uScreenSpaceX = pViewport->uScreenCenterX
-                        - ((signed int)((unsigned __int64)(v6->_screenspace_scale * (signed __int64)v16) >> 16) >> 16);
-      v33 = (signed int)((unsigned __int64)(v6->_screenspace_scale * (signed __int64)v40) >> 16) >> 16;
-      //v34 = pViewport->uScreenCenterY - v33;
-      v6->uScreenSpaceY = pViewport->uScreenCenterY - v33;
-      v6->_screenspace_scale = fixpoint_mul(fixpoint_from_float(v6->flt_28), v6->_screenspace_scale);
-      v6->sZValue = X_4;
-      v36 = v6->uScreenSpaceX;
-      if ( v36 >= (signed int)pViewport->uViewportTL_X )
-      {
-        if ( v36 < (signed int)pViewport->uViewportBR_X )
-        {
-          v37 = v6->uScreenSpaceY;
-          if ( v37 >= (signed int)pViewport->uViewportTL_Y )
-          {
-            if ( v37 < (signed int)pViewport->uViewportBR_Y )
-              return 1;
-          }
-        }
-      }
-    }
-    return false;
+    v26 = fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
+    X_4 = v26 + fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v4);
+    if ( X_4 < 0x40000 || X_4 > (pODMRenderParams->uPickDepth - 1000) << 16 )
+      return 0;
+    v17 = pParticles[uID].z;
+    v16 = fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
+        - fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v5);
+  }
+  v40 = v17;
+  v28 = abs(v16);
+  if ( abs(X_4) >= v28 )
+  {
+    LODWORD(v29) = 0;
+    HIDWORD(v29) = SLOWORD(pODMRenderParams->int_fov_rad);
+    pParticles[uID]._screenspace_scale = v29 / X_4;
+    pParticles[uID].uScreenSpaceX = pViewport->uScreenCenterX - ((signed int)fixpoint_mul(pParticles[uID]._screenspace_scale, v16) >> 16);
+    pParticles[uID].uScreenSpaceY = pViewport->uScreenCenterY - ((signed int)fixpoint_mul(pParticles[uID]._screenspace_scale, v40) >> 16);
+    pParticles[uID]._screenspace_scale = fixpoint_mul(fixpoint_from_float(pParticles[uID].flt_28), pParticles[uID]._screenspace_scale);
+    pParticles[uID].sZValue = X_4;
+    if ( pParticles[uID].uScreenSpaceX >= (signed int)pViewport->uViewportTL_X
+      && pParticles[uID].uScreenSpaceX < (signed int)pViewport->uViewportBR_X
+      && pParticles[uID].uScreenSpaceY >= (signed int)pViewport->uViewportTL_Y
+      && pParticles[uID].uScreenSpaceY < (signed int)pViewport->uViewportBR_Y )
+      return true;
+  }
+  return false;
 }
 
 //----- (0048BBA6) --------------------------------------------------------
--- a/Player.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Player.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -2008,8 +2008,8 @@
   if ( rand() % 100 < 5 || fineIfFailed > currMaxItemValue || BYTE2(actroPtr->uAttributes) & 8 )
   {
     Actor::AggroSurroundingPeasants(uActorID, 1);
-    sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[376], this->pName);
-    ShowStatusBarString(pTmpBuf2.data(), 2u);
+    sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[376], this->pName);//"%s was caught stealing!"
+    ShowStatusBarString(pTmpBuf2.data(), 2);
     return 0;
   }
   else
@@ -2019,9 +2019,7 @@
     {
       enchBonusSum = 0;
       for (int i = 0; i < v7; i++)
-      {
         enchBonusSum += rand() % StealingEnchantmentBonusForSkill[stealingMastery] + 1;
-      }
       if ( actroPtr->array_000234[3].GetItemEquipType() != EQUIP_GOLD )
         return 2;
       enchTypePtr = &actroPtr->array_000234[3].uSpecEnchantmentType;
@@ -2031,19 +2029,15 @@
         *enchTypePtr = 0;
       }
       else
-      {
         *enchTypePtr -= enchBonusSum;
-      }
       if ( enchBonusSum )
       {
         pParty->PartyFindsGold(enchBonusSum, 2);
         sprintf(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[302], this->pName, enchBonusSum);     //%stole %d gold
       }
       else
-      {
         sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[377], this->pName);   //%s failed to steal anything
-      }
-      ShowStatusBarString(pTmpBuf2.data(), 2u);
+      ShowStatusBarString(pTmpBuf2.data(), 2);
       return 2;
     }
     else if ( v11 % 100 >= 40 )   //stealing an item      
@@ -2095,7 +2089,7 @@
       }
     }
     sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[377], this->pName);   //%s failed to steal anything
-    ShowStatusBarString(pTmpBuf2.data(), 2u);
+    ShowStatusBarString(pTmpBuf2.data(), 2);
     return 2;
   }
 }
--- a/Render.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Render.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -464,48 +464,18 @@
 //----- (0047AF11) --------------------------------------------------------
 void Render::DrawSpriteObjects_ODM()
 {
-  //char *v0; // edi@2
-  //ObjectDesc *v1; // ebx@4
-  __int16 v2; // cx@5
-  RenderBillboard *v3; // esi@10
-  SpriteFrame *v4; // eax@10
-  //SpriteFrame *v5; // ebx@10
+  SpriteFrame *frame; // eax@10
   unsigned int v6; // eax@10
-  //int v7; // ecx@10
-  //int v8; // edx@10
   int v9; // ecx@10
-  unsigned __int16 v10; // ax@10
-  //int *v11; // eax@14
-  int v12; // eax@22
-  int v13; // ST3C_4@23
-  int v14; // eax@23
-  int v15; // ecx@23
-  int v16; // ebx@23
   int v17; // ecx@25
   int v18; // eax@25
-  int v19; // ST40_4@26
-  int v20; // ecx@26
-  int v21; // ST44_4@28
   int v22; // ST3C_4@29
   signed __int64 v23; // qtt@30
-  int v24; // ebx@30
-  int v25; // ST3C_4@30
   int v26; // eax@31
   char v27; // zf@31
-  //SpriteFrame *v28; // [sp+Ch] [bp-34h]@10
-  //__int16 a5; // [sp+10h] [bp-30h]@10
   int v30; // [sp+14h] [bp-2Ch]@23
-  int v31; // [sp+14h] [bp-2Ch]@29
-  __int16 v32; // [sp+14h] [bp-2Ch]@30
-  int v33; // [sp+18h] [bp-28h]@23
-  int v34; // [sp+18h] [bp-28h]@26
-  int v35; // [sp+18h] [bp-28h]@30
-  int v36; // [sp+1Ch] [bp-24h]@10
   int v37; // [sp+1Ch] [bp-24h]@23
   int a6; // [sp+20h] [bp-20h]@10
-  int a6a; // [sp+20h] [bp-20h]@23
-  int v40; // [sp+24h] [bp-1Ch]@25
-  //signed int v41; // [sp+28h] [bp-18h]@1
   int v42; // [sp+2Ch] [bp-14h]@23
   int y; // [sp+30h] [bp-10h]@10
   int x; // [sp+34h] [bp-Ch]@10
@@ -532,136 +502,133 @@
         //if ( !(v1->uFlags & 1) )
         //{
           //v2 = *((short *)v0 - 14)
-    v2 = object->uType;
-    if ( (v2 < 1000 || v2 >= 10000) && (v2 < 500 || v2 >= 600) || pGame->pStru6Instance->_4A81CA(object) )
+    //v2 = object->uType;
+    if ( (object->uType < 1000 || object->uType >= 10000) && (object->uType < 500 || object->uType >= 600)
+       || pGame->pStru6Instance->_4A81CA(object) )
     {
             //a5 = *(short *)v0;
       x = object->vPosition.x;
       y = object->vPosition.y;
       z = object->vPosition.z;
-      v3 = &pBillboardRenderList[::uNumBillboardsToDraw];
-      v4 = pSpriteFrameTable->GetFrame(object_desc->uSpriteID, object->uSpriteFrameID);
-      //v5 = v4;
-      //v28 = v4;
-      v36 = v4->uFlags;
-      a6 = v4->uGlowRadius * object->field_22_glow_radius_multiplier;
+      frame = pSpriteFrameTable->GetFrame(object_desc->uSpriteID, object->uSpriteFrameID);
+      a6 = frame->uGlowRadius * object->field_22_glow_radius_multiplier;
       v6 = stru_5C6E00->Atan2(object->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x, object->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
       //LOWORD(v7) = object->uFacing;
       //v8 = v36;
-            v9 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + object->uFacing - v6) >> 8) & 7;
-            v10 = v4->pHwSpriteIDs[v9];
-            v3->uHwSpriteID = v10;
-            if ( v36 & 0x20 )
-            {
-              //v8 = v36;
-              z -= (signed int)((unsigned __int64)(v4->scale * (signed __int64)pSprites_LOD->pSpriteHeaders[(signed __int16)v10].uHeight) >> 16) >> 1;
-            }
-            v46 = 0;
-            if ( v36 & 2 )
-              v46 = 2;
-            //v11 = (int *)(256 << v9);
-            if ( (256 << v9) & v36 )
-              v46 |= 4u;
-            if ( v36 & 0x40000 )
-              v46 |= 0x40u;
-            if ( v36 & 0x20000 )
-              LOBYTE(v46) = v46 | 0x80;
-            if ( a6 )
-            {
-              //LOBYTE(v11) = _4E94D3_light_type;
-              pMobileLightsStack->AddLight(x, y, z, object->uSectorID, a6, 0xFFu, 0xFFu, 0xFFu, _4E94D3_light_type);
-            }
-            v12 = (x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
-            if (pGame->pIndoorCameraD3D->sRotationX)
-            {
-              v13 = (y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-              v30 = ((unsigned __int64)(v12 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
-                  + ((unsigned __int64)(v13 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
-              v37 = (unsigned __int64)(v12 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-              a6a = (unsigned __int64)(v13 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
-              v33 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-              v14 = (unsigned __int64)(v30 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16;
-              v15 = (unsigned __int64)(v33 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-              v16 = v15 + v14;
-              v42 = v15 + v14;
-              if ( v15 + v14 >= 262144 && v16 <= pODMRenderParams->shading_dist_mist << 16 )
-              {
-                v17 = a6a - v37;
-                v40 = a6a - v37;
-                v18 = ((unsigned __int64)(v33 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16)
-                    - ((unsigned __int64)(v30 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
-                goto LABEL_29;
-              }
-            }
-            else
+      v9 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + object->uFacing - v6) >> 8) & 7;
+      pBillboardRenderList[::uNumBillboardsToDraw].uHwSpriteID = frame->pHwSpriteIDs[v9];
+      if ( frame->uFlags & 0x20 )
+      {
+        //v8 = v36;
+        z -= fixpoint_mul(frame->scale, pSprites_LOD->pSpriteHeaders[(signed __int16)frame->pHwSpriteIDs[v9]].uHeight) / 2;
+      }
+      v46 = 0;
+      if ( frame->uFlags & 2 )
+        v46 = 2;
+      //v11 = (int *)(256 << v9);
+      if ( (256 << v9) & frame->uFlags )
+        v46 |= 4u;
+      if ( frame->uFlags & 0x40000 )
+        v46 |= 0x40u;
+      if ( frame->uFlags & 0x20000 )
+        LOBYTE(v46) = v46 | 0x80;
+      if ( a6 )
+      {
+        //LOBYTE(v11) = _4E94D3_light_type;
+        pMobileLightsStack->AddLight(x, y, z, object->uSectorID, a6, 0xFFu, 0xFFu, 0xFFu, _4E94D3_light_type);
+      }
+      if (pGame->pIndoorCameraD3D->sRotationX)
+      {
+        v30 = fixpoint_mul((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16, pGame->pIndoorCameraD3D->int_cosine_y)
+            + fixpoint_mul((y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16, pGame->pIndoorCameraD3D->int_sine_y);
+        v37 = fixpoint_mul((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16, pGame->pIndoorCameraD3D->int_sine_y);
+        v42 = fixpoint_mul((z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x)
+            + fixpoint_mul(v30, pGame->pIndoorCameraD3D->int_cosine_x);
+        if ( v42 >= 0x40000 && v42 <= pODMRenderParams->shading_dist_mist << 16 )
+        {
+          v17 = fixpoint_mul((y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16, pGame->pIndoorCameraD3D->int_cosine_y) - v37;
+          v18 = fixpoint_mul((z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_cosine_x)
+              - fixpoint_mul(v30, pGame->pIndoorCameraD3D->int_sine_x);
+          if ( abs(v42) >= abs(v17) )
+          {
+            LODWORD(v23) = 0;
+            HIDWORD(v23) = SLOWORD(pODMRenderParams->int_fov_rad);
+
+            object->uAttributes |= 1;
+            pBillboardRenderList[::uNumBillboardsToDraw].uPalette = frame->uPaletteIndex;
+            pBillboardRenderList[::uNumBillboardsToDraw].uIndoorSectorID = object->uSectorID;
+            pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_x_scaler_packedfloat = fixpoint_mul(frame->scale, v23 / v42);
+            pBillboardRenderList[::uNumBillboardsToDraw].pSpriteFrame = frame;
+            pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_y_scaler_packedfloat = fixpoint_mul(frame->scale, v23 / v42);
+            pBillboardRenderList[::uNumBillboardsToDraw].field_1E = v46;
+            pBillboardRenderList[::uNumBillboardsToDraw].world_x = x;
+            pBillboardRenderList[::uNumBillboardsToDraw].world_y = y;
+            pBillboardRenderList[::uNumBillboardsToDraw].world_z = z;
+            pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceX = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v23 / v42, v17) + 0x8000) >> 16);
+            pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceY = pViewport->uScreenCenterY - (((unsigned int)fixpoint_mul(v23 / v42, v18) + 0x8000) >> 16);
+            HIWORD(v26) = HIWORD(v42);
+            LOWORD(v26) = 0;
+            pBillboardRenderList[::uNumBillboardsToDraw].sZValue = v26 + (PID(OBJECT_Item,i));
+            pBillboardRenderList[::uNumBillboardsToDraw].dimming_level = 0;
+            pBillboardRenderList[::uNumBillboardsToDraw].sTintColor = 0;
+            if ( !(object->uAttributes & 0x20) )
             {
-              v34 = (y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-              v19 = (unsigned __int64)(v12 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
-              v20 = (unsigned __int64)(v34 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-              v16 = v20 + v19;
-              v42 = v20 + v19;
-              if ( v20 + v19 >= 262144 && v16 <= pODMRenderParams->shading_dist_mist << 16 )
-              {
-                v21 = (unsigned __int64)(((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16) * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-                v17 = ((unsigned __int64)(v34 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - v21;
-                v40 = ((unsigned __int64)(v34 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - v21;
-                v18 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-LABEL_29:
-                v31 = v18;
-                v22 = abs(v17);
-                if ( abs(v16) >= v22 )
-                {
-                  LODWORD(v23) = 0;
-                  HIDWORD(v23) = SLOWORD(pODMRenderParams->int_fov_rad);
-                  v24 = v23 / v42;
-                  v25 = v23 / v42;
-                  LODWORD(v23) = 0;
-                  HIDWORD(v23) = SLOWORD(pODMRenderParams->int_fov_rad);
-                  v35 = pViewport->uScreenCenterX - ((signed int)(((unsigned __int64)(v25 * (signed __int64)v40) >> 16) + 32768) >> 16);
-                  v32 = LOWORD(pViewport->uScreenCenterY) - (((unsigned int)((unsigned __int64)(v23 / v42 * v31) >> 16) + 32768) >> 16);
-
-                  //if (::uNumBillboardsToDraw >= 500)
-                  //  return;
-                  assert(::uNumBillboardsToDraw < 500);
-                  ++::uNumBillboardsToDraw;
-                  ++uNumSpritesDrawnThisFrame;
-
-                  object->uAttributes |= 1;
-                  v3->uPalette = v4->uPaletteIndex;
-                  v3->uIndoorSectorID = object->uSectorID;
-                  v3->_screenspace_x_scaler_packedfloat = (unsigned __int64)(v4->scale * (signed __int64)v24) >> 16;
-                  v26 = (unsigned __int64)(v4->scale * (signed __int64)v24) >> 16;
-                  v3->pSpriteFrame = v4;
-                  v3->_screenspace_y_scaler_packedfloat = v26;
-                  v3->field_1E = v46;
-                  v3->world_x = x;
-                  v3->world_y = y;
-                  v3->world_z = z;
-                  v3->uScreenSpaceX = v35;
-                  v3->uScreenSpaceY = v32;
-                  HIWORD(v26) = HIWORD(v42);
-                  LOWORD(v26) = 0;
-                  v27 = (object->uAttributes & 0x20) == 0;
-                  v3->sZValue = v26 + (PID(OBJECT_Item,i));
-                  v3->dimming_level = 0;
-                  v3->sTintColor = 0;
-                  if ( !v27 )
-                  {
-                    if ( !pRenderer->pRenderD3D )
-                      v3->sZValue = 0;
-                  }
-                }
-                goto LABEL_34;
-              }
+              if ( !pRenderer->pRenderD3D )
+                pBillboardRenderList[::uNumBillboardsToDraw].sZValue = 0;
             }
+            //if (::uNumBillboardsToDraw >= 500)
+            //  return;
+            assert(::uNumBillboardsToDraw < 500);
+            ++::uNumBillboardsToDraw;
+            ++uNumSpritesDrawnThisFrame;
           }
-        //}
-LABEL_34:
-      ;
-      //++v41;
-      //v0 += 112;
-    //}
-    //while ( v41 < (signed int)uNumSpriteObjects );
+        }
+      }
+      else
+      {
+        v42 = fixpoint_mul((y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16, pGame->pIndoorCameraD3D->int_sine_y)
+            + fixpoint_mul((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16, pGame->pIndoorCameraD3D->int_cosine_y);
+        if ( v42 >= 0x40000 && v42 <= pODMRenderParams->shading_dist_mist << 16 )
+        {
+          v17 = fixpoint_mul((y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16, pGame->pIndoorCameraD3D->int_cosine_y)
+              - fixpoint_mul(((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16), pGame->pIndoorCameraD3D->int_sine_y);
+          v18 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
+          if ( abs(v42) >= abs(v17) )
+          {
+            LODWORD(v23) = 0;
+            HIDWORD(v23) = SLOWORD(pODMRenderParams->int_fov_rad);
+
+            object->uAttributes |= 1;
+            pBillboardRenderList[::uNumBillboardsToDraw].uPalette = frame->uPaletteIndex;
+            pBillboardRenderList[::uNumBillboardsToDraw].uIndoorSectorID = object->uSectorID;
+            pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_x_scaler_packedfloat = fixpoint_mul(frame->scale, v23 / v42);
+            pBillboardRenderList[::uNumBillboardsToDraw].pSpriteFrame = frame;
+            pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_y_scaler_packedfloat = fixpoint_mul(frame->scale, v23 / v42);
+            pBillboardRenderList[::uNumBillboardsToDraw].field_1E = v46;
+            pBillboardRenderList[::uNumBillboardsToDraw].world_x = x;
+            pBillboardRenderList[::uNumBillboardsToDraw].world_y = y;
+            pBillboardRenderList[::uNumBillboardsToDraw].world_z = z;
+            pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceX = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v23 / v42, v17) + 0x8000) >> 16);
+            pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceY = pViewport->uScreenCenterY - (((unsigned int)fixpoint_mul(v23 / v42, v18) + 0x8000) >> 16);
+            HIWORD(v26) = HIWORD(v42);
+            LOWORD(v26) = 0;
+            pBillboardRenderList[::uNumBillboardsToDraw].sZValue = v26 + (PID(OBJECT_Item,i));
+            pBillboardRenderList[::uNumBillboardsToDraw].dimming_level = 0;
+            pBillboardRenderList[::uNumBillboardsToDraw].sTintColor = 0;
+            if ( !(object->uAttributes & 0x20) )
+            {
+              if ( !pRenderer->pRenderD3D )
+                pBillboardRenderList[::uNumBillboardsToDraw].sZValue = 0;
+            }
+            //if (::uNumBillboardsToDraw >= 500)
+            //  return;
+            assert(::uNumBillboardsToDraw < 500);
+            ++::uNumBillboardsToDraw;
+            ++uNumSpritesDrawnThisFrame;
+          }
+        }
+      }
+    }
   }
 }
 
@@ -699,9 +666,7 @@
     memcpy(v20.pGUID, lpGUID, 0x10u);
   }
   else
-  {
     v20.pGUID = 0;
-  }
 
   if (FAILED(DirectDrawCreate(v20.pGUID, &pDirectDraw, 0)))
   {
@@ -723,10 +688,8 @@
     else
     {
       pDirectDraw->Release();
-      if (FAILED( pDirectDraw4->GetDeviceIdentifier(&ddDevId, 1u)))
-      {
+      if (FAILED( pDirectDraw4->GetDeviceIdentifier(&ddDevId, 1)))
         v20.pDDraw4DevDesc = 0;
-      }
       else
       {
         v7 = strlen(ddDevId.szDescription);
@@ -734,24 +697,17 @@
         strcpy(v20.pDDraw4DevDesc, ddDevId.szDescription);
       }
       memset(&ddsCaps, 0, 0x10u);
-      if (FAILED(pDirectDraw4->GetAvailableVidMem(
-             &ddsCaps,
-             (LPDWORD)&v20.uVideoMem,
-             (LPDWORD)&uFreeVideoMem)))
+      if (FAILED(pDirectDraw4->GetAvailableVidMem(&ddsCaps, (LPDWORD)&v20.uVideoMem, (LPDWORD)&uFreeVideoMem)))
         v20.uVideoMem = 0;
       memset(&v10, 0, 0x7Cu);
       v10.dwSize = 124;
       v10.dwFlags = 6;
-      v10.dwHeight = 640;
-      v10.dwWidth = 480;
+      v10.dwHeight = window->GetWidth();
+      v10.dwWidth = window->GetHeight();
       v10.ddpfPixelFormat.dwSize = 32;
 
       v19 = 0;
-      if ( FAILED(pDirectDraw4->EnumDisplayModes(
-             0,
-             0,
-             &v19,
-             (LPDDENUMMODESCALLBACK2)DDrawDisplayModesEnumerator))
+      if ( FAILED(pDirectDraw4->EnumDisplayModes(0, 0, &v19, (LPDDENUMMODESCALLBACK2)DDrawDisplayModesEnumerator))
         || !v19
         || FAILED(pDirectDraw4->QueryInterface(IID_IDirect3D3, (LPVOID *)&pDirect3D3)))
       {
@@ -872,28 +828,17 @@
     result = 0;
   }
   else
-  {
     result = 1;
-  }
   return result;
 }
 
 //----- (0047A95E) --------------------------------------------------------
 void Render::PrepareDecorationsRenderList_ODM()
 {
-  //char *v0; // esi@2
-  //DecorationDesc *v1; // ebx@6
-  __int16 v2; // ax@6
-  double v3; // st7@7
-  //int v4; // eax@9
-  //int v5; // edx@9
   unsigned int v6; // edi@9
   int v7; // eax@9
   SpriteFrame *v8; // eax@9
-  //SpriteFrame *v9; // edi@9
   unsigned __int16 *v10; // eax@9
-  int v11; // ecx@9
-  int v12; // eax@9
   int v13; // ecx@9
   int v14; // ecx@20
   char v15; // dl@20
@@ -904,57 +849,32 @@
   int v20; // ecx@24
   int v21; // ebx@26
   int v22; // eax@26
-  int v23; // eax@30
   signed __int64 v24; // qtt@31
   int v25; // ebx@31
-  int v26; // ecx@32
-  RenderBillboard *v27; // eax@37
-  __int16 v28; // dx@37
   __int16 v29; // cx@37
   int v30; // ecx@37
   int v31; // ebx@37
   Particle_sw local_0; // [sp+Ch] [bp-98h]@7
-  //int x; // [sp+74h] [bp-30h]@9
-  //int y; // [sp+78h] [bp-2Ch]@9
-  //int v35; // [sp+7Ch] [bp-28h]@1
-  //int v36; // [sp+80h] [bp-24h]@9
   unsigned __int16 *v37; // [sp+84h] [bp-20h]@9
   int v38; // [sp+88h] [bp-1Ch]@9
-  int v39; // [sp+8Ch] [bp-18h]@24
   int v40; // [sp+90h] [bp-14h]@24
   int v41; // [sp+94h] [bp-10h]@24
   int v42; // [sp+98h] [bp-Ch]@9
-  int a5; // [sp+9Ch] [bp-8h]@9
   int b; // [sp+A0h] [bp-4h]@22
 
-  //v35 = 0;
-  //if ( (signed int)uNumLevelDecorations > 0 )
-  //{
-    //v0 = (char *)&pLevelDecorations[0].vPosition.y;
-    //do
   for (int i = 0; i < uNumLevelDecorations; ++i)
   {
     LevelDecoration* decor = &pLevelDecorations[i];
-    char* v0 = (char *)&pLevelDecorations[i].vPosition.y;
-
     if ((!(decor->uFlags & LEVEL_DECORATION_OBELISK_CHEST) || decor->IsObeliskChestActive()) && !(decor->uFlags & LEVEL_DECORATION_INVISIBLE))
     {
-      //v1 = &pDecorationList->pDecorations[decor->uDecorationDescID];
       DecorationDesc* decor_desc = pDecorationList->pDecorations + decor->uDecorationDescID;
-      v2 = decor_desc->uFlags;
-      if ( (char)v2 >= 0 )
-      {
-        if ( !(v2 & 0x22) )
+      if ( (char)decor_desc->uFlags >= 0 )
+      {
+        if ( !(decor_desc->uFlags & 0x22) )
         {
-          //v4 = decor->vPosition.x;
-          //v5 = decor->vPosition.z;
           v6 = pMiscTimer->uTotalGameTimeElapsed;
-          //y = decor->vPosition.y;
-          //x = decor->vPosition.x;
-          //v36 = decor->vPosition.z;
           v7 = abs(decor->vPosition.x + decor->vPosition.y);
 
-
           #pragma region "New: seasons change"
           extern bool change_seasons;
           if (change_seasons)
@@ -1022,29 +942,20 @@
           #pragma endregion
           //v8 = pSpriteFrameTable->GetFrame(decor_desc->uSpriteID, v6 + v7);
 
-          //v9 = v8;
-          v42 = v8->uFlags;
-          a5 = v8->uGlowRadius;
           v10 = (unsigned __int16 *)stru_5C6E00->Atan2(decor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
                                                        decor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
-          v11 = *((int *)v0 + 2);
-          v37 = v10;
-          v12 = v42;
           v38 = 0;
-          v13 = ((signed int)(stru_5C6E00->uIntegerPi
-                            + ((signed int)stru_5C6E00->uIntegerPi >> 3)
-                            + v11
-                            - (signed int)v37) >> 8) & 7;
+          v13 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + decor->field_10_y_rot - (signed int)v10) >> 8) & 7;
           v37 = (unsigned __int16 *)v13;
-          if ( v42 & 2 )
+          if ( v8->uFlags & 2 )
             v38 = 2;
-          if ( (256 << v13) & v42 )
-            v38 |= 4u;
-          if ( v12 & 0x40000 )
-            v38 |= 0x40u;
-          if ( v12 & 0x20000 )
+          if ( (256 << v13) & v8->uFlags )
+            v38 |= 4;
+          if ( v8->uFlags & 0x40000 )
+            v38 |= 0x40;
+          if ( v8->uFlags & 0x20000 )
             LOBYTE(v38) = v38 | 0x80;
-          if ( a5 )
+          if ( v8->uGlowRadius )
           {
             if ( pRenderer->pRenderD3D && pRenderer->bUseColoredLights )
             {
@@ -1058,129 +969,125 @@
               v14 = 255;
               v15 = 255;
             }
-            b = v16;
-            pStationaryLightsStack->AddLight(
-              decor->vPosition.x,
-              decor->vPosition.y,
-              decor->vPosition.z + decor_desc->uDecorationHeight / 2,
-              a5,
-              v14,
-              v15,
-              v16,
-              _4E94D0_light_type);
+            pStationaryLightsStack->AddLight(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z + decor_desc->uDecorationHeight / 2,
+              v8->uGlowRadius, v14, v15, v16, _4E94D0_light_type);
           }
           v17 = (decor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
           if (pGame->pIndoorCameraD3D->sRotationX)
           {
             v40 = (decor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-            v18 = ((unsigned __int64)(v17 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
-                + ((unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
-            v42 = v18;
-            b = (unsigned __int64)(v17 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-            a5 = (unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
-            v40 = (decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-            v41 = (unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-            v19 = (unsigned __int64)(v18 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16;
-            v20 = v19 + ((unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
-            v39 = v19 + ((unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
-            if ( v20 >= 262144 && v20 <= pODMRenderParams->shading_dist_mist << 16 )
+            v18 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
+            v41 = fixpoint_mul((decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x);
+            v19 = fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_cosine_x);
+            v20 = v19 + fixpoint_mul((decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x);
+            if ( v20 >= 0x40000 && v20 <= pODMRenderParams->shading_dist_mist << 16 )
             {
-              v21 = a5 - b;
-              v41 = a5 - b;
-              a5 = (unsigned __int64)(v42 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-              b = (unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16;
-              v22 = ((unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16) - a5;
-LABEL_30:
-              v42 = v22;
-              v40 = 2 * abs(v20);
-              v23 = abs(v21);
-              if ( v40 >= v23 )
+              v21 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y) - fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_sine_y);
+              v22 = fixpoint_mul((decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_sine_x);
+              if ( 2 * abs(v20) >= abs(v21) )
               {
                 LODWORD(v24) = 0;
                 HIDWORD(v24) = SLOWORD(pODMRenderParams->int_fov_rad);
-                a5 = v24 / v39;
-                v25 = pViewport->uScreenCenterX
-                    - ((signed int)(((unsigned __int64)(v24 / v39 * v41) >> 16) + 32768) >> 16);
-                b = (unsigned __int64)(a5 * (signed __int64)v42) >> 16;
-                v41 = v24 / v39;
-                v40 = pViewport->uScreenCenterY
-                    - ((signed int)(((unsigned __int64)(a5 * (signed __int64)v42) >> 16) + 32768) >> 16);
-                v42 = v8->scale;
-                v41 = (unsigned __int64)(v42 * v24 / v39) >> 16;
-                v37 = (unsigned __int16 *)&v8->pHwSpriteIDs[(int)v37];
+                v25 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v24 / v20, v21) + 0x8000) >> 16);
+                v40 = pViewport->uScreenCenterY - ((signed int)(fixpoint_mul(v24 / v20, v22) + 0x8000) >> 16);
+                v41 = fixpoint_mul(v8->scale, v24 / v20);
                 if ( pRenderer->pRenderD3D )
-                {
-                  v26 = v41;
-                  v42 = pSprites_LOD->pHardwareSprites[(signed __int16)*v37].uBufferWidth >> 1;
-                  b = (unsigned __int64)(v42 * (signed __int64)v41) >> 16;
-                }
+                  b = fixpoint_mul(pSprites_LOD->pHardwareSprites[v8->pHwSpriteIDs[(int)v37]].uBufferWidth / 2, v41);
                 else
-                {
-                  v26 = v41;
-                  v42 = pSprites_LOD->pSpriteHeaders[(signed __int16)*v37].uWidth >> 1;
-                  b = (unsigned __int64)(v42 * (signed __int64)v41) >> 16;
-                }
+                  b = fixpoint_mul(pSprites_LOD->pSpriteHeaders[v8->pHwSpriteIDs[(int)v37]].uWidth / 2, v41);
                 if ( b + v25 >= (signed int)pViewport->uViewportTL_X && v25 - b <= (signed int)pViewport->uViewportBR_X )
                 {
                   if (::uNumBillboardsToDraw >= 500)
                     return;
-                  v27 = &pBillboardRenderList[::uNumBillboardsToDraw++];
-                  ++uNumDecorationsDrawnThisFrame;
-                  v27->uHwSpriteID = *v37;
-                  v28 = v8->uPaletteIndex;
-                  v27->_screenspace_x_scaler_packedfloat = v26;
-                  v27->_screenspace_y_scaler_packedfloat = v26;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uHwSpriteID = v8->pHwSpriteIDs[(int)v37];
+                  pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_x_scaler_packedfloat = v41;
+                  pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_y_scaler_packedfloat = v41;
                   v29 = v38;
-                  v27->uScreenSpaceX = v25;
-                  HIBYTE(v29) |= 2u;
-                  v27->uPalette = v28;
-                  v27->field_1E = v29;
-                  v27->world_x = decor->vPosition.x;
-                  v27->world_y = decor->vPosition.y;
-                  v27->world_z = decor->vPosition.z;
-                  v27->uScreenSpaceY = v40;
-                  HIWORD(v30) = HIWORD(v39);
+                  pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceX = v25;
+                  HIBYTE(v29) |= 2;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uPalette = v8->uPaletteIndex;
+                  pBillboardRenderList[::uNumBillboardsToDraw].field_1E = v29;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_x = decor->vPosition.x;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_y = decor->vPosition.y;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_z = decor->vPosition.z;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceY = v40;
+                  HIWORD(v30) = HIWORD(v20);
                   v31 = PID(OBJECT_Decoration,i);
                   LOWORD(v30) = 0;
-                  v27->uIndoorSectorID = 0;
-                  v27->sZValue = v30 + v31;
-                  v27->dimming_level = 0;
-                  v27->pSpriteFrame = v8;
-                  v27->sTintColor = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uIndoorSectorID = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].sZValue = v30 + v31;
+                  pBillboardRenderList[::uNumBillboardsToDraw].dimming_level = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].pSpriteFrame = v8;
+                  pBillboardRenderList[::uNumBillboardsToDraw].sTintColor = 0;
+                  ::uNumBillboardsToDraw++;
+                  ++uNumDecorationsDrawnThisFrame;
                 }
               }
-              goto LABEL_38;
+              continue;
             }
           }
           else
           {
             v42 = (decor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
             v40 = (decor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-            b = (unsigned __int64)(v17 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
-            a5 = (unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-            v20 = b + ((unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
-            v39 = b + ((unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
-            if ( v20 >= 262144 && v20 <= pODMRenderParams->shading_dist_mist << 16 )
+            v20 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
+            if ( v20 >= 0x40000 && v20 <= pODMRenderParams->shading_dist_mist << 16 )
             {
-              a5 = (unsigned __int64)(v42 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-              b = (unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
-              v21 = ((unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - a5;
-              v41 = ((unsigned __int64)(v40 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - a5;
+              v21 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y) - fixpoint_mul(v42, pGame->pIndoorCameraD3D->int_sine_y);
               v22 = (decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-              goto LABEL_30;
+              v42 = v22;
+              if ( 2 * abs(v20) >= abs(v21) )
+              {
+                LODWORD(v24) = 0;
+                HIDWORD(v24) = SLOWORD(pODMRenderParams->int_fov_rad);
+                v25 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v24 / v20, v21) + 0x8000) >> 16);
+                v40 = pViewport->uScreenCenterY - ((signed int)(fixpoint_mul(v24 / v20, v42) + 0x8000) >> 16);
+                v41 = fixpoint_mul(v8->scale, v24 / v20);
+                if ( pRenderer->pRenderD3D )
+                  b = fixpoint_mul(pSprites_LOD->pHardwareSprites[v8->pHwSpriteIDs[(int)v37]].uBufferWidth / 2, v41);
+                else
+                  b = fixpoint_mul(pSprites_LOD->pSpriteHeaders[v8->pHwSpriteIDs[(int)v37]].uWidth / 2, v41);
+                if ( b + v25 >= (signed int)pViewport->uViewportTL_X && v25 - b <= (signed int)pViewport->uViewportBR_X )
+                {
+                  if (::uNumBillboardsToDraw >= 500)
+                    return;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uHwSpriteID = v8->pHwSpriteIDs[(int)v37];
+                  pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_x_scaler_packedfloat = v41;
+                  pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_y_scaler_packedfloat = v41;
+                  v29 = v38;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceX = v25;
+                  HIBYTE(v29) |= 2;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uPalette = v8->uPaletteIndex;
+                  pBillboardRenderList[::uNumBillboardsToDraw].field_1E = v29;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_x = decor->vPosition.x;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_y = decor->vPosition.y;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_z = decor->vPosition.z;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceY = v40;
+                  HIWORD(v30) = HIWORD(v20);
+                  v31 = PID(OBJECT_Decoration,i);
+                  LOWORD(v30) = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uIndoorSectorID = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].sZValue = v30 + v31;
+                  pBillboardRenderList[::uNumBillboardsToDraw].dimming_level = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].pSpriteFrame = v8;
+                  pBillboardRenderList[::uNumBillboardsToDraw].sTintColor = 0;
+                  ::uNumBillboardsToDraw++;
+                  ++uNumDecorationsDrawnThisFrame;
+                }
+              }
+              continue;
             }
           }
         }
       }
       else
       {
-        memset(&local_0, 0, 0x68u);
-        v3 = (double)*((signed int *)v0 - 1);
+        memset(&local_0, 0, 0x68);
         local_0.type = ParticleType_Bitmap | ParticleType_Rotating | ParticleType_8;
         local_0.uDiffuse = 0xFF3C1E;
-        local_0.x = v3;
-        local_0.y = (double)*(signed int *)v0;
-        local_0.z = (double)*((signed int *)v0 + 1);
+        local_0.x = (double)decor->vPosition.x;
+        local_0.y = (double)decor->vPosition.y;
+        local_0.z = (double)decor->vPosition.z;
         local_0.r = 0.0;
         local_0.g = 0.0;
         local_0.b = 0.0;
@@ -1190,30 +1097,23 @@
         pGame->pParticleEngine->AddParticle(&local_0);
       }
     }
-LABEL_38:
-      ;
-      //++v35;
-      //v0 += 32;
-  }
-    //while ( v35 < (signed int)uNumLevelDecorations );
+  }
 }
 
 //----- (0049D717) --------------------------------------------------------
 HRESULT __stdcall D3DZBufferFormatEnumerator(DDPIXELFORMAT *Src, DDPIXELFORMAT *Dst)
 {
-  HRESULT v2; // esi@2
-
   if ( Src->dwFlags & (0x400 | 0x2000))
   {
-    v2 = 0;
     if ( Src->dwRGBBitCount == 16 && !Src->dwRBitMask )
-      goto LABEL_6;
+    {
+      memcpy(Dst, Src, sizeof(DDPIXELFORMAT));
+      return 0;
+    }
     if ( !Dst->dwSize )
     {
-      v2 = 1;
-LABEL_6:
       memcpy(Dst, Src, sizeof(DDPIXELFORMAT));
-      return v2;
+      return 1;
     }
   }
   return 1;
@@ -1529,7 +1429,7 @@
     sprintf(pErrorMessage, v23);
     goto LABEL_65;
   }
-  if (pHost->SetDisplayMode(640u, 480u, 16u, 0, 0) )
+  if (pHost->SetDisplayMode(window->GetWidth(), window->GetHeight(), 16, 0, 0) )
   {
     v23 = "Init - Failed to set display mode.\n";
     sprintf(pErrorMessage, v23);
@@ -1699,7 +1599,7 @@
   if (bClearDepth)
     uClearFlags |= D3DCLEAR_ZBUFFER;
   
-  D3DRECT rects[] = {{0, 0, 640, 480}};
+  D3DRECT rects[] = {{0, 0, window->GetWidth(), window->GetHeight()}};
   if (uClearFlags)
     pViewport->Clear2(1, rects, uClearFlags, uClearColor, z_clear, 0);
 }
@@ -1712,8 +1612,8 @@
 
   v5.left = 0;
   v5.top = 0;
-  v5.bottom = 480;
-  v5.right = 640;
+  v5.bottom = 480;//window->GetHeight(); //Ritor1: проблема с кнопкой "развернуть"
+  v5.right = 640; //window->GetWidth();
 
   if (bWindowed || bForceBlit)
   {
@@ -2054,11 +1954,11 @@
 //----- (0049E992) --------------------------------------------------------
 Render::Render()
 {
-  Render *v1; // esi@1
+  //Render *v1; // esi@1
   int v2; // eax@1
   char v3; // zf@1
 
-  v1 = this;
+  //v1 = this;
   this->pDirectDraw4 = 0;
   this->pFrontBuffer4 = 0;
   this->pBackBuffer4 = 0;
@@ -2069,41 +1969,41 @@
   //this->pSomeSurface2 = 0;
   //RenderHWLContainer::RenderHWLContainer(&this->pD3DBitmaps);
   //RenderHWLContainer::RenderHWLContainer(&v1->pD3DSprites);
-  v1->bWindowMode = 1;
-  //v1->field_40054 = 0;
-  //v1->field_10 = 640;
-  //v1->field_14 = 480;
-  //v1->field_40030 = 0;
-  //v1->field_4002C = 0;
-  v1->pActiveZBuffer = 0;
-  v1->pDefaultZBuffer = 0;
-  v1->raster_clip_y = 0;
-  v1->raster_clip_x = 0;
-  v1->raster_clip_z = 639;
-  v1->raster_clip_w = 479;
-  //v1->field_4003C = 0x004EED80;
-  //v1->field_40040 = dword_4EED78;
-  v1->uClipZ = 640;
-  //v1->field_40044 = 2;
-  //v1->field_40048 = 6;
-  v1->pFrontBuffer4 = 0;
-  v1->pBackBuffer4 = 0;
-  //v1->pColorKeySurface4 = 0;
-  v1->pDirectDraw4 = 0;
-  v1->pRenderD3D = 0;
-  v1->uNumSceneBegins = 0;
-  v1->uNumD3DSceneBegins = 0;
-  v1->using_software_screen_buffer = 0;
-  v1->pTargetSurface = 0;
-  v1->uTargetSurfacePitch = 0;
-  v1->uClipY = 0;
-  v1->uClipX = 0;
-  v1->uClipW = 480;
-  v1->bClip = 1;
-  //v1->bColorKeySupported = 0;
-  v1->bRequiredTextureStagesAvailable = 0;
-  v1->bTinting = 1;
-  //LOBYTE(v1->field_103668) = 0;
+  this->bWindowMode = 1;
+  //this->field_40054 = 0;
+  //this->field_10 = 640;
+  //this->field_14 = 480;
+  //this->field_40030 = 0;
+  //this->field_4002C = 0;
+  this->pActiveZBuffer = 0;
+  this->pDefaultZBuffer = 0;
+  this->raster_clip_y = 0;
+  this->raster_clip_x = 0;
+  this->raster_clip_z = 639;
+  this->raster_clip_w = 479;
+  //this->field_4003C = 0x004EED80;
+  //this->field_40040 = dword_4EED78;
+  this->uClipZ = 640;
+  //this->field_40044 = 2;
+  //this->field_40048 = 6;
+  this->pFrontBuffer4 = 0;
+  this->pBackBuffer4 = 0;
+  //this->pColorKeySurface4 = 0;
+  this->pDirectDraw4 = 0;
+  this->pRenderD3D = 0;
+  this->uNumSceneBegins = 0;
+  this->uNumD3DSceneBegins = 0;
+  this->using_software_screen_buffer = 0;
+  this->pTargetSurface = 0;
+  this->uTargetSurfacePitch = 0;
+  this->uClipY = 0;
+  this->uClipX = 0;
+  this->uClipW = 480;
+  this->bClip = 1;
+  //this->bColorKeySupported = 0;
+  this->bRequiredTextureStagesAvailable = 0;
+  this->bTinting = 1;
+  //LOBYTE(this->field_103668) = 0;
   uNumBillboardsToDraw = 0;
   bFogEnabled = false;
 
@@ -2275,16 +2175,16 @@
             lineB = (char *)lineRGB + 2 * pitch;
             for ( uint x = 0; x < this->GetRenderWidth(); x++ )
             {
-			  int p = *line_picture_data; //0x2818
-              int for_rad = (pRenderer->uTargetGBits + pRenderer->uTargetBBits );//16 = 8 + 8
-			  int value = (pRenderer->uTargetRMask & *line_picture_data);//0 = 0xFF0000 & 0x2818
-			  int result = (pRenderer->uTargetRMask & *line_picture_data) >> (pRenderer->uTargetGBits + pRenderer->uTargetBBits );
+			  //int p = *line_picture_data; //0x2818
+              //int for_rad = (pRenderer->uTargetGBits + pRenderer->uTargetBBits );//16 = 8 + 8
+			  //int value = (pRenderer->uTargetRMask & *line_picture_data);//0 = 0xFF0000 & 0x2818
+			  //int result = (pRenderer->uTargetRMask & *line_picture_data) >> (pRenderer->uTargetGBits + pRenderer->uTargetBBits );
               lineRGB[x] = (pRenderer->uTargetRMask & *line_picture_data) >> (pRenderer->uTargetGBits + pRenderer->uTargetBBits );// + pRenderer->uTargetRBits - 8);
               lineG[x] = (pRenderer->uTargetGMask & *line_picture_data) >> (pRenderer->uTargetBBits);// + pRenderer->uTargetGBits - 8);
-			  int value2 = (pRenderer->uTargetGMask & *line_picture_data); //10240 = 0xFF00 & 0x2818
-			  int result2 = (pRenderer->uTargetGMask & *line_picture_data) >> (pRenderer->uTargetBBits);
+			  //int value2 = (pRenderer->uTargetGMask & *line_picture_data); //10240 = 0xFF00 & 0x2818
+			  //int result2 = (pRenderer->uTargetGMask & *line_picture_data) >> (pRenderer->uTargetBBits);
               lineB[x] = (pRenderer->uTargetBMask & *line_picture_data);// << (8 - pRenderer->uTargetBBits);
-		      int value3 = (pRenderer->uTargetBMask & *line_picture_data);//24 = 0xFF & 0x2818
+		      //int value3 = (pRenderer->uTargetBMask & *line_picture_data);//24 = 0xFF & 0x2818
               line_picture_data += 2;
             }
           }
@@ -2766,31 +2666,28 @@
 //----- (0049FC37) --------------------------------------------------------
 void Render::Present()
 {
-  Render *v1; // esi@1
-  struct tagRECT Rect; // [sp+8h] [bp-28h]@11
-  RECT a4; // [sp+18h] [bp-18h]@11
-  struct tagPOINT Point; // [sp+28h] [bp-8h]@11
-
-  v1 = this;
+  //struct tagRECT Rect; // [sp+8h] [bp-28h]@11
+  //RECT a4; // [sp+18h] [bp-18h]@11
+  //struct tagPOINT Point; // [sp+28h] [bp-8h]@11
+
   if ( !pRenderer->pRenderD3D || this->using_software_screen_buffer )
   {
     this->pBeforePresentFunction();
-    if ( v1->pRenderD3D )
-    {
-      if ( v1->using_software_screen_buffer )
-      {
+    if ( this->pRenderD3D )
+    {
+      if ( this->using_software_screen_buffer )
         pRenderD3D->Present(false);
-      }
-    }
-    else __debugbreak(); // no sr
+    }
+    else
+      __debugbreak(); // no sr
     /*{
-      if ( v1->bWindowMode )
+      if ( this->bWindowMode )
       {
         RestoreFrontBuffer();
-        GetClientRect(v1->hWnd, &Rect);
+        GetClientRect(this->hWnd, &Rect);
         Point.y = 0;
         Point.x = 0;
-        ClientToScreen(v1->hWnd, &Point);
+        ClientToScreen(this->hWnd, &Point);
         OffsetRect(&Rect, Point.x, Point.y);
         a4.top = 0;
         a4.bottom = 480;
@@ -2830,9 +2727,9 @@
     v3 = v2->pBackBuffer4;
     v4 = v2->pFrontBuffer4;
     v5.top = 0;
-    v5.bottom = 480;
+    v5.bottom = window->GetHeight();
     v5.left = 0;
-    v5.right = 640;
+    v5.right = window->GetWidth();
     v3->BltFast(0, 0, v4, &v5, 16u);
   }
 }
@@ -3073,22 +2970,22 @@
         for (uint y = 0; y < 8; ++y)
           memcpy(pDst + y * Dst.lPitch / 2,
 
-		  pSrc + y * 640, 640 * sizeof(__int16));
+		  pSrc + y * window->GetWidth(), window->GetWidth() * sizeof(__int16));
 
         for (uint y = 8; y < 352; ++y)
         {
           memcpy(pDst + y * Dst.lPitch / 2,
-                 pSrc + y * 640, 8 * sizeof(__int16));
+                 pSrc + y * window->GetWidth(), 8 * sizeof(__int16));
           memcpy(pDst + 8 + game_viewport_width/*462*/ + y * Dst.lPitch / 2,
-                 pSrc + 8 + game_viewport_width/*462*/ + y * 640, 174/*172*/ * sizeof(__int16));
+                 pSrc + 8 + game_viewport_width/*462*/ + y * window->GetWidth(), 174/*172*/ * sizeof(__int16));
         }
 
-        for (uint y = 352; y < 480; ++y)
+        for (uint y = 352; y < window->GetHeight(); ++y)
           memcpy(pDst + y * Dst.lPitch / 2,
-                 pSrc + y * 640, 640 * sizeof(__int16));
-
-
-        ushort* pSrc_x1y1 = pSrc + 640 * pViewport->uViewportTL_Y + pViewport->uViewportTL_X;
+                 pSrc + y * window->GetWidth(), window->GetWidth() * sizeof(__int16));
+
+
+        ushort* pSrc_x1y1 = pSrc + window->GetWidth() * pViewport->uViewportTL_Y + pViewport->uViewportTL_X;
         //_this = (unsigned int)&pSrc[2 * (((signed int)pViewport->uViewportX >> 1) + 320 * pViewport->uViewportY)];
         short* pDst_x1y1 = pDst + Dst.lPitch * pViewport->uViewportTL_Y + pViewport->uViewportTL_X;
         //v23 = (unsigned __int32)((char *)v26 + 4 * (((signed int)pViewport->uViewportX >> 1) + (Dst.lPitch >> 2) * pViewport->uViewportY));
@@ -3110,8 +3007,8 @@
           //       pSrc + pViewport->uViewportX + y * 640, (pViewport->uViewportZ - pViewport->uViewportX) * sizeof(__int16));
           for (uint x = pViewport->uViewportTL_X; x < pViewport->uViewportBR_X; ++x)
           {
-            if (pSrc[y * 640 + x] != (g_mask | b_mask))
-              pDst[y * Dst.lPitch / 2 + x] = pSrc[y * 640 + x];
+            if (pSrc[y * window->GetWidth() + x] != (g_mask | b_mask))
+              pDst[y * Dst.lPitch / 2 + x] = pSrc[y * window->GetWidth() + x];
           }
         }
         }
@@ -3374,7 +3271,7 @@
     {
       pTargetSurface = 0;
       pTargetSurface_unaligned = 0;
-      pTargetSurface_unaligned = (unsigned int *)malloc(640 * 480 * 2 + 32);
+      pTargetSurface_unaligned = (unsigned int *)malloc(window->GetWidth() * window->GetHeight() * 2 + 32);
       if ( !pTargetSurface_unaligned
         || (memset(&pDesc, 0, 0x7Cu),
             pDesc.dwSize = 124,
@@ -3384,7 +3281,7 @@
       v22 = (int *)pTargetSurface_unaligned + 4;
       v23 = (unsigned int)pDesc.lpSurface & 7;
       LOBYTE(v22) = (unsigned __int8)v22 & 0xF8;
-      uTargetSurfacePitch = 640;
+      uTargetSurfacePitch = window->GetWidth();
       pBeforePresentFunction = Present_NoColorKey;
       v15 = 1;
       pTargetSurface = (unsigned __int32 *)((char *)v22 + 2 * v23);
@@ -4096,8 +3993,8 @@
     a2.dwFlags = 7;
     v7 = 0;
     a2.ddsCaps.dwCaps = 2112;
-    a2.dwWidth = 640;
-    a2.dwHeight = 480;
+    a2.dwWidth = window->GetWidth();
+    a2.dwHeight = window->GetHeight();
     v6 = 2387;
     ppBackBuffer = (IDirectDrawSurface **)&v1->pBackBuffer4;
     v4 = (struct _DDSURFACEDESC *)&a2;
@@ -4992,13 +4889,13 @@
   for ( _507D30_idx; _507D30_idx < pSkyPolygon.uNumVertices; _507D30_idx++ )
   {
     //v15 = (void *)(v72 * (v70 - (int)array_507D30[_507D30_idx].vWorldViewProjY));
-    v77 = (unsigned __int64)(pSkyPolygon.ptr_38->viewing_angle_from_west_east * (signed __int64)(v72 * (v70 - array_507D30[_507D30_idx].vWorldViewProjY))) >> 16;
+    v77 = fixpoint_mul(pSkyPolygon.ptr_38->viewing_angle_from_west_east, v72 * (v70 - array_507D30[_507D30_idx].vWorldViewProjY));
     v74 = v77 + pSkyPolygon.ptr_38->angle_from_north;
 
-    v77 = (unsigned __int64)(pSkyPolygon.ptr_38->viewing_angle_from_north_south * (signed __int64)(v72 * (v70 - array_507D30[_507D30_idx].vWorldViewProjY))) >> 16;
+    v77 = fixpoint_mul(pSkyPolygon.ptr_38->viewing_angle_from_north_south, v72 * (v70 - array_507D30[_507D30_idx].vWorldViewProjY));
     v74_ = v77 + pSkyPolygon.ptr_38->angle_from_east;
 
-    v79 = (void *)(((unsigned __int64)(pSkyPolygon.v_18.z * (signed __int64)v72 * (v70 - (int)array_507D30[_507D30_idx].vWorldViewProjY))) >> 16);
+    v79 = (void *)(fixpoint_mul(pSkyPolygon.v_18.z, v72 * (v70 - (int)array_507D30[_507D30_idx].vWorldViewProjY)));
     v17 = v72 * (pBLVRenderParams->uViewportCenterX - (int)array_507D30[_507D30_idx].vWorldViewProjX);
     v18 = array_507D30[_507D30_idx].vWorldViewProjY - 1.0;
     v19 = -pSkyPolygon.field_24;
@@ -5019,8 +4916,8 @@
       v19 = v77;
       v20 = v79;
 LABEL_14:
-      v79 = (void *)((unsigned __int64)(pSkyPolygon.v_18.z * (signed __int64)(signed int)v20) >> 16);
-      v22 = (unsigned __int64)(pSkyPolygon.v_18.z * (signed __int64)(signed int)v20) >> 16;
+      v79 = (void *)fixpoint_mul(pSkyPolygon.v_18.z, (int)v20);
+      v22 = fixpoint_mul(pSkyPolygon.v_18.z, (int)v20);
       --LODWORD(v76);
       v20 = (char *)v20 + v72;
       X = v22 + pSkyPolygon.v_18.x;
@@ -5032,16 +4929,16 @@
       HIDWORD(v23) = v77 >> 16;//v23 = 0xfffffe0000000000
       v79 = (void *)(v23 / X);//X = FFFF9014(-28652)
       v77 = v17;
-      signed __int64 s = v74 + ((pSkyPolygon.ptr_38->angle_from_west * (signed __int64)v17) >> 16);// s = 0xFFFFFFFF FFFF3EE6
-      LODWORD(v80) = v66 + ((signed int)((unsigned __int64)(SLODWORD(s) * (v23 / X)) >> 16) >> 4);
+      signed __int64 s = v74 + fixpoint_mul(pSkyPolygon.ptr_38->angle_from_west, v17);// s = 0xFFFFFFFF FFFF3EE6
+      LODWORD(v80) = v66 + ((signed int)fixpoint_mul(SLODWORD(s), v23 / X) >> 4);
       array_507D30[_507D30_idx].u = ((double)SLODWORD(v80) * 0.000015259022) * (1.0 / (double)pSkyPolygon.pTexture->uTextureWidth);
 
-      signed __int64 s2 = (signed __int64)(v74_ + ((unsigned __int64)(pSkyPolygon.ptr_38->angle_from_south * (signed __int64)v17) >> 16));
-      LODWORD(v80) = v63 + ((signed int)((unsigned __int64)(SLODWORD(s2) * (v23 / X)) >> 16) >> 4);
+      signed __int64 s2 = v74_ + fixpoint_mul(pSkyPolygon.ptr_38->angle_from_south, v17);
+      LODWORD(v80) = v63 + ((signed int)fixpoint_mul(SLODWORD(s2), v23 / X) >> 4);
       array_507D30[_507D30_idx].v = ((double)SLODWORD(v80) * 0.000015259022) * v68;
 
-      v77 = (unsigned __int64)(SLODWORD(s) * (v23 / X)) >> 16;
-      LODWORD(v73) = (unsigned __int64)(SLODWORD(s2) * (v23 / X)) >> 16;
+      v77 = fixpoint_mul(SLODWORD(s), v23 / X);
+      LODWORD(v73) = fixpoint_mul(SLODWORD(s2), v23 / X);
       array_507D30[_507D30_idx]._rhw = 65536.0 / (double)(signed int)v79;
 
       //if ( (int)v81 >= pSkyPolygon.uNumVertices )
@@ -5106,19 +5003,18 @@
     v35 = (const void *)(v72 * (v70 - (unsigned __int64)(signed __int64)array_50AC10[j].vWorldViewProjY));
 
     //v78 = pSkyPolygon.ptr_38->viewing_angle_from_west_east;
-    v81 = (const void *)((unsigned __int64)(pSkyPolygon.ptr_38->viewing_angle_from_west_east * (signed __int64)(signed int)v35) >> 16);
-    v36 = (int)((char *)v81 + pSkyPolygon.ptr_38->angle_from_north);
+    //v81 = (const void *)fixpoint_mul(pSkyPolygon.ptr_38->viewing_angle_from_west_east, v35);
+    v36 = (int)(fixpoint_mul(pSkyPolygon.ptr_38->viewing_angle_from_west_east, (int)v35) + pSkyPolygon.ptr_38->angle_from_north);
 
     v81 = v35;
     v74 = v36;
     //v78 = pSkyPolygon.ptr_38->viewing_angle_from_north_south;
-    v81 = (const void *)((unsigned __int64)(pSkyPolygon.ptr_38->viewing_angle_from_north_south * (signed __int64)(signed int)v35) >> 16);
+    v81 = (const void *)fixpoint_mul(pSkyPolygon.ptr_38->viewing_angle_from_north_south, (int)v35);
     v78 = (int)v35;
     v75 = (RenderVertexSoft *)((char *)v81 + pSkyPolygon.ptr_38->angle_from_east);
-    v81 = (const void *)pSkyPolygon.v_18.z;
-    v78 = (unsigned __int64)(pSkyPolygon.v_18.z * (signed __int64)(signed int)v35) >> 16;
-    v37 = (const void *)(v72
-                       * (pBLVRenderParams->uViewportCenterX - (unsigned __int64)(signed __int64)array_50AC10[j].vWorldViewProjX));
+    //v81 = (const void *)pSkyPolygon.v_18.z;
+    v78 = fixpoint_mul(pSkyPolygon.v_18.z, (int)v35);
+    v37 = (const void *)(v72 * (pBLVRenderParams->uViewportCenterX - (unsigned __int64)(signed __int64)array_50AC10[j].vWorldViewProjX));
     v38 = (signed __int64)(array_50AC10[j].vWorldViewProjY - 1.0);
     v81 = 0;
     LODWORD(v76) = v38;
@@ -5136,7 +5032,7 @@
       v39 = v78;
 LABEL_36:
       v78 = pSkyPolygon.v_18.z;
-      v41 = (unsigned __int64)(pSkyPolygon.v_18.z * (signed __int64)v39) >> 16;
+      v41 = fixpoint_mul(pSkyPolygon.v_18.z, v39);
       --LODWORD(v76);
       v39 += v72;
       X = v41 + pSkyPolygon.v_18.x;
@@ -5146,11 +5042,8 @@
     {
       v79 = (void *)pSkyPolygon.v_18.z;
       v78 = 2 * LODWORD(v76);
-      v81 = (const void *)((unsigned __int64)(pSkyPolygon.v_18.z
-                                            * (signed __int64)(signed int)(signed __int64)(((double)v70
-                                                                                          - ((double)(2 * LODWORD(v76))
-                                                                                           - array_50AC10[j].vWorldViewProjY))
-                                                                                         * (double)v72)) >> 16);
+      v81 = (const void *)fixpoint_mul(pSkyPolygon.v_18.z, (((double)v70 - ((double)(2 * LODWORD(v76)) - array_50AC10[j].vWorldViewProjY))
+                                                                                         * (double)v72));
       X = (int)((char *)v81 + pSkyPolygon.v_18.x);
     }
     LODWORD(v42) = v77 << 16;
@@ -5159,23 +5052,23 @@
     v81 = v37;
 
     //v78 = pSkyPolygon.ptr_38->angle_from_west;
-    v81 = (const void *)((unsigned __int64)(pSkyPolygon.ptr_38->angle_from_west * (signed __int64)(signed int)v37) >> 16);
-    v43 = v74 + ((unsigned __int64)(pSkyPolygon.ptr_38->angle_from_west * (signed __int64)(signed int)v37) >> 16);
+    v81 = (const void *)fixpoint_mul(pSkyPolygon.ptr_38->angle_from_west, (int)v37);
+    v43 = v74 + fixpoint_mul(pSkyPolygon.ptr_38->angle_from_west, (int)v37);
     v74 = (unsigned int)v37;
     LODWORD(v76) = v43;
 
     //v78 = pSkyPolygon.ptr_38->angle_from_south;
-    v75 = (RenderVertexSoft *)((char *)v75 + ((unsigned __int64)(pSkyPolygon.ptr_38->angle_from_south * (signed __int64)(signed int)v37) >> 16));
-    v74 = (unsigned __int64)(v43 * v42 / X) >> 16;
-    v81 = (const void *)((unsigned __int64)((signed int)v75 * v42 / X) >> 16);
+    v75 = (RenderVertexSoft *)((char *)v75 + fixpoint_mul(pSkyPolygon.ptr_38->angle_from_south, (int)v37));
+    //v74 = fixpoint_mul(v43, v42 / X);
+    v81 = (const void *)fixpoint_mul((int)v75, v42 / X);
 
     //v34 += 48;
-    v78 = v66 + ((signed int)v74 >> 4);
+    //v78 = v66 + ((signed int)fixpoint_mul(v43, v42 / X) >> 4);
     //v44 = HIDWORD(v69)-- == 1;
-    v45 = (double)v78 * 0.000015259022;
-    v78 = v63 + ((signed int)((unsigned __int64)((signed int)v75 * v42 / X) >> 16) >> 4);
-    array_50AC10[j].u = v45 * (1.0 / (double)pSkyPolygon.pTexture->uTextureWidth);
-    array_50AC10[j].v = (double)v78 * 0.000015259022 * v68;
+    //v45 = (double)(v66 + ((signed int)fixpoint_mul(v43, v42 / X) >> 4)) * 0.000015259022;
+    //v78 = v63 + ((signed int)fixpoint_mul((int)v75, v42 / X) >> 4);
+    array_50AC10[j].u = ((double)(v66 + ((signed int)fixpoint_mul(v43, v42 / X) >> 4)) * 0.000015259022) * (1.0 / (double)pSkyPolygon.pTexture->uTextureWidth);
+    array_50AC10[j].v = ((double)(v66 + ((signed int)fixpoint_mul(v43, v42 / X) >> 4)) * 0.000015259022) * v68;
     //v46 = (double)(signed int)v79;
     array_50AC10[j].vWorldViewPosition.x = 0.000015258789 * (double)(signed int)v79;
     array_50AC10[j]._rhw = 65536.0 / (double)(signed int)v79;
@@ -6591,7 +6484,7 @@
   this->uClipX = 0;
   this->bClip = 1;
   this->uClipW = 480;
-  this->uClipZ = 640;
+  this->uClipZ = window->GetWidth();
 }
 
 unsigned __int32 Color32(unsigned __int16 color16)
@@ -6906,24 +6799,24 @@
 //----- (004A6DF5) --------------------------------------------------------
 void Render::_4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7)
 {
-  int v8; // ecx@3
-  unsigned __int16 *v10; // ebx@4
-  int v11; // esi@4
+  int width; // ecx@3
+  unsigned __int16 *pixels; // ebx@4
+  int height; // esi@4
 
   if ( !pBitmap || !pTarget)
     return;
 
-  v8 = a7->z - a7->x;
-  v11 = a7->w - a7->y;
-  v10 = (unsigned short *)pTarget + a7->x + uTargetPitch * a7->y;
-  for ( int y = 0; y < v11; ++y )
-  {
-    for ( int x = 0; x < v8; ++x )
-    {
-      WritePixel16(a7->x + x, a7->y + y, *v10);
-      ++v10;
-    }
-    v10 += uTargetPitch - v8;
+  width = a7->z - a7->x;
+  height = a7->w - a7->y;
+  pixels = (unsigned short *)pTarget + a7->x + uTargetPitch * a7->y;
+  for ( int y = 0; y < height; ++y )
+  {
+    for ( int x = 0; x < width; ++x )
+    {
+      WritePixel16(a7->x + x, a7->y + y, *pixels);
+      ++pixels;
+    }
+    pixels += uTargetPitch - width;
   }
 }
 
@@ -7846,7 +7739,7 @@
     {
       v6 = uOutY;
       v7 = pTexture->uTextureHeight;
-      pZBuffer = &this->pActiveZBuffer[uOutX + 640 * uOutY];
+      pZBuffer = &this->pActiveZBuffer[uOutX + window->GetWidth() * uOutY];
       uOutYa = v5->pLevelOfDetail0_prolly_alpha_mask;
       v8 = v5->uTextureWidth;
       v20 = v5->uTextureWidth;
@@ -7867,7 +7760,7 @@
         {
           uOutYa += v19 * (v11 - v6);
           v7 += v6 - v11;
-          pZBuffer += 640 * (v11 - v6);
+          pZBuffer += window->GetWidth() * (v11 - v6);
           v8 = v20;
         }
         v12 = this->uClipX;
@@ -7911,7 +7804,7 @@
             }
             while ( v18 );
           }
-          pZBuffer += 640 - v8;
+          pZBuffer += window->GetWidth() - v8;
           uOutYa += v19 - v8;
           --uOutXa;
         }
@@ -7994,7 +7887,7 @@
           memset32(v8, a5, pTexturea);
           v8 = (char *)v8 + 4 * pTexturea;
         }
-        v8 = (char *)v8 + 4 * (640 - pTexturea);
+        v8 = (char *)v8 + 4 * (window->GetWidth() - pTexturea);
         --v6;
       }
       while ( v6 );
@@ -8782,10 +8675,10 @@
             array_77EC08[pODMRenderParams->uNumPolygons].pODMFace = &pOutdoor->pBModels[model_id].pFaces[face_id];
             array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices;
             array_77EC08[pODMRenderParams->uNumPolygons].field_59 = 5;
-            v51 = (unsigned __int64)(-pOutdoor->vSunlight.x * (signed __int64)pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.x) >> 16;
-            v53 = (unsigned __int64)(-pOutdoor->vSunlight.y * (signed __int64)pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.y) >> 16;
-            v52 = (unsigned __int64)(-pOutdoor->vSunlight.z * (signed __int64)pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.z) >> 16;
-            array_77EC08[pODMRenderParams->uNumPolygons].dimming_level = 20 - (20 * (signed int)(v51 + v53 + v52) >> 16);
+            v51 = fixpoint_mul(-pOutdoor->vSunlight.x, pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.x);
+            v53 = fixpoint_mul(-pOutdoor->vSunlight.y, pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.y);
+            v52 = fixpoint_mul(-pOutdoor->vSunlight.z, pOutdoor->pBModels[model_id].pFaces[face_id].pFacePlane.vNormal.z);
+            array_77EC08[pODMRenderParams->uNumPolygons].dimming_level = 20 - fixpoint_mul(20, v51 + v53 + v52);
             if ( array_77EC08[pODMRenderParams->uNumPolygons].dimming_level < 0 )
               array_77EC08[pODMRenderParams->uNumPolygons].dimming_level = 0;
             if ( array_77EC08[pODMRenderParams->uNumPolygons].dimming_level > 31 )
@@ -8948,13 +8841,13 @@
       // направление на север и/или юг (либо на восток и/или запад), значению 65536 еденицам(0х10000) соответствует угол 90.
       // две переменные хранят данные по углу обзора. field_14 по западу и востоку. field_20 по югу и северу
       // от -25080 до 25080
-      v39 = (unsigned __int64)(pSkyPolygon.ptr_38->viewing_angle_from_west_east * (signed __int64)(v33 * (v30 - floor(array_50AC10[i].vWorldViewProjY + 0.5)))) >> 16;
+      v39 = fixpoint_mul(pSkyPolygon.ptr_38->viewing_angle_from_west_east, v33 * (v30 - floor(array_50AC10[i].vWorldViewProjY + 0.5)));
       v35 = v39 + pSkyPolygon.ptr_38->angle_from_north;
 
-      v39 = (unsigned __int64)(pSkyPolygon.ptr_38->viewing_angle_from_north_south * (signed __int64)(v33 * (v30 - floor(array_50AC10[i].vWorldViewProjY + 0.f)))) >> 16;
+      v39 = fixpoint_mul(pSkyPolygon.ptr_38->viewing_angle_from_north_south, v33 * (v30 - floor(array_50AC10[i].vWorldViewProjY + 0.f)));
       v36 = v39 + pSkyPolygon.ptr_38->angle_from_east;
 
-      v9 = (unsigned __int64)(pSkyPolygon.v_18.z * (signed __int64)(v33 * (v30 - floor(array_50AC10[i].vWorldViewProjY + 0.5)))) >> 16;
+      v9 = fixpoint_mul(pSkyPolygon.v_18.z, v33 * (v30 - floor(array_50AC10[i].vWorldViewProjY + 0.5)));
       v10 = pSkyPolygon.v_18.x + v9;
       if ( v10 > 0 )
         v10 = 0;
@@ -8974,7 +8867,7 @@
               break;
           }
         }
-        v16 = (unsigned __int64)(pSkyPolygon.v_18.z * (signed __int64)v14) >> 16;
+        v16 = fixpoint_mul(pSkyPolygon.v_18.z, v14);
         --v32;
         v14 += v33;
         v10 = pSkyPolygon.v_18.x + v16;
@@ -8984,14 +8877,12 @@
       v18 = v17 / v10;
       if ( v18 < 0 )
         v18 = pODMRenderParams->shading_dist_mist;
-      v37 = v35 + ((unsigned __int64)(pSkyPolygon.ptr_38->angle_from_west * (signed __int64)v13) >> 16);
-      v35 = 224 * pMiscTimer->uTotalGameTimeElapsed
-          + ((signed int)((unsigned __int64)(v37 * (signed __int64)v18) >> 16) >> 3);
+      v37 = v35 + fixpoint_mul(pSkyPolygon.ptr_38->angle_from_west, v13);
+      v35 = 224 * pMiscTimer->uTotalGameTimeElapsed + ((signed int)fixpoint_mul(v37, v18) >> 3);
       array_50AC10[i].u = (double)v35 / ((double)pSkyPolygon.pTexture->uTextureWidth * 65536.0);
 
-      v36 = v36 + ((unsigned __int64)(pSkyPolygon.ptr_38->angle_from_south * (signed __int64)v13) >> 16);
-      v35 = 224 * pMiscTimer->uTotalGameTimeElapsed
-         + ((signed int)((unsigned __int64)(v36 * (signed __int64)v18) >> 16) >> 3);
+      v36 = v36 + fixpoint_mul(pSkyPolygon.ptr_38->angle_from_south, v13);
+      v35 = 224 * pMiscTimer->uTotalGameTimeElapsed + ((signed int)fixpoint_mul(v36, v18) >> 3);
       array_50AC10[i].v = (double)v35 / ((double)pSkyPolygon.pTexture->uTextureHeight * 65536.0);
 
       array_50AC10[i].vWorldViewPosition.x = (double)0x2000;//pODMRenderParams->shading_dist_mist 8192
@@ -9072,6 +8963,19 @@
       for (uint x = 0; x < width; ++x)
       {
         //*v3 = pRenderer->ReadPixel16((int)(x* interval_x + 8.0), (int)(y * interval_y + 8.0));//screen_data[screen_y + (int)(x* interval_x + 8.0)];
+		  /*
+        if (ddpfPrimarySuface.dwRGBBitCount == 32)
+        {
+          auto p = (unsigned __int32 *)pRenderer->pTargetSurface + (int)(x * interval_x + 8.0) + (int)(y * interval_y + 8.0) * pRenderer->uTargetSurfacePitch;
+          *v3 = Color16((*p >> 16) & 255, (*p >> 8) & 255, *p & 255);
+        }
+        else if (ddpfPrimarySuface.dwRGBBitCount == 16)
+        {
+          auto p = (unsigned __int16 *)pRenderer->pTargetSurface + (int)(x * interval_x + 8.0) + (int)(y * interval_y + 8.0) * pRenderer->uTargetSurfacePitch;
+          *v3 = *p;
+        }
+		  */
+		  pRenderer->pTargetSurface;
         if (Dst.ddpfPixelFormat.dwRGBBitCount == 32)
         {
           auto p = (unsigned __int32 *)Dst.lpSurface + (int)(x * interval_x + 8.0) + y/* (int)(y * interval_y + 8.0)*/ * Dst.lPitch;
--- a/SpriteObject.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/SpriteObject.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -274,9 +274,7 @@
     }
   }
   else
-  {
     v58 = 1;
-  }
   if ( !(object->uFlags & OBJECT_DESC_NO_GRAVITY) )
   {
     if ( v58 )
@@ -493,21 +491,19 @@
                   + face->pFacePlane.vNormal.z * pSpriteObjects[uLayingItemID].vVelocity.z) >> 16;
           if ( (stru_721530.speed >> 3) > v56 )
             v56 = stru_721530.speed >> 3;
-          v57 = (unsigned __int64)(v56 * (signed __int64)face->pFacePlane.vNormal.x) >> 16;
-          v58 = (unsigned __int64)(v56 * (signed __int64)face->pFacePlane.vNormal.y) >> 16;
-          v60 = (unsigned __int64)(v56 * (signed __int64)face->pFacePlane.vNormal.z) >> 16;
-          pSpriteObjects[uLayingItemID].vVelocity.x += 2 * v57;
-          pSpriteObjects[uLayingItemID].vVelocity.y += 2 * v58;
+          //v57 = fixpoint_mul(v56, face->pFacePlane.vNormal.x);
+          //v58 = fixpoint_mul(v56, face->pFacePlane.vNormal.y);
+          v60 = fixpoint_mul(v56, face->pFacePlane.vNormal.z);
+          pSpriteObjects[uLayingItemID].vVelocity.x += 2 * fixpoint_mul(v56, face->pFacePlane.vNormal.x);
+          pSpriteObjects[uLayingItemID].vVelocity.y += 2 * fixpoint_mul(v56, face->pFacePlane.vNormal.y);
           if ( face->pFacePlane.vNormal.z <= 32000 )
-          {
             v37 = 2 * (short)v60;
-          }
           else
           {
             v36 = v60;
             pSpriteObjects[uLayingItemID].vVelocity.z += (signed __int16)v60;
-            v58 = (unsigned __int64)(32000 * (signed __int64)(signed int)v36) >> 16;
-            v37 = (unsigned int)(32000 * v36) >> 16;
+            v58 = fixpoint_mul(0x7D00, v36);
+            v37 = fixpoint_mul(32000, v36);
           }
           pSpriteObjects[uLayingItemID].vVelocity.z += v37;
           if ( BYTE3(face->uAttributes) & 0x10 )
@@ -518,7 +514,7 @@
         if ( pSpriteObjects[uLayingItemID].vVelocity.x * pSpriteObjects[uLayingItemID].vVelocity.x
            + pSpriteObjects[uLayingItemID].vVelocity.y * pSpriteObjects[uLayingItemID].vVelocity.y >= 400 )
         {
-          if ( BYTE3(face->uAttributes) & 0x10 )
+          if ( face->uAttributes & 0x10000000 )
             EventProcessor(face->sCogTriggeredID, 0, 1);
           goto LABEL_74;
         }
@@ -536,8 +532,8 @@
                      + pSpriteObjects[uLayingItemID].vVelocity.y * pSpriteObjects[uLayingItemID].vVelocity.y);
     v38 = stru_5C6E00->Atan2(pSpriteObjects[uLayingItemID].vPosition.x - pLevelDecorations[PID_ID(stru_721530.uFaceID)].vPosition.x,
                              pSpriteObjects[uLayingItemID].vPosition.y - pLevelDecorations[PID_ID(stru_721530.uFaceID)].vPosition.y);
-    pSpriteObjects[uLayingItemID].vVelocity.x = (unsigned __int64)(stru_5C6E00->Cos(v38) * (signed __int64)v57) >> 16;
-    pSpriteObjects[uLayingItemID].vVelocity.y = (unsigned __int64)(stru_5C6E00->Sin(v38 - stru_5C6E00->uIntegerHalfPi) * (signed __int64)v57) >> 16;
+    pSpriteObjects[uLayingItemID].vVelocity.x = fixpoint_mul(stru_5C6E00->Cos(v38), v57);
+    pSpriteObjects[uLayingItemID].vVelocity.y = fixpoint_mul(stru_5C6E00->Sin(v38 - stru_5C6E00->uIntegerHalfPi), v57);
     goto LABEL_74;
   }
 }
--- a/Sprites.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Sprites.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -13,7 +13,7 @@
 #include "MM7.h"
 #include "Actor.h"
 #include "Level/Decoration.h"
-
+#include "OurMath.h"
 
 
 
@@ -784,8 +784,7 @@
                                   if ( v14 > 0 )
                                   {
                                     v15 = v5->vPosition.z;
-                                    v16 = stru_721530.normal.z
-                                        + ((unsigned __int64)(stru_721530.direction.z * (signed __int64)v14) >> 16);
+                                    v16 = stru_721530.normal.z + fixpoint_mul(stru_721530.direction.z, v14);
                                     if ( v16 >= v15 )
                                     {
                                       if ( v16 <= v22 + v15 )
--- a/UI/Books/UISpellBook.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/Books/UISpellBook.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -103,7 +103,7 @@
           {
             pX_coord = pViewport->uViewportTL_X +  pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][i]].Xpos;
             pY_coord = pViewport->uViewportTL_Y +  pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][i]].Ypos;
-            if ( BYTE1(pTexture->pBits) & 2 )
+            if ( pTexture->pBits & 0x200 )
               pRenderer->DrawTextureTransparent(pX_coord, pY_coord, pTexture);
             else
               pRenderer->DrawTextureIndexed(pX_coord, pY_coord, pTexture);
@@ -123,7 +123,7 @@
     {
       pX_coord = pViewport->uViewportTL_X + pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][v10]].Xpos;
       pY_coord = pViewport->uViewportTL_Y + pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][v10]].Ypos;
-      if ( BYTE1(SBPageCSpellsTextureList[v10]->pBits) & 2 )
+      if ( SBPageCSpellsTextureList[v10]->pBits & 0x200 )
         pRenderer->DrawTextureTransparent(pX_coord, pY_coord, SBPageCSpellsTextureList[v10]);
       else
         pRenderer->DrawTextureIndexed(pX_coord, pY_coord, SBPageCSpellsTextureList[v10]);
--- a/UI/UICharacter.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UICharacter.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -394,7 +394,7 @@
   CharacterUI_LoadPaperdollTextures();
   pCurrentScreen = _this;
 
-  pWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_CharacterRecord, uActiveCharacter, 0);
+  pWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CharacterRecord, uActiveCharacter, 0);
   pCharacterScreen_StatsBtn = pWindow->CreateButton(pViewport->uViewportTL_X + 12, pViewport->uViewportTL_Y + 308,
                                 pIcons_LOD->GetTexture(papredoll_dbrds[9])->uTextureWidth,
                                 pIcons_LOD->GetTexture(papredoll_dbrds[9])->uTextureHeight,
@@ -425,9 +425,9 @@
                  1, 0, UIMSG_ClickExitCharacterWindowBtn, 0, 0, pGlobalTXT_LocalizationStrings[79],//Exit
                  pIcons_LOD->GetTexture(papredoll_dbrds[2]),
                  pIcons_LOD->GetTexture(papredoll_dbrds[1]), 0);
-  pWindow->CreateButton(0, 0, 0x1DCu, 0x159u, 1, 122, UIMSG_InventoryLeftClick, 0, 0, "", 0);
-  pCharacterScreen_DetalizBtn = pWindow->CreateButton(0x258u, 0x12Cu, 30, 30, 1, 0, UIMSG_ChangeDetaliz, 0, 0, pGlobalTXT_LocalizationStrings[64], 0);
-  pCharacterScreen_DollBtn = pWindow->CreateButton(0x1DCu, 0, 0xA4u, 0x159u, 1, 0, UIMSG_ClickPaperdoll, 0, 0, "", 0);
+  pWindow->CreateButton(0, 0, 476, 345, 1, 122, UIMSG_InventoryLeftClick, 0, 0, "", 0);
+  pCharacterScreen_DetalizBtn = pWindow->CreateButton(600, 300, 30, 30, 1, 0, UIMSG_ChangeDetaliz, 0, 0, pGlobalTXT_LocalizationStrings[64], 0);
+  pCharacterScreen_DollBtn = pWindow->CreateButton(476, 0, 164, 345, 1, 0, UIMSG_ClickPaperdoll, 0, 0, "", 0);
 
   pWindow->CreateButton( 61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
   pWindow->CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
@@ -449,7 +449,7 @@
   bRingsShownInCharScreen = 0;
   CharacterUI_LoadPaperdollTextures();
   pCurrentScreen = SCREEN_CASTING;
-  CS_inventory_window = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell_InInventory, (int)this, 0);
+  CS_inventory_window = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CastSpell_InInventory, (int)this, 0);
   pCharacterScreen_ExitBtn = CS_inventory_window->CreateButton(394, 318, 75, 33, 1, 0, UIMSG_ClickExitCharacterWindowBtn, 0, 0,
                  pGlobalTXT_LocalizationStrings[79], // Close
                  pIcons_LOD->GetTexture(papredoll_dbrds[2]),
@@ -2731,7 +2731,7 @@
     for ( i = pGUIWindow_CurrentMenu->pControlsHead; i; i = j )
     {
       j = i->pNext;
-      if ( BYTE1(i->field_1C) & 0x80 )
+      if ( i->field_1C & 0x8000 )
       {
         i->Release();
         free(i);
--- a/UI/UIHouses.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UIHouses.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -1008,7 +1008,7 @@
         return;
       }
       pDialogueWindow->Release();
-      pDialogueWindow = GUIWindow::Create(0, 0, 640, 345, WINDOW_MainMenu, 0, 0);
+      pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), 345, WINDOW_MainMenu, 0, 0);
       pBtn_ExitCancel = pDialogueWindow->CreateButton(526, 445, 75, 33, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[74],// "End Conversation"
                                                        pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);
       pDialogueWindow->CreateButton(8, 8, 450, 320, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", nullptr);
@@ -1020,7 +1020,7 @@
           || in_current_building_type != BuildingType_Temple || uMessageParam != BuildingType_MindGuild )
       {
         pDialogueWindow->Release();
-        pDialogueWindow = GUIWindow::Create(0, 0, 640, 345, WINDOW_MainMenu, 0, 0);
+        pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), 345, WINDOW_MainMenu, 0, 0);
         pBtn_ExitCancel = pDialogueWindow->CreateButton(526, 445, 75, 33, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[74],// "End Conversation"
                                                          pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);
         pDialogueWindow->CreateButton(8, 8, 450, 320, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", nullptr);
@@ -2019,9 +2019,9 @@
     {
       if ( pArcomageGame->bGameInProgress == 1 )
         return;
-      if ( pArcomageGame->uGameResult )
+      if ( pArcomageGame->uGameWinner )
       {
-        if ( pArcomageGame->uGameResult == 1 )
+        if ( pArcomageGame->uGameWinner == 1 )
           pText = pGlobalTXT_LocalizationStrings[640];// You won!
         else
           pText = pGlobalTXT_LocalizationStrings[641];// You lost!
--- a/UI/UIMainMenu.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UIMainMenu.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -23,8 +23,8 @@
   pPaletteManager->SetColorChannelInfo(5, 6, 5);
   pPaletteManager->RecalculateAll();
 
-  for (uint i = 0; i < 480; ++i)
-    pSRZBufferLineOffsets[i] = 640 * i;
+  for (uint i = 0; i < window->GetHeight(); ++i)
+    pSRZBufferLineOffsets[i] = window->GetWidth() * i;
 
   pRenderer->ResetTextureClipRect();
 
@@ -101,7 +101,7 @@
   uTextureID_BUTTMAKE = pIcons_LOD->LoadTexture("BUTTMAKE", TEXTURE_16BIT_PALETTE);
   uTextureID_BUTTMAKE2 = pIcons_LOD->LoadTexture("BUTTMAKE2", TEXTURE_16BIT_PALETTE);
 
-  pPrimaryWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
+  pPrimaryWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
   pPrimaryWindow->CreateButton(7, 8, 460, 343, 1, 0, UIMSG_MouseLeftClickInGame, 0, 0, "", 0);
 
   pPrimaryWindow->CreateButton(61, 424, 31, 80, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);//buttons for portraits
@@ -284,7 +284,7 @@
     cred_texture.uHeight, Color16(0x70u, 0x8Fu, 0xFEu), Color16(0xECu, 0xE6u, 0x9Cu), pString, cred_texture.pPixels, cred_texture.uWidth);
   free(pString);
 
-  pWindow_MainMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, cred_texturet);
+  pWindow_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, cred_texturet);
   pWindow_MainMenu->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_Escape, 0, 27, "", 0);
   pCurrentScreen = SCREEN_CREATORS;
   SetCurrentMenuID(MENU_CREDITSPROC);
--- a/UI/UIPartyCreation.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UIPartyCreation.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -101,7 +101,7 @@
   pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
   uPlayerCreationUI_SkySliderPos = (GetTickCount() % 12800) / 20;
   pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos, 2, pTexture_MAKESKY);
-  pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos - 640, 2, pTexture_MAKESKY);
+  pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos - window->GetWidth(), 2, pTexture_MAKESKY);
   pRenderer->DrawTextureTransparent(0, 0, pTexture_MAKETOP);
 
   uPlayerCreationUI_SelectedCharacter = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem) / 7;
@@ -115,7 +115,7 @@
       Error("Invalid selected character");
   }
 
-  pTextCenter = pFontCChar->AlignText_Center(640, pGlobalTXT_LocalizationStrings[51]);
+  pTextCenter = pFontCChar->AlignText_Center(window->GetWidth(), pGlobalTXT_LocalizationStrings[51]);
   pGUIWindow_CurrentMenu->DrawText(pFontCChar, pTextCenter + 1, 0, 0, pGlobalTXT_LocalizationStrings[51], 0, 0, 0);//С О З Д А Т Ь  О Т Р Я Д
   pRenderer->DrawTextureTransparent(17, 35, pPlayerPortraits[pParty->pPlayers[0].uCurrentFace]);
   pRenderer->DrawTextureTransparent(176, 35, pPlayerPortraits[pParty->pPlayers[1].uCurrentFace]);
@@ -426,7 +426,7 @@
     pTextures_arrowr[uControlParam] = pIcons_LOD->LoadTexturePtr(pTmpBuf.data(), TEXTURE_16BIT_PALETTE);
   }
   while ( ++uControlParam < 20 );
-  pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
+  pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
   uControlParam = 0;
   uX = 8;
   do
@@ -435,7 +435,7 @@
     uX += 158;
     ++uControlParam;
   }
-  while ( (signed int)uX < 640 );
+  while ( (signed int)uX < window->GetWidth() );
 
   pCreationUI_BtnPressLeft[0]   = pGUIWindow_CurrentMenu->CreateButton( 10,  32, 11, 13, 1, 0, UIMSG_PlayerCreation_FacePrev,  0, 0, "", pTexture_presleft, 0);
   pCreationUI_BtnPressLeft[1]   = pGUIWindow_CurrentMenu->CreateButton(169,  32, 11, 13, 1, 0, UIMSG_PlayerCreation_FacePrev,  1, 0, "", pTexture_presleft, 0);
@@ -465,7 +465,7 @@
     uX += 158;
     ++uControlParam;
   }
-  while ( (signed int)uX < 640 );
+  while ( (signed int)uX < window->GetWidth() );
 
   pGUIWindow_CurrentMenu->CreateButton(  5, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 0, '1', "", 0);
   pGUIWindow_CurrentMenu->CreateButton(163, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 1, '2', "", 0);
@@ -580,9 +580,7 @@
       DispatchMessageA(&Msg);
     }
     if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
-    {
       WaitMessage();
-    }
     else
     {
       PlayerCreationUI_Draw();
--- a/UI/UIPopup.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UIPopup.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -425,7 +425,7 @@
 // 506128: using guessed type int areWeLoadingTexture;
 
 //----- (0041E360) --------------------------------------------------------
-void MonsterPopup_Draw(unsigned int uActorID, GUIWindow *window)
+void MonsterPopup_Draw(unsigned int uActorID, GUIWindow *pWindow)
 {
   int v8; // eax@4
   unsigned __int16 v9; // dx@4
@@ -512,18 +512,18 @@
   v106.pTarget = pRenderer->pTargetSurface;
   v106.pTargetZ = pRenderer->pActiveZBuffer;
   v106.uTargetPitch = pRenderer->uTargetSurfacePitch;
-  v106.uViewportX = window->uFrameX + 13;
-  v106.uViewportY = window->uFrameY + 52;
-  v106.uViewportW = (window->uFrameY + 52) + 128;
+  v106.uViewportX = pWindow->uFrameX + 13;
+  v106.uViewportY = pWindow->uFrameY + 52;
+  v106.uViewportW = (pWindow->uFrameY + 52) + 128;
   v106.uViewportZ = v106.uViewportX + 128;
   v106.uScreenSpaceX = (signed int)(v106.uViewportX + 128 + v106.uViewportX) / 2;
   v106._screenspace_x_scaler_packedfloat = 65536;
   v106._screenspace_y_scaler_packedfloat = 65536;
-  v106.uScreenSpaceY = v115 + (window->uFrameY + 52) + pSprites_LOD->pSpriteHeaders[v10->pHwSpriteIDs[0]].uHeight;
+  v106.uScreenSpaceY = v115 + (pWindow->uFrameY + 52) + pSprites_LOD->pSpriteHeaders[v10->pHwSpriteIDs[0]].uHeight;
   v106.pPalette = PaletteManager::Get_Dark_or_Red_LUT(v10->uPaletteIndex, 0, 1);
   v106.sZValue = 0;
   v106.uFlags = 0;
-  pRenderer->SetRasterClipRect(0, 0, 639, 479);
+  pRenderer->SetRasterClipRect(0, 0, window->GetWidth() - 1, window->GetHeight() - 1);
   pRenderer->RasterLine2D(v106.uViewportX - 1, v106.uViewportY - 1, v106.uViewportX + 129, v106.uViewportY - 1, Color16(0xE1u, 255, 0x9Bu));//горизонтальная верхняя линия
   pRenderer->RasterLine2D(v106.uViewportX - 1, v106.uViewportW + 1, v106.uViewportX - 1, v106.uViewportY - 1, Color16(0xE1u, 255, 0x9Bu));//горизонтальная нижняя линия
   pRenderer->RasterLine2D(v106.uViewportX + 129, v106.uViewportW + 1, v106.uViewportX - 1, v106.uViewportW + 1, Color16(0xE1u, 255, 0x9Bu));//левая вертикальная линия
@@ -662,9 +662,9 @@
     else
       strncpy(pTmpBuf.data(), pMonsterStats->pInfos[pActors[uActorID].pMonsterInfo.uID].pName, 2000);
   }
-  window->DrawTitleText(pFontComic, 0, 0xCu, Color16(0xFFu, 0xFFu, 0x9Bu), pTmpBuf.data(), 3);
+  pWindow->DrawTitleText(pFontComic, 0, 0xCu, Color16(0xFFu, 0xFFu, 0x9Bu), pTmpBuf.data(), 3);
   //health bar
-  Actor::DrawHealthBar(&pActors[uActorID], window);
+  Actor::DrawHealthBar(&pActors[uActorID], pWindow);
 
   normal_level = 0;
   expert_level = 0;
@@ -734,9 +734,9 @@
     for_effects = 1;
   }
 
-  window->DrawText(pFontSmallnum, 12, 196, Color16(0xE1u, 255, 0x9Bu), pGlobalTXT_LocalizationStrings[631], 0, 0, 0);//Effects
+  pWindow->DrawText(pFontSmallnum, 12, 196, Color16(0xE1u, 255, 0x9Bu), pGlobalTXT_LocalizationStrings[631], 0, 0, 0);//Effects
   if ( !for_effects && false)
-    window->DrawText(pFontSmallnum, 28, LOBYTE(pFontSmallnum->uFontHeight) + 193, Color16(0xE1u, 255, 0x9Bu), pGlobalTXT_LocalizationStrings[630], 0, 0, 0);//?
+    pWindow->DrawText(pFontSmallnum, 28, LOBYTE(pFontSmallnum->uFontHeight) + 193, Color16(0xE1u, 255, 0x9Bu), pGlobalTXT_LocalizationStrings[630], 0, 0, 0);//?
   else
   {
     pText = "";
@@ -834,30 +834,30 @@
         }
         if ( _stricmp(pText, "" ))
         {
-          window->DrawText(pFontSmallnum, 28, pTextHeight, GetSpellColor(pTextColorID), pText, 0, 0, 0);
+          pWindow->DrawText(pFontSmallnum, 28, pTextHeight, GetSpellColor(pTextColorID), pText, 0, 0, 0);
           pTextHeight = pTextHeight + *(char *)((int)pFontSmallnum + 5) - 3;
         }
       }
     }
     if ( !_stricmp(pText,"" ))
-      window->DrawText(pFontSmallnum, 28, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pGlobalTXT_LocalizationStrings[153], 0, 0, 0);//Нет
+      pWindow->DrawText(pFontSmallnum, 28, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pGlobalTXT_LocalizationStrings[153], 0, 0, 0);//Нет
   }
 
   if ( normal_level )
   {
     sprintf(pTmpBuf.data(), "%s\f%05u\t100%d\n", pGlobalTXT_LocalizationStrings[108], 0, pActors[uActorID].pMonsterInfo.uHP);
-    window->DrawText(pFontSmallnum, 150, (int)v106.uViewportY, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+    pWindow->DrawText(pFontSmallnum, 150, (int)v106.uViewportY, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
     pTextHeight = v106.uViewportY + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     sprintf(pTmpBuf.data(), "%s\f%05u\t100%d\n", pGlobalTXT_LocalizationStrings[12], 0, pActors[uActorID].pMonsterInfo.uAC);//Armor Class
   }
   else
   {
     sprintf(pTmpBuf.data(), "%s\f%05u\t100%s\n", pGlobalTXT_LocalizationStrings[108], 0, pGlobalTXT_LocalizationStrings[630]);//?   - [630] actually displays a question mark
-    window->DrawText(pFontSmallnum, 150, (int)v106.uViewportY, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+    pWindow->DrawText(pFontSmallnum, 150, (int)v106.uViewportY, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
     pTextHeight = v106.uViewportY + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     sprintf(pTmpBuf.data(), "%s\f%05u\t100%s\n", pGlobalTXT_LocalizationStrings[12], 0, pGlobalTXT_LocalizationStrings[630]);//?   - [630] actually displays a question mark
   }
-  window->DrawText(pFontSmallnum, 150, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+  pWindow->DrawText(pFontSmallnum, 150, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
   pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 6 + LOBYTE(pFontSmallnum->uFontHeight);
 
   content[0] = pGlobalTXT_LocalizationStrings[87];
@@ -875,7 +875,7 @@
   if ( expert_level )
   {
     sprintf(pTmpBuf.data(), "%s\f%05u\t080%s\n", pGlobalTXT_LocalizationStrings[18], 0, content[pActors[uActorID].pMonsterInfo.uAttack1Type]);//Attack
-    window->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+    pWindow->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
     pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     if ( pActors[uActorID].pMonsterInfo.uAttack1DamageBonus )
       sprintf(pTmpBuf.data(), "%s\f%05u\t080%dd%d+%d\n", pGlobalTXT_LocalizationStrings[53],
@@ -887,17 +887,17 @@
   else
   {
     sprintf(pTmpBuf.data(), "%s\f%05u\t080%s\n", pGlobalTXT_LocalizationStrings[18], 0, pGlobalTXT_LocalizationStrings[630]);
-    window->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+    pWindow->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
     pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     sprintf(pTmpBuf.data(), "%s\f%05u\t080%s\n", pGlobalTXT_LocalizationStrings[53], 0, pGlobalTXT_LocalizationStrings[630]);
   }
-  window->DrawText(pFontSmallnum, 150, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+  pWindow->DrawText(pFontSmallnum, 150, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
   pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 6 + LOBYTE(pFontSmallnum->uFontHeight);
 
   if ( !master_level )
   {
     sprintf(pTmpBuf.data(), "%s\f%05u\t080%s\n", pGlobalTXT_LocalizationStrings[628], 0, pGlobalTXT_LocalizationStrings[630]);//"Spell" "?"
-    window->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+    pWindow->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
     pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
   }
   else
@@ -908,24 +908,24 @@
     if ( pActors[uActorID].pMonsterInfo.uSpell1ID )
     {
       sprintf(pTmpBuf.data(), "%s\f%05u\t070%s\n", pText, 0, pSpellStats->pInfos[pActors[uActorID].pMonsterInfo.uSpell1ID].pShortName);//"%s\f%05u\t060%s\n"
-      window->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+      pWindow->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
       pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     }
     if ( pActors[uActorID].pMonsterInfo.uSpell2ID )
     {
       sprintf(pTmpBuf.data(), "\f%05u\t070%s\n", 0, pSpellStats->pInfos[pActors[uActorID].pMonsterInfo.uSpell2ID].pShortName);//"%s\f%05u\t060%s\n"
-      window->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+      pWindow->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
       pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     }
     if ( !pActors[uActorID].pMonsterInfo.uSpell1ID && !pActors[uActorID].pMonsterInfo.uSpell2ID )
     {
       sprintf(pTmpBuf.data(), "%s\f%05u\t070%s\n", pGlobalTXT_LocalizationStrings[628], 0, pGlobalTXT_LocalizationStrings[153]);//"%s\f%05u\t060%s\n"
-      window->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+      pWindow->DrawText(pFontSmallnum, 150, (int)pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
       pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     }
   }
   pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
-  window->DrawText(pFontSmallnum, 150, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pGlobalTXT_LocalizationStrings[626], 0, 0, 0);//Immune
+  pWindow->DrawText(pFontSmallnum, 150, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pGlobalTXT_LocalizationStrings[626], 0, 0, 0);//Immune
   pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
 
   string_name[0] = pGlobalTXT_LocalizationStrings[87];//Fire
@@ -966,7 +966,7 @@
           pText = pGlobalTXT_LocalizationStrings[153];//None
       }
       sprintf(pTmpBuf.data(), "%s\f%05u\t070%s\n", string_name[i], 0, pText);
-      window->DrawText(pFontSmallnum, 170, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+      pWindow->DrawText(pFontSmallnum, 170, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
       pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     }
   }
@@ -975,7 +975,7 @@
     for ( uint i = 0; i < 10; ++i )
     {
       sprintf(pTmpBuf.data(), "%s\f%05u\t070%s\n", string_name[i], 0, pGlobalTXT_LocalizationStrings[630]); // "?"
-      window->DrawText(pFontSmallnum, 170, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
+      pWindow->DrawText(pFontSmallnum, 170, pTextHeight, Color16(0xE1u, 255, 0x9Bu), pTmpBuf.data(), 0, 0, 0);
       pTextHeight = pTextHeight + LOBYTE(pFontSmallnum->uFontHeight) - 3;
     }
   }
@@ -984,7 +984,7 @@
   {
     sprintf(pTmpBuf.data(), "%s: %d", pGlobalTXT_LocalizationStrings[650], pActors[uActorID].sCurrentHP);//Current Hit Points
     pFontSmallnum->GetLineWidth(pTmpBuf.data());
-    window->DrawTitleText(pFontSmallnum, 0, window->uFrameHeight - LOBYTE(pFontSmallnum->uFontHeight) - 12, 0, pTmpBuf.data(), 3);
+    pWindow->DrawTitleText(pFontSmallnum, 0, pWindow->uFrameHeight - LOBYTE(pFontSmallnum->uFontHeight) - 12, 0, pTmpBuf.data(), 3);
   }
 }
 
--- a/UI/UIRest.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UIRest.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -63,7 +63,7 @@
   uTextureID_RestUI_restb4 = pIcons_LOD->LoadTexture("restb4", TEXTURE_16BIT_PALETTE);
   uTextureID_RestUI_restexit = pIcons_LOD->LoadTexture("restexit", TEXTURE_16BIT_PALETTE);
   LoadActualSkyFrame();
-  pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Rest, 0, 0);
+  pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Rest, 0, 0);
   pButton_RestUI_Exit          = pGUIWindow_CurrentMenu->CreateButton(280, 297, 154, 37, 1, 0, UIMSG_ExitRest,       0,   0, "", pIcons_LOD->GetTexture(uTextureID_RestUI_restexit), 0);
   pButton_RestUI_Main          = pGUIWindow_CurrentMenu->CreateButton( 24, 154, 225, 37, 1, 0, UIMSG_Rest8Hour,      0, 'R', "", pIcons_LOD->GetTexture(uTextureID_RestUI_restb4), 0);
   pButton_RestUI_WaitUntilDawn = pGUIWindow_CurrentMenu->CreateButton( 61, 232, 154, 33, 1, 0, UIMSG_AlreadyResting, 0, 'D', "", pIcons_LOD->GetTexture(uTextureID_RestUI_restb1), 0);
--- a/UI/UISaveLoad.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UISaveLoad.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -308,7 +308,7 @@
   uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_saveD", TEXTURE_16BIT_PALETTE);
   uTextureID_AR_UP_DN = pIcons_LOD->LoadTexture("AR_UP_DN", TEXTURE_16BIT_PALETTE);
   uTextureID_AR_DN_DN = pIcons_LOD->LoadTexture("AR_DN_DN", TEXTURE_16BIT_PALETTE);
-  pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_SaveLoadButtons, 0, 0);
+  pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SaveLoadButtons, 0, 0);
   pGUIWindow_CurrentMenu->CreateButton(21, 198, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 0, 0, "", 0);
   pGUIWindow_CurrentMenu->CreateButton(21, 218, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 1, 0, "", 0);
   pGUIWindow_CurrentMenu->CreateButton(21, 238, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 2, 0, "", 0);
--- a/UI/UIShops.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UIShops.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -79,7 +79,7 @@
         if ( pParty->StandartItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][i].uItemID)
         {
           pRenderer->DrawTextureTransparent((60 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2)) + item_X, weapons_Ypos[i] + 30, ItemsInShopTexture[i]);
-          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[(60 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2)) + item_X + 640 * (weapons_Ypos[i] + 30)], ItemsInShopTexture[i], i + 1);
+          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[(60 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2)) + item_X + window->GetWidth() * (weapons_Ypos[i] + 30)], ItemsInShopTexture[i], i + 1);
         }
         item_X += 70;
       }
@@ -130,7 +130,7 @@
         if (pParty->SpecialItemsInShops[(unsigned int)window_SpeakInHouse->ptr_1C][i].uItemID)
         {
           pRenderer->DrawTextureTransparent((60 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2)) + item_X, weapons_Ypos[i] + 30, ItemsInShopTexture[i]);
-          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[(60 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2)) + item_X + 640 * (weapons_Ypos[i] + 30)], ItemsInShopTexture[i], i + 1);
+          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[(60 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2)) + item_X + window->GetWidth() * (weapons_Ypos[i] + 30)], ItemsInShopTexture[i], i + 1);
         }
         item_X += 70;
       }
@@ -412,7 +412,7 @@
           else
           {
             pRenderer->DrawTextureTransparent(( 86 - (ItemsInShopTexture[i]->uTextureWidth / 2)) + item_x, 98 -  ItemsInShopTexture[i]->uTextureHeight, ItemsInShopTexture[i]);
-            v59 = item_x + (86 - (ItemsInShopTexture[i]->uTextureWidth / 2)) + 640 * (98 -  ItemsInShopTexture[i]->uTextureHeight);
+            v59 = item_x + (86 - (ItemsInShopTexture[i]->uTextureWidth / 2)) + window->GetWidth() * (98 -  ItemsInShopTexture[i]->uTextureHeight);
           }
           ZBuffer_DoFill(&pRenderer->pActiveZBuffer[v59], ItemsInShopTexture[i], i + 1);
         }
@@ -471,7 +471,7 @@
           else
           {
             pRenderer->DrawTextureTransparent(86 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2) + item_x, 98 - ItemsInShopTexture[i]->uTextureHeight, ItemsInShopTexture[i]);
-            v59 = (86 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2)) + item_x + 640 * (98 - ItemsInShopTexture[i]->uTextureHeight);
+            v59 = (86 - ((signed int)ItemsInShopTexture[i]->uTextureWidth / 2)) + item_x + window->GetWidth() * (98 - ItemsInShopTexture[i]->uTextureHeight);
           }
           ZBuffer_DoFill(&pRenderer->pActiveZBuffer[v59], ItemsInShopTexture[i], i + 1);
         }
@@ -765,7 +765,7 @@
           else if ( (signed int)product_width_1row < 18 )
             product_width_1row = 18;
           pRenderer->DrawTextureTransparent(product_width_1row, product_height_1row, ItemsInShopTexture[i]);
-          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_1row + 640 * product_height_1row], ItemsInShopTexture[i], i + 1);
+          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_1row + window->GetWidth() * product_height_1row], ItemsInShopTexture[i], i + 1);
         }
       }
       for ( uint i = 0; i < 6; ++i )
@@ -790,7 +790,7 @@
               product_width_2row = 18;
           }
           pRenderer->DrawTextureTransparent(product_width_2row, product_height_2row, ItemsInShopTexture[i + 6]);
-          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_2row + 640 * product_height_2row], ItemsInShopTexture[i + 6], i + 7);
+          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_2row + window->GetWidth() * product_height_2row], ItemsInShopTexture[i + 6], i + 7);
         }
       }
       if ( HouseUI_CheckIfPlayerCanInteract() )
@@ -853,7 +853,7 @@
               product_width_1row = 18;
           }
           pRenderer->DrawTextureTransparent(product_width_1row, product_height_1row, ItemsInShopTexture[i]);
-          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_1row + 640 * product_height_1row], ItemsInShopTexture[i], i + 1);
+          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_1row + window->GetWidth() * product_height_1row], ItemsInShopTexture[i], i + 1);
         }
       }
       for ( uint i = 0; i < 6; ++i )
@@ -878,7 +878,7 @@
               product_width_2row = 18;
           }
           pRenderer->DrawTextureTransparent(product_width_2row, product_height_2row, ItemsInShopTexture[i + 6]);
-          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_2row + 640 * product_height_2row], ItemsInShopTexture[i + 6], i + 7);
+          ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_2row + window->GetWidth() * product_height_2row], ItemsInShopTexture[i + 6], i + 7);
         }
       }
       if ( HouseUI_CheckIfPlayerCanInteract() )
@@ -1142,7 +1142,7 @@
             product_width_1row = 18;
         }
         pRenderer->DrawTextureTransparent(product_width_1row, product_height_1row, ItemsInShopTexture[i]);
-        ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_1row + 640 * product_height_1row], ItemsInShopTexture[i], i + 1);
+        ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_1row + window->GetWidth() * product_height_1row], ItemsInShopTexture[i], i + 1);
       }
     }
     for ( uint i = 0; i < 6; ++i )
@@ -1165,7 +1165,7 @@
             product_width_2row = 18;
         }
         pRenderer->DrawTextureTransparent(product_width_2row, product_height_2row, ItemsInShopTexture[i + 6]);
-        ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_2row + 640 * product_height_2row], ItemsInShopTexture[i + 6], i + 7);
+        ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_2row + window->GetWidth() * product_height_2row], ItemsInShopTexture[i + 6], i + 7);
       }
     }
     if ( HouseUI_CheckIfPlayerCanInteract() )
@@ -1228,7 +1228,7 @@
             product_width_1row = 18;
         }
         pRenderer->DrawTextureTransparent(product_width_1row, product_height_1row, ItemsInShopTexture[i]);
-        ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_1row + 640 * product_height_1row], ItemsInShopTexture[i], i + 1);
+        ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_1row + window->GetWidth() * product_height_1row], ItemsInShopTexture[i], i + 1);
       }
     }
     for ( uint i = 0; i < 6; ++i )
@@ -1253,7 +1253,7 @@
             product_width_2row = 18;
         }
         pRenderer->DrawTextureTransparent(product_width_2row, product_height_2row, ItemsInShopTexture[i + 6]);
-        ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_2row + 640 * product_height_2row], ItemsInShopTexture[i + 6], i + 7);
+        ZBuffer_DoFill2(&pRenderer->pActiveZBuffer[product_width_2row + window->GetWidth() * product_height_2row], ItemsInShopTexture[i + 6], i + 7);
       }
     }
     if ( HouseUI_CheckIfPlayerCanInteract() )
--- a/UI/UITransition.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UITransition.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -56,7 +56,7 @@
     if ( pMapStats->GetMapInfo(pCurrentMapName) )
     {
       sprintfex(sHouseName.data(), pGlobalTXT_LocalizationStrings[410], pMapStats->pInfos[pMapStats->GetMapInfo(pCurrentMapName)].pName); // "Leave %s"
-      pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_Transition, 0, sHouseName.data());
+      pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Transition, 0, sHouseName.data());
       //if ( pAnimatedRooms[p2DEvents[anim_id].uAnimationID].uRoomSoundId )
         //PlayHouseSound(anim_id, HouseSound_Greeting);
       if ( uCurrentlyLoadedLevelType == LEVEL_Indoor && uActiveCharacter && pParty->uFlags & 0x30 )
@@ -66,7 +66,7 @@
       return;
     }
     strcpy(sHouseName.data(), pGlobalTXT_LocalizationStrings[79]);
-    pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_Transition, 0, sHouseName.data());
+    pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Transition, 0, sHouseName.data());
     //if ( pAnimatedRooms[p2DEvents[anim_id].uAnimationID].uRoomSoundId )
       //PlayHouseSound(anim_id, HouseSound_Greeting);
     if ( uCurrentlyLoadedLevelType == LEVEL_Indoor && uActiveCharacter && pParty->uFlags & 0x30 )
@@ -81,7 +81,7 @@
   if ( pMapStats->GetMapInfo(v15) )
   {
     sprintfex(sHouseName.data(), pGlobalTXT_LocalizationStrings[411], pMapStats->pInfos[pMapStats->GetMapInfo(v15)].pName);//Войти в ^Pv[%s]
-    pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_Transition, 0, sHouseName.data());
+    pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Transition, 0, sHouseName.data());
     if ( uCurrentlyLoadedLevelType == LEVEL_Indoor && uActiveCharacter && pParty->uFlags & 0x30 )
       pPlayers[uActiveCharacter]->PlaySound(SPEECH_47, 0);
     if ( IndoorLocation::GetLocationIndex(pLocationName) )
@@ -89,7 +89,7 @@
     return;
   }
   strcpy(sHouseName.data(), pGlobalTXT_LocalizationStrings[73]);//Войти
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_Transition, 0, sHouseName.data());
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Transition, 0, sHouseName.data());
   //if ( pAnimatedRooms[p2DEvents[anim_id].uAnimationID].uRoomSoundId )
     //PlayHouseSound(anim_id, HouseSound_Greeting);
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor && uActiveCharacter && pParty->uFlags & 0x30 )
@@ -119,7 +119,7 @@
     sprintfex(sHouseName.data(), pGlobalTXT_LocalizationStrings[410], pMapStats->pInfos[pMapStats->GetMapInfo(pCurrentMapName)].pName);// "Leave %s"
   else
     strcpy(sHouseName.data(), pGlobalTXT_LocalizationStrings[79]);// "Exit"
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_ChangeLocation, 0, sHouseName.data());
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_ChangeLocation, 0, sHouseName.data());
 }
 
 //----- (00444DCA) --------------------------------------------------------
--- a/UI/UiGame.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/UI/UiGame.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -308,7 +308,7 @@
   }
   if (sDialogue_SpeakingActorNPC_ID < 0)
     v9 = 4;
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_Dialogue, 3, 0);//pNumberContacts = 1, v9 = 0; pNumberContacts = 2, v9 = 3;
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(),  window->GetHeight(), WINDOW_Dialogue, 3, 0);//pNumberContacts = 1, v9 = 0; pNumberContacts = 2, v9 = 3;
   if (pNPCInfo->Hired() && !pNPCInfo->bHasUsedTheAbility)
   {
     if (pNPCInfo->uProfession == 10 ||    //Healer
@@ -686,7 +686,6 @@
 {
   double v3; // st7@1
   int v7; // eax@4
-  ODMFace *pFace; // eax@6
   const char *v14; // eax@8
   char *result; // eax@12
   unsigned int pMapID; // eax@14
@@ -720,12 +719,11 @@
         {
           for ( uint i = 0; i < (uint)pOutdoor->pBModels[j].uNumFaces; ++i )
           {
-            pFace = &pOutdoor->pBModels[j].pFaces[i];
-            if ( pFace->sCogTriggeredID )
+            if ( pOutdoor->pBModels[j].pFaces[i].sCogTriggeredID )
             {
-              if ( !(BYTE2(pFace->uAttributes) & 0x10) )
+              if ( !(pOutdoor->pBModels[j].pFaces[i].uAttributes & FACE_UNKNOW) )
               {
-                v14 = GetEventHintString(pFace->sCogTriggeredID);
+                v14 = GetEventHintString(pOutdoor->pBModels[j].pFaces[i].sCogTriggeredID);
                 if ( v14 )
                 {
                   if ( _stricmp(v14, "") )
@@ -984,7 +982,7 @@
 
   if ( uGameState != GAME_STATE_FINAL_WINDOW )
   {
-    text_y = sub_44100D() != 0 ? 381 : 322;
+    text_y = _44100D_should_alter_right_panel() != 0 ? 381 : 322;
     sprintf(pTmpBuf.data(), "\r087%lu", pParty->uNumFoodRations);
     pPrimaryWindow->DrawText(pFontSmallnum, 0, text_y, uGameUIFontMain, pTmpBuf.data(), 0, 0, uGameUIFontShadow);
     sprintf(pTmpBuf.data(), "\r028%lu", pParty->uNumGold);
@@ -1168,7 +1166,7 @@
 
   pMouse->uPointingObjectID = 0;
   pMouse->GetClickPos(&pX, &pY);
-  if ( pX < 0 || pX > 639 || pY < 0 || pY > 479 )//границы окна игры
+  if ( pX < 0 || pX > window->GetWidth() - 1 || pY < 0 || pY > window->GetHeight() - 1 )//границы окна игры
     return;
   if ( pX <= 467 && pY <= 351 )//пределы основной области
   {
@@ -1445,7 +1443,7 @@
       }
     }
   }//конец пределов основного экрана------------------------
-  if ( pX > 467 && pX <=639 && pY <= 479 )//пределы правой области
+  if ( pX > 467 && pX <= window->GetWidth() - 1 && pY <= window->GetHeight() - 1 )//пределы правой области
   {
     if ( pCurrentScreen == SCREEN_GAME )
     {
@@ -1956,15 +1954,15 @@
     for (uint i = 0; i < (uint)pIndoor->pMapOutlines->uNumOutlines; ++i)
     {
       BLVMapOutline* pOutline = &pIndoor->pMapOutlines->pOutlines[i];
-      BLVFace* pFace1 = pIndoor->pFaces + pOutline->uFace1ID;
-      BLVFace* pFace2 = pIndoor->pFaces + pOutline->uFace2ID;
-      if (pFace1->Visible() && pFace2->Visible())
+      //BLVFace* pFace1 = &pIndoor->pFaces[pOutline->uFace1ID];
+      //BLVFace* pFace2 = &pIndoor->pFaces[pOutline->uFace2ID];
+      if (pIndoor->pFaces[pOutline->uFace1ID].Visible() && pIndoor->pFaces[pOutline->uFace2ID].Visible())
       {
         if ( pOutline->uFlags & 1 )
         {
           if (bWizardEyeActive && uWizardEyeSkillLevel >= 3 &&
-             (pFace1->Clickable() || pFace2->Clickable()) &&
-             (pIndoor->pFaceExtras[pFace1->uFaceExtraID].uEventID || pIndoor->pFaceExtras[pFace2->uFaceExtraID].uEventID))
+             (pIndoor->pFaces[pOutline->uFace1ID].Clickable() || pIndoor->pFaces[pOutline->uFace2ID].Clickable()) &&
+             (pIndoor->pFaceExtras[pIndoor->pFaces[pOutline->uFace1ID].uFaceExtraID].uEventID || pIndoor->pFaceExtras[pIndoor->pFaces[pOutline->uFace2ID].uFaceExtraID].uEventID))
           {
             if (uNumBlueFacesInBLVMinimap < 49)
               pBlueFacesInBLVMinimapIDs[uNumBlueFacesInBLVMinimap++] = i;
@@ -1982,13 +1980,13 @@
           }
           continue;
         }
-        if (pFace1->uAttributes & 0x80 || pFace2->uAttributes & 0x80)
+        if (pIndoor->pFaces[pOutline->uFace1ID].uAttributes & FACE_UNKNOW4 || pIndoor->pFaces[pOutline->uFace2ID].uAttributes & FACE_UNKNOW4)
         {
           pOutline->uFlags = pOutline->uFlags | 1;
           pIndoor->_visible_outlines[i >> 3] |= 1 << (7 - i % 8);
           if (bWizardEyeActive && uWizardEyeSkillLevel >= 3 &&
-             (pFace1->Clickable() || pFace2->Clickable()) &&
-             (pIndoor->pFaceExtras[pFace1->uFaceExtraID].uEventID || pIndoor->pFaceExtras[pFace2->uFaceExtraID].uEventID))
+             (pIndoor->pFaces[pOutline->uFace1ID].Clickable() || pIndoor->pFaces[pOutline->uFace2ID].Clickable()) &&
+             (pIndoor->pFaceExtras[pIndoor->pFaces[pOutline->uFace1ID].uFaceExtraID].uEventID || pIndoor->pFaceExtras[pIndoor->pFaces[pOutline->uFace2ID].uFaceExtraID].uEventID))
           {
             if (uNumBlueFacesInBLVMinimap < 49)
               pBlueFacesInBLVMinimapIDs[uNumBlueFacesInBLVMinimap++] = i;
--- a/VideoPlayer.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/VideoPlayer.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -65,24 +65,18 @@
 //----- (004BFE2D) --------------------------------------------------------
 _BINKBUF *VideoPlayer::CreateBinkBuffer(unsigned int uWidth, unsigned int uHeight, char a4)
 {
-  __int32 v4; // edi@3
   _BINKBUF *v5; // esi@3
   HRESULT v6; // eax@5
   IDirectDrawSurface *v7; // eax@6
   HRESULT v8; // eax@9
-  char v9; // al@11
   DDSURFACEDESC2 v11; // [sp+Ch] [bp-108h]@7
   DDSURFACEDESC Dst; // [sp+88h] [bp-8Ch]@3
-  unsigned int v13; // [sp+F4h] [bp-20h]@1
-  //struct tagRECT Rect; // [sp+F8h] [bp-1Ch]@11
   IDirectDrawSurface4 *v15; // [sp+108h] [bp-Ch]@7
   IDirectDrawSurface2 *a2; // [sp+10Ch] [bp-8h]@3
 
-  v13 = uWidth;
   //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
       //pVersion->pVersionInfo.dwMajorVersion >= 5u )
   {
-    v4 = 0;
     v15 = 0;
 
     if (uBinkVersion == 0x0001000500150000)
@@ -97,14 +91,14 @@
     }
     else __debugbreak();
 
-    memset(&v11, 0, 0x7Cu);
+    memset(&v11, 0, 0x7C);
     v11.dwSize = 124;
-    v11.dwWidth = v13;
-    v11.dwFlags = 0x1007u;                      // DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT
-    v11.ddsCaps.dwCaps = 0x4040u;               // DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY
+    v11.dwWidth = uWidth;
+    v11.dwFlags = 0x1007;                      // DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT
+    v11.ddsCaps.dwCaps = 0x4040;               // DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY
     v11.dwHeight = uHeight;
     *(_QWORD *)&v11.ddpfPixelFormat.dwSize = 0x400000020ui64;// DDPF_FOURCC
-    v11.ddpfPixelFormat.dwFourCC = 0x32595559u;
+    v11.ddpfPixelFormat.dwFourCC = 0x32595559;
     if (FAILED(pRenderer->pDirectDraw4->CreateSurface(&v11, &v15, 0)))
     {
       memset(&v11.ddpfPixelFormat, 0, sizeof(DDPIXELFORMAT));
@@ -141,7 +135,7 @@
 
     memset(&Dst, 0, 0x6Cu);
     Dst.dwSize = 108;
-    Dst.dwWidth = v13;
+    Dst.dwWidth = uWidth;
     Dst.dwFlags = 4103;
     Dst.ddsCaps.dwCaps = 16448;
     Dst.dwHeight = uHeight;
@@ -166,11 +160,10 @@
   }*/
   v5->pTargetDDrawSurface = v7;
   v5->hWnd = window->GetApiHandle();
-  v9 = a4;
-  v5->field_4C = v4;
-  v5->field_68 = v4;
-  v5->field_5C = v4;
-  v5->field_74 = v9 & 0x1F;
+  v5->field_4C = 0;
+  v5->field_68 = 0;
+  v5->field_5C = 0;
+  v5->field_74 = a4 & 0x1F;
   v5->field_78 = 1;
   v5->target_width = GetSystemMetrics(SM_CXSCREEN);
   v5->target_height = GetSystemMetrics(SM_CYSCREEN);
@@ -182,8 +175,8 @@
   v5->field_C = window->GetHeight();
   v5->field_1C = Rect.left;
   v5->field_20 = Rect.top;
-  Rect.left = v4;
-  Rect.top = v4;
+  Rect.left = 0;
+  Rect.top = 0;
   ClientToScreen(window->GetApiHandle(), (POINT *)&Rect);
   v5->field_1C = Rect.left - v5->field_1C;
   v5->field_20 = Rect.top - v5->field_20;
@@ -192,7 +185,7 @@
   v5->field_34 = v5->field_C - Rect.bottom;
   v5->field_8 = v5->uWidth + v5->field_30;
   v5->field_C = v5->uHeight + v5->field_34;
-  BinkBufferSetOffset(v5, v4, v4);
+  BinkBufferSetOffset(v5, 0, 0);
   BinkBufferSetScale(v5, v5->uWidth, v5->uHeight);
   return v5;
 }
@@ -204,7 +197,6 @@
   IDirectDrawSurface *v2; // edi@5
   IDirectDrawSurface4 *v6; // edi@11
 
-  //v1 = _this;
   //if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion >= 5u )
   {
     DDSURFACEDESC2 v8; // [sp+Ch] [bp-7Ch]@4
@@ -219,9 +211,9 @@
           break;
         
         if (uBinkVersion < 0x0003000000000000)
-          BYTE3(_this->uBinkDDSurfaceType) |= 0x80u;
+          _this->uBinkDDSurfaceType |= 0x80000000;
         else
-          BYTE3(_this->uBinkDDSurfaceType) |= 0x04;
+          _this->uBinkDDSurfaceType |= 0x4000000;
 
         if ( v6->Restore() )
           return 0;
@@ -265,16 +257,14 @@
 //----- (004C01FB) --------------------------------------------------------
 void BinkUnlockBuffer(_BINKBUF *_this)
 {
-  _BINKBUF *v1; // esi@1
   IDirectDrawSurface *v2; // eax@1
 
-  v1 = _this;
   v2 = _this->pTargetDDrawSurface;
   if ( v2 )
   {
     v2->Unlock(0);
-    v1->uDDrawSurfacePitch = 0;
-    v1->pDDrawSurfaceData = 0;
+    _this->uDDrawSurfacePitch = 0;
+    _this->pDDrawSurfaceData = 0;
 
     if (uBinkVersion < 0x0003000000000000)
       BYTE3(_this->uBinkDDSurfaceType) &= 0x7F;
@@ -330,7 +320,7 @@
   {
     pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0));
     AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-    AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 0xE, &uTrackStartMS, &uTrackEndMS);
+    AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &uTrackStartMS, &uTrackEndMS);
     AIL_redbook_play(pAudioPlayer->hAILRedbook, uTrackStartMS + 1, uTrackEndMS);
   }
   bGameoverLoop = 0;
@@ -342,7 +332,7 @@
   int v4; // ebp@1
   const char *pName; // edi@1
   MSG Msg; // [sp+Ch] [bp-1Ch]@12
- 	  	  
+
   v4 = a2;
   pName = pMovieName;
   if ( !(dword_6BE364_game_settings_1 & (GAME_SETTINGS_NO_HOUSE_ANIM | GAME_SETTINGS_NO_INTRO)) )
@@ -352,7 +342,7 @@
     ShowCursor(0);
     OpenGlobalMovie(pName, 0, ScreenSizeFlag);
     bPlayingMovie = 1;
-	field_44 = v4;
+    field_44 = v4;
     //if ( pRenderer->pRenderD3D )
     {
       pRenderer->ClearTarget(0);
@@ -365,61 +355,61 @@
     }*/
     pCurrentScreen = SCREEN_VIDEO;
 
-	auto hwnd = pVideoPlayer->window->GetApiHandle();
-	RECT rc_client;
-	GetClientRect(hwnd, &rc_client);
-	int client_width = rc_client.right - rc_client.left,
-		client_height = rc_client.bottom - rc_client.top;
+    auto hwnd = pVideoPlayer->window->GetApiHandle();
+    RECT rc_client;
+    GetClientRect(hwnd, &rc_client);
+    int client_width = rc_client.right - rc_client.left,
+        client_height = rc_client.bottom - rc_client.top;
 
-	HDC     dc = GetDC(hwnd);
-	HDC     back_dc = CreateCompatibleDC(dc);
-	HBITMAP back_bmp;
-	SelectObject(back_dc, back_bmp = CreateCompatibleBitmap(dc, client_width, client_height));
+    HDC     dc = GetDC(hwnd);
+    HDC     back_dc = CreateCompatibleDC(dc);
+    HBITMAP back_bmp;
+    SelectObject(back_dc, back_bmp = CreateCompatibleBitmap(dc, client_width, client_height));
 
-	while (true)
-	{
-		if ( pVideoPlayer->bStopBeforeSchedule )
-			break;
-		while (PeekMessageA(&Msg, hwnd, 0, 0, PM_REMOVE))
-		{
-			if (Msg.message == 18)
-				Game_DeinitializeAndTerminate(0);
-			if (Msg.message == 15)
-				break;
-			TranslateMessage(&Msg);
-			DispatchMessageA(&Msg);
-		}
-		GUI_MainMenuMessageProc();
+    while (true)
+    {
+      if ( pVideoPlayer->bStopBeforeSchedule )
+        break;
+      while (PeekMessageA(&Msg, hwnd, 0, 0, PM_REMOVE))
+      {
+        if (Msg.message == 18)
+          Game_DeinitializeAndTerminate(0);
+        if (Msg.message == 15)
+          break;
+        TranslateMessage(&Msg);
+        DispatchMessageA(&Msg);
+      }
+      GUI_MainMenuMessageProc();
 
-		if (pMovie->Stopped())
-		  break;
-		auto image = pPlayer->DoFrame();
-		if (image)
-		{
-			// draw to hwnd
-			BITMAPINFO bmi;
-			bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-			bmi.bmiHeader.biWidth = client_width;
-			bmi.bmiHeader.biHeight = -client_height;
-			bmi.bmiHeader.biPlanes = 1;
-			bmi.bmiHeader.biBitCount = 32;
-			bmi.bmiHeader.biCompression = BI_RGB;
-			bmi.bmiHeader.biSizeImage = 0;
-			bmi.bmiHeader.biXPelsPerMeter = 0;
-			bmi.bmiHeader.biYPelsPerMeter = 0;
-			bmi.bmiHeader.biClrUsed = 0;
-			bmi.bmiHeader.biClrImportant = 0;
-			GetDIBits(back_dc, back_bmp, 0, client_height, 0, &bmi, DIB_RGB_COLORS);
-			SetDIBits(back_dc, back_bmp, 0, client_height, image, &bmi, DIB_RGB_COLORS);
-			BitBlt(dc, 0, 0, client_width, client_height, back_dc, 0, 0, SRCCOPY);
+      if (pMovie->Stopped())
+        break;
+      char *image = pPlayer->DoFrame();
+      if (image)
+      {
+        // draw to hwnd
+        BITMAPINFO bmi;
+        bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+        bmi.bmiHeader.biWidth = client_width;
+        bmi.bmiHeader.biHeight = -client_height;
+        bmi.bmiHeader.biPlanes = 1;
+        bmi.bmiHeader.biBitCount = 32;
+        bmi.bmiHeader.biCompression = BI_RGB;
+        bmi.bmiHeader.biSizeImage = 0;
+        bmi.bmiHeader.biXPelsPerMeter = 0;
+        bmi.bmiHeader.biYPelsPerMeter = 0;
+        bmi.bmiHeader.biClrUsed = 0;
+        bmi.bmiHeader.biClrImportant = 0;
+        GetDIBits(back_dc, back_bmp, 0, client_height, 0, &bmi, DIB_RGB_COLORS);
+        SetDIBits(back_dc, back_bmp, 0, client_height, image, &bmi, DIB_RGB_COLORS);
+        BitBlt(dc, 0, 0, client_width, client_height, back_dc, 0, 0, SRCCOPY);
 
-			delete[] image;
-		}
-		if (pVideoPlayer->bStopBeforeSchedule == 1)
-			Sleep(0x3E8u);
-	}
-	pVideoPlayer->Unload();
-	/*
+        delete[] image;
+      }
+      if (pVideoPlayer->bStopBeforeSchedule == 1)
+      Sleep(1000);
+    }
+    pVideoPlayer->Unload();
+    /*
     if ( pVideoPlayer->uMovieFormat == 2 )
     {
       if ( pVideoPlayer->pBinkMovie )
@@ -468,9 +458,6 @@
   }
 }
 
-
-
-
 //----- (004BE95A) --------------------------------------------------------
 unsigned int VideoPlayer::SmackCheckSurfaceFromat()
 {
@@ -513,7 +500,7 @@
   uBinkVersion = (unsigned __int64)uBinkVersionMajor << 32 | uBinkVersionMinor;
 
   strcpy(pTmpBuf.data(), "anims\\might7.vid");
-  hMightVid = CreateFileW(L"anims\\might7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080u, 0);
+  hMightVid = CreateFileW(L"anims\\might7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
   if ( hMightVid == INVALID_HANDLE_VALUE )
   {
     sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data());
@@ -521,20 +508,20 @@
     return;
   }
   strcpy(pTmpBuf.data(), "anims\\magic7.vid");
-  hMagicVid = CreateFileW(L"anims\\magic7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080u, 0);
+  hMagicVid = CreateFileW(L"anims\\magic7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
   if ( hMagicVid == INVALID_HANDLE_VALUE )
   {
     if ( !bCanLoadFromCD )
-      {
+    {
        sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data());
        MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
        return;
-	  }
+    }
     sprintf(pTmpBuf2.data(), "%c:\\%s", (unsigned __int8)cMM7GameCDDriveLetter, pTmpBuf.data());
-    hMagicVid = CreateFileA(pTmpBuf2.data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080u, 0);
+    hMagicVid = CreateFileA(pTmpBuf2.data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
     if ( hMagicVid == (HANDLE)INVALID_HANDLE_VALUE )
     {
-	  sprintf(pTmpBuf2.data(), "Can't open file - %s", pTmpBuf.data());
+      sprintf(pTmpBuf2.data(), "Can't open file - %s", pTmpBuf.data());
       MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
       return;
     }
@@ -571,7 +558,6 @@
   uBinkDirectDrawSurfaceType = BinkDDSurfaceType((IDirectDrawSurface *)pRenderer->pBackBuffer4);
 }
 
-
 //----- (004BEBD7) --------------------------------------------------------
 void VideoPlayer::Unload()
 {
@@ -858,7 +844,7 @@
         pRenderer->BeginScene();
         pMouse->DrawCursorToTarget();
         SmackUpdatePalette();
-        pMouse->_469EA4();
+        pMouse->ReadCursorWithItem();
         pRenderer->EndScene();
       }
       else if ( pBinkMovie && !BinkWait(pBinkMovie) )
@@ -866,7 +852,7 @@
         pRenderer->BeginScene();
         pMouse->DrawCursorToTarget();
         BinkUpdatePalette();
-        pMouse->_469EA4();
+        pMouse->ReadCursorWithItem();
         pRenderer->EndScene();
       }
 	  */
@@ -875,7 +861,7 @@
 		pRenderer->BeginScene();
 		pMouse->DrawCursorToTarget();
 		UpdatePalette();
-		pMouse->_469EA4();
+		pMouse->ReadCursorWithItem();
 		pRenderer->EndScene();
 	}
 }
@@ -883,39 +869,38 @@
 
 void VideoPlayer::UpdatePalette()
 {
-	//VideoPlayer *v2; // esi@1
-	unsigned __int16 *v3; // ebx@1
-	unsigned int v4; // edi@1
-	unsigned int v5; // eax@1
-	//_SMACK *v6; // eax@1
-
-	Log::Warning(L"smacker");
+  Log::Warning(L"smacker");
 
-	pRenderer->BeginScene();
+  pRenderer->BeginScene();
+  if (pMovie->Stopped())//видео завершено/перезагрузка
+  {
+    int width = game_viewport_width;
+    int height = game_viewport_height;
+    delete pMovie;
 
-	if (pMovie->Stopped())
-	{
-		int width = pMovie->GetWidth();
-		int height = pMovie->GetHeight();
-		delete pMovie;
+    SetFilePointer(hVidFile, uOffset, nullptr, FILE_BEGIN);
 
-		SetFilePointer(hVidFile, uOffset, nullptr, FILE_BEGIN);
-
-		pMovie = pPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, width, height);
-	}
-	else
-	{
-
-		auto image = pPlayer->DoFrame();
-
-		if (image)
-		{
-			memcpy(pRenderer->pTargetSurface, image, 480 * 480 * 4);
-			delete[] image;
-		}
-	}
-
-	pRenderer->EndScene();
+    pMovie = pPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, width, height);
+  }
+  else
+  {
+    char *image = pPlayer->DoFrame();
+    int image_array[460 * 344];//game_viewport_width * game_viewport_height
+    if (image)
+    {
+      memcpy(image_array, image, sizeof (image_array));
+      for (unsigned int y = 8; y < 8 + game_viewport_height; ++y)//координаты местоположения видеоролика
+      {
+        for (unsigned int x = 8; x < 8 + game_viewport_width; ++x)
+        {
+          auto p = (unsigned __int32 *)pRenderer->pTargetSurface + x + y * pRenderer->uTargetSurfacePitch;
+          *p = image_array[((x - 8) + ((y - 8)*game_viewport_width))];
+        }
+      }
+      delete[] image;
+    }
+  }
+  pRenderer->EndScene();
 }
 /*
 //----- (004BF08B) --------------------------------------------------------
@@ -1040,21 +1025,21 @@
   if (!this->bBufferLoaded)
   {
     //Prepare();
-	  pEventTimer->Pause();
-	  if (pAudioPlayer->hAILRedbook)
-		  AIL_redbook_pause(pAudioPlayer->hAILRedbook);
+    pEventTimer->Pause();
+    if (pAudioPlayer->hAILRedbook)
+      AIL_redbook_pause(pAudioPlayer->hAILRedbook);
 
-	  bStopBeforeSchedule = false;
-	  bBufferLoaded = 1;
-	  /*
-	  pSmackerMovie = 0;
-	  pSmackerBuffer = 0;
-	  pBinkMovie = 0;
-	  pBinkBuffer = 0;
-	  */
-	  bPlayingMovie = false;
-	  bFirstFrame = false;
-	  bUsingSmackerMMX = SmackUseMMX(1);
+    bStopBeforeSchedule = false;
+    bBufferLoaded = 1;
+    /*
+    pSmackerMovie = 0;
+    pSmackerBuffer = 0;
+    pBinkMovie = 0;
+    pBinkBuffer = 0;
+    */
+    bPlayingMovie = false;
+    bFirstFrame = false;
+    bUsingSmackerMMX = SmackUseMMX(1);
 
     this->bLoopPlaying = a3_1;
     if ( LOBYTE(this->field_104) == 1 )
@@ -1063,9 +1048,9 @@
       return;
     }
 
-	LoadMovie(pMovieName);
-	/*
-	this->pSmackerMovie = OpenSmack(Str2);
+    LoadMovie(pMovieName);
+    /*
+    this->pSmackerMovie = OpenSmack(Str2);
     if ( !this->pSmackerMovie )
     {
       this->Unload();
@@ -1074,8 +1059,6 @@
       return;
     }
     */
- 
-
 
 	/*
 	this->pSmackerBuffer = (_SMACKBUF *)SmackBufferOpen(window->GetApiHandle(), 4, LOWORD(this->pSmackerMovie->Width), LOWORD(this->pSmackerMovie->Height), LOWORD(this->pSmackerMovie->Width), LOWORD(this->pSmackerMovie->Height));
@@ -1211,22 +1194,21 @@
   pMouse->_469E24();
   if ( window_SpeakInHouse && window_SpeakInHouse->ptr_1C == (void *)165 && !this->pMovie)//!this->pSmackerMovie )
   {
-    bGameoverLoop = 1;
+    bGameoverLoop = true;
     HouseDialogPressCloseBtn();
     window_SpeakInHouse->Release();
-    pParty->uFlags &= 0xFFFFFFFDu;
+    pParty->uFlags &= 0xFFFFFFFD;
     if ( EnterHouse(HOUSE_BODY_GUILD_ERATHIA) )
     {
       pAudioPlayer->PlaySound(SOUND_Invalid, 0, 0, -1, 0, 0, 0, 0);
-      window_SpeakInHouse = GUIWindow::Create(0, 0, 640, 480, WINDOW_HouseInterior, 165, 0);
-      window_SpeakInHouse->CreateButton(0x3Du, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 1u, 0x31u, "", 0);
-      window_SpeakInHouse->CreateButton(0xB1u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 2u, 0x32u, "", 0);
-      window_SpeakInHouse->CreateButton(0x124u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 3u, 0x33u, "", 0);
-      window_SpeakInHouse->CreateButton(0x197u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 4u, 0x34u, "", 0);
+      window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_HouseInterior, 165, 0);
+      window_SpeakInHouse->CreateButton(0x3Du, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 1, 0x31, "", 0);
+      window_SpeakInHouse->CreateButton(0xB1u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 2, 0x32, "", 0);
+      window_SpeakInHouse->CreateButton(0x124u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 3, 0x33, "", 0);
+      window_SpeakInHouse->CreateButton(0x197u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 4, 0x34, "", 0);
     }
     bGameoverLoop = 0;
   }
-  
 }
 
 //----- (004BF73A) --------------------------------------------------------
@@ -1273,100 +1255,100 @@
 
 void MultimediaPlayer::Logger(void *, int, const char *format, va_list args)
 {
-	char msg[1024];
-	vsprintf(msg, format, args);
+  char msg[1024];
+  vsprintf(msg, format, args);
 
-	DWORD w;
-	WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), msg, lstrlenA(msg), &w, nullptr);
+  DWORD w;
+  WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), msg, lstrlenA(msg), &w, nullptr);
 }
 
 int VideoPlayer::readFunction(void* opaque, uint8_t* buf, int buf_size)
 {
-	HANDLE stream = (HANDLE)opaque;
-	//int numBytes = stream->read((char*)buf, buf_size);
-	int numBytes;
-	ReadFile(stream, (char *)buf, buf_size, (LPDWORD)&numBytes, NULL);
-	return numBytes;
+  HANDLE stream = (HANDLE)opaque;
+  //int numBytes = stream->read((char*)buf, buf_size);
+  int numBytes;
+  ReadFile(stream, (char *)buf, buf_size, (LPDWORD)&numBytes, NULL);
+  return numBytes;
 }
 
 int64_t VideoPlayer::seekFunction(void* opaque, int64_t offset, int whence)
 {
-	if (whence == AVSEEK_SIZE)
-		return pVideoPlayer->uSize;
-	HANDLE h = (HANDLE)opaque;
-	LARGE_INTEGER li;
-	li.QuadPart = offset;
-	
-	if (!SetFilePointerEx(h, li, (PLARGE_INTEGER)&li, FILE_BEGIN))
-		return -1;
-	return li.QuadPart;
+  if (whence == AVSEEK_SIZE)
+    return pVideoPlayer->uSize;
+  HANDLE h = (HANDLE)opaque;
+  LARGE_INTEGER li;
+  li.QuadPart = offset;
+
+  if (!SetFilePointerEx(h, li, (PLARGE_INTEGER)&li, FILE_BEGIN))
+    return -1;
+  return li.QuadPart;
 }
 
 void VideoPlayer::LoadMovie(const char * pFilename)
 {
-	char pVideoNameBik[120]; // [sp+Ch] [bp-28h]@2
-	char pVideoNameSmk[120]; // [sp+Ch] [bp-28h]@2
+  char pVideoNameBik[120]; // [sp+Ch] [bp-28h]@2
+  char pVideoNameSmk[120]; // [sp+Ch] [bp-28h]@2
 
-	sprintf(pVideoNameBik, "%s.bik", pFilename);
-	sprintf(pVideoNameSmk, "%s.smk", pFilename);
-	for (uint i = 0; i < uNumMightVideoHeaders; ++i)
-	{
-		//no BIK in MightVid
-		/*
-		if (!_stricmp(pVideoNameBik, pMightVideoHeaders[i].pVideoName))
-		{
-			hVidFile = hMightVid;
-			uOffset = pMightVideoHeaders[i].uFileOffset;
-			uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset;
-			this->uMovieFormat = 2;
-			this->uMovieFormatSwapped = 1;
-		}
-		*/
-		if (!_stricmp(pVideoNameSmk, pMightVideoHeaders[i].pVideoName))
-		{
-			hVidFile = hMightVid;
-			uOffset = pMightVideoHeaders[i].uFileOffset;
-			uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset;
-			this->uMovieFormat = 1;
-			this->uMovieFormatSwapped = 2;
-		}
-	}
-	for (uint i = 0; i < uNumMagicVideoHeaders; ++i)
-	{
-		if (!_stricmp(pVideoNameBik, pMagicVideoHeaders[i].pVideoName))
-		{
-			hVidFile = hMagicVid;
-			uOffset = pMagicVideoHeaders[i].uFileOffset;
-			uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
-			this->uMovieFormat = 2;
-			this->uMovieFormatSwapped = 1;
-		}
-		if (!_stricmp(pVideoNameSmk, pMagicVideoHeaders[i].pVideoName))
-		{
-			hVidFile = hMagicVid;
-			uOffset = pMagicVideoHeaders[i].uFileOffset;
-			uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
-			this->uMovieFormat = 1;
-			this->uMovieFormatSwapped = 2;
-		}
-	}
-	if (!hVidFile)
-	{
-		Unload();
-		MessageBoxA(0, "VideoPlayer error", "VideoPlayer Error", 0);
-		return;
-	}
+  sprintf(pVideoNameBik, "%s.bik", pFilename);
+  sprintf(pVideoNameSmk, "%s.smk", pFilename);
+  for (uint i = 0; i < uNumMightVideoHeaders; ++i)
+  {
+    //no BIK in MightVid
+    /*
+    if (!_stricmp(pVideoNameBik, pMightVideoHeaders[i].pVideoName))
+    {
+      hVidFile = hMightVid;
+      uOffset = pMightVideoHeaders[i].uFileOffset;
+      uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset;
+      this->uMovieFormat = 2;
+      this->uMovieFormatSwapped = 1;
+    }
+    */
+    if (!_stricmp(pVideoNameSmk, pMightVideoHeaders[i].pVideoName))
+    {
+      hVidFile = hMightVid;
+      uOffset = pMightVideoHeaders[i].uFileOffset;
+      uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset;
+      this->uMovieFormat = 1;
+      this->uMovieFormatSwapped = 2;
+    }
+  }
+  for (uint i = 0; i < uNumMagicVideoHeaders; ++i)
+  {
+    if (!_stricmp(pVideoNameBik, pMagicVideoHeaders[i].pVideoName))
+    {
+      hVidFile = hMagicVid;
+      uOffset = pMagicVideoHeaders[i].uFileOffset;
+      uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
+      this->uMovieFormat = 2;
+      this->uMovieFormatSwapped = 1;
+    }
+    if (!_stricmp(pVideoNameSmk, pMagicVideoHeaders[i].pVideoName))
+    {
+      hVidFile = hMagicVid;
+      uOffset = pMagicVideoHeaders[i].uFileOffset;
+      uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
+      this->uMovieFormat = 1;
+      this->uMovieFormatSwapped = 2;
+    }
+  }
+  if (!hVidFile)
+  {
+    Unload();
+    MessageBoxA(0, "VideoPlayer error", "VideoPlayer Error", 0);
+    return;
+  }
 
-	SetFilePointer(hVidFile, uOffset, 0, FILE_BEGIN);
-	strcpy(this->pCurrentMovieName, pFilename);
+  SetFilePointer(hVidFile, uOffset, 0, FILE_BEGIN);
+  strcpy(this->pCurrentMovieName, pFilename);
 
-	auto hwnd = pVideoPlayer->window->GetApiHandle();
-	RECT rc_client;
-	GetClientRect(hwnd, &rc_client);
-	int client_width = rc_client.right - rc_client.left,
-		client_height = rc_client.bottom - rc_client.top;
+  auto hwnd = pVideoPlayer->window->GetApiHandle();
+  RECT rc_client;
+  GetClientRect(hwnd, &rc_client);
+  int client_width = rc_client.right - rc_client.left,
+      client_height = rc_client.bottom - rc_client.top;
 
 
-	pMovie = pPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height);
+  pMovie = pPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height);
 
 }
\ No newline at end of file
--- a/VideoPlayer.h	Wed Feb 19 22:26:10 2014 +0100
+++ b/VideoPlayer.h	Wed Feb 19 22:30:39 2014 +0100
@@ -266,13 +266,20 @@
 
 		int num_processed_buffers;
 		alGetSourcei(samples_source_id, AL_BUFFERS_PROCESSED, &num_processed_buffers);
-		while (num_processed_buffers)
+		/*while (num_processed_buffers)
 		{
 			unsigned int processed_buffers_id[4];
 			alSourceUnqueueBuffers(samples_source_id, min(4, num_processed_buffers), processed_buffers_id);
 			CheckError();
 			alGetSourcei(samples_source_id, AL_BUFFERS_PROCESSED, &num_processed_buffers);
-		}
+		}*/
+      for (int i = 0; i < num_processed_buffers; ++i)
+      {
+        unsigned int processed_buffer_id;
+        alSourceUnqueueBuffers(samples_source_id, 1, &processed_buffer_id);
+        if (!CheckError())
+          alDeleteBuffers(1, &processed_buffer_id);
+      }
 
 		int num_queued_buffers;
 		alGetSourcei(samples_source_id, AL_BUFFERS_QUEUED, &num_queued_buffers);
@@ -579,6 +586,11 @@
 				video_stream_idx = OpenStream(AVMEDIA_TYPE_VIDEO, &video_stream, &video_stream_dec, &video_stream_dec_ctx);
 				if (video_stream_idx < 0)
 					return Release(), false;
+				if (_stricmp("binkvideo", video_stream_dec->name) )//Ritor1: include
+				{
+					this->width = video_stream_dec_ctx->width;
+					this->height = video_stream_dec_ctx->height;
+				}
 
 				audio_stream_idx = OpenStream(AVMEDIA_TYPE_AUDIO, &audio_stream, &audio_stream_dec, &audio_stream_dec_ctx);
 				if (audio_stream_idx < 0)
@@ -738,8 +750,16 @@
 		{
 			if (movie->LoadFromLOD(h, readFunction, seekFunction, width, height))
 			{
-				current_movie_width = width;
-				current_movie_height = height;
+				if (_stricmp("binkvideo", movie->video_stream_dec->name) )
+				{
+					current_movie_width = movie->video_stream_dec_ctx->width;
+					current_movie_height = movie->video_stream_dec_ctx->height;
+				}
+				else
+				{
+					current_movie_width = width;
+					current_movie_height = height;
+				}
 				return current_movie = movie;
 			}
 			delete movie;
--- a/Viewport.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/Viewport.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -127,7 +127,7 @@
 //----- (00443249) --------------------------------------------------------
 void ViewingParams::CenterOnParty()
 {
-  this->uMapBookMapZoom = (32768 * (__int64)this->uMapBookMapZoom) >> 16;
+  this->uMapBookMapZoom = fixpoint_mul(0x8000, this->uMapBookMapZoom);
   if (this->uMapBookMapZoom < 384)
     this->uMapBookMapZoom = 384;
 
@@ -281,28 +281,28 @@
 
   if ( PID_TYPE(v0) == OBJECT_Item)
   {
-    a2.y = (signed int)(unsigned __int16)v0 >> 3;
-    v21 = (signed int)(unsigned __int16)v0 >> 3;
-    if ( !(pObjectList->pObjects[pSpriteObjects[v21].uObjectDescID].uFlags & 0x10) && a2.y < 1000 && pSpriteObjects[v21].uObjectDescID
+    int item_id = PID_ID(v0);
+    //v21 = (signed int)(unsigned __int16)v0 >> 3;
+    if ( !(pObjectList->pObjects[pSpriteObjects[item_id].uObjectDescID].uFlags & 0x10) && item_id < 1000 && pSpriteObjects[item_id].uObjectDescID
       && (unsigned int)v0 < 0x2000000 )
     {
-      if ( pSpriteObjects[v21].stru_24.GetItemEquipType() == 18 )
+      if ( pSpriteObjects[item_id].stru_24.GetItemEquipType() == 18 )
       {
-        pParty->PartyFindsGold(pSpriteObjects[v21].stru_24.uSpecEnchantmentType, 0);
+        pParty->PartyFindsGold(pSpriteObjects[item_id].stru_24.uSpecEnchantmentType, 0);
         viewparams->bRedrawGameUI = 1;
       }
       else
       {
-        sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[pSpriteObjects[v21].stru_24.uItemID].pUnidentifiedName);
-        ShowStatusBarString(pTmpBuf2.data(), 2u);
-        if ( pSpriteObjects[v21].stru_24.uItemID == ITEM_ARTIFACT_SPLITTER )
+        sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[pSpriteObjects[item_id].stru_24.uItemID].pUnidentifiedName);//You found an item (%s)!
+        ShowStatusBarString(pTmpBuf2.data(), 2);
+        if ( pSpriteObjects[item_id].stru_24.uItemID == ITEM_ARTIFACT_SPLITTER )
           _449B7E_toggle_bit(pParty->_quest_bits, 184, 1);
-        if ( pSpriteObjects[v21].stru_24.uItemID == 455 )
+        if ( pSpriteObjects[item_id].stru_24.uItemID == 455 )
           _449B7E_toggle_bit(pParty->_quest_bits, 185, 1);
-        if ( !pParty->AddItemToParty(&pSpriteObjects[v21].stru_24) )
-          pParty->SetHoldingItem(&pSpriteObjects[v21].stru_24);
+        if ( !pParty->AddItemToParty(&pSpriteObjects[item_id].stru_24) )
+          pParty->SetHoldingItem(&pSpriteObjects[item_id].stru_24);
       }
-      SpriteObject::OnInteraction(a2.y);
+      SpriteObject::OnInteraction(item_id);
       return;
     }
     if ( !pParty->pPickedItem.uItemID )
@@ -339,8 +339,8 @@
     memcpy(&a1.stru_24, &pParty->pPickedItem, 0x24u);
 
     extern int UnprojectX(int);
-    v9 = UnprojectX(v1->x);
-    a1.Create(pParty->sRotationY + v9, 184, 200, 0);
+    //v9 = UnprojectX(v1->x);
+    a1.Create(pParty->sRotationY + UnprojectX(v1->x), 184, 200, 0);
     pTextureID = pIcons_LOD->LoadTexture(pParty->pPickedItem.GetIconName(), TEXTURE_16BIT_PALETTE);
     if (pTextureID != -1)
       pIcons_LOD->pTextures[pTextureID].Release();
@@ -350,13 +350,13 @@
   }
   if ( PID_TYPE(v0) == OBJECT_Actor)
   {
-    v16 = (signed int)(unsigned __int16)v0 >> 3;
-    a2.y = v16;
-    if ( pActors[v16].uAIState == 5 )
+    int mon_id = PID_ID(v0);
+    //a2.y = v16;
+    if ( pActors[mon_id].uAIState == Dead )
     {
       if ( (unsigned int)v0 < 0x2000000 )
       {
-        pActors[v16].LootActor();
+        pActors[mon_id].LootActor();
         return;
       }
       if ( !pParty->pPickedItem.uItemID )
@@ -393,8 +393,8 @@
       memcpy(&a1.stru_24, &pParty->pPickedItem, 0x24u);
 
       extern int UnprojectX(int);
-      v9 = UnprojectX(v1->x);
-      a1.Create(pParty->sRotationY + v9, 184, 200, 0);
+      //v9 = UnprojectX(v1->x);
+      a1.Create(pParty->sRotationY + UnprojectX(v1->x), 184, 200, 0);
       pTextureID = pIcons_LOD->LoadTexture(pParty->pPickedItem.GetIconName(), TEXTURE_16BIT_PALETTE);
       if (pTextureID != -1)
         pIcons_LOD->pTextures[pTextureID].Release();
@@ -404,7 +404,7 @@
     }
     if ( GetAsyncKeyState(VK_SHIFT) >= 0 )
     {
-      if ( !pActors[v16].GetActorsRelation(0) && !(pActors[v16].uAttributes & 0x80000) )
+      if ( !pActors[mon_id].GetActorsRelation(0) && !(pActors[mon_id].uAttributes & 0x80000) )
       {
         if ( HIWORD(v0) >= clickable_distance)
         {
@@ -442,8 +442,8 @@
           memcpy(&a1.stru_24, &pParty->pPickedItem, 0x24u);
 
           extern int UnprojectX(int);
-          v9 = UnprojectX(v1->x);
-          a1.Create(pParty->sRotationY + v9, 184, 200, 0);
+          //v9 = UnprojectX(v1->x);
+          a1.Create(pParty->sRotationY + UnprojectX(v1->x), 184, 200, 0);
           pTextureID = pIcons_LOD->LoadTexture(pParty->pPickedItem.GetIconName(), TEXTURE_16BIT_PALETTE);
           if (pTextureID != -1)
             pIcons_LOD->pTextures[pTextureID].Release();
@@ -451,24 +451,24 @@
           pIcons_LOD->SyncLoadedFilesCount();
           return;
         }
-        if ( !pActors[v16].CanAct() )
+        if ( !pActors[mon_id].CanAct() )
           return;
-        v18 = a2.y;
-        Actor::AI_FaceObject(a2.y, 4, 0, 0);
-        if ( !pActors[v16].sNPC_ID )
+        //v18 = mon_id;
+        Actor::AI_FaceObject(mon_id, 4, 0, 0);
+        if ( !pActors[mon_id].sNPC_ID )
         {
-          if ( pNPCStats->pGroups_copy[pActors[v16].uGroup] )
+          if ( pNPCStats->pGroups_copy[pActors[mon_id].uGroup] )
           {
-            if ( pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[v16].uGroup]] )
+            if ( pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[mon_id].uGroup]] )
             {
-              pParty->uFlags |= 2u;
-              strcpy(byte_5B0938.data(), pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[v16].uGroup]]);
+              pParty->uFlags |= 2;
+              strcpy(byte_5B0938.data(), pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[mon_id].uGroup]]);
               sub_4451A8_press_any_key(0, 0, 0);
             }
           }
           return;
         }
-        pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v18, 0);
+        pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, mon_id, 0);
         return;
       }
       if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3 )
@@ -528,8 +528,8 @@
       memcpy(&a1.stru_24, &pParty->pPickedItem, 0x24u);
 
       extern int UnprojectX(int);
-      v9 = UnprojectX(v1->x);
-      a1.Create(pParty->sRotationY + v9, 184, 200, 0);
+      //v9 = UnprojectX(v1->x);
+      a1.Create(pParty->sRotationY + UnprojectX(v1->x), 184, 200, 0);
       pTextureID = pIcons_LOD->LoadTexture(pParty->pPickedItem.GetIconName(), TEXTURE_16BIT_PALETTE);
       if (pTextureID != -1)
         pIcons_LOD->pTextures[pTextureID].Release();
@@ -699,8 +699,8 @@
     memcpy(&a1.stru_24, &pParty->pPickedItem, 0x24u);
 
     extern int UnprojectX(int);
-    v9 = UnprojectX(v1->x);
-    a1.Create(pParty->sRotationY + v9, 184, 200, 0);
+    //v9 = UnprojectX(v1->x);
+    a1.Create(pParty->sRotationY + UnprojectX(v1->x), 184, 200, 0);
     pTextureID = pIcons_LOD->LoadTexture(pParty->pPickedItem.GetIconName(), TEXTURE_16BIT_PALETTE);
     if (pTextureID != -1)
       pIcons_LOD->pTextures[pTextureID].Release();
--- a/_deleted.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/_deleted.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -12282,7 +12282,7 @@
     pRenderer->ChangeBetweenWinFullscreenModes();
   vsprintf(pTmpBuf.data(), Format, va);
   if ( pMouse )
-    pMouse->Activate(0);
+    pMouse->ChangeActivation(0);
   ClipCursor(0);
   MessageBoxA(0, pTmpBuf.data(), "Error", 0x30u);
   Game_DeinitializeAndTerminate(1);
@@ -13873,8 +13873,8 @@
       {
         pArcomageGame->GameOver = 1;
         pArcomageGame->field_F4 = 1;
-        pArcomageGame->uGameResult = 2;
-        pArcomageGame->field_B0 = -2;
+        pArcomageGame->uGameWinner = 2;
+        pArcomageGame->Victory_type = -2;
         return DefWindowProcW(hWnd, uMsg, wParam, lParam);
       }
       if ( wParam != 114 )
--- a/mm7_2.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/mm7_2.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -256,7 +256,7 @@
 
   uDialogueType = 83;
   pDialogueWindow->Release();
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 350, WINDOW_MainMenu, 0, 0);
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), 350, WINDOW_MainMenu, 0, 0);
   pBtn_ExitCancel = pDialogueWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[34],// "Cancel"
                  pIcons_LOD->GetTexture(uExitCancelTextureId), 0);
   pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0);
@@ -730,7 +730,7 @@
   pRenderer->EndScene();
   free(_this.pPixels);
   _this.pPixels = 0;
-  window_SpeakInHouse = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
+  window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
   pWindow.uFrameX = 75;
   pWindow.uFrameY = 60;
   pWindow.uFrameWidth = 469;
@@ -916,11 +916,11 @@
 
   result = (int)pDst;
   v193 = pDst;
-  v231 = 0;
   if ( dstHeight <= 0 )
     return result;
   
-  do
+  //do
+  for ( v231 = 0; v231 < dstHeight; v231++ )
   {
     for (int counter = 0; counter < dstWidth; counter++)
     {
@@ -976,10 +976,10 @@
       v193 = (unsigned __int16 *)((char *)v193 + field_20_bits);
     }
     v193 = (unsigned __int16 *)((char *)v193 + field_20_bits * (dstPitch - dstWidth));
-    ++v231;
+    //++v231;
     result = v231;
   }
-  while(v231 < dstHeight);
+  //while(v231 < dstHeight);
   return result;
 }
 
@@ -1581,9 +1581,6 @@
 //----- (0045063B) --------------------------------------------------------
 int __fastcall _45063B_spawn_some_monster(MapInfo *a1, int a2)
 {
-  signed int v2; // edi@1
-  Actor *v3; // esi@2
-  //signed __int64 v4; // qax@3
   int result; // eax@8
   int v6; // edi@11
   int v7; // ebx@11
@@ -1599,11 +1596,7 @@
   int v17; // eax@20
   int v18; // eax@21
   SpawnPointMM7 v19; // [sp+Ch] [bp-38h]@1
-  int v20; // [sp+24h] [bp-20h]@11
-  //MapInfo *v21; // [sp+28h] [bp-1Ch]@1
   int v22; // [sp+2Ch] [bp-18h]@3
-  int v23; // [sp+30h] [bp-14h]@11
-  //int v24; // [sp+34h] [bp-10h]@1
   unsigned int uFaceID; // [sp+38h] [bp-Ch]@10
   int v26; // [sp+3Ch] [bp-8h]@11
   int v27; // [sp+40h] [bp-4h]@11
@@ -1611,27 +1604,85 @@
   if (!uNumActors)
     return 0;
 
-  //v21 = a1;
-  //v24 = a2;
-  v2 = 0;
-  v3 = pActors.data();
-  while ( 1 )
+  for ( uint mon_id = 0; mon_id < uNumActors; ++mon_id )
   {
-    if (v3->pMonsterInfo.uID >= 121 && v3->pMonsterInfo.uID <= 123 || // Dwarf FemaleC A-C
-        v3->pMonsterInfo.uID >= 124 && v3->pMonsterInfo.uID <= 126 || // Dwarf MaleA A-C
-        v3->pMonsterInfo.uID >= 133 && v3->pMonsterInfo.uID <= 135 || // Peasant Elf FemaleA A-C
-        !v3->CanAct())
+    if ((pActors[mon_id].pMonsterInfo.uID < 121 || pActors[mon_id].pMonsterInfo.uID > 123) && // Dwarf FemaleC A-C
+        (pActors[mon_id].pMonsterInfo.uID < 124 || pActors[mon_id].pMonsterInfo.uID > 126) && // Dwarf MaleA A-C
+        (pActors[mon_id].pMonsterInfo.uID < 133 || pActors[mon_id].pMonsterInfo.uID > 135) && // Peasant Elf FemaleA A-C
+         pActors[mon_id].CanAct())
     {
-      ++v2;
-      ++v3;
-
-      if (v2 >= uNumActors)
-        return 0;
-
-      continue;
+      if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+      {
+        v22 = 0;
+        uint face_id = 0;
+        for ( face_id; face_id < 100; ++face_id )
+        {
+          v6 = rand() % 1024 + 512;
+          v7 = rand() % (signed int)stru_5C6E00->uIntegerDoublePi;
+          v19.vPosition.x = pParty->vPosition.x + fixpoint_mul(stru_5C6E00->Cos(v7), v6);
+          v8 = 0;
+          v19.uIndex = a2;
+          v19.vPosition.y = fixpoint_mul(stru_5C6E00->Sin(v7), v6) + pParty->vPosition.y;
+          v19.vPosition.z = pParty->vPosition.z;
+          v26 = 0;
+          v27 = 0;
+          v19.vPosition.z = ODM_GetFloorLevel(v19.vPosition.x, v19.vPosition.y, pParty->vPosition.z, 0, &v26, &v27, 0);
+          for( int i = 0; i < pOutdoor->uNumBModels; i++ )
+          {
+            v9 = abs(v19.vPosition.y - pOutdoor->pBModels[i].vBoundingCenter.y);
+            v10 = abs(v19.vPosition.x - pOutdoor->pBModels[i].vBoundingCenter.x);
+            if ( int_get_vector_length(v10, v9, 0) < pOutdoor->pBModels[i].sBoundingRadius + 256 )
+            {
+              v22 = 1;
+              break;
+            }
+          }
+          if ( v22 )
+          {
+            v11 = face_id == 100;
+            break;
+          }
+        }
+        v11 = face_id == 100;
+      }
+      else if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+      {
+        v22 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
+        for ( uint i = 0; i < 100; ++i )
+        {
+          v12 = rand() % 512 + 256;
+          v13 = rand();
+          v14 = v13 % (signed int)stru_5C6E00->uIntegerDoublePi;
+          v15 = stru_5C6E00->Cos(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
+          v19.vPosition.x = pParty->vPosition.x + fixpoint_mul(v15, v12);
+          v16 = stru_5C6E00->Sin(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
+          v19.vPosition.y = fixpoint_mul(v16, v12) + pParty->vPosition.y;
+          v19.vPosition.z = pParty->vPosition.z;
+          v19.uIndex = a2;
+          v17 = pIndoor->GetSector(v19.vPosition.x, v19.vPosition.y, pParty->vPosition.z);
+          if ( v17 == v22 )
+          {
+            v18 = BLV_GetFloorLevel(v19.vPosition.x, v19.vPosition.y, v19.vPosition.z, v17, &uFaceID);
+            v19.vPosition.z = v18;
+            if ( v18 != -30000 )
+            {
+              if ( abs(v18 - pParty->vPosition.z) <= 1024 )
+                break;
+            }
+          }
+        }
+        v11 = v26 == 100;
+      }
+      if ( v11 )
+        result = 0;
+      else
+      {
+        SpawnEncounter(a1, &v19, 0, 0, 1);
+        result = a2;
+      }
     }
 
-    break;
+    //break;
     //v22 = v3->pMonsterInfo.uID - 1;
     //v4 = (signed __int64)((double)v22 * 0.3333333333333333);
     //if ( (int)v4 != 40 )
@@ -1644,99 +1695,6 @@
     //if ( v2 >= (signed int)uNumActors )
     //  goto LABEL_8;
   }
-  if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
-  {
-    v22 = 0;
-    uFaceID = 0;
-    while ( 1 )
-    {
-      ++uFaceID;
-      v6 = rand() % 1024 + 512;
-      v7 = rand() % (signed int)stru_5C6E00->uIntegerDoublePi;
-      v20 = stru_5C6E00->Cos(v7);
-      v23 = (unsigned __int64)(v20 * (signed __int64)v6) >> 16;
-      v19.vPosition.x = pParty->vPosition.x + v23;
-      v20 = stru_5C6E00->Sin(v7);
-      v23 = (unsigned __int64)(v20 * (signed __int64)v6) >> 16;
-      v8 = 0;
-      v19.uIndex = a2;
-      v19.vPosition.y = v23 + pParty->vPosition.y;
-      v19.vPosition.z = pParty->vPosition.z;
-      v26 = 0;
-      v27 = 0;
-      v19.vPosition.z = ODM_GetFloorLevel(
-                          v19.vPosition.x,
-                          v23 + pParty->vPosition.y,
-                          pParty->vPosition.z,
-                          0,
-                          &v26,
-                          &v27,
-                          0);
-      v23 = 0;
-	  for( int i = 0; i < pOutdoor->uNumBModels; i++ )
-	  {
-		v9 = abs(v19.vPosition.y - pOutdoor->pBModels[i].vBoundingCenter.y);
-		v10 = abs(v19.vPosition.x - pOutdoor->pBModels[i].vBoundingCenter.x);
-		if ( int_get_vector_length(v10, v9, 0) < pOutdoor->pBModels[i].sBoundingRadius + 256 )
-		{
-		  v22 = 1;
-		  break;
-		}
-	  }
-      v11 = uFaceID == 100;
-      if ( uFaceID >= 100 )
-        break;
-      if ( v22 )
-      {
-        v11 = uFaceID == 100;
-        break;
-      }
-    }
-  }
-  else
-  {
-    v26 = 0;
-    v22 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
-    do
-    {
-      ++v26;
-      v12 = rand() % 512 + 256;
-      v13 = rand();
-      v14 = v13 % (signed int)stru_5C6E00->uIntegerDoublePi;
-      v15 = stru_5C6E00->Cos(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
-      v20 = v15;
-      v23 = (unsigned __int64)(v15 * (signed __int64)v12) >> 16;
-      v19.vPosition.x = pParty->vPosition.x + v23;
-      v16 = stru_5C6E00->Sin(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
-      v20 = v16;
-      v23 = (unsigned __int64)(v16 * (signed __int64)v12) >> 16;
-      v19.vPosition.y = v23 + pParty->vPosition.y;
-      v19.vPosition.z = pParty->vPosition.z;
-      v19.uIndex = a2;
-      v17 = pIndoor->GetSector(v19.vPosition.x, v23 + pParty->vPosition.y, pParty->vPosition.z);
-      if ( v17 == v22 )
-      {
-        v18 = BLV_GetFloorLevel(v19.vPosition.x, v19.vPosition.y, v19.vPosition.z, v17, &uFaceID);
-        v19.vPosition.z = v18;
-        if ( v18 != -30000 )
-        {
-          if ( abs(v18 - pParty->vPosition.z) <= 1024 )
-            break;
-        }
-      }
-    }
-    while ( v26 < 100 );
-    v11 = v26 == 100;
-  }
-  if ( v11 )
-  {
-    result = 0;
-  }
-  else
-  {
-    SpawnEncounter(a1, &v19, 0, 0, 1);
-    result = a2;
-  }
   return result;
 }
 
@@ -2267,8 +2225,6 @@
     return result;
 }
 
-
-
 //----- (00452B2E) --------------------------------------------------------
 int __fastcall GetDiceResult(unsigned int uNumDice, unsigned int uDiceSides)
 {
@@ -2905,12 +2861,12 @@
   pCurrentScreen = SCREEN_GAME;
 
   pGUIWindow2 = 0;
-  pAudioPlayer->StopChannels(-1, -1);
-  pMouse->RemoveHoldingItem();
+  pAudioPlayer->StopChannels(-1, -1);//остановить/подготовить канал
+  pMouse->RemoveHoldingItem();//избавить курсор от вещи
 
   pIcons_LOD->_inlined_sub2();
 
-  pWindow_MainMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
+  pWindow_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
   Texture* pNew = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE);
   Texture* pLoad = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE);
   Texture* pCredits = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE);
@@ -2937,7 +2893,7 @@
       {
         pTexture_PCX.Release();
         pTexture_PCX.Load("lsave640.pcx", 0);
-        pGUIWindow2 = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
+        pGUIWindow2 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
         pCurrentScreen = SCREEN_LOADGAME;
         LoadUI_Load(0);
       }
@@ -4190,7 +4146,6 @@
       bNoMargareth = true;
   }
 
-
   /*v8 = _4AC1C9_get_cpu_speed(0, (Vec4_int_ *)a2);
   Rect.left = *(int *)v8;
   Rect.top = *(int *)(v8 + 4);
@@ -4201,141 +4156,134 @@
 
   constructors();
 
-  if (!MM7_Initialize(640, 480))
+  if (!MM7_Initialize(640, 480))//задаётся размер окна
   {
     Log::Warning(L"MM init: failed");
     pGame->Deinitialize();
     return 1;
   }
 
-    pEventTimer->Pause();
-
-    SetUserInterface(PartyAlignment_Neutral, false);
-    ShowIntroVideo_and_LoadingScreen();
-    WriteWindowsRegistryInt("Ran once", 1);
-    dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
-    pGame->InitializeGammaController();
-    SecondaryInitialization();
-    pRenderer->SetRasterClipRect(0, 0, 639, 479);
-    FinalInitialization();
-
-    Log::Warning(L"MM: entering main loop");
+  pEventTimer->Pause();
+
+  SetUserInterface(PartyAlignment_Neutral, false);
+  ShowIntroVideo_and_LoadingScreen();
+  WriteWindowsRegistryInt("Ran once", 1);
+  dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
+  pGame->InitializeGammaController();
+  SecondaryInitialization();
+  pRenderer->SetRasterClipRect(0, 0, window->GetWidth() - 1, window->GetHeight() - 1);
+  FinalInitialization();
+  Log::Warning(L"MM: entering main loop");
+  while ( 1 )
+  {
+    MainMenuWindow* main_menu_window = MainMenuWindow::Create();
+    window->AddControl(main_menu_window);
+    MainMenu_Loop();
+    uGameState = GAME_STATE_PLAYING;
     while ( 1 )
     {
-      MainMenuWindow* main_menu_window = MainMenuWindow::Create();
-      window->AddControl(main_menu_window);
-
-      MainMenu_Loop();
-      uGameState = GAME_STATE_PLAYING;
-      while ( 1 )
+      if (uGameState == GAME_FINISHED || GetCurrentMenuID() == MENU_EXIT_GAME)
+      {
+        pGame->Deinitialize();
+        return true;
+      }
+
+      if (GetCurrentMenuID() == MENU_NEWGAME)
       {
-        if (uGameState == GAME_FINISHED || GetCurrentMenuID() == MENU_EXIT_GAME)
+        if ( pAudioPlayer->hAILRedbook )
+          AIL_redbook_stop(pAudioPlayer->hAILRedbook);
+        pParty->Reset();
+        pOtherOverlayList->Reset();
+        strcpy(pCurrentMapName, pStartingMapName);
+        pParty->CreateDefaultParty(0);
+        PlayerCreationUI_Initialize();
+        if ( PlayerCreationUI_Loop() )
         {
-          pGame->Deinitialize();
-          return true;
-        }
-
-        if (GetCurrentMenuID() == MENU_NEWGAME)
-        {
-          if ( pAudioPlayer->hAILRedbook )
-            AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-          pParty->Reset();
-          pOtherOverlayList->Reset();
-
-          strcpy(pCurrentMapName, pStartingMapName);
-          pParty->CreateDefaultParty(0);
-          PlayerCreationUI_Initialize();
-          if ( PlayerCreationUI_Loop() )
-          {
-            DeleteCCharFont();
-            break;
-          }
           DeleteCCharFont();
-          bFlashQuestBook = true;
-          PlayFullscreenMovie(MOVIE_Emerald);
-          //pGame->pCShow->PlayMovie(MOVIE_Emerald, 0);
-          SaveNewGame();
-
-          if (bNoMargareth)
-            _449B7E_toggle_bit(pParty->_quest_bits, PARTY_QUEST_EMERALD_MARGARETH_OFF, 1);
-          pGame->Loop();
-
-          if (uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU)
-          {
-            SetCurrentMenuID(MENU_NEWGAME);
-            uGameState = GAME_STATE_PLAYING;
-            continue;
-          }
-          else if (uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)
-            break;
-
-          assert(false && "Invalid game state");
-        }
-        if (GetCurrentMenuID() == MENU_CREDITS)
-        {
-         if ( pAudioPlayer->hAILRedbook )
-          AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-         MainMenuUI_Credits_Loop();
-         break;
-        }
-        if (GetCurrentMenuID() == MENU_5 || GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
-        {
-          uGameState = GAME_STATE_PLAYING;
-		  pGame->Loop();
+          break;
         }
-        else
-        {
-          if (GetCurrentMenuID() == MENU_DebugBLVLevel)
-		  {
-			  pMouse->Activate(0);
-
-			  pParty->Reset();
-			  pParty->CreateDefaultParty(1);
-              
-              __debugbreak();
-              /*extern void CreateDefaultBLVLevel();
-			  CreateDefaultBLVLevel();
-
-			  OPENFILENAMEA ofn;
-			  if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) )
-			  {
-				pMouse->Activate(1);
-				break;
-			  }
-			  _chdir("..\\");
-			  strcpy(pCurrentMapName, ofn.lpstrFileTitle);*/
-			  pMouse->Activate(1);
-			  pGame->Loop();
-		  }
-        }
-        if ( uGameState == GAME_STATE_LOADING_GAME )
-        {
-          SetCurrentMenuID(MENU_5);
-          uGameState = GAME_STATE_PLAYING;
-          continue;
-        }
-        if ( uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU )
+        DeleteCCharFont();
+        bFlashQuestBook = true;
+        PlayFullscreenMovie(MOVIE_Emerald);
+        //pGame->pCShow->PlayMovie(MOVIE_Emerald, 0);
+        SaveNewGame();
+        if (bNoMargareth)
+          _449B7E_toggle_bit(pParty->_quest_bits, PARTY_QUEST_EMERALD_MARGARETH_OFF, 1);
+        pGame->Loop();
+        if (uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU)
         {
           SetCurrentMenuID(MENU_NEWGAME);
           uGameState = GAME_STATE_PLAYING;
           continue;
         }
-        if ( uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)// from the loaded game
+        else if (uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)
+          break;
+        assert(false && "Invalid game state");
+      }
+      if (GetCurrentMenuID() == MENU_CREDITS)
+      {
+        if ( pAudioPlayer->hAILRedbook )
+          AIL_redbook_stop(pAudioPlayer->hAILRedbook);
+        MainMenuUI_Credits_Loop();
+        break;
+      }
+      if (GetCurrentMenuID() == MENU_5 || GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
+      {
+        uGameState = GAME_STATE_PLAYING;
+        pGame->Loop();
+      }
+      else
+      {
+        if (GetCurrentMenuID() == MENU_DebugBLVLevel)
         {
-          pAudioPlayer->StopChannels(-1, -1);
-          uGameState = GAME_STATE_PLAYING;
-          break;
+          pMouse->ChangeActivation(0);
+          pParty->Reset();
+          pParty->CreateDefaultParty(1);
+
+          __debugbreak();
+          /*extern void CreateDefaultBLVLevel();
+          CreateDefaultBLVLevel();
+
+          OPENFILENAMEA ofn;
+          if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) )
+          {
+            pMouse->ChangeActivation(1);
+            break;
+          }
+          _chdir("..\\");
+          strcpy(pCurrentMapName, ofn.lpstrFileTitle);*/
+          pMouse->ChangeActivation(1);
+          pGame->Loop();
         }
       }
-      if (!bNoSound && pAudioPlayer->hAILRedbook)
+      if ( uGameState == GAME_STATE_LOADING_GAME )
+      {
+        SetCurrentMenuID(MENU_5);
+        uGameState = GAME_STATE_PLAYING;
+        continue;
+      }
+      if ( uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU )
       {
-        pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
-        AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-        unsigned int startms, end_ms;
-        AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 0xE, &startms, &end_ms);
-        AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
+        SetCurrentMenuID(MENU_NEWGAME);
+        uGameState = GAME_STATE_PLAYING;
+        continue;
+      }
+      if ( uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)// from the loaded game
+      {
+        pAudioPlayer->StopChannels(-1, -1);
+        uGameState = GAME_STATE_PLAYING;
+        break;
       }
     }
+    if (!bNoSound && pAudioPlayer->hAILRedbook)
+    {
+      pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+      AIL_redbook_stop(pAudioPlayer->hAILRedbook);
+      unsigned int startms, end_ms;
+      AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &startms, &end_ms);
+      AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
+    }
+  }
   //lua_close(L);
   pGame->Deinitialize();
   return 1;
@@ -4495,9 +4443,7 @@
     }
   }
   else
-  {
     LOBYTE(viewparams->field_20) = 0;
-  }
   pParty->uFlags |= 2;
   viewparams->uSomeY = viewparams->uScreen_topL_Y;
   viewparams->uSomeX = viewparams->uScreen_topL_X;
--- a/mm7_3.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/mm7_3.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -43,6 +43,16 @@
 
 #include "MM7.h"
 
+
+//----- (0044100D) --------------------------------------------------------
+bool _44100D_should_alter_right_panel()
+{
+  return pCurrentScreen == SCREEN_NPC_DIALOGUE || pCurrentScreen == SCREEN_CHARACTERS ||
+         pCurrentScreen == SCREEN_HOUSE || pCurrentScreen == SCREEN_E ||
+         pCurrentScreen == SCREEN_CHANGE_LOCATION || pCurrentScreen == SCREEN_INPUT_BLV || pCurrentScreen == SCREEN_CASTING;
+}
+
+
 //----- (0046E44E) --------------------------------------------------------
 int  _46E44E_collide_against_faces_and_portals(unsigned int b1)
 {
@@ -445,7 +455,7 @@
       v5 = (v10 * stru_721530.direction.y + v11 * stru_721530.direction.x) >> 16;
       if ( v5 > 0 )
       {
-        v6 = ((unsigned __int64)(stru_721530.direction.z * (signed __int64)v5) >> 16) + stru_721530.normal.z;
+        v6 = fixpoint_mul(stru_721530.direction.z, v5) + stru_721530.normal.z;
         result = pParty->vPosition.z;
         if ( v6 >= pParty->vPosition.z )
         {
@@ -920,9 +930,9 @@
                       + face->pFacePlane.vNormal.z * pActors[v75].vPosition.z) >> 16);
                 if ( v46 > 0 )
                 {
-                  pActors[v75].vPosition.x += (unsigned int)(v46 * face->pFacePlane.vNormal.x) >> 16;
-                  pActors[v75].vPosition.y += (unsigned int)(v46 * face->pFacePlane.vNormal.y) >> 16;
-                  pActors[v75].vPosition.z += (unsigned int)(v46 * face->pFacePlane.vNormal.z) >> 16;
+                  pActors[v75].vPosition.x += fixpoint_mul(v46, face->pFacePlane.vNormal.x);
+                  pActors[v75].vPosition.y += fixpoint_mul(v46, face->pFacePlane.vNormal.y);
+                  pActors[v75].vPosition.z += fixpoint_mul(v46, face->pFacePlane.vNormal.z);
                 }
                 pActors[v75].uYawAngle = stru_5C6E00->Atan2(pActors[v75].vVelocity.x, pActors[v75].vVelocity.y);
               }
@@ -1112,7 +1122,7 @@
   int v13; // esi@3
   int v14; // edi@4
   signed __int64 v15; // qtt@6
-  __int16 v16; // si@7
+  //__int16 v16; // si@7
   int a7a; // [sp+30h] [bp+18h]@7
   int a9b; // [sp+38h] [bp+20h]@3
   int a9a; // [sp+38h] [bp+20h]@3
@@ -1122,9 +1132,9 @@
 
   if ( a10 && face->Ethereal() )
     return 0;
-  v11 = (unsigned __int64)(dir_x * (signed __int64)face->pFacePlane_old.vNormal.x) >> 16;
-  a10b = (unsigned __int64)(dir_y * (signed __int64)face->pFacePlane_old.vNormal.y) >> 16;
-  a9b = (unsigned __int64)(dir_z * (signed __int64)face->pFacePlane_old.vNormal.z) >> 16;
+  v11 = fixpoint_mul(dir_x, face->pFacePlane_old.vNormal.x);
+  a10b = fixpoint_mul(dir_y, face->pFacePlane_old.vNormal.y);
+  a9b = fixpoint_mul(dir_z, face->pFacePlane_old.vNormal.z);
   v12 = v11 + a9b + a10b;
   a9a = v11 + a9b + a10b;
   v13 = (a1 << 16)
@@ -1150,13 +1160,10 @@
     a10a = 0;
     v14 = abs(v13) >> 16;
   }
-  v16 = pos_y + ((unsigned int)((unsigned __int64)(a10a * (signed __int64)dir_y) >> 16) >> 16);
-  LOWORD(a7a) = (short)pos_x
-              + ((unsigned int)((unsigned __int64)(a10a * (signed __int64)dir_x) >> 16) >> 16)
-              - ((unsigned int)(v14 * face->pFacePlane_old.vNormal.x) >> 16);
-  HIWORD(a7a) = v16 - ((unsigned int)(v14 * face->pFacePlane_old.vNormal.y) >> 16);
-  if ( !sub_475665(face, a7a, (short)pos_z + ((unsigned int)((unsigned __int64)(a10a * (signed __int64)dir_z) >> 16) >> 16)
-        - ((unsigned int)(v14 * face->pFacePlane_old.vNormal.z) >> 16)) )
+  //v16 = pos_y + ((unsigned int)fixpoint_mul(a10a, dir_y) >> 16);
+  LOWORD(a7a) = (short)pos_x + ((unsigned int)fixpoint_mul(a10a, dir_x) >> 16) - fixpoint_mul(v14, face->pFacePlane_old.vNormal.x);
+  HIWORD(a7a) = pos_y + ((unsigned int)fixpoint_mul(a10a, dir_y) >> 16) - fixpoint_mul(v14, face->pFacePlane_old.vNormal.y);
+  if ( !sub_475665(face, a7a, (short)pos_z + ((unsigned int)fixpoint_mul(a10a, dir_z) >> 16) - fixpoint_mul(v14, face->pFacePlane_old.vNormal.z)) )
     return 0;
   *a2 = a10a >> 16;
   if ( a10a >> 16 < 0 )
@@ -1172,7 +1179,7 @@
   int v14; // esi@3
   int v15; // edi@4
   signed __int64 v16; // qtt@6
-  __int16 v17; // si@7
+  //__int16 v17; // si@7
   int a7a; // [sp+30h] [bp+18h]@7
   int a1b; // [sp+38h] [bp+20h]@3
   int a1a; // [sp+38h] [bp+20h]@3
@@ -1182,9 +1189,9 @@
 
   if ( a11 && face->Ethereal() )
     return false;
-  v12 = (unsigned __int64)(dir_x * (signed __int64)face->pFacePlane_old.vNormal.x) >> 16;
-  a11b = (unsigned __int64)(dir_y * (signed __int64)face->pFacePlane_old.vNormal.y) >> 16;
-  a1b = (unsigned __int64)(dir_z * (signed __int64)face->pFacePlane_old.vNormal.z) >> 16;
+  v12 = fixpoint_mul(dir_x, face->pFacePlane_old.vNormal.x);
+  a11b = fixpoint_mul(dir_y, face->pFacePlane_old.vNormal.y);
+  a1b = fixpoint_mul(dir_z, face->pFacePlane_old.vNormal.z);
   v13 = v12 + a1b + a11b;
   a1a = v12 + a1b + a11b;
   v14 = (a1 << 16)
@@ -1210,13 +1217,10 @@
     a11a = 0;
     v15 = abs(v14) >> 16;
   }
-  v17 = Y + ((unsigned int)((unsigned __int64)(a11a * (signed __int64)dir_y) >> 16) >> 16);
-  LOWORD(a7a) = (short)X
-              + ((unsigned int)((unsigned __int64)(a11a * (signed __int64)dir_x) >> 16) >> 16)
-              - ((unsigned int)(v15 * face->pFacePlane_old.vNormal.x) >> 16);
-  HIWORD(a7a) = v17 - ((unsigned int)(v15 * face->pFacePlane_old.vNormal.y) >> 16);
-  if ( !sub_4759C9(face, a10, a7a, (short)Z + ((unsigned int)((unsigned __int64)(a11a * (signed __int64)dir_z) >> 16) >> 16)
-        - ((unsigned int)(v15 * face->pFacePlane_old.vNormal.z) >> 16)) )
+  //v17 = Y + ((unsigned int)fixpoint_mul(a11a, dir_y) >> 16);
+  LOWORD(a7a) = (short)X + ((unsigned int)fixpoint_mul(a11a, dir_x) >> 16) - fixpoint_mul(v15, face->pFacePlane_old.vNormal.x);
+  HIWORD(a7a) = Y + ((unsigned int)fixpoint_mul(a11a, dir_y) >> 16) - fixpoint_mul(v15, face->pFacePlane_old.vNormal.y);
+  if ( !sub_4759C9(face, a10, a7a, (short)Z + ((unsigned int)fixpoint_mul(a11a, dir_z) >> 16) - fixpoint_mul(v15, face->pFacePlane_old.vNormal.z)) )
     return false;
   *a2 = a11a >> 16;
   if ( a11a >> 16 < 0 )
@@ -1416,7 +1420,7 @@
           || (word_720A70_intercepts_xs_plus_xs[v21] + ((signed int)(((unsigned __int64)(v19
               / (word_7209A0_intercepts_ys_plus_ys[v21 + 1] - word_7209A0_intercepts_ys_plus_ys[v21])
               * ((v24 - (signed int)word_7209A0_intercepts_ys_plus_ys[v21]) << 16)) >> 16)
-              + 32768) >> 16) >= v23) )
+              + 0x8000) >> 16) >= v23) )
           ++a4d;
       }
     }
@@ -1451,13 +1455,12 @@
   v4 = a4;
   v15 = a2;
   v14 = a1;
-  if ( BYTE3(a4->uAttributes) & 0x20
-    || (v5 = (unsigned __int64)(a2->x * (signed __int64)a4->pFacePlane_old.vNormal.x) >> 16,
-        a4b = (unsigned __int64)(a2->y * (signed __int64)a4->pFacePlane_old.vNormal.y) >> 16,
-        v6 = (unsigned __int64)(a2->z * (signed __int64)v4->pFacePlane_old.vNormal.z) >> 16,
-        v7 = v5 + v6 + a4b,
-        (v16 = v5 + v6 + a4b) == 0)
-    || v7 > 0 && !v4->Portal())
+  v5 = fixpoint_mul(a2->x, a4->pFacePlane_old.vNormal.x);
+  a4b = fixpoint_mul(a2->y, a4->pFacePlane_old.vNormal.y);
+  v6 = fixpoint_mul(a2->z, v4->pFacePlane_old.vNormal.z);
+  v7 = v5 + v6 + a4b;
+  //(v16 = v5 + v6 + a4b) == 0;
+  if ( a4->uAttributes & 0x20000000 || !v7 || v7 > 0 && !v4->Portal())
     return 0;
   v8 = v4->pFacePlane_old.vNormal.z * a1->z;
   v9 = -(v4->pFacePlane_old.dist + v8 + a1->y * v4->pFacePlane_old.vNormal.y + a1->x * v4->pFacePlane_old.vNormal.x);
@@ -1472,17 +1475,14 @@
       return 0;
   }
   a4c = abs(-(v4->pFacePlane_old.dist + v8 + a1->y * v4->pFacePlane_old.vNormal.y + a1->x * v4->pFacePlane_old.vNormal.x)) >> 14;
-  if ( a4c > abs(v7)
-    || (LODWORD(v10) = v9 << 16, HIDWORD(v10) = v9 >> 16, a4a = v10 / v16, v17 = v10 / v16, v17 > *a3 << 16)
-    || (v11 = v14,
-        LOWORD(v12) = LOWORD(v14->x)
-                    + (((unsigned int)((unsigned __int64)(v17 * (signed __int64)v15->x) >> 16) + 32768) >> 16),
-        HIWORD(v12) = LOWORD(v11->y)
-                    + (((unsigned int)((unsigned __int64)(v17 * (signed __int64)v15->y) >> 16) + 32768) >> 16),
-        !sub_475665(
-           v4,
-           v12,
-           LOWORD(v11->z) + (((unsigned int)((unsigned __int64)(v17 * (signed __int64)v15->z) >> 16) + 32768) >> 16))) )
+  v11 = v14;
+  LODWORD(v10) = v9 << 16;
+  HIDWORD(v10) = v9 >> 16;
+  a4a = v10 / v7;
+  v17 = v10 / v7;
+  LOWORD(v12) = LOWORD(v14->x) + (((unsigned int)fixpoint_mul(v17, v15->x) + 0x8000) >> 16);
+  HIWORD(v12) = LOWORD(v11->y) + (((unsigned int)fixpoint_mul(v17, v15->y) + 0x8000) >> 16);
+  if ( a4c > abs(v7) || ( v17 > *a3 << 16) || !sub_475665(v4, v12, LOWORD(v11->z) + (((unsigned int)fixpoint_mul(v17, v15->z) + 0x8000) >> 16)) )
     return 0;
   *a3 = a4a >> 16;
   return 1;
@@ -1494,7 +1494,7 @@
   int v10; // ST20_4@2
   int v11; // ST28_4@2
   int v12; // ST24_4@2
-  char v13; // zf@2
+  int v13; // zf@2
   int v14; // edi@2
   signed int v16; // esi@5
   int v17; // ST20_4@9
@@ -1504,15 +1504,13 @@
   int v23; // [sp+1Ch] [bp-8h]@10
   signed int v24; // [sp+20h] [bp-4h]@10
 
-  if ( a2->Ethereal()
-    || (v10 = (unsigned __int64)(a6 * (signed __int64)a2->pFacePlane_old.vNormal.x) >> 16,
-        v11 = (unsigned __int64)(a7 * (signed __int64)a2->pFacePlane_old.vNormal.y) >> 16,
-        v12 = (unsigned __int64)(a8 * (signed __int64)a2->pFacePlane_old.vNormal.z) >> 16,
-        v13 = v10 + v12 + v11 == 0,
-        v14 = v10 + v12 + v11,
-        v22 = v10 + v12 + v11,
-        v13)
-    || v14 > 0 && !a2->Portal())
+  v10 = fixpoint_mul(a6, a2->pFacePlane_old.vNormal.x);
+  v11 = fixpoint_mul(a7, a2->pFacePlane_old.vNormal.y);
+  v12 = fixpoint_mul(a8, a2->pFacePlane_old.vNormal.z);
+  v13 = v10 + v12 + v11;
+  v14 = v10 + v12 + v11;
+  v22 = v10 + v12 + v11;
+  if ( a2->Ethereal() || !v13 || v14 > 0 && !a2->Portal())
     return 0;
   v16 = -(a2->pFacePlane_old.dist + a4 * a2->pFacePlane_old.vNormal.y + a3 * a2->pFacePlane_old.vNormal.x + a5 * a2->pFacePlane_old.vNormal.z);
   if ( v14 <= 0 )
@@ -1526,12 +1524,13 @@
       return 0;
   }
   v17 = abs(-(a2->pFacePlane_old.dist + a4 * a2->pFacePlane_old.vNormal.y + a3 * a2->pFacePlane_old.vNormal.x + a5 * a2->pFacePlane_old.vNormal.z)) >> 14;
-  if ( v17 > abs(v14)
-    || (LODWORD(v18) = v16 << 16, HIDWORD(v18) = v16 >> 16, v24 = v18 / v22, v23 = v18 / v22, v23 > *a1 << 16)
-    || (LOWORD(v19) = a3 + (((unsigned int)((unsigned __int64)(v23 * (signed __int64)a6) >> 16) + 32768) >> 16),
-        HIWORD(v19) = a4 + (((unsigned int)((unsigned __int64)(v23 * (signed __int64)a7) >> 16) + 32768) >> 16),
-        !sub_4759C9(a2, a9, v19,
-           a5 + (((unsigned int)((unsigned __int64)(v23 * (signed __int64)a8) >> 16) + 32768) >> 16))) )
+  LODWORD(v18) = v16 << 16;
+  HIDWORD(v18) = v16 >> 16;
+  v24 = v18 / v22;
+  v23 = v18 / v22;
+  LOWORD(v19) = a3 + (((unsigned int)fixpoint_mul(v23, a6) + 0x8000) >> 16);
+  HIWORD(v19) = a4 + (((unsigned int)fixpoint_mul(v23, a7) + 0x8000) >> 16);
+  if ( v17 > abs(v14) || v23 > *a1 << 16 || !sub_4759C9(a2, a9, v19, a5 + (((unsigned int)fixpoint_mul(v23, a8) + 0x8000) >> 16)) )
     return 0;
   *a1 = v24 >> 16;
   return 1;
@@ -1555,7 +1554,7 @@
 int stru6_stru1_indoor_sw_billboard::_4775ED(float a2)
 {
   char *v2; // edi@1
-  int v3; // eax@1
+  //int v3; // eax@1
   char *v4; // edx@2
   char *v5; // esi@3
   double v6; // st7@6
@@ -1594,7 +1593,7 @@
   float v39; // [sp+D0h] [bp-8h]@6
   int *v40; // [sp+D4h] [bp-4h]@2
 
-  __debugbreak();//нужно почистить, срабатывает при применении закла Точечный взрыв и при стрельбе из жезла
+//  __debugbreak();//нужно почистить, срабатывает при применении закла Точечный взрыв и при стрельбе из жезла
   v2 = (char *)&this->field_64[4 * this->uNumVertices];
   v38 = 0;
   *(int *)v2 = this->field_64[0];
@@ -1603,22 +1602,23 @@
   v2 += 4;
   *(int *)v2 = this->field_64[2];
   *((int *)v2 + 1) = this->field_64[3];
-  v3 = this->uNumVertices;
+  //v3 = this->uNumVertices;
   v35 = this;
-  if ( v3 > 0 )
+  if ( this->uNumVertices > 0 )
   {
     v40 = &this->field_64[20];
     v4 = (char *)&this->field_64[3] + 3;
-    v34 = v3;
-    while ( 1 )
+    
+    //while ( 1 )
+	for ( v34 = this->uNumVertices; v34; --v34 )
     {
       v5 = v4 - 15;
       if ( *(float *)(v4 - 15) <= (double)a2 && *(float *)(v4 + 1) <= (double)a2 )
 	  {
         v4 += 16;
-		--v34;
-		if ( !v34 )
-		  return this->uNumVertices = v38;
+		//--v34;
+		//if ( !v34 )
+		  //return this->uNumVertices = v38;
 		continue;
 	  }
       if ( *(float *)v5 <= (double)a2 )
@@ -1691,9 +1691,9 @@
       *v27 = *(int *)v28;
       v27[1] = *(int *)(v28 + 4);
       v4 += 16;
-      --v34;
-      if ( !v34 )
-          return this->uNumVertices = v38;
+      //--v34;
+      //if ( !v34 )
+          //return this->uNumVertices = v38;
     }
   }
   return this->uNumVertices = v38;
@@ -2012,7 +2012,7 @@
   signed int v9; // [sp+Ch] [bp-8h]@1
   float v10; // [sp+10h] [bp-4h]@2
 
-  __debugbreak();// почистить
+  //__debugbreak();// почистить
   v1 = 0;
   v9 = 0;
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
@@ -2067,7 +2067,7 @@
   int a6; // [sp+3Ch] [bp-8h]@5
   int a5; // [sp+40h] [bp-4h]@5
 
-  __debugbreak(); //необходимо проверить this->field_B4[i*4+16]
+//  __debugbreak(); //необходимо проверить this->field_B4[i*4+16]
   v16 = 0;
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
   {
@@ -2131,7 +2131,7 @@
   stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
   v17 = v3 * stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY) + v4 * stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
   if (pGame->pIndoorCameraD3D->sRotationX)
-    v17 = (unsigned __int64)(v17 * (signed __int64)stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX)) >> 16;
+    v17 = fixpoint_mul(v17, stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX));
   v19 = v4 * stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY) - v3 * stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
   v9 = int_get_vector_length(abs(v3), abs(v4), 0);
   //v10 = v14 * 188;
@@ -2140,9 +2140,9 @@
   if ( v9 < pOutdoor->pBModels[uModelID].sBoundingRadius + 256 )
     *reachable = true;
   if ( v19 >= 0 )
-    v11 = ((unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)v17) >> 16) - ((unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)v19) >> 16);
+    v11 = fixpoint_mul(stru_5C6E00->Sin(angle), v17) - fixpoint_mul(stru_5C6E00->Cos(angle), v19);
   else
-    v11 = ((unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)v19) >> 16) + ((unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)v17) >> 16);
+    v11 = fixpoint_mul(stru_5C6E00->Cos(angle), v19) + fixpoint_mul(stru_5C6E00->Sin(angle), v17);
   v12 = v11 >> 16;
   if ( v9 <= pODMRenderParams->shading_dist_mist + 2048 )
   {
@@ -2821,43 +2821,75 @@
 //----- (0047C3D7) --------------------------------------------------------
 int __fastcall sub_47C3D7_get_fog_specular(int a1, int a2, float a3)
 {
-  double v5; // st7@10
+  int v3; // ecx@1
   signed int v7; // ecx@11
-  double v8; // st6@12
-  double v9; // st7@15
-  double v10; // st6@16
-  float v11; // ST14_4@17
-  double v12; // ST08_8@17
-
+
+  v3 = pWeather->bNight;
+  if ( bUnderwater == 1 )
+    v3 = 0;
   if ( pParty->armageddon_timer || !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater )
     return 0xFF000000;
-  if ( a3 == 0.0 )
-    return (unsigned int)(-1 - 216) << 24;
-  if ( a2 )
-    return (unsigned int)(-1 - 248) << 24;
-  if (a3 < (double)day_fogrange_1)
-    return (unsigned int)(-1) << 24;
-  if (a3 < (double)day_fogrange_2)
-    return (unsigned int)(-1 - 216) << 24;
-
-  if ( pWeather->bNight && !bUnderwater)
+  if ( v3 )
   {
-    v5 = (double)day_fogrange_1;
-    v8 = (double)day_fogrange_2;
-    v7 = (signed __int64)((a3 - v5) / (v8 - v5) * 216.0);
+    if ( a3 < (double)day_fogrange_1 )
+    {
+      v7 = 0;
+      if ( a3 == 0.0 )
+        v7 = 216;
+      if ( a2 )
+        v7 = 248;
+      return (-1 - v7) << 24;
+    }
+    else
+    {
+      if ( a3 > (double)day_fogrange_2 )
+      {
+        v7 = 216;
+        if ( a3 == 0.0 )
+          v7 = 216;
+        if ( a2 )
+          v7 = 248;
+        return (-1 - v7) << 24;
+      }
+      v7 = (signed __int64)((a3 - (double)day_fogrange_1) / ((double)day_fogrange_2 - (double)day_fogrange_1) * 216.0);
+    }
   }
   else
   {
-    v9 = (double)day_fogrange_1;
-    v10 = (double)day_fogrange_2;
-    v11 = (a3 - v9) * 216.0 / (v10 - v9);
-    v7 = bankersRounding(v11);
+    if ( a3 < (double)day_fogrange_1 )
+    {
+      v7 = 0;
+      if ( a3 == 0.0 )
+        v7 = 216;
+      if ( a2 )
+        v7 = 248;
+      return (-1 - v7) << 24;
+    }
+    else
+    {
+      if ( a3 > (double)day_fogrange_2 )
+      {
+        v7 = 216;
+        if ( a3 == 0.0 )
+          v7 = 216;
+        if ( a2 )
+          v7 = 248;
+        return (-1 - v7) << 24;
+      }
+      else
+        v7 = floorf(((a3 - (double)day_fogrange_1) * 216.0 / ((double)day_fogrange_2 - (double)day_fogrange_1)) + 0.5f);
+    }
   }
   if ( v7 > 216 )
+    v7 = 216;
+  else
   {
-    v7 = 216;
+    if ( a3 == 0.0 )
+      v7 = 216;
   }
-  return ( -1 - v7) << 24;
+  if ( a2 )
+    v7 = 248;
+  return (-1 - v7) << 24;
 }
 
 //----- (0047C4FC) --------------------------------------------------------
@@ -3311,14 +3343,6 @@
                                 this->viewing_angle_from_north_south, this->field_8_party_dir_z);
 }
 
-//----- (0044100D) --------------------------------------------------------
-bool sub_44100D()
-{
-  return pCurrentScreen == SCREEN_NPC_DIALOGUE || pCurrentScreen == SCREEN_CHARACTERS ||
-         pCurrentScreen == SCREEN_HOUSE || pCurrentScreen == SCREEN_E ||
-         pCurrentScreen == SCREEN_CHANGE_LOCATION || pCurrentScreen == SCREEN_INPUT_BLV || pCurrentScreen == SCREEN_CASTING;
-}
-// 4E28F8: using guessed type int pCurrentScreen;
 
 //----- (00441A4E) --------------------------------------------------------
 __int16 __fastcall sub_441A4E(int a1)//for blessing
@@ -3335,7 +3359,7 @@
   RenderBillboardTransform_local0 v10; // [sp+Ch] [bp-5Ch]@1
   int v11; // [sp+5Ch] [bp-Ch]@6
   int v12; // [sp+60h] [bp-8h]@1
-  int v13; // [sp+64h] [bp-4h]@6
+  //int v13; // [sp+64h] [bp-4h]@6
 
   v10.sParentBillboardID = -1;
   v10.pTarget = pRenderer->pTargetSurface;
@@ -3345,8 +3369,8 @@
   v2 = a1;
   v10.uViewportX = 0;
   v10.uViewportY = 0;
-  v10.uViewportZ = 639;
-  v10.uViewportW = 479;
+  v10.uViewportZ = window->GetWidth() - 1;
+  v10.uViewportW = window->GetHeight() - 1;
   v12 = 0;
   //v3 = (char *)&pOtherOverlayList->pOverlays[0].field_C;
   //do
@@ -3372,18 +3396,18 @@
             //v7 = v6;
             v11 = pOtherOverlayList->pOverlays[i].field_E;
             //v13 = pFrame->scale;
-            v13 = (unsigned __int64)(v11 * (signed __int64)pFrame->scale) >> 16;
+            //v13 = fixpoint_mul(v11, pFrame->scale);
             v10.uScreenSpaceX = pOtherOverlayList->pOverlays[i].field_8;
             v10.uScreenSpaceY = pOtherOverlayList->pOverlays[i].field_A;
-            v10._screenspace_x_scaler_packedfloat = v13;
-            v10._screenspace_y_scaler_packedfloat = v13;
+            v10._screenspace_x_scaler_packedfloat = fixpoint_mul(v11, pFrame->scale);
+            v10._screenspace_y_scaler_packedfloat = fixpoint_mul(v11, pFrame->scale);
             v10.pPalette = PaletteManager::Get_Dark_or_Red_LUT(pFrame->uPaletteIndex, 0, 1);
             v8 = pOtherOverlayList->pOverlays[i].field_2;
             v10.sZValue = 0;
             v10.uFlags = 0;
-            v9 = pOverlayList->pOverlays[v8].uOverlayType;
-            if ( !v9 || v9 == 2 )
-              v10.uScreenSpaceY += pSprites_LOD->pSpriteHeaders[pFrame->pHwSpriteIDs[0]].uHeight >> 1;
+            //v9 = pOverlayList->pOverlays[v8].uOverlayType;
+            if ( !pOverlayList->pOverlays[v8].uOverlayType || pOverlayList->pOverlays[v8].uOverlayType == 2 )
+              v10.uScreenSpaceY += pSprites_LOD->pSpriteHeaders[pFrame->pHwSpriteIDs[0]].uHeight / 2;
             result = pSprites_LOD->pSpriteHeaders[pFrame->pHwSpriteIDs[0]]._4AD2D1(&v10, 0);
             ++v12;
             if ( v12 == 5 )
@@ -3857,7 +3881,7 @@
     dword_5C3418 = a1;
     dword_5C341C = a2;
     _591094_decoration = activeLevelDecoration;
-    pGUIWindow2 = GUIWindow::Create(0, 0, 640, 480, WINDOW_GreetingNPC, a4, 0);
+    pGUIWindow2 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_GreetingNPC, a4, 0);
     pGUIWindow2->CreateButton( 61, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
     pGUIWindow2->CreateButton(177, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
     pGUIWindow2->CreateButton(292, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
--- a/mm7_4.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/mm7_4.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -2324,7 +2324,7 @@
   v1 = 0;
   pDialogueWindow->eWindowType = WINDOW_MainMenu;
   pDialogueWindow->Release();
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_Dialogue, 1, 0);
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Dialogue, 1, 0);
   if ( pNPCStats->pProfessions[v0->uProfession].pBenefits)//*(&pNPCStats->field_13A5C + 5 * v0->uProfession) )
   {
     pDialogueWindow->CreateButton(480, 160, 140, 28, 1, 0, UIMSG_SelectNPCDialogueOption, 77, 0, pGlobalTXT_LocalizationStrings[407], 0);
@@ -2345,7 +2345,7 @@
   current_npc_text = (char *)pNPCTopics[a4 + 168].pText;
   _4B254D_SkillMasteryTeacher(a4);
   pDialogueWindow->Release();
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 350, WINDOW_MainMenu, a4, 0);
+  pDialogueWindow = GUIWindow::Create(0, 0, window->GetWidth(), 350, WINDOW_MainMenu, a4, 0);
   pBtn_ExitCancel = pDialogueWindow->CreateButton( 471, 445, 169,  35,   1,  0, UIMSG_Escape, 0,   0,
                  pGlobalTXT_LocalizationStrings[34], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);
   pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0);
--- a/mm7_5.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/mm7_5.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -14,6 +14,7 @@
 #include "Lights.h"
 #include "Level/Decoration.h"
 
+
 //----- (004356FF) --------------------------------------------------------
 void back_to_game()
 {
@@ -60,7 +61,7 @@
   int attacker_id; // [sp+10h] [bp-18h]@1
   int v44; // [sp+14h] [bp-14h]@15
   //Vec3_int_ *pVelocity; // [sp+1Ch] [bp-Ch]@2
-  int a1; // [sp+20h] [bp-8h]@8
+  signed int a1; // [sp+20h] [bp-8h]@8
   int v48; // [sp+24h] [bp-4h]@8
 
 
@@ -133,7 +134,7 @@
     else //damage from spells(повреждения от заклов(метеоритный дождь))
     {
       v23 = pParty->vPosition.y - AttackerInfo.pYs[attacker_id];
-      v24 = ((signed int)pParty->uPartyHeight >> 1) - AttackerInfo.pZs[attacker_id];
+      v24 = ((signed int)pParty->uPartyHeight / 2) - AttackerInfo.pZs[attacker_id];
       a1 = pParty->vPosition.x - AttackerInfo.pXs[attacker_id];
       v48 = pParty->vPosition.y - AttackerInfo.pYs[attacker_id];
       if ( a1 * a1 + v23 * v23 + (pParty->vPosition.z + v24) * (pParty->vPosition.z + v24) < (unsigned int)((AttackerInfo.field_324[attacker_id] + 32) * (AttackerInfo.field_324[attacker_id] + 32)) )
@@ -157,19 +158,19 @@
         {
           if ( pActors[actorID].CanAct() )
           {
-            v30 = pActors[actorID].vPosition.y - AttackerInfo.pYs[attacker_id];
+            //v30 = pActors[actorID].vPosition.y - AttackerInfo.pYs[attacker_id];
             a1 = pActors[actorID].vPosition.x - AttackerInfo.pXs[attacker_id];
             v31 = pActors[actorID].vPosition.z;
-            v48 = v30;
+            v48 = pActors[actorID].vPosition.y - AttackerInfo.pYs[attacker_id];
             v44 = pActors[actorID].vPosition.z;
-            v32 = (pActors[actorID].uActorHeight >> 1) - AttackerInfo.pZs[attacker_id];
+            v32 = (pActors[actorID].uActorHeight / 2) - AttackerInfo.pZs[attacker_id];
             v33 = pActors[actorID].uActorRadius + AttackerInfo.pYs[attacker_id];
             if ( a1 * a1 + v48 * v48 + (v31 + v32) * (v31 + v32) < (unsigned int)(v33 * v33) )
             {
               attacker_coord.x = AttackerInfo.pXs[attacker_id];
               attacker_coord.y = AttackerInfo.pYs[attacker_id];
               attacker_coord.z = AttackerInfo.pZs[attacker_id];
-              if ( sub_407A1C(pActors[actorID].vPosition.x, pActors[actorID].vPosition.y, pActors[actorID].vPosition.z + 50, attacker_coord) )
+              if ( sub_407A1C(pActors[actorID].vPosition.x, pActors[actorID].vPosition.y, pActors[actorID].vPosition.z + 50, attacker_coord) )//что делает ф-ция?
               {
                 Vec3_int_::Normalize(&a1, &v48, &v44);
                 AttackerInfo.vec_4B4[attacker_id].x = a1;
@@ -286,9 +287,9 @@
             a2a = 10;
           if ( !MonsterStats::BelongsToSupertype(pActors[uActorID].pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
           {
-            pVelocity->x = (unsigned __int64)(a2a * (signed __int64)pVelocity->x) >> 16;
-            pVelocity->y = (unsigned __int64)(a2a * (signed __int64)pVelocity->y) >> 16;
-            pVelocity->z = (unsigned __int64)(a2a * (signed __int64)pVelocity->z) >> 16;
+            pVelocity->x = fixpoint_mul(a2a, pVelocity->x);
+            pVelocity->y = fixpoint_mul(a2a, pVelocity->y);
+            pVelocity->z = fixpoint_mul(a2a, pVelocity->z);
             pActors[uActorID].vVelocity.x = 50 * LOWORD(pVelocity->x);
             pActors[uActorID].vVelocity.y = 50 * LOWORD(pVelocity->y);
             pActors[uActorID].vVelocity.z = 50 * LOWORD(pVelocity->z);
@@ -373,9 +374,9 @@
             v18 = 10;
           if ( !MonsterStats::BelongsToSupertype(pActors[actor_id].pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
           {
-            pVelocity->x = (unsigned __int64)(v18 * (signed __int64)pVelocity->x) >> 16;
-            pVelocity->y = (unsigned __int64)(v18 * (signed __int64)pVelocity->y) >> 16;
-            pVelocity->z = (unsigned __int64)(v18 * (signed __int64)pVelocity->z) >> 16;
+            pVelocity->x = fixpoint_mul(v18, pVelocity->x);
+            pVelocity->y = fixpoint_mul(v18, pVelocity->y);
+            pVelocity->z = fixpoint_mul(v18, pVelocity->z);
             pActors[actor_id].vVelocity.x = 50 * LOWORD(pVelocity->x);
             pActors[actor_id].vVelocity.y = 50 * LOWORD(pVelocity->y);
             pActors[actor_id].vVelocity.z = 50 * LOWORD(pVelocity->z);
@@ -1064,7 +1065,7 @@
         *pZBuffer = uZValue;
       ++pZBuffer;
     }
-    pZBuffer += 640 - pTex->uTextureWidth;
+    pZBuffer += window->GetWidth() - pTex->uTextureWidth;
   }
   if ( pIcons_LOD->dword_011BA4 )
   {
@@ -1093,7 +1094,7 @@
       *pZBuffer = a3;
       ++pZBuffer;
     }
-    pZBuffer += 640 - a2->uTextureWidth;
+    pZBuffer += window->GetWidth() - a2->uTextureWidth;
   }
   if ( pIcons_LOD->dword_011BA4 )
   {
--- a/mm7_data.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/mm7_data.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -2,7 +2,7 @@
 
 #include "GUIWindow.h"
 #include "Party.h"
-
+#include "OSWindow.h"
 
 
 void ErrHR(HRESULT hr, const char *pAPI, const char *pFunction, const char *pFile, int line)
--- a/mm7_unsorted_subs.h	Wed Feb 19 22:26:10 2014 +0100
+++ b/mm7_unsorted_subs.h	Wed Feb 19 22:30:39 2014 +0100
@@ -105,7 +105,7 @@
 void PrepareItemsRenderList_BLV();
 void AddBspNodeToRenderList(unsigned int node_id);
 void __fastcall sub_4406BC(unsigned int node_id, unsigned int uFirstNode); // idb
-bool sub_44100D();
+bool _44100D_should_alter_right_panel();
 __int16 __fastcall sub_441A4E(int a1);
 void DrawBook_Map_sub(unsigned int tl_x, unsigned int tl_y, unsigned int br_x, int br_y, int _48074); // idb
 void Initialize2DA();
--- a/stru6.cpp	Wed Feb 19 22:26:10 2014 +0100
+++ b/stru6.cpp	Wed Feb 19 22:30:39 2014 +0100
@@ -477,12 +477,7 @@
 //----- (004A7A27) --------------------------------------------------------
 bool stru6::AddMobileLight(SpriteObject *a1, unsigned int uDiffuse, int uRadius)
 {
-  return pMobileLightsStack->AddLight(
-           a1->vPosition.x,
-           a1->vPosition.y,
-           a1->vPosition.z,
-           a1->uSectorID,
-           uRadius,
+  return pMobileLightsStack->AddLight(a1->vPosition.x, a1->vPosition.y, a1->vPosition.z, a1->uSectorID, uRadius,
            (uDiffuse & 0x00FF0000) >> 16,
            (uDiffuse & 0x0000FF00) >> 8,
            uDiffuse & 0x000000FF,