changeset 1331:f0be1fecd642

turn_based start fixed
author Gloval
date Wed, 03 Jul 2013 23:21:29 +0400
parents 82431a85b28e
children 1e35cfed7928 c6695ebd8fe6
files TurnEngine.h mm7_3.cpp mm7_4.cpp mm7_5.cpp
diffstat 4 files changed, 65 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/TurnEngine.h	Wed Jul 03 01:06:41 2013 +0400
+++ b/TurnEngine.h	Wed Jul 03 23:21:29 2013 +0400
@@ -36,9 +36,9 @@
     field_1C = 0;
   }
 
-  signed int _404544();
+  void  _404544();
   void _40471C();
-  signed int Start();
+  void  Start();
   void End(bool bPlaySound);
   void _405E14();
   __int16 StartTurn();
--- a/mm7_3.cpp	Wed Jul 03 01:06:41 2013 +0400
+++ b/mm7_3.cpp	Wed Jul 03 23:21:29 2013 +0400
@@ -12419,8 +12419,8 @@
 }
 
 //----- (00404544) --------------------------------------------------------
-signed int stru262_TurnBased::_404544()
-{
+void stru262_TurnBased::_404544()
+    {
   stru262_TurnBased *v1; // ebx@1
   TurnBased_QueueElem *v2; // esi@2
   Actor *v3; // edi@4
@@ -12444,6 +12444,8 @@
   signed int v21; // [sp+28h] [bp-4h]@16
   int v22; // [sp+28h] [bp-4h]@31
 
+  int i;
+
   v20 = 0;
   v1 = this;
   v19 = this->uActorQueueSize;
@@ -12464,15 +12466,16 @@
           LOBYTE(v3->uAttributes) &= 0x7Fu;
         }
       }
+
       if ( PID_TYPE(v2->uPackedID) == OBJECT_Player)
       {
         v5 = &pParty->pPlayers[v2->uPackedID >> 3];
-        if ( v5->pConditions[14]
-          || v5->pConditions[16]
-          || v5->pConditions[15]
-          || v5->pConditions[13]
-          || v5->pConditions[12]
-          || v5->pConditions[2] )
+        if ( v5->pConditions[Player::Condition_Dead]
+          || v5->pConditions[Player::Condition_Eradicated]
+          || v5->pConditions[Player::Condition_Pertified]
+          || v5->pConditions[Player::Condition_Unconcious]
+          || v5->pConditions[Player::Condition_Paralyzed]
+          || v5->pConditions[Player::Condition_Sleep] )
         {
           --v19;
           v2->field_4 = 1001;
@@ -12483,6 +12486,8 @@
     }
     while ( v20 < v1->uActorQueueSize );
   }
+
+  //sort
   v6 = v1->uActorQueueSize;
   if ( v6 > 0 )
   {
@@ -12498,10 +12503,10 @@
         {
           v9 = v8->field_4;
           v10 = v7->field_4;
-          if ( v9 < v10
-            || v9 == v10
-            && ((v11 = PID_TYPE(v8->uPackedID), v11 == OBJECT_Player) && PID_TYPE(v7->uPackedID) == OBJECT_Actor
-             || v11 == PID_TYPE(v7->uPackedID) && (v8->uPackedID & 0xFFFFFFF8) < (v7->uPackedID & 0xFFFFFFF8)) )
+          if ( v8->field_4 < v7->field_4 || v8->field_4 == v7->field_4
+            && (( PID_TYPE(v8->uPackedID) == OBJECT_Player) && PID_TYPE(v7->uPackedID) == OBJECT_Actor
+             || PID_TYPE(v8->uPackedID) == PID_TYPE(v7->uPackedID) && 
+             (v8->uPackedID & 0xFFFFFFF8) < (v7->uPackedID & 0xFFFFFFF8)) )
           {
             v12 = v7->uPackedID;
             v13 = v7->field_4;
@@ -12528,33 +12533,26 @@
     while ( v21 - 1 < v6 );
   }
   v1->uActorQueueSize = v19;
-  result = v1->pQueue[0].uPackedID;
-  if ( PID_TYPE(v1->pQueue[0].uPackedID) == OBJECT_Player)
-  {
-    result = PID_ID(result) + 1;
-    uActiveCharacter = result;
-    v1->field_18 |= 4u;
+
+
+  if ( PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
+  {
+    uActiveCharacter = PID_ID(pQueue[0].uPackedID)+1;
+    field_18 |= 4u;
   }
   else
   {
     uActiveCharacter = 0;
-    v1->field_18 &= 0xFFFFFFFBu;
-  }
-  v22 = 0;
-  if ( v1->uActorQueueSize > 0 )
-  {
-    v17 = v1->pQueue;
-    do
-    {
-      if ( PID_TYPE(v17->uPackedID) == OBJECT_Player)
-        pParty->pPlayers[PID_ID(v17->uPackedID)].uTimeToRecovery = (signed __int64)((double)v17->field_4 * 0.46875);
-      ++v22;
-      ++v17;
-      result = v22;
-    }
-    while ( v22 < v1->uActorQueueSize );
-  }
-  return result;
+    field_18 &= 0xFFFFFFFBu;
+  }
+
+  for(i=0; i<uActorQueueSize; ++i)
+      {
+      if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)
+          pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (signed __int64)((double)pQueue[i].field_4 * 0.46875);
+      }
+
+ 
 }
 
 //----- (0040471C) --------------------------------------------------------
@@ -12568,7 +12566,7 @@
 }
 
 //----- (004059DB) --------------------------------------------------------
