changeset 1450:8ff3c675a726

more renaming TE
author Gloval
date Wed, 07 Aug 2013 08:55:34 +0400
parents 27b7ee003c7c
children 7d3bed7772cb 5c95f2246c2a
files Actor.cpp Actor.h CastSpellInfo.cpp SpriteObject.cpp TurnEngine.cpp TurnEngine.h mm7_2.cpp mm7_5.cpp mm7_6.cpp
diffstat 9 files changed, 132 insertions(+), 175 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Tue Aug 06 00:56:33 2013 +0400
+++ b/Actor.cpp	Wed Aug 07 08:55:34 2013 +0400
@@ -4049,7 +4049,7 @@
 	double v42; // st7@176
 	double v43; // st6@176
 	//bool v44; // eax@189
-	bool v45; // eax@192
+	int v45; // eax@192
 	unsigned __int8 v46; // cl@197
 	double v47; // st7@206
 	//double v48; // st7@207
@@ -4149,8 +4149,8 @@
 						pPlayer->ReceiveDamage(v4, DMGT_5);
 				}
 			}
-			if (pTurnEngine->field_1C)
-				--pTurnEngine->field_1C;
+			if (pTurnEngine->pending_actions)
+				--pTurnEngine->pending_actions;
 		}
 	}
 	
--- a/Actor.h	Tue Aug 06 00:56:33 2013 +0400
+++ b/Actor.h	Wed Aug 07 08:55:34 2013 +0400
@@ -14,7 +14,7 @@
 {
   void LootActor(struct Actor *pActor);
   int which_player_would_attack(struct Actor *pActor);
-  bool special_ability_use_check(struct Actor *pActor, int a2);
+  int  special_ability_use_check(struct Actor *pActor, int a2);
   int _427102(struct Actor *pActor, signed int a2);
   int PlayerHitOrMiss(struct Player *pPlayer, struct Actor *pActor, int a3, int a4);
   bool _4273BB(struct Actor *pActor, struct Actor *a2, int a3, int a4);
--- a/CastSpellInfo.cpp	Tue Aug 06 00:56:33 2013 +0400
+++ b/CastSpellInfo.cpp	Wed Aug 07 08:55:34 2013 +0400
@@ -478,7 +478,7 @@
 				pSpellSprite.uSectorID = pIndoor->GetSector(pSpellSprite.vPosition.x, pSpellSprite.vPosition.y, pSpellSprite.vPosition.z);
 				if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
 					pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			}
 			break;
 		}
@@ -511,7 +511,7 @@
 				LOBYTE(pSpellSprite.uAttributes) |= 4u;
 			if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
 					pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			break;
 		}
 		case SPELL_FIRE_TORCH_LIGHT:
@@ -594,7 +594,7 @@
 				LOBYTE(pSpellSprite.uAttributes) |= 4u;
 			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
 			if ( pSpellSprite.Create(pParty->sRotationY, pParty->sRotationX + 10, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			LODWORD(v727) = 1;
 			break;
 		}
@@ -751,7 +751,7 @@
 				LOBYTE(pSpellSprite.uAttributes) |= 0x40u;
 			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
 			if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			LODWORD(v727) = 1;
 			break;
 		}
@@ -786,7 +786,7 @@
 				LOBYTE(pSpellSprite.uAttributes) |= 4u;
 			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
 			if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			LODWORD(v727) = 1;
 			break;
 		}
@@ -826,7 +826,7 @@
 					LOBYTE(pSpellSprite.uAttributes) |= 4u;
 				v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
 				if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-					++pTurnEngine->field_1C;
+					++pTurnEngine->pending_actions;
 				LODWORD(v727) = 1;
 			}
 			break;
@@ -973,7 +973,7 @@
 				v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
 
 				if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			LODWORD(v727) = 1;
 			break;
 		}
@@ -1393,7 +1393,7 @@
 						pSpellSprite.uAttributes = 4;
 					if ( pSpellSprite.Create(v687, SHIDWORD(v687), pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed, 0) != -1
 						&& pParty->bTurnBasedModeOn == 1 )
-						++pTurnEngine->field_1C;
+						++pTurnEngine->pending_actions;
 					j = rand() % 1024 - 512;
 					k = rand() % 1024 - 512;
 				}
@@ -1540,7 +1540,7 @@
 						pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
 						pCastSpell->uPlayerID + 1) != -1
 						&& pParty->bTurnBasedModeOn == 1 )
-				    ++pTurnEngine->field_1C;
+				    ++pTurnEngine->pending_actions;
 				v188 += _v726 / (amount - 1);
 			}
 			LODWORD(v727) = 1;
