Debian Codegraph @

code/botlib/be_aas_sample.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, 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 Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 /*****************************************************************************
24 * name: be_aas_sample.c
25 *
26 * desc: AAS environment sampling
27 *
28 * $Archive: /MissionPack/code/botlib/be_aas_sample.c $
29 *
30 *****************************************************************************/
31
32 #include "../qcommon/q_shared.h"
33 #include "l_memory.h"
34 #include "l_script.h"
35 #include "l_precomp.h"
36 #include "l_struct.h"
37 #ifndef BSPC
38 #include "l_libvar.h"
39 #endif
40 #include "aasfile.h"
41 #include "botlib.h"
42 #include "be_aas.h"
43 #include "be_interface.h"
44 #include "be_aas_funcs.h"
45 #include "be_aas_def.h"
46
47
48 //#define AAS_SAMPLE_DEBUG
49
50 #define BBOX_NORMAL_EPSILON 0.001
51
52 #define ON_EPSILON 0 //0.0005
53
54 #define TRACEPLANE_EPSILON 0.125
55
56 typedef struct aas_tracestack_s
57 {
58 vec3_t start; //start point of the piece of line to trace
59 vec3_t end; //end point of the piece of line to trace
60 int planenum; //last plane used as splitter
61 int nodenum; //node found after splitting with planenum
62 } aas_tracestack_t;
63
64 int numaaslinks;
65
66 //===========================================================================
67 //
68 // Parameter: -
69 // Returns: -
70 // Changes Globals: -
71 //===========================================================================
72 void AAS_PresenceTypeBoundingBox(int presencetype, vec3_t mins, vec3_t maxs)
73 {
74 int index;
75 //bounding box size for each presence type
76 vec3_t boxmins[3] = {{0, 0, 0}, {-15, -15, -24}, {-15, -15, -24}};
77 vec3_t boxmaxs[3] = {{0, 0, 0}, { 15, 15, 32}, { 15, 15, 8}};
78
79 if (presencetype == PRESENCE_NORMAL) index = 1;
80 else if (presencetype == PRESENCE_CROUCH) index = 2;
81 else
82 {
83 botimport.Print(PRT_FATAL, "AAS_PresenceTypeBoundingBox: unknown presence type\n");
84 index = 2;
85 } //end if
86 VectorCopy(boxmins[index], mins);
87 VectorCopy(boxmaxs[index], maxs);
88 } //end of the function AAS_PresenceTypeBoundingBox
89 //===========================================================================
90 //
91 // Parameter: -
92 // Returns: -
93 // Changes Globals: -
94 //===========================================================================
95 void AAS_InitAASLinkHeap(void)
96 {
97 int i, max_aaslinks;
98
99 max_aaslinks = aasworld.linkheapsize;
100 //if there's no link heap present
101 if (!aasworld.linkheap)
102 {
103 #ifdef BSPC
104 max_aaslinks = 6144;
105 #else
106 max_aaslinks = (int) LibVarValue("max_aaslinks", "6144");
107 #endif
108 if (max_aaslinks < 0) max_aaslinks = 0;
109 aasworld.linkheapsize = max_aaslinks;
110 aasworld.linkheap = (aas_link_t *) GetHunkMemory(max_aaslinks * sizeof(aas_link_t));
111 } //end if
112 //link the links on the heap
113 aasworld.linkheap[0].prev_ent = NULL;
114 aasworld.linkheap[0].next_ent = &aasworld.linkheap[1];
115 for (i = 1; i < max_aaslinks-1; i++)
116 {
117 aasworld.linkheap[i].prev_ent = &aasworld.linkheap[i - 1];
118 aasworld.linkheap[i].next_ent = &aasworld.linkheap[i + 1];
119 } //end for
120 aasworld.linkheap[max_aaslinks-1].prev_ent = &aasworld.linkheap[max_aaslinks-2];
121 aasworld.linkheap[max_aaslinks-1].next_ent = NULL;
122 //pointer to the first free link
123 aasworld.freelinks = &aasworld.linkheap[0];
124 //
125 numaaslinks = max_aaslinks;
126 } //end of the function AAS_InitAASLinkHeap
127 //===========================================================================
128 //
129 // Parameter: -
130 // Returns: -
131 // Changes Globals: -
132 //===========================================================================
133 void AAS_FreeAASLinkHeap(void)
134 {
135 if (aasworld.linkheap) FreeMemory(aasworld.linkheap);
136 aasworld.linkheap = NULL;
137 aasworld.linkheapsize = 0;
138 } //end of the function AAS_FreeAASLinkHeap
139 //===========================================================================
140 //
141 // Parameter: -
142 // Returns: -
143 // Changes Globals: -
144 //===========================================================================
145 aas_link_t *AAS_AllocAASLink(void)
146 {
147 aas_link_t *link;
148
149 link = aasworld.freelinks;
150 if (!link)
151 {
152 #ifndef BSPC
153 if (botDeveloper)
154 #endif
155 {
156 botimport.Print(PRT_FATAL, "empty aas link heap\n");
157 } //end if
158 return NULL;
159 } //end if
160 if (aasworld.freelinks) aasworld.freelinks = aasworld.freelinks->next_ent;
161 if (aasworld.freelinks) aasworld.freelinks->prev_ent = NULL;
162 numaaslinks--;
163 return link;
164 } //end of the function AAS_AllocAASLink
165 //===========================================================================
166 //
167 // Parameter: -
168 // Returns: -
169 // Changes Globals: -
170 //===========================================================================
171 void AAS_DeAllocAASLink(aas_link_t *link)
172 {
173 if (aasworld.freelinks) aasworld.freelinks->prev_ent = link;
174 link->prev_ent = NULL;
175 link->next_ent = aasworld.freelinks;
176 link->prev_area = NULL;
177 link->next_area = NULL;
178 aasworld.freelinks = link;
179 numaaslinks++;
180 } //end of the function AAS_DeAllocAASLink
181 //===========================================================================
182 //
183 // Parameter: -
184 // Returns: -
185 // Changes Globals: -
186 //===========================================================================
187 void AAS_InitAASLinkedEntities(void)
188 {
189 if (!aasworld.loaded) return;
190 if (aasworld.arealinkedentities) FreeMemory(aasworld.arealinkedentities);
191 aasworld.arealinkedentities = (aas_link_t **) GetClearedHunkMemory(
192 aasworld.numareas * sizeof(aas_link_t *));
193 } //end of the function AAS_InitAASLinkedEntities
194 //===========================================================================
195 //
196 // Parameter: -
197 // Returns: -
198 // Changes Globals: -
199 //===========================================================================
200 void AAS_FreeAASLinkedEntities(void)
201 {
202 if (aasworld.arealinkedentities) FreeMemory(aasworld.arealinkedentities);
203 aasworld.arealinkedentities = NULL;
204 } //end of the function AAS_InitAASLinkedEntities
205 //===========================================================================
206 // returns the AAS area the point is in
207 //
208 // Parameter: -
209 // Returns: -
210 // Changes Globals: -
211 //===========================================================================
212 int AAS_PointAreaNum(vec3_t point)
213 {
214 int nodenum;
215 vec_t dist;
216 aas_node_t *node;
217 aas_plane_t *plane;
218
219 if (!aasworld.loaded)
220 {
221 botimport.Print(PRT_ERROR, "AAS_PointAreaNum: aas not loaded\n");
222 return 0;
223 } //end if
224
225 //start with node 1 because node zero is a dummy used for solid leafs
226 nodenum = 1;
227 while (nodenum > 0)
228 {
229 // botimport.Print(PRT_MESSAGE, "[%d]", nodenum);
230 #ifdef AAS_SAMPLE_DEBUG
231 if (nodenum >= aasworld.numnodes)
232 {
233 botimport.Print(PRT_ERROR, "nodenum = %d >= aasworld.numnodes = %d\n", nodenum, aasworld.numnodes);
234 return 0;
235 } //end if
236 #endif //AAS_SAMPLE_DEBUG
237 node = &aasworld.nodes[nodenum];
238 #ifdef AAS_SAMPLE_DEBUG
239 if (node->planenum < 0 || node->planenum >= aasworld.numplanes)
240 {
241 botimport.Print(PRT_ERROR, "node->planenum = %d >= aasworld.numplanes = %d\n", node->planenum, aasworld.numplanes);
242 return 0;
243 } //end if
244 #endif //AAS_SAMPLE_DEBUG
245 plane = &aasworld.planes[node->planenum];
246 dist = DotProduct(point, plane->normal) - plane->dist;
247 if (dist > 0) nodenum = node->children[0];
248 else nodenum = node->children[1];
249 } //end while
250 if (!nodenum)
251 {
252 #ifdef AAS_SAMPLE_DEBUG
253 botimport.Print(PRT_MESSAGE, "in solid\n");
254 #endif //AAS_SAMPLE_DEBUG
255 return 0;
256 } //end if
257 return -nodenum;
258 } //end of the function AAS_PointAreaNum
259 //===========================================================================
260 //
261 // Parameter: -
262 // Returns: -
263 // Changes Globals: -
264 //===========================================================================
265 int AAS_PointReachabilityAreaIndex( vec3_t origin )
266 {
267 int areanum, cluster, i, index;
268
269 if (!aasworld.initialized)
270 return 0;
271
272 if ( !origin )
273 {
274 index = 0;
275 for (i = 0; i < aasworld.numclusters; i++)
276 {
277 index += aasworld.clusters[i].numreachabilityareas;
278 } //end for
279 return index;
280 } //end if
281
282 areanum = AAS_PointAreaNum( origin );
283 if ( !areanum || !AAS_AreaReachability(areanum) )
284 return 0;
285 cluster = aasworld.areasettings[areanum].cluster;
286 areanum = aasworld.areasettings[areanum].clusterareanum;
287 if (cluster < 0)
288 {
289 cluster = aasworld.portals[-cluster].frontcluster;
290 areanum = aasworld.portals[-cluster].clusterareanum[0];
291 } //end if
292
293 index = 0;
294 for (i = 0; i < cluster; i++)
295 {
296 index += aasworld.clusters[i].numreachabilityareas;
297 } //end for
298 index += areanum;
299 return index;
300 } //end of the function AAS_PointReachabilityAreaIndex
301 //===========================================================================
302 //
303 // Parameter: -
304 // Returns: -
305 // Changes Globals: -
306 //===========================================================================
307 int AAS_AreaCluster(int areanum)
308 {
309 if (areanum <= 0 || areanum >= aasworld.numareas)
310 {
311 botimport.Print(PRT_ERROR, "AAS_AreaCluster: invalid area number\n");
312 return 0;
313 } //end if
314 return aasworld.areasettings[areanum].cluster;
315 } //end of the function AAS_AreaCluster
316 //===========================================================================
317 // returns the presence types of the given area
318 //
319 // Parameter: -
320 // Returns: -
321 // Changes Globals: -
322 //===========================================================================
323 int AAS_AreaPresenceType(int areanum)
324 {
325 if (!aasworld.loaded) return 0;
326 if (areanum <= 0 || areanum >= aasworld.numareas)
327 {
328 botimport.Print(PRT_ERROR, "AAS_AreaPresenceType: invalid area number\n");
329 return 0;
330 } //end if
331 return aasworld.areasettings[areanum].presencetype;
332 } //end of the function AAS_AreaPresenceType
333 //===========================================================================
334 // returns the presence type at the given point
335 //
336 // Parameter: -
337 // Returns: -
338 // Changes Globals: -
339 //===========================================================================
340 int AAS_PointPresenceType(vec3_t point)
341 {
342 int areanum;
343
344 if (!aasworld.loaded) return 0;
345
346 areanum = AAS_PointAreaNum(point);
347 if (!areanum) return PRESENCE_NONE;
348 return aasworld.areasettings[areanum].presencetype;
349 } //end of the function AAS_PointPresenceType
350 //===========================================================================
351 // calculates the minimum distance between the origin of the box and the
352 // given plane when both will collide on the given side of the plane
353 //
354 // normal = normal vector of plane to calculate distance from
355 // mins = minimums of box relative to origin
356 // maxs = maximums of box relative to origin
357 // side = side of the plane we want to calculate the distance from
358 // 0 normal vector side
359 // 1 not normal vector side
360 //
361 // Parameter: -
362 // Returns: -
363 // Changes Globals: -
364 //===========================================================================
365 vec_t AAS_BoxOriginDistanceFromPlane(vec3_t normal, vec3_t mins, vec3_t maxs, int side)
366 {
367 vec3_t v1, v2;
368 int i;
369
370 //swap maxs and mins when on the other side of the plane
371 if (side)
372 {
373 //get a point of the box that would be one of the first
374 //to collide with the plane
375 for (i = 0; i < 3; i++)
376 {
377 if (normal[i] > BBOX_NORMAL_EPSILON) v1[i] = maxs[i];
378 else if (normal[i] < -BBOX_NORMAL_EPSILON) v1[i] = mins[i];
379 else v1[i] = 0;
380 } //end for
381 } //end if
382 else
383 {
384 //get a point of the box that would be one of the first
385 //to collide with the plane
386 for (i = 0; i < 3; i++)
387 {
388 if (normal[i] > BBOX_NORMAL_EPSILON) v1[i] = mins[i];
389 else if (normal[i] < -BBOX_NORMAL_EPSILON) v1[i] = maxs[i];
390 else v1[i] = 0;
391 } //end for
392 } //end else
393 //
394 VectorCopy(normal, v2);
395 VectorInverse(v2);
396 // VectorNegate(normal, v2);
397 return DotProduct(v1, v2);
398 } //end of the function AAS_BoxOriginDistanceFromPlane
399 //===========================================================================
400 //
401 // Parameter: -
402 // Returns: -
403 // Changes Globals: -
404 //===========================================================================
405 qboolean AAS_AreaEntityCollision(int areanum, vec3_t start, vec3_t end,
406 int presencetype, int passent, aas_trace_t *trace)
407 {
408 int collision;
409 vec3_t boxmins, boxmaxs;
410 aas_link_t *link;
411 bsp_trace_t bsptrace;
412
413 AAS_PresenceTypeBoundingBox(presencetype, boxmins, boxmaxs);
414
415 Com_Memset(&bsptrace, 0, sizeof(bsp_trace_t)); //make compiler happy
416 //assume no collision
417 bsptrace.fraction = 1;
418 collision = qfalse;
419 for (link = aasworld.arealinkedentities[areanum]; link; link = link->next_ent)
420 {
421 //ignore the pass entity
422 if (link->entnum == passent) continue;
423 //
424 if (AAS_EntityCollision(link->entnum, start, boxmins, boxmaxs, end,
425 CONTENTS_SOLID|CONTENTS_PLAYERCLIP, &bsptrace))
426 {
427 collision = qtrue;
428 } //end if
429 } //end for
430 if (collision)
431 {
432 trace->startsolid = bsptrace.startsolid;
433 trace->ent = bsptrace.ent;
434 VectorCopy(bsptrace.endpos, trace->endpos);
435 trace->area = 0;
436 trace->planenum = 0;
437 return qtrue;
438 } //end if
439 return qfalse;
440 } //end of the function AAS_AreaEntityCollision
441 //===========================================================================
442 // recursive subdivision of the line by the BSP tree.
443 //
444 // Parameter: -
445 // Returns: -
446 // Changes Globals: -
447 //===========================================================================
448 aas_trace_t AAS_TraceClientBBox(vec3_t start, vec3_t end, int presencetype,
449 int passent)
450 {
451 int side, nodenum, tmpplanenum;
452 float front, back, frac;
453 vec3_t cur_start, cur_end, cur_mid, v1, v2;
454 aas_tracestack_t tracestack[127];
455 aas_tracestack_t *tstack_p;
456 aas_node_t *aasnode;
457 aas_plane_t *plane;
458 aas_trace_t trace;
459
460 //clear the trace structure
461 Com_Memset(&trace, 0, sizeof(aas_trace_t));
462
463 if (!aasworld.loaded) return trace;
464
465 tstack_p = tracestack;
466 //we start with the whole line on the stack
467 VectorCopy(start, tstack_p->start);
468 VectorCopy(end, tstack_p->end);
469 tstack_p->planenum = 0;
470 //start with node 1 because node zero is a dummy for a solid leaf
471 tstack_p->nodenum = 1; //starting at the root of the tree
472 tstack_p++;
473
474 while (1)
475 {
476 //pop up the stack
477 tstack_p--;
478 //if the trace stack is empty (ended up with a piece of the
479 //line to be traced in an area)
480 if (tstack_p < tracestack)
481 {
482 tstack_p++;
483 //nothing was hit
484 trace.startsolid = qfalse;
485 trace.fraction = 1.0;
486 //endpos is the end of the line
487 VectorCopy(end, trace.endpos);
488 //nothing hit
489 trace.ent = 0;
490 trace.area = 0;
491 trace.planenum = 0;
492 return trace;
493 } //end if
494 //number of the current node to test the line against
495 nodenum = tstack_p->nodenum;
496 //if it is an area
497 if (nodenum < 0)
498 {
499 #ifdef AAS_SAMPLE_DEBUG
500 if (-nodenum > aasworld.numareasettings)
501 {
502 botimport.Print(PRT_ERROR, "AAS_TraceBoundingBox: -nodenum out of range\n");
503 return trace;
504 } //end if
505 #endif //AAS_SAMPLE_DEBUG
506 //botimport.Print(PRT_MESSAGE, "areanum = %d, must be %d\n", -nodenum, AAS_PointAreaNum(start));
507 //if can't enter the area because it hasn't got the right presence type
508 if (!(aasworld.areasettings[-nodenum].presencetype & presencetype))
509 {
510 //if the start point is still the initial start point
511 //NOTE: no need for epsilons because the points will be
512 //exactly the same when they're both the start point
513 if (tstack_p->start[0] == start[0] &&
514 tstack_p->start[1] == start[1] &&
515 tstack_p->start[2] == start[2])
516 {
517 trace.startsolid = qtrue;
518 trace.fraction = 0.0;
519 VectorClear(v1);
520 } //end if
521 else
522 {
523 trace.startsolid = qfalse;
524 VectorSubtract(end, start, v1);
525 VectorSubtract(tstack_p->start, start, v2);
526 trace.fraction = VectorLength(v2) / VectorNormalize(v1);
527 VectorMA(tstack_p->start, -0.125, v1, tstack_p->start);
528 } //end else
529 VectorCopy(tstack_p->start, trace.endpos);
530 trace.ent = 0;
531 trace.area = -nodenum;
532 // VectorSubtract(end, start, v1);
533 trace.planenum = tstack_p->planenum;
534 //always take the plane with normal facing towards the trace start
535 plane = &aasworld.planes[trace.planenum];
536 if (DotProduct(v1, plane->normal) > 0) trace.planenum ^= 1;
537 return trace;
538 } //end if
539 else
540 {
541 if (passent >= 0)
542 {
543 if (AAS_AreaEntityCollision(-nodenum, tstack_p->start,
544 tstack_p->end, presencetype, passent,
545 &trace))
546 {
547 if (!trace.startsolid)
548 {
549 VectorSubtract(end, start, v1);
550 VectorSubtract(trace.endpos, start, v2);
551 trace.fraction = VectorLength(v2) / VectorLength(v1);
552 } //end if
553 return trace;
554 } //end if
555 } //end if
556 } //end else
557 trace.lastarea = -nodenum;
558 continue;
559 } //end if
560 //if it is a solid leaf
561 if (!nodenum)
562 {
563 //if the start point is still the initial start point
564 //NOTE: no need for epsilons because the points will be
565 //exactly the same when they're both the start point
566 if (tstack_p->start[0] == start[0] &&
567 tstack_p->start[1] == start[1] &&
568 tstack_p->start[2] == start[2])
569 {
570 trace.startsolid = qtrue;
571 trace.fraction = 0.0;
572 VectorClear(v1);
573 } //end if
574 else
575 {
576 trace.startsolid = qfalse;
577 VectorSubtract(end, start, v1);
578 VectorSubtract(tstack_p->start, start, v2);
579 trace.fraction = VectorLength(v2) / VectorNormalize(v1);
580 VectorMA(tstack_p->start, -0.125, v1, tstack_p->start);
581 } //end else
582 VectorCopy(tstack_p->start, trace.endpos);
583 trace.ent = 0;
584 trace.area = 0; //hit solid leaf
585 // VectorSubtract(end, start, v1);
586 trace.planenum = tstack_p->planenum;
587 //always take the plane with normal facing towards the trace start
588 plane = &aasworld.planes[trace.planenum];
589 if (DotProduct(v1, plane->normal) > 0) trace.planenum ^= 1;
590 return trace;
591 } //end if
592 #ifdef AAS_SAMPLE_DEBUG
593 if (nodenum > aasworld.numnodes)
594 {
595 botimport.Print(PRT_ERROR, "AAS_TraceBoundingBox: nodenum out of range\n");
596 return trace;
597 } //end if
598 #endif //AAS_SAMPLE_DEBUG
599 //the node to test against
600 aasnode = &aasworld.nodes[nodenum];
601 //start point of current line to test against node
602 VectorCopy(tstack_p->start, cur_start);
603 //end point of the current line to test against node
604 VectorCopy(tstack_p->end, cur_end);
605 //the current node plane
606 plane = &aasworld.planes[aasnode->planenum];
607
608 switch(plane->type)
609 {/*FIXME: wtf doesn't this work? obviously the axial node planes aren't always facing positive!!!
610 //check for axial planes
611 case PLANE_X:
612 {
613 front = cur_start[0] - plane->dist;
614 back = cur_end[0] - plane->dist;
615 break;
616 } //end case
617 case PLANE_Y:
618 {
619 front = cur_start[1] - plane->dist;
620 back = cur_end[1] - plane->dist;
621 break;
622 } //end case
623 case PLANE_Z:
624 {
625 front = cur_start[2] - plane->dist;
626 back = cur_end[2] - plane->dist;
627 break;
628 } //end case*/
629 default: //gee it's not an axial plane
630 {
631 front = DotProduct(cur_start, plane->normal) - plane->dist;
632 back = DotProduct(cur_end, plane->normal) - plane->dist;
633 break;
634 } //end default
635 } //end switch
636 // bk010221 - old location of FPE hack and divide by zero expression
637 //if the whole to be traced line is totally at the front of this node
638 //only go down the tree with the front child
639 if ((front >= -ON_EPSILON && back >= -ON_EPSILON))
640 {
641 //keep the current start and end point on the stack
642 //and go down the tree with the front child
643 tstack_p->nodenum = aasnode->children[0];
644 tstack_p++;
645 if (tstack_p >= &tracestack[127])
646 {
647 botimport.Print(PRT_ERROR, "AAS_TraceBoundingBox: stack overflow\n");
648 return trace;
649 } //end if
650 } //end if
651 //if the whole to be traced line is totally at the back of this node
652 //only go down the tree with the back child
653 else if ((front < ON_EPSILON && back < ON_EPSILON))
654 {
655 //keep the current start and end point on the stack
656 //and go down the tree with the back child
657 tstack_p->nodenum = aasnode->children[1];
658 tstack_p++;
659 if (tstack_p >= &tracestack[127])
660 {
661 botimport.Print(PRT_ERROR, "AAS_TraceBoundingBox: stack overflow\n");
662 return trace;
663 } //end if
664 } //end if
665 //go down the tree both at the front and back of the node
666 else
667 {
668 tmpplanenum = tstack_p->planenum;
669 // bk010221 - new location of divide by zero (see above)
670 if ( front == back ) front -= 0.001f; // bk0101022 - hack/FPE
671 //calculate the hitpoint with the node (split point of the line)
672 //put the crosspoint TRACEPLANE_EPSILON pixels on the near side
673 if (front < 0) frac = (front + TRACEPLANE_EPSILON)/(front-back);
674 else frac = (front - TRACEPLANE_EPSILON)/(front-back); // bk010221
675 //
676 if (frac < 0)
677 frac = 0.001f; //0
678 else if (frac > 1)
679 frac = 0.999f; //1
680 //frac = front / (front-back);
681 //
682 cur_mid[0] = cur_start[0] + (cur_end[0] - cur_start[0]) * frac;
683 cur_mid[1] = cur_start[1] + (cur_end[1] - cur_start[1]) * frac;
684 cur_mid[2] = cur_start[2] + (cur_end[2] - cur_start[2]) * frac;
685
686 // AAS_DrawPlaneCross(cur_mid, plane->normal, plane->dist, plane->type, LINECOLOR_RED);
687 //side the front part of the line is on
688 side = front < 0;
689 //first put the end part of the line on the stack (back side)
690 VectorCopy(cur_mid, tstack_p->start);
691 //not necessary to store because still on stack
692 //VectorCopy(cur_end, tstack_p->end);
693 tstack_p->planenum = aasnode->planenum;
694 tstack_p->nodenum = aasnode->children[!side];
695 tstack_p++;
696 if (tstack_p >= &tracestack[127])
697 {
698 botimport.Print(PRT_ERROR, "AAS_TraceBoundingBox: stack overflow\n");
699 return trace;
700 } //end if
701 //now put the part near the start of the line on the stack so we will
702 //continue with thats part first. This way we'll find the first
703 //hit of the bbox
704 VectorCopy(cur_start, tstack_p->start);
705 VectorCopy(cur_mid, tstack_p->end);
706 tstack_p->planenum = tmpplanenum;
707 tstack_p->nodenum = aasnode->children[side];
708 tstack_p++;
709 if (tstack_p >= &tracestack[127])
710 {
711 botimport.Print(PRT_ERROR, "AAS_TraceBoundingBox: stack overflow\n");
712 return trace;
713 } //end if
714 } //end else
715 } //end while
716 // return trace;
717 } //end of the function AAS_TraceClientBBox
718 //===========================================================================
719 // recursive subdivision of the line by the BSP tree.
720 //
721 // Parameter: -
722 // Returns: -
723 // Changes Globals: -
724 //===========================================================================
725 int AAS_TraceAreas(vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas)
726 {
727 int side, nodenum, tmpplanenum;
728 int numareas;
729 float front, back, frac;
730 vec3_t cur_start, cur_end, cur_mid;
731 aas_tracestack_t tracestack[127];
732 aas_tracestack_t *tstack_p;
733 aas_node_t *aasnode;
734 aas_plane_t *plane;
735
736 numareas = 0;
737 areas[0] = 0;
738 if (!aasworld.loaded) return numareas;
739
740 tstack_p = tracestack;
741 //we start with the whole line on the stack
742 VectorCopy(start, tstack_p->start);
743 VectorCopy(end, tstack_p->end);
744 tstack_p->planenum = 0;
745 //start with node 1 because node zero is a dummy for a solid leaf
746 tstack_p->nodenum = 1; //starting at the root of the tree
747 tstack_p++;
748
749 while (1)
750 {
751 //pop up the stack
752 tstack_p--;
753 //if the trace stack is empty (ended up with a piece of the
754 //line to be traced in an area)
755 if (tstack_p < tracestack)
756 {
757 return numareas;
758 } //end if
759 //number of the current node to test the line against
760 nodenum = tstack_p->nodenum;
761 //if it is an area
762 if (nodenum < 0)
763 {
764 #ifdef AAS_SAMPLE_DEBUG
765 if (-nodenum > aasworld.numareasettings)
766 {
767 botimport.Print(PRT_ERROR, "AAS_TraceAreas: -nodenum = %d out of range\n", -nodenum);
768 return numareas;
769 } //end if
770 #endif //AAS_SAMPLE_DEBUG
771 //botimport.Print(PRT_MESSAGE, "areanum = %d, must be %d\n", -nodenum, AAS_PointAreaNum(start));
772 areas[numareas] = -nodenum;
773 if (points) VectorCopy(tstack_p->start, points[numareas]);
774 numareas++;
775 if (numareas >= maxareas) return numareas;
776 continue;
777 } //end if
778 //if it is a solid leaf
779 if (!nodenum)
780 {
781 continue;
782 } //end if
783 #ifdef AAS_SAMPLE_DEBUG
784 if (nodenum > aasworld.numnodes)
785 {
786 botimport.Print(PRT_ERROR, "AAS_TraceAreas: nodenum out of range\n");
787 return numareas;
788 } //end if
789 #endif //AAS_SAMPLE_DEBUG
790 //the node to test against
791 aasnode = &aasworld.nodes[nodenum];
792 //start point of current line to test against node
793 VectorCopy(tstack_p->start, cur_start);
794 //end point of the current line to test against node
795 VectorCopy(tstack_p->end, cur_end);
796 //the current node plane
797 plane = &aasworld.planes[aasnode->planenum];
798
799 switch(plane->type)
800 {/*FIXME: wtf doesn't this work? obviously the node planes aren't always facing positive!!!
801 //check for axial planes
802 case PLANE_X:
803 {
804 front = cur_start[0] - plane->dist;
805 back = cur_end[0] - plane->dist;
806 break;
807 } //end case
808 case PLANE_Y:
809 {
810 front = cur_start[1] - plane->dist;
811 back = cur_end[1] - plane->dist;
812 break;
813 } //end case
814 case PLANE_Z:
815 {
816 front = cur_start[2] - plane->dist;
817 back = cur_end[2] - plane->dist;
818 break;
819 } //end case*/
820 default: //gee it's not an axial plane
821 {
822 front = DotProduct(cur_start, plane->normal) - plane->dist;
823 back = DotProduct(cur_end, plane->normal) - plane->dist;
824 break;
825 } //end default
826 } //end switch
827
828 //if the whole to be traced line is totally at the front of this node
829 //only go down the tree with the front child
830 if (front > 0 && back > 0)
831 {
832 //keep the current start and end point on the stack
833 //and go down the tree with the front child
834 tstack_p->nodenum = aasnode->children[0];
835 tstack_p++;
836 if (tstack_p >= &tracestack[127])
837 {
838 botimport.Print(PRT_ERROR, "AAS_TraceAreas: stack overflow\n");
839 return numareas;
840 } //end if
841 } //end if
842 //if the whole to be traced line is totally at the back of this node
843 //only go down the tree with the back child
844 else if (front <= 0 && back <= 0)
845 {
846 //keep the current start and end point on the stack
847 //and go down the tree with the back child
848 tstack_p->nodenum = aasnode->children[1];
849 tstack_p++;
850 if (tstack_p >= &tracestack[127])
851 {
852 botimport.Print(PRT_ERROR, "AAS_TraceAreas: stack overflow\n");
853 return numareas;
854 } //end if
855 } //end if
856 //go down the tree both at the front and back of the node
857 else
858 {
859 tmpplanenum = tstack_p->planenum;
860 //calculate the hitpoint with the node (split point of the line)
861 //put the crosspoint TRACEPLANE_EPSILON pixels on the near side
862 if (front < 0) frac = (front)/(front-back);
863 else frac = (front)/(front-back);
864 if (frac < 0) frac = 0;
865 else if (frac > 1) frac = 1;
866 //frac = front / (front-back);
867 //
868 cur_mid[0] = cur_start[0] + (cur_end[0] - cur_start[0]) * frac;
869 cur_mid[1] = cur_start[1] + (cur_end[1] - cur_start[1]) * frac;
870 cur_mid[2] = cur_start[2] + (cur_end[2] - cur_start[2]) * frac;
871
872 // AAS_DrawPlaneCross(cur_mid, plane->normal, plane->dist, plane->type, LINECOLOR_RED);
873 //side the front part of the line is on
874 side = front < 0;
875 //first put the end part of the line on the stack (back side)
876 VectorCopy(cur_mid, tstack_p->start);
877 //not necessary to store because still on stack
878 //VectorCopy(cur_end, tstack_p->end);
879 tstack_p->planenum = aasnode->planenum;
880 tstack_p->nodenum = aasnode->children[!side];
881 tstack_p++;
882 if (tstack_p >= &tracestack[127])
883 {
884 botimport.Print(PRT_ERROR, "AAS_TraceAreas: stack overflow\n");
885 return numareas;
886 } //end if
887 //now put the part near the start of the line on the stack so we will
888 //continue with thats part first. This way we'll find the first
889 //hit of the bbox
890 VectorCopy(cur_start, tstack_p->start);
891 VectorCopy(cur_mid, tstack_p->end);
892 tstack_p->planenum = tmpplanenum;
893 tstack_p->nodenum = aasnode->children[side];
894 tstack_p++;
895 if (tstack_p >= &tracestack[127])
896 {
897 botimport.Print(PRT_ERROR, "AAS_TraceAreas: stack overflow\n");
898 return numareas;
899 } //end if
900 } //end else
901 } //end while
902 // return numareas;
903 } //end of the function AAS_TraceAreas
904 //===========================================================================
905 // a simple cross product
906 //
907 // Parameter: -
908 // Returns: -
909 // Changes Globals: -
910 //===========================================================================
911 // void AAS_OrthogonalToVectors(vec3_t v1, vec3_t v2, vec3_t res)
912 #define AAS_OrthogonalToVectors(v1, v2, res) \
913 (res)[0] = ((v1)[1] * (v2)[2]) - ((v1)[2] * (v2)[1]);\
914 (res)[1] = ((v1)[2] * (v2)[0]) - ((v1)[0] * (v2)[2]);\
915 (res)[2] = ((v1)[0] * (v2)[1]) - ((v1)[1] * (v2)[0]);
916 //===========================================================================
917 // tests if the given point is within the face boundaries
918 //
919 // Parameter: face : face to test if the point is in it
920 // pnormal : normal of the plane to use for the face
921 // point : point to test if inside face boundaries
922 // Returns: qtrue if the point is within the face boundaries
923 // Changes Globals: -
924 //===========================================================================
925 qboolean AAS_InsideFace(aas_face_t *face, vec3_t pnormal, vec3_t point, float epsilon)
926 {
927 int i, firstvertex, edgenum;
928 vec3_t v0;
929 vec3_t edgevec, pointvec, sepnormal;
930 aas_edge_t *edge;
931 #ifdef AAS_SAMPLE_DEBUG
932 int lastvertex = 0;
933 #endif //AAS_SAMPLE_DEBUG
934
935 if (!aasworld.loaded) return qfalse;
936
937 for (i = 0; i < face->numedges; i++)
938 {
939 edgenum = aasworld.edgeindex[face->firstedge + i];
940 edge = &aasworld.edges[abs(edgenum)];
941 //get the first vertex of the edge
942 firstvertex = edgenum < 0;
943 VectorCopy(aasworld.vertexes[edge->v[firstvertex]], v0);
944 //edge vector
945 VectorSubtract(aasworld.vertexes[edge->v[!firstvertex]], v0, edgevec);
946 //
947 #ifdef AAS_SAMPLE_DEBUG
948 if (lastvertex && lastvertex != edge->v[firstvertex])
949 {
950 botimport.Print(PRT_MESSAGE, "winding not counter clockwise\n");
951 } //end if
952 lastvertex = edge->v[!firstvertex];
953 #endif //AAS_SAMPLE_DEBUG
954 //vector from first edge point to point possible in face
955 VectorSubtract(point, v0, pointvec);
956 //get a vector pointing inside the face orthogonal to both the
957 //edge vector and the normal vector of the plane the face is in
958 //this vector defines a plane through the origin (first vertex of
959 //edge) and through both the edge vector and the normal vector
960 //of the plane
961 AAS_OrthogonalToVectors(edgevec, pnormal, sepnormal);
962 //check on which side of the above plane the point is
963 //this is done by checking the sign of the dot product of the
964 //vector orthogonal vector from above and the vector from the
965 //origin (first vertex of edge) to the point
966 //if the dotproduct is smaller than zero the point is outside the face
967 if (DotProduct(pointvec, sepnormal) < -epsilon) return qfalse;
968 } //end for
969 return qtrue;
970 } //end of the function AAS_InsideFace
971 //===========================================================================
972 //
973 // Parameter: -
974 // Returns: -
975 // Changes Globals: -
976 //===========================================================================
977 qboolean AAS_PointInsideFace(int facenum, vec3_t point, float epsilon)
978 {
979 int i, firstvertex, edgenum;
980 vec_t *v1, *v2;
981 vec3_t edgevec, pointvec, sepnormal;
982 aas_edge_t *edge;
983 aas_plane_t *plane;
984 aas_face_t *face;
985
986 if (!aasworld.loaded) return qfalse;
987
988 face = &aasworld.faces[facenum];
989 plane = &aasworld.planes[face->planenum];
990 //
991 for (i = 0; i < face->numedges; i++)
992 {
993 edgenum = aasworld.edgeindex[face->firstedge + i];
994 edge = &aasworld.edges[abs(edgenum)];
995 //get the first vertex of the edge
996 firstvertex = edgenum < 0;
997 v1 = aasworld.vertexes[edge->v[firstvertex]];
998 v2 = aasworld.vertexes[edge->v[!firstvertex]];
999 //edge vector
1000 VectorSubtract(v2, v1, edgevec);
1001 //vector from first edge point to point possible in face
1002 VectorSubtract(point, v1, pointvec);
1003 //
1004 CrossProduct(edgevec, plane->normal, sepnormal);
1005 //
1006 if (DotProduct(pointvec, sepnormal) < -epsilon) return qfalse;
1007 } //end for
1008 return qtrue;
1009 } //end of the function AAS_PointInsideFace
1010 //===========================================================================
1011 // returns the ground face the given point is above in the given area
1012 //
1013 // Parameter: -
1014 // Returns: -
1015 // Changes Globals: -
1016 //===========================================================================
1017 aas_face_t *AAS_AreaGroundFace(int areanum, vec3_t point)
1018 {
1019 int i, facenum;
1020 vec3_t up = {0, 0, 1};
1021 vec3_t normal;
1022 aas_area_t *area;
1023 aas_face_t *face;
1024
1025 if (!aasworld.loaded) return NULL;
1026
1027 area = &aasworld.areas[areanum];
1028 for (i = 0; i < area->numfaces; i++)
1029 {
1030 facenum = aasworld.faceindex[area->firstface + i];
1031 face = &aasworld.faces[abs(facenum)];
1032 //if this is a ground face
1033 if (face->faceflags & FACE_GROUND)
1034 {
1035 //get the up or down normal
1036 if (aasworld.planes[face->planenum].normal[2] < 0) VectorNegate(up, normal);
1037 else VectorCopy(up, normal);
1038 //check if the point is in the face
1039 if (AAS_InsideFace(face, normal, point, 0.01f)) return face;
1040 } //end if
1041 } //end for
1042 return NULL;
1043 } //end of the function AAS_AreaGroundFace
1044 //===========================================================================
1045 // returns the face the trace end position is situated in
1046 //
1047 // Parameter: -
1048 // Returns: -
1049 // Changes Globals: -
1050 //===========================================================================
1051 void AAS_FacePlane(int facenum, vec3_t normal, float *dist)
1052 {
1053 aas_plane_t *plane;
1054
1055 plane = &aasworld.planes[aasworld.faces[facenum].planenum];
1056 VectorCopy(plane->normal, normal);
1057 *dist = plane->dist;
1058 } //end of the function AAS_FacePlane
1059 //===========================================================================
1060 // returns the face the trace end position is situated in
1061 //
1062 // Parameter: -
1063 // Returns: -
1064 // Changes Globals: -
1065 //===========================================================================
1066 aas_face_t *AAS_TraceEndFace(aas_trace_t *trace)
1067 {
1068 int i, facenum;
1069 aas_area_t *area;
1070 aas_face_t *face, *firstface = NULL;
1071
1072 if (!aasworld.loaded) return NULL;
1073
1074 //if started in solid no face was hit
1075 if (trace->startsolid) return NULL;
1076 //trace->lastarea is the last area the trace was in
1077 area = &aasworld.areas[trace->lastarea];
1078 //check which face the trace.endpos was in
1079 for (i = 0; i < area->numfaces; i++)
1080 {
1081 facenum = aasworld.faceindex[area->firstface + i];
1082 face = &aasworld.faces[abs(facenum)];
1083 //if the face is in the same plane as the trace end point
1084 if ((face->planenum & ~1) == (trace->planenum & ~1))
1085 {
1086 //firstface is used for optimization, if theres only one
1087 //face in the plane then it has to be the good one
1088 //if there are more faces in the same plane then always
1089 //check the one with the fewest edges first
1090 /* if (firstface)
1091 {
1092 if (firstface->numedges < face->numedges)
1093 {
1094 if (AAS_InsideFace(firstface,
1095 aasworld.planes[face->planenum].normal, trace->endpos))
1096 {
1097 return firstface;
1098 } //end if
1099 firstface = face;
1100 } //end if
1101 else
1102 {
1103 if (AAS_InsideFace(face,
1104 aasworld.planes[face->planenum].normal, trace->endpos))
1105 {
1106 return face;
1107 } //end if
1108 } //end else
1109 } //end if
1110 else
1111 {
1112 firstface = face;
1113 } //end else*/
1114 if (AAS_InsideFace(face,
1115 aasworld.planes[face->planenum].normal, trace->endpos, 0.01f)) return face;
1116 } //end if
1117 } //end for
1118 return firstface;
1119 } //end of the function AAS_TraceEndFace
1120 //===========================================================================
1121 //
1122 // Parameter: -
1123 // Returns: -
1124 // Changes Globals: -
1125 //===========================================================================
1126 int AAS_BoxOnPlaneSide2(vec3_t absmins, vec3_t absmaxs, aas_plane_t *p)
1127 {
1128 int i, sides;
1129 float dist1, dist2;
1130 vec3_t corners[2];
1131
1132 for (i = 0; i < 3; i++)
1133 {
1134 if (p->normal[i] < 0)
1135 {
1136 corners[0][i] = absmins[i];
1137 corners[1][i] = absmaxs[i];
1138 } //end if
1139 else
1140 {
1141 corners[1][i] = absmins[i];
1142 corners[0][i] = absmaxs[i];
1143 } //end else
1144 } //end for
1145 dist1 = DotProduct(p->normal, corners[0]) - p->dist;
1146 dist2 = DotProduct(p->normal, corners[1]) - p->dist;
1147 sides = 0;
1148 if (dist1 >= 0) sides = 1;
1149 if (dist2 < 0) sides |= 2;
1150
1151 return sides;
1152 } //end of the function AAS_BoxOnPlaneSide2
1153 //===========================================================================
1154 //
1155 // Parameter: -
1156 // Returns: -
1157 // Changes Globals: -
1158 //===========================================================================
1159 //int AAS_BoxOnPlaneSide(vec3_t absmins, vec3_t absmaxs, aas_plane_t *p)
1160 #define AAS_BoxOnPlaneSide(absmins, absmaxs, p) (\
1161 ( (p)->type < 3) ?\
1162 (\
1163 ( (p)->dist <= (absmins)[(p)->type]) ?\
1164 (\
1165 1\
1166 )\
1167 :\
1168 (\
1169 ( (p)->dist >= (absmaxs)[(p)->type]) ?\
1170 (\
1171 2\
1172 )\
1173 :\
1174 (\
1175 3\
1176 )\
1177 )\
1178 )\
1179 :\
1180 (\
1181 AAS_BoxOnPlaneSide2((absmins), (absmaxs), (p))\
1182 )\
1183 ) //end of the function AAS_BoxOnPlaneSide
1184 //===========================================================================
1185 // remove the links to this entity from all areas
1186 //
1187 // Parameter: -
1188 // Returns: -
1189 // Changes Globals: -
1190 //===========================================================================
1191 void AAS_UnlinkFromAreas(aas_link_t *areas)
1192 {
1193 aas_link_t *link, *nextlink;
1194
1195 for (link = areas; link; link = nextlink)
1196 {
1197 //next area the entity is linked in
1198 nextlink = link->next_area;
1199 //remove the entity from the linked list of this area
1200 if (link->prev_ent) link->prev_ent->next_ent = link->next_ent;
1201 else aasworld.arealinkedentities[link->areanum] = link->next_ent;
1202 if (link->next_ent) link->next_ent->prev_ent = link->prev_ent;
1203 //deallocate the link structure
1204 AAS_DeAllocAASLink(link);
1205 } //end for
1206 } //end of the function AAS_UnlinkFromAreas
1207 //===========================================================================
1208 // link the entity to the areas the bounding box is totally or partly
1209 // situated in. This is done with recursion down the tree using the
1210 // bounding box to test for plane sides
1211 //
1212 // Parameter: -
1213 // Returns: -
1214 // Changes Globals: -
1215 //===========================================================================
1216
1217 typedef struct
1218 {
1219 int nodenum; //node found after splitting
1220 } aas_linkstack_t;
1221
1222 aas_link_t *AAS_AASLinkEntity(vec3_t absmins, vec3_t absmaxs, int entnum)
1223 {
1224 int side, nodenum;
1225 aas_linkstack_t linkstack[128];
1226 aas_linkstack_t *lstack_p;
1227 aas_node_t *aasnode;
1228 aas_plane_t *plane;
1229 aas_link_t *link, *areas;
1230
1231 if (!aasworld.loaded)
1232 {
1233 botimport.Print(PRT_ERROR, "AAS_LinkEntity: aas not loaded\n");
1234 return NULL;
1235 } //end if
1236
1237 areas = NULL;
1238 //
1239 lstack_p = linkstack;
1240 //we start with the whole line on the stack
1241 //start with node 1 because node zero is a dummy used for solid leafs
1242 lstack_p->nodenum = 1; //starting at the root of the tree
1243 lstack_p++;
1244
1245 while (1)
1246 {
1247 //pop up the stack
1248 lstack_p--;
1249 //if the trace stack is empty (ended up with a piece of the
1250 //line to be traced in an area)
1251 if (lstack_p < linkstack) break;
1252 //number of the current node to test the line against
1253 nodenum = lstack_p->nodenum;
1254 //if it is an area
1255 if (nodenum < 0)
1256 {
1257 //NOTE: the entity might have already been linked into this area
1258 // because several node children can point to the same area
1259 for (link = aasworld.arealinkedentities[-nodenum]; link; link = link->next_ent)
1260 {
1261 if (link->entnum == entnum) break;
1262 } //end for
1263 if (link) continue;
1264 //
1265 link = AAS_AllocAASLink();
1266 if (!link) return areas;
1267 link->entnum = entnum;
1268 link->areanum = -nodenum;
1269 //put the link into the double linked area list of the entity
1270 link->prev_area = NULL;
1271 link->next_area = areas;
1272 if (areas) areas->prev_area = link;
1273 areas = link;
1274 //put the link into the double linked entity list of the area
1275 link->prev_ent = NULL;
1276 link->next_ent = aasworld.arealinkedentities[-nodenum];
1277 if (aasworld.arealinkedentities[-nodenum])
1278 aasworld.arealinkedentities[-nodenum]->prev_ent = link;
1279 aasworld.arealinkedentities[-nodenum] = link;
1280 //
1281 continue;
1282 } //end if
1283 //if solid leaf
1284 if (!nodenum) continue;
1285 //the node to test against
1286 aasnode = &aasworld.nodes[nodenum];
1287 //the current node plane
1288 plane = &aasworld.planes[aasnode->planenum];
1289 //get the side(s) the box is situated relative to the plane
1290 side = AAS_BoxOnPlaneSide2(absmins, absmaxs, plane);
1291 //if on the front side of the node
1292 if (side & 1)
1293 {
1294 lstack_p->nodenum = aasnode->children[0];
1295 lstack_p++;
1296 } //end if
1297 if (lstack_p >= &linkstack[127])
1298 {
1299 botimport.Print(PRT_ERROR, "AAS_LinkEntity: stack overflow\n");
1300 break;
1301 } //end if
1302 //if on the back side of the node
1303 if (side & 2)
1304 {
1305 lstack_p->nodenum = aasnode->children[1];
1306 lstack_p++;
1307 } //end if
1308 if (lstack_p >= &linkstack[127])
1309 {
1310 botimport.Print(PRT_ERROR, "AAS_LinkEntity: stack overflow\n");
1311 break;
1312 } //end if
1313 } //end while
1314 return areas;
1315 } //end of the function AAS_AASLinkEntity
1316 //===========================================================================
1317 //
1318 // Parameter: -
1319 // Returns: -
1320 // Changes Globals: -
1321 //===========================================================================
1322 aas_link_t *AAS_LinkEntityClientBBox(vec3_t absmins, vec3_t absmaxs, int entnum, int presencetype)
1323 {
1324 vec3_t mins, maxs;
1325 vec3_t newabsmins, newabsmaxs;
1326
1327 AAS_PresenceTypeBoundingBox(presencetype, mins, maxs);
1328 VectorSubtract(absmins, maxs, newabsmins);
1329 VectorSubtract(absmaxs, mins, newabsmaxs);
1330 //relink the entity
1331 return AAS_AASLinkEntity(newabsmins, newabsmaxs, entnum);
1332 } //end of the function AAS_LinkEntityClientBBox
1333 //===========================================================================
1334 //
1335 // Parameter: -
1336 // Returns: -
1337 // Changes Globals: -
1338 //===========================================================================
1339 int AAS_BBoxAreas(vec3_t absmins, vec3_t absmaxs, int *areas, int maxareas)
1340 {
1341 aas_link_t *linkedareas, *link;
1342 int num;
1343
1344 linkedareas = AAS_AASLinkEntity(absmins, absmaxs, -1);
1345 num = 0;
1346 for (link = linkedareas; link; link = link->next_area)
1347 {
1348 areas[num] = link->areanum;
1349 num++;
1350 if (num >= maxareas)
1351 break;
1352 } //end for
1353 AAS_UnlinkFromAreas(linkedareas);
1354 return num;
1355 } //end of the function AAS_BBoxAreas
1356 //===========================================================================
1357 //
1358 // Parameter: -
1359 // Returns: -
1360 // Changes Globals: -
1361 //===========================================================================
1362 int AAS_AreaInfo( int areanum, aas_areainfo_t *info )
1363 {
1364 aas_areasettings_t *settings;
1365 if (!info)
1366 return 0;
1367 if (areanum <= 0 || areanum >= aasworld.numareas)
1368 {
1369 botimport.Print(PRT_ERROR, "AAS_AreaInfo: areanum %d out of range\n", areanum);
1370 return 0;
1371 } //end if
1372 settings = &aasworld.areasettings[areanum];
1373 info->cluster = settings->cluster;
1374 info->contents = settings->contents;
1375 info->flags = settings->areaflags;
1376 info->presencetype = settings->presencetype;
1377 VectorCopy(aasworld.areas[areanum].mins, info->mins);
1378 VectorCopy(aasworld.areas[areanum].maxs, info->maxs);
1379 VectorCopy(aasworld.areas[areanum].center, info->center);
1380 return sizeof(aas_areainfo_t);
1381 } //end of the function AAS_AreaInfo
1382 //===========================================================================
1383 //
1384 // Parameter: -
1385 // Returns: -
1386 // Changes Globals: -
1387 //===========================================================================
1388 aas_plane_t *AAS_PlaneFromNum(int planenum)
1389 {
1390 if (!aasworld.loaded) return NULL;
1391
1392 return &aasworld.planes[planenum];
1393 } //end of the function AAS_PlaneFromNum