fixed ignoring clicks on global animations after executing event actions
[rocksndiamonds.git] / src / game.c
index 2f57bf51cc7f32a6aee74dc3e04f5c3c5dd10fb3..96fa321fb09a10f26898014f98dfd79846f3a7fa 100644 (file)
@@ -1731,7 +1731,7 @@ static void InitPlayerField(int x, int y, int element, boolean init_game)
     if (game.use_block_last_field_bug)
       player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
 
-    if (!options.network || player->connected)
+    if (!options.network || player->connected_network)
     {
       player->active = TRUE;
 
@@ -3545,18 +3545,6 @@ void InitGame()
 
   game.envelope_active = FALSE;
 
-  /* set focus to local player for network games, else to all players */
-  game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
-  game.centered_player_nr_next = game.centered_player_nr;
-  game.set_centered_player = FALSE;
-
-  if (network_playing && tape.recording)
-  {
-    /* store client dependent player focus when recording network games */
-    tape.centered_player_nr_next = game.centered_player_nr_next;
-    tape.set_centered_player = TRUE;
-  }
-
   for (i = 0; i < NUM_BELTS; i++)
   {
     game.belt_dir[i] = MV_NONE;
@@ -3570,6 +3558,24 @@ void InitGame()
   if (options.debug)
   {
     printf("Player status at level initialization:\n");
+
+    for (i = 0; i < MAX_PLAYERS; i++)
+    {
+      struct PlayerInfo *player = &stored_player[i];
+
+      printf("- player %d: present == %d, connected == %d [%d/%d], active == %d",
+            i + 1,
+            player->present,
+            player->connected,
+            player->connected_locally,
+            player->connected_network,
+            player->active);
+
+      if (local_player == player)
+       printf(" (local player)");
+
+      printf("\n");
+    }
   }
 #endif
 
@@ -3684,22 +3690,33 @@ void InitGame()
       game.belt_dir_nr[i] = 3;         /* not moving, next moving left */
 
 #if USE_NEW_PLAYER_ASSIGNMENTS
-  /* !!! SAME AS init.c:InitPlayerInfo() -- FIX THIS !!! */
-  /* choose default local player */
-  local_player = &stored_player[0];
-
   for (i = 0; i < MAX_PLAYERS; i++)
+  {
     stored_player[i].connected = FALSE;
 
-  local_player->connected = TRUE;
-  /* !!! SAME AS init.c:InitPlayerInfo() -- FIX THIS !!! */
+    /* in network game mode, the local player might not be the first player */
+    if (stored_player[i].connected_locally)
+      local_player = &stored_player[i];
+  }
+
+  if (!options.network)
+    local_player->connected = TRUE;
 
   if (tape.playing)
   {
     for (i = 0; i < MAX_PLAYERS; i++)
       stored_player[i].connected = tape.player_participates[i];
   }
-  else if (game.team_mode && !options.network)
+  else if (options.network)
+  {
+    /* add team mode players connected over the network (needed for correct
+       assignment of player figures from level to locally playing players) */
+
+    for (i = 0; i < MAX_PLAYERS; i++)
+      if (stored_player[i].connected_network)
+       stored_player[i].connected = TRUE;
+  }
+  else if (game.team_mode)
   {
     /* try to guess locally connected team mode players (needed for correct
        assignment of player figures from level to locally playing players) */
@@ -3719,10 +3736,12 @@ void InitGame()
     {
       struct PlayerInfo *player = &stored_player[i];
 
-      printf("- player %d: present == %d, connected == %d, active == %d",
+      printf("- player %d: present == %d, connected == %d [%d/%d], active == %d",
             i + 1,
             player->present,
             player->connected,
+            player->connected_locally,
+            player->connected_network,
             player->active);
 
       if (local_player == player)
@@ -3825,10 +3844,12 @@ void InitGame()
     {
       struct PlayerInfo *player = &stored_player[i];
 
-      printf("- player %d: present == %d, connected == %d, active == %d",
+      printf("- player %d: present == %d, connected == %d [%d/%d], active == %d",
             i + 1,
             player->present,
             player->connected,
+            player->connected_locally,
+            player->connected_network,
             player->active);
 
       if (local_player == player)
@@ -3884,6 +3905,18 @@ void InitGame()
   printf("::: local_player->present == %d\n", local_player->present);
 #endif
 
+  /* set focus to local player for network games, else to all players */
+  game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
+  game.centered_player_nr_next = game.centered_player_nr;
+  game.set_centered_player = FALSE;
+
+  if (network_playing && tape.recording)
+  {
+    /* store client dependent player focus when recording network games */
+    tape.centered_player_nr_next = game.centered_player_nr_next;
+    tape.set_centered_player = TRUE;
+  }
+
   if (tape.playing)
   {
     /* when playing a tape, eliminate all players who do not participate */
@@ -3978,10 +4011,12 @@ void InitGame()
     {
       struct PlayerInfo *player = &stored_player[i];
 
-      printf("- player %d: present == %d, connected == %d, active == %d",
+      printf("- player %d: present == %d, connected == %d [%d/%d], active == %d",
             i + 1,
             player->present,
             player->connected,
+            player->connected_locally,
+            player->connected_network,
             player->active);
 
       if (local_player == player)
@@ -4186,11 +4221,6 @@ void InitGame()
 
     OpenDoor(DOOR_OPEN_ALL);
 
-    PlaySound(SND_GAME_STARTING);
-
-    if (setup.sound_music)
-      PlayLevelMusic();
-
     KeyboardAutoRepeatOffUnlessAutoplay();
 
 #if DEBUG_INIT_PLAYER
@@ -4202,10 +4232,12 @@ void InitGame()
       {
        struct PlayerInfo *player = &stored_player[i];
 
-       printf("- player %d: present == %d, connected == %d, active == %d",
+       printf("- player %d: present == %d, connected == %d [%d/%d], active == %d",
               i + 1,
               player->present,
               player->connected,
+              player->connected_locally,
+              player->connected_network,
               player->active);
 
        if (local_player == player)
@@ -4236,6 +4268,14 @@ void InitGame()
     InitGameActions_MM();
 
   SaveEngineSnapshotToListInitial();
+
+  if (!game.restart_level)
+  {
+    PlaySound(SND_GAME_STARTING);
+
+    if (setup.sound_music)
+      PlayLevelMusic();
+  }
 }
 
 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y,
@@ -15430,7 +15470,8 @@ void CreateGameButtons()
 
   for (i = 0; i < NUM_GAME_BUTTONS; i++)
   {
-    struct GraphicInfo *gfx = &graphic_info[gamebutton_info[i].graphic];
+    int graphic = gamebutton_info[i].graphic;
+    struct GraphicInfo *gfx = &graphic_info[graphic];
     struct XY *pos = gamebutton_info[i].pos;
     struct GadgetInfo *gi;
     int button_type;
@@ -15484,6 +15525,7 @@ void CreateGameButtons()
     }
 
     gi = CreateGadget(GDI_CUSTOM_ID, id,
+                     GDI_IMAGE_ID, graphic,
                      GDI_INFO_TEXT, gamebutton_info[i].infotext,
                      GDI_X, base_x + GDI_ACTIVE_POS(pos->x),
                      GDI_Y, base_y + GDI_ACTIVE_POS(pos->y),