changeset 1452:9add223260ce

Слияние
author Ritor1
date Tue, 06 Aug 2013 09:26:17 +0600
parents 6b1c8c41c83f (current diff) 27b7ee003c7c (diff)
children dfc9484ed94c
files UI/UICharacter.cpp mm7_data.h
diffstat 16 files changed, 711 insertions(+), 920 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/Actor.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -2322,7 +2322,7 @@
       v8 = 30;
     if ( !pParty->bTurnBasedModeOn )
       pPlayer->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v8 * 2.133333333333333));
-    pTurnEngine->_40471C();
+    pTurnEngine->ApplyPlayerAction();
     result = 1;
   }
   return result;
@@ -4156,7 +4156,7 @@
 	
 	if (pParty->bTurnBasedModeOn)
 	{
-		pTurnEngine->_405E14();
+		pTurnEngine->AITurnBasedAction();
 		return;
 	}
 	
--- a/Awards.h	Tue Aug 06 09:26:06 2013 +0600
+++ b/Awards.h	Tue Aug 06 09:26:17 2013 +0600
@@ -124,4 +124,4 @@
 };
 extern std::array<AwardType, 1000> achieved_awards;
 extern int       num_achieved_awards;
-extern int       num_achieved_awards_2;
\ No newline at end of file
+extern int       full_num_items_in_book;
\ No newline at end of file
--- a/CastSpellInfo.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/CastSpellInfo.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -430,7 +430,7 @@
         //v649 = pPlayer;
         pParty->pTurnBasedPlayerRecoveryTimes[this[n].uPlayerID] = 100;
         pPlayer->SetRecoveryTime(sRecoveryTime);
-        pTurnEngine->_40471C();
+        pTurnEngine->ApplyPlayerAction();
       }
       ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u); // "Spell failed"
       pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
@@ -4046,7 +4046,7 @@
 			pParty->pTurnBasedPlayerRecoveryTimes[pCastSpell->uPlayerID] = sRecoveryTime;
 			pPlayer->SetRecoveryTime(v645);
 			if ( !some_active_character )
-				pTurnEngine->_40471C();
+				pTurnEngine->ApplyPlayerAction();
 		}
 		else
 		{
--- a/GUIWindow.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/GUIWindow.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -433,9 +433,9 @@
   InitializeBookFonts();
   v1->CreateButton(475, 445, 158, 34, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], 0); // Close
   pCurrentScreen = SCREEN_BOOKS;
-  num_achieved_awards_2 = 0;
-  dword_506528 = 0;
-  dword_50651C = 0;
+  full_num_items_in_book = 0;
+  books_primary_item_per_page = 0;
+  books_page_number = 0;
   num_achieved_awards = 0; 
   switch (v1->par1C)
       {
@@ -511,7 +511,7 @@
                                      pTex_tab_an_7b__zoot_on, 0);
       num_achieved_awards = 0;
       memset(achieved_awards.data(), 0, 4000);
-      for ( i = dword_506528; i < 512; ++i )
+      for ( i = books_primary_item_per_page; i < 512; ++i )
           {
          // v14 = (char *)pQuestTable[i];//(&dword_722F10)[4 * i];
           if ( _449B57_test_bit(pParty->_quest_bits, i) && pQuestTable[i] )
@@ -522,7 +522,7 @@
           }
       v12 = num_achieved_awards;
       num_achieved_awards = 0;
-      num_achieved_awards_2 = v12;
+      full_num_items_in_book = v12;
       }
       break;
 
@@ -566,7 +566,7 @@
                                                     UIMSG_ClickBooksBtn,  7, 0, pGlobalTXT_LocalizationStrings[662], pTexture_50636C, 0); // "Instructors"
 
       num_achieved_awards = 0;
-      for ( i = dword_506528; i < 196; ++i )
+      for ( i = books_primary_item_per_page; i < 196; ++i )
             if ( _506568_autonote_type == pAutonoteTxt[i].eType)//dword_72371C[2 * v10] )
               {
               if ( i )
@@ -652,10 +652,10 @@
       v26.uFrameW = v26.uFrameHeight + 69;
       memset(&achieved_awards, 0, 4000);
       memset(byte_5C6D50.data(), 0, 0x64u);
-      if ( dword_506528 < 29 )
+      if ( books_primary_item_per_page < 29 )
           {
-          v3 = (__int64 *)&pParty->field_3C.field_4F0[2 * dword_506528];
-          for(int i=dword_506528+1;i<dword_506528+31;i++)
+          v3 = (__int64 *)&pParty->field_3C.field_4F0[2 * books_primary_item_per_page];
+          for(int i = books_primary_item_per_page+1; i < books_primary_item_per_page + 31; i++)
               {
               v4 = pStorylineText->StoreLine[i].pText;
               if ( *v3 )
--- a/Game.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/Game.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -479,7 +479,7 @@
 
       if ( pParty->bTurnBasedModeOn == 1 )
       {
-        pTurnEngine->End(1);
+        pTurnEngine->End(true);
         pParty->bTurnBasedModeOn = 0;
       }
       //pHealth = &pParty->pPlayers[0].sHealth;//193C
--- a/Player.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/Player.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -5842,7 +5842,7 @@
                 {
                 pParty->pTurnBasedPlayerRecoveryTimes[player_num-1] = 100;
                 thisb->SetRecoveryTime(100);
-                pTurnEngine->_40471C();
+                pTurnEngine->ApplyPlayerAction();
                 }
             else
                 {
@@ -6138,7 +6138,7 @@
                 {
                 pParty->pTurnBasedPlayerRecoveryTimes[player_num-1] = 100;
                 thisb->SetRecoveryTime(100);
-                pTurnEngine->_40471C();
+                pTurnEngine->ApplyPlayerAction();
                 }
             else
                 {
@@ -6259,7 +6259,7 @@
                 {
                 pParty->pTurnBasedPlayerRecoveryTimes[player_num-1] = 100;
                 thisb->SetRecoveryTime(100);
-                pTurnEngine->_40471C();
+                pTurnEngine->ApplyPlayerAction();
                 }
             else
                 {
@@ -7997,14 +7997,6 @@
       v27->uReputation = 10000;
   }
 }
-// 506568: using guessed type int dword_506568;
-// 507948: using guessed type char bFlashHistoryBook;
-// 507949: using guessed type char bFlashAutonotesBook;
-// 50794A: using guessed type char bFlashQuestBook;
-// 72371C: using guessed type int dword_72371C[];
-// 723E80: using guessed type int dword_723E80_award_related[];
-
-
 
 
 //----- (0044B9C4) --------------------------------------------------------
@@ -8748,7 +8740,7 @@
       //v5 = 604;
       //while ( 1 )
   assert ( a1 > 0 && a1 < 5 );
-      for ( uint i = 1; i < (signed int)&qword_A750D8; ++i )
+      for ( uint i = 1; i < 5; ++i )
       {
         //item_flag = Player_has_item(604, *pPlayers, 0);
         if ( !Player_has_item(604, ::pPlayers[i], 0) )
@@ -8758,7 +8750,7 @@
         if ( !::pPlayers[i]->pEquipment.uArmor )
           return false;
         //result *= 9;
-        if ( *(int *)&::pPlayers[i]->spellbook.pDarkSpellbook.bIsSpellAvailable[4 * 9 + 5] != 604 )
+        if (::pPlayers[i]->pEquippedItems[::pPlayers[i]->pEquipment.uArmor].uItemID != 604 )
           return false;
         //++pPlayers;
         //if ( (signed int)pPlayers >= (signed int)&qword_A750D8 )
@@ -8766,23 +8758,7 @@
       }
       return true;
     }
-    //return false;
-  //}
-  //result = Player_has_item(604u, ::pPlayers[a1], 0);
-  //__debugbreak(); // player.cpp(8764): warning C4700: uninitialized local variable 'v2' used
-  //__debugbreak(); // player.cpp(8764): warning C4700: uninitialized local variable 'v3' used
-  //if ( !result
-  //  || (result = v2->pEquipment.uArmor) == 0
-  //  || (result *= 9, *(int *)&v2->spellbook.pDarkSpellbook.bIsSpellAvailable[4 * result + 5] != v3) )
-  //{
-//LABEL_6:
-    //LOBYTE(result) = 0;
-   // return false;
-  //}
-//LABEL_13:
-  //LOBYTE(result) = 1;
-  //return true;
-//}
+
 //----- (0043EE15) --------------------------------------------------------
 bool __fastcall Player_has_item(unsigned int uItemID, Player *pPlayer, char a3)
 {
--- a/TurnEngine.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/TurnEngine.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -44,7 +44,7 @@
             if ( !pActors[p_id].CanAct() )
                 {
                 --active_actors;
-                pQueue[i].field_4 = 1001;
+                pQueue[i].actor_initiative = 1001;
                 pActors[p_id].uAttributes &= ~0x80;
                 }
             }
@@ -53,7 +53,7 @@
             if ( !pParty->pPlayers[p_id].CanAct() )
                 {
                 --active_actors;
-                pQueue[i].field_4 = 1001;
+                pQueue[i].actor_initiative = 1001;
                 }
             }
         }
@@ -66,8 +66,8 @@
         for(j=i+1; j<uActorQueueSize;++j )
             {  
             v8=&pQueue[j];           
-            if ( v8->field_4 < v7->field_4  || 
-                   ((v8->field_4 == v7->field_4) && 
+            if ( v8->actor_initiative < v7->actor_initiative  || 
+                   ((v8->actor_initiative == v7->actor_initiative) && 
                        (
                           ((PID_TYPE(v8->uPackedID) == OBJECT_Player) && (PID_TYPE(v7->uPackedID) == OBJECT_Actor)) || 
                           ((PID_TYPE(v8->uPackedID) == PID_TYPE(v7->uPackedID)) && (PID_ID(v8->uPackedID) < PID_ID(v7->uPackedID)))      
@@ -96,14 +96,14 @@
     for(i=0; i<uActorQueueSize; ++i)
         {
         if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)
-            pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (signed __int64)((double)pQueue[i].field_4 * 0.46875);
+            pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (signed __int64)((double)pQueue[i].actor_initiative * 0.46875);
         }
 
 
     }
 
 //----- (0040471C) --------------------------------------------------------
-void stru262_TurnBased::_40471C()
+void stru262_TurnBased::ApplyPlayerAction()
     {
     if ( pParty->bTurnBasedModeOn == 1 )
         {
@@ -141,9 +141,9 @@
     dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength;
     dword_50C994 = 0;
 
-    this->field_10 = 100;
-    this->field_0 = 0;
-    this->field_8 = 64;
+    this->turn_initiative = 100;
+    this->turns_count = 0;
+    this->ai_turn_timer = 64;
     this->turn_stage = 1;
     this->uActorQueueSize = 0;
 
@@ -191,7 +191,7 @@
                 {
                 //v33 = pPlayers[(this->pQueue[0].uPackedID >> 3) + 1]->uTimeToRecovery;
                 v16 = (signed int)((double)pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery * 0.46875);
-                this->pQueue[v40b].field_4 = v16;
+                this->pQueue[v40b].actor_initiative = v16;
                 }
             else
                 {   
@@ -203,15 +203,15 @@
             {
             v17 = rand() % 99;
             if ( v17 < 33 )
-                this->pQueue[v40b].field_4 = 1;
+                this->pQueue[v40b].actor_initiative = 1;
             else 
-                this->pQueue[v40b].field_4= (v17 >= 66)? 5 : 3; 
+                this->pQueue[v40b].actor_initiative= (v17 >= 66)? 5 : 3; 
             }
         else 
             {
-            this->pQueue[v40b].field_4 = 666;
+            this->pQueue[v40b].actor_initiative = 666;
             }
-        this->pQueue[v40b].field_4 += 16;
+        this->pQueue[v40b].actor_initiative += 16;
         }
 
     if ( a_players_count > 0 )
@@ -238,7 +238,7 @@
 
         for (i=0; i<a_players_count; ++i)
             {
-            this->pQueue[activ_players[i]].field_4 = i+2;
+            this->pQueue[activ_players[i]].actor_initiative = i+2;
             }
         }
     this->SortTurnQueue();
@@ -274,11 +274,11 @@
         objID = PID_ID(pQueue[i].uPackedID);
         if ( objType == OBJECT_Player )
             {
-            pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)pQueue[i].field_4 * 2.133333333333333);
+            pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)pQueue[i].actor_initiative * 2.133333333333333);
             }
         else if ( objType == OBJECT_Actor )
             {
-             pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)pQueue[i].field_4 * 2.133333333333333);
+             pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)pQueue[i].actor_initiative * 2.133333333333333);
             }
         }
    
