Little style fixes for the multi-hex tiling code
Adding support for wildcards in terrain selectors
This commit is contained in:
parent
405610f2b0
commit
effdcfdc1e
3 changed files with 17 additions and 7 deletions
|
@ -20,7 +20,7 @@ terrain_builder::terrain_builder(const config& cfg, const gamemap& gmap) :
|
|||
map_(gmap), tile_map_(gmap.x(), gmap.y())
|
||||
{
|
||||
parse_config(cfg);
|
||||
build_terrains(cfg);
|
||||
build_terrains();
|
||||
}
|
||||
|
||||
const std::vector<image::locator> *terrain_builder::get_terrain_at(const gamemap::location &loc,
|
||||
|
@ -41,6 +41,10 @@ const std::vector<image::locator> *terrain_builder::get_terrain_at(const gamemap
|
|||
|
||||
void terrain_builder::rebuild_terrain(const gamemap::location &loc)
|
||||
{
|
||||
tile_map_.clear();
|
||||
// For now, rebuild the whole map on each rebuilt_terrain. This is highly slow and
|
||||
// inefficient, but this is simple
|
||||
build_terrains();
|
||||
}
|
||||
|
||||
terrain_builder::terrain_constraint terrain_builder::rotate(const terrain_builder::terrain_constraint &constraint, int angle)
|
||||
|
@ -125,8 +129,8 @@ terrain_builder::building_rule terrain_builder::rotate_rule(const terrain_builde
|
|||
}
|
||||
|
||||
void terrain_builder::add_constraints(std::map<gamemap::location, terrain_builder::terrain_constraint> & constraints,
|
||||
const gamemap::location &loc, std::string type,
|
||||
std::string set_flag, std::string no_flag)
|
||||
const gamemap::location& loc, const std::string& type,
|
||||
const std::string& set_flag, const std::string& no_flag)
|
||||
{
|
||||
if(constraints.find(loc) == constraints.end()) {
|
||||
//the terrain at the current location did not exist, so create it
|
||||
|
@ -337,7 +341,7 @@ void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, con
|
|||
}
|
||||
}
|
||||
|
||||
void terrain_builder::build_terrains(const config& cfg)
|
||||
void terrain_builder::build_terrains()
|
||||
{
|
||||
std::cerr << "Built terrain rules: \n";
|
||||
|
||||
|
|
|
@ -73,6 +73,8 @@ private:
|
|||
|
||||
tile &operator[](const gamemap::location &loc) { return map_[(loc.x+1) + (loc.y+1)*(x_+2)]; }
|
||||
const tile &operator[] (const gamemap::location &loc) const { return map_[(loc.x+1) + (loc.y+1)*(x_+2)]; }
|
||||
void clear() { map_.clear(); }
|
||||
|
||||
std::vector<tile> map_;
|
||||
int x_;
|
||||
int y_;
|
||||
|
@ -83,15 +85,15 @@ private:
|
|||
|
||||
building_rule rotate_rule(const building_rule &rule, int angle, const std::string &angle_name);
|
||||
void add_constraints(std::map<gamemap::location, terrain_constraint>& constraints,
|
||||
const gamemap::location &loc, std::string type,
|
||||
std::string set_flag = "", std::string no_flag = "");
|
||||
const gamemap::location &loc, const std::string& type,
|
||||
const std::string& set_flag = "", const std::string& no_flag = "");
|
||||
void parse_mapstring(const std::string &mapstring, struct building_rule &br,
|
||||
std::map<int, gamemap::location>& anchors);
|
||||
|
||||
void parse_config(const config &cfg);
|
||||
bool rule_matches(const building_rule &rule, const gamemap::location &loc);
|
||||
void apply_rule(const building_rule &rule, const gamemap::location &loc);
|
||||
void build_terrains(const config& cfg);
|
||||
void build_terrains();
|
||||
|
||||
const gamemap& map_;
|
||||
tilemap tile_map_;
|
||||
|
|
|
@ -150,6 +150,10 @@ bool terrain_type::matches(const std::string &expression) const
|
|||
std::string types;
|
||||
bool negative = false;
|
||||
|
||||
// If there is a wildcard in the string, it matches.
|
||||
if(expression.find('*') != std::string::npos)
|
||||
return true;
|
||||
|
||||
if(expression[0] == '!') {
|
||||
types = expression.substr(1);
|
||||
negative = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue