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);
if (game.use_block_last_field_bug)
player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
- if (!options.network || player->connected_network)
+ if (!network.enabled || player->connected_network)
{
player->active = TRUE;
/* 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);
InitGameControlValues();
/* don't play tapes over network */
- network_playing = (options.network && !tape.playing);
+ network_playing = (network.enabled && !tape.playing);
for (i = 0; i < MAX_PLAYERS; i++)
{
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++)
network_player_action_received = FALSE;
-#if defined(NETWORK_AVALIABLE)
/* initial null action */
if (network_playing)
SendToServer_MovePlayer(MV_NONE);
-#endif
ZX = ZY = -1;
ExitX = ExitY = -1;
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)
local_player = &stored_player[i];
}
- if (!options.network)
+ if (!network.enabled)
local_player->connected = TRUE;
if (tape.playing)
for (i = 0; i < MAX_PLAYERS; i++)
stored_player[i].connected = tape.player_participates[i];
}
- else if (options.network)
+ else if (network.enabled)
{
/* add team mode players connected over the network (needed for correct
assignment of player figures from level to locally playing players) */
}
#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
}
#endif
}
- else if (!options.network && !game.team_mode) /* && !tape.playing */
+ 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);
+ level_nr++; /* advance to next level */
+ TapeErase(); /* start with empty tape */
- DrawHallOfFame(hi_pos);
-
- 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 (record_tape)
TapeStartRecording(new_random_seed);
-#if defined(NETWORK_AVALIABLE)
if (init_network_game)
{
+ SendToServer_LevelFile();
SendToServer_StartPlaying();
return;
}
-#endif
InitGame();
}
}
if (game.restart_level)
- StartGameActions(options.network, setup.autorecord, level.random_seed);
+ StartGameActions(network.enabled, setup.autorecord, level.random_seed);
/* !!! SAME CODE AS IN "CheckLevelTime()" -- FIX THIS !!! */
if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
{
/* try to get network player actions in time */
-#if defined(NETWORK_AVALIABLE)
/* last chance to get network player actions without main loop delay */
HandleNetworking();
-#endif
/* game was quit by network peer */
if (game_status != GAME_MODE_PLAYING)
stored_player[i].effective_action = stored_player[i].action;
}
-#if defined(NETWORK_AVALIABLE)
if (network_playing)
SendToServer_MovePlayer(summarized_player_action);
-#endif
// summarize all actions at local players mapped input device position
// (this allows using different input devices in single player mode)
- if (!options.network && !game.team_mode)
+ if (!network.enabled && !game.team_mode)
stored_player[map_player_action[local_player->index_nr]].effective_action =
summarized_player_action;
}
}
- if (!options.network && game.centered_player_nr == -1 &&
+ if (!network.enabled && game.centered_player_nr == -1 &&
!AllPlayersInSight(player, new_jx, new_jy))
return MP_NO_ACTION;
if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
{
- if (!options.network && game.centered_player_nr == -1 &&
+ if (!network.enabled && game.centered_player_nr == -1 &&
!AllPlayersInVisibleScreen())
{
scroll_x = old_scroll_x;
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);
if (!skip_request)
CloseDoor(DOOR_CLOSE_1);
-#if defined(NETWORK_AVALIABLE)
- if (options.network)
+ if (network.enabled)
SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
else
-#endif
{
if (quick_quit)
FadeSkipNextFadeIn();
if (Request(message, REQ_ASK | REQ_STAY_CLOSED))
{
- StartGameActions(options.network, setup.autorecord, level.random_seed);
+ StartGameActions(network.enabled, setup.autorecord, level.random_seed);
}
else
{
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;
}
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),
case GAME_CTRL_ID_PAUSE:
case GAME_CTRL_ID_PAUSE2:
case GAME_CTRL_ID_PANEL_PAUSE:
- if (options.network && game_status == GAME_MODE_PLAYING)
+ if (network.enabled && game_status == GAME_MODE_PLAYING)
{
-#if defined(NETWORK_AVALIABLE)
if (tape.pausing)
SendToServer_ContinuePlaying();
else
SendToServer_PausePlaying();
-#endif
}
else
TapeTogglePause(TAPE_TOGGLE_MANUAL);
case GAME_CTRL_ID_PANEL_PLAY:
if (game_status == GAME_MODE_MAIN)
{
- StartGameActions(options.network, setup.autorecord, level.random_seed);
+ StartGameActions(network.enabled, setup.autorecord, level.random_seed);
}
else if (tape.pausing)
{
-#if defined(NETWORK_AVALIABLE)
- if (options.network)
+ if (network.enabled)
SendToServer_ContinuePlaying();
else
-#endif
TapeTogglePause(TAPE_TOGGLE_MANUAL | TAPE_TOGGLE_PLAY_PAUSE);
}
break;