private void ComputeObjectivePriority()
    {
        bool flag = false;

        if (this.departmentOfForeignAffairs.IsInWarWithSomeone())
        {
            flag = true;
        }
        else
        {
            foreach (City city in this.departmentOfTheInterior.Cities)
            {
                if (!this.worldAtlasAIHelper.IsRegionPacified(base.AIEntity.Empire, city.Region) || city.BesiegingEmpireIndex >= 0)
                {
                    flag = true;
                    break;
                }
            }
        }
        base.GlobalPriority.Reset();
        base.GlobalPriority.Add(0.1f, "(constant)", new object[0]);
        AILayer_Colonization layer = base.AIEntity.GetLayer <AILayer_Colonization>();

        for (int i = 0; i < this.globalObjectiveMessages.Count; i++)
        {
            GlobalObjectiveMessage globalObjectiveMessage = this.globalObjectiveMessages[i];
            HeuristicValue         heuristicValue         = new HeuristicValue(0f);
            heuristicValue.Add(layer.GetColonizationInterest(globalObjectiveMessage.RegionIndex), "Region colo interest", new object[0]);
            if (this.departmentOfCreepingNodes != null)
            {
                if (this.departmentOfCreepingNodes.Nodes.Any((CreepingNode CN) => CN.Region.Index == globalObjectiveMessage.RegionIndex))
                {
                    heuristicValue.Boost(1f, "bloom in region", new object[0]);
                }
                else if (this.departmentOfCreepingNodes.Nodes.Count > 0)
                {
                    heuristicValue.Max(0.5f, "bloom in region", new object[0]);
                }
            }
            heuristicValue.Multiply(0.1f, "(constant)", new object[0]);
            globalObjectiveMessage.LocalPriority  = heuristicValue;
            globalObjectiveMessage.GlobalPriority = base.GlobalPriority;
            if (i < 1 && !flag && base.AIEntity.Empire.GetAgency <DepartmentOfDefense>().Armies.Count > 2)
            {
                globalObjectiveMessage.LocalPriority.Boost(0.75f, "(constant)", new object[0]);
                globalObjectiveMessage.GlobalPriority.Boost(0.75f, "(constant)", new object[0]);
            }
            globalObjectiveMessage.TimeOut = 1;
        }
    }