@@ -1710,7 +1710,7 @@
 				pSpellSprite.uAttributes = 4;
 				if ( pSpellSprite.Create(v685, SHIDWORD(v685), pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed, 0) != -1
 					   && pParty->bTurnBasedModeOn == 1 )
-				  ++pTurnEngine->field_1C;
+				  ++pTurnEngine->pending_actions;
 				v721 = rand() % 1024 - 512;
 				v218 = rand();
 				v14 = a2-- == 1;
@@ -1799,7 +1799,7 @@
 					LOBYTE(pSpellSprite.uAttributes) |= 4u;
 				v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
 				if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-					++pTurnEngine->field_1C;
+					++pTurnEngine->pending_actions;
 			}
 			else
 			{
@@ -1834,7 +1834,7 @@
 								pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
 								pCastSpell->uPlayerID + 1) != -1
 								&& pParty->bTurnBasedModeOn == 1 )
-							++pTurnEngine->field_1C;
+							++pTurnEngine->pending_actions;
 						v227 += _v733 / (amount - 1);
 					}
 					while ( v227 <= _y );
@@ -2209,7 +2209,7 @@
 
 			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
 			if ( pSpellSprite.Create(pParty->sRotationY, pParty->sRotationX, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			LODWORD(v727) = 1;
 			break;
 		}
@@ -2246,7 +2246,7 @@
 
 			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
 			if ( pSpellSprite.Create(pParty->sRotationY, stru_5C6E00->uIntegerHalfPi / 2, v659, 0) != -1 && pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			LODWORD(v727) = 1;
 			break;
 		}
@@ -3718,7 +3718,7 @@
 							pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
 							pCastSpell->uPlayerID + 1) != -1
 							&& pParty->bTurnBasedModeOn == 1 )
-						++pTurnEngine->field_1C;
+						++pTurnEngine->pending_actions;
 					v596 += _v726 / (amount - 1);
 				}
 				while ( v596 <= (signed int)y );
@@ -4010,7 +4010,7 @@
 			pParty->field_16140 = v2;
 			++pPlayer->uNumArmageddonCasts;
 			if ( pParty->bTurnBasedModeOn == 1 )
-				++pTurnEngine->field_1C;
+				++pTurnEngine->pending_actions;
 			auto _v726 = 50;
 			do
 			{
--- a/SpriteObject.cpp	Tue Aug 06 00:56:33 2013 +0400
+++ b/SpriteObject.cpp	Wed Aug 07 08:55:34 2013 +0400
@@ -1064,7 +1064,7 @@
     if (pSpriteObjects[uLayingItemID].uAttributes & 4 )
     {
       pSpriteObjects[uLayingItemID].uAttributes &= 0xFFFB;
-      --pTurnEngine->field_1C;
+      --pTurnEngine->pending_actions;
     }
   }
 }
