diff Indoor.cpp @ 2203:4bfee77e900d

DoInteractionWithTopmostZObject cleaned
author Ritor1
date Tue, 04 Feb 2014 17:29:04 +0600
parents 9856c2f8f918
children 23e7c7299ea8
line wrap: on
line diff
--- a/Indoor.cpp	Mon Feb 03 23:07:15 2014 +0100
+++ b/Indoor.cpp	Tue Feb 04 17:29:04 2014 +0600
@@ -601,18 +601,14 @@
   stru_F8AD28.pDeltaUV[1] = pIndoor->pFaceExtras[pIndoor->pFaces[uFaceID].uFaceExtraID].sTextureDeltaV;
   result = GetTickCount() >> 3;
   if ( pIndoor->pFaces[uFaceID].uAttributes & 4 )
-  {
     stru_F8AD28.pDeltaUV[1] -= result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uHeightMinus1;
-  }
   else
   {
     if ( pIndoor->pFaces[uFaceID].uAttributes & 0x20 )
       stru_F8AD28.pDeltaUV[1] += result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uHeightMinus1;
   }
-  if ( BYTE1(pIndoor->pFaces[uFaceID].uAttributes) & 8 )
-  {
+  if ( pIndoor->pFaces[uFaceID].uAttributes & 0x800 )
     stru_F8AD28.pDeltaUV[0] -= result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uWidthMinus1;
-  }
   else
   {
     if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_DONT_CACHE_TEXTURE )
@@ -2490,13 +2486,13 @@
     goto LABEL_12;
   }
 LABEL_12:
-  if ( BYTE2(this->uAttributes) & 0x80 )
+  if ( this->uAttributes & 0x800000 )
   {
     a2->x = -a2->x;
     a2->y = -a2->y;
     a2->z = -a2->z;
   }
-  if ( BYTE3(this->uAttributes) & 1 )
+  if ( this->uAttributes & 0x1000000 )
   {
     a3->x = -a3->x;
     a3->y = -a3->y;
@@ -3610,7 +3606,7 @@
 //----- (004016FA) --------------------------------------------------------
 int  MakeActorAIList_BLV()
 {
-  Actor *v0; // esi@2
+  //Actor *v0; // esi@2
   int v1; // eax@4
   int v2; // ebx@4
   unsigned int v3; // ecx@4
@@ -3649,10 +3645,10 @@
   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 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 v43; // [sp+1Ch] [bp-8h]@1
   signed int v44; // [sp+1Ch] [bp-8h]@25
   int v45; // [sp+20h] [bp-4h]@1
 
@@ -3660,201 +3656,152 @@
   pParty->uFlags &= 0xFFFFFFCFu;
   v37 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
   v45 = 0;
-  v43 = 0;
-  if ( (signed int)uNumActors > 0 )
+  for ( uint i = 0; i < (signed int)uNumActors; ++i )
   {
-    v0 = pActors.data();//[0].uAttributes;
-    do
+    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);
+    v2 = v38;
+    v3 = v39;
+    if ( v1 < v38 )
     {
-      BYTE1(v0->uAttributes) &= 0xFBu;
-      if ( ! v0->CanAct() )
-        goto LABEL_60;
-	  v39 = abs(pParty->vPosition.z - v0->vPosition.z);
-	  v38 = abs(pParty->vPosition.y - v0->vPosition.y);
-	  v1 = abs(pParty->vPosition.x - v0->vPosition.x);
-      v2 = v38;
-      v3 = v39;
-      if ( v1 < v38 )
+      v4 = v1;
+      v1 = v38;
+      v2 = v4;
+    }
+    if ( v1 < v39 )
+    {
+      v5 = v1;
+      v1 = v39;
+      v3 = v5;
+    }
+    if ( v2 < (signed int)v3 )
+    {
+      v6 = v3;
+      v3 = v2;
+      v2 = v6;
+    }
+    v7 = ((unsigned int)(11 * v2) >> 5) + (v3 >> 2) + 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) )
       {
-        v4 = v1;
-        v1 = v38;
-        v2 = v4;
-      }
-      if ( v1 < v39 )
-      {
-        v5 = v1;
-        v1 = v39;
-        v3 = v5;
-      }
-      if ( v2 < (signed int)v3 )
-      {
-        v6 = v3;
-        v3 = v2;
-        v2 = v6;
+        pActors[i].uAttributes |= 0x1000000;
+        if ( !(pParty->uFlags & 0x10) && (double)v9 < 307.2 )
+          pParty->uFlags |= 0x10;
+        if ( !(pParty->uFlags & 0x20) && v9 < 5120 )
+          pParty->uFlags |= 0x20;
       }
