Merge remote-tracking branch 'gus/AI'

actorid
Marc Zinnschlag 12 years ago
commit 1b764e5d3c

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

Loading…
Cancel
Save