/
noire-dev
/
SourceTech
Обзор
Документация
Войти
/
noire-dev
/
SourceTech
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
sourcetech
code/botlib/be_interface.c
406 строк
13 KB
noire-dev
Update: 2025-12-07 18:12 Clear botlib
07 дек 2025, 09:12
07 дек 2025, 09:12
949b3de
Код
Авторство
О чём код?
/* =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. This file is part of Quake III Arena source code. Quake III Arena source code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Quake III Arena source code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Quake III Arena source code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ /***************************************************************************** * name: be_interface.c * * desc: bot library interface * * $Archive: /MissionPack/code/botlib/be_interface.c $ * *****************************************************************************/ #include "../qcommon/q_shared.h" #include "l_memory.h" #include "l_log.h" #include "l_libvar.h" #include "l_script.h" #include "l_precomp.h" #include "l_struct.h" #include "aasfile.h" #include "botlib.h" #include "be_aas.h" #include "be_aas_funcs.h" #include "be_aas_def.h" #include "be_interface.h" #include "be_ea.h" #include "be_ai_move.h" //library globals in a structure botlib_globals_t botlibglobals; botlib_export_t be_botlib_export; botlib_import_t botimport; // int botDeveloper; //qtrue if the library is setup int botlibsetup = qfalse; //=========================================================================== // // several functions used by the exported functions // //=========================================================================== //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int Sys_MilliSeconds(void) { return clock() * 1000 / CLOCKS_PER_SEC; } //end of the function Sys_MilliSeconds //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== static qboolean ValidEntityNumber(int num, const char *str) { if ( /*num < 0 || */ (unsigned)num > botlibglobals.maxentities ) { botimport.Print(PRT_ERROR, "%s: invalid entity number %d, [0, %d]\n", str, num, botlibglobals.maxentities); return qfalse; } //end if return qtrue; } //end of the function BotValidateClientNumber //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== static qboolean BotLibSetup(const char *str) { if (!botlibglobals.botlibsetup) { botimport.Print(PRT_ERROR, "%s: bot library used before being setup\n", str); return qfalse; } //end if return qtrue; } //end of the function BotLibSetup //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== static int Export_BotLibSetup( void ) { int errnum; botDeveloper = LibVarGetValue( "bot_developer" ); memset( &botlibglobals, 0, sizeof( botlibglobals ) ); if ( botDeveloper ) { Log_Open( "botlib.log" ); } botimport.Print( PRT_MESSAGE, "------- BotLib Initialization -------\n" ); botlibglobals.maxclients = MAX_CLIENTS; botlibglobals.maxentities = MAX_GENTITIES; errnum = AAS_Setup(); //be_aas_main.c if (errnum != BLERR_NOERROR) return errnum; errnum = EA_Setup(); //be_ea.c if (errnum != BLERR_NOERROR) return errnum; errnum = BotSetupMoveAI(); //be_ai_move.c if (errnum != BLERR_NOERROR) return errnum; botlibsetup = qtrue; botlibglobals.botlibsetup = qtrue; return BLERR_NOERROR; } //end of the function Export_BotLibSetup //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== static int Export_BotLibShutdown(void) { if ( !botlibglobals.botlibsetup ) return BLERR_LIBRARYNOTSETUP; // BotShutdownMoveAI(); //be_ai_move.c //shut down AAS AAS_Shutdown(); //shut down bot elementary actions EA_Shutdown(); //free all libvars LibVarDeAllocAll(); //remove all global defines from the pre compiler PC_RemoveAllGlobalDefines(); //dump all allocated memory // DumpMemory(); #ifdef DEBUG PrintMemoryLabels(); #endif //shut down library log file Log_Shutdown(); // botlibsetup = qfalse; botlibglobals.botlibsetup = qfalse; // print any files still open PC_CheckOpenSourceHandles(); // return BLERR_NOERROR; } //end of the function Export_BotLibShutdown //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== static int Export_BotLibVarSet( const char *var_name, const char *value ) { LibVarSet( var_name, value ); return BLERR_NOERROR; } //end of the function Export_BotLibVarSet //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== static int Export_BotLibStartFrame(float time) { if (!BotLibSetup("BotStartFrame")) return BLERR_LIBRARYNOTSETUP; return AAS_StartFrame(time); } //end of the function Export_BotLibStartFrame //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== static int Export_BotLibLoadMap(const char *mapname) { #ifdef DEBUG int starttime = Sys_MilliSeconds(); #endif int errnum; if (!BotLibSetup("BotLoadMap")) return BLERR_LIBRARYNOTSETUP; // botimport.Print(PRT_MESSAGE, "------------ Map Loading ------------\n"); //startup AAS for the current map, model and sound index errnum = AAS_LoadMap(mapname); if (errnum != BLERR_NOERROR) return errnum; BotSetBrushModelTypes(); //be_ai_move.h // botimport.Print(PRT_MESSAGE, "-------------------------------------\n"); #ifdef DEBUG botimport.Print(PRT_MESSAGE, "map loaded in %d msec\n", Sys_MilliSeconds() - starttime); #endif // return BLERR_NOERROR; } //end of the function Export_BotLibLoadMap //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== static int Export_BotLibUpdateEntity(int ent, bot_entitystate_t *state) { if (!BotLibSetup("BotUpdateEntity")) return BLERR_LIBRARYNOTSETUP; if (!ValidEntityNumber(ent, "BotUpdateEntity")) return BLERR_INVALIDENTITYNUMBER; return AAS_UpdateEntity(ent, state); } //end of the function Export_BotLibUpdateEntity //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void ElevatorBottomCenter(aas_reachability_t *reach, vec3_t bottomcenter); int BotGetReachabilityToGoal(vec3_t origin, int areanum, int lastgoalareanum, int lastareanum, int *avoidreach, float *avoidreachtimes, int *avoidreachtries, bot_goal_t *goal, int travelflags, struct bot_avoidspot_s *avoidspots, int numavoidspots, int *flags); int AAS_PointLight(vec3_t origin, int *red, int *green, int *blue); int AAS_TraceAreas(vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas); int AAS_Reachability_WeaponJump(int area1num, int area2num); int BotFuzzyPointReachabilityArea(vec3_t origin); float BotGapDistance(vec3_t origin, vec3_t hordir, int entnum); void AAS_FloodAreas(vec3_t origin); /* ============ Init_AAS_Export ============ */ static void Init_AAS_Export( aas_export_t *aas ) { //-------------------------------------------- // be_aas_entity.c //-------------------------------------------- aas->AAS_EntityInfo = AAS_EntityInfo; //-------------------------------------------- // be_aas_main.c //-------------------------------------------- aas->AAS_Initialized = AAS_Initialized; aas->AAS_PresenceTypeBoundingBox = AAS_PresenceTypeBoundingBox; aas->AAS_Time = AAS_Time; //-------------------------------------------- // be_aas_sample.c //-------------------------------------------- aas->AAS_PointAreaNum = AAS_PointAreaNum; aas->AAS_PointReachabilityAreaIndex = AAS_PointReachabilityAreaIndex; aas->AAS_TraceAreas = AAS_TraceAreas; aas->AAS_BBoxAreas = AAS_BBoxAreas; aas->AAS_AreaInfo = AAS_AreaInfo; //-------------------------------------------- // be_aas_bspq3.c //-------------------------------------------- aas->AAS_PointContents = AAS_PointContents; aas->AAS_NextBSPEntity = AAS_NextBSPEntity; aas->AAS_ValueForBSPEpairKey = AAS_ValueForBSPEpairKey; aas->AAS_VectorForBSPEpairKey = AAS_VectorForBSPEpairKey; aas->AAS_FloatForBSPEpairKey = AAS_FloatForBSPEpairKey; aas->AAS_IntForBSPEpairKey = AAS_IntForBSPEpairKey; //-------------------------------------------- // be_aas_reach.c //-------------------------------------------- aas->AAS_AreaReachability = AAS_AreaReachability; //-------------------------------------------- // be_aas_route.c //-------------------------------------------- aas->AAS_AreaTravelTimeToGoalArea = AAS_AreaTravelTimeToGoalArea; aas->AAS_EnableRoutingArea = AAS_EnableRoutingArea; aas->AAS_PredictRoute = AAS_PredictRoute; //-------------------------------------------- // be_aas_altroute.c //-------------------------------------------- aas->AAS_AlternativeRouteGoals = AAS_AlternativeRouteGoals; //-------------------------------------------- // be_aas_move.c //-------------------------------------------- aas->AAS_Swimming = AAS_Swimming; aas->AAS_PredictClientMovement = AAS_PredictClientMovement; } /* ============ Init_EA_Export ============ */ static void Init_EA_Export( ea_export_t *ea ) { //ClientCommand elementary actions ea->EA_Command = EA_Command; ea->EA_Say = EA_Say; ea->EA_SayTeam = EA_SayTeam; ea->EA_Action = EA_Action; ea->EA_Gesture = EA_Gesture; ea->EA_Talk = EA_Talk; ea->EA_Attack = EA_Attack; ea->EA_Use = EA_Use; ea->EA_Respawn = EA_Respawn; ea->EA_Crouch = EA_Crouch; ea->EA_SelectWeapon = EA_SelectWeapon; ea->EA_View = EA_View; ea->EA_GetInput = EA_GetInput; ea->EA_ResetInput = EA_ResetInput; } /* ============ Init_AI_Export ============ */ static void Init_AI_Export( ai_export_t *ai ) { //----------------------------------- // be_ai_move.h //----------------------------------- ai->BotResetMoveState = BotResetMoveState; ai->BotMoveToGoal = BotMoveToGoal; ai->BotMoveInDirection = BotMoveInDirection; ai->BotResetAvoidReach = BotResetAvoidReach; ai->BotResetLastAvoidReach = BotResetLastAvoidReach; ai->BotMovementViewTarget = BotMovementViewTarget; ai->BotPredictVisiblePosition = BotPredictVisiblePosition; ai->BotAllocMoveState = BotAllocMoveState; ai->BotFreeMoveState = BotFreeMoveState; ai->BotInitMoveState = BotInitMoveState; ai->BotAddAvoidSpot = BotAddAvoidSpot; } /* ============ GetBotLibAPI ============ */ botlib_export_t *GetBotLibAPI(int apiVersion, botlib_import_t *import) { assert(import); botimport = *import; assert(botimport.Print); Com_Memset( &be_botlib_export, 0, sizeof( be_botlib_export ) ); if ( apiVersion != BOTLIB_API_VERSION ) { botimport.Print( PRT_ERROR, "Mismatched BOTLIB_API_VERSION: expected %i, got %i\n", BOTLIB_API_VERSION, apiVersion ); return NULL; } Init_AAS_Export(&be_botlib_export.aas); Init_EA_Export(&be_botlib_export.ea); Init_AI_Export(&be_botlib_export.ai); be_botlib_export.BotLibSetup = Export_BotLibSetup; be_botlib_export.BotLibShutdown = Export_BotLibShutdown; be_botlib_export.BotLibVarSet = Export_BotLibVarSet; be_botlib_export.PC_AddGlobalDefine = PC_AddGlobalDefine; be_botlib_export.PC_LoadSourceHandle = PC_LoadSourceHandle; be_botlib_export.PC_FreeSourceHandle = PC_FreeSourceHandle; be_botlib_export.PC_ReadTokenHandle = PC_ReadTokenHandle; be_botlib_export.PC_SourceFileAndLine = PC_SourceFileAndLine; be_botlib_export.BotLibStartFrame = Export_BotLibStartFrame; be_botlib_export.BotLibLoadMap = Export_BotLibLoadMap; be_botlib_export.BotLibUpdateEntity = Export_BotLibUpdateEntity; return &be_botlib_export; }