--- a/TurnEngine.cpp	Tue Aug 06 00:56:33 2013 +0400
+++ b/TurnEngine.cpp	Wed Aug 07 08:55:34 2013 +0400
@@ -24,15 +24,15 @@
     {
 
     int active_actors;
-    TurnBased_QueueElem *v7; // eax@16
-    TurnBased_QueueElem *v8; // ecx@18
+    TurnBased_QueueElem *current_top; // eax@16
+    TurnBased_QueueElem *test_element; // ecx@18
     TurnBased_QueueElem temp_elem;
     int i,j;
     unsigned int p_type;
     unsigned int p_id;
 
     active_actors = this->uActorQueueSize;
-
+    //set non active actors in queue initiative that not allow them to paticipate 
     for( i=0; i<uActorQueueSize; ++i) 
         {
         p_type = PID_TYPE(pQueue[i].uPackedID);
@@ -62,28 +62,28 @@
     {
     for( i=0; i<uActorQueueSize-1; ++i) 
         {
-       v7=&pQueue[i];
+       current_top=&pQueue[i];
         for(j=i+1; j<uActorQueueSize;++j )
             {  
-            v8=&pQueue[j];           
-            if ( v8->actor_initiative < v7->actor_initiative  || 
-                   ((v8->actor_initiative == v7->actor_initiative) && 
+            test_element=&pQueue[j];           
+            if ( test_element->actor_initiative < current_top->actor_initiative  || // if less initiative -> top
+                   ((test_element->actor_initiative == current_top->actor_initiative) && 
                        (
-                          ((PID_TYPE(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)))      
+                          ((PID_TYPE(test_element->uPackedID) == OBJECT_Player) && (PID_TYPE(current_top->uPackedID) == OBJECT_Actor)) || //player preferable
+                          ((PID_TYPE(test_element->uPackedID) == PID_TYPE(current_top->uPackedID)) && (PID_ID(test_element->uPackedID) < PID_ID(current_top->uPackedID)))  //less id preferable    
                        ) 
                    )
                 )
-                {
-                memcpy(&temp_elem,v7,sizeof(TurnBased_QueueElem));
-                memcpy(v7,v8, sizeof(TurnBased_QueueElem));
-                memcpy(v8, &temp_elem, sizeof(TurnBased_QueueElem));
+                { //swap
+                memcpy(&temp_elem,current_top,sizeof(TurnBased_QueueElem));
+                memcpy(current_top,test_element, sizeof(TurnBased_QueueElem));
+                memcpy(test_element, &temp_elem, sizeof(TurnBased_QueueElem));
                 }
             }
         }
     }
     uActorQueueSize = active_actors;
-    if ( PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
+    if ( PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) //we have player at queue top
         {
         uActiveCharacter = PID_ID(pQueue[0].uPackedID)+1;
         field_18 |= TE_PLAYER_TURN;
@@ -95,8 +95,8 @@
         }
     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].actor_initiative * 0.46875);
+        if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) //set recovery times
+            pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 0.46875);
         }
 
 
@@ -118,9 +118,7 @@
 
     int v3; // esi@1
     unsigned int actor_id; // esi@7
-    Actor *pActor; // edi@7
     unsigned int v8; // edx@10
-    signed int v16; // qax@19
     int v17; // edx@22
     AIDirection v30; // [sp+Ch] [bp-68h]@10
     AIDirection v31; // [sp+28h] [bp-4Ch]@10
@@ -133,7 +131,7 @@
     int i,j;
     int temp;
 
-    pTurnEngine->field_18 &= ~TE_FLAG_2;
+    pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
     pEventTimer->TrackGameTime();
     pAudioPlayer->StopChannels(-1, -1);
     pAudioPlayer->PlaySound(SOUND_207, 0, 0, -1, 0, 0, 0, 0);
@@ -152,7 +150,7 @@
         if ( pParty->pPlayers[v3].CanAct() )
             {
             this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Player,v3);
-            this->pQueue[this->uActorQueueSize].field_C = 2;
+            this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE;
             this->pQueue[this->uActorQueueSize].uActionLength = 0;
             pParty->pTurnBasedPlayerRecoveryTimes[this->uActorQueueSize] = 0;
             ++this->uActorQueueSize;
@@ -174,7 +172,7 @@
                 memcpy(&v30, &v31, sizeof(AIDirection));
                 Actor::AI_StandOrBored(actor_id, 4, 32, &v30);
                 this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Actor,actor_id);
-                this->pQueue[this->uActorQueueSize].field_C = 2;
+                this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE;
                 this->pQueue[this->uActorQueueSize].uActionLength = 0;
                 ++this->uActorQueueSize;
                 }
@@ -184,14 +182,12 @@
     a_players_count=0;
     for ( v40b = 0; v40b < this->uActorQueueSize; ++v40b )
         {
-        //v13 = PID_TYPE(this->pQueue[0].uPackedID);
+        //set initial initiative for turn actors
         if ( PID_TYPE(this->pQueue[v40b].uPackedID) == OBJECT_Player )
             {
             if ( pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery != 0 )
                 {
-                //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].actor_initiative = v16;
+                this->pQueue[v40b].actor_initiative = (signed int)((double)pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery * 0.46875);
                 }
             else
                 {   
@@ -208,7 +204,7 @@
                 this->pQueue[v40b].actor_initiative= (v17 >= 66)? 5 : 3; 
             }
         else 
-            {
+            {  //fot non player and actor
             this->pQueue[v40b].actor_initiative = 666;
             }
         this->pQueue[v40b].actor_initiative += 16;
@@ -274,18 +270,18 @@
         objID = PID_ID(pQueue[i].uPackedID);
         if ( objType == OBJECT_Player )
             {
-            pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)pQueue[i].actor_initiative * 2.133333333333333);
+            pPlayers[objID + 1]->uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333);
             }
         else if ( objType == OBJECT_Actor )
             {
-             pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)pQueue[i].actor_initiative * 2.133333333333333);
+             pActors[objID].pMonsterInfo.uRecoveryTime = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333);
             }
         }
    
     pAudioPlayer->StopChannels(-1, -1);
     if ( bPlaySound != 0 )
         pAudioPlayer->PlaySound(SOUND_206, 0, 0, -1, 0, 0, 0, 0);
