The Battle for Wesnoth  1.19.0-dev
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
terrain_builder Class Reference

The class terrain_builder is constructed from a config object, and a gamemap object. More...

#include <builder.hpp>

Classes

struct  building_rule
 The in-memory representation of a [terrain_graphics] WML rule. More...
 
struct  rule_image
 Each terrain_graphics rule is associated a set of images, which are applied on the terrain if the rule matches. More...
 
struct  rule_image_variant
 An image variant. More...
 
struct  terrain_constraint
 The in-memory representation of a [tile] WML rule inside of a [terrain_graphics] WML rule. More...
 
struct  tile
 Represents a tile of the game map, with all associated builder-specific parameters: flags, images attached to this tile, etc. More...
 
class  tilemap
 The map of "tile" structures corresponding to the level map. More...
 

Public Types

enum  TERRAIN_TYPE { BACKGROUND , FOREGROUND }
 Used as a parameter for the get_terrain_at function. More...
 
typedef std::vector< animated< image::locator > > imagelist
 A shorthand typedef for a list of animated image locators, the base data type returned by the get_terrain_at method. More...
 
typedef std::vector< rule_imagerule_imagelist
 A shorthand notation for a vector of rule_images. More...
 

Public Member Functions

 terrain_builder (const config &level, const gamemap *map, const std::string &offmap_image, bool draw_border)
 Constructor for the terrain_builder class. More...
 
const gamemapmap () const
 
void reload_map ()
 Updates internals that cache map size. More...
 
void change_map (const gamemap *m)
 
const imagelistget_terrain_at (const map_location &loc, const std::string &tod, TERRAIN_TYPE const terrain_type)
 Returns a vector of strings representing the images to load & blit together to get the built content for this tile. More...
 
bool update_animation (const map_location &loc)
 Updates the animation at a given tile. More...
 
void rebuild_terrain (const map_location &loc)
 Performs a "quick-rebuild" of the terrain in a given location. More...
 
void rebuild_all ()
 Performs a complete rebuild of the list of terrain graphics attached to a map. More...
 
void rebuild_cache_all ()
 
void set_draw_border (bool do_draw)
 
tileget_tile (const map_location &loc)
 

Static Public Member Functions

static void set_terrain_rules_cfg (const game_config_view &cfg)
 Set the config where we will parse the global terrain rules. More...
 

Static Public Attributes

static const int UNITPOS = 36 + 18
 The position of unit graphics in a tile. More...
 
static const unsigned int DUMMY_HASH = 0
 

Private Types

typedef std::vector< terrain_constraintconstraint_set
 The list of constraints attached to a terrain_graphics WML rule. More...
 
typedef std::multiset< building_rulebuilding_ruleset
 A set of building rules. More...
 
typedef std::multimap< int, map_locationanchormap
 
typedef std::map< t_translation::terrain_code, std::vector< map_location > > terrain_by_type_map
 Shorthand typedef for a map associating a list of locations to a terrain type. More...
 

Private Member Functions

bool load_images (building_rule &rule)
 Load images and tests for validity of a rule. More...
 
bool start_animation (building_rule &rule)
 Starts the animation on a rule. More...
 
void rotate (terrain_constraint &constraint, int angle)
 "Rotates" a constraint from a rule. More...
 
void replace_rotate_tokens (std::string &s, int angle, const std::vector< std::string > &replacement)
 Replaces, in a given string, rotation tokens with their values. More...
 
void replace_rotate_tokens (rule_image &image, int angle, const std::vector< std::string > &replacement)
 Replaces, in a given rule_image, rotation tokens with their values. More...
 
void replace_rotate_tokens (rule_image_variant &variant, int angle, const std::vector< std::string > &replacement)
 Replaces, in a given rule_variant_image, rotation tokens with their values. More...
 
void replace_rotate_tokens (rule_imagelist &list, int angle, const std::vector< std::string > &replacement)
 Replaces, in a given rule_imagelist, rotation tokens with their values. More...
 
