예제 #1
0
    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]);
        }
    }
예제 #2
0
    private void ComputeObjectivePriority()
    {
        base.GlobalPriority.Reset();
        AILayer_Strategy layer = base.AIEntity.GetLayer <AILayer_Strategy>();

        base.GlobalPriority.Add(layer.StrategicNetwork.GetAgentValue("Pacification"), "Startegic network 'Pacification'", new object[0]);
        for (int i = 0; i < this.globalObjectiveMessages.Count; i++)
        {
            GlobalObjectiveMessage globalObjectiveMessage = this.globalObjectiveMessages[i];
            HeuristicValue         heuristicValue         = new HeuristicValue(0f);
            heuristicValue.Add(0.5f, "(constant)", new object[0]);
            Region region = this.worldPositionningService.GetRegion(globalObjectiveMessage.RegionIndex);
            if (region.City != null && region.City.Empire == base.AIEntity.Empire)
            {
                if (base.AIEntity.Empire.GetAgency <DepartmentOfForeignAffairs>().IsInWarWithSomeone())
                {
                    heuristicValue.Boost(0.5f, "At war", new object[0]);
                }
                if ((float)region.City.UnitsCount < (float)region.City.MaximumUnitSlot * 0.5f)
                {
                    heuristicValue.Boost(0.2f, "City defense low", new object[0]);
                }
            }
            globalObjectiveMessage.LocalPriority  = heuristicValue;
            globalObjectiveMessage.GlobalPriority = base.GlobalPriority;
            globalObjectiveMessage.TimeOut        = 1;
        }
    }
예제 #3
0
    private void DoProduce()
    {
        this.ComputeMilitaryBodyRatio();
        List <EvaluableMessage_UnitProduction> list = new List <EvaluableMessage_UnitProduction>();

        this.FillUnitProduction(ref list);
        HeuristicValue globalMotivation = new HeuristicValue(0.9f);

        for (int i = 0; i < list.Count; i++)
        {
            if (!this.CheckUnitProduction(list[i]))
            {
                list[i].Cancel();
            }
            else
            {
                HeuristicValue unitPriority = this.GetUnitPriority(list[i].UnitDesign);
                list[i].Refresh(globalMotivation, unitPriority);
                this.ProcessUnitProduction(list[i].UnitDesign);
            }
        }
        while (this.needMilitaryPower > 0f)
        {
            UnitDesign unitDesign = this.ChooseMilitaryUnitToBuild();
            if (unitDesign == null)
            {
                break;
            }
            HeuristicValue unitPriority2            = this.GetUnitPriority(unitDesign);
            EvaluableMessage_UnitProduction message = new EvaluableMessage_UnitProduction(globalMotivation, unitPriority2, unitDesign, -1, 1, AILayer_AccountManager.MilitaryAccountName);
            this.AIEntity.AIPlayer.Blackboard.AddMessage(message);
            this.ProcessUnitProduction(unitDesign);
        }
    }
예제 #4
0
    protected HeuristicValue ComputePowerFitness(float enemyPower, float myPower)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        enemyPower += 1f;
        myPower    += 1f;
        if (enemyPower > myPower)
        {
            float num = myPower / enemyPower;
            if (num < 0.8f)
            {
                heuristicValue.Value = -1f;
                heuristicValue.Log("Enemy really too strong. Ratio My/enemyPower = {0}", new object[]
                {
                    num
                });
                return(heuristicValue);
            }
            heuristicValue.Add(0.8f, "Max ratio as we are under the enemy power.", new object[0]);
            heuristicValue.Boost(-1f + num, "inverted negative ratio", new object[0]);
        }
        else
        {
            heuristicValue.Add(0.8f, "Max ratio as we are over the enemy power.", new object[0]);
            HeuristicValue heuristicValue2 = new HeuristicValue(0f);
            heuristicValue2.Add(enemyPower, "Enemy power", new object[0]);
            heuristicValue2.Divide(myPower, "My power", new object[0]);
            HeuristicValue heuristicValue3 = new HeuristicValue(0f);
            heuristicValue3.Add(1f, "constant", new object[0]);
            heuristicValue3.Subtract(heuristicValue2, "Enemy/my power ratio", new object[0]);
            heuristicValue3.Clamp(-1f, 1f);
            heuristicValue.Boost(heuristicValue3, "Boost based on power", new object[0]);
        }
        return(heuristicValue);
    }
예제 #5
0
 public virtual void Assign(ArmyTask task, HeuristicValue fitness)
 {
     if (this.CurrentMainTask == task)
     {
         return;
     }
     if (this.CurrentMainTask != null)
     {
         this.Unassign();
     }
     if (task != null)
     {
         if (task.AssignedArmy != null)
         {
             task.AssignedArmy.Unassign();
         }
         this.CurrentMainTask = task;
         this.CurrentMainTask.AssignedArmy = this;
         this.CurrentMainTask.CurrentAssignationFitness = fitness;
         IGameService service = Services.GetService <IGameService>();
         this.CurrentMainTask.EstimatedTurnEnd = new HeuristicValue(0f);
         this.CurrentMainTask.EstimatedTurnEnd.Add((float)(service.Game as global::Game).Turn, "current turn", new object[0]);
         this.CurrentMainTask.EstimatedTurnEnd.Add(5f, "estimated time to complete (constant)", new object[0]);
         this.CurrentMainTask.Behavior.Reset();
         this.State = TickableState.NeedTick;
     }
 }
