Dragonfly 4.19
A text-based game engine
PathFind.h
1///
2/// PathFind
3///
4/// An A* pathfinding class.
5///
6
7#ifndef __PATHFIND_H__
8#define __PATHFIND_H__
9
10// Engine includes.
11#include "EventPath.h"
12#include "Object.h"
13#include "Vector.h"
14
15namespace df {
16
17class Object; // Forward reference.
18
19// Coordinates for pathfinding.
21 int x, y;
22};
23
24// Nodes for pathfinding.
26 float from_start; // Cost from start.
27 float to_end; // Estimate to end + cost from start.
28 struct coord_struct came_from; // Most efficient path back.
29};
30
31class PathFind {
32
33 private:
34 Object *m_p_o; ///< Object finding path.
35 Object *m_p_target_o; ///< Object target (optional).
36 coord_struct m_start; ///< Start position.
37 coord_struct m_end; ///< End target position.
38 struct node_struct **m_node; ///< All nodes in 2d graph/grid.
39 std::vector<coord_struct> m_open_set; ///< Set of nodes not yet visited.
40 std::vector<coord_struct> m_closed_set;///< Set of nodes visited.
41 int m_num_plies; ///< Number of plies cycled.
42 bool m_is_path; ///< True if path is complete.
43
44 public:
45
46 /// Constructor needs Object doing pathfinding, start and end positions.
47 PathFind(Object *p_o, Vector start, Vector end);
48 ~PathFind();
49
50 /// Go through one search cycle.
51 /// Returns indication if found path {found, not found, incomplete}.
52 SearchResult cycleOnce();
53
54 /// Return path.
55 Path getPath() const;
56
57 /// Set object seeking path.
58 void setObject(Object *new_p_o);
59
60 /// Return object seeking path.
61 Object *getObject() const;
62
63 /// Return number of plies.
64 int getNumPlies() const;
65
66 /// Set target object.
67 /// Pathfinding stops when target object discovered.
68 void setTargetObject(Object *p_target_o);
69
70 /// Get target object.
71 /// Pathfinding stops when target object discovered.
73};
74
75} // end of namespace df
76#endif //__PATHFIND_H__
Definition: Object.h:59
Definition: PathFind.h:31
Object * getObject() const
Return object seeking path.
void setObject(Object *new_p_o)
Set object seeking path.
Object * getTargetObject()
Get target object.
Path getPath() const
Return path.
int getNumPlies() const
Return number of plies.
std::vector< coord_struct > m_open_set
Set of nodes not yet visited.
Definition: PathFind.h:39
std::vector< coord_struct > m_closed_set
Set of nodes visited.
Definition: PathFind.h:40
SearchResult cycleOnce()
Go through one search cycle.
Object * m_p_o
Object finding path.
Definition: PathFind.h:34
Object * m_p_target_o
Object target (optional).
Definition: PathFind.h:35
coord_struct m_end
End target position.
Definition: PathFind.h:37
void setTargetObject(Object *p_target_o)
Set target object.
coord_struct m_start
Start position.
Definition: PathFind.h:36
bool m_is_path
True if path is complete.
Definition: PathFind.h:42
PathFind(Object *p_o, Vector start, Vector end)
Constructor needs Object doing pathfinding, start and end positions.
struct node_struct ** m_node
All nodes in 2d graph/grid.
Definition: PathFind.h:38
int m_num_plies
Number of plies cycled.
Definition: PathFind.h:41
Definition: Path.h:17
Definition: Vector.h:12
An animation for a sprite.
Definition: Animation.h:15
Definition: PathFind.h:20
Definition: PathFind.h:25