moved (and renamed) global variables to game structure (ExitX/ExitY)
authorHolger Schemel <info@artsoft.org>
Wed, 14 Nov 2018 19:59:13 +0000 (20:59 +0100)
committerHolger Schemel <info@artsoft.org>
Wed, 14 Nov 2018 20:10:20 +0000 (21:10 +0100)
src/game.c
src/game.h
src/game_mm/mm_main.h
src/main.c
src/main.h

index c8c5de4..c1846d6 100644 (file)
@@ -3544,7 +3544,6 @@ void InitGame(void)
     SendToServer_MovePlayer(MV_NONE);
 
   ZX = ZY = -1;
-  ExitX = ExitY = -1;
 
   FrameCounter = 0;
   TimeFrames = 0;
@@ -3558,6 +3557,9 @@ void InitGame(void)
 
   ScrollStepSize = 0;  // will be correctly initialized by ScrollScreen()
 
+  game.exit_x = -1;
+  game.exit_y = -1;
+
   game.all_players_gone = FALSE;
 
   game.LevelSolved = FALSE;
@@ -4570,30 +4572,35 @@ void GameWon(void)
 
     if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
     {
-      if (ExitX >= 0 && ExitY >= 0)    // local player has left the level
+      // check if last player has left the level
+      if (game.exit_x >= 0 &&
+         game.exit_y >= 0)
       {
+       int x = game.exit_x;
+       int y = game.exit_y;
+       int element = Feld[x][y];
+
        // close exit door after last player
        if ((game.all_players_gone &&
-            (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
-             Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN ||
-             Feld[ExitX][ExitY] == EL_STEEL_EXIT_OPEN)) ||
-           Feld[ExitX][ExitY] == EL_EM_EXIT_OPEN ||
-           Feld[ExitX][ExitY] == EL_EM_STEEL_EXIT_OPEN)
+            (element == EL_EXIT_OPEN ||
+             element == EL_SP_EXIT_OPEN ||
+             element == EL_STEEL_EXIT_OPEN)) ||
+           element == EL_EM_EXIT_OPEN ||
+           element == EL_EM_STEEL_EXIT_OPEN)
        {
-         int element = Feld[ExitX][ExitY];
 
-         Feld[ExitX][ExitY] =
+         Feld[x][y] =
            (element == EL_EXIT_OPEN            ? EL_EXIT_CLOSING :
             element == EL_EM_EXIT_OPEN         ? EL_EM_EXIT_CLOSING :
             element == EL_SP_EXIT_OPEN         ? EL_SP_EXIT_CLOSING:
             element == EL_STEEL_EXIT_OPEN      ? EL_STEEL_EXIT_CLOSING:
             EL_EM_STEEL_EXIT_CLOSING);
 
-         PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
+         PlayLevelSoundElementAction(x, y, element, ACTION_CLOSING);
        }
 
        // player disappears
-       DrawLevelField(ExitX, ExitY);
+       DrawLevelField(x, y);
       }
 
       for (i = 0; i < MAX_PLAYERS; i++)
@@ -6815,8 +6822,8 @@ static void TurnRoundExt(int x, int y)
 
     if (game.all_players_gone)
     {
-      attr_x = ExitX;
-      attr_y = ExitY;
+      attr_x = game.exit_x;
+      attr_y = game.exit_y;
     }
     else
     {
@@ -7184,8 +7191,8 @@ static void TurnRoundExt(int x, int y)
 
     if (game.all_players_gone)
     {
-      attr_x = ExitX;
-      attr_y = ExitY;
+      attr_x = game.exit_x;
+      attr_y = game.exit_y;
     }
     else
     {
@@ -13441,8 +13448,8 @@ void RemovePlayer(struct PlayerInfo *player)
     game.GameOver = TRUE;
   }
 
-  ExitX = ZX = jx;
-  ExitY = ZY = jy;
+  game.exit_x = ZX = jx;
+  game.exit_y = ZY = jy;
 }
 
 void ExitPlayer(struct PlayerInfo *player)
@@ -15236,8 +15243,6 @@ static ListNode *SaveEngineSnapshotBuffers(void)
 
   SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ZX));
   SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ZY));
-  SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ExitX));
-  SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ExitY));
 
   SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(FrameCounter));
   SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(TimeFrames));
index aed0ce0..bba270c 100644 (file)
@@ -204,6 +204,8 @@ struct GameInfo
   int players_still_needed;
   int friends_still_needed;
 
+  int exit_x, exit_y;
+
   boolean all_players_gone;
 
   // values for the new EMC elements
index d8c8c42..9482566 100644 (file)
@@ -234,7 +234,7 @@ extern int          FfwdFrameDelay;
 extern int             BX1, BY1, BX2, BY2;
 extern int             SBX_Left, SBX_Right;
 extern int             SBY_Upper, SBY_Lower;
-extern int             ZX, ZY, ExitX, ExitY;
+extern int             ZX, ZY;
 extern int             TimeFrames, TimePlayed, TimeLeft;
 extern boolean         SiebAktiv;
 extern int             SiebCount;
index 1d3a805..1805b6e 100644 (file)
@@ -127,7 +127,6 @@ int                 BX2, BY2;
 int                    SBX_Left, SBX_Right;
 int                    SBY_Upper, SBY_Lower;
 int                    ZX, ZY;
-int                    ExitX, ExitY;
 
 int                    TimeFrames, TimePlayed, TimeLeft, TapeTime;
 
index f4a738b..45d4696 100644 (file)
@@ -3629,7 +3629,6 @@ extern int                        BX2, BY2;
 extern int                     SBX_Left, SBX_Right;
 extern int                     SBY_Upper, SBY_Lower;
 extern int                     ZX, ZY;
-extern int                     ExitX, ExitY;
 
 extern int                     TimeFrames, TimePlayed, TimeLeft, TapeTime;