changeset 1910:8d3723ca71e6

Actor::GetDirectionInfo changed the signature to a less confusing one
author Grumpy7
date Tue, 22 Oct 2013 00:39:04 -0700
parents 18dacb49efe9
children 3f0b9ffd788c
files Actor.cpp Actor.h CastSpellInfo.cpp TurnEngine.cpp mm7_3.cpp
diffstat 5 files changed, 70 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Tue Oct 22 00:04:14 2013 -0700
+++ b/Actor.cpp	Tue Oct 22 00:39:04 2013 -0700
@@ -949,7 +949,7 @@
 // // originally this function had following prototype:
 // // struct DirectionInfo GetDirectionInfo(signed int object1, signed int object2, signed int a4)
 // // but compiler converts functions returning structures by value in the such way
-struct AIDirection * Actor::GetDirectionInfo( unsigned int uObj1ID, unsigned int uObj2ID, struct AIDirection *pOut, int a4 )
+void Actor::GetDirectionInfo( unsigned int uObj1ID, unsigned int uObj2ID, struct AIDirection *pOut, int a4 )
 {
   signed int v4; // eax@1
   signed int v5; // ecx@1
@@ -1117,33 +1117,31 @@
   v33 = sqrt(a4a * a4a + outy2 + outx2);
   if ( v33 <= 1.0 )
   {
-    v41.vDirection.x = 65536;
-    v41.vDirection.y = 0;
-    v41.vDirection.z = 0;
-    v41.uDistance = 1;
-    v41.uDistanceXZ = 1;
-    v41.uYawAngle = 0;
-    v41.uPitchAngle = 0;
+    pOut->vDirection.x = 65536;
+    pOut->vDirection.y = 0;
+    pOut->vDirection.z = 0;
+    pOut->uDistance = 1;
+    pOut->uDistanceXZ = 1;
+    pOut->uYawAngle = 0;
+    pOut->uPitchAngle = 0;
   }
   else
   {
-    v41.vDirection.x = (int32_t)(1.0 / v33 * v31 * 65536.0);
-    v41.vDirection.y = (int32_t)(1.0 / v33 * v32 * 65536.0);
-    v41.vDirection.z = (int32_t)(1.0 / v33 * a4a * 65536.0);
-    v41.uDistance = (uint)v33;
-    v41.uDistanceXZ = (uint)sqrt(outy2 + outx2);
-    v41.uYawAngle = stru_5C6E00->Atan2((signed __int64)v31, (signed __int64)v32);
-    v41.uPitchAngle = stru_5C6E00->Atan2(v41.uDistanceXZ, (signed __int64)a4a);
+    pOut->vDirection.x = (int32_t)(1.0 / v33 * v31 * 65536.0);
+    pOut->vDirection.y = (int32_t)(1.0 / v33 * v32 * 65536.0);
+    pOut->vDirection.z = (int32_t)(1.0 / v33 * a4a * 65536.0);
+    pOut->uDistance = (uint)v33;
+    pOut->uDistanceXZ = (uint)sqrt(outy2 + outx2);
+    pOut->uYawAngle = stru_5C6E00->Atan2((signed __int64)v31, (signed __int64)v32);
+    pOut->uPitchAngle = stru_5C6E00->Atan2(pOut->uDistanceXZ, (signed __int64)a4a);
   }
-  result = pOut;
-  memcpy(pOut, &v41, sizeof(AIDirection));
-  return result;
 }
 
 //----- (00404030) --------------------------------------------------------
 void Actor::AI_FaceObject(unsigned int uActorID, unsigned int uObjID, int _48, AIDirection *a4)
 {
   AIDirection *v7; // eax@3
+  AIDirection v1; // eax@3
   Actor *v9; // ebx@3
   AIDirection a3; // [sp+8h] [bp-38h]@4
 
@@ -1152,7 +1150,8 @@
     v9 = &pActors[uActorID];
     if ( !a4 )
     {
-      v7 = Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), uObjID, &a3, 0);
+      Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), uObjID, &v1, 0);
+      v7 = &v1;
     }
     else
     {
@@ -1189,7 +1188,10 @@
   
   AIDirection a3;
   if (!a4)
-    a4 = Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), object_to_face_pid, &a3, 0);
+  {
+    Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), object_to_face_pid, &a3, 0);
+    a4 = &a3;
+  }
 
   actor->uAIState = Standing;
   if (!uActionLength)
