Beispiel #1
0
    private void ComputeScoresByFIDSI()
    {
        IWorldPositionEvaluationAIHelper service = AIScheduler.Services.GetService <IWorldPositionEvaluationAIHelper>();

        Diagnostics.Assert(service != null);
        IPersonalityAIHelper service2 = AIScheduler.Services.GetService <IPersonalityAIHelper>();

        Diagnostics.Assert(service2 != null);
        WorldPositionScore[] worldPositionCreepingNodeImprovementScore = service.GetWorldPositionCreepingNodeImprovementScore(base.AIEntity.Empire, this.aiEntityCity.City, this.availableNodes);
        string regitryPath   = "AI/MajorEmpire/AIEntity_Empire/AILayer_Research/ElementEvaluatorContextMultiplier/AIEmpireGrowth";
        float  registryValue = service2.GetRegistryValue <float>(base.AIEntity.Empire, regitryPath, 1f);

        regitryPath = "AI/MajorEmpire/AIEntity_Empire/AILayer_Research/ElementEvaluatorContextMultiplier/AIEmpireProduction";
        float registryValue2 = service2.GetRegistryValue <float>(base.AIEntity.Empire, regitryPath, 1f);

        regitryPath = "AI/MajorEmpire/AIEntity_Empire/AILayer_Research/ElementEvaluatorContextMultiplier/AIEmpireResearch";
        float registryValue3 = service2.GetRegistryValue <float>(base.AIEntity.Empire, regitryPath, 1f);

        regitryPath = "AI/MajorEmpire/AIEntity_Empire/AILayer_Research/ElementEvaluatorContextMultiplier/AIEmpireMoney";
        float registryValue4 = service2.GetRegistryValue <float>(base.AIEntity.Empire, regitryPath, 1f);

        regitryPath = "AI/MajorEmpire/AIEntity_Empire/AILayer_Research/ElementEvaluatorContextMultiplier/AIEmpireEmpirePoint";
        float        registryValue5 = service2.GetRegistryValue <float>(base.AIEntity.Empire, regitryPath, 1f);
        List <float> list           = new List <float>();

        foreach (WorldPositionScore worldPositionScore in worldPositionCreepingNodeImprovementScore)
        {
            float num  = worldPositionScore.Scores[0].Value * registryValue;
            float num2 = worldPositionScore.Scores[1].Value * registryValue2;
            float num3 = worldPositionScore.Scores[2].Value * registryValue3;
            float num4 = worldPositionScore.Scores[3].Value * registryValue4;
            float num5 = worldPositionScore.Scores[4].Value * registryValue5;
            float item = num + num2 + num3 + num4 + num5;
            list.Add(item);
        }
        if (list.Count > 0)
        {
            float num6 = list.Min();
            float num7 = list.Max();
            for (int j = 0; j < list.Count; j++)
            {
                float num8        = (num6 == num7) ? this.NormalizationFailSafeValue : Mathf.InverseLerp(num6, num7, list[j]);
                float score       = this.availableNodes[j].score;
                float boostFactor = num8 * this.FIDSIWeight;
                this.availableNodes[j].score = AILayer.Boost(score, boostFactor);
            }
        }
    }
    public override IEnumerator Initialize(AIEntity aiEntity)
    {
        this.aiEntityCity  = (aiEntity as AIEntity_City);
        this.amasCityLayer = this.aiEntityCity.GetLayer <AILayer_AmasCity>();
        yield return(base.Initialize(aiEntity));

        base.AIEntity.RegisterPass(AIEntity.Passes.CreateLocalNeeds.ToString(), "LayerPopulation_CreateLocalNeedsPass", new AIEntity.AIAction(this.CreateLocalNeeds), this, new StaticString[]
        {
            "LayerAmasCity_CreateLocalNeedsPass",
            "LayerExtension_CreateLocalNeedsPass"
        });
        base.AIEntity.RegisterPass(AIEntity.Passes.EvaluateNeeds.ToString(), "LayerPopulation_EvaluateNeedsPass", new AIEntity.AIAction(this.EvaluateNeeds), this, new StaticString[]
        {
            "LayerExtension_EvaluateNeedsPass"
        });
        base.AIEntity.RegisterPass(AIEntity.Passes.ExecuteNeeds.ToString(), "LayerPopulation_ExecuteNeedsPass", new AIEntity.AIAction(this.ExecuteNeeds), this, new StaticString[]
        {
            "LayerExtension_ExecuteNeedsPass"
        });
        this.interpreterContext = new InterpreterContext(this.aiEntityCity.City);
        for (int index = 0; index < AILayer_Population.PopulationResource.Length; index++)
        {
            this.interpreterContext.Register(AILayer_Population.PopulationResource[index], 1);
        }
        this.preferedPopulationMessageID = base.AIEntity.AIPlayer.Blackboard.AddMessage(new PreferedPopulationMessage(this.aiEntityCity.City.GUID));
        if (!(this.aiEntityCity.AIPlayer is AIPlayer_MajorEmpire))
        {
            AILayer.LogError("The agent context object is not an ai player.");
        }
        DepartmentOfIndustry industry = this.Empire.GetAgency <DepartmentOfIndustry>();

        DepartmentOfIndustry.ConstructibleElement[] constructibleElements = ((IConstructibleElementDatabase)industry).GetAvailableConstructibleElements(new StaticString[]
        {
            DistrictImprovementDefinition.ReadOnlyCategory
        });
        Diagnostics.Assert(constructibleElements != null);
        this.districtImprovement = Array.Find <DepartmentOfIndustry.ConstructibleElement>(constructibleElements, delegate(DepartmentOfIndustry.ConstructibleElement element)
        {
            AIPlayer_MajorEmpire aiPlayer;
            return(element.Name == aiPlayer.AIData_Faction.DistrictImprovement);
        });
        Diagnostics.Assert(this.districtImprovement != null);
        IPersonalityAIHelper personalityAIHelper = AIScheduler.Services.GetService <IPersonalityAIHelper>();

        this.populationThresholdForSacrifice = personalityAIHelper.GetRegistryValue <float>(this.Empire, "AI/MajorEmpire/AIEntity_City/AILayer_Population/PopulationThresholdForSacrifice", this.populationThresholdForSacrifice);
        this.approvalThresholdForSacrifice   = personalityAIHelper.GetRegistryValue <float>(this.Empire, "AI/MajorEmpire/AIEntity_City/AILayer_Population/ApprovalThresholdForSacrifice", this.approvalThresholdForSacrifice);
        yield break;
    }
