From: Holger Schemel Date: Sat, 23 Mar 2024 14:04:26 +0000 (+0100) Subject: extended functions to map between R'n'D and BD cave and game elements X-Git-Tag: 4.4.0.0-test-1~161 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=45befdabd623ea1d67a3db27de22f63cb7156f72;p=rocksndiamonds.git extended functions to map between R'n'D and BD cave and game elements --- diff --git a/src/files.c b/src/files.c index 8197672a..9fcc9e40 100644 --- a/src/files.c +++ b/src/files.c @@ -4024,7 +4024,7 @@ static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level) cave->pushing_stone_prob = level->bd_pushing_prob * 10000; cave->pushing_stone_prob_sweet = level->bd_pushing_prob_with_sweet * 10000; cave->mega_stones_pushable_with_sweet = level->bd_push_mega_rock_with_sweet; - cave->snap_element = map_element_RND_to_BD(level->bd_snap_element); + cave->snap_element = map_element_RND_to_BD_cave(level->bd_snap_element); // element properties cave->level_bonus_time[0] = level->bd_clock_extra_time; @@ -4048,12 +4048,12 @@ static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level) cave->amoeba_2_growth_prob = level->bd_amoeba_2_slow_growth_rate * 10000; cave->amoeba_2_fast_growth_prob = level->bd_amoeba_2_fast_growth_rate * 10000; - cave->amoeba_too_big_effect = map_element_RND_to_BD(level->bd_amoeba_content_too_big); - cave->amoeba_enclosed_effect = map_element_RND_to_BD(level->bd_amoeba_content_enclosed); - cave->amoeba_2_too_big_effect = map_element_RND_to_BD(level->bd_amoeba_2_content_too_big); - cave->amoeba_2_enclosed_effect = map_element_RND_to_BD(level->bd_amoeba_2_content_enclosed); - cave->amoeba_2_explosion_effect = map_element_RND_to_BD(level->bd_amoeba_2_content_exploding); - cave->amoeba_2_looks_like = map_element_RND_to_BD(level->bd_amoeba_2_content_looks_like); + cave->amoeba_too_big_effect = map_element_RND_to_BD_cave(level->bd_amoeba_content_too_big); + cave->amoeba_enclosed_effect = map_element_RND_to_BD_cave(level->bd_amoeba_content_enclosed); + cave->amoeba_2_too_big_effect = map_element_RND_to_BD_cave(level->bd_amoeba_2_content_too_big); + cave->amoeba_2_enclosed_effect = map_element_RND_to_BD_cave(level->bd_amoeba_2_content_enclosed); + cave->amoeba_2_explosion_effect = map_element_RND_to_BD_cave(level->bd_amoeba_2_content_exploding); + cave->amoeba_2_looks_like = map_element_RND_to_BD_cave(level->bd_amoeba_2_content_looks_like); cave->slime_predictable = level->bd_slime_is_predictable; cave->slime_correct_random = level->bd_slime_correct_random; @@ -4062,14 +4062,14 @@ static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level) cave->level_slime_seed_c64[0] = level->bd_slime_random_seed_c64; cave->level_rand[0] = level->bd_cave_random_seed_c64; - cave->acid_eats_this = map_element_RND_to_BD(level->bd_acid_eats_element); + cave->acid_eats_this = map_element_RND_to_BD_cave(level->bd_acid_eats_element); cave->acid_spread_ratio = level->bd_acid_spread_rate * 10000; - cave->acid_turns_to = map_element_RND_to_BD(level->bd_acid_turns_to_element); + cave->acid_turns_to = map_element_RND_to_BD_cave(level->bd_acid_turns_to_element); cave->biter_delay_frame = level->bd_biter_move_delay; - cave->biter_eat = map_element_RND_to_BD(level->bd_biter_eats_element); + cave->biter_eat = map_element_RND_to_BD_cave(level->bd_biter_eats_element); - cave->bladder_converts_by = map_element_RND_to_BD(level->bd_bladder_converts_by_element); + cave->bladder_converts_by = map_element_RND_to_BD_cave(level->bd_bladder_converts_by_element); cave->expanding_wall_changed = level->bd_change_expanding_wall; @@ -4088,7 +4088,7 @@ static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level) // playfield elements for (x = 0; x < cave->w; x++) for (y = 0; y < cave->h; y++) - cave->map[y][x] = map_element_RND_to_BD(level->field[x][y]); + cave->map[y][x] = map_element_RND_to_BD_cave(level->field[x][y]); } static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level) @@ -4133,7 +4133,7 @@ static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level) level->bd_pushing_prob = cave->pushing_stone_prob / 10000; level->bd_pushing_prob_with_sweet = cave->pushing_stone_prob_sweet / 10000; level->bd_push_mega_rock_with_sweet = cave->mega_stones_pushable_with_sweet; - level->bd_snap_element = map_element_BD_to_RND(cave->snap_element); + level->bd_snap_element = map_element_BD_to_RND_cave(cave->snap_element); // element properties level->bd_clock_extra_time = cave->level_bonus_time[bd_level_nr]; @@ -4157,12 +4157,12 @@ static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level) level->bd_amoeba_2_slow_growth_rate = cave->amoeba_2_growth_prob / 10000; level->bd_amoeba_2_fast_growth_rate = cave->amoeba_2_fast_growth_prob / 10000; - level->bd_amoeba_content_too_big = map_element_BD_to_RND(cave->amoeba_too_big_effect); - level->bd_amoeba_content_enclosed = map_element_BD_to_RND(cave->amoeba_enclosed_effect); - level->bd_amoeba_2_content_too_big = map_element_BD_to_RND(cave->amoeba_2_too_big_effect); - level->bd_amoeba_2_content_enclosed = map_element_BD_to_RND(cave->amoeba_2_enclosed_effect); - level->bd_amoeba_2_content_exploding = map_element_BD_to_RND(cave->amoeba_2_explosion_effect); - level->bd_amoeba_2_content_looks_like = map_element_BD_to_RND(cave->amoeba_2_looks_like); + level->bd_amoeba_content_too_big = map_element_BD_to_RND_cave(cave->amoeba_too_big_effect); + level->bd_amoeba_content_enclosed = map_element_BD_to_RND_cave(cave->amoeba_enclosed_effect); + level->bd_amoeba_2_content_too_big = map_element_BD_to_RND_cave(cave->amoeba_2_too_big_effect); + level->bd_amoeba_2_content_enclosed = map_element_BD_to_RND_cave(cave->amoeba_2_enclosed_effect); + level->bd_amoeba_2_content_exploding = map_element_BD_to_RND_cave(cave->amoeba_2_explosion_effect); + level->bd_amoeba_2_content_looks_like = map_element_BD_to_RND_cave(cave->amoeba_2_looks_like); level->bd_slime_is_predictable = cave->slime_predictable; level->bd_slime_correct_random = cave->slime_correct_random; @@ -4171,14 +4171,14 @@ static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level) level->bd_slime_random_seed_c64 = cave->level_slime_seed_c64[bd_level_nr]; level->bd_cave_random_seed_c64 = cave->level_rand[bd_level_nr]; - level->bd_acid_eats_element = map_element_BD_to_RND(cave->acid_eats_this); + level->bd_acid_eats_element = map_element_BD_to_RND_cave(cave->acid_eats_this); level->bd_acid_spread_rate = cave->acid_spread_ratio / 10000; - level->bd_acid_turns_to_element = map_element_BD_to_RND(cave->acid_turns_to); + level->bd_acid_turns_to_element = map_element_BD_to_RND_cave(cave->acid_turns_to); level->bd_biter_move_delay = cave->biter_delay_frame; - level->bd_biter_eats_element = map_element_BD_to_RND(cave->biter_eat); + level->bd_biter_eats_element = map_element_BD_to_RND_cave(cave->biter_eat); - level->bd_bladder_converts_by_element = map_element_BD_to_RND(cave->bladder_converts_by); + level->bd_bladder_converts_by_element = map_element_BD_to_RND_cave(cave->bladder_converts_by); level->bd_change_expanding_wall = cave->expanding_wall_changed; @@ -4199,7 +4199,7 @@ static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level) // playfield elements for (x = 0; x < level->fieldx; x++) for (y = 0; y < level->fieldy; y++) - level->field[x][y] = map_element_BD_to_RND(cave->map[y][x]); + level->field[x][y] = map_element_BD_to_RND_cave(cave->map[y][x]); checked_free(cave_name); } diff --git a/src/game.c b/src/game.c index 9127a1b6..0d5bec36 100644 --- a/src/game.c +++ b/src/game.c @@ -15863,7 +15863,7 @@ static int getSoundEffect_BD(int element_bd, int sample) void PlayLevelSound_BD(int xx, int yy, int element_bd, int sample) { - int element = (element_bd > -1 ? map_element_BD_to_RND(element_bd) : 0); + int element = (element_bd > -1 ? map_element_BD_to_RND_game(element_bd) : 0); int sound_effect = getSoundEffect_BD(element, sample); int sound_action = getSoundAction_BD(sample); boolean is_loop_sound = IS_LOOP_SOUND(sound_effect); @@ -15887,7 +15887,7 @@ void PlayLevelSound_BD(int xx, int yy, int element_bd, int sample) void StopSound_BD(int element_bd, int sample) { - int element = (element_bd > -1 ? map_element_BD_to_RND(element_bd) : 0); + int element = (element_bd > -1 ? map_element_BD_to_RND_game(element_bd) : 0); int sound_effect = getSoundEffect_BD(element, sample); if (sound_effect != SND_UNDEFINED) @@ -15896,7 +15896,7 @@ void StopSound_BD(int element_bd, int sample) boolean isSoundPlaying_BD(int element_bd, int sample) { - int element = (element_bd > -1 ? map_element_BD_to_RND(element_bd) : 0); + int element = (element_bd > -1 ? map_element_BD_to_RND_game(element_bd) : 0); int sound_effect = getSoundEffect_BD(element, sample); if (sound_effect != SND_UNDEFINED) diff --git a/src/tools.c b/src/tools.c index cc08a669..fa991030 100644 --- a/src/tools.c +++ b/src/tools.c @@ -7084,7 +7084,7 @@ bd_object_mapping_list[] = } }; -int map_element_RND_to_BD(int element_rnd) +int map_element_RND_to_BD_cave(int element_rnd) { static unsigned short mapping_RND_to_BD[NUM_FILE_ELEMENTS]; static boolean mapping_initialized = FALSE; @@ -7115,7 +7115,38 @@ int map_element_RND_to_BD(int element_rnd) return mapping_RND_to_BD[element_rnd]; } -int map_element_BD_to_RND(int element_bd) +int map_element_BD_to_RND_cave(int element_bd) +{ + static unsigned short mapping_BD_to_RND[O_MAX_ALL]; + static boolean mapping_initialized = FALSE; + + if (!mapping_initialized) + { + int i; + + // return "EL_UNKNOWN" for all undefined elements in mapping array + for (i = 0; i < O_MAX_ALL; i++) + mapping_BD_to_RND[i] = EL_UNKNOWN; + + for (i = 0; bd_object_mapping_list[i].element_bd != -1; i++) + if (bd_object_mapping_list[i].is_rnd_to_bd_mapping) + mapping_BD_to_RND[bd_object_mapping_list[i].element_bd] = + bd_object_mapping_list[i].element_rnd; + + mapping_initialized = TRUE; + } + + if (element_bd < 0 || element_bd >= O_MAX_ALL) + { + Warn("invalid BD element %d", element_bd); + + return EL_UNKNOWN; + } + + return mapping_BD_to_RND[element_bd]; +} + +int map_element_BD_to_RND_game(int element_bd) { static unsigned short mapping_BD_to_RND[O_MAX_ALL]; static boolean mapping_initialized = FALSE; diff --git a/src/tools.h b/src/tools.h index 28dd05c9..97fa4c95 100644 --- a/src/tools.h +++ b/src/tools.h @@ -229,8 +229,9 @@ void UndrawSpecialEditorDoor(void); void CreateToolButtons(void); void FreeToolButtons(void); -int map_element_RND_to_BD(int); -int map_element_BD_to_RND(int); +int map_element_RND_to_BD_cave(int); +int map_element_BD_to_RND_cave(int); +int map_element_BD_to_RND_game(int); int map_element_RND_to_EM_cave(int); int map_element_EM_to_RND_cave(int);