From 0c6144aa1196e8121ba38716f9f95836d0ccbb9e Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 13 Jul 2010 01:29:32 +0200 Subject: [PATCH] rnd-20100713-1-src * added level tracing (played, solved) for use in level selection screen (to display already played or solved levels in different font color) --- ChangeLog | 2 ++ src/conftime.h | 2 +- src/files.c | 4 +++ src/game.c | 23 ++++++++++++ src/libgame/setup.c | 86 ++++++++++++++++++++++++++++++++++++++++++-- src/libgame/setup.h | 7 ++++ src/libgame/system.c | 2 ++ src/libgame/system.h | 11 ++++++ src/main.h | 1 - src/screens.c | 6 +++- 10 files changed, 139 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e74f2f7..d1a0045e 100644 --- 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 diff --git a/src/conftime.h b/src/conftime.h index b3a00a14..da268da6 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2010-07-12 15:47" +#define COMPILE_DATE_STRING "2010-07-13 01:20" diff --git a/src/files.c b/src/files.c index ff33da82..fd0c4010 100644 --- a/src/files.c +++ b/src/files.c @@ -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; diff --git a/src/game.c b/src/game.c index 7c70ae07..7bfaa2cc 100644 --- a/src/game.c +++ b/src/game.c @@ -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(); } diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 3b0bc871..7bb8ecdb 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -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; /* ----------------------------------------------------------------------- */ /* ~/./levelsetup//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++; +} diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 68643a2f..c667c348 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -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 */ diff --git a/src/libgame/system.c b/src/libgame/system.c index dce2b888..6b070a26 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -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; diff --git a/src/libgame/system.h b/src/libgame/system.h index e5375e09..df95c9d3 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -316,6 +316,9 @@ /* 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; diff --git a/src/main.h b/src/main.h index b9cc814e..f319e55f 100644 --- a/src/main.h +++ b/src/main.h @@ -2056,7 +2056,6 @@ /* 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 diff --git a/src/screens.c b/src/screens.c index 37ccbe8e..3b1b92fb 100644 --- a/src/screens.c +++ b/src/screens.c @@ -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); -- 2.34.1