17 #ifndef MAP_LOCATION_H_INCLUDED
18 #define MAP_LOCATION_H_INCLUDED
69 inline bool valid()
const {
return x >= 0 &&
y >= 0; }
71 inline bool valid(
const int parWidth,
const int parHeight)
const
72 {
return ((
x >= 0) && (
y >= 0) && (
x < parWidth) && (
y < parHeight)); }
74 inline bool valid(
const int parWidth,
const int parHeight,
const int border)
const
75 {
return ((
x + border >= 0) && (
y + border >= 0) && (
x < parWidth + border) && (
y < parHeight + border)); }
150 std::ostream &operator<<(std::ostream &s, std::vector<map_location>
const &
v);
160 return (k>=0) ?
rotate_right(d, static_cast<unsigned int> (k)) :
rotate_right(d, (static_cast<unsigned int>(-k) % 6u) * 5u);
213 y += ((
x & 1) && (a.
x & 1));
247 int x_factor = (
static_cast<unsigned int> (dir) <= 2u) ? 1 : -1;
249 unsigned int tmp_y = dir - 2;
250 int y_factor = (tmp_y <= 2u) ? 1 : -1;
253 return map_location(
x + x_factor * n,
y + y_factor * ((n + ((
x & 1) == 1)) / 2));
255 return map_location(
x + x_factor * n,
y + y_factor * ((n + ((
x & 1) == 0)) / 2));
280 res->
y = a.
y - (((a.
x & 1)==0) ? 1:0);
283 res->
y = a.
y + (((a.
x & 1)==1) ? 1:0);
289 res->
y = a.
y + (((a.
x & 1)==1) ? 1:0);
292 res->
y = a.
y - (((a.
x & 1)==0) ? 1:0);
327 return (a.
x & 1) == 0;
337 return (b.
x & 1) == 0;
344 return ((a.
x - b.
x) == 1) || ((a.
x - b.
x) == - 1);
359 const size_t hdistance = std::abs(a.
x - b.
x);
361 const size_t vpenalty = ( (((a.
x & 1)==0) && ((b.
x & 1)==1) && (a.
y < b.
y))
362 || (((b.
x & 1)==0) && ((a.
x & 1)==1) && (b.
y < a.
y)) ) ? 1 : 0;
374 return std::max<int>(hdistance, std::abs(a.
y - b.
y) + vpenalty + hdistance/2);
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.
map_location(int x, int y)
std::ostream & operator<<(std::ostream &s, map_location const &l)
Dumps a position on a stream, for debug purposes.
static DIRECTION parse_direction(const std::string &str)
friend std::size_t hash_value(map_location const &a)
Moved out of inline because of the boost dependency.
static std::string write_translated_direction(DIRECTION dir)
bool matches_range(const std::string &xloc, const std::string &yloc) const
map_location rotate_right_around_center(const map_location ¢er, int k) const
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
bool operator!=(const map_location &a) const
static const map_location & ZERO()
Old implementation:
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.
bool valid(const int parWidth, const int parHeight) const
bool valid(const int parWidth, const int parHeight, const int border) const
GLdouble GLdouble GLdouble b
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
map_location vector_sum(const map_location &a) const
GLboolean GLboolean GLboolean GLboolean a
static DIRECTION get_opposite_dir(DIRECTION d)
static const std::vector< DIRECTION > & default_dirs()
Default list of directions.
static const map_location & null_location()
void write(config &cfg) const
Encapsulates the map of the game.
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.
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 operator<(const map_location &a) const
map_location & vector_sum_assign(const map_location &a)
GLint GLint GLsizei GLsizei GLsizei GLint border
std::pair< int, int > get_in_basis_N_NE() const
int do_compare(const map_location &a) const
three-way comparator
map_location get_direction(DIRECTION d, unsigned int n=1u) const
map_location vector_negation() const
Inline vector ops.
A config object defines a single node in a WML file, with access to child nodes.
static std::string write_direction(DIRECTION dir)
GLsizei const GLcharARB ** string
void read_locations(const config &cfg, std::vector< map_location > &locs)
Parse x,y keys of a config into a vector of locations.
bool operator==(const map_location &a) const