@@ -1268,7 +1270,8 @@
     }
     else
     {
-		  v12 = Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), sTargetPid, &a3, 0);
+		  Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), sTargetPid, &a3, 0);
+      v12 = &a3;
     }
     v3->uYawAngle = LOWORD(v12->uYawAngle);
     v3->uCurrentActionLength = pSpriteFrameTable->pSpriteSFrames[v3->pSpriteIDs[ANIM_AtkMelee]].uAnimLength * 8;
@@ -1542,7 +1545,8 @@
   {
     if ( pDir == nullptr)
     {
-      v9 = Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), a2, &a3, 0);
+      Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), a2, &a3, 0);
+      v9 = &a3;
     }
     else
     {
@@ -1625,7 +1629,8 @@
   {
     if ( pDir == nullptr )
     {
-      v9 = Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
+      Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
+      v9 = &a3;
     }
     else
     {
@@ -1708,7 +1713,8 @@
   {
     if ( pDir == nullptr )
     {
-      v9 = Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
+      Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
+      v9 = &a3;
     }
     else
     {
@@ -1788,7 +1794,8 @@
   {
     if ( pDir == nullptr )
     {
-      v10 = Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
+      Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
+      v10 = &a3;
     }
     else
     {
@@ -1965,7 +1972,8 @@
     && v4->uAIState != AttackingRanged4
     && v4->uAIState != AttackingMelee))
   {
-    v10 = Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), edx0, &a3, 0), sizeof(v10);
+    Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), edx0, &a3, 0);
+    v10 = &a3;
     v4->uYawAngle = LOWORD(v10->uYawAngle);
     v7 = pSpriteFrameTable->pSpriteSFrames[v4->pSpriteIDs[ANIM_GotHit]].uAnimLength;
     v4->uCurrentActionTime = 0;
@@ -1986,7 +1994,10 @@
   
   AIDirection a3; // [sp+Ch] [bp-5Ch]@2
   if (!a4)
-    a4 = Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), uObjID, &a3, 0);
+  {
+    Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), uObjID, &a3, 0);
+    a4 = &a3;
+  }
 
   actor->uCurrentActionLength = 8 * pSpriteFrameTable->pSpriteSFrames[actor->pSpriteIDs[ANIM_Bored]].uAnimLength;
 
