changeset 1256:236d39ae8f6e

arcomage playable
author Gloval
date Wed, 12 Jun 2013 12:05:39 +0400
parents fac7751b2dc9
children 8cf1eb87a44e
files Arcomage.cpp Arcomage.h mm7_data.cpp mm7_data.h
diffstat 4 files changed, 513 insertions(+), 930 deletions(-) [+]
line wrap: on
line diff
--- a/Arcomage.cpp	Tue Jun 11 18:52:42 2013 +0200
+++ b/Arcomage.cpp	Wed Jun 12 12:05:39 2013 +0400
@@ -32,9 +32,10 @@
 void GetNextCardFromDeck(int player_num);
 int  GetEmptyCardSlotIndex(int player_num);
 void IncreaseResourcesInTurn(int player_num);
-void __cdecl am_40A383();
-bool  IsGameOver();
-char __thiscall am_40A560(unsigned int _this);
+void  TurnChange();
+bool IsGameOver();
+int  CalculateCardPower(ArcomagePlayer* player, ArcomagePlayer* enemy, ArcomageCard* pCard, int mastery);
+char PlayerTurn(int player_num);
 void DrawGameUI(int a1); // idb
 void am_40AA4E();
 void DrawRectanglesForText();
@@ -49,7 +50,7 @@
 void DrawCardAnimation(int a1);
 int GetPlayerHandCardCount(int player_num);
 signed int  DrawCardsRectangles(int player_num);
-bool  am_40BCFB(int player_num, signed int card_slot_index);
+bool DiscardCard(int player_num, signed int card_slot_index);
 bool PlayCard(int player_num, signed int card_slot_num);
 bool CanCardBePlayed(int player_num, int hand_card_indx);
 void ApplyCardToPlayer(int player_num, unsigned int uCardID); // idb
@@ -81,10 +82,10 @@
   __int16 bricks_amount;
   __int16 gems_amount;
   __int16 beasts_amount;
-  int field_14;
+  int mastery_lvl;
 };
 #pragma pack(pop)
-ArcomageStartConditions start_conditions[13] =
+const ArcomageStartConditions start_conditions[13] =
 {
   { 30, 100, 15,  5,  2,  2,  2, 10, 10, 10,  0},
   { 50, 150, 20,  5,  2,  2,  2,  5,  5,  5,  1},
@@ -135,6 +136,17 @@
 #pragma pack(pop)
 
 
+#pragma pack(push, 1)
+struct am_2
+    {  
+    int slot_index;
+    int card_power;
+    };
+#pragma pack(pop)
+
+am_2  stru_4FA9B0[10];
+std::array<__int16, 12> am_sounds;
+
 char byte_4E185C  = 1; // weak
 char am_byte_4E185D = 1; // weak
 char byte_4E185E = 1; // weak
@@ -154,7 +166,7 @@
 int max_tower_height       = 50; 
 int max_resources_amount   = 100 ; 
 
-int dword_4DF3A4; // weak
+int opponent_mastery = 1 ; // weak
 
 char byte_4FAA2C; // weak
 char byte_4FAA2D; // weak
@@ -182,6 +194,24 @@
 
 int dword_4FABB8; // weak
 
+char byte_4FAA00; // weak
+
+int amuint_4FAA34; // weak
+int amuint_4FAA38; // weak
+int amuint_4FAA4C; // weak
+
+char byte_4FAA2E; // weak
+
+int dword_4FAA70; // weak
+char byte_4FAA74; // weak
+char am_byte_4FAA75; // weak
+char am_byte_4FAA76; // weak
+
+int amuint_4FABC4; // weak
+
+
+char byte_505880; // weak
+char byte_505881; // weak
 
 //----- (0040DD2F) --------------------------------------------------------
 bool stru273::_40DD2F()
@@ -428,9 +458,9 @@
   pTargetPoint.x = 0;
   pTargetPoint.y = 0;
 
-  pSrcRect.left = 0;
-  pSrcRect.right = 640;
-  pSrcRect.top = 0;
+  pSrcRect.left   = 0;
+  pSrcRect.top    = 0;
+  pSrcRect.right  = 640;
   pSrcRect.bottom = 480;
 
   pRenderer->BeginScene();
@@ -758,793 +788,444 @@
   return true;
 }
 
