Mercurial > mm7
changeset 413:111f25d1cc04
AI_Stand
author | Nomad |
---|---|
date | Sat, 23 Feb 2013 16:39:32 +0200 |
parents | bbd8888534dc |
children | d8b3056df4e2 49158f2cc88d |
files | Actor.cpp Actor.h mm7_3.cpp mm7_5.cpp mm7_6.cpp |
diffstat | 5 files changed, 83 insertions(+), 100 deletions(-) [+] |
line wrap: on
line diff
--- a/Actor.cpp Sat Feb 23 16:02:04 2013 +0200 +++ b/Actor.cpp Sat Feb 23 16:39:32 2013 +0200 @@ -1997,81 +1997,57 @@ //----- (00403F58) -------------------------------------------------------- void Actor::_403F58(unsigned int uActorID, signed int uObjID, int uActionLength, AIDirection *a4) { - unsigned int v4; // esi@1 - //unsigned int result; // eax@2 - AIDirection *v6; // eax@3 - unsigned int v7; // edi@3 - Actor *v8; // ebx@3 - AIDirection *v9; // esi@4 - AIDirection a3; // [sp+4h] [bp-3Ch]@4 - AIDirection v11; // [sp+20h] [bp-20h]@4 - signed int a2; // [sp+3Ch] [bp-4h]@1 - - a2 = uObjID; - v4 = uActorID; - if ( rand() % 2 ) + if (rand() % 2) { - Actor::_402F87(v4, a2, a4); + Actor::_402F87(uActorID, uObjID, a4); return; } - v6 = a4; - v7 = 0; - v8 = &pActors[v4]; - if ( !a4 ) - { - v9 = Actor::GetDirectionInfo(8 * v4 | 3, a2, &a3, 0); - v6 = &v11; - memcpy(&v11, v9, sizeof(v11)); - v7 = 0; - } - v8->uYawAngle = LOWORD(v6->uYawAngle); - v8->uPitchAngle = LOWORD(v6->uPitchAngle); - if ( uActionLength == v7 ) - v8->uCurrentActionLength = rand() % 256 + 256; - else - v8->uCurrentActionLength = uActionLength; - v8->uCurrentActionTime = v7; - v8->uAIState = Standing; - v8->vVelocity.z = v7; - v8->vVelocity.y = v7; - v8->vVelocity.x = v7; - v8->UpdateAnimation(); + assert(uActorID < uNumActors); + auto actor = &pActors[uActorID]; + + AIDirection a3; + if (!a4) + a4 = Actor::GetDirectionInfo(8 * uActorID | OBJECT_Actor, uObjID, &a3, 0); + + actor->uAIState = Standing; + if (!uActionLength) + actor->uCurrentActionLength = rand() % 256 + 256; + else + actor->uCurrentActionLength = uActionLength; + actor->uCurrentActionTime = 0; + actor->uYawAngle = a4->uYawAngle; + actor->uPitchAngle = a4->uPitchAngle; + actor->vVelocity.z = 0; + actor->vVelocity.y = 0; + actor->vVelocity.x = 0; + actor->UpdateAnimation(); } //----- (00403EB6) -------------------------------------------------------- -void Actor::_403EB6(unsigned int uActorID, unsigned int a2, unsigned int uActionLength, AIDirection *a4) +void Actor::AI_Stand(unsigned int uActorID, unsigned int object_to_face_pid, unsigned int uActionLength, AIDirection *a4) { - AIDirection *v4; // eax@1 - unsigned int v5; // esi@1 - Actor *v6; // ebx@1 - AIDirection *v7; // esi@2 - AIDirection a3; // [sp+Ch] [bp-38h]@2 - AIDirection v10; // [sp+28h] [bp-1Ch]@2 + assert(uActorID < uNumActors); + auto actor = pActors + uActorID; + + AIDirection a3; + if (!a4) + a4 = Actor::GetDirectionInfo(8 * uActorID | 3, object_to_face_pid, &a3, 0); - v4 = a4; - v5 = 0; - v6 = &pActors[uActorID]; - if ( !a4 ) - { - v7 = Actor::GetDirectionInfo(8 * uActorID | 3, a2, &a3, 0); - v4 = &v10; - memcpy(&v10, v7, sizeof(v10)); - v5 = 0; - } - v6->uYawAngle = LOWORD(v4->uYawAngle); - if ( uActionLength == v5 ) - v6->uCurrentActionLength = rand() % 256 + 256; + actor->uAIState = Standing; + if (!uActionLength) + actor->uCurrentActionLength = rand() % 256 + 256; else - v6->uCurrentActionLength = uActionLength; - v6->uCurrentActionTime = v5; - v6->uAIState = Standing; - v6->vVelocity.z = v5; - v6->vVelocity.y = v5; - v6->vVelocity.x = v5; - v6->UpdateAnimation(); + actor->uCurrentActionLength = uActionLength; + actor->uCurrentActionTime = 0; + actor->uYawAngle = a4->uYawAngle; + actor->uPitchAngle = a4->uPitchAngle; + actor->vVelocity.z = 0; + actor->vVelocity.y = 0; + actor->vVelocity.x = 0; + actor->UpdateAnimation(); } @@ -2123,7 +2099,7 @@ v24 = uActorID; if ( v4 && v3->pMonsterInfo.uAIType == 1 ) { - Actor::_403EB6(uActorID, edx0, 0, arg0); + Actor::AI_Stand(uActorID, edx0, 0, arg0); return; } @@ -2953,7 +2929,7 @@ { v13 = &v14; v12 = 256; - Actor::_403EB6(uActorID, v16, v12, v13); + Actor::AI_Stand(uActorID, v16, v12, v13); return; } v15 = (rand() & 0xF) << 12; @@ -2969,7 +2945,7 @@ { v13 = &v14; v12 = 256; - Actor::_403EB6(uActorID, v16, v12, v13); + Actor::AI_Stand(uActorID, v16, v12, v13); return; } v11 = v5->uMovementSpeed; @@ -3119,7 +3095,7 @@ v15 = uActorID; if ( !a4 ) { - memcpy(&v13, Actor::GetDirectionInfo(8 * uActorID | AI_OBJECT_ACTOR, uObjID, &a3, (int)a4), sizeof(v13)); + memcpy(&v13, Actor::GetDirectionInfo(8 * uActorID | OBJECT_Actor, uObjID, &a3, (int)a4), sizeof(v13)); memcpy(&v12, &v13, sizeof(v12)); v3 = v15; v4 = &v12; @@ -3132,7 +3108,7 @@ v9 = stru_5C6E00->uIntegerPi + v8 + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v7; if ( BYTE1(v9) & 7 ) { - Actor::_403EB6(v3, v14, v5->uCurrentActionLength, v4); + Actor::AI_Stand(v3, v14, v5->uCurrentActionLength, v4); } else { @@ -3342,12 +3318,12 @@ { if ( !uActionLength ) uActionLength = 256; - Actor::_403EB6(v5, v18, uActionLength, v10); + Actor::AI_Stand(v5, v18, uActionLength, v10); return; } if ( !v7->uMovementSpeed ) { - Actor::_403EB6(v5, v18, uActionLength, v10); + Actor::AI_Stand(v5, v18, uActionLength, v10); return; } v18 = 16;
--- a/Actor.h Sat Feb 23 16:02:04 2013 +0200 +++ b/Actor.h Sat Feb 23 16:39:32 2013 +0200 @@ -219,7 +219,7 @@ static void _403A60(unsigned int uActorID, signed int edx0, struct AIDirection *pDir); static void _403C6C(unsigned int uActorID, signed int edx0, struct AIDirection *arg0); static void __fastcall StandAwhile(unsigned int uActorID); - static void _403EB6(unsigned int uActorID, unsigned int a2, unsigned int uActionLength, struct AIDirection *a4); + static void AI_Stand(unsigned int uActorID, unsigned int object_to_face_pid, unsigned int uActionLength, struct AIDirection *a4); static void _403F58(unsigned int uActorID, signed int uObjID, int uActionLength, struct AIDirection *a4); static void FaceObject(unsigned int uActorID, unsigned int uObjID, int _48, struct AIDirection *a4); static struct AIDirection *__fastcall GetDirectionInfo(unsigned int uObj1ID, unsigned int uObj2ID, struct AIDirection *pOut, int a4);
--- a/mm7_3.cpp Sat Feb 23 16:02:04 2013 +0200 +++ b/mm7_3.cpp Sat Feb 23 16:39:32 2013 +0200 @@ -17754,7 +17754,7 @@ float v80; // [sp+98h] [bp-18h]@33 int v81; // [sp+9Ch] [bp-14h]@100 int v82; // [sp+A0h] [bp-10h]@45 - unsigned int uActorID; // [sp+A4h] [bp-Ch]@32 + //unsigned int uActorID; // [sp+A4h] [bp-Ch]@32 unsigned int v84; // [sp+A8h] [bp-8h]@11 signed int a2; // [sp+ACh] [bp-4h]@83 @@ -17911,7 +17911,7 @@ { if (actor->uAIState != Summoned) { - Actor::_403F58(i, Dying, 256, 0); + Actor::_403F58(i, OBJECT_Player, 256, nullptr); continue; } actor->uAIState = Standing; @@ -17929,14 +17929,17 @@ v78 = 0; + int actor_id = -1; if ( ai_arrays_size > 0 ) { while ( 1 ) { - uActorID = ai_near_actors_ids[v78]; - v20 = &dword_4F6E08[uActorID]; - v21 = &pActors[uActorID]; - Actor::_401221(uActorID, &dword_4F6E08[uActorID], 1u); + actor_id = ai_near_actors_ids[v78]; + assert(actor_id < uNumActors); + + v20 = &dword_4F6E08[actor_id]; + v21 = &pActors[actor_id]; + Actor::_401221(actor_id, &dword_4F6E08[actor_id], 1u); if ( v21->pMonsterInfo.uHostilityType && !*v20 ) v21->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly; a2 = *v20; @@ -17949,7 +17952,7 @@ if ( v22 == Dying || v22 == Dead || v22 == Removed || v22 == Disabled || v22 == Summoned) goto LABEL_254; if ( !v21->sCurrentHP ) - Actor::Die(uActorID); + Actor::Die(actor_id); if ( (signed __int64)v21->pActorBuffs[3].uExpireTime <= 0 ) { v84 = 0; @@ -18017,8 +18020,8 @@ v29 = v21->uAttributes; if ( !(v29 & 0x8000) ) v21->uAttributes = v29 | 0x8000; - a1 = 8 * uActorID | 3; - v30 = Actor::GetDirectionInfo(8 * uActorID | 3, a2, &a3, 0); + a1 = 8 * actor_id | OBJECT_Actor; + v30 = Actor::GetDirectionInfo(8 * actor_id | OBJECT_Actor, a2, &a3, 0); v49 = v21->pMonsterInfo.uHostilityType == 0; memcpy(&v75, v30, sizeof(v75)); memcpy(&pDir, &v75, sizeof(pDir)); @@ -18028,7 +18031,7 @@ && ((v31 = v21->uAIState, v31 == 6) || !v31 || v31 == 1 || v31 == 9) || v21->pMonsterInfo.uMissleAttack1Type && v21->uAIState == 8 ) { - v32 = uActorID; + v32 = actor_id; goto LABEL_152; } } @@ -18036,8 +18039,8 @@ goto LABEL_254; if ( v21->uAIState == 2 ) { - v32 = uActorID; - v35 = stru_50C198.special_ability_use_check(v21, uActorID); + v32 = actor_id; + v35 = stru_50C198.special_ability_use_check(v21, actor_id); stru_50FE08.Add( a1, 5120, @@ -18059,11 +18062,11 @@ v34 = v21->pMonsterInfo.uMissleAttack2Type; v66 = 1; LABEL_149: - v32 = uActorID; - Actor::_404874(uActorID, &pDir, v34, v66); + v32 = actor_id; + Actor::_404874(actor_id, &pDir, v34, v66); goto LABEL_152; } - v32 = uActorID; + v32 = actor_id; if ( v21->uAIState == 13 ) break; if ( v21->uAIState == 18 ) @@ -18072,7 +18075,7 @@ v60 = 3; v33 = v21->pMonsterInfo.uSpell2ID; LABEL_146: - Actor::_404AC7(uActorID, &pDir, v33, v60, v65); + Actor::_404AC7(actor_id, &pDir, v33, v60, v65); } LABEL_152: v36 = v75.uDistance; @@ -18136,7 +18139,7 @@ v67 = &pDir; if ( v21->pMonsterInfo.uMovementType != 5 ) goto LABEL_181; - Actor::_403EB6( + Actor::AI_Stand( v32, a2, (signed __int64)((double)(signed int)v21->pMonsterInfo.uRecoveryTime * 2.133333333333333), @@ -18252,7 +18255,7 @@ v64 = (signed __int64)v47; v52 = v32; LABEL_247: - Actor::_403EB6(v52, v51, v64, v69); + Actor::AI_Stand(v52, v51, v64, v69); goto LABEL_254; } v69 = &pDir; @@ -18321,7 +18324,7 @@ memcpy(&v74, v57, sizeof(v74)); memcpy(&pDir, &v74, sizeof(pDir)); v69 = &pDir; - v52 = uActorID; + v52 = actor_id; v64 = (signed __int64)v58; v51 = 4; goto LABEL_247;
--- a/mm7_5.cpp Sat Feb 23 16:02:04 2013 +0200 +++ b/mm7_5.cpp Sat Feb 23 16:39:32 2013 +0200 @@ -10104,7 +10104,7 @@ } v21 = 64; LABEL_26: - Actor::_403EB6(v15, v16, v21, v23); + Actor::AI_Stand(v15, v16, v21, v23); return; } LABEL_21: @@ -10300,7 +10300,7 @@ goto LABEL_48; } LABEL_47: - Actor::_403EB6(v13, v22, 0x40u, &v18); + Actor::AI_Stand(v13, v22, 0x40u, &v18); v3 = v21; v21->field_C = 0; goto LABEL_48; @@ -10343,7 +10343,7 @@ v8 = dword_4F6E08[v5 >> 3]; memcpy(&v7, Actor::GetDirectionInfo(v5, v8, &a3, v2), sizeof(v7)); if ( !v1->_406D10(a2) ) - Actor::_403EB6(v10->uPackedID >> 3, v8, 0x20u, &v7); + Actor::AI_Stand(v10->uPackedID >> 3, v8, 0x20u, &v7); } ++a2; ++v10; @@ -10386,7 +10386,7 @@ v4 = v2->uPackedID; v9 = dword_4F6E08[v3]; memcpy(&v6, Actor::GetDirectionInfo(v4, v9, &a3, 0), sizeof(v6)); - Actor::_403EB6(v8, v9, 0x20u, &v6); + Actor::AI_Stand(v8, v9, 0x20u, &v6); v2->field_C = 0; v2->uActionLength = 0; v1 = v7; @@ -10467,7 +10467,7 @@ } if ( !thisa->_406D10(a2) ) LABEL_26: - Actor::_403EB6(v12, v13, 0x20u, &v9); + Actor::AI_Stand(v12, v13, 0x20u, &v9); } } } @@ -10609,7 +10609,7 @@ v21 = 32; if ( v4->pMonsterInfo.uMovementType == 5 ) { - Actor::_403EB6(uActorID, a2a, 0x20u, 0); + Actor::AI_Stand(uActorID, a2a, 0x20u, 0); goto LABEL_25; } LABEL_24: @@ -10668,7 +10668,7 @@ } if ( v4->pMonsterInfo.uMovementType == 5 ) { - Actor::_403EB6(uActorID, a2a, 0x20u, 0); + Actor::AI_Stand(uActorID, a2a, 0x20u, 0); LABEL_53: v17 = v29; v29->field_C = 2; @@ -10742,7 +10742,7 @@ return; } if ( rand() % 2 ) - Actor::_403EB6(uActorID, a2, 0x40u, &a4); + Actor::AI_Stand(uActorID, a2, 0x40u, &a4); else Actor::_402F87(uActorID, a2, &a4); } @@ -12098,6 +12098,8 @@ v7 = 1; if (_449B57_test_bit(pParty->_award_bits, 100)) v5 = 1; + + Log::Warning(L"%S %S %u", __FILE__, __FUNCTION__, __LINE__); // dword_4F6E08[i] for AI_Stand seems always 0; original code behaviour is identical for (uint i = 0; i < uNumActors; ++i) { auto actor = pActors + i; @@ -12109,7 +12111,9 @@ actor->vPosition.z = actor->vInitialPosition.z; actor->sCurrentHP = actor->pMonsterInfo.uHP; if (actor->uAIState != Disabled) - Actor::_403EB6(i, dword_4F6E08[i], actor->pMonsterInfo.uRecoveryTime, 0); + { + Actor::AI_Stand(i, dword_4F6E08[i], actor->pMonsterInfo.uRecoveryTime, 0); + } } actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
--- a/mm7_6.cpp Sat Feb 23 16:02:04 2013 +0200 +++ b/mm7_6.cpp Sat Feb 23 16:39:32 2013 +0200 @@ -3860,7 +3860,7 @@ v721 = (int)&pActors[a2 >> 3], !stru_50C198.GetMagicalResistance(&pActors[a2 >> 3], 9u)) ) goto LABEL_1056; - Actor::_403EB6(v730, 4u, 0x80u, (AIDirection *)v1); + Actor::AI_Stand(v730, 4u, 0x80u, (AIDirection *)v1); v726 = (Player *)(23040 * v2); v54 = (signed __int64)((double)(23040 * v2) * 0.033333335); v55 = v721;