be_interface.c 29 KB

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