added using new method to convert slime permeability for new BD engine
authorHolger Schemel <holger.schemel@virtion.de>
Tue, 24 Sep 2024 21:49:04 +0000 (23:49 +0200)
committerHolger Schemel <holger.schemel@virtion.de>
Wed, 25 Sep 2024 07:40:33 +0000 (09:40 +0200)
src/game_bd/bd_c64import.c
src/game_bd/bd_cave.h
src/game_bd/bd_cavedb.c
src/game_bd/bd_caveobject.c

index faaa8d50adea331a81e4bacef75acbd4e8c6a2ee..47c0f16dbdaa788501d555d8db35d8c0722c89a1 100644 (file)
@@ -489,8 +489,27 @@ static const char *gd_engines[] =
   "CrLi"
 };
 
-// to convert predictable slime values to bit masks
-static int slime_shift_msb(int c64_data)
+// Take a slime predictability byte, and convert it to a bitmask.
+// Used for caves created with the original construction kit.
+// (This conversion method is used by the new game engine.)
+static int slime_plck_new(int c64_data)
+{
+  const int values[] = { 0x00, 0x10, 0x18, 0x38, 0x3c, 0x7c, 0x7e, 0xfe, 0xff };
+
+  if (c64_data > ARRAY_SIZE(values))
+  {
+    Warn("Invalid PLCK slime permeability value %x", c64_data);
+
+    return 0xff;
+  }
+
+  return values[c64_data];
+}
+
+// Take a slime predictability byte, and convert it to a bitmask.
+// Used for caves created with the original construction kit.
+// (This conversion method was used by the old game engine.)
+static int slime_plck_old(int c64_data)
 {
   int i, perm;
 
@@ -1281,7 +1300,8 @@ static int cave_copy_from_plck(GdCave *cave, const byte *data,
 
     cave->level_ckdelay[i] = data[0x1b8];
     cave->level_magic_wall_time[i] = data[0x1c6];
-    cave->level_slime_permeability_c64[i] = slime_shift_msb(data[0x1c2]);
+    cave->level_slime_permeability_c64[i] = slime_plck_new(data[0x1c2]);
+    cave->level_slime_permeability_old[i] = slime_plck_old(data[0x1c2]);
   }
 
   if (format == GD_FORMAT_PLC_ATARI)
@@ -1403,7 +1423,8 @@ static int cave_copy_from_dlb(GdCave *cave, const byte *data, int remaining_byte
       cave->level_amoeba_time[i] = 999;
 
     cave->level_magic_wall_time[i] = data[7];
-    cave->level_slime_permeability_c64[i] = slime_shift_msb(data[5]);
+    cave->level_slime_permeability_c64[i] = slime_plck_new(data[5]);
+    cave->level_slime_permeability_old[i] = slime_plck_old(data[5]);
   }
 
   cave->diamond_value = data[3];
index 42a31d3a114abc18e5f77d6cc44c7f2963288341..b5ca6391cb692712ae8138905e69b5758e43743b 100644 (file)
@@ -454,6 +454,7 @@ typedef struct _gd_cave
 
   int level_slime_permeability[5];      // true random slime
   int level_slime_permeability_c64[5];  // Appearing in bd 2
+  int level_slime_permeability_old[5];  // Appearing in bd 2 (only used by old engine)
   int level_slime_seed_c64[5];          // predictable slime random seed
   boolean slime_predictable;            // predictable random start for slime. yes for plck.
   boolean slime_correct_random;         // correct random number generator for rendered caves
index 1fd326ab270bc06d39e4dc55a58772da33e0bf28..e328b9d7879d3ec1f0d3fb711bd15755ad66d8a5 100644 (file)
@@ -3162,6 +3162,7 @@ GdPropertyDefault gd_cave_defaults_gdash[] =
   { CAVE_OFFSET(slime_predictable),                            TRUE                            },
   { CAVE_OFFSET(level_slime_seed_c64),                         -1                              },
   { CAVE_OFFSET(level_slime_permeability_c64),                 0                               },
+  { CAVE_OFFSET(level_slime_permeability_old),                 0                               },
   { CAVE_OFFSET(level_slime_permeability),                     1000000                         },
   { CAVE_OFFSET(slime_eats_1),                                 O_DIAMOND                       },
   { CAVE_OFFSET(slime_converts_1),                             O_DIAMOND_F                     },
index 25de6c5e69ea342ca31fd2d63d59c9b382718433..5f6c9818a22680aba2fb607f174c6e6b87d90384 100644 (file)
@@ -1458,6 +1458,11 @@ GdCave *gd_cave_new_rendered(const GdCave *data, const int level, const unsigned
   cave->hatching_delay_time    = data->level_hatching_delay_time[level];
   cave->hatching_delay_frame   = data->level_hatching_delay_frame[level];
 
+  // if using old game engine and old slime permeability value is defined, use that
+  if (game_bd.game != NULL && game_bd.game->use_old_engine &&
+      data->level_slime_permeability_old[level] != 0)
+    cave->slime_permeability_c64 = data->level_slime_permeability_old[level];
+
   if (!cave->map)
   {
     // if we have no map, fill with predictable random generator.