Esempio n. 1
0
        public override int CompareTo(object o)
        {
            if (!(o is SquadInfo))
            {
                return(-1);
            }

            SquadInfo toCompare = o as SquadInfo;

            if (Race.CompareTo(toCompare.Race) < 0)
            {
                return(-1);
            }
            if (Race.CompareTo(toCompare.Race) > 0)
            {
                return(1);
            }
            if (Unit == null)
            {
                return(-1);
            }
            else if (toCompare.Unit == null)
            {
                return(1);
            }
            else
            {
                int comp = Unit.ArmorType.CompareTo(toCompare.Unit.ArmorType);
                if (comp != 0)
                {
                    return(comp);
                }
            }
            return(Name.CompareTo(toCompare.Name));
        }
Esempio 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.");
        }
Esempio n. 3
0
        public override string Compile()
        {
            if (Parent != null)
            {
                string target  = "";
                string action  = "Increases ";
                bool   further = false;
                string amount  = "";
                bool   stacks  = !DoNotStacks;

                switch (UsageType)
                {
                case UsageTypes.Add:
                    if (Amount < 0)
                    {
                        action = "Decreases";
                    }
                    break;

                case UsageTypes.Multiply:
                    if (Amount < 1)
                    {
                        action = "Decreases";
                    }
                    break;
                }

                double mul = 1.0;

                if (Parent is SquadInfo || Parent is UnitInfo)
                {
                    SquadInfo squad   = Parent is UnitInfo ? (SquadInfo)((UnitInfo)Parent).Parent : (SquadInfo)Parent;
                    bool      isSquad = squad.MaxSquadSize > 1;

                    if (TargetName == squad.Unit.Name)
                    {
                        further = true;
                    }

                    if (isSquad)
                    {
                        target = TargetName + " squads";
                        mul    = squad.StartingSquadSize;
                    }
                    else
                    {
                        target = HtmlCompiler.GetPlural(TargetName);
                    }
                }
                else if (Parent is ResearchInfo)
                {
                    target = TargetName;
                }
                else if (Parent is BuildingInfo)
                {
                    if (TargetName == ((BuildingInfo)Parent).Name)
                    {
                        further = true;
                    }
                    target = HtmlCompiler.GetPlural(TargetName);
                }
                else
                {
                    target = HtmlCompiler.GetPlural(TargetName);
                }

                if (this.UsageType == UsageTypes.Add)
                {
                    amount = ((double)Math.Abs((mul * Amount))).ToString();
                }
                else
                {
                    amount = ((double)(mul * Math.Abs((this.Amount - 1) * 100))).ToString() + "%";
                }

                return(action + " the " + this.ModifierTranslation + " of " + (further ? "further " : "") + target + " by " + amount + (ModifierTranslation == "build time" ? " seconds" : "") + (stacks ? "" : "(do not stacks)"));
            }
            return(base.Compile());
        }