-    pTurnEngine->field_18 &= ~TE_FLAG_2;
+    pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
     pEventTimer->StopGameTime();
     dword_50C994 = 0;
     dword_50C998_turnbased_icon_1A = 0;
@@ -331,7 +327,7 @@
                 memcpy(&v15, v6, sizeof(AIDirection));   
                 memcpy(&v14, &v15, sizeof(AIDirection));
                 v7 = curr_actor->uAIState;
-                if(v7==AIState::Dying)
+                if(v7==Dying)
                     {
                     curr_actor->uCurrentActionTime = 0;
                     curr_actor->uCurrentActionLength = 0;
@@ -349,18 +345,14 @@
     if ( turn_stage == 1 )
         {
         if ( ai_turn_timer == 64 )
-            {
-            ActorAIDoMainAction();
-            }
+            ActorAISetMovementDecision();
         else  if ( ai_turn_timer > 0 )
-                {
-                ActorAIDoAdditionAction();
-                }
+            ActorAIDoAdditionalMove();
         else
-                {
-                ActorAISetLastAction();
-                turn_initiative = 100;
-                }
+            {
+             ActorAIStopMovement();
+             turn_initiative = 100;
+            }
         ai_turn_timer -= pEventTimer->uTimeElapsed;
         }
     else if ( turn_stage == 2 )
@@ -379,20 +371,17 @@
                 SetAIRecoveryTimes();
                 }
             }
-            NextTurn();
+        NextTurn();
         }
     else if ( turn_stage == 3 )
         {
         if ( (uActionPointsLeft > 0) && (field_18 == TE_FLAG_8) )
-            {
-           _406FA8();
-            }
+           ActorAIChooseNewTargets();
         else
             { 
             field_18 &= ~TE_FLAG_8;
-        turn_stage = 1;
-        ai_turn_timer = 64;
-            
+            turn_stage = 1;
+            ai_turn_timer = 64; 
             }
         }
     }
@@ -403,7 +392,8 @@
     {
     int player_num, actor_num, i, j;
 
-    field_1C = 0;
+    pending_actions = 0;
+    //add player to queue if he can act
     for(player_num=0; player_num<4; ++player_num) 
         {
         for(j=0; j<uActorQueueSize; ++j) 
@@ -419,11 +409,11 @@
              pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num);
              pQueue[uActorQueueSize].actor_initiative = 100;
              pQueue[uActorQueueSize].uActionLength = 0;
-             pQueue[uActorQueueSize].field_C = 0;
+             pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND;
              ++uActorQueueSize;
              }
         }
-
+    //add new arrived actors
     for(actor_num=0; actor_num<ai_arrays_size; ++actor_num) 
         {
         for(j=0; j<uActorQueueSize; ++j) 
@@ -437,7 +427,7 @@
             pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]);
             pQueue[uActorQueueSize].actor_initiative = 1;
             pQueue[uActorQueueSize].uActionLength = 0;
-            pQueue[uActorQueueSize].field_C = 0;
+            pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND;
             ++uActorQueueSize;
             }
         }
@@ -456,7 +446,7 @@
         {
         if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].actor_initiative > 0))
             break;
-        _40680F(i);
+        AI_Action_(i);
         }
     }
 // 4F75D8: using guessed type int ai_arrays_size;
@@ -478,12 +468,12 @@
          uActiveCharacter = 0;
      viewparams->bRedrawGameUI = 1;
 
-     if ( field_1C )
+     if ( pending_actions )
          {
-         pTurnEngine->field_18 |= TE_FLAG_2;
+         pTurnEngine->field_18 |= TE_HAVE_PENDING_ACTIONS;
          return;
          }
-     pTurnEngine->field_18 &= ~TE_FLAG_2;
+     pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
      if ( pQueue[0].actor_initiative <= 0 )
          return;
 
@@ -506,7 +496,7 @@
                          {
                          v13 = 1;
                          }
-                     else if ( ai_state == 4 )// Dying
+                     else if ( ai_state == AIState::Dying )// Dying
                          {
                          curr_actor->uAIState = AIState::Dead;
                          curr_actor->uCurrentActionTime = 0;
@@ -515,7 +505,7 @@
                          }
                      else
                          {
-                         if ( ai_state == 8 ) //Stunned
+                         if ( ai_state == AIState::Stunned ) //Stunned
                              Actor::AI_StandOrBored(PID_ID(pQueue[i].uPackedID), ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)], 32, 0);
                          }
                      }