+int CalculateCardPower(ArcomagePlayer* player, ArcomagePlayer* enemy, ArcomageCard* pCard, int mastery)
+    {
+    enum V_INDX{
+        P_TOWER_M10,
+        P_WALL_M10,
+        E_TOWER,
+        E_WALL,
+        E_BUILDINGS,
+        E_QUARRY,
+        E_MAGIC,
+        E_ZOO,
+        E_RES,
+        V_INDEX_MAX
+        };
+
+    const int mastery_coeff[V_INDEX_MAX][2]= {{10, 5}, //P_TOWER_M10
+                                              {2, 1},  //P_WALL_M10
+                                              {1, 10}, //E_TOWER
+                                              {1, 3},  //E_WALL
+                                              {1, 7},  //E_BUILDINGS
+                                              {1, 5},  //E_QUARRY
+                                              {1, 40},  //E_MAGIC
+                                              {1, 40},  //E_ZOO
+                                              {1, 2}   //E_RES
+        };
+    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; 
+    else
+        element_power = pCard->to_player_tower + pCard->to_pl_enm_tower + pCard->to_player_tower2 + pCard->to_pl_enm_tower2;
+        
+    if ( player->tower_height >= 10 )
+      card_power += mastery_coeff[P_TOWER_M10][mastery]*element_power; 
+    else
+      card_power += 20*element_power; 
+
+
+    if ( pCard->to_player_wall  == 99 || pCard->to_pl_enm_wall  == 99 || 
+         pCard->to_player_wall2 == 99 || pCard->to_pl_enm_wall2 == 99 )
+        element_power = enemy->wall_height - player->wall_height;
+    else
+        element_power = pCard->to_player_wall  + pCard->to_pl_enm_wall + 
+                        pCard->to_player_wall2 + pCard->to_pl_enm_wall2;
+    if ( player->wall_height >= 10 )
+        card_power += mastery_coeff[P_WALL_M10][mastery]*element_power; //1
+    else
+        card_power += 5*element_power; 
+
+
+    card_power += 7 * (pCard->to_player_buildings  + pCard->to_pl_enm_buildings + 
+                       pCard->to_player_buildings2 + pCard->to_pl_enm_buildings2);
+
+    if ( pCard->to_player_quarry_lvl  == 99 || pCard->to_pl_enm_quarry_lvl  == 99 || 
+         pCard->to_player_quarry_lvl2 == 99 || pCard->to_pl_enm_quarry_lvl2 == 99 )
+        element_power = enemy->quarry_level - player->quarry_level;
+    else
+        element_power = pCard->to_player_quarry_lvl  + pCard->to_pl_enm_quarry_lvl + 
+                        pCard->to_player_quarry_lvl2 + pCard->to_pl_enm_quarry_lvl;
+
+    card_power += 40 * element_power;
+
+    if ( pCard->to_player_magic_lvl  == 99 || pCard->to_pl_enm_magic_lvl  == 99 || 
+         pCard->to_player_magic_lvl2 == 99 || pCard->to_pl_enm_magic_lvl2 == 99 )
+        element_power = enemy->magic_level - player->magic_level;
+    else
+        element_power = pCard->to_player_magic_lvl  + pCard->to_pl_enm_magic_lvl + 
+                        pCard->to_player_magic_lvl2 + pCard->to_pl_enm_magic_lvl2;
+    card_power += 40 *element_power;
+
+    if ( pCard->to_player_zoo_lvl  == 99 || pCard->to_pl_enm_zoo_lvl  == 99 || 
+         pCard->to_player_zoo_lvl2 == 99 || pCard->to_pl_enm_zoo_lvl2 == 99 )
+        element_power = enemy->zoo_level - player->zoo_level;
+    else
+        element_power =  pCard->to_player_zoo_lvl  + pCard->to_pl_enm_zoo_lvl + 
+                         pCard->to_player_zoo_lvl2 + pCard->to_pl_enm_zoo_lvl2;
+    card_power += 40 *element_power;
+
+    if ( pCard->to_player_bricks  == 99 || pCard->to_pl_enm_bricks  == 99 || 
+         pCard->to_player_bricks2 == 99 || pCard->to_pl_enm_bricks2 == 99 )
+        element_power = enemy->resource_bricks - player->resource_bricks;
+    else
+        element_power = pCard->to_player_bricks  + pCard->to_pl_enm_bricks + 
+                        pCard->to_player_bricks2 + pCard->to_pl_enm_bricks2;
+    card_power += 2 *element_power;
+
+
+    if ( pCard->to_player_gems  == 99 || pCard->to_pl_enm_gems  == 99 || 
+         pCard->to_player_gems2 == 99 || pCard->to_pl_enm_gems2 == 99 )
+         element_power = enemy->resource_gems - player->resource_gems;
+    else
+        element_power = pCard->to_player_gems  + pCard->to_pl_enm_gems + 
+                        pCard->to_player_gems2 + pCard->to_pl_enm_gems2;
+    card_power += 2 *element_power;
+
+    if ( pCard->to_player_beasts  == 99 || pCard->to_pl_enm_beasts  == 99 || 
+        pCard->to_player_beasts2 == 99 || pCard->to_pl_enm_beasts2 == 99 )
+        element_power = enemy->resource_beasts - player->resource_beasts;
+    else
+        element_power = pCard->to_player_beasts  + pCard->to_pl_enm_beasts + 
+                        pCard->to_player_beasts2 + pCard->to_pl_enm_beasts2;
+    card_power += 2 *element_power;
+
+    if ( pCard->to_enemy_tower == 99 || pCard->to_enemy_tower2 == 99 )
+        element_power = player->tower_height - enemy->tower_height;  
+    else
+        element_power = -(pCard->to_enemy_tower + pCard->to_enemy_tower2);
+    card_power += mastery_coeff[E_TOWER][mastery]*element_power;
+
+    if ( pCard->to_enemy_wall == 99 || pCard->to_enemy_wall2 == 99 )
+        element_power = player->wall_height - enemy->wall_height;  
+    else
+        element_power = -(pCard->to_enemy_wall + pCard->to_enemy_wall2);
+    card_power += mastery_coeff[E_WALL][mastery]*element_power;
+
+     card_power -= mastery_coeff[E_BUILDINGS][mastery]*(pCard->to_enemy_buildings + pCard->to_enemy_buildings2); 
+ 
+    if ( pCard->to_enemy_quarry_lvl == 99 || pCard->to_enemy_quarry_lvl2 == 99 )
+        element_power = player->quarry_level - enemy->quarry_level;  //5
+    else
+        element_power = -(pCard->to_enemy_quarry_lvl + pCard->to_enemy_quarry_lvl2); //5
+    card_power += mastery_coeff[E_QUARRY][mastery]*element_power;
+
+    if ( pCard->to_enemy_magic_lvl == 99 || pCard->to_enemy_magic_lvl2 == 99 )
+        element_power = player->magic_level - enemy->magic_level;  //40
+    else
+        element_power = -(pCard->to_enemy_magic_lvl + pCard->to_enemy_magic_lvl2);
+    card_power += mastery_coeff[E_MAGIC][mastery]*element_power;
+
+    if ( pCard->to_enemy_zoo_lvl == 99 || pCard->to_enemy_zoo_lvl2 == 99 )
+        element_power = player->zoo_level - enemy->zoo_level; //40
+    else
+        element_power = -(pCard->to_enemy_zoo_lvl + pCard->to_enemy_zoo_lvl2);
+    card_power += mastery_coeff[E_ZOO][mastery]*element_power;
+
+    if ( pCard->to_enemy_bricks == 99 || pCard->to_enemy_bricks2 == 99 )
+        element_power = player->resource_bricks - enemy->resource_bricks;  //2
+    else
+        element_power = -(pCard->to_enemy_bricks + pCard->to_enemy_bricks2);
+    card_power += mastery_coeff[E_RES][mastery]*element_power;
+
+    if ( pCard->to_enemy_gems == 99 || pCard->to_enemy_gems2 == 99 )
+        element_power = player->resource_gems - enemy->resource_gems; //2
+    else
+        element_power = -(pCard->to_enemy_gems + pCard->to_enemy_gems2);
+    card_power += mastery_coeff[E_RES][mastery]*element_power;
+
+    if ( pCard->to_enemy_beasts == 99 || pCard->to_enemy_beasts2 == 99 )
+        element_power = player->resource_beasts - enemy->resource_beasts;  //2
+    else
+        element_power = -(pCard->to_enemy_beasts + pCard->to_enemy_beasts2);
+    card_power += mastery_coeff[E_RES][mastery]*element_power;
+
+    if ( pCard->field_30 || pCard->field_4D )
+         card_power *= 10;
+
+    if ( pCard->field_24 == 1 )
+        element_power = player->resource_bricks - pCard->needed_bricks;
+    else if ( pCard->field_24 == 2 )
+        element_power = player->resource_gems   - pCard->needed_gems;
+    else if (pCard->field_24 == 3)
+        element_power = player->resource_beasts - pCard->needed_beasts;
+    if ( element_power > 3 )
+        element_power = 3;
+    card_power += 5 * element_power;
+
+    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;
+    }
+
+
 //----- (00408BB4) --------------------------------------------------------
