changeset 1373:87155494292c

Слияние
author Ritor1
date Mon, 15 Jul 2013 17:09:48 +0600
parents 5572e7b02f45 (current diff) 6b4a1c44a56f (diff)
children 270134611caf 78671379d8da
files
diffstat 2 files changed, 115 insertions(+), 176 deletions(-) [+]
line wrap: on
line diff
--- a/TurnEngine.cpp	Mon Jul 15 17:09:22 2013 +0600
+++ b/TurnEngine.cpp	Mon Jul 15 17:09:48 2013 +0600
@@ -802,16 +802,16 @@
 // 50FE08: using guessed type stru298 stru_50FE08;
 
 //----- (0040680F) --------------------------------------------------------
-void stru262_TurnBased::_40680F( int a2 )
-        {
+void stru262_TurnBased::_40680F( int queue_index )
+    {
     TurnBased_QueueElem *v2; // eax@1
     unsigned int v3; // eax@1
-    unsigned int v4; // edi@2
+    unsigned int actor_id; // edi@2
     Actor *v5; // ebx@2
     unsigned int *v6; // esi@7
     AIDirection *v7; // esi@10
     int v8; // eax@10
-    unsigned int v9; // ecx@10
+    int v9; // ecx@10
     signed int v10; // eax@13
     unsigned __int8 v11; // sf@19
     unsigned __int8 v12; // of@19
@@ -821,141 +821,121 @@
     AIDirection a3; // [sp+Ch] [bp-44h]@10
     AIDirection v18; // [sp+28h] [bp-28h]@10
     int a2a; // [sp+44h] [bp-Ch]@2
-    unsigned int v20; // [sp+48h] [bp-8h]@10
+    int v20; // [sp+48h] [bp-8h]@10
     TurnBased_QueueElem *v21; // [sp+4Ch] [bp-4h]@1
     signed int v22; // [sp+58h] [bp+8h]@10
 
-    v2 = &pQueue[a2];
+    v2 = &pQueue[queue_index];
     v21 = v2;
     v2->uActionLength = 0;
     v3 = v2->uPackedID;
-    if ( (unsigned __int8)v3 & 3 )
+     if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor)
         {
-        v3 = PID_ID(v3);
-        v4 = v3;
+   
+        actor_id = PID_ID(pQueue[queue_index].uPackedID);
         a2a = v3;
-        v5 = &pActors[v3];
-        LOWORD(v3) = v5->uAIState;
-        if ( (short)v3 != 5 )
+        v5 = &pActors[actor_id];
+        v3 = v5->uAIState;
+        if (!(v3 == AIState::Dying || v3 == AIState::Dead ||  v3 == AIState::Summoned ||
+            v3 == AIState::Disabled || v3 == AIState::Removed))
             {
-            if ( (short)v3 != 4 && (short)v3 != 11 && (short)v3 != 19 && (short)v3 != 17 )
-                {
-                v6 = (unsigned int *)&ai_near_actors_targets_pid[(int)v4];
-                Actor::_SelectTarget((unsigned int)v4, &ai_near_actors_targets_pid[(int)v4], true);
-                if ( v5->pMonsterInfo.uHostilityType && !*v6 )
+                
+                Actor::_SelectTarget(actor_id, &ai_near_actors_targets_pid[actor_id], true);
+                v22 = ai_near_actors_targets_pid[actor_id];
+                if ( v5->pMonsterInfo.uHostilityType && !v22)
                     v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
-                v22 = *v6;
-                v7 = Actor::GetDirectionInfo(PID(OBJECT_Actor,(int)v4), *v6, &a3, 0);
+                v7 = Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v22, &a3, 0);
                 v8 = v5->uActorRadius;
-                memcpy(&a3, v7, sizeof(a3));
-                memcpy(&v18, &a3, sizeof(v18));
+                memcpy(&a3, v7, sizeof(AIDirection));
+                memcpy(&v18, &a3, sizeof(AIDirection));
                 v9 = a3.uDistance - v8;
                 v20 = a3.uDistance - v8;
-                if ( ((a3.uDistance - v8) & 0x80000000u) != 0 )
+                if ( v20 < 0 )
                     {
                     v9 = 0;
                     v20 = 0;
                     }
+
                 if (PID_TYPE(v22) == OBJECT_Actor)
                     //v10 = (unsigned __int8)*(&byte_5C8D1A[89 * (pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID - 1) / 3] + (v5->pMonsterInfo.uID - 1) / 3);
                     v10 = pFactionTable->relations[(pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID) / 3 + 1][(v5->pMonsterInfo.uID - 1) / 3 + 1];
                 else
                     v10 = 4;
-                if ( v10 == 1 )
-                    {
+
+               switch (v10)
+                   {
+               case 1:
                     if ( (double)(signed int)v20 < 307.2 )
-                        goto LABEL_25;
-                    }
-                else
+                        v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+                   break;
+               case 2:
+                   if ( v20 < 1024 )
+                       v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+                   break;
+               case 3:
+                   if ( v20 < 2560 )
+                       v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+                   break;
+               case 4:
+                   if ( v20 < 5120 )
+                       v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+                   break;
+                   }
+                
+                if ( v5->pMonsterInfo.uHostilityType == 4 && v22 && (signed int)v9 < 5120 )
                     {
-                    if ( v10 == 2 )
+                    v14 = stru_50C198.special_ability_use_check(v5, actor_id);
+                    v21->field_C = 0;
+                    switch (v14)
                         {
-                        v12 = __OFSUB__(v9, 1024);
-                        v11 = ((v9 - 1024) & 0x80000000u) != 0;
+                    case 1:
+                        if ( v5->pMonsterInfo.uMissleAttack2Type )
+                            {
+                            Actor::AI_MissileAttack2(actor_id, v22, &v18);
+                            v21->field_C = 1;
+                            }   
+                        break;
+                    case 2:
+                        if(v5->pMonsterInfo.uSpell1ID)
+                            {
+                             Actor::AI_SpellAttack1(actor_id, v22, &v18);
+                            v21->field_C = 1;
+                            }        
+                        break;
+                    case 3:
+                        if(v5->pMonsterInfo.uSpell2ID)
+                            {
+                            Actor::AI_SpellAttack2(actor_id, v22, &v18);
+                            v21->field_C = 1;
+                            }
+                            
+                        break;
+                    default:
+                        if ( v5->pMonsterInfo.uMissleAttack1Type )
+                            {
+                            Actor::AI_MissileAttack1(actor_id, v22, &v18);
+                            v21->field_C = 1;
+                            }
                         }
-                    else
-                        {
-                        if ( v10 == 3 )
+                     if (!v21->field_C)
+                        if ( (double)v20 < 307.2)
                             {
-                            v12 = __OFSUB__(v9, 2560);
-                            v11 = ((v9 - 2560) & 0x80000000u) != 0;
+                            Actor::AI_MeleeAttack(actor_id, v22, &v18);
+                            v21->field_C = 3;
                             }
                         else
                             {
-                            if ( v10 != 4 )
-                                goto LABEL_26;
-                            v12 = __OFSUB__(v9, 5120);
-                            v11 = ((v9 - 5120) & 0x80000000u) != 0;
-                            }
-                        }
-                    if ( v11 ^ v12 )
-                        {
-LABEL_25:
-                        v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
-                        goto LABEL_26;
-                        }
-                    }
-LABEL_26:
-                if ( v5->pMonsterInfo.uHostilityType != 4 || !v22 || (signed int)v9 >= 5120 )
-                    {
-                    v13 = a2a;
-                    goto LABEL_47;
-                    }
-                v13 = a2a;
-                v14 = stru_50C198.special_ability_use_check(v5, a2a);
-                if ( v14 == 1 )
-                    {
-                    if ( v5->pMonsterInfo.uMissleAttack2Type )
-                        {
-                        Actor::AI_MissileAttack2(v13, v22, &v18);
-                        goto LABEL_43;
-                        }
-                    }
+                            Actor::AI_Stand(actor_id, v22, 64, &v18);
+                            v21->field_C = 0;
+                            }             
+            }
                 else
                     {
-                    if ( v14 > 1 && v14 <= 3 )
-                        {
-                        if ( v14 == 2 )
-                            v15 = v5->pMonsterInfo.uSpell1ID;
-                        else
-                            v15 = v5->pMonsterInfo.uSpell2ID;
-                        if ( v15 )
-                            {
-                            if ( v14 == 2 )
-                                Actor::AI_SpellAttack1(v13, v22, &v18);
-                            else
-                                Actor::AI_SpellAttack2(v13, v22, &v18);
-                            goto LABEL_43;
-                            }
-                        goto LABEL_44;
-                        }
-                    if ( v5->pMonsterInfo.uMissleAttack1Type )
-                        {
-                        Actor::AI_MissileAttack1(v13, v22, &v18);
-LABEL_43:
-                        //v3 = v21;
-                        v21->field_C = 1;
-LABEL_48:
-                        v21->uActionLength = v5->uCurrentActionLength;
-                        //return (signed __int16)v3;
-                        return;
-                        }
+                    Actor::AI_Stand(actor_id, v22, 64, &v18);
+                    v21->field_C = 0;
                     }
-LABEL_44:
-                if ( (double)(signed int)v20 < 307.2 )
-                    {
-                    Actor::AI_MeleeAttack(v13, v22, &v18);
-                    //v3 = v21;
-                    v21->field_C = 3;
-                    goto LABEL_48;
-                    }
-LABEL_47:
-                Actor::AI_Stand(v13, v22, 64, &v18);
-                //v3 = v21;
-                v21->field_C = 0;
-                goto LABEL_48;
-                }
-            }
+               v21->uActionLength = v5->uCurrentActionLength;
+        }
         }
     }
 
