changeset 2124:7f403ebf619f

GAME_STATE_CHANGE_LOCATION
author Ritor1
date Fri, 27 Dec 2013 01:28:48 +0600
parents de5cdcb03fda
children ba3de1337989
files Events.cpp Game.cpp Game.h SaveLoad.cpp SpriteObject.cpp UI/UIHouses.cpp mm7_3.cpp
diffstat 7 files changed, 119 insertions(+), 154 deletions(-) [+]
line wrap: on
line diff
--- a/Events.cpp	Thu Dec 26 00:19:49 2013 +0600
+++ b/Events.cpp	Fri Dec 27 01:28:48 2013 +0600
@@ -1424,7 +1424,7 @@
           v133 = 1;
           if ( pCurrentScreen == SCREEN_HOUSE )
             {
-            if ( uGameState == GAME_STATE_2 )
+            if ( uGameState == GAME_STATE_CHANGE_LOCATION )
               {
               pAudioPlayer->StopChannels(-1, -1);
               dialog_menu_id = HOUSE_DIALOGUE_NULL;
--- a/Game.cpp	Thu Dec 26 00:19:49 2013 +0600
+++ b/Game.cpp	Fri Dec 27 01:28:48 2013 +0600
@@ -280,30 +280,15 @@
 //----- (00463149) --------------------------------------------------------
 void Game::Loop()
 {
-  //signed int v0; // ebp@3
-  //signed int v1; // esi@4
-  //Render *v2; // edi@7
-  //signed int v3; // esi@7
-  signed int pNewNPCsCount; // ecx@58
-  NPCData *pNPC; // eax@59
-  Player *pPlayer; // esi@65
-  //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
   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 v16; // [sp+14h] [bp-50h]@8
-  //int v17[4]; // [sp+18h] [bp-4Ch]@80
   MSG Msg; // [sp+28h] [bp-3Ch]@20
   char Source[64]; // [sp+44h] [bp-20h]@76
 
   bLoading = sCurrentMenuID == MENU_LoadingProcInMainMenu;
   SetCurrentMenuID((MENU_STATE)-1);
-  if (bLoading)
+  if (sCurrentMenuID == MENU_LoadingProcInMainMenu)
   {
     pParty->Reset();
     uGameState = GAME_STATE_PLAYING;
@@ -397,152 +382,129 @@
         viewparams->bRedrawGameUI = true;
       }
       pAudioPlayer->UpdateSounds();
+      if ( (signed int)uGameState == GAME_STATE_PLAYING )
+      {
+        pGame->Draw();
+        continue;
+      }
       if (uGameState == GAME_FINISHED)
-        //goto LABEL_96;
       {
         game_finished = true;
         continue;
       }
-      if (uGameState == GAME_STATE_2)
+      if (uGameState == GAME_STATE_CHANGE_LOCATION)// смена локации
       {
         pAudioPlayer->StopChannels(-1, -1);
         PrepareWorld(0);
         uGameState = GAME_STATE_PLAYING;
         continue;
       }
-      if ( (signed int)uGameState <= GAME_STATE_2 )
-        //goto LABEL_85;
+      if ( (signed int)uGameState <= GAME_STATE_5 || uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU )
       {
-        pGame->Draw();
+        game_finished = true;
         continue;
       }
-      if ( (signed int)uGameState <= GAME_STATE_5 || uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU )
+      if ( uGameState == GAME_STATE_FINAL_WINDOW )
       {
-//LABEL_96:
-        game_finished = true;
+        pRenderer->BeginScene();
+        GUI_UpdateWindows();
+        pRenderer->EndScene();
+        pRenderer->Present();
         continue;
       }
       if ( uGameState != GAME_STATE_PARTY_DIED )
       {
-        if ( uGameState != GAME_STATE_FINAL_WINDOW )
+        pGame->Draw();
+        continue;
+      }
+      if ( uGameState == GAME_STATE_PARTY_DIED )
+      {
+        pAudioPlayer->StopChannels(-1, -1);
+        memset(&pParty->pHirelings[0], 0, 0x4Cu);
+        memset(&pParty->pHirelings[1], 0, 0x4Cu);
+        for ( int i = 0; i < (signed int)pNPCStats->uNumNewNPCs; ++i )
         {
-//LABEL_85:
-          pGame->Draw();
+          if ( pNPCStats->pNewNPCData[i].field_24 )
+            pNPCStats->pNewNPCData[i].uFlags &= 0xFFFFFF7Fu;
+        }
+        pVideoPlayer->PlayDeathMovie();
+        if ( pVideoPlayer->AnyMovieLoaded() )
+          pVideoPlayer->Unload();
+        SaveGame(0, 0);
+        ++pParty->uNumDeaths;
+        for ( uint i = 0; i < 4; ++i )
+          pParty->pPlayers[i].SetVariable(VAR_Award, 85);
+        pParty->days_played_without_rest = 0;
+        pParty->uTimePlayed += 0x276000ui64;
+        LOWORD(pParty->uFlags) &= ~0x204;
+        pParty->SetGold(0);
+        pOtherOverlayList->Reset();
+        memset(pParty->pPartyBuffs.data(), 0, 0x140u);
+
+        if ( pParty->bTurnBasedModeOn == 1 )
+        {
+          pTurnEngine->End(true);
+          pParty->bTurnBasedModeOn = 0;
+        }
+        for( int i = 0; i < 4; ++i)
+        {
+          memset(pParty->pPlayers[i].pConditions.data(), 0, 0xA0u);//(pConditions, 0, 160)
+          memset(pParty->pPlayers[i].pPlayerBuffs.data(), 0, 0x180u);//(pPlayerBuffs[0], 0, 384)
+          pParty->pPlayers[i].sHealth = 1;
+          uActiveCharacter = 1;
+        }
+        if (_449B57_test_bit(pParty->_quest_bits, PARTY_QUEST_FINISHED_EMERALD_ISLE))
+        {
+          pParty->vPosition.x = -17331;            // respawn in harmondale
+          pParty->vPosition.y = 12547;
+          pParty->vPosition.z = 465;
+          pParty->sRotationY = 0;
+          pLocationName = "out02.odm";
         }
         else
         {
-          pRenderer->BeginScene();
-          GUI_UpdateWindows();
-          pRenderer->EndScene();
-          //goto LABEL_89;
-          pRenderer->Present();
-        }
-        continue;
-      }
-      pAudioPlayer->StopChannels(-1, -1);//далее в случае смерти группы
-      memset(&pParty->pHirelings[0], 0, 0x4Cu);
-      memset(&pParty->pHirelings[1], 0, 0x4Cu);
-      pNewNPCsCount = 0;
-      if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
-      {
-        pNPC = pNPCStats->pNewNPCData;
-        do
-        {
-		  if ( pNPC->field_24 )
-			  pNPC->uFlags &= 0xFFFFFF7Fu;
-          ++pNewNPCsCount;
-          ++pNPC;
+          pParty->vPosition.x = 12552;             // respawn on emerald isle
+          pParty->vPosition.y = 1816;
+          pParty->vPosition.z = 0;
+          pParty->sRotationY = 512;
+          pLocationName = "out01.odm";
         }
-        while ( pNewNPCsCount < (signed int)pNPCStats->uNumNewNPCs );
-      }
-      pVideoPlayer->PlayDeathMovie();
-      if ( pVideoPlayer->AnyMovieLoaded() )
-        pVideoPlayer->Unload();
-      SaveGame(0, 0);
-      ++pParty->uNumDeaths;
-      pPlayer = pParty->pPlayers.data();
-      do
-      {
-        pPlayer->SetVariable(VAR_Award, 85);
-        ++pPlayer;
-      }
-      while ( (signed int)pPlayer < (signed int)pParty->pHirelings.data() );
-      pParty->days_played_without_rest = 0;
-      pParty->uTimePlayed += 0x276000ui64;
-      LOWORD(pParty->uFlags) &= ~0x204;
-      pParty->SetGold(0);
-      pOtherOverlayList->Reset();
-      memset(pParty->pPartyBuffs.data(), 0, 0x140u);
+        strcpy(Source, pLocationName);
+        pParty->uFallStartY = pParty->vPosition.z;
+        pParty->sRotationX = 0;
+        pParty->uFallSpeed = 0;
+        pParty->field_6E4 = 0;
+        pParty->field_6E0 = 0;
+        if ( _stricmp(Source, pCurrentMapName) )
+        {
+          strcpy(pCurrentMapName, Source);
+          _5B65A8_npcdata_uflags_or_other = pParty->vPosition.x;
+          _5B65AC_npcdata_fame_or_other = pParty->vPosition.y;
+          _5B65B0_npcdata_rep_or_other = pParty->vPosition.z;
+          _5B65B4_npcdata_loword_house_or_other = pParty->sRotationY;
+          _5B65B8_npcdata_hiword_house_or_other = pParty->sRotationX;
+          dword_5B65C0 = 1;
+          PrepareWorld(1);
+        }
+        InitializeActors();
 
-      if ( pParty->bTurnBasedModeOn == 1 )
-      {
-        pTurnEngine->End(true);
-        pParty->bTurnBasedModeOn = 0;
+        int num_conscious_players = 0;
+        int conscious_players_ids[4] = {-1, -1, -1, -1};
+        for (int i = 0; i < 4; ++i)
+        {
+          if (pParty->pPlayers[i].CanAct())
+            conscious_players_ids[num_conscious_players++] = i;
+        }
+        if (num_conscious_players)
+        {
+          int idx = conscious_players_ids[rand() % num_conscious_players];
+          Assert(idx >= 0);
+          pParty->pPlayers[idx].PlaySound(SPEECH_99, 0);
+        }
+
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[524], 2);// "Once again you've cheated death!.." "Вы снова обхитрили смерть! …"
+        uGameState = GAME_STATE_PLAYING;
       }
-      //pHealth = &pParty->pPlayers[0].sHealth;//193C
-      //do
-	  for(int i=0; i<4; ++i)
-      {
-        memset(pParty->pPlayers[i].pConditions.data(), 0, 0xA0u);//(pConditions, 0, 160)
-        memset(pParty->pPlayers[i].pPlayerBuffs.data(), 0, 0x180u);//(pPlayerBuffs[0], 0, 384)
-        //*pHealth = 1;
-		pParty->pPlayers[i].sHealth=1;
-        //pHealth += 1743; //6CF
-        uActiveCharacter = 1;
-      }
-    //  while ( (signed int)pHealth < (signed int)&pParty->field_871C[567] );
-      if (_449B57_test_bit(pParty->_quest_bits, PARTY_QUEST_FINISHED_EMERALD_ISLE))
-      {
-        pParty->vPosition.x = -17331;            // respawn in harmondale
-        pParty->vPosition.y = 12547;
-        pParty->vPosition.z = 465;
-        pParty->sRotationY = 0;
-        pLocationName = "out02.odm";
-      }
-      else
-      {
-        pParty->vPosition.x = 12552;             // respawn on emerald isle
-        pParty->vPosition.y = 1816;
-        pParty->vPosition.z = 0;
-        pParty->sRotationY = 512;
-        pLocationName = "out01.odm";
-      }
-      strcpy(Source, pLocationName);
-      pParty->uFallStartY = pParty->vPosition.z;
-      pParty->sRotationX = 0;
-      pParty->uFallSpeed = 0;
-      pParty->field_6E4 = 0;
-      pParty->field_6E0 = 0;
-      if ( _stricmp(Source, pCurrentMapName) )
-      {
-        strcpy(pCurrentMapName, Source);
-        _5B65A8_npcdata_uflags_or_other = pParty->vPosition.x;
-        _5B65AC_npcdata_fame_or_other = pParty->vPosition.y;
-        _5B65B0_npcdata_rep_or_other = pParty->vPosition.z;
-        _5B65B4_npcdata_loword_house_or_other = pParty->sRotationY;
-        _5B65B8_npcdata_hiword_house_or_other = pParty->sRotationX;
-        dword_5B65C0 = 1;
-        PrepareWorld(1);
-      }
-      InitializeActors();
-
-
-      int num_conscious_players = 0;
-      int conscious_players_ids[4] = {-1, -1, -1, -1};
-      for (int v11 = 0; v11 < 4; ++v11)
-      {
-        if (pPlayers[v11 + 1]->CanAct())
-          conscious_players_ids[num_conscious_players++] = v11;
-      }
-      if (num_conscious_players)
-      {
-        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_PLAYING;
     }
     while (!game_finished);
 
@@ -2430,7 +2392,7 @@
                     case SCREEN_HOUSE:
                       if ( uDialogueType )
                         uDialogueType = 0;
-                      if ( uGameState == GAME_STATE_2 )
+                      if ( uGameState == GAME_STATE_CHANGE_LOCATION )
                       {
                         while ( HouseDialogPressCloseBtn() )
                           ;
@@ -2733,7 +2695,7 @@
           PlayHouseSound(uCurrentHouse_Animation, HouseSound_NotEnoughMoney_TrainingSuccessful);
           pVideoPlayer->Unload();
           DialogueEnding();
-          viewparams->bRedrawGameUI = 1;
+          viewparams->bRedrawGameUI = true;
           if ( dword_59117C_teleportx | dword_591178_teleporty | dword_591174_teleportz | dword_591170_teleport_directiony | dword_59116C_teleport_directionx | dword_591168_teleport_speedz )
           {
             if ( dword_59117C_teleportx )
@@ -2766,9 +2728,7 @@
               dword_5B65BC = dword_591168_teleport_speedz;
             }
             else
-            {
               v38 = dword_5B65BC;
-            }
             if ( *dword_591164_teleport_map_name != 48 )
             {
               pGameLoadingUI_ProgressBar->uType = (GUIProgressBar::Type)2;
@@ -2778,9 +2738,7 @@
             }
           }
           else
-          {
             EventProcessor(dword_5C3418, 0, 1, dword_5C341C);
-          }
           if ( !_stricmp(byte_6BE3B0.data(), "d05.blv") )
             pParty->uTimePlayed += 1474560i64;
           continue;
@@ -3047,7 +3005,7 @@
           SaveGame(1, 0);
           strcpy(pCurrentMapName, pMapStats->pInfos[uHouse_ExitPic].pFilename);
           dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
-          uGameState = GAME_STATE_2;
+          uGameState = GAME_STATE_CHANGE_LOCATION;
           //v53 = p2DEvents_minus1_::30[26 * (unsigned int)ptr_507BC0->ptr_1C];
           v53 = p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1]._quest_related;
           if ( v53 < 0 )
@@ -3155,7 +3113,7 @@
               OnMapLeave();
               strcpy(pCurrentMapName, (const char *)&pGames_LOD->pSubIndices[pPlayer9->pInstalledBeacons[uMessageParam].SaveFileID]);
               dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
-              uGameState = GAME_STATE_2;
+              uGameState = GAME_STATE_CHANGE_LOCATION;
               _5B65A8_npcdata_uflags_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_X;
               _5B65AC_npcdata_fame_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Y;
               _5B65B0_npcdata_rep_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Z;
@@ -3236,7 +3194,7 @@
                     SaveGame(1, 0);
                     OnMapLeave();
                     dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
-                    uGameState = GAME_STATE_2;
+                    uGameState = GAME_STATE_CHANGE_LOCATION;
                     strcpy(pCurrentMapName, pMapStats->pInfos[TownPortalList[uMessageParam].uMapInfoID].pFilename);
                     dword_5B65C0 = 1;
                     _5B65A8_npcdata_uflags_or_other = TownPortalList[uMessageParam].pos.x;
@@ -3419,7 +3377,7 @@
               {
                 strcpy(pCurrentMapName, (const char *)&pGames_LOD->pSubIndices[(int)pNPCData3]);
                 dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
-                uGameState = GAME_STATE_2;
+                uGameState = GAME_STATE_CHANGE_LOCATION;
                 OnMapLeave();
                 continue;
               }
--- a/Game.h	Thu Dec 26 00:19:49 2013 +0600
+++ b/Game.h	Fri Dec 27 01:28:48 2013 +0600
@@ -16,7 +16,7 @@
 {
   GAME_STATE_PLAYING = 0,
   GAME_FINISHED = 1,
-  GAME_STATE_2 = 2,
+  GAME_STATE_CHANGE_LOCATION = 2,
   GAME_STATE_LOADING_GAME = 3,
   GAME_STATE_NEWGAME_OUT_GAMEMENU = 4,
   GAME_STATE_5 = 5,
--- a/SaveLoad.cpp	Thu Dec 26 00:19:49 2013 +0600
+++ b/SaveLoad.cpp	Fri Dec 27 01:28:48 2013 +0600
@@ -379,7 +379,7 @@
       }
 	}
   }
