void Bang(int, int);
void InitMovDir(int, int);
void InitAmoebaNr(int, int);
-int NewHiScore(void);
+int NewHiScore(int);
void TestIfGoodThingHitsBadThing(int, int, int);
void TestIfBadThingHitsGoodThing(int, int, int);
void KillPlayer(struct PlayerInfo *);
void BuryPlayer(struct PlayerInfo *);
void RemovePlayer(struct PlayerInfo *);
+void ExitPlayer(struct PlayerInfo *);
static int getInvisibleActiveFromInvisibleElement(int);
static int getInvisibleFromInvisibleActiveElement(int);
/* update game panel control values */
- game_panel_controls[GAME_PANEL_LEVEL_NUMBER].value = level_nr;
+ /* use "level.file_info.nr" instead of "level_nr" (for network games) */
+ game_panel_controls[GAME_PANEL_LEVEL_NUMBER].value = level.file_info.nr;
game_panel_controls[GAME_PANEL_GEMS].value = gems;
game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value = 0;
=============================================================================
*/
+#if DEBUG_INIT_PLAYER
+static void DebugPrintPlayerStatus(char *message)
+{
+ int i;
+
+ if (!options.debug)
+ return;
+
+ printf("%s:\n", message);
+
+ 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
+
void InitGame()
{
int full_lev_fieldx = lev_fieldx + (BorderElement != EL_EMPTY ? 2 : 0);
player->gems_still_needed = level.gems_needed;
player->sokobanfields_still_needed = 0;
player->lights_still_needed = 0;
+ player->players_still_needed = 0;
player->friends_still_needed = 0;
for (j = 0; j < MAX_NUM_KEYS; j++)
AmoebaCnt[i] = AmoebaCnt2[i] = 0;
#if DEBUG_INIT_PLAYER
- 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");
- }
- }
+ DebugPrintPlayerStatus("Player status at level initialization");
#endif
SCAN_PLAYFIELD(x, y)
}
#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 [%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");
- }
- }
+ DebugPrintPlayerStatus("Player status after level initialization");
#endif
#if DEBUG_INIT_PLAYER
}
#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 [%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");
- }
- }
+ DebugPrintPlayerStatus("Player status after player assignment (first stage)");
#endif
#else
}
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;
}
}
}
+ for (i = 0; i < MAX_PLAYERS; i++)
+ if (stored_player[i].active)
+ local_player->players_still_needed++;
+
/* when recording the game, store which players take part in the game */
if (tape.recording)
{
}
#if DEBUG_INIT_PLAYER
- if (options.debug)
- {
- printf("Player status after player assignment (final stage):\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");
- }
- }
+ DebugPrintPlayerStatus("Player status after player assignment (final stage)");
#endif
if (BorderElement == EL_EMPTY)
KeyboardAutoRepeatOffUnlessAutoplay();
#if DEBUG_INIT_PLAYER
- if (options.debug)
- {
- printf("Player status (final):\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");
- }
- }
+ DebugPrintPlayerStatus("Player status (final)");
#endif
}
static void PlayerWins(struct PlayerInfo *player)
{
+ if (level.game_engine_type == GAME_ENGINE_TYPE_RND &&
+ local_player->players_still_needed > 0)
+ return;
+
player->LevelSolved = TRUE;
player->GameOver = TRUE;
void GameEnd()
{
int hi_pos;
- boolean raise_level = FALSE;
+ int last_level_nr = level_nr;
local_player->LevelSolved_GameEnd = TRUE;
if (setup.increment_levels &&
level_nr < leveldir_current->last_level)
- raise_level = TRUE; /* advance to next level */
-
- if ((hi_pos = NewHiScore()) >= 0)
{
- SetGameStatus(GAME_MODE_SCORES);
-
- DrawHallOfFame(hi_pos);
+ level_nr++; /* advance to next level */
+ TapeErase(); /* start with empty tape */
- if (raise_level)
+ if (setup.auto_play_next_level)
{
- level_nr++;
- TapeErase();
+ LoadLevel(level_nr);
+
+ SaveLevelSetup_SeriesInfo();
}
}
+
+ hi_pos = NewHiScore(last_level_nr);
+
+ if (hi_pos >= 0 && !setup.skip_scores_after_game)
+ {
+ SetGameStatus(GAME_MODE_SCORES);
+
+ DrawHallOfFame(last_level_nr, hi_pos);
+ }
+ else if (setup.auto_play_next_level && setup.increment_levels &&
+ !network_playing)
+ {
+ StartGameActions(network.enabled, setup.autorecord, level.random_seed);
+ }
else
{
SetGameStatus(GAME_MODE_MAIN);
- if (raise_level)
- {
- level_nr++;
- TapeErase();
- }
-
DrawMainMenu();
}
}
-int NewHiScore()
+int NewHiScore(int level_nr)
{
int k, l;
int position = -1;
{
for (i = 0; i < MAX_PLAYERS; i++)
if (action_arg_player_bits & (1 << i))
- PlayerWins(&stored_player[i]);
+ ExitPlayer(&stored_player[i]);
+
+ if (AllPlayersGone)
+ PlayerWins(local_player);
break;
}
if (init_network_game)
{
+ SendToServer_LevelFile();
SendToServer_StartPlaying();
return;
Feld[jx][jy] == EL_SP_EXIT_OPEN ||
Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
{
- DrawPlayer(player); /* needed here only to cleanup last field */
- RemovePlayer(player);
+ ExitPlayer(player);
- if (local_player->friends_still_needed == 0 ||
- IS_SP_ELEMENT(Feld[jx][jy]))
- PlayerWins(player);
+ if ((local_player->friends_still_needed == 0 ||
+ IS_SP_ELEMENT(Feld[jx][jy])) &&
+ AllPlayersGone)
+ PlayerWins(local_player);
}
/* this breaks one level: "machine", level 000 */
ExitY = ZY = jy;
}
+void ExitPlayer(struct PlayerInfo *player)
+{
+ DrawPlayer(player); /* needed here only to cleanup last field */
+ RemovePlayer(player);
+
+ local_player->players_still_needed--;
+}
+
static void setFieldForSnapping(int x, int y, int element, int direction)
{
struct ElementInfo *ei = &element_info[element];
if (local_player->sokobanfields_still_needed == 0 &&
(game.emulation == EMU_SOKOBAN || level.auto_exit_sokoban))
{
+ local_player->players_still_needed = 0;
+
PlayerWins(player);
PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);