71 int adjusted_steps = steps >= 0 ? steps : steps * -5;
72 return direction{(
static_cast<int>(
d) + (adjusted_steps % 6)) % 6};
110 bool valid()
const {
return x >= 0 &&
y >= 0; }
112 bool valid(
const int parWidth,
const int parHeight)
const
113 {
return ((
x >= 0) && (
y >= 0) && (
x < parWidth) && (
y < parHeight)); }
115 bool valid(
const int parWidth,
const int parHeight,
const int border)
const
118 bool matches_range(
const std::string& xloc,
const std::string& yloc)
const;
144 y += ((
x & 1) && (a.
x & 1));
168 int r =
y - int((
x - abs(
x) % 2) / 2);
174 int y =
h.r + int((
h.q - abs(
h.q) % 2) / 2);
189 void add(
int x_diff,
int y_diff) {
x += x_diff;
y += y_diff; }
235 std::ostream &
operator<<(std::ostream &
s,
const std::vector<map_location>& v);
246 return (l.wml_x()) * 16384 + (l.wml_y()) + 2000;
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
@ border
The border of the map.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
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.
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,.....
std::ostream & operator<<(std::ostream &s, const map_location &l)
Dumps a position on a stream, for debug purposes.
void read_locations(const config &cfg, std::vector< map_location > &locs)
Parse x,y keys of a config into a vector of locations.
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
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,...
Represents a map location in cubic hexagonal coordinates.
Encapsulates the map of the game.
map_location & vector_sum_assign(const map_location &a)
map_location & vector_difference_assign(const map_location &a)
static map_location from_cubic(cubic_location h)
bool valid(const int parWidth, const int parHeight) const
static std::string write_direction(direction dir)
map_location vector_negation() const
map_location(int x, int y)
static std::vector< direction > parse_directions(const std::string &str)
Parse_directions takes a comma-separated list, and filters out any invalid directions.
void add(int x_diff, int y_diff)
friend std::size_t hash_value(const map_location &a)
static std::vector< direction > all_directions()
bool operator==(const map_location &a) const
map_location vector_sum(const map_location &a) const
map_location get_direction(direction dir, unsigned int n=1u) const
map_location rotate_right_around_center(const map_location ¢er, int k) const
bool operator!=(const map_location &a) const
static constexpr direction get_opposite_direction(direction d)
bool operator<(const map_location &a) const
cubic_location to_cubic() const
direction
Valid directions which can be moved in our hexagonal world.
bool valid(const int parWidth, const int parHeight, const int border) const
direction get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
static const map_location & null_location()
map_location(int x, int y, wml_loc)
static direction parse_direction(const std::string &str)
map_location get_direction(direction dir, signed int n) const
static std::string write_translated_direction(direction dir)
void write(config &cfg) const
bool matches_range(const std::string &xloc, const std::string &yloc) const
map_location plus(int x_diff, int y_diff) const
int do_compare(const map_location &a) const
three-way comparator
static constexpr direction rotate_direction(direction d, int steps=1)
Returns the direction one would face having taken steps clockwise around an undefined center.
static const map_location & ZERO()
std::size_t operator()(const map_location &l) const noexcept
static map_location::direction n
static map_location::direction s