예제 #6
0
    public override void NewTurn(AILayer_Dissent dissentLayer)
    {
        this.ComputeVillageScoring();
        if (this.villagePOI.Count == 0)
        {
            base.State = TickableState.NoTick;
            return;
        }
        if (base.AssociateRequest != null && !base.AssociateRequest.IsValidForNewTurn())
        {
            base.AssociateRequest.Cancel();
            base.AssociateRequest = null;
        }
        if (base.AssociateRequest == null)
        {
            base.AssociateRequest = new DissentRequest();
            dissentLayer.AIEntity.AIPlayer.Blackboard.AddMessage(base.AssociateRequest);
        }
        HeuristicValue localOpportunity = new HeuristicValue(0f);

        base.AssociateRequest.SetInterest(dissentLayer.GlobalPriority, localOpportunity);
        base.AssociateRequest.TimeOut = 1;
        float villageCost = this.GetVillageCost();

        base.AssociateRequest.UpdateBuyEvaluation("DissentVillage", 0UL, villageCost, (int)BuyEvaluation.MaxTurnGain, 0f, 0UL);
    }
예제 #7
0
    private void ComputeCostalBoost()
    {
        DepartmentOfTheInterior agency = base.Empire.GetAgency <DepartmentOfTheInterior>();

        this.costalCityCount = 0;
        for (int i = 0; i < agency.Cities.Count; i++)
        {
            if (agency.Cities[i].Districts.Any((District match) => this.worldPositionningService.IsWaterTile(match.WorldPosition)))
            {
                this.costalCityCount++;
            }
        }
        this.costalColonizationBoost.Reset();
        if (this.costalCityCount < 3)
        {
            int            num            = 3;
            HeuristicValue heuristicValue = new HeuristicValue(0f);
            heuristicValue.Add((float)agency.Cities.Count, "City count", new object[0]);
            heuristicValue.Subtract((float)(this.costalCityCount * num), "Costal city * {0}", new object[]
            {
                num
            });
            heuristicValue.Divide((float)num, "Costal gap", new object[0]);
            heuristicValue.Clamp(0.1f, 1f);
            heuristicValue.Multiply(this.costalCityRatioMaxBoost, "Factor from xml", new object[0]);
            this.costalColonizationBoost.Boost(heuristicValue, "Costal city ratio boost", new object[0]);
        }
        if (base.Empire.SimulationObject.Tags.Contains(DownloadableContent16.AffinitySeaDemons))
        {
            this.costalColonizationBoost.Boost(0.1f, "Sea demons", new object[0]);
        }
    }
    private void GenerateRequestUnitMessages()
    {
        if (this.countByUnitModel.Count == 0)
        {
            return;
        }
        List <EvaluableMessage_UnitRequest> list = new List <EvaluableMessage_UnitRequest>(base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage_UnitRequest>(BlackboardLayerID.Empire, (EvaluableMessage_UnitRequest match) => match.EvaluationState != EvaluableMessage.EvaluableMessageState.Cancel && match.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtained));
        HeuristicValue globalMotivation          = new HeuristicValue(1f);
        int            index;

        Predicate <EvaluableMessage_UnitRequest> < > 9__1;
        int index2;

        for (index = 0; index < this.countByUnitModel.Count; index = index2 + 1)
        {
            for (int i = 0; i < this.countByUnitModel[index].Count; i++)
            {
                if (this.countByUnitModel[index].RequestArmy != null)
                {
                    List <EvaluableMessage_UnitRequest>      list2 = list;
                    Predicate <EvaluableMessage_UnitRequest> match2;
                    if ((match2 = < > 9__1) == null)
                    {
                        match2 = (< > 9__1 = delegate(EvaluableMessage_UnitRequest match)
                        {
                            if (this.countByUnitModel[index].UnitDesign != null)
                            {
                                return(match.UnitDesign != null && match.UnitDesign.Model == this.countByUnitModel[index].UnitDesign.Model && match.RequestUnitListMessageID == this.countByUnitModel[index].RequestArmy.ID);
                            }
                            return(match.UnitDesign == null && match.RequestUnitListMessageID == this.countByUnitModel[index].RequestArmy.ID);
                        });
                    }
                    int num = list2.FindIndex(match2);
                    if (num < 0)
                    {
                        HeuristicValue heuristicValue = new HeuristicValue(0f);
                        heuristicValue.Add(this.countByUnitModel[index].RequestArmy.Priority, "Army request '{0}' priority", new object[]
                        {
                            this.countByUnitModel[index].RequestArmy.ID
                        });
                        EvaluableMessage_UnitRequest message = new EvaluableMessage_UnitRequest(globalMotivation, heuristicValue, this.countByUnitModel[index].UnitDesign, this.countByUnitModel[index].WantedUnitPatternCategory, this.countByUnitModel[index].RequestArmy.ID, -1, 1, AILayer_AccountManager.MilitaryAccountName);
                        base.AIEntity.AIPlayer.Blackboard.AddMessage(message);
                    }
                    else
                    {
                        list[num].Refresh(1f, this.countByUnitModel[index].RequestArmy.Priority);
                        list.RemoveAt(num);
                    }
                }
            }
            index2 = index;
        }
        for (int j = 0; j < list.Count; j++)
        {
            list[j].Cancel();
        }
    }