-      v7 = ((unsigned int)(11 * v2) >> 5) + (v3 >> 2) + v1;
-      v8 = v0->uActorRadius;
-      v9 = v7 - v8;
-      v40 = v7 - v8;
-      if ( v40 < 0 )
-      {
-        v9 = 0;
-        v40 = 0;
-      }
-      if ( v9 < 10240 )
-      {
-        v10 = v0->uAttributes & 0xFEFFFFFF;
-        v0->uAttributes = v10;
-        if ( v10 & 0x80000 || v0->GetActorsRelation(0) )
-        {
-          v11 = (pParty->uFlags & 0x10) == 0;
-          v0->uAttributes = v10 | 0x1000000;
-          if ( v11 && (double)v40 < 307.2 )
-            pParty->uFlags |= 0x10u;
-          if ( !(pParty->uFlags & 0x20) && v9 < 5120 )
-            pParty->uFlags |= 0x20u;
-        }
-        v12 = v45++;
-        ai_near_actors_distances[v12] = v9;
-        ai_near_actors_ids[v12] = v43;
-      }
-      else
-      {
-LABEL_60:
-        BYTE1(v0->uAttributes) &= 0xBFu;
-      }
-      ++v43;
-      ++v0;
+      v12 = v45++;
+      ai_near_actors_distances[v12] = v9;
+      ai_near_actors_ids[v12] = i;
     }
-    while ( v43 < (signed int)uNumActors );
+    else
+      pActors[i].uAttributes &= 0xBF00;
   }
   v13 = 0;
   if ( v45 > 0 )
   {
-    v14 = 1;
-    v44 = 1;
-    do
+    for ( uint i = 1; i < v45; i++ )
     {
-      while ( 1 )
+      for ( uint j = 1; j < v45; ++j )
       {
-        v41 = v14;
-        if ( v14 >= v45 )
-          break;
         v15 = ai_near_actors_distances[v13];
-        if ( v15 > ai_near_actors_distances[v14] )
+        if ( ai_near_actors_distances[v13] > ai_near_actors_distances[j] )
         {
-          v16 = &ai_near_actors_ids[v14];
           v17 = ai_near_actors_ids[v13];
-          ai_near_actors_ids[v13] = *v16;
-          *v16 = v17;
-          v14 = v41;
-          ai_near_actors_distances[v13] = ai_near_actors_distances[v41];
-          ai_near_actors_distances[v41] = v15;
+          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;
         }
-        ++v14;
       }
       ++v13;
-      v14 = v44 + 1;
-      v44 = v14;
     }
-    while ( v14 - 1 < v45 );
   }
   v18 = 0;
   v19 = 0;
-  for ( i = 0; v18 < v45; i = v18 )
+  for ( i = 0; i < v45; i++ )
   {
-    v20 = &pActors[ai_near_actors_ids[v18]];
-    if ( v20->uAttributes & 0x8000
-      || (v21 = sub_4070EF_prolly_detect_player(PID(OBJECT_Actor,ai_near_actors_ids[v18]), 4u), v18 = i, v21) )
+    if ( pActors[ai_near_actors_ids[i]].uAttributes & 0x8000
+      || sub_4070EF_prolly_detect_player(PID(OBJECT_Actor,ai_near_actors_ids[i]), 4) )
     {
-      v22 = ai_near_actors_ids[v18];
-      v20->uAttributes |= 0x8000u;
-      ai_array_4F6638_actor_ids[v19] = v22;
-      ai_array_4F5E68[v19++] = ai_near_actors_distances[v18];
+      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;
     }
-    ++v18;
   }
