40 enum DIRECTION { NORTH=0, NORTH_EAST=1, SOUTH_EAST=2, SOUTH=3,
41 SOUTH_WEST=4, NORTH_WEST=5, NDIRECTIONS=6 };
43 static const std::vector<DIRECTION> & default_dirs();
52 return (k>=0) ? rotate_right(d, static_cast<unsigned int> (k)) : rotate_right(d, (static_cast<unsigned int>(-k) % 6u) * 5u);
57 return rotate_right(d,3u);
60 static DIRECTION parse_direction(
const std::string& str);
66 static std::vector<DIRECTION> parse_directions(
const std::string& str);
67 static std::string write_direction(
DIRECTION dir);
68 static std::string write_translated_direction(
DIRECTION dir);
89 bool valid()
const {
return x >= 0 && y >= 0; }
91 bool valid(
const int parWidth,
const int parHeight)
const 92 {
return ((x >= 0) && (y >= 0) && (x < parWidth) && (y < parHeight)); }
94 bool valid(
const int parWidth,
const int parHeight,
const int border)
const 95 {
return ((x + border >= 0) && (y + border >= 0) && (x < parWidth + border) && (y < parHeight + border)); }
97 bool matches_range(
const std::string& xloc,
const std::string& yloc)
const;
123 y += ((x & 1) && (a.
x & 1));
138 return (n >= 0) ? get_direction(dir, static_cast<unsigned int> (n)) : get_direction(get_opposite_dir(dir), static_cast<unsigned int> (-n));
146 std::pair<int,int> get_in_basis_N_NE()
const;
159 void add(
int x_diff,
int y_diff) { x += x_diff; y += y_diff; }
205 std::ostream &operator<<(std::ostream &s, const std::vector<map_location>& v);
213 return (l.wml_x()) * 16384 + (l.wml_y()) + 2000;
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)
map_location & vector_sum_assign(const map_location &a)
std::ostream & operator<<(std::ostream &s, const map_location &l)
Dumps a position on a stream, for debug purposes.
map_location & vector_difference_assign(const map_location &a)
map_location(int x, int y, wml_loc)
static const map_location & ZERO()
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
int do_compare(const map_location &a) const
three-way comparator
bool valid(const int parWidth, const int parHeight, const int border) const
map_location vector_negation() const
static DIRECTION rotate_right(DIRECTION d, unsigned int k=1u)
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
std::size_t operator()(const map_location &l) const noexcept
map_location plus(int x_diff, int y_diff) const
void add(int x_diff, int y_diff)
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
bool operator!=(const map_location &a) const
bool operator==(const map_location &a) const
static DIRECTION rotate_right(DIRECTION d, signed int k)
Encapsulates the map of the game.
std::size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
bool operator<(const map_location &a) const
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.
map_location vector_sum(const map_location &a) const
std::size_t hash_value(const map_location &a)
bool operator==(const config &a, const config &b)
static map_location::DIRECTION s
DIRECTION
Valid directions which can be moved in our hexagonal world.
static DIRECTION get_opposite_dir(DIRECTION d)
static const map_location & null_location()
bool valid(const int parWidth, const int parHeight) const
A config object defines a single node in a WML file, with access to child nodes.
map_location get_direction(DIRECTION dir, signed int n) const
static map_location::DIRECTION n
void read_locations(const config &cfg, std::vector< map_location > &locs)
Parse x,y keys of a config into a vector of locations.