removed unused functions and definitions
[rocksndiamonds.git] / src / game_bd / bd_gameplay.c
index 8145cce6c2c2271c557943facc33ceb0acac73a3..483d21eb258e5bc00ddfc9aad36f0bbc9abd72c4 100644 (file)
@@ -31,6 +31,10 @@ void gd_game_free(GdGame *game)
 
   if (game->element_buffer)
     gd_cave_map_free(game->element_buffer);
+  if (game->last_element_buffer)
+    gd_cave_map_free(game->last_element_buffer);
+  if (game->dir_buffer)
+    gd_cave_map_free(game->dir_buffer);
   if (game->gfx_buffer)
     gd_cave_map_free(game->gfx_buffer);
 
@@ -39,64 +43,16 @@ void gd_game_free(GdGame *game)
   if (game->cave)
     gd_cave_free(game->cave);
 
-  /* if we recorded some replays during this run, we check them.
-     we remove those which are too short */
-  if (game->replays_recorded)
-  {
-    GList *citer;
-
-    /* check all caves */
-    for (citer = gd_caveset; citer != NULL; citer = citer->next)
-    {
-      GdCave *cave = (GdCave *)citer->data;
-      GList *riter;
-
-      /* check replays of all caves */
-      for (riter = cave->replays; riter != NULL; )
-      {
-       GdReplay *replay = (GdReplay *)riter->data;
-
-       /* remember next iter, as we may delete the current */
-       GList *nextrep = riter->next;
-
-       /* if we recorded this replay now, and it is too short, we delete it */
-       /* but do not delete successful ones! */
-       if (g_list_find(game->replays_recorded, replay) &&
-           (replay->movements->len < 16) &&
-           (!replay->success))
-       {
-         /* delete from list */
-         cave->replays = g_list_delete_link(cave->replays, riter);
-
-         /* also free replay */
-         gd_replay_free(replay);
-       }
-
-       riter = nextrep;
-      }
-    }
-
-    /* free the list of newly recorded replays, as we checked them */
-    g_list_free(game->replays_recorded);
-    game->replays_recorded = NULL;
-  }
-
   free(game);
 }
 
 /* add bonus life. if sound enabled, play sound, too. */
 static void add_bonus_life(GdGame *game, boolean inform_user)
 {
-  /* only inform about bonus life when playing a game */
-  /* or when testing the cave (so the user can see that a bonus life can be earned in that cave */
-  if (game->type == GD_GAMETYPE_NORMAL ||
-      game->type == GD_GAMETYPE_TEST)
+  if (inform_user)
   {
-    if (inform_user)
-    {
-      gd_sound_play_bonus_life();
-      game->bonus_life_flash = 100;
-    }
+    gd_sound_play_bonus_life();
+    game->bonus_life_flash = 100;
   }
 
   /* really increment number of lifes? only in a real game, nowhere else. */
@@ -121,10 +77,6 @@ static void increment_score(GdGame *game, int increment)
   game->player_score += increment;
   game->cave_score += increment;
 
-  /* also record to replay */
-  if (game->replay_record)
-    game->replay_record->score += increment;
-
   /* if score crossed bonus_life_score point boundary, player won a bonus life */
   if (game->player_score / gd_caveset_data->bonus_life_score > i)
     add_bonus_life(game, TRUE);
@@ -140,6 +92,16 @@ static void load_cave(GdGame *game)
     gd_cave_map_free(game->element_buffer);
   game->element_buffer = NULL;
 
+  /* delete last element buffer */
+  if (game->last_element_buffer)
+    gd_cave_map_free(game->last_element_buffer);
+  game->last_element_buffer = NULL;
+
+  /* delete direction buffer */
+  if (game->dir_buffer)
+    gd_cave_map_free(game->dir_buffer);
+  game->dir_buffer = NULL;
+
   /* delete gfx buffer */
   if (game->gfx_buffer)
     gd_cave_map_free(game->gfx_buffer);
@@ -171,6 +133,20 @@ static void load_cave(GdGame *game)
     for (x = 0; x < game->cave->w; x++)
       game->element_buffer[y][x] = O_NONE;
 
+  /* create new last element buffer */
+  game->last_element_buffer = gd_cave_map_new(game->cave, int);
+
+  for (y = 0; y < game->cave->h; y++)
+    for (x = 0; x < game->cave->w; x++)
+      game->last_element_buffer[y][x] = O_NONE;
+
+  /* create new direction buffer */
+  game->dir_buffer = gd_cave_map_new(game->cave, int);
+
+  for (y = 0; y < game->cave->h; y++)
+    for (x = 0; x < game->cave->w; x++)
+      game->dir_buffer[y][x] = GD_MV_STILL;
+
   /* create new gfx buffer */
   game->gfx_buffer = gd_cave_map_new(game->cave, int);
 
@@ -207,7 +183,6 @@ GdGame *gd_game_new(const int cave, const int level)
   game->player_move_stick = FALSE;
   game->player_fire = FALSE;
 
-  game->type = GD_GAMETYPE_NORMAL;
   game->state_counter = GAME_INT_LOAD_CAVE;
 
   game->show_story = TRUE;
@@ -215,67 +190,13 @@ GdGame *gd_game_new(const int cave, const int level)
   return game;
 }
 
