ScummVM API documentation
AINodeContainer.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_AI_NODE_CONTAINER_H
29#define HPL_AI_NODE_CONTAINER_H
30
31#include "hpl1/engine/math/MathTypes.h"
32#include "hpl1/engine/system/SystemTypes.h"
33
34#include "common/array.h"
35#include "common/list.h"
36#include "hpl1/engine/physics/PhysicsWorld.h"
37
38namespace hpl {
39
40class cWorld3D;
41
42//--------------------------------
43
44typedef tFlag tAIFreePathFlag;
45
46#define eAIFreePathFlag_SkipStatic (0x00000001)
47#define eAIFreePathFlag_SkipDynamic (0x00000002)
48#define eAIFreePathFlag_SkipVolatile (0x00000004)
49
50//--------------------------------
51class cAINode;
52
54public:
55 float mfDistance;
56 float mfSqrDistance;
57 cAINode *mpNode;
58};
59
61typedef tAINodeEdgeVec::iterator tAINodeEdgeVecIt;
62
63//--------------------------------
64
65class cAINode {
66 friend class cAINodeContainer;
67
68public:
69 cAINode();
70 ~cAINode();
71
72 void AddEdge(cAINode *pNode);
73
74 int GetEdgeNum() const { return (int)mvEdges.size(); }
75 inline cAINodeEdge *GetEdge(int alIdx) { return &mvEdges[alIdx]; }
76
77 const cVector3f &GetPosition() { return mvPosition; }
78
79 const tString &GetName() { return msName; }
80
81private:
82 tString msName;
83 cVector3f mvPosition;
84 void *mpUserData;
85
86 tAINodeEdgeVec mvEdges;
87};
88
90typedef tAINodeVec::iterator tAINodeVecIt;
91
94
96typedef tAINodeMap::iterator tAINodeMapIt;
97
98//--------------------------------
99
101public:
102 virtual ~iAIFreePathCallback() = default;
103 virtual bool Intersects(iPhysicsBody *pBody, cPhysicsRayParams *apParams) = 0;
104};
105
106//--------------------------------
107
109public:
110 void Reset();
111 void SetFlags(tAIFreePathFlag aFlags) { mFlags = aFlags; }
112
113 bool BeforeIntersect(iPhysicsBody *pBody);
114 bool OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams);
115
116 bool Intersected();
117
118 iAIFreePathCallback *mpCallback;
119
120private:
121 bool mbIntersected;
122 tAIFreePathFlag mFlags;
123};
124
125//--------------------------------
126
128public:
129 tAINodeList mlstNodes;
130};
131
132//--------------------------------
133class cAINodeContainer;
134
136public:
137 cAINodeIterator(cAINodeContainer *apContainer, const cVector3f &avPos, float afRadius);
138
139 bool HasNext();
140 cAINode *Next();
141
142private:
143 bool IncGridPos();
144
145 cAINodeContainer *mpContainer;
146 cVector3f mvPosition;
147 float mfRadius;
148 cVector2l mvStartGridPos;
149 cVector2l mvEndGridPos;
150 cVector2l mvGridPos;
151
152 tAINodeList *mpNodeList;
153 tAINodeListIt mNodeIt;
154};
155
156//--------------------------------
157
159 friend class cAINodeIterator;
160
161public:
162 cAINodeContainer(const tString &asName, const tString &asNodeName,
163 cWorld3D *apWorld, const cVector3f &avCollideSize);
165
166 const tString &GetNodeName() { return msNodeName; }
167 const tString &GetName() { return msName; }
168
169 const cVector3f &GetCollideSize() { return mvSize; }
170
175 void ReserveSpace(size_t alReserveSpace);
176
183 void AddNode(const tString &asName, const cVector3f &avPosition, void *apUserData = NULL);
184
188 int GetNodeNum() const;
189
194 inline cAINode *GetNode(int alIdx) { return mvNodes[alIdx]; }
195
201
205 void Compile();
206
211
218 cAINodeIterator GetNodeIterator(const cVector3f &avPosition, float afRadius);
219
229 bool FreePath(const cVector3f &avStart, const cVector3f &avEnd, int alRayNum = -1,
230 tAIFreePathFlag aFlags = 0, iAIFreePathCallback *apCallback = NULL);
231
236 void SetMaxEdges(int alX) { mlMaxNodeEnds = alX; }
237
241 void SetMinEdges(int alX) { mlMinNodeEnds = alX; }
242
247 void SetMaxEdgeDistance(float afX) { mfMaxEndDistance = afX; }
248
249 float GetMaxEdgeDistance() const { return mfMaxEndDistance; }
250
251 void SetMaxHeight(float afX) { mfMaxHeight = afX; }
252 float GetMaxHeight() const { return mfMaxHeight; }
253
258 void SetNodeIsAtCenter(bool abX) { mbNodeIsAtCenter = abX; }
259 bool GetNodeIsAtCenter() { return mbNodeIsAtCenter; }
260
264 void SaveToFile(const tString &asFile);
268 void LoadFromFile(const tString &asFile);
269
270private:
271 cVector2l GetGridPosFromLocal(const cVector2f &avLocalPos);
272 cAIGridNode *GetGrid(const cVector2l &avPos);
273
274 tString msName;
275 tString msNodeName;
276
277 cWorld3D *mpWorld;
278 cVector3f mvSize;
279
280 cAINodeRayCallback *mpRayCallback;
281 tAINodeVec mvNodes;
282 tAINodeMap m_mapNodes;
283
284 bool mbNodeIsAtCenter;
285
286 cVector2l mvGridMapSize;
287 cVector2f mvGridSize;
288 cVector2f mvMinGridPos;
289 cVector2f mvMaxGridPos;
290 int mlNodesPerGrid;
291
293
294 // properties
295 int mlMaxNodeEnds;
296 int mlMinNodeEnds;
297 float mfMaxEndDistance;
298 float mfMaxHeight;
299};
300
301} // namespace hpl
302
303#endif // HPL_AI_NODE_CONTAINER_H
cAINodeEdge * iterator
Definition: array.h:54
size_type size() const
Definition: array.h:316
typename TreeT::BasicIterator iterator
Definition: stablemap.h:48
Definition: str.h:59
Definition: AINodeContainer.h:127
Definition: AINodeContainer.h:158
bool FreePath(const cVector3f &avStart, const cVector3f &avEnd, int alRayNum=-1, tAIFreePathFlag aFlags=0, iAIFreePathCallback *apCallback=NULL)
cAINode * GetNodeFromName(const tString &asName)
cAINode * GetNode(int alIdx)
Definition: AINodeContainer.h:194
void SetMaxEdges(int alX)
Definition: AINodeContainer.h:236
void SaveToFile(const tString &asFile)
void SetMaxEdgeDistance(float afX)
Definition: AINodeContainer.h:247
void ReserveSpace(size_t alReserveSpace)
void SetNodeIsAtCenter(bool abX)
Definition: AINodeContainer.h:258
int GetNodeNum() const
void SetMinEdges(int alX)
Definition: AINodeContainer.h:241
cAINodeIterator GetNodeIterator(const cVector3f &avPosition, float afRadius)
void LoadFromFile(const tString &asFile)
void AddNode(const tString &asName, const cVector3f &avPosition, void *apUserData=NULL)
Definition: AINodeContainer.h:53
Definition: AINodeContainer.h:65
Definition: AINodeContainer.h:135
Definition: AINodeContainer.h:108
Definition: World3D.h:179
Definition: AINodeContainer.h:100
Definition: PhysicsBody.h:117
Definition: PhysicsWorld.h:100
Definition: list_intern.h:54
Definition: PhysicsWorld.h:92