From b7405ce411200d7f0ed642d3178ef773ff88d2b7 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 23 Dec 2023 14:02:51 +0100 Subject: [PATCH] added more support for native Boulder Dash game engine code --- src/editor.c | 23 ++++++++++++++++++++++- src/files.c | 29 +++++++++++++++++++++++++++-- src/game_bd/export.h | 15 ++++++++++++++- src/main.h | 1 + 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/editor.c b/src/editor.c index 671ac61d..5160b02f 100644 --- a/src/editor.c +++ b/src/editor.c @@ -5859,6 +5859,22 @@ static void ReinitializeElementList_EnableSections(void) setup_editor_el_mirror_magic = FALSE; setup_editor_el_deflektor = FALSE; } + else if (level.game_engine_type == GAME_ENGINE_TYPE_BD) + { + setup_editor_el_emerald_mine = FALSE; + setup_editor_el_emerald_mine_club = FALSE; + setup_editor_el_more = FALSE; + setup_editor_el_sokoban = FALSE; + setup_editor_el_supaplex = FALSE; + setup_editor_el_diamond_caves = FALSE; + setup_editor_el_dx_boulderdash = FALSE; + setup_editor_el_mirror_magic = FALSE; + setup_editor_el_deflektor = FALSE; + setup_editor_el_chars = FALSE; + setup_editor_el_steel_chars = FALSE; + + setup_editor_el_custom = FALSE; + } else if (level.game_engine_type == GAME_ENGINE_TYPE_EM) { setup_editor_el_boulderdash = FALSE; @@ -12766,6 +12782,7 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, lev_fieldx = level.fieldx = brush_width; lev_fieldy = level.fieldy = brush_height; + boolean use_bd_engine = TRUE; boolean use_em_engine = TRUE; boolean use_sp_engine = TRUE; boolean use_mm_engine = TRUE; @@ -12776,6 +12793,9 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, { int element = Tile[x][y]; + if (!IS_BD_ELEMENT(element) && !IS_PLAYER_ELEMENT(element)) + use_bd_engine = FALSE; + if (!IS_EM_ELEMENT(element) && !IS_PLAYER_ELEMENT(element)) use_em_engine = FALSE; @@ -12787,7 +12807,8 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, } } - level.game_engine_type = (use_em_engine ? GAME_ENGINE_TYPE_EM : + level.game_engine_type = (use_bd_engine ? GAME_ENGINE_TYPE_BD : + use_em_engine ? GAME_ENGINE_TYPE_EM : use_sp_engine ? GAME_ENGINE_TYPE_SP : use_mm_engine ? GAME_ENGINE_TYPE_MM : GAME_ENGINE_TYPE_RND); diff --git a/src/files.c b/src/files.c index 3480ed74..994d854d 100644 --- a/src/files.c +++ b/src/files.c @@ -3650,6 +3650,27 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, } +// ---------------------------------------------------------------------------- +// functions for loading BD level +// ---------------------------------------------------------------------------- + +static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level) +{ + struct LevelInfo_BD *level_bd = level->native_bd_level; + + level_bd->width = MIN(level->fieldx, MAX_PLAYFIELD_WIDTH); + level_bd->height = MIN(level->fieldy, MAX_PLAYFIELD_HEIGHT); +} + +static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level) +{ + struct LevelInfo_BD *level_bd = level->native_bd_level; + + level->fieldx = MIN(level_bd->width, MAX_LEV_FIELDX); + level->fieldy = MIN(level_bd->height, MAX_LEV_FIELDY); +} + + // ---------------------------------------------------------------------------- // functions for loading EM level // ---------------------------------------------------------------------------- @@ -6323,7 +6344,9 @@ static void LoadLevelFromFileInfo_MM(struct LevelInfo *level, void CopyNativeLevel_RND_to_Native(struct LevelInfo *level) { - if (level->game_engine_type == GAME_ENGINE_TYPE_EM) + if (level->game_engine_type == GAME_ENGINE_TYPE_BD) + CopyNativeLevel_RND_to_BD(level); + else if (level->game_engine_type == GAME_ENGINE_TYPE_EM) CopyNativeLevel_RND_to_EM(level); else if (level->game_engine_type == GAME_ENGINE_TYPE_SP) CopyNativeLevel_RND_to_SP(level); @@ -6333,7 +6356,9 @@ void CopyNativeLevel_RND_to_Native(struct LevelInfo *level) void CopyNativeLevel_Native_to_RND(struct LevelInfo *level) { - if (level->game_engine_type == GAME_ENGINE_TYPE_EM) + if (level->game_engine_type == GAME_ENGINE_TYPE_BD) + CopyNativeLevel_BD_to_RND(level); + else if (level->game_engine_type == GAME_ENGINE_TYPE_EM) CopyNativeLevel_EM_to_RND(level); else if (level->game_engine_type == GAME_ENGINE_TYPE_SP) CopyNativeLevel_SP_to_RND(level); diff --git a/src/game_bd/export.h b/src/game_bd/export.h index 54a85d5a..07d3ff3f 100644 --- a/src/game_bd/export.h +++ b/src/game_bd/export.h @@ -5,11 +5,13 @@ // functions and definitions exported from game_bd to main program // ============================================================================ + // ---------------------------------------------------------------------------- // constant definitions // ---------------------------------------------------------------------------- -// ... +#define BD_MAX_CAVE_WIDTH MAX_PLAYFIELD_WIDTH +#define BD_MAX_CAVE_HEIGHT MAX_PLAYFIELD_HEIGHT // ---------------------------------------------------------------------------- @@ -18,10 +20,21 @@ struct GameInfo_BD { + boolean level_solved; + boolean game_over; + + // needed for updating panel + int time_played; + int gems_still_needed; + int score; }; struct LevelInfo_BD { + int width; + int height; + + int cave[BD_MAX_CAVE_WIDTH][BD_MAX_CAVE_HEIGHT]; }; struct EngineSnapshotInfo_BD diff --git a/src/main.h b/src/main.h index 91c9e81a..497a9a76 100644 --- a/src/main.h +++ b/src/main.h @@ -21,6 +21,7 @@ #include #include "libgame/libgame.h" +#include "game_bd/game_bd.h" #include "game_em/game_em.h" #include "game_sp/game_sp.h" #include "game_mm/game_mm.h" -- 2.34.1