/
noire-dev
/
SourceTech
Обзор
Документация
Войти
/
noire-dev
/
SourceTech
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
sourcetech
code/botlib/botlib.h
343 строки
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: botlib.h * * desc: bot AI library * * $Archive: /source/code/game/botai.h $ * *****************************************************************************/ #define BOTLIB_API_VERSION 2 struct aas_clientmove_s; struct aas_entityinfo_s; struct aas_areainfo_s; struct aas_altroutegoal_s; struct aas_predictroute_s; struct bot_consolemessage_s; struct bot_match_s; struct bot_goal_s; struct bot_moveresult_s; struct bot_initmove_s; struct weaponinfo_s; #define BOTFILESBASEFOLDER "botfiles" //debug line colors #define LINECOLOR_NONE -1 #define LINECOLOR_RED 1//0xf2f2f0f0L #define LINECOLOR_GREEN 2//0xd0d1d2d3L #define LINECOLOR_BLUE 3//0xf3f3f1f1L #define LINECOLOR_YELLOW 4//0xdcdddedfL #define LINECOLOR_ORANGE 5//0xe0e1e2e3L //Print types #define PRT_MESSAGE 1 #define PRT_WARNING 2 #define PRT_ERROR 3 #define PRT_FATAL 4 #define PRT_EXIT 5 //console message types #define CMS_NORMAL 0 #define CMS_CHAT 1 //botlib error codes #define BLERR_NOERROR 0 //no error #define BLERR_LIBRARYNOTSETUP 1 //library not setup #define BLERR_INVALIDENTITYNUMBER 2 //invalid entity number #define BLERR_NOAASFILE 3 //no AAS file available #define BLERR_CANNOTOPENAASFILE 4 //cannot open AAS file #define BLERR_WRONGAASFILEID 5 //incorrect AAS file id #define BLERR_WRONGAASFILEVERSION 6 //incorrect AAS file version #define BLERR_CANNOTREADAASLUMP 7 //cannot read AAS file lump #define BLERR_CANNOTLOADICHAT 8 //cannot load initial chats #define BLERR_CANNOTLOADITEMWEIGHTS 9 //cannot load item weights #define BLERR_CANNOTLOADITEMCONFIG 10 //cannot load item config #define BLERR_CANNOTLOADWEAPONWEIGHTS 11 //cannot load weapon weights #define BLERR_CANNOTLOADWEAPONCONFIG 12 //cannot load weapon config //action flags #define ACTION_ATTACK 0x00000001 #define ACTION_USE 0x00000002 #define ACTION_RESPAWN 0x00000008 #define ACTION_JUMP 0x00000010 #define ACTION_MOVEUP 0x00000020 #define ACTION_CROUCH 0x00000080 #define ACTION_MOVEDOWN 0x00000100 #define ACTION_MOVEFORWARD 0x00000200 #define ACTION_MOVEBACK 0x00000800 #define ACTION_MOVELEFT 0x00001000 #define ACTION_MOVERIGHT 0x00002000 #define ACTION_DELAYEDJUMP 0x00008000 #define ACTION_TALK 0x00010000 #define ACTION_GESTURE 0x00020000 #define ACTION_WALK 0x00080000 #define ACTION_AFFIRMATIVE 0x00100000 #define ACTION_NEGATIVE 0x00200000 #define ACTION_GETFLAG 0x00800000 #define ACTION_GUARDBASE 0x01000000 #define ACTION_PATROL 0x02000000 #define ACTION_FOLLOWME 0x08000000 #define ACTION_JUMPEDLASTFRAME 0x10000000 //the bot input, will be converted to a usercmd_t typedef struct bot_input_s { float thinktime; //time since last output (in seconds) vec3_t dir; //movement direction float speed; //speed in the range [0, 400] vec3_t viewangles; //the view angles int actionflags; //one of the ACTION_? flags int weapon; //weapon to use } bot_input_t; #ifndef BSPTRACE #define BSPTRACE //bsp_trace_t hit surface typedef struct bsp_surface_s { char name[16]; int flags; int value; } bsp_surface_t; //remove the bsp_trace_s structure definition l8r on //a trace is returned when a box is swept through the world typedef struct bsp_trace_s { qboolean allsolid; // if true, plane is not valid qboolean startsolid; // if true, the initial point was in a solid area float fraction; // time completed, 1.0 = didn't hit anything vec3_t endpos; // final position cplane_t plane; // surface normal at impact float exp_dist; // expanded plane distance int sidenum; // number of the brush side hit bsp_surface_t surface; // the hit point surface int contents; // contents on other side of surface hit int ent; // number of entity hit } bsp_trace_t; #endif // BSPTRACE //entity state typedef struct bot_entitystate_s { int type; // entity type int flags; // entity flags vec3_t origin; // origin of the entity vec3_t angles; // angles of the model vec3_t old_origin; // for lerping vec3_t mins; // bounding box minimums vec3_t maxs; // bounding box maximums int groundent; // ground entity int solid; // solid type int modelindex; // model used int modelindex2; // weapons, CTF flags, etc int frame; // model frame number int event; // impulse events -- muzzle flashes, footsteps, etc int eventParm; // even parameter int powerups; // bit flags int weapon; // determines weapon and flash model, etc int legsAnim; // mask off ANIM_TOGGLEBIT int torsoAnim; // mask off ANIM_TOGGLEBIT } bot_entitystate_t; //a bot goal typedef struct bot_goal_s { vec3_t origin; //origin of the goal int areanum; //area number of the goal vec3_t mins, maxs; //mins and maxs of the goal } bot_goal_t; //bot AI library exported functions typedef struct botlib_import_s { //print messages from the bot library void (QDECL *Print)(int type, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); //trace a bbox through the world void (*Trace)(bsp_trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask); //trace a bbox against a specific entity void (*EntityTrace)(bsp_trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int entnum, int contentmask); //retrieve the contents at the given point int (*PointContents)(vec3_t point); //check if the point is in potential visible sight int (*inPVS)(vec3_t p1, vec3_t p2); //retrieve the BSP entity data lump char *(*BSPEntityData)(void); // void (*BSPModelMinsMaxsOrigin)(int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin); //send a bot client command void (*BotClientCommand)( int client, const char *command ); //memory allocation void *(*GetMemory)(int size); // allocate from Zone void (*FreeMemory)(void *ptr); // free memory from Zone int (*AvailableMemory)(void); // available Zone memory void *(*HunkAlloc)(int size); // allocate from hunk //file system access int (*FS_FOpenFile)( const char *qpath, fileHandle_t *file, fsMode_t mode ); int (*FS_Read)( void *buffer, int len, fileHandle_t f ); int (*FS_Write)( const void *buffer, int len, fileHandle_t f ); void (*FS_FCloseFile)( fileHandle_t f ); int (*FS_Seek)( fileHandle_t f, long offset, fsOrigin_t origin ); int (*Sys_Milliseconds)(void); } botlib_import_t; typedef struct aas_export_s { //----------------------------------- // be_aas_entity.c //----------------------------------- void (*AAS_EntityInfo)(int entnum, struct aas_entityinfo_s *info); //----------------------------------- // be_aas_main.c //----------------------------------- int (*AAS_Initialized)(void); void (*AAS_PresenceTypeBoundingBox)(int presencetype, vec3_t mins, vec3_t maxs); float (*AAS_Time)(void); //-------------------------------------------- // be_aas_sample.c //-------------------------------------------- int (*AAS_PointAreaNum)(vec3_t point); int (*AAS_PointReachabilityAreaIndex)( vec3_t point ); int (*AAS_TraceAreas)(vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas); int (*AAS_BBoxAreas)(vec3_t absmins, vec3_t absmaxs, int *areas, int maxareas); int (*AAS_AreaInfo)( int areanum, struct aas_areainfo_s *info ); //-------------------------------------------- // be_aas_bspq3.c //-------------------------------------------- int (*AAS_PointContents)(vec3_t point); int (*AAS_NextBSPEntity)(int ent); int (*AAS_ValueForBSPEpairKey)(int ent, const char *key, char *value, int size); int (*AAS_VectorForBSPEpairKey)(int ent, const char *key, vec3_t v); int (*AAS_FloatForBSPEpairKey)(int ent, const char *key, float *value); int (*AAS_IntForBSPEpairKey)(int ent, const char *key, int *value); //-------------------------------------------- // be_aas_reach.c //-------------------------------------------- int (*AAS_AreaReachability)(int areanum); //-------------------------------------------- // be_aas_route.c //-------------------------------------------- int (*AAS_AreaTravelTimeToGoalArea)(int areanum, vec3_t origin, int goalareanum, int travelflags); int (*AAS_EnableRoutingArea)(int areanum, int enable); int (*AAS_PredictRoute)(struct aas_predictroute_s *route, int areanum, vec3_t origin, int goalareanum, int travelflags, int maxareas, int maxtime, int stopevent, int stopcontents, int stoptfl, int stopareanum); //-------------------------------------------- // be_aas_altroute.c //-------------------------------------------- int (*AAS_AlternativeRouteGoals)(vec3_t start, int startareanum, vec3_t goal, int goalareanum, int travelflags, struct aas_altroutegoal_s *altroutegoals, int maxaltroutegoals, int type); //-------------------------------------------- // be_aas_move.c //-------------------------------------------- int (*AAS_Swimming)(vec3_t origin); int (*AAS_PredictClientMovement)(struct aas_clientmove_s *move, int entnum, const vec3_t origin, int presencetype, int onground, const vec3_t velocity, const vec3_t cmdmove, int cmdframes, int maxframes, float frametime, int stopevent, int stopareanum, int visualize); } aas_export_t; typedef struct ea_export_s { //ClientCommand elementary actions void (*EA_Command)(int client, const char *command); void (*EA_Say)(int client, const char *str); void (*EA_SayTeam)(int client, const char *str); // void (*EA_Action)(int client, int action); void (*EA_Gesture)(int client); void (*EA_Talk)(int client); void (*EA_Attack)(int client); void (*EA_Use)(int client); void (*EA_Respawn)(int client); void (*EA_Crouch)(int client); void (*EA_SelectWeapon)(int client, int weapon); void (*EA_View)(int client, vec3_t viewangles); //send regular input to the server void (*EA_GetInput)(int client, float thinktime, bot_input_t *input); void (*EA_ResetInput)(int client); } ea_export_t; typedef struct ai_export_s { //----------------------------------- // be_ai_move.h //----------------------------------- void (*BotResetMoveState)(int movestate); void (*BotMoveToGoal)(int movestate, struct bot_goal_s *goal, int travelflags); int (*BotMoveInDirection)(int movestate, vec3_t dir, float speed, int type); void (*BotResetAvoidReach)(int movestate); void (*BotResetLastAvoidReach)(int movestate); int (*BotMovementViewTarget)(int movestate, struct bot_goal_s *goal, int travelflags, float lookahead, vec3_t target); int (*BotPredictVisiblePosition)(vec3_t origin, int areanum, struct bot_goal_s *goal, int travelflags, vec3_t target); int (*BotAllocMoveState)(void); void (*BotFreeMoveState)(int handle); void (*BotInitMoveState)(int handle, struct bot_initmove_s *initmove); void (*BotAddAvoidSpot)(int movestate, const vec3_t origin, float radius, int type); } ai_export_t; //bot AI library imported functions typedef struct botlib_export_s { //Area Awareness System functions aas_export_t aas; //Elementary Action functions ea_export_t ea; //AI functions ai_export_t ai; //setup the bot library, returns BLERR_ int (*BotLibSetup)(void); //shutdown the bot library, returns BLERR_ int (*BotLibShutdown)(void); //sets a library variable returns BLERR_ int (*BotLibVarSet)( const char *var_name, const char *value ); //sets a C-like define returns BLERR_ int (*PC_AddGlobalDefine)(const char *string); int (*PC_LoadSourceHandle)(const char *filename); int (*PC_FreeSourceHandle)(int handle); int (*PC_ReadTokenHandle)(int handle, pc_token_t *pc_token); int (*PC_SourceFileAndLine)(int handle, char *filename, int *line); //start a frame in the bot library int (*BotLibStartFrame)(float time); //load a new map in the bot library int (*BotLibLoadMap)(const char *mapname); //entity updates int (*BotLibUpdateEntity)(int ent, bot_entitystate_t *state); } botlib_export_t; //linking of bot library botlib_export_t *GetBotLibAPI( int apiVersion, botlib_import_t *import );