diff Actor.cpp @ 417:55684f4eda73

Actor::SelectTarget & ai_near_actors_targets_pid
author Nomad
date Sat, 23 Feb 2013 19:31:56 +0200
parents d8b3056df4e2
children e5cf03a3d98e
line wrap: on
line diff
--- a/Actor.cpp	Sat Feb 23 17:15:36 2013 +0200
+++ b/Actor.cpp	Sat Feb 23 19:31:56 2013 +0200
@@ -3055,42 +3055,19 @@
 //----- (00402F87) --------------------------------------------------------
 void Actor::AI_Bored(unsigned int uActorID, unsigned int uObjID, AIDirection *a4)
 {
-  //int v3; // edi@1
-  //AIDirection *v4; // esi@1
-  //Actor *v5; // ebx@1
-  //SpriteFrame *v6; // ecx@3
   unsigned int v7; // eax@3
-  //int v8; // edx@3
   unsigned int v9; // eax@3
-  //int result; // eax@4
-  AIDirection a3; // [sp+Ch] [bp-5Ch]@2
-  //AIDirection v12; // [sp+28h] [bp-40h]@2
-  //AIDirection v13; // [sp+44h] [bp-24h]@2
-  //unsigned int v14; // [sp+60h] [bp-8h]@1
-  //unsigned int v15; // [sp+64h] [bp-4h]@1
 
   assert(uActorID < uNumActors);
   auto actor = pActors + uActorID;
-
-  //v3 = uActorID;
-  //v4 = a4;
-  //v5 = &pActors[uActorID];
-  //v14 = uObjID;
-  //v15 = uActorID;
+  
+  AIDirection a3; // [sp+Ch] [bp-5Ch]@2
   if (!a4)
     a4 = Actor::GetDirectionInfo(8 * uActorID | OBJECT_Actor, uObjID, &a3, 0);
-  /*{
-    memcpy(&v13, Actor::GetDirectionInfo(8 * uActorID | OBJECT_Actor, uObjID, &a3, (int)a4), sizeof(v13));
-    memcpy(&v12, &v13, sizeof(v12));
-    v3 = v15;
-    v4 = &v12;
-  }*/
 
-  //v6 = pSpriteFrameTable->pSpriteSFrames;
   actor->uCurrentActionLength = 8 * pSpriteFrameTable->pSpriteSFrames[actor->pSpriteIDs[ANIM_Bored]].uAnimLength;
 
   v7 = stru_5C6E00->Atan2(actor->vPosition.x - pIndoorCamera->pos.x, actor->vPosition.y - pIndoorCamera->pos.y);
-  //LOWORD(v8) = actor->uYawAngle;
   v9 = stru_5C6E00->uIntegerPi + actor->uYawAngle + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v7;
 
   if ( BYTE1(v9) & 7 )      // turned away - just stand
@@ -3572,146 +3549,137 @@
   v6->UpdateAnimation();
 }
 