void replace_rotate_tokens (building_rule &rule, int angle, const std::vector< std::string > &replacement)
 Replaces, in a given building_rule, rotation tokens with their values. More...
 
void rotate_rule (building_rule &rule, int angle, const std::vector< std::string > &angle_name)
 Rotates a template rule to a given angle. More...
 
void add_images_from_config (rule_imagelist &images, const config &cfg, bool global, int dx=0, int dy=0)
 Parses a "config" object, which should contains [image] children, and adds the corresponding parsed rule_images to a rule_imagelist. More...
 
terrain_constraintadd_constraints (constraint_set &constraints, const map_location &loc, const t_translation::ter_match &type, const config &global_images)
 Creates a rule constraint object which matches a given list of terrains, and adds it to the list of constraints of a rule. More...
 
void add_constraints (constraint_set &constraints, const map_location &loc, const config &cfg, const config &global_images)
 Creates a rule constraint object from a config object and adds it to the list of constraints of a rule. More...
 
void parse_mapstring (const std::string &mapstring, struct building_rule &br, anchormap &anchors, const config &global_images)
 Parses a map string (the map= element of a [terrain_graphics] rule, and adds constraints from this map to a building_rule. More...
 
void add_rule (building_ruleset &rules, building_rule &rule)
 Adds a rule to a ruleset. More...
 
void add_rotated_rules (building_ruleset &rules, building_rule &tpl, const std::string &rotations)
 Adds a set of rules to a ruleset, from a template rule which spans 6 rotations (or less if some of the rotated rules are invalid). More...
 
void parse_config (const config &cfg, bool local=true)
 Parses a configuration object containing [terrain_graphics] rules, and fills the building_rules_ member of the current class according to those. More...
 
void parse_config (const game_config_view &cfg, bool local=true)
 
void parse_global_config (const game_config_view &cfg)
 
void add_off_map_rule (const std::string &image)
 Adds a builder rule for the _off^_usr tile, this tile only has 1 image. More...
 
void flush_local_rules ()
 
bool terrain_matches (const t_translation::terrain_code &tcode, const t_translation::ter_list &terrains) const
 Checks whether a terrain code matches a given list of terrain codes. More...
 
bool terrain_matches (const t_translation::terrain_code &tcode, const t_translation::ter_match &terrain) const
 Checks whether a terrain code matches a given list of terrain tcodes. More...
 
bool rule_matches (const building_rule &rule, const map_location &loc, const terrain_constraint *type_checked) const
 Checks whether a rule matches a given location in the map. More...
 
void apply_rule (const building_rule &rule, const map_location &loc)
 Applies a rule at a given location: applies the result of a matching rule at a given location: attachs the images corresponding to the rule, and sets the flags corresponding to the rule. More...
 
void build_terrains ()
 Calculates the list of terrains, and fills the tile_map_ member, from the gamemap and the building_rules_. More...
 

Private Attributes

const int tilewidth_
 The tile width used when using basex and basey. More...
 
const gamemapmap_
 A pointer to the gamemap class used in the current level. More...
 
tilemap tile_map_
 The tile_map_ for the current level, which is filled by the build_terrains_ method to contain "tiles" representing images attached to each tile. More...
 
terrain_by_type_map terrain_by_type_
 A map representing all locations whose terrain is of a given type. More...
 
bool draw_border_
 Whether the map border should be drawn. More...
 

Static Private Attributes

static building_ruleset building_rules_ {}
 Parsed terrain rules. More...
 
static const game_config_viewrules_cfg_ = nullptr
 Config used to parse global terrain rules. More...
 

Detailed Description

The class terrain_builder is constructed from a config object, and a gamemap object.

On construction, it parses the configuration and extracts the list of [terrain_graphics] rules. Each terrain_graphics rule attaches one or more images to a specific terrain pattern. It then applies the rules loaded from the configuration to the current map, and calculates the list of images that must be associated to each hex of the map.

The get_terrain_at method can then be used to obtain the list of images necessary to draw the terrain on a given tile.

Definition at line 47 of file builder.hpp.

Member Typedef Documentation

◆ anchormap

typedef std::multimap<int, map_location> terrain_builder::anchormap
private

Definition at line 716 of file builder.hpp.

◆ building_ruleset

typedef std::multiset<building_rule> terrain_builder::building_ruleset
private

A set of building rules.

In-memory representation of the whole set of [terrain_graphics] rules.

Definition at line 530 of file builder.hpp.

◆ constraint_set

The list of constraints attached to a terrain_graphics WML rule.

Definition at line 401 of file builder.hpp.

◆ imagelist

A shorthand typedef for a list of animated image locators, the base data type returned by the get_terrain_at method.

Definition at line 74 of file builder.hpp.

◆ rule_imagelist

A shorthand notation for a vector of rule_images.

Definition at line 272 of file builder.hpp.

◆ terrain_by_type_map

Shorthand typedef for a map associating a list of locations to a terrain type.

Definition at line 851 of file builder.hpp.

Member Enumeration Documentation

◆ TERRAIN_TYPE

Used as a parameter for the get_terrain_at function.

Enumerator
BACKGROUND 

Represents terrains which are to be drawn behind unit sprites.

FOREGROUND 

Represents terrains which are to be drawn in front of them.

Definition at line 51 of file builder.hpp.

Constructor & Destructor Documentation

◆ terrain_builder()

terrain_builder::terrain_builder ( const config level,
const gamemap map,
const std::string &  offmap_image,
bool  draw_border 
)

Constructor for the terrain_builder class.

Parameters
levelA level (scenario)-specific configuration file, containing scenario-specific [terrain_graphics] rules.
mapA properly-initialized gamemap object representing the current terrain map.
offmap_imageThe filename of the image which will be used as off map image (see add_off_map_rule()). This image automatically gets the 'terrain/' prefix and '.png' suffix
draw_borderWhether the map border flag should be set to allow its drawing.

Definition at line 243 of file builder.cpp.

References add_off_map_rule(), build_terrains(), building_rules_, flush_local_rules(), game_config::images::level, parse_config(), parse_global_config(), image::precache_file_existence(), and rules_cfg_.

Member Function Documentation

◆ add_constraints() [1/2]

void terrain_builder::add_constraints ( terrain_builder::constraint_set constraints,
const map_location loc,
const config cfg,
const config global_images 
)
private

Creates a rule constraint object from a config object and adds it to the list of constraints of a rule.

Parameters
constraintsThe constraint set to which to add the constraint.
locThe location of the constraint
cfgThe config object describing this constraint. Usually, a [tile] child of a [terrain_graphics] rule.
global_imagesA configuration object containing [image] tags describing rule-global images.

Definition at line 770 of file builder.cpp.

References add_constraints(), add_images_from_config(), terrain_builder::terrain_constraint::has_flag, terrain_builder::terrain_constraint::images, terrain_builder::terrain_constraint::no_draw, terrain_builder::terrain_constraint::no_flag, terrain_builder::terrain_constraint::set_flag, utils::square_parenthetical_split(), and t_translation::WILDCARD.

◆ add_constraints() [2/2]

terrain_builder::terrain_constraint & terrain_builder::add_constraints ( terrain_builder::constraint_set constraints,
const map_location loc,
const t_translation::ter_match type,
const config global_images 
)
private

Creates a rule constraint object which matches a given list of terrains, and adds it to the list of constraints of a rule.

Parameters
constraintsThe constraint set to which to add the constraint.
locThe location of the constraint
typeThe list of terrains this constraint will match
global_imagesA configuration object containing [image] tags describing rule-global images.

Definition at line 740 of file builder.cpp.

References add_images_from_config(), c, terrain_builder::terrain_constraint::images, terrain_builder::terrain_constraint::terrain_types_match, tilewidth_, map_location::x, and map_location::y.

Referenced by add_constraints(), parse_config(), and parse_mapstring().

◆ add_images_from_config()

void terrain_builder::add_images_from_config ( rule_imagelist images,
const config cfg,
bool  global,
int  dx = 0,
int  dy = 0 
)
private

Parses a "config" object, which should contains [image] children, and adds the corresponding parsed rule_images to a rule_imagelist.

Parameters
imagesThe rule_imagelist into which to add the parsed images.
cfgThe WML configuration object to parse
globalWhether those [image]s elements belong to a [terrain_graphics] element, or to a [tile] child. Set to true if those belong to a [terrain_graphics] element.
dxThe X coordinate of the constraint those images apply to, relative to the start of the rule. Only meaningful if global is set to false.
dyThe Y coordinate of the constraint those images apply to.

Definition at line 681 of file builder.cpp.

References config::child_range(), ERR_NG, utils::split(), and tilewidth_.

Referenced by add_constraints().

◆ add_off_map_rule()

void terrain_builder::add_off_map_rule ( const std::string &  image)
private

Adds a builder rule for the _off^_usr tile, this tile only has 1 image.

Parameters
imageThe filename of the image

Definition at line 993 of file builder.cpp.

References config::add_child(), t_translation::OFF_MAP_USER, parse_global_config(), game_config_view::wrap(), and t_translation::write_terrain_code().

Referenced by terrain_builder().

◆ add_rotated_rules()

void terrain_builder::add_rotated_rules ( building_ruleset rules,
building_rule tpl,
const std::string &  rotations 
)
private

Adds a set of rules to a ruleset, from a template rule which spans 6 rotations (or less if some of the rotated rules are invalid).

Parameters
rulesThe ruleset into which to add the rules.
tplThe template rule
rotationsA comma-separated string containing the 6 values for replacing rotation template template strings
(@Rn) 

Definition at line 848 of file builder.cpp.

References add_rule(), rotate_rule(), and utils::split().

Referenced by parse_config().

◆ add_rule()

void terrain_builder::add_rule ( building_ruleset rules,
building_rule rule 
)
private

Adds a rule to a ruleset.

Checks for validity before adding the rule.

Parameters
rulesThe ruleset into which to add the rules.
ruleThe rule to add.

Definition at line 841 of file builder.cpp.

References load_images().

Referenced by add_rotated_rules().

◆ apply_rule()

void terrain_builder::apply_rule ( const building_rule rule,
const map_location loc 
)
private

Applies a rule at a given location: applies the result of a matching rule at a given location: attachs the images corresponding to the rule, and sets the flags corresponding to the rule.

Parameters
ruleThe rule to apply
locThe location to which to apply the rule.

Definition at line 1074 of file builder.cpp.

References terrain_builder::building_rule::constraints, game_config::images::flag, terrain_builder::tile::flags, terrain_builder::building_rule::get_hash(), get_noise(), terrain_builder::terrain_constraint::images, terrain_builder::tile::images, legacy_sum(), terrain_builder::terrain_constraint::loc, terrain_builder::terrain_constraint::no_draw, terrain_builder::tilemap::on_map(), terrain_builder::terrain_constraint::set_flag, and tile_map_.

Referenced by build_terrains().

◆ build_terrains()

void terrain_builder::build_terrains ( )
private

◆ change_map()

void terrain_builder::change_map ( const gamemap m)

Definition at line 305 of file builder.cpp.

References map_, and reload_map().

◆ flush_local_rules()

void terrain_builder::flush_local_rules ( )
private

Definition at line 278 of file builder.cpp.

References building_rules_, and i.

Referenced by terrain_builder().

◆ get_terrain_at()

const terrain_builder::imagelist * terrain_builder::get_terrain_at ( const map_location loc,
const std::string &  tod,
TERRAIN_TYPE const  terrain_type 
)

Returns a vector of strings representing the images to load & blit together to get the built content for this tile.

Parameters
locThe location relative the the terrain map, where we ask for the image list
todThe string representing the current time-of day. Will be used if some images specify several time-of-day- related variants.
terrain_typeBACKGROUND or FOREGROUND, depending on whether we ask for the terrain which is before, or after the unit sprite.
Returns
Returns a pointer list of animated images corresponding to the parameters, or nullptr if there is none.

Definition at line 311 of file builder.cpp.

References BACKGROUND, terrain_builder::tile::images_background, terrain_builder::tile::images_foreground, terrain_builder::tile::last_tod, terrain_builder::tilemap::on_map(), terrain_builder::tile::rebuild_cache(), and tile_map_.

◆ get_tile()

terrain_builder::tile * terrain_builder::get_tile ( const map_location loc)

◆ load_images()

bool terrain_builder::load_images ( building_rule rule)
private

Load images and tests for validity of a rule.

A rule is considered valid if all its images are present. This method is used, when building the ruleset, to only add rules which are valid to the ruleset.

Parameters
ruleThe rule to test for validity
Returns
true if the rule is valid, false if it is not.
Todo:
improve this, 99% of terrains are not animated.

Definition at line 433 of file builder.cpp.

References animated< T >::add_frame(), terrain_builder::rule_image::center_x, terrain_builder::rule_image::center_y, terrain_builder::building_rule::constraints, ERR_NG, animated< T >::get_frames_count(), get_variations(), terrain_builder::rule_image::global_image, image_exists(), terrain_builder::rule_image_variant::image_string, terrain_builder::rule_image_variant::images, terrain_builder::terrain_constraint::images, mp::ui_alerts::items, terrain_builder::terrain_constraint::loc, utils::split(), utils::square_parenthetical_split(), animated< T >::start_animation(), terrain_builder::rule_image::variants, and terrain_builder::rule_image_variant::variations.

Referenced by add_rule().

◆ map()

const gamemap& terrain_builder::map ( ) const
inline

◆ parse_config() [1/2]

void terrain_builder::parse_config ( const config cfg,
bool  local = true 
)
private

Parses a configuration object containing [terrain_graphics] rules, and fills the building_rules_ member of the current class according to those.

Parameters
cfgThe configuration object to parse.
localMark the rules as local only.

Definition at line 877 of file builder.cpp.

References game_config_view::wrap().

Referenced by parse_global_config(), and terrain_builder().

◆ parse_config() [2/2]

void terrain_builder::parse_config ( const game_config_view cfg,
bool  local = true 
)
private

◆ parse_global_config()

void terrain_builder::parse_global_config ( const game_config_view cfg)
inlineprivate

Definition at line 763 of file builder.hpp.

References parse_config().

Referenced by add_off_map_rule(), and terrain_builder().

◆ parse_mapstring()

void terrain_builder::parse_mapstring ( const std::string &  mapstring,
struct building_rule br,
anchormap anchors,
const config global_images 
)
private

Parses a map string (the map= element of a [terrain_graphics] rule, and adds constraints from this map to a building_rule.

Parameters
mapstringThe map vector to parse
brThe building rule into which to add the extracted constraints
anchorsA map where to put "anchors" extracted from the map.
global_imagesA config object representing the images defined as direct children of the [terrain_graphics] rule.

Definition at line 797 of file builder.cpp.

References add_constraints(), t_translation::terrain_code::base, terrain_builder::building_rule::constraints, gamemap_base::empty(), ERR_NG, gamemap_base::h(), map(), t_translation::NONE_TERRAIN, t_translation::terrain_code::overlay, t_translation::read_builder_map(), t_translation::STAR, t_translation::TB_DOT, t_translation::TB_STAR, gamemap_base::w(), and t_translation::write_terrain_code().

Referenced by parse_config().

◆ rebuild_all()

void terrain_builder::rebuild_all ( )

Performs a complete rebuild of the list of terrain graphics attached to a map.

Should be called when a terrain is changed in the map.

Definition at line 387 of file builder.cpp.

References build_terrains(), terrain_builder::tilemap::reset(), terrain_by_type_, and tile_map_.

◆ rebuild_cache_all()

void terrain_builder::rebuild_cache_all ( )

Definition at line 269 of file builder.cpp.

References gamemap_base::h(), map(), tile_map_, and gamemap_base::w().

◆ rebuild_terrain()

void terrain_builder::rebuild_terrain ( const map_location loc)

Performs a "quick-rebuild" of the terrain in a given location.

The "quick-rebuild" is no proper rebuild: it only clears the terrain cache for a given location, and replaces it with a single, default image for this terrain.

Parameters
locthe location where to rebuild terrains
Todo:
TODO: rename this function

Definition at line 357 of file builder.cpp.

References animated< T >::add_frame(), gamemap::get_terrain_info(), terrain_builder::tile::images_background, terrain_builder::tile::images_foreground, map(), terrain_type::minimap_image(), terrain_type::minimap_image_overlay(), terrain_builder::tilemap::on_map(), animated< T >::start_animation(), and tile_map_.

◆ reload_map()

void terrain_builder::reload_map ( )

Updates internals that cache map size.

This should be called when the map size has changed.

Definition at line 298 of file builder.cpp.

References build_terrains(), h, map(), terrain_builder::tilemap::reload(), terrain_by_type_, tile_map_, and w.

Referenced by change_map().

◆ replace_rotate_tokens() [1/5]

void terrain_builder::replace_rotate_tokens ( building_rule rule,
int  angle,
const std::vector< std::string > &  replacement 
)
private

Replaces, in a given building_rule, rotation tokens with their values.

The actual substitution is done in the rule_imagelists contained in all constraints of the building_rule, and in the flags (has_flag, set_flag and no_flag) contained in all constraints of the building_rule.

Parameters
rulethe building_rule in which to do the replacement.
anglethe angle for substituting the correct replacement.
replacementthe replacement strings.

Definition at line 609 of file builder.cpp.

References terrain_builder::building_rule::constraints, game_config::images::flag, terrain_builder::terrain_constraint::has_flag, terrain_builder::terrain_constraint::images, terrain_builder::terrain_constraint::no_flag, replace_rotate_tokens(), and terrain_builder::terrain_constraint::set_flag.

◆ replace_rotate_tokens() [2/5]

void terrain_builder::replace_rotate_tokens ( rule_image image,
int  angle,
const std::vector< std::string > &  replacement 
)
private

Replaces, in a given rule_image, rotation tokens with their values.

The actual substitution is done in all variants of the given image.

Parameters
imagethe rule_image in which to do the replacement.
anglethe angle for substituting the correct replacement.
replacementthe replacement strings.

Definition at line 594 of file builder.cpp.

References replace_rotate_tokens().

◆ replace_rotate_tokens() [3/5]

void terrain_builder::replace_rotate_tokens ( rule_image_variant variant,
int  angle,
const std::vector< std::string > &  replacement 
)
inlineprivate

Replaces, in a given rule_variant_image, rotation tokens with their values.

The actual substitution is done in the "image_string" parameter of this rule_variant_image.

Parameters
variantthe rule_variant_image in which to do the replacement.
anglethe angle for substituting the correct replacement.
replacementthe replacement strings.

Definition at line 602 of file builder.hpp.

References terrain_builder::rule_image_variant::image_string, and replace_rotate_tokens().

◆ replace_rotate_tokens() [4/5]

void terrain_builder::replace_rotate_tokens ( rule_imagelist list,
int  angle,
const std::vector< std::string > &  replacement 
)
private

Replaces, in a given rule_imagelist, rotation tokens with their values.

The actual substitution is done in all rule_images contained in the rule_imagelist.

Parameters
listthe rule_imagelist in which to do the replacement.
anglethe angle for substituting the correct replacement.
replacementthe replacement strings.

Definition at line 601 of file builder.cpp.

References replace_rotate_tokens().

◆ replace_rotate_tokens() [5/5]

void terrain_builder::replace_rotate_tokens ( std::string &  s,
int  angle,
const std::vector< std::string > &  replacement 
)
private

Replaces, in a given string, rotation tokens with their values.

Parameters
sthe string in which to do the replacement
anglethe angle for substituting the correct replacement.
replacementthe replacement strings.

Definition at line 575 of file builder.cpp.

References i, and s.

Referenced by replace_rotate_tokens(), and rotate_rule().

◆ rotate()

void terrain_builder::rotate ( terrain_constraint constraint,
int  angle 
)
private

"Rotates" a constraint from a rule.

Takes a template constraint from a template rule, and rotates to the given angle.

On a constraint, the relative position of each rule, and the "base" of each vertical images, are rotated according to the given angle.

Template terrain constraints are defined like normal terrain constraints, except that, flags, and image filenames, may contain template strings of the form

*  <code>@Rn</code>,
*

n being a number from 0 to 5. See the rotate_rule method for more info.

Parameters
constraintA template constraint to rotate
angleAn int, from 0 to 5, representing the rotation angle.

Definition at line 495 of file builder.cpp.

References terrain_builder::terrain_constraint::images, terrain_builder::terrain_constraint::loc, tilewidth_, map_location::x, and map_location::y.

Referenced by rotate_rule().

◆ rotate_rule()

void terrain_builder::rotate_rule ( building_rule rule,
int  angle,
const std::vector< std::string > &  angle_name 
)
private

Rotates a template rule to a given angle.

Template rules are defined like normal rules, except that:

  • Flags and image filenames may contain template strings of the form
    *  <code>@Rn</code>, n being a number from 0 to 5.
    *
  • The rule contains the rotations=r0,r1,r2,r3,r4,r5, with r0 to r5 being strings describing the 6 different positions, typically, n, ne, se, s, sw, and nw (but maybe anything else.)

A template rule will generate 6 rules, which are similar to the template, except that:

  • The map of constraints ( [tile]s ) of this rule will be rotated by an angle, of 0 to 5 pi / 6
  • On the rule which is rotated to 0rad, the template strings
    *    @R0, @R1, @R2, @R3, @R4, @R5,
    *
    will be replaced by the corresponding r0, r1, r2, r3, r4, r5 variables given in the rotations= element.
  • On the rule which is rotated to pi/3 rad, the template strings
    *    @R0, @R1, @R2 etc.
    *
    will be replaced by the corresponding r1, r2, r3, r4, r5, r0 (note the shift in indices).
  • On the rule rotated 2pi/3, those will be replaced by r2, r3, r4, r5, r0, r1 and so on.

Definition at line 628 of file builder.cpp.

References terrain_builder::building_rule::constraints, ERR_NG, legacy_sum_assign(), terrain_builder::terrain_constraint::loc, replace_rotate_tokens(), rotate(), map_location::x, and map_location::y.

Referenced by add_rotated_rules().

◆ rule_matches()

bool terrain_builder::rule_matches ( const building_rule rule,
const map_location loc,
const terrain_constraint type_checked 
) const
private

◆ set_draw_border()

void terrain_builder::set_draw_border ( bool  do_draw)
inline

Definition at line 155 of file builder.hpp.

References draw_border_.

◆ set_terrain_rules_cfg()

void terrain_builder::set_terrain_rules_cfg ( const game_config_view cfg)
static

Set the config where we will parse the global terrain rules.

This also flushes the terrain rules cache.

Parameters
cfgThe main game configuration object, where the [terrain_graphics] rule reside.

Definition at line 289 of file builder.cpp.

References building_rules_, rules_cfg_, and swap().

Referenced by game_config_manager::load_game_config().

◆ start_animation()

bool terrain_builder::start_animation ( building_rule rule)
private

Starts the animation on a rule.

Parameters
ruleThe rule on which to start animations
Returns
true

◆ terrain_matches() [1/2]

bool terrain_builder::terrain_matches ( const t_translation::terrain_code tcode,
const t_translation::ter_list terrains 
) const
inlineprivate

Checks whether a terrain code matches a given list of terrain codes.

Parameters
tcodeThe terrain to check
terrainsThe terrain list against which to check the terrain. May contain the metacharacters
  • '*' STAR, meaning "all terrains"
  • '!' NOT, meaning "all terrains except those present in the list."
Returns
returns true if "tcode" matches the list or the list is empty, else false.

Definition at line 789 of file builder.hpp.

References t_translation::terrain_matches().

Referenced by build_terrains(), and rule_matches().

◆ terrain_matches() [2/2]

bool terrain_builder::terrain_matches ( const t_translation::terrain_code tcode,
const t_translation::ter_match terrain 
) const
inlineprivate

Checks whether a terrain code matches a given list of terrain tcodes.

Parameters
tcodeThe terrain code to check
terrainThe terrain match structure which to check the terrain. See previous definition for more details.
Returns
returns true if "tcode" matches the list or the list is empty, else false.

Definition at line 804 of file builder.hpp.

References t_translation::ter_match::is_empty, and t_translation::terrain_matches().

◆ update_animation()

bool terrain_builder::update_animation ( const map_location loc)

Updates the animation at a given tile.

Returns true if something has changed, and must be redrawn.

Parameters
locthe location to update
Return values
truethis tile must be redrawn.

Definition at line 333 of file builder.cpp.

References a, terrain_builder::tile::images_background, terrain_builder::tile::images_foreground, terrain_builder::tilemap::on_map(), and tile_map_.

Member Data Documentation

◆ building_rules_

building_ruleset terrain_builder::building_rules_ {}
inlinestaticprivate

Parsed terrain rules.

Cached between instances

Definition at line 862 of file builder.hpp.

Referenced by build_terrains(), flush_local_rules(), parse_config(), set_terrain_rules_cfg(), and terrain_builder().

◆ draw_border_

bool terrain_builder::draw_border_
private

Whether the map border should be drawn.

Definition at line 859 of file builder.hpp.

Referenced by build_terrains(), and set_draw_border().

◆ DUMMY_HASH

const unsigned int terrain_builder::DUMMY_HASH = 0
static

Definition at line 69 of file builder.hpp.

Referenced by terrain_builder::building_rule::get_hash().

◆ map_

const gamemap* terrain_builder::map_
private

A pointer to the gamemap class used in the current level.

Definition at line 839 of file builder.hpp.

Referenced by change_map(), and map().

◆ rules_cfg_

const game_config_view* terrain_builder::rules_cfg_ = nullptr
inlinestaticprivate

Config used to parse global terrain rules.

Definition at line 865 of file builder.hpp.

Referenced by set_terrain_rules_cfg(), and terrain_builder().

◆ terrain_by_type_

terrain_by_type_map terrain_builder::terrain_by_type_
private

A map representing all locations whose terrain is of a given type.

Definition at line 856 of file builder.hpp.

Referenced by build_terrains(), rebuild_all(), and reload_map().

◆ tile_map_

tilemap terrain_builder::tile_map_
private

The tile_map_ for the current level, which is filled by the build_terrains_ method to contain "tiles" representing images attached to each tile.

Definition at line 846 of file builder.hpp.

Referenced by apply_rule(), build_terrains(), get_terrain_at(), get_tile(), rebuild_all(), rebuild_cache_all(), rebuild_terrain(), reload_map(), rule_matches(), and update_animation().

◆ tilewidth_

const int terrain_builder::tilewidth_
private

The tile width used when using basex and basey.

This is not, necessarily, the tile width in pixels, this is totally arbitrary. However, it will be set to 72 for convenience.

Definition at line 396 of file builder.hpp.

Referenced by add_constraints(), add_images_from_config(), and rotate().

◆ UNITPOS

const int terrain_builder::UNITPOS = 36 + 18
static

The position of unit graphics in a tile.

Graphics whose y position is below this value are considered background for this tile; graphics whose y position is above this value are considered foreground.

Definition at line 67 of file builder.hpp.

Referenced by terrain_builder::rule_image::is_background().


The documentation for this class was generated from the following files: