Debian Codegraph @

code/botlib/be_interface.c

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