#include "g_local.h"
#include "q_shared.h"
#include "botlib.h"
#include "be_aas.h"
#include "be_ea.h"
#include "be_ai_char.h"
#include "be_ai_chat.h"
#include "be_ai_gen.h"
#include "be_ai_goal.h"
#include "be_ai_move.h"
#include "be_ai_weap.h"
#include "ai_main.h"
#include "ai_dmq3.h"
#include "ai_chat.h"
#include "ai_cmd.h"
#include "ai_dmnet.h"
#include "ai_vcmd.h"
#include "chars.h"
#include "inv.h"
#include "syn.h"
Include dependency graph for ai_main.c:

Go to the source code of this file.
|
|
|
|
||||||||||||
|
Definition at line 716 of file ai_main.c. Referenced by BotChangeViewAngles(). 00716 {
00717 float diff;
00718
00719 diff = ang1 - ang2;
00720 if (ang1 > ang2) {
00721 if (diff > 180.0) diff -= 360.0;
00722 }
00723 else {
00724 if (diff < -180.0) diff += 360.0;
00725 }
00726 return diff;
00727 }
|
|
||||||||||||
|
Definition at line 961 of file ai_main.c. References AngleMod(), bot_state_s::areanum, bot_state_t, BotAI_GetClientState(), BotAI_Print(), BotDeathmatchAI(), BotPointAreaNum(), botstates, BotVoiceChatCommand(), bot_state_s::client, CMS_CHAT, CMS_NORMAL, bot_state_s::cs, bot_state_s::cur_ps, playerState_s::delta_angles, bot_state_s::eye, bot_state_s::inuse, j, bot_state_s::ltime, memmove(), bot_state_s::origin, playerState_s::origin, PRT_FATAL, Q_stricmp(), RemoveColorEscapeSequences(), SAY_ALL, SAY_TEAM, SAY_TELL, SHORT2ANGLE, strchr(), strlen(), bot_state_s::thinktime, trap_BotGetServerCommand(), trap_BotQueueConsoleMessage(), trap_EA_ResetInput(), trap_EA_SelectWeapon(), VectorCopy, bot_state_s::viewangles, playerState_s::viewheight, and bot_state_s::weaponnum. Referenced by BotAIStartFrame(). 00961 {
00962 bot_state_t *bs;
00963 char buf[1024], *args;
00964 int j;
00965
00966 trap_EA_ResetInput(client);
00967 //
00968 bs = botstates[client];
00969 if (!bs || !bs->inuse) {
00970 BotAI_Print(PRT_FATAL, "BotAI: client %d is not setup\n", client);
00971 return qfalse;
00972 }
00973
00974 //retrieve the current client state
00975 BotAI_GetClientState( client, &bs->cur_ps );
00976
00977 //retrieve any waiting server commands
00978 while( trap_BotGetServerCommand(client, buf, sizeof(buf)) ) {
00979 //have buf point to the command and args to the command arguments
00980 args = strchr( buf, ' ');
00981 if (!args) continue;
00982 *args++ = '\0';
00983
00984 //remove color espace sequences from the arguments
00985 RemoveColorEscapeSequences( args );
00986
00987 if (!Q_stricmp(buf, "cp "))
00988 { /*CenterPrintf*/ }
00989 else if (!Q_stricmp(buf, "cs"))
00990 { /*ConfigStringModified*/ }
00991 else if (!Q_stricmp(buf, "print")) {
00992 //remove first and last quote from the chat message
00993 memmove(args, args+1, strlen(args));
00994 args[strlen(args)-1] = '\0';
00995 trap_BotQueueConsoleMessage(bs->cs, CMS_NORMAL, args);
00996 }
00997 else if (!Q_stricmp(buf, "chat")) {
00998 //remove first and last quote from the chat message
00999 memmove(args, args+1, strlen(args));
01000 args[strlen(args)-1] = '\0';
01001 trap_BotQueueConsoleMessage(bs->cs, CMS_CHAT, args);
01002 }
01003 else if (!Q_stricmp(buf, "tchat")) {
01004 //remove first and last quote from the chat message
01005 memmove(args, args+1, strlen(args));
01006 args[strlen(args)-1] = '\0';
01007 trap_BotQueueConsoleMessage(bs->cs, CMS_CHAT, args);
01008 }
01009 #ifdef MISSIONPACK
01010 else if (!Q_stricmp(buf, "vchat")) {
01011 BotVoiceChatCommand(bs, SAY_ALL, args);
01012 }
01013 else if (!Q_stricmp(buf, "vtchat")) {
01014 BotVoiceChatCommand(bs, SAY_TEAM, args);
01015 }
01016 else if (!Q_stricmp(buf, "vtell")) {
01017 BotVoiceChatCommand(bs, SAY_TELL, args);
01018 }
01019 #endif
01020 else if (!Q_stricmp(buf, "scores"))
01021 { /*FIXME: parse scores?*/ }
01022 else if (!Q_stricmp(buf, "clientLevelShot"))
01023 { /*ignore*/ }
01024 }
01025 //add the delta angles to the bot's current view angles
01026 for (j = 0; j < 3; j++) {
01027 bs->viewangles[j] = AngleMod(bs->viewangles[j] + SHORT2ANGLE(bs->cur_ps.delta_angles[j]));
01028 }
01029 //increase the local time of the bot
01030 bs->ltime += thinktime;
01031 //
01032 bs->thinktime = thinktime;
01033 //origin of the bot
01034 VectorCopy(bs->cur_ps.origin, bs->origin);
01035 //eye coordinates of the bot
01036 VectorCopy(bs->cur_ps.origin, bs->eye);
01037 bs->eye[2] += bs->cur_ps.viewheight;
01038 //get the area the bot is in
01039 bs->areanum = BotPointAreaNum(bs->origin);
01040 //the real AI
01041 BotDeathmatchAI(bs, thinktime);
01042 //set the weapon selection every AI frame
01043 trap_EA_SelectWeapon(bs->client, bs->weaponnum);
01044 //subtract the delta angles
01045 for (j = 0; j < 3; j++) {
01046 bs->viewangles[j] = AngleMod(bs->viewangles[j] - SHORT2ANGLE(bs->cur_ps.delta_angles[j]));
01047 }
01048 //everything was ok
01049 return qtrue;
01050 }
|
Here is the call graph for this function:

