changeset 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 d04017f3d2fa
children 63e1388c5463
files Actor.cpp Actor.h CastSpellInfo.cpp Game.cpp Indoor.cpp Monsters.cpp Outdoor.cpp Party.cpp Player.cpp SpriteObject.cpp SpriteObject.h mm7_3.cpp mm7_4.cpp mm7_5.cpp mm7_unsorted_subs.h
diffstat 15 files changed, 346 insertions(+), 344 deletions(-) [+]
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
--- a/Actor.h	Sat Apr 05 20:14:15 2014 +0200
+++ b/Actor.h	Sat Apr 05 20:27:09 2014 +0200
@@ -229,6 +229,15 @@
 
   static bool _46DF1A_collide_against_actor(int a1, int a2);
   static void Arena_summon_actor(int monster_id, __int16 x, int y, int z);
+  static void DamageMonsterFromParty(signed int a1, unsigned int uActorID_Monster, struct Vec3_int_ *pVelocity);
+  static void MakeActorAIList_ODM();
+  static int MakeActorAIList_BLV();
+  static void UpdateActorAI();
+  static void InitializeActors();
+  static unsigned int SearchAliveActors(unsigned int *pTotalActors);
+  static unsigned int SearchActorByMonsterID(unsigned int *pTotalActors, int uMonsterID);
+  static unsigned int SearchActorByGroup(unsigned int *pTotalActors, unsigned int uGroup);
+  static unsigned int SearchActorByID(unsigned int *pTotalActors, unsigned int a2);
 
 
   void LootActor();
--- a/CastSpellInfo.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/CastSpellInfo.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -430,7 +430,7 @@
           pSpellSprite.vPosition.z = pActors[mon_id].vPosition.z;
           pSpellSprite.vPosition.y = pActors[mon_id].vPosition.y;
           pSpellSprite.spell_target_pid = PID(OBJECT_Actor, mon_id);
-          DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), mon_id, &v697);
+          Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), mon_id, &v697);
         }
         spell_sound_flag = true;
         break;
@@ -462,7 +462,7 @@
           pSpellSprite.vPosition.y = pActors[mon_id].vPosition.y;
           pSpellSprite.vPosition.z = pActors[mon_id].vPosition.z;
           pSpellSprite.spell_target_pid = PID(OBJECT_Actor, mon_id);
-          DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), mon_id, &v704);
+          Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), mon_id, &v704);
         }
         spell_sound_flag = true;
         break;
@@ -501,7 +501,7 @@
           pCastSpell->uSpellID = 0;
           continue;
         }
-        DamageMonsterFromParty(PID(OBJECT_Item, obj_id), PID_ID(a2), &v691);
+        Actor::DamageMonsterFromParty(PID(OBJECT_Item, obj_id), PID_ID(a2), &v691);
         spell_sound_flag = true;
         break;
       }
@@ -929,7 +929,7 @@
             pSpellSprite.vPosition.y = pActors[mon_id].vPosition.y;
             pSpellSprite.vPosition.z = pActors[mon_id].vPosition.z - (unsigned int)(signed __int64)((double)pActors[mon_id].uActorHeight * -0.8);
             pSpellSprite.spell_target_pid = PID(OBJECT_Actor, a2);
-            DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), mon_id, &v701);
+            Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), mon_id, &v701);
             spell_sound_flag = true;
           }
           else
@@ -1110,7 +1110,7 @@
           pSpellSprite.vPosition.y = pActors[_50BF30_actors_in_viewport_ids[i]].vPosition.y;
           pSpellSprite.vPosition.z = pActors[_50BF30_actors_in_viewport_ids[i]].vPosition.z - (unsigned int)(signed __int64)((double)pActors[_50BF30_actors_in_viewport_ids[i]].uActorHeight * -0.8);
           pSpellSprite.spell_target_pid = PID(OBJECT_Actor, _50BF30_actors_in_viewport_ids[i]);
-          DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[i], &v700);
+          Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[i], &v700);
           pGame->GetStru6()->_4A81CA(&pSpellSprite);
           pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFF3C1E, 0x40);
         }
@@ -2608,7 +2608,7 @@
           pSpellSprite.vPosition.z = pActors[_50BF30_actors_in_viewport_ids[a2]].vPosition.z - 
                                    (unsigned int)(signed __int64)((double)pActors[_50BF30_actors_in_viewport_ids[a2]].uActorHeight * -0.8);
           pSpellSprite.spell_target_pid = PID(OBJECT_Actor, _50BF30_actors_in_viewport_ids[a2]);
