diff --git a/changelog b/changelog index f7356fe5c09..2e97df4bc93 100644 --- a/changelog +++ b/changelog @@ -30,6 +30,7 @@ Version 1.13.1+dev: option previously found in Preferences -> General. * WML engine: * Added support for mod_x,mod_y= in [terrain_graphics]. + * Added support for has_flag= in terrain graphics [variant]. * Miscellaneous and bug fixes: * Fixed Generate Map dialog bug that caused last choice of map generator to not be actually selected (bug #23711). diff --git a/src/terrain_builder.cpp b/src/terrain_builder.cpp index 57502a98b5a..94710cd764e 100644 --- a/src/terrain_builder.cpp +++ b/src/terrain_builder.cpp @@ -125,6 +125,21 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log) imagelist& img_list = is_background ? images_background : images_foreground; BOOST_FOREACH(const rule_image_variant& variant, ri->variants){ + if(!variant.has_flag.empty()) { + bool has_flag_match = true; + BOOST_FOREACH(const std::string& s, variant.has_flag) { + // If a flag listed in "has_flag" is not present, this variant does not match + if(flags.find(s) == flags.end()) { + has_flag_match = false; + break; + } + } + + if(!has_flag_match) { + continue; + } + } + if(!variant.tods.empty() && variant.tods.find(tod) == variant.tods.end()) continue; @@ -622,13 +637,17 @@ void terrain_builder::rotate_rule(building_rule &ret, int angle, replace_rotate_tokens(ret, angle, rot); } -terrain_builder::rule_image_variant::rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, bool random_start) : +terrain_builder::rule_image_variant::rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, const std::string& has_flag, bool random_start) : image_string(image_string), variations(variations), images(), tods(), + has_flag(), random_start(random_start) { + if(!has_flag.empty()) { + this->has_flag = utils::split(has_flag); + } if(!tod.empty()) { const std::vector tod_list = utils::split(tod); tods.insert(tod_list.begin(), tod_list.end()); @@ -667,9 +686,10 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi const std::string &name = variant["name"]; const std::string &variations = img["variations"]; const std::string &tod = variant["tod"]; + const std::string &has_flag = variant["has_flag"]; bool random_start = variant["random_start"].to_bool(true); - images.back().variants.push_back(rule_image_variant(name, variations, tod, random_start)); + images.back().variants.push_back(rule_image_variant(name, variations, tod, has_flag, random_start)); } // Adds the main (default) variant of the image at the end, diff --git a/src/terrain_builder.hpp b/src/terrain_builder.hpp index 4bb4ae2908b..34b60001ffd 100644 --- a/src/terrain_builder.hpp +++ b/src/terrain_builder.hpp @@ -155,11 +155,12 @@ public: variations(variations), images(), tods(), + has_flag(), random_start(random_start) {} /** Constructor for true [variant] cases */ - rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, bool random_start = true); + rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, const std::string& has_flag, bool random_start = true); /** A string representing either the filename for an image, or * a list of images, with an optional timing for each image. @@ -194,6 +195,8 @@ public: /** The Time of Day associated to this variant (if any)*/ std::set tods; + std::vector has_flag; + /** Indicate if the animation uses a random shift */ bool random_start; };