@@ -294,7 +294,7 @@
 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A;
 
 //----- (00405E14) --------------------------------------------------------
-void stru262_TurnBased::_405E14()
+void stru262_TurnBased::AITurnBasedAction()
     {
     AIDirection *v6; // esi@21
     int v7; // eax@21
@@ -348,50 +348,51 @@
     
     if ( turn_stage == 1 )
         {
-        if ( field_8 == 64 )
+        if ( ai_turn_timer == 64 )
             {
-            _406A63();
+            ActorAIDoMainAction();
             }
-        else  if ( field_8 > 0 )
+        else  if ( ai_turn_timer > 0 )
                 {
-                _406B9F();
+                ActorAIDoAdditionAction();
                 }
         else
                 {
-                _406AFE();
-                field_10 = 100;
+                ActorAISetLastAction();
+                turn_initiative = 100;
                 }
-        field_8 -= pEventTimer->uTimeElapsed;
+        ai_turn_timer -= pEventTimer->uTimeElapsed;
         }
     else if ( turn_stage == 2 )
         {
-        if ( !(field_18 & TE_FLAG_1) )
+        if ( field_18 == TE_FLAG_1)
             {
-            if ( field_10 == 100 )
+            if ( turn_initiative == 100 )
                 {
                 StartTurn();
-                _40652A();
+                SetAIRecoveryTimes();
+                return;
                 }
-            if ( field_10 > 0 || pQueue[0].field_4 <= 0 )
+            if ( turn_initiative > 0 || pQueue[0].actor_initiative <= 0 )
                 {
                 _4065B0();
-                _40652A();
+                SetAIRecoveryTimes();
                 }
             }
-        else
             NextTurn();
         }
     else if ( turn_stage == 3 )
         {
-        if ( uActionPointsLeft <= 0 || field_18 & TE_FLAG_8 )
+        if ( (uActionPointsLeft > 0) && (field_18 == TE_FLAG_8) )
             {
-            field_18 &= ~TE_FLAG_8;
-            turn_stage = 1;
-            field_8 = 64;
+           _406FA8();
             }
         else
-            {
-            _406FA8();
+            { 
+            field_18 &= ~TE_FLAG_8;
+        turn_stage = 1;
+        ai_turn_timer = 64;
+            
             }
         }
     }
@@ -416,7 +417,7 @@
          if (j==uActorQueueSize )
              {
              pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num);
-             pQueue[uActorQueueSize].field_4 = 100;
+             pQueue[uActorQueueSize].actor_initiative = 100;
              pQueue[uActorQueueSize].uActionLength = 0;
              pQueue[uActorQueueSize].field_C = 0;
              ++uActorQueueSize;
@@ -434,29 +435,29 @@
         if (j==uActorQueueSize )
             {
             pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]);
-            pQueue[uActorQueueSize].field_4 = 1;
+            pQueue[uActorQueueSize].actor_initiative = 1;
             pQueue[uActorQueueSize].uActionLength = 0;
             pQueue[uActorQueueSize].field_C = 0;
             ++uActorQueueSize;
             }
         }
 
-        ++field_0;
-        field_10 = 100;
+    ++turns_count;
+    turn_initiative = 100;
 
-        for(i=0; i<uActorQueueSize; ++i) 
-            {
-            if (pQueue[i].field_4 == 0 )
-                pQueue[i].field_4 = 100;
-            }
+    for(i=0; i<uActorQueueSize; ++i) 
+        {
+        if (pQueue[i].actor_initiative == 0 )
+            pQueue[i].actor_initiative = 100;
+        }
 
-        _4063A1();
-        for(i=0; i<uActorQueueSize; ++i) 
-            {
-            if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].field_4 > 0))
-                break;
-            _40680F(i);
-            }
+    StepTurnQueue();
+    for(i=0; i<uActorQueueSize; ++i) 
+        {
+        if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].actor_initiative > 0))
+            break;
+        _40680F(i);
+        }
     }
 // 4F75D8: using guessed type int ai_arrays_size;
 
@@ -483,7 +484,7 @@
          return;
          }
      pTurnEngine->field_18 &= ~TE_FLAG_2;
-     if ( pQueue[0].field_4 <= 0 )
+     if ( pQueue[0].actor_initiative <= 0 )
          return;
 
      v13 = 0;
@@ -552,14 +553,14 @@
      }
 
  //----- (004063A1) --------------------------------------------------------
- int stru262_TurnBased::_4063A1()
+ int stru262_TurnBased::StepTurnQueue()
      {
      int v9; // dx@12 
      int j;
 
      SortTurnQueue();
      viewparams->bRedrawGameUI = 1;
-     if ( pQueue[0].field_4 )
+     if ( pQueue[0].actor_initiative!=0 )
          {
          if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
              {
@@ -567,33 +568,36 @@
                  {
                  for (j=0; j<uActorQueueSize; ++j )
                      {      
-                     --pQueue[j].field_4;
+                     --pQueue[j].actor_initiative;
                      }
-                 --field_10;
-                 if (field_10 == 0)
+                 --turn_initiative;
+                 if (turn_initiative == 0)
                      return 1;
                  }
-                 while (pQueue[0].field_4 > 0);
+                 while (pQueue[0].actor_initiative != 0);
              }
          else
              {
+             if ( pQueue[0].actor_initiative>0 )
+                 {            
              v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState;
              if (!(v9 == AIState::Dying || v9 == AIState::Dead || 
                    v9 == AIState::Disabled || v9 == AIState::Removed))
                  {
-                 do
+                    do
                      {
                      for (j=0; j<uActorQueueSize; ++j )
                          {      
-                         --pQueue[j].field_4;
-                         if (pQueue[j].field_4 == 1)
+                         --pQueue[j].actor_initiative;
+                         if (pQueue[j].actor_initiative == 0)
                              pQueue[j].uActionLength = 0;
                          }
-                     --field_10;
-                     if (field_10 == 0)
+                     --turn_initiative;
+                     if (turn_initiative == 0)
                          return 1;
                      }
-                     while (pQueue[0].field_4 > 0); 
+                     while (pQueue[0].actor_initiative > 0); 
+                 }
                  }
              }
          }
@@ -613,7 +617,7 @@
     int v9; // ecx@14
     char v10; // zf@15
     int i;
-
+    v6=0;
     if (  PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player)
         {
         v4 = PID_ID(pQueue[a2].uPackedID);
@@ -629,30 +633,30 @@
         v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime;
         }
 
-    pQueue[a2].field_4 = v6;
+    pQueue[a2].actor_initiative = v6;
     SortTurnQueue();
     if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
         uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
     else
         uActiveCharacter = 0;
     viewparams->bRedrawGameUI = 1;
-    if (pQueue[0].field_4 > 0)
+    if (pQueue[0].actor_initiative > 0)
         {
-        while(field_10 > 0)
+        while(turn_initiative > 0)
             {
             for (i=0; i<uActorQueueSize; ++i)
                 {
-                --pQueue[i].field_4;
-                if (pQueue[i].field_4==0)
+                --pQueue[i].actor_initiative;
+                if (pQueue[i].actor_initiative==0)
                     pQueue[i].uActionLength=0;
                 }
-            --field_10;
+            --turn_initiative;
             }
         }
     }
 
 //----- (0040652A) --------------------------------------------------------
-void stru262_TurnBased::_40652A()
+void stru262_TurnBased::SetAIRecoveryTimes()
     {
     int i;
     int monster_ai_state;
@@ -660,7 +664,7 @@
 
     for (i=0; i<uActorQueueSize; ++i )
         {
-        if (pQueue[i].field_4 == 0)
+        if (pQueue[i].actor_initiative == 0)
             {
             if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) 
                 break;
@@ -670,9 +674,9 @@
                 monster_ai_state == AIState::Fleeing || 
                 monster_ai_state == AIState::Fidgeting)
                 {
-                pQueue[i].field_4 = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
+                pQueue[i].actor_initiative = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
                 if (monster->pActorBuffs[7].uExpireTime > 0)
-                    pQueue[i].field_4*=2;
+                    pQueue[i].actor_initiative*=2;
                 }
             }
         }
@@ -684,11 +688,11 @@
     int i;
 
     SortTurnQueue();
-    if (pQueue[0].field_4 <= 0)
+    if (pQueue[0].actor_initiative <= 0)
         {  
         for (i=0; i<uActorQueueSize; ++i )
             {
-            if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)|| (pQueue[i].field_4 > 0) )
+            if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)|| (pQueue[i].actor_initiative > 0) )
                 break;
             if ((pQueue[i].uActionLength<=0) && (PID_TYPE(pQueue[i].uPackedID)==OBJECT_Actor))
                 _40680F(i);
@@ -696,7 +700,7 @@
         }
     else
         {
-        _4063A1();
+        StepTurnQueue();
         if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) 
             uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
         else
@@ -705,11 +709,11 @@
         }
 
     for (i=0; i<uActorQueueSize; ++i )
-        AIRangedAttacks(i);
+        AIAttacks(i);
 }
 
 //----- (00406648) --------------------------------------------------------
-void stru262_TurnBased::AIRangedAttacks( unsigned int queue_index )
+void stru262_TurnBased::AIAttacks( unsigned int queue_index )
     {
     TurnBased_QueueElem *v1; // ecx@1
     int v3; // eax@1
@@ -940,7 +944,7 @@
     }
 
 //----- (00406A63) --------------------------------------------------------
-void stru262_TurnBased::_406A63()
+void stru262_TurnBased::ActorAIDoMainAction()
     {
   
     AIDirection a3; // [sp+8h] [bp-44h]@5
@@ -948,7 +952,7 @@
     unsigned int target_pid; // [sp+40h] [bp-Ch]@5
     int i;
 
-    this->field_8 = 64;
+    this->ai_turn_timer = 64;
     dword_50C994 = 0;
     uActiveCharacter = 0;
     for (i=0; i<uActorQueueSize; ++i )
@@ -965,7 +969,7 @@
 // 50C994: using guessed type int dword_50C994;
 
 //----- (00406AFE) --------------------------------------------------------
-void stru262_TurnBased::_406AFE()
+void stru262_TurnBased::ActorAISetLastAction()
     {
     AIDirection a3; // [sp+4h] [bp-48h]@5
     AIDirection v7; // [sp+20h] [bp-2Ch]@5
@@ -984,12 +988,12 @@
             }
         }   
     turn_stage = 2;
-    field_8 = 100;
+    ai_turn_timer = 100;
 
     }
 
 //----- (00406B9F) --------------------------------------------------------
