From d4c19f2f629758803f62f52809c889052ddf3ccf Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 20 Mar 2020 02:01:20 +0100 Subject: [PATCH] added option to swap game elements in EM caves using V5/V6 EMC graphics When having EMC level sets with EMC graphics that were originally played with the EMC player program, but that have cave files in old cave file format, setting "use_emc_tiles" to "true" causes certain game elements to be swapped just like when loading cave files with new EMC file format (version V5 or V6), like swapping dirt and grass and some wall elements. This is a level set option, not a graphics set option, so it is still possible to override graphics for classic style EM level sets with modern EMC graphics without game elements being changed (so dirt does not change to grass in this case). --- src/engines.h | 1 + src/game_em/reademc.c | 30 +++++++++++++++++++++++++++++- src/libgame/setup.c | 12 ++++++++++-- src/libgame/system.h | 2 ++ src/tools.c | 5 +++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/engines.h b/src/engines.h index f5186855..6a6dd4a7 100644 --- a/src/engines.h +++ b/src/engines.h @@ -27,6 +27,7 @@ void UpdateEngineValues(int, int, int, int); +boolean swapTiles_EM(boolean); boolean getTeamMode_EM(void); boolean isActivePlayer_EM(int); diff --git a/src/game_em/reademc.c b/src/game_em/reademc.c index a8449a04..3f366227 100644 --- a/src/game_em/reademc.c +++ b/src/game_em/reademc.c @@ -42,7 +42,7 @@ #define GET_BE16(x) ((&x)[0] << 8 | (&x)[1]) -static const short map_emc[256] = +static const short map_emc_raw[256] = { Cstone, Cstone, Cdiamond, Cdiamond, // 0 Calien, Calien, Cpause, Cpause, // 4 @@ -113,6 +113,21 @@ static const short map_emc[256] = Cwall_1, Cblank, Calpha_copyr, Cfake_acid_1 // 252 }; +static const short swap_emc[CAVE_TILE_MAX] = +{ + [Cdirt] = Cgrass, + [Cgrass] = Cdirt, + + [Csteel_1] = Csteel_2, + [Csteel_2] = Csteel_1, + + [Cwall_1] = Cwall_2, + [Cwall_2] = Cwall_1, + + [Croundwall_1] = Croundwall_2, + [Croundwall_2] = Croundwall_1 +}; + static struct { int bit_nr; @@ -256,6 +271,19 @@ static int eater_offset[8] = void convert_em_level(unsigned char *src, int file_version) { int i, x, y, temp; + short map_emc[256]; + + /* initialize element mapping */ + + for (i = 0; i < 256; i++) + map_emc[i] = map_emc_raw[i]; + + /* swap tiles for pre-EMC caves (older than V5/V6), if needed */ + + if (swapTiles_EM(file_version < FILE_VERSION_EM_V5)) + for (i = 0; i < 256; i++) + if (swap_emc[map_emc[i]] != 0) + map_emc[i] = swap_emc[map_emc[i]]; /* common to all emc caves */ diff --git a/src/libgame/setup.c b/src/libgame/setup.c index db428ad5..300e815d 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -2321,8 +2321,9 @@ SetupFileHash *loadSetupFileHash(char *filename) #define LEVELINFO_TOKEN_SPECIAL_FLAGS 24 #define LEVELINFO_TOKEN_HANDICAP 25 #define LEVELINFO_TOKEN_SKIP_LEVELS 26 +#define LEVELINFO_TOKEN_USE_EMC_TILES 27 -#define NUM_LEVELINFO_TOKENS 27 +#define NUM_LEVELINFO_TOKENS 28 static LevelDirTree ldi; @@ -2355,7 +2356,8 @@ static struct TokenInfo levelinfo_tokens[] = { TYPE_STRING, &ldi.level_filetype, "filetype" }, { TYPE_STRING, &ldi.special_flags, "special_flags" }, { TYPE_BOOLEAN, &ldi.handicap, "handicap" }, - { TYPE_BOOLEAN, &ldi.skip_levels, "skip_levels" } + { TYPE_BOOLEAN, &ldi.skip_levels, "skip_levels" }, + { TYPE_BOOLEAN, &ldi.use_emc_tiles, "use_emc_tiles" } }; static struct TokenInfo artworkinfo_tokens[] = @@ -2447,6 +2449,8 @@ static void setTreeInfoToDefaults(TreeInfo *ti, int type) ti->readonly = TRUE; ti->handicap = TRUE; ti->skip_levels = FALSE; + + ti->use_emc_tiles = FALSE; } } @@ -2524,6 +2528,8 @@ static void setTreeInfoToDefaultsFromParent(TreeInfo *ti, TreeInfo *parent) ti->readonly = parent->readonly; ti->handicap = parent->handicap; ti->skip_levels = parent->skip_levels; + + ti->use_emc_tiles = parent->use_emc_tiles; } } @@ -2589,6 +2595,8 @@ static TreeInfo *getTreeInfoCopy(TreeInfo *ti) ti_copy->handicap = ti->handicap; ti_copy->skip_levels = ti->skip_levels; + ti_copy->use_emc_tiles = ti->use_emc_tiles; + ti_copy->color = ti->color; ti_copy->class_desc = getStringCopy(ti->class_desc); ti_copy->handicap_level = ti->handicap_level; diff --git a/src/libgame/system.h b/src/libgame/system.h index d9c1b002..a949914e 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1479,6 +1479,8 @@ struct TreeInfo boolean handicap; // level set has no handicap when set to "false" boolean skip_levels; // levels can be skipped when set to "true" + boolean use_emc_tiles;// use (swapped) V5/V6 EMC tiles when set to "true" + int color; // color to use on selection screen for this level char *class_desc; // description of level series class int handicap_level; // number of the lowest unsolved level diff --git a/src/tools.c b/src/tools.c index d358aed5..67bb1795 100644 --- a/src/tools.c +++ b/src/tools.c @@ -8267,6 +8267,11 @@ int getBeltSwitchElementFromBeltNrAndBeltDir(int belt_nr, int belt_dir) return getBeltSwitchElementFromBeltNrAndBeltDirNr(belt_nr, belt_dir_nr); } +boolean swapTiles_EM(boolean is_pre_emc_cave) +{ + return is_pre_emc_cave && leveldir_current->use_emc_tiles; +} + boolean getTeamMode_EM(void) { return game.team_mode || network_playing; -- 2.34.1