From 088c9c2caa2434a1667dc8ea25b152b41cf7dc1b Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 18 Mar 2021 19:44:50 +0100 Subject: [PATCH] added level editor option to sort high scores by playing time (or steps) --- src/editor.c | 15 ++++++++++++--- src/files.c | 6 ++++++ src/game.c | 19 ++++++++++++++----- src/main.h | 1 + src/screens.c | 6 +++++- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/editor.c b/src/editor.c index 24590595..1713f04d 100644 --- a/src/editor.c +++ b/src/editor.c @@ -637,6 +637,7 @@ enum // checkbuttons/radiobuttons for level/element properties GADGET_ID_AUTO_COUNT_GEMS, + GADGET_ID_RATE_TIME_OVER_SCORE, GADGET_ID_USE_LEVELSET_ARTWORK, GADGET_ID_COPY_LEVEL_TEMPLATE, GADGET_ID_RANDOM_PERCENTAGE, @@ -946,6 +947,7 @@ enum enum { ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS, + ED_CHECKBUTTON_ID_RATE_TIME_OVER_SCORE, ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK, ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE, ED_CHECKBUTTON_ID_RANDOM_RESTRICTED, @@ -1019,7 +1021,7 @@ enum }; #define ED_CHECKBUTTON_ID_LEVEL_FIRST ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS -#define ED_CHECKBUTTON_ID_LEVEL_LAST ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS +#define ED_CHECKBUTTON_ID_LEVEL_LAST ED_CHECKBUTTON_ID_RATE_TIME_OVER_SCORE #define ED_CHECKBUTTON_ID_LEVELSET_FIRST ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK #define ED_CHECKBUTTON_ID_LEVELSET_LAST ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE @@ -1423,7 +1425,7 @@ static struct "score for time or steps left:", NULL, NULL }, { - ED_LEVEL_SETTINGS_XPOS(0), ED_LEVEL_SETTINGS_YPOS(12), + ED_LEVEL_SETTINGS_XPOS(0), ED_LEVEL_SETTINGS_YPOS(13), 0, 9999, GADGET_ID_LEVEL_RANDOM_SEED_DOWN, GADGET_ID_LEVEL_RANDOM_SEED_UP, GADGET_ID_LEVEL_RANDOM_SEED_TEXT, GADGET_ID_NONE, @@ -2510,7 +2512,7 @@ static struct NULL, NULL, NULL, "time score for 1 or 10 seconds/steps" }, { - ED_LEVEL_SETTINGS_XPOS(0), ED_LEVEL_SETTINGS_YPOS(11), + ED_LEVEL_SETTINGS_XPOS(0), ED_LEVEL_SETTINGS_YPOS(12), GADGET_ID_GAME_ENGINE_TYPE, GADGET_ID_NONE, -1, options_game_engine_type, @@ -3025,6 +3027,13 @@ static struct NULL, NULL, "automatically count gems needed", "set counter to number of gems" }, + { + ED_LEVEL_SETTINGS_XPOS(0), ED_LEVEL_SETTINGS_YPOS(11), + GADGET_ID_RATE_TIME_OVER_SCORE, GADGET_ID_NONE, + &level.rate_time_over_score, + NULL, NULL, + "rate time/steps used over score", "sort high scores by playing time/steps" + }, { ED_LEVEL_SETTINGS_XPOS(0), ED_LEVEL_SETTINGS_YPOS(7), GADGET_ID_USE_LEVELSET_ARTWORK, GADGET_ID_NONE, diff --git a/src/files.c b/src/files.c index 4dc7fceb..133a2d26 100644 --- a/src/files.c +++ b/src/files.c @@ -266,6 +266,12 @@ static struct LevelFileConfigInfo chunk_config_INFO[] = &li.time_score_base, 1 }, + { + -1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(13), + &li.rate_time_over_score, FALSE + }, + { -1, -1, -1, -1, diff --git a/src/game.c b/src/game.c index a09a5bb6..1b2db60f 100644 --- a/src/game.c +++ b/src/game.c @@ -5052,11 +5052,20 @@ int NewHiScore(int level_nr) for (k = 0; k < MAX_SCORE_ENTRIES; k++) { - boolean score_is_better = (game.score_final > scores.entry[k].score); - boolean score_is_equal = (game.score_final == scores.entry[k].score); - boolean time_is_better = (game.score_time_final < scores.entry[k].time); - - if (score_is_better || (score_is_equal && time_is_better)) + boolean score_is_better = (game.score_final > scores.entry[k].score); + boolean score_is_equal = (game.score_final == scores.entry[k].score); + boolean time_is_better = (game.score_time_final < scores.entry[k].time); + boolean time_is_equal = (game.score_time_final == scores.entry[k].time); + boolean better_by_score = (score_is_better || + (score_is_equal && time_is_better)); + boolean better_by_time = (time_is_better || + (time_is_equal && score_is_better)); + boolean is_better = (level.rate_time_over_score ? better_by_time : + better_by_score); + boolean entry_is_empty = (scores.entry[k].score == 0 && + scores.entry[k].time == 0); + + if (is_better || entry_is_empty) { // player has made it to the hall of fame diff --git a/src/main.h b/src/main.h index c0b74e80..482f7317 100644 --- a/src/main.h +++ b/src/main.h @@ -3121,6 +3121,7 @@ struct LevelInfo int time; // available time (seconds) int gems_needed; boolean auto_count_gems; + boolean rate_time_over_score; char name[MAX_LEVEL_NAME_LEN + 1]; char author[MAX_LEVEL_AUTHOR_LEN + 1]; diff --git a/src/screens.c b/src/screens.c index 0937577f..c23f7ce6 100644 --- a/src/screens.c +++ b/src/screens.c @@ -5072,8 +5072,12 @@ void DrawHallOfFame(int level_nr, int highlight_position) static char *getHallOfFameScoreText(int nr) { // use playing time instead of score for Supaplex levels - if (level.game_engine_type == GAME_ENGINE_TYPE_SP) + if (level.rate_time_over_score || + level.game_engine_type == GAME_ENGINE_TYPE_SP) { + if (level.use_step_counter) + return int2str(scores.entry[nr].time, 5); + static char score_text[10]; int time_final_max = 999; int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND; -- 2.34.1