From: Holger Schemel Date: Sun, 11 Feb 2024 12:28:21 +0000 (+0100) Subject: added code to load native Boulder Dash levels X-Git-Tag: 4.4.0.0-test-1~391 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=6e1c81b564b748d54aadb2a79235c8fbe3483677;p=rocksndiamonds.git added code to load native Boulder Dash levels --- diff --git a/src/editor.c b/src/editor.c index 3bed979d..8fa52676 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1794,6 +1794,7 @@ static struct ValueTextInfo options_time_score_base[] = static struct ValueTextInfo options_game_engine_type[] = { { GAME_ENGINE_TYPE_RND, "Rocks'n'Diamonds" }, + { GAME_ENGINE_TYPE_BD, "Boulder Dash" }, { GAME_ENGINE_TYPE_EM, "Emerald Mine" }, { GAME_ENGINE_TYPE_SP, "Supaplex" }, { GAME_ENGINE_TYPE_MM, "Mirror Magic" }, diff --git a/src/files.c b/src/files.c index 269a749b..b3ef9a7e 100644 --- a/src/files.c +++ b/src/files.c @@ -2101,6 +2101,13 @@ static int getFileTypeFromBasename(char *basename) strchr(basename, '%') == NULL) return LEVEL_FILE_TYPE_SB; + // check for typical filename of a Boulder Dash (GDash) level package file + if (strSuffixLower(basename, ".bd") || + strSuffixLower(basename, ".bdr") || + strSuffixLower(basename, ".brc") || + strSuffixLower(basename, ".gds")) + return LEVEL_FILE_TYPE_BD; + // ---------- try to determine file type from filesize ---------- checked_free(filename); @@ -6419,6 +6426,20 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, // functions for handling native levels // ------------------------------------------------------------------------- +static void LoadLevelFromFileInfo_BD(struct LevelInfo *level, + struct LevelFileInfo *level_file_info, + boolean level_info_only) +{ + int pos = 0; + + // determine position of requested level inside level package + if (level_file_info->packed) + pos = level_file_info->nr - leveldir_current->first_level; + + if (!LoadNativeLevel_BD(level_file_info->filename, pos, level_info_only)) + level->no_valid_file = TRUE; +} + static void LoadLevelFromFileInfo_EM(struct LevelInfo *level, struct LevelFileInfo *level_file_info, boolean level_info_only) @@ -6505,6 +6526,11 @@ static void LoadLevelFromFileInfo(struct LevelInfo *level, LoadLevelFromFileInfo_RND(level, level_file_info, level_info_only); break; + case LEVEL_FILE_TYPE_BD: + LoadLevelFromFileInfo_BD(level, level_file_info, level_info_only); + level->game_engine_type = GAME_ENGINE_TYPE_BD; + break; + case LEVEL_FILE_TYPE_EM: LoadLevelFromFileInfo_EM(level, level_file_info, level_info_only); level->game_engine_type = GAME_ENGINE_TYPE_EM; diff --git a/src/game_bd/export_bd.h b/src/game_bd/export_bd.h index 5545490b..c0e4d0a3 100644 --- a/src/game_bd/export_bd.h +++ b/src/game_bd/export_bd.h @@ -88,5 +88,6 @@ boolean checkGameRunning_BD(void); void setLevelInfoToDefaults_BD_Ext(int, int); void setLevelInfoToDefaults_BD(void); +boolean LoadNativeLevel_BD(char *, int, boolean); #endif // EXPORT_BD_H diff --git a/src/game_bd/main_bd.c b/src/game_bd/main_bd.c index 646927fa..efaa78f4 100644 --- a/src/game_bd/main_bd.c +++ b/src/game_bd/main_bd.c @@ -57,10 +57,95 @@ boolean checkGameRunning_BD(void) void setLevelInfoToDefaults_BD_Ext(int width, int height) { - // ... + GdCave *cave = native_bd_level.cave; + + if (cave != NULL) + gd_cave_free(cave); + + // get empty cave, using default values + cave = gd_cave_new(); + + // set cave size, if defined + if (width > 0 && height > 0) + { + cave->w = width; + cave->h = height; + } + + gd_flatten_cave(cave, 0); + + cave->selectable = TRUE; + cave->intermission = FALSE; + + native_bd_level.cave = cave; + native_bd_level.replay = NULL; + + native_bd_level.cave_nr = 0; + native_bd_level.level_nr = 0; + + native_bd_level.loaded_from_caveset = FALSE; } void setLevelInfoToDefaults_BD(void) { setLevelInfoToDefaults_BD_Ext(0, 0); } + +boolean LoadNativeLevel_BD(char *filename, int level_pos, boolean level_info_only) +{ + static char *filename_loaded = NULL; + + if (filename_loaded == NULL || !strEqual(filename, filename_loaded)) + { + if (!gd_caveset_load_from_file(filename)) + { + if (!level_info_only) + Warn("cannot load BD cave set from file '%s'", filename); + + return FALSE; + } + + setString(&filename_loaded, filename); + } + + if (level_pos < 0 || level_pos >= 5 * gd_caveset_count()) + { + Warn("invalid level position %d in BD cave set", level_pos); + + return FALSE; + } + + native_bd_level.cave_nr = level_pos % gd_caveset_count(); + native_bd_level.level_nr = level_pos / gd_caveset_count(); + + if (native_bd_level.cave != NULL) + gd_cave_free(native_bd_level.cave); + + // get selected cave, prepared for playing + native_bd_level.cave = gd_get_prepared_cave_from_caveset(native_bd_level.cave_nr, + native_bd_level.level_nr); + + // set better initial cave speed (to set better native replay tape length) + set_initial_cave_speed(native_bd_level.cave); + + native_bd_level.loaded_from_caveset = TRUE; + + // check if this cave has any replays + if (native_bd_level.cave->replays != NULL) + { + GList *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; + + // matching replay found + if (item != NULL) + native_bd_level.replay = (GdReplay *)item->data; + } + + return TRUE; +}