-bool __fastcall am_408BB4(int a1)
+bool OpponentsAITurn(int player_num)
 {
-//  char result; // al@3
-//  signed int v3; // ebx@8
-//  int v4; // esi@8
-//  int v5; // eax@9
-//  int v6; // edi@9
-//  int v7; // eax@11
-//  signed int v8; // eax@11
-//  int v9; // ebx@5
-//  int v10; // eax@5
-//  int v11; // ecx@18
-//  char v12; // bl@20
-//  int v13; // eax@20
-//  ArcomageCard *v14; // ecx@20
-//  char v15; // dl@20
-//  char v16; // dl@24
-//  int v17; // edx@25
-//  int v18; // edx@27
-//  char v19; // dl@31
-//  int v20; // edx@32
-//  char v21; // dl@35
-//  char v22; // dl@39
-//  int v23; // edx@40
-//  char v24; // dl@45
-//  int v25; // edx@46
-//  char v26; // dl@52
-//  int v27; // edx@53
-//  char v28; // dl@58
-//  int v29; // edx@59
-//  char v30; // dl@64
-//  int v31; // edx@65
-//  char v32; // dl@70
-//  int v33; // edx@71
-//  char v34; // dl@76
-//  int v35; // edx@77
-//  char v36; // dl@82
-//  int v37; // edx@83
-//  char v38; // dl@86
-//  char v39; // dl@90
-//  int v40; // edi@93
-//  char v41; // dl@93
-//  int v42; // esi@93
-//  char v43; // bl@94
-//  int v44; // esi@95
-//  char v45; // dl@99
-//  char v46; // dl@103
-//  char v47; // dl@107
-//  char v48; // dl@111
-//  char v49; // dl@115
-//  ArcomagePlayer *v50; // ebx@116
-//  ArcomagePlayer *v51; // edx@116
-//  int v52; // esi@124
-//  int v53; // edx@124
-//  int v54; // edx@127
-//  int v55; // esi@130
-//  int v56; // edi@138
-//  int l; // esi@138
-//  int v58; // eax@140
-//  int v59; // ecx@142
-//  int v60; // edx@142
-//  int v61; // ebx@142
-//  int v62; // eax@145
-//  int v63; // esi@146
-//  int v64; // ebx@4
-//  int v65; // eax@4
-//  int v66; // ecx@168
-//  char v67; // bl@170
-//  int v68; // eax@170
-//  ArcomageCard *v69; // ecx@170
-//  char v70; // dl@170
-//  char v71; // dl@174
-//  int v72; // edx@175
-//  int v73; // edx@177
-//  char v74; // dl@181
-//  char v75; // dl@184
-//  char v76; // dl@188
-//  int v77; // edx@189
-//  char v78; // dl@194
-//  char v79; // dl@200
-//  int v80; // edx@201
-//  char v81; // dl@206
-//  int v82; // edx@207
-//  char v83; // dl@212
-//  int v84; // edx@213
-//  char v85; // dl@218
-//  int v86; // edx@219
-//  char v87; // dl@224
-//  int v88; // edx@225
-//  char v89; // dl@230
-//  int v90; // edx@231
-//  char v91; // dl@234
-//  int v92; // edx@235
-//  char v93; // dl@238
-//  int v94; // edx@239
-//  int v95; // esi@241
-//  char v96; // dl@241
-//  int v97; // esi@241
-//  char v98; // bl@242
-//  int v99; // edi@243
-//  int v100; // edx@245
-//  int v101; // edi@246
-//  char v102; // dl@247
-//  int v103; // edx@248
-//  char v104; // dl@251
-//  int v105; // edx@252
-//  char v106; // dl@255
-//  int v107; // edx@256
-//  char v108; // dl@259
-//  int v109; // edx@260
-//  char v110; // dl@263
-//  ArcomagePlayer *v111; // ebx@264
-//  ArcomagePlayer *v112; // edx@264
-//  int v113; // esi@272
-//  int v114; // edx@272
-//  int v115; // edx@275
-//  int v116; // esi@278
-//  int v117; // edi@286
-//  int j; // esi@286
-//  int v119; // eax@288
-//  int v120; // ecx@290
-//  int v121; // edx@290
-//  int v122; // ebx@290
-//  int v123; // eax@293
-//  int v124; // esi@294
-//  int v125; // [sp-28h] [bp-28h]@130
-//  int v126; // [sp-28h] [bp-28h]@278
-//  int k; // [sp-24h] [bp-24h]@18
-//  int i; // [sp-24h] [bp-24h]@168
-//  int v129; // [sp-20h] [bp-20h]@5
-//  int v130; // [sp-20h] [bp-20h]@4
-//  int v131; // [sp-1Ch] [bp-1Ch]@17
-//  int v132; // [sp-1Ch] [bp-1Ch]@140
-//  int v133; // [sp-1Ch] [bp-1Ch]@167
-//  int v134; // [sp-1Ch] [bp-1Ch]@288
-//  int v135; // [sp-18h] [bp-18h]@5
-//  int v136; // [sp-18h] [bp-18h]@4
-//  signed int v137; // [sp-14h] [bp-14h]@0
-//  int v138; // [sp-14h] [bp-14h]@93
-//  int v139; // [sp-14h] [bp-14h]@130
-//  int v140; // [sp-14h] [bp-14h]@241
-//  int v141; // [sp-14h] [bp-14h]@278
-//  ArcomagePlayer *v142; // [sp-10h] [bp-10h]@5
-//  ArcomagePlayer *v143; // [sp-10h] [bp-10h]@4
-//  ArcomagePlayer *v144; // [sp-Ch] [bp-Ch]@5
-//  ArcomagePlayer *v145; // [sp-Ch] [bp-Ch]@4
-//  char v146; // [sp-8h] [bp-8h]@35
-//  char v147; // [sp-8h] [bp-8h]@184
-//  char v148; // [sp-5h] [bp-5h]@20
-//  char v149; // [sp-5h] [bp-5h]@170
-//
-//  byte_4FAA00 = 1;
-//  if ( dword_4DF3A4 )
-//  {
-//    if ( dword_4DF3A4 != 1 )
-//    {
-//      result = dword_4DF3A4 - 2;
-//      if ( dword_4DF3A4 != 2 )
-//        return result != 0;
-//      v64 = a1;
-//      v145 = &stru_505708[a1];
-//      v130 = a1;
-//      v143 = &stru_505708[(a1 + 1) % 2];
-//      v136 = GetPlayerHandCardCount(a1);
-//      v65 = 0;
-//      do
-//      {
-//        if ( v65 >= v136 )
-//        {
-//          dword_4FA9B0[2 * v65] = -1;
-//          dword_4FA9B4[2 * v65] = -9999;
-//        }
-//        else
-//        {
-//          dword_4FA9B0[2 * v65] = v65;
-//          dword_4FA9B4[2 * v65] = 0;
-//        }
-//        ++v65;
-//      }
-//      while ( v65 < 10 );
-//      v133 = 0;
-//      if ( v136 > 0 )
-//      {
-//        v66 = 47 * v64;
-//        for ( i = 47 * v64; ; v66 = i )
-//        {
-//          v67 = 99;
-//          v68 = 2 * v133;
-//          v69 = &pCards[stru_505708[0].cards_at_hand[v66 + dword_4FA9B0[2 * v133]]];
-//          v70 = v69->field_38[2];
-//          v149 = v69->field_38[2];
-//          if ( v145->field_24 >= 10 )
-//          {
-//            if ( v70 == 99
-//              || v69->field_48[4] == 99
-//              || v69->field_48[15] == 99
-//              || (v74 = BYTE1(v69->field_68), v74 == 99) )
-//              v73 = 5 * (v143->field_24 - v145->field_24);
-//            else
-//              v73 = 5 * (v149 + v69->field_48[4] + v69->field_48[15] + v74);
-//          }
-//          else
-//          {
-//            if ( v70 == 99
-//              || v69->field_48[4] == 99
-//              || v69->field_48[15] == 99
-//              || (v71 = BYTE1(v69->field_68), v71 == 99) )
-//              v72 = 5 * (v143->field_24 - v145->field_24);
-//            else
-//              v72 = 5 * (v149 + v69->field_48[4] + v69->field_48[15] + v71);
-//            v73 = 4 * v72;
-//          }
-//          dword_4FA9B4[v68] += v73;
-//          v75 = v69->field_38[1];
-//          v147 = v69->field_38[1];
-//          if ( v145->field_28 >= 10 )
-//          {
-//            if ( v75 == 99
-//              || v69->field_48[3] == 99
-//              || v69->field_48[14] == 99
-//              || (v78 = LOBYTE(v69->field_68), v78 == 99) )
-//              v77 = v143->field_28 - v145->field_28;
-//            else
-//              v77 = v147 + v69->field_48[3] + v69->field_48[14] + v78;
-//          }
-//          else
-//          {
-//            if ( v75 == 99
-//              || v69->field_48[3] == 99
-//              || v69->field_48[14] == 99
-//              || (v76 = LOBYTE(v69->field_68), v76 == 99) )
-//              v77 = 5 * (v143->field_28 - v145->field_28);
-//            else
-//              v77 = 5 * (v147 + v69->field_48[3] + v69->field_48[14] + v76);
-//          }
-//          dword_4FA9B4[v68] += v77;
-//          dword_4FA9B4[v68] += 7 * (v69->field_38[0] + v69->field_48[2] + v69->field_48[13] + v69->field_58[15]);
-//          if ( BYTE2(v69->field_30) == 99
-//            || v69->field_38[12] == 99
-//            || v69->field_48[7] == 99
-//            || (v79 = v69->field_58[9], v79 == 99) )
-//            v80 = 5 * (v143->field_2C - v145->field_2C);
-//          else
-//            v80 = 5 * (BYTE2(v69->field_30) + v69->field_38[12] + v69->field_48[7] + v79);
-//          dword_4FA9B4[v68] += 8 * v80;
-//          if ( BYTE3(v69->field_30) == 99
-//            || v69->field_38[13] == 99
-//            || v69->field_48[8] == 99
-//            || (v81 = v69->field_58[10], v81 == 99) )
-//            v82 = 5 * (v143->field_30 - v145->field_30);
-//          else
-//            v82 = 5 * (BYTE3(v69->field_30) + v69->field_38[13] + v69->field_48[8] + v81);
-//          dword_4FA9B4[v68] += 8 * v82;
-//          if ( LOBYTE(v69->field_34) == 99
-//            || v69->field_38[14] == 99
-//            || v69->field_48[9] == 99
-//            || (v83 = v69->field_58[11], v83 == 99) )
-//            v84 = 5 * (v143->field_34 - v145->field_34);
-//          else
-//            v84 = 5 * (LOBYTE(v69->field_34) + v69->field_38[14] + v69->field_48[9] + v83);
-//          dword_4FA9B4[v68] += 8 * v84;
-//          if ( BYTE1(v69->field_34) == 99
-//            || v69->field_38[15] == 99
-//            || v69->field_48[10] == 99
-//            || (v85 = v69->field_58[12], v85 == 99) )
-//            v86 = v143->field_38 - v145->field_38;
-//          else
-//            v86 = BYTE1(v69->field_34) + v69->field_38[15] + v69->field_48[10] + v85;
-//          dword_4FA9B4[v68] += 2 * v86;
-//          if ( BYTE2(v69->field_34) == 99
-//            || v69->field_48[0] == 99
-//            || v69->field_48[11] == 99
-//            || (v87 = v69->field_58[13], v87 == 99) )
-//            v88 = v143->field_3C - v145->field_3C;
-//          else
-//            v88 = BYTE2(v69->field_34) + v69->field_48[0] + v69->field_48[11] + v87;
-//          dword_4FA9B4[v68] += 2 * v88;
-//          if ( BYTE3(v69->field_34) == 99
-//            || v69->field_48[1] == 99
-//            || v69->field_48[12] == 99
-//            || (v89 = v69->field_58[14], v89 == 99) )
-//            v90 = v143->field_40 - v145->field_40;
-//          else
-//            v90 = BYTE3(v69->field_34) + v69->field_48[1] + v69->field_48[12] + v89;
-//          dword_4FA9B4[v68] += 2 * v90;
-//          if ( v69->field_38[11] == 99 || (v91 = v69->field_58[8], v91 == 99) )
-//            v92 = 10 * (v145->field_24 - v143->field_24);
-//          else
-//            v92 = -10 * (v69->field_38[11] + v91);
-//          dword_4FA9B4[v68] += v92;
-//          if ( v69->field_38[10] == 99 || (v93 = v69->field_58[7], v93 == 99) )
-//            v94 = 3 * (v145->field_28 - v143->field_28);
-//          else
-//            v94 = -3 * (v69->field_38[10] + v93);
-//          dword_4FA9B4[v68] += v94;
-//          v95 = v69->field_38[9];
-//          v140 = v95;
-//          v96 = v69->field_38[3];
-//          dword_4FA9B4[v68] += -7 * (v69->field_58[6] + v95);
-//          v97 = dword_4FA9B4[v68];
-//          if ( v96 == 99 )
-//            goto LABEL_245;
-//          v98 = v69->field_58[0];
-//          if ( v98 == 99 )
-//            break;
-//          v99 = v96 + v98;
-//          v67 = 99;
-//          dword_4FA9B4[v68] = v97 - 5 * v99;
-//LABEL_246:
-//          v101 = v140;
-//          if ( v69->field_38[4] == v67 || (v102 = v69->field_58[1], v102 == v67) )
-//            v103 = 5 * (v145->field_30 - v143->field_30);
-//          else
-//            v103 = -5 * (v69->field_38[4] + v102);
-//          dword_4FA9B4[v68] += v103;
-//          if ( v69->field_38[5] == v67 || (v104 = v69->field_58[2], v104 == v67) )
-//            v105 = 5 * (v145->field_34 - v143->field_34);
-//          else
-//            v105 = -5 * (v69->field_38[5] + v104);
-//          dword_4FA9B4[v68] += v105;
-//          if ( v69->field_38[6] == v67 || (v106 = v69->field_58[3], v106 == v67) )
-//            v107 = v145->field_38 - v143->field_38;
-//          else
-//            v107 = -(v69->field_38[6] + v106);
-//          dword_4FA9B4[v68] += 2 * v107;
-//          if ( v69->field_38[7] == v67 || (v108 = v69->field_58[4], v108 == v67) )
-//            v109 = v145->field_3C - v143->field_3C;
-//          else
-//            v109 = -(v69->field_38[7] + v108);
-//          dword_4FA9B4[v68] += 2 * v109;
-//          if ( v69->field_38[8] == v67 || (v110 = v69->field_58[5], v110 == v67) )
-//          {
-//            v112 = v145;
-//            v111 = v143;
-//            dword_4FA9B4[v68] += 2 * (v145->field_40 - v143->field_40);
-//          }
-//          else
-//          {
-//            v111 = v143;
-//            dword_4FA9B4[v68] += -2 * (v69->field_38[8] + v110);
-//            v112 = v145;
-//          }
-//          if ( LOBYTE(v69->field_30) || v69->field_48[5] )
-//            dword_4FA9B4[v68] *= 10;
-//          if ( LOBYTE(v69->field_24) == 1 )
-//          {
-//            v113 = LOBYTE(v69->field_28);
-//            v114 = v112->field_38;
-//          }
-//          else
-//          {
-//            if ( LOBYTE(v69->field_24) == 2 )
-//            {
-//              v113 = BYTE1(v69->field_28);
-//              v114 = v112->field_3C;
-//            }
-//            else
-//            {
-//              if ( LOBYTE(v69->field_24) != 3 )
-//                goto LABEL_278;
-//              v113 = BYTE2(v69->field_28);
-//              v114 = v112->field_40;
-//            }
-//          }
-//          v115 = v114 - v113;
-//          if ( v115 > 3 )
-//            v115 = 3;
-//          dword_4FA9B4[v68] += 5 * v115;
-//LABEL_278:
-//          v116 = v69->field_58[8];
-//          v141 = v111->field_24;
-//          v126 = v69->field_38[11];
-//          if ( v141 <= v116 + v126 )
-//            dword_4FA9B4[v68] += 9999;
-//          v137 = v111->field_28 + v141;
-//          if ( v137 <= v116 + v126 + v69->field_58[6] + v69->field_58[7] + v101 + v69->field_38[10] )
-//            dword_4FA9B4[v68] += 9999;
-//          if ( v69->field_48[15] + (signed int)BYTE1(v69->field_68) + v145->field_24 + v69->field_48[4] + v149 >= dword_4E1884 )
-//            dword_4FA9B4[v68] += 9999;
-//          ++v133;
-//          if ( v133 >= v136 )
-//          {
-//            v64 = v130;
-//            goto LABEL_286;
-//          }
-//        }
-//        v67 = 99;
-//LABEL_245:
-//        v100 = v145->field_2C - v143->field_2C;
-//        dword_4FA9B4[v68] = v97 + 4 * v100 + v100;
-//        goto LABEL_246;
-//      }
-//LABEL_286:
-//      v117 = v136 - 1;
-//      for ( j = v136 - 1; j >= 0; --j )
-//      {
-//        v137 = 0;
-//        if ( j > 0 )
-//        {
-//          v119 = (int)dword_4FA9B0;
-//          v134 = j;
-//          v137 = j;
-//          do
-//          {
-//            if ( *(unsigned int *)(v119 + 4) < *(unsigned int *)(v119 + 12) )
-//            {
-//              v120 = *(unsigned int *)v119;
-//              v121 = *(unsigned int *)(v119 + 4);
-//              *(unsigned int *)v119 = *(unsigned int *)(v119 + 8);
-//              v122 = *(unsigned int *)(v119 + 12);
-//              *(unsigned int *)(v119 + 8) = v120;
-//              *(unsigned int *)(v119 + 4) = v122;
-//              v64 = v130;
-//              *(unsigned int *)(v119 + 12) = v121;
-//            }
-//            v119 += 8;
-//            --v134;
-//          }
-//          while ( v134 );
-//        }
-//      }
-//      v123 = v136 - 1;
-//      if ( am_byte_4FAA77 )
-//      {
-//        if ( v117 >= 0 )
-//        {
-//          while ( !BYTE3(pCards[stru_505708[0].cards_at_hand[47 * v64 + dword_4FA9B0[2 * v123]]].field_28) )
-//          {
-//            --v123;
-//            if ( v123 < 0 )
-//              return am_40BCFB(v64, v137) != 0;
-//          }
-//          v137 = dword_4FA9B0[2 * v123];
-//        }
-//      }
-//      else
-//      {
-//        v124 = 0;
-//        if ( v117 >= 0 )
-//        {
-//          while ( !BYTE3(pCards[stru_505708[0].cards_at_hand[47 * v64 + dword_4FA9B0[2 * v123]]].field_28) )
-//          {
-//            --v123;
-//            if ( v123 < 0 )
-//              goto LABEL_299;
-//          }
-//          v137 = dword_4FA9B0[2 * v123];
-//        }
-//LABEL_299:
-//        if ( v136 > 0 )
-//        {
-//          while ( !am_40BF15(v64, dword_4FA9B0[2 * v124]) || dword_4FA9B4[2 * v124] < 0 )
-//          {
-//            ++v124;
-//            if ( v124 >= v136 )
-//              return am_40BCFB(v64, v137) != 0;
-//          }
-//          return am_40BE0E(v64, dword_4FA9B0[2 * v124]) != 0;
-//        }
-//      }
-//      return am_40BCFB(v64, v137) != 0;
-//    }
-//    v9 = a1;
-//    v144 = &stru_505708[a1];
-//    v129 = a1;
-//    v142 = &stru_505708[(a1 + 1) % 2];
-//    v135 = GetPlayerHandCardCount(a1);
-//    v10 = 0;
-//    do
-//    {
-//      if ( v10 >= v135 )
-//      {
-//        dword_4FA9B0[2 * v10] = -1;
-//        dword_4FA9B4[2 * v10] = -9999;
-//      }
-//      else
-//      {
-//        dword_4FA9B0[2 * v10] = v10;
-//        dword_4FA9B4[2 * v10] = 0;
-//      }
-//      ++v10;
-//    }
-//    while ( v10 < 10 );
-//    v131 = 0;
-//    if ( v135 > 0 )
-//    {
-//      v11 = 47 * v9;
-//      for ( k = 47 * v9; ; v11 = k )
-//      {
-//        v12 = 99;
-//        v13 = 2 * v131;
-//        v14 = &pCards[stru_505708[0].cards_at_hand[v11 + dword_4FA9B0[2 * v131]]];
-//        v15 = v14->field_38[2];
-//        v148 = v14->field_38[2];
-//        if ( v144->field_24 >= 10 )
-//        {
-//          if ( v15 == 99 || v14->field_48[4] == 99 || v14->field_48[15] == 99 || (v19 = BYTE1(v14->field_68), v19 == 99) )
-//            v20 = 5 * (v142->field_24 - v144->field_24);
-//          else
-//            v20 = 5 * (v148 + v14->field_48[4] + v14->field_48[15] + v19);
-//          v18 = 2 * v20;
-//        }
-//        else
-//        {
-//          if ( v15 == 99 || v14->field_48[4] == 99 || v14->field_48[15] == 99 || (v16 = BYTE1(v14->field_68), v16 == 99) )
-//            v17 = 5 * (v142->field_24 - v144->field_24);
-//          else
-//            v17 = 5 * (v148 + v14->field_48[4] + v14->field_48[15] + v16);
-//          v18 = 4 * v17;
-//        }
-//        dword_4FA9B4[v13] += v18;
-//        v21 = v14->field_38[1];
-//        v146 = v14->field_38[1];
-//        if ( v144->field_28 >= 10 )
-//        {
-//          if ( v21 == 99
-//            || v14->field_48[3] == 99
-//            || v14->field_48[14] == 99
-//            || (v24 = LOBYTE(v14->field_68), v24 == 99) )
-//            v25 = v142->field_28 - v144->field_28;
-//          else
-//            v25 = v146 + v14->field_48[3] + v14->field_48[14] + v24;
-//          v23 = 2 * v25;
-//        }
-//        else
-//        {
-//          if ( v21 == 99
-//            || v14->field_48[3] == 99
-//            || v14->field_48[14] == 99
-//            || (v22 = LOBYTE(v14->field_68), v22 == 99) )
-//            v23 = 5 * (v142->field_28 - v144->field_28);
-//          else
-//            v23 = 5 * (v146 + v14->field_48[3] + v14->field_48[14] + v22);
-//        }
-//        dword_4FA9B4[v13] += v23;
-//        dword_4FA9B4[v13] += 7 * (v14->field_38[0] + v14->field_48[2] + v14->field_48[13] + v14->field_58[15]);
-//        if ( BYTE2(v14->field_30) == 99
-//          || v14->field_38[12] == 99
-//          || v14->field_48[7] == 99
-//          || (v26 = v14->field_58[9], v26 == 99) )
-//          v27 = 5 * (v142->field_2C - v144->field_2C);
-//        else
-//          v27 = 5 * (BYTE2(v14->field_30) + v14->field_38[12] + v14->field_48[7] + v26);
-//        dword_4FA9B4[v13] += 8 * v27;
-//        if ( BYTE3(v14->field_30) == 99
-//          || v14->field_38[13] == 99
-//          || v14->field_48[8] == 99
-//          || (v28 = v14->field_58[10], v28 == 99) )
-//          v29 = 5 * (v142->field_30 - v144->field_30);
-//        else
-//          v29 = 5 * (BYTE3(v14->field_30) + v14->field_38[13] + v14->field_48[8] + v28);
-//        dword_4FA9B4[v13] += 8 * v29;
-//        if ( LOBYTE(v14->field_34) == 99
-//          || v14->field_38[14] == 99
-//          || v14->field_48[9] == 99
-//          || (v30 = v14->field_58[11], v30 == 99) )
-//          v31 = 5 * (v142->field_34 - v144->field_34);
-//        else
-//          v31 = 5 * (LOBYTE(v14->field_34) + v14->field_38[14] + v14->field_48[9] + v30);
-//        dword_4FA9B4[v13] += 8 * v31;
-//        if ( BYTE1(v14->field_34) == 99
-//          || v14->field_38[15] == 99
-//          || v14->field_48[10] == 99
-//          || (v32 = v14->field_58[12], v32 == 99) )
-//          v33 = v142->field_38 - v144->field_38;
-//        else
-//          v33 = BYTE1(v14->field_34) + v14->field_38[15] + v14->field_48[10] + v32;
-//        dword_4FA9B4[v13] += 2 * v33;
-//        if ( BYTE2(v14->field_34) == 99
-//          || v14->field_48[0] == 99
-//          || v14->field_48[11] == 99
-//          || (v34 = v14->field_58[13], v34 == 99) )
-//          v35 = v142->field_3C - v144->field_3C;
-//        else
-//          v35 = BYTE2(v14->field_34) + v14->field_48[0] + v14->field_48[11] + v34;
-//        dword_4FA9B4[v13] += 2 * v35;
-//        if ( BYTE3(v14->field_34) == 99
-//          || v14->field_48[1] == 99
-//          || v14->field_48[12] == 99
-//          || (v36 = v14->field_58[14], v36 == 99) )
-//          v37 = v142->field_40 - v144->field_40;
-//        else
-//          v37 = BYTE3(v14->field_34) + v14->field_48[1] + v14->field_48[12] + v36;
-//        dword_4FA9B4[v13] += 2 * v37;
-//        if ( v14->field_38[11] == 99 || (v38 = v14->field_58[8], v38 == 99) )
-//          dword_4FA9B4[v13] += v144->field_24 - v142->field_24;
-//        else
-//          dword_4FA9B4[v13] -= v14->field_38[11] + v38;
-//        if ( v14->field_38[10] == 99 || (v39 = v14->field_58[7], v39 == 99) )
-//          dword_4FA9B4[v13] += v144->field_28 - v142->field_28;
-//        else
-//          dword_4FA9B4[v13] -= v14->field_38[10] + v39;
-//        v40 = v14->field_38[9];
-//        v138 = v14->field_38[9];
-//        dword_4FA9B4[v13] -= v40 + v14->field_58[6];
-//        v41 = v14->field_38[3];
-//        v42 = dword_4FA9B4[v13];
-//        if ( v41 == 99 )
-//          goto LABEL_97;
-//        v43 = v14->field_58[0];
-//        if ( v43 == 99 )
-//          break;
-//        v44 = v42 - v43;
-//        v12 = 99;
-//        dword_4FA9B4[v13] = v44 - v41;
-//LABEL_98:
-//        if ( v14->field_38[4] == v12 || (v45 = v14->field_58[1], v45 == v12) )
-//          dword_4FA9B4[v13] += v144->field_30 - v142->field_30;
-//        else
-//          dword_4FA9B4[v13] -= v14->field_38[4] + v45;
-//        if ( v14->field_38[5] == v12 || (v46 = v14->field_58[2], v46 == v12) )
-//          dword_4FA9B4[v13] += v144->field_34 - v142->field_34;
-//        else
-//          dword_4FA9B4[v13] -= v14->field_38[5] + v46;
-//        if ( v14->field_38[6] == v12 || (v47 = v14->field_58[3], v47 == v12) )
-//          dword_4FA9B4[v13] += v144->field_38 - v142->field_38;
-//        else
-//          dword_4FA9B4[v13] -= v14->field_38[6] + v47;
-//        if ( v14->field_38[7] == v12 || (v48 = v14->field_58[4], v48 == v12) )
-//          dword_4FA9B4[v13] += v144->field_3C - v142->field_3C;
-//        else
-//          dword_4FA9B4[v13] -= v14->field_38[7] + v48;
-//        if ( v14->field_38[8] == v12 || (v49 = v14->field_58[5], v49 == v12) )
-//        {
-//          v51 = v144;
-//          v50 = v142;
-//          dword_4FA9B4[v13] += v144->field_40 - v142->field_40;
-//        }
-//        else
-//        {
-//          v50 = v142;
-//          dword_4FA9B4[v13] -= v14->field_38[8] + v49;
-//          v51 = v144;
-//        }
-//        if ( LOBYTE(v14->field_30) || v14->field_48[5] )
-//          dword_4FA9B4[v13] *= 10;
-//        if ( LOBYTE(v14->field_24) == 1 )
-//        {
-//          v52 = LOBYTE(v14->field_28);
-//          v53 = v51->field_38;
-//        }
-//        else
-//        {
-//          if ( LOBYTE(v14->field_24) == 2 )
-//          {
-//            v52 = BYTE1(v14->field_28);
-//            v53 = v51->field_3C;
-//          }
-//          else
-//          {
-//            if ( LOBYTE(v14->field_24) != 3 )
-//              goto LABEL_130;
-//            v52 = BYTE2(v14->field_28);
-//            v53 = v51->field_40;
-//          }
-//        }
-//        v54 = v53 - v52;
-//        if ( v54 > 3 )
-//          v54 = 3;
-//        dword_4FA9B4[v13] += 5 * v54;
-//LABEL_130:
-//        v55 = v14->field_58[8];
-//        v139 = v50->field_24;
-//        v125 = v14->field_38[11];
-//        if ( v139 <= v55 + v125 )
-//          dword_4FA9B4[v13] += 9999;
-//        v137 = v50->field_28 + v139;
-//        if ( v137 <= v55 + v125 + v14->field_58[6] + v14->field_58[7] + v40 + v14->field_38[10] )
-//          dword_4FA9B4[v13] += 9999;
-//        if ( v14->field_48[15] + (signed int)BYTE1(v14->field_68) + v144->field_24 + v14->field_48[4] + v148 >= dword_4E1884 )
-//          dword_4FA9B4[v13] += 9999;
-//        ++v131;
-//        if ( v131 >= v135 )
-//        {
-//          v9 = v129;
-//          goto LABEL_138;
-//        }
-//      }
-//      v12 = 99;
-//LABEL_97:
-//      v40 = v138;
-//      dword_4FA9B4[v13] = v42 + v144->field_2C - v142->field_2C;
-//      goto LABEL_98;
-//    }
-//LABEL_138:
-//    v56 = v135 - 1;
-//    for ( l = v135 - 1; l >= 0; --l )
-//    {
-//      v137 = 0;
-//      if ( l > 0 )
-//      {
-//        v58 = (int)dword_4FA9B0;
-//        v132 = l;
-//        v137 = l;
-//        do
-//        {
-//          if ( *(unsigned int *)(v58 + 4) < *(unsigned int *)(v58 + 12) )
-//          {
-//            v59 = *(unsigned int *)v58;
-//            v60 = *(unsigned int *)(v58 + 4);
-//            *(unsigned int *)v58 = *(unsigned int *)(v58 + 8);
-//            v61 = *(unsigned int *)(v58 + 12);
-//            *(unsigned int *)(v58 + 8) = v59;
-//            *(unsigned int *)(v58 + 4) = v61;
-//            v9 = v129;
-//            *(unsigned int *)(v58 + 12) = v60;
-//          }
-//          v58 += 8;
-//          --v132;
-//        }
-//        while ( v132 );
-//      }
-//    }
-//    v62 = v135 - 1;
-//    if ( am_byte_4FAA77 )
-//    {
-//      if ( v56 >= 0 )
-//      {
-//        while ( !BYTE3(pCards[stru_505708[0].cards_at_hand[47 * v9 + dword_4FA9B0[2 * v62]]].field_28) )
-//        {
-//          --v62;
-//          if ( v62 < 0 )
-//            return am_40BCFB(v9, v137) != 0;
-//        }
-//        v137 = dword_4FA9B0[2 * v62];
-//      }
-//    }
-//    else
-//    {
-//      v63 = 0;
-//      if ( v56 >= 0 )
-//      {
-//        while ( !BYTE3(pCards[stru_505708[0].cards_at_hand[47 * v9 + dword_4FA9B0[2 * v62]]].field_28) )
-//        {
-//          --v62;
-//          if ( v62 < 0 )
-//            goto LABEL_151;
-//        }
-//        v137 = dword_4FA9B0[2 * v62];
-//      }
-//LABEL_151:
-//      if ( v135 > 0 )
-//      {
-//        while ( !am_40BF15(v9, dword_4FA9B0[2 * v63]) || dword_4FA9B4[2 * v63] < 0 )
-//        {
-//          ++v63;
-//          if ( v63 >= v135 )
-//            return am_40BCFB(v9, v137) != 0;
-//        }
-//        return am_40BE0E(v9, dword_4FA9B0[2 * v63]) != 0;
-//      }
-//    }
-//    return am_40BCFB(v9, v137) != 0;
-//  }
-//  v3 = 0;
-//  v4 = a1;
-//  if ( am_byte_4FAA77 )
-//  {
-//LABEL_11:
-//    v7 = GetPlayerHandCardCount(v4);
-//    v8 = rand_interval(0, v7 - 1);
-//    result = am_40BCFB(v4, v8);
-//  }
-//  else
-//  {
-//    while ( 1 )
-//    {
-//      v5 = GetPlayerHandCardCount(v4);
-//      v6 = rand_interval(0, v5 - 1);
-//      if ( am_40BF15(v4, v6) )
-//        break;
-//      ++v3;
-//      if ( v3 >= 10 )
-//        goto LABEL_11;
-//    }
-//    result = am_40BE0E(v4, v6);
-//  }
+
+    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)
+        {
+        if ( hand_full==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 ))
+        {
+        v8 = player_num;
+        
+        v124 = player_num;
+        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 )
+                {
+                stru_4FA9B0[i].slot_index = -1;
+                stru_4FA9B0[i].card_power = -9999;
+                }
+            else
+                {
+                stru_4FA9B0[i].slot_index = i;
+                stru_4FA9B0[i].card_power = 0;
+                }
+            }
+        for(int i = 0; i< all_player_cards_count ; ++i )
+            {   
+               v12 = &pCards[am_Players[player_num].cards_at_hand[stru_4FA9B0[i].slot_index]];          
+               stru_4FA9B0[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 ( stru_4FA9B0[m].card_power < stru_4FA9B0[m+1].card_power )
+                            {
+                            v56 = stru_4FA9B0[m].slot_index;
+                            v57 = stru_4FA9B0[m].card_power;
+                            stru_4FA9B0[m].slot_index = stru_4FA9B0[m+1].slot_index;
+                            stru_4FA9B0[m].card_power = stru_4FA9B0[m+1].card_power;
+                            stru_4FA9B0[m+1].slot_index = v56;
+                            stru_4FA9B0[m+1].card_power = v57;
+                            }
+                        }
+                }                           
+            v59 = all_player_cards_count - 1;
+            if ( hand_full )
+                {
+                if ( all_player_cards_count - 1 >= 0 )
+                    {
+                    while ( !pCards[am_Players[player_num].cards_at_hand[stru_4FA9B0[v59].slot_index]].attack_or_defence )
+                        {
+                        --v59;
+                        if ( v59 < 0 )
+                            return DiscardCard(player_num, v132);
+                        }
+                    v132 = stru_4FA9B0[v59].slot_index;
+                    }
+                }
+            else
+                {
+                v60 = 0;
+                if ( all_player_cards_count - 1 >= 0 )
+                    {
+                    while ( !pCards[am_Players[player_num].cards_at_hand[stru_4FA9B0[v59].slot_index]].attack_or_defence )
+                        {
+                        --v59;
+                        if ( v59 < 0 )
+                            goto LABEL_150;
+                        }
+                    v132 = stru_4FA9B0[v59].slot_index;
+                    }
+LABEL_150:
+                if ( v130 > 0 )
+                    {
+                    while ( !CanCardBePlayed(player_num, stru_4FA9B0[v60].slot_index) || stru_4FA9B0[v60].card_power < 0 )
+                        {
+                        ++v60;
+                        if ( v60 >= v130 )
+                            return DiscardCard(player_num, v132);
+                        }
+                    return PlayCard(v8, stru_4FA9B0[v60].slot_index);
+                    }
+                }
+            return DiscardCard(player_num, v132);
+        }
+   
+
   return true;//result != 0;
 }
