20 #define GETTEXT_DOMAIN "wesnoth-lib"
31 #define ERR_G LOG_STREAM(err, lg::general())
32 #define WRN_G LOG_STREAM(warn, lg::general())
233 while(offset < str.length()) {
237 const size_t pos_separator = str.find_first_of(separators, offset);
244 result.push_back(tile);
247 if(pos_separator == std::string::npos) {
248 offset = str.length();
250 offset = pos_separator + 1;
261 t_list::const_iterator
itor = list.begin();
262 for( ; itor != list.end(); ++
itor) {
263 if(itor == list.begin()) {
278 size_t x = 0,
y = 0,
width = 0;
286 if((offset + 1) >= str.length()) {
290 while(offset < str.length()) {
294 const size_t pos_separator = str.find_first_of(separators, offset);
303 if(!starting_position.empty()) {
304 if (starting_positions.left.find(starting_position) != starting_positions.left.end()) {
305 WRN_G <<
"Starting position " << starting_position <<
" is redefined." << std::endl;
307 starting_positions.insert(tstarting_positions::value_type(starting_position,
coordinate(x - border_offset.
x,
y - border_offset.
y)));
315 if(result.size() <=
x) {
316 result.resize(x + 1);
318 if(result[x].
size() <=
y) {
319 result[
x].resize(
y + 1);
326 if(pos_separator == std::string::npos ||
utils::isnewline(str[pos_separator])) {
332 if((x + 1) !=
width ) {
333 ERR_G <<
"Map not a rectangle error occurred at line offset " <<
y <<
" position offset " << x << std::endl;
334 throw error(
"Map not a rectangle.");
338 throw error(
"Map height limit exceeded.");
347 if(pos_separator == std::string::npos) {
348 offset = str.length();
352 offset = pos_separator + 1;
361 offset = pos_separator + 1;
364 throw error(
"Map width limit exceeded.");
370 if(x != 0 && (x + 1) !=
width) {
371 ERR_G <<
"Map not a rectangle error occurred at the end" << std::endl;
372 throw error(
"Map not a rectangle.");
380 std::stringstream str;
382 for(
size_t y = 0;
y < map[0].size(); ++
y) {
383 for(
size_t x = 0;
x < map.size(); ++
x) {
389 auto itor = starting_positions.right.find(
coordinate(
x - border_offset.
x,
y - border_offset.
y));
391 if (
itor != starting_positions.right.end()) {
392 starting_position =
itor->second;
401 if (
y < map[0].
size() -1)
425 std::cerr << std::hex <<
"src = " << src.
base <<
"^" << src.
overlay <<
"\t"
426 << src_mask.base <<
"^" << src_mask.overlay <<
"\t"
427 << masked_src.base <<
"^" << masked_src.overlay <<
"\t"
428 << src_has_wildcard <<
"\n";
432 t_list::const_iterator
itor = dest.begin();
435 for(; itor != dest.end(); ++
itor) {
455 const t_terrain masked_dest = (*itor & dest_mask);
458 std::cerr << std::hex <<
"dest= "
459 << itor->base <<
"^" << itor->overlay <<
"\t"
460 << dest_mask.
base <<
"^" << dest_mask.
overlay <<
"\t"
461 << masked_dest.
base <<
"^" << masked_dest.
overlay <<
"\t"
462 << dest_has_wildcard <<
"\n";
464 if(dest_has_wildcard &&
510 t_list::const_iterator
end = dest.
terrain.end();
511 for(t_list::const_iterator terrain_itor = dest.
terrain.begin();
513 ++
i, ++terrain_itor) {
516 if(*terrain_itor == STAR) {
521 if(*terrain_itor == NOT) {
527 if(*terrain_itor == src) {
577 t_list::const_iterator
itor = list.begin();
578 for(; itor != list.end(); ++
itor) {
599 if((offset + 1) >= str.length()) {
604 while(offset < str.length()) {
608 const size_t pos_separator = str.find_first_of(separators, offset);
613 if(pos_separator != offset) {
614 terrain = str.substr(offset, pos_separator - offset);
621 if(result.size() <=
y) {
622 result.resize(
y + 1);
624 if(result[
y].
size() <= x) {
625 result[
y].resize(x + 1);
632 if(pos_separator == std::string::npos) {
638 offset = str.length();
644 offset = pos_separator + 1;
652 offset = pos_separator + 1;
671 if((terrain & 0xFF000000) == 0x2A000000)
return 0x00000000;
672 if((terrain & 0x00FF0000) == 0x002A0000)
return 0xFF000000;
673 if((terrain & 0x0000FF00) == 0x00002A00)
return 0xFFFF0000;
674 if((terrain & 0x000000FF) == 0x0000002A)
return 0xFFFFFF00;
699 size_t size = end - begin;
706 VALIDATE(size <= 4,
_(
"A terrain with a string with more "
707 "than 4 characters has been found, the affected terrain is :") +
std::string(begin, end));
713 for(
size_t i = 0;
i < 4; ++
i) {
714 const unsigned char c = (
i <
size) ? begin[
i] : 0;
734 const char* c_str = str.c_str();
736 size_t end = str.size();
741 begin = str.find_first_not_of(whitespace);
742 end = str.find_last_not_of(whitespace) + 1;
743 if(begin == std::string::npos) {
748 size_t offset = str.find(
' ', begin);
751 start_position = str.substr(begin, offset - begin);
758 offset = str.find(
'^', 0);
759 if(offset != std::string::npos) {
761 const std::string overlay_str(str, offset + 1, str.size());
782 if(!start_position.empty()) {
783 result = start_position +
" ";
791 unsigned char tcode[9] = {0};
793 tcode[0] = ((terrain.
base & 0xFF000000) >> 24);
794 tcode[1] = ((terrain.
base & 0x00FF0000) >> 16);
795 tcode[2] = ((terrain.
base & 0x0000FF00) >> 8);
796 tcode[3] = (terrain.
base & 0x000000FF);
800 tcode[5] = ((terrain.
overlay & 0xFF000000) >> 24);
801 tcode[6] = ((terrain.
overlay & 0x00FF0000) >> 16);
802 tcode[7] = ((terrain.
overlay & 0x0000FF00) >> 8);
803 tcode[8] = (terrain.
overlay & 0x000000FF);
810 for(
int i = 0;
i < 9; ++
i) {
811 if(tcode[
i] != 0 && tcode[
i] != 0xFF) {
814 if(
i == 4 && tcode[
i] == 0) {
827 str.erase(0, str.find_first_not_of(whitespace));
829 str.erase(str.find_last_not_of(whitespace) + 1);
854 int main(
int argc,
char** argv)
864 std::cout <<
"Match\n" ;
866 std::cout <<
"No match\n";
static t_terrain string_to_builder_number_(std::string str)
Converts a terrain string to a number for the builder.
Contains an x and y coordinate used for starting positions in maps.
tformula< unsigned > x_
The x coordinate of the rectangle.
boost::bimaps::bimap< boost::bimaps::set_of< std::string >, boost::bimaps::multiset_of< coordinate >> tstarting_positions
const t_terrain UNDERGROUND_VILLAGE
t_list read_list(const std::string &str, const t_layer filler)
Reads a list of terrains from a string, when reading the.
std::string write_game_map(const t_map &map, const tstarting_positions &starting_positions, coordinate border_offset)
Write a gamemap in to a vector string.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
size_t max_map_size()
Return the maximum allowed map size (in either dimension), the maximum map area is, therefore, this value squared.
static l_noret error(LoadState *S, const char *why)
static t_layer get_layer_mask_(t_layer terrain)
Get the mask for a single layer.
static t_terrain string_to_number_(std::string str, std::string &start_position, const t_layer filler)
Converts a terrain string to a number.
t_map read_game_map(const std::string &str, tstarting_positions &starting_positions, coordinate border_offset)
Reads a gamemap string into a 2D vector.
bool has_wildcard(const t_terrain &tcode)
Tests whether a terrain code contains a wildcard.
const t_terrain DEEP_WATER
GLint GLint GLint GLint GLint GLint y
const std::string number
template to number regex
const t_terrain OFF_MAP_USER
t_terrain read_terrain_code(const std::string &str, const t_layer filler)
Reads a single terrain from a string.
const t_terrain HUMAN_KEEP
GLdouble GLdouble GLdouble b
std::vector< std::vector< t_terrain > > t_map
static UNUSEDNOWARN std::string _(const char *str)
const t_terrain GRASS_LAND
const t_match ALL_FORESTS
std::string write_list(const t_list &list)
Writes a list of terrains to a string, only writes the new format.
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
This structure can be used for matching terrain strings.
const t_terrain DWARVEN_CASTLE
static const ::config * terrain
The terrain used to create the cache.
Templates and utility-routines for strings and numbers.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
const t_terrain HUMAN_CASTLE
std::map< std::string, tfilter >::iterator itor
const t_match ALL_MOUNTAINS("!,*^V*,!,M*")
static t_terrain get_mask_(const t_terrain &terrain)
Gets a mask for a terrain, this mask is used for wildcard matching.
const t_terrain CAVE_WALL
static std::string number_to_string_(t_terrain terrain, const std::string &start_position="")
Converts a terrain number to a string.
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
tformula< unsigned > y_
The y coordinate of the rectangle.
const t_terrain DWARVEN_KEEP
int main(int argc, char **argv)
bool isnewline(const char c)
std::string write_terrain_code(const t_terrain &tcode)
Writes a single terrain code to a string.
const t_terrain VOID_TERRAIN
To lexical_cast_default(From a, To def=To())
Standard logging facilities (interface).
const t_match ALL_SWAMPS("!,*^V*,*^B*,!,S*")
GLint GLint GLint GLint GLint GLint GLsizei width
const t_terrain SHALLOW_WATER
Thrown when a lexical_cast fails.
GLsizei const GLcharARB ** string
static t_layer string_to_layer_(const char *begin, const char *end)
Converts a string to a layer.
t_map read_builder_map(const std::string &str)
Reads a builder map.
const t_match ALL_HILLS("!,*^V*,!,H*")
std::vector< t_terrain > t_list