Mercurial > mm7
changeset 1341:67e47fc3133d
TE refactiring continue
author | Gloval |
---|---|
date | Sat, 06 Jul 2013 23:00:24 +0400 |
parents | 22cb507446a4 |
children | bdf0cc8620ad |
files | TurnEngine.cpp TurnEngine.h |
diffstat | 2 files changed, 141 insertions(+), 255 deletions(-) [+] |
line wrap: on
line diff
--- a/TurnEngine.cpp Sat Jul 06 00:29:29 2013 +0400 +++ b/TurnEngine.cpp Sat Jul 06 23:00:24 2013 +0400 @@ -431,270 +431,158 @@ //----- (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 == Dying) || (ai_state == Stunned) || (ai_state == AttackingMelee) || + (ai_state == AttackingRanged1) || (ai_state == AttackingRanged2) || + (ai_state == AttackingRanged3) || (ai_state == AttackingRanged4) || (ai_state ==Summoned)) + { + curr_actor->uCurrentActionTime += pEventTimer->uTimeElapsed; + if ( curr_actor->uCurrentActionTime < curr_actor->uCurrentActionLength ) + { + v13 = 1; + } + else if ( ai_state == 4 )// Dying + { + curr_actor->uAIState = 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->turn_stage = 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 != Dead) && + (monster_ai_state != Dying) && + (monster_ai_state != Removed) && + (monster_ai_state != Summoned) && + (monster_ai_state != 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() @@ -755,9 +643,7 @@ do { v9 = v8->uAIState; - if ( v9 == 5 ) - break; - if ( v9 == 4 || v9 == 19 || v9 == 11 ) + if (( v9 == 5 )|| ( v9 == 4 || v9 == 19 || v9 == 11 )) break; v10 = 0; if ( v1->uActorQueueSize > 0 ) @@ -856,7 +742,7 @@ monster_ai_state == Fleeing || monster_ai_state == 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; } @@ -925,7 +811,7 @@ 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[a2]; v28 = v1; v3 = v1->uPackedID; if (PID_TYPE(v1->uPackedID) != OBJECT_Player) @@ -1061,7 +947,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; @@ -1356,7 +1242,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);