@@ -528,7 +518,8 @@
              }
          }
 
-     field_18 &= ~TE_FLAG_1;       
+     field_18 &= ~TE_FLAG_1;   
+     //set all actors to stay
      for (i=0; i<uActorQueueSize; ++i )
          {      
          if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) 
@@ -546,6 +537,7 @@
                  }
              }
          }
+     // turn tick
      turn_stage = 3;
      pParty->uTimePlayed += 213i64;
      _494035_timed_effects__water_walking_damage__etc();
@@ -607,15 +599,8 @@
 //----- (00406457) --------------------------------------------------------
 void stru262_TurnBased::_406457( int a2 )
     {
-    stru262_TurnBased *v2; // esi@1
-    signed int v3; // eax@1
     signed int v4; // ecx@2
-    char *v5; // edx@2
     signed int v6; // eax@2
-    int result; // eax@11
-    int v8; // edx@13
-    int v9; // ecx@14
-    char v10; // zf@15
     int i;
     v6=0;
     if (  PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player)
@@ -695,7 +680,7 @@
             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);
+                AI_Action_(i);
             }
         }
     else
@@ -719,25 +704,7 @@
     int v3; // eax@1
     unsigned int v4; // ebx@2
     Actor *v5; // esi@2
-    signed int v6; // edi@5
-    int v7; // ecx@6
-    int v8; // eax@6
-    int v9; // eax@7
-    int v10; // eax@8
-    int v11; // eax@9
-    int v12; // eax@10
-    int v13; // eax@11
-    int v14; // eax@14
-    unsigned int v15; // ecx@14
-    unsigned int v16; // edx@14
-    int v17; // eax@17
-    int v18; // eax@20
     char v19; // al@24
-    unsigned int v21; // [sp-8h] [bp-50h]@16
-    int v22; // [sp-8h] [bp-50h]@17
-    AIDirection *v23; // [sp-4h] [bp-4Ch]@14
-    unsigned int v24; // [sp-4h] [bp-4Ch]@17
-    char v25; // [sp-4h] [bp-4Ch]@20
     AIDirection a3; // [sp+Ch] [bp-3Ch]@2
     AIDirection a4; // [sp+28h] [bp-20h]@2
     TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1
@@ -806,22 +773,17 @@
 // 50FE08: using guessed type stru298 stru_50FE08;
 
 //----- (0040680F) --------------------------------------------------------
-void stru262_TurnBased::_40680F( int queue_index )
+void stru262_TurnBased::AI_Action_( int queue_index )
     {
     TurnBased_QueueElem *v2; // eax@1
     unsigned int v3; // eax@1
     unsigned int actor_id; // edi@2
     Actor *v5; // ebx@2
-    unsigned int *v6; // esi@7
     AIDirection *v7; // esi@10
     int v8; // eax@10
     int v9; // ecx@10
     signed int v10; // eax@13
-    unsigned __int8 v11; // sf@19
-    unsigned __int8 v12; // of@19
-    int v13; // esi@29
-    bool v14; // eax@29
-    unsigned __int8 v15; // cl@33
+    int v14; // eax@29
     AIDirection a3; // [sp+Ch] [bp-44h]@10
     AIDirection v18; // [sp+28h] [bp-28h]@10
     int a2a; // [sp+44h] [bp-Ch]@2
@@ -889,28 +851,28 @@
                 if ( v5->pMonsterInfo.uHostilityType == 4 && v22 && (signed int)v9 < 5120 )
                     {
                     v14 = stru_50C198.special_ability_use_check(v5, actor_id);
-                    v21->field_C = 0;
+                    v21->AI_action_type = TE_AI_STAND;
                     switch (v14)
                         {
                     case 1:
                         if ( v5->pMonsterInfo.uMissleAttack2Type )
                             {
                             Actor::AI_MissileAttack2(actor_id, v22, &v18);
-                            v21->field_C = 1;
+                            v21->AI_action_type = TE_AI_RANGED_ATTACK;
                             }   
                         break;
                     case 2:
                         if(v5->pMonsterInfo.uSpell1ID)
                             {
                              Actor::AI_SpellAttack1(actor_id, v22, &v18);
-                            v21->field_C = 1;
+                            v21->AI_action_type = TE_AI_RANGED_ATTACK;
                             }        
                         break;
                     case 3:
                         if(v5->pMonsterInfo.uSpell2ID)
                             {
                             Actor::AI_SpellAttack2(actor_id, v22, &v18);
-                            v21->field_C = 1;
+                            v21->AI_action_type = TE_AI_RANGED_ATTACK;
                             }
                             
                         break;
@@ -918,25 +880,25 @@
                         if ( v5->pMonsterInfo.uMissleAttack1Type )
                             {
                             Actor::AI_MissileAttack1(actor_id, v22, &v18);
-                            v21->field_C = 1;
+                            v21->AI_action_type = TE_AI_RANGED_ATTACK;
                             }
                         }
-                     if (!v21->field_C)
+                     if (!v21->AI_action_type)
                         if ( (double)v20 < 307.2)
                             {
                             Actor::AI_MeleeAttack(actor_id, v22, &v18);
-                            v21->field_C = 3;
+                            v21->AI_action_type = TE_AI_MELEE_ATTACK;
                             }
                         else
                             {
                             Actor::AI_Stand(actor_id, v22, 64, &v18);
-                            v21->field_C = 0;
+                            v21->AI_action_type = TE_AI_STAND;
                             }             
             }
                 else
                     {
                     Actor::AI_Stand(actor_id, v22, 64, &v18);
-                    v21->field_C = 0;
+                    v21->AI_action_type = TE_AI_STAND;
                     }
                v21->uActionLength = v5->uCurrentActionLength;
         }
