rnd-20100713-1-src
authorHolger Schemel <info@artsoft.org>
Mon, 12 Jul 2010 23:29:32 +0000 (01:29 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:59:48 +0000 (10:59 +0200)
* added level tracing (played, solved) for use in level selection screen
  (to display already played or solved levels in different font color)

ChangeLog
src/conftime.h
src/files.c
src/game.c
src/libgame/setup.c
src/libgame/setup.h
src/libgame/system.c
src/libgame/system.h
src/main.h
src/screens.c

index 2e74f2f744ace1806d618736afe4000a29c23d82..d1a0045e2ab1bb9ce847ae1b33bf01f517509867 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2010-07-12
        * added level selection screen (when clicking on main menu level number)
+       * added level tracing (played, solved) for use in level selection screen
+         (to display already played or solved levels in different font color)
 
 2010-06-24
        * added alternative game mode for playing with half size playfield tiles
index b3a00a14e623b666a4c4dad29c49a3685dfa7a18..da268da6c7851bab3576d22b6428db8db0b4735b 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2010-07-12 15:47"
+#define COMPILE_DATE_STRING "2010-07-13 01:20"
index ff33da821a2a941ee786dd5217f6949796d363a9..fd0c4010c290f068d07b1f77b5254c0a71bfb018 100644 (file)
@@ -7139,8 +7139,12 @@ static void LoadLevelFromFileInfo(struct LevelInfo *level,
 
   /* if level file is invalid, restore level structure to default values */
   if (level->no_valid_file)
+  {
     setLevelInfoToDefaults(level, level_info_only);
 
+    level->no_valid_file = TRUE;       /* but keep "no valid file" flag */
+  }
+
   if (level->game_engine_type == GAME_ENGINE_TYPE_UNKNOWN)
     level->game_engine_type = GAME_ENGINE_TYPE_RND;
 
index 7c70ae071aead691d63232a5006a07089ca0e0ac..7bfaa2cc8a457786428dbf018fb7d4d29a40aae7 100644 (file)
@@ -4636,6 +4636,17 @@ void InitGame()
   MapTapeButtons();
 #endif
 
+  if (!game.restart_level && !tape.playing)
+  {
+    LevelStats_incPlayed(level_nr);
+
+    SaveLevelSetup_SeriesInfo();
+
+#if 1
+    printf("::: PLAYING LEVEL (%d)\n", LevelStats_getPlayed(level_nr));
+#endif
+  }
+
   game.restart_level = FALSE;
 }
 
@@ -4879,6 +4890,17 @@ void GameWon()
     local_player->LevelSolved_SaveTape = tape.recording;
     local_player->LevelSolved_SaveScore = !tape.playing;
 
+    if (!tape.playing)
+    {
+      LevelStats_incSolved(level_nr);
+
+      SaveLevelSetup_SeriesInfo();
+
+#if 1
+      printf("::: LEVEL SOLVED (%d)\n", LevelStats_getSolved(level_nr));
+#endif
+    }
+
     if (tape.auto_play)                /* tape might already be stopped here */
       tape.auto_play_level_solved = TRUE;
 
@@ -5083,6 +5105,7 @@ void GameEnd()
   if (level_nr == leveldir_current->handicap_level)
   {
     leveldir_current->handicap_level++;
+
     SaveLevelSetup_SeriesInfo();
   }
 
index 3b0bc8713b8ce1d45382568fa532650abd477cb1..7bb8ecdb3369ce8ad515885f0a3e29ad1f82b276 100644 (file)
@@ -4029,10 +4029,17 @@ void LoadLevelSetup_SeriesInfo()
   char *filename;
   SetupFileHash *level_setup_hash = NULL;
   char *level_subdir = leveldir_current->subdir;
+  int i;
 
   /* always start with reliable default values */
   level_nr = leveldir_current->first_level;
 
+  for (i = 0; i < MAX_LEVELS; i++)
+  {
+    LevelStats_setPlayed(i, 0);
+    LevelStats_setSolved(i, 0);
+  }
+
   checkSeriesInfo(leveldir_current);
 
   /* ----------------------------------------------------------------------- */
@@ -4047,6 +4054,8 @@ void LoadLevelSetup_SeriesInfo()
   {
     char *token_value;
 
+    /* get last played level in this level set */
+
     token_value = getHashEntry(level_setup_hash, TOKEN_STR_LAST_PLAYED_LEVEL);
 
     if (token_value)
@@ -4059,6 +4068,8 @@ void LoadLevelSetup_SeriesInfo()
        level_nr = leveldir_current->last_level;
     }
 
+    /* get handicap level in this level set */
+
     token_value = getHashEntry(level_setup_hash, TOKEN_STR_HANDICAP_LEVEL);
 
     if (token_value)
@@ -4076,6 +4087,26 @@ void LoadLevelSetup_SeriesInfo()
       leveldir_current->handicap_level = level_nr;
     }
 
