Exemplo n.º 1
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);
    }
Exemplo n.º 2
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]);
        }
    }
Exemplo n.º 3
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);
    }
Exemplo n.º 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);
    }
Exemplo n.º 5
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
                        });
                    }
                }
            }
        }
    }
Exemplo n.º 6
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);
    }
Exemplo n.º 7
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
                        });
                    }
                }
            }
        }
    }
Exemplo n.º 8
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]);
     }
 }