예제 #9
0
    private HeuristicValue GetUnitPriority(UnitDesign unitDesign)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        heuristicValue.Add(this.currentProductionPriority, "Current unit priority", new object[0]);
        HeuristicValue heuristicValue2 = new HeuristicValue(0f);
        int            num             = this.availableMilitaryBody.IndexOf(unitDesign.UnitBodyDefinition.Name);

        if (num >= 0)
        {
            float num2 = this.bodyCount[num] / this.overralUnitCount;
            float num3 = this.wantedBodyRatio[num];
            if (num2 > num3)
            {
                heuristicValue2.Log("Too much of this body already", new object[0]);
                heuristicValue2.Add(num2, "Current ratio", new object[0]);
                heuristicValue2.Divide(num3, "Wanted ratio", new object[0]);
                heuristicValue2.Clamp(0f, 2f);
                heuristicValue2.Multiply(-1f, "invert", new object[0]);
            }
            else
            {
                heuristicValue2.Log("Not enough of this body for now.", new object[0]);
                heuristicValue2.Add(num3, "Wanted ratio", new object[0]);
                heuristicValue2.Divide(num2, "Current ratio", new object[0]);
                heuristicValue2.Clamp(0f, 2f);
            }
        }
        heuristicValue2.Multiply(0.05f, "constant", new object[0]);
        heuristicValue.Boost(heuristicValue2, "Body ratio boost", new object[0]);
        DepartmentOfTheInterior agency = this.AIEntity.Empire.GetAgency <DepartmentOfTheInterior>();

        if (unitDesign.Name.ToString().Contains("Preacher") && this.VillageLayer.ConversionArmiesCount > 0 && (this.VictoryLayer == null || this.VictoryLayer.CurrentVictoryDesign != AILayer_Victory.VictoryDesign.Preacher))
        {
            heuristicValue.Boost(-0.4f, "Bad Unit Malus", new object[0]);
        }
        else if (unitDesign.Name.ToString().Contains("EyelessOnesCaecator"))
        {
            heuristicValue.Boost(-0.3f, "Bad Unit Malus", new object[0]);
        }
        else if (unitDesign.Name.ToString().Contains("CeratanDrider"))
        {
            heuristicValue.Boost(-0.15f, "Bad Unit Malus", new object[0]);
        }
        if (unitDesign.Name.ToString().Contains("Mastermind") && agency.AssimilatedFactions.Count > 0)
        {
            foreach (Faction faction in agency.AssimilatedFactions)
            {
                if (faction.Name != "Ceratan" && faction.Name != "EyelessOnes")
                {
                    heuristicValue.Boost(-0.2f, "Bad Unit Malus", new object[0]);
                    break;
                }
            }
        }
        return(heuristicValue);
    }
예제 #10
0
    public override NavyTaskEvaluation ComputeFitness(BaseNavyArmy navyGarrison)
    {
        HeuristicValue taskFitness = this.GetTaskFitness(navyGarrison);

        return(new NavyTaskEvaluation
        {
            Fitness = taskFitness,
            Task = this
        });
    }
예제 #11
0
    private HeuristicValue GetTaskFitness(BaseNavyArmy navyGarrison)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        base.Owner.GetAgency <DepartmentOfForeignAffairs>();
        if (navyGarrison.Garrison.GUID == base.TargetGuid)
        {
            heuristicValue.Value = -1f;
            heuristicValue.Log("Cannot reinforce itself.", new object[0]);
        }
        else if (navyGarrison.Role == BaseNavyArmy.ArmyRole.Land || navyGarrison.Role == BaseNavyArmy.ArmyRole.Forteress || navyGarrison.Role == BaseNavyArmy.ArmyRole.Convoi)
        {
            heuristicValue.Value = -1f;
            heuristicValue.Log("Role is not valid for the task. Role={0}.", new object[]
            {
                navyGarrison.Role.ToString()
            });
        }
        else if (navyGarrison.Garrison.StandardUnits.Count == 0)
        {
            heuristicValue.Value = -1f;
            heuristicValue.Log("Army is empty, cannot be used as reinforcement.", new object[0]);
        }
        else
        {
            heuristicValue.Add(this.NavyFortress.WantToKeepArmyFitness, "Fortress army need", new object[0]);
            if (navyGarrison.Role == BaseNavyArmy.ArmyRole.TaskForce)
            {
                heuristicValue.Boost(-0.1f, "constant avoid reinforce while task force.", new object[0]);
                float          num             = (float)navyGarrison.Garrison.CurrentUnitSlot;
                float          operand         = Math.Abs((float)this.ReinforcementSlots - num);
                HeuristicValue heuristicValue2 = new HeuristicValue(0f);
                heuristicValue2.Add(operand, "ABS(TaskSlotNeeded - armySize)", new object[0]);
                heuristicValue2.Divide(num, "Army size", new object[0]);
                heuristicValue.Subtract(heuristicValue2, "Size ratio", new object[0]);
            }
            if (heuristicValue.Value > 0f)
            {
                if (this.NavyFortress.ArmySize < BaseNavyArmy.ArmyState.Medium)
                {
                    heuristicValue.Boost(0.2f, "(constant)Under medium", new object[0]);
                }
                else if (this.NavyFortress.ArmySize < BaseNavyArmy.ArmyState.High)
                {
                    heuristicValue.Boost(0.1f, "(constant)Under high", new object[0]);
                }
                float numberOfTurnToReach = (float)this.worldPositionService.GetDistance(navyGarrison.Garrison.WorldPosition, this.NavyFortress.Garrison.WorldPosition) / navyGarrison.GetMaximumMovement();
                heuristicValue.Multiply(base.ComputeDistanceFitness(numberOfTurnToReach, navyGarrison.Role), "Distance", new object[0]);
            }
        }
        return(heuristicValue);
    }
