added functions to check if native BD cave or caveset has levels
authorHolger Schemel <info@artsoft.org>
Tue, 7 May 2024 21:58:11 +0000 (23:58 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 7 May 2024 21:58:47 +0000 (23:58 +0200)
src/game_bd/bd_cave.c
src/game_bd/bd_cave.h
src/game_bd/main_bd.c

index d946bac4c203a3decaa24f2304211802e40a217c..6a22a6379556b13d962f2cd26f7eb293eeb8aa09 100644 (file)
@@ -1678,3 +1678,60 @@ unsigned int gd_cave_adler_checksum(GdCave *cave)
   gd_cave_adler_checksum_more(cave, &a, &b);
   return (b << 16) + a;
 }
+
+boolean gd_cave_has_levels(GdCave *cave)
+{
+  GdCave c = *cave;
+  int *cave_level_value[] =
+  {
+    c.level_diamonds,
+    c.level_speed,
+    c.level_ckdelay,
+    c.level_time,
+    c.level_magic_wall_time,
+    c.level_amoeba_time,
+    c.level_amoeba_threshold,
+    c.level_amoeba_2_time,
+    c.level_amoeba_2_threshold,
+    c.level_slime_permeability,
+    c.level_slime_permeability_c64,
+    c.level_slime_seed_c64,
+    c.level_hatching_delay_frame,
+    c.level_hatching_delay_time,
+    c.level_bonus_time,
+    c.level_penalty_time,
+
+    NULL
+  };
+  int i, j;
+
+  for (i = 0; cave_level_value[i] != NULL; i++)
+    for (j = 1; j < 5; j++)
+      if (cave_level_value[i][j] != cave_level_value[i][0])
+       return TRUE;
+
+  for (j = 1; j < 5; j++)
+    if (cave->level_rand[j] != j &&
+       cave->level_rand[j - 1] != j - 1 &&
+       cave->level_rand[j] != cave->level_rand[0])
+      return TRUE;
+
+  for (j = 1; j < 5; j++)
+    if (cave->level_timevalue[j] != j + 1 &&
+       cave->level_timevalue[j - 1] != j &&
+       cave->level_timevalue[j] != cave->level_timevalue[0])
+      return TRUE;
+
+  return FALSE;
+}
+
+boolean gd_caveset_has_levels(void)
+{
+  List *iter;
+
+  for (iter = gd_caveset; iter != NULL; iter = iter->next)
+    if (gd_cave_has_levels((GdCave *)iter->data))
+      return TRUE;
+
+  return FALSE;
+}
index aea976e860decb2626630dc842eb03dd60ba0662..1a85776a68a4e17333308881e7c8807d1fe144c3 100644 (file)
@@ -721,4 +721,7 @@ void gd_replay_store_movement(GdReplay *replay, GdDirection player_move, boolean
 unsigned int gd_cave_adler_checksum(GdCave *cave);
 void gd_cave_adler_checksum_more(GdCave *cave, unsigned int *a, unsigned int *b);
 
+boolean gd_cave_has_levels(GdCave *cave);
+boolean gd_caveset_has_levels(void);
+
 #endif // BD_CAVE_H
index 25eb06310409d4a7146e442677c798a2a0887445..f69f440e25ba8bdec0269a6d7b12fecc2c669df1 100644 (file)
@@ -183,7 +183,9 @@ boolean SaveNativeLevel_BD(char *filename)
 
 void DumpLevelset_BD(void)
 {
-  Print("Number of levels:   %d\n", 5 * gd_caveset_count());
+  int num_levels_per_cave = (gd_caveset_has_levels() ? 5 : 1);
+
+  Print("Number of levels:   %d\n", num_levels_per_cave * gd_caveset_count());
   Print("First level number: %d\n", 1);
 }