added also loading non-successful replay when loading native BD level
authorHolger Schemel <info@artsoft.org>
Mon, 1 Apr 2024 22:54:12 +0000 (00:54 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 1 Apr 2024 22:54:12 +0000 (00:54 +0200)
src/files.c
src/game_bd/main_bd.c

index 157564d824603e3cdac3a0cfbc8d1823735fb368..cf35328611c6f57ced6a641035bd02ae00eff9bf 100644 (file)
@@ -4607,6 +4607,9 @@ static void CopyNativeTape_BD_to_RND(struct LevelInfo *level)
   }
 
   TapeHaltRecording();
+
+  if (!replay->success)
+    Warn("BD replay is marked as not successful");
 }
 
 
index 6b3ba1043116ebfb468eccff1cb2b3c83f274adc..77af13a28c158a4e59ce6f43e1607d09af895325 100644 (file)
@@ -95,6 +95,30 @@ void setLevelInfoToDefaults_BD(void)
   setLevelInfoToDefaults_BD_Ext(0, 0);
 }
 
+static List *getNativeLevelReplay_BD_Ext(List *item, boolean only_successful_replays)
+{
+  // look for replay that was recorded for the current difficulty level
+  while (item != NULL &&
+        (item->data == NULL ||
+         (((GdReplay *)item->data)->success == FALSE && only_successful_replays) ||
+         ((GdReplay *)item->data)->level != native_bd_level.level_nr))
+    item = item->next;
+
+  return item;
+}
+
+static List *getNativeLevelReplay_BD(List *replays)
+{
+  // 1st try: look for successful replay
+  List *item = getNativeLevelReplay_BD_Ext(replays, TRUE);
+
+  if (item != NULL)
+    return item;
+
+  // 2nd try: look for any replay
+  return getNativeLevelReplay_BD_Ext(replays, FALSE);
+}
+
 boolean LoadNativeLevel_BD(char *filename, int level_pos, boolean level_info_only)
 {
   static char *filename_loaded = NULL;
@@ -137,16 +161,9 @@ boolean LoadNativeLevel_BD(char *filename, int level_pos, boolean level_info_onl
   // check if this cave has any replays
   if (native_bd_level.cave->replays != NULL)
   {
-    List *item = native_bd_level.cave->replays;
-
-    // try to find replay that was recorded for this difficulty level
-    while (item != NULL &&
-          (item->data == NULL ||
-           ((GdReplay *)item->data)->success == FALSE ||
-           ((GdReplay *)item->data)->level != native_bd_level.level_nr))
-      item = item->next;
+    List *item = getNativeLevelReplay_BD(native_bd_level.cave->replays);
 
-    // matching replay found
+    // check if any matching replay was found
     if (item != NULL)
       native_bd_level.replay = (GdReplay *)item->data;
   }