39 #define ERR_CF LOG_STREAM(err, log_config)
40 #define LOG_G LOG_STREAM(info, lg::general())
41 #define DBG_G LOG_STREAM(debug, lg::general())
78 {
return tdata_->underlying_mvt_terrain(terrain); }
80 {
return tdata_->underlying_def_terrain(terrain); }
82 {
return tdata_->underlying_union_terrain(terrain); }
84 {
return tdata_->get_terrain_string(terrain); }
86 {
return tdata_->get_terrain_editor_string(terrain); }
88 {
return tdata_->get_underlying_terrain_string(terrain); }
90 {
return tdata_->get_terrain_info(terrain).is_village(); }
92 {
return tdata_->get_terrain_info(terrain).gives_healing(); }
94 {
return tdata_->get_terrain_info(terrain).is_castle(); }
96 {
return tdata_->get_terrain_info(terrain).is_keep(); }
99 {
return tdata_->get_terrain_info(terrain); }
112 tdata_ = gcm->terrain_types();
118 DBG_G <<
"loading map: '" <<
data <<
"'";
124 , starting_positions_()
140 if(allow_invalid)
return;
145 const std::string& data_only = std::string(
data, offset);
164 if(
tdata_->map().count(
t) == 0) {
166 std::stringstream ss;
168 <<
") '" <<
t <<
"'";
186 std::size_t header_offset =
data.find(
"\n\n");
187 if(header_offset == std::string::npos) {
192 header_offset =
data.find(
"\r\n\r\n");
194 const std::size_t comma_offset =
data.find(
",");
199 if (!(!(header_offset == std::string::npos || comma_offset < header_offset)))
202 std::string header_str(std::string(
data, 0, header_offset + 1));
204 ::read(header, header_str);
206 return header_offset + 2;
217 int xpos = loc.
wml_x();
218 int ypos = loc.
wml_y();
220 const int xstart = std::max<int>(0, -xpos);
222 const int xoffset = xpos;
224 const int ystart_even = std::max<int>(0, -ypos);
226 const int yoffset_even = ypos;
228 const int ystart_odd = std::max<int>(0, -ypos +(xpos & 1) -(m_is_odd ? 1 : 0));
230 const int yoffset_odd = ypos -(xpos & 1) + (m_is_odd ? 1 : 0);
232 for(
int x1 = xstart; x1 != xend; ++x1) {
233 int ystart, yend, yoffset;
237 yoffset = yoffset_odd;
240 ystart = ystart_even;
242 yoffset = yoffset_even;
244 for(
int y1 = ystart; y1 != yend; ++y1) {
245 const int x2 = x1 + xoffset;
246 const int y2 = y1 + yoffset;
265 rule = ¤t_rule;
278 if (!ignore_special_locations) {
281 int x = pair.second.wml_x();
282 int y = pair.second.wml_y();
284 if(x < xstart || x >= xend || y < ystart_odd || y >= yend_odd) {
289 if(x < xstart || x >= xend || y < ystart_even || y >= yend_even) {
293 int x_new = x + xoffset;
294 int y_new = y + ((x & 1 ) ? yoffset_odd : yoffset_even);
330 bool is_number(
const std::string&
id) {
331 return std::find_if(
id.begin(),
id.end(), [](
char c) {
return !std::isdigit(
c); }) ==
id.
end();
339 const std::string&
id = pair.left;
341 res = std::max(res, std::stoi(
id));
350 if(is_number(*locName)) {
351 return std::stoi(*locName);
365 bool valid = loc.
valid();
387 return loc.
valid() && loc.
x <
w() && loc.
y <
h();
399 DBG_G <<
"set_terrain: " << loc <<
" is not on the map.";
412 const bool new_village =
tdata_->is_village(new_terrain);
414 if(old_village && !new_village) {
416 }
else if(!old_village && new_village) {
421 (*this)[loc] = new_terrain;
425 bool with_border)
const
427 std::vector<map_location> res;
430 int xmin = 1, xmax =
w(), ymin = 1, ymax =
h();
439 for (
unsigned i = 0;
i < xvals.size() ||
i < yvals.size(); ++
i)
441 std::pair<int,int> xrange, yrange;
443 if (
i < xvals.size()) {
445 if (xrange.first < xmin) xrange.first = xmin;
446 if (xrange.second > xmax) xrange.second = xmax;
449 xrange.second = xmax;
452 if (
i < yvals.size()) {
454 if (yrange.first < ymin) yrange.first = ymin;
455 if (yrange.second > ymax) yrange.second = ymax;
458 yrange.second = ymax;
461 for(
int x2 = xrange.first; x2 <= xrange.second; ++x2) {
462 for(
int y2 = yrange.first; y2 <= yrange.second; ++y2) {
463 res.emplace_back(x2-1,y2-1);
477 std::vector<map_location> res;
478 for(
int i = 1;
i <=
n;
i++) {
A config object defines a single node in a WML file, with access to child nodes.
static game_config_manager * get()
static game_config_view wrap(const config &cfg)
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
int w() const
Effective map width.
void set_starting_position(int side, const map_location &loc)
Manipulate starting positions of the different sides.
void set_special_location(const std::string &id, const map_location &loc)
int h() const
Effective map height.
void overlay(const gamemap_base &m, map_location loc, const std::vector< overlay_rule > &rules=std::vector< overlay_rule >(), bool is_odd=false, bool ignore_special_locations=false)
Overlays another map onto this one at the given position.
map_location special_location(const std::string &id) const
std::vector< map_location > parse_location_range(const std::string &xvals, const std::string &yvals, bool with_border=false) const
Parses ranges of locations into a vector of locations, using this map's dimensions as bounds.
map_location starting_position(int side) const
virtual void set_terrain(const map_location &loc, const terrain_code &terrain, const terrain_type_data::merge_mode mode=terrain_type_data::BOTH, bool replace_if_failed=false)=0
Clobbers over the terrain at location 'loc', with the given terrain.
int total_width() const
Real width of the map, including borders.
std::string to_string() const
int num_valid_starting_positions() const
Counts the number of sides that have valid starting positions on this map.
bool on_board_with_border(const map_location &loc) const
int total_height() const
Real height of the map, including borders.
int is_starting_position(const map_location &loc) const
returns the side number of the side starting at position loc, 0 if no such side exists.
location_map starting_positions_
const std::string * is_special_location(const map_location &loc) const
returns the name of the special location at position loc, null if no such location exists.
int border_size() const
Size of the map border.
const std::vector< map_location > starting_positions() const
bool on_board(const map_location &loc) const
Tell if a location is on the map.
location_map & special_locations()
const t_translation::ter_list & underlying_union_terrain(const map_location &loc) const
bool is_village(const map_location &loc) const
std::string get_underlying_terrain_string(const t_translation::terrain_code &terrain) const
bool is_castle(const map_location &loc) const
void read(const std::string &data, const bool allow_invalid=true)
const t_translation::ter_list & underlying_mvt_terrain(const map_location &loc) const
const t_translation::ter_list & underlying_def_terrain(const map_location &loc) const
const t_translation::ter_list & get_terrain_list() const
Gets the list of terrains.
std::string write() const
std::vector< map_location > villages_
std::string get_terrain_editor_string(const map_location &loc) const
void write_terrain(const map_location &loc, config &cfg) const
Writes the terrain at loc to cfg.
gamemap(const std::string &data)
Loads a map.
bool is_keep(const map_location &loc) const
std::string get_terrain_string(const map_location &loc) const
std::shared_ptr< terrain_type_data > tdata_
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
void set_terrain(const map_location &loc, const terrain_code &terrain, const terrain_type_data::merge_mode mode=terrain_type_data::BOTH, bool replace_if_failed=false) override
Clobbers over the terrain at location 'loc', with the given terrain.
int gives_healing(const map_location &loc) const
int read_header(const std::string &data)
Reads the header of a map which is saved in the deprecated map_data format.
Definitions for the interface to Wesnoth Markup Language (WML).
T end(const std::pair< T, T > &p)
Standard logging facilities (interface).
static lg::log_domain log_config("config")
ter_map read_game_map(std::string_view str, starting_positions &starting_positions, coordinate border_offset)
Reads a gamemap string into a 2D vector.
std::string write_game_map(const ter_map &map, const starting_positions &starting_positions, coordinate border_offset)
Write a gamemap in to a vector string.
const terrain_code VOID_TERRAIN
VOID_TERRAIN is used for shrouded hexes.
bool terrain_matches(const terrain_code &src, const terrain_code &dest)
Tests whether a specific terrain matches an expression, for matching rules see above.
std::vector< terrain_code > ter_list
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::string write_terrain_code(const terrain_code &tcode)
Writes a single terrain code to a string.
const terrain_code FOGGED
const terrain_code NONE_TERRAIN
std::size_t erase(Container &container, const Value &value)
Convenience wrapper for using std::remove on a container.
std::pair< int, int > parse_range(const std::string &str)
Recognises the following patterns, and returns a {min, max} pair.
std::vector< std::string > split(const config_attribute_value &val)
terrain_type_data::merge_mode mode_
utils::optional< t_translation::terrain_code > terrain_
Encapsulates the map of the game.
static const map_location & null_location()
terrain_code & get(int x, int y)
std::vector< terrain_code > data
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
static map_location::direction n
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.