93 lines
3.6 KiB
C++
93 lines
3.6 KiB
C++
|
#ifndef PATHFINDING_HPP_INCLUDED
|
||
|
#define PATHFINDING_HPP_INCLUDED
|
||
|
|
||
|
#include "../../Core/Types/Tile.hpp"
|
||
|
#include <vector>
|
||
|
#include <functional>
|
||
|
|
||
|
class Pathfinding
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
enum COLLISION_FLAG
|
||
|
{
|
||
|
OPEN = 0,
|
||
|
CLOSED = 0xFFFFFF,
|
||
|
UNINITIALIZED = 0x1000000,
|
||
|
OCCUPIED = 0x100,
|
||
|
SOLID = 0x20000,
|
||
|
BLOCKED = 0x200000,
|
||
|
|
||
|
NORTH = 0x2,
|
||
|
EAST = 0x8,
|
||
|
SOUTH = 0x20,
|
||
|
WEST = 0x80,
|
||
|
|
||
|
NORTHEAST = 0x4,
|
||
|
SOUTHEAST = 0x10,
|
||
|
SOUTHWEST = 0x40,
|
||
|
NORTHWEST = 0x1,
|
||
|
|
||
|
BLOCKED_NORTH = 0x400,
|
||
|
BLOCKED_EAST = 0x1000,
|
||
|
BLOCKED_SOUTH = 0x4000,
|
||
|
BLOCKED_WEST = 0x10000,
|
||
|
|
||
|
BLOCKED_NORTHEAST = 0x800,
|
||
|
BLOCKED_SOUTHEAST = 0x2000,
|
||
|
BLOCKED_NORTHWEST = 0x200,
|
||
|
BLOCKED_SOUTHWEST = 0x8000,
|
||
|
};
|
||
|
|
||
|
typedef enum PATHFINDER
|
||
|
{
|
||
|
BREADTH_FIRST_SEARCH
|
||
|
} PATHFINDER;
|
||
|
|
||
|
class TileNode
|
||
|
{
|
||
|
public:
|
||
|
std::int32_t X;
|
||
|
std::int32_t Y;
|
||
|
std::int32_t Flag;
|
||
|
bool Inspected;
|
||
|
std::int32_t Parent[2];
|
||
|
TileNode();
|
||
|
TileNode(std::int32_t X, std::int32_t Y, std::int32_t Flag);
|
||
|
bool IsBlocked(bool AllowOccupied = true) const;
|
||
|
Tile ToWorldTile() const;
|
||
|
bool operator==(const TileNode& N) const;
|
||
|
operator bool() const;
|
||
|
};
|
||
|
|
||
|
static void RegenerateNodes();
|
||
|
static std::vector<std::vector<TileNode>> GetNodes();
|
||
|
|
||
|
static Tile FindWalkableTile(const Tile& T);
|
||
|
static Tile FindWalkableTile(const Tile& T, const Tile& Min, const Tile& Max);
|
||
|
static std::vector<Tile> FindWalkableTiles(const Tile& T);
|
||
|
static std::vector<Tile> FindWalkableTiles(const Tile& T, const Tile& Min, const Tile& Max);
|
||
|
|
||
|
static std::vector<Tile> FindPathTo(const Tile& Goal, bool AllowOccupied = false, PATHFINDER Finder = BREADTH_FIRST_SEARCH);
|
||
|
static std::vector<Tile> FindPathTo(const std::vector<Tile>& Goals, bool AllowOccupied = false, PATHFINDER Finder = BREADTH_FIRST_SEARCH);
|
||
|
// Ignores collision
|
||
|
static std::vector<Tile> FindDirectPathTo(const Tile& Goal, PATHFINDER Finder = BREADTH_FIRST_SEARCH);
|
||
|
static std::vector<Tile> FindDirectPathTo(const std::vector<Tile>& Goals, PATHFINDER Finder = BREADTH_FIRST_SEARCH);
|
||
|
|
||
|
|
||
|
|
||
|
static bool IsInside(std::uint32_t X, std::uint32_t Y);
|
||
|
static std::vector<Pathfinding::TileNode*> GetNeighborsTo(std::uint32_t X, std::uint32_t Y, bool AllowOccupied = false, bool CheckCollision = true);
|
||
|
static std::vector<Pathfinding::TileNode> Finder_BFS( std::uint32_t StartX, std::uint32_t StartY,
|
||
|
std::uint32_t EndX, std::uint32_t EndY,
|
||
|
bool AllowOccupied = false, bool CheckCollision = true );
|
||
|
|
||
|
static std::vector<Pathfinding::TileNode> Finder_BFS( std::uint32_t StartX, std::uint32_t StartY,
|
||
|
const std::vector<std::pair<std::uint32_t, std::uint32_t>>& Ends,
|
||
|
bool AllowOccupied = false, bool CheckCollision = true );
|
||
|
private:
|
||
|
static std::vector<std::vector<TileNode>> Nodes;
|
||
|
};
|
||
|
|
||
|
#endif // PATHFINDING_HPP_INCLUDED
|