removed parameter from functions (which always had the same value)
[rocksndiamonds.git] / src / game.c
index a780952b9749960b09146a81745a8dbf496be539..410fec92a79180a7c5b014b1c95e375750c3c171 100644 (file)
@@ -1683,28 +1683,28 @@ int GetElementFromGroupElement(int element)
   return element;
 }
 
-static void IncrementPlayerSokobanFieldsNeeded(struct PlayerInfo *player)
+static void IncrementPlayerSokobanFieldsNeeded(void)
 {
   if (level.sb_fields_needed)
-    player->sokoban_fields_still_needed++;
+    local_player->sokoban_fields_still_needed++;
 }
 
-static void IncrementPlayerSokobanObjectsNeeded(struct PlayerInfo *player)
+static void IncrementPlayerSokobanObjectsNeeded(void)
 {
   if (level.sb_objects_needed)
-    player->sokoban_objects_still_needed++;
+    local_player->sokoban_objects_still_needed++;
 }
 
-static void DecrementPlayerSokobanFieldsNeeded(struct PlayerInfo *player)
+static void DecrementPlayerSokobanFieldsNeeded(void)
 {
-  if (player->sokoban_fields_still_needed > 0)
-    player->sokoban_fields_still_needed--;
+  if (local_player->sokoban_fields_still_needed > 0)
+    local_player->sokoban_fields_still_needed--;
 }
 
-static void DecrementPlayerSokobanObjectsNeeded(struct PlayerInfo *player)
+static void DecrementPlayerSokobanObjectsNeeded(void)
 {
-  if (player->sokoban_objects_still_needed > 0)
-    player->sokoban_objects_still_needed--;
+  if (local_player->sokoban_objects_still_needed > 0)
+    local_player->sokoban_objects_still_needed--;
 }
 
 static void InitPlayerField(int x, int y, int element, boolean init_game)
@@ -1816,11 +1816,11 @@ static void InitField(int x, int y, boolean init_game)
       break;
 
     case EL_SOKOBAN_FIELD_EMPTY:
-      IncrementPlayerSokobanFieldsNeeded(local_player);
+      IncrementPlayerSokobanFieldsNeeded();
       break;
 
     case EL_SOKOBAN_OBJECT:
-      IncrementPlayerSokobanObjectsNeeded(local_player);
+      IncrementPlayerSokobanObjectsNeeded();
       break;
 
     case EL_STONEBLOCK:
