Esempio n. 1
0
// Return random unused profile that matches the given difficulty level
const BotProfile *BotProfileManager::GetRandomProfile(BotDifficultyType difficulty, BotProfileTeamType team) const
{
#ifdef RANDOM_LONG
	BotProfileList::const_iterator iter;

	// count up valid profiles
	int validCount = 0;
	for (auto profile : m_profileList)
	{
		if (profile->IsDifficulty(difficulty) && !UTIL_IsNameTaken(profile->GetName()) && profile->IsValidForTeam(team))
			validCount++;
	}

	if (validCount == 0)
		return nullptr;

	// select one at random
	int which = RANDOM_LONG(0, validCount - 1);
	for (auto profile : m_profileList)
	{
		if (profile->IsDifficulty(difficulty) && !UTIL_IsNameTaken(profile->GetName()) && profile->IsValidForTeam(team))
		{
			if (which-- == 0)
				return profile;
		}
	}

	return nullptr;
#else
	// we don't need random profiles when we're not in the game dll
	return nullptr;
#endif // RANDOM_LONG
}
Esempio n. 2
0
/**
 * Return random unused profile that matches the given difficulty level
 */
const BotProfile *BotProfileManager::GetRandomProfile( BotDifficultyType difficulty, BotProfileTeamType team ) const
{
#ifndef RANDOM_LONG
	return NULL;	// we don't need random profiles when we're not in the game dll
#else
	BotProfileList::const_iterator iter;

	// count up valid profiles
	int validCount = 0;
	for( iter = m_profileList.begin(); iter != m_profileList.end(); ++iter )
	{
		const BotProfile *profile = *iter;

		if (profile->IsDifficulty( difficulty ) && !UTIL_IsNameTaken( profile->GetName() ) && profile->IsValidForTeam( team ))
			++validCount;
	}

	if (validCount == 0)
		return NULL;

	// select one at random
	int which = RANDOM_LONG( 0, validCount-1 );
	for( iter = m_profileList.begin(); iter != m_profileList.end(); ++iter )
	{
		const BotProfile *profile = *iter;

		if (profile->IsDifficulty( difficulty ) && !UTIL_IsNameTaken( profile->GetName() ) && profile->IsValidForTeam( team ))
			if (which-- == 0)
				return profile;
	}

	return NULL;
#endif;
}
Esempio n. 3
0
/* <36c3c2> ../cstrike/dlls/bot/cs_bot_manager.cpp:903 */
NOBODY bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
{
	if (IMPLEMENT_ARRAY(m_isLearningMap) || ENG_CHECK_PARM("-nobots", NULL))
		return false;

	const BotProfile *profile = NULL;

	if (!isFromConsole || CMD_ARGC() < 2)
	{
		if (team == BOT_TEAM_ANY)
		{
			// if team not specified, check cv_bot_join_team cvar for preference
			if (!Q_stricmp(cv_bot_join_team.string, "T"))
				team = BOT_TEAM_T;

			else if (!Q_stricmp(cv_bot_join_team.string, "CT"))
				team = BOT_TEAM_CT;
			else
			{
				TeamName defaultTeam = SelectDefaultTeam();

				if (defaultTeam == TERRORIST)
					team = BOT_TEAM_T;

				else if (defaultTeam == CT)
					team = BOT_TEAM_CT;
			}
		}

		// try to add a bot by name
		profile = TheBotProfiles->GetRandomProfile(GetDifficultyLevel(), team);

		if (profile == NULL)
		{
			CONSOLE_ECHO("All bot profiles at this difficulty level are in use.\n");
			return true;
		}
	}
	else
	{
		// in career, ignore humans
		bool ignoreHumans = false;
		CHalfLifeMultiplay *mp = g_pGameRules;

		if (mp && mp->IsCareer())
			ignoreHumans = true;

		if (UTIL_IsNameTaken(CMD_ARGV(1), ignoreHumans))
		{
			CONSOLE_ECHO("Error - %s is already in the game.\n", CMD_ARGV(1));
			return true;
		}

		profile = TheBotProfiles->GetProfile(CMD_ARGV(1), team);
		if (profile == NULL)
		{
			CONSOLE_ECHO("Error - no profile for '%s' exists.\n", CMD_ARGV(1));
			return true;
		}
	}

	// create the bot
	if (CCSBotManager::AddBot(profile, team))	// TODO: Reverse me
	{
		if (isFromConsole)
		{
			// increase the bot quota to account for manually added bot
			CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value + 1);
		}
	}

	return true;
}