Пример #1
0
    private float ScoreTransferFunctionDelegate(ConstructibleElement constructibleElement, float score)
    {
        EmpirePlanDefinition empirePlanDefinition = constructibleElement as EmpirePlanDefinition;

        Diagnostics.Assert(empirePlanDefinition != null);
        float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.AIEntity.Empire.SimulationObject, empirePlanDefinition, DepartmentOfTheTreasury.Resources.EmpirePoint);

        return((productionCostWithBonus <= float.Epsilon) ? score : (score / productionCostWithBonus));
    }
Пример #2
0
    private SynchronousJobState SynchronousJob_ChangeEmpirePlan()
    {
        if (this.empirePlanClasses == null)
        {
            this.empirePlanMessages.Clear();
            return(SynchronousJobState.Failure);
        }
        float num = 0f;
        AILayer_AccountManager layer = base.AIEntity.GetLayer <AILayer_AccountManager>();

        Diagnostics.Assert(layer != null);
        Account account = layer.TryGetAccount(AILayer_AccountManager.EmpirePlanAccountName);

        if (account == null)
        {
            this.empirePlanMessages.Clear();
            return(SynchronousJobState.Failure);
        }
        if (this.empirePlanMessages.Count != this.empirePlanClasses.Length)
        {
            Diagnostics.LogError("There must be one empire plan evaluable message by empire plan class.");
            this.empirePlanMessages.Clear();
            return(SynchronousJobState.Failure);
        }
        for (int i = 0; i < this.empirePlanMessages.Count; i++)
        {
            EvaluableMessage_EmpirePlan evaluableMessage_EmpirePlan = this.empirePlanMessages[i];
            if (this.departmentOfPlanification.IsEmpirePlanChoiced)
            {
                evaluableMessage_EmpirePlan.SetObtained();
            }
            else
            {
                EmpirePlanDefinition empirePlanDefinition = this.departmentOfPlanification.GetEmpirePlanDefinition(evaluableMessage_EmpirePlan.EmpirePlanClass, evaluableMessage_EmpirePlan.EmpirePlanLevel);
                if (empirePlanDefinition != null)
                {
                    float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.AIEntity.Empire.SimulationObject, empirePlanDefinition, DepartmentOfTheTreasury.Resources.EmpirePoint);
                    if (num + productionCostWithBonus <= account.PromisedAmount)
                    {
                        num += productionCostWithBonus;
                        OrderChangeEmpirePlan order = new OrderChangeEmpirePlan(base.AIEntity.Empire.Index, empirePlanDefinition.EmpirePlanClass, empirePlanDefinition.EmpirePlanLevel);
                        Ticket ticket;
                        base.AIEntity.Empire.PlayerControllers.Client.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderChangeEmpirePlan_TicketRaised));
                    }
                }
            }
        }
        this.empirePlanMessages.Clear();
        return(SynchronousJobState.Success);
    }
Пример #3
0
 protected override void EvaluateNeeds(StaticString context, StaticString pass)
 {
     base.EvaluateNeeds(context, pass);
     Diagnostics.Assert(this.empirePlanMessages != null && this.empirePlanMessages.Count == 0);
     if (!this.departmentOfPlanification.IsEmpirePlanChoiceTurn)
     {
         return;
     }
     this.empirePlanMessages.AddRange(base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage_EmpirePlan>(BlackboardLayerID.Empire, (EvaluableMessage_EmpirePlan match) => match.EvaluationState == EvaluableMessage.EvaluableMessageState.Pending));
     this.empirePlanMessages.Sort((EvaluableMessage_EmpirePlan left, EvaluableMessage_EmpirePlan right) => - 1 * left.Interest.CompareTo(right.Interest));
     for (int i = 0; i < this.empirePlanMessages.Count; i++)
     {
         EvaluableMessage_EmpirePlan evaluableMessage_EmpirePlan = this.empirePlanMessages[i];
         EmpirePlanDefinition        empirePlanDefinition        = this.departmentOfPlanification.GetEmpirePlanDefinition(evaluableMessage_EmpirePlan.EmpirePlanClass, evaluableMessage_EmpirePlan.EmpirePlanLevel);
         float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.AIEntity.Empire.SimulationObject, empirePlanDefinition, DepartmentOfTheTreasury.Resources.EmpirePoint);
         evaluableMessage_EmpirePlan.UpdateBuyEvaluation("EmpirePlan", 0UL, productionCostWithBonus, 2, 0f, 0UL);
     }
 }
Пример #4
0
    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);
            }
        }
    }