diff mm7_2.cpp @ 2207:ff8920a40c21

fixpoint_mul
author Ritor1
date Thu, 06 Feb 2014 17:20:12 +0600
parents 42c8807225a2
children 0b2eea6f80c9
line wrap: on
line diff
--- a/mm7_2.cpp	Thu Feb 06 00:38:03 2014 +0600
+++ b/mm7_2.cpp	Thu Feb 06 17:20:12 2014 +0600
@@ -1581,9 +1581,6 @@
 //----- (0045063B) --------------------------------------------------------
 int __fastcall _45063B_spawn_some_monster(MapInfo *a1, int a2)
 {
-  signed int v2; // edi@1
-  Actor *v3; // esi@2
-  //signed __int64 v4; // qax@3
   int result; // eax@8
   int v6; // edi@11
   int v7; // ebx@11
@@ -1599,11 +1596,7 @@
   int v17; // eax@20
   int v18; // eax@21
   SpawnPointMM7 v19; // [sp+Ch] [bp-38h]@1
-  int v20; // [sp+24h] [bp-20h]@11
-  //MapInfo *v21; // [sp+28h] [bp-1Ch]@1
   int v22; // [sp+2Ch] [bp-18h]@3
-  int v23; // [sp+30h] [bp-14h]@11
-  //int v24; // [sp+34h] [bp-10h]@1
   unsigned int uFaceID; // [sp+38h] [bp-Ch]@10
   int v26; // [sp+3Ch] [bp-8h]@11
   int v27; // [sp+40h] [bp-4h]@11
@@ -1611,27 +1604,85 @@
   if (!uNumActors)
     return 0;
 
-  //v21 = a1;
-  //v24 = a2;
-  v2 = 0;
-  v3 = pActors.data();
-  while ( 1 )
+  for ( uint mon_id = 0; mon_id < uNumActors; ++mon_id )
   {
-    if (v3->pMonsterInfo.uID >= 121 && v3->pMonsterInfo.uID <= 123 || // Dwarf FemaleC A-C
-        v3->pMonsterInfo.uID >= 124 && v3->pMonsterInfo.uID <= 126 || // Dwarf MaleA A-C
-        v3->pMonsterInfo.uID >= 133 && v3->pMonsterInfo.uID <= 135 || // Peasant Elf FemaleA A-C
-        !v3->CanAct())
+    if ((pActors[mon_id].pMonsterInfo.uID < 121 || pActors[mon_id].pMonsterInfo.uID > 123) && // Dwarf FemaleC A-C
+        (pActors[mon_id].pMonsterInfo.uID < 124 || pActors[mon_id].pMonsterInfo.uID > 126) && // Dwarf MaleA A-C
+        (pActors[mon_id].pMonsterInfo.uID < 133 || pActors[mon_id].pMonsterInfo.uID > 135) && // Peasant Elf FemaleA A-C
+         pActors[mon_id].CanAct())
     {
-      ++v2;
-      ++v3;
-
-      if (v2 >= uNumActors)
-        return 0;
-
-      continue;
+      if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+      {
+        v22 = 0;
+        uint face_id = 0;
+        for ( face_id; face_id < 100; ++face_id )
+        {
+          v6 = rand() % 1024 + 512;
+          v7 = rand() % (signed int)stru_5C6E00->uIntegerDoublePi;
+          v19.vPosition.x = pParty->vPosition.x + fixpoint_mul(stru_5C6E00->Cos(v7), v6);
+          v8 = 0;
+          v19.uIndex = a2;
+          v19.vPosition.y = fixpoint_mul(stru_5C6E00->Sin(v7), v6) + pParty->vPosition.y;
+          v19.vPosition.z = pParty->vPosition.z;
+          v26 = 0;
+          v27 = 0;
+          v19.vPosition.z = ODM_GetFloorLevel(v19.vPosition.x, v19.vPosition.y, pParty->vPosition.z, 0, &v26, &v27, 0);
+          for( int i = 0; i < pOutdoor->uNumBModels; i++ )
+          {
+            v9 = abs(v19.vPosition.y - pOutdoor->pBModels[i].vBoundingCenter.y);
+            v10 = abs(v19.vPosition.x - pOutdoor->pBModels[i].vBoundingCenter.x);
+            if ( int_get_vector_length(v10, v9, 0) < pOutdoor->pBModels[i].sBoundingRadius + 256 )
+            {
+              v22 = 1;
+              break;
+            }
+          }
+          if ( v22 )
+          {
+            v11 = face_id == 100;
+            break;
+          }
+        }
+        v11 = face_id == 100;
+      }
+      else if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+      {
+        v22 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
+        for ( uint i = 0; i < 100; ++i )
+        {
+          v12 = rand() % 512 + 256;
+          v13 = rand();
+          v14 = v13 % (signed int)stru_5C6E00->uIntegerDoublePi;
+          v15 = stru_5C6E00->Cos(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
+          v19.vPosition.x = pParty->vPosition.x + fixpoint_mul(v15, v12);
+          v16 = stru_5C6E00->Sin(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
+          v19.vPosition.y = fixpoint_mul(v16, v12) + pParty->vPosition.y;
+          v19.vPosition.z = pParty->vPosition.z;
+          v19.uIndex = a2;
+          v17 = pIndoor->GetSector(v19.vPosition.x, v19.vPosition.y, pParty->vPosition.z);
+          if ( v17 == v22 )
+          {
+            v18 = BLV_GetFloorLevel(v19.vPosition.x, v19.vPosition.y, v19.vPosition.z, v17, &uFaceID);
+            v19.vPosition.z = v18;
+            if ( v18 != -30000 )
+            {
+              if ( abs(v18 - pParty->vPosition.z) <= 1024 )
+                break;
+            }
+          }
+        }
+        v11 = v26 == 100;
+      }
+      if ( v11 )
+        result = 0;
+      else
+      {
+        SpawnEncounter(a1, &v19, 0, 0, 1);
+        result = a2;
+      }
     }
 
-    break;
+    //break;
     //v22 = v3->pMonsterInfo.uID - 1;
     //v4 = (signed __int64)((double)v22 * 0.3333333333333333);
     //if ( (int)v4 != 40 )
@@ -1644,99 +1695,6 @@
     //if ( v2 >= (signed int)uNumActors )
     //  goto LABEL_8;
   }
-  if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
-  {
-    v22 = 0;
-    uFaceID = 0;
-    while ( 1 )
-    {
-      ++uFaceID;
-      v6 = rand() % 1024 + 512;
-      v7 = rand() % (signed int)stru_5C6E00->uIntegerDoublePi;
-      v20 = stru_5C6E00->Cos(v7);
-      v23 = (unsigned __int64)(v20 * (signed __int64)v6) >> 16;
-      v19.vPosition.x = pParty->vPosition.x + v23;
-      v20 = stru_5C6E00->Sin(v7);
-      v23 = (unsigned __int64)(v20 * (signed __int64)v6) >> 16;
-      v8 = 0;
-      v19.uIndex = a2;
-      v19.vPosition.y = v23 + pParty->vPosition.y;
-      v19.vPosition.z = pParty->vPosition.z;
-      v26 = 0;
-      v27 = 0;
-      v19.vPosition.z = ODM_GetFloorLevel(
-                          v19.vPosition.x,
-                          v23 + pParty->vPosition.y,
-                          pParty->vPosition.z,
-                          0,
-                          &v26,
-                          &v27,
-                          0);
-      v23 = 0;
-	  for( int i = 0; i < pOutdoor->uNumBModels; i++ )
-	  {
-		v9 = abs(v19.vPosition.y - pOutdoor->pBModels[i].vBoundingCenter.y);
-		v10 = abs(v19.vPosition.x - pOutdoor->pBModels[i].vBoundingCenter.x);
-		if ( int_get_vector_length(v10, v9, 0) < pOutdoor->pBModels[i].sBoundingRadius + 256 )
-		{
-		  v22 = 1;
-		  break;
-		}
-	  }
-      v11 = uFaceID == 100;
-      if ( uFaceID >= 100 )
-        break;
-      if ( v22 )
-      {
-        v11 = uFaceID == 100;
-        break;
-      }
-    }
-  }
-  else
-  {
-    v26 = 0;
-    v22 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
-    do
-    {
-      ++v26;
-      v12 = rand() % 512 + 256;
-      v13 = rand();
-      v14 = v13 % (signed int)stru_5C6E00->uIntegerDoublePi;
-      v15 = stru_5C6E00->Cos(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
-      v20 = v15;
-      v23 = (unsigned __int64)(v15 * (signed __int64)v12) >> 16;
-      v19.vPosition.x = pParty->vPosition.x + v23;
-      v16 = stru_5C6E00->Sin(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
-      v20 = v16;
-      v23 = (unsigned __int64)(v16 * (signed __int64)v12) >> 16;
-      v19.vPosition.y = v23 + pParty->vPosition.y;
-      v19.vPosition.z = pParty->vPosition.z;
-      v19.uIndex = a2;
-      v17 = pIndoor->GetSector(v19.vPosition.x, v23 + pParty->vPosition.y, pParty->vPosition.z);
-      if ( v17 == v22 )
-      {
-        v18 = BLV_GetFloorLevel(v19.vPosition.x, v19.vPosition.y, v19.vPosition.z, v17, &uFaceID);
-        v19.vPosition.z = v18;
-        if ( v18 != -30000 )
-        {
-          if ( abs(v18 - pParty->vPosition.z) <= 1024 )
-            break;
-        }
-      }
-    }
-    while ( v26 < 100 );
-    v11 = v26 == 100;
-  }
-  if ( v11 )
-  {
-    result = 0;
-  }
-  else
-  {
-    SpawnEncounter(a1, &v19, 0, 0, 1);
-    result = a2;
-  }
   return result;
 }