コード例 #1
0
    public static float GetCampDefenseLocalPriority(Camp camp, float unitRatioBoost, int simulatedUnitsCount = -1)
    {
        if (camp == null)
        {
            return(0f);
        }
        DepartmentOfForeignAffairs agency = camp.Empire.GetAgency <DepartmentOfForeignAffairs>();

        if (agency.IsInWarWithSomeone() && AILayer_Military.AreaIsSave(camp.WorldPosition, 12, agency, false))
        {
            return(0f);
        }
        if (camp.City.BesiegingEmpire != null)
        {
            return(0f);
        }
        float normalizedScore = 0f;
        float num;

        if (simulatedUnitsCount >= 0)
        {
            num = (float)simulatedUnitsCount / (float)camp.MaximumUnitSlot;
        }
        else
        {
            num = (float)camp.StandardUnits.Count / (float)camp.MaximumUnitSlot;
        }
        float normalizedScore2       = AILayer.Boost(normalizedScore, (1f - num) * unitRatioBoost);
        float developmentRatioOfCamp = AIScheduler.Services.GetService <IEntityInfoAIHelper>().GetDevelopmentRatioOfCamp(camp);

        return(AILayer.Boost(normalizedScore2, (1f - developmentRatioOfCamp) * AILayer_Military.cityDevRatioBoost));
    }
コード例 #2
0
ファイル: NavyFortress.cs プロジェクト: LeaderEnemyBoss/ELCP
    public override void UpdateRole()
    {
        base.Role = BaseNavyArmy.ArmyRole.Forteress;
        this.WantToKeepArmyFitness.Reset();
        NavyRegionData navyRegionData = base.Commander.RegionData as NavyRegionData;

        this.WantToKeepArmyFitness.Add(0.3f, "constant", new object[0]);
        if (navyRegionData.NumberOfWaterEnemy > 0)
        {
            HeuristicValue heuristicValue = new HeuristicValue(0f);
            heuristicValue.Add((float)navyRegionData.NumberOfWaterEnemy, "Number of enemy water region around.", new object[0]);
            heuristicValue.Multiply(0.1f, "boost constant", new object[0]);
            heuristicValue.Min(0.5f, "Avoid too big factor!", new object[0]);
            this.WantToKeepArmyFitness.Boost(heuristicValue, "Water region owned by enemy around.", new object[0]);
        }
        if (navyRegionData.NumberOfEnemyCityOnTheBorder > 0)
        {
            this.WantToKeepArmyFitness.Boost(0.2f, "Enemy city in the region.", new object[0]);
        }
        if (navyRegionData.EnemyNavalPower > 0f)
        {
            this.WantToKeepArmyFitness.Boost(0.9f, "Enemy roaming in the region.", new object[0]);
        }
        MajorEmpire occupant = this.Fortress.Occupant;

        if (occupant != null && !AILayer_Military.AreaIsSave(this.Fortress.WorldPosition, 10, occupant.GetAgency <DepartmentOfForeignAffairs>(), true))
        {
            this.WantToKeepArmyFitness.Boost(0.9f, "Enemy roaming in the region.", new object[0]);
        }
    }
コード例 #3
0
    public static float GetCityDefenseLocalPriority(City city, float unitRatioBoost, int simulatedUnitsCount = -1)
    {
        if (city == null)
        {
            return(0f);
        }
        bool flag = false;
        DepartmentOfForeignAffairs agency = city.Empire.GetAgency <DepartmentOfForeignAffairs>();

        if (!agency.IsInWarWithSomeone() && !AIScheduler.Services.GetService <IWorldAtlasAIHelper>().IsRegionPacified(city.Empire, city.Region))
        {
            return(0f);
        }
        if (agency.IsInWarWithSomeone() && city.BesiegingEmpire == null)
        {
            flag = !AILayer_Military.AreaIsSave(city.WorldPosition, 10, agency, false);
        }
        float num = 0f;
        float num2;

        if (simulatedUnitsCount >= 0)
        {
            num2 = (float)simulatedUnitsCount / (float)city.MaximumUnitSlot;
        }
        else
        {
            num2 = (float)city.StandardUnits.Count / (float)city.MaximumUnitSlot;
        }
        num = AILayer.Boost(num, (1f - num2) * unitRatioBoost);
        if (city.BesiegingEmpire != null)
        {
            float propertyValue = city.GetPropertyValue(SimulationProperties.MaximumCityDefensePoint);
            float num3          = city.GetPropertyValue(SimulationProperties.CityDefensePoint) / propertyValue;
            num3 = 1f - num3;
            num  = AILayer.Boost(num, num3 * AILayer_Military.cityDefenseUnderSiegeBoost);
        }
        else
        {
            float developmentRatioOfCity = AIScheduler.Services.GetService <IEntityInfoAIHelper>().GetDevelopmentRatioOfCity(city);
            num = AILayer.Boost(num, (1f - developmentRatioOfCity) * AILayer_Military.cityDevRatioBoost);
            if (flag)
            {
                num = AILayer.Boost(num, 0.5f);
            }
        }
        return(num);
    }
