diff Game.cpp @ 986:b584c743cb47

Слияние
author Ritor1
date Sun, 12 May 2013 09:38:30 +0600
parents 1462a5f12b65
children 3431f6abc786
line wrap: on
line diff
--- a/Game.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/Game.cpp	Sun May 12 09:38:30 2013 +0600
@@ -256,17 +256,17 @@
   signed int pNewNPCsCount; // ecx@58
   char *pFlags; // eax@59
   Player *pPlayer; // esi@65
-  OtherOverlay *pOtherOverlay; // esi@67
-  signed int v8; // edi@67
-  int pPlayerNum; // edi@69
+  //OtherOverlay *pOtherOverlay; // esi@67
+  //signed int v8; // edi@67
+  //int pPlayerNum; // edi@69
   int *pHealth; // esi@71
-  signed int v11; // esi@78
-  int v12; // eax@83
+  //signed int v11; // esi@78
+  //int v12; // eax@83
   const char *pLocationName; // [sp-4h] [bp-68h]@74
   bool bLoading; // [sp+10h] [bp-54h]@1
-  signed int bLoadinga; // [sp+10h] [bp-54h]@19
+  //signed int bLoadinga; // [sp+10h] [bp-54h]@19
   signed int v16; // [sp+14h] [bp-50h]@8
-  int v17[4]; // [sp+18h] [bp-4Ch]@80
+  //int v17[4]; // [sp+18h] [bp-4Ch]@80
   MSG Msg; // [sp+28h] [bp-3Ch]@20
   char Source[64]; // [sp+44h] [bp-20h]@76
 
@@ -276,7 +276,7 @@
   {
     pParty->Reset();
     dword_6BE340 = 0;
-    uGameState = GAME_STATE_0;
+    uGameState = GAME_STATE_PLAYING;
     LoadGame(uLoadGameUI_SelectedSlot);
   }
 
@@ -314,7 +314,8 @@
       pAsyncKeyboard->Resume();
     if ( pRenderer->pRenderD3D )
       pGame->pVisInstance->_4C1A02();
-    bLoadinga = 0;
+
+    bool game_finished = false;
     do
     {
       while ( PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE) )
@@ -349,7 +350,7 @@
         pMouse->_469EA4();
         pRenderer->EndScene();
       }
-      if ( pVideoPlayer->pBinkMovie && !BinkWait(pVideoPlayer->pBinkMovie) )
+      else if ( pVideoPlayer->pBinkMovie && !BinkWait(pVideoPlayer->pBinkMovie) )
       {
         pRenderer->BeginScene();
         pMouse->DrawCursorToTarget();
@@ -357,13 +358,12 @@
         pMouse->_469EA4();
         pRenderer->EndScene();
       }
+      
+      pEventTimer->Update();
+      pMiscTimer->Update();
 
       static int gtc_old = GetTickCount();
       int gtc = GetTickCount();
-      auto evt_old = pEventTimer->uStartTime,
-           msc_old = pMiscTimer->uStartTime;
-      pEventTimer->Update();
-      pMiscTimer->Update();
       Log::Warning(L"Evt/Msc/GTC dt: %u/%u/%u", pEventTimer->uTimeElapsed, pMiscTimer->uTimeElapsed, gtc - gtc_old);
       gtc_old = gtc;
 
@@ -373,7 +373,7 @@
         pMiscTimer->Resume();
       if ( pEventTimer->bTackGameTime && !pParty->bTurnBasedModeOn )
         pEventTimer->bTackGameTime = 0;
