From 5bb4dba95d27f31aaa4a060c0efef70c671ebd7e Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 11 Feb 2024 02:54:51 +0100 Subject: [PATCH] added code to convert native Boulder Dash levels --- src/files.c | 51 +++++++++++++++++++++++++++++++++++++---- src/game_bd/export_bd.h | 10 +++++--- src/game_bd/main_bd.c | 7 +++++- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/files.c b/src/files.c index ae0dbf7d..c56fc69e 100644 --- a/src/files.c +++ b/src/files.c @@ -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]); } diff --git a/src/game_bd/export_bd.h b/src/game_bd/export_bd.h index 069c10a3..eaf511f6 100644 --- a/src/game_bd/export_bd.h +++ b/src/game_bd/export_bd.h @@ -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 diff --git a/src/game_bd/main_bd.c b/src/game_bd/main_bd.c index f7609891..1c18117b 100644 --- a/src/game_bd/main_bd.c +++ b/src/game_bd/main_bd.c @@ -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); +} -- 2.34.1