| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 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; |
| 59 |
vec3_t end; |
| 60 |
int planenum; |
| 61 |
int nodenum; |
| 62 |
} aas_tracestack_t; |
| 63 |
|
| 64 |
int numaaslinks; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
void AAS_PresenceTypeBoundingBox(int presencetype, vec3_t mins, vec3_t maxs) |
| 73 |
{ |
| 74 |
int index; |
| 75 |
|
| 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 |
} |
| 86 |
VectorCopy(boxmins[index], mins); |
| 87 |
VectorCopy(boxmaxs[index], maxs); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
void AAS_InitAASLinkHeap(void) |
| 96 |
{ |
| 97 |
int i, max_aaslinks; |
| 98 |
|
| 99 |
max_aaslinks = aasworld.linkheapsize; |
| 100 |
|
| 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 |
} |
| 112 |
|
| 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 |
} |
| 120 |
aasworld.linkheap[max_aaslinks-1].prev_ent = &aasworld.linkheap[max_aaslinks-2]; |
| 121 |
aasworld.linkheap[max_aaslinks-1].next_ent = NULL; |
| 122 |
|
| 123 |
aasworld.freelinks = &aasworld.linkheap[0]; |
| 124 |
|
| 125 |
numaaslinks = max_aaslinks; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
void AAS_FreeAASLinkHeap(void) |
| 134 |
{ |
| 135 |
if (aasworld.linkheap) FreeMemory(aasworld.linkheap); |
| 136 |
aasworld.linkheap = NULL; |
| 137 |
aasworld.linkheapsize = 0; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 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 |
} |
| 158 |
return NULL; |
| 159 |
} |
| 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 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 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 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 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 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
void AAS_FreeAASLinkedEntities(void) |
| 201 |
{ |
| 202 |
if (aasworld.arealinkedentities) FreeMemory(aasworld.arealinkedentities); |
| 203 |
aasworld.arealinkedentities = NULL; |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 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 |
} |
| 224 |
|
| 225 |
|
| 226 |
nodenum = 1; |
| 227 |
while (nodenum > 0) |
| 228 |
{ |
| 229 |
|
| 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 |
} |
| 236 |
#endif |
| 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 |
} |
| 244 |
#endif |
| 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 |
} |
| 250 |
if (!nodenum) |
| 251 |
{ |
| 252 |
#ifdef AAS_SAMPLE_DEBUG |
| 253 |
botimport.Print(PRT_MESSAGE, "in solid\n"); |
| 254 |
#endif |
| 255 |
return 0; |
| 256 |
} |
| 257 |
return -nodenum; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 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 |
} |
| 279 |
return index; |
| 280 |
} |
| 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 |
} |
| 292 |
|
| 293 |
index = 0; |
| 294 |
for (i = 0; i < cluster; i++) |
| 295 |
{ |
| 296 |
index += aasworld.clusters[i].numreachabilityareas; |
| 297 |
} |
| 298 |
index += areanum; |
| 299 |
return index; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 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 |
} |
| 314 |
return aasworld.areasettings[areanum].cluster; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 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 |
} |
| 331 |
return aasworld.areasettings[areanum].presencetype; |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 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 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 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 |
|
| 371 |
if (side) |
| 372 |
{ |
| 373 |
|
| 374 |
|
| 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 |
} |
| 381 |
} |
| 382 |
else |
| 383 |
{ |
| 384 |
|
| 385 |
|
| 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 |
} |
| 392 |
} |
| 393 |
|
| 394 |
VectorCopy(normal, v2); |
| 395 |
VectorInverse(v2); |
| 396 |
|
| 397 |
return DotProduct(v1, v2); |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 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)); |
| 416 |
|
| 417 |
bsptrace.fraction = 1; |
| 418 |
collision = qfalse; |
| 419 |
for (link = aasworld.arealinkedentities[areanum]; link; link = link->next_ent) |
| 420 |
{ |
| 421 |
|
| 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 |
} |
| 429 |
} |
| 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 |
} |
| 439 |
return qfalse; |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 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 |
|
| 461 |
Com_Memset(&trace, 0, sizeof(aas_trace_t)); |
| 462 |
|
| 463 |
if (!aasworld.loaded) return trace; |
| 464 |
|
| 465 |
tstack_p = tracestack; |
| 466 |
|
| 467 |
VectorCopy(start, tstack_p->start); |
| 468 |
VectorCopy(end, tstack_p->end); |
| 469 |
tstack_p->planenum = 0; |
| 470 |
|
| 471 |
tstack_p->nodenum = 1; |
| 472 |
tstack_p++; |
| 473 |
|
| 474 |
while (1) |
| 475 |
{ |
| 476 |
|
| 477 |
tstack_p--; |
| 478 |
|
| 479 |
|
| 480 |
if (tstack_p < tracestack) |
| 481 |
{ |
| 482 |
tstack_p++; |
| 483 |
|
| 484 |
trace.startsolid = qfalse; |
| 485 |
trace.fraction = 1.0; |
| 486 |
|
| 487 |
VectorCopy(end, trace.endpos); |
| 488 |
|
| 489 |
trace.ent = 0; |
| 490 |
trace.area = 0; |
| 491 |
trace.planenum = 0; |
| 492 |
return trace; |
| 493 |
} |
| 494 |
|
| 495 |
nodenum = tstack_p->nodenum; |
| 496 |
|
| 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 |
} |
| 505 |
#endif |
| 506 |
|
| 507 |
|
| 508 |
if (!(aasworld.areasettings[-nodenum].presencetype & presencetype)) |
| 509 |
{ |
| 510 |
|
| 511 |
|
| 512 |
|
| 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 |
} |
| 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 |
} |
| 529 |
VectorCopy(tstack_p->start, trace.endpos); |
| 530 |
trace.ent = 0; |
| 531 |
trace.area = -nodenum; |
| 532 |
|
| 533 |
trace.planenum = tstack_p->planenum; |
| 534 |
|
| 535 |
plane = &aasworld.planes[trace.planenum]; |
| 536 |
if (DotProduct(v1, plane->normal) > 0) trace.planenum ^= 1; |
| 537 |
return trace; |
| 538 |
} |
| 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 |
} |
| 553 |
return trace; |
| 554 |
} |
| 555 |
} |
| 556 |
} |
| 557 |
trace.lastarea = -nodenum; |
| 558 |
continue; |
| 559 |
} |
| 560 |
|
| 561 |
if (!nodenum) |
| 562 |
{ |
| 563 |
|
| 564 |
|
| 565 |
|
| 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 |
} |
| 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 |
} |
| 582 |
VectorCopy(tstack_p->start, trace.endpos); |
| 583 |
trace.ent = 0; |
| 584 |
trace.area = 0; |
| 585 |
|
| 586 |
trace.planenum = tstack_p->planenum; |
| 587 |
|
| 588 |
plane = &aasworld.planes[trace.planenum]; |
| 589 |
if (DotProduct(v1, plane->normal) > 0) trace.planenum ^= 1; |
| 590 |
return trace; |
| 591 |
} |
| 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 |
} |
| 598 |
#endif |
| 599 |
|
| 600 |
aasnode = &aasworld.nodes[nodenum]; |
| 601 |
|
| 602 |
VectorCopy(tstack_p->start, cur_start); |
| 603 |
|
| 604 |
VectorCopy(tstack_p->end, cur_end); |
| 605 |
|
| 606 |
plane = &aasworld.planes[aasnode->planenum]; |
| 607 |
|
| 608 |
switch(plane->type) |
| 609 |
{ |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
default: |
| 630 |
{ |
| 631 |
front = DotProduct(cur_start, plane->normal) - plane->dist; |
| 632 |
back = DotProduct(cur_end, plane->normal) - plane->dist; |
| 633 |
break; |
| 634 |
} |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
if ((front >= -ON_EPSILON && back >= -ON_EPSILON)) |
| 640 |
{ |
| 641 |
|
| 642 |
|
| 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 |
} |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
else if ((front < ON_EPSILON && back < ON_EPSILON)) |
| 654 |
{ |
| 655 |
|
| 656 |
|
| 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 |
} |
| 664 |
} |
| 665 |
|
| 666 |
else |
| 667 |
{ |
| 668 |
tmpplanenum = tstack_p->planenum; |
| 669 |
|
| 670 |
if ( front == back ) front -= 0.001f; |
| 671 |
|
| 672 |
|
| 673 |
if (front < 0) frac = (front + TRACEPLANE_EPSILON)/(front-back); |
| 674 |
else frac = (front - TRACEPLANE_EPSILON)/(front-back); |
| 675 |
|
| 676 |
if (frac < 0) |
| 677 |
frac = 0.001f; |
| 678 |
else if (frac > 1) |
| 679 |
frac = 0.999f; |
| 680 |
|
| 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 |
|
| 687 |
|
| 688 |
side = front < 0; |
| 689 |
|
| 690 |
VectorCopy(cur_mid, tstack_p->start); |
| 691 |
|
| 692 |
|
| 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 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 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 |
} |
| 714 |
} |
| 715 |
} |
| 716 |
|
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 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 |
|
| 742 |
VectorCopy(start, tstack_p->start); |
| 743 |
VectorCopy(end, tstack_p->end); |
| 744 |
tstack_p->planenum = 0; |
| 745 |
|
| 746 |
tstack_p->nodenum = 1; |
| 747 |
tstack_p++; |
| 748 |
|
| 749 |
while (1) |
| 750 |
{ |
| 751 |
|
| 752 |
tstack_p--; |
| 753 |
|
| 754 |
|
| 755 |
if (tstack_p < tracestack) |
| 756 |
{ |
| 757 |
return numareas; |
| 758 |
} |
| 759 |
|
| 760 |
nodenum = tstack_p->nodenum; |
| 761 |
|
| 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 |
} |
| 770 |
#endif |
| 771 |
|
| 772 |
areas[numareas] = -nodenum; |
| 773 |
if (points) VectorCopy(tstack_p->start, points[numareas]); |
| 774 |
numareas++; |
| 775 |
if (numareas >= maxareas) return numareas; |
| 776 |
continue; |
| 777 |
} |
| 778 |
|
| 779 |
if (!nodenum) |
| 780 |
{ |
| 781 |
continue; |
| 782 |
} |
| 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 |
} |
| 789 |
#endif |
| 790 |
|
| 791 |
aasnode = &aasworld.nodes[nodenum]; |
| 792 |
|
| 793 |
VectorCopy(tstack_p->start, cur_start); |
| 794 |
|
| 795 |
VectorCopy(tstack_p->end, cur_end); |
| 796 |
|
| 797 |
plane = &aasworld.planes[aasnode->planenum]; |
| 798 |
|
| 799 |
switch(plane->type) |
| 800 |
{ |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
default: |
| 821 |
{ |
| 822 |
front = DotProduct(cur_start, plane->normal) - plane->dist; |
| 823 |
back = DotProduct(cur_end, plane->normal) - plane->dist; |
| 824 |
break; |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
if (front > 0 && back > 0) |
| 831 |
{ |
| 832 |
|
| 833 |
|
| 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 |
} |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
else if (front <= 0 && back <= 0) |
| 845 |
{ |
| 846 |
|
| 847 |
|
| 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 |
} |
| 855 |
} |
| 856 |
|
| 857 |
else |
| 858 |
{ |
| 859 |
tmpplanenum = tstack_p->planenum; |
| 860 |
|
| 861 |
|
| 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 |
|
| 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 |
|
| 873 |
|
| 874 |
side = front < 0; |
| 875 |
|
| 876 |
VectorCopy(cur_mid, tstack_p->start); |
| 877 |
|
| 878 |
|
| 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 |
} |
| 887 |
|
| 888 |
|
| 889 |
|
| 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 |
} |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 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 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 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 |
| 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 |
|
| 942 |
firstvertex = edgenum < 0; |
| 943 |
VectorCopy(aasworld.vertexes[edge->v[firstvertex]], v0); |
| 944 |
|
| 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 |
} |
| 952 |
lastvertex = edge->v[!firstvertex]; |
| 953 |
#endif |
| 954 |
|
| 955 |
VectorSubtract(point, v0, pointvec); |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
AAS_OrthogonalToVectors(edgevec, pnormal, sepnormal); |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
if (DotProduct(pointvec, sepnormal) < -epsilon) return qfalse; |
| 968 |
} |
| 969 |
return qtrue; |
| 970 |
} |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 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 |
|
| 996 |
firstvertex = edgenum < 0; |
| 997 |
v1 = aasworld.vertexes[edge->v[firstvertex]]; |
| 998 |
v2 = aasworld.vertexes[edge->v[!firstvertex]]; |
| 999 |
|
| 1000 |
VectorSubtract(v2, v1, edgevec); |
| 1001 |
|
| 1002 |
VectorSubtract(point, v1, pointvec); |
| 1003 |
|
| 1004 |
CrossProduct(edgevec, plane->normal, sepnormal); |
| 1005 |
|
| 1006 |
if (DotProduct(pointvec, sepnormal) < -epsilon) return qfalse; |
| 1007 |
} |
| 1008 |
return qtrue; |
| 1009 |
} |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 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 |
|
| 1033 |
if (face->faceflags & FACE_GROUND) |
| 1034 |
{ |
| 1035 |
|
| 1036 |
if (aasworld.planes[face->planenum].normal[2] < 0) VectorNegate(up, normal); |
| 1037 |
else VectorCopy(up, normal); |
| 1038 |
|
| 1039 |
if (AAS_InsideFace(face, normal, point, 0.01f)) return face; |
| 1040 |
} |
| 1041 |
} |
| 1042 |
return NULL; |
| 1043 |
} |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 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 |
} |
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 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 |
|
| 1075 |
if (trace->startsolid) return NULL; |
| 1076 |
|
| 1077 |
area = &aasworld.areas[trace->lastarea]; |
| 1078 |
|
| 1079 |
for (i = 0; i < area->numfaces; i++) |
| 1080 |
{ |
| 1081 |
facenum = aasworld.faceindex[area->firstface + i]; |
| 1082 |
face = &aasworld.faces[abs(facenum)]; |
| 1083 |
|
| 1084 |
if ((face->planenum & ~1) == (trace->planenum & ~1)) |
| 1085 |
{ |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
if (AAS_InsideFace(face, |
| 1115 |
aasworld.planes[face->planenum].normal, trace->endpos, 0.01f)) return face; |
| 1116 |
} |
| 1117 |
} |
| 1118 |
return firstface; |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 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 |
} |
| 1139 |
else |
| 1140 |
{ |
| 1141 |
corners[1][i] = absmins[i]; |
| 1142 |
corners[0][i] = absmaxs[i]; |
| 1143 |
} |
| 1144 |
} |
| 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 |
} |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 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 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 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 |
|
| 1198 |
nextlink = link->next_area; |
| 1199 |
|
| 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 |
|
| 1204 |
AAS_DeAllocAASLink(link); |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
typedef struct |
| 1218 |
{ |
| 1219 |
int nodenum; |
| 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 |
} |
| 1236 |
|
| 1237 |
areas = NULL; |
| 1238 |
|
| 1239 |
lstack_p = linkstack; |
| 1240 |
|
| 1241 |
|
| 1242 |
lstack_p->nodenum = 1; |
| 1243 |
lstack_p++; |
| 1244 |
|
| 1245 |
while (1) |
| 1246 |
{ |
| 1247 |
|
| 1248 |
lstack_p--; |
| 1249 |
|
| 1250 |
|
| 1251 |
if (lstack_p < linkstack) break; |
| 1252 |
|
| 1253 |
nodenum = lstack_p->nodenum; |
| 1254 |
|
| 1255 |
if (nodenum < 0) |
| 1256 |
{ |
| 1257 |
|
| 1258 |
|
| 1259 |
for (link = aasworld.arealinkedentities[-nodenum]; link; link = link->next_ent) |
| 1260 |
{ |
| 1261 |
if (link->entnum == entnum) break; |
| 1262 |
} |
| 1263 |
if (link) continue; |
| 1264 |
|
| 1265 |
link = AAS_AllocAASLink(); |
| 1266 |
if (!link) return areas; |
| 1267 |
link->entnum = entnum; |
| 1268 |
link->areanum = -nodenum; |
| 1269 |
|
| 1270 |
link->prev_area = NULL; |
| 1271 |
link->next_area = areas; |
| 1272 |
if (areas) areas->prev_area = link; |
| 1273 |
areas = link; |
| 1274 |
|
| 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 |
} |
| 1283 |
|
| 1284 |
if (!nodenum) continue; |
| 1285 |
|
| 1286 |
aasnode = &aasworld.nodes[nodenum]; |
| 1287 |
|
| 1288 |
plane = &aasworld.planes[aasnode->planenum]; |
| 1289 |
|
| 1290 |
side = AAS_BoxOnPlaneSide2(absmins, absmaxs, plane); |
| 1291 |
|
| 1292 |
if (side & 1) |
| 1293 |
{ |
| 1294 |
lstack_p->nodenum = aasnode->children[0]; |
| 1295 |
lstack_p++; |
| 1296 |
} |
| 1297 |
if (lstack_p >= &linkstack[127]) |
| 1298 |
{ |
| 1299 |
botimport.Print(PRT_ERROR, "AAS_LinkEntity: stack overflow\n"); |
| 1300 |
break; |
| 1301 |
} |
| 1302 |
|
| 1303 |
if (side & 2) |
| 1304 |
{ |
| 1305 |
lstack_p->nodenum = aasnode->children[1]; |
| 1306 |
lstack_p++; |
| 1307 |
} |
| 1308 |
if (lstack_p >= &linkstack[127]) |
| 1309 |
{ |
| 1310 |
botimport.Print(PRT_ERROR, "AAS_LinkEntity: stack overflow\n"); |
| 1311 |
break; |
| 1312 |
} |
| 1313 |
} |
| 1314 |
return areas; |
| 1315 |
} |
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 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 |
|
| 1331 |
return AAS_AASLinkEntity(newabsmins, newabsmaxs, entnum); |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 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 |
} |
| 1353 |
AAS_UnlinkFromAreas(linkedareas); |
| 1354 |
return num; |
| 1355 |
} |
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 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 |
} |
| 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 |
} |
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
aas_plane_t *AAS_PlaneFromNum(int planenum) |
| 1389 |
{ |
| 1390 |
if (!aasworld.loaded) return NULL; |
| 1391 |
|
| 1392 |
return &aasworld.planes[planenum]; |
| 1393 |
} |