-      if ( !pEventTimer->bPaused && !uGameState )
+      if ( !pEventTimer->bPaused && uGameState == GAME_STATE_PLAYING)
       {
         if ( !pEventTimer->bTackGameTime )
           _494035_timed_effects__water_walking_damage__etc();
@@ -396,14 +396,14 @@
       if (uGameState == GAME_FINISHED)
         //goto LABEL_96;
       {
-        bLoadinga = 1;
+        game_finished = true;
         continue;
       }
       if (uGameState == GAME_STATE_2)
       {
         pAudioPlayer->StopChannels(-1, -1);
         PrepareWorld(0);
-        uGameState = GAME_STATE_0;
+        uGameState = GAME_STATE_PLAYING;
         continue;
       }
       if ( (signed int)uGameState <= GAME_STATE_2 )
@@ -415,22 +415,24 @@
       if ( (signed int)uGameState <= GAME_STATE_5 || uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU )
       {
 //LABEL_96:
-        bLoadinga = 1;
+        game_finished = true;
         continue;
       }
-      if ( uGameState != GAME_STATE_8 )
+      if ( uGameState != GAME_STATE_PARTY_DIED )
       {
         if ( uGameState != GAME_STATE_FINAL_WINDOW )
         {
 //LABEL_85:
           pGame->Draw();
-          continue;
         }
-        pRenderer->BeginScene();
-        GUI_UpdateWindows();
-        pRenderer->EndScene();
-        //goto LABEL_89;
-        pRenderer->Present();
+        else
+        {
+          pRenderer->BeginScene();
+          GUI_UpdateWindows();
+          pRenderer->EndScene();
+          //goto LABEL_89;
+          pRenderer->Present();
+        }
         continue;
       }
       pAudioPlayer->StopChannels(-1, -1);//    
@@ -465,17 +467,9 @@
       pParty->uTimePlayed += 0x276000ui64;
       LOWORD(pParty->uFlags) &= ~0x204;
       pParty->SetGold(0);
-      pOtherOverlay = pOtherOverlayList->pOverlays;
-      v8 = 50;
-      do
-      {
-        pOtherOverlay->Reset();
-        ++pOtherOverlay;
-        --v8;
-      }
-      while ( v8 );
+      pOtherOverlayList->Reset();
       memset(pParty->pPartyBuffs, 0, 0x140u);
-      pPlayerNum = 1;
+
       if ( pParty->bTurnBasedModeOn == 1 )
       {
         pTurnEngine->End(1);
@@ -493,7 +487,7 @@
         uActiveCharacter = 1;
       }
     //  while ( (signed int)pHealth < (signed int)&pParty->field_871C[567] );
-      if ( (unsigned __int16)_449B57_test_bit(pParty->_quest_bits, 136) )
+      if (_449B57_test_bit(pParty->_quest_bits, PARTY_QUEST_FINISHED_EMERALD_ISLE))
       {
         pParty->vPosition.x = -17331;            // respawn in harmondale
         pParty->vPosition.y = 12547;
@@ -527,23 +521,27 @@
         PrepareWorld(1);
       }
       InitializeActors();
-      v11 = 0;
-      do
+
+
+      int num_conscious_players = 0;
+      int conscious_players_ids[4] = {-1, -1, -1, -1};
+      for (int v11 = 0; v11 < 4; ++v11)
       {
-        if ( pPlayers[pPlayerNum]->CanAct() )
-          v17[v11++] = pPlayerNum;
-        ++pPlayerNum;
+        if (pPlayers[v11 + 1]->CanAct())
+          conscious_players_ids[num_conscious_players++] = v11;
       }
-      while ( pPlayerNum <= 4 );
-      if ( v11 )
+      if (num_conscious_players)
       {
-        v12 = rand();
-        pPlayers[v17[v12 % v11]]->PlaySound(SPEECH_99, 0);
+        int idx = conscious_players_ids[rand() % num_conscious_players];
+        assert(idx >= 0);
+        pPlayers[idx + 1]->PlaySound(SPEECH_99, 0);
       }
+
       ShowStatusBarString(pGlobalTXT_LocalizationStrings[524], 2u);// "Once again you've cheated death!.." "   ! "
-      uGameState = GAME_STATE_0;
+      uGameState = GAME_STATE_PLAYING;
     }
-    while ( !bLoadinga );
+    while (!game_finished);
+
     dword_6BE340 = 0;
     pEventTimer->Pause();
     ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
@@ -551,7 +549,7 @@
     {
       sub_491E3A();
       LoadPlayerPortraintsAndVoices();
-      uGameState = GAME_STATE_0;
+      uGameState = GAME_STATE_PLAYING;
       pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
       bLoading = true;
       continue;