ScummVM API documentation
AStar.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/*
23 * Copyright (C) 2006-2010 - Frictional Games
24 *
25 * This file is part of HPL1 Engine.
26 */
27
28#ifndef HPL_A_STAR_H
29#define HPL_A_STAR_H
30
31#include "common/list.h"
32#include "hpl1/engine/game/GameTypes.h"
33#include "hpl1/engine/math/MathTypes.h"
34#include "hpl1/engine/system/SystemTypes.h"
35
36namespace hpl {
37
38class cAINodeContainer;
39class cAINode;
40
41//--------------------------------------
42
43typedef Hpl1::Std::set<cAINode *> tAINodeSet;
44typedef tAINodeSet::iterator tAINodeSetIt;
45
46//--------------------------------------
47
48typedef Common::List<cAINode *> tAINodeList;
49typedef tAINodeList::iterator tAINodeListIt;
50
51//--------------------------------------
52
54public:
55 cAStarNode(cAINode *apAINode);
56
57 float mfCost;
58 float mfDistance;
59
60 cAStarNode *mpParent;
61 cAINode *mpAINode;
62};
63
65public:
66 bool operator()(cAStarNode *apNodeA, cAStarNode *apNodeB) const;
67};
68
70typedef tAStarNodeSet::iterator tAStarNodeSetIt;
71
72//--------------------------------------
73class cAStarHandler;
74
76public:
77 virtual ~iAStarCallback() {}
78
79 virtual bool CanAddNode(cAINode *apParentNode, cAINode *apChildNode) = 0;
80};
81
82//--------------------------------------
83
85public:
86 cAStarHandler(cAINodeContainer *apContainer);
88
89 bool GetPath(const cVector3f &avStart, const cVector3f &avGoal, tAINodeList *apNodeList);
90
95 void SetMaxIterations(int alX) { mlMaxIterations = alX; }
96
97 void SetCallback(iAStarCallback *apCallback) { mpCallback = apCallback; }
98
99private:
100 void IterateAlgorithm();
101
102 void AddOpenNode(cAINode *apAINode, cAStarNode *apParent, float afDistance);
103
104 cAStarNode *GetBestNode();
105
106 float Cost(float afDistance, cAINode *apAINode, cAStarNode *apParent);
107 float Heuristic(const cVector3f &avStart, const cVector3f &avGoal);
108
109 bool IsGoalNode(cAINode *apAINode);
110
111 cVector3f mvGoal;
112
113 cAStarNode *mpGoalNode;
114 tAINodeSet m_setGoalNodes;
115
116 cAINodeContainer *mpContainer;
117
118 int mlMaxIterations;
119
120 iAStarCallback *mpCallback;
121
122 tAStarNodeSet m_setOpenList;
123 tAStarNodeSet m_setClosedList;
124};
125
126} // namespace hpl
127
128#endif // HPL_A_STAR_H
ListInternal::Iterator< cAINode * > iterator
Definition: list.h:52
Definition: AINodeContainer.h:158
Definition: AINodeContainer.h:65
Definition: AStar.h:84
void SetMaxIterations(int alX)
Definition: AStar.h:95
Definition: AStar.h:64
Definition: AStar.h:53
Definition: AStar.h:75