@@ -2145,7 +2156,8 @@
 
   if ( pDir == nullptr )
   {
-    v10 = Actor::GetDirectionInfo(v8, a2, &a3, v6);
+    Actor::GetDirectionInfo(v8, a2, &a3, v6);
+    v10 = &a3;
   }
   else
   {
@@ -2203,9 +2215,11 @@
     v7 = PID(OBJECT_Actor,uActorID);
     if ( !a4 )
     {
-      a4 = Actor::GetDirectionInfo(v7, sTargetPid, &a3, v5->pMonsterInfo.uFlying);
+      Actor::GetDirectionInfo(v7, sTargetPid, &a3, v5->pMonsterInfo.uFlying);
+      a4 = &a3;
     }
-    v13 = Actor::GetDirectionInfo(v7, 4u, &v10, 0);
+    Actor::GetDirectionInfo(v7, 4u, &v10, 0);
+    v13 = &v10;
     if ( MonsterStats::BelongsToSupertype(v5->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT)
       || PID_TYPE(sTargetPid) == OBJECT_Actor && v13->uDistance < 307.2 )
     {
@@ -2257,7 +2271,8 @@
   v10 = pDir;
   if ( !pDir )
   {
-    v10 = Actor::GetDirectionInfo(v8, a2, &a3, v6);
+    Actor::GetDirectionInfo(v8, a2, &a3, v6);
+    v10 = &a3;
   }
   if ( MonsterStats::BelongsToSupertype(v7->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
   {
@@ -2319,7 +2334,8 @@
   }
   if ( !a4 )
   {
-    v20 = Actor::GetDirectionInfo(v7, a2, &a3, v5);
+    Actor::GetDirectionInfo(v7, a2, &a3, v5);
+    v20 = &a3;
   }
   if ( MonsterStats::BelongsToSupertype(v6->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
   {
@@ -3052,7 +3068,8 @@
 		if ( !(pActor->uAttributes & 0x8000) )
 			pActor->uAttributes |= 0x8000;
 		a1 = PID(OBJECT_Actor,actor_id);
-		pDir = Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), target_pid, &a3, 0);
+		Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), target_pid, &a3, 0);
+    pDir = &a3;
 		uAIState = pActor->uAIState; 
 		if ( pActor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Friendly
 			|| (signed int)pActor->pMonsterInfo.uRecoveryTime > 0
@@ -3322,9 +3339,9 @@
 			}
 			else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
 			{
-				v57 = Actor::GetDirectionInfo(a1, 4u, &v72, 0);
+				Actor::GetDirectionInfo(a1, 4u, &v72, 0);
 				v58 = (uint)(pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333);
-				Actor::AI_Stand(actor_id, 4, v58, v57);
+				Actor::AI_Stand(actor_id, 4, v58, &v72);
 			}				
 		}
 		else if ( !pActor->pMonsterInfo.uMissleAttack2Type )
--- a/Actor.h	Tue Oct 22 00:04:14 2013 -0700
+++ b/Actor.h	Tue Oct 22 00:39:04 2013 -0700
@@ -228,7 +228,7 @@
   static void AI_Stand(unsigned int uActorID, unsigned int object_to_face_pid, unsigned int uActionLength, struct AIDirection *a4);
   static void AI_StandOrBored(unsigned int uActorID, signed int uObjID, int uActionLength, struct AIDirection *a4);
   static void AI_FaceObject(unsigned int uActorID, unsigned int uObjID, int _48, struct AIDirection *a4);
-  static struct AIDirection * GetDirectionInfo(unsigned int uObj1ID, unsigned int uObj2ID, struct AIDirection *pOut, int a4);
+  static void GetDirectionInfo(unsigned int uObj1ID, unsigned int uObj2ID, struct AIDirection *pOut, int a4);
   static void Explode(unsigned int uActorID);
   static void AI_RangedAttack(unsigned int uActorID, struct AIDirection *a2, int type, char a4);
   static void AI_SpellAttack(unsigned int uActorID, struct AIDirection *pDir, int uSpellID, int a4, unsigned int uSkillLevel);
--- a/CastSpellInfo.cpp	Tue Oct 22 00:04:14 2013 -0700
+++ b/CastSpellInfo.cpp	Tue Oct 22 00:39:04 2013 -0700
@@ -350,7 +350,7 @@
     {
       if (PID_TYPE(a2) == OBJECT_Actor)
       {
-        memcpy(&v715, Actor::GetDirectionInfo(PID(OBJECT_Player, pCastSpell->uPlayerID + 1), a2, &a3, 0), sizeof(v715));
+        Actor::GetDirectionInfo(PID(OBJECT_Player, pCastSpell->uPlayerID + 1), a2, &v715, 0);
         v2 = v723;
       }
       else
--- a/TurnEngine.cpp	Tue Oct 22 00:04:14 2013 -0700
+++ b/TurnEngine.cpp	Tue Oct 22 00:39:04 2013 -0700
@@ -168,7 +168,7 @@
                 {
                 v8 = ai_near_actors_targets_pid[actor_id];
                 pActors[actor_id].uAttributes |= 0x80;
-                memcpy(&v31, Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v8, &a3, 0), sizeof(AIDirection));
+                Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v8, &v31, 0);
                 memcpy(&v30, &v31, sizeof(AIDirection));
                 Actor::AI_StandOrBored(actor_id, 4, 32, &v30);
                 this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Actor,actor_id);
@@ -292,7 +292,7 @@
 //----- (00405E14) --------------------------------------------------------
 void stru262_TurnBased::AITurnBasedAction()
     {
-    AIDirection *v6; // esi@21
+    AIDirection v6; // esi@21
     int v7; // eax@21
     AIDirection a3; // [sp+4h] [bp-68h]@21
     AIDirection v14; // [sp+20h] [bp-4Ch]@21
@@ -323,8 +323,8 @@
             if (curr_actor->uCurrentActionTime>=curr_actor->uCurrentActionLength)
                 {
                 target_pid = ai_near_actors_targets_pid[i];
-                v6 = Actor::GetDirectionInfo(PID(OBJECT_Actor,i), target_pid, &a3, 0);  
-                memcpy(&v15, v6, sizeof(AIDirection));   
+                Actor::GetDirectionInfo(PID(OBJECT_Actor,i), target_pid, &v6, 0);  
+                memcpy(&v15, &v6, sizeof(AIDirection));   
                 memcpy(&v14, &v15, sizeof(AIDirection));
                 v7 = curr_actor->uAIState;
                 if(v7==Dying)
@@ -715,7 +715,7 @@
         {
         v4 = PID_ID(v3);
         a2a = ai_near_actors_targets_pid[PID_ID(pQueue[queue_index].uPackedID)];
-        memcpy(&a3, Actor::GetDirectionInfo(v1->uPackedID, ai_near_actors_targets_pid[PID_ID(v3)], &a3, 0), sizeof(a3));
+        Actor::GetDirectionInfo(v1->uPackedID, ai_near_actors_targets_pid[PID_ID(v3)], &a3, 0);
         memcpy(&a4, &a3, sizeof(a4));
         v5 = &pActors[PID_ID(v3)];
         LOWORD(v3) = v5->uAIState;
@@ -777,7 +777,7 @@
     unsigned int v3; // eax@1
     unsigned int actor_id; // edi@2
     Actor *v5; // ebx@2
-    AIDirection *v7; // esi@10
+    AIDirection v7; // esi@10
     int v8; // eax@10
     int v9; // ecx@10
     signed int v10; // eax@13
@@ -808,9 +808,9 @@
                 v22 = ai_near_actors_targets_pid[actor_id];
                 if ( v5->pMonsterInfo.uHostilityType && !v22)
                     v5->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
-                v7 = Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v22, &a3, 0);
+                Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v22, &v7, 0);
                 v8 = v5->uActorRadius;
-                memcpy(&a3, v7, sizeof(AIDirection));
+                memcpy(&a3, &v7, sizeof(AIDirection));
                 memcpy(&v18, &a3, sizeof(AIDirection));
                 v9 = a3.uDistance - v8;
                 v20 = a3.uDistance - v8;
@@ -920,7 +920,7 @@
         if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
             {
             target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
-            memcpy(&v7, Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &a3, 0), sizeof(AIDirection));
+            Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0);
             if ( !ActorMove(i) )
                 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
             }
