]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/ai/AAS_local.h
hello world
[icculus/iodoom3.git] / neo / d3xp / ai / AAS_local.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #ifndef __AAS_LOCAL_H__
30 #define __AAS_LOCAL_H__
31
32 #include "AAS.h"
33 #include "../Pvs.h"
34
35
36 class idRoutingCache {
37         friend class idAASLocal;
38
39 public:
40                                                                 idRoutingCache( int size );
41                                                                 ~idRoutingCache( void );
42
43         int                                                     Size( void ) const;
44
45 private:
46         int                                                     type;                                   // portal or area cache
47         int                                                     size;                                   // size of cache
48         int                                                     cluster;                                // cluster of the cache
49         int                                                     areaNum;                                // area of the cache
50         int                                                     travelFlags;                    // combinations of the travel flags
51         idRoutingCache *                        next;                                   // next in list
52         idRoutingCache *                        prev;                                   // previous in list
53         idRoutingCache *                        time_next;                              // next in time based list
54         idRoutingCache *                        time_prev;                              // previous in time based list
55         unsigned short                          startTravelTime;                // travel time to start with
56         unsigned char *                         reachabilities;                 // reachabilities used for routing
57         unsigned short *                        travelTimes;                    // travel time for every area
58 };
59
60
61 class idRoutingUpdate {
62         friend class idAASLocal;
63
64 private:
65         int                                                     cluster;                                // cluster number of this update
66         int                                                     areaNum;                                // area number of this update
67         unsigned short                          tmpTravelTime;                  // temporary travel time
68         unsigned short *                        areaTravelTimes;                // travel times within the area
69         idVec3                                          start;                                  // start point into area
70         idRoutingUpdate *                       next;                                   // next in list
71         idRoutingUpdate *                       prev;                                   // prev in list
72         bool                                            isInList;                               // true if the update is in the list
73 };
74
75
76 class idRoutingObstacle {
77         friend class idAASLocal;
78                                                                 idRoutingObstacle( void ) { }
79
80 private:
81         idBounds                                        bounds;                                 // obstacle bounds
82         idList<int>                                     areas;                                  // areas the bounds are in
83 };
84
85
86 class idAASLocal : public idAAS {
87 public:
88                                                                 idAASLocal( void );
89         virtual                                         ~idAASLocal( void );
90         virtual bool                            Init( const idStr &mapName, unsigned int mapFileCRC );
91         virtual void                            Shutdown( void );
92         virtual void                            Stats( void ) const;
93         virtual void                            Test( const idVec3 &origin );
94         virtual const idAASSettings *GetSettings( void ) const;
95         virtual int                                     PointAreaNum( const idVec3 &origin ) const;
96         virtual int                                     PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags ) const;
97         virtual int                                     BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags ) const;
98         virtual void                            PushPointIntoAreaNum( int areaNum, idVec3 &origin ) const;
99         virtual idVec3                          AreaCenter( int areaNum ) const;
100         virtual int                                     AreaFlags( int areaNum ) const;
101         virtual int                                     AreaTravelFlags( int areaNum ) const;
102         virtual bool                            Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const;
103         virtual const idPlane &         GetPlane( int planeNum ) const;
104         virtual int                                     GetWallEdges( int areaNum, const idBounds &bounds, int travelFlags, int *edges, int maxEdges ) const;
105         virtual void                            SortWallEdges( int *edges, int numEdges ) const;
106         virtual void                            GetEdgeVertexNumbers( int edgeNum, int verts[2] ) const;
107         virtual void                            GetEdge( int edgeNum, idVec3 &start, idVec3 &end ) const;
108         virtual bool                            SetAreaState( const idBounds &bounds, const int areaContents, bool disabled );
109         virtual aasHandle_t                     AddObstacle( const idBounds &bounds );
110         virtual void                            RemoveObstacle( const aasHandle_t handle );
111         virtual void                            RemoveAllObstacles( void );
112         virtual int                                     TravelTimeToGoalArea( int areaNum, const idVec3 &origin, int goalAreaNum, int travelFlags ) const;
113         virtual bool                            RouteToGoalArea( int areaNum, const idVec3 origin, int goalAreaNum, int travelFlags, int &travelTime, idReachability **reach ) const;
114         virtual bool                            WalkPathToGoal( aasPath_t &path, int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags ) const;
115         virtual bool                            WalkPathValid( int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags, idVec3 &endPos, int &endAreaNum ) const;
116         virtual bool                            FlyPathToGoal( aasPath_t &path, int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags ) const;
117         virtual bool                            FlyPathValid( int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags, idVec3 &endPos, int &endAreaNum ) const;
118         virtual void                            ShowWalkPath( const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const;
119         virtual void                            ShowFlyPath( const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const;
120         virtual bool                            FindNearestGoal( aasGoal_t &goal, int areaNum, const idVec3 origin, const idVec3 &target, int travelFlags, aasObstacle_t *obstacles, int numObstacles, idAASCallback &callback ) const;
121
122 private:
123         idAASFile *                                     file;
124         idStr                                           name;
125
126 private:        // routing data
127         idRoutingCache ***                      areaCacheIndex;                 // for each area in each cluster the travel times to all other areas in the cluster
128         int                                                     areaCacheIndexSize;             // number of area cache entries
129         idRoutingCache **                       portalCacheIndex;               // for each area in the world the travel times from each portal
130         int                                                     portalCacheIndexSize;   // number of portal cache entries
131         idRoutingUpdate *                       areaUpdate;                             // memory used to update the area routing cache
132         idRoutingUpdate *                       portalUpdate;                   // memory used to update the portal routing cache
133         unsigned short *                        goalAreaTravelTimes;    // travel times to goal areas
134         unsigned short *                        areaTravelTimes;                // travel times through the areas
135         int                                                     numAreaTravelTimes;             // number of area travel times
136         mutable idRoutingCache *        cacheListStart;                 // start of list with cache sorted from oldest to newest
137         mutable idRoutingCache *        cacheListEnd;                   // end of list with cache sorted from oldest to newest
138         mutable int                                     totalCacheMemory;               // total cache memory used
139         idList<idRoutingObstacle *>     obstacleList;                   // list with obstacles
140
141 private:        // routing
142         bool                                            SetupRouting( void );
143         void                                            ShutdownRouting( void );
144         unsigned short                          AreaTravelTime( int areaNum, const idVec3 &start, const idVec3 &end ) const;
145         void                                            CalculateAreaTravelTimes( void );
146         void                                            DeleteAreaTravelTimes( void );
147         void                                            SetupRoutingCache( void );
148         void                                            DeleteClusterCache( int clusterNum );
149         void                                            DeletePortalCache( void );
150         void                                            ShutdownRoutingCache( void );
151         void                                            RoutingStats( void ) const;
152         void                                            LinkCache( idRoutingCache *cache ) const;
153         void                                            UnlinkCache( idRoutingCache *cache ) const;
154         void                                            DeleteOldestCache( void ) const;
155         idReachability *                        GetAreaReachability( int areaNum, int reachabilityNum ) const;
156         int                                                     ClusterAreaNum( int clusterNum, int areaNum ) const;
157         void                                            UpdateAreaRoutingCache( idRoutingCache *areaCache ) const;
158         idRoutingCache *                        GetAreaRoutingCache( int clusterNum, int areaNum, int travelFlags ) const;
159         void                                            UpdatePortalRoutingCache( idRoutingCache *portalCache ) const;
160         idRoutingCache *                        GetPortalRoutingCache( int clusterNum, int areaNum, int travelFlags ) const;
161         void                                            RemoveRoutingCacheUsingArea( int areaNum );
162         void                                            DisableArea( int areaNum );
163         void                                            EnableArea( int areaNum );
164         bool                                            SetAreaState_r( int nodeNum, const idBounds &bounds, const int areaContents, bool disabled );
165         void                                            GetBoundsAreas_r( int nodeNum, const idBounds &bounds, idList<int> &areas ) const;
166         void                                            SetObstacleState( const idRoutingObstacle *obstacle, bool enable );
167
168 private:        // pathing
169         bool                                            EdgeSplitPoint( idVec3 &split, int edgeNum, const idPlane &plane ) const;
170         bool                                            FloorEdgeSplitPoint( idVec3 &split, int areaNum, const idPlane &splitPlane, const idPlane &frontPlane, bool closest ) const;
171         idVec3                                          SubSampleWalkPath( int areaNum, const idVec3 &origin, const idVec3 &start, const idVec3 &end, int travelFlags, int &endAreaNum ) const;
172         idVec3                                          SubSampleFlyPath( int areaNum, const idVec3 &origin, const idVec3 &start, const idVec3 &end, int travelFlags, int &endAreaNum ) const;
173
174 private:        // debug
175         const idBounds &                        DefaultSearchBounds( void ) const;
176         void                                            DrawCone( const idVec3 &origin, const idVec3 &dir, float radius, const idVec4 &color ) const;
177         void                                            DrawArea( int areaNum ) const;
178         void                                            DrawFace( int faceNum, bool side ) const;
179         void                                            DrawEdge( int edgeNum, bool arrow ) const;
180         void                                            DrawReachability( const idReachability *reach ) const;
181         void                                            ShowArea( const idVec3 &origin ) const;
182         void                                            ShowWallEdges( const idVec3 &origin ) const;
183         void                                            ShowHideArea( const idVec3 &origin, int targerAreaNum ) const;
184         bool                                            PullPlayer( const idVec3 &origin, int toAreaNum ) const;
185         void                                            RandomPullPlayer( const idVec3 &origin ) const;
186         void                                            ShowPushIntoArea( const idVec3 &origin ) const;
187 };
188
189 #endif /* !__AAS_LOCAL_H__ */