-void stru262_TurnBased::_406B9F()
+void stru262_TurnBased::ActorAIDoAdditionAction()
     {
     Actor *v6; // ebx@5
     AIDirection a3; // [sp+0h] [bp-50h]@15
@@ -1045,7 +1049,7 @@
     int v8; // eax@7
     AIDirection *v9; // esi@10
     int v10; // eax@10
-    unsigned int v11; // ecx@10
+    int v11; // ecx@10
     unsigned __int8 pHostileType; // al@12
     unsigned __int8 v13; // sf@16
     unsigned __int8 v14; // of@16
@@ -1057,7 +1061,7 @@
     AIDirection a3; // [sp+Ch] [bp-48h]@10
     AIDirection pDir; // [sp+28h] [bp-2Ch]@10
     int v27; // [sp+44h] [bp-10h]@33
-    unsigned int v28; // [sp+48h] [bp-Ch]@10
+    int v28; // [sp+48h] [bp-Ch]@10
     TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7
     unsigned int uActorID; // [sp+50h] [bp-4h]@2
     unsigned int a2a; // [sp+5Ch] [bp+8h]@7
@@ -1070,7 +1074,9 @@
     //uActorID = v3;
     actor = &pActors[uActorID];
     //v5 = v4->uAIState;
-    if ( actor->uAIState == 5 || actor->uAIState == 4 || actor->uAIState == 11 || actor->uAIState == 19 || actor->uAIState == 17 )
+    if ( actor->uAIState == AIState::Dead || actor->uAIState ==  AIState::Dying || 
+         actor->uAIState == AIState::Removed|| actor->uAIState == AIState::Disabled || 
+         actor->uAIState == AIState::Summoned  )
         return 1;
     v6 = &ai_near_actors_targets_pid[uActorID];
     v7 = &pTurnEngine->pQueue[a2];
@@ -1082,116 +1088,96 @@
         actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
     v9 = Actor::GetDirectionInfo(v7->uPackedID, a2a, &a3, 0);
     v10 = actor->uActorRadius;
-    memcpy(&a3, v9, sizeof(a3));
-    memcpy(&pDir, &a3, sizeof(pDir));
+    memcpy(&a3, v9, sizeof(AIDirection));
+    memcpy(&pDir, &a3, sizeof(AIDirection));
     v11 = a3.uDistance - v10;
     v28 = a3.uDistance - v10;
-    if ( ((a3.uDistance - v10) & 0x80000000u) != 0 )
+    if ( v28 < 0 )
         {
         v11 = 0;
         v28 = 0;
         }
     pHostileType = actor->pMonsterInfo.uHostilityType;
-    if ( pHostileType == 1 )
-        {
-        if ( (double)(signed int)v28 >= 307.2 )
-            goto LABEL_21;
-        actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-        goto LABEL_21;
-        }
-    if ( pHostileType == 2 )
-        {
-        v14 = __OFSUB__(v11, 1024);
-        v13 = ((v11 - 1024) & 0x80000000u) != 0;
-        }
-    else
+   
+
+    switch (pHostileType)
         {
-        if ( pHostileType != 3 )
-            goto LABEL_21;
-        v14 = __OFSUB__(v11, 2560);
-        v13 = ((v11 - 2560) & 0x80000000u) != 0;
+    case 1:
+        if ( (double)v28 < 307.2 )
+            actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+        break;
+    case 2:
+        if ( v28 < 1024 )
+            actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+        break;
+    case 3:
+        if ( v28 < 2560 )
+            actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+        break;
         }
-    if ( v13 ^ v14 )
+
+    if ( actor->pActorBuffs[4].uExpireTime > 0 )
         {
-        actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-        }
-LABEL_21:
-    if ( (signed __int64)actor->pActorBuffs[4].uExpireTime > 0 )
-        {
-        if ( (signed int)v11 < 10240 )
+        if (v11 < 10240 )
             {
             Actor::AI_Flee(uActorID, a2a, 0, &pDir);
             v29->field_C = 4;
-            v29->uActionLength = actor->uCurrentActionLength;
-            return 1;
             }
-        Actor::AI_4032B2(uActorID, a2a, 1024, 0);
-        v29->field_C = 2;
+        else
+            {
+             Actor::AI_4032B2(uActorID, a2a, 1024, 0);
+             v29->field_C = 2;
+            }         
+    
         v29->uActionLength = actor->uCurrentActionLength;
         return 1;
         }
-    if ( actor->pMonsterInfo.uHostilityType != 4 )
-        goto LABEL_46;
+
+    if ( actor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long )
+  {     
     if ( !(actor->uAttributes & 0x020000) || actor->pMonsterInfo.uAIType == 1 )
         {
         if ( actor->pMonsterInfo.uAIType == 1 )
             {
             if ( actor->pMonsterInfo.uMovementType == 5 )
-                {
                 Actor::AI_Stand(uActorID, a2a, 32, 0);
-                v29->field_C = 4;
-                v29->uActionLength = actor->uCurrentActionLength;
-                return 1;
-                }
-            Actor::AI_Flee(uActorID, a2a, 32, 0);
+            else
+                Actor::AI_Flee(uActorID, a2a, 32, 0);
             v29->field_C = 4;
             v29->uActionLength = actor->uCurrentActionLength;
             return 1;
             }
         if ( actor->pMonsterInfo.uAIType == 2 )
             {
-            v27 = actor->sCurrentHP;
-            v18 = (double)v27;
-            v19 = (double)(signed int)actor->pMonsterInfo.uHP * 0.2;
-            if ( v19 > v18 && (signed int)v11 < 10240 )
+           
+            if (((double)actor->pMonsterInfo.uHP * 0.2) > (double)actor->sCurrentHP && (v11 < 10240 ) )
                 {
                 if ( actor->pMonsterInfo.uMovementType == 5 )
-                    {
                     Actor::AI_Stand(uActorID, a2a, 32, 0);
-                    v29->field_C = 4;
-                    v29->uActionLength = actor->uCurrentActionLength;
-                    return 1;
-                    }
-                Actor::AI_Flee(uActorID, a2a, 32, 0);
+                else
+                     Actor::AI_Flee(uActorID, a2a, 32, 0);
                 v29->field_C = 4;
                 v29->uActionLength = actor->uCurrentActionLength;
                 return 1;
                 }
-            goto LABEL_39;
             }
         if ( actor->pMonsterInfo.uAIType == 3 )
             {
-            v27 = actor->sCurrentHP;
-            v18 = (double)v27;
-            v19 = (double)(signed int)actor->pMonsterInfo.uHP * 0.1;
-            if ( v19 > v18 && (signed int)v11 < 10240 )
+
+            if ( ((double)actor->pMonsterInfo.uHP * 0.1) > (double)actor->sCurrentHP && (v11 < 10240 ))
                 {
                 if ( actor->pMonsterInfo.uMovementType == 5 )
-                    {
                     Actor::AI_Stand(uActorID, a2a, 32, 0);
-                    v29->field_C = 4;
-                    v29->uActionLength = actor->uCurrentActionLength;
-                    return 1;
-                    }
-                Actor::AI_Flee(uActorID, a2a, 32, 0);
+                else
+                     Actor::AI_Flee(uActorID, a2a, 32, 0);
                 v29->field_C = 4;
                 v29->uActionLength = actor->uCurrentActionLength;
                 return 1;
                 }
-            goto LABEL_39;
+
             }
         }
-LABEL_39:
+
     if ( (double)(signed int)v28 < 307.2 )
         return 0;
     if ( (signed int)v11 < 5120 )
@@ -1204,42 +1190,29 @@
         v29->uActionLength = actor->uCurrentActionLength;
         return 1;
         }
-LABEL_46:
-    if ( actor->pMonsterInfo.uMovementType == 0 )
-        {
-        Actor::AI_4032B2(uActorID, a2a, 1024, 32);
-        v29->field_C = 2;
-        v29->uActionLength = actor->uCurrentActionLength;
-        return 1;
         }
-    if ( actor->pMonsterInfo.uMovementType == 1 )
-        {
-        Actor::AI_4032B2(uActorID, a2a, 2560, 32);
-        v29->field_C = 2;
-        v29->uActionLength = actor->uCurrentActionLength;
-        return 1;
-        }
-    if ( actor->pMonsterInfo.uMovementType == 2 )
+    switch(actor->pMonsterInfo.uMovementType)
         {
-        Actor::AI_4032B2(uActorID, a2a, 5120, 32);
-        v29->field_C = 2;
-        v29->uActionLength = actor->uCurrentActionLength;
-        return 1;
+        case 0: 
+            Actor::AI_4032B2(uActorID, a2a, 1024, 32);
+            break;
+        case 1:
+             Actor::AI_4032B2(uActorID, a2a, 2560, 32);
+             break;
+         case 2:
+             Actor::AI_4032B2(uActorID, a2a, 5120, 32);
+             break;
+         case 4:
+             Actor::AI_4032B2(uActorID, a2a, 10240, 32);
+             break;
+         case 5:
+             Actor::AI_Stand(uActorID, a2a, 32, 0);
+              break;
+         default:
+             return 1;
         }
-    if ( actor->pMonsterInfo.uMovementType == 4 )
-        {
-        Actor::AI_4032B2(uActorID, a2a, 10240, 32);
-        v29->field_C = 2;
-        v29->uActionLength = actor->uCurrentActionLength;
-        return 1;
-        }
-    if ( actor->pMonsterInfo.uMovementType == 5 )
-        {
-        Actor::AI_Stand(uActorID, a2a, 32, 0);
-        v29->field_C = 2;
-        v29->uActionLength = actor->uCurrentActionLength;
-        return 1;
-        }
+    v29->field_C = 2;
+    v29->uActionLength = actor->uCurrentActionLength;
     return 1;
     }
 
--- a/TurnEngine.h	Tue Aug 06 09:26:06 2013 +0600
+++ b/TurnEngine.h	Tue Aug 06 09:26:17 2013 +0600
@@ -17,12 +17,12 @@
   inline TurnBased_QueueElem()
   {
     uPackedID = 0;
-    field_4 = 0;
+    actor_initiative = 0;
     uActionLength = 0;
     field_C = 0;
   }
   int uPackedID;
-  int field_4;
+  int actor_initiative;
   int uActionLength;
   int field_C;
 };
