From: Holger Schemel Date: Tue, 27 Feb 2024 20:13:57 +0000 (+0100) Subject: improved color handling when loading BDCFF file in BD engine X-Git-Tag: 4.4.0.0-test-1~272 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=dec4d0bad52cff4f2fab1385d01b9f65347bd552;p=rocksndiamonds.git improved color handling when loading BDCFF file in BD engine --- diff --git a/src/game_bd/bd_bdcff.c b/src/game_bd/bd_bdcff.c index ff5a60ca..07c6cd61 100644 --- a/src/game_bd/bd_bdcff.c +++ b/src/game_bd/bd_bdcff.c @@ -398,9 +398,11 @@ static void replay_process_tags(GdReplay *replay, HashTable *tags) static boolean cave_process_tags_func(const char *attrib, const char *param, GdCave *cave) { char **params; + int paramcount; boolean identifier_found; params = getSplitStringArray(param, " ", -1); + paramcount = getStringArrayLength(params); identifier_found = FALSE; if (strcasecmp(attrib, "SnapExplosions") == 0) @@ -462,17 +464,65 @@ static boolean cave_process_tags_func(const char *attrib, const char *param, GdC else if (strcasecmp(attrib, "Colors") == 0) { /* colors attribute is a mess, have to process explicitly */ + boolean ok = TRUE; /* Colors = [border background] foreground1 foreground2 foreground3 [amoeba slime] */ identifier_found = TRUE; - cave->colorb = GD_GDASH_BLACK; /* border - black */ - cave->color0 = GD_GDASH_BLACK; /* background - black */ - cave->color1 = GD_GDASH_RED; - cave->color2 = GD_GDASH_PURPLE; - cave->color3 = GD_GDASH_YELLOW; - cave->color4 = cave->color3; /* amoeba */ - cave->color5 = cave->color1; /* slime */ + if (paramcount == 3) + { + /* only color1,2,3 */ + cave->colorb = gd_c64_color(0); /* border - black */ + cave->color0 = gd_c64_color(0); /* background - black */ + cave->color1 = gd_color_get_from_string(params[0]); + cave->color2 = gd_color_get_from_string(params[1]); + cave->color3 = gd_color_get_from_string(params[2]); + cave->color4 = cave->color3; /* amoeba */ + cave->color5 = cave->color1; /* slime */ + } + else if (paramcount == 5) + { + /* bg,color0,1,2,3 */ + cave->colorb = gd_color_get_from_string(params[0]); + cave->color0 = gd_color_get_from_string(params[1]); + cave->color1 = gd_color_get_from_string(params[2]); + cave->color2 = gd_color_get_from_string(params[3]); + cave->color3 = gd_color_get_from_string(params[4]); + cave->color4 = cave->color3; /* amoeba */ + cave->color5 = cave->color1; /* slime */ + } + else if (paramcount == 7) + { + /* bg,color0,1,2,3,amoeba,slime */ + cave->colorb = gd_color_get_from_string(params[0]); + cave->color0 = gd_color_get_from_string(params[1]); + cave->color1 = gd_color_get_from_string(params[2]); + cave->color2 = gd_color_get_from_string(params[3]); + cave->color3 = gd_color_get_from_string(params[4]); + cave->color4 = gd_color_get_from_string(params[5]); /* amoeba */ + cave->color5 = gd_color_get_from_string(params[6]); /* slime */ + } + else + { + Warn("invalid number of color strings: %s", param); + + ok = FALSE; + } + + /* now check and maybe make up some new. */ + if (!ok || + gd_color_is_unknown(cave->colorb) || + gd_color_is_unknown(cave->color0) || + gd_color_is_unknown(cave->color1) || + gd_color_is_unknown(cave->color2) || + gd_color_is_unknown(cave->color3) || + gd_color_is_unknown(cave->color4) || + gd_color_is_unknown(cave->color5)) + { + Warn("created a new C64 color scheme."); + + gd_cave_set_random_c64_colors(cave); /* just create some random */ + } } else { diff --git a/src/game_bd/bd_cave.c b/src/game_bd/bd_cave.c index a1d528ec..4c5b4287 100644 --- a/src/game_bd/bd_cave.c +++ b/src/game_bd/bd_cave.c @@ -774,6 +774,38 @@ void gd_cave_c64_random_set_seed(GdCave *cave, int seed1, int seed2) gd_c64_random_set_seed(&cave->c64_rand, seed1, seed2); } +void gd_cave_set_random_c64_colors(GdCave *cave) +{ + const int bright_colors[] = { 1, 3, 7 }; + const int dark_colors[] = { 2, 6, 8, 9, 11 }; + + /* always black */ + cave->colorb = gd_c64_color(0); + cave->color0 = gd_c64_color(0); + + /* choose some bright color for brick */ + cave->color3 = gd_c64_color(bright_colors[gd_random_int_range(0, ARRAY_SIZE(bright_colors))]); + + /* choose a dark color for dirt, but should not be == color of brick */ + do + { + cave->color1 = gd_c64_color(dark_colors[gd_random_int_range(0, ARRAY_SIZE(dark_colors))]); + } + while (cave->color1 == cave->color3); /* so it is not the same as color 1 */ + + /* choose any but black for steel wall, but should not be == brick or dirt */ + do + { + /* between 1 and 15 - do not use black for this. */ + cave->color2 = gd_c64_color(gd_random_int_range(1, 16)); + } + while (cave->color1 == cave->color2 || cave->color2 == cave->color3); /* so colors are not the same */ + + /* copy amoeba and slime color */ + cave->color4 = cave->color3; + cave->color5 = cave->color1; +} + /* shrink cave if last line or last row is just steel wall (or (invisible) outbox). diff --git a/src/game_bd/bd_cave.h b/src/game_bd/bd_cave.h index 3bdc02f0..f792feb3 100644 --- a/src/game_bd/bd_cave.h +++ b/src/game_bd/bd_cave.h @@ -623,6 +623,7 @@ unsigned int gd_c64_random(GdC64RandomGenerator *rand); unsigned int gd_cave_c64_random(GdCave *); void gd_c64_random_set_seed(GdC64RandomGenerator *rand, int seed1, int seed2); void gd_cave_c64_random_set_seed(GdCave *cave, int seed1, int seed2); +void gd_cave_set_random_c64_colors(GdCave *cave); /* support */ void *gd_cave_map_new_for_cave(const GdCave *cave, const int cell_size);