-// 408BB4: could not find valid save-restore pair for ebp
-// 4DF3A4: using guessed type int dword_4DF3A4;
-// 4E1884: using guessed type int dword_4E1884;
-// 4FA9B0: using guessed type int dword_4FA9B0[];
-// 4FA9B4: using guessed type int dword_4FA9B4[];
-// 4FAA00: using guessed type char byte_4FAA00;
-// 4FAA77: using guessed type char am_byte_4FAA77;
 
 
 
@@ -1569,7 +1250,7 @@
       GetNextCardFromDeck(current_player_num);
       while ( 1 )
       {
-        byte_4FAA24 = am_40A560(current_player_num);
+        byte_4FAA24 = PlayerTurn(current_player_num);
         if ( GetPlayerHandCardCount(current_player_num) <= minimum_cards_at_hand )
           break;
         hand_full = 1;
@@ -1580,7 +1261,7 @@
     }
     pArcomageGame->GameOver = IsGameOver();
     if ( !pArcomageGame->GameOver )
-      am_40A383();
+      TurnChange();
     if ( pArcomageGame->field_F4 )
       pArcomageGame->GameOver = 1;
   }
@@ -1658,13 +1339,13 @@
       am_Players[i].cards_at_hand[j] = -1;
       if ( am_byte_4E185D )
       {
-        am_Players[i].arr_6C[j].field_0 = -1;
-        am_Players[i].arr_6C[j].field_4 = -1;
+        am_Players[i].card_shift[j].x = -1;
+        am_Players[i].card_shift[j].y = -1;
       }
       else
       {
-      am_Players[i].arr_6C[j].field_0 = 0;
-      am_Players[i].arr_6C[j].field_4 = 0;
+      am_Players[i].card_shift[j].x = 0;
+      am_Players[i].card_shift[j].y = 0;
       }
     }
    