@@ -34,41 +34,41 @@
 {
   inline stru262_TurnBased()
   {
-    field_0 = 0;
+    turns_count = 0;
     turn_stage = 0;
-    field_8 = 0;
+    ai_turn_timer = 0;
     uActorQueueSize = 0;
-    field_10 = 0;
+    turn_initiative = 0;
     uActionPointsLeft = 0;
     field_18 = 0;
     field_1C = 0;
   }
 
   void  SortTurnQueue();
-  void _40471C();
+  void ApplyPlayerAction();
   void  Start();
   void End(bool bPlaySound);
-  void _405E14();
+  void AITurnBasedAction();
   void StartTurn();
   void NextTurn();
-  int _4063A1();
+  int StepTurnQueue();
   void _406457(int a2);
-  void _40652A();
+  void SetAIRecoveryTimes();
   void _4065B0();
-  void AIRangedAttacks(unsigned int queue_index);
+  void AIAttacks(unsigned int queue_index);
   void _40680F(int queue_index);
-  void _406A63();
-  void _406AFE();
-  void  _406B9F();
+  void ActorAIDoMainAction();
+  void ActorAISetLastAction();
+  void  ActorAIDoAdditionAction();
   bool ActorTurn(signed int a2);
   void _406FA8();
 
 
-  int field_0;
+  int turns_count;
   int turn_stage;
-  int field_8;
+  int ai_turn_timer;
   int uActorQueueSize; //c
-  int field_10;
+  int turn_initiative;
   int uActionPointsLeft; //14
   int field_18;
   int field_1C;
--- a/UI/Books/UIMapBook.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/UI/Books/UIMapBook.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -33,30 +33,23 @@
 
 
 
-
-
 //----- (00411150) --------------------------------------------------------
 void BookUI_DrawTownPortalMap()
 {
-  //signed int v0; // edi@1
-  //__int16 v1; // dx@8
-  //POINT *v2; // edi@17
   int v3; // edi@17
-  //__int16 v4; // dx@24
-  GUIWindow v6; // [sp+Ch] [bp-64h]@1
-  //POINT v7; // [sp+60h] [bp-10h]@17
+  GUIWindow TownPortalWindow; // [sp+Ch] [bp-64h]@1
   POINT a2; // [sp+68h] [bp-8h]@17
 
   pRenderer->ClearZBuffer(0, 479);
   pRenderer->DrawTextureTransparent(8, 8, pTexture_CurrentBook);
   pRenderer->DrawTextureTransparent(471, 445, pIcons_LOD->GetTexture(uExitCancelTextureId));
 
-  v6.uFrameX = game_viewport_x;
-  v6.uFrameY = game_viewport_y;
-  v6.uFrameWidth = game_viewport_width;
-  v6.uFrameHeight = game_viewport_height;
-  v6.uFrameZ = game_viewport_z;
-  v6.uFrameW = game_viewport_w;
+  TownPortalWindow.uFrameX = game_viewport_x;
+  TownPortalWindow.uFrameY = game_viewport_y;
+  TownPortalWindow.uFrameWidth = game_viewport_width;
+  TownPortalWindow.uFrameHeight = game_viewport_height;
+  TownPortalWindow.uFrameZ = game_viewport_z;
+  TownPortalWindow.uFrameW = game_viewport_w;
 
   const uint fountain_bits_lut[] = {PARTY_QUEST_FOUNTAIN_HARMONDALE,
                                     PARTY_QUEST_FOUNTAIN_PIERPONT,
@@ -81,7 +74,7 @@
     if (_449B57_test_bit(pParty->_quest_bits, fountain_bits_lut[v3 - 1]))
       pRenderer->DrawTextureIndexed(pTownPortalBook_xs[v3 - 1], pTownPortalBook_ys[v3 - 1], pTexture_TownPortalIcons[v3 - 1]);
   }
-  v6.DrawTitleText(pBook2Font, 0, 22u, 0, pGlobalTXT_LocalizationStrings[10], 3u);
+  TownPortalWindow.DrawTitleText(pBook2Font, 0, 22, 0, pGlobalTXT_LocalizationStrings[10], 3);
 }
 
 //----- (00410DEC) --------------------------------------------------------
@@ -89,28 +82,15 @@
 {
   Player *pPlayer; // esi@1
   char *pText; // eax@1
-  //unsigned __int16 v2; // ax@6
-  //unsigned int result; // eax@11
-  //unsigned int v4; // esi@13
-  //unsigned int v5; // ecx@13
-  //char v6; // zf@13
-  //LloydBeacon *v7; // esi@14
   int pTextHeight; // eax@14
   int RemainingTime; // kr08_8@14
   unsigned int pHours; // esi@14
   unsigned int pDays; // eax@14
   char *pSelectionText; // eax@19
-  //char *v13; // ecx@22
-  //int v14; // eax@27
   Texture *v19; // [sp-4h] [bp-8Ch]@4
   GUIWindow pWindow; // [sp+Ch] [bp-7Ch]@1
-  //unsigned int v23; // [sp+64h] [bp-24h]@14
-  //__int64 v24; // [sp+68h] [bp-20h]@14
-  //unsigned int v25; // [sp+70h] [bp-18h]@13
   char *Str; // [sp+74h] [bp-14h]@14
   int BeaconID; // [sp+78h] [bp-10h]@11
-  //LloydBeacon *v28; // [sp+7Ch] [bp-Ch]@12
-  //RGBTexture *v29; // [sp+80h] [bp-8h]@12
   int uNumMaxBeacons; // [sp+84h] [bp-4h]@6
 
   pPlayer = &pParty->pPlayers[_506348_current_lloyd_playerid];
@@ -125,7 +105,7 @@
   if ( !bRecallingBeacon )
     pText = pGlobalTXT_LocalizationStrings[375];   // Set Beacon
   sprintf(pTmpBuf.data(), "%s", pText);
-  pWindow.DrawTitleText(pBook2Font, 0, 22u, 0, pTmpBuf.data(), 3);
+  pWindow.DrawTitleText(pBook2Font, 0, 22, 0, pTmpBuf.data(), 3);
   if ( bRecallingBeacon )
   {
     pRenderer->DrawTextureTransparent(pBtn_Book_1->uX, pBtn_Book_1->uY, pTex_tab_an_6b__zoom_on);
@@ -337,10 +317,6 @@
 //----- (00442955) --------------------------------------------------------
 void DrawBook_Map_sub( unsigned int tl_x, unsigned int tl_y, unsigned int br_x, int br_y, int _48074 )
 {
-  //unsigned int v11; // edx@11
-  //__int16 v12; // cx@12
-  //signed int v13; // eax@15
-  //int v14; // eax@16
   int v20; // eax@16
   signed int v21; // esi@18
   int v22; // ecx@21
@@ -374,7 +350,6 @@
   signed int v50; // edx@55
   unsigned int v51; // ecx@55
   int result; // eax@72
-  int v53; // eax@75
   int v54; // esi@75
   int v55; // eax@75
   __int16 v56; // si@85
@@ -417,7 +392,6 @@
   unsigned int v88; // [sp+4803Ch] [bp-28h]@16
   int black; // [sp+48040h] [bp-24h]@8
   int screenCenterY; // [sp+48044h] [bp-20h]@1
-  unsigned int i; // [sp+48048h] [bp-1Ch]@9
   unsigned int screenHeight; // [sp+4804Ch] [bp-18h]@16
   unsigned __int16 *v93; // [sp+48050h] [bp-14h]@16
   signed int screenWidth; // [sp+48054h] [bp-10h]@8
@@ -622,134 +596,112 @@
     pRenderer->DrawTransparentRedShade(v47, v49, pIcons_LOD->GetTexture(pTextureIDs_pMapDirs[v50]));
   }
   result = TargetColor(0xFFu, 0xFFu, 0xFFu);
-  v95 = 0;
   pCenterX = result;
   if ( (signed int)uNumLevelDecorations > 0 )
   {
-    screenWidth = (unsigned int)&pLevelDecorations[0].vPosition;
-    do
+    for ( uint i = 0; i < (signed int)uNumLevelDecorations; ++i )
     {
-      if ( *(char *)(screenWidth - 2) & 8 )
+      if ( pLevelDecorations[i].field_2 & 8 )
       {
-        v53 = *(int *)(screenWidth + 4) - pCenterY;
-        v93 = (unsigned __int16 *)(*(int *)screenWidth - viewparams->sViewCenterX);
-              screenHeight = v53;
-              v54 = ((unsigned __int64)((signed int)v93 * (signed __int64)viewparams->field_2C) >> 16) + screenCenter_X;
-              v97 = (const void *)((unsigned __int64)(v53 * (signed __int64)viewparams->field_2C) >> 16);
-              v55 = screenCenterY - (int)v97;
-              if ( v54 >= pRenderer->raster_clip_x )
-              {
-                if ( v54 <= pRenderer->raster_clip_z && v55 >= pRenderer->raster_clip_y && v55 <= pRenderer->raster_clip_w )
-                {
-                  if ( viewparams->field_2C > 512 )
-                  {
-                    v96 = v55 + 1;
-                    black = v55 - 1;
-                    pRenderer->RasterLine2D(v54 - 1, v55 - 1, v54 - 1, v55 + 1, pCenterX);
-                    pRenderer->RasterLine2D(v54, black, v54, v96, pCenterX);
-                    ++v54;
-                    v72 = v96;
-                    v71 = v54;
-                    v70 = black;
-                  }
-                  else
-                  {
-                    v72 = screenCenterY - (int)v97;
-                    v71 = ((unsigned __int64)((signed int)v93 * (signed __int64)viewparams->field_2C) >> 16) + screenCenter_X;
-                    v70 = screenCenterY - (int)v97;
-                  }
-                  pRenderer->RasterLine2D(v54, v70, v71, v72, pCenterX);
-                }
-              }
+        screenHeight = pLevelDecorations[i].vPosition.y - pCenterY;
+        v93 = (unsigned __int16 *)(pLevelDecorations[i].vPosition.x - viewparams->sViewCenterX);
+        v54 = ((unsigned __int64)((signed int)v93 * (signed __int64)viewparams->field_2C) >> 16) + screenCenter_X;
+        v97 = (const void *)((unsigned __int64)(screenHeight * (signed __int64)viewparams->field_2C) >> 16);
+        v55 = screenCenterY - (int)v97;
+        if ( v54 >= pRenderer->raster_clip_x )
+        {
+          if ( v54 <= pRenderer->raster_clip_z && v55 >= pRenderer->raster_clip_y && v55 <= pRenderer->raster_clip_w )
+          {
+            if ( viewparams->field_2C > 512 )
+            {
+              pRenderer->RasterLine2D(v54 - 1, v55 - 1, v54 - 1, v55 + 1, pCenterX);
+              pRenderer->RasterLine2D(v54, v55 - 1, v54, v55 + 1, pCenterX);
+              ++v54;
+              v72 = v55 + 1;
+              v71 = v54;
+              v70 = v55 - 1;
             }
-            ++v95;
-            result = v95;
-            screenWidth += 32;
-            }
-            while ( (signed int)v95 < (signed int)uNumLevelDecorations );
-        }
-    if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-        {
-        screenCenterY = br_x - tl_x + 1;
-        v95 = br_y - tl_y + 1;
-        v77 = &pRenderer->pTargetSurface[tl_x + tl_y * pRenderer->uTargetSurfacePitch];
-        v56 = pIcons_LOD->pTextures[viewparams->uTextureID_LocationMap].uWidthLn2;
-        black = (1 << (v56 + 16)) / viewparams->field_2C;
-        v57 = (double)(1 << (16 - v56));
-        v58 = 22528 / (viewparams->field_2C / 384);
-        v59 = (signed __int64)((double)(viewparams->sViewCenterX - v58 + 32768) / v57);
-        v60 = (int)v59 << 16;
-        v97 = (const void *)((int)v59 << 16);
-        v61 = (signed __int64)((double)(32768 - v58 - pCenterY) / v57);
-        pPalette_16 = (unsigned __int16 *)(v60 >> 16);
-        v62 = (int)v61 << 16;
-        teal = v60 >> 16;
-        v63 = (signed __int16)v61;
-        a4a = map_texture_16;
-        result = TargetColor(0xCu, 0xCu, 0xCu);
-        screenCenter_X = 0;
-        for ( i = result; screenCenter_X < (signed int)v95; result = screenCenter_X )
+            else
             {
-            a5a = 0;
-            if ( screenCenterY > 0 )
-                {
-                v96 = (v63 - 80) / 4;
-                v64 = teal;
-                do
-                    {
-                    v81 = (v64 - 80) / 4;
-                    if ( !pOutdoor->_47F04C(v81, v96) )
-                        {
-                        if ( pOutdoor->_47F097(v81, v96) )
-                            {
-                            if ( !((a5a + screenCenter_X) % 2) )
-                                *a4a = i;
-                            }
-                        else
-                            {
-                            *a4a = 0;
-                            }
-                        }
-                    ++a4a;
-                    v97 = (char *)v97 + black;
-                    v64 = (signed int)v97 >> 16;
-                    ++a5a;
-                    }
-                    while ( a5a < screenCenterY );
-                }
-            v62 += black;
-            v97 = (const void *)v60;
-            a4a += screenCenterY - a5a;
-            v63 = v62 >> 16;
-            ++screenCenter_X;
-            teal = (unsigned int)pPalette_16;
+              v72 = screenCenterY - (int)v97;
+              v71 = ((unsigned __int64)((signed int)v93 * (signed __int64)viewparams->field_2C) >> 16) + screenCenter_X;
+              v70 = screenCenterY - (int)v97;
             }
-        v65 = v95;
-        v66 = map_texture_16;
-        if ( (signed int)v95 > 0 )
+            pRenderer->RasterLine2D(v54, v70, v71, v72, pCenterX);
+          }
+        }
+      }
+    }
+  }
+  if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+  {
+    screenCenterY = br_x - tl_x + 1;
+    v95 = br_y - tl_y + 1;
+    v77 = &pRenderer->pTargetSurface[tl_x + tl_y * pRenderer->uTargetSurfacePitch];
+    v56 = pIcons_LOD->pTextures[viewparams->uTextureID_LocationMap].uWidthLn2;
+    black = (1 << (v56 + 16)) / viewparams->field_2C;
+    v57 = (double)(1 << (16 - v56));
+    v58 = 22528 / (viewparams->field_2C / 384);
+    v59 = (signed __int64)((double)(viewparams->sViewCenterX - v58 + 32768) / v57);
+    v60 = (int)v59 << 16;
+    v97 = (const void *)((int)v59 << 16);
+    v61 = (signed __int64)((double)(32768 - v58 - pCenterY) / v57);
+    pPalette_16 = (unsigned __int16 *)(v60 >> 16);
+    v62 = (int)v61 << 16;
+    teal = v60 >> 16;
+    v63 = (signed __int16)v61;
+    a4a = map_texture_16;
+    result = TargetColor(0xCu, 0xCu, 0xCu);
+    for ( screenCenter_X = 0; screenCenter_X < (signed int)v95; ++screenCenter_X )
+    {
+      if ( screenCenterY > 0 )
+      {
+        v96 = (v63 - 80) / 4;
+        v64 = teal;
+        for ( a5a = 0; a5a < screenCenterY; ++a5a )
+        {
+          v81 = (v64 - 80) / 4;
+          if ( !pOutdoor->_47F04C(v81, v96) )
+          {
+            if ( pOutdoor->_47F097(v81, v96) )
             {
-            v67 = v77;
-            result = 2 * (pRenderer->uTargetSurfacePitch - screenCenterY);
-            do
-                {
-                if ( screenCenterY > 0 )
-                    {
-                    v68 = screenCenterY;
-                    do
-                        {
-                        v69 = *(short *)v66;
-                        if ( !*(short *)v66 || v69 == (short)i )
-                            *v67 = v69;
-                        ++v66;
-                        ++v67;
-                        --v68;
-                        }
-                        while ( v68 );
-                    }
-                v67 = (unsigned __int16 *)((char *)v67 + result);
-                --v65;
-                }
-                while ( v65 );
+              if ( !((a5a + screenCenter_X) % 2) )
+                *a4a = result;
             }
+            else
+              *a4a = 0;
+          }
+          ++a4a;
+          v97 = (char *)v97 + black;
+          v64 = (signed int)v97 >> 16;
         }
+      }
+      v62 += black;
+      v97 = (const void *)v60;
+      a4a += screenCenterY - a5a;
+      v63 = v62 >> 16;
+      teal = (unsigned int)pPalette_16;
     }
+    v66 = map_texture_16;
+    if ( (signed int)v95 > 0 )
+    {
+      v67 = v77;
+      result = 2 * (pRenderer->uTargetSurfacePitch - screenCenterY);
+      for ( v65 = v95; v65; --v65 )
+      {
+        if ( screenCenterY > 0 )
+        {
+          for ( v68 = screenCenterY; v68; --v68 )
+          {
+            v69 = *(short *)v66;
+            if ( !*(short *)v66 || v69 == (short)result )
+              *v67 = v69;
+            ++v66;
+            ++v67;
+          }
+        }
+        v67 = (unsigned __int16 *)((char *)v67 + result);
+      }
+    }
+  }
+}
--- a/UI/Books/UINotesBooks.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/UI/Books/UINotesBooks.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -42,506 +42,395 @@
         return pGlobalTXT_LocalizationStrings[56]; // "Day"
     }
 