@@ -944,7 +906,7 @@
     }
 
 //----- (00406A63) --------------------------------------------------------
-void stru262_TurnBased::ActorAIDoMainAction()
+void stru262_TurnBased::ActorAISetMovementDecision()
     {
   
     AIDirection a3; // [sp+8h] [bp-44h]@5
@@ -961,7 +923,7 @@
             {
             target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
             memcpy(&v7, Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &a3, 0), sizeof(AIDirection));
-            if ( !ActorTurn(i) )
+            if ( !ActorMove(i) )
                 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
             }
         }   
@@ -969,7 +931,7 @@
 // 50C994: using guessed type int dword_50C994;
 
 //----- (00406AFE) --------------------------------------------------------
-void stru262_TurnBased::ActorAISetLastAction()
+void stru262_TurnBased::ActorAIStopMovement()
     {
     AIDirection a3; // [sp+4h] [bp-48h]@5
     AIDirection v7; // [sp+20h] [bp-2Ch]@5
@@ -983,7 +945,7 @@
             target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
             memcpy(&v7, Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &a3, 0), sizeof(AIDirection));
             Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
-            pQueue[i].field_C = 0;
+            pQueue[i].AI_action_type = TE_AI_STAND;
             pQueue[i].uActionLength = 0;
             }
         }   
@@ -993,7 +955,7 @@
     }
 
 //----- (00406B9F) --------------------------------------------------------
-void stru262_TurnBased::ActorAIDoAdditionAction()
+void stru262_TurnBased::ActorAIDoAdditionalMove()
     {
     Actor *v6; // ebx@5
     AIDirection a3; // [sp+0h] [bp-50h]@15
@@ -1028,7 +990,7 @@
                             v6->uAIState = AIState::Dead;
                             v6->UpdateAnimation();
                             }
-                        if ( !ActorTurn(i) )
+                        if ( !ActorMove(i) )
                             Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
                         }
                     }
@@ -1038,36 +1000,25 @@
     }
 
 //----- (00406D10) --------------------------------------------------------
-bool stru262_TurnBased::ActorTurn(signed int a2)
+bool stru262_TurnBased::ActorMove(signed int queue_position)
     {
     int v2; // ecx@1
     //int v3; // ecx@2
     Actor *actor; // ebx@2
-    //unsigned __int16 v5; // dx@2
-    int *v6; // esi@7
-    TurnBased_QueueElem *v7; // edi@7
-    int v8; // eax@7
+
     AIDirection *v9; // esi@10
     int v10; // eax@10
     int v11; // ecx@10
     unsigned __int8 pHostileType; // al@12
-    unsigned __int8 v13; // sf@16
-    unsigned __int8 v14; // of@16
-    unsigned int v15; // edx@22
-    unsigned int v16; // ecx@23
-    TurnBased_QueueElem *v17; // eax@25
-    double v18; // st7@33
-    double v19; // st6@33
     AIDirection a3; // [sp+Ch] [bp-48h]@10
     AIDirection pDir; // [sp+28h] [bp-2Ch]@10
-    int v27; // [sp+44h] [bp-10h]@33
     int v28; // [sp+48h] [bp-Ch]@10
     TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7
     unsigned int uActorID; // [sp+50h] [bp-4h]@2
     unsigned int a2a; // [sp+5Ch] [bp+8h]@7
 
     // __debugbreak();//срабатывает при пошаговом режиме после пяти шагов
-    v2 = pQueue[a2].uPackedID;
+    v2 = pQueue[queue_position].uPackedID;
     if (PID_TYPE(v2) == OBJECT_Player)
         return 0;
     uActorID = PID_ID(v2);
@@ -1078,15 +1029,12 @@
          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];
