diff --git a/src/actions/attack.cpp b/src/actions/attack.cpp index 9f49900ec35..81eb4c5f6c2 100644 --- a/src/actions/attack.cpp +++ b/src/actions/attack.cpp @@ -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") { diff --git a/src/actions/create.cpp b/src/actions/create.cpp index 0ebcc69807c..57fe6830ec5 100644 --- a/src/actions/create.cpp +++ b/src/actions/create.cpp @@ -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); diff --git a/src/game_display.cpp b/src/game_display.cpp index b121d4d8a3d..035b6ffc2bb 100644 --- a/src/game_display.cpp +++ b/src/game_display.cpp @@ -507,7 +507,7 @@ std::vector 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)"; } diff --git a/src/map/location.cpp b/src/map/location.cpp index 4b93313762e..52c0ece8766 100644 --- a/src/map/location.cpp +++ b/src/map/location.cpp @@ -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::default_dirs() { - static const std::vector 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 +{ + 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) { diff --git a/src/map/location.hpp b/src/map/location.hpp index f863e279a71..23f67407dec 100644 --- a/src/map/location.hpp +++ b/src/map/location.hpp @@ -54,7 +54,7 @@ struct map_location { indeterminate }; - static const std::vector & default_dirs(); + static std::vector 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 (k)) : rotate_right(d, (static_cast(-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 (n)) : get_direction(get_opposite_dir(dir), static_cast (-n)); + return (n >= 0) ? get_direction(dir, static_cast (n)) : get_direction(get_opposite_direction(dir), static_cast (-n)); } enum RELATIVE_DIR_MODE { DEFAULT , RADIAL_SYMMETRY }; diff --git a/src/terrain/filter.cpp b/src/terrain/filter.cpp index c6957ff7f52..2174e8f5095 100644 --- a/src/terrain/filter.cpp +++ b/src/terrain/filter.cpp @@ -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 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::const_iterator j, j_end = dirs.end(); for (j = dirs.begin(); j != j_end; ++j) { const map_location &adj = adjacent[static_cast(*j)]; diff --git a/src/tests/test_map_location.cpp b/src/tests/test_map_location.cpp index d91ae6270d3..5f4ca3034c5 100644 --- a/src/tests/test_map_location.cpp +++ b/src/tests/test_map_location.cpp @@ -98,7 +98,7 @@ static void characterization_distance_direction (const std::vector 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 mirror_walk( std::pair 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 (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 (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) ); } } diff --git a/src/units/filter.cpp b/src/units/filter.cpp index efff09350c7..c2dfb3439ad 100644 --- a/src/units/filter.cpp +++ b/src/units/filter.cpp @@ -133,7 +133,7 @@ struct unit_filter_adjacent : public unit_filter_base config::attribute_value i_adjacent = cfg_["adjacent"]; std::vector dirs; if (i_adjacent.empty()) { - dirs = map_location::default_dirs(); + dirs = map_location::all_directions(); } else { dirs = map_location::parse_directions(i_adjacent); }