31 #include <boost/functional/hash.hpp>
33 #define ERR_CF LOG_STREAM(err, config)
34 #define LOG_G LOG_STREAM(info, general)
35 #define DBG_G LOG_STREAM(debug, general)
38 s << (l.
x + 1) <<
',' << (l.
y + 1);
41 std::ostream &operator<<(std::ostream &s, std::vector<map_location>
const &
v) {
42 std::vector<map_location>::const_iterator
i =
v.begin();
43 for(; i!=
v.end(); ++
i) {
44 s <<
"(" << *i <<
") ";
64 boost::hash<size_t>
h;
65 return h( (a.
x << 16) ^ a.
y );
80 const size_t open = str.find_first_of(
'('), close = str.find_last_of(
')');
81 if (open != std::string::npos && close != std::string::npos) {
89 const size_t start = str[0] ==
'-' ? 1 : 0;
90 const size_t end = str.find_first_of(
':');
91 const std::string& main_dir = str.substr(start, end - start);
94 if (main_dir ==
"n") {
96 }
else if (main_dir ==
"ne") {
98 }
else if (main_dir ==
"se") {
100 }
else if (main_dir ==
"s") {
102 }
else if (main_dir ==
"sw") {
104 }
else if (main_dir ==
"nw") {
114 if (end != std::string::npos) {
116 if (rel_dir ==
"cw") {
118 }
else if (rel_dir ==
"ccw") {
131 std::vector<map_location::DIRECTION> to_return;
133 std::vector<std::string>::const_iterator
i, i_end=dir_strs.end();
134 for(i = dir_strs.begin(); i != i_end; ++
i) {
138 to_return.push_back(temp);
171 return _(
"North East");
173 return _(
"North West");
177 return _(
"South East");
179 return _(
"South West");
198 if(xs.empty() ==
false && xs !=
"recall")
199 x = std::stoi(xs) - 1;
201 if(ys.empty() ==
false && ys !=
"recall")
202 y = std::stoi(ys) - 1;
227 if (loc.
x%2==0 &&
x%2==1) dy--;
232 int dist_diag_SW_NE = abs(dy + (dx + (dy>0?0:1) )/2);
233 int dist_diag_SE_NW = abs(dy - (dx - (dy>0?0:1) )/2);
235 if (dy > 0) dir =
SOUTH;
238 if (dist_diag_SE_NW < dist) {
241 dist = dist_diag_SE_NW;
243 if (dist_diag_SW_NE < dist) {
271 }
else if (temp.
x >
x) {
273 }
else if (temp.
x <
x) {
283 std::pair<int, int> ret;
295 assert(temp == *
this);
313 if(
std::find(xloc.begin(),xloc.end(),
',') != xloc.end()
314 ||
std::find(yloc.begin(),yloc.end(),
',') != yloc.end()) {
319 for(size = xlocs.size(); size < ylocs.size(); ++
size) {
322 while(size > ylocs.size()) {
325 for(
size_t i = 0;
i !=
size; ++
i) {
332 const std::string::const_iterator dash =
334 if(dash != xloc.begin() && dash != xloc.end()) {
338 const int bot = std::stoi(beg) - 1;
339 const int top = std::stoi(
end) - 1;
344 const int xval = std::stoi(xloc) - 1;
350 const std::string::const_iterator dash =
353 if(dash != yloc.begin() && dash != yloc.end()) {
357 const int bot = std::stoi(beg) - 1;
358 const int top = std::stoi(
end) - 1;
363 const int yval = std::stoi(yloc) - 1;
382 std::stringstream
x,
y;
383 std::set<map_location>::const_iterator
390 for(++i; i != locs.end(); ++
i) {
391 if(i->x !=
first->x || i->y != last->y+1){
392 if(last->y !=
first->y)
393 y <<
"-" << (last->y + 1);
394 x <<
"," << (i->x + 1);
395 y <<
"," << (i->y + 1);
401 if(last->y !=
first->y)
402 y <<
"-" << (last->y + 1);
410 return map_location(lexical_cast<int>(xi)-1, lexical_cast<int>(yi)-1);
415 const std::vector<std::string> xvals =
utils::split(cfg[
"x"]);
416 const std::vector<std::string> yvals =
utils::split(cfg[
"y"]);
418 if (xvals.size() != yvals.size()) {
427 std::stringstream
x,
y;
429 std::vector<map_location>::const_iterator
i = locs.begin(),
432 for(; i !=
end; ++
i) {
void read_locations(const config &cfg, std::vector< map_location > &locs)
Parse x,y keys of a config into a vector of locations.
static DIRECTION parse_direction(const std::string &str)
static std::string write_translated_direction(DIRECTION dir)
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
bool matches_range(const std::string &xloc, const std::string &yloc) const
static bool is_vertically_higher_than(const map_location &m1, const map_location &m2)
map_location rotate_right_around_center(const map_location ¢er, int k) const
std::ostream & operator<<(std::ostream &s, map_location const &l)
Dumps a position on a stream, for debug purposes.
map_location & vector_difference_assign(const map_location &a)
DIRECTION get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
GLint GLint GLint GLint GLint GLint y
static std::vector< DIRECTION > parse_directions(const std::string &str)
Parse_directions takes a comma-separated list, and filters out any invalid directions.
Definitions for the interface to Wesnoth Markup Language (WML).
GLuint GLenum GLenum transform
std::size_t hash_value(map_location const &a)
Moved out of inline because of the boost dependency.
static UNUSEDNOWARN std::string _(const char *str)
static std::string sub(const std::string &s)
Private function to surround an argument with brackets.
GLboolean GLboolean GLboolean GLboolean a
static DIRECTION get_opposite_dir(DIRECTION d)
static const std::vector< DIRECTION > & default_dirs()
Default list of directions.
Templates and utility-routines for strings and numbers.
void write(config &cfg) const
Encapsulates the map of the game.
void write_location_range(const std::set< map_location > &locs, config &cfg)
Write a set of locations into a config using ranges, adding keys x=x1,..,xn and y=y1a-y1b,..,yna-ynb.
static DIRECTION rotate_right(DIRECTION d, unsigned int k=1u)
Inlined bodies.
GLint GLint GLint GLint GLint x
DIRECTION
Valid directions which can be moved in our hexagonal world.
bool find(E event, F functor)
Tests whether an event handler is available.
std::pair< int, int > get_in_basis_N_NE() const
map_location get_direction(DIRECTION d, unsigned int n=1u) const
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
A config object defines a single node in a WML file, with access to child nodes.
Thrown when a lexical_cast fails.
static std::string write_direction(DIRECTION dir)
GLsizei const GLcharARB ** string
static map_location read_locations_helper(const std::string &xi, const std::string &yi)
void write_locations(const std::vector< map_location > &locs, config &cfg)
Write a vector of locations into a config adding keys x=x1,x2,..,xn and y=y1,y2,..,yn.