Added support for mod_x,mod_y in [terrain_graphics]

These work like x,y except that they match the rule on all locations
with coordinates that are multiples of the given values. For example,
mod_x,mod_y=4,3 matches (4,3)(8,3)(12,3)(16,3)(20,3)(etc) and then
(4,6)(8,6)(12,6)(16,6)(20,6)(etc) and so on.
This commit is contained in:
ln-zookeeper 2015-07-27 11:59:24 +03:00
parent 79c8ba2c82
commit a87e7e16ed
3 changed files with 21 additions and 0 deletions

View file

@ -28,6 +28,8 @@ Version 1.13.1+dev:
visible.
* Added a version dialog button to the title screen, replacing the Paths
option previously found in Preferences -> General.
* WML engine:
* Added support for mod_x,mod_y= in [terrain_graphics].
* Miscellaneous and bug fixes:
* Fixed Generate Map dialog bug that caused last choice of map
generator to not be actually selected (bug #23711).

View file

@ -835,6 +835,9 @@ void terrain_builder::parse_config(const config &cfg, bool local)
pbr.location_constraints =
map_location(br["x"].to_int() - 1, br["y"].to_int() - 1);
pbr.modulo_constraints =
map_location(br["mod_x"].to_int(), br["mod_y"].to_int());
pbr.probability = br["probability"].to_int(100);
// Mapping anchor indices to anchor locations.
@ -970,6 +973,14 @@ void terrain_builder::add_off_map_rule(const std::string& image)
bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule,
const map_location &loc, const terrain_constraint *type_checked) const
{
// Don't match if the location isn't a multiple of mod_x and mod_y
if(rule.modulo_constraints.x > 0 && (loc.x % rule.modulo_constraints.x != 0)) {
return false;
}
if(rule.modulo_constraints.y > 0 && (loc.y % rule.modulo_constraints.y != 0)) {
return false;
}
if(rule.location_constraints.valid() && rule.location_constraints != loc) {
return false;
}

View file

@ -357,6 +357,7 @@ private:
building_rule() :
constraints(),
location_constraints(),
modulo_constraints(),
probability(100),
precedence(0),
local(false),
@ -375,6 +376,13 @@ private:
*/
map_location location_constraints;
/**
* Used to constrain locations to ones with coordinates that are
* multiples of the "mod_x" and "mod_y" parameters. Doesn't actually
* refer to a real map location.
*/
map_location modulo_constraints;
/**
* The probability of this rule to match, when all conditions
* are met. Defined if the "probability" parameter of the