AlpacaLibary  1.63
A closed source C++ bot for OSRS
Pathfinding.hpp
Go to the documentation of this file.
1 #ifndef PATHFINDING_HPP_INCLUDED
2 #define PATHFINDING_HPP_INCLUDED
3 
4 #include "../../Core/Types/Tile.hpp"
5 #include <vector>
6 #include <functional>
7 
11 namespace Pathfinding
12 {
14  {
15  OPEN = 0,
16  CLOSED = 0xFFFFFF,
17  UNINITIALIZED = 0x1000000,
18  OCCUPIED = 0x100,
19  SOLID = 0x20000,
20  BLOCKED = 0x200000,
21 
22  NORTH = 0x2,
23  EAST = 0x8,
24  SOUTH = 0x20,
25  WEST = 0x80,
26 
27  NORTHEAST = 0x4,
28  SOUTHEAST = 0x10,
29  SOUTHWEST = 0x40,
30  NORTHWEST = 0x1
31  };
32 
33  typedef enum PATHFINDER
34  {
38 
40  {
42  CHECK_COLLISION = (1 << 1),
44  CHECK_WHITELIST = (1 << 2),
46  CHECK_BLACKLIST = (1 << 3),
48  GOAL_IS_LOCAL = (1 << 4),
50  RETURN_LOCAL = (1 << 5)
51  };
52 
56  class TileNode
57  {
58  public:
60  std::int32_t X;
62  std::int32_t Y;
64  std::int32_t Flag;
66  bool Inspected = false;
68  bool MatchesWhitelist = false;
70  bool MatchesBlacklist = false;
72  std::int32_t Parent[2];
74  TileNode(std::int32_t X, std::int32_t Y, std::int32_t Flag);
76  bool IsBlocked() const;
78  Tile ToWorldTile() const;
80  Tile ToWorldTile(std::int32_t ClientX, std::int32_t ClientY, std::int32_t ClientPlane) const;
81  bool operator==(const TileNode& N) const;
82  operator bool() const;
83  };
84 
86  std::int32_t GetCurrentRegion();
87 
89  void GenerateNodes();
94  void SetWhitelist(const std::vector<Tile>& W);
99  void SetBlacklist(const std::vector<Tile>& B);
101  std::vector<std::vector<TileNode>> GetNodes();
103  std::vector<Tile> GetWhitelist();
105  std::vector<Tile> GetBlacklist();
106 
108  Tile FindWalkableTile(const Tile& T, const Tile& Min, const Tile& Max);
109  std::vector<Tile> FindWalkableTiles(const Tile& T);
110  std::vector<Tile> FindWalkableTiles(const Tile& T, const Tile& Min, const Tile& Max);
111 
112  std::vector<Tile> FindPathTo(const Tile& Goal,
115 
116  std::vector<Tile> FindPathTo(const std::vector<Tile>& Goals,
119 
120  std::vector<Pathfinding::TileNode> FindNodePathTo(const Tile& Goal,
123 
124  std::vector<Pathfinding::TileNode> FindNodePathTo(const std::vector<Tile>& Goals,
127  //std::vector<std::vector<TileNode>> Nodes;
128  //std::vector<Tile> Whitelist;
129  //std::vector<Tile> Blacklist;
130 
131  bool IsInside(std::int32_t X, std::int32_t Y);
132  std::vector<Pathfinding::TileNode*> GetNeighborsTo(std::int32_t X, std::int32_t Y, bool CheckCollision = true);
133  std::vector<Pathfinding::TileNode> Finder_BFS(std::uint32_t StartX, std::uint32_t StartY, std::uint32_t EndX, std::uint32_t EndY, std::int32_t Options );
134  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, std::int32_t Options );
135 }
136 
137 #endif // PATHFINDING_HPP_INCLUDED
A subclass used to store information about tile nodes generated by the Pathfinding class.
Definition: Pathfinding.hpp:57
std::int32_t Y
The local region Y coordinate.
Definition: Pathfinding.hpp:62
bool MatchesBlacklist
True if this node matches the blacklisted tiles set in Pathfinding
Definition: Pathfinding.hpp:70
bool operator==(const TileNode &N) const
Tile ToWorldTile() const
Adds ClientX/Y to the local X and Y coordinates of the node, returning a world tile
bool IsBlocked() const
True if the node is occupied or blocked according to its collision flag.
Tile ToWorldTile(std::int32_t ClientX, std::int32_t ClientY, std::int32_t ClientPlane) const
Adds ClientX/Y to the local X and Y coordinates of the node, returning a world tile
std::int32_t X
The local region X coordinate.
Definition: Pathfinding.hpp:60
std::int32_t Flag
The collision flag associated with the node.
Definition: Pathfinding.hpp:64
bool Inspected
For pathfinding use only
Definition: Pathfinding.hpp:66
TileNode(std::int32_t X, std::int32_t Y, std::int32_t Flag)
bool MatchesWhitelist
True if this node matches the whitelisted tiles set in Pathfinding
Definition: Pathfinding.hpp:68
std::int32_t Parent[2]
For pathfinding use only
Definition: Pathfinding.hpp:72
Definition: Tile.hpp:8
A class allowing easy pathfinding within the local region.
Definition: Pathfinding.hpp:12
void SetWhitelist(const std::vector< Tile > &W)
Sets the internal Whitelist tiles.
std::vector< Pathfinding::TileNode > FindNodePathTo(const Tile &Goal, std::int32_t Options=CHECK_COLLISION|CHECK_WHITELIST|CHECK_BLACKLIST, PATHFINDER Finder=BREADTH_FIRST_SEARCH)
void SetBlacklist(const std::vector< Tile > &B)
Sets the internal Blacklist tiles.
std::vector< Tile > FindPathTo(const Tile &Goal, std::int32_t Options=CHECK_COLLISION|CHECK_WHITELIST|CHECK_BLACKLIST, PATHFINDER Finder=BREADTH_FIRST_SEARCH)
std::int32_t GetCurrentRegion()
Returns the region ID the local player is in.
std::vector< Tile > GetBlacklist()
Returns the internal Blacklist cache.
Tile FindWalkableTile(const Tile &T)
@ BREADTH_FIRST_SEARCH
Definition: Pathfinding.hpp:36
std::vector< std::vector< TileNode > > GetNodes()
Returns the internal TileNode cache generated by GenerateNodes()
void GenerateNodes()
Clears the internal cached nodes, and generates new ones based on the local region
std::vector< Pathfinding::TileNode * > GetNeighborsTo(std::int32_t X, std::int32_t Y, bool CheckCollision=true)
std::vector< Tile > FindWalkableTiles(const Tile &T)
std::vector< Pathfinding::TileNode > Finder_BFS(std::uint32_t StartX, std::uint32_t StartY, std::uint32_t EndX, std::uint32_t EndY, std::int32_t Options)
bool IsInside(std::int32_t X, std::int32_t Y)
std::vector< Tile > GetWhitelist()
Returns the internal Whitelist cache.