コード例 #4
0
    protected override void RefreshObjectives(StaticString context, StaticString pass)
    {
        base.RefreshObjectives(context, pass);
        base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.Defense.ToString(), ref this.globalObjectiveMessages);
        base.ValidateMessages(ref this.globalObjectiveMessages);
        AILayer_War layer = base.AIEntity.GetLayer <AILayer_War>();

        base.GlobalPriority.Reset();
        AILayer_Strategy layer2 = base.AIEntity.GetLayer <AILayer_Strategy>();

        base.GlobalPriority.Add(layer2.StrategicNetwork.GetAgentValue("InternalMilitary"), "Strategic Network 'InternalMilitary'", new object[0]);
        AILayer_ArmyManagement layer3 = base.AIEntity.GetLayer <AILayer_ArmyManagement>();
        float worldColonizationRatio  = this.worldAtlasHelper.GetWorldColonizationRatio(base.AIEntity.Empire);
        bool  flag     = layer.WantWarWithSomoeone() || layer.NumberOfWar > 0;
        City  mainCity = this.departmentOfTheInterior.MainCity;
        bool  flag2    = false;

        if (this.departmentOfTheInterior.NonInfectedCities.Count < 4)
        {
            List <IGarrison> list = new List <IGarrison>();
            list.AddRange(this.departmentOfDefense.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler && match.UnitsCount > 3).Cast <IGarrison>());
            if (list.Count > 1)
            {
                flag2 = true;
            }
        }
        for (int i = 0; i < this.departmentOfTheInterior.Cities.Count; i++)
        {
            City city = this.departmentOfTheInterior.Cities[i];
            if (this.IsObjectiveValid(AICommanderMissionDefinition.AICommanderCategory.Defense.ToString(), city.Region.Index, true))
            {
                GlobalObjectiveMessage globalObjectiveMessage = this.globalObjectiveMessages.Find((GlobalObjectiveMessage match) => match.RegionIndex == city.Region.Index);
                if (globalObjectiveMessage == null)
                {
                    globalObjectiveMessage = base.GenerateObjective(city.Region.Index);
                    globalObjectiveMessage.LocalPriority = new HeuristicValue(0f);
                    this.globalObjectiveMessages.Add(globalObjectiveMessage);
                }
                globalObjectiveMessage.TimeOut = 1;
                globalObjectiveMessage.LocalPriority.Reset();
                if (flag2 && city == mainCity)
                {
                    bool flag3 = !AILayer_Military.AreaIsSave(city.WorldPosition, 15, this.departmentOfForeignAffairs, false, false);
                    if (!flag3)
                    {
                        foreach (Region region in this.worldPositionningService.GetNeighbourRegions(city.Region, false, false))
                        {
                            if (region.IsLand && region.Owner is MajorEmpire)
                            {
                                DiplomaticRelation diplomaticRelation = this.departmentOfForeignAffairs.GetDiplomaticRelation(region.Owner);
                                if (diplomaticRelation.State.Name == DiplomaticRelationState.Names.War || diplomaticRelation.State.Name == DiplomaticRelationState.Names.ColdWar || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Truce)
                                {
                                    flag3 = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (flag3)
                    {
                        globalObjectiveMessage.LocalPriority  = new HeuristicValue(1f);
                        globalObjectiveMessage.GlobalPriority = new HeuristicValue(1f);
                    }
                }
                else
                {
                    globalObjectiveMessage.GlobalPriority = base.GlobalPriority;
                    AICommanderWithObjective aicommanderWithObjective = layer3.FindCommander(globalObjectiveMessage);
                    if (aicommanderWithObjective != null && aicommanderWithObjective is AICommander_Defense)
                    {
                        AICommander_Defense aicommander_Defense = aicommanderWithObjective as AICommander_Defense;
                        globalObjectiveMessage.LocalPriority.Add(AILayer_Military.GetCityDefenseLocalPriority(city, this.unitRatioBoost, aicommander_Defense.ComputeCurrentUnitInDefense()), "CityDefenseLocalPriority", new object[0]);
                    }
                    else
                    {
                        globalObjectiveMessage.LocalPriority.Add(AILayer_Military.GetCityDefenseLocalPriority(city, this.unitRatioBoost, -1), "CityDefenseLocalPriority", new object[0]);
                    }
                    HeuristicValue heuristicValue = new HeuristicValue(0f);
                    heuristicValue.Add(worldColonizationRatio, "colonization ratio", new object[0]);
                    heuristicValue.Multiply(0.2f, "(constant)", new object[0]);
                    globalObjectiveMessage.LocalPriority.Boost(heuristicValue, "Colonization boost", new object[0]);
                    if (flag)
                    {
                        globalObjectiveMessage.LocalPriority.Boost(0.3f, "Want war", new object[0]);
                    }
                    AIData_City aidata_City;
                    if (this.aiDataRepositoryAIHelper.TryGetAIData <AIData_City>(city.GUID, out aidata_City) && aidata_City.IsAtWarBorder)
                    {
                        globalObjectiveMessage.LocalPriority.Boost(0.3f, "War border", new object[0]);
                    }
                    if ((float)this.endTurnService.Turn < this.unitInGarrisonTurnLimit)
                    {
                        globalObjectiveMessage.LocalPriority.Boost(-0.3f, "turn under 'unitInGarrisonTurnLimit' ({0})", new object[]
                        {
                            this.unitInGarrisonTurnLimit
                        });
                    }
                }
            }
        }
        MajorEmpire majorEmpire = base.AIEntity.Empire as MajorEmpire;

        if (majorEmpire == null || majorEmpire.ConvertedVillages.Count == 0)
        {
            return;
        }
        if (mainCity == null)
        {
            return;
        }
        float num = AILayer_Military.GetCityDefenseLocalPriority(mainCity, this.unitRatioBoost, AICommanderMission_Garrison.SimulatedUnitsCount);

        num *= this.villageDefenseRatioDeboost;
        num *= base.GlobalPriority;
        for (int k = 0; k < this.VillageDOFPriority.Count; k++)
        {
            this.VillageDOFPriority[k].Reset();
        }
        float num2 = 0f;

        for (int l = 0; l < majorEmpire.ConvertedVillages.Count; l++)
        {
            Village village = majorEmpire.ConvertedVillages[l];
            AILayer_Military.VillageDefensePriority villageDefensePriority = this.VillageDOFPriority.Find((AILayer_Military.VillageDefensePriority match) => match.Village.GUID == village.GUID);
            if (villageDefensePriority == null)
            {
                villageDefensePriority = new AILayer_Military.VillageDefensePriority();
                villageDefensePriority.Reset();
                villageDefensePriority.Village = village;
                this.VillageDOFPriority.Add(villageDefensePriority);
            }
            villageDefensePriority.ToDelete          = false;
            villageDefensePriority.FirstUnitPriority = num;
            float num3 = (float)this.worldPositionningService.GetDistance(village.WorldPosition, mainCity.WorldPosition);
            villageDefensePriority.DistanceToMainCity = num3;
            if (num3 > num2)
            {
                num2 = num3;
            }
        }
        for (int m = this.VillageDOFPriority.Count - 1; m >= 0; m--)
        {
            AILayer_Military.VillageDefensePriority villageDefensePriority2 = this.VillageDOFPriority[m];
            if (villageDefensePriority2.ToDelete)
            {
                this.VillageDOFPriority.Remove(villageDefensePriority2);
            }
            else
            {
                float num4 = villageDefensePriority2.DistanceToMainCity / num2;
                if (majorEmpire.ConvertedVillages.Count > 1)
                {
                    villageDefensePriority2.FirstUnitPriority = AILayer.Boost(villageDefensePriority2.FirstUnitPriority, num4 * -0.1f);
                }
            }
        }
    }