diff Game.cpp @ 982:08fd1436ef35

enums & lod
author Nomad
date Sat, 11 May 2013 13:19:55 +0200
parents a6ef7125f6e4
children 1462a5f12b65
line wrap: on
line diff
--- a/Game.cpp	Sat May 11 01:28:06 2013 +0200
+++ b/Game.cpp	Sat May 11 13:19:55 2013 +0200
@@ -258,15 +258,15 @@
   Player *pPlayer; // esi@65
   //OtherOverlay *pOtherOverlay; // esi@67
   //signed int v8; // edi@67
-  int pPlayerNum; // edi@69
+  //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();
@@ -358,22 +359,13 @@
         pRenderer->EndScene();
       }
 
-      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;
-
       OnTimer(0);
       GameUI_StatusBar_UpdateTimedString(0);
       if ( pMiscTimer->bPaused && !pEventTimer->bPaused )
         pMiscTimer->Resume();
       if ( pEventTimer->bTackGameTime && !pParty->bTurnBasedModeOn )
         pEventTimer->bTackGameTime = 0;
-      if ( !pEventTimer->bPaused && uGameState == GAME_STATE_0)
+      if ( !pEventTimer->bPaused && uGameState == GAME_STATE_PLAYING)
       {
         if ( !pEventTimer->bTackGameTime )
           _494035_timed_effects__water_walking_damage__etc();
@@ -396,14 +388,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,7 +407,7 @@
       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_PARTY_DIED )
@@ -467,11 +459,9 @@
       pParty->uTimePlayed += 0x276000ui64;
       LOWORD(pParty->uFlags) &= ~0x204;
       pParty->SetGold(0);
-
       pOtherOverlayList->Reset();
+      memset(pParty->pPartyBuffs, 0, 0x140u);
 
-      memset(pParty->pPartyBuffs, 0, 0x140u);
-      pPlayerNum = 1;
       if ( pParty->bTurnBasedModeOn == 1 )
       {
         pTurnEngine->End(1);
@@ -523,23 +513,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();
@@ -547,7 +541,7 @@
     {
       sub_491E3A();
       LoadPlayerPortraintsAndVoices();
-      uGameState = GAME_STATE_0;
+      uGameState = GAME_STATE_PLAYING;
       pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
       bLoading = true;
       continue;