예제 #12
0
    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;
        }
    }
예제 #13
0
    public override NavyTaskEvaluation ComputeFitness(BaseNavyArmy navyGarrison)
    {
        NavyTaskEvaluation navyTaskEvaluation = new NavyTaskEvaluation();

        navyTaskEvaluation.Fitness = new HeuristicValue(0f);
        navyTaskEvaluation.Task    = this;
        if (base.ForbiddenGUIDs.Contains(navyGarrison.Garrison.GUID))
        {
            return(navyTaskEvaluation);
        }
        if (navyGarrison.Role == BaseNavyArmy.ArmyRole.Land || navyGarrison.Role == BaseNavyArmy.ArmyRole.Convoi)
        {
            navyTaskEvaluation.Fitness.Value = -1f;
            navyTaskEvaluation.Fitness.Log("Role is not valid for the task. Role={0}.", new object[]
            {
                navyGarrison.Role.ToString()
            });
        }
        else
        {
            float enemyPower    = this.GetEnemyPower();
            float propertyValue = navyGarrison.Garrison.GetPropertyValue(SimulationProperties.MilitaryPower);
            navyTaskEvaluation.Fitness.Add(base.ComputePowerFitness(enemyPower, propertyValue), "MilitaryPower", new object[0]);
            if (navyTaskEvaluation.Fitness > 0f)
            {
                WorldPosition  targetPosition = this.GetTargetPosition();
                float          num            = (float)this.worldPositionService.GetDistance(navyGarrison.Garrison.WorldPosition, targetPosition) / navyGarrison.GetMaximumMovement();
                HeuristicValue operand        = base.ComputeDistanceFitness(num, navyGarrison.Role);
                navyTaskEvaluation.Fitness.Multiply(operand, "Distance", new object[0]);
                if (num <= 1f && propertyValue > enemyPower * 1.2f)
                {
                    navyTaskEvaluation.Fitness.Boost(0.9f, "Distance", new object[0]);
                }
                if (navyGarrison.Role == BaseNavyArmy.ArmyRole.Forteress)
                {
                    navyTaskEvaluation.Fitness.Boost(-0.2f, "Fortress...", new object[0]);
                }
                else if (navyGarrison.Garrison.GetPropertyValue(SimulationProperties.ActionPointsSpent) > 0f)
                {
                    navyTaskEvaluation.Fitness.Boost(-0.2f, "No more action point...", new object[0]);
                }
            }
        }
        if (base.AssignedArmy == navyGarrison)
        {
            navyTaskEvaluation.Fitness.Boost(0.2f, "Already assigned to the task", new object[0]);
        }
        return(navyTaskEvaluation);
    }
예제 #14
0
    private void RefreshMessagePriority(GlobalObjectiveMessage objectiveMessage)
    {
        HeuristicValue heuristicValue  = new HeuristicValue(1f);
        HeuristicValue heuristicValue2 = new HeuristicValue(1f);
        float          value;

        if (this.messagePriorityOverrides.TryGetValue(objectiveMessage.SubObjectifGUID, out value))
        {
            heuristicValue.Value  = value;
            heuristicValue2.Value = 0.7f;
        }
        objectiveMessage.GlobalPriority = heuristicValue2;
        objectiveMessage.LocalPriority  = heuristicValue;
        objectiveMessage.TimeOut        = 1;
    }
    private void SettlerProduction()
    {
        UnitDesign unitDesign = this.FindSettlerDesign();

        if (unitDesign == null)
        {
            return;
        }
        List <EvaluableMessage_SettlerProduction> list = new List <EvaluableMessage_SettlerProduction>();

        base.AIEntity.AIPlayer.Blackboard.FillMessages <EvaluableMessage_SettlerProduction>(BlackboardLayerID.Empire, (EvaluableMessage_SettlerProduction match) => match.EvaluationState != EvaluableMessage.EvaluableMessageState.Cancel && match.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtained, ref list);
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        heuristicValue.Add(1f, "(constant)", new object[0]);
        if (this.ColonizationLayer == null || this.ColonizationLayer.CurrentSettlerCount < 2)
        {
            for (int i = 0; i < this.requestArmyMessages.Count; i++)
            {
                if (this.requestArmyMessages[i].CommanderCategory == AICommanderMissionDefinition.AICommanderCategory.Colonization && this.requestArmyMessages[i].ExecutionState == RequestUnitListMessage.RequestUnitListState.Pending)
                {
                    if (list.Count == 0)
                    {
                        HeuristicValue heuristicValue2 = new HeuristicValue(0f);
                        heuristicValue2.Add(this.requestArmyMessages[i].Priority, "Army request priority", new object[0]);
                        EvaluableMessage_SettlerProduction message = new EvaluableMessage_SettlerProduction(heuristicValue, heuristicValue2, unitDesign, -1, 1, AILayer_AccountManager.MilitaryAccountName);
                        base.AIEntity.AIPlayer.Blackboard.AddMessage(message);
                    }
                    else
                    {
                        list[0].Refresh(1f, this.requestArmyMessages[i].Priority);
                    }
                }
            }
        }
        if (this.VictoryLayer != null && this.VictoryLayer.CurrentVictoryDesign == AILayer_Victory.VictoryDesign.Settler && (this.ColonizationLayer == null || this.ColonizationLayer.CurrentSettlerCount < 10))
        {
            if (list.Count < 1)
            {
                HeuristicValue localOpportunity             = new HeuristicValue(1f);
                EvaluableMessage_SettlerProduction message2 = new EvaluableMessage_SettlerProduction(heuristicValue, localOpportunity, unitDesign, -1, 1, AILayer_AccountManager.MilitaryAccountName);
                base.AIEntity.AIPlayer.Blackboard.AddMessage(message2);
                return;
            }
            list[0].Refresh(1f, 1f);
        }
    }
