added some comments
[rocksndiamonds.git] / src / files.c
index 4dc7fceb920713954d13f135147dec071bc433b8..1909cbecb81475fa93220dc2193d3fc6a67fc8c0 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,
@@ -3932,12 +3938,11 @@ static void CopyNativeLevel_SP_to_RND(struct LevelInfo *level)
   level->time_wheel = 0;
   level->amoeba_content = EL_EMPTY;
 
-#if 1
-  // original Supaplex does not use score values -- use default values
-#else
+  // original Supaplex does not use score values -- rate by playing time
   for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++)
     level->score[i] = 0;
-#endif
+
+  level->rate_time_over_score = TRUE;
 
   // there are no yamyams in supaplex levels
   for (i = 0; i < level->num_yamyam_contents; i++)
@@ -8446,6 +8451,25 @@ static void LoadScore_OLD(int nr)
   fclose(file);
 }
 
+static void ConvertScore_OLD(void)
+{
+  // only convert score to time for levels that rate playing time over score
+  if (!level.rate_time_over_score)
+    return;
+
+  // convert old score to playing time for score-less levels (like Supaplex)
+  int time_final_max = 999;
+  int i;
+
+  for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+  {
+    int score = scores.entry[i].score;
+
+    if (score > 0 && score < time_final_max)
+      scores.entry[i].time = (time_final_max - score - 1) * FRAMES_PER_SECOND;
+  }
+}
+
 static int LoadScore_VERS(File *file, int chunk_size, struct ScoreInfo *scores)
 {
   scores->file_version = getFileVersion(file);
@@ -8575,6 +8599,9 @@ void LoadScore(int nr)
   {
     // score files from versions before 4.2.4.0 without chunk structure
     LoadScore_OLD(nr);
+
+    // convert score to time, if possible (mainly for Supaplex levels)
+    ConvertScore_OLD();
   }
   else
   {