Example #2
0
    private int GetNumberOfAcceptedColonization()
    {
        int num = 0;

        if (this.departmentOfTheInterior.Cities.Count == 0)
        {
            return(1);
        }
        if (this.CurrentSettlerCount == 0 && !AILayer_Colonization.IsAbleToColonize(base.AIEntity.Empire))
        {
            return(0);
        }
        int num2 = 0;

        for (int i = 0; i < this.departmentOfTheInterior.Cities.Count; i++)
        {
            if (!this.worldAtlasHelper.IsRegionPacified(base.AIEntity.Empire.Index, this.departmentOfTheInterior.Cities[i].Region.Index))
            {
                num2++;
            }
        }
        float num3 = Mathf.Clamp(this.empireApprovalNeededToEngageColonization, 0f, 100f);
        float num4 = base.AIEntity.Empire.GetPropertyValue(SimulationProperties.NetEmpireApproval);
        float propertyBaseValue  = this.departmentOfTheInterior.Cities[0].GetPropertyBaseValue(SimulationProperties.CityExpansionDisapproval);
        float propertyBaseValue2 = this.departmentOfTheInterior.Cities[0].GetPropertyBaseValue(SimulationProperties.CityApproval);
        int   num5 = Mathf.RoundToInt(this.acceptedNumberOfUnPacifiedRegion);

        while (num4 >= num3 && num2 + num <= num5)
        {
            num++;
            float num6 = 0f;
            float num7 = 0f;
            for (int j = 0; j < this.departmentOfTheInterior.Cities.Count; j++)
            {
                float num8          = this.departmentOfTheInterior.Cities[j].GetPropertyValue(SimulationProperties.NetCityApproval) - (float)num * propertyBaseValue;
                float propertyValue = this.departmentOfTheInterior.Cities[j].GetPropertyValue(SimulationProperties.Population);
                num7 += num8 * propertyValue;
                num6 += propertyValue;
            }
            for (int k = 0; k < num; k++)
            {
                float num9  = propertyBaseValue2 - (float)(this.departmentOfTheInterior.Cities.Count - 1 + num) * propertyBaseValue;
                float num10 = 1f;
                num7 += num9 * num10;
                num6 += num10;
            }
            num4 = num7 / num6;
        }
        return(Mathf.Max(0, num - 1));
    }
    private void ComputeWantedMilitaryUnitCount()
    {
        float propertyValue = base.AIEntity.Empire.GetPropertyValue(SimulationProperties.ArmyUnitSlot);

        this.LandRecruiter.WantedUnitCount.Reset();
        this.NavalRecruiter.WantedUnitCount.Reset();
        DepartmentOfTheInterior agency = base.AIEntity.Empire.GetAgency <DepartmentOfTheInterior>();

        if (agency != null)
        {
            HeuristicValue heuristicValue = new HeuristicValue(0f);
            heuristicValue.Add((float)agency.Cities.Count, "Number of city", new object[0]);
            heuristicValue.Multiply(1.2f, "constant", new object[0]);
            this.LandRecruiter.WantedUnitCount.Add(heuristicValue, "1.2f per owned land region", new object[0]);
            HeuristicValue heuristicValue2 = new HeuristicValue(0f);
            heuristicValue2.Add((float)agency.OccupiedFortresses.Count, "Number of fortress", new object[0]);
            heuristicValue2.Multiply(0.5f, "constant", new object[0]);
            this.NavalRecruiter.WantedUnitCount.Add(heuristicValue2, "Half per owned fortresses", new object[0]);
        }
        MajorEmpire majorEmpire = base.AIEntity.Empire as MajorEmpire;

        if (majorEmpire != null)
        {
            HeuristicValue heuristicValue3 = new HeuristicValue(0f);
            heuristicValue3.Add((float)majorEmpire.ConvertedVillages.Count, "Number of village", new object[0]);
            heuristicValue3.Multiply(0.5f, "constant", new object[0]);
            this.LandRecruiter.WantedUnitCount.Add(heuristicValue3, "Half per converted village", new object[0]);
        }
        DepartmentOfForeignAffairs agency2 = base.AIEntity.Empire.GetAgency <DepartmentOfForeignAffairs>();

        if (agency2 != null)
        {
            HeuristicValue heuristicValue4 = new HeuristicValue(0f);
            heuristicValue4.Add((float)agency.Cities.Count, "Number of city", new object[0]);
            heuristicValue4.Multiply((float)agency2.CountNumberOfWar(), "Number of war", new object[0]);
            heuristicValue4.Multiply(0.5f, "constant", new object[0]);
            this.LandRecruiter.WantedUnitCount.Add(heuristicValue4, "Half per city per war.", new object[0]);
        }
        AILayer_Navy layer = base.AIEntity.GetLayer <AILayer_Navy>();

        if (layer != null)
        {
            this.NavalRecruiter.WantedUnitCount.Add(layer.WantedArmies(), "Navy wanted army count", new object[0]);
        }
        AILayer_Colonization layer2 = base.AIEntity.GetLayer <AILayer_Colonization>();

        if (layer2 != null)
        {
            this.LandRecruiter.WantedUnitCount.Add((float)(layer2.WantedNewCity / 2), "Half per wanted region", new object[0]);
        }
        if (this.LandRecruiter.WantedUnitCount == 0f)
        {
            this.LandRecruiter.WantedUnitCount.Add(1f, "avoid 0", new object[0]);
        }
        if (this.NavalRecruiter.WantedUnitCount == 0f)
        {
            this.NavalRecruiter.WantedUnitCount.Add(1f, "avoid 0", new object[0]);
        }
        this.LandRecruiter.WantedUnitCount.Multiply(propertyValue, "Army size", new object[0]);
        this.NavalRecruiter.WantedUnitCount.Multiply(propertyValue, "Army size", new object[0]);
        float propertyValue2 = base.AIEntity.Empire.GetPropertyValue(SimulationProperties.GameSpeedMultiplier);

        if ((float)this.endTurnService.Turn < 30f * propertyValue2)
        {
            this.LandRecruiter.WantedUnitCount.Multiply(0.3f, "Early game factor", new object[0]);
            this.NavalRecruiter.WantedUnitCount.Multiply(0.3f, "Early game factor", new object[0]);
        }
    }