+    /* get number of played and solved levels in this level set */
+
+    BEGIN_HASH_ITERATION(level_setup_hash, itr)
+    {
+      char *token = HASH_ITERATION_TOKEN(itr);
+      char *value = HASH_ITERATION_TOKEN(itr);
+
+      if (strlen(token) == 3 &&
+         token[0] >= '0' && token[0] <= '9' &&
+         token[1] >= '0' && token[1] <= '9' &&
+         token[2] >= '0' && token[2] <= '9')
+      {
+       int level_nr = atoi(token);
+
+       LevelStats_setPlayed(level_nr, atoi(value));
+       LevelStats_setSolved(level_nr, atoi(strchr(value, ' ')));
+      }
+    }
+    END_HASH_ITERATION(hash, itr)
+
     checkSetupFileHashIdentifier(level_setup_hash, filename,
                                 getCookie("LEVELSETUP"));
 
@@ -4094,6 +4125,7 @@ void SaveLevelSetup_SeriesInfo()
   char *level_nr_str = int2str(level_nr, 0);
   char *handicap_level_str = int2str(leveldir_current->handicap_level, 0);
   FILE *file;
+  int i;
 
   /* ----------------------------------------------------------------------- */
   /* ~/.<program>/levelsetup/<level series>/levelsetup.conf                  */
@@ -4114,8 +4146,24 @@ void SaveLevelSetup_SeriesInfo()
                                                 getCookie("LEVELSETUP")));
   fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_LAST_PLAYED_LEVEL,
                                               level_nr_str));
-  fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_HANDICAP_LEVEL,
-                                              handicap_level_str));
+  fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_HANDICAP_LEVEL,
+                                                handicap_level_str));
+
+  for (i = leveldir_current->first_level; i <= leveldir_current->last_level;
+       i++)
+  {
+    if (LevelStats_getPlayed(i) > 0 ||
+       LevelStats_getSolved(i) > 0)
+    {
+      char token[16];
+      char value[16];
+
+      sprintf(token, "%03d", i);
+      sprintf(value, "%d %d", LevelStats_getPlayed(i), LevelStats_getSolved(i));
+
+      fprintf(file, "%s\n", getFormattedSetupEntry(token, value));
+    }
+  }
 
   fclose(file);
 
@@ -4123,3 +4171,37 @@ void SaveLevelSetup_SeriesInfo()
 
   free(filename);
 }
