changeset 1889:397059718a9a

Actor::_SelectTarget, Actor::GetActorsRelation some cleanups
author Grumpy7
date Sat, 19 Oct 2013 21:26:31 -0700
parents cbeb25a148ad
children eafc12a77a92
files Actor.cpp
diffstat 1 files changed, 87 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Sat Oct 19 08:21:57 2013 +0200
+++ b/Actor.cpp	Sat Oct 19 21:26:31 2013 -0700
@@ -2380,18 +2380,18 @@
   int v16; // ebx@45
   int v17; // eax@45
   //int v18; // eax@51
-  int v19; // [sp+Ch] [bp-24h]@16
+  int v12; // [sp+Ch] [bp-24h]@16
   //int *v20; // [sp+10h] [bp-20h]@1
   signed int v21; // [sp+14h] [bp-1Ch]@1
   //unsigned int v22; // [sp+18h] [bp-18h]@1
   int v23; // [sp+1Ch] [bp-14h]@16
   //unsigned int v24; // [sp+20h] [bp-10h]@1
-  int v25; // [sp+24h] [bp-Ch]@1
+  unsigned int v25; // [sp+24h] [bp-Ch]@1
   //signed int v26; // [sp+28h] [bp-8h]@1
   int v27; // [sp+2Ch] [bp-4h]@16
   int v28; // [sp+2Ch] [bp-4h]@45
 
-  v25 = -1;
+  v25 = UINT_MAX;
   //v22 = uActorID;
   //v3 = &pActors[uActorID];
   //v4 = 0;
@@ -2403,7 +2403,7 @@
   //v24 = v3->uLastCharacterIDToHit;
   //v26 = 0;
   assert(uActorID < uNumActors);
-  auto _this = &pActors[uActorID];
+  Actor* thisActor = &pActors[uActorID];
 
   for (uint i = 0; i < uNumActors; ++i)
   {
@@ -2416,40 +2416,39 @@
         actor->uAIState == Removed || actor->uAIState == Summoned || actor->uAIState == Disabled || uActorID == i )
       continue;
 
-		if (_this->uLastCharacterIDToHit == 0 || (v9 = 8 * v5, LOBYTE(v9) = PID(OBJECT_Actor,v5), _this->uLastCharacterIDToHit != v9) )
+		if (thisActor->uLastCharacterIDToHit == 0 || PID(OBJECT_Actor,v5) != thisActor->uLastCharacterIDToHit )
 		{
-		  v10 = _this->GetActorsRelation(actor);
+		  v10 = thisActor->GetActorsRelation(actor);
 		  if ( v10 == 0 )
 			continue;
 		}
-		else if (_this->IsNotAlive())
+		else if (thisActor->IsNotAlive())
 		{
-		  _this->uLastCharacterIDToHit = 0;
-		  v10 = _this->GetActorsRelation(actor);
+		  thisActor->uLastCharacterIDToHit = 0;
+		  v10 = thisActor->GetActorsRelation(actor);
 		  if ( v10 == 0 )
 			continue;
 		}
 		else
 		{
 			//v18 = actor->uGroup;
-			if ( (actor->uGroup != 0 || _this->uGroup != 0) && actor->uGroup == _this->uGroup )
+			if ( (actor->uGroup != 0 || thisActor->uGroup != 0) && actor->uGroup == thisActor->uGroup )
 				continue;
 			v10 = 4;
 		}
-		if ( _this->pMonsterInfo.uHostilityType )
-		  v10 = pMonsterStats->pInfos[_this->pMonsterInfo.uID].uHostilityType;
+		if ( thisActor->pMonsterInfo.uHostilityType )
+		  v10 = pMonsterStats->pInfos[thisActor->pMonsterInfo.uID].uHostilityType;
 		v11 = dword_4DF380[v10];
-		v23 = abs(_this->vPosition.x - actor->vPosition.x);
-		v27 = abs(_this->vPosition.y - actor->vPosition.y);
-		v12 = abs(_this->vPosition.z - actor->vPosition.z);
-		v19 = v12;
+		v23 = abs(thisActor->vPosition.x - actor->vPosition.x);
+		v27 = abs(thisActor->vPosition.y - actor->vPosition.y);
+		v12 = abs(thisActor->vPosition.z - actor->vPosition.z);
 		if ( v23 <= v11
 		  && v27 <= v11
 		  && v12 <= v11
 		  && sub_4070EF_prolly_detect_player(PID(OBJECT_Actor, i), PID(OBJECT_Actor, uActorID))
-		  && v23 * v23 + v27 * v27 + v19 * v19 < (unsigned int)v25 )
+		  && v23 * v23 + v27 * v27 + v12 * v12 < v25 )
 		{
-		  v25 = v23 * v23 + v27 * v27 + v19 * v19;
+		  v25 = v23 * v23 + v27 * v27 + v12 * v12;
 		  v21 = i;
 		}
 		//v4 = 0;
