/// <summary>
        /// Adds a bot to the control
        /// </summary>
        /// <param name="bot">the instance of Bot to add</param>
        public void AddBot(Bot bot)
        {
            string[] items = new string[10];
            char[] modelSkinSeperator = new char[] { '/' };

            //foreach (Bot b in bots)
            //{
                string[] modelAndSkin = bot.ModelAndSkin.Split(modelSkinSeperator);
                items[0] = bot.Name;

                // if two substrings dont result from the split operation,
                // falling back to the original string is probably the best bet.
                if (modelAndSkin.Length == 2)
                {
                    items[1] = modelAndSkin[0];
                    items[2] = modelAndSkin[1];
                }
                else
                {
                    items[1] = bot.ModelAndSkin;
                    items[2] = bot.ModelAndSkin;
                }

                items[3] = bot.FiringAccuracy.ToString();
                items[4] = bot.Aggressiveness.ToString();
                items[5] = bot.CombatSkills.ToString();
                items[6] = bot.FavouredWeapon.ToString();
                items[7] = bot.IsQuadFreak.ToString();
                items[8] = bot.IsCamper.ToString();
                items[9] = bot.Ping.ToString();

                ListViewItem lvi = new ListViewItem(items);
                this.Items.Add(lvi);
        }
 public void PopulateListView(Bot[] bots)
 {
     foreach (Bot b in bots)
     {
         specificBotsListView.AddBot(b);
     }
 }
        /// <summary>
        /// Use CheckedBots() to easily retrieve instances of any bots that are checked within
        /// the control. 
        /// </summary>
        /// <returns>If 1 or more bots are checked, an Array of type Bot will be returned
        /// containing instances of all bots checked within the control. If not bots are checked
        /// an empty array will be returned.</returns>
        public Bot[] CheckedBots()
        {
            List<Bot> botList = new List<Bot>();

            foreach (ListViewItem item in this.CheckedItems)
            {
                StringBuilder modelAndSkin = new StringBuilder(
                    item.SubItems[1].Text + "/" + item.SubItems[2].Text
                    );

                uint accuracy = uint.Parse(item.SubItems[3].Text);
                uint aggressiveness = uint.Parse(item.SubItems[4].Text);
                uint combat = uint.Parse(item.SubItems[5].Text);

                FavouriteWeapon weapon = (FavouriteWeapon) Enum.Parse(typeof(FavouriteWeapon),
                    item.SubItems[6].Text, true);

                bool quadFreak = Boolean.Parse(item.SubItems[7].Text);
                bool camper = Boolean.Parse(item.SubItems[8].Text);
                uint averagePing = uint.Parse(item.SubItems[9].Text);

                Bot checkedBot = new Bot(
                    item.SubItems[0].Text,  // Name
                    modelAndSkin.ToString(),
                    accuracy,
                    aggressiveness,
                    combat,  // combat skill
                    weapon,                 // favourite weapon
                    quadFreak,
                    camper,
                    averagePing
                    );

                botList.Add(checkedBot);
            }

            return botList.ToArray();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses the bot file, storing bots and bot team data in the appropriate structures.
        /// </summary>
        /// <param name="path">Absolute path to the bot configuration file</param>
        /// <returns>Array containing the bots stored in the bot file</returns>
        public BotFileOutput ParseFile(string path)
        {
            // This code is rough but it does the trick. It could do with some stress
            // testing.

            bool insideBotSection = false;
            bool insideTeamSection = false;

            try
            {
                using (StreamReader sr = new StreamReader(path))
                {
                    //string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        line.Trim();

                        if (line.Length > 0)
                        {
                            if (line[0] != '#') // # are comments
                            {
                                startPosition = 0;

                                if (line[0] == '[')
                                {
                                    int start = line.IndexOf("[");
                                    int finish = line.IndexOf("]");

                                    string subString = line.Substring(start + 1, finish - 1);
                                    subString = subString.ToLower();

                                    // determine which section the file pointer is currently
                                    // entering. Kinda redundant - it's probably better
                                    // to just go ahead and parse the especified section, instead
                                    // of waiting for the next iteration of the loop. But whatever.
                                    if (subString == "bots")
                                    {
                                        insideBotSection = true;
                                        insideTeamSection = false;
                                    }
                                    else if (subString == "teams")
                                    {
                                        insideTeamSection = true;
                                        insideBotSection = false;
                                    }
                                    else
                                    {
                                        insideBotSection = false;
                                        insideTeamSection = false;
                                    }
                                }

                                else if (insideBotSection)
                                {

                                    //StringBuilder sb = new StringBuilder();
                                    Bot parsedBot = new Bot("", "", 0, 0, 0, FavouriteWeapon.BFG,
                                        false, false, 0);

                                    parsedBot.Name = RetrieveNextString();
                                    parsedBot.ModelAndSkin = RetrieveNextString();
                                    parsedBot.FiringAccuracy = (uint)RetrieveNextInteger(0);
                                    parsedBot.Aggressiveness = (uint)RetrieveNextInteger(0);
                                    parsedBot.CombatSkills = (uint)RetrieveNextInteger(0);
                                    parsedBot.FavouredWeapon = (FavouriteWeapon)RetrieveNextInteger(0);
                                    parsedBot.IsQuadFreak = Convert.ToBoolean(RetrieveNextInteger(0));
                                    parsedBot.IsCamper = Convert.ToBoolean(RetrieveNextInteger(0));
                                    parsedBot.Ping = (uint)RetrieveNextInteger(0);

                                    bots.Add(parsedBot);
                                }
                                else if (insideTeamSection)
                                {
                                    Team parsedTeam = new Team("", "", "", null);

                                    parsedTeam.Name = RetrieveNextString();
                                    parsedTeam.Abbreviation = RetrieveNextString();
                                    parsedTeam.SkinAndModel = RetrieveNextString();
                                    parsedTeam.Members = RetrieveStringCollection();

                                    teams.Add(parsedTeam);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message + e.StackTrace);
                StringBuilder sb = new StringBuilder();
                sb.Append(e.Message + Environment.NewLine);
                sb.Append(e.StackTrace + Environment.NewLine);

                throw new Exception(sb.ToString());

            }

            BotFileOutput output = new BotFileOutput(bots, teams);

            return output;
        }