/// <summary>
/// Loads the bot settings from the Settings object and the /ai/aidefault.ai file
/// </summary>
protected void GetBotSettings()
{
// Get the Bot Count
int BotCount = Int32.Parse(Settings.GetValue("coopBotCount", "16"));
if (BotCount > 48)
{
BotCount = 48;
}
// Set form values
BotCountBar.Value = BotCount;
BotRatioBar.Value = Int32.Parse(Settings.GetValue("coopBotRatio", "50"));
BotDifficultyBar.Value = Int32.Parse(Settings.GetValue("coopBotDifficulty", "70"));
// Global settings does not have a aidefault.ai file
if (UseGlobalSettings)
{
ForceBotCount.Enabled = false;
return;
}
// Load the mods AiDefault.ai file
try
{
AiDefaultText = File.ReadAllText(Path.Combine(MainForm.SelectedMod.RootPath, "ai", "AiDefault.ai"));
if (!AiDefaultText.StartsWith("rem BF2Statistics Formatted"))
{
AiDefaultText = Program.GetResourceAsString("BF2Statistics.Resources.Ai.AIDefault.ai");
}
}
catch (Exception e)
{
Program.ErrorLog.Write("Warning: [ServerSettings] Could not open the AiDefault.ai file : " + e.Message);
ForceBotCount.Enabled = false;
return;
}
// Use regex to parse the settings
int MaxBots = 16;
Regex Reg = new Regex(@"aiSettings.(?<name>[A-Za-z]+)[\s|\t]+(?<value>[.0-9]+)");
MatchCollection Matches = Reg.Matches(AiDefaultText);
foreach (Match M in Matches)
{
switch (M.Groups["name"].Value.ToLower())
{
case "overridemenusettings":
ForceBotCount.Checked = BotCountForced = (M.Groups["value"].Value.Trim() == "1");
AiMatches[0] = M.Value;
break;
case "setmaxnbots":
Int32.TryParse(M.Groups["value"].Value, out MaxBots);
AiMatches[1] = M.Value;
break;
case "setbotskill":
AiMatches[2] = M.Value;
break;
case "maxbotsincludehumans":
AiMatches[3] = M.Value;
break;
}
}
// Make sure Team 1's bot count is not higher then the total bot count
if (MaxBots < BotCount)
{
MaxBots = BotCount;
}
// Set values
int Count = MaxBots - BotCount;
BotCountBar1.Value = ((Count > 48) ? 48 : Count);
BotCountBar2.Value = BotCount;
}