示例#1
0
    private void OrderCityBuilding()
    {
        DepartmentOfTheInterior agency  = this.Empire.GetAgency <DepartmentOfTheInterior>();
        DepartmentOfIndustry    agency2 = this.Empire.GetAgency <DepartmentOfIndustry>();

        if (this.CityLocation.IsValid && agency != null)
        {
            City closestCityFromWorldPosition = agency.GetClosestCityFromWorldPosition(this.CityLocation, true);
            if ((closestCityFromWorldPosition != null || closestCityFromWorldPosition.Empire == this.Empire) && agency2.GetConstructionQueue(closestCityFromWorldPosition).PendingConstructions.Count <= 0)
            {
                List <string> list = new List <string>
                {
                    "CityImprovementIndustry0",
                    "CityImprovementDust0",
                    "CityImprovementFood0",
                    "CityImprovementApproval1",
                    "CityImprovementScience0"
                };
                List <DepartmentOfIndustry.ConstructibleElement> list2 = new List <DepartmentOfIndustry.ConstructibleElement>();
                DepartmentOfIndustry.ConstructibleElement        constructibleElement = null;
                foreach (DepartmentOfIndustry.ConstructibleElement constructibleElement2 in agency2.ConstructibleElementDatabase.GetAvailableConstructibleElements(new StaticString[]
                {
                    CityImprovementDefinition.ReadOnlyCategory
                }))
                {
                    if (DepartmentOfTheTreasury.CheckConstructiblePrerequisites(closestCityFromWorldPosition, constructibleElement2, new string[]
                    {
                        ConstructionFlags.Prerequisite
                    }))
                    {
                        if (agency.Cities.Count == 1 && constructibleElement2.ToString().Contains("CityImprovementFIDS"))
                        {
                            constructibleElement = constructibleElement2;
                            break;
                        }
                        if (list.Contains(constructibleElement2.ToString()))
                        {
                            list2.Add(constructibleElement2);
                        }
                    }
                }
                if (constructibleElement == null && list2.Count > 0)
                {
                    using (List <string> .Enumerator enumerator = list.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            string important = enumerator.Current;
                            if (list2.Any((DepartmentOfIndustry.ConstructibleElement item) => item.Name == important))
                            {
                                constructibleElement = list2.First((DepartmentOfIndustry.ConstructibleElement item) => item.Name == important);
                                break;
                            }
                        }
                    }
                }
                if (constructibleElement != null)
                {
                    OrderQueueConstruction order = new OrderQueueConstruction(this.Empire.Index, closestCityFromWorldPosition.GUID, constructibleElement, string.Empty);
                    Ticket ticket;
                    this.Empire.PlayerControllers.AI.PostOrder(order, out ticket, null);
                }
            }
        }
    }