Beispiel #3
0
    public override IEnumerator Initialize(AIEntity aiEntity)
    {
        yield return(base.Initialize(aiEntity));

        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        this.worldPositionningService = service.Game.Services.GetService <IWorldPositionningService>();
        Diagnostics.Assert(this.worldPositionningService != null);
        this.worldAtlasHelper           = AIScheduler.Services.GetService <IWorldAtlasAIHelper>();
        this.departmentOfTheInterior    = base.AIEntity.Empire.GetAgency <DepartmentOfTheInterior>();
        this.departmentOfForeignAffairs = base.AIEntity.Empire.GetAgency <DepartmentOfForeignAffairs>();
        this.departmentOfDefense        = base.AIEntity.Empire.GetAgency <DepartmentOfDefense>();
        IPersonalityAIHelper service2 = AIScheduler.Services.GetService <IPersonalityAIHelper>();

        this.unitRatioBoost              = service2.GetRegistryValue <float>(base.AIEntity.Empire, string.Format("{0}/{1}", AILayer_Patrol.RegistryPath, "UnitRatioBoost"), this.unitRatioBoost);
        this.questManagementService      = service.Game.Services.GetService <IQuestManagementService>();
        this.questRepositoryService      = service.Game.Services.GetService <IQuestRepositoryService>();
        this.gameEntityRepositoryService = service.Game.Services.GetService <IGameEntityRepositoryService>();
        if (base.AIEntity.Empire is MajorEmpire)
        {
            this.questSolverLayer = base.AIEntity.GetLayer <AILayer_QuestSolver>();
        }
        base.AIEntity.RegisterPass(AIEntity.Passes.RefreshObjectives.ToString(), "AILayer_Patrol_RefreshObjectives", new AIEntity.AIAction(this.RefreshObjectives), this, new StaticString[]
        {
            "AILayer_QuestSolver_RefreshObjectives"
        });
        yield break;
    }
    private void CacheAttitudeMultipliers()
    {
        IPersonalityAIHelper service = AIScheduler.Services.GetService <IPersonalityAIHelper>();

        Diagnostics.Assert(service != null);
        this.attitudeMultipliers = new Dictionary <StaticString, float>();
        string arg = string.Format("AI/AgentDefinition/{0}", base.GetType().Name);

        for (int i = 0; i < AILayer_Attitude.AttitudeScoreDefinitionReferences.All.Length; i++)
        {
            StaticString staticString  = AILayer_Attitude.AttitudeScoreDefinitionReferences.All[i];
            string       regitryPath   = string.Format("{0}/{1}{2}", arg, staticString.ToString().Substring("AttitudeScore".Length), "Multiplier");
            float        registryValue = service.GetRegistryValue <float>(this.Empire, regitryPath, 0f);
            if (registryValue != 0f)
            {
                this.attitudeMultipliers[staticString] = registryValue;
            }
        }
    }
    protected override bool Initialize(AIBehaviorTree aiBehaviorTree)
    {
        if (this.WorldPath != null)
        {
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_PathVarName))
            {
                aiBehaviorTree.Variables[this.Output_PathVarName] = this.WorldPath;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_PathVarName, this.WorldPath);
            }
        }
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        this.worldPositionningService = service.Game.Services.GetService <IWorldPositionningService>();
        Diagnostics.Assert(this.worldPositionningService != null);
        this.pathfindingService = service.Game.Services.GetService <IPathfindingService>();
        Diagnostics.Assert(this.pathfindingService != null);
        if (this.SafePathOpportunityMax < 0f)
        {
            IPersonalityAIHelper service2 = AIScheduler.Services.GetService <IPersonalityAIHelper>();
            this.SafePathOpportunityMax = service2.GetRegistryValue <float>(aiBehaviorTree.AICommander.Empire, "AI/Behavior/GlobalSafePathOpportunity", 1.25f);
        }
        if (!Services.GetService <IDownloadableContentService>().IsShared(DownloadableContent13.ReadOnlyName))
        {
            this.SafePathOpportunityMax = -1f;
        }
        if (aiBehaviorTree.AICommander.Empire is MajorEmpire)
        {
            this.departmentOfTransportation = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfTransportation>();
            ArmyAction armyAction;
            if (Databases.GetDatabase <ArmyAction>(false).TryGetValue("ArmyActionFastTravel", out armyAction))
            {
                this.armyAction_FastTravel = (armyAction as ArmyAction_FastTravel);
            }
        }
        return(base.Initialize(aiBehaviorTree));
    }
    protected override void CreateLocalNeeds(StaticString context, StaticString pass)
    {
        base.CreateLocalNeeds(context, pass);
        Account account = this.aiLayerAccountManager.TryGetAccount(AILayer_AccountManager.EmpirePlanAccountName);

        if (account == null)
        {
            AILayer.LogError("Can't retrieve the empire plan account.");
            return;
        }
        Diagnostics.Assert(this.empirePlanClasses != null);
        Diagnostics.Assert(this.wantedEmpirePlan != null);
        for (int i = 0; i < this.empirePlanClasses.Length; i++)
        {
            this.wantedEmpirePlan.SubmitPlan(this.departmentOfPlanification.GetEmpirePlanDefinition(this.empirePlanClasses[i], 0));
        }
        Diagnostics.Assert(this.availableEmpirePlans != null);
        this.availableEmpirePlans.Clear();
        for (int j = 0; j < this.empirePlanClasses.Length; j++)
        {
            int empirePlanAvailableLevel = this.departmentOfPlanification.GetEmpirePlanAvailableLevel(this.empirePlanClasses[j]);
            for (int k = 1; k <= empirePlanAvailableLevel; k++)
            {
                this.availableEmpirePlans.Add(this.departmentOfPlanification.GetEmpirePlanDefinition(this.empirePlanClasses[j], k));
            }
        }
        Diagnostics.Assert(this.decisionMaker != null);
        base.AIEntity.Context.InitializeDecisionMaker <ConstructibleElement>(AILayer_Strategy.EmpirePlanParameterModifier, this.decisionMaker);
        this.decisionMaker.ClearAIParametersOverrides();
        this.FillDecisionMakerVariables();
        Diagnostics.Assert(this.decisionResults != null);
        this.decisionResults.Clear();
        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
        {
            DecisionMakerEvaluationData <ConstructibleElement, InterpreterContext> decisionMakerEvaluationData;
            this.decisionMaker.EvaluateDecisions(this.availableEmpirePlans, ref this.decisionResults, out decisionMakerEvaluationData);
            IGameService service = Services.GetService <IGameService>();
            decisionMakerEvaluationData.Turn = (service.Game as global::Game).Turn;
            this.DecisionMakerEvaluationDataHistoric.Add(decisionMakerEvaluationData);
        }
        else
        {
            this.decisionMaker.EvaluateDecisions(this.availableEmpirePlans, ref this.decisionResults);
        }
        IPersonalityAIHelper service2 = AIScheduler.Services.GetService <IPersonalityAIHelper>();
        float registryValue           = service2.GetRegistryValue <float>(base.AIEntity.Empire, "AI/MajorEmpire/AIEntity_Empire/AILayer_EmpirePlan/MaximumPopulationPercentToReachObjective", 0f);

        Diagnostics.Assert(this.wantedEmpirePlan != null);
        float num  = 0f;
        float num2 = float.MaxValue;
        float num3 = float.MinValue;

        for (int l = 0; l < this.decisionResults.Count; l++)
        {
            DecisionResult decisionResult = this.decisionResults[l];
            if (decisionResult.Score < 0.05f)
            {
                break;
            }
            EmpirePlanDefinition empirePlanDefinition = decisionResult.Element as EmpirePlanDefinition;
            num2 = Mathf.Min(num2, decisionResult.Score);
            num3 = Mathf.Max(num3, decisionResult.Score);
            EmpirePlanDefinition currentEmpirePlanDefinition = this.wantedEmpirePlan.GetCurrentEmpirePlanDefinition(empirePlanDefinition.EmpirePlanClass);
            if (currentEmpirePlanDefinition == null || empirePlanDefinition.EmpirePlanLevel > currentEmpirePlanDefinition.EmpirePlanLevel)
            {
                float num4 = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.AIEntity.Empire.SimulationObject, empirePlanDefinition, DepartmentOfTheTreasury.Resources.EmpirePoint);
                if (currentEmpirePlanDefinition != null)
                {
                    float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.AIEntity.Empire.SimulationObject, currentEmpirePlanDefinition, DepartmentOfTheTreasury.Resources.EmpirePoint);
                    num4 -= productionCostWithBonus;
                }
                float empirePointProductionStress = this.GetEmpirePointProductionStress(num + num4, account, this.departmentOfPlanification.EmpirePlanChoiceRemainingTurn);
                if (empirePointProductionStress <= registryValue)
                {
                    num += num4;
                    this.wantedEmpirePlan.SubmitPlan(empirePlanDefinition);
                }
            }
        }
        Diagnostics.Assert(this.empirePlanClasses != null);
        Diagnostics.Assert(this.wantedEmpirePlan != null);
        for (int m = 0; m < this.empirePlanClasses.Length; m++)
        {
            EmpirePlanDefinition empirePlan = this.wantedEmpirePlan.GetCurrentEmpirePlanDefinition(this.empirePlanClasses[m]);
            float localOpportunity          = 0f;
            if (empirePlan.EmpirePlanLevel > 0)
            {
                float score = this.decisionResults.Find((DecisionResult match) => match.Element == empirePlan).Score;
                localOpportunity = ((num3 - num2 <= float.Epsilon) ? 0f : ((score - num2) / (num3 - num2)));
            }
            EvaluableMessage_EmpirePlan evaluableMessage_EmpirePlan = base.AIEntity.AIPlayer.Blackboard.FindFirst <EvaluableMessage_EmpirePlan>(BlackboardLayerID.Empire, (EvaluableMessage_EmpirePlan match) => match.State == BlackboardMessage.StateValue.Message_InProgress && match.EmpirePlanClass == empirePlan.EmpirePlanClass);
            if (evaluableMessage_EmpirePlan != null)
            {
                evaluableMessage_EmpirePlan.EmpirePlanLevel = empirePlan.EmpirePlanLevel;
                evaluableMessage_EmpirePlan.SetInterest(1f, localOpportunity);
            }
            else
            {
                evaluableMessage_EmpirePlan = new EvaluableMessage_EmpirePlan(empirePlan.EmpirePlanClass, empirePlan.EmpirePlanLevel, this.departmentOfPlanification.EmpirePlanChoiceRemainingTurn, AILayer_AccountManager.EmpirePlanAccountName);
                evaluableMessage_EmpirePlan.SetInterest(1f, localOpportunity);
                base.AIEntity.AIPlayer.Blackboard.AddMessage(evaluableMessage_EmpirePlan);
            }
        }
    }