Regroup similar utility fonctions in pathutils.?pp where they clearly belong.
Remove or simplify some include of pathfind.hpp
This commit is contained in:
parent
90fe25a13b
commit
1f32116d33
8 changed files with 81 additions and 81 deletions
|
@ -29,7 +29,6 @@ class gamemap;
|
|||
#include "../game_display.hpp"
|
||||
#include "../gamestatus.hpp"
|
||||
#include "../generic_event.hpp"
|
||||
#include "../pathfind.hpp"
|
||||
#include "../playturn.hpp"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "../../log.hpp"
|
||||
#include "../../map_label.hpp"
|
||||
#include "../../menu_events.hpp"
|
||||
#include "../../pathfind.hpp"
|
||||
#include "../../replay.hpp"
|
||||
#include "../../terrain_filter.hpp"
|
||||
#include "../../unit.hpp"
|
||||
|
|
|
@ -222,63 +222,3 @@ plain_route a_star_search(const map_location& src, const map_location& dst,
|
|||
return route;
|
||||
}
|
||||
|
||||
static void get_tiles_radius_internal(const map_location& a, size_t radius,
|
||||
std::set<map_location>& res, std::map<map_location,int>& visited)
|
||||
{
|
||||
visited[a] = radius;
|
||||
res.insert(a);
|
||||
|
||||
if(radius == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(a,adj);
|
||||
for(size_t i = 0; i != 6; ++i) {
|
||||
if(visited.count(adj[i]) == 0 || visited[adj[i]] < int(radius)-1) {
|
||||
get_tiles_radius_internal(adj[i],radius-1,res,visited);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_tiles_radius(const map_location& a, size_t radius,
|
||||
std::set<map_location>& res)
|
||||
{
|
||||
std::map<map_location,int> visited;
|
||||
get_tiles_radius_internal(a,radius,res,visited);
|
||||
}
|
||||
|
||||
void get_tiles_radius(gamemap const &map, std::vector<map_location> const &locs,
|
||||
size_t radius, std::set<map_location> &res, xy_pred *pred)
|
||||
{
|
||||
typedef std::set<map_location> location_set;
|
||||
location_set not_visited(locs.begin(), locs.end()), must_visit, filtered_out;
|
||||
++radius;
|
||||
|
||||
for(;;) {
|
||||
location_set::const_iterator it = not_visited.begin(), it_end = not_visited.end();
|
||||
std::copy(it,it_end,std::inserter(res,res.end()));
|
||||
for(; it != it_end; ++it) {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(*it, adj);
|
||||
for(size_t i = 0; i != 6; ++i) {
|
||||
map_location const &loc = adj[i];
|
||||
if(map.on_board(loc) && !res.count(loc) && !filtered_out.count(loc)) {
|
||||
if(!pred || (*pred)(loc)) {
|
||||
must_visit.insert(loc);
|
||||
} else {
|
||||
filtered_out.insert(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(--radius == 0 || must_visit.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
not_visited.swap(must_visit);
|
||||
must_visit.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "map.hpp"
|
||||
#include "map_label.hpp"
|
||||
#include "minimap.hpp"
|
||||
#include "pathfind.hpp"
|
||||
#include "pathutils.hpp"
|
||||
#include "preferences.hpp"
|
||||
#include "sdl_utils.hpp"
|
||||
#include "tooltips.hpp"
|
||||
|
|
|
@ -33,23 +33,6 @@ class unit_map;
|
|||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
|
||||
class xy_pred : public std::unary_function<map_location const&, bool>
|
||||
{
|
||||
public:
|
||||
virtual bool operator()(map_location const&) = 0;
|
||||
protected:
|
||||
virtual ~xy_pred() {}
|
||||
};
|
||||
|
||||
/** Function which, given a location, will find all tiles within 'radius' of that tile */
|
||||
void get_tiles_radius(const map_location& a, size_t radius,
|
||||
std::set<map_location>& res);
|
||||
|
||||
/** Function which, given a set of locations, will find all tiles within 'radius' of those tiles */
|
||||
void get_tiles_radius(const gamemap& map, const std::vector<map_location>& locs, size_t radius,
|
||||
std::set<map_location>& res, xy_pred *pred=NULL);
|
||||
|
||||
enum VACANT_TILE_TYPE { VACANT_CASTLE, VACANT_ANY };
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,3 +96,64 @@ bool tiles_adjacent(const map_location& a, const map_location& b)
|
|||
(xdiff == 1 && ydiff == 1 && (a.y > b.y ? is_even(a.x) : is_even(b.x)));
|
||||
}
|
||||
|
||||
|
||||
static void get_tiles_radius_internal(const map_location& a, size_t radius,
|
||||
std::set<map_location>& res, std::map<map_location,int>& visited)
|
||||
{
|
||||
visited[a] = radius;
|
||||
res.insert(a);
|
||||
|
||||
if(radius == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(a,adj);
|
||||
for(size_t i = 0; i != 6; ++i) {
|
||||
if(visited.count(adj[i]) == 0 || visited[adj[i]] < int(radius)-1) {
|
||||
get_tiles_radius_internal(adj[i],radius-1,res,visited);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_tiles_radius(const map_location& a, size_t radius,
|
||||
std::set<map_location>& res)
|
||||
{
|
||||
std::map<map_location,int> visited;
|
||||
get_tiles_radius_internal(a,radius,res,visited);
|
||||
}
|
||||
|
||||
void get_tiles_radius(gamemap const &map, std::vector<map_location> const &locs,
|
||||
size_t radius, std::set<map_location> &res, xy_pred *pred)
|
||||
{
|
||||
typedef std::set<map_location> location_set;
|
||||
location_set not_visited(locs.begin(), locs.end()), must_visit, filtered_out;
|
||||
++radius;
|
||||
|
||||
for(;;) {
|
||||
location_set::const_iterator it = not_visited.begin(), it_end = not_visited.end();
|
||||
std::copy(it,it_end,std::inserter(res,res.end()));
|
||||
for(; it != it_end; ++it) {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(*it, adj);
|
||||
for(size_t i = 0; i != 6; ++i) {
|
||||
map_location const &loc = adj[i];
|
||||
if(map.on_board(loc) && !res.count(loc) && !filtered_out.count(loc)) {
|
||||
if(!pred || (*pred)(loc)) {
|
||||
must_visit.insert(loc);
|
||||
} else {
|
||||
filtered_out.insert(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(--radius == 0 || must_visit.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
not_visited.swap(must_visit);
|
||||
must_visit.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#define PATHUTILS_H_INCLUDED
|
||||
|
||||
#include "map_location.hpp"
|
||||
#include "map.hpp"
|
||||
#include <set>
|
||||
|
||||
/** Function which tells if two locations are adjacent. */
|
||||
bool tiles_adjacent(const map_location& a, const map_location& b);
|
||||
|
@ -34,6 +36,22 @@ void get_adjacent_tiles(const map_location& a, map_location* res);
|
|||
*/
|
||||
void get_tile_ring(const map_location& a, const int r, std::vector<map_location>& res);
|
||||
|
||||
class xy_pred : public std::unary_function<map_location const&, bool>
|
||||
{
|
||||
public:
|
||||
virtual bool operator()(map_location const&) = 0;
|
||||
protected:
|
||||
virtual ~xy_pred() {}
|
||||
};
|
||||
|
||||
/** Function which, given a location, will find all tiles within 'radius' of that tile */
|
||||
void get_tiles_radius(const map_location& a, size_t radius,
|
||||
std::set<map_location>& res);
|
||||
|
||||
/** Function which, given a set of locations, will find all tiles within 'radius' of those tiles */
|
||||
void get_tiles_radius(const gamemap& map, const std::vector<map_location>& locs, size_t radius,
|
||||
std::set<map_location>& res, xy_pred *pred=NULL);
|
||||
|
||||
/**
|
||||
* Function which, given a location, will place all locations in the radius of r in res
|
||||
* res must be a std::vector of location
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define TERRAIN_FILTER_H_INCLUDED
|
||||
|
||||
#include "map_location.hpp"
|
||||
#include "pathfind.hpp"
|
||||
#include "pathutils.hpp"
|
||||
#include "variable.hpp"
|
||||
|
||||
class config;
|
||||
|
|
Loading…
Add table
Reference in a new issue