예제 #1
0
        // Spawn Area combobox management

        void InitSpawnAreaComboBox()
        {
            comboBoxSpawnArea.Items.Clear();
            StringCollection strc = CaTypeArea.GetAreaNames();

            for (int i = CaTypeArea.VirtualAreaCount; i < strc.Count; i++)
            {
                comboBoxSpawnArea.Items.Add(strc[i]);
            }

            if (m_ugSelected != null)
            {
                int i = -1;
                if (m_ugSelected.SpawnArea != null)
                {
                    i = comboBoxSpawnArea.Items.IndexOf(m_ugSelected.SpawnArea);
                }
                if (i == -1)
                {
                    comboBoxSpawnArea.ResetText();
                }
                else
                {
                    comboBoxSpawnArea.SelectedIndex = i;
                }
            }
        }
예제 #2
0
        public static UnitGroup FromIniSection(Ini.Section sec)
        {
            UnitGroup ug = new UnitGroup(sec["Name"].Value);

            ug.Side                  = (Side)int.Parse(sec["Side"].Value);
            ug.Aggressiveness        = (Aggressiveness)int.Parse(sec["Aggressiveness"].Value);
            ug.LoopForever           = (int.Parse(sec["LoopForever"].Value) != 0);
            ug.CreateAtLevelLoad     = (int.Parse(sec["CreateAtLevelLoad"].Value) != 0);
            ug.RandomGroup           = (int.Parse(sec["RandomGroup"].Value) != 0);
            ug.Spawn                 = (int.Parse(sec["Spawn"].Value) != 0);
            ug.ReplaceDestroyedGroup = (int.Parse(sec["ReplaceGroup"].Value) != 0);
            if (sec["SpawnArea"] != null)
            {
                ug.SpawnArea = CaTypeArea.GetAreaNameFromIndex(int.Parse(sec["SpawnArea"].Value));
            }
            ug.Health = int.Parse(sec["Health"].Value);

            // Units

            string strUTC = null;

            if (sec["Units"] != null)
            {
                strUTC = sec["Units"].Value;
            }
            if (strUTC != null)
            {
                Regex  re   = new Regex(@"^(?<count>\d+),(?<end>.*)$");
                Match  m    = re.Match(strUTC);
                string strT = m.Groups["end"].Value;
                while (strT.Length != 0)
                {
                    UnitTypeAndCount utc = new UnitTypeAndCount();
                    strT = utc.FromSaveString(strT);
                    ug.UnitTypeAndCounts.Add(utc);
                    re   = new Regex(@"^\s*,(?<end>.*)$");
                    m    = re.Match(strT);
                    strT = m.Groups["end"].Value;
                }
            }

            // UnitGroup actions

            foreach (Ini.Property prop in sec.Properties)
            {
                if (prop.Name != "A")
                {
                    continue;
                }
                CaBase cab = UnitGroupActionLoader.LoadIni(prop.Value);
                ug.Actions.Add(cab);
            }
            return(ug);
        }
예제 #3
0
        public void AddIniProperties(Ini.Section sec)
        {
            // Save Name

            sec.Add(new Ini.Property("Name", Name));

            // Save Side

            sec.Add(new Ini.Property("Side", "k" + m_side.ToString()));

            // Save Aggressiveness

            sec.Add(new Ini.Property("Aggressiveness", "knAggressiveness" + m_aggr.ToString()));

            // Save flags

            sec.Add(new Ini.Property("LoopForever", m_fLoopForever ? "1" : "0"));
            sec.Add(new Ini.Property("CreateAtLevelLoad", m_fCreateAtLevelLoad ? "1" : "0"));
            sec.Add(new Ini.Property("RandomGroup", m_fRandomGroup ? "1" : "0"));
            sec.Add(new Ini.Property("Spawn", m_fSpawn ? "1" : "0"));
            sec.Add(new Ini.Property("ReplaceGroup", m_fReplaceDestroyedGroup ? "1" : "0"));

            // Save SpawnArea

            int nSpawnArea = CaTypeArea.GetArea(m_strSpawnArea);

            if (nSpawnArea != -1)
            {
                sec.Add(new Ini.Property("SpawnArea", nSpawnArea.ToString()));
            }

            // Save Health

            sec.Add(new Ini.Property("Health", Health.ToString()));

            // Save unit list

            if (m_alsUnitTypeAndCounts.Count > 0)
            {
                // Write total # of units

                int cTotalUnits = 0;
                foreach (UnitTypeAndCount utc in m_alsUnitTypeAndCounts)
                {
                    cTotalUnits += utc.c;
                }
                string str = cTotalUnits.ToString();

                // Write unit/count pairs

                foreach (UnitTypeAndCount utc in m_alsUnitTypeAndCounts)
                {
                    str += "," + utc.ToSaveString();
                }

                sec.Add(new Ini.Property("Units", str));
            }

            // Save actions

            foreach (CaBase cab in m_alsActions)
            {
                if (!(cab is CommentUnitGroupAction))
                {
                    sec.Add(new Ini.Property("A", cab.ToSaveString()));
                }
            }
        }