changeset 1493:9e9a12506d51

player detection partly working
author zipi
date Fri, 30 Aug 2013 22:23:54 +0100
parents 480b09200f88
children 3efe35df79c3 19890e50e2f6
files Actor.cpp Indoor.cpp mm7_5.cpp mm7_data.h
diffstat 4 files changed, 166 insertions(+), 186 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Fri Aug 30 21:59:09 2013 +0200
+++ b/Actor.cpp	Fri Aug 30 22:23:54 2013 +0100
@@ -3468,7 +3468,7 @@
 		if ( v23 <= v11
 		  && v27 <= v11
 		  && v12 <= v11
-		  && sub_4070EF_prolly_collide_objects(PID(OBJECT_Actor, i), PID(OBJECT_Actor, uActorID))
+		  && sub_4070EF_prolly_detect_player(PID(OBJECT_Actor, i), PID(OBJECT_Actor, uActorID))
 		  && v23 * v23 + v27 * v27 + v19 * v19 < (unsigned int)v25 )
 		{
 		  v25 = v23 * v23 + v27 * v27 + v19 * v19;
--- a/Indoor.cpp	Fri Aug 30 21:59:09 2013 +0200
+++ b/Indoor.cpp	Fri Aug 30 22:23:54 2013 +0100
@@ -4397,7 +4397,7 @@
   {
     v20 = &pActors[ai_near_actors_ids[v18]];
     if ( v20->uAttributes & 0x8000
-      || (v21 = sub_4070EF_prolly_collide_objects(PID(OBJECT_Actor,ai_near_actors_ids[v18]), 4u), v18 = i, v21) )
+      || (v21 = sub_4070EF_prolly_detect_player(PID(OBJECT_Actor,ai_near_actors_ids[v18]), 4u), v18 = i, v21) )
     {
       v22 = ai_near_actors_ids[v18];
       v20->uAttributes |= 0x8000u;
--- a/mm7_5.cpp	Fri Aug 30 21:59:09 2013 +0200
+++ b/mm7_5.cpp	Fri Aug 30 22:23:54 2013 +0100
@@ -4316,14 +4316,14 @@
 
 
 //----- (004070EF) --------------------------------------------------------
-bool __fastcall sub_4070EF_prolly_collide_objects(unsigned int uObjID, unsigned int uObj2ID)
+bool __fastcall sub_4070EF_prolly_detect_player(unsigned int uObjID, unsigned int uObj2ID)
 {
   signed int v2; // eax@1
-  unsigned int v3; // ecx@1
-  signed int v4; // esi@1
+  //unsigned int v3; // ecx@1
+  //signed int v4; // esi@1
   int v5; // ecx@2
   signed int v6; // eax@4
-  int v7; // eax@4
+  int object1_sector; // eax@4
   float v8; // ST24_4@5
   double v9; // ST18_8@5
   signed int v10; // eax@6
@@ -4333,18 +4333,18 @@
   int v14; // esi@8
   int v15; // esi@9
   signed int v16; // eax@11
-  int v17; // edi@11
-  int v18; // esi@11
-  int v19; // eax@13
+  int obj2_z; // edi@11
+  int obj2_x; // esi@11
+  int obj2_sector; // eax@13
   float v20; // ST24_4@14
   double v21; // ST18_8@14
   signed int v22; // eax@15
-  int v23; // ebx@16
+  int dist2_x; // ebx@16
   signed int v24; // ecx@16
   int v25; // eax@18
-  int v26; // eax@28
-  BLVSector *v27; // edx@31
-  int v28; // ecx@31
+  //int v26; // eax@28
+  //BLVSector *v27; // edx@31
+  //int v28; // ecx@31
   BLVFace *v29; // ebx@32
   Vec3_short_ *v30; // esi@32
   int v31; // eax@32
@@ -4360,12 +4360,12 @@
   __int16 v42; // bx@58
   int v43; // [sp-8h] [bp-70h]@11
   int v44; // [sp-4h] [bp-6Ch]@11
-  int v45; // [sp+Ch] [bp-5Ch]@32
-  __int16 v46; // [sp+10h] [bp-58h]@32
+  //int v45; // [sp+Ch] [bp-5Ch]@32
+  //__int16 v46; // [sp+10h] [bp-58h]@32
   int v47; // [sp+18h] [bp-50h]@20
   int v48; // [sp+1Ch] [bp-4Ch]@20
   int v49; // [sp+20h] [bp-48h]@20
-  int v50; // [sp+24h] [bp-44h]@16
+  int dist2_z; // [sp+24h] [bp-44h]@16
   signed int v51; // [sp+24h] [bp-44h]@27
   signed int v52; // [sp+28h] [bp-40h]@26
   signed int v53; // [sp+2Ch] [bp-3Ch]@23
@@ -4375,101 +4375,85 @@
   signed int v57; // [sp+3Ch] [bp-2Ch]@28
   int v58; // [sp+44h] [bp-24h]@50
   int v59; // [sp+48h] [bp-20h]@44
-  int v60; // [sp+50h] [bp-18h]@11
+  int obj2_y; // [sp+50h] [bp-18h]@11
   signed int v61; // [sp+50h] [bp-18h]@31
-  int v62; // [sp+54h] [bp-14h]@16
-  int v63; // [sp+58h] [bp-10h]@4
-  int v64; // [sp+5Ch] [bp-Ch]@4
-  int v65; // [sp+60h] [bp-8h]@4
+  //int v62; // [sp+54h] [bp-14h]@16
+  int obj_x; // [sp+58h] [bp-10h]@4
+  int obj_y; // [sp+5Ch] [bp-Ch]@4
+  int obj_z; // [sp+60h] [bp-8h]@4
   int v66; // [sp+64h] [bp-4h]@7
 
   v2 = PID_ID(uObjID);
-  v3 = PID_TYPE(uObjID) - 2;
-  v4 = uObj2ID;
-  if ( v3 )
+  if ( PID_TYPE(uObjID) == 5 )
   {
-    v5 = v3 - 1;
-    if ( v5 )
-    {
-      if ( v5 != 2 )
-        return 0;
       v6 = v2;
-      v63 = pLevelDecorations[v6].vPosition.x;
-      v64 = pLevelDecorations[v6].vPosition.y;
-      v65 = pLevelDecorations[v6].vPosition.z;
-      v7 = pIndoor->GetSector(v63, v64, v65);
-    }
-    else
-    {
-      v63 = pActors[v2].vPosition.x;
-      v64 = pActors[v2].vPosition.y;
+      obj_x = pLevelDecorations[v6].vPosition.x;
+      obj_y = pLevelDecorations[v6].vPosition.y;
+      obj_z = pLevelDecorations[v6].vPosition.z;
+      object1_sector = pIndoor->GetSector(obj_x, obj_y, obj_z);
+  }
+  else if ( PID_TYPE(uObjID) == 3 )
+  {
+      obj_x = pActors[v2].vPosition.x;
+      obj_y = pActors[v2].vPosition.y;
       v8 = (double)pActors[v2].uActorHeight * 0.69999999;
-      v9 = v8 + 6.7553994e15;
-      v65 = LODWORD(v9) + pActors[v2].vPosition.z;
-      v7 = pActors[v2].uSectorID;
-    }
+      //v9 = v8 + 6.7553994e15;
+      //obj_z = LODWORD(v9) + pActors[v2].vPosition.z;
+	  obj_z = (int)v8 + pActors[v2].vPosition.z;
+      object1_sector = pActors[v2].uSectorID;
   }
-  else
+  else if ( PID_TYPE(uObjID) == 2 )
   {
     v10 = v2;
-    v63 = pSpriteObjects[v10].vPosition.x;
-    v64 = pSpriteObjects[v10].vPosition.y;
-    v11 = pSpriteObjects[v10].vPosition.z;
-    v7 = pSpriteObjects[v10].uSectorID;
-    v65 = v11;
-  }
-  v66 = v7;
-  v12 = PID_ID(v4);
-  v13 = PID_TYPE(v4) - 2;
-  if ( v13 )
-  {
-    v14 = v13 - 1;
-    if ( v14 )
-    {
-      v15 = v14 - 1;
-      if ( v15 )
-      {
-        if ( v15 != 1 )
-          return 0;
-        v16 = v12;
-        v17 = pLevelDecorations[v16].vPosition.z;
-        v18 = pLevelDecorations[v16].vPosition.x;
-        v44 = pLevelDecorations[v16].vPosition.z;
-        v60 = pLevelDecorations[v16].vPosition.y;
-        v43 = pLevelDecorations[v16].vPosition.y;
-      }
-      else
-      {
-        v18 = pParty->vPosition.x;
-        v17 = pParty->sEyelevel + pParty->vPosition.z;
-        v60 = pParty->vPosition.y;
-        v44 = pParty->sEyelevel + pParty->vPosition.z;
-        v43 = pParty->vPosition.y;
-      }
-      v19 = pIndoor->GetSector(v18, v43, v44);
-    }
-    else
-    {
-      v60 = pActors[v12].vPosition.y;
-      v18 = pActors[v12].vPosition.x;
-      v20 = (double)pActors[v12].uActorHeight * 0.69999999;
-      v21 = v20 + 6.7553994e15;
-      v17 = LODWORD(v21) + pActors[v12].vPosition.z;
-      v19 = pActors[v12].uSectorID;
-    }
+    obj_x = pSpriteObjects[v10].vPosition.x;
+    obj_y = pSpriteObjects[v10].vPosition.y;
+    obj_z = pSpriteObjects[v10].vPosition.z;
+    object1_sector = pSpriteObjects[v10].uSectorID;
   }
   else
+	  return 0;
+  v66 = object1_sector;
+  v12 = PID_ID(uObj2ID);
+  if ( PID_TYPE(uObj2ID) == 5)
+  {
+	v16 = v12;
+    obj2_z = pLevelDecorations[v16].vPosition.z;
+    obj2_x = pLevelDecorations[v16].vPosition.x;
+    obj2_y = pLevelDecorations[v16].vPosition.y;
+	obj2_sector = pIndoor->GetSector(obj2_x, obj2_y, obj2_z);
+   }
+   else if ( PID_TYPE(uObj2ID) == 4)
+   {
+     obj2_x = pParty->vPosition.x;
+     obj2_z = pParty->sEyelevel + pParty->vPosition.z;
+     obj2_y = pParty->vPosition.y;
+	 obj2_sector = pIndoor->GetSector(obj2_x, obj2_y, obj2_z);
+    }
+  
+  else if( PID_TYPE(uObj2ID) == 3)
+  {
+    obj2_y = pActors[v12].vPosition.y;
+    obj2_x = pActors[v12].vPosition.x;
+    v20 = (double)pActors[v12].uActorHeight * 0.69999999;
+    //v21 = v20 + 6.7553994e15;
+    //obj2_z = LODWORD(v21) + pActors[v12].vPosition.z;
+	obj2_z = (int)v20 + pActors[v12].vPosition.z;
+    obj2_sector = pActors[v12].uSectorID;
+  }
+  
+  else if ( PID_TYPE(uObj2ID) == 2)
   {
     v22 = v12;
-    v18 = pSpriteObjects[v22].vPosition.x;
-    v17 = pSpriteObjects[v22].vPosition.z;
-    v60 = pSpriteObjects[v22].vPosition.y;
-    v19 = pSpriteObjects[v22].uSectorID;
+    obj2_x = pSpriteObjects[v22].vPosition.x;
+    obj2_z = pSpriteObjects[v22].vPosition.z;
+    obj2_y = pSpriteObjects[v22].vPosition.y;
+    obj2_sector = pSpriteObjects[v22].uSectorID;
   }
-  v62 = v19;
-  v23 = v18 - v63;
-  v50 = v17 - v65;
-  v24 = integer_sqrt(v23 * v23 + (v60 - v64) * (v60 - v64) + v50 * v50);
+  else
+	  return 0;
+  dist2_x = obj2_x - obj_x;
+  dist2_z = obj2_z - obj_z;
+  v24 = integer_sqrt(dist2_x * dist2_x + (obj2_y - obj_y) * (obj2_y - obj_y) + dist2_z * dist2_z);
   if ( v24 > 5120 )
     return 0;
   if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
@@ -4477,120 +4461,116 @@
   v25 = 65536;
   if ( v24 )
     v25 = 65536 / v24;
-  v49 = v23 * v25;
-  v47 = v50 * v25;
-  v48 = (v60 - v64) * v25;
-  v56 = v63;
-  if ( v63 < v18 )
+  v49 = dist2_x * v25;
+  v47 = dist2_z * v25;
+  v48 = (obj2_y - obj_y) * v25;
+  if ( obj_x < obj2_x )
   {
-    v55 = v18;
+	v56 = obj_x;
+    v55 = obj2_x;
   }
   else
   {
-    v56 = v18;
-    v55 = v63;
+    v56 = obj2_x;
+    v55 = obj_x;
   }
-  v54 = v64;
-  if ( v64 < v60 )
+  if ( obj_y < obj2_y )
   {
-    v53 = v60;
+	v54 = obj_y;
+    v53 = obj2_y;
   }
   else
   {
-    v54 = v60;
-    v53 = v64;
+    v54 = obj2_y;
+    v53 = obj_y;
   }
-  v52 = v65;
-  if ( v65 < v17 )
+  if ( obj_z < obj2_z )
   {
-    v51 = v17;
+	v52 = obj_z;
+    v51 = obj2_z;
   }
   else
   {
-    v52 = v17;
-    v51 = v65;
+    v52 = obj2_z;
+    v51 = obj_z;
   }
   v57 = 0;
-  v26 = v66;
-  while ( 2 )
-  {
-    if ( v26 == v62 )
+  if ( v66 == obj2_sector )
       return 1;
-    if ( v57 >= 30 || (v27 = pIndoor->pSectors, v28 = v66, v61 = 0, pIndoor->pSectors[v66].uNumPortals <= 0) )
-      break;
-    while ( 1 )
-    {
-      v29 = &pIndoor->pFaces[v27[v28].pPortals[v61]];
+  //for ( v57 = 0; v57 < 30; v57++ )
+  if ( v57 < 30 && !(v61 = 0, pIndoor->pSectors[v66].uNumPortals <= 0) )
+	for( int v61 = 0; v61 < pIndoor->pSectors[v66].uNumPortals; v61++ )
+	{
+      v29 = &pIndoor->pFaces[pIndoor->pSectors[v66].pPortals[v61]];
       v30 = &pIndoor->pVertices[*v29->pVertexIDs];
-      v45 = *(int *)&v30->x;
-      v46 = v30->z;
-      v31 = v29->pFacePlane_old.vNormal.z * (v46 - v65)
-          + v29->pFacePlane_old.vNormal.y * (SHIWORD(v45) - v64)
-          + v29->pFacePlane_old.vNormal.x * ((signed __int16)v45 - v63);
+      //v45 = *(int *)&v30->x;
+      //v46 = v30->z;
+      //v31 = v29->pFacePlane_old.vNormal.z * (v46 - obj_z)
+	  v31 = v29->pFacePlane_old.vNormal.z * (v30->z - obj_z)
+          //+ v29->pFacePlane_old.vNormal.y * (SHIWORD(v45) - obj_y)
+		  + v29->pFacePlane_old.vNormal.y * (v30->y - obj_y)
+          //+ v29->pFacePlane_old.vNormal.x * ((signed __int16)v45 - obj_x);
+		  + v29->pFacePlane_old.vNormal.x * (v30->x - obj_x);
       if ( v66 != v29->uSectorID )
         v31 = -v31;
-      if ( v31 >= 0 && (signed __int16)v45 != v63 && SHIWORD(v45) != v64 && v46 != v65
+      //if (!( v31 >= 0 && (signed __int16)v45 != obj_x && SHIWORD(v45) != obj_y && v46 != obj_z
+	  if (!( v31 >= 0 && v30->x != obj_x && v30->y != obj_y && v30->z != obj_z
         || v56 > v29->pBounding.x2
         || v55 < v29->pBounding.x1
         || v54 > v29->pBounding.y2
         || v53 < v29->pBounding.y1
         || v52 > v29->pBounding.z2
-        || v51 < v29->pBounding.z1 )
-        goto LABEL_54;
-      v32 = (unsigned __int64)(v49 * (signed __int64)v29->pFacePlane_old.vNormal.x) >> 16;
-      v33 = (unsigned __int64)(v47 * (signed __int64)v29->pFacePlane_old.vNormal.z) >> 16;
-      v34 = (unsigned __int64)(v48 * (signed __int64)v29->pFacePlane_old.vNormal.y) >> 16;
-      v35 = v32 + v33 + v34 == 0;
-      v36 = v32 + v33 + v34;
-      v59 = v32 + v33 + v34;
-      if ( v35 )
-        goto LABEL_53;
-      v37 = v65 * v29->pFacePlane_old.vNormal.z;
-      v38 = -(v29->pFacePlane_old.dist + v37 + v63 * v29->pFacePlane_old.vNormal.x + v64 * v29->pFacePlane_old.vNormal.y);
-      if ( v36 <= 0 )
-        break;
-      if ( v29->pFacePlane_old.dist + v37 + v63 * v29->pFacePlane_old.vNormal.x + v64 * v29->pFacePlane_old.vNormal.y <= 0 )
-        goto LABEL_49;
-LABEL_53:
-      v27 = pIndoor->pSectors;
-LABEL_54:
-      ++v61;
-      if ( v61 >= v27[v28].uNumPortals )
-        goto LABEL_55;
+        || v51 < v29->pBounding.z1 ) )
+	  {
+		  v32 = (unsigned __int64)(v49 * (signed __int64)v29->pFacePlane_old.vNormal.x) >> 16;
+		  v33 = (unsigned __int64)(v47 * (signed __int64)v29->pFacePlane_old.vNormal.z) >> 16;
+		  v34 = (unsigned __int64)(v48 * (signed __int64)v29->pFacePlane_old.vNormal.y) >> 16;
+		  v35 = v32 + v33 + v34 == 0;
+		  v36 = v32 + v33 + v34;
+		  v59 = v32 + v33 + v34;
+		  if ( !v35 )
+		  {
+			  v37 = obj_z * v29->pFacePlane_old.vNormal.z;
+			  v38 = -(v29->pFacePlane_old.dist + v37 + obj_x * v29->pFacePlane_old.vNormal.x + obj_y * v29->pFacePlane_old.vNormal.y);
+			  if ( v36 <= 0 ^ v29->pFacePlane_old.dist + v37 + obj_x * v29->pFacePlane_old.vNormal.x + obj_y * v29->pFacePlane_old.vNormal.y <= 0)
+			  {
+				v39 = abs(-(v29->pFacePlane_old.dist
+						  + v37
+						  + obj_x * v29->pFacePlane_old.vNormal.x
+						  + obj_y * v29->pFacePlane_old.vNormal.y)) >> 14;
+				if ( v39 > abs(v36)
+				  || (LODWORD(v40) = v38 << 16, HIDWORD(v40) = v38 >> 16, v58 = v40 / v59, (signed int)(v40 / v59) < 0)
+				  || !sub_4075DB(
+						obj_x + ((signed int)(((unsigned __int64)(v58 * (signed __int64)v49) >> 16) + 32768) >> 16),
+						obj_y + ((signed int)(((unsigned __int64)(v58 * (signed __int64)v48) >> 16) + 32768) >> 16),
+						obj_z + ((signed int)(((unsigned __int64)(v58 * (signed __int64)v47) >> 16) + 32768) >> 16),
+						v29) )
+				{
+				  continue;
+				}
+				if ( v29->uSectorID == v66 )
+				  v42 = v29->uBackSectorID;
+				else
+				  v42 = v29->uSectorID;
+				if ( v42 != v66 )
+				{
+				  ++v57;
+				  v66 = v42;
+				  if ( v42 == obj2_sector )
+					return 1;
+				  if ( v57 < 30 && pIndoor->pSectors[v66].uNumPortals > 0)
+				  {
+					  v61=-1;
+					  continue;
+				  }
+
+				}
+				break;
+			  }
+		  }
+	  }
     }
-    if ( v29->pFacePlane_old.dist + v37 + v63 * v29->pFacePlane_old.vNormal.x + v64 * v29->pFacePlane_old.vNormal.y < 0 )
-      goto LABEL_53;
-LABEL_49:
-    v39 = abs(-(v29->pFacePlane_old.dist
-              + v37
-              + v63 * v29->pFacePlane_old.vNormal.x
-              + v64 * v29->pFacePlane_old.vNormal.y)) >> 14;
-    if ( v39 > abs(v36)
-      || (LODWORD(v40) = v38 << 16, HIDWORD(v40) = v38 >> 16, v58 = v40 / v59, (signed int)(v40 / v59) < 0)
-      || !sub_4075DB(
-            v63 + ((signed int)(((unsigned __int64)(v58 * (signed __int64)v49) >> 16) + 32768) >> 16),
-            v64 + ((signed int)(((unsigned __int64)(v58 * (signed __int64)v48) >> 16) + 32768) >> 16),
-            v65 + ((signed int)(((unsigned __int64)(v58 * (signed __int64)v47) >> 16) + 32768) >> 16),
-            v29) )
-    {
-      v28 = v66;
-      goto LABEL_53;
-    }
-    if ( v29->uSectorID == v66 )
-      v42 = v29->uBackSectorID;
-    else
-      v42 = v29->uSectorID;
-    v26 = v42;
-    if ( v42 != v66 )
-    {
-      ++v57;
-      v66 = v42;
-      continue;
-    }
-    break;
-  }
-LABEL_55:
-  if ( v66 != v62 )
+  if ( v66 != obj2_sector )
     return 0;
   return 1;
 }
@@ -4621,7 +4601,7 @@
   signed int a3a; // [sp+24h] [bp+8h]@14
   int a4a; // [sp+28h] [bp+Ch]@2
 
-  __debugbreak();
+  //__debugbreak();
 
   v5 = a4->uAttributes;
   v9 = pIndoor->pVertices;
--- a/mm7_data.h	Fri Aug 30 21:59:09 2013 +0200
+++ b/mm7_data.h	Fri Aug 30 22:23:54 2013 +0100
@@ -1073,7 +1073,7 @@
 void MakeActorAIList_ODM();
 int MakeActorAIList_BLV();
 void UpdateActorAI();
-bool __fastcall sub_4070EF_prolly_collide_objects(unsigned int uObjID, unsigned int uObj2ID);
+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 *a4);
 bool __fastcall sub_4077F1(int a1, int a2, int a3, struct ODMFace *a4, struct BSPVertexBuffer *a5);
 bool __fastcall sub_407A1C(int x, int z, int y, struct Vec3_int_ v); // idb