Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

be_interface.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 
00023 /*****************************************************************************
00024  * name:        be_interface.c // bk010221 - FIXME - DEAD code elimination
00025  *
00026  * desc:        bot library interface
00027  *
00028  * $Archive: /MissionPack/code/botlib/be_interface.c $
00029  *
00030  *****************************************************************************/
00031 
00032 #include "../game/q_shared.h"
00033 #include "l_memory.h"
00034 #include "l_log.h"
00035 #include "l_libvar.h"
00036 #include "l_script.h"
00037 #include "l_precomp.h"
00038 #include "l_struct.h"
00039 #include "aasfile.h"
00040 #include "../game/botlib.h"
00041 #include "../game/be_aas.h"
00042 #include "be_aas_funcs.h"
00043 #include "be_aas_def.h"
00044 #include "be_interface.h"
00045 
00046 #include "../game/be_ea.h"
00047 #include "be_ai_weight.h"
00048 #include "../game/be_ai_goal.h"
00049 #include "../game/be_ai_move.h"
00050 #include "../game/be_ai_weap.h"
00051 #include "../game/be_ai_chat.h"
00052 #include "../game/be_ai_char.h"
00053 #include "../game/be_ai_gen.h"
00054 
00055 //library globals in a structure
00056 botlib_globals_t botlibglobals;
00057 
00058 botlib_export_t be_botlib_export;
00059 botlib_import_t botimport;
00060 //
00061 int bot_developer;
00062 //qtrue if the library is setup
00063 int botlibsetup = qfalse;
00064 
00065 //===========================================================================
00066 //
00067 // several functions used by the exported functions
00068 //
00069 //===========================================================================
00070 
00071 //===========================================================================
00072 //
00073 // Parameter:               -
00074 // Returns:                 -
00075 // Changes Globals:     -
00076 //===========================================================================
00077 int Sys_MilliSeconds(void)
00078 {
00079     return clock() * 1000 / CLOCKS_PER_SEC;
00080 } //end of the function Sys_MilliSeconds
00081 //===========================================================================
00082 //
00083 // Parameter:               -
00084 // Returns:                 -
00085 // Changes Globals:     -
00086 //===========================================================================
00087 qboolean ValidClientNumber(int num, char *str)
00088 {
00089     if (num < 0 || num > botlibglobals.maxclients)
00090     {
00091         //weird: the disabled stuff results in a crash
00092         botimport.Print(PRT_ERROR, "%s: invalid client number %d, [0, %d]\n",
00093                                         str, num, botlibglobals.maxclients);
00094         return qfalse;
00095     } //end if
00096     return qtrue;
00097 } //end of the function BotValidateClientNumber
00098 //===========================================================================
00099 //
00100 // Parameter:               -
00101 // Returns:                 -
00102 // Changes Globals:     -
00103 //===========================================================================
00104 qboolean ValidEntityNumber(int num, char *str)
00105 {
00106     if (num < 0 || num > botlibglobals.maxentities)
00107     {
00108         botimport.Print(PRT_ERROR, "%s: invalid entity number %d, [0, %d]\n",
00109                                         str, num, botlibglobals.maxentities);
00110         return qfalse;
00111     } //end if
00112     return qtrue;
00113 } //end of the function BotValidateClientNumber
00114 //===========================================================================
00115 //
00116 // Parameter:               -
00117 // Returns:                 -
00118 // Changes Globals:     -
00119 //===========================================================================
00120 qboolean BotLibSetup(char *str)
00121 {
00122     if (!botlibglobals.botlibsetup)
00123     {
00124         botimport.Print(PRT_ERROR, "%s: bot library used before being setup\n", str);
00125         return qfalse;
00126     } //end if
00127     return qtrue;
00128 } //end of the function BotLibSetup
00129 
00130 //===========================================================================
00131 //
00132 // Parameter:               -
00133 // Returns:                 -
00134 // Changes Globals:     -
00135 //===========================================================================
00136 int Export_BotLibSetup(void)
00137 {
00138     int     errnum;
00139     
00140     bot_developer = LibVarGetValue("bot_developer");
00141   memset( &botlibglobals, 0, sizeof(botlibglobals) ); // bk001207 - init
00142     //initialize byte swapping (litte endian etc.)
00143 //  Swap_Init();
00144     Log_Open("botlib.log");
00145     //
00146     botimport.Print(PRT_MESSAGE, "------- BotLib Initialization -------\n");
00147     //
00148     botlibglobals.maxclients = (int) LibVarValue("maxclients", "128");
00149     botlibglobals.maxentities = (int) LibVarValue("maxentities", "1024");
00150 
00151     errnum = AAS_Setup();           //be_aas_main.c
00152     if (errnum != BLERR_NOERROR) return errnum;
00153     errnum = EA_Setup();            //be_ea.c
00154     if (errnum != BLERR_NOERROR) return errnum;
00155     errnum = BotSetupWeaponAI();    //be_ai_weap.c
00156     if (errnum != BLERR_NOERROR)return errnum;
00157     errnum = BotSetupGoalAI();      //be_ai_goal.c
00158     if (errnum != BLERR_NOERROR) return errnum;
00159     errnum = BotSetupChatAI();      //be_ai_chat.c
00160     if (errnum != BLERR_NOERROR) return errnum;
00161     errnum = BotSetupMoveAI();      //be_ai_move.c
00162     if (errnum != BLERR_NOERROR) return errnum;
00163 
00164     botlibsetup = qtrue;
00165     botlibglobals.botlibsetup = qtrue;
00166 
00167     return BLERR_NOERROR;
00168 } //end of the function Export_BotLibSetup
00169 //===========================================================================
00170 //
00171 // Parameter:               -
00172 // Returns:                 -
00173 // Changes Globals:     -
00174 //===========================================================================
00175 int Export_BotLibShutdown(void)
00176 {
00177     if (!BotLibSetup("BotLibShutdown")) return BLERR_LIBRARYNOTSETUP;
00178 #ifndef DEMO
00179     //DumpFileCRCs();
00180 #endif //DEMO
00181     //
00182     BotShutdownChatAI();        //be_ai_chat.c
00183     BotShutdownMoveAI();        //be_ai_move.c
00184     BotShutdownGoalAI();        //be_ai_goal.c
00185     BotShutdownWeaponAI();      //be_ai_weap.c
00186     BotShutdownWeights();       //be_ai_weight.c
00187     BotShutdownCharacters();    //be_ai_char.c
00188     //shud down aas
00189     AAS_Shutdown();
00190     //shut down bot elemantary actions
00191     EA_Shutdown();
00192     //free all libvars
00193     LibVarDeAllocAll();
00194     //remove all global defines from the pre compiler
00195     PC_RemoveAllGlobalDefines();
00196 
00197     //dump all allocated memory
00198 //  DumpMemory();
00199 #ifdef DEBUG
00200     PrintMemoryLabels();
00201 #endif
00202     //shut down library log file
00203     Log_Shutdown();
00204     //
00205     botlibsetup = qfalse;
00206     botlibglobals.botlibsetup = qfalse;
00207     // print any files still open
00208     PC_CheckOpenSourceHandles();
00209     //
00210     return BLERR_NOERROR;
00211 } //end of the function Export_BotLibShutdown
00212 //===========================================================================
00213 //
00214 // Parameter:               -
00215 // Returns:                 -
00216 // Changes Globals:     -
00217 //===========================================================================
00218 int Export_BotLibVarSet(char *var_name, char *value)
00219 {
00220     LibVarSet(var_name, value);
00221     return BLERR_NOERROR;
00222 } //end of the function Export_BotLibVarSet
00223 //===========================================================================
00224 //
00225 // Parameter:               -
00226 // Returns:                 -
00227 // Changes Globals:     -
00228 //===========================================================================
00229 int Export_BotLibVarGet(char *var_name, char *value, int size)
00230 {
00231     char *varvalue;
00232 
00233     varvalue = LibVarGetString(var_name);
00234     strncpy(value, varvalue, size-1);
00235     value[size-1] = '\0';
00236     return BLERR_NOERROR;
00237 } //end of the function Export_BotLibVarGet
00238 //===========================================================================
00239 //
00240 // Parameter:               -
00241 // Returns:                 -
00242 // Changes Globals:     -
00243 //===========================================================================
00244 int Export_BotLibStartFrame(float time)
00245 {
00246     if (!BotLibSetup("BotStartFrame")) return BLERR_LIBRARYNOTSETUP;
00247     return AAS_StartFrame(time);
00248 } //end of the function Export_BotLibStartFrame
00249 //===========================================================================
00250 //
00251 // Parameter:               -
00252 // Returns:                 -
00253 // Changes Globals:     -
00254 //===========================================================================
00255 int Export_BotLibLoadMap(const char *mapname)
00256 {
00257 #ifdef DEBUG
00258     int starttime = Sys_MilliSeconds();
00259 #endif
00260     int errnum;
00261 
00262     if (!BotLibSetup("BotLoadMap")) return BLERR_LIBRARYNOTSETUP;
00263     //
00264     botimport.Print(PRT_MESSAGE, "------------ Map Loading ------------\n");
00265     //startup AAS for the current map, model and sound index
00266     errnum = AAS_LoadMap(mapname);
00267     if (errnum != BLERR_NOERROR) return errnum;
00268     //initialize the items in the level
00269     BotInitLevelItems();        //be_ai_goal.h
00270     BotSetBrushModelTypes();    //be_ai_move.h
00271     //
00272     botimport.Print(PRT_MESSAGE, "-------------------------------------\n");
00273 #ifdef DEBUG
00274     botimport.Print(PRT_MESSAGE, "map loaded in %d msec\n", Sys_MilliSeconds() - starttime);
00275 #endif
00276     //
00277     return BLERR_NOERROR;
00278 } //end of the function Export_BotLibLoadMap
00279 //===========================================================================
00280 //
00281 // Parameter:               -
00282 // Returns:                 -
00283 // Changes Globals:     -
00284 //===========================================================================
00285 int Export_BotLibUpdateEntity(int ent, bot_entitystate_t *state)
00286 {
00287     if (!BotLibSetup("BotUpdateEntity")) return BLERR_LIBRARYNOTSETUP;
00288     if (!ValidEntityNumber(ent, "BotUpdateEntity")) return BLERR_INVALIDENTITYNUMBER;
00289 
00290     return AAS_UpdateEntity(ent, state);
00291 } //end of the function Export_BotLibUpdateEntity
00292 //===========================================================================
00293 //
00294 // Parameter:               -
00295 // Returns:                 -
00296 // Changes Globals:     -
00297 //===========================================================================
00298 void AAS_TestMovementPrediction(int entnum, vec3_t origin, vec3_t dir);
00299 void ElevatorBottomCenter(aas_reachability_t *reach, vec3_t bottomcenter);
00300 int BotGetReachabilityToGoal(vec3_t origin, int areanum,
00301                                       int lastgoalareanum, int lastareanum,
00302                                       int *avoidreach, float *avoidreachtimes, int *avoidreachtries,
00303                                       bot_goal_t *goal, int travelflags, int movetravelflags,
00304                                       struct bot_avoidspot_s *avoidspots, int numavoidspots, int *flags);
00305 
00306 int AAS_PointLight(vec3_t origin, int *red, int *green, int *blue);
00307 
00308 int AAS_TraceAreas(vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas);
00309 
00310 int AAS_Reachability_WeaponJump(int area1num, int area2num);
00311 
00312 int BotFuzzyPointReachabilityArea(vec3_t origin);
00313 
00314 float BotGapDistance(vec3_t origin, vec3_t hordir, int entnum);
00315 
00316 void AAS_FloodAreas(vec3_t origin);
00317 
00318 int BotExportTest(int parm0, char *parm1, vec3_t parm2, vec3_t parm3)
00319 {
00320 
00321 //  return AAS_PointLight(parm2, NULL, NULL, NULL);
00322 
00323 #ifdef DEBUG
00324     static int area = -1;
00325     static int line[2];
00326     int newarea, i, highlightarea, flood;
00327 //  int reachnum;
00328     vec3_t eye, forward, right, end, origin;
00329 //  vec3_t bottomcenter;
00330 //  aas_trace_t trace;
00331 //  aas_face_t *face;
00332 //  aas_entity_t *ent;
00333 //  bsp_trace_t bsptrace;
00334 //  aas_reachability_t reach;
00335 //  bot_goal_t goal;
00336 
00337     // clock_t start_time, end_time;
00338     vec3_t mins = {-16, -16, -24};
00339     vec3_t maxs = {16, 16, 32};
00340 
00341 //  int areas[10], numareas;
00342 
00343 
00344     //return 0;
00345 
00346     if (!aasworld.loaded) return 0;
00347 
00348     /*
00349     if (parm0 & 1)
00350     {
00351         AAS_ClearShownPolygons();
00352         AAS_FloodAreas(parm2);
00353     } //end if
00354     return 0;
00355     */
00356     for (i = 0; i < 2; i++) if (!line[i]) line[i] = botimport.DebugLineCreate();
00357 
00358 //  AAS_ClearShownDebugLines();
00359 
00360     //if (AAS_AgainstLadder(parm2)) botimport.Print(PRT_MESSAGE, "against ladder\n");
00361     //BotOnGround(parm2, PRESENCE_NORMAL, 1, &newarea, &newarea);
00362     //botimport.Print(PRT_MESSAGE, "%f %f %f\n", parm2[0], parm2[1], parm2[2]);
00363     //*
00364     highlightarea = LibVarGetValue("bot_highlightarea");
00365     if (highlightarea > 0)
00366     {
00367         newarea = highlightarea;
00368     } //end if
00369     else
00370     {
00371         VectorCopy(parm2, origin);
00372         origin[2] += 0.5;
00373         //newarea = AAS_PointAreaNum(origin);
00374         newarea = BotFuzzyPointReachabilityArea(origin);
00375     } //end else
00376 
00377     botimport.Print(PRT_MESSAGE, "\rtravel time to goal (%d) = %d  ", botlibglobals.goalareanum,
00378         AAS_AreaTravelTimeToGoalArea(newarea, origin, botlibglobals.goalareanum, TFL_DEFAULT));
00379     //newarea = BotReachabilityArea(origin, qtrue);
00380     if (newarea != area)
00381     {
00382         botimport.Print(PRT_MESSAGE, "origin = %f, %f, %f\n", origin[0], origin[1], origin[2]);
00383         area = newarea;
00384         botimport.Print(PRT_MESSAGE, "new area %d, cluster %d, presence type %d\n",
00385                     area, AAS_AreaCluster(area), AAS_PointPresenceType(origin));
00386         botimport.Print(PRT_MESSAGE, "area contents: ");
00387         if (aasworld.areasettings[area].contents & AREACONTENTS_WATER)
00388         {
00389             botimport.Print(PRT_MESSAGE, "water &");
00390         } //end if
00391         if (aasworld.areasettings[area].contents & AREACONTENTS_LAVA)
00392         {
00393             botimport.Print(PRT_MESSAGE, "lava &");
00394         } //end if
00395         if (aasworld.areasettings[area].contents & AREACONTENTS_SLIME)
00396         {
00397             botimport.Print(PRT_MESSAGE, "slime &");
00398         } //end if
00399         if (aasworld.areasettings[area].contents & AREACONTENTS_JUMPPAD)
00400         {
00401             botimport.Print(PRT_MESSAGE, "jump pad &");
00402         } //end if
00403         if (aasworld.areasettings[area].contents & AREACONTENTS_CLUSTERPORTAL)
00404         {
00405             botimport.Print(PRT_MESSAGE, "cluster portal &");
00406         } //end if
00407         if (aasworld.areasettings[area].contents & AREACONTENTS_VIEWPORTAL)
00408         {
00409             botimport.Print(PRT_MESSAGE, "view portal &");
00410         } //end if
00411         if (aasworld.areasettings[area].contents & AREACONTENTS_DONOTENTER)
00412         {
00413             botimport.Print(PRT_MESSAGE, "do not enter &");
00414         } //end if
00415         if (aasworld.areasettings[area].contents & AREACONTENTS_MOVER)
00416         {
00417             botimport.Print(PRT_MESSAGE, "mover &");
00418         } //end if
00419         if (!aasworld.areasettings[area].contents)
00420         {
00421             botimport.Print(PRT_MESSAGE, "empty");
00422         } //end if
00423         botimport.Print(PRT_MESSAGE, "\n");
00424         botimport.Print(PRT_MESSAGE, "travel time to goal (%d) = %d\n", botlibglobals.goalareanum,
00425                     AAS_AreaTravelTimeToGoalArea(newarea, origin, botlibglobals.goalareanum, TFL_DEFAULT|TFL_ROCKETJUMP));
00426         /*
00427         VectorCopy(origin, end);
00428         end[2] += 5;
00429         numareas = AAS_TraceAreas(origin, end, areas, NULL, 10);
00430         AAS_TraceClientBBox(origin, end, PRESENCE_CROUCH, -1);
00431         botimport.Print(PRT_MESSAGE, "num areas = %d, area = %d\n", numareas, areas[0]);
00432         */
00433         /*
00434         botlibglobals.goalareanum = newarea;
00435         VectorCopy(parm2, botlibglobals.goalorigin);
00436         botimport.Print(PRT_MESSAGE, "new goal %2.1f %2.1f %2.1f area %d\n",
00437                                 origin[0], origin[1], origin[2], newarea);
00438         */
00439     } //end if
00440     //*
00441     flood = LibVarGetValue("bot_flood");
00442     if (parm0 & 1)
00443     {
00444         if (flood)
00445         {
00446             AAS_ClearShownPolygons();
00447             AAS_ClearShownDebugLines();
00448             AAS_FloodAreas(parm2);
00449         }
00450         else
00451         {
00452             botlibglobals.goalareanum = newarea;
00453             VectorCopy(parm2, botlibglobals.goalorigin);
00454             botimport.Print(PRT_MESSAGE, "new goal %2.1f %2.1f %2.1f area %d\n",
00455                                     origin[0], origin[1], origin[2], newarea);
00456         }
00457     } //end if*/
00458     if (flood)
00459         return 0;
00460 //  if (parm0 & BUTTON_USE)
00461 //  {
00462 //      botlibglobals.runai = !botlibglobals.runai;
00463 //      if (botlibglobals.runai) botimport.Print(PRT_MESSAGE, "started AI\n");
00464 //      else botimport.Print(PRT_MESSAGE, "stopped AI\n");
00465         //* /
00466         /*
00467         goal.areanum = botlibglobals.goalareanum;
00468         reachnum = BotGetReachabilityToGoal(parm2, newarea, 1,
00469                                         ms.avoidreach, ms.avoidreachtimes,
00470                                         &goal, TFL_DEFAULT);
00471         if (!reachnum)
00472         {
00473             botimport.Print(PRT_MESSAGE, "goal not reachable\n");
00474         } //end if
00475         else
00476         {
00477             AAS_ReachabilityFromNum(reachnum, &reach);
00478             AAS_ClearShownDebugLines();
00479             AAS_ShowArea(area, qtrue);
00480             AAS_ShowArea(reach.areanum, qtrue);
00481             AAS_DrawCross(reach.start, 6, LINECOLOR_BLUE);
00482             AAS_DrawCross(reach.end, 6, LINECOLOR_RED);
00483             //
00484             if ((reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_ELEVATOR)
00485             {
00486                 ElevatorBottomCenter(&reach, bottomcenter);
00487                 AAS_DrawCross(bottomcenter, 10, LINECOLOR_GREEN);
00488             } //end if
00489         } //end else*/
00490 //      botimport.Print(PRT_MESSAGE, "travel time to goal = %d\n",
00491 //                  AAS_AreaTravelTimeToGoalArea(area, origin, botlibglobals.goalareanum, TFL_DEFAULT));
00492 //      botimport.Print(PRT_MESSAGE, "test rj from 703 to 716\n");
00493 //      AAS_Reachability_WeaponJump(703, 716);
00494 //  } //end if*/
00495 
00496 /*  face = AAS_AreaGroundFace(newarea, parm2);
00497     if (face)
00498     {
00499         AAS_ShowFace(face - aasworld.faces);
00500     } //end if*/
00501     /*
00502     AAS_ClearShownDebugLines();
00503     AAS_ShowArea(newarea, parm0 & BUTTON_USE);
00504     AAS_ShowReachableAreas(area);
00505     */
00506     AAS_ClearShownPolygons();
00507     AAS_ClearShownDebugLines();
00508     AAS_ShowAreaPolygons(newarea, 1, parm0 & 4);
00509     if (parm0 & 2) AAS_ShowReachableAreas(area);
00510     else
00511     {
00512         static int lastgoalareanum, lastareanum;
00513         static int avoidreach[MAX_AVOIDREACH];
00514         static float avoidreachtimes[MAX_AVOIDREACH];
00515         static int avoidreachtries[MAX_AVOIDREACH];
00516         int reachnum, resultFlags;
00517         bot_goal_t goal;
00518         aas_reachability_t reach;
00519 
00520         /*
00521         goal.areanum = botlibglobals.goalareanum;
00522         VectorCopy(botlibglobals.goalorigin, goal.origin);
00523         reachnum = BotGetReachabilityToGoal(origin, newarea,
00524                                       lastgoalareanum, lastareanum,
00525                                       avoidreach, avoidreachtimes, avoidreachtries,
00526                                       &goal, TFL_DEFAULT|TFL_FUNCBOB|TFL_ROCKETJUMP, TFL_DEFAULT|TFL_FUNCBOB|TFL_ROCKETJUMP,
00527                                       NULL, 0, &resultFlags);
00528         AAS_ReachabilityFromNum(reachnum, &reach);
00529         AAS_ShowReachability(&reach);
00530         */
00531         int curarea;
00532         vec3_t curorigin;
00533 
00534         goal.areanum = botlibglobals.goalareanum;
00535         VectorCopy(botlibglobals.goalorigin, goal.origin);
00536         VectorCopy(origin, curorigin);
00537         curarea = newarea;
00538         for ( i = 0; i < 100; i++ ) {
00539             if ( curarea == goal.areanum ) {
00540                 break;
00541             }
00542             reachnum = BotGetReachabilityToGoal(curorigin, curarea,
00543                                           lastgoalareanum, lastareanum,
00544                                           avoidreach, avoidreachtimes, avoidreachtries,
00545                                           &goal, TFL_DEFAULT|TFL_FUNCBOB|TFL_ROCKETJUMP, TFL_DEFAULT|TFL_FUNCBOB|TFL_ROCKETJUMP,
00546                                           NULL, 0, &resultFlags);
00547             AAS_ReachabilityFromNum(reachnum, &reach);
00548             AAS_ShowReachability(&reach);
00549             VectorCopy(reach.end, origin);
00550             lastareanum = curarea;
00551             curarea = reach.areanum;
00552         }
00553     } //end else
00554     VectorClear(forward);
00555     //BotGapDistance(origin, forward, 0);
00556     /*
00557     if (parm0 & BUTTON_USE)
00558     {
00559         botimport.Print(PRT_MESSAGE, "test rj from 703 to 716\n");
00560         AAS_Reachability_WeaponJump(703, 716);
00561     } //end if*/
00562 
00563     AngleVectors(parm3, forward, right, NULL);
00564     //get the eye 16 units to the right of the origin
00565     VectorMA(parm2, 8, right, eye);
00566     //get the eye 24 units up
00567     eye[2] += 24;
00568     //get the end point for the line to be traced
00569     VectorMA(eye, 800, forward, end);
00570 
00571 //  AAS_TestMovementPrediction(1, parm2, forward);
00572 /*
00573     //trace the line to find the hit point
00574     trace = AAS_TraceClientBBox(eye, end, PRESENCE_NORMAL, 1);
00575     if (!line[0]) line[0] = botimport.DebugLineCreate();
00576     botimport.DebugLineShow(line[0], eye, trace.endpos, LINECOLOR_BLUE);
00577     //
00578     AAS_ClearShownDebugLines();
00579     if (trace.ent)
00580     {
00581         ent = &aasworld.entities[trace.ent];
00582         AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs);
00583     } //end if
00584 */
00585 
00586 /*
00587     start_time = clock();
00588     for (i = 0; i < 2000; i++)
00589     {
00590         AAS_Trace2(eye, mins, maxs, end, 1, MASK_PLAYERSOLID);
00591 //      AAS_TraceClientBBox(eye, end, PRESENCE_NORMAL, 1);
00592     } //end for
00593     end_time = clock();
00594     botimport.Print(PRT_MESSAGE, "me %lu clocks, %lu CLOCKS_PER_SEC\n", end_time - start_time, CLOCKS_PER_SEC);
00595     start_time = clock();
00596     for (i = 0; i < 2000; i++)
00597     {
00598         AAS_Trace(eye, mins, maxs, end, 1, MASK_PLAYERSOLID);
00599     } //end for
00600     end_time = clock();
00601     botimport.Print(PRT_MESSAGE, "id %lu clocks, %lu CLOCKS_PER_SEC\n", end_time - start_time, CLOCKS_PER_SEC);
00602 */
00603 
00604     // TTimo: nested comments are BAD for gcc -Werror, use #if 0 instead..
00605 #if 0
00606     AAS_ClearShownDebugLines();
00607     //bsptrace = AAS_Trace(eye, NULL, NULL, end, 1, MASK_PLAYERSOLID);
00608     bsptrace = AAS_Trace(eye, mins, maxs, end, 1, MASK_PLAYERSOLID);
00609     if (!line[0]) line[0] = botimport.DebugLineCreate();
00610     botimport.DebugLineShow(line[0], eye, bsptrace.endpos, LINECOLOR_YELLOW);
00611     if (bsptrace.fraction < 1.0)
00612     {
00613         face = AAS_TraceEndFace(&trace);
00614         if (face)
00615         {
00616             AAS_ShowFace(face - aasworld.faces);
00617         } //end if
00618         
00619         AAS_DrawPlaneCross(bsptrace.endpos,
00620                                     bsptrace.plane.normal,
00621                                     bsptrace.plane.dist + bsptrace.exp_dist,
00622                                     bsptrace.plane.type, LINECOLOR_GREEN);
00623         if (trace.ent)
00624         {
00625             ent = &aasworld.entities[trace.ent];
00626             AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs);
00627         } //end if
00628     } //end if
00629     //bsptrace = AAS_Trace2(eye, NULL, NULL, end, 1, MASK_PLAYERSOLID);
00630     bsptrace = AAS_Trace2(eye, mins, maxs, end, 1, MASK_PLAYERSOLID);
00631     botimport.DebugLineShow(line[1], eye, bsptrace.endpos, LINECOLOR_BLUE);
00632     if (bsptrace.fraction < 1.0)
00633     {
00634         AAS_DrawPlaneCross(bsptrace.endpos,
00635                                     bsptrace.plane.normal,
00636                                     bsptrace.plane.dist,// + bsptrace.exp_dist,
00637                                     bsptrace.plane.type, LINECOLOR_RED);
00638         if (bsptrace.ent)
00639         {
00640             ent = &aasworld.entities[bsptrace.ent];
00641             AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs);
00642         } //end if
00643     } //end if
00644 #endif
00645 #endif
00646     return 0;
00647 } //end of the function BotExportTest
00648 
00649 
00650 /*
00651 ============
00652 Init_AAS_Export
00653 ============
00654 */
00655 static void Init_AAS_Export( aas_export_t *aas ) {
00656     //--------------------------------------------
00657     // be_aas_entity.c
00658     //--------------------------------------------
00659     aas->AAS_EntityInfo = AAS_EntityInfo;
00660     //--------------------------------------------
00661     // be_aas_main.c
00662     //--------------------------------------------
00663     aas->AAS_Initialized = AAS_Initialized;
00664     aas->AAS_PresenceTypeBoundingBox = AAS_PresenceTypeBoundingBox;
00665     aas->AAS_Time = AAS_Time;
00666     //--------------------------------------------
00667     // be_aas_sample.c
00668     //--------------------------------------------
00669     aas->AAS_PointAreaNum = AAS_PointAreaNum;
00670     aas->AAS_PointReachabilityAreaIndex = AAS_PointReachabilityAreaIndex;
00671     aas->AAS_TraceAreas = AAS_TraceAreas;
00672     aas->AAS_BBoxAreas = AAS_BBoxAreas;
00673     aas->AAS_AreaInfo = AAS_AreaInfo;
00674     //--------------------------------------------
00675     // be_aas_bspq3.c
00676     //--------------------------------------------
00677     aas->AAS_PointContents = AAS_PointContents;
00678     aas->AAS_NextBSPEntity = AAS_NextBSPEntity;
00679     aas->AAS_ValueForBSPEpairKey = AAS_ValueForBSPEpairKey;
00680     aas->AAS_VectorForBSPEpairKey = AAS_VectorForBSPEpairKey;
00681     aas->AAS_FloatForBSPEpairKey = AAS_FloatForBSPEpairKey;
00682     aas->AAS_IntForBSPEpairKey = AAS_IntForBSPEpairKey;
00683     //--------------------------------------------
00684     // be_aas_reach.c
00685     //--------------------------------------------
00686     aas->AAS_AreaReachability = AAS_AreaReachability;
00687     //--------------------------------------------
00688     // be_aas_route.c
00689     //--------------------------------------------
00690     aas->AAS_AreaTravelTimeToGoalArea = AAS_AreaTravelTimeToGoalArea;
00691     aas->AAS_EnableRoutingArea = AAS_EnableRoutingArea;
00692     aas->AAS_PredictRoute = AAS_PredictRoute;
00693     //--------------------------------------------
00694     // be_aas_altroute.c
00695     //--------------------------------------------
00696     aas->AAS_AlternativeRouteGoals = AAS_AlternativeRouteGoals;
00697     //--------------------------------------------
00698     // be_aas_move.c
00699     //--------------------------------------------
00700     aas->AAS_Swimming = AAS_Swimming;
00701     aas->AAS_PredictClientMovement = AAS_PredictClientMovement;
00702 }
00703 
00704   
00705 /*
00706 ============
00707 Init_EA_Export
00708 ============
00709 */
00710 static void Init_EA_Export( ea_export_t *ea ) {
00711     //ClientCommand elementary actions
00712     ea->EA_Command = EA_Command;
00713     ea->EA_Say = EA_Say;
00714     ea->EA_SayTeam = EA_SayTeam;
00715 
00716     ea->EA_Action = EA_Action;
00717     ea->EA_Gesture = EA_Gesture;
00718     ea->EA_Talk = EA_Talk;
00719     ea->EA_Attack = EA_Attack;
00720     ea->EA_Use = EA_Use;
00721     ea->EA_Respawn = EA_Respawn;
00722     ea->EA_Crouch = EA_Crouch;
00723     ea->EA_MoveUp = EA_MoveUp;
00724     ea->EA_MoveDown = EA_MoveDown;
00725     ea->EA_MoveForward = EA_MoveForward;
00726     ea->EA_MoveBack = EA_MoveBack;
00727     ea->EA_MoveLeft = EA_MoveLeft;
00728     ea->EA_MoveRight = EA_MoveRight;
00729 
00730     ea->EA_SelectWeapon = EA_SelectWeapon;
00731     ea->EA_Jump = EA_Jump;
00732     ea->EA_DelayedJump = EA_DelayedJump;
00733     ea->EA_Move = EA_Move;
00734     ea->EA_View = EA_View;
00735     ea->EA_GetInput = EA_GetInput;
00736     ea->EA_EndRegular = EA_EndRegular;
00737     ea->EA_ResetInput = EA_ResetInput;
00738 }
00739 
00740 
00741 /*
00742 ============
00743 Init_AI_Export
00744 ============
00745 */
00746 static void Init_AI_Export( ai_export_t *ai ) {
00747     //-----------------------------------
00748     // be_ai_char.h
00749     //-----------------------------------
00750     ai->BotLoadCharacter = BotLoadCharacter;
00751     ai->BotFreeCharacter = BotFreeCharacter;
00752     ai->Characteristic_Float = Characteristic_Float;
00753     ai->Characteristic_BFloat = Characteristic_BFloat;
00754     ai->Characteristic_Integer = Characteristic_Integer;
00755     ai->Characteristic_BInteger = Characteristic_BInteger;
00756     ai->Characteristic_String = Characteristic_String;
00757     //-----------------------------------
00758     // be_ai_chat.h
00759     //-----------------------------------
00760     ai->BotAllocChatState = BotAllocChatState;
00761     ai->BotFreeChatState = BotFreeChatState;
00762     ai->BotQueueConsoleMessage = BotQueueConsoleMessage;
00763     ai->BotRemoveConsoleMessage = BotRemoveConsoleMessage;
00764     ai->BotNextConsoleMessage = BotNextConsoleMessage;
00765     ai->BotNumConsoleMessages = BotNumConsoleMessages;
00766     ai->BotInitialChat = BotInitialChat;
00767     ai->BotNumInitialChats = BotNumInitialChats;
00768     ai->BotReplyChat = BotReplyChat;
00769     ai->BotChatLength = BotChatLength;
00770     ai->BotEnterChat = BotEnterChat;
00771     ai->BotGetChatMessage = BotGetChatMessage;
00772     ai->StringContains = StringContains;
00773     ai->BotFindMatch = BotFindMatch;
00774     ai->BotMatchVariable = BotMatchVariable;
00775     ai->UnifyWhiteSpaces = UnifyWhiteSpaces;
00776     ai->BotReplaceSynonyms = BotReplaceSynonyms;
00777     ai->BotLoadChatFile = BotLoadChatFile;
00778     ai->BotSetChatGender = BotSetChatGender;
00779     ai->BotSetChatName = BotSetChatName;
00780     //-----------------------------------
00781     // be_ai_goal.h
00782     //-----------------------------------
00783     ai->BotResetGoalState = BotResetGoalState;
00784     ai->BotResetAvoidGoals = BotResetAvoidGoals;
00785     ai->BotRemoveFromAvoidGoals = BotRemoveFromAvoidGoals;
00786     ai->BotPushGoal = BotPushGoal;
00787     ai->BotPopGoal = BotPopGoal;
00788     ai->BotEmptyGoalStack = BotEmptyGoalStack;
00789     ai->BotDumpAvoidGoals = BotDumpAvoidGoals;
00790     ai->BotDumpGoalStack = BotDumpGoalStack;
00791     ai->BotGoalName = BotGoalName;
00792     ai->BotGetTopGoal = BotGetTopGoal;
00793     ai->BotGetSecondGoal = BotGetSecondGoal;
00794     ai->BotChooseLTGItem = BotChooseLTGItem;
00795     ai->BotChooseNBGItem = BotChooseNBGItem;
00796     ai->BotTouchingGoal = BotTouchingGoal;
00797     ai->BotItemGoalInVisButNotVisible = BotItemGoalInVisButNotVisible;
00798     ai->BotGetLevelItemGoal = BotGetLevelItemGoal;
00799     ai->BotGetNextCampSpotGoal = BotGetNextCampSpotGoal;
00800     ai->BotGetMapLocationGoal = BotGetMapLocationGoal;
00801     ai->BotAvoidGoalTime = BotAvoidGoalTime;
00802     ai->BotSetAvoidGoalTime = BotSetAvoidGoalTime;
00803     ai->BotInitLevelItems = BotInitLevelItems;
00804     ai->BotUpdateEntityItems = BotUpdateEntityItems;
00805     ai->BotLoadItemWeights = BotLoadItemWeights;
00806     ai->BotFreeItemWeights = BotFreeItemWeights;
00807     ai->BotInterbreedGoalFuzzyLogic = BotInterbreedGoalFuzzyLogic;
00808     ai->BotSaveGoalFuzzyLogic = BotSaveGoalFuzzyLogic;
00809     ai->BotMutateGoalFuzzyLogic = BotMutateGoalFuzzyLogic;
00810     ai->BotAllocGoalState = BotAllocGoalState;
00811     ai->BotFreeGoalState = BotFreeGoalState;
00812     //-----------------------------------
00813     // be_ai_move.h
00814     //-----------------------------------
00815     ai->BotResetMoveState = BotResetMoveState;
00816     ai->BotMoveToGoal = BotMoveToGoal;
00817     ai->BotMoveInDirection = BotMoveInDirection;
00818     ai->BotResetAvoidReach = BotResetAvoidReach;
00819     ai->BotResetLastAvoidReach = BotResetLastAvoidReach;
00820     ai->BotReachabilityArea = BotReachabilityArea;
00821     ai->BotMovementViewTarget = BotMovementViewTarget;
00822     ai->BotPredictVisiblePosition = BotPredictVisiblePosition;
00823     ai->BotAllocMoveState = BotAllocMoveState;
00824     ai->BotFreeMoveState = BotFreeMoveState;
00825     ai->BotInitMoveState = BotInitMoveState;
00826     ai->BotAddAvoidSpot = BotAddAvoidSpot;
00827     //-----------------------------------
00828     // be_ai_weap.h
00829     //-----------------------------------
00830     ai->BotChooseBestFightWeapon = BotChooseBestFightWeapon;
00831     ai->BotGetWeaponInfo = BotGetWeaponInfo;
00832     ai->BotLoadWeaponWeights = BotLoadWeaponWeights;
00833     ai->BotAllocWeaponState = BotAllocWeaponState;
00834     ai->BotFreeWeaponState = BotFreeWeaponState;
00835     ai->BotResetWeaponState = BotResetWeaponState;
00836     //-----------------------------------
00837     // be_ai_gen.h
00838     //-----------------------------------
00839     ai->GeneticParentsAndChildSelection = GeneticParentsAndChildSelection;
00840 }
00841 
00842 
00843 /*
00844 ============
00845 GetBotLibAPI
00846 ============
00847 */
00848 botlib_export_t *GetBotLibAPI(int apiVersion, botlib_import_t *import) {
00849     assert(import);   // bk001129 - this wasn't set for baseq3/
00850   botimport = *import;
00851   assert(botimport.Print);   // bk001129 - pars pro toto
00852 
00853     Com_Memset( &be_botlib_export, 0, sizeof( be_botlib_export ) );
00854 
00855     if ( apiVersion != BOTLIB_API_VERSION ) {
00856         botimport.Print( PRT_ERROR, "Mismatched BOTLIB_API_VERSION: expected %i, got %i\n", BOTLIB_API_VERSION, apiVersion );
00857         return NULL;
00858     }
00859 
00860     Init_AAS_Export(&be_botlib_export.aas);
00861     Init_EA_Export(&be_botlib_export.ea);
00862     Init_AI_Export(&be_botlib_export.ai);
00863 
00864     be_botlib_export.BotLibSetup = Export_BotLibSetup;
00865     be_botlib_export.BotLibShutdown = Export_BotLibShutdown;
00866     be_botlib_export.BotLibVarSet = Export_BotLibVarSet;
00867     be_botlib_export.BotLibVarGet = Export_BotLibVarGet;
00868 
00869     be_botlib_export.PC_AddGlobalDefine = PC_AddGlobalDefine;
00870     be_botlib_export.PC_LoadSourceHandle = PC_LoadSourceHandle;
00871     be_botlib_export.PC_FreeSourceHandle = PC_FreeSourceHandle;
00872     be_botlib_export.PC_ReadTokenHandle = PC_ReadTokenHandle;
00873     be_botlib_export.PC_SourceFileAndLine = PC_SourceFileAndLine;
00874 
00875     be_botlib_export.BotLibStartFrame = Export_BotLibStartFrame;
00876     be_botlib_export.BotLibLoadMap = Export_BotLibLoadMap;
00877     be_botlib_export.BotLibUpdateEntity = Export_BotLibUpdateEntity;
00878     be_botlib_export.Test = BotExportTest;
00879 
00880     return &be_botlib_export;
00881 }

Generated on Thu Aug 25 12:37:12 2005 for Quake III Arena by  doxygen 1.3.9.1