private void VoteForSeasonEffect_TicketRaised(object sender, TicketRaisedEventArgs e) { OrderVoteForSeasonEffect orderVoteForSeasonEffect = e.Order as OrderVoteForSeasonEffect; Diagnostics.Assert(orderVoteForSeasonEffect != null); List <EvaluableMessage_VoteForSeasonEffect> list = new List <EvaluableMessage_VoteForSeasonEffect>(base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage_VoteForSeasonEffect>(BlackboardLayerID.Empire, (EvaluableMessage_VoteForSeasonEffect message) => message.SeasonEffectReference == orderVoteForSeasonEffect.SeasonEffectName)); if (list.Count == 0) { return; } if (list.Count > 1) { AILayer.LogWarning("There should not be several PopulationBuyout EvaluableMessages for the same city"); } EvaluableMessage_VoteForSeasonEffect evaluableMessage_VoteForSeasonEffect = list[0]; if (e.Result == PostOrderResponse.Processed) { evaluableMessage_VoteForSeasonEffect.SetObtained(); } else { evaluableMessage_VoteForSeasonEffect.SetFailedToObtain(); } }
private SynchronousJobState SynchronousJob_VoteForSeasonEffect() { List <EvaluableMessage_VoteForSeasonEffect> list = new List <EvaluableMessage_VoteForSeasonEffect>(base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage_VoteForSeasonEffect>(BlackboardLayerID.Empire, (EvaluableMessage_VoteForSeasonEffect match) => match.State == BlackboardMessage.StateValue.Message_InProgress)); if (list.Count != 0) { if (list.Count > 1) { AILayer.LogWarning("There should not be several VoteForSeasonEffect EvaluableMessages for the same empire ({0})", new object[] { base.AIEntity.Empire.Index }); } EvaluableMessage_VoteForSeasonEffect evaluableMessage_VoteForSeasonEffect = list[0]; if (evaluableMessage_VoteForSeasonEffect.EvaluationState == EvaluableMessage.EvaluableMessageState.Validate) { OrderVoteForSeasonEffect order = new OrderVoteForSeasonEffect(base.AIEntity.Empire.Index, evaluableMessage_VoteForSeasonEffect.SeasonEffectReference, evaluableMessage_VoteForSeasonEffect.VoteCount); Ticket ticket; base.AIEntity.Empire.PlayerControllers.AI.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.VoteForSeasonEffect_TicketRaised)); return(SynchronousJobState.Success); } } return(SynchronousJobState.Success); }
protected override void EvaluateNeeds(StaticString context, StaticString pass) { base.EvaluateNeeds(context, pass); if (!this.CanUseAltar()) { return; } if (!this.seasonService.IsAlive || this.seasonService.Target == null) { return; } Season winterSeason = this.seasonService.Target.GetWinterSeason(); if (this.seasonService.Target.IsCurrentSeason(winterSeason)) { return; } global::Game game = Services.GetService <IGameService>().Game as global::Game; List <SeasonEffect> candidateEffectsForSeasonType = this.seasonService.Target.GetCandidateEffectsForSeasonType(Season.ReadOnlyWinter); Diagnostics.Assert(this.elementEvaluator != null); this.decisions.Clear(); this.RegisterInterpreterContextData(); if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools) { EvaluationData <SeasonEffect, InterpreterContext> evaluationData = new EvaluationData <SeasonEffect, InterpreterContext>(); this.elementEvaluator.Evaluate(candidateEffectsForSeasonType, ref this.decisions, evaluationData); evaluationData.Turn = game.Turn; this.SeasonEffectsEvaluationDataHistoric.Add(evaluationData); } else { this.elementEvaluator.Evaluate(candidateEffectsForSeasonType, ref this.decisions, null); } if (this.decisions.Count <= 0) { return; } int num = 0; int num2 = 0; for (int i = 0; i < candidateEffectsForSeasonType.Count; i++) { SeasonEffect seasonEffect = candidateEffectsForSeasonType[i]; int seasonEffectDisplayedScoreForEmpire = this.seasonService.Target.GetSeasonEffectDisplayedScoreForEmpire(base.AIEntity.Empire, seasonEffect); if (seasonEffectDisplayedScoreForEmpire > num) { num = seasonEffectDisplayedScoreForEmpire; num2 = 1; } else if (seasonEffectDisplayedScoreForEmpire == num) { num2++; } } DecisionResult decisionResult = this.decisions[0]; float score = decisionResult.Score; float score2 = this.decisions[this.decisions.Count - 1].Score; float num3 = score - score2; num3 = Mathf.Clamp01(num3 / this.maximumGainFromXml); SeasonEffect seasonEffect2 = decisionResult.Element as SeasonEffect; Diagnostics.Assert(seasonEffect2 != null); int seasonEffectScore = this.seasonService.Target.GetSeasonEffectScore(seasonEffect2); if (seasonEffectScore == num && num2 == 1) { return; } int neededVoteCount = num - seasonEffectScore + 1; List <EvaluableMessage_VoteForSeasonEffect> list = new List <EvaluableMessage_VoteForSeasonEffect>(base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage_VoteForSeasonEffect>(BlackboardLayerID.Empire, (EvaluableMessage_VoteForSeasonEffect message) => message.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtained && message.EvaluationState != EvaluableMessage.EvaluableMessageState.Cancel)); EvaluableMessage_VoteForSeasonEffect evaluableMessage_VoteForSeasonEffect; if (list.Count == 0) { evaluableMessage_VoteForSeasonEffect = new EvaluableMessage_VoteForSeasonEffect(seasonEffect2.SeasonEffectDefinition.Name, 1, AILayer_AccountManager.OrbAccountName); base.AIEntity.AIPlayer.Blackboard.AddMessage(evaluableMessage_VoteForSeasonEffect); } else { evaluableMessage_VoteForSeasonEffect = list[0]; if (seasonEffect2.SeasonEffectDefinition.Name != evaluableMessage_VoteForSeasonEffect.SeasonEffectReference) { Diagnostics.Log("AI don't want to vote for the season effect {0} anymore. AI now wants season effect {1}.", new object[] { evaluableMessage_VoteForSeasonEffect.SeasonEffectReference, seasonEffect2.SeasonEffectDefinition.Name }); evaluableMessage_VoteForSeasonEffect.Cancel(); evaluableMessage_VoteForSeasonEffect = new EvaluableMessage_VoteForSeasonEffect(seasonEffect2.SeasonEffectDefinition.Name, 1, AILayer_AccountManager.OrbAccountName); base.AIEntity.AIPlayer.Blackboard.AddMessage(evaluableMessage_VoteForSeasonEffect); } } float num4 = this.seasonService.Target.ComputePrayerOrbCost(base.AIEntity.Empire); float num5 = 10f * base.AIEntity.Empire.GetPropertyValue(SimulationProperties.GameSpeedMultiplier); int num6 = this.seasonService.Target.GetExactSeasonStartTurn(winterSeason) - game.Turn; float num7 = Mathf.Clamp01((num5 - (float)num6) / num5); float num8 = num3 * (0.5f + num7 / 2f); num8 = Mathf.Clamp01(num8); int num9 = this.ComputeWantedNumberOfOrbs(neededVoteCount); DepartmentOfScience agency = base.AIEntity.Empire.GetAgency <DepartmentOfScience>(); float num10 = 0f; float num11 = 0f; for (int j = 0; j < this.orbUnlockDefinitions.Length; j++) { TechnologyDefinition technologyDefinition = this.orbUnlockDefinitions[j]; if (DepartmentOfTheTreasury.CheckConstructiblePrerequisites(base.AIEntity.Empire, technologyDefinition, new string[] { ConstructionFlags.Prerequisite })) { DepartmentOfScience.ConstructibleElement.State technologyState = agency.GetTechnologyState(technologyDefinition); if (technologyState != DepartmentOfScience.ConstructibleElement.State.Researched && technologyState != DepartmentOfScience.ConstructibleElement.State.NotAvailable) { num11 += 1f; } else if (technologyState == DepartmentOfScience.ConstructibleElement.State.Researched) { num10 += 1f; } } } float num12 = num11 / (num11 + num10); num12 = Mathf.Min(1f, Mathf.Max(0f, 2f * num12 - 0.6f)); if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools) { Diagnostics.Log("[ELCP: AILayer_Altar] {0} has reasearched {1} of {2} Orb Techs", new object[] { base.AIEntity.Empire, num10, num11 + num10 }); Diagnostics.Log("... Season Effect Voting score altered from {0} to {1}", new object[] { num8, num8 * num12 }); } evaluableMessage_VoteForSeasonEffect.VoteCount = num9; evaluableMessage_VoteForSeasonEffect.Refresh(0.5f, num8 * num12, (float)num9 * num4, int.MaxValue); }