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