@@ -2471,26 +2470,26 @@
 
   if (can_target_party)
   {
-    v14 = _this->GetActorsRelation(0);
-    if ( BYTE2(_this->uAttributes) & 8
-      && SHIDWORD(_this->pActorBuffs[12].uExpireTime) <= (signed int)0
-      && (SHIDWORD(_this->pActorBuffs[12].uExpireTime) < (signed int)0 || LODWORD(_this->pActorBuffs[12].uExpireTime) <= 0)
-      && SHIDWORD(_this->pActorBuffs[1].uExpireTime) <= (signed int)0
-      && (SHIDWORD(_this->pActorBuffs[1].uExpireTime) < (signed int)0 || LODWORD(_this->pActorBuffs[1].uExpireTime) <= 0)
-      && SHIDWORD(_this->pActorBuffs[2].uExpireTime) <= (signed int)0
-      && (SHIDWORD(_this->pActorBuffs[2].uExpireTime) < (signed int)0 || LODWORD(_this->pActorBuffs[2].uExpireTime) <= 0) )
+    v14 = thisActor->GetActorsRelation(0);
+    if ( BYTE2(thisActor->uAttributes) & 8
+      && SHIDWORD(thisActor->pActorBuffs[12].uExpireTime) <= (signed int)0
+      && (SHIDWORD(thisActor->pActorBuffs[12].uExpireTime) < (signed int)0 || LODWORD(thisActor->pActorBuffs[12].uExpireTime) <= 0)
+      && SHIDWORD(thisActor->pActorBuffs[1].uExpireTime) <= (signed int)0
+      && (SHIDWORD(thisActor->pActorBuffs[1].uExpireTime) < (signed int)0 || LODWORD(thisActor->pActorBuffs[1].uExpireTime) <= 0)
+      && SHIDWORD(thisActor->pActorBuffs[2].uExpireTime) <= (signed int)0
+      && (SHIDWORD(thisActor->pActorBuffs[2].uExpireTime) < (signed int)0 || LODWORD(thisActor->pActorBuffs[2].uExpireTime) <= 0) )
       v14 = 4;
     if ( v14 != 0 )
     {
       v15 = dword_4DF380[4];
-      if ( !_this->pMonsterInfo.uHostilityType )
+      if ( !thisActor->pMonsterInfo.uHostilityType )
         v15 = dword_4DF380[v14];
-      v16 = abs(_this->vPosition.x - pParty->vPosition.x);
-      v28 = abs(_this->vPosition.y - pParty->vPosition.y);
-      v17 = abs(_this->vPosition.z - pParty->vPosition.z);
+      v16 = abs(thisActor->vPosition.x - pParty->vPosition.x);
+      v28 = abs(thisActor->vPosition.y - pParty->vPosition.y);
+      v17 = abs(thisActor->vPosition.z - pParty->vPosition.z);
       if ( v16 <= v15 && v28 <= v15 && v17 <= v15 )
       {
-        if ( v16 * v16 + v28 * v28 + v17 * v17 < (unsigned int)v25 )
+        if ( v16 * v16 + v28 * v28 + v17 * v17 < v25 )
           *a2 = OBJECT_Player;
       }
     }
@@ -2500,9 +2499,8 @@
 // 4DF390: using guessed type int dword_4DF390;
 
 //----- (0040104C) --------------------------------------------------------
-signed int Actor::GetActorsRelation(Actor *a2)
+signed int Actor::GetActorsRelation(Actor *otherActPtr)
 {
-  Actor *v2; // esi@1
   int v3; // ebp@5
   int v4; // edi@11
   unsigned int v5; // edx@15
@@ -2512,45 +2510,32 @@
   unsigned int v9; // edx@25
   unsigned int v10; // edx@33
 
-  auto a1 = this;
-  v2 = a2;
-  if ( a1 )
+  if ( this )
   {
-    if ( SHIDWORD(a1->pActorBuffs[9].uExpireTime) >= 0
-      && (SHIDWORD(a1->pActorBuffs[9].uExpireTime) > 0 || LODWORD(a1->pActorBuffs[9].uExpireTime) > 0) )
+    if (this->pActorBuffs[ACTOR_BUFF_BERSERK].uExpireTime > 0)
       return 4;
-    v3 = a1->pMonsterInfo.uID;
+    v3 = this->pMonsterInfo.uID;
   }
   else
   {
     v3 = 0;
   }
-  if ( a2 )
+  if ( otherActPtr )
   {
-    if ( SHIDWORD(a2->pActorBuffs[9].uExpireTime) >= 0
-      && (SHIDWORD(a2->pActorBuffs[9].uExpireTime) > 0 || LODWORD(a2->pActorBuffs[9].uExpireTime) > 0) )
+    if (otherActPtr->pActorBuffs[ACTOR_BUFF_BERSERK].uExpireTime > 0)
       return 4;
-    v4 = a2->pMonsterInfo.uID;
+    v4 = otherActPtr->pMonsterInfo.uID;
   }
   else
   {
     v4 = 0;
   }
-  if ( a2 )
+  if ( otherActPtr && this)
   {
-    if ( a1 )
-    {
-      v5 = a2->uGroup;
-      if ( v5 )
-      {
-        v6 = a1->uGroup;
-        if ( v6 )
-        {
-          if ( v5 == v6 )
-            return 0;
-        }
-      }
-    }
+    v5 = otherActPtr->uGroup;
+    v6 = this->uGroup;
+    if ( v5 != 0 && v6 != 0 && v5 == v6 )
+      return 0;
   }
   if ( v3 )
     v7 = (v3 - 1) / 3 + 1;
@@ -2560,58 +2545,66 @@
     v8 = (v4 - 1) / 3 + 1;
   else
     v8 = 0;
-  if ( a1 )
+  if ( this )
   {
-    v9 = a1->uAlly;
-    if ( (signed int)v9 > 0 )
+    if ( this->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime > 0 )
+      v7 = 0;
+    else
     {
-      if ( v9 != 9999 )
+      v9 = this->uAlly;
+      if ( v9 > 0 )
       {
-        v7 = a1->uAlly;
+        if ( v9 != 9999 )
+        {
+          v7 = this->uAlly;
+        }
+        else
+          v7 = 0;
       }
     }
-	if(v9==9999)
-      v7 = 0;
-    if ( (signed __int64)a1->pActorBuffs[12].uExpireTime > 0 )
-      v7 = 0;
   }
-  if ( v2 )
+  if ( otherActPtr )
   {
-	  v10 = v2->uAlly;
-	  if ( (signed int)v10 > 0 )
-	  {
-		if ( v10 != 9999 )
-		{
-		  v8 = v2->uAlly;
-		}
-	  }
-	  if(v10==9999)
-	    v8 = 0;
-	  if ( (signed __int64)v2->pActorBuffs[12].uExpireTime > 0 )
-		v8 = 0;
+    if ( otherActPtr->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime > 0 )
+      v8 = 0;
+    else
+    {
+      v10 = otherActPtr->uAlly;
+      if ( (signed int)v10 > 0 )
+      {
+        if ( v10 != 9999 )
+        {
+          v8 = otherActPtr->uAlly;
+        }
+        else
+        {
+          v8 = 0;
+        }
+      }
+    }
   }
-  if ( a1 && (signed __int64)a1->pActorBuffs[1].uExpireTime > 0 && !v8
-    || v2 && (signed __int64)v2->pActorBuffs[1].uExpireTime > 0 && !v7 )
+  if ( this && this->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0 && !v8
+    || otherActPtr && otherActPtr->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0 && !v7 )
     return 0;
-  if ( a1 && (signed __int64)a1->pActorBuffs[12].uExpireTime <= 0 && a1->uAttributes & 0x80000 && !v8 )
+  if ( this && this->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime <= 0 && this->uAttributes & 0x80000 && !v8 )
     return 4;
-  if ( v2 && a1 && (signed __int64)a1->pActorBuffs[12].uExpireTime <= 0 && v2->uAttributes & 0x80000 )
+  if ( otherActPtr && this && this->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime <= 0 && otherActPtr->uAttributes & 0x80000 )
   {
     if ( v7 )
-	{
-		if ( (signed int)v7 < 89 )
-		{
-		  if ( v8 < 89 )
-			return pFactionTable->relations[v7][v8];
-		  return 0;
-		}
-		return 0;
-	}
+    {
+      if ( (signed int)v7 < 89 )
+      {
+        if ( v8 < 89 )
+          return pFactionTable->relations[v7][v8];
+        return 0;
+      }
+      return 0;
+    }
     return 4;
   }
   if ( !v7 )
   {
-    if ( (!v2 || (signed __int64)v2->pActorBuffs[12].uExpireTime > 0 || !(v2->uAttributes & 0x80000))
+    if ( (!otherActPtr || otherActPtr->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime > 0 || !(otherActPtr->uAttributes & 0x80000))
       && !pFactionTable->relations[v8][0]) 
     {
       if ( v8 < 89 )
@@ -2620,7 +2613,7 @@
     }
     return 4;
   }
-  if ( (signed int)v7 < 89 )
+  if ( v7 < 89 )
   {
     if ( v8 < 89 )
       return pFactionTable->relations[v7][v8];