00001 /* $Id: builder.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2004 - 2012 by Philippe Plantier <ayin@anathas.org> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 /** 00017 * @file 00018 * Definitions for the terrain builder. 00019 */ 00020 00021 #ifndef BUILDER_H_INCLUDED 00022 #define BUILDER_H_INCLUDED 00023 00024 #include "animated.hpp" 00025 #include "map_location.hpp" 00026 #include "terrain_translation.hpp" 00027 00028 class config; 00029 class gamemap; 00030 namespace image{ class locator; } 00031 /** 00032 * The class terrain_builder is constructed from a config object, and a 00033 * gamemap object. On construction, it parses the configuration and extracts 00034 * the list of [terrain_graphics] rules. Each terrain_graphics rule attaches 00035 * one or more images to a specific terrain pattern. 00036 * It then applies the rules loaded from the configuration to the current map, 00037 * and calculates the list of images that must be associated to each hex of 00038 * the map. 00039 * 00040 * The get_terrain_at method can then be used to obtain the list of images 00041 * necessary to draw the terrain on a given tile. 00042 */ 00043 class terrain_builder 00044 { 00045 public: 00046 /** Used as a parameter for the get_terrain_at function. */ 00047 enum TERRAIN_TYPE { 00048 BACKGROUND, /**< 00049 * Represents terrains which are to be 00050 * drawn behind unit sprites 00051 */ 00052 FOREGROUND /**< 00053 * Represents terrains which are to be 00054 * drawn in front of them. 00055 */ 00056 }; 00057 00058 /** The tile width used when using basex and basey. This is not, 00059 * necessarily, the tile width in pixels, this is totally 00060 * arbitrary. However, it will be set to 72 for convenience. 00061 */ 00062 static const int TILEWIDTH = 72; 00063 00064 /** The position of unit graphics in a tile. Graphics whose y 00065 * position is below this value are considered background for 00066 * this tile; graphics whose y position is above this value are 00067 * considered foreground. 00068 */ 00069 static const int UNITPOS = 36 + 18; 00070 00071 static const unsigned int DUMMY_HASH = 0; 00072 00073 /** A shorthand typedef for a list of animated image locators, 00074 * the base data type returned by the get_terrain_at method. 00075 */ 00076 typedef std::vector<animated<image::locator> > imagelist; 00077 00078 /** Constructor for the terrain_builder class. 00079 * 00080 * @param level A level (scenario)-specific configuration file, 00081 * containing scenario-specific [terrain_graphics] rules. 00082 * @param map A properly-initialized gamemap object representing 00083 * the current terrain map. 00084 * @param offmap_image The filename of the image which will be used as 00085 * off map image (see add_off_map_rule()). 00086 * This image automatically gets the 'terrain/' prefix 00087 * and '.png' suffix 00088 */ 00089 terrain_builder(const config &level, const gamemap* map, 00090 const std::string& offmap_image); 00091 00092 /** Set the config where we will parse the global terrain rules. 00093 * This also flushes the terrain rules cache. 00094 * 00095 * @param cfg The main grame configuration object, where the 00096 * [terrain_graphics] rule reside. 00097 */ 00098 static void set_terrain_rules_cfg(const config& cfg); 00099 00100 const gamemap& map() const { return *map_; } 00101 00102 /** 00103 * Updates internals that cache map size. This should be called when the map 00104 * size has changed. 00105 */ 00106 void reload_map(); 00107 00108 void change_map(const gamemap* m); 00109 00110 /** Returns a vector of strings representing the images to load & blit 00111 * together to get the built content for this tile. 00112 * 00113 * @param loc The location relative the the terrain map, 00114 * where we ask for the image list 00115 * @param tod The string representing the current time-of day. 00116 * Will be used if some images specify several 00117 * time-of-day- related variants. 00118 * @param terrain_type BACKGROUND or FOREGROUND, 00119 * depending on whether we ask for the terrain which is 00120 * before, or after the unit sprite. 00121 * 00122 * @return Returns a pointer list of animated images corresponding 00123 * to the parameters, or NULL if there is none. 00124 */ 00125 const imagelist *get_terrain_at(const map_location &loc, 00126 const std::string &tod, TERRAIN_TYPE const terrain_type); 00127 00128 /** Updates the animation at a given tile. 00129 * Returns true if something has changed, and must be redrawn. 00130 * 00131 * @param loc the location to update 00132 * 00133 * @retval true: this tile must be redrawn. 00134 */ 00135 bool update_animation(const map_location &loc); 00136 00137 /** Performs a "quick-rebuild" of the terrain in a given location. 00138 * The "quick-rebuild" is no proper rebuild: it only clears the 00139 * terrain cache for a given location, and replaces it with a single, 00140 * default image for this terrain. 00141 * 00142 * @param loc the location where to rebuild terrains 00143 */ 00144 void rebuild_terrain(const map_location &loc); 00145 00146 /** Performs a complete rebuild of the list of terrain graphics 00147 * attached to a map. 00148 * Should be called when a terrain is changed in the map. 00149 */ 00150 void rebuild_all(); 00151 00152 /** 00153 * An image variant. The in-memory representation of the [variant] 00154 * WML tag of the [image] WML tag. When an image only has one variant, 00155 * the [variant] tag may be omitted. 00156 */ 00157 struct rule_image_variant { 00158 /** Constructor for the normal defaut case */ 00159 rule_image_variant(const std::string &image_string, const std::string& variations, bool random_start = true) : 00160 image_string(image_string), 00161 variations(variations), 00162 images(), 00163 tods(), 00164 random_start(random_start) 00165 {}; 00166 00167 /** Constructor for true [variant] cases */ 00168 rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, bool random_start = true); 00169 00170 /** A string representing either the filename for an image, or 00171 * a list of images, with an optional timing for each image. 00172 * Corresponds to the "name" parameter of the [variant] (or of 00173 * the [image]) WML tag. 00174 * 00175 * The timing string is in the following format (expressed in EBNF) 00176 * 00177 *@verbatim 00178 * <timing_string> ::= <timed_image> ( "," <timed_image> ) + 00179 * 00180 * <timed_image> ::= <image_name> [ ":" <timing> ] 00181 * 00182 * Where <image_name> represents the actual filename of an image, 00183 * and <timing> the number of milliseconds this image will last 00184 * in the animation. 00185 *@endverbatim 00186 */ 00187 std::string image_string; 00188 00189 /** A semi-solon separated list of string used to replace 00190 * @verbatim <code>@V</code> @endverbatim in image_string (if present) 00191 */ 00192 std::string variations; 00193 00194 /** An animated image locator built according to the image string. 00195 * This will be the image locator which will actually 00196 * be returned to the user. 00197 */ 00198 std::vector< animated<image::locator> > images; 00199 00200 /** The Time of Day associated to this variant (if any)*/ 00201 std::set<std::string> tods; 00202 00203 /** Indicate if the animation uses a random shift */ 00204 bool random_start; 00205 }; 00206 00207 /** 00208 * Each terrain_graphics rule is associated a set of images, which are 00209 * applied on the terrain if the rule matches. An image is more than 00210 * graphics: it is graphics (with several possible tod-alternatives,) 00211 * and a position for these graphics. 00212 * The rule_image structure represents one such image. 00213 */ 00214 struct rule_image { 00215 rule_image(int layer, int x, int y, bool global_image=false, int center_x=-1, int center_y=-1); 00216 00217 bool is_background() const { 00218 return layer < 0 || (layer == 0 && basey < UNITPOS); 00219 } 00220 00221 /** The layer of the image for horizontal layering */ 00222 int layer; 00223 /** The position of the image base (that is, the point where 00224 * the image reaches the floor) for vertical layering 00225 */ 00226 int basex, basey; 00227 00228 /** A list of variants for this image */ 00229 std::vector<rule_image_variant> variants; 00230 00231 /** Set to true if the image was defined as a child of the 00232 * [terrain_graphics] tag, set to false if it was defined as a 00233 * child of a [tile] tag */ 00234 bool global_image; 00235 00236 /** The position where the center of the image base should be 00237 */ 00238 int center_x, center_y; 00239 }; 00240 00241 /** 00242 * A shorthand notation for a vector of rule_images 00243 */ 00244 typedef std::vector<rule_image> rule_imagelist; 00245 00246 /** 00247 * The in-memory representation of a [tile] WML rule 00248 * inside of a [terrain_graphics] WML rule. 00249 */ 00250 struct terrain_constraint 00251 { 00252 terrain_constraint() : 00253 loc(), 00254 terrain_types_match(), 00255 set_flag(), 00256 no_flag(), 00257 has_flag(), 00258 images() 00259 {}; 00260 00261 terrain_constraint(map_location loc) : 00262 loc(loc), 00263 terrain_types_match(), 00264 set_flag(), 00265 no_flag(), 00266 has_flag(), 00267 images() 00268 {}; 00269 00270 map_location loc; 00271 t_translation::t_match terrain_types_match; 00272 std::vector<std::string> set_flag; 00273 std::vector<std::string> no_flag; 00274 std::vector<std::string> has_flag; 00275 rule_imagelist images; 00276 }; 00277 00278 /** 00279 * Represents a tile of the game map, with all associated 00280 * builder-specific parameters: flags, images attached to this tile, 00281 * etc. An array of those tiles is built when terrains are built either 00282 * during construction, or upon calling the rebuild_all() method. 00283 */ 00284 struct tile 00285 { 00286 /** Contructor for the tile() structure */ 00287 tile(); 00288 00289 struct rule_image_rand; 00290 typedef std::pair<const rule_image_rand*, const rule_image_variant*> log_details; 00291 typedef std::vector<log_details> logs; 00292 /** Rebuilds the whole image cache, for a given time-of-day. 00293 * Must be called when the time-of-day has changed, 00294 * to select the correct images. 00295 * 00296 * @param tod The current time-of-day 00297 */ 00298 void rebuild_cache(const std::string &tod, logs* log = NULL); 00299 00300 /** Clears all data in this tile, and resets the cache */ 00301 void clear(); 00302 00303 /** The list of flags present in this tile */ 00304 std::set<std::string> flags; 00305 00306 /** Represent a rule_image applied with a random seed.*/ 00307 struct rule_image_rand{ 00308 rule_image_rand(const rule_image* r_i, unsigned int rnd) : ri(r_i), rand(rnd) {} 00309 00310 const rule_image* operator->() const {return ri;} 00311 /** sort by layer first then by basey */ 00312 bool operator<(const rule_image_rand& o) const { 00313 return ri->layer < o.ri->layer || 00314 (ri->layer == o.ri->layer && ri->basey < o.ri->basey);} 00315 00316 const rule_image* ri; 00317 unsigned int rand; 00318 }; 00319 00320 /** The list of rule_images and random seeds associated to this tile. 00321 */ 00322 std::vector<rule_image_rand> images; 00323 00324 /** The list of images which are in front of the unit sprites, 00325 * attached to this tile. This member is considered a cache: 00326 * it is built once, and on-demand. 00327 */ 00328 imagelist images_foreground; 00329 /** The list of images which are behind the unit sprites, 00330 * attached to this tile. This member is considered a cache: 00331 * it is built once, and on-demand. 00332 */ 00333 imagelist images_background; 00334 /** 00335 * The time-of-day to which the image caches correspond. 00336 */ 00337 std::string last_tod; 00338 00339 /** Indicates if 'images' is sorted */ 00340 bool sorted_images; 00341 }; 00342 00343 tile* get_tile(const map_location &loc); 00344 00345 private: 00346 /** 00347 * The list of constraints attached to a terrain_graphics WML rule. 00348 */ 00349 typedef std::vector<terrain_constraint> constraint_set; 00350 00351 /** 00352 * The in-memory representation of a [terrain_graphics] WML rule. 00353 */ 00354 struct building_rule 00355 { 00356 building_rule() : 00357 constraints(), 00358 location_constraints(), 00359 probability(100), 00360 precedence(0), 00361 local(false), 00362 hash_(DUMMY_HASH) 00363 {} 00364 00365 /** 00366 * The set of [tile] constraints of this rule. 00367 */ 00368 constraint_set constraints; 00369 00370 /** 00371 * The location on which this map may match. 00372 * Set to a valid map_location if the "x" and "y" parameters 00373 * of the [terrain_graphics] rule are set. 00374 */ 00375 map_location location_constraints; 00376 00377 /** 00378 * The probability of this rule to match, when all conditions 00379 * are met. Defined if the "probability" parameter of the 00380 * [terrain_graphics] element is set. 00381 */ 00382 int probability; 00383 00384 /** 00385 * Ordering relation between the rules. 00386 */ 00387 int precedence; 00388 00389 /** 00390 * Indicate if the rule is only for this scenario 00391 */ 00392 bool local; 00393 00394 bool operator<(building_rule const &that) const 00395 { return precedence < that.precedence; } 00396 00397 unsigned int get_hash() const; 00398 private: 00399 mutable unsigned int hash_; 00400 }; 00401 00402 /** 00403 * The map of "tile" structures corresponding to the level map. 00404 */ 00405 class tilemap 00406 { 00407 public: 00408 /** 00409 * Constructs a tilemap of dimensions x * y 00410 */ 00411 tilemap(int x, int y) : 00412 tiles_((x + 4) * (y + 4)), 00413 x_(x), 00414 y_(y) 00415 {reset();} 00416 00417 /** 00418 * Returns a reference to the tile which is at the position 00419 * pointed by loc. The location MUST be on the map! 00420 * 00421 * @param loc The location of the tile 00422 * 00423 * @return A reference to the tile at this location. 00424 * 00425 */ 00426 tile &operator[](const map_location &loc); 00427 /** 00428 * a const variant of operator[] 00429 */ 00430 const tile &operator[] (const map_location &loc) const; 00431 00432 /** 00433 * Tests if a location is on the map. 00434 * 00435 * @param loc The location to test 00436 * 00437 * @return true if loc is on the map, false otherwise. 00438 */ 00439 bool on_map(const map_location &loc) const; 00440 00441 /** 00442 * Resets the whole tile map 00443 */ 00444 void reset(); 00445 00446 /** 00447 * Rebuilds the map to a new set of dimensions 00448 */ 00449 void reload(int x, int y); 00450 private: 00451 /** The map */ 00452 std::vector<tile> tiles_; 00453 /** The x dimension of the map */ 00454 int x_; 00455 /** The y dimension of the map */ 00456 int y_; 00457 }; 00458 00459 /** 00460 * A set of building rules. In-memory representation 00461 * of the whole set of [terrain_graphics] rules. 00462 */ 00463 typedef std::multiset<building_rule> building_ruleset; 00464 00465 /** 00466 * Load images and tests for validity of a rule. A rule is considered 00467 * valid if all its images are present. This method is used, when building 00468 * the ruleset, to only add rules which are valid to the ruleset. 00469 * 00470 * @param rule The rule to test for validity 00471 * 00472 * @return true if the rule is valid, false if it is not. 00473 */ 00474 bool load_images(building_rule &rule); 00475 00476 /** 00477 * Starts the animation on a rule. 00478 * 00479 * @param rule The rule on which ot start animations 00480 * 00481 * @return true 00482 */ 00483 bool start_animation(building_rule &rule); 00484 00485 /** 00486 * "Rotates" a constraint from a rule. 00487 * Takes a template constraint from a template rule, and rotates 00488 * to the given angle. 00489 * 00490 * On a constraint, the relative position of each rule, and the "base" 00491 * of each vertical images, are rotated according to the given angle. 00492 * 00493 * Template terrain constraints are defined like normal terrain 00494 * constraints, except that, flags, and image filenames, 00495 * may contain template strings of the form 00496 *@verbatim 00497 * <code>@Rn</code>, 00498 *@endverbatim 00499 * n being a number from 0 to 5. 00500 * See the rotate_rule method for more info. 00501 * 00502 * @param constraint A template constraint to rotate 00503 * @param angle An int, from 0 to 5, representing the rotation angle. 00504 */ 00505 void rotate(terrain_constraint &constraint, int angle); 00506 00507 /** 00508 * Replaces, in a given string, rotation tokens with their values. 00509 * 00510 * @param s the string in which to do the replacement 00511 * @param angle the angle for substituting the correct replacement. 00512 * @param replacement the replacement strings. 00513 */ 00514 void replace_rotate_tokens(std::string &s, int angle, 00515 const std::vector<std::string> &replacement); 00516 00517 /** 00518 * Replaces, in a given rule_image, rotation tokens with their values. 00519 * The actual substitution is done in all variants of the given image. 00520 * 00521 * @param image the rule_image in which to do the replacement. 00522 * @param angle the angle for substituting the correct replacement. 00523 * @param replacement the replacement strings. 00524 */ 00525 void replace_rotate_tokens(rule_image &image, int angle, 00526 const std::vector<std::string> &replacement); 00527 00528 /** 00529 * Replaces, in a given rule_variant_image, rotation tokens with their values. 00530 * The actual substitution is done in the "image_string" parameter 00531 * of this rule_variant_image. 00532 * 00533 * @param variant the rule_variant_image in which to do the replacement. 00534 * @param angle the angle for substituting the correct replacement. 00535 * @param replacement the replacement strings. 00536 */ 00537 void replace_rotate_tokens(rule_image_variant &variant, int angle, 00538 const std::vector<std::string> &replacement) 00539 { replace_rotate_tokens(variant.image_string, angle, replacement); } 00540 00541 /** 00542 * Replaces, in a given rule_imagelist, rotation tokens with their values. 00543 * The actual substitution is done in all rule_images contained 00544 * in the rule_imagelist. 00545 * 00546 * @param list the rule_imagelist in which to do the replacement. 00547 * @param angle the angle for substituting the correct replacement. 00548 * @param replacement the replacement strings. 00549 */ 00550 void replace_rotate_tokens(rule_imagelist &list, int angle, 00551 const std::vector<std::string> &replacement); 00552 00553 /** 00554 * Replaces, in a given building_rule, rotation tokens with their values. 00555 * The actual substitution is done in the rule_imagelists contained 00556 * in all constraints of the building_rule, and in the flags 00557 * (has_flag, set_flag and no_flag) contained in all constraints 00558 * of the building_rule. 00559 * 00560 * @param rule the building_rule in which to do the replacement. 00561 * @param angle the angle for substituting the correct replacement. 00562 * @param replacement the replacement strings. 00563 */ 00564 void replace_rotate_tokens(building_rule &rule, int angle, 00565 const std::vector<std::string> &replacement); 00566 00567 /** 00568 * Rotates a template rule to a given angle. 00569 * 00570 * Template rules are defined like normal rules, except that: 00571 * * Flags and image filenames may contain template strings of the form 00572 *@verbatim 00573 * <code>@Rn</code>, n being a number from 0 to 5. 00574 *@endverbatim 00575 * * The rule contains the rotations=r0,r1,r2,r3,r4,r5, with r0 to r5 00576 * being strings describing the 6 different positions, typically, 00577 * n, ne, se, s, sw, and nw (but maybe anything else.) 00578 * 00579 * A template rule will generate 6 rules, which are similar 00580 * to the template, except that: 00581 * 00582 * * The map of constraints ( [tile]s ) of this rule will be 00583 * rotated by an angle, of 0 to 5 pi / 6 00584 * 00585 * * On the rule which is rotated to 0rad, the template strings 00586 *@verbatim 00587 * @R0, @R1, @R2, @R3, @R4, @R5, 00588 *@endverbatim 00589 * will be replaced by the corresponding r0, r1, r2, r3, r4, r5 00590 * variables given in the rotations= element. 00591 * 00592 * * On the rule which is rotated to pi/3 rad, the template strings 00593 *@verbatim 00594 * @R0, @R1, @R2 etc. 00595 *@endverbatim 00596 * will be replaced by the corresponding 00597 * <strong>r1, r2, r3, r4, r5, r0</strong> (note the shift in indices). 00598 * 00599 * * On the rule rotated 2pi/3, those will be replaced by 00600 * r2, r3, r4, r5, r0, r1 and so on. 00601 * 00602 */ 00603 void rotate_rule(building_rule &rule, int angle, 00604 const std::vector<std::string> &angle_name); 00605 00606 /** 00607 * Parses a "config" object, which should contains [image] children, 00608 * and adds the corresponding parsed rule_images to a rule_imagelist. 00609 * 00610 * @param images The rule_imagelist into which to add the parsed images. 00611 * @param cfg The WML configuration object to parse 00612 * @param global Whether those [image]s elements belong to a 00613 * [terrain_graphics] element, or to a [tile] child. 00614 * Set to true if those belong to a [terrain_graphics] 00615 * element. 00616 * @param dx The X coordinate of the constraint those images 00617 * apply to, relative to the start of the rule. Only 00618 * meaningful if global is set to false. 00619 * @param dy The Y coordinate of the constraint those images 00620 * apply to. 00621 */ 00622 void add_images_from_config(rule_imagelist &images, const config &cfg, bool global, 00623 int dx=0, int dy=0); 00624 00625 00626 /** 00627 * Creates a rule constraint object which matches a given list of 00628 * terrains, and adds it to the list of constraints of a rule. 00629 * 00630 * @param constraints The constraint set to which to add the constraint. 00631 * @param loc The location of the constraint 00632 * @param type The list of terrains this constraint will match 00633 * @param global_images A configuration object containing [image] tags 00634 * describing rule-global images. 00635 */ 00636 terrain_constraint &add_constraints(constraint_set& constraints, 00637 const map_location &loc, const t_translation::t_match& type, 00638 const config& global_images); 00639 00640 /** 00641 * Creates a rule constraint object from a config object and 00642 * adds it to the list of constraints of a rule. 00643 * 00644 * @param constraints The constraint set to which to add the constraint. 00645 * @param loc The location of the constraint 00646 * @param cfg The config object describing this constraint. 00647 * Usually, a [tile] child of a [terrain_graphics] rule. 00648 * @param global_images A configuration object containing [image] tags 00649 * describing rule-global images. 00650 */ 00651 void add_constraints(constraint_set& constraints, 00652 const map_location &loc, const config &cfg, 00653 const config& global_images); 00654 00655 typedef std::multimap<int, map_location> anchormap; 00656 00657 /** 00658 * Parses a map string (the map= element of a [terrain_graphics] rule, 00659 * and adds constraints from this map to a building_rule. 00660 * 00661 * @param mapstring The map vector to parse 00662 * @param br The building rule into which to add the extracted 00663 * constraints 00664 * @param anchors A map where to put "anchors" extracted from the map. 00665 * @param global_images A config object representing the images defined 00666 * as direct children of the [terrain_graphics] rule. 00667 */ 00668 void parse_mapstring(const std::string &mapstring, struct building_rule &br, 00669 anchormap& anchors, const config& global_images); 00670 00671 /** 00672 * Adds a rule to a ruleset. Checks for validity before adding the rule. 00673 * 00674 * @param rules The ruleset into which to add the rules. 00675 * @param rule The rule to add. 00676 */ 00677 void add_rule(building_ruleset& rules, building_rule &rule); 00678 00679 /** 00680 * Adds a set of rules to a ruleset, from a template rule which spans 00681 * 6 rotations (or less if some of the rotated rules are invalid). 00682 * 00683 * @param rules The ruleset into which to add the rules. 00684 * @param tpl The template rule 00685 * @param rotations A comma-separated string containing the 00686 * 6 values for replacing rotation template 00687 * template strings @verbatim (@Rn) @endverbatim 00688 */ 00689 void add_rotated_rules(building_ruleset& rules, building_rule& tpl, 00690 const std::string &rotations); 00691 00692 /** 00693 * Parses a configuration object containing [terrain_graphics] rules, 00694 * and fills the building_rules_ member of the current class according 00695 * to those. 00696 * 00697 * @param cfg The configuration object to parse. 00698 * @param local Mark the rules as local only. 00699 */ 00700 void parse_config(const config &cfg, bool local = true); 00701 00702 void parse_global_config(const config &cfg) { parse_config(cfg, false); } 00703 00704 /** 00705 * Adds a builder rule for the _off^_usr tile, this tile only has 1 image. 00706 * 00707 * @param image The filename of the image 00708 */ 00709 void add_off_map_rule(const std::string& image); 00710 00711 void flush_local_rules(); 00712 00713 /** 00714 * Checks whether a terrain code matches a given list of terrain codes. 00715 * 00716 * @param tcode The terrain to check 00717 * @param terrains The terrain list agains which to check the terrain. 00718 * May contain the metacharacters 00719 * - '*' STAR, meaning "all terrains" 00720 * - '!' NOT, meaning "all terrains except those present in the list." 00721 * 00722 * @return returns true if "tcode" matches the list or the list is empty, 00723 * else false. 00724 */ 00725 bool terrain_matches(t_translation::t_terrain tcode, const t_translation::t_list& terrains) const 00726 { return terrains.empty()? true : t_translation::terrain_matches(tcode, terrains); } 00727 00728 /** 00729 * Checks whether a terrain code matches a given list of terrain tcodes. 00730 * 00731 * @param tcode The terrain code to check 00732 * @param terrain The terrain match structure which to check the terrain. 00733 * See previous definition for more details. 00734 * 00735 * @return returns true if "tcode" matches the list or the list is empty, 00736 * else false. 00737 */ 00738 bool terrain_matches(t_translation::t_terrain tcode, const t_translation::t_match &terrain) const 00739 { return terrain.is_empty ? true : t_translation::terrain_matches(tcode, terrain); } 00740 00741 /** 00742 * Checks whether a rule matches a given location in the map. 00743 * 00744 * @param rule The rule to check. 00745 * @param loc The location in the map where we want to check 00746 * whether the rule matches. 00747 * @param type_checked The constraint which we already know that its 00748 * terrain types matches. 00749 */ 00750 bool rule_matches(const building_rule &rule, const map_location &loc, const terrain_constraint *type_checked) const; 00751 00752 /** 00753 * Applies a rule at a given location: applies the result of a 00754 * matching rule at a given location: attachs the images corresponding 00755 * to the rule, and sets the flags corresponding to the rule. 00756 * 00757 * @param rule The rule to apply 00758 * @param loc The location to which to apply the rule. 00759 */ 00760 void apply_rule(const building_rule &rule, const map_location &loc); 00761 00762 /** 00763 * Calculates the list of terrains, and fills the tile_map_ member, 00764 * from the gamemap and the building_rules_. 00765 */ 00766 void build_terrains(); 00767 00768 /** 00769 * A pointer to the gamemap class used in the current level. 00770 */ 00771 const gamemap* map_; 00772 00773 /** 00774 * The tile_map_ for the current level, which is filled by the 00775 * build_terrains_ method to contain "tiles" representing images 00776 * attached to each tile. 00777 */ 00778 tilemap tile_map_; 00779 00780 /** 00781 * Shorthand typedef for a map associating a list of locations to a terrain type. 00782 */ 00783 typedef std::map<t_translation::t_terrain, std::vector<map_location> > terrain_by_type_map; 00784 00785 /** 00786 * A map representing all locations whose terrain is of a given type. 00787 */ 00788 terrain_by_type_map terrain_by_type_; 00789 00790 /** Parsed terrain rules. Cached between instances */ 00791 static building_ruleset building_rules_; 00792 00793 /** Config used to parse global terrain rules */ 00794 static const config* rules_cfg_; 00795 }; 00796 00797 #endif
| Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:34 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |