added option to swap game elements in EM caves using V5/V6 EMC graphics
authorHolger Schemel <info@artsoft.org>
Fri, 20 Mar 2020 01:01:20 +0000 (02:01 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 19 May 2020 16:20:01 +0000 (18:20 +0200)
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
src/game_em/reademc.c
src/libgame/setup.c
src/libgame/system.h
src/tools.c

index f51868556b3ae5408930c1d59d91a2f3f42a5135..6a6dd4a73b9bd1cca0ca7c6dc62a4807597d2c77 100644 (file)
@@ -27,6 +27,7 @@
 
 void UpdateEngineValues(int, int, int, int);
 
+boolean swapTiles_EM(boolean);
 boolean getTeamMode_EM(void);
 boolean isActivePlayer_EM(int);
 
index a8449a04dd4113b1ffb03b1bcc3498e2e3f4d62c..3f366227a6785c7d0cee3010ac22f8c723c66209 100644 (file)
@@ -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 */
 
index db428ad5248b8afc6b029dbf27960efc79e7a388..300e815d919e6f20e40ecd1f9c6bb99659ed2f77 100644 (file)
@@ -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;
index d9c1b002be000dcaaefd3ce61c451eaebc35d66c..a949914ee1cbb900faa42aab4e71da903d54fa1a 100644 (file)
@@ -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
index d358aed5203ec88473f5668dc6e45c16656c804b..67bb1795a766b963738122a3bf1d9c96fe172b9d 100644 (file)
@@ -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;