@@ -2207,8 +2207,8 @@ static void UpdatePlayfieldElementCount(void)
 static void UpdateGameControlValues(void)
 {
   int i, k;
-  int time = (local_player->LevelSolved ?
-             local_player->LevelSolved_CountingTime :
+  int time = (game.LevelSolved ?
+             game.LevelSolved_CountingTime :
              level.game_engine_type == GAME_ENGINE_TYPE_EM ?
              level.native_em_level->lev->time :
              level.game_engine_type == GAME_ENGINE_TYPE_SP ?
@@ -2216,8 +2216,8 @@ static void UpdateGameControlValues(void)
              level.game_engine_type == GAME_ENGINE_TYPE_MM ?
              game_mm.energy_left :
              game.no_time_limit ? TimePlayed : TimeLeft);
-  int score = (local_player->LevelSolved ?
-              local_player->LevelSolved_CountingScore :
+  int score = (game.LevelSolved ?
+              game.LevelSolved_CountingScore :
               level.game_engine_type == GAME_ENGINE_TYPE_EM ?
               level.native_em_level->lev->score :
               level.game_engine_type == GAME_ENGINE_TYPE_SP ?
@@ -2243,8 +2243,8 @@ static void UpdateGameControlValues(void)
                     local_player->sokoban_fields_still_needed > 0 ||
                     local_player->sokoban_objects_still_needed > 0 ||
                     local_player->lights_still_needed > 0);
-  int health = (local_player->LevelSolved ?
-               local_player->LevelSolved_CountingHealth :
+  int health = (game.LevelSolved ?
+               game.LevelSolved_CountingHealth :
                level.game_engine_type == GAME_ENGINE_TYPE_MM ?
                MM_HEALTH(game_mm.laser_overload_value) :
                local_player->health);
@@ -3546,18 +3546,8 @@ void InitGame(void)
     DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
     SnapField(player, 0, 0);
 
-    player->LevelSolved = FALSE;
     player->GameOver = FALSE;
 
-    player->LevelSolved_GameWon = FALSE;
-    player->LevelSolved_GameEnd = FALSE;
-    player->LevelSolved_SaveTape = FALSE;
-    player->LevelSolved_SaveScore = FALSE;
-
-    player->LevelSolved_CountingTime = 0;
-    player->LevelSolved_CountingScore = 0;
-    player->LevelSolved_CountingHealth = 0;
-
     map_player_action[i] = i;
   }
 
@@ -3584,6 +3574,17 @@ void InitGame(void)
 
   AllPlayersGone = FALSE;
 
+  game.LevelSolved = FALSE;
+
+  game.LevelSolved_GameWon = FALSE;
+  game.LevelSolved_GameEnd = FALSE;
+  game.LevelSolved_SaveTape = FALSE;
+  game.LevelSolved_SaveScore = FALSE;
+
+  game.LevelSolved_CountingTime = 0;
+  game.LevelSolved_CountingScore = 0;
+  game.LevelSolved_CountingHealth = 0;
+
   game.panel.active = TRUE;
 
   game.no_time_limit = (level.time == 0);
@@ -4456,28 +4457,28 @@ void InitAmoebaNr(int x, int y)
   AmoebaCnt2[group_nr]++;
 }
 
-static void PlayerWins(struct PlayerInfo *player)
+static void LevelSolved(void)
 {
   if (level.game_engine_type == GAME_ENGINE_TYPE_RND &&
       local_player->players_still_needed > 0)
     return;
 
-  player->LevelSolved = TRUE;
-  player->GameOver = TRUE;
+  game.LevelSolved = TRUE;
+
+  local_player->GameOver = TRUE;
 
-  player->score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
-                        level.native_em_level->lev->score :
-                        level.game_engine_type == GAME_ENGINE_TYPE_MM ?
-                        game_mm.score :
-                        player->score);
-  player->health_final = (level.game_engine_type == GAME_ENGINE_TYPE_MM ?
-                         MM_HEALTH(game_mm.laser_overload_value) :
-                         player->health);
+  local_player->score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
+                              level.native_em_level->lev->score :
+                              level.game_engine_type == GAME_ENGINE_TYPE_MM ?
+                              game_mm.score :
+                              local_player->score);
+  local_player->health_final = (level.game_engine_type == GAME_ENGINE_TYPE_MM ?
+                               MM_HEALTH(game_mm.laser_overload_value) :
+                               local_player->health);
 
-  player->LevelSolved_CountingTime = (game.no_time_limit ? TimePlayed :
-                                     TimeLeft);
-  player->LevelSolved_CountingScore = player->score_final;
-  player->LevelSolved_CountingHealth = player->health_final;
+  game.LevelSolved_CountingTime = (game.no_time_limit ? TimePlayed : TimeLeft);
+  game.LevelSolved_CountingScore = local_player->score_final;
+  game.LevelSolved_CountingHealth = local_player->health_final;
 }
 
 void GameWon(void)
@@ -4493,7 +4494,7 @@ void GameWon(void)
   int game_over_delay_value_2 = 25;
   int game_over_delay_value_3 = 50;
 