-signed int stru262_TurnBased::Start()
+void stru262_TurnBased::Start()
     {
     //stru262_TurnBased *v1; // ebx@1
     int v3; // esi@1
@@ -12609,7 +12607,8 @@
     int activ_players[4];
     int players_recovery_time[4];
     int a_players_count;
-    int i;
+    int i,j;
+    int temp;
 
 
     pTurnEngine->field_18 &= 0xFFFFFFFDu;
@@ -12700,47 +12699,27 @@
         for (i=0; i<a_players_count; ++i)
             players_recovery_time[i] = pParty->pPlayers[PID_ID(this->pQueue[activ_players[i]].uPackedID)].GetAttackRecoveryTime(0);
         //sort players by recovery time
-        for (i=0; i<a_players_count; ++i)
-            {  //to fix
-            //v35 = v2;
-            //v34 = (int *)1;
-            //do
-            //    {
-            //    v40b = (int)v34;
-            //    if ( (signed int)v34 < (signed int)v37 )
-            //        {
-            //        v19 = (char *)&v31.uDistance + v35;
-            //        do
-            //            {
-            //            v20 = *(int *)v19;
-            //            //v33 = 4 * v40b;
-            //            v21 = (char *)(&v31.uDistance + v40b);
-            //            v22 = *(int *)v21;
-            //            if ( *(int *)v21 < v20 )
-            //                {
-            //                *(int *)v21 = v20;
-            //                v23 = 4 * v40b;
-            //                *(int *)v19 = v22;
-            //                v24 = (char *)&a3.uDistance + v23;
-            //                v25 = (char *)&a3.uDistance + v35;
-            //                v26 = *(int *)v24;
-            //                *(int *)v24 = *(unsigned int *)((char *)&a3.uDistance + v35);
-            //                *(int *)v25 = v26;
-            //                v2 = 0;
-            //                }
-            //            ++v40b;
-            //            }
-            //            while ( v40b < (signed int)v37 );
-            //        }
-            //    v34 = (int *)((char *)v34 + 1);
-            //    v35 += 4;
-            //    }
-            //    while ( (signed int)((char *)v34 - 1) < (signed int)v37 );
+        for (i=0; i < a_players_count; ++i)
+            {  
+            for(j=i+1; j<a_players_count;++j )
+                {       
+                if (players_recovery_time[j] < players_recovery_time[i]) //swap values
+                    {
+                    temp = players_recovery_time[i];
+                    players_recovery_time[i] = players_recovery_time[j];
+                    players_recovery_time[j] = temp;
+
+                    temp = activ_players[i];
+                    activ_players[i] = activ_players[j];
+                    activ_players[j] = temp;
+                    }
+                }
             }
+           
         for (i=0; i<a_players_count; ++i)
             {
             this->pQueue[activ_players[i]].field_4 = i+2;
             }
         }
-    return this->_404544();
-    }
+    this->_404544();
+    }
--- a/mm7_4.cpp	Wed Jul 03 01:06:41 2013 +0400
+++ b/mm7_4.cpp	Wed Jul 03 23:21:29 2013 +0400
@@ -6280,7 +6280,6 @@
 void stru262_TurnBased::End(bool bPlaySound)
 {
   stru262_TurnBased *v2; // edi@1
-  int v3; // ebx@1
   int v4; // esi@1
   unsigned __int8 v5; // zf@1
   unsigned __int8 v6; // sf@1
@@ -6294,7 +6293,6 @@
   int v14; // [sp+Ch] [bp-4h]@11
 
   v2 = this;
-  v3 = 0;
   v4 = 0;
   v5 = this->uActorQueueSize == 0;
   v6 = this->uActorQueueSize < 0;
@@ -6311,6 +6309,7 @@
     }
     while ( v4 < v2->uActorQueueSize );
   }
+
   if ( (signed int)uNumSpriteObjects > 0 )
   {
     pAttributes = &pSpriteObjects[0].uAttributes;
@@ -6328,6 +6327,7 @@
     }
     while ( v9 );
   }
+
   v14 = 0;
   if ( v2->uActorQueueSize > 0 )
   {
@@ -6349,15 +6349,15 @@
       ++v11;
     }
     while ( v14 < v2->uActorQueueSize );
-    v3 = 0;
   }
+
   pAudioPlayer->StopChannels(-1, -1);
-  if ( bPlaySound != v3 )
-    pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|SOUND_EnteringAHouse), v3, v3, -1, v3, v3, v3, v3);
+  if ( bPlaySound != 0 )
+    pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|SOUND_EnteringAHouse), 0, 0, -1, 0, 0, 0, 0);
   pTurnEngine->field_18 &= 0xFFFFFFFDu;
   pEventTimer->StopGameTime();
-  dword_50C994 = v3;
-  dword_50C998_turnbased_icon_1A = v3;
+  dword_50C994 = 0;
+  dword_50C998_turnbased_icon_1A = 0;
 }
 // 50C994: using guessed type int dword_50C994;
 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A;
--- a/mm7_5.cpp	Wed Jul 03 01:06:41 2013 +0400
+++ b/mm7_5.cpp	Wed Jul 03 23:21:29 2013 +0400
@@ -5242,7 +5242,7 @@
   unsigned int v5; // edi@14
 
   v1 = this;
-  LOWORD(v2) = _404544();
+  _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 = (PID_ID(v2)) + 1, uActiveCharacter = v2),
         viewparams->bRedrawGameUI = 1,
@@ -5785,7 +5785,7 @@
   unsigned int uActorID; // [sp+50h] [bp-4h]@2
   unsigned int a2a; // [sp+5Ch] [bp+8h]@7
 
-  __debugbreak();//срабатывает при пошаговом режиме после пяти шагов
+ // __debugbreak();//срабатывает при пошаговом режиме после пяти шагов
   v2 = *(&this->field_0 + 4 * (a2 + 2));
   if (PID_TYPE(v2) == OBJECT_Player)
     return 0;