fixed selecting correct player in single player mode (after network gaming)
authorHolger Schemel <info@artsoft.org>
Sun, 17 Jun 2018 09:23:55 +0000 (11:23 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 18 Jun 2018 17:47:32 +0000 (19:47 +0200)
When playing levels that contain more than one player in single player
mode, selecting the actual player when starting the level worked
correctly before only if the game was always played in single player
mode since it was started. It did not work correctly in the following
special case: There was a network multi-player game played before, but
the other (remote) client has disconnected (quit the game), leaving the
other client with a local player that might not be the first player.

In this case, using the first active player (which could be the first
player in the level) for the local player (which could be the second
player, because the network client was started after the now
disconnected client) would result in a broken player mapping, so the
player in the game cannot be moved.

This bugfix solves the problem by not using the first active player,
but the local player.

src/game.c

index 13634a2c76122ab7b2a37f0482a5c123b1ecb90a..d37dee3a5f7c162ce69acdf33167a2d3b64f2233 100644 (file)
@@ -3962,26 +3962,21 @@ void InitGame()
   }
   else if (!network.enabled && !game.team_mode)                /* && !tape.playing */
   {
-    /* when in single player mode, eliminate all but the first active player */
+    /* when in single player mode, eliminate all but the local player */
 
     for (i = 0; i < MAX_PLAYERS; i++)
     {
-      if (stored_player[i].active)
+      struct PlayerInfo *player = &stored_player[i];
+
+      if (player->active && player != local_player)
       {
-       for (j = i + 1; j < MAX_PLAYERS; j++)
-       {
-         if (stored_player[j].active)
-         {
-           struct PlayerInfo *player = &stored_player[j];
-           int jx = player->jx, jy = player->jy;
+       int jx = player->jx, jy = player->jy;
 
-           player->active = FALSE;
-           player->present = FALSE;
+       player->active = FALSE;
+       player->present = FALSE;
 
-           StorePlayer[jx][jy] = 0;
-           Feld[jx][jy] = EL_EMPTY;
-         }
-       }
+       StorePlayer[jx][jy] = 0;
+       Feld[jx][jy] = EL_EMPTY;
       }
     }
   }