#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 "w_saber.h"#include "chars.h"#include "inv.h"#include "syn.h"Go to the source code of this file.
|
|
|
|
|
Definition at line 43 of file ai_main.c. Referenced by BotAIStartFrame(), and BotScheduleBotThink(). |
|
|
|
|
|
Definition at line 1552 of file ai_main.c. Referenced by BotTrace_Strafe(), and StandardBotAI(). |
|
|
Definition at line 1551 of file ai_main.c. Referenced by BotTrace_Strafe(), and StandardBotAI(). |
|
|
Definition at line 5502 of file ai_main.c. References bot_state_t, bot_state_s::cur_ps, bot_state_s::doAltAttack, WEAPON_CHARGING_ALT, and playerState_s::weaponstate. Referenced by StandardBotAI().
05503 {
05504 if (bs->cur_ps.weaponstate != WEAPON_CHARGING_ALT &&
05505 bs->doAltAttack)
05506 {
05507 return 1;
05508 }
05509
05510 if (bs->cur_ps.weaponstate == WEAPON_CHARGING_ALT &&
05511 !bs->doAltAttack)
05512 {
05513 return 1;
05514 }
05515
05516 return 0;
05517 }
|
|
||||||||||||
|
Definition at line 425 of file ai_main.c. Referenced by BotChangeViewAngles(), and BotTrace_Strafe().
00425 {
00426 float diff;
00427
00428 diff = ang1 - ang2;
00429 if (ang1 > ang2) {
00430 if (diff > 180.0) diff -= 360.0;
00431 }
00432 else {
00433 if (diff < -180.0) diff += 360.0;
00434 }
00435 return diff;
00436 }
|
|
||||||||||||||||||||
|
Definition at line 5883 of file ai_main.c. References bot_state_t, botstates, bot_state_s::forceMove_Forward, bot_state_s::forceMove_Right, and bot_state_s::forceMove_Up. Referenced by ClientCommand().
05884 {
05885 bot_state_t *bs;
05886
05887 bs = botstates[bot];
05888
05889 if (!bs)
05890 { //not a bot
05891 return;
05892 }
05893
05894 if (forward != -1)
05895 {
05896 if (bs->forceMove_Forward)
05897 {
05898 bs->forceMove_Forward = 0;
05899 }
05900 else
05901 {
05902 bs->forceMove_Forward = forward;
05903 }
05904 }
05905 if (right != -1)
05906 {
05907 if (bs->forceMove_Right)
05908 {
05909 bs->forceMove_Right = 0;
05910 }
05911 else
05912 {
05913 bs->forceMove_Right = right;
05914 }
05915 }
05916 if (up != -1)
05917 {
05918 if (bs->forceMove_Up)
05919 {
05920 bs->forceMove_Up = 0;
05921 }
05922 else
05923 {
05924 bs->forceMove_Up = up;
05925 }
05926 }
05927 }
|
|
||||||||||||
|
Definition at line 696 of file ai_main.c. References AngleMod(), bot_state_t, BotAI_GetClientState(), BotAI_Print(), botstates, client, Com_Printf(), bot_state_s::cur_ps, playerState_s::delta_angles, bot_state_s::eye, vmCvar_t::integer, bot_state_s::inuse, bot_state_s::ltime, bot_state_s::origin, playerState_s::origin, PRT_FATAL, Q_stricmp(), qfalse, qtrue, RemoveColorEscapeSequences(), SHORT2ANGLE, StandardBotAI(), strchr(), bot_state_s::thinktime, trap_BotGetServerCommand(), trap_Cvar_Update(), trap_EA_ResetInput(), trap_Milliseconds(), VectorCopy, bot_state_s::viewangles, and playerState_s::viewheight. Referenced by BotAIStartFrame().
00696 {
00697 bot_state_t *bs;
00698 char buf[1024], *args;
00699 int j;
00700 #ifdef _DEBUG
00701 int start = 0;
00702 int end = 0;
00703 #endif
00704
00705 trap_EA_ResetInput(client);
00706 //
00707 bs = botstates[client];
00708 if (!bs || !bs->inuse) {
00709 BotAI_Print(PRT_FATAL, "BotAI: client %d is not setup\n", client);
00710 return qfalse;
00711 }
00712
00713 //retrieve the current client state
00714 BotAI_GetClientState( client, &bs->cur_ps );
00715
00716 //retrieve any waiting server commands
00717 while( trap_BotGetServerCommand(client, buf, sizeof(buf)) ) {
00718 //have buf point to the command and args to the command arguments
00719 args = strchr( buf, ' ');
00720 if (!args) continue;
00721 *args++ = '\0';
00722
00723 //remove color espace sequences from the arguments
00724 RemoveColorEscapeSequences( args );
00725
00726 if (!Q_stricmp(buf, "cp "))
00727 { /*CenterPrintf*/ }
00728 else if (!Q_stricmp(buf, "cs"))
00729 { /*ConfigStringModified*/ }
00730 else if (!Q_stricmp(buf, "scores"))
00731 { /*FIXME: parse scores?*/ }
00732 else if (!Q_stricmp(buf, "clientLevelShot"))
00733 { /*ignore*/ }
00734 }
00735 //add the delta angles to the bot's current view angles
00736 for (j = 0; j < 3; j++) {
00737 bs->viewangles[j] = AngleMod(bs->viewangles[j] + SHORT2ANGLE(bs->cur_ps.delta_angles[j]));
00738 }
00739 //increase the local time of the bot
00740 bs->ltime += thinktime;
00741 //
00742 bs->thinktime = thinktime;
00743 //origin of the bot
00744 VectorCopy(bs->cur_ps.origin, bs->origin);
00745 //eye coordinates of the bot
00746 VectorCopy(bs->cur_ps.origin, bs->eye);
00747 bs->eye[2] += bs->cur_ps.viewheight;
00748 //get the area the bot is in
00749
00750 #ifdef _DEBUG
00751 start = trap_Milliseconds();
00752 #endif
00753 StandardBotAI(bs, thinktime);
00754 #ifdef _DEBUG
00755 end = trap_Milliseconds();
00756
00757 trap_Cvar_Update(&bot_debugmessages);
00758
00759 if (bot_debugmessages.integer)
00760 {
00761 Com_Printf("Single AI frametime: %i\n", (end - start));
00762 }
00763 #endif
00764
00765 //subtract the delta angles
00766 for (j = 0; j < 3; j++) {
00767 bs->viewangles[j] = AngleMod(bs->viewangles[j] - SHORT2ANGLE(bs->cur_ps.delta_angles[j]));
00768 }
00769 //everything was ok
00770 return qtrue;
00771 }
|
|
||||||||||||
|
Definition at line 351 of file ai_main.c. References gentity_s::client, g_entities, gentity_t, gentity_s::inuse, memcpy(), playerState_t, gclient_s::ps, qfalse, and qtrue. Referenced by BotAI().
|
|
||||||||||||
|
Definition at line 371 of file ai_main.c. References entityState_t, g_entities, gentity_t, gentity_s::inuse, entityShared_t::linked, memcpy(), memset(), qfalse, qtrue, gentity_s::r, gentity_s::s, SVF_NOCLIENT, and entityShared_t::svFlags. Referenced by BotAI_GetSnapshotEntity().
00371 {
00372 gentity_t *ent;
00373
00374 ent = &g_entities[entityNum];
00375 memset( state, 0, sizeof(entityState_t) );
00376 if (!ent->inuse) return qfalse;
00377 if (!ent->r.linked) return qfalse;
00378 if (ent->r.svFlags & SVF_NOCLIENT) return qfalse;
00379 memcpy( state, &ent->s, sizeof(entityState_t) );
00380 return qtrue;
00381 }
|
|
||||||||||||||||
|
Definition at line 388 of file ai_main.c. References BotAI_GetEntityState(), entityState_t, memset(), and trap_BotGetSnapshotEntity().
00388 {
00389 int entNum;
00390
00391 entNum = trap_BotGetSnapshotEntity( clientNum, sequence );
00392 if ( entNum == -1 ) {
00393 memset(state, 0, sizeof(entityState_t));
00394 return -1;
00395 }
00396
00397 BotAI_GetEntityState( entNum, state );
00398
00399 return sequence + 1;
00400 }
|
|
||||||||||||||||
|
Definition at line 332 of file ai_main.c. References QDECL. Referenced by BotAI(), and BotAISetupClient().
00332 { return; }
|
|
|
Definition at line 966 of file ai_main.c. References BotResetState(), botstates, bot_state_s::inuse, MAX_CLIENTS, qtrue, and bot_state_s::setupcount. Referenced by G_InitGame().
00966 {
00967 int i;
00968
00969 for (i = 0; i < MAX_CLIENTS; i++) {
00970 if (botstates[i] && botstates[i]->inuse) {
00971 BotResetState( botstates[i] );
00972 botstates[i]->setupcount = 4;
00973 }
00974 }
00975
00976 return qtrue;
00977 }
|
|
||||||||||||||||
|
Definition at line 4607 of file ai_main.c. References bot_state_t, gentity_s::client, bot_state_s::currentEnemy, bot_state_s::eye, bot_state_s::frame_Enemy_Len, bot_state_s::goalAngles, gclient_s::ps, vec3_t, vectoangles(), VectorCopy, VectorNormalize(), VectorSubtract, and playerState_s::velocity. Referenced by StandardBotAI().
04608 {
04609 int x;
04610 vec3_t predictedSpot;
04611 vec3_t movementVector;
04612 vec3_t a, ang;
04613 float vtotal;
04614
04615 if (!bs->currentEnemy ||
04616 !bs->currentEnemy->client)
04617 {
04618 return;
04619 }
04620
04621 if (!bs->frame_Enemy_Len)
04622 {
04623 return;
04624 }
04625
04626 vtotal = 0;
04627
04628 if (bs->currentEnemy->client->ps.velocity[0] < 0)
04629 {
04630 vtotal += -bs->currentEnemy->client->ps.velocity[0];
04631 }
04632 else
04633 {
04634 vtotal += bs->currentEnemy->client->ps.velocity[0];
04635 }
04636
04637 if (bs->currentEnemy->client->ps.velocity[1] < 0)
04638 {
04639 vtotal += -bs->currentEnemy->client->ps.velocity[1];
04640 }
04641 else
04642 {
04643 vtotal += bs->currentEnemy->client->ps.velocity[1];
04644 }
04645
04646 if (bs->currentEnemy->client->ps.velocity[2] < 0)
04647 {
04648 vtotal += -bs->currentEnemy->client->ps.velocity[2];
04649 }
04650 else
04651 {
04652 vtotal += bs->currentEnemy->client->ps.velocity[2];
04653 }
04654
04655 //G_Printf("Leadin target with a velocity total of %f\n", vtotal);
04656
04657 VectorCopy(bs->currentEnemy->client->ps.velocity, movementVector);
04658
04659 VectorNormalize(movementVector);
04660
04661 x = bs->frame_Enemy_Len*leadAmount; //hardly calculated with an exact science, but it works
04662
04663 if (vtotal > 400)
04664 {
04665 vtotal = 400;
04666 }
04667
04668 if (vtotal)
04669 {
04670 x = (bs->frame_Enemy_Len*0.9)*leadAmount*(vtotal*0.0012); //hardly calculated with an exact science, but it works
04671 }
04672 else
04673 {
04674 x = (bs->frame_Enemy_Len*0.9)*leadAmount; //hardly calculated with an exact science, but it works
04675 }
04676
04677 predictedSpot[0] = headlevel[0] + (movementVector[0]*x);
04678 predictedSpot[1] = headlevel[1] + (movementVector[1]*x);
04679 predictedSpot[2] = headlevel[2] + (movementVector[2]*x);
04680
04681 VectorSubtract(predictedSpot, bs->eye, a);
04682 vectoangles(a, ang);
04683 VectorCopy(ang, bs->goalAngles);
04684 }
|
|
|
Definition at line 4687 of file ai_main.c. References botskills_s::accuracy, bot_state_s::aimOffsetAmtPitch, bot_state_s::aimOffsetAmtYaw, bot_state_s::aimOffsetTime, bot_state_t, BotMindTricked(), bot_state_s::client, bot_state_s::currentEnemy, bot_state_s::frame_Enemy_Vis, g_entities, bot_state_s::goalAngles, level, entityState_s::number, botskills_s::perfectaim, PITCH, entityState_s::pos, rand(), bot_state_s::revengeEnemy, bot_state_s::revengeHateLevel, gentity_s::s, bot_state_s::settings, bot_settings_s::skill, bot_state_s::skills, level_locals_t::time, trajectory_t::trDelta, and YAW. Referenced by StandardBotAI().
04688 {
04689 int i;
04690 float accVal;
04691 i = 0;
04692
04693 if (bs->skills.perfectaim)
04694 {
04695 return;
04696 }
04697
04698 if (bs->aimOffsetTime > level.time)
04699 {
04700 if (bs->aimOffsetAmtYaw)
04701 {
04702 bs->goalAngles[YAW] += bs->aimOffsetAmtYaw;
04703 }
04704
04705 if (bs->aimOffsetAmtPitch)
04706 {
04707 bs->goalAngles[PITCH] += bs->aimOffsetAmtPitch;
04708 }
04709
04710 while (i <= 2)
04711 {
04712 if (bs->goalAngles[i] > 360)
04713 {
04714 bs->goalAngles[i] -= 360;
04715 }
04716
04717 if (bs->goalAngles[i] < 0)
04718 {
04719 bs->goalAngles[i] += 360;
04720 }
04721
04722 i++;
04723 }
04724 return;
04725 }
04726
04727 accVal = bs->skills.accuracy/bs->settings.skill;
04728
04729 if (bs->currentEnemy && BotMindTricked(bs->client, bs->currentEnemy->s.number))
04730 { //having to judge where they are by hearing them, so we should be quite inaccurate here
04731 accVal *= 7;
04732
04733 if (accVal < 30)
04734 {
04735 accVal = 30;
04736 }
04737 }
04738
04739 if (bs->revengeEnemy && bs->revengeHateLevel &&
04740 bs->currentEnemy == bs->revengeEnemy)
04741 { //bot becomes more skilled as anger level raises
04742 accVal = accVal/bs->revengeHateLevel;
04743 }
04744
04745 if (bs->currentEnemy && bs->frame_Enemy_Vis)
04746 { //assume our goal is aiming at the enemy, seeing as he's visible and all
04747 if (!bs->currentEnemy->s.pos.trDelta[0] &&
04748 !bs->currentEnemy->s.pos.trDelta[1] &&
04749 !bs->currentEnemy->s.pos.trDelta[2])
04750 {
04751 accVal = 0; //he's not even moving, so he shouldn't really be hard to hit.
04752 }
04753 else
04754 {
04755 accVal += accVal*0.25; //if he's moving he's this much harder to hit
04756 }
04757
04758 if (g_entities[bs->client].s.pos.trDelta[0] ||
04759 g_entities[bs->client].s.pos.trDelta[1] ||
04760 g_entities[bs->client].s.pos.trDelta[2])
04761 {
04762 accVal += accVal*0.15; //make it somewhat harder to aim if we're moving also
04763 }
04764 }
04765
04766 if (accVal > 90)
04767 {
04768 accVal = 90;
04769 }
04770 if (accVal < 1)
04771 {
04772 accVal = 0;
04773 }
04774
04775 if (!accVal)
04776 {
04777 bs->aimOffsetAmtYaw = 0;
04778 bs->aimOffsetAmtPitch = 0;
04779 return;
04780 }
04781
04782 if (rand()%10 <= 5)
04783 {
04784 bs->aimOffsetAmtYaw = rand()%(int)accVal;
04785 }
04786 else
04787 {
04788 bs->aimOffsetAmtYaw = -(rand()%(int)accVal);
04789 }
04790
04791 if (rand()%10 <= 5)
04792 {
04793 bs->aimOffsetAmtPitch = rand()%(int)accVal;
04794 }
04795 else
04796 {
04797 bs->aimOffsetAmtPitch = -(rand()%(int)accVal);
04798 }
04799
04800 bs->aimOffsetTime = level.time + rand()%500 + 200;
04801 }
|
|
|
Definition at line 662 of file ai_main.c. References FloatTime, regularupdate_time, and trap_BotUpdateEntityItems().
00662 {
00663 if (regularupdate_time < FloatTime()) {
00664 trap_BotUpdateEntityItems();
00665 regularupdate_time = FloatTime() + 0.3;
00666 }
00667 }
|
|
|
Definition at line 7575 of file ai_main.c. References bot_attachments, bot_camp, bot_forcepowers, bot_forgimmick, bot_getinthecarrr, bot_honorableduelacceptance, bot_pvstype, bot_wp_clearweight, bot_wp_distconnect, bot_wp_edit, bot_wp_info, bot_wp_visconnect, botstates, CVAR_CHEAT, memset(), qfalse, qtrue, trap_BotLibSetup(), trap_Cvar_Register(), and trap_Cvar_Update(). Referenced by G_InitGame().
07575 {
07576 //rww - new bot cvars..
07577 trap_Cvar_Register(&bot_forcepowers, "bot_forcepowers", "1", CVAR_CHEAT);
07578 trap_Cvar_Register(&bot_forgimmick, "bot_forgimmick", "0", CVAR_CHEAT);
07579 trap_Cvar_Register(&bot_honorableduelacceptance, "bot_honorableduelacceptance", "0", CVAR_CHEAT);
07580 trap_Cvar_Register(&bot_pvstype, "bot_pvstype", "1", CVAR_CHEAT);
07581 #ifndef FINAL_BUILD
07582 trap_Cvar_Register(&bot_getinthecarrr, "bot_getinthecarrr", "0", 0);
07583 #endif
07584
07585 #ifdef _DEBUG
07586 trap_Cvar_Register(&bot_nogoals, "bot_nogoals", "0", CVAR_CHEAT);
07587 trap_Cvar_Register(&bot_debugmessages, "bot_debugmessages", "0", CVAR_CHEAT);
07588 #endif
07589
07590 trap_Cvar_Register(&bot_attachments, "bot_attachments", "1", 0);
07591 trap_Cvar_Register(&bot_camp, "bot_camp", "1", 0);
07592
07593 trap_Cvar_Register(&bot_wp_info, "bot_wp_info", "1", 0);
07594 trap_Cvar_Register(&bot_wp_edit, "bot_wp_edit", "0", CVAR_CHEAT);
07595 trap_Cvar_Register(&bot_wp_clearweight, "bot_wp_clearweight", "1", 0);
07596 trap_Cvar_Register(&bot_wp_distconnect, "bot_wp_distconnect", "1", 0);
07597 trap_Cvar_Register(&bot_wp_visconnect, "bot_wp_visconnect", "1", 0);
07598
07599 trap_Cvar_Update(&bot_forcepowers);
07600 //end rww
07601
07602 //if the game is restarted for a tournament
07603 if (restart) {
07604 return qtrue;
07605 }
07606
07607 //initialize the bot states
07608 memset( botstates, 0, sizeof(botstates) );
07609
07610 if (!trap_BotLibSetup())
07611 {
07612 return qfalse; //wts?!
07613 }
07614
07615 return qtrue;
07616 }
|
|
||||||||||||||||
|
|
Definition at line 7623 of file ai_main.c. References BotAIShutdownClient(), botstates, client, bot_state_s::inuse, MAX_CLIENTS, qtrue, and trap_BotLibShutdown(). Referenced by G_ShutdownGame().
07623 {
07624
07625 int i;
07626
07627 //if the game is restarted for a tournament
07628 if ( restart ) {
07629 //shutdown all the bots in the botlib
07630 for (i = 0; i < MAX_CLIENTS; i++) {
07631 if (botstates[i] && botstates[i]->inuse) {
07632 BotAIShutdownClient(botstates[i]->client, restart);
07633 }
07634 }
07635 //don't shutdown the bot library
07636 }
07637 else {
07638 trap_BotLibShutdown();
07639 }
07640 return qtrue;
07641 }
|
|
||||||||||||
|
Definition at line 891 of file ai_main.c. References bot_state_t, botstates, client, bot_state_s::gs, bot_state_s::inuse, memset(), bot_state_s::ms, numbots, qfalse, qtrue, trap_BotFreeGoalState(), trap_BotFreeMoveState(), trap_BotFreeWeaponState(), and bot_state_s::ws. Referenced by BotAIShutdown(), and ClientDisconnect().
00891 {
00892 bot_state_t *bs;
00893
00894 bs = botstates[client];
00895 if (!bs || !bs->inuse) {
00896 //BotAI_Print(PRT_ERROR, "BotAIShutdownClient: client %d already shutdown\n", client);
00897 return qfalse;
00898 }
00899
00900 trap_BotFreeMoveState(bs->ms);
00901 //free the goal state`
00902 trap_BotFreeGoalState(bs->gs);
00903 //free the weapon weights
00904 trap_BotFreeWeaponState(bs->ws);
00905 //
00906 //clear the bot state
00907 memset(bs, 0, sizeof(bot_state_t));
00908 //set the inuse flag to qfalse
00909 bs->inuse = qfalse;
00910 //there's one bot less
00911 numbots--;
00912 //everything went ok
00913 return qtrue;
00914 }
|
|