-  v23 = 0;
   ai_arrays_size = v19;
   if ( (signed int)uNumActors > 0 )
   {
-    v24 = pActors.data();//[0].uAttributes;
-    do
+    for ( uint i = 0; i < (signed int)uNumActors; ++i )
     {
-      if ( v24->CanAct() && v24->uSectorID == v37 )
+      if ( pActors[i].CanAct() && pActors[i].uSectorID == v37 )
       {
         v25 = 0;
         if ( v19 <= 0 )
         {
-LABEL_43:
-          v26 = ai_arrays_size;
-          BYTE1(v24->uAttributes) |= 0x40u;
-          ++ai_arrays_size;
-          ai_array_4F6638_actor_ids[v26] = v23;
+          pActors[i].uAttributes |= 0x4000;
+          ai_array_4F6638_actor_ids[ai_arrays_size++] = i;
         }
         else
         {
-          while ( ai_array_4F6638_actor_ids[v25] != v23 )
+          while ( ai_array_4F6638_actor_ids[v25] != i )
           {
             ++v25;
             if ( v25 >= v19 )
-              goto LABEL_43;
+            {
+              pActors[i].uAttributes |= 0x4000;
+              ai_array_4F6638_actor_ids[ai_arrays_size++] = i;
+			  break;
+            }
           }
         }
       }
-      ++v23;
-      ++v24;
     }
-    while ( v23 < (signed int)uNumActors );
   }
   v27 = ai_arrays_size;
   for ( j = 0; j < v45; ++j )
   {
-    v29 = ai_near_actors_ids[j];
-    if ( pActors[v29].uAttributes & 0xC000 && pActors[v29].CanAct() )
+    //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 )
-      {
-LABEL_51:
-        v31 = ai_arrays_size;
-        v32 = ai_near_actors_ids[j];
-        ++ai_arrays_size;
-        ai_array_4F6638_actor_ids[v31] = v32;
-      }
+        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 )
-            goto LABEL_51;
+		  {
+            ai_array_4F6638_actor_ids[ai_arrays_size++] = ai_near_actors_ids[j];
+			break;
+		  }
         }
       }
     }
   }
-  v33 = ai_arrays_size;
   if ( ai_arrays_size > 30 )
-  {
-    v33 = 30;
     ai_arrays_size = 30;
-  }
-  memcpy(ai_near_actors_ids.data(), ai_array_4F6638_actor_ids.data(), 4 * v33);
+  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);
-  v34 = (unsigned int)ai_arrays_size;
-  if ( ai_arrays_size > 0 )
-  {
-    do
-    {
-      v35 = (char *)&pActors[ai_near_actors_ids[HIDWORD(v34)]].uAttributes;
-      v35[1] |= 4u;
-      ++HIDWORD(v34);
-    }
-    while ( SHIDWORD(v34) < (signed int)v34 );
-  }
-  return v34;
+  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()
@@ -4511,7 +4458,7 @@
   int v59; // eax@90
   BLVSector *v60; // edx@90
   int v61; // ecx@90
-  BLVFace *v62; // esi@91
+  BLVFace *face; // esi@91
   int v63; // ST34_4@98
   int v64; // ST30_4@98
   int v65; // eax@98
@@ -4539,7 +4486,7 @@
   int v87; // ecx@128
   BLVSector *v88; // eax@128
   int v89; // ecx@128
-  BLVFace *v90; // esi@129
+  //BLVFace *v90; // esi@129
   int v91; // ebx@136
   int v92; // eax@137
   signed int v93; // edi@137
@@ -4662,9 +4609,7 @@
     v151 = v53;
     v119 = pOut.x;
     if ( pOut.x < outx )
