From: Holger Schemel Date: Sat, 24 Oct 2020 00:50:36 +0000 (+0200) Subject: improved inserting level sketch from clipboard to level editor X-Git-Tag: 4.2.0.4~8 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=def07be5d5db9eaa30453b67b0ad591100f8fed5;p=rocksndiamonds.git improved inserting level sketch from clipboard to level editor When pasting a level sketch to the level editor that has been copied from the R'n'D forum, obsolete (historic) game elements will be mapped to their current counterparts (just like it is done when loading an old R'n'D level file). In addition, the corresponding game engine is auto-detected (if possible) and set accordingly. --- diff --git a/src/editor.c b/src/editor.c index b7b739f5..acd199d5 100644 --- a/src/editor.c +++ b/src/editor.c @@ -12162,6 +12162,9 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, ptr++; } + // remap some (historic, now obsolete) elements + element = getMappedElement(element); + if (element >= NUM_FILE_ELEMENTS) element = EL_UNKNOWN; @@ -12237,6 +12240,36 @@ 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_em_engine = TRUE; + boolean use_sp_engine = TRUE; + boolean use_mm_engine = TRUE; + + for (x = 0; x < MAX_LEV_FIELDX; x++) + { + for (y = 0; y < MAX_LEV_FIELDY; y++) + { + int element = Tile[x][y]; + + if (!IS_EM_ELEMENT(element) && !ELEM_IS_PLAYER(element)) + use_em_engine = FALSE; + + if (!IS_SP_ELEMENT(element)) + use_sp_engine = FALSE; + + if (!IS_MM_ELEMENT(element) && element != EL_EMPTY) + use_mm_engine = FALSE; + } + } + + level.game_engine_type = (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); + + // update element selection list + ReinitializeElementList(); + ModifyEditorElementList(); + SetBorderElement(); DrawEditModeWindow(); diff --git a/src/files.c b/src/files.c index 706b819e..13deca88 100644 --- a/src/files.c +++ b/src/files.c @@ -2334,7 +2334,7 @@ static void copyLevelFileInfo(struct LevelFileInfo *lfi_from, // functions for loading R'n'D level // ---------------------------------------------------------------------------- -static int getMappedElement(int element) +int getMappedElement(int element) { // remap some (historic, now obsolete) elements diff --git a/src/files.h b/src/files.h index ca331ad7..e324404b 100644 --- a/src/files.h +++ b/src/files.h @@ -33,6 +33,8 @@ char *getDefaultLevelFilename(int); char *getLocalLevelTemplateFilename(void); char *getGlobalLevelTemplateFilename(void); +int getMappedElement(int); + void LoadLevelFromFilename(struct LevelInfo *, char *); void LoadLevel(int); void LoadLevelTemplate(int); diff --git a/src/main.h b/src/main.h index 9837ffdd..a10e6468 100644 --- a/src/main.h +++ b/src/main.h @@ -808,6 +808,9 @@ #define IS_DC_STEELWALL_2(e) ((e) >= EL_DC_STEELWALL_2_LEFT && \ (e) <= EL_DC_STEELWALL_2_SINGLE) +// !!! IMPROVE THIS !!! +#define IS_EM_ELEMENT(e) (map_element_EM_to_RND_cave(map_element_RND_to_EM_cave(e)) == (e)) + #define MM_WALL_BASE(e) ((e) & 0xfff0) #define MM_WALL_BITS(e) ((e) & 0x000f)