void BotControl::Think (void) { // this function calls think () function for all available at call moment bots, and // try to catch internal error if such shit occurs for (int i = 0; i < engine->GetMaxClients (); i++) { if (m_bots[i] != null) { if (m_bots[i]->m_thinkTimer <= engine->GetTime ()) { // use these try-catch blocks to prevent server crashes when error occurs #if !defined (NDEBUG) && !defined (_DEBUG) try { m_bots[i]->Think (); } catch (...) { // error occurred. kick off all bots and then print a warning message RemoveAll (); ServerPrintNoTag ("**** INTERNAL BOT ERROR! PLEASE SHUTDOWN AND RESTART YOUR SERVER! ****"); } #else m_bots[i]->Think (); #endif //m_bots[i]->m_thinkTimer = engine->GetTime () + thinkFps; if (IsDedicatedServer ()) m_bots[i]->m_thinkTimer = engine->GetTime () + (1.0f / (CVAR_GET_FLOAT("fps_max")/2)) * 0.88f; else m_bots[i]->m_thinkTimer = engine->GetTime (); } } } }
Bot::Bot (edict_t *bot, int skill, int personality, int team, int member) { // this function does core operation of creating bot, it's called by CreateBot (), // when bot setup completed, (this is a bot class constructor) char rejectReason[128]; int clientIndex = ENTINDEX (bot); memset (this, 0, sizeof (Bot)); pev = VARS (bot); if (bot->pvPrivateData != null) FREE_PRIVATE (bot); bot->pvPrivateData = null; bot->v.frags = 0; // create the player entity by calling MOD's player function BotControl::CallGameEntity (&bot->v); // set all info buffer keys for this bot char *buffer = GET_INFOKEYBUFFER (bot); SET_CLIENT_KEYVALUE (clientIndex, buffer, "model", ""); SET_CLIENT_KEYVALUE (clientIndex, buffer, "rate", "3500.000000"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_updaterate", "20"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_lw", "1"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_lc", "1"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "tracker", "0"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_dlmax", "128"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "friends", "0"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "dm", "0"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "_ah", "0"); if (yb_tagbots.GetBool ()) SET_CLIENT_KEYVALUE (clientIndex, buffer, "*bot", "1"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "_vgui_menus", "0"); memset (rejectReason, 0, sizeof (rejectReason)); // reset the reject reason template string MDLL_ClientConnect (bot, "fakeclient", FormatBuffer ("192.168.1.%d", ENTINDEX (bot) + 100), rejectReason); if (!IsNullString (rejectReason)) { AddLogEntry (true, LOG_WARNING, "Server refused '%s' connection (%s)", STRING (bot->v.netname), rejectReason); ServerCommand ("kick \"%s\"", STRING (bot->v.netname)); // kick the bot player if the server refused it bot->v.flags |= FL_KILLME; } if (IsDedicatedServer () && engine->GetDeveloperLevel () > 0) { if (engine->GetDeveloperLevel () == 2) { ServerPrint ("Server requiring authentication"); ServerPrint ("Client '%s' connected", STRING (bot->v.netname)); ServerPrint ("Adr: 127.0.0.%d:27005", ENTINDEX (bot) + 100); } ServerPrint ("Verifying and uploading resources..."); ServerPrint ("Custom resources total 0 bytes"); ServerPrint (" Decals: 0 bytes"); ServerPrint ("----------------------"); ServerPrint ("Resources to request: 0 bytes"); } MDLL_ClientPutInServer (bot); bot->v.flags = 0; bot->v.flags |= FL_FAKECLIENT | FL_CLIENT; // set this player as fakeclient // initialize all the variables for this bot... m_notStarted = true; // hasn't joined game yet m_startAction = CMENU_IDLE; m_moneyAmount = 0; m_logotypeIndex = engine->RandomInt (0, 5); // initialize msec value m_msecNum = m_msecDel = 0.0f; m_msecInterval = engine->GetTime (); m_msecVal = static_cast <uint8_t> (g_pGlobals->frametime * 1000.0f); m_msecBuiltin = engine->RandomInt (1, 4); // assign how talkative this bot will be m_sayTextBuffer.chatDelay = engine->RandomFloat (3.8f, 10.0f); m_sayTextBuffer.chatProbability = engine->RandomInt (1, 100); m_notKilled = false; m_skill = skill; m_weaponBurstMode = BURST_DISABLED; m_lastThinkTime = engine->GetTime (); m_frameInterval = engine->GetTime (); bot->v.idealpitch = bot->v.v_angle.x; bot->v.ideal_yaw = bot->v.v_angle.y; bot->v.yaw_speed = engine->RandomFloat (g_skillTab[m_skill / 20].minTurnSpeed, g_skillTab[m_skill / 20].maxTurnSpeed); bot->v.pitch_speed = engine->RandomFloat (g_skillTab[m_skill / 20].minTurnSpeed, g_skillTab[m_skill / 20].maxTurnSpeed); switch (personality) { case 1: m_personality = PERSONALITY_RUSHER; m_baseAgressionLevel = engine->RandomFloat (0.7f, 1.0f); m_baseFearLevel = engine->RandomFloat (0.0f, 0.4f); break; case 2: m_personality = PERSONALITY_CAREFUL; m_baseAgressionLevel = engine->RandomFloat (0.0f, 0.4f); m_baseFearLevel = engine->RandomFloat (0.7f, 1.0f); break; default: m_personality = PERSONALITY_NORMAL; m_baseAgressionLevel = engine->RandomFloat (0.4f, 0.7f); m_baseFearLevel = engine->RandomFloat (0.4f, 0.7f); break; } memset (&m_ammoInClip, 0, sizeof (m_ammoInClip)); memset (&m_ammo, 0, sizeof (m_ammo)); m_currentWeapon = 0; // current weapon is not assigned at start m_voicePitch = engine->RandomInt (166, 250) / 2; // assign voice pitch // copy them over to the temp level variables m_agressionLevel = m_baseAgressionLevel; m_fearLevel = m_baseFearLevel; m_nextEmotionUpdate = engine->GetTime () + 0.5f; // just to be sure m_actMessageIndex = 0; m_pushMessageIndex = 0; // assign team and class m_wantedTeam = team; m_wantedClass = member; NewRound (); }