private static void SetToIdealTier(IColonizationResearchScenario colonizationResearch, IEnumerable <ITieredProducer> producers) { foreach (var producer in producers) { StaticAnalysis.SetToIdealTier(colonizationResearch, producer); } }
private PartSetupDialog(TieredResource product, string body, TechTier tier, TechTier maxTierForPart) { this.Body = body; this.Tier = tier; this.Product = product; this.MaxTierForPart = maxTierForPart; this.RiskLevel = StaticAnalysis.GetTierSuitability(ColonizationResearchScenario.Instance, this.Product, tier, maxTierForPart, this.Body); }
private static void SetToIdealTier(IColonizationResearchScenario colonizationResearch, ITieredProducer producer) { for (TechTier tier = TechTier.Tier4; tier >= TechTier.Tier0; --tier) { var suitability = StaticAnalysis.GetTierSuitability(colonizationResearch, producer.Output, tier, producer.MaximumTier, producer.Body); if (suitability == TierSuitability.Ideal) { producer.Tier = tier; break; } } }
public void OnLaunchClicked() { this.CalculateWarnings(); if (this.lastWarningList.Any(w => w.IsClearlyBroken)) { string message = "You might want to check this list of concerns the boys in the office have about this vessel:" + Environment.NewLine + string.Join(Environment.NewLine, this.lastWarningList.Select(w => w.Message).ToArray()); PopupMessageWithKerbal.ShowOkayCancel("You sure, boss?", message, "Don't worry, I have a plan!", "Good point", () => { StaticAnalysis.FixBannedCargos(); EditorLogic.fetch.launchVessel(); }); } else { EditorLogic.fetch.launchVessel(); } }
internal static IEnumerable <WarningMessage> CheckTieredProduction(IColonizationResearchScenario colonizationResearch, List <ITieredProducer> producers, Dictionary <string, double> amountAvailable, Dictionary <string, double> storageAvailable) { List <ITieredProducer> noScannerParts = new List <ITieredProducer>(); List <ITieredProducer> noSubResearchParts = new List <ITieredProducer>(); List <ITieredProducer> underTier = new List <ITieredProducer>(); foreach (var producer in producers) { var suitability = StaticAnalysis.GetTierSuitability(colonizationResearch, producer.Output, producer.Tier, producer.MaximumTier, producer.Body); switch (suitability) { case TierSuitability.LacksScanner: noScannerParts.Add(producer); break; case TierSuitability.LacksSubordinateResearch: noSubResearchParts.Add(producer); break; case TierSuitability.UnderTier: underTier.Add(producer); break; default: break; } } if (noScannerParts.Any()) { var examplePart = noScannerParts[0]; yield return(new WarningMessage { Message = $"Scanning technology at {examplePart.Body} has not kept up with production technologies - {examplePart.Tier.DisplayName()} parts will not function until you deploy an equal-tier scanner to orbit around {examplePart.Body}.", IsClearlyBroken = true, FixIt = () => SetToIdealTier(colonizationResearch, noScannerParts) }); } if (noSubResearchParts.Any()) { var examplePart = noSubResearchParts[0]; yield return(new WarningMessage { Message = $"Not all the products in the production chain for {examplePart.Output.DisplayName} have advanced to {examplePart.Tier}.", IsClearlyBroken = true, FixIt = () => SetToIdealTier(colonizationResearch, noSubResearchParts) }); } if (underTier.Any()) { var examplePart = underTier[0]; yield return(new WarningMessage { Message = $"This base is not taking advantage of the latest tech for producing {examplePart.Output.DisplayName}", IsClearlyBroken = true, FixIt = () => SetToIdealTier(colonizationResearch, underTier) }); } var mostUsedBodyAndCount = producers .Where(c => c.Output.ProductionRestriction != ProductionRestriction.Space) .Where(c => c.Body != null) .GroupBy(c => c.Body) .Select(g => new { body = g.Key, count = g.Count() }) .OrderByDescending(o => o.count) .ToArray(); string targetBody = mostUsedBodyAndCount.Length > 0 ? mostUsedBodyAndCount[0].body : null; foreach (var pair in producers.GroupBy(producer => producer.Output)) { TieredResource output = pair.Key; IEnumerable <ITieredProducer> parts = pair; // Parts should be set consistently TechTier minTier = parts.Min(p => p.Tier); TechTier maxTier = parts.Max(p => p.Tier); if (minTier != maxTier) { yield return(new WarningMessage { Message = $"Not all of the parts producing {output.BaseName} are set at {maxTier}", IsClearlyBroken = false, FixIt = () => { foreach (var part in parts) { part.Tier = maxTier; } } }); break; } // Supplier parts should be at least maxTier var firstPart = parts.First(); TieredResource input = firstPart.Input; if (parts.First().Input == null && output.IsHarvestedLocally && targetBody != null) { // then it depends on scanning TechTier maxScanningTier = colonizationResearch.GetMaxUnlockedScanningTier(targetBody); if (maxTier > maxScanningTier) { } } else if (input != null) { // Ensure that the suppliers are all at least the same tier. if (producers.Any(producer => producer.Output == input && producer.Tier < maxTier)) { yield return(new WarningMessage { Message = $"There are {maxTier.DisplayName()} producers of {output.BaseName}, but it requires equal-tier {input.BaseName} production in order to work.", IsClearlyBroken = true, FixIt = null }); } } } }
private void CalculateTierLabels(bool setTier) { for (TechTier tier = TechTier.Tier0; tier <= TechTier.Tier4; ++tier) { var suitability = StaticAnalysis.GetTierSuitability(ColonizationResearchScenario.Instance, this.Product, tier, this.MaxTierForPart, this.Body); bool isEnabled; Func <string, string> transform; string toolTipTag; switch (suitability) { default: case TierSuitability.Ideal: transform = TextEffects.Green; toolTipTag = "#LOC_KPBS_IDEAL_TIER"; isEnabled = true; if (setTier) { this.RiskLevel = TierSuitability.Ideal; this.Tier = tier; } break; case TierSuitability.LacksScanner: transform = TextEffects.Yellow; toolTipTag = "#LOC_KPBS_SCANNING_SKILL_LAGS"; isEnabled = true; break; case TierSuitability.LacksSubordinateResearch: transform = TextEffects.Red; toolTipTag = "#LOC_KPBS_SUBORDINATE_SKILL_LAGS"; isEnabled = true; break; case TierSuitability.UnderTier: transform = TextEffects.Yellow; toolTipTag = "#LOC_KPBS_UNDER_TIER"; isEnabled = true; break; case TierSuitability.NotResearched: transform = s => s; toolTipTag = "#LOC_KPBS_NOT_RESEARCHED"; isEnabled = false; break; case TierSuitability.BodyNotSelected: transform = s => s; toolTipTag = "#LOC_KPBS_CHOOSE_A_BODY_FIRST"; isEnabled = false; break; case TierSuitability.PartDoesntSupportTier: transform = s => s; toolTipTag = "#LOC_KPBS_PART_DOES_NOT_SUPPORT_TIER"; isEnabled = false; break; } TechTier techTierCopy = tier; string labelGetter() => transform(techTierCopy.DisplayName()); void onToggled(bool isSelected) { if (isSelected && isEnabled) { this.Tier = techTierCopy; this.RiskLevel = suitability; } } if (this.tierToggles[(int)tier] == null) { this.tierToggles[(int)tier] = new DialogGUIToggle(() => techTierCopy == this.Tier, labelGetter, onToggled); } else { this.tierToggles[(int)tier].setLabel = labelGetter; this.tierToggles[(int)tier].onToggled = onToggled; } this.tierToggles[(int)tier].OptionInteractableCondition = () => isEnabled; this.tierToggles[(int)tier].tooltipText = Localizer.GetStringByTag(toolTipTag); } }