예제 #16
0
 public HeuristicValue GetColonizationInterest(int regionIndex)
 {
     if (this.globalObjectiveMessages.Exists((GlobalObjectiveMessage match) => match.RegionIndex == regionIndex))
     {
         return(base.GlobalPriority);
     }
     for (int i = 0; i < this.departmentOfTheInterior.Cities.Count; i++)
     {
         if (this.IsNeighbourgTo(this.departmentOfTheInterior.Cities[i].Region, regionIndex))
         {
             HeuristicValue heuristicValue = new HeuristicValue(0f);
             heuristicValue.Add(base.GlobalPriority, "Global priority", new object[0]);
             heuristicValue.Multiply(0.2f, "constant", new object[0]);
             return(heuristicValue);
         }
     }
     return(new HeuristicValue(0f));
 }
예제 #17
0
    private void ComputeOpportunityScore_PointOfInterest(BaseNavyArmy army)
    {
        NavyArmy navyArmy = army as NavyArmy;

        if (navyArmy == null)
        {
            return;
        }
        Army army2 = army.Garrison as Army;

        if (army2 != null && army2.HasCatspaw)
        {
            return;
        }
        for (int i = 0; i < this.worldPositionService.World.Regions.Length; i++)
        {
            if (this.worldPositionService.World.Regions[i].IsOcean)
            {
                for (int j = 0; j < this.worldPositionService.World.Regions[i].PointOfInterests.Length; j++)
                {
                    PointOfInterest pointOfInterest = this.worldPositionService.World.Regions[i].PointOfInterests[j];
                    float           num             = this.ComputeOpportunityTurnOverhead(army, pointOfInterest.WorldPosition);
                    if ((army.CurrentMainTask == null || this.IsDetourWorthChecking(army, num)) && this.CouldSearch(army, pointOfInterest) && this.IsCloseEnoughToOrigin(army, pointOfInterest.WorldPosition, 2f))
                    {
                        HeuristicValue heuristicValue = new HeuristicValue(0f);
                        heuristicValue.Add(1f, "constant", new object[0]);
                        HeuristicValue heuristicValue2 = new HeuristicValue(0f);
                        float          operand         = 1f;
                        heuristicValue2.Add(operand, "Factor from xml(constant for now)", new object[0]);
                        heuristicValue2.Multiply(num, "Nb turn added by opportunity", new object[0]);
                        heuristicValue2.Add(1f, "Constant to avoid divide by 0", new object[0]);
                        heuristicValue.Divide(heuristicValue2, "Distance factor", new object[0]);
                        navyArmy.Opportunities.Add(new BehaviorOpportunity
                        {
                            OpportunityPosition = pointOfInterest.WorldPosition,
                            Score = heuristicValue,
                            Type  = BehaviorOpportunity.OpportunityType.Ruin
                        });
                    }
                }
            }
        }
    }
예제 #18
0
    protected HeuristicValue ComputeDistanceFitness(float numberOfTurnToReach, BaseNavyArmy.ArmyRole armyRole)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);
        float          num            = 5f;

        heuristicValue.Add(numberOfTurnToReach, "Turn to reach", new object[0]);
        float operand = 4f;

        heuristicValue.Divide(operand, "constant", new object[0]);
        heuristicValue.Clamp(0f, num);
        HeuristicValue heuristicValue2 = new HeuristicValue(0f);

        heuristicValue2.Add(num, "constant", new object[0]);
        heuristicValue2.Subtract(heuristicValue, "Turn ratio", new object[0]);
        HeuristicValue heuristicValue3 = new HeuristicValue(0f);

        heuristicValue3.Add(heuristicValue2, "inverted turn ratio", new object[0]);
        heuristicValue3.Divide(num, "constant for normalization", new object[0]);
        return(heuristicValue3);
    }
