private bool CanAffordTechs() { ConstructionQueue constructionQueueForEmpire = this.kaijuTechsService.GetConstructionQueueForEmpire(base.Empire); Dictionary <string, float> dictionary = new Dictionary <string, float>(); for (int i = 0; i < constructionQueueForEmpire.Length; i++) { ConstructibleElement constructibleElement = constructionQueueForEmpire.PeekAt(i).ConstructibleElement; for (int j = 0; j < constructibleElement.Costs.Length; j++) { string key = constructibleElement.Costs[j].ResourceName; float num = -constructibleElement.Costs[j].GetValue(base.Empire); if (!dictionary.ContainsKey(constructibleElement.Costs[j].ResourceName)) { dictionary.Add(constructibleElement.Costs[j].ResourceName, num); } else { num += dictionary[key]; dictionary[key] = num; } } } foreach (KeyValuePair <string, float> keyValuePair in dictionary) { float value = keyValuePair.Value; if (!this.departmentOfTheTreasury.IsTransferOfResourcePossible(base.Empire, keyValuePair.Key, ref value)) { return(false); } } return(true); }
private float DecisionScoreTransferFunctionDelegate(ConstructibleElement aiEvaluableElement, float score) { BoosterDefinition constructibleElement = aiEvaluableElement as BoosterDefinition; ConstructionResourceStock[] array; base.DepartmentOfTheTreasury.GetInstantConstructionResourceCostForBuyout(base.Empire, constructibleElement, out array); float num = 0f; for (int i = 0; i < array.Length; i++) { float num2 = 0f; if (!base.DepartmentOfTheTreasury.TryGetResourceStockValue(base.Empire, array[i].PropertyName, out num2, false) || num2 == 0f) { num = 1f; break; } float num3 = array[i].Stock / num2; if (num3 > num) { num = num3; } } score = AILayer.Boost(score, this.costFactorFromRegistry * (1f - num)); return(score); }
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)); }
public void SwapPointOfInterestImprovement(ConstructibleElement constructibleElement, Empire empire = null) { this.RemovePointOfInterestImprovement(); this.PointOfInterestImprovement = constructibleElement; this.RefreshEmpireAffinityMapping(empire); if (this.PointOfInterestImprovement != null && this.PointOfInterestImprovement.Descriptors != null) { this.AddImprovementDescriptors(this.PointOfInterestImprovement.Descriptors); } this.LineOfSightDirty = true; }
public static void ComputeCostAndTurn(Amplitude.Unity.Gui.IGuiService guiService, ReadOnlyCollection <Construction> constructibles, DepartmentOfTheTreasury departmentOfTheTreasury, SimulationObjectWrapper context, out string costString, out int turn) { PanelFeatureCost.costByResource.Clear(); for (int i = 0; i < constructibles.Count; i++) { ConstructibleElement constructibleElement = constructibles[i].ConstructibleElement; if (constructibleElement.Costs != null) { if (constructibleElement is TechnologyDefinition && context.SimulationObject.Tags.Contains(FactionTrait.FactionTraitReplicants1) && (constructibleElement as TechnologyDefinition).TechnologyFlags != DepartmentOfScience.ConstructibleElement.TechnologyFlag.OrbUnlock && (constructibleElement as TechnologyDefinition).TechnologyFlags != DepartmentOfScience.ConstructibleElement.TechnologyFlag.KaijuUnlock) { costString = string.Empty; turn = -1; global::Empire empire = context as global::Empire; if (empire == null) { Diagnostics.LogError("Empire is null."); return; } DepartmentOfScience agency = empire.GetAgency <DepartmentOfScience>(); if (agency == null) { Diagnostics.LogError("Department of science is null"); return; } float buyOutTechnologyCost = agency.GetBuyOutTechnologyCost(constructibleElement); if (buyOutTechnologyCost != 3.40282347E+38f) { costString = GuiFormater.FormatInstantCost(empire, buyOutTechnologyCost, DepartmentOfTheTreasury.Resources.EmpireMoney, true, 0); return; } costString = "-"; return; } else { for (int j = 0; j < constructibleElement.Costs.Length; j++) { if (constructibleElement.Costs[j] is PopulationConstructionCost) { PopulationConstructionCost populationConstructionCost = constructibleElement.Costs[j] as PopulationConstructionCost; PanelFeatureCost.AppendCost(SimulationProperties.Population, populationConstructionCost.PopulationValue, true); } else { float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(context, constructibleElement, constructibleElement.Costs[j], true); PanelFeatureCost.AppendCost(constructibleElement.Costs[j].ResourceName, productionCostWithBonus, constructibleElement.Costs[j].Instant || constructibleElement.Costs[j].InstantOnCompletion); } } } } } PanelFeatureCost.GetCostAndTurn(guiService, departmentOfTheTreasury, context, out costString, out turn); }
public DepartmentOfScience.ConstructibleElement.State GetTechnologyState(ConstructibleElement technology, Empire empire) { if (technology == null) { throw new ArgumentNullException("technology"); } ConstructionQueue constructionQueue = null; if (!this.researchQueues.TryGetValue(empire.Index, out constructionQueue)) { Diagnostics.LogError("The provided empire does not have a construction queue. Make sure one is created."); return(DepartmentOfScience.ConstructibleElement.State.NotAvailable); } if (this.researchedTechNames.Contains(technology.Name)) { if (empire is MajorEmpire && !DepartmentOfTheTreasury.CheckConstructiblePrerequisites(empire, technology, new string[] { ConstructionFlags.Prerequisite })) { return(DepartmentOfScience.ConstructibleElement.State.ResearchedButUnavailable); } return(DepartmentOfScience.ConstructibleElement.State.Researched); } else { Diagnostics.Assert(constructionQueue != null); Construction construction = constructionQueue.Get(technology); if (construction != null && construction.ConstructibleElement.Name == technology.Name) { return(DepartmentOfScience.ConstructibleElement.State.InProgress); } if (constructionQueue.Contains(technology)) { return(DepartmentOfScience.ConstructibleElement.State.Queued); } if (!DepartmentOfTheTreasury.CheckConstructiblePrerequisites(empire, technology, new string[] { ConstructionFlags.Prerequisite })) { return(DepartmentOfScience.ConstructibleElement.State.NotAvailable); } return(DepartmentOfScience.ConstructibleElement.State.Available); } }
public void RefreshBuyout(AgeControlButton buyoutButton) { DepartmentOfTheTreasury agency = base.Empire.GetAgency <DepartmentOfTheTreasury>(); ConstructibleElement technology = null; if (this.departmentOfScience.ResearchQueue.Peek() != null) { technology = this.departmentOfScience.ResearchQueue.Peek().ConstructibleElement; } float buyOutTechnologyCost = this.departmentOfScience.GetBuyOutTechnologyCost(technology); float num = -buyOutTechnologyCost; string text = GuiFormater.FormatInstantCost(base.Empire, buyOutTechnologyCost, DepartmentOfTheTreasury.Resources.EmpireMoney, true, 0); string content; if (buyOutTechnologyCost != 3.40282347E+38f) { if (agency.IsTransferOfResourcePossible(base.Empire, DepartmentOfTheTreasury.Resources.TechnologiesBuyOut, ref num) && this.interactionsAllowed) { buyoutButton.AgeTransform.Enable = true; buyoutButton.AgeTransform.Alpha = 1f; this.ResearchBuyoutCostLabel.Text = text; content = AgeLocalizer.Instance.LocalizeString("%ResearchBuyoutAvailableFormat").Replace("$Cost", text); } else { buyoutButton.AgeTransform.Enable = false; buyoutButton.AgeTransform.Alpha = 0.5f; this.ResearchBuyoutCostLabel.Text = text; content = AgeLocalizer.Instance.LocalizeString("%ResearchBuyoutUnavailableFormat").Replace("$Cost", text); } } else { buyoutButton.AgeTransform.Enable = false; buyoutButton.AgeTransform.Alpha = 0.5f; this.ResearchBuyoutCostLabel.Text = "%ResearchVoidSymbol"; content = AgeLocalizer.Instance.LocalizeString("%ResearchBuyoutNoSelection"); } if (buyoutButton.AgeTransform.AgeTooltip != null) { buyoutButton.AgeTransform.AgeTooltip.Content = content; } }
protected override void ComputeInitValue() { base.ComputeInitValue(); Diagnostics.Assert(this.contextSimulationObject != null); float propertyValue = this.contextSimulationObject.GetPropertyValue(SimulationProperties.NetCityProduction); Diagnostics.Assert(this.constructionQueue != null); Construction construction = this.constructionQueue.Peek(); ConstructibleElement constructibleElement = (construction == null) ? null : construction.ConstructibleElement; this.currentCostWithReduction = ((constructibleElement == null) ? 0f : DepartmentOfTheTreasury.GetProductionCostWithBonus(this.contextSimulationObject, constructibleElement, DepartmentOfTheTreasury.Resources.Production)); this.currentProductionStress = 1f; UnitDesign unitDesign = constructibleElement as UnitDesign; if (unitDesign != null) { this.currentProductionStress = 0f; bool flag = false; IEnumerable <EvaluableMessageWithUnitDesign> messages = this.aiPlayer.Blackboard.GetMessages <EvaluableMessageWithUnitDesign>(BlackboardLayerID.Empire, (EvaluableMessageWithUnitDesign match) => match.UnitDesign != null && match.UnitDesign.Model == unitDesign.Model); foreach (EvaluableMessageWithUnitDesign evaluableMessageWithUnitDesign in messages) { if (float.IsNaN(evaluableMessageWithUnitDesign.Interest)) { Diagnostics.LogWarning("Unit request interest is at value NaN, it will be skipped."); } else { this.currentProductionStress = Mathf.Max(this.currentProductionStress, evaluableMessageWithUnitDesign.Interest); flag = true; } } if (!flag) { this.currentProductionStress = 1f; } } this.currentProductionStress = Mathf.Clamp01(this.currentProductionStress); float num = this.currentCostWithReduction * this.currentProductionStress; float num2 = (propertyValue <= 0f) ? this.maximumTurnCount : (num / propertyValue); base.ValueInit = ((this.maximumTurnCount <= 0f) ? base.ValueMax : Mathf.Clamp(Mathf.Max(num2 - 1f, 0f) / Mathf.Max(1f, this.maximumTurnCount - 1f), base.ValueMin, base.ValueMax)); }
private void RefreshCosts() { ConstructionQueue constructionQueueForEmpire = this.kaijuTechsService.GetConstructionQueueForEmpire(base.Empire); ConstructibleElement constructibleElement = null; if (constructionQueueForEmpire.Peek() != null) { constructibleElement = constructionQueueForEmpire.Peek().ConstructibleElement; } int num = 0; string text; PanelFeatureCost.ComputeCostAndTurn(base.GuiService, constructionQueueForEmpire.PendingConstructions, this.departmentOfTheTreasury, base.Empire, out text, out num); if (constructibleElement != null) { if (this.CanAffordTechs()) { this.buyoutCostLabel.Text = text; this.buyoutButton.AgeTransform.Enable = true; this.buyoutButton.AgeTransform.Alpha = 1f; string text2 = AgeLocalizer.Instance.LocalizeString("%KaijuUnlockBuyoutAvailableFormat").Replace("$Cost", text); } else { this.buyoutCostLabel.Text = text; this.buyoutButton.AgeTransform.Enable = false; this.buyoutButton.AgeTransform.Alpha = 0.5f; string text2 = AgeLocalizer.Instance.LocalizeString("%KaijuUnlockBuyoutUnavailableFormat").Replace("$Cost", text); } } else { this.buyoutButton.AgeTransform.Enable = false; this.buyoutButton.AgeTransform.Alpha = 0.5f; this.buyoutCostLabel.Text = "%ResearchVoidSymbol"; string text2 = AgeLocalizer.Instance.LocalizeString("%KaijuUnlockBuyoutNoSelectionDescription"); } }
public void UnlockTechnology(ConstructibleElement technology, Empire empire) { if (technology == null) { throw new ArgumentNullException("technology"); } if (this.GetTechnologyState(technology, empire) == DepartmentOfScience.ConstructibleElement.State.Researched) { return; } ConstructionQueue constructionQueueForEmpire = this.GetConstructionQueueForEmpire(empire); if (constructionQueueForEmpire.Contains(technology)) { constructionQueueForEmpire.Remove(technology); } this.researchedTechNames.Add(technology.Name); this.researchedTechs.Add(technology); if (this.KaijuTechnologyUnlocked != null) { this.KaijuTechnologyUnlocked(this, new ConstructibleElementEventArgs(technology)); } }
private void RefreshCurrentResearch() { DepartmentOfScience agency = base.Empire.GetAgency <DepartmentOfScience>(); DepartmentOfTheTreasury agency2 = base.Empire.GetAgency <DepartmentOfTheTreasury>(); Construction construction = agency.ResearchQueue.Peek(); IDownloadableContentService service = Services.GetService <IDownloadableContentService>(); if (service != null && service.IsShared(DownloadableContent11.ReadOnlyName) && base.Empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitReplicants1)) { this.ResearchBuyoutButton.AgeTransform.Visible = true; this.ResearchBuyoutLabel.AgeTransform.Visible = true; this.CurrentResearchTitle.AgeTransform.Visible = false; this.EmpireResearchPanel.Enable = true; this.EmpireResearchPanel.AgeTooltip.Class = string.Empty; this.EmpireResearchPanel.AgeTooltip.Content = string.Empty; this.EmpireResearchPanel.AgeTooltip.ClientData = null; ConstructibleElement technology = null; if (this.departmentOfScience.ResearchQueue.Peek() != null) { technology = this.departmentOfScience.ResearchQueue.Peek().ConstructibleElement; } float buyOutTechnologyCost = this.departmentOfScience.GetBuyOutTechnologyCost(technology); float num = -buyOutTechnologyCost; string newValue = GuiFormater.FormatInstantCost(base.Empire, buyOutTechnologyCost, DepartmentOfTheTreasury.Resources.EmpireMoney, true, 0); string content; if (construction != null) { this.ResearchBuyoutLabel.AgeTransform.Alpha = 1f; TechnologyDefinition technologyDefinition = construction.ConstructibleElement as TechnologyDefinition; if (technologyDefinition != null) { AgeUtils.TruncateString(AgeLocalizer.Instance.LocalizeString(DepartmentOfScience.GetTechnologyTitle(technologyDefinition)), this.ResearchBuyoutLabel, out this.format, '.'); DepartmentOfScience.BuildTechnologyTooltip(technologyDefinition, base.Empire, this.ResearchBuyoutLabel.AgeTransform.AgeTooltip, MultipleConstructibleTooltipData.TechnologyState.Normal); } if (agency2.IsTransferOfResourcePossible(base.Empire, DepartmentOfTheTreasury.Resources.TechnologiesBuyOut, ref num) && this.interactionsAllowed) { this.ResearchBuyoutButton.AgeTransform.Enable = true; this.ResearchBuyoutButton.AgeTransform.Alpha = 1f; this.ResearchBuyoutLabel.Text = this.format; content = AgeLocalizer.Instance.LocalizeString("%ResearchBuyoutAvailableFormat").Replace("$Cost", newValue); } else { this.ResearchBuyoutButton.AgeTransform.Enable = false; this.ResearchBuyoutButton.AgeTransform.Alpha = 0.5f; this.ResearchBuyoutLabel.Text = this.format; content = AgeLocalizer.Instance.LocalizeString("%ResearchBuyoutUnavailableFormat").Replace("$Cost", newValue); } } else { this.ResearchBuyoutButton.AgeTransform.Enable = false; this.ResearchBuyoutButton.AgeTransform.Alpha = 0.5f; this.ResearchBuyoutLabel.Text = "%ResearchNoneTitle"; this.ResearchBuyoutLabel.AgeTransform.Alpha = 0.5f; content = AgeLocalizer.Instance.LocalizeString("%ResearchBuyoutNoSelection"); this.ResearchBuyoutLabel.AgeTransform.AgeTooltip.Class = string.Empty; this.ResearchBuyoutLabel.AgeTransform.AgeTooltip.Content = "%ResearchNoneDescription"; this.ResearchBuyoutLabel.AgeTransform.AgeTooltip.ClientData = null; } if (this.ResearchBuyoutButton.AgeTransform.AgeTooltip != null) { this.ResearchBuyoutButton.AgeTransform.AgeTooltip.Content = content; return; } } else { this.ResearchBuyoutButton.AgeTransform.Visible = false; this.ResearchBuyoutLabel.AgeTransform.Visible = false; this.CurrentResearchTitle.AgeTransform.Visible = true; if (construction != null) { this.EmpireResearchPanel.Enable = true; int num2 = agency2.ComputeConstructionRemainingTurn(base.Empire, construction); if (num2 == 2147483647) { this.format = string.Format("$Tech ({0})", GuiFormater.Infinite.ToString()); } else { this.format = string.Format("$Tech ({0})", QueueGuiItem.FormatNumberOfTurns(num2)); } TechnologyDefinition technologyDefinition2 = construction.ConstructibleElement as TechnologyDefinition; if (technologyDefinition2 != null) { AgeUtils.TruncateStringWithSubst(this.format, "$Tech", AgeLocalizer.Instance.LocalizeString(DepartmentOfScience.GetTechnologyTitle(technologyDefinition2)), this.CurrentResearchTitle, out this.format, '.'); this.CurrentResearchTitle.Text = this.format; DepartmentOfScience.BuildTechnologyTooltip(technologyDefinition2, base.Empire, this.EmpireResearchPanel.AgeTooltip, MultipleConstructibleTooltipData.TechnologyState.Normal); } } else { this.EmpireResearchPanel.Enable = false; AgeUtils.TruncateString(AgeLocalizer.Instance.LocalizeString("%ResearchNoneTitle"), this.CurrentResearchTitle, out this.format, '.'); this.CurrentResearchTitle.Text = this.format; this.EmpireResearchPanel.AgeTooltip.Class = string.Empty; this.EmpireResearchPanel.AgeTooltip.Content = "%ResearchNoneDescription"; this.EmpireResearchPanel.AgeTooltip.ClientData = null; } this.CurrentResearchTitle.Text = this.format; } }
private float ParameterContextModifierDelegate(ConstructibleElement element, StaticString aiParameterName) { return(base.AIEntity.Context.GetModifierValue(AILayer_Strategy.EmpirePlanParameterModifier, aiParameterName)); }
private float GenerateMessageScoreForIndustry() { float result = 0f; if (!AILayer_Colonization.IsAbleToColonize(base.AIEntity.Empire)) { result = 1f; } else if (this.aiEntityCity.City.BesiegingEmpire == null && this.constructionQueue.PendingConstructions.Count > 0) { ConstructibleElement constructibleElement = this.constructionQueue.Peek().ConstructibleElement; if (constructibleElement != null && (constructibleElement.SubCategory == "SubCategoryWonder" || constructibleElement.SubCategory == "SubCategoryVictory")) { return(1f); } } else { float num = 0f; float num2; for (int i = 0; i < this.departmentOfTheInterior.Cities.Count; i++) { num2 = (float)this.departmentOfTheInterior.Cities[i].CityImprovements.Count; if (num2 > num) { num = num2; } } num2 = (float)this.aiEntityCity.City.CityImprovements.Count; float num3 = 1f - num2 / num; float num4 = 0f; if (!this.departmentOfTheTreasury.TryGetNetResourceValue(this.aiEntityCity.City, "Production", out num4, false)) { num4 = 0f; } if (num4 == 0f) { num4 = 1f; } bool flag = false; bool flag2 = false; float num5 = 0f; if (!this.departmentOfTheTreasury.TryGetResourceStockValue(this.aiEntityCity.City, DepartmentOfTheTreasury.Resources.Production, out num5, false)) { num5 = 0f; } num5 += this.aiEntityCity.City.GetPropertyValue(SimulationProperties.NetCityProduction); num5 = Math.Max(1f, num5); for (int j = 0; j < this.constructionQueue.Length; j++) { Construction construction = this.constructionQueue.PeekAt(j); if (DepartmentOfTheTreasury.CheckConstructiblePrerequisites(this.aiEntityCity.City, construction.ConstructibleElement, new string[] { ConstructionFlags.Prerequisite })) { if (!flag2) { float num6 = 0f; for (int k = 0; k < construction.CurrentConstructionStock.Length; k++) { if (construction.CurrentConstructionStock[k].PropertyName == "Production") { num6 += construction.CurrentConstructionStock[k].Stock; if (construction.IsBuyout) { num6 = DepartmentOfTheTreasury.GetProductionCostWithBonus(this.aiEntityCity.City, construction.ConstructibleElement, "Production"); } } } float num7 = DepartmentOfTheTreasury.GetProductionCostWithBonus(this.aiEntityCity.City, construction.ConstructibleElement, "Production") - num6; num5 -= num7; if (num5 < 0f && !construction.ConstructibleElementName.ToString().Contains("BoosterGenerator")) { flag = true; flag2 = true; } if (construction.ConstructibleElementName.ToString().Contains("BoosterGenerator")) { flag2 = true; } } float num8 = 0f; for (int l = 0; l < construction.CurrentConstructionStock.Length; l++) { if (construction.CurrentConstructionStock[l].PropertyName == "Production") { num8 += construction.CurrentConstructionStock[l].Stock; } } float num9 = DepartmentOfTheTreasury.GetProductionCostWithBonus(this.aiEntityCity.City, construction.ConstructibleElement, "Production") - num8; num3 = AILayer.Boost(num3, this.ComputeCostBoost(num9 / num4)); } } if (this.aiEntityCity.City.BesiegingEmpire != null) { num3 = AILayer.Boost(num3, 0.5f); } if (!flag && !flag2) { flag = true; } if (!flag) { num3 = 0f; } result = num3; } return(result); }