@@ -1011,11 +991,9 @@
 //----- (00406B9F) --------------------------------------------------------
 void stru262_TurnBased::_406B9F()
     {
-    unsigned int v5; // esi@5
     Actor *v6; // ebx@5
     AIDirection a3; // [sp+0h] [bp-50h]@15
     AIDirection v9; // [sp+1Ch] [bp-34h]@15
-    unsigned int v12; // [sp+40h] [bp-10h]@5
     unsigned int v13; // [sp+44h] [bp-Ch]@8
     int i;
 
@@ -1265,87 +1243,48 @@
     return 1;
     }
 
-//----- (00406FA8) --------------------------------------------------------
+    //----- (00406FA8) --------------------------------------------------------
 void stru262_TurnBased::_406FA8()
     {
-    unsigned __int8 v1; // zf@1
-    unsigned __int8 v2; // sf@1
-    TurnBased_QueueElem *v3; // edi@2
-    int v4; // eax@4
-    Actor *v5; // ebx@4
-    unsigned __int16 v6; // cx@4
-    unsigned int *v7; // edx@8
-    unsigned int v8; // esi@8
-    unsigned __int8 v9; // of@13
+    Actor *curr_acror; // ebx@4
     AIDirection a3; // [sp+Ch] [bp-6Ch]@8
-    AIDirection v11; // [sp+28h] [bp-50h]@8
+    AIDirection v9; // [sp+28h] [bp-50h]@8
     AIDirection a4; // [sp+44h] [bp-34h]@8
-    stru262_TurnBased *v13; // [sp+60h] [bp-18h]@1
-    TurnBased_QueueElem *v14; // [sp+64h] [bp-14h]@2
+    unsigned int target_pid; // [sp+60h] [bp-18h]@1
     int uActorID; // [sp+68h] [bp-10h]@4
-    unsigned int a2; // [sp+6Ch] [bp-Ch]@8
-    int v17; // [sp+70h] [bp-8h]@1
-    unsigned int v18; // [sp+74h] [bp-4h]@2
+    int i;
 
-    v17 = 0;
-    v1 = this->uActorQueueSize == 0;
-    v2 = this->uActorQueueSize < 0;
-    v13 = this;
-    if ( !(v2 | v1) )
+    for (i=0; i<uActorQueueSize; ++i )
         {
-        v3 = this->pQueue;
-        v18 = (char *)&pTurnEngine - (char *)this;
-        v14 = this->pQueue;
-        do
+        if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
             {
-            if (PID_TYPE(v3->uPackedID) != OBJECT_Player)
-                {
-                v4 = PID_ID(v3->uPackedID);
-                uActorID = v4;
-                v5 = &pActors[v4];
-                v6 = v5->uAIState;
-                if ( v6 != 5 ) // Dead 
+            uActorID=PID_ID(pQueue[i].uPackedID);
+            curr_acror = &pActors[uActorID];
+            if ( !( curr_acror->uAIState == AIState::Summoned|| curr_acror->uAIState == AIState::Dead ||
+                    curr_acror->uAIState == AIState::Removed || curr_acror->uAIState == AIState::Disabled) )
+                { 
+                target_pid = ai_near_actors_targets_pid[uActorID];      
+                Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);  
+                memcpy(&v9, Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &a3, 0), sizeof(AIDirection));
+                memcpy(&a4, &v9, sizeof(AIDirection));     
+                curr_acror->uCurrentActionTime += pEventTimer->uTimeElapsed;
+                if ( curr_acror->uCurrentActionTime > curr_acror->uCurrentActionLength )
                     {
-                    if ( v6 != 11 )// Removed
+                    if ( curr_acror->uAIState == AIState::Dying )
                         {
-                        if ( v6 != 19 ) //Disabled 
-                            {
-                            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(AIDirection));
-                                memcpy(&a4, &v11, sizeof(AIDirection));
-                                v5->uCurrentActionTime += pMiscTimer->uTimeElapsed;
-                                if ( (signed int)v5->uCurrentActionTime >= v5->uCurrentActionLength )
-                                    {
-                                    if (v5->uAIState == Dying)
-                                        {
-                                        v5->uCurrentActionTime = 0;
-                                        v5->uCurrentActionLength = 0;
-                                        v5->uAIState = Dead;
-                                        v5->UpdateAnimation();
-                                        return;
-                                        }
-                                    if ( rand() % 2 )
-                                        Actor::AI_Stand(uActorID, a2, 64, &a4);
-                                    else
-                                        Actor::AI_Bored(uActorID, a2, &a4);
-                                    }
-                                }
-                            }
+                        curr_acror->uCurrentActionTime = 0;
+                        curr_acror->uCurrentActionLength = 0;
+                        curr_acror->uAIState = AIState::Dead;
+                        curr_acror->UpdateAnimation();
+                        break;
                         }
+                    if ( rand() % 2 )
+                        Actor::AI_Stand(uActorID, target_pid, 64, &a4);
+                    else
+                        Actor::AI_Bored(uActorID, target_pid, &a4);
                     }
                 }
-            ++v17;
-            v3 = v14 + 1;
-            v9 = __OFSUB__(v17, v13->uActorQueueSize);
-            v2 = v17 - v13->uActorQueueSize < 0;
-            ++v14;
             }
-            while ( v2 ^ v9 );
         }
     }
 
--- a/TurnEngine.h	Mon Jul 15 17:09:22 2013 +0600
+++ b/TurnEngine.h	Mon Jul 15 17:09:48 2013 +0600
@@ -56,7 +56,7 @@
   void _40652A();
   void _4065B0();
   void AIRangedAttacks(unsigned int queue_index);
-  void  _40680F(int a2);
+  void _40680F(int queue_index);
   void _406A63();
   void _406AFE();
   void  _406B9F();