-    v8 = *v6;
-    v29 = &pTurnEngine->pQueue[a2];
-    a2a = v8;
+    v29 = &pTurnEngine->pQueue[queue_position];
+    a2a = ai_near_actors_targets_pid[uActorID];
     Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);
-    if ( actor->pMonsterInfo.uHostilityType && !*v6 )
+    if ( actor->pMonsterInfo.uHostilityType && !ai_near_actors_targets_pid[uActorID] )
         actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
-    v9 = Actor::GetDirectionInfo(v7->uPackedID, a2a, &a3, 0);
+    v9 = Actor::GetDirectionInfo(pQueue[queue_position].uPackedID, ai_near_actors_targets_pid[uActorID], &a3, 0);
     v10 = actor->uActorRadius;
     memcpy(&a3, v9, sizeof(AIDirection));
     memcpy(&pDir, &a3, sizeof(AIDirection));
@@ -1099,7 +1047,6 @@
         }
     pHostileType = actor->pMonsterInfo.uHostilityType;
    
-
     switch (pHostileType)
         {
     case 1:
@@ -1121,12 +1068,12 @@
         if (v11 < 10240 )
             {
             Actor::AI_Flee(uActorID, a2a, 0, &pDir);
-            v29->field_C = 4;
+            v29->AI_action_type = 4;
             }
         else
             {
              Actor::AI_4032B2(uActorID, a2a, 1024, 0);
-             v29->field_C = 2;
+             v29->AI_action_type = TE_AI_PURSUE;
             }         
     
         v29->uActionLength = actor->uCurrentActionLength;
@@ -1143,7 +1090,7 @@
                 Actor::AI_Stand(uActorID, a2a, 32, 0);
             else
                 Actor::AI_Flee(uActorID, a2a, 32, 0);
-            v29->field_C = 4;
+            v29->AI_action_type = 4;
             v29->uActionLength = actor->uCurrentActionLength;
             return 1;
             }
@@ -1156,7 +1103,7 @@
                     Actor::AI_Stand(uActorID, a2a, 32, 0);
                 else
                      Actor::AI_Flee(uActorID, a2a, 32, 0);
-                v29->field_C = 4;
+                v29->AI_action_type = 4;
                 v29->uActionLength = actor->uCurrentActionLength;
                 return 1;
                 }
@@ -1170,7 +1117,7 @@
                     Actor::AI_Stand(uActorID, a2a, 32, 0);
                 else
                      Actor::AI_Flee(uActorID, a2a, 32, 0);
-                v29->field_C = 4;
+                v29->AI_action_type = 4;
                 v29->uActionLength = actor->uCurrentActionLength;
                 return 1;
                 }
@@ -1186,7 +1133,7 @@
             Actor::AI_Pursue1(uActorID, a2a, uActorID, 32, &pDir);
         else
             Actor::AI_Pursue2(uActorID, a2a, 32, &pDir, 307);
-        v29->field_C = 2;
+        v29->AI_action_type = TE_AI_PURSUE;
         v29->uActionLength = actor->uCurrentActionLength;
         return 1;
         }
@@ -1211,13 +1158,13 @@
          default:
              return 1;
         }
-    v29->field_C = 2;
+    v29->AI_action_type = TE_AI_PURSUE;
     v29->uActionLength = actor->uCurrentActionLength;
     return 1;
     }
 
     //----- (00406FA8) --------------------------------------------------------
-void stru262_TurnBased::_406FA8()
+void stru262_TurnBased::ActorAIChooseNewTargets()
     {
     Actor *curr_acror; // ebx@4
     AIDirection a3; // [sp+Ch] [bp-6Ch]@8
--- a/TurnEngine.h	Tue Aug 06 00:56:33 2013 +0400
+++ b/TurnEngine.h	Wed Aug 07 08:55:34 2013 +0400
@@ -4,11 +4,21 @@
 enum TURN_ENGINE_FLAGS
     {
     TE_FLAG_1 =1,
-    TE_FLAG_2 =2,
+    TE_HAVE_PENDING_ACTIONS =2,
     TE_PLAYER_TURN =4,
     TE_FLAG_8 =8
     };
 
+enum TURN_ENGINE_AI_ACTION
+    {
+    TE_AI_STAND         =0,
+    TE_AI_RANGED_ATTACK =1,
+    TE_AI_PURSUE        =2,
+    TE_AI_MELEE_ATTACK  =3,
+    TE_AI_FLEE          =4
+    };
+
+
 
 /*  299 */
 #pragma pack(push, 1)
@@ -19,12 +29,12 @@
     uPackedID = 0;
     actor_initiative = 0;
     uActionLength = 0;
-    field_C = 0;
+    AI_action_type = 0;
   }
   int uPackedID;
