| 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 |
#include "l_log.h" |
| 38 |
#include "l_memory.h" |
| 39 |
#include "l_libvar.h" |
| 40 |
#include "aasfile.h" |
| 41 |
#include "botlib.h" |
| 42 |
#include "be_aas.h" |
| 43 |
#include "be_aas_funcs.h" |
| 44 |
#include "be_aas_def.h" |
| 45 |
#include "be_aas_cluster.h" |
| 46 |
|
| 47 |
extern botlib_import_t botimport; |
| 48 |
|
| 49 |
#define AAS_MAX_PORTALS 65536 |
| 50 |
#define AAS_MAX_PORTALINDEXSIZE 65536 |
| 51 |
#define AAS_MAX_CLUSTERS 65536 |
| 52 |
|
| 53 |
#define MAX_PORTALAREAS 1024 |
| 54 |
|
| 55 |
|
| 56 |
int nofaceflood = qtrue; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
void AAS_RemoveClusterAreas(void) |
| 65 |
{ |
| 66 |
int i; |
| 67 |
|
| 68 |
for (i = 1; i < aasworld.numareas; i++) |
| 69 |
{ |
| 70 |
aasworld.areasettings[i].cluster = 0; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
void AAS_ClearCluster(int clusternum) |
| 80 |
{ |
| 81 |
int i; |
| 82 |
|
| 83 |
for (i = 1; i < aasworld.numareas; i++) |
| 84 |
{ |
| 85 |
if (aasworld.areasettings[i].cluster == clusternum) |
| 86 |
{ |
| 87 |
aasworld.areasettings[i].cluster = 0; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
void AAS_RemovePortalsClusterReference(int clusternum) |
| 98 |
{ |
| 99 |
int portalnum; |
| 100 |
|
| 101 |
for (portalnum = 1; portalnum < aasworld.numportals; portalnum++) |
| 102 |
{ |
| 103 |
if (aasworld.portals[portalnum].frontcluster == clusternum) |
| 104 |
{ |
| 105 |
aasworld.portals[portalnum].frontcluster = 0; |
| 106 |
} |
| 107 |
if (aasworld.portals[portalnum].backcluster == clusternum) |
| 108 |
{ |
| 109 |
aasworld.portals[portalnum].backcluster = 0; |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
int AAS_UpdatePortal(int areanum, int clusternum) |
| 120 |
{ |
| 121 |
int portalnum; |
| 122 |
aas_portal_t *portal; |
| 123 |
aas_cluster_t *cluster; |
| 124 |
|
| 125 |
|
| 126 |
for (portalnum = 1; portalnum < aasworld.numportals; portalnum++) |
| 127 |
{ |
| 128 |
if (aasworld.portals[portalnum].areanum == areanum) break; |
| 129 |
} |
| 130 |
|
| 131 |
if (portalnum == aasworld.numportals) |
| 132 |
{ |
| 133 |
AAS_Error("no portal of area %d\n", areanum); |
| 134 |
return qtrue; |
| 135 |
} |
| 136 |
|
| 137 |
portal = &aasworld.portals[portalnum]; |
| 138 |
|
| 139 |
if (portal->frontcluster == clusternum) return qtrue; |
| 140 |
if (portal->backcluster == clusternum) return qtrue; |
| 141 |
|
| 142 |
if (!portal->frontcluster) |
| 143 |
{ |
| 144 |
portal->frontcluster = clusternum; |
| 145 |
} |
| 146 |
|
| 147 |
else if (!portal->backcluster) |
| 148 |
{ |
| 149 |
portal->backcluster = clusternum; |
| 150 |
} |
| 151 |
else |
| 152 |
{ |
| 153 |
|
| 154 |
aasworld.areasettings[areanum].contents &= ~AREACONTENTS_CLUSTERPORTAL; |
| 155 |
Log_Write("portal area %d is separating more than two clusters\r\n", areanum); |
| 156 |
return qfalse; |
| 157 |
} |
| 158 |
if (aasworld.portalindexsize >= AAS_MAX_PORTALINDEXSIZE) |
| 159 |
{ |
| 160 |
AAS_Error("AAS_MAX_PORTALINDEXSIZE\n"); |
| 161 |
return qtrue; |
| 162 |
} |
| 163 |
|
| 164 |
aasworld.areasettings[areanum].cluster = -portalnum; |
| 165 |
|
| 166 |
cluster = &aasworld.clusters[clusternum]; |
| 167 |
aasworld.portalindex[cluster->firstportal + cluster->numportals] = portalnum; |
| 168 |
aasworld.portalindexsize++; |
| 169 |
cluster->numportals++; |
| 170 |
return qtrue; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
int AAS_FloodClusterAreas_r(int areanum, int clusternum) |
| 179 |
{ |
| 180 |
aas_area_t *area; |
| 181 |
aas_face_t *face; |
| 182 |
int facenum, i; |
| 183 |
|
| 184 |
|
| 185 |
if (areanum <= 0 || areanum >= aasworld.numareas) |
| 186 |
{ |
| 187 |
AAS_Error("AAS_FloodClusterAreas_r: areanum out of range\n"); |
| 188 |
return qfalse; |
| 189 |
} |
| 190 |
|
| 191 |
if (aasworld.areasettings[areanum].cluster > 0) |
| 192 |
{ |
| 193 |
if (aasworld.areasettings[areanum].cluster == clusternum) return qtrue; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
AAS_Error("cluster %d touched cluster %d at area %d\n", |
| 198 |
clusternum, aasworld.areasettings[areanum].cluster, areanum); |
| 199 |
return qfalse; |
| 200 |
} |
| 201 |
|
| 202 |
if (aasworld.areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL) |
| 203 |
{ |
| 204 |
return AAS_UpdatePortal(areanum, clusternum); |
| 205 |
} |
| 206 |
|
| 207 |
aasworld.areasettings[areanum].cluster = clusternum; |
| 208 |
aasworld.areasettings[areanum].clusterareanum = |
| 209 |
aasworld.clusters[clusternum].numareas; |
| 210 |
|
| 211 |
aasworld.clusters[clusternum].numareas++; |
| 212 |
|
| 213 |
area = &aasworld.areas[areanum]; |
| 214 |
|
| 215 |
if (!nofaceflood) |
| 216 |
{ |
| 217 |
for (i = 0; i < area->numfaces; i++) |
| 218 |
{ |
| 219 |
facenum = abs(aasworld.faceindex[area->firstface + i]); |
| 220 |
face = &aasworld.faces[facenum]; |
| 221 |
if (face->frontarea == areanum) |
| 222 |
{ |
| 223 |
if (face->backarea) if (!AAS_FloodClusterAreas_r(face->backarea, clusternum)) return qfalse; |
| 224 |
} |
| 225 |
else |
| 226 |
{ |
| 227 |
if (face->frontarea) if (!AAS_FloodClusterAreas_r(face->frontarea, clusternum)) return qfalse; |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
for (i = 0; i < aasworld.areasettings[areanum].numreachableareas; i++) |
| 233 |
{ |
| 234 |
if (!aasworld.reachability[ |
| 235 |
aasworld.areasettings[areanum].firstreachablearea + i].areanum) |
| 236 |
{ |
| 237 |
continue; |
| 238 |
} |
| 239 |
if (!AAS_FloodClusterAreas_r(aasworld.reachability[ |
| 240 |
aasworld.areasettings[areanum].firstreachablearea + i].areanum, clusternum)) return qfalse; |
| 241 |
} |
| 242 |
return qtrue; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
int AAS_FloodClusterAreasUsingReachabilities(int clusternum) |
| 252 |
{ |
| 253 |
int i, j, areanum; |
| 254 |
|
| 255 |
for (i = 1; i < aasworld.numareas; i++) |
| 256 |
{ |
| 257 |
|
| 258 |
if (aasworld.areasettings[i].cluster) |
| 259 |
continue; |
| 260 |
|
| 261 |
if (aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL) |
| 262 |
continue; |
| 263 |
|
| 264 |
for (j = 0; j < aasworld.areasettings[i].numreachableareas; j++) |
| 265 |
{ |
| 266 |
|
| 267 |
areanum = aasworld.reachability[aasworld.areasettings[i].firstreachablearea + j].areanum; |
| 268 |
|
| 269 |
if (aasworld.areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL) |
| 270 |
continue; |
| 271 |
|
| 272 |
if (aasworld.areasettings[areanum].cluster) |
| 273 |
{ |
| 274 |
if (!AAS_FloodClusterAreas_r(i, clusternum)) |
| 275 |
return qfalse; |
| 276 |
i = 0; |
| 277 |
break; |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
return qtrue; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
void AAS_NumberClusterPortals(int clusternum) |
| 290 |
{ |
| 291 |
int i, portalnum; |
| 292 |
aas_cluster_t *cluster; |
| 293 |
aas_portal_t *portal; |
| 294 |
|
| 295 |
cluster = &aasworld.clusters[clusternum]; |
| 296 |
for (i = 0; i < cluster->numportals; i++) |
| 297 |
{ |
| 298 |
portalnum = aasworld.portalindex[cluster->firstportal + i]; |
| 299 |
portal = &aasworld.portals[portalnum]; |
| 300 |
if (portal->frontcluster == clusternum) |
| 301 |
{ |
| 302 |
portal->clusterareanum[0] = cluster->numareas++; |
| 303 |
} |
| 304 |
else |
| 305 |
{ |
| 306 |
portal->clusterareanum[1] = cluster->numareas++; |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
void AAS_NumberClusterAreas(int clusternum) |
| 317 |
{ |
| 318 |
int i, portalnum; |
| 319 |
aas_cluster_t *cluster; |
| 320 |
aas_portal_t *portal; |
| 321 |
|
| 322 |
aasworld.clusters[clusternum].numareas = 0; |
| 323 |
aasworld.clusters[clusternum].numreachabilityareas = 0; |
| 324 |
|
| 325 |
for (i = 1; i < aasworld.numareas; i++) |
| 326 |
{ |
| 327 |
|
| 328 |
if (aasworld.areasettings[i].cluster != clusternum) continue; |
| 329 |
|
| 330 |
if (!AAS_AreaReachability(i)) continue; |
| 331 |
|
| 332 |
aasworld.areasettings[i].clusterareanum = aasworld.clusters[clusternum].numareas; |
| 333 |
|
| 334 |
aasworld.clusters[clusternum].numareas++; |
| 335 |
aasworld.clusters[clusternum].numreachabilityareas++; |
| 336 |
} |
| 337 |
|
| 338 |
cluster = &aasworld.clusters[clusternum]; |
| 339 |
for (i = 0; i < cluster->numportals; i++) |
| 340 |
{ |
| 341 |
portalnum = aasworld.portalindex[cluster->firstportal + i]; |
| 342 |
portal = &aasworld.portals[portalnum]; |
| 343 |
if (!AAS_AreaReachability(portal->areanum)) continue; |
| 344 |
if (portal->frontcluster == clusternum) |
| 345 |
{ |
| 346 |
portal->clusterareanum[0] = cluster->numareas++; |
| 347 |
aasworld.clusters[clusternum].numreachabilityareas++; |
| 348 |
} |
| 349 |
else |
| 350 |
{ |
| 351 |
portal->clusterareanum[1] = cluster->numareas++; |
| 352 |
aasworld.clusters[clusternum].numreachabilityareas++; |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
for (i = 1; i < aasworld.numareas; i++) |
| 357 |
{ |
| 358 |
|
| 359 |
if (aasworld.areasettings[i].cluster != clusternum) continue; |
| 360 |
|
| 361 |
if (AAS_AreaReachability(i)) continue; |
| 362 |
|
| 363 |
aasworld.areasettings[i].clusterareanum = aasworld.clusters[clusternum].numareas; |
| 364 |
|
| 365 |
aasworld.clusters[clusternum].numareas++; |
| 366 |
} |
| 367 |
|
| 368 |
cluster = &aasworld.clusters[clusternum]; |
| 369 |
for (i = 0; i < cluster->numportals; i++) |
| 370 |
{ |
| 371 |
portalnum = aasworld.portalindex[cluster->firstportal + i]; |
| 372 |
portal = &aasworld.portals[portalnum]; |
| 373 |
if (AAS_AreaReachability(portal->areanum)) continue; |
| 374 |
if (portal->frontcluster == clusternum) |
| 375 |
{ |
| 376 |
portal->clusterareanum[0] = cluster->numareas++; |
| 377 |
} |
| 378 |
else |
| 379 |
{ |
| 380 |
portal->clusterareanum[1] = cluster->numareas++; |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
int AAS_FindClusters(void) |
| 391 |
{ |
| 392 |
int i; |
| 393 |
aas_cluster_t *cluster; |
| 394 |
|
| 395 |
AAS_RemoveClusterAreas(); |
| 396 |
|
| 397 |
for (i = 1; i < aasworld.numareas; i++) |
| 398 |
{ |
| 399 |
|
| 400 |
if (aasworld.areasettings[i].cluster) |
| 401 |
continue; |
| 402 |
|
| 403 |
if (nofaceflood) |
| 404 |
{ |
| 405 |
if (!aasworld.areasettings[i].numreachableareas) |
| 406 |
continue; |
| 407 |
} |
| 408 |
|
| 409 |
if (aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL) |
| 410 |
continue; |
| 411 |
if (aasworld.numclusters >= AAS_MAX_CLUSTERS) |
| 412 |
{ |
| 413 |
AAS_Error("AAS_MAX_CLUSTERS\n"); |
| 414 |
return qfalse; |
| 415 |
} |
| 416 |
cluster = &aasworld.clusters[aasworld.numclusters]; |
| 417 |
cluster->numareas = 0; |
| 418 |
cluster->numreachabilityareas = 0; |
| 419 |
cluster->firstportal = aasworld.portalindexsize; |
| 420 |
cluster->numportals = 0; |
| 421 |
|
| 422 |
if (!AAS_FloodClusterAreas_r(i, aasworld.numclusters)) |
| 423 |
return qfalse; |
| 424 |
if (!AAS_FloodClusterAreasUsingReachabilities(aasworld.numclusters)) |
| 425 |
return qfalse; |
| 426 |
|
| 427 |
|
| 428 |
AAS_NumberClusterAreas(aasworld.numclusters); |
| 429 |
|
| 430 |
aasworld.numclusters++; |
| 431 |
} |
| 432 |
return qtrue; |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
void AAS_CreatePortals(void) |
| 441 |
{ |
| 442 |
int i; |
| 443 |
aas_portal_t *portal; |
| 444 |
|
| 445 |
for (i = 1; i < aasworld.numareas; i++) |
| 446 |
{ |
| 447 |
|
| 448 |
if (aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL) |
| 449 |
{ |
| 450 |
if (aasworld.numportals >= AAS_MAX_PORTALS) |
| 451 |
{ |
| 452 |
AAS_Error("AAS_MAX_PORTALS\n"); |
| 453 |
return; |
| 454 |
} |
| 455 |
portal = &aasworld.portals[aasworld.numportals]; |
| 456 |
portal->areanum = i; |
| 457 |
portal->frontcluster = 0; |
| 458 |
portal->backcluster = 0; |
| 459 |
aasworld.numportals++; |
| 460 |
} |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
void AAS_ConnectedAreas_r(int *areanums, int numareas, int *connectedareas, int curarea) |
| 689 |
{ |
| 690 |
int i, j, otherareanum, facenum; |
| 691 |
aas_area_t *area; |
| 692 |
aas_face_t *face; |
| 693 |
|
| 694 |
connectedareas[curarea] = qtrue; |
| 695 |
area = &aasworld.areas[areanums[curarea]]; |
| 696 |
for (i = 0; i < area->numfaces; i++) |
| 697 |
{ |
| 698 |
facenum = abs(aasworld.faceindex[area->firstface + i]); |
| 699 |
face = &aasworld.faces[facenum]; |
| 700 |
|
| 701 |
if (face->faceflags & FACE_SOLID) continue; |
| 702 |
|
| 703 |
if (face->frontarea != areanums[curarea]) otherareanum = face->frontarea; |
| 704 |
else otherareanum = face->backarea; |
| 705 |
|
| 706 |
for (j = 0; j < numareas; j++) |
| 707 |
{ |
| 708 |
if (areanums[j] == otherareanum) break; |
| 709 |
} |
| 710 |
|
| 711 |
if (j == numareas) continue; |
| 712 |
|
| 713 |
if (connectedareas[j]) continue; |
| 714 |
|
| 715 |
AAS_ConnectedAreas_r(areanums, numareas, connectedareas, j); |
| 716 |
} |
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
qboolean AAS_ConnectedAreas(int *areanums, int numareas) |
| 725 |
{ |
| 726 |
int connectedareas[MAX_PORTALAREAS], i; |
| 727 |
|
| 728 |
Com_Memset(connectedareas, 0, sizeof(connectedareas)); |
| 729 |
if (numareas < 1) return qfalse; |
| 730 |
if (numareas == 1) return qtrue; |
| 731 |
AAS_ConnectedAreas_r(areanums, numareas, connectedareas, 0); |
| 732 |
for (i = 0; i < numareas; i++) |
| 733 |
{ |
| 734 |
if (!connectedareas[i]) return qfalse; |
| 735 |
} |
| 736 |
return qtrue; |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
int AAS_GetAdjacentAreasWithLessPresenceTypes_r(int *areanums, int numareas, int curareanum) |
| 746 |
{ |
| 747 |
int i, j, presencetype, otherpresencetype, otherareanum, facenum; |
| 748 |
aas_area_t *area; |
| 749 |
aas_face_t *face; |
| 750 |
|
| 751 |
areanums[numareas++] = curareanum; |
| 752 |
area = &aasworld.areas[curareanum]; |
| 753 |
presencetype = aasworld.areasettings[curareanum].presencetype; |
| 754 |
for (i = 0; i < area->numfaces; i++) |
| 755 |
{ |
| 756 |
facenum = abs(aasworld.faceindex[area->firstface + i]); |
| 757 |
face = &aasworld.faces[facenum]; |
| 758 |
|
| 759 |
if (face->faceflags & FACE_SOLID) continue; |
| 760 |
|
| 761 |
if (face->frontarea != curareanum) otherareanum = face->frontarea; |
| 762 |
else otherareanum = face->backarea; |
| 763 |
|
| 764 |
otherpresencetype = aasworld.areasettings[otherareanum].presencetype; |
| 765 |
|
| 766 |
if ((presencetype & ~otherpresencetype) && |
| 767 |
!(otherpresencetype & ~presencetype)) |
| 768 |
{ |
| 769 |
|
| 770 |
for (j = 0; j < numareas; j++) |
| 771 |
{ |
| 772 |
if (otherareanum == areanums[j]) break; |
| 773 |
} |
| 774 |
|
| 775 |
if (j == numareas) |
| 776 |
{ |
| 777 |
if (numareas >= MAX_PORTALAREAS) |
| 778 |
{ |
| 779 |
AAS_Error("MAX_PORTALAREAS\n"); |
| 780 |
return numareas; |
| 781 |
} |
| 782 |
numareas = AAS_GetAdjacentAreasWithLessPresenceTypes_r(areanums, numareas, otherareanum); |
| 783 |
} |
| 784 |
} |
| 785 |
} |
| 786 |
return numareas; |
| 787 |
} |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
int AAS_CheckAreaForPossiblePortals(int areanum) |
| 795 |
{ |
| 796 |
int i, j, k, fen, ben, frontedgenum, backedgenum, facenum; |
| 797 |
int areanums[MAX_PORTALAREAS], numareas, otherareanum; |
| 798 |
int numareafrontfaces[MAX_PORTALAREAS], numareabackfaces[MAX_PORTALAREAS]; |
| 799 |
int frontfacenums[MAX_PORTALAREAS], backfacenums[MAX_PORTALAREAS]; |
| 800 |
int numfrontfaces, numbackfaces; |
| 801 |
int frontareanums[MAX_PORTALAREAS], backareanums[MAX_PORTALAREAS]; |
| 802 |
int numfrontareas, numbackareas; |
| 803 |
int frontplanenum, backplanenum, faceplanenum; |
| 804 |
aas_area_t *area; |
| 805 |
aas_face_t *frontface, *backface, *face; |
| 806 |
|
| 807 |
|
| 808 |
if (aasworld.areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL) return 0; |
| 809 |
|
| 810 |
if (!(aasworld.areasettings[areanum].areaflags & AREA_GROUNDED)) return 0; |
| 811 |
|
| 812 |
Com_Memset(numareafrontfaces, 0, sizeof(numareafrontfaces)); |
| 813 |
Com_Memset(numareabackfaces, 0, sizeof(numareabackfaces)); |
| 814 |
numfrontfaces = numbackfaces = 0; |
| 815 |
numfrontareas = numbackareas = 0; |
| 816 |
frontplanenum = backplanenum = -1; |
| 817 |
|
| 818 |
numareas = AAS_GetAdjacentAreasWithLessPresenceTypes_r(areanums, 0, areanum); |
| 819 |
|
| 820 |
for (i = 0; i < numareas; i++) |
| 821 |
{ |
| 822 |
area = &aasworld.areas[areanums[i]]; |
| 823 |
for (j = 0; j < area->numfaces; j++) |
| 824 |
{ |
| 825 |
facenum = abs(aasworld.faceindex[area->firstface + j]); |
| 826 |
face = &aasworld.faces[facenum]; |
| 827 |
|
| 828 |
if (face->faceflags & FACE_SOLID) continue; |
| 829 |
|
| 830 |
for (k = 0; k < numareas; k++) |
| 831 |
{ |
| 832 |
if (k == i) continue; |
| 833 |
if (face->frontarea == areanums[k] || face->backarea == areanums[k]) break; |
| 834 |
} |
| 835 |
|
| 836 |
if (k != numareas) continue; |
| 837 |
|
| 838 |
if (face->frontarea == areanums[i]) otherareanum = face->backarea; |
| 839 |
else otherareanum = face->frontarea; |
| 840 |
|
| 841 |
if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) return 0; |
| 842 |
|
| 843 |
faceplanenum = face->planenum & ~1; |
| 844 |
|
| 845 |
if (frontplanenum < 0 || faceplanenum == frontplanenum) |
| 846 |
{ |
| 847 |
frontplanenum = faceplanenum; |
| 848 |
frontfacenums[numfrontfaces++] = facenum; |
| 849 |
for (k = 0; k < numfrontareas; k++) |
| 850 |
{ |
| 851 |
if (frontareanums[k] == otherareanum) break; |
| 852 |
} |
| 853 |
if (k == numfrontareas) frontareanums[numfrontareas++] = otherareanum; |
| 854 |
numareafrontfaces[i]++; |
| 855 |
} |
| 856 |
else if (backplanenum < 0 || faceplanenum == backplanenum) |
| 857 |
{ |
| 858 |
backplanenum = faceplanenum; |
| 859 |
backfacenums[numbackfaces++] = facenum; |
| 860 |
for (k = 0; k < numbackareas; k++) |
| 861 |
{ |
| 862 |
if (backareanums[k] == otherareanum) break; |
| 863 |
} |
| 864 |
if (k == numbackareas) backareanums[numbackareas++] = otherareanum; |
| 865 |
numareabackfaces[i]++; |
| 866 |
} |
| 867 |
else |
| 868 |
{ |
| 869 |
return 0; |
| 870 |
} |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
for (i = 0; i < numareas; i++) |
| 875 |
{ |
| 876 |
if (!numareafrontfaces[i] || !numareabackfaces[i]) return 0; |
| 877 |
} |
| 878 |
|
| 879 |
if (!AAS_ConnectedAreas(frontareanums, numfrontareas)) return 0; |
| 880 |
|
| 881 |
if (!AAS_ConnectedAreas(backareanums, numbackareas)) return 0; |
| 882 |
|
| 883 |
for (i = 0; i < numfrontfaces; i++) |
| 884 |
{ |
| 885 |
frontface = &aasworld.faces[frontfacenums[i]]; |
| 886 |
for (fen = 0; fen < frontface->numedges; fen++) |
| 887 |
{ |
| 888 |
frontedgenum = abs(aasworld.edgeindex[frontface->firstedge + fen]); |
| 889 |
for (j = 0; j < numbackfaces; j++) |
| 890 |
{ |
| 891 |
backface = &aasworld.faces[backfacenums[j]]; |
| 892 |
for (ben = 0; ben < backface->numedges; ben++) |
| 893 |
{ |
| 894 |
backedgenum = abs(aasworld.edgeindex[backface->firstedge + ben]); |
| 895 |
if (frontedgenum == backedgenum) break; |
| 896 |
} |
| 897 |
if (ben != backface->numedges) break; |
| 898 |
} |
| 899 |
if (j != numbackfaces) break; |
| 900 |
} |
| 901 |
if (fen != frontface->numedges) break; |
| 902 |
} |
| 903 |
if (i != numfrontfaces) return 0; |
| 904 |
|
| 905 |
for (i = 0; i < numareas; i++) |
| 906 |
{ |
| 907 |
aasworld.areasettings[areanums[i]].contents |= AREACONTENTS_CLUSTERPORTAL; |
| 908 |
|
| 909 |
aasworld.areasettings[areanums[i]].contents |= AREACONTENTS_ROUTEPORTAL; |
| 910 |
Log_Write("possible portal: %d\r\n", areanums[i]); |
| 911 |
} |
| 912 |
|
| 913 |
return numareas; |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
void AAS_FindPossiblePortals(void) |
| 922 |
{ |
| 923 |
int i, numpossibleportals; |
| 924 |
|
| 925 |
numpossibleportals = 0; |
| 926 |
for (i = 1; i < aasworld.numareas; i++) |
| 927 |
{ |
| 928 |
numpossibleportals += AAS_CheckAreaForPossiblePortals(i); |
| 929 |
} |
| 930 |
botimport.Print(PRT_MESSAGE, "\r%6d possible portal areas\n", numpossibleportals); |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
void AAS_RemoveAllPortals(void) |
| 939 |
{ |
| 940 |
int i; |
| 941 |
|
| 942 |
for (i = 1; i < aasworld.numareas; i++) |
| 943 |
{ |
| 944 |
aasworld.areasettings[i].contents &= ~AREACONTENTS_CLUSTERPORTAL; |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
#if 0 |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
void AAS_FloodCluster_r(int areanum, int clusternum) |
| 956 |
{ |
| 957 |
int i, otherareanum; |
| 958 |
aas_face_t *face; |
| 959 |
aas_area_t *area; |
| 960 |
|
| 961 |
|
| 962 |
aasworld.areasettings[areanum].cluster = clusternum; |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
area = &aasworld.areas[areanum]; |
| 967 |
|
| 968 |
for (i = 0; i < area->numfaces; i++) |
| 969 |
{ |
| 970 |
face = &aasworld.faces[abs(aasworld.faceindex[area->firstface + i])]; |
| 971 |
|
| 972 |
if (face->frontarea != areanum) otherareanum = face->frontarea; |
| 973 |
else otherareanum = face->backarea; |
| 974 |
|
| 975 |
if (!otherareanum) continue; |
| 976 |
|
| 977 |
if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; |
| 978 |
|
| 979 |
if (aasworld.areasettings[otherareanum].cluster) continue; |
| 980 |
|
| 981 |
AAS_FloodCluster_r(otherareanum, clusternum); |
| 982 |
} |
| 983 |
|
| 984 |
for (i = 0; i < aasworld.areasettings[areanum].numreachableareas; i++) |
| 985 |
{ |
| 986 |
otherareanum = aasworld.reachability[ |
| 987 |
aasworld.areasettings[areanum].firstreachablearea + i].areanum; |
| 988 |
if (!otherareanum) |
| 989 |
{ |
| 990 |
continue; |
| 991 |
AAS_Error("reachability %d has zero area\n", aasworld.areasettings[areanum].firstreachablearea + i); |
| 992 |
} |
| 993 |
|
| 994 |
if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; |
| 995 |
|
| 996 |
if (aasworld.areasettings[otherareanum].cluster) continue; |
| 997 |
|
| 998 |
AAS_FloodCluster_r(otherareanum, clusternum); |
| 999 |
} |
| 1000 |
} |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
void AAS_RemoveTeleporterPortals(void) |
| 1008 |
{ |
| 1009 |
int i, j, areanum; |
| 1010 |
|
| 1011 |
for (i = 1; i < aasworld.numareas; i++) |
| 1012 |
{ |
| 1013 |
for (j = 0; j < aasworld.areasettings[i].numreachableareas; j++) |
| 1014 |
{ |
| 1015 |
areanum = aasworld.reachability[aasworld.areasettings[i].firstreachablearea + j].areanum; |
| 1016 |
if (aasworld.reachability[aasworld.areasettings[i].firstreachablearea + j].traveltype == TRAVEL_TELEPORT) |
| 1017 |
{ |
| 1018 |
aasworld.areasettings[i].contents &= ~AREACONTENTS_CLUSTERPORTAL; |
| 1019 |
aasworld.areasettings[areanum].contents &= ~AREACONTENTS_CLUSTERPORTAL; |
| 1020 |
break; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
} |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
void AAS_FloodClusterReachabilities(int clusternum) |
| 1032 |
{ |
| 1033 |
int i, j, areanum; |
| 1034 |
|
| 1035 |
for (i = 1; i < aasworld.numareas; i++) |
| 1036 |
{ |
| 1037 |
|
| 1038 |
if (aasworld.areasettings[i].cluster) continue; |
| 1039 |
|
| 1040 |
if (aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL) continue; |
| 1041 |
|
| 1042 |
for (j = 0; j < aasworld.areasettings[i].numreachableareas; j++) |
| 1043 |
{ |
| 1044 |
|
| 1045 |
areanum = aasworld.reachability[aasworld.areasettings[i].firstreachablearea + j].areanum; |
| 1046 |
|
| 1047 |
if (aasworld.areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; |
| 1048 |
|
| 1049 |
if (aasworld.areasettings[areanum].cluster == clusternum) |
| 1050 |
{ |
| 1051 |
AAS_FloodCluster_r(i, clusternum); |
| 1052 |
i = 0; |
| 1053 |
break; |
| 1054 |
} |
| 1055 |
} |
| 1056 |
} |
| 1057 |
} |
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
void AAS_RemoveNotClusterClosingPortals(void) |
| 1066 |
{ |
| 1067 |
int i, j, k, facenum, otherareanum, nonclosingportals; |
| 1068 |
aas_area_t *area; |
| 1069 |
aas_face_t *face; |
| 1070 |
|
| 1071 |
AAS_RemoveTeleporterPortals(); |
| 1072 |
|
| 1073 |
nonclosingportals = 0; |
| 1074 |
for (i = 1; i < aasworld.numareas; i++) |
| 1075 |
{ |
| 1076 |
if (!(aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL)) continue; |
| 1077 |
|
| 1078 |
|
| 1079 |
area = &aasworld.areas[i]; |
| 1080 |
for (j = 0; j < area->numfaces; j++) |
| 1081 |
{ |
| 1082 |
facenum = abs(aasworld.faceindex[area->firstface + j]); |
| 1083 |
face = &aasworld.faces[facenum]; |
| 1084 |
|
| 1085 |
if (face->frontarea != i) otherareanum = face->frontarea; |
| 1086 |
else otherareanum = face->backarea; |
| 1087 |
|
| 1088 |
if (!otherareanum) continue; |
| 1089 |
|
| 1090 |
if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) |
| 1091 |
{ |
| 1092 |
continue; |
| 1093 |
} |
| 1094 |
|
| 1095 |
AAS_RemoveClusterAreas(); |
| 1096 |
|
| 1097 |
AAS_FloodCluster_r(otherareanum, 1); |
| 1098 |
AAS_FloodClusterReachabilities(1); |
| 1099 |
|
| 1100 |
for (k = 0; k < area->numfaces; k++) |
| 1101 |
{ |
| 1102 |
facenum = abs(aasworld.faceindex[area->firstface + k]); |
| 1103 |
face = &aasworld.faces[facenum]; |
| 1104 |
|
| 1105 |
if (face->frontarea != i) otherareanum = face->frontarea; |
| 1106 |
else otherareanum = face->backarea; |
| 1107 |
|
| 1108 |
if (!otherareanum) continue; |
| 1109 |
|
| 1110 |
if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) |
| 1111 |
{ |
| 1112 |
continue; |
| 1113 |
} |
| 1114 |
|
| 1115 |
if (!aasworld.areasettings[otherareanum].cluster) break; |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
if (k >= area->numfaces) |
| 1120 |
{ |
| 1121 |
aasworld.areasettings[i].contents &= ~AREACONTENTS_CLUSTERPORTAL; |
| 1122 |
nonclosingportals++; |
| 1123 |
|
| 1124 |
i = 0; |
| 1125 |
break; |
| 1126 |
} |
| 1127 |
} |
| 1128 |
} |
| 1129 |
botimport.Print(PRT_MESSAGE, "\r%6d non closing portals removed\n", nonclosingportals); |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
void AAS_RemoveNotClusterClosingPortals(void) |
| 1140 |
{ |
| 1141 |
int i, j, facenum, otherareanum, nonclosingportals, numseperatedclusters; |
| 1142 |
aas_area_t *area; |
| 1143 |
aas_face_t *face; |
| 1144 |
|
| 1145 |
AAS_RemoveTeleporterPortals(); |
| 1146 |
|
| 1147 |
nonclosingportals = 0; |
| 1148 |
for (i = 1; i < aasworld.numareas; i++) |
| 1149 |
{ |
| 1150 |
if (!(aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL)) continue; |
| 1151 |
|
| 1152 |
numseperatedclusters = 0; |
| 1153 |
|
| 1154 |
AAS_RemoveClusterAreas(); |
| 1155 |
|
| 1156 |
|
| 1157 |
area = &aasworld.areas[i]; |
| 1158 |
for (j = 0; j < area->numfaces; j++) |
| 1159 |
{ |
| 1160 |
facenum = abs(aasworld.faceindex[area->firstface + j]); |
| 1161 |
face = &aasworld.faces[facenum]; |
| 1162 |
|
| 1163 |
if (face->frontarea != i) otherareanum = face->frontarea; |
| 1164 |
else otherareanum = face->backarea; |
| 1165 |
|
| 1166 |
if (!otherareanum) continue; |
| 1167 |
|
| 1168 |
if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; |
| 1169 |
|
| 1170 |
if (aasworld.areasettings[otherareanum].cluster) continue; |
| 1171 |
|
| 1172 |
numseperatedclusters++; |
| 1173 |
|
| 1174 |
AAS_FloodCluster_r(otherareanum, numseperatedclusters); |
| 1175 |
AAS_FloodClusterReachabilities(numseperatedclusters); |
| 1176 |
} |
| 1177 |
|
| 1178 |
for (j = 0; j < aasworld.areasettings[i].numreachableareas; j++) |
| 1179 |
{ |
| 1180 |
otherareanum = aasworld.reachability[ |
| 1181 |
aasworld.areasettings[i].firstreachablearea + j].areanum; |
| 1182 |
|
| 1183 |
if (!otherareanum) continue; |
| 1184 |
|
| 1185 |
if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; |
| 1186 |
|
| 1187 |
if (aasworld.areasettings[otherareanum].cluster) continue; |
| 1188 |
|
| 1189 |
numseperatedclusters++; |
| 1190 |
|
| 1191 |
AAS_FloodCluster_r(otherareanum, numseperatedclusters); |
| 1192 |
AAS_FloodClusterReachabilities(numseperatedclusters); |
| 1193 |
} |
| 1194 |
|
| 1195 |
if (numseperatedclusters != 2) |
| 1196 |
{ |
| 1197 |
aasworld.areasettings[i].contents &= ~AREACONTENTS_CLUSTERPORTAL; |
| 1198 |
nonclosingportals++; |
| 1199 |
|
| 1200 |
i = 0; |
| 1201 |
} |
| 1202 |
} |
| 1203 |
botimport.Print(PRT_MESSAGE, "\r%6d non closing portals removed\n", nonclosingportals); |
| 1204 |
} |
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
void AAS_AddTeleporterPortals(void) |
| 1214 |
{ |
| 1215 |
int j, area2num, facenum, otherareanum; |
| 1216 |
char *target, *targetname, *classname; |
| 1217 |
bsp_entity_t *entities, *ent, *dest; |
| 1218 |
vec3_t origin, destorigin, mins, maxs, end; |
| 1219 |
vec3_t bbmins, bbmaxs; |
| 1220 |
aas_area_t *area; |
| 1221 |
aas_face_t *face; |
| 1222 |
aas_trace_t trace; |
| 1223 |
aas_link_t *areas, *link; |
| 1224 |
|
| 1225 |
entities = AAS_ParseBSPEntities(); |
| 1226 |
|
| 1227 |
for (ent = entities; ent; ent = ent->next) |
| 1228 |
{ |
| 1229 |
classname = AAS_ValueForBSPEpairKey(ent, "classname"); |
| 1230 |
if (classname && !strcmp(classname, "misc_teleporter")) |
| 1231 |
{ |
| 1232 |
if (!AAS_VectorForBSPEpairKey(ent, "origin", origin)) |
| 1233 |
{ |
| 1234 |
botimport.Print(PRT_ERROR, "teleporter (%s) without origin\n", target); |
| 1235 |
continue; |
| 1236 |
} |
| 1237 |
|
| 1238 |
target = AAS_ValueForBSPEpairKey(ent, "target"); |
| 1239 |
if (!target) |
| 1240 |
{ |
| 1241 |
botimport.Print(PRT_ERROR, "teleporter (%s) without target\n", target); |
| 1242 |
continue; |
| 1243 |
} |
| 1244 |
for (dest = entities; dest; dest = dest->next) |
| 1245 |
{ |
| 1246 |
classname = AAS_ValueForBSPEpairKey(dest, "classname"); |
| 1247 |
if (classname && !strcmp(classname, "misc_teleporter_dest")) |
| 1248 |
{ |
| 1249 |
targetname = AAS_ValueForBSPEpairKey(dest, "targetname"); |
| 1250 |
if (targetname && !strcmp(targetname, target)) |
| 1251 |
{ |
| 1252 |
break; |
| 1253 |
} |
| 1254 |
} |
| 1255 |
} |
| 1256 |
if (!dest) |
| 1257 |
{ |
| 1258 |
botimport.Print(PRT_ERROR, "teleporter without destination (%s)\n", target); |
| 1259 |
continue; |
| 1260 |
} |
| 1261 |
if (!AAS_VectorForBSPEpairKey(dest, "origin", destorigin)) |
| 1262 |
{ |
| 1263 |
botimport.Print(PRT_ERROR, "teleporter destination (%s) without origin\n", target); |
| 1264 |
continue; |
| 1265 |
} |
| 1266 |
destorigin[2] += 24; |
| 1267 |
VectorCopy(destorigin, end); |
| 1268 |
end[2] -= 100; |
| 1269 |
trace = AAS_TraceClientBBox(destorigin, end, PRESENCE_CROUCH, -1); |
| 1270 |
if (trace.startsolid) |
| 1271 |
{ |
| 1272 |
botimport.Print(PRT_ERROR, "teleporter destination (%s) in solid\n", target); |
| 1273 |
continue; |
| 1274 |
} |
| 1275 |
VectorCopy(trace.endpos, destorigin); |
| 1276 |
area2num = AAS_PointAreaNum(destorigin); |
| 1277 |
|
| 1278 |
for (j = 0; j < aasworld.numareas; j++) |
| 1279 |
{ |
| 1280 |
aasworld.areasettings[j].cluster = 0; |
| 1281 |
} |
| 1282 |
|
| 1283 |
VectorSet(mins, -8, -8, 8); |
| 1284 |
VectorSet(maxs, 8, 8, 24); |
| 1285 |
|
| 1286 |
AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bbmins, bbmaxs); |
| 1287 |
|
| 1288 |
VectorAdd(origin, mins, mins); |
| 1289 |
VectorAdd(origin, maxs, maxs); |
| 1290 |
|
| 1291 |
VectorSubtract(mins, bbmaxs, mins); |
| 1292 |
VectorSubtract(maxs, bbmins, maxs); |
| 1293 |
|
| 1294 |
areas = AAS_AASLinkEntity(mins, maxs, -1); |
| 1295 |
|
| 1296 |
for (link = areas; link; link = link->next_area) |
| 1297 |
{ |
| 1298 |
if (!AAS_AreaGrounded(link->areanum)) continue; |
| 1299 |
|
| 1300 |
aasworld.areasettings[link->areanum].contents |= AREACONTENTS_CLUSTERPORTAL | |
| 1301 |
AREACONTENTS_TELEPORTAL; |
| 1302 |
} |
| 1303 |
|
| 1304 |
for (link = areas; link; link = link->next_area) |
| 1305 |
{ |
| 1306 |
if (!AAS_AreaGrounded(link->areanum)) continue; |
| 1307 |
|
| 1308 |
|
| 1309 |
area = &aasworld.areas[link->areanum]; |
| 1310 |
for (j = 0; j < area->numfaces; j++) |
| 1311 |
{ |
| 1312 |
facenum = abs(aasworld.faceindex[area->firstface + j]); |
| 1313 |
face = &aasworld.faces[facenum]; |
| 1314 |
|
| 1315 |
if (face->frontarea != link->areanum) otherareanum = face->frontarea; |
| 1316 |
else otherareanum = face->backarea; |
| 1317 |
|
| 1318 |
if (!otherareanum) continue; |
| 1319 |
|
| 1320 |
if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) |
| 1321 |
{ |
| 1322 |
continue; |
| 1323 |
} |
| 1324 |
|
| 1325 |
AAS_FloodCluster_r(otherareanum, 1); |
| 1326 |
} |
| 1327 |
} |
| 1328 |
|
| 1329 |
if (aasworld.areasettings[area2num].cluster) |
| 1330 |
{ |
| 1331 |
for (link = areas; link; link = link->next_area) |
| 1332 |
{ |
| 1333 |
if (!AAS_AreaGrounded(link->areanum)) continue; |
| 1334 |
|
| 1335 |
aasworld.areasettings[link->areanum].contents &= ~(AREACONTENTS_CLUSTERPORTAL | |
| 1336 |
AREACONTENTS_TELEPORTAL); |
| 1337 |
} |
| 1338 |
} |
| 1339 |
} |
| 1340 |
} |
| 1341 |
AAS_FreeBSPEntities(entities); |
| 1342 |
} |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
void AAS_AddTeleporterPortals(void) |
| 1351 |
{ |
| 1352 |
int i, j, areanum; |
| 1353 |
|
| 1354 |
for (i = 1; i < aasworld.numareas; i++) |
| 1355 |
{ |
| 1356 |
for (j = 0; j < aasworld.areasettings[i].numreachableareas; j++) |
| 1357 |
{ |
| 1358 |
if (aasworld.reachability[aasworld.areasettings[i].firstreachablearea + j].traveltype != TRAVEL_TELEPORT) continue; |
| 1359 |
areanum = aasworld.reachability[aasworld.areasettings[i].firstreachablearea + j].areanum; |
| 1360 |
aasworld.areasettings[areanum].contents |= AREACONTENTS_CLUSTERPORTAL; |
| 1361 |
} |
| 1362 |
} |
| 1363 |
} |
| 1364 |
|
| 1365 |
#endif |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
int AAS_TestPortals(void) |
| 1374 |
{ |
| 1375 |
int i; |
| 1376 |
aas_portal_t *portal; |
| 1377 |
|
| 1378 |
for (i = 1; i < aasworld.numportals; i++) |
| 1379 |
{ |
| 1380 |
portal = &aasworld.portals[i]; |
| 1381 |
if (!portal->frontcluster) |
| 1382 |
{ |
| 1383 |
aasworld.areasettings[portal->areanum].contents &= ~AREACONTENTS_CLUSTERPORTAL; |
| 1384 |
Log_Write("portal area %d has no front cluster\r\n", portal->areanum); |
| 1385 |
return qfalse; |
| 1386 |
} |
| 1387 |
if (!portal->backcluster) |
| 1388 |
{ |
| 1389 |
aasworld.areasettings[portal->areanum].contents &= ~AREACONTENTS_CLUSTERPORTAL; |
| 1390 |
Log_Write("portal area %d has no back cluster\r\n", portal->areanum); |
| 1391 |
return qfalse; |
| 1392 |
} |
| 1393 |
} |
| 1394 |
return qtrue; |
| 1395 |
} |
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
void AAS_CountForcedClusterPortals(void) |
| 1403 |
{ |
| 1404 |
int num, i; |
| 1405 |
|
| 1406 |
num = 0; |
| 1407 |
for (i = 1; i < aasworld.numareas; i++) |
| 1408 |
{ |
| 1409 |
if (aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL) |
| 1410 |
{ |
| 1411 |
Log_Write("area %d is a forced portal area\r\n", i); |
| 1412 |
num++; |
| 1413 |
} |
| 1414 |
} |
| 1415 |
botimport.Print(PRT_MESSAGE, "%6d forced portal areas\n", num); |
| 1416 |
} |
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
void AAS_CreateViewPortals(void) |
| 1424 |
{ |
| 1425 |
int i; |
| 1426 |
|
| 1427 |
for (i = 1; i < aasworld.numareas; i++) |
| 1428 |
{ |
| 1429 |
if (aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL) |
| 1430 |
{ |
| 1431 |
aasworld.areasettings[i].contents |= AREACONTENTS_VIEWPORTAL; |
| 1432 |
} |
| 1433 |
} |
| 1434 |
} |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
void AAS_SetViewPortalsAsClusterPortals(void) |
| 1442 |
{ |
| 1443 |
int i; |
| 1444 |
|
| 1445 |
for (i = 1; i < aasworld.numareas; i++) |
| 1446 |
{ |
| 1447 |
if (aasworld.areasettings[i].contents & AREACONTENTS_VIEWPORTAL) |
| 1448 |
{ |
| 1449 |
aasworld.areasettings[i].contents |= AREACONTENTS_CLUSTERPORTAL; |
| 1450 |
} |
| 1451 |
} |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
void AAS_InitClustering(void) |
| 1460 |
{ |
| 1461 |
int i, removedPortalAreas; |
| 1462 |
int n, total, numreachabilityareas; |
| 1463 |
|
| 1464 |
if (!aasworld.loaded) return; |
| 1465 |
|
| 1466 |
if (aasworld.numclusters >= 1) |
| 1467 |
{ |
| 1468 |
#ifndef BSPC |
| 1469 |
|
| 1470 |
if (!((int)LibVarGetValue("forceclustering")) && |
| 1471 |
!((int)LibVarGetValue("forcereachability"))) return; |
| 1472 |
#endif |
| 1473 |
} |
| 1474 |
|
| 1475 |
AAS_SetViewPortalsAsClusterPortals(); |
| 1476 |
|
| 1477 |
AAS_CountForcedClusterPortals(); |
| 1478 |
|
| 1479 |
AAS_RemoveClusterAreas(); |
| 1480 |
|
| 1481 |
AAS_FindPossiblePortals(); |
| 1482 |
|
| 1483 |
AAS_CreateViewPortals(); |
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
if (aasworld.portals) FreeMemory(aasworld.portals); |
| 1488 |
aasworld.portals = (aas_portal_t *) GetClearedMemory(AAS_MAX_PORTALS * sizeof(aas_portal_t)); |
| 1489 |
|
| 1490 |
if (aasworld.portalindex) FreeMemory(aasworld.portalindex); |
| 1491 |
aasworld.portalindex = (aas_portalindex_t *) GetClearedMemory(AAS_MAX_PORTALINDEXSIZE * sizeof(aas_portalindex_t)); |
| 1492 |
|
| 1493 |
if (aasworld.clusters) FreeMemory(aasworld.clusters); |
| 1494 |
aasworld.clusters = (aas_cluster_t *) GetClearedMemory(AAS_MAX_CLUSTERS * sizeof(aas_cluster_t)); |
| 1495 |
|
| 1496 |
removedPortalAreas = 0; |
| 1497 |
botimport.Print(PRT_MESSAGE, "\r%6d removed portal areas", removedPortalAreas); |
| 1498 |
while(1) |
| 1499 |
{ |
| 1500 |
botimport.Print(PRT_MESSAGE, "\r%6d", removedPortalAreas); |
| 1501 |
|
| 1502 |
aasworld.numportals = 1; |
| 1503 |
aasworld.portalindexsize = 0; |
| 1504 |
aasworld.numclusters = 1; |
| 1505 |
|
| 1506 |
AAS_CreatePortals(); |
| 1507 |
|
| 1508 |
removedPortalAreas++; |
| 1509 |
|
| 1510 |
if (!AAS_FindClusters()) |
| 1511 |
continue; |
| 1512 |
|
| 1513 |
if (!AAS_TestPortals()) |
| 1514 |
continue; |
| 1515 |
|
| 1516 |
break; |
| 1517 |
} |
| 1518 |
botimport.Print(PRT_MESSAGE, "\n"); |
| 1519 |
|
| 1520 |
aasworld.savefile = qtrue; |
| 1521 |
|
| 1522 |
for (i = 1; i < aasworld.numportals; i++) |
| 1523 |
{ |
| 1524 |
Log_Write("portal %d: area %d\r\n", i, aasworld.portals[i].areanum); |
| 1525 |
} |
| 1526 |
|
| 1527 |
botimport.Print(PRT_MESSAGE, "%6d portals created\n", aasworld.numportals); |
| 1528 |
botimport.Print(PRT_MESSAGE, "%6d clusters created\n", aasworld.numclusters); |
| 1529 |
for (i = 1; i < aasworld.numclusters; i++) |
| 1530 |
{ |
| 1531 |
botimport.Print(PRT_MESSAGE, "cluster %d has %d reachability areas\n", i, |
| 1532 |
aasworld.clusters[i].numreachabilityareas); |
| 1533 |
} |
| 1534 |
|
| 1535 |
numreachabilityareas = 0; |
| 1536 |
total = 0; |
| 1537 |
for (i = 0; i < aasworld.numclusters; i++) { |
| 1538 |
n = aasworld.clusters[i].numreachabilityareas; |
| 1539 |
numreachabilityareas += n; |
| 1540 |
total += n * n; |
| 1541 |
} |
| 1542 |
total += numreachabilityareas * aasworld.numportals; |
| 1543 |
|
| 1544 |
botimport.Print(PRT_MESSAGE, "%6i total reachability areas\n", numreachabilityareas); |
| 1545 |
botimport.Print(PRT_MESSAGE, "%6i AAS memory/CPU usage (the lower the better)\n", total * 3); |
| 1546 |
} |