mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
* a bit of pathfinding (still needs testing and implementation of something like BFS (I consider Dijkstra usless in this case))
* some minor changes
This commit is contained in:
36
CPathfinder.h
Normal file
36
CPathfinder.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef CPATHFINDER_H
|
||||
#define CPATHFINDER_H
|
||||
#include "CGameInfo.h"
|
||||
#include "int3.h"
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
struct CPathNode
|
||||
{
|
||||
bool v1, v2, v3,
|
||||
v4, v5,
|
||||
v6, v7, v8; //true if we can pass, false if not
|
||||
bool accesible; //true if a hero can be on this node
|
||||
int dist; //distance from the first node of searching; -1 is infinity
|
||||
CPathNode * theNodeBefore;
|
||||
int x, y; //coordiantes
|
||||
};
|
||||
|
||||
struct CPath
|
||||
{
|
||||
std::queue<CPathNode> nodes; //just get node by node
|
||||
};
|
||||
|
||||
/**
|
||||
* main pathfinder class
|
||||
*/
|
||||
class CPathfinder
|
||||
{
|
||||
private:
|
||||
std::vector< std::vector<CPathNode> > graph;
|
||||
public:
|
||||
CPath * getPath(int3 & src, int3 & dest); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists
|
||||
CPath * getPath(int3 & src, int3 & dest, int (*getDist)(int3 & a, int3 b)); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance
|
||||
};
|
||||
|
||||
#endif //CPATHFINDER_H
|
||||
Reference in New Issue
Block a user