-
-
-
-
 //----- (00413D6F) --------------------------------------------------------
 void BookUI_Calendar_Draw()
-    {
-    unsigned int v0; // esi@1
-    //char *v1; // eax@5
-    int v2; // ecx@5
-    char *v3; // eax@6
-    GUIWindow a1; // [sp+Ch] [bp-60h]@5
-    unsigned int v6; // [sp+60h] [bp-Ch]@1
-    //int v7; // [sp+64h] [bp-8h]@1
-    //int a5; // [sp+68h] [bp-4h]@1
-
+{
+  int am; // ecx@5
+  char *pMapName; // eax@6
+  GUIWindow calendar_window; // [sp+Ch] [bp-60h]@5
+  unsigned int pMapID; // [sp+60h] [bp-Ch]@1
+  unsigned int pHour;
 
-    static unsigned int pDayMoonPhase[28] = // 4E1B18
-        {
-        0, 0, 0,
-        1, 1, 1, 1,
-        2, 2, 2,
-        3, 3, 3, 3,
-        4, 4, 4,
-        3, 3, 3, 3,
-        2, 2, 2,
-        1, 1, 1, 1
-        };
-
+  static unsigned int pDayMoonPhase[28] = // 4E1B18
+  {
+    0, 0, 0,
+    1, 1, 1, 1,
+    2, 2, 2,
+    3, 3, 3, 3,
+    4, 4, 4,
+    3, 3, 3, 3,
+    2, 2, 2,
+    1, 1, 1, 1
+  };
 
-    v0 = pParty->uCurrentHour;
-    pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pSpellBookPagesTextr_13);
-    if ( (signed int)v0 <= 12 )
-        {
-        if ( !v0 )
-            v0 = 12;
-        }
-    else
-        {
-        v0 -= 12;
-        }
-    a1.uFrameX = game_viewport_x;
-    a1.uFrameY = game_viewport_y;
-    a1.uFrameWidth = game_viewport_width;
-    a1.uFrameHeight = game_viewport_height;
-    a1.uFrameZ = game_viewport_z;
-    a1.uFrameW = game_viewport_w;
-    a1.DrawTitleText(pBook2Font, 0, 0x16u, ui_book_calendar_title_color, pGlobalTXT_LocalizationStrings[186], 3); // "Time in Erathia"
+  pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pSpellBookPagesTextr_13);
+  pHour = pParty->uCurrentHour;
+  if ( (signed int)pHour >= 12 )
+  {
+    pHour -= 12;
+    if ( !pHour )
+      pHour = 12;
+    am = 1;
+  }
+  else
+    am = 0;
 
-    v2 = 0;
-    if ( pParty->uCurrentHour >= 12 )
-        {
-        if ( pParty->uCurrentHour >= 24 )
-            v2=0;
-        else
-            v2=1;
-        }
+  calendar_window.uFrameX = game_viewport_x;
+  calendar_window.uFrameY = game_viewport_y;
+  calendar_window.uFrameWidth = game_viewport_width;
+  calendar_window.uFrameHeight = game_viewport_height;
+  calendar_window.uFrameZ = game_viewport_z;
+  calendar_window.uFrameW = game_viewport_w;
+  calendar_window.DrawTitleText(pBook2Font, 0, 22, ui_book_calendar_title_color, pGlobalTXT_LocalizationStrings[186], 3); // "Time in Erathia"
 
-    sprintf(pTmpBuf.data(), "%s\t100:\t110%d:%02d %s - %s",
-        pGlobalTXT_LocalizationStrings[526], // "Time"
-        v0,
-        pParty->uCurrentMinute,
-        aAMPMNames[v2],
-        GetDayPart());
-    a1.DrawText(pBookFont, 70, 55, ui_book_calendar_time_color, pTmpBuf.data(), 0, 0, 0);
+  sprintf(pTmpBuf.data(), "%s\t100:\t110%d:%02d %s - %s", pGlobalTXT_LocalizationStrings[526], // "Time"
+     pHour, pParty->uCurrentMinute, aAMPMNames[am], GetDayPart());
+  calendar_window.DrawText(pBookFont, 70, 55, ui_book_calendar_time_color, pTmpBuf.data(), 0, 0, 0);
 
-    sprintf(pTmpBuf.data(), "%s\t100:\t110%d - %s",
-        pGlobalTXT_LocalizationStrings[56], // "Day"
-        pParty->uDaysPlayed + 1,
-        aDayNames[pParty->uDaysPlayed % 7]);
-    a1.DrawText(pBookFont, 70, 2 * LOBYTE(pBookFont->uFontHeight) + 49, ui_book_calendar_day_color, pTmpBuf.data(), 0, 0, 0);
+  sprintf(pTmpBuf.data(), "%s\t100:\t110%d - %s", pGlobalTXT_LocalizationStrings[56], // "Day"
+     pParty->uDaysPlayed + 1, aDayNames[pParty->uDaysPlayed % 7]);
+  calendar_window.DrawText(pBookFont, 70, 2 * LOBYTE(pBookFont->uFontHeight) + 49, ui_book_calendar_day_color, pTmpBuf.data(), 0, 0, 0);
 
-    sprintf(pTmpBuf.data(), "%s\t100:\t110%d - %s",
-        pGlobalTXT_LocalizationStrings[146], // "Month"
-        pParty->uCurrentMonth + 1,
-        aMonthNames[pParty->uCurrentMonth]);
-    a1.DrawText(pBookFont, 70, 4 * LOBYTE(pBookFont->uFontHeight) + 43, ui_book_calendar_month_color, pTmpBuf.data(), 0, 0, 0);
+  sprintf(pTmpBuf.data(), "%s\t100:\t110%d - %s", pGlobalTXT_LocalizationStrings[146], // "Month"
+        pParty->uCurrentMonth + 1, aMonthNames[pParty->uCurrentMonth]);
+  calendar_window.DrawText(pBookFont, 70, 4 * LOBYTE(pBookFont->uFontHeight) + 43, ui_book_calendar_month_color, pTmpBuf.data(), 0, 0, 0);
 
-    sprintf(pTmpBuf.data(), "%s\t100:\t110%d", pGlobalTXT_LocalizationStrings[245], pParty->uCurrentYear); // "Year"
-    a1.DrawText(pBookFont, 70, 6 * LOBYTE(pBookFont->uFontHeight) + 37, ui_book_calendar_year_color, pTmpBuf.data(), 0, 0, 0);
-
-    sprintf(pTmpBuf.data(), "%s\t100:\t110%s", pGlobalTXT_LocalizationStrings[530], aMoonPhaseNames[pDayMoonPhase[pParty->uDaysPlayed]]); // "Moon"
-    a1.DrawText(pBookFont, 70, 8 * LOBYTE(pBookFont->uFontHeight) + 31, ui_book_calendar_moon_color, pTmpBuf.data(), 0, 0, 0);
+  sprintf(pTmpBuf.data(), "%s\t100:\t110%d", pGlobalTXT_LocalizationStrings[245], pParty->uCurrentYear); // "Year"
+  calendar_window.DrawText(pBookFont, 70, 6 * LOBYTE(pBookFont->uFontHeight) + 37, ui_book_calendar_year_color, pTmpBuf.data(), 0, 0, 0);
 
-    v6 = pMapStats->GetMapInfo(pCurrentMapName.data());
-    if ( v6 )
-        v3 = pMapStats->pInfos[v6].pName;
-    else
-        v3 = "Unknown";
-    sprintf(pTmpBuf.data(), "%s\t100:\t110%s", pGlobalTXT_LocalizationStrings[531], v3); // "Location"
-    a1.DrawText(pBookFont, 70, 10 * LOBYTE(pBookFont->uFontHeight) + 25, ui_book_calendar_location_color, pTmpBuf.data(), 0, 0, 0);
-    }
+  sprintf(pTmpBuf.data(), "%s\t100:\t110%s", pGlobalTXT_LocalizationStrings[530], aMoonPhaseNames[pDayMoonPhase[pParty->uDaysPlayed]]); // "Moon"
+  calendar_window.DrawText(pBookFont, 70, 8 * LOBYTE(pBookFont->uFontHeight) + 31, ui_book_calendar_moon_color, pTmpBuf.data(), 0, 0, 0);
 
-
-
-
+  pMapID = pMapStats->GetMapInfo(pCurrentMapName.data());
+  if ( pMapID )
+    pMapName = pMapStats->pInfos[pMapID].pName;
+  else
+    pMapName = "Unknown";
+  sprintf(pTmpBuf.data(), "%s\t100:\t110%s", pGlobalTXT_LocalizationStrings[531], pMapName); // "Location"
+  calendar_window.DrawText(pBookFont, 70, 10 * LOBYTE(pBookFont->uFontHeight) + 25, ui_book_calendar_location_color, pTmpBuf.data(), 0, 0, 0);
+}
 
 //----- (00413126) --------------------------------------------------------
 void BookUI_Questbook_Draw()
-    {
-    unsigned int v0; // eax@3
-    unsigned int v1; // eax@7
-    int v2; // ecx@11
-    int v3; // ebx@16
-    int v4; // eax@19
-    const char *v5; // edi@19
-    int v6; // eax@19
-    unsigned int v7; // edi@19
-    unsigned int v8; // [sp-8h] [bp-68h]@3
-    unsigned int v9; // [sp-8h] [bp-68h]@7
-    Texture *v10; // [sp-4h] [bp-64h]@3
-    Texture *v11; // [sp-4h] [bp-64h]@7
-    GUIWindow a1; // [sp+Ch] [bp-54h]@9
+{
+  int pTextHeight; // eax@19
+  GUIWindow questbook_window; // [sp+Ch] [bp-54h]@9
+
+  pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pTexture_CurrentBook);
+  if ( BtnUp_flag || !books_primary_item_per_page )//Bookmark Up( )
+    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 407, pViewport->uViewportTL_Y + 2, pTex_tab_an_6a__zoom_off);
+  else
+    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 1, pTex_tab_an_6b__zoom_on);
+
+  if ( BtnDown_flag || books_primary_item_per_page + num_achieved_awards >= full_num_items_in_book )//Bookmark Down( )
+    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 407, pViewport->uViewportTL_Y + 38, pTex_tab_an_7a__zoot_off);
+  else
+    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 38, pTex_tab_an_7b__zoot_on);
+
+  questbook_window.uFrameWidth = game_viewport_width;
+  questbook_window.uFrameHeight = game_viewport_height;
+  questbook_window.uFrameX = game_viewport_x;
+  questbook_window.uFrameY = game_viewport_y;
+  questbook_window.uFrameZ = game_viewport_z;
+  questbook_window.uFrameW = game_viewport_w;
+  questbook_window.DrawTitleText(pBook2Font, 0, 22, ui_book_quests_title_color, pGlobalTXT_LocalizationStrings[174], 3); //"Current Quests"
 