-//----- (00401221) --------------------------------------------------------
-void Actor::_401221(unsigned int uActorID, int *a2, unsigned int a3)
+//----- (00SelectTarget) --------------------------------------------------------
+void Actor::_SelectTarget(unsigned int uActorID, int *a2, bool can_target_party)
 {
-  Actor *v3; // esi@1
-  unsigned int v4; // ebx@1
+  //Actor *v3; // esi@1
+  //unsigned int v4; // ebx@1
   int v5; // ecx@1
-  unsigned int v6; // eax@1
-  Actor *v7; // edi@2
-  __int16 v8; // ax@3
+  //unsigned int v6; // eax@1
+  //Actor *v7; // edi@2
+  //__int16 v8; // ax@3
   int v9; // eax@10
   signed int v10; // eax@13
   int v11; // ebx@16
   int v12; // eax@16
-  int v13; // eax@25
+  //int v13; // eax@25
   signed int v14; // eax@31
   int v15; // edi@43
   int v16; // ebx@45
   int v17; // eax@45
-  int v18; // eax@51
+  //int v18; // eax@51
   int v19; // [sp+Ch] [bp-24h]@16
-  int *v20; // [sp+10h] [bp-20h]@1
+  //int *v20; // [sp+10h] [bp-20h]@1
   signed int v21; // [sp+14h] [bp-1Ch]@1
-  unsigned int v22; // [sp+18h] [bp-18h]@1
+  //unsigned int v22; // [sp+18h] [bp-18h]@1
   int v23; // [sp+1Ch] [bp-14h]@16
-  unsigned int v24; // [sp+20h] [bp-10h]@1
+  //unsigned int v24; // [sp+20h] [bp-10h]@1
   int v25; // [sp+24h] [bp-Ch]@1
-  signed int v26; // [sp+28h] [bp-8h]@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;
-  v22 = uActorID;
-  v3 = &pActors[uActorID];
-  v4 = 0;
+  //v22 = uActorID;
+  //v3 = &pActors[uActorID];
+  //v4 = 0;
   v5 = 0;
-  v6 = v3->uLastCharacterIDToHit;
+  //v6 = v3->uLastCharacterIDToHit;
   *a2 = 0;
-  v20 = a2;
+  //v20 = a2;
   v21 = 0;
-  v24 = v6;
-  v26 = 0;
-  if ( (signed int)uNumActors > 0 )
+  //v24 = v3->uLastCharacterIDToHit;
+  //v26 = 0;
+  assert(uActorID < uNumActors);
+  auto _this = pActors + uActorID;
+
+  for (uint i = 0; i < uNumActors; ++i)
   {
-	  v7 = pActors;
-	  do
-	  {
-		v8 = v7->uAIState;
-		if ( v7->uAIState == 5 || v8 == 4 || v8 == 11 || v8 == 17 || v8 == 19 || v22 == v5 )
+    auto actor = pActors + i;
+	  //v7 = pActors;
+	  //do
+	  //{
+		//v8 = v7->uAIState;
+    if (actor->uAIState == Dead || actor->uAIState == Dying ||
+        actor->uAIState == Removed || actor->uAIState == Summoned || actor->uAIState == Disabled || uActorID == i )
+      continue;
+
+		if (_this->uLastCharacterIDToHit == 0 || (v9 = 8 * v5, LOBYTE(v9) = 8 * v5 | 3, _this->uLastCharacterIDToHit != v9) )
 		{
-			++v7;
-			v5 = v26++ + 1;
+		  v10 = _this->GetActorsRelation(actor);
+		  if ( v10 == 0 )
 			continue;
 		}
-		if ( v24 == v4 || (v9 = 8 * v5, LOBYTE(v9) = 8 * v5 | 3, v24 != v9) )
+		else if (_this->IsNotAlive())
 		{
-		  v10 = v3->GetActorsRelation(v7);
-		  if ( v10 == v4 )
-		  {
-			++v7;
-			v5 = v26++ + 1;
+		  _this->uLastCharacterIDToHit = 0;
+		  v10 = _this->GetActorsRelation(actor);
+		  if ( v10 == 0 )
 			continue;
-		  }
-		}
-		else if (v7->IsNotAlive())
-		{
-		  v24 = v4;
-		  v3->uLastCharacterIDToHit = v4;
-		  v10 = v3->GetActorsRelation(v7);
-		  if ( v10 == v4 )
-		  {
-			++v7;
-			v5 = v26++ + 1;
-			continue;
-		  }
 		}
 		else
 		{
-			v18 = v7->uGroup;
-			if ( (v18 != v4 || v3->uGroup != v4) && v18 == v3->uGroup )
-			{
-				++v7;
-				v5 = v26++ + 1;
+			//v18 = actor->uGroup;
+			if ( (actor->uGroup != 0 || _this->uGroup != 0) && actor->uGroup == _this->uGroup )
 				continue;
-			}
 			v10 = 4;
 		}
-		if ( v3->pMonsterInfo.uHostilityType )
-		  v10 = pMonsterStats->pInfos[v3->pMonsterInfo.uID].uHostilityType;
+		if ( _this->pMonsterInfo.uHostilityType )
+		  v10 = pMonsterStats->pInfos[_this->pMonsterInfo.uID].uHostilityType;
 		v11 = dword_4DF380[v10];
-		v23 = abs(v3->vPosition.x - v7->vPosition.x);
-		v27 = abs(v3->vPosition.y - v7->vPosition.y);
-		v12 = abs(v3->vPosition.z - v7->vPosition.z);
+		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;
 		if ( v23 <= v11
 		  && v27 <= v11
 		  && v12 <= v11
-		  && sub_4070EF_prolly_collide_objects(8 * v26 | 3, 8 * v22 | 3)
+		  && sub_4070EF_prolly_collide_objects(8 * i | OBJECT_Actor, 8 * uActorID | OBJECT_Actor)
 		  && v23 * v23 + v27 * v27 + v19 * v19 < (unsigned int)v25 )
 		{
 		  v25 = v23 * v23 + v27 * v27 + v19 * v19;
-		  v21 = v26;
+		  v21 = i;
 		}
-		v4 = 0;
-		++v7;
-		v5 = v26++ + 1;
-	  }
-	  while ( v26 < (signed int)uNumActors );
-	  if ( v25 != -1 )
-	  {
-		v13 = 8 * v21;
-		LOBYTE(v13) = 8 * v21 | 3;
-		*v20 = v13;
-	  }
+		//v4 = 0;
+		//++v7;
+		//v5 = v26++ + 1;
+	  //}
+	  //while ( v26 < (signed int)uNumActors );
+
   }
-  if ( SHIDWORD(pParty->pPartyBuffs[11].uExpireTime) >= (signed int)v4
-    && (SHIDWORD(pParty->pPartyBuffs[11].uExpireTime) > (signed int)v4 || LODWORD(pParty->pPartyBuffs[11].uExpireTime) > v4) )
-    a3 = v4;
-  if ( a3 != v4 )
+  	  if ( v25 != -1 )
+	  {
+		//v13 = 8 * v21;
+		//LOBYTE(v13) = 8 * v21 | OBJECT_Actor;
+		*a2 = 8 * v21 | OBJECT_Actor;
+	  }
+
+  if (pParty->Invisible())
+    can_target_party = false;
+
+  if (can_target_party)
   {
-    v14 = v3->GetActorsRelation(0);
-    if ( BYTE2(v3->uAttributes) & 8
-      && SHIDWORD(v3->pActorBuffs[12].uExpireTime) <= (signed int)v4
-      && (SHIDWORD(v3->pActorBuffs[12].uExpireTime) < (signed int)v4 || LODWORD(v3->pActorBuffs[12].uExpireTime) <= v4)
-      && SHIDWORD(v3->pActorBuffs[1].uExpireTime) <= (signed int)v4
-      && (SHIDWORD(v3->pActorBuffs[1].uExpireTime) < (signed int)v4 || LODWORD(v3->pActorBuffs[1].uExpireTime) <= v4)
-      && SHIDWORD(v3->pActorBuffs[2].uExpireTime) <= (signed int)v4
-      && (SHIDWORD(v3->pActorBuffs[2].uExpireTime) < (signed int)v4 || LODWORD(v3->pActorBuffs[2].uExpireTime) <= v4) )
+    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 = 4;
-    if ( v14 != v4 )
+    if ( v14 != 0 )
     {
       v15 = dword_4DF390;
-      if ( !v3->pMonsterInfo.uHostilityType )
+      if ( !_this->pMonsterInfo.uHostilityType )
         v15 = dword_4DF380[v14];
-      v16 = abs(v3->vPosition.x - pParty->vPosition.x);
-      v28 = abs(v3->vPosition.y - pParty->vPosition.y);
-      v17 = abs(v3->vPosition.z - pParty->vPosition.z);
+      v16 = abs(_this->vPosition.x - pParty->vPosition.x);
+      v28 = abs(_this->vPosition.y - pParty->vPosition.y);
+      v17 = abs(_this->vPosition.z - pParty->vPosition.z);
       if ( v16 <= v15 && v28 <= v15 && v17 <= v15 )
       {
         if ( v16 * v16 + v28 * v28 + v17 * v17 < (unsigned int)v25 )
-          *v20 = 4;
+          *a2 = OBJECT_Player;
       }
     }
   }