changeset 1345:b99aeb077d4f

Слияние
author Ritor1
date Thu, 11 Jul 2013 17:47:33 +0600
parents 65379a50e4eb (current diff) f0b95fb02b83 (diff)
children 84db43e7db93 cc2a25ce8ed2 14695590d7a6
files Indoor.cpp mm7_3.cpp mm7_4.cpp
diffstat 17 files changed, 447 insertions(+), 835 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/Actor.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -4188,7 +4188,7 @@
 			for (uint j = 0; j < 22; ++j)
 			{
 				if (j != 10)
-				pActor->pActorBuffs[j]._4585CA(pParty->uTimePlayed);
+				pActor->pActorBuffs[j].IsBuffExpiredToTime(pParty->uTimePlayed);
 			}
 			/*do
 			{
@@ -4287,7 +4287,7 @@
 			{
 				if ( i != 10 )
 				{
-					pActor->pActorBuffs[i]._4585CA(pParty->uTimePlayed);
+					pActor->pActorBuffs[i].IsBuffExpiredToTime(pParty->uTimePlayed);
 				}
 			}
 			if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime < 0 )
--- a/CastSpellInfo.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/CastSpellInfo.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -4165,7 +4165,7 @@
   //  || (result = pTurnEngine->field_4, pTurnEngine->field_4 != 1) && pTurnEngine->field_4 != 3 )
   if (pParty->bTurnBasedModeOn)
   {
-    if (pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 3)
+    if (pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3)
       return;
   }
 
--- a/Indoor.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/Indoor.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -3893,7 +3893,7 @@
           v6 *= 2;
           v61 = v6;
         }
-        if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 1 )
+        if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 1 )
           v6 = (signed __int64)((double)v61 * flt_6BE3AC_debug_recmod1_x_1_6);
         if ( v6 > 1000 )
           v6 = 1000;
@@ -4196,7 +4196,7 @@
               Actor::AI_FaceObject(v63, v36, v22, (AIDirection *)v22);
               goto LABEL_119;
             }
-            if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->field_4 == 2 || pTurnEngine->field_4 == 3) )
+            if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == 2 || pTurnEngine->turn_stage == 3) )
               goto LABEL_119;
             if ( v0->pMonsterInfo.uHostilityType )
             {
@@ -4224,7 +4224,7 @@
         }
         else
         {
-          if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->field_4 == 2 || pTurnEngine->field_4 == 3) )
+          if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == 2 || pTurnEngine->turn_stage == 3) )
             goto LABEL_123;
           if ( !v0->pMonsterInfo.uHostilityType || v56 != v22 )
           {
--- a/Mouse.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/Mouse.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -630,7 +630,7 @@
 
     if ( pParty->bTurnBasedModeOn == 1 )
     {
-      if ( pTurnEngine->field_4 == 3 )
+      if ( pTurnEngine->turn_stage == 3 )
         pTurnEngine->field_18 |= TE_FLAG_8;
     }
   }
--- a/Overlays.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/Overlays.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -110,14 +110,14 @@
   if ( pCurrentScreen != SCREEN_GAME || !pParty->bTurnBasedModeOn)
     return;
 
-  if ( pTurnEngine->field_4 == 3 )
+  if ( pTurnEngine->turn_stage == 3 )
   {
     v6 = pEventTimer->uStartTime;
     v5 = pIconIDs_Turn[5 - pTurnEngine->uActionPointsLeft / 26];
   }
   else
   {
-    if ( pTurnEngine->field_4 == 1 )
+    if ( pTurnEngine->turn_stage == 1 )
     {
       v6 = dword_50C994;
       v3 = pIconsFrameTable;
@@ -127,7 +127,7 @@
         v5 = uIconID_TurnHour;
       goto LABEL_12;
     }
-    if ( pTurnEngine->field_4 != 2 )
+    if ( pTurnEngine->turn_stage != 2 )
     {
       v4 = this;
       goto LABEL_14;
--- a/Party.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/Party.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -164,7 +164,7 @@
   v12 = 0;
   if ( pParty->bTurnBasedModeOn == 1 )
   {
-    if ( pTurnEngine->field_4 != 2 || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) != OBJECT_Player)
+    if ( pTurnEngine->turn_stage != 2 || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) != OBJECT_Player)
       return 0;
     v2 = PID_ID(pTurnEngine->pQueue[0].uPackedID);
     return v2 + 1;
--- a/Player.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/Player.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -6518,7 +6518,7 @@
     thisb = this;
     v3 = &pParty->pPlayers[player_num-1];
     v73 = 1;
-    if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 3) )
+    if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3) )
         return;
     if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_REAGENT )
         {
--- a/Spells.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/Spells.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -256,9 +256,9 @@
 }
 
 //----- (004585CA) --------------------------------------------------------
-signed int SpellBuff::_4585CA(__int64 a2)
-{
-  if (uExpireTime && uExpireTime < a2)
+bool SpellBuff::IsBuffExpiredToTime( __int64 time_end )
+    {
+  if (uExpireTime && (uExpireTime < time_end))
   {
     uExpireTime = 0;
     uPower = 0;
@@ -270,9 +270,9 @@
 }
 
 //----- (004584E0) --------------------------------------------------------
-bool SpellBuff::Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int uOverlayID, unsigned __int8 caster)
-{
-  if (this->uExpireTime && uExpireTime < this->uExpireTime)
+bool SpellBuff::Apply( signed __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int uOverlayID, unsigned __int8 caster )
+    {
+  if (this->uExpireTime && (uExpireTime < this->uExpireTime))
     return false;
 
   this->uSkill = uSkillLevel;
--- a/Spells.h	Thu Jul 11 17:47:12 2013 +0600
+++ b/Spells.h	Thu Jul 11 17:47:33 2013 +0600
@@ -155,12 +155,12 @@
     uFlags = 0;
   }
 
-  bool Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int uOverlayID, unsigned __int8 caster);
+  bool Apply(signed __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int uOverlayID, unsigned __int8 caster);
   void Reset();
-  signed int _4585CA(__int64 a2);
+  bool IsBuffExpiredToTime(__int64 time_end);
   bool NotExpired();
 
-  unsigned __int64 uExpireTime;
+  signed __int64 uExpireTime;
   unsigned __int16 uPower;
   unsigned __int16 uSkill;
   unsigned __int16 uOverlayID;
--- a/TurnEngine.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/TurnEngine.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -60,7 +60,6 @@
      //sort
 if (uActorQueueSize>0)
     {
-
     for( i=0; i<uActorQueueSize-1; ++i) 
         {
        v7=&pQueue[i];
@@ -83,9 +82,7 @@
             }
         }
     }
-   
     uActorQueueSize = active_actors;
-
     if ( PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
         {
         uActiveCharacter = PID_ID(pQueue[0].uPackedID)+1;
@@ -96,7 +93,6 @@
         uActiveCharacter = 0;
         field_18 &= ~TE_PLAYER_TURN;
         }
-
     for(i=0; i<uActorQueueSize; ++i)
         {
         if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)
@@ -111,7 +107,7 @@
     {
     if ( pParty->bTurnBasedModeOn == 1 )
         {
-        if ( pTurnEngine->field_4 == 2 )
+        if ( pTurnEngine->turn_stage == 2 )
             _406457(0);
         }
     }
@@ -119,51 +115,25 @@
 //----- (004059DB) --------------------------------------------------------
 void stru262_TurnBased::Start()
     {
-    //stru262_TurnBased *v1; // ebx@1
+
     int v3; // esi@1
-    int v4; // eax@5
     unsigned int actor_id; // esi@7
     Actor *pActor; // edi@7
-    unsigned int v7; // eax@9
     unsigned int v8; // edx@10
-    //unsigned __int8 v9; // zf@14
-    //unsigned __int8 v10; // sf@14
-    //unsigned __int8 v11; // of@14
-    //char *v12; // esi@15
-    //int v13; // ecx@16
-    //unsigned __int16 v14; // ax@17
-    int v15; // ecx@18
-    signed __int64 v16; // qax@19
+    signed int v16; // qax@19
     int v17; // edx@22
-    unsigned int v18; // esi@27
-    char *v19; // esi@32
-    int v20; // edx@33
-    char *v21; // eax@33
-    int v22; // ecx@33
-    int v23; // eax@34
-    char *v24; // eax@34
-    char *v25; // ecx@34
-    int v26; // edx@34
-    int v27; // eax@38
-    int v28; // ecx@38
     AIDirection v30; // [sp+Ch] [bp-68h]@10
     AIDirection v31; // [sp+28h] [bp-4Ch]@10
     AIDirection a3; // [sp+44h] [bp-30h]@10
-    //int v33; // [sp+60h] [bp-14h]@10
-    int *v34; // [sp+64h] [bp-10h]@6
-    int v35; // [sp+68h] [bp-Ch]@5
     Player *pPlayer; // [sp+6Ch] [bp-8h]@1
     int v40b;
-    unsigned int v37; // [sp+70h] [bp-4h]@7
     int activ_players[4];
     int players_recovery_time[4];
     int a_players_count;
     int i,j;
     int temp;
 
-
     pTurnEngine->field_18 &= ~TE_FLAG_2;
-    //v1 = this;
     pEventTimer->TrackGameTime();
     pAudioPlayer->StopChannels(-1, -1);
     pAudioPlayer->PlaySound(SOUND_207, 0, 0, -1, 0, 0, 0, 0);
@@ -174,7 +144,7 @@
     this->field_10 = 100;
     this->field_0 = 0;
     this->field_8 = 64;
-    this->field_4 = 1;
+    this->turn_stage = 1;
     this->uActorQueueSize = 0;
 
     for ( v3 = 0; v3 < 4 ; ++v3 )
@@ -244,7 +214,6 @@
         this->pQueue[v40b].field_4 += 16;
         }
 
-
     if ( a_players_count > 0 )
         {
         for (i=0; i<a_players_count; ++i)
@@ -285,7 +254,7 @@
     int objID; // esi@13
     int i; 
 
-    this->field_4 = 0;
+    this->turn_stage = 0;
 
     for( i=0; i<uActorQueueSize; ++i) 
         { 
@@ -327,524 +296,312 @@
 //----- (00405E14) --------------------------------------------------------
 void stru262_TurnBased::_405E14()
     {
-    stru262_TurnBased *v1; // esi@1
-    int v2; // ecx@1
-    SpellBuff *v3; // edi@2
-    Actor *v4; // ebx@3
-    signed int v5; // edx@20
     AIDirection *v6; // esi@21
     int v7; // eax@21
-    int v8; // eax@21
-    int v9; // eax@22
-    int v10; // eax@23
-    int v11; // eax@37
-    int v12; // eax@44
     AIDirection a3; // [sp+4h] [bp-68h]@21
     AIDirection v14; // [sp+20h] [bp-4Ch]@21
     AIDirection v15; // [sp+3Ch] [bp-30h]@21
-    Actor *v16; // [sp+58h] [bp-14h]@2
-    int v17; // [sp+5Ch] [bp-10h]@6
-    stru262_TurnBased *v18; // [sp+60h] [bp-Ch]@1
-    int v19; // [sp+64h] [bp-8h]@8
-    unsigned int v20; // [sp+68h] [bp-4h]@1
+    Actor *curr_actor; // [sp+58h] [bp-14h]@2
+    int target_pid; // [sp+5Ch] [bp-10h]@6
+    int shrinked;
+    int i,j;
 
-    v1 = this;
-    v2 = 0;
-    v18 = v1;
-    v20 = 0;
-    if ( (signed int)uNumActors > 0 )
+    for (i =0; i<uNumActors; ++i )
         {
-        //v3 = pActors;//[0].pActorBuffs;
-        v16 = pActors.data();//[0].pActorBuffs;
-        v3 = v16->pActorBuffs;
-        do
+        curr_actor=&pActors[i];
+        shrinked=pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0;
+        for (j =0; j<22; ++j) //check expired spell Buffs
+            {
+            if(j != 10)
+                pActors[i].pActorBuffs[j].IsBuffExpiredToTime(pParty->uTimePlayed);
+            }
+        if (shrinked && pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <=0) //buff 3 expired
             {
-            v4 = v16;
-            if ( SHIDWORD(v3[3].uExpireTime) < v2 || SHIDWORD(v3[3].uExpireTime) <= v2 && LODWORD(v3[3].uExpireTime) <= v2 )
-                v17 = v2;
-            else
-                v17 = 1;
-            v19 = v2;
-            do
+            pActors[i].uActorHeight = pMonsterList->pMonsters[pActors[i].pMonsterInfo.uID - 1].uMonsterHeight;
+            }
+        if(!(curr_actor->uAttributes&0x80)&&
+              (!curr_actor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime)&&
+              (!curr_actor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime)) 
+            {
+            curr_actor->uCurrentActionTime += pMiscTimer->uTimeElapsed;
+            if (curr_actor->uCurrentActionTime>=curr_actor->uCurrentActionLength)
                 {
-                if ( v19 != 10 )
+                target_pid = ai_near_actors_targets_pid[i];
+                v6 = Actor::GetDirectionInfo(PID(OBJECT_Actor,i), target_pid, &a3, 0);  
+                memcpy(&v15, v6, sizeof(AIDirection));   
+                memcpy(&v14, &v15, sizeof(AIDirection));
+                v7 = curr_actor->uAIState;
+                if(v7==AIState::Dying)
                     {
-                    v3->_4585CA(pParty->uTimePlayed);
-                    v2 = 0;
+                    curr_actor->uCurrentActionTime = 0;
+                    curr_actor->uCurrentActionLength = 0;
+                    curr_actor->uAIState = Dead;
+                    curr_actor->UpdateAnimation();
                     }
-                ++v19;
-                ++v3;
-                }
-                while ( v19 < 22 );
-                if ( v17 != 0
-                    && SHIDWORD(v4->pActorBuffs[3].uExpireTime) <= 0
-                    && (SHIDWORD(v4->pActorBuffs[3].uExpireTime) < 0 || LODWORD(v4->pActorBuffs[3].uExpireTime) <= 0) )
-                    v4->uActorHeight = pMonsterList->pMonsters[v4->pMonsterInfo.uID - 1].uMonsterHeight;
-                if ( !(v4->uAttributes & 0x80) )
+                else  if ( (v7 > AIState::Removed)&&(v7 < AIState::Disabled))
                     {
-                    if ( !v4->pActorBuffs[5].uExpireTime )
-                        {
-                        if ( !v4->pActorBuffs[6].uExpireTime )
-                            {
-                            v5 = v4->uCurrentActionLength;
-                            v4->uCurrentActionTime += pMiscTimer->uTimeElapsed;
-                            if ( (signed int)v4->uCurrentActionTime >= v5 )
-                                {
-                                v17 = ai_near_actors_targets_pid[v20];
-                                v6 = Actor::GetDirectionInfo(PID(OBJECT_Actor,v20), v17, &a3, 0);
-                                v7 = v4->uAIState;
-                                memcpy(&v15, v6, sizeof(v15));
-                                v8 = v7 - 4;
-                                memcpy(&v14, &v15, sizeof(v14));
-                                if ( v8 )
-                                    {
-                                    v9 = v8 - 1;
-                                    if ( v9 )
-                                        {
-                                        v10 = v9 - 6;
-                                        if ( v10 )
-                                            {
-                                            if ( v10 != 8 )
-                                                Actor::AI_StandOrBored(v20, v17, 32, &v14);
-                                            }
-                                        }
-                                    }
-                                else
-                                    {
-                                    v4->uCurrentActionTime = 0;
-                                    v4->uCurrentActionLength = 0;
-                                    v4->uAIState = Dead;
-                                    v4->UpdateAnimation();
-                                    }
-                                v1 = v18;
-                                v2 = 0;
-                                }
-                            }
-                        }
+                     Actor::AI_StandOrBored(i, target_pid, 32, &v14);
                     }
-                ++v20;
-                v3 = v16[1].pActorBuffs;
-                ++v16;
+                }
+            }
+        }
+    
+    if ( turn_stage == 1 )
+        {
+        if ( field_8 == 64 )
+            {
+            _406A63();
             }
-            while ( (signed int)v20 < (signed int)uNumActors );
+        else  if ( field_8 > 0 )
+                {
+                _406B9F();
+                }
+        else
+                {
+                _406AFE();
+                field_10 = 100;
+                }
+        field_8 -= pEventTimer->uTimeElapsed;
         }
-    if ( v1->field_4 == 1 )
+    else if ( turn_stage == 2 )
         {
-        v12 = v1->field_8;
-        if ( v12 == 64 )
+        if ( !(field_18 & TE_FLAG_1) )
             {
-            v1->_406A63();
+            if ( field_10 == 100 )
+                {
+                StartTurn();
+                _40652A();
+                }
+            if ( field_10 > 0 || pQueue[0].field_4 <= 0 )
+                {
+                _4065B0();
+                _40652A();
+                }
+            }
+        else
+            NextTurn();
+        }
+    else if ( turn_stage == 3 )
+        {
+        if ( uActionPointsLeft <= 0 || field_18 & TE_FLAG_8 )
+            {
+            field_18 &= ~TE_FLAG_8;
+            turn_stage = 1;
+            field_8 = 64;
             }
         else
             {
-            if ( v12 > 0 )
-                {
-                v1->_406B9F();
-                }
-            else
-                {
-                v1->_406AFE();
-                v1->field_10 = 100;
-                }
-            }
-        v1->field_8 -= pEventTimer->uTimeElapsed;
-        return;
-        }
-    if ( v1->field_4 == 2 )
-        {
-        if ( !(v1->field_18 & TE_FLAG_1) )
-            {
-            v11 = v1->field_10;
-            if ( v11 == 100 )
-                {
-                v1->StartTurn();
-LABEL_39:
-                v1->_40652A();
-                return;
-                }
-            if ( v11 > 0 || v1->pQueue[0].field_4 <= 0 )
-                {
-                v1->_4065B0();
-                goto LABEL_39;
-                }
-            }
-        v1->NextTurn();
-        return;
-        }
-    if ( v1->field_4 == 3 )
-        {
-        if ( v1->uActionPointsLeft <= 0 || v1->field_18 & TE_FLAG_8 )
-            {
-            v1->field_18 &= ~TE_FLAG_8;
-            v1->field_4 = 1;
-            v1->field_8 = 64;
-            }
-        else
-            {
-            v1->_406FA8();
+            _406FA8();
             }
         }
     }
 
 
 //----- (00406051) --------------------------------------------------------
-__int16 stru262_TurnBased::StartTurn()
+ void stru262_TurnBased::StartTurn()
     {
-    stru262_TurnBased *v1; // esi@1
-    int v2; // ecx@1
-    int v3; // ebx@1
-    char *v4; // edi@1
-    int v5; // eax@4
-    int v6; // eax@12
-    char *v7; // eax@15
-    TurnBased_QueueElem *v8; // edi@17
-    unsigned int v9; // edx@23
-    char *v10; // eax@26
-    int v11; // eax@30
-    int v12; // ebx@30
-    char *v13; // edi@31
-    int v15; // [sp+Ch] [bp-10h]@5
-    TurnBased_QueueElem *v16; // [sp+10h] [bp-Ch]@3
-    int v17; // [sp+14h] [bp-8h]@2
-    int v18; // [sp+14h] [bp-8h]@16
-    signed int v19; // [sp+18h] [bp-4h]@1
-    int v20; // [sp+18h] [bp-4h]@14
+    int player_num, actor_num, i, j;
 
-    v1 = this;
-    v2 = 0;
-    v19 = 0;
-    v3 = v1->uActorQueueSize;
-    v1->field_1C = 0;
-    v4 = (char *)&v1->pQueue[v3].field_4;
-    do
+    field_1C = 0;
+    for(player_num=0; player_num<4; ++player_num) 
         {
-        v17 = v2;
-        if ( v1->uActorQueueSize <= v2 )
-            goto LABEL_11;
-        v16 = v1->pQueue;
-        while ( 1 )
-            {
-            v5 = v16->uPackedID;
-            if ( PID_TYPE(v16->uPackedID) == OBJECT_Player)
-                break;
-LABEL_8:
-            ++v17;
-            ++v16;
-            if ( v17 >= v1->uActorQueueSize )
-                goto LABEL_11;
-            }
-        v15 = PID_ID(v5);
-        if ( !pPlayers[(PID_ID(v5)) + 1]->CanAct() || v19 != v15 )
+        for(j=0; j<uActorQueueSize; ++j) 
             {
-            v2 = 0;
-            goto LABEL_8;
+            if (PID_TYPE(pQueue[j].uPackedID)== OBJECT_Player)
+                {
+                if (pPlayers[PID_ID(pQueue[j].uPackedID) + 1]->CanAct() && (player_num != PID_ID(pQueue[j].uPackedID)) )
+                    break;
+                }
             }
-        v2 = 0;
-LABEL_11:
-        if ( v17 == v1->uActorQueueSize )
-            {
-            *(int *)v4 = 100;
-            v6 = 8 * v19;
-            LOBYTE(v6) = PID(OBJECT_Player,v19);
-            *((int *)v4 + 2) = v2;
-            *((int *)v4 - 1) = v6;
-            *((int *)v4 + 1) = v2;
-            ++v3;
-            v4 += 16;
-            }
-        ++v19;
+         if (j==uActorQueueSize )
+             {
+             pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num);
+             pQueue[uActorQueueSize].field_4 = 100;
+             pQueue[uActorQueueSize].uActionLength = 0;
+             pQueue[uActorQueueSize].field_C = 0;
+             ++uActorQueueSize;
+             }
         }
-        while ( v19 < 4 );
-        v1->uActorQueueSize = v3;
-        v20 = v2;
-        if ( ai_arrays_size > v2 )
+
+    for(actor_num=0; actor_num<ai_arrays_size; ++actor_num) 
+        {
+        for(j=0; j<uActorQueueSize; ++j) 
+            {
+            if ((PID_TYPE(pQueue[j].uPackedID)== OBJECT_Actor)&&
+                 ai_near_actors_ids[actor_num] == PID_ID(pQueue[j].uPackedID))
+                    break;
+            }
+        if (j==uActorQueueSize )
             {
-            v7 = (char *)&v1->pQueue[v3].field_4;
-            do
-                {
-                v18 = v2;
-                if ( v1->uActorQueueSize > v2 )
-                    {
-                    v8 = v1->pQueue;
-                    do
-                        {
-                        if ( PID_TYPE(v8->uPackedID) == OBJECT_Actor && ai_near_actors_ids[v20] == PID_ID(v8->uPackedID) )
-                            break;
-                        ++v18;
-                        ++v8;
-                        }
-                        while ( v18 < v1->uActorQueueSize );
-                        v2 = 0;
-                    }
-                if ( v18 == v1->uActorQueueSize )
-                    {
-                    v9 = ai_near_actors_ids[v20];
-                    *(int *)v7 = 1;
-                    *((int *)v7 + 2) = v2;
-                    *((int *)v7 - 1) = PID(OBJECT_Actor,v9);
-                    *((int *)v7 + 1) = v2;
-                    ++v3;
-                    v7 += 16;
-                    }
-                ++v20;
-                }
-                while ( v20 < ai_arrays_size );
+            pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]);
+            pQueue[uActorQueueSize].field_4 = 1;
+            pQueue[uActorQueueSize].uActionLength = 0;
+            pQueue[uActorQueueSize].field_C = 0;
+            ++uActorQueueSize;
             }
-        ++v1->field_0;
-        v1->uActorQueueSize = v3;
-        v1->field_10 = 100;
-        if ( v3 > 0 )
+        }
+
+        ++field_0;
+        field_10 = 100;
+
+        for(i=0; i<uActorQueueSize; ++i) 
             {
-            v10 = (char *)&v1->pQueue[0].field_4;
-            do
-                {
-                if ( *(int *)v10 <= 0 )
-                    *(int *)v10 = 100;
-                ++v2;
-                v10 += 16;
-                }
-                while ( v2 < v1->uActorQueueSize );
+            if (pQueue[i].field_4 == 0 )
+                pQueue[i].field_4 = 100;
             }
-        LOWORD(v11) = v1->_4063A1();
-        v12 = 0;
-        if ( v1->uActorQueueSize > 0 )
+
+        _4063A1();
+        for(i=0; i<uActorQueueSize; ++i) 
             {
-            v13 = (char *)&v1->pQueue[0].field_4;
-            do
-                {
-                v11 = PID_TYPE(*((int *)v13 - 1));
-                if ( (char)v11 == 4 )
-                    break;
-                if ( *(int *)v13 > 0 )
-                    break;
-                LOWORD(v11) = v1->_40680F(v12++);
-                v13 += 16;
-                }
-                while ( v12 < v1->uActorQueueSize );
+            if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].field_4 > 0))
+                break;
+            _40680F(i);
             }
-        return v11;
     }
 // 4F75D8: using guessed type int ai_arrays_size;
 
-//----- (004061CA) --------------------------------------------------------
-void stru262_TurnBased::NextTurn()
-    {
-    stru262_TurnBased *v1; // esi@1
-    TurnBased_QueueElem *v2; // ebp@1
-    int v3; // ebx@1
-    int v4; // edi@7
-    Actor *v5; // eax@9
-    int v6; // ecx@9
-    signed int v7; // ebx@17
-    int v8; // ebp@27
-    TurnBased_QueueElem *v9; // edi@28
-    int v10; // ecx@30
-    unsigned __int16 v11; // ax@30
-    signed int v12; // edx@35
-    signed int v13; // [sp+10h] [bp-4h]@7
+ //----- (004061CA) --------------------------------------------------------
+ void stru262_TurnBased::NextTurn()
+     {
+     Actor *curr_actor; // eax@9
+     int ai_state; // ecx@9
+     int v13; // [sp+10h] [bp-4h]@7
+     int i;
+     int monster_ai_state;
+     int monster; // eax@5
+
+     SortTurnQueue();
+     if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
+         uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
+     else
+         uActiveCharacter = 0;
+     viewparams->bRedrawGameUI = 1;
+
+     if ( field_1C )
+         {
+         pTurnEngine->field_18 |= TE_FLAG_2;
+         return;
+         }
+     pTurnEngine->field_18 &= ~TE_FLAG_2;
+     if ( pQueue[0].field_4 <= 0 )
+         return;
+
+     v13 = 0;
+     if (uActorQueueSize > 0 )
+         {   
 
-    v1 = this;
-    SortTurnQueue();
-    v2 = v1->pQueue;
-    v3 = 0;
-    if (PID_TYPE(v1->pQueue[0].uPackedID) == OBJECT_Player)
-        uActiveCharacter = PID_ID(v1->pQueue[0].uPackedID) + 1;
-    else
-        uActiveCharacter = 0;
-    viewparams->bRedrawGameUI = 1;
-    if ( v1->field_1C )
-        {
-        pTurnEngine->field_18 |= TE_FLAG_2;
-        return;
-        }
-    pTurnEngine->field_18 &= ~TE_FLAG_2;
-    if ( v1->pQueue[0].field_4 <= 0 )
-        return;
-    v4 = 0;
-    v13 = 0;
-    if ( v1->uActorQueueSize <= 0 )
-        goto LABEL_27;
-    do
-        {
-        if (PID_TYPE(v2->uPackedID) != OBJECT_Player)
-            {
-            v5 = &pActors[PID_ID(v2->uPackedID)];
-            LOWORD(v6) = v5->uAIState;
-            if ( (short)v6 == 4
-                || (short)v6 == 8
-                || (short)v6 == 2
-                || (short)v6 == 3
-                || (short)v6 == 12
-                || (short)v6 == 13
-                || (short)v6 == 18
-                || (short)v6 == 17 )
-                {
-                v7 = v5->uCurrentActionLength;
-                v5->uCurrentActionTime += pEventTimer->uTimeElapsed;
-                if ( (signed int)v5->uCurrentActionTime < v7 )
-                    {
-                    v13 = 1;
-LABEL_19:
-                    v3 = 0;
-                    goto LABEL_20;
-                    }
-                v6 = (signed __int16)v6;
-                if ( (signed __int16)v6 == 4 )
-                    {
-                    v3 = 0;
-                    v5->uAIState = Dead;
-                    v5->uCurrentActionTime = 0;
-                    v5->uCurrentActionLength = 0;
-                    v5->UpdateAnimation();
-                    }
-                else
-                    {
-                    if ( v6 != 8 )
-                        goto LABEL_19;
-                    v3 = 0;
-                    Actor::AI_StandOrBored(PID_ID(v2->uPackedID), ai_near_actors_targets_pid[PID_ID(v2->uPackedID)], 32, 0);
-                    }
-                }
-            }
-LABEL_20:
-        ++v4;
-        ++v2;
-        }
-   while ( v4 < v1->uActorQueueSize );
+         for (i=0; i<uActorQueueSize; ++i )
+             {
+             if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
+                 {
+                 curr_actor = &pActors[PID_ID(pQueue[i].uPackedID)];
+                 ai_state = curr_actor->uAIState;
+                 if ( (ai_state == AIState::Dying) || (ai_state == AIState::Stunned) || (ai_state == AIState::AttackingMelee) ||
+                     (ai_state == AIState::AttackingRanged1) || (ai_state == AIState::AttackingRanged2) || 
+                     (ai_state == AIState::AttackingRanged3) || (ai_state == AIState::AttackingRanged4) || (ai_state ==AIState::Summoned))
+                     {
+                     curr_actor->uCurrentActionTime += pEventTimer->uTimeElapsed;
+                     if ( curr_actor->uCurrentActionTime < curr_actor->uCurrentActionLength )
+                         {
+                         v13 = 1;
+                         }
+                     else if ( ai_state == 4 )// Dying
+                         {
+                         curr_actor->uAIState = AIState::Dead;
+                         curr_actor->uCurrentActionTime = 0;
+                         curr_actor->uCurrentActionLength = 0;
+                         curr_actor->UpdateAnimation();
+                         }
+                     else
+                         {
+                         if ( ai_state == 8 ) //Stunned
+                             Actor::AI_StandOrBored(PID_ID(pQueue[i].uPackedID), ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)], 32, 0);
+                         }
+                     }
+                 }
+             }
+         if ( v13 != 0 )
+             {
+             field_18 |= TE_FLAG_1;
+             return;
+             }
+         }
 
-        if ( v13 != v3 )
-            {
-            v1->field_18 |= TE_FLAG_1;
-            return;
-            }
-LABEL_27:
-        v1->field_18 &= ~TE_FLAG_1;
-        v8 = 0;
-        if ( v1->uActorQueueSize > v3 )
-            {
-            v9 = v1->pQueue;
-            do
-                {
-                if (PID_TYPE(v9->uPackedID) != OBJECT_Player)
-                    {
-                    v10 = PID_ID(v9->uPackedID);
-                    v11 = pActors[v10].uAIState;
-                    if ( v11 != 5 )
-                        {
-                        if ( v11 != 4 && v11 != 11 && v11 != 19 )
-                            {
-                            if ( v11 != 17 )
-                                {
-                                v12 = ai_near_actors_targets_pid[v10];
-                                v9->uActionLength = v3;
-                                Actor::AI_StandOrBored(v10, v12, 32, (AIDirection *)v3);
-                                }
-                            }
-                        }
-                    }
-                ++v8;
-                ++v9;
-                }
-                while ( v8 < v1->uActorQueueSize );
-            }
-        v1->field_4 = 3;
-        pParty->uTimePlayed += __PAIR__(v3, 213);
-        _494035_timed_effects__water_walking_damage__etc();
-        v1->uActionPointsLeft = 130;
-    }
+     field_18 &= ~TE_FLAG_1;       
+     for (i=0; i<uActorQueueSize; ++i )
+         {      
+         if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) 
+             {
+             monster=PID_ID(pQueue[i].uPackedID);
+             monster_ai_state=pActors[monster].uAIState;
+             if ((monster_ai_state != AIState::Dead) && 
+                 (monster_ai_state != AIState::Dying) &&
+                 (monster_ai_state != AIState::Removed) &&
+                 (monster_ai_state != AIState::Summoned) &&
+                 (monster_ai_state != AIState::Disabled))
+                 {
+                 pQueue[i].uActionLength = 0;
+                 Actor::AI_StandOrBored(monster, ai_near_actors_targets_pid[monster], 32, nullptr);
+                 }
+             }
+         }
+     turn_stage = 3;
+     pParty->uTimePlayed += 213i64;
+     _494035_timed_effects__water_walking_damage__etc();
+     uActionPointsLeft = 130;
+     }
 
-//----- (004063A1) --------------------------------------------------------
-int stru262_TurnBased::_4063A1()
-    {
-    stru262_TurnBased *v1; // esi@1
-    int v2; // ebp@1
-    signed int result; // eax@1
-    int v4; // edx@1
-    int v5; // edx@3
-    int v6; // edi@4
-    int v7; // ecx@5
-    Actor *v8; // ecx@11
-    unsigned __int16 v9; // dx@12
-    int v10; // edi@16
-    int v11; // edx@17
-    char v12; // zf@18
+ //----- (004063A1) --------------------------------------------------------
+ int stru262_TurnBased::_4063A1()
+     {
+     int v9; // dx@12 
+     int j;
 
-    v1 = this;
-    SortTurnQueue();
-    v2 = (int)&v1->pQueue[0].field_4;
-    result = 1;
-    viewparams->bRedrawGameUI = 1;
-    v4 = v1->pQueue[0].field_4;
-    if ( v4 )
-        {
-        if (PID_TYPE(v1->pQueue[0].uPackedID) == OBJECT_Player)
-            {
-            v5 = v1->uActorQueueSize;
-            while ( 1 )
-                {
-                v6 = 0;
-                if ( v5 > 0 )
-                    {
-                    v7 = (int)&v1->pQueue[0].field_4;
-                    do
-                        {
-                        --*(int *)v7;
-                        v5 = v1->uActorQueueSize;
-                        ++v6;
-                        v7 += 16;
-                        }
-                        while ( v6 < v5 );
-                    }
-                --v1->field_10;
-                if ( v1->field_10 <= 0 )
-                    break;
-                if ( !*(int *)v2 )
-                    goto LABEL_9;
-                }
-LABEL_24:
-            result = 1;
-            }
-        else
-            {
-            v8 = &pActors[PID_ID(v1->pQueue[0].uPackedID)];
-            if ( v4 > 0 )
-                {
-                do
-                    {
-                    v9 = v8->uAIState;
-                    if ( v9 == 5 )
-                        break;
-                    if ( v9 == 4 || v9 == 19 || v9 == 11 )
-                        break;
-                    v10 = 0;
-                    if ( v1->uActorQueueSize > 0 )
-                        {
-                        v11 = (int)&v1->pQueue[0].field_4;
-                        do
-                            {
-                            v12 = (*(int *)v11)-- == 1;
-                            if ( v12 )
-                                *(int *)(v11 + 4) = 0;
-                            ++v10;
-                            v11 += 16;
-                            }
-                            while ( v10 < v1->uActorQueueSize );
-                        }
-                    --v1->field_10;
-                    if ( v1->field_10 <= 0 )
-                        goto LABEL_24;
-                    }
-                    while ( *(int *)v2 > 0 );
-                }
-LABEL_9:
-            result = 0;
-            }
-        }
-    return result;
-    }
+     SortTurnQueue();
+     viewparams->bRedrawGameUI = 1;
+     if ( pQueue[0].field_4 )
+         {
+         if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
+             {
+             do
+                 {
+                 for (j=0; j<uActorQueueSize; ++j )
+                     {      
+                     --pQueue[j].field_4;
+                     }
+                 --field_10;
+                 if (field_10 == 0)
+                     return 1;
+                 }
+                 while (pQueue[0].field_4 > 0);
+             }
+         else
+             {
+             v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState;
+             if (!(v9 == AIState::Dying || v9 == AIState::Dead || 
+                   v9 == AIState::Disabled || v9 == AIState::Removed))
+                 {
+                 do
+                     {
+                     for (j=0; j<uActorQueueSize; ++j )
+                         {      
+                         --pQueue[j].field_4;
+                         if (pQueue[j].field_4 == 1)
+                             pQueue[j].uActionLength = 0;
+                         }
+                     --field_10;
+                     if (field_10 == 0)
+                         return 1;
+                     }
+                     while (pQueue[0].field_4 > 0); 
+                 }
+             }
+         }
+     return 0;
+     }
 
 //----- (00406457) --------------------------------------------------------
-int stru262_TurnBased::_406457(int a2)
+void stru262_TurnBased::_406457( int a2 )
     {
     stru262_TurnBased *v2; // esi@1
     signed int v3; // eax@1
@@ -855,16 +612,13 @@
     int v8; // edx@13
     int v9; // ecx@14
     char v10; // zf@15
+    int i;
 
-    v2 = this;
-    v3 = *(&this->field_0 + 4 * (a2 + 2));
-    if ( (*((char *)&this->field_0 + 16 * PID_TYPE(a2 + 2))) == OBJECT_Player)
+    if (  PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player)
         {
-        v4 = PID_ID(v3);
-        v5 = (char *)&pParty->pTurnBasedPlayerRecoveryTimes[PID_ID(v3)];
-        v6 = *(int *)v5;
-        if ( *(int *)v5 )
-            *(int *)v5 = 0;
+        v4 = PID_ID(pQueue[a2].uPackedID);
+        if ( pParty->pTurnBasedPlayerRecoveryTimes[v4] )
+            pParty->pTurnBasedPlayerRecoveryTimes[v4] = 0;
         else
             v6 = pPlayers[v4 + 1]->GetAttackRecoveryTime(0);
         if ( v6 < 30 )
@@ -872,44 +626,34 @@
         }
     else
         {
-        v6 = pMonsterStats->pInfos[pActors[PID_ID(v3)].pMonsterInfo.uID].uRecoveryTime;
+        v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime;
         }
-    v2->pQueue[a2].field_4 = v6;
-    v2->SortTurnQueue();
-    if (PID_TYPE(v2->pQueue[0].uPackedID) == OBJECT_Player)
-        uActiveCharacter = PID_ID(v2->pQueue[0].uPackedID) + 1;
+
+    pQueue[a2].field_4 = v6;
+    SortTurnQueue();
+    if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
+        uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
     else
         uActiveCharacter = 0;
-    result = (int)&v2->pQueue[0].field_4;
     viewparams->bRedrawGameUI = 1;
-    while ( *(int *)result > 0 )
+    if (pQueue[0].field_4 > 0)
         {
-        if ( v2->field_10 <= 0 )
-            break;
-        v8 = 0;
-        if ( v2->uActorQueueSize > 0 )
+        while(field_10 > 0)
             {
-            v9 = (int)&v2->pQueue[0].field_4;
-            do
+            for (i=0; i<uActorQueueSize; ++i)
                 {
-                v10 = (*(int *)v9)-- == 1;
-                if ( v10 )
-                    *(int *)(v9 + 4) = 0;
-                ++v8;
-                v9 += 16;
+                --pQueue[i].field_4;
+                if (pQueue[i].field_4==0)
+                    pQueue[i].uActionLength=0;
                 }
-                while ( v8 < v2->uActorQueueSize );
+            --field_10;
             }
-        --v2->field_10;
-        if ( v2->field_10 <= 0 )
-            break;
         }
-    return result;
     }
 
 //----- (0040652A) --------------------------------------------------------
 void stru262_TurnBased::_40652A()
-{
+    {
     int i;
     int monster_ai_state;
     Actor *monster; // eax@5
@@ -922,18 +666,17 @@
                 break;
             monster=&pActors[PID_ID(pQueue[i].uPackedID)];
             monster_ai_state=monster->uAIState;
-            if (monster_ai_state == Standing || 
-                monster_ai_state == Fleeing || 
-                monster_ai_state == Fidgeting)
+            if (monster_ai_state == AIState::Standing || 
+                monster_ai_state == AIState::Fleeing || 
+                monster_ai_state == AIState::Fidgeting)
                 {
-                pQueue[i].field_4 == pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
+                pQueue[i].field_4 = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
                 if (monster->pActorBuffs[7].uExpireTime > 0)
                     pQueue[i].field_4*=2;
-
                 }
             }
         }
-}
+    }
 
 //----- (004065B0) --------------------------------------------------------
 void stru262_TurnBased::_4065B0()
@@ -962,11 +705,11 @@
         }
 
     for (i=0; i<uActorQueueSize; ++i )
-        _406648(i);
+        AIRangedAttacks(i);
 }
 
 //----- (00406648) --------------------------------------------------------
-void stru262_TurnBased::_406648(unsigned int a2)
+void stru262_TurnBased::AIRangedAttacks( unsigned int queue_index )
     {
     TurnBased_QueueElem *v1; // ecx@1
     int v3; // eax@1
@@ -996,121 +739,71 @@
     TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1
     unsigned int a2a; // [sp+50h] [bp+8h]@2
 
-    v1 = (TurnBased_QueueElem *)((char *)this + 16 * (a2 + 2));
+    v1 = &pQueue[queue_index];
     v28 = v1;
     v3 = v1->uPackedID;
-    if (PID_TYPE(v1->uPackedID) != OBJECT_Player)
+    if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor)
         {
         v4 = PID_ID(v3);
-        a2a = ai_near_actors_targets_pid[PID_ID(v3)];
+        a2a = ai_near_actors_targets_pid[PID_ID(pQueue[queue_index].uPackedID)];
         memcpy(&a3, Actor::GetDirectionInfo(v1->uPackedID, ai_near_actors_targets_pid[PID_ID(v3)], &a3, 0), sizeof(a3));
         memcpy(&a4, &a3, sizeof(a4));
         v5 = &pActors[PID_ID(v3)];
         LOWORD(v3) = v5->uAIState;
-        if ( (short)v3 != Dead )
-            {
-            if ( (short)v3 != Disabled )
-                {
-                if ( (short)v3 != Removed )
+        if (( (short)v3 != AIState::Dead )&& ( (short)v3 != AIState::Disabled )&&( (short)v3 != AIState::Removed ))  
                     {
-                    v6 = v5->uCurrentActionLength;
                     v5->uCurrentActionTime += pEventTimer->uTimeElapsed;
-                    if ( (signed int)v5->uCurrentActionTime >= v6 )
+                    if ( (signed int)v5->uCurrentActionTime >= v5->uCurrentActionLength )
                         {
-                        v7 = (signed __int16)v3;
-                        v8 = (signed __int16)v3 - 2;
-                        if ( !v8 )
-                            {
-                            v19 = stru_50C198.special_ability_use_check(&pActors[v4], v4);
-                            stru_50FE08.Add(
-                                v28->uPackedID,
-                                5120,
-                                v5->vPosition.x,
-                                v5->vPosition.y,
-                                v5->vPosition.z + ((signed int)v5->uActorHeight >> 1),
-                                v19,
-                                1);
-                            goto LABEL_25;
-                            }
-                        v9 = v8 - 1;
-                        if ( v9 )
-                            {
-                            v10 = v9 - 1;
-                            if ( !v10 )
-                                goto LABEL_21;
-                            v11 = v10 - 4;
-                            if ( !v11 )
-                                goto LABEL_25;
-                            v12 = v11 - 4;
-                            if ( v12 )
-                                {
-                                v13 = v12 - 1;
-                                if ( v13 )
-                                    {
-                                    if ( v13 != Dead )
-                                        {
-                                        if ( v7 != 4 )
-                                            {
-                                            v14 = rand();
-                                            v15 = v4;
-                                            v23 = &a4;
-                                            v16 = a2a;
-                                            if ( !(v14 % 2) )
-                                                {
-                                                Actor::AI_Bored(v4, a2a, &a4);
-                                                return;
-                                                }
-                                            v21 = 64;
-LABEL_26:
-                                            Actor::AI_Stand(v15, v16, v21, v23);
-                                            return;
-                                            }
-LABEL_21:
-                                        v5->uCurrentActionTime = 0;
-                                        v5->uCurrentActionLength = 0;
-                                        v5->uAIState = Dead;
-                                        pActors[v4].UpdateAnimation();
-                                        return;
-                                        }
-                                    v24 = v5->pMonsterInfo.uSpellSkillAndMastery2;
-                                    v22 = 3;
-                                    v17 = v5->pMonsterInfo.uSpell2ID;
-                                    }
-                                else
-                                    {
-                                    v24 = v5->pMonsterInfo.uSpellSkillAndMastery1;
-                                    v22 = 2;
-                                    v17 = v5->pMonsterInfo.uSpell1ID;
-                                    }
-                                Actor::AI_SpellAttack(v4, &a4, v17, v22, v24);
-LABEL_25:
-                                v16 = a2a;
-                                v23 = &a4;
-                                v21 = 0;
-                                v15 = v4;
-                                goto LABEL_26;
-                                }
-                            v18 = v5->pMonsterInfo.uMissleAttack2Type;
-                            v25 = 1;
-                            }
-                        else
-                            {
-                            v18 = v5->pMonsterInfo.uMissleAttack1Type;
-                            v25 = 0;
-                            }
-                        Actor::AI_RangedAttack(v4, &a4, v18, v25);
-                        goto LABEL_25;
-                        }
+                         switch (v3)
+                         {
+                           case  AIState::AttackingMelee:
+                             v19 = stru_50C198.special_ability_use_check(&pActors[v4], v4);
+                             stru_50FE08.Add( v28->uPackedID,  5120,  v5->vPosition.x, v5->vPosition.y, v5->vPosition.z + ((signed int)v5->uActorHeight >> 1), v19,  1);
+                             Actor::AI_Stand(v4, a2a, 0, &a4);
+                             break;
+                           case AIState::AttackingRanged1:
+                             Actor::AI_RangedAttack(v4, &a4, v5->pMonsterInfo.uMissleAttack1Type, 0);
+                             Actor::AI_Stand(v4, a2a, 0,&a4);
+                             break;
+                           case AIState::Dying:
+                             v5->uCurrentActionTime = 0;
+                             v5->uCurrentActionLength = 0;
+                             v5->uAIState = Dead;
+                             pActors[v4].UpdateAnimation();
+                             break;
+                           case AIState::Stunned:
+                              Actor::AI_Stand(v4, a2a, 0,&a4);
+                              break;
+                           case AIState::AttackingRanged2:
+                             Actor::AI_RangedAttack(v4, &a4, v5->pMonsterInfo.uMissleAttack2Type, 1);
+                             Actor::AI_Stand(v4, a2a, 0,&a4);
+                             break;
+                           case AIState::AttackingRanged3:
+                             Actor::AI_SpellAttack(v4, &a4, v5->pMonsterInfo.uSpell1ID, 2, v5->pMonsterInfo.uSpellSkillAndMastery1);
+                             Actor::AI_Stand(v4, a2a, 0, &a4);
+                             break;
+                           case AIState::AttackingRanged4:
+                             Actor::AI_SpellAttack(v4, &a4, v5->pMonsterInfo.uSpell2ID, 3, v5->pMonsterInfo.uSpellSkillAndMastery2);
+                             Actor::AI_Stand(v4, a2a, 0, &a4);
+                             break;
+                           default:
+                             if ( !(rand() % 2) )
+                               Actor::AI_Bored(v4, a2a, &a4);
+                             else
+                               Actor::AI_Stand(v4, a2a, 64,&a4);
+                         }
                     }
-                }
-            }
         }
+
+        }
+        
     }
 // 50FE08: using guessed type stru298 stru_50FE08;
 
 //----- (0040680F) --------------------------------------------------------
-__int16 stru262_TurnBased::_40680F(int a2)
-    {
+void stru262_TurnBased::_40680F( int a2 )
+        {
     TurnBased_QueueElem *v2; // eax@1
     unsigned int v3; // eax@1
     unsigned int v4; // edi@2
@@ -1132,7 +825,7 @@
     TurnBased_QueueElem *v21; // [sp+4Ch] [bp-4h]@1
     signed int v22; // [sp+58h] [bp+8h]@10
 
-    v2 = (TurnBased_QueueElem *)((char *)this + 16 * (a2 + 2));
+    v2 = &pQueue[a2];
     v21 = v2;
     v2->uActionLength = 0;
     v3 = v2->uPackedID;
@@ -1245,7 +938,7 @@
 LABEL_48:
                         v21->uActionLength = v5->uCurrentActionLength;
                         //return (signed __int16)v3;
-                        return (signed __int16)&v21;
+                        return;
                         }
                     }
 LABEL_44:
@@ -1257,186 +950,109 @@
                     goto LABEL_48;
                     }
 LABEL_47:
-                Actor::AI_Stand(v13, v22, 0x40u, &v18);
+                Actor::AI_Stand(v13, v22, 64, &v18);
                 //v3 = v21;
                 v21->field_C = 0;
                 goto LABEL_48;
                 }
             }
         }
-    return (signed __int16)v3;
     }
 
 //----- (00406A63) --------------------------------------------------------
 void stru262_TurnBased::_406A63()
     {
-    stru262_TurnBased *v1; // ebx@1
-    int v2; // esi@1
-    unsigned __int8 v3; // zf@1
-    unsigned __int8 v4; // sf@1
-    signed int v5; // ecx@4
+  
     AIDirection a3; // [sp+8h] [bp-44h]@5
     AIDirection v7; // [sp+24h] [bp-28h]@5
-    unsigned int v8; // [sp+40h] [bp-Ch]@5
-    signed int a2; // [sp+44h] [bp-8h]@1
-    TurnBased_QueueElem *v10; // [sp+48h] [bp-4h]@2
+    unsigned int target_pid; // [sp+40h] [bp-Ch]@5
+    int i;
 
-    v1 = this;
-    v2 = 0;
     this->field_8 = 64;
     dword_50C994 = 0;
     uActiveCharacter = 0;
-    v3 = this->uActorQueueSize == 0;
-    v4 = this->uActorQueueSize < 0;
-    a2 = 0;
-    if ( !(v4 | v3) )
+    for (i=0; i<uActorQueueSize; ++i )
         {
-        v10 = this->pQueue;
-        while ( 1 )
+        if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
             {
-            v5 = v10->uPackedID;
-            if (PID_TYPE(v10->uPackedID) == OBJECT_Actor)
-                {
-                v8 = ai_near_actors_targets_pid[PID_ID(v5)];
-                memcpy(&v7, Actor::GetDirectionInfo(v5, v8, &a3, 0), sizeof(v7));
-                if ( !v1->ActorTurn(a2) )
-                    Actor::AI_Stand(PID_ID(v10->uPackedID), v8, 32, &v7);
-                }
-            ++a2;
-            ++v10;
-            if ( a2 >= v1->uActorQueueSize )
-                break;
-            v2 = 0;
+            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) )
+                Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
             }
-        }
+        }   
     }
 // 50C994: using guessed type int dword_50C994;
 
 //----- (00406AFE) --------------------------------------------------------
 void stru262_TurnBased::_406AFE()
     {
-    stru262_TurnBased *v1; // edi@1
-    TurnBased_QueueElem *v2; // ebx@2
-    int v3; // esi@4
-    int v4; // ecx@5
     AIDirection a3; // [sp+4h] [bp-48h]@5
-    AIDirection v6; // [sp+20h] [bp-2Ch]@5
-    stru262_TurnBased *v7; // [sp+3Ch] [bp-10h]@1
-    unsigned int v8; // [sp+40h] [bp-Ch]@4
-    unsigned int v9; // [sp+44h] [bp-8h]@5
-    int v10; // [sp+48h] [bp-4h]@1
+    AIDirection v7; // [sp+20h] [bp-2Ch]@5
+    unsigned int target_pid; 
+    int i;
 
-    v10 = 0;
-    v1 = this;
-    v7 = this;
-    if ( this->uActorQueueSize > 0 )
+    for (i=0; i<uActorQueueSize; ++i )
         {
-        v2 = this->pQueue;
-        do
+        if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
             {
-            if (PID_TYPE(v2->uPackedID) == OBJECT_Actor)
-                {
-                v3 = PID_ID(v2->uPackedID);
-                v8 = v3;
-                if ( pActors[v3].CanAct() )
-                    {
-                    v4 = v2->uPackedID;
-                    v9 = ai_near_actors_targets_pid[v3];
-                    memcpy(&v6, Actor::GetDirectionInfo(v4, v9, &a3, 0), sizeof(v6));
-                    Actor::AI_Stand(v8, v9, 32, &v6);
-                    v2->field_C = 0;
-                    v2->uActionLength = 0;
-                    v1 = v7;
-                    }
-                }
-            ++v10;
-            ++v2;
+            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].uActionLength = 0;
             }
-            while ( v10 < v1->uActorQueueSize );
-        }
-    v1->field_4 = 2;
-    v1->field_8 = 100;
+        }   
+    turn_stage = 2;
+    field_8 = 100;
+
     }
 
 //----- (00406B9F) --------------------------------------------------------
-int stru262_TurnBased::_406B9F()
+void stru262_TurnBased::_406B9F()
     {
-    signed int result; // eax@1
-    unsigned __int8 v2; // zf@1
-    unsigned __int8 v3; // sf@1
-    int v4; // esi@4
     unsigned int v5; // esi@5
     Actor *v6; // ebx@5
-    unsigned __int16 v7; // cx@15
     AIDirection a3; // [sp+0h] [bp-50h]@15
     AIDirection v9; // [sp+1Ch] [bp-34h]@15
-    signed int a1; // [sp+38h] [bp-18h]@4
-    stru262_TurnBased *thisa; // [sp+3Ch] [bp-14h]@1
     unsigned int v12; // [sp+40h] [bp-10h]@5
     unsigned int v13; // [sp+44h] [bp-Ch]@8
-    TurnBased_QueueElem *v14; // [sp+48h] [bp-8h]@2
-    signed int a2; // [sp+4Ch] [bp-4h]@1
+    int i;
 
-    result = 0;
-    thisa = this;
-    v2 = this->uActorQueueSize == 0;
-    v3 = this->uActorQueueSize < 0;
-    a2 = 0;
-    if ( !(v3 | v2) )
+    for (i=0; i<uActorQueueSize; ++i )
         {
-        v14 = this->pQueue;
-        while ( 1 )
+        if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
             {
-            v4 = v14->uPackedID;
-            a1 = v14->uPackedID;
-            if (PID_TYPE(a1) != OBJECT_Player)
+            v6 = &pActors[PID_ID(pQueue[i].uPackedID)];
+            if ( !(v6->pActorBuffs[5].uExpireTime > 0|| (v6->pActorBuffs[6].uExpireTime > 0) || 
+                    v6->uAIState == AIState::Dead || v6->uAIState == AIState::Removed || v6->uAIState == AIState::Disabled) )
                 {
-                v5 = PID_ID(v4);
-                v12 = v5;
-                v6 = &pActors[v5];
-                if ( SHIDWORD(v6->pActorBuffs[5].uExpireTime) < result
-                    || SHIDWORD(v6->pActorBuffs[5].uExpireTime) <= result && LODWORD(v6->pActorBuffs[5].uExpireTime) <= result )
-                    v13 = result;
-                else
-                    v13 = 1;
-                if ( SHIDWORD(v6->pActorBuffs[6].uExpireTime) >= result
-                    && (SHIDWORD(v6->pActorBuffs[6].uExpireTime) > result || LODWORD(v6->pActorBuffs[6].uExpireTime) > result) )
-                    result = 1;
-                if ( !(v13 != 0 || result || v6->uAIState == 5 || v6->uAIState == 11 || v6->uAIState == 19) )
+                v13 = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
+                memcpy(&v9, Actor::GetDirectionInfo(pQueue[i].uPackedID, v13, &a3, 0), sizeof(AIDirection));
+                if ( v6->uAIState == AIState::Pursuing || v6->uAIState == AIState::Tethered ) 
                     {
-                    v13 = ai_near_actors_targets_pid[v5];
-                    memcpy(&v9, Actor::GetDirectionInfo(a1, v13, &a3, 0), sizeof(v9));
-                    v7 = v6->uAIState;
-                    if ( v7 == 6 || v7 == 1 )
+                    if ( (double)(signed int)v9.uDistance < 307.2 )
+                        Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
+                    }
+                else
+                    {           
+                    v6->uCurrentActionTime += pEventTimer->uTimeElapsed;
+                    if ( v6->uCurrentActionTime > v6->uCurrentActionLength )
                         {
-                        if ( (double)(signed int)v9.uDistance < 307.2 )
-                            goto LABEL_26;
-                        }
-                    v6->uCurrentActionTime += pEventTimer->uTimeElapsed;
-                    if ( (signed int)v6->uCurrentActionTime > v6->uCurrentActionLength )
-                        {
-                        if ( v7 == 4 )
+                        if ( v6->uAIState == AIState::Dying )
                             {
                             v6->uCurrentActionTime = 0;
                             v6->uCurrentActionLength = 0;
-                            v6->uAIState = Dead;
+                            v6->uAIState = AIState::Dead;
                             v6->UpdateAnimation();
                             }
-                        if ( !thisa->ActorTurn(a2) )
-LABEL_26:
-                        Actor::AI_Stand(v12, v13, 32, &v9);
+                        if ( !ActorTurn(i) )
+                            Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
                         }
                     }
                 }
-            ++a2;
-            result = (signed int)thisa;
-            ++v14;
-            if ( a2 >= thisa->uActorQueueSize )
-                break;
-            result = 0;
             }
         }
-    return result;
     }
 
 //----- (00406D10) --------------------------------------------------------
@@ -1460,10 +1076,6 @@
     TurnBased_QueueElem *v17; // eax@25
     double v18; // st7@33
     double v19; // st6@33
-    int v21; // [sp-8h] [bp-5Ch]@23
-    int v22; // [sp-8h] [bp-5Ch]@26
-    AIDirection *v23; // [sp-4h] [bp-58h]@23
-    int v24; // [sp-4h] [bp-58h]@26
     AIDirection a3; // [sp+Ch] [bp-48h]@10
     AIDirection pDir; // [sp+28h] [bp-2Ch]@10
     int v27; // [sp+44h] [bp-10h]@33
@@ -1473,7 +1085,7 @@
     unsigned int a2a; // [sp+5Ch] [bp+8h]@7
 
     // __debugbreak();//      
-    v2 = *(&this->field_0 + 4 * (a2 + 2));
+    v2 = pQueue[a2].uPackedID;
     if (PID_TYPE(v2) == OBJECT_Player)
         return 0;
     uActorID = PID_ID(v2);
@@ -1692,20 +1304,20 @@
                 uActorID = v4;
                 v5 = &pActors[v4];
                 v6 = v5->uAIState;
-                if ( v6 != 5 )
+                if ( v6 != 5 ) // Dead 
                     {
-                    if ( v6 != 11 )
+                    if ( v6 != 11 )// Removed
                         {
-                        if ( v6 != 19 )
+                        if ( v6 != 19 ) //Disabled 
                             {
-                            if ( v6 != 17 )
+                            if ( v6 != 17 ) //Summoned
                                 {
                                 v7 = (unsigned int *)&ai_near_actors_targets_pid[v4];
                                 a2 = *v7;
                                 v8 = a2;
                                 Actor::_SelectTarget(v4, (int *)v7, true);
-                                memcpy(&v11, Actor::GetDirectionInfo(*(int *)((char *)&v3->uPackedID + v18), v8, &a3, 0), sizeof(v11));
-                                memcpy(&a4, &v11, sizeof(a4));
+                                memcpy(&v11, Actor::GetDirectionInfo(*(int *)((char *)&v3->uPackedID + v18), v8, &a3, 0), sizeof(AIDirection));
+                                memcpy(&a4, &v11, sizeof(AIDirection));
                                 v5->uCurrentActionTime += pMiscTimer->uTimeElapsed;
                                 if ( (signed int)v5->uCurrentActionTime >= v5->uCurrentActionLength )
                                     {
--- a/TurnEngine.h	Thu Jul 11 17:47:12 2013 +0600
+++ b/TurnEngine.h	Thu Jul 11 17:47:33 2013 +0600
@@ -35,7 +35,7 @@
   inline stru262_TurnBased()
   {
     field_0 = 0;
-    field_4 = 0;
+    turn_stage = 0;
     field_8 = 0;
     uActorQueueSize = 0;
     field_10 = 0;
@@ -49,23 +49,23 @@
   void  Start();
   void End(bool bPlaySound);
   void _405E14();
-  __int16 StartTurn();
+  void StartTurn();
   void NextTurn();
   int _4063A1();
-  int _406457(int a2);
+  void _406457(int a2);
   void _40652A();
   void _4065B0();
-  void _406648(unsigned int a2);
-  __int16 _40680F(int a2);
+  void AIRangedAttacks(unsigned int queue_index);
+  void  _40680F(int a2);
   void _406A63();
   void _406AFE();
-  int _406B9F();
+  void  _406B9F();
   bool ActorTurn(signed int a2);
   void _406FA8();
 
 
   int field_0;
-  int field_4;
+  int turn_stage;
   int field_8;
   int uActorQueueSize; //c
   int field_10;
--- a/UI/UiGame.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/UI/UiGame.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -2289,7 +2289,7 @@
         }
     if ( pParty->bTurnBasedModeOn == 1 )
         {
-        if ( pTurnEngine->field_4 != 1 )
+        if ( pTurnEngine->turn_stage != 1 )
             {
             if (PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player)
                 {
--- a/Viewport.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/Viewport.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -467,7 +467,7 @@
         pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v18, 0);
         return;
       }
-      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3 )
+      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3 )
       {
         pTurnEngine->field_18 |= TE_FLAG_8;
         return;
@@ -476,7 +476,7 @@
     }
     else
     {
-      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3 )
+      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3 )
       {
         pParty->uFlags |= PARTY_FLAGS_1_FALLING;
         return;
--- a/mm7_3.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/mm7_3.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -997,7 +997,7 @@
         v8 *= 2;
         v73 = v8;
       }
-      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 1 )
+      if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 1 )
         v8 = (signed __int64)((double)v73 * flt_6BE3AC_debug_recmod1_x_1_6);
       if ( v8 > 1000 )
         v8 = 1000;
@@ -1176,7 +1176,7 @@
       switch ( PID_TYPE(v38) )
       {
         case OBJECT_Actor:
-          if ( pTurnEngine->field_4 != 2 && pTurnEngine->field_4 != 3 || pParty->bTurnBasedModeOn != 1 )
+          if ( pTurnEngine->turn_stage != 2 && pTurnEngine->turn_stage != 3 || pParty->bTurnBasedModeOn != 1 )
           {
 			//if(pParty->bTurnBasedModeOn == 1)
 				//v34 = 0;
@@ -1874,7 +1874,7 @@
     stru_721530.field_24 = pParty->uFallSpeed;
     stru_721530.uSectorID = uSectorID;
     v38 = 0;
-    if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3 )
+    if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3 )
       v38 = 13312;
     if ( stru_721530._47050A(v38) )
       break;
@@ -2778,7 +2778,7 @@
     stru_721530.field_24 = v121;
     v36 = 0;
     stru_721530.uSectorID = 0;
-    if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3 )
+    if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3 )
       v36 = 13312;
     if ( stru_721530._47050A(v36) )
       break;
--- a/mm7_4.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/mm7_4.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -1875,7 +1875,7 @@
     v43 = (signed __int64)v21->pPlayerBuffs[7].uExpireTime > 0;
 
     for (uint k = 0; k < 24; ++k)
-      v21->pPlayerBuffs[k]._4585CA(pParty->uTimePlayed);
+      v21->pPlayerBuffs[k].IsBuffExpiredToTime(pParty->uTimePlayed);
 
     if ( v43 && (signed __int64)v21->pPlayerBuffs[7].uExpireTime <= 0 )
       v21->SetCondition(1u, 0);
@@ -1886,7 +1886,7 @@
 
   for (uint i = 0; i < 20; ++i)
   {
-    if (pParty->pPartyBuffs[i]._4585CA(pParty->uTimePlayed) == 1)
+    if (pParty->pPartyBuffs[i].IsBuffExpiredToTime(pParty->uTimePlayed) == 1)
       viewparams->bRedrawGameUI = 1;
   }
 
--- a/mm7_5.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/mm7_5.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -2427,7 +2427,7 @@
               Actor::StealFrom(uMessageParam);
             continue;
           }
-          if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 3 )
+          if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3 )
             continue;
           if ( !(pTurnEngine->field_18 & TE_FLAG_2) )
           {
@@ -2446,7 +2446,7 @@
             _42ECB5_PlayerAttacksActor();
             continue;
           }
-          if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 3 )
+          if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3 )
             continue;
           if ( !(pTurnEngine->field_18 & TE_FLAG_2) )
             _42ECB5_PlayerAttacksActor();
@@ -2720,7 +2720,7 @@
           pAudioPlayer->PlaySound((SoundID)v127, 0, 0, -1, 0, 0, 0, 0);
           continue;
         case UIMSG_OpenSpellbookPage:
-          if ( pTurnEngine->field_4 == 3 || !uActiveCharacter || uMessageParam == pPlayers[uActiveCharacter]->lastOpenedSpellbookPage )
+          if ( pTurnEngine->turn_stage == 3 || !uActiveCharacter || uMessageParam == pPlayers[uActiveCharacter]->lastOpenedSpellbookPage )
             continue;
           sub_41140B();
           pPlayers[uActiveCharacter]->lastOpenedSpellbookPage = uMessageParam;
@@ -2730,7 +2730,7 @@
           continue;
         case UIMSG_SelectSpell:
         {
-          if (pTurnEngine->field_4 == 3)
+          if (pTurnEngine->turn_stage == 3)
             continue;
           if (!uActiveCharacter)
             continue;
@@ -2768,17 +2768,17 @@
         continue;
 
         case UIMSG_CastSpellFromBook:
-          if ( pTurnEngine->field_4 != 3 )
+          if ( pTurnEngine->turn_stage != 3 )
             _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 0, 0, 0);
         continue;
 
         case UIMSG_SpellScrollUse:
 			__debugbreak();
-          if ( pTurnEngine->field_4 != 3 )
+          if ( pTurnEngine->turn_stage != 3 )
             _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 133, 1, 0);
           continue;
         case UIMSG_SpellBookWindow:
-          if ( pTurnEngine->field_4 == 3 )
+          if ( pTurnEngine->turn_stage == 3 )
             continue;
           if ( bUnderwater == 1 )
           {
--- a/mm7_6.cpp	Thu Jul 11 17:47:12 2013 +0600
+++ b/mm7_6.cpp	Thu Jul 11 17:47:33 2013 +0600
@@ -2919,7 +2919,7 @@
               pPartyActionQueue->Add(partyAction);
               break;
             }
-            if (pTurnEngine->field_4 != 1 && pTurnEngine->field_4 != 2 && pTurnEngine->uActionPointsLeft > 0 )
+            if (pTurnEngine->turn_stage != 1 && pTurnEngine->turn_stage != 2 && pTurnEngine->uActionPointsLeft > 0 )
             {
               pTurnEngine->uActionPointsLeft -= 26;
               if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)
@@ -2942,7 +2942,7 @@
               pPartyActionQueue->Add(partyAction);
               break;
             }
-            if ( pTurnEngine->field_4 != 1 && pTurnEngine->field_4 != 2 && pTurnEngine->uActionPointsLeft > 0 )
+            if ( pTurnEngine->turn_stage != 1 && pTurnEngine->turn_stage != 2 && pTurnEngine->uActionPointsLeft > 0 )
             {
               pTurnEngine->uActionPointsLeft -= 26;
               if ( pParty->uFlags2 & 2 )
@@ -2962,7 +2962,7 @@
               pPartyActionQueue->Add(partyAction);
               break;
             }
-            if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
+            if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 2 || pTurnEngine->uActionPointsLeft <= 0 )
               break;
             pTurnEngine->uActionPointsLeft -= 26;
             partyAction = PARTY_StrafeLeft;
@@ -2977,7 +2977,7 @@
               pPartyActionQueue->Add(partyAction);
               break;
             }
-            if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
+            if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 2 || pTurnEngine->uActionPointsLeft <= 0 )
               break;
             pTurnEngine->uActionPointsLeft -= 26;
             partyAction = PARTY_StrafeRight;
@@ -2990,7 +2990,7 @@
             {
               if (pParty->bTurnBasedModeOn)
               {
-                if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
+                if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 2 || pTurnEngine->uActionPointsLeft <= 0 )
                   break;
                 pTurnEngine->uActionPointsLeft -= 26;
               }
@@ -3016,7 +3016,7 @@
             {
               if (pParty->bTurnBasedModeOn)
               {
-                if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
+                if ( pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 2 || pTurnEngine->uActionPointsLeft <= 0 )
                   break;
                 pTurnEngine->uActionPointsLeft -= 26;
               }
@@ -3051,7 +3051,7 @@
           case INPUT_Pass:
             if ( pCurrentScreen )
               break;
-            if (pParty->bTurnBasedModeOn && pTurnEngine->field_4 == 3)
+            if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == 3)
             {
               pTurnEngine->field_18 |= TE_FLAG_8;
               break;
@@ -3073,7 +3073,7 @@
             {
               if (pParty->bTurnBasedModeOn)
               {
-                if (pTurnEngine->field_4 == 3 || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player)
+                if (pTurnEngine->turn_stage == 3 || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player)
                 {
                   pParty->bTurnBasedModeOn = 0;
                   pTurnEngine->End(true);
@@ -3089,7 +3089,7 @@
           case INPUT_CastReady:
             if (pCurrentScreen != SCREEN_GAME)
               break;
-            if (pParty->bTurnBasedModeOn && pTurnEngine->field_4 == 3)
+            if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == 3)
             {
               pTurnEngine->field_18 |= TE_FLAG_8;
               break;
@@ -3118,7 +3118,7 @@
           case INPUT_Attack:
             if (pCurrentScreen != SCREEN_GAME)
               break;
-            if (pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3)
+            if (pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 3)
             {
               pTurnEngine->field_18 |= TE_FLAG_8;
               break;