added code to convert native Boulder Dash levels
authorHolger Schemel <info@artsoft.org>
Sun, 11 Feb 2024 01:54:51 +0000 (02:54 +0100)
committerHolger Schemel <info@artsoft.org>
Sun, 18 Feb 2024 14:57:41 +0000 (15:57 +0100)
src/files.c
src/game_bd/export_bd.h
src/game_bd/main_bd.c

index ae0dbf7dc053f11ad0c966185bc2b0115227c2d7..c56fc69ee741c145fbaabe22b397042150011dc9 100644 (file)
@@ -3657,17 +3657,60 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
 static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level)
 {
   struct LevelInfo_BD *level_bd = level->native_bd_level;
+  GdCave *cave = NULL; // will be changed below
+  int cave_w = MIN(level->fieldx, MAX_PLAYFIELD_WIDTH);
+  int cave_h = MIN(level->fieldy, MAX_PLAYFIELD_HEIGHT);
+  int i, x, y;
+
+  setLevelInfoToDefaults_BD_Ext(cave_w, cave_h);
+
+  // cave and map newly allocated when set to defaults above
+  cave = level_bd->cave;
+
+  for (i = 0; i < 5; i++)
+  {
+    cave->level_time[i]                        = level->time;
+    cave->level_diamonds[i]            = level->gems_needed;
+    cave->level_magic_wall_time[i]     = level->time_magic_wall;
+    cave->level_timevalue[i]           = level->score[SC_TIME_BONUS];
+  }
+
+  cave->diamond_value                  = level->score[SC_DIAMOND];
+  cave->extra_diamond_value            = level->score[SC_DIAMOND];
+
+  cave->level_speed[0]                 = 160;  // set cave speed
 
-  level_bd->width  = MIN(level->fieldx, MAX_PLAYFIELD_WIDTH);
-  level_bd->height = MIN(level->fieldy, MAX_PLAYFIELD_HEIGHT);
+  strncpy(cave->name, level->name, sizeof(GdString));
+  cave->name[sizeof(GdString) - 1] = '\0';
+
+  for (x = 0; x < cave->w; x++)
+    for (y = 0; y < cave->h; y++)
+      cave->map[y][x] = map_element_RND_to_BD(level->field[x][y]);
 }
 
 static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level)
 {
   struct LevelInfo_BD *level_bd = level->native_bd_level;
+  GdCave *cave = level_bd->cave;
+  int bd_level_nr = level_bd->level_nr;
+  int x, y;
+
+  level->fieldx = MIN(cave->w, MAX_LEV_FIELDX);
+  level->fieldy = MIN(cave->h, MAX_LEV_FIELDY);
+
+  level->time                  = cave->level_time[bd_level_nr];
+  level->gems_needed           = cave->level_diamonds[bd_level_nr];
+  level->time_magic_wall       = cave->level_magic_wall_time[bd_level_nr];
 
-  level->fieldx = MIN(level_bd->width,  MAX_LEV_FIELDX);
-  level->fieldy = MIN(level_bd->height, MAX_LEV_FIELDY);
+  level->score[SC_TIME_BONUS]  = cave->level_timevalue[bd_level_nr];
+  level->score[SC_DIAMOND]     = cave->diamond_value;
+
+  strncpy(level->name, cave->name, MAX_LEVEL_NAME_LEN);
+  level->name[MAX_LEVEL_NAME_LEN] = '\0';
+
+  for (x = 0; x < level->fieldx; x++)
+    for (y = 0; y < level->fieldy; y++)
+      level->field[x][y] = map_element_BD_to_RND(cave->map[y][x]);
 }
 
 
index 069c10a304a44f9d4dcc0e8126e09b6424c067cf..eaf511f629b6c3b71ece7e1e354a2ef26009ec42 100644 (file)
@@ -45,10 +45,13 @@ struct GameInfo_BD
 
 struct LevelInfo_BD
 {
-  int width;
-  int height;
+  GdCave *cave;
+  GdReplay *replay;
 
-  int cave[BD_MAX_CAVE_WIDTH][BD_MAX_CAVE_HEIGHT];
+  int cave_nr;
+  int level_nr;
+
+  boolean loaded_from_caveset;
 };
 
 struct EngineSnapshotInfo_BD
@@ -64,6 +67,7 @@ extern struct GameInfo_BD game_bd;
 extern struct LevelInfo_BD native_bd_level;
 extern struct EngineSnapshotInfo_BD engine_snapshot_bd;
 
+void setLevelInfoToDefaults_BD_Ext(int, int);
 void setLevelInfoToDefaults_BD(void);
 
 #endif // EXPORT_BD_H
index f76098910fffb1a92ca161d57744121202e2f047..1c18117bd42c79882f09eef6f76bef346e856d28 100644 (file)
@@ -21,7 +21,12 @@ struct EngineSnapshotInfo_BD engine_snapshot_bd;
 // level file functions
 // ============================================================================
 
-void setLevelInfoToDefaults_BD(void)
+void setLevelInfoToDefaults_BD_Ext(int width, int height)
 {
   // ...
 }
+
+void setLevelInfoToDefaults_BD(void)
+{
+  setLevelInfoToDefaults_BD_Ext(0, 0);
+}