Esempio n. 1
0
        public static ObservableCollection <Technology> getTechnologies(ThreadingObservableCollection <Technology> ret, ThreadingObservableCollection <WeaponCategory> weaponCategories)
        {
            GlobalInfos global   = GlobalInfos.getInstance();
            TextFile    techFile = global.getPath(@"\localisation\technology.csv");

            if (techFile == null)
            {
                return(null);
            }
            bool   isstart = true;
            string typ     = "";

            //ObservableCollection<Technology> ret = new ObservableCollection<Technology>();
            string[] techLines   = techFile.Lines;
            Regex    infantryReg = new Regex("Infantry Techs");
            Regex    descReg     = new Regex("_desc");

            for (int i = 0; i < techLines.Length; i++)
            {
                string   line      = techLines[i];
                string[] lineparts = line.Split(';');
                if (isstart)
                {
                    if (infantryReg.IsMatch(lineparts[0]))
                    {
                        isstart = false;
                        typ     = "_Infantry Technologies.txt";
                    }
                }
                else if (!line.StartsWith("#") && i != 0)
                {
                    if (!descReg.IsMatch(lineparts[0]))
                    {
                        Technology tech = new Technology(line);
                        tech.Typ = typ;
                        findTyps_new(tech, weaponCategories);
                        ret.Add(tech);
                    }
                }
                else
                {
                    string typline = lineparts[0].Split('#')[1].Trim();
                    switch (typline)
                    {
                    case "Artillery Techs":
                        typ = "ArtilleryTechnologies.txt";
                        break;

                    case "Tech Names":
                        i = techLines.Length;
                        break;

                    case "Naval Techs":
                        typ = "Naval Technologies.txt";
                        break;

                    case "Armour Techs":
                        typ = "Armour Technologies.txt";
                        break;

                    case "Aircraft Techs":
                        typ = "Aircraft Technology.txt";
                        break;

                    case "Industry Techs":
                        typ = "_Industry Technologies.txt";
                        break;

                    case "Secret Weapons":
                        typ = "Secret Weapons.txt";
                        break;

                    case "Theoretical Research":
                        typ = "Theories.txt";
                        break;

                    case "Land Doctrine Techs":
                        typ = "Land Doctrines.txt";
                        break;

                    case "Naval Doctrine Techs":
                        typ = "Naval Doctrines.txt";
                        break;

                    case "Air Doctrine Techs":
                        typ = "Aircraftz Doctrines.txt";
                        break;
                    }
                }
            }
            return(ret);
        }
Esempio n. 2
0
        public static ObservableCollection <Technologyname> getTechnologynames(ThreadingObservableCollection <Technologyname> ret, ThreadingObservableCollection <Country> countries, ThreadingObservableCollection <Technology> technologies)
        {
            //ObservableCollection<Technologyname> ret = new ObservableCollection<Technologyname>();
            GlobalInfos global       = GlobalInfos.getInstance();
            bool        isstart      = true;
            TextFile    technameFile = global.getPath(@"\localisation\technology.csv");

            if (technameFile == null)
            {
                return(null);
            }
            string[] technameLines = technameFile.Lines;
            //for (int i = 0; i < technameLines.Length; i++) {
            //    string line = technameLines[i];
            foreach (string line in technameLines)
            {
                string[] lineparts = line.Split(';');
                if (isstart)
                {
                    if (lineparts[0] == "# Tech Names")
                    {
                        isstart = false;
                    }
                }
                else
                {
                    if (lineparts[0] == "# Building Names")
                    {
                        break;
                    }
                    else
                    {
                        if (line.StartsWith("#"))
                        {
                            continue;
                        }
                        Technologyname t         = new Technologyname(line);
                        string[]       nameparts = t.Shortcut.Split('_');
                        if (!countries.Any(x => x.Shortcut == nameparts[0]))
                        {
                            continue;
                        }
                        t.Country = countries.First(x => x.Shortcut == nameparts[0]);
                        string Technology = "";
                        for (int j = 1; j < nameparts.Length - 1; j++)
                        {
                            Technology += nameparts[j];
                            if (j != nameparts.Length - 2)
                            {
                                Technology += "_";
                            }
                        }
                        if (!technologies.Any(x => x.Shortcut == Technology))
                        {
                            continue;
                        }
                        t.Technology = technologies.First(x => x.Shortcut == Technology);
                        t.Stage      = (nameparts[nameparts.Length - 1]);
                        ret.Add(t);
                    }
                }
            }
            return(ret);
        }
Esempio n. 3
0
        private static void findTyps_new(Technology t, ObservableCollection <WeaponCategory> weaponCategories)
        {
            GlobalInfos global  = GlobalInfos.getInstance();
            TextFile    typFile = global.getPath(@"technologies\" + t.Typ);

            if (typFile == null)
            {
                return;
            }
            int           breckets   = -1;
            string        aktTech    = "";
            List <string> List_Lines = new List <string>();

            string[] typLines = typFile.Lines;
            for (int i = 0; i < typLines.Length; i++)
            {
                string line = typLines[i];
                Regex  r    = new Regex("\\b" + t.Shortcut + "( |=)");
                if (!r.IsMatch(line))
                {
                    continue;
                }
                aktTech = t.Shortcut;
                while (breckets != 0)
                {
                    if (line != "" && line != "\t" && line != "\t\t")
                    {
                        if (line.IndexOf('{') != -1)
                        {
                            if (breckets != -1)
                            {
                                breckets++;
                            }
                            else
                            {
                                breckets = 1;
                            }
                        }
                        if (line.IndexOf('}') != -1 && aktTech != "")
                        {
                            breckets--;
                        }
                        List_Lines.Add(line.Split('=')[0].Trim());
                    }
                    i++;
                    if (i < typLines.Length)
                    {
                        line = typLines[i];
                    }
                }
                if (List_Lines.Count > 0)
                {
                    break;
                }
            }
            int  tmpBreckets = 0;
            bool allow       = false;

            foreach (string line in List_Lines)
            {
                if (line.IndexOf('{') != -1)
                {
                    if (breckets != -1)
                    {
                        breckets++;
                    }
                    else
                    {
                        breckets = 1;
                    }
                }
                if (line.IndexOf('}') != -1)
                {
                    breckets--;
                }
                if (!allow)
                {
                    Regex r = new Regex("additional_offset");
                    if (r.IsMatch(line))
                    {
                        t.OnceTech = false;
                    }
                    else
                    {
                        r = new Regex("allow = {");
                        if (r.IsMatch(line))
                        {
                            allow       = true;
                            tmpBreckets = breckets;
                        }
                        else if (weaponCategories.Any(x => x.Shortcut == line))
                        {
                            WeaponCategory wt = weaponCategories.First(x => x.Shortcut == line);
                            wt.ListTechnologies.Add(t);
                            t.WeaponCategories.Add(wt);
                        }
                    }
                }
                if (tmpBreckets == breckets)
                {
                    allow = false;
                }
            }
        }