Merge remote-tracking branch 'gus/AI'

This commit is contained in:
Marc Zinnschlag 2013-04-18 22:17:49 +02:00
commit 1b764e5d3c

View file

@ -1,5 +1,5 @@
#include "pathfinding.hpp" #include "pathfinding.hpp"
#include <boost/graph/astar_search.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/adjacency_list.hpp> #include <boost/graph/adjacency_list.hpp>
#include "boost/tuple/tuple.hpp" #include "boost/tuple/tuple.hpp"
#include "OgreMath.h" #include "OgreMath.h"
@ -55,7 +55,7 @@ namespace
struct found_path {}; struct found_path {};
class goalVisited : public boost::default_astar_visitor /*class goalVisited : public boost::default_astar_visitor
{ {
public: public:
goalVisited(PointID goal) : mGoal(goal) {} goalVisited(PointID goal) : mGoal(goal) {}
@ -69,7 +69,7 @@ namespace
PointID mGoal; PointID mGoal;
}; };
class DistanceHeuristic : public boost::astar_heuristic <PathGridGraph, float> class DistanceHeuristic : public boost::atasr_heuristic <PathGridGraph, float>
{ {
public: public:
DistanceHeuristic(const PathGridGraph & l, PointID goal) DistanceHeuristic(const PathGridGraph & l, PointID goal)
@ -87,11 +87,23 @@ namespace
private: private:
const PathGridGraph & mGraph; const PathGridGraph & mGraph;
PointID mGoal; PointID mGoal;
}; };*/
}
class goalVisited : public boost::default_dijkstra_visitor
{
public:
goalVisited(PointID goal) : mGoal(goal) {}
void examine_vertex(PointID u, const PathGridGraph g)
{
if(u == mGoal)
throw found_path();
}
private:
PointID mGoal;
};
namespace MWMechanics
{
PathGridGraph buildGraph(const ESM::Pathgrid* pathgrid,float xCell = 0,float yCell = 0) PathGridGraph buildGraph(const ESM::Pathgrid* pathgrid,float xCell = 0,float yCell = 0)
{ {
PathGridGraph graph; PathGridGraph graph;
@ -126,13 +138,12 @@ namespace MWMechanics
std::list<ESM::Pathgrid::Point> shortest_path; std::list<ESM::Pathgrid::Point> shortest_path;
try { try {
boost::astar_search boost::dijkstra_shortest_paths
( (
graph, graph,
start, start,
DistanceHeuristic(graph,end),
boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(goalVisited(end))//.weight_map(boost::get(&Edge::distance, graph)) boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(goalVisited(end))//.weight_map(boost::get(&Edge::distance, graph))
); );
} catch(found_path fg) { } catch(found_path fg) {
for(PointID v = end;; v = p[v]) { for(PointID v = end;; v = p[v]) {
@ -146,6 +157,10 @@ namespace MWMechanics
//end of helpers functions //end of helpers functions
}
namespace MWMechanics
{
PathFinder::PathFinder() PathFinder::PathFinder()
{ {
mIsPathConstructed = false; mIsPathConstructed = false;