-  if (!local_player->LevelSolved_GameWon)
+  if (!game.LevelSolved_GameWon)
   {
     int i;
 
@@ -4501,9 +4502,9 @@ void GameWon(void)
     if (local_player->MovPos)
       return;
 
-    local_player->LevelSolved_GameWon = TRUE;
-    local_player->LevelSolved_SaveTape = tape.recording;
-    local_player->LevelSolved_SaveScore = !tape.playing;
+    game.LevelSolved_GameWon = TRUE;
+    game.LevelSolved_SaveTape = tape.recording;
+    game.LevelSolved_SaveScore = !tape.playing;
 
     if (!tape.playing)
     {
@@ -4559,8 +4560,8 @@ void GameWon(void)
       time = time_final;
       score = score_final;
 
-      local_player->LevelSolved_CountingTime = time;
-      local_player->LevelSolved_CountingScore = score;
+      game.LevelSolved_CountingTime = time;
+      game.LevelSolved_CountingScore = score;
 
       game_panel_controls[GAME_PANEL_TIME].value = time;
       game_panel_controls[GAME_PANEL_SCORE].value = score;
@@ -4631,8 +4632,8 @@ void GameWon(void)
     time  += time_count_steps * time_count_dir;
     score += time_count_steps * level.score[SC_TIME_BONUS];
 
-    local_player->LevelSolved_CountingTime = time;
-    local_player->LevelSolved_CountingScore = score;
+    game.LevelSolved_CountingTime = time;
+    game.LevelSolved_CountingScore = score;
 
     game_panel_controls[GAME_PANEL_TIME].value = time;
     game_panel_controls[GAME_PANEL_SCORE].value = score;
@@ -4663,8 +4664,8 @@ void GameWon(void)
     health += health_count_dir;
     score  += level.score[SC_TIME_BONUS];
 
-    local_player->LevelSolved_CountingHealth = health;
-    local_player->LevelSolved_CountingScore = score;
+    game.LevelSolved_CountingHealth = health;
+    game.LevelSolved_CountingScore = score;
 
     game_panel_controls[GAME_PANEL_HEALTH].value = health;
     game_panel_controls[GAME_PANEL_SCORE].value = score;
@@ -4699,9 +4700,9 @@ void GameEnd(void)
   int last_level_nr = levelset.level_nr;
   int hi_pos;
 
-  local_player->LevelSolved_GameEnd = TRUE;
+  game.LevelSolved_GameEnd = TRUE;
 
-  if (local_player->LevelSolved_SaveTape)
+  if (game.LevelSolved_SaveTape)
   {
     // make sure that request dialog to save tape does not open door again
     if (!global.use_envelope_request)
@@ -4722,7 +4723,7 @@ void GameEnd(void)
     return;
   }
 
-  if (!local_player->LevelSolved_SaveScore)
+  if (!game.LevelSolved_SaveScore)
   {
     SetGameStatus(GAME_MODE_MAIN);
 
@@ -7951,7 +7952,7 @@ static void StartMoving(int x, int y)
        local_player->friends_still_needed--;
        if (!local_player->friends_still_needed &&
            !local_player->GameOver && AllPlayersGone)
-         PlayerWins(local_player);
+         LevelSolved();
 
        return;
       }
@@ -9848,7 +9849,7 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page)
          ExitPlayer(&stored_player[i]);
 
       if (AllPlayersGone)
-       PlayerWins(local_player);
+       LevelSolved();
 
       break;
     }
