be_interface.c (29195B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 23 /***************************************************************************** 24 * name: be_interface.c // bk010221 - FIXME - DEAD code elimination 25 * 26 * desc: bot library interface 27 * 28 * $Archive: /MissionPack/code/botlib/be_interface.c $ 29 * 30 *****************************************************************************/ 31 32 #include "../game/q_shared.h" 33 #include "l_memory.h" 34 #include "l_log.h" 35 #include "l_libvar.h" 36 #include "l_script.h" 37 #include "l_precomp.h" 38 #include "l_struct.h" 39 #include "aasfile.h" 40 #include "../game/botlib.h" 41 #include "../game/be_aas.h" 42 #include "be_aas_funcs.h" 43 #include "be_aas_def.h" 44 #include "be_interface.h" 45 46 #include "../game/be_ea.h" 47 #include "be_ai_weight.h" 48 #include "../game/be_ai_goal.h" 49 #include "../game/be_ai_move.h" 50 #include "../game/be_ai_weap.h" 51 #include "../game/be_ai_chat.h" 52 #include "../game/be_ai_char.h" 53 #include "../game/be_ai_gen.h" 54 55 //library globals in a structure 56 botlib_globals_t botlibglobals; 57 58 botlib_export_t be_botlib_export; 59 botlib_import_t botimport; 60 // 61 int bot_developer; 62 //qtrue if the library is setup 63 int botlibsetup = qfalse; 64 65 //=========================================================================== 66 // 67 // several functions used by the exported functions 68 // 69 //=========================================================================== 70 71 //=========================================================================== 72 // 73 // Parameter: - 74 // Returns: - 75 // Changes Globals: - 76 //=========================================================================== 77 int Sys_MilliSeconds(void) 78 { 79 return clock() * 1000 / CLOCKS_PER_SEC; 80 } //end of the function Sys_MilliSeconds 81 //=========================================================================== 82 // 83 // Parameter: - 84 // Returns: - 85 // Changes Globals: - 86 //=========================================================================== 87 qboolean ValidClientNumber(int num, char *str) 88 { 89 if (num < 0 || num > botlibglobals.maxclients) 90 { 91 //weird: the disabled stuff results in a crash 92 botimport.Print(PRT_ERROR, "%s: invalid client number %d, [0, %d]\n", 93 str, num, botlibglobals.maxclients); 94 return qfalse; 95 } //end if 96 return qtrue; 97 } //end of the function BotValidateClientNumber 98 //=========================================================================== 99 // 100 // Parameter: - 101 // Returns: - 102 // Changes Globals: - 103 //=========================================================================== 104 qboolean ValidEntityNumber(int num, char *str) 105 { 106 if (num < 0 || num > botlibglobals.maxentities) 107 { 108 botimport.Print(PRT_ERROR, "%s: invalid entity number %d, [0, %d]\n", 109 str, num, botlibglobals.maxentities); 110 return qfalse; 111 } //end if 112 return qtrue; 113 } //end of the function BotValidateClientNumber 114 //=========================================================================== 115 // 116 // Parameter: - 117 // Returns: - 118 // Changes Globals: - 119 //=========================================================================== 120 qboolean BotLibSetup(char *str) 121 { 122 if (!botlibglobals.botlibsetup) 123 { 124 botimport.Print(PRT_ERROR, "%s: bot library used before being setup\n", str); 125 return qfalse; 126 } //end if 127 return qtrue; 128 } //end of the function BotLibSetup 129 130 //=========================================================================== 131 // 132 // Parameter: - 133 // Returns: - 134 // Changes Globals: - 135 //=========================================================================== 136 int Export_BotLibSetup(void) 137 { 138 int errnum; 139 140 bot_developer = LibVarGetValue("bot_developer"); 141 memset( &botlibglobals, 0, sizeof(botlibglobals) ); // bk001207 - init 142 //initialize byte swapping (litte endian etc.) 143 // Swap_Init(); 144 Log_Open("botlib.log"); 145 // 146 botimport.Print(PRT_MESSAGE, "------- BotLib Initialization -------\n"); 147 // 148 botlibglobals.maxclients = (int) LibVarValue("maxclients", "128"); 149 botlibglobals.maxentities = (int) LibVarValue("maxentities", "1024"); 150 151 errnum = AAS_Setup(); //be_aas_main.c 152 if (errnum != BLERR_NOERROR) return errnum; 153 errnum = EA_Setup(); //be_ea.c 154 if (errnum != BLERR_NOERROR) return errnum; 155 errnum = BotSetupWeaponAI(); //be_ai_weap.c 156 if (errnum != BLERR_NOERROR)return errnum; 157 errnum = BotSetupGoalAI(); //be_ai_goal.c 158 if (errnum != BLERR_NOERROR) return errnum; 159 errnum = BotSetupChatAI(); //be_ai_chat.c 160 if (errnum != BLERR_NOERROR) return errnum; 161 errnum = BotSetupMoveAI(); //be_ai_move.c 162 if (errnum != BLERR_NOERROR) return errnum; 163 164 botlibsetup = qtrue; 165 botlibglobals.botlibsetup = qtrue; 166 167 return BLERR_NOERROR; 168 } //end of the function Export_BotLibSetup 169 //=========================================================================== 170 // 171 // Parameter: - 172 // Returns: - 173 // Changes Globals: - 174 //=========================================================================== 175 int Export_BotLibShutdown(void) 176 { 177 if (!BotLibSetup("BotLibShutdown")) return BLERR_LIBRARYNOTSETUP; 178 #ifndef DEMO 179 //DumpFileCRCs(); 180 #endif //DEMO 181 // 182 BotShutdownChatAI(); //be_ai_chat.c 183 BotShutdownMoveAI(); //be_ai_move.c 184 BotShutdownGoalAI(); //be_ai_goal.c 185 BotShutdownWeaponAI(); //be_ai_weap.c 186 BotShutdownWeights(); //be_ai_weight.c 187 BotShutdownCharacters(); //be_ai_char.c 188 //shud down aas 189 AAS_Shutdown(); 190 //shut down bot elemantary actions 191 EA_Shutdown(); 192 //free all libvars 193 LibVarDeAllocAll(); 194 //remove all global defines from the pre compiler 195 PC_RemoveAllGlobalDefines(); 196 197 //dump all allocated memory 198 // DumpMemory(); 199 #ifdef DEBUG 200 PrintMemoryLabels(); 201 #endif 202 //shut down library log file 203 Log_Shutdown(); 204 // 205 botlibsetup = qfalse; 206 botlibglobals.botlibsetup = qfalse; 207 // print any files still open 208 PC_CheckOpenSourceHandles(); 209 // 210 return BLERR_NOERROR; 211 } //end of the function Export_BotLibShutdown 212 //=========================================================================== 213 // 214 // Parameter: - 215 // Returns: - 216 // Changes Globals: - 217 //=========================================================================== 218 int Export_BotLibVarSet(char *var_name, char *value) 219 { 220 LibVarSet(var_name, value); 221 return BLERR_NOERROR; 222 } //end of the function Export_BotLibVarSet 223 //=========================================================================== 224 // 225 // Parameter: - 226 // Returns: - 227 // Changes Globals: - 228 //=========================================================================== 229 int Export_BotLibVarGet(char *var_name, char *value, int size) 230 { 231 char *varvalue; 232 233 varvalue = LibVarGetString(var_name); 234 strncpy(value, varvalue, size-1); 235 value[size-1] = '\0'; 236 return BLERR_NOERROR; 237 } //end of the function Export_BotLibVarGet 238 //=========================================================================== 239 // 240 // Parameter: - 241 // Returns: - 242 // Changes Globals: - 243 //=========================================================================== 244 int Export_BotLibStartFrame(float time) 245 { 246 if (!BotLibSetup("BotStartFrame")) return BLERR_LIBRARYNOTSETUP; 247 return AAS_StartFrame(time); 248 } //end of the function Export_BotLibStartFrame 249 //=========================================================================== 250 // 251 // Parameter: - 252 // Returns: - 253 // Changes Globals: - 254 //=========================================================================== 255 int Export_BotLibLoadMap(const char *mapname) 256 { 257 #ifdef DEBUG 258 int starttime = Sys_MilliSeconds(); 259 #endif 260 int errnum; 261 262 if (!BotLibSetup("BotLoadMap")) return BLERR_LIBRARYNOTSETUP; 263 // 264 botimport.Print(PRT_MESSAGE, "------------ Map Loading ------------\n"); 265 //startup AAS for the current map, model and sound index 266 errnum = AAS_LoadMap(mapname); 267 if (errnum != BLERR_NOERROR) return errnum; 268 //initialize the items in the level 269 BotInitLevelItems(); //be_ai_goal.h 270 BotSetBrushModelTypes(); //be_ai_move.h 271 // 272 botimport.Print(PRT_MESSAGE, "-------------------------------------\n"); 273 #ifdef DEBUG 274 botimport.Print(PRT_MESSAGE, "map loaded in %d msec\n", Sys_MilliSeconds() - starttime); 275 #endif 276 // 277 return BLERR_NOERROR; 278 } //end of the function Export_BotLibLoadMap 279 //=========================================================================== 280 // 281 // Parameter: - 282 // Returns: - 283 // Changes Globals: - 284 //=========================================================================== 285 int Export_BotLibUpdateEntity(int ent, bot_entitystate_t *state) 286 { 287 if (!BotLibSetup("BotUpdateEntity")) return BLERR_LIBRARYNOTSETUP; 288 if (!ValidEntityNumber(ent, "BotUpdateEntity")) return BLERR_INVALIDENTITYNUMBER; 289 290 return AAS_UpdateEntity(ent, state); 291 } //end of the function Export_BotLibUpdateEntity 292 //=========================================================================== 293 // 294 // Parameter: - 295 // Returns: - 296 // Changes Globals: - 297 //=========================================================================== 298 void AAS_TestMovementPrediction(int entnum, vec3_t origin, vec3_t dir); 299 void ElevatorBottomCenter(aas_reachability_t *reach, vec3_t bottomcenter); 300 int BotGetReachabilityToGoal(vec3_t origin, int areanum, 301 int lastgoalareanum, int lastareanum, 302 int *avoidreach, float *avoidreachtimes, int *avoidreachtries, 303 bot_goal_t *goal, int travelflags, int movetravelflags, 304 struct bot_avoidspot_s *avoidspots, int numavoidspots, int *flags); 305 306 int AAS_PointLight(vec3_t origin, int *red, int *green, int *blue); 307 308 int AAS_TraceAreas(vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas); 309 310 int AAS_Reachability_WeaponJump(int area1num, int area2num); 311 312 int BotFuzzyPointReachabilityArea(vec3_t origin); 313 314 float BotGapDistance(vec3_t origin, vec3_t hordir, int entnum); 315 316 void AAS_FloodAreas(vec3_t origin); 317 318 int BotExportTest(int parm0, char *parm1, vec3_t parm2, vec3_t parm3) 319 { 320 321 // return AAS_PointLight(parm2, NULL, NULL, NULL); 322 323 #ifdef DEBUG 324 static int area = -1; 325 static int line[2]; 326 int newarea, i, highlightarea, flood; 327 // int reachnum; 328 vec3_t eye, forward, right, end, origin; 329 // vec3_t bottomcenter; 330 // aas_trace_t trace; 331 // aas_face_t *face; 332 // aas_entity_t *ent; 333 // bsp_trace_t bsptrace; 334 // aas_reachability_t reach; 335 // bot_goal_t goal; 336 337 // clock_t start_time, end_time; 338 vec3_t mins = {-16, -16, -24}; 339 vec3_t maxs = {16, 16, 32}; 340 341 // int areas[10], numareas; 342 343 344 //return 0; 345 346 if (!aasworld.loaded) return 0; 347 348 /* 349 if (parm0 & 1) 350 { 351 AAS_ClearShownPolygons(); 352 AAS_FloodAreas(parm2); 353 } //end if 354 return 0; 355 */ 356 for (i = 0; i < 2; i++) if (!line[i]) line[i] = botimport.DebugLineCreate(); 357 358 // AAS_ClearShownDebugLines(); 359 360 //if (AAS_AgainstLadder(parm2)) botimport.Print(PRT_MESSAGE, "against ladder\n"); 361 //BotOnGround(parm2, PRESENCE_NORMAL, 1, &newarea, &newarea); 362 //botimport.Print(PRT_MESSAGE, "%f %f %f\n", parm2[0], parm2[1], parm2[2]); 363 //* 364 highlightarea = LibVarGetValue("bot_highlightarea"); 365 if (highlightarea > 0) 366 { 367 newarea = highlightarea; 368 } //end if 369 else 370 { 371 VectorCopy(parm2, origin); 372 origin[2] += 0.5; 373 //newarea = AAS_PointAreaNum(origin); 374 newarea = BotFuzzyPointReachabilityArea(origin); 375 } //end else 376 377 botimport.Print(PRT_MESSAGE, "\rtravel time to goal (%d) = %d ", botlibglobals.goalareanum, 378 AAS_AreaTravelTimeToGoalArea(newarea, origin, botlibglobals.goalareanum, TFL_DEFAULT)); 379 //newarea = BotReachabilityArea(origin, qtrue); 380 if (newarea != area) 381 { 382 botimport.Print(PRT_MESSAGE, "origin = %f, %f, %f\n", origin[0], origin[1], origin[2]); 383 area = newarea; 384 botimport.Print(PRT_MESSAGE, "new area %d, cluster %d, presence type %d\n", 385 area, AAS_AreaCluster(area), AAS_PointPresenceType(origin)); 386 botimport.Print(PRT_MESSAGE, "area contents: "); 387 if (aasworld.areasettings[area].contents & AREACONTENTS_WATER) 388 { 389 botimport.Print(PRT_MESSAGE, "water &"); 390 } //end if 391 if (aasworld.areasettings[area].contents & AREACONTENTS_LAVA) 392 { 393 botimport.Print(PRT_MESSAGE, "lava &"); 394 } //end if 395 if (aasworld.areasettings[area].contents & AREACONTENTS_SLIME) 396 { 397 botimport.Print(PRT_MESSAGE, "slime &"); 398 } //end if 399 if (aasworld.areasettings[area].contents & AREACONTENTS_JUMPPAD) 400 { 401 botimport.Print(PRT_MESSAGE, "jump pad &"); 402 } //end if 403 if (aasworld.areasettings[area].contents & AREACONTENTS_CLUSTERPORTAL) 404 { 405 botimport.Print(PRT_MESSAGE, "cluster portal &"); 406 } //end if 407 if (aasworld.areasettings[area].contents & AREACONTENTS_VIEWPORTAL) 408 { 409 botimport.Print(PRT_MESSAGE, "view portal &"); 410 } //end if 411 if (aasworld.areasettings[area].contents & AREACONTENTS_DONOTENTER) 412 { 413 botimport.Print(PRT_MESSAGE, "do not enter &"); 414 } //end if 415 if (aasworld.areasettings[area].contents & AREACONTENTS_MOVER) 416 { 417 botimport.Print(PRT_MESSAGE, "mover &"); 418 } //end if 419 if (!aasworld.areasettings[area].contents) 420 { 421 botimport.Print(PRT_MESSAGE, "empty"); 422 } //end if 423 botimport.Print(PRT_MESSAGE, "\n"); 424 botimport.Print(PRT_MESSAGE, "travel time to goal (%d) = %d\n", botlibglobals.goalareanum, 425 AAS_AreaTravelTimeToGoalArea(newarea, origin, botlibglobals.goalareanum, TFL_DEFAULT|TFL_ROCKETJUMP)); 426 /* 427 VectorCopy(origin, end); 428 end[2] += 5; 429 numareas = AAS_TraceAreas(origin, end, areas, NULL, 10); 430 AAS_TraceClientBBox(origin, end, PRESENCE_CROUCH, -1); 431 botimport.Print(PRT_MESSAGE, "num areas = %d, area = %d\n", numareas, areas[0]); 432 */ 433 /* 434 botlibglobals.goalareanum = newarea; 435 VectorCopy(parm2, botlibglobals.goalorigin); 436 botimport.Print(PRT_MESSAGE, "new goal %2.1f %2.1f %2.1f area %d\n", 437 origin[0], origin[1], origin[2], newarea); 438 */ 439 } //end if 440 //* 441 flood = LibVarGetValue("bot_flood"); 442 if (parm0 & 1) 443 { 444 if (flood) 445 { 446 AAS_ClearShownPolygons(); 447 AAS_ClearShownDebugLines(); 448 AAS_FloodAreas(parm2); 449 } 450 else 451 { 452 botlibglobals.goalareanum = newarea; 453 VectorCopy(parm2, botlibglobals.goalorigin); 454 botimport.Print(PRT_MESSAGE, "new goal %2.1f %2.1f %2.1f area %d\n", 455 origin[0], origin[1], origin[2], newarea); 456 } 457 } //end if*/ 458 if (flood) 459 return 0; 460 // if (parm0 & BUTTON_USE) 461 // { 462 // botlibglobals.runai = !botlibglobals.runai; 463 // if (botlibglobals.runai) botimport.Print(PRT_MESSAGE, "started AI\n"); 464 // else botimport.Print(PRT_MESSAGE, "stopped AI\n"); 465 //* / 466 /* 467 goal.areanum = botlibglobals.goalareanum; 468 reachnum = BotGetReachabilityToGoal(parm2, newarea, 1, 469 ms.avoidreach, ms.avoidreachtimes, 470 &goal, TFL_DEFAULT); 471 if (!reachnum) 472 { 473 botimport.Print(PRT_MESSAGE, "goal not reachable\n"); 474 } //end if 475 else 476 { 477 AAS_ReachabilityFromNum(reachnum, &reach); 478 AAS_ClearShownDebugLines(); 479 AAS_ShowArea(area, qtrue); 480 AAS_ShowArea(reach.areanum, qtrue); 481 AAS_DrawCross(reach.start, 6, LINECOLOR_BLUE); 482 AAS_DrawCross(reach.end, 6, LINECOLOR_RED); 483 // 484 if ((reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_ELEVATOR) 485 { 486 ElevatorBottomCenter(&reach, bottomcenter); 487 AAS_DrawCross(bottomcenter, 10, LINECOLOR_GREEN); 488 } //end if 489 } //end else*/ 490 // botimport.Print(PRT_MESSAGE, "travel time to goal = %d\n", 491 // AAS_AreaTravelTimeToGoalArea(area, origin, botlibglobals.goalareanum, TFL_DEFAULT)); 492 // botimport.Print(PRT_MESSAGE, "test rj from 703 to 716\n"); 493 // AAS_Reachability_WeaponJump(703, 716); 494 // } //end if*/ 495 496 /* face = AAS_AreaGroundFace(newarea, parm2); 497 if (face) 498 { 499 AAS_ShowFace(face - aasworld.faces); 500 } //end if*/ 501 /* 502 AAS_ClearShownDebugLines(); 503 AAS_ShowArea(newarea, parm0 & BUTTON_USE); 504 AAS_ShowReachableAreas(area); 505 */ 506 AAS_ClearShownPolygons(); 507 AAS_ClearShownDebugLines(); 508 AAS_ShowAreaPolygons(newarea, 1, parm0 & 4); 509 if (parm0 & 2) AAS_ShowReachableAreas(area); 510 else 511 { 512 static int lastgoalareanum, lastareanum; 513 static int avoidreach[MAX_AVOIDREACH]; 514 static float avoidreachtimes[MAX_AVOIDREACH]; 515 static int avoidreachtries[MAX_AVOIDREACH]; 516 int reachnum, resultFlags; 517 bot_goal_t goal; 518 aas_reachability_t reach; 519 520 /* 521 goal.areanum = botlibglobals.goalareanum; 522 VectorCopy(botlibglobals.goalorigin, goal.origin); 523 reachnum = BotGetReachabilityToGoal(origin, newarea, 524 lastgoalareanum, lastareanum, 525 avoidreach, avoidreachtimes, avoidreachtries, 526 &goal, TFL_DEFAULT|TFL_FUNCBOB|TFL_ROCKETJUMP, TFL_DEFAULT|TFL_FUNCBOB|TFL_ROCKETJUMP, 527 NULL, 0, &resultFlags); 528 AAS_ReachabilityFromNum(reachnum, &reach); 529 AAS_ShowReachability(&reach); 530 */ 531 int curarea; 532 vec3_t curorigin; 533 534 goal.areanum = botlibglobals.goalareanum; 535 VectorCopy(botlibglobals.goalorigin, goal.origin); 536 VectorCopy(origin, curorigin); 537 curarea = newarea; 538 for ( i = 0; i < 100; i++ ) { 539 if ( curarea == goal.areanum ) { 540 break; 541 } 542 reachnum = BotGetReachabilityToGoal(curorigin, curarea, 543 lastgoalareanum, lastareanum, 544 avoidreach, avoidreachtimes, avoidreachtries, 545 &goal, TFL_DEFAULT|TFL_FUNCBOB|TFL_ROCKETJUMP, TFL_DEFAULT|TFL_FUNCBOB|TFL_ROCKETJUMP, 546 NULL, 0, &resultFlags); 547 AAS_ReachabilityFromNum(reachnum, &reach); 548 AAS_ShowReachability(&reach); 549 VectorCopy(reach.end, origin); 550 lastareanum = curarea; 551 curarea = reach.areanum; 552 } 553 } //end else 554 VectorClear(forward); 555 //BotGapDistance(origin, forward, 0); 556 /* 557 if (parm0 & BUTTON_USE) 558 { 559 botimport.Print(PRT_MESSAGE, "test rj from 703 to 716\n"); 560 AAS_Reachability_WeaponJump(703, 716); 561 } //end if*/ 562 563 AngleVectors(parm3, forward, right, NULL); 564 //get the eye 16 units to the right of the origin 565 VectorMA(parm2, 8, right, eye); 566 //get the eye 24 units up 567 eye[2] += 24; 568 //get the end point for the line to be traced 569 VectorMA(eye, 800, forward, end); 570 571 // AAS_TestMovementPrediction(1, parm2, forward); 572 /* 573 //trace the line to find the hit point 574 trace = AAS_TraceClientBBox(eye, end, PRESENCE_NORMAL, 1); 575 if (!line[0]) line[0] = botimport.DebugLineCreate(); 576 botimport.DebugLineShow(line[0], eye, trace.endpos, LINECOLOR_BLUE); 577 // 578 AAS_ClearShownDebugLines(); 579 if (trace.ent) 580 { 581 ent = &aasworld.entities[trace.ent]; 582 AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs); 583 } //end if 584 */ 585 586 /* 587 start_time = clock(); 588 for (i = 0; i < 2000; i++) 589 { 590 AAS_Trace2(eye, mins, maxs, end, 1, MASK_PLAYERSOLID); 591 // AAS_TraceClientBBox(eye, end, PRESENCE_NORMAL, 1); 592 } //end for 593 end_time = clock(); 594 botimport.Print(PRT_MESSAGE, "me %lu clocks, %lu CLOCKS_PER_SEC\n", end_time - start_time, CLOCKS_PER_SEC); 595 start_time = clock(); 596 for (i = 0; i < 2000; i++) 597 { 598 AAS_Trace(eye, mins, maxs, end, 1, MASK_PLAYERSOLID); 599 } //end for 600 end_time = clock(); 601 botimport.Print(PRT_MESSAGE, "id %lu clocks, %lu CLOCKS_PER_SEC\n", end_time - start_time, CLOCKS_PER_SEC); 602 */ 603 604 // TTimo: nested comments are BAD for gcc -Werror, use #if 0 instead.. 605 #if 0 606 AAS_ClearShownDebugLines(); 607 //bsptrace = AAS_Trace(eye, NULL, NULL, end, 1, MASK_PLAYERSOLID); 608 bsptrace = AAS_Trace(eye, mins, maxs, end, 1, MASK_PLAYERSOLID); 609 if (!line[0]) line[0] = botimport.DebugLineCreate(); 610 botimport.DebugLineShow(line[0], eye, bsptrace.endpos, LINECOLOR_YELLOW); 611 if (bsptrace.fraction < 1.0) 612 { 613 face = AAS_TraceEndFace(&trace); 614 if (face) 615 { 616 AAS_ShowFace(face - aasworld.faces); 617 } //end if 618 619 AAS_DrawPlaneCross(bsptrace.endpos, 620 bsptrace.plane.normal, 621 bsptrace.plane.dist + bsptrace.exp_dist, 622 bsptrace.plane.type, LINECOLOR_GREEN); 623 if (trace.ent) 624 { 625 ent = &aasworld.entities[trace.ent]; 626 AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs); 627 } //end if 628 } //end if 629 //bsptrace = AAS_Trace2(eye, NULL, NULL, end, 1, MASK_PLAYERSOLID); 630 bsptrace = AAS_Trace2(eye, mins, maxs, end, 1, MASK_PLAYERSOLID); 631 botimport.DebugLineShow(line[1], eye, bsptrace.endpos, LINECOLOR_BLUE); 632 if (bsptrace.fraction < 1.0) 633 { 634 AAS_DrawPlaneCross(bsptrace.endpos, 635 bsptrace.plane.normal, 636 bsptrace.plane.dist,// + bsptrace.exp_dist, 637 bsptrace.plane.type, LINECOLOR_RED); 638 if (bsptrace.ent) 639 { 640 ent = &aasworld.entities[bsptrace.ent]; 641 AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs); 642 } //end if 643 } //end if 644 #endif 645 #endif 646 return 0; 647 } //end of the function BotExportTest 648 649 650 /* 651 ============ 652 Init_AAS_Export 653 ============ 654 */ 655 static void Init_AAS_Export( aas_export_t *aas ) { 656 //-------------------------------------------- 657 // be_aas_entity.c 658 //-------------------------------------------- 659 aas->AAS_EntityInfo = AAS_EntityInfo; 660 //-------------------------------------------- 661 // be_aas_main.c 662 //-------------------------------------------- 663 aas->AAS_Initialized = AAS_Initialized; 664 aas->AAS_PresenceTypeBoundingBox = AAS_PresenceTypeBoundingBox; 665 aas->AAS_Time = AAS_Time; 666 //-------------------------------------------- 667 // be_aas_sample.c 668 //-------------------------------------------- 669 aas->AAS_PointAreaNum = AAS_PointAreaNum; 670 aas->AAS_PointReachabilityAreaIndex = AAS_PointReachabilityAreaIndex; 671 aas->AAS_TraceAreas = AAS_TraceAreas; 672 aas->AAS_BBoxAreas = AAS_BBoxAreas; 673 aas->AAS_AreaInfo = AAS_AreaInfo; 674 //-------------------------------------------- 675 // be_aas_bspq3.c 676 //-------------------------------------------- 677 aas->AAS_PointContents = AAS_PointContents; 678 aas->AAS_NextBSPEntity = AAS_NextBSPEntity; 679 aas->AAS_ValueForBSPEpairKey = AAS_ValueForBSPEpairKey; 680 aas->AAS_VectorForBSPEpairKey = AAS_VectorForBSPEpairKey; 681 aas->AAS_FloatForBSPEpairKey = AAS_FloatForBSPEpairKey; 682 aas->AAS_IntForBSPEpairKey = AAS_IntForBSPEpairKey; 683 //-------------------------------------------- 684 // be_aas_reach.c 685 //-------------------------------------------- 686 aas->AAS_AreaReachability = AAS_AreaReachability; 687 //-------------------------------------------- 688 // be_aas_route.c 689 //-------------------------------------------- 690 aas->AAS_AreaTravelTimeToGoalArea = AAS_AreaTravelTimeToGoalArea; 691 aas->AAS_EnableRoutingArea = AAS_EnableRoutingArea; 692 aas->AAS_PredictRoute = AAS_PredictRoute; 693 //-------------------------------------------- 694 // be_aas_altroute.c 695 //-------------------------------------------- 696 aas->AAS_AlternativeRouteGoals = AAS_AlternativeRouteGoals; 697 //-------------------------------------------- 698 // be_aas_move.c 699 //-------------------------------------------- 700 aas->AAS_Swimming = AAS_Swimming; 701 aas->AAS_PredictClientMovement = AAS_PredictClientMovement; 702 } 703 704 705 /* 706 ============ 707 Init_EA_Export 708 ============ 709 */ 710 static void Init_EA_Export( ea_export_t *ea ) { 711 //ClientCommand elementary actions 712 ea->EA_Command = EA_Command; 713 ea->EA_Say = EA_Say; 714 ea->EA_SayTeam = EA_SayTeam; 715 716 ea->EA_Action = EA_Action; 717 ea->EA_Gesture = EA_Gesture; 718 ea->EA_Talk = EA_Talk; 719 ea->EA_Attack = EA_Attack; 720 ea->EA_Use = EA_Use; 721 ea->EA_Respawn = EA_Respawn; 722 ea->EA_Crouch = EA_Crouch; 723 ea->EA_MoveUp = EA_MoveUp; 724 ea->EA_MoveDown = EA_MoveDown; 725 ea->EA_MoveForward = EA_MoveForward; 726 ea->EA_MoveBack = EA_MoveBack; 727 ea->EA_MoveLeft = EA_MoveLeft; 728 ea->EA_MoveRight = EA_MoveRight; 729 730 ea->EA_SelectWeapon = EA_SelectWeapon; 731 ea->EA_Jump = EA_Jump; 732 ea->EA_DelayedJump = EA_DelayedJump; 733 ea->EA_Move = EA_Move; 734 ea->EA_View = EA_View; 735 ea->EA_GetInput = EA_GetInput; 736 ea->EA_EndRegular = EA_EndRegular; 737 ea->EA_ResetInput = EA_ResetInput; 738 } 739 740 741 /* 742 ============ 743 Init_AI_Export 744 ============ 745 */ 746 static void Init_AI_Export( ai_export_t *ai ) { 747 //----------------------------------- 748 // be_ai_char.h 749 //----------------------------------- 750 ai->BotLoadCharacter = BotLoadCharacter; 751 ai->BotFreeCharacter = BotFreeCharacter; 752 ai->Characteristic_Float = Characteristic_Float; 753 ai->Characteristic_BFloat = Characteristic_BFloat; 754 ai->Characteristic_Integer = Characteristic_Integer; 755 ai->Characteristic_BInteger = Characteristic_BInteger; 756 ai->Characteristic_String = Characteristic_String; 757 //----------------------------------- 758 // be_ai_chat.h 759 //----------------------------------- 760 ai->BotAllocChatState = BotAllocChatState; 761 ai->BotFreeChatState = BotFreeChatState; 762 ai->BotQueueConsoleMessage = BotQueueConsoleMessage; 763 ai->BotRemoveConsoleMessage = BotRemoveConsoleMessage; 764 ai->BotNextConsoleMessage = BotNextConsoleMessage; 765 ai->BotNumConsoleMessages = BotNumConsoleMessages; 766 ai->BotInitialChat = BotInitialChat; 767 ai->BotNumInitialChats = BotNumInitialChats; 768 ai->BotReplyChat = BotReplyChat; 769 ai->BotChatLength = BotChatLength; 770 ai->BotEnterChat = BotEnterChat; 771 ai->BotGetChatMessage = BotGetChatMessage; 772 ai->StringContains = StringContains; 773 ai->BotFindMatch = BotFindMatch; 774 ai->BotMatchVariable = BotMatchVariable; 775 ai->UnifyWhiteSpaces = UnifyWhiteSpaces; 776 ai->BotReplaceSynonyms = BotReplaceSynonyms; 777 ai->BotLoadChatFile = BotLoadChatFile; 778 ai->BotSetChatGender = BotSetChatGender; 779 ai->BotSetChatName = BotSetChatName; 780 //----------------------------------- 781 // be_ai_goal.h 782 //----------------------------------- 783 ai->BotResetGoalState = BotResetGoalState; 784 ai->BotResetAvoidGoals = BotResetAvoidGoals; 785 ai->BotRemoveFromAvoidGoals = BotRemoveFromAvoidGoals; 786 ai->BotPushGoal = BotPushGoal; 787 ai->BotPopGoal = BotPopGoal; 788 ai->BotEmptyGoalStack = BotEmptyGoalStack; 789 ai->BotDumpAvoidGoals = BotDumpAvoidGoals; 790 ai->BotDumpGoalStack = BotDumpGoalStack; 791 ai->BotGoalName = BotGoalName; 792 ai->BotGetTopGoal = BotGetTopGoal; 793 ai->BotGetSecondGoal = BotGetSecondGoal; 794 ai->BotChooseLTGItem = BotChooseLTGItem; 795 ai->BotChooseNBGItem = BotChooseNBGItem; 796 ai->BotTouchingGoal = BotTouchingGoal; 797 ai->BotItemGoalInVisButNotVisible = BotItemGoalInVisButNotVisible; 798 ai->BotGetLevelItemGoal = BotGetLevelItemGoal; 799 ai->BotGetNextCampSpotGoal = BotGetNextCampSpotGoal; 800 ai->BotGetMapLocationGoal = BotGetMapLocationGoal; 801 ai->BotAvoidGoalTime = BotAvoidGoalTime; 802 ai->BotSetAvoidGoalTime = BotSetAvoidGoalTime; 803 ai->BotInitLevelItems = BotInitLevelItems; 804 ai->BotUpdateEntityItems = BotUpdateEntityItems; 805 ai->BotLoadItemWeights = BotLoadItemWeights; 806 ai->BotFreeItemWeights = BotFreeItemWeights; 807 ai->BotInterbreedGoalFuzzyLogic = BotInterbreedGoalFuzzyLogic; 808 ai->BotSaveGoalFuzzyLogic = BotSaveGoalFuzzyLogic; 809 ai->BotMutateGoalFuzzyLogic = BotMutateGoalFuzzyLogic; 810 ai->BotAllocGoalState = BotAllocGoalState; 811 ai->BotFreeGoalState = BotFreeGoalState; 812 //----------------------------------- 813 // be_ai_move.h 814 //----------------------------------- 815 ai->BotResetMoveState = BotResetMoveState; 816 ai->BotMoveToGoal = BotMoveToGoal; 817 ai->BotMoveInDirection = BotMoveInDirection; 818 ai->BotResetAvoidReach = BotResetAvoidReach; 819 ai->BotResetLastAvoidReach = BotResetLastAvoidReach; 820 ai->BotReachabilityArea = BotReachabilityArea; 821 ai->BotMovementViewTarget = BotMovementViewTarget; 822 ai->BotPredictVisiblePosition = BotPredictVisiblePosition; 823 ai->BotAllocMoveState = BotAllocMoveState; 824 ai->BotFreeMoveState = BotFreeMoveState; 825 ai->BotInitMoveState = BotInitMoveState; 826 ai->BotAddAvoidSpot = BotAddAvoidSpot; 827 //----------------------------------- 828 // be_ai_weap.h 829 //----------------------------------- 830 ai->BotChooseBestFightWeapon = BotChooseBestFightWeapon; 831 ai->BotGetWeaponInfo = BotGetWeaponInfo; 832 ai->BotLoadWeaponWeights = BotLoadWeaponWeights; 833 ai->BotAllocWeaponState = BotAllocWeaponState; 834 ai->BotFreeWeaponState = BotFreeWeaponState; 835 ai->BotResetWeaponState = BotResetWeaponState; 836 //----------------------------------- 837 // be_ai_gen.h 838 //----------------------------------- 839 ai->GeneticParentsAndChildSelection = GeneticParentsAndChildSelection; 840 } 841 842 843 /* 844 ============ 845 GetBotLibAPI 846 ============ 847 */ 848 botlib_export_t *GetBotLibAPI(int apiVersion, botlib_import_t *import) { 849 assert(import); // bk001129 - this wasn't set for baseq3/ 850 botimport = *import; 851 assert(botimport.Print); // bk001129 - pars pro toto 852 853 Com_Memset( &be_botlib_export, 0, sizeof( be_botlib_export ) ); 854 855 if ( apiVersion != BOTLIB_API_VERSION ) { 856 botimport.Print( PRT_ERROR, "Mismatched BOTLIB_API_VERSION: expected %i, got %i\n", BOTLIB_API_VERSION, apiVersion ); 857 return NULL; 858 } 859 860 Init_AAS_Export(&be_botlib_export.aas); 861 Init_EA_Export(&be_botlib_export.ea); 862 Init_AI_Export(&be_botlib_export.ai); 863 864 be_botlib_export.BotLibSetup = Export_BotLibSetup; 865 be_botlib_export.BotLibShutdown = Export_BotLibShutdown; 866 be_botlib_export.BotLibVarSet = Export_BotLibVarSet; 867 be_botlib_export.BotLibVarGet = Export_BotLibVarGet; 868 869 be_botlib_export.PC_AddGlobalDefine = PC_AddGlobalDefine; 870 be_botlib_export.PC_LoadSourceHandle = PC_LoadSourceHandle; 871 be_botlib_export.PC_FreeSourceHandle = PC_FreeSourceHandle; 872 be_botlib_export.PC_ReadTokenHandle = PC_ReadTokenHandle; 873 be_botlib_export.PC_SourceFileAndLine = PC_SourceFileAndLine; 874 875 be_botlib_export.BotLibStartFrame = Export_BotLibStartFrame; 876 be_botlib_export.BotLibLoadMap = Export_BotLibLoadMap; 877 be_botlib_export.BotLibUpdateEntity = Export_BotLibUpdateEntity; 878 be_botlib_export.Test = BotExportTest; 879 880 return &be_botlib_export; 881 }