20 #ifndef TERRAIN_BUILDER_H_INCLUDED
21 #define TERRAIN_BUILDER_H_INCLUDED
30 namespace image{
class locator; }
70 typedef std::vector<animated<image::locator> >
imagelist;
156 image_string(image_string),
157 variations(variations),
195 std::vector< animated<image::locator> >
images;
297 typedef std::pair<const rule_image_rand*, const rule_image_variant*>
log_details;
298 typedef std::vector<log_details>
logs;
434 tiles_((x + 4) * (y + 4)),
537 const std::vector<std::string> &replacement);
548 const std::vector<std::string> &replacement);
560 const std::vector<std::string> &replacement)
573 const std::vector<std::string> &replacement);
587 const std::vector<std::string> &replacement);
626 const std::vector<std::string> &angle_name);
660 const config& global_images);
675 const config& global_images);
691 anchormap& anchors,
const config& global_images);
772 bool rule_matches(
const building_rule &rule,
const map_location &loc,
const terrain_constraint *type_checked)
const;
std::vector< tile > tiles_
The map.
void rebuild_terrain(const map_location &loc)
Performs a "quick-rebuild" of the terrain in a given location.
std::pair< const rule_image_rand *, const rule_image_variant * > log_details
int layer
The layer of the image for horizontal layering.
rule_image_rand(const rule_image *r_i, unsigned int rnd)
void reload_map()
Updates internals that cache map size.
The in-memory representation of a [terrain_graphics] WML rule.
terrain_by_type_map terrain_by_type_
A map representing all locations whose terrain is of a given type.
tile * get_tile(const map_location &loc)
int y_
The y dimension of the map.
terrain_constraint & add_constraints(constraint_set &constraints, const map_location &loc, const t_translation::t_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 c...
map_location modulo_constraints
Used to constrain locations to ones with coordinates that are multiples of the "mod_x" and "mod_y" pa...
void reset()
Resets the whole tile map.
The in-memory representation of a [tile] WML rule inside of a [terrain_graphics] WML rule...
void add_rule(building_ruleset &rules, building_rule &rule)
Adds a rule to a ruleset.
rule_image_variant(const std::string &image_string, const std::string &variations, bool random_start=true)
Constructor for the normal defaut case.
tile & operator[](const map_location &loc)
Returns a reference to the tile which is at the position pointed by loc.
bool no_draw
Whether to actually draw the images onto this hex or not.
void add_off_map_rule(const std::string &image)
Adds a builder rule for the _off^_usr tile, this tile only has 1 image.
GLuint GLuint GLsizei GLenum type
bool load_images(building_rule &rule)
Load images and tests for validity of a rule.
std::vector< terrain_constraint > constraint_set
The list of constraints attached to a terrain_graphics WML rule.
Represent a rule_image applied with a random seed.
imagelist images_background
The list of images which are behind the unit sprites, attached to this tile.
int precedence
Ordering relation between the rules.
static building_ruleset building_rules_
Parsed terrain rules.
std::multimap< int, map_location > anchormap
The class terrain_builder is constructed from a config object, and a gamemap object.
t_translation::t_match terrain_types_match
static const int UNITPOS
The position of unit graphics in a tile.
int basex
The position of the image base (that is, the point where the image reaches the floor) for vertical la...
const int tilewidth_
The tile width used when using basex and basey.
bool operator<(building_rule const &that) const
GLint GLint GLint GLint GLint GLint y
bool is_background() const
terrain_constraint(map_location loc)
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.
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 th...
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: attach...
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.
void rebuild_all()
Performs a complete rebuild of the list of terrain graphics attached to a map.
void rebuild_cache(const std::string &tod, logs *log=nullptr)
Rebuilds the whole image cache, for a given time-of-day.
static const unsigned int DUMMY_HASH
tilemap(int x, int y)
Constructs a tilemap of dimensions x * y.
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.
int probability
The probability of this rule to match, when all conditions are met.
Represents a tile of the game map, with all associated builder-specific parameters: flags...
void change_map(const gamemap *m)
bool operator<(const rule_image_rand &o) const
sort by layer first then by basey
const gamemap * map_
A pointer to the gamemap class used in the current level.
GLenum GLenum GLuint GLint GLint layer
This structure can be used for matching terrain strings.
tilemap tile_map_
The tile_map_ for the current level, which is filled by the build_terrains_ method to contain "tiles"...
Encapsulates the map of the game.
std::set< std::string > tods
The Time of Day associated to this variant (if any)
TERRAIN_TYPE
Used as a parameter for the get_terrain_at function.
terrain_builder(const config &level, const gamemap *map, const std::string &offmap_image)
Constructor for the terrain_builder class.
std::vector< rule_image_variant > variants
A list of variants for this image.
std::map< t_translation::t_terrain, std::vector< map_location > > terrain_by_type_map
Shorthand typedef for a map associating a list of locations to a terrain type.
std::vector< rule_image_rand > images
The list of rule_images and random seeds associated to this tile.
static const ::config * terrain
The terrain used to create the cache.
std::vector< log_details > logs
std::vector< animated< image::locator > > images
An animated image locator built according to the image string.
The map of "tile" structures corresponding to the level map.
bool local
Indicate if the rule is only for this scenario.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Encapsulates the map of the game.
void rotate_rule(building_rule &rule, int angle, const std::vector< std::string > &angle_name)
Rotates a template rule to a given angle.
bool update_animation(const map_location &loc)
Updates the animation at a given tile.
bool global_image
Set to true if the image was defined as a child of the [terrain_graphics] tag, set to false if it was...
std::string last_tod
The time-of-day to which the image caches correspond.
void rotate(terrain_constraint &constraint, int angle)
"Rotates" a constraint from a rule.
static const config * rules_cfg_
Config used to parse global terrain rules.
std::vector< std::string > set_flag
std::set< std::string > flags
The list of flags present in this tile.
unsigned int get_hash() const
rule_image(int layer, int x, int y, bool global_image=false, int center_x=-1, int center_y=-1, bool is_water=false)
std::vector< rule_image > rule_imagelist
A shorthand notation for a vector of rule_images.
bool terrain_matches(const t_terrain &src, const t_terrain &dest)
Tests whether a specific terrain matches an expression, for matching rules see above.
GLint GLint GLint GLint GLint x
bool terrain_matches(const t_translation::t_terrain &tcode, const t_translation::t_match &terrain) const
Checks whether a terrain code matches a given list of terrain tcodes.
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 ma...
Represents terrains which are to be drawn in front of them.
std::vector< std::string > has_flag
void reload(int x, int y)
Rebuilds the map to a new set of dimensions.
int center_x
The position where the center of the image base should be.
Represents terrains which are to be drawn behind unit sprites.
Each terrain_graphics rule is associated a set of images, which are applied on the terrain if the rul...
std::vector< std::string > has_flag
std::vector< animated< image::locator > > imagelist
A shorthand typedef for a list of animated image locators, the base data type returned by the get_ter...
void build_terrains()
Calculates the list of terrains, and fills the tile_map_ member, from the gamemap and the building_ru...
tile()
Constructor for the tile() structure.
std::multiset< building_rule > building_ruleset
A set of building rules.
int x_
The x dimension of the map.
const rule_image * operator->() const
constraint_set constraints
The set of [tile] constraints of this rule.
static std::map< std::string, std::string > images
bool sorted_images
Indicates if 'images' is sorted.
static void set_terrain_rules_cfg(const config &cfg)
Set the config where we will parse the global terrain rules.
bool random_start
Indicate if the animation uses a random shift.
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 r...
map_location location_constraints
The location on which this map may match.
bool terrain_matches(const t_translation::t_terrain &tcode, const t_translation::t_list &terrains) const
Checks whether a terrain code matches a given list of terrain codes.
this module manages the cache of images.
std::string image_string
A string representing either the filename for an image, or a list of images, with an optional timing ...
std::string variations
A semi-solon separated list of string used to replace.
void parse_config(const config &cfg, bool local=true)
Parses a configuration object containing [terrain_graphics] rules, and fills the building_rules_ memb...
imagelist images_foreground
The list of images which are in front of the unit sprites, attached to this tile. ...
A config object defines a single node in a WML file, with access to child nodes.
void parse_global_config(const config &cfg)
void clear()
Clears all data in this tile, and resets the cache.
std::vector< std::string > no_flag
GLsizei const GLcharARB ** string
bool start_animation(building_rule &rule)
Starts the animation on a rule.
bool on_map(const map_location &loc) const
Tests if a location is on the map.
const gamemap & map() const
std::vector< t_terrain > t_list
const imagelist * 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 ...