diff mm7_5.cpp @ 848:ceef50611567

* AI fixed (temporary) * PID_ID, PID_TYPE replaces * >> 7 error in AudioPlayer
author zipi
date Sun, 31 Mar 2013 10:44:43 +0100
parents ae8f83e1b0cf
children 8fafe3645f36
line wrap: on
line diff
--- a/mm7_5.cpp	Sat Mar 30 19:36:05 2013 +0400
+++ b/mm7_5.cpp	Sun Mar 31 10:44:43 2013 +0100
@@ -1741,9 +1741,9 @@
             v42 = pRenderer->pActiveZBuffer[*(int *)uNumSeconds + pSRZBufferLineOffsets[pPoint->y]];
           }
           v44 = (unsigned __int16)v42;
-          v45 = v44 & 7;
+          v45 = PID_TYPE(v44);
           uNumSeconds = v44;
-          v46 = v44 >> 3;
+          v46 = PID_ID(v44);
           if ( v45 == 3 )
           {
             v47 = pActors[v46].uAIState == Dead;
@@ -2397,7 +2397,7 @@
           v83 = v81;
           v44 = (unsigned __int16)v81;
           v84 = v83 >> 16;
-          if ( (v44 & 7) != 3 || v84 >= 5120 )
+          if ( PID_TYPE(v44) != 3 || v84 >= 5120 )
             //goto LABEL_90;
             {
             v1 = "";
@@ -4532,24 +4532,24 @@
     v1 = (char *)stru_50FE08.pZs;
     do
     {
-      v2 = *((short *)v1 - 300) & 7;
-      v3 = (signed int)*((short *)v1 - 300) >> 3;
-      v39 = (signed int)*((short *)v1 - 300) >> 3;
+      v2 = PID_TYPE(*((short *)v1 - 300));
+      v3 = PID_ID((signed int)*((short *)v1 - 300));
+      v39 = PID_ID((signed int)*((short *)v1 - 300));
       if ( v2 == 2 )
       {
         v4 = &pSpriteObjects[v3];
         v36 = v4;
         v5 = v4->spell_caster_pid;
-        v2 = v5 & 7;
-        v3 = v5 >> 3;
+        v2 = PID_TYPE(v5);
+        v3 = PID_ID(v5);
       }
       v41 = v2;
       v37 = v3;
       if ( stru_50FE08.field_3EC[v0] & 1 )
       {
         v6 = ai_near_actors_targets_pid[v3];
-        v7 = v6 >> 3;
-        v8 = (v6 & 7) - 3;
+        v7 = PID_ID(v6);
+        v8 = PID_TYPE(v6) - 3;
         uActorID = v7;
         if ( v8 )
         {
@@ -4775,9 +4775,9 @@
   v61 = 0;
   v59 = 0;
   v62 = 0;
-  if ( (a1 & 7) == OBJECT_Item)
-  {
-    v4 = &pSpriteObjects[a1 >> 3];
+  if ( PID_TYPE(a1) == OBJECT_Item)
+  {
+    v4 = &pSpriteObjects[PID_ID(a1)];
     //uDamageAmount = (int)v4;
     v61 = v4->field_60_distance_related_prolly_lod;
     a1 = v4->spell_caster_pid;
@@ -4785,11 +4785,11 @@
   }
   //v5 = a1 & 7;
   //uPlayerID = a1 >> 3;
-  if ((a1 & 7) != OBJECT_Player)
+  if (PID_TYPE(a1) != OBJECT_Player)
     return;
 
-  assert(abs(a1 >> 3) < 4);
-  auto player = &pParty->pPlayers[a1 >> 3];
+  assert(PID_ID(abs(a1)) < 4);
+  auto player = &pParty->pPlayers[PID_ID(a1)];
   pMonster = &pActors[uActorID_Monster_];
   //uPlayerID = pMonster->IsAlive();
   if (pMonster->IsNotAlive())
@@ -5250,8 +5250,8 @@
   signed int a4a; // [sp+60h] [bp+Ch]@162
   Player *a4b; // [sp+60h] [bp+Ch]@168
 
-  v4 = (signed int)uObjID >> 3;
-  v5 = (uObjID & 7) - 2;
+  v4 = PID_ID(uObjID);
+  v5 = PID_TYPE(uObjID) - 2;
   v74 = a2;
   uActorID = v4;
   if ( v5 )
@@ -5448,10 +5448,10 @@
     return;
   }
   v37 = &pSpriteObjects[uActorID];
-  v38 = v37->spell_caster_pid & 7;
-  v39 = v37->spell_caster_pid >> 3;
-  v40 = v37->spell_caster_pid & 7;
-  uActorID = v37->spell_caster_pid >> 3;
+  v38 = PID_TYPE(v37->spell_caster_pid);
+  v39 = PID_ID(v37->spell_caster_pid);
+  v40 = PID_TYPE(v37->spell_caster_pid);
+  uActorID = PID_ID(v37->spell_caster_pid);
   v41 = v40 - 2;
   if ( !v41 )
     goto LABEL_80;
@@ -5847,9 +5847,9 @@
   a2 = uObjID;
   if ( !pActors[uActorID].IsNotAlive() )
   {
-    if ( (a2 & 7) == OBJECT_Item)
-    {
-      v4 = &pSpriteObjects[(signed int)a2 >> 3];
+    if ( PID_TYPE(a2) == OBJECT_Item)
+    {
+      v4 = &pSpriteObjects[PID_ID(a2)];
       v5 = v4->spell_id;
       if ( v5 )
       {
@@ -5906,17 +5906,17 @@
   v4 = 0;
   uActorID = a2;
   v17 = a1;
-  if ( (a1 & 7) == OBJECT_Item)
-  {
-    v5 = &pSpriteObjects[a1 >> 3];
+  if ( PID_TYPE(a1) == OBJECT_Item)
+  {
+    v5 = &pSpriteObjects[PID_ID(a1)];
     v4 = v5->field_60_distance_related_prolly_lod;
     v17 = v5->spell_caster_pid;
   }
-  LOWORD(v6) = v17 & 7;
+  LOWORD(v6) = PID_TYPE(v17);
   if ( v6 == OBJECT_Actor)
   {
     v7 = &pActors[a2];
-    v8 = &pActors[v17 >> 3];
+    v8 = &pActors[PID_ID(v17)];
     v6 = pActors[a2].IsNotAlive();
     if ( !v6 )
     {
@@ -6759,7 +6759,7 @@
     while ( 1 )
     {
       v5 = v16->uPackedID;
-      if ( (v16->uPackedID & 7) == OBJECT_Player)
+      if ( PID_TYPE(v16->uPackedID) == OBJECT_Player)
         break;
 LABEL_8:
       ++v17;
@@ -6767,8 +6767,8 @@
       if ( v17 >= v1->uActorQueueSize )
         goto LABEL_11;
     }
-    v15 = v5 >> 3;
-    if ( !pPlayers[(v5 >> 3) + 1]->CanAct() || v19 != v15 )
+    v15 = PID_ID(v5);
+    if ( !pPlayers[(PID_ID(v5)) + 1]->CanAct() || v19 != v15 )
     {
       v2 = 0;
       goto LABEL_8;
@@ -6802,7 +6802,7 @@
         v8 = v1->pQueue;
         do
         {
-          if ( (v8->uPackedID & 7) == OBJECT_Actor && ai_near_actors_ids[v20] == v8->uPackedID >> 3 )
+          if ( PID_TYPE(v8->uPackedID) == OBJECT_Actor && ai_near_actors_ids[v20] == PID_ID(v8->uPackedID) )
             break;
           ++v18;
           ++v8;
@@ -6846,7 +6846,7 @@
     v13 = (char *)&v1->pQueue[0].field_4;
     do
     {
-      v11 = *((int *)v13 - 1) & 7;
+      v11 = PID_TYPE(*((int *)v13 - 1));
       if ( (char)v11 == 4 )
         break;
       if ( *(int *)v13 > 0 )
@@ -6936,7 +6936,7 @@
           if ( v6 != 8 )
             goto LABEL_19;
           v3 = 0;
-          Actor::AI_StandOrBored(v2->uPackedID >> 3, ai_near_actors_targets_pid[v2->uPackedID >> 3], 32, 0);
+          Actor::AI_StandOrBored(PID_ID(v2->uPackedID), ai_near_actors_targets_pid[PID_ID(v2->uPackedID)], 32, 0);
         }
       }
     }
@@ -7039,7 +7039,7 @@
     }
     else
     {
-      v8 = &pActors[v1->pQueue[0].uPackedID >> 3];
+      v8 = &pActors[PID_ID(v1->pQueue[0].uPackedID)];
       if ( v4 > 0 )
       {
         do
@@ -7091,10 +7091,10 @@
 
   v2 = this;
   v3 = *(&this->field_0 + 4 * (a2 + 2));
-  if ( (*((char *)&this->field_0 + 16 * (a2 + 2)) & 7) == OBJECT_Player)
-  {
-    v4 = v3 >> 3;
-    v5 = (char *)&pParty->pTurnBasedPlayerRecoveryTimes[v3 >> 3];
+  if ( (*((char *)&this->field_0 + 16 * PID_TYPE(a2 + 2))) == OBJECT_Player)
+  {
+    v4 = PID_ID(v3);
+    v5 = (char *)&pParty->pTurnBasedPlayerRecoveryTimes[PID_ID(v3)];
     v6 = *(int *)v5;
     if ( *(int *)v5 )
       *(int *)v5 = 0;
@@ -7105,7 +7105,7 @@
   }
   else
   {
-    v6 = pMonsterStats->pInfos[pActors[v3 >> 3].pMonsterInfo.uID].uRecoveryTime;
+    v6 = pMonsterStats->pInfos[pActors[PID_ID(v3)].pMonsterInfo.uID].uRecoveryTime;
   }
   v2->pQueue[a2].field_4 = v6;
   v2->_404544();
@@ -7143,7 +7143,7 @@
 //----- (0040652A) --------------------------------------------------------
 void stru262_TurnBased::_40652A()
 {
-  char *v1; // edx@2
+  int *v1; // edx@2
   Actor *v2; // eax@5
   unsigned __int16 v3; // si@5
   unsigned int v4; // esi@8
@@ -7152,14 +7152,14 @@
   v5 = 0;
   if ( this->uActorQueueSize > 0 )
   {
-    v1 = (char *)&this->pQueue[0].field_4;
+    v1 = &this->pQueue[0].field_4;
     do
     {
       if ( !*(int *)v1 )
       {
-        if ( (*(v1 - 4) & 7) == OBJECT_Player)
+        if ( PID_TYPE(*(v1 - 4)) == OBJECT_Player)
           return;
-        v2 = &pActors[*((int *)v1 - 1) >> 3];
+        v2 = &pActors[PID_ID(*(v1 - 1))];
         v3 = v2->uAIState;
         if (v3 == Standing || v3 == Fleeing || v3 == Fidgeting)
         {
@@ -7188,7 +7188,7 @@
   v1 = this;
   LOWORD(v2) = _404544();
   if ( v1->pQueue[0].field_4 <= 0
-    || ((_4063A1(), v2 = v1->pQueue[0].uPackedID, PID_TYPE(v1->pQueue[0].uPackedID) != OBJECT_Player) ? (uActiveCharacter = 0) : (v2 = (v2 >> 3) + 1, uActiveCharacter = v2),
+    || ((_4063A1(), v2 = v1->pQueue[0].uPackedID, PID_TYPE(v1->pQueue[0].uPackedID) != OBJECT_Player) ? (uActiveCharacter = 0) : (v2 = (PID_ID(v2)) + 1, uActiveCharacter = v2),
         viewparams->bRedrawGameUI = 1,
         v1->pQueue[0].field_4 <= 0) )
   {
@@ -7199,7 +7199,7 @@
       do
       {
         v2 = *(int *)v4;
-        if ( (*(char *)v4 & 7) == OBJECT_Player || *(int *)(v4 + 4) > 0 )
+        if ( PID_TYPE(*(char *)v4) == OBJECT_Player || *(int *)(v4 + 4) > 0 )
           break;
         if ( *(int *)(v4 + 8) <= 0 )
         {
@@ -7262,7 +7262,7 @@
     a2a = ai_near_actors_targets_pid[PID_ID(v3)];
     memcpy(&a3, Actor::GetDirectionInfo(v1->uPackedID, ai_near_actors_targets_pid[PID_ID(v3)], &a3, 0), sizeof(a3));
     memcpy(&a4, &a3, sizeof(a4));
-    v5 = &pActors[PID_ID(v3 >> 3)];
+    v5 = &pActors[PID_ID(v3)];
     LOWORD(v3) = v5->uAIState;
     if ( (short)v3 != Dead )
     {
@@ -7369,8 +7369,8 @@
 __int16 stru262_TurnBased::_40680F(int a2)
 {
   TurnBased_QueueElem *v2; // eax@1
-  TurnBased_QueueElem *v3; // eax@1
-  TurnBased_QueueElem *v4; // edi@2
+  unsigned int v3; // eax@1
+  unsigned int v4; // edi@2
   Actor *v5; // ebx@2
   unsigned int *v6; // esi@7
   AIDirection *v7; // esi@10
@@ -7392,13 +7392,13 @@
   v2 = (TurnBased_QueueElem *)((char *)this + 16 * (a2 + 2));
   v21 = v2;
   v2->uActionLength = 0;
-  v3 = (TurnBased_QueueElem *)v2->uPackedID;
+  v3 = v2->uPackedID;
   if ( (unsigned __int8)v3 & 3 )
   {
-    v3 = (TurnBased_QueueElem *)((signed int)v3 >> 3);
+    v3 = PID_ID(v3);
     v4 = v3;
-    a2a = (int)v3;
-    v5 = &pActors[(int)v3];
+    a2a = v3;
+    v5 = &pActors[v3];
     LOWORD(v3) = v5->uAIState;
     if ( (short)v3 != 5 )
     {
@@ -7421,7 +7421,7 @@
           v20 = 0;
         }
         if (PID_TYPE(v22) == OBJECT_Actor)
-          v10 = (unsigned __int8)*(&byte_5C8D1A[89 * (pMonsterStats->pInfos[pActors[v22 >> 3].pMonsterInfo.uID].uID - 1) / 3] + (v5->pMonsterInfo.uID - 1) / 3);
+          v10 = (unsigned __int8)*(&byte_5C8D1A[89 * (pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID - 1) / 3] + (v5->pMonsterInfo.uID - 1) / 3);
         else
           v10 = 4;
         if ( v10 == 1 )
@@ -7496,24 +7496,25 @@
           {
             Actor::_403476(v13, v22, &v18);
 LABEL_43:
-            v3 = v21;
+            //v3 = v21;
             v21->field_C = 1;
 LABEL_48:
-            v3->uActionLength = v5->uCurrentActionLength;
-            return (signed __int16)v3;
+            v21->uActionLength = v5->uCurrentActionLength;
+            //return (signed __int16)v3;
+			return (signed __int16)&v21;
           }
         }
 LABEL_44:
         if ( (double)(signed int)v20 < 307.2 )
         {
           Actor::_403C6C(v13, v22, &v18);
-          v3 = v21;
+          //v3 = v21;
           v21->field_C = 3;
           goto LABEL_48;
         }
 LABEL_47:
         Actor::AI_Stand(v13, v22, 0x40u, &v18);
-        v3 = v21;
+        //v3 = v21;
         v21->field_C = 0;
         goto LABEL_48;
       }
@@ -7555,7 +7556,7 @@
         v8 = ai_near_actors_targets_pid[PID_ID(v5)];
         memcpy(&v7, Actor::GetDirectionInfo(v5, v8, &a3, v2), sizeof(v7));
         if ( !v1->_406D10(a2) )
-          Actor::AI_Stand(v10->uPackedID >> 3, v8, 0x20u, &v7);
+          Actor::AI_Stand(PID_ID(v10->uPackedID), v8, 0x20u, &v7);
       }
       ++a2;
       ++v10;
@@ -7646,7 +7647,7 @@
       a1 = v14->uPackedID;
       if (PID_TYPE(a1) != OBJECT_Player)
       {
-        v5 = v4 >> 3;
+        v5 = PID_ID(v4);
         v12 = v5;
         v6 = &pActors[v5];
         if ( SHIDWORD(v6->pActorBuffs[5].uExpireTime) < result
@@ -8042,8 +8043,8 @@
   int v65; // [sp+60h] [bp-8h]@4
   int v66; // [sp+64h] [bp-4h]@7
 
-  v2 = (signed int)uObjID >> 3;
-  v3 = (uObjID & 7) - 2;
+  v2 = PID_ID(uObjID);
+  v3 = PID_TYPE(uObjID) - 2;
   v4 = uObj2ID;
   if ( v3 )
   {
@@ -8078,8 +8079,8 @@
     v65 = v11;
   }
   v66 = v7;
-  v12 = v4 >> 3;
-  v13 = (v4 & 7) - 2;
+  v12 = PID_ID(v4);
+  v13 = PID_TYPE(v4) - 2;
   if ( v13 )
   {
     v14 = v13 - 1;