added level editor option to sort high scores by playing time (or steps)
authorHolger Schemel <info@artsoft.org>
Thu, 18 Mar 2021 18:44:50 +0000 (19:44 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 1 May 2021 13:38:01 +0000 (15:38 +0200)
src/editor.c
src/files.c
src/game.c
src/main.h
src/screens.c

index 24590595e96d645f563ad4ee6e9c9fa375feed44..1713f04d9119d1044d351c73d42d4a3301ebbe30 100644 (file)
@@ -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,
index 4dc7fceb920713954d13f135147dec071bc433b8..133a2d2609b2515de8b5eeb3edf82d34ae65a798 100644 (file)
@@ -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,
index a09a5bb6858f3710fdf0a8601338e6d4a684b206..1b2db60f629cda8509a6fd42d5f0e5bf760fc43b 100644 (file)
@@ -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
 
index c0b74e80f8765ea1503941f8b7c61905dadbab8f..482f7317e5d81b41fd2d0265f520c16e41eefe38 100644 (file)
@@ -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];
index 0937577f26b411e625a05550634257599f7482c8..c23f7ce6cd2af8a40baf75989ef39ef22d188962 100644 (file)
@@ -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;