@@ -941,7 +941,7 @@
         if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
             {
             target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
-            memcpy(&v7, Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &a3, 0), sizeof(AIDirection));
+            Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0);
             Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
             pQueue[i].AI_action_type = TE_AI_STAND;
             pQueue[i].uActionLength = 0;
@@ -970,7 +970,7 @@
                     v6->uAIState == AIState::Dead || v6->uAIState == AIState::Removed || v6->uAIState == AIState::Disabled) )
                 {
                 v13 = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
-                memcpy(&v9, Actor::GetDirectionInfo(pQueue[i].uPackedID, v13, &a3, 0), sizeof(AIDirection));
+                Actor::GetDirectionInfo(pQueue[i].uPackedID, v13, &v9, 0);
                 if ( v6->uAIState == AIState::Pursuing || v6->uAIState == AIState::Tethered ) 
                     {
                     if ( (double)(signed int)v9.uDistance < 307.2 )
@@ -1004,7 +1004,7 @@
     //int v3; // ecx@2
     Actor *actor; // ebx@2
 
-    AIDirection *v9; // esi@10
+    AIDirection v9; // esi@10
     int v10; // eax@10
     int v11; // ecx@10
     unsigned __int8 pHostileType; // al@12
@@ -1032,9 +1032,9 @@
     Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);
     if ( actor->pMonsterInfo.uHostilityType && !ai_near_actors_targets_pid[uActorID] )
         actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
-    v9 = Actor::GetDirectionInfo(pQueue[queue_position].uPackedID, ai_near_actors_targets_pid[uActorID], &a3, 0);
+    Actor::GetDirectionInfo(pQueue[queue_position].uPackedID, ai_near_actors_targets_pid[uActorID], &v9, 0);
     v10 = actor->uActorRadius;
-    memcpy(&a3, v9, sizeof(AIDirection));
+    memcpy(&a3, &v9, sizeof(AIDirection));
     memcpy(&pDir, &a3, sizeof(AIDirection));
     v11 = a3.uDistance - v10;
     v28 = a3.uDistance - v10;
@@ -1183,7 +1183,7 @@
                 { 
                 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));
+                Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v9, 0);
                 memcpy(&a4, &v9, sizeof(AIDirection));     
                 curr_acror->uCurrentActionTime += pEventTimer->uTimeElapsed;
                 if ( curr_acror->uCurrentActionTime > curr_acror->uCurrentActionLength )
--- a/mm7_3.cpp	Tue Oct 22 00:04:14 2013 -0700
+++ b/mm7_3.cpp	Tue Oct 22 00:39:04 2013 -0700
@@ -6863,7 +6863,7 @@
   {
     v11 = uNumActors;
     SpawnEncounter(&pMapStats->pInfos[v10], &v16, 0, count, 0);
-    memcpy(&v15, Actor::GetDirectionInfo(PID(OBJECT_Actor, v11), 4u, &a3, 1), sizeof(v15));
+    Actor::GetDirectionInfo(PID(OBJECT_Actor, v11), 4u, &v15, 1);
     v12 = v11;
     if ( (signed int)v11 < (signed int)uNumActors )
     {