]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/game/ai/AAS.cpp
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / game / ai / AAS.cpp
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 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "AAS_local.h"
33
34 /*
35 ============
36 idAAS::Alloc
37 ============
38 */
39 idAAS *idAAS::Alloc( void ) {
40         return new idAASLocal;
41 }
42
43 /*
44 ============
45 idAAS::idAAS
46 ============
47 */
48 idAAS::~idAAS( void ) {
49 }
50
51 /*
52 ============
53 idAASLocal::idAASLocal
54 ============
55 */
56 idAASLocal::idAASLocal( void ) {
57         file = NULL;
58 }
59
60 /*
61 ============
62 idAASLocal::~idAASLocal
63 ============
64 */
65 idAASLocal::~idAASLocal( void ) {
66         Shutdown();
67 }
68
69 /*
70 ============
71 idAASLocal::Init
72 ============
73 */
74 bool idAASLocal::Init( const idStr &mapName, unsigned int mapFileCRC ) {
75         if ( file && mapName.Icmp( file->GetName() ) == 0 && mapFileCRC == file->GetCRC() ) {
76                 common->Printf( "Keeping %s\n", file->GetName() );
77                 RemoveAllObstacles();
78         }
79         else {
80                 Shutdown();
81
82                 file = AASFileManager->LoadAAS( mapName, mapFileCRC );
83                 if ( !file ) {
84                         common->DWarning( "Couldn't load AAS file: '%s'", mapName.c_str() );
85                         return false;
86                 }
87                 SetupRouting();
88         }
89         return true;
90 }
91
92 /*
93 ============
94 idAASLocal::Shutdown
95 ============
96 */
97 void idAASLocal::Shutdown( void ) {
98         if ( file ) {
99                 ShutdownRouting();
100                 RemoveAllObstacles();
101                 AASFileManager->FreeAAS( file );
102                 file = NULL;
103         }
104 }
105
106 /*
107 ============
108 idAASLocal::Stats
109 ============
110 */
111 void idAASLocal::Stats( void ) const {
112         if ( !file ) {
113                 return;
114         }
115         common->Printf( "[%s]\n", file->GetName() );
116         file->PrintInfo();
117         RoutingStats();
118 }
119
120 /*
121 ============
122 idAASLocal::GetSettings
123 ============
124 */
125 const idAASSettings *idAASLocal::GetSettings( void ) const {
126         if ( !file ) {
127                 return NULL;
128         }
129         return &file->GetSettings();
130 }
131
132 /*
133 ============
134 idAASLocal::PointAreaNum
135 ============
136 */
137 int idAASLocal::PointAreaNum( const idVec3 &origin ) const {
138         if ( !file ) {
139                 return 0;
140         }
141         return file->PointAreaNum( origin );
142 }
143
144 /*
145 ============
146 idAASLocal::PointReachableAreaNum
147 ============
148 */
149 int idAASLocal::PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags ) const {
150         if ( !file ) {
151                 return 0;
152         }
153
154         return file->PointReachableAreaNum( origin, searchBounds, areaFlags, TFL_INVALID );
155 }
156
157 /*
158 ============
159 idAASLocal::BoundsReachableAreaNum
160 ============
161 */
162 int idAASLocal::BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags ) const {
163         if ( !file ) {
164                 return 0;
165         }
166         
167         return file->BoundsReachableAreaNum( bounds, areaFlags, TFL_INVALID );
168 }
169
170 /*
171 ============
172 idAASLocal::PushPointIntoAreaNum
173 ============
174 */
175 void idAASLocal::PushPointIntoAreaNum( int areaNum, idVec3 &origin ) const {
176         if ( !file ) {
177                 return;
178         }
179         file->PushPointIntoAreaNum( areaNum, origin );
180 }
181
182 /*
183 ============
184 idAASLocal::AreaCenter
185 ============
186 */
187 idVec3 idAASLocal::AreaCenter( int areaNum ) const {
188         if ( !file ) {
189                 return vec3_origin;
190         }
191         return file->GetArea( areaNum ).center;
192 }
193
194 /*
195 ============
196 idAASLocal::AreaFlags
197 ============
198 */
199 int idAASLocal::AreaFlags( int areaNum ) const {
200         if ( !file ) {
201                 return 0;
202         }
203         return file->GetArea( areaNum ).flags;
204 }
205
206 /*
207 ============
208 idAASLocal::AreaTravelFlags
209 ============
210 */
211 int idAASLocal::AreaTravelFlags( int areaNum ) const {
212         if ( !file ) {
213                 return 0;
214         }
215         return file->GetArea( areaNum ).travelFlags;
216 }
217
218 /*
219 ============
220 idAASLocal::Trace
221 ============
222 */
223 bool idAASLocal::Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const {
224         if ( !file ) {
225                 trace.fraction = 0.0f;
226                 trace.lastAreaNum = 0;
227                 trace.numAreas = 0;
228                 return true;
229         }
230         return file->Trace( trace, start, end );
231 }
232
233 /*
234 ============
235 idAASLocal::GetPlane
236 ============
237 */
238 const idPlane &idAASLocal::GetPlane( int planeNum ) const {
239         if ( !file ) {
240                 static idPlane dummy;
241                 return dummy;
242         }
243         return file->GetPlane( planeNum );
244 }
245
246 /*
247 ============
248 idAASLocal::GetEdgeVertexNumbers
249 ============
250 */
251 void idAASLocal::GetEdgeVertexNumbers( int edgeNum, int verts[2] ) const {
252         if ( !file ) {
253                 verts[0] = verts[1] = 0;
254                 return;
255         }
256         const int *v = file->GetEdge( abs(edgeNum) ).vertexNum;
257         verts[0] = v[INTSIGNBITSET(edgeNum)];
258         verts[1] = v[INTSIGNBITNOTSET(edgeNum)];
259 }
260
261 /*
262 ============
263 idAASLocal::GetEdge
264 ============
265 */
266 void idAASLocal::GetEdge( int edgeNum, idVec3 &start, idVec3 &end ) const {
267         if ( !file ) {
268                 start.Zero();
269                 end.Zero();
270                 return;
271         }
272         const int *v = file->GetEdge( abs(edgeNum) ).vertexNum;
273         start = file->GetVertex( v[INTSIGNBITSET(edgeNum)] );
274         end = file->GetVertex( v[INTSIGNBITNOTSET(edgeNum)] );
275 }