| 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_utils.h" |
| 34 |
#include "l_memory.h" |
| 35 |
#include "l_log.h" |
| 36 |
#include "l_crc.h" |
| 37 |
#include "l_libvar.h" |
| 38 |
#include "l_script.h" |
| 39 |
#include "l_precomp.h" |
| 40 |
#include "l_struct.h" |
| 41 |
#include "aasfile.h" |
| 42 |
#include "botlib.h" |
| 43 |
#include "be_aas.h" |
| 44 |
#include "be_aas_funcs.h" |
| 45 |
#include "be_interface.h" |
| 46 |
#include "be_aas_def.h" |
| 47 |
|
| 48 |
#define ROUTING_DEBUG |
| 49 |
|
| 50 |
|
| 51 |
#define DISTANCEFACTOR_CROUCH 1.3f //crouch speed = 100 |
| 52 |
#define DISTANCEFACTOR_SWIM 1 //should be 0.66, swim speed = 150 |
| 53 |
#define DISTANCEFACTOR_WALK 0.33f //walk speed = 300 |
| 54 |
|
| 55 |
|
| 56 |
#define CACHE_REFRESHTIME 15.0f //15 seconds refresh time |
| 57 |
|
| 58 |
|
| 59 |
#define MAX_FRAMEROUTINGUPDATES 10 |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
#ifdef ROUTING_DEBUG |
| 80 |
int numareacacheupdates; |
| 81 |
int numportalcacheupdates; |
| 82 |
#endif |
| 83 |
|
| 84 |
int routingcachesize; |
| 85 |
int max_routingcachesize; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
#ifdef ROUTING_DEBUG |
| 94 |
void AAS_RoutingInfo(void) |
| 95 |
{ |
| 96 |
botimport.Print(PRT_MESSAGE, "%d area cache updates\n", numareacacheupdates); |
| 97 |
botimport.Print(PRT_MESSAGE, "%d portal cache updates\n", numportalcacheupdates); |
| 98 |
botimport.Print(PRT_MESSAGE, "%d bytes routing cache\n", routingcachesize); |
| 99 |
} |
| 100 |
#endif |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
static ID_INLINE int AAS_ClusterAreaNum(int cluster, int areanum) |
| 110 |
{ |
| 111 |
int side, areacluster; |
| 112 |
|
| 113 |
areacluster = aasworld.areasettings[areanum].cluster; |
| 114 |
if (areacluster > 0) return aasworld.areasettings[areanum].clusterareanum; |
| 115 |
else |
| 116 |
{ |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
side = aasworld.portals[-areacluster].frontcluster != cluster; |
| 126 |
return aasworld.portals[-areacluster].clusterareanum[side]; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
void AAS_InitTravelFlagFromType(void) |
| 136 |
{ |
| 137 |
int i; |
| 138 |
|
| 139 |
for (i = 0; i < MAX_TRAVELTYPES; i++) |
| 140 |
{ |
| 141 |
aasworld.travelflagfortype[i] = TFL_INVALID; |
| 142 |
} |
| 143 |
aasworld.travelflagfortype[TRAVEL_INVALID] = TFL_INVALID; |
| 144 |
aasworld.travelflagfortype[TRAVEL_WALK] = TFL_WALK; |
| 145 |
aasworld.travelflagfortype[TRAVEL_CROUCH] = TFL_CROUCH; |
| 146 |
aasworld.travelflagfortype[TRAVEL_BARRIERJUMP] = TFL_BARRIERJUMP; |
| 147 |
aasworld.travelflagfortype[TRAVEL_JUMP] = TFL_JUMP; |
| 148 |
aasworld.travelflagfortype[TRAVEL_LADDER] = TFL_LADDER; |
| 149 |
aasworld.travelflagfortype[TRAVEL_WALKOFFLEDGE] = TFL_WALKOFFLEDGE; |
| 150 |
aasworld.travelflagfortype[TRAVEL_SWIM] = TFL_SWIM; |
| 151 |
aasworld.travelflagfortype[TRAVEL_WATERJUMP] = TFL_WATERJUMP; |
| 152 |
aasworld.travelflagfortype[TRAVEL_TELEPORT] = TFL_TELEPORT; |
| 153 |
aasworld.travelflagfortype[TRAVEL_ELEVATOR] = TFL_ELEVATOR; |
| 154 |
aasworld.travelflagfortype[TRAVEL_ROCKETJUMP] = TFL_ROCKETJUMP; |
| 155 |
aasworld.travelflagfortype[TRAVEL_BFGJUMP] = TFL_BFGJUMP; |
| 156 |
aasworld.travelflagfortype[TRAVEL_GRAPPLEHOOK] = TFL_GRAPPLEHOOK; |
| 157 |
aasworld.travelflagfortype[TRAVEL_DOUBLEJUMP] = TFL_DOUBLEJUMP; |
| 158 |
aasworld.travelflagfortype[TRAVEL_RAMPJUMP] = TFL_RAMPJUMP; |
| 159 |
aasworld.travelflagfortype[TRAVEL_STRAFEJUMP] = TFL_STRAFEJUMP; |
| 160 |
aasworld.travelflagfortype[TRAVEL_JUMPPAD] = TFL_JUMPPAD; |
| 161 |
aasworld.travelflagfortype[TRAVEL_FUNCBOB] = TFL_FUNCBOB; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
static ID_INLINE int AAS_TravelFlagForType_inline(int traveltype) |
| 170 |
{ |
| 171 |
int tfl = 0; |
| 172 |
|
| 173 |
if (traveltype & TRAVELFLAG_NOTTEAM1) |
| 174 |
tfl |= TFL_NOTTEAM1; |
| 175 |
if (traveltype & TRAVELFLAG_NOTTEAM2) |
| 176 |
tfl |= TFL_NOTTEAM2; |
| 177 |
traveltype &= TRAVELTYPE_MASK; |
| 178 |
if (traveltype < 0 || traveltype >= MAX_TRAVELTYPES) |
| 179 |
return TFL_INVALID; |
| 180 |
tfl |= aasworld.travelflagfortype[traveltype]; |
| 181 |
return tfl; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
int AAS_TravelFlagForType(int traveltype) |
| 190 |
{ |
| 191 |
return AAS_TravelFlagForType_inline(traveltype); |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
void AAS_UnlinkCache(aas_routingcache_t *cache) |
| 200 |
{ |
| 201 |
if (cache->time_next) cache->time_next->time_prev = cache->time_prev; |
| 202 |
else aasworld.newestcache = cache->time_prev; |
| 203 |
if (cache->time_prev) cache->time_prev->time_next = cache->time_next; |
| 204 |
else aasworld.oldestcache = cache->time_next; |
| 205 |
cache->time_next = NULL; |
| 206 |
cache->time_prev = NULL; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
void AAS_LinkCache(aas_routingcache_t *cache) |
| 215 |
{ |
| 216 |
if (aasworld.newestcache) |
| 217 |
{ |
| 218 |
aasworld.newestcache->time_next = cache; |
| 219 |
cache->time_prev = aasworld.newestcache; |
| 220 |
} |
| 221 |
else |
| 222 |
{ |
| 223 |
aasworld.oldestcache = cache; |
| 224 |
cache->time_prev = NULL; |
| 225 |
} |
| 226 |
cache->time_next = NULL; |
| 227 |
aasworld.newestcache = cache; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
void AAS_FreeRoutingCache(aas_routingcache_t *cache) |
| 236 |
{ |
| 237 |
AAS_UnlinkCache(cache); |
| 238 |
routingcachesize -= cache->size; |
| 239 |
FreeMemory(cache); |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
void AAS_RemoveRoutingCacheInCluster( int clusternum ) |
| 248 |
{ |
| 249 |
int i; |
| 250 |
aas_routingcache_t *cache, *nextcache; |
| 251 |
aas_cluster_t *cluster; |
| 252 |
|
| 253 |
if (!aasworld.clusterareacache) |
| 254 |
return; |
| 255 |
cluster = &aasworld.clusters[clusternum]; |
| 256 |
for (i = 0; i < cluster->numareas; i++) |
| 257 |
{ |
| 258 |
for (cache = aasworld.clusterareacache[clusternum][i]; cache; cache = nextcache) |
| 259 |
{ |
| 260 |
nextcache = cache->next; |
| 261 |
AAS_FreeRoutingCache(cache); |
| 262 |
} |
| 263 |
aasworld.clusterareacache[clusternum][i] = NULL; |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
void AAS_RemoveRoutingCacheUsingArea( int areanum ) |
| 273 |
{ |
| 274 |
int i, clusternum; |
| 275 |
aas_routingcache_t *cache, *nextcache; |
| 276 |
|
| 277 |
clusternum = aasworld.areasettings[areanum].cluster; |
| 278 |
if (clusternum > 0) |
| 279 |
{ |
| 280 |
|
| 281 |
AAS_RemoveRoutingCacheInCluster( clusternum ); |
| 282 |
} |
| 283 |
else |
| 284 |
{ |
| 285 |
|
| 286 |
AAS_RemoveRoutingCacheInCluster( aasworld.portals[-clusternum].frontcluster ); |
| 287 |
AAS_RemoveRoutingCacheInCluster( aasworld.portals[-clusternum].backcluster ); |
| 288 |
} |
| 289 |
|
| 290 |
for (i = 0; i < aasworld.numareas; i++) |
| 291 |
{ |
| 292 |
|
| 293 |
for (cache = aasworld.portalcache[i]; cache; cache = nextcache) |
| 294 |
{ |
| 295 |
nextcache = cache->next; |
| 296 |
AAS_FreeRoutingCache(cache); |
| 297 |
} |
| 298 |
aasworld.portalcache[i] = NULL; |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
int AAS_EnableRoutingArea(int areanum, int enable) |
| 308 |
{ |
| 309 |
int flags; |
| 310 |
|
| 311 |
if (areanum <= 0 || areanum >= aasworld.numareas) |
| 312 |
{ |
| 313 |
if (botDeveloper) |
| 314 |
{ |
| 315 |
botimport.Print(PRT_ERROR, "AAS_EnableRoutingArea: areanum %d out of range\n", areanum); |
| 316 |
} |
| 317 |
return 0; |
| 318 |
} |
| 319 |
flags = aasworld.areasettings[areanum].areaflags & AREA_DISABLED; |
| 320 |
if (enable < 0) |
| 321 |
return !flags; |
| 322 |
|
| 323 |
if (enable) |
| 324 |
aasworld.areasettings[areanum].areaflags &= ~AREA_DISABLED; |
| 325 |
else |
| 326 |
aasworld.areasettings[areanum].areaflags |= AREA_DISABLED; |
| 327 |
|
| 328 |
if ( (flags & AREA_DISABLED) != (aasworld.areasettings[areanum].areaflags & AREA_DISABLED) ) |
| 329 |
{ |
| 330 |
|
| 331 |
AAS_RemoveRoutingCacheUsingArea( areanum ); |
| 332 |
} |
| 333 |
return !flags; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
static ID_INLINE float AAS_RoutingTime(void) |
| 342 |
{ |
| 343 |
return AAS_Time(); |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
int AAS_GetAreaContentsTravelFlags(int areanum) |
| 352 |
{ |
| 353 |
int contents, tfl; |
| 354 |
|
| 355 |
contents = aasworld.areasettings[areanum].contents; |
| 356 |
tfl = 0; |
| 357 |
if (contents & AREACONTENTS_WATER) |
| 358 |
tfl |= TFL_WATER; |
| 359 |
else if (contents & AREACONTENTS_SLIME) |
| 360 |
tfl |= TFL_SLIME; |
| 361 |
else if (contents & AREACONTENTS_LAVA) |
| 362 |
tfl |= TFL_LAVA; |
| 363 |
else |
| 364 |
tfl |= TFL_AIR; |
| 365 |
if (contents & AREACONTENTS_DONOTENTER) |
| 366 |
tfl |= TFL_DONOTENTER; |
| 367 |
if (contents & AREACONTENTS_NOTTEAM1) |
| 368 |
tfl |= TFL_NOTTEAM1; |
| 369 |
if (contents & AREACONTENTS_NOTTEAM2) |
| 370 |
tfl |= TFL_NOTTEAM2; |
| 371 |
if (aasworld.areasettings[areanum].areaflags & AREA_BRIDGE) |
| 372 |
tfl |= TFL_BRIDGE; |
| 373 |
return tfl; |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
static ID_INLINE int AAS_AreaContentsTravelFlags_inline(int areanum) |
| 382 |
{ |
| 383 |
return aasworld.areacontentstravelflags[areanum]; |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
int AAS_AreaContentsTravelFlags(int areanum) |
| 392 |
{ |
| 393 |
return aasworld.areacontentstravelflags[areanum]; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
void AAS_InitAreaContentsTravelFlags(void) |
| 402 |
{ |
| 403 |
int i; |
| 404 |
|
| 405 |
if (aasworld.areacontentstravelflags) FreeMemory(aasworld.areacontentstravelflags); |
| 406 |
aasworld.areacontentstravelflags = (int *) GetClearedMemory(aasworld.numareas * sizeof(int)); |
| 407 |
|
| 408 |
for (i = 0; i < aasworld.numareas; i++) { |
| 409 |
aasworld.areacontentstravelflags[i] = AAS_GetAreaContentsTravelFlags(i); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
void AAS_CreateReversedReachability(void) |
| 419 |
{ |
| 420 |
int i, n; |
| 421 |
aas_reversedlink_t *revlink; |
| 422 |
aas_reachability_t *reach; |
| 423 |
aas_areasettings_t *settings; |
| 424 |
char *ptr; |
| 425 |
#ifdef DEBUG |
| 426 |
int starttime; |
| 427 |
|
| 428 |
starttime = Sys_MilliSeconds(); |
| 429 |
#endif |
| 430 |
|
| 431 |
if (aasworld.reversedreachability) FreeMemory(aasworld.reversedreachability); |
| 432 |
|
| 433 |
ptr = (char *) GetClearedMemory(aasworld.numareas * sizeof(aas_reversedreachability_t) + |
| 434 |
aasworld.reachabilitysize * sizeof(aas_reversedlink_t)); |
| 435 |
|
| 436 |
aasworld.reversedreachability = (aas_reversedreachability_t *) ptr; |
| 437 |
|
| 438 |
ptr += aasworld.numareas * sizeof(aas_reversedreachability_t); |
| 439 |
|
| 440 |
for (i = 1; i < aasworld.numareas; i++) |
| 441 |
{ |
| 442 |
|
| 443 |
settings = &aasworld.areasettings[i]; |
| 444 |
|
| 445 |
if (settings->numreachableareas >= 128) |
| 446 |
botimport.Print(PRT_WARNING, "area %d has more than 128 reachabilities\n", i); |
| 447 |
|
| 448 |
for (n = 0; n < settings->numreachableareas && n < 128; n++) |
| 449 |
{ |
| 450 |
|
| 451 |
reach = &aasworld.reachability[settings->firstreachablearea + n]; |
| 452 |
|
| 453 |
revlink = (aas_reversedlink_t *) ptr; |
| 454 |
ptr += sizeof(aas_reversedlink_t); |
| 455 |
|
| 456 |
revlink->areanum = i; |
| 457 |
revlink->linknum = settings->firstreachablearea + n; |
| 458 |
revlink->next = aasworld.reversedreachability[reach->areanum].first; |
| 459 |
aasworld.reversedreachability[reach->areanum].first = revlink; |
| 460 |
aasworld.reversedreachability[reach->areanum].numlinks++; |
| 461 |
} |
| 462 |
} |
| 463 |
#ifdef DEBUG |
| 464 |
botimport.Print(PRT_MESSAGE, "reversed reachability %d msec\n", Sys_MilliSeconds() - starttime); |
| 465 |
#endif |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
unsigned short int AAS_AreaTravelTime(int areanum, vec3_t start, vec3_t end) |
| 474 |
{ |
| 475 |
int intdist; |
| 476 |
float dist; |
| 477 |
vec3_t dir; |
| 478 |
|
| 479 |
VectorSubtract(start, end, dir); |
| 480 |
dist = VectorLength(dir); |
| 481 |
|
| 482 |
if (AAS_AreaCrouch(areanum)) dist *= DISTANCEFACTOR_CROUCH; |
| 483 |
|
| 484 |
else if (AAS_AreaSwim(areanum)) dist *= DISTANCEFACTOR_SWIM; |
| 485 |
|
| 486 |
else dist *= DISTANCEFACTOR_WALK; |
| 487 |
|
| 488 |
intdist = (int) dist; |
| 489 |
|
| 490 |
if (intdist <= 0) intdist = 1; |
| 491 |
return intdist; |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
void AAS_CalculateAreaTravelTimes(void) |
| 500 |
{ |
| 501 |
int i, l, n, size; |
| 502 |
char *ptr; |
| 503 |
vec3_t end; |
| 504 |
aas_reversedreachability_t *revreach; |
| 505 |
aas_reversedlink_t *revlink; |
| 506 |
aas_reachability_t *reach; |
| 507 |
aas_areasettings_t *settings; |
| 508 |
#ifdef DEBUG |
| 509 |
int starttime; |
| 510 |
|
| 511 |
starttime = Sys_MilliSeconds(); |
| 512 |
#endif |
| 513 |
|
| 514 |
if (aasworld.areatraveltimes) FreeMemory(aasworld.areatraveltimes); |
| 515 |
|
| 516 |
size = aasworld.numareas * sizeof(unsigned short **); |
| 517 |
for (i = 0; i < aasworld.numareas; i++) |
| 518 |
{ |
| 519 |
revreach = &aasworld.reversedreachability[i]; |
| 520 |
|
| 521 |
settings = &aasworld.areasettings[i]; |
| 522 |
|
| 523 |
size += settings->numreachableareas * sizeof(unsigned short *); |
| 524 |
|
| 525 |
size += settings->numreachableareas * |
| 526 |
PAD(revreach->numlinks, sizeof(long)) * sizeof(unsigned short); |
| 527 |
} |
| 528 |
|
| 529 |
ptr = (char *) GetClearedMemory(size); |
| 530 |
aasworld.areatraveltimes = (unsigned short ***) ptr; |
| 531 |
ptr += aasworld.numareas * sizeof(unsigned short **); |
| 532 |
|
| 533 |
for (i = 0; i < aasworld.numareas; i++) |
| 534 |
{ |
| 535 |
|
| 536 |
revreach = &aasworld.reversedreachability[i]; |
| 537 |
|
| 538 |
settings = &aasworld.areasettings[i]; |
| 539 |
|
| 540 |
aasworld.areatraveltimes[i] = (unsigned short **) ptr; |
| 541 |
ptr += settings->numreachableareas * sizeof(unsigned short *); |
| 542 |
|
| 543 |
for (l = 0; l < settings->numreachableareas; l++) |
| 544 |
{ |
| 545 |
aasworld.areatraveltimes[i][l] = (unsigned short *) ptr; |
| 546 |
ptr += PAD(revreach->numlinks, sizeof(long)) * sizeof(unsigned short); |
| 547 |
|
| 548 |
reach = &aasworld.reachability[settings->firstreachablearea + l]; |
| 549 |
|
| 550 |
for (n = 0, revlink = revreach->first; revlink; revlink = revlink->next, n++) |
| 551 |
{ |
| 552 |
VectorCopy(aasworld.reachability[revlink->linknum].end, end); |
| 553 |
|
| 554 |
aasworld.areatraveltimes[i][l][n] = AAS_AreaTravelTime(i, end, reach->start); |
| 555 |
} |
| 556 |
} |
| 557 |
} |
| 558 |
#ifdef DEBUG |
| 559 |
botimport.Print(PRT_MESSAGE, "area travel times %d msec\n", Sys_MilliSeconds() - starttime); |
| 560 |
#endif |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
int AAS_PortalMaxTravelTime(int portalnum) |
| 569 |
{ |
| 570 |
int l, n, t, maxt; |
| 571 |
aas_portal_t *portal; |
| 572 |
aas_reversedreachability_t *revreach; |
| 573 |
aas_reversedlink_t *revlink; |
| 574 |
aas_areasettings_t *settings; |
| 575 |
|
| 576 |
portal = &aasworld.portals[portalnum]; |
| 577 |
|
| 578 |
revreach = &aasworld.reversedreachability[portal->areanum]; |
| 579 |
|
| 580 |
settings = &aasworld.areasettings[portal->areanum]; |
| 581 |
|
| 582 |
maxt = 0; |
| 583 |
for (l = 0; l < settings->numreachableareas; l++) |
| 584 |
{ |
| 585 |
for (n = 0, revlink = revreach->first; revlink; revlink = revlink->next, n++) |
| 586 |
{ |
| 587 |
t = aasworld.areatraveltimes[portal->areanum][l][n]; |
| 588 |
if (t > maxt) |
| 589 |
{ |
| 590 |
maxt = t; |
| 591 |
} |
| 592 |
} |
| 593 |
} |
| 594 |
return maxt; |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
void AAS_InitPortalMaxTravelTimes(void) |
| 603 |
{ |
| 604 |
int i; |
| 605 |
|
| 606 |
if (aasworld.portalmaxtraveltimes) FreeMemory(aasworld.portalmaxtraveltimes); |
| 607 |
|
| 608 |
aasworld.portalmaxtraveltimes = (int *) GetClearedMemory(aasworld.numportals * sizeof(int)); |
| 609 |
|
| 610 |
for (i = 0; i < aasworld.numportals; i++) |
| 611 |
{ |
| 612 |
aasworld.portalmaxtraveltimes[i] = AAS_PortalMaxTravelTime(i); |
| 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 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
int AAS_FreeOldestCache(void) |
| 698 |
{ |
| 699 |
int clusterareanum; |
| 700 |
aas_routingcache_t *cache; |
| 701 |
|
| 702 |
for (cache = aasworld.oldestcache; cache; cache = cache->time_next) { |
| 703 |
|
| 704 |
if (cache->type == CACHETYPE_AREA && aasworld.areasettings[cache->areanum].cluster < 0) { |
| 705 |
continue; |
| 706 |
} |
| 707 |
break; |
| 708 |
} |
| 709 |
if (cache) { |
| 710 |
|
| 711 |
if (cache->type == CACHETYPE_AREA) { |
| 712 |
|
| 713 |
clusterareanum = AAS_ClusterAreaNum(cache->cluster, cache->areanum); |
| 714 |
|
| 715 |
if (cache->prev) cache->prev->next = cache->next; |
| 716 |
else aasworld.clusterareacache[cache->cluster][clusterareanum] = cache->next; |
| 717 |
if (cache->next) cache->next->prev = cache->prev; |
| 718 |
} |
| 719 |
else { |
| 720 |
|
| 721 |
if (cache->prev) cache->prev->next = cache->next; |
| 722 |
else aasworld.portalcache[cache->areanum] = cache->next; |
| 723 |
if (cache->next) cache->next->prev = cache->prev; |
| 724 |
} |
| 725 |
AAS_FreeRoutingCache(cache); |
| 726 |
return qtrue; |
| 727 |
} |
| 728 |
return qfalse; |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
aas_routingcache_t *AAS_AllocRoutingCache(int numtraveltimes) |
| 737 |
{ |
| 738 |
aas_routingcache_t *cache; |
| 739 |
int size; |
| 740 |
|
| 741 |
|
| 742 |
size = sizeof(aas_routingcache_t) |
| 743 |
+ numtraveltimes * sizeof(unsigned short int) |
| 744 |
+ numtraveltimes * sizeof(unsigned char); |
| 745 |
|
| 746 |
routingcachesize += size; |
| 747 |
|
| 748 |
cache = (aas_routingcache_t *) GetClearedMemory(size); |
| 749 |
cache->reachabilities = (unsigned char *) cache + sizeof(aas_routingcache_t) |
| 750 |
+ numtraveltimes * sizeof(unsigned short int); |
| 751 |
cache->size = size; |
| 752 |
return cache; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
void AAS_FreeAllClusterAreaCache(void) |
| 761 |
{ |
| 762 |
int i, j; |
| 763 |
aas_routingcache_t *cache, *nextcache; |
| 764 |
aas_cluster_t *cluster; |
| 765 |
|
| 766 |
|
| 767 |
if (!aasworld.clusterareacache) return; |
| 768 |
|
| 769 |
for (i = 0; i < aasworld.numclusters; i++) |
| 770 |
{ |
| 771 |
cluster = &aasworld.clusters[i]; |
| 772 |
for (j = 0; j < cluster->numareas; j++) |
| 773 |
{ |
| 774 |
for (cache = aasworld.clusterareacache[i][j]; cache; cache = nextcache) |
| 775 |
{ |
| 776 |
nextcache = cache->next; |
| 777 |
AAS_FreeRoutingCache(cache); |
| 778 |
} |
| 779 |
aasworld.clusterareacache[i][j] = NULL; |
| 780 |
} |
| 781 |
} |
| 782 |
|
| 783 |
FreeMemory(aasworld.clusterareacache); |
| 784 |
aasworld.clusterareacache = NULL; |
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
void AAS_InitClusterAreaCache(void) |
| 793 |
{ |
| 794 |
int i, size; |
| 795 |
char *ptr; |
| 796 |
|
| 797 |
|
| 798 |
for (size = 0, i = 0; i < aasworld.numclusters; i++) |
| 799 |
{ |
| 800 |
size += aasworld.clusters[i].numareas; |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
ptr = (char *) GetClearedMemory( |
| 805 |
aasworld.numclusters * sizeof(aas_routingcache_t **) + |
| 806 |
size * sizeof(aas_routingcache_t *)); |
| 807 |
aasworld.clusterareacache = (aas_routingcache_t ***) ptr; |
| 808 |
ptr += aasworld.numclusters * sizeof(aas_routingcache_t **); |
| 809 |
for (i = 0; i < aasworld.numclusters; i++) |
| 810 |
{ |
| 811 |
aasworld.clusterareacache[i] = (aas_routingcache_t **) ptr; |
| 812 |
ptr += aasworld.clusters[i].numareas * sizeof(aas_routingcache_t *); |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
void AAS_FreeAllPortalCache(void) |
| 822 |
{ |
| 823 |
int i; |
| 824 |
aas_routingcache_t *cache, *nextcache; |
| 825 |
|
| 826 |
|
| 827 |
if (!aasworld.portalcache) return; |
| 828 |
|
| 829 |
for (i = 0; i < aasworld.numareas; i++) |
| 830 |
{ |
| 831 |
for (cache = aasworld.portalcache[i]; cache; cache = nextcache) |
| 832 |
{ |
| 833 |
nextcache = cache->next; |
| 834 |
AAS_FreeRoutingCache(cache); |
| 835 |
} |
| 836 |
aasworld.portalcache[i] = NULL; |
| 837 |
} |
| 838 |
FreeMemory(aasworld.portalcache); |
| 839 |
aasworld.portalcache = NULL; |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
void AAS_InitPortalCache(void) |
| 848 |
{ |
| 849 |
|
| 850 |
aasworld.portalcache = (aas_routingcache_t **) GetClearedMemory( |
| 851 |
aasworld.numareas * sizeof(aas_routingcache_t *)); |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
void AAS_InitRoutingUpdate(void) |
| 860 |
{ |
| 861 |
int i, maxreachabilityareas; |
| 862 |
|
| 863 |
|
| 864 |
if (aasworld.areaupdate) FreeMemory(aasworld.areaupdate); |
| 865 |
|
| 866 |
maxreachabilityareas = 0; |
| 867 |
for (i = 0; i < aasworld.numclusters; i++) |
| 868 |
{ |
| 869 |
if (aasworld.clusters[i].numreachabilityareas > maxreachabilityareas) |
| 870 |
{ |
| 871 |
maxreachabilityareas = aasworld.clusters[i].numreachabilityareas; |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
aasworld.areaupdate = (aas_routingupdate_t *) GetClearedMemory( |
| 876 |
maxreachabilityareas * sizeof(aas_routingupdate_t)); |
| 877 |
|
| 878 |
if (aasworld.portalupdate) FreeMemory(aasworld.portalupdate); |
| 879 |
|
| 880 |
aasworld.portalupdate = (aas_routingupdate_t *) GetClearedMemory( |
| 881 |
(aasworld.numportals+1) * sizeof(aas_routingupdate_t)); |
| 882 |
} |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
void AAS_CreateAllRoutingCache(void) |
| 890 |
{ |
| 891 |
int i, j; |
| 892 |
|
| 893 |
|
| 894 |
aasworld.initialized = qtrue; |
| 895 |
botimport.Print(PRT_MESSAGE, "AAS_CreateAllRoutingCache\n"); |
| 896 |
for (i = 1; i < aasworld.numareas; i++) |
| 897 |
{ |
| 898 |
if (!AAS_AreaReachability(i)) continue; |
| 899 |
for (j = 1; j < aasworld.numareas; j++) |
| 900 |
{ |
| 901 |
if (i == j) continue; |
| 902 |
if (!AAS_AreaReachability(j)) continue; |
| 903 |
AAS_AreaTravelTimeToGoalArea(i, aasworld.areas[i].center, j, TFL_DEFAULT); |
| 904 |
|
| 905 |
|
| 906 |
} |
| 907 |
} |
| 908 |
aasworld.initialized = qfalse; |
| 909 |
} |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
typedef struct routecacheheader_s |
| 921 |
{ |
| 922 |
int ident; |
| 923 |
int version; |
| 924 |
int numareas; |
| 925 |
int numclusters; |
| 926 |
int areacrc; |
| 927 |
int clustercrc; |
| 928 |
int numportalcache; |
| 929 |
int numareacache; |
| 930 |
} routecacheheader_t; |
| 931 |
|
| 932 |
#define RCID (('C'<<24)+('R'<<16)+('E'<<8)+'M') |
| 933 |
#define RCVERSION 2 |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
void AAS_WriteRouteCache(void) |
| 939 |
{ |
| 940 |
int i, j, numportalcache, numareacache, totalsize; |
| 941 |
aas_routingcache_t *cache; |
| 942 |
aas_cluster_t *cluster; |
| 943 |
fileHandle_t fp; |
| 944 |
char filename[MAX_QPATH]; |
| 945 |
routecacheheader_t routecacheheader; |
| 946 |
|
| 947 |
numportalcache = 0; |
| 948 |
for (i = 0; i < aasworld.numareas; i++) |
| 949 |
{ |
| 950 |
for (cache = aasworld.portalcache[i]; cache; cache = cache->next) |
| 951 |
{ |
| 952 |
numportalcache++; |
| 953 |
} |
| 954 |
} |
| 955 |
numareacache = 0; |
| 956 |
for (i = 0; i < aasworld.numclusters; i++) |
| 957 |
{ |
| 958 |
cluster = &aasworld.clusters[i]; |
| 959 |
for (j = 0; j < cluster->numareas; j++) |
| 960 |
{ |
| 961 |
for (cache = aasworld.clusterareacache[i][j]; cache; cache = cache->next) |
| 962 |
{ |
| 963 |
numareacache++; |
| 964 |
} |
| 965 |
} |
| 966 |
} |
| 967 |
|
| 968 |
Com_sprintf(filename, MAX_QPATH, "maps/%s.rcd", aasworld.mapname); |
| 969 |
botimport.FS_FOpenFile( filename, &fp, FS_WRITE ); |
| 970 |
if (!fp) |
| 971 |
{ |
| 972 |
AAS_Error("Unable to open file: %s\n", filename); |
| 973 |
return; |
| 974 |
} |
| 975 |
|
| 976 |
routecacheheader.ident = RCID; |
| 977 |
routecacheheader.version = RCVERSION; |
| 978 |
routecacheheader.numareas = aasworld.numareas; |
| 979 |
routecacheheader.numclusters = aasworld.numclusters; |
| 980 |
routecacheheader.areacrc = CRC_ProcessString( (unsigned char *)aasworld.areas, sizeof(aas_area_t) * aasworld.numareas ); |
| 981 |
routecacheheader.clustercrc = CRC_ProcessString( (unsigned char *)aasworld.clusters, sizeof(aas_cluster_t) * aasworld.numclusters ); |
| 982 |
routecacheheader.numportalcache = numportalcache; |
| 983 |
routecacheheader.numareacache = numareacache; |
| 984 |
|
| 985 |
botimport.FS_Write(&routecacheheader, sizeof(routecacheheader_t), fp); |
| 986 |
|
| 987 |
totalsize = 0; |
| 988 |
|
| 989 |
for (i = 0; i < aasworld.numareas; i++) |
| 990 |
{ |
| 991 |
for (cache = aasworld.portalcache[i]; cache; cache = cache->next) |
| 992 |
{ |
| 993 |
botimport.FS_Write(cache, cache->size, fp); |
| 994 |
totalsize += cache->size; |
| 995 |
} |
| 996 |
} |
| 997 |
for (i = 0; i < aasworld.numclusters; i++) |
| 998 |
{ |
| 999 |
cluster = &aasworld.clusters[i]; |
| 1000 |
for (j = 0; j < cluster->numareas; j++) |
| 1001 |
{ |
| 1002 |
for (cache = aasworld.clusterareacache[i][j]; cache; cache = cache->next) |
| 1003 |
{ |
| 1004 |
botimport.FS_Write(cache, cache->size, fp); |
| 1005 |
totalsize += cache->size; |
| 1006 |
} |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
botimport.FS_FCloseFile(fp); |
| 1026 |
botimport.Print(PRT_MESSAGE, "\nroute cache written to %s\n", filename); |
| 1027 |
botimport.Print(PRT_MESSAGE, "written %d bytes of routing cache\n", totalsize); |
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
aas_routingcache_t *AAS_ReadCache(fileHandle_t fp) |
| 1036 |
{ |
| 1037 |
int size; |
| 1038 |
aas_routingcache_t *cache; |
| 1039 |
|
| 1040 |
botimport.FS_Read(&size, sizeof(size), fp); |
| 1041 |
cache = (aas_routingcache_t *) GetMemory(size); |
| 1042 |
cache->size = size; |
| 1043 |
botimport.FS_Read((unsigned char *)cache + sizeof(size), size - sizeof(size), fp); |
| 1044 |
cache->reachabilities = (unsigned char *) cache + sizeof(aas_routingcache_t) - sizeof(unsigned short) + |
| 1045 |
(size - sizeof(aas_routingcache_t) + sizeof(unsigned short)) / 3 * 2; |
| 1046 |
return cache; |
| 1047 |
} |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
int AAS_ReadRouteCache(void) |
| 1055 |
{ |
| 1056 |
int i, clusterareanum; |
| 1057 |
fileHandle_t fp; |
| 1058 |
char filename[MAX_QPATH]; |
| 1059 |
routecacheheader_t routecacheheader; |
| 1060 |
aas_routingcache_t *cache; |
| 1061 |
|
| 1062 |
Com_sprintf(filename, MAX_QPATH, "maps/%s.rcd", aasworld.mapname); |
| 1063 |
botimport.FS_FOpenFile( filename, &fp, FS_READ ); |
| 1064 |
if (!fp) |
| 1065 |
{ |
| 1066 |
return qfalse; |
| 1067 |
} |
| 1068 |
botimport.FS_Read(&routecacheheader, sizeof(routecacheheader_t), fp ); |
| 1069 |
if (routecacheheader.ident != RCID) |
| 1070 |
{ |
| 1071 |
AAS_Error("%s is not a route cache dump\n", filename); |
| 1072 |
return qfalse; |
| 1073 |
} |
| 1074 |
if (routecacheheader.version != RCVERSION) |
| 1075 |
{ |
| 1076 |
AAS_Error("route cache dump has wrong version %d, should be %d\n", routecacheheader.version, RCVERSION); |
| 1077 |
return qfalse; |
| 1078 |
} |
| 1079 |
if (routecacheheader.numareas != aasworld.numareas) |
| 1080 |
{ |
| 1081 |
|
| 1082 |
return qfalse; |
| 1083 |
} |
| 1084 |
if (routecacheheader.numclusters != aasworld.numclusters) |
| 1085 |
{ |
| 1086 |
|
| 1087 |
return qfalse; |
| 1088 |
} |
| 1089 |
if (routecacheheader.areacrc != |
| 1090 |
CRC_ProcessString( (unsigned char *)aasworld.areas, sizeof(aas_area_t) * aasworld.numareas )) |
| 1091 |
{ |
| 1092 |
|
| 1093 |
return qfalse; |
| 1094 |
} |
| 1095 |
if (routecacheheader.clustercrc != |
| 1096 |
CRC_ProcessString( (unsigned char *)aasworld.clusters, sizeof(aas_cluster_t) * aasworld.numclusters )) |
| 1097 |
{ |
| 1098 |
|
| 1099 |
return qfalse; |
| 1100 |
} |
| 1101 |
|
| 1102 |
for (i = 0; i < routecacheheader.numportalcache; i++) |
| 1103 |
{ |
| 1104 |
cache = AAS_ReadCache(fp); |
| 1105 |
cache->next = aasworld.portalcache[cache->areanum]; |
| 1106 |
cache->prev = NULL; |
| 1107 |
if (aasworld.portalcache[cache->areanum]) |
| 1108 |
aasworld.portalcache[cache->areanum]->prev = cache; |
| 1109 |
aasworld.portalcache[cache->areanum] = cache; |
| 1110 |
} |
| 1111 |
|
| 1112 |
for (i = 0; i < routecacheheader.numareacache; i++) |
| 1113 |
{ |
| 1114 |
cache = AAS_ReadCache(fp); |
| 1115 |
clusterareanum = AAS_ClusterAreaNum(cache->cluster, cache->areanum); |
| 1116 |
cache->next = aasworld.clusterareacache[cache->cluster][clusterareanum]; |
| 1117 |
cache->prev = NULL; |
| 1118 |
if (aasworld.clusterareacache[cache->cluster][clusterareanum]) |
| 1119 |
aasworld.clusterareacache[cache->cluster][clusterareanum]->prev = cache; |
| 1120 |
aasworld.clusterareacache[cache->cluster][clusterareanum] = cache; |
| 1121 |
} |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
botimport.FS_FCloseFile(fp); |
| 1137 |
return qtrue; |
| 1138 |
} |
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
#define MAX_REACHABILITYPASSAREAS 32 |
| 1146 |
|
| 1147 |
void AAS_InitReachabilityAreas(void) |
| 1148 |
{ |
| 1149 |
int i, j, numareas, areas[MAX_REACHABILITYPASSAREAS]; |
| 1150 |
int numreachareas; |
| 1151 |
aas_reachability_t *reach; |
| 1152 |
vec3_t start, end; |
| 1153 |
|
| 1154 |
if (aasworld.reachabilityareas) |
| 1155 |
FreeMemory(aasworld.reachabilityareas); |
| 1156 |
if (aasworld.reachabilityareaindex) |
| 1157 |
FreeMemory(aasworld.reachabilityareaindex); |
| 1158 |
|
| 1159 |
aasworld.reachabilityareas = (aas_reachabilityareas_t *) |
| 1160 |
GetClearedMemory(aasworld.reachabilitysize * sizeof(aas_reachabilityareas_t)); |
| 1161 |
aasworld.reachabilityareaindex = (int *) |
| 1162 |
GetClearedMemory(aasworld.reachabilitysize * MAX_REACHABILITYPASSAREAS * sizeof(int)); |
| 1163 |
numreachareas = 0; |
| 1164 |
for (i = 0; i < aasworld.reachabilitysize; i++) |
| 1165 |
{ |
| 1166 |
reach = &aasworld.reachability[i]; |
| 1167 |
numareas = 0; |
| 1168 |
switch(reach->traveltype & TRAVELTYPE_MASK) |
| 1169 |
{ |
| 1170 |
|
| 1171 |
case TRAVEL_BARRIERJUMP: |
| 1172 |
case TRAVEL_WATERJUMP: |
| 1173 |
VectorCopy(reach->start, end); |
| 1174 |
end[2] = reach->end[2]; |
| 1175 |
numareas = AAS_TraceAreas(reach->start, end, areas, NULL, MAX_REACHABILITYPASSAREAS); |
| 1176 |
break; |
| 1177 |
case TRAVEL_WALKOFFLEDGE: |
| 1178 |
VectorCopy(reach->end, start); |
| 1179 |
start[2] = reach->start[2]; |
| 1180 |
numareas = AAS_TraceAreas(start, reach->end, areas, NULL, MAX_REACHABILITYPASSAREAS); |
| 1181 |
break; |
| 1182 |
case TRAVEL_GRAPPLEHOOK: |
| 1183 |
numareas = AAS_TraceAreas(reach->start, reach->end, areas, NULL, MAX_REACHABILITYPASSAREAS); |
| 1184 |
break; |
| 1185 |
|
| 1186 |
|
| 1187 |
case TRAVEL_JUMP: break; |
| 1188 |
case TRAVEL_ROCKETJUMP: break; |
| 1189 |
case TRAVEL_BFGJUMP: break; |
| 1190 |
case TRAVEL_JUMPPAD: break; |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
case TRAVEL_ELEVATOR: break; |
| 1195 |
case TRAVEL_FUNCBOB: break; |
| 1196 |
|
| 1197 |
|
| 1198 |
case TRAVEL_WALK: break; |
| 1199 |
case TRAVEL_CROUCH: break; |
| 1200 |
case TRAVEL_LADDER: break; |
| 1201 |
case TRAVEL_SWIM: break; |
| 1202 |
case TRAVEL_TELEPORT: break; |
| 1203 |
default: break; |
| 1204 |
} |
| 1205 |
aasworld.reachabilityareas[i].firstarea = numreachareas; |
| 1206 |
aasworld.reachabilityareas[i].numareas = numareas; |
| 1207 |
for (j = 0; j < numareas; j++) |
| 1208 |
{ |
| 1209 |
aasworld.reachabilityareaindex[numreachareas++] = areas[j]; |
| 1210 |
} |
| 1211 |
} |
| 1212 |
} |
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
void AAS_InitRouting(void) |
| 1220 |
{ |
| 1221 |
AAS_InitTravelFlagFromType(); |
| 1222 |
|
| 1223 |
AAS_InitAreaContentsTravelFlags(); |
| 1224 |
|
| 1225 |
AAS_InitRoutingUpdate(); |
| 1226 |
|
| 1227 |
AAS_CreateReversedReachability(); |
| 1228 |
|
| 1229 |
AAS_InitClusterAreaCache(); |
| 1230 |
|
| 1231 |
AAS_InitPortalCache(); |
| 1232 |
|
| 1233 |
AAS_CalculateAreaTravelTimes(); |
| 1234 |
|
| 1235 |
AAS_InitPortalMaxTravelTimes(); |
| 1236 |
|
| 1237 |
AAS_InitReachabilityAreas(); |
| 1238 |
|
| 1239 |
#ifdef ROUTING_DEBUG |
| 1240 |
numareacacheupdates = 0; |
| 1241 |
numportalcacheupdates = 0; |
| 1242 |
#endif |
| 1243 |
|
| 1244 |
routingcachesize = 0; |
| 1245 |
max_routingcachesize = 1024 * (int) LibVarValue("max_routingcache", "4096"); |
| 1246 |
|
| 1247 |
AAS_ReadRouteCache(); |
| 1248 |
} |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
void AAS_FreeRoutingCaches(void) |
| 1256 |
{ |
| 1257 |
|
| 1258 |
AAS_FreeAllClusterAreaCache(); |
| 1259 |
|
| 1260 |
AAS_FreeAllPortalCache(); |
| 1261 |
|
| 1262 |
if (aasworld.areatraveltimes) FreeMemory(aasworld.areatraveltimes); |
| 1263 |
aasworld.areatraveltimes = NULL; |
| 1264 |
|
| 1265 |
if (aasworld.portalmaxtraveltimes) FreeMemory(aasworld.portalmaxtraveltimes); |
| 1266 |
aasworld.portalmaxtraveltimes = NULL; |
| 1267 |
|
| 1268 |
if (aasworld.reversedreachability) FreeMemory(aasworld.reversedreachability); |
| 1269 |
aasworld.reversedreachability = NULL; |
| 1270 |
|
| 1271 |
if (aasworld.areaupdate) FreeMemory(aasworld.areaupdate); |
| 1272 |
aasworld.areaupdate = NULL; |
| 1273 |
if (aasworld.portalupdate) FreeMemory(aasworld.portalupdate); |
| 1274 |
aasworld.portalupdate = NULL; |
| 1275 |
|
| 1276 |
if (aasworld.reachabilityareas) FreeMemory(aasworld.reachabilityareas); |
| 1277 |
aasworld.reachabilityareas = NULL; |
| 1278 |
|
| 1279 |
if (aasworld.reachabilityareaindex) FreeMemory(aasworld.reachabilityareaindex); |
| 1280 |
aasworld.reachabilityareaindex = NULL; |
| 1281 |
|
| 1282 |
if (aasworld.areacontentstravelflags) FreeMemory(aasworld.areacontentstravelflags); |
| 1283 |
aasworld.areacontentstravelflags = NULL; |
| 1284 |
} |
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
void AAS_UpdateAreaRoutingCache(aas_routingcache_t *areacache) |
| 1293 |
{ |
| 1294 |
int i, nextareanum, cluster, badtravelflags, clusterareanum, linknum; |
| 1295 |
int numreachabilityareas; |
| 1296 |
unsigned short int t, startareatraveltimes[128]; |
| 1297 |
aas_routingupdate_t *updateliststart, *updatelistend, *curupdate, *nextupdate; |
| 1298 |
aas_reachability_t *reach; |
| 1299 |
aas_reversedreachability_t *revreach; |
| 1300 |
aas_reversedlink_t *revlink; |
| 1301 |
|
| 1302 |
#ifdef ROUTING_DEBUG |
| 1303 |
numareacacheupdates++; |
| 1304 |
#endif |
| 1305 |
|
| 1306 |
numreachabilityareas = aasworld.clusters[areacache->cluster].numreachabilityareas; |
| 1307 |
|
| 1308 |
aasworld.frameroutingupdates++; |
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
badtravelflags = ~areacache->travelflags; |
| 1313 |
|
| 1314 |
clusterareanum = AAS_ClusterAreaNum(areacache->cluster, areacache->areanum); |
| 1315 |
if (clusterareanum >= numreachabilityareas) return; |
| 1316 |
|
| 1317 |
Com_Memset(startareatraveltimes, 0, sizeof(startareatraveltimes)); |
| 1318 |
|
| 1319 |
curupdate = &aasworld.areaupdate[clusterareanum]; |
| 1320 |
curupdate->areanum = areacache->areanum; |
| 1321 |
|
| 1322 |
curupdate->areatraveltimes = startareatraveltimes; |
| 1323 |
curupdate->tmptraveltime = areacache->starttraveltime; |
| 1324 |
|
| 1325 |
areacache->traveltimes[clusterareanum] = areacache->starttraveltime; |
| 1326 |
|
| 1327 |
curupdate->next = NULL; |
| 1328 |
curupdate->prev = NULL; |
| 1329 |
updateliststart = curupdate; |
| 1330 |
updatelistend = curupdate; |
| 1331 |
|
| 1332 |
while (updateliststart) |
| 1333 |
{ |
| 1334 |
curupdate = updateliststart; |
| 1335 |
|
| 1336 |
if (curupdate->next) curupdate->next->prev = NULL; |
| 1337 |
else updatelistend = NULL; |
| 1338 |
updateliststart = curupdate->next; |
| 1339 |
|
| 1340 |
curupdate->inlist = qfalse; |
| 1341 |
|
| 1342 |
revreach = &aasworld.reversedreachability[curupdate->areanum]; |
| 1343 |
|
| 1344 |
for (i = 0, revlink = revreach->first; revlink; revlink = revlink->next, i++) |
| 1345 |
{ |
| 1346 |
linknum = revlink->linknum; |
| 1347 |
reach = &aasworld.reachability[linknum]; |
| 1348 |
|
| 1349 |
if (AAS_TravelFlagForType_inline(reach->traveltype) & badtravelflags) continue; |
| 1350 |
|
| 1351 |
if (aasworld.areasettings[reach->areanum].areaflags & AREA_DISABLED) continue; |
| 1352 |
|
| 1353 |
if (AAS_AreaContentsTravelFlags_inline(reach->areanum) & badtravelflags) continue; |
| 1354 |
|
| 1355 |
nextareanum = revlink->areanum; |
| 1356 |
|
| 1357 |
cluster = aasworld.areasettings[nextareanum].cluster; |
| 1358 |
|
| 1359 |
if (cluster > 0 && cluster != areacache->cluster) continue; |
| 1360 |
|
| 1361 |
clusterareanum = AAS_ClusterAreaNum(areacache->cluster, nextareanum); |
| 1362 |
if (clusterareanum >= numreachabilityareas) continue; |
| 1363 |
|
| 1364 |
|
| 1365 |
t = curupdate->tmptraveltime + |
| 1366 |
|
| 1367 |
curupdate->areatraveltimes[i] + |
| 1368 |
reach->traveltime; |
| 1369 |
|
| 1370 |
if (!areacache->traveltimes[clusterareanum] || |
| 1371 |
areacache->traveltimes[clusterareanum] > t) |
| 1372 |
{ |
| 1373 |
areacache->traveltimes[clusterareanum] = t; |
| 1374 |
areacache->reachabilities[clusterareanum] = linknum - aasworld.areasettings[nextareanum].firstreachablearea; |
| 1375 |
nextupdate = &aasworld.areaupdate[clusterareanum]; |
| 1376 |
nextupdate->areanum = nextareanum; |
| 1377 |
nextupdate->tmptraveltime = t; |
| 1378 |
|
| 1379 |
nextupdate->areatraveltimes = aasworld.areatraveltimes[nextareanum][linknum - |
| 1380 |
aasworld.areasettings[nextareanum].firstreachablearea]; |
| 1381 |
if (!nextupdate->inlist) |
| 1382 |
{ |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
nextupdate->next = NULL; |
| 1387 |
nextupdate->prev = updatelistend; |
| 1388 |
if (updatelistend) updatelistend->next = nextupdate; |
| 1389 |
else updateliststart = nextupdate; |
| 1390 |
updatelistend = nextupdate; |
| 1391 |
nextupdate->inlist = qtrue; |
| 1392 |
} |
| 1393 |
} |
| 1394 |
} |
| 1395 |
} |
| 1396 |
} |
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
aas_routingcache_t *AAS_GetAreaRoutingCache(int clusternum, int areanum, int travelflags) |
| 1404 |
{ |
| 1405 |
int clusterareanum; |
| 1406 |
aas_routingcache_t *cache, *clustercache; |
| 1407 |
|
| 1408 |
|
| 1409 |
clusterareanum = AAS_ClusterAreaNum(clusternum, areanum); |
| 1410 |
|
| 1411 |
clustercache = aasworld.clusterareacache[clusternum][clusterareanum]; |
| 1412 |
|
| 1413 |
for (cache = clustercache; cache; cache = cache->next) |
| 1414 |
{ |
| 1415 |
|
| 1416 |
if (cache->travelflags == travelflags) break; |
| 1417 |
} |
| 1418 |
|
| 1419 |
if (!cache) |
| 1420 |
{ |
| 1421 |
cache = AAS_AllocRoutingCache(aasworld.clusters[clusternum].numreachabilityareas); |
| 1422 |
cache->cluster = clusternum; |
| 1423 |
cache->areanum = areanum; |
| 1424 |
VectorCopy(aasworld.areas[areanum].center, cache->origin); |
| 1425 |
cache->starttraveltime = 1; |
| 1426 |
cache->travelflags = travelflags; |
| 1427 |
cache->prev = NULL; |
| 1428 |
cache->next = clustercache; |
| 1429 |
if (clustercache) clustercache->prev = cache; |
| 1430 |
aasworld.clusterareacache[clusternum][clusterareanum] = cache; |
| 1431 |
AAS_UpdateAreaRoutingCache(cache); |
| 1432 |
} |
| 1433 |
else |
| 1434 |
{ |
| 1435 |
AAS_UnlinkCache(cache); |
| 1436 |
} |
| 1437 |
|
| 1438 |
cache->time = AAS_RoutingTime(); |
| 1439 |
cache->type = CACHETYPE_AREA; |
| 1440 |
AAS_LinkCache(cache); |
| 1441 |
return cache; |
| 1442 |
} |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
void AAS_UpdatePortalRoutingCache(aas_routingcache_t *portalcache) |
| 1450 |
{ |
| 1451 |
int i, portalnum, clusterareanum, clusternum; |
| 1452 |
unsigned short int t; |
| 1453 |
aas_portal_t *portal; |
| 1454 |
aas_cluster_t *cluster; |
| 1455 |
aas_routingcache_t *cache; |
| 1456 |
aas_routingupdate_t *updateliststart, *updatelistend, *curupdate, *nextupdate; |
| 1457 |
|
| 1458 |
#ifdef ROUTING_DEBUG |
| 1459 |
numportalcacheupdates++; |
| 1460 |
#endif |
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
curupdate = &aasworld.portalupdate[aasworld.numportals]; |
| 1465 |
curupdate->cluster = portalcache->cluster; |
| 1466 |
curupdate->areanum = portalcache->areanum; |
| 1467 |
curupdate->tmptraveltime = portalcache->starttraveltime; |
| 1468 |
|
| 1469 |
clusternum = aasworld.areasettings[portalcache->areanum].cluster; |
| 1470 |
if (clusternum < 0) |
| 1471 |
{ |
| 1472 |
portalcache->traveltimes[-clusternum] = portalcache->starttraveltime; |
| 1473 |
} |
| 1474 |
|
| 1475 |
curupdate->next = NULL; |
| 1476 |
curupdate->prev = NULL; |
| 1477 |
updateliststart = curupdate; |
| 1478 |
updatelistend = curupdate; |
| 1479 |
|
| 1480 |
while (updateliststart) |
| 1481 |
{ |
| 1482 |
curupdate = updateliststart; |
| 1483 |
|
| 1484 |
if (curupdate->next) curupdate->next->prev = NULL; |
| 1485 |
else updatelistend = NULL; |
| 1486 |
updateliststart = curupdate->next; |
| 1487 |
|
| 1488 |
curupdate->inlist = qfalse; |
| 1489 |
|
| 1490 |
cluster = &aasworld.clusters[curupdate->cluster]; |
| 1491 |
|
| 1492 |
cache = AAS_GetAreaRoutingCache(curupdate->cluster, |
| 1493 |
curupdate->areanum, portalcache->travelflags); |
| 1494 |
|
| 1495 |
for (i = 0; i < cluster->numportals; i++) |
| 1496 |
{ |
| 1497 |
portalnum = aasworld.portalindex[cluster->firstportal + i]; |
| 1498 |
portal = &aasworld.portals[portalnum]; |
| 1499 |
|
| 1500 |
if (portal->areanum == curupdate->areanum) continue; |
| 1501 |
|
| 1502 |
clusterareanum = AAS_ClusterAreaNum(curupdate->cluster, portal->areanum); |
| 1503 |
if (clusterareanum >= cluster->numreachabilityareas) continue; |
| 1504 |
|
| 1505 |
t = cache->traveltimes[clusterareanum]; |
| 1506 |
if (!t) continue; |
| 1507 |
t += curupdate->tmptraveltime; |
| 1508 |
|
| 1509 |
if (!portalcache->traveltimes[portalnum] || |
| 1510 |
portalcache->traveltimes[portalnum] > t) |
| 1511 |
{ |
| 1512 |
portalcache->traveltimes[portalnum] = t; |
| 1513 |
nextupdate = &aasworld.portalupdate[portalnum]; |
| 1514 |
if (portal->frontcluster == curupdate->cluster) |
| 1515 |
{ |
| 1516 |
nextupdate->cluster = portal->backcluster; |
| 1517 |
} |
| 1518 |
else |
| 1519 |
{ |
| 1520 |
nextupdate->cluster = portal->frontcluster; |
| 1521 |
} |
| 1522 |
nextupdate->areanum = portal->areanum; |
| 1523 |
|
| 1524 |
nextupdate->tmptraveltime = t + aasworld.portalmaxtraveltimes[portalnum]; |
| 1525 |
if (!nextupdate->inlist) |
| 1526 |
{ |
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
nextupdate->next = NULL; |
| 1531 |
nextupdate->prev = updatelistend; |
| 1532 |
if (updatelistend) updatelistend->next = nextupdate; |
| 1533 |
else updateliststart = nextupdate; |
| 1534 |
updatelistend = nextupdate; |
| 1535 |
nextupdate->inlist = qtrue; |
| 1536 |
} |
| 1537 |
} |
| 1538 |
} |
| 1539 |
} |
| 1540 |
} |
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
aas_routingcache_t *AAS_GetPortalRoutingCache(int clusternum, int areanum, int travelflags) |
| 1548 |
{ |
| 1549 |
aas_routingcache_t *cache; |
| 1550 |
|
| 1551 |
|
| 1552 |
for (cache = aasworld.portalcache[areanum]; cache; cache = cache->next) |
| 1553 |
{ |
| 1554 |
if (cache->travelflags == travelflags) break; |
| 1555 |
} |
| 1556 |
|
| 1557 |
if (!cache) |
| 1558 |
{ |
| 1559 |
cache = AAS_AllocRoutingCache(aasworld.numportals); |
| 1560 |
cache->cluster = clusternum; |
| 1561 |
cache->areanum = areanum; |
| 1562 |
VectorCopy(aasworld.areas[areanum].center, cache->origin); |
| 1563 |
cache->starttraveltime = 1; |
| 1564 |
cache->travelflags = travelflags; |
| 1565 |
|
| 1566 |
cache->prev = NULL; |
| 1567 |
cache->next = aasworld.portalcache[areanum]; |
| 1568 |
if (aasworld.portalcache[areanum]) aasworld.portalcache[areanum]->prev = cache; |
| 1569 |
aasworld.portalcache[areanum] = cache; |
| 1570 |
|
| 1571 |
AAS_UpdatePortalRoutingCache(cache); |
| 1572 |
} |
| 1573 |
else |
| 1574 |
{ |
| 1575 |
AAS_UnlinkCache(cache); |
| 1576 |
} |
| 1577 |
|
| 1578 |
cache->time = AAS_RoutingTime(); |
| 1579 |
cache->type = CACHETYPE_PORTAL; |
| 1580 |
AAS_LinkCache(cache); |
| 1581 |
return cache; |
| 1582 |
} |
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
int AAS_AreaRouteToGoalArea(int areanum, vec3_t origin, int goalareanum, int travelflags, int *traveltime, int *reachnum) |
| 1590 |
{ |
| 1591 |
int clusternum, goalclusternum, portalnum, i, clusterareanum, bestreachnum; |
| 1592 |
unsigned short int t, besttime; |
| 1593 |
aas_portal_t *portal; |
| 1594 |
aas_cluster_t *cluster; |
| 1595 |
aas_routingcache_t *areacache, *portalcache; |
| 1596 |
aas_reachability_t *reach; |
| 1597 |
|
| 1598 |
if (!aasworld.initialized) return qfalse; |
| 1599 |
|
| 1600 |
if (areanum == goalareanum) |
| 1601 |
{ |
| 1602 |
*traveltime = 1; |
| 1603 |
*reachnum = 0; |
| 1604 |
return qtrue; |
| 1605 |
} |
| 1606 |
|
| 1607 |
if (areanum <= 0 || areanum >= aasworld.numareas) |
| 1608 |
{ |
| 1609 |
if (botDeveloper) |
| 1610 |
{ |
| 1611 |
botimport.Print(PRT_ERROR, "AAS_AreaTravelTimeToGoalArea: areanum %d out of range\n", areanum); |
| 1612 |
} |
| 1613 |
return qfalse; |
| 1614 |
} |
| 1615 |
if (goalareanum <= 0 || goalareanum >= aasworld.numareas) |
| 1616 |
{ |
| 1617 |
if (botDeveloper) |
| 1618 |
{ |
| 1619 |
botimport.Print(PRT_ERROR, "AAS_AreaTravelTimeToGoalArea: goalareanum %d out of range\n", goalareanum); |
| 1620 |
} |
| 1621 |
return qfalse; |
| 1622 |
} |
| 1623 |
if (!aasworld.areasettings[areanum].numreachableareas || !aasworld.areasettings[goalareanum].numreachableareas) |
| 1624 |
{ |
| 1625 |
return qfalse; |
| 1626 |
} |
| 1627 |
|
| 1628 |
while(AvailableMemory() < 1 * 1024 * 1024) { |
| 1629 |
if (!AAS_FreeOldestCache()) break; |
| 1630 |
} |
| 1631 |
|
| 1632 |
if (AAS_AreaDoNotEnter(areanum) || AAS_AreaDoNotEnter(goalareanum)) |
| 1633 |
{ |
| 1634 |
travelflags |= TFL_DONOTENTER; |
| 1635 |
} |
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
clusternum = aasworld.areasettings[areanum].cluster; |
| 1648 |
goalclusternum = aasworld.areasettings[goalareanum].cluster; |
| 1649 |
|
| 1650 |
if (clusternum < 0 && goalclusternum > 0) |
| 1651 |
{ |
| 1652 |
portal = &aasworld.portals[-clusternum]; |
| 1653 |
if (portal->frontcluster == goalclusternum || |
| 1654 |
portal->backcluster == goalclusternum) |
| 1655 |
{ |
| 1656 |
clusternum = goalclusternum; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
|
| 1660 |
else if (clusternum > 0 && goalclusternum < 0) |
| 1661 |
{ |
| 1662 |
portal = &aasworld.portals[-goalclusternum]; |
| 1663 |
if (portal->frontcluster == clusternum || |
| 1664 |
portal->backcluster == clusternum) |
| 1665 |
{ |
| 1666 |
goalclusternum = clusternum; |
| 1667 |
} |
| 1668 |
} |
| 1669 |
|
| 1670 |
|
| 1671 |
if (clusternum > 0 && goalclusternum > 0 && clusternum == goalclusternum) |
| 1672 |
{ |
| 1673 |
|
| 1674 |
areacache = AAS_GetAreaRoutingCache(clusternum, goalareanum, travelflags); |
| 1675 |
|
| 1676 |
clusterareanum = AAS_ClusterAreaNum(clusternum, areanum); |
| 1677 |
|
| 1678 |
cluster = &aasworld.clusters[clusternum]; |
| 1679 |
|
| 1680 |
if (clusterareanum >= cluster->numreachabilityareas) return 0; |
| 1681 |
|
| 1682 |
if (areacache->traveltimes[clusterareanum] != 0) |
| 1683 |
{ |
| 1684 |
*reachnum = aasworld.areasettings[areanum].firstreachablearea + |
| 1685 |
areacache->reachabilities[clusterareanum]; |
| 1686 |
if (!origin) { |
| 1687 |
*traveltime = areacache->traveltimes[clusterareanum]; |
| 1688 |
return qtrue; |
| 1689 |
} |
| 1690 |
reach = &aasworld.reachability[*reachnum]; |
| 1691 |
*traveltime = areacache->traveltimes[clusterareanum] + |
| 1692 |
AAS_AreaTravelTime(areanum, origin, reach->start); |
| 1693 |
|
| 1694 |
return qtrue; |
| 1695 |
} |
| 1696 |
} |
| 1697 |
|
| 1698 |
clusternum = aasworld.areasettings[areanum].cluster; |
| 1699 |
goalclusternum = aasworld.areasettings[goalareanum].cluster; |
| 1700 |
|
| 1701 |
if (goalclusternum < 0) |
| 1702 |
{ |
| 1703 |
|
| 1704 |
portal = &aasworld.portals[-goalclusternum]; |
| 1705 |
goalclusternum = portal->frontcluster; |
| 1706 |
} |
| 1707 |
|
| 1708 |
portalcache = AAS_GetPortalRoutingCache(goalclusternum, goalareanum, travelflags); |
| 1709 |
|
| 1710 |
if (clusternum < 0) |
| 1711 |
{ |
| 1712 |
*traveltime = portalcache->traveltimes[-clusternum]; |
| 1713 |
*reachnum = aasworld.areasettings[areanum].firstreachablearea + |
| 1714 |
portalcache->reachabilities[-clusternum]; |
| 1715 |
return qtrue; |
| 1716 |
} |
| 1717 |
|
| 1718 |
besttime = 0; |
| 1719 |
bestreachnum = -1; |
| 1720 |
|
| 1721 |
cluster = &aasworld.clusters[clusternum]; |
| 1722 |
|
| 1723 |
for (i = 0; i < cluster->numportals; i++) |
| 1724 |
{ |
| 1725 |
portalnum = aasworld.portalindex[cluster->firstportal + i]; |
| 1726 |
|
| 1727 |
if (!portalcache->traveltimes[portalnum]) continue; |
| 1728 |
|
| 1729 |
portal = &aasworld.portals[portalnum]; |
| 1730 |
|
| 1731 |
areacache = AAS_GetAreaRoutingCache(clusternum, portal->areanum, travelflags); |
| 1732 |
|
| 1733 |
clusterareanum = AAS_ClusterAreaNum(clusternum, areanum); |
| 1734 |
|
| 1735 |
if (clusterareanum >= cluster->numreachabilityareas) continue; |
| 1736 |
|
| 1737 |
if (!areacache->traveltimes[clusterareanum]) continue; |
| 1738 |
|
| 1739 |
|
| 1740 |
t = portalcache->traveltimes[portalnum] + areacache->traveltimes[clusterareanum]; |
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
t += aasworld.portalmaxtraveltimes[portalnum]; |
| 1747 |
|
| 1748 |
if (origin) |
| 1749 |
{ |
| 1750 |
*reachnum = aasworld.areasettings[areanum].firstreachablearea + |
| 1751 |
areacache->reachabilities[clusterareanum]; |
| 1752 |
reach = aasworld.reachability + *reachnum; |
| 1753 |
t += AAS_AreaTravelTime(areanum, origin, reach->start); |
| 1754 |
} |
| 1755 |
|
| 1756 |
if (!besttime || t < besttime) |
| 1757 |
{ |
| 1758 |
bestreachnum = *reachnum; |
| 1759 |
besttime = t; |
| 1760 |
} |
| 1761 |
} |
| 1762 |
if (bestreachnum < 0) { |
| 1763 |
return qfalse; |
| 1764 |
} |
| 1765 |
*reachnum = bestreachnum; |
| 1766 |
*traveltime = besttime; |
| 1767 |
return qtrue; |
| 1768 |
} |
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
int AAS_AreaTravelTimeToGoalArea(int areanum, vec3_t origin, int goalareanum, int travelflags) |
| 1776 |
{ |
| 1777 |
int traveltime, reachnum = 0; |
| 1778 |
|
| 1779 |
if (AAS_AreaRouteToGoalArea(areanum, origin, goalareanum, travelflags, &traveltime, &reachnum)) |
| 1780 |
{ |
| 1781 |
return traveltime; |
| 1782 |
} |
| 1783 |
return 0; |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
int AAS_AreaReachabilityToGoalArea(int areanum, vec3_t origin, int goalareanum, int travelflags) |
| 1792 |
{ |
| 1793 |
int traveltime, reachnum = 0; |
| 1794 |
|
| 1795 |
if (AAS_AreaRouteToGoalArea(areanum, origin, goalareanum, travelflags, &traveltime, &reachnum)) |
| 1796 |
{ |
| 1797 |
return reachnum; |
| 1798 |
} |
| 1799 |
return 0; |
| 1800 |
} |
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
int AAS_PredictRoute(struct aas_predictroute_s *route, int areanum, vec3_t origin, |
| 1809 |
int goalareanum, int travelflags, int maxareas, int maxtime, |
| 1810 |
int stopevent, int stopcontents, int stoptfl, int stopareanum) |
| 1811 |
{ |
| 1812 |
int curareanum, reachnum, i, j, testareanum; |
| 1813 |
vec3_t curorigin; |
| 1814 |
aas_reachability_t *reach; |
| 1815 |
aas_reachabilityareas_t *reachareas; |
| 1816 |
|
| 1817 |
|
| 1818 |
route->stopevent = RSE_NONE; |
| 1819 |
route->endarea = goalareanum; |
| 1820 |
route->endcontents = 0; |
| 1821 |
route->endtravelflags = 0; |
| 1822 |
VectorCopy(origin, route->endpos); |
| 1823 |
route->time = 0; |
| 1824 |
|
| 1825 |
curareanum = areanum; |
| 1826 |
VectorCopy(origin, curorigin); |
| 1827 |
|
| 1828 |
for (i = 0; curareanum != goalareanum && (!maxareas || i < maxareas) && i < aasworld.numareas; i++) |
| 1829 |
{ |
| 1830 |
reachnum = AAS_AreaReachabilityToGoalArea(curareanum, curorigin, goalareanum, travelflags); |
| 1831 |
if (!reachnum) |
| 1832 |
{ |
| 1833 |
route->stopevent = RSE_NOROUTE; |
| 1834 |
return qfalse; |
| 1835 |
} |
| 1836 |
reach = &aasworld.reachability[reachnum]; |
| 1837 |
|
| 1838 |
if (stopevent & RSE_USETRAVELTYPE) |
| 1839 |
{ |
| 1840 |
if (AAS_TravelFlagForType_inline(reach->traveltype) & stoptfl) |
| 1841 |
{ |
| 1842 |
route->stopevent = RSE_USETRAVELTYPE; |
| 1843 |
route->endarea = curareanum; |
| 1844 |
route->endcontents = aasworld.areasettings[curareanum].contents; |
| 1845 |
route->endtravelflags = AAS_TravelFlagForType_inline(reach->traveltype); |
| 1846 |
VectorCopy(reach->start, route->endpos); |
| 1847 |
return qtrue; |
| 1848 |
} |
| 1849 |
if (AAS_AreaContentsTravelFlags_inline(reach->areanum) & stoptfl) |
| 1850 |
{ |
| 1851 |
route->stopevent = RSE_USETRAVELTYPE; |
| 1852 |
route->endarea = reach->areanum; |
| 1853 |
route->endcontents = aasworld.areasettings[reach->areanum].contents; |
| 1854 |
route->endtravelflags = AAS_AreaContentsTravelFlags_inline(reach->areanum); |
| 1855 |
VectorCopy(reach->end, route->endpos); |
| 1856 |
route->time += AAS_AreaTravelTime(areanum, origin, reach->start); |
| 1857 |
route->time += reach->traveltime; |
| 1858 |
return qtrue; |
| 1859 |
} |
| 1860 |
} |
| 1861 |
reachareas = &aasworld.reachabilityareas[reachnum]; |
| 1862 |
for (j = 0; j < reachareas->numareas + 1; j++) |
| 1863 |
{ |
| 1864 |
if (j >= reachareas->numareas) |
| 1865 |
testareanum = reach->areanum; |
| 1866 |
else |
| 1867 |
testareanum = aasworld.reachabilityareaindex[reachareas->firstarea + j]; |
| 1868 |
if (stopevent & RSE_ENTERCONTENTS) |
| 1869 |
{ |
| 1870 |
if (aasworld.areasettings[testareanum].contents & stopcontents) |
| 1871 |
{ |
| 1872 |
route->stopevent = RSE_ENTERCONTENTS; |
| 1873 |
route->endarea = testareanum; |
| 1874 |
route->endcontents = aasworld.areasettings[testareanum].contents; |
| 1875 |
VectorCopy(reach->end, route->endpos); |
| 1876 |
route->time += AAS_AreaTravelTime(areanum, origin, reach->start); |
| 1877 |
route->time += reach->traveltime; |
| 1878 |
return qtrue; |
| 1879 |
} |
| 1880 |
} |
| 1881 |
if (stopevent & RSE_ENTERAREA) |
| 1882 |
{ |
| 1883 |
if (testareanum == stopareanum) |
| 1884 |
{ |
| 1885 |
route->stopevent = RSE_ENTERAREA; |
| 1886 |
route->endarea = testareanum; |
| 1887 |
route->endcontents = aasworld.areasettings[testareanum].contents; |
| 1888 |
VectorCopy(reach->start, route->endpos); |
| 1889 |
return qtrue; |
| 1890 |
} |
| 1891 |
} |
| 1892 |
} |
| 1893 |
|
| 1894 |
route->time += AAS_AreaTravelTime(areanum, origin, reach->start); |
| 1895 |
route->time += reach->traveltime; |
| 1896 |
route->endarea = reach->areanum; |
| 1897 |
route->endcontents = aasworld.areasettings[reach->areanum].contents; |
| 1898 |
route->endtravelflags = AAS_TravelFlagForType_inline(reach->traveltype); |
| 1899 |
VectorCopy(reach->end, route->endpos); |
| 1900 |
|
| 1901 |
curareanum = reach->areanum; |
| 1902 |
VectorCopy(reach->end, curorigin); |
| 1903 |
|
| 1904 |
if (maxtime && route->time > maxtime) |
| 1905 |
break; |
| 1906 |
} |
| 1907 |
if (curareanum != goalareanum) |
| 1908 |
return qfalse; |
| 1909 |
return qtrue; |
| 1910 |
} |
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
int AAS_BridgeWalkable(int areanum) |
| 1918 |
{ |
| 1919 |
return qfalse; |
| 1920 |
} |
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
void AAS_ReachabilityFromNum(int num, struct aas_reachability_s *reach) |
| 1928 |
{ |
| 1929 |
if (!aasworld.initialized) |
| 1930 |
{ |
| 1931 |
Com_Memset(reach, 0, sizeof(aas_reachability_t)); |
| 1932 |
return; |
| 1933 |
} |
| 1934 |
if (num < 0 || num >= aasworld.reachabilitysize) |
| 1935 |
{ |
| 1936 |
Com_Memset(reach, 0, sizeof(aas_reachability_t)); |
| 1937 |
return; |
| 1938 |
} |
| 1939 |
Com_Memcpy(reach, &aasworld.reachability[num], sizeof(aas_reachability_t));; |
| 1940 |
} |
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
int AAS_NextAreaReachability(int areanum, int reachnum) |
| 1948 |
{ |
| 1949 |
aas_areasettings_t *settings; |
| 1950 |
|
| 1951 |
if (!aasworld.initialized) return 0; |
| 1952 |
|
| 1953 |
if (areanum <= 0 || areanum >= aasworld.numareas) |
| 1954 |
{ |
| 1955 |
botimport.Print(PRT_ERROR, "AAS_NextAreaReachability: areanum %d out of range\n", areanum); |
| 1956 |
return 0; |
| 1957 |
} |
| 1958 |
|
| 1959 |
settings = &aasworld.areasettings[areanum]; |
| 1960 |
if (!reachnum) |
| 1961 |
{ |
| 1962 |
return settings->firstreachablearea; |
| 1963 |
} |
| 1964 |
if (reachnum < settings->firstreachablearea) |
| 1965 |
{ |
| 1966 |
botimport.Print(PRT_FATAL, "AAS_NextAreaReachability: reachnum < settings->firstreachableara"); |
| 1967 |
return 0; |
| 1968 |
} |
| 1969 |
reachnum++; |
| 1970 |
if (reachnum >= settings->firstreachablearea + settings->numreachableareas) |
| 1971 |
{ |
| 1972 |
return 0; |
| 1973 |
} |
| 1974 |
return reachnum; |
| 1975 |
} |
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
int AAS_NextModelReachability(int num, int modelnum) |
| 1983 |
{ |
| 1984 |
int i; |
| 1985 |
|
| 1986 |
if (num <= 0) num = 1; |
| 1987 |
else if (num >= aasworld.reachabilitysize) return 0; |
| 1988 |
else num++; |
| 1989 |
|
| 1990 |
for (i = num; i < aasworld.reachabilitysize; i++) |
| 1991 |
{ |
| 1992 |
if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == TRAVEL_ELEVATOR) |
| 1993 |
{ |
| 1994 |
if (aasworld.reachability[i].facenum == modelnum) return i; |
| 1995 |
} |
| 1996 |
else if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == TRAVEL_FUNCBOB) |
| 1997 |
{ |
| 1998 |
if ((aasworld.reachability[i].facenum & 0x0000FFFF) == modelnum) return i; |
| 1999 |
} |
| 2000 |
} |
| 2001 |
return 0; |
| 2002 |
} |
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
int AAS_RandomGoalArea(int areanum, int travelflags, int *goalareanum, vec3_t goalorigin) |
| 2010 |
{ |
| 2011 |
int i, n, t; |
| 2012 |
vec3_t start, end; |
| 2013 |
aas_trace_t trace; |
| 2014 |
|
| 2015 |
|
| 2016 |
if (!AAS_AreaReachability(areanum)) return qfalse; |
| 2017 |
|
| 2018 |
n = aasworld.numareas * random(); |
| 2019 |
for (i = 0; i < aasworld.numareas; i++) |
| 2020 |
{ |
| 2021 |
if (n <= 0) n = 1; |
| 2022 |
if (n >= aasworld.numareas) n = 1; |
| 2023 |
if (AAS_AreaReachability(n)) |
| 2024 |
{ |
| 2025 |
t = AAS_AreaTravelTimeToGoalArea(areanum, aasworld.areas[areanum].center, n, travelflags); |
| 2026 |
|
| 2027 |
if (t > 0) |
| 2028 |
{ |
| 2029 |
if (AAS_AreaSwim(n)) |
| 2030 |
{ |
| 2031 |
*goalareanum = n; |
| 2032 |
VectorCopy(aasworld.areas[n].center, goalorigin); |
| 2033 |
|
| 2034 |
return qtrue; |
| 2035 |
} |
| 2036 |
VectorCopy(aasworld.areas[n].center, start); |
| 2037 |
if (!AAS_PointAreaNum(start)) |
| 2038 |
Log_Write("area %d center %f %f %f in solid?", n, start[0], start[1], start[2]); |
| 2039 |
VectorCopy(start, end); |
| 2040 |
end[2] -= 300; |
| 2041 |
trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1); |
| 2042 |
if (!trace.startsolid && trace.fraction < 1 && AAS_PointAreaNum(trace.endpos) == n) |
| 2043 |
{ |
| 2044 |
if (AAS_AreaGroundFaceArea(n) > 300) |
| 2045 |
{ |
| 2046 |
*goalareanum = n; |
| 2047 |
VectorCopy(trace.endpos, goalorigin); |
| 2048 |
|
| 2049 |
return qtrue; |
| 2050 |
} |
| 2051 |
} |
| 2052 |
} |
| 2053 |
} |
| 2054 |
n++; |
| 2055 |
} |
| 2056 |
return qfalse; |
| 2057 |
} |
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
int AAS_AreaVisible(int srcarea, int destarea) |
| 2065 |
{ |
| 2066 |
return qfalse; |
| 2067 |
} |
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
float DistancePointToLine(vec3_t v1, vec3_t v2, vec3_t point) |
| 2075 |
{ |
| 2076 |
vec3_t vec, p2; |
| 2077 |
|
| 2078 |
AAS_ProjectPointOntoVector(point, v1, v2, p2); |
| 2079 |
VectorSubtract(point, p2, vec); |
| 2080 |
return VectorLength(vec); |
| 2081 |
} |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
int AAS_NearestHideArea(int srcnum, vec3_t origin, int areanum, int enemynum, vec3_t enemyorigin, int enemyareanum, int travelflags) |
| 2089 |
{ |
| 2090 |
int i, j, nextareanum, badtravelflags, numreach, bestarea; |
| 2091 |
unsigned short int t, besttraveltime; |
| 2092 |
static unsigned short int *hidetraveltimes; |
| 2093 |
aas_routingupdate_t *updateliststart, *updatelistend, *curupdate, *nextupdate; |
| 2094 |
aas_reachability_t *reach; |
| 2095 |
float dist1, dist2; |
| 2096 |
vec3_t v1, v2, p; |
| 2097 |
qboolean startVisible; |
| 2098 |
|
| 2099 |
|
| 2100 |
if (!hidetraveltimes) |
| 2101 |
{ |
| 2102 |
hidetraveltimes = (unsigned short int *) GetClearedMemory(aasworld.numareas * sizeof(unsigned short int)); |
| 2103 |
} |
| 2104 |
else |
| 2105 |
{ |
| 2106 |
Com_Memset(hidetraveltimes, 0, aasworld.numareas * sizeof(unsigned short int)); |
| 2107 |
} |
| 2108 |
besttraveltime = 0; |
| 2109 |
bestarea = 0; |
| 2110 |
|
| 2111 |
startVisible = qtrue; |
| 2112 |
|
| 2113 |
badtravelflags = ~travelflags; |
| 2114 |
|
| 2115 |
curupdate = &aasworld.areaupdate[areanum]; |
| 2116 |
curupdate->areanum = areanum; |
| 2117 |
VectorCopy(origin, curupdate->start); |
| 2118 |
curupdate->areatraveltimes = aasworld.areatraveltimes[areanum][0]; |
| 2119 |
curupdate->tmptraveltime = 0; |
| 2120 |
|
| 2121 |
curupdate->next = NULL; |
| 2122 |
curupdate->prev = NULL; |
| 2123 |
updateliststart = curupdate; |
| 2124 |
updatelistend = curupdate; |
| 2125 |
|
| 2126 |
while (updateliststart) |
| 2127 |
{ |
| 2128 |
curupdate = updateliststart; |
| 2129 |
|
| 2130 |
if (curupdate->next) curupdate->next->prev = NULL; |
| 2131 |
else updatelistend = NULL; |
| 2132 |
updateliststart = curupdate->next; |
| 2133 |
|
| 2134 |
curupdate->inlist = qfalse; |
| 2135 |
|
| 2136 |
numreach = aasworld.areasettings[curupdate->areanum].numreachableareas; |
| 2137 |
reach = &aasworld.reachability[aasworld.areasettings[curupdate->areanum].firstreachablearea]; |
| 2138 |
|
| 2139 |
for (i = 0; i < numreach; i++, reach++) |
| 2140 |
{ |
| 2141 |
|
| 2142 |
if (AAS_TravelFlagForType_inline(reach->traveltype) & badtravelflags) continue; |
| 2143 |
|
| 2144 |
if (AAS_AreaContentsTravelFlags_inline(reach->areanum) & badtravelflags) continue; |
| 2145 |
|
| 2146 |
nextareanum = reach->areanum; |
| 2147 |
|
| 2148 |
if (nextareanum == enemyareanum) continue; |
| 2149 |
|
| 2150 |
|
| 2151 |
t = curupdate->tmptraveltime + |
| 2152 |
AAS_AreaTravelTime(curupdate->areanum, curupdate->start, reach->start) + |
| 2153 |
reach->traveltime; |
| 2154 |
|
| 2155 |
|
| 2156 |
AAS_ProjectPointOntoVector(enemyorigin, curupdate->start, reach->end, p); |
| 2157 |
for (j = 0; j < 3; j++) |
| 2158 |
if ((p[j] > curupdate->start[j] && p[j] > reach->end[j]) || |
| 2159 |
(p[j] < curupdate->start[j] && p[j] < reach->end[j])) |
| 2160 |
break; |
| 2161 |
if (j < 3) |
| 2162 |
{ |
| 2163 |
VectorSubtract(enemyorigin, reach->end, v2); |
| 2164 |
} |
| 2165 |
else |
| 2166 |
{ |
| 2167 |
VectorSubtract(enemyorigin, p, v2); |
| 2168 |
} |
| 2169 |
dist2 = VectorLength(v2); |
| 2170 |
|
| 2171 |
if (dist2 < 40) continue; |
| 2172 |
|
| 2173 |
VectorSubtract(enemyorigin, curupdate->start, v1); |
| 2174 |
dist1 = VectorLength(v1); |
| 2175 |
|
| 2176 |
if (dist2 < dist1) |
| 2177 |
{ |
| 2178 |
t += (dist1 - dist2) * 10; |
| 2179 |
} |
| 2180 |
|
| 2181 |
if (!startVisible && AAS_AreaVisible(enemyareanum, nextareanum)) { |
| 2182 |
continue; |
| 2183 |
} |
| 2184 |
|
| 2185 |
if (besttraveltime && t >= besttraveltime) continue; |
| 2186 |
|
| 2187 |
if (!hidetraveltimes[nextareanum] || |
| 2188 |
hidetraveltimes[nextareanum] > t) |
| 2189 |
{ |
| 2190 |
|
| 2191 |
if (!AAS_AreaVisible(enemyareanum, nextareanum)) |
| 2192 |
{ |
| 2193 |
besttraveltime = t; |
| 2194 |
bestarea = nextareanum; |
| 2195 |
} |
| 2196 |
hidetraveltimes[nextareanum] = t; |
| 2197 |
nextupdate = &aasworld.areaupdate[nextareanum]; |
| 2198 |
nextupdate->areanum = nextareanum; |
| 2199 |
nextupdate->tmptraveltime = t; |
| 2200 |
|
| 2201 |
VectorCopy(reach->end, nextupdate->start); |
| 2202 |
|
| 2203 |
if (!nextupdate->inlist) |
| 2204 |
{ |
| 2205 |
|
| 2206 |
nextupdate->next = NULL; |
| 2207 |
nextupdate->prev = updatelistend; |
| 2208 |
if (updatelistend) updatelistend->next = nextupdate; |
| 2209 |
else updateliststart = nextupdate; |
| 2210 |
updatelistend = nextupdate; |
| 2211 |
nextupdate->inlist = qtrue; |
| 2212 |
} |
| 2213 |
} |
| 2214 |
} |
| 2215 |
} |
| 2216 |
return bestarea; |
| 2217 |
} |