-/* starts a new snapshot playing */
-GdGame *gd_game_new_replay(GdCave *cave, GdReplay *replay)
-{
-  GdGame *game;
-
-  game = checked_calloc(sizeof(GdGame));
-
-  gd_strcpy(game->player_name, "");
-
-  game->player_lives = 0;
-  game->player_score = 0;
-
-  game->player_move = GD_MV_STILL;
-  game->player_move_stick = FALSE;
-  game->player_fire = FALSE;
-
-  game->original_cave = cave;
-  game->replay_from = replay;
-
-  game->type = GD_GAMETYPE_REPLAY;
-  game->state_counter = GAME_INT_LOAD_CAVE;
-
-  return game;
-}
-
 static void iterate_cave(GdGame *game, GdDirection player_move, boolean fire)
 {
   boolean suicide = FALSE;
 
-  /* if we are playing a replay, but the user intervents, continue as a snapshot. */
-  /* do not trigger this for fire, as it would not be too intuitive. */
-  if (game->type == GD_GAMETYPE_REPLAY)
-  {
-    if (player_move != GD_MV_STILL)
-    {
-      game->type = GD_GAMETYPE_CONTINUE_REPLAY;
-      game->replay_from = NULL;
-    }
-  }
-
   /* ANYTHING EXCEPT A TIMEOUT, WE ITERATE THE CAVE */
   if (game->cave->player_state != GD_PL_TIMEOUT)
   {
-    /* IF PLAYING FROM REPLAY, OVERWRITE KEYPRESS VARIABLES FROM REPLAY */
-    if (game->type == GD_GAMETYPE_REPLAY)
-    {
-      boolean result;
-
-      /* if the user does touch the keyboard, we immediately exit replay,
-        and he can continue playing */
-      result = gd_replay_get_next_movement(game->replay_from, &player_move, &fire, &suicide);
-      /* if could not get move from snapshot, continue from keyboard input. */
-      if (!result)
-       game->replay_no_more_movements++;
-
-      /* if no more available movements, and the user does not do anything,
-        we cover cave and stop game. */
-      if (game->replay_no_more_movements > 15)
-       game->state_counter = GAME_INT_COVER_START;
-    }
-
     if (TapeIsPlaying_ReplayBD())
     {
       byte *action_rnd = TapePlayAction_BD();
@@ -292,9 +213,6 @@ static void iterate_cave(GdGame *game, GdDirection player_move, boolean fire)
     /* iterate cave */
     gd_cave_iterate(game->cave, player_move, fire, suicide);
 
-    if (game->replay_record)
-      gd_replay_store_movement(game->replay_record, player_move, fire, suicide);
-
     if (game->cave->score)
       increment_score(game, game->cave->score);
 
@@ -311,9 +229,6 @@ static void iterate_cave(GdGame *game, GdDirection player_move, boolean fire)
       add_bonus_life(game, FALSE);
     }
 
-    if (game->replay_record)
-      game->replay_record->success = TRUE;
-
     /* start adding points for remaining time */
     game->state_counter = GAME_INT_CHECK_BONUS_TIME;
     gd_cave_clear_sounds(game->cave);
@@ -369,8 +284,8 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
 
     /* if we have a story... */
 #if 0
-    if (game->show_story && game->original_cave && game->original_cave->story->len != 0)
-      Info("Cave Story: %s", game->original_cave->story->str);
+    if (game->show_story && game->original_cave && game->original_cave->story != NULL)
+      Info("Cave Story: %s", game->original_cave->story);
 #endif
 
     counter_next = GAME_INT_START_UNCOVER;
@@ -396,7 +311,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
     /* uncover animation */
 
     /* to play cover sound */
-    gd_sound_play(game->cave, GD_S_COVER, O_COVERED, -1, -1);
+    gd_sound_play(game->cave, GD_S_COVERING, O_COVERED, -1, -1);
     gd_sound_play_cave(game->cave);
 
     counter_next = game->state_counter;
@@ -455,6 +370,9 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
     if (allow_iterate)
       game->milliseconds_game += millisecs_elapsed;
 
+    /* increment cycle (frame) counter for the current cave iteration */
+    game->itercycle++;
+
     if (game->milliseconds_game >= cavespeed)
     {
       GdPlayerState pl;
@@ -462,6 +380,25 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
       game->milliseconds_game -= cavespeed;
       pl = game->cave->player_state;
 
+      /* initialize buffers for last cave element and direction for next iteration */
+      for (y = 0; y < game->cave->h; y++)
+      {
+       for (x = 0; x < game->cave->w; x++)
+       {
+         game->last_element_buffer[y][x] = game->element_buffer[y][x];
+         game->dir_buffer[y][x] = GD_MV_STILL;
+       }
+      }
+
+      /* store last maximum number of cycles (to force redraw if changed) */
+      game->itermax_last = game->itermax;
+
+      /* update maximum number of cycles (frame) per cave iteration */
+      game->itermax = game->itercycle;
+
+      /* reset cycle (frame) counter for the next cave iteration */
+      game->itercycle = 0;
+
       iterate_cave(game, game->player_move, game->player_fire);
 
       if (game->player_move == GD_MV_STILL)
@@ -546,7 +483,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
     /* if no more lives, game is over. */
     counter_next = game->state_counter;
 
-    if (game->type == GD_GAMETYPE_NORMAL && game->player_lives == 0)
+    if (game->player_lives == 0)
       return_state = GD_GAME_NO_MORE_LIVES;
     else
       return_state = GD_GAME_NOTHING;
@@ -567,7 +504,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
     /* starting to cover. start cover sound. */
 
     gd_cave_clear_sounds(game->cave);
-    gd_sound_play(game->cave, GD_S_COVER, O_COVERED, -1, -1);
+    gd_sound_play(game->cave, GD_S_COVERING, O_COVERED, -1, -1);
 
     /* to play cover sound */
     gd_sound_play_cave(game->cave);
@@ -579,7 +516,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
           game->state_counter < GAME_INT_COVER_ALL)
   {
     /* covering. */
-    gd_sound_play(game->cave, GD_S_COVER, O_COVERED, -1, -1);
+    gd_sound_play(game->cave, GD_S_COVERING, O_COVERED, -1, -1);
 
     counter_next = game->state_counter;
 
@@ -614,19 +551,10 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
   {
     /* cover all + 1 */
 
-    /* if this is a normal game: */
-    if (game->type == GD_GAMETYPE_NORMAL)
-    {
-      if (game->player_lives != 0)
-       return_state = GD_GAME_NOTHING;    /* and go to next level */
-      else
-       return_state = GD_GAME_GAME_OVER;
-    }
+    if (game->player_lives != 0)
+      return_state = GD_GAME_NOTHING;    /* and go to next level */
     else
-    {
-      /* for snapshots and replays and the like, this is the end. */
-      return_state = GD_GAME_STOP;
-    }
+      return_state = GD_GAME_GAME_OVER;
   }
 
   /* draw the cave */