+#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 !!! */
+
+#if 0
+ printf("::: TEAM MODE: %d\n", game.team_mode);
+#endif
+
+ if (tape.playing)
+ {
+#if 1
+ for (i = 0; i < MAX_PLAYERS; i++)
+ stored_player[i].connected = tape.player_participates[i];
+#else
+ /* try to guess locally connected team mode players (needed for correct
+ assignment of player figures from level to locally playing players) */
+
+ for (i = 0; i < MAX_PLAYERS; i++)
+ if (tape.player_participates[i])
+ stored_player[i].connected = TRUE;
+#endif
+ }
+ else if (game.team_mode && !options.network)
+ {
+ /* try to guess locally connected team mode players (needed for correct
+ assignment of player figures from level to locally playing players) */
+
+ for (i = 0; i < MAX_PLAYERS; i++)
+ if (setup.input[i].use_joystick ||
+ setup.input[i].key.left != KSYM_UNDEFINED)
+ stored_player[i].connected = TRUE;
+ }
+
+#if DEBUG_INIT_PLAYER
+ if (options.debug)
+ {
+ printf("Player status after level initialization:\n");
+
+ for (i = 0; i < MAX_PLAYERS; i++)
+ {
+ struct PlayerInfo *player = &stored_player[i];
+
+ printf("- player %d: present == %d, connected == %d, active == %d",
+ i + 1,
+ player->present,
+ player->connected,
+ player->active);
+
+ if (local_player == player)
+ printf(" (local player)");
+
+ printf("\n");
+ }
+ }
+#endif
+
+#if DEBUG_INIT_PLAYER
+ if (options.debug)
+ printf("Reassigning players ...\n");
+#endif
+
+ /* check if any connected player was not found in playfield */
+ for (i = 0; i < MAX_PLAYERS; i++)
+ {
+ struct PlayerInfo *player = &stored_player[i];
+
+ if (player->connected && !player->present)
+ {
+ struct PlayerInfo *field_player = NULL;
+
+#if DEBUG_INIT_PLAYER
+ if (options.debug)
+ printf("- looking for field player for player %d ...\n", i + 1);
+#endif
+
+ /* assign first free player found that is present in the playfield */
+
+#if 1
+ /* first try: look for unmapped playfield player that is not connected */
+ for (j = 0; j < MAX_PLAYERS; j++)
+ if (field_player == NULL &&
+ stored_player[j].present &&
+ !stored_player[j].mapped &&
+ !stored_player[j].connected)
+ field_player = &stored_player[j];
+
+ /* second try: look for *any* unmapped playfield player */
+ for (j = 0; j < MAX_PLAYERS; j++)
+ if (field_player == NULL &&
+ stored_player[j].present &&
+ !stored_player[j].mapped)
+ field_player = &stored_player[j];
+#else
+ /* first try: look for unmapped playfield player that is not connected */
+ if (field_player == NULL)
+ for (j = 0; j < MAX_PLAYERS; j++)
+ if (stored_player[j].present &&
+ !stored_player[j].mapped &&
+ !stored_player[j].connected)
+ field_player = &stored_player[j];
+
+ /* second try: look for *any* unmapped playfield player */
+ if (field_player == NULL)
+ for (j = 0; j < MAX_PLAYERS; j++)
+ if (stored_player[j].present &&
+ !stored_player[j].mapped)
+ field_player = &stored_player[j];
+#endif
+
+ if (field_player != NULL)
+ {
+ int jx = field_player->jx, jy = field_player->jy;
+
+#if DEBUG_INIT_PLAYER
+ if (options.debug)
+ printf("- found player %d\n", field_player->index_nr + 1);
+#endif
+
+ player->present = FALSE;
+ player->active = FALSE;
+
+ field_player->present = TRUE;
+ field_player->active = TRUE;
+
+ /*
+ player->initial_element = field_player->initial_element;
+ player->artwork_element = field_player->artwork_element;
+
+ player->block_last_field = field_player->block_last_field;
+ player->block_delay_adjustment = field_player->block_delay_adjustment;
+ */
+
+ StorePlayer[jx][jy] = field_player->element_nr;
+
+ field_player->jx = field_player->last_jx = jx;
+ field_player->jy = field_player->last_jy = jy;
+
+ if (local_player == player)
+ local_player = field_player;
+
+ map_player_action[field_player->index_nr] = i;
+
+ field_player->mapped = TRUE;
+
+#if DEBUG_INIT_PLAYER
+ if (options.debug)
+ printf("- map_player_action[%d] == %d\n",
+ field_player->index_nr + 1, i + 1);
+#endif
+ }
+ }
+
+ if (player->connected && player->present)
+ player->mapped = TRUE;
+ }
+
+#if DEBUG_INIT_PLAYER
+ if (options.debug)
+ {
+ printf("Player status after player assignment (first stage):\n");
+
+ for (i = 0; i < MAX_PLAYERS; i++)
+ {
+ struct PlayerInfo *player = &stored_player[i];
+
+ printf("- player %d: present == %d, connected == %d, active == %d",
+ i + 1,
+ player->present,
+ player->connected,
+ player->active);
+
+ if (local_player == player)
+ printf(" (local player)");
+
+ printf("\n");
+ }
+ }
+#endif
+
+#else
+