@@ -11117,19 +11118,17 @@ static void CheckLevelSolved(void)
 {
   if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
   {
-    if (level.native_em_level->lev->home == 0) // all players at home
+    if (game_em.level_solved &&
+       !game_em.game_over)                             // game won
     {
-      PlayerWins(local_player);
+      LevelSolved();
 
-      AllPlayersGone = TRUE;
+      game_em.game_over = TRUE;
 
-      level.native_em_level->lev->home = -1;
+      AllPlayersGone = TRUE;
     }
 
-    if (level.native_em_level->ply[0]->alive == 0 &&
-       level.native_em_level->ply[1]->alive == 0 &&
-       level.native_em_level->ply[2]->alive == 0 &&
-       level.native_em_level->ply[3]->alive == 0)      // all dead
+    if (game_em.game_over)                             // game lost
       AllPlayersGone = TRUE;
   }
   else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
@@ -11137,7 +11136,7 @@ static void CheckLevelSolved(void)
     if (game_sp.level_solved &&
        !game_sp.game_over)                             // game won
     {
-      PlayerWins(local_player);
+      LevelSolved();
 
       game_sp.game_over = TRUE;
 
@@ -11152,7 +11151,7 @@ static void CheckLevelSolved(void)
     if (game_mm.level_solved &&
        !game_mm.game_over)                             // game won
     {
-      PlayerWins(local_player);
+      LevelSolved();
 
       game_mm.game_over = TRUE;
 
@@ -11186,7 +11185,7 @@ static void CheckLevelTime(void)
       }
     }
 
-    if (!local_player->LevelSolved && !level.use_step_counter)
+    if (!game.LevelSolved && !level.use_step_counter)
     {
       TimePlayed++;
 
@@ -11333,7 +11332,7 @@ static void GameActionsExt(void)
 
   CheckLevelSolved();
 
-  if (local_player->LevelSolved && !local_player->LevelSolved_GameEnd)
+  if (game.LevelSolved && !game.LevelSolved_GameEnd)
     GameWon();
 
   if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
@@ -12679,7 +12678,7 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
       if ((local_player->friends_still_needed == 0 ||
           IS_SP_ELEMENT(Feld[jx][jy])) &&
          AllPlayersGone)
-       PlayerWins(local_player);
+       LevelSolved();
     }
 
     // this breaks one level: "machine", level 000
@@ -12727,7 +12726,7 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
        RemovePlayer(player);
     }
 
-    if (!local_player->LevelSolved && level.use_step_counter)
+    if (!game.LevelSolved && level.use_step_counter)
     {
       int i;
 
@@ -13973,16 +13972,16 @@ static int DigField(struct PlayerInfo *player,
       {
        Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
 
-       IncrementPlayerSokobanFieldsNeeded(local_player);
-       IncrementPlayerSokobanObjectsNeeded(local_player);
+       IncrementPlayerSokobanFieldsNeeded();
+       IncrementPlayerSokobanObjectsNeeded();
       }
 
       if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
       {
        Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
 
-       DecrementPlayerSokobanFieldsNeeded(local_player);
-       DecrementPlayerSokobanObjectsNeeded(local_player);
+       DecrementPlayerSokobanFieldsNeeded();
+       DecrementPlayerSokobanObjectsNeeded();
 
        // sokoban object was pushed from empty field to sokoban field
        if (Back[x][y] == EL_EMPTY)
@@ -14007,7 +14006,7 @@ static int DigField(struct PlayerInfo *player,
       {
        local_player->players_still_needed = 0;
 
-       PlayerWins(local_player);
+       LevelSolved();
 
        PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
       }
@@ -15032,7 +15031,7 @@ void CheckGameOver(void)
 boolean checkGameSolved(void)
 {
   // set for all game engines if level was solved
-  return local_player->LevelSolved_GameEnd;
+  return game.LevelSolved_GameEnd;
 }
 
 boolean checkGameFailed(void)
@@ -15041,13 +15040,13 @@ boolean checkGameFailed(void)
     return FALSE;
 
   if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
-    return (level.native_em_level->lev->home > 0);
+    return (game_em.game_over && !game_em.level_solved);
   else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
     return (game_sp.game_over && !game_sp.level_solved);
   else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
     return (game_mm.game_over && !game_mm.level_solved);
   else                         // GAME_ENGINE_TYPE_RND
-    return (local_player->GameOver && !local_player->LevelSolved);
+    return (local_player->GameOver && !game.LevelSolved);
 }
 
 boolean checkGameEnded(void)