From 9f9755626ee7b4b6960bee26d78b25debf946f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Nunes?= Date: Tue, 1 Mar 2022 18:23:41 +0000 Subject: [PATCH 1/8] Add level attempts statistics --- ball/level.c | 12 ++++++++++++ ball/level.h | 11 +++++++++++ ball/progress.c | 25 ++++++++++++++++++------- ball/set.c | 21 +++++++++++++++++++++ ball/st_goal.c | 2 ++ ball/st_start.c | 2 ++ ball/util.c | 29 +++++++++++++++++++++++++++++ ball/util.h | 2 ++ 8 files changed, 97 insertions(+), 7 deletions(-) diff --git a/ball/level.c b/ball/level.c index 10a517fac..5e0271a6d 100644 --- a/ball/level.c +++ b/ball/level.c @@ -261,5 +261,17 @@ void level_rename_player(struct level *l, SAFECPY(l->scores[SCORE_COIN].player[coin_rank], player); } +void level_attempts_update(struct level *l, int result) +{ + l->attempts[result]++; +} + +void level_attempts_set(struct level *l, int success, int timeout, int fallout) +{ + l->attempts[SUCCESS] = success; + l->attempts[TIMEOUT] = timeout; + l->attempts[FALLOUT] = fallout; +} + /*---------------------------------------------------------------------------*/ diff --git a/ball/level.h b/ball/level.h index 33a00c34f..517e66fd4 100644 --- a/ball/level.h +++ b/ball/level.h @@ -13,6 +13,13 @@ enum SCORE_COIN }; +enum +{ + SUCCESS = 0, + TIMEOUT, + FALLOUT +}; + #define LEVEL_LOCKED 0x1 #define LEVEL_COMPLETED 0x2 @@ -32,6 +39,7 @@ struct level int goal; /* Coins needed */ struct score scores[3]; + int attempts[3]; /* Set information. */ @@ -76,6 +84,9 @@ const struct score *level_score(struct level *, int); int level_score_update (struct level *, int, int, int *, int *, int *); void level_rename_player(struct level *, int, int, int, const char *); +void level_attempts_update(struct level *, int); +void level_attempts_set (struct level *, int, int, int); + /*---------------------------------------------------------------------------*/ #endif diff --git a/ball/progress.c b/ball/progress.c index aa7eb0598..d86eff736 100644 --- a/ball/progress.c +++ b/ball/progress.c @@ -157,7 +157,7 @@ void progress_step(void) void progress_stat(int s) { - int i, dirty = 0; + int i; status = s; @@ -178,15 +178,16 @@ void progress_stat(int s) curr.score += coins; curr.times += timer; - dirty = level_score_update(level, timer, coins, + level_score_update(level, timer, coins, &time_rank, goal == 0 ? &goal_rank : NULL, &coin_rank); + level_attempts_update(level, SUCCESS); + if (!level_completed(level)) { level_complete(level); - dirty = 1; } /* Compute next level. */ @@ -200,7 +201,6 @@ void progress_stat(int s) if (!level_opened(next)) { level_open(next); - dirty = 1; } } } @@ -217,7 +217,6 @@ void progress_stat(int s) if (next) { level_open(next); - dirty = 1; } else done = mode == MODE_CHALLENGE; @@ -226,6 +225,17 @@ void progress_stat(int s) case GAME_FALL: /* Fall through. */ + for (next = level->next; + next && !level_opened(next); + next = next->next) + /* Do nothing */; + + curr.times += timer; + curr.balls -= 1; + + level_attempts_update(level, FALLOUT); + + break; case GAME_TIME: for (next = level->next; @@ -236,11 +246,12 @@ void progress_stat(int s) curr.times += timer; curr.balls -= 1; + level_attempts_update(level, TIMEOUT); + break; } - if (dirty && mode != MODE_STANDALONE) - set_store_hs(); + set_store_hs(); demo_play_stat(status, coins, timer); } diff --git a/ball/set.c b/ball/set.c index f3149627d..992f403b0 100644 --- a/ball/set.c +++ b/ball/set.c @@ -124,6 +124,9 @@ void set_store_hs(void) fs_printf(fp, "level %d %d %s\n", flags, l->version_num, l->file); + fs_printf(fp, "attmps %d %d %d\n", l->attempts[SUCCESS], + l->attempts[TIMEOUT], l->attempts[FALLOUT]); + put_score(fp, &l->scores[SCORE_TIME]); put_score(fp, &l->scores[SCORE_GOAL]); put_score(fp, &l->scores[SCORE_COIN]); @@ -174,6 +177,23 @@ static struct level *find_level(const struct set *s, const char *file) return NULL; } +static int get_attempts(fs_file fp, struct level *l) +{ + char line[MAXSTR]; + + if (!fs_gets(line, sizeof(line), fp)) + return 0; + + strip_newline(line); + + if (sscanf(line, "attmps %d %d %d", &l->attempts[SUCCESS], + &l->attempts[TIMEOUT], + &l->attempts[FALLOUT]) < 2) + return 0; + + return 1; +} + static void set_load_hs_v2(fs_file fp, struct set *s, char *buf, int size) { struct score time_score; @@ -203,6 +223,7 @@ static void set_load_hs_v2(fs_file fp, struct set *s, char *buf, int size) if ((l = find_level(s, buf + n))) { + get_attempts(fp, l); /* Always prefer "locked" flag from the score file. */ l->is_locked = !!(flags & LEVEL_LOCKED); diff --git a/ball/st_goal.c b/ball/st_goal.c index 1e609a9f9..c8b57d158 100644 --- a/ball/st_goal.c +++ b/ball/st_goal.c @@ -228,6 +228,8 @@ static int goal_gui(void) } + gui_set_attempts(curr_level()); + set_score_board(level_score(curr_level(), SCORE_COIN), progress_coin_rank(), level_score(curr_level(), SCORE_TIME), progress_time_rank(), level_score(curr_level(), SCORE_GOAL), progress_goal_rank()); diff --git a/ball/st_start.c b/ball/st_start.c index 480684665..40155d4a8 100644 --- a/ball/st_start.c +++ b/ball/st_start.c @@ -85,6 +85,8 @@ static void start_over_level(int i) { gui_set_image(shot_id, level_shot(l)); + gui_set_attempts(l); + set_score_board(level_score(l, SCORE_COIN), -1, level_score(l, SCORE_TIME), -1, level_score(l, SCORE_GOAL), -1); diff --git a/ball/util.c b/ball/util.c index ac3ffd07d..71d83cfc7 100644 --- a/ball/util.c +++ b/ball/util.c @@ -57,6 +57,8 @@ static int score_coin[4]; static int score_name[4]; static int score_time[4]; +static int attempts[3]; + static int score_extra_row; /* Build a top three score list with default values. */ @@ -110,6 +112,24 @@ static void gui_scores(int id, int e) } } +static void gui_attempts(int id) +{ + int at; + + if ((at = gui_vstack(id))) + { + gui_filler(at); + gui_label(at, "Attempts", GUI_SML, 0, 0); + + attempts[SUCCESS] = gui_count(at, 0, GUI_SML); + attempts[TIMEOUT] = gui_count(at, 0, GUI_SML); + attempts[FALLOUT] = gui_count(at, 0, GUI_SML); + + gui_set_rect(at, GUI_ALL); + gui_filler(at); + } +} + /* Set the top three score list values. */ static void gui_set_scores(const char *label, const struct score *s, int hilite) @@ -214,6 +234,8 @@ void gui_score_board(int pd, unsigned int types, int e, int h) gui_scores(id, e); + gui_attempts(id); + gui_filler(id); } } @@ -256,6 +278,13 @@ int gui_score_get(void) return score_type; } +void gui_set_attempts(const struct level *l) +{ + gui_set_count(attempts[SUCCESS], l->attempts[SUCCESS]); + gui_set_count(attempts[TIMEOUT], l->attempts[TIMEOUT]); + gui_set_count(attempts[FALLOUT], l->attempts[FALLOUT]); +} + /*---------------------------------------------------------------------------*/ static int lock = 1; diff --git a/ball/util.h b/ball/util.h index 4bf52f387..e0cd72805 100644 --- a/ball/util.h +++ b/ball/util.h @@ -19,6 +19,8 @@ void gui_score_set(int); int gui_score_get(void); +void gui_set_attempts(const struct level *); + void gui_score_board(int, unsigned int, int, int); void set_score_board(const struct score *, int, const struct score *, int, From 079ba06ff65b7a60896bad2693c9e23ead08d9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Nunes?= Date: Tue, 1 Mar 2022 19:22:15 +0000 Subject: [PATCH 2/8] Add compat to level highscores files --- ball/set.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ball/set.c b/ball/set.c index 992f403b0..1c2457dfb 100644 --- a/ball/set.c +++ b/ball/set.c @@ -188,8 +188,15 @@ static int get_attempts(fs_file fp, struct level *l) if (sscanf(line, "attmps %d %d %d", &l->attempts[SUCCESS], &l->attempts[TIMEOUT], - &l->attempts[FALLOUT]) < 2) - return 0; + &l->attempts[FALLOUT]) < 3) { + /* compatible with save files without attempts info */ + l->attempts[SUCCESS] = 0; + l->attempts[TIMEOUT] = 0; + l->attempts[FALLOUT] = 0; + + /* attmps not available, rewind file pointer */ + fs_seek(fp, - strlen(line) - 1, SEEK_CUR); + } return 1; } From 198ec2d7bfa442ba8d57f24825a9984379a446b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Nunes?= Date: Tue, 20 Dec 2022 17:51:37 +0000 Subject: [PATCH 3/8] Add colors to attempt labels --- ball/util.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ball/util.c b/ball/util.c index 71d83cfc7..b6dc6d8f3 100644 --- a/ball/util.c +++ b/ball/util.c @@ -114,16 +114,16 @@ static void gui_scores(int id, int e) static void gui_attempts(int id) { - int at; + int at, attempt_id; if ((at = gui_vstack(id))) { gui_filler(at); - gui_label(at, "Attempts", GUI_SML, 0, 0); + gui_label(at, _("Attempts"), GUI_SML, 0, 0); - attempts[SUCCESS] = gui_count(at, 0, GUI_SML); - attempts[TIMEOUT] = gui_count(at, 0, GUI_SML); - attempts[FALLOUT] = gui_count(at, 0, GUI_SML); + attempts[SUCCESS] = gui_label(at, "0", GUI_SML, gui_grn, gui_wht); + attempts[TIMEOUT] = gui_label(at, "0", GUI_SML, gui_yel, gui_wht); + attempts[FALLOUT] = gui_label(at, "0", GUI_SML, gui_red, gui_wht); gui_set_rect(at, GUI_ALL); gui_filler(at); @@ -280,9 +280,13 @@ int gui_score_get(void) void gui_set_attempts(const struct level *l) { - gui_set_count(attempts[SUCCESS], l->attempts[SUCCESS]); - gui_set_count(attempts[TIMEOUT], l->attempts[TIMEOUT]); - gui_set_count(attempts[FALLOUT], l->attempts[FALLOUT]); + char buffer[10]; + sprintf(buffer, "%d", l->attempts[SUCCESS]); + gui_set_label(attempts[SUCCESS], buffer); + sprintf(buffer, "%d", l->attempts[TIMEOUT]); + gui_set_label(attempts[TIMEOUT], buffer); + sprintf(buffer, "%d", l->attempts[FALLOUT]); + gui_set_label(attempts[FALLOUT], buffer); } /*---------------------------------------------------------------------------*/ From c8f9ca064b3cf52534510aac17210b1d7af9fe65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Nunes?= Date: Wed, 23 Aug 2023 22:06:21 +0100 Subject: [PATCH 4/8] Remame attmps to stats --- ball/level.c | 12 ++++++------ ball/level.h | 6 +++--- ball/progress.c | 6 +++--- ball/set.c | 24 ++++++++++++------------ ball/st_goal.c | 2 +- ball/st_start.c | 2 +- ball/util.c | 30 +++++++++++++++--------------- ball/util.h | 2 +- 8 files changed, 42 insertions(+), 42 deletions(-) diff --git a/ball/level.c b/ball/level.c index 5e0271a6d..b2f5ddc60 100644 --- a/ball/level.c +++ b/ball/level.c @@ -261,16 +261,16 @@ void level_rename_player(struct level *l, SAFECPY(l->scores[SCORE_COIN].player[coin_rank], player); } -void level_attempts_update(struct level *l, int result) +void level_stats_update(struct level *l, int result) { - l->attempts[result]++; + l->stats[result]++; } -void level_attempts_set(struct level *l, int success, int timeout, int fallout) +void level_stats_set(struct level *l, int success, int timeout, int fallout) { - l->attempts[SUCCESS] = success; - l->attempts[TIMEOUT] = timeout; - l->attempts[FALLOUT] = fallout; + l->stats[SUCCESS] = success; + l->stats[TIMEOUT] = timeout; + l->stats[FALLOUT] = fallout; } /*---------------------------------------------------------------------------*/ diff --git a/ball/level.h b/ball/level.h index 517e66fd4..e753c388f 100644 --- a/ball/level.h +++ b/ball/level.h @@ -39,7 +39,7 @@ struct level int goal; /* Coins needed */ struct score scores[3]; - int attempts[3]; + int stats[3]; /* Set information. */ @@ -84,8 +84,8 @@ const struct score *level_score(struct level *, int); int level_score_update (struct level *, int, int, int *, int *, int *); void level_rename_player(struct level *, int, int, int, const char *); -void level_attempts_update(struct level *, int); -void level_attempts_set (struct level *, int, int, int); +void level_stats_update(struct level *, int); +void level_stats_set (struct level *, int, int, int); /*---------------------------------------------------------------------------*/ diff --git a/ball/progress.c b/ball/progress.c index d86eff736..2e8165af7 100644 --- a/ball/progress.c +++ b/ball/progress.c @@ -183,7 +183,7 @@ void progress_stat(int s) goal == 0 ? &goal_rank : NULL, &coin_rank); - level_attempts_update(level, SUCCESS); + level_stats_update(level, SUCCESS); if (!level_completed(level)) { @@ -233,7 +233,7 @@ void progress_stat(int s) curr.times += timer; curr.balls -= 1; - level_attempts_update(level, FALLOUT); + level_stats_update(level, FALLOUT); break; @@ -246,7 +246,7 @@ void progress_stat(int s) curr.times += timer; curr.balls -= 1; - level_attempts_update(level, TIMEOUT); + level_stats_update(level, TIMEOUT); break; } diff --git a/ball/set.c b/ball/set.c index 48f8f7b35..3912c0502 100644 --- a/ball/set.c +++ b/ball/set.c @@ -123,8 +123,8 @@ void set_store_hs(void) fs_printf(fp, "level %d %d %s\n", flags, l->version_num, l->file); - fs_printf(fp, "attmps %d %d %d\n", l->attempts[SUCCESS], - l->attempts[TIMEOUT], l->attempts[FALLOUT]); + fs_printf(fp, "stats %d %d %d\n", l->stats[SUCCESS], + l->stats[TIMEOUT], l->stats[FALLOUT]); put_score(fp, &l->scores[SCORE_TIME]); put_score(fp, &l->scores[SCORE_GOAL]); @@ -176,7 +176,7 @@ static struct level *find_level(const struct set *s, const char *file) return NULL; } -static int get_attempts(fs_file fp, struct level *l) +static int get_stats(fs_file fp, struct level *l) { char line[MAXSTR]; @@ -185,15 +185,15 @@ static int get_attempts(fs_file fp, struct level *l) strip_newline(line); - if (sscanf(line, "attmps %d %d %d", &l->attempts[SUCCESS], - &l->attempts[TIMEOUT], - &l->attempts[FALLOUT]) < 3) { - /* compatible with save files without attempts info */ - l->attempts[SUCCESS] = 0; - l->attempts[TIMEOUT] = 0; - l->attempts[FALLOUT] = 0; + if (sscanf(line, "stats %d %d %d", &l->stats[SUCCESS], + &l->stats[TIMEOUT], + &l->stats[FALLOUT]) < 3) { + /* compatible with save files without stats info */ + l->stats[SUCCESS] = 0; + l->stats[TIMEOUT] = 0; + l->stats[FALLOUT] = 0; - /* attmps not available, rewind file pointer */ + /* stats not available, rewind file pointer */ fs_seek(fp, - strlen(line) - 1, SEEK_CUR); } @@ -229,7 +229,7 @@ static void set_load_hs_v2(fs_file fp, struct set *s, char *buf, int size) if ((l = find_level(s, buf + n))) { - get_attempts(fp, l); + get_stats(fp, l); /* Always prefer "locked" flag from the score file. */ l->is_locked = !!(flags & LEVEL_LOCKED); diff --git a/ball/st_goal.c b/ball/st_goal.c index c8b57d158..89fa1c508 100644 --- a/ball/st_goal.c +++ b/ball/st_goal.c @@ -228,7 +228,7 @@ static int goal_gui(void) } - gui_set_attempts(curr_level()); + gui_set_stats(curr_level()); set_score_board(level_score(curr_level(), SCORE_COIN), progress_coin_rank(), level_score(curr_level(), SCORE_TIME), progress_time_rank(), diff --git a/ball/st_start.c b/ball/st_start.c index 397338991..4c30f868d 100644 --- a/ball/st_start.c +++ b/ball/st_start.c @@ -85,7 +85,7 @@ static void start_over_level(int i) { gui_set_image(shot_id, level_shot(l)); - gui_set_attempts(l); + gui_set_stats(l); set_score_board(level_score(l, SCORE_COIN), -1, level_score(l, SCORE_TIME), -1, diff --git a/ball/util.c b/ball/util.c index b6dc6d8f3..38c38a502 100644 --- a/ball/util.c +++ b/ball/util.c @@ -57,7 +57,7 @@ static int score_coin[4]; static int score_name[4]; static int score_time[4]; -static int attempts[3]; +static int stats[3]; static int score_extra_row; @@ -112,18 +112,18 @@ static void gui_scores(int id, int e) } } -static void gui_attempts(int id) +static void gui_stats(int id) { - int at, attempt_id; + int at; if ((at = gui_vstack(id))) { gui_filler(at); - gui_label(at, _("Attempts"), GUI_SML, 0, 0); + gui_label(at, _("Stats"), GUI_SML, 0, 0); - attempts[SUCCESS] = gui_label(at, "0", GUI_SML, gui_grn, gui_wht); - attempts[TIMEOUT] = gui_label(at, "0", GUI_SML, gui_yel, gui_wht); - attempts[FALLOUT] = gui_label(at, "0", GUI_SML, gui_red, gui_wht); + stats[SUCCESS] = gui_label(at, "0", GUI_SML, gui_grn, gui_wht); + stats[TIMEOUT] = gui_label(at, "0", GUI_SML, gui_yel, gui_wht); + stats[FALLOUT] = gui_label(at, "0", GUI_SML, gui_red, gui_wht); gui_set_rect(at, GUI_ALL); gui_filler(at); @@ -234,7 +234,7 @@ void gui_score_board(int pd, unsigned int types, int e, int h) gui_scores(id, e); - gui_attempts(id); + gui_stats(id); gui_filler(id); } @@ -278,15 +278,15 @@ int gui_score_get(void) return score_type; } -void gui_set_attempts(const struct level *l) +void gui_set_stats(const struct level *l) { char buffer[10]; - sprintf(buffer, "%d", l->attempts[SUCCESS]); - gui_set_label(attempts[SUCCESS], buffer); - sprintf(buffer, "%d", l->attempts[TIMEOUT]); - gui_set_label(attempts[TIMEOUT], buffer); - sprintf(buffer, "%d", l->attempts[FALLOUT]); - gui_set_label(attempts[FALLOUT], buffer); + sprintf(buffer, "%d", l->stats[SUCCESS]); + gui_set_label(stats[SUCCESS], buffer); + sprintf(buffer, "%d", l->stats[TIMEOUT]); + gui_set_label(stats[TIMEOUT], buffer); + sprintf(buffer, "%d", l->stats[FALLOUT]); + gui_set_label(stats[FALLOUT], buffer); } /*---------------------------------------------------------------------------*/ diff --git a/ball/util.h b/ball/util.h index e0cd72805..f6dac5435 100644 --- a/ball/util.h +++ b/ball/util.h @@ -19,7 +19,7 @@ void gui_score_set(int); int gui_score_get(void); -void gui_set_attempts(const struct level *); +void gui_set_stats(const struct level *); void gui_score_board(int, unsigned int, int, int); void set_score_board(const struct score *, int, From 644e6202f83ecd9b2b94679d4f73ae7b6019201f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Nunes?= Date: Thu, 24 Aug 2023 21:33:14 +0100 Subject: [PATCH 5/8] Rename SUCCESS to COMPLETED --- ball/level.c | 2 +- ball/level.h | 4 ++-- ball/progress.c | 2 +- ball/set.c | 12 +++++------- ball/util.c | 10 +++++----- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/ball/level.c b/ball/level.c index b2f5ddc60..44d3317ad 100644 --- a/ball/level.c +++ b/ball/level.c @@ -268,7 +268,7 @@ void level_stats_update(struct level *l, int result) void level_stats_set(struct level *l, int success, int timeout, int fallout) { - l->stats[SUCCESS] = success; + l->stats[COMPLETED] = success; l->stats[TIMEOUT] = timeout; l->stats[FALLOUT] = fallout; } diff --git a/ball/level.h b/ball/level.h index e753c388f..e320e8183 100644 --- a/ball/level.h +++ b/ball/level.h @@ -15,7 +15,7 @@ enum enum { - SUCCESS = 0, + COMPLETED = 0, TIMEOUT, FALLOUT }; @@ -39,7 +39,7 @@ struct level int goal; /* Coins needed */ struct score scores[3]; - int stats[3]; + int stats[3]; /* Statistics: completed, timeout, fallout. */ /* Set information. */ diff --git a/ball/progress.c b/ball/progress.c index 2e8165af7..7575daa06 100644 --- a/ball/progress.c +++ b/ball/progress.c @@ -183,7 +183,7 @@ void progress_stat(int s) goal == 0 ? &goal_rank : NULL, &coin_rank); - level_stats_update(level, SUCCESS); + level_stats_update(level, COMPLETED); if (!level_completed(level)) { diff --git a/ball/set.c b/ball/set.c index 3912c0502..d9a1408ed 100644 --- a/ball/set.c +++ b/ball/set.c @@ -123,7 +123,7 @@ void set_store_hs(void) fs_printf(fp, "level %d %d %s\n", flags, l->version_num, l->file); - fs_printf(fp, "stats %d %d %d\n", l->stats[SUCCESS], + fs_printf(fp, "stats %d %d %d\n", l->stats[COMPLETED], l->stats[TIMEOUT], l->stats[FALLOUT]); put_score(fp, &l->scores[SCORE_TIME]); @@ -176,28 +176,26 @@ static struct level *find_level(const struct set *s, const char *file) return NULL; } -static int get_stats(fs_file fp, struct level *l) +static void get_stats(fs_file fp, struct level *l) { char line[MAXSTR]; if (!fs_gets(line, sizeof(line), fp)) - return 0; + return; strip_newline(line); - if (sscanf(line, "stats %d %d %d", &l->stats[SUCCESS], + if (sscanf(line, "stats %d %d %d", &l->stats[COMPLETED], &l->stats[TIMEOUT], &l->stats[FALLOUT]) < 3) { /* compatible with save files without stats info */ - l->stats[SUCCESS] = 0; + l->stats[COMPLETED] = 0; l->stats[TIMEOUT] = 0; l->stats[FALLOUT] = 0; /* stats not available, rewind file pointer */ fs_seek(fp, - strlen(line) - 1, SEEK_CUR); } - - return 1; } static void set_load_hs_v2(fs_file fp, struct set *s, char *buf, int size) diff --git a/ball/util.c b/ball/util.c index 38c38a502..bbdbd1d12 100644 --- a/ball/util.c +++ b/ball/util.c @@ -121,9 +121,9 @@ static void gui_stats(int id) gui_filler(at); gui_label(at, _("Stats"), GUI_SML, 0, 0); - stats[SUCCESS] = gui_label(at, "0", GUI_SML, gui_grn, gui_wht); - stats[TIMEOUT] = gui_label(at, "0", GUI_SML, gui_yel, gui_wht); - stats[FALLOUT] = gui_label(at, "0", GUI_SML, gui_red, gui_wht); + stats[COMPLETED] = gui_label(at, "0", GUI_SML, gui_grn, gui_wht); + stats[TIMEOUT] = gui_label(at, "0", GUI_SML, gui_yel, gui_wht); + stats[FALLOUT] = gui_label(at, "0", GUI_SML, gui_red, gui_wht); gui_set_rect(at, GUI_ALL); gui_filler(at); @@ -281,8 +281,8 @@ int gui_score_get(void) void gui_set_stats(const struct level *l) { char buffer[10]; - sprintf(buffer, "%d", l->stats[SUCCESS]); - gui_set_label(stats[SUCCESS], buffer); + sprintf(buffer, "%d", l->stats[COMPLETED]); + gui_set_label(stats[COMPLETED], buffer); sprintf(buffer, "%d", l->stats[TIMEOUT]); gui_set_label(stats[TIMEOUT], buffer); sprintf(buffer, "%d", l->stats[FALLOUT]); From 944066dc7ade738fb57a2c444ce73cf1c511c7b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Nunes?= Date: Fri, 25 Aug 2023 21:05:10 +0100 Subject: [PATCH 6/8] Rename stats to stats_label --- ball/util.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ball/util.c b/ball/util.c index bbdbd1d12..fb07e923f 100644 --- a/ball/util.c +++ b/ball/util.c @@ -57,7 +57,7 @@ static int score_coin[4]; static int score_name[4]; static int score_time[4]; -static int stats[3]; +static int stats_label[3]; static int score_extra_row; @@ -121,9 +121,9 @@ static void gui_stats(int id) gui_filler(at); gui_label(at, _("Stats"), GUI_SML, 0, 0); - stats[COMPLETED] = gui_label(at, "0", GUI_SML, gui_grn, gui_wht); - stats[TIMEOUT] = gui_label(at, "0", GUI_SML, gui_yel, gui_wht); - stats[FALLOUT] = gui_label(at, "0", GUI_SML, gui_red, gui_wht); + stats_label[COMPLETED] = gui_label(at, " ", GUI_SML, gui_grn, gui_wht); + stats_label[TIMEOUT] = gui_label(at, " ", GUI_SML, gui_yel, gui_wht); + stats_label[FALLOUT] = gui_label(at, " ", GUI_SML, gui_red, gui_wht); gui_set_rect(at, GUI_ALL); gui_filler(at); @@ -282,11 +282,11 @@ void gui_set_stats(const struct level *l) { char buffer[10]; sprintf(buffer, "%d", l->stats[COMPLETED]); - gui_set_label(stats[COMPLETED], buffer); + gui_set_label(stats_label[COMPLETED], buffer); sprintf(buffer, "%d", l->stats[TIMEOUT]); - gui_set_label(stats[TIMEOUT], buffer); + gui_set_label(stats_label[TIMEOUT], buffer); sprintf(buffer, "%d", l->stats[FALLOUT]); - gui_set_label(stats[FALLOUT], buffer); + gui_set_label(stats_label[FALLOUT], buffer); } /*---------------------------------------------------------------------------*/ From bc5368f4dba1a59e28432f915fe80f4d58071367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Nunes?= Date: Fri, 25 Aug 2023 21:57:13 +0100 Subject: [PATCH 7/8] Remove duplicate code --- ball/progress.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/ball/progress.c b/ball/progress.c index 7575daa06..a2f70bbe8 100644 --- a/ball/progress.c +++ b/ball/progress.c @@ -225,17 +225,6 @@ void progress_stat(int s) case GAME_FALL: /* Fall through. */ - for (next = level->next; - next && !level_opened(next); - next = next->next) - /* Do nothing */; - - curr.times += timer; - curr.balls -= 1; - - level_stats_update(level, FALLOUT); - - break; case GAME_TIME: for (next = level->next; @@ -246,7 +235,7 @@ void progress_stat(int s) curr.times += timer; curr.balls -= 1; - level_stats_update(level, TIMEOUT); + level_stats_update(level, status == GAME_FALL ? FALLOUT : TIMEOUT); break; } From 2f4253f36a338257cf72c4dbac51b08bf3333974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Nunes?= Date: Mon, 28 Aug 2023 14:40:18 +0100 Subject: [PATCH 8/8] Create struct stats --- ball/level.c | 12 ------------ ball/level.h | 14 +++++--------- ball/progress.c | 4 ++-- ball/set.c | 16 ++++++++-------- ball/util.c | 24 ++++++++++++++---------- 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/ball/level.c b/ball/level.c index 44d3317ad..10a517fac 100644 --- a/ball/level.c +++ b/ball/level.c @@ -261,17 +261,5 @@ void level_rename_player(struct level *l, SAFECPY(l->scores[SCORE_COIN].player[coin_rank], player); } -void level_stats_update(struct level *l, int result) -{ - l->stats[result]++; -} - -void level_stats_set(struct level *l, int success, int timeout, int fallout) -{ - l->stats[COMPLETED] = success; - l->stats[TIMEOUT] = timeout; - l->stats[FALLOUT] = fallout; -} - /*---------------------------------------------------------------------------*/ diff --git a/ball/level.h b/ball/level.h index e320e8183..dfbbbbc3c 100644 --- a/ball/level.h +++ b/ball/level.h @@ -13,11 +13,10 @@ enum SCORE_COIN }; -enum -{ - COMPLETED = 0, - TIMEOUT, - FALLOUT +struct stats { + int completed; + int timeout; + int fallout; }; #define LEVEL_LOCKED 0x1 @@ -39,7 +38,7 @@ struct level int goal; /* Coins needed */ struct score scores[3]; - int stats[3]; /* Statistics: completed, timeout, fallout. */ + struct stats stats; /* Set information. */ @@ -84,9 +83,6 @@ const struct score *level_score(struct level *, int); int level_score_update (struct level *, int, int, int *, int *, int *); void level_rename_player(struct level *, int, int, int, const char *); -void level_stats_update(struct level *, int); -void level_stats_set (struct level *, int, int, int); - /*---------------------------------------------------------------------------*/ #endif diff --git a/ball/progress.c b/ball/progress.c index a2f70bbe8..98a20772e 100644 --- a/ball/progress.c +++ b/ball/progress.c @@ -183,7 +183,7 @@ void progress_stat(int s) goal == 0 ? &goal_rank : NULL, &coin_rank); - level_stats_update(level, COMPLETED); + level->stats.completed++; if (!level_completed(level)) { @@ -235,7 +235,7 @@ void progress_stat(int s) curr.times += timer; curr.balls -= 1; - level_stats_update(level, status == GAME_FALL ? FALLOUT : TIMEOUT); + status == GAME_FALL ? level->stats.fallout++ : level->stats.timeout++; break; } diff --git a/ball/set.c b/ball/set.c index d9a1408ed..1df4ba301 100644 --- a/ball/set.c +++ b/ball/set.c @@ -123,8 +123,8 @@ void set_store_hs(void) fs_printf(fp, "level %d %d %s\n", flags, l->version_num, l->file); - fs_printf(fp, "stats %d %d %d\n", l->stats[COMPLETED], - l->stats[TIMEOUT], l->stats[FALLOUT]); + fs_printf(fp, "stats %d %d %d\n", l->stats.completed, + l->stats.timeout, l->stats.fallout); put_score(fp, &l->scores[SCORE_TIME]); put_score(fp, &l->scores[SCORE_GOAL]); @@ -185,13 +185,13 @@ static void get_stats(fs_file fp, struct level *l) strip_newline(line); - if (sscanf(line, "stats %d %d %d", &l->stats[COMPLETED], - &l->stats[TIMEOUT], - &l->stats[FALLOUT]) < 3) { + if (sscanf(line, "stats %d %d %d", &l->stats.completed, + &l->stats.timeout, + &l->stats.fallout) < 3) { /* compatible with save files without stats info */ - l->stats[COMPLETED] = 0; - l->stats[TIMEOUT] = 0; - l->stats[FALLOUT] = 0; + l->stats.completed = 0; + l->stats.timeout = 0; + l->stats.fallout = 0; /* stats not available, rewind file pointer */ fs_seek(fp, - strlen(line) - 1, SEEK_CUR); diff --git a/ball/util.c b/ball/util.c index fb07e923f..b7cffc225 100644 --- a/ball/util.c +++ b/ball/util.c @@ -57,7 +57,11 @@ static int score_coin[4]; static int score_name[4]; static int score_time[4]; -static int stats_label[3]; +struct { + int completed; + int timeout; + int fallout; +} stats_labels; static int score_extra_row; @@ -121,9 +125,9 @@ static void gui_stats(int id) gui_filler(at); gui_label(at, _("Stats"), GUI_SML, 0, 0); - stats_label[COMPLETED] = gui_label(at, " ", GUI_SML, gui_grn, gui_wht); - stats_label[TIMEOUT] = gui_label(at, " ", GUI_SML, gui_yel, gui_wht); - stats_label[FALLOUT] = gui_label(at, " ", GUI_SML, gui_red, gui_wht); + stats_labels.completed = gui_label(at, " ", GUI_SML, gui_grn, gui_wht); + stats_labels.timeout = gui_label(at, " ", GUI_SML, gui_yel, gui_wht); + stats_labels.fallout = gui_label(at, " ", GUI_SML, gui_red, gui_wht); gui_set_rect(at, GUI_ALL); gui_filler(at); @@ -281,12 +285,12 @@ int gui_score_get(void) void gui_set_stats(const struct level *l) { char buffer[10]; - sprintf(buffer, "%d", l->stats[COMPLETED]); - gui_set_label(stats_label[COMPLETED], buffer); - sprintf(buffer, "%d", l->stats[TIMEOUT]); - gui_set_label(stats_label[TIMEOUT], buffer); - sprintf(buffer, "%d", l->stats[FALLOUT]); - gui_set_label(stats_label[FALLOUT], buffer); + sprintf(buffer, "%d", l->stats.completed); + gui_set_label(stats_labels.completed, buffer); + sprintf(buffer, "%d", l->stats.timeout); + gui_set_label(stats_labels.timeout, buffer); + sprintf(buffer, "%d", l->stats.fallout); + gui_set_label(stats_labels.fallout, buffer); } /*---------------------------------------------------------------------------*/