|
||||||||||||||||
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 162 of file ai_main.c. References gentity_s::client, g_entities, gentity_t, gentity_s::inuse, memcpy(), playerState_t, gclient_s::ps, and state. Referenced by BotAI(), BotClientTravelTimeToGoal(), BotFirstClientInRankings(), BotIsFirstInRankings(), BotIsLastInRankings(), BotLastClientInRankings(), and EntityIsDead(). 00162 {
00163 gentity_t *ent;
00164
00165 ent = &g_entities[clientNum];
00166 if ( !ent->inuse ) {
00167 return qfalse;
00168 }
00169 if ( !ent->client ) {
00170 return qfalse;
00171 }
00172
00173 memcpy( state, &ent->client->ps, sizeof(playerState_t) );
00174 return qtrue;
00175 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 182 of file ai_main.c. References entityState_t, g_entities, gentity_t, gentity_s::inuse, entityShared_t::linked, memcpy(), memset(), gentity_s::r, gentity_s::s, state, and entityShared_t::svFlags. Referenced by BotAI_GetSnapshotEntity(), BotCheckSnapshot(), and BotClearPath(). 00182 {
00183 gentity_t *ent;
00184
00185 ent = &g_entities[entityNum];
00186 memset( state, 0, sizeof(entityState_t) );
00187 if (!ent->inuse) return qfalse;
00188 if (!ent->r.linked) return qfalse;
00189 if (ent->r.svFlags & SVF_NOCLIENT) return qfalse;
00190 memcpy( state, &ent->s, sizeof(entityState_t) );
00191 return qtrue;
00192 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 199 of file ai_main.c. References BotAI_GetEntityState(), entityState_t, memset(), state, and trap_BotGetSnapshotEntity(). Referenced by BotCheckSnapshot(). 00199 {
00200 int entNum;
00201
00202 entNum = trap_BotGetSnapshotEntity( clientNum, sequence );
00203 if ( entNum == -1 ) {
00204 memset(state, 0, sizeof(entityState_t));
00205 return -1;
00206 }
00207
00208 BotAI_GetEntityState( entNum, state );
00209
00210 return sequence + 1;
00211 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 95 of file ai_main.c. References G_Error(), G_Printf(), PRT_ERROR, PRT_EXIT, PRT_FATAL, PRT_MESSAGE, PRT_WARNING, QDECL, S_COLOR_RED, S_COLOR_YELLOW, va_end, va_list, va_start, and vsprintf(). Referenced by AINode_Battle_Fight(), AINode_Battle_Retreat(), AINode_Seek_ActivateEntity(), BotAI(), BotAIBlocked(), BotAISetupClient(), BotCheckConsoleMessages(), BotCheckEvents(), BotCreateWayPoint(), BotDeathmatchAI(), BotDumpNodeSwitches(), BotGetActivateGoal(), BotGetItemLongTermGoal(), BotGPSToPosition(), BotMatchMessage(), BotRecordNodeSwitch(), BotReportStatus(), BotSetupAlternativeRouteGoals(), BotSetupDeathmatchAI(), BotTeamplayReport(), BotTestAAS(), ClientName(), and ClientSkin(). 00095 {
00096 char str[2048];
00097 va_list ap;
00098
00099 va_start(ap, fmt);
00100 vsprintf(str, fmt, ap);
00101 va_end(ap);
00102
00103 switch(type) {
00104 case PRT_MESSAGE: {
00105 G_Printf("%s", str);
00106 break;
00107 }
00108 case PRT_WARNING: {
00109 G_Printf( S_COLOR_YELLOW "Warning: %s", str );
00110 break;
00111 }
00112 case PRT_ERROR: {
00113 G_Printf( S_COLOR_RED "Error: %s", str );
00114 break;
00115 }
00116 case PRT_FATAL: {
00117 G_Printf( S_COLOR_RED "Fatal: %s", str );
00118 break;
00119 }
00120 case PRT_EXIT: {
00121 G_Error( S_COLOR_RED "Exit: %s", str );
00122 break;
00123 }
00124 default: {
00125 G_Printf( "unknown print type\n" );
00126 break;
00127 }
00128 }
00129 }
|
Here is the call graph for this function:

|
||||||||||||||||||||||||||||||||
Here is the call graph for this function:

|
|
Definition at line 1347 of file ai_main.c. References BotResetState(), BotSetupDeathmatchAI(), botstates, CVAR_ROM, CVAR_SERVERINFO, i, bot_state_s::inuse, bot_state_s::setupcount, vmCvar_t::string, trap_BotLibLoadMap(), and trap_Cvar_Register(). Referenced by G_InitGame(). 01347 {
01348 int i;
01349 vmCvar_t mapname;
01350
01351 if (!restart) {
01352 trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM );
01353 trap_BotLibLoadMap( mapname.string );
01354 }
01355
01356 for (i = 0; i < MAX_CLIENTS; i++) {
01357 if (botstates[i] && botstates[i]->inuse) {
01358 BotResetState( botstates[i] );
01359 botstates[i]->setupcount = 4;
01360 }
01361 }
01362
01363 BotSetupDeathmatchAI();
01364
01365 return qtrue;
01366 }
|
Here is the call graph for this function:

|
|
Definition at line 928 of file ai_main.c. References FloatTime, regularupdate_time, and trap_BotUpdateEntityItems(). Referenced by BotAIStartFrame(). 00928 {
00929 if (regularupdate_time < FloatTime()) {
00930 trap_BotUpdateEntityItems();
00931 regularupdate_time = FloatTime() + 0.3;
00932 }
00933 }
|
Here is the call graph for this function:

|
|
Definition at line 1642 of file ai_main.c. References bot_developer, bot_interbreedbots, bot_interbreedchar, bot_interbreedcycle, bot_interbreedwrite, bot_memorydump, bot_pause, bot_report, bot_saveroutingcache, bot_testclusters, bot_testsolid, bot_thinktime, BotInitLibrary(), botstates, CVAR_CHEAT, memset(), and trap_Cvar_Register(). Referenced by G_InitGame(). 01642 {
01643 int errnum;
01644
01645 trap_Cvar_Register(&bot_thinktime, "bot_thinktime", "100", CVAR_CHEAT);
01646 trap_Cvar_Register(&bot_memorydump, "bot_memorydump", "0", CVAR_CHEAT);
01647 trap_Cvar_Register(&bot_saveroutingcache, "bot_saveroutingcache", "0", CVAR_CHEAT);
01648 trap_Cvar_Register(&bot_pause, "bot_pause", "0", CVAR_CHEAT);
01649 trap_Cvar_Register(&bot_report, "bot_report", "0", CVAR_CHEAT);
01650 trap_Cvar_Register(&bot_testsolid, "bot_testsolid", "0", CVAR_CHEAT);
01651 trap_Cvar_Register(&bot_testclusters, "bot_testclusters", "0", CVAR_CHEAT);
01652 trap_Cvar_Register(&bot_developer, "bot_developer", "0", CVAR_CHEAT);
01653 trap_Cvar_Register(&bot_interbreedchar, "bot_interbreedchar", "", 0);
01654 trap_Cvar_Register(&bot_interbreedbots, "bot_interbreedbots", "10", 0);
01655 trap_Cvar_Register(&bot_interbreedcycle, "bot_interbreedcycle", "20", 0);
01656 trap_Cvar_Register(&bot_interbreedwrite, "bot_interbreedwrite", "", 0);
01657
01658 //if the game is restarted for a tournament
01659 if (restart) {
01660 return qtrue;
01661 }
01662
01663 //initialize the bot states
01664 memset( botstates, 0, sizeof(botstates) );
01665
01666 errnum = BotInitLibrary();
01667 if (errnum != BLERR_NOERROR) return qfalse;
01668 return qtrue;
01669 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 1152 of file ai_main.c. References bot_settings_t, bot_state_t, BotAI_Print(), BotChatTest(), BotReadSessionData(), BotScheduleBotThink(), botstates, bot_state_s::character, bot_settings_s::characterfile, CHARACTERISTIC_CHAT_FILE, CHARACTERISTIC_CHAT_NAME, CHARACTERISTIC_GENDER, CHARACTERISTIC_ITEMWEIGHTS, CHARACTERISTIC_WALKER, CHARACTERISTIC_WEAPONWEIGHTS, CHAT_GENDERFEMALE, CHAT_GENDERLESS, CHAT_GENDERMALE, bot_state_s::client, bot_state_s::cs, bot_state_s::entergame_time, bot_state_s::entitynum, FloatTime, G_Alloc(), bot_state_s::gs, bot_state_s::inuse, MAX_PATH, memcpy(), bot_state_s::ms, name, numbots, PRT_FATAL, bot_state_s::settings, bot_state_s::setupcount, bot_settings_s::skill, trap_AAS_Initialized(), trap_BotAllocChatState(), trap_BotAllocGoalState(), trap_BotAllocMoveState(), trap_BotAllocWeaponState(), trap_BotFreeChatState(), trap_BotFreeGoalState(), trap_BotFreeWeaponState(), trap_BotLibVarSet(), trap_BotLoadCharacter(), trap_BotLoadChatFile(), trap_BotLoadItemWeights(), trap_BotLoadWeaponWeights(), trap_BotMutateGoalFuzzyLogic(), trap_BotSetChatGender(), trap_Characteristic_BFloat(), trap_Characteristic_String(), trap_Cvar_VariableIntegerValue(), bot_state_s::walker, and bot_state_s::ws. Referenced by G_BotConnect(). 01152 {
01153 char filename[MAX_PATH], name[MAX_PATH], gender[MAX_PATH];
01154 bot_state_t *bs;
01155 int errnum;
01156
01157 if (!botstates[client]) botstates[client] = G_Alloc(sizeof(bot_state_t));
01158 bs = botstates[client];
01159
01160 if (bs && bs->inuse) {
01161 BotAI_Print(PRT_FATAL, "BotAISetupClient: client %d already setup\n", client);
01162 return qfalse;
01163 }
01164
01165 if (!trap_AAS_Initialized()) {
01166 BotAI_Print(PRT_FATAL, "AAS not initialized\n");
01167 return qfalse;
01168 }
01169
01170 //load the bot character
01171 bs->character = trap_BotLoadCharacter(settings->characterfile, settings->skill);
01172 if (!bs->character) {
01173 BotAI_Print(PRT_FATAL, "couldn't load skill %f from %s\n", settings->skill, settings->characterfile);
01174 return qfalse;
01175 }
01176 //copy the settings
01177 memcpy(&bs->settings, settings, sizeof(bot_settings_t));
01178 //allocate a goal state
01179 bs->gs = trap_BotAllocGoalState(client);
01180 //load the item weights
01181 trap_Characteristic_String(bs->character, CHARACTERISTIC_ITEMWEIGHTS, filename, MAX_PATH);
01182 errnum = trap_BotLoadItemWeights(bs->gs, filename);
01183 if (errnum != BLERR_NOERROR) {
01184 trap_BotFreeGoalState(bs->gs);
01185 return qfalse;
01186 }
01187 //allocate a weapon state
01188 bs->ws = trap_BotAllocWeaponState();
01189 //load the weapon weights
01190 trap_Characteristic_String(bs->character, CHARACTERISTIC_WEAPONWEIGHTS, filename, MAX_PATH);
01191 errnum = trap_BotLoadWeaponWeights(bs->ws, filename);
01192 if (errnum != BLERR_NOERROR) {
01193 trap_BotFreeGoalState(bs->gs);
01194 trap_BotFreeWeaponState(bs->ws);
01195 return qfalse;
01196 }
01197 //allocate a chat state
01198 bs->cs = trap_BotAllocChatState();
01199 //load the chat file
01200 trap_Characteristic_String(bs->character, CHARACTERISTIC_CHAT_FILE, filename, MAX_PATH);
01201 trap_Characteristic_String(bs->character, CHARACTERISTIC_CHAT_NAME, name, MAX_PATH);
01202 errnum = trap_BotLoadChatFile(bs->cs, filename, name);
01203 if (errnum != BLERR_NOERROR) {
01204 trap_BotFreeChatState(bs->cs);
01205 trap_BotFreeGoalState(bs->gs);
01206 trap_BotFreeWeaponState(bs->ws);
01207 return qfalse;
01208 }
01209 //get the gender characteristic
01210 trap_Characteristic_String(bs->character, CHARACTERISTIC_GENDER, gender, MAX_PATH);
01211 //set the chat gender
01212 if (*gender == 'f' || *gender == 'F') trap_BotSetChatGender(bs->cs, CHAT_GENDERFEMALE);
01213 else if (*gender == 'm' || *gender == 'M') trap_BotSetChatGender(bs->cs, CHAT_GENDERMALE);
01214 else trap_BotSetChatGender(bs->cs, CHAT_GENDERLESS);
01215
01216 bs->inuse = qtrue;
01217 bs->client = client;
01218 bs->entitynum = client;
01219 bs->setupcount = 4;
01220 bs->entergame_time = FloatTime();
01221 bs->ms = trap_BotAllocMoveState();
01222 bs->walker = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_WALKER, 0, 1);
01223 numbots++;
01224
01225 if (trap_Cvar_VariableIntegerValue("bot_testichat")) {
01226 trap_BotLibVarSet("bot_testichat", "1");
01227 BotChatTest(bs);
01228 }
01229 //NOTE: reschedule the bot thinking
01230 BotScheduleBotThink();
01231 //if interbreeding start with a mutation
01232 if (bot_interbreed) {
01233 trap_BotMutateGoalFuzzyLogic(bs->gs, 1);
01234 }
01235 // if we kept the bot client
01236 if (restart) {
01237 BotReadSessionData(bs);
01238 }
01239 //bot has been setup succesfully
01240 return qtrue;
01241 }
|
Here is the call graph for this function:

|
|
Definition at line 1676 of file ai_main.c. References BotAIShutdownClient(), botstates, i, bot_state_s::inuse, and trap_BotLibShutdown(). Referenced by G_ShutdownGame(). 01676 {
01677
01678 int i;
01679
01680 //if the game is restarted for a tournament
01681 if ( restart ) {
01682 //shutdown all the bots in the botlib
01683 for (i = 0; i < MAX_CLIENTS; i++) {
01684 if (botstates[i] && botstates[i]->inuse) {
01685 BotAIShutdownClient(botstates[i]->client, restart);
01686 }
01687 }
01688 //don't shutdown the bot library
01689 }
01690 else {
01691 trap_BotLibShutdown();
01692 }
01693 return qtrue;
01694 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1248 of file ai_main.c. References bot_state_t, BotChat_ExitGame(), BotClearActivateGoalStack(), BotFreeWaypoints(), botstates, BotWriteSessionData(), bot_state_s::character, CHAT_ALL, bot_state_s::checkpoints, bot_state_s::client, bot_state_s::cs, bot_state_s::gs, bot_state_s::inuse, memset(), bot_state_s::ms, numbots, bot_state_s::patrolpoints, trap_BotEnterChat(), trap_BotFreeCharacter(), trap_BotFreeChatState(), trap_BotFreeGoalState(), trap_BotFreeMoveState(), trap_BotFreeWeaponState(), and bot_state_s::ws. Referenced by BotAIShutdown(), BotInterbreeding(), and ClientDisconnect(). 01248 {
01249 bot_state_t *bs;
01250
01251 bs = botstates[client];
01252 if (!bs || !bs->inuse) {
01253 //BotAI_Print(PRT_ERROR, "BotAIShutdownClient: client %d already shutdown\n", client);
01254 return qfalse;
01255 }
01256
01257 if (restart) {
01258 BotWriteSessionData(bs);
01259 }
01260
01261 if (BotChat_ExitGame(bs)) {
01262 trap_BotEnterChat(bs->cs, bs->client, CHAT_ALL);
01263 }
01264
01265 trap_BotFreeMoveState(bs->ms);
01266 //free the goal state`
01267 trap_BotFreeGoalState(bs->gs);
01268 //free the chat file
01269 trap_BotFreeChatState(bs->cs);
01270 //free the weapon weights
01271 trap_BotFreeWeaponState(bs->ws);
01272 //free the bot character
01273 trap_BotFreeCharacter(bs->character);
01274 //
01275 BotFreeWaypoints(bs->checkpoints);
01276 BotFreeWaypoints(bs->patrolpoints);
01277 //clear activate goal stack
01278 BotClearActivateGoalStack(bs);
01279 //clear the bot state
01280 memset(bs, 0, sizeof(bot_state_t));
01281 //set the inuse flag to qfalse
01282 bs->inuse = qfalse;
01283 //there's one bot less
01284 numbots--;
01285 //everything went ok
01286 return qtrue;
01287 }
|
Here is the call graph for this function:

|