diff TurnEngine.cpp @ 1333:d14bc530cddb

turnengine refactor continue
author Gloval
date Fri, 05 Jul 2013 08:51:37 +0400
parents 1e35cfed7928
children 22cb507446a4
line wrap: on
line diff
--- a/TurnEngine.cpp	Fri Jul 05 01:46:44 2013 +0400
+++ b/TurnEngine.cpp	Fri Jul 05 08:51:37 2013 +0400
@@ -909,86 +909,61 @@
 
 //----- (0040652A) --------------------------------------------------------
 void stru262_TurnBased::_40652A()
-    {
-    int *v1; // edx@2
-    Actor *v2; // eax@5
-    unsigned __int16 v3; // si@5
-    unsigned int v4; // esi@8
-    int v5; // [sp+Ch] [bp-4h]@1
+{
+    int i;
+    int monster_ai_state;
+    Actor *monster; // eax@5
 
-    v5 = 0;
-    if ( this->uActorQueueSize > 0 )
+    for (i=0; i<uActorQueueSize; ++i )
         {
-        v1 = &this->pQueue[0].field_4;
-        do
+        if (pQueue[i].field_4 == 0)
             {
-            if ( !*(int *)v1 )
+            if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) 
+                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 ( PID_TYPE(*(v1 - 4)) == OBJECT_Player)
-                    return;
-                v2 = &pActors[PID_ID(*(v1 - 1))];
-                v3 = v2->uAIState;
-                if (v3 == Standing || v3 == Fleeing || v3 == Fidgeting)
-                    {
-                    v4 = pMonsterStats->pInfos[v2->pMonsterInfo.uID].uRecoveryTime;
-                    *(int *)v1 = v4;
-                    if ( (signed __int64)v2->pActorBuffs[7].uExpireTime > 0 )
-                        *(int *)v1 = 2 * v4;
-                    }
+                pQueue[i].field_4 == pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
+                if (monster->pActorBuffs[7].uExpireTime > 0)
+                    pQueue[i].field_4*=2;
+
                 }
-            ++v5;
-            v1 += 16;
             }
-            while ( v5 < this->uActorQueueSize );
         }
-    }
+}
 
 //----- (004065B0) --------------------------------------------------------
 void stru262_TurnBased::_4065B0()
-    {
-    stru262_TurnBased *v1; // esi@1
-    signed int v2; // eax@1
-    int v3; // ebx@6
-    int v4; // edi@7
-    unsigned int v5; // edi@14
+{
+    int i;
 
-    v1 = this;
     SortTurnQueue();
-    if ( v1->pQueue[0].field_4 <= 0
-        || ((_4063A1(), v2 = v1->pQueue[0].uPackedID, PID_TYPE(v1->pQueue[0].uPackedID) != OBJECT_Player) ? 
-        (uActiveCharacter = 0) : (v2 = (PID_ID(v2)) + 1, uActiveCharacter = v2),
-        viewparams->bRedrawGameUI = 1,
-        v1->pQueue[0].field_4 <= 0) )
-        {
-        v3 = 0;
-        if ( v1->uActorQueueSize > 0 )
+    if (pQueue[0].field_4 <= 0)
+        {  
+        for (i=0; i<uActorQueueSize; ++i )
             {
-            v4 = (int)v1->pQueue;
-            do
-                {
-                v2 = *(int *)v4;
-                if ( PID_TYPE(*(char *)v4) == OBJECT_Player || *(int *)(v4 + 4) > 0 )
-                    break;
-                if ( *(int *)(v4 + 8) <= 0 )
-                    {
-                    LOWORD(v2) = v2 & 3;
-                    if ( (char)v2 == 3 )
-                        LOWORD(v2) = v1->_40680F(v3);
-                    }
-                ++v3;
-                v4 += 16;
-                }
-                while ( v3 < v1->uActorQueueSize );
+            if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)|| (pQueue[i].field_4 > 0) )
+                break;
+            if ((pQueue[i].uActionLength<=0) && (PID_TYPE(pQueue[i].uPackedID)==OBJECT_Actor))
+                _40680F(i);
             }
         }
-    v5 = 0;
-    if ( v1->uActorQueueSize > 0 )
+    else
         {
-        do
-        v1->_406648(v5++);
-        while ( (signed int)v5 < v1->uActorQueueSize );
+        _4063A1();
+        if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) 
+            uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
+        else
+            uActiveCharacter = 0;
+        viewparams->bRedrawGameUI = 1;
         }
-    }
+
+    for (i=0; i<uActorQueueSize; ++i )
+        _406648(i);
+}
 
 //----- (00406648) --------------------------------------------------------
 void stru262_TurnBased::_406648(unsigned int a2)
@@ -1323,7 +1298,7 @@
             if (PID_TYPE(v10->uPackedID) == OBJECT_Actor)
                 {
                 v8 = ai_near_actors_targets_pid[PID_ID(v5)];
-                memcpy(&v7, Actor::GetDirectionInfo(v5, v8, &a3, v2), sizeof(v7));
+                memcpy(&v7, Actor::GetDirectionInfo(v5, v8, &a3, 0), sizeof(v7));
                 if ( !v1->ActorTurn(a2) )
                     Actor::AI_Stand(PID_ID(v10->uPackedID), v8, 32, &v7);
                 }