Example #4
0
    private float GenerateMessageScoreForIndustry()
    {
        float result = 0f;

        if (!AILayer_Colonization.IsAbleToColonize(base.AIEntity.Empire))
        {
            result = 1f;
        }
        else if (this.aiEntityCity.City.BesiegingEmpire == null && this.constructionQueue.PendingConstructions.Count > 0)
        {
            ConstructibleElement constructibleElement = this.constructionQueue.Peek().ConstructibleElement;
            if (constructibleElement != null && (constructibleElement.SubCategory == "SubCategoryWonder" || constructibleElement.SubCategory == "SubCategoryVictory"))
            {
                return(1f);
            }
        }
        else
        {
            float num = 0f;
            float num2;
            for (int i = 0; i < this.departmentOfTheInterior.Cities.Count; i++)
            {
                num2 = (float)this.departmentOfTheInterior.Cities[i].CityImprovements.Count;
                if (num2 > num)
                {
                    num = num2;
                }
            }
            num2 = (float)this.aiEntityCity.City.CityImprovements.Count;
            float num3 = 1f - num2 / num;
            float num4 = 0f;
            if (!this.departmentOfTheTreasury.TryGetNetResourceValue(this.aiEntityCity.City, "Production", out num4, false))
            {
                num4 = 0f;
            }
            if (num4 == 0f)
            {
                num4 = 1f;
            }
            bool  flag  = false;
            bool  flag2 = false;
            float num5  = 0f;
            if (!this.departmentOfTheTreasury.TryGetResourceStockValue(this.aiEntityCity.City, DepartmentOfTheTreasury.Resources.Production, out num5, false))
            {
                num5 = 0f;
            }
            num5 += this.aiEntityCity.City.GetPropertyValue(SimulationProperties.NetCityProduction);
            num5  = Math.Max(1f, num5);
            for (int j = 0; j < this.constructionQueue.Length; j++)
            {
                Construction construction = this.constructionQueue.PeekAt(j);
                if (DepartmentOfTheTreasury.CheckConstructiblePrerequisites(this.aiEntityCity.City, construction.ConstructibleElement, new string[]
                {
                    ConstructionFlags.Prerequisite
                }))
                {
                    if (!flag2)
                    {
                        float num6 = 0f;
                        for (int k = 0; k < construction.CurrentConstructionStock.Length; k++)
                        {
                            if (construction.CurrentConstructionStock[k].PropertyName == "Production")
                            {
                                num6 += construction.CurrentConstructionStock[k].Stock;
                                if (construction.IsBuyout)
                                {
                                    num6 = DepartmentOfTheTreasury.GetProductionCostWithBonus(this.aiEntityCity.City, construction.ConstructibleElement, "Production");
                                }
                            }
                        }
                        float num7 = DepartmentOfTheTreasury.GetProductionCostWithBonus(this.aiEntityCity.City, construction.ConstructibleElement, "Production") - num6;
                        num5 -= num7;
                        if (num5 < 0f && !construction.ConstructibleElementName.ToString().Contains("BoosterGenerator"))
                        {
                            flag  = true;
                            flag2 = true;
                        }
                        if (construction.ConstructibleElementName.ToString().Contains("BoosterGenerator"))
                        {
                            flag2 = true;
                        }
                    }
                    float num8 = 0f;
                    for (int l = 0; l < construction.CurrentConstructionStock.Length; l++)
                    {
                        if (construction.CurrentConstructionStock[l].PropertyName == "Production")
                        {
                            num8 += construction.CurrentConstructionStock[l].Stock;
                        }
                    }
                    float num9 = DepartmentOfTheTreasury.GetProductionCostWithBonus(this.aiEntityCity.City, construction.ConstructibleElement, "Production") - num8;
                    num3 = AILayer.Boost(num3, this.ComputeCostBoost(num9 / num4));
                }
            }
            if (this.aiEntityCity.City.BesiegingEmpire != null)
            {
                num3 = AILayer.Boost(num3, 0.5f);
            }
            if (!flag && !flag2)
            {
                flag = true;
            }
            if (!flag)
            {
                num3 = 0f;
            }
            result = num3;
        }
        return(result);
    }