diff Actor.cpp @ 2338:1e865e8690ba

Moving some function declarations from unsorted subs to Actor.h and SpriteObject.h
author Grumpy7
date Sat, 05 Apr 2014 20:27:09 +0200
parents d6887ee81068
children 4100fb5c4913
line wrap: on
line diff
--- a/Actor.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/Actor.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -2827,7 +2827,7 @@
   return true;
 }
 //----- (00401A91) --------------------------------------------------------
-void  UpdateActorAI()
+void  Actor::UpdateActorAI()
 {
 	signed int v4; // edi@10
 	signed int sDmg; // eax@14
@@ -2862,9 +2862,9 @@
 	uint v38;
 	
 	if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-		MakeActorAIList_ODM();
+		Actor::MakeActorAIList_ODM();
 	else
-		MakeActorAIList_BLV();
+		Actor::MakeActorAIList_BLV();
 	
 	if ( uCurrentlyLoadedLevelType != LEVEL_Indoor && pParty->armageddon_timer > 0 )
 	{
@@ -3297,21 +3297,21 @@
   if ( uType )
   {
     if ( uType == 1 )
-      uAliveActors = SearchActorByGroup(&uTotalActors, uParam);
+      uAliveActors = Actor::SearchActorByGroup(&uTotalActors, uParam);
     else
     {
       if ( uType == 2 )
-        uAliveActors = SearchActorByMonsterID(&uTotalActors, uParam);
+        uAliveActors = Actor::SearchActorByMonsterID(&uTotalActors, uParam);
       else
       {
         if ( uType != 3 )
           return 0;
-        uAliveActors = SearchActorByID(&uTotalActors, uParam);
+        uAliveActors = Actor::SearchActorByID(&uTotalActors, uParam);
       }
     }
   }
   else
-    uAliveActors = SearchAliveActors(&uTotalActors);
+    uAliveActors = Actor::SearchAliveActors(&uTotalActors);
 
   if (uNumAlive)
     return uAliveActors >= uNumAlive;
@@ -3319,7 +3319,7 @@
     return uTotalActors == uAliveActors;
 }
 //----- (00408B54) --------------------------------------------------------
-unsigned int SearchActorByID(unsigned int *pTotalActors, unsigned int a2)
+unsigned int Actor::SearchActorByID(unsigned int *pTotalActors, unsigned int a2)
 {
   int v4; // eax@1
   unsigned int v5; // ebx@1
@@ -3335,7 +3335,7 @@
   return v5;
 }
 //----- (00408AE7) --------------------------------------------------------
-unsigned int SearchActorByGroup(unsigned int *pTotalActors, unsigned int uGroup)
+unsigned int Actor::SearchActorByGroup(unsigned int *pTotalActors, unsigned int uGroup)
 {
   int v8; // [sp+Ch] [bp-8h]@1
   unsigned int v9; // [sp+10h] [bp-4h]@1
@@ -3357,7 +3357,7 @@
   return v9;
 }
 //----- (00408A7E) --------------------------------------------------------
-unsigned int SearchActorByMonsterID(unsigned int *pTotalActors, int uMonsterID)
+unsigned int Actor::SearchActorByMonsterID(unsigned int *pTotalActors, int uMonsterID)
 {
   Actor *v4; // edi@2
   int v8; // [sp+Ch] [bp-8h]@1
@@ -3379,7 +3379,7 @@
   return v9;
 }
 //----- (00408A27) --------------------------------------------------------
-unsigned int SearchAliveActors(unsigned int *pTotalActors)
+unsigned int Actor::SearchAliveActors(unsigned int *pTotalActors)
 {
   int v2; // eax@1
   unsigned int v3; // ebp@1
@@ -3401,7 +3401,7 @@
   return v3;
 }
 //----- (00408768) --------------------------------------------------------
-void InitializeActors()
+void Actor::InitializeActors()
 {
   signed int v5; // [sp+Ch] [bp-10h]@1
   signed int v6; // [sp+10h] [bp-Ch]@1
@@ -3451,7 +3451,7 @@
   }
 }
 //----- (00439474) --------------------------------------------------------
