예제 #1
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;
        }
    }
예제 #2
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);
    }
예제 #3
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);
    }
예제 #4
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);
    }
예제 #5
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;
     }
 }
예제 #6
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;
        }
    }
예제 #7
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");
            }
        }
    }