+
+int LevelStats_getPlayed(int nr)
+{
+  return (nr >= 0 && nr < MAX_LEVELS ? level_stats[nr].played : 0);
+}
+
+int LevelStats_getSolved(int nr)
+{
+  return (nr >= 0 && nr < MAX_LEVELS ? level_stats[nr].solved : 0);
+}
+
+void LevelStats_setPlayed(int nr, int value)
+{
+  if (nr >= 0 && nr < MAX_LEVELS)
+    level_stats[nr].played = value;
+}
+
+void LevelStats_setSolved(int nr, int value)
+{
+  if (nr >= 0 && nr < MAX_LEVELS)
+    level_stats[nr].solved = value;
+}
+
+void LevelStats_incPlayed(int nr)
+{
+  if (nr >= 0 && nr < MAX_LEVELS)
+    level_stats[nr].played++;
+}
+
+void LevelStats_incSolved(int nr)
+{
+  if (nr >= 0 && nr < MAX_LEVELS)
+    level_stats[nr].solved++;
+}
index 68643a2f3f2fe803ed6a003883dab231978584b0..c667c348b38304164c924697ce86bcb8ba60dab8 100644 (file)
@@ -320,4 +320,11 @@ void SaveLevelSetup_LastSeries(void);
 void LoadLevelSetup_SeriesInfo(void);
 void SaveLevelSetup_SeriesInfo(void);
 
+int LevelStats_getPlayed(int);
+int LevelStats_getSolved(int);
+void LevelStats_setPlayed(int, int);
+void LevelStats_setSolved(int, int);
+void LevelStats_incPlayed(int);
+void LevelStats_incSolved(int);
+
 #endif /* MISC_H */
index dce2b888943693f787fb882b19dd4a20dd9413e3..6b070a262eb2f4c7f2797754c56703fea9bc44a3 100644 (file)
@@ -46,6 +46,8 @@ LevelDirTree         *leveldir_first = NULL;
 LevelDirTree          *leveldir_current = NULL;
 int                    level_nr;
 
+struct LevelStats      level_stats[MAX_LEVELS];
+
 Display                       *display = NULL;
 Visual                *visual = NULL;
 int                    screen = 0;
index e5375e090c2e2143d3f506b94d8921c997748309..df95c9d336ff7ed064fb095c09572b5149b947b0 100644 (file)
 /* maximum allowed length of player name */
 #define MAX_PLAYER_NAME_LEN    10
 
+/* maximum number of levels in a level set */
+#define MAX_LEVELS             1000
+
 /* default name for empty highscore entry */
 #define EMPTY_PLAYER_NAME      "no name"
 
@@ -1159,6 +1162,12 @@ struct TextPosInfo
   int id;
 };
 
+struct LevelStats
+{
+  int played;
+  int solved;
+};
+
 
 /* ========================================================================= */
 /* exported variables                                                        */
@@ -1179,6 +1188,8 @@ extern LevelDirTree              *leveldir_first;
 extern LevelDirTree           *leveldir_current;
 extern int                     level_nr;
 
+extern struct LevelStats       level_stats[];
+
 extern Display                *display;
 extern Visual                 *visual;
 extern int                     screen;
index b9cc814edd65a2988fd398c347cd2cf76e292c3b..f319e55f55acd6687746ba90b0a2f08fbb3a7b9d 100644 (file)
 /* special definitions currently only used for custom artwork configuration */
 #define MUSIC_PREFIX_BACKGROUND                0
 #define NUM_MUSIC_PREFIXES             1
-#define MAX_LEVELS                     1000
 
 /* definitions for demo animation lists */
 #define HELPANIM_LIST_NEXT             -1
index 37ccbe8e193e77c51880710bded1760114043ff5..3b1b92fbf16088894d8ba9d369c680b9b3553b29 100644 (file)
@@ -3767,9 +3767,13 @@ void DrawChooseLevelNr()
 
     ti->node_top = &level_number;
     ti->sort_priority = 10000 + value;
+    ti->color = (level.no_valid_file ? FC_BLUE :
+                LevelStats_getSolved(i) ? FC_GREEN :
+                LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
 
     sprintf(identifier, "%d", value);
-    sprintf(name, "%03d: %s", value, level.name);
+    sprintf(name, "%03d: %s", value,
+           (level.no_valid_file ? "(empty)" : level.name));
 
     setString(&ti->identifier, identifier);
     setString(&ti->name, name);