-    {
       v123 = outx;
-    }
     else
     {
       v119 = outx;
@@ -4674,9 +4619,7 @@
     v56 = outy;
     v127 = pOut.y;
     if ( pOut.y < outy )
-    {
       v131 = outy;
-    }
     else
     {
       v127 = outy;
@@ -4686,9 +4629,7 @@
     v58 = outz;
     v135 = outz;
     if ( outz < v163 )
-    {
       v139 = v163;
-    }
     else
     {
       v135 = v163;
@@ -4718,47 +4659,45 @@
                     + 2 * *(__int16 *)((char *)&pIndoor->pSectors->uNumFloors + v61);
             ++sDepthb )
       {
-        v62 = &pIndoor->pFaces[(*(unsigned __int16 **)((char *)&v60->pWalls + v61))[sDepthb]];
-        if ( v62->Portal()
-          || v119 > v62->pBounding.x2
-          || v123 < v62->pBounding.x1
-          || v127 > v62->pBounding.y2
-          || v131 < v62->pBounding.y1
-          || v135 > v62->pBounding.z2
-          || v139 < v62->pBounding.z1
-          || (v63 = (unsigned __int64)(v143 * (signed __int64)v62->pFacePlane_old.vNormal.x) >> 16,
-              v64 = (unsigned __int64)(v151 * (signed __int64)v62->pFacePlane_old.vNormal.z) >> 16,
-              v65 = (unsigned __int64)(v147 * (signed __int64)v62->pFacePlane_old.vNormal.y) >> 16,
+        face = &pIndoor->pFaces[(*(unsigned __int16 **)((char *)&v60->pWalls + v61))[sDepthb]];
+        if ( face->Portal()
+          || v119 > face->pBounding.x2
+          || v123 < face->pBounding.x1
+          || v127 > face->pBounding.y2
+          || v131 < face->pBounding.y1
+          || v135 > face->pBounding.z2
+          || v139 < face->pBounding.z1
+          || (v63 = fixpoint_mul(v143, face->pFacePlane_old.vNormal.x),
+              v64 = fixpoint_mul(v151, face->pFacePlane_old.vNormal.z),
+              v65 = fixpoint_mul(v147, face->pFacePlane_old.vNormal.y),
               v20 = v63 + v64 + v65 == 0,
               v66 = v63 + v64 + v65,
               v107 = v63 + v64 + v65,
               v20) )
           goto LABEL_107;
-        v67 = outz * v62->pFacePlane_old.vNormal.z;
-        v68 = -(v62->pFacePlane_old.dist
-              + v67
-              + pOut.y * v62->pFacePlane_old.vNormal.y
-              + pOut.x * v62->pFacePlane_old.vNormal.x);
+        //v67 = outz * face->pFacePlane_old.vNormal.z;
+        v68 = -(face->pFacePlane_old.dist + outz * face->pFacePlane_old.vNormal.z + pOut.y * face->pFacePlane_old.vNormal.y
+              + pOut.x * face->pFacePlane_old.vNormal.x);
         if ( v66 <= 0 )
         {
-          if ( v62->pFacePlane_old.dist
-             + v67
-             + pOut.y * v62->pFacePlane_old.vNormal.y
-             + pOut.x * v62->pFacePlane_old.vNormal.x < 0 )
+          if ( face->pFacePlane_old.dist
+             + outz * face->pFacePlane_old.vNormal.z
+             + pOut.y * face->pFacePlane_old.vNormal.y
+             + pOut.x * face->pFacePlane_old.vNormal.x < 0 )
             goto LABEL_107;
         }
         else
         {
-          if ( v62->pFacePlane_old.dist
-             + v67
-             + pOut.y * v62->pFacePlane_old.vNormal.y
-             + pOut.x * v62->pFacePlane_old.vNormal.x > 0 )
+          if ( face->pFacePlane_old.dist
+             + outz * face->pFacePlane_old.vNormal.z
+             + pOut.y * face->pFacePlane_old.vNormal.y
+             + pOut.x * face->pFacePlane_old.vNormal.x > 0 )
             goto LABEL_107;
         }
-        v69 = abs(-(v62->pFacePlane_old.dist
-                  + v67
-                  + pOut.y * v62->pFacePlane_old.vNormal.y
-                  + pOut.x * v62->pFacePlane_old.vNormal.x)) >> 14;
+        v69 = abs(-(face->pFacePlane_old.dist
+                  + outz * face->pFacePlane_old.vNormal.z
+                  + pOut.y * face->pFacePlane_old.vNormal.y
+                  + pOut.x * face->pFacePlane_old.vNormal.x)) >> 14;
         if ( v69 <= abs(v66) )
         {
           //LODWORD(v70) = v68 << 16;
@@ -4772,7 +4711,7 @@
                    pOut.x + ((signed int)(fixpoint_mul(v108, v143) + 32768) >> 16),
                    pOut.y + ((signed int)(fixpoint_mul(v108, v147) + 32768) >> 16),
                    outz + ((signed int)(fixpoint_mul(v108, v151) + 32768) >> 16),
-                   v62) )
+                   face) )
             {
               v114 = 1;
               break;
@@ -4829,9 +4768,7 @@
     v84 = outy;
     v128 = pOut.y;
     if ( pOut.y < outy )
-    {
       v132 = outy;
-    }
     else
     {
       v128 = outy;
@@ -4841,9 +4778,7 @@
     v86 = outz;
     v136 = outz;
     if ( outz < v163 )
-    {
       v140 = v163;
-    }
     else
     {
       v136 = v163;
@@ -4887,47 +4822,47 @@
     }
     while ( 1 )
     {
-      v90 = &pIndoor->pFaces[(*(unsigned __int16 **)((char *)&v88->pWalls + v89))[v162]];
-      if ( v90->Portal()
-        || v120 > v90->pBounding.x2
-        || v124 < v90->pBounding.x1
-        || v128 > v90->pBounding.y2
-        || v132 < v90->pBounding.y1
-        || v136 > v90->pBounding.z2
-        || v140 < v90->pBounding.z1
-        || (yb = fixpoint_mul(v144, v90->pFacePlane_old.vNormal.x),
-            v_4b = fixpoint_mul(v148, v90->pFacePlane_old.vNormal.y),
-            vf = fixpoint_mul(v152, v90->pFacePlane_old.vNormal.z),
+      face = &pIndoor->pFaces[(*(unsigned __int16 **)((char *)&v88->pWalls + v89))[v162]];
+      if ( face->Portal()
+        || v120 > face->pBounding.x2
+        || v124 < face->pBounding.x1
+        || v128 > face->pBounding.y2
+        || v132 < face->pBounding.y1
+        || v136 > face->pBounding.z2
+        || v140 < face->pBounding.z1
+        || (yb = fixpoint_mul(v144, face->pFacePlane_old.vNormal.x),
+            v_4b = fixpoint_mul(v148, face->pFacePlane_old.vNormal.y),
+            vf = fixpoint_mul(v152, face->pFacePlane_old.vNormal.z),
             v20 = yb + vf + v_4b == 0,
             v91 = yb + vf + v_4b,
             vc = yb + vf + v_4b,
             v20) )
         goto LABEL_145;
-      v92 = outz * v90->pFacePlane_old.vNormal.z;
-      v93 = -(v90->pFacePlane_old.dist
+      v92 = outz * face->pFacePlane_old.vNormal.z;
+      v93 = -(face->pFacePlane_old.dist
             + v92
-            + pOut.y * v90->pFacePlane_old.vNormal.y
-            + pOut.x * v90->pFacePlane_old.vNormal.x);
+            + pOut.y * face->pFacePlane_old.vNormal.y
+            + pOut.x * face->pFacePlane_old.vNormal.x);
       if ( v91 <= 0 )
       {
-        if ( v90->pFacePlane_old.dist
+        if ( face->pFacePlane_old.dist
            + v92
-           + pOut.y * v90->pFacePlane_old.vNormal.y
-           + pOut.x * v90->pFacePlane_old.vNormal.x < 0 )
+           + pOut.y * face->pFacePlane_old.vNormal.y
+           + pOut.x * face->pFacePlane_old.vNormal.x < 0 )
           goto LABEL_145;
       }
       else
       {
-        if ( v90->pFacePlane_old.dist
+        if ( face->pFacePlane_old.dist
            + v92
-           + pOut.y * v90->pFacePlane_old.vNormal.y
-           + pOut.x * v90->pFacePlane_old.vNormal.x > 0 )
+           + pOut.y * face->pFacePlane_old.vNormal.y
+           + pOut.x * face->pFacePlane_old.vNormal.x > 0 )
           goto LABEL_145;
       }
-      v_4c = abs(-(v90->pFacePlane_old.dist
+      v_4c = abs(-(face->pFacePlane_old.dist
                  + v92
-                 + pOut.y * v90->pFacePlane_old.vNormal.y
-                 + pOut.x * v90->pFacePlane_old.vNormal.x)) >> 14;
+                 + pOut.y * face->pFacePlane_old.vNormal.y
+                 + pOut.x * face->pFacePlane_old.vNormal.x)) >> 14;
       if ( v_4c <= abs(v91) )
       {
         //LODWORD(v94) = v93 << 16;
@@ -4941,7 +4876,7 @@
                  pOut.x + ((signed int)(fixpoint_mul(vd, v144) + 32768) >> 16),
                  pOut.y + ((signed int)(fixpoint_mul(vd, v148) + 32768) >> 16),
                  outz + ((signed int)(fixpoint_mul(vd, v152) + 32768) >> 16),
-                 v90) )
+                 face) )
           {
             v113 = 1;
             goto LABEL_148;
@@ -4977,9 +4912,7 @@
   v121 = v6 * v11;
   v149 = pOut.x;
   if ( pOut.x < outx )
-  {
     v145 = outx;
-  }
   else
   {
     v149 = outx;
@@ -4988,9 +4921,7 @@
   v14 = outy;
   v141 = pOut.y;
   if ( pOut.y < outy )
-  {
     v137 = outy;
-  }
   else
   {
     v141 = outy;
@@ -4998,9 +4929,7 @@
   }
   v133 = outz;
   if ( outz < v163 )
-  {
     v129 = v163;
-  }
   else
   {
     v133 = v163;
@@ -5230,120 +5159,74 @@
   uNumVisibleNotEmptySectors = 0;
   for (uint i = 0; i < num_nodes; ++i)
   {
-      if (!uNumVisibleNotEmptySectors)
-      {
-        pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
-        continue;
-      }
-      
-      v6 = 0;
-        while (pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6] != nodes[i].uSectorID )
-        {
-          ++v6;
-          if ( v6 >= uNumVisibleNotEmptySectors)
-          {
-            pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
-          }
-        }
-
+    //if (!uNumVisibleNotEmptySectors)
+    //{
+      //pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
+      //continue;
+    //}
+    //v6 = 0;
+    //while (pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6] != nodes[i].uSectorID )
+    for ( uint j = 0; j < uNumVisibleNotEmptySectors; j++ )
+    {
+      //++v6;
+      if ( pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[j] == nodes[i].uSectorID)
+        break;
+    }
+    pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
   }
 }
 //----- (0046A334) --------------------------------------------------------
 char __fastcall DoInteractionWithTopmostZObject(int a1, int a2)
 {
-  int v2; // edx@1
-  BLVFace *v4; // eax@9
-  unsigned int v5; // ecx@9
-  unsigned __int16 v6; // ax@11
-  //ODMFace *v7; // eax@16
-  LevelDecoration *v8; // esi@19
-  __int16 v9; // ax@19
-  int v10; // eax@22
-  int v11; // ecx@22
-  int v12; // edi@23
-  Actor *v13; // esi@23
-  unsigned __int16 v14; // ax@23
-  unsigned __int16 v15; // ax@33
-  const char *v16; // eax@34
   int v17; // edi@36
-  int v18; // eax@36
-  ItemGen *v19; // esi@39
-  unsigned int v20; // eax@39
-  int v21; // ecx@40
-  std::string v22; // [sp-18h] [bp-2Ch]@5
-  const char *v23; // [sp-8h] [bp-1Ch]@5
-  int v24; // [sp-4h] [bp-18h]@5
-  char v25; // [sp+8h] [bp-Ch]@5
-  int v26; // [sp+Ch] [bp-8h]@1
-  int a3; // [sp+13h] [bp-1h]@5
-
-  v26 = a2;
-  v2 = a1;
+
+  v17 = PID_ID(a1);
   switch ( PID_TYPE(a1) )
   {
     case OBJECT_Item: // take the item
-      v17 = PID_ID(a1);
-      v26 = PID_ID(a1);
-      v18 = PID_ID(a1);
-      if ( pObjectList->pObjects[pSpriteObjects[v18].uObjectDescID].uFlags & 0x10
-        || v17 >= 1000
-        || !pSpriteObjects[v18].uObjectDescID )
+      if ( pObjectList->pObjects[pSpriteObjects[v17].uObjectDescID].uFlags & 0x10 || v17 >= 1000 || !pSpriteObjects[v17].uObjectDescID )
         return 1;
-      v19 = &pSpriteObjects[v18].stru_24;
-      v20 = pSpriteObjects[v18].stru_24.uItemID;
-      if ( pItemsTable->pItems[v20].uEquipType == EQUIP_GOLD)
+      if ( pItemsTable->pItems[pSpriteObjects[v17].stru_24.uItemID].uEquipType == EQUIP_GOLD)
       {
-        pParty->PartyFindsGold(v19->uSpecEnchantmentType, 0);
+        pParty->PartyFindsGold(pSpriteObjects[v17].stru_24.uSpecEnchantmentType, 0);
         viewparams->bRedrawGameUI = 1;
-        v21 = v17;
       }
       else
       {
         if ( pParty->pPickedItem.uItemID )
           return 1;
-        v24 = (int)pItemsTable->pItems[v20].pUnidentifiedName;
-        sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], v24);
-        ShowStatusBarString(pTmpBuf2.data(), 2u);
-        if ( v19->uItemID == 506 )
-          _449B7E_toggle_bit(pParty->_quest_bits, 184, 1u);
-        if ( v19->uItemID == 455 )
-          _449B7E_toggle_bit(pParty->_quest_bits, 185, 1u);
-        if ( !pParty->AddItemToParty(v19) )
-          pParty->SetHoldingItem(v19);
-        v21 = v26;
+        sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[v17].pUnidentifiedName);//You found an item (%s)!
+        ShowStatusBarString(pTmpBuf2.data(), 2);
+        if ( pSpriteObjects[v17].stru_24.uItemID == 506 )//artefact
+          _449B7E_toggle_bit(pParty->_quest_bits, 184, 1);
+        if ( pSpriteObjects[v17].stru_24.uItemID == 455 )
+          _449B7E_toggle_bit(pParty->_quest_bits, 185, 1);
+        if ( !pParty->AddItemToParty(&pSpriteObjects[v17].stru_24) )
+          pParty->SetHoldingItem(&pSpriteObjects[v17].stru_24);
       }
-      SpriteObject::OnInteraction(v21);
+      SpriteObject::OnInteraction(v17);
       break;
 
     case OBJECT_Actor:
-      v12 = PID_ID(a1);
-      v13 = &pActors[PID_ID(a1)];
-      v14 = v13->uAIState;
-      if ( v14 == 4 || v14 == 17 )
+      if ( pActors[v17].uAIState == Dying || pActors[v17].uAIState == Summoned )
         return 1;
-      if ( v14 == 5 )
-      {
-        pActors[PID_ID(a1)].LootActor();
-      }
+      if ( pActors[v17].uAIState == Dead )
+        pActors[v17].LootActor();
       else
       {
-        if ( !v13->GetActorsRelation(0) && !(BYTE2(v13->uAttributes) & 8) && v13->CanAct() )
+        if ( !pActors[v17].GetActorsRelation(0) && !(pActors[v17].uAttributes & 0x80000) && pActors[v17].CanAct() )
         {
-          Actor::AI_FaceObject(v12, 4u, 0, 0);
-          if ( v13->sNPC_ID )
-          {
-            pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v12, 0);
-          }
+          Actor::AI_FaceObject(v17, 4, 0, 0);
+          if ( pActors[v17].sNPC_ID )
+            pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v17, 0);
           else
           {
-            v15 = pNPCStats->pGroups_copy[v13->uGroup];
-            if ( v15 )
+            if ( pNPCStats->pGroups_copy[pActors[v17].uGroup] )
             {
-              v16 = pNPCStats->pCatchPhrases[v15];
-              if ( v16 )
+              if ( pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[v17].uGroup]] )
               {
-                pParty->uFlags |= 2u;
-                strcpy(byte_5B0938.data(), v16);
+                pParty->uFlags |= 2;
+                strcpy(byte_5B0938.data(), pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[v17].uGroup]]);
                 sub_4451A8_press_any_key(0, 0, 0);
               }
             }
@@ -5353,22 +5236,17 @@
       break;
 
     case OBJECT_Decoration:
-      v8 = &pLevelDecorations[PID_ID(a1)];
-      v9 = v8->uEventID;
-      if ( v9 )
+      if ( pLevelDecorations[v17].uEventID )
       {
-        EventProcessor(v9, a1, 1);
-        v8->uFlags |= LEVEL_DECORATION_VISIBLE_ON_MAP;
+        EventProcessor(pLevelDecorations[v17].uEventID, a1, 1);
+        pLevelDecorations[v17].uFlags |= LEVEL_DECORATION_VISIBLE_ON_MAP;
       }
       else
       {
-        if ( !pLevelDecorations[PID_ID(a1)].IsInteractive() )
+        if ( !pLevelDecorations[v17].IsInteractive() )
           return 1;
-        v10 = v8->_idx_in_stru123;
-        v24 = 1;
-        v11 = stru_5E4C90_MapPersistVars._decor_events[v10 - 75] + 380;
-        activeLevelDecoration = v8;
-        EventProcessor(v11, 0, 1);
+        activeLevelDecoration = &pLevelDecorations[v17];
+        EventProcessor(stru_5E4C90_MapPersistVars._decor_events[pLevelDecorations[v17]._idx_in_stru123 - 75] + 380, 0, 1);
         activeLevelDecoration = NULL;
       }
       break;
@@ -5381,27 +5259,25 @@
       if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
       {
         int bmodel_id = a1 >> 9,
-            face_id = PID_ID(a1) & 0x3F;
+            face_id = v17 & 0x3F;
         if (bmodel_id >= pOutdoor->uNumBModels)
           return 1;
-        ODMFace* face = &pOutdoor->pBModels[bmodel_id].pFaces[face_id];
-        if (face->uAttributes & 0x100000 || face->sCogTriggeredID == 0 )
+        if (pOutdoor->pBModels[bmodel_id].pFaces[face_id].uAttributes & FACE_UNKNOW 
+         || pOutdoor->pBModels[bmodel_id].pFaces[face_id].sCogTriggeredID == 0 )
           return 1;
-        EventProcessor((signed __int16)face->sCogTriggeredID, v2, 1);
+        EventProcessor((signed __int16)pOutdoor->pBModels[bmodel_id].pFaces[face_id].sCogTriggeredID, a1, 1);
       }
       else
       {
-        v4 = &pIndoor->pFaces[PID_ID(a1)];
-        v5 = v4->uAttributes;
-        if ( !(v5 & 0x2000000) )
+        if ( !(pIndoor->pFaces[v17].uAttributes & FACE_CLICKABLE) )
         {
           ShowNothingHereStatus();
           return 1;
         }
-        if ( v5 & 0x100000 || (v6 = pIndoor->pFaceExtras[v4->uFaceExtraID].uEventID) == 0 )
+        if ( pIndoor->pFaces[v17].uAttributes & FACE_UNKNOW || !pIndoor->pFaceExtras[pIndoor->pFaces[v17].uFaceExtraID].uEventID )
           return 1;
         if ( pCurrentScreen != SCREEN_BRANCHLESS_NPC_DIALOG )
-          EventProcessor((signed __int16)v6, v2, 1);
+          EventProcessor((signed __int16)pIndoor->pFaceExtras[pIndoor->pFaces[v17].uFaceExtraID].uEventID, a1, 1);
       }
       return 0;
       break;