changeset 1342:bdf0cc8620ad

TE continue
author Gloval
date Mon, 08 Jul 2013 01:04:42 +0400
parents 67e47fc3133d
children f0b95fb02b83
files TurnEngine.cpp TurnEngine.h
diffstat 2 files changed, 119 insertions(+), 234 deletions(-) [+]
line wrap: on
line diff
--- a/TurnEngine.cpp	Sat Jul 06 23:00:24 2013 +0400
+++ b/TurnEngine.cpp	Mon Jul 08 01:04:42 2013 +0400
@@ -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)
@@ -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);
@@ -244,7 +214,6 @@
         this->pQueue[v40b].field_4 += 16;
         }
 
-
     if ( a_players_count > 0 )
         {
         for (i=0; i<a_players_count; ++i)
@@ -362,14 +331,14 @@
                 memcpy(&v15, v6, sizeof(AIDirection));   
                 memcpy(&v14, &v15, sizeof(AIDirection));
                 v7 = curr_actor->uAIState;
-                if(v7==Dying)
+                if(v7==AIState::Dying)
                     {
                     curr_actor->uCurrentActionTime = 0;
                     curr_actor->uCurrentActionLength = 0;
                     curr_actor->uAIState = Dead;
                     curr_actor->UpdateAnimation();
                     }
-                else  if ( (v7 > Removed)&&(v7 < Disabled))
+                else  if ( (v7 > AIState::Removed)&&(v7 < AIState::Disabled))
                     {
                      Actor::AI_StandOrBored(i, target_pid, 32, &v14);
                     }
@@ -393,7 +362,6 @@
                 field_10 = 100;
                 }
         field_8 -= pEventTimer->uTimeElapsed;
-
         }
     else if ( turn_stage == 2 )
         {
@@ -412,7 +380,6 @@
             }
         else
             NextTurn();
-
         }
     else if ( turn_stage == 3 )
         {
@@ -529,9 +496,9 @@
                  {
                  curr_actor = &pActors[PID_ID(pQueue[i].uPackedID)];
                  ai_state = curr_actor->uAIState;
-                 if ( (ai_state == Dying) || (ai_state == Stunned) || (ai_state == AttackingMelee) ||
-                     (ai_state == AttackingRanged1) || (ai_state == AttackingRanged2) || 
-                     (ai_state == AttackingRanged3) || (ai_state == AttackingRanged4) || (ai_state ==Summoned))
+                 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 )
@@ -540,7 +507,7 @@
                          }
                      else if ( ai_state == 4 )// Dying
                          {
-                         curr_actor->uAIState = Dead;
+                         curr_actor->uAIState = AIState::Dead;
                          curr_actor->uCurrentActionTime = 0;
                          curr_actor->uCurrentActionLength = 0;
                          curr_actor->UpdateAnimation();
@@ -567,11 +534,11 @@
              {
              monster=PID_ID(pQueue[i].uPackedID);
              monster_ai_state=pActors[monster].uAIState;
-             if ((monster_ai_state != Dead) && 
-                 (monster_ai_state != Dying) &&
-                 (monster_ai_state != Removed) &&
-                 (monster_ai_state != Summoned) &&
-                 (monster_ai_state != Disabled))
+             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);
@@ -584,93 +551,54 @@
      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 )|| ( 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) --------------------------------------------------------
 void stru262_TurnBased::_406457( int a2 )
@@ -738,9 +666,9 @@
                 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;
                 if (monster->pActorBuffs[7].uExpireTime > 0)
@@ -777,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
@@ -811,7 +739,7 @@
     TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1
     unsigned int a2a; // [sp+50h] [bp+8h]@2
 
-    v1 = &pQueue[a2];
+    v1 = &pQueue[queue_index];
     v28 = v1;
     v3 = v1->uPackedID;
     if (PID_TYPE(v1->uPackedID) != OBJECT_Player)
@@ -822,65 +750,60 @@
         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,
+                            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;
+                                v19,  1);
+                            Actor::AI_Stand(v4, a2a, 0,&a4);
+                            return;
                             }
                         v9 = v8 - 1;
                         if ( v9 )
                             {
                             v10 = v9 - 1;
                             if ( !v10 )
-                                goto LABEL_21;
+                                {
+                                v5->uCurrentActionTime = 0;
+                                v5->uCurrentActionLength = 0;
+                                v5->uAIState = Dead;
+                                pActors[v4].UpdateAnimation();
+                                return;
+                                }
                             v11 = v10 - 4;
                             if ( !v11 )
-                                goto LABEL_25;
+                                {
+                                Actor::AI_Stand(v4, a2a, 0,&a4);
+                                return;
+                                }
                             v12 = v11 - 4;
                             if ( v12 )
                                 {
                                 v13 = v12 - 1;
                                 if ( v13 )
                                     {
-                                    if ( v13 != Dead )
+                                    if ( v13 != 5 )
                                         {
                                         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);
+                                            Actor::AI_Stand(v4, a2a, 64,&a4);
                                             return;
                                             }
-LABEL_21:
                                         v5->uCurrentActionTime = 0;
                                         v5->uCurrentActionLength = 0;
                                         v5->uAIState = Dead;
@@ -898,12 +821,8 @@
                                     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;
+                                Actor::AI_Stand(v4, a2a, 0, &a4);
+                                return;
                                 }
                             v18 = v5->pMonsterInfo.uMissleAttack2Type;
                             v25 = 1;
@@ -914,18 +833,19 @@
                             v25 = 0;
                             }
                         Actor::AI_RangedAttack(v4, &a4, v18, v25);
-                        goto LABEL_25;
+                        Actor::AI_Stand(v4, a2a, 0,&a4);
+                        return;
                         }
                     }
-                }
-            }
+                
         }
+        
     }
 // 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
@@ -1060,7 +980,7 @@
 LABEL_48:
                         v21->uActionLength = v5->uCurrentActionLength;
                         //return (signed __int16)v3;
-                        return (signed __int16)&v21;
+                        return;
                         }
                     }
 LABEL_44:
@@ -1079,7 +999,6 @@
                 }
             }
         }
-    return (signed __int16)v3;
     }
 
 //----- (00406A63) --------------------------------------------------------
@@ -1132,84 +1051,50 @@
     }
 
 //----- (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) --------------------------------------------------------
--- a/TurnEngine.h	Sat Jul 06 23:00:24 2013 +0400
+++ b/TurnEngine.h	Mon Jul 08 01:04:42 2013 +0400
@@ -55,11 +55,11 @@
   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();