-  if ( !NotSaveWorld )
+  if ( !NotSaveWorld )//autosave for change location
   {
     //__debugbreak();
     CompactLayingItemsList();
--- a/SpriteObject.cpp	Thu Dec 26 00:19:49 2013 +0600
+++ b/SpriteObject.cpp	Fri Dec 27 01:28:48 2013 +0600
@@ -917,10 +917,17 @@
 {
   int new_obj_pos = 0;
 
-  for (int i=0; i < MAX_SPRITE_OBJECTS; ++i)
+  for ( int i = 0; i < MAX_SPRITE_OBJECTS; ++i )
   {
-    if (pSpriteObjects[i].uObjectDescID)
-      memcpy(&pSpriteObjects[new_obj_pos++], &pSpriteObjects[i],sizeof(SpriteObject));
+    if ( pSpriteObjects[i].uObjectDescID )
+    {
+      if ( i != new_obj_pos )// 
+      {
+        memcpy(&pSpriteObjects[new_obj_pos], &pSpriteObjects[i],sizeof(SpriteObject));
+        pSpriteObjects[i].uObjectDescID = 0;
+      }
+      new_obj_pos++;
+    }
   }
   uNumSpriteObjects = new_obj_pos;
 }
--- a/UI/UIHouses.cpp	Thu Dec 26 00:19:49 2013 +0600
+++ b/UI/UIHouses.cpp	Fri Dec 27 01:28:48 2013 +0600
@@ -1548,7 +1548,7 @@
           _5B65B8_npcdata_hiword_house_or_other = 0;
           dword_5B65BC = 0;
           _5B65B4_npcdata_loword_house_or_other = pTravel->arrival_rot_y;
-          uGameState = GAME_STATE_2;
+          uGameState = GAME_STATE_CHANGE_LOCATION;
           _5B65A8_npcdata_uflags_or_other = pTravel->arrival_x;
           _5B65AC_npcdata_fame_or_other = pTravel->arrival_y;
           _5B65B0_npcdata_rep_or_other = pTravel->arrival_z;
--- a/mm7_3.cpp	Thu Dec 26 00:19:49 2013 +0600
+++ b/mm7_3.cpp	Fri Dec 27 01:28:48 2013 +0600
@@ -4309,7 +4309,7 @@
   if ( _stricmp(pCurrentMapName, pMapName) )
     SaveGame(1, 0);
 
-  uGameState = GAME_STATE_2;
+  uGameState = GAME_STATE_CHANGE_LOCATION;
   strcpy(pCurrentMapName, pMapName);
   uLevel_StartingPointType = start_point;
 }