-          DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[a2], &v688);
+          Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[a2], &v688);
         }
         for ( a2 = 0; a2 < mon_num; ++a2 )
         {
@@ -2712,7 +2712,7 @@
           pSpellSprite.vPosition.z = pActors[_50BF30_actors_in_viewport_ids[mon_id]].vPosition.z -
                 (unsigned int)(signed __int64)((double)pActors[_50BF30_actors_in_viewport_ids[mon_id]].uActorHeight * -0.8);
           pSpellSprite.spell_target_pid = PID(OBJECT_Actor, _50BF30_actors_in_viewport_ids[mon_id]);
-          DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[mon_id], &v694);
+          Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[mon_id], &v694);
         }
         //v537 = pGame->GetStru6();
         pGame->GetStru6()->_4A8BFC();
@@ -3156,7 +3156,7 @@
             pSpellSprite.vPosition.z = pActors[_50BF30_actors_in_viewport_ids[mon_id]].vPosition.z - 
                        (unsigned int)(signed __int64)((double)pActors[_50BF30_actors_in_viewport_ids[mon_id]].uActorHeight * -0.8);
             pSpellSprite.spell_target_pid = PID(OBJECT_Actor, _50BF30_actors_in_viewport_ids[mon_id]);
-            DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[mon_id], &v707);
+            Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[mon_id], &v707);
           }
         }
         int pl_num = 0;
--- a/Game.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/Game.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -363,7 +363,7 @@
           dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_0001;
         else
         {
-          UpdateActorAI();
+          Actor::UpdateActorAI();
           UpdateUserInput_and_MapSpecificStuff();
         }
       }
@@ -477,7 +477,7 @@
           dword_5B65C0 = 1;
           PrepareWorld(1);
         }
-        InitializeActors();
+        Actor::InitializeActors();
 
         int num_conscious_players = 0;
         int conscious_players_ids[4] = {-1, -1, -1, -1};
@@ -3129,7 +3129,7 @@
                     v66 = TownPortalList[uMessageParam].rot_x;
                     _5B65B4_npcdata_loword_house_or_other = TownPortalList[uMessageParam].rot_y;
                     _5B65B8_npcdata_hiword_house_or_other = v66;
-                    InitializeActors();
+                    Actor::InitializeActors();
                   }
                   v67 = (char*)pGUIWindow_CurrentMenu->Hint;
                   if ( v67 )
--- a/Indoor.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/Indoor.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -3130,8 +3130,8 @@
     Error("Out of memory loading indoor level");
   if ( !(dword_6BE364_game_settings_1 & GAME_SETTINGS_2000) )
   {
-    InitializeActors();
-    InitializeSpriteObjects();
+    Actor::InitializeActors();
+    SpriteObject::InitializeSpriteObjects();
   }
   dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_2000;
   if ( !map_id )
@@ -3544,186 +3544,6 @@
 
   return result;
 }
-//----- (004016FA) --------------------------------------------------------
-int  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;
-}
 //----- (0043FDED) --------------------------------------------------------
 void PrepareActorRenderList_BLV()
 {
--- a/Monsters.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/Monsters.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -1275,4 +1275,5 @@
       break;
   }
   return result;
-}
\ No newline at end of file
+}
+
--- a/Outdoor.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/Outdoor.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -3111,124 +3111,6 @@
     out->z = invmag * nz * 65536.0;
   }
 }
-//----- (004014E6) --------------------------------------------------------
-void 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;
-}
 //----- (0046BE0A) --------------------------------------------------------
 void ODM_UpdateUserInputAndOther()
 {
--- a/Party.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/Party.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -805,7 +805,7 @@
   signed __int64 v2; // st7@3
 
   if ( uHoursToSleep > 240 )
-    InitializeActors();
+    Actor::InitializeActors();
   v2 = (signed __int64)((7680 * uHoursToSleep) * 0.033333335);
   pParty->uTimePlayed += v2;
   for (int i = 1; i <= 4; i++)
--- a/Player.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/Player.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -8072,7 +8072,7 @@
     a3.z = actor->vPosition.z - pParty->vPosition.z;
     Vec3_int_::Normalize(&a3.x, &a3.y, &a3.z);
 
-    DamageMonsterFromParty(PID(OBJECT_Player, uActiveCharacter - 1), target_id, &a3);
+    Actor::DamageMonsterFromParty(PID(OBJECT_Player, uActiveCharacter - 1), target_id, &a3);
     if (player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_TWO_HANDED) || player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_SINGLE_HANDED))
           _42FA66_do_explosive_impact(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z + actor->uActorHeight / 2, 0, 512, uActiveCharacter);
   }
--- a/SpriteObject.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/SpriteObject.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -931,7 +931,7 @@
   uNumSpriteObjects = new_obj_pos;
 }
 //----- (00408896) --------------------------------------------------------