-    pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pTexture_CurrentBook);
-    if ( BtnUp_flag || !dword_506528 )
-        {
-        v10 = pTex_tab_an_6a__zoom_off;
-        v8 = pViewport->uViewportTL_Y + 2;
-        v0 = pViewport->uViewportTL_X + 407;
-        }
-    else
-        {
-        v10 = pTex_tab_an_6b__zoom_on;
-        v8 = pViewport->uViewportTL_Y + 1;
-        v0 = pViewport->uViewportTL_X + 398;
-        }
-    pRenderer->DrawTextureTransparent(v0, v8, v10);
-    if ( BtnDown_flag || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
-        {
-        v11 = pTex_tab_an_7a__zoot_off;
-        v9 = pViewport->uViewportTL_Y + 38;
-        v1 = pViewport->uViewportTL_X + 407;
-        }
-    else
-        {
-        v11 = pTex_tab_an_7b__zoot_on;
-        v9 = pViewport->uViewportTL_Y + 38;
-        v1 = pViewport->uViewportTL_X + 398;
-        }
-    pRenderer->DrawTextureTransparent(v1, v9, v11);
-    a1.uFrameWidth = game_viewport_width;
-    a1.uFrameHeight = game_viewport_height;
-    a1.uFrameX = game_viewport_x;
-    a1.uFrameY = game_viewport_y;
-    a1.uFrameZ = game_viewport_z;
-    a1.uFrameW = game_viewport_w;
-    a1.DrawTitleText(pBook2Font, 0, 22, ui_book_quests_title_color, pGlobalTXT_LocalizationStrings[174], 3); //"Current Quests"
-
-    a1.uFrameX = 48;
-    a1.uFrameY = 70;
-    a1.uFrameWidth = 360;
-    a1.uFrameHeight = 264;
-    a1.uFrameZ = 407;
-    a1.uFrameW = 333;
-    if ( BtnDown_flag && dword_506528 + num_achieved_awards < num_achieved_awards_2 )
-        {
-        pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
-        v2 = dword_50651C++;
-        dword_506528 += num_achieved_awards;
-        byte_506130[v2] = num_achieved_awards;
-        }
-    if ( BtnUp_flag && dword_50651C )
-        {
-        pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
-        --dword_50651C;
-        dword_506528 -= (unsigned __int8)byte_506130[dword_50651C];
-        }
-    if ( !num_achieved_awards || (v3 = dword_506528, dword_506528 < 1) )
-        {
-        v3 = 0;
-        dword_50651C = 0;
-        dword_506528 = 0;
-        }
-    BtnDown_flag = 0;
-    BtnUp_flag = 0;
-    num_achieved_awards = 0;
-    while ( v3 < num_achieved_awards_2 )
-        {
-        v4 = achieved_awards[v3];
-        ++num_achieved_awards;
-        v5 = pQuestTable[v4];//(&dword_722F10)[4 * v4];
-        a1.DrawText(pAutonoteFont, 1, 0, ui_book_quests_text_color, pQuestTable[v4], 0, 0, 0);//(&dword_722F10)[4 * v4], 0, 0, 0);
-        v6 = pAutonoteFont->CalcTextHeight(v5, &a1, 1, 0);
-        v7 = a1.uFrameY + v6;
-        if ( (signed int)(a1.uFrameY + v6) > (signed int)a1.uFrameHeight )
-            break;
-        pRenderer->DrawTextureTransparent(100, v7 + 12, pSpellBookPagesTextr_10);
-        ++v3;
-        a1.uFrameY = v7 + 24;
-        }
-    }
-
+  questbook_window.uFrameX = 48;
+  questbook_window.uFrameY = 70;
+  questbook_window.uFrameWidth = 360;
+  questbook_window.uFrameHeight = 264;
+  questbook_window.uFrameZ = 407;
+  questbook_window.uFrameW = 333;
+  if ( BtnDown_flag && books_primary_item_per_page + num_achieved_awards < full_num_items_in_book )//Click Bookmark Down
+  {
+    pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
+    books_primary_item_per_page += num_achieved_awards;
+    books_num_items_per_page[books_page_number++] = num_achieved_awards;
+  }
+  if ( BtnUp_flag && books_page_number )//Click Bookmark Up
+  {
+    pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
+    --books_page_number;
+    books_primary_item_per_page -= (unsigned __int8)books_num_items_per_page[books_page_number];
+  }
+  if ( !num_achieved_awards || !books_primary_item_per_page )
+  {
+    books_page_number = 0;
+    books_primary_item_per_page = 0;
+  }
+  BtnDown_flag = 0;
+  BtnUp_flag = 0;
+  num_achieved_awards = 0;
+  for ( uint i = books_primary_item_per_page; i < full_num_items_in_book; ++i )
+  {
+    ++num_achieved_awards;
+    //v5 = pQuestTable[achieved_awards[v3]];//(&dword_722F10)[4 * v4];
+    questbook_window.DrawText(pAutonoteFont, 1, 0, ui_book_quests_text_color, pQuestTable[achieved_awards[i]], 0, 0, 0);//(&dword_722F10)[4 * v4], 0, 0, 0);
+    pTextHeight = pAutonoteFont->CalcTextHeight(pQuestTable[achieved_awards[i]], &questbook_window, 1, 0);
+    if ( (signed int)(questbook_window.uFrameY + pTextHeight) > (signed int)questbook_window.uFrameHeight )
+      break;
+    pRenderer->DrawTextureTransparent(100, (questbook_window.uFrameY + pTextHeight) + 12, pSpellBookPagesTextr_10);
+    questbook_window.uFrameY = (questbook_window.uFrameY + pTextHeight) + 24;
+  }
+}
 
 //----- (0041338E) --------------------------------------------------------
 void BookUI_Autonotes_Draw()
+{
+  unsigned int v3; // eax@18
+  unsigned int v4; // eax@24
+  unsigned int v5; // eax@30
+  unsigned int v6; // eax@36
+  unsigned int v7; // eax@42
+  signed int v8; // ebp@47
+  int v9; // eax@52
+  int v10; // eax@56
+  int v11; // edx@57
+  int v12; // ebp@64
+  int v13; // eax@65
+  const char *v14; // edi@65
+  int v15; // eax@65
+  unsigned int v16; // edi@65
+  unsigned int v19; // [sp-8h] [bp-70h]@18
+  unsigned int v20; // [sp-8h] [bp-70h]@24
+  unsigned int v21; // [sp-8h] [bp-70h]@30
+  unsigned int v22; // [sp-8h] [bp-70h]@36
+  unsigned int v23; // [sp-8h] [bp-70h]@42
+  Texture *v26; // [sp-4h] [bp-6Ch]@18
+  Texture *v27; // [sp-4h] [bp-6Ch]@24
+  Texture *v28; // [sp-4h] [bp-6Ch]@30
+  Texture *v29; // [sp-4h] [bp-6Ch]@36
+  Texture *v30; // [sp-4h] [bp-6Ch]@42
+  signed __int16 v31; // [sp+10h] [bp-58h]@1
+  char *v32; // [sp+10h] [bp-58h]@49
+  GUIWindow autonotes_window; // [sp+14h] [bp-54h]@46
+
+  v31 = 0;
+  pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pTexture_AutonotesBook);
+  if ( BtnUp_flag || !books_primary_item_per_page )
+    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 407, pViewport->uViewportTL_Y + 2, pTex_tab_an_6a__zoom_off);
+  else
+    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 1, pTex_tab_an_6b__zoom_on);
+
+  if ( BtnDown_flag || books_primary_item_per_page + num_achieved_awards >= full_num_items_in_book )
+    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 407, pViewport->uViewportTL_Y + 38, pTex_tab_an_7a__zoot_off);
+  else
+    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 38, pTex_tab_an_7b__zoot_on);
+
+  if ( Book_PageBtn3_flag )//Potions_page_flag
+  {
+    if (_506568_autonote_type == AUTONOTE_POTION_RECEPIE)//press again( )
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTexture_506394);
+    else//press()
     {
-    unsigned int v0; // eax@3
-    unsigned int v1; // eax@7
-    signed int v2; // ebp@11
-    unsigned int v3; // eax@18
-    unsigned int v4; // eax@24
-    unsigned int v5; // eax@30
-    unsigned int v6; // eax@36
-    unsigned int v7; // eax@42
-    signed int v8; // ebp@47
-    int v9; // eax@52
-    int v10; // eax@56
-    int v11; // edx@57
-    int v12; // ebp@64
-    int v13; // eax@65
-    const char *v14; // edi@65
-    int v15; // eax@65
-    unsigned int v16; // edi@65
-    unsigned int v17; // [sp-8h] [bp-70h]@3
-    unsigned int v18; // [sp-8h] [bp-70h]@7
-    unsigned int v19; // [sp-8h] [bp-70h]@18
-    unsigned int v20; // [sp-8h] [bp-70h]@24
-    unsigned int v21; // [sp-8h] [bp-70h]@30
-    unsigned int v22; // [sp-8h] [bp-70h]@36
-    unsigned int v23; // [sp-8h] [bp-70h]@42
-    Texture *v24; // [sp-4h] [bp-6Ch]@3
-    Texture *v25; // [sp-4h] [bp-6Ch]@7
-    Texture *v26; // [sp-4h] [bp-6Ch]@18
-    Texture *v27; // [sp-4h] [bp-6Ch]@24
-    Texture *v28; // [sp-4h] [bp-6Ch]@30
-    Texture *v29; // [sp-4h] [bp-6Ch]@36
-    Texture *v30; // [sp-4h] [bp-6Ch]@42
-    signed __int16 v31; // [sp+10h] [bp-58h]@1
-    char *v32; // [sp+10h] [bp-58h]@49
-    GUIWindow a1; // [sp+14h] [bp-54h]@46
+      v31 = 1;
+      pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
+      _506568_autonote_type = AUTONOTE_POTION_RECEPIE;
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTexture_506394);
+    }
+  }
+  else 
+  {
+    if (_506568_autonote_type == AUTONOTE_POTION_RECEPIE)// default(    )
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTexture_506394);
+    else//Potions_page not active(   )
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 113, pTexture_506390);
+  }
 
-    v31 = 0;
-    pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pTexture_AutonotesBook);
-    if ( BtnUp_flag || !dword_506528 )
-        {
-        v24 = pTex_tab_an_6a__zoom_off;
-        v17 = pViewport->uViewportTL_Y + 2;
-        v0 = pViewport->uViewportTL_X + 407;
-        }
+  if ( Book_PageBtn4_flag )//Fontains_page_flag
+  {
+    if ( _506568_autonote_type == AUTONOTE_STAT_HINT )
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 399, pViewport->uViewportTL_Y + 150, pTexture_50638C);
     else
-        {
-        v24 = pTex_tab_an_6b__zoom_on;
-        v17 = pViewport->uViewportTL_Y + 1;
-        v0 = pViewport->uViewportTL_X + 398;
-        }
-    pRenderer->DrawTextureTransparent(v0, v17, v24);
-    if ( BtnDown_flag || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
-        {
-        v25 = pTex_tab_an_7a__zoot_off;
-        v18 = pViewport->uViewportTL_Y + 38;
-        v1 = pViewport->uViewportTL_X + 407;
-        }
+    {
+      v31 = 1;
+      pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
+      _506568_autonote_type = AUTONOTE_STAT_HINT;
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 399, pViewport->uViewportTL_Y + 150, pTexture_50638C);
+    }
+  }
+  else
+  {
+    if ( _506568_autonote_type == AUTONOTE_STAT_HINT )
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 399, pViewport->uViewportTL_Y + 150, pTexture_50638C);
+    else
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 150, pTexture_506388);
+  }
+
+  if ( Book_PageBtn5_flag )//Autonotes_Obelisks_page_flag
+  {
+    if ( _506568_autonote_type == AUTONOTE_OBELISK)
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 188, pTexture_506384);
     else
-        {
-        v25 = pTex_tab_an_7b__zoot_on;
-        v18 = pViewport->uViewportTL_Y + 38;
-        v1 = pViewport->uViewportTL_X + 398;
-        }
-    pRenderer->DrawTextureTransparent(v1, v18, v25);
-    if ( !Book_PageBtn3_flag )//Potions_page_flag
-        {
-        if (_506568_autonote_type != AUTONOTE_POTION_RECEPIE)
-            {
-            pRenderer->DrawTextureTransparent(
-                pViewport->uViewportTL_X + 408,
-                pViewport->uViewportTL_Y + 113,
-                pTexture_506390);
-            v2 = 1;
-            goto LABEL_16;
-            }
-        goto LABEL_14;
-        }
-    if (_506568_autonote_type == AUTONOTE_POTION_RECEPIE)
-        {
-LABEL_14:
-        v2 = 1;
-        goto LABEL_15;
-        }
-    v2 = 1;
-    v31 = 1;
-    pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
-LABEL_15:
-    _506568_autonote_type = AUTONOTE_POTION_RECEPIE;
-    pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTexture_506394);
-LABEL_16:
-    if ( Book_PageBtn4_flag )//Fontains_page_flag
-        {
-        if ( _506568_autonote_type != v2 )
-            {
-            v31 = v2;
-            pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
-            }
-        }
+    {
+      v31 = 1;
+      pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
+      _506568_autonote_type = AUTONOTE_OBELISK;
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 188, pTexture_506384);
+    }
+  }
+  else
+  {
+    if ( _506568_autonote_type == AUTONOTE_OBELISK)
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 188, pTexture_506384);
+    else
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 188, pTexture_506380);
+  }
+
+  if ( Book_PageBtn6_flag )//Autonotes_Seer_page_flag
+  {
+    if ( _506568_autonote_type == AUTONOTE_SEER)
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 226, pTexture_50637C);
+    else
+    {
+      v31 = 1;
+      pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
+      _506568_autonote_type = AUTONOTE_SEER;
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 226, pTexture_50637C);
+    }
+  }
+  else
+  {
+    if ( _506568_autonote_type == AUTONOTE_SEER)
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 226, pTexture_50637C);
+    else
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 226, pTexture_506378);
+  }
+
+  if ( Autonotes_Misc_page_flag )
+  {
+    if ( _506568_autonote_type == AUTONOTE_MISC)
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 264, pTexture_506374);
+    else
+    {
+      v31 = 1;
+      pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
+      _506568_autonote_type = AUTONOTE_MISC;
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 264, pTexture_506374);
+    }
+  }
+  else
+  {
+    if ( _506568_autonote_type == AUTONOTE_MISC)
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 264, pTexture_506374);
     else
