public static string GetTechTitleById(string id)
        {
            var result = ResearchAndDevelopment.GetTechnologyTitle(id);

            if (!String.IsNullOrEmpty(result))
            {
                return(result);
            }

            PartUpgradeHandler.Upgrade partUpgrade;
            if (PartUpgradeByName.TryGetValue(id, out partUpgrade))
            {
                RDTech upgradeTechnode;
                if (RDTechByName.TryGetValue(partUpgrade.techRequired, out upgradeTechnode))
                {
                    return(upgradeTechnode.title);
                }
            }

            RDTech technode;

            if (RDTechByName.TryGetValue(id, out technode))
            {
                return(technode.title);
            }

            return(id);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called from RP0KCT
        /// </summary>
        /// <param name="validationError"></param>
        /// <param name="canBeResolved"></param>
        /// <param name="costToResolve"></param>
        /// <returns></returns>
        public virtual bool Validate(out string validationError, out bool canBeResolved, out float costToResolve)
        {
            validationError = null;
            canBeResolved   = false;
            costToResolve   = 0;

            if (IsConfigUnlocked(heatShieldType))
            {
                return(true);
            }

            PartUpgradeHandler.Upgrade upgd = PartUpgradeManager.Handler.GetUpgrade(heatShieldType);
            if (PartUpgradeManager.Handler.IsAvailableToUnlock(heatShieldType))
            {
                canBeResolved   = true;
                costToResolve   = upgd.entryCost;
                validationError = $"purchase config {upgd.title}";
            }
            else
            {
                validationError = $"unlock tech {ResearchAndDevelopment.GetTechnologyTitle(upgd.techRequired)}";
            }

            return(false);
        }
Exemplo n.º 3
0
        public virtual bool Validate(out string validationError, out bool canBeResolved, out float costToResolve)
        {
            validationError = null;
            canBeResolved   = false;
            costToResolve   = 0;

            if (CurrentProceduralAvionicsConfig == null && !string.IsNullOrEmpty(avionicsConfigName))
            {
                CurrentProceduralAvionicsConfig = ProceduralAvionicsTechManager.GetProceduralAvionicsConfig(avionicsConfigName);
            }

            if (!CurrentProceduralAvionicsTechNode.IsAvailable)
            {
                validationError = $"unlock tech {ResearchAndDevelopment.GetTechnologyTitle(CurrentProceduralAvionicsTechNode.name)}";
                return(false);
            }

            int unlockCost = ProceduralAvionicsTechManager.GetUnlockCost(CurrentProceduralAvionicsConfig.name, CurrentProceduralAvionicsTechNode);

            if (unlockCost == 0)
            {
                return(true);
            }

            canBeResolved   = true;
            costToResolve   = unlockCost;
            validationError = $"purchase config {CurrentProceduralAvionicsTechNode.dispName}";

            return(false);
        }
Exemplo n.º 4
0
        private void InitializeSuffixes()
        {
            AddSuffix("TECHID", new Suffix <StringValue>(() => m_node.techID));
            AddSuffix("SCIENCECOST", new Suffix <ScalarIntValue>(() => m_node.scienceCost));
            AddSuffix("STATE", new Suffix <StringValue>(() => m_node.state.ToString()));
            AddSuffix("TITLE", new Suffix <StringValue>(() => ResearchAndDevelopment.GetTechnologyTitle(m_node.techID)));

            AddSuffix("RESEARCH", new NoArgsVoidSuffix(Research));
        }
Exemplo n.º 5
0
        // specifics support
        public Specifics Specs()
        {
            Specifics specs = new Specifics();

            specs.add("slots", slots.ToString());
            specs.add("reconfigure", new CrewSpecs(reconfigure).info());
            specs.add(string.Empty);
            specs.add("setups:");

            // organize setups by tech required, and add the ones without tech
            Dictionary <string, List <string> > org = new Dictionary <string, List <string> >();

            foreach (ConfigureSetup setup in setups)
            {
                if (setup.tech.Length > 0)
                {
                    if (!org.ContainsKey(setup.tech))
                    {
                        org.Add(setup.tech, new List <string>());
                    }
                    org[setup.tech].Add(setup.name);
                }
                else
                {
                    specs.add(Lib.BuildString("• <b>", setup.name, "</b>"));
                }
            }

            // add setups grouped by tech
            foreach (var pair in org)
            {
                // shortcuts
                string        tech_id     = pair.Key;
                List <string> setup_names = pair.Value;

                // get tech title
                // note: non-stock technologies will return empty titles, so we use tech-id directly in that case
                string tech_title = ResearchAndDevelopment.GetTechnologyTitle(tech_id).ToLower();
                tech_title = !string.IsNullOrEmpty(tech_title) ? tech_title : tech_id;

                // add tech name
                specs.add(string.Empty);
                specs.add(Lib.BuildString("<color=#00ffff>", tech_title, ":</color>"));

                // add setup names
                foreach (string setup_name in setup_names)
                {
                    specs.add(Lib.BuildString("• <b>", setup_name, "</b>"));
                }
            }

            return(specs);
        }
Exemplo n.º 6
0
        public void RecoverVessel()
        {
            if (KCTGameStates.IsSimulatedFlight)
            {
                KCT_GUI.GUIStates.ShowSimulationGUI = true;
                return;
            }

            bool isSPHAllowed = Utilities.IsSphRecoveryAvailable(FlightGlobals.ActiveVessel);
            bool isVABAllowed = Utilities.IsVabRecoveryAvailable(FlightGlobals.ActiveVessel);
            var  options      = new List <DialogGUIBase>();

            if (!FlightGlobals.ActiveVessel.isEVA)
            {
                string nodeTitle     = ResearchAndDevelopment.GetTechnologyTitle(PresetManager.Instance.ActivePreset.GeneralSettings.VABRecoveryTech);
                string techLimitText = string.IsNullOrEmpty(nodeTitle) ? string.Empty :
                                       $"\nAdditionally requires {nodeTitle} tech node to be researched (unless the vessel is in Prelaunch state).";
                string genericReuseText = "Allows the vessel to be launched again after a short recovery delay.";

                options.Add(new DialogGUIButtonWithTooltip("Recover to SPH", RecoverToSPH)
                {
                    OptionInteractableCondition = () => isSPHAllowed,
                    tooltipText = isSPHAllowed ? genericReuseText : "Can only be used when the vessel was built in SPH."
                });

                options.Add(new DialogGUIButtonWithTooltip("Recover to VAB", RecoverToVAB)
                {
                    OptionInteractableCondition = () => isVABAllowed,
                    tooltipText = isVABAllowed ? genericReuseText : $"Can only be used when the vessel was built in VAB.{techLimitText}"
                });

                options.Add(new DialogGUIButtonWithTooltip("Normal recovery", DoNormalRecovery)
                {
                    tooltipText = "Vessel will be scrapped and the total value of recovered parts will be refunded."
                });
            }
            else
            {
                options.Add(new DialogGUIButtonWithTooltip("Recover", DoNormalRecovery));
            }

            options.Add(new DialogGUIButton("Cancel", () => { }));

            var diag = new MultiOptionDialog("RecoverVesselPopup",
                                             "Do you want KCT to do the recovery?",
                                             "Recover vessel",
                                             null, options: options.ToArray());

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
        }
Exemplo n.º 7
0
        public static string GetTechTitleById(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(id);
            }

            var result = ResearchAndDevelopment.GetTechnologyTitle(id);

            if (!string.IsNullOrEmpty(result))
            {
                return(result);
            }

            if (PartUpgradeByName.TryGetValue(id, out var partUpgrade))
            {
                if (partUpgrade != null && !string.IsNullOrWhiteSpace(partUpgrade.techRequired))
                {
                    if (RdTechByName == null)
                    {
                        Debug.LogError("[KSPI]: GetTechTitleById - RdTechByName is null");
                        return(partUpgrade.techRequired);
                    }

                    if (RdTechByName.TryGetValue(partUpgrade.techRequired, out var upgradeTechNode))
                    {
                        return(upgradeTechNode?.title);
                    }
                }
                else if (partUpgrade == null)
                {
                    Debug.LogError("[KSPI]: GetTechTitleById - partUpgrade is null");
                }
                else
                {
                    Debug.LogError("[KSPI]: GetTechTitleById - partUpgrade.techRequired is null");
                }
            }

            if (RdTechByName.TryGetValue(id, out var techNode))
            {
                return(techNode.title);
            }

            return(id);
        }
