ScummVM API documentation
astar_path.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_PATHFINDER_ASTAR_PATH_H
23 #define NUVIE_PATHFINDER_ASTAR_PATH_H
24 
25 #include "ultima/nuvie/core/map.h"
26 #include "ultima/nuvie/pathfinder/path.h"
27 
28 namespace Ultima {
29 namespace Nuvie {
30 
31 typedef struct astar_node_s {
32  MapCoord loc; // location
33  uint32 to_start; // costs from this node to start and to goal
34  uint32 to_goal;
35  uint32 score; // node score
36  uint32 len; // number of nodes before this one, regardless of score
37  struct astar_node_s *parent;
38  astar_node_s() : loc(0, 0, 0), to_start(0), to_goal(0), score(0), len(0),
39  parent(nullptr) { }
40 } astar_node;
41 /* Provides A* search and cost methods for PathFinder and subclasses.
42  */class AStarPath: public Path {
43 protected:
44  Std::list<astar_node *> open_nodes, closed_nodes; // nodes seen
45  astar_node *final_node; // last node in path search, used by create_path()
46  /* Forms a usable path from results of a search. */
47  void create_path();
48  /* Search routine. */
49  bool search_node_neighbors(astar_node *nnode, const MapCoord &goal, const uint32 max_score);
50  bool compare_neighbors(astar_node *nnode, astar_node *neighbor,
51  sint32 nnode_to_neighbor, astar_node *in_open,
52  astar_node *in_closed);
53  bool score_to_neighbor(sint8 dir, astar_node *nnode, astar_node *neighbor,
54  sint32 &nnode_to_neighbor);
55 public:
56  AStarPath();
57  ~AStarPath() override { }
58  bool path_search(const MapCoord &start, const MapCoord &goal) override;
59  uint32 path_cost_est(const MapCoord &s, const MapCoord &g) override {
60  return Path::path_cost_est(s, g);
61  }
62  uint32 get_max_score(uint32 cost) override {
63  return Path::get_max_score(cost);
64  }
65  uint32 path_cost_est(const astar_node &n1, const astar_node &n2) {
66  return Path::path_cost_est(n1.loc, n2.loc);
67  }
68  sint32 step_cost(const MapCoord &c1, const MapCoord &c2) override;
69 protected:
70  /* FIXME: These node functions can be replaced with a priority_queue and a list. */
71  astar_node *find_open_node(astar_node *ncmp);
72  void push_open_node(astar_node *node);
73  astar_node *pop_open_node();
74  astar_node *find_closed_node(astar_node *ncmp);
75  void remove_closed_node(astar_node *ncmp);
76  void delete_nodes();
77 };
78 
79 } // End of namespace Nuvie
80 } // End of namespace Ultima
81 
82 #endif
Definition: path.h:36
Definition: detection.h:27
Definition: astar_path.h:42
Definition: astar_path.h:31
Definition: map.h:84
Definition: containers.h:200