Map Location: rename default_dirs and get_opposite_dir
all_directions better reflects the purpose of the former. Also made it return a value, since the only places that used it immediately assigned it to a local variable.
This commit is contained in:
parent
f4fda31707
commit
f04e19934f
8 changed files with 23 additions and 22 deletions
|
@ -1307,7 +1307,7 @@ void attack::unit_killed(unit_info& attacker,
|
|||
unit_ptr newunit = unit::create(*reanimator, attacker.get_unit().side(), true, unit_race::MALE);
|
||||
newunit->set_attacks(0);
|
||||
newunit->set_movement(0, true);
|
||||
newunit->set_facing(map_location::get_opposite_dir(attacker.get_unit().facing()));
|
||||
newunit->set_facing(map_location::get_opposite_direction(attacker.get_unit().facing()));
|
||||
|
||||
// Apply variation
|
||||
if(undead_variation != "null") {
|
||||
|
|
|
@ -608,7 +608,7 @@ namespace { // Helpers for place_recruit()
|
|||
new_unit_itor->set_facing(recruit_loc.get_relative_dir(min_loc));
|
||||
} else if (leader_loc != map_location::null_location()) {
|
||||
// Face away from leader
|
||||
new_unit_itor->set_facing(map_location::get_opposite_dir(recruit_loc.get_relative_dir(leader_loc)));
|
||||
new_unit_itor->set_facing(map_location::get_opposite_direction(recruit_loc.get_relative_dir(leader_loc)));
|
||||
} else {
|
||||
// Face towards center of map
|
||||
const map_location center(map->w()/2, map->h()/2);
|
||||
|
|
|
@ -507,7 +507,7 @@ std::vector<texture> footsteps_images(const map_location& loc, const pathfind::m
|
|||
std::string rotate;
|
||||
if (dir > map_location::direction::south_east) {
|
||||
// No image, take the opposite direction and do a 180 rotation
|
||||
dir = i->get_opposite_dir(dir);
|
||||
dir = i->get_opposite_direction(dir);
|
||||
rotate = "~FL(horiz)~FL(vert)";
|
||||
}
|
||||
|
||||
|
|
|
@ -50,15 +50,16 @@ map_location::map_location(const config_attribute_value& x, const config_attribu
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Default list of directions
|
||||
*
|
||||
**/
|
||||
const std::vector<map_location::direction> & map_location::default_dirs() {
|
||||
static const std::vector<map_location::direction> dirs {map_location::direction::north,
|
||||
map_location::direction::north_east, map_location::direction::south_east, map_location::direction::south,
|
||||
map_location::direction::south_west, map_location::direction::north_west};
|
||||
return dirs;
|
||||
auto map_location::all_directions() -> std::vector<direction>
|
||||
{
|
||||
return {
|
||||
map_location::direction::north,
|
||||
map_location::direction::north_east,
|
||||
map_location::direction::south_east,
|
||||
map_location::direction::south,
|
||||
map_location::direction::south_west,
|
||||
map_location::direction::north_west
|
||||
};
|
||||
}
|
||||
|
||||
std::size_t hash_value(const map_location& a){
|
||||
|
@ -109,7 +110,7 @@ map_location::direction map_location::parse_direction(const std::string& str)
|
|||
}
|
||||
|
||||
if (start == 1) {
|
||||
dir = get_opposite_dir(dir);
|
||||
dir = get_opposite_direction(dir);
|
||||
}
|
||||
|
||||
if (end != std::string::npos) {
|
||||
|
|
|
@ -54,7 +54,7 @@ struct map_location {
|
|||
indeterminate
|
||||
};
|
||||
|
||||
static const std::vector<direction> & default_dirs();
|
||||
static std::vector<direction> all_directions();
|
||||
|
||||
static direction rotate_right(direction d, unsigned int k = 1u)
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ struct map_location {
|
|||
return (k>=0) ? rotate_right(d, static_cast<unsigned int> (k)) : rotate_right(d, (static_cast<unsigned int>(-k) % 6u) * 5u);
|
||||
}
|
||||
|
||||
static direction get_opposite_dir(direction d)
|
||||
static direction get_opposite_direction(direction d)
|
||||
{
|
||||
return rotate_right(d,3u);
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ struct map_location {
|
|||
map_location get_direction(direction dir, unsigned int n = 1u) const;
|
||||
map_location get_direction(direction dir, signed int n) const
|
||||
{
|
||||
return (n >= 0) ? get_direction(dir, static_cast<unsigned int> (n)) : get_direction(get_opposite_dir(dir), static_cast<unsigned int> (-n));
|
||||
return (n >= 0) ? get_direction(dir, static_cast<unsigned int> (n)) : get_direction(get_opposite_direction(dir), static_cast<unsigned int> (-n));
|
||||
}
|
||||
|
||||
enum RELATIVE_DIR_MODE { DEFAULT , RADIAL_SYMMETRY };
|
||||
|
|
|
@ -213,7 +213,7 @@ bool terrain_filter::match_internal(const map_location& loc, const unit* ref_uni
|
|||
int match_count = 0;
|
||||
vconfig::child_list::difference_type index = i - i_begin;
|
||||
std::vector<map_location::direction> dirs = (*i).has_attribute("adjacent")
|
||||
? map_location::parse_directions((*i)["adjacent"]) : map_location::default_dirs();
|
||||
? map_location::parse_directions((*i)["adjacent"]) : map_location::all_directions();
|
||||
std::vector<map_location::direction>::const_iterator j, j_end = dirs.end();
|
||||
for (j = dirs.begin(); j != j_end; ++j) {
|
||||
const map_location &adj = adjacent[static_cast<int>(*j)];
|
||||
|
|
|
@ -98,7 +98,7 @@ static void characterization_distance_direction (const std::vector<map_location>
|
|||
BOOST_CHECK_EQUAL( expected_dir, a.get_relative_dir(b, mode) );
|
||||
//Note: This is not a valid assertion. get_relative_dir has much symmetry but not radial.
|
||||
if (mode == map_location::RADIAL_SYMMETRY) {
|
||||
BOOST_CHECK_EQUAL( map_location::get_opposite_dir(expected_dir), b.get_relative_dir(a,mode) );
|
||||
BOOST_CHECK_EQUAL( map_location::get_opposite_direction(expected_dir), b.get_relative_dir(a,mode) );
|
||||
}
|
||||
BOOST_CHECK_EQUAL( a.vector_sum(b), b.vector_sum(a));
|
||||
map_location temp1 = a;
|
||||
|
@ -267,7 +267,7 @@ std::make_pair(1, "nw")};
|
|||
static std::pair<map_location , map_location> mirror_walk( std::pair<map_location,map_location> p, map_location::direction d)
|
||||
{
|
||||
p.first = p.first.get_direction(d);
|
||||
p.second = p.second.get_direction(map_location::get_opposite_dir(d));
|
||||
p.second = p.second.get_direction(map_location::get_opposite_direction(d));
|
||||
BOOST_CHECK_EQUAL(p.first, p.second.vector_negation());
|
||||
return p;
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ BOOST_AUTO_TEST_CASE ( check_get_opposite_dir_refactor )
|
|||
{
|
||||
for (unsigned int i = 0; i < 7; i++ ) {
|
||||
map_location::direction d = static_cast<map_location::direction> (i);
|
||||
BOOST_CHECK_EQUAL ( map_location::get_opposite_dir(d), legacy_get_opposite_dir(d) );
|
||||
BOOST_CHECK_EQUAL ( map_location::get_opposite_direction(d), legacy_get_opposite_dir(d) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,7 +374,7 @@ BOOST_AUTO_TEST_CASE ( check_rotate )
|
|||
|
||||
for (unsigned int i = 0; i < 7; i++ ) {
|
||||
map_location::direction d = static_cast<map_location::direction> (i);
|
||||
BOOST_CHECK_EQUAL ( map_location::get_opposite_dir(d), map_location::rotate_right(d,3) );
|
||||
BOOST_CHECK_EQUAL ( map_location::get_opposite_direction(d), map_location::rotate_right(d,3) );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(d,-2), map_location::rotate_right(d,4) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ struct unit_filter_adjacent : public unit_filter_base
|
|||
config::attribute_value i_adjacent = cfg_["adjacent"];
|
||||
std::vector<map_location::direction> dirs;
|
||||
if (i_adjacent.empty()) {
|
||||
dirs = map_location::default_dirs();
|
||||
dirs = map_location::all_directions();
|
||||
} else {
|
||||
dirs = map_location::parse_directions(i_adjacent);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue