From a5f7c1f3ea5e23a74821572d1b90dc15c787db2a Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 24 Sep 2024 23:49:04 +0200 Subject: [PATCH] added using new method to convert slime permeability for new BD engine --- src/game_bd/bd_c64import.c | 29 +++++++++++++++++++++++++---- src/game_bd/bd_cave.h | 1 + src/game_bd/bd_cavedb.c | 1 + src/game_bd/bd_caveobject.c | 5 +++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/game_bd/bd_c64import.c b/src/game_bd/bd_c64import.c index faaa8d50..47c0f16d 100644 --- a/src/game_bd/bd_c64import.c +++ b/src/game_bd/bd_c64import.c @@ -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]; diff --git a/src/game_bd/bd_cave.h b/src/game_bd/bd_cave.h index 42a31d3a..b5ca6391 100644 --- a/src/game_bd/bd_cave.h +++ b/src/game_bd/bd_cave.h @@ -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 diff --git a/src/game_bd/bd_cavedb.c b/src/game_bd/bd_cavedb.c index 1fd326ab..e328b9d7 100644 --- a/src/game_bd/bd_cavedb.c +++ b/src/game_bd/bd_cavedb.c @@ -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 }, diff --git a/src/game_bd/bd_caveobject.c b/src/game_bd/bd_caveobject.c index 25de6c5e..5f6c9818 100644 --- a/src/game_bd/bd_caveobject.c +++ b/src/game_bd/bd_caveobject.c @@ -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. -- 2.34.1