-void InitializeSpriteObjects()
+void SpriteObject::InitializeSpriteObjects()
 {
   for (uint i = 0; i < uNumSpriteObjects; ++i)
   {
--- a/SpriteObject.h	Sat Apr 05 20:14:15 2014 +0200
+++ b/SpriteObject.h	Sat Apr 05 20:27:09 2014 +0200
@@ -24,6 +24,7 @@
   static void OnInteraction(unsigned int uLayingItemID);
   static bool sub_42F7EB_DropItemAt(unsigned int uSpriteID, int x, int y, int z, int a4, int count, int a7, unsigned __int16 attributes, ItemGen *a9);
   static void sub_42F960_create_object(int x, int y, int z);
+  static void InitializeSpriteObjects();
 
 
   unsigned __int16 uType;
--- a/mm7_3.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/mm7_3.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -2688,8 +2688,8 @@
     (int)&thisa);
   if ( !(dword_6BE364_game_settings_1 & GAME_SETTINGS_2000) )
   {
-    InitializeActors();
-    InitializeSpriteObjects();
+    Actor::InitializeActors();
+    SpriteObject::InitializeSpriteObjects();
   }
   dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_2000;
   //v5 = 0;
--- a/mm7_4.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/mm7_4.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -345,7 +345,7 @@
         a1.vPosition.z = pActors[v14].vPosition.z;
         a1.spell_target_pid = PID(OBJECT_Actor,v14);
         v19 = a1.Create(0, 0, 0, 0);
-        DamageMonsterFromParty(PID(OBJECT_Item,v19), v14, &a3);
+        Actor::DamageMonsterFromParty(PID(OBJECT_Item,v19), v14, &a3);
       }
     }
 
--- a/mm7_5.cpp	Sat Apr 05 20:14:15 2014 +0200
+++ b/mm7_5.cpp	Sat Apr 05 20:27:09 2014 +0200
@@ -182,7 +182,7 @@
                 switch ( attacker_type )
                 {
                   case OBJECT_Player:
-                    DamageMonsterFromParty(AttackerInfo.pIDs[attacker_id], actorID, &AttackerInfo.vec_4B4[attacker_id]);
+                    Actor::DamageMonsterFromParty(AttackerInfo.pIDs[attacker_id], actorID, &AttackerInfo.vec_4B4[attacker_id]);
                     break;
                   case OBJECT_Actor:
                     if ( v36 && pActors[v3].GetActorsRelation(&pActors[actorID]) )
@@ -228,7 +228,7 @@
         Actor::ActorDamageFromMonster(PID(OBJECT_Item, uLayingItemID), PID_ID(a2), &layingitem_vel_50FDFC, pSpriteObjects[uLayingItemID].field_61);
         break;
       case OBJECT_Player:
-        DamageMonsterFromParty(PID(OBJECT_Item, uLayingItemID), PID_ID(a2), &layingitem_vel_50FDFC);
+        Actor::DamageMonsterFromParty(PID(OBJECT_Item, uLayingItemID), PID_ID(a2), &layingitem_vel_50FDFC);
         break;
       case OBJECT_Item:
         ItemDamageFromActor(PID(OBJECT_Item, uLayingItemID), PID_ID(a2), &layingitem_vel_50FDFC);
--- a/mm7_unsorted_subs.h	Sat Apr 05 20:14:15 2014 +0200
+++ b/mm7_unsorted_subs.h	Sat Apr 05 20:27:09 2014 +0200
@@ -13,23 +13,12 @@
 
 //void ShowMM7IntroVideo_and_LoadingScreen();
 unsigned int GameOverMenu(void *ecx0);
-int __fastcall SpawnRandomTreasure(struct MapInfo *a1, struct SpawnPointMM7 *a2);
-void DamageMonsterFromParty(signed int a1, unsigned int uActorID_Monster, struct Vec3_int_ *pVelocity);
 
-void MakeActorAIList_ODM();
-int MakeActorAIList_BLV();
-void UpdateActorAI();
 bool __fastcall sub_4070EF_prolly_detect_player(unsigned int uObjID, unsigned int uObj2ID);
 bool __fastcall sub_4075DB(int a1, int a2, int a3, struct BLVFace *face);
 bool __fastcall sub_4077F1(int a1, int a2, int a3, struct ODMFace *face, struct BSPVertexBuffer *a5);
 bool __fastcall sub_407A1C(int x, int z, int y, struct Vec3_int_ v); // idb
-void InitializeActors();
-void InitializeSpriteObjects();
 int __fastcall sub_4088E9(int a1, int a2, int a3, int a4, int a5, int a6);
-unsigned int SearchAliveActors(unsigned int *pTotalActors);
-unsigned int SearchActorByMonsterID(unsigned int *pTotalActors, int uMonsterID);
-unsigned int SearchActorByGroup(unsigned int *pTotalActors, unsigned int uGroup);
-unsigned int SearchActorByID(unsigned int *pTotalActors, unsigned int a2);
 void PrepareArcomage();
 void DoBlt_Copy(unsigned __int16 *pPixels); // idb
 void __fastcall ZBuffer_Fill(int *pZBuffer, int uTextureId, int iZValue);