예제 #19
0
 private void ComputeObjectivePriority()
 {
     base.GlobalPriority.Reset();
     base.GlobalPriority.Add(1f, "(constant) always high priority", new object[0]);
     for (int i = 0; i < this.globalObjectiveMessages.Count; i++)
     {
         HeuristicValue heuristicValue = new HeuristicValue(0.5f);
         if (base.AIEntity.Empire.GetAgency <DepartmentOfForeignAffairs>().IsInWarWithSomeone())
         {
             heuristicValue.Boost(0.5f, "(constant) At war", new object[0]);
         }
         Region region = this.worldPositionningService.GetRegion(this.globalObjectiveMessages[i].RegionIndex);
         if ((float)region.City.UnitsCount < (float)region.City.MaximumUnitSlot * 0.5f)
         {
             heuristicValue.Boost(0.2f, "(constant) City defense is low", new object[0]);
         }
         this.globalObjectiveMessages[i].LocalPriority  = heuristicValue;
         this.globalObjectiveMessages[i].GlobalPriority = base.GlobalPriority;
         this.globalObjectiveMessages[i].TimeOut        = 1;
     }
 }
예제 #20
0
    private void ComputeOpportunityScore_Orbs(BaseNavyArmy army)
    {
        NavyArmy navyArmy = army as NavyArmy;

        if (navyArmy == null)
        {
            return;
        }
        IOrbAIHelper service = AIScheduler.Services.GetService <IOrbAIHelper>();

        for (int i = 0; i < service.OrbSpawns.Count; i++)
        {
            OrbSpawnInfo orbSpawnInfo = service.OrbSpawns[i];
            if (orbSpawnInfo != null && orbSpawnInfo.CurrentOrbCount != 0f)
            {
                HeuristicValue heuristicValue = orbSpawnInfo.EmpireNeedModifier[army.Garrison.Empire.Index];
                if (heuristicValue > 0f)
                {
                    float num = this.ComputeOpportunityTurnOverhead(army, orbSpawnInfo.WorldPosition);
                    if ((army.CurrentMainTask == null || this.IsDetourWorthChecking(army, num)) && this.worldPositionService.IsOceanTile(orbSpawnInfo.WorldPosition) && this.IsCloseEnoughToOrigin(army, orbSpawnInfo.WorldPosition, 1f))
                    {
                        HeuristicValue heuristicValue2 = new HeuristicValue(0f);
                        heuristicValue2.Add(heuristicValue, "Orb position eval", new object[0]);
                        float          orbDistanceExponent = service.GetOrbDistanceExponent(army.Garrison.Empire);
                        HeuristicValue heuristicValue3     = new HeuristicValue(0f);
                        heuristicValue3.Add(num, "Nb turn added by opportunity", new object[0]);
                        heuristicValue3.Power(orbDistanceExponent, "From xml registry", new object[0]);
                        heuristicValue3.Add(1f, "avoid divide by 0", new object[0]);
                        heuristicValue2.Divide(heuristicValue3, "DistanceFactor", new object[0]);
                        navyArmy.Opportunities.Add(new BehaviorOpportunity
                        {
                            OpportunityPosition = orbSpawnInfo.WorldPosition,
                            Score = heuristicValue2,
                            Type  = BehaviorOpportunity.OpportunityType.Orbs
                        });
                    }
                }
            }
        }
    }
예제 #21
0
 private void ResetProductionPriority(float currentMilitaryPower)
 {
     this.InitialProductionPriority.Reset();
     if (this.needMilitaryPower < currentMilitaryPower)
     {
         float          num            = 2f;
         HeuristicValue heuristicValue = new HeuristicValue(0f);
         heuristicValue.Add(currentMilitaryPower, "Current military power", new object[0]);
         heuristicValue.Divide(this.needMilitaryPower, "Wanted military power", new object[0]);
         HeuristicValue heuristicValue2 = new HeuristicValue(0f);
         heuristicValue2.Add(heuristicValue, "Ratio", new object[0]);
         heuristicValue2.Clamp(0f, num);
         heuristicValue2.Divide(num, "Normalize", new object[0]);
         heuristicValue2.Multiply(0.7f, "Max difference", new object[0]);
         this.InitialProductionPriority.Add(0.8f, "Max priority when over wanted", new object[0]);
         this.InitialProductionPriority.Subtract(heuristicValue2, "Current higher than wanted", new object[0]);
     }
     else if (currentMilitaryPower > 0f)
     {
         float          num2            = 4f;
         HeuristicValue heuristicValue3 = new HeuristicValue(0f);
         heuristicValue3.Add(this.needMilitaryPower, "Wanted military power", new object[0]);
         heuristicValue3.Divide(currentMilitaryPower, "Current military power", new object[0]);
         HeuristicValue heuristicValue4 = new HeuristicValue(0f);
         heuristicValue4.Add(heuristicValue3, "Ratio", new object[0]);
         heuristicValue4.Clamp(0f, num2);
         heuristicValue4.Divide(num2, "Normalize", new object[0]);
         heuristicValue4.Multiply(0.6f, "Max difference", new object[0]);
         this.InitialProductionPriority.Add(0.3f, "Minimal priority", new object[0]);
         this.InitialProductionPriority.Add(heuristicValue4, "Current is under needed", new object[0]);
     }
     else
     {
         this.InitialProductionPriority.Add(0.8f, "current == 0, max priority!", new object[0]);
     }
 }
    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]);
        }
    }
