Ejemplo n.º 1
0
        public override int CompareTo(object o)
        {
            ResearchInfo toCompare = o as ResearchInfo;

            if (toCompare != null)
            {
                foreach (RequirementInfo req in this.Requirements.Values)
                {
                    if (req is RequiredResearch)
                    {
                        RequiredResearch reqRes = (RequiredResearch)req;
                        if (Translation.Translate(reqRes.Research) == toCompare.Name)
                        {
                            return(1);
                        }
                    }
                }
                foreach (RequirementInfo req in toCompare.Requirements.Values)
                {
                    if (req is RequiredResearch)
                    {
                        RequiredResearch reqRes = (RequiredResearch)req;
                        if (Translation.Translate(reqRes.Research) == this.Name)
                        {
                            return(-1);
                        }
                    }
                }
            }
            return(base.CompareTo(o));
        }
Ejemplo n.º 2
0
        public static void Dump()
        {
            // Clear Resources
            Addons.Clear();
            Skills.Clear();
            Squads.Clear();
            Buildings.Clear();
            Units.Clear();
            Researches.Clear();
            MainForm.Log("Lua processing started...");
            DateTime start = DateTime.Now;


            Hashtable temp = (Hashtable)FilesTable.Clone();

            foreach (string lua in temp.Keys)
            {
                LuaInfo lInfo = temp[lua] as LuaInfo;
                if (lInfo.Type == InfoTypes.Building)
                {
                    StreamReader file = new StreamReader(File.OpenRead(lInfo.Path), System.Text.Encoding.ASCII);
                    file.BaseStream.Seek(0, SeekOrigin.Begin);

                    string s = file.ReadToEnd();

                    file.Close();

                    MatchCollection mccR = Regex.Matches(s, @"GameData\[""research_ext""\]\[""research_table""\]\[""research_([0-9]?[0-9]?)""\]\s=\s""(.*\\\\)?((?<research>.*)\.lua|(?<research>.*))""");
                    if (mccR.Count > 0)
                    {
                        foreach (Match mt in mccR)
                        {
                            Group research = mt.Groups["research"];

                            if (research.Success && research.Value != "")
                            {
                                string res = research.Value;
                                if (!res.EndsWith(".lua"))
                                {
                                    res += ".lua";
                                }
                                res = Path.Combine("research", res);
                                string path = DataPath.GetPath(res);

                                string  race   = GetRace(lInfo.Path);
                                LuaInfo resLua = new LuaInfo(path, InfoTypes.Research, race);

                                if (!FilesTable.Contains(res))
                                {
                                    FilesTable.Add(res, resLua);
                                }
                            }
                        }
                    }
                }
            }
            int count = FilesTable.Count;

            MainForm.BarSetMax(Bars.Data, count);
            // Collecting resources from lua files.
            foreach (string lua in FilesTable.Keys)
            {
                LuaInfo lInfo = FilesTable[lua] as LuaInfo;

                switch (lInfo.Type)
                {
                case InfoTypes.Research:
                    ResearchInfo rInfo = new ResearchInfo();
                    rInfo.Race     = lInfo.Race;
                    rInfo.FileName = Regex.Replace(lua, @"\.lua|\.nil|(.*)\\", "");

                    try
                    {
                        LuaParser.ParseResearch(lInfo.Path, rInfo);
                    }
                    catch (Exception e)
                    {
                    }

                    MainForm.BarInc(Bars.Data);
                    Researches.Add(rInfo);
                    break;

                case InfoTypes.Unit:

                    SquadInfo sInfo = new SquadInfo();
                    sInfo.Race     = lInfo.Race;
                    sInfo.FileName = Regex.Replace(lua, @"\.lua|\.nil", "");
                    LuaParser.ParseSquad(lInfo.Path, sInfo);
                    MainForm.BarInc(Bars.Data);
                    if (sInfo.Unit != null)
                    {
                        Squads.Add(sInfo);
                    }
                    break;

                case InfoTypes.Building:
                    BuildingInfo bInfo = new BuildingInfo();
                    bInfo.Race     = lInfo.Race;
                    bInfo.FileName = Regex.Replace(lua, @"\.lua|\.nil", "");
                    LuaParser.ParseBuilding(lInfo.Path, bInfo);
                    MainForm.BarInc(Bars.Data);
                    Buildings.Add(bInfo);
                    break;
                }
            }
            Researches.Sort();
            Squads.Sort();
            Buildings.Sort();

            TimeSpan elapsed = DateTime.Now - start;

            MainForm.Log("Lua processing done in " + Math.Round(elapsed.TotalSeconds, 2) + " seconds.");
        }