-void DamageMonsterFromParty(signed int a1, unsigned int uActorID_Monster, Vec3_int_ *pVelocity)
+void Actor::DamageMonsterFromParty(signed int a1, unsigned int uActorID_Monster, Vec3_int_ *pVelocity)
 {
   SpriteObject *projectileSprite; // ebx@1
   Actor *pMonster; // esi@7
@@ -4416,4 +4416,304 @@
       }
     }
   }
+}
+
+//----- (004014E6) --------------------------------------------------------
+void Actor::MakeActorAIList_ODM()
+{
+  int v1; // eax@4
+//  int v2; // ebx@4
+//  unsigned int v3; // ecx@4
+//  int v4; // edx@5
+//  int v5; // edx@7
+//  unsigned int v6; // edx@9
+  unsigned int v7; // ST20_4@10
+  int v9; // edi@10
+  int v10; // ebx@14
+  int v21; // [sp+Ch] [bp-14h]@4
+  int v22; // [sp+10h] [bp-10h]@4
+
+  pParty->uFlags &= 0xFFFFFFCFu;
+
+  ai_arrays_size = 0;
+  for (uint i = 0; i < uNumActors; ++i)
+  {
+    Actor* actor = &pActors[i];
+
+    actor->uAttributes &= 0xFFFFFBFF;
+    if (!actor->CanAct())
+    {
+      actor->uAttributes &= 0xFFFFBFFF;
+      continue;
+    }
+
+    v22 = abs(pParty->vPosition.z - actor->vPosition.z);
+    v21 = abs(pParty->vPosition.y - actor->vPosition.y);
+    v1 = abs(pParty->vPosition.x - actor->vPosition.x);
+      v7 = int_get_vector_length(v22, v21, v1);
+	  //v8 = actor->uActorRadius;
+      v9 = v7 - actor->uActorRadius;
+      //v23 = v7 - v8;
+      if ( v9 < 0 )
+      {
+        v9 = 0;
+        //v23 = 0;
+      }
+
+      if (v9 < 5632)
+      {
+        v10 = actor->uAttributes & 0xFEFFFFFF;
+        actor->uAttributes = v10;
+        if ( v10 & 0x80000 || actor->GetActorsRelation(0) )
+        {
+          //v11 = (pParty->uFlags & 0x10) == 0;
+          actor->uAttributes = v10 | 0x1000000;
+          if (v9 < 5120 )
+            pParty->SetYellowAlert();
+          if (v9 < 307)
+            pParty->SetRedAlert();
+        }
+		actor->uAttributes |= 0x00004000;
+        ai_near_actors_distances[ai_arrays_size] = v9;
+        ai_near_actors_ids[ai_arrays_size++] = i;
+      }
+      else
+		  actor->uAttributes &= 0xFFFFBFFF;
+  }
+
+  /*
+  result = v27;
+  if ( v27 > 0 )
+  {
+    v14 = 0;
+    v15 = 1;
+    v26 = 1;
+    do
+    {
+      while ( 1 )
+      {
+        v24 = v15;
+        if ( v15 >= result )
+          break;
+        v16 = ai_near_actors_distances[v14];
+        if ( v16 > ai_near_actors_distances[v15] )
+        {
+          v17 = &ai_near_actors_ids[v15];
+          v18 = ai_near_actors_ids[v14];
+          ai_near_actors_ids[v14] = *v17;
+          *v17 = v18;
+          v15 = v24;
+          ai_near_actors_distances[v14] = ai_near_actors_distances[v24];
+          ai_near_actors_distances[v24] = v16;
+        }
+        result = v27;
+        ++v15;
+      }
+      ++v14;
+      v15 = v26 + 1;
+      v26 = v15;
+    }
+    while ( v15 - 1 < result );
+  }*/
+
+  for (uint i = 0; i < ai_arrays_size; ++i)
+    for (uint j = 0; j < i; ++j)
+      if (ai_near_actors_distances[j] > ai_near_actors_distances[i])
+      {
+        int tmp = ai_near_actors_distances[j];
+        ai_near_actors_distances[j] = ai_near_actors_distances[i];
+        ai_near_actors_distances[i] = tmp;
+
+        tmp = ai_near_actors_ids[j];
+        ai_near_actors_ids[j] = ai_near_actors_ids[i];
+        ai_near_actors_ids[i] = tmp;
+      }
+
+
+  if (ai_arrays_size > 30)
+    ai_arrays_size = 30;
+
+  for (uint i = 0; i < ai_arrays_size; ++i)
+    pActors[ai_near_actors_ids[i]].uAttributes |= 0x0400;
+}
+
+//----- (004016FA) --------------------------------------------------------
+int  Actor::MakeActorAIList_BLV()
+{
+  //Actor *v0; // esi@2
+  int v1; // eax@4
+  //  int v2; // ebx@4
+  //  unsigned int v3; // ecx@4
+  //  int v4; // edx@5
+  //  int v5; // edx@7
+  //  unsigned int v6; // edx@9
+  unsigned int v7; // ST24_4@10
+  //  int v8; // eax@10
+  int v9; // edi@10
+  //  int v10; // ebx@14
+  //  char v11; // zf@16
+  int v12; // eax@22
+  int v13; // edx@24
+  //  int v14; // ecx@25
+  int v15; // ebx@26
+  //  unsigned int *v16; // ecx@27
+  unsigned int v17; // esi@27
+  int v18; // ecx@31
+  signed int v19; // edi@31
+  //  Actor *v20; // esi@32
+  //  bool v21; // eax@33
+  //  int v22; // eax@34
+  //  signed int v23; // ebx@36
+  //  Actor *v24; // esi@37
+  signed int v25; // eax@40
+  //  int v26; // eax@43
+  int v27; // ebx@45
+  int j; // edi@45
+  //  unsigned int v29; // eax@46
+  int v30; // eax@48
+  //  int v31; // ecx@51
+  //  int v32; // eax@51
+  //  signed int v33; // eax@53
+  //  __int64 v34; // qax@55
+  //  char *v35; // ecx@56
+  int v37; // [sp+Ch] [bp-18h]@1
+  int v38; // [sp+10h] [bp-14h]@4
+  int v39; // [sp+14h] [bp-10h]@4
+  //int v40; // [sp+18h] [bp-Ch]@10
+  //  int v41; // [sp+18h] [bp-Ch]@29
+  int i; // [sp+18h] [bp-Ch]@31
+  //signed int v43; // [sp+1Ch] [bp-8h]@1
+  //  signed int v44; // [sp+1Ch] [bp-8h]@25
+  int v45; // [sp+20h] [bp-4h]@1
+
+  //  __debugbreak(); // refactor for blv ai
+  pParty->uFlags &= 0xFFFFFFCFu;
+  v37 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
+  v45 = 0;
+  for ( uint i = 0; i < (signed int)uNumActors; ++i )
+  {
+    pActors[i].uAttributes &= 0xFB00;
+    if ( !pActors[i].CanAct() )
+    {
+      pActors[i].uAttributes &= 0xBF00;
+      continue;
+    }
+    v39 = abs(pParty->vPosition.z - pActors[i].vPosition.z);
+    v38 = abs(pParty->vPosition.y - pActors[i].vPosition.y);
+    v1 = abs(pParty->vPosition.x - pActors[i].vPosition.x);
+    v7 = int_get_vector_length(v39, v38, v1);
+    v9 = v7 - pActors[i].uActorRadius;
+    if ( v9 < 0 )
+      v9 = 0;
+    if ( v9 < 10240 )
+    {
+      pActors[i].uAttributes &= 0xFEFFFFFF;
+      if ( pActors[i].uAttributes & 0x80000 || pActors[i].GetActorsRelation(0) )
+      {
+        pActors[i].uAttributes |= 0x1000000;
+        if ( !(pParty->uFlags & 0x10) && (double)v9 < 307.2 )
+          pParty->uFlags |= 0x10;
+        if ( !(pParty->uFlags & 0x20) && v9 < 5120 )
+          pParty->uFlags |= 0x20;
+      }
+      v12 = v45++;
+      ai_near_actors_distances[v12] = v9;
+      ai_near_actors_ids[v12] = i;
+    }
+    else
+      pActors[i].uAttributes &= 0xBF00;
+  }
+  v13 = 0;
+  if ( v45 > 0 )
+  {
+    for ( uint i = 1; i < v45; i++ )
+    {
+      for ( uint j = 1; j < v45; ++j )
+      {
+        v15 = ai_near_actors_distances[v13];
+        if ( ai_near_actors_distances[v13] > ai_near_actors_distances[j] )
+        {
+          v17 = ai_near_actors_ids[v13];
+          ai_near_actors_ids[v13] = ai_near_actors_ids[j];
+          ai_near_actors_ids[j] = v17;
+          ai_near_actors_distances[v13] = ai_near_actors_distances[j];
+          ai_near_actors_distances[j] = v15;
+        }
+      }
+      ++v13;
+    }
+  }
+  v18 = 0;
+  v19 = 0;
+  for ( i = 0; i < v45; i++ )
+  {
+    if ( pActors[ai_near_actors_ids[i]].uAttributes & 0x8000
+      || sub_4070EF_prolly_detect_player(PID(OBJECT_Actor,ai_near_actors_ids[i]), 4) )
+    {
+      pActors[ai_near_actors_ids[i]].uAttributes |= 0x8000;
+      ai_array_4F6638_actor_ids[v19] = ai_near_actors_ids[i];
+      ai_array_4F5E68[v19++] = ai_near_actors_distances[i];
+      if ( v19 >= 30 )
+        break;
+    }
+  }
+  ai_arrays_size = v19;
+  if ( (signed int)uNumActors > 0 )
+  {
+    for ( uint i = 0; i < (signed int)uNumActors; ++i )
+    {
+      if ( pActors[i].CanAct() && pActors[i].uSectorID == v37 )
+      {
+        v25 = 0;
+        if ( v19 <= 0 )
+        {
+          pActors[i].uAttributes |= 0x4000;
+          ai_array_4F6638_actor_ids[ai_arrays_size++] = i;
+        }
+        else
+        {
+          while ( ai_array_4F6638_actor_ids[v25] != i )
+          {
+            ++v25;
+            if ( v25 >= v19 )
+            {
+              pActors[i].uAttributes |= 0x4000;
+              ai_array_4F6638_actor_ids[ai_arrays_size++] = i;
+              break;
+            }
+          }
+        }
+      }
+    }
+  }
+  v27 = ai_arrays_size;
+  for ( j = 0; j < v45; ++j )
+  {
+    //v29 = ai_near_actors_ids[j];
+    if ( pActors[ai_near_actors_ids[j]].uAttributes & 0xC000 && pActors[ai_near_actors_ids[j]].CanAct() )
+    {
+      v30 = 0;
+      if ( v27 <= 0 )
+        ai_array_4F6638_actor_ids[ai_arrays_size++] = ai_near_actors_ids[j];
+      else
+      {
+        while ( ai_array_4F6638_actor_ids[v30] != ai_near_actors_ids[j] )
+        {
+          ++v30;
+          if ( v30 >= v27 )
+          {
+            ai_array_4F6638_actor_ids[ai_arrays_size++] = ai_near_actors_ids[j];
+            break;
+          }
+        }
+      }
+    }
+  }
+  if ( ai_arrays_size > 30 )
+    ai_arrays_size = 30;
+  memcpy(ai_near_actors_ids.data(), ai_array_4F6638_actor_ids.data(), 4 * ai_arrays_size);
+  memcpy(ai_near_actors_distances.data(), ai_array_4F5E68.data(), 4 * ai_arrays_size);
+  for ( uint i = 0; i < ai_arrays_size; i++ )
+    pActors[ai_near_actors_ids[i]].uAttributes |= 0x400;
+  return ai_arrays_size;
 }
\ No newline at end of file