-  int actor_initiative;
+  int actor_initiative;  //act first who have less
   int uActionLength;
-  int field_C;
+  int AI_action_type;
 };
 #pragma pack(pop)
 
@@ -41,7 +51,7 @@
     turn_initiative = 0;
     uActionPointsLeft = 0;
     field_18 = 0;
-    field_1C = 0;
+    pending_actions = 0;
   }
 
   void  SortTurnQueue();
@@ -56,12 +66,12 @@
   void SetAIRecoveryTimes();
   void _4065B0();
   void AIAttacks(unsigned int queue_index);
-  void _40680F(int queue_index);
-  void ActorAIDoMainAction();
-  void ActorAISetLastAction();
-  void  ActorAIDoAdditionAction();
-  bool ActorTurn(signed int a2);
-  void _406FA8();
+  void AI_Action_(int queue_index);
+  void ActorAISetMovementDecision();
+  void ActorAIStopMovement();
+  void ActorAIDoAdditionalMove();
+  bool ActorMove(signed int a2);
+  void ActorAIChooseNewTargets();
 
 
   int turns_count;
@@ -71,7 +81,7 @@
   int turn_initiative;
   int uActionPointsLeft; //14
   int field_18;
-  int field_1C;
+  int pending_actions;
   TurnBased_QueueElem pQueue[504]; //20
 };
 #pragma pack(pop)
--- a/mm7_2.cpp	Tue Aug 06 00:56:33 2013 +0400
+++ b/mm7_2.cpp	Wed Aug 07 08:55:34 2013 +0400
@@ -6422,7 +6422,7 @@
     v5 = pSpriteObjects[uLayingItemID].uAttributes;
     if ( v5 & 4 )
     {
-      --pTurnEngine->field_1C;
+      --pTurnEngine->pending_actions;
       pSpriteObjects[uLayingItemID].uAttributes = v5 & 0xFFFB;
     }
   }
--- a/mm7_5.cpp	Tue Aug 06 00:56:33 2013 +0400
+++ b/mm7_5.cpp	Wed Aug 07 08:55:34 2013 +0400
@@ -2410,7 +2410,7 @@
           }
           if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3 )
             continue;
-          if ( !(pTurnEngine->field_18 & TE_FLAG_2) )
+          if ( !(pTurnEngine->field_18 & TE_HAVE_PENDING_ACTIONS) )
           {
             if ( pActors[uMessageParam].uAIState == 5 )
               stru_50C198.LootActor(&pActors[uMessageParam]);
@@ -2429,7 +2429,7 @@
           }
           if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3 )
             continue;
-          if ( !(pTurnEngine->field_18 & TE_FLAG_2) )
+          if ( !(pTurnEngine->field_18 & TE_HAVE_PENDING_ACTIONS) )
             _42ECB5_PlayerAttacksActor();
           continue;
         case UIMSG_ExitRest:
--- a/mm7_6.cpp	Tue Aug 06 00:56:33 2013 +0400
+++ b/mm7_6.cpp	Wed Aug 07 08:55:34 2013 +0400
@@ -671,8 +671,8 @@
 }
 
 //----- (0042704B) --------------------------------------------------------
-bool stru319::special_ability_use_check(Actor *pActor, int a2)
-{
+int stru319::special_ability_use_check( struct Actor *pActor, int a2 )
+    {
   stru319 *v3; // edi@1
   signed int v4; // ebx@5
   signed int v5; // edi@5
@@ -688,7 +688,7 @@
     return 2;
   if ( v5 && pActor->pMonsterInfo.uSpell2UseChance && rand() % 100 < pActor->pMonsterInfo.uSpell2UseChance )
     return 3;
-  return pActor->pMonsterInfo.uAttack2Chance && rand() % 100 < pActor->pMonsterInfo.uAttack2Chance;
+  return pActor->pMonsterInfo.uAttack2Chance && rand() % 100 < pActor->pMonsterInfo.uAttack2Chance?1:0;
 }
 
 //----- (00427102) --------------------------------------------------------