-        {
-        if ( _506568_autonote_type != v2 )
-            {
-            v26 = pTexture_506388;
-            v19 = pViewport->uViewportTL_Y + 150;
-            v3 = pViewport->uViewportTL_X + 408;
-            goto LABEL_22;
-            }
-        }
-    v26 = pTexture_50638C;
-    _506568_autonote_type = v2;
-    v19 = pViewport->uViewportTL_Y + 150;
-    v3 = pViewport->uViewportTL_X + 399;
-LABEL_22:
-    pRenderer->DrawTextureTransparent(v3, v19, v26);
-    if ( Book_PageBtn5_flag )//Autonotes_Obelisks_page_flag
-        {
-        if ( _506568_autonote_type != AUTONOTE_OBELISK)
-            {
-            v31 = v2;
-            pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
-            }
-        }
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 263, pTexture_506370);
+  }
+
+  if ( Autonotes_Instructors_page_flag )
+  {
+    if ( _506568_autonote_type == AUTONOTE_TEACHER)
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 302, pTexture_50636C);
+    else
+    {
+      v31 = 1;
+      pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
+      _506568_autonote_type = AUTONOTE_TEACHER;
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 302, pTexture_50636C);
+    }
+  }
+  else
+  {
+    if ( _506568_autonote_type == AUTONOTE_TEACHER)
+      pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 302, pTexture_50636C);
     else
-        {
-        if ( _506568_autonote_type != AUTONOTE_OBELISK)
-            {
-            v27 = pTexture_506380;
-            v20 = pViewport->uViewportTL_Y + 188;
-            v4 = pViewport->uViewportTL_X + 408;
-            goto LABEL_28;
-            }
-        }
-    v27 = pTexture_506384;
-    _506568_autonote_type = AUTONOTE_OBELISK;
-    v20 = pViewport->uViewportTL_Y + 188;
-    v4 = pViewport->uViewportTL_X + 397;
-LABEL_28:
-    pRenderer->DrawTextureTransparent(v4, v20, v27);
-    if ( Book_PageBtn6_flag )//Autonotes_Seer_page_flag
-        {
-        if ( _506568_autonote_type != AUTONOTE_SEER)
-            {
-            v31 = v2;
-            pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
-            }
-        }
-    else
+     pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 302, pTexture_506368);
+  }
+
+  autonotes_window.uFrameWidth = game_viewport_width;
+  autonotes_window.uFrameHeight = game_viewport_height;
+  autonotes_window.uFrameX = game_viewport_x;
+  autonotes_window.uFrameY = game_viewport_y;
+  autonotes_window.uFrameZ = game_viewport_z;
+  autonotes_window.uFrameW = game_viewport_w;
+  autonotes_window.DrawTitleText(pBook2Font, 0, 22, ui_book_autonotes_title_color, pGlobalTXT_LocalizationStrings[154], 3); // "Auto notes"
+
+  autonotes_window.uFrameX = 48;
+  autonotes_window.uFrameY = 70;
+  autonotes_window.uFrameWidth = 360;
+  autonotes_window.uFrameHeight = 264;
+  autonotes_window.uFrameZ = 407;
+  autonotes_window.uFrameW = 333;
+  if ( v31 )
+  {
+    full_num_items_in_book = 0;
+    books_primary_item_per_page = 0;
+    books_page_number = 0;
+    num_achieved_awards = 0;
+    v8 = 0;
+    do
+    {
+      //if ( dword_72371C[2 * v8] == dword_506568 )
+      if ( pAutonoteTxt[v8].eType == _506568_autonote_type )
+      {
+        //v32 = (&dword_723718_autonote_related)[8 * (signed __int16)v8];
+        v32 = (char *)pAutonoteTxt[v8].pText;
+        if ( (short)v8 )
         {
-        if ( _506568_autonote_type != AUTONOTE_SEER)
-            {
-            v28 = pTexture_506378;
-            v21 = pViewport->uViewportTL_Y + 226;
-            v5 = pViewport->uViewportTL_X + 408;
-            goto LABEL_34;
-            }
-        }
-    v28 = pTexture_50637C;
-    _506568_autonote_type = AUTONOTE_SEER;
-    v21 = pViewport->uViewportTL_Y + 226;
-    v5 = pViewport->uViewportTL_X + 397;
-LABEL_34:
-    pRenderer->DrawTextureTransparent(v5, v21, v28);
-    if ( Autonotes_Misc_page_flag )
-        {
-        if ( _506568_autonote_type != AUTONOTE_MISC)
-            {
-            v31 = v2;
-            pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
-            }
-        }
-    else
-        {
-        if ( _506568_autonote_type != AUTONOTE_MISC)
-            {
-            v29 = pTexture_506370;
-            v22 = pViewport->uViewportTL_Y + 263;
-            v6 = pViewport->uViewportTL_X + 408;
-            goto LABEL_40;
-            }
-        }
-    v29 = pTexture_506374;
-    _506568_autonote_type = AUTONOTE_MISC;
-    v22 = pViewport->uViewportTL_Y + 264;
-    v6 = pViewport->uViewportTL_X + 397;
-LABEL_40:
-    pRenderer->DrawTextureTransparent(v6, v22, v29);
-    if ( Autonotes_Instructors_page_flag )
-        {
-        if ( _506568_autonote_type != AUTONOTE_TEACHER)
-            {
-            v31 = v2;
-            pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
-            }
-        }
-    else
-        {
-        if ( _506568_autonote_type != AUTONOTE_TEACHER)
-            {
-            v30 = pTexture_506368;
-            v23 = pViewport->uViewportTL_Y + 302;
-            v7 = pViewport->uViewportTL_X + 408;
-            goto LABEL_46;
-            }
+          if ( (unsigned __int16)_449B57_test_bit(pParty->_autonote_bits, v8) && v32 )
+          {
+            v9 = num_achieved_awards++;
+            achieved_awards[v9] = (AwardType)v8;
+          }
         }
-    v30 = pTexture_50636C;
-    _506568_autonote_type = AUTONOTE_TEACHER;
-    v23 = pViewport->uViewportTL_Y + 302;
-    v7 = pViewport->uViewportTL_X + 397;
-LABEL_46:
-    pRenderer->DrawTextureTransparent(v7, v23, v30);
-    a1.uFrameWidth = game_viewport_width;
-    a1.uFrameHeight = game_viewport_height;
-    a1.uFrameX = game_viewport_x;
-    a1.uFrameY = game_viewport_y;
-    a1.uFrameZ = game_viewport_z;
-    a1.uFrameW = game_viewport_w;
-    a1.DrawTitleText(pBook2Font, 0, 22, ui_book_autonotes_title_color, pGlobalTXT_LocalizationStrings[154], 3); // "Auto notes"
-
-    a1.uFrameX = 48;
-    a1.uFrameY = 70;
-    a1.uFrameWidth = 360;
-    a1.uFrameHeight = 264;
-    a1.uFrameZ = 407;
-    a1.uFrameW = 333;
-    if ( v31 )
-        {
-        num_achieved_awards_2 = 0;
-        dword_506528 = 0;
-        dword_50651C = 0;
-        num_achieved_awards = 0;
-        v8 = 0;
-        do
-            {
-            //if ( dword_72371C[2 * v8] == dword_506568 )
-            if ( pAutonoteTxt[v8].eType == _506568_autonote_type )
-                {
-                //v32 = (&dword_723718_autonote_related)[8 * (signed __int16)v8];
-                v32 = (char *)pAutonoteTxt[v8].pText;
-                if ( (short)v8 )
-                    {
-                    if ( (unsigned __int16)_449B57_test_bit(pParty->_autonote_bits, v8) && v32 )
-                        {
-                        v9 = num_achieved_awards++;
-                        achieved_awards[v9] = (AwardType)v8;
-                        }
-                    }
-                }
-            ++v8;
-            }
-            while ( v8 < 196 );
-            num_achieved_awards_2 = num_achieved_awards;
-        }
-    else
-        {
-        if ( BtnDown_flag )
-            {
-            v10 = num_achieved_awards + dword_506528;
-            if ( num_achieved_awards + dword_506528 < num_achieved_awards_2 )
-                {
-                v11 = dword_50651C++;
-                byte_506130[v11] = num_achieved_awards;
-                dword_506528 = v10;
-                pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
-                }
-            }
-        if ( BtnUp_flag && dword_50651C )
-            {
-            --dword_50651C;
-            dword_506528 -= (unsigned __int8)byte_506130[dword_50651C];
-            pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
-            }
-        if ( !num_achieved_awards || dword_506528 < 1 )
-            {
-            dword_506528 = 0;
-            dword_50651C = 0;
-            }
-        }
-    v12 = dword_506528;
-    Autonotes_Instructors_page_flag = 0;
-    BtnDown_flag = 0;
-    BtnUp_flag = 0;
-    num_achieved_awards = 0;
-    Autonotes_Misc_page_flag = 0;
-    Book_PageBtn6_flag = 0;//Autonotes_Seer_page_flag
-    Book_PageBtn5_flag = 0;//Autonotes_Obelisks_page_flag
-    Book_PageBtn4_flag = 0;//Fontains_page_flag
-    Book_PageBtn3_flag = 0;//Potions_page_flag
-    while ( v12 < num_achieved_awards_2 )
-        {
-        v13 = achieved_awards[v12];
-        ++num_achieved_awards;
-        //v14 = (&dword_723718_autonote_related)[8 * v13];
-        v14 = pAutonoteTxt[v13].pText;
-        //a1.DrawText(pAutonoteFont, 1, 0, 0, (&dword_723718_autonote_related)[8 * v13], 0, 0, 0);
-        a1.DrawText(pAutonoteFont, 1, 0, ui_book_autonotes_text_color, pAutonoteTxt[v13].pText, 0, 0, 0);
-        v15 = pAutonoteFont->CalcTextHeight(v14, &a1, 1, 0);
-        v16 = a1.uFrameY + v15;
-        if ( (signed int)(a1.uFrameY + v15) > (signed int)a1.uFrameHeight )
-            break;
-        pRenderer->DrawTextureTransparent(0x64u, v16 + 12, pSpellBookPagesTextr_10);
-        ++v12;
-        a1.uFrameY = v16 + 24;
-        }
+      }
+      ++v8;
+    }
+    while ( v8 < 196 );
+    full_num_items_in_book = num_achieved_awards;
+  }
+  else
+  {
+    if ( BtnDown_flag )
+    {
+      v10 = num_achieved_awards + books_primary_item_per_page;
+      if ( num_achieved_awards + books_primary_item_per_page < full_num_items_in_book )
+      {
+        v11 = books_page_number++;
+        books_num_items_per_page[v11] = num_achieved_awards;
+        books_primary_item_per_page = v10;
+        pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
+      }
+    }
+    if ( BtnUp_flag && books_page_number )
+    {
+      --books_page_number;
+      books_primary_item_per_page -= (unsigned __int8)books_num_items_per_page[books_page_number];
+      pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
     }
+    if ( !num_achieved_awards || books_primary_item_per_page < 1 )
+    {
+      books_primary_item_per_page = 0;
+      books_page_number = 0;
+    }
+  }
+  v12 = books_primary_item_per_page;
+  Autonotes_Instructors_page_flag = 0;
+  BtnDown_flag = 0;
+  BtnUp_flag = 0;
+  num_achieved_awards = 0;
+  Autonotes_Misc_page_flag = 0;
+  Book_PageBtn6_flag = 0;//Autonotes_Seer_page_flag
+  Book_PageBtn5_flag = 0;//Autonotes_Obelisks_page_flag
+  Book_PageBtn4_flag = 0;//Fontains_page_flag
+  Book_PageBtn3_flag = 0;//Potions_page_flag
+  while ( v12 < full_num_items_in_book )
+  {
+    v13 = achieved_awards[v12];
+    ++num_achieved_awards;
+    //v14 = (&dword_723718_autonote_related)[8 * v13];
+    v14 = pAutonoteTxt[v13].pText;
+    //a1.DrawText(pAutonoteFont, 1, 0, 0, (&dword_723718_autonote_related)[8 * v13], 0, 0, 0);
+    autonotes_window.DrawText(pAutonoteFont, 1, 0, ui_book_autonotes_text_color, pAutonoteTxt[v13].pText, 0, 0, 0);
+    v15 = pAutonoteFont->CalcTextHeight(v14, &autonotes_window, 1, 0);
+    v16 = autonotes_window.uFrameY + v15;
+    if ( (signed int)(autonotes_window.uFrameY + v15) > (signed int)autonotes_window.uFrameHeight )
+      break;
+    pRenderer->DrawTextureTransparent(0x64u, v16 + 12, pSpellBookPagesTextr_10);
+    ++v12;
+    autonotes_window.uFrameY = v16 + 24;
+  }
+}
 
     //----- (00412E85) --------------------------------------------------------
 void BookUI_Journal_Draw()