Exemplo n.º 8
0
        protected virtual void unlockTechNode()
        {
            if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER && HighLogic.CurrentGame.Mode != Game.Modes.SCIENCE_SANDBOX)
            {
                return;
            }

            int unlockRoll = UnityEngine.Random.Range(1, dieRoll);

            if (unlockRoll < unlockTargetNumber)
            {
                return;
            }

            //Get the list of unavailable nodes and their tech IDs
            List <ProtoTechNode> unavailableNodes = AssetBase.RnDTechTree.GetNextUnavailableNodes();

            if (unavailableNodes.Count <= 0)
            {
                return;
            }
            ProtoTechNode            node;
            int                      index     = 0;
            Dictionary <string, int> techNodes = new Dictionary <string, int>();

            for (index = 0; index < unavailableNodes.Count; index++)
            {
                if (techNodes.ContainsKey(unavailableNodes[index].techID) == false)
                {
                    techNodes.Add(unavailableNodes[index].techID, index);
                }
            }

            index = UnityEngine.Random.Range(0, unavailableNodes.Count);
            node  = unavailableNodes[index];
            ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);
            ResearchAndDevelopment.RefreshTechTreeUI();

            ScreenMessages.PostScreenMessage(unlockMessage, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
            ScreenMessages.PostScreenMessage(ResearchAndDevelopment.GetTechnologyTitle(node.techID) + kUnlockTechNodeMsg, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
        }
Exemplo n.º 9
0
        public PartUpgrade(string name, string partName)
        {
            this.partName = partName;
            upgradeName   = name;
            isUnlocked    = PartUpgradeManager.Handler.IsUnlocked(upgradeName);
            string techRequired = PartUpgradeManager.Handler.GetUpgrade(upgradeName).techRequired;

            if (techRequired != null)
            {
                techTitle   = ResearchAndDevelopment.GetTechnologyTitle(techRequired);
                isUntracked = false;
            }
            else
            {
                techTitle   = "Undefined";
                isUntracked = true;
            }
            upgradeTitle      = PartUpgradeManager.Handler.GetUpgrade(upgradeName).title;
            moduleUpgrades    = new List <ModuleUpgrade>();
            overridenUpgrades = new List <string>();
        }
Exemplo n.º 10
0
        // specifics support
        public Specifics Specs()
        {
            Specifics specs = new Specifics();

            specs.Add("Slots", slots.ToString());
            specs.Add("Reconfigure", new CrewSpecs(reconfigure).Info());
            specs.Add(string.Empty);
            specs.Add("Setups:");

            // organize setups by tech required, and add the ones without tech
            Dictionary <string, List <string> > org = new Dictionary <string, List <string> >();

            foreach (ConfigureSetup setup in setups)
            {
                if (setup.tech.Length > 0)
                {
                    if (!org.ContainsKey(setup.tech))
                    {
                        org.Add(setup.tech, new List <string>());
                    }
                    org[setup.tech].Add(setup.name);
                }
                else
                {
                    specs.Add(Lib.BuildString("• <b>", setup.name, "</b>"));
                }
            }

            // add setups grouped by tech
            foreach (var pair in org)
            {
                // shortcuts
                string        tech_id     = pair.Key;
                List <string> setup_names = pair.Value;

                // get tech title
                // note: non-stock technologies will return empty titles, so we use tech-id directly in that case

                // this works in KSP 1.6
                string tech_title = Localizer.Format(ResearchAndDevelopment.GetTechnologyTitle(tech_id));
                tech_title = !string.IsNullOrEmpty(tech_title) ? tech_title : tech_id;

                // this seems to have worked for KSP < 1.6
                if (tech_title.StartsWith("#", StringComparison.Ordinal))
                {
                    tech_title = Localizer.Format(ResearchAndDevelopment.GetTechnologyTitle(tech_id.ToLower()));
                }

                // safeguard agains having #autoloc_1234 texts in the UI
                if (tech_title.StartsWith("#", StringComparison.Ordinal))
                {
                    tech_title = tech_id;
                }

                // add tech name
                specs.Add(string.Empty);
                specs.Add(Lib.BuildString("<color=#00ffff>", tech_title, ":</color>"));

                // add setup names
                foreach (string setup_name in setup_names)
                {
                    specs.Add(Lib.BuildString("• <b>", setup_name, "</b>"));
                }
            }

            return(specs);
        }
Exemplo n.º 11
0
        public void ExperimentRequirementsMet(string experimentID, float chanceOfSuccess, float resultRoll)
        {
            Log("ExperimentRequirementsMet called");

            //Career/Science mode only
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                Log("Not in flight scene.");
                return;
            }
            if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER && HighLogic.CurrentGame.Mode != Game.Modes.SCIENCE_SANDBOX)
            {
                Log("Current game is neither career nor science sandbox.");
                return;
            }
            if (resultRoll < chanceOfSuccess)
            {
                Log(string.Format("resultRoll ({0:f2}) < chanceOfSuccess ({1:f2}), exiting.", resultRoll, chanceOfSuccess));
                return;
            }

            //Make sure we reach our target number
            int unlockRoll = UnityEngine.Random.Range(1, dieRoll);

            if (unlockRoll < targetNumber)
            {
                Log(string.Format("unlockRoll ({0:n}) < targetNumber ({1:n}), exiting.", unlockRoll, targetNumber));
                return;
            }

            //Get the list of unavailable nodes and their tech IDs
            List <ProtoTechNode> unavailableNodes = AssetBase.RnDTechTree.GetNextUnavailableNodes();

            if (unavailableNodes.Count <= 0)
            {
                return;
            }
            ProtoTechNode            node;
            int                      index     = 0;
            Dictionary <string, int> techNodes = new Dictionary <string, int>();

            for (index = 0; index < unavailableNodes.Count; index++)
            {
                if (techNodes.ContainsKey(unavailableNodes[index].techID) == false)
                {
                    techNodes.Add(unavailableNodes[index].techID, index);
                }
            }

            //Unlock the first tech node on our priority list that hasn't been unlocked yet.
            char[] delimiters = new char[] { ';' };
            if (!string.IsNullOrEmpty(priorityNodes))
            {
                string[] priorityList = priorityNodes.Split(delimiters);
                Log("priorityList length: " + priorityList.Length);

                for (index = 0; index < priorityList.Length; index++)
                {
                    //Check the compiled list for the tech item we're interested in
                    //If we find one, the unlock the node
                    if (techNodes.ContainsKey(priorityList[index]))
                    {
                        node = unavailableNodes[techNodes[priorityList[index]]];
                        ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);
                        ResearchAndDevelopment.RefreshTechTreeUI();

                        ScreenMessages.PostScreenMessage(kUnlockTechNodeMsg + ResearchAndDevelopment.GetTechnologyTitle(node.techID), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }
            }

            //Ok, at this point we need to try and unlock a random node.
            //If we have no blacklisted nodes then just select one at random.
            if (string.IsNullOrEmpty(blacklistNodes))
            {
                index = UnityEngine.Random.Range(0, unavailableNodes.Count);
                node  = unavailableNodes[index];
                ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);
                ResearchAndDevelopment.RefreshTechTreeUI();

                ScreenMessages.PostScreenMessage(kUnlockTechNodeMsg + ResearchAndDevelopment.GetTechnologyTitle(node.techID), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
            }

            //We must skip any nodes that are blacklisted.
            //We have a maximum number of tries equal to the number of blacklisted nodes.
            else
            {
                string[] nodesBlacklisted = blacklistNodes.Split(delimiters);
                int      nodeIndex        = -1;
                for (index = 0; index < nodesBlacklisted.Length; index++)
                {
                    nodeIndex = UnityEngine.Random.Range(0, unavailableNodes.Count);
                    node      = unavailableNodes[nodeIndex];

                    if (!blacklistNodes.Contains(node.techID))
                    {
                        ResearchAndDevelopment.Instance.UnlockProtoTechNode(node);
                        ResearchAndDevelopment.RefreshTechTreeUI();

                        ScreenMessages.PostScreenMessage(kUnlockTechNodeMsg + ResearchAndDevelopment.GetTechnologyTitle(node.techID), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }
            }
        }