예제 #23
0
 public int CompareTo(ISearchable <T> other)
 {
     return(HeuristicValue.CompareTo(other.HeuristicValue));
 }
예제 #24
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);
                }
            }
        }
    }
예제 #25
0
    protected override void RefreshObjectives(StaticString context, StaticString pass)
    {
        base.RefreshObjectives(context, pass);
        AILayer_Military layer = base.AIEntity.GetLayer <AILayer_Military>();

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

        base.GlobalPriority.Add(layer2.StrategicNetwork.GetAgentValue("InternalMilitary"), "Strategic network 'InternalMilitary'", new object[0]);
        base.GlobalPriority.Boost(-0.5f, "Avoid patrol to be high", new object[0]);
        base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.Patrol.ToString(), ref this.patrolObjectives);
        base.ValidateMessages(ref this.patrolObjectives);
        if (base.AIEntity.Empire is MajorEmpire)
        {
            MajorEmpire majorEmpire = base.AIEntity.Empire as MajorEmpire;
            for (int i = 0; i < majorEmpire.ConvertedVillages.Count; i++)
            {
                Village village = majorEmpire.ConvertedVillages[i];
                if (this.worldAtlasHelper.IsRegionExplored(base.AIEntity.Empire, village.Region, 0.95f))
                {
                    GlobalObjectiveMessage globalObjectiveMessage = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == village.Region.Index);
                    if (globalObjectiveMessage == null)
                    {
                        globalObjectiveMessage = base.GenerateObjective(village.Region.Index);
                        this.patrolObjectives.Add(globalObjectiveMessage);
                    }
                    globalObjectiveMessage.TimeOut        = 1;
                    globalObjectiveMessage.GlobalPriority = base.GlobalPriority;
                    HeuristicValue heuristicValue = new HeuristicValue(0f);
                    heuristicValue.Add(layer.GetVillageUnitPriority(village, village.StandardUnits.Count), "Village unit priority", new object[0]);
                    globalObjectiveMessage.LocalPriority = heuristicValue;
                }
            }
            for (int j = 0; j < majorEmpire.TamedKaijus.Count; j++)
            {
                Kaiju kaiju = majorEmpire.TamedKaijus[j];
                if (kaiju.OnGarrisonMode())
                {
                    GlobalObjectiveMessage globalObjectiveMessage2 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == kaiju.Region.Index);
                    if (globalObjectiveMessage2 == null)
                    {
                        globalObjectiveMessage2 = base.GenerateObjective(kaiju.Region.Index);
                        this.patrolObjectives.Add(globalObjectiveMessage2);
                    }
                    globalObjectiveMessage2.TimeOut        = 1;
                    globalObjectiveMessage2.GlobalPriority = base.GlobalPriority;
                    HeuristicValue heuristicValue2 = new HeuristicValue(0.6f);
                    AIRegionData   regionData      = this.worldAtlasHelper.GetRegionData(base.AIEntity.Empire.Index, kaiju.Region.Index);
                    if (regionData != null)
                    {
                        float operand = Mathf.Min(1f, 0.1f * (float)regionData.BorderWithNeutral + 0.2f * (float)regionData.BorderWithEnnemy);
                        heuristicValue2.Boost(operand, "Border with enemy!", new object[0]);
                    }
                    globalObjectiveMessage2.LocalPriority = heuristicValue2;
                }
            }
        }
        for (int k = 0; k < this.departmentOfTheInterior.Cities.Count; k++)
        {
            City city = this.departmentOfTheInterior.Cities[k];
            if (this.worldAtlasHelper.IsRegionExplored(base.AIEntity.Empire, city.Region, 0.8f))
            {
                GlobalObjectiveMessage globalObjectiveMessage3 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == city.Region.Index);
                if (globalObjectiveMessage3 == null)
                {
                    globalObjectiveMessage3 = base.GenerateObjective(city.Region.Index);
                    this.patrolObjectives.Add(globalObjectiveMessage3);
                }
                globalObjectiveMessage3.TimeOut        = 1;
                globalObjectiveMessage3.GlobalPriority = base.GlobalPriority;
                HeuristicValue heuristicValue3 = new HeuristicValue(0f);
                heuristicValue3.Add(AILayer_Military.GetCityDefenseLocalPriority(city, this.unitRatioBoost, 0), "City defense local priority", new object[0]);
                globalObjectiveMessage3.LocalPriority = heuristicValue3;
            }
        }
        if (base.AIEntity.Empire is MajorEmpire)
        {
            using (List <int> .Enumerator enumerator = this.questSolverLayer.QuestRegions.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    int regionIndex = enumerator.Current;
                    GlobalObjectiveMessage globalObjectiveMessage4 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == regionIndex);
                    if (globalObjectiveMessage4 == null)
                    {
                        globalObjectiveMessage4 = base.GenerateObjective(regionIndex);
                        this.patrolObjectives.Add(globalObjectiveMessage4);
                    }
                    if (globalObjectiveMessage4 != null)
                    {
                        globalObjectiveMessage4.GlobalPriority.Value = 0.85f;
                        globalObjectiveMessage4.LocalPriority.Value  = 0.85f;
                    }
                }
            }
        }
        if (this.departmentOfForeignAffairs.IsInWarWithSomeone())
        {
            base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString(), ref this.warPatrolObjectives);
            base.ValidateMessages(ref this.warPatrolObjectives);
            if (base.AIEntity.Empire is MajorEmpire)
            {
                MajorEmpire majorEmpire2 = base.AIEntity.Empire as MajorEmpire;
                for (int l = 0; l < majorEmpire2.ConvertedVillages.Count; l++)
                {
                    Village village = majorEmpire2.ConvertedVillages[l];
                    GlobalObjectiveMessage globalObjectiveMessage5 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == village.Region.Index);
                    if (globalObjectiveMessage5 == null)
                    {
                        globalObjectiveMessage5 = base.GenerateObjective(village.Region.Index);
                        globalObjectiveMessage5.ObjectiveType = AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString();
                        this.warPatrolObjectives.Add(globalObjectiveMessage5);
                    }
                    globalObjectiveMessage5.TimeOut        = 1;
                    globalObjectiveMessage5.GlobalPriority = base.GlobalPriority;
                    HeuristicValue heuristicValue4 = new HeuristicValue(0f);
                    heuristicValue4.Add(layer.GetVillageUnitPriority(village, village.StandardUnits.Count), "Village unit priority", new object[0]);
                    globalObjectiveMessage5.LocalPriority = heuristicValue4;
                }
                for (int m = 0; m < majorEmpire2.TamedKaijus.Count; m++)
                {
                    Kaiju kaiju = majorEmpire2.TamedKaijus[m];
                    if (kaiju.OnGarrisonMode())
                    {
                        GlobalObjectiveMessage globalObjectiveMessage6 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == kaiju.Region.Index);
                        if (globalObjectiveMessage6 == null)
                        {
                            globalObjectiveMessage6 = base.GenerateObjective(kaiju.Region.Index);
                            this.warPatrolObjectives.Add(globalObjectiveMessage6);
                        }
                        globalObjectiveMessage6.TimeOut        = 1;
                        globalObjectiveMessage6.GlobalPriority = base.GlobalPriority;
                        HeuristicValue heuristicValue5 = new HeuristicValue(0.8f);
                        AIRegionData   regionData2     = this.worldAtlasHelper.GetRegionData(base.AIEntity.Empire.Index, kaiju.Region.Index);
                        if (regionData2 != null)
                        {
                            float operand2 = Mathf.Min(1f, 0.2f * (float)regionData2.BorderWithNeutral + 0.3f * (float)regionData2.BorderWithEnnemy);
                            heuristicValue5.Boost(operand2, "Border with enemy!", new object[0]);
                        }
                        globalObjectiveMessage6.LocalPriority = heuristicValue5;
                    }
                }
            }
            for (int n = 0; n < this.departmentOfTheInterior.Cities.Count; n++)
            {
                City city = this.departmentOfTheInterior.Cities[n];
                GlobalObjectiveMessage globalObjectiveMessage7 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == city.Region.Index);
                if (globalObjectiveMessage7 == null)
                {
                    globalObjectiveMessage7 = base.GenerateObjective(city.Region.Index);
                    globalObjectiveMessage7.ObjectiveType = AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString();
                    this.warPatrolObjectives.Add(globalObjectiveMessage7);
                }
                globalObjectiveMessage7.TimeOut        = 1;
                globalObjectiveMessage7.GlobalPriority = base.GlobalPriority;
                HeuristicValue heuristicValue6 = new HeuristicValue(0f);
                heuristicValue6.Add(AILayer_Military.GetCityDefenseLocalPriority(city, this.unitRatioBoost, 0), "City defense local priority", new object[0]);
                if (this.worldAtlasHelper.GetRegionData(city.Empire.Index, city.Region.Index).BorderWithEnnemy > 0)
                {
                    heuristicValue6.Boost(0.2f, "Border with enemy!", new object[0]);
                }
                globalObjectiveMessage7.LocalPriority = heuristicValue6;
            }
            bool flag = false;
            for (int num = 0; num < this.warPatrolObjectives.Count; num++)
            {
                GlobalObjectiveMessage warPatrolObjective = this.warPatrolObjectives[num];
                if (base.AIEntity.GetCommanderProcessingTheNeededGlobalObjective(warPatrolObjective.ID) == null)
                {
                    GlobalObjectiveMessage globalObjectiveMessage8 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == warPatrolObjective.RegionIndex);
                    if (globalObjectiveMessage8 != null)
                    {
                        AICommander commanderProcessingTheNeededGlobalObjective = base.AIEntity.GetCommanderProcessingTheNeededGlobalObjective(globalObjectiveMessage8.ID);
                        if (commanderProcessingTheNeededGlobalObjective != null)
                        {
                            commanderProcessingTheNeededGlobalObjective.Release();
                            flag = true;
                        }
                    }
                }
            }
            if (flag)
            {
                base.AIEntity.KillAllCommanders("AICommander_Exploration");
            }
        }
    }