Mercurial > mm7
diff TurnEngine.cpp @ 1448:5a5d0c713d47
some turn engine renaming
author | Gloval |
---|---|
date | Tue, 06 Aug 2013 00:52:46 +0400 |
parents | e33188605eeb |
children | 8ff3c675a726 |
line wrap: on
line diff
--- a/TurnEngine.cpp Mon Jul 15 08:20:28 2013 +0400 +++ b/TurnEngine.cpp Tue Aug 06 00:52:46 2013 +0400 @@ -44,7 +44,7 @@ if ( !pActors[p_id].CanAct() ) { --active_actors; - pQueue[i].field_4 = 1001; + pQueue[i].actor_initiative = 1001; pActors[p_id].uAttributes &= ~0x80; } } @@ -53,7 +53,7 @@ if ( !pParty->pPlayers[p_id].CanAct() ) { --active_actors; - pQueue[i].field_4 = 1001; + pQueue[i].actor_initiative = 1001; } } } @@ -66,8 +66,8 @@ for(j=i+1; j<uActorQueueSize;++j ) { v8=&pQueue[j]; - if ( v8->field_4 < v7->field_4 || - ((v8->field_4 == v7->field_4) && + if ( v8->actor_initiative < v7->actor_initiative || + ((v8->actor_initiative == v7->actor_initiative) && ( ((PID_TYPE(v8->uPackedID) == OBJECT_Player) && (PID_TYPE(v7->uPackedID) == OBJECT_Actor)) || ((PID_TYPE(v8->uPackedID) == PID_TYPE(v7->uPackedID)) && (PID_ID(v8->uPackedID) < PID_ID(v7->uPackedID))) @@ -96,14 +96,14 @@ for(i=0; i<uActorQueueSize; ++i) { if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) - pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (signed __int64)((double)pQueue[i].field_4 * 0.46875); + pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (signed __int64)((double)pQueue[i].actor_initiative * 0.46875); } } //----- (0040471C) -------------------------------------------------------- -void stru262_TurnBased::_40471C() +void stru262_TurnBased::ApplyPlayerAction() { if ( pParty->bTurnBasedModeOn == 1 ) { @@ -141,9 +141,9 @@ dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength; dword_50C994 = 0; - this->field_10 = 100; - this->field_0 = 0; - this->field_8 = 64; + this->turn_initiative = 100; + this->turns_count = 0; + this->ai_turn_timer = 64; this->turn_stage = 1; this->uActorQueueSize = 0; @@ -191,7 +191,7 @@ { //v33 = pPlayers[(this->pQueue[0].uPackedID >> 3) + 1]->uTimeToRecovery; v16 = (signed int)((double)pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery * 0.46875); - this->pQueue[v40b].field_4 = v16; + this->pQueue[v40b].actor_initiative = v16; } else { @@ -203,15 +203,15 @@ { v17 = rand() % 99; if ( v17 < 33 ) - this->pQueue[v40b].field_4 = 1; + this->pQueue[v40b].actor_initiative = 1; else - this->pQueue[v40b].field_4= (v17 >= 66)? 5 : 3; + this->pQueue[v40b].actor_initiative= (v17 >= 66)? 5 : 3; } else { - this->pQueue[v40b].field_4 = 666; + this->pQueue[v40b].actor_initiative = 666; } - this->pQueue[v40b].field_4 += 16; + this->pQueue[v40b].actor_initiative += 16; } if ( a_players_count > 0 ) @@ -238,7 +238,7 @@ for (i=0; i<a_players_count; ++i) { - this->pQueue[activ_players[i]].field_4 = i+2; + this->pQueue[activ_players[i]].actor_initiative = i+2; } } this->SortTurnQueue(); @@ -274,11 +274,11 @@ objID = PID_ID(pQueue[i].uPackedID); if ( objType == OBJECT_Player ) { - pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)pQueue[i].field_4 * 2.133333333333333); + pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)pQueue[i].actor_initiative * 2.133333333333333); } else if ( objType == OBJECT_Actor ) { - pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)pQueue[i].field_4 * 2.133333333333333); + pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)pQueue[i].actor_initiative * 2.133333333333333); } } @@ -294,7 +294,7 @@ // 50C998: using guessed type int dword_50C998_turnbased_icon_1A; //----- (00405E14) -------------------------------------------------------- -void stru262_TurnBased::_405E14() +void stru262_TurnBased::AITurnBasedAction() { AIDirection *v6; // esi@21 int v7; // eax@21 @@ -348,50 +348,51 @@ if ( turn_stage == 1 ) { - if ( field_8 == 64 ) + if ( ai_turn_timer == 64 ) { - _406A63(); + ActorAIDoMainAction(); } - else if ( field_8 > 0 ) + else if ( ai_turn_timer > 0 ) { - _406B9F(); + ActorAIDoAdditionAction(); } else { - _406AFE(); - field_10 = 100; + ActorAISetLastAction(); + turn_initiative = 100; } - field_8 -= pEventTimer->uTimeElapsed; + ai_turn_timer -= pEventTimer->uTimeElapsed; } else if ( turn_stage == 2 ) { - if ( !(field_18 & TE_FLAG_1) ) + if ( field_18 == TE_FLAG_1) { - if ( field_10 == 100 ) + if ( turn_initiative == 100 ) { StartTurn(); - _40652A(); + SetAIRecoveryTimes(); + return; } - if ( field_10 > 0 || pQueue[0].field_4 <= 0 ) + if ( turn_initiative > 0 || pQueue[0].actor_initiative <= 0 ) { _4065B0(); - _40652A(); + SetAIRecoveryTimes(); } } - else NextTurn(); } else if ( turn_stage == 3 ) { - if ( uActionPointsLeft <= 0 || field_18 & TE_FLAG_8 ) + if ( (uActionPointsLeft > 0) && (field_18 == TE_FLAG_8) ) { - field_18 &= ~TE_FLAG_8; - turn_stage = 1; - field_8 = 64; + _406FA8(); } else - { - _406FA8(); + { + field_18 &= ~TE_FLAG_8; + turn_stage = 1; + ai_turn_timer = 64; + } } } @@ -416,7 +417,7 @@ if (j==uActorQueueSize ) { pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num); - pQueue[uActorQueueSize].field_4 = 100; + pQueue[uActorQueueSize].actor_initiative = 100; pQueue[uActorQueueSize].uActionLength = 0; pQueue[uActorQueueSize].field_C = 0; ++uActorQueueSize; @@ -434,29 +435,29 @@ if (j==uActorQueueSize ) { pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]); - pQueue[uActorQueueSize].field_4 = 1; + pQueue[uActorQueueSize].actor_initiative = 1; pQueue[uActorQueueSize].uActionLength = 0; pQueue[uActorQueueSize].field_C = 0; ++uActorQueueSize; } } - ++field_0; - field_10 = 100; + ++turns_count; + turn_initiative = 100; - for(i=0; i<uActorQueueSize; ++i) - { - if (pQueue[i].field_4 == 0 ) - pQueue[i].field_4 = 100; - } + for(i=0; i<uActorQueueSize; ++i) + { + if (pQueue[i].actor_initiative == 0 ) + pQueue[i].actor_initiative = 100; + } - _4063A1(); - for(i=0; i<uActorQueueSize; ++i) - { - if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].field_4 > 0)) - break; - _40680F(i); - } + StepTurnQueue(); + for(i=0; i<uActorQueueSize; ++i) + { + if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].actor_initiative > 0)) + break; + _40680F(i); + } } // 4F75D8: using guessed type int ai_arrays_size; @@ -483,7 +484,7 @@ return; } pTurnEngine->field_18 &= ~TE_FLAG_2; - if ( pQueue[0].field_4 <= 0 ) + if ( pQueue[0].actor_initiative <= 0 ) return; v13 = 0; @@ -552,14 +553,14 @@ } //----- (004063A1) -------------------------------------------------------- - int stru262_TurnBased::_4063A1() + int stru262_TurnBased::StepTurnQueue() { int v9; // dx@12 int j; SortTurnQueue(); viewparams->bRedrawGameUI = 1; - if ( pQueue[0].field_4 ) + if ( pQueue[0].actor_initiative!=0 ) { if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) { @@ -567,33 +568,36 @@ { for (j=0; j<uActorQueueSize; ++j ) { - --pQueue[j].field_4; + --pQueue[j].actor_initiative; } - --field_10; - if (field_10 == 0) + --turn_initiative; + if (turn_initiative == 0) return 1; } - while (pQueue[0].field_4 > 0); + while (pQueue[0].actor_initiative != 0); } else { + if ( pQueue[0].actor_initiative>0 ) + { v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState; if (!(v9 == AIState::Dying || v9 == AIState::Dead || v9 == AIState::Disabled || v9 == AIState::Removed)) { - do + do { for (j=0; j<uActorQueueSize; ++j ) { - --pQueue[j].field_4; - if (pQueue[j].field_4 == 1) + --pQueue[j].actor_initiative; + if (pQueue[j].actor_initiative == 0) pQueue[j].uActionLength = 0; } - --field_10; - if (field_10 == 0) + --turn_initiative; + if (turn_initiative == 0) return 1; } - while (pQueue[0].field_4 > 0); + while (pQueue[0].actor_initiative > 0); + } } } } @@ -613,7 +617,7 @@ int v9; // ecx@14 char v10; // zf@15 int i; - + v6=0; if ( PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player) { v4 = PID_ID(pQueue[a2].uPackedID); @@ -629,30 +633,30 @@ v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime; } - pQueue[a2].field_4 = v6; + pQueue[a2].actor_initiative = v6; SortTurnQueue(); if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1; else uActiveCharacter = 0; viewparams->bRedrawGameUI = 1; - if (pQueue[0].field_4 > 0) + if (pQueue[0].actor_initiative > 0) { - while(field_10 > 0) + while(turn_initiative > 0) { for (i=0; i<uActorQueueSize; ++i) { - --pQueue[i].field_4; - if (pQueue[i].field_4==0) + --pQueue[i].actor_initiative; + if (pQueue[i].actor_initiative==0) pQueue[i].uActionLength=0; } - --field_10; + --turn_initiative; } } } //----- (0040652A) -------------------------------------------------------- -void stru262_TurnBased::_40652A() +void stru262_TurnBased::SetAIRecoveryTimes() { int i; int monster_ai_state; @@ -660,7 +664,7 @@ for (i=0; i<uActorQueueSize; ++i ) { - if (pQueue[i].field_4 == 0) + if (pQueue[i].actor_initiative == 0) { if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) break; @@ -670,9 +674,9 @@ monster_ai_state == AIState::Fleeing || monster_ai_state == AIState::Fidgeting) { - pQueue[i].field_4 = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime; + pQueue[i].actor_initiative = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime; if (monster->pActorBuffs[7].uExpireTime > 0) - pQueue[i].field_4*=2; + pQueue[i].actor_initiative*=2; } } } @@ -684,11 +688,11 @@ int i; SortTurnQueue(); - if (pQueue[0].field_4 <= 0) + if (pQueue[0].actor_initiative <= 0) { for (i=0; i<uActorQueueSize; ++i ) { - if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)|| (pQueue[i].field_4 > 0) ) + if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)|| (pQueue[i].actor_initiative > 0) ) break; if ((pQueue[i].uActionLength<=0) && (PID_TYPE(pQueue[i].uPackedID)==OBJECT_Actor)) _40680F(i); @@ -696,7 +700,7 @@ } else { - _4063A1(); + StepTurnQueue(); if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1; else @@ -705,11 +709,11 @@ } for (i=0; i<uActorQueueSize; ++i ) - AIRangedAttacks(i); + AIAttacks(i); } //----- (00406648) -------------------------------------------------------- -void stru262_TurnBased::AIRangedAttacks( unsigned int queue_index ) +void stru262_TurnBased::AIAttacks( unsigned int queue_index ) { TurnBased_QueueElem *v1; // ecx@1 int v3; // eax@1 @@ -940,7 +944,7 @@ } //----- (00406A63) -------------------------------------------------------- -void stru262_TurnBased::_406A63() +void stru262_TurnBased::ActorAIDoMainAction() { AIDirection a3; // [sp+8h] [bp-44h]@5 @@ -948,7 +952,7 @@ unsigned int target_pid; // [sp+40h] [bp-Ch]@5 int i; - this->field_8 = 64; + this->ai_turn_timer = 64; dword_50C994 = 0; uActiveCharacter = 0; for (i=0; i<uActorQueueSize; ++i ) @@ -965,7 +969,7 @@ // 50C994: using guessed type int dword_50C994; //----- (00406AFE) -------------------------------------------------------- -void stru262_TurnBased::_406AFE() +void stru262_TurnBased::ActorAISetLastAction() { AIDirection a3; // [sp+4h] [bp-48h]@5 AIDirection v7; // [sp+20h] [bp-2Ch]@5 @@ -984,12 +988,12 @@ } } turn_stage = 2; - field_8 = 100; + ai_turn_timer = 100; } //----- (00406B9F) -------------------------------------------------------- -void stru262_TurnBased::_406B9F() +void stru262_TurnBased::ActorAIDoAdditionAction() { Actor *v6; // ebx@5 AIDirection a3; // [sp+0h] [bp-50h]@15 @@ -1045,7 +1049,7 @@ int v8; // eax@7 AIDirection *v9; // esi@10 int v10; // eax@10 - unsigned int v11; // ecx@10 + int v11; // ecx@10 unsigned __int8 pHostileType; // al@12 unsigned __int8 v13; // sf@16 unsigned __int8 v14; // of@16 @@ -1057,7 +1061,7 @@ AIDirection a3; // [sp+Ch] [bp-48h]@10 AIDirection pDir; // [sp+28h] [bp-2Ch]@10 int v27; // [sp+44h] [bp-10h]@33 - unsigned int v28; // [sp+48h] [bp-Ch]@10 + int v28; // [sp+48h] [bp-Ch]@10 TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7 unsigned int uActorID; // [sp+50h] [bp-4h]@2 unsigned int a2a; // [sp+5Ch] [bp+8h]@7 @@ -1070,7 +1074,9 @@ //uActorID = v3; actor = &pActors[uActorID]; //v5 = v4->uAIState; - if ( actor->uAIState == 5 || actor->uAIState == 4 || actor->uAIState == 11 || actor->uAIState == 19 || actor->uAIState == 17 ) + if ( actor->uAIState == AIState::Dead || actor->uAIState == AIState::Dying || + actor->uAIState == AIState::Removed|| actor->uAIState == AIState::Disabled || + actor->uAIState == AIState::Summoned ) return 1; v6 = &ai_near_actors_targets_pid[uActorID]; v7 = &pTurnEngine->pQueue[a2]; @@ -1082,116 +1088,96 @@ actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly; v9 = Actor::GetDirectionInfo(v7->uPackedID, a2a, &a3, 0); v10 = actor->uActorRadius; - memcpy(&a3, v9, sizeof(a3)); - memcpy(&pDir, &a3, sizeof(pDir)); + memcpy(&a3, v9, sizeof(AIDirection)); + memcpy(&pDir, &a3, sizeof(AIDirection)); v11 = a3.uDistance - v10; v28 = a3.uDistance - v10; - if ( ((a3.uDistance - v10) & 0x80000000u) != 0 ) + if ( v28 < 0 ) { v11 = 0; v28 = 0; } pHostileType = actor->pMonsterInfo.uHostilityType; - if ( pHostileType == 1 ) - { - if ( (double)(signed int)v28 >= 307.2 ) - goto LABEL_21; - actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; - goto LABEL_21; - } - if ( pHostileType == 2 ) - { - v14 = __OFSUB__(v11, 1024); - v13 = ((v11 - 1024) & 0x80000000u) != 0; - } - else + + + switch (pHostileType) { - if ( pHostileType != 3 ) - goto LABEL_21; - v14 = __OFSUB__(v11, 2560); - v13 = ((v11 - 2560) & 0x80000000u) != 0; + case 1: + if ( (double)v28 < 307.2 ) + actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; + break; + case 2: + if ( v28 < 1024 ) + actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; + break; + case 3: + if ( v28 < 2560 ) + actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; + break; } - if ( v13 ^ v14 ) + + if ( actor->pActorBuffs[4].uExpireTime > 0 ) { - actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; - } -LABEL_21: - if ( (signed __int64)actor->pActorBuffs[4].uExpireTime > 0 ) - { - if ( (signed int)v11 < 10240 ) + if (v11 < 10240 ) { Actor::AI_Flee(uActorID, a2a, 0, &pDir); v29->field_C = 4; - v29->uActionLength = actor->uCurrentActionLength; - return 1; } - Actor::AI_4032B2(uActorID, a2a, 1024, 0); - v29->field_C = 2; + else + { + Actor::AI_4032B2(uActorID, a2a, 1024, 0); + v29->field_C = 2; + } + v29->uActionLength = actor->uCurrentActionLength; return 1; } - if ( actor->pMonsterInfo.uHostilityType != 4 ) - goto LABEL_46; + + if ( actor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long ) + { if ( !(actor->uAttributes & 0x020000) || actor->pMonsterInfo.uAIType == 1 ) { if ( actor->pMonsterInfo.uAIType == 1 ) { if ( actor->pMonsterInfo.uMovementType == 5 ) - { Actor::AI_Stand(uActorID, a2a, 32, 0); - v29->field_C = 4; - v29->uActionLength = actor->uCurrentActionLength; - return 1; - } - Actor::AI_Flee(uActorID, a2a, 32, 0); + else + Actor::AI_Flee(uActorID, a2a, 32, 0); v29->field_C = 4; v29->uActionLength = actor->uCurrentActionLength; return 1; } if ( actor->pMonsterInfo.uAIType == 2 ) { - v27 = actor->sCurrentHP; - v18 = (double)v27; - v19 = (double)(signed int)actor->pMonsterInfo.uHP * 0.2; - if ( v19 > v18 && (signed int)v11 < 10240 ) + + if (((double)actor->pMonsterInfo.uHP * 0.2) > (double)actor->sCurrentHP && (v11 < 10240 ) ) { if ( actor->pMonsterInfo.uMovementType == 5 ) - { Actor::AI_Stand(uActorID, a2a, 32, 0); - v29->field_C = 4; - v29->uActionLength = actor->uCurrentActionLength; - return 1; - } - Actor::AI_Flee(uActorID, a2a, 32, 0); + else + Actor::AI_Flee(uActorID, a2a, 32, 0); v29->field_C = 4; v29->uActionLength = actor->uCurrentActionLength; return 1; } - goto LABEL_39; } if ( actor->pMonsterInfo.uAIType == 3 ) { - v27 = actor->sCurrentHP; - v18 = (double)v27; - v19 = (double)(signed int)actor->pMonsterInfo.uHP * 0.1; - if ( v19 > v18 && (signed int)v11 < 10240 ) + + if ( ((double)actor->pMonsterInfo.uHP * 0.1) > (double)actor->sCurrentHP && (v11 < 10240 )) { if ( actor->pMonsterInfo.uMovementType == 5 ) - { Actor::AI_Stand(uActorID, a2a, 32, 0); - v29->field_C = 4; - v29->uActionLength = actor->uCurrentActionLength; - return 1; - } - Actor::AI_Flee(uActorID, a2a, 32, 0); + else + Actor::AI_Flee(uActorID, a2a, 32, 0); v29->field_C = 4; v29->uActionLength = actor->uCurrentActionLength; return 1; } - goto LABEL_39; + } } -LABEL_39: + if ( (double)(signed int)v28 < 307.2 ) return 0; if ( (signed int)v11 < 5120 ) @@ -1204,42 +1190,29 @@ v29->uActionLength = actor->uCurrentActionLength; return 1; } -LABEL_46: - if ( actor->pMonsterInfo.uMovementType == 0 ) - { - Actor::AI_4032B2(uActorID, a2a, 1024, 32); - v29->field_C = 2; - v29->uActionLength = actor->uCurrentActionLength; - return 1; } - if ( actor->pMonsterInfo.uMovementType == 1 ) - { - Actor::AI_4032B2(uActorID, a2a, 2560, 32); - v29->field_C = 2; - v29->uActionLength = actor->uCurrentActionLength; - return 1; - } - if ( actor->pMonsterInfo.uMovementType == 2 ) + switch(actor->pMonsterInfo.uMovementType) { - Actor::AI_4032B2(uActorID, a2a, 5120, 32); - v29->field_C = 2; - v29->uActionLength = actor->uCurrentActionLength; - return 1; + case 0: + Actor::AI_4032B2(uActorID, a2a, 1024, 32); + break; + case 1: + Actor::AI_4032B2(uActorID, a2a, 2560, 32); + break; + case 2: + Actor::AI_4032B2(uActorID, a2a, 5120, 32); + break; + case 4: + Actor::AI_4032B2(uActorID, a2a, 10240, 32); + break; + case 5: + Actor::AI_Stand(uActorID, a2a, 32, 0); + break; + default: + return 1; } - if ( actor->pMonsterInfo.uMovementType == 4 ) - { - Actor::AI_4032B2(uActorID, a2a, 10240, 32); - v29->field_C = 2; - v29->uActionLength = actor->uCurrentActionLength; - return 1; - } - if ( actor->pMonsterInfo.uMovementType == 5 ) - { - Actor::AI_Stand(uActorID, a2a, 32, 0); - v29->field_C = 2; - v29->uActionLength = actor->uCurrentActionLength; - return 1; - } + v29->field_C = 2; + v29->uActionLength = actor->uCurrentActionLength; return 1; }