@@ -1802,8 +1483,8 @@
   {
     amuint_4FAA4C = card_slot_indx;
     am_Players[player_num].cards_at_hand[card_slot_indx] = new_card_id;
-    am_Players[player_num].arr_6C[card_slot_indx].field_0 = rand_interval(-4, 4);
-    am_Players[player_num].arr_6C[card_slot_indx].field_4 = rand_interval(-4, 4);
+    am_Players[player_num].card_shift[card_slot_indx].x = rand_interval(-4, 4);
+    am_Players[player_num].card_shift[card_slot_indx].y = rand_interval(-4, 4);
     pArcomageGame->field_F6 = 1;
     byte_4FAA2D = 1;
   }
@@ -1836,8 +1517,8 @@
 
 
 //----- (0040A383) --------------------------------------------------------
-void __cdecl am_40A383()
-{
+void TurnChange()
+    {
   int v0; // eax@4
   int v1; // ecx@4
   unsigned __int8 v2; // sf@4
@@ -1948,8 +1629,8 @@
 
 
 //----- (0040A560) --------------------------------------------------------
-char am_40A560(unsigned int player_num)
-{
+char PlayerTurn( int player_num )
+    {
   int v1; // ebp@0
   unsigned __int64 v2; // qax@3
   unsigned __int64 v3; // kr00_8@3
@@ -2013,7 +1694,7 @@
     {
       if ( am_byte_4FAA75 )
         am_byte_4FAA76 = 1;
-      am_408BB4(current_player_num);
+      OpponentsAITurn(current_player_num);
       byte_4FAA2E = 1;
     }
     if ( amuint_4FAA4C != -1 && amuint_4FAA38 > 10 )
@@ -2054,7 +1735,7 @@
     {
       if ( hand_full )
       {
-        if ( a2.field_0 == 7 && am_40BCFB(player_num, current_card_slot_index) )
+        if ( a2.field_0 == 7 && DiscardCard(player_num, current_card_slot_index) )
         {
           if ( am_byte_4FAA75 )
             am_byte_4FAA76 = 1;
@@ -2065,7 +1746,7 @@
           }
           byte_4FAA2E = 1;
         }
-        if ( a2.field_0 == 8 && am_40BCFB(player_num, current_card_slot_index) )
+        if ( a2.field_0 == 8 && DiscardCard(player_num, current_card_slot_index) )
         {
           if ( am_byte_4FAA75 )
             am_byte_4FAA76 = 1;
@@ -2090,7 +1771,7 @@
         }
         if ( a2.field_0 == 8 )
         {
-          if ( am_40BCFB(player_num, current_card_slot_index) )
+          if ( DiscardCard(player_num, current_card_slot_index) )
           {
             byte_4FAA2E = 1;
             if ( am_byte_4FAA75 )
@@ -2708,8 +2389,8 @@
     if ( am_byte_4E185D)
         {
 
-        pTargetXY.x += am_Players[current_player_num].arr_6C[v2].field_0 ;
-        pTargetXY.y += am_Players[current_player_num].arr_6C[v2].field_4;
+        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 )
@@ -2743,8 +2424,8 @@
 LABEL_15:
     if ( am_byte_4E185D )
         {
-        pTargetXY.x -= am_Players[current_player_num].arr_6C[v2].field_0 ;
-        pTargetXY.y -= am_Players[current_player_num].arr_6C[v2].field_4 ;
+        pTargetXY.x -= am_Players[current_player_num].card_shift[v2].x ;
+        pTargetXY.y -= am_Players[current_player_num].card_shift[v2].y ;
         }
     ++v2;
     }
@@ -2853,8 +2534,8 @@
             {
            // 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].arr_6C[amuint_4FAA4C].field_0-120)/10;
-            v4 = (am_Players[current_player_num].arr_6C[amuint_4FAA4C].field_4+309) /10;//(*(&am_Players[0].arr_6C[0][1] + v3) + 309) / 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
             {
@@ -3140,8 +2821,8 @@
                 if ( am_byte_4E185D )
                     {
                  //   v9 = v3 + 8 * v7;
-                    v10 = am_Players[player_num].arr_6C[v7].field_0;//*(am_player[0].arr_6C[0] + v9);
-                    v11 = am_Players[player_num].arr_6C[v7].field_4;//*(&am_player[0].arr_6C[0][1] + v9);
+                    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;
@@ -3157,8 +2838,8 @@
                 pXYZW.right += var18;
                 if ( am_byte_4E185D )
                     {
-                    v16 = am_Players[player_num].arr_6C[v30].field_0;//*(am_player[0].arr_6C[0] + v15);
-                    v17 = am_Players[player_num].arr_6C[v30].field_4;//*(&am_player[0].arr_6C[0][1] + v15);
+                    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;
@@ -3193,7 +2874,7 @@
 // 4E185D: using guessed type char am_byte_4E185D;
 
 //----- (0040BCFB) --------------------------------------------------------
-bool am_40BCFB( int player_num, signed int card_slot_index )
+bool DiscardCard( int player_num, signed int card_slot_index )
     {
   int v2; // esi@2
   signed int v3; // edi@2
@@ -3229,9 +2910,9 @@
   {
     ArcomageGame::PlaySound(22);
     v8 = GetPlayerHandCardCount(current_player_num);
-    v10=am_Players[player_num].arr_6C[i].field_0 + (640 - 96 * v8) / (v8 + 1);
+    v10=am_Players[player_num].card_shift[i].x + (640 - 96 * v8) / (v8 + 1);
     amuint_4FAA5C_blt_xy.x = v10;
-    amuint_4FAA5C_blt_xy.y = am_Players[player_num].arr_6C[i].field_4 + 327;//v11;
+    amuint_4FAA5C_blt_xy.y = am_Players[player_num].card_shift[i].y + 327;//v11;
     v12 = 0;
 
     if ( !am_byte_4FAA75 )
@@ -3301,10 +2982,10 @@
   //  v10 = 188 * v8 + 8 * v6;
   //  v11 = v6 + 47 * v3;
     pArcomageGame->field_F6 = 1;
-    v12 =  am_Players[player_num].arr_6C[v6].field_0 + (640 - 96 * v9) / (v9 + 1)+ 96 * v6 +(640 - 96 * v9) / (v9 + 1);
+    v12 =  am_Players[player_num].card_shift[v6].x + (640 - 96 * v9) / (v9 + 1)+ 96 * v6 +(640 - 96 * v9) / (v9 + 1);
   //  v13 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v10) + 327;
     amuint_4FAA5C_blt_xy.x = v12;//v12;
-    amuint_4FAA5C_blt_xy.y = am_Players[player_num].arr_6C[v6].field_4 + 327;//v13;
+    amuint_4FAA5C_blt_xy.y = am_Players[player_num].card_shift[v6].y + 327;//v13;
 
     amuint_4FAA54_blt_xy.x = (272 - v12) / 5;
     amuint_4FAA54_blt_xy.y = -30;
@@ -4396,7 +4077,7 @@
 //----- (00409BE8) --------------------------------------------------------
 void SetStartConditions()
 {
-  ArcomageStartConditions *st_cond; // eax@1
+  const ArcomageStartConditions *st_cond; // eax@1
     
   st_cond = &start_conditions[window_SpeakInHouse->par1C - 108];
   start_tower_height = st_cond->tower_height;
@@ -4411,7 +4092,7 @@
   max_tower_height = st_cond->max_tower;
   max_resources_amount = st_cond->max_resources;
 
-  dword_4DF3A4 = st_cond->field_14;
+  opponent_mastery = st_cond->mastery_lvl;
 
   start_bricks_amount = st_cond->bricks_amount;
   start_gems_amount   = st_cond->gems_amount;
@@ -4423,9 +4104,7 @@
 //----- (0040D75D) --------------------------------------------------------
 void pPrimaryWindow_draws_text( int a1, const char *pText, POINT *pXY )
     {
-    int v4; // qax@1
-    v4 = pFontComic->uFontHeight - 3;
-    pPrimaryWindow->DrawText( pFontComic, pXY->x, pXY->y - (v4 >> 1) + 3, 0, pText, 0, 0, 0);
+    pPrimaryWindow->DrawText( pFontComic, pXY->x, pXY->y - ((pFontComic->uFontHeight - 3) >> 1) + 3, 0, pText, 0, 0, 0);
     }
 
 
--- a/Arcomage.h	Tue Jun 11 18:52:42 2013 +0200
+++ b/Arcomage.h	Wed Jun 12 12:05:39 2013 +0400
@@ -120,7 +120,7 @@
   int resource_gems;
   int resource_beasts;
   int cards_at_hand[10];
-  am_st1 arr_6C[10];
+  POINT card_shift[10];
 };
 #pragma pack(pop)
 
--- a/mm7_data.cpp	Tue Jun 11 18:52:42 2013 +0200
+++ b/mm7_data.cpp	Wed Jun 12 12:05:39 2013 +0400
@@ -892,65 +892,15 @@
 std::array<int, 500> ai_near_actors_distances;
 std::array<unsigned int, 500> ai_near_actors_ids;
 std::array<int, 121> dword_4F8580; // weak
-int dword_4FA9B0[777]; // weak
-int dword_4FA9B4[777]; // weak
-char byte_4FAA00; // weak
-std::array<__int16, 12> am_sounds;
+
+
+
 _UNKNOWN unk_4FAA20; // weak
 char byte_4FAA24; // weak
 HWND dword_4FAA28; // idb
 
 
-char byte_4FAA2E; // weak
-int amuint_4FAA34; // weak
-int amuint_4FAA38; // weak
 
-int amuint_4FAA4C; // weak
-
-
-
-
-int dword_4FAA70; // weak
-char byte_4FAA74; // weak
-char am_byte_4FAA75; // weak
-char am_byte_4FAA76; // weak
-
-
-char am_byte_4FAA7C[777]; // weak
-
-int amuint_4FAA88[777]; // weak
-int amuint_4FAA8C[777]; // weak
-int amuint_4FAA90[777][2];
-
-
-
-int amuint_4FABC4; // weak
-
-char byte_4FABD0[777]; // weak
-char byte_4FABD1[777]; // weak
-_UNKNOWN unk_4FABD4; // weak
-int dword_4FABD8[777]; // weak
-int dword_4FABDC[777]; // weak
-int dword_4FABE0[777]; // weak
-int dword_4FABE4[777]; // weak
-int dword_4FABE8[777]; // weak
-int dword_4FABEC[777]; // weak
-int dword_4FABF0[777]; // weak
-int dword_4FABF4[777]; // weak
-int dword_4FABF8[777]; // weak
-int dword_4FABFC[777]; // weak
-int dword_4FAC00[777]; // weak
-int dword_4FAC04[777]; // weak
-int dword_4FAC08[777]; // weak
-int dword_4FAC0C[777]; // weak
-_UNKNOWN unk_5052C8; // weak
-
-
-
-
-
-char byte_505880; // weak
-char byte_505881; // weak
 
 int dword_505890; // weak
 std::array<unsigned int, 480> pSRZBufferLineOffsets;
--- a/mm7_data.h	Tue Jun 11 18:52:42 2013 +0200
+++ b/mm7_data.h	Wed Jun 12 12:05:39 2013 +0400
@@ -530,58 +530,12 @@
 extern std::array<int, 121> dword_4F8580; // weak
 extern int dword_4FA9B0[]; // weak
 extern int dword_4FA9B4[]; // weak
-extern char byte_4FAA00; // weak
-extern std::array<__int16, 12> am_sounds;
+
 extern _UNKNOWN unk_4FAA20; // weak
 extern char byte_4FAA24; // weak
 extern HWND dword_4FAA28; // idb
 
-extern char byte_4FAA2E; // weak
-extern int amuint_4FAA34; // weak
-extern int amuint_4FAA38; // weak
 
-extern int amuint_4FAA4C; // weak
-
-
-extern int dword_4FAA70; // weak
-extern char byte_4FAA74; // weak
-extern char am_byte_4FAA75; // weak
-extern char am_byte_4FAA76; // weak
-
-
-extern char am_byte_4FAA7C[777]; // weak
-
-extern int amuint_4FAA88[777]; // weak
-extern int amuint_4FAA8C[777]; // weak
-extern int amuint_4FAA90[777][2];
-
-
-
-extern int amuint_4FABC4; // weak
-
-extern char byte_4FABD0[]; // weak
-extern char byte_4FABD1[]; // weak
-extern _UNKNOWN unk_4FABD4; // weak
-extern int dword_4FABD8[]; // weak
-extern int dword_4FABDC[]; // weak
-extern int dword_4FABE0[]; // weak
-extern int dword_4FABE4[]; // weak
-extern int dword_4FABE8[]; // weak
-extern int dword_4FABEC[]; // weak
-extern int dword_4FABF0[]; // weak
-extern int dword_4FABF4[]; // weak
-extern int dword_4FABF8[]; // weak
-extern int dword_4FABFC[]; // weak
-extern int dword_4FAC00[]; // weak
-extern int dword_4FAC04[]; // weak
-extern int dword_4FAC08[]; // weak
-extern int dword_4FAC0C[]; // weak
-extern _UNKNOWN unk_5052C8; // weak
-
-extern char byte_5054C8[32]; // idb
-
-extern char byte_505880; // weak
-extern char byte_505881; // weak
 
 extern int dword_505890; // weak
 extern std::array<unsigned int, 480> pSRZBufferLineOffsets;