@@ -563,7 +452,7 @@
   GUIWindow a1; // [sp+8h] [bp-54h]@10
 
   pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pSpellBookPagesTextr_11);
-  if ( BtnUp_flag || !dword_506528 )
+  if ( BtnUp_flag || !books_primary_item_per_page )
   {
     v13 = pTex_tab_an_6a__zoom_off;
     v11 = pViewport->uViewportTL_Y + 2;
@@ -577,7 +466,7 @@
   }
   pRenderer->DrawTextureTransparent(v0, v11, v13);
 
-  if ( BtnDown_flag || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
+  if ( BtnDown_flag || books_primary_item_per_page + num_achieved_awards >= full_num_items_in_book )
   {
     v14 = pTex_tab_an_7a__zoot_off;
     v12 = pViewport->uViewportTL_Y + 38;
@@ -591,9 +480,9 @@
   }
   pRenderer->DrawTextureTransparent(v1, v12, v14);
 
-  if ( !byte_5C6D50[dword_506528] )
+  if ( !byte_5C6D50[books_primary_item_per_page] )
   {
-    v2 = achieved_awards[dword_506528];
+    v2 = achieved_awards[books_primary_item_per_page];
     a1.uFrameWidth = game_viewport_width;
     a1.uFrameX = game_viewport_x;
     a1.uFrameY = game_viewport_y;
@@ -613,26 +502,26 @@
   a1.uFrameZ = 407;
   a1.uFrameHeight = v4 * 264 / v4;
   a1.uFrameW = a1.uFrameHeight + 69;
-  if ( BtnDown_flag && dword_506528 + num_achieved_awards < num_achieved_awards_2 )
+  if ( BtnDown_flag && books_primary_item_per_page + num_achieved_awards < full_num_items_in_book )
   {
     pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
-    v5 = dword_50651C++;
-    dword_506528 += num_achieved_awards;
-    byte_506130[v5] = num_achieved_awards;
+    v5 = books_page_number++;
+    books_primary_item_per_page += num_achieved_awards;
+    books_num_items_per_page[v5] = num_achieved_awards;
   }
-  if ( BtnUp_flag && dword_50651C )
+  if ( BtnUp_flag && books_page_number )
   {
     pAudioPlayer->PlaySound(SOUND_OpenBook, 0, 0, -1, 0, 0, 0, 0);
-    --dword_50651C;
-    dword_506528 -= (unsigned __int8)byte_506130[dword_50651C];
+    --books_page_number;
+    books_primary_item_per_page -= (unsigned __int8)books_num_items_per_page[books_page_number];
   }
-  if ( !num_achieved_awards || dword_506528 < 1 )
+  if ( !num_achieved_awards || books_primary_item_per_page < 1 )
   {
-    dword_506528 = 0;
-    dword_50651C = 0;
+    books_primary_item_per_page = 0;
+    books_page_number = 0;
   }
   BtnDown_flag = 0;
-  v6 = achieved_awards[dword_506528];
+  v6 = achieved_awards[books_primary_item_per_page];
   BtnUp_flag = 0;
   num_achieved_awards = 0;
   //v7 = *pStorylineText->StoreLine[v6].pText;//*(&pStorylineText->field_0 + 3 * v6);
@@ -640,7 +529,7 @@
   v8 = BuildDialogueString(pStorylineText->StoreLine[v6].pText, uActiveCharacter - 1, 0, 0, 0, (__int64 *)&pParty->field_3C._s_times[ v6 + 21]);
   if ( v7 )
   {
-    v9 = pAutonoteFont->_44C6C2(v8, &a1, 1u, (unsigned __int8)byte_5C6D50[dword_506528]);
+    v9 = pAutonoteFont->_44C6C2(v8, &a1, 1u, (unsigned __int8)byte_5C6D50[books_primary_item_per_page]);
     a1.DrawText(pAutonoteFont, 1, 0, ui_book_journal_text_color, (const char *)v9, 0, a1.uFrameY + a1.uFrameHeight, ui_book_journal_text_shadow);
     ++num_achieved_awards;
   }
--- a/UI/UICharacter.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/UI/UICharacter.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -615,49 +615,49 @@
   strcat(pTmpBuf.data(), "\f00000");
 
   pGUIWindow_CurrentMenu->DrawText(pFontArrus, 24, 18, 0, pTmpBuf.data(), 0, 0, 0);
-  result = dword_506528;
+  result = books_primary_item_per_page;
   a1.uFrameX = 12;
   a1.uFrameY = 48;
   a1.uFrameWidth = 424;
   a1.uFrameHeight = 290;
   a1.uFrameZ = 435;
   a1.uFrameW = 337;
-  if (BtnDown_flag && num_achieved_awards + dword_506528 < num_achieved_awards_2)
-    result = dword_506528++ + 1;
+  if (BtnDown_flag && num_achieved_awards + books_primary_item_per_page < full_num_items_in_book)
+    result = books_primary_item_per_page++ + 1;
   if (BtnUp_flag && result)
   {
     --result;
-    dword_506528 = result;
+    books_primary_item_per_page = result;
   }
 
-    if ( dword_50651C < 0 )
+    if ( books_page_number < 0 )
         {
         result += num_achieved_awards;
-        dword_506528 = result;
-        if ( (signed int)(num_achieved_awards + result) > num_achieved_awards_2 )
+        books_primary_item_per_page = result;
+        if ( (signed int)(num_achieved_awards + result) > full_num_items_in_book )
             {
-            result = num_achieved_awards_2 - num_achieved_awards;
-            dword_506528 = result;
+            result = full_num_items_in_book - num_achieved_awards;
+            books_primary_item_per_page = result;
             }
         }
-    else if ( dword_50651C > 0 )
+    else if ( books_page_number > 0 )
         {
         result -= num_achieved_awards;
-        dword_506528 = result;
+        books_primary_item_per_page = result;
         if ( (result & 0x80000000u) != 0 )
             {
             result = 0;
-            dword_506528 = result;
+            books_primary_item_per_page = result;
             }
         }
     //LABEL_14:
     BtnDown_flag = 0;
     BtnUp_flag = 0;
     num_achieved_awards = 0;
-    dword_50651C = 0;
+    books_page_number = 0;
 
 
-    for (uint i = result; i < num_achieved_awards_2; ++i)
+    for (uint i = result; i < full_num_items_in_book; ++i)
     {
       v5 = achieved_awards[i];
       v6 = (char *)pAwards[v5].pText;//(char *)dword_723E80_award_related[v20 / 4];
@@ -2570,8 +2570,8 @@
         memset(pTmpBuf2.data(), 0, 0x7D0u);
         BtnDown_flag = 0;
         BtnUp_flag = 0;
-        dword_50651C = 0;
-        dword_506528 = 0;
+        books_page_number = 0;
+        books_primary_item_per_page = 0;
         for (int i = 0; i < 105; ++i)
         {
             if ( _449B57_test_bit(pPlayer->_guilds_member_bits, i) && pAwards[i].pText )
@@ -2579,11 +2579,11 @@
                 achieved_awards[num_achieved_awards++] = (AwardType)i;
             }
         }
-        num_achieved_awards_2 = num_achieved_awards;
+        full_num_items_in_book = num_achieved_awards;
         num_achieved_awards = 0;
 
         //sort awards index 
-        if (num_achieved_awards_2 > 0)
+        if (full_num_items_in_book > 0)
         {
             std::stable_sort(achieved_awards.begin(), achieved_awards.end(), awardSort);
         }
--- a/UI/UIHouses.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/UI/UIHouses.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -4435,6 +4435,7 @@
     a1.DrawText(v47, 13, 354 - v48, 0, v49, 0, 0, 0);
   }
 }
+
 //----- (004B4F4F) --------------------------------------------------------
 void JailDialog()
 {
--- a/mm7_5.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/mm7_5.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -1038,7 +1038,7 @@
                         uActiveCharacter = pParty->GetNextActiveCharacter();
                         some_active_character = 0;
                         if ( pParty->bTurnBasedModeOn )
-                          pTurnEngine->_40471C();
+                          pTurnEngine->ApplyPlayerAction();
                         dword_50C9D0 = 0;
                         dword_50C9D4 = 0;
                         dword_50C9D8 = 0;
@@ -2006,7 +2006,7 @@
             v60 = sRecoveryTime;
             pParty->pTurnBasedPlayerRecoveryTimes[_506348_current_lloyd_playerid] = sRecoveryTime;
             pPlayer9->SetRecoveryTime(v60);
-            pTurnEngine->_40471C();
+            pTurnEngine->ApplyPlayerAction();
           }
           else
           {
@@ -2843,9 +2843,9 @@
           pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
           continue;
         case UIMSG_ClickAwardScrollBar:
-          dword_50651C = 1;
+          books_page_number = 1;
           if ( pMouse->GetCursorPos(&v211)->y > 178 )
-            dword_50651C = -1;
+            books_page_number = -1;
           continue;
         case UIMSG_ClickAwardsUpBtn:
           GUIWindow::Create(pBtn_Up->uX, pBtn_Up->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pBtn_Up, 0);
--- a/mm7_6.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/mm7_6.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -1334,7 +1334,7 @@
     int main_hand_idx = player->pEquipment.uMainHand;
     if (player->HasItemEquipped(EQUIP_MAIN_HAND))
       v34 = pItemsTable->pItems[*(int *)&player->pInventoryItemList[main_hand_idx - 1]].uSkillType;
-    pTurnEngine->_40471C();
+    pTurnEngine->ApplyPlayerAction();
   }
 
   switch (v34)
@@ -2151,7 +2151,7 @@
                 if ( !pParty->bTurnBasedModeOn )
                   pPlayers[uActiveCharacter]->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v24 * 2.133333333333333));
                 pCastSpellInfo.data()->_427D48(uActiveCharacter);
-                pTurnEngine->_40471C();
+                pTurnEngine->ApplyPlayerAction();
               }
             }
             break;
--- a/mm7_data.cpp	Tue Aug 06 09:26:06 2013 +0600
+++ b/mm7_data.cpp	Tue Aug 06 09:26:17 2013 +0600
@@ -58,7 +58,7 @@
 std::array<Award, 105> pAwards;
 std::array<AwardType, 1000> achieved_awards;
 int num_achieved_awards;
-int num_achieved_awards_2;
+int full_num_items_in_book;
 
 #include "stru160.h"
 std::array<stru160, 66> array_4EB8B8 =
@@ -886,7 +886,7 @@
 int dword_505890; // weak
 std::array<unsigned int, 480> pSRZBufferLineOffsets;
 int areWeLoadingTexture; // weak
-std::array<char, 777> byte_506130; // weak
+std::array<char, 777> books_num_items_per_page; // weak
 int dword_506338; // weak
 int dword_50633C; // idb
 signed int sRecoveryTime; // idb
@@ -898,8 +898,8 @@
 //Texture *dword_506404[12]; // weak
 //Texture *dword_50640C[12]; // weak
 unsigned int uExitCancelTextureId;
-int dword_50651C; // weak
-int dword_506528; // weak
+int books_page_number; // weak
+int books_primary_item_per_page; // weak
 int Autonotes_Instructors_page_flag; // dword_50652C
 int Autonotes_Misc_page_flag; //dword_506530
 int Book_PageBtn6_flag; //dword_506534
--- a/mm7_data.h	Tue Aug 06 09:26:06 2013 +0600
+++ b/mm7_data.h	Tue Aug 06 09:26:17 2013 +0600
@@ -532,7 +532,7 @@
 extern int dword_505890; // weak
 extern std::array<unsigned int, 480> pSRZBufferLineOffsets;
 extern int areWeLoadingTexture; // weak
-extern std::array<char, 777> byte_506130; // weak
+extern std::array<char, 777> books_num_items_per_page; // weak
 extern int dword_506338; // weak
 extern int dword_50633C; // idb
 extern signed int sRecoveryTime; // idb
@@ -543,8 +543,8 @@
 extern int dword_506364; // weak
 //extern Texture *dword_50640C[]; // weak
 extern unsigned int uExitCancelTextureId;
-extern int dword_50651C; // weak
-extern int dword_506528; // weak
+extern int books_page_number; // number for page in books(   )
+extern int books_primary_item_per_page; // number primary item in book page(    )
 extern int Autonotes_Instructors_page_flag; // dword_50652C
 extern int Autonotes_Misc_page_flag; //dword_506530
 extern int Book_PageBtn6_flag; //dword_506534